blob: 97468114a1ae5eb075eb577028096c31386b4117 [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>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +00008
Jens Wiklander52c798e2015-12-07 14:37:10 +01009#include <platform_def.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000010
11#include <common/bl_common.h>
12#include <drivers/arm/gic_common.h>
13#include <drivers/arm/gicv2.h>
14#include <plat/common/platform.h>
15
Jens Wiklander52c798e2015-12-07 14:37:10 +010016#include "qemu_private.h"
17
18/*
19 * The next 3 constants identify the extents of the code, RO data region and the
20 * limit of the BL3-1 image. These addresses are used by the MMU setup code and
21 * therefore they must be page-aligned. It is the responsibility of the linker
22 * script to ensure that __RO_START__, __RO_END__ & __BL31_END__ linker symbols
23 * refer to page-aligned addresses.
24 */
Jens Wiklander52c798e2015-12-07 14:37:10 +010025#define BL31_END (unsigned long)(&__BL31_END__)
26
27/*
Jens Wiklander52c798e2015-12-07 14:37:10 +010028 * Placeholder variables for copying the arguments that have been passed to
29 * BL3-1 from BL2.
30 */
31static entry_point_info_t bl32_image_ep_info;
32static entry_point_info_t bl33_image_ep_info;
33
34/*******************************************************************************
35 * Perform any BL3-1 early platform setup. Here is an opportunity to copy
John Tsichritzisd653d332018-09-14 10:34:57 +010036 * parameters passed by the calling EL (S-EL1 in BL2 & EL3 in BL1) before
Jens Wiklander52c798e2015-12-07 14:37:10 +010037 * they are lost (potentially). This needs to be done before the MMU is
38 * initialized so that the memory layout can be used while creating page
39 * tables. BL2 has flushed this information to memory, so we are guaranteed
40 * to pick up good data.
41 ******************************************************************************/
Jens Wiklandere22b91e2018-09-04 14:07:19 +020042void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
43 u_register_t arg2, u_register_t arg3)
Jens Wiklander52c798e2015-12-07 14:37:10 +010044{
45 /* Initialize the console to provide early debug support */
Michalis Pappascca6cb72018-03-04 15:43:38 +080046 qemu_console_init();
Jens Wiklander52c798e2015-12-07 14:37:10 +010047
Fu Weic2f78442017-05-27 21:21:42 +080048 /*
49 * Check params passed from BL2
50 */
Jens Wiklandere22b91e2018-09-04 14:07:19 +020051 bl_params_t *params_from_bl2 = (bl_params_t *)arg0;
Fu Weic2f78442017-05-27 21:21:42 +080052
53 assert(params_from_bl2);
54 assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
55 assert(params_from_bl2->h.version >= VERSION_2);
56
57 bl_params_node_t *bl_params = params_from_bl2->head;
58
59 /*
60 * Copy BL33 and BL32 (if present), entry point information.
61 * They are stored in Secure RAM, in BL2's address space.
62 */
63 while (bl_params) {
64 if (bl_params->image_id == BL32_IMAGE_ID)
65 bl32_image_ep_info = *bl_params->ep_info;
66
67 if (bl_params->image_id == BL33_IMAGE_ID)
68 bl33_image_ep_info = *bl_params->ep_info;
69
70 bl_params = bl_params->next_params_info;
71 }
72
73 if (!bl33_image_ep_info.pc)
74 panic();
Jens Wiklander52c798e2015-12-07 14:37:10 +010075}
76
77void bl31_plat_arch_setup(void)
78{
Michalis Pappasba861122018-02-28 14:36:03 +080079 qemu_configure_mmu_el3(BL31_BASE, (BL31_END - BL31_BASE),
80 BL_CODE_BASE, BL_CODE_END,
81 BL_RO_DATA_BASE, BL_RO_DATA_END,
Masahiro Yamada0fac5af2016-12-28 16:11:41 +090082 BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END);
Jens Wiklander52c798e2015-12-07 14:37:10 +010083}
84
Etienne Carriere84aa3a72017-11-02 12:05:12 +010085/******************************************************************************
86 * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0
87 * interrupts.
88 *****************************************************************************/
89#define PLATFORM_G1S_PROPS(grp) \
90 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY, \
91 grp, GIC_INTR_CFG_EDGE), \
92 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY, \
93 grp, GIC_INTR_CFG_EDGE), \
94 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY, \
95 grp, GIC_INTR_CFG_EDGE), \
96 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY, \
97 grp, GIC_INTR_CFG_EDGE), \
98 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY, \
99 grp, GIC_INTR_CFG_EDGE), \
100 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY, \
101 grp, GIC_INTR_CFG_EDGE), \
102 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY, \
103 grp, GIC_INTR_CFG_EDGE), \
104 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY, \
105 grp, GIC_INTR_CFG_EDGE)
106
107#define PLATFORM_G0_PROPS(grp)
108
109static const interrupt_prop_t qemu_interrupt_props[] = {
110 PLATFORM_G1S_PROPS(GICV2_INTR_GROUP0),
111 PLATFORM_G0_PROPS(GICV2_INTR_GROUP0)
Jens Wiklander52c798e2015-12-07 14:37:10 +0100112};
113
114static const struct gicv2_driver_data plat_gicv2_driver_data = {
115 .gicd_base = GICD_BASE,
116 .gicc_base = GICC_BASE,
Etienne Carriere84aa3a72017-11-02 12:05:12 +0100117 .interrupt_props = qemu_interrupt_props,
118 .interrupt_props_num = ARRAY_SIZE(qemu_interrupt_props),
Jens Wiklander52c798e2015-12-07 14:37:10 +0100119};
120
121void bl31_platform_setup(void)
122{
123 /* Initialize the gic cpu and distributor interfaces */
124 gicv2_driver_init(&plat_gicv2_driver_data);
125 gicv2_distif_init();
126 gicv2_pcpu_distif_init();
127 gicv2_cpuif_enable();
128}
129
130unsigned int plat_get_syscnt_freq2(void)
131{
132 return SYS_COUNTER_FREQ_IN_TICKS;
133}
134
135/*******************************************************************************
136 * Return a pointer to the 'entry_point_info' structure of the next image
137 * for the security state specified. BL3-3 corresponds to the non-secure
138 * image type while BL3-2 corresponds to the secure image type. A NULL
139 * pointer is returned if the image does not exist.
140 ******************************************************************************/
141entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
142{
143 entry_point_info_t *next_image_info;
144
145 assert(sec_state_is_valid(type));
146 next_image_info = (type == NON_SECURE)
147 ? &bl33_image_ep_info : &bl32_image_ep_info;
148 /*
149 * None of the images on the ARM development platforms can have 0x0
150 * as the entrypoint
151 */
152 if (next_image_info->pc)
153 return next_image_info;
154 else
155 return NULL;
156}