From patchwork Sat Feb 25 11:51:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13152202 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2761C7EE2D for ; Sat, 25 Feb 2023 11:51:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229577AbjBYLv5 (ORCPT ); Sat, 25 Feb 2023 06:51:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbjBYLv4 (ORCPT ); Sat, 25 Feb 2023 06:51:56 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B2B6EB66; Sat, 25 Feb 2023 03:51:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1677325909; i=w_armin@gmx.de; bh=uNkbSijDFzzTJZKTSAPmytRUJkMoQgMb2ySqr5S1jhI=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=Z0Mwqs/1QKrzB00G56YTFOiw15irpwTvDO68WHXEiTlY34aDPhWtgOvoXfaHiyytq EAglFYr+CsZzg0T3iTq18Od3qxShMV4dk38ePGRh2Lt2qyKTSCgyFPkW3wONrNXhEx i4FrajEoG6OJu2wCPjjRJta4VeH9OPzdEQsp8lriSRmav4/Nu6WtqmnQ0WPJJN7FPu iHHoVRzdzf2kr9nK03eqIhXmxjg8GTHL87q55L19tq0s5yg4hLIwkfiCShiO71ECSu TYUmvTe67lMazZAJYKGbgbUSZkJM/eUTav8j4PEUfWNsFjcL19LWuOoslkZcgOfdYd MDoqzflLqqnlA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx105 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MWzfl-1oyVIq106D-00XH2d; Sat, 25 Feb 2023 12:51:49 +0100 From: Armin Wolf To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/4] ACPI: EC: Add query notifier support Date: Sat, 25 Feb 2023 12:51:41 +0100 Message-Id: <20230225115144.31212-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230225115144.31212-1-W_Armin@gmx.de> References: <20230225115144.31212-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:9qgZ5XlFM1dryjZe2sJc4b7Jw5L9axQsA1h4k3y+Zz7idOC6AjV +Yi6jVeciqKezY5I+NJ8gOD3G949OkqtS9X/mjfILfFkBlcALfEEru9YySIK0D5kljYPqoH iExcNfLy7BiMrCl5mK2clH0dMri8Vt1KT3iG7Yul/sNnKHA3VxXSo1J48fpCwO4Ok9ayhAR SUJaft8Ub5SXn+Sjb36Vg== UI-OutboundReport: notjunk:1;M01:P0:ydJxzquC0oA=;LaAWoSS1aHtgk6pESX/9Q62um7y iVOKgI+IUGy+wUD8bRNFa95biLuSgdO/MYjpLC2JMlk0lpUVoctLShTBV619AGgXjHDF9rHr8 KjANzzvmCG4NzKMZnqhYnJ6WsZL1YKspUjovPF+914FPhp/B38iDwNrrG5lyRH5HXX6aLF/gM Zppuh70gFmBcas+NzlPbY6eMjOGHw4DDVmWhu2Rbnz0R4J+LNTkMM3kwzoteRMRw+5ICzTYlk W60GsdzMsMdPOY6dfY8WwK8/7yg8ePV+5CKZlu+D76kk/QrNj8Wr/Htl9+GZzN3Y4N1BJxfv0 bKorxlt22atlV/m1BRUMMem280815pvTWsStHUAOoZb4EFvhUQrMR8pR9EPjQMoEQBWtVGuDC K+NZwN/RGolAypQCo4+wtWtn0J+acnm847/I0PUw2S1puV7rs5qmUcvD5lDaGFCC8YttEUwOT GXUR96DeH8UZSvjjsVyv3RJzK+SLBan4MfwV0apH5tVuCOCSLyGKbmCi1OzBZW5cNKpvYULwg l77gO7UcTsYuPlZRKRgxFOqciiNCJSrrulCWw5PIyRxS/njJrbMetGKNvYfBw0rLWgqlAJBXe d5WBFXMwm5vmP1tUXi/pfoOCuKRRBsKRgsiuhkKJ5fqK2BerucJ/0o19FIp0jB2LrZzmhIsqb naajBPqYBGMeFLPX/DhATVRrs8pwpALYEl3gePXQtOrPXFPaSVSs3cgPfSpmMlsVosOIIDgAF iPkgcXbY6bg//VtVsXgagKJUOimc8fKGpDUGwtv6Hze2oLRhM9qEW8ZpyoiAaoNIL2wAFFrcM ehaFdpTRgiE/TkYB1z7hntBlTdgbn8izw7BUVy7fIv3s4zHy1QEOYJfcEgwNp9Dgs1pSDS8su NkgXe4/bbBbyZ0jBOaK2JYOiWmzBBG/2pQDVZjNzJxZ4Tp8Robq+WmYL3tPqCUobwVfaB91Ts o5OiVt9MX9yNHDKtQ89sIEnfxwY= Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Allow external drivers to register notifiers to act on query events and possibly override the query handler. Use the existing notifier infrastructure for this to ensure correct locking. Tested on a Acer Travelmate 4002WLMi. Signed-off-by: Armin Wolf --- drivers/acpi/ec.c | 28 ++++++++++++++++++++++++---- drivers/acpi/internal.h | 5 +++++ 2 files changed, 29 insertions(+), 4 deletions(-) -- 2.30.2 diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index 105d2e795afa..dc7860a825a0 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -184,6 +185,8 @@ static int EC_FLAGS_CORRECT_ECDT; /* Needs ECDT port address correction */ static int EC_FLAGS_TRUST_DSDT_GPE; /* Needs DSDT GPE as correction setting */ static int EC_FLAGS_CLEAR_ON_RESUME; /* Needs acpi_ec_clear() on boot/resume */ +static BLOCKING_NOTIFIER_HEAD(acpi_ec_chain_head); + /* -------------------------------------------------------------------------- * Logging/Debugging * -------------------------------------------------------------------------- */ @@ -1125,18 +1128,35 @@ void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit) } EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler); +int register_acpi_ec_query_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_register(&acpi_ec_chain_head, nb); +} +EXPORT_SYMBOL_GPL(register_acpi_ec_query_notifier); + +int unregister_acpi_ec_query_notifier(struct notifier_block *nb) +{ + return blocking_notifier_chain_unregister(&acpi_ec_chain_head, nb); +} +EXPORT_SYMBOL_GPL(unregister_acpi_ec_query_notifier); + static void acpi_ec_event_processor(struct work_struct *work) { struct acpi_ec_query *q = container_of(work, struct acpi_ec_query, work); struct acpi_ec_query_handler *handler = q->handler; struct acpi_ec *ec = q->ec; + int ret; ec_dbg_evt("Query(0x%02x) started", handler->query_bit); - if (handler->func) - handler->func(handler->data); - else if (handler->handle) - acpi_evaluate_object(handler->handle, NULL, NULL, NULL); + /* Allow notifier handlers to override query handlers */ + ret = blocking_notifier_call_chain(&acpi_ec_chain_head, handler->query_bit, ec); + if (ret != NOTIFY_BAD) { + if (handler->func) + handler->func(handler->data); + else if (handler->handle) + acpi_evaluate_object(handler->handle, NULL, NULL, NULL); + } ec_dbg_evt("Query(0x%02x) stopped", handler->query_bit); diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index ec584442fb29..6f41d42375ab 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h @@ -11,6 +11,8 @@ #include +struct notifier_block; + int early_acpi_osi_init(void); int acpi_osi_init(void); acpi_status acpi_os_initialize1(void); @@ -212,6 +214,9 @@ int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit, void *data); void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit); +int register_acpi_ec_query_notifier(struct notifier_block *nb); +int unregister_acpi_ec_query_notifier(struct notifier_block *nb); + #ifdef CONFIG_PM_SLEEP void acpi_ec_flush_work(void); bool acpi_ec_dispatch_gpe(void); From patchwork Sat Feb 25 11:51:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13152203 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50406C7EE2D for ; Sat, 25 Feb 2023 11:52:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229672AbjBYLwH (ORCPT ); Sat, 25 Feb 2023 06:52:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229584AbjBYLv5 (ORCPT ); Sat, 25 Feb 2023 06:51:57 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8225DEB56; Sat, 25 Feb 2023 03:51:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1677325910; i=w_armin@gmx.de; bh=9r+ibg9eKkn9LExgzAaFAAWxIQXWfKeAQOOzxQ4bOco=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=suEfYPFINR/U/BcFNv/JmDGwoghohvyQEZAP8M89uDhziNaD7UHoPw0Msc9n3fE79 U8XNWMUEv3CQXo6fF92lSWr/lmG//Q3bfXOLa5z+U8zOY2weAx6zilSUYWMy2XrxFY KryXXt9yq5yco8vCd8FUyyPlKhZWM0lfFlxhaId/QoUx5t+Q2Nqylgu1pb4MfRmVUh d+N99etPwPErwqfbCuXmrQ3k2agfhcbg8myOfy8418FYF5gqkq1NygcGO67O8m7eV6 ThTbv1y6VRLfaIg6rP7/wgwE+wisMXuz/yekZTe1t0ra5C6lDLVN84KJT4lZXW1Vc/ T1Usum1C8c/ZA== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx004 [212.227.17.190]) with ESMTPSA (Nemesis) id 1Ml6mE-1omciw2sWa-00lR83; Sat, 25 Feb 2023 12:51:50 +0100 From: Armin Wolf To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/4] ACPI: sbshc: Use ec query notifier call chain Date: Sat, 25 Feb 2023 12:51:42 +0100 Message-Id: <20230225115144.31212-3-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230225115144.31212-1-W_Armin@gmx.de> References: <20230225115144.31212-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:97y7HOV9TVYZthxibjFFCPaN/VhpTWBWew6Ay/XiBe1eLrtT4jU Fw7QnixGQ+kddXPMRCfPm+sCmGWIpAiCtFO77dDa3Ch0PSVr4hMVctzHWpIfaXHslgfZG0c PJ7PPyzdYR2u98MAL7rWUCdi+bRrBCgFvU6y7D76zaapP65gCd2obDYrwb4pEymtj+9EtBD EYsqKPTYqQANHFWJm5Mdg== UI-OutboundReport: notjunk:1;M01:P0:vAzVw2yu2HA=;MiXpS3/tw8r/Yfje2i/WqqIDtp7 iHaRRPBz8EYzStKtlluD1ePm7TuWvXkbzJM/ElzrZv97eAk9rGU2ty1oV9Jl2MtuGh0QJ2A/B i5KMFfjkUU7H+97HNjrVHj4ubTJLrjhPBqQAZwPZ6hE2nFExjoBsq44mad/jLaBPMKDwT+LEw zhBa3aydp6ZmgELlnnmZDUrH/BsMzpAgxzpgwgQM0ky6MPPCUfWbLcnUBvDL5M8Je+T+kN5n8 U95xVMZqixfPgY8otFl98CSfXXbX7BwHgD3cwc1YPTlQyepj/9wyOTzsXfQfwsVcWWbXPGYIk 6jdU06pLdQ0z4+vHDV7nXz/yF/GJhleRQ27UK6wBTlsx/mjnc7DdThP/sCUux/uNN/HFoi/8L SMiTC7Ppu14UByRDJhhLFLvSGOMICWgRxWaFso/871yCTcjRPUBaJ0yk8HvAYZn3D9jGtH0dz R4j1pbTmNEeyANrckKrLirR+NfHVcAN236IF+obSeI41qP/auvipSHGAxEB3iKAEkoOiZViII WOP76AURq0+MXEex5+CZ8ORgYGJcKHCvmfeFlNDm+BaB0fN0aCeSWdVIwrFOxIdx9vRExtjmE va5TNRr9ptnYDONfmJFvp4Lvpr4Rn/iKE7oiINb52NOD5SsPWunnengA/2rfN6l+fsq2/bif5 ded8GX2m7bKgpEr5qx9Xxv8d6KTbvOkAXUK1vGoVyENtzSippq3UncJg/SZX31U5Jt+JDGOxF yLfZ2BDOYavfP45LMOrhBtKBjSKFqNan6BSM7r1aA6uq/eiGftvGg+WD0oIZ228+3xRkKOYjW H3vRQ7UdRuqD9yA0VpSrQlhNvCznt3ONY2UlkXgiVrKS6Q8QTdn9wt5KXwhhcc8SgmYvILzmL BhrJWGzL8B1OqwuWS4Qs1w/R+UWpt65DzsSkAc5pjT601mR0CVvu98QVSTNV3SO6ssXJV/zUm OCT9BiQqDoEuFL4hx3pchgdpiMg= Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org When using acpi_ec_add_query_handler(), a kernel oops can occur when unloading the sbshc module, since the handler callback might still be used by a work item inside the ec workqueue. Use the new ec query notifier call chain to register the handler in a safe way. Return NOTIFY_BAD to override the existing _Qxx handler in case the query was meant for the EC SMBus controller. Tested on a Acer Travelmate 4002WLMi. Signed-off-by: Armin Wolf --- drivers/acpi/sbshc.c | 45 ++++++++++++++++++++++++++++---------------- 1 file changed, 29 insertions(+), 16 deletions(-) -- 2.30.2 diff --git a/drivers/acpi/sbshc.c b/drivers/acpi/sbshc.c index 16f2daaa2c45..e3280f646eb5 100644 --- a/drivers/acpi/sbshc.c +++ b/drivers/acpi/sbshc.c @@ -8,11 +8,14 @@ #define pr_fmt(fmt) "ACPI: " fmt #include +#include #include #include #include #include #include + +#include "internal.h" #include "sbshc.h" #define ACPI_SMB_HC_CLASS "smbus_host_ctl" @@ -20,6 +23,7 @@ struct acpi_smb_hc { struct acpi_ec *ec; + struct notifier_block nb; struct mutex lock; wait_queue_head_t wait; u8 offset; @@ -194,6 +198,7 @@ int acpi_smbus_unregister_callback(struct acpi_smb_hc *hc) hc->context = NULL; mutex_unlock(&hc->lock); acpi_os_wait_events_complete(); + return 0; } @@ -206,20 +211,28 @@ static inline void acpi_smbus_callback(void *context) hc->callback(hc->context); } -static int smbus_alarm(void *context) +static int acpi_smbus_hc_notify(struct notifier_block *block, unsigned long action, void *data) { - struct acpi_smb_hc *hc = context; + struct acpi_smb_hc *hc = container_of(block, struct acpi_smb_hc, nb); union acpi_smb_status status; + struct acpi_ec *ec = data; u8 address; + + if (ec != hc->ec || action != hc->query_bit) + return NOTIFY_DONE; + if (smb_hc_read(hc, ACPI_SMB_STATUS, &status.raw)) - return 0; + return NOTIFY_OK; + /* Check if it is only a completion notify */ if (status.fields.done && status.fields.status == SMBUS_OK) { hc->done = true; wake_up(&hc->wait); } + if (!status.fields.alarm) - return 0; + return NOTIFY_BAD; + mutex_lock(&hc->lock); smb_hc_read(hc, ACPI_SMB_ALARM_ADDRESS, &address); status.fields.alarm = 0; @@ -233,20 +246,16 @@ static int smbus_alarm(void *context) acpi_smbus_callback, hc); } mutex_unlock(&hc->lock); - return 0; -} -typedef int (*acpi_ec_query_func) (void *data); - -extern int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit, - acpi_handle handle, acpi_ec_query_func func, - void *data); + /* We may need to override existing _Qxx handlers */ + return NOTIFY_BAD; +} static int acpi_smbus_hc_add(struct acpi_device *device) { - int status; unsigned long long val; struct acpi_smb_hc *hc; + int status, ret; if (!device) return -EINVAL; @@ -271,15 +280,19 @@ static int acpi_smbus_hc_add(struct acpi_device *device) hc->query_bit = val & 0xff; device->driver_data = hc; - acpi_ec_add_query_handler(hc->ec, hc->query_bit, NULL, smbus_alarm, hc); + hc->nb.notifier_call = acpi_smbus_hc_notify; + ret = register_acpi_ec_query_notifier(&hc->nb); + if (ret < 0) { + kfree(hc); + return ret; + } + dev_info(&device->dev, "SBS HC: offset = 0x%0x, query_bit = 0x%0x\n", hc->offset, hc->query_bit); return 0; } -extern void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit); - static void acpi_smbus_hc_remove(struct acpi_device *device) { struct acpi_smb_hc *hc; @@ -288,7 +301,7 @@ static void acpi_smbus_hc_remove(struct acpi_device *device) return; hc = acpi_driver_data(device); - acpi_ec_remove_query_handler(hc->ec, hc->query_bit); + unregister_acpi_ec_query_notifier(&hc->nb); acpi_os_wait_events_complete(); kfree(hc); device->driver_data = NULL; From patchwork Sat Feb 25 11:51:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13152205 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B11AFC64EC7 for ; Sat, 25 Feb 2023 11:52:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229688AbjBYLwH (ORCPT ); Sat, 25 Feb 2023 06:52:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229589AbjBYLv7 (ORCPT ); Sat, 25 Feb 2023 06:51:59 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91230EC78; Sat, 25 Feb 2023 03:51:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1677325912; i=w_armin@gmx.de; bh=aFx93Bs3vYD/A1ztGnO44q1Pozj+Rsgp1DXI8DNLUVM=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=SsJIX2Njz3jsKKh5Lhjm7mgnEedGtKoTZeJsl9W/wW+MDKmveRzdE8fxOf9PeM8CR 6pcgMX3WLkAbZG5jMupEf8lck5Nm8m1HY8iZcGq/iFjZOr+ScgO3k+2jXglqQWaVfz iqJ2CxEskcAj6co4hYrg5NxYHsZEqyK6CouP+tpMy+upC+MDsuaGYv6p7S8f2Wdy2x 1q41sB7CXUGE4uqiHhL4xPWssRW0Xo+iF3Ioav0uVeqQilVkP7D0Bja7eIUmzYLS3d v3Bzw4l69GPEcogDZg/Ym1/lewtmtsUT+NZUObSQQUQ60oG4ymPmDPDtld3KZS24oy JwAbgqL3xgIKw== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx005 [212.227.17.190]) with ESMTPSA (Nemesis) id 1MYNNo-1p1W6f3XKk-00VQAL; Sat, 25 Feb 2023 12:51:51 +0100 From: Armin Wolf To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 3/4] ACPI: EC: Make query handlers private Date: Sat, 25 Feb 2023 12:51:43 +0100 Message-Id: <20230225115144.31212-4-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230225115144.31212-1-W_Armin@gmx.de> References: <20230225115144.31212-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:T1zgduE095Lm7fr46vit2+r1mQQBRo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YOX1S+A/5AGWdY2IW55+etqYoJj7Q5DP9f0vIR/Fa KZJHyvLMKRXQ6aYveF262Q0qZ73kBf9mmfkdGQ87iqMD2OnbOvH3GvA6W5VZIPBaPsHfEfEDZ UB3hiEtq83wdADHQaNtQo1izfQM= Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The ability for external modules to register query handlers was broken for a long time due to having only a single user. With the only user (sbshc) having been converted to use the more robust query notifier call chain, the query handler functionality can be made private. This also allows for some cleanups. Tested on a Acer Travelmate 4000WLMi. Signed-off-by: Armin Wolf --- drivers/acpi/ec.c | 36 ++++++++---------------------------- drivers/acpi/internal.h | 5 ----- 2 files changed, 8 insertions(+), 33 deletions(-) -- 2.30.2 diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index dc7860a825a0..825493d38a4f 100644 --- a/drivers/acpi/ec.c +++ b/drivers/acpi/ec.c @@ -143,9 +143,7 @@ MODULE_PARM_DESC(ec_no_wakeup, "Do not wake up from suspend-to-idle"); struct acpi_ec_query_handler { struct list_head node; - acpi_ec_query_func func; acpi_handle handle; - void *data; u8 query_bit; struct kref kref; }; @@ -1082,9 +1080,7 @@ static void acpi_ec_put_query_handler(struct acpi_ec_query_handler *handler) kref_put(&handler->kref, acpi_ec_query_handler_release); } -int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit, - acpi_handle handle, acpi_ec_query_func func, - void *data) +static int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit, acpi_handle handle) { struct acpi_ec_query_handler *handler = kzalloc(sizeof(struct acpi_ec_query_handler), GFP_KERNEL); @@ -1094,40 +1090,28 @@ int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit, handler->query_bit = query_bit; handler->handle = handle; - handler->func = func; - handler->data = data; mutex_lock(&ec->mutex); kref_init(&handler->kref); list_add(&handler->node, &ec->list); mutex_unlock(&ec->mutex); return 0; } -EXPORT_SYMBOL_GPL(acpi_ec_add_query_handler); -static void acpi_ec_remove_query_handlers(struct acpi_ec *ec, - bool remove_all, u8 query_bit) +static void acpi_ec_remove_query_handlers(struct acpi_ec *ec) { struct acpi_ec_query_handler *handler, *tmp; LIST_HEAD(free_list); mutex_lock(&ec->mutex); list_for_each_entry_safe(handler, tmp, &ec->list, node) { - if (remove_all || query_bit == handler->query_bit) { - list_del_init(&handler->node); - list_add(&handler->node, &free_list); - } + list_del_init(&handler->node); + list_add(&handler->node, &free_list); } mutex_unlock(&ec->mutex); list_for_each_entry_safe(handler, tmp, &free_list, node) acpi_ec_put_query_handler(handler); } -void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit) -{ - acpi_ec_remove_query_handlers(ec, false, query_bit); -} -EXPORT_SYMBOL_GPL(acpi_ec_remove_query_handler); - int register_acpi_ec_query_notifier(struct notifier_block *nb) { return blocking_notifier_chain_register(&acpi_ec_chain_head, nb); @@ -1151,12 +1135,8 @@ static void acpi_ec_event_processor(struct work_struct *work) /* Allow notifier handlers to override query handlers */ ret = blocking_notifier_call_chain(&acpi_ec_chain_head, handler->query_bit, ec); - if (ret != NOTIFY_BAD) { - if (handler->func) - handler->func(handler->data); - else if (handler->handle) - acpi_evaluate_object(handler->handle, NULL, NULL, NULL); - } + if (ret != NOTIFY_BAD && handler->handle) + acpi_evaluate_object(handler->handle, NULL, NULL, NULL); ec_dbg_evt("Query(0x%02x) stopped", handler->query_bit); @@ -1402,7 +1382,7 @@ acpi_ec_register_query_methods(acpi_handle handle, u32 level, status = acpi_get_name(handle, ACPI_SINGLE_NAME, &buffer); if (ACPI_SUCCESS(status) && sscanf(node_name, "_Q%x", &value) == 1) - acpi_ec_add_query_handler(ec, value, handle, NULL, NULL); + acpi_ec_add_query_handler(ec, value, handle); return AE_OK; } @@ -1587,7 +1567,7 @@ static void ec_remove_handlers(struct acpi_ec *ec) clear_bit(EC_FLAGS_EVENT_HANDLER_INSTALLED, &ec->flags); } if (test_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags)) { - acpi_ec_remove_query_handlers(ec, true, 0); + acpi_ec_remove_query_handlers(ec); clear_bit(EC_FLAGS_QUERY_METHODS_INSTALLED, &ec->flags); } } diff --git a/drivers/acpi/internal.h b/drivers/acpi/internal.h index 6f41d42375ab..72ce5a9ba57f 100644 --- a/drivers/acpi/internal.h +++ b/drivers/acpi/internal.h @@ -202,17 +202,12 @@ extern struct acpi_ec *first_ec; /* If we find an EC via the ECDT, we need to keep a ptr to its context */ /* External interfaces use first EC only, so remember */ -typedef int (*acpi_ec_query_func) (void *data); void acpi_ec_init(void); void acpi_ec_ecdt_probe(void); void acpi_ec_dsdt_probe(void); void acpi_ec_block_transactions(void); void acpi_ec_unblock_transactions(void); -int acpi_ec_add_query_handler(struct acpi_ec *ec, u8 query_bit, - acpi_handle handle, acpi_ec_query_func func, - void *data); -void acpi_ec_remove_query_handler(struct acpi_ec *ec, u8 query_bit); int register_acpi_ec_query_notifier(struct notifier_block *nb); int unregister_acpi_ec_query_notifier(struct notifier_block *nb); From patchwork Sat Feb 25 11:51:44 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13152204 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DDF47C7EE2F for ; Sat, 25 Feb 2023 11:52:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229700AbjBYLwI (ORCPT ); Sat, 25 Feb 2023 06:52:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbjBYLwA (ORCPT ); Sat, 25 Feb 2023 06:52:00 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.17.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2B96419F31; Sat, 25 Feb 2023 03:51:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1677325914; i=w_armin@gmx.de; bh=Kf5tr2Sg9Jqyp+j3xyIw9/QWCzBL3T6tk+vssRythnI=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=c0xUIIR4n8Ta7Pq7e9hvf2X5cHaEbZm+PoZFbaPg7b6b2EFiv+u1G33ibkY4OZrql 6boChBK+jv1p4hPBagpvxw/b2Luc7pu2DKvhhz4Au2CpIRA9WfUO93GfRpE5QdCXkQ 8qztMahw+2Ti0FIwILlblrTUIFQDpHNGU57Lfq44Ofzxiw7Ri7coBD/9Bt2uY3NFYq UpvtfMIyVSE/VV9wtjfaFv+byC6cnd3ru8KNSVeIxOBdN4i6VyohLUrZMb15Gy+Phf E6Lmz4KgbZx1kWiMSSHhUdjEkzgrmJguL7UYxizCZTz0gsJiqFAllmphnSrCCziM0K SkrRXClOn0Omg== X-UI-Sender-Class: 724b4f7f-cbec-4199-ad4e-598c01a50d3a Received: from esprimo-mx.users.agdsn.de ([141.30.226.129]) by mail.gmx.net (mrgmx104 [212.227.17.168]) with ESMTPSA (Nemesis) id 1MoO24-1oh6wL3TUO-00oncz; Sat, 25 Feb 2023 12:51:53 +0100 From: Armin Wolf To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 4/4] ACPI: SBS: Fix handling of Smart Battery Selectors Date: Sat, 25 Feb 2023 12:51:44 +0100 Message-Id: <20230225115144.31212-5-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230225115144.31212-1-W_Armin@gmx.de> References: <20230225115144.31212-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:kj0EMGZQOKo1DIaNjvZpdw3cvFja6SPU6xwfeorMcBeWFCVw6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rUT5OldYPhbyibr/S6DMqnsjrFjaWsh2wdSAcEQBrCelsEHzViD 4roC4p8QYUijIyhcZvBflYhVO0A56iQAXBryWDZtRbuKV+NBRGLpI11WisE8bi+JY650rthPM pPHD92ESyUDgjLMtRkL1zb0Q4ZA= Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org The "Smart Battery Selector" standard says that when writing SelectorState (0x1), the nibbles which should not be modified need to be masked with 0xff. This is necessary since in contrast to a "Smart Battery Manager", the last three nibbles are writable. Failing to do so might trigger the following cycle: 1. Host accidentally changes power source of the system (3rd nibble) when selecting a battery. 2. Power source is invalid, Selector changes to another power source. 3. Selector notifies host that it changed the power source. 4. Host re-reads some batteries. 5. goto 1 for each re-read battery. This loop might also be entered when a battery which is not present is selected for SMBus access. In the end some workqueues fill up, which causes the system to lockup upon suspend/shutdown. Fix this by correctly masking the value to be written, and avoid selecting batteries which are absent. Tested on a Acer Travelmate 4002WLMi. Signed-off-by: Armin Wolf --- drivers/acpi/sbs.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) -- 2.30.2 diff --git a/drivers/acpi/sbs.c b/drivers/acpi/sbs.c index e90752d4f488..94e3c000df2e 100644 --- a/drivers/acpi/sbs.c +++ b/drivers/acpi/sbs.c @@ -473,23 +473,32 @@ static const struct device_attribute alarm_attr = { -------------------------------------------------------------------------- */ static int acpi_battery_read(struct acpi_battery *battery) { - int result = 0, saved_present = battery->present; + int result, saved_present = battery->present; u16 state; if (battery->sbs->manager_present) { result = acpi_smbus_read(battery->sbs->hc, SMBUS_READ_WORD, ACPI_SBS_MANAGER, 0x01, (u8 *)&state); - if (!result) - battery->present = state & (1 << battery->id); - state &= 0x0fff; + if (result) + return result; + + battery->present = state & (1 << battery->id); + if (!battery->present) + return 0; + + /* Masking necessary for Smart Battery Selectors */ + state = 0x0fff; state |= 1 << (battery->id + 12); acpi_smbus_write(battery->sbs->hc, SMBUS_WRITE_WORD, ACPI_SBS_MANAGER, 0x01, (u8 *)&state, 2); - } else if (battery->id == 0) - battery->present = 1; - - if (result || !battery->present) - return result; + } else { + if (battery->id == 0) { + battery->present = 1; + } else { + if (!battery->present) + return 0; + } + } if (saved_present != battery->present) { battery->update_time = 0;