blob: 9f512601b1ef9aaf7de466248c10d16bc3959cc7 [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"
27#include "agilex5_system_manager.h"
28#include "ccu/ncore_ccu.h"
29#include "combophy/combophy.h"
30#include "nand/nand.h"
31#include "qspi/cadence_qspi.h"
32#include "sdmmc/sdmmc.h"
33#include "socfpga_emac.h"
34#include "socfpga_f2sdram_manager.h"
35#include "socfpga_handoff.h"
36#include "socfpga_mailbox.h"
37#include "socfpga_private.h"
38#include "socfpga_reset_manager.h"
Mahesh Raoc2715992023-08-22 17:26:23 +080039#include "socfpga_ros.h"
Sieu Mun Tang6848bd62024-07-20 00:43:43 +080040#include "socfpga_vab.h"
Jit Loon Lim4c249f12023-05-17 12:26:11 +080041#include "wdt/watchdog.h"
42
43
44/* Declare mmc_info */
45static struct mmc_device_info mmc_info;
46
47/* Declare cadence idmac descriptor */
48extern struct cdns_idmac_desc cdns_desc[8] __aligned(32);
49
50const mmap_region_t agilex_plat_mmap[] = {
51 MAP_REGION_FLAT(DRAM_BASE, DRAM_SIZE,
52 MT_MEMORY | MT_RW | MT_NS),
53 MAP_REGION_FLAT(PSS_BASE, PSS_SIZE,
54 MT_DEVICE | MT_RW | MT_NS),
55 MAP_REGION_FLAT(MPFE_BASE, MPFE_SIZE,
56 MT_DEVICE | MT_RW | MT_SECURE),
57 MAP_REGION_FLAT(OCRAM_BASE, OCRAM_SIZE,
58 MT_NON_CACHEABLE | MT_RW | MT_SECURE),
59 MAP_REGION_FLAT(CCU_BASE, CCU_SIZE,
60 MT_DEVICE | MT_RW | MT_SECURE),
61 MAP_REGION_FLAT(MEM64_BASE, MEM64_SIZE,
62 MT_DEVICE | MT_RW | MT_NS),
63 MAP_REGION_FLAT(GIC_BASE, GIC_SIZE,
64 MT_DEVICE | MT_RW | MT_SECURE),
65 {0},
66};
67
68boot_source_type boot_source = BOOT_SOURCE;
69
70void bl2_el3_early_platform_setup(u_register_t x0, u_register_t x1,
71 u_register_t x2, u_register_t x4)
72{
73 static console_t console;
74
Sieu Mun Tang2b3ac0b2023-07-08 02:30:08 +080075 handoff reverse_handoff_ptr = { 0 };
Jit Loon Lim4c249f12023-05-17 12:26:11 +080076
77 generic_delay_timer_init();
78 config_clkmgr_handoff(&reverse_handoff_ptr);
79 mailbox_init();
80 enable_nonsecure_access();
81
82 deassert_peripheral_reset();
Sieu Mun Tang7bb345c2024-08-26 22:51:16 +080083
84 /* DDR and IOSSM driver init */
85 agilex5_ddr_init(&reverse_handoff_ptr);
86
Jit Loon Lim4c249f12023-05-17 12:26:11 +080087 if (combo_phy_init(&reverse_handoff_ptr) != 0) {
88 ERROR("Combo Phy initialization failed\n");
89 }
90
91 console_16550_register(PLAT_INTEL_UART_BASE, PLAT_UART_CLOCK,
92 PLAT_BAUDRATE, &console);
93
94 /* Store magic number */
Sieu Mun Tang33a0de72023-08-01 13:43:26 +080095 // TODO: Temp workaround to ungate testing
96 // mmio_write_32(L2_RESET_DONE_REG, PLAT_L2_RESET_REQ);
Sieu Mun Tangeede0992023-12-22 00:26:42 +080097
98 if (!intel_mailbox_is_fpga_not_ready()) {
99 socfpga_bridges_enable(SOC2FPGA_MASK | LWHPS2FPGA_MASK |
100 FPGA2SOC_MASK | F2SDRAM0_MASK);
101 }
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800102}
103
104void bl2_el3_plat_arch_setup(void)
105{
106 handoff reverse_handoff_ptr;
Mahesh Raoc2715992023-08-22 17:26:23 +0800107 unsigned long offset = 0;
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800108
109 struct cdns_sdmmc_params params = EMMC_INIT_PARAMS((uintptr_t) &cdns_desc, get_mmc_clk());
110
111 mmc_info.mmc_dev_type = MMC_DEVICE_TYPE;
112 mmc_info.ocr_voltage = OCR_3_3_3_4 | OCR_3_2_3_3;
113
114 /* Request ownership and direct access to QSPI */
115 mailbox_hps_qspi_enable();
116
117 switch (boot_source) {
118 case BOOT_SOURCE_SDMMC:
119 NOTICE("SDMMC boot\n");
120 sdmmc_init(&reverse_handoff_ptr, &params, &mmc_info);
Mahesh Raoc2715992023-08-22 17:26:23 +0800121 socfpga_io_setup(boot_source, PLAT_SDMMC_DATA_BASE);
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800122 break;
123
124 case BOOT_SOURCE_QSPI:
125 NOTICE("QSPI boot\n");
126 cad_qspi_init(0, QSPI_CONFIG_CPHA, QSPI_CONFIG_CPOL,
127 QSPI_CONFIG_CSDA, QSPI_CONFIG_CSDADS,
128 QSPI_CONFIG_CSEOT, QSPI_CONFIG_CSSOT, 0);
Mahesh Raoc2715992023-08-22 17:26:23 +0800129 if (ros_qspi_get_ssbl_offset(&offset) != ROS_RET_OK) {
130 offset = PLAT_QSPI_DATA_BASE;
131 }
132 socfpga_io_setup(boot_source, offset);
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800133 break;
134
135 case BOOT_SOURCE_NAND:
136 NOTICE("NAND boot\n");
137 nand_init(&reverse_handoff_ptr);
Mahesh Raoc2715992023-08-22 17:26:23 +0800138 socfpga_io_setup(boot_source, PLAT_NAND_DATA_BASE);
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800139 break;
140
141 default:
142 ERROR("Unsupported boot source\n");
143 panic();
144 break;
145 }
146}
147
148uint32_t get_spsr_for_bl33_entry(void)
149{
150 unsigned long el_status;
151 unsigned int mode;
152 uint32_t spsr;
153
154 /* Figure out what mode we enter the non-secure world in */
155 el_status = read_id_aa64pfr0_el1() >> ID_AA64PFR0_EL2_SHIFT;
156 el_status &= ID_AA64PFR0_ELX_MASK;
157
158 mode = (el_status) ? MODE_EL2 : MODE_EL1;
159
160 /*
161 * TODO: Consider the possibility of specifying the SPSR in
162 * the FIP ToC and allowing the platform to have a say as
163 * well.
164 */
165 spsr = SPSR_64(mode, MODE_SP_ELX, DISABLE_ALL_EXCEPTIONS);
166 return spsr;
167}
168
169int bl2_plat_handle_post_image_load(unsigned int image_id)
170{
171 bl_mem_params_node_t *bl_mem_params = get_bl_mem_params_node(image_id);
172
173 assert(bl_mem_params);
174
Sieu Mun Tang6848bd62024-07-20 00:43:43 +0800175#if SOCFPGA_SECURE_VAB_AUTH
176 /*
177 * VAB Authentication start here.
178 * If failed to authenticate, shall not proceed to process BL31 and hang.
179 */
180 int ret = 0;
181
182 ret = socfpga_vab_init(image_id);
183 if (ret < 0) {
184 ERROR("SOCFPGA VAB Authentication failed\n");
185 wfi();
186 }
187#endif
188
Jit Loon Lim4c249f12023-05-17 12:26:11 +0800189 switch (image_id) {
190 case BL33_IMAGE_ID:
191 bl_mem_params->ep_info.args.arg0 = 0xffff & read_mpidr();
192 bl_mem_params->ep_info.spsr = get_spsr_for_bl33_entry();
193 break;
194 default:
195 break;
196 }
197
198 return 0;
199}
200
201/*******************************************************************************
202 * Perform any BL3-1 platform setup code
203 ******************************************************************************/
204void bl2_platform_setup(void)
205{
206}