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