Skip to content

Commit ddfd9dc

Browse files
jwrdegoederafaeljw
authored andcommitted
ACPI: PM: Add acpi_[un]register_wakeup_handler()
Since commit fdde0ff ("ACPI: PM: s2idle: Prevent spurious SCIs from waking up the system") the SCI triggering without there being a wakeup cause recognized by the ACPI sleep code will no longer wakeup the system. This works as intended, but this is a problem for devices where the SCI is shared with another device which is also a wakeup source. In the past these, from the pov of the ACPI sleep code, spurious SCIs would still cause a wakeup so the wakeup from the device sharing the interrupt would actually wakeup the system. This now no longer works. This is a problem on e.g. Bay Trail-T and Cherry Trail devices where some peripherals (typically the XHCI controller) can signal a Power Management Event (PME) to the Power Management Controller (PMC) to wakeup the system, this uses the same interrupt as the SCI. These wakeups are handled through a special INT0002 ACPI device which checks for events in the GPE0a_STS for this and takes care of acking the PME so that the shared interrupt stops triggering. The change to the ACPI sleep code to ignore the spurious SCI, causes the system to no longer wakeup on these PME events. To make things worse this means that the INT0002 device driver interrupt handler will no longer run, causing the PME to not get cleared and resulting in the system hanging. Trying to wakeup the system after such a PME through e.g. the power button no longer works. Add an acpi_register_wakeup_handler() function which registers a handler to be called from acpi_s2idle_wake() and when the handler returns true, return true from acpi_s2idle_wake(). The INT0002 driver will use this mechanism to check the GPE0a_STS register from acpi_s2idle_wake() and to tell the system to wakeup if a PME is signaled in the register. Fixes: fdde0ff ("ACPI: PM: s2idle: Prevent spurious SCIs from waking up the system") Cc: 5.4+ <[email protected]> # 5.4+ Signed-off-by: Hans de Goede <[email protected]> Signed-off-by: Rafael J. Wysocki <[email protected]>
1 parent 2ce94bc commit ddfd9dc

File tree

4 files changed

+91
-0
lines changed

4 files changed

+91
-0
lines changed

drivers/acpi/sleep.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,6 +1009,10 @@ static bool acpi_s2idle_wake(void)
10091009
if (acpi_any_fixed_event_status_set())
10101010
return true;
10111011

1012+
/* Check wakeups from drivers sharing the SCI. */
1013+
if (acpi_check_wakeup_handlers())
1014+
return true;
1015+
10121016
/*
10131017
* If the status bit is set for any enabled GPE other than the
10141018
* EC one, the wakeup is regarded as a genuine one.

drivers/acpi/sleep.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
extern void acpi_enable_wakeup_devices(u8 sleep_state);
44
extern void acpi_disable_wakeup_devices(u8 sleep_state);
5+
extern bool acpi_check_wakeup_handlers(void);
56

67
extern struct list_head acpi_wakeup_device_list;
78
extern struct mutex acpi_device_lock;

drivers/acpi/wakeup.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
#include "internal.h"
1313
#include "sleep.h"
1414

15+
struct acpi_wakeup_handler {
16+
struct list_head list_node;
17+
bool (*wakeup)(void *context);
18+
void *context;
19+
};
20+
21+
static LIST_HEAD(acpi_wakeup_handler_head);
22+
static DEFINE_MUTEX(acpi_wakeup_handler_mutex);
23+
1524
/*
1625
* We didn't lock acpi_device_lock in the file, because it invokes oops in
1726
* suspend/resume and isn't really required as this is called in S-state. At
@@ -90,3 +99,75 @@ int __init acpi_wakeup_device_init(void)
9099
mutex_unlock(&acpi_device_lock);
91100
return 0;
92101
}
102+
103+
/**
104+
* acpi_register_wakeup_handler - Register wakeup handler
105+
* @wake_irq: The IRQ through which the device may receive wakeups
106+
* @wakeup: Wakeup-handler to call when the SCI has triggered a wakeup
107+
* @context: Context to pass to the handler when calling it
108+
*
109+
* Drivers which may share an IRQ with the SCI can use this to register
110+
* a handler which returns true when the device they are managing wants
111+
* to trigger a wakeup.
112+
*/
113+
int acpi_register_wakeup_handler(int wake_irq, bool (*wakeup)(void *context),
114+
void *context)
115+
{
116+
struct acpi_wakeup_handler *handler;
117+
118+
/*
119+
* If the device is not sharing its IRQ with the SCI, there is no
120+
* need to register the handler.
121+
*/
122+
if (!acpi_sci_irq_valid() || wake_irq != acpi_sci_irq)
123+
return 0;
124+
125+
handler = kmalloc(sizeof(*handler), GFP_KERNEL);
126+
if (!handler)
127+
return -ENOMEM;
128+
129+
handler->wakeup = wakeup;
130+
handler->context = context;
131+
132+
mutex_lock(&acpi_wakeup_handler_mutex);
133+
list_add(&handler->list_node, &acpi_wakeup_handler_head);
134+
mutex_unlock(&acpi_wakeup_handler_mutex);
135+
136+
return 0;
137+
}
138+
EXPORT_SYMBOL_GPL(acpi_register_wakeup_handler);
139+
140+
/**
141+
* acpi_unregister_wakeup_handler - Unregister wakeup handler
142+
* @wakeup: Wakeup-handler passed to acpi_register_wakeup_handler()
143+
* @context: Context passed to acpi_register_wakeup_handler()
144+
*/
145+
void acpi_unregister_wakeup_handler(bool (*wakeup)(void *context),
146+
void *context)
147+
{
148+
struct acpi_wakeup_handler *handler;
149+
150+
mutex_lock(&acpi_wakeup_handler_mutex);
151+
list_for_each_entry(handler, &acpi_wakeup_handler_head, list_node) {
152+
if (handler->wakeup == wakeup && handler->context == context) {
153+
list_del(&handler->list_node);
154+
kfree(handler);
155+
break;
156+
}
157+
}
158+
mutex_unlock(&acpi_wakeup_handler_mutex);
159+
}
160+
EXPORT_SYMBOL_GPL(acpi_unregister_wakeup_handler);
161+
162+
bool acpi_check_wakeup_handlers(void)
163+
{
164+
struct acpi_wakeup_handler *handler;
165+
166+
/* No need to lock, nothing else is running when we're called. */
167+
list_for_each_entry(handler, &acpi_wakeup_handler_head, list_node) {
168+
if (handler->wakeup(handler->context))
169+
return true;
170+
}
171+
172+
return false;
173+
}

include/linux/acpi.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -488,6 +488,11 @@ void __init acpi_nvs_nosave_s3(void);
488488
void __init acpi_sleep_no_blacklist(void);
489489
#endif /* CONFIG_PM_SLEEP */
490490

491+
int acpi_register_wakeup_handler(
492+
int wake_irq, bool (*wakeup)(void *context), void *context);
493+
void acpi_unregister_wakeup_handler(
494+
bool (*wakeup)(void *context), void *context);
495+
491496
struct acpi_osc_context {
492497
char *uuid_str; /* UUID string */
493498
int rev;

0 commit comments

Comments
 (0)