blob: 7453b89007c03d65733dab55b88ba258b7611320 [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/*
Jens Wiklander52c798e2015-12-07 14:37:10 +010019 * Placeholder variables for copying the arguments that have been passed to
20 * BL3-1 from BL2.
21 */
22static entry_point_info_t bl32_image_ep_info;
23static entry_point_info_t bl33_image_ep_info;
24
25/*******************************************************************************
26 * Perform any BL3-1 early platform setup. Here is an opportunity to copy
John Tsichritzisd653d332018-09-14 10:34:57 +010027 * parameters passed by the calling EL (S-EL1 in BL2 & EL3 in BL1) before
Jens Wiklander52c798e2015-12-07 14:37:10 +010028 * they are lost (potentially). This needs to be done before the MMU is
29 * initialized so that the memory layout can be used while creating page
30 * tables. BL2 has flushed this information to memory, so we are guaranteed
31 * to pick up good data.
32 ******************************************************************************/
Jens Wiklandere22b91e2018-09-04 14:07:19 +020033void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
34 u_register_t arg2, u_register_t arg3)
Jens Wiklander52c798e2015-12-07 14:37:10 +010035{
36 /* Initialize the console to provide early debug support */
Michalis Pappascca6cb72018-03-04 15:43:38 +080037 qemu_console_init();
Jens Wiklander52c798e2015-12-07 14:37:10 +010038
Fu Weic2f78442017-05-27 21:21:42 +080039 /*
40 * Check params passed from BL2
41 */
Jens Wiklandere22b91e2018-09-04 14:07:19 +020042 bl_params_t *params_from_bl2 = (bl_params_t *)arg0;
Fu Weic2f78442017-05-27 21:21:42 +080043
44 assert(params_from_bl2);
45 assert(params_from_bl2->h.type == PARAM_BL_PARAMS);
46 assert(params_from_bl2->h.version >= VERSION_2);
47
48 bl_params_node_t *bl_params = params_from_bl2->head;
49
50 /*
51 * Copy BL33 and BL32 (if present), entry point information.
52 * They are stored in Secure RAM, in BL2's address space.
53 */
54 while (bl_params) {
55 if (bl_params->image_id == BL32_IMAGE_ID)
56 bl32_image_ep_info = *bl_params->ep_info;
57
58 if (bl_params->image_id == BL33_IMAGE_ID)
59 bl33_image_ep_info = *bl_params->ep_info;
60
61 bl_params = bl_params->next_params_info;
62 }
63
64 if (!bl33_image_ep_info.pc)
65 panic();
Jens Wiklander52c798e2015-12-07 14:37:10 +010066}
67
68void bl31_plat_arch_setup(void)
69{
Michalis Pappasba861122018-02-28 14:36:03 +080070 qemu_configure_mmu_el3(BL31_BASE, (BL31_END - BL31_BASE),
71 BL_CODE_BASE, BL_CODE_END,
72 BL_RO_DATA_BASE, BL_RO_DATA_END,
Masahiro Yamada0fac5af2016-12-28 16:11:41 +090073 BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END);
Jens Wiklander52c798e2015-12-07 14:37:10 +010074}
75
Etienne Carriere84aa3a72017-11-02 12:05:12 +010076/******************************************************************************
77 * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0
78 * interrupts.
79 *****************************************************************************/
80#define PLATFORM_G1S_PROPS(grp) \
81 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY, \
82 grp, GIC_INTR_CFG_EDGE), \
83 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY, \
84 grp, GIC_INTR_CFG_EDGE), \
85 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY, \
86 grp, GIC_INTR_CFG_EDGE), \
87 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY, \
88 grp, GIC_INTR_CFG_EDGE), \
89 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY, \
90 grp, GIC_INTR_CFG_EDGE), \
91 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY, \
92 grp, GIC_INTR_CFG_EDGE), \
93 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY, \
94 grp, GIC_INTR_CFG_EDGE), \
95 INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY, \
96 grp, GIC_INTR_CFG_EDGE)
97
98#define PLATFORM_G0_PROPS(grp)
99
100static const interrupt_prop_t qemu_interrupt_props[] = {
101 PLATFORM_G1S_PROPS(GICV2_INTR_GROUP0),
102 PLATFORM_G0_PROPS(GICV2_INTR_GROUP0)
Jens Wiklander52c798e2015-12-07 14:37:10 +0100103};
104
105static const struct gicv2_driver_data plat_gicv2_driver_data = {
106 .gicd_base = GICD_BASE,
107 .gicc_base = GICC_BASE,
Etienne Carriere84aa3a72017-11-02 12:05:12 +0100108 .interrupt_props = qemu_interrupt_props,
109 .interrupt_props_num = ARRAY_SIZE(qemu_interrupt_props),
Jens Wiklander52c798e2015-12-07 14:37:10 +0100110};
111
112void bl31_platform_setup(void)
113{
114 /* Initialize the gic cpu and distributor interfaces */
115 gicv2_driver_init(&plat_gicv2_driver_data);
116 gicv2_distif_init();
117 gicv2_pcpu_distif_init();
118 gicv2_cpuif_enable();
119}
120
121unsigned int plat_get_syscnt_freq2(void)
122{
123 return SYS_COUNTER_FREQ_IN_TICKS;
124}
125
126/*******************************************************************************
127 * Return a pointer to the 'entry_point_info' structure of the next image
128 * for the security state specified. BL3-3 corresponds to the non-secure
129 * image type while BL3-2 corresponds to the secure image type. A NULL
130 * pointer is returned if the image does not exist.
131 ******************************************************************************/
132entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
133{
134 entry_point_info_t *next_image_info;
135
136 assert(sec_state_is_valid(type));
137 next_image_info = (type == NON_SECURE)
138 ? &bl33_image_ep_info : &bl32_image_ep_info;
139 /*
140 * None of the images on the ARM development platforms can have 0x0
141 * as the entrypoint
142 */
143 if (next_image_info->pc)
144 return next_image_info;
145 else
146 return NULL;
147}