1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef __ASM_ARM_CP15_H
3 #define __ASM_ARM_CP15_H
5 #include <asm/barrier.h>
6 #include <linux/stringify.h>
11 #define CR_M (1 << 0) /* MMU enable */
12 #define CR_A (1 << 1) /* Alignment abort enable */
13 #define CR_C (1 << 2) /* Dcache enable */
14 #define CR_W (1 << 3) /* Write buffer enable */
15 #define CR_P (1 << 4) /* 32-bit exception handler */
16 #define CR_D (1 << 5) /* 32-bit data address range */
17 #define CR_L (1 << 6) /* Implementation defined */
18 #define CR_B (1 << 7) /* Big endian */
19 #define CR_S (1 << 8) /* System MMU protection */
20 #define CR_R (1 << 9) /* ROM MMU protection */
21 #define CR_F (1 << 10) /* Implementation defined */
22 #define CR_Z (1 << 11) /* Implementation defined */
23 #define CR_I (1 << 12) /* Icache enable */
24 #define CR_V (1 << 13) /* Vectors relocated to 0xffff0000 */
25 #define CR_RR (1 << 14) /* Round Robin cache replacement */
26 #define CR_L4 (1 << 15) /* LDR pc can set T bit */
27 #define CR_DT (1 << 16)
29 #define CR_HA (1 << 17) /* Hardware management of Access Flag */
31 #define CR_BR (1 << 17) /* MPU Background region enable (PMSA) */
33 #define CR_IT (1 << 18)
34 #define CR_ST (1 << 19)
35 #define CR_FI (1 << 21) /* Fast interrupt (lower latency mode) */
36 #define CR_U (1 << 22) /* Unaligned access operation */
37 #define CR_XP (1 << 23) /* Extended page tables */
38 #define CR_VE (1 << 24) /* Vectored interrupts */
39 #define CR_EE (1 << 25) /* Exception (Big) Endian */
40 #define CR_TRE (1 << 28) /* TEX remap enable */
41 #define CR_AFE (1 << 29) /* Access flag enable */
42 #define CR_TE (1 << 30) /* Thumb exception enable */
46 #if __LINUX_ARM_ARCH__ >= 4
47 #define vectors_high() (get_cr() & CR_V)
49 #define vectors_high() (0)
52 #ifdef CONFIG_CPU_CP15
54 #define __ACCESS_CP15(CRn, Op1, CRm, Op2) \
55 "mrc", "mcr", __stringify(p15, Op1, %0, CRn, CRm, Op2), u32
56 #define __ACCESS_CP15_64(Op1, CRm) \
57 "mrrc", "mcrr", __stringify(p15, Op1, %Q0, %R0, CRm), u64
59 #define __read_sysreg(r, w, c, t) ({ \
61 asm volatile(r " " c : "=r" (__val)); \
64 #define read_sysreg(...) __read_sysreg(__VA_ARGS__)
66 #define __write_sysreg(v, r, w, c, t) asm volatile(w " " c : : "r" ((t)(v)))
67 #define write_sysreg(v, ...) __write_sysreg(v, __VA_ARGS__)
69 #define BPIALL __ACCESS_CP15(c7, 0, c5, 6)
70 #define ICIALLU __ACCESS_CP15(c7, 0, c5, 0)
72 #define TTBR0_32 __ACCESS_CP15(c2, 0, c0, 0)
73 #define TTBR1_32 __ACCESS_CP15(c2, 0, c0, 1)
74 #define PAR_32 __ACCESS_CP15(c7, 0, c4, 0)
75 #define TTBR0_64 __ACCESS_CP15_64(0, c2)
76 #define TTBR1_64 __ACCESS_CP15_64(1, c2)
77 #define PAR_64 __ACCESS_CP15_64(0, c7)
78 #define VTTBR __ACCESS_CP15_64(6, c2)
79 #define CNTV_CVAL __ACCESS_CP15_64(3, c14)
80 #define CNTVOFF __ACCESS_CP15_64(4, c14)
82 #define MIDR __ACCESS_CP15(c0, 0, c0, 0)
83 #define CSSELR __ACCESS_CP15(c0, 2, c0, 0)
84 #define VPIDR __ACCESS_CP15(c0, 4, c0, 0)
85 #define VMPIDR __ACCESS_CP15(c0, 4, c0, 5)
86 #define SCTLR __ACCESS_CP15(c1, 0, c0, 0)
87 #define CPACR __ACCESS_CP15(c1, 0, c0, 2)
88 #define HCR __ACCESS_CP15(c1, 4, c1, 0)
89 #define HDCR __ACCESS_CP15(c1, 4, c1, 1)
90 #define HCPTR __ACCESS_CP15(c1, 4, c1, 2)
91 #define HSTR __ACCESS_CP15(c1, 4, c1, 3)
92 #define TTBCR __ACCESS_CP15(c2, 0, c0, 2)
93 #define HTCR __ACCESS_CP15(c2, 4, c0, 2)
94 #define VTCR __ACCESS_CP15(c2, 4, c1, 2)
95 #define DACR __ACCESS_CP15(c3, 0, c0, 0)
96 #define DFSR __ACCESS_CP15(c5, 0, c0, 0)
97 #define IFSR __ACCESS_CP15(c5, 0, c0, 1)
98 #define ADFSR __ACCESS_CP15(c5, 0, c1, 0)
99 #define AIFSR __ACCESS_CP15(c5, 0, c1, 1)
100 #define HSR __ACCESS_CP15(c5, 4, c2, 0)
101 #define DFAR __ACCESS_CP15(c6, 0, c0, 0)
102 #define IFAR __ACCESS_CP15(c6, 0, c0, 2)
103 #define HDFAR __ACCESS_CP15(c6, 4, c0, 0)
104 #define HIFAR __ACCESS_CP15(c6, 4, c0, 2)
105 #define HPFAR __ACCESS_CP15(c6, 4, c0, 4)
106 #define ICIALLUIS __ACCESS_CP15(c7, 0, c1, 0)
107 #define BPIALLIS __ACCESS_CP15(c7, 0, c1, 6)
108 #define ICIMVAU __ACCESS_CP15(c7, 0, c5, 1)
109 #define ATS1CPR __ACCESS_CP15(c7, 0, c8, 0)
110 #define TLBIALLIS __ACCESS_CP15(c8, 0, c3, 0)
111 #define TLBIALL __ACCESS_CP15(c8, 0, c7, 0)
112 #define TLBIALLNSNHIS __ACCESS_CP15(c8, 4, c3, 4)
113 #define PRRR __ACCESS_CP15(c10, 0, c2, 0)
114 #define NMRR __ACCESS_CP15(c10, 0, c2, 1)
115 #define AMAIR0 __ACCESS_CP15(c10, 0, c3, 0)
116 #define AMAIR1 __ACCESS_CP15(c10, 0, c3, 1)
117 #define VBAR __ACCESS_CP15(c12, 0, c0, 0)
118 #define CID __ACCESS_CP15(c13, 0, c0, 1)
119 #define TID_URW __ACCESS_CP15(c13, 0, c0, 2)
120 #define TID_URO __ACCESS_CP15(c13, 0, c0, 3)
121 #define TID_PRIV __ACCESS_CP15(c13, 0, c0, 4)
122 #define HTPIDR __ACCESS_CP15(c13, 4, c0, 2)
123 #define CNTKCTL __ACCESS_CP15(c14, 0, c1, 0)
124 #define CNTV_CTL __ACCESS_CP15(c14, 0, c3, 1)
125 #define CNTHCTL __ACCESS_CP15(c14, 4, c1, 0)
127 extern unsigned long cr_alignment; /* defined in entry-armv.S */
129 static inline void set_par(u64 val)
131 if (IS_ENABLED(CONFIG_ARM_LPAE))
132 write_sysreg(val, PAR_64);
134 write_sysreg(val, PAR_32);
137 static inline u64 get_par(void)
139 if (IS_ENABLED(CONFIG_ARM_LPAE))
140 return read_sysreg(PAR_64);
142 return read_sysreg(PAR_32);
145 static inline void set_ttbr0(u64 val)
147 if (IS_ENABLED(CONFIG_ARM_LPAE))
148 write_sysreg(val, TTBR0_64);
150 write_sysreg(val, TTBR0_32);
153 static inline u64 get_ttbr0(void)
155 if (IS_ENABLED(CONFIG_ARM_LPAE))
156 return read_sysreg(TTBR0_64);
158 return read_sysreg(TTBR0_32);
161 static inline void set_ttbr1(u64 val)
163 if (IS_ENABLED(CONFIG_ARM_LPAE))
164 write_sysreg(val, TTBR1_64);
166 write_sysreg(val, TTBR1_32);
169 static inline u64 get_ttbr1(void)
171 if (IS_ENABLED(CONFIG_ARM_LPAE))
172 return read_sysreg(TTBR1_64);
174 return read_sysreg(TTBR1_32);
177 static inline unsigned long get_cr(void)
180 asm("mrc p15, 0, %0, c1, c0, 0 @ get CR" : "=r" (val) : : "cc");
184 static inline void set_cr(unsigned long val)
186 asm volatile("mcr p15, 0, %0, c1, c0, 0 @ set CR"
187 : : "r" (val) : "cc");
191 static inline unsigned int get_auxcr(void)
194 asm("mrc p15, 0, %0, c1, c0, 1 @ get AUXCR" : "=r" (val));
198 static inline void set_auxcr(unsigned int val)
200 asm volatile("mcr p15, 0, %0, c1, c0, 1 @ set AUXCR"
205 #define CPACC_FULL(n) (3 << (n * 2))
206 #define CPACC_SVC(n) (1 << (n * 2))
207 #define CPACC_DISABLE(n) (0 << (n * 2))
209 static inline unsigned int get_copro_access(void)
212 asm("mrc p15, 0, %0, c1, c0, 2 @ get copro access"
213 : "=r" (val) : : "cc");
217 static inline void set_copro_access(unsigned int val)
219 asm volatile("mcr p15, 0, %0, c1, c0, 2 @ set copro access"
220 : : "r" (val) : "cc");
224 #else /* ifdef CONFIG_CPU_CP15 */
227 * cr_alignment is tightly coupled to cp15 (at least in the minds of the
228 * developers). Yielding 0 for machines without a cp15 (and making it
229 * read-only) is fine for most cases and saves quite some #ifdeffery.
231 #define cr_alignment UL(0)
233 static inline unsigned long get_cr(void)
238 #endif /* ifdef CONFIG_CPU_CP15 / else */
240 #endif /* ifndef __ASSEMBLY__ */