From patchwork Fri Feb 3 17:33: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: 52576 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp968955wrn; Fri, 3 Feb 2023 09:35:26 -0800 (PST) X-Google-Smtp-Source: AK7set9tzne7fIjUSquu1JSeTAXf2CiJ9q6LPf9pEZ8Kv+M33iw0BtWJGOr6vhTKks52Fk6ecgeB X-Received: by 2002:a17:90a:db8d:b0:230:3af9:179 with SMTP id h13-20020a17090adb8d00b002303af90179mr4898392pjv.10.1675445726520; Fri, 03 Feb 2023 09:35:26 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675445726; cv=none; d=google.com; s=arc-20160816; b=06c/Bg3e2uCW4bDQumPy36iJEWigg9TzJhZWnjGkZIBfPb5dKEOQsT1qDGNQrkYOFq OS0fpDPG3ZMQsOIc8lObNId5pwvSLudRdO54IZ2SirSk0zeYvW/wFfCbPUrFijbsN5u9 pn74Un1ewuqVHv+BNSR3/nr4HOI5jjI6HTqhke6vtOR8X58Lfx13drYumYqW6JwZFLZ+ GbUwE2MjVHec6Y7O7PbIAHiqscKuwGrHDsUwRwDttUbyDtETNtKroQ+DNG/6sSti/PI7 kAoiXSV8Fdl+cPG/s1sfNw0HoXGHQ4JerGuXfGqpSUOT6mQGUi1QKjfOxFdPmgOg5oA/ E4GA== 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=i3eh7OVbZgpWWNCpHPPLLulMNgKZlxK2se4kyNemAvMfO+vbKewjjOxONRbYJB6NuN bkB9xYl6z3sCH07OGuNnSPwa2Yxu7zMP+3Pwq6OuCdPjJZeSoxCvxbuw/zJPHvl796Ow VWLkorTH04UjT3Zy3nU5srLo2NRDz0kUoKN+1VKNzO1h1X9i0cgJIx1841Kz0k0bHvK/ bNz7yszC+Q/sybX977VMIwTCuw8sHBCcKzv9c4xtnhEmvQPVi43K8D3+hT9SpbvD5sPE r202qaD3VrT6vSm/i3vSl1lYKvkXsHMFNz8TtPdL7kBdiD9vpY9+nivoro3CF42+CFox w44g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=llcz6uxh; 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 q27-20020a638c5b000000b004dfd271e3a3si3280449pgn.560.2023.02.03.09.35.14; Fri, 03 Feb 2023 09:35:26 -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=llcz6uxh; 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 S231989AbjBCReA (ORCPT + 99 others); Fri, 3 Feb 2023 12:34:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232822AbjBCRdx (ORCPT ); Fri, 3 Feb 2023 12:33:53 -0500 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4791EA4287 for ; Fri, 3 Feb 2023 09:33:50 -0800 (PST) Received: by mail-wm1-x332.google.com with SMTP id k8-20020a05600c1c8800b003dc57ea0dfeso6542307wms.0 for ; Fri, 03 Feb 2023 09:33:50 -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=llcz6uxhKfNqi32p6BH/8MBxXmNge1GRdv2QPzOsrAkJcPtFlL6r4zmbBjd1a8JP5U w83JeXrg7j2lQ77XjAUuw5b5LOWt1RGKgHBEnUDImBvfWBxTOPCdvMTacjT2/7Ag6fs9 3Fu5C8v5dMunOEx353FGlojcFriOYi0/qjzOzuO1HZZnxV7eB11k7yxWr/kr7Vqqe3pz Row5DXhJOXwzmBeL3oOVrvD1rHs+aial40UtfYQBudQZFnVmffS44wtNy/T5O4tmrU2U LXQ9QiLInHdYK2dsdClSjzg0JQa0vzZA/UYUkqQjOB6d7g7oixNp0/nvaEcn7DAtSCBh Y+ww== 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=lLIObsecjyhO1dX5yj3+oETJ+Qa/ZQlljEqr2Yx0WQAHfsZMjgyQL+w4EBbPK//QSV VX5EeA8Ow+XrO3ENcvEjyLRevTUtPDaMfwg9BTpqQHbUP17vRPwo+FRM4GUyqBBXBcOm OpyxuPBeZIEUaZwzpzLxtlv4OAR4/nk7baji3857CwCFwP7gWAE+QGL4rof+gkbCl7vr p9x424pdJE9B7xArA8T0FceSMYdrZy7QEpYIOSDeQwgONspalZObrSMfGZSJbqa+bM1A TPxyadMzuO1mYgBXuIrKrrWhK3Tfq2CO12/zxCHPIVCnL+SOIR0sHV2skxp6oSxUrlVE siwQ== X-Gm-Message-State: AO0yUKXP8PWYDPxTZGqrhgvAWiSmqxwGm0M5hrFG3a+XH/zIvznG0Pdo G7qemsIkPAw1KQYm7gKMXYkDEA== X-Received: by 2002:a05:600c:1e8d:b0:3df:7948:886b with SMTP id be13-20020a05600c1e8d00b003df7948886bmr7931768wmb.31.1675445628712; Fri, 03 Feb 2023 09:33:48 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z4-20020a05600c0a0400b003dfdeb57027sm5876356wmp.38.2023.02.03.09.33.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:33:48 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: 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 v1 01/11] thermal/acpi: Remove the intermediate acpi_thermal_trip structure Date: Fri, 3 Feb 2023 18:33:21 +0100 Message-Id: <20230203173331.3322089-2-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203173331.3322089-1-daniel.lezcano@linaro.org> References: <20230203173331.3322089-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?1756832178122773396?= X-GMAIL-MSGID: =?utf-8?q?1756832178122773396?= 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:33: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: 52579 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp969115wrn; Fri, 3 Feb 2023 09:35:48 -0800 (PST) X-Google-Smtp-Source: AK7set/haBZHlQAPGxt8ZmETPEmifa1zm3l9VlyEZpE0xLhGv87v3+D/K1xInuurytFjmOTic6oF X-Received: by 2002:a17:90a:1d1:b0:22b:b78f:ba04 with SMTP id 17-20020a17090a01d100b0022bb78fba04mr11656907pjd.41.1675445747674; Fri, 03 Feb 2023 09:35:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675445747; cv=none; d=google.com; s=arc-20160816; b=urxDevHlmR3MpGJwPyRR1vABHPA4ZHLkKECt/5gze7R90RrTaAbwiDybc4acc1wsA9 B/Do/451PJdVVsXY6TlOPhZLKFY3650hXxbHs4N877Zr6gGxoon0NkriL21iKkqaOP97 VQJeKhOPzAecNB0Yk/+ePSa/HR4tL40/vHLoTABbsr/LC8jVEtxfURdAOGGwbMjddyIs DiYEQ8pTvDO9Y5pDnSOb4N8u11hPYCYbu4x4JSztSUnkKC4XZRJdqBtt5aGAAYQkjhWq zUf1KojT1WUtwuCdC+UCmVlmeNwr/kcfmfJ+CxifXhwTcuC6gyRde3UHRfaL+PbI0F5C V3pw== 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=XYPa6zzKv0H8kWKoj7RNAtj7m7gUo87NangF/2kV+ge98JRZ+5S7DFH8abZTr9x0xf IPX3Kw8QqFOYWItSE1v5unIvG62rAogZlf+mnt97Tj1XUwarHMo+Bo1iVqiCm2mJDGxr fFclojmHFAlgvVmf/BTiCYeR70rJQ69JW5mbft/jzpZRSAlwDQmap09lgDVgV7uMizdj mRaHzW6ZIv1HqsZ9kHaLrr5CPf6syuh28mZ8Q9qz0TUFuFCay6N+1NY9sHByG6nKn3QM FogKVqKmvcWrLlCEVOMIyyBMLH4fgZ2ZOG+tJ0C4g9iHhvabroxzV6BUDMpQby6ygVHl 9i1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=P0Y2vZ3X; 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 b20-20020a17090a551400b0022c8ba1bd77si8134881pji.174.2023.02.03.09.35.34; Fri, 03 Feb 2023 09:35:47 -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=P0Y2vZ3X; 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 S233726AbjBCReG (ORCPT + 99 others); Fri, 3 Feb 2023 12:34:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39588 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232875AbjBCRdy (ORCPT ); Fri, 3 Feb 2023 12:33:54 -0500 Received: from mail-wm1-x32d.google.com (mail-wm1-x32d.google.com [IPv6:2a00:1450:4864:20::32d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51BF9A428E for ; Fri, 3 Feb 2023 09:33:51 -0800 (PST) Received: by mail-wm1-x32d.google.com with SMTP id d4-20020a05600c3ac400b003db1de2aef0so4445281wms.2 for ; Fri, 03 Feb 2023 09:33:51 -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=P0Y2vZ3XD8ktpIwFi/Qr/mOT/TImaxqPg5YbVDEPDqt5Gmg813D89bZXpB7ukNEcWO kqAC4G0t1LLUG3CJJg0/lcgD7DkbjiqJnUHluYvRh0rHKu1l/29IeQ8e0/G1Mqm2q1DD CxwrCrmCreJxZnshMYmGprWbq72ic3XBKengj+YrZBU/R4mYuKOPMbdEmM+dnRooTYC3 nvdLhCNedc1TcVindRjoSgnBDTN0K8w8ONMf7q5WQhXxHtFAVEA8Xim9c5jF89AjlPVz ntYw0prj5hx7nzXDjWU4Em3RVeSp54kYTwYrsWV9bu9m/fy0sTT4pAg7NfDsy7/KQR23 Xf2A== 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=kqIrWWTG7yKl7TZZBnip8PjlIA9UjjvC8OvYXHTt1yb/sHhMu1Cshc4w86nBoabTBH l6cN6wC10WUZ9FD2UvEbVSnbRfnbjZSRPOY5E+xb2Zh+v5eYzLgd/GVYXPNmYsUHUWQf wB73VxB3S36D1iJXYJeFBRsIHpDOfIFzLus+43tJ4+qAuhKas3kVQCtyaLyan5CukPkn cppYqO2MPGyfs7Ge9lCP/vm2KOiXQXu8h2m9dl1m1EvSKuUIe0d6uFAAm1oyJCymZXdp Scb1PAxMpZW5oLhYv5FIL4SaB1joyl0jMxjIEGe0Ld1yqqvTxX1zeDrGsMPtbyFRMtIk n7jQ== X-Gm-Message-State: AO0yUKWX5n4IaUbQGM4nvs4FaVeFxMAz57bfFvpyVXjPbQ7CPbimzp0A S1WVpT7BGwb0Fm3NY7+J/o2SBA== X-Received: by 2002:a05:600c:1e24:b0:3da:f665:5b66 with SMTP id ay36-20020a05600c1e2400b003daf6655b66mr13119621wmb.6.1675445629774; Fri, 03 Feb 2023 09:33:49 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z4-20020a05600c0a0400b003dfdeb57027sm5876356wmp.38.2023.02.03.09.33.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:33:49 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: 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 v1 02/11] thermal/acpi: Change to a common acpi_thermal_trip structure Date: Fri, 3 Feb 2023 18:33:22 +0100 Message-Id: <20230203173331.3322089-3-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203173331.3322089-1-daniel.lezcano@linaro.org> References: <20230203173331.3322089-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?1756832200087041284?= X-GMAIL-MSGID: =?utf-8?q?1756832200087041284?= 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:33: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: 52578 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp969032wrn; Fri, 3 Feb 2023 09:35:35 -0800 (PST) X-Google-Smtp-Source: AK7set9ETKoFW2pmNF/hcG0uaj0w326QuF4/njzMSq/TNxjen9ikpXy6K/ByMEU++hatidQ7oS0J X-Received: by 2002:a17:90b:4ad0:b0:22c:9078:178 with SMTP id mh16-20020a17090b4ad000b0022c90780178mr11195222pjb.27.1675445734810; Fri, 03 Feb 2023 09:35:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675445734; cv=none; d=google.com; s=arc-20160816; b=kIFlkbXRw84uukxhRAxtcjxrYiGmvDhfZWdDFq0D0NymauQyNMEcs7goVDwM5xBaXt R7a4BRHt4SFk6T5hIiokxhIHMC9CBtB8FUG3gr8dMTS88vpDhcEDvt2MUv6Uq/x96W1d WDpvYA/oKVQyByzg2bUlSKyRHFp2MStr6v0kQLdGCnYd24dqpW4q26vTl4gpxpwy9W9v gHIL9zVgJ7vrca9vnJhqef5ZMkn/q/yr/Z59r2VCFT7qODJhS12rapef00FCggFKNOpV v5M6FjgZKlWiqnmczsFr+kP5rBfngAqSKqotn6QCR/W7EmRn1aILBTswDvPpn1MGrjZD ZnOw== 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=p03gFqbSPIQpECEzWJIO7XRdvfABM3ISepEC6u0QVq554KLCqPNUNSNUrtvbf3gApb 9USsNnAMSCF0asqLJLBhi/iDhoWgI3GqeB6buqFkk2e6SeBZHFvWgTY5n9x6JpdP2Qdv e9/sCXN/JjfM/Xq4C12oTwp0r+eXeRqHSRQRElOIajwDgBOJa21Ee0F6j62+gqZlITZG nVKU0Wvt2E2r8VVcORqCPwiSEp8E73lfuy/v+bdTeppl8byN5or1dvsVO/ylagvs/P9D C5srlKoLHs0NfhuYOOqkVvdeG1zO7t1f3CrUjTu2EtyihYHBWSJ50Ol+87jZcxIvbxmm dLPw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=t8ZgldBZ; 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 b75-20020a63344e000000b0049d55f8b9fbsi3651378pga.12.2023.02.03.09.35.21; Fri, 03 Feb 2023 09:35:34 -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=t8ZgldBZ; 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 S231665AbjBCReD (ORCPT + 99 others); Fri, 3 Feb 2023 12:34:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39606 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232956AbjBCRdy (ORCPT ); Fri, 3 Feb 2023 12:33:54 -0500 Received: from mail-wm1-x32e.google.com (mail-wm1-x32e.google.com [IPv6:2a00:1450:4864:20::32e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7EF4BA4292 for ; Fri, 3 Feb 2023 09:33:52 -0800 (PST) Received: by mail-wm1-x32e.google.com with SMTP id j29-20020a05600c1c1d00b003dc52fed235so4447381wms.1 for ; Fri, 03 Feb 2023 09:33:52 -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=t8ZgldBZCGzxhcueoE963fGMGt0RN2t93rSkJDpg+pfgaIujsTgpMjULYPRCv47S8j Ua+UdV3/XxxSON+QsJHVLrbZ6v/g7iqtcdlZgRTNjhPn3AUzRmVPulTOEz2M/Lk+w5Vp JfRR5SJXOaciPIyemkZIjosAsFI1DQxr/TaNrjvI2TKCo1slcZn5ZEUp6nPq+UM8CZGo prWK0TTiu3hU6QAweIYLiiPh8Pz1/TeOkO1FuhZum5bo4+/jv4nELoNiXYoxcVaxSvoP vE3XFjGBUodP9VT6Xm4b+4zTq2LEWCpmPzUii02A05x6vicTdPMY3MKZcEAj3qsnwkKT qgfA== 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=wjawBuBtbIHUfHnwaPD+KMQqBxwwwMd39QlClZtOQZdMWiMi2akfqz4+eEayuTntHP SmIjF6JwuiELIQe6xgD9CVTwPg3N632Bn1KZCvUQB0wyf5pwE4pHNhtjnxRBWEWqKGsS Dfl0tDXuVTsbTW9QdY+FAB2bAeoG2duijXXBvcmen1hcWSyL9uP5SgkmBRElb/pPP9fK OLkL+45n9zmhzQYEUQakVkp1/P0zn0xv59kj7hv6Jo+3BLC3OCgjMntEt23R/JquHdg/ hEdIsYOPgtCng47/wFINCG381CKCyDhEHSBsCWVYxekXX5qs0dx6hoZnoaYAh9V3ehuA giYg== X-Gm-Message-State: AO0yUKX67IFXwDMpSUnFSnPSNumMmgsGOuGykusZwS8h65jHCPPDKFaj b4bQRoQ9H94bEXMDuyjXm6qOmA== X-Received: by 2002:a05:600c:1d11:b0:3de:3381:24f2 with SMTP id l17-20020a05600c1d1100b003de338124f2mr10653315wms.30.1675445630934; Fri, 03 Feb 2023 09:33:50 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z4-20020a05600c0a0400b003dfdeb57027sm5876356wmp.38.2023.02.03.09.33.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:33:50 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: 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 v1 03/11] thermal/acpi: Convert the acpi thermal trips to an array Date: Fri, 3 Feb 2023 18:33:23 +0100 Message-Id: <20230203173331.3322089-4-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203173331.3322089-1-daniel.lezcano@linaro.org> References: <20230203173331.3322089-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?1756832186721931852?= X-GMAIL-MSGID: =?utf-8?q?1756832186721931852?= 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:33: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: 52577 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp969016wrn; Fri, 3 Feb 2023 09:35:33 -0800 (PST) X-Google-Smtp-Source: AK7set+qI9HyTzixGChsd6Za3fAmrDF9HIvVX78NCtLnc7E7Y7+re2IDoDM1Fg2GLP26WqHct0Wo X-Received: by 2002:a17:903:2444:b0:195:f06f:84ff with SMTP id l4-20020a170903244400b00195f06f84ffmr14171923pls.50.1675445732845; Fri, 03 Feb 2023 09:35:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675445732; cv=none; d=google.com; s=arc-20160816; b=CH078UwOO2+MsA+0QGIEdZqS22EHf3XScPfcWRE1d4Sc+hK/jl2Hzlf4aulfP3uVJ/ xKQo1l5aXI8V44UlHuOedH3aAHVu24oCipFP1GPsK2DaQfLPWmvT/G+fo6t8xtcz7cSG Dwvr+nwKY380BGhFwlb7JTKHHcyylgM21udyISAp6iUTmBBI6Cl+diQQoJL44qX1ife8 9QM8g2CRKpQnycqRsWEg4jlyq+1RcdB2fbVqMdwp9XeH0HKw1SvBe53euX2JmYgTqbM/ YzU79HFJnItuaNDbQAvkHFVQLT6ZIb5C7Uttz8siTmKe4LR9TzTXy/uxCABPdQhUAlRw 0PLA== 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=hWfNgdQJmnj5EyeldCjxcEKi1HDBn7feKB1z4MrlxYtWvIHkTw5sbeYPA5OmUU70dX UHH+qFGZ6YNik1EgsutEJXxKHU7nRSAmaICvDZgdkI7j7Y7K/KCDxn6/7DUeb1f7jqFv sCf4Gidyfjz9t0Iv46rg/esm5o3jj6KWNvj0dzhUmcmKFBZAxlgjmDjE7yYjX06Uc8p7 N5mzUY8AdD/FOZcVmnw5AZJ6bxl0S/FNAddpSt9xNRTyt3RjPLjlAMtGSxqfKhnLNyKK KW6Ln7Zv1yEY4YS34EWByuz+9neWLZUjsjWow49MZEBVpwx6yFshJl+1xpf1tfZK6qlO PKdA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=lnQ3roig; 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 o13-20020a63a80d000000b0046b1dabcb34si2982580pgf.765.2023.02.03.09.35.19; Fri, 03 Feb 2023 09:35:32 -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=lnQ3roig; 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 S233746AbjBCReL (ORCPT + 99 others); Fri, 3 Feb 2023 12:34:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39582 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230230AbjBCRd4 (ORCPT ); Fri, 3 Feb 2023 12:33:56 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A1449A4280 for ; Fri, 3 Feb 2023 09:33:53 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id k8-20020a05600c1c8800b003dc57ea0dfeso6542408wms.0 for ; Fri, 03 Feb 2023 09:33:53 -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=lnQ3roigEDYuqBl6Otv/hvV7G4ayuVGLtkEXGGFHNIpWLvlu9dpE2OXbeLlVGd3/Rp ARXaI1yYU+9dZTFsolhTGw/ySAv6tZ+5GwNGDYCxbpOVl0XY/05sLUl4pPwfmBBIXjJy 6lYYEc5C7TesGe9NlGwRVmtZUnC09PzmHs3L17HiG81gb53AFbsHEC6N4ovW5gD1q4SR Xvrj/6O+c/7g4FH3lhOMV2z/hzV1cvHvj8r8JRLFetziuI+xVr+OjEC2ox21yWbB8hFK o0nyTsS0y+iP+ntp3oKEKeKaptnXl61zDQb0Y6K3EgJhq51lgMC3nwnHQnJcpCYbzun/ CxNQ== 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=Bjyqajvhq3zFZ1IUeLadZ6dEIdkht90WIWmDu/I91QneBgPckwYPsF/Fl0Yizi8GZe 7cBtiSXZ4kp2NsZ7XNSHHFf8ujLwRBsSbYHEmmnEssoOSukQmBXf7+SlaBvuVtHM4Ae8 CJDFjRMzBW9ip4BUAWBdiJTEtjgLqCsy2vgy0Yje3jAv8WNzOhsTf4AzBMGEuVe7d894 6ut20Noy0rMIQHkntL+pMvGfOviEeMy10t1u0zkrKxPJpy0IcgjBm2uhagb2fFRS63q6 DjgY8ZgZujxNR6+KszNNCWHrVBUlIY0xvqE1NoBuf3cNL4lItRyDGmG9wsFn+vVxCH3V T2Ag== X-Gm-Message-State: AO0yUKX32hn2nhykXEfWPqDOuP9Tv4K4PIBvzicupkNg/III3SOm+/fO 3nSEyEasKFzhrJ2HcaaEbcS9LWl0Ph/+0L2+ X-Received: by 2002:a05:600c:4446:b0:3dc:98a4:787d with SMTP id v6-20020a05600c444600b003dc98a4787dmr10275192wmn.3.1675445632024; Fri, 03 Feb 2023 09:33:52 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z4-20020a05600c0a0400b003dfdeb57027sm5876356wmp.38.2023.02.03.09.33.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:33:51 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: 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 v1 04/11] thermal/acpi: Move the active trip points to the same array Date: Fri, 3 Feb 2023 18:33:24 +0100 Message-Id: <20230203173331.3322089-5-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203173331.3322089-1-daniel.lezcano@linaro.org> References: <20230203173331.3322089-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?1756832184641521380?= X-GMAIL-MSGID: =?utf-8?q?1756832184641521380?= 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:33: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: 52581 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp969531wrn; Fri, 3 Feb 2023 09:36:34 -0800 (PST) X-Google-Smtp-Source: AK7set/QA9Jz55rennOFtqQWxL8+Ufs1OTbIOaR5RUbaUWF/O0TAmYFoj9u2qwjwD1/sZlgU3STE X-Received: by 2002:a05:6a00:1905:b0:593:a800:2abc with SMTP id y5-20020a056a00190500b00593a8002abcmr12973276pfi.8.1675445794112; Fri, 03 Feb 2023 09:36:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675445794; cv=none; d=google.com; s=arc-20160816; b=mYfmHGwsUpWQ612Fq6y6iqwDgrrYRG26Jj5Ix4VJCqsTQLHeNRDCZruaYdX/B6QnAD dNsXdK86TDVt96eqH7LzxEISD4XFPcQevk0WYgA735/AhO7aQwTYJz63bFpKtRhxPt6h jwd8Llmxxz/g9YVKqBLwTI4mzWvqUdBLARrQhHnUE7fFQVJ2zmdU36jjj2UWyA1DyhI+ bxw6Z7lerNmSZcYPKeywDUk1wYaUcY5yTXfk44qNEB3oBDGiFsyIp16k/ZyX89yk6od/ Cw8ElpEZz5i1jNYNRN59aFUe11xgirog0mScXArrcCpeHcUB+9/bjSIbTMyd7f2nP71U zQWQ== 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=G/zOp3IZX2JGEOJJybFXseDpm0NbVU0qyQIRaso/umbPLHOa6mPPO5b7BxQLYVlegJ aydrqcOrAgrnGpnON4qRk4JGC3SGZ1cTX0Lk6c0DRj6vju1fi6pzEg1r+c5h/tIfhybd Kx3/grfF/iCB6sxoBF+A6aYEIqI2CDrXhtgxHPTxfVqxNPiiiAU460NW0GaQ0qKEU1X6 lQkS0jAGtFNSI2d0mxpauqXTCM7LQdO2uxL0RYJkjZNLJ3pRC/5j07trkqYNZSBH1nCo hMf+60+7C49NjiM57K3PCSevjciMvNOZgjhLEme1GDb5ygguV9HvIWjgVzqDHXtLdF7t +KvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DrUrXi+3; 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 137-20020a62198f000000b0059394f3d4a0si3032604pfz.93.2023.02.03.09.36.21; Fri, 03 Feb 2023 09:36:34 -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=DrUrXi+3; 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 S233754AbjBCReP (ORCPT + 99 others); Fri, 3 Feb 2023 12:34:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233217AbjBCRd5 (ORCPT ); Fri, 3 Feb 2023 12:33:57 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A597EA428B for ; Fri, 3 Feb 2023 09:33:54 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id bg13-20020a05600c3c8d00b003d9712b29d2so6528157wmb.2 for ; Fri, 03 Feb 2023 09:33:54 -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=DrUrXi+3MZkKGS1YkNuyIUAsszP2BKSd0lj3kjyE32lDqIQzjAc32ARNByxftBoL/L bECIbPXeJlDE12N+JgqGeUucqOHSkO+7huARpQlwgpwwAoJw/Jk0qCoVxF2Eei/03wci MNDGHZpZn1oBctXywwrApgshMLnVywL1UzrInacXI7ASed8Ibc5CNGtvXOHXl/snQcUB YTbLPBwy6uv1CgqJAkIfMhQc8auPb0Lh2L98VSq/2mXHLfsm2qeGAGTrHwlSXCRK/k1v +xnP1sAufZJWvvFZMKcU+v+6DJGGs859kK1uQG3LuY9txUs1xJURgTNai1rBhukduh+O w1Ig== 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=kSdVzE2lC9zwy4MchF2aD/ZiaeHSMfMpAvq+6+nujapydZBzylDtouP+NaPrCYOb/g w8lbrodN6wiE1//5mugDwD59Pt/qzcaNUm5XEEBVSjGP8UYhLZoUtxf3PRtVp1bxmHYb EVkml+J9CgK2BcGMqand8/aFd4cW+Owjn6H8gx6m7q5I/0iQ+2VjWT5Y6sMit3SafQeq GwU6HWMMQnPUc9VqF2hZJpsPa4kjDsucD85PQdWo9tkuHOzC04zvWQxpuhHAz98u00vK TWyt+ZjJro+2ByuJ3/14ZtLjm6xLBgdYSg+mtvb8ZeGrqxLQ89xmQe0u430c6IiZmuZ5 MHvQ== X-Gm-Message-State: AO0yUKUQYX5P4wf/tIqH36CuSMDmjNe8XlM+lLspnVwksovUs25m5mng Try8uEwwydudLN+Erwc6/tKKHw== X-Received: by 2002:a05:600c:3ba7:b0:3df:50eb:7ca6 with SMTP id n39-20020a05600c3ba700b003df50eb7ca6mr8334613wms.15.1675445633074; Fri, 03 Feb 2023 09:33:53 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z4-20020a05600c0a0400b003dfdeb57027sm5876356wmp.38.2023.02.03.09.33.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:33:52 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: 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 v1 05/11] thermal/acpi: Optimize get_trip_points() Date: Fri, 3 Feb 2023 18:33:25 +0100 Message-Id: <20230203173331.3322089-6-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203173331.3322089-1-daniel.lezcano@linaro.org> References: <20230203173331.3322089-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?1756832249008564094?= X-GMAIL-MSGID: =?utf-8?q?1756832249008564094?= 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:33: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: 52586 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp970139wrn; Fri, 3 Feb 2023 09:37:49 -0800 (PST) X-Google-Smtp-Source: AK7set/u8Vl7YEZJGEpCCUGxZg19S0N7IjqTmPNSRjqV00AA8jRWfr6qjt6fN/4Bg3sYgcpos/xF X-Received: by 2002:a05:6a20:7fa0:b0:bf:5073:6cb1 with SMTP id d32-20020a056a207fa000b000bf50736cb1mr15011418pzj.36.1675445869352; Fri, 03 Feb 2023 09:37:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675445869; cv=none; d=google.com; s=arc-20160816; b=S7cN/Y5miGenyNuCM4qZicWPTywL+nGHehd4ULKUCr+O1NaSUYXc+p+xzvttnfmXSv iV+h5GxDs9UL7XdZShsDniBee+HDzwjd9gIuj3QebsH9CwkPn1+F4E5DnagXaUbN7DSB MlfbM6vwYztnE/8ONDABakHC2BWQ4fQN2dTPAGX6RgpyGQWMc9+X4ECi+DrSMsucPIOA 4TQ/zYE6GVObWZiOvyOkc8avVSrf9XgL2WrJbwgOFWGN3JxN9f9QRYQNJSadZlXJE4hc ksn+rwlsc86rmoLtQwEfEOWDCcmrX1IAmIAX3ZtdMvShZEG7WuAzPKQ8R/eVesGDH4g0 lkfQ== 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=hGtHeuoxAp2nUCvLUevgfyMGGIgPVj5id6MF+9ONVegzkRWmFiR88mivak/tLKNAFC 8/hA4uLFXafPZf2GP9rvYp3Vw9B++WWD+zcexh04BbkG0zCKHPqPYGb4r8cX4EH5I7+J fdPaJBV6BSiiCaRviy0ngre4tiCxR5KfCh9qi95/vUZ9fvF/4dKfkBgaTPbVNXgrzkF5 Rvt9MY7udplZ1jfH8Bx+1gz9ecOcynPJ+8QYOlaNHRlekZiALaq9DRPGjnw7QVcB+Oq4 AFRwF7z7609fzW6ZRSHMeHX542p8bwsYF0OUksJQfcltnin6X/+0y+z5Sk6zrCoHMQuW efIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fP96O09t; 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 w22-20020a63af16000000b004d422660fe8si3794136pge.5.2023.02.03.09.37.36; Fri, 03 Feb 2023 09:37:49 -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=fP96O09t; 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 S232978AbjBCRer (ORCPT + 99 others); Fri, 3 Feb 2023 12:34:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39604 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233570AbjBCReB (ORCPT ); Fri, 3 Feb 2023 12:34:01 -0500 Received: from mail-wm1-x329.google.com (mail-wm1-x329.google.com [IPv6:2a00:1450:4864:20::329]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D648FA56D5 for ; Fri, 3 Feb 2023 09:33:55 -0800 (PST) Received: by mail-wm1-x329.google.com with SMTP id q8so4423577wmo.5 for ; Fri, 03 Feb 2023 09:33:55 -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=fP96O09tFdYsJTmC6eXLyl14WDoHUGqDsl5HcJXm2pMczExOBbEBwcmx5rnXoNG5vg G7RUnGyDTBt15mybbBVoUAhlebN6IJ49RiKaPfiuHGIKoAcuP36FIqi3MmghgxFpMlqA 7bNGR8bBAvgxb5n47//Az6CDg30Rhe1XlUl6Pa9W4cJcEwLxxnXS7xxuM5lXJvTAdwDn KJXG2zc7NEKYC8FUyKxb4osQvZZszjyX+YjIJsx+MQg+XTpyC/XdSJIkEI4Vft6PxIbC 6/m362S10ypEKT7cKfH1lGSVRB5xyjSVAMW6PJ0F3732qYyP3kM1aGLLI2atFZyebOHH 6Obw== 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=p6UO5Rm1lEJ86gRHUXB4M98qDJxKW9EuyVjZObTAXLIIgY4fODikWb5Uhwo99TiViU aUguHpdhuGSMMFLaoRiOlp/Ng93VE45RRdkXwTa7OKRCbt6ayVFMqAF8AyA3pmCaLAv7 OPXlXLnQPBj+aROI6HCtfoX74cP6NrwgBl4bJ6q18FbrrpQUIOa7wH292eRpE14d86UY U9mJmzvisZlbbno/J+0XOZRTTf8YRN56ig/UK/pN4w82LP4nSCH0T+lyVOVrQypsK+Yc 4o6MqCQAEv59qcudrdifJdSulJNxgkaJnlXHwnslkJJNq13ph12ylx3KCpce+WGJatfD Ralw== X-Gm-Message-State: AO0yUKU2VC0A0YIFhAEau/g0Xi2Rm4cQGUHAa/xJ5rfZzJCCyAnYouF8 m/zvGAEKTKphRfXn75AoDE9qYg== X-Received: by 2002:a05:600c:5006:b0:3dd:caa8:3ae2 with SMTP id n6-20020a05600c500600b003ddcaa83ae2mr10847151wmr.6.1675445634153; Fri, 03 Feb 2023 09:33:54 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z4-20020a05600c0a0400b003dfdeb57027sm5876356wmp.38.2023.02.03.09.33.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:33:53 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: 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 v1 06/11] thermal/acpi: Encapsulate in functions the trip initialization Date: Fri, 3 Feb 2023 18:33:26 +0100 Message-Id: <20230203173331.3322089-7-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203173331.3322089-1-daniel.lezcano@linaro.org> References: <20230203173331.3322089-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?1756832327644235338?= X-GMAIL-MSGID: =?utf-8?q?1756832327644235338?= 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:33:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 52580 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp969120wrn; Fri, 3 Feb 2023 09:35:48 -0800 (PST) X-Google-Smtp-Source: AK7set9NFmEv8FXqicsGovEahSpEFhAAOB+TGSQsUREJllOaZlBTKKzxmsip4sgRmKsdP5f9g2HP X-Received: by 2002:a05:6a20:4428:b0:bd:278:f68f with SMTP id ce40-20020a056a20442800b000bd0278f68fmr13535498pzb.52.1675445748271; Fri, 03 Feb 2023 09:35:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675445748; cv=none; d=google.com; s=arc-20160816; b=anUzXwDQQBDWDkyeGwjpI0k4lBnT21k+V+cCE0I6bKjGjrG84xo6w739fECkwSAQ4x Nb/FlbZw7ZT7qeGCPZiNYCrGb/7tMovVHjPn9GanXC08j7Yv/JWq+LV9u8UL9wuF0cLy Oexioa8VA87KYzNhwDDShmEWGmB0VLe6LbB6pA+FN+pq6FqinMXMmIe84jHBOTFP3Whr ivEzAOQZyRWjfy6MrVg5OQZoN4u1DOxR0Y2zN77QUn/hVII+W5GO+xKRvFt/IKqHzMDJ Um+xlXg/7vn/pKMfPGTqWb8//LrhV+JeXcq98NIZuesQVtj7iPKVoxuhlz4joHGgy9kN 0gcw== 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=YdBeT7qUCrh3zRDybVf5UvauOy/ffvzHOhlKqW4aRs6TkMogha6yhIWHFEDX3Oqr0s Hc9GU49c1RLCjQhVed2J5CjFlRSkTBfyllz1F4D1CnXpS4qdo0jZPfrIiyO35DqCwwbR zTeCvgXAoggZ9w/Tzs35gQekpAj2NdAKgVhW+A0gyBYxfvTJG0mn7HEP0eeYFtWYPKB7 PRQ4v2TL/lnkcJl+FbIi3hXSjMaPDpNrTVfhKjNdsxdXkP7WdbEVj8VV+FzK404NonUz btkfq0bKqFyitWr7Z8CeBu6s/JgMFM/gAZgEQJY8n0KZhYyjFOyFoMDKHreoN0zHFdED m2bA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XHOfdsZu; 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 a187-20020a6390c4000000b004f1ce43e6b8si3406451pge.22.2023.02.03.09.35.35; Fri, 03 Feb 2023 09:35:48 -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=XHOfdsZu; 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 S233761AbjBCReS (ORCPT + 99 others); Fri, 3 Feb 2023 12:34:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233255AbjBCRd6 (ORCPT ); Fri, 3 Feb 2023 12:33:58 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B5814A428F for ; Fri, 3 Feb 2023 09:33:55 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id j32-20020a05600c1c2000b003dc4fd6e61dso6511821wms.5 for ; Fri, 03 Feb 2023 09:33:55 -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=XHOfdsZuhQ64j8+pZNPju1LBEDBsM5d7gyUiAOkeKBc9vEbcIvqsDaDN4IETWMjbQp ZrHX0rW380A/WYefqmUKfScwbTttISBpjVzSochOvs0f77cBjt6Opf4+uMTSi3nMbhkf 9uAy4fsfmLxX4t6ph19DRXFq8zC5ccMJq2eIgSsQtPTNl+7KmMuGpfWjhOA7GQoSYGR7 I/pmwdxj0LZGeSJA7345nd2y3mpcQEJBQczKp0umtrTV/VgcWUZ5uVjqDN+n3IEVqlqX C/HK95ys11iiPgpVOTS9Xt08cuAUDcdf9kdNJFo6IS2wDlij0h6vZ6p7qj5A7J3wqE6z XLDA== 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=Q2je9q34gecoelaufgw+RvD9tartsR82KM5si1dBRkKUDM1WxSlTJi+oj1Tl+p8Cov p49GKfFF/AT5BerDrM3KqHDLgWAj/26aXX3ndi1XPNpI1y3WCeahJ5b2rbE/qLrOV/kT SoIW3Z+d25Qde7T6sPk8B1UJbOuq/9iryF2dagRMkSDVMUA1Zov8mDAn9/YvdvZXGdOH 3jM0AuyV4m3kJi7qx0ADg/58UfT5NLT96IGVaBe14r0QtmUHulL3CkybCNxgxr3/pWOL LgHrDO4NFeOr+6KJ8GexykNNd0lJvJEw5hYNoYUw+lrYkN+VRUdbpcydi6EOUWPj01dg MbjA== X-Gm-Message-State: AO0yUKVXreE76wpIkfDkZvMXpSQBPDmxt4Qs+W2F3QuTZwYxATsDL29Q WwA85D1Dnn3of0DRSQLCG+5Va4DhFA7X0DWM X-Received: by 2002:a05:600c:3ba3:b0:3dc:58a2:3900 with SMTP id n35-20020a05600c3ba300b003dc58a23900mr10266362wms.29.1675445635238; Fri, 03 Feb 2023 09:33:55 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z4-20020a05600c0a0400b003dfdeb57027sm5876356wmp.38.2023.02.03.09.33.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:33:54 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: 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 v1 07/11] thermal/acpi: Simplifify the condition check Date: Fri, 3 Feb 2023 18:33:27 +0100 Message-Id: <20230203173331.3322089-8-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203173331.3322089-1-daniel.lezcano@linaro.org> References: <20230203173331.3322089-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?1756832201196479971?= X-GMAIL-MSGID: =?utf-8?q?1756832201196479971?= 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:33:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 52584 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp969713wrn; Fri, 3 Feb 2023 09:36:57 -0800 (PST) X-Google-Smtp-Source: AK7set8KyAXA9M6oMyL8j+9M47URLq7KCfFU0kf5bxNhqgOjSI8xzZk4s2IGuTBmztQzKSEDuDRT X-Received: by 2002:a05:6a21:3942:b0:be:ea27:3c16 with SMTP id ac2-20020a056a21394200b000beea273c16mr11583031pzc.35.1675445817660; Fri, 03 Feb 2023 09:36:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675445817; cv=none; d=google.com; s=arc-20160816; b=KpncLx4X9LOTTEZYJSznTi6nX0wsne7Uw7ho2Bjejqu6ITHhsRXVEsQ+vaqWmjPoMY IEOp9eLFhm7HHf2QFUO0L4RH0bKNe5zWLzOkYR5RgsSGS92PKpJ8ltKwtBYckjGV/EMj ExDtCOXbpDnOHTcKYzZv2GnIvUtKUAowtX9w7HOjnXOj5OzskBUkEPhfW11gNOLr5ISG l0qMaex7ifgOMWYhxznOaX52V0+l+NX5kQrp5z+Bi7nkMo3huMEr4wm55fyk2Y7ILGs9 fiSGB6Tm3v8a28ZQBz/Fq5FREtN5G5eiXDch9RpZmIcnpkDUspiDLI4Bn5TqL5zcWgXg L8NA== 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=B6Uox1dFzFlX42gaM6ChdS0dFbIPmhKf+Ua1Sg7JM9EcpecY5WLY/27fcVVgJQhfm4 p8Un8uXZ/8ZQdq6jIp/R9dVrkH8g5kam4NdeSRgF+t2ld738mBczSqijMO5eihtIX+Jz oYG1Mo/7TTCzUdnWniyI3mC2euzY28p5m55cCkN18CI00xOhPFcSO03RJAld99uN3CSg B0agGkRnvYze7+KnGPjN+mxxGHIEQBTBHb7DGB94z/Xbos4KypgzYQ7IbUpyyDASWBfw kIny9wz+mWa9nKQo76+3mrOt72iJHeZmeObPh7mjeTXvxuJlI+M0yJe7NQYr12ApgjCo zueA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=woZ+KOPP; 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 r9-20020a63b109000000b004c86424dc69si3029263pgf.876.2023.02.03.09.36.44; Fri, 03 Feb 2023 09:36: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=woZ+KOPP; 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 S233777AbjBCReW (ORCPT + 99 others); Fri, 3 Feb 2023 12:34:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39676 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233362AbjBCRd7 (ORCPT ); Fri, 3 Feb 2023 12:33:59 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E9B7EA2A7F for ; Fri, 3 Feb 2023 09:33:57 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id q10-20020a1cf30a000000b003db0edfdb74so5909543wmq.1 for ; Fri, 03 Feb 2023 09:33:57 -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=woZ+KOPPRvuO4deKvfXWa7zhtaLVQWO5ATsvUf7wxj9cB3oCEOS6Y6K6ah2x9jepdA qpLNa35s8wIuA1S9XvXx04R1O1IzpRNF+u+r2keduAfcCF6HX+1+IlpmjSgj6ewCzA+B 4XxyYtdpZx3geySdx1BzE53jCY7KAVsHL9Hb66OCeDjnhHxutTZz/feVkmWZp8DSM44E 6pKC0axYJJcwE5FLkAgEl1+KK2DskUOYq1UrzvzymvwXRrlsHCAm63KtiW0pfBSck/Dq sUDFYUBxnQEx9G05J7csNae1o9MS+3Covr3I6OYA6mEFxj5j3+BTwf3A3TYycZksUeVm 1vEA== 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=GDBuZrg4/rW36i1/23qr3MHq/RSg7jRkNur6T11tijIynJIcR+KFsAWLPIGx9dw+ws saHJdFoAT/JJj+ONgfmGyThz5eYLUTLkB6EOvvTvyTFkMUuEoZvtEGU89vxKUH5QT0S7 W7dOAOMmKfOfT1Pzfm4smbfrTCRunNRGjnHyj2RHYH+0aFLASAcW8dCQZsRjchKKTprL loBok8ot77rwVYLvm6mbNWQdk5e/QndKG9eHqG+woCaEqsWzY7reLdJ+z04INhd+qrWN eanrUxRGm2HSF4XVgTF0sNVdEWcGdG294xXcMVMlwy/8U8ANYUq29WUIvIs2Li0rlF11 vhlw== X-Gm-Message-State: AO0yUKUQG57bnrzZwpFVZB9P3dwVEIeq0nOJVp5juBGduNVoMEy9xEJY fZYKPVbpkeGAFj0m+50nKYD/Dw== X-Received: by 2002:a1c:f603:0:b0:3df:dea7:8ec with SMTP id w3-20020a1cf603000000b003dfdea708ecmr6280583wmc.20.1675445636284; Fri, 03 Feb 2023 09:33:56 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z4-20020a05600c0a0400b003dfdeb57027sm5876356wmp.38.2023.02.03.09.33.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:33:56 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: 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 v1 08/11] thermal/acpi: Remove active and enabled flags Date: Fri, 3 Feb 2023 18:33:28 +0100 Message-Id: <20230203173331.3322089-9-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203173331.3322089-1-daniel.lezcano@linaro.org> References: <20230203173331.3322089-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?1756832273479818937?= X-GMAIL-MSGID: =?utf-8?q?1756832273479818937?= 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:33:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 52582 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp969612wrn; Fri, 3 Feb 2023 09:36:45 -0800 (PST) X-Google-Smtp-Source: AK7set9unQ76nZqCJs93Q021vjavEgKkc2+JDGDGb+2Rgu5epS2SBB6Ggs6+GYGj7GvZP3+F49gb X-Received: by 2002:a05:6a20:8410:b0:bc:f665:8653 with SMTP id c16-20020a056a20841000b000bcf6658653mr17416803pzd.45.1675445804904; Fri, 03 Feb 2023 09:36:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675445804; cv=none; d=google.com; s=arc-20160816; b=qifvWM6NpIjFyGur10Mm4B9oJy61DM6xqPpiux7wuNRzQJmKi2PSrDnfwY1OiXGbdq Sz1xdWRE3QOe8fCp3iiG3i7zPJDhte0+X1b7ouKKpbibGav/t9deD+CBG2hjsK3h+Uj4 kifT/4dh41iiuzSdVLWmcTn0b6TamJ8xKSw47LSnJPrX1ZaCjogw9xnVPVI9Sq9nfiG7 IqEEOQZoZeEmjMFo2iBrOjmAP2dRks4hjq0FRMfFHj4bef7TZLpjBUPoZLaO7f6HiuSi Ah/poFiT2LzabWgFgtY2vSYSaTmpd3p1IqrpJzNqxasBZXsGMC5qg7est5tMibNN4rqo bkwg== 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=eDUT3cr/ltZCM06QS6tOc3KKKogLCXDUaxnCKEYrGt962cF6A33avaA6ZO2sElcB/1 j/LEunV44l1WFFH3csJMC69wcF+a+0xgWrjJDe0y30GZI1cxOEws+tXADr+e34S5ARBc IZVWuSYGbfm4HAUgtJwUGFFzBDGr119WtdkHzx8X3875hEErw9Dqc/kh/NghggPfj3gq JvBske3ybsZbZTE5QSud+p2XfcMLIPixGmgXgzwdkoFw2kpINfDuDUpJuvZuqbR+SLhi M7Cz6+Ypqbi3jWSxLduhEVgOcy615Jue2I1U81CqhxwbBc1VSE98gBpEAjP75Kcak01Q y8jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BwPh2K1s; 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 j7-20020a637a47000000b004d08be9517fsi3117292pgn.478.2023.02.03.09.36.32; Fri, 03 Feb 2023 09:36:44 -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=BwPh2K1s; 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 S233524AbjBCRef (ORCPT + 99 others); Fri, 3 Feb 2023 12:34:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39642 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232949AbjBCReB (ORCPT ); Fri, 3 Feb 2023 12:34:01 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED7FAA4287 for ; Fri, 3 Feb 2023 09:33:57 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id bg13-20020a05600c3c8d00b003d9712b29d2so6528314wmb.2 for ; Fri, 03 Feb 2023 09:33:57 -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=BwPh2K1s3VvrNIFZ2qnZis7vTO6tK++DzNrfzs3Pted+Yr4HfKoXjAUkPh1CwzYp45 +vq9FSKPZLhTukJI7nBnbewsG+08a8+StMb3qLJjmbTxvb7/ZTxUvf6qERkVLErxzdsS Urgi2wAb2B12FObZ38pPBUlwNTY4zpsDBm/BG8vQC5386AoIBElIBgeBwJ1JxurVpjQ8 ZmiYQSl4+do5jR71MneUuBGDmoRko0jYthu14ioOSrZRMq4uWRT8RJQyfqaGkISloFfi htNNvoCM7kkd44KbL6nVa9xVEo2gOATtfRmQmrl6jthil+exkX+W2ZGWkW7C8RuLfk2r w97g== 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=z88pt+8Ptq6q7qSPq57oBNmfObi1JOJcS7g49jR82wndHIuI6Scln9BBG5fR05CmFZ TE+ITJCi8oy0295koU9bBm6BLdBIgG8c3I7AvGiT+u7lCsqBgR5OgINl20vONrSrb+OQ 9uA+OAXCA5K1TDKrGuxCu2G7qT8O5n9ooW51yB/M+PtvOv8La7Ytkg7f8tCdkI0LQoV3 j3FzXgcrrn0PQMdkDHEquY8pf97JDWxrOqmbX7L8CfDCS6M34NQzDh51OIW3gAK9zCmf T5IQXxkGbICMGjuRe2pfiaHdyMTqADM1AbMDnVdRBHwStrUroOE25hZPViZXBsRAJZR6 VPew== X-Gm-Message-State: AO0yUKXN+707+K9xwrafJCRYtkzkQ5lJxzwNblEoLnvluKhEvJ7Bdn3O T7dDPCq6VvHUAfCjA/bIlml10A== X-Received: by 2002:a05:600c:c13:b0:3dc:496f:ad56 with SMTP id fm19-20020a05600c0c1300b003dc496fad56mr10290025wmb.14.1675445637441; Fri, 03 Feb 2023 09:33:57 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z4-20020a05600c0a0400b003dfdeb57027sm5876356wmp.38.2023.02.03.09.33.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:33:57 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: 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 v1 09/11] thermal/acpi: Convert the units to milli Celsuis Date: Fri, 3 Feb 2023 18:33:29 +0100 Message-Id: <20230203173331.3322089-10-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203173331.3322089-1-daniel.lezcano@linaro.org> References: <20230203173331.3322089-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?1756832260126576202?= X-GMAIL-MSGID: =?utf-8?q?1756832260126576202?= 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:33:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 52585 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp969738wrn; Fri, 3 Feb 2023 09:37:01 -0800 (PST) X-Google-Smtp-Source: AK7set972qKCn38XkYHbvCRpybyO+La9wnfts6SNnu/kMk9qQMx5+QAh3IU78FxeIjlv5BMv13Uk X-Received: by 2002:a05:6a20:d70a:b0:a2:ed21:d820 with SMTP id iz10-20020a056a20d70a00b000a2ed21d820mr5013629pzb.42.1675445820898; Fri, 03 Feb 2023 09:37:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675445820; cv=none; d=google.com; s=arc-20160816; b=syPNPRbLtqm/dR3qUT/ZeZfosX87VoNUqxiEU1bxpNmU7wXMmC5BedKkxHLfvj0yZU b8d3cAFEjfx04vy/tY+qBvUvRbYbgnPMGOSFb3bwa1Z/+5roGhvdovvfC0v1K2uLnxtR jXwFVFz7tDMV+AUjhq2urKti/weDOgHdSjlw01zmwfpjD9jFKkb/I5WnTrFHLPfImNLx MqU8iKOU9cBOAgdCSUi2XHTmpX9jyN409xhBzUBtcf28amP8XOQ10MVTmKX8GEQ8Kvsn 6OHjHHOYXAeyjGRp+wAa6cWDsCIrM/DtZ2xVICPCh+U9NABvmxY3yjhiq0+/qlJZ2Rt3 JbSw== 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=01Jv3WEplP/4+h0MnYts93CiHJ2yA9AzDFeIXh5LUeg7OKoMMKmQVBfGeyWD7bXOl8 ys/vMLSLD+ICoU6vSMrTYJKmcoAsgI96ccTmM29CH+v1t2wWgjRztIzKWeKNjn0M7CHo 5sArycLP/9JESRC+mhsvn6jHOoCSlAEDNH2DghFF+8s9QQ3VpcdgkY03dGchycD9U5oD 2PHP00T8fErYCfE3VBN5Bs3Ogs4jYZvKREy5pMkVc1uW5x+M7vG6kEkAUn3jOPIRXLMx lHf8GrZz+XxZiVBhTvEI7qyOj/90Yl55/tsBjixKhCQPdgzBAdi6yPSfWBhlDDWoc1Py sFAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SfBfzQCu; 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 n23-20020a637217000000b004789f4ef89fsi3411991pgc.875.2023.02.03.09.36.48; Fri, 03 Feb 2023 09:37: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=SfBfzQCu; 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 S233813AbjBCRew (ORCPT + 99 others); Fri, 3 Feb 2023 12:34:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39742 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233209AbjBCReC (ORCPT ); Fri, 3 Feb 2023 12:34:02 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32E7CA4292 for ; Fri, 3 Feb 2023 09:34:00 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id n13so4422479wmr.4 for ; Fri, 03 Feb 2023 09:34:00 -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=SfBfzQCuNQe4AnDxzxTU+LJrjLjDaqNCE7rH+vRTD8glqFGZamrCEkLuXvMp+7Tt6P JC/nwiLpa1yrbT6piicwn5pad6GtMxjX4NKVzrYhKHvq9pwXDW17ocwNjDghUDsvCwp+ 2I2kXlGd4cz/IOFm2jaTg6rDtJDYZ6W0CWrkkv9pypQ9WNFfWqkErgzR+QxWUdojtqZJ 0xOxXTPnJLQxDqErP/ARcZS2SZ5XB7N27z9vSwxAJcJ9ODvC4Y8TFw+Q7RuepquU0Wxg uNDoEIC9a6/v/bn26IYlxH8L2mGIuPg0vune8eoCREseaOE/zn7X5GiMBE3sdPDJ0yro /2rQ== 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=AV81yjfIqEmz/omyvdjuDsPN2EA98002eIkwNddGUn5jdhMeHAULyCgZdicDvDSZDm XdoxWZrOCFnO/ShR+6wUIEFheORXzPZjNe8Kur6Rbzf5SnlxLQSlTp6TpOifxkS09P5x 16qzxw/TqOioqNnG/cpcWryLSMVli0GFSv8kJfm8Ax7omi27V8RawEhBrj5nlNloGbOZ 3Dsxec+5Vipi600wpM66+kOEISYgl0jcXKDjQ+4QcL7DH+HkAHCfng4mbXFGWNHeguRz g5uT7XHrASBj3Fk26IrPEu0iyfjCfyFO8mfo43h3g4eduM0Teq+EzLEmVh+RObPouEcw XENg== X-Gm-Message-State: AO0yUKWUuFRcscEMopLYzSftJSoD4I52G42zGho+FXDvuyJexqz83lLM ygXfAx7eANsOdxV+hZOR3K4MWQ== X-Received: by 2002:a05:600c:16c4:b0:3dc:eaef:c1bb with SMTP id l4-20020a05600c16c400b003dceaefc1bbmr10687968wmn.35.1675445638533; Fri, 03 Feb 2023 09:33:58 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z4-20020a05600c0a0400b003dfdeb57027sm5876356wmp.38.2023.02.03.09.33.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:33:58 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: 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 v1 10/11] thermal/acpi: Rewrite the trip point intialization to use the generic thermal trip Date: Fri, 3 Feb 2023 18:33:30 +0100 Message-Id: <20230203173331.3322089-11-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203173331.3322089-1-daniel.lezcano@linaro.org> References: <20230203173331.3322089-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?1756832276658989047?= X-GMAIL-MSGID: =?utf-8?q?1756832276658989047?= 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:33:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 52583 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp969692wrn; Fri, 3 Feb 2023 09:36:55 -0800 (PST) X-Google-Smtp-Source: AK7set90TynHgxdZiJwBMfpw2y2/aaibdaQSD8BDib7Px7Xy4tecsFBae23w18sksKqmAnAgPhHD X-Received: by 2002:a17:90a:35d:b0:230:8452:6794 with SMTP id 29-20020a17090a035d00b0023084526794mr1094756pjf.31.1675445814877; Fri, 03 Feb 2023 09:36:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1675445814; cv=none; d=google.com; s=arc-20160816; b=sTLwxOUqqFUAPiq1WEMEFB6j5BeIDX0eNND4arSNZnd2SXy9O71hTR20Dykt46N4uT ALYroGfu3Mbarb0TjAoerbjLFElW99f6lOVNWl8TOQ/0sOOBYIt6JntWrfUpYGvPwLtK vG2cekNqVxoFXX5stP8wXS+r4L+WvIT6cUDldsqDro8ND//DF+Y3CkO1y+1V2x84WpGG Tdj4fieMUwVUu0dG/esnvsK5FphAJaZsuSdck2MpIA/rz0AfkCZ9NLR+yKBVFRu3IGBh Syj4ums9zPPM1/tGLxC1gF6G3MhBE9r18lE5tqGmmlvJa6vcEpDl9vlNv+bteTlnzCXf n0LQ== 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=v1jm23bKqAdfecJUh5x31wqV5kGYV/iMiWQLCUHrEsc=; b=EHHpQEjC8Vz0+V/YRK/wK0j0+A2Tbam2AfWviB4gjpKCw32PkVgC1icid9PgQOyBDF W/xLIBGdzeHpSSC+aN4mjrQcbrHRWLnXe/fT0gakx6/TD1TFDOUyphmiJX60IIHJX7mH VyokD2HCYk0SnTKHzCCyyMZJRy1OYp/7QYM3XG6QcVfQtERKKoTFXHdMhiCryKVXo+im NgZFP2UeswWi99TZjyNquRpCERaGvC4qvEapP0LgXWcr+NGSBYise3ivwbUkT3+wf0Qd JkQGtcWLVLCegSDkgHFkkOA3hdpNsDesAURNxhbHgnUuY1TS71obWex8U9Q46K75/0py sQiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=e6+R38l+; 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 co11-20020a17090afe8b00b0023088fefca6si74209pjb.31.2023.02.03.09.36.42; Fri, 03 Feb 2023 09:36:54 -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=e6+R38l+; 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 S231614AbjBCReu (ORCPT + 99 others); Fri, 3 Feb 2023 12:34:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232552AbjBCReB (ORCPT ); Fri, 3 Feb 2023 12:34:01 -0500 Received: from mail-wm1-x32b.google.com (mail-wm1-x32b.google.com [IPv6:2a00:1450:4864:20::32b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 25406A428D for ; Fri, 3 Feb 2023 09:34:00 -0800 (PST) Received: by mail-wm1-x32b.google.com with SMTP id u10so1375658wmj.3 for ; Fri, 03 Feb 2023 09:34:00 -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=v1jm23bKqAdfecJUh5x31wqV5kGYV/iMiWQLCUHrEsc=; b=e6+R38l+TvNtRO87bY87KBezjqZ31U0a70n58FykqUxAOKc1ezyr2yuIsfsDmizalx BgIzuWB04fiqMaOFVLmVHMXvCPIZg5E9si0mtCF6tv5VrQ7VTPEckgRycwN7/DkRJ/lq g2EPKJ0XlhlulnT43VcUe3IAWjsGkG96Ubhh1hdjk0N7aGqA+vKjGNUoEZ3T1C5W4Flc 1vgPZi38m5DhaZmMUg2MrXAjk+wYN6+ZS4EAxkoSC+afQmtbxOJOkmWF98OJ9rk3bwE8 XB2IOv5ZC6U/w3sMUGVC4+9jAKH4D23ulCEq50YQwKcBO0xEwKQJcfjely+FkSbhhb32 JM6Q== 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=v1jm23bKqAdfecJUh5x31wqV5kGYV/iMiWQLCUHrEsc=; b=hiSVtsFrcHnAO6LVDj7WLZ8xK6GGSzKjO1RiK+6xv1MaDoG8ec/GMN+jS7tA47PPRo IrLHOTYiAL3yhYG0bIbi37ayp7QGFpkk6lUk+4peujbs8+4j2n3NcXuK/8gwH0LR5OMq a7R7bblc468imVRdXkVdbR7hwv610UfqlmHX6UqpzGMrdutcofRBcc5szNR665Siuc5p U+R2w7cpB05NTYN7RT1LNaZtZQ9vLfol7yxysEMgvc8cVsYozDew2cBCXsRs25c5rjI9 dND1AkPV+W5h6W5mNWxSBG/4oBdde/2d3h5u3jJ3UfMv5NUPPeNW3HCCKuD7epDxQ+gi uqLw== X-Gm-Message-State: AO0yUKXS2O9DxncVWXWj+SAipxJxhs16olD8sokY/7L3KOPCzKc3inmL 9cflsEX0RPLiXT+GDdT6Sn7ntg== X-Received: by 2002:a7b:ce11:0:b0:3dd:37a5:dc90 with SMTP id m17-20020a7bce11000000b003dd37a5dc90mr10372544wmc.32.1675445639608; Fri, 03 Feb 2023 09:33:59 -0800 (PST) Received: from mai.. (146725694.box.freepro.com. [130.180.211.218]) by smtp.gmail.com with ESMTPSA id z4-20020a05600c0a0400b003dfdeb57027sm5876356wmp.38.2023.02.03.09.33.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Feb 2023 09:33:59 -0800 (PST) From: Daniel Lezcano To: rjw@rjwysocki.net Cc: 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 v1 11/11] thermal/acpi: Use the thermal framework ACPI API Date: Fri, 3 Feb 2023 18:33:31 +0100 Message-Id: <20230203173331.3322089-12-daniel.lezcano@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230203173331.3322089-1-daniel.lezcano@linaro.org> References: <20230203173331.3322089-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?1756832270956503014?= X-GMAIL-MSGID: =?utf-8?q?1756832270956503014?= 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 | 75 ++++++++++++++++-------------------------- 1 file changed, 28 insertions(+), 47 deletions(-) diff --git a/drivers/acpi/thermal.c b/drivers/acpi/thermal.c index f89236cd4fcd..3c0652a369f0 100644 --- a/drivers/acpi/thermal.c +++ b/drivers/acpi/thermal.c @@ -259,8 +259,8 @@ 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; + int ret; /* * Module parameters disable the critical trip point @@ -268,14 +268,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_trip_crit(tz->device->handle, &trip); + 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 +281,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 +295,18 @@ 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; + int ret; - status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &temp); - if (ACPI_FAILURE(status)) { - acpi_handle_debug(tz->device->handle, "No hot threshold\n"); + ret = thermal_acpi_trip_hot(tz->device->handle, &trip); + 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 +317,10 @@ 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 thermal_trip trip; + struct acpi_handle_list devices; + int ret; /* * Module parameters disable all passive trip points @@ -337,26 +328,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_trip_psv(tz->device->handle, &trip); + 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 +353,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 +364,11 @@ 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; 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_trip_act(tz->device->handle, &trip, i); + if (ret) break; sprintf(name, "_AL%d", i); @@ -394,16 +378,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)++; }