sparc32: LEON SMP, timer accounting and legacy board support
cover sparc32: LEON SMP, timer accounting and legacy board support
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: [email protected]
[PATCH 9/9] sparc32: enroll and order CPUs before switching address spaces
Message-ID: [email protected]
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/[email protected]/
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
Signature · 1 line
2.43.0
PATCH 1/18 sparc32,leon: give the cross-call IRQ highest priority
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.
--- arch/sparc/kernel/leon_smp.c | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/sparc/kernel/leon_smp.c +9 -0
@@ -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);
Signature · 1 line
2.43.0
PATCH 2/18 sparc32,leon: retain SMP TLB shootdowns
In reply to Magnus LindholmLEON 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".
--- arch/sparc/mm/leon_mm.c | 3 ++- arch/sparc/mm/srmmu.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-)
arch/sparc/mm/leon_mm.c +2 -1
@@ -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 (); }
arch/sparc/mm/srmmu.c +2 -1
@@ -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;
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 02/18] sparc32,leon: retain SMP TLB shootdowns
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [High] sparc32: missing preemption disable in…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [High] sparc32: missing preemption disable in smp_flush_tlb_mm() [1] --
commit 20d5675eb7a3d5e5a3910745d8ae9ac1da8711f2
Author: Magnus Lindholm <[email protected]>
sparc32,leon: retain SMP TLB shootdowns
This commit retains the SMP TLB flush wrappers on LEON instead of replacing them with local operations, and updates leon_switch_mm() to invoke leon_flush_tlb_all() directly for local context switches.
Quoted 5 lines
arch/sparc/mm/srmmu.c +0
-0
arch/sparc/mm/srmmu.c void __init load_mmu(void) · line 1753
Quoted 9 lines
arch/sparc/mm/srmmu.c +2
-1@@ -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;
[Severity: High]
This problem wasn't introduced by this patch, but can smp_flush_tlb_mm() leave stale TLB entries on the original CPU if the caller is preempted and migrated mid-flush [1]?
With LEON now using smp_cachetlb_ops.tlb_mm, flush_tlb_mm() calls smp_flush_tlb_mm(), which runs without disabling preemption when invoked from preemptible context (such as fork() -> dup_mmap() -> flush_tlb_mm()):
arch/sparc/mm/srmmu.c:any_other_mm_cpus() {
return cpumask_any_but(mm_cpumask(mm), smp_processor_id()) < nr_cpu_ids;
}
...
arch/sparc/mm/srmmu.c:smp_flush_tlb_mm() {
if (mm->context != NO_CONTEXT) {
if (any_other_mm_cpus(mm))
xc1(local_ops->tlb_mm, (unsigned long)mm);
local_ops->tlb_mm(mm);
}
}Aside from calling smp_processor_id() in preemptible context (which warns under CONFIG_DEBUG_PREEMPT), the cross-call excludes the initiating CPU and re-enables preemption before local_ops->tlb_mm() runs:
CPU0 CPU1smp_flush_tlb_mm(mm)
xc1(local_ops->tlb_mm, ...)
sun4m_cross_call(...)
cpumask_clear_cpu(0, &mask)
...
spin_unlock_irqrestore(...)
[migrated to CPU1]
local_ops->tlb_mm(mm) <-- CPU0 missedCPU1 is flushed twice while CPU0's TLB is never flushed, which can cause memory corruption after page table updates.
[1] https://sashiko.dev/#/bug/linux-faa0e34b-f932-4bee-ba78-e5a71fbc6fe8
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
PATCH 3/18 sparc32,leon: publish instruction updates across CPUs
In reply to Magnus Lindholmflush_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.
--- arch/sparc/include/asm/cacheflush_32.h | 2 +- arch/sparc/mm/srmmu.c | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-)
arch/sparc/include/asm/cacheflush_32.h +1 -1
@@ -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 { \
arch/sparc/mm/srmmu.c +14 -0
@@ -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 ) {
Signature · 1 line
2.43.0
PATCH 4/18 sparc32,leon: avoid nested IRQ accounting in the timer handler
In reply to Magnus Lindholmhandler_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.
--- arch/sparc/kernel/leon_kernel.c | 2 -- 1 file changed, 2 deletions(-)
arch/sparc/kernel/leon_kernel.c +0 -2
@@ -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 ; }
Signature · 1 line
2.43.0
PATCH 5/18 sparc32: preserve both LEON PROM character-output conventions
In reply to Magnus LindholmFactory 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.
--- 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(-)
arch/sparc/include/asm/oplib_32.h +2 -0
@@ -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;
arch/sparc/prom/console_32.c +3 -2
@@ -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 :
arch/sparc/prom/init_32.c +23 -0
@@ -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 ();
Signature · 1 line
2.43.0
PATCH 6/18 sparc32: tolerate firmware nodes without a name property
In reply to Magnus LindholmFactory 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.
--- arch/sparc/kernel/prom_32.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/sparc/kernel/prom_32.c +10 -0
@@ -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);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 06/18] sparc32: tolerate firmware nodes without a name property
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] sparc32: missing Fixes: trailer for NULL dereference in build_path_component() --
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] sparc32: missing Fixes: trailer for NULL dereference in build_path_component()
--
commit f438c40f8b6eebf1210958ddefc12bef550dbce9
Author: Magnus Lindholm <[email protected]>
Quoted 7 lines
sparc32: tolerate firmware nodes without a name property
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 <[email protected]>
[Severity: Low]
This fixes a NULL pointer dereference introduced when build_path_component() switched from dp->name to of_get_property(dp, "name", NULL). Should this include:
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=6
PATCH 7/18 sparc32: skip unavailable PROM V0 console metadata
In reply to Magnus LindholmThe 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.
--- arch/sparc/kernel/prom_32.c | 6 ++++++ 1 file changed, 6 insertions(+)
arch/sparc/kernel/prom_32.c +6 -0
@@ -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) {
Signature · 1 line
2.43.0
PATCH 8/18 sparc32,leon: identify LEON before the firmware model lookup
In reply to Magnus LindholmThe 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.
--- arch/sparc/kernel/head_32.S | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-)
arch/sparc/kernel/head_32.S +25 -4
@@ -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 */
Signature · 1 line
2.43.0
PATCH 9/18 sparc32,leon: preserve the Linux IRQ14 vector during startup
In reply to Magnus LindholmWhen 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.
--- arch/sparc/kernel/head_32.S | 9 +++++++++ 1 file changed, 9 insertions(+)
arch/sparc/kernel/head_32.S +9 -0
@@ -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
Signature · 1 line
2.43.0
PATCH 10/18 sparc32,leon: use ASI 1 for locks on the GR-LEON4-ITX
In reply to Magnus LindholmCached 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.
--- 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
arch/sparc/include/asm/ldstub.h new file +46 -0
@@ -0,0 +1,46 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Written by Magnus Lindholm, [email protected] +* +* 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 */
arch/sparc/include/asm/leon.h +1 -0
@@ -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 );
arch/sparc/include/asm/leon_amba.h +2 -0
@@ -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
arch/sparc/include/asm/sections.h +2 -0
@@ -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
arch/sparc/include/asm/spinlock_32.h +22 -10
@@ -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; }
arch/sparc/kernel/module.c +25 -0
@@ -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 */
arch/sparc/kernel/setup_32.c +40 -15
79 lines not on this page · raw message
arch/sparc/kernel/vmlinux.lds.S +5 -0
@@ -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)
arch/sparc/lib/locks.S +19 -5
@@ -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
Signature · 1 line
2.43.0
PATCH 11/18 sparc32,leon: restore the kernel header offsets used by U-Boot
In reply to Magnus LindholmFactory 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.
--- arch/sparc/kernel/head_32.S | 8 ++++++++ 1 file changed, 8 insertions(+)
arch/sparc/kernel/head_32.S +8 -0
@@ -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
Signature · 1 line
2.43.0
PATCH 12/18 sparc32: recognize the legacy LEON firmware machine ID
In reply to Magnus LindholmFactory 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.
--- arch/sparc/include/asm/machines.h | 1 + arch/sparc/kernel/idprom.c | 2 ++ 2 files changed, 3 insertions(+)
arch/sparc/include/asm/machines.h +1 -0
@@ -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
arch/sparc/kernel/idprom.c +2 -0
@@ -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 ) },
Signature · 1 line
2.43.0
PATCH 13/18 sparc32,leon: discover AMBA devices for legacy U-Boot PROMs
In reply to Magnus LindholmFactory 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.
--- 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
arch/sparc/kernel/Makefile +1 -0
@@ -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
arch/sparc/kernel/leon_legacy.c new file +343 -0
343 lines not on this page · raw message
arch/sparc/kernel/prom.h +5 -0
@@ -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;
arch/sparc/kernel/prom_common.c +1 -0
@@ -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",
drivers/of/pdt.c +7 -2
@@ -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)
include/linux/of_pdt.h +5 -0
@@ -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);
Signature · 1 line
2.43.0
PATCH 14/18 sparc32,leon: describe legacy AMBA I2C controllers
In reply to Magnus LindholmDescribe 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.
--- arch/sparc/kernel/leon_legacy.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
arch/sparc/kernel/leon_legacy.c +14 -0
@@ -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); }
Signature · 1 line
2.43.0
PATCH 15/18 sparc32,leon: skip the GR-LEON4-ITX PROM mapping import
In reply to Magnus LindholmThe 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.
--- 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(+)
arch/sparc/include/asm/leon.h +1 -0
@@ -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 );
arch/sparc/kernel/leon_legacy.c +5 -0
@@ -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 &&
arch/sparc/mm/srmmu.c +4 -0
@@ -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 */
Signature · 1 line
2.43.0
PATCH 16/18 sparc32,leon: use the upper SDRAM on the GR-LEON4-ITX
In reply to Magnus LindholmThe 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.
--- 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(+)
arch/sparc/include/asm/leon.h +1 -0
@@ -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 );
arch/sparc/kernel/leon_legacy.c +56 -0
78 lines not on this page · raw message
arch/sparc/kernel/setup_32.c +2 -0
@@ -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. */
Signature · 1 line
2.43.0
PATCH 17/18 sparc32,leon: combine legacy GRPCI1 plug-and-play resources
In reply to Magnus LindholmThe 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.
--- arch/sparc/kernel/leon_legacy.c | 62 +++++++++++++++++++++++++++++++-- 1 file changed, 60 insertions(+), 2 deletions(-)
arch/sparc/kernel/leon_legacy.c +60 -2
@@ -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 ;
Signature · 1 line
2.43.0
PATCH 18/18 sparc32,leon: describe the DS1672 on the GR-LEON4-ITX
In reply to Magnus LindholmThe 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.
--- arch/sparc/kernel/leon_legacy.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-)
arch/sparc/kernel/leon_legacy.c +13 -2
@@ -32,6 +32,7 @@#define ITX_DDR_END 0x50000000#define ITX_DDR2CFG1 0xffe00100#define ITX_GRVGA 0xc0800000 +#define ITX_I2CM0 0xc0000700struct 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); }
Signature · 1 line
2.43.0