blob: 98cf534c73766bb068c07b1800108ce4da1cbdd8 [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, \
26 MT_DEVICE | MT_RW | MT_SECURE)
27
28#define MAP_NS_DRAM0 MAP_REGION_FLAT(NS_DRAM0_BASE, NS_DRAM0_SIZE, \
29 MT_MEMORY | MT_RW | MT_NS)
30
31#define MAP_FIP MAP_REGION_FLAT(PLAT_RPI3_FIP_BASE, \
32 PLAT_RPI3_FIP_MAX_SIZE, \
33 MT_MEMORY | MT_RO | MT_NS)
34
35#define MAP_BL32_MEM MAP_REGION_FLAT(BL32_MEM_BASE, BL32_MEM_SIZE, \
36 MT_MEMORY | MT_RW | MT_SECURE)
37
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +080038#ifdef SPD_opteed
39#define MAP_OPTEE_PAGEABLE MAP_REGION_FLAT( \
40 RPI3_OPTEE_PAGEABLE_LOAD_BASE, \
41 RPI3_OPTEE_PAGEABLE_LOAD_SIZE, \
42 MT_MEMORY | MT_RW | MT_SECURE)
43#endif
44
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000045/*
46 * Table of regions for various BL stages to map using the MMU.
47 */
48#ifdef IMAGE_BL1
49static const mmap_region_t plat_rpi3_mmap[] = {
50 MAP_SHARED_RAM,
51 MAP_DEVICE0,
52 MAP_FIP,
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +080053#ifdef SPD_opteed
54 MAP_OPTEE_PAGEABLE,
55#endif
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000056 {0}
57};
58#endif
59
60#ifdef IMAGE_BL2
61static const mmap_region_t plat_rpi3_mmap[] = {
62 MAP_SHARED_RAM,
63 MAP_DEVICE0,
64 MAP_FIP,
65 MAP_NS_DRAM0,
66#ifdef BL32_BASE
67 MAP_BL32_MEM,
68#endif
69 {0}
70};
71#endif
72
73#ifdef IMAGE_BL31
74static const mmap_region_t plat_rpi3_mmap[] = {
75 MAP_SHARED_RAM,
76 MAP_DEVICE0,
77#ifdef BL32_BASE
78 MAP_BL32_MEM,
79#endif
80 {0}
81};
82#endif
83
84/*******************************************************************************
Antonio Nino Diaz1f470022018-03-27 09:39:47 +010085 * Function that sets up the console
86 ******************************************************************************/
87static console_16550_t rpi3_console;
88
89void rpi3_console_init(void)
90{
91 int rc = console_16550_register(PLAT_RPI3_UART_BASE,
92 PLAT_RPI3_UART_CLK_IN_HZ,
93 PLAT_RPI3_UART_BAUDRATE,
94 &rpi3_console);
95 if (rc == 0) {
96 /*
97 * The crash console doesn't use the multi console API, it uses
98 * the core console functions directly. It is safe to call panic
99 * and let it print debug information.
100 */
101 panic();
102 }
103
104 console_set_scope(&rpi3_console.console,
105 CONSOLE_FLAG_BOOT | CONSOLE_FLAG_RUNTIME);
106}
107
108/*******************************************************************************
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000109 * Function that sets up the translation tables.
110 ******************************************************************************/
111void rpi3_setup_page_tables(uintptr_t total_base, size_t total_size,
112 uintptr_t code_start, uintptr_t code_limit,
113 uintptr_t rodata_start, uintptr_t rodata_limit
114#if USE_COHERENT_MEM
115 , uintptr_t coh_start, uintptr_t coh_limit
116#endif
117 )
118{
119 /*
120 * Map the Trusted SRAM with appropriate memory attributes.
121 * Subsequent mappings will adjust the attributes for specific regions.
122 */
123 VERBOSE("Trusted SRAM seen by this BL image: %p - %p\n",
124 (void *) total_base, (void *) (total_base + total_size));
125 mmap_add_region(total_base, total_base,
126 total_size,
127 MT_MEMORY | MT_RW | MT_SECURE);
128
129 /* Re-map the code section */
130 VERBOSE("Code region: %p - %p\n",
131 (void *) code_start, (void *) code_limit);
132 mmap_add_region(code_start, code_start,
133 code_limit - code_start,
134 MT_CODE | MT_SECURE);
135
136 /* Re-map the read-only data section */
137 VERBOSE("Read-only data region: %p - %p\n",
138 (void *) rodata_start, (void *) rodata_limit);
139 mmap_add_region(rodata_start, rodata_start,
140 rodata_limit - rodata_start,
141 MT_RO_DATA | MT_SECURE);
142
143#if USE_COHERENT_MEM
144 /* Re-map the coherent memory region */
145 VERBOSE("Coherent region: %p - %p\n",
146 (void *) coh_start, (void *) coh_limit);
147 mmap_add_region(coh_start, coh_start,
148 coh_limit - coh_start,
149 MT_DEVICE | MT_RW | MT_SECURE);
150#endif
151
152 mmap_add(plat_rpi3_mmap);
153
154 init_xlat_tables();
155}
156
157/*******************************************************************************
158 * Return entrypoint of BL33.
159 ******************************************************************************/
160uintptr_t plat_get_ns_image_entrypoint(void)
161{
162#ifdef PRELOADED_BL33_BASE
163 return PRELOADED_BL33_BASE;
164#else
165 return PLAT_RPI3_NS_IMAGE_OFFSET;
166#endif
167}
168
169/*******************************************************************************
170 * Gets SPSR for BL32 entry
171 ******************************************************************************/
172uint32_t rpi3_get_spsr_for_bl32_entry(void)
173{
174 /*
175 * The Secure Payload Dispatcher service is responsible for
176 * setting the SPSR prior to entry into the BL32 image.
177 */
178 return 0;
179}
180
181/*******************************************************************************
182 * Gets SPSR for BL33 entry
183 ******************************************************************************/
184uint32_t rpi3_get_spsr_for_bl33_entry(void)
185{
186#if RPI3_BL33_IN_AARCH32
187 INFO("BL33 will boot in Non-secure AArch32 Hypervisor mode\n");
188 return SPSR_MODE32(MODE32_hyp, SPSR_T_ARM, SPSR_E_LITTLE,
189 DISABLE_ALL_EXCEPTIONS);
190#else
191 return SPSR_64(MODE_EL2, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
192#endif
193}
194
195unsigned int plat_get_syscnt_freq2(void)
196{
197 return SYS_COUNTER_FREQ_IN_TICKS;
198}
199
200uint32_t plat_ic_get_pending_interrupt_type(void)
201{
Antonio Nino Diaz9abd78d2018-07-11 21:00:32 +0100202 ERROR("rpi3: Interrupt routed to EL3.\n");
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000203 return INTR_TYPE_INVAL;
204}
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +0800205
Antonio Nino Diaz9abd78d2018-07-11 21:00:32 +0100206uint32_t plat_interrupt_type_to_line(uint32_t type, uint32_t security_state)
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +0800207{
Antonio Nino Diaz9abd78d2018-07-11 21:00:32 +0100208 assert((type == INTR_TYPE_S_EL1) || (type == INTR_TYPE_EL3) ||
209 (type == INTR_TYPE_NS));
210
211 assert(sec_state_is_valid(security_state));
212
213 /* Non-secure interrupts are signalled on the IRQ line always. */
214 if (type == INTR_TYPE_NS)
215 return __builtin_ctz(SCR_IRQ_BIT);
216
217 /* Secure interrupts are signalled on the FIQ line always. */
218 return __builtin_ctz(SCR_FIQ_BIT);
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +0800219}