Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp10970433rwp; Fri, 21 Jul 2023 07:27:13 -0700 (PDT) X-Google-Smtp-Source: APBJJlGGXezEL2cyFhn63NzcqM4/CcDQuzZYa7Xcb5oL1iHnpDKrvbLGDZk0KnQOyn8uA1imBnTm X-Received: by 2002:aa7:d1ca:0:b0:51e:5789:a71d with SMTP id g10-20020aa7d1ca000000b0051e5789a71dmr1515643edp.12.1689949633307; Fri, 21 Jul 2023 07:27:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689949633; cv=none; d=google.com; s=arc-20160816; b=BIff8JKvvfOalMdRP0JJvDv1kY0hVqN5odTw2DOCQA2Cb1UmjqZv+aXoKp9hTDGroc HHBvFB64ShVbuSbmsg++uvB+EqjnV9ML2T0p0/v1QJlWxZ53bSKUsmcoy9vnfe8ScbQ3 ntkw1LPDdrEPxbxEOdEt3vGaLwQ19z5G5zKJlF9f8+UFn0dPKu4rxYnxwDRK/TaKR8qA SWUjF99BGP7Jy2h4MNeEN2w6zuRJSzIku+gvwYO0lRk+4xuDIAXYy96MuX2qnGqZAp/A qgys3yoY+/gtuAPyBf8nfWy/0WqP9cbSHaQbiSmfkM+9ACSMecuNn6I6UAwMGhX6JkYB AlZg== 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=7YPAhkn/ybOsSstiqyMkCk/r2doVagVgOxB61LHdxGM=; fh=WAm0nkxw3rD71A4QzwJS1JiPPKRsyn91IiWMPsOrzoY=; b=wl2fugwHVvf6TOzD+O7gnvfvtgbiOyF5SOZ25w2Zn13KbD/8Upig1NDRdbN+uBJmX1 mLolQb/54lRS/ORU2FyHdEppQ9qbM3S78uoYsorCjUr2nnds7yWdSprqxQATRXcFuhjG 7N5UqSDbIvSWb2hJb8aG5QaY1pfcwJWRM4y/OtnsUcmt6feuGJngMy6//YukW44ksf+8 Fk9uiOCbJiV3z3ixR2fVUParXSCBMDILpjp1k+NlWhr+Qh1O07339LYhng/ApVITfGhj SQiNeBVjErsciTlZwvM3V0/Wa0D1yPM3Xz41ntLHyulvp+f2LY+yNzFbHr0+SE1iB4DF ACLg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d3-20020aa7ce03000000b00521d1c34b1bsi2222628edv.189.2023.07.21.07.26.43; Fri, 21 Jul 2023 07:27:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231771AbjGUOHk (ORCPT + 99 others); Fri, 21 Jul 2023 10:07:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231641AbjGUOH1 (ORCPT ); Fri, 21 Jul 2023 10:07:27 -0400 Received: from cloudserver094114.home.pl (cloudserver094114.home.pl [79.96.170.134]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3CA58273F; Fri, 21 Jul 2023 07:07:24 -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 3dc22f17bb37cb2b; Fri, 21 Jul 2023 16:07:22 +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 v370.home.net.pl (Postfix) with ESMTPSA id 3E98A6618EA; Fri, 21 Jul 2023 16:07:22 +0200 (CEST) From: "Rafael J. Wysocki" To: Linux ACPI Cc: LKML , Linux PM , Michal Wilczynski , Zhang Rui , Srinivas Pandruvada , Daniel Lezcano Subject: [PATCH v2 1/8] thermal: core: Add mechanism for connecting trips with driver data Date: Fri, 21 Jul 2023 14:46:38 +0200 Message-ID: <4862397.31r3eYUQgx@kreacher> In-Reply-To: <5710197.DvuYhMxLoT@kreacher> References: <13318886.uLZWGnKmhe@kreacher> <5710197.DvuYhMxLoT@kreacher> MIME-Version: 1.0 Content-Transfer-Encoding: 7Bit Content-Type: text/plain; charset="UTF-8" X-CLIENT-IP: 195.136.19.94 X-CLIENT-HOSTNAME: 195.136.19.94 X-VADE-SPAMSTATE: clean X-VADE-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedviedrhedvgdeikecutefuodetggdotefrodftvfcurfhrohhfihhlvgemucfjqffogffrnfdpggftiffpkfenuceurghilhhouhhtmecuudehtdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujfgurhephffvvefufffkjghfggfgtgesthfuredttddtjeenucfhrhhomhepfdftrghfrggvlhculfdrucghhihsohgtkhhifdcuoehrjhifsehrjhifhihsohgtkhhirdhnvghtqeenucggtffrrghtthgvrhhnpedvffeuiedtgfdvtddugeeujedtffetteegfeekffdvfedttddtuefhgeefvdejhfenucfkphepudelhedrudefiedrudelrdelgeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpeduleehrddufeeirdduledrleegpdhhvghlohepkhhrvggrtghhvghrrdhlohgtrghlnhgvthdpmhgrihhlfhhrohhmpedftfgrfhgrvghlucflrdcuhgihshhotghkihdfuceorhhjfiesrhhjfiihshhotghkihdrnhgvtheqpdhnsggprhgtphhtthhopeejpdhrtghpthhtoheplhhinhhugidqrggtphhisehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqkhgvrhhnvghlsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtoheplhhinhhugidqphhmsehvghgvrhdrkhgvrhhnvghlrdhorhhgpdhrtghpthhtohepmhhitghhrghlrdifihhltgiihihnshhkihesihhnthgvlhdrtghomhdprhgt phhtthhopehruhhirdiihhgrnhhgsehinhhtvghlrdgtohhmpdhrtghpthhtohepshhrihhnihhvrghsrdhprghnughruhhvrggurgeslhhinhhugidrihhnthgvlhdrtghomh X-DCC--Metrics: v370.home.net.pl 1024; Body=7 Fuz1=7 Fuz2=7 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Rafael J. Wysocki Some drivers need to update trip point data (temperature and/or hysteresis) upon notifications from the platform firmware or they may need to reprogram hardware when trip point parameters are changed via sysfs. For those purposes, they need to connect struct thermal_trip to a private data set associated with the trip or the other way around and using a trip point index for that may not always work, because the core may need to reorder the trips during thermal zone registration (in particular, they may need to be sorted). To allow that to be done without using a trip point index, introduce a new field in struct thermal_trip that can be pointed by the driver to its own data structure containing a trip pointer to be initialized by the core during thermal zone registration. That pointer will then have to be updated by the core every time the location of the given trip point object in memory changes. Signed-off-by: Rafael J. Wysocki --- v1 -> v2: No changes. --- drivers/thermal/thermal_core.c | 20 +++++++++++++++++--- include/linux/thermal.h | 13 +++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) Index: linux-pm/include/linux/thermal.h =================================================================== --- linux-pm.orig/include/linux/thermal.h +++ linux-pm/include/linux/thermal.h @@ -76,16 +76,29 @@ struct thermal_zone_device_ops { void (*critical)(struct thermal_zone_device *); }; +struct thermal_trip_ref { + struct thermal_trip *trip; +}; + /** * struct thermal_trip - representation of a point in temperature domain * @temperature: temperature value in miliCelsius * @hysteresis: relative hysteresis in miliCelsius * @type: trip point type + * @driver_ref: driver's reference to this trip point + * + * If @driver_ref is not NULL, the trip pointer in the object pointed to by it + * will be initialized by the core during thermal zone registration and updated + * whenever the location of the given trip object changes. This allows the + * driver to access the trip point data without knowing the relative ordering + * of trips within the trip table used by the core and, given a trip pointer, + * to get back to its private data associated with the given trip. */ struct thermal_trip { int temperature; int hysteresis; enum thermal_trip_type type; + struct thermal_trip_ref *driver_ref; }; struct thermal_cooling_device_ops { Index: linux-pm/drivers/thermal/thermal_core.c =================================================================== --- linux-pm.orig/drivers/thermal/thermal_core.c +++ linux-pm/drivers/thermal/thermal_core.c @@ -1306,14 +1306,28 @@ thermal_zone_device_register_with_trips( if (result) goto release_device; + mutex_lock(&tz->lock); + for (count = 0; count < num_trips; count++) { - struct thermal_trip trip; + int temperature = 0; + + if (trips) { + temperature = trips[count].temperature; + if (trips[count].driver_ref) + trips[count].driver_ref->trip = &trips[count]; + } else { + struct thermal_trip trip; - result = thermal_zone_get_trip(tz, count, &trip); - if (result || !trip.temperature) + result = __thermal_zone_get_trip(tz, count, &trip); + if (!result) + temperature = trip.temperature; + } + if (!temperature) set_bit(count, &tz->trips_disabled); } + mutex_unlock(&tz->lock); + /* Update 'this' zone's governor information */ mutex_lock(&thermal_governor_lock);