Skip to contentSkip to conversation

hw/arm/mpam: Implement PRI priority partitioning

PATCH In review Jinjie Ruan 5 participants 46 messages Oct 16 – Nov 25 1 message not in the archive Arm/Amlogic Meson SoC support

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw

PATCH 1/37 target/arm: Add support for MPAM CPU registers

From: Jonathan Cameron <[email protected]>

Add the MPAM system registers for TCG: MPAMIDR_EL1 (RO) reporting 64 PARTIDs and 4 PMGs, and MPAM0_EL1/MPAM1_EL1 (RW, of which only MPAM1_EL1.MPAMEN is architecturally reset). Advertise FEAT_MPAM via ID_AA64PFR0.MPAM for TCG CPUs.

It is common to support MPAM on CPU cores, but not in the rest of the system, so there is little disadvantage in always enabling these.

Based on an RFC series by Jonathan Cameron, adapted to the current idregs[] storage and access_tid3() naming.

---
 target/arm/cpu-features.h | 11 +++++++++++
 target/arm/cpu.c          | 10 +++++++++-
 target/arm/cpu.h          |  3 +++
 target/arm/helper.c       | 17 +++++++++++++++++
 4 files changed, 40 insertions(+), 1 deletion(-)
target/arm/cpu-features.h +11 -0
index a9eebb4..4b7d47b 100644
@@ -459,6 +459,17 @@ FIELD(DBGDEVID, DOUBLELOCK, 20, 4)
 FIELD(DBGDEVID, AUXREGS, 24, 4)
 FIELD(DBGDEVID, CIDMASK, 28, 4)
 
+FIELD(MPAMIDR, PARTID_MAX, 0, 16)
+FIELD(MPAMIDR, HAS_HCR, 17, 1)
+FIELD(MPAMIDR, VMR_MAX, 18, 3)
+FIELD(MPAMIDR, PMG_MAX, 32, 8)
+FIELD(MPAMIDR, HAS_ALTSP, 57, 1)
+FIELD(MPAMIDR, HAS_TIDR, 58, 1)
+FIELD(MPAMIDR, SP4, 59, 1)
+FIELD(MPAMIDR, HAS_FORCE_NS, 60, 1)
+FIELD(MPAMIDR, HAS_SDEFLT, 61, 1)
+FIELD(MPAM1_EL1, MPAMEN, 63, 1)
+
 FIELD(DBGDEVID1, PCSROFFSET, 0, 4)
 
 FIELD(MVFR0, SIMDREG, 0, 4)
target/arm/cpu.c +9 -1
index 10ac6c9..e7529d5 100644
@@ -439,6 +439,8 @@ static void arm_cpu_reset_hold(Object *obj, ResetType type)
         /* Sample rvbar at reset.  */
         env->cp15.rvbar = cpu->rvbar_prop;
         env->pc = env->cp15.rvbar;
+
+        env->mpam1_el1 = R_MPAM1_EL1_MPAMEN_MASK;
 #endif
     } else {
 #if defined(CONFIG_USER_ONLY)
@@ -452,6 +454,8 @@ static void arm_cpu_reset_hold(Object *obj, ResetType type)
             env->cp15.rvbar = cpu->rvbar_prop;
             env->regs[15] = cpu->rvbar_prop;
         }
+
+        env->mpam1_el1 = R_MPAM1_EL1_MPAMEN_MASK;
     }
 
 #if defined(CONFIG_USER_ONLY)
@@ -2333,7 +2337,11 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
         FIELD_DP64_IDREG(isar, ID_AA64PFR0, AMU, 0);
         FIELD_DP32_IDREG(isar, ID_PFR0, AMU, 0);
         /* FEAT_MPAM (Memory Partitioning and Monitoring Extension) */
-        FIELD_DP64_IDREG(isar, ID_AA64PFR0, MPAM, 0);
+        FIELD_DP64_IDREG(isar, ID_AA64PFR0, MPAM, 1);
+        cpu->isar.mpamidr_el1 =
+            FIELD_DP64(cpu->isar.mpamidr_el1, MPAMIDR, PARTID_MAX, 63);
+        cpu->isar.mpamidr_el1 =
+            FIELD_DP64(cpu->isar.mpamidr_el1, MPAMIDR, PMG_MAX, 3);
     }
 
     /* MPU can be configured out of a PMSA CPU either by setting has-mpu
target/arm/cpu.h +3 -0
index 06ebed4..51a36fa 100644
@@ -757,6 +757,8 @@ typedef struct CPUArchState {
     struct CPUBreakpoint *cpu_breakpoint[16];
     struct CPUWatchpoint *cpu_watchpoint[16];
 
+    uint64_t mpam0_el1;
+    uint64_t mpam1_el1;
     /* Optional fault info across tlb lookup. */
     ARMMMUFaultInfo *tlb_fi;
 
@@ -1121,6 +1123,7 @@ struct ArchCPU {
         uint32_t dbgdevid;
         uint32_t dbgdevid1;
         uint64_t reset_pmcr_el0;
+        uint64_t mpamidr_el1;
         uint64_t idregs[NUM_ID_IDX];
     } isar;
     uint64_t midr;
target/arm/helper.c +17 -0
index ff0b766..896ac0e 100644
@@ -6907,6 +6907,23 @@ void register_cp_regs_for_features(ARMCPU *cpu)
               .access = PL1_R, .type = ARM_CP_CONST,
               .accessfn = access_tid3,
               .resetvalue = cpu->isar.mvfr0 },
+            { .name = "MPAMIDR_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 4, .opc2 = 4,
+              .access = PL1_R, .type = ARM_CP_CONST,
+              .accessfn = access_tid3,
+              .resetvalue = cpu->isar.mpamidr_el1 },
+            { .name = "MPAM0_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 1,
+              .access = PL1_RW, .type = ARM_CP_ALIAS,
+              .accessfn = access_tid3,
+              .fieldoffset = offsetof(CPUARMState, mpam0_el1),
+            },
+            { .name = "MPAM1_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 0,
+              .access = PL1_RW, .type = ARM_CP_ALIAS,
+              .accessfn = access_tid3,
+              .fieldoffset = offsetof(CPUARMState, mpam1_el1),
+            },
             { .name = "MVFR1_EL1", .state = ARM_CP_STATE_AA64,
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 3, .opc2 = 1,
               .access = PL1_R, .type = ARM_CP_CONST,
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 01/37] target/arm: Add support for MPAM CPU registers

Quoted 7 lines · Jinjie Ruan

From: Jonathan Cameron <[email protected]>

Add the MPAM system registers for TCG: MPAMIDR_EL1 (RO) reporting 64 PARTIDs and 4 PMGs, and MPAM0_EL1/MPAM1_EL1 (RW, of which only MPAM1_EL1.MPAMEN is architecturally reset). Advertise FEAT_MPAM via ID_AA64PFR0.MPAM for TCG CPUs.

Quoted 8 lines

It is common to support MPAM on CPU cores, but not in the rest of the system, so there is little disadvantage in always enabling these.

Based on an RFC series by Jonathan Cameron, adapted to the current idregs[] storage and access_tid3() naming.

Something is wrong with this thread, when I was reading the cover letter I couldn't find the rest of the thread. How did you post this series? It looks like the cover letter, first 16 and remaining patches where sent in separate batches?

Quoted 113 lines
---
 target/arm/cpu-features.h | 11 +++++++++++
 target/arm/cpu.c          | 10 +++++++++-
 target/arm/cpu.h          |  3 +++
 target/arm/helper.c       | 17 +++++++++++++++++
 4 files changed, 40 insertions(+), 1 deletion(-)
target/arm/cpu-features.h +11 -0
index a9eebb4..4b7d47b 100644
@@ -459,6 +459,17 @@ FIELD(DBGDEVID, DOUBLELOCK, 20, 4)
 FIELD(DBGDEVID, AUXREGS, 24, 4)
 FIELD(DBGDEVID, CIDMASK, 28, 4)
 
+FIELD(MPAMIDR, PARTID_MAX, 0, 16)
+FIELD(MPAMIDR, HAS_HCR, 17, 1)
+FIELD(MPAMIDR, VMR_MAX, 18, 3)
+FIELD(MPAMIDR, PMG_MAX, 32, 8)
+FIELD(MPAMIDR, HAS_ALTSP, 57, 1)
+FIELD(MPAMIDR, HAS_TIDR, 58, 1)
+FIELD(MPAMIDR, SP4, 59, 1)
+FIELD(MPAMIDR, HAS_FORCE_NS, 60, 1)
+FIELD(MPAMIDR, HAS_SDEFLT, 61, 1)
+FIELD(MPAM1_EL1, MPAMEN, 63, 1)
+
 FIELD(DBGDEVID1, PCSROFFSET, 0, 4)
 
 FIELD(MVFR0, SIMDREG, 0, 4)
target/arm/cpu.c +9 -1
index 10ac6c9..e7529d5 100644
@@ -439,6 +439,8 @@ static void arm_cpu_reset_hold(Object *obj, ResetType type)
         /* Sample rvbar at reset.  */
         env->cp15.rvbar = cpu->rvbar_prop;
         env->pc = env->cp15.rvbar;
+
+        env->mpam1_el1 = R_MPAM1_EL1_MPAMEN_MASK;
 #endif
     } else {
 #if defined(CONFIG_USER_ONLY)
@@ -452,6 +454,8 @@ static void arm_cpu_reset_hold(Object *obj, ResetType type)
             env->cp15.rvbar = cpu->rvbar_prop;
             env->regs[15] = cpu->rvbar_prop;
         }
+
+        env->mpam1_el1 = R_MPAM1_EL1_MPAMEN_MASK;
     }
 
 #if defined(CONFIG_USER_ONLY)
@@ -2333,7 +2337,11 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
         FIELD_DP64_IDREG(isar, ID_AA64PFR0, AMU, 0);
         FIELD_DP32_IDREG(isar, ID_PFR0, AMU, 0);
         /* FEAT_MPAM (Memory Partitioning and Monitoring Extension) */
-        FIELD_DP64_IDREG(isar, ID_AA64PFR0, MPAM, 0);
+        FIELD_DP64_IDREG(isar, ID_AA64PFR0, MPAM, 1);
+        cpu->isar.mpamidr_el1 =
+            FIELD_DP64(cpu->isar.mpamidr_el1, MPAMIDR, PARTID_MAX, 63);
+        cpu->isar.mpamidr_el1 =
+            FIELD_DP64(cpu->isar.mpamidr_el1, MPAMIDR, PMG_MAX, 3);
     }
 
     /* MPU can be configured out of a PMSA CPU either by setting has-mpu
target/arm/cpu.h +3 -0
index 06ebed4..51a36fa 100644
@@ -757,6 +757,8 @@ typedef struct CPUArchState {
     struct CPUBreakpoint *cpu_breakpoint[16];
     struct CPUWatchpoint *cpu_watchpoint[16];
 
+    uint64_t mpam0_el1;
+    uint64_t mpam1_el1;
     /* Optional fault info across tlb lookup. */
     ARMMMUFaultInfo *tlb_fi;
 
@@ -1121,6 +1123,7 @@ struct ArchCPU {
         uint32_t dbgdevid;
         uint32_t dbgdevid1;
         uint64_t reset_pmcr_el0;
+        uint64_t mpamidr_el1;
         uint64_t idregs[NUM_ID_IDX];
     } isar;
     uint64_t midr;
target/arm/helper.c +17 -0
index ff0b766..896ac0e 100644
@@ -6907,6 +6907,23 @@ void register_cp_regs_for_features(ARMCPU *cpu)
               .access = PL1_R, .type = ARM_CP_CONST,
               .accessfn = access_tid3,
               .resetvalue = cpu->isar.mvfr0 },
+            { .name = "MPAMIDR_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 4, .opc2 = 4,
+              .access = PL1_R, .type = ARM_CP_CONST,
+              .accessfn = access_tid3,
+              .resetvalue = cpu->isar.mpamidr_el1 },
+            { .name = "MPAM0_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 1,
+              .access = PL1_RW, .type = ARM_CP_ALIAS,
+              .accessfn = access_tid3,
+              .fieldoffset = offsetof(CPUARMState, mpam0_el1),
+            },
+            { .name = "MPAM1_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 0,
+              .access = PL1_RW, .type = ARM_CP_ALIAS,
+              .accessfn = access_tid3,
+              .fieldoffset = offsetof(CPUARMState, mpam1_el1),
+            },
             { .name = "MVFR1_EL1", .state = ARM_CP_STATE_AA64,
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 3, .opc2 = 1,
               .access = PL1_R, .type = ARM_CP_CONST,
Signature · 2 lines
Alex Bennée
Virtualisation Tech Lead @ Linaro
#3 lore raw

Re: [PATCH 01/37] target/arm: Add support for MPAM CPU registers

Quoted 15 lines · Alex Bennée
Quoted 13 lines · Jinjie Ruan

From: Jonathan Cameron <[email protected]>

Add the MPAM system registers for TCG: MPAMIDR_EL1 (RO) reporting 64 PARTIDs and 4 PMGs, and MPAM0_EL1/MPAM1_EL1 (RW, of which only MPAM1_EL1.MPAMEN is architecturally reset). Advertise FEAT_MPAM via ID_AA64PFR0.MPAM for TCG CPUs.

It is common to support MPAM on CPU cores, but not in the rest of the system, so there is little disadvantage in always enabling these.

Based on an RFC series by Jonathan Cameron, adapted to the current idregs[] storage and access_tid3() naming.

Quoted 7 lines
Quoted 2 lines

Something is wrong with this thread, when I was reading the cover letter I couldn't find the rest of the thread. How did you post this series? It looks like the cover letter, first 16 and remaining patches where sent in separate batches?

Hi Alex,

Sorry, due to SMTP rate limiting, this series has been split into multiple threads. The complete 37 patches are as follows:

- cover letter:
https://lore.kernel.org/all/[email protected]/

- patch 1 ~ 16:
https://lore.kernel.org/all/[email protected]/

- patch 17 ~ 37:
https://lore.kernel.org/all/[email protected]/#t

Quoted 115 lines
Quoted 114 lines
---
 target/arm/cpu-features.h | 11 +++++++++++
 target/arm/cpu.c          | 10 +++++++++-
 target/arm/cpu.h          |  3 +++
 target/arm/helper.c       | 17 +++++++++++++++++
 4 files changed, 40 insertions(+), 1 deletion(-)
target/arm/cpu-features.h +11 -0
index a9eebb4..4b7d47b 100644
@@ -459,6 +459,17 @@ FIELD(DBGDEVID, DOUBLELOCK, 20, 4)
 FIELD(DBGDEVID, AUXREGS, 24, 4)
 FIELD(DBGDEVID, CIDMASK, 28, 4)
 
+FIELD(MPAMIDR, PARTID_MAX, 0, 16)
+FIELD(MPAMIDR, HAS_HCR, 17, 1)
+FIELD(MPAMIDR, VMR_MAX, 18, 3)
+FIELD(MPAMIDR, PMG_MAX, 32, 8)
+FIELD(MPAMIDR, HAS_ALTSP, 57, 1)
+FIELD(MPAMIDR, HAS_TIDR, 58, 1)
+FIELD(MPAMIDR, SP4, 59, 1)
+FIELD(MPAMIDR, HAS_FORCE_NS, 60, 1)
+FIELD(MPAMIDR, HAS_SDEFLT, 61, 1)
+FIELD(MPAM1_EL1, MPAMEN, 63, 1)
+
 FIELD(DBGDEVID1, PCSROFFSET, 0, 4)
 
 FIELD(MVFR0, SIMDREG, 0, 4)
target/arm/cpu.c +9 -1
index 10ac6c9..e7529d5 100644
@@ -439,6 +439,8 @@ static void arm_cpu_reset_hold(Object *obj, ResetType type)
         /* Sample rvbar at reset.  */
         env->cp15.rvbar = cpu->rvbar_prop;
         env->pc = env->cp15.rvbar;
+
+        env->mpam1_el1 = R_MPAM1_EL1_MPAMEN_MASK;
 #endif
     } else {
 #if defined(CONFIG_USER_ONLY)
@@ -452,6 +454,8 @@ static void arm_cpu_reset_hold(Object *obj, ResetType type)
             env->cp15.rvbar = cpu->rvbar_prop;
             env->regs[15] = cpu->rvbar_prop;
         }
+
+        env->mpam1_el1 = R_MPAM1_EL1_MPAMEN_MASK;
     }
 
 #if defined(CONFIG_USER_ONLY)
@@ -2333,7 +2337,11 @@ static void arm_cpu_realizefn(DeviceState *dev, Error **errp)
         FIELD_DP64_IDREG(isar, ID_AA64PFR0, AMU, 0);
         FIELD_DP32_IDREG(isar, ID_PFR0, AMU, 0);
         /* FEAT_MPAM (Memory Partitioning and Monitoring Extension) */
-        FIELD_DP64_IDREG(isar, ID_AA64PFR0, MPAM, 0);
+        FIELD_DP64_IDREG(isar, ID_AA64PFR0, MPAM, 1);
+        cpu->isar.mpamidr_el1 =
+            FIELD_DP64(cpu->isar.mpamidr_el1, MPAMIDR, PARTID_MAX, 63);
+        cpu->isar.mpamidr_el1 =
+            FIELD_DP64(cpu->isar.mpamidr_el1, MPAMIDR, PMG_MAX, 3);
     }
 
     /* MPU can be configured out of a PMSA CPU either by setting has-mpu
target/arm/cpu.h +3 -0
index 06ebed4..51a36fa 100644
@@ -757,6 +757,8 @@ typedef struct CPUArchState {
     struct CPUBreakpoint *cpu_breakpoint[16];
     struct CPUWatchpoint *cpu_watchpoint[16];
 
+    uint64_t mpam0_el1;
+    uint64_t mpam1_el1;
     /* Optional fault info across tlb lookup. */
     ARMMMUFaultInfo *tlb_fi;
 
@@ -1121,6 +1123,7 @@ struct ArchCPU {
         uint32_t dbgdevid;
         uint32_t dbgdevid1;
         uint64_t reset_pmcr_el0;
+        uint64_t mpamidr_el1;
         uint64_t idregs[NUM_ID_IDX];
     } isar;
     uint64_t midr;
target/arm/helper.c +17 -0
index ff0b766..896ac0e 100644
@@ -6907,6 +6907,23 @@ void register_cp_regs_for_features(ARMCPU *cpu)
               .access = PL1_R, .type = ARM_CP_CONST,
               .accessfn = access_tid3,
               .resetvalue = cpu->isar.mvfr0 },
+            { .name = "MPAMIDR_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 4, .opc2 = 4,
+              .access = PL1_R, .type = ARM_CP_CONST,
+              .accessfn = access_tid3,
+              .resetvalue = cpu->isar.mpamidr_el1 },
+            { .name = "MPAM0_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 1,
+              .access = PL1_RW, .type = ARM_CP_ALIAS,
+              .accessfn = access_tid3,
+              .fieldoffset = offsetof(CPUARMState, mpam0_el1),
+            },
+            { .name = "MPAM1_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 0,
+              .access = PL1_RW, .type = ARM_CP_ALIAS,
+              .accessfn = access_tid3,
+              .fieldoffset = offsetof(CPUARMState, mpam1_el1),
+            },
             { .name = "MVFR1_EL1", .state = ARM_CP_STATE_AA64,
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 3, .opc2 = 1,
               .access = PL1_R, .type = ARM_CP_CONST,
Signature · 2 lines
Best regards,
Jinjie
#4 lore raw

Re: [PATCH 01/37] target/arm: Add support for MPAM CPU registers

Quoted 26 lines · Jinjie Ruan
Quoted 9 lines · Alex Bennée
Quoted 6 lines · Jinjie Ruan

From: Jonathan Cameron <[email protected]>

Add the MPAM system registers for TCG: MPAMIDR_EL1 (RO) reporting 64 PARTIDs and 4 PMGs, and MPAM0_EL1/MPAM1_EL1 (RW, of which only MPAM1_EL1.MPAMEN is architecturally reset). Advertise FEAT_MPAM via ID_AA64PFR0.MPAM for TCG CPUs.

Quoted 4 lines

Something is wrong with this thread, when I was reading the cover letter I couldn't find the rest of the thread. How did you post this series? It looks like the cover letter, first 16 and remaining patches where sent in separate batches?

Hi Alex,

Sorry, due to SMTP rate limiting, this series has been split into multiple threads. The complete 37 patches are as follows:

- cover letter:
https://lore.kernel.org/all/[email protected]/

Quoted 6 lines

- patch 1 ~ 16:
https://lore.kernel.org/all/[email protected]/

- patch 17 ~ 37:
https://lore.kernel.org/all/[email protected]/#t

This is OK for initial first pass human review, but you'll need to fix this for future submissions, because it breaks the automated patch handling tooling. I do fix this up for first-time submitters for small series, but 37 patches is way too many to fix up by hand, so this isn't going to get applied unless it appears as a complete series in one thread on the list.

Note that you don't need to *send* all 38 emails in one big lump, you just need to send them so they all have the right threading headers.

thanks
-- PMM

#5 lore raw

Re: [PATCH 01/37] target/arm: Add support for MPAM CPU registers

In reply to Jinjie Ruan
Quoted 7 lines · On Fri, 16 Oct 2026 17:46:55 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

Add the MPAM system registers for TCG: MPAMIDR_EL1 (RO) reporting 64 PARTIDs and 4 PMGs, and MPAM0_EL1/MPAM1_EL1 (RW, of which only MPAM1_EL1.MPAMEN is architecturally reset). Advertise FEAT_MPAM via ID_AA64PFR0.MPAM for TCG CPUs.

Quoted 7 lines

It is common to support MPAM on CPU cores, but not in the rest of the system, so there is little disadvantage in always enabling these.

Based on an RFC series by Jonathan Cameron, adapted to the current idregs[] storage and access_tid3() naming.

Definitely wouldn't trust this guy :) He took a few naughty short cuts.

Quoted 8 lines
target/arm/helper.c +0 -0
index ff0b766..896ac0e 100644
@@ -6907,6 +6907,23 @@ void register_cp_regs_for_features(ARMCPU *cpu)
               .access = PL1_R, .type = ARM_CP_CONST,

target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu) · line 6917

Quoted 10 lines
target/arm/helper.c +8 -0
               .accessfn = access_tid3,
               .resetvalue = cpu->isar.mvfr0 },
+            { .name = "MPAMIDR_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 4, .opc2 = 4,
+              .access = PL1_R, .type = ARM_CP_CONST,
+              .accessfn = access_tid3,
+              .resetvalue = cpu->isar.mpamidr_el1 },
+            { .name = "MPAM0_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 1,
+              .access = PL1_RW, .type = ARM_CP_ALIAS,

Similar to patch 2 (I reviewed them backwards) not sure why I ever set this to ARM_CP_ALIAS.

target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu) · line 6918

Quoted 1 line
target/arm/helper.c +1 -0
+              .accessfn = access_tid3,

Never trust code I bodged years ago :( Wrong trap. Now you have the appropriate EL2 registers in next patch should use a trap on the relevant bits being set there. Will want to swap the patches around for that to work I think. Also possibly needs the EL3 trap register defined.

Quoted 11 lines
target/arm/helper.c +8 -0
+              .fieldoffset = offsetof(CPUARMState, mpam0_el1),
+            },
+            { .name = "MPAM1_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 0,
+              .access = PL1_RW, .type = ARM_CP_ALIAS,
+              .accessfn = access_tid3,
+              .fieldoffset = offsetof(CPUARMState, mpam1_el1),
+            },
             { .name = "MVFR1_EL1", .state = ARM_CP_STATE_AA64,
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 3, .opc2 = 1,
               .access = PL1_R, .type = ARM_CP_CONST,
#6 lore raw

Re: [PATCH 01/37] target/arm: Add support for MPAM CPU registers

Quoted 4 lines · Jonathan Cameron
Quoted 1 line · On Fri, 16 Oct 2026 17:46:55 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

Hi Jonathan,

Sorry for the late reply. I've been busy with improving the quality and increasing coverage of the Linux MPAM mainline code and developing related features (the QEMU simulation for MPAM has made everything go very smoothly).

Quoted 29 lines
Quoted 6 lines

Add the MPAM system registers for TCG: MPAMIDR_EL1 (RO) reporting 64 PARTIDs and 4 PMGs, and MPAM0_EL1/MPAM1_EL1 (RW, of which only MPAM1_EL1.MPAMEN is architecturally reset). Advertise FEAT_MPAM via ID_AA64PFR0.MPAM for TCG CPUs.

Quoted 7 lines

It is common to support MPAM on CPU cores, but not in the rest of the system, so there is little disadvantage in always enabling these.

Based on an RFC series by Jonathan Cameron, adapted to the current idregs[] storage and access_tid3() naming.

Definitely wouldn't trust this guy :) He took a few naughty short cuts.

Quoted 13 lines
target/arm/helper.c +3 -0
index ff0b766..896ac0e 100644
@@ -6907,6 +6907,23 @@ void register_cp_regs_for_features(ARMCPU *cpu)
               .access = PL1_R, .type = ARM_CP_CONST,
               .accessfn = access_tid3,
               .resetvalue = cpu->isar.mvfr0 },
