linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2 1/3] thermal/int340x_thermal: Export GDDV
@ 2020-04-14  2:09 Matthew Garrett
  2020-04-14  2:09 ` [PATCH V2 2/3] thermal/int340x_thermal: Export OEM vendor variables Matthew Garrett
                   ` (3 more replies)
  0 siblings, 4 replies; 11+ messages in thread
From: Matthew Garrett @ 2020-04-14  2:09 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-pm, rui.zhang, nisha.aram, Matthew Garrett

From: Matthew Garrett <mjg59@google.com>

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.

Signed-off-by: Matthew Garrett <mjg59@google.com>
---
 .../intel/int340x_thermal/int3400_thermal.c   | 60 +++++++++++++++++++
 1 file changed, 60 insertions(+)

diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
index ceef89c956bd4..00a7732724cd0 100644
--- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
+++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
@@ -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);
-- 
2.26.0.110.g2183baf09c-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH V2 2/3] thermal/int340x_thermal: Export OEM vendor variables
  2020-04-14  2:09 [PATCH V2 1/3] thermal/int340x_thermal: Export GDDV Matthew Garrett
@ 2020-04-14  2:09 ` Matthew Garrett
  2020-05-18 23:18   ` Pandruvada, Srinivas
  2020-04-14  2:09 ` [PATCH V2 3/3] thermal/int340x_thermal: Don't require IDSP to exist Matthew Garrett
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 11+ messages in thread
From: Matthew Garrett @ 2020-04-14  2:09 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-pm, rui.zhang, nisha.aram, Matthew Garrett

From: Matthew Garrett <mjg59@google.com>

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.

Signed-off-by: Matthew Garrett <mjg59@google.com>
---
 .../intel/int340x_thermal/int3400_thermal.c   | 132 +++++++++++++++++-
 1 file changed, 131 insertions(+), 1 deletion(-)

diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
index 00a7732724cd0..3919098a73b47 100644
--- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
+++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
@@ -13,6 +13,7 @@
 #include "acpi_thermal_rel.h"
 
 #define INT3400_THERMAL_TABLE_CHANGED 0x83
+#define INT3400_ODVP_CHANGED 0x88
 
 enum 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(&odvp->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);
 
-- 
2.26.0.110.g2183baf09c-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH V2 3/3] thermal/int340x_thermal: Don't require IDSP to exist
  2020-04-14  2:09 [PATCH V2 1/3] thermal/int340x_thermal: Export GDDV Matthew Garrett
  2020-04-14  2:09 ` [PATCH V2 2/3] thermal/int340x_thermal: Export OEM vendor variables Matthew Garrett
@ 2020-04-14  2:09 ` Matthew Garrett
  2020-05-18 23:18   ` Pandruvada, Srinivas
  2020-04-14  3:33 ` [PATCH V2 1/3] thermal/int340x_thermal: Export GDDV Pandruvada, Srinivas
  2020-05-18 23:18 ` Pandruvada, Srinivas
  3 siblings, 1 reply; 11+ messages in thread
From: Matthew Garrett @ 2020-04-14  2:09 UTC (permalink / raw)
  To: linux-kernel; +Cc: linux-pm, rui.zhang, nisha.aram, Matthew Garrett

From: Matthew Garrett <mjg59@google.com>

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.

Signed-off-by: Matthew Garrett <mjg59@google.com>
---
 .../intel/int340x_thermal/int3400_thermal.c   | 30 ++++++++++++++-----
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
index 3919098a73b47..19936709c2ad0 100644
--- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
+++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
@@ -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)
-- 
2.26.0.110.g2183baf09c-goog


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* Re: [PATCH V2 1/3] thermal/int340x_thermal: Export GDDV
  2020-04-14  2:09 [PATCH V2 1/3] thermal/int340x_thermal: Export GDDV Matthew Garrett
  2020-04-14  2:09 ` [PATCH V2 2/3] thermal/int340x_thermal: Export OEM vendor variables Matthew Garrett
  2020-04-14  2:09 ` [PATCH V2 3/3] thermal/int340x_thermal: Don't require IDSP to exist Matthew Garrett
