blob: 39133564353829d9310d7cb852c43222fab6633b [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 <assert.h>
8#include <bl_common.h>
9#include <console.h>
10#include <platform.h>
11#include <platform_def.h>
12#include <xlat_mmu_helpers.h>
13#include <xlat_tables_defs.h>
14
15#include "rpi3_private.h"
16
17#define BL31_END (uintptr_t)(&__BL31_END__)
18
19/*
20 * Placeholder variables for copying the arguments that have been passed to
21 * BL31 from BL2.
22 */
23static entry_point_info_t bl32_image_ep_info;
24static entry_point_info_t bl33_image_ep_info;
25
26/*******************************************************************************
27 * Return a pointer to the 'entry_point_info' structure of the next image for
28 * the security state specified. BL33 corresponds to the non-secure image type
29 * while BL32 corresponds to the secure image type. A NULL pointer is returned
30 * if the image does not exist.
31 ******************************************************************************/
32entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
33{
34 entry_point_info_t *next_image_info;
35
36 assert(sec_state_is_valid(type) != 0);
37
38 next_image_info = (type == NON_SECURE)
39 ? &bl33_image_ep_info : &bl32_image_ep_info;
40
41 /* None of the images can have 0x0 as the entrypoint. */
42 if (next_image_info->pc) {
43 return next_image_info;
44 } else {
45 return NULL;
46 }
47}
48
49/*******************************************************************************
50 * Perform any BL31 early platform setup. Here is an opportunity to copy
51 * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before
52 * they are lost (potentially). This needs to be done before the MMU is
53 * initialized so that the memory layout can be used while creating page
54 * tables. BL2 has flushed this information to memory, so we are guaranteed
55 * to pick up good data.
56 ******************************************************************************/
57void bl31_early_platform_setup(void *from_bl2,
58 void *plat_params_from_bl2)
59{
60 /* Initialize the console to provide early debug support */
61 console_init(PLAT_RPI3_UART_BASE, PLAT_RPI3_UART_CLK_IN_HZ,
62 PLAT_RPI3_UART_BAUDRATE);
63
64#if RESET_TO_BL31
65
66 /* There are no parameters from BL2 if BL31 is a reset vector */
67 assert(from_bl2 == NULL);
68 assert(plat_params_from_bl2 == NULL);
69
70#ifdef BL32_BASE
71 /* Populate entry point information for BL32 */
72 SET_PARAM_HEAD(&bl32_image_ep_info,
73 PARAM_EP,
74 VERSION_1,
75 0);
76 SET_SECURITY_STATE(bl32_image_ep_info.h.attr, SECURE);
77 bl32_image_ep_info.pc = BL32_BASE;
78 bl32_image_ep_info.spsr = rpi3_get_spsr_for_bl32_entry();
79#endif /* BL32_BASE */
80
81 /* Populate entry point information for BL33 */
82 SET_PARAM_HEAD(&bl33_image_ep_info,
83 PARAM_EP,
84 VERSION_1,
85 0);
86 /*
87 * Tell BL31 where the non-trusted software image
88 * is located and the entry state information
89 */
90 bl33_image_ep_info.pc = plat_get_ns_image_entrypoint();
91
92 bl33_image_ep_info.spsr = rpi3_get_spsr_for_bl33_entry();
93 SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE);
94
95#else /* RESET_TO_BL31 */
96
97 /*
98 * In debug builds, we pass a special value in 'plat_params_from_bl2'
99 * to verify platform parameters from BL2 to BL31.
100 * In release builds, it's not used.
101 */
102 assert(((uintptr_t)plat_params_from_bl2) == RPI3_BL31_PLAT_PARAM_VAL);
103
104 /*
105 * Check params passed from BL2 should not be NULL,
106 */
107 bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
108
109 assert(params_from_bl2 != NULL);
110 assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
111 assert(params_from_bl2->h.version >= VERSION_2);
112
113 bl_params_node_t *bl_params = params_from_bl2->head;
114
115 /*
116 * Copy BL33 and BL32 (if present), entry point information.
117 * They are stored in Secure RAM, in BL2's address space.
118 */
119 while (bl_params) {
120 if (bl_params->image_id == BL32_IMAGE_ID) {
121 bl32_image_ep_info = *bl_params->ep_info;
122 }
123
124 if (bl_params->image_id == BL33_IMAGE_ID) {
125 bl33_image_ep_info = *bl_params->ep_info;
126 }
127
128 bl_params = bl_params->next_params_info;
129 }
130
131 if (bl33_image_ep_info.pc == 0) {
132 panic();
133 }
134
135#endif /* RESET_TO_BL31 */
136}
137
138void bl31_plat_arch_setup(void)
139{
140 rpi3_setup_page_tables(BL31_BASE, BL31_END - BL31_BASE,
141 BL_CODE_BASE, BL_CODE_END,
142 BL_RO_DATA_BASE, BL_RO_DATA_END
143#if USE_COHERENT_MEM
144 , BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END
145#endif
146 );
147
148 enable_mmu_el3(0);
149}
150
151void bl31_platform_setup(void)
152{
153#if RESET_TO_BL31
154 /*
155 * Do initial security configuration to allow DRAM/device access
156 * (if earlier BL has not already done so).
157 */
158#endif /* RESET_TO_BL31 */
159
160 return;
161}
162
163void bl31_plat_runtime_setup(void)
164{
165 /* Initialize the runtime console */
166 console_init(PLAT_RPI3_UART_BASE, PLAT_RPI3_UART_CLK_IN_HZ,
167 PLAT_RPI3_UART_BAUDRATE);
168}