diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2021-11-23 19:37:39 +0100 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2021-12-01 20:17:32 +0100 |
commit | ca8283dcd933a2ca776fade77fb4527321521463 (patch) | |
tree | 33ce0de9ee41d357e5a43c907f43c7394ce1b8c8 /drivers/acpi | |
parent | ACPI: EC: Rework flushing of EC work while suspended to idle (diff) | |
download | linux-ca8283dcd933a2ca776fade77fb4527321521463.tar.xz linux-ca8283dcd933a2ca776fade77fb4527321521463.zip |
ACPI: EC: Call advance_transaction() from acpi_ec_dispatch_gpe()
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>
Diffstat (limited to 'drivers/acpi')
-rw-r--r-- | drivers/acpi/ec.c | 39 |
1 files changed, 28 insertions, 11 deletions
diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c index b9c44e6c5e40..bfc29cdfa5f0 100644 --- a/drivers/acpi/ec.c +++ b/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_request(struct acpi_ec *ec) 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(struct acpi_ec *ec, struct transaction *t 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 acpi_ec *ec, bool interrupt) 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 { |