From 12ad93ab6eeb0c30dbcb5df7f72415a092f6f191 Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Fri, 7 Jul 2023 22:37:30 +0200 Subject: thermal/drivers/int3400: Use thermal zone device wrappers Use the thermal core API to access the thermal zone "type" field instead of directly using the structure field. While here, remove access to the temperature field, as this driver is reporting fake temperature, which can be replaced with INT3400_FAKE_TEMP. Also replace hardcoded 20C with INT3400_FAKE_TEMP Acked-by: srinivas pandruvada Signed-off-by: Daniel Lezcano Signed-off-by: Rafael J. Wysocki --- drivers/thermal/intel/int340x_thermal/int3400_thermal.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index 5e1164226ada..6aadfd72d910 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -15,6 +15,7 @@ #define INT3400_THERMAL_TABLE_CHANGED 0x83 #define INT3400_ODVP_CHANGED 0x88 #define INT3400_KEEP_ALIVE 0xA0 +#define INT3400_FAKE_TEMP (20 * 1000) /* faked temp sensor with 20C */ enum int3400_thermal_uuid { INT3400_THERMAL_ACTIVE = 0, @@ -453,6 +454,7 @@ static void int3400_notify(acpi_handle handle, void *data) { struct int3400_thermal_priv *priv = data; + struct device *dev; char *thermal_prop[5]; int therm_event; @@ -475,12 +477,14 @@ static void int3400_notify(acpi_handle handle, return; } - thermal_prop[0] = kasprintf(GFP_KERNEL, "NAME=%s", priv->thermal->type); - thermal_prop[1] = kasprintf(GFP_KERNEL, "TEMP=%d", priv->thermal->temperature); + dev = thermal_zone_device(priv->thermal); + + thermal_prop[0] = kasprintf(GFP_KERNEL, "NAME=%s", thermal_zone_device_type(priv->thermal)); + thermal_prop[1] = kasprintf(GFP_KERNEL, "TEMP=%d", INT3400_FAKE_TEMP); thermal_prop[2] = kasprintf(GFP_KERNEL, "TRIP="); thermal_prop[3] = kasprintf(GFP_KERNEL, "EVENT=%d", therm_event); thermal_prop[4] = NULL; - kobject_uevent_env(&priv->thermal->device.kobj, KOBJ_CHANGE, thermal_prop); + kobject_uevent_env(&dev->kobj, KOBJ_CHANGE, thermal_prop); kfree(thermal_prop[0]); kfree(thermal_prop[1]); kfree(thermal_prop[2]); @@ -490,7 +494,7 @@ static void int3400_notify(acpi_handle handle, static int int3400_thermal_get_temp(struct thermal_zone_device *thermal, int *temp) { - *temp = 20 * 1000; /* faked temp sensor with 20C */ + *temp = INT3400_FAKE_TEMP; return 0; } -- cgit v1.2.3 From e49c8ed8e0ec29d3ae8cb6342cad147d9738bfbe Mon Sep 17 00:00:00 2001 From: Daniel Lezcano Date: Fri, 7 Jul 2023 22:37:31 +0200 Subject: thermal/drivers/int340x: Do not check the thermal zone state The driver is accessing the thermal zone state to ensure the state is different from the one we want to set. We don't want the driver to access the thermal zone device internals. Actually, the thermal core code already checks if the thermal zone's state is different before calling this function, thus this check is duplicate. Remove it. Acked-by: srinivas pandruvada Signed-off-by: Daniel Lezcano Signed-off-by: Rafael J. Wysocki --- .../intel/int340x_thermal/int3400_thermal.c | 32 ++++++++++------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c index 6aadfd72d910..ddd600820f68 100644 --- a/drivers/thermal/intel/int340x_thermal/int3400_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3400_thermal.c @@ -503,32 +503,28 @@ static int int3400_thermal_change_mode(struct thermal_zone_device *thermal, { struct int3400_thermal_priv *priv = thermal_zone_device_priv(thermal); int result = 0; + int enabled; if (!priv) return -EINVAL; - if (mode != thermal->mode) { - int enabled; + enabled = mode == THERMAL_DEVICE_ENABLED; - enabled = mode == THERMAL_DEVICE_ENABLED; - - if (priv->os_uuid_mask) { - if (!enabled) { - priv->os_uuid_mask = 0; - result = set_os_uuid_mask(priv, priv->os_uuid_mask); - } - goto eval_odvp; + if (priv->os_uuid_mask) { + if (!enabled) { + priv->os_uuid_mask = 0; + result = set_os_uuid_mask(priv, priv->os_uuid_mask); } - - if (priv->current_uuid_index < 0 || - priv->current_uuid_index >= INT3400_THERMAL_MAXIMUM_UUID) - return -EINVAL; - - result = int3400_thermal_run_osc(priv->adev->handle, - int3400_thermal_uuids[priv->current_uuid_index], - &enabled); + goto eval_odvp; } + if (priv->current_uuid_index < 0 || + priv->current_uuid_index >= INT3400_THERMAL_MAXIMUM_UUID) + return -EINVAL; + + result = int3400_thermal_run_osc(priv->adev->handle, + int3400_thermal_uuids[priv->current_uuid_index], + &enabled); eval_odvp: evaluate_odvp(priv); -- cgit v1.2.3 From f6a756e8fb12923f0e3996a575e935e94f3594eb Mon Sep 17 00:00:00 2001 From: Rob Herring Date: Fri, 14 Jul 2023 11:50:07 -0600 Subject: thermal: Explicitly include correct DT includes The DT of_device.h and of_platform.h date back to the separate of_platform_bus_type before it as merged into the regular platform bus. As part of that merge prepping Arm DT support 13 years ago, they "temporarily" include each other. They also include platform_device.h and of.h. As a result, there's a pretty much random mix of those include files used throughout the tree. In order to detangle these headers and replace the implicit includes with struct declarations, users need to explicitly include the correct includes. Signed-off-by: Rob Herring Reviewed-by: Alim Akhtar Signed-off-by: Rafael J. Wysocki --- drivers/thermal/amlogic_thermal.c | 2 -- drivers/thermal/broadcom/bcm2711_thermal.c | 2 +- drivers/thermal/broadcom/brcmstb_thermal.c | 2 +- drivers/thermal/hisi_thermal.c | 2 +- drivers/thermal/imx8mm_thermal.c | 1 - drivers/thermal/imx_sc_thermal.c | 1 - drivers/thermal/imx_thermal.c | 2 +- drivers/thermal/k3_bandgap.c | 2 +- drivers/thermal/k3_j72xx_bandgap.c | 2 +- drivers/thermal/mediatek/auxadc_thermal.c | 1 - drivers/thermal/mediatek/lvts_thermal.c | 2 +- drivers/thermal/qcom/qcom-spmi-adc-tm5.c | 1 - drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 1 - drivers/thermal/rcar_gen3_thermal.c | 2 +- drivers/thermal/rcar_thermal.c | 2 +- drivers/thermal/rzg2l_thermal.c | 2 +- drivers/thermal/samsung/exynos_tmu.c | 2 +- drivers/thermal/sprd_thermal.c | 2 +- drivers/thermal/st/stm_thermal.c | 2 -- drivers/thermal/sun8i_thermal.c | 2 +- drivers/thermal/tegra/tegra30-tsensor.c | 2 +- drivers/thermal/thermal_of.c | 3 +-- drivers/thermal/uniphier_thermal.c | 1 - 23 files changed, 15 insertions(+), 26 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/amlogic_thermal.c b/drivers/thermal/amlogic_thermal.c index 756b218880a7..81ebbf6de0de 100644 --- a/drivers/thermal/amlogic_thermal.c +++ b/drivers/thermal/amlogic_thermal.c @@ -22,8 +22,6 @@ #include #include #include -#include -#include #include #include #include diff --git a/drivers/thermal/broadcom/bcm2711_thermal.c b/drivers/thermal/broadcom/bcm2711_thermal.c index c243a76a3471..03ac2d02e9d4 100644 --- a/drivers/thermal/broadcom/bcm2711_thermal.c +++ b/drivers/thermal/broadcom/bcm2711_thermal.c @@ -15,8 +15,8 @@ #include #include #include +#include #include -#include #include #include diff --git a/drivers/thermal/broadcom/brcmstb_thermal.c b/drivers/thermal/broadcom/brcmstb_thermal.c index 72d1dbe60b8f..0b73abdaa792 100644 --- a/drivers/thermal/broadcom/brcmstb_thermal.c +++ b/drivers/thermal/broadcom/brcmstb_thermal.c @@ -17,8 +17,8 @@ #include #include #include +#include #include -#include #include #define AVS_TMON_STATUS 0x00 diff --git a/drivers/thermal/hisi_thermal.c b/drivers/thermal/hisi_thermal.c index 3f09ef8be41a..fb54ed4bf6f0 100644 --- a/drivers/thermal/hisi_thermal.c +++ b/drivers/thermal/hisi_thermal.c @@ -13,9 +13,9 @@ #include #include #include +#include #include #include -#include #include #define HI6220_TEMP0_LAG (0x0) diff --git a/drivers/thermal/imx8mm_thermal.c b/drivers/thermal/imx8mm_thermal.c index d4b40869c7d7..e89b11b3f2b9 100644 --- a/drivers/thermal/imx8mm_thermal.c +++ b/drivers/thermal/imx8mm_thermal.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include diff --git a/drivers/thermal/imx_sc_thermal.c b/drivers/thermal/imx_sc_thermal.c index 8d6b4ef23746..7224f8d21db9 100644 --- a/drivers/thermal/imx_sc_thermal.c +++ b/drivers/thermal/imx_sc_thermal.c @@ -8,7 +8,6 @@ #include #include #include -#include #include #include #include diff --git a/drivers/thermal/imx_thermal.c b/drivers/thermal/imx_thermal.c index a94ec0a0c9dd..826358cbe810 100644 --- a/drivers/thermal/imx_thermal.c +++ b/drivers/thermal/imx_thermal.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/drivers/thermal/k3_bandgap.c b/drivers/thermal/k3_bandgap.c index 1c3e590157ec..68f59b3735d3 100644 --- a/drivers/thermal/k3_bandgap.c +++ b/drivers/thermal/k3_bandgap.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/drivers/thermal/k3_j72xx_bandgap.c b/drivers/thermal/k3_j72xx_bandgap.c index 5be1f09eeb2c..a5a0fc9b9356 100644 --- a/drivers/thermal/k3_j72xx_bandgap.c +++ b/drivers/thermal/k3_j72xx_bandgap.c @@ -10,10 +10,10 @@ #include #include #include +#include #include #include #include -#include #include #include #include diff --git a/drivers/thermal/mediatek/auxadc_thermal.c b/drivers/thermal/mediatek/auxadc_thermal.c index f59d36de20a0..c537aed71017 100644 --- a/drivers/thermal/mediatek/auxadc_thermal.c +++ b/drivers/thermal/mediatek/auxadc_thermal.c @@ -15,7 +15,6 @@ #include #include #include -#include #include #include #include diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c index b693fac2d677..054c965ae5e1 100644 --- a/drivers/thermal/mediatek/lvts_thermal.c +++ b/drivers/thermal/mediatek/lvts_thermal.c @@ -13,7 +13,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c index 5ddc39b2be32..756ac6842ff9 100644 --- a/drivers/thermal/qcom/qcom-spmi-adc-tm5.c +++ b/drivers/thermal/qcom/qcom-spmi-adc-tm5.c @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c index 0e8ebfcd84c5..78c5cfe6a0c0 100644 --- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c +++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c @@ -10,7 +10,6 @@ #include #include #include -#include #include #include #include diff --git a/drivers/thermal/rcar_gen3_thermal.c b/drivers/thermal/rcar_gen3_thermal.c index 9029d01e029b..bd2fb8c2e968 100644 --- a/drivers/thermal/rcar_gen3_thermal.c +++ b/drivers/thermal/rcar_gen3_thermal.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/drivers/thermal/rcar_thermal.c b/drivers/thermal/rcar_thermal.c index b8571f7090aa..293f8dd9fe0a 100644 --- a/drivers/thermal/rcar_thermal.c +++ b/drivers/thermal/rcar_thermal.c @@ -11,7 +11,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/drivers/thermal/rzg2l_thermal.c b/drivers/thermal/rzg2l_thermal.c index b56981f85306..6b2bf3426f52 100644 --- a/drivers/thermal/rzg2l_thermal.c +++ b/drivers/thermal/rzg2l_thermal.c @@ -9,8 +9,8 @@ #include #include #include +#include #include -#include #include #include #include diff --git a/drivers/thermal/samsung/exynos_tmu.c b/drivers/thermal/samsung/exynos_tmu.c index 45e5c840d130..58f4d8f7a3fd 100644 --- a/drivers/thermal/samsung/exynos_tmu.c +++ b/drivers/thermal/samsung/exynos_tmu.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/drivers/thermal/sprd_thermal.c b/drivers/thermal/sprd_thermal.c index 2fb90fdad76e..e27c4bdc8912 100644 --- a/drivers/thermal/sprd_thermal.c +++ b/drivers/thermal/sprd_thermal.c @@ -6,7 +6,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/drivers/thermal/st/stm_thermal.c b/drivers/thermal/st/stm_thermal.c index 903fcf1763f1..142a7e5d12f4 100644 --- a/drivers/thermal/st/stm_thermal.c +++ b/drivers/thermal/st/stm_thermal.c @@ -14,8 +14,6 @@ #include #include #include -#include -#include #include #include diff --git a/drivers/thermal/sun8i_thermal.c b/drivers/thermal/sun8i_thermal.c index 195f3c5d0b38..cca16d632d9f 100644 --- a/drivers/thermal/sun8i_thermal.c +++ b/drivers/thermal/sun8i_thermal.c @@ -14,7 +14,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/drivers/thermal/tegra/tegra30-tsensor.c b/drivers/thermal/tegra/tegra30-tsensor.c index c243e9d76d3c..d911fa60f100 100644 --- a/drivers/thermal/tegra/tegra30-tsensor.c +++ b/drivers/thermal/tegra/tegra30-tsensor.c @@ -18,7 +18,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index bc07ae1c284c..330690a3a208 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -10,8 +10,7 @@ #include #include -#include -#include +#include #include #include #include diff --git a/drivers/thermal/uniphier_thermal.c b/drivers/thermal/uniphier_thermal.c index aef6119cc004..6f32ab61d174 100644 --- a/drivers/thermal/uniphier_thermal.c +++ b/drivers/thermal/uniphier_thermal.c @@ -12,7 +12,6 @@ #include #include #include -#include #include #include #include -- cgit v1.2.3 From b429b6ffbdc976d22bdf0b5ba9183c8466209cba Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Wed, 9 Aug 2023 22:27:18 +0200 Subject: thermal: intel: intel_soc_dts_iosf: Always use 2 trips Both the existing callers of intel_soc_dts_iosf_init() pass 2 as the trip count argument, so it can be replaced with SOC_MAX_DTS_TRIPS everywhere in the code and the trip_count argument of that function can be dropped. This also allows the trip_count field to be dropped from struct intel_soc_dts_sensor_entry, as it is always equal to 2, and some related code can be simplified. Make changes accordingly. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Srinivas Pandruvada --- .../processor_thermal_device_pci_legacy.c | 2 +- drivers/thermal/intel/intel_soc_dts_iosf.c | 26 +++++++--------------- drivers/thermal/intel/intel_soc_dts_iosf.h | 9 ++++---- drivers/thermal/intel/intel_soc_dts_thermal.c | 2 +- 4 files changed, 15 insertions(+), 24 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c index 09e032f822f3..46ec0e243692 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c @@ -59,7 +59,7 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, * ACPI/MSR. So we don't want to fail for auxiliary DTSs. */ proc_priv->soc_dts = intel_soc_dts_iosf_init( - INTEL_SOC_DTS_INTERRUPT_MSI, 2, 0); + INTEL_SOC_DTS_INTERRUPT_MSI, 0); if (!IS_ERR(proc_priv->soc_dts) && pdev->irq) { ret = pci_enable_msi(pdev); diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index db97499f4f0a..426d5bb5a373 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.c +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -37,9 +37,6 @@ /* DTS encoding for TJ MAX temperature */ #define SOC_DTS_TJMAX_ENCODING 0x7F -/* Only 2 out of 4 is allowed for OSPM */ -#define SOC_MAX_DTS_TRIPS 2 - /* Mask for two trips in status bits */ #define SOC_DTS_TRIP_MASK 0x03 @@ -253,12 +250,10 @@ static void remove_dts_thermal_zone(struct intel_soc_dts_sensor_entry *dts) } static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, - bool notification_support, int trip_cnt, - int read_only_trip_cnt) + bool notification_support, int read_only_trip_cnt) { char name[10]; unsigned long trip; - int trip_count = 0; int trip_mask = 0; int writable_trip_cnt = 0; unsigned long ptps; @@ -274,8 +269,7 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, dts->id = id; if (notification_support) { - trip_count = min(SOC_MAX_DTS_TRIPS, trip_cnt); - writable_trip_cnt = trip_count - read_only_trip_cnt; + writable_trip_cnt = SOC_MAX_DTS_TRIPS - read_only_trip_cnt; trip_mask = GENMASK(writable_trip_cnt - 1, 0); } @@ -290,10 +284,9 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, trip_mask &= ~BIT(i / 8); } dts->trip_mask = trip_mask; - dts->trip_count = trip_count; snprintf(name, sizeof(name), "soc_dts%d", id); dts->tzone = thermal_zone_device_register(name, - trip_count, + SOC_MAX_DTS_TRIPS, trip_mask, dts, &tzone_ops, NULL, 0, 0); @@ -324,11 +317,10 @@ int intel_soc_dts_iosf_add_read_only_critical_trip( for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { struct intel_soc_dts_sensor_entry *entry = &sensors->soc_dts[i]; int temp = sensors->tj_max - critical_offset; - unsigned long count = entry->trip_count; unsigned long mask = entry->trip_mask; - j = find_first_zero_bit(&mask, count); - if (j < count) + j = find_first_zero_bit(&mask, SOC_MAX_DTS_TRIPS); + if (j < SOC_MAX_DTS_TRIPS) return update_trip_temp(entry, j, temp, THERMAL_TRIP_CRITICAL); } @@ -372,8 +364,7 @@ void intel_soc_dts_iosf_interrupt_handler(struct intel_soc_dts_sensors *sensors) EXPORT_SYMBOL_GPL(intel_soc_dts_iosf_interrupt_handler); struct intel_soc_dts_sensors *intel_soc_dts_iosf_init( - enum intel_soc_dts_interrupt_type intr_type, int trip_count, - int read_only_trip_count) + enum intel_soc_dts_interrupt_type intr_type, int read_only_trip_count) { struct intel_soc_dts_sensors *sensors; bool notification; @@ -384,7 +375,7 @@ struct intel_soc_dts_sensors *intel_soc_dts_iosf_init( if (!iosf_mbi_available()) return ERR_PTR(-ENODEV); - if (!trip_count || read_only_trip_count > trip_count) + if (read_only_trip_count > SOC_MAX_DTS_TRIPS) return ERR_PTR(-EINVAL); tj_max = intel_tcc_get_tjmax(-1); @@ -406,8 +397,7 @@ struct intel_soc_dts_sensors *intel_soc_dts_iosf_init( for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { sensors->soc_dts[i].sensors = sensors; ret = add_dts_thermal_zone(i, &sensors->soc_dts[i], - notification, trip_count, - read_only_trip_count); + notification, read_only_trip_count); if (ret) goto err_free; } diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.h b/drivers/thermal/intel/intel_soc_dts_iosf.h index c54945748200..d10902e12592 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.h +++ b/drivers/thermal/intel/intel_soc_dts_iosf.h @@ -12,6 +12,9 @@ /* DTS0 and DTS 1 */ #define SOC_MAX_DTS_SENSORS 2 +/* Only 2 out of 4 is allowed for OSPM */ +#define SOC_MAX_DTS_TRIPS 2 + enum intel_soc_dts_interrupt_type { INTEL_SOC_DTS_INTERRUPT_NONE, INTEL_SOC_DTS_INTERRUPT_APIC, @@ -26,8 +29,7 @@ struct intel_soc_dts_sensor_entry { int id; u32 store_status; u32 trip_mask; - u32 trip_count; - enum thermal_trip_type trip_types[2]; + enum thermal_trip_type trip_types[SOC_MAX_DTS_TRIPS]; struct thermal_zone_device *tzone; struct intel_soc_dts_sensors *sensors; }; @@ -41,8 +43,7 @@ struct intel_soc_dts_sensors { }; struct intel_soc_dts_sensors *intel_soc_dts_iosf_init( - enum intel_soc_dts_interrupt_type intr_type, int trip_count, - int read_only_trip_count); + enum intel_soc_dts_interrupt_type intr_type, int read_only_trip_count); void intel_soc_dts_iosf_exit(struct intel_soc_dts_sensors *sensors); void intel_soc_dts_iosf_interrupt_handler( struct intel_soc_dts_sensors *sensors); diff --git a/drivers/thermal/intel/intel_soc_dts_thermal.c b/drivers/thermal/intel/intel_soc_dts_thermal.c index 92e5c19d03f6..8e21e5213dff 100644 --- a/drivers/thermal/intel/intel_soc_dts_thermal.c +++ b/drivers/thermal/intel/intel_soc_dts_thermal.c @@ -51,7 +51,7 @@ static int __init intel_soc_thermal_init(void) return -ENODEV; /* Create a zone with 2 trips with marked as read only */ - soc_dts = intel_soc_dts_iosf_init(INTEL_SOC_DTS_INTERRUPT_APIC, 2, 1); + soc_dts = intel_soc_dts_iosf_init(INTEL_SOC_DTS_INTERRUPT_APIC, 1); if (IS_ERR(soc_dts)) { err = PTR_ERR(soc_dts); return err; -- cgit v1.2.3 From a39524aca314a93100cafa49f0a0cf0508a00d1e Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Wed, 9 Aug 2023 22:28:12 +0200 Subject: thermal: intel: intel_soc_dts_iosf: Drop redundant symbol definition SOC_MAX_DTS_SENSORS is already defined in intel_soc_dts_iosf.h which is included in intel_soc_dts_iosf.c, so it does not need to be defined in the latter again. Drop the redundant definition of that symbol from intel_soc_dts_iosf.c. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Srinivas Pandruvada --- drivers/thermal/intel/intel_soc_dts_iosf.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index 426d5bb5a373..60bdca997c21 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.c +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -40,9 +40,6 @@ /* Mask for two trips in status bits */ #define SOC_DTS_TRIP_MASK 0x03 -/* DTS0 and DTS 1 */ -#define SOC_MAX_DTS_SENSORS 2 - static int sys_get_trip_temp(struct thermal_zone_device *tzd, int trip, int *temp) { -- cgit v1.2.3 From 4f16443596f4d3dcf0474f8c753219bd6b9470f2 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Thu, 10 Aug 2023 21:09:54 +0200 Subject: thermal: intel: intel_soc_dts_iosf: Always assume notification support None of the existing callers of intel_soc_dts_iosf_init() passes INTEL_SOC_DTS_INTERRUPT_NONE as the first argument to it, so the notification local variable in it is always true and the notification_support argument of add_dts_thermal_zone() is always true either. For this reason, drop the notification local variable from intel_soc_dts_iosf_init() and the notification_support argument from add_dts_thermal_zone() and rearrange the latter to always set writable_trip_cnt and trip_mask. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Srinivas Pandruvada --- drivers/thermal/intel/intel_soc_dts_iosf.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index 60bdca997c21..5c5790d6e786 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.c +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -247,12 +247,12 @@ static void remove_dts_thermal_zone(struct intel_soc_dts_sensor_entry *dts) } static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, - bool notification_support, int read_only_trip_cnt) + int read_only_trip_cnt) { char name[10]; unsigned long trip; - int trip_mask = 0; - int writable_trip_cnt = 0; + int writable_trip_cnt; + int trip_mask; unsigned long ptps; u32 store_ptps; unsigned long i; @@ -265,10 +265,9 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, goto err_ret; dts->id = id; - if (notification_support) { - writable_trip_cnt = SOC_MAX_DTS_TRIPS - read_only_trip_cnt; - trip_mask = GENMASK(writable_trip_cnt - 1, 0); - } + + writable_trip_cnt = SOC_MAX_DTS_TRIPS - read_only_trip_cnt; + trip_mask = GENMASK(writable_trip_cnt - 1, 0); /* Check if the writable trip we provide is not used by BIOS */ ret = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ, @@ -364,7 +363,6 @@ struct intel_soc_dts_sensors *intel_soc_dts_iosf_init( enum intel_soc_dts_interrupt_type intr_type, int read_only_trip_count) { struct intel_soc_dts_sensors *sensors; - bool notification; int tj_max; int ret; int i; @@ -387,14 +385,11 @@ struct intel_soc_dts_sensors *intel_soc_dts_iosf_init( mutex_init(&sensors->dts_update_lock); sensors->intr_type = intr_type; sensors->tj_max = tj_max * 1000; - if (intr_type == INTEL_SOC_DTS_INTERRUPT_NONE) - notification = false; - else - notification = true; + for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { sensors->soc_dts[i].sensors = sensors; ret = add_dts_thermal_zone(i, &sensors->soc_dts[i], - notification, read_only_trip_count); + read_only_trip_count); if (ret) goto err_free; } -- cgit v1.2.3 From 0b28ba273ef3bdf26c933cbe2a624deb35c82aac Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Thu, 10 Aug 2023 21:11:26 +0200 Subject: thermal: intel: intel_soc_dts_iosf: Untangle update_trip_temp() Function update_trip_temp() is currently used for the initialization of trip points as well as for changing trip point temperatures in sys_set_trip_temp(). This is quite confusing and passing the value of dts->trip_types[trip] to it so that it can store that value in the same memory location is not particularly useful, because it only is necessary to set the trip point type once, at the initialization time. For this reason, drop the last argument from update_trip_temp() and introduce configure_trip() calling the former internally for the initial configuration of trip points. Modify the majority of update_trip_temp() callers to use configure_trip() instead of it. Signed-off-by: Rafael J. Wysocki Reviewed-by: Srinivas Pandruvada --- drivers/thermal/intel/intel_soc_dts_iosf.c | 37 +++++++++++++++++++----------- 1 file changed, 24 insertions(+), 13 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index 5c5790d6e786..1f4a0ae1fda0 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.c +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -67,8 +67,7 @@ static int sys_get_trip_temp(struct thermal_zone_device *tzd, int trip, } static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts, - int thres_index, int temp, - enum thermal_trip_type trip_type) + int thres_index, int temp) { int status; u32 temp_out; @@ -142,8 +141,6 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts, if (status) goto err_restore_te_out; - dts->trip_types[thres_index] = trip_type; - return 0; err_restore_te_out: iosf_mbi_write(BT_MBI_UNIT_PMC, MBI_REG_WRITE, @@ -159,6 +156,21 @@ err_restore_ptps: return status; } +static int configure_trip(struct intel_soc_dts_sensor_entry *dts, + int thres_index, enum thermal_trip_type trip_type, + int temp) +{ + int ret; + + ret = update_trip_temp(dts, thres_index, temp); + if (ret) + return ret; + + dts->trip_types[thres_index] = trip_type; + + return 0; +} + static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, int temp) { @@ -170,8 +182,7 @@ static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, return -EINVAL; mutex_lock(&sensors->dts_update_lock); - status = update_trip_temp(dts, trip, temp, - dts->trip_types[trip]); + status = update_trip_temp(dts, trip, temp); mutex_unlock(&sensors->dts_update_lock); return status; @@ -317,7 +328,7 @@ int intel_soc_dts_iosf_add_read_only_critical_trip( j = find_first_zero_bit(&mask, SOC_MAX_DTS_TRIPS); if (j < SOC_MAX_DTS_TRIPS) - return update_trip_temp(entry, j, temp, THERMAL_TRIP_CRITICAL); + return configure_trip(entry, j, THERMAL_TRIP_CRITICAL, temp); } return -EINVAL; @@ -395,13 +406,13 @@ struct intel_soc_dts_sensors *intel_soc_dts_iosf_init( } for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { - ret = update_trip_temp(&sensors->soc_dts[i], 0, 0, - THERMAL_TRIP_PASSIVE); + ret = configure_trip(&sensors->soc_dts[i], 0, + THERMAL_TRIP_PASSIVE, 0); if (ret) goto err_remove_zone; - ret = update_trip_temp(&sensors->soc_dts[i], 1, 0, - THERMAL_TRIP_PASSIVE); + ret = configure_trip(&sensors->soc_dts[i], 1, + THERMAL_TRIP_PASSIVE, 0); if (ret) goto err_remove_zone; } @@ -422,8 +433,8 @@ void intel_soc_dts_iosf_exit(struct intel_soc_dts_sensors *sensors) int i; for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { - update_trip_temp(&sensors->soc_dts[i], 0, 0, 0); - update_trip_temp(&sensors->soc_dts[i], 1, 0, 0); + configure_trip(&sensors->soc_dts[i], 0, 0, 0); + configure_trip(&sensors->soc_dts[i], 1, 0, 0); remove_dts_thermal_zone(&sensors->soc_dts[i]); } kfree(sensors); -- cgit v1.2.3 From cbc280570438ce0e6bcb10288048eaa00762b3db Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Thu, 10 Aug 2023 21:12:32 +0200 Subject: thermal: intel: intel_soc_dts_iosf: Pass sensors to update_trip_temp() After previous changes, update_trip_temp() only uses its dts argument to get to the sensors field in the struct intel_soc_dts_sensor_entry object pointed to by that argument, so pass the value of that field directly to it instead. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Srinivas Pandruvada --- drivers/thermal/intel/intel_soc_dts_iosf.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index 1f4a0ae1fda0..afd1cbe280bf 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.c +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -66,7 +66,7 @@ static int sys_get_trip_temp(struct thermal_zone_device *tzd, int trip, return 0; } -static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts, +static int update_trip_temp(struct intel_soc_dts_sensors *sensors, int thres_index, int temp) { int status; @@ -78,7 +78,6 @@ static int update_trip_temp(struct intel_soc_dts_sensor_entry *dts, u32 store_te_out; u32 te_out; u32 int_enable_bit = SOC_DTS_TE_APICA_ENABLE; - struct intel_soc_dts_sensors *sensors = dts->sensors; if (sensors->intr_type == INTEL_SOC_DTS_INTERRUPT_MSI) int_enable_bit |= SOC_DTS_TE_MSI_ENABLE; @@ -162,7 +161,7 @@ static int configure_trip(struct intel_soc_dts_sensor_entry *dts, { int ret; - ret = update_trip_temp(dts, thres_index, temp); + ret = update_trip_temp(dts->sensors, thres_index, temp); if (ret) return ret; @@ -182,7 +181,7 @@ static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, return -EINVAL; mutex_lock(&sensors->dts_update_lock); - status = update_trip_temp(dts, trip, temp); + status = update_trip_temp(sensors, trip, temp); mutex_unlock(&sensors->dts_update_lock); return status; -- cgit v1.2.3 From 51f2aaf0dfb1a21281e2d47c94b1a5b245b033fa Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Thu, 10 Aug 2023 21:13:25 +0200 Subject: thermal: intel: intel_soc_dts_iosf: Change initialization ordering The initial configuration of trip points in intel_soc_dts_iosf_init() takes place after registering the sensor thermal zones which is potentially problematic, because it may race with the setting of trip point temperatures via sysfs, as there is no synchronization between it and sys_set_trip_temp(). To address this, change the initialization ordering so that the trip points are configured prior to the registration of thermal zones. Accordingly, change the cleanup ordering in intel_soc_dts_iosf_exit() to remove the thermal zones before resetting the trip points. Signed-off-by: Rafael J. Wysocki Reviewed-by: Srinivas Pandruvada --- drivers/thermal/intel/intel_soc_dts_iosf.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index afd1cbe280bf..5ca2e565f9a3 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.c +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -398,30 +398,37 @@ struct intel_soc_dts_sensors *intel_soc_dts_iosf_init( for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { sensors->soc_dts[i].sensors = sensors; - ret = add_dts_thermal_zone(i, &sensors->soc_dts[i], - read_only_trip_count); - if (ret) - goto err_free; - } - for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { ret = configure_trip(&sensors->soc_dts[i], 0, THERMAL_TRIP_PASSIVE, 0); if (ret) - goto err_remove_zone; + goto err_reset_trips; ret = configure_trip(&sensors->soc_dts[i], 1, THERMAL_TRIP_PASSIVE, 0); + if (ret) + goto err_reset_trips; + } + + for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { + ret = add_dts_thermal_zone(i, &sensors->soc_dts[i], + read_only_trip_count); if (ret) goto err_remove_zone; } return sensors; + err_remove_zone: for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) remove_dts_thermal_zone(&sensors->soc_dts[i]); -err_free: +err_reset_trips: + for (i = 0; i < SOC_MAX_DTS_SENSORS; i++) { + configure_trip(&sensors->soc_dts[i], 0, 0, 0); + configure_trip(&sensors->soc_dts[i], 1, 0, 0); + } + kfree(sensors); return ERR_PTR(ret); } @@ -432,9 +439,9 @@ void intel_soc_dts_iosf_exit(struct intel_soc_dts_sensors *sensors) int i; for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { + remove_dts_thermal_zone(&sensors->soc_dts[i]); configure_trip(&sensors->soc_dts[i], 0, 0, 0); configure_trip(&sensors->soc_dts[i], 1, 0, 0); - remove_dts_thermal_zone(&sensors->soc_dts[i]); } kfree(sensors); } -- cgit v1.2.3 From 5bc3da35d7ad35e61d2b902f0fdc9b530bed3d89 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Thu, 10 Aug 2023 21:14:49 +0200 Subject: thermal: intel: intel_soc_dts_iosf: Add helper for resetting trip points Because trip points are reset for each sensor in two places in the same way, add a helper function for that to reduce code duplication a bit. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Srinivas Pandruvada --- drivers/thermal/intel/intel_soc_dts_iosf.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index 5ca2e565f9a3..d1d2c77bbce7 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.c +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -369,6 +369,12 @@ void intel_soc_dts_iosf_interrupt_handler(struct intel_soc_dts_sensors *sensors) } EXPORT_SYMBOL_GPL(intel_soc_dts_iosf_interrupt_handler); +static void dts_trips_reset(struct intel_soc_dts_sensors *sensors, int dts_index) +{ + configure_trip(&sensors->soc_dts[dts_index], 0, 0, 0); + configure_trip(&sensors->soc_dts[dts_index], 1, 0, 0); +} + struct intel_soc_dts_sensors *intel_soc_dts_iosf_init( enum intel_soc_dts_interrupt_type intr_type, int read_only_trip_count) { @@ -424,10 +430,8 @@ err_remove_zone: remove_dts_thermal_zone(&sensors->soc_dts[i]); err_reset_trips: - for (i = 0; i < SOC_MAX_DTS_SENSORS; i++) { - configure_trip(&sensors->soc_dts[i], 0, 0, 0); - configure_trip(&sensors->soc_dts[i], 1, 0, 0); - } + for (i = 0; i < SOC_MAX_DTS_SENSORS; i++) + dts_trips_reset(sensors, i); kfree(sensors); return ERR_PTR(ret); @@ -440,8 +444,7 @@ void intel_soc_dts_iosf_exit(struct intel_soc_dts_sensors *sensors) for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { remove_dts_thermal_zone(&sensors->soc_dts[i]); - configure_trip(&sensors->soc_dts[i], 0, 0, 0); - configure_trip(&sensors->soc_dts[i], 1, 0, 0); + dts_trips_reset(sensors, i); } kfree(sensors); } -- cgit v1.2.3 From 02a49aaceff4a229d775b82ccaaafe59fe16b8f5 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Thu, 10 Aug 2023 21:16:14 +0200 Subject: thermal: intel: intel_soc_dts_iosf: Rework critical trip setup Critical trip points appear in the DTS thermal zones only after those thermal zones have been registered via intel_soc_dts_iosf_init(). Moreover, they are "created" by changing the type of an existing trip point from THERMAL_TRIP_PASSIVE to THERMAL_TRIP_CRITICAL via intel_soc_dts_iosf_add_read_only_critical_trip(), the caller of which has to be careful enough to pass at least 1 as the number of read-only trip points to intel_soc_dts_iosf_init() beforehand. This is questionable, because user space may have started to use the trips at the time when intel_soc_dts_iosf_add_read_only_critical_trip() runs and there is no synchronization between it and sys_set_trip_temp(). To address it, use the observation that nonzero number of read-only trip points is only passed to intel_soc_dts_iosf_init() when critical trip points are going to be used, so in fact that function may get all of the information regarding the critical trip points upfront and it can configure them before registering the corresponding thermal zones. Accordingly, replace the read_only_trip_count argument of intel_soc_dts_iosf_init() with a pair of new arguments related to critical trip points: a bool one indicating whether or not critical trip points are to be used at all and an int one representing the critical trip point temperature offset relative to Tj_max. Use these arguments to configure the critical trip points before the registration of the thermal zones and to compute the number of writeable trip points in add_dts_thermal_zone(). Modify both callers of intel_soc_dts_iosf_init() to take these changes into account and drop the intel_soc_dts_iosf_add_read_only_critical_trip() call, that is not necessary any more, from intel_soc_thermal_init(), which also allows it to return success right after requesting the IRQ. Finally, drop intel_soc_dts_iosf_add_read_only_critical_trip() altogether, because it does not have any more users. Signed-off-by: Rafael J. Wysocki Reviewed-by: Srinivas Pandruvada --- .../processor_thermal_device_pci_legacy.c | 2 +- drivers/thermal/intel/intel_soc_dts_iosf.c | 51 +++++++++------------- drivers/thermal/intel/intel_soc_dts_iosf.h | 8 ++-- drivers/thermal/intel/intel_soc_dts_thermal.c | 17 +------- 4 files changed, 27 insertions(+), 51 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c index 46ec0e243692..16fd9df5f36d 100644 --- a/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c +++ b/drivers/thermal/intel/int340x_thermal/processor_thermal_device_pci_legacy.c @@ -59,7 +59,7 @@ static int proc_thermal_pci_probe(struct pci_dev *pdev, * ACPI/MSR. So we don't want to fail for auxiliary DTSs. */ proc_priv->soc_dts = intel_soc_dts_iosf_init( - INTEL_SOC_DTS_INTERRUPT_MSI, 0); + INTEL_SOC_DTS_INTERRUPT_MSI, false, 0); if (!IS_ERR(proc_priv->soc_dts) && pdev->irq) { ret = pci_enable_msi(pdev); diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index d1d2c77bbce7..cb418a91100c 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.c +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -257,11 +257,11 @@ static void remove_dts_thermal_zone(struct intel_soc_dts_sensor_entry *dts) } static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, - int read_only_trip_cnt) + bool critical_trip) { + int writable_trip_cnt = SOC_MAX_DTS_TRIPS; char name[10]; unsigned long trip; - int writable_trip_cnt; int trip_mask; unsigned long ptps; u32 store_ptps; @@ -276,7 +276,9 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, dts->id = id; - writable_trip_cnt = SOC_MAX_DTS_TRIPS - read_only_trip_cnt; + if (critical_trip) + writable_trip_cnt--; + trip_mask = GENMASK(writable_trip_cnt - 1, 0); /* Check if the writable trip we provide is not used by BIOS */ @@ -315,25 +317,6 @@ err_ret: return ret; } -int intel_soc_dts_iosf_add_read_only_critical_trip( - struct intel_soc_dts_sensors *sensors, int critical_offset) -{ - int i, j; - - for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { - struct intel_soc_dts_sensor_entry *entry = &sensors->soc_dts[i]; - int temp = sensors->tj_max - critical_offset; - unsigned long mask = entry->trip_mask; - - j = find_first_zero_bit(&mask, SOC_MAX_DTS_TRIPS); - if (j < SOC_MAX_DTS_TRIPS) - return configure_trip(entry, j, THERMAL_TRIP_CRITICAL, temp); - } - - return -EINVAL; -} -EXPORT_SYMBOL_GPL(intel_soc_dts_iosf_add_read_only_critical_trip); - void intel_soc_dts_iosf_interrupt_handler(struct intel_soc_dts_sensors *sensors) { u32 sticky_out; @@ -375,8 +358,9 @@ static void dts_trips_reset(struct intel_soc_dts_sensors *sensors, int dts_index configure_trip(&sensors->soc_dts[dts_index], 1, 0, 0); } -struct intel_soc_dts_sensors *intel_soc_dts_iosf_init( - enum intel_soc_dts_interrupt_type intr_type, int read_only_trip_count) +struct intel_soc_dts_sensors * +intel_soc_dts_iosf_init(enum intel_soc_dts_interrupt_type intr_type, + bool critical_trip, int crit_offset) { struct intel_soc_dts_sensors *sensors; int tj_max; @@ -386,9 +370,6 @@ struct intel_soc_dts_sensors *intel_soc_dts_iosf_init( if (!iosf_mbi_available()) return ERR_PTR(-ENODEV); - if (read_only_trip_count > SOC_MAX_DTS_TRIPS) - return ERR_PTR(-EINVAL); - tj_max = intel_tcc_get_tjmax(-1); if (tj_max < 0) return ERR_PTR(tj_max); @@ -403,6 +384,9 @@ struct intel_soc_dts_sensors *intel_soc_dts_iosf_init( sensors->tj_max = tj_max * 1000; for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { + enum thermal_trip_type trip_type; + int temp; + sensors->soc_dts[i].sensors = sensors; ret = configure_trip(&sensors->soc_dts[i], 0, @@ -410,15 +394,20 @@ struct intel_soc_dts_sensors *intel_soc_dts_iosf_init( if (ret) goto err_reset_trips; - ret = configure_trip(&sensors->soc_dts[i], 1, - THERMAL_TRIP_PASSIVE, 0); + if (critical_trip) { + trip_type = THERMAL_TRIP_CRITICAL; + temp = sensors->tj_max - crit_offset; + } else { + trip_type = THERMAL_TRIP_PASSIVE; + temp = 0; + } + ret = configure_trip(&sensors->soc_dts[i], 1, trip_type, temp); if (ret) goto err_reset_trips; } for (i = 0; i < SOC_MAX_DTS_SENSORS; ++i) { - ret = add_dts_thermal_zone(i, &sensors->soc_dts[i], - read_only_trip_count); + ret = add_dts_thermal_zone(i, &sensors->soc_dts[i], critical_trip); if (ret) goto err_remove_zone; } diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.h b/drivers/thermal/intel/intel_soc_dts_iosf.h index d10902e12592..739aa556dc43 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.h +++ b/drivers/thermal/intel/intel_soc_dts_iosf.h @@ -42,11 +42,11 @@ struct intel_soc_dts_sensors { struct intel_soc_dts_sensor_entry soc_dts[SOC_MAX_DTS_SENSORS]; }; -struct intel_soc_dts_sensors *intel_soc_dts_iosf_init( - enum intel_soc_dts_interrupt_type intr_type, int read_only_trip_count); + +struct intel_soc_dts_sensors * +intel_soc_dts_iosf_init(enum intel_soc_dts_interrupt_type intr_type, + bool critical_trip, int crit_offset); void intel_soc_dts_iosf_exit(struct intel_soc_dts_sensors *sensors); void intel_soc_dts_iosf_interrupt_handler( struct intel_soc_dts_sensors *sensors); -int intel_soc_dts_iosf_add_read_only_critical_trip( - struct intel_soc_dts_sensors *sensors, int critical_offset); #endif diff --git a/drivers/thermal/intel/intel_soc_dts_thermal.c b/drivers/thermal/intel/intel_soc_dts_thermal.c index 8e21e5213dff..9c825c6e1f38 100644 --- a/drivers/thermal/intel/intel_soc_dts_thermal.c +++ b/drivers/thermal/intel/intel_soc_dts_thermal.c @@ -51,7 +51,8 @@ static int __init intel_soc_thermal_init(void) return -ENODEV; /* Create a zone with 2 trips with marked as read only */ - soc_dts = intel_soc_dts_iosf_init(INTEL_SOC_DTS_INTERRUPT_APIC, 1); + soc_dts = intel_soc_dts_iosf_init(INTEL_SOC_DTS_INTERRUPT_APIC, true, + crit_offset); if (IS_ERR(soc_dts)) { err = PTR_ERR(soc_dts); return err; @@ -88,21 +89,7 @@ static int __init intel_soc_thermal_init(void) } } - err = intel_soc_dts_iosf_add_read_only_critical_trip(soc_dts, - crit_offset); - if (err) - goto error_trips; - return 0; - -error_trips: - if (soc_dts_thres_irq) { - free_irq(soc_dts_thres_irq, soc_dts); - acpi_unregister_gsi(soc_dts_thres_gsi); - } - intel_soc_dts_iosf_exit(soc_dts); - - return err; } static void __exit intel_soc_thermal_exit(void) -- cgit v1.2.3 From 4effd28e61e768bcc2017c58cd23bd0846649ac4 Mon Sep 17 00:00:00 2001 From: "Rafael J. Wysocki" Date: Thu, 10 Aug 2023 21:17:36 +0200 Subject: thermal: intel: intel_soc_dts_iosf: Use struct thermal_trip Because the number of trip points in each thermal zone and their types are known to intel_soc_dts_iosf_init() prior to the registration of the thermal zones, make it create an array of struct thermal_trip entries in each struct intel_soc_dts_sensor_entry object and make add_dts_thermal_zone() use thermal_zone_device_register_with_trips() for thermal zone registration and pass that array as its second argument. Drop the sys_get_trip_temp() and sys_get_trip_type() callback functions along with the respective callback pointers in tzone_ops, because they are not necessary any more. Signed-off-by: Rafael J. Wysocki Reviewed-by: Srinivas Pandruvada --- drivers/thermal/intel/intel_soc_dts_iosf.c | 51 ++++-------------------------- drivers/thermal/intel/intel_soc_dts_iosf.h | 2 +- 2 files changed, 8 insertions(+), 45 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index cb418a91100c..7a66d0f077b0 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.c +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -40,32 +40,6 @@ /* Mask for two trips in status bits */ #define SOC_DTS_TRIP_MASK 0x03 -static int sys_get_trip_temp(struct thermal_zone_device *tzd, int trip, - int *temp) -{ - int status; - u32 out; - struct intel_soc_dts_sensor_entry *dts; - struct intel_soc_dts_sensors *sensors; - - dts = thermal_zone_device_priv(tzd); - sensors = dts->sensors; - mutex_lock(&sensors->dts_update_lock); - status = iosf_mbi_read(BT_MBI_UNIT_PMC, MBI_REG_READ, - SOC_DTS_OFFSET_PTPS, &out); - mutex_unlock(&sensors->dts_update_lock); - if (status) - return status; - - out = (out >> (trip * 8)) & SOC_DTS_TJMAX_ENCODING; - if (!out) - *temp = 0; - else - *temp = sensors->tj_max - out * 1000; - - return 0; -} - static int update_trip_temp(struct intel_soc_dts_sensors *sensors, int thres_index, int temp) { @@ -165,7 +139,8 @@ static int configure_trip(struct intel_soc_dts_sensor_entry *dts, if (ret) return ret; - dts->trip_types[thres_index] = trip_type; + dts->trips[thres_index].temperature = temp; + dts->trips[thres_index].type = trip_type; return 0; } @@ -187,16 +162,6 @@ static int sys_set_trip_temp(struct thermal_zone_device *tzd, int trip, return status; } -static int sys_get_trip_type(struct thermal_zone_device *tzd, - int trip, enum thermal_trip_type *type) -{ - struct intel_soc_dts_sensor_entry *dts = thermal_zone_device_priv(tzd); - - *type = dts->trip_types[trip]; - - return 0; -} - static int sys_get_curr_temp(struct thermal_zone_device *tzd, int *temp) { @@ -221,8 +186,6 @@ static int sys_get_curr_temp(struct thermal_zone_device *tzd, static struct thermal_zone_device_ops tzone_ops = { .get_temp = sys_get_curr_temp, - .get_trip_temp = sys_get_trip_temp, - .get_trip_type = sys_get_trip_type, .set_trip_temp = sys_set_trip_temp, }; @@ -293,11 +256,11 @@ static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, } dts->trip_mask = trip_mask; snprintf(name, sizeof(name), "soc_dts%d", id); - dts->tzone = thermal_zone_device_register(name, - SOC_MAX_DTS_TRIPS, - trip_mask, - dts, &tzone_ops, - NULL, 0, 0); + dts->tzone = thermal_zone_device_register_with_trips(name, dts->trips, + SOC_MAX_DTS_TRIPS, + trip_mask, + dts, &tzone_ops, + NULL, 0, 0); if (IS_ERR(dts->tzone)) { ret = PTR_ERR(dts->tzone); goto err_ret; diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.h b/drivers/thermal/intel/intel_soc_dts_iosf.h index 739aa556dc43..162841df0ebe 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.h +++ b/drivers/thermal/intel/intel_soc_dts_iosf.h @@ -29,7 +29,7 @@ struct intel_soc_dts_sensor_entry { int id; u32 store_status; u32 trip_mask; - enum thermal_trip_type trip_types[SOC_MAX_DTS_TRIPS]; + struct thermal_trip trips[SOC_MAX_DTS_TRIPS]; struct thermal_zone_device *tzone; struct intel_soc_dts_sensors *sensors; }; -- cgit v1.2.3 From f96801f0cfcefc0a16b146596577c53c75ee9773 Mon Sep 17 00:00:00 2001 From: Peng Fan Date: Wed, 19 Jul 2023 09:16:36 +0800 Subject: thermal/of: Fix potential uninitialized value access If of_parse_phandle_with_args() called from __thermal_of_bind() or __thermal_of_unbind() fails, cooling_spec.np will not be initialized, so move the of_node_put() calls below the respective return value checks to avoid dereferencing an uninitialized pointer. Fixes: 3fd6d6e2b4e8 ("thermal/of: Rework the thermal device tree initialization") Signed-off-by: Peng Fan [ rjw: Subject and changelog edits ] Signed-off-by: Rafael J. Wysocki --- drivers/thermal/thermal_of.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/thermal_of.c b/drivers/thermal/thermal_of.c index 330690a3a208..4ca905723429 100644 --- a/drivers/thermal/thermal_of.c +++ b/drivers/thermal/thermal_of.c @@ -291,13 +291,13 @@ static int __thermal_of_unbind(struct device_node *map_np, int index, int trip_i ret = of_parse_phandle_with_args(map_np, "cooling-device", "#cooling-cells", index, &cooling_spec); - of_node_put(cooling_spec.np); - if (ret < 0) { pr_err("Invalid cooling-device entry\n"); return ret; } + of_node_put(cooling_spec.np); + if (cooling_spec.args_count < 2) { pr_err("wrong reference to cooling device, missing limits\n"); return -EINVAL; @@ -324,13 +324,13 @@ static int __thermal_of_bind(struct device_node *map_np, int index, int trip_id, ret = of_parse_phandle_with_args(map_np, "cooling-device", "#cooling-cells", index, &cooling_spec); - of_node_put(cooling_spec.np); - if (ret < 0) { pr_err("Invalid cooling-device entry\n"); return ret; } + of_node_put(cooling_spec.np); + if (cooling_spec.args_count < 2) { pr_err("wrong reference to cooling device, missing limits\n"); return -EINVAL; -- cgit v1.2.3 From 1a6e1004f3225bebbe27e1575c22484a56e96f56 Mon Sep 17 00:00:00 2001 From: Yang Yingliang Date: Fri, 4 Aug 2023 17:21:01 +0800 Subject: thermal: intel: int340x: simplify the code with module_platform_driver() The init/exit() of the driver only calls platform_driver_{un}register(), so it can be simpilfied by using module_platform_driver(). Signed-off-by: Yang Yingliang [ rjw: Subject and changelog edits ] Signed-off-by: Rafael J. Wysocki --- drivers/thermal/intel/int340x_thermal/int3401_thermal.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/intel/int340x_thermal/int3401_thermal.c b/drivers/thermal/intel/int340x_thermal/int3401_thermal.c index 217786fba185..c93a28eec4db 100644 --- a/drivers/thermal/intel/int340x_thermal/int3401_thermal.c +++ b/drivers/thermal/intel/int340x_thermal/int3401_thermal.c @@ -70,18 +70,7 @@ static struct platform_driver int3401_driver = { }, }; -static int __init proc_thermal_init(void) -{ - return platform_driver_register(&int3401_driver); -} - -static void __exit proc_thermal_exit(void) -{ - platform_driver_unregister(&int3401_driver); -} - -module_init(proc_thermal_init); -module_exit(proc_thermal_exit); +module_platform_driver(int3401_driver); MODULE_AUTHOR("Srinivas Pandruvada "); MODULE_DESCRIPTION("Processor Thermal Reporting Device Driver"); -- cgit v1.2.3 From ee188ee6ed3821ec20c1d3e8b7aacd844924b10b Mon Sep 17 00:00:00 2001 From: Zhang Rui Date: Sun, 13 Aug 2023 10:52:20 +0800 Subject: thermal: intel: intel_soc_dts_iosf: Remove redundant check Remove the redundant check in remove_dts_thermal_zone() because all of its existing callers pass a valid pointer as the argument. Signed-off-by: Zhang Rui Signed-off-by: Rafael J. Wysocki --- drivers/thermal/intel/intel_soc_dts_iosf.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'drivers/thermal') diff --git a/drivers/thermal/intel/intel_soc_dts_iosf.c b/drivers/thermal/intel/intel_soc_dts_iosf.c index 7a66d0f077b0..d00def3c4703 100644 --- a/drivers/thermal/intel/intel_soc_dts_iosf.c +++ b/drivers/thermal/intel/intel_soc_dts_iosf.c @@ -212,11 +212,9 @@ static int soc_dts_enable(int id) static void remove_dts_thermal_zone(struct intel_soc_dts_sensor_entry *dts) { - if (dts) { - iosf_mbi_write(BT_MBI_UNIT_PMC, MBI_REG_WRITE, - SOC_DTS_OFFSET_ENABLE, dts->store_status); - thermal_zone_device_unregister(dts->tzone); - } + iosf_mbi_write(BT_MBI_UNIT_PMC, MBI_REG_WRITE, + SOC_DTS_OFFSET_ENABLE, dts->store_status); + thermal_zone_device_unregister(dts->tzone); } static int add_dts_thermal_zone(int id, struct intel_soc_dts_sensor_entry *dts, -- cgit v1.2.3