Skip to contentSkip to conversation

ACPI: thermal: Use ACPI thermal library functions

PATCH New Rafael J. Wysocki 1 participant 4 messages Oct 17, 2023

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover ACPI: thermal: Use ACPI thermal library functions

Hi All,

This series modifies the ACPI thermal driver to make it use the ACPI library functions for retrieving trip point temperature values through the platform firmware (patch [3/3]).

However, for this purpose it needs to move the file containing those functions to drivers/acpi (patch [1/3]) and rearrange the code in it to provide functions returning temperature values in deci-Kelvin needed by the ACPI thermal driver (patch [2/3]).

Please refer to the patch changelogs for details.

Thanks!

#1 lore raw

PATCH 1/3 thermal: ACPI: Move the ACPI thermal library to drivers/acpi/

From: Rafael J. Wysocki <[email protected]>

The ACPI thermal library contains functions that can be used to retrieve trip point temperature values through the platform firmware for various types of trip points. Each of these functions basically evaluates a specific ACPI object, checks if the value produced by it is reasonable and returns it (or THERMAL_TEMP_INVALID if anything fails).

It made sense to hold it in drivers/thermal/ so long as it was only used by the code in that directory, but since it is also going to be used by the ACPI thermal driver, located in drivers/acpi/, move it to the latter in order to keep the code related to evaluating ACPI objects defined in the specification proper together.

No intentional functional impact.

---
 drivers/acpi/Kconfig                          |    4 
 drivers/acpi/Makefile                         |    1 
 drivers/acpi/thermal_lib.c                    |  116 ++++++++++++++++++++++++++
 drivers/thermal/Kconfig                       |    4 
 drivers/thermal/Makefile                      |    1 
 drivers/thermal/intel/Kconfig                 |    2 
 drivers/thermal/intel/int340x_thermal/Kconfig |    2 
 drivers/thermal/thermal_acpi.c                |  116 --------------------------
 include/linux/acpi.h                          |    7 +
 include/linux/thermal.h                       |    7 -
 10 files changed, 130 insertions(+), 130 deletions(-)
drivers/thermal/intel/Kconfig +1 -1
Index: linux-pm/drivers/thermal/intel/Kconfig
===================================================================
@@ -85,7 +85,7 @@ config INTEL_BXT_PMIC_THERMAL
 config INTEL_PCH_THERMAL
 	tristate "Intel PCH Thermal Reporting Driver"
 	depends on X86 && PCI
-	select THERMAL_ACPI if ACPI
+	select ACPI_THERMAL_LIB if ACPI
 	help
 	  Enable this to support thermal reporting on certain intel PCHs.
 	  Thermal reporting device will provide temperature reading,
drivers/thermal/intel/int340x_thermal/Kconfig +1 -1
Index: linux-pm/drivers/thermal/intel/int340x_thermal/Kconfig
===================================================================
@@ -9,7 +9,7 @@ config INT340X_THERMAL
 	select THERMAL_GOV_USER_SPACE
 	select ACPI_THERMAL_REL
 	select ACPI_FAN
-	select THERMAL_ACPI
+	select ACPI_THERMAL_LIB
 	select INTEL_SOC_DTS_IOSF_CORE
 	select INTEL_TCC
 	select PROC_THERMAL_MMIO_RAPL if POWERCAP
drivers/acpi/Kconfig +4 -0
Index: linux-pm/drivers/acpi/Kconfig
===================================================================
@@ -60,6 +60,10 @@ config ACPI_CCA_REQUIRED
 config ACPI_TABLE_LIB
 	bool
 
+config ACPI_THERMAL_LIB
+       depends on THERMAL
+       bool
+
 config ACPI_DEBUGGER
 	bool "AML debugger interface"
 	select ACPI_DEBUG
drivers/thermal/Kconfig +0 -4
Index: linux-pm/drivers/thermal/Kconfig
===================================================================
@@ -76,10 +76,6 @@ config THERMAL_OF
 	  Say 'Y' here if you need to build thermal infrastructure
 	  based on device tree.
 