+            { .name = "MPAMIDR_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 4, .opc2 = 4,
+              .access = PL1_R, .type = ARM_CP_CONST,
Quoted 8 lines

target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu) · line 6917

Quoted 5 lines
target/arm/helper.c +5 -0
+              .accessfn = access_tid3,
+              .resetvalue = cpu->isar.mpamidr_el1 },
+            { .name = "MPAM0_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 1,
+              .access = PL1_RW, .type = ARM_CP_ALIAS,

Similar to patch 2 (I reviewed them backwards) not sure why I ever set this to ARM_CP_ALIAS.

I update them to ARM_CP_STATE_AA64 as other code done.

Quoted 7 lines

target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu) · line 6918

Quoted 2 lines
target/arm/helper.c +1 -0
+              .accessfn = access_tid3,

Never trust code I bodged years ago :( Wrong trap. Now you have the appropriate EL2 registers in next patch should use a trap on the relevant bits being set there. Will want to swap the patches around for that to work I think. Also possibly needs the EL3 trap

Yes, will make the EL2 register patch go first as below:

3. target/arm: Add MPAMSM_EL1 register
2. target/arm: Add support for MPAM CPU registers
1. target/arm: Add MPAM2_EL2 and MPAMHCR_EL2 registers

Quoted 1 line

register defined.

Yes, we could use the EL2 and EL3 register to control the trap as below:

+ { .name = "MPAM0_EL1", .state = ARM_CP_STATE_AA64,

+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 1,
+              .access = PL1_RW,
+              .accessfn = access_mpam0,
+              .fieldoffset = offsetof(CPUARMState, mpam0_el1),
+              .resetvalue = 0 },

+static CPAccessResult access_mpam0(CPUARMState *env,
+ const ARMCPRegInfo *ri, bool isread)
+{
+ if (arm_current_el(env) < 2 && arm_is_el2_enabled(env) &&
+ (env->mpam2_el2 & R_MPAM2_EL2_TRAPMPAM0EL1_MASK)) {
+ return CP_ACCESS_TRAP_EL2;
+ }
+ return CP_ACCESS_OK;
+}

The EL3 is missing and I will try to add it.

Best regards,
Jinjie

Quoted 14 lines
Quoted 13 lines
target/arm/helper.c +8 -0
+              .fieldoffset = offsetof(CPUARMState, mpam0_el1),
+            },
+            { .name = "MPAM1_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 0,
+              .access = PL1_RW, .type = ARM_CP_ALIAS,
+              .accessfn = access_tid3,
+              .fieldoffset = offsetof(CPUARMState, mpam1_el1),
+            },
             { .name = "MVFR1_EL1", .state = ARM_CP_STATE_AA64,
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 3, .opc2 = 1,
               .access = PL1_R, .type = ARM_CP_CONST,
#7 lore raw

Re: [PATCH 01/37] target/arm: Add support for MPAM CPU registers

In reply to Jonathan Cameron
Quoted 42 lines · Jonathan Cameron
Quoted 7 lines · On Fri, 16 Oct 2026 17:46:55 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

Add the MPAM system registers for TCG: MPAMIDR_EL1 (RO) reporting 64 PARTIDs and 4 PMGs, and MPAM0_EL1/MPAM1_EL1 (RW, of which only MPAM1_EL1.MPAMEN is architecturally reset). Advertise FEAT_MPAM via ID_AA64PFR0.MPAM for TCG CPUs.

Quoted 7 lines

It is common to support MPAM on CPU cores, but not in the rest of the system, so there is little disadvantage in always enabling these.

Based on an RFC series by Jonathan Cameron, adapted to the current idregs[] storage and access_tid3() naming.

Definitely wouldn't trust this guy :) He took a few naughty short cuts.

Quoted 8 lines
target/arm/helper.c +0 -0
index ff0b766..896ac0e 100644
@@ -6907,6 +6907,23 @@ void register_cp_regs_for_features(ARMCPU *cpu)
               .access = PL1_R, .type = ARM_CP_CONST,

target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu) · line 6917

Quoted 10 lines
target/arm/helper.c +8 -0
               .accessfn = access_tid3,
               .resetvalue = cpu->isar.mvfr0 },
+            { .name = "MPAMIDR_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 4, .opc2 = 4,
+              .access = PL1_R, .type = ARM_CP_CONST,
+              .accessfn = access_tid3,
+              .resetvalue = cpu->isar.mpamidr_el1 },
+            { .name = "MPAM0_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 1,
+              .access = PL1_RW, .type = ARM_CP_ALIAS,

Similar to patch 2 (I reviewed them backwards) not sure why I ever set this to ARM_CP_ALIAS.

Quoted 7 lines

target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu) · line 6918

Quoted 1 line
target/arm/helper.c +1 -0
+              .accessfn = access_tid3,

Never trust code I bodged years ago :( Wrong trap. Now you have the appropriate EL2 registers in next patch should use a trap on the relevant bits being set there. Will want to swap the patches around for that to work I think. Also possibly needs the EL3 trap register defined.

Maybe we can first implement only EL2 to reduce the workload?

I believe that achieving EL1 and EL2 functions is basically sufficient.

Quoted 14 lines
Quoted 13 lines
target/arm/helper.c +8 -0
+              .fieldoffset = offsetof(CPUARMState, mpam0_el1),
+            },
+            { .name = "MPAM1_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 0,
+              .access = PL1_RW, .type = ARM_CP_ALIAS,
+              .accessfn = access_tid3,
+              .fieldoffset = offsetof(CPUARMState, mpam1_el1),
+            },
             { .name = "MVFR1_EL1", .state = ARM_CP_STATE_AA64,
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 3, .opc2 = 1,
               .access = PL1_R, .type = ARM_CP_CONST,
#8 lore raw

Re: [PATCH 01/37] target/arm: Add support for MPAM CPU registers

Quoted 51 lines · On Tue, 17 Nov 2026 15:33:00 +0800 Jinjie Ruan <[email protected]> wrote:
Quoted 42 lines · Jonathan Cameron
Quoted 7 lines · On Fri, 16 Oct 2026 17:46:55 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

Add the MPAM system registers for TCG: MPAMIDR_EL1 (RO) reporting 64 PARTIDs and 4 PMGs, and MPAM0_EL1/MPAM1_EL1 (RW, of which only MPAM1_EL1.MPAMEN is architecturally reset). Advertise FEAT_MPAM via ID_AA64PFR0.MPAM for TCG CPUs.

Quoted 7 lines

It is common to support MPAM on CPU cores, but not in the rest of the system, so there is little disadvantage in always enabling these.

Based on an RFC series by Jonathan Cameron, adapted to the current idregs[] storage and access_tid3() naming.

Definitely wouldn't trust this guy :) He took a few naughty short cuts.

Quoted 8 lines
target/arm/helper.c +0 -0
index ff0b766..896ac0e 100644
@@ -6907,6 +6907,23 @@ void register_cp_regs_for_features(ARMCPU *cpu)
               .access = PL1_R, .type = ARM_CP_CONST,

target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu) · line 6917

Quoted 10 lines
target/arm/helper.c +8 -0
               .accessfn = access_tid3,
               .resetvalue = cpu->isar.mvfr0 },
+            { .name = "MPAMIDR_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 4, .opc2 = 4,
+              .access = PL1_R, .type = ARM_CP_CONST,
+              .accessfn = access_tid3,
+              .resetvalue = cpu->isar.mpamidr_el1 },
+            { .name = "MPAM0_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 1,
+              .access = PL1_RW, .type = ARM_CP_ALIAS,  

Similar to patch 2 (I reviewed them backwards) not sure why I ever set this to ARM_CP_ALIAS.

Quoted 7 lines

target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu) · line 6918

Quoted 1 line
target/arm/helper.c +1 -0
+              .accessfn = access_tid3,  

Never trust code I bodged years ago :( Wrong trap. Now you have the appropriate EL2 registers in next patch should use a trap on the relevant bits being set there. Will want to swap the patches around for that to work I think. Also possibly needs the EL3 trap register defined.

Quoted 3 lines

Maybe we can first implement only EL2 to reduce the workload?

I believe that achieving EL1 and EL2 functions is basically sufficient.

I don't mind as long as it is correct enough not to trip up anyones code.

Quoted 16 lines
Quoted 15 lines
Quoted 14 lines
target/arm/helper.c +8 -0
+              .fieldoffset = offsetof(CPUARMState, mpam0_el1),
+            },
+            { .name = "MPAM1_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 0,
+              .access = PL1_RW, .type = ARM_CP_ALIAS,
+              .accessfn = access_tid3,
+              .fieldoffset = offsetof(CPUARMState, mpam1_el1),
+            },
             { .name = "MVFR1_EL1", .state = ARM_CP_STATE_AA64,
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 3, .opc2 = 1,
               .access = PL1_R, .type = ARM_CP_CONST,  
#9 lore raw

PATCH 2/37 target/arm: Add MPAM2_EL2 and MPAMHCR_EL2 registers

In reply to a message not in the archive

From: Jinjie Ruan <[email protected]>

FEAT_MPAM's EL2 registers were missing, so a guest kernel that owns or drops out of EL2 takes an UNDEFINED exception the first time it runs its MPAM capability enable callback, which unconditionally clears MPAM2_EL2 (and MPAMHCR_EL2 when HAS_HCR is present).

Register both as normal EL2 read/write registers backed by CPU state.

---
 target/arm/cpu.h    |  2 ++
 target/arm/helper.c | 10 ++++++++++
 2 files changed, 12 insertions(+)
target/arm/cpu.h +2 -0
index 51a36fa..218923a 100644
@@ -759,6 +759,8 @@ typedef struct CPUArchState {
 
     uint64_t mpam0_el1;
     uint64_t mpam1_el1;
+    uint64_t mpam2_el2;
+    uint64_t mpamhcr_el2;
     /* Optional fault info across tlb lookup. */
     ARMMMUFaultInfo *tlb_fi;
 
target/arm/helper.c +10 -0
index 896ac0e..d5d96d5 100644
@@ -6924,6 +6924,16 @@ void register_cp_regs_for_features(ARMCPU *cpu)
               .accessfn = access_tid3,
               .fieldoffset = offsetof(CPUARMState, mpam1_el1),
             },
+            { .name = "MPAM2_EL2", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 4, .crn = 0xa, .crm = 5, .opc2 = 0,
+              .access = PL2_RW, .type = ARM_CP_ALIAS,
+              .fieldoffset = offsetof(CPUARMState, mpam2_el2),
+            },
+            { .name = "MPAMHCR_EL2", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 4, .crn = 0xa, .crm = 4, .opc2 = 0,
+              .access = PL2_RW, .type = ARM_CP_ALIAS,
+              .fieldoffset = offsetof(CPUARMState, mpamhcr_el2),
+            },
             { .name = "MVFR1_EL1", .state = ARM_CP_STATE_AA64,
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 3, .opc2 = 1,
               .access = PL1_R, .type = ARM_CP_CONST,
Signature · 1 line
2.43.0
#10 lore raw

Re: [PATCH 02/37] target/arm: Add MPAM2_EL2 and MPAMHCR_EL2 registers

Quoted 33 lines · On Fri, 16 Oct 2026 17:46:56 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jinjie Ruan <[email protected]>

FEAT_MPAM's EL2 registers were missing, so a guest kernel that owns or drops out of EL2 takes an UNDEFINED exception the first time it runs its MPAM capability enable callback, which unconditionally clears MPAM2_EL2 (and MPAMHCR_EL2 when HAS_HCR is present).

Register both as normal EL2 read/write registers backed by CPU state.

---
 target/arm/cpu.h    |  2 ++
 target/arm/helper.c | 10 ++++++++++
 2 files changed, 12 insertions(+)
target/arm/cpu.h +2 -0
index 51a36fa..218923a 100644
@@ -759,6 +759,8 @@ typedef struct CPUArchState {
 
     uint64_t mpam0_el1;
     uint64_t mpam1_el1;
+    uint64_t mpam2_el2;
+    uint64_t mpamhcr_el2;
     /* Optional fault info across tlb lookup. */
     ARMMMUFaultInfo *tlb_fi;
 
target/arm/helper.c +0 -0
index 896ac0e..d5d96d5 100644

target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu) · line 6929

Quoted 6 lines
target/arm/helper.c +3 -0
@@ -6924,6 +6924,16 @@ void register_cp_regs_for_features(ARMCPU *cpu)
               .accessfn = access_tid3,
               .fieldoffset = offsetof(CPUARMState, mpam1_el1),
             },
+            { .name = "MPAM2_EL2", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 4, .crn = 0xa, .crm = 5, .opc2 = 0,
+              .access = PL2_RW, .type = ARM_CP_ALIAS,

I've most forgotten how this stuff works (if I ever really knew!) Why ARM_CP_ALIAS? Probably just wants that dropped and provide resetvalue = 0.

Also, given emulation isn't yet supporting MPAM v2, there are a load of res0 bits in here so we probably need a write mask. There are more complex things around what MPAM3_EL3 has in it but given I don't think that is emulated yet, can probably just assume here it is in it's most permissive state.

target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu) · line 6936

Quoted 7 lines
target/arm/helper.c +7 -0
+              .fieldoffset = offsetof(CPUARMState, mpam2_el2),
+            },
+            { .name = "MPAMHCR_EL2", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 4, .crn = 0xa, .crm = 4, .opc2 = 0,
+              .access = PL2_RW, .type = ARM_CP_ALIAS,
+              .fieldoffset = offsetof(CPUARMState, mpamhcr_el2),
+            },

Similar for this one.

