1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * arch/arm/include/asm/arch_gicv3.h
5 * Copyright (C) 2015 ARM Ltd.
7 #ifndef __ASM_ARCH_GICV3_H
8 #define __ASM_ARCH_GICV3_H
13 #include <linux/io-64-nonatomic-lo-hi.h>
14 #include <asm/barrier.h>
15 #include <asm/cacheflush.h>
18 #define ICC_EOIR1 __ACCESS_CP15(c12, 0, c12, 1)
19 #define ICC_DIR __ACCESS_CP15(c12, 0, c11, 1)
20 #define ICC_IAR1 __ACCESS_CP15(c12, 0, c12, 0)
21 #define ICC_SGI1R __ACCESS_CP15_64(0, c12)
22 #define ICC_PMR __ACCESS_CP15(c4, 0, c6, 0)
23 #define ICC_CTLR __ACCESS_CP15(c12, 0, c12, 4)
24 #define ICC_SRE __ACCESS_CP15(c12, 0, c12, 5)
25 #define ICC_IGRPEN1 __ACCESS_CP15(c12, 0, c12, 7)
26 #define ICC_BPR1 __ACCESS_CP15(c12, 0, c12, 3)
27 #define ICC_RPR __ACCESS_CP15(c12, 0, c11, 3)
29 #define __ICC_AP0Rx(x) __ACCESS_CP15(c12, 0, c8, 4 | x)
30 #define ICC_AP0R0 __ICC_AP0Rx(0)
31 #define ICC_AP0R1 __ICC_AP0Rx(1)
32 #define ICC_AP0R2 __ICC_AP0Rx(2)
33 #define ICC_AP0R3 __ICC_AP0Rx(3)
35 #define __ICC_AP1Rx(x) __ACCESS_CP15(c12, 0, c9, x)
36 #define ICC_AP1R0 __ICC_AP1Rx(0)
37 #define ICC_AP1R1 __ICC_AP1Rx(1)
38 #define ICC_AP1R2 __ICC_AP1Rx(2)
39 #define ICC_AP1R3 __ICC_AP1Rx(3)
41 #define ICC_HSRE __ACCESS_CP15(c12, 4, c9, 5)
43 #define ICH_VSEIR __ACCESS_CP15(c12, 4, c9, 4)
44 #define ICH_HCR __ACCESS_CP15(c12, 4, c11, 0)
45 #define ICH_VTR __ACCESS_CP15(c12, 4, c11, 1)
46 #define ICH_MISR __ACCESS_CP15(c12, 4, c11, 2)
47 #define ICH_EISR __ACCESS_CP15(c12, 4, c11, 3)
48 #define ICH_ELRSR __ACCESS_CP15(c12, 4, c11, 5)
49 #define ICH_VMCR __ACCESS_CP15(c12, 4, c11, 7)
51 #define __LR0(x) __ACCESS_CP15(c12, 4, c12, x)
52 #define __LR8(x) __ACCESS_CP15(c12, 4, c13, x)
54 #define ICH_LR0 __LR0(0)
55 #define ICH_LR1 __LR0(1)
56 #define ICH_LR2 __LR0(2)
57 #define ICH_LR3 __LR0(3)
58 #define ICH_LR4 __LR0(4)
59 #define ICH_LR5 __LR0(5)
60 #define ICH_LR6 __LR0(6)
61 #define ICH_LR7 __LR0(7)
62 #define ICH_LR8 __LR8(0)
63 #define ICH_LR9 __LR8(1)
64 #define ICH_LR10 __LR8(2)
65 #define ICH_LR11 __LR8(3)
66 #define ICH_LR12 __LR8(4)
67 #define ICH_LR13 __LR8(5)
68 #define ICH_LR14 __LR8(6)
69 #define ICH_LR15 __LR8(7)
72 #define __LRC0(x) __ACCESS_CP15(c12, 4, c14, x)
73 #define __LRC8(x) __ACCESS_CP15(c12, 4, c15, x)
75 #define ICH_LRC0 __LRC0(0)
76 #define ICH_LRC1 __LRC0(1)
77 #define ICH_LRC2 __LRC0(2)
78 #define ICH_LRC3 __LRC0(3)
79 #define ICH_LRC4 __LRC0(4)
80 #define ICH_LRC5 __LRC0(5)
81 #define ICH_LRC6 __LRC0(6)
82 #define ICH_LRC7 __LRC0(7)
83 #define ICH_LRC8 __LRC8(0)
84 #define ICH_LRC9 __LRC8(1)
85 #define ICH_LRC10 __LRC8(2)
86 #define ICH_LRC11 __LRC8(3)
87 #define ICH_LRC12 __LRC8(4)
88 #define ICH_LRC13 __LRC8(5)
89 #define ICH_LRC14 __LRC8(6)
90 #define ICH_LRC15 __LRC8(7)
92 #define __ICH_AP0Rx(x) __ACCESS_CP15(c12, 4, c8, x)
93 #define ICH_AP0R0 __ICH_AP0Rx(0)
94 #define ICH_AP0R1 __ICH_AP0Rx(1)
95 #define ICH_AP0R2 __ICH_AP0Rx(2)
96 #define ICH_AP0R3 __ICH_AP0Rx(3)
98 #define __ICH_AP1Rx(x) __ACCESS_CP15(c12, 4, c9, x)
99 #define ICH_AP1R0 __ICH_AP1Rx(0)
100 #define ICH_AP1R1 __ICH_AP1Rx(1)
101 #define ICH_AP1R2 __ICH_AP1Rx(2)
102 #define ICH_AP1R3 __ICH_AP1Rx(3)
104 /* A32-to-A64 mappings used by VGIC save/restore */
106 #define CPUIF_MAP(a32, a64) \
107 static inline void write_ ## a64(u32 val) \
109 write_sysreg(val, a32); \
111 static inline u32 read_ ## a64(void) \
113 return read_sysreg(a32); \
116 #define CPUIF_MAP_LO_HI(a32lo, a32hi, a64) \
117 static inline void write_ ## a64(u64 val) \
119 write_sysreg(lower_32_bits(val), a32lo);\
120 write_sysreg(upper_32_bits(val), a32hi);\
122 static inline u64 read_ ## a64(void) \
124 u64 val = read_sysreg(a32lo); \
126 val |= (u64)read_sysreg(a32hi) << 32; \
131 CPUIF_MAP(ICC_PMR
, ICC_PMR_EL1
)
132 CPUIF_MAP(ICC_AP0R0
, ICC_AP0R0_EL1
)
133 CPUIF_MAP(ICC_AP0R1
, ICC_AP0R1_EL1
)
134 CPUIF_MAP(ICC_AP0R2
, ICC_AP0R2_EL1
)
135 CPUIF_MAP(ICC_AP0R3
, ICC_AP0R3_EL1
)
136 CPUIF_MAP(ICC_AP1R0
, ICC_AP1R0_EL1
)
137 CPUIF_MAP(ICC_AP1R1
, ICC_AP1R1_EL1
)
138 CPUIF_MAP(ICC_AP1R2
, ICC_AP1R2_EL1
)
139 CPUIF_MAP(ICC_AP1R3
, ICC_AP1R3_EL1
)
141 CPUIF_MAP(ICH_HCR
, ICH_HCR_EL2
)
142 CPUIF_MAP(ICH_VTR
, ICH_VTR_EL2
)
143 CPUIF_MAP(ICH_MISR
, ICH_MISR_EL2
)
144 CPUIF_MAP(ICH_EISR
, ICH_EISR_EL2
)
145 CPUIF_MAP(ICH_ELRSR
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, ICH_LRC4
, ICH_LR4_EL2
)
170 CPUIF_MAP_LO_HI(ICH_LR3
, ICH_LRC3
, ICH_LR3_EL2
)
171 CPUIF_MAP_LO_HI(ICH_LR2
, ICH_LRC2
, ICH_LR2_EL2
)
172 CPUIF_MAP_LO_HI(ICH_LR1
, ICH_LRC1
, ICH_LR1_EL2
)
173 CPUIF_MAP_LO_HI(ICH_LR0
, ICH_LRC0
, ICH_LR0_EL2
)
175 #define read_gicreg(r) read_##r()
176 #define write_gicreg(v, r) write_##r(v)
178 /* Low-level accessors */
180 static inline void gic_write_eoir(u32 irq
)
182 write_sysreg(irq
, ICC_EOIR1
);
186 static inline void gic_write_dir(u32 val
)
188 write_sysreg(val
, ICC_DIR
);
192 static inline u32
gic_read_iar(void)
194 u32 irqstat
= read_sysreg(ICC_IAR1
);
201 static inline void gic_write_ctlr(u32 val
)
203 write_sysreg(val
, ICC_CTLR
);
207 static inline u32
gic_read_ctlr(void)
209 return read_sysreg(ICC_CTLR
);
212 static inline void gic_write_grpen1(u32 val
)
214 write_sysreg(val
, ICC_IGRPEN1
);
218 static inline void gic_write_sgi1r(u64 val
)
220 write_sysreg(val
, ICC_SGI1R
);
223 static inline u32
gic_read_sre(void)
225 return read_sysreg(ICC_SRE
);
228 static inline void gic_write_sre(u32 val
)
230 write_sysreg(val
, ICC_SRE
);
234 static inline void gic_write_bpr1(u32 val
)
236 write_sysreg(val
, ICC_BPR1
);
239 static inline u32
gic_read_pmr(void)
241 return read_sysreg(ICC_PMR
);
244 static inline void gic_write_pmr(u32 val
)
246 write_sysreg(val
, ICC_PMR
);
249 static inline u32
gic_read_rpr(void)
251 return read_sysreg(ICC_RPR
);
255 * Even in 32bit systems that use LPAE, there is no guarantee that the I/O
256 * interface provides true 64bit atomic accesses, so using strd/ldrd doesn't
258 * Moreover, 64bit I/O emulation is extremely difficult to implement on
259 * AArch32, since the syndrome register doesn't provide any information for
261 * Consequently, the following IO helpers use 32bit accesses.
263 static inline void __gic_writeq_nonatomic(u64 val
, volatile void __iomem
*addr
)
265 writel_relaxed((u32
)val
, addr
);
266 writel_relaxed((u32
)(val
>> 32), addr
+ 4);
269 static inline u64
__gic_readq_nonatomic(const volatile void __iomem
*addr
)
273 val
= readl_relaxed(addr
);
274 val
|= (u64
)readl_relaxed(addr
+ 4) << 32;
278 #define gic_flush_dcache_to_poc(a,l) __cpuc_flush_dcache_area((a), (l))
281 * GICD_IROUTERn, contain the affinity values associated to each interrupt.
282 * The upper-word (aff3) will always be 0, so there is no need for a lock.
284 #define gic_write_irouter(v, c) __gic_writeq_nonatomic(v, c)
287 * GICR_TYPER is an ID register and doesn't need atomicity.
289 #define gic_read_typer(c) __gic_readq_nonatomic(c)
292 * GITS_BASER - hi and lo bits may be accessed independently.
294 #define gits_read_baser(c) __gic_readq_nonatomic(c)
295 #define gits_write_baser(v, c) __gic_writeq_nonatomic(v, c)
298 * GICR_PENDBASER and GICR_PROPBASE are changed with LPIs disabled, so they
299 * won't be being used during any updates and can be changed non-atomically
301 #define gicr_read_propbaser(c) __gic_readq_nonatomic(c)
302 #define gicr_write_propbaser(v, c) __gic_writeq_nonatomic(v, c)
303 #define gicr_read_pendbaser(c) __gic_readq_nonatomic(c)
304 #define gicr_write_pendbaser(v, c) __gic_writeq_nonatomic(v, c)
307 * GICR_xLPIR - only the lower bits are significant
309 #define gic_read_lpir(c) readl_relaxed(c)
310 #define gic_write_lpir(v, c) writel_relaxed(lower_32_bits(v), c)
313 * GITS_TYPER is an ID register and doesn't need atomicity.
315 #define gits_read_typer(c) __gic_readq_nonatomic(c)
318 * GITS_CBASER - hi and lo bits may be accessed independently.
320 #define gits_read_cbaser(c) __gic_readq_nonatomic(c)
321 #define gits_write_cbaser(v, c) __gic_writeq_nonatomic(v, c)
324 * GITS_CWRITER - hi and lo bits may be accessed independently.
326 #define gits_write_cwriter(v, c) __gic_writeq_nonatomic(v, c)
329 * GITS_VPROPBASER - hi and lo bits may be accessed independently.
331 #define gits_read_vpropbaser(c) __gic_readq_nonatomic(c)
332 #define gits_write_vpropbaser(v, c) __gic_writeq_nonatomic(v, c)
335 * GITS_VPENDBASER - the Valid bit must be cleared before changing
338 static inline void gits_write_vpendbaser(u64 val
, void __iomem
*addr
)
342 tmp
= readl_relaxed(addr
+ 4);
343 if (tmp
& (GICR_VPENDBASER_Valid
>> 32)) {
344 tmp
&= ~(GICR_VPENDBASER_Valid
>> 32);
345 writel_relaxed(tmp
, addr
+ 4);
349 * Use the fact that __gic_writeq_nonatomic writes the second
350 * half of the 64bit quantity after the first.
352 __gic_writeq_nonatomic(val
, addr
);
355 #define gits_read_vpendbaser(c) __gic_readq_nonatomic(c)
357 static inline bool gic_prio_masking_enabled(void)
362 static inline void gic_pmr_mask_irqs(void)
364 /* Should not get called. */
368 static inline void gic_arch_enable_irqs(void)
370 /* Should not get called. */
374 #endif /* !__ASSEMBLY__ */
375 #endif /* !__ASM_ARCH_GICV3_H */