linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v6 1/2] ACPI: Add stubs for wakeup handler functions
@ 2021-10-29 20:40 Mario Limonciello
  2021-10-29 20:40 ` [PATCH v6 2/2] pinctrl: amd: Fix wakeups when IRQ is shared with SCI Mario Limonciello
  0 siblings, 1 reply; 4+ messages in thread
From: Mario Limonciello @ 2021-10-29 20:40 UTC (permalink / raw)
  To: Linus Walleij, Basavaraj Natikar, Shyam Sundar S K
  Cc: open list:PIN CONTROL SUBSYSTEM, open list, linux-acpi,
	Nehal Shah, Mario Limonciello, Rafael J . Wysocki

The 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.

Fixes: ddfd9dcf270c ("ACPI: PM: Add acpi_[un]register_wakeup_handler()")
Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
---
Changes from v5->v6:
 * No changes
Changes from v4->v5:
 * Pick up Rafael's tag
 * Target to stable as well
Changes from v3->v4:
 * Reword commit message
 * Adjust whitespace
 * Return -ENXIO instead of -EINVAL
 include/linux/acpi.h | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/include/linux/acpi.h b/include/linux/acpi.h
index 72e4f7fd268c..e29b4c1da377 100644
--- a/include/linux/acpi.h
+++ b/include/linux/acpi.h
@@ -976,6 +976,15 @@ 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 -ENXIO;
+}
+
+static inline void acpi_unregister_wakeup_handler(
+	bool (*wakeup)(void *context), void *context) { }
+
 #endif	/* !CONFIG_ACPI */
 
 #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v6 2/2] pinctrl: amd: Fix wakeups when IRQ is shared with SCI
  2021-10-29 20:40 [PATCH v6 1/2] ACPI: Add stubs for wakeup handler functions Mario Limonciello
@ 2021-10-29 20:40 ` Mario Limonciello
  2021-10-31 13:15   ` Andy Shevchenko
  0 siblings, 1 reply; 4+ messages in thread
From: Mario Limonciello @ 2021-10-29 20:40 UTC (permalink / raw)
  To: Linus Walleij, Basavaraj Natikar, Shyam Sundar S K
  Cc: open list:PIN CONTROL SUBSYSTEM, open list, linux-acpi,
	Nehal Shah, Mario Limonciello, stable, Joerie de Gram

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.

Cc: stable@kernel.org
BugLink: https://gitlab.freedesktop.org/drm/amd/-/issues/1738
Reported-by: Joerie de Gram <j.de.gram@gmail.com>
Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
Acked-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
---
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 v5->v6:
 * Add a cast to debugging statement for an error caught by 0-day CI.
 * Add Basavaraj's tag
Changes from v4->v5:
 * Correct debugging statement that was obfuscated by kernel %p behavior.
 * Instead show actual GPIO number, which is much more useful for debugging
 * Target to stable as well
Changes from v3->v4:
 * Adjust to reverse xmas for newly added variable
 * Add a debugging line to show the values in the register that caused system
   wake to allow for debugging of spurious wakeups
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 | 31 ++++++++++++++++++++++++++++---
 1 file changed, 28 insertions(+), 3 deletions(-)

diff --git a/drivers/pinctrl/pinctrl-amd.c b/drivers/pinctrl/pinctrl-amd.c
index d19974aceb2e..c750ffd5c012 100644
--- a/drivers/pinctrl/pinctrl-amd.c
+++ b/drivers/pinctrl/pinctrl-amd.c
@@ -598,14 +598,14 @@ 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;
+	bool ret = false;
 	u32  regval;
 	u64 status, mask;
 
@@ -627,6 +627,16 @@ 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))) {
+				dev_dbg(&gpio_dev->pdev->dev,
+					"Waking due to GPIO %ld: 0x%x",
+					(long)(regs + i - ((u32 __iomem *)gpio_dev->base)), regval);
+				return true;
+			}
+
 			if (!(regval & PIN_IRQ_PENDING) ||
 			    !(regval & BIT(INTERRUPT_MASK_OFF)))
 				continue;
@@ -652,9 +662,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 +679,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 +1027,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 +1045,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;
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v6 2/2] pinctrl: amd: Fix wakeups when IRQ is shared with SCI
  2021-10-29 20:40 ` [PATCH v6 2/2] pinctrl: amd: Fix wakeups when IRQ is shared with SCI Mario Limonciello
@ 2021-10-31 13:15   ` Andy Shevchenko
  2021-11-01  1:50     ` Limonciello, Mario
  0 siblings, 1 reply; 4+ messages in thread
From: Andy Shevchenko @ 2021-10-31 13:15 UTC (permalink / raw)
  To: Mario Limonciello
  Cc: Linus Walleij, Basavaraj Natikar, Shyam Sundar S K,
	open list:PIN CONTROL SUBSYSTEM, open list,
	ACPI Devel Maling List, Nehal Shah, stable, Joerie de Gram

On Fri, Oct 29, 2021 at 11:42 PM Mario Limonciello
<mario.limonciello@amd.com> wrote:
>
> 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.
>
> Cc: stable@kernel.org
> BugLink: https://gitlab.freedesktop.org/drm/amd/-/issues/1738
> Reported-by: Joerie de Gram <j.de.gram@gmail.com>
> Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> Acked-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>

...

> +static bool _amd_gpio_irq_handler(int irq, void *dev_id)

