blob: fe5dc6e71bd5adb5eda41865f16fa4aea2ba79c0 [file] [log] [blame]
Jit Loon Lim4c249f12023-05-17 12:26:11 +08001/*
2 * Copyright (c) 2019-2021, ARM Limited and Contributors. All rights reserved.
3 * Copyright (c) 2019-2023, Intel Corporation. All rights reserved.
Sieu Mun Tang6848bd62024-07-20 00:43:43 +08004 * Copyright (c) 2024, Altera Corporation. All rights reserved.
Jit Loon Lim4c249f12023-05-17 12:26:11 +08005 *
6 * SPDX-License-Identifier: BSD-3-Clause
7 */
8
9#include <assert.h>
10#include <arch.h>
11#include <arch_helpers.h>
12#include <common/bl_common.h>
13#include <common/debug.h>
14#include <common/desc_image_load.h>
15#include <drivers/cadence/cdns_sdmmc.h>
16#include <drivers/generic_delay_timer.h>
17#include <drivers/synopsys/dw_mmc.h>
18#include <drivers/ti/uart/uart_16550.h>
19#include <lib/mmio.h>
20#include <lib/xlat_tables/xlat_tables_v2.h>
21
22#include "agilex5_clock_manager.h"
Sieu Mun Tang7bb345c2024-08-26 22:51:16 +080023#include "agilex5_ddr.h"
Jit Loon Lim4c249f12023-05-17 12:26:11 +080024#include "agilex5_memory_controller.h"
25#include "agilex5_mmc.h"
26#include "agilex5_pinmux.h"
Sieu Mun Tang85606722024-08-27 00:01:51 +080027#include "agilex5_power_manager.h"
Jit Loon Lim4c249f12023-05-17 12:26:11 +080028#include "agilex5_system_manager.h"
29#include "ccu/ncore_ccu.h"
30#include "combophy/combophy.h"
31#include "nand/nand.h"
32#include "qspi/cadence_qspi.h"
33#include "sdmmc/sdmmc.h"
34#include "socfpga_emac.h"
35#include "socfpga_f2sdram_manager.h"
36#include "socfpga_handoff.h"
37#include "socfpga_mailbox.h"
38#include "socfpga_private.h"
39#include "socfpga_reset_manager.h"
Mahesh Raoc2715992023-08-22 17:26:23 +080040#include "socfpga_ros.h"
Sieu Mun Tang6848bd62024-07-20 00:43:43 +080041#include "socfpga_vab.h"
Jit Loon Lim4c249f12023-05-17 12:26:11 +080042#include "wdt/watchdog.h"
43
44
45/* Declare mmc_info */
46static struct mmc_device_info mmc_info;
47
48/* Declare cadence idmac descriptor */
49extern struct cdns_idmac_desc cdns_desc[8] __aligned(32);
50
51const mmap_region_t agilex_plat_mmap[] = {
52 MAP_REGION_FLAT(DRAM_BASE, DRAM_SIZE,
53 MT_MEMORY | MT_RW | MT_NS),
54 MAP_REGION_FLAT(PSS_BASE, PSS_SIZE,
55 MT_DEVICE | MT_RW | MT_NS),
56 MAP_REGION_FLAT(MPFE_BASE, MPFE_SIZE,
57 MT_DEVICE | MT_RW | MT_SECURE),
58 MAP_REGION_FLAT(OCRAM_BASE, OCRAM_SIZE,
59 MT_NON_CACHEABLE | MT_RW | MT_SECURE),
60 MAP_REGION_FLAT(CCU_BASE, CCU_SIZE,
61 MT_DEVICE | MT_RW | MT_SECURE),
62 MAP_REGION_FLAT(MEM64_BASE, MEM64_SIZE,
63 MT_DEVICE | MT_RW | MT_NS),
64 MAP_REGION_FLAT(GIC_BASE, GIC_SIZE,
65 MT_DEVICE | MT_RW | MT_SECURE),
66 {0},
67};
68
69boot_source_type boot_source = BOOT_SOURCE;
70
Sieu Mun Tangf5ab8362024-10-24 19:23:42 +080071void bl2_el3_early_platform_setup(u_register_t x0 __unused,
72 u_register_t x1 __unused,
73 u_register_t x2 __unused,
74 u_register_t x3 __unused)
Jit Loon Lim4c249f12023-05-17 12:26:11 +080075{
76 static console_t console;
Sieu Mun Tang85606722024-08-27 00:01:51 +080077 handoff reverse_handoff_ptr;
Jit Loon Lim4c249f12023-05-17 12:26:11 +080078
Sieu Mun Tang85606722024-08-27 00:01:51 +080079 /* Enable nonsecure access for peripherals and other misc components */
80 enable_nonsecure_access();
81
82 /* Bring all the required peripherals out of reset */
83 deassert_peripheral_reset();
84
85 /*
86 * Initialize the UART console early in BL2 EL3 boot flow to get
87 * the error/notice messages wherever required.
88 */
89 console_16550_register(PLAT_INTEL_UART_BASE, PLAT_UART_CLOCK,
90 PLAT_BAUDRATE, &console);
Jit Loon Lim4c249f12023-05-17 12:26:11 +080091
Sieu Mun Tang85606722024-08-27 00:01:51 +080092 /* Generic delay timer init */
Jit Loon Lim4c249f12023-05-17 12:26:11 +080093 generic_delay_timer_init();
Sieu Mun Tang85606722024-08-27 00:01:51 +080094
95 socfpga_delay_timer_init();
96
97 /* Get the handoff data */
98 if ((socfpga_get_handoff(&reverse_handoff_ptr)) != 0) {
Sieu Mun Tangf5ab8362024-10-24 19:23:42 +080099 ERROR("SOCFPGA: Failed to get the correct handoff data\n");
Sieu Mun Tang85606722024-08-27 00:01:51 +0800100 panic();
101 }
102
Sieu Mun Tangf5ab8362024-10-24 19:23:42 +0800103 /* Configure the pinmux */
104 config_pinmux(&reverse_handoff_ptr);
105
Sieu Mun Tang31464052024-10-25 09:37:42 +0800106 /* Configure OCRAM to NON SECURE ACCESS */
107 mmio_write_32(OCRAM_REGION_0_REG_BASE, OCRAM_NON_SECURE_ENABLE);
108 mmio_write_32(SOCFPGA_L4_PER_SCR_REG_BASE + SOCFPGA_SDMMC_SECU_BIT,
109 SOCFPGA_SDMMC_SECU_BIT_ENABLE);
110 mmio_write_32(SOCFPGA_L4_SYS_SCR_REG_BASE + SOCFPGA_SDMMC_SECU_BIT,
111 SOCFPGA_SDMMC_SECU_BIT_ENABLE);
112 mmio_write_32(SOCFPGA_LWSOC2FPGA_SCR_REG_BASE,
113 SOCFPGA_LWSOC2FPGA_ENABLE);
114
Sieu Mun Tangf5ab8362024-10-24 19:23:42 +0800115 /* Configure the clock manager */
116 if ((config_clkmgr_handoff(&reverse_handoff_ptr)) != 0) {
117 ERROR("SOCFPGA: Failed to initialize the clock manager\n");
118 panic();
119 }
120
Sieu Mun Tang85606722024-08-27 00:01:51 +0800121 /* Configure power manager PSS SRAM power gate */
122 config_pwrmgr_handoff(&reverse_handoff_ptr);
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800123
Sieu Mun Tang85606722024-08-27 00:01:51 +0800124 /* Initialize the mailbox to enable communication between HPS and SDM */
125 mailbox_init();
Sieu Mun Tang7bb345c2024-08-26 22:51:16 +0800126
Sieu Mun Tangf5ab8362024-10-24 19:23:42 +0800127 /* Perform a handshake with certain peripherals before issuing a reset */
128 config_hps_hs_before_warm_reset();
129
130 /* TODO: watchdog init */
131 //watchdog_init(clkmgr_get_rate(CLKMGR_WDT_CLK_ID));
132
133 /* Initialize the CCU module for hardware cache coherency */
134 init_ncore_ccu();
135
136 socfpga_emac_init();
137
Sieu Mun Tang7bb345c2024-08-26 22:51:16 +0800138 /* DDR and IOSSM driver init */
139 agilex5_ddr_init(&reverse_handoff_ptr);
140
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800141 if (combo_phy_init(&reverse_handoff_ptr) != 0) {
Sieu Mun Tangf5ab8362024-10-24 19:23:42 +0800142 ERROR("SOCFPGA: Combo Phy initialization failed\n");
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800143 }
144
Sieu Mun Tang85606722024-08-27 00:01:51 +0800145 /* Enable FPGA bridges as required */
Sieu Mun Tangeede0992023-12-22 00:26:42 +0800146 if (!intel_mailbox_is_fpga_not_ready()) {
147 socfpga_bridges_enable(SOC2FPGA_MASK | LWHPS2FPGA_MASK |
Sieu Mun Tang85606722024-08-27 00:01:51 +0800148 FPGA2SOC_MASK | F2SDRAM0_MASK);
Sieu Mun Tangeede0992023-12-22 00:26:42 +0800149 }
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800150}
151
152void bl2_el3_plat_arch_setup(void)
153{
154 handoff reverse_handoff_ptr;
Mahesh Raoc2715992023-08-22 17:26:23 +0800155 unsigned long offset = 0;
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800156
Sieu Mun Tang81410d32024-10-25 09:22:00 +0800157 struct cdns_sdmmc_params params = EMMC_INIT_PARAMS((uintptr_t) &cdns_desc,
158 clkmgr_get_rate(CLKMGR_SDMMC_CLK_ID));
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800159
160 mmc_info.mmc_dev_type = MMC_DEVICE_TYPE;
161 mmc_info.ocr_voltage = OCR_3_3_3_4 | OCR_3_2_3_3;
162
163 /* Request ownership and direct access to QSPI */
164 mailbox_hps_qspi_enable();
165
166 switch (boot_source) {
167 case BOOT_SOURCE_SDMMC:
168 NOTICE("SDMMC boot\n");
Sieu Mun Tang31464052024-10-25 09:37:42 +0800169 cdns_mmc_init(&params, &mmc_info);
Mahesh Raoc2715992023-08-22 17:26:23 +0800170 socfpga_io_setup(boot_source, PLAT_SDMMC_DATA_BASE);
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800171 break;
172
173 case BOOT_SOURCE_QSPI:
174 NOTICE("QSPI boot\n");
175 cad_qspi_init(0, QSPI_CONFIG_CPHA, QSPI_CONFIG_CPOL,
176 QSPI_CONFIG_CSDA, QSPI_CONFIG_CSDADS,
177 QSPI_CONFIG_CSEOT, QSPI_CONFIG_CSSOT, 0);
Mahesh Raoc2715992023-08-22 17:26:23 +0800178 if (ros_qspi_get_ssbl_offset(&offset) != ROS_RET_OK) {
179 offset = PLAT_QSPI_DATA_BASE;
180 }
181 socfpga_io_setup(boot_source, offset);
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800182 break;
183
184 case BOOT_SOURCE_NAND:
185 NOTICE("NAND boot\n");
186 nand_init(&reverse_handoff_ptr);
Mahesh Raoc2715992023-08-22 17:26:23 +0800187 socfpga_io_setup(boot_source, PLAT_NAND_DATA_BASE);
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800188 break;
189
190 default:
191 ERROR("Unsupported boot source\n");
192 panic();
193 break;
194 }
195}
196
197uint32_t get_spsr_for_bl33_entry(void)
198{
199 unsigned long el_status;
200 unsigned int mode;
201 uint32_t spsr;
202
203 /* Figure out what mode we enter the non-secure world in */
204 el_status = read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL2_SHIFT;
205 el_status &= ID_AA64PFR0_ELX_MASK;
206
207 mode = (el_status) ? MODE_EL2 : MODE_EL1;
208
209 /*
210 * TODO: Consider the possibility of specifying the SPSR in
211 * the FIP ToC and allowing the platform to have a say as
212 * well.
213 */
214 spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
215 return spsr;
216}
217
218int bl2_plat_handle_post_image_load(unsigned int image_id)
219{
220 bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
221
222 assert(bl_mem_params);
223
Sieu Mun Tang6848bd62024-07-20 00:43:43 +0800224#if SOCFPGA_SECURE_VAB_AUTH
225 /*
226 * VAB Authentication start here.
227 * If failed to authenticate, shall not proceed to process BL31 and hang.
228 */
229 int ret = 0;
230
231 ret = socfpga_vab_init(image_id);
232 if (ret < 0) {
233 ERROR("SOCFPGA VAB Authentication failed\n");
234 wfi();
235 }
236#endif
237
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800238 switch (image_id) {
239 case BL33_IMAGE_ID:
240 bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
241 bl_mem_params->ep_info.spsr = get_spsr_for_bl33_entry();
242 break;
243 default:
244 break;
245 }
246
247 return 0;
248}
249
250/*******************************************************************************
251 * Perform any BL3-1 platform setup code
252 ******************************************************************************/
253void bl2_platform_setup(void)
254{
255}