-config THERMAL_ACPI
-       depends on ACPI
-       bool
-
 config THERMAL_WRITABLE_TRIPS
 	bool "Enable writable trip points"
 	help
drivers/acpi/Makefile +1 -0
Index: linux-pm/drivers/acpi/Makefile
===================================================================
@@ -89,6 +89,7 @@ obj-$(CONFIG_ACPI_TAD)		+= acpi_tad.o
 obj-$(CONFIG_ACPI_PCI_SLOT)	+= pci_slot.o
 obj-$(CONFIG_ACPI_PROCESSOR)	+= processor.o
 obj-$(CONFIG_ACPI)		+= container.o
+obj-$(CONFIG_ACPI_THERMAL_LIB)	+= thermal_lib.o
 obj-$(CONFIG_ACPI_THERMAL)	+= thermal.o
 obj-$(CONFIG_ACPI_PLATFORM_PROFILE) 	+= platform_profile.o
 obj-$(CONFIG_ACPI_NFIT)		+= nfit/
drivers/thermal/Makefile +0 -1
Index: linux-pm/drivers/thermal/Makefile
===================================================================
@@ -13,7 +13,6 @@ thermal_sys-$(CONFIG_THERMAL_NETLINK)		+
 # interface to/from other layers providing sensors
 thermal_sys-$(CONFIG_THERMAL_HWMON)		+= thermal_hwmon.o
 thermal_sys-$(CONFIG_THERMAL_OF)		+= thermal_of.o
-thermal_sys-$(CONFIG_THERMAL_ACPI)		+= thermal_acpi.o
 
 # governors
 CFLAGS_gov_power_allocator.o			:= -I$(src)
include/linux/acpi.h +7 -0
Index: linux-pm/include/linux/acpi.h
===================================================================
@@ -439,6 +439,13 @@ extern int acpi_blacklisted(void);
 extern void acpi_osi_setup(char *str);
 extern bool acpi_osi_is_win8(void);
 
+#ifdef CONFIG_ACPI_THERMAL_LIB
+int thermal_acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp);
+int thermal_acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp);
+int thermal_acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp);
+int thermal_acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp);
+#endif
+
 #ifdef CONFIG_ACPI_NUMA
 int acpi_map_pxm_to_node(int pxm);
 int acpi_get_node(acpi_handle handle);
include/linux/thermal.h +0 -7
Index: linux-pm/include/linux/thermal.h
===================================================================
@@ -294,13 +294,6 @@ int thermal_zone_get_num_trips(struct th
 
 int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp);
 
