xref: /arm-trusted-firmware/plat/intel/soc/stratix10/bl2_plat_setup.c (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu /*
2*91f16700Schasinglulu  * Copyright (c) 2019-2022, ARM Limited and Contributors. All rights reserved.
3*91f16700Schasinglulu  * Copyright (c) 2019-2022, Intel Corporation. All rights reserved.
4*91f16700Schasinglulu  *
5*91f16700Schasinglulu  * SPDX-License-Identifier: BSD-3-Clause
6*91f16700Schasinglulu  */
7*91f16700Schasinglulu 
8*91f16700Schasinglulu #include <arch.h>
9*91f16700Schasinglulu #include <arch_helpers.h>
10*91f16700Schasinglulu #include <assert.h>
11*91f16700Schasinglulu #include <common/bl_common.h>
12*91f16700Schasinglulu #include <common/debug.h>
13*91f16700Schasinglulu #include <common/desc_image_load.h>
14*91f16700Schasinglulu #include <drivers/generic_delay_timer.h>
15*91f16700Schasinglulu #include <drivers/synopsys/dw_mmc.h>
16*91f16700Schasinglulu #include <drivers/ti/uart/uart_16550.h>
17*91f16700Schasinglulu #include <lib/xlat_tables/xlat_tables.h>
18*91f16700Schasinglulu 
19*91f16700Schasinglulu #include "qspi/cadence_qspi.h"
20*91f16700Schasinglulu #include "socfpga_emac.h"
21*91f16700Schasinglulu #include "socfpga_f2sdram_manager.h"
22*91f16700Schasinglulu #include "socfpga_handoff.h"
23*91f16700Schasinglulu #include "socfpga_mailbox.h"
24*91f16700Schasinglulu #include "socfpga_private.h"
25*91f16700Schasinglulu #include "socfpga_reset_manager.h"
26*91f16700Schasinglulu #include "socfpga_system_manager.h"
27*91f16700Schasinglulu #include "s10_clock_manager.h"
28*91f16700Schasinglulu #include "s10_memory_controller.h"
29*91f16700Schasinglulu #include "s10_mmc.h"
30*91f16700Schasinglulu #include "s10_pinmux.h"
31*91f16700Schasinglulu #include "wdt/watchdog.h"
32*91f16700Schasinglulu 
33*91f16700Schasinglulu static struct mmc_device_info mmc_info;
34*91f16700Schasinglulu 
35*91f16700Schasinglulu const mmap_region_t plat_stratix10_mmap[] = {
36*91f16700Schasinglulu 	MAP_REGION_FLAT(DRAM_BASE, DRAM_SIZE,
37*91f16700Schasinglulu 		MT_MEMORY | MT_RW | MT_NS),
38*91f16700Schasinglulu 	MAP_REGION_FLAT(DEVICE1_BASE, DEVICE1_SIZE,
39*91f16700Schasinglulu 		MT_DEVICE | MT_RW | MT_NS),
40*91f16700Schasinglulu 	MAP_REGION_FLAT(DEVICE2_BASE, DEVICE2_SIZE,
41*91f16700Schasinglulu 		MT_DEVICE | MT_RW | MT_SECURE),
42*91f16700Schasinglulu 	MAP_REGION_FLAT(OCRAM_BASE, OCRAM_SIZE,
43*91f16700Schasinglulu 		MT_NON_CACHEABLE | MT_RW | MT_SECURE),
44*91f16700Schasinglulu 	MAP_REGION_FLAT(DEVICE3_BASE, DEVICE3_SIZE,
45*91f16700Schasinglulu 		MT_DEVICE | MT_RW | MT_SECURE),
46*91f16700Schasinglulu 	MAP_REGION_FLAT(MEM64_BASE, MEM64_SIZE,
47*91f16700Schasinglulu 		MT_DEVICE | MT_RW | MT_NS),
48*91f16700Schasinglulu 	MAP_REGION_FLAT(DEVICE4_BASE, DEVICE4_SIZE,
49*91f16700Schasinglulu 		MT_DEVICE | MT_RW | MT_NS),
50*91f16700Schasinglulu 	{0},
51*91f16700Schasinglulu };
52*91f16700Schasinglulu 
53*91f16700Schasinglulu boot_source_type boot_source = BOOT_SOURCE;
54*91f16700Schasinglulu 
55*91f16700Schasinglulu void bl2_el3_early_platform_setup(u_register_t x0, u_register_t x1,
56*91f16700Schasinglulu 				u_register_t x2, u_register_t x4)
57*91f16700Schasinglulu {
58*91f16700Schasinglulu 	static console_t console;
59*91f16700Schasinglulu 	handoff reverse_handoff_ptr;
60*91f16700Schasinglulu 
61*91f16700Schasinglulu 	generic_delay_timer_init();
62*91f16700Schasinglulu 
63*91f16700Schasinglulu 	if (socfpga_get_handoff(&reverse_handoff_ptr))
64*91f16700Schasinglulu 		return;
65*91f16700Schasinglulu 	config_pinmux(&reverse_handoff_ptr);
66*91f16700Schasinglulu 
67*91f16700Schasinglulu 	config_clkmgr_handoff(&reverse_handoff_ptr);
68*91f16700Schasinglulu 	enable_nonsecure_access();
69*91f16700Schasinglulu 	deassert_peripheral_reset();
70*91f16700Schasinglulu 	config_hps_hs_before_warm_reset();
71*91f16700Schasinglulu 
72*91f16700Schasinglulu 	watchdog_init(get_wdt_clk());
73*91f16700Schasinglulu 
74*91f16700Schasinglulu 	console_16550_register(PLAT_INTEL_UART_BASE, get_uart_clk(),
75*91f16700Schasinglulu 		PLAT_BAUDRATE, &console);
76*91f16700Schasinglulu 
77*91f16700Schasinglulu 	socfpga_emac_init();
78*91f16700Schasinglulu 	socfpga_delay_timer_init();
79*91f16700Schasinglulu 	init_hard_memory_controller();
80*91f16700Schasinglulu 	mailbox_init();
81*91f16700Schasinglulu 	s10_mmc_init();
82*91f16700Schasinglulu 
83*91f16700Schasinglulu 	if (!intel_mailbox_is_fpga_not_ready()) {
84*91f16700Schasinglulu 		socfpga_bridges_enable(SOC2FPGA_MASK | LWHPS2FPGA_MASK |
85*91f16700Schasinglulu 					FPGA2SOC_MASK | F2SDRAM0_MASK | F2SDRAM1_MASK |
86*91f16700Schasinglulu 					F2SDRAM2_MASK);
87*91f16700Schasinglulu 	}
88*91f16700Schasinglulu }
89*91f16700Schasinglulu 
90*91f16700Schasinglulu 
91*91f16700Schasinglulu void bl2_el3_plat_arch_setup(void)
92*91f16700Schasinglulu {
93*91f16700Schasinglulu 
94*91f16700Schasinglulu 	const mmap_region_t bl_regions[] = {
95*91f16700Schasinglulu 		MAP_REGION_FLAT(BL2_BASE, BL2_END - BL2_BASE,
96*91f16700Schasinglulu 			MT_MEMORY | MT_RW | MT_SECURE),
97*91f16700Schasinglulu 		MAP_REGION_FLAT(BL_CODE_BASE, BL_CODE_END - BL_CODE_BASE,
98*91f16700Schasinglulu 			MT_CODE | MT_SECURE),
99*91f16700Schasinglulu 		MAP_REGION_FLAT(BL_RO_DATA_BASE,
100*91f16700Schasinglulu 			BL_RO_DATA_END - BL_RO_DATA_BASE,
101*91f16700Schasinglulu 			MT_RO_DATA | MT_SECURE),
102*91f16700Schasinglulu #if USE_COHERENT_MEM_BAR
103*91f16700Schasinglulu 		MAP_REGION_FLAT(BL_COHERENT_RAM_BASE,
104*91f16700Schasinglulu 			BL_COHERENT_RAM_END - BL_COHERENT_RAM_BASE,
105*91f16700Schasinglulu 			MT_DEVICE | MT_RW | MT_SECURE),
106*91f16700Schasinglulu #endif
107*91f16700Schasinglulu 		{0},
108*91f16700Schasinglulu 	};
109*91f16700Schasinglulu 
110*91f16700Schasinglulu 	setup_page_tables(bl_regions, plat_stratix10_mmap);
111*91f16700Schasinglulu 
112*91f16700Schasinglulu 	enable_mmu_el3(0);
113*91f16700Schasinglulu 
114*91f16700Schasinglulu 	dw_mmc_params_t params = EMMC_INIT_PARAMS(0x100000, get_mmc_clk());
115*91f16700Schasinglulu 
116*91f16700Schasinglulu 	mmc_info.mmc_dev_type = MMC_IS_SD;
117*91f16700Schasinglulu 	mmc_info.ocr_voltage = OCR_3_3_3_4 | OCR_3_2_3_3;
118*91f16700Schasinglulu 
119*91f16700Schasinglulu 	/* Request ownership and direct access to QSPI */
120*91f16700Schasinglulu 	mailbox_hps_qspi_enable();
121*91f16700Schasinglulu 
122*91f16700Schasinglulu 	switch (boot_source) {
123*91f16700Schasinglulu 	case BOOT_SOURCE_SDMMC:
124*91f16700Schasinglulu 		dw_mmc_init(&params, &mmc_info);
125*91f16700Schasinglulu 		socfpga_io_setup(boot_source);
126*91f16700Schasinglulu 		break;
127*91f16700Schasinglulu 
128*91f16700Schasinglulu 	case BOOT_SOURCE_QSPI:
129*91f16700Schasinglulu 		cad_qspi_init(0, QSPI_CONFIG_CPHA, QSPI_CONFIG_CPOL,
130*91f16700Schasinglulu 			QSPI_CONFIG_CSDA, QSPI_CONFIG_CSDADS,
131*91f16700Schasinglulu 			QSPI_CONFIG_CSEOT, QSPI_CONFIG_CSSOT, 0);
132*91f16700Schasinglulu 		socfpga_io_setup(boot_source);
133*91f16700Schasinglulu 		break;
134*91f16700Schasinglulu 
135*91f16700Schasinglulu 	default:
136*91f16700Schasinglulu 		ERROR("Unsupported boot source\n");
137*91f16700Schasinglulu 		panic();
138*91f16700Schasinglulu 		break;
139*91f16700Schasinglulu 	}
140*91f16700Schasinglulu }
141*91f16700Schasinglulu 
142*91f16700Schasinglulu uint32_t get_spsr_for_bl33_entry(void)
143*91f16700Schasinglulu {
144*91f16700Schasinglulu 	unsigned long el_status;
145*91f16700Schasinglulu 	unsigned int mode;
146*91f16700Schasinglulu 	uint32_t spsr;
147*91f16700Schasinglulu 
148*91f16700Schasinglulu 	/* Figure out what mode we enter the non-secure world in */
149*91f16700Schasinglulu 	el_status = read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL2_SHIFT;
150*91f16700Schasinglulu 	el_status &= ID_AA64PFR0_ELX_MASK;
151*91f16700Schasinglulu 
152*91f16700Schasinglulu 	mode = (el_status) ? MODE_EL2 : MODE_EL1;
153*91f16700Schasinglulu 
154*91f16700Schasinglulu 	/*
155*91f16700Schasinglulu 	 * TODO: Consider the possibility of specifying the SPSR in
156*91f16700Schasinglulu 	 * the FIP ToC and allowing the platform to have a say as
157*91f16700Schasinglulu 	 * well.
158*91f16700Schasinglulu 	 */
159*91f16700Schasinglulu 	spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
160*91f16700Schasinglulu 	return spsr;
161*91f16700Schasinglulu }
162*91f16700Schasinglulu 
163*91f16700Schasinglulu 
164*91f16700Schasinglulu int bl2_plat_handle_post_image_load(unsigned int image_id)
165*91f16700Schasinglulu {
166*91f16700Schasinglulu 	bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
167*91f16700Schasinglulu 
168*91f16700Schasinglulu 	assert(bl_mem_params);
169*91f16700Schasinglulu 
170*91f16700Schasinglulu 	switch (image_id) {
171*91f16700Schasinglulu 	case BL33_IMAGE_ID:
172*91f16700Schasinglulu 		bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
173*91f16700Schasinglulu 		bl_mem_params->ep_info.spsr = get_spsr_for_bl33_entry();
174*91f16700Schasinglulu 		break;
175*91f16700Schasinglulu 	default:
176*91f16700Schasinglulu 		break;
177*91f16700Schasinglulu 	}
178*91f16700Schasinglulu 
179*91f16700Schasinglulu 	return 0;
180*91f16700Schasinglulu }
181*91f16700Schasinglulu 
182*91f16700Schasinglulu /*******************************************************************************
183*91f16700Schasinglulu  * Perform any BL3-1 platform setup code
184*91f16700Schasinglulu  ******************************************************************************/
185*91f16700Schasinglulu void bl2_platform_setup(void)
186*91f16700Schasinglulu {
187*91f16700Schasinglulu }
188*91f16700Schasinglulu 
189