blob: 44827c63a34649363427637b1d318c29ab727a2d [file] [log] [blame]
Antonio Nino Diazae6779e2017-11-06 14:49:04 +00001/*
Andre Przywara4ea3bd32019-07-09 14:32:11 +01002 * Copyright (c) 2015-2019, ARM Limited and Contributors. All rights reserved.
Antonio Nino Diazae6779e2017-11-06 14:49:04 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
Antonio Nino Diazae6779e2017-11-06 14:49:04 +00007#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
Antonio Nino Diazae6779e2017-11-06 14:49:04 +00009#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
11#include <arch_helpers.h>
12#include <common/bl_common.h>
13#include <common/debug.h>
14#include <common/desc_image_load.h>
15#include <lib/optee_utils.h>
16#include <lib/xlat_tables/xlat_mmu_helpers.h>
17#include <lib/xlat_tables/xlat_tables_defs.h>
Ying-Chun Liu (PaulLiu)34527382019-01-22 03:27:55 +080018#include <drivers/generic_delay_timer.h>
19#include <drivers/rpi3/gpio/rpi3_gpio.h>
Ying-Chun Liu (PaulLiu)de6f2f42019-01-30 04:20:38 +080020#include <drivers/rpi3/sdhost/rpi3_sdhost.h>
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000021
Andre Przywara4ea3bd32019-07-09 14:32:11 +010022#include <rpi_shared.h>
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000023
24/* Data structure which holds the extents of the trusted SRAM for BL2 */
25static meminfo_t bl2_tzram_layout __aligned(CACHE_WRITEBACK_GRANULE);
26
Ying-Chun Liu (PaulLiu)34527382019-01-22 03:27:55 +080027/* rpi3 GPIO setup function. */
28static void rpi3_gpio_setup(void)
29{
30 struct rpi3_gpio_params params;
31
32 memset(&params, 0, sizeof(struct rpi3_gpio_params));
33 params.reg_base = RPI3_GPIO_BASE;
34
35 rpi3_gpio_init(&params);
36}
37
Ying-Chun Liu (PaulLiu)de6f2f42019-01-30 04:20:38 +080038/* Data structure which holds the MMC info */
39static struct mmc_device_info mmc_info;
40
41static void rpi3_sdhost_setup(void)
42{
43 struct rpi3_sdhost_params params;
44
45 memset(&params, 0, sizeof(struct rpi3_sdhost_params));
46 params.reg_base = RPI3_SDHOST_BASE;
Ying-Chun Liu (PaulLiu)a5cdc082019-02-12 22:41:06 +080047 params.bus_width = MMC_BUS_WIDTH_1;
48 params.clk_rate = 50000000;
Ying-Chun Liu (PaulLiu)de6f2f42019-01-30 04:20:38 +080049 mmc_info.mmc_dev_type = MMC_IS_SD_HC;
50 rpi3_sdhost_init(&params, &mmc_info);
51}
52
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000053/*******************************************************************************
54 * BL1 has passed the extents of the trusted SRAM that should be visible to BL2
55 * in x0. This memory layout is sitting at the base of the free trusted SRAM.
56 * Copy it to a safe location before its reclaimed by later BL2 functionality.
57 ******************************************************************************/
Antonio Nino Diaz83d8c792018-08-17 14:25:08 +010058
59void bl2_early_platform_setup2(u_register_t arg0, u_register_t arg1,
60 u_register_t arg2, u_register_t arg3)
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000061{
Antonio Nino Diaz83d8c792018-08-17 14:25:08 +010062 meminfo_t *mem_layout = (meminfo_t *) arg1;
63
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000064 /* Initialize the console to provide early debug support */
Andre Przywarafaf86182019-08-04 10:46:21 +010065 rpi3_console_init(PLAT_RPI3_UART_CLK_IN_HZ);
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000066
Ying-Chun Liu (PaulLiu)34527382019-01-22 03:27:55 +080067 /* Enable arch timer */
68 generic_delay_timer_init();
69
70 /* Setup GPIO driver */
71 rpi3_gpio_setup();
72
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000073 /* Setup the BL2 memory layout */
74 bl2_tzram_layout = *mem_layout;
75
Ying-Chun Liu (PaulLiu)de6f2f42019-01-30 04:20:38 +080076 /* Setup SDHost driver */
77 rpi3_sdhost_setup();
78
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000079 plat_rpi3_io_setup();
80}
81
82void bl2_platform_setup(void)
83{
84 /*
85 * This is where a TrustZone address space controller and other
Antonio Nino Diaz1f470022018-03-27 09:39:47 +010086 * security related peripherals would be configured.
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000087 */
88}
89
90/*******************************************************************************
91 * Perform the very early platform specific architectural setup here.
92 ******************************************************************************/
93void bl2_plat_arch_setup(void)
94{
95 rpi3_setup_page_tables(bl2_tzram_layout.total_base,
96 bl2_tzram_layout.total_size,
97 BL_CODE_BASE, BL_CODE_END,
98 BL_RO_DATA_BASE, BL_RO_DATA_END
99#if USE_COHERENT_MEM
100 , BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END
101#endif
102 );
103
104 enable_mmu_el1(0);
105}
106
107/*******************************************************************************
108 * This function can be used by the platforms to update/use image
109 * information for given `image_id`.
110 ******************************************************************************/
111int bl2_plat_handle_post_image_load(unsigned int image_id)
112{
113 int err = 0;
114 bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +0800115#ifdef SPD_opteed
116 bl_mem_params_node_t *pager_mem_params = NULL;
117 bl_mem_params_node_t *paged_mem_params = NULL;
118#endif
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000119
120 assert(bl_mem_params != NULL);
121
122 switch (image_id) {
123 case BL32_IMAGE_ID:
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +0800124#ifdef SPD_opteed
125 pager_mem_params = get_bl_mem_params_node(BL32_EXTRA1_IMAGE_ID);
126 assert(pager_mem_params);
127
128 paged_mem_params = get_bl_mem_params_node(BL32_EXTRA2_IMAGE_ID);
129 assert(paged_mem_params);
130
131 err = parse_optee_header(&bl_mem_params->ep_info,
132 &pager_mem_params->image_info,
133 &paged_mem_params->image_info);
134 if (err != 0)
135 WARN("OPTEE header parse error.\n");
136#endif
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000137 bl_mem_params->ep_info.spsr = rpi3_get_spsr_for_bl32_entry();
138 break;
139
140 case BL33_IMAGE_ID:
141 /* BL33 expects to receive the primary CPU MPID (through r0) */
142 bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
143 bl_mem_params->ep_info.spsr = rpi3_get_spsr_for_bl33_entry();
Ying-Chun Liu (PaulLiu)de6f2f42019-01-30 04:20:38 +0800144
145 /* Shutting down the SDHost driver to let BL33 drives SDHost.*/
146 rpi3_sdhost_stop();
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000147 break;
148
Jonathan Wrightff957ed2018-03-14 15:24:00 +0000149 default:
150 /* Do nothing in default case */
151 break;
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000152 }
153
154 return err;
155}