Quoted 3 lines
target/arm/helper.c +0 -0
             { .name = "MVFR1_EL1", .state = ARM_CP_STATE_AA64,
               .opc0 = 3, .opc1 = 0, .crn = 0, .crm = 3, .opc2 = 1,
               .access = PL1_R, .type = ARM_CP_CONST,
#11 lore raw

PATCH 3/37 target/arm: Add MPAMSM_EL1 register

In reply to a message not in the archive

From: Jinjie Ruan <[email protected]>

FEAT_MPAM_SMS's MPAMSM_EL1 (S3_0_C10_C5_3) was missing, so a v7.x guest with SME enabled took an UNDEFINED instruction in cpu_enable_mpam(), which writes the register unconditionally when ARM64_SME is present. Register it backed by CPU state like the other MPAM registers, letting linux v7.x boot with -cpu max unmodified.

---
 target/arm/cpu.h    | 1 +
 target/arm/helper.c | 6 ++++++
 2 files changed, 7 insertions(+)
target/arm/cpu.h +1 -0
index 218923a..c60ec62 100644
@@ -761,6 +761,7 @@ typedef struct CPUArchState {
     uint64_t mpam1_el1;
     uint64_t mpam2_el2;
     uint64_t mpamhcr_el2;
+    uint64_t mpamsm_el1;
     /* Optional fault info across tlb lookup. */
     ARMMMUFaultInfo *tlb_fi;
 
target/arm/helper.c +6 -0
index d5d96d5..a9b1521 100644
@@ -6912,6 +6912,12 @@ void register_cp_regs_for_features(ARMCPU *cpu)
               .access = PL1_R, .type = ARM_CP_CONST,
               .accessfn = access_tid3,
               .resetvalue = cpu->isar.mpamidr_el1 },
+            { .name = "MPAMSM_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 3,
+              .access = PL1_RW, .type = ARM_CP_ALIAS,
+              .accessfn = access_tid3,
+              .fieldoffset = offsetof(CPUARMState, mpamsm_el1),
+            },
             { .name = "MPAM0_EL1", .state = ARM_CP_STATE_AA64,
               .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 1,
               .access = PL1_RW, .type = ARM_CP_ALIAS,
Signature · 1 line
2.43.0
#12 lore raw

Re: [PATCH 03/37] target/arm: Add MPAMSM_EL1 register

Quoted 31 lines · On Fri, 16 Oct 2026 17:46:57 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jinjie Ruan <[email protected]>

FEAT_MPAM_SMS's MPAMSM_EL1 (S3_0_C10_C5_3) was missing, so a v7.x guest with SME enabled took an UNDEFINED instruction in cpu_enable_mpam(), which writes the register unconditionally when ARM64_SME is present. Register it backed by CPU state like the other MPAM registers, letting linux v7.x boot with -cpu max unmodified.

---
 target/arm/cpu.h    | 1 +
 target/arm/helper.c | 6 ++++++
 2 files changed, 7 insertions(+)
target/arm/cpu.h +1 -0
index 218923a..c60ec62 100644
@@ -761,6 +761,7 @@ typedef struct CPUArchState {
     uint64_t mpam1_el1;
     uint64_t mpam2_el2;
     uint64_t mpamhcr_el2;
+    uint64_t mpamsm_el1;
     /* Optional fault info across tlb lookup. */
     ARMMMUFaultInfo *tlb_fi;
 
target/arm/helper.c +0 -0
index d5d96d5..a9b1521 100644

target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu) · line 6918

Quoted 7 lines
target/arm/helper.c +4 -0
@@ -6912,6 +6912,12 @@ void register_cp_regs_for_features(ARMCPU *cpu)
               .access = PL1_R, .type = ARM_CP_CONST,
               .accessfn = access_tid3,
               .resetvalue = cpu->isar.mpamidr_el1 },
+            { .name = "MPAMSM_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 3,
+              .access = PL1_RW, .type = ARM_CP_ALIAS,
+              .accessfn = access_tid3,

Same as previous. Wrong trap. Also depends on SME being present, otherwise this register needs hiding.

FWIW claude at least is really good at giving at poking holes in these entries. Other LLMs might be too. Bunch of RES0 in this one as well.

Quoted 5 lines
target/arm/helper.c +2 -0
+              .fieldoffset = offsetof(CPUARMState, mpamsm_el1),
+            },
             { .name = "MPAM0_EL1", .state = ARM_CP_STATE_AA64,
               .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 1,
               .access = PL1_RW, .type = ARM_CP_ALIAS,
#13 lore raw

Re: [PATCH 03/37] target/arm: Add MPAMSM_EL1 register

Quoted 29 lines · Jonathan Cameron
Quoted 26 lines · On Fri, 16 Oct 2026 17:46:57 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jinjie Ruan <[email protected]>

FEAT_MPAM_SMS's MPAMSM_EL1 (S3_0_C10_C5_3) was missing, so a v7.x guest with SME enabled took an UNDEFINED instruction in cpu_enable_mpam(), which writes the register unconditionally when ARM64_SME is present. Register it backed by CPU state like the other MPAM registers, letting linux v7.x boot with -cpu max unmodified.

---
 target/arm/cpu.h    | 1 +
 target/arm/helper.c | 6 ++++++
 2 files changed, 7 insertions(+)
target/arm/cpu.h +1 -0
index 218923a..c60ec62 100644
@@ -761,6 +761,7 @@ typedef struct CPUArchState {
     uint64_t mpam1_el1;
     uint64_t mpam2_el2;
     uint64_t mpamhcr_el2;
+    uint64_t mpamsm_el1;
     /* Optional fault info across tlb lookup. */
     ARMMMUFaultInfo *tlb_fi;
 
Quoted 14 lines

target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu) · line 6918

Quoted 12 lines
target/arm/helper.c +4 -0
index d5d96d5..a9b1521 100644
@@ -6912,6 +6912,12 @@ void register_cp_regs_for_features(ARMCPU *cpu)
               .access = PL1_R, .type = ARM_CP_CONST,
               .accessfn = access_tid3,
               .resetvalue = cpu->isar.mpamidr_el1 },
+            { .name = "MPAMSM_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 3,
+              .access = PL1_RW, .type = ARM_CP_ALIAS,
+              .accessfn = access_tid3,

Same as previous. Wrong trap. Also depends on SME being present, otherwise this register needs hiding.

Have fixed them, thank you!

Quoted 11 lines

FWIW claude at least is really good at giving at poking holes in these entries. Other LLMs might be too. Bunch of RES0 in this one as well.

Quoted 5 lines
target/arm/helper.c +2 -0
+              .fieldoffset = offsetof(CPUARMState, mpamsm_el1),
+            },
             { .name = "MPAM0_EL1", .state = ARM_CP_STATE_AA64,
               .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 1,
               .access = PL1_RW, .type = ARM_CP_ALIAS,
#14 lore raw

Re: [PATCH 03/37] target/arm: Add MPAMSM_EL1 register

In reply to Jonathan Cameron
Quoted 29 lines · Jonathan Cameron
Quoted 26 lines · On Fri, 16 Oct 2026 17:46:57 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jinjie Ruan <[email protected]>

FEAT_MPAM_SMS's MPAMSM_EL1 (S3_0_C10_C5_3) was missing, so a v7.x guest with SME enabled took an UNDEFINED instruction in cpu_enable_mpam(), which writes the register unconditionally when ARM64_SME is present. Register it backed by CPU state like the other MPAM registers, letting linux v7.x boot with -cpu max unmodified.

---
 target/arm/cpu.h    | 1 +
 target/arm/helper.c | 6 ++++++
 2 files changed, 7 insertions(+)
target/arm/cpu.h +1 -0
index 218923a..c60ec62 100644
@@ -761,6 +761,7 @@ typedef struct CPUArchState {
     uint64_t mpam1_el1;
     uint64_t mpam2_el2;
     uint64_t mpamhcr_el2;
+    uint64_t mpamsm_el1;
     /* Optional fault info across tlb lookup. */
     ARMMMUFaultInfo *tlb_fi;
 
Quoted 13 lines

target/arm/helper.c void register_cp_regs_for_features(ARMCPU *cpu) · line 6918

Quoted 12 lines
target/arm/helper.c +4 -0
index d5d96d5..a9b1521 100644
@@ -6912,6 +6912,12 @@ void register_cp_regs_for_features(ARMCPU *cpu)
               .access = PL1_R, .type = ARM_CP_CONST,
               .accessfn = access_tid3,
               .resetvalue = cpu->isar.mpamidr_el1 },
+            { .name = "MPAMSM_EL1", .state = ARM_CP_STATE_AA64,
+              .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 3,
+              .access = PL1_RW, .type = ARM_CP_ALIAS,
+              .accessfn = access_tid3,

Same as previous. Wrong trap. Also depends on SME being present, otherwise

+static CPAccessResult access_mpamsm(CPUARMState *env,
+ const ARMCPRegInfo *ri, bool isread)
+{
+ if (arm_current_el(env) < 2 && arm_is_el2_enabled(env) &&
+ !(env->mpam2_el2 & R_MPAM2_EL2_EnMPAMSM_MASK)) {
+ return CP_ACCESS_TRAP_EL2;
+ }
+ return CP_ACCESS_OK;
+}

Now as below:

Quoted 1 line

this register needs hiding.

Now define as below:

    if (cpu_isar_feature(aa64_sme, cpu)) {
         define_arm_cp_regs(cpu, sme_reginfo);
+        define_one_arm_cp_reg(cpu, &mpamsm_el1_reginfo);
     }
Quoted 3 lines

FWIW claude at least is really good at giving at poking holes in these entries. Other LLMs might be too. Bunch of RES0 in this one as well.

Will mask tyhe RES0, thank you!

Quoted 8 lines
Quoted 7 lines
target/arm/helper.c +2 -0
+              .fieldoffset = offsetof(CPUARMState, mpamsm_el1),
+            },
             { .name = "MPAM0_EL1", .state = ARM_CP_STATE_AA64,
               .opc0 = 3, .opc1 = 0, .crn = 0xa, .crm = 5, .opc2 = 1,
               .access = PL1_RW, .type = ARM_CP_ALIAS,
#15 lore raw

PATCH 4/37 hw/acpi: Build PPTT rev 3 with cache IDs for MPAM cross-references

In reply to a message not in the archive

From: Jinjie Ruan <[email protected]>

The MPAM ACPI table points at cache MSCs via a cache_reference that the kernel resolves against a PPTT cache node carrying a Cache ID (only present in PPTT revision 3, with the Cache ID valid flag). Without it, a guest MPAM driver cannot associate cache MSCs with caches and rejects them.

Bump the PPTT to revision 3 and give every cache node an ID derived from its type, level and the first CPU of the topology container it belongs to. The virt machine's MPAM cache MSC creation uses the same topology levels (L3 at socket, L2 at cluster) as the PPTT builder and derives the same IDs, so MSC locators resolve to real cache nodes.

---
 hw/acpi/aml-build.c         | 31 ++++++++++++++++++++++---------
 include/hw/acpi/aml-build.h |  8 ++++++++
 2 files changed, 30 insertions(+), 9 deletions(-)
hw/acpi/aml-build.c +22 -9
index 990abc6..2e09a39 100644
@@ -2185,16 +2185,16 @@ void build_spcr(GArray *table_data, BIOSLinker *linker,
  * 5.2.29.2 Cache Type Structure (Type 1)
  */
 static void build_cache_nodes(GArray *tbl, CPUCoreCaches *cache,
-                              uint32_t next_offset)
+                              uint32_t next_offset, uint32_t cache_id)
 {
-    const uint8_t node_length = 24;
+    const uint8_t node_length = 28;
     int start_len = tbl->len;
     int val;
 
     build_append_byte(tbl, 1);                         /* Type 1 - cache */
     build_append_byte(tbl, node_length);               /* Length */
     build_append_int_noprefix(tbl, 0, 2);              /* Reserved */
-    build_append_int_noprefix(tbl, 0x7f, 4);           /* Flags */
+    build_append_int_noprefix(tbl, 0xff, 4);           /* Flags */
     build_append_int_noprefix(tbl, next_offset, 4);    /* Next Level of Cache */
     build_append_int_noprefix(tbl, cache->size, 4);    /* Size */
     build_append_int_noprefix(tbl, cache->sets, 4);    /* Number of sets */
@@ -2213,6 +2213,7 @@ static void build_cache_nodes(GArray *tbl, CPUCoreCaches *cache,
     }
     build_append_byte(tbl, val);                        /* Attributes */
     build_append_int_noprefix(tbl, cache->linesize, 2); /* Line size */
+    build_append_int_noprefix(tbl, cache_id, 4);        /* Cache ID (v1) */
     g_assert(tbl->len == start_len + node_length);
 }
 
@@ -2230,7 +2231,8 @@ static bool build_caches(GArray *table_data, uint32_t pptt_start,
                          uint8_t level_high, /* Inclusive */
                          uint8_t level_low,  /* Inclusive */
                          uint32_t *data_offset,
-                         uint32_t *instr_offset)
+                         uint32_t *instr_offset,
+                         uint32_t base_cpu)
 {
     uint32_t next_level_offset_data = 0, next_level_offset_instruction = 0;
     uint32_t this_offset, next_offset = 0;
@@ -2240,10 +2242,20 @@ static bool build_caches(GArray *table_data, uint32_t pptt_start,
     /* Walk caches from top to bottom */
     for (level = level_high; level >= level_low; level--) {
         for (c = 0; c < num_caches; c++) {
+            uint32_t cache_id;
+
             if (caches[c].level != level) {
                 continue;
             }
 
+            /*
+             * MPAM cross-references caches from the MPAM table using
+             * this id. base_cpu identifies the topology container the
+             * cache belongs to (the id at which this call was made).
+             */
+            cache_id = PPTT_CACHE_ID(caches[c].type, caches[c].level,
+                                     base_cpu);
+
             /* Assume only unified above l1 for now */
             this_offset = table_data->len - pptt_start;
             switch (caches[c].type) {
@@ -2258,7 +2270,7 @@ static bool build_caches(GArray *table_data, uint32_t pptt_start,
                 next_offset = next_level_offset_instruction;
                 break;
             }
-            build_cache_nodes(table_data, &caches[c], next_offset);
+            build_cache_nodes(table_data, &caches[c], next_offset, cache_id);
             switch (caches[c].type) {
             case INSTRUCTION_CACHE:
                 next_level_offset_instruction = this_offset;
@@ -2316,7 +2328,7 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,
     uint32_t num_priv = 0;
     bool cache_at_topo_level;
 
-    AcpiTable table = { .sig = "PPTT", .rev = 2,
+    AcpiTable table = { .sig = "PPTT", .rev = 3,
                         .oem_id = oem_id, .oem_table_id = oem_table_id };
 
     acpi_table_begin(&table, table_data);
@@ -2353,7 +2365,7 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,
             if (cache_at_topo_level) {
                 build_caches(table_data, pptt_start, num_caches, caches,
                              top_node, bottom_node, &node_data_offset,
-                             &node_instr_offset);
+                             &node_instr_offset, n);
                 priv_rsrc[0] = node_instr_offset;
                 priv_rsrc[1] = node_data_offset;
                 if (node_instr_offset || node_data_offset) {
@@ -2384,7 +2396,8 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,
                 if (cache_at_topo_level) {
                     build_caches(table_data, pptt_start, num_caches, caches,
                                  top_cluster, bottom_cluster,
-                                 &cluster_data_offset, &cluster_instr_offset);
+                                 &cluster_data_offset, &cluster_instr_offset,
+                                 n);
                     priv_rsrc[0] = cluster_instr_offset;
                     priv_rsrc[1] = cluster_data_offset;
                     if (cluster_instr_offset || cluster_data_offset) {
@@ -2423,7 +2436,7 @@ void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,
             if (cache_at_topo_level) {
                 build_caches(table_data, pptt_start, num_caches, caches,
                              top_core, bottom_core, &core_data_offset,
-                             &core_instr_offset);
+                             &core_instr_offset, n);
                 priv_rsrc[0] = core_instr_offset;
                 priv_rsrc[1] = core_data_offset;
                 num_priv = core_instr_offset == core_data_offset ? 1 : 2;
include/hw/acpi/aml-build.h +8 -0
index eaff025..f64e04e 100644
@@ -501,6 +501,14 @@ void build_srat_acpi_generic_port(GArray *table_data, uint32_t node,
 void build_slit(GArray *table_data, BIOSLinker *linker, MachineState *ms,
                 const char *oem_id, const char *oem_table_id);
 
+/*
+ * PPTT rev 3 Cache ID (ACPI 6.5 Table 5.157): cache type and level in
+ * the high bytes, the first CPU of the topology container in the low
+ * half.  The MPAM table cache locator uses the same encoding.
+ */
+#define PPTT_CACHE_ID(type, level, cpu)                          \
+    (((uint32_t)(type) << 24) | ((uint32_t)(level) << 16) | (cpu))
+
 void build_pptt(GArray *table_data, BIOSLinker *linker, MachineState *ms,
                 const char *oem_id, const char *oem_table_id,
                 int num_caches, CPUCoreCaches *caches);
Signature · 1 line
2.43.0
Reviewed-by on v1 4/37
#16 lore raw

Re: [PATCH 04/37] hw/acpi: Build PPTT rev 3 with cache IDs for MPAM cross-references

Quoted 8 lines · On Fri, 16 Oct 2026 17:46:58 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jinjie Ruan <[email protected]>

The MPAM ACPI table points at cache MSCs via a cache_reference that the kernel resolves against a PPTT cache node carrying a Cache ID (only present in PPTT revision 3, with the Cache ID valid flag). Without it, a guest MPAM driver cannot associate cache MSCs with caches and rejects them.

Quoted 5 lines

Bump the PPTT to revision 3 and give every cache node an ID derived from its type, level and the first CPU of the topology container it belongs to. The virt machine's MPAM cache MSC creation uses the same topology levels (L3 at socket, L2 at cluster) as the PPTT builder and derives the same IDs, so MSC locators resolve to real cache nodes.

Good. We dropped this from the last PPTT revision upgrade on basis we had no user without MPAM. Now we do indeed need an upgrade.

PPTT is tested though so you need to add the two wrapping commits described at the top of tests/qtest/bios-tables-test.c and upgrade any effect tables in tests/data/acpi/arm/...

Given the implementation defined aspect of this is how the cache IDs are derived, I'd add a description of that here.

With that stuff tidied up.

Quoted 2 lines
#17 lore raw

Re: [PATCH 04/37] hw/acpi: Build PPTT rev 3 with cache IDs for MPAM cross-references

Quoted 17 lines · Jonathan Cameron
Quoted 8 lines · On Fri, 16 Oct 2026 17:46:58 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jinjie Ruan <[email protected]>

The MPAM ACPI table points at cache MSCs via a cache_reference that the kernel resolves against a PPTT cache node carrying a Cache ID (only present in PPTT revision 3, with the Cache ID valid flag). Without it, a guest MPAM driver cannot associate cache MSCs with caches and rejects them.

Quoted 5 lines

Bump the PPTT to revision 3 and give every cache node an ID derived from its type, level and the first CPU of the topology container it belongs to. The virt machine's MPAM cache MSC creation uses the same topology levels (L3 at socket, L2 at cluster) as the PPTT builder and derives the same IDs, so MSC locators resolve to real cache nodes.

Quoted 6 lines

Good. We dropped this from the last PPTT revision upgrade on basis we had no user without MPAM. Now we do indeed need an upgrade.

PPTT is tested though so you need to add the two wrapping commits described at the top of tests/qtest/bios-tables-test.c and upgrade any effect tables in tests/data/acpi/arm/...

OK, have added it.

Quoted 7 lines

Given the implementation defined aspect of this is how the cache IDs are derived, I'd add a description of that here.

With that stuff tidied up.

Thank you for the review.

Quoted 5 lines
Quoted 4 lines
#18 lore raw

PATCH 5/37 hw/arm/mpam: Add MPAM MSC register map

In reply to a message not in the archive

From: Jonathan Cameron <[email protected]>

Add the MMIO register map of an MPAM 1.1 Memory System Component (IHI 0099 sections 4-6) as registerfields definitions:
- The feature IDRs (MPAMF_IDR, IIDR/AIDR, CPOR/CCAP/MBW/PRI/PARTID_NRW, MSMON family)
- The error registers (ERR_MSI block, ECR, ESR)
- The configuration registers (PART_SEL, CMAX/CMIN/CASSOC, MBW_MIN/MAX/PBM/PROP, PRI, INTPARTID, CPBM/MBW_PBM arrays) and their write masks
- The portion-width constants of this model.

Based on an RFC series by Jonathan Cameron.

---
 hw/arm/Kconfig        |   4 +
 hw/arm/meson.build    |   1 +
 hw/arm/mpam.c         | 223 ++++++++++++++++++++++++++++++++++++++++++
 include/hw/arm/mpam.h |  20 ++++
 4 files changed, 248 insertions(+)
 create mode 100644 hw/arm/mpam.c
 create mode 100644 include/hw/arm/mpam.h
hw/arm/Kconfig +4 -0
index 4445f16..6a2a36a 100644
@@ -37,6 +37,7 @@ config ARM_VIRT
     select ACPI_CXL
     select ACPI_HMAT
     select WDT_SBSA
+    select MPAM
 
 config CUBIEBOARD
     bool
@@ -650,6 +651,9 @@ config ARM_SMMUV3
     select ARM_SMMUV3_ACCEL if IOMMUFD
     imply TEGRA241_CMDQV
 
+config MPAM
+    bool
+
 config FSL_IMX6UL
     bool
     default y
hw/arm/meson.build +1 -0
index bcc068d..42ca75b 100644
@@ -106,6 +106,7 @@ arm_common_ss.add(when: 'CONFIG_NETDUINO2', if_true: files('netduino2.c'))
 arm_common_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_peripherals.c'))
 arm_common_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2838_peripherals.c'))
 arm_common_ss.add(when: 'CONFIG_STRONGARM', if_true: files('strongarm.c'))
+arm_common_ss.add(when: 'CONFIG_MPAM', if_true: files('mpam.c'))
 arm_common_ss.add(when: 'CONFIG_SX1', if_true: files('omap_sx1.c'))
 arm_common_ss.add(when: 'CONFIG_VERSATILE', if_true: files('versatilepb.c'))
 arm_common_ss.add(when: 'CONFIG_VEXPRESS', if_true: files('vexpress.c'))
hw/arm/mpam.c new file +223 -0

223 lines not on this page · raw message

include/hw/arm/mpam.h new file +20 -0
new file mode 100644
index 0000000..e7557a9
@@ -0,0 +1,20 @@
+/*
+ * QEMU MPAM emulation
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef _MPAM_H_
+#define _MPAM_H_
+
+#include "qom/object.h"
+
+#define TYPE_MPAM_MSC_MEM "mpam-msc-mem"
+#define TYPE_MPAM_MSC_CACHE "mpam-msc-cache"
+
+/*
+ * MMIO window of one MSC: IHI 0099 places the register block in a 16 KiB
+ * region (0x4000).  The virt board reserves a 1 MiB slot for up to 256 MSCs.
+ */
+#define MPAM_SIZE 0x4000
+
+#endif /* _MPAM_H_ */
Signature · 1 line
2.43.0
#19 lore raw

Re: [PATCH 05/37] hw/arm/mpam: Add MPAM MSC register map

Quoted 12 lines · On Fri, 16 Oct 2026 17:46:59 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

Add the MMIO register map of an MPAM 1.1 Memory System Component (IHI 0099 sections 4-6) as registerfields definitions:
- The feature IDRs (MPAMF_IDR, IIDR/AIDR, CPOR/CCAP/MBW/PRI/PARTID_NRW, MSMON family)
- The error registers (ERR_MSI block, ECR, ESR)
- The configuration registers (PART_SEL, CMAX/CMIN/CASSOC, MBW_MIN/MAX/PBM/PROP, PRI, INTPARTID, CPBM/MBW_PBM arrays) and their write masks
- The portion-width constants of this model.

Quoted 1 line

Based on an RFC series by Jonathan Cameron.

Maybe a link tag to that old piece of garbage - might be more useful than referring to it like this.

A few typos in here that should be tidied up. I clearly didn't check this closely enough at the time. Nothing major but need tidying up.

Also, an LLM pointed out that some of the write masks are more complex that this implies as depend on other register values. Maybe add comments where that is true as enforcement will be needed in the writing code - what we have here just acts as some sort of worst case masking. I guess you could define some macros to create the masks here.

Thanks,

Jonathan

Quoted 31 lines
hw/arm/meson.build +1 -0
index bcc068d..42ca75b 100644
@@ -106,6 +106,7 @@ arm_common_ss.add(when: 'CONFIG_NETDUINO2', if_true: files('netduino2.c'))
 arm_common_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_peripherals.c'))
 arm_common_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2838_peripherals.c'))
 arm_common_ss.add(when: 'CONFIG_STRONGARM', if_true: files('strongarm.c'))
+arm_common_ss.add(when: 'CONFIG_MPAM', if_true: files('mpam.c'))
 arm_common_ss.add(when: 'CONFIG_SX1', if_true: files('omap_sx1.c'))
 arm_common_ss.add(when: 'CONFIG_VERSATILE', if_true: files('versatilepb.c'))
 arm_common_ss.add(when: 'CONFIG_VEXPRESS', if_true: files('vexpress.c'))
hw/arm/mpam.c new file +9 -0
new file mode 100644
index 0000000..772a120
@@ -0,0 +1,223 @@
+/*
+ * ARM MPAM emulation
+ *
+ * Copyright (c) 2023 Huawei
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include "qemu/osdep.h"
+#include "qapi/error.h"

hw/arm/mpam.c line 19

Quoted 10 lines
hw/arm/mpam.c new file +10 -0
+#include "qemu/log.h"
+#include "hw/core/irq.h"
+#include "hw/core/qdev-properties.h"
+#include "hw/core/registerfields.h"
+#include "hw/core/sysbus.h"
+#include "qom/object.h"
+#include "hw/arm/mpam.h"
+
+REG64(MPAMF_IDR, 0)
+    FIELD(MPAMF_IDR, PART_ID_MAX, 0, 16)

Maybe call it PARTID_MAX given spec naming.

Quoted 14 lines
hw/arm/mpam.c new file +14 -0
+    FIELD(MPAMF_IDR, PMG_MAX, 16, 8)
+    FIELD(MPAMF_IDR, HAS_CCAP_PART, 24, 1)
+    FIELD(MPAMF_IDR, HAS_CPOR_PART, 25, 1)
+    FIELD(MPAMF_IDR, HAS_MBW_PART, 26, 1)
+    FIELD(MPAMF_IDR, HAS_PRI_PART, 27, 1)
+    FIELD(MPAMF_IDR, EXT, 28, 1)
+    FIELD(MPAMF_IDR, HAS_IMPL_IDR, 29, 1)
+    FIELD(MPAMF_IDR, HAS_MSMON, 30, 1)
+    FIELD(MPAMF_IDR, HAS_PARTID_NRW, 31, 1)
+    FIELD(MPAMF_IDR, HAS_RIS, 32, 1)
+    FIELD(MPAMF_IDR, NO_IMPL_PART, 36, 1)
+    FIELD(MPAMF_IDR, NO_IMPL_MSMON, 37, 1)
+    FIELD(MPAMF_IDR, HAS_EXTD_ESR, 38, 1)
+    FIELD(MPAMF_IDR, HAS_ESR, 39, 1)

hw/arm/mpam.c line 82

Quoted 10 lines
hw/arm/mpam.c new file +7 -0
+    FIELD(MPAMF_IDR, HAS_ERR_MS, 40, 1)
+    FIELD(MPAMF_IDR, SP4, 41, 1)
+    FIELD(MPAMF_IDR, HAS_ENDIS, 42, 1)
+    FIELD(MPAMF_IDR, HAS_NFU, 43, 1)
+    FIELD(MPAMF_IDR, RIS_MAX, 56, 4)
 
 
 
+
+REG32(MPAMF_MSMON_IDR, 0x080)

An LLM pointed out I was really inconsistent in numbers of digits. 0x0080
Ah the heady days of copying typing specs.

hw/arm/mpam.c line 86

Quoted 4 lines
hw/arm/mpam.c new file +4 -0
+    FIELD(MPAMF_MSMON_IDR, MSMON_CSU, 16, 1)
+    FIELD(MPAMF_MSMON_IDR, MSMON_MBWU, 17, 1)
+    FIELD(MPAMF_MSMON_IDR, HAS_OFLOW_SR, 28, 1)
+    FIELD(MPAMF_MSMON_IDR, HAS_OFLW_MS, 29, 1)

_MSI

Quoted 2 lines
hw/arm/mpam.c new file +2 -0
+    FIELD(MPAMF_MSMON_IDR, NO_OFLW_INTR, 30, 1)
+    FIELD(MPAMF_MSMON_IDR, HAS_LOCAL_CAPT_EVNT, 31, 1)

...

hw/arm/mpam.c line 173

Quoted 6 lines
hw/arm/mpam.c new file +6 -0
+REG32(MPAMF_MPAMCFG_WINWD, 0x0220)
+    FIELD(MPAMF_MPAMCFG_WINWD, US_FRAC, 0, 8)
+    FIELD(MPAMF_MPAMCFG_WINWD, US_INT, 8, 16)
+#define MPAMF_MPAMCFG_WINWD_WRITE_MASK ( \
+    R_MPAMF_MPAMCFG_WINWD_US_FRAC | \
+    R_MPAMF_MPAMCFG_WINWD_US_INT)

Those need _MASK suffix.

hw/arm/mpam.c line 185

Quoted 12 lines
hw/arm/mpam.c new file +12 -0
+
+REG32(MPAMF_MPAMCFG_EN, 0x0300)
+    FIELD(MPAMF_MPAMCFG_EN, PARTID, 0, 16)
+#define MPAMF_MPAMCFG_EN_WRITE_MASK ( \
+    R_MPAMF_MPAMCFG_EN_PARTID_MASK)
+
+REG32(MPAMF_MPAMCFG_DIS, 0x0310) /* WHat is this for? */
+    FIELD(MPAMF_MPAMCFG_DIS, PARTID, 0, 16)
+    FIELD(MPAMF_MPAMCFG_DIS, NFU, 31, 1)
+#define MPAMF_MPAMCFG_DIS_WRITE_MASK ( \
+    R_MPAMF_MPAMCFG_DIS_PARTID_MASK | \
+    R_MPAMF_MPAMCFG_DIS_NFU)

Needs a _MASK suffic.

hw/arm/mpam.c

Quoted 2 lines
hw/arm/mpam.c new file +2 -0
+
+REG32(MPAMF_MPAMCFG_EN_FLAGS, 0x320)

Lots of 3 digit addresses scattered through here that should all be 4 digits.

Quoted 17 lines
hw/arm/mpam.c new file +11 -0
+
+#define TYPE_MPAM_MSC "mpam-msc"
+/*
+ * Max number of portions this model exposes for the cache-portion (CPOR)
+ * bitmap and the memory-bandwidth-portion (MBW_PBM) bitmap.  IHI 0099
+ * dimensions CPBM_WD/BWPBM_WD by these widths (see MPAMF_CPOR/MBW_IDR).
+ */
+#define MPAM_MBW_PART 4
+#define MPAM_CACHE_PART 32
+/* MPAMF_IIDR.IMPLEMENTER: ARM JEP106 code for Huawei (0x736). */
+#define MPAM_IIDR_IMPLEMENTER 0x736
include/hw/arm/mpam.h new file +0 -0
new file mode 100644
index 0000000..e7557a9

include/hw/arm/mpam.h line 2

Quoted 2 lines
include/hw/arm/mpam.h new file +2 -0
@@ -0,0 +1,20 @@
+/*
+ * QEMU MPAM emulation

Come to think of it, why have QEMU in a QEMU header.

MPAM emulation.

Quoted 18 lines
include/hw/arm/mpam.h new file +18 -0
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef _MPAM_H_
+#define _MPAM_H_
+
+#include "qom/object.h"
+
+#define TYPE_MPAM_MSC_MEM "mpam-msc-mem"
+#define TYPE_MPAM_MSC_CACHE "mpam-msc-cache"
+
+/*
+ * MMIO window of one MSC: IHI 0099 places the register block in a 16 KiB
+ * region (0x4000).  The virt board reserves a 1 MiB slot for up to 256 MSCs.
+ */
+#define MPAM_SIZE 0x4000
+
+#endif /* _MPAM_H_ */
#20 lore raw

Re: [PATCH 05/37] hw/arm/mpam: Add MPAM MSC register map

Quoted 15 lines · Jonathan Cameron
Quoted 12 lines · On Fri, 16 Oct 2026 17:46:59 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

Add the MMIO register map of an MPAM 1.1 Memory System Component (IHI 0099 sections 4-6) as registerfields definitions:
- The feature IDRs (MPAMF_IDR, IIDR/AIDR, CPOR/CCAP/MBW/PRI/PARTID_NRW, MSMON family)
- The error registers (ERR_MSI block, ECR, ESR)
- The configuration registers (PART_SEL, CMAX/CMIN/CASSOC, MBW_MIN/MAX/PBM/PROP, PRI, INTPARTID, CPBM/MBW_PBM arrays) and their write masks
- The portion-width constants of this model.

Quoted 4 lines
Quoted 1 line

Based on an RFC series by Jonathan Cameron.

Maybe a link tag to that old piece of garbage - might be more useful than referring to it like this.

Yes, you are right! A link will be more clear.

Quoted 51 lines

A few typos in here that should be tidied up. I clearly didn't check this closely enough at the time. Nothing major but need tidying up.

Also, an LLM pointed out that some of the write masks are more complex that this implies as depend on other register values. Maybe add comments where that is true as enforcement will be needed in the writing code - what we have here just acts as some sort of worst case masking. I guess you could define some macros to create the masks here.

Thanks,

Jonathan

Quoted 35 lines
hw/arm/meson.build +1 -0
index bcc068d..42ca75b 100644
@@ -106,6 +106,7 @@ arm_common_ss.add(when: 'CONFIG_NETDUINO2', if_true: files('netduino2.c'))
 arm_common_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_peripherals.c'))
 arm_common_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2838_peripherals.c'))
 arm_common_ss.add(when: 'CONFIG_STRONGARM', if_true: files('strongarm.c'))
+arm_common_ss.add(when: 'CONFIG_MPAM', if_true: files('mpam.c'))
 arm_common_ss.add(when: 'CONFIG_SX1', if_true: files('omap_sx1.c'))
 arm_common_ss.add(when: 'CONFIG_VERSATILE', if_true: files('versatilepb.c'))
 arm_common_ss.add(when: 'CONFIG_VEXPRESS', if_true: files('vexpress.c'))
hw/arm/mpam.c new file +13 -0
new file mode 100644
index 0000000..772a120
@@ -0,0 +1,223 @@
+/*
+ * ARM MPAM emulation
+ *
+ * Copyright (c) 2023 Huawei
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qemu/log.h"
+#include "hw/core/irq.h"
+#include "hw/core/qdev-properties.h"
+#include "hw/core/registerfields.h"
Quoted 8 lines

hw/arm/mpam.c line 19

Quoted 6 lines
hw/arm/mpam.c new file +6 -0
+#include "hw/core/sysbus.h"
+#include "qom/object.h"
+#include "hw/arm/mpam.h"
+
+REG64(MPAMF_IDR, 0)
+    FIELD(MPAMF_IDR, PART_ID_MAX, 0, 16)

Maybe call it PARTID_MAX given spec naming.

Yes, the spec naming is PARTID_MAX.

Quoted 23 lines
Quoted 20 lines
hw/arm/mpam.c new file +19 -0
+    FIELD(MPAMF_IDR, PMG_MAX, 16, 8)
+    FIELD(MPAMF_IDR, HAS_CCAP_PART, 24, 1)
+    FIELD(MPAMF_IDR, HAS_CPOR_PART, 25, 1)
+    FIELD(MPAMF_IDR, HAS_MBW_PART, 26, 1)
+    FIELD(MPAMF_IDR, HAS_PRI_PART, 27, 1)
+    FIELD(MPAMF_IDR, EXT, 28, 1)
+    FIELD(MPAMF_IDR, HAS_IMPL_IDR, 29, 1)
+    FIELD(MPAMF_IDR, HAS_MSMON, 30, 1)
+    FIELD(MPAMF_IDR, HAS_PARTID_NRW, 31, 1)
+    FIELD(MPAMF_IDR, HAS_RIS, 32, 1)
+    FIELD(MPAMF_IDR, NO_IMPL_PART, 36, 1)
+    FIELD(MPAMF_IDR, NO_IMPL_MSMON, 37, 1)
+    FIELD(MPAMF_IDR, HAS_EXTD_ESR, 38, 1)
+    FIELD(MPAMF_IDR, HAS_ESR, 39, 1)
+    FIELD(MPAMF_IDR, HAS_ERR_MS, 40, 1)
+    FIELD(MPAMF_IDR, SP4, 41, 1)
+    FIELD(MPAMF_IDR, HAS_ENDIS, 42, 1)
+    FIELD(MPAMF_IDR, HAS_NFU, 43, 1)
+    FIELD(MPAMF_IDR, RIS_MAX, 56, 4)
Quoted 5 lines

hw/arm/mpam.c line 40

Quoted 2 lines
hw/arm/mpam.c new file +2 -0
+
+REG32(MPAMF_MSMON_IDR, 0x080)

An LLM pointed out I was really inconsistent in numbers of digits. 0x0080

Yes, it is 0x0080 in the spec.

Quoted 7 lines

Ah the heady days of copying typing specs.

hw/arm/mpam.c line 86

Quoted 4 lines
hw/arm/mpam.c new file +4 -0
+    FIELD(MPAMF_MSMON_IDR, MSMON_CSU, 16, 1)
+    FIELD(MPAMF_MSMON_IDR, MSMON_MBWU, 17, 1)
+    FIELD(MPAMF_MSMON_IDR, HAS_OFLOW_SR, 28, 1)
+    FIELD(MPAMF_MSMON_IDR, HAS_OFLW_MS, 29, 1)

_MSI

Right, will fix them.

Quoted 14 lines
Quoted 3 lines
hw/arm/mpam.c new file +2 -0
+    FIELD(MPAMF_MSMON_IDR, NO_OFLW_INTR, 30, 1)
+    FIELD(MPAMF_MSMON_IDR, HAS_LOCAL_CAPT_EVNT, 31, 1)

...

hw/arm/mpam.c line 173

Quoted 6 lines
hw/arm/mpam.c new file +6 -0
+REG32(MPAMF_MPAMCFG_WINWD, 0x0220)
+    FIELD(MPAMF_MPAMCFG_WINWD, US_FRAC, 0, 8)
+    FIELD(MPAMF_MPAMCFG_WINWD, US_INT, 8, 16)
+#define MPAMF_MPAMCFG_WINWD_WRITE_MASK ( \
+    R_MPAMF_MPAMCFG_WINWD_US_FRAC | \
+    R_MPAMF_MPAMCFG_WINWD_US_INT)

Those need _MASK suffix.

Quoted 14 lines

hw/arm/mpam.c line 185

Quoted 12 lines
hw/arm/mpam.c new file +12 -0
+
+REG32(MPAMF_MPAMCFG_EN, 0x0300)
+    FIELD(MPAMF_MPAMCFG_EN, PARTID, 0, 16)
+#define MPAMF_MPAMCFG_EN_WRITE_MASK ( \
+    R_MPAMF_MPAMCFG_EN_PARTID_MASK)
+
+REG32(MPAMF_MPAMCFG_DIS, 0x0310) /* WHat is this for? */
+    FIELD(MPAMF_MPAMCFG_DIS, PARTID, 0, 16)
+    FIELD(MPAMF_MPAMCFG_DIS, NFU, 31, 1)
+#define MPAMF_MPAMCFG_DIS_WRITE_MASK ( \
+    R_MPAMF_MPAMCFG_DIS_PARTID_MASK | \
+    R_MPAMF_MPAMCFG_DIS_NFU)

Needs a _MASK suffic.

OK

Quoted 6 lines

hw/arm/mpam.c

Quoted 3 lines
hw/arm/mpam.c new file +2 -0
+
+REG32(MPAMF_MPAMCFG_EN_FLAGS, 0x320)

Lots of 3 digit addresses scattered through here that should all be 4 digits.

Will fix them all.

Quoted 22 lines
Quoted 18 lines
hw/arm/mpam.c new file +11 -0
+
+#define TYPE_MPAM_MSC "mpam-msc"
+/*
+ * Max number of portions this model exposes for the cache-portion (CPOR)
+ * bitmap and the memory-bandwidth-portion (MBW_PBM) bitmap.  IHI 0099
+ * dimensions CPBM_WD/BWPBM_WD by these widths (see MPAMF_CPOR/MBW_IDR).
+ */
+#define MPAM_MBW_PART 4
+#define MPAM_CACHE_PART 32
+/* MPAMF_IIDR.IMPLEMENTER: ARM JEP106 code for Huawei (0x736). */
+#define MPAM_IIDR_IMPLEMENTER 0x736
include/hw/arm/mpam.h new file +0 -0
new file mode 100644
index 0000000..e7557a9

include/hw/arm/mpam.h line 2

Quoted 2 lines
include/hw/arm/mpam.h new file +2 -0
@@ -0,0 +1,20 @@
+/*
+ * QEMU MPAM emulation

Come to think of it, why have QEMU in a QEMU header.

Quoted 1 line

MPAM emulation.

OK.

Quoted 20 lines
Quoted 19 lines
include/hw/arm/mpam.h new file +18 -0
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef _MPAM_H_
+#define _MPAM_H_
+
+#include "qom/object.h"
+
+#define TYPE_MPAM_MSC_MEM "mpam-msc-mem"
+#define TYPE_MPAM_MSC_CACHE "mpam-msc-cache"
+
+/*
+ * MMIO window of one MSC: IHI 0099 places the register block in a 16 KiB
+ * region (0x4000).  The virt board reserves a 1 MiB slot for up to 256 MSCs.
+ */
+#define MPAM_SIZE 0x4000
+
+#endif /* _MPAM_H_ */
#21 lore raw

Re: [PATCH 05/37] hw/arm/mpam: Add MPAM MSC register map

In reply to Jonathan Cameron
Quoted 4 lines · Jonathan Cameron
Quoted 1 line · On Fri, 16 Oct 2026 17:46:59 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

Hi Jonathan,

Quoted 66 lines
Quoted 11 lines

Add the MMIO register map of an MPAM 1.1 Memory System Component (IHI 0099 sections 4-6) as registerfields definitions:
- The feature IDRs (MPAMF_IDR, IIDR/AIDR, CPOR/CCAP/MBW/PRI/PARTID_NRW, MSMON family)
- The error registers (ERR_MSI block, ECR, ESR)
- The configuration registers (PART_SEL, CMAX/CMIN/CASSOC, MBW_MIN/MAX/PBM/PROP, PRI, INTPARTID, CPBM/MBW_PBM arrays) and their write masks
- The portion-width constants of this model.

Quoted 1 line

Based on an RFC series by Jonathan Cameron.

Maybe a link tag to that old piece of garbage - might be more useful than referring to it like this.

A few typos in here that should be tidied up. I clearly didn't check this closely enough at the time. Nothing major but need tidying up.

Also, an LLM pointed out that some of the write masks are more complex that this implies as depend on other register values. Maybe add comments where that is true as enforcement will be needed in the writing code - what we have here just acts as some sort of worst case masking. I guess you could define some macros to create the masks here.

Thanks,

Jonathan

Quoted 35 lines
hw/arm/meson.build +1 -0
index bcc068d..42ca75b 100644
@@ -106,6 +106,7 @@ arm_common_ss.add(when: 'CONFIG_NETDUINO2', if_true: files('netduino2.c'))
 arm_common_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2835_peripherals.c'))
 arm_common_ss.add(when: 'CONFIG_RASPI', if_true: files('bcm2838_peripherals.c'))
 arm_common_ss.add(when: 'CONFIG_STRONGARM', if_true: files('strongarm.c'))
+arm_common_ss.add(when: 'CONFIG_MPAM', if_true: files('mpam.c'))
 arm_common_ss.add(when: 'CONFIG_SX1', if_true: files('omap_sx1.c'))
 arm_common_ss.add(when: 'CONFIG_VERSATILE', if_true: files('versatilepb.c'))
 arm_common_ss.add(when: 'CONFIG_VEXPRESS', if_true: files('vexpress.c'))
hw/arm/mpam.c new file +13 -0
new file mode 100644
index 0000000..772a120
@@ -0,0 +1,223 @@
+/*
+ * ARM MPAM emulation
+ *
+ * Copyright (c) 2023 Huawei
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qemu/log.h"
+#include "hw/core/irq.h"
+#include "hw/core/qdev-properties.h"
+#include "hw/core/registerfields.h"
Quoted 8 lines

hw/arm/mpam.c line 19

Quoted 6 lines
hw/arm/mpam.c new file +6 -0
+#include "hw/core/sysbus.h"
+#include "qom/object.h"
+#include "hw/arm/mpam.h"
+
+REG64(MPAMF_IDR, 0)
+    FIELD(MPAMF_IDR, PART_ID_MAX, 0, 16)

Maybe call it PARTID_MAX given spec naming.

Many spec MPAMCFG_* are named as MPAMF_MPAMCFG_*, such as MPAMCFG_CASSOC and MPAMCFG_MBW_MIN.

I will correct all of them.

Thanks,
Jinjie

Quoted 112 lines
Quoted 15 lines
hw/arm/mpam.c new file +14 -0
+    FIELD(MPAMF_IDR, PMG_MAX, 16, 8)
+    FIELD(MPAMF_IDR, HAS_CCAP_PART, 24, 1)
+    FIELD(MPAMF_IDR, HAS_CPOR_PART, 25, 1)
+    FIELD(MPAMF_IDR, HAS_MBW_PART, 26, 1)
+    FIELD(MPAMF_IDR, HAS_PRI_PART, 27, 1)
+    FIELD(MPAMF_IDR, EXT, 28, 1)
+    FIELD(MPAMF_IDR, HAS_IMPL_IDR, 29, 1)
+    FIELD(MPAMF_IDR, HAS_MSMON, 30, 1)
+    FIELD(MPAMF_IDR, HAS_PARTID_NRW, 31, 1)
+    FIELD(MPAMF_IDR, HAS_RIS, 32, 1)
+    FIELD(MPAMF_IDR, NO_IMPL_PART, 36, 1)
+    FIELD(MPAMF_IDR, NO_IMPL_MSMON, 37, 1)
+    FIELD(MPAMF_IDR, HAS_EXTD_ESR, 38, 1)
+    FIELD(MPAMF_IDR, HAS_ESR, 39, 1)

hw/arm/mpam.c line 82

Quoted 10 lines
hw/arm/mpam.c new file +7 -0
+    FIELD(MPAMF_IDR, HAS_ERR_MS, 40, 1)
+    FIELD(MPAMF_IDR, SP4, 41, 1)
+    FIELD(MPAMF_IDR, HAS_ENDIS, 42, 1)
+    FIELD(MPAMF_IDR, HAS_NFU, 43, 1)
+    FIELD(MPAMF_IDR, RIS_MAX, 56, 4)
 
 
 
+
+REG32(MPAMF_MSMON_IDR, 0x080)

An LLM pointed out I was really inconsistent in numbers of digits. 0x0080
Ah the heady days of copying typing specs.

hw/arm/mpam.c line 86

Quoted 4 lines
hw/arm/mpam.c new file +4 -0
+    FIELD(MPAMF_MSMON_IDR, MSMON_CSU, 16, 1)
+    FIELD(MPAMF_MSMON_IDR, MSMON_MBWU, 17, 1)
+    FIELD(MPAMF_MSMON_IDR, HAS_OFLOW_SR, 28, 1)
+    FIELD(MPAMF_MSMON_IDR, HAS_OFLW_MS, 29, 1)

_MSI

Quoted 2 lines
hw/arm/mpam.c new file +2 -0
+    FIELD(MPAMF_MSMON_IDR, NO_OFLW_INTR, 30, 1)
+    FIELD(MPAMF_MSMON_IDR, HAS_LOCAL_CAPT_EVNT, 31, 1)

...

hw/arm/mpam.c line 173

Quoted 6 lines
hw/arm/mpam.c new file +6 -0
+REG32(MPAMF_MPAMCFG_WINWD, 0x0220)
+    FIELD(MPAMF_MPAMCFG_WINWD, US_FRAC, 0, 8)
+    FIELD(MPAMF_MPAMCFG_WINWD, US_INT, 8, 16)
+#define MPAMF_MPAMCFG_WINWD_WRITE_MASK ( \
+    R_MPAMF_MPAMCFG_WINWD_US_FRAC | \
+    R_MPAMF_MPAMCFG_WINWD_US_INT)

Those need _MASK suffix.

hw/arm/mpam.c line 185

Quoted 12 lines
hw/arm/mpam.c new file +12 -0
+
+REG32(MPAMF_MPAMCFG_EN, 0x0300)
+    FIELD(MPAMF_MPAMCFG_EN, PARTID, 0, 16)
+#define MPAMF_MPAMCFG_EN_WRITE_MASK ( \
+    R_MPAMF_MPAMCFG_EN_PARTID_MASK)
+
+REG32(MPAMF_MPAMCFG_DIS, 0x0310) /* WHat is this for? */
+    FIELD(MPAMF_MPAMCFG_DIS, PARTID, 0, 16)
+    FIELD(MPAMF_MPAMCFG_DIS, NFU, 31, 1)
+#define MPAMF_MPAMCFG_DIS_WRITE_MASK ( \
+    R_MPAMF_MPAMCFG_DIS_PARTID_MASK | \
+    R_MPAMF_MPAMCFG_DIS_NFU)

Needs a _MASK suffic.

hw/arm/mpam.c

Quoted 2 lines
hw/arm/mpam.c new file +2 -0
+
+REG32(MPAMF_MPAMCFG_EN_FLAGS, 0x320)

Lots of 3 digit addresses scattered through here that should all be 4 digits.

Quoted 17 lines
hw/arm/mpam.c new file +11 -0
+
+#define TYPE_MPAM_MSC "mpam-msc"
+/*
+ * Max number of portions this model exposes for the cache-portion (CPOR)
+ * bitmap and the memory-bandwidth-portion (MBW_PBM) bitmap.  IHI 0099
+ * dimensions CPBM_WD/BWPBM_WD by these widths (see MPAMF_CPOR/MBW_IDR).
+ */
+#define MPAM_MBW_PART 4
+#define MPAM_CACHE_PART 32
+/* MPAMF_IIDR.IMPLEMENTER: ARM JEP106 code for Huawei (0x736). */
+#define MPAM_IIDR_IMPLEMENTER 0x736
include/hw/arm/mpam.h new file +0 -0
new file mode 100644
index 0000000..e7557a9

include/hw/arm/mpam.h line 2

Quoted 2 lines
include/hw/arm/mpam.h new file +2 -0
@@ -0,0 +1,20 @@
+/*
+ * QEMU MPAM emulation

Come to think of it, why have QEMU in a QEMU header.

MPAM emulation.

Quoted 18 lines
include/hw/arm/mpam.h new file +18 -0
+ *
+ * SPDX-License-Identifier: GPL-2.0-or-later
+ */
+#ifndef _MPAM_H_
+#define _MPAM_H_
+
+#include "qom/object.h"
+
+#define TYPE_MPAM_MSC_MEM "mpam-msc-mem"
+#define TYPE_MPAM_MSC_CACHE "mpam-msc-cache"
+
+/*
+ * MMIO window of one MSC: IHI 0099 places the register block in a 16 KiB
+ * region (0x4000).  The virt board reserves a 1 MiB slot for up to 256 MSCs.
+ */
+#define MPAM_SIZE 0x4000
+
+#endif /* _MPAM_H_ */
#22 lore raw

PATCH 6/37 hw/arm/mpam: Add MPAM MSC base device

In reply to a message not in the archive

From: Jonathan Cameron <[email protected]>

Add the mpam-msc sysbus device core:
- Per-RIS register storage(Mpamf)
- The device state (selector state, num-ris/num-partid/ num-int-partid properties), realize with the per-RIS allocation and the MMIO region (MPAM_SIZE window).
- The MMIO handlers covering the identification registers (MPAMF_IDR with its 64-bit EXT view IIDR, AIDR, IMPL_IDR, PARTID_NRW_IDR and the MSMON IDRs that read as zero until monitoring is implemented).

The base type registers no features; the mpam-msc-mem and mpam-msc-cache subtypes assemble their feature IDR fields.

Based on an RFC series by Jonathan Cameron.

---
 hw/arm/mpam.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 171 insertions(+)
hw/arm/mpam.c +171 -0
index 772a120..b1d6472 100644
@@ -221,3 +221,174 @@ REG32(MPAMF_MPAMCFG_MBW_PBM0, 0x2000)
 #define MPAM_CACHE_PART 32
 /* MPAMF_IIDR.IMPLEMENTER: ARM JEP106 code for Huawei (0x736). */
 #define MPAM_IIDR_IMPLEMENTER 0x736
+
+typedef struct Mpamf {
+    uint64_t idr;
+    uint32_t iidr;
+    uint32_t aidr;
+    uint32_t impl_idr;
+    uint32_t cpor_idr;
+    uint32_t ccap_idr;
+    uint32_t mbw_idr;
+    uint32_t pri_idr;
+    uint32_t partid_nrw_idr;
+    uint32_t msmon_idr;
+    uint32_t csumon_idr;
+    uint32_t mbwumon_idr;
+    uint32_t err_msi_mpam;
+    uint32_t err_msi_addr_l;
+    uint32_t err_msi_addr_h;
+    uint32_t err_msi_data;
+    uint32_t err_msi_attr;
+    uint32_t ecr;
+    uint32_t esr;
+    uint32_t cfg_part_sel;
+} Mpamf;
+
+typedef struct MPAMMSCState {
+    SysBusDevice parent_obj;
+
+    Mpamf *mpamf;
+
+    uint8_t ris;
+    uint16_t part_sel; /* Technically per ris, but in same reg */
+    bool internal_part_sel;
+    struct MemoryRegion mr;
+    uint32_t num_partid;
+    uint32_t num_int_partid;
+    uint8_t num_ris;
+
+} MPAMMSCState;
+
+DECLARE_INSTANCE_CHECKER(MPAMMSCState, MPAM_MSC_DEVICE, TYPE_MPAM_MSC);
+
+static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
+                                  unsigned size)
+{
+    MPAMMSCState *s = MPAM_MSC_DEVICE(opaque);
+    Mpamf *mpamf = &s->mpamf[s->ris];
+
+    switch (offset) {
+    case A_MPAMF_IDR:
+        switch (size) {
+        case 4:
+            return mpamf->idr & 0xffffffff;
+        case 8:
+            return mpamf->idr;
+        default:
+            qemu_log_mask(LOG_UNIMP, "MPAM: Unexpected read size\n");
+            return 0;
+        }
+    case A_MPAMF_IDR + 0x04:
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, EXT)) {
+            qemu_log_mask(LOG_UNIMP, "MPAM: Unexpected read of top of IDR\n");
+            return 0;
+        }
+        switch (size) {
+        case 4:
+            return mpamf->idr >> 32;
+        default:
+            qemu_log_mask(LOG_UNIMP, "MPAM: Unexpected read size\n");
+            return 0;
+        }
+    case A_MPAMF_IIDR:
+        return mpamf->iidr;
+    case A_MPAMF_AIDR:
+        return mpamf->aidr;
+    case A_MPAMF_IMPL_IDR:
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_IMPL_IDR)) {
+            qemu_log_mask(LOG_UNIMP,
+                "MPAM: Accessing IMPL_IDR which isn't suported\n");
+            return 0;
+        }
+        return mpamf->impl_idr;
+    case A_MPAMF_PARTID_NRW_IDR: {
+        return mpamf->partid_nrw_idr;
+    }
+    case A_MPAMF_MSMON_IDR:
+        return mpamf->msmon_idr;
+    case A_MPAMF_CSUMON_IDR:
+        return mpamf->csumon_idr;
+    case A_MPAMF_MBWUMON_IDR:
+        return mpamf->mbwumon_idr;
+    default:
+        qemu_log_mask(LOG_UNIMP,
+                      "MPAM: Unexpected read of %lx\n", offset);
+        return 0x0;
+    }
+}
+
+static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value,
+                               unsigned size)
+{
+    switch (offset) {
+    default:
+        qemu_log_mask(LOG_UNIMP,
+                      "MPAM: Write to unexpected register Addr %lx Value=%lx\n",
+                      offset, value);
+    }
+}
+
+static const MemoryRegionOps mpam_msc_ops = {
+    .read = mpam_msc_read_reg,
+    .write = mpam_msc_write_reg,
+    .endianness = DEVICE_LITTLE_ENDIAN,
+    .valid = {
+        .min_access_size = 1,
+        .max_access_size = 8,
+        .unaligned = false,
+    },
+    .impl = {
+        .min_access_size = 1,
+        .max_access_size = 8,
+    },
+};
+
+static void mpam_msc_realize(DeviceState *dev, Error **errp)
+{
+    MPAMMSCState *s = MPAM_MSC_DEVICE(dev);
+
+    /* IHI 0099: MPAMF_CFG_PART_SEL.RIS is 4 bits, so at most 16 RIS. */
+    if (s->num_ris > 16) {
+        error_setg(errp, "num-ris must be <= 16");
+        return;
+    }
+    if (s->num_partid == 0) {
+        error_setg(errp, "num-ris must be <= 16");
+        return;
+    }
+    if (s->num_int_partid == 0) {
+        s->num_int_partid = s->num_partid;
+    }
+
+    s->mpamf = g_new0(Mpamf, s->num_ris);
+    memory_region_init_io(&s->mr, OBJECT(s), &mpam_msc_ops, s, "mpam_msc",
+                          MPAM_SIZE);
+    sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mr);
+}
+
+static const Property mpam_msc_props[] = {
+    DEFINE_PROP_UINT8("num-ris", MPAMMSCState, num_ris, 1),
+    DEFINE_PROP_UINT32("num-partid", MPAMMSCState, num_partid, 1),
+    DEFINE_PROP_UINT32("num-int-partid", MPAMMSCState, num_int_partid, 0),
+};
+
+static void mpam_msc_init(ObjectClass *klass, const void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    device_class_set_props(dc, mpam_msc_props);
+}
+
+static const TypeInfo mpam_msc_info = {
+    .name = TYPE_MPAM_MSC,
+    .parent = TYPE_SYS_BUS_DEVICE,
+    .instance_size = sizeof(MPAMMSCState),
+    .class_init = mpam_msc_init
+};
+
+static void mpam_register_types(void)
+{
+    type_register_static(&mpam_msc_info);
+}
+type_init(mpam_register_types);
Signature · 1 line
2.43.0
#23 lore raw

Re: [PATCH 06/37] hw/arm/mpam: Add MPAM MSC base device

Quoted 11 lines · On Fri, 16 Oct 2026 17:47:00 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

Add the mpam-msc sysbus device core:
- Per-RIS register storage(Mpamf)
- The device state (selector state, num-ris/num-partid/ num-int-partid properties), realize with the per-RIS allocation and the MMIO region (MPAM_SIZE window).
- The MMIO handlers covering the identification registers (MPAMF_IDR with its 64-bit EXT view IIDR, AIDR, IMPL_IDR, PARTID_NRW_IDR and the MSMON IDRs that read as zero until monitoring is implemented).

Quoted 7 lines

The base type registers no features; the mpam-msc-mem and mpam-msc-cache subtypes assemble their feature IDR fields.

Based on an RFC series by Jonathan Cameron.

A few trivial things inline.

Quoted 39 lines
---
 hw/arm/mpam.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 171 insertions(+)
hw/arm/mpam.c +27 -0
index 772a120..b1d6472 100644
@@ -221,3 +221,174 @@ REG32(MPAMF_MPAMCFG_MBW_PBM0, 0x2000)
 #define MPAM_CACHE_PART 32
 /* MPAMF_IIDR.IMPLEMENTER: ARM JEP106 code for Huawei (0x736). */
 #define MPAM_IIDR_IMPLEMENTER 0x736
+
+typedef struct Mpamf {
+    uint64_t idr;
+    uint32_t iidr;
+    uint32_t aidr;
+    uint32_t impl_idr;
+    uint32_t cpor_idr;
+    uint32_t ccap_idr;
+    uint32_t mbw_idr;
+    uint32_t pri_idr;
+    uint32_t partid_nrw_idr;
+    uint32_t msmon_idr;
+    uint32_t csumon_idr;
+    uint32_t mbwumon_idr;
+    uint32_t err_msi_mpam;
+    uint32_t err_msi_addr_l;
+    uint32_t err_msi_addr_h;
+    uint32_t err_msi_data;
+    uint32_t err_msi_attr;
+    uint32_t ecr;
+    uint32_t esr;
+    uint32_t cfg_part_sel;
+} Mpamf;
+
+typedef struct MPAMMSCState {
+    SysBusDevice parent_obj;
+

hw/arm/mpam.c REG32(MPAMF_MPAMCFG_MBW_PBM0, 0x2000) · line 260

Quoted 10 lines
hw/arm/mpam.c +10 -0
+    Mpamf *mpamf;
+
+    uint8_t ris;
+    uint16_t part_sel; /* Technically per ris, but in same reg */
+    bool internal_part_sel;
+    struct MemoryRegion mr;
+    uint32_t num_partid;
+    uint32_t num_int_partid;
+    uint8_t num_ris;
+

Blank line seems pointless. Probably belongs in some later patch.

Quoted 5 lines
hw/arm/mpam.c +5 -0
+} MPAMMSCState;
+
+DECLARE_INSTANCE_CHECKER(MPAMMSCState, MPAM_MSC_DEVICE, TYPE_MPAM_MSC);
+
+static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,

hw/arm/mpam.c REG32(MPAMF_MPAMCFG_MBW_PBM0, 0x2000) · line 275

Quoted 10 lines
hw/arm/mpam.c +10 -0
+                                  unsigned size)
+{
+    MPAMMSCState *s = MPAM_MSC_DEVICE(opaque);
+    Mpamf *mpamf = &s->mpamf[s->ris];
+
+    switch (offset) {
+    case A_MPAMF_IDR:
+        switch (size) {
+        case 4:
+            return mpamf->idr & 0xffffffff;

Maybe use MAKE_64BIT_MASK(0, 32) from qemu/bitops.h

Quoted 9 lines
hw/arm/mpam.c +9 -0
+        case 8:
+            return mpamf->idr;
+        default:
+            qemu_log_mask(LOG_UNIMP, "MPAM: Unexpected read size\n");
+            return 0;
+        }
+    case A_MPAMF_IDR + 0x04:
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, EXT)) {
+            qemu_log_mask(LOG_UNIMP, "MPAM: Unexpected read of top of IDR\n");

hw/arm/mpam.c REG32(MPAMF_MPAMCFG_MBW_PBM0, 0x2000) · line 294

Quoted 10 lines
hw/arm/mpam.c +10 -0
+            return 0;
+        }
+        switch (size) {
+        case 4:
+            return mpamf->idr >> 32;
+        default:
+            qemu_log_mask(LOG_UNIMP, "MPAM: Unexpected read size\n");
+            return 0;
+        }
+    case A_MPAMF_IIDR:

Not sure why I allowed 1 byte reads. Probably want to check each of the read widths for 4 or 8 though as appropriate.

Quoted 22 lines
hw/arm/mpam.c +22 -0
+        return mpamf->iidr;
+    case A_MPAMF_AIDR:
+        return mpamf->aidr;
+    case A_MPAMF_IMPL_IDR:
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_IMPL_IDR)) {
+            qemu_log_mask(LOG_UNIMP,
+                "MPAM: Accessing IMPL_IDR which isn't suported\n");
+            return 0;
+        }
+        return mpamf->impl_idr;
+    case A_MPAMF_PARTID_NRW_IDR: {
+        return mpamf->partid_nrw_idr;
+    }
+    case A_MPAMF_MSMON_IDR:
+        return mpamf->msmon_idr;
+    case A_MPAMF_CSUMON_IDR:
+        return mpamf->csumon_idr;
+    case A_MPAMF_MBWUMON_IDR:
+        return mpamf->mbwumon_idr;
+    default:
+        qemu_log_mask(LOG_UNIMP,
+                      "MPAM: Unexpected read of %lx\n", offset);

