linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] cache: sifive_ccache: Partially convert to a platform driver
@ 2024-03-27  5:45 Samuel Holland
  2024-03-28 14:45 ` Geert Uytterhoeven
  2024-03-28 22:44 ` Conor Dooley
  0 siblings, 2 replies; 3+ messages in thread
From: Samuel Holland @ 2024-03-27  5:45 UTC (permalink / raw)
  To: Conor Dooley
  Cc: Samuel Holland, Anup Patel, Paul Walmsley, Thomas Gleixner,
	linux-kernel, linux-riscv

Commit 8ec99b033147 ("irqchip/sifive-plic: Convert PLIC driver into a
platform driver") broke ccache initialization because the PLIC IRQ
domain is no longer available during an arch_initcall:

  [    0.087229] irq: no irq domain found for interrupt-controller@c000000 !
  [    0.087255] CCACHE: Could not request IRQ 0

Fix this by moving the IRQ handling code to a platform driver.

Fixes: 8ec99b033147 ("irqchip/sifive-plic: Convert PLIC driver into a platform driver")
Signed-off-by: Samuel Holland <samuel.holland@sifive.com>
---

 drivers/cache/sifive_ccache.c | 72 ++++++++++++++++++++++-------------
 1 file changed, 46 insertions(+), 26 deletions(-)

diff --git a/drivers/cache/sifive_ccache.c b/drivers/cache/sifive_ccache.c
index 89ed6cd6b059..e9cc8b4786fb 100644
--- a/drivers/cache/sifive_ccache.c
+++ b/drivers/cache/sifive_ccache.c
@@ -15,6 +15,8 @@
 #include <linux/of_address.h>
 #include <linux/device.h>
 #include <linux/bitfield.h>
+#include <linux/platform_device.h>
+#include <linux/property.h>
 #include <asm/cacheflush.h>
 #include <asm/cacheinfo.h>
 #include <asm/dma-noncoherent.h>
@@ -247,13 +249,49 @@ static irqreturn_t ccache_int_handler(int irq, void *device)
 	return IRQ_HANDLED;
 }
 
+static int sifive_ccache_probe(struct platform_device *pdev)
+{
+	struct device *dev = &pdev->dev;
+	unsigned long quirks;
+	int intr_num, rc;
+
+	quirks = (unsigned long)device_get_match_data(dev);
+
+	intr_num = platform_irq_count(pdev);
+	if (!intr_num)
+		return dev_err_probe(dev, -ENODEV, "No interrupts property\n");
+
+	for (int i = 0; i < intr_num; i++) {
+		if (i == DATA_UNCORR && (quirks & QUIRK_BROKEN_DATA_UNCORR))
+			continue;
+
+		g_irq[i] = platform_get_irq(pdev, i);
+		if (g_irq[i] < 0)
+			return g_irq[i];
+
+		rc = devm_request_irq(dev, g_irq[i], ccache_int_handler, 0, "ccache_ecc", NULL);
+		if (rc)
+			return dev_err_probe(dev, rc, "Could not request IRQ %d\n", g_irq[i]);
+	}
+
+	return 0;
+}
+
+static struct platform_driver sifive_ccache_driver = {
+	.probe	= sifive_ccache_probe,
+	.driver	= {
+		.name		= "sifive_ccache",
+		.of_match_table	= sifive_ccache_ids,
+	},
+};
+
 static int __init sifive_ccache_init(void)
 {
 	struct device_node *np;
 	struct resource res;
-	int i, rc, intr_num;
 	const struct of_device_id *match;
 	unsigned long quirks;
+	int rc;
 
 	np = of_find_matching_node_and_match(NULL, sifive_ccache_ids, &match);
 	if (!np)
@@ -277,28 +315,6 @@ static int __init sifive_ccache_init(void)
 		goto err_unmap;
 	}
 
