18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef __ASM_ARM_CP15_H 38c2ecf20Sopenharmony_ci#define __ASM_ARM_CP15_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <asm/barrier.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci/* 88c2ecf20Sopenharmony_ci * CR1 bits (CP#15 CR1) 98c2ecf20Sopenharmony_ci */ 108c2ecf20Sopenharmony_ci#define CR_M (1 << 0) /* MMU enable */ 118c2ecf20Sopenharmony_ci#define CR_A (1 << 1) /* Alignment abort enable */ 128c2ecf20Sopenharmony_ci#define CR_C (1 << 2) /* Dcache enable */ 138c2ecf20Sopenharmony_ci#define CR_W (1 << 3) /* Write buffer enable */ 148c2ecf20Sopenharmony_ci#define CR_P (1 << 4) /* 32-bit exception handler */ 158c2ecf20Sopenharmony_ci#define CR_D (1 << 5) /* 32-bit data address range */ 168c2ecf20Sopenharmony_ci#define CR_L (1 << 6) /* Implementation defined */ 178c2ecf20Sopenharmony_ci#define CR_B (1 << 7) /* Big endian */ 188c2ecf20Sopenharmony_ci#define CR_S (1 << 8) /* System MMU protection */ 198c2ecf20Sopenharmony_ci#define CR_R (1 << 9) /* ROM MMU protection */ 208c2ecf20Sopenharmony_ci#define CR_F (1 << 10) /* Implementation defined */ 218c2ecf20Sopenharmony_ci#define CR_Z (1 << 11) /* Implementation defined */ 228c2ecf20Sopenharmony_ci#define CR_I (1 << 12) /* Icache enable */ 238c2ecf20Sopenharmony_ci#define CR_V (1 << 13) /* Vectors relocated to 0xffff0000 */ 248c2ecf20Sopenharmony_ci#define CR_RR (1 << 14) /* Round Robin cache replacement */ 258c2ecf20Sopenharmony_ci#define CR_L4 (1 << 15) /* LDR pc can set T bit */ 268c2ecf20Sopenharmony_ci#define CR_DT (1 << 16) 278c2ecf20Sopenharmony_ci#ifdef CONFIG_MMU 288c2ecf20Sopenharmony_ci#define CR_HA (1 << 17) /* Hardware management of Access Flag */ 298c2ecf20Sopenharmony_ci#else 308c2ecf20Sopenharmony_ci#define CR_BR (1 << 17) /* MPU Background region enable (PMSA) */ 318c2ecf20Sopenharmony_ci#endif 328c2ecf20Sopenharmony_ci#define CR_IT (1 << 18) 338c2ecf20Sopenharmony_ci#define CR_ST (1 << 19) 348c2ecf20Sopenharmony_ci#define CR_FI (1 << 21) /* Fast interrupt (lower latency mode) */ 358c2ecf20Sopenharmony_ci#define CR_U (1 << 22) /* Unaligned access operation */ 368c2ecf20Sopenharmony_ci#define CR_XP (1 << 23) /* Extended page tables */ 378c2ecf20Sopenharmony_ci#define CR_VE (1 << 24) /* Vectored interrupts */ 388c2ecf20Sopenharmony_ci#define CR_EE (1 << 25) /* Exception (Big) Endian */ 398c2ecf20Sopenharmony_ci#define CR_TRE (1 << 28) /* TEX remap enable */ 408c2ecf20Sopenharmony_ci#define CR_AFE (1 << 29) /* Access flag enable */ 418c2ecf20Sopenharmony_ci#define CR_TE (1 << 30) /* Thumb exception enable */ 428c2ecf20Sopenharmony_ci 438c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__ 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#if __LINUX_ARM_ARCH__ >= 4 468c2ecf20Sopenharmony_ci#define vectors_high() (get_cr() & CR_V) 478c2ecf20Sopenharmony_ci#else 488c2ecf20Sopenharmony_ci#define vectors_high() (0) 498c2ecf20Sopenharmony_ci#endif 508c2ecf20Sopenharmony_ci 518c2ecf20Sopenharmony_ci#ifdef CONFIG_CPU_CP15 528c2ecf20Sopenharmony_ci 538c2ecf20Sopenharmony_ci#include <asm/vdso/cp15.h> 548c2ecf20Sopenharmony_ci 558c2ecf20Sopenharmony_ciextern unsigned long cr_alignment; /* defined in entry-armv.S */ 568c2ecf20Sopenharmony_ci 578c2ecf20Sopenharmony_cistatic inline unsigned long get_cr(void) 588c2ecf20Sopenharmony_ci{ 598c2ecf20Sopenharmony_ci unsigned long val; 608c2ecf20Sopenharmony_ci asm("mrc p15, 0, %0, c1, c0, 0 @ get CR" : "=r" (val) : : "cc"); 618c2ecf20Sopenharmony_ci return val; 628c2ecf20Sopenharmony_ci} 638c2ecf20Sopenharmony_ci 648c2ecf20Sopenharmony_cistatic inline void set_cr(unsigned long val) 658c2ecf20Sopenharmony_ci{ 668c2ecf20Sopenharmony_ci asm volatile("mcr p15, 0, %0, c1, c0, 0 @ set CR" 678c2ecf20Sopenharmony_ci : : "r" (val) : "cc"); 688c2ecf20Sopenharmony_ci isb(); 698c2ecf20Sopenharmony_ci} 708c2ecf20Sopenharmony_ci 718c2ecf20Sopenharmony_cistatic inline unsigned int get_auxcr(void) 728c2ecf20Sopenharmony_ci{ 738c2ecf20Sopenharmony_ci unsigned int val; 748c2ecf20Sopenharmony_ci asm("mrc p15, 0, %0, c1, c0, 1 @ get AUXCR" : "=r" (val)); 758c2ecf20Sopenharmony_ci return val; 768c2ecf20Sopenharmony_ci} 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_cistatic inline void set_auxcr(unsigned int val) 798c2ecf20Sopenharmony_ci{ 808c2ecf20Sopenharmony_ci asm volatile("mcr p15, 0, %0, c1, c0, 1 @ set AUXCR" 818c2ecf20Sopenharmony_ci : : "r" (val)); 828c2ecf20Sopenharmony_ci isb(); 838c2ecf20Sopenharmony_ci} 848c2ecf20Sopenharmony_ci 858c2ecf20Sopenharmony_ci#define CPACC_FULL(n) (3 << (n * 2)) 868c2ecf20Sopenharmony_ci#define CPACC_SVC(n) (1 << (n * 2)) 878c2ecf20Sopenharmony_ci#define CPACC_DISABLE(n) (0 << (n * 2)) 888c2ecf20Sopenharmony_ci 898c2ecf20Sopenharmony_cistatic inline unsigned int get_copro_access(void) 908c2ecf20Sopenharmony_ci{ 918c2ecf20Sopenharmony_ci unsigned int val; 928c2ecf20Sopenharmony_ci asm("mrc p15, 0, %0, c1, c0, 2 @ get copro access" 938c2ecf20Sopenharmony_ci : "=r" (val) : : "cc"); 948c2ecf20Sopenharmony_ci return val; 958c2ecf20Sopenharmony_ci} 968c2ecf20Sopenharmony_ci 978c2ecf20Sopenharmony_cistatic inline void set_copro_access(unsigned int val) 988c2ecf20Sopenharmony_ci{ 998c2ecf20Sopenharmony_ci asm volatile("mcr p15, 0, %0, c1, c0, 2 @ set copro access" 1008c2ecf20Sopenharmony_ci : : "r" (val) : "cc"); 1018c2ecf20Sopenharmony_ci isb(); 1028c2ecf20Sopenharmony_ci} 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci#else /* ifdef CONFIG_CPU_CP15 */ 1058c2ecf20Sopenharmony_ci 1068c2ecf20Sopenharmony_ci/* 1078c2ecf20Sopenharmony_ci * cr_alignment is tightly coupled to cp15 (at least in the minds of the 1088c2ecf20Sopenharmony_ci * developers). Yielding 0 for machines without a cp15 (and making it 1098c2ecf20Sopenharmony_ci * read-only) is fine for most cases and saves quite some #ifdeffery. 1108c2ecf20Sopenharmony_ci */ 1118c2ecf20Sopenharmony_ci#define cr_alignment UL(0) 1128c2ecf20Sopenharmony_ci 1138c2ecf20Sopenharmony_cistatic inline unsigned long get_cr(void) 1148c2ecf20Sopenharmony_ci{ 1158c2ecf20Sopenharmony_ci return 0; 1168c2ecf20Sopenharmony_ci} 1178c2ecf20Sopenharmony_ci 1188c2ecf20Sopenharmony_ci#endif /* ifdef CONFIG_CPU_CP15 / else */ 1198c2ecf20Sopenharmony_ci 1208c2ecf20Sopenharmony_ci#endif /* ifndef __ASSEMBLY__ */ 1218c2ecf20Sopenharmony_ci 1228c2ecf20Sopenharmony_ci#endif 123