hw/arm/mpam.c REG32(MPAMF_MPAMCFG_MBW_PBM0, 0x2000) · line 351

Quoted 10 lines
hw/arm/mpam.c +9 -0
+        return 0x0;
+    }
+}
 
+
+static void mpam_msc_realize(DeviceState *dev, Error **errp)
+{
+    MPAMMSCState *s = MPAM_MSC_DEVICE(dev);
+
+    /* IHI 0099: MPAMF_CFG_PART_SEL.RIS is 4 bits, so at most 16 RIS. */

Hmm. I wonder if this changed name. The spec now has MPAMCFG_PART_SEL. Should match that naming I suppose.

Quoted 17 lines
hw/arm/mpam.c +17 -0
+    if (s->num_ris > 16) {
+        error_setg(errp, "num-ris must be <= 16");
+        return;
+    }
+    if (s->num_partid == 0) {
+        error_setg(errp, "num-ris must be <= 16");
+        return;
+    }
+    if (s->num_int_partid == 0) {
+        s->num_int_partid = s->num_partid;
+    }
+
+    s->mpamf = g_new0(Mpamf, s->num_ris);
+    memory_region_init_io(&s->mr, OBJECT(s), &mpam_msc_ops, s, "mpam_msc",
+                          MPAM_SIZE);
+    sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mr);
+}
#24 lore raw

