blob: ef88bf10e62a786853bf64f7a19d183bcb8915f3 [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 Diaz9abd78d2018-07-11 21:00:32 +01007#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 <bl31/interrupt_mgmt.h>
15#include <drivers/console.h>
Andre Przywara980556d2020-03-11 15:18:03 +000016#include <drivers/rpi3/gpio/rpi3_gpio.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000017#include <drivers/ti/uart/uart_16550.h>
Andre Przywara9ba6bb02020-03-10 12:34:56 +000018#include <drivers/arm/pl011.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000019#include <lib/xlat_tables/xlat_tables_v2.h>
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000020
Andre Przywarabb6ef152019-07-09 11:44:14 +010021#include <rpi_hw.h>
Andre Przywara4ea3bd32019-07-09 14:32:11 +010022#include <rpi_shared.h>
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000023
24#define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \
25 DEVICE0_SIZE, \
26 MT_DEVICE | MT_RW | MT_SECURE)
27
Andre Przywara0467ce92019-07-15 08:58:23 +010028#ifdef SHARED_RAM_BASE
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000029#define MAP_SHARED_RAM MAP_REGION_FLAT(SHARED_RAM_BASE, \
30 SHARED_RAM_SIZE, \
Antonio Nino Diazf96582a2018-10-19 00:57:16 +010031 MT_DEVICE | MT_RW | MT_SECURE)
Andre Przywara0467ce92019-07-15 08:58:23 +010032#endif
Antonio Nino Diazf96582a2018-10-19 00:57:16 +010033
34#ifdef RPI3_PRELOADED_DTB_BASE
35#define MAP_NS_DTB MAP_REGION_FLAT(RPI3_PRELOADED_DTB_BASE, 0x10000, \
36 MT_MEMORY | MT_RW | MT_NS)
37#endif
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000038
39#define MAP_NS_DRAM0 MAP_REGION_FLAT(NS_DRAM0_BASE, NS_DRAM0_SIZE, \
40 MT_MEMORY | MT_RW | MT_NS)
41
42#define MAP_FIP MAP_REGION_FLAT(PLAT_RPI3_FIP_BASE, \
43 PLAT_RPI3_FIP_MAX_SIZE, \
44 MT_MEMORY | MT_RO | MT_NS)
45
46#define MAP_BL32_MEM MAP_REGION_FLAT(BL32_MEM_BASE, BL32_MEM_SIZE, \
47 MT_MEMORY | MT_RW | MT_SECURE)
48
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +080049#ifdef SPD_opteed
50#define MAP_OPTEE_PAGEABLE MAP_REGION_FLAT( \
51 RPI3_OPTEE_PAGEABLE_LOAD_BASE, \
52 RPI3_OPTEE_PAGEABLE_LOAD_SIZE, \
53 MT_MEMORY | MT_RW | MT_SECURE)
54#endif
55
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000056/*
57 * Table of regions for various BL stages to map using the MMU.
58 */
59#ifdef IMAGE_BL1
60static const mmap_region_t plat_rpi3_mmap[] = {
Andre Przywara0467ce92019-07-15 08:58:23 +010061#ifdef MAP_SHARED_RAM
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000062 MAP_SHARED_RAM,
Andre Przywara0467ce92019-07-15 08:58:23 +010063#endif
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000064 MAP_DEVICE0,
65 MAP_FIP,
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +080066#ifdef SPD_opteed
67 MAP_OPTEE_PAGEABLE,
68#endif
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000069 {0}
70};
71#endif
72
73#ifdef IMAGE_BL2
74static const mmap_region_t plat_rpi3_mmap[] = {
Andre Przywara0467ce92019-07-15 08:58:23 +010075#ifdef MAP_SHARED_RAM
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000076 MAP_SHARED_RAM,
Andre Przywara0467ce92019-07-15 08:58:23 +010077#endif
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000078 MAP_DEVICE0,
79 MAP_FIP,
80 MAP_NS_DRAM0,
81#ifdef BL32_BASE
82 MAP_BL32_MEM,
83#endif
84 {0}
85};
86#endif
87
88#ifdef IMAGE_BL31
89static const mmap_region_t plat_rpi3_mmap[] = {
Andre Przywara0467ce92019-07-15 08:58:23 +010090#ifdef MAP_SHARED_RAM
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000091 MAP_SHARED_RAM,
Andre Przywara0467ce92019-07-15 08:58:23 +010092#endif
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000093 MAP_DEVICE0,
Antonio Nino Diazf96582a2018-10-19 00:57:16 +010094#ifdef RPI3_PRELOADED_DTB_BASE
95 MAP_NS_DTB,
96#endif
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000097#ifdef BL32_BASE
98 MAP_BL32_MEM,
99#endif
100 {0}
101};
102#endif
103
104/*******************************************************************************
Antonio Nino Diaz1f470022018-03-27 09:39:47 +0100105 * Function that sets up the console
106 ******************************************************************************/
Andre Przywara98b5a112020-01-25 00:58:35 +0000107static console_t rpi3_console;
Antonio Nino Diaz1f470022018-03-27 09:39:47 +0100108
Andre Przywara980556d2020-03-11 15:18:03 +0000109
Andre Przywara9ba6bb02020-03-10 12:34:56 +0000110static bool rpi3_use_mini_uart(void)
111{
Andre Przywara980556d2020-03-11 15:18:03 +0000112 return rpi3_gpio_get_select(14) == RPI3_GPIO_FUNC_ALT5;
Andre Przywara9ba6bb02020-03-10 12:34:56 +0000113}
114
Andre Przywara57ccecc2020-03-10 12:33:16 +0000115void rpi3_console_init(void)
Antonio Nino Diaz1f470022018-03-27 09:39:47 +0100116{
Pete Batardc9acd6c2018-11-13 13:14:26 +0000117 int console_scope = CONSOLE_FLAG_BOOT;
Andre Przywara57ccecc2020-03-10 12:33:16 +0000118 int rc;
119
120 if (RPI3_RUNTIME_UART != -1)
121 console_scope |= CONSOLE_FLAG_RUNTIME;
122
Andre Przywara980556d2020-03-11 15:18:03 +0000123 rpi3_gpio_init();
124
Andre Przywara9ba6bb02020-03-10 12:34:56 +0000125 if (rpi3_use_mini_uart())
126 rc = console_16550_register(PLAT_RPI_MINI_UART_BASE,
127 0,
128 PLAT_RPI_UART_BAUDRATE,
129 &rpi3_console);
130 else
131 rc = console_pl011_register(PLAT_RPI_PL011_UART_BASE,
132 PLAT_RPI_PL011_UART_CLOCK,
133 PLAT_RPI_UART_BAUDRATE,
134 &rpi3_console);
Andre Przywara57ccecc2020-03-10 12:33:16 +0000135
Antonio Nino Diaz1f470022018-03-27 09:39:47 +0100136 if (rc == 0) {
137 /*
138 * The crash console doesn't use the multi console API, it uses
139 * the core console functions directly. It is safe to call panic
140 * and let it print debug information.
141 */
142 panic();
143 }
144
Andre Przywara98b5a112020-01-25 00:58:35 +0000145 console_set_scope(&rpi3_console, console_scope);
Antonio Nino Diaz1f470022018-03-27 09:39:47 +0100146}
147
148/*******************************************************************************
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000149 * Function that sets up the translation tables.
150 ******************************************************************************/
151void rpi3_setup_page_tables(uintptr_t total_base, size_t total_size,
152 uintptr_t code_start, uintptr_t code_limit,
153 uintptr_t rodata_start, uintptr_t rodata_limit
154#if USE_COHERENT_MEM
155 , uintptr_t coh_start, uintptr_t coh_limit
156#endif
157 )
158{
159 /*
160 * Map the Trusted SRAM with appropriate memory attributes.
161 * Subsequent mappings will adjust the attributes for specific regions.
162 */
163 VERBOSE("Trusted SRAM seen by this BL image: %p - %p\n",
164 (void *) total_base, (void *) (total_base + total_size));
165 mmap_add_region(total_base, total_base,
166 total_size,
167 MT_MEMORY | MT_RW | MT_SECURE);
168
169 /* Re-map the code section */
170 VERBOSE("Code region: %p - %p\n",
171 (void *) code_start, (void *) code_limit);
172 mmap_add_region(code_start, code_start,
173 code_limit - code_start,
174 MT_CODE | MT_SECURE);
175
176 /* Re-map the read-only data section */
177 VERBOSE("Read-only data region: %p - %p\n",
178 (void *) rodata_start, (void *) rodata_limit);
179 mmap_add_region(rodata_start, rodata_start,
180 rodata_limit - rodata_start,
181 MT_RO_DATA | MT_SECURE);
182
183#if USE_COHERENT_MEM
184 /* Re-map the coherent memory region */
185 VERBOSE("Coherent region: %p - %p\n",
186 (void *) coh_start, (void *) coh_limit);
187 mmap_add_region(coh_start, coh_start,
188 coh_limit - coh_start,
189 MT_DEVICE | MT_RW | MT_SECURE);
190#endif
191
192 mmap_add(plat_rpi3_mmap);
193
194 init_xlat_tables();
195}
196
197/*******************************************************************************
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000198 * Gets SPSR for BL32 entry
199 ******************************************************************************/
200uint32_t rpi3_get_spsr_for_bl32_entry(void)
201{
202 /*
203 * The Secure Payload Dispatcher service is responsible for
204 * setting the SPSR prior to entry into the BL32 image.
205 */
206 return 0;
207}
208
209/*******************************************************************************
210 * Gets SPSR for BL33 entry
211 ******************************************************************************/
212uint32_t rpi3_get_spsr_for_bl33_entry(void)
213{
214#if RPI3_BL33_IN_AARCH32
215 INFO("BL33 will boot in Non-secure AArch32 Hypervisor mode\n");
216 return SPSR_MODE32(MODE32_hyp, SPSR_T_ARM, SPSR_E_LITTLE,
217 DISABLE_ALL_EXCEPTIONS);
218#else
219 return SPSR_64(MODE_EL2, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
220#endif
221}
222
223unsigned int plat_get_syscnt_freq2(void)
224{
225 return SYS_COUNTER_FREQ_IN_TICKS;
226}
227
228uint32_t plat_ic_get_pending_interrupt_type(void)
229{
Antonio Nino Diaz9abd78d2018-07-11 21:00:32 +0100230 ERROR("rpi3: Interrupt routed to EL3.\n");
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000231 return INTR_TYPE_INVAL;
232}
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +0800233
Antonio Nino Diaz9abd78d2018-07-11 21:00:32 +0100234uint32_t plat_interrupt_type_to_line(uint32_t type, uint32_t security_state)
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +0800235{
Antonio Nino Diaz9abd78d2018-07-11 21:00:32 +0100236 assert((type == INTR_TYPE_S_EL1) || (type == INTR_TYPE_EL3) ||
237 (type == INTR_TYPE_NS));
238
239 assert(sec_state_is_valid(security_state));
240
241 /* Non-secure interrupts are signalled on the IRQ line always. */
242 if (type == INTR_TYPE_NS)
243 return __builtin_ctz(SCR_IRQ_BIT);
244
245 /* Secure interrupts are signalled on the FIQ line always. */
246 return __builtin_ctz(SCR_FIQ_BIT);
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +0800247}