[v2] thermal: int340x_thermal: Add production mode attribute

Message ID 20230123024040.337866-1-srinivas.pandruvada@linux.intel.com
State New
Headers
Series [v2] thermal: int340x_thermal: Add production mode attribute |

Commit Message

srinivas pandruvada Jan. 23, 2023, 2:40 a.m. UTC
  It is possible that the system manufacturer locks down thermal tuning
beyond what is usually done on the given platform. In that case user
space calibration tools should not try to adjust the thermal
configuration of the system.

To allow user space to check if that is the case, add a new sysfs
attribute "production_mode" that will be present when the ACPI DCFG
method is present under the INT3400 device object in the ACPI Namespace.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
v2
Addressed comments from Rafael:
- Updated commit excatly same as Rafael wrote
- Removed production_mode_support bool
- Use sysfs_emit
- Update documentation

 .../driver-api/thermal/intel_dptf.rst         |  3 ++
 .../intel/int340x_thermal/int3400_thermal.c   | 48 +++++++++++++++++++
 2 files changed, 51 insertions(+)
  

Comments

kernel test robot Jan. 23, 2023, 5:10 a.m. UTC | #1
Hi Srinivas,

I love your patch! Perhaps something to improve:

[auto build test WARNING on rafael-pm/thermal]
[also build test WARNING on linus/master v6.2-rc5]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Srinivas-Pandruvada/thermal-int340x_thermal-Add-production-mode-attribute/20230123-104105
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git thermal
patch link:    https://lore.kernel.org/r/20230123024040.337866-1-srinivas.pandruvada%40linux.intel.com
patch subject: [PATCH v2] thermal: int340x_thermal: Add production mode attribute
config: x86_64-allyesconfig (https://download.01.org/0day-ci/archive/20230123/202301231218.inlZXxdA-lkp@intel.com/config)
compiler: gcc-11 (Debian 11.3.0-8) 11.3.0
reproduce (this is a W=1 build):
        # https://github.com/intel-lab-lkp/linux/commit/2c4e5f536a8e523a9f48701629806ecb63346cc0
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Srinivas-Pandruvada/thermal-int340x_thermal-Add-production-mode-attribute/20230123-104105
        git checkout 2c4e5f536a8e523a9f48701629806ecb63346cc0
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        make W=1 O=build_dir ARCH=x86_64 olddefconfig
        make W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/thermal/intel/int340x_thermal/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/thermal/intel/int340x_thermal/int3400_thermal.c:351:6: warning: no previous prototype for 'production_mode_exit' [-Wmissing-prototypes]
     351 | void production_mode_exit(struct int3400_thermal_priv *priv)
         |      ^~~~~~~~~~~~~~~~~~~~


vim +/production_mode_exit +351 drivers/thermal/intel/int340x_thermal/int3400_thermal.c

   350	
 > 351	void production_mode_exit(struct int3400_thermal_priv *priv)
   352	{
   353		if (priv->production_mode >= 0)
   354			sysfs_remove_file(&priv->pdev->dev.kobj, &dev_attr_production_mode.attr);
   355	}
   356
  
kernel test robot Jan. 23, 2023, 6:01 a.m. UTC | #2
Hi Srinivas,

I love your patch! Perhaps something to improve:

[auto build test WARNING on rafael-pm/thermal]
[also build test WARNING on linus/master v6.2-rc5 next-20230120]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]

