driver inclusion category: bugfix bugzilla: https://atomgit.com/openeuler/kernel/issues/9840 ---------------------------------------------------------------------- Add workaround for hisi cpbm_wd When a specific device cannot be identified through the IIDR. Signed-off-by: Yifan Wu <wuyifan50@huawei.com> Signed-off-by: Hongye Lin <linhongye@h-partners.com> --- drivers/platform/mpam/mpam_devices.c | 125 +++++++++++++++----------- drivers/platform/mpam/mpam_internal.h | 8 +- drivers/platform/mpam/mpam_resctrl.c | 39 ++++---- 3 files changed, 104 insertions(+), 68 deletions(-) diff --git a/drivers/platform/mpam/mpam_devices.c b/drivers/platform/mpam/mpam_devices.c index 217155f612e3..6b9b7433b360 100644 --- a/drivers/platform/mpam/mpam_devices.c +++ b/drivers/platform/mpam/mpam_devices.c @@ -113,6 +113,9 @@ static const struct midr_range hisi_cpus[] = { #define HIP12_ACPI_PLAT { "HISI ", "HIP12 ", 0, ACPI_SIG_MPAM, all_versions } #define HIP12B_ACPI_PLAT { "HISI ", "HIP12B ", 0, ACPI_SIG_MPAM, all_versions } #define HIP13_ACPI_PLAT { "HISI ", "HIP13 ", 0, ACPI_SIG_MPAM, all_versions } +u16 hisi_config_cpbm_wd; +u16 hisi_hardware_cpbm_wd; +u32 hisi_valid_cpbm_mask; static u32 __mpam_read_reg(struct mpam_msc *msc, u16 reg) { @@ -619,6 +622,19 @@ static struct mpam_msc_ris *mpam_get_or_create_ris(struct mpam_msc *msc, return found; } +static int mpam_enable_quirk_hisi_cpbm_wd(struct mpam_msc *msc, const struct mpam_quirk *quirk) +{ + struct mpam_msc_ris *ris; + + list_for_each_entry(ris, &msc->ris, msc_list) { + struct mpam_class *class = ris->comp->class; + + if (class->type == MPAM_CLASS_CACHE && class->level == 3) + return 0; + } + return -EINVAL; +} + static const struct mpam_quirk mpam_quirks[] = { { .iidr_mask = MPAM_IIDR_MATCH_ONE, @@ -629,6 +645,15 @@ static const struct mpam_quirk mpam_quirks[] = { {} }, .workaround = HISI_SHRINK_PMG_MAX, }, + { + .init = mpam_enable_quirk_hisi_cpbm_wd, + .iidr_mask = MPAM_IIDR_MATCH_ONE, + .plat = (struct acpi_platform_list[]) { + HIP12_ACPI_PLAT, + HIP13_ACPI_PLAT, + {} }, + .workaround = HISI_EXPAND_CPBM_WD, + }, { NULL } /* Sentinel */ }; @@ -653,21 +678,26 @@ static void mpam_enable_quirks(struct mpam_msc *msc) } } -u16 mpam_cpbm_wd_hisi_workaround(u16 cpbm_wd, enum mpam_device_features feat, - u8 cache_level) +void mpam_cpbm_wd_hisi_workaround(u16 cpor_idr_cpbm_wd, struct mpam_class *class) { - if (cache_level != 3) - return cpbm_wd; + struct cpu_cacheinfo *cpu_cinfo; + struct cacheinfo *cinfo; + + if (hisi_config_cpbm_wd) + return; - if (is_midr_in_range_list(hip12_cpus)) { - if (feat == mpam_feat_cpor_part) - return 19; - else if (feat == mpam_feat_ccap_part || - feat == mpam_feat_cmin) - return 21; + cpu_cinfo = get_cpu_cacheinfo(smp_processor_id()); + for (unsigned int i = 0; i < cpu_cinfo->num_leaves; i++) { + cinfo = &cpu_cinfo->info_list[i]; + if (cinfo->level == class->level) { + hisi_config_cpbm_wd = cinfo->ways_of_associativity; + hisi_hardware_cpbm_wd = hisi_config_cpbm_wd * 2 - cpor_idr_cpbm_wd; + hisi_valid_cpbm_mask = BIT_MASK(cpor_idr_cpbm_wd) - 1; + return; + } } - return cpbm_wd; + return; } static struct dentry *mpam_debugfs; @@ -700,9 +730,11 @@ static void mpam_ris_hw_probe(struct mpam_msc_ris *ris) if (FIELD_GET(MPAMF_IDR_HAS_CPOR_PART, ris->idr)) { ris->cpor_idr = mpam_read_partsel_reg(msc, CPOR_IDR); - props->cpbm_wd = mpam_cpbm_wd_hisi_workaround( - FIELD_GET(MPAMF_CPOR_IDR_CPBM_WD, ris->cpor_idr), - mpam_feat_cpor_part, class->level); + props->cpbm_wd = FIELD_GET(MPAMF_CPOR_IDR_CPBM_WD, ris->cpor_idr); + + if (mpam_has_quirk(HISI_EXPAND_CPBM_WD, msc)) + mpam_cpbm_wd_hisi_workaround(props->cpbm_wd, class); + if (props->cpbm_wd) mpam_set_feature(mpam_feat_cpor_part, props); } @@ -1399,37 +1431,25 @@ static void mpam_reset_msc_bitmap(struct mpam_msc *msc, u16 reg, u16 wd) __mpam_write_reg(msc, reg, bm); } -static u32 mpam_cpbm_hisi_workaround(u32 cpbm, u8 cache_level) +/* + * Hardware restriction: cpor_idr_cpbm_wd to hisi_hardware_cpbm_wd + * only have half the normal capacity. + */ +static u32 mpam_cpbm_hisi_workaround(u32 cpbm, struct mpam_class *class) { - if (cache_level != 3 || !is_midr_in_range_list(hip12_cpus)) - return cpbm; - - if (cpbm & BIT(18)) - cpbm |= (BIT(19) | BIT(20)); - - if (cpbm & BIT(17)) - cpbm |= BIT(18); - else - cpbm &= ~BIT(18); + u16 cpor_idr_cpbm_wd, shift, i; + cpor_idr_cpbm_wd = class->props.cpbm_wd; + for (i = hisi_config_cpbm_wd - 1; i >= cpor_idr_cpbm_wd; i--) { + shift = i * 2 - cpor_idr_cpbm_wd; + if (cpbm & BIT(i)) + cpbm |= GENMASK(shift + 1, shift); + else + cpbm &= ~GENMASK(shift + 1, shift); + } return cpbm; } -bool mpam_cpbm_hisi_check_invalid(struct rdt_resource *r, - unsigned long val) -{ - if (!is_midr_in_range_list(hip12_cpus)) - return false; - - if (r->cache_level != 3) - return false; - - if (val & ~(BIT(18) | BIT(17))) - return false; - - return true; -} - static u16 mpam_intpri_default_val(struct mpam_msc_ris *ris) { struct mpam_class *class = ris->comp->class; @@ -1486,16 +1506,21 @@ static void mpam_reprogram_ris_partid(struct mpam_msc_ris *ris, u16 partid, } if (mpam_has_feature(mpam_feat_cpor_part, rprops)) { - if (mpam_has_feature(mpam_feat_cpor_part, cfg)) - mpam_write_partsel_reg(msc, CPBM, - mpam_cpbm_hisi_workaround(cfg->cpbm, - ris->comp->class->level)); - else - mpam_reset_msc_bitmap(msc, MPAMCFG_CPBM, - mpam_cpbm_wd_hisi_workaround( - rprops->cpbm_wd, - mpam_feat_cpor_part, - ris->comp->class->level)); + if (mpam_has_feature(mpam_feat_cpor_part, cfg)) { + u32 cpbm = cfg->cpbm; + + if (mpam_has_quirk(HISI_EXPAND_CPBM_WD, msc)) + cpbm = mpam_cpbm_hisi_workaround(cpbm, ris->comp->class); + + mpam_write_partsel_reg(msc, CPBM, cpbm); + } else { + u16 cpbm_wd = rprops->cpbm_wd; + + if (mpam_has_quirk(HISI_EXPAND_CPBM_WD, msc)) + cpbm_wd = hisi_hardware_cpbm_wd; + + mpam_reset_msc_bitmap(msc, MPAMCFG_CPBM, cpbm_wd); + } } if (mpam_has_feature(mpam_feat_ccap_part, rprops)) { diff --git a/drivers/platform/mpam/mpam_internal.h b/drivers/platform/mpam/mpam_internal.h index acce68708de2..65bcae070d99 100644 --- a/drivers/platform/mpam/mpam_internal.h +++ b/drivers/platform/mpam/mpam_internal.h @@ -27,6 +27,11 @@ DECLARE_STATIC_KEY_FALSE(mpam_enabled); */ #define MPAM_RESTRL_EVT_CONFIG_VALID (READS_TO_LOCAL_MEM | NON_TEMP_WRITE_TO_LOCAL_MEM) +/* Values for the HISI workaround */ +extern u16 hisi_config_cpbm_wd; +extern u16 hisi_hardware_cpbm_wd; +extern u32 hisi_valid_cpbm_mask; + static inline bool mpam_is_enabled(void) { return static_branch_likely(&mpam_enabled); @@ -149,6 +154,7 @@ static inline void mpam_clear_feature(enum mpam_device_features feat, /* Workaround bits for msc->quirks */ enum mpam_device_quirks { HISI_SHRINK_PMG_MAX, + HISI_EXPAND_CPBM_WD, MPAM_QUIRK_LAST }; @@ -367,8 +373,6 @@ int mpam_resctrl_offline_cpu(unsigned int cpu); int mpam_resctrl_setup(void); void mpam_resctrl_exit(void); -u16 mpam_cpbm_wd_hisi_workaround(u16 cpbm_wd, enum mpam_device_features feat, u8 cache_level); -bool mpam_cpbm_hisi_check_invalid(struct rdt_resource *r, unsigned long val); u32 mpam_min_cbm_bits(enum resctrl_res_level rid); /* diff --git a/drivers/platform/mpam/mpam_resctrl.c b/drivers/platform/mpam/mpam_resctrl.c index a67fc24b3b04..d04e1f0b1911 100644 --- a/drivers/platform/mpam/mpam_resctrl.c +++ b/drivers/platform/mpam/mpam_resctrl.c @@ -880,7 +880,7 @@ static u16 percent_to_mbw_max(u32 pc, u8 wd) return value; } -static u16 percent_to_ca_max(u32 pc, u8 wd) +static u16 percent_to_ca_max(u32 pc, u8 wd, struct mpam_class *class) { struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3); u32 valid_max, ca_max; @@ -888,9 +888,10 @@ static u16 percent_to_ca_max(u32 pc, u8 wd) if (read_cpuid_implementor() != ARM_CPU_IMP_HISI) return percent_to_mbw_max(pc, wd); - valid_max = mpam_cpbm_wd_hisi_workaround(l3->cache.cbm_len, - mpam_feat_ccap_part, - l3->cache_level); + valid_max = l3->cache.cbm_len; + + if (mpam_has_quirk(HISI_EXPAND_CPBM_WD, class)) + valid_max = hisi_hardware_cpbm_wd; if (pc >= MAX_MBA_BW) return valid_max << (16 - wd); @@ -899,7 +900,7 @@ static u16 percent_to_ca_max(u32 pc, u8 wd) return ca_max << (16 - wd); } -static u16 ca_max_to_percent(u16 ca_max, u8 wd) +static u16 ca_max_to_percent(u16 ca_max, u8 wd, struct mpam_class *class) { struct rdt_resource *l3 = resctrl_arch_get_resource(RDT_RESOURCE_L3); u32 valid_max; @@ -907,9 +908,10 @@ static u16 ca_max_to_percent(u16 ca_max, u8 wd) if (read_cpuid_implementor() != ARM_CPU_IMP_HISI) return mbw_max_to_percent(ca_max, wd); - valid_max = mpam_cpbm_wd_hisi_workaround(l3->cache.cbm_len, - mpam_feat_ccap_part, - l3->cache_level); + valid_max = l3->cache.cbm_len; + + if (mpam_has_quirk(HISI_EXPAND_CPBM_WD, class)) + valid_max = hisi_hardware_cpbm_wd; ca_max = ca_max >> (16 - wd); if (ca_max >= valid_max) @@ -1157,13 +1159,17 @@ static int mpam_resctrl_resource_init(struct mpam_resctrl_res *res) struct rdt_resource *r = &res->resctrl_res; bool has_mbwu = class_has_usable_mbwu(class); bool has_csu = cache_has_usable_csu(class); + u16 cpbm_wd; /* Is this one of the two well-known caches? */ switch (res->resctrl_res.rid) { case RDT_RESOURCE_L2: case RDT_RESOURCE_L3: + cpbm_wd = class->props.cpbm_wd; + if (mpam_has_quirk(HISI_EXPAND_CPBM_WD, class)) + cpbm_wd = hisi_config_cpbm_wd; /* TODO: Scaling is not yet supported */ - r->cache.cbm_len = class->props.cpbm_wd; + r->cache.cbm_len = cpbm_wd; r->cache.arch_has_sparse_bitmasks = true; /* mpam_devices will reject empty bitmaps */ @@ -1173,8 +1179,8 @@ static int mpam_resctrl_resource_init(struct mpam_resctrl_res *res) r->format_str = "%d=%0*x"; r->schema_fmt = RESCTRL_SCHEMA_BITMAP; r->fflags = RFTYPE_RES_CACHE; - r->default_ctrl = BIT_MASK(class->props.cpbm_wd) - 1; - r->data_width = (class->props.cpbm_wd + 3) / 4; + r->default_ctrl = BIT_MASK(cpbm_wd) - 1; + r->data_width = (cpbm_wd + 3) / 4; r->cache_level = class->level; /* @@ -1653,9 +1659,9 @@ u32 resctrl_arch_get_config(struct rdt_resource *r, struct rdt_domain *d, /* TODO: Scaling is not yet supported */ return cfg->cpbm; case mpam_feat_ccap_part: - return ca_max_to_percent(cfg->cmax, cprops->cmax_wd); + return ca_max_to_percent(cfg->cmax, cprops->cmax_wd, res->class); case mpam_feat_cmin: - return ca_max_to_percent(cfg->cmin, cprops->cmax_wd); + return ca_max_to_percent(cfg->cmin, cprops->cmax_wd, res->class); case mpam_feat_intpri_part: return cfg->intpri; case mpam_feat_mbw_part: @@ -1709,7 +1715,8 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d, switch (r->rid) { case RDT_RESOURCE_L2: case RDT_RESOURCE_L3: - if (mpam_cpbm_hisi_check_invalid(r, cfg_val)) + if (mpam_has_quirk(HISI_EXPAND_CPBM_WD, res->class) && + !(cfg_val & hisi_valid_cpbm_mask)) return -EINVAL; /* TODO: Scaling is not yet supported */ @@ -1718,12 +1725,12 @@ int resctrl_arch_update_one(struct rdt_resource *r, struct rdt_domain *d, break; case RDT_RESOURCE_L2_MAX: case RDT_RESOURCE_L3_MAX: - cfg.cmax = percent_to_ca_max(cfg_val, cprops->cmax_wd); + cfg.cmax = percent_to_ca_max(cfg_val, cprops->cmax_wd, res->class); mpam_set_feature(mpam_feat_ccap_part, &cfg); break; case RDT_RESOURCE_L2_MIN: case RDT_RESOURCE_L3_MIN: - cfg.cmin = percent_to_ca_max(cfg_val, cprops->cmax_wd); + cfg.cmin = percent_to_ca_max(cfg_val, cprops->cmax_wd, res->class); mpam_set_feature(mpam_feat_cmin, &cfg); break; case RDT_RESOURCE_L2_PRI: -- 2.33.0