blob: 03914a6d746125f0b67f6624f620c0c49e67f863 [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
37/*
38 * Table of regions for various BL stages to map using the MMU.
39 */
40#ifdef IMAGE_BL1
41static const mmap_region_t plat_rpi3_mmap[] = {
42 MAP_SHARED_RAM,
43 MAP_DEVICE0,
44 MAP_FIP,
45 {0}
46};
47#endif
48
49#ifdef IMAGE_BL2
50static const mmap_region_t plat_rpi3_mmap[] = {
51 MAP_SHARED_RAM,
52 MAP_DEVICE0,
53 MAP_FIP,
54 MAP_NS_DRAM0,
55#ifdef BL32_BASE
56 MAP_BL32_MEM,
57#endif
58 {0}
59};
60#endif
61
62#ifdef IMAGE_BL31
63static const mmap_region_t plat_rpi3_mmap[] = {
64 MAP_SHARED_RAM,
65 MAP_DEVICE0,
66#ifdef BL32_BASE
67 MAP_BL32_MEM,
68#endif
69 {0}
70};
71#endif
72
73/*******************************************************************************
Antonio Nino Diaz1f470022018-03-27 09:39:47 +010074 * Function that sets up the console
75 ******************************************************************************/
76static console_16550_t rpi3_console;
77
78void rpi3_console_init(void)
79{
80 int rc = console_16550_register(PLAT_RPI3_UART_BASE,
81 PLAT_RPI3_UART_CLK_IN_HZ,
82 PLAT_RPI3_UART_BAUDRATE,
83 &rpi3_console);
84 if (rc == 0) {
85 /*
86 * The crash console doesn't use the multi console API, it uses
87 * the core console functions directly. It is safe to call panic
88 * and let it print debug information.
89 */
90 panic();
91 }
92
93 console_set_scope(&rpi3_console.console,
94 CONSOLE_FLAG_BOOT | CONSOLE_FLAG_RUNTIME);
95}
96
97/*******************************************************************************
Antonio Nino Diazae6779e2017-11-06 14:49:04 +000098 * Function that sets up the translation tables.
99 ******************************************************************************/
100void rpi3_setup_page_tables(uintptr_t total_base, size_t total_size,
101 uintptr_t code_start, uintptr_t code_limit,
102 uintptr_t rodata_start, uintptr_t rodata_limit
103#if USE_COHERENT_MEM
104 , uintptr_t coh_start, uintptr_t coh_limit
105#endif
106 )
107{
108 /*
109 * Map the Trusted SRAM with appropriate memory attributes.
110 * Subsequent mappings will adjust the attributes for specific regions.
111 */
112 VERBOSE("Trusted SRAM seen by this BL image: %p - %p\n",
113 (void *) total_base, (void *) (total_base + total_size));
114 mmap_add_region(total_base, total_base,
115 total_size,
116 MT_MEMORY | MT_RW | MT_SECURE);
117
118 /* Re-map the code section */
119 VERBOSE("Code region: %p - %p\n",
120 (void *) code_start, (void *) code_limit);
121 mmap_add_region(code_start, code_start,
122 code_limit - code_start,
123 MT_CODE | MT_SECURE);
124
125 /* Re-map the read-only data section */
126 VERBOSE("Read-only data region: %p - %p\n",
127 (void *) rodata_start, (void *) rodata_limit);
128 mmap_add_region(rodata_start, rodata_start,
129 rodata_limit - rodata_start,
130 MT_RO_DATA | MT_SECURE);
131
132#if USE_COHERENT_MEM
133 /* Re-map the coherent memory region */
134 VERBOSE("Coherent region: %p - %p\n",
135 (void *) coh_start, (void *) coh_limit);
136 mmap_add_region(coh_start, coh_start,
137 coh_limit - coh_start,
138 MT_DEVICE | MT_RW | MT_SECURE);
139#endif
140
141 mmap_add(plat_rpi3_mmap);
142
143 init_xlat_tables();
144}
145
146/*******************************************************************************
147 * Return entrypoint of BL33.
148 ******************************************************************************/
149uintptr_t plat_get_ns_image_entrypoint(void)
150{
151#ifdef PRELOADED_BL33_BASE
152 return PRELOADED_BL33_BASE;
153#else
154 return PLAT_RPI3_NS_IMAGE_OFFSET;
155#endif
156}
157
158/*******************************************************************************
159 * Gets SPSR for BL32 entry
160 ******************************************************************************/
161uint32_t rpi3_get_spsr_for_bl32_entry(void)
162{
163 /*
164 * The Secure Payload Dispatcher service is responsible for
165 * setting the SPSR prior to entry into the BL32 image.
166 */
167 return 0;
168}
169
170/*******************************************************************************
171 * Gets SPSR for BL33 entry
172 ******************************************************************************/
173uint32_t rpi3_get_spsr_for_bl33_entry(void)
174{
175#if RPI3_BL33_IN_AARCH32
176 INFO("BL33 will boot in Non-secure AArch32 Hypervisor mode\n");
177 return SPSR_MODE32(MODE32_hyp, SPSR_T_ARM, SPSR_E_LITTLE,
178 DISABLE_ALL_EXCEPTIONS);
179#else
180 return SPSR_64(MODE_EL2, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
181#endif
182}
183
184unsigned int plat_get_syscnt_freq2(void)
185{
186 return SYS_COUNTER_FREQ_IN_TICKS;
187}
188
189uint32_t plat_ic_get_pending_interrupt_type(void)
190{
191 return INTR_TYPE_INVAL;
192}