blob: 65f5e7ad00bb09ac357bbbf6cf87e208ed2e62f0 [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>
8#include <bl_common.h>
Antonio Nino Diaz1f470022018-03-27 09:39:47 +01009#include <console.h>
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000010#include <debug.h>
11#include <interrupt_mgmt.h>
12#include <platform_def.h>
Antonio Nino Diaz1f470022018-03-27 09:39:47 +010013#include <uart_16550.h>
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000014#include <xlat_tables_v2.h>
15
16#include "rpi3_hw.h"
17#include "rpi3_private.h"
18
19#define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \
20 DEVICE0_SIZE, \
21 MT_DEVICE | MT_RW | MT_SECURE)
22
23#define MAP_SHARED_RAM MAP_REGION_FLAT(SHARED_RAM_BASE, \
24 SHARED_RAM_SIZE, \
25 MT_DEVICE | MT_RW | MT_SECURE)
26
27#define MAP_NS_DRAM0 MAP_REGION_FLAT(NS_DRAM0_BASE, NS_DRAM0_SIZE, \
28 MT_MEMORY | MT_RW | MT_NS)
29
30#define MAP_FIP MAP_REGION_FLAT(PLAT_RPI3_FIP_BASE, \
31 PLAT_RPI3_FIP_MAX_SIZE, \
32 MT_MEMORY | MT_RO | MT_NS)
33
34#define MAP_BL32_MEM MAP_REGION_FLAT(BL32_MEM_BASE, BL32_MEM_SIZE, \
35 MT_MEMORY | MT_RW | MT_SECURE)
36
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +080037#ifdef SPD_opteed
38#define MAP_OPTEE_PAGEABLE MAP_REGION_FLAT( \
39 RPI3_OPTEE_PAGEABLE_LOAD_BASE, \
40 RPI3_OPTEE_PAGEABLE_LOAD_SIZE, \
41 MT_MEMORY | MT_RW | MT_SECURE)
42#endif
43
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000044/*
45 * Table of regions for various BL stages to map using the MMU.
46 */
47#ifdef IMAGE_BL1
48static const mmap_region_t plat_rpi3_mmap[] = {
49 MAP_SHARED_RAM,
50 MAP_DEVICE0,
51 MAP_FIP,
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +080052#ifdef SPD_opteed
53 MAP_OPTEE_PAGEABLE,
54#endif
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000055 {0}
56};
57#endif
58
59#ifdef IMAGE_BL2
60static const mmap_region_t plat_rpi3_mmap[] = {
61 MAP_SHARED_RAM,
62 MAP_DEVICE0,
63 MAP_FIP,
64 MAP_NS_DRAM0,
65#ifdef BL32_BASE
66 MAP_BL32_MEM,
67#endif
68 {0}
69};
70#endif
71
72#ifdef IMAGE_BL31
73static const mmap_region_t plat_rpi3_mmap[] = {
74 MAP_SHARED_RAM,
75 MAP_DEVICE0,
76#ifdef BL32_BASE
77 MAP_BL32_MEM,
78#endif
79 {0}
80};
81#endif
82
83/*******************************************************************************
Antonio Nino Diaz1f470022018-03-27 09:39:47 +010084 * Function that sets up the console
85 ******************************************************************************/
86static console_16550_t rpi3_console;
87
88void rpi3_console_init(void)
89{
90 int rc = console_16550_register(PLAT_RPI3_UART_BASE,
91 PLAT_RPI3_UART_CLK_IN_HZ,
92 PLAT_RPI3_UART_BAUDRATE,
93 &rpi3_console);
94 if (rc == 0) {
95 /*
96 * The crash console doesn't use the multi console API, it uses
97 * the core console functions directly. It is safe to call panic
98 * and let it print debug information.
99 */
100 panic();
101 }
102
103 console_set_scope(&rpi3_console.console,
104 CONSOLE_FLAG_BOOT | CONSOLE_FLAG_RUNTIME);
105}
106
107/*******************************************************************************
Antonio Nino Diazae6779e2017-11-06 14:49:04 +0000108 * Function that sets up the translation tables.
109 ******************************************************************************/
110void rpi3_setup_page_tables(uintptr_t total_base, size_t total_size,
111 uintptr_t code_start, uintptr_t code_limit,
112 uintptr_t rodata_start, uintptr_t rodata_limit
113#if USE_COHERENT_MEM
114 , uintptr_t coh_start, uintptr_t coh_limit
115#endif
116 )
117{
118 /*
119 * Map the Trusted SRAM with appropriate memory attributes.
120 * Subsequent mappings will adjust the attributes for specific regions.
121 */
122 VERBOSE("Trusted SRAM seen by this BL image: %p - %p\n",
123 (void *) total_base, (void *) (total_base + total_size));
124 mmap_add_region(total_base, total_base,
125 total_size,
126 MT_MEMORY | MT_RW | MT_SECURE);
127
128 /* Re-map the code section */
129 VERBOSE("Code region: %p - %p\n",
130 (void *) code_start, (void *) code_limit);
131 mmap_add_region(code_start, code_start,
132 code_limit - code_start,
133 MT_CODE | MT_SECURE);
134
135 /* Re-map the read-only data section */
136 VERBOSE("Read-only data region: %p - %p\n",
137 (void *) rodata_start, (void *) rodata_limit);
138 mmap_add_region(rodata_start, rodata_start,
139 rodata_limit - rodata_start,
140 MT_RO_DATA | MT_SECURE);
141
142#if USE_COHERENT_MEM
143 /* Re-map the coherent memory region */
144 VERBOSE("Coherent region: %p - %p\n",
145 (void *) coh_start, (void *) coh_limit);
146 mmap_add_region(coh_start, coh_start,
147 coh_limit - coh_start,
148 MT_DEVICE | MT_RW | MT_SECURE);
149#endif
150
151 mmap_add(plat_rpi3_mmap);
152
153 init_xlat_tables();
154}
155
156/*******************************************************************************
157 * Return entrypoint of BL33.
158 ******************************************************************************/
159uintptr_t plat_get_ns_image_entrypoint(void)
160{
161#ifdef PRELOADED_BL33_BASE
162 return PRELOADED_BL33_BASE;
163#else
164 return PLAT_RPI3_NS_IMAGE_OFFSET;
165#endif
166}
167
168/*******************************************************************************
169 * Gets SPSR for BL32 entry
170 ******************************************************************************/
171uint32_t rpi3_get_spsr_for_bl32_entry(void)
172{
173 /*
174 * The Secure Payload Dispatcher service is responsible for
175 * setting the SPSR prior to entry into the BL32 image.
176 */
177 return 0;
178}
179
180/*******************************************************************************
181 * Gets SPSR for BL33 entry
182 ******************************************************************************/
183uint32_t rpi3_get_spsr_for_bl33_entry(void)
184{
185#if RPI3_BL33_IN_AARCH32
186 INFO("BL33 will boot in Non-secure AArch32 Hypervisor mode\n");
187 return SPSR_MODE32(MODE32_hyp, SPSR_T_ARM, SPSR_E_LITTLE,
188 DISABLE_ALL_EXCEPTIONS);
189#else
190 return SPSR_64(MODE_EL2, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
191#endif
192}
193
194unsigned int plat_get_syscnt_freq2(void)
195{
196 return SYS_COUNTER_FREQ_IN_TICKS;
197}
198
199uint32_t plat_ic_get_pending_interrupt_type(void)
200{
201 return INTR_TYPE_INVAL;
202}
Ying-Chun Liu (PaulLiu)d9f76e62018-06-10 02:00:27 +0800203
204uint32_t plat_interrupt_type_to_line(uint32_t type,
205 uint32_t security_state)
206{
207 /* It is not expected to receive an interrupt route to EL3.
208 * Hence panic() to flag error.
209 */
210 ERROR("Interrupt not expected to be routed to EL3");
211 panic();
212}