blob: 6ded9295999a3be812ba5dd2db912cdb2b5716e3 [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>
Etienne Carriere84aa3a72017-11-02 12:05:12 +010010#include <gic_common.h>
Jens Wiklander52c798e2015-12-07 14:37:10 +010011#include <gicv2.h>
12#include <platform_def.h>
13#include "qemu_private.h"
14
15/*
16 * The next 3 constants identify the extents of the code, RO data region and the
17 * limit of the BL3-1 image. These addresses are used by the MMU setup code and
18 * therefore they must be page-aligned. It is the responsibility of the linker
19 * script to ensure that __RO_START__, __RO_END__ & __BL31_END__ linker symbols
20 * refer to page-aligned addresses.
21 */
Jens Wiklander52c798e2015-12-07 14:37:10 +010022#define BL31_END (unsigned long)(&__BL31_END__)
23
24/*
Jens Wiklander52c798e2015-12-07 14:37:10 +010025 * Placeholder variables for copying the arguments that have been passed to
26 * BL3-1 from BL2.
27 */
28static entry_point_info_t bl32_image_ep_info;
29static entry_point_info_t bl33_image_ep_info;
30
31/*******************************************************************************
32 * Perform any BL3-1 early platform setup. Here is an opportunity to copy
33 * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before
34 * they are lost (potentially). This needs to be done before the MMU is
35 * initialized so that the memory layout can be used while creating page
36 * tables. BL2 has flushed this information to memory, so we are guaranteed
37 * to pick up good data.
38 ******************************************************************************/
Fu Weic2f78442017-05-27 21:21:42 +080039#if LOAD_IMAGE_V2
40void bl31_early_platform_setup(void *from_bl2,
41 void *plat_params_from_bl2)
42#else
Jens Wiklander52c798e2015-12-07 14:37:10 +010043void bl31_early_platform_setup(bl31_params_t *from_bl2,
44 void *plat_params_from_bl2)
Fu Weic2f78442017-05-27 21:21:42 +080045#endif
Jens Wiklander52c798e2015-12-07 14:37:10 +010046{
47 /* Initialize the console to provide early debug support */
48 console_init(PLAT_QEMU_BOOT_UART_BASE, PLAT_QEMU_BOOT_UART_CLK_IN_HZ,
49 PLAT_QEMU_CONSOLE_BAUDRATE);
50
Fu Weic2f78442017-05-27 21:21:42 +080051#if LOAD_IMAGE_V2
52 /*
53 * Check params passed from BL2
54 */
55 bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
56
57 assert(params_from_bl2);
58 assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
59 assert(params_from_bl2->h.version >= VERSION_2);
60
61 bl_params_node_t *bl_params = params_from_bl2->head;
62
63 /*
64 * Copy BL33 and BL32 (if present), entry point information.
65 * They are stored in Secure RAM, in BL2's address space.
66 */
67 while (bl_params) {
68 if (bl_params->image_id == BL32_IMAGE_ID)
69 bl32_image_ep_info = *bl_params->ep_info;
70
71 if (bl_params->image_id == BL33_IMAGE_ID)
72 bl33_image_ep_info = *bl_params->ep_info;
73
74 bl_params = bl_params->next_params_info;
75 }
76
77 if (!bl33_image_ep_info.pc)
78 panic();
79
80#else /* LOAD_IMAGE_V2 */
81
Jens Wiklander52c798e2015-12-07 14:37:10 +010082 /*
83 * Check params passed from BL2 should not be NULL,
84 */
85 assert(from_bl2 != NULL);
86 assert(from_bl2->h.type == PARAM_BL31);
87 assert(from_bl2->h.version >= VERSION_1);
88 /*
89 * In debug builds, we pass a special value in 'plat_params_from_bl2'
90 * to verify platform parameters from BL2 to BL3-1.
91 * In release builds, it's not used.
92 */
93 assert(((unsigned long long)plat_params_from_bl2) ==
94 QEMU_BL31_PLAT_PARAM_VAL);
95
96 /*
97 * Copy BL3-2 (if populated by BL2) and BL3-3 entry point information.
98 * They are stored in Secure RAM, in BL2's address space.
99 */
100 if (from_bl2->bl32_ep_info)
101 bl32_image_ep_info = *from_bl2->bl32_ep_info;
102 bl33_image_ep_info = *from_bl2->bl33_ep_info;
Fu Weic2f78442017-05-27 21:21:42 +0800103
104#endif /* !LOAD_IMAGE_V2 */
Jens Wiklander52c798e2015-12-07 14:37:10 +0100105}
106
107void bl31_plat_arch_setup(void)
108{
Michalis Pappasba861122018-02-28 14:36:03 +0800109 qemu_configure_mmu_el3(BL31_BASE, (BL31_END - BL31_BASE),
110 BL_CODE_BASE, BL_CODE_END,
111 BL_RO_DATA_BASE, BL_RO_DATA_END,
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
Etienne Carriere84aa3a72017-11-02 12:05:12 +0100115/******************************************************************************
116 * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0
117 * interrupts.
118 *****************************************************************************/
119#define PLATFORM_G1S_PROPS(grp) \
120 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY, \
121 grp, GIC_INTR_CFG_EDGE), \
122 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY, \
123 grp, GIC_INTR_CFG_EDGE), \
124 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY, \
125 grp, GIC_INTR_CFG_EDGE), \
126 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY, \
127 grp, GIC_INTR_CFG_EDGE), \
128 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY, \
129 grp, GIC_INTR_CFG_EDGE), \
130 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY, \
131 grp, GIC_INTR_CFG_EDGE), \
132 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY, \
133 grp, GIC_INTR_CFG_EDGE), \
134 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY, \
135 grp, GIC_INTR_CFG_EDGE)
136
137#define PLATFORM_G0_PROPS(grp)
138
139static const interrupt_prop_t qemu_interrupt_props[] = {
140 PLATFORM_G1S_PROPS(GICV2_INTR_GROUP0),
141 PLATFORM_G0_PROPS(GICV2_INTR_GROUP0)
Jens Wiklander52c798e2015-12-07 14:37:10 +0100142};
143
144static const struct gicv2_driver_data plat_gicv2_driver_data = {
145 .gicd_base = GICD_BASE,
146 .gicc_base = GICC_BASE,
Etienne Carriere84aa3a72017-11-02 12:05:12 +0100147 .interrupt_props = qemu_interrupt_props,
148 .interrupt_props_num = ARRAY_SIZE(qemu_interrupt_props),
Jens Wiklander52c798e2015-12-07 14:37:10 +0100149};
150
151void bl31_platform_setup(void)
152{
153 /* Initialize the gic cpu and distributor interfaces */
154 gicv2_driver_init(&plat_gicv2_driver_data);
155 gicv2_distif_init();
156 gicv2_pcpu_distif_init();
157 gicv2_cpuif_enable();
158}
159
160unsigned int plat_get_syscnt_freq2(void)
161{
162 return SYS_COUNTER_FREQ_IN_TICKS;
163}
164
165/*******************************************************************************
166 * Return a pointer to the 'entry_point_info' structure of the next image
167 * for the security state specified. BL3-3 corresponds to the non-secure
168 * image type while BL3-2 corresponds to the secure image type. A NULL
169 * pointer is returned if the image does not exist.
170 ******************************************************************************/
171entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
172{
173 entry_point_info_t *next_image_info;
174
175 assert(sec_state_is_valid(type));
176 next_image_info = (type == NON_SECURE)
177 ? &bl33_image_ep_info : &bl32_image_ep_info;
178 /*
179 * None of the images on the ARM development platforms can have 0x0
180 * as the entrypoint
181 */
182 if (next_image_info->pc)
183 return next_image_info;
184 else
185 return NULL;
186}