1*91f16700Schasinglulu /* 2*91f16700Schasinglulu * Copyright (c) 2018-2019, 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 bl33_image_ep_info; 23*91f16700Schasinglulu static image_info_t bl30_image_info; 24*91f16700Schasinglulu static image_info_t bl301_image_info; 25*91f16700Schasinglulu 26*91f16700Schasinglulu /******************************************************************************* 27*91f16700Schasinglulu * Return a pointer to the 'entry_point_info' structure of the next image for 28*91f16700Schasinglulu * the security state specified. BL33 corresponds to the non-secure image type 29*91f16700Schasinglulu * while BL32 corresponds to the secure image type. A NULL pointer is returned 30*91f16700Schasinglulu * if the image does not exist. 31*91f16700Schasinglulu ******************************************************************************/ 32*91f16700Schasinglulu entry_point_info_t *bl31_plat_get_next_image_ep_info(uint32_t type) 33*91f16700Schasinglulu { 34*91f16700Schasinglulu entry_point_info_t *next_image_info; 35*91f16700Schasinglulu 36*91f16700Schasinglulu assert(type == NON_SECURE); 37*91f16700Schasinglulu 38*91f16700Schasinglulu next_image_info = &bl33_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 } else { 44*91f16700Schasinglulu return NULL; 45*91f16700Schasinglulu } 46*91f16700Schasinglulu } 47*91f16700Schasinglulu 48*91f16700Schasinglulu /******************************************************************************* 49*91f16700Schasinglulu * Perform any BL31 early platform setup. Here is an opportunity to copy 50*91f16700Schasinglulu * parameters passed by the calling EL (S-EL1 in BL2 & S-EL3 in BL1) before 51*91f16700Schasinglulu * they are lost (potentially). This needs to be done before the MMU is 52*91f16700Schasinglulu * initialized so that the memory layout can be used while creating page 53*91f16700Schasinglulu * tables. BL2 has flushed this information to memory, so we are guaranteed 54*91f16700Schasinglulu * to pick up good data. 55*91f16700Schasinglulu ******************************************************************************/ 56*91f16700Schasinglulu struct gxl_bl31_param { 57*91f16700Schasinglulu param_header_t h; 58*91f16700Schasinglulu image_info_t *bl31_image_info; 59*91f16700Schasinglulu entry_point_info_t *bl32_ep_info; 60*91f16700Schasinglulu image_info_t *bl32_image_info; 61*91f16700Schasinglulu entry_point_info_t *bl33_ep_info; 62*91f16700Schasinglulu image_info_t *bl33_image_info; 63*91f16700Schasinglulu image_info_t *scp_image_info[]; 64*91f16700Schasinglulu }; 65*91f16700Schasinglulu 66*91f16700Schasinglulu void bl31_early_platform_setup2(u_register_t arg0, u_register_t arg1, 67*91f16700Schasinglulu u_register_t arg2, u_register_t arg3) 68*91f16700Schasinglulu { 69*91f16700Schasinglulu struct gxl_bl31_param *from_bl2; 70*91f16700Schasinglulu 71*91f16700Schasinglulu /* Initialize the console to provide early debug support */ 72*91f16700Schasinglulu aml_console_init(); 73*91f16700Schasinglulu 74*91f16700Schasinglulu /* Check that params passed from BL2 are not NULL. */ 75*91f16700Schasinglulu from_bl2 = (struct gxl_bl31_param *) arg0; 76*91f16700Schasinglulu 77*91f16700Schasinglulu /* Check params passed from BL2 are not NULL. */ 78*91f16700Schasinglulu assert(from_bl2 != NULL); 79*91f16700Schasinglulu assert(from_bl2->h.type == PARAM_BL31); 80*91f16700Schasinglulu assert(from_bl2->h.version >= VERSION_1); 81*91f16700Schasinglulu 82*91f16700Schasinglulu /* 83*91f16700Schasinglulu * Copy BL33 entry point information. It is stored in Secure RAM, in 84*91f16700Schasinglulu * BL2's address space. 85*91f16700Schasinglulu */ 86*91f16700Schasinglulu bl33_image_ep_info = *from_bl2->bl33_ep_info; 87*91f16700Schasinglulu 88*91f16700Schasinglulu if (bl33_image_ep_info.pc == 0U) { 89*91f16700Schasinglulu ERROR("BL31: BL33 entrypoint not obtained from BL2\n"); 90*91f16700Schasinglulu panic(); 91*91f16700Schasinglulu } 92*91f16700Schasinglulu 93*91f16700Schasinglulu bl30_image_info = *from_bl2->scp_image_info[0]; 94*91f16700Schasinglulu bl301_image_info = *from_bl2->scp_image_info[1]; 95*91f16700Schasinglulu } 96*91f16700Schasinglulu 97*91f16700Schasinglulu void bl31_plat_arch_setup(void) 98*91f16700Schasinglulu { 99*91f16700Schasinglulu aml_setup_page_tables(); 100*91f16700Schasinglulu 101*91f16700Schasinglulu enable_mmu_el3(0); 102*91f16700Schasinglulu } 103*91f16700Schasinglulu 104*91f16700Schasinglulu static inline bool gxl_scp_ready(void) 105*91f16700Schasinglulu { 106*91f16700Schasinglulu return AML_AO_RTI_SCP_IS_READY(mmio_read_32(AML_AO_RTI_SCP_STAT)); 107*91f16700Schasinglulu } 108*91f16700Schasinglulu 109*91f16700Schasinglulu static inline void gxl_scp_boot(void) 110*91f16700Schasinglulu { 111*91f16700Schasinglulu aml_scpi_upload_scp_fw(bl30_image_info.image_base, 112*91f16700Schasinglulu bl30_image_info.image_size, 0); 113*91f16700Schasinglulu aml_scpi_upload_scp_fw(bl301_image_info.image_base, 114*91f16700Schasinglulu bl301_image_info.image_size, 1); 115*91f16700Schasinglulu while (!gxl_scp_ready()) 116*91f16700Schasinglulu ; 117*91f16700Schasinglulu } 118*91f16700Schasinglulu 119*91f16700Schasinglulu /******************************************************************************* 120*91f16700Schasinglulu * GICv2 driver setup information 121*91f16700Schasinglulu ******************************************************************************/ 122*91f16700Schasinglulu static const interrupt_prop_t gxl_interrupt_props[] = { 123*91f16700Schasinglulu INTR_PROP_DESC(IRQ_SEC_PHY_TIMER, GIC_HIGHEST_SEC_PRIORITY, 124*91f16700Schasinglulu GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL), 125*91f16700Schasinglulu INTR_PROP_DESC(IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY, 126*91f16700Schasinglulu GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL), 127*91f16700Schasinglulu INTR_PROP_DESC(IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY, 128*91f16700Schasinglulu GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL), 129*91f16700Schasinglulu INTR_PROP_DESC(IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY, 130*91f16700Schasinglulu GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL), 131*91f16700Schasinglulu INTR_PROP_DESC(IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY, 132*91f16700Schasinglulu GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL), 133*91f16700Schasinglulu INTR_PROP_DESC(IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY, 134*91f16700Schasinglulu GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL), 135*91f16700Schasinglulu INTR_PROP_DESC(IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY, 136*91f16700Schasinglulu GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL), 137*91f16700Schasinglulu INTR_PROP_DESC(IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY, 138*91f16700Schasinglulu GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL), 139*91f16700Schasinglulu INTR_PROP_DESC(IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY, 140*91f16700Schasinglulu GICV2_INTR_GROUP0, GIC_INTR_CFG_LEVEL), 141*91f16700Schasinglulu }; 142*91f16700Schasinglulu 143*91f16700Schasinglulu static const gicv2_driver_data_t gxl_gic_data = { 144*91f16700Schasinglulu .gicd_base = AML_GICD_BASE, 145*91f16700Schasinglulu .gicc_base = AML_GICC_BASE, 146*91f16700Schasinglulu .interrupt_props = gxl_interrupt_props, 147*91f16700Schasinglulu .interrupt_props_num = ARRAY_SIZE(gxl_interrupt_props), 148*91f16700Schasinglulu }; 149*91f16700Schasinglulu 150*91f16700Schasinglulu void bl31_platform_setup(void) 151*91f16700Schasinglulu { 152*91f16700Schasinglulu aml_mhu_secure_init(); 153*91f16700Schasinglulu 154*91f16700Schasinglulu gicv2_driver_init(&gxl_gic_data); 155*91f16700Schasinglulu gicv2_distif_init(); 156*91f16700Schasinglulu gicv2_pcpu_distif_init(); 157*91f16700Schasinglulu gicv2_cpuif_enable(); 158*91f16700Schasinglulu 159*91f16700Schasinglulu gxl_scp_boot(); 160*91f16700Schasinglulu 161*91f16700Schasinglulu aml_thermal_unknown(); 162*91f16700Schasinglulu } 163