-	intr_num = of_property_count_u32_elems(np, "interrupts");
-	if (!intr_num) {
-		pr_err("No interrupts property\n");
-		rc = -ENODEV;
-		goto err_unmap;
-	}
-
-	for (i = 0; i < intr_num; i++) {
-		g_irq[i] = irq_of_parse_and_map(np, i);
-
-		if (i == DATA_UNCORR && (quirks & QUIRK_BROKEN_DATA_UNCORR))
-			continue;
-
-		rc = request_irq(g_irq[i], ccache_int_handler, 0, "ccache_ecc",
-				 NULL);
-		if (rc) {
-			pr_err("Could not request IRQ %d\n", g_irq[i]);
-			goto err_free_irq;
-		}
-	}
-	of_node_put(np);
-
 #ifdef CONFIG_RISCV_NONSTANDARD_CACHE_OPS
 	if (quirks & QUIRK_NONSTANDARD_CACHE_OPS) {
 		riscv_cbom_block_size = SIFIVE_CCACHE_LINE_SIZE;
@@ -315,11 +331,15 @@ static int __init sifive_ccache_init(void)
 #ifdef CONFIG_DEBUG_FS
 	setup_sifive_debug();
 #endif
+
+	rc = platform_driver_register(&sifive_ccache_driver);
+	if (rc)
+		goto err_unmap;
+
+	of_node_put(np);
+
 	return 0;
 
-err_free_irq:
-	while (--i >= 0)
-		free_irq(g_irq[i], NULL);
 err_unmap:
 	iounmap(ccache_base);
 err_node_put:
-- 
2.43.1


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

* Re: [PATCH] cache: sifive_ccache: Partially convert to a platform driver
  2024-03-27  5:45 [PATCH] cache: sifive_ccache: Partially convert to a platform driver Samuel Holland
@ 2024-03-28 14:45 ` Geert Uytterhoeven
  2024-03-28 22:44 ` Conor Dooley
  1 sibling, 0 replies; 3+ messages in thread
From: Geert Uytterhoeven @ 2024-03-28 14:45 UTC (permalink / raw)
  To: Samuel Holland
  Cc: Conor Dooley, Anup Patel, Paul Walmsley, Thomas Gleixner,
	linux-kernel, linux-riscv

Hi Samuel,

On Wed, Mar 27, 2024 at 6:45 AM Samuel Holland
<samuel.holland@sifive.com> wrote:
> Commit 8ec99b033147 ("irqchip/sifive-plic: Convert PLIC driver into a
> platform driver") broke ccache initialization because the PLIC IRQ
> domain is no longer available during an arch_initcall:
>
>   [    0.087229] irq: no irq domain found for interrupt-controller@c000000 !
>   [    0.087255] CCACHE: Could not request IRQ 0
>
> Fix this by moving the IRQ handling code to a platform driver.
>
> Fixes: 8ec99b033147 ("irqchip/sifive-plic: Convert PLIC driver into a platform driver")
> Signed-off-by: Samuel Holland <samuel.holland@sifive.com>

Thanks, this fixes the Starlight boot failure I didn't get to bisect yet.
Tested-by: Geert Uytterhoeven <geert@linux-m68k.org>

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

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

* Re: [PATCH] cache: sifive_ccache: Partially convert to a platform driver
  2024-03-27  5:45 [PATCH] cache: sifive_ccache: Partially convert to a platform driver Samuel Holland
  2024-03-28 14:45 ` Geert Uytterhoeven
@ 2024-03-28 22:44 ` Conor Dooley
  1 sibling, 0 replies; 3+ messages in thread
From: Conor Dooley @ 2024-03-28 22:44 UTC (permalink / raw)
  To: Conor Dooley, Samuel Holland
  Cc: Conor Dooley, Anup Patel, Paul Walmsley, Thomas Gleixner,
	linux-kernel, linux-riscv

From: Conor Dooley <conor.dooley@microchip.com>

On Tue, 26 Mar 2024 22:45:24 -0700, Samuel Holland wrote:
> Commit 8ec99b033147 ("irqchip/sifive-plic: Convert PLIC driver into a
> platform driver") broke ccache initialization because the PLIC IRQ
> domain is no longer available during an arch_initcall:
> 
>   [    0.087229] irq: no irq domain found for interrupt-controller@c000000 !
>   [    0.087255] CCACHE: Could not request IRQ 0
> 
> [...]

Applied to riscv-soc-fixes, thanks for doing this Samuel.

[1/1] cache: sifive_ccache: Partially convert to a platform driver
      https://git.kernel.org/conor/c/c90847bcbfb6

Thanks,
Conor.

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

end of thread, other threads:[~2024-03-28 22:45 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-27  5:45 [PATCH] cache: sifive_ccache: Partially convert to a platform driver Samuel Holland
2024-03-28 14:45 ` Geert Uytterhoeven
2024-03-28 22:44 ` Conor Dooley

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