diff options
| author | Marek Vasut <[email protected]> | 2026-03-16 00:50:33 +0100 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2026-03-27 13:22:02 -0600 |
| commit | c3c082aa437d077ab103a8f841137ac3a6fa57e2 (patch) | |
| tree | de6bc3ffc6dae7728f4d6b4ad47ee290abad79eb | |
| parent | b5517950e6ef9b631299f33a4ce84ba380928258 (diff) | |
arm: Introduce current_pl() on ARM32 and compatibility current_el()
The ARM32 has PLx Privilege Levels instead of Exception Levels present
on ARM64. Introduce current_pl() function which reports the current PL
on ARM32.
Introduce current_el() for ARM32 as well and current_pl() for ARM64
which each call the other matching function. This is mainly mean to
allow code like this to compile and retain compile time code coverage:
if (IS_ENABLED(CONFIG_ARM64) && current_el() != 3) { ... }
if (!IS_ENABLED(CONFIG_ARM64) && current_pl() != 0) { ... }
Signed-off-by: Marek Vasut <[email protected]>
| -rw-r--r-- | arch/arm/include/asm/system.h | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/arch/arm/include/asm/system.h b/arch/arm/include/asm/system.h index 4c1b81483c9..9e3ad57073d 100644 --- a/arch/arm/include/asm/system.h +++ b/arch/arm/include/asm/system.h @@ -171,6 +171,12 @@ static inline unsigned int current_el(void) return 3 & (el >> 2); } +static inline unsigned int current_pl(void) +{ + /* Aarch32 compatibility */ + return current_el(); +}; + static inline unsigned long get_sctlr(void) { unsigned int el; @@ -466,6 +472,39 @@ static inline int is_hyp(void) #endif } +static inline int is_usr(void) +{ + return (get_cpsr() & 0x1f) == 0x10; +} + +static inline unsigned int current_pl(void) +{ + /* + * ARM DDI 0406C.d ID040418 , page 140 chapter A3.6.1 "Processor + * privilege levels, execution privilege, and access privilege", + * clarifies the PLx levels as follows (abbreviated): + * The characteristics of the privilege levels are: + * - PL0 - The privilege level of application software, that + * executes in User mode. + * - PL1 - Software execution in all modes other than User mode + * and Hyp mode is at PL1. + * - PL2 - Software executing in Hyp mode executes at PL2. + */ + if (is_hyp()) /* HYP */ + return 2; + + if (is_usr()) /* USR */ + return 0; + + return 1; /* The rest */ +} + +static inline unsigned int current_el(void) +{ + /* Aarch64 compatibility */ + return current_pl(); +}; + static inline unsigned int get_cr(void) { unsigned int val; |
