From patchwork Tue Oct 17 20:05:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Rafael J. Wysocki" X-Patchwork-Id: 154490 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4375407vqb; Tue, 17 Oct 2023 13:13:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IERRWrjV6VFuJ5ev87pUvubO5uGTJZS8XtC8xDHfDxGgXCdsW6+VnDmHXDAuZw2TTFZWbDE X-Received: by 2002:a05:6359:5e20:b0:166:d93e:339 with SMTP id pw32-20020a0563595e2000b00166d93e0339mr3276569rwb.0.1697573597734; Tue, 17 Oct 2023 13:13:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697573597; cv=none; d=google.com; s=arc-20160816; b=iTkwzwmxhIBBfCGBABNOK+v4CzyltyOMoGUKxM2dwaRHjDAl7K6TZaTMbVF0ZNvLZ2 NFZPbtsHNRbtRuhjXt7YjSz0HrprNAWC3opnHZoNEHNHs6aTvwPC7QiL9h44BUPdyroE jQDvliFZB7ZOqXcbc3aqMZPOq42X9kYIjTpjUd8oFAmbxDT/idUQSg/DmnUn0EcR2my6 CL4YIr2xH0iYYUIWkCLHWI+L0xHgYprm0MvtsfnxcBcJdwGwZecZag3/8JV9EvmPw6UL j1pOh+F8wccubMdfLQNVtBbaosX1WkRydIl5Z6qMev259u0JBSY7e3OOJSoQaFax5+91 ZF5g== 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=tNVx/0TusTLbfCxBc0TTGCOJ7/49sDnqTDB7gPIV83A=; fh=p/Yd/06WV/NRg/vf6gGQsBGSNtCRQ5gqTvI3QmryL7M=; b=WFiEOJO4J9xil0PiEEPN9Ucn+vq/8yisjcvZUDhsJD1DVahi2L+IA1cxGULQtsoX3N WWMUWNYvz+uzGLIuqaJhxKHYuFoXvSilYn6yUlsPAlh7gOfvBDtSkSttXS8QG0ckWGlm OzoTidoEKDUqQM1i7wyaPh7sTNrw0nM13ylim0wh01Pte6eciFaKYC6oIDDnsgW8F1PZ 6izsgsBYnBQUvj5tHLyM+j4Kt7HlEUDe/8tYLfu/g/GjPPZ/e2CftFPw4GKPYTGChKvU 0wyVLMgCizusixXw5sGLSHeogk3ESQViWAIEG7V3+SlCmg8V4uSqithxT74w+4amAxHC k5Aw== 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:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id x14-20020aa7940e000000b006b7884dcd6csi2288967pfo.14.2023.10.17.13.13.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:13:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id 83DCE8027E94; Tue, 17 Oct 2023 13:13:14 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344196AbjJQUMz convert rfc822-to-8bit (ORCPT + 21 others); Tue, 17 Oct 2023 16:12:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231149AbjJQUMt (ORCPT ); Tue, 17 Oct 2023 16:12:49 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99CE26FA9; Tue, 17 Oct 2023 13:12: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 25056178d9cded64; Tue, 17 Oct 2023 22:12:45 +0200 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 cloudserver094114.home.pl (Postfix) with ESMTPSA id 86C38666BCD; Tue, 17 Oct 2023 22:12:44 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: Linux ACPI , Daniel Lezcano , LKML , Srinivas Pandruvada , "Rafael J. Wysocki" , Zhang Rui Subject: [PATCH v1 1/3] thermal: ACPI: Move the ACPI thermal library to drivers/acpi/ Date: Tue, 17 Oct 2023 22:05:23 +0200 Message-ID: <4539892.LvFx2qVVIh@kreacher> In-Reply-To: <5740803.DvuYhMxLoT@kreacher> References: <5740803.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: gggruggvucftvghtrhhoucdtuddrgedvkedrjedvgddugeefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtqhertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnheptddvfeegledvfedvveevhedvteeffeehvdeuiedukeeiledttefgvdeihffgteetnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhg X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 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 agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Tue, 17 Oct 2023 13:13:14 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780034932549146430 X-GMAIL-MSGID: 1780034932549146430 From: Rafael J. Wysocki The ACPI thermal library contains functions that can be used to retrieve trip point temperature values through the platform firmware for various types of trip points. Each of these functions basically evaluates a specific ACPI object, checks if the value produced by it is reasonable and returns it (or THERMAL_TEMP_INVALID if anything fails). It made sense to hold it in drivers/thermal/ so long as it was only used by the code in that directory, but since it is also going to be used by the ACPI thermal driver, located in drivers/acpi/, move it to the latter in order to keep the code related to evaluating ACPI objects defined in the specification proper together. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- drivers/acpi/Kconfig | 4 drivers/acpi/Makefile | 1 drivers/acpi/thermal_lib.c | 116 ++++++++++++++++++++++++++ drivers/thermal/Kconfig | 4 drivers/thermal/Makefile | 1 drivers/thermal/intel/Kconfig | 2 drivers/thermal/intel/int340x_thermal/Kconfig | 2 drivers/thermal/thermal_acpi.c | 116 -------------------------- include/linux/acpi.h | 7 + include/linux/thermal.h | 7 - 10 files changed, 130 insertions(+), 130 deletions(-) Index: linux-pm/drivers/thermal/intel/Kconfig =================================================================== --- linux-pm.orig/drivers/thermal/intel/Kconfig +++ linux-pm/drivers/thermal/intel/Kconfig @@ -85,7 +85,7 @@ config INTEL_BXT_PMIC_THERMAL config INTEL_PCH_THERMAL tristate "Intel PCH Thermal Reporting Driver" depends on X86 && PCI - select THERMAL_ACPI if ACPI + select ACPI_THERMAL_LIB if ACPI help Enable this to support thermal reporting on certain intel PCHs. Thermal reporting device will provide temperature reading, Index: linux-pm/drivers/thermal/intel/int340x_thermal/Kconfig =================================================================== --- linux-pm.orig/drivers/thermal/intel/int340x_thermal/Kconfig +++ linux-pm/drivers/thermal/intel/int340x_thermal/Kconfig @@ -9,7 +9,7 @@ config INT340X_THERMAL select THERMAL_GOV_USER_SPACE select ACPI_THERMAL_REL select ACPI_FAN - select THERMAL_ACPI + select ACPI_THERMAL_LIB select INTEL_SOC_DTS_IOSF_CORE select INTEL_TCC select PROC_THERMAL_MMIO_RAPL if POWERCAP Index: linux-pm/drivers/acpi/Kconfig =================================================================== --- linux-pm.orig/drivers/acpi/Kconfig +++ linux-pm/drivers/acpi/Kconfig @@ -60,6 +60,10 @@ config ACPI_CCA_REQUIRED config ACPI_TABLE_LIB bool +config ACPI_THERMAL_LIB + depends on THERMAL + bool + config ACPI_DEBUGGER bool "AML debugger interface" select ACPI_DEBUG Index: linux-pm/drivers/thermal/Kconfig =================================================================== --- linux-pm.orig/drivers/thermal/Kconfig +++ linux-pm/drivers/thermal/Kconfig @@ -76,10 +76,6 @@ config THERMAL_OF Say 'Y' here if you need to build thermal infrastructure based on device tree. -config THERMAL_ACPI - depends on ACPI - bool - config THERMAL_WRITABLE_TRIPS bool "Enable writable trip points" help Index: linux-pm/drivers/acpi/Makefile =================================================================== --- linux-pm.orig/drivers/acpi/Makefile +++ linux-pm/drivers/acpi/Makefile @@ -89,6 +89,7 @@ obj-$(CONFIG_ACPI_TAD) += acpi_tad.o obj-$(CONFIG_ACPI_PCI_SLOT) += pci_slot.o obj-$(CONFIG_ACPI_PROCESSOR) += processor.o obj-$(CONFIG_ACPI) += container.o +obj-$(CONFIG_ACPI_THERMAL_LIB) += thermal_lib.o obj-$(CONFIG_ACPI_THERMAL) += thermal.o obj-$(CONFIG_ACPI_PLATFORM_PROFILE) += platform_profile.o obj-$(CONFIG_ACPI_NFIT) += nfit/ Index: linux-pm/drivers/thermal/Makefile =================================================================== --- linux-pm.orig/drivers/thermal/Makefile +++ linux-pm/drivers/thermal/Makefile @@ -13,7 +13,6 @@ thermal_sys-$(CONFIG_THERMAL_NETLINK) + # interface to/from other layers providing sensors thermal_sys-$(CONFIG_THERMAL_HWMON) += thermal_hwmon.o thermal_sys-$(CONFIG_THERMAL_OF) += thermal_of.o -thermal_sys-$(CONFIG_THERMAL_ACPI) += thermal_acpi.o # governors CFLAGS_gov_power_allocator.o := -I$(src) Index: linux-pm/include/linux/acpi.h =================================================================== --- linux-pm.orig/include/linux/acpi.h +++ linux-pm/include/linux/acpi.h @@ -439,6 +439,13 @@ extern int acpi_blacklisted(void); extern void acpi_osi_setup(char *str); extern bool acpi_osi_is_win8(void); +#ifdef CONFIG_ACPI_THERMAL_LIB +int thermal_acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp); +int thermal_acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp); +int thermal_acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp); +int thermal_acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp); +#endif + #ifdef CONFIG_ACPI_NUMA int acpi_map_pxm_to_node(int pxm); int acpi_get_node(acpi_handle handle); Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -294,13 +294,6 @@ int thermal_zone_get_num_trips(struct th int thermal_zone_get_crit_temp(struct thermal_zone_device *tz, int *temp); -#ifdef CONFIG_THERMAL_ACPI -int thermal_acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp); -int thermal_acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp); -int thermal_acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp); -int thermal_acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp); -#endif - #ifdef CONFIG_THERMAL struct thermal_zone_device *thermal_zone_device_register_with_trips( const char *type, Index: linux-pm/drivers/acpi/thermal_lib.c =================================================================== --- /dev/null +++ linux-pm/drivers/acpi/thermal_lib.c @@ -0,0 +1,116 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright 2023 Linaro Limited + * Copyright 2023 Intel Corporation + * + * Library routines for populating a generic thermal trip point structure + * with data obtained by evaluating a specific object in the ACPI Namespace. + */ +#include +#include +#include + +/* + * Minimum temperature for full military grade is 218°K (-55°C) and + * max temperature is 448°K (175°C). We can consider those values as + * the boundaries for the [trips] temperature returned by the + * firmware. Any values out of these boundaries may be considered + * bogus and we can assume the firmware has no data to provide. + */ +#define TEMP_MIN_DECIK 2180 +#define TEMP_MAX_DECIK 4480 + +static int thermal_acpi_trip_temp(struct acpi_device *adev, char *obj_name, + int *ret_temp) +{ + unsigned long long temp; + acpi_status status; + + status = acpi_evaluate_integer(adev->handle, obj_name, NULL, &temp); + if (ACPI_FAILURE(status)) { + acpi_handle_debug(adev->handle, "%s evaluation failed\n", obj_name); + return -ENODATA; + } + + if (temp >= TEMP_MIN_DECIK && temp <= TEMP_MAX_DECIK) { + *ret_temp = deci_kelvin_to_millicelsius(temp); + } else { + acpi_handle_debug(adev->handle, "%s result %llu out of range\n", + obj_name, temp); + *ret_temp = THERMAL_TEMP_INVALID; + } + + return 0; +} + +/** + * thermal_acpi_active_trip_temp - Retrieve active trip point temperature + * @adev: Target thermal zone ACPI device object. + * @id: Active cooling level (0 - 9). + * @ret_temp: Address to store the retrieved temperature value on success. + * + * Evaluate the _ACx object for the thermal zone represented by @adev to obtain + * the temperature of the active cooling trip point corresponding to the active + * cooling level given by @id. + * + * Return 0 on success or a negative error value on failure. + */ +int thermal_acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp) +{ + char obj_name[] = {'_', 'A', 'C', '0' + id, '\0'}; + + if (id < 0 || id > 9) + return -EINVAL; + + return thermal_acpi_trip_temp(adev, obj_name, ret_temp); +} +EXPORT_SYMBOL_GPL(thermal_acpi_active_trip_temp); + +/** + * thermal_acpi_passive_trip_temp - Retrieve passive trip point temperature + * @adev: Target thermal zone ACPI device object. + * @ret_temp: Address to store the retrieved temperature value on success. + * + * Evaluate the _PSV object for the thermal zone represented by @adev to obtain + * the temperature of the passive cooling trip point. + * + * Return 0 on success or -ENODATA on failure. + */ +int thermal_acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp) +{ + return thermal_acpi_trip_temp(adev, "_PSV", ret_temp); +} +EXPORT_SYMBOL_GPL(thermal_acpi_passive_trip_temp); + +/** + * thermal_acpi_hot_trip_temp - Retrieve hot trip point temperature + * @adev: Target thermal zone ACPI device object. + * @ret_temp: Address to store the retrieved temperature value on success. + * + * Evaluate the _HOT object for the thermal zone represented by @adev to obtain + * the temperature of the trip point at which the system is expected to be put + * into the S4 sleep state. + * + * Return 0 on success or -ENODATA on failure. + */ +int thermal_acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp) +{ + return thermal_acpi_trip_temp(adev, "_HOT", ret_temp); +} +EXPORT_SYMBOL_GPL(thermal_acpi_hot_trip_temp); + +/** + * thermal_acpi_critical_trip_temp - Retrieve critical trip point temperature + * @adev: Target thermal zone ACPI device object. + * @ret_temp: Address to store the retrieved temperature value on success. + * + * Evaluate the _CRT object for the thermal zone represented by @adev to obtain + * the temperature of the critical cooling trip point. + * + * Return 0 on success or -ENODATA on failure. + */ +int thermal_acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp) +{ + return thermal_acpi_trip_temp(adev, "_CRT", ret_temp); +} +EXPORT_SYMBOL_GPL(thermal_acpi_critical_trip_temp); Index: linux-pm/drivers/thermal/thermal_acpi.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_acpi.c +++ /dev/null @@ -1,116 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Copyright 2023 Linaro Limited - * Copyright 2023 Intel Corporation - * - * Library routines for populating a generic thermal trip point structure - * with data obtained by evaluating a specific object in the ACPI Namespace. - */ -#include -#include -#include - -/* - * Minimum temperature for full military grade is 218°K (-55°C) and - * max temperature is 448°K (175°C). We can consider those values as - * the boundaries for the [trips] temperature returned by the - * firmware. Any values out of these boundaries may be considered - * bogus and we can assume the firmware has no data to provide. - */ -#define TEMP_MIN_DECIK 2180 -#define TEMP_MAX_DECIK 4480 - -static int thermal_acpi_trip_temp(struct acpi_device *adev, char *obj_name, - int *ret_temp) -{ - unsigned long long temp; - acpi_status status; - - status = acpi_evaluate_integer(adev->handle, obj_name, NULL, &temp); - if (ACPI_FAILURE(status)) { - acpi_handle_debug(adev->handle, "%s evaluation failed\n", obj_name); - return -ENODATA; - } - - if (temp >= TEMP_MIN_DECIK && temp <= TEMP_MAX_DECIK) { - *ret_temp = deci_kelvin_to_millicelsius(temp); - } else { - acpi_handle_debug(adev->handle, "%s result %llu out of range\n", - obj_name, temp); - *ret_temp = THERMAL_TEMP_INVALID; - } - - return 0; -} - -/** - * thermal_acpi_active_trip_temp - Retrieve active trip point temperature - * @adev: Target thermal zone ACPI device object. - * @id: Active cooling level (0 - 9). - * @ret_temp: Address to store the retrieved temperature value on success. - * - * Evaluate the _ACx object for the thermal zone represented by @adev to obtain - * the temperature of the active cooling trip point corresponding to the active - * cooling level given by @id. - * - * Return 0 on success or a negative error value on failure. - */ -int thermal_acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp) -{ - char obj_name[] = {'_', 'A', 'C', '0' + id, '\0'}; - - if (id < 0 || id > 9) - return -EINVAL; - - return thermal_acpi_trip_temp(adev, obj_name, ret_temp); -} -EXPORT_SYMBOL_GPL(thermal_acpi_active_trip_temp); - -/** - * thermal_acpi_passive_trip_temp - Retrieve passive trip point temperature - * @adev: Target thermal zone ACPI device object. - * @ret_temp: Address to store the retrieved temperature value on success. - * - * Evaluate the _PSV object for the thermal zone represented by @adev to obtain - * the temperature of the passive cooling trip point. - * - * Return 0 on success or -ENODATA on failure. - */ -int thermal_acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp) -{ - return thermal_acpi_trip_temp(adev, "_PSV", ret_temp); -} -EXPORT_SYMBOL_GPL(thermal_acpi_passive_trip_temp); - -/** - * thermal_acpi_hot_trip_temp - Retrieve hot trip point temperature - * @adev: Target thermal zone ACPI device object. - * @ret_temp: Address to store the retrieved temperature value on success. - * - * Evaluate the _HOT object for the thermal zone represented by @adev to obtain - * the temperature of the trip point at which the system is expected to be put - * into the S4 sleep state. - * - * Return 0 on success or -ENODATA on failure. - */ -int thermal_acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp) -{ - return thermal_acpi_trip_temp(adev, "_HOT", ret_temp); -} -EXPORT_SYMBOL_GPL(thermal_acpi_hot_trip_temp); - -/** - * thermal_acpi_critical_trip_temp - Retrieve critical trip point temperature - * @adev: Target thermal zone ACPI device object. - * @ret_temp: Address to store the retrieved temperature value on success. - * - * Evaluate the _CRT object for the thermal zone represented by @adev to obtain - * the temperature of the critical cooling trip point. - * - * Return 0 on success or -ENODATA on failure. - */ -int thermal_acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp) -{ - return thermal_acpi_trip_temp(adev, "_CRT", ret_temp); -} -EXPORT_SYMBOL_GPL(thermal_acpi_critical_trip_temp); From patchwork Tue Oct 17 20:06: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: 154489 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4375336vqb; Tue, 17 Oct 2023 13:13:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGD9WCFJDaU5DGdMgB3Wr5uHVJGsvdKGkpL6tAe/AGC4Hz4jct7H5e0NLWSFgKU+VI7WYFg X-Received: by 2002:a05:6a20:9741:b0:163:ab09:196d with SMTP id hs1-20020a056a20974100b00163ab09196dmr3135342pzc.1.1697573588317; Tue, 17 Oct 2023 13:13:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697573588; cv=none; d=google.com; s=arc-20160816; b=cz9p/jjZ6ebCuNG27GW1YRP4CsOHxY1B8zSPXAOqfL7cJdZHvo0qbZbNcUD9uQIG4o rFs0Iwr19mRhDrN0EFPxxBcW/RTBTWHBIyv0j2SXtuS/4kihksA497cMRAgNdRwv7BVJ kJZXmE3BCA9AuaK1M51g340EmNIdZsZg7qA3EuPyz2UPt5lIasgFCiO8x5BtxybD5AwP psn/aMI1puzoyOxaZVid77UR5IUa0OWgHqY5kUNJ0e/B+/v8dtoxDOvms410yA+dNxaH hM7zGUskNB8pNFqoX/32fXG9NpHaMv5MSaav+X+4wiU9iIpNnN3GY0ONVsmKq3PMWM6L 1Ieg== 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=H+6oC/lwpHa+eL8Pa1czoLxgL9AOgeUcSP1wb+UviAE=; fh=p/Yd/06WV/NRg/vf6gGQsBGSNtCRQ5gqTvI3QmryL7M=; b=hgZqNLjKUaQkJfH6fzvSS5Mm+qsDpz5jvc4gnpSSud8EIUDnnXtzr4XQRtYWW16Y0u HyrD3zWsc6NDlbaGfbFOnOGW5alXsOe7uCOFfAgYGqJ/Rdw042qY9bIXHqt+HZVT/4XM AYWPMl2QsJR0muRFlcIHpT1+MX/H6fdTweBMqvwmlUEnh8qBPSF3/V9gWozRsuZ1RpaS r42wB1Oj/APDb2vCbkcCbSE8BixlBzSQ2kB64ppl0bVsGMDwCOn5YxnOQFw6IPT+de+l hG3Iw+s+noEjvZHz8p8Kp0CvmTVLqHgRvuIRvO9VRq89Tr2h/lN1BhW0U/uhnFFgk0OY vZJQ== 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:2 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from agentk.vger.email (agentk.vger.email. [2620:137:e000::3:2]) by mx.google.com with ESMTPS id r12-20020a17090aa08c00b0027760c30acfsi2315982pjp.4.2023.10.17.13.13.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:13:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 as permitted sender) client-ip=2620:137:e000::3:2; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:2 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 agentk.vger.email (Postfix) with ESMTP id CC36B8028FA8; Tue, 17 Oct 2023 13:13:02 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at agentk.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234752AbjJQUMv (ORCPT + 21 others); Tue, 17 Oct 2023 16:12:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231478AbjJQUMs (ORCPT ); Tue, 17 Oct 2023 16:12:48 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C58156FAA; Tue, 17 Oct 2023 13:12: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 b9b0ec6ca16d320a; Tue, 17 Oct 2023 22:12:44 +0200 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 cloudserver094114.home.pl (Postfix) with ESMTPSA id 7ACE7666BCD; Tue, 17 Oct 2023 22:12:43 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: Linux ACPI , Daniel Lezcano , LKML , Srinivas Pandruvada , "Rafael J. Wysocki" , Zhang Rui Subject: [PATCH v1 2/3] ACPI: thermal_lib: Add functions returning temperature in deci-Kelvin Date: Tue, 17 Oct 2023 22:06:52 +0200 Message-ID: <4861460.GXAFRqVoOG@kreacher> In-Reply-To: <5740803.DvuYhMxLoT@kreacher> References: <5740803.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: gggruggvucftvghtrhhoucdtuddrgedvkedrjedvgddugeefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhg X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 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 agentk.vger.email 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 (agentk.vger.email [0.0.0.0]); Tue, 17 Oct 2023 13:13:02 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780034922695613887 X-GMAIL-MSGID: 1780034922695613887 From: Rafael J. Wysocki Because the ACPI thermal driver generally operates temperature values in deci-Kelvin, it needs the library functions returning temperature for various trip point types to use deci-Kelvin too. To address that, arrange the ACPI thermal library code in three levels of functions where the high-level ones will return temperature in milli-Celsius, as needed by the thermal core and the majority of thermal drivers, the mid-level ones will return temperature in deci-Kelvin and will be called internally by the corresponding high- level functions, and all of the mid-level functions will call the same low-level one, acpi_trip_temp(), to actually evaluate ACPI objects to retrieve themperature values from the platform firmware. Going forward, this will allow the ACPI thermal driver to use the mid-level functions to provide temperature values needed by it, so as to reduce code duplication related to evaluating trip temperature ACPI control methods. No intentional functional impact. Signed-off-by: Rafael J. Wysocki --- drivers/acpi/thermal_lib.c | 75 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 60 insertions(+), 15 deletions(-) Index: linux-pm/drivers/acpi/thermal_lib.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal_lib.c +++ linux-pm/drivers/acpi/thermal_lib.c @@ -3,8 +3,8 @@ * Copyright 2023 Linaro Limited * Copyright 2023 Intel Corporation * - * Library routines for populating a generic thermal trip point structure - * with data obtained by evaluating a specific object in the ACPI Namespace. + * Library routines for retrieving trip point temperature values from the + * platform firmware via ACPI. */ #include #include @@ -17,11 +17,11 @@ * firmware. Any values out of these boundaries may be considered * bogus and we can assume the firmware has no data to provide. */ -#define TEMP_MIN_DECIK 2180 -#define TEMP_MAX_DECIK 4480 +#define TEMP_MIN_DECIK 2180ULL +#define TEMP_MAX_DECIK 4480ULL -static int thermal_acpi_trip_temp(struct acpi_device *adev, char *obj_name, - int *ret_temp) +static int acpi_trip_temp(struct acpi_device *adev, char *obj_name, + int *ret_temp) { unsigned long long temp; acpi_status status; @@ -33,7 +33,7 @@ static int thermal_acpi_trip_temp(struct } if (temp >= TEMP_MIN_DECIK && temp <= TEMP_MAX_DECIK) { - *ret_temp = deci_kelvin_to_millicelsius(temp); + *ret_temp = temp; } else { acpi_handle_debug(adev->handle, "%s result %llu out of range\n", obj_name, temp); @@ -43,6 +43,44 @@ static int thermal_acpi_trip_temp(struct return 0; } +int acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp) +{ + char obj_name[] = {'_', 'A', 'C', '0' + id, '\0'}; + + if (id < 0 || id > 9) + return -EINVAL; + + return acpi_trip_temp(adev, obj_name, ret_temp); +} + +int acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp) +{ + return acpi_trip_temp(adev, "_PSV", ret_temp); +} + +int acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp) +{ + return acpi_trip_temp(adev, "_HOT", ret_temp); +} + +int acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp) +{ + return acpi_trip_temp(adev, "_CRT", ret_temp); +} + +static int thermal_temp(int error, int temp_decik, int *ret_temp) +{ + if (error) + return error; + + if (temp_decik == THERMAL_TEMP_INVALID) + *ret_temp = THERMAL_TEMP_INVALID; + else + *ret_temp = deci_kelvin_to_millicelsius(temp_decik); + + return 0; +} + /** * thermal_acpi_active_trip_temp - Retrieve active trip point temperature * @adev: Target thermal zone ACPI device object. @@ -57,12 +95,10 @@ static int thermal_acpi_trip_temp(struct */ int thermal_acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp) { - char obj_name[] = {'_', 'A', 'C', '0' + id, '\0'}; - - if (id < 0 || id > 9) - return -EINVAL; + int temp_decik; + int ret = acpi_active_trip_temp(adev, id, &temp_decik); - return thermal_acpi_trip_temp(adev, obj_name, ret_temp); + return thermal_temp(ret, temp_decik, ret_temp); } EXPORT_SYMBOL_GPL(thermal_acpi_active_trip_temp); @@ -78,7 +114,10 @@ EXPORT_SYMBOL_GPL(thermal_acpi_active_tr */ int thermal_acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp) { - return thermal_acpi_trip_temp(adev, "_PSV", ret_temp); + int temp_decik; + int ret = acpi_passive_trip_temp(adev, &temp_decik); + + return thermal_temp(ret, temp_decik, ret_temp); } EXPORT_SYMBOL_GPL(thermal_acpi_passive_trip_temp); @@ -95,7 +134,10 @@ EXPORT_SYMBOL_GPL(thermal_acpi_passive_t */ int thermal_acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp) { - return thermal_acpi_trip_temp(adev, "_HOT", ret_temp); + int temp_decik; + int ret = acpi_hot_trip_temp(adev, &temp_decik); + + return thermal_temp(ret, temp_decik, ret_temp); } EXPORT_SYMBOL_GPL(thermal_acpi_hot_trip_temp); @@ -111,6 +153,9 @@ EXPORT_SYMBOL_GPL(thermal_acpi_hot_trip_ */ int thermal_acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp) { - return thermal_acpi_trip_temp(adev, "_CRT", ret_temp); + int temp_decik; + int ret = acpi_critical_trip_temp(adev, &temp_decik); + + return thermal_temp(ret, temp_decik, ret_temp); } EXPORT_SYMBOL_GPL(thermal_acpi_critical_trip_temp); From patchwork Tue Oct 17 20:12:33 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: 154488 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp4375289vqb; Tue, 17 Oct 2023 13:13:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFAwlrtMHOLCt/BCQ2S93Id7N70y1j0PmsYq9suVZk/RImPCqPG31sr8/FjBSasIvpRjdyZ X-Received: by 2002:a17:902:d1c2:b0:1c7:1eed:10f2 with SMTP id g2-20020a170902d1c200b001c71eed10f2mr3329193plb.2.1697573582731; Tue, 17 Oct 2023 13:13:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697573582; cv=none; d=google.com; s=arc-20160816; b=Boy+y3/dKac1MMTywdY1blNX6UA3IekzL1Mg+nMGIIXbH0IcImN16EVB1mWePHkjdQ wwtY3qeI7ZNyazE24ABm4DQiBEu9f7RPfet4l0Mf8UbdSggsV6vrEXfZIXb7PA1f1E+c OWTa6w6Pa2mln/NdEHiyFamWGBUPVEuTWkCVtYhPJ5D4iDPInjClRXxXsAndGfWHYFmD t4WIk7djD3GgH6T8bNV/tv0A/zVWXy5dk2wA6TH7HxCjcoHhnjn7uVVWdw6jNDGUF2ei 45ofLdcNw0LYXUO/1ze4cXzi4PhZF6qznT2Zt1rFHhqJi8TxE4teBifArtboeduDsTgt Kwyw== 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=fO7kCKq4HZwri1f0DFaINOVzKoJH8NN6yUTrVCtWwDQ=; fh=p/Yd/06WV/NRg/vf6gGQsBGSNtCRQ5gqTvI3QmryL7M=; b=xCep6pwPE8XG1FD48nfWTZUtlOxRwUjDCWtss2fcqoQuJYoBPz326kirY8gWr+dVTn 4r6bChLbfhPOStIF9S0u7iJItpt8+3iFeJeXTh9QZY1tI+88AF7HiaWGPgw34RTTarZu TgHUMnv9iFXzlRPX0EQZdGzxkAC8ZK7fhNkuhcUXpF6nAtdWa7u4wH+P5j0XVadDvhIk zPpdrse6LEa0qJ5Zpinmf7hVGHclGMD8efksatqDbIjANn6P9FmOfaO7TsFJ0lITzmFi 2Or1LkR0Er0/OmbPUfmpEla7aINq02y1Z43Sm+CV0vOwV2dXPmyHIbq8KjaDQ2zS6I3b Pvgw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from morse.vger.email (morse.vger.email. [23.128.96.31]) by mx.google.com with ESMTPS id d17-20020a170902ced100b001c9cd55e303si2511778plg.589.2023.10.17.13.13.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Oct 2023 13:13:02 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 as permitted sender) client-ip=23.128.96.31; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.31 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 morse.vger.email (Postfix) with ESMTP id E9008801B8B7; Tue, 17 Oct 2023 13:12:58 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at morse.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234284AbjJQUMt (ORCPT + 21 others); Tue, 17 Oct 2023 16:12:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231149AbjJQUMr (ORCPT ); Tue, 17 Oct 2023 16:12:47 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11E4D6FAC; Tue, 17 Oct 2023 13:12:44 -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 5ff2401e82b762db; Tue, 17 Oct 2023 22:12:43 +0200 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 cloudserver094114.home.pl (Postfix) with ESMTPSA id 72FA9666BCD; Tue, 17 Oct 2023 22:12:42 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux PM Cc: Linux ACPI , Daniel Lezcano , LKML , Srinivas Pandruvada , "Rafael J. Wysocki" , Zhang Rui Subject: [PATCH v1 3/3] ACPI: thermal: Use library functions to obtain trip point temperature values Date: Tue, 17 Oct 2023 22:12:33 +0200 Message-ID: <2926905.e9J7NaK4W3@kreacher> In-Reply-To: <5740803.DvuYhMxLoT@kreacher> References: <5740803.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: gggruggvucftvghtrhhoucdtuddrgedvkedrjedvgddugeegucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecujffqoffgrffnpdggtffipffknecuuegrihhlohhuthemucduhedtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpefhvfevufffkfgjfhgggfgtsehtufertddttdejnecuhfhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqnecuggftrfgrthhtvghrnhepvdffueeitdfgvddtudegueejtdffteetgeefkeffvdeftddttdeuhfegfedvjefhnecukfhppeduleehrddufeeirdduledrleegnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepudelhedrudefiedrudelrdelgedphhgvlhhopehkrhgvrggthhgvrhdrlhhotggrlhhnvghtpdhmrghilhhfrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqedpnhgspghrtghpthhtohepjedprhgtphhtthhopehlihhnuhigqdhpmhesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopehlihhnuhigqdgrtghpihesvhhgvghrrdhkvghrnhgvlhdrohhrghdprhgtphhtthhopegurghnihgvlhdrlhgviigtrghnoheslhhinhgrrhhordhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghp thhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomhdprhgtphhtthhopehrrghfrggvlheskhgvrhhnvghlrdhorhhg X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 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 morse.vger.email 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 (morse.vger.email [0.0.0.0]); Tue, 17 Oct 2023 13:12:59 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1780034917069866773 X-GMAIL-MSGID: 1780034917069866773 From: Rafael J. Wysocki Modify the ACPI thermal driver to use functions from the ACPI thermal library to obtain trip point temperature values instead of duplicating them locally. Among other things, this requires the functions in question to be exported to it, because it can be built as a module. It effectively changes the behavior of the driver to treat temperature values out of the reasonable range (-55 centigrade to 175 centigrade) as invalid, but there is no other expected functional impact. Signed-off-by: Rafael J. Wysocki --- drivers/acpi/internal.h | 5 +++ drivers/acpi/thermal.c | 57 +++++++++++++++++++-------------------------- drivers/acpi/thermal_lib.c | 4 +++ 3 files changed, 34 insertions(+), 32 deletions(-) Index: linux-pm/drivers/acpi/thermal_lib.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal_lib.c +++ linux-pm/drivers/acpi/thermal_lib.c @@ -52,21 +52,25 @@ int acpi_active_trip_temp(struct acpi_de return acpi_trip_temp(adev, obj_name, ret_temp); } +EXPORT_SYMBOL_NS_GPL(acpi_active_trip_temp, ACPI_THERMAL); int acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp) { return acpi_trip_temp(adev, "_PSV", ret_temp); } +EXPORT_SYMBOL_NS_GPL(acpi_passive_trip_temp, ACPI_THERMAL); int acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp) { return acpi_trip_temp(adev, "_HOT", ret_temp); } +EXPORT_SYMBOL_NS_GPL(acpi_hot_trip_temp, ACPI_THERMAL); int acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp) { return acpi_trip_temp(adev, "_CRT", ret_temp); } +EXPORT_SYMBOL_NS_GPL(acpi_critical_trip_temp, ACPI_THERMAL); static int thermal_temp(int error, int temp_decik, int *ret_temp) { Index: linux-pm/drivers/acpi/internal.h =================================================================== --- linux-pm.orig/drivers/acpi/internal.h +++ linux-pm/drivers/acpi/internal.h @@ -85,6 +85,11 @@ bool acpi_scan_is_offline(struct acpi_de acpi_status acpi_sysfs_table_handler(u32 event, void *table, void *context); void acpi_scan_table_notify(void); +int acpi_active_trip_temp(struct acpi_device *adev, int id, int *ret_temp); +int acpi_passive_trip_temp(struct acpi_device *adev, int *ret_temp); +int acpi_hot_trip_temp(struct acpi_device *adev, int *ret_temp); +int acpi_critical_trip_temp(struct acpi_device *adev, int *ret_temp); + /* -------------------------------------------------------------------------- Device Node Initialization / Removal -------------------------------------------------------------------------- */ Index: linux-pm/drivers/acpi/thermal.c =================================================================== --- linux-pm.orig/drivers/acpi/thermal.c +++ linux-pm/drivers/acpi/thermal.c @@ -31,6 +31,8 @@ #include #include +#include "internal.h" + #define ACPI_THERMAL_CLASS "thermal_zone" #define ACPI_THERMAL_DEVICE_NAME "Thermal Zone" #define ACPI_THERMAL_NOTIFY_TEMPERATURE 0x80 @@ -188,24 +190,19 @@ static int active_trip_index(struct acpi static long get_passive_temp(struct acpi_thermal *tz) { - unsigned long long tmp; - acpi_status status; + int temp; - status = acpi_evaluate_integer(tz->device->handle, "_PSV", NULL, &tmp); - if (ACPI_FAILURE(status)) + if (acpi_passive_trip_temp(tz->device, &temp)) return THERMAL_TEMP_INVALID; - return tmp; + return temp; } 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; + int temp; - status = acpi_evaluate_integer(tz->device->handle, method, NULL, &tmp); - if (ACPI_FAILURE(status)) + if (acpi_active_trip_temp(tz->device, index, &temp)) return THERMAL_TEMP_INVALID; /* @@ -215,10 +212,10 @@ static long get_active_temp(struct acpi_ if (act > 0) { unsigned long long override = celsius_to_deci_kelvin(act); - if (tmp > override) - tmp = override; + if (temp > override) + return override; } - return tmp; + return temp; } static void acpi_thermal_update_trip(struct acpi_thermal *tz, @@ -339,13 +336,12 @@ static void acpi_thermal_trips_update(st dev_name(&adev->dev), event, 0); } -static long acpi_thermal_get_critical_trip(struct acpi_thermal *tz) +static int acpi_thermal_get_critical_trip(struct acpi_thermal *tz) { - unsigned long long tmp; - acpi_status status; + int temp; if (crt > 0) { - tmp = celsius_to_deci_kelvin(crt); + temp = celsius_to_deci_kelvin(crt); goto set; } if (crt == -1) { @@ -353,38 +349,34 @@ static long acpi_thermal_get_critical_tr return THERMAL_TEMP_INVALID; } - status = acpi_evaluate_integer(tz->device->handle, "_CRT", NULL, &tmp); - if (ACPI_FAILURE(status)) { - acpi_handle_debug(tz->device->handle, "No critical threshold\n"); + if (acpi_critical_trip_temp(tz->device, &temp)) return THERMAL_TEMP_INVALID; - } - if (tmp <= 2732) { + + if (temp <= 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); + pr_info(FW_BUG "Invalid critical threshold (%d)\n", temp); return THERMAL_TEMP_INVALID; } set: - acpi_handle_debug(tz->device->handle, "Critical threshold [%llu]\n", tmp); - return tmp; + acpi_handle_debug(tz->device->handle, "Critical threshold [%d]\n", temp); + return temp; } -static long acpi_thermal_get_hot_trip(struct acpi_thermal *tz) +static int acpi_thermal_get_hot_trip(struct acpi_thermal *tz) { - unsigned long long tmp; - acpi_status status; + int temp; - status = acpi_evaluate_integer(tz->device->handle, "_HOT", NULL, &tmp); - if (ACPI_FAILURE(status)) { + if (acpi_hot_trip_temp(tz->device, &temp) || temp == THERMAL_TEMP_INVALID) { acpi_handle_debug(tz->device->handle, "No hot threshold\n"); return THERMAL_TEMP_INVALID; } - acpi_handle_debug(tz->device->handle, "Hot threshold [%llu]\n", tmp); - return tmp; + acpi_handle_debug(tz->device->handle, "Hot threshold [%d]\n", temp); + return temp; } static bool passive_trip_params_init(struct acpi_thermal *tz) @@ -1142,6 +1134,7 @@ static void __exit acpi_thermal_exit(voi module_init(acpi_thermal_init); module_exit(acpi_thermal_exit); +MODULE_IMPORT_NS(ACPI_THERMAL); MODULE_AUTHOR("Paul Diefenbaugh"); MODULE_DESCRIPTION("ACPI Thermal Zone Driver"); MODULE_LICENSE("GPL");