xref: /arm-trusted-firmware/plat/amlogic/g12a/g12a_bl31_setup.c (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu /*
2*91f16700Schasinglulu  * Copyright (c) 2019, ARM Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu  *
4*91f16700Schasinglulu  * SPDX-License-Identifier: BSD-3-Clause
5*91f16700Schasinglulu  */
6*91f16700Schasinglulu 
7*91f16700Schasinglulu #include <assert.h>
8*91f16700Schasinglulu #include <common/bl_common.h>
9*91f16700Schasinglulu #include <common/interrupt_props.h>
10*91f16700Schasinglulu #include <drivers/arm/gicv2.h>
11*91f16700Schasinglulu #include <lib/mmio.h>
12*91f16700Schasinglulu #include <lib/xlat_tables/xlat_mmu_helpers.h>
13*91f16700Schasinglulu #include <plat/common/platform.h>
14*91f16700Schasinglulu #include <platform_def.h>
15*91f16700Schasinglulu 
16*91f16700Schasinglulu #include "aml_private.h"
17*91f16700Schasinglulu 
18*91f16700Schasinglulu /*
19*91f16700Schasinglulu  * Placeholder variables for copying the arguments that have been passed to
20*91f16700Schasinglulu  * BL31 from BL2.
21*91f16700Schasinglulu  */
22*91f16700Schasinglulu static entry_point_info_t bl32_image_ep_info;
23*91f16700Schasinglulu static entry_point_info_t bl33_image_ep_info;
24*91f16700Schasinglulu static image_info_t bl30_image_info;
25*91f16700Schasinglulu static image_info_t bl301_image_info;
26*91f16700Schasinglulu 
27*91f16700Schasinglulu /*******************************************************************************
28*91f16700Schasinglulu  * Return a pointer to the 'entry_point_info' structure of the next image for
29*91f16700Schasinglulu  * the security state specified. BL33 corresponds to the non-secure image type
30*91f16700Schasinglulu  * while BL32 corresponds to the secure image type. A NULL pointer is returned
31*91f16700Schasinglulu  * if the image does not exist.
32*91f16700Schasinglulu  ******************************************************************************/
33*91f16700Schasinglulu entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
34*91f16700Schasinglulu {
35*91f16700Schasinglulu 	entry_point_info_t *next_image_info;
36*91f16700Schasinglulu 
37*91f16700Schasinglulu 	next_image_info = (type == NON_SECURE) ?
38*91f16700Schasinglulu 			  &bl33_image_ep_info : &bl32_image_ep_info;
39*91f16700Schasinglulu 
40*91f16700Schasinglulu 	/* None of the images can have 0x0 as the entrypoint. */
41*91f16700Schasinglulu 	if (next_image_info->pc != 0U)
42*91f16700Schasinglulu 		return next_image_info;
43*91f16700Schasinglulu 
44*91f16700Schasinglulu 	return NULL;
45*91f16700Schasinglulu }
46*91f16700Schasinglulu 
47*91f16700Schasinglulu /*******************************************************************************
48*91f16700Schasinglulu  * Perform any BL31 early platform setup. Here is an opportunity to copy
49*91f16700Schasinglulu  * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before
50*91f16700Schasinglulu  * they are lost (potentially). This needs to be done before the MMU is
51*91f16700Schasinglulu  * initialized so that the memory layout can be used while creating page
52*91f16700Schasinglulu  * tables. BL2 has flushed this information to memory, so we are guaranteed
53*91f16700Schasinglulu  * to pick up good data.
54*91f16700Schasinglulu  ******************************************************************************/
55*91f16700Schasinglulu struct g12a_bl31_param {
56*91f16700Schasinglulu 	param_header_t h;
57*91f16700Schasinglulu 	image_info_t *bl31_image_info;
58*91f16700Schasinglulu 	entry_point_info_t *bl32_ep_info;
59*91f16700Schasinglulu 	image_info_t *bl32_image_info;
60*91f16700Schasinglulu 	entry_point_info_t *bl33_ep_info;
61*91f16700Schasinglulu 	image_info_t *bl33_image_info;
62*91f16700Schasinglulu 	image_info_t *scp_image_info[];
63*91f16700Schasinglulu };
64*91f16700Schasinglulu 
65*91f16700Schasinglulu void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
66*91f16700Schasinglulu 				u_register_t arg2, u_register_t arg3)
67*91f16700Schasinglulu {
68*91f16700Schasinglulu 	struct g12a_bl31_param *from_bl2;
69*91f16700Schasinglulu 
70*91f16700Schasinglulu 	/* Initialize the console to provide early debug support */
71*91f16700Schasinglulu 	aml_console_init();
72*91f16700Schasinglulu 
73*91f16700Schasinglulu 	from_bl2 = (struct g12a_bl31_param *)arg0;
74*91f16700Schasinglulu 
75*91f16700Schasinglulu 	/* Check params passed from BL2 are not NULL. */
76*91f16700Schasinglulu 	assert(from_bl2 != NULL);
77*91f16700Schasinglulu 	assert(from_bl2->h.type == PARAM_BL31);
78*91f16700Schasinglulu 	assert(from_bl2->h.version >= VERSION_1);
79*91f16700Schasinglulu 
80*91f16700Schasinglulu 	/*
81*91f16700Schasinglulu 	 * Copy BL32 and BL33 entry point information. It is stored in Secure
82*91f16700Schasinglulu 	 * RAM, in BL2's address space.
83*91f16700Schasinglulu 	 */
84*91f16700Schasinglulu 	bl32_image_ep_info = *from_bl2->bl32_ep_info;
85*91f16700Schasinglulu 	bl33_image_ep_info = *from_bl2->bl33_ep_info;
86*91f16700Schasinglulu 
87*91f16700Schasinglulu 	if (bl33_image_ep_info.pc == 0U) {
88*91f16700Schasinglulu 		ERROR("BL31: BL33 entrypoint not obtained from BL2\n");
89*91f16700Schasinglulu 		panic();
90*91f16700Schasinglulu 	}
91*91f16700Schasinglulu 
92*91f16700Schasinglulu 	bl30_image_info = *from_bl2->scp_image_info[0];
93*91f16700Schasinglulu 	bl301_image_info = *from_bl2->scp_image_info[1];
94*91f16700Schasinglulu }
95*91f16700Schasinglulu 
96*91f16700Schasinglulu void bl31_plat_arch_setup(void)
97*91f16700Schasinglulu {
98*91f16700Schasinglulu 	aml_setup_page_tables();
99*91f16700Schasinglulu 
100*91f16700Schasinglulu 	enable_mmu_el3(0);
101*91f16700Schasinglulu }
102*91f16700Schasinglulu 
103*91f16700Schasinglulu /*******************************************************************************
104*91f16700Schasinglulu  * GICv2 driver setup information
105*91f16700Schasinglulu  ******************************************************************************/
106*91f16700Schasinglulu static const interrupt_prop_t g12a_interrupt_props[] = {
107*91f16700Schasinglulu 	INTR_PROP_DESC(IRQ_SEC_PHY_TIMER, GIC_HIGHEST_SEC_PRIORITY,
108*91f16700Schasinglulu 		       GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
109*91f16700Schasinglulu 	INTR_PROP_DESC(IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY,
110*91f16700Schasinglulu 		       GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
111*91f16700Schasinglulu 	INTR_PROP_DESC(IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY,
112*91f16700Schasinglulu 		       GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
113*91f16700Schasinglulu 	INTR_PROP_DESC(IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY,
114*91f16700Schasinglulu 		       GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
115*91f16700Schasinglulu 	INTR_PROP_DESC(IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY,
116*91f16700Schasinglulu 		       GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
117*91f16700Schasinglulu 	INTR_PROP_DESC(IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY,
118*91f16700Schasinglulu 		       GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
119*91f16700Schasinglulu 	INTR_PROP_DESC(IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY,
120*91f16700Schasinglulu 		       GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
121*91f16700Schasinglulu 	INTR_PROP_DESC(IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY,
122*91f16700Schasinglulu 		       GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL),
123*91f16700Schasinglulu 	INTR_PROP_DESC(IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY,
124*91f16700Schasinglulu 		       GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL)
125*91f16700Schasinglulu };
126*91f16700Schasinglulu 
127*91f16700Schasinglulu static const gicv2_driver_data_t g12a_gic_data = {
128*91f16700Schasinglulu 	.gicd_base = AML_GICD_BASE,
129*91f16700Schasinglulu 	.gicc_base = AML_GICC_BASE,
130*91f16700Schasinglulu 	.interrupt_props = g12a_interrupt_props,
131*91f16700Schasinglulu 	.interrupt_props_num = ARRAY_SIZE(g12a_interrupt_props)
132*91f16700Schasinglulu };
133*91f16700Schasinglulu 
134*91f16700Schasinglulu void bl31_platform_setup(void)
135*91f16700Schasinglulu {
136*91f16700Schasinglulu 	aml_mhu_secure_init();
137*91f16700Schasinglulu 
138*91f16700Schasinglulu 	gicv2_driver_init(&g12a_gic_data);
139*91f16700Schasinglulu 	gicv2_distif_init();
140*91f16700Schasinglulu 	gicv2_pcpu_distif_init();
141*91f16700Schasinglulu 	gicv2_cpuif_enable();
142*91f16700Schasinglulu }
143