-#ifdef CONFIG_THERMAL_ACPI
-int thermal_acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp);
-int thermal_acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp);
-int thermal_acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp);
-int thermal_acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp);
-#endif
-
 #ifdef CONFIG_THERMAL
 struct thermal_zone_device *thermal_zone_device_register_with_trips(
 					const char *type,
drivers/acpi/thermal_lib.c new file +116 -0

116 lines not on this page · raw message

drivers/thermal/thermal_acpi.c deleted +0 -116

116 lines not on this page · raw message

#2 lore raw

PATCH 2/3 ACPI: thermal_lib: Add functions returning temperature in deci-Kelvin

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Because the ACPI thermal driver generally operates temperature values in deci-Kelvin, it needs the library functions returning temperature for various trip point types to use deci-Kelvin too.

To address that, arrange the ACPI thermal library code in three levels of functions where the high-level ones will return temperature in milli-Celsius, as needed by the thermal core and the majority of thermal drivers, the mid-level ones will return temperature in deci-Kelvin and will be called internally by the corresponding high- level functions, and all of the mid-level functions will call the same low-level one, acpi_trip_temp(), to actually evaluate ACPI objects to retrieve themperature values from the platform firmware.

Going forward, this will allow the ACPI thermal driver to use the mid-level functions to provide temperature values needed by it, so as to reduce code duplication related to evaluating trip temperature ACPI control methods.

No intentional functional impact.

---
 drivers/acpi/thermal_lib.c |   75 ++++++++++++++++++++++++++++++++++++---------
 1 file changed, 60 insertions(+), 15 deletions(-)
drivers/acpi/thermal_lib.c +60 -15
Index: linux-pm/drivers/acpi/thermal_lib.c
===================================================================
@@ -3,8 +3,8 @@
  * Copyright 2023 Linaro Limited
  * Copyright 2023 Intel Corporation
  *
- * Library routines for populating a generic thermal trip point structure
- * with data obtained by evaluating a specific object in the ACPI Namespace.
+ * Library routines for retrieving trip point temperature values from the
+ * platform firmware via ACPI.
  */
 #include <linux/acpi.h>
 #include <linux/units.h>
@@ -17,11 +17,11 @@
  * firmware. Any values out of these boundaries may be considered
  * bogus and we can assume the firmware has no data to provide.
  */
-#define TEMP_MIN_DECIK	2180
-#define TEMP_MAX_DECIK	4480
+#define TEMP_MIN_DECIK	2180ULL
+#define TEMP_MAX_DECIK	4480ULL
 
-static int thermal_acpi_trip_temp(struct acpi_device *adev, char *obj_name,
-				  int *ret_temp)
+static int acpi_trip_temp(struct acpi_device *adev, char *obj_name,
+			  int *ret_temp)
 {
 	unsigned long long temp;
 	acpi_status status;
@@ -33,7 +33,7 @@ static int thermal_acpi_trip_temp(struct
 	}
 
 	if (temp >= TEMP_MIN_DECIK && temp <= TEMP_MAX_DECIK) {
-		*ret_temp = deci_kelvin_to_millicelsius(temp);
+		*ret_temp = temp;
 	} else {
 		acpi_handle_debug(adev->handle, "%s result %llu out of range\n",
 				  obj_name, temp);
@@ -43,6 +43,44 @@ static int thermal_acpi_trip_temp(struct
 	return 0;
 }
 
+int acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp)
+{
+	char obj_name[] = {'_', 'A', 'C', '0' + id, '\0'};
+
+	if (id < 0 || id > 9)
+		return -EINVAL;
+
+	return acpi_trip_temp(adev, obj_name, ret_temp);
+}
+
+int acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp)
+{
+	return acpi_trip_temp(adev, "_PSV", ret_temp);
+}
+
+int acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp)
+{
+	return acpi_trip_temp(adev, "_HOT", ret_temp);
+}
+
+int acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp)
+{
+	return acpi_trip_temp(adev, "_CRT", ret_temp);
+}
+
+static int thermal_temp(int error, int temp_decik, int *ret_temp)
+{
+	if (error)
+		return error;
+
+	if (temp_decik == THERMAL_TEMP_INVALID)
+		*ret_temp = THERMAL_TEMP_INVALID;
+	else
+		*ret_temp = deci_kelvin_to_millicelsius(temp_decik);
+
+	return 0;
+}
+
 /**
  * thermal_acpi_active_trip_temp - Retrieve active trip point temperature
  * @adev: Target thermal zone ACPI device object.
@@ -57,12 +95,10 @@ static int thermal_acpi_trip_temp(struct
  */
 int thermal_acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp)
 {
-	char obj_name[] = {'_', 'A', 'C', '0' + id, '\0'};
-
-	if (id < 0 || id > 9)
-		return -EINVAL;
+	int temp_decik;
+	int ret = acpi_active_trip_temp(adev, id, &temp_decik);
 
-	return thermal_acpi_trip_temp(adev, obj_name, ret_temp);
+	return thermal_temp(ret, temp_decik, ret_temp);
 }
 EXPORT_SYMBOL_GPL(thermal_acpi_active_trip_temp);
 
