[PATCH 16/18] sparc32,leon: use the upper SDRAM on the GR-LEON4-ITX
From: Magnus Lindholm
Date: Thu Nov 26 2026 - 04:31:58 EST
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@xxxxxxxxx>
---
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