powerpc: Cleanup SPR and MSR definitions
Move SPR and MSR defines out of ppc_asm.h and processor.h and into a
new include, asm/reg.h.
Add a define for the PVR SPR and various processor versions, and replace
the open coded numbers in the sprs.c test case.
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Message-ID: <20240226101218.1472843-6-npiggin@gmail.com>
Reviewed-by: Thomas Huth <thuth@redhat.com>
Signed-off-by: Thomas Huth <thuth@redhat.com>
diff --git a/lib/powerpc/asm/ppc_asm.h b/lib/powerpc/asm/ppc_asm.h
index 46b4be0..52a42df 100644
--- a/lib/powerpc/asm/ppc_asm.h
+++ b/lib/powerpc/asm/ppc_asm.h
@@ -2,6 +2,7 @@
#define _ASMPOWERPC_PPC_ASM_H
#include <asm/asm-offsets.h>
+#include <asm/reg.h>
#define SAVE_GPR(n, base) std n,GPR0+8*(n)(base)
#define REST_GPR(n, base) ld n,GPR0+8*(n)(base)
@@ -35,11 +36,4 @@
#endif /* __BYTE_ORDER__ */
-#define SPR_HSRR0 0x13A
-#define SPR_HSRR1 0x13B
-
-/* Machine State Register definitions: */
-#define MSR_EE_BIT 15 /* External Interrupts Enable */
-#define MSR_SF_BIT 63 /* 64-bit mode */
-
#endif /* _ASMPOWERPC_PPC_ASM_H */
diff --git a/lib/powerpc/asm/processor.h b/lib/powerpc/asm/processor.h
index fe10529..e415f92 100644
--- a/lib/powerpc/asm/processor.h
+++ b/lib/powerpc/asm/processor.h
@@ -3,18 +3,13 @@
#include <libcflat.h>
#include <asm/ptrace.h>
+#include <asm/reg.h>
#ifndef __ASSEMBLY__
void handle_exception(int trap, void (*func)(struct pt_regs *, void *), void *);
void do_handle_exception(struct pt_regs *regs);
#endif /* __ASSEMBLY__ */
-#define SPR_TB 0x10c
-#define SPR_SPRG0 0x110
-#define SPR_SPRG1 0x111
-#define SPR_SPRG2 0x112
-#define SPR_SPRG3 0x113
-
static inline uint64_t mfspr(int nr)
{
uint64_t ret;
diff --git a/lib/powerpc/asm/reg.h b/lib/powerpc/asm/reg.h
new file mode 100644
index 0000000..6810c1d
--- /dev/null
+++ b/lib/powerpc/asm/reg.h
@@ -0,0 +1,30 @@
+#ifndef _ASMPOWERPC_REG_H
+#define _ASMPOWERPC_REG_H
+
+#include <linux/const.h>
+
+#define UL(x) _AC(x, UL)
+
+#define SPR_TB 0x10c
+#define SPR_SPRG0 0x110
+#define SPR_SPRG1 0x111
+#define SPR_SPRG2 0x112
+#define SPR_SPRG3 0x113
+#define SPR_PVR 0x11f
+#define PVR_VERSION_MASK UL(0xffff0000)
+#define PVR_VER_970 UL(0x00390000)
+#define PVR_VER_970FX UL(0x003c0000)
+#define PVR_VER_970MP UL(0x00440000)
+#define PVR_VER_POWER8E UL(0x004b0000)
+#define PVR_VER_POWER8NVL UL(0x004c0000)
+#define PVR_VER_POWER8 UL(0x004d0000)
+#define PVR_VER_POWER9 UL(0x004e0000)
+#define PVR_VER_POWER10 UL(0x00800000)
+#define SPR_HSRR0 0x13a
+#define SPR_HSRR1 0x13b
+
+/* Machine State Register definitions: */
+#define MSR_EE_BIT 15 /* External Interrupts Enable */
+#define MSR_SF_BIT 63 /* 64-bit mode */
+
+#endif
diff --git a/lib/powerpc/asm/time.h b/lib/powerpc/asm/time.h
index 72fcb1b..a1f0729 100644
--- a/lib/powerpc/asm/time.h
+++ b/lib/powerpc/asm/time.h
@@ -3,6 +3,7 @@
#include <libcflat.h>
#include <asm/processor.h>
+#include <asm/reg.h>
static inline uint64_t get_tb(void)
{
diff --git a/lib/ppc64/asm/reg.h b/lib/ppc64/asm/reg.h
new file mode 100644
index 0000000..bc407b5
--- /dev/null
+++ b/lib/ppc64/asm/reg.h
@@ -0,0 +1 @@
+#include "../../powerpc/asm/reg.h"
diff --git a/powerpc/sprs.c b/powerpc/sprs.c
index 2859764..a19d80a 100644
--- a/powerpc/sprs.c
+++ b/powerpc/sprs.c
@@ -23,6 +23,7 @@
#include <util.h>
#include <migrate.h>
#include <alloc.h>
+#include <asm/ppc_asm.h>
#include <asm/handlers.h>
#include <asm/hcall.h>
#include <asm/processor.h>
@@ -120,25 +121,23 @@
static void set_sprs(uint64_t val)
{
- uint32_t pvr = mfspr(287); /* Processor Version Register */
-
set_sprs_common(val);
- switch (pvr >> 16) {
- case 0x39: /* PPC970 */
- case 0x3C: /* PPC970FX */
- case 0x44: /* PPC970MP */
+ switch (mfspr(SPR_PVR) & PVR_VERSION_MASK) {
+ case PVR_VER_970:
+ case PVR_VER_970FX:
+ case PVR_VER_970MP:
set_sprs_book3s_201(val);
break;
- case 0x4b: /* POWER8E */
- case 0x4c: /* POWER8NVL */
- case 0x4d: /* POWER8 */
+ case PVR_VER_POWER8E:
+ case PVR_VER_POWER8NVL:
+ case PVR_VER_POWER8:
set_sprs_book3s_207(val);
break;
- case 0x4e: /* POWER9 */
+ case PVR_VER_POWER9:
set_sprs_book3s_300(val);
break;
- case 0x80: /* POWER10 */
+ case PVR_VER_POWER10:
set_sprs_book3s_31(val);
break;
default: