public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Linux ACPI <linux-acpi@vger.kernel.org>,
	Daniel Lezcano <daniel.lezcano@linaro.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Linux PM <linux-pm@vger.kernel.org>,
	Michal Wilczynski <michal.wilczynski@intel.com>,
	Zhang Rui <rui.zhang@intel.com>,
	Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Subject: [PATCH v5 06/11] ACPI: thermal: Introduce struct acpi_thermal_trip
Date: Mon, 07 Aug 2023 20:10:06 +0200	[thread overview]
Message-ID: <21971973.EfDdHjke4D@kreacher> (raw)
In-Reply-To: <4503814.LvFx2qVVIh@kreacher>

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Add struct acpi_thermal_trip to contain the temperature and valid flag
of each trip point in the driver's local data structures.

This helps to make the subsequent changes more straightforward.

No intentional functional impact.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---

New patch in v5.

---
 drivers/acpi/thermal.c |   96 ++++++++++++++++++++++---------------------------
 1 file changed, 45 insertions(+), 51 deletions(-)

Index: linux-pm/drivers/acpi/thermal.c
===================================================================
--- linux-pm.orig/drivers/acpi/thermal.c
+++ linux-pm/drivers/acpi/thermal.c
@@ -92,34 +92,27 @@ MODULE_PARM_DESC(psv, "Disable or overri
 
 static struct workqueue_struct *acpi_thermal_pm_queue;
 
-struct acpi_thermal_critical {
-	unsigned long temperature;
-	bool valid;
-};
-
-struct acpi_thermal_hot {
+struct acpi_thermal_trip {
 	unsigned long temperature;
 	bool valid;
 };
 
 struct acpi_thermal_passive {
+	struct acpi_thermal_trip trip;
 	struct acpi_handle_list devices;
-	unsigned long temperature;
 	unsigned long tc1;
 	unsigned long tc2;
 	unsigned long tsp;
-	bool valid;
 };
 
 struct acpi_thermal_active {
+	struct acpi_thermal_trip trip;
 	struct acpi_handle_list devices;
-	unsigned long temperature;
-	bool valid;
 };
 
 struct acpi_thermal_trips {
-	struct acpi_thermal_critical critical;
-	struct acpi_thermal_hot hot;
+	struct acpi_thermal_trip critical;
+	struct acpi_thermal_trip hot;
 	struct acpi_thermal_passive passive;
 	struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE];
 };
@@ -250,9 +243,9 @@ static void __acpi_thermal_trips_update(
 	}
 
 	/* Passive (optional) */
-	if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.valid) ||
+	if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.trip.valid) ||
 	    flag == ACPI_TRIPS_INIT) {
-		valid = tz->trips.passive.valid;
+		valid = tz->trips.passive.trip.valid;
 		if (psv == -1) {
 			status = AE_SUPPORT;
 		} else if (psv > 0) {
@@ -264,44 +257,44 @@ static void __acpi_thermal_trips_update(
 		}
 
 		if (ACPI_FAILURE(status)) {
-			tz->trips.passive.valid = false;
+			tz->trips.passive.trip.valid = false;
 		} else {
-			tz->trips.passive.temperature = tmp;
-			tz->trips.passive.valid = true;
+			tz->trips.passive.trip.temperature = tmp;
+			tz->trips.passive.trip.valid = true;
 			if (flag == ACPI_TRIPS_INIT) {
 				status = acpi_evaluate_integer(tz->device->handle,
 							       "_TC1", NULL, &tmp);
 				if (ACPI_FAILURE(status))
-					tz->trips.passive.valid = false;
+					tz->trips.passive.trip.valid = false;
 				else
 					tz->trips.passive.tc1 = tmp;
 
 				status = acpi_evaluate_integer(tz->device->handle,
 							       "_TC2", NULL, &tmp);
 				if (ACPI_FAILURE(status))
-					tz->trips.passive.valid = false;
+					tz->trips.passive.trip.valid = false;
 				else
 					tz->trips.passive.tc2 = tmp;
 
 				status = acpi_evaluate_integer(tz->device->handle,
 							       "_TSP", NULL, &tmp);
 				if (ACPI_FAILURE(status))
-					tz->trips.passive.valid = false;
+					tz->trips.passive.trip.valid = false;
 				else
 					tz->trips.passive.tsp = tmp;
 			}
 		}
 	}
-	if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.valid) {
+	if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.trip.valid) {
 		memset(&devices, 0, sizeof(struct acpi_handle_list));
 		status = acpi_evaluate_reference(tz->device->handle, "_PSL",
 						 NULL, &devices);
 		if (ACPI_FAILURE(status)) {
 			acpi_handle_info(tz->device->handle,
 					 "Invalid passive threshold\n");
-			tz->trips.passive.valid = false;
+			tz->trips.passive.trip.valid = false;
 		} else {
-			tz->trips.passive.valid = true;
+			tz->trips.passive.trip.valid = true;
 		}
 
 		if (memcmp(&tz->trips.passive.devices, &devices,
@@ -312,24 +305,24 @@ static void __acpi_thermal_trips_update(
 		}
 	}
 	if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) {
-		if (valid != tz->trips.passive.valid)
+		if (valid != tz->trips.passive.trip.valid)
 			ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state");
 	}
 
 	/* Active (optional) */
 	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
 		char name[5] = { '_', 'A', 'C', ('0' + i), '\0' };
-		valid = tz->trips.active[i].valid;
+		valid = tz->trips.active[i].trip.valid;
 
 		if (act == -1)
 			break; /* disable all active trip points */
 
 		if (flag == ACPI_TRIPS_INIT || ((flag & ACPI_TRIPS_ACTIVE) &&
-		    tz->trips.active[i].valid)) {
+		    tz->trips.active[i].trip.valid)) {
 			status = acpi_evaluate_integer(tz->device->handle,
 						       name, NULL, &tmp);
 			if (ACPI_FAILURE(status)) {
-				tz->trips.active[i].valid = false;
+				tz->trips.active[i].trip.valid = false;
 				if (i == 0)
 					break;
 
@@ -337,35 +330,36 @@ static void __acpi_thermal_trips_update(
 					break;
 
 				if (i == 1)
-					tz->trips.active[0].temperature = celsius_to_deci_kelvin(act);
+					tz->trips.active[0].trip.temperature =
+							celsius_to_deci_kelvin(act);
 				else
 					/*
 					 * Don't allow override higher than
 					 * the next higher trip point
 					 */
-					tz->trips.active[i-1].temperature =
+					tz->trips.active[i-1].trip.temperature =
 						min_t(unsigned long,
-						      tz->trips.active[i-2].temperature,
+						      tz->trips.active[i-2].trip.temperature,
 						      celsius_to_deci_kelvin(act));
 
 				break;
 			} else {
-				tz->trips.active[i].temperature = tmp;
-				tz->trips.active[i].valid = true;
+				tz->trips.active[i].trip.temperature = tmp;
+				tz->trips.active[i].trip.valid = true;
 			}
 		}
 
 		name[2] = 'L';
-		if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].valid) {
+		if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].trip.valid) {
 			memset(&devices, 0, sizeof(struct acpi_handle_list));
 			status = acpi_evaluate_reference(tz->device->handle,
 							 name, NULL, &devices);
 			if (ACPI_FAILURE(status)) {
 				acpi_handle_info(tz->device->handle,
 						 "Invalid active%d threshold\n", i);
-				tz->trips.active[i].valid = false;
+				tz->trips.active[i].trip.valid = false;
 			} else {
-				tz->trips.active[i].valid = true;
+				tz->trips.active[i].trip.valid = true;
 			}
 
 			if (memcmp(&tz->trips.active[i].devices, &devices,
@@ -376,10 +370,10 @@ static void __acpi_thermal_trips_update(
 			}
 		}
 		if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES))
