[RFC PATCH 20/36] arm_mpam: Probe the hardware features resctrl supports
Jonathan Cameron
Jonathan.Cameron at huawei.com
Mon Jul 28 09:16:28 PDT 2025
}
> >
> > +/*
> > + * IHI009A.a has this nugget: "If a monitor does not support automatic behaviour
> > + * of NRDY, software can use this bit for any purpose" - so hardware might not
> > + * implement this - but it isn't RES0.
> > + *
> > + * Try and see what values stick in this bit. If we can write either value,
> > + * its probably not implemented by hardware.
> > + */
> > +#define mpam_ris_hw_probe_hw_nrdy(_ris, _mon_reg, _result) \
> > +do { \
> > + u32 now; \
> > + u64 mon_sel; \
> > + bool can_set, can_clear; \
> > + struct mpam_msc *_msc = _ris->vmsc->msc; \
> > + \
> > + if (WARN_ON_ONCE(!mpam_mon_sel_inner_lock(_msc))) { \
> > + _result = false; \
> > + break; \
> > + } \
> > + mon_sel = FIELD_PREP(MSMON_CFG_MON_SEL_MON_SEL, 0) | \
> > + FIELD_PREP(MSMON_CFG_MON_SEL_RIS, _ris->ris_idx); \
> > + mpam_write_monsel_reg(_msc, CFG_MON_SEL, mon_sel); \
> > + \
> > + mpam_write_monsel_reg(_msc, _mon_reg, MSMON___NRDY); \
> > + now = mpam_read_monsel_reg(_msc, _mon_reg); \
> > + can_set = now & MSMON___NRDY; \
> > + \
> > + mpam_write_monsel_reg(_msc, _mon_reg, 0); \
> > + now = mpam_read_monsel_reg(_msc, _mon_reg); \
> > + can_clear = !(now & MSMON___NRDY); \
> > + mpam_mon_sel_inner_unlock(_msc); \
> > + \
> > + _result = (!can_set || !can_clear); \
> > +} while (0)
> It is a bit surprising that something that looks like a function
> modifies a boolean passed by value. Consider continuing the pattern you
> have above:
> #define mpam_ris_hw_probe_hw_nrdy(_ris, _mon_reg, _result)
> _mpam_ris_hw_probe_hw_nrdy(_ris, MSMON##_mon_reg, _result)
>
> with signature:
> void _mpam_ris_hw_probe_hw_nrdy(struct mpam_msc *msc, u16 reg, bool
> *hw_managed);
>
> and using the _mpam functions from the new _mpam_ris_hw_probe_hw_nrdy().
>
Agreed that this is ugly. Only a tiny bit of macro stuff is actually going on here.
I'd make it function.
If you really want to construct MSMON_CSU etc then wrap that helper with
a macro that builds reg from the name.
I might have missed something though in converting this.
The version I have has some other changes though so not trivial to post here :(
More information about the linux-arm-kernel
mailing list