ACPI / PM: Fix incorrect wakeup irq setting before suspend-to-idle
PATCH v2 1/1 ACPI / PM: Fix incorrect wakeup irq setting before suspend-to-idle
For ACPI compatible system, SCI(ACPI System Control Interrupt) is used to wake system up from suspend-to-idle. Once CPU is woken up by SCI, interrupt handler will firstly checks if current interrupt is legal to wake up the whole system, thus irq_pm_check_wakeup is invoked to validate the irq number. However, before suspend-to-idle, acpi_gbl_FADT.sci_interrupt is marked rather than actual irq number in acpi_freeze_prepare, this might lead to unable to wake up the system.
This patch fixes this problem by marking the irq number return by acpi_gsi_to_irq as IRQD_WAKEUP_STATE, rather than marking the acpi_gbl_FADT.sci_interrupt. Meanwhile this patch fixes the same problems inside acpi_os_remove_interrupt_handler and acpi_os_wait_events_complete respectively.
---
v2:
- 1.Define a global acpi_inuse_irq variable, store irq in it and access it directly from acpi_freeze_prepare(), and it doesn't have to depend on CONFIG_SUSPEND as it is just the IRQ number actually used by ACPI.
2.Also fix the same problems inside acpi_os_remove_interrupt_handler, acpi_os_wait_events_complete.
--- drivers/acpi/osl.c | 9 ++++++++- drivers/acpi/sleep.c | 10 ++++++++-- include/linux/acpi.h | 3 +++ 3 files changed, 19 insertions(+), 3 deletions(-)
drivers/acpi/osl.c +8 -1
@@ -81,6 +81,7 @@ static struct workqueue_struct *kacpid_wq;static struct workqueue_struct *kacpi_notify_wq;static struct workqueue_struct *kacpi_hotplug_wq;static bool acpi_os_initialized; +unsigned int acpi_inuse_irq =INVALID_ACPI_IRQ ;/* * This list of permanent mappings is for memory that may be accessed from
@@ -856,6 +857,7 @@ acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler, acpi_irq_handler =NULL ;return AE_NOT_ACQUIRED ; } + acpi_inuse_irq = irq;return AE_OK ; }
@@ -865,6 +867,9 @@ acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)if (irq != acpi_gbl_FADT.sci_interrupt)return AE_BAD_PARAMETER ; +if (!IS_INVALID_ACPI_IRQ (acpi_inuse_irq)) + irq = acpi_inuse_irq; +free_irq (irq, acpi_irq); acpi_irq_handler =NULL ;
@@ -1176,12 +1181,14 @@ EXPORT_SYMBOL(acpi_os_execute);void acpi_os_wait_events_complete (void ) { +unsigned int irq =IS_INVALID_ACPI_IRQ (acpi_inuse_irq) ? + acpi_gbl_FADT.sci_interrupt : acpi_inuse_irq;/* * Make sure the GPE handler or the fixed event handler is not used * on another CPU after removal. */ if (acpi_irq_handler) -synchronize_hardirq (acpi_gbl_FADT.sci_interrupt); +synchronize_hardirq (irq);flush_workqueue (kacpid_wq);flush_workqueue (kacpi_notify_wq); }
drivers/acpi/sleep.c +8 -2
@@ -629,17 +629,23 @@ static int acpi_freeze_begin(void)static int acpi_freeze_prepare (void ) { +unsigned int irq =IS_INVALID_ACPI_IRQ (acpi_inuse_irq) ? + acpi_gbl_FADT.sci_interrupt : acpi_inuse_irq; +acpi_enable_wakeup_devices (ACPI_STATE_S0 );acpi_enable_all_wakeup_gpes ();acpi_os_wait_events_complete (); -enable_irq_wake (acpi_gbl_FADT.sci_interrupt); +enable_irq_wake (irq);return 0 ; }static void acpi_freeze_restore (void ) { +unsigned int irq =IS_INVALID_ACPI_IRQ (acpi_inuse_irq) ? + acpi_gbl_FADT.sci_interrupt : acpi_inuse_irq; +acpi_disable_wakeup_devices (ACPI_STATE_S0 ); -disable_irq_wake (acpi_gbl_FADT.sci_interrupt); +disable_irq_wake (irq);acpi_enable_all_runtime_gpes (); }
include/linux/acpi.h +3 -0
@@ -193,6 +193,9 @@ int acpi_ioapic_registered(acpi_handle handle, u32 gsi_base);void acpi_irq_stats_init (void );extern u32 acpi_irq_handled;extern u32 acpi_irq_not_handled; +extern unsigned int acpi_inuse_irq; +#define INVALID_ACPI_IRQ ((unsigned)-1) +#define IS_INVALID_ACPI_IRQ (x) unlikely((x) == INVALID_ACPI_IRQ)extern int sbf_port;extern unsigned long acpi_realmode_flags;
Signature · 1 line
1.8.4.2
Quoted 36 lines · Chen Yu
For ACPI compatible system, SCI(ACPI System Control Interrupt) is used to wake system up from suspend-to-idle. Once CPU is woken up by SCI, interrupt handler will firstly checks if current interrupt is legal to wake up the whole system, thus
irq_pm_check_wakeupis invoked to validate the irq number. However, before suspend-to-idle, acpi_gbl_FADT.sci_interrupt is marked rather than actual irq number inacpi_freeze_prepare, this might lead to unable to wake up the system.This patch fixes this problem by marking the irq number return by
acpi_gsi_to_irqasIRQD_WAKEUP_STATE, rather than marking the acpi_gbl_FADT.sci_interrupt. Meanwhile this patch fixes the same problems insideacpi_os_remove_interrupt_handlerandacpi_os_wait_events_completerespectively.Signed-off-by Chen Yu <[email protected]>---
v2:
- 1.Define a globalacpi_inuse_irqvariable, store irq in it and access it directly fromacpi_freeze_prepare(), and it doesn't have to depend onCONFIG_SUSPENDas it is just the IRQ number actually used by ACPI.
2.Also fix the same problems insideacpi_os_remove_interrupt_handler,acpi_os_wait_events_complete.--- drivers/acpi/osl.c | 9 ++++++++- drivers/acpi/sleep.c | 10 ++++++++-- include/linux/acpi.h | 3 +++ 3 files changed, 19 insertions(+), 3 deletions(-)drivers/acpi/osl.c +0
-0
drivers/acpi/osl.c static struct workqueue_struct *kacpid_wq; · line 84
Quoted 4 lines
drivers/acpi/osl.c +1
-0@@ -81,6 +81,7 @@ static struct workqueue_struct *kacpid_wq;static struct workqueue_struct *kacpi_notify_wq;static struct workqueue_struct *kacpi_hotplug_wq;static bool acpi_os_initialized; +unsigned int acpi_inuse_irq =INVALID_ACPI_IRQ ;
What about calling it acpi_sci_irq instead?
Quoted 12 lines
drivers/acpi/osl.c +1
-0/* * This list of permanent mappings is for memory that may be accessed from @@ -856,6 +857,7 @@ acpi_os_install_interrupt_handler(u32 gsi, acpi_osd_handler handler, acpi_irq_handler =NULL ;return AE_NOT_ACQUIRED ; } + acpi_inuse_irq = irq;return AE_OK ; }
drivers/acpi/osl.c acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler) · line 871
Quoted 5 lines
drivers/acpi/osl.c +2
-0@@ -865,6 +867,9 @@ acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)if (irq != acpi_gbl_FADT.sci_interrupt)return AE_BAD_PARAMETER ; +if (!IS_INVALID_ACPI_IRQ (acpi_inuse_irq)) + irq = acpi_inuse_irq;
I'd think that we should return from here if acpi_inuse_irq is invalid?
It surely can't be invalid if acpi_os_install_interrupt_handler() has succeeded, right?
drivers/acpi/osl.c EXPORT_SYMBOL(acpi_os_execute); · line 1185
Quoted 10 lines
drivers/acpi/osl.c +3
-0+free_irq (irq, acpi_irq); acpi_irq_handler =NULL ;@@ -1176,12 +1181,14 @@ EXPORT_SYMBOL(acpi_os_execute);void acpi_os_wait_events_complete (void ) { +unsigned int irq =IS_INVALID_ACPI_IRQ (acpi_inuse_irq) ? + acpi_gbl_FADT.sci_interrupt : acpi_inuse_irq;
That, again. If acpi_inuse_irq is invalid, acpi_os_install_interrupt_handler() has failed, so we have nothing to synchronize here, or am I missing anything?
Quoted 15 lines
drivers/acpi/osl.c +1
-1/* * Make sure the GPE handler or the fixed event handler is not used * on another CPU after removal. */ if (acpi_irq_handler) -synchronize_hardirq (acpi_gbl_FADT.sci_interrupt); +synchronize_hardirq (irq);flush_workqueue (kacpid_wq);flush_workqueue (kacpi_notify_wq); }drivers/acpi/sleep.c +0
-0
drivers/acpi/sleep.c static int acpi_freeze_begin(void) · line 633
Quoted 5 lines
drivers/acpi/sleep.c +2
-0@@ -629,17 +629,23 @@ static int acpi_freeze_begin(void)static int acpi_freeze_prepare (void ) { +unsigned int irq =IS_INVALID_ACPI_IRQ (acpi_inuse_irq) ? + acpi_gbl_FADT.sci_interrupt : acpi_inuse_irq;
Same comment as above.
Plus, you seem to be duplicating code from acpi_os_wait_events_complete() here, so what about putting it into a separate routine (maybe static inline)?
Quoted 4 lines
drivers/acpi/sleep.c +1
-0+acpi_enable_wakeup_devices (ACPI_STATE_S0 );acpi_enable_all_wakeup_gpes ();acpi_os_wait_events_complete ();
drivers/acpi/sleep.c static int acpi_freeze_begin(void) · line 646
Quoted 10 lines
drivers/acpi/sleep.c +4
-1-enable_irq_wake (acpi_gbl_FADT.sci_interrupt); +enable_irq_wake (irq);return 0 ; }static void acpi_freeze_restore (void ) { +unsigned int irq =IS_INVALID_ACPI_IRQ (acpi_inuse_irq) ? + acpi_gbl_FADT.sci_interrupt : acpi_inuse_irq; +
Ditto.
Quoted 11 lines
drivers/acpi/sleep.c +1
-1acpi_disable_wakeup_devices (ACPI_STATE_S0 ); -disable_irq_wake (acpi_gbl_FADT.sci_interrupt); +disable_irq_wake (irq);acpi_enable_all_runtime_gpes (); }include/linux/acpi.h +0
-0
include/linux/acpi.h int acpi_ioapic_registered(acpi_handle handle, u32 gsi_base); · line 201
Quoted 9 lines
include/linux/acpi.h +3
-0@@ -193,6 +193,9 @@ int acpi_ioapic_registered(acpi_handle handle, u32 gsi_base);void acpi_irq_stats_init (void );extern u32 acpi_irq_handled;extern u32 acpi_irq_not_handled; +extern unsigned int acpi_inuse_irq; +#define INVALID_ACPI_IRQ ((unsigned)-1) +#define IS_INVALID_ACPI_IRQ (x) unlikely((x) == INVALID_ACPI_IRQ)extern int sbf_port;extern unsigned long acpi_realmode_flags;
Thanks,
Rafael
Hi, Rafael
Sorry for my late response, just came back from home:)
Quoted 11 lines
-----Original Message-----
From: [email protected] [mailto:linux-pm- [email protected]] On Behalf Of Rafael J. Wysocki
Sent: Thursday, October 01, 2015 9:11 AM
To: Chen, Yu C
Cc: [email protected]; Zhang, Rui; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH] [v2] ACPI / PM: Fix incorrect wakeup irq setting before suspend-to-idleOn Sunday, September 27, 2015 09:23:10 AM Chen Yu wrote:
Quoted 11 lines
Quoted 8 lines
drivers/acpi/osl.c index renamed from drivers/acpi/osl.c +0
-0739a4a6..97507fc 100644
drivers/acpi/osl.c +0
-0@@ -81,6 +81,7 @@ static struct workqueue_struct *kacpid_wq; staticstruct
workqueue_struct*kacpi_notify_wq; static structworkqueue_struct*kacpi_hotplug_wq; static boolacpi_os_initialized; +unsigned intacpi_inuse_irq=INVALID_ACPI_IRQ;What about calling it
acpi_sci_irqinstead?
OK.
Quoted 5 lines
drivers/acpi/osl.c acpi_status
Quoted 1 line
drivers/acpi/osl.c +0
-0@@ -865,6 +867,9 @@ acpi_status
acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler)Quoted 3 lines
drivers/acpi/osl.c +0
-0if (irq != acpi_gbl_FADT.sci_interrupt)return AE_BAD_PARAMETER ;
Quoted 8 lines
drivers/acpi/osl.c acpi_status acpi_os_remove_interrupt_handler(u32 irq, acpi_osd_handler handler) · line 871
Quoted 2 lines
drivers/acpi/osl.c +2
-0+if (!IS_INVALID_ACPI_IRQ (acpi_inuse_irq)) + irq = acpi_inuse_irq;I'd think that we should return from here if
acpi_inuse_irqis invalid?It surely can't be invalid if
acpi_os_install_interrupt_handler()has succeeded, right?
Yes, there is no need to remove the handler if it is not registered, will rewite it.
Quoted 6 lines
Quoted 6 lines
drivers/acpi/osl.c +1
-0+free_irq (irq, acpi_irq); acpi_irq_handler =NULL ;@@ -1176,12 +1181,14 @@ EXPORT_SYMBOL(acpi_os_execute);
Quoted 8 lines
drivers/acpi/osl.c EXPORT_SYMBOL(acpi_os_execute); · line 1185
Quoted 4 lines
drivers/acpi/osl.c +2
-0void acpi_os_wait_events_complete (void ) { +unsigned int irq =IS_INVALID_ACPI_IRQ (acpi_inuse_irq) ? + acpi_gbl_FADT.sci_interrupt : acpi_inuse_irq;That, again. If
acpi_inuse_irqis invalid,acpi_os_install_interrupt_handler()has failed, so we have nothing to synchronize here, or am I missing anything?
Right, will optimize this.
Quoted 10 lines
drivers/acpi/osl.c EXPORT_SYMBOL(acpi_os_execute); · line 1189
Quoted 4 lines
drivers/acpi/osl.c +2
-0static int acpi_freeze_prepare (void ) { +unsigned int irq =IS_INVALID_ACPI_IRQ (acpi_inuse_irq) ? + acpi_gbl_FADT.sci_interrupt : acpi_inuse_irq;Same comment as above.
Plus, you seem to be duplicating code from
acpi_os_wait_events_complete()here, so what about putting it into a separate routine (maybe static inline)?
I've sent out another version 3 patch, which simplified this logic that, the code flow will firstly check if the acpi irq is registered, If not, we simply bypass the code. So the duplicating code would become one line:
" if (!IS_INVALID_ACPI_IRQ(acpi_sci_irq))"
v3:
- 1.Rename acpi_inuse_irq to acpi_sci_irq for better understanding.
2.If the irq handler is not registered, skip the synchronize_hardirq
in acpi_os_wait_events_complete and return immediately in acpi_os_remove_interrupt_handler.
3.For acpi_freeze_prepare and acpi_freeze_restore, if the acpi irq
handler is not properly registered, we do not leverage acpi irq to wake up the system, but expect other peripherals(such as PCI devices and USB devices)to invoke enable_irq_wake for us.
Quoted 7 lines
Thanks,
Rafael--
To unsubscribe from this list: send the line "unsubscribe linux-pm" in the body of a message to [email protected] More majordomo info at
http://vger.kernel.org/majordomo-info.html