2 * Copyright (c) 2015-2018, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
7 #include <arch_helpers.h>
12 #include <interrupt_mgmt.h>
13 #include <platform_def.h>
14 #include <uart_16550.h>
15 #include <xlat_tables_v2.h>
18 #include "rpi3_private.h"
20 #define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \
22 MT_DEVICE | MT_RW | MT_SECURE)
24 #define MAP_SHARED_RAM MAP_REGION_FLAT(SHARED_RAM_BASE, \
26 MT_DEVICE | MT_RW | MT_SECURE)
28 #ifdef RPI3_PRELOADED_DTB_BASE
29 #define MAP_NS_DTB MAP_REGION_FLAT(RPI3_PRELOADED_DTB_BASE, 0x10000, \
30 MT_MEMORY | MT_RW | MT_NS)
33 #define MAP_NS_DRAM0 MAP_REGION_FLAT(NS_DRAM0_BASE, NS_DRAM0_SIZE, \
34 MT_MEMORY | MT_RW | MT_NS)
36 #define MAP_FIP MAP_REGION_FLAT(PLAT_RPI3_FIP_BASE, \
37 PLAT_RPI3_FIP_MAX_SIZE, \
38 MT_MEMORY | MT_RO | MT_NS)
40 #define MAP_BL32_MEM MAP_REGION_FLAT(BL32_MEM_BASE, BL32_MEM_SIZE, \
41 MT_MEMORY | MT_RW | MT_SECURE)
44 #define MAP_OPTEE_PAGEABLE MAP_REGION_FLAT( \
45 RPI3_OPTEE_PAGEABLE_LOAD_BASE, \
46 RPI3_OPTEE_PAGEABLE_LOAD_SIZE, \
47 MT_MEMORY | MT_RW | MT_SECURE)
51 * Table of regions for various BL stages to map using the MMU.
54 static const mmap_region_t plat_rpi3_mmap
[] = {
66 static const mmap_region_t plat_rpi3_mmap
[] = {
79 static const mmap_region_t plat_rpi3_mmap
[] = {
82 #ifdef RPI3_PRELOADED_DTB_BASE
92 /*******************************************************************************
93 * Function that sets up the console
94 ******************************************************************************/
95 static console_16550_t rpi3_console
;
97 void rpi3_console_init(void)
99 int console_scope
= CONSOLE_FLAG_BOOT
;
100 #if RPI3_RUNTIME_UART != -1
101 console_scope
|= CONSOLE_FLAG_RUNTIME
;
103 int rc
= console_16550_register(PLAT_RPI3_UART_BASE
,
104 PLAT_RPI3_UART_CLK_IN_HZ
,
105 PLAT_RPI3_UART_BAUDRATE
,
109 * The crash console doesn't use the multi console API, it uses
110 * the core console functions directly. It is safe to call panic
111 * and let it print debug information.
116 console_set_scope(&rpi3_console
.console
, console_scope
);
119 /*******************************************************************************
120 * Function that sets up the translation tables.
121 ******************************************************************************/
122 void rpi3_setup_page_tables(uintptr_t total_base
, size_t total_size
,
123 uintptr_t code_start
, uintptr_t code_limit
,
124 uintptr_t rodata_start
, uintptr_t rodata_limit
126 , uintptr_t coh_start
, uintptr_t coh_limit
131 * Map the Trusted SRAM with appropriate memory attributes.
132 * Subsequent mappings will adjust the attributes for specific regions.
134 VERBOSE("Trusted SRAM seen by this BL image: %p - %p\n",
135 (void *) total_base
, (void *) (total_base
+ total_size
));
136 mmap_add_region(total_base
, total_base
,
138 MT_MEMORY
| MT_RW
| MT_SECURE
);
140 /* Re-map the code section */
141 VERBOSE("Code region: %p - %p\n",
142 (void *) code_start
, (void *) code_limit
);
143 mmap_add_region(code_start
, code_start
,
144 code_limit
- code_start
,
145 MT_CODE
| MT_SECURE
);
147 /* Re-map the read-only data section */
148 VERBOSE("Read-only data region: %p - %p\n",
149 (void *) rodata_start
, (void *) rodata_limit
);
150 mmap_add_region(rodata_start
, rodata_start
,
151 rodata_limit
- rodata_start
,
152 MT_RO_DATA
| MT_SECURE
);
155 /* Re-map the coherent memory region */
156 VERBOSE("Coherent region: %p - %p\n",
157 (void *) coh_start
, (void *) coh_limit
);
158 mmap_add_region(coh_start
, coh_start
,
159 coh_limit
- coh_start
,
160 MT_DEVICE
| MT_RW
| MT_SECURE
);
163 mmap_add(plat_rpi3_mmap
);
168 /*******************************************************************************
169 * Return entrypoint of BL33.
170 ******************************************************************************/
171 uintptr_t plat_get_ns_image_entrypoint(void)
173 #ifdef PRELOADED_BL33_BASE
174 return PRELOADED_BL33_BASE
;
176 return PLAT_RPI3_NS_IMAGE_OFFSET
;
180 /*******************************************************************************
181 * Gets SPSR for BL32 entry
182 ******************************************************************************/
183 uint32_t rpi3_get_spsr_for_bl32_entry(void)
186 * The Secure Payload Dispatcher service is responsible for
187 * setting the SPSR prior to entry into the BL32 image.
192 /*******************************************************************************
193 * Gets SPSR for BL33 entry
194 ******************************************************************************/
195 uint32_t rpi3_get_spsr_for_bl33_entry(void)
197 #if RPI3_BL33_IN_AARCH32
198 INFO("BL33 will boot in Non-secure AArch32 Hypervisor mode\n");
199 return SPSR_MODE32(MODE32_hyp
, SPSR_T_ARM
, SPSR_E_LITTLE
,
200 DISABLE_ALL_EXCEPTIONS
);
202 return SPSR_64(MODE_EL2
, MODE_SP_ELX
, DISABLE_ALL_EXCEPTIONS
);
206 unsigned int plat_get_syscnt_freq2(void)
208 return SYS_COUNTER_FREQ_IN_TICKS
;
211 uint32_t plat_ic_get_pending_interrupt_type(void)
213 ERROR("rpi3: Interrupt routed to EL3.\n");
214 return INTR_TYPE_INVAL
;
217 uint32_t plat_interrupt_type_to_line(uint32_t type
, uint32_t security_state
)
219 assert((type
== INTR_TYPE_S_EL1
) || (type
== INTR_TYPE_EL3
) ||
220 (type
== INTR_TYPE_NS
));
222 assert(sec_state_is_valid(security_state
));
224 /* Non-secure interrupts are signalled on the IRQ line always. */
225 if (type
== INTR_TYPE_NS
)
226 return __builtin_ctz(SCR_IRQ_BIT
);
228 /* Secure interrupts are signalled on the FIQ line always. */
229 return __builtin_ctz(SCR_FIQ_BIT
);