mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support
@ 2026-11-26  9:30 Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 01/18] sparc32,leon: give the cross-call IRQ highest priority Magnus Lindholm
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7

This series fixes four problems on LEON SMP and restores Linux boot
on the dual-CPU GR-LEON4-ITX with its factory U-Boot. Patches 1-4 can
be merged separately from the firmware and board support. Patch 1
gives cross-call IRQ15 highest priority so a lower-numbered interrupt
cannot block it at the controller. Patches 2 and 3 fix stale TLB and
I-cache entries on remote CPUs. Patch 4 fixes nested timer IRQ
accounting that made idle CPUs appear fully busy.

Thanks to Sam for providing me with a LEON4 board for testing, and to
Andreas for helping make that possible. This work grew out of my
ongoing efforts to fix similar issues on legacy Sun systems with
SuperSPARC and HyperSPARC CPUs.

Base and prerequisites
----------------------
The base is Andreas Larsson's for-next at c95443b98771, plus two posted
patches from "sparc32: repair cache hooks, mappings and TLB tracking".

  [PATCH 8/9] sparc32: retain mm_cpumask across TLB shootdowns
  Message-ID: 20261108223516.1125534-9-linmag7@gmail.com

  [PATCH 9/9] sparc32: enroll and order CPUs before switching address spaces
  Message-ID: 20261108223516.1125534-10-linmag7@gmail.com

Patch 2 needs both. The generic SMP flush uses mm_cpumask to find CPUs
that may hold a translation. The prerequisites keep CPUs in that mask
across shootdowns and record each CPU before it enters an address space.

  https://lore.kernel.org/sparclinux/20261108223516.1125534-1-linmag7@gmail.com/

Factory U-Boot and memory
-------------------------
Patches 5-14 handle the legacy PROM console and machine identification,
preserve the Linux IRQ14 vector during startup and discover the AMBA
and I2C devices missing from the firmware tree. On this board, cached
LDSTUB lock acquisitions can stall. Patch 10 selects ASI 1 for kernel
and module locks when the GRLIB system ID matches 0x01020db4. Patch 11
restores the header offsets that factory U-Boot checks, at a cost of
32 KiB in LEON-enabled images.

Patches 15-16 recover 62 MiB of upper SDRAM. The factory PROM reports
only the lower 192 MiB minus 8 KiB. With the upper banks enabled,
importing U-Boot's SDRAM mappings leaves aliases in the kernel's I/O
and vmalloc areas. Linux skips that import on this board and checks the
PROM map, DDR2 geometry and active scanout before adding RAM. The 8 KiB
PROM and 2 MiB framebuffer reservation stay outside the page allocator.
Mapping and unmapping a HIGHMEM page incurs cache and TLB flushes on
both CPUs. The workload cost is unmeasured. Booting with mem=192M
keeps the original memory limit for comparison.

Patch 17 joins the APB control registers and AHB windows into the
single device expected by the GRPCI1 host driver. Patch 18 describes
the DS1672 at address 0x68 on I2CM0. The LEON4-ASIC-DEMO was also
sold as a standalone chip. System ID 0x01020db4 identifies the ASIC,
and I2CM0 is at 0xc0000700 on that chip.

Andreas, did any other carrier ship with this ASIC and the factory
GR-LEON4-ITX U-Boot? If so, is there a firmware property or board ID
we can use to tell which carriers have the DS1672? Patches 1-17 can
proceed while we confirm the match for patch 18.

Testing
-------
Hardware testing used a dual-CPU GR-LEON4-ITX with PREEMPT_VOLUNTARY.
The TLB, I-cache, timer and cross-CPU memory tests used integration
kernels with other pending sparc32 work, including earlier revisions of
the LEON changes. The module-reload comparisons used for-next and both
posted prerequisites, with the TLB fix as the only source difference
within each pair.

* During a HIGHMEM unmap, the Ethernet debug link (EDCL) showed CPU0
  spinning on the cross-call lock held by CPU1. CPU1 was waiting for
  CPU0 to acknowledge IRQ15. With patch 1, the board booted from the
  Maxtor and EDCL confirmed ILEVEL=0x800e with both CPUs online.
* In the TLB and I-cache tests, one CPU changed a mapping or rewrote
  an instruction. The other CPU read the page or executed the code. The
  baseline returned stale results. Each fix made the corresponding
  remote test pass. Repeated module loads also faulted without the TLB
  fix. With it, the corrected harness completed 74 load/unload cycles.
* In an earlier boot with patches 2-16 and both CPUs online, EDCL and
  a test module confirmed ASI 1 at kernel and module lock sites.
  The module's lock tests passed. In
  Gentoo, we checked per-CPU accounting at rest and with a workload
  pinned to one CPU. The idle CPU continued to report idle time.
* The CPUs took turns writing and verifying page patterns in both
  HIGHMEM banks. An EDCL page-table walk confirmed coverage above 98%
  in each bank, with all tested pages outside the reserved ranges
  and the 800x600 framebuffer active. A second walk found no inherited
  U-Boot SDRAM mappings in the PROM-import window.
* Gentoo booted from the Maxtor on a PCI 53C895 with sym53c8xx.burst=0.
  The stage3 install with bursts enabled logged 15 PCI master aborts
  (status 0x2000), each followed by a SCSI bus reset. The install with
  bursts disabled logged no master aborts. The cause is unknown.
  The DS1672 registered as rtc0 at boot, set the system clock and
  returned advancing times in two hwclock reads.

Before the IRQ15 change, an integration kernel with patches 2-18 booted
Gentoo on a dual HyperSPARC SS-20 with both CPUs online. Those patches
also built at each step with modules for LEON and generic sparc32,
both UP and SMP, without warnings or errors. That tip also built with
sparc64_defconfig. Host tests covered the U-Boot header, firmware
discovery, lock selection, framebuffer conflicts and GRPCI1 pairing.
Full-preemption and context-exhaustion testing remain open.

OpenAI Codex assisted with implementation, board-capture analysis and
validation tooling.

Magnus Lindholm (18):
  sparc32,leon: give the cross-call IRQ highest priority
  sparc32,leon: retain SMP TLB shootdowns
  sparc32,leon: publish instruction updates across CPUs
  sparc32,leon: avoid nested IRQ accounting in the timer handler
  sparc32: preserve both LEON PROM character-output conventions
  sparc32: tolerate firmware nodes without a name property
  sparc32: skip unavailable PROM V0 console metadata
  sparc32,leon: identify LEON before the firmware model lookup
  sparc32,leon: preserve the Linux IRQ14 vector during startup
  sparc32,leon: use ASI 1 for locks on the GR-LEON4-ITX
  sparc32,leon: restore the kernel header offsets used by U-Boot
  sparc32: recognize the legacy LEON firmware machine ID
  sparc32,leon: discover AMBA devices for legacy U-Boot PROMs
  sparc32,leon: describe legacy AMBA I2C controllers
  sparc32,leon: skip the GR-LEON4-ITX PROM mapping import
  sparc32,leon: use the upper SDRAM on the GR-LEON4-ITX
  sparc32,leon: combine legacy GRPCI1 plug-and-play resources
  sparc32,leon: describe the DS1672 on the GR-LEON4-ITX

 arch/sparc/include/asm/cacheflush_32.h |   2 +-
 arch/sparc/include/asm/ldstub.h        |  46 +++
 arch/sparc/include/asm/leon.h          |   3 +
 arch/sparc/include/asm/leon_amba.h     |   2 +
 arch/sparc/include/asm/machines.h      |   1 +
 arch/sparc/include/asm/oplib_32.h      |   2 +
 arch/sparc/include/asm/sections.h      |   2 +
 arch/sparc/include/asm/spinlock_32.h   |  32 +-
 arch/sparc/kernel/Makefile             |   1 +
 arch/sparc/kernel/head_32.S            |  46 ++-
 arch/sparc/kernel/idprom.c             |   2 +
 arch/sparc/kernel/leon_kernel.c        |   2 -
 arch/sparc/kernel/leon_legacy.c        | 487 +++++++++++++++++++++++++
 arch/sparc/kernel/leon_smp.c           |   9 +
 arch/sparc/kernel/module.c             |  25 ++
 arch/sparc/kernel/prom.h               |   5 +
 arch/sparc/kernel/prom_32.c            |  16 +
 arch/sparc/kernel/prom_common.c        |   1 +
 arch/sparc/kernel/setup_32.c           |  57 ++-
 arch/sparc/kernel/vmlinux.lds.S        |   5 +
 arch/sparc/lib/locks.S                 |  24 +-
 arch/sparc/mm/leon_mm.c                |   3 +-
 arch/sparc/mm/srmmu.c                  |  21 +-
 arch/sparc/prom/console_32.c           |   5 +-
 arch/sparc/prom/init_32.c              |  23 ++
 drivers/of/pdt.c                       |   9 +-
 include/linux/of_pdt.h                 |   5 +
 27 files changed, 793 insertions(+), 43 deletions(-)
 create mode 100644 arch/sparc/include/asm/ldstub.h
 create mode 100644 arch/sparc/kernel/leon_legacy.c


base-commit: c95443b98771a74c6689f5e7bbc56794fe95f550
prerequisite-patch-id: f4142189700ce7c766378c481a47244a7dd13140
prerequisite-patch-id: d2a8aa69c22fd06cbd2dae10f81e1c6db1b95a6d
-- 
2.43.0


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

* [PATCH 01/18] sparc32,leon: give the cross-call IRQ highest priority
  2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
@ 2026-11-26  9:30 ` Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 02/18] sparc32,leon: retain SMP TLB shootdowns Magnus Lindholm
                   ` (16 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7

A CPU can spin on cross_call_lock at PIL 15 while the lock holder
waits for it to acknowledge IRQ15. If firmware gives a lower-numbered
interrupt higher priority in IRQMP, that interrupt can keep IRQ15 from
reaching the waiting CPU.

Put IRQ15 in IRQMP's high-priority group before enabling cross-calls.
IRQ15 wins within that group. Preserve the priorities of the other
interrupts.

Fixes: 8401707ff645 ("sparc,leon: Sparc-Leon SMP support")
Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/sparc/kernel/leon_smp.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/sparc/kernel/leon_smp.c b/arch/sparc/kernel/leon_smp.c
index 1ee393abc463..649f219e2b69 100644
--- a/arch/sparc/kernel/leon_smp.c
+++ b/arch/sparc/kernel/leon_smp.c
@@ -159,6 +159,7 @@ void __init leon_boot_cpus(void)
 {
 	int nrcpu = leon_smp_nrcpus();
 	int me = smp_processor_id();
+	u32 level;
 
 	/* Setup IPI */
 	leon_ipi_init();
@@ -167,6 +168,14 @@ void __init leon_boot_cpus(void)
 	       (unsigned int)nrcpu, (unsigned int)NR_CPUS,
 	       (unsigned int)&(leon3_irqctrl_regs->mpstatus));
 
+	/*
+	 * Cross-calls must reach a CPU even while it spins with PIL 15.
+	 * A lower-numbered IRQ in IRQMP's high priority group can otherwise
+	 * keep IRQ15 from reaching the CPU until that IRQ is serviced.
+	 */
+	level = LEON3_BYPASS_LOAD_PA(&leon3_irqctrl_regs->ilevel);
+	LEON3_BYPASS_STORE_PA(&leon3_irqctrl_regs->ilevel,
+			      level | BIT(LEON3_IRQ_CROSS_CALL));
 	leon_enable_irq_cpu(LEON3_IRQ_CROSS_CALL, me);
 	leon_enable_irq_cpu(LEON3_IRQ_TICKER, me);
 	leon_enable_irq_cpu(leon_ipi_irq, me);
-- 
2.43.0


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

* [PATCH 02/18] sparc32,leon: retain SMP TLB shootdowns
  2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 01/18] sparc32,leon: give the cross-call IRQ highest priority Magnus Lindholm