@@ -78,7 +114,10 @@ EXPORT_SYMBOL_GPL(thermal_acpi_active_tr
  */
 int thermal_acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp)
 {
-	return thermal_acpi_trip_temp(adev, "_PSV", ret_temp);
+	int temp_decik;
+	int ret = acpi_passive_trip_temp(adev, &temp_decik);
+
+	return thermal_temp(ret, temp_decik, ret_temp);
 }
 EXPORT_SYMBOL_GPL(thermal_acpi_passive_trip_temp);
 
@@ -95,7 +134,10 @@ EXPORT_SYMBOL_GPL(thermal_acpi_passive_t
  */
 int thermal_acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp)
 {
-	return thermal_acpi_trip_temp(adev, "_HOT", ret_temp);
+	int temp_decik;
+	int ret = acpi_hot_trip_temp(adev, &temp_decik);
+
+	return thermal_temp(ret, temp_decik, ret_temp);
 }
 EXPORT_SYMBOL_GPL(thermal_acpi_hot_trip_temp);
 
@@ -111,6 +153,9 @@ EXPORT_SYMBOL_GPL(thermal_acpi_hot_trip_
  */
 int thermal_acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp)
 {
-	return thermal_acpi_trip_temp(adev, "_CRT", ret_temp);
+	int temp_decik;
+	int ret = acpi_critical_trip_temp(adev, &temp_decik);
+
+	return thermal_temp(ret, temp_decik, ret_temp);
 }
 EXPORT_SYMBOL_GPL(thermal_acpi_critical_trip_temp);
#3 lore raw

PATCH 3/3 ACPI: thermal: Use library functions to obtain trip point temperature values

In reply to Rafael J. Wysocki

From: Rafael J. Wysocki <[email protected]>

Modify the ACPI thermal driver to use functions from the ACPI thermal library to obtain trip point temperature values instead of duplicating them locally.

Among other things, this requires the functions in question to be exported to it, because it can be built as a module.

It effectively changes the behavior of the driver to treat temperature values out of the reasonable range (-55 centigrade to 175 centigrade) as invalid, but there is no other expected functional impact.

---
 drivers/acpi/internal.h    |    5 +++
 drivers/acpi/thermal.c     |   57 +++++++++++++++++++--------------------------
 drivers/acpi/thermal_lib.c |    4 +++
 3 files changed, 34 insertions(+), 32 deletions(-)
drivers/acpi/thermal_lib.c +4 -0
Index: linux-pm/drivers/acpi/thermal_lib.c
===================================================================
@@ -52,21 +52,25 @@ int acpi_active_trip_temp(struct acpi_de
 
 	return acpi_trip_temp(adev, obj_name, ret_temp);
 }
+EXPORT_SYMBOL_NS_GPL(acpi_active_trip_temp, ACPI_THERMAL);
 
 int acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp)
 {
 	return acpi_trip_temp(adev, "_PSV", ret_temp);
 }
+EXPORT_SYMBOL_NS_GPL(acpi_passive_trip_temp, ACPI_THERMAL);
 
 int acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp)
 {
 	return acpi_trip_temp(adev, "_HOT", ret_temp);
 }
+EXPORT_SYMBOL_NS_GPL(acpi_hot_trip_temp, ACPI_THERMAL);
 
 int acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp)
 {
 	return acpi_trip_temp(adev, "_CRT", ret_temp);
 }
+EXPORT_SYMBOL_NS_GPL(acpi_critical_trip_temp, ACPI_THERMAL);
 
 static int thermal_temp(int error, int temp_decik, int *ret_temp)
 {
drivers/acpi/internal.h +5 -0
Index: linux-pm/drivers/acpi/internal.h
===================================================================
@@ -85,6 +85,11 @@ bool acpi_scan_is_offline(struct acpi_de
 acpi_status acpi_sysfs_table_handler(u32 event, void *table, void *context);
 void acpi_scan_table_notify(void);
 
+int acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp);
+int acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp);
+int acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp);
+int acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp);
+
 /* --------------------------------------------------------------------------
                      Device Node Initialization / Removal
    -------------------------------------------------------------------------- */
drivers/acpi/thermal.c +25 -32

122 lines not on this page · raw message