From patchwork Sat Feb 25 08:04:55 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13152039 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 646D6C7EE23 for ; Sat, 25 Feb 2023 08:05:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229616AbjBYIFu (ORCPT ); Sat, 25 Feb 2023 03:05:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51080 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229507AbjBYIFt (ORCPT ); Sat, 25 Feb 2023 03:05:49 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C26411ACC0; Sat, 25 Feb 2023 00:05:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1677312342; i=w_armin@gmx.de; bh=uNkbSijDFzzTJZKTSAPmytRUJkMoQgMb2ySqr5S1jhI=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=uZEt74xGMuUCKWJj/iMz0Wrx2MDgPmtseo+YcMojPM2+kdRMIGEvmNqQOOauBRBht co+a68jvm3+XdgK1kvPG3aUTtXRRGzDiRRCoy/QvBJ4mbyGQ5wQLp1B6v22ZpwpCz/ BQauuHeKgaaY4EA/vMotWxacyduwI1OUmTz6ChfsxlT74SjaBLvBt5o3aprsxkZUR+ Kkl0vcbfIlvg5u+MXvHn+k+15q0izf8JKTTaRit4+23aQ1xkT5x/yvJAIc5Puyap7U E6rdRI7e0Ikc0Va5YnGGAY/OALnAcAf8FzapbqKtr14JOe9AgEVD7qdrPm/Dk6KNOC Od7QW5/9cb8CQ== 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 1N2E1M-1oVWoN3iQA-013gER; Sat, 25 Feb 2023 09:05:41 +0100 From: Armin Wolf To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/4] ACPI: EC: Add query notifier support Date: Sat, 25 Feb 2023 09:04:55 +0100 Message-Id: <20230225080458.1342359-2-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230225080458.1342359-1-W_Armin@gmx.de> References: <20230225080458.1342359-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:2BYlHgFBzShqWAg74t5pHaYHaQpx5PKzRhy701iI8iKtxomCRRx W1jtqO3XCZmULQd7lfvCtxmjaZvka5ekz4VCvcs5S/YeplJGrAKkBwJYLltHMPZ5lP/R2V/ lkrp5qClZBp84P8Md6uiSBG9c/Lbx2BTCRuEyENn0Zd7THuXAH+d2OHTvBdYzTo+ectD/Lr aYp9whDx0zohibWZrzeHw== UI-OutboundReport: notjunk:1;M01:P0:PJWarSnfWNQ=;vZe/d137UfhVDAkQ4Jq26UOee2H mYYkU23xCD+FVRygQgUtkjjJZoTle8VZJ5jylJXXLK+A/kcHnUHf7B/uQkA+3YnzXQVRp0MLI 3agH0hlyHGq9iIvr1byXqfAdcGZ9buYmfpr1dK1K0LODACgpalBgji2L1rtMGflNaPKCFEepL ph/wPOUmwQ5V6/dpEtqzOGoydFFISf0o5Q2frQ/5ZlBRweRkhhGFDbP6qqFgXWC6bngrgwX1B cc3hwiMnR1YyZ3gNlFdbVdu8ziLktJ38oWGZDqF/lJVjNamBd20ePlRhzTOcE50L0MO8FSrlF 6vLP/GHhQb9HVDAQQ9j1MxDpOPrPk/EmG+RfhM/nIokN3gsWn7q2QPDRj1gSos6tTPN1/gC8R tEobkjAmMbNYgLsZMuU2S8tkpxWI0LBBxXPQydQbqSq2ANxaDb8swhVzyzjNdysM6m3LorJBH rMhe2MqQXD2XW0bhldobuJMS3INhNHsO2Mn4WbPcRTKmf/yuzQq137ta974vm8EI3Qu6o2S25 dM9P8XxBsQDFZaQDXKC+TbVOY+FYosNEC3tDOoh/ieSnDisa+F+Kasib4RsVLB8UkuboXq9SU HeVlW7WXsr2gEIGkU872YJ97L7zZqY9g0Rm9J8Tn0HJpQHb4wkENVyMgRVl/7WZihNl+x+cUe wUawiD4Z+796yaZhT6eYBe+0CBSfmCp3/TnfKSucCf3NTOZbTw+/k2fn7+oatylEqSXmapLih uYP9h1mr+Ku5kXXVjqCrlkPJj3vry+1RMNZLYWzPAA1hMaJsnHpAGFKg9nZSz3Y3kunc5f4m0 +dyALoh53ykYdAq/4e9IdFXYc+o2qUEHW1HMMi3fw94RY9ywmvRRB0WPBVttiH+2xe5XblfEK hT6Qk3iNXF+J3fMqticiiqtuQxRf6yzZ8nSz5rV5yOHu766Cl5RzlCKgmlDTznehpcliHht5S rxkaIkPu4oS6x6loaKgTaLgUakw= 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 08:04:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13152040 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 B5049C7EE23 for ; Sat, 25 Feb 2023 08:06:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229660AbjBYIGB (ORCPT ); Sat, 25 Feb 2023 03:06:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51092 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229618AbjBYIFu (ORCPT ); Sat, 25 Feb 2023 03:05:50 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.17.21]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6DAEC1ABC6; Sat, 25 Feb 2023 00:05:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1677312343; i=w_armin@gmx.de; bh=9r+ibg9eKkn9LExgzAaFAAWxIQXWfKeAQOOzxQ4bOco=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=ly+q8gux9JOzt7C5k/JdiChEfPehPk3l/8Dn9ABkzKzik4y1d+F2y5Vg4/jXxVQkt 12j5zMYwP/Y3N3Hz3y5OQDpUSvSf+i8wqPdYYBIZkTt65xUqa+rUvDTYMmKNx35l6e TFSn8FbFZPA+YVl4sdmHtXD8bHpsQOhPoAwsbsBrnnB5FRdJk5yVYbhUywjZVBvt/H DW0tBgU7qKDtVozJlrkkg3JpKcg3wqTsVugxs57Wym3/pZkf3EJlLvKjRvmvUPWPNo M2LIV7GByba9rn4cyPRET9OgEiWujbiNHW7ox//BLsvFCpfSs9YLabErbULvkNt79f Jv8Bfajl/jFKA== 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 1MTiTt-1p42DS1Ik9-00Tzdq; Sat, 25 Feb 2023 09:05:43 +0100 From: Armin Wolf To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/4] ACPI: sbshc: Use ec query notifier call chain Date: Sat, 25 Feb 2023 09:04:56 +0100 Message-Id: <20230225080458.1342359-3-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230225080458.1342359-1-W_Armin@gmx.de> References: <20230225080458.1342359-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:/QJk2JY0PRTEasYkeEf2FULmHkSNE/mMBkzvwv67jMa7uh3umD+ vny1ZCe4cN6VaarxatggGjrQt/0E/FRI5x8MHF1gjSZh3kpp0hjn76IExfr8fl7i0YSdJDK My1rKdEQZBDCtB0J2RqrgBj2SV3dLPvWisYQARgb/Cn4WADy667lvlo595QDilybk9g6cmb yDv8CYiDXdjCGybAaQXhA== UI-OutboundReport: notjunk:1;M01:P0:mXH8Cqbp6vg=;V0EDYoQ0YPtE4yjcApMHYeF5gtw W1OdvtsMDkAg9jpZhAOF2OFmxZUUGNJEhaN8ZrTuhRoGbL+VBgZBO58db2HKufZNOsP0trhCu hykS59a5Oq7ddYEc+nD0VajfHk3iK1CLlCd9T2hvM8wY1Bv0Y2oaXKHk30/t6bnydWbbnTBUN 0y+Pnmyw/LIDV4wu0+rjdbSvI8gqJlL52QjDlvFeJcynPEYOFqCrTmyoroaaec5Weq85bYGvR rdv7m8jVJLX+KQYBtosDj0rhyNnb+7FQEK/011QXgQbBDw1DVJVgtxArtfUBa7CKBiWAwaCLY RtIJ/Uqfhoj3YNXPvLzZhrh/66ud0wDgoZhvl3g33AEhwzI5ByucQQL0glzSsHTyqI6Aj6pMb vmQ6BF7DsOTgF3r5j/nM2QLCtPBEOIbczGLMSRnHy5dd2OZhEZcNeInM9iJD7lglf2NfBCnhA JC+0y/CZe5sfPi6pyoM5UUwsfPQDexn9MV+fzbp0oSRdF35VoJ8TpLCSWC+An2mHIOdTJn1qh rOqSTkou2O6DZKrnSek30Bv7tKjIir9uqLjkSIrZgqqUWSVfsU0HsnnzflH/SdA/LhqMp3mXb cAMtkUI3g7+/yZCNqI/zow5QQNbxHMa7MRVLW2GS/+6NQNP+j00gCpBXAFCzfllb732si9q+D 4Vw01MtYs1ppbAlbbXaXgF70oT9ubsbdqHVnrQvbDqViE1DUDsvLtXAhaG9bSxgr/scZs2vCo hYfZk+UskrBGmdszb/N3HIG1aZd7kl0LkTkDL084Z6N9GuFI06nEZI0ae31w8K8YeZuV4UMgh pvuWxP0T/eo9N1re4l/pmslgf/+BL3XUNzlsrhVr0mkdcBm/Z8Eqhc/24mPQUtRmo74UK7lL3 XJHffnJR3QC6pwFOfdtsMR150DltiT/lCu+Tqwo4srGn8lizEHxsDq1HN52gIoqD+7RRMDjTY zKZQqUIoo8+NravqPzMgYJ/qPMU= 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 08:04:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13152042 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 1CD7CC7EE30 for ; Sat, 25 Feb 2023 08:06:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229671AbjBYIGC (ORCPT ); Sat, 25 Feb 2023 03:06:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51102 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229620AbjBYIFv (ORCPT ); Sat, 25 Feb 2023 03:05:51 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.15.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3905F1ACC2; Sat, 25 Feb 2023 00:05:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1677312344; i=w_armin@gmx.de; bh=ARMhndNiVUL09RLJuOzxVFQztlSRTxeVHCef2qBjh7k=; h=X-UI-Sender-Class:From:To:Cc:Subject:Date:In-Reply-To:References; b=CeQzxpBOXS/xuEapDfaDuWvvS6qvXo1jFFIgxpEKXI5JgkAgPVgGU5Yo7Y3JPWP0o inHIZ6yZM2eWmsoIvi9CRK9TMUz8Qq9AAcXy2a5htdv39mgSkGqyFJnZKsstMuOPeh gbxfhpQ3hosTjhInA2lACmG25N9iRJmHjepIMjuZiRte3xn+jKdE4kbuhrsfYm9mdZ 1YKfqMdxTKIcVeF5HiJ3B6E/NwXXVHLoN/P5N4oH6Mt3d946kQKPamEH1iksV2f7Et 06sXbUeTmNNB5w35dPxquoP3t3gD8uHOz5ipQLziF15osdTEplGoPXA4kS+1HwPmzg s9z020V58kl+Q== 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 1Mn2aD-1op6xr26hr-00k57M; Sat, 25 Feb 2023 09:05:44 +0100 From: Armin Wolf To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] ACPI: EC: Make query handlers private Date: Sat, 25 Feb 2023 09:04:57 +0100 Message-Id: <20230225080458.1342359-4-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230225080458.1342359-1-W_Armin@gmx.de> References: <20230225080458.1342359-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:B6xNyHRHfUEAzQcQf9i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tLZqdvAELQ6Vep8eXKeEPalsu8/2vCVImwJaz6Fq266QB7amOvYreKOukK1eQOWXo8Bz Ew6QIomtN9h4Q5GunnZ2CucAj341TKzutpMFFHfX0IgIaVCKF6Us0ArkMHiFnmQvPJ/Prk3UZ N1cDEFUz9eDOnoIkwTIiwVxsx9c= 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..94391a62a44c 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) +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 08:04:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Armin Wolf X-Patchwork-Id: 13152041 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 2EB46C7EE31 for ; Sat, 25 Feb 2023 08:06:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229629AbjBYIGC (ORCPT ); Sat, 25 Feb 2023 03:06:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229642AbjBYIFx (ORCPT ); Sat, 25 Feb 2023 03:05:53 -0500 Received: from mout.gmx.net (mout.gmx.net [212.227.17.22]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 997011ACC8; Sat, 25 Feb 2023 00:05:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.de; s=s31663417; t=1677312346; 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=K99OKWKHOOzh05TDpZSxJE4GN6wiueUJLo6LO0haukLOys0FpZNus5BsgoIogxz/V k+NUWpPFENWVi5MNRNGIH0MqCmq++w9KTv1hPte4Tvnt6FfMfUXFsD0qXvUFxR+lAl VZlKp4Rq8plMnv4PyaSsvvv1Ct4ubVhBoenahAOfQyPrx3Cs0quL6TzRMBSRBcsLAW IkxCR9v6ubd6O1HtTzyk8zj4H8dmxIU+pozts1YYeWxLiJuMJEK0rYIcDeeFdy/I7B 8mvytGFZnplh9I+p9DRRIRdr7blAXGdpRK18+if/PbRJ+E1JGRFZJvAP3/UcAs7/bP usEcy5zKn+nEA== 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 1MIMbU-1pJmsX44gO-00ENWP; Sat, 25 Feb 2023 09:05:46 +0100 From: Armin Wolf To: rafael@kernel.org, lenb@kernel.org Cc: linux-acpi@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] ACPI: SBS: Fix handling of Smart Battery Selectors Date: Sat, 25 Feb 2023 09:04:58 +0100 Message-Id: <20230225080458.1342359-5-W_Armin@gmx.de> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230225080458.1342359-1-W_Armin@gmx.de> References: <20230225080458.1342359-1-W_Armin@gmx.de> MIME-Version: 1.0 X-Provags-ID: V03:K1:2Bj5TWsf+QBe1Q82Bfbxp7fvAa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h4+t05CqH83CK2KIObGgXRON/ZqhdVPHwdJyukKcgiGXO5RJp4yzVd0dDxXVbc/lF3QcS4 OaP+uQEegNhU46fEoU+nu8i4bDL7SRY1l8vRrTlIXgCoZJT9QTDuRDfbm3GFgAY6EgoNakzmL LcYgGNLeaHZA2Xj8FV5S6oFpwss= 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;