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> 11*c69f815bSAndre Przywara #include <lib/mmio.h> 121a0f9366SAndre Przywara #include <libfdt.h> 1387762bceSOliver Swede 141a0f9366SAndre Przywara #include <platform_def.h> 1587762bceSOliver Swede #include <plat/common/platform.h> 1687762bceSOliver Swede #include <platform_def.h> 1787762bceSOliver Swede 1887762bceSOliver Swede static const interrupt_prop_t fpga_interrupt_props[] = { 1987762bceSOliver Swede PLATFORM_G1S_PROPS(INTR_GROUP1S), 2087762bceSOliver Swede PLATFORM_G0_PROPS(INTR_GROUP0) 2187762bceSOliver Swede }; 2287762bceSOliver Swede 2387762bceSOliver Swede static uintptr_t fpga_rdistif_base_addrs[PLATFORM_CORE_COUNT]; 2487762bceSOliver Swede 2587762bceSOliver Swede static unsigned int fpga_mpidr_to_core_pos(unsigned long mpidr) 2687762bceSOliver Swede { 2787762bceSOliver Swede return (unsigned int)plat_core_pos_by_mpidr(mpidr); 2887762bceSOliver Swede } 2987762bceSOliver Swede 301a0f9366SAndre Przywara static gicv3_driver_data_t fpga_gicv3_driver_data = { 3187762bceSOliver Swede .interrupt_props = fpga_interrupt_props, 3287762bceSOliver Swede .interrupt_props_num = ARRAY_SIZE(fpga_interrupt_props), 3387762bceSOliver Swede .rdistif_num = PLATFORM_CORE_COUNT, 3487762bceSOliver Swede .rdistif_base_addrs = fpga_rdistif_base_addrs, 3587762bceSOliver Swede .mpidr_to_core_pos = fpga_mpidr_to_core_pos 3687762bceSOliver Swede }; 3787762bceSOliver Swede 3887762bceSOliver Swede void plat_fpga_gic_init(void) 3987762bceSOliver Swede { 401a0f9366SAndre Przywara const void *fdt = (void *)(uintptr_t)FPGA_PRELOADED_DTB_BASE; 411a0f9366SAndre Przywara int node, ret; 421a0f9366SAndre Przywara 431a0f9366SAndre Przywara node = fdt_node_offset_by_compatible(fdt, 0, "arm,gic-v3"); 441a0f9366SAndre Przywara if (node < 0) { 451a0f9366SAndre Przywara WARN("No \"arm,gic-v3\" compatible node found in DT, no GIC support.\n"); 461a0f9366SAndre Przywara return; 471a0f9366SAndre Przywara } 481a0f9366SAndre Przywara 491a0f9366SAndre Przywara /* TODO: Assuming only empty "ranges;" properties up the bus path. */ 501a0f9366SAndre Przywara ret = fdt_get_reg_props_by_index(fdt, node, 0, 511a0f9366SAndre Przywara &fpga_gicv3_driver_data.gicd_base, NULL); 521a0f9366SAndre Przywara if (ret < 0) { 531a0f9366SAndre Przywara WARN("Could not read GIC distributor address from DT.\n"); 541a0f9366SAndre Przywara return; 551a0f9366SAndre Przywara } 561a0f9366SAndre Przywara 571a0f9366SAndre Przywara ret = fdt_get_reg_props_by_index(fdt, node, 1, 581a0f9366SAndre Przywara &fpga_gicv3_driver_data.gicr_base, NULL); 591a0f9366SAndre Przywara if (ret < 0) { 601a0f9366SAndre Przywara WARN("Could not read GIC redistributor address from DT.\n"); 611a0f9366SAndre Przywara return; 621a0f9366SAndre Przywara } 631a0f9366SAndre Przywara 6487762bceSOliver Swede gicv3_driver_init(&fpga_gicv3_driver_data); 6587762bceSOliver Swede gicv3_distif_init(); 6687762bceSOliver Swede gicv3_rdistif_init(plat_my_core_pos()); 6787762bceSOliver Swede gicv3_cpuif_enable(plat_my_core_pos()); 6887762bceSOliver Swede } 6987762bceSOliver Swede 7087762bceSOliver Swede void fpga_pwr_gic_on_finish(void) 7187762bceSOliver Swede { 7287762bceSOliver Swede gicv3_rdistif_init(plat_my_core_pos()); 7387762bceSOliver Swede gicv3_cpuif_enable(plat_my_core_pos()); 7487762bceSOliver Swede } 7587762bceSOliver Swede 7687762bceSOliver Swede void fpga_pwr_gic_off(void) 7787762bceSOliver Swede { 7887762bceSOliver Swede gicv3_cpuif_disable(plat_my_core_pos()); 7987762bceSOliver Swede gicv3_rdistif_off(plat_my_core_pos()); 8087762bceSOliver Swede } 81283e5595SAndre Przywara 82283e5595SAndre Przywara unsigned int fpga_get_nr_gic_cores(void) 83283e5595SAndre Przywara { 84283e5595SAndre Przywara return gicv3_rdistif_get_number_frames(fpga_gicv3_driver_data.gicr_base); 85283e5595SAndre Przywara } 86*c69f815bSAndre Przywara 87*c69f815bSAndre Przywara uintptr_t fpga_get_redist_size(void) 88*c69f815bSAndre Przywara { 89*c69f815bSAndre Przywara uint64_t typer_val = mmio_read_64(fpga_gicv3_driver_data.gicr_base + 90*c69f815bSAndre Przywara GICR_TYPER); 91*c69f815bSAndre Przywara 92*c69f815bSAndre Przywara return gicv3_redist_size(typer_val); 93*c69f815bSAndre Przywara } 94