]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
thermal: trip: Pass trip pointer to .set_trip_temp() thermal zone callback
authorRafael J. Wysocki <rafael.j.wysocki@intel.com>
Tue, 2 Jul 2024 14:42:33 +0000 (16:42 +0200)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Fri, 12 Jul 2024 13:14:01 +0000 (15:14 +0200)
Out of several drivers implementing the .set_trip_temp() thermal zone
operation, three don't actually use the trip ID argument passed to it,
two call __thermal_zone_get_trip() to get a struct thermal_trip
corresponding to the given trip ID, and the other use the trip ID as an
index into their own data structures with the assumption that it will
always match the ordering of entries in the trips table passed to the
core during thermal zone registration, which is fragile and not really
guaranteed.

Even though the trip IDs used by the core are in fact their indices in the
trips table passed to it by the thermal zone creator, that is purely a
matter of convenience and should not be relied on for correctness.

For this reason, modify trip_point_temp_store() to pass a (const) trip
pointer to .set_trip_temp() and adjust the drivers implementing it
accordingly.

This helps to simplify the drivers invoking __thermal_zone_get_trip()
from their .set_trip_temp() callback functions because they will not
need to do it now and the other drivers can store their internal
trip indices in the priv field in struct thermal_trip and their
.set_trip_temp() callback functions can get those indices from there.

The intel_quark_dts thermal driver can instead use the trip type to
determine the requisite trip index.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Link: https://patch.msgid.link/8392906.T7Z3S40VBb@rjwysocki.net
[ rjw: Add missing colon and 2 empty code lines ]
[ rjw: Add missing change in imx_thermal.c and adjust the changelog ]
[ rjw: Drop an unused local variable ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/net/wireless/intel/iwlwifi/mvm/tt.c
drivers/thermal/imx_thermal.c
drivers/thermal/intel/int340x_thermal/int340x_thermal_zone.c
drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci.c
drivers/thermal/intel/intel_quark_dts_thermal.c
drivers/thermal/intel/intel_soc_dts_iosf.c
drivers/thermal/intel/x86_pkg_temp_thermal.c
drivers/thermal/qcom/qcom-spmi-temp-alarm.c
drivers/thermal/tegra/soctherm.c
drivers/thermal/thermal_sysfs.c
include/linux/thermal.h

index 61a4638d1be2f2fdf952db252bb3755359f85eae..f8b08f98daa086435118b5d89ed0014b3b8a4025 100644 (file)
@@ -638,7 +638,7 @@ out:
 }
 
 static int iwl_mvm_tzone_set_trip_temp(struct thermal_zone_device *device,
-                                      int trip, int temp)
+                                      const struct thermal_trip *trip, int temp)
 {
        struct iwl_mvm *mvm = thermal_zone_device_priv(device);
        int ret;
index c90f28ee4698942a09b601da01f73d162a29d4bf..6ad97309bc0a7911dae3bd6f8541c0fbdffcd6de 100644 (file)
@@ -331,8 +331,8 @@ static int imx_change_mode(struct thermal_zone_device *tz,
        return 0;
 }
 
-static int imx_set_trip_temp(struct thermal_zone_device *tz, int trip_id,
-                            int temp)
+static int imx_set_trip_temp(struct thermal_zone_device *tz,
+                            const struct thermal_trip *trip, int temp)
 {
        struct imx_thermal_data *data = thermal_zone_device_priv(tz);
        int ret;
index cd28a5582a6045d623bc796f32eb454b64f00105..31ed338eb83c09bcee3dc8562f7527aca4223a8a 100644 (file)
@@ -39,13 +39,14 @@ static int int340x_thermal_get_zone_temp(struct thermal_zone_device *zone,
 }
 
 static int int340x_thermal_set_trip_temp(struct thermal_zone_device *zone,
-                                        int trip, int temp)
+                                        const struct thermal_trip *trip, int temp)
 {
        struct int34x_thermal_zone *d = thermal_zone_device_priv(zone);
-       char name[] = {'P', 'A', 'T', '0' + trip, '\0'};
+       unsigned int trip_index = THERMAL_TRIP_PRIV_TO_INT(trip->priv);
+       char name[] = {'P', 'A', 'T', '0' + trip_index, '\0'};
        acpi_status status;
 
-       if (trip > 9)
+       if (trip_index > 9)
                return -EINVAL;
 
        status = acpi_execute_simple_method(d->adev->handle, name,
@@ -144,6 +145,7 @@ struct int34x_thermal_zone *int340x_thermal_zone_add(struct acpi_device *adev,
                zone_trips[i].type = THERMAL_TRIP_PASSIVE;
                zone_trips[i].temperature = THERMAL_TEMP_INVALID;
                zone_trips[i].flags |= THERMAL_TRIP_FLAG_RW_TEMP;
+               zone_trips[i].priv = THERMAL_INT_TO_TRIP_PRIV(i);
        }
 
        trip_cnt = int340x_thermal_read_trips(adev, zone_trips, trip_cnt);
index 4a1bfebb1b8e52076fd536085c08c5e53204ee72..4f41fe543340851de5bb41c6431eef88f55f812e 100644 (file)
@@ -194,7 +194,8 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
        return 0;
 }
 
-static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
+static int sys_set_trip_temp(struct thermal_zone_device *tzd,
+                            const struct thermal_trip *trip, int temp)
 {
        struct proc_thermal_pci *pci_info = thermal_zone_device_priv(tzd);
        int tjmax, _temp;
index ec6ad26027bcb21122faf0d85dbeee1b9b3f80fe..47296a14db3c156f928726e6a382dfc9a9202faf 100644 (file)
@@ -195,7 +195,7 @@ static int get_trip_temp(int trip)
 }
 
 static int update_trip_temp(struct soc_sensor_entry *aux_entry,
-                               int trip, int temp)
+                               int trip_index, int temp)
 {
        u32 out;
        u32 temp_out;
@@ -230,9 +230,9 @@ static int update_trip_temp(struct soc_sensor_entry *aux_entry,
         */
        temp_out = temp + QRK_DTS_TEMP_BASE;
        out = (store_ptps & ~(QRK_DTS_MASK_TP_THRES <<
-               (trip * QRK_DTS_SHIFT_TP)));
+               (trip_index * QRK_DTS_SHIFT_TP)));
        out |= (temp_out & QRK_DTS_MASK_TP_THRES) <<
-               (trip * QRK_DTS_SHIFT_TP);
+               (trip_index * QRK_DTS_SHIFT_TP);
 
        ret = iosf_mbi_write(QRK_MBI_UNIT_RMU, MBI_REG_WRITE,
                             QRK_DTS_REG_OFFSET_PTPS, out);
@@ -242,10 +242,26 @@ failed:
        return ret;
 }
 
