* [PATCH v1 0/2] Add _TZD method for ACPI thermal
@ 2024-11-07 3:26 Huisong Li
2024-11-07 3:26 ` [PATCH v1 1/2] ACPI: thermal: Support for linking devices associated with the thermal zone Huisong Li
2024-11-07 3:26 ` [PATCH v1 2/2] hwmon: (acpi_power_meter) Fix fail to load module on platform without _PMD method Huisong Li
0 siblings, 2 replies; 5+ messages in thread
From: Huisong Li @ 2024-11-07 3:26 UTC (permalink / raw)
To: linux-pm, rafael; +Cc: linux-kernel, liuyonglong, zhanjie9, lihuisong
This series is mainly used to support _TZD method for ACPI thermal so as
to directly know the devices associated with the thermal zone.
And fix a little issue for acpi_power_meter by the way.
Huisong Li (2):
ACPI: thermal: Support for linking devices associated with the thermal
zone
hwmon: (acpi_power_meter) Fix fail to load module on platform without
_PMD method
drivers/acpi/thermal.c | 114 ++++++++++++++++++++++++++++++-
drivers/hwmon/acpi_power_meter.c | 3 +-
2 files changed, 115 insertions(+), 2 deletions(-)
--
2.22.0
^ permalink raw reply [flat|nested] 5+ messages in thread* [PATCH v1 1/2] ACPI: thermal: Support for linking devices associated with the thermal zone 2024-11-07 3:26 [PATCH v1 0/2] Add _TZD method for ACPI thermal Huisong Li @ 2024-11-07 3:26 ` Huisong Li 2024-11-07 3:26 ` [PATCH v1 2/2] hwmon: (acpi_power_meter) Fix fail to load module on platform without _PMD method Huisong Li 1 sibling, 0 replies; 5+ messages in thread From: Huisong Li @ 2024-11-07 3:26 UTC (permalink / raw) To: linux-pm, rafael; +Cc: linux-kernel, liuyonglong, zhanjie9, lihuisong As ACPI spec said, '_TZD' evaluates to a package of device names. Each name corresponds to a device in the ACPI namespace that is associated with the thermal zone. The temperature reported by the thermal zone is roughly correspondent to that of each of the devices. Signed-off-by: Huisong Li <lihuisong@huawei.com> --- drivers/acpi/thermal.c | 114 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 113 insertions(+), 1 deletion(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 78db38c7076e..398195a5d42f 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -119,6 +119,9 @@ struct acpi_thermal { struct work_struct thermal_check_work; struct mutex thermal_check_lock; refcount_t thermal_check_count; + int num_domain_devices; + struct acpi_device **domain_devices; + struct kobject *holders_dir; }; /* -------------------------------------------------------------------------- @@ -589,6 +592,103 @@ static const struct thermal_zone_device_ops acpi_thermal_zone_ops = { .critical = acpi_thermal_zone_device_critical, }; +static void acpi_thermal_remove_domain_devices(struct acpi_thermal *tz) +{ + int i; + + if (!tz->num_domain_devices) + return; + + for (i = 0; i < tz->num_domain_devices; i++) { + struct acpi_device *obj = tz->domain_devices[i]; + + if (!obj) + continue; + + sysfs_remove_link(tz->holders_dir, + kobject_name(&obj->dev.kobj)); + acpi_dev_put(obj); + } + + kfree(tz->domain_devices); + kobject_put(tz->holders_dir); + tz->num_domain_devices = 0; +} + +static int acpi_thermal_read_domain_devices(struct acpi_thermal *tz) +{ + struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; + union acpi_object *pss; + acpi_status status; + int ret = 0; + int i; + + status = acpi_evaluate_object(tz->device->handle, "_TZD", NULL, + &buffer); + if (ACPI_FAILURE(status)) { + acpi_evaluation_failure_warn(tz->device->handle, "_TZD", + status); + return -ENODEV; + } + + pss = buffer.pointer; + if (!pss || + pss->type != ACPI_TYPE_PACKAGE) { + dev_err(&tz->device->dev, "Thermal zone invalid _TZD data\n"); + ret = -EFAULT; + goto end; + } + + if (!pss->package.count) + goto end; + + tz->domain_devices = kcalloc(pss->package.count, + sizeof(struct acpi_device *), GFP_KERNEL); + if (!tz->domain_devices) { + ret = -ENOMEM; + goto end; + } + + tz->holders_dir = kobject_create_and_add("measures", + &tz->device->dev.kobj); + if (!tz->holders_dir) { + ret = -ENOMEM; + goto exit_free; + } + + tz->num_domain_devices = pss->package.count; + for (i = 0; i < pss->package.count; i++) { + struct acpi_device *obj; + union acpi_object *element = &pss->package.elements[i]; + + /* Refuse non-references */ + if (element->type != ACPI_TYPE_LOCAL_REFERENCE) + continue; + + /* Create a symlink to domain objects */ + obj = acpi_get_acpi_dev(element->reference.handle); + tz->domain_devices[i] = obj; + if (!obj) + continue; + + ret = sysfs_create_link(tz->holders_dir, &obj->dev.kobj, + kobject_name(&obj->dev.kobj)); + if (ret) { + acpi_dev_put(obj); + tz->domain_devices[i] = NULL; + } + } + + ret = 0; + goto end; + +exit_free: + kfree(tz->domain_devices); +end: + kfree(buffer.pointer); + return ret; +} + static int acpi_thermal_zone_sysfs_add(struct acpi_thermal *tz) { struct device *tzdev = thermal_zone_device(tz->thermal_zone); @@ -602,8 +702,19 @@ static int acpi_thermal_zone_sysfs_add(struct acpi_thermal *tz) ret = sysfs_create_link(&tzdev->kobj, &tz->device->dev.kobj, "device"); if (ret) - sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); + goto remove_thermal_zone; + /* _TZD method is optional. */ + ret = acpi_thermal_read_domain_devices(tz); + if (ret != -ENODEV) + goto remove_device; + + return 0; + +remove_device: + sysfs_remove_link(&tz->device->dev.kobj, "device"); +remove_thermal_zone: + sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); return ret; } @@ -611,6 +722,7 @@ static void acpi_thermal_zone_sysfs_remove(struct acpi_thermal *tz) { struct device *tzdev = thermal_zone_device(tz->thermal_zone); + acpi_thermal_remove_domain_devices(tz); sysfs_remove_link(&tz->device->dev.kobj, "thermal_zone"); sysfs_remove_link(&tzdev->kobj, "device"); } -- 2.22.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v1 2/2] hwmon: (acpi_power_meter) Fix fail to load module on platform without _PMD method 2024-11-07 3:26 [PATCH v1 0/2] Add _TZD method for ACPI thermal Huisong Li 2024-11-07 3:26 ` [PATCH v1 1/2] ACPI: thermal: Support for linking devices associated with the thermal zone Huisong Li @ 2024-11-07 3:26 ` Huisong Li 2024-11-07 10:55 ` Rafael J. Wysocki 1 sibling, 1 reply; 5+ messages in thread From: Huisong Li @ 2024-11-07 3:26 UTC (permalink / raw) To: linux-pm, rafael; +Cc: linux-kernel, liuyonglong, zhanjie9, lihuisong As ACPI spec said, _PMD method is optional. The acpi_power_meter shouldn't fail to load when the platform hasn't _PMD method. Signed-off-by: Huisong Li <lihuisong@huawei.com> --- drivers/hwmon/acpi_power_meter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c index 6c8a9c863528..2f1c9d97ad21 100644 --- a/drivers/hwmon/acpi_power_meter.c +++ b/drivers/hwmon/acpi_power_meter.c @@ -680,8 +680,9 @@ static int setup_attrs(struct acpi_power_meter_resource *resource) { int res = 0; + /* _PMD method is optional. */ res = read_domain_devices(resource); - if (res) + if (res != -ENODEV) return res; if (resource->caps.flags & POWER_METER_CAN_MEASURE) { -- 2.22.0 ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1 2/2] hwmon: (acpi_power_meter) Fix fail to load module on platform without _PMD method 2024-11-07 3:26 ` [PATCH v1 2/2] hwmon: (acpi_power_meter) Fix fail to load module on platform without _PMD method Huisong Li @ 2024-11-07 10:55 ` Rafael J. Wysocki 2024-11-07 12:07 ` lihuisong (C) 0 siblings, 1 reply; 5+ messages in thread From: Rafael J. Wysocki @ 2024-11-07 10:55 UTC (permalink / raw) To: Huisong Li; +Cc: linux-pm, rafael, linux-kernel, liuyonglong, zhanjie9 On Thu, Nov 7, 2024 at 4:37 AM Huisong Li <lihuisong@huawei.com> wrote: > > As ACPI spec said, _PMD method is optional. The acpi_power_meter > shouldn't fail to load when the platform hasn't _PMD method. > > Signed-off-by: Huisong Li <lihuisong@huawei.com> How exactly is this related to the first patch? > --- > drivers/hwmon/acpi_power_meter.c | 3 ++- > 1 file changed, 2 insertions(+), 1 deletion(-) > > diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c > index 6c8a9c863528..2f1c9d97ad21 100644 > --- a/drivers/hwmon/acpi_power_meter.c > +++ b/drivers/hwmon/acpi_power_meter.c > @@ -680,8 +680,9 @@ static int setup_attrs(struct acpi_power_meter_resource *resource) > { > int res = 0; > > + /* _PMD method is optional. */ > res = read_domain_devices(resource); > - if (res) > + if (res != -ENODEV) > return res; > > if (resource->caps.flags & POWER_METER_CAN_MEASURE) { > -- > 2.22.0 > > ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v1 2/2] hwmon: (acpi_power_meter) Fix fail to load module on platform without _PMD method 2024-11-07 10:55 ` Rafael J. Wysocki @ 2024-11-07 12:07 ` lihuisong (C) 0 siblings, 0 replies; 5+ messages in thread From: lihuisong (C) @ 2024-11-07 12:07 UTC (permalink / raw) To: Rafael J. Wysocki; +Cc: linux-pm, linux-kernel, liuyonglong, zhanjie9 在 2024/11/7 18:55, Rafael J. Wysocki 写道: > On Thu, Nov 7, 2024 at 4:37 AM Huisong Li <lihuisong@huawei.com> wrote: >> As ACPI spec said, _PMD method is optional. The acpi_power_meter >> shouldn't fail to load when the platform hasn't _PMD method. >> >> Signed-off-by: Huisong Li <lihuisong@huawei.com> > How exactly is this related to the first patch? They're not related, they're just similar. Sorry, I should separate them😂 Should I resend them now? > >> --- >> drivers/hwmon/acpi_power_meter.c | 3 ++- >> 1 file changed, 2 insertions(+), 1 deletion(-) >> >> diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c >> index 6c8a9c863528..2f1c9d97ad21 100644 >> --- a/drivers/hwmon/acpi_power_meter.c >> +++ b/drivers/hwmon/acpi_power_meter.c >> @@ -680,8 +680,9 @@ static int setup_attrs(struct acpi_power_meter_resource *resource) >> { >> int res = 0; >> >> + /* _PMD method is optional. */ >> res = read_domain_devices(resource); >> - if (res) >> + if (res != -ENODEV) >> return res; >> >> if (resource->caps.flags & POWER_METER_CAN_MEASURE) { >> -- >> 2.22.0 >> >> > . ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2024-11-07 12:07 UTC | newest] Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2024-11-07 3:26 [PATCH v1 0/2] Add _TZD method for ACPI thermal Huisong Li 2024-11-07 3:26 ` [PATCH v1 1/2] ACPI: thermal: Support for linking devices associated with the thermal zone Huisong Li 2024-11-07 3:26 ` [PATCH v1 2/2] hwmon: (acpi_power_meter) Fix fail to load module on platform without _PMD method Huisong Li 2024-11-07 10:55 ` Rafael J. Wysocki 2024-11-07 12:07 ` lihuisong (C)
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®