rpi3_bl2_setup.c 4.12 KB
Newer Older
1
/*
2
 * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
3
4
5
6
7
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <assert.h>
8

9
#include <platform_def.h>
10
11
12
13
14
15
16
17

#include <arch_helpers.h>
#include <common/bl_common.h>
#include <common/debug.h>
#include <common/desc_image_load.h>
#include <lib/optee_utils.h>
#include <lib/xlat_tables/xlat_mmu_helpers.h>
#include <lib/xlat_tables/xlat_tables_defs.h>
18
19
#include <drivers/generic_delay_timer.h>
#include <drivers/rpi3/gpio/rpi3_gpio.h>
20
#include <drivers/rpi3/sdhost/rpi3_sdhost.h>
21

22
#include <rpi_shared.h>
23
24
25
26

/* Data structure which holds the extents of the trusted SRAM for BL2 */
static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);

27
28
29
30
31
32
33
34
35
/* Data structure which holds the MMC info */
static struct mmc_device_info mmc_info;

static void rpi3_sdhost_setup(void)
{
	struct rpi3_sdhost_params params;

	memset(&params, 0, sizeof(struct rpi3_sdhost_params));
	params.reg_base = RPI3_SDHOST_BASE;
36
37
	params.bus_width = MMC_BUS_WIDTH_1;
	params.clk_rate = 50000000;
38
39
40
41
	mmc_info.mmc_dev_type = MMC_IS_SD_HC;
	rpi3_sdhost_init(&params, &mmc_info);
}

42
43
44
45
46
/*******************************************************************************
 * BL1 has passed the extents of the trusted SRAM that should be visible to BL2
 * in x0. This memory layout is sitting at the base of the free trusted SRAM.
 * Copy it to a safe location before its reclaimed by later BL2 functionality.
 ******************************************************************************/
47
48
49

void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1,
			       u_register_t arg2, u_register_t arg3)
50
{
51
52
	meminfo_t *mem_layout = (meminfo_t *) arg1;

53
	/* Initialize the console to provide early debug support */
54
	rpi3_console_init(PLAT_RPI3_UART_CLK_IN_HZ);
55

56
57
58
59
	/* Enable arch timer */
	generic_delay_timer_init();

	/* Setup GPIO driver */
60
	rpi3_gpio_init();
61

62
63
64
	/* Setup the BL2 memory layout */
	bl2_tzram_layout = *mem_layout;

65
66
67
	/* Setup SDHost driver */
	rpi3_sdhost_setup();

68
69
70
71
72
73
74
	plat_rpi3_io_setup();
}

void bl2_platform_setup(void)
{
	/*
	 * This is where a TrustZone address space controller and other
Antonio Nino Diaz's avatar
Antonio Nino Diaz committed
75
	 * security related peripherals would be configured.
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
	 */
}

/*******************************************************************************
 * Perform the very early platform specific architectural setup here.
 ******************************************************************************/
void bl2_plat_arch_setup(void)
{
	rpi3_setup_page_tables(bl2_tzram_layout.total_base,
			       bl2_tzram_layout.total_size,
			       BL_CODE_BASE, BL_CODE_END,
			       BL_RO_DATA_BASE, BL_RO_DATA_END
#if USE_COHERENT_MEM
			       , BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END
#endif
			      );

	enable_mmu_el1(0);
}

/*******************************************************************************
 * This function can be used by the platforms to update/use image
 * information for given `image_id`.
 ******************************************************************************/
int bl2_plat_handle_post_image_load(unsigned int image_id)
{
	int err = 0;
	bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
104
105
106
107
#ifdef SPD_opteed
	bl_mem_params_node_t *pager_mem_params = NULL;
	bl_mem_params_node_t *paged_mem_params = NULL;
#endif
108
109
110
111
112

	assert(bl_mem_params != NULL);

	switch (image_id) {
	case BL32_IMAGE_ID:
113
114
115
116
117
118
119
120
121
122
123
124
125
#ifdef SPD_opteed
		pager_mem_params = get_bl_mem_params_node(BL32_EXTRA1_IMAGE_ID);
		assert(pager_mem_params);

		paged_mem_params = get_bl_mem_params_node(BL32_EXTRA2_IMAGE_ID);
		assert(paged_mem_params);

		err = parse_optee_header(&bl_mem_params->ep_info,
				&pager_mem_params->image_info,
				&paged_mem_params->image_info);
		if (err != 0)
			WARN("OPTEE header parse error.\n");
#endif
126
127
128
129
130
131
132
		bl_mem_params->ep_info.spsr = rpi3_get_spsr_for_bl32_entry();
		break;

	case BL33_IMAGE_ID:
		/* BL33 expects to receive the primary CPU MPID (through r0) */
		bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
		bl_mem_params->ep_info.spsr = rpi3_get_spsr_for_bl33_entry();
133
134
135

		/* Shutting down the SDHost driver to let BL33 drives SDHost.*/
		rpi3_sdhost_stop();
136
137
		break;

138
139
140
	default:
		/* Do nothing in default case */
		break;
141
142
143
144
	}

	return err;
}