blob: 18ff1c82ebe7f7d9777d5dc9732c679157afda7f [file] [log] [blame]
Antonio Nino Diazae6779e2017-11-06 14:49:04 +00001/*
Antonio Nino Diaz1f470022018-03-27 09:39:47 +01002 * Copyright (c) 2015-2018, 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
7#include <arch_helpers.h>
Antonio Nino Diaz9abd78d2018-07-11 21:00:32 +01008#include <assert.h>
Antonio Nino Diazae6779e2017-11-06 14:49:04 +00009#include <bl_common.h>
Antonio Nino Diaz1f470022018-03-27 09:39:47 +010010#include <console.h>
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000011#include <debug.h>
12#include <interrupt_mgmt.h>
13#include <platform_def.h>
Antonio Nino Diaz1f470022018-03-27 09:39:47 +010014#include <uart_16550.h>
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000015#include <xlat_tables_v2.h>
16
17#include "rpi3_hw.h"
18#include "rpi3_private.h"
19
20#define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \
21 DEVICE0_SIZE, \
22 MT_DEVICE | MT_RW | MT_SECURE)
23
24#define MAP_SHARED_RAM MAP_REGION_FLAT(SHARED_RAM_BASE, \
25 SHARED_RAM_SIZE, \
Antonio Nino Diazf96582a2018-10-19 00:57:16 +010026 MT_DEVICE | MT_RW | MT_SECURE)
27
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)
31#endif
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000032
33#define MAP_NS_DRAM0 MAP_REGION_FLAT(NS_DRAM0_BASE, NS_DRAM0_SIZE, \
34 MT_MEMORY | MT_RW | MT_NS)
35
36#define MAP_FIP MAP_REGION_FLAT(PLAT_RPI3_FIP_BASE, \
37 PLAT_RPI3_FIP_MAX_SIZE, \
38 MT_MEMORY | MT_RO | MT_NS)
39
40#define MAP_BL32_MEM MAP_REGION_FLAT(BL32_MEM_BASE, BL32_MEM_SIZE, \
41 MT_MEMORY | MT_RW | MT_SECURE)
42
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +080043#ifdef SPD_opteed
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)
48#endif
49
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000050/*
51 * Table of regions for various BL stages to map using the MMU.
52 */
53#ifdef IMAGE_BL1
54static const mmap_region_t plat_rpi3_mmap[] = {
55 MAP_SHARED_RAM,
56 MAP_DEVICE0,
57 MAP_FIP,
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +080058#ifdef SPD_opteed
59 MAP_OPTEE_PAGEABLE,
60#endif
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000061 {0}
62};
63#endif
64
65#ifdef IMAGE_BL2
66static const mmap_region_t plat_rpi3_mmap[] = {
67 MAP_SHARED_RAM,
68 MAP_DEVICE0,
69 MAP_FIP,
70 MAP_NS_DRAM0,
71#ifdef BL32_BASE
72 MAP_BL32_MEM,
73#endif
74 {0}
75};
76#endif
77
78#ifdef IMAGE_BL31
79static const mmap_region_t plat_rpi3_mmap[] = {
80 MAP_SHARED_RAM,
81 MAP_DEVICE0,
Antonio Nino Diazf96582a2018-10-19 00:57:16 +010082#ifdef RPI3_PRELOADED_DTB_BASE
83 MAP_NS_DTB,
84#endif
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000085#ifdef BL32_BASE
86 MAP_BL32_MEM,
87#endif
88 {0}
89};
90#endif
91
92/*******************************************************************************
Antonio Nino Diaz1f470022018-03-27 09:39:47 +010093 * Function that sets up the console
94 ******************************************************************************/
95static console_16550_t rpi3_console;
96
97void rpi3_console_init(void)
98{
99 int rc = console_16550_register(PLAT_RPI3_UART_BASE,
100 PLAT_RPI3_UART_CLK_IN_HZ,
101 PLAT_RPI3_UART_BAUDRATE,
102 &rpi3_console);
103 if (rc == 0) {
104 /*
105 * The crash console doesn't use the multi console API, it uses
106 * the core console functions directly. It is safe to call panic
107 * and let it print debug information.
108 */
109 panic();
110 }
111
112 console_set_scope(&rpi3_console.console,
113 CONSOLE_FLAG_BOOT | CONSOLE_FLAG_RUNTIME);
114}
115
116/*******************************************************************************
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000117 * Function that sets up the translation tables.
118 ******************************************************************************/
119void rpi3_setup_page_tables(uintptr_t total_base, size_t total_size,
120 uintptr_t code_start, uintptr_t code_limit,
121 uintptr_t rodata_start, uintptr_t rodata_limit
122#if USE_COHERENT_MEM
123 , uintptr_t coh_start, uintptr_t coh_limit
124#endif
125 )
126{
127 /*
128 * Map the Trusted SRAM with appropriate memory attributes.
129 * Subsequent mappings will adjust the attributes for specific regions.
130 */
131 VERBOSE("Trusted SRAM seen by this BL image: %p - %p\n",
132 (void *) total_base, (void *) (total_base + total_size));
133 mmap_add_region(total_base, total_base,
134 total_size,
135 MT_MEMORY | MT_RW | MT_SECURE);
136
137 /* Re-map the code section */
138 VERBOSE("Code region: %p - %p\n",
139 (void *) code_start, (void *) code_limit);
140 mmap_add_region(code_start, code_start,
141 code_limit - code_start,
142 MT_CODE | MT_SECURE);
143
144 /* Re-map the read-only data section */
145 VERBOSE("Read-only data region: %p - %p\n",
146 (void *) rodata_start, (void *) rodata_limit);
147 mmap_add_region(rodata_start, rodata_start,
148 rodata_limit - rodata_start,
149 MT_RO_DATA | MT_SECURE);
150
151#if USE_COHERENT_MEM
152 /* Re-map the coherent memory region */
153 VERBOSE("Coherent region: %p - %p\n",
154 (void *) coh_start, (void *) coh_limit);
155 mmap_add_region(coh_start, coh_start,
156 coh_limit - coh_start,
157 MT_DEVICE | MT_RW | MT_SECURE);
158#endif
159
160 mmap_add(plat_rpi3_mmap);
161
162 init_xlat_tables();
163}
164
165/*******************************************************************************
166 * Return entrypoint of BL33.
167 ******************************************************************************/
168uintptr_t plat_get_ns_image_entrypoint(void)
169{
170#ifdef PRELOADED_BL33_BASE
171 return PRELOADED_BL33_BASE;
172#else
173 return PLAT_RPI3_NS_IMAGE_OFFSET;
174#endif
175}
176
177/*******************************************************************************
178 * Gets SPSR for BL32 entry
179 ******************************************************************************/
180uint32_t rpi3_get_spsr_for_bl32_entry(void)
181{
182 /*
183 * The Secure Payload Dispatcher service is responsible for
184 * setting the SPSR prior to entry into the BL32 image.
185 */
186 return 0;
187}
188
189/*******************************************************************************
190 * Gets SPSR for BL33 entry
191 ******************************************************************************/
192uint32_t rpi3_get_spsr_for_bl33_entry(void)
193{
194#if RPI3_BL33_IN_AARCH32
195 INFO("BL33 will boot in Non-secure AArch32 Hypervisor mode\n");
196 return SPSR_MODE32(MODE32_hyp, SPSR_T_ARM, SPSR_E_LITTLE,
197 DISABLE_ALL_EXCEPTIONS);
198#else
199 return SPSR_64(MODE_EL2, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
200#endif
201}
202
203unsigned int plat_get_syscnt_freq2(void)
204{
205 return SYS_COUNTER_FREQ_IN_TICKS;
206}
207
208uint32_t plat_ic_get_pending_interrupt_type(void)
209{
Antonio Nino Diaz9abd78d2018-07-11 21:00:32 +0100210 ERROR("rpi3: Interrupt routed to EL3.\n");
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000211 return INTR_TYPE_INVAL;
212}
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +0800213
Antonio Nino Diaz9abd78d2018-07-11 21:00:32 +0100214uint32_t plat_interrupt_type_to_line(uint32_t type, uint32_t security_state)
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +0800215{
Antonio Nino Diaz9abd78d2018-07-11 21:00:32 +0100216 assert((type == INTR_TYPE_S_EL1) || (type == INTR_TYPE_EL3) ||
217 (type == INTR_TYPE_NS));
218
219 assert(sec_state_is_valid(security_state));
220
221 /* Non-secure interrupts are signalled on the IRQ line always. */
222 if (type == INTR_TYPE_NS)
223 return __builtin_ctz(SCR_IRQ_BIT);
224
225 /* Secure interrupts are signalled on the FIQ line always. */
226 return __builtin_ctz(SCR_FIQ_BIT);
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +0800227}