xref: /aosp_15_r20/external/arm-trusted-firmware/plat/xilinx/versal/versal_gicv3.c (revision 54fd6939e177f8ff529b10183254802c76df6d08)
1*54fd6939SJiyong Park /*
2*54fd6939SJiyong Park  * Copyright (c) 2018-2019, ARM Limited and Contributors. All rights reserved.
3*54fd6939SJiyong Park  *
4*54fd6939SJiyong Park  * SPDX-License-Identifier: BSD-3-Clause
5*54fd6939SJiyong Park  */
6*54fd6939SJiyong Park 
7*54fd6939SJiyong Park #include <plat_private.h>
8*54fd6939SJiyong Park #include <platform_def.h>
9*54fd6939SJiyong Park 
10*54fd6939SJiyong Park #include <common/interrupt_props.h>
11*54fd6939SJiyong Park #include <drivers/arm/gicv3.h>
12*54fd6939SJiyong Park #include <lib/utils.h>
13*54fd6939SJiyong Park #include <plat/common/platform.h>
14*54fd6939SJiyong Park 
15*54fd6939SJiyong Park /******************************************************************************
16*54fd6939SJiyong Park  * The following functions are defined as weak to allow a platform to override
17*54fd6939SJiyong Park  * the way the GICv3 driver is initialised and used.
18*54fd6939SJiyong Park  *****************************************************************************/
19*54fd6939SJiyong Park #pragma weak plat_versal_gic_driver_init
20*54fd6939SJiyong Park #pragma weak plat_versal_gic_init
21*54fd6939SJiyong Park #pragma weak plat_versal_gic_cpuif_enable
22*54fd6939SJiyong Park #pragma weak plat_versal_gic_cpuif_disable
23*54fd6939SJiyong Park #pragma weak plat_versal_gic_pcpu_init
24*54fd6939SJiyong Park #pragma weak plat_versal_gic_redistif_on
25*54fd6939SJiyong Park #pragma weak plat_versal_gic_redistif_off
26*54fd6939SJiyong Park 
27*54fd6939SJiyong Park /* The GICv3 driver only needs to be initialized in EL3 */
28*54fd6939SJiyong Park static uintptr_t rdistif_base_addrs[PLATFORM_CORE_COUNT];
29*54fd6939SJiyong Park 
30*54fd6939SJiyong Park static const interrupt_prop_t versal_interrupt_props[] = {
31*54fd6939SJiyong Park 	PLAT_VERSAL_G1S_IRQ_PROPS(INTR_GROUP1S),
32*54fd6939SJiyong Park 	PLAT_VERSAL_G0_IRQ_PROPS(INTR_GROUP0)
33*54fd6939SJiyong Park };
34*54fd6939SJiyong Park 
35*54fd6939SJiyong Park /*
36*54fd6939SJiyong Park  * We save and restore the GICv3 context on system suspend. Allocate the
37*54fd6939SJiyong Park  * data in the designated EL3 Secure carve-out memory.
38*54fd6939SJiyong Park  */
39*54fd6939SJiyong Park static gicv3_redist_ctx_t rdist_ctx __section("versal_el3_tzc_dram");
40*54fd6939SJiyong Park static gicv3_dist_ctx_t dist_ctx __section("versal_el3_tzc_dram");
41*54fd6939SJiyong Park 
42*54fd6939SJiyong Park /*
43*54fd6939SJiyong Park  * MPIDR hashing function for translating MPIDRs read from GICR_TYPER register
44*54fd6939SJiyong Park  * to core position.
45*54fd6939SJiyong Park  *
46*54fd6939SJiyong Park  * Calculating core position is dependent on MPIDR_EL1.MT bit. However, affinity
47*54fd6939SJiyong Park  * values read from GICR_TYPER don't have an MT field. To reuse the same
48*54fd6939SJiyong Park  * translation used for CPUs, we insert MT bit read from the PE's MPIDR into
49*54fd6939SJiyong Park  * that read from GICR_TYPER.
50*54fd6939SJiyong Park  *
51*54fd6939SJiyong Park  * Assumptions:
52*54fd6939SJiyong Park  *
53*54fd6939SJiyong Park  *   - All CPUs implemented in the system have MPIDR_EL1.MT bit set;
54*54fd6939SJiyong Park  *   - No CPUs implemented in the system use affinity level 3.
55*54fd6939SJiyong Park  */
versal_gicv3_mpidr_hash(u_register_t mpidr)56*54fd6939SJiyong Park static unsigned int versal_gicv3_mpidr_hash(u_register_t mpidr)
57*54fd6939SJiyong Park {
58*54fd6939SJiyong Park 	mpidr |= (read_mpidr_el1() & MPIDR_MT_MASK);
59*54fd6939SJiyong Park 	return versal_calc_core_pos(mpidr);
60*54fd6939SJiyong Park }
61*54fd6939SJiyong Park 
62*54fd6939SJiyong Park static const gicv3_driver_data_t versal_gic_data __unused = {
63*54fd6939SJiyong Park 	.gicd_base = PLAT_VERSAL_GICD_BASE,
64*54fd6939SJiyong Park 	.gicr_base = PLAT_VERSAL_GICR_BASE,
65*54fd6939SJiyong Park 	.interrupt_props = versal_interrupt_props,
66*54fd6939SJiyong Park 	.interrupt_props_num = ARRAY_SIZE(versal_interrupt_props),
67*54fd6939SJiyong Park 	.rdistif_num = PLATFORM_CORE_COUNT,
68*54fd6939SJiyong Park 	.rdistif_base_addrs = rdistif_base_addrs,
69*54fd6939SJiyong Park 	.mpidr_to_core_pos = versal_gicv3_mpidr_hash
70*54fd6939SJiyong Park };
71*54fd6939SJiyong Park 
plat_versal_gic_driver_init(void)72*54fd6939SJiyong Park void __init plat_versal_gic_driver_init(void)
73*54fd6939SJiyong Park {
74*54fd6939SJiyong Park 	/*
75*54fd6939SJiyong Park 	 * The GICv3 driver is initialized in EL3 and does not need
76*54fd6939SJiyong Park 	 * to be initialized again in SEL1. This is because the S-EL1
77*54fd6939SJiyong Park 	 * can use GIC system registers to manage interrupts and does
78*54fd6939SJiyong Park 	 * not need GIC interface base addresses to be configured.
79*54fd6939SJiyong Park 	 */
80*54fd6939SJiyong Park #if IMAGE_BL31
81*54fd6939SJiyong Park 	gicv3_driver_init(&versal_gic_data);
82*54fd6939SJiyong Park #endif
83*54fd6939SJiyong Park }
84*54fd6939SJiyong Park 
85*54fd6939SJiyong Park /******************************************************************************
86*54fd6939SJiyong Park  * Versal common helper to initialize the GIC. Only invoked by BL31
87*54fd6939SJiyong Park  *****************************************************************************/
plat_versal_gic_init(void)88*54fd6939SJiyong Park void __init plat_versal_gic_init(void)
89*54fd6939SJiyong Park {
90*54fd6939SJiyong Park 	gicv3_distif_init();
91*54fd6939SJiyong Park 	gicv3_rdistif_init(plat_my_core_pos());
92*54fd6939SJiyong Park 	gicv3_cpuif_enable(plat_my_core_pos());
93*54fd6939SJiyong Park }
94*54fd6939SJiyong Park 
95*54fd6939SJiyong Park /******************************************************************************
96*54fd6939SJiyong Park  * Versal common helper to enable the GIC CPU interface
97*54fd6939SJiyong Park  *****************************************************************************/
plat_versal_gic_cpuif_enable(void)98*54fd6939SJiyong Park void plat_versal_gic_cpuif_enable(void)
99*54fd6939SJiyong Park {
100*54fd6939SJiyong Park 	gicv3_cpuif_enable(plat_my_core_pos());
101*54fd6939SJiyong Park }
102*54fd6939SJiyong Park 
103*54fd6939SJiyong Park /******************************************************************************
104*54fd6939SJiyong Park  * Versal common helper to disable the GIC CPU interface
105*54fd6939SJiyong Park  *****************************************************************************/
plat_versal_gic_cpuif_disable(void)106*54fd6939SJiyong Park void plat_versal_gic_cpuif_disable(void)
107*54fd6939SJiyong Park {
108*54fd6939SJiyong Park 	gicv3_cpuif_disable(plat_my_core_pos());
109*54fd6939SJiyong Park }
110*54fd6939SJiyong Park 
111*54fd6939SJiyong Park /******************************************************************************
112*54fd6939SJiyong Park  * Versal common helper to initialize the per-cpu redistributor interface in
113*54fd6939SJiyong Park  * GICv3
114*54fd6939SJiyong Park  *****************************************************************************/
plat_versal_gic_pcpu_init(void)115*54fd6939SJiyong Park void plat_versal_gic_pcpu_init(void)
116*54fd6939SJiyong Park {
117*54fd6939SJiyong Park 	gicv3_rdistif_init(plat_my_core_pos());
118*54fd6939SJiyong Park }
119*54fd6939SJiyong Park 
120*54fd6939SJiyong Park /******************************************************************************
121*54fd6939SJiyong Park  * Versal common helpers to power GIC redistributor interface
122*54fd6939SJiyong Park  *****************************************************************************/
plat_versal_gic_redistif_on(void)123*54fd6939SJiyong Park void plat_versal_gic_redistif_on(void)
124*54fd6939SJiyong Park {
125*54fd6939SJiyong Park 	gicv3_rdistif_on(plat_my_core_pos());
126*54fd6939SJiyong Park }
127*54fd6939SJiyong Park 
plat_versal_gic_redistif_off(void)128*54fd6939SJiyong Park void plat_versal_gic_redistif_off(void)
129*54fd6939SJiyong Park {
130*54fd6939SJiyong Park 	gicv3_rdistif_off(plat_my_core_pos());
131*54fd6939SJiyong Park }
132*54fd6939SJiyong Park 
133*54fd6939SJiyong Park /******************************************************************************
134*54fd6939SJiyong Park  * Versal common helper to save & restore the GICv3 on resume from system
135*54fd6939SJiyong Park  * suspend
136*54fd6939SJiyong Park  *****************************************************************************/
plat_versal_gic_save(void)137*54fd6939SJiyong Park void plat_versal_gic_save(void)
138*54fd6939SJiyong Park {
139*54fd6939SJiyong Park 	/*
140*54fd6939SJiyong Park 	 * If an ITS is available, save its context before
141*54fd6939SJiyong Park 	 * the Redistributor using:
142*54fd6939SJiyong Park 	 * gicv3_its_save_disable(gits_base, &its_ctx[i])
143*54fd6939SJiyong Park 	 * Additionnaly, an implementation-defined sequence may
144*54fd6939SJiyong Park 	 * be required to save the whole ITS state.
145*54fd6939SJiyong Park 	 */
146*54fd6939SJiyong Park 
147*54fd6939SJiyong Park 	/*
148*54fd6939SJiyong Park 	 * Save the GIC Redistributors and ITS contexts before the
149*54fd6939SJiyong Park 	 * Distributor context. As we only handle SYSTEM SUSPEND API,
150*54fd6939SJiyong Park 	 * we only need to save the context of the CPU that is issuing
151*54fd6939SJiyong Park 	 * the SYSTEM SUSPEND call, i.e. the current CPU.
152*54fd6939SJiyong Park 	 */
153*54fd6939SJiyong Park 	gicv3_rdistif_save(plat_my_core_pos(), &rdist_ctx);
154*54fd6939SJiyong Park 
155*54fd6939SJiyong Park 	/* Save the GIC Distributor context */
156*54fd6939SJiyong Park 	gicv3_distif_save(&dist_ctx);
157*54fd6939SJiyong Park 
158*54fd6939SJiyong Park 	/*
159*54fd6939SJiyong Park 	 * From here, all the components of the GIC can be safely powered down
160*54fd6939SJiyong Park 	 * as long as there is an alternate way to handle wakeup interrupt
161*54fd6939SJiyong Park 	 * sources.
162*54fd6939SJiyong Park 	 */
163*54fd6939SJiyong Park }
164*54fd6939SJiyong Park 
plat_versal_gic_resume(void)165*54fd6939SJiyong Park void plat_versal_gic_resume(void)
166*54fd6939SJiyong Park {
167*54fd6939SJiyong Park 	/* Restore the GIC Distributor context */
168*54fd6939SJiyong Park 	gicv3_distif_init_restore(&dist_ctx);
169*54fd6939SJiyong Park 
170*54fd6939SJiyong Park 	/*
171*54fd6939SJiyong Park 	 * Restore the GIC Redistributor and ITS contexts after the
172*54fd6939SJiyong Park 	 * Distributor context. As we only handle SYSTEM SUSPEND API,
173*54fd6939SJiyong Park 	 * we only need to restore the context of the CPU that issued
174*54fd6939SJiyong Park 	 * the SYSTEM SUSPEND call.
175*54fd6939SJiyong Park 	 */
176*54fd6939SJiyong Park 	gicv3_rdistif_init_restore(plat_my_core_pos(), &rdist_ctx);
177*54fd6939SJiyong Park 
178*54fd6939SJiyong Park 	/*
179*54fd6939SJiyong Park 	 * If an ITS is available, restore its context after
180*54fd6939SJiyong Park 	 * the Redistributor using:
181*54fd6939SJiyong Park 	 * gicv3_its_restore(gits_base, &its_ctx[i])
182*54fd6939SJiyong Park 	 * An implementation-defined sequence may be required to
183*54fd6939SJiyong Park 	 * restore the whole ITS state. The ITS must also be
184*54fd6939SJiyong Park 	 * re-enabled after this sequence has been executed.
185*54fd6939SJiyong Park 	 */
186*54fd6939SJiyong Park }
187