xref: /arm-trusted-firmware/plat/marvell/armada/common/marvell_gicv3.c (revision 91f16700b400a8c0651d24a598fc48ee2997a0d7)
1*91f16700Schasinglulu /*
2*91f16700Schasinglulu  * Copyright (C) 2018 Marvell International Ltd.
3*91f16700Schasinglulu  *
4*91f16700Schasinglulu  * SPDX-License-Identifier:     BSD-3-Clause
5*91f16700Schasinglulu  * https://spdx.org/licenses
6*91f16700Schasinglulu  */
7*91f16700Schasinglulu 
8*91f16700Schasinglulu #include <platform_def.h>
9*91f16700Schasinglulu 
10*91f16700Schasinglulu #include <common/debug.h>
11*91f16700Schasinglulu #include <common/interrupt_props.h>
12*91f16700Schasinglulu #include <drivers/arm/gicv3.h>
13*91f16700Schasinglulu #include <plat/common/platform.h>
14*91f16700Schasinglulu 
15*91f16700Schasinglulu #include <marvell_def.h>
16*91f16700Schasinglulu #include <plat_marvell.h>
17*91f16700Schasinglulu 
18*91f16700Schasinglulu /******************************************************************************
19*91f16700Schasinglulu  * The following functions are defined as weak to allow a platform to override
20*91f16700Schasinglulu  * the way the GICv3 driver is initialised and used.
21*91f16700Schasinglulu  ******************************************************************************
22*91f16700Schasinglulu  */
23*91f16700Schasinglulu #pragma weak plat_marvell_gic_driver_init
24*91f16700Schasinglulu #pragma weak plat_marvell_gic_init
25*91f16700Schasinglulu #pragma weak plat_marvell_gic_cpuif_enable
26*91f16700Schasinglulu #pragma weak plat_marvell_gic_cpuif_disable
27*91f16700Schasinglulu #pragma weak plat_marvell_gic_pcpu_init
28*91f16700Schasinglulu 
29*91f16700Schasinglulu /* The GICv3 driver only needs to be initialized in EL3 */
30*91f16700Schasinglulu static uintptr_t rdistif_base_addrs[PLATFORM_CORE_COUNT];
31*91f16700Schasinglulu 
32*91f16700Schasinglulu static const interrupt_prop_t marvell_interrupt_props[] = {
33*91f16700Schasinglulu 	PLAT_MARVELL_G1S_IRQ_PROPS(INTR_GROUP1S),
34*91f16700Schasinglulu 	PLAT_MARVELL_G0_IRQ_PROPS(INTR_GROUP0)
35*91f16700Schasinglulu };
36*91f16700Schasinglulu 
37*91f16700Schasinglulu /*
38*91f16700Schasinglulu  * We save and restore the GICv3 context on system suspend. Allocate the
39*91f16700Schasinglulu  * data in the designated EL3 Secure carve-out memory
40*91f16700Schasinglulu  */
41*91f16700Schasinglulu static gicv3_redist_ctx_t rdist_ctx __section(".arm_el3_tzc_dram");
42*91f16700Schasinglulu static gicv3_dist_ctx_t dist_ctx __section(".arm_el3_tzc_dram");
43*91f16700Schasinglulu 
44*91f16700Schasinglulu /*
45*91f16700Schasinglulu  * MPIDR hashing function for translating MPIDRs read from GICR_TYPER register
46*91f16700Schasinglulu  * to core position.
47*91f16700Schasinglulu  *
48*91f16700Schasinglulu  * Calculating core position is dependent on MPIDR_EL1.MT bit. However, affinity
49*91f16700Schasinglulu  * values read from GICR_TYPER don't have an MT field. To reuse the same
50*91f16700Schasinglulu  * translation used for CPUs, we insert MT bit read from the PE's MPIDR into
51*91f16700Schasinglulu  * that read from GICR_TYPER.
52*91f16700Schasinglulu  *
53*91f16700Schasinglulu  * Assumptions:
54*91f16700Schasinglulu  *
55*91f16700Schasinglulu  *   - All CPUs implemented in the system have MPIDR_EL1.MT bit set;
56*91f16700Schasinglulu  *   - No CPUs implemented in the system use affinity level 3.
57*91f16700Schasinglulu  */
58*91f16700Schasinglulu static unsigned int marvell_gicv3_mpidr_hash(u_register_t mpidr)
59*91f16700Schasinglulu {
60*91f16700Schasinglulu 	mpidr |= (read_mpidr_el1() & MPIDR_MT_MASK);
61*91f16700Schasinglulu 	return plat_marvell_calc_core_pos(mpidr);
62*91f16700Schasinglulu }
63*91f16700Schasinglulu 
64*91f16700Schasinglulu const gicv3_driver_data_t marvell_gic_data = {
65*91f16700Schasinglulu 	.gicd_base = PLAT_MARVELL_GICD_BASE,
66*91f16700Schasinglulu 	.gicr_base = PLAT_MARVELL_GICR_BASE,
67*91f16700Schasinglulu 	.interrupt_props = marvell_interrupt_props,
68*91f16700Schasinglulu 	.interrupt_props_num = ARRAY_SIZE(marvell_interrupt_props),
69*91f16700Schasinglulu 	.rdistif_num = PLATFORM_CORE_COUNT,
70*91f16700Schasinglulu 	.rdistif_base_addrs = rdistif_base_addrs,
71*91f16700Schasinglulu 	.mpidr_to_core_pos = marvell_gicv3_mpidr_hash
72*91f16700Schasinglulu };
73*91f16700Schasinglulu 
74*91f16700Schasinglulu void plat_marvell_gic_driver_init(void)
75*91f16700Schasinglulu {
76*91f16700Schasinglulu 	/*
77*91f16700Schasinglulu 	 * The GICv3 driver is initialized in EL3 and does not need
78*91f16700Schasinglulu 	 * to be initialized again in SEL1. This is because the S-EL1
79*91f16700Schasinglulu 	 * can use GIC system registers to manage interrupts and does
80*91f16700Schasinglulu 	 * not need GIC interface base addresses to be configured.
81*91f16700Schasinglulu 	 */
82*91f16700Schasinglulu #if IMAGE_BL31
83*91f16700Schasinglulu 	gicv3_driver_init(&marvell_gic_data);
84*91f16700Schasinglulu #endif
85*91f16700Schasinglulu }
86*91f16700Schasinglulu 
87*91f16700Schasinglulu /******************************************************************************
88*91f16700Schasinglulu  * Marvell common helper to initialize the GIC. Only invoked by BL31
89*91f16700Schasinglulu  ******************************************************************************
90*91f16700Schasinglulu  */
91*91f16700Schasinglulu void plat_marvell_gic_init(void)
92*91f16700Schasinglulu {
93*91f16700Schasinglulu 	/* Initialize GIC-600 Multi Chip feature,
94*91f16700Schasinglulu 	 * only if the maximum number of north bridges
95*91f16700Schasinglulu 	 * is more than 1 - otherwise no need for multi
96*91f16700Schasinglulu 	 * chip feature initialization
97*91f16700Schasinglulu 	 */
98*91f16700Schasinglulu #if (PLAT_MARVELL_NORTHB_COUNT > 1)
99*91f16700Schasinglulu 	if (gic600_multi_chip_init())
100*91f16700Schasinglulu 		ERROR("GIC-600 Multi Chip initialization failed\n");
101*91f16700Schasinglulu #endif
102*91f16700Schasinglulu 	gicv3_distif_init();
103*91f16700Schasinglulu 	gicv3_rdistif_init(plat_my_core_pos());
104*91f16700Schasinglulu 	gicv3_cpuif_enable(plat_my_core_pos());
105*91f16700Schasinglulu }
106*91f16700Schasinglulu 
107*91f16700Schasinglulu /******************************************************************************
108*91f16700Schasinglulu  * Marvell common helper to enable the GIC CPU interface
109*91f16700Schasinglulu  ******************************************************************************
110*91f16700Schasinglulu  */
111*91f16700Schasinglulu void plat_marvell_gic_cpuif_enable(void)
112*91f16700Schasinglulu {
113*91f16700Schasinglulu 	gicv3_cpuif_enable(plat_my_core_pos());
114*91f16700Schasinglulu }
115*91f16700Schasinglulu 
116*91f16700Schasinglulu /******************************************************************************
117*91f16700Schasinglulu  * Marvell common helper to disable the GIC CPU interface
118*91f16700Schasinglulu  ******************************************************************************
119*91f16700Schasinglulu  */
120*91f16700Schasinglulu void plat_marvell_gic_cpuif_disable(void)
121*91f16700Schasinglulu {
122*91f16700Schasinglulu 	gicv3_cpuif_disable(plat_my_core_pos());
123*91f16700Schasinglulu }
124*91f16700Schasinglulu 
125*91f16700Schasinglulu /******************************************************************************
126*91f16700Schasinglulu  * Marvell common helper to init. the per-cpu redistributor interface in GICv3
127*91f16700Schasinglulu  ******************************************************************************
128*91f16700Schasinglulu  */
129*91f16700Schasinglulu void plat_marvell_gic_pcpu_init(void)
130*91f16700Schasinglulu {
131*91f16700Schasinglulu 	gicv3_rdistif_init(plat_my_core_pos());
132*91f16700Schasinglulu }
133*91f16700Schasinglulu 
134*91f16700Schasinglulu /******************************************************************************
135*91f16700Schasinglulu  * Marvell common helper to save SPI irq states in GICv3
136*91f16700Schasinglulu  ******************************************************************************
137*91f16700Schasinglulu  */
138*91f16700Schasinglulu void plat_marvell_gic_irq_save(void)
139*91f16700Schasinglulu {
140*91f16700Schasinglulu 
141*91f16700Schasinglulu 	/*
142*91f16700Schasinglulu 	 * If an ITS is available, save its context before
143*91f16700Schasinglulu 	 * the Redistributor using:
144*91f16700Schasinglulu 	 * gicv3_its_save_disable(gits_base, &its_ctx[i])
145*91f16700Schasinglulu 	 * Additionally, an implementation-defined sequence may
146*91f16700Schasinglulu 	 * be required to save the whole ITS state.
147*91f16700Schasinglulu 	 */
148*91f16700Schasinglulu 
149*91f16700Schasinglulu 	/*
150*91f16700Schasinglulu 	 * Save the GIC Redistributors and ITS contexts before the
151*91f16700Schasinglulu 	 * Distributor context. As we only handle SYSTEM SUSPEND API,
152*91f16700Schasinglulu 	 * we only need to save the context of the CPU that is issuing
153*91f16700Schasinglulu 	 * the SYSTEM SUSPEND call, i.e. the current CPU.
154*91f16700Schasinglulu 	 */
155*91f16700Schasinglulu 	gicv3_rdistif_save(plat_my_core_pos(), &rdist_ctx);
156*91f16700Schasinglulu 
157*91f16700Schasinglulu 	/* Save the GIC Distributor context */
158*91f16700Schasinglulu 	gicv3_distif_save(&dist_ctx);
159*91f16700Schasinglulu 
160*91f16700Schasinglulu 	/*
161*91f16700Schasinglulu 	 * From here, all the components of the GIC can be safely powered down
162*91f16700Schasinglulu 	 * as long as there is an alternate way to handle wakeup interrupt
163*91f16700Schasinglulu 	 * sources.
164*91f16700Schasinglulu 	 */
165*91f16700Schasinglulu }
166*91f16700Schasinglulu 
167*91f16700Schasinglulu /******************************************************************************
168*91f16700Schasinglulu  * Marvell common helper to restore SPI irq states in GICv3
169*91f16700Schasinglulu  ******************************************************************************
170*91f16700Schasinglulu  */
171*91f16700Schasinglulu void plat_marvell_gic_irq_restore(void)
172*91f16700Schasinglulu {
173*91f16700Schasinglulu 	/* Restore the GIC Distributor context */
174*91f16700Schasinglulu 	gicv3_distif_init_restore(&dist_ctx);
175*91f16700Schasinglulu 
176*91f16700Schasinglulu 	/*
177*91f16700Schasinglulu 	 * Restore the GIC Redistributor and ITS contexts after the
178*91f16700Schasinglulu 	 * Distributor context. As we only handle SYSTEM SUSPEND API,
179*91f16700Schasinglulu 	 * we only need to restore the context of the CPU that issued
180*91f16700Schasinglulu 	 * the SYSTEM SUSPEND call.
181*91f16700Schasinglulu 	 */
182*91f16700Schasinglulu 	gicv3_rdistif_init_restore(plat_my_core_pos(), &rdist_ctx);
183*91f16700Schasinglulu 
184*91f16700Schasinglulu 	/*
185*91f16700Schasinglulu 	 * If an ITS is available, restore its context after
186*91f16700Schasinglulu 	 * the Redistributor using:
187*91f16700Schasinglulu 	 * gicv3_its_restore(gits_base, &its_ctx[i])
188*91f16700Schasinglulu 	 * An implementation-defined sequence may be required to
189*91f16700Schasinglulu 	 * restore the whole ITS state. The ITS must also be
190*91f16700Schasinglulu 	 * re-enabled after this sequence has been executed.
191*91f16700Schasinglulu 	 */
192*91f16700Schasinglulu }
193*91f16700Schasinglulu 
194*91f16700Schasinglulu /******************************************************************************
195*91f16700Schasinglulu  * Marvell common helper to save per-cpu PPI irq states in GICv3
196*91f16700Schasinglulu  ******************************************************************************
197*91f16700Schasinglulu  */
198*91f16700Schasinglulu void plat_marvell_gic_irq_pcpu_save(void)
199*91f16700Schasinglulu {
200*91f16700Schasinglulu 	gicv3_rdistif_save(plat_my_core_pos(), &rdist_ctx);
201*91f16700Schasinglulu }
202*91f16700Schasinglulu 
203*91f16700Schasinglulu /******************************************************************************
204*91f16700Schasinglulu  * Marvell common helper to restore per-cpu PPI irq states in GICv3
205*91f16700Schasinglulu  ******************************************************************************
206*91f16700Schasinglulu  */
207*91f16700Schasinglulu void plat_marvell_gic_irq_pcpu_restore(void)
208*91f16700Schasinglulu {
209*91f16700Schasinglulu 	gicv3_rdistif_init_restore(plat_my_core_pos(), &rdist_ctx);
210*91f16700Schasinglulu }
211