PATCH 7/37 hw/arm/mpam: Add mpam-msc-mem memory-side MSC subtype

In reply to a message not in the archive

From: Jonathan Cameron <[email protected]>

Add the mpam-msc-mem subtype for memory-side components. Its realize assembles the identity view of MPAMF_IDR (PARTID space, optional RIS support, HAS_ESR/HAS_EXTD_ESR, HAS_PARTID_NRW when the internal PARTID space is smaller) plus IIDR/AIDR, and advertises no partitioning features yet: the bandwidth controls come with the MBW patch.

Based on an RFC series by Jonathan Cameron.

---
 hw/arm/mpam.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
hw/arm/mpam.c +68 -0
index b1d6472..8a85c3b 100644
@@ -260,8 +260,15 @@ typedef struct MPAMMSCState {
 
 } MPAMMSCState;
 
+typedef struct MPAMMSCMemState {
+    MPAMMSCState parent;
+} MPAMMSCMemState;
+
 DECLARE_INSTANCE_CHECKER(MPAMMSCState, MPAM_MSC_DEVICE, TYPE_MPAM_MSC);
 
+DECLARE_INSTANCE_CHECKER(MPAMMSCMemState, MPAM_MSC_MEM_DEVICE,
+                         TYPE_MPAM_MSC_MEM);
+
 static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
                                   unsigned size)
 {
@@ -367,6 +374,52 @@ static void mpam_msc_realize(DeviceState *dev, Error **errp)
     sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mr);
 }
 
+static void mpam_msc_mem_realize(DeviceState *dev, Error **errp)
+{    MPAMMSCState *s = MPAM_MSC_DEVICE(dev);
+    int i;
+
+    mpam_msc_realize(dev, errp);
+
+    for (i = 0; i < s->num_ris; i++) {
+        Mpamf *mpamf = &s->mpamf[i];
+
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, PART_ID_MAX,
+                                s->num_partid - 1);
+        /* No PCMG for now */
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, PMG_MAX, 0);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, EXT, 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_RIS, s->num_ris > 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, RIS_MAX,
+                                  s->num_ris > 1 ? s->num_ris - 1 : 0);
+         /* Optional - test with and without */
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_ESR, 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_EXTD_ESR, 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_PARTID_NRW,
+                                s->num_int_partid < s->num_partid);
+
+        /* We won't implement any implementation specific stuff */
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, NO_IMPL_PART, 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, NO_IMPL_MSMON, 1);
+
+        mpamf->iidr = FIELD_DP64(mpamf->iidr, MPAMF_IIDR, IMPLEMENTER,
+                                 MPAM_IIDR_IMPLEMENTER);
+        mpamf->iidr = FIELD_DP64(mpamf->iidr, MPAMF_IIDR, REVISION, 0);
+        mpamf->iidr = FIELD_DP64(mpamf->iidr, MPAMF_IIDR, VARIANT, 0);
+        /* FIXME get allocation for this emulation */
+        mpamf->iidr = FIELD_DP64(mpamf->iidr, MPAMF_IIDR, PRODUCT_ID, 42);
+
+        mpamf->aidr = FIELD_DP64(mpamf->aidr, MPAMF_AIDR, ARCH_MINOR_REV, 1);
+        mpamf->aidr = FIELD_DP64(mpamf->aidr, MPAMF_AIDR, ARCH_MAJOR_REV, 1);
+
+        if (s->num_int_partid < s->num_partid) {
+            mpamf->partid_nrw_idr = FIELD_DP32(mpamf->partid_nrw_idr,
+                                               MPAMF_PARTID_NRW_IDR,
+                                               INTPARTID_MAX,
+                                               s->num_int_partid - 1);
+        }
+    }
+}
+
 static const Property mpam_msc_props[] = {
     DEFINE_PROP_UINT8("num-ris", MPAMMSCState, num_ris, 1),
     DEFINE_PROP_UINT32("num-partid", MPAMMSCState, num_partid, 1),
@@ -380,6 +433,13 @@ static void mpam_msc_init(ObjectClass *klass, const void *data)
     device_class_set_props(dc, mpam_msc_props);
 }
 
+static void mpam_msc_mem_init(ObjectClass *klass, const void *data)
+{
+    DeviceClass *dc = DEVICE_CLASS(klass);
+
+    dc->realize = mpam_msc_mem_realize;
+}
+
 static const TypeInfo mpam_msc_info = {
     .name = TYPE_MPAM_MSC,
     .parent = TYPE_SYS_BUS_DEVICE,
@@ -387,8 +447,16 @@ static const TypeInfo mpam_msc_info = {
     .class_init = mpam_msc_init
 };
 
+static const TypeInfo mpam_msc_mem_info = {
+    .name = TYPE_MPAM_MSC_MEM,
+    .parent = TYPE_MPAM_MSC,
+    .instance_size = sizeof(MPAMMSCMemState),
+    .class_init = mpam_msc_mem_init
+};
+
 static void mpam_register_types(void)
 {
     type_register_static(&mpam_msc_info);
+    type_register_static(&mpam_msc_mem_info);
 }
 type_init(mpam_register_types);
Signature · 1 line
2.43.0
#25 lore raw

Re: [PATCH 07/37] hw/arm/mpam: Add mpam-msc-mem memory-side MSC subtype

Quoted 9 lines · On Fri, 16 Oct 2026 17:47:01 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

Add the mpam-msc-mem subtype for memory-side components. Its realize assembles the identity view of MPAMF_IDR (PARTID space, optional RIS support, HAS_ESR/HAS_EXTD_ESR, HAS_PARTID_NRW when the internal PARTID space is smaller) plus IIDR/AIDR, and advertises no partitioning features yet: the bandwidth controls come with the MBW patch.

Quoted 4 lines

Based on an RFC series by Jonathan Cameron.

Just some minor comments, mostly about comments I left lying around that I now don't see any purpose in keeping.

Quoted 25 lines
---
 hw/arm/mpam.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
hw/arm/mpam.c +7 -0
index b1d6472..8a85c3b 100644
@@ -260,8 +260,15 @@ typedef struct MPAMMSCState {
 
 } MPAMMSCState;
 
+typedef struct MPAMMSCMemState {
+    MPAMMSCState parent;
+} MPAMMSCMemState;
+
 DECLARE_INSTANCE_CHECKER(MPAMMSCState, MPAM_MSC_DEVICE, TYPE_MPAM_MSC);
 
+DECLARE_INSTANCE_CHECKER(MPAMMSCMemState, MPAM_MSC_MEM_DEVICE,
+                         TYPE_MPAM_MSC_MEM);
+
 static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
                                   unsigned size)
 {

hw/arm/mpam.c static void mpam_msc_realize(DeviceState *dev, Error **errp) · line 383

Quoted 10 lines
hw/arm/mpam.c +7 -0
@@ -367,6 +374,52 @@ static void mpam_msc_realize(DeviceState *dev, Error **errp)
     sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mr);
 }
 
+static void mpam_msc_mem_realize(DeviceState *dev, Error **errp)
+{    MPAMMSCState *s = MPAM_MSC_DEVICE(dev);
+    int i;
+
+    mpam_msc_realize(dev, errp);
+
+    for (i = 0; i < s->num_ris; i++) {
    for (int i = 0; ..

hw/arm/mpam.c static void mpam_msc_realize(DeviceState *dev, Error **errp) · line 390

Quoted 7 lines
hw/arm/mpam.c +7 -0
+        Mpamf *mpamf = &s->mpamf[i];
+
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, PART_ID_MAX,
+                                s->num_partid - 1);
+        /* No PCMG for now */
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, PMG_MAX, 0);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, EXT, 1);

I guess if being flexible this would emulate with and without EXT, but meh, not sure it adds much value.

hw/arm/mpam.c static void mpam_msc_realize(DeviceState *dev, Error **errp) · line 394

Quoted 4 lines
hw/arm/mpam.c +4 -0
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_RIS, s->num_ris > 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, RIS_MAX,
+                                  s->num_ris > 1 ? s->num_ris - 1 : 0);
+         /* Optional - test with and without */

Should drop that comment, or add the ability to test with and without
- honestly I'm not sure which field that was even referring too as kind of applies to all the HAS_ ones.

Quoted 4 lines
hw/arm/mpam.c +4 -0
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_ESR, 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_EXTD_ESR, 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_PARTID_NRW,
+                                s->num_int_partid < s->num_partid);

hw/arm/mpam.c static void mpam_msc_realize(DeviceState *dev, Error **errp) · line 408

Quoted 10 lines
hw/arm/mpam.c +10 -0
+
+        /* We won't implement any implementation specific stuff */
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, NO_IMPL_PART, 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, NO_IMPL_MSMON, 1);
+
+        mpamf->iidr = FIELD_DP64(mpamf->iidr, MPAMF_IIDR, IMPLEMENTER,
+                                 MPAM_IIDR_IMPLEMENTER);
+        mpamf->iidr = FIELD_DP64(mpamf->iidr, MPAMF_IIDR, REVISION, 0);
+        mpamf->iidr = FIELD_DP64(mpamf->iidr, MPAMF_IIDR, VARIANT, 0);
+        /* FIXME get allocation for this emulation */

That still needs fixing before this can be merged. If sticking to Hisilicon implementer, need to get one set aside so it is never real hardware - just in case we run into problems.

Or... Use implementer 0 which is reserved for software use on CPUs and hence I assume is fine here? Maybe then set the product ID to 'Q' like the gicv2m emulation does?

hw/arm/mpam.c static void mpam_msc_realize(DeviceState *dev, Error **errp) · line 409

Quoted 1 line
hw/arm/mpam.c +1 -0
+        mpamf->iidr = FIELD_DP64(mpamf->iidr, MPAMF_IIDR, PRODUCT_ID, 42);

:) I was clearly having one of those sorts of days.

Quoted 12 lines
hw/arm/mpam.c +12 -0
+
+        mpamf->aidr = FIELD_DP64(mpamf->aidr, MPAMF_AIDR, ARCH_MINOR_REV, 1);
+        mpamf->aidr = FIELD_DP64(mpamf->aidr, MPAMF_AIDR, ARCH_MAJOR_REV, 1);
+
+        if (s->num_int_partid < s->num_partid) {
+            mpamf->partid_nrw_idr = FIELD_DP32(mpamf->partid_nrw_idr,
+                                               MPAMF_PARTID_NRW_IDR,
+                                               INTPARTID_MAX,
+                                               s->num_int_partid - 1);
+        }
+    }
+}
#26 lore raw

PATCH 8/37 hw/arm/mpam: Add mpam-msc-cache MSC subtype

In reply to a message not in the archive

From: Jonathan Cameron <[email protected]>

Add the mpam-msc-cache subtype for cache components, with the cache-level/cache-type/cpu properties the board uses to place the MSC in the cache topology. Its realize assembles the cache identity view of MPAMF_IDR (same as the memory side, plus SP4=0 for RME) and IIDR/AIDR; the CPOR/CCAP/PRI feature bits arrive with their respective partitioning patches.

Based on an RFC series by Jonathan Cameron.

---
 hw/arm/mpam.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
hw/arm/mpam.c +87 -0
index 8a85c3b..17ca286 100644
@@ -264,11 +264,22 @@ typedef struct MPAMMSCMemState {
     MPAMMSCState parent;
 } MPAMMSCMemState;
 
+typedef struct MPAMMSCCacheState {
+    MPAMMSCState parent;
+    uint8_t cache_level;
+    uint8_t cache_type;
+    uint16_t cpu;
+
+} MPAMMSCCacheState;
+
 DECLARE_INSTANCE_CHECKER(MPAMMSCState, MPAM_MSC_DEVICE, TYPE_MPAM_MSC);
 
 DECLARE_INSTANCE_CHECKER(MPAMMSCMemState, MPAM_MSC_MEM_DEVICE,
                          TYPE_MPAM_MSC_MEM);
 
+DECLARE_INSTANCE_CHECKER(MPAMMSCCacheState, MPAM_MSC_CACHE_DEVICE,
+                         TYPE_MPAM_MSC_CACHE);
+
 static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
                                   unsigned size)
 {
@@ -420,12 +431,72 @@ static void mpam_msc_mem_realize(DeviceState *dev, Error **errp)
     }
 }
 
+static void mpam_msc_cache_realize(DeviceState *dev, Error **errp)
+{
+    MPAMMSCState *s = MPAM_MSC_DEVICE(dev);
+    int i;
+
+    mpam_msc_realize(dev, errp);
+
+    for (i = 0; i < s->num_ris; i++) {
+        Mpamf *mpamf = &s->mpamf[i];
+
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, PART_ID_MAX,
+                                s->num_partid - 1);
+        /* No PCMG for now */
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, PMG_MAX, 0);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, EXT, 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_RIS, s->num_ris > 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, RIS_MAX,
+                                  s->num_ris > 1 ? s->num_ris - 1 : 0);
+
+        /* Optional - test with and without */
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_ESR, 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_EXTD_ESR,
+                                s->num_ris > 1);
+
+        /* We won't implement any implementation specific stuff */
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, NO_IMPL_PART, 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, NO_IMPL_MSMON, 1);
+
+        /* Need to implement for RME */
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, SP4, 0);
+
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_PARTID_NRW,
+                                s->num_int_partid < s->num_partid);
+
+        mpamf->iidr = FIELD_DP32(mpamf->iidr, MPAMF_IIDR, IMPLEMENTER,
+                                 MPAM_IIDR_IMPLEMENTER);
+        mpamf->iidr = FIELD_DP32(mpamf->iidr, MPAMF_IIDR, REVISION, 0);
+        mpamf->iidr = FIELD_DP32(mpamf->iidr, MPAMF_IIDR, VARIANT, 0);
+        /* FIXME get allocation for this emulation */
+        mpamf->iidr = FIELD_DP32(mpamf->iidr, MPAMF_IIDR, PRODUCT_ID, 42);
+
+        mpamf->aidr = FIELD_DP32(mpamf->aidr, MPAMF_AIDR, ARCH_MINOR_REV, 1);
+        mpamf->aidr = FIELD_DP32(mpamf->aidr, MPAMF_AIDR, ARCH_MAJOR_REV, 1);
+
+        if (s->num_int_partid < s->num_partid) {
+            mpamf->partid_nrw_idr = FIELD_DP32(mpamf->partid_nrw_idr,
+                                               MPAMF_PARTID_NRW_IDR,
+                                               INTPARTID_MAX,
+                                               s->num_int_partid - 1);
+        }
+        /* TODO: Initialize all on as if firmware had done it for us */
+    }
+}
+
 static const Property mpam_msc_props[] = {
     DEFINE_PROP_UINT8("num-ris", MPAMMSCState, num_ris, 1),
     DEFINE_PROP_UINT32("num-partid", MPAMMSCState, num_partid, 1),
     DEFINE_PROP_UINT32("num-int-partid", MPAMMSCState, num_int_partid, 0),
 };
 
+static const Property mpam_msc_cache_props[] = {
+    DEFINE_PROP_UINT8("cache-level", MPAMMSCCacheState, cache_level, 1),
+    DEFINE_PROP_UINT8("cache-type", MPAMMSCCacheState, cache_type, 1),
+    DEFINE_PROP_UINT16("cpu", MPAMMSCCacheState, cpu, 2),
+};
+
 static void mpam_msc_init(ObjectClass *klass, const void *data)
 {
     DeviceClass *dc = DEVICE_CLASS(klass);
@@ -440,6 +511,14 @@ static void mpam_msc_mem_init(ObjectClass *klass, const void *data)
     dc->realize = mpam_msc_mem_realize;
 }
 
+static void mpam_msc_cache_init(ObjectClass *klass, const void *data)
+{
+   DeviceClass *dc = DEVICE_CLASS(klass);
+
+   dc->realize = mpam_msc_cache_realize;
+   device_class_set_props(dc, mpam_msc_cache_props);
+}
+
 static const TypeInfo mpam_msc_info = {
     .name = TYPE_MPAM_MSC,
     .parent = TYPE_SYS_BUS_DEVICE,
@@ -454,9 +533,17 @@ static const TypeInfo mpam_msc_mem_info = {
     .class_init = mpam_msc_mem_init
 };
 
+static const TypeInfo mpam_msc_cache_info = {
+    .name = TYPE_MPAM_MSC_CACHE,
+    .parent = TYPE_MPAM_MSC,
+    .instance_size = sizeof(MPAMMSCCacheState),
+    .class_init = mpam_msc_cache_init
+};
+
 static void mpam_register_types(void)
 {
     type_register_static(&mpam_msc_info);
     type_register_static(&mpam_msc_mem_info);
+    type_register_static(&mpam_msc_cache_info);
 }
 type_init(mpam_register_types);
Signature · 1 line
2.43.0
#27 lore raw

Re: [PATCH 08/37] hw/arm/mpam: Add mpam-msc-cache MSC subtype

Quoted 9 lines · On Fri, 16 Oct 2026 17:47:02 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jonathan Cameron <[email protected]>

Add the mpam-msc-cache subtype for cache components, with the cache-level/cache-type/cpu properties the board uses to place the MSC in the cache topology. Its realize assembles the cache identity view of MPAMF_IDR (same as the memory side, plus SP4=0 for RME) and IIDR/AIDR; the CPOR/CCAP/PRI feature bits arrive with their respective partitioning patches.

Quoted 4 lines

Based on an RFC series by Jonathan Cameron.

Very similar comments to previous as you might expect.

Quoted 33 lines
---
 hw/arm/mpam.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 87 insertions(+)
hw/arm/mpam.c +11 -0
index 8a85c3b..17ca286 100644
@@ -264,11 +264,22 @@ typedef struct MPAMMSCMemState {
     MPAMMSCState parent;
 } MPAMMSCMemState;
 
+typedef struct MPAMMSCCacheState {
+    MPAMMSCState parent;
+    uint8_t cache_level;
+    uint8_t cache_type;
+    uint16_t cpu;
+
+} MPAMMSCCacheState;
+
 DECLARE_INSTANCE_CHECKER(MPAMMSCState, MPAM_MSC_DEVICE, TYPE_MPAM_MSC);
 
 DECLARE_INSTANCE_CHECKER(MPAMMSCMemState, MPAM_MSC_MEM_DEVICE,
                          TYPE_MPAM_MSC_MEM);
 
+DECLARE_INSTANCE_CHECKER(MPAMMSCCacheState, MPAM_MSC_CACHE_DEVICE,
+                         TYPE_MPAM_MSC_CACHE);
+
 static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
                                   unsigned size)
 {
@@ -420,12 +431,72 @@ static void mpam_msc_mem_realize(DeviceState *dev, Error **errp)
     }

hw/arm/mpam.c static void mpam_msc_mem_realize(DeviceState *dev, Error **errp) · line 441

Quoted 10 lines
hw/arm/mpam.c +8 -0
 }
 
+static void mpam_msc_cache_realize(DeviceState *dev, Error **errp)
+{
+    MPAMMSCState *s = MPAM_MSC_DEVICE(dev);
+    int i;
+
+    mpam_msc_realize(dev, errp);
+
+    for (i = 0; i < s->num_ris; i++) {
    for (int i = 0;...

hw/arm/mpam.c static void mpam_msc_mem_realize(DeviceState *dev, Error **errp) · line 453

Quoted 12 lines
hw/arm/mpam.c +12 -0
+        Mpamf *mpamf = &s->mpamf[i];
+
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, PART_ID_MAX,
+                                s->num_partid - 1);
+        /* No PCMG for now */
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, PMG_MAX, 0);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, EXT, 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_RIS, s->num_ris > 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, RIS_MAX,
+                                  s->num_ris > 1 ? s->num_ris - 1 : 0);
+
+        /* Optional - test with and without */

