1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 /* 3 * Copyright (C) 2024, Charleye <wangkart@aliyun.com> 4 * All rights reserved. 5 */ 6 7 #include <drivers/arm/gicv2.h> 8 #include <drivers/arm/gic_common.h> 9 #include <platform_def.h> 10 11 static const interrupt_prop_t lua_interrupt_props[] = { 12 #if ENABLE_FEAT_RAS && FFH_SUPPORT 13 PLATFORM_RAS_G0_PROPS(GICV2_INTR_GROUP0), 14 #endif 15 PLATFORM_G1S_PROPS(GICV2_INTR_GROUP0), 16 PLATFORM_FAB_PERIPH_G0_PROPS(GICV2_INTR_GROUP0), 17 #if LUA_SEC_UART1_IRQ 18 PLATFORM_UART1_G0_PROPS(GICV2_INTR_GROUP0) 19 #endif 20 }; 21 22 static unsigned int lua_target_masks[] = { 23 BIT_32(0), 24 BIT_32(1), 25 BIT_32(2), 26 BIT_32(3), 27 }; 28 29 static const struct gicv2_driver_data plat_gicv2_driver_data = { 30 .gicd_base = GICD_BASE, 31 .gicc_base = GICC_BASE, 32 .target_masks = lua_target_masks, 33 .target_masks_num = ARRAY_SIZE(lua_target_masks), 34 .interrupt_props = lua_interrupt_props, 35 .interrupt_props_num = ARRAY_SIZE(lua_interrupt_props), 36 }; 37 38 static inline void lua_ras_intr_configure(void) 39 { 40 gicv2_set_spi_routing(PLAT_LUA_CPU0_ERRIRQ, 0); 41 gicv2_set_spi_routing(PLAT_LUA_CPU0_FAULTIRQ, 0); 42 43 gicv2_set_spi_routing(PLAT_LUA_CPU1_ERRIRQ, 1); 44 gicv2_set_spi_routing(PLAT_LUA_CPU1_FAULTIRQ, 1); 45 46 gicv2_set_spi_routing(PLAT_LUA_CPU2_ERRIRQ, 2); 47 gicv2_set_spi_routing(PLAT_LUA_CPU2_FAULTIRQ, 2); 48 49 gicv2_set_spi_routing(PLAT_LUA_CPU3_ERRIRQ, 3); 50 gicv2_set_spi_routing(PLAT_LUA_CPU3_FAULTIRQ, 3); 51 } 52 53 void plat_lua_gic_init(void) 54 { 55 /* Initialize the gic cpu and distributor interfaces */ 56 gicv2_driver_init(&plat_gicv2_driver_data); 57 gicv2_distif_init(); 58 gicv2_pcpu_distif_init(); 59 gicv2_cpuif_enable(); 60 #if ENABLE_FEAT_RAS && FFH_SUPPORT 61 lua_ras_intr_configure(); 62 #endif 63 } 64 65 void lua_pwr_gic_on_finish(void) 66 { 67 /* TODO: This setup is needed only after a cold boot */ 68 gicv2_pcpu_distif_init(); 69 70 /* Enable the gic cpu interface */ 71 gicv2_cpuif_enable(); 72 } 73 74 void lua_pwr_gic_off(void) 75 { 76 gicv2_cpuif_disable(); 77 } 78