-			if (valid != tz->trips.active[i].valid)
+			if (valid != tz->trips.active[i].trip.valid)
 				ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state");
 
-		if (!tz->trips.active[i].valid)
+		if (!tz->trips.active[i].trip.valid)
 			break;
 	}
 
@@ -429,10 +423,10 @@ static int acpi_thermal_get_trip_points(
 
 	valid = tz->trips.critical.valid |
 		tz->trips.hot.valid |
-		tz->trips.passive.valid;
+		tz->trips.passive.trip.valid;
 
 	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++)
-		valid = valid || tz->trips.active[i].valid;
+		valid = valid || tz->trips.active[i].trip.valid;
 
 	if (!valid) {
 		pr_warn(FW_BUG "No valid trip found\n");
@@ -485,7 +479,7 @@ static int thermal_get_trip_type(struct
 		trip--;
 	}
 
-	if (tz->trips.passive.valid) {
+	if (tz->trips.passive.trip.valid) {
 		if (!trip) {
 			*type = THERMAL_TRIP_PASSIVE;
 			return 0;
@@ -493,7 +487,7 @@ static int thermal_get_trip_type(struct
 		trip--;
 	}
 
-	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].valid; i++) {
+	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].trip.valid; i++) {
 		if (!trip) {
 			*type = THERMAL_TRIP_ACTIVE;
 			return 0;
@@ -533,10 +527,10 @@ static int thermal_get_trip_temp(struct
 		trip--;
 	}
 
-	if (tz->trips.passive.valid) {
+	if (tz->trips.passive.trip.valid) {
 		if (!trip) {
 			*temp = deci_kelvin_to_millicelsius_with_offset(
-					tz->trips.passive.temperature,
+					tz->trips.passive.trip.temperature,
 					tz->kelvin_offset);
 			return 0;
 		}
@@ -544,10 +538,10 @@ static int thermal_get_trip_temp(struct
 	}
 
 	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE &&
-		tz->trips.active[i].valid; i++) {
+		tz->trips.active[i].trip.valid; i++) {
 		if (!trip) {
 			*temp = deci_kelvin_to_millicelsius_with_offset(
-					tz->trips.active[i].temperature,
+					tz->trips.active[i].trip.temperature,
 					tz->kelvin_offset);
 			return 0;
 		}
@@ -603,7 +597,7 @@ static int thermal_get_trend(struct ther
 	 * before this callback being invoked
 	 */
 	i = tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature) +
-	    tz->trips.passive.tc2 * (tz->temperature - tz->trips.passive.temperature);
+	    tz->trips.passive.tc2 * (tz->temperature - tz->trips.passive.trip.temperature);
 
 	if (i > 0)
 		*trend = THERMAL_TREND_RAISING;
@@ -654,7 +648,7 @@ static int acpi_thermal_cooling_device_c
 	if (tz->trips.hot.valid)
 		trip++;
 
-	if (tz->trips.passive.valid) {
+	if (tz->trips.passive.trip.valid) {
 		trip++;
 		for (i = 0; i < tz->trips.passive.devices.count; i++) {
 			handle = tz->trips.passive.devices.handles[i];
@@ -679,7 +673,7 @@ static int acpi_thermal_cooling_device_c
 	}
 
 	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
-		if (!tz->trips.active[i].valid)
+		if (!tz->trips.active[i].trip.valid)
 			break;
 
 		trip++;
@@ -775,12 +769,12 @@ static int acpi_thermal_register_thermal
 	if (tz->trips.hot.valid)
 		trip_count++;
 
-	if (tz->trips.passive.valid) {
+	if (tz->trips.passive.trip.valid) {
 		trip_count++;
 		passive_delay = tz->trips.passive.tsp * 100;
 	}
 
-	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].valid; i++)
+	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].trip.valid; i++)
 		trip_count++;
 
 	tz->thermal_zone = thermal_zone_device_register("acpitz", trip_count, 0,
@@ -1060,7 +1054,7 @@ static int acpi_thermal_resume(struct de
 		return -EINVAL;
 
 	for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) {
-		if (!tz->trips.active[i].valid)
+		if (!tz->trips.active[i].trip.valid)
 			break;
 
 		for (j = 0; j < tz->trips.active[i].devices.count; j++) {




  parent reply	other threads:[~2023-08-07 18:21 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-18 18:01 [PATCH v1 0/7] ACPI: thermal: Use trip point table to register thermal zones Rafael J. Wysocki
2023-07-18 18:02 ` [PATCH v1 1/7] thermal: core: Add mechanism for connecting trips with driver data Rafael J. Wysocki
2023-07-18 18:04 ` [PATCH v1 2/7] thermal: core: Do not handle trip points with invalid temperature Rafael J. Wysocki
2023-07-18 18:05 ` [PATCH v1 3/7] ACPI: thermal: Clean up acpi_thermal_register_thermal_zone() Rafael J. Wysocki
2023-07-18 18:06 ` [PATCH v1 4/7] ACPI: thermal: Hold thermal_check_lock around trip updates Rafael J. Wysocki
2023-07-18 18:06 ` [PATCH v1 5/7] ACPI: thermal: Use trip point table to register thermal zones Rafael J. Wysocki
2023-07-19 18:46   ` Rafael J. Wysocki
2023-07-18 18:07 ` [PATCH v1 6/7] ACPI: thermal: Rework thermal_get_trend() Rafael J. Wysocki
2023-07-19 18:50   ` Rafael J. Wysocki
2023-07-18 18:19 ` [PATCH v1 7/7] ACPI: thermal: Drop unnecessary thermal zone callbacks Rafael J. Wysocki
2023-07-18 22:45 ` [PATCH v1 0/7] ACPI: thermal: Use trip point table to register thermal zones Daniel Lezcano
2023-07-19 13:33   ` Rafael J. Wysocki
2023-07-21 12:44 ` [PATCH v2 0/8] " Rafael J. Wysocki
2023-07-21 12:46   ` [PATCH v2 1/8] thermal: core: Add mechanism for connecting trips with driver data Rafael J. Wysocki
2023-07-21 12:47   ` [PATCH v2 2/8] thermal: core: Do not handle trip points with invalid temperature Rafael J. Wysocki
2023-07-21 12:50   ` [PATCH v2 3/8] thermal: core: Add routines for locking and unlocking thermal zones Rafael J. Wysocki
2023-07-21 14:12   ` [PATCH v2 4/8] ACPI: thermal: Clean up acpi_thermal_register_thermal_zone() Rafael J. Wysocki
2023-07-21 14:51   ` [PATCH v2 5/8] ACPI: thermal: Hold thermal zone lock around trip updates Rafael J. Wysocki
2023-07-21 15:00   ` [PATCH v2 6/8] ACPI: thermal: Use trip point table to register thermal zones Rafael J. Wysocki
2023-07-21 15:08   ` [PATCH v2 7/8] ACPI: thermal: Rework thermal_get_trend() Rafael J. Wysocki
2023-07-21 15:10   ` [PATCH v2 8/8] ACPI: thermal: Drop unnecessary thermal zone callbacks Rafael J. Wysocki
2023-07-23 10:19   ` [PATCH v2 0/8] ACPI: thermal: Use trip point table to register thermal zones Daniel Lezcano
2023-07-24  7:59     ` Rafael J. Wysocki
2023-07-25 12:02 ` [PATCH v3 " Rafael J. Wysocki
2023-07-25 12:04   ` [PATCH v3 1/8] thermal: core: Add mechanism for connecting trips with driver data Rafael J. Wysocki
2023-08-01 18:29     ` Daniel Lezcano
2023-08-01 19:02       ` Rafael J. Wysocki
2023-08-02 12:34         ` Daniel Lezcano
2023-08-02 13:03           ` Rafael J. Wysocki
2023-08-02 15:50             ` Daniel Lezcano
2023-08-02 16:48               ` Rafael J. Wysocki
2023-08-03 13:06                 ` Daniel Lezcano
2023-08-03 14:15                   ` Rafael J. Wysocki
2023-08-03 16:20                     ` Daniel Lezcano
2023-08-03 19:58                       ` Rafael J. Wysocki
2023-08-04  8:17                         ` Daniel Lezcano
2023-08-04 11:14                           ` Rafael J. Wysocki
2023-07-25 12:06   ` [PATCH v3 2/8] thermal: core: Do not handle trip points with invalid temperature Rafael J. Wysocki
2023-08-01 18:29     ` Daniel Lezcano
2023-08-01 19:05       ` Rafael J. Wysocki
2023-08-01 19:31         ` Daniel Lezcano
2023-07-25 12:08   ` [PATCH v3 3/8] thermal: core: Add routines for locking and unlocking thermal zones Rafael J. Wysocki
2023-08-01 18:30     ` Daniel Lezcano
2023-08-01 19:11       ` Rafael J. Wysocki
2023-07-25 12:09   ` [PATCH v3 4/8] ACPI: thermal: Clean up acpi_thermal_register_thermal_zone() Rafael J. Wysocki
2023-07-25 12:16   ` [PATCH v3 5/8] ACPI: thermal: Hold thermal zone lock around trip updates Rafael J. Wysocki
2023-08-01 18:39     ` Daniel Lezcano
2023-08-01 18:51       ` Rafael J. Wysocki
2023-07-25 12:20   ` [PATCH v3 6/8] ACPI: thermal: Use trip point table to register thermal zones Rafael J. Wysocki
2023-07-25 18:08     ` Rafael J. Wysocki
2023-07-25 18:12     ` [PATCH v3.1 " Rafael J. Wysocki
2023-07-25 12:22   ` [PATCH v3 7/8] ACPI: thermal: Rework thermal_get_trend() Rafael J. Wysocki
2023-07-25 12:24   ` [PATCH v3 8/8] ACPI: thermal: Drop unnecessary thermal zone callbacks Rafael J. Wysocki
2023-08-01 18:26   ` [PATCH v3 0/8] ACPI: thermal: Use trip point table to register thermal zones Daniel Lezcano
2023-08-01 18:39     ` Rafael J. Wysocki
2023-08-04 20:58 ` [PATCH v4 00/10] " Rafael J. Wysocki
2023-08-04 21:00   ` [PATCH v4 01/10] thermal: core: Do not handle trip points with invalid temperature Rafael J. Wysocki
2023-08-07 11:25     ` Daniel Lezcano
2023-08-04 21:03   ` [PATCH v4 02/10] thermal: core: Introduce thermal_zone_device_adjust() Rafael J. Wysocki
2023-08-04 21:04   ` [PATCH v4 03/10] thermal: core: Add priv pointer to struct thermal_trip Rafael J. Wysocki
2023-08-07 11:25     ` Daniel Lezcano
2023-08-04 21:05   ` [PATCH v4 04/10] thermal: core: Add thermal_zone_update_trip_temp() helper routine Rafael J. Wysocki
2023-08-07 11:29     ` Daniel Lezcano
2023-08-07 15:40       ` Rafael J. Wysocki
2023-08-07 16:17         ` Daniel Lezcano
2023-08-07 16:23           ` Rafael J. Wysocki
2023-08-04 21:07   ` [PATCH v4 05/10] ACPI: thermal: Clean up acpi_thermal_register_thermal_zone() Rafael J. Wysocki
2023-08-04 21:13   ` [PATCH v4 06/10] ACPI: thermal: Carry out trip point updates under zone lock Rafael J. Wysocki
2023-08-04 21:18   ` [PATCH v4 07/10] ACPI: thermal: Use trip point table to register thermal zones Rafael J. Wysocki
2023-08-04 21:22   ` [PATCH v4 08/10] ACPI: thermal: Rework thermal_get_trend() Rafael J. Wysocki
2023-08-04 21:24   ` [PATCH v4 09/10] ACPI: thermal: Drop unnecessary thermal zone callbacks Rafael J. Wysocki
2023-08-04 21:25   ` [PATCH v4 10/10] thermal: core: Eliminate code duplication from acpi_thermal_notify() Rafael J. Wysocki
2023-08-07 17:59 ` [PATCH v5 00/11] ACPI: thermal: Use trip point table to register thermal zones Rafael J. Wysocki
2023-08-07 18:01   ` [PATCH v5 01/11] thermal: core: Do not handle trip points with invalid temperature Rafael J. Wysocki
2023-08-07 18:02   ` [PATCH v5 02/11] thermal: core: Introduce thermal_zone_device_adjust() Rafael J. Wysocki
2023-08-07 18:04   ` [PATCH v5 03/11] thermal: core: Add priv pointer to struct thermal_trip Rafael J. Wysocki
2023-08-07 18:06   ` [PATCH v5 04/11] ACPI: thermal: Clean up acpi_thermal_register_thermal_zone() Rafael J. Wysocki
2023-08-07 18:08   ` [PATCH v5 05/11] ACPI: thermal: Carry out trip point updates under zone lock Rafael J. Wysocki
2023-08-16 16:25     ` Daniel Lezcano
2023-08-17 13:09       ` Rafael J. Wysocki
2023-08-07 18:10   ` Rafael J. Wysocki [this message]
2023-08-07 18:11   ` [PATCH v5 07/11] thermal: core: Rework and rename __for_each_thermal_trip() Rafael J. Wysocki
2023-08-07 18:14   ` [PATCH v5 08/11] ACPI: thermal: Use trip point table to register thermal zones Rafael J. Wysocki
2023-08-09 11:07     ` [PATCH v5.1 " Rafael J. Wysocki
2023-08-07 18:17   ` [PATCH v5 09/11] ACPI: thermal: Rework thermal_get_trend() Rafael J. Wysocki
2023-08-07 18:18   ` [PATCH v5 10/11] ACPI: thermal: Drop unnecessary thermal zone callbacks Rafael J. Wysocki
2023-08-07 18:20   ` [PATCH v5 11/11] thermal: core: Eliminate code duplication from acpi_thermal_notify() Rafael J. Wysocki

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=21971973.EfDdHjke4D@kreacher \
    --to=rjw@rjwysocki.net \
    --cc=daniel.lezcano@linaro.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pm@vger.kernel.org \
    --cc=michal.wilczynski@intel.com \
    --cc=rui.zhang@intel.com \
    --cc=srinivas.pandruvada@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox