ACPI: Add stubs for wakeup handler functions
Subsystems (4)
PATCH v3 1/2 ACPI: Add stubs for wakeup handler functions
commit ddfd9dcf270c ("ACPI: PM: Add acpi_[un]register_wakeup_handler()") added new functions for drivers to use during the s2idle wakeup path, but didn't add stubs for when CONFIG_ACPI wasn't set.
Add those stubs in for other drivers to be able to use.
--- include/linux/acpi.h | 8 ++++++++ 1 file changed, 8 insertions(+)
include/linux/acpi.h +8 -0
@@ -976,6 +976,14 @@ static inline int acpi_get_local_address(acpi_handle handle, u32 *addr) return -ENODEV; } +static inline int acpi_register_wakeup_handler ( +int wake_irq,bool (*wakeup)(void *context),void *context) +{ +return -EINVAL ; +} +static inline void acpi_unregister_wakeup_handler ( +bool (*wakeup)(void *context),void *context) { } +#endif /* !CONFIG_ACPI */ #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
Signature · 1 line
2.25.1
PATCH v3 2/2 pinctrl: amd: Fix wakeups when IRQ is shared with SCI
On some Lenovo AMD Gen2 platforms the IRQ for the SCI and pinctrl drivers are shared. Due to how the s2idle loop handling works, this case needs an extra explicit check whether the interrupt was caused by SCI or by the GPIO controller.
To fix this rework the existing IRQ handler function to function as a checker and an IRQ handler depending on the calling arguments.
---
Note:
This is *possibly* a fix from fdde0ff8590b, 56b991849009 or other changes in the acpi_s2idle_wake handling, but AMD didn't support s2idle across the kernel widely until 5.14 or later. This is the reason for lack of a fixes tag.
Changes from v2->v3:
* Add new precursor patch for fixing missing ACPI function stubs
* Add __maybe_unused for unused function when set with COMPILE_TEST
Changes from v1->v2:
* drop Kconfig changes to drop COMPILE_TEST, instead #ifdef CONFIG_ACPI
* fix a logic error during wakeup
* Use IRQ_RETVAL()
drivers/pinctrl/pinctrl-amd.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)
drivers/pinctrl/pinctrl-amd.c +24 -3
@@ -598,16 +598,16 @@ static struct irq_chip amd_gpio_irqchip = {#define PIN_IRQ_PENDING (BIT(INTERRUPT_STS_OFF) | BIT(WAKE_STS_OFF)) -static irqreturn_t amd_gpio_irq_handler (int irq,void *dev_id) +static bool _amd_gpio_irq_handler (int irq,void *dev_id) {struct amd_gpio *gpio_dev = dev_id;struct gpio_chip *gc = &gpio_dev->gc; -irqreturn_t ret =IRQ_NONE ;unsigned int i, irqnr;unsigned long flags;u32 __iomem *regs;u32 regval;u64 status, mask; +bool ret = false;/* Read the wake status */ raw_spin_lock_irqsave (&gpio_dev->lock, flags);
@@ -627,6 +627,12 @@ static irqreturn_t amd_gpio_irq_handler(int irq, void *dev_id)/* Each status bit covers four pins */ for (i =0 ; i <4 ; i++) { regval =readl (regs + i); +/* called from resume context on a shared IRQ, just +* checking wake source. +*/ +if (irq <0 && (regval &BIT (WAKE_STS_OFF ))) +return true; +if (!(regval &PIN_IRQ_PENDING ) || !(regval &BIT (INTERRUPT_MASK_OFF )))continue ;
@@ -652,9 +658,12 @@ static irqreturn_t amd_gpio_irq_handler(int irq, void *dev_id) }writel (regval, regs + i);raw_spin_unlock_irqrestore (&gpio_dev->lock, flags); - ret =IRQ_HANDLED ; + ret = true; } } +/* called from resume context on shared IRQ but didn't cause wake */ +if (irq <0 ) +return false;/* Signal EOI to the GPIO unit */ raw_spin_lock_irqsave (&gpio_dev->lock, flags);
@@ -666,6 +675,16 @@ static irqreturn_t amd_gpio_irq_handler(int irq, void *dev_id)return ret; } +static irqreturn_t amd_gpio_irq_handler (int irq,void *dev_id) +{ +return IRQ_RETVAL (_amd_gpio_irq_handler (irq, dev_id)); +} + +static bool __maybe_unused amd_gpio_check_wake (void *dev_id) +{ +return _amd_gpio_irq_handler (-1 , dev_id); +} +static int amd_get_groups_count (struct pinctrl_dev *pctldev) {struct amd_gpio *gpio_dev =pinctrl_dev_get_drvdata (pctldev);
@@ -1004,6 +1023,7 @@ static int amd_gpio_probe(struct platform_device *pdev) goto out2;platform_set_drvdata (pdev, gpio_dev); +acpi_register_wakeup_handler (gpio_dev->irq, amd_gpio_check_wake, gpio_dev);dev_dbg (&pdev->dev,"amd gpio driver loaded\n" );return ret;
@@ -1021,6 +1041,7 @@ static int amd_gpio_remove(struct platform_device *pdev) gpio_dev =platform_get_drvdata (pdev);gpiochip_remove (&gpio_dev->gc); +acpi_unregister_wakeup_handler (amd_gpio_check_wake, gpio_dev);return 0 ; }
Signature · 1 line
2.25.1
Re: [PATCH v3 2/2] pinctrl: amd: Fix wakeups when IRQ is shared with SCI
Quoted 37 lines · Mario Limonciello
On some Lenovo AMD Gen2 platforms the IRQ for the SCI and pinctrl drivers are shared. Due to how the s2idle loop handling works, this case needs an extra explicit check whether the interrupt was caused by SCI or by the GPIO controller.
To fix this rework the existing IRQ handler function to function as a checker and an IRQ handler depending on the calling arguments.
Reported-by Joerie de Gram <[email protected]>Signed-off-by Mario Limonciello <[email protected]>---
Note:
This is *possibly* a fix fromfdde0ff8590b,56b991849009or other changes in theacpi_s2idle_wakehandling, but AMD didn't support s2idle across the kernel widely until 5.14 or later. This is the reason for lack of a fixes tag.
Changes fromv2->v3:
* Add new precursor patch for fixing missing ACPI function stubs
* Add__maybe_unusedfor unused function when set withCOMPILE_TEST
Changes fromv1->v2:
* dropKconfigchanges to dropCOMPILE_TEST, instead #ifdefCONFIG_ACPI
* fix a logic error during wakeup
* UseIRQ_RETVAL()drivers/pinctrl/pinctrl-amd.c | 27 ++++++++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-)drivers/pinctrl/pinctrl-amd.c +1
-1@@ -598,16 +598,16 @@ static struct irq_chip amd_gpio_irqchip = {#define PIN_IRQ_PENDING (BIT(INTERRUPT_STS_OFF) | BIT(WAKE_STS_OFF)) -static irqreturn_t amd_gpio_irq_handler (int irq,void *dev_id) +static bool _amd_gpio_irq_handler (int irq,void *dev_id)
drivers/pinctrl/pinctrl-amd.c static struct irq_chip amd_gpio_irqchip = { · line 610
Quoted 10 lines
drivers/pinctrl/pinctrl-amd.c +1
-1{struct amd_gpio *gpio_dev = dev_id;struct gpio_chip *gc = &gpio_dev->gc; -irqreturn_t ret =IRQ_NONE ;unsigned int i, irqnr;unsigned long flags;u32 __iomem *regs;u32 regval;u64 status, mask; +bool ret = false;
Just a minor nit. Can you do it reverse Xmas?
With that change
Thanks,
Basavaraj
Quoted 63 lines
drivers/pinctrl/pinctrl-amd.c +22
-1/* Read the wake status */ raw_spin_lock_irqsave (&gpio_dev->lock, flags);@@ -627,6 +627,12 @@ static irqreturn_t amd_gpio_irq_handler(int irq, void *dev_id)/* Each status bit covers four pins */ for (i =0 ; i <4 ; i++) { regval =readl (regs + i); +/* called from resume context on a shared IRQ, just +* checking wake source. +*/ +if (irq <0 && (regval &BIT (WAKE_STS_OFF ))) +return true; +if (!(regval &PIN_IRQ_PENDING ) || !(regval &BIT (INTERRUPT_MASK_OFF )))continue ;@@ -652,9 +658,12 @@ static irqreturn_t amd_gpio_irq_handler(int irq, void *dev_id) }writel (regval, regs + i);raw_spin_unlock_irqrestore (&gpio_dev->lock, flags); - ret =IRQ_HANDLED ; + ret = true; } } +/* called from resume context on shared IRQ but didn't cause wake */ +if (irq <0 ) +return false;/* Signal EOI to the GPIO unit */ raw_spin_lock_irqsave (&gpio_dev->lock, flags);@@ -666,6 +675,16 @@ static irqreturn_t amd_gpio_irq_handler(int irq, void *dev_id)return ret; } +static irqreturn_t amd_gpio_irq_handler (int irq,void *dev_id) +{ +return IRQ_RETVAL (_amd_gpio_irq_handler (irq, dev_id)); +} + +static bool __maybe_unused amd_gpio_check_wake (void *dev_id) +{ +return _amd_gpio_irq_handler (-1 , dev_id); +} +static int amd_get_groups_count (struct pinctrl_dev *pctldev) {struct amd_gpio *gpio_dev =pinctrl_dev_get_drvdata (pctldev);@@ -1004,6 +1023,7 @@ static int amd_gpio_probe(struct platform_device *pdev) goto out2;platform_set_drvdata (pdev, gpio_dev); +acpi_register_wakeup_handler (gpio_dev->irq, amd_gpio_check_wake, gpio_dev);dev_dbg (&pdev->dev,"amd gpio driver loaded\n" );return ret;@@ -1021,6 +1041,7 @@ static int amd_gpio_remove(struct platform_device *pdev) gpio_dev =platform_get_drvdata (pdev);gpiochip_remove (&gpio_dev->gc); +acpi_unregister_wakeup_handler (amd_gpio_check_wake, gpio_dev);return 0 ; }
Quoted 17 lines · Mario Limonciello
commit
ddfd9dcf270c("ACPI: PM: Add acpi_[un]register_wakeup_handler()") added new functions for drivers to use during the s2idle wakeup path, but didn't add stubs for whenCONFIG_ACPIwasn't set.Add those stubs in for other drivers to be able to use.
Fixes ddfd9dcf270c ("ACPI: PM: Add acpi_[un]register_wakeup_handler()")Signed-off-by Mario Limonciello <[email protected]>--- include/linux/acpi.h | 8 ++++++++ 1 file changed, 8 insertions(+)include/linux/acpi.h +0
-0
include/linux/acpi.h static inline int acpi_get_local_address(acpi_handle handle, u32 *addr) · line 983
Quoted 8 lines
include/linux/acpi.h +5
-0@@ -976,6 +976,14 @@ static inline int acpi_get_local_address(acpi_handle handle, u32 *addr)return -ENODEV ; } +static inline int acpi_register_wakeup_handler ( +int wake_irq,bool (*wakeup)(void *context),void *context) +{ +return -EINVAL ; +}
line break is missing.
Thanks,
Basavaraj
Quoted 6 lines
include/linux/acpi.h +3
-0+static inline void acpi_unregister_wakeup_handler ( +bool (*wakeup)(void *context),void *context) { } +#endif /* !CONFIG_ACPI */ #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
Quoted 17 lines · CEST Mario Limonciello
commit
ddfd9dcf270c("ACPI: PM: Add acpi_[un]register_wakeup_handler()") added new functions for drivers to use during the s2idle wakeup path, but didn't add stubs for whenCONFIG_ACPIwasn't set.Add those stubs in for other drivers to be able to use.
Fixes ddfd9dcf270c ("ACPI: PM: Add acpi_[un]register_wakeup_handler()")Signed-off-by Mario Limonciello <[email protected]>--- include/linux/acpi.h | 8 ++++++++ 1 file changed, 8 insertions(+)include/linux/acpi.h +0
-0
include/linux/acpi.h static inline int acpi_get_local_address(acpi_handle handle, u32 *addr) · line 982
Quoted 7 lines
include/linux/acpi.h +4
-0@@ -976,6 +976,14 @@ static inline int acpi_get_local_address(acpi_handle handle, u32 *addr)return -ENODEV ; } +static inline int acpi_register_wakeup_handler ( +int wake_irq,bool (*wakeup)(void *context),void *context) +{ +return -EINVAL ;
-ENOTSUPP ?
Quoted 8 lines
include/linux/acpi.h +4
-0+} +static inline void acpi_unregister_wakeup_handler ( +bool (*wakeup)(void *context),void *context) { } +#endif /* !CONFIG_ACPI */ #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
[Public]
Quoted 36 lines
-----Original Message-----
From: Rafael J. Wysocki <[email protected]>
Sent: Friday, October 22, 2021 07:54
To: Limonciello, Mario <[email protected]>
Cc: Linus Walleij <[email protected]>; Natikar, Basavaraj <[email protected]>; S-k, Shyam-sundar <Shyam-sundar.S- [email protected]>; open list:PIN CONTROL SUBSYSTEM <linux- [email protected]>; open list <[email protected]>; Shah, Nehal- bakulchandra <[email protected]>; Limonciello, Mario <[email protected]>; Linux ACPI <[email protected]>
Subject: Re: [PATCH v3 1/2] ACPI: Add stubs for wakeup handler functionsCC linux-acpiinclude/linux/acpi.h static inline int acpi_get_local_address(acpi_handle
Quoted 17 lines · CEST Mario Limonciello
commit
ddfd9dcf270c("ACPI: PM: Add acpi_[un]register_wakeup_handler()") added new functions for drivers to use during the s2idle wakeup path, but didn't add stubs for whenCONFIG_ACPIwasn't set.Add those stubs in for other drivers to be able to use.
Fixes ddfd9dcf270c ("ACPI: PM: Add acpi_[un]register_wakeup_handler()")Signed-off-by Mario Limonciello <[email protected]>--- include/linux/acpi.h | 8 ++++++++ 1 file changed, 8 insertions(+)include/linux/acpi.h +0
-0@@ -976,6 +976,14 @@ static inline int acpi_get_local_address(acpi_handlehandle, u32 *addr)
Quoted 3 lines
include/linux/acpi.h +0
-0return -ENODEV ; }
Quoted 7 lines
include/linux/acpi.h static inline int acpi_get_local_address(acpi_handle handle, u32 *addr) · line 982
Quoted 4 lines
include/linux/acpi.h +4
-0+static inline int acpi_register_wakeup_handler ( +int wake_irq,bool (*wakeup)(void *context),void *context) +{ +return -EINVAL ;
-ENOTSUPP?
checkpatch reports:
WARNING: ENOTSUPP is not a SUSV4 error code, prefer EOPNOTSUPP
So what to use?
Quoted 11 lines
Quoted 8 lines
include/linux/acpi.h +4
-0+} +static inline void acpi_unregister_wakeup_handler ( +bool (*wakeup)(void *context),void *context) { } +#endif /* !CONFIG_ACPI */ #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
On Tue, Oct 19, 2021 at 7:05 PM Mario Limonciello
<[email protected]> wrote:
Thanks! My comments below.
Quoted 1 line
commit
ddfd9dcf270c("ACPI: PM: Add acpi_[un]register_wakeup_handler()")
The commit
Quoted 4 lines
added new functions for drivers to use during the s2idle wakeup path, but didn't add stubs for when
CONFIG_ACPIwasn't set.Add those stubs in for other drivers to be able to use.
...
include/linux/acpi.h static inline int acpi_get_local_address(acpi_handle handle, u32 *addr) · line 980
Quoted 2 lines
include/linux/acpi.h +2
-0+static inline int acpi_register_wakeup_handler ( +int wake_irq,bool (*wakeup)(void *context),void *context)
A bit of a strange indentation. Can wake_irq be on the previous line?
Signature · 2 lines
With Best Regards, Andy Shevchenko