Re: [kvm-unit-tests PATCH 05/32] powerpc: Cleanup SPR and MSR definitions

2024-03-01 Thread Thomas Huth

On 26/02/2024 11.11, Nicholas Piggin wrote:

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 
---
  lib/powerpc/asm/ppc_asm.h   |  8 +---
  lib/powerpc/asm/processor.h |  7 +--
  lib/powerpc/asm/reg.h   | 30 ++
  lib/powerpc/asm/time.h  |  1 +
  lib/ppc64/asm/reg.h |  1 +
  powerpc/sprs.c  | 21 ++---
  6 files changed, 44 insertions(+), 24 deletions(-)
  create mode 100644 lib/powerpc/asm/reg.h
  create mode 100644 lib/ppc64/asm/reg.h


Reviewed-by: Thomas Huth 



[kvm-unit-tests PATCH 05/32] powerpc: Cleanup SPR and MSR definitions

2024-02-26 Thread Nicholas Piggin
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 
---
 lib/powerpc/asm/ppc_asm.h   |  8 +---
 lib/powerpc/asm/processor.h |  7 +--
 lib/powerpc/asm/reg.h   | 30 ++
 lib/powerpc/asm/time.h  |  1 +
 lib/ppc64/asm/reg.h |  1 +
 powerpc/sprs.c  | 21 ++---
 6 files changed, 44 insertions(+), 24 deletions(-)
 create mode 100644 lib/powerpc/asm/reg.h
 create mode 100644 lib/ppc64/asm/reg.h

diff --git a/lib/powerpc/asm/ppc_asm.h b/lib/powerpc/asm/ppc_asm.h
index 46b4be009..52a42dfbe 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 
+#include 
 
 #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 fe1052939..e415f9235 100644
--- a/lib/powerpc/asm/processor.h
+++ b/lib/powerpc/asm/processor.h
@@ -3,18 +3,13 @@
 
 #include 
 #include 
+#include 
 
 #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 0..6810c1d82
--- /dev/null
+++ b/lib/powerpc/asm/reg.h
@@ -0,0 +1,30 @@
+#ifndef _ASMPOWERPC_REG_H
+#define _ASMPOWERPC_REG_H
+
+#include 
+
+#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_PVR0x11f
+#define   PVR_VERSION_MASK UL(0x)
+#define   PVR_VER_970  UL(0x0039)
+#define   PVR_VER_970FXUL(0x003c)
+#define   PVR_VER_970MPUL(0x0044)
+#define   PVR_VER_POWER8E  UL(0x004b)
+#define   PVR_VER_POWER8NVLUL(0x004c)
+#define   PVR_VER_POWER8   UL(0x004d)
+#define   PVR_VER_POWER9   UL(0x004e)
+#define   PVR_VER_POWER10  UL(0x0080)
+#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 72fcb1bd0..a1f072989 100644
--- a/lib/powerpc/asm/time.h
+++ b/lib/powerpc/asm/time.h
@@ -3,6 +3,7 @@
 
 #include 
 #include 
+#include 
 
 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 0..bc407b555
--- /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 285976488..a19d80a1a 100644
--- a/powerpc/sprs.c
+++ b/powerpc/sprs.c
@@ -23,6 +23,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -120,25 +121,23 @@ static void set_sprs_book3s_31(uint64_t val)
 
 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);