blob: 97dce09134940c036eb4b95dcd9c29f5e4b518f1 [file] [log] [blame]
Antonio Nino Diazae6779e2017-11-06 14:49:04 +00001/*
2 * Copyright (c) 2015-2017, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch_helpers.h>
8#include <bl_common.h>
9#include <debug.h>
10#include <interrupt_mgmt.h>
11#include <platform_def.h>
12#include <xlat_tables_v2.h>
13
14#include "rpi3_hw.h"
15#include "rpi3_private.h"
16
17#define MAP_DEVICE0 MAP_REGION_FLAT(DEVICE0_BASE, \
18 DEVICE0_SIZE, \
19 MT_DEVICE | MT_RW | MT_SECURE)
20
21#define MAP_SHARED_RAM MAP_REGION_FLAT(SHARED_RAM_BASE, \
22 SHARED_RAM_SIZE, \
23 MT_DEVICE | MT_RW | MT_SECURE)
24
25#define MAP_NS_DRAM0 MAP_REGION_FLAT(NS_DRAM0_BASE, NS_DRAM0_SIZE, \
26 MT_MEMORY | MT_RW | MT_NS)
27
28#define MAP_FIP MAP_REGION_FLAT(PLAT_RPI3_FIP_BASE, \
29 PLAT_RPI3_FIP_MAX_SIZE, \
30 MT_MEMORY | MT_RO | MT_NS)
31
32#define MAP_BL32_MEM MAP_REGION_FLAT(BL32_MEM_BASE, BL32_MEM_SIZE, \
33 MT_MEMORY | MT_RW | MT_SECURE)
34
35/*
36 * Table of regions for various BL stages to map using the MMU.
37 */
38#ifdef IMAGE_BL1
39static const mmap_region_t plat_rpi3_mmap[] = {
40 MAP_SHARED_RAM,
41 MAP_DEVICE0,
42 MAP_FIP,
43 {0}
44};
45#endif
46
47#ifdef IMAGE_BL2
48static const mmap_region_t plat_rpi3_mmap[] = {
49 MAP_SHARED_RAM,
50 MAP_DEVICE0,
51 MAP_FIP,
52 MAP_NS_DRAM0,
53#ifdef BL32_BASE
54 MAP_BL32_MEM,
55#endif
56 {0}
57};
58#endif
59
60#ifdef IMAGE_BL31
61static const mmap_region_t plat_rpi3_mmap[] = {
62 MAP_SHARED_RAM,
63 MAP_DEVICE0,
64#ifdef BL32_BASE
65 MAP_BL32_MEM,
66#endif
67 {0}
68};
69#endif
70
71/*******************************************************************************
72 * Function that sets up the translation tables.
73 ******************************************************************************/
74void rpi3_setup_page_tables(uintptr_t total_base, size_t total_size,
75 uintptr_t code_start, uintptr_t code_limit,
76 uintptr_t rodata_start, uintptr_t rodata_limit
77#if USE_COHERENT_MEM
78 , uintptr_t coh_start, uintptr_t coh_limit
79#endif
80 )
81{
82 /*
83 * Map the Trusted SRAM with appropriate memory attributes.
84 * Subsequent mappings will adjust the attributes for specific regions.
85 */
86 VERBOSE("Trusted SRAM seen by this BL image: %p - %p\n",
87 (void *) total_base, (void *) (total_base + total_size));
88 mmap_add_region(total_base, total_base,
89 total_size,
90 MT_MEMORY | MT_RW | MT_SECURE);
91
92 /* Re-map the code section */
93 VERBOSE("Code region: %p - %p\n",
94 (void *) code_start, (void *) code_limit);
95 mmap_add_region(code_start, code_start,
96 code_limit - code_start,
97 MT_CODE | MT_SECURE);
98
99 /* Re-map the read-only data section */
100 VERBOSE("Read-only data region: %p - %p\n",
101 (void *) rodata_start, (void *) rodata_limit);
102 mmap_add_region(rodata_start, rodata_start,
103 rodata_limit - rodata_start,
104 MT_RO_DATA | MT_SECURE);
105
106#if USE_COHERENT_MEM
107 /* Re-map the coherent memory region */
108 VERBOSE("Coherent region: %p - %p\n",
109 (void *) coh_start, (void *) coh_limit);
110 mmap_add_region(coh_start, coh_start,
111 coh_limit - coh_start,
112 MT_DEVICE | MT_RW | MT_SECURE);
113#endif
114
115 mmap_add(plat_rpi3_mmap);
116
117 init_xlat_tables();
118}
119
120/*******************************************************************************
121 * Return entrypoint of BL33.
122 ******************************************************************************/
123uintptr_t plat_get_ns_image_entrypoint(void)
124{
125#ifdef PRELOADED_BL33_BASE
126 return PRELOADED_BL33_BASE;
127#else
128 return PLAT_RPI3_NS_IMAGE_OFFSET;
129#endif
130}
131
132/*******************************************************************************
133 * Gets SPSR for BL32 entry
134 ******************************************************************************/
135uint32_t rpi3_get_spsr_for_bl32_entry(void)
136{
137 /*
138 * The Secure Payload Dispatcher service is responsible for
139 * setting the SPSR prior to entry into the BL32 image.
140 */
141 return 0;
142}
143
144/*******************************************************************************
145 * Gets SPSR for BL33 entry
146 ******************************************************************************/
147uint32_t rpi3_get_spsr_for_bl33_entry(void)
148{
149#if RPI3_BL33_IN_AARCH32
150 INFO("BL33 will boot in Non-secure AArch32 Hypervisor mode\n");
151 return SPSR_MODE32(MODE32_hyp, SPSR_T_ARM, SPSR_E_LITTLE,
152 DISABLE_ALL_EXCEPTIONS);
153#else
154 return SPSR_64(MODE_EL2, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
155#endif
156}
157
158unsigned int plat_get_syscnt_freq2(void)
159{
160 return SYS_COUNTER_FREQ_IN_TICKS;
161}
162
163uint32_t plat_ic_get_pending_interrupt_type(void)
164{
165 return INTR_TYPE_INVAL;
166}