-static inline int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
-                               int temp)
+static inline int sys_set_trip_temp(struct thermal_zone_device *tzd,
+                                   const struct thermal_trip *trip,
+                                   int temp)
 {
-       return update_trip_temp(thermal_zone_device_priv(tzd), trip, temp);
+       unsigned int trip_index;
+
+       switch (trip->type) {
+       case THERMAL_TRIP_HOT:
+               trip_index = QRK_DTS_ID_TP_HOT;
+               break;
+
+       case THERMAL_TRIP_CRITICAL:
+               trip_index = QRK_DTS_ID_TP_CRITICAL;
+               break;
+
+       default:
+               return -EINVAL;
+       }
+
+       return update_trip_temp(thermal_zone_device_priv(tzd), trip_index, temp);
 }
 
 static int sys_get_curr_temp(struct thermal_zone_device *tzd,
index 7adf942665d496b1fc03c0ed69b0e6af389808ec..43a29551ba17ebc057269db0b31c5acdab72a158 100644 (file)
@@ -129,18 +129,20 @@ err_restore_ptps:
        return status;
 }
 
-static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip,
+static int sys_set_trip_temp(struct thermal_zone_device *tzd,
+                            const struct thermal_trip *trip,
                             int temp)
 {
        struct intel_soc_dts_sensor_entry *dts = thermal_zone_device_priv(tzd);
        struct intel_soc_dts_sensors *sensors = dts->sensors;
+       unsigned int trip_index = THERMAL_TRIP_PRIV_TO_INT(trip->priv);
        int status;
 
        if (temp > sensors->tj_max)
                return -EINVAL;
 
        mutex_lock(&sensors->dts_update_lock);
-       status = update_trip_temp(sensors, trip, temp);
+       status = update_trip_temp(sensors, trip_index, temp);
        mutex_unlock(&sensors->dts_update_lock);
 
        return status;
@@ -293,11 +295,12 @@ static void dts_trips_reset(struct intel_soc_dts_sensors *sensors, int dts_index
 }
 
 static void set_trip(struct thermal_trip *trip, enum thermal_trip_type type,
-                    u8 flags, int temp)
+                    u8 flags, int temp, unsigned int index)
 {
        trip->type = type;
        trip->flags = flags;
        trip->temperature = temp;
+       trip->priv = THERMAL_INT_TO_TRIP_PRIV(index);
 }
 
 struct intel_soc_dts_sensors *
