blob: 5bf458955d73f61464506b6e7264ff656a48a7b5 [file] [log] [blame]
Jens Wiklander52c798e2015-12-07 14:37:10 +01001/*
2 * Copyright (c) 2015-2016, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Jens Wiklander52c798e2015-12-07 14:37:10 +01005 */
6
7#include <assert.h>
8#include <bl_common.h>
9#include <console.h>
10#include <gicv2.h>
11#include <platform_def.h>
12#include "qemu_private.h"
13
14/*
15 * The next 3 constants identify the extents of the code, RO data region and the
16 * limit of the BL3-1 image. These addresses are used by the MMU setup code and
17 * therefore they must be page-aligned. It is the responsibility of the linker
18 * script to ensure that __RO_START__, __RO_END__ & __BL31_END__ linker symbols
19 * refer to page-aligned addresses.
20 */
21#define BL31_RO_BASE (unsigned long)(&__RO_START__)
22#define BL31_RO_LIMIT (unsigned long)(&__RO_END__)
23#define BL31_END (unsigned long)(&__BL31_END__)
24
25/*
Jens Wiklander52c798e2015-12-07 14:37:10 +010026 * Placeholder variables for copying the arguments that have been passed to
27 * BL3-1 from BL2.
28 */
29static entry_point_info_t bl32_image_ep_info;
30static entry_point_info_t bl33_image_ep_info;
31
32/*******************************************************************************
33 * Perform any BL3-1 early platform setup. Here is an opportunity to copy
34 * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before
35 * they are lost (potentially). This needs to be done before the MMU is
36 * initialized so that the memory layout can be used while creating page
37 * tables. BL2 has flushed this information to memory, so we are guaranteed
38 * to pick up good data.
39 ******************************************************************************/
Fu Weic2f78442017-05-27 21:21:42 +080040#if LOAD_IMAGE_V2
41void bl31_early_platform_setup(void *from_bl2,
42 void *plat_params_from_bl2)
43#else
Jens Wiklander52c798e2015-12-07 14:37:10 +010044void bl31_early_platform_setup(bl31_params_t *from_bl2,
45 void *plat_params_from_bl2)
Fu Weic2f78442017-05-27 21:21:42 +080046#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +010047{
48 /* Initialize the console to provide early debug support */
49 console_init(PLAT_QEMU_BOOT_UART_BASE, PLAT_QEMU_BOOT_UART_CLK_IN_HZ,
50 PLAT_QEMU_CONSOLE_BAUDRATE);
51
Fu Weic2f78442017-05-27 21:21:42 +080052#if LOAD_IMAGE_V2
53 /*
54 * Check params passed from BL2
55 */
56 bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
57
58 assert(params_from_bl2);
59 assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
60 assert(params_from_bl2->h.version >= VERSION_2);
61
62 bl_params_node_t *bl_params = params_from_bl2->head;
63
64 /*
65 * Copy BL33 and BL32 (if present), entry point information.
66 * They are stored in Secure RAM, in BL2's address space.
67 */
68 while (bl_params) {
69 if (bl_params->image_id == BL32_IMAGE_ID)
70 bl32_image_ep_info = *bl_params->ep_info;
71
72 if (bl_params->image_id == BL33_IMAGE_ID)
73 bl33_image_ep_info = *bl_params->ep_info;
74
75 bl_params = bl_params->next_params_info;
76 }
77
78 if (!bl33_image_ep_info.pc)
79 panic();
80
81#else /* LOAD_IMAGE_V2 */
82
Jens Wiklander52c798e2015-12-07 14:37:10 +010083 /*
84 * Check params passed from BL2 should not be NULL,
85 */
86 assert(from_bl2 != NULL);
87 assert(from_bl2->h.type == PARAM_BL31);
88 assert(from_bl2->h.version >= VERSION_1);
89 /*
90 * In debug builds, we pass a special value in 'plat_params_from_bl2'
91 * to verify platform parameters from BL2 to BL3-1.
92 * In release builds, it's not used.
93 */
94 assert(((unsigned long long)plat_params_from_bl2) ==
95 QEMU_BL31_PLAT_PARAM_VAL);
96
97 /*
98 * Copy BL3-2 (if populated by BL2) and BL3-3 entry point information.
99 * They are stored in Secure RAM, in BL2's address space.
100 */
101 if (from_bl2->bl32_ep_info)
102 bl32_image_ep_info = *from_bl2->bl32_ep_info;
103 bl33_image_ep_info = *from_bl2->bl33_ep_info;
Fu Weic2f78442017-05-27 21:21:42 +0800104
105#endif /* !LOAD_IMAGE_V2 */
Jens Wiklander52c798e2015-12-07 14:37:10 +0100106}
107
108void bl31_plat_arch_setup(void)
109{
110 qemu_configure_mmu_el3(BL31_RO_BASE, (BL31_END - BL31_RO_BASE),
111 BL31_RO_BASE, BL31_RO_LIMIT,
Masahiro Yamada0fac5af2016-12-28 16:11:41 +0900112 BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END);
Jens Wiklander52c798e2015-12-07 14:37:10 +0100113}
114
115static const unsigned int irq_sec_array[] = {
116 QEMU_IRQ_SEC_SGI_0,
117 QEMU_IRQ_SEC_SGI_1,
118 QEMU_IRQ_SEC_SGI_2,
119 QEMU_IRQ_SEC_SGI_3,
120 QEMU_IRQ_SEC_SGI_4,
121 QEMU_IRQ_SEC_SGI_5,
122 QEMU_IRQ_SEC_SGI_6,
123 QEMU_IRQ_SEC_SGI_7,
124};
125
126static const struct gicv2_driver_data plat_gicv2_driver_data = {
127 .gicd_base = GICD_BASE,
128 .gicc_base = GICC_BASE,
129 .g0_interrupt_num = ARRAY_SIZE(irq_sec_array),
130 .g0_interrupt_array = irq_sec_array,
131};
132
133void bl31_platform_setup(void)
134{
135 /* Initialize the gic cpu and distributor interfaces */
136 gicv2_driver_init(&plat_gicv2_driver_data);
137 gicv2_distif_init();
138 gicv2_pcpu_distif_init();
139 gicv2_cpuif_enable();
140}
141
142unsigned int plat_get_syscnt_freq2(void)
143{
144 return SYS_COUNTER_FREQ_IN_TICKS;
145}
146
147/*******************************************************************************
148 * Return a pointer to the 'entry_point_info' structure of the next image
149 * for the security state specified. BL3-3 corresponds to the non-secure
150 * image type while BL3-2 corresponds to the secure image type. A NULL
151 * pointer is returned if the image does not exist.
152 ******************************************************************************/
153entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
154{
155 entry_point_info_t *next_image_info;
156
157 assert(sec_state_is_valid(type));
158 next_image_info = (type == NON_SECURE)
159 ? &bl33_image_ep_info : &bl32_image_ep_info;
160 /*
161 * None of the images on the ARM development platforms can have 0x0
162 * as the entrypoint
163 */
164 if (next_image_info->pc)
165 return next_image_info;
166 else
167 return NULL;
168}