I know Linus does not like leading _* in the function names, what
about 'do_' instead?

...

> +                       /* called from resume context on a shared IRQ, just
> +                        * checking wake source.
> +                        */

Is this comment aligned with the style used elsewhere in the driver code?

...

> +                               dev_dbg(&gpio_dev->pdev->dev,
> +                                       "Waking due to GPIO %ld: 0x%x",
> +                                       (long)(regs + i - ((u32 __iomem *)gpio_dev->base)), regval);

Oy vey, these castings are ugly. The rule of thumb is that if one does
such a thing for printf() it means something is really wrong (in 99%
of the cases).

AFAICS you may simply use 'irqnr + i' as the other message does.

...

>         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 +1045,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);

Thinking about making this in the generic GPIO library code, but this
is out of scope of the patch...

-- 
With Best Regards,
Andy Shevchenko

^ permalink raw reply	[flat|nested] 4+ messages in thread

* RE: [PATCH v6 2/2] pinctrl: amd: Fix wakeups when IRQ is shared with SCI
  2021-10-31 13:15   ` Andy Shevchenko
@ 2021-11-01  1:50     ` Limonciello, Mario
  0 siblings, 0 replies; 4+ messages in thread
From: Limonciello, Mario @ 2021-11-01  1:50 UTC (permalink / raw)
  To: Andy Shevchenko
  Cc: Linus Walleij, Natikar, Basavaraj, S-k, Shyam-sundar,
	open list:PIN CONTROL SUBSYSTEM, open list,
	ACPI Devel Maling List, Shah, Nehal-bakulchandra, stable,
	Joerie de Gram

[Public]

> -----Original Message-----
> From: Andy Shevchenko <andy.shevchenko@gmail.com>
> Sent: Sunday, October 31, 2021 08:15
> To: Limonciello, Mario <Mario.Limonciello@amd.com>
> Cc: Linus Walleij <linus.walleij@linaro.org>; Natikar, Basavaraj
> <Basavaraj.Natikar@amd.com>; S-k, Shyam-sundar <Shyam-sundar.S-
> k@amd.com>; open list:PIN CONTROL SUBSYSTEM <linux-
> gpio@vger.kernel.org>; open list <linux-kernel@vger.kernel.org>; ACPI Devel
> Maling List <linux-acpi@vger.kernel.org>; Shah, Nehal-bakulchandra <Nehal-
> bakulchandra.Shah@amd.com>; stable@kernel.org; Joerie de Gram
> <j.de.gram@gmail.com>
> Subject: Re: [PATCH v6 2/2] pinctrl: amd: Fix wakeups when IRQ is shared with
> SCI
> 
> On Fri, Oct 29, 2021 at 11:42 PM Mario Limonciello
> <mario.limonciello@amd.com> wrote:
> >
> > 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.
> >
> > Cc: stable@kernel.org
> > BugLink:
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.fr
> eedesktop.org%2Fdrm%2Famd%2F-
> %2Fissues%2F1738&amp;data=04%7C01%7Cmario.limonciello%40amd.com%7
> C8962eb61c66843248eff08d99c708f19%7C3dd8961fe4884e608e11a82d994e18
> 3d%7C0%7C0%7C637712829517705057%7CUnknown%7CTWFpbGZsb3d8eyJWI
> joiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C100
> 0&amp;sdata=57LKx3moIAVwtjmncHiqDMgvYP5tkEL7JuAP76iaCHI%3D&amp;re
> served=0
> > Reported-by: Joerie de Gram <j.de.gram@gmail.com>
> > Signed-off-by: Mario Limonciello <mario.limonciello@amd.com>
> > Acked-by: Basavaraj Natikar <Basavaraj.Natikar@amd.com>
> 
> ...
> 
> > +static bool _amd_gpio_irq_handler(int irq, void *dev_id)
> 
> I know Linus does not like leading _* in the function names, what
> about 'do_' instead?
> 
> ...
> 
> > +                       /* called from resume context on a shared IRQ, just
> > +                        * checking wake source.
> > +                        */
> 
> Is this comment aligned with the style used elsewhere in the driver code?
> 
> ...
> 
> > +                               dev_dbg(&gpio_dev->pdev->dev,
> > +                                       "Waking due to GPIO %ld: 0x%x",
> > +                                       (long)(regs + i - ((u32 __iomem *)gpio_dev->base)),
> regval);
> 
> Oy vey, these castings are ugly. The rule of thumb is that if one does
> such a thing for printf() it means something is really wrong (in 99%
> of the cases).
> 
> AFAICS you may simply use 'irqnr + i' as the other message does.
> 

Andy,

Appreciate your comments.  You're correct.  I've sent a follow up addressing them.

> ...
> 
> >         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 +1045,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);
> 
> Thinking about making this in the generic GPIO library code, but this
> is out of scope of the patch...

Sure, we can think about this if/when there ends up being another consumer of it.

> 
> --
> With Best Regards,
> Andy Shevchenko

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-11-01  1:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-29 20:40 [PATCH v6 1/2] ACPI: Add stubs for wakeup handler functions Mario Limonciello
2021-10-29 20:40 ` [PATCH v6 2/2] pinctrl: amd: Fix wakeups when IRQ is shared with SCI Mario Limonciello
2021-10-31 13:15   ` Andy Shevchenko
2021-11-01  1:50     ` Limonciello, Mario

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).