From patchwork Tue Oct 4 17:26:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 12998609 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 5C88FC433F5 for ; Tue, 4 Oct 2022 17:27:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229797AbiJDR1T (ORCPT ); Tue, 4 Oct 2022 13:27:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229640AbiJDR1Q (ORCPT ); Tue, 4 Oct 2022 13:27:16 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 158605809A for ; Tue, 4 Oct 2022 10:27:09 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id r3-20020a05600c35c300b003b4b5f6c6bdso7954410wmq.2 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=7grGbGevJVGI+OWHIAQNveCBlrXD4ihunPl0RrJ97/fXuexb4YMdKsmoIFkokqq1KQ SYnBBe5IH29nwXhixM/Mn3zpM+LZNEL/2+ir10Y2TcejvEfWYfhNnbavMZtRJXVD7Kdi iun8HcYdNrrwkoxDZk/hOqWFUwIMA8x+ocK/ykcEyUmbDTDW9sBZKTwZmHvHwYRG1Og1 fjI7L9HeX/2UbmgTkUxBbaqF1FjLJUCbeZxPPqwwA8uTUoJaPvR0znvfhdZCkaSGwOun YDhC/zXEXHnBWqQWRHYLAKjy6Lp8I8oDfwlk5zBXekuwfnNnHq50drN3zypQm/g5nXav Qvog== X-Gm-Message-State: ACrzQf1nVdQZQQrPX+Zs/qgRRPe/HQAjhIB98MtbROujFtcIgnt65mCF AhvexYf2T8gPG4c+5LWOkHjgFg== 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 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org 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_thermal *tz, int flag) if (flag & ACPI_TRIPS_CRITICAL) { status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp); - tz->trips.critical.temperature = tmp; + tz->critical.temperature = 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_thermal *tz, int flag) * ... so lets discard those as invalid. */ if (ACPI_FAILURE(status)) { - tz->trips.critical.flags.valid = 0; + tz->critical.flags.valid = 0; acpi_handle_debug(tz->device->handle, "No critical threshold\n"); } else if (tmp <= 2732) { pr_info(FW_BUG "Invalid critical threshold (%llu)\n", tmp); - tz->trips.critical.flags.valid = 0; + tz->critical.flags.valid = 0; } else { - tz->trips.critical.flags.valid = 1; + tz->critical.flags.valid = 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 == 1) { + if (tz->critical.flags.valid == 1) { if (crt == -1) { - tz->trips.critical.flags.valid = 0; + tz->critical.flags.valid = 0; } else if (crt > 0) { unsigned long crt_k = celsius_to_deci_kelvin(crt); /* * 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); - tz->trips.critical.temperature = crt_k; + tz->critical.temperature = crt_k; } } } @@ -315,22 +318,22 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp); if (ACPI_FAILURE(status)) { - tz->trips.hot.flags.valid = 0; + tz->hot.flags.valid = 0; acpi_handle_debug(tz->device->handle, "No hot threshold\n"); } else { - tz->trips.hot.temperature = tmp; - tz->trips.hot.flags.valid = 1; + tz->hot.temperature = tmp; + tz->hot.flags.valid = 1; acpi_handle_debug(tz->device->handle, "Found hot threshold [%lu]\n", - tz->trips.hot.temperature); + tz->hot.temperature); } } /* Passive (optional) */ - if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.flags.valid) || + if (((flag & ACPI_TRIPS_PASSIVE) && tz->passive.flags.valid) || (flag == ACPI_TRIPS_INIT)) { - valid = tz->trips.passive.flags.valid; + valid = tz->passive.flags.valid; if (psv == -1) { status = AE_SUPPORT; } else if (psv > 0) { @@ -342,122 +345,122 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) } if (ACPI_FAILURE(status)) - tz->trips.passive.flags.valid = 0; + tz->passive.flags.valid = 0; else { - tz->trips.passive.temperature = tmp; - tz->trips.passive.flags.valid = 1; + tz->passive.temperature = tmp; + tz->passive.flags.valid = 1; if (flag == ACPI_TRIPS_INIT) { status = acpi_evaluate_integer( tz->device->handle, "_TC1", NULL, &tmp); if (ACPI_FAILURE(status)) - tz->trips.passive.flags.valid = 0; + tz->passive.flags.valid = 0; else - tz->trips.passive.tc1 = tmp; + tz->passive.tc1 = tmp; status = acpi_evaluate_integer( tz->device->handle, "_TC2", NULL, &tmp); if (ACPI_FAILURE(status)) - tz->trips.passive.flags.valid = 0; + tz->passive.flags.valid = 0; else - tz->trips.passive.tc2 = tmp; + tz->passive.tc2 = tmp; status = acpi_evaluate_integer( tz->device->handle, "_TSP", NULL, &tmp); if (ACPI_FAILURE(status)) - tz->trips.passive.flags.valid = 0; + tz->passive.flags.valid = 0; else - tz->trips.passive.tsp = tmp; + tz->passive.tsp = 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 = 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 = 0; + tz->passive.flags.valid = 0; } else - tz->trips.passive.flags.valid = 1; + tz->passive.flags.valid = 1; - 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 != tz->trips.passive.flags.valid) + if (valid != tz->passive.flags.valid) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); } /* Active (optional) */ for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; - valid = tz->trips.active[i].flags.valid; + valid = tz->active[i].flags.valid; if (act == -1) break; /* disable all active trip points */ if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) && - tz->trips.active[i].flags.valid)) { + tz->active[i].flags.valid)) { status = acpi_evaluate_integer(tz->device->handle, name, NULL, &tmp); if (ACPI_FAILURE(status)) { - tz->trips.active[i].flags.valid = 0; + tz->active[i].flags.valid = 0; if (i == 0) break; if (act <= 0) break; if (i == 1) - tz->trips.active[0].temperature = + tz->active[0].temperature = celsius_to_deci_kelvin(act); else /* * Don't allow override higher than * the next higher trip point */ - tz->trips.active[i - 1].temperature = - (tz->trips.active[i - 2].temperature < + tz->active[i - 1].temperature = + (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 = tmp; - tz->trips.active[i].flags.valid = 1; + tz->active[i].temperature = tmp; + tz->active[i].flags.valid = 1; } } name[2] = '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 = 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 = 0; + tz->active[i].flags.valid = 0; } else - tz->trips.active[i].flags.valid = 1; + tz->active[i].flags.valid = 1; - 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 != tz->trips.active[i].flags.valid) + if (valid != tz->active[i].flags.valid) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); - if (!tz->trips.active[i].flags.valid) + if (!tz->active[i].flags.valid) break; } @@ -482,12 +485,12 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) if (ret) return ret; - valid = tz->trips.critical.flags.valid | - tz->trips.hot.flags.valid | - tz->trips.passive.flags.valid; + valid = tz->critical.flags.valid | + tz->hot.flags.valid | + tz->passive.flags.valid; for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) - valid |= tz->trips.active[i].flags.valid; + valid |= tz->active[i].flags.valid; if (!valid) { pr_warn(FW_BUG "No valid trip found\n"); @@ -524,7 +527,7 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal, if (!tz || trip < 0) return -EINVAL; - if (tz->trips.critical.flags.valid) { + if (tz->critical.flags.valid) { if (!trip) { *type = THERMAL_TRIP_CRITICAL; return 0; @@ -532,7 +535,7 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal, trip--; } - if (tz->trips.hot.flags.valid) { + if (tz->hot.flags.valid) { if (!trip) { *type = THERMAL_TRIP_HOT; return 0; @@ -540,7 +543,7 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal, trip--; } - if (tz->trips.passive.flags.valid) { + if (tz->passive.flags.valid) { if (!trip) { *type = THERMAL_TRIP_PASSIVE; return 0; @@ -549,7 +552,7 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal, } for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->trips.active[i].flags.valid; i++) { + tz->active[i].flags.valid; i++) { if (!trip) { *type = 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; - if (tz->trips.critical.flags.valid) { + if (tz->critical.flags.valid) { if (!trip) { *temp = deci_kelvin_to_millicelsius_with_offset( - tz->trips.critical.temperature, + tz->critical.temperature, tz->kelvin_offset); return 0; } trip--; } - if (tz->trips.hot.flags.valid) { + if (tz->hot.flags.valid) { if (!trip) { *temp = deci_kelvin_to_millicelsius_with_offset( - tz->trips.hot.temperature, + tz->hot.temperature, tz->kelvin_offset); return 0; } trip--; } - if (tz->trips.passive.flags.valid) { + if (tz->passive.flags.valid) { if (!trip) { *temp = 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, } for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->trips.active[i].flags.valid; i++) { + tz->active[i].flags.valid; i++) { if (!trip) { *temp = 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_device *thermal, { struct acpi_thermal *tz = thermal->devdata; - if (tz->trips.critical.flags.valid) { + if (tz->critical.flags.valid) { *temperature = 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 = (tz->trips.passive.tc1 * (tz->temperature - tz->last_temperature)) - + (tz->trips.passive.tc2 - * (tz->temperature - tz->trips.passive.temperature)); + i = (tz->passive.tc1 * (tz->temperature - tz->last_temperature)) + + (tz->passive.tc2 + * (tz->temperature - tz->passive.temperature)); if (i > 0) *trend = THERMAL_TREND_RAISING; @@ -703,17 +706,17 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal, int trip = -1; int result = 0; - if (tz->trips.critical.flags.valid) + if (tz->critical.flags.valid) trip++; - if (tz->trips.hot.flags.valid) + if (tz->hot.flags.valid) trip++; - if (tz->trips.passive.flags.valid) { + if (tz->passive.flags.valid) { trip++; - for (i = 0; i < tz->trips.passive.devices.count; + for (i = 0; i < tz->passive.devices.count; i++) { - handle = tz->trips.passive.devices.handles[i]; + handle = tz->passive.devices.handles[i]; dev = acpi_fetch_acpi_dev(handle); if (dev != device) continue; @@ -733,13 +736,13 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal, } for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - if (!tz->trips.active[i].flags.valid) + if (!tz->active[i].flags.valid) break; trip++; for (j = 0; - j < tz->trips.active[i].devices.count; + j < tz->active[i].devices.count; j++) { - handle = tz->trips.active[i].devices.handles[j]; + handle = tz->active[i].devices.handles[j]; dev = acpi_fetch_acpi_dev(handle); if (dev != device) continue; @@ -793,23 +796,23 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) acpi_status status; int i; - if (tz->trips.critical.flags.valid) + if (tz->critical.flags.valid) trips++; - if (tz->trips.hot.flags.valid) + if (tz->hot.flags.valid) trips++; - if (tz->trips.passive.flags.valid) + if (tz->passive.flags.valid) trips++; for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->trips.active[i].flags.valid; i++, trips++); + tz->active[i].flags.valid; i++, trips++); - if (tz->trips.passive.flags.valid) + if (tz->passive.flags.valid) tz->thermal_zone = 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 = @@ -986,8 +989,8 @@ static int acpi_thermal_get_info(struct acpi_thermal *tz) */ static void acpi_thermal_guess_offset(struct acpi_thermal *tz) { - if (tz->trips.critical.flags.valid && - (tz->trips.critical.temperature % 5) == 1) + if (tz->critical.flags.valid && + (tz->critical.temperature % 5) == 1) tz->kelvin_offset = 273100; else tz->kelvin_offset = 273200; @@ -1097,19 +1100,19 @@ static int acpi_thermal_resume(struct device *dev) return -EINVAL; for (i = 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 = 1; - for (j = 0; j < tz->trips.active[i].devices.count; j++) { + tz->active[i].flags.enabled = 1; + for (j = 0; j < tz->active[i].devices.count; j++) { result = acpi_bus_update_power( - tz->trips.active[i].devices.handles[j], + tz->active[i].devices.handles[j], &power_state); if (result || (power_state != ACPI_STATE_D0)) { - tz->trips.active[i].flags.enabled = 0; + tz->active[i].flags.enabled = 0; break; } } - tz->state.active |= tz->trips.active[i].flags.enabled; + tz->state.active |= tz->active[i].flags.enabled; } acpi_queue_thermal_check(tz); From patchwork Tue Oct 4 17:26:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 12998610 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 9E800C43217 for ; Tue, 4 Oct 2022 17:27:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229735AbiJDR1U (ORCPT ); Tue, 4 Oct 2022 13:27:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229712AbiJDR1Q (ORCPT ); Tue, 4 Oct 2022 13:27:16 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 257F75F7F2 for ; Tue, 4 Oct 2022 10:27:11 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id iv17so9350394wmb.4 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=nNfUtIvD9+xMCJlkoVOju6Tm2yCfnUYMAd45jQ53cjH2PS/jHmlr2hPZstr2K8YD46 McCyFkENAfl6yNRTwxBuCLkQasqVxssrekHbpgAcMxD93zvoi6jIM4xwh1/ITN6AZSL0 cTxQYrNv3+4ko+Y1AyjYRyZm2xx/K34S0VvVxRL1f/I9HO+FK6/vds+TW4ki1/asKsrM 0xyWAKdAVvJ2BF1yqcYSAnNGThhZx+LvQ1fXKJmqhc7KuisRIB3OBRtQDiAeV4EaU3sK LeggZcUZiJgRw+6RrLcagxIInFpaqD8E8jzKuwRFpzzZNR8IOghQsjKUXE3yqN9DwoKr 6w3w== X-Gm-Message-State: ACrzQf2Q1RlpCGt6IWLbUuT4Z3yfocF8DJGZpVJnhJWcOSBpvxaZPeeG EGu4u+s6gA2v8iu6/Y/W4X8S0+kXUqAcVw== 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 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org 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; }; -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]; }; 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 */ From patchwork Tue Oct 4 17:26:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 12998611 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 2E82AC4321E for ; Tue, 4 Oct 2022 17:27:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229712AbiJDR1V (ORCPT ); Tue, 4 Oct 2022 13:27:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229648AbiJDR1R (ORCPT ); Tue, 4 Oct 2022 13:27:17 -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 37EC161D5C for ; Tue, 4 Oct 2022 10:27:12 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id bk15so22374305wrb.13 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=VWzPShEo0Ig461V/eytTZZ9/LkIRx3OkcDVg5uPr1Jdm/4KW5aEgrWb47M0LiVGPNp V+exe/a2f4CMnaLy2f3gzryADM2gqQSayfnU2DiLnid3ggk3ew5DF+TQugfDT6oQwLCG 0svFaSV9W1ztNSP7sSNykDIovA4c3dyYZFChySMGTqpp43KRPx4mZJDYVVm/ekBquiE2 lnbqUoWHyon4MOS6f2AMqn5/wt5TgBGFy8/HgIJ4xC16/7TOHDfx9lcid6V3Ri1sSc6P ClAgLjKMpMCrs1+sBHwz+jQ9UbyEnCwmOMEGfoXr17eCiYyXVyausw4DBqEt+KjH1GZ8 KDTA== X-Gm-Message-State: ACrzQf1IcdsR9dl43P2pm/GnSX+oMDMZW14e1e2yNs/cPKAnz1RPOxZz w/0gbows51CBwShuPMCG/BxL77g7Yrtc4w== 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 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org 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 = { .drv.pm = &acpi_thermal_pm, }; +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_thermal *tz, int flag) if (flag & ACPI_TRIPS_CRITICAL) { status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp); - tz->critical.temperature = tmp; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature = 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_thermal *tz, int flag) * ... so lets discard those as invalid. */ if (ACPI_FAILURE(status)) { - tz->critical.flags.valid = 0; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0; acpi_handle_debug(tz->device->handle, "No critical threshold\n"); } else if (tmp <= 2732) { pr_info(FW_BUG "Invalid critical threshold (%llu)\n", tmp); - tz->critical.flags.valid = 0; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0; } else { - tz->critical.flags.valid = 1; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 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 == 1) { + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid == 1) { if (crt == -1) { - tz->critical.flags.valid = 0; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0; } else if (crt > 0) { unsigned long crt_k = celsius_to_deci_kelvin(crt); /* * 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); - tz->critical.temperature = crt_k; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature = crt_k; } } } @@ -295,22 +302,22 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp); if (ACPI_FAILURE(status)) { - tz->hot.flags.valid = 0; + tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid = 0; acpi_handle_debug(tz->device->handle, "No hot threshold\n"); } else { - tz->hot.temperature = tmp; - tz->hot.flags.valid = 1; + tz->trips[ACPI_THERMAL_TRIP_HOT].temperature = tmp; + tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid = 1; acpi_handle_debug(tz->device->handle, "Found hot threshold [%lu]\n", - tz->hot.temperature); + tz->trips[ACPI_THERMAL_TRIP_HOT].temperature); } } /* 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 == ACPI_TRIPS_INIT)) { - valid = tz->passive.flags.valid; + valid = tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; if (psv == -1) { status = AE_SUPPORT; } else if (psv > 0) { @@ -322,56 +329,56 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) } if (ACPI_FAILURE(status)) - tz->passive.flags.valid = 0; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; else { - tz->passive.temperature = tmp; - tz->passive.flags.valid = 1; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].temperature = tmp; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 1; if (flag == ACPI_TRIPS_INIT) { status = acpi_evaluate_integer( tz->device->handle, "_TC1", NULL, &tmp); if (ACPI_FAILURE(status)) - tz->passive.flags.valid = 0; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; else - tz->passive.tc1 = tmp; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc1 = tmp; status = acpi_evaluate_integer( tz->device->handle, "_TC2", NULL, &tmp); if (ACPI_FAILURE(status)) - tz->passive.flags.valid = 0; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; else - tz->passive.tc2 = tmp; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc2 = tmp; status = acpi_evaluate_integer( tz->device->handle, "_TSP", NULL, &tmp); if (ACPI_FAILURE(status)) - tz->passive.flags.valid = 0; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; else - tz->passive.tsp = tmp; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tsp = tmp; } } } - if ((flag & ACPI_TRIPS_DEVICES) && tz->passive.flags.valid) { + if ((flag & ACPI_TRIPS_DEVICES) && tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) { memset(&devices, 0, sizeof(struct acpi_handle_list)); status = acpi_evaluate_reference(tz->device->handle, "_PSL", NULL, &devices); if (ACPI_FAILURE(status)) { acpi_handle_info(tz->device->handle, "Invalid passive threshold\n"); - tz->passive.flags.valid = 0; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; } else - tz->passive.flags.valid = 1; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 1; - 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 != tz->passive.flags.valid) + if (valid != tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); } @@ -462,9 +469,9 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) if (ret) return ret; - valid = tz->critical.flags.valid | - tz->hot.flags.valid | - tz->passive.flags.valid; + valid = 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 = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) valid |= tz->active[i].flags.valid; @@ -504,7 +511,7 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal, if (!tz || trip < 0) return -EINVAL; - if (tz->critical.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) { if (!trip) { *type = THERMAL_TRIP_CRITICAL; return 0; @@ -512,7 +519,7 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal, trip--; } - if (tz->hot.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid) { if (!trip) { *type = THERMAL_TRIP_HOT; return 0; @@ -520,7 +527,7 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal, trip--; } - if (tz->passive.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) { if (!trip) { *type = 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; - if (tz->critical.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) { if (!trip) { *temp = deci_kelvin_to_millicelsius_with_offset( - tz->critical.temperature, + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature, tz->kelvin_offset); return 0; } trip--; } - if (tz->hot.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid) { if (!trip) { *temp = deci_kelvin_to_millicelsius_with_offset( - tz->hot.temperature, + tz->trips[ACPI_THERMAL_TRIP_HOT].temperature, tz->kelvin_offset); return 0; } trip--; } - if (tz->passive.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) { if (!trip) { *temp = 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_device *thermal, { struct acpi_thermal *tz = thermal->devdata; - if (tz->critical.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) { *temperature = 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 = (tz->passive.tc1 * (tz->temperature - tz->last_temperature)) - + (tz->passive.tc2 - * (tz->temperature - tz->passive.temperature)); + i = (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)); if (i > 0) *trend = THERMAL_TREND_RAISING; @@ -683,17 +690,17 @@ static int acpi_thermal_cooling_device_cb(struct thermal_zone_device *thermal, int trip = -1; int result = 0; - if (tz->critical.flags.valid) + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) trip++; - if (tz->hot.flags.valid) + if (tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid) trip++; - if (tz->passive.flags.valid) { + if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) { trip++; - for (i = 0; i < tz->passive.devices.count; + for (i = 0; i < tz->trips[ACPI_THERMAL_TRIP_PASSIVE].devices.count; i++) { - handle = tz->passive.devices.handles[i]; + handle = tz->trips[ACPI_THERMAL_TRIP_PASSIVE].devices.handles[i]; dev = acpi_fetch_acpi_dev(handle); if (dev != device) continue; @@ -773,23 +780,23 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) acpi_status status; int i; - if (tz->critical.flags.valid) + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) trips++; - if (tz->hot.flags.valid) + if (tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid) trips++; - if (tz->passive.flags.valid) + if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) trips++; for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->active[i].flags.valid; i++, trips++); - if (tz->passive.flags.valid) + if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) tz->thermal_zone = 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 = @@ -966,8 +973,8 @@ static int acpi_thermal_get_info(struct acpi_thermal *tz) */ static void acpi_thermal_guess_offset(struct acpi_thermal *tz) { - if (tz->critical.flags.valid && - (tz->critical.temperature % 5) == 1) + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid && + (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature % 5) == 1) tz->kelvin_offset = 273100; else tz->kelvin_offset = 273200; From patchwork Tue Oct 4 17:26:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 12998612 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 AD2BCC433FE for ; Tue, 4 Oct 2022 17:27:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229531AbiJDR1Y (ORCPT ); Tue, 4 Oct 2022 13:27:24 -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 S229789AbiJDR1T (ORCPT ); Tue, 4 Oct 2022 13:27:19 -0400 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51CD35F107 for ; Tue, 4 Oct 2022 10:27:14 -0700 (PDT) Received: by mail-wm1-x32f.google.com with SMTP id o5so9362762wms.1 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=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=OnKUfdvfI1f09GgbGNb5wzAI8ix9bI5ML+IWxVkGhjsj4tnYFeUhr81ApaMmjRJu0B KNn5jE/vPQtUdIpO7nJM2rPw9crirmktctWF6BXogiBH/PjSJ/Hbc7b5E//1iKqZM+O+ AyPQnLJcCHkRYrC1O0pPzXtnfQimfoezhevkFAS1+n6hObv8shmPQmmDfXbeROPorAfk a/hFZ8VRw16YvVt0o7TXhPuAI2Vt+nhNGkEwNoNx/IjApO1O4BEdODEHN4RkbfwPEAo6 NAaHFhYxerzj3TGXSASM2ocbyiWxZtGghDbyRnczGkLafOxpSSfdQ5ayBY0pKwZv3qU5 N+kA== X-Gm-Message-State: ACrzQf2xGA7pqx7vYSz+S77DVK9WpEHO54W4J6SU06C8W4EMVfm3KsaR a/bUqf1oIqiFAhyaCsLDfGeEBA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org 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_thermal *tz, int flag) } /* Active (optional) */ - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; - valid = tz->active[i].flags.valid; + valid = tz->trips[i].flags.valid; if (act == -1) break; /* disable all active trip points */ if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) && - tz->active[i].flags.valid)) { + tz->trips[i].flags.valid)) { status = acpi_evaluate_integer(tz->device->handle, name, NULL, &tmp); if (ACPI_FAILURE(status)) { - tz->active[i].flags.valid = 0; + tz->trips[i].flags.valid = 0; if (i == 0) break; if (act <= 0) break; if (i == 1) - tz->active[0].temperature = + tz->trips[0].temperature = celsius_to_deci_kelvin(act); else /* * Don't allow override higher than * the next higher trip point */ - tz->active[i - 1].temperature = - (tz->active[i - 2].temperature < + tz->trips[i - 1].temperature = + (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 = tmp; - tz->active[i].flags.valid = 1; + tz->trips[i].temperature = tmp; + tz->trips[i].flags.valid = 1; } } name[2] = '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 = 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 = 0; + tz->trips[i].flags.valid = 0; } else - tz->active[i].flags.valid = 1; + tz->trips[i].flags.valid = 1; - 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 != tz->active[i].flags.valid) + if (valid != tz->trips[i].flags.valid) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); - if (!tz->active[i].flags.valid) + if (!tz->trips[i].flags.valid) break; } @@ -473,8 +472,8 @@ static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid | tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) - valid |= tz->active[i].flags.valid; + for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) + valid |= tz->trips[i].flags.valid; if (!valid) { pr_warn(FW_BUG "No valid trip found\n"); @@ -535,8 +534,8 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal, trip--; } - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->active[i].flags.valid; i++) { + for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE && + tz->trips[i].flags.valid; i++) { if (!trip) { *type = THERMAL_TRIP_ACTIVE; return 0; @@ -586,11 +585,11 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal, trip--; } - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->active[i].flags.valid; i++) { + for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE && + tz->trips[i].flags.valid; i++) { if (!trip) { *temp = 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 thermal_zone_device *thermal, } } - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - if (!tz->active[i].flags.valid) + for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + if (!tz->trips[i].flags.valid) break; trip++; for (j = 0; - j < tz->active[i].devices.count; + j < tz->trips[i].devices.count; j++) { - handle = tz->active[i].devices.handles[j]; + handle = tz->trips[i].devices.handles[j]; dev = acpi_fetch_acpi_dev(handle); if (dev != device) continue; @@ -789,8 +788,8 @@ static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) trips++; - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && - tz->active[i].flags.valid; i++, trips++); + for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE && + tz->trips[i].flags.valid; i++, trips++); if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) tz->thermal_zone = @@ -1083,20 +1082,20 @@ static int acpi_thermal_resume(struct device *dev) if (!tz) return -EINVAL; - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - if (!tz->active[i].flags.valid) + for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + if (!tz->trips[i].flags.valid) break; - tz->active[i].flags.enabled = 1; - for (j = 0; j < tz->active[i].devices.count; j++) { + tz->trips[i].flags.enabled = 1; + for (j = 0; j < tz->trips[i].devices.count; j++) { result = acpi_bus_update_power( - tz->active[i].devices.handles[j], + tz->trips[i].devices.handles[j], &power_state); if (result || (power_state != ACPI_STATE_D0)) { - tz->active[i].flags.enabled = 0; + tz->trips[i].flags.enabled = 0; break; } } - tz->state.active |= tz->active[i].flags.enabled; + tz->state.active |= tz->trips[i].flags.enabled; } acpi_queue_thermal_check(tz); From patchwork Tue Oct 4 17:26:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 12998613 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 A3B31C4332F for ; Tue, 4 Oct 2022 17:27:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229789AbiJDR1Z (ORCPT ); Tue, 4 Oct 2022 13:27:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229791AbiJDR1T (ORCPT ); Tue, 4 Oct 2022 13:27:19 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 392D743E4C for ; Tue, 4 Oct 2022 10:27:15 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id n12so2799545wrp.10 for ; Tue, 04 Oct 2022 10:27:15 -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=FoXzNsDZ9f9OiHzas5Z+sLfAslb+apwJm/Kms2TBIOuaOjDmaGjgMfaGv83IdqSi7g X9LS0Cc/9RSUylYY35Uole76ehlMyB2GqwmK8rbdLOYmEzQ3p3HtfLLlY/HnFWBTjdfr HbENa6luOFEKAQC/mL42sA9/C6XGjgC2ToHMRcYIjO1MrqVH6pryzHoOzAzqqcHAMho/ 3coW+g95gx4HE2/WSqCR0wtNmw8O6iuQ+1xqvKEDVrXT2ad288OybQ2OghJiayeym0jN m0Lb268MCmQAL7uW7p1bIJiL9cqcRjleHcoq3kYQD7DRmI4FctzpiaoRiorEqLwJVgUs F06Q== X-Gm-Message-State: ACrzQf3FmMJGjJ531PbNZtDuQvV9EyA0ylBPq1k8yTvk1m0xU6audZPM 6i54glrYfn7Bc/td6W/77ASBuA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org 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_thermal *tz, int flag) static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) { - int i, valid, ret = acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); + int i, ret; + ret = acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); if (ret) return ret; - valid = 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 = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + if (tz->trips[i].flags.valid) + return 0; + } - for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) - valid |= tz->trips[i].flags.valid; + pr_warn(FW_BUG "No valid trip found\n"); - if (!valid) { - pr_warn(FW_BUG "No valid trip found\n"); - return -ENODEV; - } - return 0; + return -ENODEV; } /* sys I/F for generic thermal sysfs support */ From patchwork Tue Oct 4 17:26:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 12998614 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 CFAD6C4332F for ; Tue, 4 Oct 2022 17:27:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229791AbiJDR1Z (ORCPT ); Tue, 4 Oct 2022 13:27:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229703AbiJDR1T (ORCPT ); Tue, 4 Oct 2022 13:27:19 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83C235F7DD for ; Tue, 4 Oct 2022 10:27:16 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id r3-20020a05600c35c300b003b4b5f6c6bdso7954542wmq.2 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=L/z1mxBWt1rOduEmzcwrW56EcFYdguuR97/LGIEv55Cgm291W54ALnPPlxbaH0xyFV xt2Y1PWy1zepA2PZNLaTgsgOea0q9R4+zySG61edt6phKlwZqrjuLDvNeK6ZqwmSbcHv LUXX2GUB8NcbA9diNF3TN/WY9Q50+9OvYkUYJsErQH4SJZV22kWOvQZgpbGXIadYMXQ+ sM3G/5PYVrEkRNDiDMme3y9ztzvSTCMc95H6KhZrt65LU1Fy8FXbgNHMMBuIKDKqdySW Z4wpqUJ0VwaHY/hKVtRGeyOHMfNYDHgT3JDsvtvgHClDeFi6mtOjxueiDNkBqaPZlfNQ /j/A== X-Gm-Message-State: ACrzQf2DVZpc86osba+9jElvB8q/uwOmW4bfLYevg51DIMDm6jtlSxlK 3tMZjOgmDUvkrkypXQVpO4PHXw== 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 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org 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) -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 = AE_OK; unsigned long long tmp; - struct acpi_handle_list devices; - int valid = 0; - int i; - /* Critical Shutdown */ - if (flag & ACPI_TRIPS_CRITICAL) { - status = acpi_evaluate_integer(tz->device->handle, + status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp); - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature = 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 = 0; - acpi_handle_debug(tz->device->handle, - "No critical threshold\n"); - } else if (tmp <= 2732) { - pr_info(FW_BUG "Invalid critical threshold (%llu)\n", - tmp); + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature = 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 = 0; + acpi_handle_debug(tz->device->handle, + "No critical threshold\n"); + } else if (tmp <= 2732) { + pr_info(FW_BUG "Invalid critical threshold (%llu)\n", + tmp); + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0; + } else { + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 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 == 1) { + if (crt == -1) { tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0; - } else { - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 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 == 1) { - if (crt == -1) { - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0; - } else if (crt > 0) { - unsigned long crt_k = 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 = crt_k; - } + } else if (crt > 0) { + unsigned long crt_k = 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 = crt_k; } } - /* Critical Sleep (optional) */ - if (flag & ACPI_TRIPS_HOT) { - status = acpi_evaluate_integer(tz->device->handle, - "_HOT", NULL, &tmp); - if (ACPI_FAILURE(status)) { - tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid = 0; - acpi_handle_debug(tz->device->handle, - "No hot threshold\n"); - } else { - tz->trips[ACPI_THERMAL_TRIP_HOT].temperature = tmp; - tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid = 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 = AE_OK; + unsigned long long tmp; + + status = acpi_evaluate_integer(tz->device->handle, + "_HOT", NULL, &tmp); + if (ACPI_FAILURE(status)) { + tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid = 0; + acpi_handle_debug(tz->device->handle, + "No hot threshold\n"); + } else { + tz->trips[ACPI_THERMAL_TRIP_HOT].temperature = tmp; + tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid = 1; + acpi_handle_debug(tz->device->handle, + "Found hot threshold [%lu]\n", + tz->trips[ACPI_THERMAL_TRIP_HOT].temperature); } - /* Passive (optional) */ - if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) || - (flag == ACPI_TRIPS_INIT)) { - valid = tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; - if (psv == -1) { - status = AE_SUPPORT; - } else if (psv > 0) { - tmp = celsius_to_deci_kelvin(psv); - status = AE_OK; - } else { - status = acpi_evaluate_integer(tz->device->handle, - "_PSV", NULL, &tmp); - } + return 0; +} - if (ACPI_FAILURE(status)) - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; - else { - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].temperature = tmp; - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 1; - if (flag == ACPI_TRIPS_INIT) { - status = acpi_evaluate_integer( - tz->device->handle, "_TC1", - NULL, &tmp); - if (ACPI_FAILURE(status)) - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; - else - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc1 = tmp; - status = acpi_evaluate_integer( - tz->device->handle, "_TC2", - NULL, &tmp); - if (ACPI_FAILURE(status)) - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; - else - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc2 = tmp; - status = acpi_evaluate_integer( - tz->device->handle, "_TSP", - NULL, &tmp); - if (ACPI_FAILURE(status)) - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; - else - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tsp = tmp; - } +static int acpi_thermal_trips_update_passive(struct acpi_thermal *tz, int flag) +{ + acpi_status status = AE_OK; + unsigned long long tmp; + struct acpi_handle_list devices; + int valid = 0; + + valid = tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; + if (psv == -1) { + status = AE_SUPPORT; + } else if (psv > 0) { + tmp = celsius_to_deci_kelvin(psv); + status = AE_OK; + } else { + status = acpi_evaluate_integer(tz->device->handle, + "_PSV", NULL, &tmp); + } + + if (ACPI_FAILURE(status)) + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; + else { + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].temperature = tmp; + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 1; + if (flag == ACPI_TRIPS_INIT) { + status = acpi_evaluate_integer( + tz->device->handle, "_TC1", + NULL, &tmp); + if (ACPI_FAILURE(status)) + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; + else + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc1 = tmp; + status = acpi_evaluate_integer( + tz->device->handle, "_TC2", + NULL, &tmp); + if (ACPI_FAILURE(status)) + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; + else + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tc2 = tmp; + status = acpi_evaluate_integer( + tz->device->handle, "_TSP", + NULL, &tmp); + if (ACPI_FAILURE(status)) + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid = 0; + else + tz->trips[ACPI_THERMAL_TRIP_PASSIVE].tsp = tmp; } } + if ((flag & ACPI_TRIPS_DEVICES) && tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) { memset(&devices, 0, sizeof(struct acpi_handle_list)); status = acpi_evaluate_reference(tz->device->handle, "_PSL", @@ -376,12 +382,23 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "device"); } } + if ((flag & ACPI_TRIPS_PASSIVE) || (flag & ACPI_TRIPS_DEVICES)) { if (valid != tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) - ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); + ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); } - /* Active (optional) */ + return 0; +} + +static int acpi_thermal_trips_update_active(struct acpi_thermal *tz, int flag) +{ + acpi_status status = AE_OK; + unsigned long long tmp; + struct acpi_handle_list devices; + int valid = 0; + int i; + for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; valid = tz->trips[i].flags.valid; @@ -447,17 +464,51 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) break; } - if (flag & ACPI_TRIPS_DEVICES) { - memset(&devices, 0, sizeof(devices)); - status = acpi_evaluate_reference(tz->device->handle, "_TZD", - NULL, &devices); - if (ACPI_SUCCESS(status) - && memcmp(&tz->devices, &devices, sizeof(devices))) { - tz->devices = 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 = AE_OK; + struct acpi_handle_list devices; + + memset(&devices, 0, sizeof(devices)); + status = acpi_evaluate_reference(tz->device->handle, "_TZD", + NULL, &devices); + if (ACPI_SUCCESS(status) + && memcmp(&tz->devices, &devices, sizeof(devices))) { + tz->devices = 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); } + /* 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 == 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); + } + return 0; } From patchwork Tue Oct 4 17:26:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 12998615 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 1ED6EC4321E for ; Tue, 4 Oct 2022 17:27:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229880AbiJDR11 (ORCPT ); Tue, 4 Oct 2022 13:27:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43182 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229708AbiJDR1U (ORCPT ); Tue, 4 Oct 2022 13:27:20 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C52795A82E for ; Tue, 4 Oct 2022 10:27:17 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id w18so13654431wro.7 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=mAams55aoMN6esbSjUfgy9KcxnS25jVI+EmA4nQ/xMm1vUg8fhjsUniKQ+keQHk1W8 lQYl36d68IbwpWU/RRbarFhEuegLjeXv/mJJQUtuEuHTDJBud54gS9+yemx4SKHLoTQH ZHIY6C0fbJ6zL32c9TUFEl1Xh17+yUXOIApXcKTteGkOCZEu6rsZe0pFs+ThMqgSNkQP bsjjH8MlaVFnSggFCNiQLAGU9SOzMy3U2a8rXLxwZ63t75JTw0n6V4W/ym0aHG0feDyx 87Sj2QrryBNvDsTxBfZZYevcJOgdub2fzK1zJfwpg5tEUxzXsp13sJhYshjEP9teQS3I INUw== X-Gm-Message-State: ACrzQf0VsxYqDOZV00CUXhst0fPffb1sD8stD1C4Q1CS9Wl29P+FHbVP PDKocedMkmxGz+oCM+IV2x//Ng== 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 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The condition: if ((flag == 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 acpi_thermal *tz, int flag) int valid = 0; valid = tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid; + if (!valid) + return 0; + if (psv == -1) { status = AE_SUPPORT; } else if (psv > 0) { @@ -401,13 +404,16 @@ static int acpi_thermal_trips_update_active(struct acpi_thermal *tz, int flag) for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; + valid = tz->trips[i].flags.valid; if (act == -1) break; /* disable all active trip points */ - if ((flag == ACPI_TRIPS_INIT) || ((flag & ACPI_TRIPS_ACTIVE) && - tz->trips[i].flags.valid)) { + if (!tz->trips[i].flags.valid) + continue; + + if (flag & ACPI_TRIPS_ACTIVE) { status = 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) } name[2] = '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 = 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 != tz->trips[i].flags.valid) ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); @@ -497,8 +504,7 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) } /* Passive (optional) */ - if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) || - (flag == ACPI_TRIPS_INIT)) { + if (flag & ACPI_TRIPS_PASSIVE) { acpi_thermal_trips_update_passive(tz, flag); } From patchwork Tue Oct 4 17:26:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 12998616 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 B9318C43219 for ; Tue, 4 Oct 2022 17:27:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229640AbiJDR1a (ORCPT ); Tue, 4 Oct 2022 13:27:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43214 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229451AbiJDR1U (ORCPT ); Tue, 4 Oct 2022 13:27:20 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38F5965838 for ; Tue, 4 Oct 2022 10:27:18 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id f11so19739130wrm.6 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=Gh2X7OYhHa5ef0+j13Rw7bMJzHUZ1uzf8kQ09t2UwiMipmMO81I/vLYjLB/ZdXoe46 UkWWGksCszgE8dDuALpErnMdxODrO9HDjqIaoHaoIgTkm+iPWJ+UhYGuQRcL9XvWhcMP KOtzLvEdd0akfb9q1F+mqafRjqMzVTipveCVIbKq2wqc8FtfyKihDq1LBMDBZwTp8jfW z2nyzrgmNOrISl+eBbTU/8DxVt6TATeNaMmAuAL8NVv+9UK8q8wjQtzeoqj4Py70lSqh A/Nv0pkIFJnk+9BEgRMm3UV1y7bwJcoHykz/f0/ha8VO6JiK3eo6BIQrtOL8L4+IPymZ BM7A== X-Gm-Message-State: ACrzQf3s/2a9rbQkOeKyOFHgl6xjbbwQ9jfIQmZ/0WaNo/GVTfAzvtQb V8CKSo28qFBVG2pepCxCRorkuA== 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 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org 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; }; struct acpi_thermal_state_flags { u8 valid:1; - u8 enabled:1; u8 reserved:6; }; @@ -1139,17 +1137,14 @@ static int acpi_thermal_resume(struct device *dev) for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { if (!tz->trips[i].flags.valid) break; - tz->trips[i].flags.enabled = 1; + for (j = 0; j < tz->trips[i].devices.count; j++) { result = acpi_bus_update_power( tz->trips[i].devices.handles[j], &power_state); - if (result || (power_state != ACPI_STATE_D0)) { - tz->trips[i].flags.enabled = 0; + if (result || (power_state != ACPI_STATE_D0)) break; - } } - tz->state.active |= tz->trips[i].flags.enabled; } acpi_queue_thermal_check(tz); From patchwork Tue Oct 4 17:26:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 12998617 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 6DADFC4332F for ; Tue, 4 Oct 2022 17:27:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229938AbiJDR1b (ORCPT ); Tue, 4 Oct 2022 13:27:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43682 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229819AbiJDR1W (ORCPT ); Tue, 4 Oct 2022 13:27:22 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F6095509F for ; Tue, 4 Oct 2022 10:27:20 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id a3so10114618wrt.0 for ; Tue, 04 Oct 2022 10:27:20 -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=N2Be4cOTzYdMmat2KfcEBCZCA2JNdm2iBZPl2RIbDx+fmQd+8iPaBWjoCNOhI14Dte g3FiCuXjaVAMuF1yF6JeZw2z+NIQ4WrqT6l7ytram9lhdgXD7/ALyvYDUKl3ReSJwUDl 5CW6eFcSRYii4umJFqn2b+cF7RSyOH8vPqOzHdXvCpQ1aoQqLjGYTIttEsHV+LGNTrZP PIySvBRBzoASt4e2VyLH0naf9pbzeUAp9txg6ipxFm6fvfoJN/VAg1YL1R0M5PXhGZKE rjymzzqcyRpKs4C0FUvSCVlNAKF+8c0IffPMBAk2XRUST2CBQ0zK4eyXXoU1V7ow7wad DF2g== X-Gm-Message-State: ACrzQf0PYDITy0Z+4/Uko4zKjfGo6ukTUkTiGLYt8gwibu33dkuj01Pq 3cylA/VJ0qDOIgZsV1LccZjwIjDnmIePsw== 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 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org 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) +static void acpi_thermal_trips_override_critical(struct thermal_trip *trip, + int temperature) +{ + int ktemp = = celsius_to_deci_kelvin(temperature); + + if (ktemp > trip->temperature) + pr_info("Overriding %d C\n", temperature); + + trip->temperature = ktemp; +} + +static struct thermal_trip *acpi_thermal_trips_alloc_critical(struct acpi_thermal *tz, + struct thermal_trip *trips, + int *num_trips) +{ + acpi_status status = AE_OK; + unsigned long long temp; + + /* + * Module parameters disable the critical trip point + */ + if (crt < 0) + goto out; + + status = 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 <= 2732) { + pr_info(FW_BUG "Invalid critical threshold (%llu)\n", temp); + goto out; + } + + trips = krealloc(trips, sizeof(*trips) * (*num_trips + 1), GFP_KERNEL); + if (!trips) + goto out; + + memset(&trips[*num_trips], 0, sizeof(*trips)); + + trips[*num_trips].temperature = deci_kelvin_to_millicelsius(temp); + trips[*num_trips].type = THERMAL_TRIP_CRITICAL; + + if (crt > 0) + acpi_thermal_trips_override_critical(&trips[*num_trips], crt); + + (*num_trips)++; +out: + return trips; +} + +static struct thermal_trip *acpi_thermal_trips_alloc_hot(struct acpi_thermal *tz, + struct thermal_trip *trips, + int *num_trips) +{ + acpi_status status = AE_OK; + unsigned long long temp; + + status = 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 = krealloc(trips, sizeof(*trips) * (*num_trips + 1), GFP_KERNEL); + if (!trips) + goto out; + + memset(&trips[*num_trips], 0, sizeof(*trips)); + + trips[*num_trips].temperature = deci_kelvin_to_millicelsius(temp); + trips[*num_trips].type = THERMAL_TRIP_HOT; + + (*num_trips)++; +out: + return trips; +} + +static struct thermal_trip *acpi_thermal_trips_alloc_passive(struct acpi_thermal *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; + + status = 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 = krealloc(trips, sizeof(*trips) * (*num_trips + 1), GFP_KERNEL); + if (!trips) + goto out; + + memset(&trips[*num_trips], 0, sizeof(*trips)); + + trips[*num_trips].temperature = deci_kelvin_to_millicelsius(temp); + trips[*num_trips].type = THERMAL_TRIP_PASSIVE; + + (*num_trips)++; +out: + return trips; +} + +static struct thermal_trip *acpi_thermal_trips_alloc_active(struct acpi_thermal *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 = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; + + status = acpi_evaluate_integer(tz->device->handle, name, NULL, &temp); + if (ACPI_FAILURE(status)) + break; + + trips = krealloc(trips, sizeof(*trips) * (*num_trips + 1), GFP_KERNEL); + if (!trips) + break; + + memset(&trips[*num_trips], 0, sizeof(*trips)); + + trips[*num_trips].temperature = deci_kelvin_to_millicelsius(temp); + trips[*num_trips].type = THERMAL_TRIP_ACTIVE; + + (*num_trips)++; + } + + return trips; +} + +static struct thermal_trip *acpi_thermal_trips_alloc(struct acpi_thermal *tz, int *num_trips) +{ + struct thermal_trip *trips = NULL; + + *num_trips = 0; + + trips = acpi_thermal_trips_alloc_critical(tz, trips, num_trips); + + trips = acpi_thermal_trips_alloc_hot(tz, trips, num_trips); + + trips = acpi_thermal_trips_alloc_passive(tz, trips, num_trips); + + trips = 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 = AE_OK; @@ -824,36 +989,24 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { .critical = acpi_thermal_zone_device_critical, }; -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 = 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 = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE && - tz->trips[i].flags.valid; i++, trips++); if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) tz->thermal_zone = - 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 = - 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; @@ -1060,7 +1213,8 @@ static int acpi_thermal_add(struct acpi_device *device) { int result = 0; struct acpi_thermal *tz = NULL; - + struct thermal_trip *trips; + int num_trips; if (!device) return -EINVAL; @@ -1081,9 +1235,13 @@ static int acpi_thermal_add(struct acpi_device *device) acpi_thermal_guess_offset(tz); - result = acpi_thermal_register_thermal_zone(tz); + trips = acpi_thermal_trips_alloc(tz, &num_trips); + if (!trips) + goto free_trips; + + result = acpi_thermal_register_thermal_zone(tz, trips, num_trips); if (result) - goto free_memory; + goto free_trips; 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 *device) free_memory: kfree(tz); +free_trips: + kfree(trips); end: return result; } @@ -1109,6 +1269,7 @@ static int acpi_thermal_remove(struct acpi_device *device) flush_workqueue(acpi_thermal_pm_queue); tz = acpi_driver_data(device); + kfree(tz->trips); acpi_thermal_unregister_thermal_zone(tz); kfree(tz); return 0;