thermal/int340x_thermal: Export GDDV
PATCH 1/3 thermal/int340x_thermal: Export GDDV
From: Matthew Garrett <[email protected]>
Implementing DPTF properly requires making use of firmware-provided information associated with the INT3400 device. Calling GDDV provides a buffer of information which userland can then interpret to determine appropriate DPTF policy.
--- .../intel/int340x_thermal/int3400_thermal.c | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+)
drivers/thermal/intel/int340x_thermal/int3400_thermal.c +60 -0
@@ -52,6 +52,25 @@ struct int3400_thermal_priv {u8 uuid_bitmap;int rel_misc_dev_res;int current_uuid_index; +char *data_vault; +}; + +static ssize_t data_vault_read (struct file *file,struct kobject *kobj, +struct bin_attribute *attr,char *buf,loff_t off,size_t count) +{ +memcpy (buf, attr->private + off, count); +return count; +} + +static BIN_ATTR_RO(data_vault, 0); + +static struct bin_attribute *data_attributes[] = { + &bin_attr_data_vault, +NULL , +}; + +static const struct attribute_group data_attribute_group = { + .bin_attrs = data_attributes, }; static ssize_t available_uuids_show(struct device *dev,
@@ -278,6 +297,32 @@ static struct thermal_zone_params int3400_thermal_params = { .no_hwmon = true, }; +static void int3400_setup_gddv (struct int3400_thermal_priv *priv) +{ +struct acpi_buffer buffer = {ACPI_ALLOCATE_BUFFER ,NULL }; +union acpi_object *obj; +acpi_status status; + + status =acpi_evaluate_object (priv->adev->handle,"GDDV" ,NULL , + &buffer); +if (ACPI_FAILURE (status) || !buffer.length) +return ; + + obj = buffer.pointer; +if (obj->type !=ACPI_TYPE_PACKAGE || obj->package.count !=1 + || obj->package.elements[0 ].type !=ACPI_TYPE_BUFFER ) { +kfree (buffer.pointer); +return ; + } + + priv->data_vault =kmemdup (obj->package.elements[0 ].buffer.pointer, + obj->package.elements[0 ].buffer.length, +GFP_KERNEL ); + bin_attr_data_vault.private = priv->data_vault; + bin_attr_data_vault.size = obj->package.elements[0 ].buffer.length; +kfree (buffer.pointer); +} +static int int3400_thermal_probe (struct platform_device *pdev) {struct acpi_device *adev =ACPI_COMPANION (&pdev->dev);
@@ -309,6 +354,8 @@ static int int3400_thermal_probe(struct platform_device *pdev)platform_set_drvdata (pdev, priv); +int3400_setup_gddv (priv); + int3400_thermal_ops.get_mode = int3400_thermal_get_mode; int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
@@ -327,6 +374,13 @@ static int int3400_thermal_probe(struct platform_device *pdev)if (result) goto free_rel_misc; +if (priv->data_vault) { + result =sysfs_create_group (&pdev->dev.kobj, + &data_attribute_group); +if (result) + goto free_uuid; + } + result =acpi_install_notify_handler ( priv->adev->handle,ACPI_DEVICE_NOTIFY , int3400_notify, (void *)priv);
@@ -336,6 +390,9 @@ static int int3400_thermal_probe(struct platform_device *pdev)return 0 ; free_sysfs: +if (priv->data_vault) +sysfs_remove_group (&pdev->dev.kobj, &data_attribute_group); +free_uuid:sysfs_remove_group (&pdev->dev.kobj, &uuid_attribute_group); free_rel_misc:if (!priv->rel_misc_dev_res)
@@ -360,8 +417,11 @@ static int int3400_thermal_remove(struct platform_device *pdev)if (!priv->rel_misc_dev_res)acpi_thermal_rel_misc_device_remove (priv->adev->handle); +if (priv->data_vault) +sysfs_remove_group (&pdev->dev.kobj, &data_attribute_group);sysfs_remove_group (&pdev->dev.kobj, &uuid_attribute_group);thermal_zone_device_unregister (priv->thermal); +kfree (priv->data_vault);kfree (priv->trts);kfree (priv->arts);kfree (priv);
Signature · 1 line
2.26.0.110.g2183baf09c-goog
PATCH 2/3 thermal/int340x_thermal: Export OEM vendor variables
From: Matthew Garrett <[email protected]>
The platform vendor may expose an array of OEM-specific values to be used in determining DPTF policy. These are obtained via the ODVP method, and then simply exposed in sysfs. In addition, they are updated when a notification is received or when the DPTF policy is changed by userland.
--- .../intel/int340x_thermal/int3400_thermal.c | 132 +++++++++++++++++- 1 file changed, 131 insertions(+), 1 deletion(-)
drivers/thermal/intel/int340x_thermal/int3400_thermal.c +131 -1
@@ -13,6 +13,7 @@#include "acpi_thermal_rel.h" #define INT3400_THERMAL_TABLE_CHANGED 0x83 +#define INT3400_ODVP_CHANGED 0x88enum int3400_thermal_uuid {INT3400_THERMAL_PASSIVE_1 ,
@@ -41,8 +42,11 @@ static char *int3400_thermal_uuids[INT3400_THERMAL_MAXIMUM_UUID] = { "BE84BABF-C4D4-403D-B495-3128FD44dAC1", }; +struct odvp_attr ; +struct int3400_thermal_priv {struct acpi_device *adev; +struct platform_device *pdev;struct thermal_zone_device *thermal;int mode;int art_count;
@@ -53,6 +57,17 @@ struct int3400_thermal_priv {int rel_misc_dev_res;int current_uuid_index;char *data_vault; +int odvp_count; +int *odvp; +struct odvp_attr *odvp_attrs; +}; + +static int evaluate_odvp (struct int3400_thermal_priv *priv); + +struct odvp_attr { +int odvp; +struct int3400_thermal_priv *priv; +struct kobj_attribute attr; }; static ssize_t data_vault_read(struct file *file, struct kobject *kobj,
@@ -210,9 +225,110 @@ static int int3400_thermal_run_osc(acpi_handle handle, result = -EPERM ;kfree (context.ret.pointer); +return result; } +static ssize_t odvp_show (struct kobject *kobj,struct kobj_attribute *attr, +char *buf) +{ +struct odvp_attr *odvp_attr; + + odvp_attr = container_of(attr, struct odvp_attr, attr); + +return sprintf (buf,"%d\n" , odvp_attr->priv->odvp[odvp_attr->odvp]); +} + +static void cleanup_odvp (struct int3400_thermal_priv *priv) +{ +int i; + +if (priv->odvp_attrs) { +for (i =0 ; i < priv->odvp_count; i++) { +sysfs_remove_file (&priv->pdev->dev.kobj, + &priv->odvp_attrs[i].attr.attr); +kfree (priv->odvp_attrs[i].attr.attr.name); + } +kfree (priv->odvp_attrs); + } +kfree (priv->odvp); + priv->odvp_count =0 ; +} + +static int evaluate_odvp (struct int3400_thermal_priv *priv) +{ +struct acpi_buffer odvp = {ACPI_ALLOCATE_BUFFER ,NULL }; +union acpi_object *obj =NULL ; +acpi_status status; +int i, ret; + + status =acpi_evaluate_object (priv->adev->handle,"ODVP" ,NULL , &odvp); +if (ACPI_FAILURE (status)) { + ret = -EINVAL ; + goto out_err; + } + + obj = odvp.pointer; +if (obj->type !=ACPI_TYPE_PACKAGE ) { + ret = -EINVAL ; + goto out_err; + } + +if (priv->odvp ==NULL ) { + priv->odvp_count = obj->package.count; + priv->odvp =kmalloc_array (priv->odvp_count,sizeof (int ), +GFP_KERNEL ); +if (!priv->odvp) { + ret = -ENOMEM ; + goto out_err; + } + } + +if (priv->odvp_attrs ==NULL ) { + priv->odvp_attrs =kcalloc (priv->odvp_count, +sizeof (struct odvp_attr ), +GFP_KERNEL ); +if (!priv->odvp_attrs) { + ret = -ENOMEM ; + goto out_err; + } +for (i =0 ; i < priv->odvp_count; i++) { +struct odvp_attr *odvp = &priv->odvp_attrs[i]; + +sysfs_attr_init (attr->attr); + odvp->priv = priv; + odvp->odvp = i; + odvp->attr.attr.name =kasprintf (GFP_KERNEL , +"odvp%d" , i); + +if (!odvp->attr.attr.name) { + ret = -ENOMEM ; + goto out_err; + } + odvp->attr.attr.mode =0444 ; + odvp->attr.show = odvp_show; + odvp->attr.store =NULL ; + ret =sysfs_create_file (&priv->pdev->dev.kobj, + &odvp->attr.attr); +if (ret) + goto out_err; + } + } + +for (i =0 ; i < obj->package.count; i++) { +if (obj->package.elements[i].type ==ACPI_TYPE_INTEGER ) + priv->odvp[i] = obj->package.elements[i].integer.value; + } + +kfree (obj); +return 0 ; + +out_err: +cleanup_odvp (priv); +kfree (obj); +return ret; +} +static void int3400_notify (acpi_handle handle,u32 event,void *data)
@@ -236,6 +352,9 @@ static void int3400_notify(acpi_handle handle,kobject_uevent_env (&priv->thermal->device.kobj,KOBJ_CHANGE , thermal_prop);break ; +case INT3400_ODVP_CHANGED : +evaluate_odvp (priv); +break ;default :/* Ignore unknown notification codes sent to INT3400 device */ break ;
@@ -285,6 +404,9 @@ static int int3400_thermal_set_mode(struct thermal_zone_device *thermal, priv->current_uuid_index, enable); } + +evaluate_odvp (priv); +return result; }
@@ -336,6 +458,7 @@ static int int3400_thermal_probe(struct platform_device *pdev)if (!priv)return -ENOMEM ; + priv->pdev = pdev; priv->adev = adev; result =int3400_thermal_get_uuids (priv);
@@ -356,6 +479,8 @@ static int int3400_thermal_probe(struct platform_device *pdev)int3400_setup_gddv (priv); +evaluate_odvp (priv); + int3400_thermal_ops.get_mode = int3400_thermal_get_mode; int3400_thermal_ops.set_mode = int3400_thermal_set_mode;
@@ -390,8 +515,11 @@ static int int3400_thermal_probe(struct platform_device *pdev)return 0 ; free_sysfs: -if (priv->data_vault) +cleanup_odvp (priv); +if (priv->data_vault) {sysfs_remove_group (&pdev->dev.kobj, &data_attribute_group); +kfree (priv->data_vault); + } free_uuid:sysfs_remove_group (&pdev->dev.kobj, &uuid_attribute_group); free_rel_misc:
@@ -414,6 +542,8 @@ static int int3400_thermal_remove(struct platform_device *pdev) priv->adev->handle,ACPI_DEVICE_NOTIFY , int3400_notify); +cleanup_odvp (priv); +if (!priv->rel_misc_dev_res)acpi_thermal_rel_misc_device_remove (priv->adev->handle);
Signature · 1 line
2.26.0.110.g2183baf09c-goog
PATCH 3/3 thermal/int340x_thermal: Don't require IDSP to exist
In reply to Matthew GarrettFrom: Matthew Garrett <[email protected]>
The IDSP method doesn't appear to exist on the most recent Intel platforms:
instead, the IDSP data is included in the GDDV blob. Since we probably don't want to decompress and parse that in-kernel, just allow any UUID to be written if IDSP is missing.
--- .../intel/int340x_thermal/int3400_thermal.c | 30 ++++++++++++++----- 1 file changed, 22 insertions(+), 8 deletions(-)
drivers/thermal/intel/int340x_thermal/int3400_thermal.c +22 -8
@@ -96,6 +96,9 @@ static ssize_t available_uuids_show(struct device *dev,int i;int length =0 ; +if (!priv->uuid_bitmap) +return sprintf (buf,"UNKNOWN\n" ); +for (i =0 ; i <INT3400_THERMAL_MAXIMUM_UUID ; i++) {if (priv->uuid_bitmap & (1 << i))if (PAGE_SIZE - length >0 )
@@ -113,11 +116,11 @@ static ssize_t current_uuid_show(struct device *dev, {struct int3400_thermal_priv *priv =dev_get_drvdata (dev); -if (priv->uuid_bitmap & (1 << priv->current_uuid_index)) -return sprintf (buf,"%s\n" , - int3400_thermal_uuids[priv->current_uuid_index]); -else +if (priv->current_uuid_index ==-1 )return sprintf (buf,"INVALID\n" ); + +return sprintf (buf,"%s\n" , + int3400_thermal_uuids[priv->current_uuid_index]); } static ssize_t current_uuid_store(struct device *dev,
@@ -128,9 +131,16 @@ static ssize_t current_uuid_store(struct device *dev,int i;for (i =0 ; i <INT3400_THERMAL_MAXIMUM_UUID ; ++i) { -if ((priv->uuid_bitmap & (1 << i)) && - !(strncmp (buf, int3400_thermal_uuids[i], -sizeof (int3400_thermal_uuids[i]) -1 ))) { +if (!strncmp (buf, int3400_thermal_uuids[i], +sizeof (int3400_thermal_uuids[i]) -1 )) { +/* +* If we have a list of supported UUIDs, make sure +* this one is supported. +*/ +if (priv->uuid_bitmap && + !(priv->uuid_bitmap & (1 << i))) +return -EINVAL ; + priv->current_uuid_index = i;return count; }
@@ -462,9 +472,13 @@ static int int3400_thermal_probe(struct platform_device *pdev) priv->adev = adev; result =int3400_thermal_get_uuids (priv); -if (result) + +/* Missing IDSP isn't fatal */ +if (result && result != -ENODEV ) goto free_priv; + priv->current_uuid_index =-1 ; + result =acpi_parse_art (priv->adev->handle, &priv->art_count, &priv->arts, true);if (result)
Signature · 1 line
2.26.0.110.g2183baf09c-goog
kbuild test robot
build botRe: [PATCH 2/3] thermal/int340x_thermal: Export OEM vendor variables
In reply to Matthew GarrettI love your patch! Yet something to improve:
Hi Matthew,
I love your patch! Yet something to improve:
[auto build test ERROR on linus/master]
[also build test ERROR on linux/master soc-thermal/next v5.7-rc1 next-20200413] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please see https://stackoverflow.com/a/37406982]
url: https://github.com/0day-ci/linux/commits/Matthew-Garrett/thermal-int340x_thermal-Export-GDDV/20200414-052440 base: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 8f3d9f354286745c751374f5f1fcafee6b3f3136 config: i386-allyesconfig (attached as .config) compiler: gcc-7 (Ubuntu 7.5.0-6ubuntu2) 7.5.0 reproduce: # save the attached .config to linux build tree make ARCH=i386
If you fix the issue, kindly add following tag as appropriate
All errors (new ones prefixed by >>):
In file included from include/linux/kobject.h:20:0,
from include/linux/module.h:20,
from drivers/thermal/intel/int340x_thermal/int3400_thermal.c:9:
drivers/thermal/intel/int340x_thermal/int3400_thermal.c: In function 'evaluate_odvp':
>> drivers/thermal/intel/int340x_thermal/int3400_thermal.c:298:20: error: 'attr' undeclared (first use in this function); did you mean 'iattr'?
sysfs_attr_init(attr->attr);
^
include/linux/sysfs.h:55:3: note: in definition of macro 'sysfs_attr_init'
(attr)->key = &__key; \
^~~~
drivers/thermal/intel/int340x_thermal/int3400_thermal.c:298:20: note: each undeclared identifier is reported only once for each function it appears in
sysfs_attr_init(attr->attr);
^
include/linux/sysfs.h:55:3: note: in definition of macro 'sysfs_attr_init'
(attr)->key = &__key; \
^~~~vim +298 drivers/thermal/intel/int340x_thermal/int3400_thermal.c
257
258 static int evaluate_odvp(struct int3400_thermal_priv *priv)
259 {
260 struct acpi_buffer odvp = { ACPI_ALLOCATE_BUFFER, NULL };
261 union acpi_object *obj = NULL;
262 acpi_status status;
263 int i, ret;
264
265 status = acpi_evaluate_object(priv->adev->handle, "ODVP", NULL, &odvp);
266 if (ACPI_FAILURE(status)) {
267 ret = -EINVAL;
268 goto out_err;
269 }
270
271 obj = odvp.pointer;
272 if (obj->type != ACPI_TYPE_PACKAGE) {
273 ret = -EINVAL;
274 goto out_err;
275 }
276
277 if (priv->odvp == NULL) {
278 priv->odvp_count = obj->package.count;
279 priv->odvp = kmalloc_array(priv->odvp_count, sizeof(int),
280 GFP_KERNEL);
281 if (!priv->odvp) {
282 ret = -ENOMEM;
283 goto out_err;
284 }
285 }
286
287 if (priv->odvp_attrs == NULL) {
288 priv->odvp_attrs = kcalloc(priv->odvp_count,
289 sizeof(struct odvp_attr),
290 GFP_KERNEL);
291 if (!priv->odvp_attrs) {
292 ret = -ENOMEM;
293 goto out_err;
294 }
295 for (i = 0; i < priv->odvp_count; i++) {
296 struct odvp_attr *odvp = &priv->odvp_attrs[i];
297
> 298 sysfs_attr_init(attr->attr);
299 odvp->priv = priv;
300 odvp->odvp = i;
301 odvp->attr.attr.name = kasprintf(GFP_KERNEL,
302 "odvp%d", i);
303
304 if (!odvp->attr.attr.name) {
305 ret = -ENOMEM;
306 goto out_err;
307 }
308 odvp->attr.attr.mode = 0444;
309 odvp->attr.show = odvp_show;
310 odvp->attr.store = NULL;
311 ret = sysfs_create_file(&priv->pdev->dev.kobj,
312 &odvp->attr.attr);
313 if (ret)
314 goto out_err;
315 }
316 }
317
318 for (i = 0; i < obj->package.count; i++) {
319 if (obj->package.elements[i].type == ACPI_TYPE_INTEGER)
320 priv->odvp[i] = obj->package.elements[i].integer.value;
321 }
322
323 kfree(obj);
324 return 0;
325
326 out_err:
327 cleanup_odvp(priv);
328 kfree(obj);
329 return ret;
330 }
331
---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org