Skip to contentSkip to conversation

m68k: virt: Switch to generic goldfish PIC driver

PATCH In review Kuan-Wei Chiu 2 participants 9 messages Sep 8 – Oct 12

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover m68k: virt: Switch to generic goldfish PIC driver

Convert the m68k virt machine to use the generic goldfish PIC irqchip driver instead of maintaining a duplicate, platform-specific interrupt controller implementation in arch/m68k/virt/.

The whole patchset is tested on qemu-system-m68k -M virt and verified that interrupts across multiple goldfish PIC instances fire and increment properly in /proc/interrupts.
---
P.S. From a quick search on lore, Miodrag has been inactive on LKML for a while. His last appearance was just handing over the goldfish-rtc driver 6 years ago, and prior to that it goes all the way back to 2017.

With tglx's recent call for irqchip reviews in mind, I actually use and care about goldfish devices on qemu for both linux and u-boot, so I'm happy to help review future patches for this driver. I can follow up with a MAINTAINERS patch if that sounds good.

Kuan-Wei Chiu (6):
irqchip/goldfish-pic: Use gf_ioread32/gf_iowrite32 for MMIO access irqchip/goldfish-pic: Use for_each_set_bit() to iterate pending IRQ irqchip/goldfish-pic: Allow selecting CONFIG_GOLDFISH_PIC on other
architectures
irqchip/goldfish-pic: Add goldfish_pic_init() for non DT platforms m68k/irq: Add empty irq_eoi callback to auto/user IRQ chips
m68k: virt: Switch to generic goldfish-pic driver

 MAINTAINERS                              |   1 +
 arch/m68k/Kconfig.machine                |   1 +
 arch/m68k/kernel/ints.c                  |   6 ++
 arch/m68k/virt/ints.c                    |  89 ++----------------
 drivers/irqchip/Kconfig                  |   2 +-
 drivers/irqchip/irq-goldfish-pic.c       | 113 +++++++++++++++--------
 include/linux/irqchip/irq-goldfish-pic.h |  15 +++
 7 files changed, 105 insertions(+), 122 deletions(-)
 create mode 100644 include/linux/irqchip/irq-goldfish-pic.h
Signature · 1 line
2.55.0.979.g7e5102b832-goog
#1 lore raw

PATCH 1/6 irqchip/goldfish-pic: Use gf_ioread32/gf_iowrite32 for MMIO access

The goldfish PIC driver uses readl() and writel() directly for register accesses. On big endian architectures, goldfish devices require big endian MMIO accessors [1].

Switch to gf_ioread32() and gf_iowrite32() to make MMIO accesses endian safe.

---
 drivers/irqchip/irq-goldfish-pic.c | 18 ++++++++++++++++--
 1 file changed, 16 insertions(+), 2 deletions(-)
drivers/irqchip/irq-goldfish-pic.c +16 -2
index d458cf898f8e..c3c33f066140 100644
@@ -7,6 +7,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/goldfish.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
 #include <linux/irqchip.h>
@@ -38,7 +39,7 @@ static void goldfish_pic_cascade(struct irq_desc *desc)
 
 	chained_irq_enter(host_chip, desc);
 
