blob: fecf7bf863f012450621a5b7775285ba63c2f04c [file] [log] [blame]
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +01001/*
2 * arch/arm64/include/asm/arch_gicv3.h
3 *
4 * Copyright (C) 2015 ARM Ltd.
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18#ifndef __ASM_ARCH_GICV3_H
19#define __ASM_ARCH_GICV3_H
20
21#include <asm/sysreg.h>
22
23#define ICC_EOIR1_EL1 sys_reg(3, 0, 12, 12, 1)
24#define ICC_DIR_EL1 sys_reg(3, 0, 12, 11, 1)
25#define ICC_IAR1_EL1 sys_reg(3, 0, 12, 12, 0)
26#define ICC_SGI1R_EL1 sys_reg(3, 0, 12, 11, 5)
27#define ICC_PMR_EL1 sys_reg(3, 0, 4, 6, 0)
28#define ICC_CTLR_EL1 sys_reg(3, 0, 12, 12, 4)
29#define ICC_SRE_EL1 sys_reg(3, 0, 12, 12, 5)
30#define ICC_GRPEN1_EL1 sys_reg(3, 0, 12, 12, 7)
Daniel Thompson91ef8442016-08-19 17:13:09 +010031#define ICC_BPR1_EL1 sys_reg(3, 0, 12, 12, 3)
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +010032
33#define ICC_SRE_EL2 sys_reg(3, 4, 12, 9, 5)
34
35/*
36 * System register definitions
37 */
38#define ICH_VSEIR_EL2 sys_reg(3, 4, 12, 9, 4)
39#define ICH_HCR_EL2 sys_reg(3, 4, 12, 11, 0)
40#define ICH_VTR_EL2 sys_reg(3, 4, 12, 11, 1)
41#define ICH_MISR_EL2 sys_reg(3, 4, 12, 11, 2)
42#define ICH_EISR_EL2 sys_reg(3, 4, 12, 11, 3)
43#define ICH_ELSR_EL2 sys_reg(3, 4, 12, 11, 5)
44#define ICH_VMCR_EL2 sys_reg(3, 4, 12, 11, 7)
45
46#define __LR0_EL2(x) sys_reg(3, 4, 12, 12, x)
47#define __LR8_EL2(x) sys_reg(3, 4, 12, 13, x)
48
49#define ICH_LR0_EL2 __LR0_EL2(0)
50#define ICH_LR1_EL2 __LR0_EL2(1)
51#define ICH_LR2_EL2 __LR0_EL2(2)
52#define ICH_LR3_EL2 __LR0_EL2(3)
53#define ICH_LR4_EL2 __LR0_EL2(4)
54#define ICH_LR5_EL2 __LR0_EL2(5)
55#define ICH_LR6_EL2 __LR0_EL2(6)
56#define ICH_LR7_EL2 __LR0_EL2(7)
57#define ICH_LR8_EL2 __LR8_EL2(0)
58#define ICH_LR9_EL2 __LR8_EL2(1)
59#define ICH_LR10_EL2 __LR8_EL2(2)
60#define ICH_LR11_EL2 __LR8_EL2(3)
61#define ICH_LR12_EL2 __LR8_EL2(4)
62#define ICH_LR13_EL2 __LR8_EL2(5)
63#define ICH_LR14_EL2 __LR8_EL2(6)
64#define ICH_LR15_EL2 __LR8_EL2(7)
65
66#define __AP0Rx_EL2(x) sys_reg(3, 4, 12, 8, x)
67#define ICH_AP0R0_EL2 __AP0Rx_EL2(0)
68#define ICH_AP0R1_EL2 __AP0Rx_EL2(1)
69#define ICH_AP0R2_EL2 __AP0Rx_EL2(2)
70#define ICH_AP0R3_EL2 __AP0Rx_EL2(3)
71
72#define __AP1Rx_EL2(x) sys_reg(3, 4, 12, 9, x)
73#define ICH_AP1R0_EL2 __AP1Rx_EL2(0)
74#define ICH_AP1R1_EL2 __AP1Rx_EL2(1)
75#define ICH_AP1R2_EL2 __AP1Rx_EL2(2)
76#define ICH_AP1R3_EL2 __AP1Rx_EL2(3)
77
78#ifndef __ASSEMBLY__
79
80#include <linux/stringify.h>
Marc Zyngier8e31ed92015-12-07 10:11:12 +000081#include <asm/barrier.h>
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +010082
Vladimir Murzinb5525ce2016-09-12 15:49:16 +010083#define read_gicreg(r) \
84 ({ \
85 u64 reg; \
Alex Matveev79b4e3c2017-11-14 15:06:17 -080086 asm volatile(DEFINE_MRS_S \
87 "mrs_s %0, " __stringify(r) "\n" \
88 UNDEFINE_MRS_S \
89 : "=r" (reg)); \
Vladimir Murzinb5525ce2016-09-12 15:49:16 +010090 reg; \
91 })
92
93#define write_gicreg(v,r) \
94 do { \
95 u64 __val = (v); \
Alex Matveev79b4e3c2017-11-14 15:06:17 -080096 asm volatile(DEFINE_MSR_S \
97 "msr_s " __stringify(r) ", %0\n" \
98 UNDEFINE_MSR_S \
99 : : "r" (__val)); \
Vladimir Murzinb5525ce2016-09-12 15:49:16 +0100100 } while (0)
101
Jean-Philippe Bruckerf6c86a42015-10-01 13:47:15 +0100102/*
103 * Low-level accessors
104 *
105 * These system registers are 32 bits, but we make sure that the compiler
106 * sets the GP register's most significant bits to 0 with an explicit cast.
107 */
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100108
Jean-Philippe Bruckerf6c86a42015-10-01 13:47:15 +0100109static inline void gic_write_eoir(u32 irq)
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100110{
Alex Matveev79b4e3c2017-11-14 15:06:17 -0800111 asm volatile(DEFINE_MSR_S
112 "msr_s " __stringify(ICC_EOIR1_EL1) ", %0\n"
113 UNDEFINE_MSR_S
114 : : "r" ((u64)irq));
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100115 isb();
116}
117
Jean-Philippe Bruckerf6c86a42015-10-01 13:47:15 +0100118static inline void gic_write_dir(u32 irq)
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100119{
Alex Matveev79b4e3c2017-11-14 15:06:17 -0800120 asm volatile(DEFINE_MSR_S
121 "msr_s " __stringify(ICC_DIR_EL1) ", %0\n"
122 UNDEFINE_MSR_S
123 : : "r" ((u64)irq));
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100124 isb();
125}
126
127static inline u64 gic_read_iar_common(void)
128{
129 u64 irqstat;
130
Alex Matveev79b4e3c2017-11-14 15:06:17 -0800131 asm volatile(DEFINE_MRS_S
132 "mrs_s %0, " __stringify(ICC_IAR1_EL1) "\n"
133 UNDEFINE_MRS_S
134 : "=r" (irqstat));
Tirumalesh Chalamarla1a1ebd52016-02-04 10:45:25 -0800135 dsb(sy);
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100136 return irqstat;
137}
138
139/*
140 * Cavium ThunderX erratum 23154
141 *
142 * The gicv3 of ThunderX requires a modified version for reading the
143 * IAR status to ensure data synchronization (access to icc_iar1_el1
144 * is not sync'ed before and after).
145 */
146static inline u64 gic_read_iar_cavium_thunderx(void)
147{
148 u64 irqstat;
149
150 asm volatile(
151 "nop;nop;nop;nop\n\t"
152 "nop;nop;nop;nop\n\t"
Alex Matveev79b4e3c2017-11-14 15:06:17 -0800153 DEFINE_MRS_S
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100154 "mrs_s %0, " __stringify(ICC_IAR1_EL1) "\n\t"
Alex Matveev79b4e3c2017-11-14 15:06:17 -0800155 UNDEFINE_MRS_S
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100156 "nop;nop;nop;nop"
157 : "=r" (irqstat));
158 mb();
159
160 return irqstat;
161}
162
Jean-Philippe Bruckerf6c86a42015-10-01 13:47:15 +0100163static inline void gic_write_pmr(u32 val)
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100164{
Alex Matveev79b4e3c2017-11-14 15:06:17 -0800165 asm volatile(DEFINE_MSR_S
166 "msr_s " __stringify(ICC_PMR_EL1) ", %0\n"
167 UNDEFINE_MSR_S
168 : : "r" ((u64)val));
169 /* As per the architecture specification */
170 mb();
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100171}
172
Jean-Philippe Bruckerf6c86a42015-10-01 13:47:15 +0100173static inline void gic_write_ctlr(u32 val)
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100174{
Alex Matveev79b4e3c2017-11-14 15:06:17 -0800175 asm volatile(DEFINE_MSR_S
176 "msr_s " __stringify(ICC_CTLR_EL1) ", %0\n"
177 UNDEFINE_MSR_S
178 : : "r" ((u64)val));
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100179 isb();
180}
181
Jean-Philippe Bruckerf6c86a42015-10-01 13:47:15 +0100182static inline void gic_write_grpen1(u32 val)
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100183{
Alex Matveev79b4e3c2017-11-14 15:06:17 -0800184 asm volatile(DEFINE_MSR_S
185 "msr_s " __stringify(ICC_GRPEN1_EL1) ", %0\n"
186 UNDEFINE_MSR_S
187 : : "r" ((u64)val));
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100188 isb();
189}
190
191static inline void gic_write_sgi1r(u64 val)
192{
Alex Matveev79b4e3c2017-11-14 15:06:17 -0800193 asm volatile(DEFINE_MSR_S
194 "msr_s " __stringify(ICC_SGI1R_EL1) ", %0\n"
195 UNDEFINE_MSR_S
196 : : "r" (val));
197 /* As per the architecture specification */
198 mb();
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100199}
200
Jean-Philippe Bruckerf6c86a42015-10-01 13:47:15 +0100201static inline u32 gic_read_sre(void)
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100202{
203 u64 val;
204
Alex Matveev79b4e3c2017-11-14 15:06:17 -0800205 asm volatile(DEFINE_MRS_S
206 "mrs_s %0, " __stringify(ICC_SRE_EL1) "\n"
207 UNDEFINE_MRS_S
208 : "=r" (val));
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100209 return val;
210}
211
Jean-Philippe Bruckerf6c86a42015-10-01 13:47:15 +0100212static inline void gic_write_sre(u32 val)
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100213{
Alex Matveev79b4e3c2017-11-14 15:06:17 -0800214 asm volatile(DEFINE_MSR_S
215 "msr_s " __stringify(ICC_SRE_EL1) ", %0\n"
216 UNDEFINE_MSR_S
217 : : "r" ((u64)val));
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100218 isb();
219}
220
Daniel Thompson91ef8442016-08-19 17:13:09 +0100221static inline void gic_write_bpr1(u32 val)
222{
Alex Matveev79b4e3c2017-11-14 15:06:17 -0800223 asm volatile(DEFINE_MSR_S
224 "msr_s " __stringify(ICC_BPR1_EL1) ", %x0\n"
225 UNDEFINE_MSR_S
226 : : "rZ" (val));
Daniel Thompson91ef8442016-08-19 17:13:09 +0100227}
228
Jean-Philippe Brucker72c97122015-10-01 13:47:16 +0100229#define gic_read_typer(c) readq_relaxed(c)
230#define gic_write_irouter(v, c) writeq_relaxed(v, c)
231
Jean-Philippe Brucker7936e912015-10-01 13:47:14 +0100232#endif /* __ASSEMBLY__ */
233#endif /* __ASM_ARCH_GICV3_H */