blob: 25fe407c5e0fa30b116286710de57ee4be12ec3c [file] [log] [blame]
Jiafei Pan46367ad2018-03-02 07:23:30 +00001/*
2 * Copyright (c) 2018, ARM Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <assert.h>
Antonio Nino Diaze0b757d2018-08-24 16:30:29 +01008#include <bl_common.h>
Jiafei Pan46367ad2018-03-02 07:23:30 +00009#include <console.h>
10#include <mmio.h>
11#include <gicv2.h>
12#include "ls_16550.h"
13#include "plat_ls.h"
14#include "soc.h"
15
Jiafei Pan46367ad2018-03-02 07:23:30 +000016/*
17 * Placeholder variables for copying the arguments that have been passed to
18 * BL31 from BL2.
19 */
20static entry_point_info_t bl32_image_ep_info;
21static entry_point_info_t bl33_image_ep_info;
22
23const unsigned int g0_interrupt_array1[] = {
24 9
25};
26
27gicv2_driver_data_t ls_gic_data = {
28 .gicd_base = GICD_BASE,
29 .gicc_base = GICC_BASE,
30 .g0_interrupt_num = ARRAY_SIZE(g0_interrupt_array1),
31 .g0_interrupt_array = g0_interrupt_array1,
32};
33
34
35/*******************************************************************************
36 * Return a pointer to the 'entry_point_info' structure of the next image for the
37 * security state specified. BL33 corresponds to the non-secure image type
38 * while BL32 corresponds to the secure image type. A NULL pointer is returned
39 * if the image does not exist.
40 ******************************************************************************/
41entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
42{
43 entry_point_info_t *next_image_info;
44
45 assert(sec_state_is_valid(type));
46 next_image_info = (type == NON_SECURE)
47 ? &bl33_image_ep_info : &bl32_image_ep_info;
48
49 if (next_image_info->pc)
50 return next_image_info;
51 else
52 return NULL;
53}
54
55/*******************************************************************************
56 * Perform any BL31 early platform setup common to Layerscape platforms.
57 * Here is an opportunity to copy parameters passed by the calling EL (S-EL1
58 * in BL2 & S-EL3 in BL1) before they are lost (potentially). This needs to be
59 * done before the MMU is initialized so that the memory layout can be used
60 * while creating page tables. BL2 has flushed this information to memory, so
61 * we are guaranteed to pick up good data.
62 ******************************************************************************/
63void ls_bl31_early_platform_setup(void *from_bl2,
64 void *plat_params_from_bl2)
65{
66 static console_ls_16550_t console;
67
68 /* Initialize the console to provide early debug support */
69 console_ls_16550_register(LS_TF_UART_BASE, LS_TF_UART_CLOCK,
70 LS_TF_UART_BAUDRATE, &console);
71#if RESET_TO_BL31
72 /* There are no parameters from BL2 if BL31 is a reset vector */
73 assert(from_bl2 == NULL);
74 assert(plat_params_from_bl2 == NULL);
75
76#ifdef BL32_BASE
77 /* Populate entry point information for BL32 */
78 SET_PARAM_HEAD(&bl32_image_ep_info,
79 PARAM_EP,
80 VERSION_1,
81 0);
82 SET_SECURITY_STATE(bl32_image_ep_info.h.attr, SECURE);
83 bl32_image_ep_info.pc = BL32_BASE;
84 bl32_image_ep_info.spsr = ls_get_spsr_for_bl32_entry();
85#endif /* BL32_BASE */
86
87 /* Populate entry point information for BL33 */
88 SET_PARAM_HEAD(&bl33_image_ep_info,
89 PARAM_EP,
90 VERSION_1,
91 0);
92 /*
93 * Tell BL31 where the non-trusted software image
94 * is located and the entry state information
95 */
96 bl33_image_ep_info.pc = plat_get_ns_image_entrypoint();
97
98 bl33_image_ep_info.spsr = ls_get_spsr_for_bl33_entry();
99 SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE);
100
101#else /* RESET_TO_BL31 */
102
103 /*
104 * In debug builds, we pass a special value in 'plat_params_from_bl2'
105 * to verify platform parameters from BL2 to BL31.
106 * In release builds, it's not used.
107 */
108 assert(((unsigned long long)plat_params_from_bl2) ==
109 LS_BL31_PLAT_PARAM_VAL);
110
111 /*
112 * Check params passed from BL2 should not be NULL,
113 */
114 bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
115
116 assert(params_from_bl2 != NULL);
117 assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
118 assert(params_from_bl2->h.version >= VERSION_2);
119
120 bl_params_node_t *bl_params = params_from_bl2->head;
121
122 /*
123 * Copy BL33 and BL32 (if present), entry point information.
124 * They are stored in Secure RAM, in BL2's address space.
125 */
126 while (bl_params) {
127 if (bl_params->image_id == BL32_IMAGE_ID)
128 bl32_image_ep_info = *bl_params->ep_info;
129
130 if (bl_params->image_id == BL33_IMAGE_ID)
131 bl33_image_ep_info = *bl_params->ep_info;
132
133 bl_params = bl_params->next_params_info;
134 }
135
136 if (bl33_image_ep_info.pc == 0)
137 panic();
138
139#endif /* RESET_TO_BL31 */
140}
141
142/*******************************************************************************
143 * Perform any BL31 platform setup common to Layerscape platforms
144 ******************************************************************************/
145void ls_bl31_platform_setup(void)
146{
147 uint32_t gicc_base, gicd_base;
148
149 NOTICE(FIRMWARE_WELCOME_STR_LS1043_BL31);
150 /* Initialize the GIC driver, cpu and distributor interfaces */
151 get_gic_offset(&gicc_base, &gicd_base);
152 ls_gic_data.gicd_base = (uintptr_t)gicd_base;
153 ls_gic_data.gicc_base = (uintptr_t)gicc_base;
154 gicv2_driver_init(&ls_gic_data);
155 gicv2_distif_init();
156 gicv2_pcpu_distif_init();
157 gicv2_cpuif_enable();
158
159#if RESET_TO_BL31
160 /*
161 * Do initial security configuration to allow DRAM/device access
162 * (if earlier BL has not already done so).
163 */
164 plat_ls_security_setup();
165
166#endif /* RESET_TO_BL31 */
167
168 /* Enable and initialize the System level generic timer */
169 mmio_write_32(LS1043_SYS_CNTCTL_BASE + CNTCR_OFF,
Antonio Nino Diaze0b757d2018-08-24 16:30:29 +0100170 CNTCR_FCREQ(0U) | CNTCR_EN);
Jiafei Pan46367ad2018-03-02 07:23:30 +0000171
172 VERBOSE("Leave arm_bl31_platform_setup\n");
173}
174
175/*******************************************************************************
176 * Perform any BL31 platform runtime setup prior to BL31 exit common to Layerscape
177 * platforms
178 ******************************************************************************/
179void ls_bl31_plat_runtime_setup(void)
180{
181 static console_ls_16550_t console;
182
183 /* Initialize the runtime console */
184 console_ls_16550_register(PLAT_LS1043_UART_BASE, PLAT_LS1043_UART_CLOCK,
185 PLAT_LS1043_UART_BAUDRATE, &console);
186}
187
188void bl31_platform_setup(void)
189{
190 ls_bl31_platform_setup();
191}
192
193void bl31_plat_runtime_setup(void)
194{
195 ls_bl31_plat_runtime_setup();
196}
197
198/*******************************************************************************
199 * Perform the very early platform specific architectural setup shared between
200 * Layerscape platforms. This only does basic initialization. Later
201 * architectural setup (bl31_arch_setup()) does not do anything platform
202 * specific.
203 ******************************************************************************/
204void ls_bl31_plat_arch_setup(void)
205{
206 ls_setup_page_tables(BL31_BASE,
207 BL31_END - BL31_BASE,
208 BL_CODE_BASE,
209 BL_CODE_END,
210 BL_RO_DATA_BASE,
211 BL_RO_DATA_END
212#if USE_COHERENT_MEM
213 , BL_COHERENT_RAM_BASE,
214 BL_COHERENT_RAM_END
215#endif
216 );
217 enable_mmu_el3(0);
218}
219
220void bl31_plat_arch_setup(void)
221{
222 ls_bl31_plat_arch_setup();
223}