1*91f16700Schasinglulu /* 2*91f16700Schasinglulu * Copyright (c) 2020, ARM Limited and Contributors. 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 <common/bl_common.h> 9*91f16700Schasinglulu #include <common/interrupt_props.h> 10*91f16700Schasinglulu #include <drivers/arm/gicv2.h> 11*91f16700Schasinglulu #include <lib/mmio.h> 12*91f16700Schasinglulu #include <lib/xlat_tables/xlat_mmu_helpers.h> 13*91f16700Schasinglulu #include <plat/common/platform.h> 14*91f16700Schasinglulu #include <platform_def.h> 15*91f16700Schasinglulu 16*91f16700Schasinglulu #include "aml_private.h" 17*91f16700Schasinglulu 18*91f16700Schasinglulu /* 19*91f16700Schasinglulu * Placeholder variables for copying the arguments that have been passed to 20*91f16700Schasinglulu * BL31 from BL2. 21*91f16700Schasinglulu */ 22*91f16700Schasinglulu static entry_point_info_t bl32_image_ep_info; 23*91f16700Schasinglulu static entry_point_info_t bl33_image_ep_info; 24*91f16700Schasinglulu static image_info_t bl30_image_info; 25*91f16700Schasinglulu static image_info_t bl301_image_info; 26*91f16700Schasinglulu 27*91f16700Schasinglulu /******************************************************************************* 28*91f16700Schasinglulu * Return a pointer to the 'entry_point_info' structure of the next image for 29*91f16700Schasinglulu * the security state specified. BL33 corresponds to the non-secure image type 30*91f16700Schasinglulu * while BL32 corresponds to the secure image type. A NULL pointer is returned 31*91f16700Schasinglulu * if the image does not exist. 32*91f16700Schasinglulu ******************************************************************************/ 33*91f16700Schasinglulu entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) 34*91f16700Schasinglulu { 35*91f16700Schasinglulu entry_point_info_t *next_image_info; 36*91f16700Schasinglulu 37*91f16700Schasinglulu next_image_info = (type == NON_SECURE) ? 38*91f16700Schasinglulu &bl33_image_ep_info : &bl32_image_ep_info; 39*91f16700Schasinglulu 40*91f16700Schasinglulu /* None of the images can have 0x0 as the entrypoint. */ 41*91f16700Schasinglulu if (next_image_info->pc != 0U) 42*91f16700Schasinglulu return next_image_info; 43*91f16700Schasinglulu 44*91f16700Schasinglulu return NULL; 45*91f16700Schasinglulu } 46*91f16700Schasinglulu 47*91f16700Schasinglulu /******************************************************************************* 48*91f16700Schasinglulu * Perform any BL31 early platform setup. Here is an opportunity to copy 49*91f16700Schasinglulu * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before 50*91f16700Schasinglulu * they are lost (potentially). This needs to be done before the MMU is 51*91f16700Schasinglulu * initialized so that the memory layout can be used while creating page 52*91f16700Schasinglulu * tables. BL2 has flushed this information to memory, so we are guaranteed 53*91f16700Schasinglulu * to pick up good data. 54*91f16700Schasinglulu ******************************************************************************/ 55*91f16700Schasinglulu struct axg_bl31_param { 56*91f16700Schasinglulu param_header_t h; 57*91f16700Schasinglulu image_info_t *bl31_image_info; 58*91f16700Schasinglulu entry_point_info_t *bl32_ep_info; 59*91f16700Schasinglulu image_info_t *bl32_image_info; 60*91f16700Schasinglulu entry_point_info_t *bl33_ep_info; 61*91f16700Schasinglulu image_info_t *bl33_image_info; 62*91f16700Schasinglulu image_info_t *scp_image_info[]; 63*91f16700Schasinglulu }; 64*91f16700Schasinglulu 65*91f16700Schasinglulu void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1, 66*91f16700Schasinglulu u_register_t arg2, u_register_t arg3) 67*91f16700Schasinglulu { 68*91f16700Schasinglulu struct axg_bl31_param *from_bl2; 69*91f16700Schasinglulu 70*91f16700Schasinglulu /* Initialize the console to provide early debug support */ 71*91f16700Schasinglulu aml_console_init(); 72*91f16700Schasinglulu 73*91f16700Schasinglulu from_bl2 = (struct axg_bl31_param *)arg0; 74*91f16700Schasinglulu 75*91f16700Schasinglulu /* Check params passed from BL2 are not NULL. */ 76*91f16700Schasinglulu assert(from_bl2 != NULL); 77*91f16700Schasinglulu assert(from_bl2->h.type == PARAM_BL31); 78*91f16700Schasinglulu assert(from_bl2->h.version >= VERSION_1); 79*91f16700Schasinglulu 80*91f16700Schasinglulu /* 81*91f16700Schasinglulu * Copy BL32 and BL33 entry point information. It is stored in Secure 82*91f16700Schasinglulu * RAM, in BL2's address space. 83*91f16700Schasinglulu */ 84*91f16700Schasinglulu bl32_image_ep_info = *from_bl2->bl32_ep_info; 85*91f16700Schasinglulu bl33_image_ep_info = *from_bl2->bl33_ep_info; 86*91f16700Schasinglulu 87*91f16700Schasinglulu #if AML_USE_ATOS 88*91f16700Schasinglulu /* 89*91f16700Schasinglulu * BL2 is unconditionally setting 0 (OPTEE_AARCH64) in arg0 even when 90*91f16700Schasinglulu * the BL32 image is 32bit (OPTEE_AARCH32). This is causing the boot to 91*91f16700Schasinglulu * hang when ATOS (32bit Amlogic BL32 binary-only TEE OS) is used. 92*91f16700Schasinglulu * 93*91f16700Schasinglulu * Hardcode to OPTEE_AARCH32 / MODE_RW_32. 94*91f16700Schasinglulu */ 95*91f16700Schasinglulu bl32_image_ep_info.args.arg0 = MODE_RW_32; 96*91f16700Schasinglulu #endif 97*91f16700Schasinglulu 98*91f16700Schasinglulu if (bl33_image_ep_info.pc == 0U) { 99*91f16700Schasinglulu ERROR("BL31: BL33 entrypoint not obtained from BL2\n"); 100*91f16700Schasinglulu panic(); 101*91f16700Schasinglulu } 102*91f16700Schasinglulu 103*91f16700Schasinglulu bl30_image_info = *from_bl2->scp_image_info[0]; 104*91f16700Schasinglulu bl301_image_info = *from_bl2->scp_image_info[1]; 105*91f16700Schasinglulu } 106*91f16700Schasinglulu 107*91f16700Schasinglulu void bl31_plat_arch_setup(void) 108*91f16700Schasinglulu { 109*91f16700Schasinglulu aml_setup_page_tables(); 110*91f16700Schasinglulu 111*91f16700Schasinglulu enable_mmu_el3(0); 112*91f16700Schasinglulu } 113*91f16700Schasinglulu 114*91f16700Schasinglulu static inline bool axg_scp_ready(void) 115*91f16700Schasinglulu { 116*91f16700Schasinglulu return AML_AO_RTI_SCP_IS_READY(mmio_read_32(AML_AO_RTI_SCP_STAT)); 117*91f16700Schasinglulu } 118*91f16700Schasinglulu 119*91f16700Schasinglulu static inline void axg_scp_boot(void) 120*91f16700Schasinglulu { 121*91f16700Schasinglulu aml_scpi_upload_scp_fw(bl30_image_info.image_base, 122*91f16700Schasinglulu bl30_image_info.image_size, 0); 123*91f16700Schasinglulu aml_scpi_upload_scp_fw(bl301_image_info.image_base, 124*91f16700Schasinglulu bl301_image_info.image_size, 1); 125*91f16700Schasinglulu while (!axg_scp_ready()) 126*91f16700Schasinglulu ; 127*91f16700Schasinglulu } 128*91f16700Schasinglulu 129*91f16700Schasinglulu /******************************************************************************* 130*91f16700Schasinglulu * GICv2 driver setup information 131*91f16700Schasinglulu ******************************************************************************/ 132*91f16700Schasinglulu static const interrupt_prop_t axg_interrupt_props[] = { 133*91f16700Schasinglulu INTR_PROP_DESC(IRQ_SEC_PHY_TIMER, GIC_HIGHEST_SEC_PRIORITY, 134*91f16700Schasinglulu GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL), 135*91f16700Schasinglulu INTR_PROP_DESC(IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY, 136*91f16700Schasinglulu GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL), 137*91f16700Schasinglulu INTR_PROP_DESC(IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY, 138*91f16700Schasinglulu GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL), 139*91f16700Schasinglulu INTR_PROP_DESC(IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY, 140*91f16700Schasinglulu GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL), 141*91f16700Schasinglulu INTR_PROP_DESC(IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY, 142*91f16700Schasinglulu GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL), 143*91f16700Schasinglulu INTR_PROP_DESC(IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY, 144*91f16700Schasinglulu GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL), 145*91f16700Schasinglulu INTR_PROP_DESC(IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY, 146*91f16700Schasinglulu GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL), 147*91f16700Schasinglulu INTR_PROP_DESC(IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY, 148*91f16700Schasinglulu GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL), 149*91f16700Schasinglulu INTR_PROP_DESC(IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY, 150*91f16700Schasinglulu GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL) 151*91f16700Schasinglulu }; 152*91f16700Schasinglulu 153*91f16700Schasinglulu static const gicv2_driver_data_t axg_gic_data = { 154*91f16700Schasinglulu .gicd_base = AML_GICD_BASE, 155*91f16700Schasinglulu .gicc_base = AML_GICC_BASE, 156*91f16700Schasinglulu .interrupt_props = axg_interrupt_props, 157*91f16700Schasinglulu .interrupt_props_num = ARRAY_SIZE(axg_interrupt_props) 158*91f16700Schasinglulu }; 159*91f16700Schasinglulu 160*91f16700Schasinglulu void bl31_platform_setup(void) 161*91f16700Schasinglulu { 162*91f16700Schasinglulu aml_mhu_secure_init(); 163*91f16700Schasinglulu 164*91f16700Schasinglulu gicv2_driver_init(&axg_gic_data); 165*91f16700Schasinglulu gicv2_distif_init(); 166*91f16700Schasinglulu gicv2_pcpu_distif_init(); 167*91f16700Schasinglulu gicv2_cpuif_enable(); 168*91f16700Schasinglulu 169*91f16700Schasinglulu axg_scp_boot(); 170*91f16700Schasinglulu } 171