summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Vasut <[email protected]>2025-01-01 20:19:04 +0100
committerMarek Vasut <[email protected]>2025-01-12 23:49:58 +0100
commitddb0f26dc45ff2f2528c5e11629c490308ccc708 (patch)
treef3a3c5ee7676f008ca93c1f52c20a5612aa77c19
parentbc157bb6667ed97e33be8ce8436c28baa275b295 (diff)
arm64: Convert core type check macros into inline functions
Turn the core type check macros into inline functions to perform better type checking on them. The inline functions get optimized out in case they are not used. Indent the MIDR_PARTNUM_CORTEX_An macros in preparation for addition of future three-digit cores and use MIDR_PARTNUM_SHIFT in MIDR_PARTNUM_MASK to be consistent. Reviewed-by: Paul Barker <[email protected]> Reviewed-by: Peter Robinson <[email protected]> Signed-off-by: Marek Vasut <[email protected]>
-rw-r--r--arch/arm/include/asm/armv8/cpu.h28
1 files changed, 17 insertions, 11 deletions
diff --git a/arch/arm/include/asm/armv8/cpu.h b/arch/arm/include/asm/armv8/cpu.h
index 40d54dc85ab..aa1470bb72d 100644
--- a/arch/arm/include/asm/armv8/cpu.h
+++ b/arch/arm/include/asm/armv8/cpu.h
@@ -3,11 +3,11 @@
* Copyright 2018 NXP
*/
-#define MIDR_PARTNUM_CORTEX_A35 0xD04
-#define MIDR_PARTNUM_CORTEX_A53 0xD03
-#define MIDR_PARTNUM_CORTEX_A72 0xD08
-#define MIDR_PARTNUM_SHIFT 0x4
-#define MIDR_PARTNUM_MASK (0xFFF << 0x4)
+#define MIDR_PARTNUM_CORTEX_A35 0xD04
+#define MIDR_PARTNUM_CORTEX_A53 0xD03
+#define MIDR_PARTNUM_CORTEX_A72 0xD08
+#define MIDR_PARTNUM_SHIFT 0x4
+#define MIDR_PARTNUM_MASK (0xFFF << MIDR_PARTNUM_SHIFT)
static inline unsigned int read_midr(void)
{
@@ -18,9 +18,15 @@ static inline unsigned int read_midr(void)
return val;
}
-#define is_cortex_a35() (((read_midr() & MIDR_PARTNUM_MASK) >> \
- MIDR_PARTNUM_SHIFT) == MIDR_PARTNUM_CORTEX_A35)
-#define is_cortex_a53() (((read_midr() & MIDR_PARTNUM_MASK) >> \
- MIDR_PARTNUM_SHIFT) == MIDR_PARTNUM_CORTEX_A53)
-#define is_cortex_a72() (((read_midr() & MIDR_PARTNUM_MASK) >>\
- MIDR_PARTNUM_SHIFT) == MIDR_PARTNUM_CORTEX_A72)
+#define is_cortex_a(__n) \
+ static inline int is_cortex_a##__n(void) \
+ { \
+ unsigned int midr = read_midr(); \
+ midr &= MIDR_PARTNUM_MASK; \
+ midr >>= MIDR_PARTNUM_SHIFT; \
+ return midr == MIDR_PARTNUM_CORTEX_A##__n; \
+ }
+
+is_cortex_a(35)
+is_cortex_a(53)
+is_cortex_a(72)