xref: /linux/arch/arm/include/asm/cp15.h (revision 78c85161)
1b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
215d07dc9SRussell King #ifndef __ASM_ARM_CP15_H
315d07dc9SRussell King #define __ASM_ARM_CP15_H
415d07dc9SRussell King 
59f97da78SDavid Howells #include <asm/barrier.h>
615d07dc9SRussell King 
715d07dc9SRussell King /*
815d07dc9SRussell King  * CR1 bits (CP#15 CR1)
915d07dc9SRussell King  */
1015d07dc9SRussell King #define CR_M	(1 << 0)	/* MMU enable				*/
1115d07dc9SRussell King #define CR_A	(1 << 1)	/* Alignment abort enable		*/
1215d07dc9SRussell King #define CR_C	(1 << 2)	/* Dcache enable			*/
1315d07dc9SRussell King #define CR_W	(1 << 3)	/* Write buffer enable			*/
1415d07dc9SRussell King #define CR_P	(1 << 4)	/* 32-bit exception handler		*/
1515d07dc9SRussell King #define CR_D	(1 << 5)	/* 32-bit data address range		*/
1615d07dc9SRussell King #define CR_L	(1 << 6)	/* Implementation defined		*/
1715d07dc9SRussell King #define CR_B	(1 << 7)	/* Big endian				*/
1815d07dc9SRussell King #define CR_S	(1 << 8)	/* System MMU protection		*/
1915d07dc9SRussell King #define CR_R	(1 << 9)	/* ROM MMU protection			*/
2015d07dc9SRussell King #define CR_F	(1 << 10)	/* Implementation defined		*/
2115d07dc9SRussell King #define CR_Z	(1 << 11)	/* Implementation defined		*/
2215d07dc9SRussell King #define CR_I	(1 << 12)	/* Icache enable			*/
2315d07dc9SRussell King #define CR_V	(1 << 13)	/* Vectors relocated to 0xffff0000	*/
2415d07dc9SRussell King #define CR_RR	(1 << 14)	/* Round Robin cache replacement	*/
2515d07dc9SRussell King #define CR_L4	(1 << 15)	/* LDR pc can set T bit			*/
2615d07dc9SRussell King #define CR_DT	(1 << 16)
27aca7e592SJonathan Austin #ifdef CONFIG_MMU
28aca7e592SJonathan Austin #define CR_HA	(1 << 17)	/* Hardware management of Access Flag   */
29aca7e592SJonathan Austin #else
30aca7e592SJonathan Austin #define CR_BR	(1 << 17)	/* MPU Background region enable (PMSA)  */
31aca7e592SJonathan Austin #endif
3215d07dc9SRussell King #define CR_IT	(1 << 18)
3315d07dc9SRussell King #define CR_ST	(1 << 19)
3415d07dc9SRussell King #define CR_FI	(1 << 21)	/* Fast interrupt (lower latency mode)	*/
3515d07dc9SRussell King #define CR_U	(1 << 22)	/* Unaligned access operation		*/
3615d07dc9SRussell King #define CR_XP	(1 << 23)	/* Extended page tables			*/
3715d07dc9SRussell King #define CR_VE	(1 << 24)	/* Vectored interrupts			*/
3815d07dc9SRussell King #define CR_EE	(1 << 25)	/* Exception (Big) Endian		*/
3915d07dc9SRussell King #define CR_TRE	(1 << 28)	/* TEX remap enable			*/
4015d07dc9SRussell King #define CR_AFE	(1 << 29)	/* Access flag enable			*/
4115d07dc9SRussell King #define CR_TE	(1 << 30)	/* Thumb exception enable		*/
4215d07dc9SRussell King 
4315d07dc9SRussell King #ifndef __ASSEMBLY__
4415d07dc9SRussell King 
4515d07dc9SRussell King #if __LINUX_ARM_ARCH__ >= 4
464585eaffSRussell King #define vectors_high()	(get_cr() & CR_V)
4715d07dc9SRussell King #else
4815d07dc9SRussell King #define vectors_high()	(0)
4915d07dc9SRussell King #endif
5015d07dc9SRussell King 
51b849a60eSUwe Kleine-König #ifdef CONFIG_CPU_CP15
52b849a60eSUwe Kleine-König 
53*78c85161SVincenzo Frascino #include <asm/vdso/cp15.h>
541f5b62f0SMarc Zyngier 
5515d07dc9SRussell King extern unsigned long cr_alignment;	/* defined in entry-armv.S */
5615d07dc9SRussell King 
get_cr(void)577668fd57SRussell King static inline unsigned long get_cr(void)
5815d07dc9SRussell King {
597668fd57SRussell King 	unsigned long val;
6015d07dc9SRussell King 	asm("mrc p15, 0, %0, c1, c0, 0	@ get CR" : "=r" (val) : : "cc");
6115d07dc9SRussell King 	return val;
6215d07dc9SRussell King }
6315d07dc9SRussell King 
set_cr(unsigned long val)647668fd57SRussell King static inline void set_cr(unsigned long val)
6515d07dc9SRussell King {
6615d07dc9SRussell King 	asm volatile("mcr p15, 0, %0, c1, c0, 0	@ set CR"
6715d07dc9SRussell King 	  : : "r" (val) : "cc");
6815d07dc9SRussell King 	isb();
6915d07dc9SRussell King }
7015d07dc9SRussell King 
get_auxcr(void)71bbc8d77dSRob Herring static inline unsigned int get_auxcr(void)
72bbc8d77dSRob Herring {
73bbc8d77dSRob Herring 	unsigned int val;
74bbc8d77dSRob Herring 	asm("mrc p15, 0, %0, c1, c0, 1	@ get AUXCR" : "=r" (val));
75bbc8d77dSRob Herring 	return val;
76bbc8d77dSRob Herring }
77bbc8d77dSRob Herring 
set_auxcr(unsigned int val)78bbc8d77dSRob Herring static inline void set_auxcr(unsigned int val)
79bbc8d77dSRob Herring {
80bbc8d77dSRob Herring 	asm volatile("mcr p15, 0, %0, c1, c0, 1	@ set AUXCR"
81bbc8d77dSRob Herring 	  : : "r" (val));
82bbc8d77dSRob Herring 	isb();
83bbc8d77dSRob Herring }
84bbc8d77dSRob Herring 
8515d07dc9SRussell King #define CPACC_FULL(n)		(3 << (n * 2))
8615d07dc9SRussell King #define CPACC_SVC(n)		(1 << (n * 2))
8715d07dc9SRussell King #define CPACC_DISABLE(n)	(0 << (n * 2))
8815d07dc9SRussell King 
get_copro_access(void)8915d07dc9SRussell King static inline unsigned int get_copro_access(void)
9015d07dc9SRussell King {
9115d07dc9SRussell King 	unsigned int val;
9215d07dc9SRussell King 	asm("mrc p15, 0, %0, c1, c0, 2 @ get copro access"
9315d07dc9SRussell King 	  : "=r" (val) : : "cc");
9415d07dc9SRussell King 	return val;
9515d07dc9SRussell King }
9615d07dc9SRussell King 
set_copro_access(unsigned int val)9715d07dc9SRussell King static inline void set_copro_access(unsigned int val)
9815d07dc9SRussell King {
9915d07dc9SRussell King 	asm volatile("mcr p15, 0, %0, c1, c0, 2 @ set copro access"
10015d07dc9SRussell King 	  : : "r" (val) : "cc");
10115d07dc9SRussell King 	isb();
10215d07dc9SRussell King }
10315d07dc9SRussell King 
104b849a60eSUwe Kleine-König #else /* ifdef CONFIG_CPU_CP15 */
105b849a60eSUwe Kleine-König 
106b849a60eSUwe Kleine-König /*
1070aeb3408SRussell King  * cr_alignment is tightly coupled to cp15 (at least in the minds of the
1080aeb3408SRussell King  * developers). Yielding 0 for machines without a cp15 (and making it
1090aeb3408SRussell King  * read-only) is fine for most cases and saves quite some #ifdeffery.
110b849a60eSUwe Kleine-König  */
111b849a60eSUwe Kleine-König #define cr_alignment	UL(0)
112b849a60eSUwe Kleine-König 
get_cr(void)1134585eaffSRussell King static inline unsigned long get_cr(void)
1144585eaffSRussell King {
1154585eaffSRussell King 	return 0;
1164585eaffSRussell King }
1174585eaffSRussell King 
118b849a60eSUwe Kleine-König #endif /* ifdef CONFIG_CPU_CP15 / else */
119b849a60eSUwe Kleine-König 
120b849a60eSUwe Kleine-König #endif /* ifndef __ASSEMBLY__ */
12115d07dc9SRussell King 
12215d07dc9SRussell King #endif
123