Skip to contentSkip to conversation

ppc/pnv: HOMER and OCC fixes and improvements

PATCH In review Nicholas Piggin 2 participants 12 messages Dec 10, 2024 – Jan 14, 2025

lore
Share & tools
lore
#0 lore raw

cover ppc/pnv: HOMER and OCC fixes and improvements

This series makes a bunch of fixes and improvements to the HOMER and OCC unit models for powernv. It gets OPAL OCC code happier again, but requires this series of skiboot fixes (which I will hope to get upstream and then into QEMU in the same release as this series is merged.

https://lists.ozlabs.org/pipermail/skiboot/2024-November/019013.html

Big changes is moving HOMER from mmio register implementation to a RAM memory region which better maches hardware and is much easier to work with; and the addition of some dynamic OCC behaviour to the device model.

I wouldn't expect any review of OCC details. It's neglected and this series gets it in better shape than before. But anything on the basic structure and QEMU details is welcome. I will add some test cases to help ensure it doesn't regress in future, I will have to juggle the skiboot fixes as well though, so will do that later.

Thanks,
Nick

Nicholas Piggin (9):
ppc/pnv/homer: Fix OCC registers ppc/pnv/homer: Make dummy reads return 0 ppc/pnv/occ: Fix common area sensor offsets ppc/pnv/homer: class-based base and size ppc/pnv/occ: Better document OCCMISC bits ppc/pnv: Make HOMER memory a RAM region ppc/pnv/occ: Update pstate frequency tables ppc/pnv/occ: Add POWER10 OCC-OPAL data format ppc/pnv/occ: Implement a basic dynamic OCC model

 include/hw/ppc/pnv.h       |   6 +-
 include/hw/ppc/pnv_homer.h |  12 +-
 include/hw/ppc/pnv_occ.h   |   9 +
 hw/ppc/pnv.c               |  87 +++--
 hw/ppc/pnv_homer.c         | 230 +++----------
 hw/ppc/pnv_occ.c           | 668 +++++++++++++++++++++++++++++++++++--
 6 files changed, 742 insertions(+), 270 deletions(-)
Signature · 1 line
2.45.2
#1 lore raw

PATCH 1/9 ppc/pnv/homer: Fix OCC registers

The HOMER OCC registers seem to have bitrotted and fail for various reasons on powernv8, 9, and 10.

The major problems are that POWER8 has the wrong version value and its pstate ordering is incorrect. POWER9/10 have not set the OCC state to active. Non-zero chips are also set to OCC slaves for POWER9/10.

Unfortunately skiboot has also bitrotted and requires fixes that are not yet in the bios files to run. With a patched skiboot, before this change, powernv9/10 report:

[ 0.262050394,3] OCC: Chip: 0: OCC not active
[ 0.262128603,3] OCC: Initialization on all chips did not complete(timed out)

powernv8 reports:

[ 0.173572100,3] OCC: Unknown OCC-OPAL interface version.
[ 0.173812059,3] OCC: Initialization on all chips did not complete(timed out)

After this patch, all report:

[ 0.176815668,5] OCC: All Chip Rdy after 0 ms

---
 hw/ppc/pnv_homer.c | 41 +++++++++++++++++++++++++++++------------
 1 file changed, 29 insertions(+), 12 deletions(-)
hw/ppc/pnv_homer.c +29 -12
index f9a203d11d0..9aedc08cc00 100644
@@ -70,21 +70,24 @@ static uint64_t pnv_power8_homer_read(void *opaque, hwaddr addr,
     PnvHomer *homer = PNV_HOMER(opaque);
 
     switch (addr) {
-    case PNV8_OCC_PSTATE_VERSION:
-    case PNV8_OCC_PSTATE_MIN:
-    case PNV8_OCC_PSTATE_ID_ZERO:
-        return 0;
     case PNV8_OCC_PSTATE_VALID:
+        return 1;
     case PNV8_OCC_PSTATE_THROTTLE:
+        return 0;
+    case PNV8_OCC_PSTATE_VERSION:
+        return 0x02;
+    case PNV8_OCC_PSTATE_MIN:
+        return -2;
     case PNV8_OCC_PSTATE_NOM:
     case PNV8_OCC_PSTATE_TURBO:
-    case PNV8_OCC_PSTATE_ID_ONE:
+        return -1;
+    case PNV8_OCC_PSTATE_ULTRA_TURBO:
+        return 0;
+    case PNV8_OCC_PSTATE_ID_ZERO:
+        return 0;
     case PNV8_OCC_VDD_VOLTAGE_IDENTIFIER:
     case PNV8_OCC_VCS_VOLTAGE_IDENTIFIER:
         return 1;
-    case PNV8_OCC_PSTATE_ULTRA_TURBO:
-    case PNV8_OCC_PSTATE_ID_TWO:
-        return 2;
     case PNV8_OCC_PSTATE_DATA:
         return 0x1000000000000000;
     /* P8 frequency for 0, 1, and 2 pstates */
@@ -92,6 +95,10 @@ static uint64_t pnv_power8_homer_read(void *opaque, hwaddr addr,
     case PNV8_OCC_PSTATE_ONE_FREQUENCY:
     case PNV8_OCC_PSTATE_TWO_FREQUENCY:
         return 3000;
+    case PNV8_OCC_PSTATE_ID_ONE:
+        return -1;
+    case PNV8_OCC_PSTATE_ID_TWO:
+        return -2;
     }
     /* pstate table core max array */
     if (core_max_array(homer, addr)) {
@@ -192,11 +199,12 @@ static const TypeInfo pnv_homer_power8_type_info = {
 
 /* P9 Pstate table */
 
+#define PNV9_OCC_PSTATE_VALID            0xe2000
 #define PNV9_OCC_PSTATE_ID_ZERO          0xe2018
 #define PNV9_OCC_PSTATE_ID_ONE           0xe2020
 #define PNV9_OCC_PSTATE_ID_TWO           0xe2028
 #define PNV9_OCC_PSTATE_DATA             0xe2000
-#define PNV9_OCC_PSTATE_DATA_AREA        0xe2008
+#define PNV9_OCC_PSTATE_MINOR_VERSION    0xe2008
 #define PNV9_OCC_PSTATE_MIN              0xe2003
 #define PNV9_OCC_PSTATE_NOM              0xe2004
 #define PNV9_OCC_PSTATE_TURBO            0xe2005
@@ -211,7 +219,7 @@ static const TypeInfo pnv_homer_power8_type_info = {
 #define PNV9_OCC_PSTATE_TWO_FREQUENCY    0xe202c
 #define PNV9_OCC_ROLE_MASTER_OR_SLAVE    0xe2002
 #define PNV9_CORE_MAX_BASE               0xe2819
-
+#define PNV9_DYNAMIC_DATA_STATE          0xe2b80
 
 static uint64_t pnv_power9_homer_read(void *opaque, hwaddr addr,
                                       unsigned size)
@@ -219,11 +227,17 @@ static uint64_t pnv_power9_homer_read(void *opaque, hwaddr addr,
     PnvHomer *homer = PNV_HOMER(opaque);
 
     switch (addr) {
+    case PNV9_OCC_PSTATE_VALID:
+        return 1;
     case PNV9_OCC_MAX_PSTATE_ULTRA_TURBO:
     case PNV9_OCC_PSTATE_ID_ZERO:
         return 0;
-    case PNV9_OCC_PSTATE_DATA:
     case PNV9_OCC_ROLE_MASTER_OR_SLAVE:
+        if (homer->chip->chip_id == 0) {
+            return 0x1; /* master */
+        } else {
+            return 0x0; /* slave */
+        }
     case PNV9_OCC_PSTATE_NOM:
     case PNV9_OCC_PSTATE_TURBO:
     case PNV9_OCC_PSTATE_ID_ONE:
@@ -241,10 +255,13 @@ static uint64_t pnv_power9_homer_read(void *opaque, hwaddr addr,
         return 3000;
     case PNV9_OCC_PSTATE_MAJOR_VERSION:
         return 0x90;
+    case PNV9_OCC_PSTATE_MINOR_VERSION:
+        return 0x01;
     case PNV9_CHIP_HOMER_BASE:
-    case PNV9_OCC_PSTATE_DATA_AREA:
     case PNV9_CHIP_HOMER_IMAGE_POINTER:
         return 0x1000000000000000;
+    case PNV9_DYNAMIC_DATA_STATE:
+        return 0x03; /* active */
     }
     /* pstate table core max array */
     if (core_max_array(homer, addr)) {
Signature · 1 line
2.45.2
#2 lore raw

PATCH 2/9 ppc/pnv/homer: Make dummy reads return 0

In reply to Nicholas Piggin

HOMER memory implements some dummy registers that return a nonsense value to satisfy skiboot accesses caused by "SLW" init and register save/restore programming that has never worked under QEMU:

[ 0.265000943,3] SLW: Failed to set HRMOR for CPU 0,RC=0x1
[ 0.265356988,3] Disabling deep stop states

To simplify a later change to implement HOMER as a RAM area, make these return zero, which has the same result.

---
 hw/ppc/pnv_homer.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/ppc/pnv_homer.c +2 -2
index 9aedc08cc00..658b0186a38 100644
@@ -89,7 +89,7 @@ static uint64_t pnv_power8_homer_read(void *opaque, hwaddr addr,
     case PNV8_OCC_VCS_VOLTAGE_IDENTIFIER:
         return 1;
     case PNV8_OCC_PSTATE_DATA:
-        return 0x1000000000000000;
+        return 0;
     /* P8 frequency for 0, 1, and 2 pstates */
     case PNV8_OCC_PSTATE_ZERO_FREQUENCY:
     case PNV8_OCC_PSTATE_ONE_FREQUENCY:
@@ -259,7 +259,7 @@ static uint64_t pnv_power9_homer_read(void *opaque, hwaddr addr,
         return 0x01;
     case PNV9_CHIP_HOMER_BASE:
     case PNV9_CHIP_HOMER_IMAGE_POINTER:
-        return 0x1000000000000000;
+        return 0;
     case PNV9_DYNAMIC_DATA_STATE:
         return 0x03; /* active */
     }
Signature · 1 line
2.45.2
#3 lore raw

PATCH 3/9 ppc/pnv/occ: Fix common area sensor offsets

In reply to Nicholas Piggin

The commit to fix the OCC common area sensor mappings didn't update the register offsets to match.

Before this change, skiboot reports:

[ 0.347100086,3] OCC: Chip 0 sensor data invalid

Afterward, there is no error and the sensor_groups directory appears under /sys/firmware/opal/.

The SLW_IMAGE_BASE address looks like a workaround to intercept firmware memory accesses, but that does not seem to be required now (and would have been broken by the OCC common area region mapping change anyway). So it can be removed.

Fixes 3a1b70b66b5cb4 ("ppc/pnv: Fix OCC common area region mapping")
---
 hw/ppc/pnv_occ.c | 33 +++++++++++++++------------------
 1 file changed, 15 insertions(+), 18 deletions(-)
hw/ppc/pnv_occ.c +15 -18
index 48123ceae17..c6681a035a7 100644
@@ -32,22 +32,21 @@
 #define OCB_OCI_OCCMISC_OR      0x4022
 
 /* OCC sensors */
-#define OCC_SENSOR_DATA_BLOCK_OFFSET          0x580000
-#define OCC_SENSOR_DATA_VALID                 0x580001
-#define OCC_SENSOR_DATA_VERSION               0x580002
-#define OCC_SENSOR_DATA_READING_VERSION       0x580004
-#define OCC_SENSOR_DATA_NR_SENSORS            0x580008
-#define OCC_SENSOR_DATA_NAMES_OFFSET          0x580010
-#define OCC_SENSOR_DATA_READING_PING_OFFSET   0x580014
-#define OCC_SENSOR_DATA_READING_PONG_OFFSET   0x58000c
-#define OCC_SENSOR_DATA_NAME_LENGTH           0x58000d
-#define OCC_SENSOR_NAME_STRUCTURE_TYPE        0x580023
-#define OCC_SENSOR_LOC_CORE                   0x580022
-#define OCC_SENSOR_LOC_GPU                    0x580020
-#define OCC_SENSOR_TYPE_POWER                 0x580003
-#define OCC_SENSOR_NAME                       0x580005
-#define HWMON_SENSORS_MASK                    0x58001e
-#define SLW_IMAGE_BASE                        0x0
+#define OCC_SENSOR_DATA_BLOCK_OFFSET          0x0000
+#define OCC_SENSOR_DATA_VALID                 0x0001
+#define OCC_SENSOR_DATA_VERSION               0x0002
+#define OCC_SENSOR_DATA_READING_VERSION       0x0004
+#define OCC_SENSOR_DATA_NR_SENSORS            0x0008
+#define OCC_SENSOR_DATA_NAMES_OFFSET          0x0010
+#define OCC_SENSOR_DATA_READING_PING_OFFSET   0x0014
+#define OCC_SENSOR_DATA_READING_PONG_OFFSET   0x000c
+#define OCC_SENSOR_DATA_NAME_LENGTH           0x000d
+#define OCC_SENSOR_NAME_STRUCTURE_TYPE        0x0023
+#define OCC_SENSOR_LOC_CORE                   0x0022
+#define OCC_SENSOR_LOC_GPU                    0x0020
+#define OCC_SENSOR_TYPE_POWER                 0x0003
+#define OCC_SENSOR_NAME                       0x0005
+#define HWMON_SENSORS_MASK                    0x001e
 
 static void pnv_occ_set_misc(PnvOCC *occ, uint64_t val)
 {
@@ -129,8 +128,6 @@ static uint64_t pnv_occ_common_area_read(void *opaque, hwaddr addr,
     case HWMON_SENSORS_MASK:
     case OCC_SENSOR_LOC_GPU:
         return 0x8e00;
-    case SLW_IMAGE_BASE:
-        return 0x1000000000000000;
     }
     return 0;
 }
Signature · 1 line
2.45.2
#4 lore raw

PATCH 4/9 ppc/pnv/homer: class-based base and size

In reply to Nicholas Piggin

Put HOMER memory region base and size into the class, to allow more code-reuse between different machines in later changes.

---
 include/hw/ppc/pnv.h       |  6 ++---
 include/hw/ppc/pnv_homer.h |  7 +++++-
 hw/ppc/pnv_homer.c         | 46 +++++++++++++++++++++++++++-----------
 3 files changed, 41 insertions(+), 18 deletions(-)
include/hw/ppc/pnv.h +2 -4
index fcb6699150c..d8fca079f2f 100644
@@ -205,9 +205,8 @@ void pnv_bmc_set_pnor(IPMIBmc *bmc, PnvPnor *pnor);
 #define PNV9_OCC_SENSOR_BASE(chip)   (PNV9_OCC_COMMON_AREA_BASE +       \
     PNV_OCC_SENSOR_DATA_BLOCK_BASE((chip)->chip_id))
 
-#define PNV9_HOMER_SIZE              0x0000000000400000ull
 #define PNV9_HOMER_BASE(chip)                                           \
-    (0x203ffd800000ull + ((uint64_t)(chip)->chip_id) * PNV9_HOMER_SIZE)
+    (0x203ffd800000ull + ((uint64_t)(chip)->chip_id) * PNV_HOMER_SIZE)
 
 /*
  * POWER10 MMIO base addresses - 16TB stride per chip
@@ -250,8 +249,7 @@ void pnv_bmc_set_pnor(IPMIBmc *bmc, PnvPnor *pnor);
 #define PNV10_OCC_SENSOR_BASE(chip) (PNV10_OCC_COMMON_AREA_BASE +       \
     PNV_OCC_SENSOR_DATA_BLOCK_BASE((chip)->chip_id))
 
-#define PNV10_HOMER_SIZE              0x0000000000400000ull
 #define PNV10_HOMER_BASE(chip)                                           \
-    (0x300ffd800000ll + ((uint64_t)(chip)->chip_id) * PNV10_HOMER_SIZE)
+    (0x300ffd800000ll + ((uint64_t)(chip)->chip_id) * PNV_HOMER_SIZE)
 
 #endif /* PPC_PNV_H */
include/hw/ppc/pnv_homer.h +6 -1
index b1c5d498dc5..5ffc0c97afe 100644
@@ -42,15 +42,20 @@ struct PnvHomer {
     PnvChip *chip;
     MemoryRegion pba_regs;
     MemoryRegion regs;
+    hwaddr base;
 };
 
 
 struct PnvHomerClass {
     DeviceClass parent_class;
 
+    /* Get base address of HOMER memory */
+    hwaddr (*get_base)(PnvChip *chip);
+    /* Size of HOMER memory */
+    int size;
+
     int pba_size;
     const MemoryRegionOps *pba_ops;
-    int homer_size;
     const MemoryRegionOps *homer_ops;
 
     hwaddr core_max_base;
hw/ppc/pnv_homer.c +33 -13

129 lines not on this page · raw message

Signature · 1 line
2.45.2
#5 lore raw

PATCH 5/9 ppc/pnv/occ: Better document OCCMISC bits

In reply to Nicholas Piggin

Use defines for the OCCMISC register bits, and add a comment about the IRQ request bit, which QEMU may not model quite correctly.

---
 hw/ppc/pnv_occ.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)
hw/ppc/pnv_occ.c +9 -5
index c6681a035a7..5424d87ee97 100644
@@ -30,6 +30,7 @@
 #define OCB_OCI_OCCMISC         0x4020
 #define OCB_OCI_OCCMISC_AND     0x4021
 #define OCB_OCI_OCCMISC_OR      0x4022
+#define   OCCMISC_PSI_IRQ       PPC_BIT(0)
 
 /* OCC sensors */
 #define OCC_SENSOR_DATA_BLOCK_OFFSET          0x0000
@@ -50,13 +51,16 @@
 
 static void pnv_occ_set_misc(PnvOCC *occ, uint64_t val)
 {
-    bool irq_state;
-
-    val &= 0xffff000000000000ull;
+    val &= PPC_BITMASK(0, 18); /* Mask out unimplemented bits */
 
     occ->occmisc = val;
-    irq_state = !!(val >> 63);
-    qemu_set_irq(occ->psi_irq, irq_state);
+
+    /*
+     * OCCMISC IRQ bit triggers the interrupt on a 0->1 edge, but not clear
+     * how that is handled in PSI so it is level-triggered here, which is not
+     * really correct (but skiboot is okay with it).
+     */
+    qemu_set_irq(occ->psi_irq, !!(val & OCCMISC_PSI_IRQ));
 }
 
 static uint64_t pnv_occ_power8_xscom_read(void *opaque, hwaddr addr,
Signature · 1 line
2.45.2
#6 lore raw

PATCH 6/9 ppc/pnv: Make HOMER memory a RAM region

In reply to Nicholas Piggin

The HOMER is a region of memory used by host and firmware and microconrollers. It has very little logic by itself, just some BAR registers. Users of this memory should operate on it rather than have HOMER implement them with MMIO registers, which is not the right model.

This change switches the implementation of HOMER from MMIO to RAM, and moves the OCC register implementation to in-memory structure accesses performed by the OCC model.

This has the downside that access to unimplemented regions of HOMER are no longer flagged. Perhaps that could be done by adding a memory region for HOMER, and ram subregions under that for each implemented part. But for now this takes the simpler approach.

Note: This brings some data structure definitions from skiboot, which does not match QEMU coding style but is not changed to make comparisons and updates simpler.

---
 include/hw/ppc/pnv_homer.h |   5 +-
 include/hw/ppc/pnv_occ.h   |   6 +
 hw/ppc/pnv.c               |  87 ++++----
 hw/ppc/pnv_homer.c         | 203 +----------------
 hw/ppc/pnv_occ.c           | 433 ++++++++++++++++++++++++++++++++++++-
 5 files changed, 488 insertions(+), 246 deletions(-)
include/hw/ppc/pnv_homer.h +1 -4
index 5ffc0c97afe..a6f2710fa16 100644
@@ -41,7 +41,7 @@ struct PnvHomer {
 
     PnvChip *chip;
     MemoryRegion pba_regs;
-    MemoryRegion regs;
+    MemoryRegion mem;
     hwaddr base;
 };
 
@@ -56,9 +56,6 @@ struct PnvHomerClass {
 
     int pba_size;
     const MemoryRegionOps *pba_ops;
-    const MemoryRegionOps *homer_ops;
-
-    hwaddr core_max_base;
 };
 
 #endif /* PPC_PNV_HOMER_H */
include/hw/ppc/pnv_occ.h +6 -0
index df321244e3b..f9948609808 100644
@@ -46,6 +46,9 @@ struct PnvOCC {
 
     qemu_irq psi_irq;
 
+    /* OCCs operate on regions of HOMER memory */
+    PnvHomer *homer;
+
     MemoryRegion xscom_regs;
     MemoryRegion sram_regs;
 };
@@ -53,6 +56,9 @@ struct PnvOCC {
 struct PnvOCCClass {
     DeviceClass parent_class;
 
+    hwaddr opal_shared_memory_offset; /* offset in HOMER */
+    uint8_t opal_shared_memory_version;
+
     int xscom_size;
     const MemoryRegionOps *xscom_ops;
 };
hw/ppc/pnv.c +41 -46

132 lines not on this page · raw message

hw/ppc/pnv_homer.c +8 -195

247 lines not on this page · raw message

hw/ppc/pnv_occ.c +432 -1

481 lines not on this page · raw message

Signature · 1 line
2.45.2
#7 lore raw

PATCH 7/9 ppc/pnv/occ: Update pstate frequency tables

In reply to Nicholas Piggin

Make each pstate have a different frequency, because that's easier to observe and test.

---
 hw/ppc/pnv_occ.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
hw/ppc/pnv_occ.c +4 -4
index 918b08ba2ff..5567fbf008e 100644
@@ -681,11 +681,11 @@ static bool occ_init_homer_memory(PnvOCC *occ, Error **errp)
         static_data.v2.pstate_turbo = -1;
         static_data.v2.pstate_ultra_turbo = 0;
         static_data.v2.pstates[0].id = 0;
-        static_data.v2.pstates[1].freq_khz = cpu_to_be32(3000);
+        static_data.v2.pstates[1].freq_khz = cpu_to_be32(4000);
         static_data.v2.pstates[1].id = -1;
         static_data.v2.pstates[1].freq_khz = cpu_to_be32(3000);
         static_data.v2.pstates[2].id = -2;
-        static_data.v2.pstates[2].freq_khz = cpu_to_be32(3000);
+        static_data.v2.pstates[2].freq_khz = cpu_to_be32(2000);
         for (i = 0; i < chip->nr_cores; i++) {
             static_data.v2.core_max[i] = 1;
         }
@@ -701,11 +701,11 @@ static bool occ_init_homer_memory(PnvOCC *occ, Error **errp)
         static_data.v9.pstate_turbo = 1;
         static_data.v9.pstate_ultra_turbo = 0;
         static_data.v9.pstates[0].id = 0;
-        static_data.v9.pstates[0].freq_khz = cpu_to_be32(3000);
+        static_data.v9.pstates[0].freq_khz = cpu_to_be32(4000);
         static_data.v9.pstates[1].id = 1;
         static_data.v9.pstates[1].freq_khz = cpu_to_be32(3000);
         static_data.v9.pstates[2].id = 2;
-        static_data.v9.pstates[2].freq_khz = cpu_to_be32(3000);
+        static_data.v9.pstates[2].freq_khz = cpu_to_be32(2000);
         for (i = 0; i < chip->nr_cores; i++) {
             static_data.v9.core_max[i] = 1;
         }
Signature · 1 line
2.45.2
#8 lore raw

PATCH 8/9 ppc/pnv/occ: Add POWER10 OCC-OPAL data format

In reply to Nicholas Piggin

Add POWER10 OCC-OPAL data format. POWER10 changes major version and adds a few fields.

---
 hw/ppc/pnv_occ.c | 43 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 42 insertions(+), 1 deletion(-)
hw/ppc/pnv_occ.c +42 -1
index 5567fbf008e..aa46e118e93 100644
@@ -263,14 +263,20 @@ static const TypeInfo pnv_occ_power9_type_info = {
 
 static void pnv_occ_power10_class_init(ObjectClass *klass, void *data)
 {
+    PnvOCCClass *poc = PNV_OCC_CLASS(klass);
     DeviceClass *dc = DEVICE_CLASS(klass);
 
     dc->desc = "PowerNV OCC Controller (POWER10)";
+    poc->opal_shared_memory_offset = P9_HOMER_OPAL_DATA_OFFSET;
+    poc->opal_shared_memory_version = 0xA0;
+    poc->xscom_size = PNV9_XSCOM_OCC_SIZE;
+    poc->xscom_ops = &pnv_occ_power9_xscom_ops;
+    assert(!dc->user_creatable);
 }
 
 static const TypeInfo pnv_occ_power10_type_info = {
     .name          = TYPE_PNV10_OCC,
-    .parent        = TYPE_PNV9_OCC,
+    .parent        = TYPE_PNV_OCC,
     .class_init    = pnv_occ_power10_class_init,
 };
 
@@ -710,6 +716,37 @@ static bool occ_init_homer_memory(PnvOCC *occ, Error **errp)
             static_data.v9.core_max[i] = 1;
         }
         break;
+    case 0xA0:
+        if (chip->chip_id == 0) {
+            static_data.v10.occ_role = OCC_ROLE_MASTER;
+        } else {
+            static_data.v10.occ_role = OCC_ROLE_SLAVE;
+        }
+        static_data.v10.pstate_min = 4;
+        static_data.v10.pstate_fixed_freq = 3;
+        static_data.v10.pstate_base = 2;
+        static_data.v10.pstate_ultra_turbo = 1;
+        static_data.v10.pstate_fmax = 0;
+        static_data.v10.minor = 0x01;
+        static_data.v10.pstates[0].valid = 1;
+        static_data.v10.pstates[0].id = 0;
+        static_data.v10.pstates[0].freq_khz = cpu_to_be32(4200);
+        static_data.v10.pstates[1].valid = 1;
+        static_data.v10.pstates[1].id = 1;
+        static_data.v10.pstates[1].freq_khz = cpu_to_be32(4000);
+        static_data.v10.pstates[2].valid = 1;
+        static_data.v10.pstates[2].id = 2;
+        static_data.v10.pstates[2].freq_khz = cpu_to_be32(3800);
+        static_data.v10.pstates[3].valid = 1;
+        static_data.v10.pstates[3].id = 3;
+        static_data.v10.pstates[3].freq_khz = cpu_to_be32(3000);
+        static_data.v10.pstates[4].valid = 1;
+        static_data.v10.pstates[4].id = 4;
+        static_data.v10.pstates[4].freq_khz = cpu_to_be32(2000);
+        for (i = 0; i < chip->nr_cores; i++) {
+            static_data.v10.core_max[i] = 1;
+        }
+        break;
     default:
         g_assert_not_reached();
     }
@@ -725,6 +762,10 @@ static bool occ_init_homer_memory(PnvOCC *occ, Error **errp)
     dynamic_data.cur_pwr_cap = cpu_to_be16(PCAP_MAX_POWER_W);
     dynamic_data.soft_min_pwr_cap = cpu_to_be16(PCAP_SOFT_MIN_POWER_W);
     switch (poc->opal_shared_memory_version) {
+    case 0xA0:
+        dynamic_data.minor_version = 0x1;
+        dynamic_data.v10.wof_enabled = 0x1;
+        break;
     case 0x90:
         dynamic_data.minor_version = 0x1;
         break;
Signature · 1 line
2.45.2
#9 lore raw

PATCH 9/9 ppc/pnv/occ: Implement a basic dynamic OCC model

In reply to Nicholas Piggin

The OCC is an On Chip Controller that handles various thermal and power management. It is a PPC405 microcontroller that runs its own firmware which is out of scope of the powernv machine model. Some dynamic behaviour and interfaces that are important for host CPU testing can be implemented with a much simpler state machine.

This change adds a 100ms timer that ticks through a simple state machine that looks for "OCC command requests" coming from host firmware, and responds to them.

For now the powercap command is implemented because that is used by OPAL and exported to Linux and is easy to test.

  $ F=/sys/firmware/opal/powercap/system-powercap/powercap-current
  $ cat $F
  100
  $ echo 50 | sudo tee $F
  50
  $ cat $F
  50
---
 include/hw/ppc/pnv_occ.h |   3 +
 hw/ppc/pnv_occ.c         | 145 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 148 insertions(+)
include/hw/ppc/pnv_occ.h +3 -0
index f9948609808..3ec42de0ff1 100644
@@ -41,6 +41,9 @@ DECLARE_INSTANCE_CHECKER(PnvOCC, PNV10_OCC, TYPE_PNV10_OCC)
 struct PnvOCC {
     DeviceState xd;
 
+    /* OCC dynamic model is driven by this timer. */
+    QEMUTimer state_machine_timer;
+
     /* OCC Misc interrupt */
     uint64_t occmisc;
 
hw/ppc/pnv_occ.c +145 -0

181 lines not on this page · raw message

Signature · 1 line
2.45.2
#10 lore raw
In reply to Nicholas Piggin

Hello,

Quoted 2 lines · Nicholas Piggin

This series makes a bunch of fixes and improvements to the HOMER and OCC unit models for powernv. It gets OPAL OCC code happier again,

Nice. I had similar changes exposing pstates and sensors for QEMU. I am glad this is now possible.

Quoted 11 lines

but requires this series of skiboot fixes (which I will hope to get upstream and then into QEMU in the same release as this series is merged.

https://lists.ozlabs.org/pipermail/skiboot/2024-November/019013.html

Big changes is moving HOMER from mmio register implementation to a RAM memory region which better maches hardware and is much easier to work with; and the addition of some dynamic OCC behaviour to the device model.

Quoted 5 lines

I wouldn't expect any review of OCC details. It's neglected and this series gets it in better shape than before. But anything on the basic structure and QEMU details is welcome. I will add some test cases to help ensure it doesn't regress in future, I will have to juggle the skiboot fixes as well though, so will do that later.

Have you considered modeling the OCC in QEMU ? I am asking because I have a series removing all 405 support in QEMU 10.0.

Thanks,

C.

Quoted 23 lines

Thanks,
Nick

Nicholas Piggin (9):
ppc/pnv/homer: Fix OCC registers ppc/pnv/homer: Make dummy reads return 0 ppc/pnv/occ: Fix common area sensor offsets ppc/pnv/homer: class-based base and size ppc/pnv/occ: Better document OCCMISC bits ppc/pnv: Make HOMER memory a RAM region ppc/pnv/occ: Update pstate frequency tables ppc/pnv/occ: Add POWER10 OCC-OPAL data format ppc/pnv/occ: Implement a basic dynamic OCC model

  include/hw/ppc/pnv.h       |   6 +-
  include/hw/ppc/pnv_homer.h |  12 +-
  include/hw/ppc/pnv_occ.h   |   9 +
  hw/ppc/pnv.c               |  87 +++--
  hw/ppc/pnv_homer.c         | 230 +++----------
  hw/ppc/pnv_occ.c           | 668 +++++++++++++++++++++++++++++++++++--
  6 files changed, 742 insertions(+), 270 deletions(-)
#11 lore raw
Quoted 20 lines · Cédric Le Goater

Hello,

Quoted 2 lines · Nicholas Piggin

This series makes a bunch of fixes and improvements to the HOMER and OCC unit models for powernv. It gets OPAL OCC code happier again,

Nice. I had similar changes exposing pstates and sensors for QEMU. I am glad this is now possible.

Quoted 11 lines

but requires this series of skiboot fixes (which I will hope to get upstream and then into QEMU in the same release as this series is merged.

https://lists.ozlabs.org/pipermail/skiboot/2024-November/019013.html

Big changes is moving HOMER from mmio register implementation to a RAM memory region which better maches hardware and is much easier to work with; and the addition of some dynamic OCC behaviour to the device model.

Quoted 8 lines
Quoted 5 lines

I wouldn't expect any review of OCC details. It's neglected and this series gets it in better shape than before. But anything on the basic structure and QEMU details is welcome. I will add some test cases to help ensure it doesn't regress in future, I will have to juggle the skiboot fixes as well though, so will do that later.

Have you considered modeling the OCC in QEMU ? I am asking because I have a series removing all 405 support in QEMU 10.0.

Yes we are looking at modelling some of the microcontrollers by emulating them not just simple state machines. I think starting with SBE, but OCC is on the wishlist.

Perhaps hold off the removal for now?

Thanks,
Nick