xref: /arm-trusted-firmware/plat/intel/soc/n5x/bl31_plat_setup.c (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu /*
2*91f16700Schasinglulu  * Copyright (c) 2020-2022, Intel Corporation. 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 <arch.h>
9*91f16700Schasinglulu #include <arch_helpers.h>
10*91f16700Schasinglulu #include <common/bl_common.h>
11*91f16700Schasinglulu #include <drivers/arm/gicv2.h>
12*91f16700Schasinglulu #include <drivers/ti/uart/uart_16550.h>
13*91f16700Schasinglulu #include <lib/mmio.h>
14*91f16700Schasinglulu #include <lib/xlat_tables/xlat_tables.h>
15*91f16700Schasinglulu 
16*91f16700Schasinglulu #include "ccu/ncore_ccu.h"
17*91f16700Schasinglulu #include "socfpga_mailbox.h"
18*91f16700Schasinglulu #include "socfpga_private.h"
19*91f16700Schasinglulu 
20*91f16700Schasinglulu static entry_point_info_t bl32_image_ep_info;
21*91f16700Schasinglulu static entry_point_info_t bl33_image_ep_info;
22*91f16700Schasinglulu 
23*91f16700Schasinglulu entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type)
24*91f16700Schasinglulu {
25*91f16700Schasinglulu 	entry_point_info_t *next_image_info;
26*91f16700Schasinglulu 
27*91f16700Schasinglulu 	next_image_info = (type == NON_SECURE) ?
28*91f16700Schasinglulu 			  &bl33_image_ep_info : &bl32_image_ep_info;
29*91f16700Schasinglulu 
30*91f16700Schasinglulu 	/* None of the images on this platform can have 0x0 as the entrypoint */
31*91f16700Schasinglulu 	if (next_image_info->pc) {
32*91f16700Schasinglulu 		return next_image_info;
33*91f16700Schasinglulu 	} else {
34*91f16700Schasinglulu 		return NULL;
35*91f16700Schasinglulu 	}
36*91f16700Schasinglulu }
37*91f16700Schasinglulu 
38*91f16700Schasinglulu void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1,
39*91f16700Schasinglulu 				u_register_t arg2, u_register_t arg3)
40*91f16700Schasinglulu {
41*91f16700Schasinglulu 	static console_t console;
42*91f16700Schasinglulu 
43*91f16700Schasinglulu 	mmio_write_64(PLAT_SEC_ENTRY, 0);
44*91f16700Schasinglulu 
45*91f16700Schasinglulu 	console_16550_register(PLAT_INTEL_UART_BASE, PLAT_UART_CLOCK,
46*91f16700Schasinglulu 		PLAT_BAUDRATE, &console);
47*91f16700Schasinglulu 	/*
48*91f16700Schasinglulu 	 * Check params passed from BL31 should not be NULL,
49*91f16700Schasinglulu 	 */
50*91f16700Schasinglulu 	void *from_bl2 = (void *) arg0;
51*91f16700Schasinglulu 
52*91f16700Schasinglulu 	bl_params_t *params_from_bl2 = (bl_params_t *)from_bl2;
53*91f16700Schasinglulu 
54*91f16700Schasinglulu 	assert(params_from_bl2 != NULL);
55*91f16700Schasinglulu 
56*91f16700Schasinglulu 	/*
57*91f16700Schasinglulu 	 * Copy BL32 (if populated by BL31) and BL33 entry point information.
58*91f16700Schasinglulu 	 * They are stored in Secure RAM, in BL31's address space.
59*91f16700Schasinglulu 	 */
60*91f16700Schasinglulu 
61*91f16700Schasinglulu 	if (params_from_bl2->h.type == PARAM_BL_PARAMS &&
62*91f16700Schasinglulu 		params_from_bl2->h.version >= VERSION_2) {
63*91f16700Schasinglulu 
64*91f16700Schasinglulu 		bl_params_node_t *bl_params = params_from_bl2->head;
65*91f16700Schasinglulu 
66*91f16700Schasinglulu 		while (bl_params != NULL) {
67*91f16700Schasinglulu 			if (bl_params->image_id == BL33_IMAGE_ID)
68*91f16700Schasinglulu 				bl33_image_ep_info = *bl_params->ep_info;
69*91f16700Schasinglulu 
70*91f16700Schasinglulu 			bl_params = bl_params->next_params_info;
71*91f16700Schasinglulu 		}
72*91f16700Schasinglulu 	} else {
73*91f16700Schasinglulu 		struct socfpga_bl31_params *arg_from_bl2 =
74*91f16700Schasinglulu 			(struct socfpga_bl31_params *) from_bl2;
75*91f16700Schasinglulu 
76*91f16700Schasinglulu 		assert(arg_from_bl2->h.type == PARAM_BL31);
77*91f16700Schasinglulu 		assert(arg_from_bl2->h.version >= VERSION_1);
78*91f16700Schasinglulu 
79*91f16700Schasinglulu 		bl32_image_ep_info = *arg_from_bl2->bl32_ep_info;
80*91f16700Schasinglulu 		bl33_image_ep_info = *arg_from_bl2->bl33_ep_info;
81*91f16700Schasinglulu 	}
82*91f16700Schasinglulu 	SET_SECURITY_STATE(bl33_image_ep_info.h.attr, NON_SECURE);
83*91f16700Schasinglulu }
84*91f16700Schasinglulu 
85*91f16700Schasinglulu static const interrupt_prop_t s10_interrupt_props[] = {
86*91f16700Schasinglulu 	PLAT_INTEL_SOCFPGA_G1S_IRQ_PROPS(GICV2_INTR_GROUP0),
87*91f16700Schasinglulu 	PLAT_INTEL_SOCFPGA_G0_IRQ_PROPS(GICV2_INTR_GROUP0)
88*91f16700Schasinglulu };
89*91f16700Schasinglulu 
90*91f16700Schasinglulu static unsigned int target_mask_array[PLATFORM_CORE_COUNT];
91*91f16700Schasinglulu 
92*91f16700Schasinglulu static const gicv2_driver_data_t plat_gicv2_gic_data = {
93*91f16700Schasinglulu 	.gicd_base = PLAT_INTEL_SOCFPGA_GICD_BASE,
94*91f16700Schasinglulu 	.gicc_base = PLAT_INTEL_SOCFPGA_GICC_BASE,
95*91f16700Schasinglulu 	.interrupt_props = s10_interrupt_props,
96*91f16700Schasinglulu 	.interrupt_props_num = ARRAY_SIZE(s10_interrupt_props),
97*91f16700Schasinglulu 	.target_masks = target_mask_array,
98*91f16700Schasinglulu 	.target_masks_num = ARRAY_SIZE(target_mask_array),
99*91f16700Schasinglulu };
100*91f16700Schasinglulu 
101*91f16700Schasinglulu /*******************************************************************************
102*91f16700Schasinglulu  * Perform any BL3-1 platform setup code
103*91f16700Schasinglulu  ******************************************************************************/
104*91f16700Schasinglulu void bl31_platform_setup(void)
105*91f16700Schasinglulu {
106*91f16700Schasinglulu 	socfpga_delay_timer_init();
107*91f16700Schasinglulu 
108*91f16700Schasinglulu 	/* Initialize the gic cpu and distributor interfaces */
109*91f16700Schasinglulu 	gicv2_driver_init(&plat_gicv2_gic_data);
110*91f16700Schasinglulu 	gicv2_distif_init();
111*91f16700Schasinglulu 	gicv2_pcpu_distif_init();
112*91f16700Schasinglulu 	gicv2_cpuif_enable();
113*91f16700Schasinglulu 
114*91f16700Schasinglulu 	/* Signal secondary CPUs to jump to BL31 (BL2 = U-boot SPL) */
115*91f16700Schasinglulu 	mmio_write_64(PLAT_CPU_RELEASE_ADDR,
116*91f16700Schasinglulu 		(uint64_t)plat_secondary_cpus_bl31_entry);
117*91f16700Schasinglulu 
118*91f16700Schasinglulu 	mailbox_hps_stage_notify(HPS_EXECUTION_STATE_SSBL);
119*91f16700Schasinglulu 
120*91f16700Schasinglulu 	ncore_enable_ocram_firewall();
121*91f16700Schasinglulu }
122*91f16700Schasinglulu 
123*91f16700Schasinglulu const mmap_region_t plat_dm_mmap[] = {
124*91f16700Schasinglulu 	MAP_REGION_FLAT(DRAM_BASE, DRAM_SIZE,
125*91f16700Schasinglulu 		MT_MEMORY | MT_RW | MT_NS),
126*91f16700Schasinglulu 	MAP_REGION_FLAT(DEVICE1_BASE, DEVICE1_SIZE,
127*91f16700Schasinglulu 		MT_DEVICE | MT_RW | MT_NS),
128*91f16700Schasinglulu 	MAP_REGION_FLAT(DEVICE2_BASE, DEVICE2_SIZE,
129*91f16700Schasinglulu 		MT_DEVICE | MT_RW | MT_SECURE),
130*91f16700Schasinglulu 	MAP_REGION_FLAT(OCRAM_BASE, OCRAM_SIZE,
131*91f16700Schasinglulu 		MT_NON_CACHEABLE | MT_RW | MT_SECURE),
132*91f16700Schasinglulu 	MAP_REGION_FLAT(DEVICE3_BASE, DEVICE3_SIZE,
133*91f16700Schasinglulu 		MT_DEVICE | MT_RW | MT_SECURE),
134*91f16700Schasinglulu 	MAP_REGION_FLAT(MEM64_BASE, MEM64_SIZE,
135*91f16700Schasinglulu 		MT_DEVICE | MT_RW | MT_NS),
136*91f16700Schasinglulu 	MAP_REGION_FLAT(DEVICE4_BASE, DEVICE4_SIZE,
137*91f16700Schasinglulu 		MT_DEVICE | MT_RW | MT_NS),
138*91f16700Schasinglulu 	{0}
139*91f16700Schasinglulu };
140*91f16700Schasinglulu 
141*91f16700Schasinglulu /*******************************************************************************
142*91f16700Schasinglulu  * Perform the very early platform specific architectural setup here. At the
143*91f16700Schasinglulu  * moment this is only initializes the mmu in a quick and dirty way.
144*91f16700Schasinglulu  ******************************************************************************/
145*91f16700Schasinglulu void bl31_plat_arch_setup(void)
146*91f16700Schasinglulu {
147*91f16700Schasinglulu 	const mmap_region_t bl_regions[] = {
148*91f16700Schasinglulu 		MAP_REGION_FLAT(BL31_BASE, BL31_END - BL31_BASE,
149*91f16700Schasinglulu 			MT_MEMORY | MT_RW | MT_SECURE),
150*91f16700Schasinglulu 		MAP_REGION_FLAT(BL_CODE_BASE, BL_CODE_END - BL_CODE_BASE,
151*91f16700Schasinglulu 			MT_CODE | MT_SECURE),
152*91f16700Schasinglulu 		MAP_REGION_FLAT(BL_RO_DATA_BASE,
153*91f16700Schasinglulu 			BL_RO_DATA_END - BL_RO_DATA_BASE,
154*91f16700Schasinglulu 			MT_RO_DATA | MT_SECURE),
155*91f16700Schasinglulu #if USE_COHERENT_MEM
156*91f16700Schasinglulu 		MAP_REGION_FLAT(BL_COHERENT_RAM_BASE,
157*91f16700Schasinglulu 			BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE,
158*91f16700Schasinglulu 			MT_DEVICE | MT_RW | MT_SECURE),
159*91f16700Schasinglulu #endif
160*91f16700Schasinglulu 		{0}
161*91f16700Schasinglulu 	};
162*91f16700Schasinglulu 
163*91f16700Schasinglulu 	setup_page_tables(bl_regions, plat_dm_mmap);
164*91f16700Schasinglulu 	enable_mmu_el3(0);
165*91f16700Schasinglulu }
166