-	pending = readl(gfpic->base + GFPIC_REG_IRQ_PENDING);
+	pending = gf_ioread32(gfpic->base + GFPIC_REG_IRQ_PENDING);
 	while (pending) {
 		hwirq = __fls(pending);
 		generic_handle_domain_irq(gfpic->irq_domain, hwirq);
@@ -52,6 +53,16 @@ static const struct irq_domain_ops goldfish_irq_domain_ops = {
 	.xlate = irq_domain_xlate_onecell,
 };
 
+static u32 gfpic_read(void __iomem *addr)
+{
+	return gf_ioread32(addr);
+}
+
+static void gfpic_write(u32 val, void __iomem *addr)
+{
+	gf_iowrite32(val, addr);
+}
+
 static int __init goldfish_pic_of_init(struct device_node *of_node,
 				       struct device_node *parent)
 {
@@ -82,7 +93,7 @@ static int __init goldfish_pic_of_init(struct device_node *of_node,
 	}
 
 	/* Mask interrupts. */
-	writel(1, gfpic->base + GFPIC_REG_IRQ_DISABLE_ALL);
+	gf_iowrite32(1, gfpic->base + GFPIC_REG_IRQ_DISABLE_ALL);
 
 	gc = irq_alloc_generic_chip("GFPIC", 1, GFPIC_IRQ_BASE, gfpic->base,
 				    handle_level_irq);
@@ -92,6 +103,9 @@ static int __init goldfish_pic_of_init(struct device_node *of_node,
 		goto out_iounmap;
 	}
 
+	gc->reg_readl = gfpic_read;
+	gc->reg_writel = gfpic_write;
+
 	ct = gc->chip_types;
 	ct->regs.enable = GFPIC_REG_IRQ_ENABLE;
 	ct->regs.disable = GFPIC_REG_IRQ_DISABLE;
Signature · 1 line
2.55.0.979.g7e5102b832-goog
#2 lore raw

PATCH 2/6 irqchip/goldfish-pic: Use for_each_set_bit() to iterate pending IRQ

In reply to Kuan-Wei Chiu

Use for_each_set_bit() instead of open-coding the loop with __fls() in goldfish_pic_cascade() to simplify the code.

---
 drivers/irqchip/irq-goldfish-pic.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)
drivers/irqchip/irq-goldfish-pic.c +4 -5
index c3c33f066140..12113ca90872 100644
@@ -7,6 +7,7 @@
 
 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
 
+#include <linux/bitops.h>
 #include <linux/goldfish.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
@@ -35,16 +36,14 @@ static void goldfish_pic_cascade(struct irq_desc *desc)
 {
 	struct goldfish_pic_data *gfpic = irq_desc_get_handler_data(desc);
 	struct irq_chip *host_chip = irq_desc_get_chip(desc);
-	u32 pending, hwirq;
+	unsigned long pending;
+	u32 hwirq;
 
 	chained_irq_enter(host_chip, desc);
 
 	pending = gf_ioread32(gfpic->base + GFPIC_REG_IRQ_PENDING);
-	while (pending) {
-		hwirq = __fls(pending);
+	for_each_set_bit(hwirq, &pending, GFPIC_NR_IRQS)
 		generic_handle_domain_irq(gfpic->irq_domain, hwirq);
-		pending &= ~(1 << hwirq);
-	}
 
 	chained_irq_exit(host_chip, desc);
 }
Signature · 1 line
2.55.0.979.g7e5102b832-goog
#3 lore raw

PATCH 3/6 irqchip/goldfish-pic: Allow selecting CONFIG_GOLDFISH_PIC on other architectures

In reply to Kuan-Wei Chiu

Drop the MIPS dependency from CONFIG_GOLDFISH_PIC so that other architectures can use this driver. Also update the file header comment to remove the MIPS reference.

---
 drivers/irqchip/Kconfig            | 2 +-
 drivers/irqchip/irq-goldfish-pic.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/irqchip/Kconfig +1 -1
index 20b77fbc51ee..a0f0f3a0e8ea 100644
@@ -513,7 +513,7 @@ config MESON_IRQ_GPIO
 
 config GOLDFISH_PIC
        bool "Goldfish programmable interrupt controller"
-       depends on MIPS && (GOLDFISH || COMPILE_TEST)
+       depends on GOLDFISH || COMPILE_TEST
        select GENERIC_IRQ_CHIP
        select IRQ_DOMAIN
        help
drivers/irqchip/irq-goldfish-pic.c +1 -1
index 12113ca90872..8d40df0e3a88 100644
@@ -1,6 +1,6 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /*
- * Driver for MIPS Goldfish Programmable Interrupt Controller.
+ * Driver for Goldfish Programmable Interrupt Controller.
  *
  * Author: Miodrag Dinic <[email protected]>
  */
Signature · 1 line
2.55.0.979.g7e5102b832-goog
#4 lore raw

PATCH 4/6 irqchip/goldfish-pic: Add goldfish_pic_init() for non DT platforms

In reply to Kuan-Wei Chiu

The driver currently only supports device tree initialization and hardcodes the IRQ base to 8, which prevents non DT platforms from using it.

Split the core controller setup out of goldfish_pic_of_init() into a new exported helper goldfish_pic_init() that accepts a mapped base address, parent IRQ, IRQ base, and fwnode.

---
 MAINTAINERS                              |  1 +
 drivers/irqchip/irq-goldfish-pic.c       | 84 ++++++++++++++----------
 include/linux/irqchip/irq-goldfish-pic.h | 15 +++++
 3 files changed, 67 insertions(+), 33 deletions(-)
 create mode 100644 include/linux/irqchip/irq-goldfish-pic.h
MAINTAINERS +1 -0
index 6215fcb07770..f6c37e1dbee7 100644
@@ -2004,6 +2004,7 @@ M:	Miodrag Dinic <[email protected]>
 S:	Supported
 F:	Documentation/devicetree/bindings/interrupt-controller/google,goldfish-pic.yaml
 F:	drivers/irqchip/irq-goldfish-pic.c
+F:	include/linux/irqchip/irq-goldfish-pic.h
 
 ANDROID GOLDFISH RTC DRIVER
 M:	Jiaxun Yang <[email protected]>
drivers/irqchip/irq-goldfish-pic.c +51 -33

133 lines not on this page · raw message

include/linux/irqchip/irq-goldfish-pic.h new file +15 -0
new file mode 100644
index 000000000000..f2e8762aec88
@@ -0,0 +1,15 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Goldfish Programmable Interrupt Controller support
+ */
+
+#ifndef __LINUX_IRQCHIP_IRQ_GOLDFISH_PIC_H
+#define __LINUX_IRQCHIP_IRQ_GOLDFISH_PIC_H
+
+#include <linux/fwnode.h>
+#include <linux/types.h>
+
+int goldfish_pic_init(void __iomem *base, unsigned int parent_irq,
+		      unsigned int irq_base, struct fwnode_handle *fwnode);
+
+#endif /* __LINUX_IRQCHIP_IRQ_GOLDFISH_PIC_H */
Signature · 1 line
2.55.0.979.g7e5102b832-goog
#5 lore raw

PATCH 5/6 m68k/irq: Add empty irq_eoi callback to auto/user IRQ chips

In reply to Kuan-Wei Chiu

When an irq_chip lacks an irq_eoi callback, chained_irq_enter() falls back to invoking chip->irq_mask(). On auto_irq_chip and user_irq_chip, this leads to a NULL pointer dereference because autovector interrupts are masked via the CPU SR rather than dedicated mask registers.

Add a no-op m68k_irq_eoi() callback to auto_irq_chip and user_irq_chip so chained interrupt handlers can safely attach to these chips.

---
 arch/m68k/kernel/ints.c | 6 ++++++
 1 file changed, 6 insertions(+)
arch/m68k/kernel/ints.c +6 -0
index cf2b13488476..731d04ac95bd 100644
@@ -33,16 +33,22 @@ extern u16 user_irqvec_fixup[];
 
 static int m68k_first_user_vec;
 
+static void m68k_irq_eoi(struct irq_data *data)
+{
+}
+
 static struct irq_chip auto_irq_chip = {
 	.name		= "auto",
 	.irq_startup	= m68k_irq_startup,
 	.irq_shutdown	= m68k_irq_shutdown,
+	.irq_eoi	= m68k_irq_eoi,
 };
 
 static struct irq_chip user_irq_chip = {
 	.name		= "user",
 	.irq_startup	= m68k_irq_startup,
 	.irq_shutdown	= m68k_irq_shutdown,
+	.irq_eoi	= m68k_irq_eoi,
 };
 
 /*
Signature · 1 line
2.55.0.979.g7e5102b832-goog
#6 lore raw

PATCH 6/6 m68k: virt: Switch to generic goldfish-pic driver

In reply to Kuan-Wei Chiu

The m68k virt platform implements a custom irq_chip and chained handler in arch/m68k/virt/ints.c to handle its 6 goldfish PIC instances.

Replace this custom implementation with calls to goldfish_pic_init() to use the generic goldfish-pic driver, and select CONFIG_GOLDFISH_PIC for CONFIG_VIRT.

---
 arch/m68k/Kconfig.machine |  1 +
 arch/m68k/virt/ints.c     | 89 ++++-----------------------------------
 2 files changed, 10 insertions(+), 80 deletions(-)
arch/m68k/Kconfig.machine +1 -0
index cff990c319cb..7b15012ffb28 100644
@@ -130,6 +130,7 @@ config VIRT
 	depends on MMU
 	select GENERIC_CLOCKEVENTS
 	select GOLDFISH
+	select GOLDFISH_PIC
 	select GOLDFISH_TIMER
 	select GOLDFISH_TTY
 	select M68040
arch/m68k/virt/ints.c +9 -80

125 lines not on this page · raw message

Signature · 1 line
2.55.0.979.g7e5102b832-goog
#7 lore raw
In reply to Kuan-Wei Chiu
Quoted 7 lines · Kuan-Wei Chiu

Convert the m68k virt machine to use the generic goldfish PIC irqchip driver instead of maintaining a duplicate, platform-specific interrupt controller implementation in arch/m68k/virt/.

The whole patchset is tested on qemu-system-m68k -M virt and verified that interrupts across multiple goldfish PIC instances fire and increment properly in /proc/interrupts.

It seems Miodrag's email bounced, so I guess I'll need to look for others to help review this patchset.

+Cc Laurent Vivier since he wrote the initial m68k virt machine code.

Regards,
Kuan-Wei

#8 lore raw

Hi Kuan-Wei,

Quoted 2 lines · Kuan-Wei Chiu

It seems Miodrag's email bounced, so I guess I'll need to look for others to help review this patchset.

FWIW, I have a version of this in my devicetree'd nommu m68k setup I think. When I get some time I will pull in your version and test it out.

Cheers,

Daniel