diff --git a/drivers/platform/arm64/mpam/mpam_resctrl.c b/drivers/platform/arm64/mpam/mpam_resctrl.c
index f3f8fb0ff421..c6ca086f7dd8 100644
--- a/drivers/platform/arm64/mpam/mpam_resctrl.c
+++ b/drivers/platform/arm64/mpam/mpam_resctrl.c
@@ -186,6 +186,11 @@ static u32 get_num_reqpartid(void)
return mpam_partid_max + 1;
}
+static u32 get_num_reqpartid_per_closid(void)
+{
+ return get_num_reqpartid() / resctrl_arch_get_num_closid(NULL);
+}
+
u32 resctrl_arch_system_num_rmid_idx(void)
{
u8 closid_shift = fls(mpam_pmg_max);@@ -194,24 +199,73 @@ u32 resctrl_arch_system_num_rmid_idx(void)
return num_reqpartid << closid_shift;
}
+/*
+ * Under MPAM driver, the rmid contains two pieces of information: one is
+ * req_idx, and the other is pmg. Therefore,
+ * closid_shift = req_shift + pmg_shift.
+ */
u32 resctrl_arch_rmid_idx_encode(u32 closid, u32 rmid)
{
- u8 closid_shift = fls(mpam_pmg_max);
+ u32 rmid_mask;
+ u8 closid_shift;
+ u8 pmg_shift = fls(mpam_pmg_max);
+ u8 req_shift = fls(get_num_reqpartid_per_closid() - 1);
+
+ closid_shift = req_shift + pmg_shift;
+ rmid_mask = ~(~0 << closid_shift);
WARN_ON_ONCE(closid_shift > 8);
- return (closid << closid_shift) | rmid;
+ return (closid << closid_shift) | (rmid & rmid_mask);
}
void resctrl_arch_rmid_idx_decode(u32 idx, u32 *closid, u32 *rmid)
{
- u8 closid_shift = fls(mpam_pmg_max);
- u32 pmg_mask = ~(~0 << closid_shift);
+ u32 rmid_mask;
+ u8 closid_shift;
+ u8 pmg_shift = fls(mpam_pmg_max);
+ u8 req_shift = fls(get_num_reqpartid_per_closid() - 1);
+
+ closid_shift = req_shift + pmg_shift;
+ rmid_mask = ~(~0 << closid_shift);
WARN_ON_ONCE(closid_shift > 8);
- *closid = idx >> closid_shift;
- *rmid = idx & pmg_mask;
+ if (closid)
+ *closid = idx >> closid_shift;
+ if (rmid)
+ *rmid = idx & rmid_mask;
+}
+
+static u32 closid_rmid2reqpartid(u32 closid, u32 rmid)
+{
+ u32 intpartid;
+ u8 pmg_shift = fls(mpam_pmg_max);
+ u32 req_idx = (rmid >> pmg_shift);
+ u8 intpartid_shift = fls(mpam_intpartid_max);
+
+ if (!cdp_enabled)
+ intpartid = resctrl_get_config_index(closid, CDP_NONE);
+ else
+ intpartid = resctrl_get_config_index(closid, CDP_DATA);
+
+ return (req_idx << intpartid_shift) | intpartid;
+}
+
+static u32 rmid2pmg(u32 rmid)
+{
+ u8 pmg_shift = fls(mpam_pmg_max);
+ u32 pmg_mask = ~(~0 << pmg_shift);
+
+ return rmid & pmg_mask;
+}
+
+static u32 req2intpartid(u32 reqpartid)
+{
+ u8 intpartid_shift = fls(mpam_intpartid_max);
+ u32 intpartid_mask = ~(~0 << intpartid_shift);
+
+ return reqpartid & intpartid_mask;
}
void resctrl_arch_sched_in(struct task_struct *tsk)@@ -223,21 +277,20 @@ void resctrl_arch_sched_in(struct task_struct *tsk)
void resctrl_arch_set_cpu_default_closid_rmid(int cpu, u32 closid, u32 rmid)
{
- WARN_ON_ONCE(closid > U16_MAX);
- WARN_ON_ONCE(rmid > U8_MAX);
+ u32 reqpartid = closid_rmid2reqpartid(closid, rmid);
+ u32 pmg = rmid2pmg(rmid);
- if (!cdp_enabled) {
- mpam_set_cpu_defaults(cpu, closid, closid, rmid, rmid);
- } else {
+ WARN_ON_ONCE(reqpartid > U16_MAX);
+ WARN_ON_ONCE(pmg > U8_MAX);
+
+ if (!cdp_enabled)
+ mpam_set_cpu_defaults(cpu, reqpartid, reqpartid, pmg, pmg);
+ else
/*
* When CDP is enabled, resctrl halves the closid range and we
* use odd/even partid for one closid.
*/
- u32 partid_d = resctrl_get_config_index(closid, CDP_DATA);
- u32 partid_i = resctrl_get_config_index(closid, CDP_CODE);
-
- mpam_set_cpu_defaults(cpu, partid_d, partid_i, rmid, rmid);
- }
+ mpam_set_cpu_defaults(cpu, reqpartid, reqpartid + 1, pmg, pmg);
}
void resctrl_arch_sync_cpu_closid_rmid(void *info)@@ -256,41 +309,41 @@ void resctrl_arch_sync_cpu_closid_rmid(void *info)
void resctrl_arch_set_closid_rmid(struct task_struct *tsk, u32 closid, u32 rmid)
{
- WARN_ON_ONCE(closid > U16_MAX);
- WARN_ON_ONCE(rmid > U8_MAX);
+ u32 reqpartid = closid_rmid2reqpartid(closid, rmid);
+ u32 pmg = rmid2pmg(rmid);
- if (!cdp_enabled) {
- mpam_set_task_partid_pmg(tsk, closid, closid, rmid, rmid);
- } else {
- u32 partid_d = resctrl_get_config_index(closid, CDP_DATA);
- u32 partid_i = resctrl_get_config_index(closid, CDP_CODE);
+ WARN_ON_ONCE(reqpartid > U16_MAX);
+ WARN_ON_ONCE(pmg > U8_MAX);
+
+ if (!cdp_enabled)
+ mpam_set_task_partid_pmg(tsk, reqpartid, reqpartid, pmg, pmg);
+ else
+ mpam_set_task_partid_pmg(tsk, reqpartid, reqpartid + 1, pmg, pmg);
- mpam_set_task_partid_pmg(tsk, partid_d, partid_i, rmid, rmid);
- }
}
bool resctrl_arch_match_closid(struct task_struct *tsk, u32 closid)
{
u64 regval = mpam_get_regval(tsk);
- u32 tsk_closid = FIELD_GET(MPAM1_EL1_PARTID_D, regval);
+ u32 tsk_partid = FIELD_GET(MPAM1_EL1_PARTID_D, regval);
+
+ tsk_partid = req2intpartid(tsk_partid);
if (cdp_enabled)
- tsk_closid >>= 1;
+ tsk_partid >>= 1;
- return tsk_closid == closid;
+ return tsk_partid == closid;
}
/* The task's pmg is not unique, the partid must be considered too */
bool resctrl_arch_match_rmid(struct task_struct *tsk, u32 closid, u32 rmid)
{
u64 regval = mpam_get_regval(tsk);
- u32 tsk_closid = FIELD_GET(MPAM1_EL1_PARTID_D, regval);
- u32 tsk_rmid = FIELD_GET(MPAM1_EL1_PMG_D, regval);
-
- if (cdp_enabled)
- tsk_closid >>= 1;
+ u32 tsk_partid = FIELD_GET(MPAM1_EL1_PARTID_D, regval);
+ u32 tsk_pmg = FIELD_GET(MPAM1_EL1_PMG_D, regval);
- return (tsk_closid == closid) && (tsk_rmid == rmid);
+ return (tsk_partid == closid_rmid2reqpartid(closid, rmid)) &&
+ (tsk_pmg == rmid2pmg(rmid));
}
struct rdt_resource *resctrl_arch_get_resource(enum resctrl_res_level l)@@ -412,7 +465,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
cfg.mon = resctrl_arch_rmid_idx_encode(closid, rmid);
cfg.match_pmg = true;
- cfg.pmg = rmid;
+ cfg.pmg = rmid2pmg(rmid);
cfg.opts = resctrl_evt_config_to_mpam(dom->mbm_local_evt_cfg);
if (irqs_disabled()) {@@ -420,7 +473,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
err = -EIO;
} else {
if (cdp_enabled) {
- cfg.partid = closid << 1;
+ cfg.partid = closid_rmid2reqpartid(closid, rmid);
err = mpam_msmon_read(dom->comp, &cfg, type, val);
if (err)
return err;@@ -430,7 +483,7 @@ int resctrl_arch_rmid_read(struct rdt_resource *r, struct rdt_mon_domain *d,
if (!err)
*val += cdp_val;
} else {
- cfg.partid = closid;
+ cfg.partid = closid_rmid2reqpartid(closid, rmid);
err = mpam_msmon_read(dom->comp, &cfg, type, val);
}
}@@ -449,18 +502,18 @@ void resctrl_arch_reset_rmid(struct rdt_resource *r, struct rdt_mon_domain *d,
cfg.mon = resctrl_arch_rmid_idx_encode(closid, rmid);
cfg.match_pmg = true;
- cfg.pmg = rmid;
+ cfg.pmg = rmid2pmg(rmid);
dom = container_of(d, struct mpam_resctrl_dom, resctrl_mon_dom);
if (cdp_enabled) {
- cfg.partid = closid << 1;
+ cfg.partid = closid_rmid2reqpartid(closid, rmid);
mpam_msmon_reset_mbwu(dom->comp, &cfg);
cfg.partid += 1;
mpam_msmon_reset_mbwu(dom->comp, &cfg);
} else {
- cfg.partid = closid;
+ cfg.partid = closid_rmid2reqpartid(closid, rmid);
mpam_msmon_reset_mbwu(dom->comp, &cfg);
}
}--
2.25.1