@ 2020-04-14  3:33 ` Pandruvada, Srinivas
  2020-04-14  3:53   ` Matthew Garrett
  2020-05-18 23:18 ` Pandruvada, Srinivas
  3 siblings, 1 reply; 11+ messages in thread
From: Pandruvada, Srinivas @ 2020-04-14  3:33 UTC (permalink / raw)
  To: matthewgarrett, linux-kernel; +Cc: Zhang, Rui, linux-pm, Aram, Nisha, mjg59

On Mon, 2020-04-13 at 19:09 -0700, Matthew Garrett wrote:
> From: Matthew Garrett <mjg59@google.com>
> 
> 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.
> 

Anything changed in v2 series?

Thanks,
Srinivas

> Signed-off-by: Matthew Garrett <mjg59@google.com>
> ---
>  .../intel/int340x_thermal/int3400_thermal.c   | 60
> +++++++++++++++++++
>  1 file changed, 60 insertions(+)
> 
> diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> index ceef89c956bd4..00a7732724cd0 100644
> --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> @@ -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);

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH V2 1/3] thermal/int340x_thermal: Export GDDV
  2020-04-14  3:33 ` [PATCH V2 1/3] thermal/int340x_thermal: Export GDDV Pandruvada, Srinivas
@ 2020-04-14  3:53   ` Matthew Garrett
  2020-04-14  3:58     ` Pandruvada, Srinivas
  0 siblings, 1 reply; 11+ messages in thread
From: Matthew Garrett @ 2020-04-14  3:53 UTC (permalink / raw)
  To: Pandruvada, Srinivas; +Cc: linux-kernel, Zhang, Rui, linux-pm, Aram, Nisha

On Mon, Apr 13, 2020 at 8:33 PM Pandruvada, Srinivas
<srinivas.pandruvada@intel.com> wrote:
> Anything changed in v2 series?

Sorry, forgot to explain the diffs. Patch 2 in V2 was passing the
wrong value to sysfs_attr_init(), but I didn't notice during testing
because that's a macro that does nothing unless a specific debug flag
is set. The kernel build bot noticed. Only difference is passing the
correct argument there.

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH V2 1/3] thermal/int340x_thermal: Export GDDV
  2020-04-14  3:53   ` Matthew Garrett
@ 2020-04-14  3:58     ` Pandruvada, Srinivas
  0 siblings, 0 replies; 11+ messages in thread
From: Pandruvada, Srinivas @ 2020-04-14  3:58 UTC (permalink / raw)
  To: mjg59; +Cc: Zhang, Rui, linux-pm, Aram, Nisha, linux-kernel

On Mon, 2020-04-13 at 20:53 -0700, Matthew Garrett wrote:
> On Mon, Apr 13, 2020 at 8:33 PM Pandruvada, Srinivas
> <srinivas.pandruvada@intel.com> wrote:
> > Anything changed in v2 series?
> 
> Sorry, forgot to explain the diffs. Patch 2 in V2 was passing the
> wrong value to sysfs_attr_init(), but I didn't notice during testing
> because that's a macro that does nothing unless a specific debug flag
> is set. The kernel build bot noticed. Only difference is passing the
> correct argument there.
Thanks.
I will give a try next week.

-Srinivas

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH V2 2/3] thermal/int340x_thermal: Export OEM vendor variables
  2020-04-14  2:09 ` [PATCH V2 2/3] thermal/int340x_thermal: Export OEM vendor variables Matthew Garrett
@ 2020-05-18 23:18   ` Pandruvada, Srinivas
  0 siblings, 0 replies; 11+ messages in thread