Same as before.

Quoted 9 lines
hw/arm/mpam.c +9 -0
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_ESR, 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_EXTD_ESR,
+                                s->num_ris > 1);
+
+        /* We won't implement any implementation specific stuff */
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, NO_IMPL_PART, 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, NO_IMPL_MSMON, 1);
+
+        /* Need to implement for RME */

hw/arm/mpam.c static void mpam_msc_mem_realize(DeviceState *dev, Error **errp) · line 472

Quoted 10 lines
hw/arm/mpam.c +10 -0
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, SP4, 0);
+
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_PARTID_NRW,
+                                s->num_int_partid < s->num_partid);
+
+        mpamf->iidr = FIELD_DP32(mpamf->iidr, MPAMF_IIDR, IMPLEMENTER,
+                                 MPAM_IIDR_IMPLEMENTER);
+        mpamf->iidr = FIELD_DP32(mpamf->iidr, MPAMF_IIDR, REVISION, 0);
+        mpamf->iidr = FIELD_DP32(mpamf->iidr, MPAMF_IIDR, VARIANT, 0);
+        /* FIXME get allocation for this emulation */

Follow through from previous.

Quoted 14 lines
hw/arm/mpam.c +14 -0
+        mpamf->iidr = FIELD_DP32(mpamf->iidr, MPAMF_IIDR, PRODUCT_ID, 42);
+
+        mpamf->aidr = FIELD_DP32(mpamf->aidr, MPAMF_AIDR, ARCH_MINOR_REV, 1);
+        mpamf->aidr = FIELD_DP32(mpamf->aidr, MPAMF_AIDR, ARCH_MAJOR_REV, 1);
+
+        if (s->num_int_partid < s->num_partid) {
+            mpamf->partid_nrw_idr = FIELD_DP32(mpamf->partid_nrw_idr,
+                                               MPAMF_PARTID_NRW_IDR,
+                                               INTPARTID_MAX,
+                                               s->num_int_partid - 1);
+        }
+        /* TODO: Initialize all on as if firmware had done it for us */
+    }
+}
#28 lore raw

PATCH 9/37 hw/arm/mpam: Handle MPAMCFG_PART_SEL selection

In reply to a message not in the archive

From: Jinjie Ruan <[email protected]>

Add read/write handling for the MPAMCFG_PART_SEL selector: the RIS field switches the per-RIS register bank (rejecting RIS values beyond num-ris, and nonzero RIS on an MSC without RIS support), and PARTID_SEL/INTERNAL record the selected partition for the configuration registers. Writes are stored per RIS so the selector reads back as written.

---
 hw/arm/mpam.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
hw/arm/mpam.c +32 -0
index 17ca286..c21a737 100644
@@ -329,6 +329,8 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
         return mpamf->csumon_idr;
     case A_MPAMF_MBWUMON_IDR:
         return mpamf->mbwumon_idr;
+    case A_MPAMF_CFG_PART_SEL:
+        return mpamf->cfg_part_sel;
     default:
         qemu_log_mask(LOG_UNIMP,
                       "MPAM: Unexpected read of %lx\n", offset);
@@ -339,7 +341,37 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
 static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value,
                                unsigned size)
 {
+    MPAMMSCState *s = MPAM_MSC_DEVICE(opaque);
+    /* Update in the ris setting path */
+    Mpamf *mpamf = &s->mpamf[s->ris];
+
     switch (offset) {
+    case A_MPAMF_CFG_PART_SEL:
+        if (value & ~MPAMF_CFG_PART_SEL_WRITE_MASK) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write to CFG_PART_SEL Mask=%x Value=%lx\n",
+                          MPAMF_CFG_PART_SEL_WRITE_MASK, value);
+        }
+        /* Field matches for all RIS */
+        if (!FIELD_EX64(mpamf->idr, MPAMF_IDR, HAS_RIS) &&
+            FIELD_EX32(value, MPAMF_CFG_PART_SEL, RIS) != 0) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write of non 0 RIS on MSC with !HAS_RIS\n");
+            return;
+        }
+        if (FIELD_EX32(value, MPAMF_CFG_PART_SEL, RIS) >= s->num_ris) {
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "MPAM: RIS %d out of range (num-ris %d)\n",
+                          FIELD_EX32(value, MPAMF_CFG_PART_SEL, RIS),
+                          s->num_ris);
+            return;
+        }
+        s->ris = FIELD_EX32(value, MPAMF_CFG_PART_SEL, RIS);
+        s->part_sel = FIELD_EX32(value, MPAMF_CFG_PART_SEL, PARTID_SEL);
+        s->internal_part_sel = FIELD_EX32(value, MPAMF_CFG_PART_SEL, INTERNAL);
+        mpamf = &s->mpamf[s->ris];
+        mpamf->cfg_part_sel = value;
+        return;
     default:
         qemu_log_mask(LOG_UNIMP,
                       "MPAM: Write to unexpected register Addr %lx Value=%lx\n",
Signature · 1 line
2.43.0
Reviewed-by on v1 9/37
#29 lore raw

Re: [PATCH 09/37] hw/arm/mpam: Handle MPAMCFG_PART_SEL selection

Quoted 8 lines · On Fri, 16 Oct 2026 17:47:03 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jinjie Ruan <[email protected]>

Add read/write handling for the MPAMCFG_PART_SEL selector: the RIS field switches the per-RIS register bank (rejecting RIS values beyond num-ris, and nonzero RIS on an MSC without RIS support), and PARTID_SEL/INTERNAL record the selected partition for the configuration registers. Writes are stored per RIS so the selector reads back as written.

For all these patches, the commit message wrap seems a touch short. Probably wrap at 75ish.

Otherwise a suggestion inline.

With that

Quoted 39 lines
---
 hw/arm/mpam.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
hw/arm/mpam.c +17 -0
index 17ca286..c21a737 100644
@@ -329,6 +329,8 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
         return mpamf->csumon_idr;
     case A_MPAMF_MBWUMON_IDR:
         return mpamf->mbwumon_idr;
+    case A_MPAMF_CFG_PART_SEL:
+        return mpamf->cfg_part_sel;
     default:
         qemu_log_mask(LOG_UNIMP,
                       "MPAM: Unexpected read of %lx\n", offset);
@@ -339,7 +341,37 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
 static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value,
                                unsigned size)
 {
+    MPAMMSCState *s = MPAM_MSC_DEVICE(opaque);
+    /* Update in the ris setting path */
+    Mpamf *mpamf = &s->mpamf[s->ris];
+
     switch (offset) {
+    case A_MPAMF_CFG_PART_SEL:
+        if (value & ~MPAMF_CFG_PART_SEL_WRITE_MASK) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write to CFG_PART_SEL Mask=%x Value=%lx\n",
+                          MPAMF_CFG_PART_SEL_WRITE_MASK, value);
+        }
+        /* Field matches for all RIS */
+        if (!FIELD_EX64(mpamf->idr, MPAMF_IDR, HAS_RIS) &&
+            FIELD_EX32(value, MPAMF_CFG_PART_SEL, RIS) != 0) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write of non 0 RIS on MSC with !HAS_RIS\n");

hw/arm/mpam.c static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset, · line 369

Quoted 10 lines
hw/arm/mpam.c +10 -0
+            return;
+        }
+        if (FIELD_EX32(value, MPAMF_CFG_PART_SEL, RIS) >= s->num_ris) {
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "MPAM: RIS %d out of range (num-ris %d)\n",
+                          FIELD_EX32(value, MPAMF_CFG_PART_SEL, RIS),
+                          s->num_ris);
+            return;
+        }
+        s->ris = FIELD_EX32(value, MPAMF_CFG_PART_SEL, RIS);

It seems like this is reused a fair bit above. Perhaps put it in a local variable.

      ris = FIELD_EX32(value, MPAMF_CFG_PART_SEL, RIS);
and then here
      s->ris = ris;
Quoted 8 lines
hw/arm/mpam.c +5 -0
+        s->part_sel = FIELD_EX32(value, MPAMF_CFG_PART_SEL, PARTID_SEL);
+        s->internal_part_sel = FIELD_EX32(value, MPAMF_CFG_PART_SEL, INTERNAL);
+        mpamf = &s->mpamf[s->ris];
+        mpamf->cfg_part_sel = value;
+        return;
     default:
         qemu_log_mask(LOG_UNIMP,
                       "MPAM: Write to unexpected register Addr %lx Value=%lx\n",
#30 lore raw

Re: [PATCH 09/37] hw/arm/mpam: Handle MPAMCFG_PART_SEL selection

Quoted 12 lines · Jonathan Cameron
Quoted 8 lines · On Fri, 16 Oct 2026 17:47:03 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jinjie Ruan <[email protected]>

Add read/write handling for the MPAMCFG_PART_SEL selector: the RIS field switches the per-RIS register bank (rejecting RIS values beyond num-ris, and nonzero RIS on an MSC without RIS support), and PARTID_SEL/INTERNAL record the selected partition for the configuration registers. Writes are stored per RIS so the selector reads back as written.

Quoted 2 lines

For all these patches, the commit message wrap seems a touch short. Probably wrap at 75ish.

Hi Jonathan,

Thank you for the review. Will make it wrap at 75ish.

Quoted 58 lines

Otherwise a suggestion inline.

With that

Quoted 39 lines
---
 hw/arm/mpam.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)
hw/arm/mpam.c +17 -0
index 17ca286..c21a737 100644
@@ -329,6 +329,8 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
         return mpamf->csumon_idr;
     case A_MPAMF_MBWUMON_IDR:
         return mpamf->mbwumon_idr;
+    case A_MPAMF_CFG_PART_SEL:
+        return mpamf->cfg_part_sel;
     default:
         qemu_log_mask(LOG_UNIMP,
                       "MPAM: Unexpected read of %lx\n", offset);
@@ -339,7 +341,37 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
 static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value,
                                unsigned size)
 {
+    MPAMMSCState *s = MPAM_MSC_DEVICE(opaque);
+    /* Update in the ris setting path */
+    Mpamf *mpamf = &s->mpamf[s->ris];
+
     switch (offset) {
+    case A_MPAMF_CFG_PART_SEL:
+        if (value & ~MPAMF_CFG_PART_SEL_WRITE_MASK) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write to CFG_PART_SEL Mask=%x Value=%lx\n",
+                          MPAMF_CFG_PART_SEL_WRITE_MASK, value);
+        }
+        /* Field matches for all RIS */
+        if (!FIELD_EX64(mpamf->idr, MPAMF_IDR, HAS_RIS) &&
+            FIELD_EX32(value, MPAMF_CFG_PART_SEL, RIS) != 0) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write of non 0 RIS on MSC with !HAS_RIS\n");

hw/arm/mpam.c static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset, · line 369

Quoted 10 lines
hw/arm/mpam.c +10 -0
+            return;
+        }
+        if (FIELD_EX32(value, MPAMF_CFG_PART_SEL, RIS) >= s->num_ris) {
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "MPAM: RIS %d out of range (num-ris %d)\n",
+                          FIELD_EX32(value, MPAMF_CFG_PART_SEL, RIS),
+                          s->num_ris);
+            return;
+        }
+        s->ris = FIELD_EX32(value, MPAMF_CFG_PART_SEL, RIS);

It seems like this is reused a fair bit above. Perhaps put it in a local variable.

Quoted 3 lines
      ris = FIELD_EX32(value, MPAMF_CFG_PART_SEL, RIS);
and then here
      s->ris = ris;

Will reuse it, thank you very much!

Quoted 10 lines
Quoted 9 lines
hw/arm/mpam.c +5 -0
+        s->part_sel = FIELD_EX32(value, MPAMF_CFG_PART_SEL, PARTID_SEL);
+        s->internal_part_sel = FIELD_EX32(value, MPAMF_CFG_PART_SEL, INTERNAL);
+        mpamf = &s->mpamf[s->ris];
+        mpamf->cfg_part_sel = value;
+        return;
     default:
         qemu_log_mask(LOG_UNIMP,
                       "MPAM: Write to unexpected register Addr %lx Value=%lx\n",
Signature · 2 lines
Best regards,
Jinjie
#31 lore raw

PATCH 10/37 hw/arm/mpam: Add per-RIS partition config storage

In reply to a message not in the archive

From: Jinjie Ruan <[email protected]>

Add the per-internal-PARTID configuration storage: MpamfPerNrwId holds every partition's CPBM bitmap, bandwidth, priority and capacity settings, allocated per RIS at realize together with the request-to-internal PARTID indirection table. mpam_get_nrw_id() resolves the currently selected partition for the configuration register accesses: with INTERNAL selection the selector addresses the internal PARTID space directly, otherwise the indirection table maps the request PARTID.

---
 hw/arm/mpam.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 44 insertions(+)
hw/arm/mpam.c +44 -0
index c21a737..cce9355 100644
@@ -222,6 +222,16 @@ REG32(MPAMF_MPAMCFG_MBW_PBM0, 0x2000)
 /* MPAMF_IIDR.IMPLEMENTER: ARM JEP106 code for Huawei (0x736). */
 #define MPAM_IIDR_IMPLEMENTER 0x736
 
+typedef struct MpamfPerNrwId {
+        uint32_t cfg_cpbm[(MPAM_CACHE_PART + 31) / 32];
+        uint32_t cfg_mbw_pbm[(MPAM_MBW_PART + 31) / 32];
+        uint32_t cfg_pri;
+        uint32_t cfg_cmax;
+        uint32_t cfg_mbw_min;
+        uint32_t cfg_mbw_max;
+        uint32_t cfg_mbw_prop;
+} MpamfPerNrwId;
+
 typedef struct Mpamf {
     uint64_t idr;
     uint32_t iidr;
@@ -243,6 +253,10 @@ typedef struct Mpamf {
     uint32_t ecr;
     uint32_t esr;
     uint32_t cfg_part_sel;
+    uint32_t *cfg_intpartid;
+
+    MpamfPerNrwId *per_nrw_id;
+
 } Mpamf;
 
 typedef struct MPAMMSCState {
@@ -260,6 +274,27 @@ typedef struct MPAMMSCState {
 
 } MPAMMSCState;
 
+/*
+ * ID narrowing may be in effect.  If it is there is an indirection
+ * table per RIS mapping from part_sel to the internal ID. To make things
+ * more complex, the Partition selection register can directly address
+ * internal IDs. That works for everything other than the ID map itself.
+ * This function pulls the right internal ID out of this complexity
+ * for use in accessing the per_nrw_id structures.
+ */
+static uint32_t mpam_get_nrw_id(MPAMMSCState *s)
+{
+    Mpamf *mpamf = &s->mpamf[s->ris];
+
+    if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_PARTID_NRW)) {
+        return s->part_sel;
+    }
+    if (s->internal_part_sel) {
+        return s->part_sel;
+    }
+    return mpamf->cfg_intpartid[s->part_sel];
+}
+
 typedef struct MPAMMSCMemState {
     MPAMMSCState parent;
 } MPAMMSCMemState;
@@ -285,6 +320,7 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
 {
     MPAMMSCState *s = MPAM_MSC_DEVICE(opaque);
     Mpamf *mpamf = &s->mpamf[s->ris];
+    uint32_t nrw_part_sel = mpam_get_nrw_id(s);
 
     switch (offset) {
     case A_MPAMF_IDR:
@@ -344,6 +380,8 @@ static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value,
     MPAMMSCState *s = MPAM_MSC_DEVICE(opaque);
     /* Update in the ris setting path */
     Mpamf *mpamf = &s->mpamf[s->ris];
+    /* Update if cfg_intpartid being touched */
+    uint32_t nrw_part_sel = mpam_get_nrw_id(s);
 
     switch (offset) {
     case A_MPAMF_CFG_PART_SEL:
@@ -397,6 +435,7 @@ static const MemoryRegionOps mpam_msc_ops = {
 static void mpam_msc_realize(DeviceState *dev, Error **errp)
 {
     MPAMMSCState *s = MPAM_MSC_DEVICE(dev);
+    int i;
 
     /* IHI 0099: MPAMF_CFG_PART_SEL.RIS is 4 bits, so at most 16 RIS. */
     if (s->num_ris > 16) {
@@ -412,6 +451,11 @@ static void mpam_msc_realize(DeviceState *dev, Error **errp)
     }
 
     s->mpamf = g_new0(Mpamf, s->num_ris);
+    for (i = 0; i < s->num_ris; i++) {
+        s->mpamf[i].per_nrw_id = g_new0(MpamfPerNrwId, s->num_int_partid);
+        s->mpamf[i].cfg_intpartid = g_new0(uint32_t, s->num_partid);
+    }
+
     memory_region_init_io(&s->mr, OBJECT(s), &mpam_msc_ops, s, "mpam_msc",
                           MPAM_SIZE);
     sysbus_init_mmio(SYS_BUS_DEVICE(dev), &s->mr);
Signature · 1 line
2.43.0
Reviewed-by on v1 10/37
#32 lore raw

Re: [PATCH 10/37] hw/arm/mpam: Add per-RIS partition config storage

Quoted 11 lines · On Fri, 16 Oct 2026 17:47:04 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jinjie Ruan <[email protected]>

Add the per-internal-PARTID configuration storage: MpamfPerNrwId holds every partition's CPBM bitmap, bandwidth, priority and capacity settings, allocated per RIS at realize together with the request-to-internal PARTID indirection table. mpam_get_nrw_id() resolves the currently selected partition for the configuration register accesses: with INTERNAL selection the selector addresses the internal PARTID space directly, otherwise the indirection table maps the request PARTID.

Quoted 1 line
#33 lore raw

PATCH 11/37 hw/arm/mpam: Implement CPOR cache portion partitioning

In reply to a message not in the archive

From: Jinjie Ruan <[email protected]>

Add the cache-portion controls: MPAMF_CPOR_IDR advertises the CPBM bitmap width (MPAM_CACHE_PART portions) and the cache subtype sets HAS_CPOR_PART, and the CPBM array registers become readable and writable per selected internal PARTID. Reads and writes of CPOR_IDR/CPBM on an MSC without CPOR support are logged and ignored.

---
 hw/arm/mpam.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
hw/arm/mpam.c +41 -0
index cce9355..2b1401e 100644
@@ -356,6 +356,13 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
             return 0;
         }
         return mpamf->impl_idr;
+    case A_MPAMF_CPOR_IDR:
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_CPOR_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                "MPAM: Unexpected read of CPOR_IDR with no CPOR support\n");
+            return 0;
+        }
+        return mpamf->cpor_idr;
     case A_MPAMF_PARTID_NRW_IDR: {
         return mpamf->partid_nrw_idr;
     }
@@ -367,6 +374,19 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
         return mpamf->mbwumon_idr;
     case A_MPAMF_CFG_PART_SEL:
         return mpamf->cfg_part_sel;
+    case A_MPAMF_MPAMCFG_CPBM0...
+        (A_MPAMF_MPAMCFG_CPBM0 + ((MPAM_CACHE_PART + 31) / 32 - 1) * 4):
+    {
+        uint32_t array_offset;
+
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_CPOR_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                "MPAM: Unexpected read of CPBM with no CPOR support\n");
+            return 0;
+        }
+        array_offset = (offset - A_MPAMF_MPAMCFG_CPBM0) / sizeof(uint32_t);
+        return mpamf->per_nrw_id[nrw_part_sel].cfg_cpbm[array_offset];
+    }
     default:
         qemu_log_mask(LOG_UNIMP,
                       "MPAM: Unexpected read of %lx\n", offset);
@@ -410,6 +430,21 @@ static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value,
         mpamf = &s->mpamf[s->ris];
         mpamf->cfg_part_sel = value;
         return;
+    case A_MPAMF_MPAMCFG_CPBM0...
+        (A_MPAMF_MPAMCFG_CPBM0 + ((MPAM_CACHE_PART + 31) / 32 - 1) * 4):
+    {
+        uint32_t array_offset;
+
+        /* TODO: Figure out write mask to check this stays in write bits */
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_CPOR_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write to CPMB when !HAS_CPORT_PART\n");
+            return;
+        }
+        array_offset = (offset - A_MPAMF_MPAMCFG_CPBM0) / sizeof(uint32_t);
+        mpamf->per_nrw_id[nrw_part_sel].cfg_cpbm[array_offset] = value;
+        return;
+    }
     default:
         qemu_log_mask(LOG_UNIMP,
                       "MPAM: Write to unexpected register Addr %lx Value=%lx\n",
@@ -538,6 +573,8 @@ static void mpam_msc_cache_realize(DeviceState *dev, Error **errp)
         /* Need to implement for RME */
         mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, SP4, 0);
 
+        /* Cache specific bit */
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_CPOR_PART, 1);
         mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_PARTID_NRW,
                                 s->num_int_partid < s->num_partid);
 
@@ -551,6 +588,10 @@ static void mpam_msc_cache_realize(DeviceState *dev, Error **errp)
         mpamf->aidr = FIELD_DP32(mpamf->aidr, MPAMF_AIDR, ARCH_MINOR_REV, 1);
         mpamf->aidr = FIELD_DP32(mpamf->aidr, MPAMF_AIDR, ARCH_MAJOR_REV, 1);
 
+        /* Portion */
+        mpamf->cpor_idr = FIELD_DP32(mpamf->cpor_idr, MPAMF_CPOR_IDR, CPBM_WD,
+                                     MPAM_CACHE_PART);
+
         if (s->num_int_partid < s->num_partid) {
             mpamf->partid_nrw_idr = FIELD_DP32(mpamf->partid_nrw_idr,
                                                MPAMF_PARTID_NRW_IDR,
Signature · 1 line
2.43.0
#34 lore raw

Re: [PATCH 11/37] hw/arm/mpam: Implement CPOR cache portion partitioning

Quoted 10 lines · On Fri, 16 Oct 2026 17:47:05 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jinjie Ruan <[email protected]>

Add the cache-portion controls: MPAMF_CPOR_IDR advertises the CPBM bitmap width (MPAM_CACHE_PART portions) and the cache subtype sets HAS_CPOR_PART, and the CPBM array registers become readable and writable per selected internal PARTID. Reads and writes of CPOR_IDR/CPBM on an MSC without CPOR support are logged and ignored.

Comment in here is fix the fixme ;)

Otherwise looks fine to me and I think it is a wise decision to always allocate backing for the max sized bitmap rather than trying to do it dependent on what the width is for a particular instance.

Quoted 25 lines
---
 hw/arm/mpam.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
hw/arm/mpam.c +7 -0
index cce9355..2b1401e 100644
@@ -356,6 +356,13 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
             return 0;
         }
         return mpamf->impl_idr;
+    case A_MPAMF_CPOR_IDR:
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_CPOR_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                "MPAM: Unexpected read of CPOR_IDR with no CPOR support\n");
+            return 0;
+        }
+        return mpamf->cpor_idr;
     case A_MPAMF_PARTID_NRW_IDR: {
         return mpamf->partid_nrw_idr;
     }
@@ -367,6 +374,19 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
         return mpamf->mbwumon_idr;
     case A_MPAMF_CFG_PART_SEL:

hw/arm/mpam.c static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset, · line 385

Quoted 10 lines
hw/arm/mpam.c +9 -0
         return mpamf->cfg_part_sel;
+    case A_MPAMF_MPAMCFG_CPBM0...
+        (A_MPAMF_MPAMCFG_CPBM0 + ((MPAM_CACHE_PART + 31) / 32 - 1) * 4):
+    {
+        uint32_t array_offset;
+
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_CPOR_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                "MPAM: Unexpected read of CPBM with no CPOR support\n");
+            return 0;

Sanity check for whether the width is large enough would just be informational here but it would I think be nice to have.

Quoted 8 lines
hw/arm/mpam.c +4 -0
+        }
+        array_offset = (offset - A_MPAMF_MPAMCFG_CPBM0) / sizeof(uint32_t);
+        return mpamf->per_nrw_id[nrw_part_sel].cfg_cpbm[array_offset];
+    }
     default:
         qemu_log_mask(LOG_UNIMP,
                       "MPAM: Unexpected read of %lx\n", offset);

hw/arm/mpam.c static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value, · line 438

Quoted 9 lines
hw/arm/mpam.c +6 -0
@@ -410,6 +430,21 @@ static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value,
         mpamf = &s->mpamf[s->ris];
         mpamf->cfg_part_sel = value;
         return;