url:    https://github.com/intel-lab-lkp/linux/commits/Srinivas-Pandruvada/thermal-int340x_thermal-Add-production-mode-attribute/20230123-104105
base:   https://git.kernel.org/pub/scm/linux/kernel/git/rafael/linux-pm.git thermal
patch link:    https://lore.kernel.org/r/20230123024040.337866-1-srinivas.pandruvada%40linux.intel.com
patch subject: [PATCH v2] thermal: int340x_thermal: Add production mode attribute
config: x86_64-randconfig-a014-20230123 (https://download.01.org/0day-ci/archive/20230123/202301231356.x7cUwKr8-lkp@intel.com/config)
compiler: clang version 14.0.6 (https://github.com/llvm/llvm-project f28c006a5895fc0e329fe15fead81e37457cb1d1)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # https://github.com/intel-lab-lkp/linux/commit/2c4e5f536a8e523a9f48701629806ecb63346cc0
        git remote add linux-review https://github.com/intel-lab-lkp/linux
        git fetch --no-tags linux-review Srinivas-Pandruvada/thermal-int340x_thermal-Add-production-mode-attribute/20230123-104105
        git checkout 2c4e5f536a8e523a9f48701629806ecb63346cc0
        # save the config file
        mkdir build_dir && cp config build_dir/.config
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 olddefconfig
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross W=1 O=build_dir ARCH=x86_64 SHELL=/bin/bash drivers/thermal/intel/int340x_thermal/

If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <lkp@intel.com>

All warnings (new ones prefixed by >>):

>> drivers/thermal/intel/int340x_thermal/int3400_thermal.c:351:6: warning: no previous prototype for function 'production_mode_exit' [-Wmissing-prototypes]
   void production_mode_exit(struct int3400_thermal_priv *priv)
        ^
   drivers/thermal/intel/int340x_thermal/int3400_thermal.c:351:1: note: declare 'static' if the function is not intended to be used outside of this translation unit
   void production_mode_exit(struct int3400_thermal_priv *priv)
   ^
   static 
   1 warning generated.


vim +/production_mode_exit +351 drivers/thermal/intel/int340x_thermal/int3400_thermal.c

   350	
 > 351	void production_mode_exit(struct int3400_thermal_priv *priv)
   352	{
   353		if (priv->production_mode >= 0)
   354			sysfs_remove_file(&priv->pdev->dev.kobj, &dev_attr_production_mode.attr);
   355	}
   356
  

Patch

diff --git a/Documentation/driver-api/thermal/intel_dptf.rst b/Documentation/driver-api/thermal/intel_dptf.rst
index 372bdb4d04c6..f5c193cccbda 100644
--- a/Documentation/driver-api/thermal/intel_dptf.rst
+++ b/Documentation/driver-api/thermal/intel_dptf.rst
@@ -84,6 +84,9 @@  DPTF ACPI Drivers interface
 	https:/github.com/intel/thermal_daemon for decoding
 	thermal table.
 
+``production_mode`` (RO)
+	When different from zero, manufacturer locked thermal configuration
+	from further changes.
 
 ACPI Thermal Relationship table interface
 ------------------------------------------
diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
index db8a6f63657d..326f493b9c91 100644
--- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
+++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c
@@ -60,6 +60,7 @@  struct int3400_thermal_priv {
 	int odvp_count;
 	int *odvp;
 	u32 os_uuid_mask;
+	int production_mode;
 	struct odvp_attr *odvp_attrs;
 };
 
@@ -315,6 +316,44 @@  static int int3400_thermal_get_uuids(struct int3400_thermal_priv *priv)
 	return result;
 }
 
+static ssize_t production_mode_show(struct device *dev, struct device_attribute *attr,
+				     char *buf)
+{
+	struct int3400_thermal_priv *priv = dev_get_drvdata(dev);
+
+	return sysfs_emit(buf, "%d\n", priv->production_mode);
+}
+
+static DEVICE_ATTR_RO(production_mode);
+
+static int production_mode_init(struct int3400_thermal_priv *priv)
+{
+	unsigned long long mode;
+	acpi_status status;
+	int ret;
+
+	priv->production_mode = -1;
+
+	status = acpi_evaluate_integer(priv->adev->handle, "DCFG", NULL, &mode);
+	/* If the method is not present, this is not an error */
+	if (ACPI_FAILURE(status))
+		return 0;
+
+	ret = sysfs_create_file(&priv->pdev->dev.kobj, &dev_attr_production_mode.attr);
+	if (ret)
+		return ret;
+
+	priv->production_mode = mode;
+
+	return 0;
+}
+
+void production_mode_exit(struct int3400_thermal_priv *priv)
+{
+	if (priv->production_mode >= 0)
+		sysfs_remove_file(&priv->pdev->dev.kobj, &dev_attr_production_mode.attr);
+}
+
 static ssize_t odvp_show(struct device *dev, struct device_attribute *attr,
 			 char *buf)
 {
@@ -610,8 +649,15 @@  static int int3400_thermal_probe(struct platform_device *pdev)
 	if (result)
 		goto free_sysfs;
 
+	result = production_mode_init(priv);
+	if (result)
+		goto free_notify;
+
 	return 0;
 
+free_notify:
+	acpi_remove_notify_handler(priv->adev->handle, ACPI_DEVICE_NOTIFY,
+				   int3400_notify);
 free_sysfs:
 	cleanup_odvp(priv);
 	if (!ZERO_OR_NULL_PTR(priv->data_vault)) {
@@ -638,6 +684,8 @@  static int int3400_thermal_remove(struct platform_device *pdev)
 {
 	struct int3400_thermal_priv *priv = platform_get_drvdata(pdev);
 
+	production_mode_exit(priv);
+
 	acpi_remove_notify_handler(
 			priv->adev->handle, ACPI_DEVICE_NOTIFY,
 			int3400_notify);