From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Linux ACPI <linux-acpi@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>, Linux PM <linux-pm@vger.kernel.org>
Subject: [PATCH 02/10] ACPI: EC: Call advance_transaction() from acpi_ec_dispatch_gpe()
Date: Tue, 23 Nov 2021 19:37:39 +0100 [thread overview]
Message-ID: <4376198.LvFx2qVVIh@kreacher> (raw)
In-Reply-To: <11887969.O9o76ZdvQC@kreacher>
From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Calling acpi_dispatch_gpe() from acpi_ec_dispatch_gpe() is generally
problematic, because it may cause the spurious interrupt handling in
advance_transaction() to trigger in theory.
However, instead of calling acpi_dispatch_gpe() to dispatch the EC
GPE, acpi_ec_dispatch_gpe() can call advance_transaction() directly
on first_ec and it can pass 'false' as its second argument to indicate
calling it from process context.
Moreover, if advance_transaction() is modified to return a bool value
indicating whether or not the EC work needs to be flushed, it can be
used to avoid unnecessary EC work flushing in acpi_ec_dispatch_gpe(),
so change the code accordingly.
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
drivers/acpi/ec.c | 39 ++++++++++++++++++++++++++++-----------
1 file changed, 28 insertions(+), 11 deletions(-)
Index: linux-pm/drivers/acpi/ec.c
===================================================================
--- linux-pm.orig/drivers/acpi/ec.c
+++ linux-pm/drivers/acpi/ec.c
@@ -170,7 +170,7 @@ struct acpi_ec_query {
};
static int acpi_ec_query(struct acpi_ec *ec, u8 *data);
-static void advance_transaction(struct acpi_ec *ec, bool interrupt);
+static bool advance_transaction(struct acpi_ec *ec, bool interrupt);
static void acpi_ec_event_handler(struct work_struct *work);
static void acpi_ec_event_processor(struct work_struct *work);
@@ -444,18 +444,25 @@ static bool acpi_ec_submit_flushable_req
return true;
}
-static void acpi_ec_submit_query(struct acpi_ec *ec)
+static bool acpi_ec_submit_query(struct acpi_ec *ec)
{
acpi_ec_mask_events(ec);
if (!acpi_ec_event_enabled(ec))
- return;
+ return false;
+
if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) {
ec_dbg_evt("Command(%s) submitted/blocked",
acpi_ec_cmd_string(ACPI_EC_COMMAND_QUERY));
ec->nr_pending_queries++;
ec->events_in_progress++;
- queue_work(ec_wq, &ec->work);
+ return queue_work(ec_wq, &ec->work);
}
+
+ /*
+ * The event handling work has not been completed yet, so it needs to be
+ * flushed.
+ */
+ return true;
}
static void acpi_ec_complete_query(struct acpi_ec *ec)
@@ -628,10 +635,11 @@ static void acpi_ec_spurious_interrupt(s
acpi_ec_mask_events(ec);
}
-static void advance_transaction(struct acpi_ec *ec, bool interrupt)
+static bool advance_transaction(struct acpi_ec *ec, bool interrupt)
{
struct transaction *t = ec->curr;
bool wakeup = false;
+ bool ret = false;
u8 status;
ec_dbg_stm("%s (%d)", interrupt ? "IRQ" : "TASK", smp_processor_id());
@@ -698,10 +706,12 @@ static void advance_transaction(struct a
out:
if (status & ACPI_EC_FLAG_SCI)
- acpi_ec_submit_query(ec);
+ ret = acpi_ec_submit_query(ec);
if (wakeup && interrupt)
wake_up(&ec->wait);
+
+ return ret;
}
static void start_transaction(struct acpi_ec *ec)
@@ -2038,8 +2048,7 @@ void acpi_ec_set_gpe_wake_mask(u8 action
bool acpi_ec_dispatch_gpe(void)
{
- bool work_in_progress;
- u32 ret;
+ bool work_in_progress = false;
if (!first_ec)
return acpi_any_gpe_status_set(U32_MAX);
@@ -2055,9 +2064,17 @@ bool acpi_ec_dispatch_gpe(void)
* Dispatch the EC GPE in-band, but do not report wakeup in any case
* to allow the caller to process events properly after that.
*/
- ret = acpi_dispatch_gpe(NULL, first_ec->gpe);
- if (ret == ACPI_INTERRUPT_HANDLED)
- pm_pr_dbg("ACPI EC GPE dispatched\n");
+ spin_lock_irq(&first_ec->lock);
+
+ if (acpi_ec_gpe_status_set(first_ec))
+ work_in_progress = advance_transaction(first_ec, false);
+
+ spin_unlock_irq(&first_ec->lock);
+
+ if (!work_in_progress)
+ return false;
+
+ pm_pr_dbg("ACPI EC GPE dispatched\n");
/* Drain EC work. */
do {
next prev parent reply other threads:[~2021-11-23 18:49 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-23 18:35 [PATCH 00/10] ACPI: EC: Two fixes and cleanups Rafael J. Wysocki
2021-11-23 18:36 ` [PATCH 01/10] ACPI: EC: Rework flushing of EC work while suspended to idle Rafael J. Wysocki
2021-11-23 18:37 ` Rafael J. Wysocki [this message]
2021-11-23 18:38 ` [PATCH 03/10] ACPI: EC: Pass one argument to acpi_ec_query() Rafael J. Wysocki
2021-11-23 18:39 ` [PATCH 04/10] ACPI: EC: Fold acpi_ec_check_event() into acpi_ec_event_handler() Rafael J. Wysocki
2021-11-23 18:40 ` [PATCH 05/10] ACPI: EC: Rearrange the loop in acpi_ec_event_handler() Rafael J. Wysocki
2021-11-23 18:40 ` [PATCH 06/10] ACPI: EC: Simplify locking " Rafael J. Wysocki
2021-11-23 18:42 ` [PATCH 07/10] ACPI: EC: Rename three functions Rafael J. Wysocki
2021-11-23 18:43 ` [PATCH 08/10] ACPI: EC: Avoid queuing unnecessary work in acpi_ec_submit_event() Rafael J. Wysocki
2021-11-23 18:44 ` [PATCH 09/10] ACPI: EC: Make the event work state machine visible Rafael J. Wysocki
2021-11-23 18:46 ` [PATCH 10/10] ACPI: EC: Relocate acpi_ec_create_query() and drop acpi_ec_delete_query() Rafael J. Wysocki
2021-12-01 19:22 ` [PATCH 00/10] ACPI: EC: Two fixes and cleanups Rafael J. Wysocki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4376198.LvFx2qVVIh@kreacher \
--to=rjw@rjwysocki.net \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pm@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).