[PATCH 17/18] sparc32,leon: combine legacy GRPCI1 plug-and-play resources
From: Magnus Lindholm
Date: Thu Nov 26 2026 - 04:32:02 EST
The GRPCI1 host driver expects one node with APB control registers, an
AHB memory window and an AHB I/O window. Legacy discovery creates two
nodes, leaving neither with enough resources for the host to probe.
Pair the APB and AHB entries on each AHB bus and take the interrupt
from the APB entry. Omit incomplete or ambiguous pairs.
Signed-off-by: Magnus Lindholm <linmag7@xxxxxxxxx>
---
arch/sparc/kernel/leon_legacy.c | 62 +++++++++++++++++++++++++++++++--
1 file changed, 60 insertions(+), 2 deletions(-)
diff --git a/arch/sparc/kernel/leon_legacy.c b/arch/sparc/kernel/leon_legacy.c
index 03d3120797f0..d4b3c48a4a10 100644
--- a/arch/sparc/kernel/leon_legacy.c
+++ b/arch/sparc/kernel/leon_legacy.c
@@ -314,7 +314,48 @@ static void __init legacy_device(struct device_node *bus, u32 id, u32 freq,
be32_to_cpu(regs[0]), irq, freq);
}
-static void __init legacy_apb(struct device_node *bus, u32 base, u32 freq)
+/* A GRPCI1 exposes the control registers on APB and two windows on AHB. */
+struct legacy_grpci1 {
+ u32 apb_id;
+ u32 ahb_pnp;
+ unsigned int apb_count;
+ unsigned int ahb_count;
+ __be32 regs[6];
+};
+
+static void __init legacy_add_grpci1(struct device_node *bus, u32 area,
+ u32 freq, struct legacy_grpci1 *pci)
+{
+ u32 mem, io, addr, size;
+
+ if (!pci->apb_count && !pci->ahb_count)
+ return;
+ /* The PnP ID alone cannot pair multiple cores on the same AHB bus. */
+ if (pci->apb_count != 1 || pci->ahb_count != 1 ||
+ !(pci->apb_id & 0x1f))
+ goto invalid;
+
+ mem = legacy_read(pci->ahb_pnp + 16);
+ io = legacy_read(pci->ahb_pnp + 20);
+ if ((mem & 0xf) != 2 || !legacy_bar(area, mem, &addr, &size))
+ goto invalid;
+ pci->regs[2] = cpu_to_be32(addr);
+ pci->regs[3] = cpu_to_be32(size);
+ /* The driver uses 64 KiB each for I/O and configuration space. */
+ if ((io & 0xf) != 3 || !legacy_bar(area, io, &addr, &size) ||
+ size < 0x20000)
+ goto invalid;
+ pci->regs[4] = cpu_to_be32(addr);
+ pci->regs[5] = cpu_to_be32(size);
+ legacy_device(bus, pci->apb_id, freq, pci->regs, 3);
+ return;
+
+invalid:
+ pr_warn("LEON: incomplete or ambiguous GRPCI1 on AHB bus %08x\n", area);
+}
+
+static void __init legacy_apb(struct device_node *bus, u32 base, u32 freq,
+ struct legacy_grpci1 *pci)
{
unsigned int slot;
@@ -325,6 +366,10 @@ static void __init legacy_apb(struct device_node *bus, u32 base, u32 freq)
if (!(id >> 24) || !((id >> 12) & 0xfff))
continue;
+ if (legacy_is(id, GAISLER_PCIFBRG)) {
+ pci->apb_count++;
+ legacy_irqs |= BIT(id & 0x1f);
+ }
bar = legacy_read(pnp + 4);
if ((bar & 0xf) != 1)
continue;
@@ -337,6 +382,11 @@ static void __init legacy_apb(struct device_node *bus, u32 base, u32 freq)
}
regs[0] = cpu_to_be32(addr);
regs[1] = cpu_to_be32(size);
+ if (legacy_is(id, GAISLER_PCIFBRG)) {
+ pci->apb_id = id;
+ memcpy(pci->regs, regs, sizeof(regs));
+ continue;
+ }
legacy_device(bus, id, freq, regs, 1);
}
}
@@ -374,6 +424,7 @@ void __init leon_legacy_amba_init(void)
pr_info("LEON PnP: system ID %08x\n", systemid);
for (b = 0; b < legacy_bus_count; b++) {
+ struct legacy_grpci1 pci = {};
u32 area = legacy_buses[b].area;
u32 freq = legacy_buses[b].freq;
u32 table = area | LEON3_CONF_AREA;
@@ -388,6 +439,12 @@ void __init leon_legacy_amba_init(void)
if (!(id >> 24) || !((id >> 12) & 0xfff) ||
legacy_is(id, GAISLER_AHB2AHB))
continue;
+ if (legacy_is(id, GAISLER_PCIFBRG)) {
+ pci.ahb_count++;
+ pci.ahb_pnp = pnp;
+ legacy_irqs |= BIT(id & 0x1f);
+ continue;
+ }
for (bar = 0; bar < 4; bar++) {
if (!legacy_bar(area, legacy_read(pnp + 16 + bar * 4),
&addr, &size))
@@ -399,11 +456,12 @@ void __init leon_legacy_amba_init(void)
if (!count)
continue;
if (legacy_is(id, GAISLER_APBMST)) {
- legacy_apb(bus, be32_to_cpu(regs[0]), freq);
+ legacy_apb(bus, be32_to_cpu(regs[0]), freq, &pci);
continue;
}
legacy_device(bus, id, freq, regs, count);
}
+ legacy_add_grpci1(bus, area, freq, &pci);
}
if (!IS_ENABLED(CONFIG_SMP))
return;
--
2.43.0