From patchwork Fri Feb 3 17:44:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 52588 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp973920wrn; Fri, 3 Feb 2023 09:46:57 -0800 (PST) X-Google-Smtp-Source: AK7set/vkeqrKs/YSS8o2OGMgjBrTVnKRo0fhmD5UkC+5hatybE7vuiRPmLE/jMELdbufJXYI92n X-Received: by 2002:a05:6a20:c184:b0:bf:4f83:5cdf with SMTP id bg4-20020a056a20c18400b000bf4f835cdfmr11382969pzb.31.1675446417358; Fri, 03 Feb 2023 09:46:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675446417; cv=none; d=google.com; s=arc-20160816; b=gYQHpodegtPbLhTvlHEx5+tAdwurwKsNZYfLoiPlxbA9zzQaFXRpmPJOV2hPAdL6KE bECszDsFUbkAlVByybW2le7QF77UJkvMUaDho5BwAgy9UydhanITPp12P+aT1keE2yYK f+hRqCQOlrNBAGIbNdzhNqARWIFOP+wG5q8FK0kM+onlJ9uJFMA6SapJ3bG+mP2vpXOf x/5GjOtsWeUW9ddo8hW8y22IPDhlPT1o7nTr8cu9ED315mIePOoQ1H+GOTatQOgFXpjU bj1zaAfp2WA5nXyK7wS6JEZwXWZ1ck5cb0uZVluagA5j15MOvxisHYGSJQZ5OcBybufr KDmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=WTJte4qZE/LXbMp1K0FOI8nJeIqbfiwwJeeV+duwur8=; b=0vWXmcUw86LXKWzzI6LkslbR/+1Pze/jeqscGRo5CpPvyfaxrlN1WuAPU7g9YFft7E oIPyS9xgfOMvqWFkrS2PM1FSpQIaSh7CQcxE9iSSlebGAnbVI34A6JtKBUvnK9OpPx9D HIvXL/arQxW5MUPPCE3olP/ULBmX/w/Ld1MhLkr0l03XT+0iI3I2O15d+2XeAA/ZpOch 3vSpGheUVjSv8jdFZuz/OrRVhURvM03B2URGdCiTCXLluNyNV2WO4MBFJML7jEfYnqE/ N0lS5DvdDy9P3n4WfHPMyFt/J5nZfaV0f7gPPZM7at+JPDYN6GcxlGNzxbXGgvqb/4/Y dwcw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nfivpy9s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o3-20020a170902d4c300b00193353fb086si3376180plg.383.2023.02.03.09.46.45; Fri, 03 Feb 2023 09:46:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nfivpy9s; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233540AbjBCRol (ORCPT + 99 others); Fri, 3 Feb 2023 12:44:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48040 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231205AbjBCRoh (ORCPT ); Fri, 3 Feb 2023 12:44:37 -0500 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 F19746DFC3 for ; Fri, 3 Feb 2023 09:44:34 -0800 (PST) Received: by mail-wm1-x32c.google.com with SMTP id j32-20020a05600c1c2000b003dc4fd6e61dso6531848wms.5 for ; Fri, 03 Feb 2023 09:44:34 -0800 (PST) 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=WTJte4qZE/LXbMp1K0FOI8nJeIqbfiwwJeeV+duwur8=; b=nfivpy9slATDSW5QCPXHCagBLS4OIGxOhcaPbFRuQslx4rRFB4QXr9HjCY3MAlGYFD uOuDzrTBGBFYfzBBapVihH1Z+FHMCctSC47y35wLrwg9qrmVLd7MuncN0rpC1C1AIKg9 HBrShOlV9afpj/EAzz6jJuWWyYYK1Zgr74+4bPHLCPEYzFSRebDatp1BLlhxFQwrmQ+N ApznrGqS+HVl6KNloK2+gzk74DfxPHwFryhK5HnWmPuFX100/9F0lcwX3c4XUpkv8Zx2 gz1tTpGwYTWm/hxIfl89iMpryIfpWh7aQVc+ly0hXQZzq1eOGM4eOvMgVC9qalek/4gJ PqiA== 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=WTJte4qZE/LXbMp1K0FOI8nJeIqbfiwwJeeV+duwur8=; b=QLbaSiIA/quoa5Y29bszK7v/hyi5Yw4Jl8eQeiLQJQUfOSC8Cg3heXNj+v/MRtkGHV J+aqd0BFnrsDOjiQzUlEVr/YsaJ0QBp6mKvcjoYU1FC3Y+jkzROhViu8C7cETs7fP0W6 8SBCFXCuaK5uv3ssWvwSnRMHbgMLKa1Fwe3Y5OluL6xE46lQ3hFMgN29Pyv3d0cYBH+u fzwniJJ85v1nEDD9WprcQ+Feh17RpzFBrj5VmVvAWrWBhX5rWC7nH+/wMsGp+V/v25dJ zNk3aQMzn/kLTIQfZorItwMJs2u7T2Kb3/NSuu6SDebwQQqzOO4Q2SYztnSPsYuoa1jJ K5EA== X-Gm-Message-State: AO0yUKWhBLeXOTtnuzXq0/Ik9LvfSCpjXh71Xey7lf6JWgZN+EIiNTKD hqSzImIwZSxkj0FP7IvbTGSMZiSkXL//fYh4 X-Received: by 2002:a7b:ce11:0:b0:3dc:5e16:37ea with SMTP id m17-20020a7bce11000000b003dc5e1637eamr10559000wmc.30.1675446273359; Fri, 03 Feb 2023 09:44:33 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z1-20020a5d4c81000000b002bdd8f12effsm2443528wrs.30.2023.02.03.09.44.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:44:33 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: daniel.lezcano@linaro.org, linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, "Rafael J. Wysocki" , Zhang Rui , Len Brown , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 01/11] thermal/acpi: Remove the intermediate acpi_thermal_trip structure Date: Fri, 3 Feb 2023 18:44:19 +0100 Message-Id: <20230203174429.3375691-2-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203174429.3375691-1-daniel.lezcano@linaro.org> References: <20230203174429.3375691-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756832902080705220?= X-GMAIL-MSGID: =?utf-8?q?1756832902080705220?= The struct acpi_thermal_trips() contains the critical, hot, passive and active trip points structure. In order to use the generic thermal trips which is a simple array, let's move out those fields in the struct acpi_thermal instead of having them encapsulated in an intermediate structure. No functional changes, just simplification of code. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 197 +++++++++++++++++++++-------------------- 1 file changed, 100 insertions(+), 97 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 0b4b844f9d4c..0dbce190cacc 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 */ @@ -271,7 +274,8 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) /* Critical Shutdown */ 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. @@ -279,31 +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) { + + if (tz->critical.flags.valid) { 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; } } } @@ -312,22 +317,22 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) if (flag & ACPI_TRIPS_HOT) { 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) { @@ -339,72 +344,70 @@ 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; @@ -412,50 +415,50 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) break; if (i == 1) - tz->trips.active[0].temperature = celsius_to_deci_kelvin(act); + 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; } @@ -480,12 +483,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"); @@ -522,7 +525,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; @@ -530,7 +533,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; @@ -538,7 +541,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; @@ -546,7 +549,7 @@ static int thermal_get_trip_type(struct thermal_zone_device *thermal, trip--; } - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].flags.valid; i++) { + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->active[i].flags.valid; i++) { if (!trip) { *type = THERMAL_TRIP_ACTIVE; return 0; @@ -566,30 +569,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; } @@ -597,10 +600,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; } @@ -615,9 +618,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; } @@ -655,8 +658,8 @@ 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; @@ -701,16 +704,16 @@ 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; i++) { - handle = tz->trips.passive.devices.handles[i]; + for (i = 0; i < tz->passive.devices.count; i++) { + handle = tz->passive.devices.handles[i]; dev = acpi_fetch_acpi_dev(handle); if (dev != device) continue; @@ -732,12 +735,12 @@ 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++) { - handle = tz->trips.active[i].devices.handles[j]; + for (j = 0; j < tz->active[i].devices.count; j++) { + handle = tz->active[i].devices.handles[j]; dev = acpi_fetch_acpi_dev(handle); if (dev != device) continue; @@ -794,28 +797,29 @@ 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; + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->active[i].flags.valid; i++, trips++); - if (tz->trips.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->polling_frequency * 100); + if (tz->passive.flags.valid) + tz->thermal_zone = + thermal_zone_device_register("acpitz", trips, 0, tz, + &acpi_thermal_zone_ops, NULL, + tz->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); + &acpi_thermal_zone_ops, NULL, + 0, tz->polling_frequency * 100); if (IS_ERR(tz->thermal_zone)) return -ENODEV; @@ -985,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; @@ -1094,20 +1098,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 Fri Feb 3 17:44:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 52589 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp973942wrn; Fri, 3 Feb 2023 09:47:01 -0800 (PST) X-Google-Smtp-Source: AK7set9qnsD77hqNkwYTTwvx2nSbnhbIPnBWsZKpRvt4jSbqDQ37RRrXSQ1244+eK9Y8AZU0NU+S X-Received: by 2002:a05:6a20:3955:b0:be:df22:96ca with SMTP id r21-20020a056a20395500b000bedf2296camr14520191pzg.25.1675446420760; Fri, 03 Feb 2023 09:47:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675446420; cv=none; d=google.com; s=arc-20160816; b=Diptf0CNk8sQ+vUZBDh2ikLi5KAuUjhKYduNpf9LikV3+yG9+4EaW/9boAI/78+Mrq DcGUFkYCOp9Z9WDNLShAT6sOeo4kW06g1GXAn6WCya3akTtqCZjZINkOxfNVdwH2EQtU R40kybMPist+xTaE77/u3QLCLDgWou5Miv3pXcdTojVApujw8d1erV7fcwWvoZ6EQLx+ S7eiFqQkyXuc37juIudx8gjpVO8FK+i6zDJUAZf50em/RR+juPE/Pshaerg2xtz7bQuO XaPOQbpvG/BHfRm0aEAM1MTQDmcI5VqreWbASs99WaIgevT59VO5kpdmGqMGHqIYZPva WObQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QLokg2NHvRs8lyMVKIrJy/BKSUdWDoE+8uppdEp+JpA=; b=zFkX5LbfmWR9RCVp+1HEqvaGS1kZ2KZBLLbDg9cUwGsFxAKQuhm08zQte7hfbtWPlF okCIpCWxPDJ+OfxWxcEJnQ849kAdPLzOsl4gWD86e0BipGyIuMtyOxrlnOLBzV1i5V7G nJEcdmvewwqlPurlZnSJEEYDsTPbsJ0DhWrOvfnUJf1+qS6t8euqjIfCW6KcZkmLBmfU CLf/gUnJLCCUNrPzV5QJch8TW8OQ4b4zfVbQg5jjv5FDzH7xif/R1nso7vAgvLotem9j NMpI1cVSvluz2qX5SRs/A/2DMQpWnazMjJjA2f1YnWDF5PHXQWOws7Js2AHlNT/6hFMe Q6CQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sZRjljkr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e4-20020a63ae44000000b00478c0ebc7c0si3041043pgp.746.2023.02.03.09.46.48; Fri, 03 Feb 2023 09:47:00 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sZRjljkr; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233642AbjBCRon (ORCPT + 99 others); Fri, 3 Feb 2023 12:44:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48074 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233172AbjBCRoi (ORCPT ); Fri, 3 Feb 2023 12:44:38 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 12F457D98A for ; Fri, 3 Feb 2023 09:44:36 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id bt17so2294762wrb.8 for ; Fri, 03 Feb 2023 09:44:35 -0800 (PST) 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=QLokg2NHvRs8lyMVKIrJy/BKSUdWDoE+8uppdEp+JpA=; b=sZRjljkr6bJYeB4OrmFyNTCBRtYs6quMNFi9nqhdgWamo9qgpOnOE6zldkfIpgGpBu esIFInDsT+nubJI71sW8L7ivDzru9kf4QiIUNp5GESU5dzH+MF2lQCLt8bwyo11ErNl6 YtcC4Td0cSmuM0ywDVpeXW7tvy7qIEN4cJsIulhqDbZv0zx450Z3KNmCp3FPUV2aA2yU P8XidWqFHv1qqwd2/qj9AQ8TUsmaTaZUIkHis4dllxUPIy5o2p/kN++kLLkEEcb7RGde PyQyFuCZiawkZORNU21wavgD905PQQCQBVJlep13d3PFjzgt0jENJldfYD3ZHULkkhCO gstQ== 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=QLokg2NHvRs8lyMVKIrJy/BKSUdWDoE+8uppdEp+JpA=; b=jdlJQ3DBUtXohtwFQjQGYoqZ0r5e7OPc4FcVQyoF3kTvI4AWgMNrBozj4JoImBnPVt fNUVKpPmW30VojNm+83DTXhtxm8LWeQ0g8+K+DAPvYlZOlN3TxwXV/NdpMAZdzY0vraw uGj8UPMssAmvHF7XjOmtjHzPt4PAgNd/3/OeFYj8YhUKAMFh3P5TuoA2qtTG3htPpddH Wv44eNn5srYeBnuI9wecHxzI8gbWymtOkGPWffMbEUcqlCqOfgS2uVuz1cJ/nBPk98hS xrG4kRf9PjyMdNR5dosCib9hmd5b84Tm1e1ss8fotef/gkzXctiZOoVkSoE9nRJVXZtl 6Tew== X-Gm-Message-State: AO0yUKWdoSDypNtYBxa5SNP0ktQUqxXcnfSPdat8Z9BAcwjJNlE778lM EFnyw6EN0Xy9cibtk2xr77/kAw== X-Received: by 2002:a05:6000:1005:b0:2c3:be89:7c29 with SMTP id a5-20020a056000100500b002c3be897c29mr4288351wrx.12.1675446274468; Fri, 03 Feb 2023 09:44:34 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z1-20020a5d4c81000000b002bdd8f12effsm2443528wrs.30.2023.02.03.09.44.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:44:34 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: daniel.lezcano@linaro.org, linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, "Rafael J. Wysocki" , Zhang Rui , Len Brown , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 02/11] thermal/acpi: Change to a common acpi_thermal_trip structure Date: Fri, 3 Feb 2023 18:44:20 +0100 Message-Id: <20230203174429.3375691-3-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203174429.3375691-1-daniel.lezcano@linaro.org> References: <20230203174429.3375691-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756832906130964214?= X-GMAIL-MSGID: =?utf-8?q?1756832906130964214?= The acpi trip point definition are very similar whatever their types. Instead of creating a different structure for each trip type, let's define and use a common one. With this change we move a step forward to the generic trip point. No functional changes. 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 0dbce190cacc..e27b0b71fcf8 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 Fri Feb 3 17:44:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 52595 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp974353wrn; Fri, 3 Feb 2023 09:48:03 -0800 (PST) X-Google-Smtp-Source: AK7set8orzEmYR6JnZ4F9XTtgC0w9xKFXcRPCqMZPsnZlXth1do26jwTYWzMEHcUiwbQkznk8Qn8 X-Received: by 2002:a17:902:ecd0:b0:196:8445:56be with SMTP id a16-20020a170902ecd000b00196844556bemr13286300plh.42.1675446483306; Fri, 03 Feb 2023 09:48:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675446483; cv=none; d=google.com; s=arc-20160816; b=MIgGRTikvJv2ZjdMf35dYo/QrTCq9/l56ed5sXw084GonCshp4kjSU2qKAvzg1/r8V AW1KFPqIRink6xLbt3EvwFUMkw8BGJpgPovQkTYcK91awIL0Ay6EIsNe4cyDqBSmkgzd yC48h0uLuO+SYGahxIFpi7thohK96XhSlboYyfX6igWeJ0bZIjUFRF0G0nxRdJ0AA8Qv mLOMGtVlEdsmoxUOE13YiiCP1A44rs9Swqi0EgvyE9adm+AHZf86ajV2mwh0JQls7V6q 4NqFxVNzTwVBNHMAbleT50YscQ7TW+Wzl1pAerpI0R/xWP2tc9c2ZMLpbdEM3pB11+pJ cliA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=3gq0E/YoPxBHVucgVAdwG/B9OSJ+hQO93j4O3hXiF4s=; b=ZRwlJEvUd7H7rBsBCpi4UyA5Yy0PJXqYDIkAG4o9o4bqAJQmC2I8jP/iuup/qhtne8 IBV/i72V/tEsHilbeApnT77OqV/WRBRW+pVHD8nfzzHDXXgBOlKO6LSDHxfQxs+O5yVf U8Xg/ayWpw+muYkH66fR+gl4S2OPLj5b963oDWZowbNBg12rAgFTr09v20JkvVdvu2Yf +99NvlkEcC7OTITe6CJl4p6xdeUWU0bOWZpRhlnlhKw+kJqoyd/TxpRf2QmeTSH1zZn3 I3y8+dztLW9QO9GWLqXJMO+TNpjzSCQM0cIT+99Z/FALSQASYvkimdzD1UXEeB8WPpLJ gFjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EiUgBGFg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bt27-20020a63291b000000b004df3908854dsi3540374pgb.735.2023.02.03.09.47.50; Fri, 03 Feb 2023 09:48:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EiUgBGFg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233700AbjBCRoq (ORCPT + 99 others); Fri, 3 Feb 2023 12:44:46 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233399AbjBCRoj (ORCPT ); Fri, 3 Feb 2023 12:44:39 -0500 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 471229119B for ; Fri, 3 Feb 2023 09:44:37 -0800 (PST) Received: by mail-wr1-x431.google.com with SMTP id r2so5324316wrv.7 for ; Fri, 03 Feb 2023 09:44:37 -0800 (PST) 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=3gq0E/YoPxBHVucgVAdwG/B9OSJ+hQO93j4O3hXiF4s=; b=EiUgBGFg+IZtrkgshrjMw9NhkIw51oabUGEtQG4CGKDSNxdcGtlKaZHYgMyqTzmSCT 2+gH72tKugYjNsPhOTsLpR2UmbqwX3mxFq3R4Gx2CCQ32AGuvYYtDX+huDJ7+Sm/Ke1U RGMWnB7I9Ct4xyauoFNwvdv+uulB3JNgUKX3AG2dQX1m1HsFzKVqv0v8J6Kirl/8JCwi RP72dpcYN17OZp1CW/0+sBn8oWC7n8SKV7h9Ary+GtmiAnq+3WGZD0kFchSnLCdcEqcu iGcsw5QSIhCNkGxhC8Eqvx0clVKC6y6YFm+22lHgO0ZAPdmZzi9w95LevAB/NVg696mZ tKeg== 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=3gq0E/YoPxBHVucgVAdwG/B9OSJ+hQO93j4O3hXiF4s=; b=EgzrGf5bGEGmRA7CUfWYjRli2WTNIlXM94vvnCMcXpEixVJZJOMtUpc+Fqe0T7cf9n 3OZyS2e9ewcPny1E2RjQbWfTRc5MqUWOpVBucHAlqwVDg0PnoZxgtQa8lg+OKG2nuzHe 9dFoVyUomxtbxcpAD3bRDRgQbHkYjFkbL1ZKe9Dx5sJLrbRpBDSZgsFAIQQ3/YRpyRO5 25LYdlk3L1V7gX7I0Qsqmjz15tTOiTkPiXrxZyvXRQ9Sp5UHJZXTj8qCZ/GBRZlY/E7I HY6vV2TBT6ZITuQChQzg9XRbimEmLCZRBvlQzUvadP1obo6fv21zNpR4g+4Hff8GQsyE AkmQ== X-Gm-Message-State: AO0yUKW0CssI76WYY8v/5Lg7V4EclsZq6illgikC4LsDJk14HmqixJbn d8guaUcse+waGm/vXrZdlzi3Pg== X-Received: by 2002:adf:d0cc:0:b0:2bf:e01c:b9d0 with SMTP id z12-20020adfd0cc000000b002bfe01cb9d0mr9257756wrh.13.1675446275662; Fri, 03 Feb 2023 09:44:35 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z1-20020a5d4c81000000b002bdd8f12effsm2443528wrs.30.2023.02.03.09.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:44:35 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: daniel.lezcano@linaro.org, linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, "Rafael J. Wysocki" , Zhang Rui , Len Brown , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 03/11] thermal/acpi: Convert the acpi thermal trips to an array Date: Fri, 3 Feb 2023 18:44:21 +0100 Message-Id: <20230203174429.3375691-4-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203174429.3375691-1-daniel.lezcano@linaro.org> References: <20230203174429.3375691-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756832971496047036?= X-GMAIL-MSGID: =?utf-8?q?1756832971496047036?= Instead of having multiple trip points in the structure fields for each trip type, let's create an array of trip points. No functional changes. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 130 ++++++++++++++++++++++------------------- 1 file changed, 69 insertions(+), 61 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index e27b0b71fcf8..6b07de78c4c6 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; @@ -251,7 +258,7 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) /* Critical Shutdown */ 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 @@ -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) { + if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) { 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; } } } @@ -294,22 +301,22 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) if (flag & ACPI_TRIPS_HOT) { 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) { @@ -321,53 +328,53 @@ 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"); } @@ -460,9 +467,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; @@ -502,7 +509,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; @@ -510,7 +517,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; @@ -518,7 +525,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; @@ -546,30 +553,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; } @@ -595,9 +602,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; } @@ -635,8 +642,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; @@ -681,16 +689,16 @@ 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; i++) { - handle = tz->passive.devices.handles[i]; + for (i = 0; i < tz->trips[ACPI_THERMAL_TRIP_PASSIVE].devices.count; i++) { + handle = tz->trips[ACPI_THERMAL_TRIP_PASSIVE].devices.handles[i]; dev = acpi_fetch_acpi_dev(handle); if (dev != device) continue; @@ -774,23 +782,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 +974,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 Fri Feb 3 17:44:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 52590 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp973998wrn; Fri, 3 Feb 2023 09:47:08 -0800 (PST) X-Google-Smtp-Source: AK7set+CaY/VGmawNAKNa/uWh3zUwdpUN5UpDLXIT/HFUS5LdiUJF3UEWHqIYDop4V6jLcODlyHD X-Received: by 2002:a05:6a21:9009:b0:bf:1143:818 with SMTP id tq9-20020a056a21900900b000bf11430818mr9197958pzb.52.1675446427762; Fri, 03 Feb 2023 09:47:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675446427; cv=none; d=google.com; s=arc-20160816; b=v1sc+OMaOQXSfKb3MtfFUZnRmq6BREKCnzceF59e84jnWqwwUYBi3KJCZGlJKo+o99 kVMHbQwINPYShYcYwn08W319KXiGxr3qFyDfDdL8cewKcQ5d6PWfWsFB0s6gZPebsHwH PJGud5uv9lzovWHjMr7xl9Da29tCaUQLr/wz6d1d1nwj5GtUIA05EbgwUca6jW77w0aP PJpjkP14Fz79mBwe9gvSNrnXVdRG51eKSoDmaOsHmvu3KwfCFoUADnX8vnh4JudEf3xj rCA4E433pJUabmycVZuqNFmVj2HkUawjBka0Dkar5Skrz/epwXGSN7t7uj7OYKqA/4BP u59A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=dvG3PRWH913fhYfH6droRPy4T3voXfu7htf9rVkWrmY=; b=EwwhPKSZnYHDnFteeJCHHqfpVqgdqZB4yFNEat6r33PxWkMk088tKrD2QOjSD5qMBE 7MMq9L+YhanEfQiyvsddvJVz42nRXxU04ZbN4EXfsqkASU4bOcP/qIStr3We0DSZ7J2N YQ/5VUEtI2veqOI2JUOaPmlE/zNcHrcfr4jXY6NQkShTTJJWQr7Yxa/BTpL7r6LeqmEn ZoGy5TZox+GvEnp4Nd3coP115pS6eqZefqspSqT9tLpri/j+hNRiG48yN7KAXsFU+qG7 26aZUmtwrg9QawkfKE5rhNfL1mJZtoEL7gty4HF67wfCGmVzGdTlECWjFg9+5DPwuqB5 dD5g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qwNlPSp1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a184-20020a6390c1000000b004f27761a9f2si3356843pge.123.2023.02.03.09.46.55; Fri, 03 Feb 2023 09:47:07 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qwNlPSp1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233399AbjBCRos (ORCPT + 99 others); Fri, 3 Feb 2023 12:44:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233482AbjBCRok (ORCPT ); Fri, 3 Feb 2023 12:44:40 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5584E6DFC3 for ; Fri, 3 Feb 2023 09:44:38 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id h12so5318208wrv.10 for ; Fri, 03 Feb 2023 09:44:38 -0800 (PST) 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=dvG3PRWH913fhYfH6droRPy4T3voXfu7htf9rVkWrmY=; b=qwNlPSp1MnZRQDOzdvzYvscwlJf/fPN9pAI2O8lFIa3Afq0jZDw8I4kT7BJUuQxbHq AjJOO+MkoJCEeYs7T3bye/AAX0bBBi2JFJYOTjHXK15vdfDohAjdBeA7iC/DVIzI8hAL iYet/5hpYBv2KbrI3y4GB4ty95bAo2zJegAWkicQFeN2Q++hqIKf6LMyWhcKPyHHXGUq EWhGLwO7h1AxG+PMzjwg+UzqVkyNleK5rNS9HNpzl6axS7TFiHDz8+7WASq691E4FotA UYfuJSLUYPMNBqWK+Qo+66J8q6HYlimuOMMS+VZl5yfHoP00ogau7hn+DhIKFOoLyQiC zOcQ== 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=dvG3PRWH913fhYfH6droRPy4T3voXfu7htf9rVkWrmY=; b=0cpIs0BQJ+PDA4M9nnDlSbMJFGu8/PcoxxIm+UQICgTWTNAw1hlKXpTTDHG0ESfi7d JkpqpKL+bsT5XAxtuzDUeYCzu7naHNRKYdbRotewO/LFXNVXQsKuxnkx/jf/lVNbXdHF hy7wBplzFIbDmTAWGtkJYNO2fRNPNVGeLlLt0dGQCiNWqVA6tYEiTYi42I/KHMrTmxNg Hjeunzme+Q5tm9Q7lFNO9kX3cTECVc0eAx/OHXrWzceBcQ3VvmoxaQYBLZ/uKpETRKn2 HGjBW5fdmw8KC/r761N52PDPM2+SURisO+oHYe1uSvXSB1j4Z/320DT5/tlUukvdkeR4 YmMg== X-Gm-Message-State: AO0yUKUqzBv3O4tcVjX3k3u9ser+b22jvKX2N9y5lWIqWC7UyV1rSR8q nHsU2ykjMSIQxe2c/eOnm/Vh8w== X-Received: by 2002:a5d:6501:0:b0:2c2:de2b:e7cd with SMTP id x1-20020a5d6501000000b002c2de2be7cdmr11285651wru.50.1675446276812; Fri, 03 Feb 2023 09:44:36 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z1-20020a5d4c81000000b002bdd8f12effsm2443528wrs.30.2023.02.03.09.44.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:44:36 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: daniel.lezcano@linaro.org, linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, "Rafael J. Wysocki" , Zhang Rui , Len Brown , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 04/11] thermal/acpi: Move the active trip points to the same array Date: Fri, 3 Feb 2023 18:44:22 +0100 Message-Id: <20230203174429.3375691-5-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203174429.3375691-1-daniel.lezcano@linaro.org> References: <20230203174429.3375691-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756832913781272084?= X-GMAIL-MSGID: =?utf-8?q?1756832913781272084?= 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 | 71 +++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 36 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 6b07de78c4c6..903f0e3d95f5 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 */ @@ -379,19 +378,19 @@ 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; @@ -399,50 +398,50 @@ static int acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) break; if (i == 1) - tz->active[0].temperature = celsius_to_deci_kelvin(act); + 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; } @@ -471,8 +470,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"); @@ -533,7 +532,7 @@ 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 = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips[i].flags.valid; i++) { if (!trip) { *type = THERMAL_TRIP_ACTIVE; return 0; @@ -583,11 +582,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,13 +718,13 @@ 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++) { - handle = tz->active[i].devices.handles[j]; + for (j = 0; j < tz->trips[i].devices.count; j++) { + handle = tz->trips[i].devices.handles[j]; dev = acpi_fetch_acpi_dev(handle); if (dev != device) continue; @@ -791,7 +790,7 @@ 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; + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips[i].flags.valid; i++, trips++); if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) @@ -1082,20 +1081,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 Fri Feb 3 17:44:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 52601 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp978262wrn; Fri, 3 Feb 2023 09:58:16 -0800 (PST) X-Google-Smtp-Source: AK7set+BfPz1g7EwcZ5llbfqYBEOr/Kaj2AB3rWLUyiezQFiOfEbu8ZiUnHAoftt1fN6FiW5UlZi X-Received: by 2002:a17:903:110f:b0:196:89c9:20f4 with SMTP id n15-20020a170903110f00b0019689c920f4mr13228008plh.7.1675447095673; Fri, 03 Feb 2023 09:58:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675447095; cv=none; d=google.com; s=arc-20160816; b=Rz+CdI6mF1QX6quf64uhRbJbWzY75b+HaKp5tZ/dZyUT9duKpUqp/Zf2oxlS7KlCX+ sgWILRdV4JKTrfA3ymyUlXAyx7BNdJVuSgaZfjSK2qpWBe62OgSvFbphvzwjDsIO2XXs NxfDBrXjQ2AAFxxd8JRh37jbO+ZgYM28JE6zGzm7OZJUdlwQA+P0Dxv+YPv8M63hao0J OxAXdlMwkM4FSV31bt/iJIJ3v3lkx6L/47O05XX0FQgkr8kzDqFUuIHLPBDfQX7OgBBi lLON6ZWZe1buAR4D0AcjHYQZ9JGNXBY98yVOvCAIaDkykCXNXE0E4sZyL/MF/c0GGxGI EW2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=ImiRnspQldFz7aUHwWWQjNaQE6HDsbMFrGvzaxyK5ic=; b=gvE8k4VsjhxnLF0BXKxqosdqQ6WfQGclOQpkF1aMmmGs55+YU0IBY2lqHhwU096JWi 2OJs0Mp8AQuOtKHo2kRmezPQJT4BRUvSj4XQcQ1uoxBaW+m/ZadulkWuljnHEE6iCGfU TTkpHL23SY9npPJ9sVFyHsvYZTyrA1cmCwMW4jUrbXxtMckAeC9lZWrUawTbuTOKYaKv Q7sBZJhAoYadv/pUHOqr6/vV7IVrEvRSS0/NNXM+qzsjbRtojJoQKAhsE8hk/VuizitT POY90XntJfjTUsqtyhB5x1zocJx5EzZ04CdhWi8LoocROZs/EKiJkvBbAzYxNzHrMEcA BBwg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TsvIRqby; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h13-20020a170902f7cd00b00189ccadd447si2707533plw.101.2023.02.03.09.58.02; Fri, 03 Feb 2023 09:58:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=TsvIRqby; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233747AbjBCRvx (ORCPT + 99 others); Fri, 3 Feb 2023 12:51:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233548AbjBCRvh (ORCPT ); Fri, 3 Feb 2023 12:51:37 -0500 Received: from mail-ed1-x52f.google.com (mail-ed1-x52f.google.com [IPv6:2a00:1450:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3B7462713 for ; Fri, 3 Feb 2023 09:51:34 -0800 (PST) Received: by mail-ed1-x52f.google.com with SMTP id z11so5953560ede.1 for ; Fri, 03 Feb 2023 09:51:34 -0800 (PST) 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=ImiRnspQldFz7aUHwWWQjNaQE6HDsbMFrGvzaxyK5ic=; b=TsvIRqby7Oz8eG1DHfd++shiHsmPHIh06ieKcJEAFrbgyAN3mVLH1IZrTA7AtgxtJC m85VH4bkWFZVKrlBC3Ml39ZbV0PQvUS9hbNeett0FCjNZ4uVnFrX6cb9JQ2C+d8Vdr+Q Yvyx9iUO6tH3apNERAoefugBdBieK1HWn3/IM2duyWtxe3DAYRRm5N/B0THNk7jLjuOR H4nAdZIpHTGeuOmZP9DTnvWgmT3RAW0/yl93pRC6sGfoMBs0VX/KSb7m3+dtuZidxQY6 TBWsJ1jl4ti7WGYPWJGGHvT/NbqqsR+mOSMPfOvbSVhugLPuOZuGd1fCkkYUc6kGEJRb 7s4A== 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=ImiRnspQldFz7aUHwWWQjNaQE6HDsbMFrGvzaxyK5ic=; b=KuhrOOKMnHSFbV+wZWK8n+70I/ArR0VQ8m9rfHIJFRlD6eg8xMa6qdK9NQ9Zhr3T/Y WSteuGHkgqTNdNeNZsRPYzMtJjdDYj61QbEYK109PdRrWZfYiSqOyUJScnxnGDbgYgpu sjm7COXeb8dkgqy/h9Pox8kfN3MqkxjTFIFOCZUEDj1HvXTgktx7Qyq/G5KHQ+AXLJKP tpMRY8Dvbmq9xqvp99ulLKqCfeDj2W+RFmfO6p0mWxUQKxYE1ip9Ts/XVTnbX56nXXoW iqMx7rRkBsEVMBoKdpa+rdi+jpbqrwywQLDEUeImtVl3SokMs21G2JK80AZXV8fmuTWS Tx1g== X-Gm-Message-State: AO0yUKU8+XaDYKcfsiYGYepT36rwXt7gxBaiRciRqil2EBdL8Os25lwG i/u/ckxhzEYw4HpAcIfOOWu19Skay7HoMO+L X-Received: by 2002:a5d:5949:0:b0:2bf:9582:1378 with SMTP id e9-20020a5d5949000000b002bf95821378mr9589419wri.37.1675446277891; Fri, 03 Feb 2023 09:44:37 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z1-20020a5d4c81000000b002bdd8f12effsm2443528wrs.30.2023.02.03.09.44.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:44:37 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: daniel.lezcano@linaro.org, linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, "Rafael J. Wysocki" , Zhang Rui , Len Brown , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 05/11] thermal/acpi: Optimize get_trip_points() Date: Fri, 3 Feb 2023 18:44:23 +0100 Message-Id: <20230203174429.3375691-6-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203174429.3375691-1-daniel.lezcano@linaro.org> References: <20230203174429.3375691-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756833613898305625?= X-GMAIL-MSGID: =?utf-8?q?1756833613898305625?= 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 903f0e3d95f5..c4fd583fbf5c 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -461,23 +461,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 Fri Feb 3 17:44:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 52591 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp974050wrn; Fri, 3 Feb 2023 09:47:15 -0800 (PST) X-Google-Smtp-Source: AK7set81oYa94OUnJZfrMGADOMdf0PHTXtqTEg2bql5irO+UarxHnlvzaq5b5+cPsPfxELEI8k5j X-Received: by 2002:a17:90b:4a4c:b0:226:c196:db55 with SMTP id lb12-20020a17090b4a4c00b00226c196db55mr11312156pjb.18.1675446435154; Fri, 03 Feb 2023 09:47:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675446435; cv=none; d=google.com; s=arc-20160816; b=Qi6iwEI2bHZM6JTCQHLy/QyG1ITWEFxk43iHss+e7x5N870uDN24F6WLlRqTD1GGMT ZZO+INxWMAQGDD4zaKju+rPAoDY1enzkObOp/TAybrfvCfz2hg4TU7Nb9QxcJqQ1j7aL 3e6jRudCwxwsMT8aSDyt8Yv9Xlvq82Ex5ZiMgn0KnQTaVhYYE47nUF6TY5io8zKfuj+T H9ACgyIXmDqzd2lhJw0nyMzf/p9bgU1Ws55u6wz08jTw7lZrjShU51RHvnv3CMRIboXf qh9iUhPI2e9I4wbTXdQAzpY/ujTnMJtVfzDCylL5MrfUaFIbYExQEGkPKGyLQ8W83fQU B/NA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Za8uPsw5SSvV8WX2HiDt+VQyx2NN7X9xXkrZzQ/66K8=; b=IaULLVOs5u9HjhikvkZuIsBd4ClLgxXK17XlwTcaOLAQjcvubjHDgtjnY1rZihZZzY 9VJiAIzGmcG1VTk4sZHXB3V4P3RiMBUqBkjMQUaY0+qP0gbOKQ9TxaJpGNKSzjodLJSb 0z4e5KMtu9iPAcy6MX2rJG9nXzyxSlCapZ1QNt1k1+HMmca12Xowid104gULXQyN0w71 TkkY1OmSUqZp6YLjRQaeHYBY5Pn/9xd9RWMW2+CmtTWDtJffRh56R7MXaEYFoB3/Ryf0 TVB6GRa1p2PQg5YuFxbPDXiRc06jZul+0qq4dI58pfJTyihcsej+Si7sO8ENlYug+YPq J1iA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Y0BpwNoF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s7-20020a17090aa10700b002298dbf7be1si7922005pjp.90.2023.02.03.09.47.01; Fri, 03 Feb 2023 09:47:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Y0BpwNoF; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233733AbjBCRpA (ORCPT + 99 others); Fri, 3 Feb 2023 12:45:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233492AbjBCRon (ORCPT ); Fri, 3 Feb 2023 12:44:43 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1BD979609 for ; Fri, 3 Feb 2023 09:44:40 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id ba1so1267705wrb.5 for ; Fri, 03 Feb 2023 09:44:40 -0800 (PST) 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=Za8uPsw5SSvV8WX2HiDt+VQyx2NN7X9xXkrZzQ/66K8=; b=Y0BpwNoFg1Yst7n0lERp8nuJl2HJZTQZQ9zMTMXzLiAw44A1jdf7fp8FkJ5CjAMCge gxLKA0sTVyo5A7NBJgCZNWxdwmRNgvSoSO/XGwPpnwQzHDIdPsgWyYDq6UGGAEpMEvaP 1umiZzO7PrR/fCpQOybQd6zbiX1wvjsKzRZTV0DU2jqo9dg//sseJJ/v6Lq5kBv8Hi9u miH2GTVjXJ2g3+vExVQYZbIM0vDCW1Msfbyc9SS016wWm8VCkUpvQc1mQ2mX/4L4bawE BWA0GvPfaGlkRY2OjgzY3Z4SAcMfieifO/3k8HbgladkMPcly4zIOO/nljtU60pzTu9x iE6w== 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=Za8uPsw5SSvV8WX2HiDt+VQyx2NN7X9xXkrZzQ/66K8=; b=T8lwG5QbTRKN2IE/vJH3EVqEQ3pfhG6TzoqkfuoJF2ZOKtCyVJN3Vt/5KW/ckeStj1 wmssV/K9bKv9PCZG22F4A7JoJqTcI0pYQFtD+svMjLdFs4krxOw7iDpdy1lV1gTcPOFQ +r/0OneWIGiq/BOGQqM9EqU0DwGRTcTES+Tiqxxas9tjOsbYCOS5WIdTCwAxedIQxC/g SAY2DHiZhu1sPuFnDeN5M8RGMSpKVtkq5Q+3wZUk31JCU+Ry+4KZsNBvq+A/nS7Rex/G koJuZJTWWHl/JJviLi7PxiFn6kNoMC1xGFSv1c5hIJ88mB0Ej0GLuRMnf8B11MqUbCFF HBmA== X-Gm-Message-State: AO0yUKWB2O9/TJMmf0v1HCpcP6y7wimYzETGTrvCl8bpBrzUMqymBHF3 cMBcaLP6js5aHSrNjxeoWH7ITw== X-Received: by 2002:adf:c754:0:b0:2bf:e533:3158 with SMTP id b20-20020adfc754000000b002bfe5333158mr10328604wrh.20.1675446279253; Fri, 03 Feb 2023 09:44:39 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z1-20020a5d4c81000000b002bdd8f12effsm2443528wrs.30.2023.02.03.09.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:44:38 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: daniel.lezcano@linaro.org, linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, "Rafael J. Wysocki" , Zhang Rui , Len Brown , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 06/11] thermal/acpi: Encapsulate in functions the trip initialization Date: Fri, 3 Feb 2023 18:44:24 +0100 Message-Id: <20230203174429.3375691-7-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203174429.3375691-1-daniel.lezcano@linaro.org> References: <20230203174429.3375691-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756832920920836267?= X-GMAIL-MSGID: =?utf-8?q?1756832920920836267?= The thermal trip update function is a bit difficult to read, it is very long and has everything put in there to initialize the trip points. In order to improve its readability, let's encapuslate the different parts into dedicated functions. So we can act individually per trip type changes and will make easier to review the next changes. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 257 ++++++++++++++++++++++++----------------- 1 file changed, 154 insertions(+), 103 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index c4fd583fbf5c..a3a8130c955f 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -246,113 +246,120 @@ 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; + 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, "_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); + 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].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) { - 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); + } 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); + /* + * 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; - } + 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; + 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", @@ -372,12 +379,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"); } - /* 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; @@ -445,17 +463,50 @@ 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 Fri Feb 3 17:44:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 52596 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp974452wrn; Fri, 3 Feb 2023 09:48:19 -0800 (PST) X-Google-Smtp-Source: AK7set/cedxjVh4yUgszCZj5jh0fFo8h8NHRk/55Q+iHx/VZT7DCZgRiGMfnK2dV5aYUYXfmkNxI X-Received: by 2002:aa7:8e89:0:b0:593:b021:7d42 with SMTP id a9-20020aa78e89000000b00593b0217d42mr11640884pfr.6.1675446499630; Fri, 03 Feb 2023 09:48:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675446499; cv=none; d=google.com; s=arc-20160816; b=OsWLWcKeB+k/300iSn2erC0C70xUQhbwPXmZx54RK+F65kY1vLyWIn7+7juf2bWBCf d+VWm5a9Mxg1HhyHCXItAHCSDIzj2SsBhaUNutiLLXNx1w78j8ak8DFXungbQUxPI2tq QPigQPM2n0+PCEH2ZS2JahV+fj5FObJPEOUQJGi2IqCtAKJeiMKL1hlTTGWExfQLdhbO 6QZztfhBcYVQdk/1JYlG8Yc6QSjVO0h/LzJJ2RCHMO9cjdXdOZy179yhIQOqDWW4VJTz 0064NmiuRfvVhfogjZ1mUmOUZ8DqK2Hlk1V9Q2i3cq4+KRXn2Jwb3MWFppAVM+GK7ZhO fSZw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=W0WMeqO1vZNLVskDd96ga8DPKCx7MU4pvjHfg5TCNV4=; b=b43dtbyHVmWhg6+fWQedKClca6Yl6jAapr8aI/EMSWvv6NYW6sTmeVqhUhOoUme5Hu ToCPXc/b/vj9phnHVrGWVXOlUMXClEPoUrckaNTEC041iOZixa4MIpBMjdov1zl0/J1h VXZdJKLIdFrh/B3TvoKs3SSNiHcpqf3X1pmLLT8QYpYTYzcAUQ8hhHM9k6C+TvWhA5+U sh8miWn3adjWWINWXmSwQX7+3tWoG6A/cK2CfwsUYmKo2qDjgFwtflyCuvCxjQ5jM/C7 wjJpuj6SREI67JAHzgfTSUlMvAT2X7yIYJ/6K4A+pas4usuH3eSD20Z1PDrWT6YWsygo WhSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eDdQGU+o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b129-20020a621b87000000b005827af240basi2949132pfb.289.2023.02.03.09.48.07; Fri, 03 Feb 2023 09:48:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eDdQGU+o; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233106AbjBCRpD (ORCPT + 99 others); Fri, 3 Feb 2023 12:45:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233734AbjBCRoy (ORCPT ); Fri, 3 Feb 2023 12:44:54 -0500 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F990A6B97 for ; Fri, 3 Feb 2023 09:44:42 -0800 (PST) Received: by mail-wr1-x42d.google.com with SMTP id m14so5297561wrg.13 for ; Fri, 03 Feb 2023 09:44:42 -0800 (PST) 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=W0WMeqO1vZNLVskDd96ga8DPKCx7MU4pvjHfg5TCNV4=; b=eDdQGU+o+vQBj916o88d/DuKFcRUq1sVlFHxSPl+uAEDmb/AbcpCoUSEbz/4e5P9jg 2X9+igApY6B6gHQ4RsKf6WQPYg730TJw9eCrZ5o+ZaJrTLiONzrGZz8U4T4JKFLe0FOY lWEHvR03BaPUo9aa8fRHBLYvgpu9MSPIiWbxakQXKtDR+id+CrCTf1zRdgEi60iAwtP8 J2p3oEsCfWg/56/y/5/w/2cg0N9KNDEgNuUgdFpneLcqkM/i1LMBDFcc0l/UMEh4itAD gtsmBZ/InnJundV9aXm5lZAyKjWMWMESV58rhonGg1HvnM1noBVCyWuIOsgGih9NHBNk 478A== 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=W0WMeqO1vZNLVskDd96ga8DPKCx7MU4pvjHfg5TCNV4=; b=NPjt05BtLwHHK2Q5FdpDWDsWP5UItexzfXvaN2TpvlyEP3gpKLbcK524tvMO3OjcDA HDS5WUeZWJuG5ATTktCo9/cF++LKqK5lOcsPFCDO891Y76JWbnSvhjm+SLvRmq7nQc4N KHvCHLQl4NNT7eZ2oCd8QjFkSeXPtCbtVAjtEf/IbAZdpuQZNUuMBQl+ZflELU20mGiw BlJZ2/7vGDn+HaGK0uo2zdJPBcEauf1JORXoKNYlh9TELPKEQKyQaJezdYvK2zJEdN4c 7l8l9BNTEUqbd/6u3AO3B2c1/brlLBne/gO/zsi5DIZ4anxTO2kn1RQXliOOpc2fbKGh LoFw== X-Gm-Message-State: AO0yUKXxj2ORroMt4Fi79qkVNaUii6mfmIdMNFHvt38fPpNJHwzszmGK YoqG4JQ5l3GBAfqCklomZB3HjPZEcwfLiCYz X-Received: by 2002:adf:e9c3:0:b0:2bb:eb3d:8d20 with SMTP id l3-20020adfe9c3000000b002bbeb3d8d20mr8795450wrn.43.1675446280703; Fri, 03 Feb 2023 09:44:40 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z1-20020a5d4c81000000b002bdd8f12effsm2443528wrs.30.2023.02.03.09.44.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:44:40 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: daniel.lezcano@linaro.org, linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, "Rafael J. Wysocki" , Zhang Rui , Len Brown , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 07/11] thermal/acpi: Simplifify the condition check Date: Fri, 3 Feb 2023 18:44:25 +0100 Message-Id: <20230203174429.3375691-8-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203174429.3375691-1-daniel.lezcano@linaro.org> References: <20230203174429.3375691-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756832988947774187?= X-GMAIL-MSGID: =?utf-8?q?1756832988947774187?= 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 as it is unchanged. 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 a3a8130c955f..c7c2b3d63e90 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -321,6 +321,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) { @@ -398,13 +401,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)) { @@ -436,7 +442,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); @@ -455,6 +461,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"); @@ -495,8 +502,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 Fri Feb 3 17:44:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 52593 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp974165wrn; Fri, 3 Feb 2023 09:47:35 -0800 (PST) X-Google-Smtp-Source: AK7set+Aa/kxHhK68WZ9X1FD454GBAsM4nXjtHgPhi5gXVFH04ANm+YXIxkycAEelmQ3Tkn9/ObB X-Received: by 2002:a05:6a00:23d5:b0:58d:be61:4859 with SMTP id g21-20020a056a0023d500b0058dbe614859mr13005697pfc.11.1675446455105; Fri, 03 Feb 2023 09:47:35 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675446455; cv=none; d=google.com; s=arc-20160816; b=M+2wb/Vv0PtOp35ew9Bvi2uc5E0KHv824UxJxXYZyT3Lck9w1lwnpbEVF/rGVi9PR/ 9Yub4dllJjzZATMbttXBtQEjyN+5haRT8VKDnadYKUVbp2K8j//Rhc4mRv1VeDGEOC3y bTi8PaXeKKu1FMx0otkKCKsX8LIRQL/eb9iVs5oARTdULlH6Fltu07rWehfes1JemWXS ugqFYRvgPDgrgLkZ6KHWYt3JNHFMM5mz7DY3dfXblTGNmWuNkKiVOk91GnFPhJJIquET eahet/YqgcYUse4vP94ZQNxyJz4FUyevCwHV0i3z7zJqoDFH6BEb+KiLU2kCc9xfxt45 TZTg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=n5nHHSh5TfhObVB27BdAlj0+jr/HbFgiMaA9A4Ts7wk=; b=qaNtA8joD29icyWNVZ7ogXFX6LTa7NrJIn7bxpDvC0iuYv5t+wOPI34XY11X3olD36 TCMnmcGF526YJfEitsKxjZWBuJ6m/hyrHZCLMaopb8h2s2jLStE4q4PLa5Yw0ZL08FHt BUy1T/p4Y499QXwoHwqbgE1CpUIU2PJATAOSeGABIKnhqref80coE5y7k8d5nak3cZ6M 3zderr1t5qfLvGVfJ+KKEKkIwUaoUtJv39huNnzJRpitxi5PcWjTDeYq9Q8a2boDXOig XNC1032hoU2mwlAP3yrQNOEY8fAk8B3jhCHk5Ujdk+wyM5hd0efLjXLfUGjn/IIGZ135 Hi4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q4PvJDbS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o3-20020a656a43000000b004ec10a76885si4104971pgu.721.2023.02.03.09.47.21; Fri, 03 Feb 2023 09:47:35 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=q4PvJDbS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233112AbjBCRpG (ORCPT + 99 others); Fri, 3 Feb 2023 12:45:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48816 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233742AbjBCRoy (ORCPT ); Fri, 3 Feb 2023 12:44:54 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E87FA77A7 for ; Fri, 3 Feb 2023 09:44:43 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id j25so1798511wrc.4 for ; Fri, 03 Feb 2023 09:44:43 -0800 (PST) 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=n5nHHSh5TfhObVB27BdAlj0+jr/HbFgiMaA9A4Ts7wk=; b=q4PvJDbS4h+Vm7gtjuSp5SfPDEZs2aQMuhxNgiB/QpLhxxaioTTfwl0SX91tfglgI9 5Sj7bUM0UQV+cRRaX6RrFna0Q+1XQ1pGkTJ2j5Kg3MRAv4bznBi+0zlDbR29UpvPhroq b6A/NQ0gOPa5sY0yBiNZ6Nc9uGsmpWSUhMSuaLQkzWHHX+itsbknRohXFyv5dx4G+MGn E5xGkKQAdQ3fnByhmnvd3WQT+fJBoqUAb+umBwHFvFKgAySCKf4384E15JtZUW9Nw5KL E+ZWsxI5nf1u/RoPyjD996RNc5VjVxapUiHkHgbIUQFL6uI7AKv5PqbE+d4/+7+22RH6 bwlQ== 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=n5nHHSh5TfhObVB27BdAlj0+jr/HbFgiMaA9A4Ts7wk=; b=vmxva71cf8NHr5IM2jffouMBfw5lLdvVi73m1oimIl3n5hxc4wj+8048y8gf79HIv0 i5zjxWzJzzZMfy2HDclh8uTQnUncAiEzhyfBtaPqEG2mgZljXiNTTR4yelOUHMVLN53A 8lGhaeKNsfUDA96tHpNrfR8GksazjihVb/Qo2gExG/zS5zopSnIKASpzMZZfSB07QBib pbVQI6S4wurW1WgmiNVi0jM0qExLACZrIfLMdhr0jn3pygEl/szxqU2GUh97DNKGa8FZ ZPOi1ckaVomdRWfXeWRKUiQkoF5SWGe+9wnAWhks2fjUAdfzPyuWb9bNddL2z+4BWORa jszw== X-Gm-Message-State: AO0yUKXpS6B/LfLFRROj1RubSDNfW/NDngsmi0LpeQeejRX2g1EG0imh iEak2ivlHKMtLSbw2CjGdjA3Gg== X-Received: by 2002:a05:6000:1085:b0:2bf:d511:18a9 with SMTP id y5-20020a056000108500b002bfd51118a9mr9559555wrw.29.1675446281872; Fri, 03 Feb 2023 09:44:41 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z1-20020a5d4c81000000b002bdd8f12effsm2443528wrs.30.2023.02.03.09.44.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:44:41 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: daniel.lezcano@linaro.org, linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, "Rafael J. Wysocki" , Zhang Rui , Len Brown , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 08/11] thermal/acpi: Remove active and enabled flags Date: Fri, 3 Feb 2023 18:44:26 +0100 Message-Id: <20230203174429.3375691-9-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203174429.3375691-1-daniel.lezcano@linaro.org> References: <20230203174429.3375691-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756832942010867407?= X-GMAIL-MSGID: =?utf-8?q?1756832942010867407?= 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 c7c2b3d63e90..316a16ac1a09 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; }; @@ -1138,17 +1136,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 Fri Feb 3 17:44:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 52592 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp974112wrn; Fri, 3 Feb 2023 09:47:23 -0800 (PST) X-Google-Smtp-Source: AK7set/79az7nqojtIyY+SxzAoNsxiygeIzNMsFGfIXM3ejUL31pCJ7iljM7Ozz3iu5bnUwHBA/t X-Received: by 2002:a17:902:f2c5:b0:196:8437:1b38 with SMTP id h5-20020a170902f2c500b0019684371b38mr8949352plc.58.1675446443358; Fri, 03 Feb 2023 09:47:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675446443; cv=none; d=google.com; s=arc-20160816; b=THX1yUFY08GrVNG1HhrzwI/sXt80O7/JHBeZ8/7kU7kyA1ppc50qhPB2Bvrt3xYP2n h1F/b6X2gDps15wzByhYZH50IVPQIoEfzgHBVU9e4AaqzgkOBLqbXD6yVKZ1m8UPYN/G hwsXSooddOSRoT8RcCnVk70BHFpOGwzKxk6oFQ+UR1ROOOiLpBygXYX6WGXOZ/NaeRw1 XRTrP2pGiIc67f5fUvtp2dqfNU4BQb2LW1BWKZ8TQO5JRchIOjpRbZDfcpA6UgNHGcbo zQbFfolPNVKkwOnkDHrVAyB+dU6TOsx1A70oyONYklN24IKe0WgVN2iI2gxLbQfefAJm q3Sg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=QC3Bc1ZBnDqOCsf2GYYuc3UMis7l5JLiGW3gDWAr4Jo=; b=sENMmyqYYPejfREV9mAhDT7Wl+7q6YtnKr7WWQwEJjRqjDksuj4AN6V2K4czqkDxmF GDmGOqpwN9iiK8GFTUsM4EyhUmSRz9BcR6zwetAbd5r4UcPjJXU5jyIP3I8sP8PZUB08 hANF53yGnhbUL78QEy7URvR1Q8oi57Ciwz21YWVcaWAAf2bCajTyUZ2/aBHGH+Z0IzQi U4zo8J0TYFkZmXV3xGGr95GvxaEnh10IRLf5wwCI69AtquQsvyBciWqZBLvrEDekX2h5 pkv/fcmTCCSj6V+NR/KPhWnhzsANHk2xhRXCjoWDeqWl/2Z0o2NoEhlw5qC/d+VDuyQl dA/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pJ732D7w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id w14-20020a637b0e000000b004789ac3a1acsi3467617pgc.207.2023.02.03.09.47.11; Fri, 03 Feb 2023 09:47:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=pJ732D7w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232723AbjBCRpN (ORCPT + 99 others); Fri, 3 Feb 2023 12:45:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233764AbjBCRoy (ORCPT ); Fri, 3 Feb 2023 12:44:54 -0500 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 CACEBAA26A for ; Fri, 3 Feb 2023 09:44:44 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id ba1so1267854wrb.5 for ; Fri, 03 Feb 2023 09:44:44 -0800 (PST) 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=QC3Bc1ZBnDqOCsf2GYYuc3UMis7l5JLiGW3gDWAr4Jo=; b=pJ732D7wxi7dC/ACoJ+N7AadtG+fy3kkhpMKjo9B9q/XI4FbuQcIftbwc4hash+Kh8 FJQzlOrXdWxJAoQDO3uHMZO+Ysk8u/JAffEPVr0qR6BIBiNvnm6yVCSdofBQG6L09+IW Lp82Ix4mezOKOEiUcIwJunT8OQxlYdxQhYraoADpk44ESIM7TBkgGbYg+wjTlFVe3B7d gwSXRGciCB9K6sqxSYjR+CRh1NxqnjyxQphQ9ZWCOwMKG6MKKcNadvMWK35auY8G3M20 KTS1unaRQwFEYJxNuAItC6aNuJ+ugDxvKq7Q7WhgitqURRxXjdv9UI+C/rKH2NiH7gbj CZKg== 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=QC3Bc1ZBnDqOCsf2GYYuc3UMis7l5JLiGW3gDWAr4Jo=; b=RgaU9R/LixuniP+aO6oWOUMgyd1HtVJR4yH34e3CrPHGWub9xe7pCxP+MqJwGKjLuU u/nlj1GmyJBbhoRKR/4c97xCJW5KB0R3DvwcBJLVBKeJk1m7FEQgvj8/DC4q9WJeyJ+Q Sd1vNhcSLjwxYq8Y9sVQTSjg6lXNuFtjee4gXexY6mfNWHkg0//9Gp66oNOb5XQ0CmL0 iooQhNacy1T7rGBc6Gwz54YDizr4SyR+9JHUjwi1QD22mo3Bu58BSe6j8aVReUrQsPvJ UXflsmED/80qKCsed9iyql8c/EOozoZMnf/mTQkpn+DHme9r0UbBa72uGrm84jmpyI2s UhJg== X-Gm-Message-State: AO0yUKW72Pii5d3Ng6IS5VCi6apcmKa4oFtOzOX9hY7zs8QjATWP/NNb +UVuvCfd4mf6/j6zrziiWhG1SA== X-Received: by 2002:adf:f481:0:b0:2bf:f6e6:edde with SMTP id l1-20020adff481000000b002bff6e6eddemr7809306wro.3.1675446283027; Fri, 03 Feb 2023 09:44:43 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z1-20020a5d4c81000000b002bdd8f12effsm2443528wrs.30.2023.02.03.09.44.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:44:42 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: daniel.lezcano@linaro.org, linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, Daniel Lezcano , "Rafael J. Wysocki" , Zhang Rui , Len Brown , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 09/11] thermal/acpi: Convert the units to milli Celsuis Date: Fri, 3 Feb 2023 18:44:27 +0100 Message-Id: <20230203174429.3375691-10-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203174429.3375691-1-daniel.lezcano@linaro.org> References: <20230203174429.3375691-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756832929803168100?= X-GMAIL-MSGID: =?utf-8?q?1756832929803168100?= From: Daniel Lezcano The trip points are storing the temperature using the Deci Kelvin units but the thermal framework expects milli Celsius. In order to migrate to the generic trip points where the temperature unit is millicelsius. Let's change the unit, so the resulting code will be compatible with thermal framework used unit. Signed-off-by: Daniel Lezcano Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 56 ++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 32 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 316a16ac1a09..9122d1c44777 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -177,9 +177,9 @@ static int acpi_thermal_get_temperature(struct acpi_thermal *tz) if (ACPI_FAILURE(status)) return -ENODEV; - tz->temperature = tmp; + tz->temperature = deci_kelvin_to_millicelsius(tmp); - acpi_handle_debug(tz->device->handle, "Temperature is %lu dK\n", + acpi_handle_debug(tz->device->handle, "Temperature is %lu m°C\n", tz->temperature); return 0; @@ -250,7 +250,7 @@ static int acpi_thermal_trips_update_critical(struct acpi_thermal *tz, int flag) unsigned long long tmp; status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp); - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature = tmp; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature = deci_kelvin_to_millicelsius(tmp); /* * Treat freezing temperatures as invalid as well; some * BIOSes return really low values and cause reboots at startup. @@ -261,7 +261,7 @@ static int acpi_thermal_trips_update_critical(struct acpi_thermal *tz, int flag) tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0; acpi_handle_debug(tz->device->handle, "No critical threshold\n"); - } else if (tmp <= 2732) { + } else if (tmp <= 0) { pr_info(FW_BUG "Invalid critical threshold (%llu)\n", tmp); tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid = 0; } else { @@ -274,15 +274,15 @@ static int acpi_thermal_trips_update_critical(struct acpi_thermal *tz, int flag) 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); + crt *= MILLIDEGREE_PER_DEGREE; /* * Allow override critical threshold */ - if (crt_k > tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature) - pr_info("Critical threshold %d C\n", crt); + if (crt > tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature) + pr_info("Critical threshold %d m°C\n", crt); - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature = crt_k; + tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature = crt; } } @@ -325,10 +325,11 @@ static int acpi_thermal_trips_update_passive(struct acpi_thermal *tz, int flag) if (psv == -1) { status = AE_SUPPORT; } else if (psv > 0) { - tmp = celsius_to_deci_kelvin(psv); + tmp = psv * MILLIDEGREE_PER_DEGREE; status = AE_OK; } else { status = acpi_evaluate_integer(tz->device->handle, "_PSV", NULL, &tmp); + tmp = deci_kelvin_to_millicelsius(tmp); } if (ACPI_FAILURE(status)) @@ -411,6 +412,7 @@ static int acpi_thermal_trips_update_active(struct acpi_thermal *tz, int flag) if (flag & ACPI_TRIPS_ACTIVE) { status = acpi_evaluate_integer(tz->device->handle, name, NULL, &tmp); + tmp = deci_kelvin_to_millicelsius(tmp); if (ACPI_FAILURE(status)) { tz->trips[i].flags.valid = 0; if (i == 0) @@ -420,7 +422,7 @@ static int acpi_thermal_trips_update_active(struct acpi_thermal *tz, int flag) break; if (i == 1) - tz->trips[0].temperature = celsius_to_deci_kelvin(act); + tz->trips[0].temperature = act * MILLIDEGREE_PER_DEGREE; else /* * Don't allow override higher than @@ -428,9 +430,9 @@ static int acpi_thermal_trips_update_active(struct acpi_thermal *tz, int flag) */ tz->trips[i - 1].temperature = (tz->trips[i - 2].temperature < - celsius_to_deci_kelvin(act) ? + act * MILLIDEGREE_PER_DEGREE ? tz->trips[i - 2].temperature : - celsius_to_deci_kelvin(act)); + act * MILLIDEGREE_PER_DEGREE); break; } else { @@ -546,8 +548,8 @@ static int thermal_get_temp(struct thermal_zone_device *thermal, int *temp) if (result) return result; - *temp = deci_kelvin_to_millicelsius_with_offset(tz->temperature, - tz->kelvin_offset); + *temp = tz->temperature; + return 0; } @@ -606,9 +608,7 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal, if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) { if (!trip) { - *temp = deci_kelvin_to_millicelsius_with_offset( - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature, - tz->kelvin_offset); + *temp = tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature; return 0; } trip--; @@ -616,9 +616,7 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal, if (tz->trips[ACPI_THERMAL_TRIP_HOT].flags.valid) { if (!trip) { - *temp = deci_kelvin_to_millicelsius_with_offset( - tz->trips[ACPI_THERMAL_TRIP_HOT].temperature, - tz->kelvin_offset); + *temp = tz->trips[ACPI_THERMAL_TRIP_HOT].temperature; return 0; } trip--; @@ -626,9 +624,7 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal, if (tz->trips[ACPI_THERMAL_TRIP_PASSIVE].flags.valid) { if (!trip) { - *temp = deci_kelvin_to_millicelsius_with_offset( - tz->trips[ACPI_THERMAL_TRIP_PASSIVE].temperature, - tz->kelvin_offset); + *temp = tz->trips[ACPI_THERMAL_TRIP_PASSIVE].temperature; return 0; } trip--; @@ -637,9 +633,7 @@ static int thermal_get_trip_temp(struct thermal_zone_device *thermal, 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->trips[i].temperature, - tz->kelvin_offset); + *temp = tz->trips[i].temperature; return 0; } trip--; @@ -654,9 +648,7 @@ static int thermal_get_crit_temp(struct thermal_zone_device *thermal, struct acpi_thermal *tz = thermal->devdata; if (tz->trips[ACPI_THERMAL_TRIP_CRITICAL].flags.valid) { - *temperature = deci_kelvin_to_millicelsius_with_offset( - tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature, - tz->kelvin_offset); + *temperature = tz->trips[ACPI_THERMAL_TRIP_CRITICAL].temperature; return 0; } @@ -675,8 +667,8 @@ static int thermal_get_trend(struct thermal_zone_device *thermal, if (type == THERMAL_TRIP_ACTIVE) { int trip_temp; - int temp = deci_kelvin_to_millicelsius_with_offset( - tz->temperature, tz->kelvin_offset); + int temp = tz->temperature; + if (thermal_get_trip_temp(thermal, trip, &trip_temp)) return -EINVAL; @@ -1090,7 +1082,7 @@ static int acpi_thermal_add(struct acpi_device *device) INIT_WORK(&tz->thermal_check_work, acpi_thermal_check_fn); pr_info("%s [%s] (%ld C)\n", acpi_device_name(device), - acpi_device_bid(device), deci_kelvin_to_celsius(tz->temperature)); + acpi_device_bid(device), tz->temperature); goto end; free_memory: From patchwork Fri Feb 3 17:44:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 52594 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp974224wrn; Fri, 3 Feb 2023 09:47:46 -0800 (PST) X-Google-Smtp-Source: AK7set8yEN/GoDFfkaQs3NeVaBULkmpN8/shuutZczw9THdPx+MEcUBbOE7I9w9v8R4CuBkb2Dd5 X-Received: by 2002:a05:6a20:94c5:b0:bf:997f:354b with SMTP id ht5-20020a056a2094c500b000bf997f354bmr7454080pzb.17.1675446466102; Fri, 03 Feb 2023 09:47:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675446466; cv=none; d=google.com; s=arc-20160816; b=toi9F96fZ23Abvk3VthccSoCwnY9LJsYuPwcCZ1p+3FbUptJBuRm2DZVvoEEKX52jL 7Pvn2X8Ko2yjXQCCqJgPkKAtefHFh8pN9dyyOPlG7eqcbBqZkazJa6qhb//XdXRTw92K 3RFahtlnFHZlM155RA2jUJr6xh/QBQkKdHyTLOK+vLV/FtMqJJvNb06/Cbr43VMJsY5Z Hh0lYkfBkx+WoPHuh1EK5YUvvPEYIzAaqiqzYARO0yJW9fppPQSWnmVcym3oOE1ANlFL BUMYu0ofBZWMtDExYa7qJA9HFQsJSHsUTQoUcfq9cUReHoMd2l8bUrzp//M6tOu/ZRGP lEXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=nCvJ2+qCRMxXy+MMEVuUk39VFz7D4oUUKPSRDhGhsPo=; b=xCPe1DtA2DMBGhi8KWolquG0tU/JDc2XSyQGOWI0ATicxm9YWF8qRoz64gQlt3hUQm EgbBoH2c1b7XngUl8z6MCiF1q5H/nX6F24sKN4OBuC4yIf/jSmYgM8fvR07GwlRbFKas /ENBoihsuC/+scLfTFD7/j+azZ3vA5xIXXfpdFwnTdusTLIjUCsLb6YqbtwfUpzwtwnv 1HdGRCgP+3fXQEYC684gJFZqODnm3TEAxT+m6YbeMnIBnN4kJ5LqNtJHngEo9EmveOFJ /D4I91Q8k/6dJVAGpXMyq21NR82/prsy1OG+MzR9nFKTktSoRrib+1EbAx+qwYmzHbI5 HZSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E+97ESBW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o21-20020a637e55000000b004e13271404csi3372527pgn.697.2023.02.03.09.47.33; Fri, 03 Feb 2023 09:47:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=E+97ESBW; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232503AbjBCRpT (ORCPT + 99 others); Fri, 3 Feb 2023 12:45:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233766AbjBCRoz (ORCPT ); Fri, 3 Feb 2023 12:44:55 -0500 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB070AA27C for ; Fri, 3 Feb 2023 09:44:44 -0800 (PST) Received: by mail-wr1-x435.google.com with SMTP id h12so5318496wrv.10 for ; Fri, 03 Feb 2023 09:44:44 -0800 (PST) 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=nCvJ2+qCRMxXy+MMEVuUk39VFz7D4oUUKPSRDhGhsPo=; b=E+97ESBWZOs108fKz16uQQpPEsJKRiqUPP0jSzNIqq2u9M5Mk0tKU6xTnC5NHxtcwi gHULtHVX6ZfVxhLwVFQVi/sWxMjHBafJob7MeWEQkLdMj902laL9KYlVx3hmbx51LcRl kv9Y6cSIlzZehYQnz4+im37CY9TdjZOMlP4HyR8EYKT/EN4hx4IAjdHsXh91yEJymRUp s9ur1dvzz3AJ9b/4o9gVtSdcfX1ih8MbEHJnlw0dJYa8gwgaqm+iOew80uYvJ9XhQpCa XZA3qRfCdIjeth4ecTF4qe3KdjnIyozAqWx1C7zyLblD1kGUzumKG5xs0uJq9RHQQpsL zQxw== 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=nCvJ2+qCRMxXy+MMEVuUk39VFz7D4oUUKPSRDhGhsPo=; b=C+FOU3ObSyiqrYjdW19KV1SuKso+ybWH0fTtEP5rejkD2PTguAGdTvh20bCgNa2Q/2 q98lDWyj5JgxkfS+/aN7Y2Hbsp2HrJyRr84Smi6Bk6H9uaNFUSdx+uO21t92SJ9eVo9e TWNU7wQKWBbSalb4V+W0iCxvwJQdN11zLI+hKeJAXfsVZlqRBBidZrm8Z9kK5xGTos+b xA7iz8xSNSpcTVGPXCoHNh9QoDKeKbrGNxyel10pCi8EAcswv6vynee+mG9D4naP0yzZ QMY7hSeHvkrAjS8Wg8XqH63VrvQGC4mTMrO2piqB3G8VGGv6+33Dw0iu0Vw5SsZBWSDv fpzQ== X-Gm-Message-State: AO0yUKUM2VoCtDAsFzC9OfE2shF8OkOiXPdbP70guFiQ+7U89u8WhypH IEeIYP1ZP/NoGhpffcyQOBU16w== X-Received: by 2002:a05:6000:1a45:b0:29a:375d:4c41 with SMTP id t5-20020a0560001a4500b0029a375d4c41mr9771982wry.14.1675446284232; Fri, 03 Feb 2023 09:44:44 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z1-20020a5d4c81000000b002bdd8f12effsm2443528wrs.30.2023.02.03.09.44.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:44:43 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: daniel.lezcano@linaro.org, linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, "Rafael J. Wysocki" , Zhang Rui , Len Brown , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 10/11] thermal/acpi: Rewrite the trip point intialization to use the generic thermal trip Date: Fri, 3 Feb 2023 18:44:28 +0100 Message-Id: <20230203174429.3375691-11-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203174429.3375691-1-daniel.lezcano@linaro.org> References: <20230203174429.3375691-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756832954117778877?= X-GMAIL-MSGID: =?utf-8?q?1756832954117778877?= 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. Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 238 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 212 insertions(+), 26 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index 9122d1c44777..f89236cd4fcd 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -153,6 +153,8 @@ struct acpi_thermal { struct acpi_thermal_trip trips[ACPI_THERMAL_TRIP_MAX]; struct acpi_handle_list devices; struct thermal_zone_device *thermal_zone; + struct thermal_trip *_trips; + int num_trips; int kelvin_offset; /* in millidegrees */ struct work_struct thermal_check_work; struct mutex thermal_check_lock; @@ -244,6 +246,198 @@ do { \ "Please report to linux-acpi@vger.kernel.org\n", str); \ } while (0) +static void acpi_thermal_trips_override(struct thermal_trip *trip, int temperature) +{ + if (temperature > trip->temperature) + pr_info("Overriding temperature %d->%d m°C\n", + trip->temperature, temperature); + + trip->temperature = temperature; +} + +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(&trips[*num_trips], crt * MILLI); + + (*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; + 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) +{ + struct acpi_handle_list devices; + 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; + } + + status = acpi_evaluate_reference(tz->device->handle, "_PSL", NULL, &devices); + if (ACPI_FAILURE(status)) { + acpi_handle_debug(tz->device->handle, "No passive device associated\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) +{ + struct acpi_handle_list devices; + acpi_status status; + unsigned long long temp; + int i; + + /* + * Module parameters disable all active trip points + */ + if (act < 0) + return trips; + + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + char name[5]; + + sprintf(name, "_AC%d", i); + + status = acpi_evaluate_integer(tz->device->handle, name, NULL, &temp); + if (ACPI_FAILURE(status)) + break; + + sprintf(name, "_AL%d", i); + + status = acpi_evaluate_reference(tz->device->handle, name, NULL, &devices); + if (ACPI_FAILURE(status)) { + acpi_handle_info(tz->device->handle, "No _AL%d defined for _AC%d\n", i, i); + 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)++; + } + + /* + * We found at least one trip point and we have an override option + */ + if (i && act) { + /* + * Regarding the ACPI specification AC0 is the highest active + * temperature trip point. We will override this one. + */ + acpi_thermal_trips_override(&trips[*num_trips], act * MILLI); + } + + 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; @@ -398,7 +592,7 @@ static int acpi_thermal_trips_update_active(struct acpi_thermal *tz, int flag) int valid = 0; int i; - for (i = ACPI_THERMAL_TRIP_ACTIVE; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; valid = tz->trips[i].flags.valid; @@ -820,35 +1014,20 @@ static struct thermal_zone_device_ops acpi_thermal_zone_ops = { static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) { - 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 = 0; 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", tz->_trips, tz->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", tz->_trips, tz->num_trips, 0, tz, + &acpi_thermal_zone_ops, NULL, + 0, tz->polling_frequency*100); if (IS_ERR(tz->thermal_zone)) return -ENODEV; @@ -1051,8 +1230,8 @@ static void acpi_thermal_check_fn(struct work_struct *work) static int acpi_thermal_add(struct acpi_device *device) { - struct acpi_thermal *tz; - int result; + struct acpi_thermal *tz = NULL; + int result = 0; if (!device) return -EINVAL; @@ -1073,9 +1252,13 @@ static int acpi_thermal_add(struct acpi_device *device) acpi_thermal_guess_offset(tz); + tz->_trips = acpi_thermal_trips_alloc(tz, &tz->num_trips); + if (!tz->_trips) + goto free_trips; + result = acpi_thermal_register_thermal_zone(tz); if (result) - goto free_memory; + goto free_trips; refcount_set(&tz->thermal_check_count, 3); mutex_init(&tz->thermal_check_lock); @@ -1085,6 +1268,8 @@ static int acpi_thermal_add(struct acpi_device *device) acpi_device_bid(device), tz->temperature); goto end; +free_trips: + kfree(tz->_trips); free_memory: kfree(tz); end: @@ -1101,6 +1286,7 @@ static void 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); } From patchwork Fri Feb 3 17:44:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 52599 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp974624wrn; Fri, 3 Feb 2023 09:48:46 -0800 (PST) X-Google-Smtp-Source: AK7set+YfO95iGCZAOFnXK0WRkgNnE6ZP+171eousKwBZ8gqk9xYUI3HLxYnzPosmPE0gyb4+CHZ X-Received: by 2002:a17:90b:1b4a:b0:230:7dd:afc4 with SMTP id nv10-20020a17090b1b4a00b0023007ddafc4mr11533402pjb.35.1675446526149; Fri, 03 Feb 2023 09:48:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675446526; cv=none; d=google.com; s=arc-20160816; b=W8Qzd4/gctk/dT49F4CSaUnwmQREf4oXJDyURQY9VzesUXkgzBqNtU0fXbS/TbFyrt gBbD4OqejHhRQcS/5Ud672mVPEOJ3Q5W/iWvZQP0TeK+GExmPqwqCLyK782e6xpgQpSC SR2tZavWwoNgyLKAMZ2jA9+iOmMNtCOHJ0S3v0SgjB7ZBxpCuTxyE+3uBBHrcddsKhC8 WOP2AK2aXsO+GTHLcpFkHYf8CCbZBpCXDmUUVpxXgaQFiRkoxT0R+ZoNfVhBOR7jeIfL YpZsziSJFdYB9f+HQgLFARSRTtBlbkNUOIxUBYRE3NlPaQbVnkJCKS8ORCoNq1WsGfEH vNAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=m+5C4ydL02isaLKa3zc+GpYQSiiz854VPklETAp2HFU=; b=QXrgTDy9+kUNvboyteq6fQwx2Qq0KS7tNdkFXM3BSbHIkCX3b/S5QppzOH0zu6ZXze vp5/lqb7lQpuJdCPrzXcLMwYsdIJBMRNjXmnu6zomCX/K9wsZRNnuVawhBQmJY0yTNHH 5ZfABV4rKahQsf0GofV08N+96yuYK9pIfuZAfoSZD7Hq74b8E2Uso1WHd0g8cos2E8gX qVmqjztEFjQ2O68PqbZCAD50G9ITuGZiC24hu/VB/im8yvTabIX7lhYQI+NtUxxSACpk MdhD0Tkh9mDk+Dhc9MnY0TRIxAWlVJJN1rlVj/+v1CrbmLauJGoEmRtMQH0NoYCkgwHJ h6cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sG6xh8xQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t2-20020a17090aba8200b0022c6e16b4c0si8390956pjr.157.2023.02.03.09.48.34; Fri, 03 Feb 2023 09:48:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sG6xh8xQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233522AbjBCRpd (ORCPT + 99 others); Fri, 3 Feb 2023 12:45:33 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233372AbjBCRpE (ORCPT ); Fri, 3 Feb 2023 12:45:04 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42A8FA6C3B for ; Fri, 3 Feb 2023 09:44:45 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id h16so5304441wrz.12 for ; Fri, 03 Feb 2023 09:44:45 -0800 (PST) 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=m+5C4ydL02isaLKa3zc+GpYQSiiz854VPklETAp2HFU=; b=sG6xh8xQNejGSuKPUa4k/fJ86szxWvQ9HoNdYvHpioZo5m0dRyM6sTVyyY94whVgv6 N1+sA9Tq1IoCDxCfHehebc2xGyzlY92iQjYq5zxyydxWelux8OI737w5gSXoNGhnDdYC 1cADmm/gMMohMtZgar4AjsoCdYPEy2nkhEMn3x+/dSO3h7U9aNWqUCAqz+tyUEwSos5f OrcBootA7nuW5iqyPB8A0QRDmILWpt5cdql5Dzoi73rt8zP+5aJoYAgxPizkps4OdYzc Xr+JSJ9BLolzO0xmo7UAN5qTnU6GFt91wI9B9b5k0gsxWx7KDGIyzaOi8p5Ifz5qI6Or 0TAA== 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=m+5C4ydL02isaLKa3zc+GpYQSiiz854VPklETAp2HFU=; b=T7Q8qsFfJPNPODOqQqJGp965/en4HXsLBtgV4jx3yz+mah9eU1BRUGYcvZaIznqgY6 nlXWN9wzGgKOa1wmjIYeFX5yMUgtmIJUcGafnjWWkJuO6y0Ym+IUnDI9wvQPe5870m7Y GjD7ilVh4xL34KLjb4IppdNuYNYmsxBBnig+vCjd2DbtL603mjeobbjubX1o/v6yQBM7 U8KIb3idFQ9eFOFYPY2XSCOEA3iMkMlKvAyV7sMfiAMjrioZMWjkigZbArT+Ip8mauKX VJlS2RwM7EU1xy0jHw0rzl0awcD1tBCN505j2MBii2kqztG8pp09JYT1I8Wwejk4rI6n GzDg== X-Gm-Message-State: AO0yUKWqURz0eGjRZ6Ud8jekrBwqnRfwqSIJ2VlrsAvBA/aJs7Bjzy7N vqYI/HbfOTPCFKnqHDfrmFKTQg== X-Received: by 2002:a5d:660f:0:b0:2bf:95cc:744c with SMTP id n15-20020a5d660f000000b002bf95cc744cmr10179895wru.0.1675446285470; Fri, 03 Feb 2023 09:44:45 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z1-20020a5d4c81000000b002bdd8f12effsm2443528wrs.30.2023.02.03.09.44.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:44:45 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: daniel.lezcano@linaro.org, linux-acpi@vger.kernel.org, linux-pm@vger.kernel.org, Daniel Lezcano , "Rafael J. Wysocki" , Zhang Rui , Len Brown , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 11/11] thermal/acpi: Use the thermal framework ACPI API Date: Fri, 3 Feb 2023 18:44:29 +0100 Message-Id: <20230203174429.3375691-12-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203174429.3375691-1-daniel.lezcano@linaro.org> References: <20230203174429.3375691-1-daniel.lezcano@linaro.org> MIME-Version: 1.0 X-Spam-Status: No, score=1.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_SBL_CSS,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Level: * X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756833016829605466?= X-GMAIL-MSGID: =?utf-8?q?1756833016829605466?= From: Daniel Lezcano The thermal framework has a set of functions to fill the trip points. Those functions are already used by the int340x and the quark Intel's platform. Reuse these functions in order to consolidate the generic trip points usage across the thermal ACPI user. Signed-off-by: Daniel Lezcano Signed-off-by: Daniel Lezcano --- drivers/acpi/thermal.c | 85 +++++++++++++++++++----------------------- 1 file changed, 38 insertions(+), 47 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index f89236cd4fcd..5e4d93c67b75 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -259,8 +259,11 @@ static struct thermal_trip *acpi_thermal_trips_alloc_critical(struct acpi_therma struct thermal_trip *trips, int *num_trips) { - acpi_status status = AE_OK; - unsigned long long temp; + struct thermal_trip trip = { + .type = THERMAL_TRIP_CRITICAL, + }; + + int ret; /* * Module parameters disable the critical trip point @@ -268,14 +271,12 @@ static struct thermal_trip *acpi_thermal_trips_alloc_critical(struct acpi_therma 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"); + ret = thermal_acpi_critical_trip_temp(tz->device->handle, &trip.temperature); + if (ret) goto out; - } - - if (temp <= 2732) { - pr_info(FW_BUG "Invalid critical threshold (%llu)\n", temp); + + if (trip.temperature <= 0) { + pr_info(FW_BUG "Invalid critical threshold (%d)\n", trip.temperature); goto out; } @@ -283,10 +284,7 @@ static struct thermal_trip *acpi_thermal_trips_alloc_critical(struct acpi_therma 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; + trips[*num_trips] = trip; /* structure copy */ if (crt > 0) acpi_thermal_trips_override(&trips[*num_trips], crt * MILLI); @@ -300,23 +298,21 @@ static struct thermal_trip *acpi_thermal_trips_alloc_hot(struct acpi_thermal *tz struct thermal_trip *trips, int *num_trips) { - acpi_status status; - unsigned long long temp; + struct thermal_trip trip = { + .type = THERMAL_TRIP_HOT, + }; - status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &temp); - if (ACPI_FAILURE(status)) { - acpi_handle_debug(tz->device->handle, "No hot threshold\n"); + int ret; + + ret = thermal_acpi_hot_trip_temp(tz->device->handle, &trip.temperature); + if (ret) 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; + trips[*num_trips] = trip; /* structure copy */ (*num_trips)++; out: @@ -327,9 +323,12 @@ static struct thermal_trip *acpi_thermal_trips_alloc_passive(struct acpi_thermal struct thermal_trip *trips, int *num_trips) { - struct acpi_handle_list devices; acpi_status status; - unsigned long long temp; + struct acpi_handle_list devices; + struct thermal_trip trip = { + .type = THERMAL_TRIP_PASSIVE + }; + int ret; /* * Module parameters disable all passive trip points @@ -337,26 +336,21 @@ static struct thermal_trip *acpi_thermal_trips_alloc_passive(struct acpi_thermal 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"); + ret = thermal_acpi_passive_trip_temp(tz->device->handle, &trip.temperature); + if (ret) goto out; - } - + status = acpi_evaluate_reference(tz->device->handle, "_PSL", NULL, &devices); if (ACPI_FAILURE(status)) { acpi_handle_debug(tz->device->handle, "No passive device associated\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; + trips[*num_trips] = trip; /* structure copy */ (*num_trips)++; out: @@ -367,10 +361,9 @@ static struct thermal_trip *acpi_thermal_trips_alloc_active(struct acpi_thermal struct thermal_trip *trips, int *num_trips) { - struct acpi_handle_list devices; acpi_status status; - unsigned long long temp; - int i; + struct acpi_handle_list devices; + int i, ret; /* * Module parameters disable all active trip points @@ -379,12 +372,13 @@ static struct thermal_trip *acpi_thermal_trips_alloc_active(struct acpi_thermal return trips; for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + struct thermal_trip trip = { + .type = THERMAL_TRIP_ACTIVE, + }; char name[5]; - sprintf(name, "_AC%d", i); - - status = acpi_evaluate_integer(tz->device->handle, name, NULL, &temp); - if (ACPI_FAILURE(status)) + ret = thermal_acpi_active_trip_temp(tz->device->handle, i , &trip.temperature); + if (ret) break; sprintf(name, "_AL%d", i); @@ -394,16 +388,13 @@ static struct thermal_trip *acpi_thermal_trips_alloc_active(struct acpi_thermal acpi_handle_info(tz->device->handle, "No _AL%d defined for _AC%d\n", i, i); break; } - + trips = krealloc(trips, sizeof(*trips) * (*num_trips + 1), GFP_KERNEL); if (!trips) break; - memset(&trips[*num_trips], 0, sizeof(*trips)); + trips[*num_trips] = trip; /* structure copy */ - trips[*num_trips].temperature = deci_kelvin_to_millicelsius(temp); - trips[*num_trips].type = THERMAL_TRIP_ACTIVE; - (*num_trips)++; }