From: Pandruvada, Srinivas @ 2020-05-18 23:18 UTC (permalink / raw)
  To: matthewgarrett, linux-kernel; +Cc: Zhang, Rui, linux-pm, Aram, Nisha, mjg59

On Mon, 2020-04-13 at 19:09 -0700, Matthew Garrett wrote:
> From: Matthew Garrett <mjg59@google.com>
> 
> 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.
> 
> Signed-off-by: Matthew Garrett <mjg59@google.com>
Tested-by: Pandruvada, Srinivas <srinivas.pandruvada@linux.intel.com>

> ---
>  .../intel/int340x_thermal/int3400_thermal.c   | 132
> +++++++++++++++++-
>  1 file changed, 131 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> index 00a7732724cd0..3919098a73b47 100644
> --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> @@ -13,6 +13,7 @@
>  #include "acpi_thermal_rel.h"
>  
>  #define INT3400_THERMAL_TABLE_CHANGED 0x83
> +#define INT3400_ODVP_CHANGED 0x88
>  
>  enum 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(&odvp->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);
>  

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH V2 3/3] thermal/int340x_thermal: Don't require IDSP to exist
  2020-04-14  2:09 ` [PATCH V2 3/3] thermal/int340x_thermal: Don't require IDSP to exist Matthew Garrett
@ 2020-05-18 23:18   ` Pandruvada, Srinivas
  0 siblings, 0 replies; 11+ messages in thread
From: Pandruvada, Srinivas @ 2020-05-18 23:18 UTC (permalink / raw)
  To: matthewgarrett, linux-kernel; +Cc: Zhang, Rui, linux-pm, Aram, Nisha, mjg59

On Mon, 2020-04-13 at 19:09 -0700, Matthew Garrett wrote:
> From: Matthew Garrett <mjg59@google.com>
> 
> 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.
> 
> Signed-off-by: Matthew Garrett <mjg59@google.com>
Tested-by: Pandruvada, Srinivas <srinivas.pandruvada@linux.intel.com>

> ---
>  .../intel/int340x_thermal/int3400_thermal.c   | 30 ++++++++++++++---
> --
>  1 file changed, 22 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> index 3919098a73b47..19936709c2ad0 100644
> --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> @@ -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)

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH V2 1/3] thermal/int340x_thermal: Export GDDV
  2020-04-14  2:09 [PATCH V2 1/3] thermal/int340x_thermal: Export GDDV Matthew Garrett
                   ` (2 preceding siblings ...)
  2020-04-14  3:33 ` [PATCH V2 1/3] thermal/int340x_thermal: Export GDDV Pandruvada, Srinivas
@ 2020-05-18 23:18 ` Pandruvada, Srinivas
  2020-05-29  6:00   ` Pandruvada, Srinivas
  3 siblings, 1 reply; 11+ messages in thread
From: Pandruvada, Srinivas @ 2020-05-18 23:18 UTC (permalink / raw)
  To: matthewgarrett, linux-kernel; +Cc: Zhang, Rui, linux-pm, Aram, Nisha, mjg59

On Mon, 2020-04-13 at 19:09 -0700, Matthew Garrett wrote:
> From: Matthew Garrett <mjg59@google.com>
> 
> 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.
> 
> Signed-off-by: Matthew Garrett <mjg59@google.com>
Tested-by: Pandruvada, Srinivas <srinivas.pandruvada@linux.intel.com>

