From nobody Mon Apr 6 18:06:12 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE7A3C43219 for ; Tue, 4 Oct 2022 17:27:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229747AbiJDR1Y (ORCPT ); Tue, 4 Oct 2022 13:27:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229710AbiJDR1P (ORCPT ); Tue, 4 Oct 2022 13:27:15 -0400 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 15D1F5A899 for ; Tue, 4 Oct 2022 10:27:09 -0700 (PDT) Received: by mail-wm1-x329.google.com with SMTP id i83-20020a1c3b56000000b003bd44dc526fso1215272wma.3 for ; Tue, 04 Oct 2022 10:27:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=f+UH6eHRlE/MTxCKRlbB94yySc6CPvVskocmDXPZ1ko=; b=rSeZSThbp1adPwA74ZTvwspF6EWUoGUJdGpR9GbxnB2tfpzniKQrul5Gf6OFj97Wca zpoH3oBT+zdI9JJ1t9vLo3GhOSA90OWancwRmU3exbgtRM4rh1p+IwWrtvaPCcCbABxl +wnmMJOkeookBw4tKeUyoV2qj2bAs2RTyzwPNfQU+c/NkbIDExV2nslHQZ4J9SrshBYF itPrj0hUTxi1tAKJvYeZT4X+RcrWG8AQDQZ5BkzAhGeVNXl8VCleBd/h+fDADP/7k2k+ ePVNoAlqkjvVP4BSm1K1GMAN+HHS+hbTgLybqx8//PJuUo3nbFSs4RAiAzLgB2daUK1E 1mAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=f+UH6eHRlE/MTxCKRlbB94yySc6CPvVskocmDXPZ1ko=; b=lU1CAJq8FQuiEDtY0qdjTBmr6wPP8A8kKcG01diELbFKyaGxRM3aIeLYpFkqUGghUe nFiF8fjgGtzIGfj0KUiqnqC90baFpqKfv1JfxyAkk6/bJVIT6N0KXD86wqzrzC/Le0pq GrEyM2KBoVUMFEvLvkpUUoqUv5oLgzca3QHc8AGbjCAUy//VjCWGP8sCdmd/Ya1KTN0r pkwQHc5nPVk+DvbZXYSZiWlO2sKDXPXLIaxjR8u+RJZOqdcU6orHqRZ5es9VL9+q7Z8T 4lG556cd3LKBq/SQhOQNAh8u6SUoRtTQHUEHodFBSLglzPdDwbNcdP0WTZ1mcMQ/XQIX QiIw== X-Gm-Message-State: ACrzQf1g0fNhXdfo006vpTqBKTWhJ06lVCGGRLVrWfnfJ8cdnQG8m6G4 L/YRv9NjIlwhvw84/Q48sJTKPA== X-Google-Smtp-Source: AMsMyM47YrG4B1I62NMttOD8xCnS4Oa0WqUvvvUfsXwTaorb52kIib0lRTGlLBpEpi7voCeEKpk2ZQ== X-Received: by 2002:a05:600c:5014:b0:3b5:889:58a5 with SMTP id n20-20020a05600c501400b003b5088958a5mr589786wmr.140.1664904427990; Tue, 04 Oct 2022 10:27:07 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:c456:8337:99aa:2667]) by smtp.gmail.com with ESMTPSA id l19-20020a5d5273000000b00228dbf15072sm13060941wrc.62.2022.10.04.10.27.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 10:27:07 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Rui , Len Brown Subject: [PATCH RFC 1/9] thermal/acpi: Remove the intermediate acpi_thermal_trip structure Date: Tue, 4 Oct 2022 19:26:50 +0200 Message-Id: <20221004172658.2302511-2-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004172658.2302511-1-daniel.lezcano@linaro.org> References: <12068304.O9o76ZdvQC@kreacher> <20221004172658.2302511-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The struct acpi_thermal_trips() contains the critical, hot, passive and active trip points structure. In order to use the generic thermal trips, let's move out those fields in the struct acpi_thermal instead of having them encapsulated in an intermediate structure. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 183 +++++++++++++++++++++-------------------- 1 file changed, 93 insertions(+), 90 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 539660ef93c7..b2e73e45c6d6 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -166,7 +166,10 @@ struct acpi_thermal { volatile u8 zombie; struct acpi_thermal_flags flags; struct acpi_thermal_state state; - struct acpi_thermal_trips trips; + struct acpi_thermal_critical critical; + struct acpi_thermal_hot hot; + struct acpi_thermal_passive passive; + struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE]; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; int kelvin_offset; /* in millidegrees */ @@ -272,7 +275,7 @@ static int acpi_thermal_trips_update(struct acpi_therma= l *tz, int flag) if (flag & ACPI_TRIPS_CRITICAL) { status =3D acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp); - tz->trips.critical.temperature =3D tmp; + tz->critical.temperature =3D tmp; /* * Treat freezing temperatures as invalid as well; some * BIOSes return really low values and cause reboots at startup. @@ -280,32 +283,32 @@ static int acpi_thermal_trips_update(struct acpi_ther= mal *tz, int flag) * ... so lets discard those as invalid. */ if (ACPI_FAILURE(status)) { - tz->trips.critical.flags.valid =3D 0; + tz->critical.flags.valid =3D 0; acpi_handle_debug(tz->device->handle, "No critical threshold\n"); } else if (tmp <=3D 2732) { pr_info(FW_BUG "Invalid critical threshold (%llu)\n", tmp); - tz->trips.critical.flags.valid =3D 0; + tz->critical.flags.valid =3D 0; } else { - tz->trips.critical.flags.valid =3D 1; + tz->critical.flags.valid =3D 1; acpi_handle_debug(tz->device->handle, "Found critical threshold [%lu]\n", - tz->trips.critical.temperature); + tz->critical.temperature); } - if (tz->trips.critical.flags.valid =3D=3D 1) { + if (tz->critical.flags.valid =3D=3D 1) { if (crt =3D=3D -1) { - tz->trips.critical.flags.valid =3D 0; + tz->critical.flags.valid =3D 0; } else if (crt > 0) { unsigned long crt_k =3D celsius_to_deci_kelvin(crt); =20 /* * Allow override critical threshold */ - if (crt_k > tz->trips.critical.temperature) + if (crt_k > tz->critical.temperature) pr_info("Critical threshold %d C\n", crt); =20 - tz->trips.critical.temperature =3D crt_k; + tz->critical.temperature =3D crt_k; } } } @@ -315,22 +318,22 @@ static int acpi_thermal_trips_update(struct acpi_ther= mal *tz, int flag) status =3D acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp); if (ACPI_FAILURE(status)) { - tz->trips.hot.flags.valid =3D 0; + tz->hot.flags.valid =3D 0; acpi_handle_debug(tz->device->handle, "No hot threshold\n"); } else { - tz->trips.hot.temperature =3D tmp; - tz->trips.hot.flags.valid =3D 1; + tz->hot.temperature =3D tmp; + tz->hot.flags.valid =3D 1; acpi_handle_debug(tz->device->handle, "Found hot threshold [%lu]\n", - tz->trips.hot.temperature); + tz->hot.temperature); } } =20 /* Passive (optional) */ - if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) || + if (((flag & ACPI_TRIPS_PASSIVE) && tz->passive.flags.valid) || (flag =3D=3D ACPI_TRIPS_INIT)) { - valid =3D tz->trips.passive.flags.valid; + valid =3D tz->passive.flags.valid; if (psv =3D=3D -1) { status =3D AE_SUPPORT; } else if (psv > 0) { @@ -342,122 +345,122 @@ static int acpi_thermal_trips_update(struct acpi_th= ermal *tz, int flag) } =20 if (ACPI_FAILURE(status)) - tz->trips.passive.flags.valid =3D 0; + tz->passive.flags.valid =3D 0; else { - tz->trips.passive.temperature =3D tmp; - tz->trips.passive.flags.valid =3D 1; + tz->passive.temperature =3D tmp; + tz->passive.flags.valid =3D 1; if (flag =3D=3D ACPI_TRIPS_INIT) { status =3D acpi_evaluate_integer( tz->device->handle, "_TC1", NULL, &tmp); if (ACPI_FAILURE(status)) - tz->trips.passive.flags.valid =3D 0; + tz->passive.flags.valid =3D 0; else - tz->trips.passive.tc1 =3D tmp; + tz->passive.tc1 =3D tmp; status =3D acpi_evaluate_integer( tz->device->handle, "_TC2", NULL, &tmp); if (ACPI_FAILURE(status)) - tz->trips.passive.flags.valid =3D 0; + tz->passive.flags.valid =3D 0; else - tz->trips.passive.tc2 =3D tmp; + tz->passive.tc2 =3D tmp; status =3D acpi_evaluate_integer( tz->device->handle, "_TSP", NULL, &tmp); if (ACPI_FAILURE(status)) - tz->trips.passive.flags.valid =3D 0; + tz->passive.flags.valid =3D 0; else - tz->trips.passive.tsp =3D tmp; + tz->passive.tsp =3D tmp; } } } - if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.flags.valid) { + if ((flag & ACPI_TRIPS_DEVICES) && tz->passive.flags.valid) { memset(&devices, 0, sizeof(struct acpi_handle_list)); status =3D 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.flags.valid =3D 0; + tz->passive.flags.valid =3D 0; } else - tz->trips.passive.flags.valid =3D 1; + tz->passive.flags.valid =3D 1; =20 - if (memcmp(&tz->trips.passive.devices, &devices, + if (memcmp(&tz->passive.devices, &devices, sizeof(struct acpi_handle_list))) { - memcpy(&tz->trips.passive.devices, &devices, + memcpy(&tz->passive.devices, &devices, sizeof(struct acpi_handle_list)); ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); } } if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) { - if (valid !=3D tz->trips.passive.flags.valid) + if (valid !=3D tz->passive.flags.valid) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); } =20 /* Active (optional) */ for (i =3D 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { char name[5] =3D { '_', 'A', 'C', ('0' + i), '\0' }; - valid =3D tz->trips.active[i].flags.valid; + valid =3D tz->active[i].flags.valid; =20 if (act =3D=3D -1) break; /* disable all active trip points */ =20 if ((flag =3D=3D ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) && - tz->trips.active[i].flags.valid)) { + tz->active[i].flags.valid)) { status =3D acpi_evaluate_integer(tz->device->handle, name, NULL, &tmp); if (ACPI_FAILURE(status)) { - tz->trips.active[i].flags.valid =3D 0; + tz->active[i].flags.valid =3D 0; if (i =3D=3D 0) break; if (act <=3D 0) break; if (i =3D=3D 1) - tz->trips.active[0].temperature =3D + tz->active[0].temperature =3D celsius_to_deci_kelvin(act); else /* * Don't allow override higher than * the next higher trip point */ - tz->trips.active[i - 1].temperature =3D - (tz->trips.active[i - 2].temperature < + tz->active[i - 1].temperature =3D + (tz->active[i - 2].temperature < celsius_to_deci_kelvin(act) ? - tz->trips.active[i - 2].temperature : + tz->active[i - 2].temperature : celsius_to_deci_kelvin(act)); break; } else { - tz->trips.active[i].temperature =3D tmp; - tz->trips.active[i].flags.valid =3D 1; + tz->active[i].temperature =3D tmp; + tz->active[i].flags.valid =3D 1; } } =20 name[2] =3D 'L'; - if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].flags.valid ) { + if ((flag & ACPI_TRIPS_DEVICES) && tz->active[i].flags.valid ) { memset(&devices, 0, sizeof(struct acpi_handle_list)); status =3D 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].flags.valid =3D 0; + tz->active[i].flags.valid =3D 0; } else - tz->trips.active[i].flags.valid =3D 1; + tz->active[i].flags.valid =3D 1; =20 - if (memcmp(&tz->trips.active[i].devices, &devices, + if (memcmp(&tz->active[i].devices, &devices, sizeof(struct acpi_handle_list))) { - memcpy(&tz->trips.active[i].devices, &devices, + memcpy(&tz->active[i].devices, &devices, sizeof(struct acpi_handle_list)); ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); } } if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES)) - if (valid !=3D tz->trips.active[i].flags.valid) + if (valid !=3D tz->active[i].flags.valid) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); =20 - if (!tz->trips.active[i].flags.valid) + if (!tz->active[i].flags.valid) break; } =20 @@ -482,12 +485,12 @@ static int acpi_thermal_get_trip_points(struct acpi_t= hermal *tz) if (ret) return ret; =20 - valid =3D tz->trips.critical.flags.valid | - tz->trips.hot.flags.valid | - tz->trips.passive.flags.valid; + valid =3D tz->critical.flags.valid | + tz->hot.flags.valid | + tz->passive.flags.valid; =20 for (i =3D 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) - valid |=3D tz->trips.active[i].flags.valid; + valid |=3D tz->active[i].flags.valid; =20 if (!valid) { pr_warn(FW_BUG "No valid trip found\n"); @@ -524,7 +527,7 @@ static int thermal_get_trip_type(struct thermal_zone_de= vice *thermal, if (!tz || trip < 0) return -EINVAL; =20 - if (tz->trips.critical.flags.valid) { + if (tz->critical.flags.valid) { if (!trip) { *type =3D THERMAL_TRIP_CRITICAL; return 0; @@ -532,7 +535,7 @@ static int thermal_get_trip_type(struct thermal_zone_de= vice *thermal, trip--; } =20 - if (tz->trips.hot.flags.valid) { + if (tz->hot.flags.valid) { if (!trip) { *type =3D THERMAL_TRIP_HOT; return 0; @@ -540,7 +543,7 @@ static int thermal_get_trip_type(struct thermal_zone_de= vice *thermal, trip--; } =20 - if (tz->trips.passive.flags.valid) { + if (tz->passive.flags.valid) { if (!trip) { *type =3D THERMAL_TRIP_PASSIVE; return 0; @@ -549,7 +552,7 @@ static int thermal_get_trip_type(struct thermal_zone_de= vice *thermal, } =20 for (i =3D 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->trips.active[i].flags.valid; i++) { + tz->active[i].flags.valid; i++) { if (!trip) { *type =3D THERMAL_TRIP_ACTIVE; return 0; @@ -569,30 +572,30 @@ static int thermal_get_trip_temp(struct thermal_zone_= device *thermal, if (!tz || trip < 0) return -EINVAL; =20 - if (tz->trips.critical.flags.valid) { + if (tz->critical.flags.valid) { if (!trip) { *temp =3D deci_kelvin_to_millicelsius_with_offset( - tz->trips.critical.temperature, + tz->critical.temperature, tz->kelvin_offset); return 0; } trip--; } =20 - if (tz->trips.hot.flags.valid) { + if (tz->hot.flags.valid) { if (!trip) { *temp =3D deci_kelvin_to_millicelsius_with_offset( - tz->trips.hot.temperature, + tz->hot.temperature, tz->kelvin_offset); return 0; } trip--; } =20 - if (tz->trips.passive.flags.valid) { + if (tz->passive.flags.valid) { if (!trip) { *temp =3D deci_kelvin_to_millicelsius_with_offset( - tz->trips.passive.temperature, + tz->passive.temperature, tz->kelvin_offset); return 0; } @@ -600,10 +603,10 @@ static int thermal_get_trip_temp(struct thermal_zone_= device *thermal, } =20 for (i =3D 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->trips.active[i].flags.valid; i++) { + tz->active[i].flags.valid; i++) { if (!trip) { *temp =3D deci_kelvin_to_millicelsius_with_offset( - tz->trips.active[i].temperature, + tz->active[i].temperature, tz->kelvin_offset); return 0; } @@ -618,9 +621,9 @@ static int thermal_get_crit_temp(struct thermal_zone_de= vice *thermal, { struct acpi_thermal *tz =3D thermal->devdata; =20 - if (tz->trips.critical.flags.valid) { + if (tz->critical.flags.valid) { *temperature =3D deci_kelvin_to_millicelsius_with_offset( - tz->trips.critical.temperature, + tz->critical.temperature, tz->kelvin_offset); return 0; } else @@ -657,9 +660,9 @@ static int thermal_get_trend(struct thermal_zone_device= *thermal, * tz->temperature has already been updated by generic thermal layer, * before this callback being invoked */ - i =3D (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature)) - + (tz->trips.passive.tc2 - * (tz->temperature - tz->trips.passive.temperature)); + i =3D (tz->passive.tc1 * (tz->temperature - tz->last_temperature)) + + (tz->passive.tc2 + * (tz->temperature - tz->passive.temperature)); =20 if (i > 0) *trend =3D THERMAL_TREND_RAISING; @@ -703,17 +706,17 @@ static int acpi_thermal_cooling_device_cb(struct ther= mal_zone_device *thermal, int trip =3D -1; int result =3D 0; =20 - if (tz->trips.critical.flags.valid) + if (tz->critical.flags.valid) trip++; =20 - if (tz->trips.hot.flags.valid) + if (tz->hot.flags.valid) trip++; =20 - if (tz->trips.passive.flags.valid) { + if (tz->passive.flags.valid) { trip++; - for (i =3D 0; i < tz->trips.passive.devices.count; + for (i =3D 0; i < tz->passive.devices.count; i++) { - handle =3D tz->trips.passive.devices.handles[i]; + handle =3D tz->passive.devices.handles[i]; dev =3D acpi_fetch_acpi_dev(handle); if (dev !=3D device) continue; @@ -733,13 +736,13 @@ static int acpi_thermal_cooling_device_cb(struct ther= mal_zone_device *thermal, } =20 for (i =3D 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - if (!tz->trips.active[i].flags.valid) + if (!tz->active[i].flags.valid) break; trip++; for (j =3D 0; - j < tz->trips.active[i].devices.count; + j < tz->active[i].devices.count; j++) { - handle =3D tz->trips.active[i].devices.handles[j]; + handle =3D tz->active[i].devices.handles[j]; dev =3D acpi_fetch_acpi_dev(handle); if (dev !=3D device) continue; @@ -793,23 +796,23 @@ static int acpi_thermal_register_thermal_zone(struct = acpi_thermal *tz) acpi_status status; int i; =20 - if (tz->trips.critical.flags.valid) + if (tz->critical.flags.valid) trips++; =20 - if (tz->trips.hot.flags.valid) + if (tz->hot.flags.valid) trips++; =20 - if (tz->trips.passive.flags.valid) + if (tz->passive.flags.valid) trips++; =20 for (i =3D 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->trips.active[i].flags.valid; i++, trips++); + tz->active[i].flags.valid; i++, trips++); =20 - if (tz->trips.passive.flags.valid) + if (tz->passive.flags.valid) tz->thermal_zone =3D thermal_zone_device_register("acpitz", trips, 0, tz, &acpi_thermal_zone_ops, NULL, - tz->trips.passive.tsp*100, + tz->passive.tsp*100, tz->polling_frequency*100); else tz->thermal_zone =3D @@ -986,8 +989,8 @@ static int acpi_thermal_get_info(struct acpi_thermal *t= z) */ static void acpi_thermal_guess_offset(struct acpi_thermal *tz) { - if (tz->trips.critical.flags.valid && - (tz->trips.critical.temperature % 5) =3D=3D 1) + if (tz->critical.flags.valid && + (tz->critical.temperature % 5) =3D=3D 1) tz->kelvin_offset =3D 273100; else tz->kelvin_offset =3D 273200; @@ -1097,19 +1100,19 @@ static int acpi_thermal_resume(struct device *dev) return -EINVAL; =20 for (i =3D 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - if (!tz->trips.active[i].flags.valid) + if (!tz->active[i].flags.valid) break; - tz->trips.active[i].flags.enabled =3D 1; - for (j =3D 0; j < tz->trips.active[i].devices.count; j++) { + tz->active[i].flags.enabled =3D 1; + for (j =3D 0; j < tz->active[i].devices.count; j++) { result =3D acpi_bus_update_power( - tz->trips.active[i].devices.handles[j], + tz->active[i].devices.handles[j], &power_state); if (result || (power_state !=3D ACPI_STATE_D0)) { - tz->trips.active[i].flags.enabled =3D 0; + tz->active[i].flags.enabled =3D 0; break; } } - tz->state.active |=3D tz->trips.active[i].flags.enabled; + tz->state.active |=3D tz->active[i].flags.enabled; } =20 acpi_queue_thermal_check(tz); --=20 2.34.1 From nobody Mon Apr 6 18:06:12 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4CE50C43217 for ; Tue, 4 Oct 2022 17:27:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229904AbiJDR13 (ORCPT ); Tue, 4 Oct 2022 13:27:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43370 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229716AbiJDR1Q (ORCPT ); Tue, 4 Oct 2022 13:27:16 -0400 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 256BF5F7ED for ; Tue, 4 Oct 2022 10:27:11 -0700 (PDT) Received: by mail-wm1-x32b.google.com with SMTP id i83-20020a1c3b56000000b003bd44dc526fso1215299wma.3 for ; Tue, 04 Oct 2022 10:27:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=aN4DlCPGos4eyvhsW5aRQQoXE+IjMULxnKXbP9xGXDQ=; b=MdmC3bD5Oh/cdnenOJ4NEb7GbyqpiNsMH7lGhHBrJLpw1yx3byvR93U+jh5z5iOGlD b75aU6vU6F+rMmSPGydOKObwpCVCDvk4V3cXM3dkSMsMwN+9IOC1PUKvngNyj3VyNUpz mbogigJ/uimDvPP1hrK0nKkB3d6L0saIiCbnyboPbICRqVt0z8Tj2Je3BJh7fGnuLMox EH0m4+fuYDfz1MxQD8ycqeuWcAWwC/J2d+GXy0+rbaxPbfmUTBOzdZc5VTK81+scNSv/ ctRFKpPCJtg/dRvu5uyCmIjXoqBpFVPiYdnrrPaeUIQ8vzlpFgr1SQhqJFzXEFr2pUWz JM+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=aN4DlCPGos4eyvhsW5aRQQoXE+IjMULxnKXbP9xGXDQ=; b=u8c59wG834e0B83WDcMUAAG4JCV6kqGzkf2bG2Po/HACd+PRfU2PNW/tBKN4nSK9ax PyCealtwivwcO4nUh/xnHt6dhTnmV0WaRz69SodF5rqzDOW9beGWJprFGpJDh9+Eoi43 UoXywm0fBmmW/5a/AgZ3sLSvYvdJhVnQwAfJQhFAOoYB1y8fGrq8Xf1fVLgF10CVkDpa hiZqX15zxRpQsO2pEltg2v5GIUS85jILnNX07OV3Lgio6YdNmVfrA2p1y+gifViYione XPLWzSQlZMjRGl4ICJMkTIiU6Cg1iFQidWvd9OXWmxUH23CQZfPO7JFfnfK3E2OhT58Z e2og== X-Gm-Message-State: ACrzQf1Z44+rzTOZE7Zn1EMEEQpUdnqikUAtWkb4gdpbfjNA/GiFRAQa 495Sl31F5Yc6Zwv+ccSCnDx+vQ== X-Google-Smtp-Source: AMsMyM4fewkyF1YEUvyBECAFoXHpF17NNPpniY1oejie64eK+YzJln4WINw1gXXB15BLecFQmz7z5A== X-Received: by 2002:a05:600c:1d2a:b0:3b4:6e31:92da with SMTP id l42-20020a05600c1d2a00b003b46e3192damr559571wms.103.1664904429185; Tue, 04 Oct 2022 10:27:09 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:c456:8337:99aa:2667]) by smtp.gmail.com with ESMTPSA id l19-20020a5d5273000000b00228dbf15072sm13060941wrc.62.2022.10.04.10.27.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 10:27:08 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Rui , Len Brown Subject: [PATCH RFC 2/9] thermal/acpi: Change to a common acpi_thermal_trip structure Date: Tue, 4 Oct 2022 19:26:51 +0200 Message-Id: <20221004172658.2302511-3-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004172658.2302511-1-daniel.lezcano@linaro.org> References: <12068304.O9o76ZdvQC@kreacher> <20221004172658.2302511-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Do not differentiate hot, critical, passive and active trip points. Use a single acpi_thermal_trip structure. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 35 ++++++----------------------------- 1 file changed, 6 insertions(+), 29 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index b2e73e45c6d6..9620128f05d2 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -119,36 +119,13 @@ struct acpi_thermal_state_flags { u8 reserved:6; }; =20 -struct acpi_thermal_critical { - struct acpi_thermal_state_flags flags; - unsigned long temperature; -}; - -struct acpi_thermal_hot { - struct acpi_thermal_state_flags flags; - unsigned long temperature; -}; - -struct acpi_thermal_passive { +struct acpi_thermal_trip { struct acpi_thermal_state_flags flags; + struct acpi_handle_list devices; unsigned long temperature; unsigned long tc1; unsigned long tc2; unsigned long tsp; - struct acpi_handle_list devices; -}; - -struct acpi_thermal_active { - struct acpi_thermal_state_flags flags; - unsigned long temperature; - struct acpi_handle_list devices; -}; - -struct acpi_thermal_trips { - struct acpi_thermal_critical critical; - struct acpi_thermal_hot hot; - struct acpi_thermal_passive passive; - struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE]; }; =20 struct acpi_thermal_flags { @@ -166,10 +143,10 @@ struct acpi_thermal { volatile u8 zombie; struct acpi_thermal_flags flags; struct acpi_thermal_state state; - struct acpi_thermal_critical critical; - struct acpi_thermal_hot hot; - struct acpi_thermal_passive passive; - struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE]; + struct acpi_thermal_trip critical; + struct acpi_thermal_trip hot; + struct acpi_thermal_trip passive; + struct acpi_thermal_trip active[ACPI_THERMAL_MAX_ACTIVE]; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; int kelvin_offset; /* in millidegrees */ --=20 2.34.1 From nobody Mon Apr 6 18:06:12 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 65A31C433F5 for ; Tue, 4 Oct 2022 17:27:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229726AbiJDR1f (ORCPT ); Tue, 4 Oct 2022 13:27:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43224 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229661AbiJDR1S (ORCPT ); Tue, 4 Oct 2022 13:27:18 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38218642C0 for ; Tue, 4 Oct 2022 10:27:12 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id b7so14769986wrq.9 for ; Tue, 04 Oct 2022 10:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=XO25AA5MH7o6mmP/ulciu6/M0rMSBo6p6lETw4mAlpw=; b=EYd8ISRDRP3m6H0QOJ3lqAOf+GTcDb53IVGkGXxakLLhtte45Jaf3vQy8+MXsceTxF JTeuRMTQ+OcHFTsvGpBar0nVFWi2w9MihV+26iK501AxsjoE32lZzYhiA54dUm1DKkDV GxXphFuSaBNlBw1RpglSx4fOnvOUOZxUVJo+ViHt++gT5FkWM+oRtJwMjDddr6vQEXJ5 RXsiDdAXcHQtm/BNZaasg9Wy4JbvzqxiNueGl30YezOl/CoNfb1/2lhWluzejdeF0gpo JKcGvzggpMhYPwSq+VWpmgdM2UArR8FfXLo3l4yWPjgD43w6XOTOlNsv/e07WD0OzFdb WqkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=XO25AA5MH7o6mmP/ulciu6/M0rMSBo6p6lETw4mAlpw=; b=vUwCJAvCYr+AEE+xoLpqMniMbWGiELWzSKH9I0KnehCVhTwWTgT9kbV16+gB+Ao6wO P5AvE4BPUWvUe5XHrktl/axZuOK2awKg6JM4AIVds9pJTywmX6URE2ciwABgFcbg/sGR BnBc2EOCLOVQyHM16C6BzixkNmo5RMyEiZDLu/JtMN/o4GMvZJhDIEr8TTR6E1ojWCyk 7H9xQB6VOPGBDWAYHU4i9WCBuZwRWKEwrpktArQ4M5LCiIQdWnpPyvAK6cc+aRlJ4Y+M TNX69WwRKACZQUBk4AJlX7C4/RxNX90oawhuvAjSDxPQcgMP/5JsvveP2PolKK/cMCku ARMA== X-Gm-Message-State: ACrzQf1DiSYrMTHp/vffBA/ktBnB2463USQZAjl5XOVTgpttKgpDpV3l Eq2vSBo4Sf5RkKs5xR7p7+lB0Q== X-Google-Smtp-Source: AMsMyM7TdOf06JeB9+3SJ05CnANDstNHT8p3fNmJYTRBtajZuQEhDlRBVfxebl+FQkKKeFHEeXe3jA== X-Received: by 2002:a05:6000:18ab:b0:22e:39f1:861a with SMTP id b11-20020a05600018ab00b0022e39f1861amr7260752wri.129.1664904430642; Tue, 04 Oct 2022 10:27:10 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:c456:8337:99aa:2667]) by smtp.gmail.com with ESMTPSA id l19-20020a5d5273000000b00228dbf15072sm13060941wrc.62.2022.10.04.10.27.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 10:27:10 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Rui , Len Brown Subject: [PATCH RFC 3/9] thermal/acpi: Convert the acpi thermal trips to an array Date: Tue, 4 Oct 2022 19:26:52 +0200 Message-Id: <20221004172658.2302511-4-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004172658.2302511-1-daniel.lezcano@linaro.org> References: <12068304.O9o76ZdvQC@kreacher> <20221004172658.2302511-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Instead of having multiple trip points in the structure fields for each trip type, let's create an array of trip points. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 131 ++++++++++++++++++++++------------------- 1 file changed, 69 insertions(+), 62 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 9620128f05d2..8bf2b25acdf1 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -104,6 +104,15 @@ static struct acpi_driver acpi_thermal_driver =3D { .drv.pm =3D &acpi_thermal_pm, }; =20 +enum { + ACPI_THERMAL_TRIP_CRITICAL, + ACPI_THERMAL_TRIP_HOT, + ACPI_THERMAL_TRIP_PASSIVE, + ACPI_THERMAL_TRIP_ACTIVE +}; + +#define ACPI_THERMAL_TRIP_MAX (ACPI_THERMAL_TRIP_ACTIVE + ACPI_THERMAL_MAX= _ACTIVE) + struct acpi_thermal_state { u8 critical:1; u8 hot:1; @@ -143,9 +152,7 @@ struct acpi_thermal { volatile u8 zombie; struct acpi_thermal_flags flags; struct acpi_thermal_state state; - struct acpi_thermal_trip critical; - struct acpi_thermal_trip hot; - struct acpi_thermal_trip passive; + struct acpi_thermal_trip trips[ACPI_THERMAL_TRIP_MAX]; struct acpi_thermal_trip active[ACPI_THERMAL_MAX_ACTIVE]; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; @@ -252,7 +259,7 @@ static int acpi_thermal_trips_update(struct acpi_therma= l *tz, int flag) if (flag & ACPI_TRIPS_CRITICAL) { status =3D acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp); - tz->critical.temperature =3D tmp; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature =3D tmp; /* * Treat freezing temperatures as invalid as well; some * BIOSes return really low values and cause reboots at startup. @@ -260,32 +267,32 @@ static int acpi_thermal_trips_update(struct acpi_ther= mal *tz, int flag) * ... so lets discard those as invalid. */ if (ACPI_FAILURE(status)) { - tz->critical.flags.valid =3D 0; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid =3D 0; acpi_handle_debug(tz->device->handle, "No critical threshold\n"); } else if (tmp <=3D 2732) { pr_info(FW_BUG "Invalid critical threshold (%llu)\n", tmp); - tz->critical.flags.valid =3D 0; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid =3D 0; } else { - tz->critical.flags.valid =3D 1; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid =3D 1; acpi_handle_debug(tz->device->handle, "Found critical threshold [%lu]\n", - tz->critical.temperature); + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature); } - if (tz->critical.flags.valid =3D=3D 1) { + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid =3D=3D 1) { if (crt =3D=3D -1) { - tz->critical.flags.valid =3D 0; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid =3D 0; } else if (crt > 0) { unsigned long crt_k =3D celsius_to_deci_kelvin(crt); =20 /* * Allow override critical threshold */ - if (crt_k > tz->critical.temperature) + if (crt_k > tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature) pr_info("Critical threshold %d C\n", crt); =20 - tz->critical.temperature =3D crt_k; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature =3D crt_k; } } } @@ -295,22 +302,22 @@ static int acpi_thermal_trips_update(struct acpi_ther= mal *tz, int flag) status =3D acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp); if (ACPI_FAILURE(status)) { - tz->hot.flags.valid =3D 0; + tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid =3D 0; acpi_handle_debug(tz->device->handle, "No hot threshold\n"); } else { - tz->hot.temperature =3D tmp; - tz->hot.flags.valid =3D 1; + tz->trips[ACPI_THERMAL_TRIP_HOT].temperature =3D tmp; + tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid =3D 1; acpi_handle_debug(tz->device->handle, "Found hot threshold [%lu]\n", - tz->hot.temperature); + tz->trips[ACPI_THERMAL_TRIP_HOT].temperature); } } =20 /* Passive (optional) */ - if (((flag & ACPI_TRIPS_PASSIVE) && tz->passive.flags.valid) || + if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips[ACPI_THERMAL_TRIP_PASSIVE].= flags.valid) || (flag =3D=3D ACPI_TRIPS_INIT)) { - valid =3D tz->passive.flags.valid; + valid =3D tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; if (psv =3D=3D -1) { status =3D AE_SUPPORT; } else if (psv > 0) { @@ -322,56 +329,56 @@ static int acpi_thermal_trips_update(struct acpi_ther= mal *tz, int flag) } =20 if (ACPI_FAILURE(status)) - tz->passive.flags.valid =3D 0; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid =3D 0; else { - tz->passive.temperature =3D tmp; - tz->passive.flags.valid =3D 1; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].temperature =3D tmp; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid =3D 1; if (flag =3D=3D ACPI_TRIPS_INIT) { status =3D acpi_evaluate_integer( tz->device->handle, "_TC1", NULL, &tmp); if (ACPI_FAILURE(status)) - tz->passive.flags.valid =3D 0; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid =3D 0; else - tz->passive.tc1 =3D tmp; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc1 =3D tmp; status =3D acpi_evaluate_integer( tz->device->handle, "_TC2", NULL, &tmp); if (ACPI_FAILURE(status)) - tz->passive.flags.valid =3D 0; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid =3D 0; else - tz->passive.tc2 =3D tmp; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc2 =3D tmp; status =3D acpi_evaluate_integer( tz->device->handle, "_TSP", NULL, &tmp); if (ACPI_FAILURE(status)) - tz->passive.flags.valid =3D 0; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid =3D 0; else - tz->passive.tsp =3D tmp; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tsp =3D tmp; } } } - if ((flag & ACPI_TRIPS_DEVICES) && tz->passive.flags.valid) { + if ((flag & ACPI_TRIPS_DEVICES) && tz->trips[ACPI_THERMAL_TRIP_PASSIVE].f= lags.valid) { memset(&devices, 0, sizeof(struct acpi_handle_list)); status =3D acpi_evaluate_reference(tz->device->handle, "_PSL", NULL, &devices); if (ACPI_FAILURE(status)) { acpi_handle_info(tz->device->handle, "Invalid passive threshold\n"); - tz->passive.flags.valid =3D 0; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid =3D 0; } else - tz->passive.flags.valid =3D 1; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid =3D 1; =20 - if (memcmp(&tz->passive.devices, &devices, + if (memcmp(&tz->trips[ACPI_THERMAL_TRIP_PASSIVE].devices, &devices, sizeof(struct acpi_handle_list))) { - memcpy(&tz->passive.devices, &devices, + memcpy(&tz->trips[ACPI_THERMAL_TRIP_PASSIVE].devices, &devices, sizeof(struct acpi_handle_list)); ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); } } if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) { - if (valid !=3D tz->passive.flags.valid) + if (valid !=3D tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); } =20 @@ -462,9 +469,9 @@ static int acpi_thermal_get_trip_points(struct acpi_the= rmal *tz) if (ret) return ret; =20 - valid =3D tz->critical.flags.valid | - tz->hot.flags.valid | - tz->passive.flags.valid; + valid =3D tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid | + tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid | + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; =20 for (i =3D 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) valid |=3D tz->active[i].flags.valid; @@ -504,7 +511,7 @@ static int thermal_get_trip_type(struct thermal_zone_de= vice *thermal, if (!tz || trip < 0) return -EINVAL; =20 - if (tz->critical.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) { if (!trip) { *type =3D THERMAL_TRIP_CRITICAL; return 0; @@ -512,7 +519,7 @@ static int thermal_get_trip_type(struct thermal_zone_de= vice *thermal, trip--; } =20 - if (tz->hot.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid) { if (!trip) { *type =3D THERMAL_TRIP_HOT; return 0; @@ -520,7 +527,7 @@ static int thermal_get_trip_type(struct thermal_zone_de= vice *thermal, trip--; } =20 - if (tz->passive.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) { if (!trip) { *type =3D THERMAL_TRIP_PASSIVE; return 0; @@ -549,30 +556,30 @@ static int thermal_get_trip_temp(struct thermal_zone_= device *thermal, if (!tz || trip < 0) return -EINVAL; =20 - if (tz->critical.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) { if (!trip) { *temp =3D deci_kelvin_to_millicelsius_with_offset( - tz->critical.temperature, + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature, tz->kelvin_offset); return 0; } trip--; } =20 - if (tz->hot.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid) { if (!trip) { *temp =3D deci_kelvin_to_millicelsius_with_offset( - tz->hot.temperature, + tz->trips[ACPI_THERMAL_TRIP_HOT].temperature, tz->kelvin_offset); return 0; } trip--; } =20 - if (tz->passive.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) { if (!trip) { *temp =3D deci_kelvin_to_millicelsius_with_offset( - tz->passive.temperature, + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].temperature, tz->kelvin_offset); return 0; } @@ -598,9 +605,9 @@ static int thermal_get_crit_temp(struct thermal_zone_de= vice *thermal, { struct acpi_thermal *tz =3D thermal->devdata; =20 - if (tz->critical.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) { *temperature =3D deci_kelvin_to_millicelsius_with_offset( - tz->critical.temperature, + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature, tz->kelvin_offset); return 0; } else @@ -637,9 +644,9 @@ static int thermal_get_trend(struct thermal_zone_device= *thermal, * tz->temperature has already been updated by generic thermal layer, * before this callback being invoked */ - i =3D (tz->passive.tc1 * (tz->temperature - tz->last_temperature)) - + (tz->passive.tc2 - * (tz->temperature - tz->passive.temperature)); + i =3D (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc1 * (tz->temperature - tz->= last_temperature)) + + (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc2 + * (tz->temperature - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].temperature)); =20 if (i > 0) *trend =3D THERMAL_TREND_RAISING; @@ -683,17 +690,17 @@ static int acpi_thermal_cooling_device_cb(struct ther= mal_zone_device *thermal, int trip =3D -1; int result =3D 0; =20 - if (tz->critical.flags.valid) + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) trip++; =20 - if (tz->hot.flags.valid) + if (tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid) trip++; =20 - if (tz->passive.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) { trip++; - for (i =3D 0; i < tz->passive.devices.count; + for (i =3D 0; i < tz->trips[ACPI_THERMAL_TRIP_PASSIVE].devices.count; i++) { - handle =3D tz->passive.devices.handles[i]; + handle =3D tz->trips[ACPI_THERMAL_TRIP_PASSIVE].devices.handles[i]; dev =3D acpi_fetch_acpi_dev(handle); if (dev !=3D device) continue; @@ -773,23 +780,23 @@ static int acpi_thermal_register_thermal_zone(struct = acpi_thermal *tz) acpi_status status; int i; =20 - if (tz->critical.flags.valid) + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) trips++; =20 - if (tz->hot.flags.valid) + if (tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid) trips++; =20 - if (tz->passive.flags.valid) + if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) trips++; =20 for (i =3D 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->active[i].flags.valid; i++, trips++); =20 - if (tz->passive.flags.valid) + if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) tz->thermal_zone =3D thermal_zone_device_register("acpitz", trips, 0, tz, &acpi_thermal_zone_ops, NULL, - tz->passive.tsp*100, + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tsp*100, tz->polling_frequency*100); else tz->thermal_zone =3D @@ -966,8 +973,8 @@ static int acpi_thermal_get_info(struct acpi_thermal *t= z) */ static void acpi_thermal_guess_offset(struct acpi_thermal *tz) { - if (tz->critical.flags.valid && - (tz->critical.temperature % 5) =3D=3D 1) + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid && + (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature % 5) =3D=3D 1) tz->kelvin_offset =3D 273100; else tz->kelvin_offset =3D 273200; --=20 2.34.1 From nobody Mon Apr 6 18:06:12 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2F17CC433FE for ; Tue, 4 Oct 2022 17:27:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229881AbiJDR1k (ORCPT ); Tue, 4 Oct 2022 13:27:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229763AbiJDR1S (ORCPT ); Tue, 4 Oct 2022 13:27:18 -0400 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51DBD6555A for ; Tue, 4 Oct 2022 10:27:14 -0700 (PDT) Received: by mail-wm1-x32d.google.com with SMTP id v130-20020a1cac88000000b003bcde03bd44so607945wme.5 for ; Tue, 04 Oct 2022 10:27:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ruxSNDrAyIsZW86sIahAkKmDpVpE5j1H1T3C5bdYovs=; b=qT6Sc8H6U7PqP88ISMx9JRsYeDCfwmeX8XWzBqw95Zrw1oRDxbv2ZYcI9VAHdjwAB2 pz5kjGKiYP9t4Yr3k+48GNB8t8PzobVT3ivtR840ofya6AZrG/4gmlkEuOj9wa16Jq20 wFmzLe7iNFlxJLBDtGGzPXDqA4tk2jajpOYzizM68o1NlkZj6RivqqxNMIbX09vTGLxN vVlLa8wm/Ury9rWdCoarZ2aPoRntQwlzaFfH5z8whVoojLmuuwUi5kOWKZiirw7pO3fi oyi/oBrgMElJBlDuzedb60Iyuqf+K57GZsK7sv4bx12ik9RJY2hD8xtoue9Sbrd+rcFP CCNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ruxSNDrAyIsZW86sIahAkKmDpVpE5j1H1T3C5bdYovs=; b=ZAigLBRHJZPze87OoMce2f3aTaCBsnyghAHhDukjFLe3TtlJyIh5EyEiJ+UOSNIb7N QU0KuBDE/Wh12tI9iA6UrvYcYkN+SCMBEeEciBxaCFadR+zc1YH3K2XnvIHa5fpaGj7a JUOmpTtkJI5/Kkykw5M3L1y93+PB7F6+Vdc4nrtGXxSrxGWUqxvnBQDUBG52UxwTT9c2 i437j/U1AnC5Ux5atTEy+XbvXsmr7x3GtCWkX9mRva3bfMFmqDaivykKDyfI67MGyoVG TmgBc8Zqj4ndfjtONvEoVDZrWKvvlPP8e+lqgzklJUp8XdBR2l12VogGHhzxKoRzFjqu MICA== X-Gm-Message-State: ACrzQf0LEEiRV428jV4+meQV1wyfQK2em4378sZmv4K4onHCyg8vjvY1 o0sVgJ5KfiUcf+CvuSzjyRyyk2Ug9EJVeA== X-Google-Smtp-Source: AMsMyM6XiJfl/UzOMKRZDskQDdM+15btP26qbCA/h4X62O/v3STY2X5zlfvron0IxxKvFOluIQLvVg== X-Received: by 2002:a1c:cc0e:0:b0:3b4:fda3:c808 with SMTP id h14-20020a1ccc0e000000b003b4fda3c808mr573627wmb.146.1664904432111; Tue, 04 Oct 2022 10:27:12 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:c456:8337:99aa:2667]) by smtp.gmail.com with ESMTPSA id l19-20020a5d5273000000b00228dbf15072sm13060941wrc.62.2022.10.04.10.27.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 10:27:11 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Rui , Len Brown Subject: [PATCH RFC 4/9] thermal/acpi: Move the active trip points to the same array Date: Tue, 4 Oct 2022 19:26:53 +0200 Message-Id: <20221004172658.2302511-5-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004172658.2302511-1-daniel.lezcano@linaro.org> References: <12068304.O9o76ZdvQC@kreacher> <20221004172658.2302511-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" This change does the second pass to move the active trip points in the thermal trip array. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 75 +++++++++++++++++++++--------------------- 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 8bf2b25acdf1..ce37494bd133 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -153,7 +153,6 @@ struct acpi_thermal { struct acpi_thermal_flags flags; struct acpi_thermal_state state; struct acpi_thermal_trip trips[ACPI_THERMAL_TRIP_MAX]; - struct acpi_thermal_trip active[ACPI_THERMAL_MAX_ACTIVE]; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; int kelvin_offset; /* in millidegrees */ @@ -383,68 +382,68 @@ static int acpi_thermal_trips_update(struct acpi_ther= mal *tz, int flag) } =20 /* Active (optional) */ - for (i =3D 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + for (i =3D ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { char name[5] =3D { '_', 'A', 'C', ('0' + i), '\0' }; - valid =3D tz->active[i].flags.valid; + valid =3D tz->trips[i].flags.valid; =20 if (act =3D=3D -1) break; /* disable all active trip points */ =20 if ((flag =3D=3D ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) && - tz->active[i].flags.valid)) { + tz->trips[i].flags.valid)) { status =3D acpi_evaluate_integer(tz->device->handle, name, NULL, &tmp); if (ACPI_FAILURE(status)) { - tz->active[i].flags.valid =3D 0; + tz->trips[i].flags.valid =3D 0; if (i =3D=3D 0) break; if (act <=3D 0) break; if (i =3D=3D 1) - tz->active[0].temperature =3D + tz->trips[0].temperature =3D celsius_to_deci_kelvin(act); else /* * Don't allow override higher than * the next higher trip point */ - tz->active[i - 1].temperature =3D - (tz->active[i - 2].temperature < + tz->trips[i - 1].temperature =3D + (tz->trips[i - 2].temperature < celsius_to_deci_kelvin(act) ? - tz->active[i - 2].temperature : + tz->trips[i - 2].temperature : celsius_to_deci_kelvin(act)); break; } else { - tz->active[i].temperature =3D tmp; - tz->active[i].flags.valid =3D 1; + tz->trips[i].temperature =3D tmp; + tz->trips[i].flags.valid =3D 1; } } =20 name[2] =3D 'L'; - if ((flag & ACPI_TRIPS_DEVICES) && tz->active[i].flags.valid ) { + if ((flag & ACPI_TRIPS_DEVICES) && tz->trips[i].flags.valid ) { memset(&devices, 0, sizeof(struct acpi_handle_list)); status =3D 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->active[i].flags.valid =3D 0; + tz->trips[i].flags.valid =3D 0; } else - tz->active[i].flags.valid =3D 1; + tz->trips[i].flags.valid =3D 1; =20 - if (memcmp(&tz->active[i].devices, &devices, + if (memcmp(&tz->trips[i].devices, &devices, sizeof(struct acpi_handle_list))) { - memcpy(&tz->active[i].devices, &devices, + memcpy(&tz->trips[i].devices, &devices, sizeof(struct acpi_handle_list)); ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); } } if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES)) - if (valid !=3D tz->active[i].flags.valid) + if (valid !=3D tz->trips[i].flags.valid) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); =20 - if (!tz->active[i].flags.valid) + if (!tz->trips[i].flags.valid) break; } =20 @@ -473,8 +472,8 @@ static int acpi_thermal_get_trip_points(struct acpi_the= rmal *tz) tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid | tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; =20 - for (i =3D 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) - valid |=3D tz->active[i].flags.valid; + for (i =3D ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) + valid |=3D tz->trips[i].flags.valid; =20 if (!valid) { pr_warn(FW_BUG "No valid trip found\n"); @@ -535,8 +534,8 @@ static int thermal_get_trip_type(struct thermal_zone_de= vice *thermal, trip--; } =20 - for (i =3D 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->active[i].flags.valid; i++) { + for (i =3D ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE && + tz->trips[i].flags.valid; i++) { if (!trip) { *type =3D THERMAL_TRIP_ACTIVE; return 0; @@ -586,11 +585,11 @@ static int thermal_get_trip_temp(struct thermal_zone_= device *thermal, trip--; } =20 - for (i =3D 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->active[i].flags.valid; i++) { + for (i =3D ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE && + tz->trips[i].flags.valid; i++) { if (!trip) { *temp =3D deci_kelvin_to_millicelsius_with_offset( - tz->active[i].temperature, + tz->trips[i].temperature, tz->kelvin_offset); return 0; } @@ -719,14 +718,14 @@ static int acpi_thermal_cooling_device_cb(struct ther= mal_zone_device *thermal, } } =20 - for (i =3D 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - if (!tz->active[i].flags.valid) + for (i =3D ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + if (!tz->trips[i].flags.valid) break; trip++; for (j =3D 0; - j < tz->active[i].devices.count; + j < tz->trips[i].devices.count; j++) { - handle =3D tz->active[i].devices.handles[j]; + handle =3D tz->trips[i].devices.handles[j]; dev =3D acpi_fetch_acpi_dev(handle); if (dev !=3D device) continue; @@ -789,8 +788,8 @@ static int acpi_thermal_register_thermal_zone(struct ac= pi_thermal *tz) if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) trips++; =20 - for (i =3D 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->active[i].flags.valid; i++, trips++); + for (i =3D ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE && + tz->trips[i].flags.valid; i++, trips++); =20 if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) tz->thermal_zone =3D @@ -1083,20 +1082,20 @@ static int acpi_thermal_resume(struct device *dev) if (!tz) return -EINVAL; =20 - for (i =3D 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - if (!tz->active[i].flags.valid) + for (i =3D ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + if (!tz->trips[i].flags.valid) break; - tz->active[i].flags.enabled =3D 1; - for (j =3D 0; j < tz->active[i].devices.count; j++) { + tz->trips[i].flags.enabled =3D 1; + for (j =3D 0; j < tz->trips[i].devices.count; j++) { result =3D acpi_bus_update_power( - tz->active[i].devices.handles[j], + tz->trips[i].devices.handles[j], &power_state); if (result || (power_state !=3D ACPI_STATE_D0)) { - tz->active[i].flags.enabled =3D 0; + tz->trips[i].flags.enabled =3D 0; break; } } - tz->state.active |=3D tz->active[i].flags.enabled; + tz->state.active |=3D tz->trips[i].flags.enabled; } =20 acpi_queue_thermal_check(tz); --=20 2.34.1 From nobody Mon Apr 6 18:06:12 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8446CC433F5 for ; Tue, 4 Oct 2022 17:27:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229996AbiJDR1o (ORCPT ); Tue, 4 Oct 2022 13:27:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229695AbiJDR1S (ORCPT ); Tue, 4 Oct 2022 13:27:18 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51E406557E for ; Tue, 4 Oct 2022 10:27:14 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id j7so17021757wrr.3 for ; Tue, 04 Oct 2022 10:27:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ffflrD4DXIWja44hBCEf9IQ+O0RpUhCuc08rXykRjDg=; b=o8wah8z8XT1ziWccJxJ9Cmb/4HGi1U8gEOqZUzPdEc2rv/FmTnpl+gj2oR+bB7R+Ef quao0/x+CfVNyMiuCz15YAezFgCGNsq/caIMXmYbH9b4LAGOGUAWU4VnagwUqsS0Xu/5 G+ioBlERSqNGsUSKVxkK3zyMaeTc0V+04Cq7QBC4s1r3uzf4rp9KSMq2PIJeL+3NS9Ax JSPW/EYHn6ERHfnr82Uzul0XpwAog3wGvvSzIldTaPnXXkLj0hNgL62Ft6YvPxT/umyD BMoO9V0TSlEilv2Q+4QuH4uX8U3Mwc+kBrJOr+tmwDFuFEGLQ9XAR5QGMPS5VcmC6a1e dTmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ffflrD4DXIWja44hBCEf9IQ+O0RpUhCuc08rXykRjDg=; b=TdiRqaHfroAwX7AFZptOLVK6CHaLBAtHyM7S3OGHiGriCA7brdzK9sUijfNv1+CR6P IEw+2ZBwf2rBrMlXVcqA6zH2XT1lWGmYmHa5XgLQu/9cBHUNIOJMlmuYKS/x73Eip7x1 YXid4wFc3/c2EHawu8A9q0bW+clOZXtJs4v01ZFv13pCAWtmB87rUJGwo98Cn7KyTJr3 8C89C2jV7HCFIQqEL0KUxVZ9nLPGCc41z6WjvafJwuLjJG8RVrOV3rLUB7g0D/vlqnqw 1eEkZK7jM6dYudzr5O9BEmPusNUNAzZI2b7VQ5FmjKlIpwRX1CeKUQ/SlQsRn1y6ZHYW IQCA== X-Gm-Message-State: ACrzQf3c+4EZ02xyEj9urjbz4QWby2iLswHGqadmB0FIuS+WtK+FAjqf VuxAj+249v+HmK479ceqizCGVw== X-Google-Smtp-Source: AMsMyM5NjECWapjJ7d70XwY9SIHtxnFliyPngXpj7L5b8H234DSD5P7SSw1R2URsRMaDYoK8HMsksw== X-Received: by 2002:a05:6000:1a8f:b0:228:e3c3:679 with SMTP id f15-20020a0560001a8f00b00228e3c30679mr16757847wry.281.1664904433625; Tue, 04 Oct 2022 10:27:13 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:c456:8337:99aa:2667]) by smtp.gmail.com with ESMTPSA id l19-20020a5d5273000000b00228dbf15072sm13060941wrc.62.2022.10.04.10.27.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 10:27:13 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Rui , Len Brown Subject: [PATCH RFC 5/9] thermal/acpi: Optimize get_trip_points() Date: Tue, 4 Oct 2022 19:26:54 +0200 Message-Id: <20221004172658.2302511-6-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004172658.2302511-1-daniel.lezcano@linaro.org> References: <12068304.O9o76ZdvQC@kreacher> <20221004172658.2302511-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The function has two purposes. Initialize the trip points by reading the ACPI table and then doing a check trip points exists. This check will go through all the trip points and at the end if a valid trip point is found, the parsing is considered valid. Instead of checking all the trip points, exit when a valid trip point is found. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index ce37494bd133..9841b597a9c7 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -463,23 +463,20 @@ static int acpi_thermal_trips_update(struct acpi_ther= mal *tz, int flag) =20 static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) { - int i, valid, ret =3D acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); + int i, ret; =20 + ret =3D acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); if (ret) return ret; =20 - valid =3D tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid | - tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid | - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; + for (i =3D 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + if (tz->trips[i].flags.valid) + return 0; + } =20 - for (i =3D ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) - valid |=3D tz->trips[i].flags.valid; + pr_warn(FW_BUG "No valid trip found\n"); =20 - if (!valid) { - pr_warn(FW_BUG "No valid trip found\n"); - return -ENODEV; - } - return 0; + return -ENODEV; } =20 /* sys I/F for generic thermal sysfs support */ --=20 2.34.1 From nobody Mon Apr 6 18:06:12 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6EEDBC433F5 for ; Tue, 4 Oct 2022 17:27:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230014AbiJDR1q (ORCPT ); Tue, 4 Oct 2022 13:27:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43612 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229803AbiJDR1T (ORCPT ); Tue, 4 Oct 2022 13:27:19 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 43E0865809 for ; Tue, 4 Oct 2022 10:27:17 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id n35-20020a05600c502300b003b4924c6868so980725wmr.1 for ; Tue, 04 Oct 2022 10:27:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JV78r0khKIiVMoqle2Ji/80JCnIJufCj0psslXCqQ5A=; b=F6wDpcwl5ot3TQcMzPUxRoigjYRXF3M2Y2IAQ2j85gh1vseO7Eo0xFf9d8xlgCQPeK mWfqR/Q/obiFkQmLP90BbfZXT+AafX6xFDCtQqLfL5B2U+H5aotBBpxz79HxjOfWxeee fcPUHhp0xp1yMoHPMQDWF/lelYJBs6ZrslFrk2EowpZ1tHynvx6Qz6IlY1SRwgbwcqAN qWVN48XBdgGbzDwe5MMPXtfBsQRzV2GRQUi+PIgqg5Bd0fNoUjD77GOiHxGXAa2cGZ0n LjlxrLOCc3FmPhY1GdZQ/ZpW2DZKE1r6cbPify6A1QO2iCGCJmegsdXUqxnXh0QPhHik HIQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JV78r0khKIiVMoqle2Ji/80JCnIJufCj0psslXCqQ5A=; b=BmyRbnmWC56eS5entEkaR14uihmzcIi1mEn50w9ncXW6/8iveNQ0nipvJeFAPtE6NV 64oVIqYbrRFSGIuQgHltDWwqzaeTwDp1W+E0plk3ayrz86+3YsPG6AKnNT+UNsKfBNYf /5TMbaQB/8IeKdhqWWhWaInErg8BJdnRIxiLeRkcYYnpwjqVTWCpkzcRb8+VEI89O+MG hcZv+7mjnpTQlTYgYtlBLscduWXCMPKAS8l7Jgby22f6UOxLeODHJYC8sDOFsjQpteSF ae+LsuBv2aS+8CDMreGi9b2SClsyAlNjGsYNQD5T9rO7XbsI9Qpjq/V55RmYqCAKUC2Y 5I8A== X-Gm-Message-State: ACrzQf1ZH5EjN++XBiQEnxAi+X6JzB9oSlbDJ6NeGtLgR/mWaGXz32zi NUxGW98nWkGY2Kf7TZ8tkW8zDPH4kFdbaQ== X-Google-Smtp-Source: AMsMyM4fF1yhBIxAQ1lvjEfocDTVgWjd/SuzwVIm6gIeECdmc+PYKnm1lKeoxZTYCDZHaxMdAXv9kw== X-Received: by 2002:a05:600c:21c7:b0:3bd:ef29:2d08 with SMTP id x7-20020a05600c21c700b003bdef292d08mr563673wmj.177.1664904434840; Tue, 04 Oct 2022 10:27:14 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:c456:8337:99aa:2667]) by smtp.gmail.com with ESMTPSA id l19-20020a5d5273000000b00228dbf15072sm13060941wrc.62.2022.10.04.10.27.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 10:27:14 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Rui , Len Brown Subject: [PATCH RFC 6/9] thermal/acpi: Encapsualte in functions the trip initialization Date: Tue, 4 Oct 2022 19:26:55 +0200 Message-Id: <20221004172658.2302511-7-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004172658.2302511-1-daniel.lezcano@linaro.org> References: <12068304.O9o76ZdvQC@kreacher> <20221004172658.2302511-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The thermal trip update function is a bit difficult to read. In order to improve its readability, let's encapuslate the different parts into dedicated functions. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 267 ++++++++++++++++++++++++----------------- 1 file changed, 159 insertions(+), 108 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 9841b597a9c7..e62381561255 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -246,117 +246,123 @@ do { \ "Please report to linux-acpi@vger.kernel.org\n", str); \ } while (0) =20 -static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) +static int acpi_thermal_trips_update_critical(struct acpi_thermal *tz, int= flag) { acpi_status status =3D AE_OK; unsigned long long tmp; - struct acpi_handle_list devices; - int valid =3D 0; - int i; =20 - /* Critical Shutdown */ - if (flag & ACPI_TRIPS_CRITICAL) { - status =3D acpi_evaluate_integer(tz->device->handle, + status =3D acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp); - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature =3D tmp; - /* - * Treat freezing temperatures as invalid as well; some - * BIOSes return really low values and cause reboots at startup. - * Below zero (Celsius) values clearly aren't right for sure.. - * ... so lets discard those as invalid. - */ - if (ACPI_FAILURE(status)) { - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid =3D 0; - acpi_handle_debug(tz->device->handle, - "No critical threshold\n"); - } else if (tmp <=3D 2732) { - pr_info(FW_BUG "Invalid critical threshold (%llu)\n", - tmp); + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature =3D tmp; + /* + * Treat freezing temperatures as invalid as well; some + * BIOSes return really low values and cause reboots at startup. + * Below zero (Celsius) values clearly aren't right for sure.. + * ... so lets discard those as invalid. + */ + if (ACPI_FAILURE(status)) { + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid =3D 0; + acpi_handle_debug(tz->device->handle, + "No critical threshold\n"); + } else if (tmp <=3D 2732) { + pr_info(FW_BUG "Invalid critical threshold (%llu)\n", + tmp); + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid =3D 0; + } else { + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid =3D 1; + acpi_handle_debug(tz->device->handle, + "Found critical threshold [%lu]\n", + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature); + } + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid =3D=3D 1) { + if (crt =3D=3D -1) { tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid =3D 0; - } else { - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid =3D 1; - acpi_handle_debug(tz->device->handle, - "Found critical threshold [%lu]\n", - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature); - } - if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid =3D=3D 1) { - if (crt =3D=3D -1) { - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid =3D 0; - } else if (crt > 0) { - unsigned long crt_k =3D celsius_to_deci_kelvin(crt); - - /* - * Allow override critical threshold - */ - if (crt_k > tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature) - pr_info("Critical threshold %d C\n", crt); - - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature =3D crt_k; - } + } else if (crt > 0) { + unsigned long crt_k =3D celsius_to_deci_kelvin(crt); + + /* + * Allow override critical threshold + */ + if (crt_k > tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature) + pr_info("Critical threshold %d C\n", crt); + + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature =3D crt_k; } } =20 - /* Critical Sleep (optional) */ - if (flag & ACPI_TRIPS_HOT) { - status =3D acpi_evaluate_integer(tz->device->handle, - "_HOT", NULL, &tmp); - if (ACPI_FAILURE(status)) { - tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid =3D 0; - acpi_handle_debug(tz->device->handle, - "No hot threshold\n"); - } else { - tz->trips[ACPI_THERMAL_TRIP_HOT].temperature =3D tmp; - tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid =3D 1; - acpi_handle_debug(tz->device->handle, - "Found hot threshold [%lu]\n", - tz->trips[ACPI_THERMAL_TRIP_HOT].temperature); - } + return 0; +} + +static int acpi_thermal_trips_update_hot(struct acpi_thermal *tz, int flag) +{ + acpi_status status =3D AE_OK; + unsigned long long tmp; + + status =3D acpi_evaluate_integer(tz->device->handle, + "_HOT", NULL, &tmp); + if (ACPI_FAILURE(status)) { + tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid =3D 0; + acpi_handle_debug(tz->device->handle, + "No hot threshold\n"); + } else { + tz->trips[ACPI_THERMAL_TRIP_HOT].temperature =3D tmp; + tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid =3D 1; + acpi_handle_debug(tz->device->handle, + "Found hot threshold [%lu]\n", + tz->trips[ACPI_THERMAL_TRIP_HOT].temperature); } =20 - /* Passive (optional) */ - if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips[ACPI_THERMAL_TRIP_PASSIVE].= flags.valid) || - (flag =3D=3D ACPI_TRIPS_INIT)) { - valid =3D tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; - if (psv =3D=3D -1) { - status =3D AE_SUPPORT; - } else if (psv > 0) { - tmp =3D celsius_to_deci_kelvin(psv); - status =3D AE_OK; - } else { - status =3D acpi_evaluate_integer(tz->device->handle, - "_PSV", NULL, &tmp); - } + return 0; +} =20 - if (ACPI_FAILURE(status)) - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid =3D 0; - else { - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].temperature =3D tmp; - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid =3D 1; - if (flag =3D=3D ACPI_TRIPS_INIT) { - status =3D acpi_evaluate_integer( - tz->device->handle, "_TC1", - NULL, &tmp); - if (ACPI_FAILURE(status)) - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid =3D 0; - else - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc1 =3D tmp; - status =3D acpi_evaluate_integer( - tz->device->handle, "_TC2", - NULL, &tmp); - if (ACPI_FAILURE(status)) - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid =3D 0; - else - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc2 =3D tmp; - status =3D acpi_evaluate_integer( - tz->device->handle, "_TSP", - NULL, &tmp); - if (ACPI_FAILURE(status)) - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid =3D 0; - else - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tsp =3D tmp; - } +static int acpi_thermal_trips_update_passive(struct acpi_thermal *tz, int = flag) +{ + acpi_status status =3D AE_OK; + unsigned long long tmp; + struct acpi_handle_list devices; + int valid =3D 0; + + valid =3D tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; + if (psv =3D=3D -1) { + status =3D AE_SUPPORT; + } else if (psv > 0) { + tmp =3D celsius_to_deci_kelvin(psv); + status =3D AE_OK; + } else { + status =3D acpi_evaluate_integer(tz->device->handle, + "_PSV", NULL, &tmp); + } + + if (ACPI_FAILURE(status)) + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid =3D 0; + else { + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].temperature =3D tmp; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid =3D 1; + if (flag =3D=3D ACPI_TRIPS_INIT) { + status =3D acpi_evaluate_integer( + tz->device->handle, "_TC1", + NULL, &tmp); + if (ACPI_FAILURE(status)) + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid =3D 0; + else + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc1 =3D tmp; + status =3D acpi_evaluate_integer( + tz->device->handle, "_TC2", + NULL, &tmp); + if (ACPI_FAILURE(status)) + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid =3D 0; + else + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc2 =3D tmp; + status =3D acpi_evaluate_integer( + tz->device->handle, "_TSP", + NULL, &tmp); + if (ACPI_FAILURE(status)) + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid =3D 0; + else + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tsp =3D tmp; } } + if ((flag & ACPI_TRIPS_DEVICES) && tz->trips[ACPI_THERMAL_TRIP_PASSIVE].f= lags.valid) { memset(&devices, 0, sizeof(struct acpi_handle_list)); status =3D acpi_evaluate_reference(tz->device->handle, "_PSL", @@ -376,12 +382,23 @@ static int acpi_thermal_trips_update(struct acpi_ther= mal *tz, int flag) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); } } + if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) { if (valid !=3D tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) - ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); + ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); } =20 - /* Active (optional) */ + return 0; +} + +static int acpi_thermal_trips_update_active(struct acpi_thermal *tz, int f= lag) +{ + acpi_status status =3D AE_OK; + unsigned long long tmp; + struct acpi_handle_list devices; + int valid =3D 0; + int i; + for (i =3D ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { char name[5] =3D { '_', 'A', 'C', ('0' + i), '\0' }; valid =3D tz->trips[i].flags.valid; @@ -447,17 +464,51 @@ static int acpi_thermal_trips_update(struct acpi_ther= mal *tz, int flag) break; } =20 - if (flag & ACPI_TRIPS_DEVICES) { - memset(&devices, 0, sizeof(devices)); - status =3D acpi_evaluate_reference(tz->device->handle, "_TZD", - NULL, &devices); - if (ACPI_SUCCESS(status) - && memcmp(&tz->devices, &devices, sizeof(devices))) { - tz->devices =3D devices; - ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); - } + return 0; +} + +static int acpi_thermal_trips_update_devices(struct acpi_thermal *tz, int = flag) +{ + acpi_status status =3D AE_OK; + struct acpi_handle_list devices; + + memset(&devices, 0, sizeof(devices)); + status =3D acpi_evaluate_reference(tz->device->handle, "_TZD", + NULL, &devices); + if (ACPI_SUCCESS(status) + && memcmp(&tz->devices, &devices, sizeof(devices))) { + tz->devices =3D devices; + ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); + } + + return 0; +} + +static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) +{ + /* Critical Shutdown */ + if (flag & ACPI_TRIPS_CRITICAL) { + acpi_thermal_trips_update_critical(tz, flag); } =20 + /* Critical Sleep (optional) */ + if (flag & ACPI_TRIPS_HOT) { + acpi_thermal_trips_update_hot(tz, flag); + } + + /* Passive (optional) */ + if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips[ACPI_THERMAL_TRIP_PASSIVE].= flags.valid) || + (flag =3D=3D ACPI_TRIPS_INIT)) { + acpi_thermal_trips_update_passive(tz, flag); + } + + /* Active (optional) */ + acpi_thermal_trips_update_active(tz, flag); + + if (flag & ACPI_TRIPS_DEVICES) { + acpi_thermal_trips_update_devices(tz, flag); + } +=09 return 0; } =20 --=20 2.34.1 From nobody Mon Apr 6 18:06:12 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9218BC433FE for ; Tue, 4 Oct 2022 17:27:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230054AbiJDR1v (ORCPT ); Tue, 4 Oct 2022 13:27:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229674AbiJDR1U (ORCPT ); Tue, 4 Oct 2022 13:27:20 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2BAA65811 for ; Tue, 4 Oct 2022 10:27:17 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id b4so15432188wrs.1 for ; Tue, 04 Oct 2022 10:27:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=X/wkXK/VoNshwYJ83FzY4wXHrBNAZHWyNhQmshjdi+0=; b=ULlderE9PrJ6jo1NnPTqYQLkjZBAtWAa2Jgc3YfPEKyMdp8aCVIc75YB7FJ0/e42mk z09bZEWgoFsxxNSNJPl6DBhs6JjholHc616znfP78OR4S7rx745fcGkR7gAFWBNXh/2d h3HFUygS3z7pgEw5JE6zKpNuIKdGK9Gp/P80cExsbxNL5PY1tiL7ut2tlEhcjlgB+4Cw layLN59rADcM4r3rywzo2N9pIW4dCpRAbiBjvuKC6L8Zyst0tThrhyZWzLJp6q8uQx7N BFWm0MFEMSe78zJXJM3zABJjZDRtK7v07rEcxsgYqQptebaKtD9SxxlAuW5lqs6WuPVR yfSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X/wkXK/VoNshwYJ83FzY4wXHrBNAZHWyNhQmshjdi+0=; b=a5Fr7jMBE6bqD1AmKFrKSk6ON5UGXyRa3pNZk+TvLd+47AL/C324pmjubrGdC5lpkZ RN2sBcghIDe44hoW2lc6sl6w8XnTf64KYDw3Dr9KMaiHDzYF/6W9PCAFlF+tPvlMYsNE QWCudM7c+ESDDcj7VyaeTSXxX+FSTf8GZLS/XkTiMTzdsNfemge8z2wU0P5YVBgWue1P Xb9TfK3D4SNSxo6BNeyb140jd2vw/fUiaHtilTBY6AmGDD1I7drN5q9SalyRI5WvE1gH iDEfaC8a2+smlwM1ZvNOuQSORmpq9uUlhN3iegWf9jrrIAPBvF45zgKXwNnUVr7eo2a6 0Z+w== X-Gm-Message-State: ACrzQf3/H7dVWB/6aB6FWIspZ9omg8LoirdxDLYsf8IIX3UXXVSNo+wZ H0JaDM+cey2dh387o6yMEGE83Q== X-Google-Smtp-Source: AMsMyM7Xp8iqAHHWmGPM3+tdztVeDOHDC954tnbDHhlpH4EBnUFR9rfsqtLQlv0GC7PyhdYdnD1n/Q== X-Received: by 2002:a05:6000:1861:b0:22a:bb41:886d with SMTP id d1-20020a056000186100b0022abb41886dmr16757834wri.661.1664904436154; Tue, 04 Oct 2022 10:27:16 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:c456:8337:99aa:2667]) by smtp.gmail.com with ESMTPSA id l19-20020a5d5273000000b00228dbf15072sm13060941wrc.62.2022.10.04.10.27.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 10:27:15 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Rui , Len Brown Subject: [PATCH RFC 7/9] thermal/acpi: Simplifify the condition check Date: Tue, 4 Oct 2022 19:26:56 +0200 Message-Id: <20221004172658.2302511-8-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004172658.2302511-1-daniel.lezcano@linaro.org> References: <12068304.O9o76ZdvQC@kreacher> <20221004172658.2302511-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The condition: if ((flag =3D=3D ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE)) and on the other side: ACPI_TRIPS_INIT (... | ACPI_TRIPS_ACTIVE) So if the first predicate is true, the second is also true. The 'valid' flag for the trip point is also checked before, so it is pointless to redo the same check again and again. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index e62381561255..116e5cf19c5d 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -323,6 +323,9 @@ static int acpi_thermal_trips_update_passive(struct acp= i_thermal *tz, int flag) int valid =3D 0; =20 valid =3D tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; + if (!valid) + return 0; + if (psv =3D=3D -1) { status =3D AE_SUPPORT; } else if (psv > 0) { @@ -401,13 +404,16 @@ static int acpi_thermal_trips_update_active(struct ac= pi_thermal *tz, int flag) =20 for (i =3D ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { char name[5] =3D { '_', 'A', 'C', ('0' + i), '\0' }; + valid =3D tz->trips[i].flags.valid; =20 if (act =3D=3D -1) break; /* disable all active trip points */ =20 - if ((flag =3D=3D ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) && - tz->trips[i].flags.valid)) { + if (!tz->trips[i].flags.valid) + continue; + =09 + if (flag & ACPI_TRIPS_ACTIVE) { status =3D acpi_evaluate_integer(tz->device->handle, name, NULL, &tmp); if (ACPI_FAILURE(status)) { @@ -437,7 +443,7 @@ static int acpi_thermal_trips_update_active(struct acpi= _thermal *tz, int flag) } =20 name[2] =3D 'L'; - if ((flag & ACPI_TRIPS_DEVICES) && tz->trips[i].flags.valid ) { + if (flag & ACPI_TRIPS_DEVICES) { memset(&devices, 0, sizeof(struct acpi_handle_list)); status =3D acpi_evaluate_reference(tz->device->handle, name, NULL, &devices); @@ -456,6 +462,7 @@ static int acpi_thermal_trips_update_active(struct acpi= _thermal *tz, int flag) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); } } + if ((flag & ACPI_TRIPS_ACTIVE) || (flag & ACPI_TRIPS_DEVICES)) if (valid !=3D tz->trips[i].flags.valid) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); @@ -497,8 +504,7 @@ static int acpi_thermal_trips_update(struct acpi_therma= l *tz, int flag) } =20 /* Passive (optional) */ - if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips[ACPI_THERMAL_TRIP_PASSIVE].= flags.valid) || - (flag =3D=3D ACPI_TRIPS_INIT)) { + if (flag & ACPI_TRIPS_PASSIVE) { acpi_thermal_trips_update_passive(tz, flag); } =20 --=20 2.34.1 From nobody Mon Apr 6 18:06:12 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E783C433F5 for ; Tue, 4 Oct 2022 17:28:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229532AbiJDR2F (ORCPT ); Tue, 4 Oct 2022 13:28:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229806AbiJDR1U (ORCPT ); Tue, 4 Oct 2022 13:27:20 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38FFE659CC for ; Tue, 4 Oct 2022 10:27:18 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id j7so17021989wrr.3 for ; Tue, 04 Oct 2022 10:27:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=X3dYKf0qeHKGAU0Mki69uVmAl8R+LfwbHqZ8xsk7ums=; b=dII8QRZ6zhyQT9a2/PchBDxFaBAr8L5XyqNrbjTTidqs+PrVbzughtWLokmMb0b8ME CIgnXABDQqiBBkaLVbIRJiuvM5cNqSmVQz38ATAgqE3rLScurH7PajORNFe3zKp6PB0c UJ2LxGHu1a+T2ddxIcUTu6LfOsg4gnXCywMRwFFKaj3OZhoHEY2YROsghbybs3vTH7bl Af13qD2gR48X2LQIgMvDKLe7AfetnewxOIk7dRRa0TLoHncAuIdUSXCsQRgtX/PyG2Zq HMfSUI1a2k6T2gvYryRRTTPkXDv4UYh+KQj1TYxm0lZJb9zeadypDIY1my424slmLCex QbtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=X3dYKf0qeHKGAU0Mki69uVmAl8R+LfwbHqZ8xsk7ums=; b=a4rvny1kioE393zprAIjXOUTgSM+qQDXcAwNB2r0TG8FTrxfePx/SvkA38G5erRsjf J4WyU+dHKpp3ShGwMoqwo804RhxJzh0/79ZeZD28/sAHIeDtUHY3N8WGbpYr3G2/kdWQ Z/RIKuippkKiECIacuDI9mQ29KCJ6JukMgvLUjgS7K1Kg22atb9WX776lNy59TSvuTkc dYHL1HPHz0X7Agm19zTD2gWiS859PptK1Do8CcCUjp4iTXYKkqMqlp9Fn4tRGzYLqouu URoI2wvW14wkw9ibzCI+xR2Ibk3Lu3rjdmGpHoI3927TEvcT/n+VC3WM9G1jK2ku+c9H 8LqA== X-Gm-Message-State: ACrzQf22y/wqCLuhUiOc1tx1fRE67O4NmcZnmza+kv4o66D3kixtVJgY 6LnWGu9LqjF4UGLxKFjZAjWZ+Q== X-Google-Smtp-Source: AMsMyM4LXI8R1HuZNW+5VD6dycQqURSOfLBrLzAoKRh7h9K6VcQasQv31GKtfIo9sQgarr/piJKXsg== X-Received: by 2002:a5d:4209:0:b0:22c:d5fd:1a06 with SMTP id n9-20020a5d4209000000b0022cd5fd1a06mr15858552wrq.508.1664904437688; Tue, 04 Oct 2022 10:27:17 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:c456:8337:99aa:2667]) by smtp.gmail.com with ESMTPSA id l19-20020a5d5273000000b00228dbf15072sm13060941wrc.62.2022.10.04.10.27.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 10:27:17 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Rui , Len Brown Subject: [PATCH RFC 8/9] thermal/acpi: Remove active and enabled flags Date: Tue, 4 Oct 2022 19:26:57 +0200 Message-Id: <20221004172658.2302511-9-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004172658.2302511-1-daniel.lezcano@linaro.org> References: <12068304.O9o76ZdvQC@kreacher> <20221004172658.2302511-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The 'active' field in the struct acpi_thermal_state is never used. The 'enabled' field of the structure acpi_thermal_state_flags is assigned but never used. Remove them. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 116e5cf19c5d..f530dbfa80db 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -117,14 +117,12 @@ struct acpi_thermal_state { u8 critical:1; u8 hot:1; u8 passive:1; - u8 active:1; u8 reserved:4; int active_index; }; =20 struct acpi_thermal_state_flags { u8 valid:1; - u8 enabled:1; u8 reserved:6; }; =20 @@ -1139,17 +1137,14 @@ static int acpi_thermal_resume(struct device *dev) for (i =3D ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { if (!tz->trips[i].flags.valid) break; - tz->trips[i].flags.enabled =3D 1; + for (j =3D 0; j < tz->trips[i].devices.count; j++) { result =3D acpi_bus_update_power( tz->trips[i].devices.handles[j], &power_state); - if (result || (power_state !=3D ACPI_STATE_D0)) { - tz->trips[i].flags.enabled =3D 0; + if (result || (power_state !=3D ACPI_STATE_D0)) break; - } } - tz->state.active |=3D tz->trips[i].flags.enabled; } =20 acpi_queue_thermal_check(tz); --=20 2.34.1 From nobody Mon Apr 6 18:06:12 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2D190C433FE for ; Tue, 4 Oct 2022 17:28:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230043AbiJDR2M (ORCPT ); Tue, 4 Oct 2022 13:28:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43670 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229748AbiJDR1V (ORCPT ); Tue, 4 Oct 2022 13:27:21 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A26F45E67F for ; Tue, 4 Oct 2022 10:27:19 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id b7so14770508wrq.9 for ; Tue, 04 Oct 2022 10:27:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=uHWVJjYFys4E4VnwcJwmNb2PtDiS0NwkDLnS2KTt1pw=; b=pluwJqgQQFeUu18QT/MQePJPn3oDIyzD7d3xvyWidLpLiqJYr2mv2B7kxxfq4pFNp3 q1iDaVs1NMANu/AENgfAuBgGZjFcXTEa6xK9NWBzn4OFc8b715HSsrSH6Ll0+BLsqjmU 9P7fvpWx7WqegwnAoVCXgjSPAqU1hvQx9Jlxs8AAIxdC/UrHztzHcIyCoYSMxuWnxkyc sx0Z3A6l2mud8VVSuhlSITHntNnxsRj4bwAdbJuthhG6gBeRsCUKrjWbuGiWHegCYs4M Ey9MxqUJi+fVkenpvV1JyTC9kKUJT5IGMGV7sfcd28JipsyjbflWA+WFUIPxliJ1ht/U 7Skg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uHWVJjYFys4E4VnwcJwmNb2PtDiS0NwkDLnS2KTt1pw=; b=78/zQlcYvx61AQCM75+++BE68NrgVGNhXiupreYVNFRR13ic5L/OBSlZMLy2Q7DR1Y g3WPhefJJ2XW+jCHb8y4tch7juqkeLhTsKEtnGPxmFeLEXbfHJrZOSF3BGVb6PD9Id0T JlNw8qKacaqyVudON/ewTe3z858WZ4JnLdZH+mjB/KP66/eMvKJ7Jh4+d92SGOBKRSR/ SA1Jb8CtFszCAmDI9kc0cEyiXFaezRKiWjao8RUp1cDG6g0GyDbQiV83GqlHTKRRCsmF aTIuM/9VLUbcpFNWzreN4t/f9VovYK7igasRTrhjTngr0zMraqSowVFgbxSKoooFATI1 Jtvw== X-Gm-Message-State: ACrzQf1J//bixaCeHF97EZ2e9zPh1Cn6uoIlCP6cCXkLztPcHK+b/RL1 tWtQjoKoBjfVnwAKAY2UL5fqrw== X-Google-Smtp-Source: AMsMyM5UpumukXIoVvrJrUKr894WHOr/KlXAAce/RDZZCESdtJwSKZmswqVXZTJz+gGA8M12fmPDpA== X-Received: by 2002:a05:6000:144f:b0:22a:94f1:25d6 with SMTP id v15-20020a056000144f00b0022a94f125d6mr16343460wrx.422.1664904438890; Tue, 04 Oct 2022 10:27:18 -0700 (PDT) Received: from mai.. ([2a05:6e02:1041:c10:c456:8337:99aa:2667]) by smtp.gmail.com with ESMTPSA id l19-20020a5d5273000000b00228dbf15072sm13060941wrc.62.2022.10.04.10.27.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Oct 2022 10:27:18 -0700 (PDT) From: Daniel Lezcano To: rafael@kernel.org Cc: linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, Zhang Rui , Len Brown Subject: [PATCH RFC 9/9] thermal/acpi: Rewrite the trip point intialization to use the generic thermal trip Date: Tue, 4 Oct 2022 19:26:58 +0200 Message-Id: <20221004172658.2302511-10-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20221004172658.2302511-1-daniel.lezcano@linaro.org> References: <12068304.O9o76ZdvQC@kreacher> <20221004172658.2302511-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" We can use the thermal trip points defined in the thermal.h. Let's initialize them properly and when the code will be moved to the generic thermal structure, we will be able to remove the specific acpi trip points. Still WIP. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 211 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 186 insertions(+), 25 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index f530dbfa80db..994b96807be3 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -244,6 +244,171 @@ do { \ "Please report to linux-acpi@vger.kernel.org\n", str); \ } while (0) =20 +static void acpi_thermal_trips_override_critical(struct thermal_trip *trip, + int temperature) +{ + int ktemp =3D =3D celsius_to_deci_kelvin(temperature); + + if (ktemp > trip->temperature) + pr_info("Overriding %d C\n", temperature); + + trip->temperature =3D ktemp; +} + +static struct thermal_trip *acpi_thermal_trips_alloc_critical(struct acpi_= thermal *tz, + struct thermal_trip *trips, + int *num_trips) +{ + acpi_status status =3D AE_OK; + unsigned long long temp; + + /* + * Module parameters disable the critical trip point + */ + if (crt < 0) + goto out; + + status =3D acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &temp); + if (ACPI_FAILURE(status)) { + acpi_handle_debug(tz->device->handle, "No critical threshold\n"); + goto out; + } + + if (temp <=3D 2732) { + pr_info(FW_BUG "Invalid critical threshold (%llu)\n", temp); + goto out; + } + + trips =3D krealloc(trips, sizeof(*trips) * (*num_trips + 1), GFP_KERNEL); + if (!trips) + goto out; + + memset(&trips[*num_trips], 0, sizeof(*trips)); + + trips[*num_trips].temperature =3D deci_kelvin_to_millicelsius(temp); + trips[*num_trips].type =3D THERMAL_TRIP_CRITICAL; + + if (crt > 0) + acpi_thermal_trips_override_critical(&trips[*num_trips], crt); +=09 + (*num_trips)++; +out: + return trips; +} + +static struct thermal_trip *acpi_thermal_trips_alloc_hot(struct acpi_therm= al *tz, + struct thermal_trip *trips, + int *num_trips) +{ + acpi_status status =3D AE_OK; + unsigned long long temp; + + status =3D acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &temp); + if (ACPI_FAILURE(status)) { + acpi_handle_debug(tz->device->handle, "No hot threshold\n"); + goto out; + } + + trips =3D krealloc(trips, sizeof(*trips) * (*num_trips + 1), GFP_KERNEL); + if (!trips) + goto out; + + memset(&trips[*num_trips], 0, sizeof(*trips)); + + trips[*num_trips].temperature =3D deci_kelvin_to_millicelsius(temp); + trips[*num_trips].type =3D THERMAL_TRIP_HOT; +=09 + (*num_trips)++; +out: + return trips; +} + +static struct thermal_trip *acpi_thermal_trips_alloc_passive(struct acpi_t= hermal *tz, + struct thermal_trip *trips, + int *num_trips) +{ + acpi_status status; + unsigned long long temp; + + /* + * Module parameters disable all passive trip points + */ + if (psv < 0) + goto out; +=09 + status =3D acpi_evaluate_integer(tz->device->handle, "_PSV", NULL, &temp); + if (ACPI_FAILURE(status)) { + acpi_handle_debug(tz->device->handle, "No passive threshold\n"); + goto out; + } + + trips =3D krealloc(trips, sizeof(*trips) * (*num_trips + 1), GFP_KERNEL); + if (!trips) + goto out; + + memset(&trips[*num_trips], 0, sizeof(*trips)); + + trips[*num_trips].temperature =3D deci_kelvin_to_millicelsius(temp); + trips[*num_trips].type =3D THERMAL_TRIP_PASSIVE; +=09 + (*num_trips)++; +out: + return trips; +} + +static struct thermal_trip *acpi_thermal_trips_alloc_active(struct acpi_th= ermal *tz, + struct thermal_trip *trips, + int *num_trips) +{ + acpi_status status; + unsigned long long temp; + int i; + + /* + * Module parameters disable all active trip points + */ + if (act < 0) + return trips; + + for (i =3D ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + char name[5] =3D { '_', 'A', 'C', ('0' + i), '\0' }; + + status =3D acpi_evaluate_integer(tz->device->handle, name, NULL, &temp); + if (ACPI_FAILURE(status)) + break; + + trips =3D krealloc(trips, sizeof(*trips) * (*num_trips + 1), GFP_KERNEL); + if (!trips) + break; + + memset(&trips[*num_trips], 0, sizeof(*trips)); + + trips[*num_trips].temperature =3D deci_kelvin_to_millicelsius(temp); + trips[*num_trips].type =3D THERMAL_TRIP_ACTIVE; +=09 + (*num_trips)++; + } + + return trips; +} + +static struct thermal_trip *acpi_thermal_trips_alloc(struct acpi_thermal *= tz, int *num_trips) +{ + struct thermal_trip *trips =3D NULL; + + *num_trips =3D 0; + + trips =3D acpi_thermal_trips_alloc_critical(tz, trips, num_trips); + + trips =3D acpi_thermal_trips_alloc_hot(tz, trips, num_trips); + + trips =3D acpi_thermal_trips_alloc_passive(tz, trips, num_trips); + + trips =3D acpi_thermal_trips_alloc_active(tz, trips, num_trips); + + return trips; +} + static int acpi_thermal_trips_update_critical(struct acpi_thermal *tz, int= flag) { acpi_status status =3D AE_OK; @@ -824,36 +989,24 @@ static struct thermal_zone_device_ops acpi_thermal_zo= ne_ops =3D { .critical =3D acpi_thermal_zone_device_critical, }; =20 -static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) +static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz, + struct thermal_trip *trips, + int num_trips) { - int trips =3D 0; int result; acpi_status status; - int i; - - if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) - trips++; - - if (tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid) - trips++; - - if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) - trips++; - - for (i =3D ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE && - tz->trips[i].flags.valid; i++, trips++); =20 if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) tz->thermal_zone =3D - thermal_zone_device_register("acpitz", trips, 0, tz, - &acpi_thermal_zone_ops, NULL, - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tsp*100, - tz->polling_frequency*100); + thermal_zone_device_register_with_trips("acpitz", trips, num_trips, 0, = tz, + &acpi_thermal_zone_ops, NULL, + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tsp*100, + tz->polling_frequency*100); else tz->thermal_zone =3D - thermal_zone_device_register("acpitz", trips, 0, tz, - &acpi_thermal_zone_ops, NULL, - 0, tz->polling_frequency*100); + thermal_zone_device_register_with_trips("acpitz", trips, num_trips, 0, = tz, + &acpi_thermal_zone_ops, NULL, + 0, tz->polling_frequency*100); if (IS_ERR(tz->thermal_zone)) return -ENODEV; =20 @@ -1060,7 +1213,8 @@ static int acpi_thermal_add(struct acpi_device *devic= e) { int result =3D 0; struct acpi_thermal *tz =3D NULL; - + struct thermal_trip *trips; + int num_trips; =20 if (!device) return -EINVAL; @@ -1081,9 +1235,13 @@ static int acpi_thermal_add(struct acpi_device *devi= ce) =20 acpi_thermal_guess_offset(tz); =20 - result =3D acpi_thermal_register_thermal_zone(tz); + trips =3D acpi_thermal_trips_alloc(tz, &num_trips); + if (!trips) + goto free_trips; + + result =3D acpi_thermal_register_thermal_zone(tz, trips, num_trips); if (result) - goto free_memory; + goto free_trips; =20 refcount_set(&tz->thermal_check_count, 3); mutex_init(&tz->thermal_check_lock); @@ -1095,6 +1253,8 @@ static int acpi_thermal_add(struct acpi_device *devic= e) =20 free_memory: kfree(tz); +free_trips: + kfree(trips); end: return result; } @@ -1109,6 +1269,7 @@ static int acpi_thermal_remove(struct acpi_device *de= vice) flush_workqueue(acpi_thermal_pm_queue); tz =3D acpi_driver_data(device); =20 + kfree(tz->trips); acpi_thermal_unregister_thermal_zone(tz); kfree(tz); return 0; --=20 2.34.1