Re: [PATCH 3/5] platform/x86: lenovo-wmi-other: Factor out tunable_attr_01 definition into a macro
From: Mark Pearson
Date: Wed Nov 18 2026 - 17:20:10 EST
On Wed, Nov 18, 2026, at 1:58 PM, Rong Zhang wrote:
> Currently, all definitions of statically allocated tunable_attr_01
> variables are open-coded, making them hard to refactor.
>
> Add a macro to define statically allocated tunable_attr_01 variables so
> that further refactoring only touches the macro itself.
>
> Meanwhile, move the definition of statically allocated tunable_attr_01
> variables before the definition of struct lwmi_om_priv, so that upcoming
> changes can reference the former as needed.
>
> No functional change intended.
>
> Signed-off-by: Rong Zhang <i@xxxxxxxx>
> ---
> drivers/platform/x86/lenovo/wmi-other.c | 178 +++++++-------------------------
> 1 file changed, 38 insertions(+), 140 deletions(-)
>
> diff --git a/drivers/platform/x86/lenovo/wmi-other.c
> b/drivers/platform/x86/lenovo/wmi-other.c
> index 4d51b05a5acf..252ef775f300 100644
> --- a/drivers/platform/x86/lenovo/wmi-other.c
> +++ b/drivers/platform/x86/lenovo/wmi-other.c
> @@ -130,6 +130,44 @@ struct lwmi_fan_info {
> long max_rpm;
> };
>
> +struct tunable_attr_01 {
> + u8 feature_id;
> + u8 device_id;
> + u8 type_id;
Really just a minor note that everywhere else in the code goes device, feature, type.
If you end up doing a v2 can you swap the order of feature and device in the above - purely for universal karma?
> + u8 cd_mode_id; /* mode arg for searching capdata */
> + u8 cv_mode_id; /* mode arg for set/get current_value */
> +};
> +
> +#define DEFINE_TUNABLE_ATTR_01(_name, _device, _feature, _type) \
> + static struct tunable_attr_01 _name = { \
> + .device_id = LWMI_DEVICE_ID_##_device, \
> + .feature_id = LWMI_FEATURE_ID_##_feature, \
> + .type_id = LWMI_TYPE_ID_##_type, \
> + }
> +
> +DEFINE_TUNABLE_ATTR_01(ppt_pl1_spl, CPU, CPU_SPL, NONE);
> +DEFINE_TUNABLE_ATTR_01(ppt_pl1_spl_cl, CPU, CPU_SPL, CROSSLOAD);
> +DEFINE_TUNABLE_ATTR_01(ppt_pl2_sppt, CPU, CPU_SPPT, NONE);
> +DEFINE_TUNABLE_ATTR_01(ppt_pl2_sppt_cl, CPU, CPU_SPPT, CROSSLOAD);
> +DEFINE_TUNABLE_ATTR_01(ppt_pl3_fppt, CPU, CPU_FPPT, NONE);
> +DEFINE_TUNABLE_ATTR_01(ppt_pl3_fppt_cl, CPU, CPU_FPPT, CROSSLOAD);
> +DEFINE_TUNABLE_ATTR_01(cpu_temp, CPU, CPU_TEMP, NONE);
> +DEFINE_TUNABLE_ATTR_01(ppt_pl1_apu_spl, CPU, CPU_APU, NONE);
> +DEFINE_TUNABLE_ATTR_01(ppt_cpu_cl, CPU, CPU_CL, NONE);
> +DEFINE_TUNABLE_ATTR_01(ppt_pl1_tau, CPU, CPU_TAU, NONE);
> +DEFINE_TUNABLE_ATTR_01(ppt_pl4_ipl, CPU, CPU_IPL, NONE);
> +DEFINE_TUNABLE_ATTR_01(ppt_pl4_ipl_cl, CPU, CPU_IPL, CROSSLOAD);
> +DEFINE_TUNABLE_ATTR_01(gpu_nv_ppab, GPU, GPU_NV_PPAB, NONE);
> +DEFINE_TUNABLE_ATTR_01(gpu_nv_ctgp, GPU, GPU_NV_CTGP, NONE);
> +DEFINE_TUNABLE_ATTR_01(gpu_temp, GPU, GPU_TEMP, NONE);
> +DEFINE_TUNABLE_ATTR_01(gpu_nv_ac_offset, GPU, GPU_AC_OFFSET, NONE);
> +DEFINE_TUNABLE_ATTR_01(dgpu_boost_clk, GPU, DGPU_BOOST_CLK, NONE);
> +DEFINE_TUNABLE_ATTR_01(dgpu_enable, GPU, DGPU_EN, NONE);
> +DEFINE_TUNABLE_ATTR_01(gpu_mode, GPU, GPU_MODE, NONE);
> +DEFINE_TUNABLE_ATTR_01(dgpu_didvid, GPU, DGPU_DIDVID, NONE);
> +DEFINE_TUNABLE_ATTR_01(gpu_nv_bpl, GPU, GPU_NV_BPL, NONE);
> +DEFINE_TUNABLE_ATTR_01(gpu_nv_cpu_boost, GPU, GPU_NV_CPU_BOOST, NONE);
> +
> struct lwmi_om_priv {
> struct component_master_ops *ops;
>
> @@ -966,14 +1004,6 @@ static void lwmi_om_psy_remove(struct lwmi_om_priv *priv)
>
> /* ======== fw_attributes (component: lenovo-wmi-capdata 01) ======== */
>
> -struct tunable_attr_01 {
> - u8 feature_id;
> - u8 device_id;
> - u8 type_id;
> - u8 cd_mode_id; /* mode arg for searching capdata */
> - u8 cv_mode_id; /* mode arg for set/get current_value */
> -};
> -
> /**
> * tunable_attr_01_id() - Formats a tunable_attr_01 to a capdata
> attribute ID
> * @attr: The tunable_attr_01 to format.
> @@ -986,138 +1016,6 @@ static u32 tunable_attr_01_id(const struct
> tunable_attr_01 *attr, u8 mode)
> return lwmi_attr_id(attr->device_id, attr->feature_id, mode,
> attr->type_id);
> }
>
> -static struct tunable_attr_01 ppt_pl1_spl = {
> - .device_id = LWMI_DEVICE_ID_CPU,
> - .feature_id = LWMI_FEATURE_ID_CPU_SPL,
> - .type_id = LWMI_TYPE_ID_NONE,
> -};
> -
> -static struct tunable_attr_01 ppt_pl1_spl_cl = {
> - .device_id = LWMI_DEVICE_ID_CPU,
> - .feature_id = LWMI_FEATURE_ID_CPU_SPL,
> - .type_id = LWMI_TYPE_ID_CROSSLOAD,
> -};
> -
> -static struct tunable_attr_01 ppt_pl2_sppt = {
> - .device_id = LWMI_DEVICE_ID_CPU,
> - .feature_id = LWMI_FEATURE_ID_CPU_SPPT,
> - .type_id = LWMI_TYPE_ID_NONE,
> -};
> -
> -static struct tunable_attr_01 ppt_pl2_sppt_cl = {
> - .device_id = LWMI_DEVICE_ID_CPU,
> - .feature_id = LWMI_FEATURE_ID_CPU_SPPT,
> - .type_id = LWMI_TYPE_ID_CROSSLOAD,
> -};
> -
> -static struct tunable_attr_01 ppt_pl3_fppt = {
> - .device_id = LWMI_DEVICE_ID_CPU,
> - .feature_id = LWMI_FEATURE_ID_CPU_FPPT,
> - .type_id = LWMI_TYPE_ID_NONE,
> -};
> -
> -static struct tunable_attr_01 ppt_pl3_fppt_cl = {
> - .device_id = LWMI_DEVICE_ID_CPU,
> - .feature_id = LWMI_FEATURE_ID_CPU_FPPT,
> - .type_id = LWMI_TYPE_ID_CROSSLOAD,
> -};
> -
> -static struct tunable_attr_01 cpu_temp = {
> - .device_id = LWMI_DEVICE_ID_CPU,
> - .feature_id = LWMI_FEATURE_ID_CPU_TEMP,
> - .type_id = LWMI_TYPE_ID_NONE,
> -};
> -
> -static struct tunable_attr_01 ppt_pl1_apu_spl = {
> - .device_id = LWMI_DEVICE_ID_CPU,
> - .feature_id = LWMI_FEATURE_ID_CPU_APU,
> - .type_id = LWMI_TYPE_ID_NONE,
> -};
> -
> -static struct tunable_attr_01 ppt_cpu_cl = {
> - .device_id = LWMI_DEVICE_ID_CPU,
> - .feature_id = LWMI_FEATURE_ID_CPU_CL,
> - .type_id = LWMI_TYPE_ID_NONE,
> -};
> -
> -static struct tunable_attr_01 ppt_pl1_tau = {
> - .device_id = LWMI_DEVICE_ID_CPU,
> - .feature_id = LWMI_FEATURE_ID_CPU_TAU,
> - .type_id = LWMI_TYPE_ID_NONE,
> -};
> -
> -static struct tunable_attr_01 ppt_pl4_ipl = {
> - .device_id = LWMI_DEVICE_ID_CPU,
> - .feature_id = LWMI_FEATURE_ID_CPU_IPL,
> - .type_id = LWMI_TYPE_ID_NONE,
> -};
> -
> -static struct tunable_attr_01 ppt_pl4_ipl_cl = {
> - .device_id = LWMI_DEVICE_ID_CPU,
> - .feature_id = LWMI_FEATURE_ID_CPU_IPL,
> - .type_id = LWMI_TYPE_ID_CROSSLOAD,
> -};
> -
> -static struct tunable_attr_01 gpu_nv_ppab = {
> - .device_id = LWMI_DEVICE_ID_GPU,
> - .feature_id = LWMI_FEATURE_ID_GPU_NV_PPAB,
> - .type_id = LWMI_TYPE_ID_NONE,
> -};
> -
> -static struct tunable_attr_01 gpu_nv_ctgp = {
> - .device_id = LWMI_DEVICE_ID_GPU,
> - .feature_id = LWMI_FEATURE_ID_GPU_NV_CTGP,
> - .type_id = LWMI_TYPE_ID_NONE,
> -};
> -
> -static struct tunable_attr_01 gpu_temp = {
> - .device_id = LWMI_DEVICE_ID_GPU,
> - .feature_id = LWMI_FEATURE_ID_GPU_TEMP,
> - .type_id = LWMI_TYPE_ID_NONE,
> -};
> -
> -static struct tunable_attr_01 gpu_nv_ac_offset = {
> - .device_id = LWMI_DEVICE_ID_GPU,
> - .feature_id = LWMI_FEATURE_ID_GPU_AC_OFFSET,
> - .type_id = LWMI_TYPE_ID_NONE,
> -};
> -
> -static struct tunable_attr_01 dgpu_boost_clk = {
> - .device_id = LWMI_DEVICE_ID_GPU,
> - .feature_id = LWMI_FEATURE_ID_DGPU_BOOST_CLK,
> - .type_id = LWMI_TYPE_ID_NONE,
> -};
> -
> -static struct tunable_attr_01 dgpu_enable = {
> - .device_id = LWMI_DEVICE_ID_GPU,
> - .feature_id = LWMI_FEATURE_ID_DGPU_EN,
> - .type_id = LWMI_TYPE_ID_NONE,
> -};
> -
> -static struct tunable_attr_01 gpu_mode = {
> - .device_id = LWMI_DEVICE_ID_GPU,
> - .feature_id = LWMI_FEATURE_ID_GPU_MODE,
> - .type_id = LWMI_TYPE_ID_NONE,
> -};
> -
> -static struct tunable_attr_01 dgpu_didvid = {
> - .device_id = LWMI_DEVICE_ID_GPU,
> - .feature_id = LWMI_FEATURE_ID_DGPU_DIDVID,
> - .type_id = LWMI_TYPE_ID_NONE,
> -};
> -
> -static struct tunable_attr_01 gpu_nv_bpl = {
> - .device_id = LWMI_DEVICE_ID_GPU,
> - .feature_id = LWMI_FEATURE_ID_GPU_NV_BPL,
> - .type_id = LWMI_TYPE_ID_NONE,
> -};
> -
> -static struct tunable_attr_01 gpu_nv_cpu_boost = {
> - .device_id = LWMI_DEVICE_ID_GPU,
> - .feature_id = LWMI_FEATURE_ID_GPU_NV_CPU_BOOST,
> - .type_id = LWMI_TYPE_ID_NONE,
> -};
> -
> struct capdata01_attr {
> struct kobj_attribute kobj_attr;
> struct tunable_attr_01 *tunable_attr;
>
> --
> 2.55.0
Looks good to me (I'm OK if my comment above is ignored)
Reviewed-by: Mark Pearson <mpearson-lenovo@xxxxxxxxx>
Mark