@ 2026-11-26  9:30 ` Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 03/18] sparc32,leon: publish instruction updates across CPUs Magnus Lindholm
                   ` (15 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7

LEON replaces the synchronous SMP TLB wrappers with local operations,
leaving remote translations stale after a mapping change. Keep the SMP
wrappers for LEON. On GR-LEON4-ITX, all 512 remapping reads were stale
without this change and all 512 were fresh with it.

leon_switch_mm() passed NULL to flush_tlb_mm(), which the SMP wrapper
would dereference. A context switch only needs a local flush, so call
leon_flush_tlb_all() directly.

This is based on "sparc32: retain mm_cpumask across TLB shootdowns" and
"sparc32: enroll and order CPUs before switching address spaces".

Fixes: 8401707ff645 ("sparc,leon: Sparc-Leon SMP support")
Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/sparc/mm/leon_mm.c | 3 ++-
 arch/sparc/mm/srmmu.c   | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/arch/sparc/mm/leon_mm.c b/arch/sparc/mm/leon_mm.c
index a43c5ffbbbe5..c19eb23b62e2 100644
--- a/arch/sparc/mm/leon_mm.c
+++ b/arch/sparc/mm/leon_mm.c
@@ -264,7 +264,8 @@ int __init leon_flush_needed(void)
 
 void leon_switch_mm(void)
 {
-	flush_tlb_mm((void *)0);
+	/* Context switches are local; mapping changes use the SMP wrappers. */
+	leon_flush_tlb_all();
 	if (leon_flush_during_switch)
 		leon_flush_cache_all();
 }
diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
index 145a63a5fda9..fb95865d7ddd 100644
--- a/arch/sparc/mm/srmmu.c
+++ b/arch/sparc/mm/srmmu.c
@@ -1746,7 +1746,8 @@ void __init load_mmu(void)
 	/* El switcheroo... */
 	local_ops = sparc32_cachetlb_ops;
 
-	if (sparc_cpu_model == sun4d || sparc_cpu_model == sparc_leon) {
+	/* sun4d supplies its own SMP TLB operations. */
+	if (sparc_cpu_model == sun4d) {
 		smp_cachetlb_ops.tlb_all = local_ops->tlb_all;
 		smp_cachetlb_ops.tlb_mm = local_ops->tlb_mm;
 		smp_cachetlb_ops.tlb_range = local_ops->tlb_range;
-- 
2.43.0


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

* [PATCH 03/18] sparc32,leon: publish instruction updates across CPUs
  2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 01/18] sparc32,leon: give the cross-call IRQ highest priority Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 02/18] sparc32,leon: retain SMP TLB shootdowns Magnus Lindholm
@ 2026-11-26  9:30 ` Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 04/18] sparc32,leon: avoid nested IRQ accounting in the timer handler Magnus Lindholm
                   ` (14 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7

flush_icache_range() is a no-op on sparc32, so another LEON CPU can
execute old instructions after code is rewritten at an existing mapping.
The LEON4 data cache snoops bus writes (GRIP 104.3.8); publishing code
also requires invalidating the other CPU's instruction cache.

Flush locally and through a synchronous cross-call with preemption
disabled. Keep empty ranges and non-LEON systems as runtime no-ops;
generic SPARC32 kernels can detect LEON without CONFIG_SPARC_LEON.
This covers in-place code updates. The module loader already flushes
caches when creating mappings for module text.

Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/sparc/include/asm/cacheflush_32.h |  2 +-
 arch/sparc/mm/srmmu.c                  | 14 ++++++++++++++
 2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/arch/sparc/include/asm/cacheflush_32.h b/arch/sparc/include/asm/cacheflush_32.h
index 9fee0ccfccb8..4249663efacc 100644
--- a/arch/sparc/include/asm/cacheflush_32.h
+++ b/arch/sparc/include/asm/cacheflush_32.h
@@ -15,7 +15,7 @@
 	sparc32_cachetlb_ops->cache_range(vma, start, end)
 #define flush_cache_page(vma,addr,pfn) \
 	sparc32_cachetlb_ops->cache_page(vma, addr)
-#define flush_icache_range(start, end)		do { } while (0)
+void flush_icache_range(unsigned long start, unsigned long end);
 
 #define copy_to_user_page(vma, page, vaddr, dst, src, len) \
 	do {							\
diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
index fb95865d7ddd..d2963fab829c 100644
--- a/arch/sparc/mm/srmmu.c
+++ b/arch/sparc/mm/srmmu.c
@@ -1736,6 +1736,20 @@ static struct sparc32_cachetlb_ops smp_cachetlb_ops __ro_after_init = {
 };
 #endif
 
+void flush_icache_range(unsigned long start, unsigned long end)
+{
+	if (start >= end || sparc_cpu_model != sparc_leon)
+		return;
+
+	preempt_disable();
+	leon_flush_cache_all();
+#ifdef CONFIG_SMP
+	xc0(leon_flush_cache_all);
+#endif
+	preempt_enable();
+}
+EXPORT_SYMBOL(flush_icache_range);
+
 /* Load up routines and constants for sun4m and sun4d mmu */
 void __init load_mmu(void)
 {
-- 
2.43.0


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

* [PATCH 04/18] sparc32,leon: avoid nested IRQ accounting in the timer handler
  2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
                   ` (2 preceding siblings ...)
  2026-11-26  9:30 ` [PATCH 03/18] sparc32,leon: publish instruction updates across CPUs Magnus Lindholm
@ 2026-11-26  9:30 ` Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 05/18] sparc32: preserve both LEON PROM character-output conventions Magnus Lindholm
                   ` (13 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7, stable

handler_irq() enters hardirq context before genirq dispatches the LEON
per-CPU timer. Entering it a second time around the clockevent makes
account_process_tick() charge idle, system and softirq ticks to hardirq
time. As a result, htop shows idle CPUs as busy.

Remove the inner irq_enter()/irq_exit() pair. Commit 2cf9530420e4
("sparc32,leon: per-cpu ticker use genirq per-cpu handler") removed
it when LEON switched to genirq. The clockevent conversion restored
it. The sun4m and sun4d tickers enter through dedicated traps and
still need their own pair.

Fixes: 62f082830d63 ("sparc32: generic clockevent support")
Cc: stable@vger.kernel.org
Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/sparc/kernel/leon_kernel.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/arch/sparc/kernel/leon_kernel.c b/arch/sparc/kernel/leon_kernel.c
index a43cf794bb1e..e560f0237165 100644
--- a/arch/sparc/kernel/leon_kernel.c
+++ b/arch/sparc/kernel/leon_kernel.c
@@ -289,10 +289,8 @@ static irqreturn_t leon_percpu_timer_ce_interrupt(int irq, void *unused)
 
 	ce = &per_cpu(sparc32_clockevent, cpu);
 
-	irq_enter();
 	if (ce->event_handler)
 		ce->event_handler(ce);
-	irq_exit();
 
 	return IRQ_HANDLED;
 }
-- 
2.43.0


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

* [PATCH 05/18] sparc32: preserve both LEON PROM character-output conventions
  2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
                   ` (3 preceding siblings ...)
  2026-11-26  9:30 ` [PATCH 04/18] sparc32,leon: avoid nested IRQ accounting in the timer handler Magnus Lindholm
@ 2026-11-26  9:30 ` Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 06/18] sparc32: tolerate firmware nodes without a name property Magnus Lindholm
                   ` (12 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7, stable

Factory GR-LEON4-ITX U-Boot returns zero after character output, while
modern MKLINUXIMG returns zero when busy and one after transmission.
Recognize the legacy PROM before printing and adapt only its zero-success
callback. Match the exact legacy properties and accept its getprop()
success value of one; preserve other firmware conventions.

Fixes: 154337688bfa ("sparc: prom: Sanitize return value from prom_nbputchar()")
Cc: stable@vger.kernel.org
Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/sparc/include/asm/oplib_32.h |  2 ++
 arch/sparc/prom/console_32.c      |  5 +++--
 arch/sparc/prom/init_32.c         | 23 +++++++++++++++++++++++
 3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/arch/sparc/include/asm/oplib_32.h b/arch/sparc/include/asm/oplib_32.h
index d1cf3a27a40d..5f009615cecf 100644
--- a/arch/sparc/include/asm/oplib_32.h
+++ b/arch/sparc/include/asm/oplib_32.h
@@ -25,6 +25,8 @@ enum prom_major_version {
 };
 
 extern enum prom_major_version prom_vers;
+/* Old LEON U-Boot uses a blocking, zero-success V0 putchar. */
+extern bool prom_leon_legacy;
 /* Revision, and firmware revision. */
 extern unsigned int prom_rev, prom_prev;
 
diff --git a/arch/sparc/prom/console_32.c b/arch/sparc/prom/console_32.c
index 6404e5bbb7e6..8615005ca67f 100644
--- a/arch/sparc/prom/console_32.c
+++ b/arch/sparc/prom/console_32.c
@@ -22,12 +22,13 @@ extern void restore_current(void);
 static int prom_nbputchar(const char *buf)
 {
 	unsigned long flags;
-	int i = -1;
+	int i = -1, ret;
 
 	spin_lock_irqsave(&prom_lock, flags);
 	switch(prom_vers) {
 	case PROM_V0:
-		if ((*(romvec->pv_nbputchar))(*buf))
+		ret = romvec->pv_nbputchar(*buf);
+		if (prom_leon_legacy ? ret == 0 : ret)
 			i = 1;
 		break;
 	case PROM_V2:
diff --git a/arch/sparc/prom/init_32.c b/arch/sparc/prom/init_32.c
index d20470166cb1..d36fa4e7207a 100644
--- a/arch/sparc/prom/init_32.c
+++ b/arch/sparc/prom/init_32.c
@@ -10,6 +10,7 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/module.h>
+#include <linux/string.h>
 
 #include <asm/openprom.h>
 #include <asm/oplib.h>
@@ -19,6 +20,7 @@ EXPORT_SYMBOL(romvec);
 
 enum prom_major_version prom_vers;
 unsigned int prom_rev, prom_prev;
+bool prom_leon_legacy __ro_after_init;
 
 /* The root node of the prom device tree. */
 phandle prom_root_node;
@@ -27,6 +29,25 @@ EXPORT_SYMBOL(prom_root_node);
 /* Pointer to the device tree operations structure. */
 struct linux_nodeops *prom_nodeops;
 
+/* Identify the old U-Boot PROM before any library routine can print. */
+static void __init prom_check_legacy_leon(void)
+{
+	char compat[5] = { };
+
+	if (!IS_ENABLED(CONFIG_SPARC_LEON) || prom_vers != PROM_V0 ||
+	    romvec->pv_stdin || romvec->pv_stdout)
+		return;
+	if (prom_getproplen(prom_root_node, "compatible") >= 0)
+		return;
+	/* Old U-Boot's getprop returns one on success, not the byte count. */
+	if (prom_getproplen(prom_root_node, "compatability") != sizeof(compat))
+		return;
+	if (prom_getproperty(prom_root_node, "compatability", compat,
+			     sizeof(compat)) > 0 &&
+	    !memcmp(compat, "leon2", sizeof(compat)))
+		prom_leon_legacy = true;
+}
+
 /* You must call prom_init() before you attempt to use any of the
  * routines in the prom library.
  * It gets passed the pointer to the PROM vector.
@@ -65,6 +86,8 @@ void __init prom_init(struct linux_romvec *rp)
 	   (((unsigned long) prom_nodeops) == -1))
 		prom_halt();
 
+	prom_check_legacy_leon();
+
 	prom_meminit();
 
 	prom_ranges_init();
-- 
2.43.0


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

* [PATCH 06/18] sparc32: tolerate firmware nodes without a name property
  2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
                   ` (4 preceding siblings ...)
  2026-11-26  9:30 ` [PATCH 05/18] sparc32: preserve both LEON PROM character-output conventions Magnus Lindholm
@ 2026-11-26  9:30 ` Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 07/18] sparc32: skip unavailable PROM V0 console metadata Magnus Lindholm
                   ` (11 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7

Factory LEON U-Boot omits device-tree name properties, causing
build_path_component() to dereference NULL. Use an empty root component
and phandle-based child names when the property is absent.

Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/sparc/kernel/prom_32.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/arch/sparc/kernel/prom_32.c b/arch/sparc/kernel/prom_32.c
index cd94f1e8d644..804ca0b2a5b5 100644
--- a/arch/sparc/kernel/prom_32.c
+++ b/arch/sparc/kernel/prom_32.c
@@ -189,11 +189,21 @@ char * __init build_path_component(struct device_node *dp)
 	char tmp_buf[64], *n;
 	size_t n_sz;
 
+	/* Old LEON firmware omits the root name; handle unnamed children too. */
+	if (!name) {
+		if (dp->parent)
+			snprintf(tmp_buf, sizeof(tmp_buf), "node@%x", dp->phandle);
+		else
+			tmp_buf[0] = '\0';
+		goto alloc_name;
+	}
+
 	tmp_buf[0] = '\0';
 	__build_path_component(dp, tmp_buf);
 	if (tmp_buf[0] == '\0')
 		strscpy(tmp_buf, name);
 
+alloc_name:
 	n_sz = strlen(tmp_buf) + 1;
 	n = prom_early_alloc(n_sz);
 	strscpy(n, tmp_buf, n_sz);
-- 
2.43.0


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

* [PATCH 07/18] sparc32: skip unavailable PROM V0 console metadata
  2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
                   ` (5 preceding siblings ...)
  2026-11-26  9:30 ` [PATCH 06/18] sparc32: tolerate firmware nodes without a name property Magnus Lindholm
@ 2026-11-26  9:30 ` Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 08/18] sparc32,leon: identify LEON before the firmware model lookup Magnus Lindholm
                   ` (10 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7

The factory LEON PROM has a character callback but no pv_stdout.
Skip V0 console discovery when that pointer is absent, leaving explicit
kernel console selection and other PROM versions unchanged.

Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/sparc/kernel/prom_32.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/arch/sparc/kernel/prom_32.c b/arch/sparc/kernel/prom_32.c
index 804ca0b2a5b5..29da4e682acc 100644
--- a/arch/sparc/kernel/prom_32.c
+++ b/arch/sparc/kernel/prom_32.c
@@ -223,6 +223,12 @@ void __init of_console_init(void)
 	phandle node;
 	int skip, tmp, fd;
 
+	/* Legacy LEON PROMs provide output callbacks but no console metadata. */
+	if (prom_vers == PROM_V0 && !romvec->pv_stdout) {
+		pr_info("OF stdout unavailable; using kernel console selection\n");
+		return;
+	}
+
 	of_console_path = prom_early_alloc(of_console_path_sz);
 
 	switch (prom_vers) {
-- 
2.43.0


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

* [PATCH 08/18] sparc32,leon: identify LEON before the firmware model lookup
  2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
                   ` (6 preceding siblings ...)
  2026-11-26  9:30 ` [PATCH 07/18] sparc32: skip unavailable PROM V0 console metadata Magnus Lindholm
@ 2026-11-26  9:30 ` Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 09/18] sparc32,leon: preserve the Linux IRQ14 vector during startup Magnus Lindholm
                   ` (9 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7

The legacy firmware lacks the compatible property expected by startup,
so LEON is misidentified as sun4m. With LEON support enabled, identify
PSR implementation 0xf before the firmware lookup and enter leon_init.

Fixes: 1ddb22e13dea ("sparc32,leon: fix leon bootup")
Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/sparc/kernel/head_32.S | 29 +++++++++++++++++++++++++----
 1 file changed, 25 insertions(+), 4 deletions(-)

diff --git a/arch/sparc/kernel/head_32.S b/arch/sparc/kernel/head_32.S
index 11a1746829a4..97000e9dffd6 100644
--- a/arch/sparc/kernel/head_32.S
+++ b/arch/sparc/kernel/head_32.S
@@ -27,6 +27,13 @@
 #include <asm/errno.h>
 #include <asm/pgtable.h>	/* PGDIR_SHIFT */
 
+	.macro leon_psr_compare reg
+	rd	%psr, \reg
+	srl	\reg, PSR_IMPL_SHIFT, \reg
+	and	\reg, PSR_IMPL_SHIFTED_MASK, \reg
+	cmp	\reg, PSR_IMPL_LEON
+	.endm
+
 	.data
 /* The following are used with the prom_vector node-ops to figure out
  * the cpu-type
@@ -205,10 +212,7 @@ not_a_sun4:
 		 */
 
 		/* Check if this is a LEON CPU */
-		rd	%psr, %g3
-		srl	%g3, PSR_IMPL_SHIFT, %g3
-		and	%g3, PSR_IMPL_SHIFTED_MASK, %g3
-		cmp	%g3, PSR_IMPL_LEON
+		leon_psr_compare %g3
 		be	leon_remap		/* It is a LEON - jump */
 		 nop
 
@@ -366,6 +370,23 @@ execute_in_high_mem:
 		sethi	%hi(linux_dbvec), %g1
 		st	%o1, [%g1 + %lo(linux_dbvec)]
 
+#ifdef CONFIG_SPARC_LEON
+		/* Old LEON U-Boot uses "compatability", not "compatible".
+		 * Identify the CPU before choosing platform initialization,
+		 * and publish the same model for sparc32_start_kernel().
+		 */
+		leon_psr_compare %g3
+		bne	.Lprom_machine_type
+		 nop
+		set	cputypval, %o2
+		set	0x6c656f6e, %g3		! "leon"
+		st	%g3, [%o2]
+		stb	%g0, [%o2 + 4]
+		ba	leon_init
+		 nop
+.Lprom_machine_type:
+#endif /* CONFIG_SPARC_LEON */
+
 		/* Get the machine type via the romvec
 		 * getprops node operation
 		 */
-- 
2.43.0


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

* [PATCH 09/18] sparc32,leon: preserve the Linux IRQ14 vector during startup
  2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
                   ` (7 preceding siblings ...)
  2026-11-26  9:30 ` [PATCH 08/18] sparc32,leon: identify LEON before the firmware model lookup Magnus Lindholm
@ 2026-11-26  9:30 ` Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 10/18] sparc32,leon: use ASI 1 for locks on the GR-LEON4-ITX Magnus Lindholm
                   ` (8 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7

When LEON uses IRQ14 for IPIs, copying the firmware IRQ14 handler
overwrites Linux's IPI vector, including during secondary CPU startup.
Firmware supplies the IPI level through ipi_num. Legacy AMBA discovery
selects the highest free level below 15, IRQ14 on GR-LEON4-ITX.

Skip the firmware save/copy on every LEON CPU, preserving the linked
and patched Linux vector. Preserve the firmware-vector handling used
by other SPARC implementations.

Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/sparc/kernel/head_32.S | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/arch/sparc/kernel/head_32.S b/arch/sparc/kernel/head_32.S
index 97000e9dffd6..6547717aac20 100644
--- a/arch/sparc/kernel/head_32.S
+++ b/arch/sparc/kernel/head_32.S
@@ -148,6 +148,15 @@ already_mapped:
 
 		/* Copy over the Prom's level 14 clock handler. */
 copy_prom_lvl14:
+#ifdef CONFIG_SPARC_LEON
+		/* LEON uses the Linux IRQ14 vector, potentially for IPIs.
+		 * Secondary CPUs also pass here and share the trap table,
+		 * so never replace its vector with the firmware's handler.
+		 */
+		leon_psr_compare %g3
+		be	copy_prom_done
+		 nop
+#endif
 #if 1
 		/* DJHR
 		 * preserve our linked/calculated instructions
-- 
2.43.0


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

* [PATCH 10/18] sparc32,leon: use ASI 1 for locks on the GR-LEON4-ITX
  2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
                   ` (8 preceding siblings ...)
  2026-11-26  9:30 ` [PATCH 09/18] sparc32,leon: preserve the Linux IRQ14 vector during startup Magnus Lindholm
@ 2026-11-26  9:30 ` Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 11/18] sparc32,leon: restore the kernel header offsets used by U-Boot Magnus Lindholm
                   ` (7 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7

Cached LDSTUB lock acquisitions stall on the dual-CPU GR-LEON4-ITX.
The same tests complete with LDSTUBA ASI 1. The cause and the range of
affected CPUs are unknown. LEON SMP already uses SWAPA with ASI 1 for
the secondary CPU handshake.

Match the full GRLIB system ID (0x01020db4) of the ASIC fitted to the
GR-LEON4-ITX. Read it from the AMBA firmware node or, on factory U-Boot,
from AHB plug-and-play. Use the saved match for kernel and module locks.
Userspace retains its LDSTUB and SWAP instructions. The SWAP in
srmmu_swap() operates on uncached LEON page tables.

Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/sparc/include/asm/ldstub.h      | 46 +++++++++++++++++++++++
 arch/sparc/include/asm/leon.h        |  1 +
 arch/sparc/include/asm/leon_amba.h   |  2 +
 arch/sparc/include/asm/sections.h    |  2 +
 arch/sparc/include/asm/spinlock_32.h | 32 +++++++++++-----
 arch/sparc/kernel/module.c           | 25 +++++++++++++
 arch/sparc/kernel/setup_32.c         | 55 ++++++++++++++++++++--------
 arch/sparc/kernel/vmlinux.lds.S      |  5 +++
 arch/sparc/lib/locks.S               | 24 +++++++++---
 9 files changed, 162 insertions(+), 30 deletions(-)
 create mode 100644 arch/sparc/include/asm/ldstub.h

diff --git a/arch/sparc/include/asm/ldstub.h b/arch/sparc/include/asm/ldstub.h
new file mode 100644
index 000000000000..f5d95deaf4cf
--- /dev/null
+++ b/arch/sparc/include/asm/ldstub.h
@@ -0,0 +1,46 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Written by Magnus Lindholm, linmag7@gmail.com
+ *
+ * Use ASI 1 to avoid stalled lock acquisitions on the GR-LEON4-ITX.
+ */
+
+#ifndef _SPARC_LDSTUB_H
+#define _SPARC_LDSTUB_H
+
+#include <linux/stringify.h>
+#include <asm/asi.h>
+
+/*
+ * Emit LDSTUB at each lock site. On the GR-LEON4-ITX, early boot and the
+ * module loader replace it with the corresponding LDSTUBA ASI 1.
+ * The address must use registers only: alternate-space loads have no simm13.
+ */
+#if defined(CONFIG_SPARC_LEON) && defined(CONFIG_SMP)
+#define SPARC_RWLOCK_SETUP "mov 3, %%g5\n\t"
+#define SPARC_RWLOCK_ADDR "%%g1 + %%g5"
+#define SPARC_RWLOCK_CLOBBER "g5",
+#define SPARC_LDSTUB(addr, reg)				\
+	"663: ldstub [" addr "], " reg "\n\t"		\
+	".pushsection .leon_ldstub_patch, \"ax\"\n\t"	\
+	".align 4\n\t"					\
+	".word 663b\n\t"					\
+	"ldstuba [" addr "] " __stringify(ASI_LEON_DCACHE_MISS) \
+	", " reg "\n\t"					\
+	".popsection\n\t"
+#else
+#define SPARC_RWLOCK_SETUP ""
+#define SPARC_RWLOCK_ADDR "%%g1 + 3"
+#define SPARC_RWLOCK_CLOBBER
+#define SPARC_LDSTUB(addr, reg) "ldstub [" addr "], " reg "\n\t"
+#endif
+
+struct leon_1insn_patch_entry {
+	unsigned int addr;
+	unsigned int insn;
+};
+
+void leon_patch_1insn_range(struct leon_1insn_patch_entry *start,
+			    struct leon_1insn_patch_entry *end);
+
+#endif /* _SPARC_LDSTUB_H */
diff --git a/arch/sparc/include/asm/leon.h b/arch/sparc/include/asm/leon.h
index 2a1bdc2c2f1d..67f2822d5fc6 100644
--- a/arch/sparc/include/asm/leon.h
+++ b/arch/sparc/include/asm/leon.h
@@ -224,6 +224,7 @@ unsigned int leon_build_device_irq(unsigned int real_irq,
 void leon_update_virq_handling(unsigned int virq,
 			       irq_flow_handler_t flow_handler,
 			       const char *name, int do_ack);
+extern bool leon_gr_leon4_itx;
 void leon_init_timers(void);
 void leon_node_init(struct device_node *dp, struct device_node ***nextp);
 void init_leon(void);
diff --git a/arch/sparc/include/asm/leon_amba.h b/arch/sparc/include/asm/leon_amba.h
index 2ff5714d7a63..6663f8afa098 100644
--- a/arch/sparc/include/asm/leon_amba.h
+++ b/arch/sparc/include/asm/leon_amba.h
@@ -193,6 +193,8 @@ extern unsigned int sparc_leon_eirq;
 
 #define LEON3_IO_AREA 0xfff00000
 #define LEON3_CONF_AREA 0xff000
+#define LEON3_AHB_SYSTEMID 0xff0
+#define GR_LEON4_ITX_SYSTEMID 0x01020db4
 #define LEON3_AHB_SLAVE_CONF_AREA (1 << 11)
 
 #define LEON3_AHB_CONF_WORDS 8
diff --git a/arch/sparc/include/asm/sections.h b/arch/sparc/include/asm/sections.h
index 08f833453ab3..675745aa5d42 100644
--- a/arch/sparc/include/asm/sections.h
+++ b/arch/sparc/include/asm/sections.h
@@ -10,5 +10,7 @@ extern char _start[];
 
 extern char __leon_1insn_patch[];
 extern char __leon_1insn_patch_end[];
+extern char __leon_ldstub_patch[];
+extern char __leon_ldstub_patch_end[];
 
 #endif
diff --git a/arch/sparc/include/asm/spinlock_32.h b/arch/sparc/include/asm/spinlock_32.h
index 6d6d261bf8d2..a467bbff0bef 100644
--- a/arch/sparc/include/asm/spinlock_32.h
+++ b/arch/sparc/include/asm/spinlock_32.h
@@ -10,6 +10,7 @@
 #ifndef __ASSEMBLER__
 
 #include <asm/psr.h>
+#include <asm/ldstub.h>
 #include <asm/barrier.h>
 #include <asm/processor.h> /* for cpu_relax */
 
@@ -19,7 +20,7 @@ static inline void arch_spin_lock(arch_spinlock_t *lock)
 {
 	__asm__ __volatile__(
 	"\n1:\n\t"
-	"ldstub	[%0], %%g2\n\t"
+	SPARC_LDSTUB("%0", "%%g2")
 	"orcc	%%g2, 0x0, %%g0\n\t"
 	"bne,a	2f\n\t"
 	" ldub	[%0], %%g2\n\t"
@@ -38,7 +39,7 @@ static inline void arch_spin_lock(arch_spinlock_t *lock)
 static inline int arch_spin_trylock(arch_spinlock_t *lock)
 {
 	unsigned int result;
-	__asm__ __volatile__("ldstub [%1], %0"
+	__asm__ __volatile__(SPARC_LDSTUB("%1", "%0")
 			     : "=r" (result)
 			     : "r" (lock)
 			     : "memory");
@@ -82,11 +83,12 @@ static inline void __arch_read_lock(arch_rwlock_t *rw)
 	lp = rw;
 	__asm__ __volatile__(
 	"mov	%%o7, %%g4\n\t"
+	SPARC_RWLOCK_SETUP
 	"call	___rw_read_enter\n\t"
-	" ldstub	[%%g1 + 3], %%g2\n"
+	SPARC_LDSTUB(SPARC_RWLOCK_ADDR, "%%g2")
 	: /* no outputs */
 	: "r" (lp)
-	: "g2", "g4", "memory", "cc");
+	: "g2", "g4", SPARC_RWLOCK_CLOBBER "memory", "cc");
 }
 
 #define arch_read_lock(lock) \
@@ -102,11 +104,12 @@ static inline void __arch_read_unlock(arch_rwlock_t *rw)
 	lp = rw;
 	__asm__ __volatile__(
 	"mov	%%o7, %%g4\n\t"
+	SPARC_RWLOCK_SETUP
 	"call	___rw_read_exit\n\t"
-	" ldstub	[%%g1 + 3], %%g2\n"
+	SPARC_LDSTUB(SPARC_RWLOCK_ADDR, "%%g2")
 	: /* no outputs */
 	: "r" (lp)
-	: "g2", "g4", "memory", "cc");
+	: "g2", "g4", SPARC_RWLOCK_CLOBBER "memory", "cc");
 }
 
 #define arch_read_unlock(lock) \
@@ -122,11 +125,12 @@ static inline void arch_write_lock(arch_rwlock_t *rw)
 	lp = rw;
 	__asm__ __volatile__(
 	"mov	%%o7, %%g4\n\t"
+	SPARC_RWLOCK_SETUP
 	"call	___rw_write_enter\n\t"
-	" ldstub	[%%g1 + 3], %%g2\n"
+	SPARC_LDSTUB(SPARC_RWLOCK_ADDR, "%%g2")
 	: /* no outputs */
 	: "r" (lp)
-	: "g2", "g4", "memory", "cc");
+	: "g2", "g4", SPARC_RWLOCK_CLOBBER "memory", "cc");
 	*(volatile __u32 *)&lp->lock = ~0U;
 }
 
@@ -143,10 +147,17 @@ static inline int arch_write_trylock(arch_rwlock_t *rw)
 {
 	unsigned int val;
 
+#if defined(CONFIG_SPARC_LEON) && defined(CONFIG_SMP)
+	__asm__ __volatile__(SPARC_LDSTUB("%1", "%0")
+			     : "=r" (val)
+			     : "r" ((unsigned char *)&rw->lock + 3)
+			     : "memory");
+#else
 	__asm__ __volatile__("ldstub [%1 + 3], %0"
 			     : "=r" (val)
 			     : "r" (&rw->lock)
 			     : "memory");
+#endif
 
 	if (val == 0) {
 		val = rw->lock & ~0xff;
@@ -166,11 +177,12 @@ static inline int __arch_read_trylock(arch_rwlock_t *rw)
 	lp = rw;
 	__asm__ __volatile__(
 	"mov	%%o7, %%g4\n\t"
+	SPARC_RWLOCK_SETUP
 	"call	___rw_read_try\n\t"
-	" ldstub	[%%g1 + 3], %%g2\n"
+	SPARC_LDSTUB(SPARC_RWLOCK_ADDR, "%%g2")
 	: "=r" (res)
 	: "r" (lp)
-	: "g2", "g4", "memory", "cc");
+	: "g2", "g4", SPARC_RWLOCK_CLOBBER "memory", "cc");
 	return res;
 }
 
diff --git a/arch/sparc/kernel/module.c b/arch/sparc/kernel/module.c
index 2a8770369beb..9fa8b346416d 100644
--- a/arch/sparc/kernel/module.c
+++ b/arch/sparc/kernel/module.c
@@ -19,6 +19,11 @@
 #include <asm/spitfire.h>
 #include <asm/cacheflush.h>
 
+#ifdef CONFIG_SPARC32
+#include <asm/leon.h>
+#include <asm/ldstub.h>
+#endif
+
 #include "entry.h"
 
 /* Make generic code ignore STT_REGISTER dummy undefined symbols.  */
@@ -191,4 +196,24 @@ int module_finalize(const Elf_Ehdr *hdr,
 
 	return 0;
 }
+#else /* CONFIG_SPARC32 */
+int module_finalize(const Elf_Ehdr *hdr, const Elf_Shdr *sechdrs,
+		    struct module *me)
+{
+	const Elf_Shdr *s;
+	const char *secstrings = (void *)hdr + sechdrs[hdr->e_shstrndx].sh_offset;
+
+	if (!IS_ENABLED(CONFIG_SPARC_LEON) || !IS_ENABLED(CONFIG_SMP) ||
+	    !leon_gr_leon4_itx)
+		return 0;
+
+	for (s = sechdrs; s < sechdrs + hdr->e_shnum; s++) {
+		if (!strcmp(".leon_ldstub_patch", secstrings + s->sh_name)) {
+			void *p = (void *)s->sh_addr;
+
+			leon_patch_1insn_range(p, p + s->sh_size);
+		}
+	}
+	return 0;
+}
 #endif /* CONFIG_SPARC64 */
diff --git a/arch/sparc/kernel/setup_32.c b/arch/sparc/kernel/setup_32.c
index 246533fba60d..c84ac2f1ad15 100644
--- a/arch/sparc/kernel/setup_32.c
+++ b/arch/sparc/kernel/setup_32.c
@@ -48,6 +48,9 @@
 #include <asm/setup.h>
 #include <asm/cacheflush.h>
 #include <asm/sections.h>
+#include <asm/ldstub.h>
+#include <asm/leon.h>
+#include <asm/leon_amba.h>
 
 #include "kernel.h"
 
@@ -226,33 +229,55 @@ static void __init per_cpu_patch(void)
 	}
 }
 
-struct leon_1insn_patch_entry {
-	unsigned int addr;
-	unsigned int insn;
-};
-
 enum sparc_cpu sparc_cpu_model;
 EXPORT_SYMBOL(sparc_cpu_model);
 
-static __init void leon_patch(void)
+void leon_patch_1insn_range(struct leon_1insn_patch_entry *start,
+			    struct leon_1insn_patch_entry *end)
 {
-	struct leon_1insn_patch_entry *start = (void *)__leon_1insn_patch;
-	struct leon_1insn_patch_entry *end = (void *)__leon_1insn_patch_end;
-
-	/* Default instruction is leon - no patching */
-	if (sparc_cpu_model == sparc_leon)
-		return;
-
 	while (start < end) {
 		unsigned long addr = start->addr;
 
-		*(unsigned int *)(addr) = start->insn;
+		*(unsigned int *)addr = start->insn;
 		flushi(addr);
-
 		start++;
 	}
 }
 
+bool leon_gr_leon4_itx __ro_after_init;
+
+static bool __init leon_detect_itx(void)
+{
+	phandle bus;
+	u32 id = 0;
+
+	if (prom_leon_legacy) {
+		/* The factory PROM omits the AMBA bus from its device tree. */
+		id = LEON3_BYPASS_LOAD_PA(LEON3_IO_AREA | LEON3_CONF_AREA |
+					  LEON3_AHB_SYSTEMID);
+	} else {
+		bus = prom_finddevice("/ambapp0");
+		if (!bus || prom_getproplen(bus, "systemid") != sizeof(id) ||
+		    prom_getproperty(bus, "systemid", (char *)&id, sizeof(id)) < 0)
+			return false;
+	}
+	return id == GR_LEON4_ITX_SYSTEMID;
+}
+
+static __init void leon_patch(void)
+{
+	if (sparc_cpu_model == sparc_leon) {
+		if (IS_ENABLED(CONFIG_SPARC_LEON))
+			leon_gr_leon4_itx = leon_detect_itx();
+		if (IS_ENABLED(CONFIG_SMP) && leon_gr_leon4_itx)
+			leon_patch_1insn_range((void *)__leon_ldstub_patch,
+					       (void *)__leon_ldstub_patch_end);
+	} else {
+		leon_patch_1insn_range((void *)__leon_1insn_patch,
+				       (void *)__leon_1insn_patch_end);
+	}
+}
+
 struct tt_entry *sparc_ttable;
 
 unsigned long phys_base;
diff --git a/arch/sparc/kernel/vmlinux.lds.S b/arch/sparc/kernel/vmlinux.lds.S
index 7ea510d9b42f..da93457c45f3 100644
--- a/arch/sparc/kernel/vmlinux.lds.S
+++ b/arch/sparc/kernel/vmlinux.lds.S
@@ -123,6 +123,11 @@ SECTIONS
 		*(.leon_1insn_patch)
 		__leon_1insn_patch_end = .;
 	}
+	.leon_ldstub_patch : {
+		__leon_ldstub_patch = .;
+		*(.leon_ldstub_patch)
+		__leon_ldstub_patch_end = .;
+	}
 	.swapper_tsb_phys_patch : {
 		__swapper_tsb_phys_patch = .;
 		*(.swapper_tsb_phys_patch)
diff --git a/arch/sparc/lib/locks.S b/arch/sparc/lib/locks.S
index 47a39f4384a2..d5d9d4c93af5 100644
--- a/arch/sparc/lib/locks.S
+++ b/arch/sparc/lib/locks.S
@@ -12,6 +12,7 @@
 #include <asm/psr.h>
 #include <asm/smp.h>
 #include <asm/spinlock.h>
+#include <asm/asi.h>
 
 	.text
 	.align	4
@@ -20,17 +21,30 @@
 	 * as fast as possible.
 	 */
 
-	/* caches... */
+	.macro	rw_ldstub
+#if defined(CONFIG_SPARC_LEON) && defined(CONFIG_SMP)
+	/* The inline caller supplies the writer-lock byte offset in %g5. */
+1:	ldstub	[%g1 + %g5], %g2
+	.pushsection .leon_ldstub_patch, "ax"
+	.align	4
+	.word	1b
+	ldstuba	[%g1 + %g5] ASI_LEON_DCACHE_MISS, %g2
+	.popsection
+#else
+	ldstub	[%g1 + 3], %g2
+#endif
+	.endm
+
 ___rw_read_enter_spin_on_wlock:
 	orcc	%g2, 0x0, %g0
 	be,a	___rw_read_enter
-	 ldstub	[%g1 + 3], %g2
+	 rw_ldstub
 	b	___rw_read_enter_spin_on_wlock
 	 ldub	[%g1 + 3], %g2
 ___rw_read_try_spin_on_wlock:
 	andcc	%g2, 0xff, %g0
 	be,a	___rw_read_try
-	 ldstub	[%g1 + 3], %g2
+	 rw_ldstub
 	xnorcc	%g2, 0x0, %o0	/* if g2 is ~0, set o0 to 0 and bugger off */
 	bne,a	___rw_read_enter_spin_on_wlock
 	 ld	[%g1], %g2
@@ -39,13 +53,13 @@ ___rw_read_try_spin_on_wlock:
 ___rw_read_exit_spin_on_wlock:
 	orcc	%g2, 0x0, %g0
 	be,a	___rw_read_exit
-	 ldstub	[%g1 + 3], %g2
+	 rw_ldstub
 	b	___rw_read_exit_spin_on_wlock
 	 ldub	[%g1 + 3], %g2
 ___rw_write_enter_spin_on_wlock:
 	orcc	%g2, 0x0, %g0
 	be,a	___rw_write_enter
-	 ldstub	[%g1 + 3], %g2
+	 rw_ldstub
 	b	___rw_write_enter_spin_on_wlock
 	 ld	[%g1], %g2
 
-- 
2.43.0


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

* [PATCH 11/18] sparc32,leon: restore the kernel header offsets used by U-Boot
  2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
                   ` (9 preceding siblings ...)
  2026-11-26  9:30 ` [PATCH 10/18] sparc32,leon: use ASI 1 for locks on the GR-LEON4-ITX Magnus Lindholm
@ 2026-11-26  9:30 ` Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 12/18] sparc32: recognize the legacy LEON firmware machine ID Magnus Lindholm
                   ` (6 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7

Factory GR-LEON4-ITX U-Boot checks for HdrS at 0x9000, then at 0xc000.
Reserve eight pages before HdrS in LEON-enabled kernels to restore the
UP and SMP offsets. This costs 32 KiB in the loaded image.

SILO, TILO and the kernel's piggyback tool can locate HdrS relative to
the branch to gokernel. The ELF entry point and header ABI stay the same.

Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/sparc/kernel/head_32.S | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/arch/sparc/kernel/head_32.S b/arch/sparc/kernel/head_32.S
index 6547717aac20..d36839ca1f03 100644
--- a/arch/sparc/kernel/head_32.S
+++ b/arch/sparc/kernel/head_32.S
@@ -64,6 +64,14 @@ sun4e_notsup:
 
 	.align PAGE_SIZE
 
+#ifdef CONFIG_SPARC_LEON
+/*
+ * Factory GR-LEON4-ITX U-Boot checks for HdrS at 0x9000 (UP), then at
+ * 0xc000 (SMP). Older kernels had eight pages before the header.
+ */
+	.skip 8 * PAGE_SIZE
+#endif
+
 	.global root_flags
 	.global ram_flags
 	.global root_dev
-- 
2.43.0


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

* [PATCH 12/18] sparc32: recognize the legacy LEON firmware machine ID
  2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
                   ` (10 preceding siblings ...)
  2026-11-26  9:30 ` [PATCH 11/18] sparc32,leon: restore the kernel header offsets used by U-Boot Magnus Lindholm
@ 2026-11-26  9:30 ` Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 13/18] sparc32,leon: discover AMBA devices for legacy U-Boot PROMs Magnus Lindholm
                   ` (5 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7

Factory GR-LEON4-ITX firmware reports IDPROM type 0x31. Recognize that
legacy LEON identifier in the machine-name table. This only corrects
the diagnostic; CPU identification and IDPROM contents are unchanged.

Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/sparc/include/asm/machines.h | 1 +
 arch/sparc/kernel/idprom.c        | 2 ++
 2 files changed, 3 insertions(+)

diff --git a/arch/sparc/include/asm/machines.h b/arch/sparc/include/asm/machines.h
index 9f78f70c6f11..ee79cc8e929c 100644
--- a/arch/sparc/include/asm/machines.h
+++ b/arch/sparc/include/asm/machines.h
@@ -32,6 +32,7 @@ struct Sun_Machine_Models {
 #define SM_TYP_MASK   0x0f
 
 /* Leon machines */
+#define M_LEON2_SOC   0x01    /* Legacy LEON firmware ID */
 #define M_LEON3_SOC   0x02    /* Leon3 SoC */
 
 /* Sun4m machines, these predate the OpenBoot.  These values only mean
diff --git a/arch/sparc/kernel/idprom.c b/arch/sparc/kernel/idprom.c
index d6c46d512220..8aba9b4d4498 100644
--- a/arch/sparc/kernel/idprom.c
+++ b/arch/sparc/kernel/idprom.c
@@ -29,6 +29,8 @@ static struct idprom idprom_buffer;
  */
 static struct Sun_Machine_Models Sun_Machines[] = {
 /* First, Leon */
+{ .name = "LEON system (legacy firmware ID)",
+	.id_machtype = (M_LEON | M_LEON2_SOC) },
 { .name = "Leon3 System-on-a-Chip",  .id_machtype = (M_LEON | M_LEON3_SOC) },
 /* Finally, early Sun4m's */
 { .name = "Sun4m SparcSystem600",    .id_machtype = (SM_SUN4M | SM_4M_SS60) },
-- 
2.43.0


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

* [PATCH 13/18] sparc32,leon: discover AMBA devices for legacy U-Boot PROMs
  2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
                   ` (11 preceding siblings ...)
  2026-11-26  9:30 ` [PATCH 12/18] sparc32: recognize the legacy LEON firmware machine ID Magnus Lindholm
@ 2026-11-26  9:30 ` Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 14/18] sparc32,leon: describe legacy AMBA I2C controllers Magnus Lindholm
                   ` (4 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7

Factory LEON U-Boot supplies no AMBA device nodes. For its legacy PROM
signature, discover GRLIB plug-and-play buses and synthesize the missing
nodes, resources and clocks with bounded traversal.

Publish the system ID needed by the existing LEON4 idle workaround.
Reserve a conflict-free IPI only for SMP. Preserve firmware-supplied
trees; reject unsupported required topology rather than continuing
without usable interrupt and timer controllers.

Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/sparc/kernel/Makefile      |   1 +
 arch/sparc/kernel/leon_legacy.c | 343 ++++++++++++++++++++++++++++++++
 arch/sparc/kernel/prom.h        |   5 +
 arch/sparc/kernel/prom_common.c |   1 +
 drivers/of/pdt.c                |   9 +-
 include/linux/of_pdt.h          |   5 +
 6 files changed, 362 insertions(+), 2 deletions(-)
 create mode 100644 arch/sparc/kernel/leon_legacy.c

diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
index 497b5714fa8f..6bfc23ce3b08 100644
--- a/arch/sparc/kernel/Makefile
+++ b/arch/sparc/kernel/Makefile
@@ -53,6 +53,7 @@ obj-$(CONFIG_SPARC64)   += prom_irqtrans.o
 
 obj-$(CONFIG_SPARC32)   += leon_kernel.o
 obj-$(CONFIG_SPARC32)   += leon_pmc.o
+obj-$(CONFIG_SPARC_LEON) += leon_legacy.o
 
 obj-$(CONFIG_SPARC64)   += reboot.o
 obj-$(CONFIG_SPARC64)   += sysfs.o
diff --git a/arch/sparc/kernel/leon_legacy.c b/arch/sparc/kernel/leon_legacy.c
new file mode 100644
index 000000000000..a9364708e231
--- /dev/null
+++ b/arch/sparc/kernel/leon_legacy.c
@@ -0,0 +1,343 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Written by Magnus Lindholm, linmag7@gmail.com
+ *
+ * Build the AMBA device tree omitted by the factory LEON U-Boot.
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/of.h>
+#include <linux/of_pdt.h>
+#include <linux/string.h>
+
+#include <asm/leon.h>
+#include <asm/leon_amba.h>
+#include <asm/oplib.h>
+#include <asm/cpu_type.h>
+
+#include "prom.h"
+
+#define LEGACY_MAX_BUSES 8
+#define LEGACY_AHB_SLOTS 64
+#define LEGACY_APB_SLOTS 16
+
+struct legacy_bus {
+	u32 area;
+	u32 freq;
+	u32 bridge;
+	unsigned int parent;
+};
+
+static struct legacy_bus legacy_buses[LEGACY_MAX_BUSES] __initdata;
+static unsigned int legacy_bus_count __initdata;
+static phandle legacy_phandle __initdata;
+static u32 legacy_irqs __initdata = BIT(0) | BIT(15);
+
+static u32 __init legacy_read(u32 address)
+{
+	return LEON3_BYPASS_LOAD_PA(address);
+}
+
+static bool __init legacy_is(u32 id, unsigned int device)
+{
+	return (id >> 24) == VENDOR_GAISLER &&
+	       ((id >> 12) & 0xfff) == device;
+}
+
+/* GRLIB AHB memory and bus-relative AHB I/O BAR encodings. */
+static bool __init legacy_bar(u32 area, u32 bar, u32 *addr, u32 *size)
+{
+	u32 mask = (bar >> 4) & 0xfff;
+	u32 start = (bar & 0xfff00000) & (mask << 20);
+
+	switch (bar & 0xf) {
+	case 2:
+		*addr = start;
+		*size = -(mask << 20);
+		break;
+	case 3:
+		*addr = area | (start >> 12);
+		*size = ((~mask & 0xfff) + 1) << 8;
+		break;
+	default:
+		return false;
+	}
+	return *size && is_power_of_2(*size);
+}
+
+static void __init legacy_property(struct device_node *np, const char *name,
+				   const void *value, unsigned int length)
+{
+	struct property *p = prom_early_alloc(sizeof(*p));
+
+	p->name = prom_early_alloc(strlen(name) + 1);
+	strscpy(p->name, name, strlen(name) + 1);
+	p->value = prom_early_alloc(length + 1);
+	memcpy(p->value, value, length);
+	p->length = length;
+	p->unique_id = of_pdt_alloc_unique_id();
+	p->next = np->properties;
+	np->properties = p;
+}
+
+static void __init legacy_u32(struct device_node *np, const char *name, u32 val)
+{
+	__be32 cell = cpu_to_be32(val);
+
+	legacy_property(np, name, &cell, sizeof(cell));
+}
+
+static struct device_node * __init legacy_node(struct device_node *parent,
+					       const char *name, const char *path)
+{
+	struct device_node *np = prom_early_alloc(sizeof(*np));
+	struct device_node **tail = &parent->child;
+
+	of_node_init(np);
+	np->name = prom_early_alloc(strlen(name) + 1);
+	strscpy((char *)np->name, name, strlen(name) + 1);
+	np->full_name = prom_early_alloc(strlen(path) + 1);
+	strscpy((char *)np->full_name, path, strlen(path) + 1);
+	np->parent = parent;
+	np->phandle = ++legacy_phandle;
+	np->unique_id = of_pdt_alloc_unique_id();
+	legacy_property(np, "name", name, strlen(name) + 1);
+	legacy_u32(np, ".node", np->phandle);
+	/* Like the PROM builder, publish before OF device registration starts. */
+	while (*tail)
+		tail = &(*tail)->sibling;
+	*tail = np;
+	return np;
+}
+
+/* Follow version-1 AHB2AHB bridges, including reverse links, once per bus. */
+static int __init legacy_scan_buses(void)
+{
+	unsigned int b, slot, seen;
+	int cpu_bus = -1;
+
+	legacy_bus_count = 1;
+	legacy_buses[0].area = LEON3_IO_AREA;
+	for (b = 0; b < legacy_bus_count; b++) {
+		u32 table = legacy_buses[b].area | LEON3_CONF_AREA;
+
+		for (slot = 0; slot < LEGACY_AHB_SLOTS; slot++) {
+			u32 id = legacy_read(table + slot * 32);
+
+			legacy_irqs |= BIT(id & 0x1f);
+			if (legacy_is(id, GAISLER_LEON3) ||
+			    legacy_is(id, GAISLER_LEON4))
+				cpu_bus = b;
+		}
+		for (slot = 0; slot < LEGACY_AHB_SLOTS; slot++) {
+			u32 pnp = table + 0x800 + slot * 32;
+			u32 id = legacy_read(pnp);
+			u32 area;
+
+			if (!legacy_is(id, GAISLER_AHB2AHB))
+				continue;
+			if (((id >> 5) & 0x1f) != 1) {
+				pr_warn("LEON: unsupported legacy AHB bridge at %x\n", pnp);
+				continue;
+			}
+			area = legacy_read(pnp + 8);
+			if (!area || (area & 0xfffff))
+				continue;
+			for (seen = 0; seen < legacy_bus_count; seen++)
+				if (legacy_buses[seen].area == area)
+					break;
+			if (seen < legacy_bus_count)
+				continue;
+			if (legacy_bus_count == LEGACY_MAX_BUSES)
+				panic("LEON: too many legacy AMBA buses");
+			legacy_buses[seen].area = area;
+			legacy_buses[seen].parent = b;
+			legacy_buses[seen].bridge = legacy_read(pnp + 4);
+			legacy_bus_count++;
+		}
+	}
+	return cpu_bus;
+}
+
+/*
+ * This U-Boot puts CONFIG_SYS_CLK_FREQ / 1000 in the CPU property, but
+ * uses CONFIG_SYS_CLK_FREQ for its initial bus at LEON3_IO_AREA. It is
+ * the I/O-bus clock in kHz, not the actual CPU clock on a bridged LEON4.
+ */
+static bool __init legacy_clocks(int cpu_bus)
+{
+	struct device_node *cpu;
+	u32 freq, factor, config;
+	unsigned int b;
+
+	if (cpu_bus < 0)
+		return false;
+	cpu = of_find_node_by_type(NULL, "cpu");
+	if (!cpu)
+		return false;
+	freq = of_getintprop_default(cpu, "clock-frequency", 0);
+	of_node_put(cpu);
+	if (!freq || freq > U32_MAX / 1000)
+		return false;
+	freq *= 1000;
+	legacy_buses[0].freq = freq;
+	for (b = 1; b < legacy_bus_count; b++) {
+		freq = legacy_buses[legacy_buses[b].parent].freq;
+		/* AHB2AHB user[0]: FFACT at 7:4, direction at bit 8. */
+		config = legacy_buses[b].bridge;
+		factor = (config >> 4) & 0xf;
+		if (!factor)
+			factor = 1;
+		if (config & 0x100) {
+			if (freq > U32_MAX / factor)
+				return false;
+			freq *= factor;
+		} else {
+			freq /= factor;
+		}
+		legacy_buses[b].freq = freq;
+	}
+	return true;
+}
+
+static void __init legacy_device(struct device_node *bus, u32 id, u32 freq,
+				 __be32 *regs, unsigned int count)
+{
+	struct device_node *np;
+	char name[16], path[48];
+	u32 device = (id >> 12) & 0xfff;
+	u32 irq = id & 0x1f;
+	u32 addr = be32_to_cpu(regs[0]);
+	u32 config;
+	unsigned int timer;
+
+	legacy_irqs |= BIT(irq);
+	if (legacy_is(id, GAISLER_GPTIMER)) {
+		config = legacy_read(addr + 8);
+		if (config & BIT(8))
+			for (timer = 0; timer < (config & 7); timer++)
+				legacy_irqs |= BIT((irq + timer) & 0x1f);
+	}
+	if (legacy_is(id, GAISLER_IRQMP)) {
+		config = legacy_read(addr + 0x10);
+		legacy_irqs |= BIT((config >> 16) & 0xf);
+	}
+
+	snprintf(name, sizeof(name), "%02x_%03x", id >> 24, device);
+	snprintf(path, sizeof(path), "%s@%x,%x", name, irq,
+		 be32_to_cpu(regs[0]));
+	np = legacy_node(bus, name, path);
+	legacy_property(np, "reg", regs, count * 2 * sizeof(*regs));
+	legacy_u32(np, "freq", freq);
+	legacy_u32(np, "vendor", id >> 24);
+	legacy_u32(np, "device", device);
+	legacy_u32(np, "version", (id >> 5) & 0x1f);
+	if (irq)
+		legacy_u32(np, "interrupts", irq);
+	pr_info("LEON PnP: %s at %08x irq %u clock %u\n", name,
+		be32_to_cpu(regs[0]), irq, freq);
+}
+
+static void __init legacy_apb(struct device_node *bus, u32 base, u32 freq)
+{
+	unsigned int slot;
+
+	for (slot = 0; slot < LEGACY_APB_SLOTS; slot++) {
+		u32 pnp = (base | LEON3_CONF_AREA) + slot * 8;
+		u32 id = legacy_read(pnp), bar, addr, size, mask;
+		__be32 regs[2];
+
+		if (!(id >> 24) || !((id >> 12) & 0xfff))
+			continue;
+		bar = legacy_read(pnp + 4);
+		if ((bar & 0xf) != 1)
+			continue;
+		mask = (bar >> 4) & 0xfff;
+		addr = base | (((bar & 0xfff00000) >> 12) & (mask << 8));
+		size = ((~mask & 0xfff) + 1) << 8;
+		if (!is_power_of_2(size)) {
+			pr_warn("LEON: invalid APB mask at %x\n", pnp);
+			continue;
+		}
+		regs[0] = cpu_to_be32(addr);
+		regs[1] = cpu_to_be32(size);
+		legacy_device(bus, id, freq, regs, 1);
+	}
+}
+
+void __init leon_legacy_amba_init(void)
+{
+	struct device_node *bus, *np;
+	unsigned int b, slot, bar;
+	u32 systemid;
+	int cpu_bus, ipi;
+
+	if (sparc_cpu_model != sparc_leon || !prom_leon_legacy)
+		return;
+	np = of_find_node_by_path("/ambapp0");
+	if (np) {
+		of_node_put(np);
+		return;
+	}
+
+	cpu_bus = legacy_scan_buses();
+	if (!legacy_clocks(cpu_bus))
+		panic("LEON: cannot determine legacy AMBA clocks");
+	for_each_of_allnodes(np)
+		if (np->phandle > legacy_phandle)
+			legacy_phandle = np->phandle;
+	bus = legacy_node(of_root, "ambapp0", "ambapp0");
+	legacy_property(bus, "device_type", "ambapp", sizeof("ambapp"));
+	legacy_u32(bus, "#address-cells", 1);
+	legacy_u32(bus, "#size-cells", 1);
+	legacy_u32(bus, "freq", legacy_buses[0].freq);
+	/* The last four words of the AHB PnP area contain the system ID. */
+	systemid = legacy_read(legacy_buses[0].area | LEON3_CONF_AREA |
+			       LEON3_AHB_SYSTEMID);
+	legacy_u32(bus, "systemid", systemid);
+	pr_info("LEON PnP: system ID %08x\n", systemid);
+
+	for (b = 0; b < legacy_bus_count; b++) {
+		u32 area = legacy_buses[b].area;
+		u32 freq = legacy_buses[b].freq;
+		u32 table = area | LEON3_CONF_AREA;
+
+		pr_info("LEON PnP: bus %08x clock %u\n", area, freq);
+		for (slot = 0; slot < LEGACY_AHB_SLOTS; slot++) {
+			u32 pnp = table + 0x800 + slot * 32;
+			u32 id = legacy_read(pnp), addr, size;
+			__be32 regs[8];
+			unsigned int count = 0;
+
+			if (!(id >> 24) || !((id >> 12) & 0xfff) ||
+			    legacy_is(id, GAISLER_AHB2AHB))
+				continue;
+			for (bar = 0; bar < 4; bar++) {
+				if (!legacy_bar(area, legacy_read(pnp + 16 + bar * 4),
+						&addr, &size))
+					continue;
+				regs[count * 2] = cpu_to_be32(addr);
+				regs[count * 2 + 1] = cpu_to_be32(size);
+				count++;
+			}
+			if (!count)
+				continue;
+			if (legacy_is(id, GAISLER_APBMST)) {
+				legacy_apb(bus, be32_to_cpu(regs[0]), freq);
+				continue;
+			}
+			legacy_device(bus, id, freq, regs, count);
+		}
+	}
+	if (!IS_ENABLED(CONFIG_SMP))
+		return;
+	/* IRQ15 is reserved for cross-calls; avoid all peripheral IRQs. */
+	for (ipi = 14; ipi > 0; ipi--)
+		if (!(legacy_irqs & BIT(ipi)))
+			break;
+	if (!ipi)
+		panic("LEON: no free legacy AMBA IPI interrupt");
+	legacy_u32(bus, "ipi_num", ipi);
+	pr_info("LEON PnP: selected IPI IRQ %d\n", ipi);
+}
diff --git a/arch/sparc/kernel/prom.h b/arch/sparc/kernel/prom.h
index 26a1cca7c761..60ecbd064a4f 100644
--- a/arch/sparc/kernel/prom.h
+++ b/arch/sparc/kernel/prom.h
@@ -6,6 +6,11 @@
 #include <asm/prom.h>
 
 void of_console_init(void);
+#ifdef CONFIG_SPARC_LEON
+void leon_legacy_amba_init(void);
+#else
+static inline void leon_legacy_amba_init(void) { }
+#endif
 
 extern unsigned int prom_early_allocated;
 
diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
index d258fd10db01..770d780bf830 100644
--- a/arch/sparc/kernel/prom_common.c
+++ b/arch/sparc/kernel/prom_common.c
@@ -154,6 +154,7 @@ static struct of_pdt_ops prom_sparc_ops __initdata = {
 void __init prom_build_devicetree(void)
 {
 	of_pdt_build_devicetree(prom_root_node, &prom_sparc_ops);
+	leon_legacy_amba_init();
 	of_console_init();
 
 	pr_info("PROM: Built device tree with %u bytes of memory.\n",
diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c
index cb0cb374b21f..3c2d4684b7c4 100644
--- a/drivers/of/pdt.c
+++ b/drivers/of/pdt.c
@@ -24,10 +24,15 @@
 static struct of_pdt_ops *of_pdt_prom_ops __initdata;
 
 #if defined(CONFIG_SPARC)
-unsigned int of_pdt_unique_id __initdata;
+static unsigned int of_pdt_unique_id __initdata;
+
+unsigned int __init of_pdt_alloc_unique_id(void)
+{
+	return of_pdt_unique_id++;
+}
 
 #define of_pdt_incr_unique_id(p) do { \
-	(p)->unique_id = of_pdt_unique_id++; \
+	(p)->unique_id = of_pdt_alloc_unique_id(); \
 } while (0)
 
 static char * __init of_pdt_build_full_name(struct device_node *dp)
diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
index 89e4eb076a01..f89999ae68e5 100644
--- a/include/linux/of_pdt.h
+++ b/include/linux/of_pdt.h
@@ -32,6 +32,11 @@ struct of_pdt_ops {
 
 extern void *prom_early_alloc(unsigned long size);
 
+#ifdef CONFIG_SPARC
+/* Share the PROM node/property ID space with synthesized nodes. */
+unsigned int of_pdt_alloc_unique_id(void);
+#endif
+
 /* for building the device tree */
 extern void of_pdt_build_devicetree(phandle root_node, struct of_pdt_ops *ops);
 
-- 
2.43.0


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

* [PATCH 14/18] sparc32,leon: describe legacy AMBA I2C controllers
  2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
                   ` (12 preceding siblings ...)
  2026-11-26  9:30 ` [PATCH 13/18] sparc32,leon: discover AMBA devices for legacy U-Boot PROMs Magnus Lindholm
@ 2026-11-26  9:30 ` Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 15/18] sparc32,leon: skip the GR-LEON4-ITX PROM mapping import Magnus Lindholm
                   ` (3 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7

Describe I2CMST controllers discovered from legacy GRLIB plug-and-play
with the compatible string, register spacing and input clock required
by i2c-ocores. Do not infer attached peripherals from the ASIC system ID;
RTC instantiation needs reliable board-specific information.

Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/sparc/kernel/leon_legacy.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/arch/sparc/kernel/leon_legacy.c b/arch/sparc/kernel/leon_legacy.c
index a9364708e231..fa978620f4a6 100644
--- a/arch/sparc/kernel/leon_legacy.c
+++ b/arch/sparc/kernel/leon_legacy.c
@@ -201,6 +201,18 @@ static bool __init legacy_clocks(int cpu_bus)
 	return true;
 }
 
+static void __init legacy_i2c(struct device_node *np, u32 freq)
+{
+	legacy_property(np, "compatible", "aeroflexgaisler,i2cmst",
+			sizeof("aeroflexgaisler,i2cmst"));
+	legacy_u32(np, "reg-shift", 2);
+	legacy_u32(np, "reg-io-width", 4);
+	legacy_u32(np, "opencores,ip-clock-frequency", freq);
+	legacy_u32(np, "clock-frequency", 100000);
+	legacy_u32(np, "#address-cells", 1);
+	legacy_u32(np, "#size-cells", 0);
+}
+
 static void __init legacy_device(struct device_node *bus, u32 id, u32 freq,
 				 __be32 *regs, unsigned int count)
 {
@@ -235,6 +247,8 @@ static void __init legacy_device(struct device_node *bus, u32 id, u32 freq,
 	legacy_u32(np, "version", (id >> 5) & 0x1f);
 	if (irq)
 		legacy_u32(np, "interrupts", irq);
+	if (legacy_is(id, GAISLER_I2CMST))
+		legacy_i2c(np, freq);
 	pr_info("LEON PnP: %s at %08x irq %u clock %u\n", name,
 		be32_to_cpu(regs[0]), irq, freq);
 }
-- 
2.43.0


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

* [PATCH 15/18] sparc32,leon: skip the GR-LEON4-ITX PROM mapping import
  2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
                   ` (13 preceding siblings ...)
  2026-11-26  9:30 ` [PATCH 14/18] sparc32,leon: describe legacy AMBA I2C controllers Magnus Lindholm
@ 2026-11-26  9:30 ` Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 16/18] sparc32,leon: use the upper SDRAM on the GR-LEON4-ITX Magnus Lindholm
                   ` (2 subsequent siblings)
  17 siblings, 0 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7

The factory U-Boot maps SDRAM with 16 MiB leaves. Linux reaches the
PROM through the linear mapping. Until now leon_swprobe() rejected its
context table at 0x4bffe000 because it lay at max_pfn. Adding the upper
RAM raises max_pfn and makes the importer copy these leaves into the I/O
and vmalloc areas. The first vmap() then faults in
__vmap_pages_range_noflush().

Skip the import on this board, including the high virtual addresses
whose leaves alias RAM that Linux will allocate.

Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/sparc/include/asm/leon.h   | 1 +
 arch/sparc/kernel/leon_legacy.c | 5 +++++
 arch/sparc/mm/srmmu.c           | 4 ++++
 3 files changed, 10 insertions(+)

diff --git a/arch/sparc/include/asm/leon.h b/arch/sparc/include/asm/leon.h
index 67f2822d5fc6..9e51f1fb70fd 100644
--- a/arch/sparc/include/asm/leon.h
+++ b/arch/sparc/include/asm/leon.h
@@ -226,6 +226,7 @@ void leon_update_virq_handling(unsigned int virq,
 			       const char *name, int do_ack);
 extern bool leon_gr_leon4_itx;
 void leon_init_timers(void);
+bool leon_legacy_is_itx(void);
 void leon_node_init(struct device_node *dp, struct device_node ***nextp);
 void init_leon(void);
 void poke_leonsparc(void);
diff --git a/arch/sparc/kernel/leon_legacy.c b/arch/sparc/kernel/leon_legacy.c
index fa978620f4a6..d6c9efe59f42 100644
--- a/arch/sparc/kernel/leon_legacy.c
+++ b/arch/sparc/kernel/leon_legacy.c
@@ -39,6 +39,11 @@ static u32 __init legacy_read(u32 address)
 	return LEON3_BYPASS_LOAD_PA(address);
 }
 
+bool __init leon_legacy_is_itx(void)
+{
+	return prom_leon_legacy && leon_gr_leon4_itx;
+}
+
 static bool __init legacy_is(u32 id, unsigned int device)
 {
 	return (id >> 24) == VENDOR_GAISLER &&
diff --git a/arch/sparc/mm/srmmu.c b/arch/sparc/mm/srmmu.c
index d2963fab829c..2ecc42f6c935 100644
--- a/arch/sparc/mm/srmmu.c
+++ b/arch/sparc/mm/srmmu.c
@@ -767,6 +767,10 @@ static void __init srmmu_inherit_prom_mappings(unsigned long start,
 	pte_t *ptep;
 	int what; /* 0 = normal-pte, 1 = pmd-level pte, 2 = pgd-level pte */
 
+	/* The ITX U-Boot maps only SDRAM here. Its PROM is in the linear map. */
+	if (IS_ENABLED(CONFIG_SPARC_LEON) && leon_legacy_is_itx())
+		return;
+
 	while (start <= end) {
 		if (start == 0)
 			break; /* probably wrap around */
-- 
2.43.0


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

* [PATCH 16/18] sparc32,leon: use the upper SDRAM on the GR-LEON4-ITX
  2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
                   ` (14 preceding siblings ...)
  2026-11-26  9:30 ` [PATCH 15/18] sparc32,leon: skip the GR-LEON4-ITX PROM mapping import Magnus Lindholm
@ 2026-11-26  9:30 ` Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 17/18] sparc32,leon: combine legacy GRPCI1 plug-and-play resources Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 18/18] sparc32,leon: describe the DS1672 on the GR-LEON4-ITX Magnus Lindholm
  17 siblings, 0 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7

The factory PROM reports only 192 MiB minus 8 KiB on this 256 MiB
board. Match the board, PROM map, DDR2 geometry and active scanout
before registering the unused upper ranges. Honor an explicit mem=
limit.

Keep the PROM and 2 MiB at the framebuffer base out of the allocator.
The latter accommodates grvga's 800x600 RGB565 double buffer. Claim
the adjacent RAM before adding it so an oversized fixed framebuffer
cannot overlap an allocated page.

Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/sparc/include/asm/leon.h   |  1 +
 arch/sparc/kernel/leon_legacy.c | 56 +++++++++++++++++++++++++++++++++
 arch/sparc/kernel/setup_32.c    |  2 ++
 3 files changed, 59 insertions(+)

diff --git a/arch/sparc/include/asm/leon.h b/arch/sparc/include/asm/leon.h
index 9e51f1fb70fd..733394efe0eb 100644
--- a/arch/sparc/include/asm/leon.h
+++ b/arch/sparc/include/asm/leon.h
@@ -227,6 +227,7 @@ void leon_update_virq_handling(unsigned int virq,
 extern bool leon_gr_leon4_itx;
 void leon_init_timers(void);
 bool leon_legacy_is_itx(void);
+void leon_legacy_add_highmem(void);
 void leon_node_init(struct device_node *dp, struct device_node ***nextp);
 void init_leon(void);
 void poke_leonsparc(void);
diff --git a/arch/sparc/kernel/leon_legacy.c b/arch/sparc/kernel/leon_legacy.c
index d6c9efe59f42..03d3120797f0 100644
--- a/arch/sparc/kernel/leon_legacy.c
+++ b/arch/sparc/kernel/leon_legacy.c
@@ -5,10 +5,14 @@
  * Build the AMBA device tree omitted by the factory LEON U-Boot.
  */
 
+#include <linux/bitfield.h>
 #include <linux/init.h>
+#include <linux/ioport.h>
 #include <linux/kernel.h>
+#include <linux/memblock.h>
 #include <linux/of.h>
 #include <linux/of_pdt.h>
+#include <linux/sizes.h>
 #include <linux/string.h>
 
 #include <asm/leon.h>
@@ -22,6 +26,13 @@
 #define LEGACY_AHB_SLOTS 64
 #define LEGACY_APB_SLOTS 16
 
+#define ITX_DDR_BASE		0x40000000
+#define ITX_PROM_END		0x4c000000
+#define ITX_FB_BASE		0x4d000000
+#define ITX_DDR_END		0x50000000
+#define ITX_DDR2CFG1		0xffe00100
+#define ITX_GRVGA		0xc0800000
+
 struct legacy_bus {
 	u32 area;
 	u32 freq;
@@ -44,6 +55,51 @@ bool __init leon_legacy_is_itx(void)
 	return prom_leon_legacy && leon_gr_leon4_itx;
 }
 
+/* grvga may request a fixed framebuffer with devm_request_mem_region(). */
+static struct resource itx_highmem[] = {
+	DEFINE_RES_NAMED(ITX_PROM_END, ITX_FB_BASE - ITX_PROM_END, "System RAM",
+			 IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY),
+	DEFINE_RES_NAMED(ITX_FB_BASE + SZ_2M, ITX_DDR_END - ITX_FB_BASE - SZ_2M,
+			 "System RAM", IORESOURCE_SYSTEM_RAM | IORESOURCE_BUSY),
+};
+
+void __init leon_legacy_add_highmem(void)
+{
+	struct resource *res;
+	unsigned int i;
+
+	/* The factory PROM reports only the first 192 MiB minus 8 KiB. */
+	if (!leon_legacy_is_itx() || memblock.memory.cnt != 1 ||
+	    memblock_start_of_DRAM() != ITX_DDR_BASE ||
+	    memblock_end_of_DRAM() != ITX_PROM_END - SZ_8K)
+		return;
+
+	/* DDR2CFG1 bank size code 5 selects 256 MiB per chip select. */
+	if (FIELD_GET(GENMASK(25, 23), legacy_read(ITX_DDR2CFG1)) != 5)
+		return;
+
+	/* Match U-Boot's 800x600 RGB565 scanout before reusing the rest. */
+	if (legacy_read(ITX_GRVGA + 0x14) != ITX_FB_BASE ||
+	    legacy_read(ITX_GRVGA + 0x04) != ((599 << 16) | 799) ||
+	    FIELD_GET(GENMASK(5, 4), legacy_read(ITX_GRVGA)) != 2)
+		return;
+
+	/* Leave room for the factory scanout and grvga's double buffer. */
+	for (i = 0; i < ARRAY_SIZE(itx_highmem); i++) {
+		res = &itx_highmem[i];
+		if (request_resource(&iomem_resource, res)) {
+			pr_warn("LEON: GR-LEON4-ITX high memory %pr is busy\n", res);
+			continue;
+		}
+		if (memblock_add(res->start, resource_size(res))) {
+			release_resource(res);
+			pr_warn("LEON: failed to add GR-LEON4-ITX high memory %pr\n", res);
+			continue;
+		}
+		pr_info("LEON: added GR-LEON4-ITX high memory %pr\n", res);
+	}
+}
+
 static bool __init legacy_is(u32 id, unsigned int device)
 {
 	return (id >> 24) == VENDOR_GAISLER &&
diff --git a/arch/sparc/kernel/setup_32.c b/arch/sparc/kernel/setup_32.c
index c84ac2f1ad15..20c8914cb965 100644
--- a/arch/sparc/kernel/setup_32.c
+++ b/arch/sparc/kernel/setup_32.c
@@ -313,6 +313,8 @@ static void __init setup_memory(void)
 
 	memblock_set_bottom_up(true);
 	memblock_allow_resize();
+	if (IS_ENABLED(CONFIG_SPARC_LEON) && !cmdline_memory_size)
+		leon_legacy_add_highmem();
 
 	phys_base = ram_base;
 	/* phys_base must describe what PAGE_OFFSET maps to, not where RAM starts. */
-- 
2.43.0


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

* [PATCH 17/18] sparc32,leon: combine legacy GRPCI1 plug-and-play resources
  2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
                   ` (15 preceding siblings ...)
  2026-11-26  9:30 ` [PATCH 16/18] sparc32,leon: use the upper SDRAM on the GR-LEON4-ITX Magnus Lindholm
@ 2026-11-26  9:30 ` Magnus Lindholm
  2026-11-26  9:30 ` [PATCH 18/18] sparc32,leon: describe the DS1672 on the GR-LEON4-ITX Magnus Lindholm
  17 siblings, 0 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7

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@gmail.com>
---
 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


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

* [PATCH 18/18] sparc32,leon: describe the DS1672 on the GR-LEON4-ITX
  2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
                   ` (16 preceding siblings ...)
  2026-11-26  9:30 ` [PATCH 17/18] sparc32,leon: combine legacy GRPCI1 plug-and-play resources Magnus Lindholm
@ 2026-11-26  9:30 ` Magnus Lindholm
  17 siblings, 0 replies; 19+ messages in thread
From: Magnus Lindholm @ 2026-11-26  9:30 UTC (permalink / raw)
  To: davem, andreas; +Cc: sam, sparclinux, linux-kernel, linmag7

The factory PROM omits the RTC on I2CM0. Add an rtc@68 child to the
controller at 0xc0000700 when the legacy ITX check matches, so the
DS1672 driver can register the hardware clock at boot.

Signed-off-by: Magnus Lindholm <linmag7@gmail.com>
---
 arch/sparc/kernel/leon_legacy.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/arch/sparc/kernel/leon_legacy.c b/arch/sparc/kernel/leon_legacy.c
index d4b3c48a4a10..f9fb35c3bb06 100644
--- a/arch/sparc/kernel/leon_legacy.c
+++ b/arch/sparc/kernel/leon_legacy.c
@@ -32,6 +32,7 @@
 #define ITX_DDR_END		0x50000000
 #define ITX_DDR2CFG1		0xffe00100
 #define ITX_GRVGA		0xc0800000
+#define ITX_I2CM0		0xc0000700
 
 struct legacy_bus {
 	u32 area;
@@ -262,8 +263,10 @@ static bool __init legacy_clocks(int cpu_bus)
 	return true;
 }
 
-static void __init legacy_i2c(struct device_node *np, u32 freq)
+static void __init legacy_i2c(struct device_node *np, u32 freq, u32 addr)
 {
+	struct device_node *rtc;
+
 	legacy_property(np, "compatible", "aeroflexgaisler,i2cmst",
 			sizeof("aeroflexgaisler,i2cmst"));
 	legacy_u32(np, "reg-shift", 2);
@@ -272,6 +275,14 @@ static void __init legacy_i2c(struct device_node *np, u32 freq)
 	legacy_u32(np, "clock-frequency", 100000);
 	legacy_u32(np, "#address-cells", 1);
 	legacy_u32(np, "#size-cells", 0);
+
+	/* The GR-LEON4-ITX wires its DS1672 to I2CM0 (board manual, 2.14). */
+	if (leon_legacy_is_itx() && addr == ITX_I2CM0) {
+		rtc = legacy_node(np, "rtc", "rtc@68");
+		legacy_property(rtc, "compatible", "dallas,ds1672",
+				sizeof("dallas,ds1672"));
+		legacy_u32(rtc, "reg", 0x68);
+	}
 }
 
 static void __init legacy_device(struct device_node *bus, u32 id, u32 freq,
@@ -309,7 +320,7 @@ static void __init legacy_device(struct device_node *bus, u32 id, u32 freq,
 	if (irq)
 		legacy_u32(np, "interrupts", irq);
 	if (legacy_is(id, GAISLER_I2CMST))
-		legacy_i2c(np, freq);
+		legacy_i2c(np, freq, addr);
 	pr_info("LEON PnP: %s at %08x irq %u clock %u\n", name,
 		be32_to_cpu(regs[0]), irq, freq);
 }
-- 
2.43.0


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

end of thread, other threads:[~2026-11-26  9:31 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-26  9:30 [PATCH 00/18] sparc32: LEON SMP, timer accounting and legacy board support Magnus Lindholm
2026-11-26  9:30 ` [PATCH 01/18] sparc32,leon: give the cross-call IRQ highest priority Magnus Lindholm
2026-11-26  9:30 ` [PATCH 02/18] sparc32,leon: retain SMP TLB shootdowns Magnus Lindholm
2026-11-26  9:30 ` [PATCH 03/18] sparc32,leon: publish instruction updates across CPUs Magnus Lindholm
2026-11-26  9:30 ` [PATCH 04/18] sparc32,leon: avoid nested IRQ accounting in the timer handler Magnus Lindholm
2026-11-26  9:30 ` [PATCH 05/18] sparc32: preserve both LEON PROM character-output conventions Magnus Lindholm
2026-11-26  9:30 ` [PATCH 06/18] sparc32: tolerate firmware nodes without a name property Magnus Lindholm
2026-11-26  9:30 ` [PATCH 07/18] sparc32: skip unavailable PROM V0 console metadata Magnus Lindholm
2026-11-26  9:30 ` [PATCH 08/18] sparc32,leon: identify LEON before the firmware model lookup Magnus Lindholm
2026-11-26  9:30 ` [PATCH 09/18] sparc32,leon: preserve the Linux IRQ14 vector during startup Magnus Lindholm
2026-11-26  9:30 ` [PATCH 10/18] sparc32,leon: use ASI 1 for locks on the GR-LEON4-ITX Magnus Lindholm
2026-11-26  9:30 ` [PATCH 11/18] sparc32,leon: restore the kernel header offsets used by U-Boot Magnus Lindholm
2026-11-26  9:30 ` [PATCH 12/18] sparc32: recognize the legacy LEON firmware machine ID Magnus Lindholm
2026-11-26  9:30 ` [PATCH 13/18] sparc32,leon: discover AMBA devices for legacy U-Boot PROMs Magnus Lindholm
2026-11-26  9:30 ` [PATCH 14/18] sparc32,leon: describe legacy AMBA I2C controllers Magnus Lindholm
2026-11-26  9:30 ` [PATCH 15/18] sparc32,leon: skip the GR-LEON4-ITX PROM mapping import Magnus Lindholm
2026-11-26  9:30 ` [PATCH 16/18] sparc32,leon: use the upper SDRAM on the GR-LEON4-ITX Magnus Lindholm
2026-11-26  9:30 ` [PATCH 17/18] sparc32,leon: combine legacy GRPCI1 plug-and-play resources Magnus Lindholm
2026-11-26  9:30 ` [PATCH 18/18] sparc32,leon: describe the DS1672 on the GR-LEON4-ITX Magnus Lindholm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®