187762bceSOliver Swede /* 287762bceSOliver Swede * Copyright (c) 2020, ARM Limited and Contributors. All rights reserved. 387762bceSOliver Swede * 487762bceSOliver Swede * SPDX-License-Identifier: BSD-3-Clause 587762bceSOliver Swede */ 687762bceSOliver Swede 71a0f9366SAndre Przywara #include <common/debug.h> 81a0f9366SAndre Przywara #include <common/fdt_wrappers.h> 987762bceSOliver Swede #include <drivers/arm/gicv3.h> 1087762bceSOliver Swede #include <drivers/arm/gic_common.h> 111a0f9366SAndre Przywara #include <libfdt.h> 1287762bceSOliver Swede 131a0f9366SAndre Przywara #include <platform_def.h> 1487762bceSOliver Swede #include <plat/common/platform.h> 1587762bceSOliver Swede #include <platform_def.h> 1687762bceSOliver Swede 1787762bceSOliver Swede static const interrupt_prop_t fpga_interrupt_props[] = { 1887762bceSOliver Swede PLATFORM_G1S_PROPS(INTR_GROUP1S), 1987762bceSOliver Swede PLATFORM_G0_PROPS(INTR_GROUP0) 2087762bceSOliver Swede }; 2187762bceSOliver Swede 2287762bceSOliver Swede static uintptr_t fpga_rdistif_base_addrs[PLATFORM_CORE_COUNT]; 2387762bceSOliver Swede 2487762bceSOliver Swede static unsigned int fpga_mpidr_to_core_pos(unsigned long mpidr) 2587762bceSOliver Swede { 2687762bceSOliver Swede return (unsigned int)plat_core_pos_by_mpidr(mpidr); 2787762bceSOliver Swede } 2887762bceSOliver Swede 291a0f9366SAndre Przywara static gicv3_driver_data_t fpga_gicv3_driver_data = { 3087762bceSOliver Swede .interrupt_props = fpga_interrupt_props, 3187762bceSOliver Swede .interrupt_props_num = ARRAY_SIZE(fpga_interrupt_props), 3287762bceSOliver Swede .rdistif_num = PLATFORM_CORE_COUNT, 3387762bceSOliver Swede .rdistif_base_addrs = fpga_rdistif_base_addrs, 3487762bceSOliver Swede .mpidr_to_core_pos = fpga_mpidr_to_core_pos 3587762bceSOliver Swede }; 3687762bceSOliver Swede 3787762bceSOliver Swede void plat_fpga_gic_init(void) 3887762bceSOliver Swede { 391a0f9366SAndre Przywara const void *fdt = (void *)(uintptr_t)FPGA_PRELOADED_DTB_BASE; 401a0f9366SAndre Przywara int node, ret; 411a0f9366SAndre Przywara 421a0f9366SAndre Przywara node = fdt_node_offset_by_compatible(fdt, 0, "arm,gic-v3"); 431a0f9366SAndre Przywara if (node < 0) { 441a0f9366SAndre Przywara WARN("No \"arm,gic-v3\" compatible node found in DT, no GIC support.\n"); 451a0f9366SAndre Przywara return; 461a0f9366SAndre Przywara } 471a0f9366SAndre Przywara 481a0f9366SAndre Przywara /* TODO: Assuming only empty "ranges;" properties up the bus path. */ 491a0f9366SAndre Przywara ret = fdt_get_reg_props_by_index(fdt, node, 0, 501a0f9366SAndre Przywara &fpga_gicv3_driver_data.gicd_base, NULL); 511a0f9366SAndre Przywara if (ret < 0) { 521a0f9366SAndre Przywara WARN("Could not read GIC distributor address from DT.\n"); 531a0f9366SAndre Przywara return; 541a0f9366SAndre Przywara } 551a0f9366SAndre Przywara 561a0f9366SAndre Przywara ret = fdt_get_reg_props_by_index(fdt, node, 1, 571a0f9366SAndre Przywara &fpga_gicv3_driver_data.gicr_base, NULL); 581a0f9366SAndre Przywara if (ret < 0) { 591a0f9366SAndre Przywara WARN("Could not read GIC redistributor address from DT.\n"); 601a0f9366SAndre Przywara return; 611a0f9366SAndre Przywara } 621a0f9366SAndre Przywara 6387762bceSOliver Swede gicv3_driver_init(&fpga_gicv3_driver_data); 6487762bceSOliver Swede gicv3_distif_init(); 6587762bceSOliver Swede gicv3_rdistif_init(plat_my_core_pos()); 6687762bceSOliver Swede gicv3_cpuif_enable(plat_my_core_pos()); 6787762bceSOliver Swede } 6887762bceSOliver Swede 6987762bceSOliver Swede void fpga_pwr_gic_on_finish(void) 7087762bceSOliver Swede { 7187762bceSOliver Swede gicv3_rdistif_init(plat_my_core_pos()); 7287762bceSOliver Swede gicv3_cpuif_enable(plat_my_core_pos()); 7387762bceSOliver Swede } 7487762bceSOliver Swede 7587762bceSOliver Swede void fpga_pwr_gic_off(void) 7687762bceSOliver Swede { 7787762bceSOliver Swede gicv3_cpuif_disable(plat_my_core_pos()); 7887762bceSOliver Swede gicv3_rdistif_off(plat_my_core_pos()); 7987762bceSOliver Swede } 80*283e5595SAndre Przywara 81*283e5595SAndre Przywara unsigned int fpga_get_nr_gic_cores(void) 82*283e5595SAndre Przywara { 83*283e5595SAndre Przywara return gicv3_rdistif_get_number_frames(fpga_gicv3_driver_data.gicr_base); 84*283e5595SAndre Przywara } 85