Commit ca8283dc authored by Rafael J. Wysocki's avatar Rafael J. Wysocki

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: default avatarRafael J. Wysocki <rafael.j.wysocki@intel.com>
parent 4a9af6ca
...@@ -170,7 +170,7 @@ struct acpi_ec_query { ...@@ -170,7 +170,7 @@ struct acpi_ec_query {
}; };
static int acpi_ec_query(struct acpi_ec *ec, u8 *data); 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_handler(struct work_struct *work);
static void acpi_ec_event_processor(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) ...@@ -444,18 +444,25 @@ static bool acpi_ec_submit_flushable_request(struct acpi_ec *ec)
return true; 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); acpi_ec_mask_events(ec);
if (!acpi_ec_event_enabled(ec)) if (!acpi_ec_event_enabled(ec))
return; return false;
if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) { if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) {
ec_dbg_evt("Command(%s) submitted/blocked", ec_dbg_evt("Command(%s) submitted/blocked",
acpi_ec_cmd_string(ACPI_EC_COMMAND_QUERY)); acpi_ec_cmd_string(ACPI_EC_COMMAND_QUERY));
ec->nr_pending_queries++; ec->nr_pending_queries++;
ec->events_in_progress++; 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) 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 ...@@ -628,10 +635,11 @@ static void acpi_ec_spurious_interrupt(struct acpi_ec *ec, struct transaction *t
acpi_ec_mask_events(ec); 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; struct transaction *t = ec->curr;
bool wakeup = false; bool wakeup = false;
bool ret = false;
u8 status; u8 status;
ec_dbg_stm("%s (%d)", interrupt ? "IRQ" : "TASK", smp_processor_id()); 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) ...@@ -698,10 +706,12 @@ static void advance_transaction(struct acpi_ec *ec, bool interrupt)
out: out:
if (status & ACPI_EC_FLAG_SCI) if (status & ACPI_EC_FLAG_SCI)
acpi_ec_submit_query(ec); ret = acpi_ec_submit_query(ec);
if (wakeup && interrupt) if (wakeup && interrupt)
wake_up(&ec->wait); wake_up(&ec->wait);
return ret;
} }
static void start_transaction(struct acpi_ec *ec) static void start_transaction(struct acpi_ec *ec)
...@@ -2038,8 +2048,7 @@ void acpi_ec_set_gpe_wake_mask(u8 action) ...@@ -2038,8 +2048,7 @@ void acpi_ec_set_gpe_wake_mask(u8 action)
bool acpi_ec_dispatch_gpe(void) bool acpi_ec_dispatch_gpe(void)
{ {
bool work_in_progress; bool work_in_progress = false;
u32 ret;
if (!first_ec) if (!first_ec)
return acpi_any_gpe_status_set(U32_MAX); return acpi_any_gpe_status_set(U32_MAX);
...@@ -2055,8 +2064,16 @@ bool acpi_ec_dispatch_gpe(void) ...@@ -2055,8 +2064,16 @@ bool acpi_ec_dispatch_gpe(void)
* Dispatch the EC GPE in-band, but do not report wakeup in any case * Dispatch the EC GPE in-band, but do not report wakeup in any case
* to allow the caller to process events properly after that. * to allow the caller to process events properly after that.
*/ */
ret = acpi_dispatch_gpe(NULL, first_ec->gpe); spin_lock_irq(&first_ec->lock);
if (ret == ACPI_INTERRUPT_HANDLED)
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"); pm_pr_dbg("ACPI EC GPE dispatched\n");
/* Drain EC work. */ /* Drain EC work. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment