37#ifndef _RTEMS_DEV_IRQ_ARM_GICV3_H
38#define _RTEMS_DEV_IRQ_ARM_GICV3_H
41#include <dev/irq/arm-gic-arch.h>
47#define PRIORITY_DEFAULT 127
49#define MPIDR_AFFINITY2(val) BSP_FLD64(val, 16, 23)
50#define MPIDR_AFFINITY2_GET(reg) BSP_FLD64GET(reg, 16, 23)
51#define MPIDR_AFFINITY2_SET(reg, val) BSP_FLD64SET(reg, val, 16, 23)
52#define MPIDR_AFFINITY1(val) BSP_FLD64(val, 8, 15)
53#define MPIDR_AFFINITY1_GET(reg) BSP_FLD64GET(reg, 8, 15)
54#define MPIDR_AFFINITY1_SET(reg, val) BSP_FLD64SET(reg, val, 8, 15)
55#define MPIDR_AFFINITY0(val) BSP_FLD64(val, 0, 7)
56#define MPIDR_AFFINITY0_GET(reg) BSP_FLD64GET(reg, 0, 7)
57#define MPIDR_AFFINITY0_SET(reg, val) BSP_FLD64SET(reg, val, 0, 7)
59#define ICC_SGIR_AFFINITY3(val) BSP_FLD64(val, 48, 55)
60#define ICC_SGIR_AFFINITY3_GET(reg) BSP_FLD64GET(reg, 48, 55)
61#define ICC_SGIR_AFFINITY3_SET(reg, val) BSP_FLD64SET(reg, val, 48, 55)
62#define ICC_SGIR_IRM BSP_BIT32(40)
63#define ICC_SGIR_AFFINITY2(val) BSP_FLD64(val, 32, 39)
64#define ICC_SGIR_AFFINITY2_GET(reg) BSP_FLD64GET(reg, 32, 39)
65#define ICC_SGIR_AFFINITY2_SET(reg, val) BSP_FLD64SET(reg, val, 32, 39)
66#define ICC_SGIR_INTID(val) BSP_FLD64(val, 24, 27)
67#define ICC_SGIR_INTID_GET(reg) BSP_FLD64GET(reg, 24, 27)
68#define ICC_SGIR_INTID_SET(reg, val) BSP_FLD64SET(reg, val, 24, 27)
69#define ICC_SGIR_AFFINITY1(val) BSP_FLD64(val, 16, 23)
70#define ICC_SGIR_AFFINITY1_GET(reg) BSP_FLD64GET(reg, 16, 23)
71#define ICC_SGIR_AFFINITY1_SET(reg, val) BSP_FLD64SET(reg, val, 16, 23)
72#define ICC_SGIR_CPU_TARGET_LIST(val) BSP_FLD64(val, 0, 15)
73#define ICC_SGIR_CPU_TARGET_LIST_GET(reg) BSP_FLD64GET(reg, 0, 15)
74#define ICC_SGIR_CPU_TARGET_LIST_SET(reg, val) BSP_FLD64SET(reg, val, 0, 15)
76#ifdef ARM_MULTILIB_ARCH_V4
78#define ICC_CTLR "p15, 0, %0, c12, c12, 4"
81#define ICC_PMR "p15, 0, %0, c4, c6, 0"
84#define ICC_BPR0 "p15, 0, %0, c12, c8, 3"
85#define ICC_BPR1 "p15, 0, %0, c12, c12, 3"
88#define ICC_IAR0 "p15, 0, %0, c12, c8, 0"
89#define ICC_IAR1 "p15, 0, %0, c12, c12, 0"
92#define ICC_EOIR0 "p15, 0, %0, c12, c8, 1"
93#define ICC_EOIR1 "p15, 0, %0, c12, c12, 1"
95#define ICC_SRE "p15, 0, %0, c12, c12, 5"
97#define ICC_IGRPEN0 "p15, 0, %0, c12, c12, 6"
98#define ICC_IGRPEN1 "p15, 0, %0, c12, c12, 7"
100#define MPIDR "p15, 0, %0, c0, c0, 5"
102#define READ_SR(SR_NAME) \
105 __asm__ volatile("mrc " SR_NAME : "=r" (value) ); \
109#define WRITE_SR(SR_NAME, VALUE) \
110 __asm__ volatile("mcr " SR_NAME " \n" : : "r" (VALUE) );
112#define ICC_SGI1 "p15, 0, %Q0, %R0, c12"
113#define WRITE64_SR(SR_NAME, VALUE) \
114 __asm__ volatile("mcrr " SR_NAME " \n" : : "r" (VALUE) );
119#define ICC_IGRPEN0_EL1 "S3_0_C12_C12_6, %0"
120#define ICC_IGRPEN1_EL1 "S3_0_C12_C12_7, %0"
121#define ICC_IGRPEN1_EL3 "S3_6_C12_C12_7, %0"
122#define ICC_IGRPEN0 ICC_IGRPEN0_EL1
123#define ICC_IGRPEN1 ICC_IGRPEN1_EL1
124#define ICC_PMR "S3_0_C4_C6_0, %0"
125#define ICC_EOIR1 "S3_0_C12_C12_1, %0"
126#define ICC_SRE "S3_0_C12_C12_5, %0"
127#define ICC_BPR0 "S3_0_C12_C8_3, %0"
128#define ICC_BPR1 "S3_0_C12_C12_3, %0"
129#define ICC_CTLR "S3_0_C12_C12_4, %0"
130#define ICC_IAR1 "%0, S3_0_C12_C12_0"
131#define MPIDR "%0, mpidr_el1"
132#define MPIDR_AFFINITY3(val) BSP_FLD64(val, 32, 39)
133#define MPIDR_AFFINITY3_GET(reg) BSP_FLD64GET(reg, 32, 39)
134#define MPIDR_AFFINITY3_SET(reg, val) BSP_FLD64SET(reg, val, 32, 39)
136#define ICC_SGI1 "S3_0_C12_C11_5, %0"
137#define WRITE64_SR(SR_NAME, VALUE) \
138 __asm__ volatile("msr " SR_NAME " \n" : : "r" (VALUE) );
139#define WRITE_SR(SR_NAME, VALUE) WRITE64_SR(SR_NAME, VALUE)
141#define READ_SR(SR_NAME) \
144 __asm__ volatile("mrs " SR_NAME : "=&r" (value) ); \
150static inline volatile gic_redist *gicv3_get_redist(uint32_t cpu_index)
153 ((uintptr_t)BSP_ARM_GIC_REDIST_BASE + cpu_index * 0x20000);
156static inline volatile gic_sgi_ppi *gicv3_get_sgi_ppi(uint32_t cpu_index)
159 ((uintptr_t)BSP_ARM_GIC_REDIST_BASE + cpu_index * 0x20000 + 0x10000);
162static inline void gicv3_sgi_ppi_enable(
167 volatile gic_sgi_ppi *sgi_ppi = gicv3_get_sgi_ppi(cpu_index);
170 sgi_ppi->icspigrpr[0] |= 1U << vector;
171 sgi_ppi->icspigrpmodr[0] &= ~(1U << vector);
174 sgi_ppi->icspiser[0] = 1U << vector;
177static inline void gicv3_sgi_ppi_disable(
182 volatile gic_sgi_ppi *sgi_ppi = gicv3_get_sgi_ppi(cpu_index);
184 sgi_ppi->icspicer[0] = 1U << vector;
187static inline bool gicv3_sgi_ppi_is_enabled(
192 volatile gic_sgi_ppi *sgi_ppi = gicv3_get_sgi_ppi(cpu_index);
194 return (sgi_ppi->icspiser[0] & (1U << vector)) != 0;
197static inline void gicv3_sgi_ppi_set_priority(
203 volatile gic_sgi_ppi *sgi_ppi = gicv3_get_sgi_ppi(cpu_index);
205 sgi_ppi->icspiprior[vector] = priority;
208static inline uint8_t gicv3_sgi_ppi_get_priority(
213 volatile gic_sgi_ppi *sgi_ppi = gicv3_get_sgi_ppi(cpu_index);
215 return sgi_ppi->icspiprior[vector];
218static inline bool gicv3_sgi_ppi_is_pending(
223 volatile gic_sgi_ppi *sgi_ppi = gicv3_get_sgi_ppi(cpu_index);
225 return (sgi_ppi->icspispendr[0] & (1U << vector)) != 0;
228static inline void gicv3_ppi_set_pending(
233 volatile gic_sgi_ppi *sgi_ppi = gicv3_get_sgi_ppi(cpu_index);
235 sgi_ppi->icspispendr[0] = 1U << vector;
238static inline void gicv3_ppi_clear_pending(
243 volatile gic_sgi_ppi *sgi_ppi = gicv3_get_sgi_ppi(cpu_index);
245 sgi_ppi->icspicpendr[0] = 1U << vector;
248static inline void gicv3_trigger_sgi(
253#ifndef ARM_MULTILIB_ARCH_V4
258 mpidr = READ_SR(MPIDR);
259 uint64_t value = ICC_SGIR_AFFINITY2(MPIDR_AFFINITY2_GET(mpidr))
260 | ICC_SGIR_INTID(vector)
261 | ICC_SGIR_AFFINITY1(MPIDR_AFFINITY1_GET(mpidr))
262 | ICC_SGIR_CPU_TARGET_LIST(targets);
263#ifndef ARM_MULTILIB_ARCH_V4
264 value |= ICC_SGIR_AFFINITY3(MPIDR_AFFINITY3_GET(mpidr));
266 WRITE64_SR(ICC_SGI1, value);
269static inline uint32_t gicv3_get_id_count(
volatile gic_dist *dist)
271 uint32_t id_count = GIC_DIST_ICDICTR_IT_LINES_NUMBER_GET(dist->icdictr);
273 id_count = 32 * (id_count + 1);
274 id_count = id_count <= 1020 ? id_count : 1020;
279static void gicv3_init_dist(
volatile gic_dist *dist)
281 uint32_t id_count = gicv3_get_id_count(dist);
284 dist->icddcr = GIC_DIST_ICDDCR_ARE_NS | GIC_DIST_ICDDCR_ARE_S
285 | GIC_DIST_ICDDCR_ENABLE_GRP1S | GIC_DIST_ICDDCR_ENABLE_GRP1NS
286 | GIC_DIST_ICDDCR_ENABLE_GRP0;
288 for (
id = 0;
id < id_count;
id += 32) {
290 dist->icdicer[
id / 32] = 0xffffffff;
293 dist->icdigr[
id / 32] = 0xffffffff;
294 dist->icdigmr[
id / 32] = 0;
297 for (
id = 0;
id < id_count; ++id) {
298 gic_id_set_priority(dist,
id, PRIORITY_DEFAULT);
301 for (
id = 32;
id < id_count; ++id) {
302 gic_id_set_targets(dist,
id, 0x01);
306static void gicv3_init_cpu_interface(uint32_t cpu_index)
309#ifdef BSP_ARM_GIC_ICC_SRE
310 WRITE_SR(ICC_SRE, BSP_ARM_GIC_ICC_SRE);
314#ifdef BSP_ARM_GIC_ICC_PMR
315 WRITE_SR(ICC_PMR, BSP_ARM_GIC_ICC_PMR);
319#ifdef BSP_ARM_GIC_ICC_BPR0
320 WRITE_SR(ICC_BPR0, BSP_ARM_GIC_ICC_BPR0);
324#ifdef BSP_ARM_GIC_ICC_BPR1
325 WRITE_SR(ICC_BPR1, BSP_ARM_GIC_ICC_BPR1);
328 volatile gic_redist *redist = gicv3_get_redist(cpu_index);
329 uint32_t waker = redist->icrwaker;
330 uint32_t waker_mask = GIC_REDIST_ICRWAKER_PROCESSOR_SLEEP;
331 waker &= ~waker_mask;
332 redist->icrwaker = waker;
334 volatile gic_sgi_ppi *sgi_ppi = gicv3_get_sgi_ppi(cpu_index);
336 sgi_ppi->icspigrpr[0] = 0xffffffff;
337 sgi_ppi->icspigrpmodr[0] = 0;
338 for (
int id = 0;
id < 32;
id++) {
339 sgi_ppi->icspiprior[id] = PRIORITY_DEFAULT;
343#ifdef BSP_ARM_GIC_ICC_IGRPEN0
344 WRITE_SR(ICC_IGRPEN0, BSP_ARM_GIC_ICC_IGRPEN0);
348#ifdef BSP_ARM_GIC_ICC_IGRPEN1
349 WRITE_SR(ICC_IGRPEN1, BSP_ARM_GIC_ICC_IGRPEN1);
353#ifdef BSP_ARM_GIC_ICC_CTRL
354 WRITE_SR(ICC_CTLR, BSP_ARM_GIC_ICC_CTRL);
358static inline void gicv3_get_attributes(
368 if ( vector <= ARM_GIC_IRQ_SGI_LAST ) {
382 if ( vector > ARM_GIC_IRQ_PPI_LAST ) {
ISR_Vector_number rtems_vector_number
This integer type represents interrupt vector numbers.
Definition: intr.h:102
@ RTEMS_INTERRUPT_NO_SIGNAL
This interrupt signal variant indicates that the interrupt cannot be triggered by a signal.
Definition: intr.h:1820
@ RTEMS_INTERRUPT_UNSPECIFIED_SIGNAL
This interrupt signal variant indicates that the interrupt trigger signal is unspecified.
Definition: intr.h:1814
Definition: arm-gic-regs.h:101
Definition: arm-gic-regs.h:170
Definition: arm-gic-regs.h:202
This structure provides the attributes of an interrupt vector.
Definition: intr.h:1857
bool can_raise_on
This member is true, if the interrupt vector can be raised on a processor by rtems_interrupt_raise_on...
Definition: intr.h:1921
bool can_disable
This member is true, if the interrupt vector can be disabled by rtems_interrupt_vector_disable(),...
Definition: intr.h:1898
bool maybe_enable
This member is true, if the interrupt vector may be enabled by rtems_interrupt_vector_enable(),...
Definition: intr.h:1888
rtems_interrupt_signal_variant trigger_signal
This member describes the trigger signal of the interrupt associated with the interrupt vector.
Definition: intr.h:1967
bool can_raise
This member is true, if the interrupt vector can be raised by rtems_interrupt_raise(),...
Definition: intr.h:1915
bool can_clear
This member is true, if the interrupt vector can be cleared by rtems_interrupt_clear(),...
Definition: intr.h:1927
bool can_set_affinity
This member is true, if the affinity set of the interrupt vector can be set by rtems_interrupt_set_af...
Definition: intr.h:1946
bool cleared_by_acknowledge
This member is true, if the pending status of the interrupt associated with the interrupt vector is c...
Definition: intr.h:1934
bool maybe_disable
This member is true, if the interrupt vector may be disabled by rtems_interrupt_vector_disable(),...
Definition: intr.h:1909
bool is_maskable
This member is true, if the interrupt vector is maskable by rtems_interrupt_local_disable(),...
Definition: intr.h:1866
bool can_get_affinity
This member is true, if the affinity set of the interrupt vector can be obtained by rtems_interrupt_g...
Definition: intr.h:1940