Skip to content

Commit ca8283d

Browse files
committed
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>
1 parent 4a9af6c commit ca8283d

1 file changed

Lines changed: 28 additions & 11 deletions

File tree

drivers/acpi/ec.c

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ struct acpi_ec_query {
170170
};
171171

172172
static int acpi_ec_query(struct acpi_ec *ec, u8 *data);
173-
static void advance_transaction(struct acpi_ec *ec, bool interrupt);
173+
static bool advance_transaction(struct acpi_ec *ec, bool interrupt);
174174
static void acpi_ec_event_handler(struct work_struct *work);
175175
static void acpi_ec_event_processor(struct work_struct *work);
176176

@@ -444,18 +444,25 @@ static bool acpi_ec_submit_flushable_request(struct acpi_ec *ec)
444444
return true;
445445
}
446446

447-
static void acpi_ec_submit_query(struct acpi_ec *ec)
447+
static bool acpi_ec_submit_query(struct acpi_ec *ec)
448448
{
449449
acpi_ec_mask_events(ec);
450450
if (!acpi_ec_event_enabled(ec))
451-
return;
451+
return false;
452+
452453
if (!test_and_set_bit(EC_FLAGS_QUERY_PENDING, &ec->flags)) {
453454
ec_dbg_evt("Command(%s) submitted/blocked",
454455
acpi_ec_cmd_string(ACPI_EC_COMMAND_QUERY));
455456
ec->nr_pending_queries++;
456457
ec->events_in_progress++;
457-
queue_work(ec_wq, &ec->work);
458+
return queue_work(ec_wq, &ec->work);
458459
}
460+
461+
/*
462+
* The event handling work has not been completed yet, so it needs to be
463+
* flushed.
464+
*/
465+
return true;
459466
}
460467

461468
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
628635
acpi_ec_mask_events(ec);
629636
}
630637

631-
static void advance_transaction(struct acpi_ec *ec, bool interrupt)
638+
static bool advance_transaction(struct acpi_ec *ec, bool interrupt)
632639
{
633640
struct transaction *t = ec->curr;
634641
bool wakeup = false;
642+
bool ret = false;
635643
u8 status;
636644

637645
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)
698706

699707
out:
700708
if (status & ACPI_EC_FLAG_SCI)
701-
acpi_ec_submit_query(ec);
709+
ret = acpi_ec_submit_query(ec);
702710

703711
if (wakeup && interrupt)
704712
wake_up(&ec->wait);
713+
714+
return ret;
705715
}
706716

707717
static void start_transaction(struct acpi_ec *ec)
@@ -2038,8 +2048,7 @@ void acpi_ec_set_gpe_wake_mask(u8 action)
20382048

20392049
bool acpi_ec_dispatch_gpe(void)
20402050
{
2041-
bool work_in_progress;
2042-
u32 ret;
2051+
bool work_in_progress = false;
20432052

20442053
if (!first_ec)
20452054
return acpi_any_gpe_status_set(U32_MAX);
@@ -2055,9 +2064,17 @@ bool acpi_ec_dispatch_gpe(void)
20552064
* Dispatch the EC GPE in-band, but do not report wakeup in any case
20562065
* to allow the caller to process events properly after that.
20572066
*/
2058-
ret = acpi_dispatch_gpe(NULL, first_ec->gpe);
2059-
if (ret == ACPI_INTERRUPT_HANDLED)
2060-
pm_pr_dbg("ACPI EC GPE dispatched\n");
2067+
spin_lock_irq(&first_ec->lock);
2068+
2069+
if (acpi_ec_gpe_status_set(first_ec))
2070+
work_in_progress = advance_transaction(first_ec, false);
2071+
2072+
spin_unlock_irq(&first_ec->lock);
2073+
2074+
if (!work_in_progress)
2075+
return false;
2076+
2077+
pm_pr_dbg("ACPI EC GPE dispatched\n");
20612078

20622079
/* Drain EC work. */
20632080
do {

0 commit comments

Comments
 (0)