@@ -332,7 +335,7 @@ intel_soc_dts_iosf_init(enum intel_soc_dts_interrupt_type intr_type,
                sensors->soc_dts[i].sensors = sensors;
 
                set_trip(&trips[i][0], THERMAL_TRIP_PASSIVE,
-                        THERMAL_TRIP_FLAG_RW_TEMP, 0);
+                        THERMAL_TRIP_FLAG_RW_TEMP, 0, 0);
 
                ret = update_trip_temp(sensors, 0, 0);
                if (ret)
@@ -340,10 +343,10 @@ intel_soc_dts_iosf_init(enum intel_soc_dts_interrupt_type intr_type,
 
                if (critical_trip) {
                        temp = sensors->tj_max - crit_offset;
-                       set_trip(&trips[i][1], THERMAL_TRIP_CRITICAL, 0, temp);
+                       set_trip(&trips[i][1], THERMAL_TRIP_CRITICAL, 0, temp, 1);
                } else {
                        set_trip(&trips[i][1], THERMAL_TRIP_PASSIVE,
-                                THERMAL_TRIP_FLAG_RW_TEMP, 0);
+                                THERMAL_TRIP_FLAG_RW_TEMP, 0, 1);
                        temp = 0;
                }
 
index c0ca8e3ff2e78c137220a50076c0ee4d2544e391..65b33b56a9be5e170cf268835307792238250bd7 100644 (file)
@@ -119,9 +119,11 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp)
 }
 
 static int
-sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
+sys_set_trip_temp(struct thermal_zone_device *tzd,
+                 const struct thermal_trip *trip, int temp)
 {
        struct zone_device *zonedev = thermal_zone_device_priv(tzd);
+       unsigned int trip_index = THERMAL_TRIP_PRIV_TO_INT(trip->priv);
        u32 l, h, mask, shift, intr;
        int tj_max, val, ret;
 
@@ -132,7 +134,7 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
 
        val = (tj_max - temp)/1000;
 
-       if (trip >= MAX_NUMBER_OF_TRIPS || val < 0 || val > 0x7f)
+       if (trip_index >= MAX_NUMBER_OF_TRIPS || val < 0 || val > 0x7f)
                return -EINVAL;
 
        ret = rdmsr_on_cpu(zonedev->cpu, MSR_IA32_PACKAGE_THERM_INTERRUPT,
@@ -140,7 +142,7 @@ sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp)
        if (ret < 0)
                return ret;
 
-       if (trip) {
+       if (trip_index) {
                mask = THERM_MASK_THRESHOLD1;
                shift = THERM_SHIFT_THRESHOLD1;
                intr = THERM_INT_THRESHOLD1_ENABLE;
@@ -296,6 +298,7 @@ static int pkg_temp_thermal_trips_init(int cpu, int tj_max,
 
                trips[i].type = THERMAL_TRIP_PASSIVE;
                trips[i].flags |= THERMAL_TRIP_FLAG_RW_TEMP;
+               trips[i].priv = THERMAL_INT_TO_TRIP_PRIV(i);
 
                pr_debug("%s: cpu=%d, trip=%d, temp=%d\n",
                         __func__, cpu, i, trips[i].temperature);
index 3cd74f6cac8f6eabd04bd6efbc1a16964bb5b4eb..96daad28b0c04cbc6b84fff827fc178fd0eb8ef5 100644 (file)
@@ -261,17 +261,13 @@ skip:
        return qpnp_tm_write(chip, QPNP_TM_REG_SHUTDOWN_CTRL1, reg);
 }
 
-static int qpnp_tm_set_trip_temp(struct thermal_zone_device *tz, int trip_id, int temp)
+static int qpnp_tm_set_trip_temp(struct thermal_zone_device *tz,
+                                const struct thermal_trip *trip, int temp)
 {
        struct qpnp_tm_chip *chip = thermal_zone_device_priv(tz);
-       struct thermal_trip trip;
        int ret;
 
-       ret = __thermal_zone_get_trip(chip->tz_dev, trip_id, &trip);
-       if (ret)
-               return ret;
-
-       if (trip.type != THERMAL_TRIP_CRITICAL)
+       if (trip->type != THERMAL_TRIP_CRITICAL)
                return 0;
 
        mutex_lock(&chip->lock);
index e7fe8683bfc55aa9e727f669f915d0a0416252b3..d3dfc34c62c6844ab60de141f04bdfc0a6e80226 100644 (file)
@@ -582,23 +582,18 @@ static int tsensor_group_thermtrip_get(struct tegra_soctherm *ts, int id)
        return temp;
 }
 
-static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, int trip_id, int temp)
+static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz,
+                                       const struct thermal_trip *trip, int temp)
 {
        struct tegra_thermctl_zone *zone = thermal_zone_device_priv(tz);
        struct tegra_soctherm *ts = zone->ts;
-       struct thermal_trip trip;
        const struct tegra_tsensor_group *sg = zone->sg;
        struct device *dev = zone->dev;
-       int ret;
 
        if (!tz)
                return -EINVAL;
 
-       ret = __thermal_zone_get_trip(tz, trip_id, &trip);
-       if (ret)
-               return ret;
-
-       if (trip.type == THERMAL_TRIP_CRITICAL) {
+       if (trip->type == THERMAL_TRIP_CRITICAL) {
                /*
                 * If thermtrips property is set in DT,
                 * doesn't need to program critical type trip to HW,
@@ -609,7 +604,7 @@ static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, int trip
                else
                        return 0;
 
-       } else if (trip.type == THERMAL_TRIP_HOT) {
+       } else if (trip->type == THERMAL_TRIP_HOT) {
                int i;
 
                for (i = 0; i < THROTTLE_SIZE; i++) {
@@ -620,7 +615,7 @@ static int tegra_thermctl_set_trip_temp(struct thermal_zone_device *tz, int trip
                                continue;
 
                        cdev = ts->throt_cfgs[i].cdev;
-                       if (get_thermal_instance(tz, cdev, trip_id))
+                       if (thermal_trip_is_bound_to_cdev(tz, trip, cdev))
                                stc = find_throttle_cfg_by_name(ts, cdev->type);
                        else
                                continue;
index 434b577950be4bfcf78216674ac875636c51e23a..72b302bf914e31f03c27f723fba35ed5a0cc42d9 100644 (file)
@@ -113,7 +113,7 @@ trip_point_temp_store(struct device *dev, struct device_attribute *attr,
 
        if (temp != trip->temperature) {
                if (tz->ops.set_trip_temp) {
-                       ret = tz->ops.set_trip_temp(tz, trip_id, temp);
+                       ret = tz->ops.set_trip_temp(tz, trip, temp);
                        if (ret)
                                goto unlock;
                }
index 3bd1b361ec348fa2c1d79d95ee96083f4baf111d..cdd9c722cda26586002a4ab94713d29a9294159c 100644 (file)
@@ -93,7 +93,8 @@ struct thermal_zone_device_ops {
        int (*set_trips) (struct thermal_zone_device *, int, int);
        int (*change_mode) (struct thermal_zone_device *,
                enum thermal_device_mode);
-       int (*set_trip_temp) (struct thermal_zone_device *, int, int);
+       int (*set_trip_temp) (struct thermal_zone_device *,
+                             const struct thermal_trip *, int);
        int (*get_crit_temp) (struct thermal_zone_device *, int *);
        int (*set_emul_temp) (struct thermal_zone_device *, int);
        int (*get_trend) (struct thermal_zone_device *,