+    case A_MPAMF_MPAMCFG_CPBM0...
+        (A_MPAMF_MPAMCFG_CPBM0 + ((MPAM_CACHE_PART + 31) / 32 - 1) * 4):
+    {
+        uint32_t array_offset;
+
+        /* TODO: Figure out write mask to check this stays in write bits */

Ah. Indeed, this is the thing the LLM was complaining about earlier. The width depends on how many partitions there are.
Definitely need that enforced (and a log on going over it).

Roughly speaking n such that (from the spec)
When ((n * 32) + x) >= UInt(MPAMF_CPOR_IDR().CPBM_WD)
is bad so either register out of range where n is the register offset and x is the bit in it. So shouldn't be too tricky to fix this.

Quoted 9 lines
hw/arm/mpam.c +9 -0
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_CPOR_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write to CPMB when !HAS_CPORT_PART\n");
+            return;
+        }
+        array_offset = (offset - A_MPAMF_MPAMCFG_CPBM0) / sizeof(uint32_t);
+        mpamf->per_nrw_id[nrw_part_sel].cfg_cpbm[array_offset] = value;
+        return;
+    }
#35 lore raw

Re: [PATCH 11/37] hw/arm/mpam: Implement CPOR cache portion partitioning

Quoted 50 lines · Jonathan Cameron
Quoted 10 lines · On Fri, 16 Oct 2026 17:47:05 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jinjie Ruan <[email protected]>

Add the cache-portion controls: MPAMF_CPOR_IDR advertises the CPBM bitmap width (MPAM_CACHE_PART portions) and the cache subtype sets HAS_CPOR_PART, and the CPBM array registers become readable and writable per selected internal PARTID. Reads and writes of CPOR_IDR/CPBM on an MSC without CPOR support are logged and ignored.

Comment in here is fix the fixme ;)

Otherwise looks fine to me and I think it is a wise decision to always allocate backing for the max sized bitmap rather than trying to do it dependent on what the width is for a particular instance.

Quoted 30 lines
---
 hw/arm/mpam.c | 41 +++++++++++++++++++++++++++++++++++++++++
 1 file changed, 41 insertions(+)
hw/arm/mpam.c +11 -0
index cce9355..2b1401e 100644
@@ -356,6 +356,13 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
             return 0;
         }
         return mpamf->impl_idr;
+    case A_MPAMF_CPOR_IDR:
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_CPOR_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                "MPAM: Unexpected read of CPOR_IDR with no CPOR support\n");
+            return 0;
+        }
+        return mpamf->cpor_idr;
     case A_MPAMF_PARTID_NRW_IDR: {
         return mpamf->partid_nrw_idr;
     }
@@ -367,6 +374,19 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
         return mpamf->mbwumon_idr;
     case A_MPAMF_CFG_PART_SEL:
         return mpamf->cfg_part_sel;
+    case A_MPAMF_MPAMCFG_CPBM0...
+        (A_MPAMF_MPAMCFG_CPBM0 + ((MPAM_CACHE_PART + 31) / 32 - 1) * 4):
+    {
+        uint32_t array_offset;
Quoted 8 lines

hw/arm/mpam.c static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset, · line 385

Quoted 5 lines
hw/arm/mpam.c +5 -0
+
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_CPOR_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                "MPAM: Unexpected read of CPBM with no CPOR support\n");
+            return 0;

Sanity check for whether the width is large enough would just be informational here but it would I think be nice to have.

Will add a Sanity check for the width.

Quoted 23 lines
Quoted 9 lines
hw/arm/mpam.c +4 -0
+        }
+        array_offset = (offset - A_MPAMF_MPAMCFG_CPBM0) / sizeof(uint32_t);
+        return mpamf->per_nrw_id[nrw_part_sel].cfg_cpbm[array_offset];
+    }
     default:
         qemu_log_mask(LOG_UNIMP,
                       "MPAM: Unexpected read of %lx\n", offset);

hw/arm/mpam.c static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value, · line 438

Quoted 9 lines
hw/arm/mpam.c +6 -0
@@ -410,6 +430,21 @@ static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value,
         mpamf = &s->mpamf[s->ris];
         mpamf->cfg_part_sel = value;
         return;
+    case A_MPAMF_MPAMCFG_CPBM0...
+        (A_MPAMF_MPAMCFG_CPBM0 + ((MPAM_CACHE_PART + 31) / 32 - 1) * 4):
+    {
+        uint32_t array_offset;
+
+        /* TODO: Figure out write mask to check this stays in write bits */

Ah. Indeed, this is the thing the LLM was complaining about earlier. The width depends on how many partitions there are.
Definitely need that enforced (and a log on going over it).

Quoted 5 lines

Roughly speaking n such that (from the spec)
When ((n * 32) + x) >= UInt(MPAMF_CPOR_IDR().CPBM_WD)
is bad so either register out of range where n is the register offset and x is the bit in it. So shouldn't be too tricky to fix this.

Yes, the spec requires this, we should fix it.

Quoted 12 lines
Quoted 11 lines
hw/arm/mpam.c +9 -0
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_CPOR_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write to CPMB when !HAS_CPORT_PART\n");
+            return;
+        }
+        array_offset = (offset - A_MPAMF_MPAMCFG_CPBM0) / sizeof(uint32_t);
+        mpamf->per_nrw_id[nrw_part_sel].cfg_cpbm[array_offset] = value;
+        return;
+    }
Signature · 2 lines
Best regards,
Jinjie
#36 lore raw

PATCH 12/37 hw/arm/mpam: Implement MBW bandwidth partitioning

In reply to a message not in the archive

From: Jinjie Ruan <[email protected]>

Add the memory-bandwidth controls: MPAMF_MBW_IDR (16-bit BWA_WD fraction, MIN/MAX/PBM/PROP support, BWPBM_WD = MPAM_MBW_PART) with HAS_MBW_PART on the memory subtype, and read/write handling for MBW_MIN, MBW_MAX, MBW_PROP and the MBW_PBM bitmap per selected internal PARTID.

Note the MBW_MIN write mask check references the CMIN mask -- a leftover fixed later by the CMIN/CASSOC patch.

---
 hw/arm/mpam.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
hw/arm/mpam.c +73 -0
index 2b1401e..7c33ec4 100644
@@ -363,6 +363,8 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
             return 0;
         }
         return mpamf->cpor_idr;
+    case A_MPAMF_MBW_IDR:
+        return mpamf->mbw_idr;
     case A_MPAMF_PARTID_NRW_IDR: {
         return mpamf->partid_nrw_idr;
     }
@@ -374,6 +376,12 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
         return mpamf->mbwumon_idr;
     case A_MPAMF_CFG_PART_SEL:
         return mpamf->cfg_part_sel;
+    case A_MPAMF_MPAMCFG_MBW_MIN:
+        return mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_min;
+    case A_MPAMF_MPAMCFG_MBW_MAX:
+        return mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_max;
+    case A_MPAMF_MPAMCFG_MBW_PROP:
+        return mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_prop;
     case A_MPAMF_MPAMCFG_CPBM0...
         (A_MPAMF_MPAMCFG_CPBM0 + ((MPAM_CACHE_PART + 31) / 32 - 1) * 4):
     {
@@ -387,6 +395,19 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
         array_offset = (offset - A_MPAMF_MPAMCFG_CPBM0) / sizeof(uint32_t);
         return mpamf->per_nrw_id[nrw_part_sel].cfg_cpbm[array_offset];
     }
+    case A_MPAMF_MPAMCFG_MBW_PBM0...
+            (A_MPAMF_MPAMCFG_MBW_PBM0 + ((MPAM_MBW_PART + 31) / 32 - 1) * 4):
+    {
+        uint32_t array_offset;
+
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_MBW_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                "MPAM: Unexpected read of MBW_PBM with no MBW_PART support\n");
+            return 0;
+        }
+        array_offset = (offset - A_MPAMF_MPAMCFG_MBW_PBM0) / sizeof(uint32_t);
+        return mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_pbm[array_offset];
+    }
     default:
         qemu_log_mask(LOG_UNIMP,
                       "MPAM: Unexpected read of %lx\n", offset);
@@ -430,6 +451,30 @@ static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value,
         mpamf = &s->mpamf[s->ris];
         mpamf->cfg_part_sel = value;
         return;
+    case A_MPAMF_MPAMCFG_MBW_MIN:
+        if (value & ~MPAMF_MPAMCFG_CMIN_WRITE_MASK) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write to CMAX Mask=%x Value=%lx\n",
+                          MPAMF_MPAMCFG_CMIN_WRITE_MASK, value);
+        }
+        mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_min = value;
+        return;
+    case A_MPAMF_MPAMCFG_MBW_MAX:
+        if (value & ~MPAMF_MPAMCFG_MBW_MAX_WRITE_MASK) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write to MBW_MAX Mask=%x Value=%lx\n",
+                          MPAMF_MPAMCFG_MBW_MAX_WRITE_MASK, value);
+        }
+        mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_max = value;
+        return;
+    case A_MPAMF_MPAMCFG_MBW_PROP:
+        if (value & ~MPAMF_MPAMCFG_MBW_PROP_WRITE_MASK) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write to MBW_PROP Mask=%x Value=%lx\n",
+                          MPAMF_MPAMCFG_MBW_MAX_WRITE_MASK, value);
+        }
+        mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_prop = value;
+        return;
     case A_MPAMF_MPAMCFG_CPBM0...
         (A_MPAMF_MPAMCFG_CPBM0 + ((MPAM_CACHE_PART + 31) / 32 - 1) * 4):
     {
@@ -445,6 +490,22 @@ static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value,
         mpamf->per_nrw_id[nrw_part_sel].cfg_cpbm[array_offset] = value;
         return;
     }
+    case A_MPAMF_MPAMCFG_MBW_PBM0...
+        (A_MPAMF_MPAMCFG_MBW_PBM0 + ((MPAM_MBW_PART + 31) / 32 - 1) * 4):
+    {
+        uint32_t array_offset;
+
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_MBW_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write to MBW_PBM when !HAS_MBW_PART\n");
+            return;
+        }
+        /* TODO: Figure out write mask to check this stays in write bits */
+        array_offset = (offset - A_MPAMF_MPAMCFG_MBW_PBM0) / sizeof(uint32_t);
+
+        mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_pbm[array_offset] = value;
+        return;
+    }
     default:
         qemu_log_mask(LOG_UNIMP,
                       "MPAM: Write to unexpected register Addr %lx Value=%lx\n",
@@ -522,6 +583,8 @@ static void mpam_msc_mem_realize(DeviceState *dev, Error **errp)
         /* We won't implement any implementation specific stuff */
         mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, NO_IMPL_PART, 1);
         mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, NO_IMPL_MSMON, 1);
+        /* Memory specific bit */
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_MBW_PART, 1);
 
         mpamf->iidr = FIELD_DP64(mpamf->iidr, MPAMF_IIDR, IMPLEMENTER,
                                  MPAM_IIDR_IMPLEMENTER);
@@ -533,6 +596,16 @@ static void mpam_msc_mem_realize(DeviceState *dev, Error **errp)
         mpamf->aidr = FIELD_DP64(mpamf->aidr, MPAMF_AIDR, ARCH_MINOR_REV, 1);
         mpamf->aidr = FIELD_DP64(mpamf->aidr, MPAMF_AIDR, ARCH_MAJOR_REV, 1);
 
+        mpamf->mbw_idr = FIELD_DP32(mpamf->mbw_idr, MPAMF_MBW_IDR, BWA_WD, 16);
+        mpamf->mbw_idr = FIELD_DP32(mpamf->mbw_idr, MPAMF_MBW_IDR, HAS_MIN, 1);
+        mpamf->mbw_idr = FIELD_DP32(mpamf->mbw_idr, MPAMF_MBW_IDR, HAS_MAX, 1);
+        mpamf->mbw_idr = FIELD_DP32(mpamf->mbw_idr, MPAMF_MBW_IDR, HAS_PBM, 1);
+        mpamf->mbw_idr = FIELD_DP32(mpamf->mbw_idr, MPAMF_MBW_IDR, HAS_PROP, 1);
+
+        mpamf->mbw_idr = FIELD_DP32(mpamf->mbw_idr, MPAMF_MBW_IDR, WINDWR, 0);
+        mpamf->mbw_idr = FIELD_DP32(mpamf->mbw_idr, MPAMF_MBW_IDR,
+                                    BWPBM_WD, MPAM_MBW_PART);
+
         if (s->num_int_partid < s->num_partid) {
             mpamf->partid_nrw_idr = FIELD_DP32(mpamf->partid_nrw_idr,
                                                MPAMF_PARTID_NRW_IDR,
Signature · 1 line
2.43.0
#37 lore raw

Re: [PATCH 12/37] hw/arm/mpam: Implement MBW bandwidth partitioning

Quoted 8 lines · On Fri, 16 Oct 2026 17:47:06 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jinjie Ruan <[email protected]>

Add the memory-bandwidth controls: MPAMF_MBW_IDR (16-bit BWA_WD fraction, MIN/MAX/PBM/PROP support, BWPBM_WD = MPAM_MBW_PART) with HAS_MBW_PART on the memory subtype, and read/write handling for MBW_MIN, MBW_MAX, MBW_PROP and the MBW_PBM bitmap per selected internal PARTID.

Quoted 4 lines

Note the MBW_MIN write mask check references the CMIN mask -- a leftover fixed later by the CMIN/CASSOC patch.

I'm a bit amused that the Todo from my RFC is still here and not fixed. Needs doing.

Quoted 17 lines
---
 hw/arm/mpam.c | 73 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 73 insertions(+)
hw/arm/mpam.c +1 -0
index 2b1401e..7c33ec4 100644
 
     case A_MPAMF_MPAMCFG_CPBM0...
         (A_MPAMF_MPAMCFG_CPBM0 + ((MPAM_CACHE_PART + 31) / 32 - 1) * 4):
     {
@@ -445,6 +490,22 @@ static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value,
         mpamf->per_nrw_id[nrw_part_sel].cfg_cpbm[array_offset] = value;
         return;
     }
+    case A_MPAMF_MPAMCFG_MBW_PBM0...

hw/arm/mpam.c static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value, · line 503

Quoted 10 lines
hw/arm/mpam.c +10 -0
+        (A_MPAMF_MPAMCFG_MBW_PBM0 + ((MPAM_MBW_PART + 31) / 32 - 1) * 4):
+    {
+        uint32_t array_offset;
+
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_MBW_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write to MBW_PBM when !HAS_MBW_PART\n");
+            return;
+        }
+        /* TODO: Figure out write mask to check this stays in write bits */

Indeed that needs doing. Wasn't I lazy in that RFC? :)

Quoted 5 lines
hw/arm/mpam.c +5 -0
+        array_offset = (offset - A_MPAMF_MPAMCFG_MBW_PBM0) / sizeof(uint32_t);
+
+        mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_pbm[array_offset] = value;
+        return;
+    }
#38 lore raw

PATCH 13/37 hw/arm/mpam: Implement PRI priority partitioning

In reply to a message not in the archive

From: Jinjie Ruan <[email protected]>

Add the priority controls: MPAMF_PRI_IDR advertises a 2-bit INTPRI (0 = low) with no DSPRI, HAS_PRI_PART is set on the cache subtype, and MPAMCFG_PRI is readable and writable per selected internal PARTID, logging writes of DSPRI/INTPRI fields the IDR does not implement.

---
 hw/arm/mpam.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
hw/arm/mpam.c +36 -0
index 7c33ec4..94e517b 100644
@@ -365,6 +365,13 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
         return mpamf->cpor_idr;
     case A_MPAMF_MBW_IDR:
         return mpamf->mbw_idr;
+    case A_MPAMF_PRI_IDR:
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_PRI_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                "MPAM: Unexpected read of PRI_IDR with no PRI PART support\n");
+            return 0;
+        }
+        return mpamf->pri_idr;
     case A_MPAMF_PARTID_NRW_IDR: {
         return mpamf->partid_nrw_idr;
     }
@@ -380,6 +387,8 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
         return mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_min;
     case A_MPAMF_MPAMCFG_MBW_MAX:
         return mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_max;
+    case A_MPAMF_MPAMCFG_PRI:
+        return mpamf->per_nrw_id[nrw_part_sel].cfg_pri;
     case A_MPAMF_MPAMCFG_MBW_PROP:
         return mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_prop;
     case A_MPAMF_MPAMCFG_CPBM0...
@@ -467,6 +476,24 @@ static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value,
         }
         mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_max = value;
         return;
+    case A_MPAMF_MPAMCFG_PRI:
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_PRI_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write to CFG_PRI when !HAS_PRI_PART\n");
+        } else {
+            if (!FIELD_EX32(mpamf->pri_idr, MPAMF_PRI_IDR, HAS_DSPRI) &&
+                FIELD_EX32(value, MPAMF_MPAMCFG_PRI, DSPRI)) {
+                qemu_log_mask(LOG_UNIMP,
+                              "MPAM: Unexpected write to CFGP_PRI DSPRI when !HAS_DSPRI\n");
+            }
+            if (!FIELD_EX32(mpamf->pri_idr, MPAMF_PRI_IDR, HAS_INTPRI) &&
+                FIELD_EX32(value, MPAMF_MPAMCFG_PRI, INTPRI)) {
+                qemu_log_mask(LOG_UNIMP,
+                              "MPAM: Unexpected write to CFGP_PRI INTPRI when !HAS_INTPRI\n");
+            }
+        }
+        mpamf->per_nrw_id[nrw_part_sel].cfg_pri = value;
+        return;
     case A_MPAMF_MPAMCFG_MBW_PROP:
         if (value & ~MPAMF_MPAMCFG_MBW_PROP_WRITE_MASK) {
             qemu_log_mask(LOG_UNIMP,
@@ -648,6 +675,7 @@ static void mpam_msc_cache_realize(DeviceState *dev, Error **errp)
 
         /* Cache specific bit */
         mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_CPOR_PART, 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_PRI_PART, 1);
         mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_PARTID_NRW,
                                 s->num_int_partid < s->num_partid);
 
@@ -665,6 +693,14 @@ static void mpam_msc_cache_realize(DeviceState *dev, Error **errp)
         mpamf->cpor_idr = FIELD_DP32(mpamf->cpor_idr, MPAMF_CPOR_IDR, CPBM_WD,
                                      MPAM_CACHE_PART);
 
+        /* Priority */
+        mpamf->pri_idr = FIELD_DP32(mpamf->pri_idr, MPAMF_PRI_IDR,
+                                    HAS_INTPRI, 1);
+        mpamf->pri_idr = FIELD_DP32(mpamf->pri_idr, MPAMF_PRI_IDR,
+                                    INTPRI_0_IS_LOW, 1);
+        mpamf->pri_idr = FIELD_DP32(mpamf->pri_idr, MPAMF_PRI_IDR,
+                                    INTPRI_WD, 2);
+
         if (s->num_int_partid < s->num_partid) {
             mpamf->partid_nrw_idr = FIELD_DP32(mpamf->partid_nrw_idr,
                                                MPAMF_PARTID_NRW_IDR,
Signature · 1 line
2.43.0
#39 lore raw
Quoted 9 lines · On Fri, 16 Oct 2026 17:47:07 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jinjie Ruan <[email protected]>

Add the priority controls: MPAMF_PRI_IDR advertises a 2-bit INTPRI (0 = low) with no DSPRI, HAS_PRI_PART is set on the cache subtype, and MPAMCFG_PRI is readable and writable per selected internal PARTID, logging writes of DSPRI/INTPRI fields the IDR does not implement.

I wonder if it is worth maintaining the flexibility of all the rest of the code not assuming HAS_PRI when it is hard coded to 1?

Maybe it is worth piping through the ability to turn each feature off? Or simplifying the code by removing the checks.

When I wrote that original I was mostly tweaking options and rebuilding to see what bugs I could find in James' kernel code. I think it would be useful to keep the ability to do that, but I have no idea if anyone wants the rich set of control parameters that needs. Maybe x-has_no_pri or something like that to indicate debug only?

BTW not sure how you decided which patches to keep my original SoB and which not. I don't really care given this was ancient code I was probably never getting back to, but maybe do another pass for what was more or less straight out of the RFC vs needing a bigger rewrite.

Thanks,

Jonathan

Quoted 79 lines
---
 hw/arm/mpam.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
hw/arm/mpam.c +36 -0
index 7c33ec4..94e517b 100644
@@ -365,6 +365,13 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
         return mpamf->cpor_idr;
     case A_MPAMF_MBW_IDR:
         return mpamf->mbw_idr;
+    case A_MPAMF_PRI_IDR:
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_PRI_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                "MPAM: Unexpected read of PRI_IDR with no PRI PART support\n");
+            return 0;
+        }
+        return mpamf->pri_idr;
     case A_MPAMF_PARTID_NRW_IDR: {
         return mpamf->partid_nrw_idr;
     }
@@ -380,6 +387,8 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
         return mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_min;
     case A_MPAMF_MPAMCFG_MBW_MAX:
         return mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_max;
+    case A_MPAMF_MPAMCFG_PRI:
+        return mpamf->per_nrw_id[nrw_part_sel].cfg_pri;
     case A_MPAMF_MPAMCFG_MBW_PROP:
         return mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_prop;
     case A_MPAMF_MPAMCFG_CPBM0...
@@ -467,6 +476,24 @@ static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value,
         }
         mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_max = value;
         return;
+    case A_MPAMF_MPAMCFG_PRI:
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_PRI_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write to CFG_PRI when !HAS_PRI_PART\n");
+        } else {
+            if (!FIELD_EX32(mpamf->pri_idr, MPAMF_PRI_IDR, HAS_DSPRI) &&
+                FIELD_EX32(value, MPAMF_MPAMCFG_PRI, DSPRI)) {
+                qemu_log_mask(LOG_UNIMP,
+                              "MPAM: Unexpected write to CFGP_PRI DSPRI when !HAS_DSPRI\n");
+            }
+            if (!FIELD_EX32(mpamf->pri_idr, MPAMF_PRI_IDR, HAS_INTPRI) &&
+                FIELD_EX32(value, MPAMF_MPAMCFG_PRI, INTPRI)) {
+                qemu_log_mask(LOG_UNIMP,
+                              "MPAM: Unexpected write to CFGP_PRI INTPRI when !HAS_INTPRI\n");
+            }
+        }
+        mpamf->per_nrw_id[nrw_part_sel].cfg_pri = value;
+        return;
     case A_MPAMF_MPAMCFG_MBW_PROP:
         if (value & ~MPAMF_MPAMCFG_MBW_PROP_WRITE_MASK) {
             qemu_log_mask(LOG_UNIMP,
@@ -648,6 +675,7 @@ static void mpam_msc_cache_realize(DeviceState *dev, Error **errp)
 
         /* Cache specific bit */
         mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_CPOR_PART, 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_PRI_PART, 1);
         mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_PARTID_NRW,
                                 s->num_int_partid < s->num_partid);
 
@@ -665,6 +693,14 @@ static void mpam_msc_cache_realize(DeviceState *dev, Error **errp)
         mpamf->cpor_idr = FIELD_DP32(mpamf->cpor_idr, MPAMF_CPOR_IDR, CPBM_WD,
                                      MPAM_CACHE_PART);
 
+        /* Priority */
+        mpamf->pri_idr = FIELD_DP32(mpamf->pri_idr, MPAMF_PRI_IDR,
+                                    HAS_INTPRI, 1);
+        mpamf->pri_idr = FIELD_DP32(mpamf->pri_idr, MPAMF_PRI_IDR,
+                                    INTPRI_0_IS_LOW, 1);
+        mpamf->pri_idr = FIELD_DP32(mpamf->pri_idr, MPAMF_PRI_IDR,
+                                    INTPRI_WD, 2);
+
         if (s->num_int_partid < s->num_partid) {
             mpamf->partid_nrw_idr = FIELD_DP32(mpamf->partid_nrw_idr,
                                                MPAMF_PARTID_NRW_IDR,
#40 lore raw
Quoted 15 lines · Jonathan Cameron
Quoted 9 lines · On Fri, 16 Oct 2026 17:47:07 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jinjie Ruan <[email protected]>

Add the priority controls: MPAMF_PRI_IDR advertises a 2-bit INTPRI (0 = low) with no DSPRI, HAS_PRI_PART is set on the cache subtype, and MPAMCFG_PRI is readable and writable per selected internal PARTID, logging writes of DSPRI/INTPRI fields the IDR does not implement.

I wonder if it is worth maintaining the flexibility of all the rest of the code not assuming HAS_PRI when it is hard coded to 1?

Quoted 8 lines

Maybe it is worth piping through the ability to turn each feature off? Or simplifying the code by removing the checks.

When I wrote that original I was mostly tweaking options and rebuilding to see what bugs I could find in James' kernel code. I think it would be useful to keep the ability to do that, but I have no idea if anyone wants the rich set of control parameters that needs. Maybe x-has_no_pri or something like that to indicate debug only?

I agree. I think it makes sense to provide users with configurable options

Quoted 5 lines

BTW not sure how you decided which patches to keep my original SoB and which not. I don't really care given this was ancient code I was probably never getting back to, but maybe do another pass for what was more or less straight out of the RFC vs needing a bigger rewrite.

Ok, I will recheck it.

Quoted 86 lines

Thanks,

Jonathan

Quoted 79 lines
---
 hw/arm/mpam.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
hw/arm/mpam.c +36 -0
index 7c33ec4..94e517b 100644
@@ -365,6 +365,13 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
         return mpamf->cpor_idr;
     case A_MPAMF_MBW_IDR:
         return mpamf->mbw_idr;
+    case A_MPAMF_PRI_IDR:
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_PRI_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                "MPAM: Unexpected read of PRI_IDR with no PRI PART support\n");
+            return 0;
+        }
+        return mpamf->pri_idr;
     case A_MPAMF_PARTID_NRW_IDR: {
         return mpamf->partid_nrw_idr;
     }
