From patchwork Tue Sep 12 18:35:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 138379 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp612362vqx; Tue, 12 Sep 2023 11:50:48 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFQuaEbFDtJ2I6nc6DE6CcVNXytdAYmo52CLk3p0PnMgq/ZLVT2kZbaTnrsa4K9V0xRjPCw X-Received: by 2002:a05:6358:e4a9:b0:140:f08c:2b55 with SMTP id by41-20020a056358e4a900b00140f08c2b55mr629091rwb.9.1694544648541; Tue, 12 Sep 2023 11:50:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694544648; cv=none; d=google.com; s=arc-20160816; b=Ckt5MKJW+eq+HwJqsq9KslOuhKwo9iuDJoGJPnLDkLIWdaQxCg43dc9/CBKBLrUUBi p8Q3sWtZBpRPMmUOlB0Q+oJu1eRuEaIhTrjzUNkomTEwbz6T1+0IaFHyvbLMWTapWJPv PgJfe8N7Z1gAB1+YdfC23NXEdsy/v6p5pPGkwSGDccIhy4SyW9rJk5GeLbdBWjWhIsa6 TPABl8q1+3y5n+pi+tZsap+B78nA0p91gS0juhB3hAYx/OZuDzvYrr4sGzuytzOR4Uxy bzVAXwyX7k9JF/3TMCN1xDkhEY/3r2AGVofXGyiZZFQuWMKafk5+wRn9/llof94lbuSL P3wA== 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; bh=tGRA61hoGgoCFS0D40TvlDdgqANLMKxkwjDplss986k=; fh=TcRPROXzT9svfC8PL4GA9v01BlJpZsrjV4HRPcpqUxk=; b=l9ChvYjJapOsHv1HhHgbqeNgIsT4ZHMF6NbAilbZnOEjEM39oFQUfr4y5k8gAlkVLi yd1JtnomktGl1BLgrjytpU1b8uwWqgsd/ALp8UHSYrHhZqCOmMLPXp2IqF65MKWoXe2R HcWNFrIDUF6C0RUCjT0zBlN95nTfAMM7u3fhQy4HWJYzw7tLRqMkexat+ne3v+N+EBpL itFOfOLsyvTp5Uo1M1NBRGo0FVmec5432atrUVFqDY4D5IxrC460pcFYAGZUK5rWBPfI i1CnHzTiP4KrIF7ZEkrR2u7kRvJkndphvTLAtCwR9/Ja2HsrrimhgZWITbX7qVILe6Rv 4bkA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id k184-20020a636fc1000000b005702c84e4c2si8092490pgc.508.2023.09.12.11.50.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 11:50:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 55AAE8022841; Tue, 12 Sep 2023 11:49:01 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237546AbjILSsR (ORCPT + 36 others); Tue, 12 Sep 2023 14:48:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237610AbjILSry (ORCPT ); Tue, 12 Sep 2023 14:47:54 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C988A1725; Tue, 12 Sep 2023 11:47:46 -0700 (PDT) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.2.0) id cd625864ca82de2a; Tue, 12 Sep 2023 20:47:45 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id C09AD663BE5; Tue, 12 Sep 2023 20:47:44 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v1 1/9] ACPI: thermal: Simplify initialization of critical and hot trips Date: Tue, 12 Sep 2023 20:35:40 +0200 Message-ID: <4858652.31r3eYUQgx@kreacher> In-Reply-To: <5708760.DvuYhMxLoT@kreacher> References: <5708760.DvuYhMxLoT@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedgudeftdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhhuihdriihhrghnghesihhnthgvlhdrtghomhdprhgtphhtthhopehs rhhinhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Tue, 12 Sep 2023 11:49:01 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776858849256636819 X-GMAIL-MSGID: 1776858849256636819 From: Rafael J. Wysocki Use the observation that the critical and hot trip points are never updated by the ACPI thermal driver, because the flags passed from acpi_thermal_notify() to acpi_thermal_trips_update() do not include ACPI_TRIPS_CRITICAL or ACPI_TRIPS_HOT, to move the initialization of those trip points directly into acpi_thermal_get_trip_points() and reduce the size of __acpi_thermal_trips_update(). Also make the critical and hot trip points initialization code more straightforward and drop the flags that are not needed any more. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano --- drivers/acpi/thermal.c | 130 ++++++++++++++++++++++++------------------------- 1 file changed, 66 insertions(+), 64 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -43,17 +43,13 @@ #define ACPI_THERMAL_MAX_ACTIVE 10 #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65 -#define ACPI_TRIPS_CRITICAL BIT(0) -#define ACPI_TRIPS_HOT BIT(1) -#define ACPI_TRIPS_PASSIVE BIT(2) -#define ACPI_TRIPS_ACTIVE BIT(3) -#define ACPI_TRIPS_DEVICES BIT(4) +#define ACPI_TRIPS_PASSIVE BIT(0) +#define ACPI_TRIPS_ACTIVE BIT(1) +#define ACPI_TRIPS_DEVICES BIT(2) #define ACPI_TRIPS_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE) -#define ACPI_TRIPS_INIT (ACPI_TRIPS_CRITICAL | ACPI_TRIPS_HOT | \ - ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE | \ - ACPI_TRIPS_DEVICES) +#define ACPI_TRIPS_INIT (ACPI_TRIPS_THRESHOLDS | ACPI_TRIPS_DEVICES) /* * This exception is thrown out in two cases: @@ -196,62 +192,6 @@ static void __acpi_thermal_trips_update( bool valid = false; int i; - /* Critical Shutdown */ - if (flag & ACPI_TRIPS_CRITICAL) { - status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp); - tz->trips.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.critical.valid = false; - 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.valid = false; - } else { - tz->trips.critical.valid = true; - acpi_handle_debug(tz->device->handle, - "Found critical threshold [%lu]\n", - tz->trips.critical.temperature); - } - if (tz->trips.critical.valid) { - if (crt == -1) { - tz->trips.critical.valid = false; - } else if (crt > 0) { - unsigned long crt_k = celsius_to_deci_kelvin(crt); - - /* - * Allow override critical threshold - */ - if (crt_k > tz->trips.critical.temperature) - pr_info("Critical threshold %d C\n", crt); - - tz->trips.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.hot.valid = false; - acpi_handle_debug(tz->device->handle, - "No hot threshold\n"); - } else { - tz->trips.hot.temperature = tmp; - tz->trips.hot.valid = true; - acpi_handle_debug(tz->device->handle, - "Found hot threshold [%lu]\n", - tz->trips.hot.temperature); - } - } - /* Passive (optional) */ if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.trip.valid) || flag == ACPI_TRIPS_INIT) { @@ -451,11 +391,73 @@ static void acpi_thermal_trips_update(st dev_name(&adev->dev), event, 0); } +static void acpi_thermal_get_critical_trip(struct acpi_thermal *tz) +{ + unsigned long long tmp; + acpi_status status; + + if (crt > 0) { + tmp = celsius_to_deci_kelvin(crt); + goto set; + } + if (crt == -1) { + acpi_handle_debug(tz->device->handle, "Critical threshold disabled\n"); + goto fail; + } + + status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp); + if (ACPI_FAILURE(status)) { + acpi_handle_debug(tz->device->handle, "No critical threshold\n"); + goto fail; + } + if (tmp <= 2732) { + /* + * Below zero (Celsius) values clearly aren't right for sure, + * so discard them as invalid. + */ + pr_info(FW_BUG "Invalid critical threshold (%llu)\n", tmp); + goto fail; + } + +set: + tz->trips.critical.valid = true; + tz->trips.critical.temperature = tmp; + acpi_handle_debug(tz->device->handle, "Critical threshold [%lu]\n", + tz->trips.critical.temperature); + return; + +fail: + tz->trips.critical.valid = false; + tz->trips.critical.temperature = THERMAL_TEMP_INVALID; +} + +static void acpi_thermal_get_hot_trip(struct acpi_thermal *tz) +{ + unsigned long long tmp; + acpi_status status; + + status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp); + if (ACPI_FAILURE(status)) { + tz->trips.hot.valid = false; + tz->trips.hot.temperature = THERMAL_TEMP_INVALID; + acpi_handle_debug(tz->device->handle, "No hot threshold\n"); + return; + } + + tz->trips.hot.valid = true; + tz->trips.hot.temperature = tmp; + acpi_handle_debug(tz->device->handle, "Hot threshold [%lu]\n", + tz->trips.hot.temperature); +} + static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) { bool valid; int i; + acpi_thermal_get_critical_trip(tz); + acpi_thermal_get_hot_trip(tz); + /* Passive and active trip points (optional). */ __acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); valid = tz->trips.critical.valid | From patchwork Tue Sep 12 18:36:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 138526 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp789034vqx; Tue, 12 Sep 2023 18:30:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHLi5EMhzCwawC2APCGDZ02zggqBdgyTIDL5qmaQu4dtsMKzEKKeTNUOSJ4NIsqslgSChbo X-Received: by 2002:a17:903:32d0:b0:1c3:6667:5ff1 with SMTP id i16-20020a17090332d000b001c366675ff1mr1502830plr.27.1694568602035; Tue, 12 Sep 2023 18:30:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694568602; cv=none; d=google.com; s=arc-20160816; b=qtmDq4DEPKLUR0gUWuAjujShfONTBN24pR3Dzt45ZF+eMGBdmv3Y6Tz1bVoC+DDqWg gZiqqov1XLP6TwxHB8ZUcYYFcv/nGo+cRQxNYI9J5B9/VJbcpHbhaaHboT9rvP9A12rX GZrR+ilGMnVXGHah7iEGtBxkjTcbxQkhU0NyKjYRP2gsT/MhLa9Thz0VTGTg37DeUQ+T WX7mPhaXPqz+3vRtVxO7IcxSSqQb9l4piyiG79oBG26YaP8sPrIT1dlCcEiZpXZH4S5u ut9L40Q4Nv/fPNeaXxUCTkFE1xxLevgSe1xzMck3Sk4Y1JbLySYd+mxlnVHHnVl0riYd Vg5A== 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; bh=I/I5OW+zlY265B/B5Cb8NTi6jPZKFbH0+mKArIVklLY=; fh=TcRPROXzT9svfC8PL4GA9v01BlJpZsrjV4HRPcpqUxk=; b=lomOVyTIikX/yAbUC2CF0WnyX7rZyxDYFl+jVDwwWF51lnpvMg8bfTso04qocMehEH 52KjWHoRh9Ms3jnvzEOutR3+JM1dYBlQzQk7MMrS5mn+JhPBp0Z/wdkzUNvv3ZmbSjWP nKF7nSM0O8rtJFfc7oJk+WbokHY4gBH1YJmmMvnY7ixkc+OVedWfyphJoKvXTHJFwmVg mm0DnGSXRarAN68M3mzcRJjI7ouF2Gh33XRiA0NqmP+aui5BcMBeSU9hi4g+NU6NNC9t Nh1lmc9yEl/Fh9jYgBM+PrjDRX2qwAItDGfsw3WIRd/vo2MqM3OK68dMzmyNexE5S3EW lfWw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id m9-20020a170902db0900b001b801bd7fbasi9614792plx.417.2023.09.12.18.29.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 18:30:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id C3B5787182BF; Tue, 12 Sep 2023 11:48:09 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237695AbjILSsF (ORCPT + 36 others); Tue, 12 Sep 2023 14:48:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41250 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237606AbjILSry (ORCPT ); Tue, 12 Sep 2023 14:47:54 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B23751722; Tue, 12 Sep 2023 11:47:45 -0700 (PDT) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.2.0) id d5ab5436fc065d13; Tue, 12 Sep 2023 20:47:44 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id AAB59663BE5; Tue, 12 Sep 2023 20:47:43 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v1 2/9] ACPI: thermal: Fold acpi_thermal_get_info() into its caller Date: Tue, 12 Sep 2023 20:36:21 +0200 Message-ID: <2296248.ElGaqSPkdT@kreacher> In-Reply-To: <5708760.DvuYhMxLoT@kreacher> References: <5708760.DvuYhMxLoT@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedgudeftdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhhuihdriihhrghnghesihhnthgvlhdrtghomhdprhgtphhtthhopehs rhhinhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Sep 2023 11:48:09 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776883966126935440 X-GMAIL-MSGID: 1776883966126935440 From: Rafael J. Wysocki There is only one caller of acpi_thermal_get_info() and the code from it can be folded into its caller just fine, so do that. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano --- drivers/acpi/thermal.c | 52 +++++++++++++++++-------------------------------- 1 file changed, 19 insertions(+), 33 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -846,38 +846,6 @@ static void acpi_thermal_aml_dependency_ acpi_evaluate_integer(handle, "_TMP", NULL, &value); } -static int acpi_thermal_get_info(struct acpi_thermal *tz) -{ - int result; - - if (!tz) - return -EINVAL; - - acpi_thermal_aml_dependency_fix(tz); - - /* Get trip points [_CRT, _PSV, etc.] (required) */ - result = acpi_thermal_get_trip_points(tz); - if (result) - return result; - - /* Get temperature [_TMP] (required) */ - result = acpi_thermal_get_temperature(tz); - if (result) - return result; - - /* Set the cooling mode [_SCP] to active cooling (default) */ - acpi_execute_simple_method(tz->device->handle, "_SCP", - ACPI_THERMAL_MODE_ACTIVE); - - /* Get default polling frequency [_TZP] (optional) */ - if (tzp) - tz->polling_frequency = tzp; - else - acpi_thermal_get_polling_frequency(tz); - - return 0; -} - /* * The exact offset between Kelvin and degree Celsius is 273.15. However ACPI * handles temperature values with a single decimal place. As a consequence, @@ -940,10 +908,28 @@ static int acpi_thermal_add(struct acpi_ strcpy(acpi_device_class(device), ACPI_THERMAL_CLASS); device->driver_data = tz; - result = acpi_thermal_get_info(tz); + acpi_thermal_aml_dependency_fix(tz); + + /* Get trip points [_CRT, _PSV, etc.] (required). */ + result = acpi_thermal_get_trip_points(tz); if (result) goto free_memory; + /* Get temperature [_TMP] (required). */ + result = acpi_thermal_get_temperature(tz); + if (result) + goto free_memory; + + /* Set the cooling mode [_SCP] to active cooling. */ + acpi_execute_simple_method(tz->device->handle, "_SCP", + ACPI_THERMAL_MODE_ACTIVE); + + /* Determine the default polling frequency [_TZP]. */ + if (tzp) + tz->polling_frequency = tzp; + else + acpi_thermal_get_polling_frequency(tz); + acpi_thermal_guess_offset(tz); result = acpi_thermal_register_thermal_zone(tz); From patchwork Tue Sep 12 18:37:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 138761 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp1029190vqx; Wed, 13 Sep 2023 04:59:13 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhFs3C0skwCkJGcvYUdVHw58lVBNyDRNmAzDzrfNFfi9NfZtTqN6SZ8h+Vv/8NbX7GG8BI X-Received: by 2002:a05:6808:157:b0:3a7:60f7:c9ad with SMTP id h23-20020a056808015700b003a760f7c9admr2294815oie.13.1694606353518; Wed, 13 Sep 2023 04:59:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694606353; cv=none; d=google.com; s=arc-20160816; b=nr7bK71STMfbyt+VhNVm+LnYdt0DJmjsZHz6EIdtcgKhbw7MOqPwQ4vHy/jkJoHN2x C/bRzWKrJvPp4FpMOpFVJeQhbSi5TO9xRRWqPcHolXKklo9U9KR+eStyXteetzyu8Qi4 7hSJvV4qPSs/7ABS5Kxlw+mP0iEvkzuMp5xaNCz2EAUVDMpSRWz+V2mRCZnG0FQbcFch nAdPV5bQmjICEcA6zIPHs5dPAml/LfGWUOXh6VmQJC1NbSVDzFWeed7glhLWwqf6e51D n1NOibOQp/VoLclhYm0UnXKQZ3OGfY+5b9hwXfz1sAZLVqQYMLvKpuWUa+zjS/A4x4Gf R2KA== 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; bh=RrWN44HYNRqOADuMcYuxSH5ajqM9v+NFgeaFOpUM+zo=; fh=TcRPROXzT9svfC8PL4GA9v01BlJpZsrjV4HRPcpqUxk=; b=Dh2jEKUo+/5ZFr84ucl3e666TmiAi58wwO6VDZEXV3xvlSi9Flk4Jwb2pQ3EezPL5v y4COyZyM12Joos1/+JYIP/uTWu/1pwTCTBo8cbARr5UKmb115hp8QyJWW/8H16XoVBIh MaRvQL7ag6AAr6DuxclyFJx/2051rEbeMJO3er6EoS28Pwdpj9NzCJo8T/n51XA9grUl tVGR1v7QHclUGns9A/nJepxloJvhUpiiA6+lJrQDdLR4XKexI9NKUr7zVgpPadQQLX2k 3/qd9lHn1nmOnSVQgITNG+lfE4TKwTSHPWEVBxBNVU39M66C71EToc19ZPdeBJGXM+Ey +6zA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id k15-20020a6568cf000000b00565f294417bsi9933938pgt.426.2023.09.13.04.59.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 04:59:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 4BD5F801B919; Tue, 12 Sep 2023 11:48:07 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237687AbjILSsD (ORCPT + 36 others); Tue, 12 Sep 2023 14:48:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41220 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237590AbjILSry (ORCPT ); Tue, 12 Sep 2023 14:47:54 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DD9C21716; Tue, 12 Sep 2023 11:47:43 -0700 (PDT) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.2.0) id 1f78031281b7904c; Tue, 12 Sep 2023 20:47:42 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id E0F5A663BE5; Tue, 12 Sep 2023 20:47:41 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v1 3/9] ACPI: thermal: Determine the number of trip points earlier Date: Tue, 12 Sep 2023 20:37:59 +0200 Message-ID: <1863318.tdWV9SEqCh@kreacher> In-Reply-To: <5708760.DvuYhMxLoT@kreacher> References: <5708760.DvuYhMxLoT@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedgudeftdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhhuihdriihhrghnghesihhnthgvlhdrtghomhdprhgtphhtthhopehs rhhinhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 12 Sep 2023 11:48:07 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776923551642372617 X-GMAIL-MSGID: 1776923551642372617 From: Rafael J. Wysocki Compute the number of trip points in acpi_thermal_add() so as to allow the driver's data structures to be simplified going forward. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano --- drivers/acpi/thermal.c | 60 +++++++++++++++++++++++-------------------------- 1 file changed, 29 insertions(+), 31 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -452,7 +452,7 @@ static void acpi_thermal_get_hot_trip(st static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) { - bool valid; + unsigned int count = 0; int i; acpi_thermal_get_critical_trip(tz); @@ -460,18 +460,24 @@ static int acpi_thermal_get_trip_points( /* Passive and active trip points (optional). */ __acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); - valid = tz->trips.critical.valid | - tz->trips.hot.valid | - tz->trips.passive.trip.valid; - - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) - valid = valid || tz->trips.active[i].trip.valid; - - if (!valid) { - pr_warn(FW_BUG "No valid trip found\n"); - return -ENODEV; + if (tz->trips.critical.valid) + count++; + + if (tz->trips.hot.valid) + count++; + + if (tz->trips.passive.trip.valid) + count++; + + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + if (tz->trips.active[i].trip.valid) + count++; + else + break; + } - return 0; + + return count; } /* sys I/F for generic thermal sysfs support */ @@ -681,29 +687,15 @@ static void acpi_thermal_zone_sysfs_remo sysfs_remove_link(&tzdev->kobj, "device"); } -static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz) +static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz, + unsigned int trip_count) { struct acpi_thermal_trip *acpi_trip; struct thermal_trip *trip; int passive_delay = 0; - int trip_count = 0; int result; int i; - if (tz->trips.critical.valid) - trip_count++; - - if (tz->trips.hot.valid) - trip_count++; - - if (tz->trips.passive.trip.valid) { - trip_count++; - passive_delay = tz->trips.passive.tsp * 100; - } - - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE && tz->trips.active[i].trip.valid; i++) - trip_count++; - trip = kcalloc(trip_count, sizeof(*trip), GFP_KERNEL); if (!trip) return -ENOMEM; @@ -724,6 +716,8 @@ static int acpi_thermal_register_thermal acpi_trip = &tz->trips.passive.trip; if (acpi_trip->valid) { + passive_delay = tz->trips.passive.tsp * 100; + trip->type = THERMAL_TRIP_PASSIVE; trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature); trip->priv = acpi_trip; @@ -893,6 +887,7 @@ static void acpi_thermal_check_fn(struct static int acpi_thermal_add(struct acpi_device *device) { struct acpi_thermal *tz; + unsigned int trip_count; int result; if (!device) @@ -911,9 +906,12 @@ static int acpi_thermal_add(struct acpi_ acpi_thermal_aml_dependency_fix(tz); /* Get trip points [_CRT, _PSV, etc.] (required). */ - result = acpi_thermal_get_trip_points(tz); - if (result) + trip_count = acpi_thermal_get_trip_points(tz); + if (!trip_count) { + pr_warn(FW_BUG "No valid trip points!\n"); + result = -ENODEV; goto free_memory; + } /* Get temperature [_TMP] (required). */ result = acpi_thermal_get_temperature(tz); @@ -932,7 +930,7 @@ static int acpi_thermal_add(struct acpi_ acpi_thermal_guess_offset(tz); - result = acpi_thermal_register_thermal_zone(tz); + result = acpi_thermal_register_thermal_zone(tz, trip_count); if (result) goto free_memory; From patchwork Tue Sep 12 18:39:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 138767 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp1037239vqx; Wed, 13 Sep 2023 05:09:57 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEoH99aYbsxYaMq/i7oQ99jj1FejloYhbS8UCWSxldMAweyzLOq8ojgex1AQISD2uWSIQtl X-Received: by 2002:a05:6a00:2315:b0:68f:bd37:13df with SMTP id h21-20020a056a00231500b0068fbd3713dfmr2628260pfh.16.1694606996912; Wed, 13 Sep 2023 05:09:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694606996; cv=none; d=google.com; s=arc-20160816; b=XtR90CBqB/GZwDiLbhhRhmZiRUwHH7T2vXAdqwpd+vxm1rxa7uLY8WlI4eLl7ie8D5 EOwbnjbAP/ThZYKybNNrB2D1OKJYZgMt1vWsthhRS25Kbj3ythlYvsTz/XVxI+bVBzwL 9JlbCXoBVsEWejirB/VVxIr/kgFNZlgxxggfl7JNcxXud2F13qV+ITTlqEFSKG5F17B/ gM+XVgkWIRKJdbFUM9qIKpJLttN9+4U2nwlefIu6yPIaG4MuVb0O/Q5Nh7KU9+9p7I17 G50+2HWmW7ZCnz7UEXjpxOqWqsdC/4n7lu8Rh8II4xp2hwmUbMiX3gpIgp3vSkquGrrH rpMA== 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; bh=KlJVeZmf+f7fjZS8Go7E7VtWeFFTNpMbzvovQpSsGrs=; fh=TcRPROXzT9svfC8PL4GA9v01BlJpZsrjV4HRPcpqUxk=; b=ujuxjgL2gADvuOjXG2dtcwlUQIokGnBm2s5YEzIi6zVZzsZs5z/rY+C5kc9J1ZYMCM qNwgoykZqzVMT4U1wd6E6BeTgL8jOtPu2CK3MC4iLNTriQYBy2IC6fl7nXKraRB3S13d /hOBMbFbqIjsD4Fi/Kc6EMuX53th/1c0E/os4I1aQwtDPSvqYd9scql6jqmGntc4CJYW Q3F0A6XemWkV4L5VzC+vkoGhP9PUswI/XAzSl39IJaSYulZeJ9sDs/e6DYzFTLckRdab a01Of0eX7HnfrcZ5c/o6enFCuHbN6wCZ4SDIG8eOuAFZdYNnQ9dlYgwYNw91/T1sqeAZ F1Cw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id cn3-20020a056a00340300b0068ffeb6a949si1402391pfb.73.2023.09.13.05.09.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 05:09:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 929B4801B9D2; Tue, 12 Sep 2023 11:48:04 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237585AbjILSsA (ORCPT + 36 others); Tue, 12 Sep 2023 14:48:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46458 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237545AbjILSry (ORCPT ); Tue, 12 Sep 2023 14:47:54 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0D64E1705; Tue, 12 Sep 2023 11:47:41 -0700 (PDT) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.2.0) id 25b387b3422685a1; Tue, 12 Sep 2023 20:47:40 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id CE019663BE5; Tue, 12 Sep 2023 20:47:39 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v1 4/9] ACPI: thermal: Create and populate trip points table earlier Date: Tue, 12 Sep 2023 20:39:15 +0200 Message-ID: <13346091.uLZWGnKmhe@kreacher> In-Reply-To: <5708760.DvuYhMxLoT@kreacher> References: <5708760.DvuYhMxLoT@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedgudefudcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhhuihdriihhrghnghesihhnthgvlhdrtghomhdprhgtphhtthhopehs rhhinhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Tue, 12 Sep 2023 11:48:04 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776924226000453535 X-GMAIL-MSGID: 1776924226000453535 From: Rafael J. Wysocki Create and populate the driver's trip points table in acpi_thermal_add() so as to allow the its data structures to be simplified going forward. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano --- drivers/acpi/thermal.c | 105 ++++++++++++++++++++++++------------------------- 1 file changed, 52 insertions(+), 53 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -688,53 +688,10 @@ static void acpi_thermal_zone_sysfs_remo } static int acpi_thermal_register_thermal_zone(struct acpi_thermal *tz, - unsigned int trip_count) + unsigned int trip_count, + int passive_delay) { - struct acpi_thermal_trip *acpi_trip; - struct thermal_trip *trip; - int passive_delay = 0; int result; - int i; - - trip = kcalloc(trip_count, sizeof(*trip), GFP_KERNEL); - if (!trip) - return -ENOMEM; - - tz->trip_table = trip; - - if (tz->trips.critical.valid) { - trip->type = THERMAL_TRIP_CRITICAL; - trip->temperature = acpi_thermal_temp(tz, tz->trips.critical.temperature); - trip++; - } - - if (tz->trips.hot.valid) { - trip->type = THERMAL_TRIP_HOT; - trip->temperature = acpi_thermal_temp(tz, tz->trips.hot.temperature); - trip++; - } - - acpi_trip = &tz->trips.passive.trip; - if (acpi_trip->valid) { - passive_delay = tz->trips.passive.tsp * 100; - - trip->type = THERMAL_TRIP_PASSIVE; - trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature); - trip->priv = acpi_trip; - trip++; - } - - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - acpi_trip = &tz->trips.active[i].trip; - - if (!acpi_trip->valid) - break; - - trip->type = THERMAL_TRIP_ACTIVE; - trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature); - trip->priv = acpi_trip; - trip++; - } tz->thermal_zone = thermal_zone_device_register_with_trips("acpitz", tz->trip_table, @@ -744,10 +701,8 @@ static int acpi_thermal_register_thermal NULL, passive_delay, tz->polling_frequency * 100); - if (IS_ERR(tz->thermal_zone)) { - result = PTR_ERR(tz->thermal_zone); - goto free_trip_table; - } + if (IS_ERR(tz->thermal_zone)) + return PTR_ERR(tz->thermal_zone); result = acpi_thermal_zone_sysfs_add(tz); if (result) @@ -766,8 +721,6 @@ remove_links: acpi_thermal_zone_sysfs_remove(tz); unregister_tzd: thermal_zone_device_unregister(tz->thermal_zone); -free_trip_table: - kfree(tz->trip_table); return result; } @@ -886,9 +839,13 @@ static void acpi_thermal_check_fn(struct static int acpi_thermal_add(struct acpi_device *device) { + struct acpi_thermal_trip *acpi_trip; + struct thermal_trip *trip; struct acpi_thermal *tz; unsigned int trip_count; + int passive_delay = 0; int result; + int i; if (!device) return -EINVAL; @@ -930,9 +887,49 @@ static int acpi_thermal_add(struct acpi_ acpi_thermal_guess_offset(tz); - result = acpi_thermal_register_thermal_zone(tz, trip_count); + trip = kcalloc(trip_count, sizeof(*trip), GFP_KERNEL); + if (!trip) + return -ENOMEM; + + tz->trip_table = trip; + + if (tz->trips.critical.valid) { + trip->type = THERMAL_TRIP_CRITICAL; + trip->temperature = acpi_thermal_temp(tz, tz->trips.critical.temperature); + trip++; + } + + if (tz->trips.hot.valid) { + trip->type = THERMAL_TRIP_HOT; + trip->temperature = acpi_thermal_temp(tz, tz->trips.hot.temperature); + trip++; + } + + acpi_trip = &tz->trips.passive.trip; + if (acpi_trip->valid) { + passive_delay = tz->trips.passive.tsp * 100; + + trip->type = THERMAL_TRIP_PASSIVE; + trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature); + trip->priv = acpi_trip; + trip++; + } + + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { + acpi_trip = &tz->trips.active[i].trip; + + if (!acpi_trip->valid) + break; + + trip->type = THERMAL_TRIP_ACTIVE; + trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature); + trip->priv = acpi_trip; + trip++; + } + + result = acpi_thermal_register_thermal_zone(tz, trip_count, passive_delay); if (result) - goto free_memory; + goto free_trips; refcount_set(&tz->thermal_check_count, 3); mutex_init(&tz->thermal_check_lock); @@ -951,6 +948,8 @@ static int acpi_thermal_add(struct acpi_ flush_wq: flush_workqueue(acpi_thermal_pm_queue); acpi_thermal_unregister_thermal_zone(tz); +free_trips: + kfree(tz->trip_table); free_memory: kfree(tz); From patchwork Tue Sep 12 18:41:06 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 138534 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp792886vqx; Tue, 12 Sep 2023 18:40:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHJbIZVfujmDHGHEhQBooN435Dd8JyU3Np7jDLn9lRMcH0aTXSV/iiOLDUnunHswUOmn0T7 X-Received: by 2002:a05:6a20:42a4:b0:14c:a53c:498e with SMTP id o36-20020a056a2042a400b0014ca53c498emr1179000pzj.42.1694569258352; Tue, 12 Sep 2023 18:40:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694569258; cv=none; d=google.com; s=arc-20160816; b=UNQXb1ngxE4Dtiv6KYMxapOdNj+N6CXpY3jALc8DDMM0+grdqfNtnUe6iEnqPaekWh 7YAobV/IoKDbEYPZW/6hCJg3RTDb1coYdb34fiLcZs03HYMJJOwXAHBU+33toieiO0+0 q5btCSRGGGCDqdPEy3Nsaj3o3gD0Zl9DS9kXD6f6gLgGX7CgGyfxnbEBv4NFqRE1hBX2 bSY6NYdF7dMOuaJHdWoG4OBkVUA3bkDukvP2AgjCFa4qY+xRT4atO7qhwVHyXIp8LZFA fJfqGwFIWPrmu8pUEDdSou/l8Ac3rQzugD8hZyGBc/Zq1hjWUNXa4wayu4HESqvsdj/3 4AVA== 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; bh=VMYWgrMrCC5CLhqCRebE0VdH6rfufE7NmRhQDIlP0Ew=; fh=TcRPROXzT9svfC8PL4GA9v01BlJpZsrjV4HRPcpqUxk=; b=UqYKF+0cwAsOw/UKdP0J8NnKK/s75GMZ3klzzH+ss+Pb8CuR8taLh3Wz1hGYm9CcD6 Kh0aa26XQmYdsf36OvYMsr7ZAj5UkWVqgjC7By7xvKb7WBEfcNJYIrJoim5GlwP2atdD 9dHm5JUUkU92wW6HaIw3VmZ3H15B2o5FYpIUHzgeos5SoBaufXWkJ45F1cBKX0c1+Tft G+RgElEcjuP4eetwzEYFpmgIzAxjOH7VeUSSdq3qHTp1ZdRxT9eJJJ/murYOLpbgnAzd BPryy3fp5zVCl3SDmpYBrjo15LVOyU9DBsUOwExnLuB5LVKmBIqqtC7TK/NZ0IpUrJIz qvRw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id cx19-20020a17090afd9300b002691d885301si533497pjb.0.2023.09.12.18.40.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 18:40:58 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 4300E84EBE15; Tue, 12 Sep 2023 11:48:05 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237518AbjILSr6 (ORCPT + 36 others); Tue, 12 Sep 2023 14:47:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46494 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237535AbjILSrp (ORCPT ); Tue, 12 Sep 2023 14:47:45 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F0A7F10F6; Tue, 12 Sep 2023 11:47:40 -0700 (PDT) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.2.0) id 14a9d9dd490c3409; Tue, 12 Sep 2023 20:47:39 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 81E38663C2D; Tue, 12 Sep 2023 20:47:38 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v1 5/9] ACPI: thermal: Simplify critical and hot trips representation Date: Tue, 12 Sep 2023 20:41:06 +0200 Message-ID: <3249479.aeNJFYEL58@kreacher> In-Reply-To: <5708760.DvuYhMxLoT@kreacher> References: <5708760.DvuYhMxLoT@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedgudeftdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhhuihdriihhrghnghesihhnthgvlhdrtghomhdprhgtphhtthhopehs rhhinhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Sep 2023 11:48:05 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776884654432699344 X-GMAIL-MSGID: 1776884654432699344 From: Rafael J. Wysocki Notice that the only piece of information regarding the critical and hot trips that needs to be stored in the driver's local data structures is whether or not these trips are valid, so drop all of the redundant information from there and adjust the code accordingly. Among other things, this requires acpi_thermal_add() to be rearranged so as to obtain the critical trip temperature before populating the trip points table and for symmetry, the hot trip temperature is obtained earlier too. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano --- drivers/acpi/thermal.c | 69 +++++++++++++++++++++++-------------------------- 1 file changed, 33 insertions(+), 36 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -107,10 +107,10 @@ struct acpi_thermal_active { }; struct acpi_thermal_trips { - struct acpi_thermal_trip critical; - struct acpi_thermal_trip hot; struct acpi_thermal_passive passive; struct acpi_thermal_active active[ACPI_THERMAL_MAX_ACTIVE]; + bool critical_valid; + bool hot_valid; }; struct acpi_thermal { @@ -391,7 +391,7 @@ static void acpi_thermal_trips_update(st dev_name(&adev->dev), event, 0); } -static void acpi_thermal_get_critical_trip(struct acpi_thermal *tz) +static long acpi_thermal_get_critical_trip(struct acpi_thermal *tz) { unsigned long long tmp; acpi_status status; @@ -420,34 +420,30 @@ static void acpi_thermal_get_critical_tr } set: - tz->trips.critical.valid = true; - tz->trips.critical.temperature = tmp; - acpi_handle_debug(tz->device->handle, "Critical threshold [%lu]\n", - tz->trips.critical.temperature); - return; + tz->trips.critical_valid = true; + acpi_handle_debug(tz->device->handle, "Critical threshold [%llu]\n", tmp); + return tmp; fail: - tz->trips.critical.valid = false; - tz->trips.critical.temperature = THERMAL_TEMP_INVALID; + tz->trips.critical_valid = false; + return THERMAL_TEMP_INVALID; } -static void acpi_thermal_get_hot_trip(struct acpi_thermal *tz) +static long acpi_thermal_get_hot_trip(struct acpi_thermal *tz) { unsigned long long tmp; acpi_status status; status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp); if (ACPI_FAILURE(status)) { - tz->trips.hot.valid = false; - tz->trips.hot.temperature = THERMAL_TEMP_INVALID; + tz->trips.hot_valid = false; acpi_handle_debug(tz->device->handle, "No hot threshold\n"); - return; + return THERMAL_TEMP_INVALID; } - tz->trips.hot.valid = true; - tz->trips.hot.temperature = tmp; - acpi_handle_debug(tz->device->handle, "Hot threshold [%lu]\n", - tz->trips.hot.temperature); + tz->trips.hot_valid = true; + acpi_handle_debug(tz->device->handle, "Hot threshold [%llu]\n", tmp); + return tmp; } static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) @@ -455,17 +451,9 @@ static int acpi_thermal_get_trip_points( unsigned int count = 0; int i; - acpi_thermal_get_critical_trip(tz); - acpi_thermal_get_hot_trip(tz); /* Passive and active trip points (optional). */ __acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); - if (tz->trips.critical.valid) - count++; - - if (tz->trips.hot.valid) - count++; - if (tz->trips.passive.trip.valid) count++; @@ -578,10 +566,10 @@ static int acpi_thermal_cooling_device_c int trip = -1; int result = 0; - if (tz->trips.critical.valid) + if (tz->trips.critical_valid) trip++; - if (tz->trips.hot.valid) + if (tz->trips.hot_valid) trip++; if (tz->trips.passive.trip.valid) { @@ -803,10 +791,9 @@ static void acpi_thermal_aml_dependency_ * The heuristic below should work for all ACPI thermal zones which have a * critical trip point with a value being a multiple of 0.5 degree Celsius. */ -static void acpi_thermal_guess_offset(struct acpi_thermal *tz) +static void acpi_thermal_guess_offset(struct acpi_thermal *tz, long crit_temp) { - if (tz->trips.critical.valid && - (tz->trips.critical.temperature % 5) == 1) + if (tz->trips.critical_valid && crit_temp % 5 == 1) tz->kelvin_offset = 273100; else tz->kelvin_offset = 273200; @@ -843,6 +830,7 @@ static int acpi_thermal_add(struct acpi_ struct thermal_trip *trip; struct acpi_thermal *tz; unsigned int trip_count; + int crit_temp, hot_temp; int passive_delay = 0; int result; int i; @@ -864,6 +852,15 @@ static int acpi_thermal_add(struct acpi_ /* Get trip points [_CRT, _PSV, etc.] (required). */ trip_count = acpi_thermal_get_trip_points(tz); + + crit_temp = acpi_thermal_get_critical_trip(tz); + if (tz->trips.critical_valid) + trip_count++; + + hot_temp = acpi_thermal_get_hot_trip(tz); + if (tz->trips.hot_valid) + trip_count++; + if (!trip_count) { pr_warn(FW_BUG "No valid trip points!\n"); result = -ENODEV; @@ -885,7 +882,7 @@ static int acpi_thermal_add(struct acpi_ else acpi_thermal_get_polling_frequency(tz); - acpi_thermal_guess_offset(tz); + acpi_thermal_guess_offset(tz, crit_temp); trip = kcalloc(trip_count, sizeof(*trip), GFP_KERNEL); if (!trip) @@ -893,15 +890,15 @@ static int acpi_thermal_add(struct acpi_ tz->trip_table = trip; - if (tz->trips.critical.valid) { + if (tz->trips.critical_valid) { trip->type = THERMAL_TRIP_CRITICAL; - trip->temperature = acpi_thermal_temp(tz, tz->trips.critical.temperature); + trip->temperature = acpi_thermal_temp(tz, crit_temp); trip++; } - if (tz->trips.hot.valid) { + if (tz->trips.hot_valid) { trip->type = THERMAL_TRIP_HOT; - trip->temperature = acpi_thermal_temp(tz, tz->trips.hot.temperature); + trip->temperature = acpi_thermal_temp(tz, hot_temp); trip++; } From patchwork Tue Sep 12 18:43:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 138533 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp792647vqx; Tue, 12 Sep 2023 18:40:19 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF/hAnXRlohMMS3Y2sSA66jIYaDc1HMKKKR/UG6optmNwjub34eP07EYfSY7w6ljHvh+lLA X-Received: by 2002:a05:6a20:6a0b:b0:153:b245:50ff with SMTP id p11-20020a056a206a0b00b00153b24550ffmr1206518pzk.40.1694569218864; Tue, 12 Sep 2023 18:40:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694569218; cv=none; d=google.com; s=arc-20160816; b=D97SQcEWJgUKz1wq9AMNexkB/MpECsP3wHdtKblVMRwFXubmzJOLz2j08GXZq10eu2 csdFwlHPegMKJ3jFVy4y4f72dvKgQ0uPwA9YAKM06p09CRYkiSmp1nSJxxHKok0E8H1V ejLNM99IDoiV4m4Tr+knljILhS4deU13AFKlU4dr2yRGD6y8v1Dw/Zq9tMGoqhbtZt90 bNR720koExMvTDPsm/4RNL1iG8crccIqDPeXuqe4XK2xJBwo5zPimfHHrqoVaqJPMjln 3py5h2EHYntyfKrfmXzxPu+ijKCUKLxAPDt1XBkePEW2krWP2X5hvOpVGGtcy1rqECq6 v61g== 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; bh=n9gu5H241x8mOGJA4ZbA5wxxJn59eEH5Kf6RO748PBw=; fh=TcRPROXzT9svfC8PL4GA9v01BlJpZsrjV4HRPcpqUxk=; b=Nwr2xkC7/vCVw08B0fAFAU4FfPWAVHqLdYaCpP2W/A74E0nF2RZc6aw8JkLP/9tNDX XInSR/UeRf3O/MVJSmXXtWIZnEKznu801JcjQSyA+PtkjYK/t0KiFpH0hYz0sZiqxr7Q l935xTNbBmHP/AVyROfeHziVRCTNIbUWf4/vZBXbe+XVODIY5uCcLBAEDmmHpHNxr5iu 3ILF80V69apeIrXXnVQTVLa0RWGRavaG/1MV1N2xxxIlyjiMFCnDPbrg+FhKT+OfO4ge NQFUmu6bilYF7C13QuLpdwXT/OqRdzQFi50ROiDl5Ks9HGF9IGn6cLHDuMY4v8YbDQ3f BmJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [23.128.96.34]) by mx.google.com with ESMTPS id ob6-20020a17090b390600b0025bec4468c2si567548pjb.167.2023.09.12.18.40.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 18:40:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) client-ip=23.128.96.34; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.34 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 969D784D60C4; Tue, 12 Sep 2023 11:47:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237644AbjILSr4 (ORCPT + 36 others); Tue, 12 Sep 2023 14:47:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46476 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237523AbjILSro (ORCPT ); Tue, 12 Sep 2023 14:47:44 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ADBBA10DF; Tue, 12 Sep 2023 11:47:39 -0700 (PDT) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.2.0) id b410579ed5f883e6; Tue, 12 Sep 2023 20:47:38 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 36EB3663BE5; Tue, 12 Sep 2023 20:47:37 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v1 6/9] ACPI: thermal: Untangle initialization and updates of the passive trip Date: Tue, 12 Sep 2023 20:43:52 +0200 Message-ID: <1942063.PYKUYFuaPT@kreacher> In-Reply-To: <5708760.DvuYhMxLoT@kreacher> References: <5708760.DvuYhMxLoT@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedgudeftdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhhuihdriihhrghnghesihhnthgvlhdrtghomhdprhgtphhtthhopehs rhhinhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Sep 2023 11:47:58 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776884613107191432 X-GMAIL-MSGID: 1776884613107191432 From: Rafael J. Wysocki Separate the code needed to update the passive trip (in a response to a notification from the platform firmware) as well as to initialize it from the code that is only necessary for its initialization and cleanly divide it into functions that each carry out a specific action. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano --- drivers/acpi/thermal.c | 198 ++++++++++++++++++++++++++++++------------------- 1 file changed, 125 insertions(+), 73 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -192,73 +192,6 @@ static void __acpi_thermal_trips_update( bool valid = false; int i; - /* Passive (optional) */ - if (((flag & ACPI_TRIPS_PASSIVE) && tz->trips.passive.trip.valid) || - flag == ACPI_TRIPS_INIT) { - valid = tz->trips.passive.trip.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.passive.trip.valid = false; - } else { - tz->trips.passive.trip.temperature = tmp; - tz->trips.passive.trip.valid = true; - if (flag == ACPI_TRIPS_INIT) { - status = acpi_evaluate_integer(tz->device->handle, - "_TC1", NULL, &tmp); - if (ACPI_FAILURE(status)) - tz->trips.passive.trip.valid = false; - else - tz->trips.passive.tc1 = tmp; - - status = acpi_evaluate_integer(tz->device->handle, - "_TC2", NULL, &tmp); - if (ACPI_FAILURE(status)) - tz->trips.passive.trip.valid = false; - else - tz->trips.passive.tc2 = tmp; - - status = acpi_evaluate_integer(tz->device->handle, - "_TSP", NULL, &tmp); - if (ACPI_FAILURE(status)) - tz->trips.passive.trip.valid = false; - else - tz->trips.passive.tsp = tmp; - } - } - } - if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.passive.trip.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.trip.valid = false; - } else { - tz->trips.passive.trip.valid = true; - } - - if (memcmp(&tz->trips.passive.devices, &devices, - sizeof(struct acpi_handle_list))) { - memcpy(&tz->trips.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.trip.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' }; @@ -339,6 +272,72 @@ static void __acpi_thermal_trips_update( } } +static void update_acpi_thermal_trip_temp(struct acpi_thermal_trip *acpi_trip, + int temp) +{ + acpi_trip->valid = temp != THERMAL_TEMP_INVALID; + acpi_trip->temperature = temp; +} + +static long get_passive_temp(struct acpi_thermal *tz) +{ + unsigned long long tmp; + acpi_status status; + + status = acpi_evaluate_integer(tz->device->handle, "_PSV", NULL, &tmp); + if (ACPI_FAILURE(status)) + return THERMAL_TEMP_INVALID; + + return tmp; +} + +static void acpi_thermal_update_passive_trip(struct acpi_thermal *tz) +{ + struct acpi_thermal_trip *acpi_trip = &tz->trips.passive.trip; + + if (!acpi_trip->valid || psv > 0) + return; + + update_acpi_thermal_trip_temp(acpi_trip, get_passive_temp(tz)); + if (!acpi_trip->valid) + ACPI_THERMAL_TRIPS_EXCEPTION(ACPI_TRIPS_PASSIVE, tz, "state"); +} + +static bool update_passive_devices(struct acpi_thermal *tz, bool compare) +{ + struct acpi_handle_list devices; + acpi_status status; + + memset(&devices, 0, sizeof(devices)); + + status = acpi_evaluate_reference(tz->device->handle, "_PSL", NULL, &devices); + if (ACPI_FAILURE(status)) { + acpi_handle_info(tz->device->handle, + "Missing device list for passive threshold\n"); + return false; + } + + if (compare && memcmp(&tz->trips.passive.devices, &devices, sizeof(devices))) + ACPI_THERMAL_TRIPS_EXCEPTION(ACPI_TRIPS_PASSIVE, tz, "device"); + + memcpy(&tz->trips.passive.devices, &devices, sizeof(devices)); + return true; +} + +static void acpi_thermal_update_passive_devices(struct acpi_thermal *tz) +{ + struct acpi_thermal_trip *acpi_trip = &tz->trips.passive.trip; + + if (!acpi_trip->valid) + return; + + if (update_passive_devices(tz, true)) + return; + + update_acpi_thermal_trip_temp(acpi_trip, THERMAL_TEMP_INVALID); + ACPI_THERMAL_TRIPS_EXCEPTION(ACPI_TRIPS_PASSIVE, tz, "state"); +} + static int acpi_thermal_adjust_trip(struct thermal_trip *trip, void *data) { struct acpi_thermal_trip *acpi_trip = trip->priv; @@ -359,8 +358,15 @@ static void acpi_thermal_adjust_thermal_ unsigned long data) { struct acpi_thermal *tz = thermal_zone_device_priv(thermal); - int flag = data == ACPI_THERMAL_NOTIFY_THRESHOLDS ? - ACPI_TRIPS_THRESHOLDS : ACPI_TRIPS_DEVICES; + int flag; + + if (data == ACPI_THERMAL_NOTIFY_THRESHOLDS) { + acpi_thermal_update_passive_trip(tz); + flag = ACPI_TRIPS_THRESHOLDS; + } else { + acpi_thermal_update_passive_devices(tz); + flag = ACPI_TRIPS_DEVICES; + } __acpi_thermal_trips_update(tz, flag); @@ -446,17 +452,63 @@ static long acpi_thermal_get_hot_trip(st return tmp; } +static bool acpi_thermal_init_passive_trip(struct acpi_thermal *tz) +{ + unsigned long long tmp; + acpi_status status; + int temp; + + if (psv == -1) + goto fail; + + if (psv > 0) { + temp = celsius_to_deci_kelvin(psv); + } else { + temp = get_passive_temp(tz); + if (temp == THERMAL_TEMP_INVALID) + goto fail; + } + + status = acpi_evaluate_integer(tz->device->handle, "_TC1", NULL, &tmp); + if (ACPI_FAILURE(status)) + goto fail; + + tz->trips.passive.tc1 = tmp; + + status = acpi_evaluate_integer(tz->device->handle, "_TC2", NULL, &tmp); + if (ACPI_FAILURE(status)) + goto fail; + + tz->trips.passive.tc2 = tmp; + + status = acpi_evaluate_integer(tz->device->handle, "_TSP", NULL, &tmp); + if (ACPI_FAILURE(status)) + goto fail; + + tz->trips.passive.tsp = tmp; + + if (!update_passive_devices(tz, false)) + goto fail; + + update_acpi_thermal_trip_temp(&tz->trips.passive.trip, temp); + return true; + +fail: + update_acpi_thermal_trip_temp(&tz->trips.passive.trip, THERMAL_TEMP_INVALID); + return false; +} + static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) { unsigned int count = 0; int i; - /* Passive and active trip points (optional). */ - __acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); - - if (tz->trips.passive.trip.valid) + if (acpi_thermal_init_passive_trip(tz)) count++; + /* Active trip points (optional). */ + __acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { if (tz->trips.active[i].trip.valid) count++; From patchwork Tue Sep 12 18:43:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 138532 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp792456vqx; Tue, 12 Sep 2023 18:39:44 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG8OB/sYhnbdIdgZWuL35UCesgs/e5S+pKTHQskI8OIeEgg3VZe8I41lqOUPl/WW3vKAO9n X-Received: by 2002:a17:90a:2e8a:b0:274:2f7e:782 with SMTP id r10-20020a17090a2e8a00b002742f7e0782mr930822pjd.7.1694569184014; Tue, 12 Sep 2023 18:39:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694569183; cv=none; d=google.com; s=arc-20160816; b=FFeZJBBlwIrqJzkqfBcDslat3dlBou/voU8crznpnuzDvTq6v+BJ0e1OiOClgTKUuB 4JUOsAo0SvV4gQlBv6QneNtBHFiIh3koqiTfk/HZCinw45rwEAYcXYCtDYg2remyrEZD ngvwGWivUU5O53NDSEQtaf4DS4xYW4fArv6w7SH91oIue8pstiGuTGmWn66uw2I0tFJK h4v4yLjHqelO0BHbR01vsotc7j3vfKXl3NgqE7j3QcEuDCWzrE5xKkIdEhJ4NetpSnsv xd7i4RKWIGw8D94ZqnVMaI0s3QXht/MKfudDMyIg4BQzW8bviJ17EytYt0by23T+6iYL SHGQ== 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; bh=NMuum/VEDI8iwpjeb5QaryrQORs5WriyjrzPMC+bhGM=; fh=TcRPROXzT9svfC8PL4GA9v01BlJpZsrjV4HRPcpqUxk=; b=PqG+1bmB5+2XmS76koSr8ewvi/FOntLuvzrKxC2uFtgWI1pufxDrGbI3APlTtAokpz y1PxRvRtCQNlPmORHNRqAbo7BlwjQJ5oAP+8tdkp2MTAM7Q5SVBZaBRSOPDuo1fiH7NT 47z6lXSMQcaCoGSHrck4Wi0puEQtduQ7N/fzqWGvxV3EuJ84Wz+uP77MYRx/xmGxy+cA XoBWSzwYfu0Pt5InmEWS0h8w7NBr1OoNKFXJ9OXBz10KcSeJVMJvTyWDJC8X6vEd1yLc UcWVNTfzV645EzzoCIRxq19yxd0LK6NMG8ZUUh4snKrAn1dhuFCf/vaYSsFJZpbcaDCB FzcA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id ch8-20020a17090af40800b002740f52e526si479342pjb.139.2023.09.12.18.39.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 18:39:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id C034F8483177; Tue, 12 Sep 2023 11:47:48 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236494AbjILSrr (ORCPT + 36 others); Tue, 12 Sep 2023 14:47:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237498AbjILSrm (ORCPT ); Tue, 12 Sep 2023 14:47:42 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6459D10D3; Tue, 12 Sep 2023 11:47:38 -0700 (PDT) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.2.0) id c5c47177dc7dc82b; Tue, 12 Sep 2023 20:47:36 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id 604C4663BE5; Tue, 12 Sep 2023 20:47:36 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v1 7/9] ACPI: thermal: Untangle initialization and updates of active trips Date: Tue, 12 Sep 2023 20:43:59 +0200 Message-ID: <22010294.EfDdHjke4D@kreacher> In-Reply-To: <5708760.DvuYhMxLoT@kreacher> References: <5708760.DvuYhMxLoT@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedgudeftdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhhuihdriihhrghnghesihhnthgvlhdrtghomhdprhgtphhtthhopehs rhhinhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Sep 2023 11:47:48 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776884576787706421 X-GMAIL-MSGID: 1776884576787706421 From: Rafael J. Wysocki Separate the code needed to update active trips (in a response to a notification from the platform firmware) as well as to initialize them from the code that is only necessary for their initialization and cleanly divide it into functions that each carry out a specific action. Signed-off-by: Rafael J. Wysocki Acked-by: Daniel Lezcano --- drivers/acpi/thermal.c | 197 ++++++++++++++++++++++++------------------------- 1 file changed, 100 insertions(+), 97 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -184,94 +184,6 @@ static int acpi_thermal_temp(struct acpi tz->kelvin_offset); } -static void __acpi_thermal_trips_update(struct acpi_thermal *tz, int flag) -{ - acpi_status status; - unsigned long long tmp; - struct acpi_handle_list devices; - bool valid = false; - int i; - - /* Active (optional) */ - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - char name[5] = { '_', 'A', 'C', ('0' + i), '\0' }; - valid = tz->trips.active[i].trip.valid; - - if (act == -1) - break; /* disable all active trip points */ - - if (flag == ACPI_TRIPS_INIT || ((flag & ACPI_TRIPS_ACTIVE) && - tz->trips.active[i].trip.valid)) { - status = acpi_evaluate_integer(tz->device->handle, - name, NULL, &tmp); - if (ACPI_FAILURE(status)) { - tz->trips.active[i].trip.valid = false; - if (i == 0) - break; - - if (act <= 0) - break; - - if (i == 1) - tz->trips.active[0].trip.temperature = - celsius_to_deci_kelvin(act); - else - /* - * Don't allow override higher than - * the next higher trip point - */ - tz->trips.active[i-1].trip.temperature = - min_t(unsigned long, - tz->trips.active[i-2].trip.temperature, - celsius_to_deci_kelvin(act)); - - break; - } else { - tz->trips.active[i].trip.temperature = tmp; - tz->trips.active[i].trip.valid = true; - } - } - - name[2] = 'L'; - if ((flag & ACPI_TRIPS_DEVICES) && tz->trips.active[i].trip.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].trip.valid = false; - } else { - tz->trips.active[i].trip.valid = true; - } - - if (memcmp(&tz->trips.active[i].devices, &devices, - sizeof(struct acpi_handle_list))) { - memcpy(&tz->trips.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].trip.valid) - ACPI_THERMAL_TRIPS_EXCEPTION(flag, tz, "state"); - - if (!tz->trips.active[i].trip.valid) - 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"); - } - } -} - static void update_acpi_thermal_trip_temp(struct acpi_thermal_trip *acpi_trip, int temp) { @@ -338,6 +250,78 @@ static void acpi_thermal_update_passive_ ACPI_THERMAL_TRIPS_EXCEPTION(ACPI_TRIPS_PASSIVE, tz, "state"); } +static long get_active_temp(struct acpi_thermal *tz, int index) +{ + char method[] = { '_', 'A', 'C', '0' + index, '\0' }; + unsigned long long tmp; + acpi_status status; + + status = acpi_evaluate_integer(tz->device->handle, method, NULL, &tmp); + if (ACPI_FAILURE(status)) + return THERMAL_TEMP_INVALID; + + /* + * If an override has been provided, apply it so there are no active + * trips with thresholds greater than the override. + */ + if (act > 0) { + unsigned long long override = celsius_to_deci_kelvin(act); + + if (tmp > override) + tmp = override; + } + return tmp; +} + +static void acpi_thermal_update_active_trip(struct acpi_thermal *tz, int index) +{ + struct acpi_thermal_trip *acpi_trip = &tz->trips.active[index].trip; + + if (!acpi_trip->valid) + return; + + update_acpi_thermal_trip_temp(acpi_trip, get_active_temp(tz, index)); + if (!acpi_trip->valid) + ACPI_THERMAL_TRIPS_EXCEPTION(ACPI_TRIPS_ACTIVE, tz, "state"); +} + +static bool update_active_devices(struct acpi_thermal *tz, int index, bool compare) +{ + char method[] = { '_', 'A', 'L', '0' + index, '\0' }; + struct acpi_handle_list devices; + acpi_status status; + + memset(&devices, 0, sizeof(devices)); + + status = acpi_evaluate_reference(tz->device->handle, method, NULL, &devices); + if (ACPI_FAILURE(status)) { + acpi_handle_info(tz->device->handle, + "Missing device list for active threshold %d\n", + index); + return false; + } + + if (compare && memcmp(&tz->trips.active[index].devices, &devices, sizeof(devices))) + ACPI_THERMAL_TRIPS_EXCEPTION(ACPI_TRIPS_ACTIVE, tz, "device"); + + memcpy(&tz->trips.active[index].devices, &devices, sizeof(devices)); + return true; +} + +static void acpi_thermal_update_active_devices(struct acpi_thermal *tz, int index) +{ + struct acpi_thermal_trip *acpi_trip = &tz->trips.active[index].trip; + + if (!acpi_trip->valid) + return; + + if (update_active_devices(tz, index, true)) + return; + + update_acpi_thermal_trip_temp(acpi_trip, THERMAL_TEMP_INVALID); + ACPI_THERMAL_TRIPS_EXCEPTION(ACPI_TRIPS_ACTIVE, tz, "state"); +} + static int acpi_thermal_adjust_trip(struct thermal_trip *trip, void *data) { struct acpi_thermal_trip *acpi_trip = trip->priv; @@ -358,18 +342,18 @@ static void acpi_thermal_adjust_thermal_ unsigned long data) { struct acpi_thermal *tz = thermal_zone_device_priv(thermal); - int flag; + int i; if (data == ACPI_THERMAL_NOTIFY_THRESHOLDS) { acpi_thermal_update_passive_trip(tz); - flag = ACPI_TRIPS_THRESHOLDS; + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) + acpi_thermal_update_active_trip(tz, i); } else { acpi_thermal_update_passive_devices(tz); - flag = ACPI_TRIPS_DEVICES; + for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) + acpi_thermal_update_active_devices(tz, i); } - __acpi_thermal_trips_update(tz, flag); - for_each_thermal_trip(tz->thermal_zone, acpi_thermal_adjust_trip, tz); } @@ -498,6 +482,28 @@ fail: return false; } +static bool acpi_thermal_init_active_trip(struct acpi_thermal *tz, int index) +{ + long temp; + + if (act == -1) + goto fail; + + temp = get_active_temp(tz, index); + if (temp == THERMAL_TEMP_INVALID) + goto fail; + + if (!update_active_devices(tz, false, index)) + goto fail; + + update_acpi_thermal_trip_temp(&tz->trips.active[index].trip, temp); + return true; + +fail: + update_acpi_thermal_trip_temp(&tz->trips.active[index].trip, THERMAL_TEMP_INVALID); + return false; +} + static int acpi_thermal_get_trip_points(struct acpi_thermal *tz) { unsigned int count = 0; @@ -506,11 +512,8 @@ static int acpi_thermal_get_trip_points( if (acpi_thermal_init_passive_trip(tz)) count++; - /* Active trip points (optional). */ - __acpi_thermal_trips_update(tz, ACPI_TRIPS_INIT); - for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - if (tz->trips.active[i].trip.valid) + if (acpi_thermal_init_active_trip(tz, i)) count++; else break; From patchwork Tue Sep 12 18:46:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 138531 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp792420vqx; Tue, 12 Sep 2023 18:39:36 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHuH4df3iJ5R0ug9O1isX5FSiiSnvAm6KgIu3ziwc6Az+LVcA6oPgryTGUfCGEk+pBkhvXZ X-Received: by 2002:a05:6870:d354:b0:1bf:7b3:5116 with SMTP id h20-20020a056870d35400b001bf07b35116mr1294785oag.47.1694569176048; Tue, 12 Sep 2023 18:39:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694569176; cv=none; d=google.com; s=arc-20160816; b=O06GHQmVFpRhwYoz4BlZ6DJIRVZYo7y+XTVSnkp8xolYn0l44cC2a7N3IJ7G0hRyzB YknsdDA9qqmXGB3BEcxICmH9Bz754Bl+nN1wYGUSPEAhXqEsQWYhF67IrnDA7Xh8cZ9v FCZumTq+QXv10NVtMeWOPZ1QLo0bXvchfxGsytlJJm6TN9aRMiL1QRc2UASiaYwpGaQo PqCzcxm0G9Maf7x9Kd8Cz2SteAycHjgSXYDujYcgZ5AFQYwGooMwqSKwMm8mOlEWgbg5 l+JCGT8mXj5sBy07OnUvQ54iyYRRW3gLGSS6duwJJaZi8cXnrxAuKfI6AqyqgnXfLtmS iIgQ== 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; bh=ohS9LV+ewW49/fB4yh5TLnsogYspb/daA/q4Tz3AVgM=; fh=TcRPROXzT9svfC8PL4GA9v01BlJpZsrjV4HRPcpqUxk=; b=l9JpyCPVC5o4M3NciDwsm/RBRI9DlfnaCeO0fJwC5IAv0t7oUgaJZ1FnuDMkpbMjiV ZcAasyyJ4iT4uyz2phxAPKKnMkPe3JJ24Mm2+rqUo19eX88ZbtcO5esLd/xlwGM+JhUX JNERMtzTTxLH/y0rJJMycufYTBg8l++zyMh9pjsXO4nXnczEEz8fppIOKys5mbhWs+4O X06RUKN0xzElFRvKq+MG0w4541FgfQCk4BwZn6lDsxB7dfEh8JQfCM997TzfhOZ0wPzS jeZPZEin4RtzKk03O5TumCEn8E/48WAPGEb4VcDbNmkJqCohZZTPGCMtMYVbIAWwhu9c 0FMw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from howler.vger.email (howler.vger.email. [2620:137:e000::3:4]) by mx.google.com with ESMTPS id x18-20020a634a12000000b0056da0ae25casi9001277pga.327.2023.09.12.18.39.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 18:39:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) client-ip=2620:137:e000::3:4; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:4 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by howler.vger.email (Postfix) with ESMTP id 103FA8436B6E; Tue, 12 Sep 2023 11:47:46 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at howler.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234760AbjILSro (ORCPT + 36 others); Tue, 12 Sep 2023 14:47:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237337AbjILSrl (ORCPT ); Tue, 12 Sep 2023 14:47:41 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 642CB10D3; Tue, 12 Sep 2023 11:47:37 -0700 (PDT) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.2.0) id e4066c49c5a5a305; Tue, 12 Sep 2023 20:47:35 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id D70DE663BE5; Tue, 12 Sep 2023 20:47:34 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v1 8/9] ACPI: thermal: Drop redundant trip point flags Date: Tue, 12 Sep 2023 20:46:02 +0200 Message-ID: <3760530.kQq0lBPeGt@kreacher> In-Reply-To: <5708760.DvuYhMxLoT@kreacher> References: <5708760.DvuYhMxLoT@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedgudeftdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhhuihdriihhrghnghesihhnthgvlhdrtghomhdprhgtphhtthhopehs rhhinhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (howler.vger.email [0.0.0.0]); Tue, 12 Sep 2023 11:47:46 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776884567878407645 X-GMAIL-MSGID: 1776884567878407645 From: Rafael J. Wysocki Trip point flags previously used by the driver need not be used any more after the preceding changes, so drop them and adjust the code accordingly. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Reviewed-by: Daniel Lezcano --- drivers/acpi/thermal.c | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -43,14 +43,6 @@ #define ACPI_THERMAL_MAX_ACTIVE 10 #define ACPI_THERMAL_MAX_LIMIT_STR_LEN 65 -#define ACPI_TRIPS_PASSIVE BIT(0) -#define ACPI_TRIPS_ACTIVE BIT(1) -#define ACPI_TRIPS_DEVICES BIT(2) - -#define ACPI_TRIPS_THRESHOLDS (ACPI_TRIPS_PASSIVE | ACPI_TRIPS_ACTIVE) - -#define ACPI_TRIPS_INIT (ACPI_TRIPS_THRESHOLDS | ACPI_TRIPS_DEVICES) - /* * This exception is thrown out in two cases: * 1.An invalid trip point becomes invalid or a valid trip point becomes invalid @@ -58,12 +50,11 @@ * 2.TODO: Devices listed in _PSL, _ALx, _TZD may change. * We need to re-bind the cooling devices of a thermal zone when this occurs. */ -#define ACPI_THERMAL_TRIPS_EXCEPTION(flags, tz, str) \ +#define ACPI_THERMAL_TRIPS_EXCEPTION(tz, str) \ do { \ - if (flags != ACPI_TRIPS_INIT) \ - acpi_handle_info(tz->device->handle, \ - "ACPI thermal trip point %s changed\n" \ - "Please report to linux-acpi@vger.kernel.org\n", str); \ + acpi_handle_info(tz->device->handle, \ + "ACPI thermal trip point %s changed\n" \ + "Please report to linux-acpi@vger.kernel.org\n", str); \ } while (0) static int act; @@ -212,7 +203,7 @@ static void acpi_thermal_update_passive_ update_acpi_thermal_trip_temp(acpi_trip, get_passive_temp(tz)); if (!acpi_trip->valid) - ACPI_THERMAL_TRIPS_EXCEPTION(ACPI_TRIPS_PASSIVE, tz, "state"); + ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state"); } static bool update_passive_devices(struct acpi_thermal *tz, bool compare) @@ -230,7 +221,7 @@ static bool update_passive_devices(struc } if (compare && memcmp(&tz->trips.passive.devices, &devices, sizeof(devices))) - ACPI_THERMAL_TRIPS_EXCEPTION(ACPI_TRIPS_PASSIVE, tz, "device"); + ACPI_THERMAL_TRIPS_EXCEPTION(tz, "device"); memcpy(&tz->trips.passive.devices, &devices, sizeof(devices)); return true; @@ -247,7 +238,7 @@ static void acpi_thermal_update_passive_ return; update_acpi_thermal_trip_temp(acpi_trip, THERMAL_TEMP_INVALID); - ACPI_THERMAL_TRIPS_EXCEPTION(ACPI_TRIPS_PASSIVE, tz, "state"); + ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state"); } static long get_active_temp(struct acpi_thermal *tz, int index) @@ -282,7 +273,7 @@ static void acpi_thermal_update_active_t update_acpi_thermal_trip_temp(acpi_trip, get_active_temp(tz, index)); if (!acpi_trip->valid) - ACPI_THERMAL_TRIPS_EXCEPTION(ACPI_TRIPS_ACTIVE, tz, "state"); + ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state"); } static bool update_active_devices(struct acpi_thermal *tz, int index, bool compare) @@ -302,7 +293,7 @@ static bool update_active_devices(struct } if (compare && memcmp(&tz->trips.active[index].devices, &devices, sizeof(devices))) - ACPI_THERMAL_TRIPS_EXCEPTION(ACPI_TRIPS_ACTIVE, tz, "device"); + ACPI_THERMAL_TRIPS_EXCEPTION(tz, "device"); memcpy(&tz->trips.active[index].devices, &devices, sizeof(devices)); return true; @@ -319,7 +310,7 @@ static void acpi_thermal_update_active_d return; update_acpi_thermal_trip_temp(acpi_trip, THERMAL_TEMP_INVALID); - ACPI_THERMAL_TRIPS_EXCEPTION(ACPI_TRIPS_ACTIVE, tz, "state"); + ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state"); } static int acpi_thermal_adjust_trip(struct thermal_trip *trip, void *data) From patchwork Tue Sep 12 18:47:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 138380 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:9ecd:0:b0:3f2:4152:657d with SMTP id t13csp613450vqx; Tue, 12 Sep 2023 11:52:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEClmusU8250eMHjDYH332WPc2WD91QSt5X24uSeXKHMi5eP8TXcQbWot7Qk1zO2g2WWLZh X-Received: by 2002:a05:6a21:7988:b0:155:bff3:ea1d with SMTP id bh8-20020a056a21798800b00155bff3ea1dmr209480pzc.58.1694544769699; Tue, 12 Sep 2023 11:52:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694544769; cv=none; d=google.com; s=arc-20160816; b=yshVUlkmmPqGNOGj/O4Ksn6trSdCqFJyf7LA7I+0KyYgPEzIlgRczCyTAp49iXvy8s PkFYSF02+o3QKGvgGRJXNTzpQaRZ6xSJJJ+oPdN5m6wb0RfPWQkyix8sh+iA9zsSij4A 4HzQFoDW2bWiSxWKFIoOMrgNU0Z82rU4YZkU4Ukx7BagYsxNel4qpduDnKAy2bRWru1e FL5t7tIL1exKk+AnbkMkoAMmms8ices7M4MvlhS2GO4oLtQMrqh47zCTbx06cEY4Gp9y 0qJlxN1k6PsAZ4MlhKgtO1Aawca9JZTXbzCgx8P5jQGQMQg5wBr+cvMQGIYr1bIYnI2V Xr7w== 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; bh=u0NTx4TLDXWUazZTrjRzmC9b6rF0xkRay09dimp/omc=; fh=TcRPROXzT9svfC8PL4GA9v01BlJpZsrjV4HRPcpqUxk=; b=LzDj/eYThZ5kuhRrhkqqb1Jcpzi7mv1XLxfVCw65J6Lvli+t/r49ro6nlWmBNkbr8l CmG9znz7eZ4B+2OCMvSOoOFUJtFe55VwTOpet4MMdejI94s7MHoOcQVKXx21bQMQY7+Q TaLddbLSjPp8tRG2OUIFp3ow6jlUB/XOtN+/XBVHYVlS2SFEI99Tnz4e2jpaCl2ZLNE5 FYZ8KjqITaPbZu2EmIACdoJj62HorpnFSvxEHbaAvC1nbJodiI/JT2egzsLd74Dxnimu JPgTHHUs+c22rYY5vLESod+A+eLWnr5pYACgLV7Nw0FjQekDQ2b1fNrWjv4WmJEv/Sr7 sJXw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id h5-20020a170902680500b001c3e3b19908si392210plk.485.2023.09.12.11.52.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 12 Sep 2023 11:52:49 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id A8D51825350A; Tue, 12 Sep 2023 11:47:50 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237450AbjILSrl (ORCPT + 36 others); Tue, 12 Sep 2023 14:47:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48872 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231382AbjILSrk (ORCPT ); Tue, 12 Sep 2023 14:47:40 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4BEC810D3; Tue, 12 Sep 2023 11:47:36 -0700 (PDT) Received: from localhost (127.0.0.1) (HELO v370.home.net.pl) by /usr/run/smtp (/usr/run/postfix/private/idea_relay_lmtp) via UNIX with SMTP (IdeaSmtpServer 5.2.0) id d591d3eab9350a03; Tue, 12 Sep 2023 20:47:33 +0200 Authentication-Results: v370.home.net.pl; spf=softfail (domain owner discourages use of this host) smtp.mailfrom=rjwysocki.net (client-ip=195.136.19.94; helo=[195.136.19.94]; envelope-from=rjw@rjwysocki.net; receiver=) Received: from kreacher.localnet (unknown [195.136.19.94]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by v370.home.net.pl (Postfix) with ESMTPSA id BAB64663C2D; Tue, 12 Sep 2023 20:47:32 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v1 9/9] ACPI: thermal: Drop valid flag from struct acpi_thermal_trip Date: Tue, 12 Sep 2023 20:47:23 +0200 Message-ID: <9162925.CDJkKcVGEf@kreacher> In-Reply-To: <5708760.DvuYhMxLoT@kreacher> References: <5708760.DvuYhMxLoT@kreacher> MIME-Version: 1.0 X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedviedrudeiiedgudeftdcutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeeipdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheprhhuihdriihhrghnghesihhnthgvlhdrtghomhdprhgtphhtthhopehs rhhinhhivhgrshdrphgrnhgurhhuvhgruggrsehlihhnuhigrdhinhhtvghlrdgtohhmpdhrtghpthhtohepuggrnhhivghlrdhlvgiitggrnhhosehlihhnrghrohdrohhrgh X-DCC--Metrics: v370.home.net.pl 1024; Body=6 Fuz1=6 Fuz2=6 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Tue, 12 Sep 2023 11:47:50 -0700 (PDT) X-Spam-Status: No, score=-0.8 required=5.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776858976358408058 X-GMAIL-MSGID: 1776858976358408058 From: Rafael J. Wysocki Notice that the valid flag in struct acpi_thermal_trip is in fact redundant, because the temperature field of invalid trips is always equal to THERMAL_TEMP_INVALID, so drop it from there and adjust the code accordingly. No intentional functional impact. Signed-off-by: Rafael J. Wysocki Acked-by: Daniel Lezcano Reviewed-by: Daniel Lezcano --- drivers/acpi/thermal.c | 49 +++++++++++++++++++++++-------------------------- 1 file changed, 23 insertions(+), 26 deletions(-) Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -81,7 +81,6 @@ static struct workqueue_struct *acpi_the struct acpi_thermal_trip { unsigned long temperature; - bool valid; }; struct acpi_thermal_passive { @@ -175,11 +174,9 @@ static int acpi_thermal_temp(struct acpi tz->kelvin_offset); } -static void update_acpi_thermal_trip_temp(struct acpi_thermal_trip *acpi_trip, - int temp) +static bool acpi_thermal_trip_valid(struct acpi_thermal_trip *acpi_trip) { - acpi_trip->valid = temp != THERMAL_TEMP_INVALID; - acpi_trip->temperature = temp; + return acpi_trip->temperature != THERMAL_TEMP_INVALID; } static long get_passive_temp(struct acpi_thermal *tz) @@ -198,11 +195,11 @@ static void acpi_thermal_update_passive_ { struct acpi_thermal_trip *acpi_trip = &tz->trips.passive.trip; - if (!acpi_trip->valid || psv > 0) + if (!acpi_thermal_trip_valid(acpi_trip) || psv > 0) return; - update_acpi_thermal_trip_temp(acpi_trip, get_passive_temp(tz)); - if (!acpi_trip->valid) + acpi_trip->temperature = get_passive_temp(tz); + if (!acpi_thermal_trip_valid(acpi_trip)) ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state"); } @@ -231,13 +228,13 @@ static void acpi_thermal_update_passive_ { struct acpi_thermal_trip *acpi_trip = &tz->trips.passive.trip; - if (!acpi_trip->valid) + if (!acpi_thermal_trip_valid(acpi_trip)) return; if (update_passive_devices(tz, true)) return; - update_acpi_thermal_trip_temp(acpi_trip, THERMAL_TEMP_INVALID); + acpi_trip->temperature = THERMAL_TEMP_INVALID; ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state"); } @@ -268,11 +265,11 @@ static void acpi_thermal_update_active_t { struct acpi_thermal_trip *acpi_trip = &tz->trips.active[index].trip; - if (!acpi_trip->valid) + if (!acpi_thermal_trip_valid(acpi_trip)) return; - update_acpi_thermal_trip_temp(acpi_trip, get_active_temp(tz, index)); - if (!acpi_trip->valid) + acpi_trip->temperature = get_active_temp(tz, index); + if (!acpi_thermal_trip_valid(acpi_trip)) ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state"); } @@ -303,13 +300,13 @@ static void acpi_thermal_update_active_d { struct acpi_thermal_trip *acpi_trip = &tz->trips.active[index].trip; - if (!acpi_trip->valid) + if (!acpi_thermal_trip_valid(acpi_trip)) return; if (update_active_devices(tz, index, true)) return; - update_acpi_thermal_trip_temp(acpi_trip, THERMAL_TEMP_INVALID); + acpi_trip->temperature = THERMAL_TEMP_INVALID; ACPI_THERMAL_TRIPS_EXCEPTION(tz, "state"); } @@ -321,7 +318,7 @@ static int acpi_thermal_adjust_trip(stru if (!acpi_trip) return 0; - if (acpi_trip->valid) + if (acpi_thermal_trip_valid(acpi_trip)) trip->temperature = acpi_thermal_temp(tz, acpi_trip->temperature); else trip->temperature = THERMAL_TEMP_INVALID; @@ -465,11 +462,11 @@ static bool acpi_thermal_init_passive_tr if (!update_passive_devices(tz, false)) goto fail; - update_acpi_thermal_trip_temp(&tz->trips.passive.trip, temp); + tz->trips.passive.trip.temperature = temp; return true; fail: - update_acpi_thermal_trip_temp(&tz->trips.passive.trip, THERMAL_TEMP_INVALID); + tz->trips.passive.trip.temperature = THERMAL_TEMP_INVALID; return false; } @@ -487,11 +484,11 @@ static bool acpi_thermal_init_active_tri if (!update_active_devices(tz, false, index)) goto fail; - update_acpi_thermal_trip_temp(&tz->trips.active[index].trip, temp); + tz->trips.active[index].trip.temperature = temp; return true; fail: - update_acpi_thermal_trip_temp(&tz->trips.active[index].trip, THERMAL_TEMP_INVALID); + tz->trips.active[index].trip.temperature = THERMAL_TEMP_INVALID; return false; } @@ -545,7 +542,7 @@ static int thermal_get_trend(struct ther return -EINVAL; acpi_trip = trip->priv; - if (!acpi_trip || !acpi_trip->valid) + if (!acpi_trip || !acpi_thermal_trip_valid(acpi_trip)) return -EINVAL; switch (trip->type) { @@ -618,7 +615,7 @@ static int acpi_thermal_cooling_device_c if (tz->trips.hot_valid) trip++; - if (tz->trips.passive.trip.valid) { + if (acpi_thermal_trip_valid(&tz->trips.passive.trip)) { trip++; for (i = 0; i < tz->trips.passive.devices.count; i++) { handle = tz->trips.passive.devices.handles[i]; @@ -643,7 +640,7 @@ static int acpi_thermal_cooling_device_c } for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - if (!tz->trips.active[i].trip.valid) + if (!acpi_thermal_trip_valid(&tz->trips.active[i].trip)) break; trip++; @@ -949,7 +946,7 @@ static int acpi_thermal_add(struct acpi_ } acpi_trip = &tz->trips.passive.trip; - if (acpi_trip->valid) { + if (acpi_thermal_trip_valid(acpi_trip)) { passive_delay = tz->trips.passive.tsp * 100; trip->type = THERMAL_TRIP_PASSIVE; @@ -961,7 +958,7 @@ static int acpi_thermal_add(struct acpi_ for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { acpi_trip = &tz->trips.active[i].trip; - if (!acpi_trip->valid) + if (!acpi_thermal_trip_valid(acpi_trip)) break; trip->type = THERMAL_TRIP_ACTIVE; @@ -1038,7 +1035,7 @@ static int acpi_thermal_resume(struct de return -EINVAL; for (i = 0; i < ACPI_THERMAL_MAX_ACTIVE; i++) { - if (!tz->trips.active[i].trip.valid) + if (!acpi_thermal_trip_valid(&tz->trips.active[i].trip)) break; for (j = 0; j < tz->trips.active[i].devices.count; j++) {