1*91f16700Schasinglulu /* 2*91f16700Schasinglulu * Copyright (c) 2017-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 <string.h> 9*91f16700Schasinglulu 10*91f16700Schasinglulu #include <platform_def.h> 11*91f16700Schasinglulu 12*91f16700Schasinglulu #include <arch_helpers.h> 13*91f16700Schasinglulu #include <common/bl_common.h> 14*91f16700Schasinglulu #include <common/debug.h> 15*91f16700Schasinglulu #include <drivers/arm/gic_common.h> 16*91f16700Schasinglulu #include <drivers/arm/gicv2.h> 17*91f16700Schasinglulu #include <drivers/console.h> 18*91f16700Schasinglulu #include <lib/mmio.h> 19*91f16700Schasinglulu #include <lib/xlat_tables/xlat_tables_v2.h> 20*91f16700Schasinglulu #include <plat/common/platform.h> 21*91f16700Schasinglulu 22*91f16700Schasinglulu #include "../qemu_private.h" 23*91f16700Schasinglulu 24*91f16700Schasinglulu #if RESET_TO_SP_MIN 25*91f16700Schasinglulu #error qemu does not support RESET_TO_SP_MIN 26*91f16700Schasinglulu #endif 27*91f16700Schasinglulu 28*91f16700Schasinglulu static entry_point_info_t bl33_image_ep_info; 29*91f16700Schasinglulu 30*91f16700Schasinglulu /****************************************************************************** 31*91f16700Schasinglulu * On a GICv2 system, the Group 1 secure interrupts are treated as Group 0 32*91f16700Schasinglulu * interrupts. 33*91f16700Schasinglulu *****************************************************************************/ 34*91f16700Schasinglulu #define PLATFORM_G1S_PROPS(grp) \ 35*91f16700Schasinglulu INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_0, GIC_HIGHEST_SEC_PRIORITY, \ 36*91f16700Schasinglulu grp, GIC_INTR_CFG_LEVEL), \ 37*91f16700Schasinglulu INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_1, GIC_HIGHEST_SEC_PRIORITY, \ 38*91f16700Schasinglulu grp, GIC_INTR_CFG_LEVEL), \ 39*91f16700Schasinglulu INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_2, GIC_HIGHEST_SEC_PRIORITY, \ 40*91f16700Schasinglulu grp, GIC_INTR_CFG_LEVEL), \ 41*91f16700Schasinglulu INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_3, GIC_HIGHEST_SEC_PRIORITY, \ 42*91f16700Schasinglulu grp, GIC_INTR_CFG_LEVEL), \ 43*91f16700Schasinglulu INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_4, GIC_HIGHEST_SEC_PRIORITY, \ 44*91f16700Schasinglulu grp, GIC_INTR_CFG_LEVEL), \ 45*91f16700Schasinglulu INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_5, GIC_HIGHEST_SEC_PRIORITY, \ 46*91f16700Schasinglulu grp, GIC_INTR_CFG_LEVEL), \ 47*91f16700Schasinglulu INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_6, GIC_HIGHEST_SEC_PRIORITY, \ 48*91f16700Schasinglulu grp, GIC_INTR_CFG_LEVEL), \ 49*91f16700Schasinglulu INTR_PROP_DESC(QEMU_IRQ_SEC_SGI_7, GIC_HIGHEST_SEC_PRIORITY, \ 50*91f16700Schasinglulu grp, GIC_INTR_CFG_LEVEL) 51*91f16700Schasinglulu 52*91f16700Schasinglulu #define PLATFORM_G0_PROPS(grp) 53*91f16700Schasinglulu 54*91f16700Schasinglulu static const interrupt_prop_t stih410_interrupt_props[] = { 55*91f16700Schasinglulu PLATFORM_G1S_PROPS(GICV2_INTR_GROUP0), 56*91f16700Schasinglulu PLATFORM_G0_PROPS(GICV2_INTR_GROUP0) 57*91f16700Schasinglulu }; 58*91f16700Schasinglulu 59*91f16700Schasinglulu static unsigned int target_mask_array[PLATFORM_CORE_COUNT]; 60*91f16700Schasinglulu 61*91f16700Schasinglulu static const struct gicv2_driver_data plat_gicv2_driver_data = { 62*91f16700Schasinglulu .gicd_base = GICD_BASE, 63*91f16700Schasinglulu .gicc_base = GICC_BASE, 64*91f16700Schasinglulu .interrupt_props = stih410_interrupt_props, 65*91f16700Schasinglulu .interrupt_props_num = ARRAY_SIZE(stih410_interrupt_props), 66*91f16700Schasinglulu .target_masks = target_mask_array, 67*91f16700Schasinglulu .target_masks_num = ARRAY_SIZE(target_mask_array), 68*91f16700Schasinglulu }; 69*91f16700Schasinglulu 70*91f16700Schasinglulu /******************************************************************************* 71*91f16700Schasinglulu * Return a pointer to the 'entry_point_info' structure of the next image for 72*91f16700Schasinglulu * the security state specified. BL33 corresponds to the non-secure image type 73*91f16700Schasinglulu * while BL32 corresponds to the secure image type. A NULL pointer is returned 74*91f16700Schasinglulu * if the image does not exist. 75*91f16700Schasinglulu ******************************************************************************/ 76*91f16700Schasinglulu entry_point_info_t *sp_min_plat_get_bl33_ep_info(void) 77*91f16700Schasinglulu { 78*91f16700Schasinglulu entry_point_info_t *next_image_info = &bl33_image_ep_info; 79*91f16700Schasinglulu 80*91f16700Schasinglulu /* 81*91f16700Schasinglulu * None of the images on the ARM development platforms can have 0x0 82*91f16700Schasinglulu * as the entrypoint 83*91f16700Schasinglulu */ 84*91f16700Schasinglulu if (next_image_info->pc) 85*91f16700Schasinglulu return next_image_info; 86*91f16700Schasinglulu else 87*91f16700Schasinglulu return NULL; 88*91f16700Schasinglulu } 89*91f16700Schasinglulu 90*91f16700Schasinglulu void sp_min_early_platform_setup2(u_register_t arg0, u_register_t arg1, 91*91f16700Schasinglulu u_register_t arg2, u_register_t arg3) 92*91f16700Schasinglulu { 93*91f16700Schasinglulu bl_params_t *params_from_bl2 = (bl_params_t *)arg0; 94*91f16700Schasinglulu 95*91f16700Schasinglulu /* Initialize the console to provide early debug support */ 96*91f16700Schasinglulu qemu_console_init(); 97*91f16700Schasinglulu 98*91f16700Schasinglulu ERROR("qemu sp_min, console init\n"); 99*91f16700Schasinglulu /* 100*91f16700Schasinglulu * Check params passed from BL2 101*91f16700Schasinglulu */ 102*91f16700Schasinglulu assert(params_from_bl2); 103*91f16700Schasinglulu assert(params_from_bl2->h.type == PARAM_BL_PARAMS); 104*91f16700Schasinglulu assert(params_from_bl2->h.version >= VERSION_2); 105*91f16700Schasinglulu 106*91f16700Schasinglulu bl_params_node_t *bl_params = params_from_bl2->head; 107*91f16700Schasinglulu 108*91f16700Schasinglulu /* 109*91f16700Schasinglulu * Copy BL33 entry point information from BL2's address space. 110*91f16700Schasinglulu */ 111*91f16700Schasinglulu while (bl_params) { 112*91f16700Schasinglulu if (bl_params->image_id == BL33_IMAGE_ID) 113*91f16700Schasinglulu bl33_image_ep_info = *bl_params->ep_info; 114*91f16700Schasinglulu 115*91f16700Schasinglulu bl_params = bl_params->next_params_info; 116*91f16700Schasinglulu } 117*91f16700Schasinglulu 118*91f16700Schasinglulu if (!bl33_image_ep_info.pc) 119*91f16700Schasinglulu panic(); 120*91f16700Schasinglulu } 121*91f16700Schasinglulu 122*91f16700Schasinglulu void sp_min_plat_arch_setup(void) 123*91f16700Schasinglulu { 124*91f16700Schasinglulu qemu_configure_mmu_svc_mon(BL32_RO_BASE, BL32_END - BL32_RO_BASE, 125*91f16700Schasinglulu BL_CODE_BASE, BL_CODE_END, 126*91f16700Schasinglulu BL_COHERENT_RAM_BASE, BL_COHERENT_RAM_END); 127*91f16700Schasinglulu 128*91f16700Schasinglulu } 129*91f16700Schasinglulu 130*91f16700Schasinglulu void sp_min_platform_setup(void) 131*91f16700Schasinglulu { 132*91f16700Schasinglulu /* Initialize the gic cpu and distributor interfaces */ 133*91f16700Schasinglulu gicv2_driver_init(&plat_gicv2_driver_data); 134*91f16700Schasinglulu gicv2_distif_init(); 135*91f16700Schasinglulu gicv2_pcpu_distif_init(); 136*91f16700Schasinglulu gicv2_cpuif_enable(); 137*91f16700Schasinglulu } 138*91f16700Schasinglulu 139*91f16700Schasinglulu unsigned int plat_get_syscnt_freq2(void) 140*91f16700Schasinglulu { 141*91f16700Schasinglulu return SYS_COUNTER_FREQ_IN_TICKS; 142*91f16700Schasinglulu } 143*91f16700Schasinglulu 144*91f16700Schasinglulu void sp_min_plat_fiq_handler(uint32_t id) 145*91f16700Schasinglulu { 146*91f16700Schasinglulu VERBOSE("[sp_min] interrupt #%d\n", id); 147*91f16700Schasinglulu } 148