@@ -380,6 +387,8 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
         return mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_min;
     case A_MPAMF_MPAMCFG_MBW_MAX:
         return mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_max;
+    case A_MPAMF_MPAMCFG_PRI:
+        return mpamf->per_nrw_id[nrw_part_sel].cfg_pri;
     case A_MPAMF_MPAMCFG_MBW_PROP:
         return mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_prop;
     case A_MPAMF_MPAMCFG_CPBM0...
@@ -467,6 +476,24 @@ static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value,
         }
         mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_max = value;
         return;
+    case A_MPAMF_MPAMCFG_PRI:
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_PRI_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write to CFG_PRI when !HAS_PRI_PART\n");
+        } else {
+            if (!FIELD_EX32(mpamf->pri_idr, MPAMF_PRI_IDR, HAS_DSPRI) &&
+                FIELD_EX32(value, MPAMF_MPAMCFG_PRI, DSPRI)) {
+                qemu_log_mask(LOG_UNIMP,
+                              "MPAM: Unexpected write to CFGP_PRI DSPRI when !HAS_DSPRI\n");
+            }
+            if (!FIELD_EX32(mpamf->pri_idr, MPAMF_PRI_IDR, HAS_INTPRI) &&
+                FIELD_EX32(value, MPAMF_MPAMCFG_PRI, INTPRI)) {
+                qemu_log_mask(LOG_UNIMP,
+                              "MPAM: Unexpected write to CFGP_PRI INTPRI when !HAS_INTPRI\n");
+            }
+        }
+        mpamf->per_nrw_id[nrw_part_sel].cfg_pri = value;
+        return;
     case A_MPAMF_MPAMCFG_MBW_PROP:
         if (value & ~MPAMF_MPAMCFG_MBW_PROP_WRITE_MASK) {
             qemu_log_mask(LOG_UNIMP,
@@ -648,6 +675,7 @@ static void mpam_msc_cache_realize(DeviceState *dev, Error **errp)
 
         /* Cache specific bit */
         mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_CPOR_PART, 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_PRI_PART, 1);
         mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_PARTID_NRW,
                                 s->num_int_partid < s->num_partid);
 
@@ -665,6 +693,14 @@ static void mpam_msc_cache_realize(DeviceState *dev, Error **errp)
         mpamf->cpor_idr = FIELD_DP32(mpamf->cpor_idr, MPAMF_CPOR_IDR, CPBM_WD,
                                      MPAM_CACHE_PART);
 
+        /* Priority */
+        mpamf->pri_idr = FIELD_DP32(mpamf->pri_idr, MPAMF_PRI_IDR,
+                                    HAS_INTPRI, 1);
+        mpamf->pri_idr = FIELD_DP32(mpamf->pri_idr, MPAMF_PRI_IDR,
+                                    INTPRI_0_IS_LOW, 1);
+        mpamf->pri_idr = FIELD_DP32(mpamf->pri_idr, MPAMF_PRI_IDR,
+                                    INTPRI_WD, 2);
+
         if (s->num_int_partid < s->num_partid) {
             mpamf->partid_nrw_idr = FIELD_DP32(mpamf->partid_nrw_idr,
                                                MPAMF_PARTID_NRW_IDR,
Signature · 2 lines
Best regards,
Jinjie
#41 lore raw

PATCH 14/37 hw/arm/mpam: Implement CCAP capacity partitioning

In reply to a message not in the archive

From: Jinjie Ruan <[email protected]>

Add the cache-capacity controls: MPAMF_CCAP_IDR (4-bit CMAX/CASSOC band widths, HAS_CMIN/HAS_CASSOC advertised ahead of their storage, CMAX soft-limit support) with HAS_CCAP_PART on the cache subtype, and read/write handling for MPAMCFG_CMAX per selected internal PARTID, guarded on CCAP support.

---
 hw/arm/mpam.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
hw/arm/mpam.c +37 -0
index 94e517b..fafe74f 100644
@@ -363,6 +363,13 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
             return 0;
         }
         return mpamf->cpor_idr;
+    case A_MPAMF_CCAP_IDR:
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_CCAP_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                "MPAM: Unexpected read of CCAP_IDR with no CCAP support\n");
+            return 0;
+        }
+        return mpamf->ccap_idr;
     case A_MPAMF_MBW_IDR:
         return mpamf->mbw_idr;
     case A_MPAMF_PRI_IDR:
@@ -383,6 +390,13 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
         return mpamf->mbwumon_idr;
     case A_MPAMF_CFG_PART_SEL:
         return mpamf->cfg_part_sel;
+    case A_MPAMF_MPAMCFG_CMAX:
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_CCAP_PART)) {
+            qemu_log_mask(LOG_UNIMP,
+                "MPAM: Unexpected read of CMAX with no CCAP support\n");
+            return 0;
+        }
+        return mpamf->per_nrw_id[nrw_part_sel].cfg_cmax;
     case A_MPAMF_MPAMCFG_MBW_MIN:
         return mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_min;
     case A_MPAMF_MPAMCFG_MBW_MAX:
@@ -460,6 +474,14 @@ static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value,
         mpamf = &s->mpamf[s->ris];
         mpamf->cfg_part_sel = value;
         return;
+    case A_MPAMF_MPAMCFG_CMAX:
+        if (value & ~MPAMF_MPAMCFG_CMAX_WRITE_MASK) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write to CMAX Mask=%x Value=%lx\n",
+                          MPAMF_MPAMCFG_CMAX_WRITE_MASK, value);
+        }
+        mpamf->per_nrw_id[nrw_part_sel].cfg_cmax = value;
+        return;
     case A_MPAMF_MPAMCFG_MBW_MIN:
         if (value & ~MPAMF_MPAMCFG_CMIN_WRITE_MASK) {
             qemu_log_mask(LOG_UNIMP,
@@ -675,6 +697,7 @@ static void mpam_msc_cache_realize(DeviceState *dev, Error **errp)
 
         /* Cache specific bit */
         mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_CPOR_PART, 1);
+        mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_CCAP_PART, 1);
         mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_PRI_PART, 1);
         mpamf->idr = FIELD_DP64(mpamf->idr, MPAMF_IDR, HAS_PARTID_NRW,
                                 s->num_int_partid < s->num_partid);
@@ -701,6 +724,20 @@ static void mpam_msc_cache_realize(DeviceState *dev, Error **errp)
         mpamf->pri_idr = FIELD_DP32(mpamf->pri_idr, MPAMF_PRI_IDR,
                                     INTPRI_WD, 2);
 
+        /* Capacity Partitioning */
+        mpamf->ccap_idr = FIELD_DP32(mpamf->ccap_idr, MPAMF_CCAP_IDR,
+                                     HAS_CMAX_SOFTLIM, 1);
+        mpamf->ccap_idr = FIELD_DP32(mpamf->ccap_idr, MPAMF_CCAP_IDR,
+                                     NO_CMAX, 0);
+        mpamf->ccap_idr = FIELD_DP32(mpamf->ccap_idr, MPAMF_CCAP_IDR,
+                                     HAS_CMIN, 1);
+        mpamf->ccap_idr = FIELD_DP32(mpamf->ccap_idr, MPAMF_CCAP_IDR,
+                                     HAS_CASSOC, 1);
+        mpamf->ccap_idr = FIELD_DP32(mpamf->ccap_idr, MPAMF_CCAP_IDR,
+                                     CASSOC_WD, 4); /* Not much flex on this */
+        mpamf->ccap_idr = FIELD_DP32(mpamf->ccap_idr, MPAMF_CCAP_IDR,
+                                     CMAX_WD, 4);
+
         if (s->num_int_partid < s->num_partid) {
             mpamf->partid_nrw_idr = FIELD_DP32(mpamf->partid_nrw_idr,
                                                MPAMF_PARTID_NRW_IDR,
Signature · 1 line
2.43.0
Reviewed-by on v1 14/37
#42 lore raw

Re: [PATCH 14/37] hw/arm/mpam: Implement CCAP capacity partitioning

Quoted 4 lines · On Fri, 16 Oct 2026 17:47:08 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jinjie Ruan <[email protected]>

Add the cache-capacity controls: MPAMF_CCAP_IDR (4-bit CMAX/CASSOC band widths, HAS_CMIN/HAS_CASSOC advertised ahead of their storage,

bandwidths

Quoted 5 lines

CMAX soft-limit support) with HAS_CCAP_PART on the cache subtype, and read/write handling for MPAMCFG_CMAX per selected internal PARTID, guarded on CCAP support.

One trivial inline otherwise fine

Quoted 9 lines
---
 hw/arm/mpam.c | 37 +++++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
hw/arm/mpam.c +1 -0
@@ -701,6 +724,20 @@ static void mpam_msc_cache_realize(DeviceState *dev, Error **errp)
         mpamf->pri_idr = FIELD_DP32(mpamf->pri_idr, MPAMF_PRI_IDR,
                                     INTPRI_WD, 2);
 
+        /* Capacity Partitioning */

hw/arm/mpam.c static void mpam_msc_cache_realize(DeviceState *dev, Error **errp) · line 737

Quoted 10 lines
hw/arm/mpam.c +10 -0
+        mpamf->ccap_idr = FIELD_DP32(mpamf->ccap_idr, MPAMF_CCAP_IDR,
+                                     HAS_CMAX_SOFTLIM, 1);
+        mpamf->ccap_idr = FIELD_DP32(mpamf->ccap_idr, MPAMF_CCAP_IDR,
+                                     NO_CMAX, 0);
+        mpamf->ccap_idr = FIELD_DP32(mpamf->ccap_idr, MPAMF_CCAP_IDR,
+                                     HAS_CMIN, 1);
+        mpamf->ccap_idr = FIELD_DP32(mpamf->ccap_idr, MPAMF_CCAP_IDR,
+                                     HAS_CASSOC, 1);
+        mpamf->ccap_idr = FIELD_DP32(mpamf->ccap_idr, MPAMF_CCAP_IDR,
+                                     CASSOC_WD, 4); /* Not much flex on this */

Any idea what I meant by that comment? I've no idea. Probably drop it
- it might just have been me musing about the MPAM spec.

Quoted 6 lines
hw/arm/mpam.c +3 -0
+        mpamf->ccap_idr = FIELD_DP32(mpamf->ccap_idr, MPAMF_CCAP_IDR,
+                                     CMAX_WD, 4);
+
         if (s->num_int_partid < s->num_partid) {
             mpamf->partid_nrw_idr = FIELD_DP32(mpamf->partid_nrw_idr,
                                                MPAMF_PARTID_NRW_IDR,
#43 lore raw

PATCH 15/37 hw/arm/mpam: Add ECR/ESR and error MSI register storage

In reply to a message not in the archive

From: Jinjie Ruan <[email protected]>

Add read/write handling for the error report surface as plain per-RIS storage: MPAMF_ECR (INTEN write mask), MPAMF_ESR and the ERR_MSI configuration block. Error recording semantics, the MSC- global ESR view and the interrupt outputs arrive with the error reporting patches.

---
 hw/arm/mpam.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
hw/arm/mpam.c +22 -0
index fafe74f..441356e 100644
@@ -388,6 +388,20 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
         return mpamf->csumon_idr;
     case A_MPAMF_MBWUMON_IDR:
         return mpamf->mbwumon_idr;
+    case A_MPAMF_ERR_MSI_MPAM:
+        return mpamf->err_msi_mpam;
+    case A_MPAMF_ERR_MSI_ADDR_L:
+        return mpamf->err_msi_addr_l;
+    case A_MPAMF_ERR_MSI_ADDR_H:
+        return mpamf->err_msi_addr_h;
+    case A_MPAMF_ERR_MSI_DATA:
+        return mpamf->err_msi_data;
+    case A_MPAMF_ERR_MSI_ATTR:
+        return mpamf->err_msi_attr;
+    case A_MPAMF_ECR:
+        return mpamf->ecr;
+    case A_MPAMF_ESR:
+        return mpamf->esr;
     case A_MPAMF_CFG_PART_SEL:
         return mpamf->cfg_part_sel;
     case A_MPAMF_MPAMCFG_CMAX:
@@ -555,6 +569,14 @@ static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value,
         mpamf->per_nrw_id[nrw_part_sel].cfg_mbw_pbm[array_offset] = value;
         return;
     }
+    case A_MPAMF_ECR:
+        if (value & ~MPAMF_ECR_WRITE_MASK) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write to ECR Mask=%x Value=%lx\n",
+                          MPAMF_ECR_WRITE_MASK, value);
+        }
+        mpamf->ecr = value;
+        return;
     default:
         qemu_log_mask(LOG_UNIMP,
                       "MPAM: Write to unexpected register Addr %lx Value=%lx\n",
Signature · 1 line
2.43.0
Reviewed-by on v1 15/37
#44 lore raw

Re: [PATCH 15/37] hw/arm/mpam: Add ECR/ESR and error MSI register storage

Quoted 9 lines · On Fri, 16 Oct 2026 17:47:09 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jinjie Ruan <[email protected]>

Add read/write handling for the error report surface as plain per-RIS storage: MPAMF_ECR (INTEN write mask), MPAMF_ESR and the ERR_MSI configuration block. Error recording semantics, the MSC- global ESR view and the interrupt outputs arrive with the error reporting patches.

#45 lore raw

PATCH 16/37 hw/arm/mpam: Implement PARTID narrowing

In reply to a message not in the archive

From: Jinjie Ruan <[email protected]>

The MPAMCFG_INTPARTID register (0x600) was defined but never handled, so a guest could not program the request PARTID to internal PARTID mapping that PARTID narrowing is based on. Add read/write support:

- Writing MPAMCFG_INTPARTID stores the mapping for the request PARTID selected by MPAMCFG_PART_SEL; reads return the stored mapping.
- At realize, initialise the map to partid % num_int_partid so the indirection is always in range before a driver programs it, mirroring the Linux driver's fallback mapping. MBW_MAX also resets to 0xffff (full bandwidth) for every internal PARTID, matching
hardware: an unprogrammed PARTID must not read as zero bandwidth.
- Clamp the narrowing indirection lookup to num_int_partid, and wrap MPAMCFG_PART_SEL writes into the supported PARTID space (the narrowed space for INTERNAL selectors) so a guest cannot trigger out-of-bounds accesses on the emulated arrays.

A guest driver can now exercise PARTID narrowing: several request PARTIDs share one internal PARTID's configuration, and the guest can re-map them at runtime.

---
 hw/arm/mpam.c | 64 ++++++++++++++++++++++++++++++++++++++++++++++++---
 1 file changed, 61 insertions(+), 3 deletions(-)
hw/arm/mpam.c +61 -3
index 441356e..91d1c31 100644
@@ -285,14 +285,18 @@ typedef struct MPAMMSCState {
 static uint32_t mpam_get_nrw_id(MPAMMSCState *s)
 {
     Mpamf *mpamf = &s->mpamf[s->ris];
+    uint32_t intpartid;
 
     if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_PARTID_NRW)) {
         return s->part_sel;
     }
     if (s->internal_part_sel) {
-        return s->part_sel;
+        intpartid = s->part_sel;
+    } else {
+        intpartid = mpamf->cfg_intpartid[s->part_sel];
     }
-    return mpamf->cfg_intpartid[s->part_sel];
+
+    return intpartid % s->num_int_partid;
 }
 
 typedef struct MPAMMSCMemState {
@@ -404,6 +408,17 @@ static uint64_t mpam_msc_read_reg(void *opaque, hwaddr offset,
         return mpamf->esr;
     case A_MPAMF_CFG_PART_SEL:
         return mpamf->cfg_part_sel;
+    case A_MPAMF_MPAMCFG_INTPARTID: {
+        /*
+         * The map is only meaningful for resources that implement
+         * narrowing; others read as zero.
+         */
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_PARTID_NRW)) {
+            return 0;
+        }
+
+        return mpamf->cfg_intpartid[s->part_sel];
+    }
     case A_MPAMF_MPAMCFG_CMAX:
         if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_CCAP_PART)) {
             qemu_log_mask(LOG_UNIMP,
@@ -482,12 +497,38 @@ static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value,
                           s->num_ris);
             return;
         }
+        {
+            /*
+             * IHI 0099 7.2.1: the MSC does not check PARTID_SEL on write
+             * (the first IMPLEMENTATION DEFINED behaviour); the selector
+             * wraps into the supported PARTID space instead.
+             */
+            uint32_t limit = FIELD_EX32(value, MPAMF_CFG_PART_SEL, INTERNAL) ?
+                             s->num_int_partid : s->num_partid;
+
+            s->part_sel = FIELD_EX32(value, MPAMF_CFG_PART_SEL,
+                                     PARTID_SEL) % limit;
+        }
         s->ris = FIELD_EX32(value, MPAMF_CFG_PART_SEL, RIS);
-        s->part_sel = FIELD_EX32(value, MPAMF_CFG_PART_SEL, PARTID_SEL);
         s->internal_part_sel = FIELD_EX32(value, MPAMF_CFG_PART_SEL, INTERNAL);
         mpamf = &s->mpamf[s->ris];
         mpamf->cfg_part_sel = value;
         return;
+    case A_MPAMF_MPAMCFG_INTPARTID:
+        if (value & ~MPAMF_MPAMCFG_INTPARTID_WRITE_MASK) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write to INTPARTID Mask=%x Value=%lx\n",
+                          MPAMF_MPAMCFG_INTPARTID_WRITE_MASK, value);
+        }
+        if (!FIELD_EX32(mpamf->idr, MPAMF_IDR, HAS_PARTID_NRW)) {
+            qemu_log_mask(LOG_UNIMP,
+                          "MPAM: Unexpected write to INTPARTID when !HAS_PARTID_NRW\n");
+            return;
+        }
+
+        mpamf->cfg_intpartid[s->part_sel] =
+            FIELD_EX32(value, MPAMF_MPAMCFG_INTPARTID, INTPARTID);
+        return;
     case A_MPAMF_MPAMCFG_CMAX:
         if (value & ~MPAMF_MPAMCFG_CMAX_WRITE_MASK) {
             qemu_log_mask(LOG_UNIMP,
@@ -619,8 +660,25 @@ static void mpam_msc_realize(DeviceState *dev, Error **errp)
 
     s->mpamf = g_new0(Mpamf, s->num_ris);
     for (i = 0; i < s->num_ris; i++) {
+        int p;
+
         s->mpamf[i].per_nrw_id = g_new0(MpamfPerNrwId, s->num_int_partid);
         s->mpamf[i].cfg_intpartid = g_new0(uint32_t, s->num_partid);
+        /*
+         * Until resctrl programs the map, wrap each request PARTID onto an
+         * internal PARTID so the narrowing indirection is always in range.
+         */
+        for (p = 0; p < s->num_partid; p++) {
+            s->mpamf[i].cfg_intpartid[p] = p % s->num_int_partid;
+        }
+        /*
+         * per_nrw_id is indexed by INTERNAL PARTID: it has num_int_partid
+         * entries, not num_partid.
+         */
+        for (p = 0; p < s->num_int_partid; p++) {
+            /* MBW_MAX resets to full bandwidth on real hardware */
+            s->mpamf[i].per_nrw_id[p].cfg_mbw_max = 0xffff;
+        }
     }
 
     memory_region_init_io(&s->mr, OBJECT(s), &mpam_msc_ops, s, "mpam_msc",
Signature · 1 line
2.43.0
Reviewed-by on v1 16/37
#46 lore raw

Re: [PATCH 16/37] hw/arm/mpam: Implement PARTID narrowing

Quoted 3 lines · On Fri, 16 Oct 2026 17:47:10 +0800 Jinjie Ruan <[email protected]> wrote:

From: Jinjie Ruan <[email protected]>

The MPAMCFG_INTPARTID register (0x600) was defined but never handled,

Never handled in original set? I can't remember but it seems an odd
comment to have in this series. Or is intent to say it's there earlier
in the series. If so I'd say "has been define but not yet handled"

I'm guessing it was buggy in the RFC. Not sure I tested it so I'm certainly not surprised it was!

Quoted 15 lines

so a guest could not program the request PARTID to internal PARTID mapping that PARTID narrowing is based on. Add read/write support:

- Writing MPAMCFG_INTPARTID stores the mapping for the request PARTID selected by MPAMCFG_PART_SEL; reads return the stored mapping.
- At realize, initialise the map to partid % num_int_partid so the indirection is always in range before a driver programs it, mirroring the Linux driver's fallback mapping. MBW_MAX also resets to 0xffff (full bandwidth) for every internal PARTID, matching
hardware: an unprogrammed PARTID must not read as zero bandwidth.
- Clamp the narrowing indirection lookup to num_int_partid, and wrap MPAMCFG_PART_SEL writes into the supported PARTID space (the narrowed space for INTERNAL selectors) so a guest cannot trigger out-of-bounds accesses on the emulated arrays.

Quoted 5 lines

A guest driver can now exercise PARTID narrowing: several request PARTIDs share one internal PARTID's configuration, and the guest can re-map them at runtime.

Just trivial stuff. Looks good to me and having looked again, the RFC clearly failed to do half of what was needed :(

Quoted 5 lines
hw/arm/mpam.c +1 -0
@@ -482,12 +497,38 @@ static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value,
                           s->num_ris);
             return;
         }
+        {

hw/arm/mpam.c static void mpam_msc_write_reg(void *opaque, hwaddr offset, uint64_t value, · line 510

Quoted 10 lines
hw/arm/mpam.c +10 -0
+            /*
+             * IHI 0099 7.2.1: the MSC does not check PARTID_SEL on write
+             * (the first IMPLEMENTATION DEFINED behaviour); the selector
+             * wraps into the supported PARTID space instead.
+             */
+            uint32_t limit = FIELD_EX32(value, MPAMF_CFG_PART_SEL, INTERNAL) ?
+                             s->num_int_partid : s->num_partid;
+
+            s->part_sel = FIELD_EX32(value, MPAMF_CFG_PART_SEL,
+                                     PARTID_SEL) % limit;

I'd rewrap that. I think slightly over 80 chars is fine here.

Quoted 8 lines
hw/arm/mpam.c +1 -0
+        }
 
     case A_MPAMF_MPAMCFG_CMAX:
         if (value & ~MPAMF_MPAMCFG_CMAX_WRITE_MASK) {
             qemu_log_mask(LOG_UNIMP,
@@ -619,8 +660,25 @@ static void mpam_msc_realize(DeviceState *dev, Error **errp)
 
     s->mpamf = g_new0(Mpamf, s->num_ris);

hw/arm/mpam.c static void mpam_msc_realize(DeviceState *dev, Error **errp) · line 671

Quoted 10 lines
hw/arm/mpam.c +7 -0
     for (i = 0; i < s->num_ris; i++) {
+        int p;
+
         s->mpamf[i].per_nrw_id = g_new0(MpamfPerNrwId, s->num_int_partid);
         s->mpamf[i].cfg_intpartid = g_new0(uint32_t, s->num_partid);
+        /*
+         * Until resctrl programs the map, wrap each request PARTID onto an
+         * internal PARTID so the narrowing indirection is always in range.
+         */
+        for (p = 0; p < s->num_partid; p++) {
        for (int p = 0;

hw/arm/mpam.c static void mpam_msc_realize(DeviceState *dev, Error **errp) · line 678

Quoted 7 lines
hw/arm/mpam.c +7 -0
+            s->mpamf[i].cfg_intpartid[p] = p % s->num_int_partid;
+        }
+        /*
+         * per_nrw_id is indexed by INTERNAL PARTID: it has num_int_partid
+         * entries, not num_partid.
+         */
+        for (p = 0; p < s->num_int_partid; p++) {
        for (int p = 0;

particularly given it has a different use to previous p!

Quoted 6 lines
hw/arm/mpam.c +3 -0
+            /* MBW_MAX resets to full bandwidth on real hardware */
+            s->mpamf[i].per_nrw_id[p].cfg_mbw_max = 0xffff;
+        }
     }
 
     memory_region_init_io(&s->mr, OBJECT(s), &mpam_msc_ops, s, "mpam_msc",