> ---
>  .../intel/int340x_thermal/int3400_thermal.c   | 60
> +++++++++++++++++++
>  1 file changed, 60 insertions(+)
> 
> diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> index ceef89c956bd4..00a7732724cd0 100644
> --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> @@ -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);

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH V2 1/3] thermal/int340x_thermal: Export GDDV
  2020-05-18 23:18 ` Pandruvada, Srinivas
@ 2020-05-29  6:00   ` Pandruvada, Srinivas
  2020-05-29  6:02     ` Zhang Rui
  0 siblings, 1 reply; 11+ messages in thread
From: Pandruvada, Srinivas @ 2020-05-29  6:00 UTC (permalink / raw)
  To: matthewgarrett, linux-kernel; +Cc: Zhang, Rui, linux-pm, Aram, Nisha, mjg59

On Mon, 2020-05-18 at 23:18 +0000, Pandruvada, Srinivas wrote:
> On Mon, 2020-04-13 at 19:09 -0700, Matthew Garrett wrote:
> > From: Matthew Garrett <mjg59@google.com>
> > 
> > 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.
> > 
> > Signed-off-by: Matthew Garrett <mjg59@google.com>
> Tested-by: Pandruvada, Srinivas <srinivas.pandruvada@linux.intel.com>

Can we take this series for 5.8?

Thanks,
Srinivas

> 
> > ---
> >  .../intel/int340x_thermal/int3400_thermal.c   | 60
> > +++++++++++++++++++
> >  1 file changed, 60 insertions(+)
> > 
> > diff --git
> > a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> > b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> > index ceef89c956bd4..00a7732724cd0 100644
> > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> > @@ -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);

^ permalink raw reply	[flat|nested] 11+ messages in thread

* Re: [PATCH V2 1/3] thermal/int340x_thermal: Export GDDV
  2020-05-29  6:00   ` Pandruvada, Srinivas
@ 2020-05-29  6:02     ` Zhang Rui
  0 siblings, 0 replies; 11+ messages in thread
From: Zhang Rui @ 2020-05-29  6:02 UTC (permalink / raw)
  To: Pandruvada, Srinivas, matthewgarrett, linux-kernel
  Cc: linux-pm, Aram, Nisha, mjg59

On Fri, 2020-05-29 at 00:00 -0600, Pandruvada, Srinivas wrote:
> On Mon, 2020-05-18 at 23:18 +0000, Pandruvada, Srinivas wrote:
> > On Mon, 2020-04-13 at 19:09 -0700, Matthew Garrett wrote:
> > > From: Matthew Garrett <mjg59@google.com>
> > > 
> > > 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.
> > > 
> > > Signed-off-by: Matthew Garrett <mjg59@google.com>
> > 
> > Tested-by: Pandruvada, Srinivas <
> > srinivas.pandruvada@linux.intel.com>
> 
> Can we take this series for 5.8?

They are in testing branch and has just passed the build test, will
queue them for 5.8.

thanks,
rui
> 
> Thanks,
> Srinivas
> 
> > 
> > > ---
> > >  .../intel/int340x_thermal/int3400_thermal.c   | 60
> > > +++++++++++++++++++
> > >  1 file changed, 60 insertions(+)
> > > 
> > > diff --git
> > > a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> > > b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> > > index ceef89c956bd4..00a7732724cd0 100644
> > > --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> > > +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
> > > @@ -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);


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2020-05-29  6:02 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-04-14  2:09 [PATCH V2 1/3] thermal/int340x_thermal: Export GDDV Matthew Garrett
2020-04-14  2:09 ` [PATCH V2 2/3] thermal/int340x_thermal: Export OEM vendor variables Matthew Garrett
2020-05-18 23:18   ` Pandruvada, Srinivas
2020-04-14  2:09 ` [PATCH V2 3/3] thermal/int340x_thermal: Don't require IDSP to exist Matthew Garrett
2020-05-18 23:18   ` Pandruvada, Srinivas
2020-04-14  3:33 ` [PATCH V2 1/3] thermal/int340x_thermal: Export GDDV Pandruvada, Srinivas
2020-04-14  3:53   ` Matthew Garrett
2020-04-14  3:58     ` Pandruvada, Srinivas
2020-05-18 23:18 ` Pandruvada, Srinivas
2020-05-29  6:00   ` Pandruvada, Srinivas
2020-05-29  6:02     ` Zhang Rui

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).