xref: /rk3399_ARM-atf/plat/arm/board/arm_fpga/fpga_gicv3.c (revision 1a0f9366d82f7e9fac96a29bd38c78828044a147)
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 
7*1a0f9366SAndre Przywara #include <common/debug.h>
8*1a0f9366SAndre Przywara #include <common/fdt_wrappers.h>
987762bceSOliver Swede #include <drivers/arm/gicv3.h>
1087762bceSOliver Swede #include <drivers/arm/gic_common.h>
11*1a0f9366SAndre Przywara #include <libfdt.h>
1287762bceSOliver Swede 
13*1a0f9366SAndre 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 
29*1a0f9366SAndre 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 {
39*1a0f9366SAndre Przywara 	const void *fdt = (void *)(uintptr_t)FPGA_PRELOADED_DTB_BASE;
40*1a0f9366SAndre Przywara 	int node, ret;
41*1a0f9366SAndre Przywara 
42*1a0f9366SAndre Przywara 	node = fdt_node_offset_by_compatible(fdt, 0, "arm,gic-v3");
43*1a0f9366SAndre Przywara 	if (node < 0) {
44*1a0f9366SAndre Przywara 		WARN("No \"arm,gic-v3\" compatible node found in DT, no GIC support.\n");
45*1a0f9366SAndre Przywara 		return;
46*1a0f9366SAndre Przywara 	}
47*1a0f9366SAndre Przywara 
48*1a0f9366SAndre Przywara 	/* TODO: Assuming only empty "ranges;" properties up the bus path. */
49*1a0f9366SAndre Przywara 	ret = fdt_get_reg_props_by_index(fdt, node, 0,
50*1a0f9366SAndre Przywara 				 &fpga_gicv3_driver_data.gicd_base, NULL);
51*1a0f9366SAndre Przywara 	if (ret < 0) {
52*1a0f9366SAndre Przywara 		WARN("Could not read GIC distributor address from DT.\n");
53*1a0f9366SAndre Przywara 		return;
54*1a0f9366SAndre Przywara 	}
55*1a0f9366SAndre Przywara 
56*1a0f9366SAndre Przywara 	ret = fdt_get_reg_props_by_index(fdt, node, 1,
57*1a0f9366SAndre Przywara 				 &fpga_gicv3_driver_data.gicr_base, NULL);
58*1a0f9366SAndre Przywara 	if (ret < 0) {
59*1a0f9366SAndre Przywara 		WARN("Could not read GIC redistributor address from DT.\n");
60*1a0f9366SAndre Przywara 		return;
61*1a0f9366SAndre Przywara 	}
62*1a0f9366SAndre 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