Skip to contentSkip to conversation

lmb: Always compile arch_lmb_reserve() into U-Boot on arm

PATCH In review Marek Vasut 4 participants 28 messages Sep 10, 2021 – Sep 24, 2021

Subsystems (14)
lore
Share & tools
lore
#0 lore raw

PATCH 1/12 lmb: Always compile arch_lmb_reserve() into U-Boot on arm

The arch_lmb_reserve() is called by lib/lmb.c lmb_reserve_common() even if CMD_BOOT{I,M,Z} is not enabled. However, the arm32/arm64 variant of arch_lmb_reserve() is only compiled in if CMD_BOOT{I,M,Z} is enabled.

This currently does not trigger build error, because there is an empty weak implementation of arch_lmb_reserve(), however that is not the function that should be used on arm32/arm64.

Fix this by moving the arch_lmb_reserve() implementation into common code and always compile it in.

Cc Simon Glass <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>

---
V2: Add RB

---
 arch/arm/lib/bootm.c | 45 --------------------------------------------
 arch/arm/lib/stack.c | 45 ++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 45 insertions(+), 45 deletions(-)
arch/arm/lib/bootm.c +0 -45
index f60ee3a7e6..dd6a69315a 100644
@@ -16,7 +16,6 @@
 #include <command.h>
 #include <cpu_func.h>
 #include <dm.h>
-#include <lmb.h>
 #include <log.h>
 #include <asm/global_data.h>
 #include <dm/root.h>
@@ -43,50 +42,6 @@ DECLARE_GLOBAL_DATA_PTR;
 
 static struct tag *params;
 
-static ulong get_sp(void)
-{
-	ulong ret;
-
-	asm("mov %0, sp" : "=r"(ret) : );
-	return ret;
-}
-
-void arch_lmb_reserve(struct lmb *lmb)
-{
-	ulong sp, bank_end;
-	int bank;
-
-	/*
-	 * Booting a (Linux) kernel image
-	 *
-	 * Allocate space for command line and board info - the
-	 * address should be as high as possible within the reach of
-	 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
-	 * memory, which means far enough below the current stack
-	 * pointer.
-	 */
-	sp = get_sp();
-	debug("## Current stack ends at 0x%08lx ", sp);
-
-	/* adjust sp by 4K to be safe */
-	sp -= 4096;
-	for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
-		if (!gd->bd->bi_dram[bank].size ||
-		    sp < gd->bd->bi_dram[bank].start)
-			continue;
-		/* Watch out for RAM at end of address space! */
-		bank_end = gd->bd->bi_dram[bank].start +
-			gd->bd->bi_dram[bank].size - 1;
-		if (sp > bank_end)
-			continue;
-		if (bank_end > gd->ram_top)
-			bank_end = gd->ram_top - 1;
-
-		lmb_reserve(lmb, sp, bank_end - sp + 1);
-		break;
-	}
-}
-
 __weak void board_quiesce_devices(void)
 {
 }
arch/arm/lib/stack.c +45 -0

54 lines not on this page · raw message

Signature · 1 line
2.33.0
#1 lore raw

PATCH 2/12 lmb: Always compile arch_lmb_reserve() into U-Boot on arc

The arch_lmb_reserve() is called by lib/lmb.c lmb_reserve_common() even if CMD_BOOTM is not enabled. However, the arc variant of arch_lmb_reserve() is only compiled in if CMD_BOOTM is enabled.

This currently does not trigger build error, because there is an empty weak implementation of arch_lmb_reserve(), however that is not the function that should be used on arc.

Fix this by moving the arch_lmb_reserve() implementation into common code and always compile it in.

Cc Simon Glass <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>

---
V2: No change

---
 arch/arc/lib/bootm.c | 30 ------------------------------
 arch/arc/lib/cache.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 30 insertions(+), 30 deletions(-)
arch/arc/lib/bootm.c +0 -30
index 8a8d394a5f..41408c2b46 100644
@@ -8,42 +8,12 @@
 #include <env.h>
 #include <image.h>
 #include <irq_func.h>
-#include <lmb.h>
 #include <log.h>
 #include <asm/cache.h>
 #include <asm/global_data.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
-static ulong get_sp(void)
-{
-	ulong ret;
-
-	asm("mov %0, sp" : "=r"(ret) : );
-	return ret;
-}
-
-void arch_lmb_reserve(struct lmb *lmb)
-{
-	ulong sp;
-
-	/*
-	 * Booting a (Linux) kernel image
-	 *
-	 * Allocate space for command line and board info - the
-	 * address should be as high as possible within the reach of
-	 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
-	 * memory, which means far enough below the current stack
-	 * pointer.
-	 */
-	sp = get_sp();
-	debug("## Current stack ends at 0x%08lx ", sp);
-
-	/* adjust sp by 4K to be safe */
-	sp -= 4096;
-	lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp));
-}
-
 static int cleanup_before_linux(void)
 {
 	disable_interrupts();
arch/arc/lib/cache.c +30 -0
index f807cd83d6..4ba180482c 100644
@@ -11,6 +11,7 @@
 #include <linux/compiler.h>
 #include <linux/kernel.h>
 #include <linux/log2.h>
+#include <lmb.h>
 #include <asm/arcregs.h>
 #include <asm/arc-bcr.h>
 #include <asm/cache.h>
@@ -820,3 +821,32 @@ void sync_n_cleanup_cache_all(void)
 
 	__ic_entire_invalidate();
 }
+
+static ulong get_sp(void)
+{
+	ulong ret;
+
+	asm("mov %0, sp" : "=r"(ret) : );
+	return ret;
+}
+
+void arch_lmb_reserve(struct lmb *lmb)
+{
+	ulong sp;
+
+	/*
+	 * Booting a (Linux) kernel image
+	 *
+	 * Allocate space for command line and board info - the
+	 * address should be as high as possible within the reach of
+	 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
+	 * memory, which means far enough below the current stack
+	 * pointer.
+	 */
+	sp = get_sp();
+	debug("## Current stack ends at 0x%08lx ", sp);
+
+	/* adjust sp by 4K to be safe */
+	sp -= 4096;
+	lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp));
+}
Signature · 1 line
2.33.0
#2 lore raw

Re: [PATCH 02/12] lmb: Always compile arch_lmb_reserve() into U-Boot on arc

Quoted 8 lines · Marek Vasut

The arch_lmb_reserve() is called by lib/lmb.c lmb_reserve_common() even if CMD_BOOTM is not enabled. However, the arc variant of arch_lmb_reserve() is only compiled in if CMD_BOOTM is enabled.

This currently does not trigger build error, because there is an empty weak implementation of arch_lmb_reserve(), however that is not the function that should be used on arc.

Quoted 7 lines

Fix this by moving the arch_lmb_reserve() implementation into common code and always compile it in.

Cc Simon Glass <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>

Applied to u-boot/next, thanks!

Signature · 1 line
Tom
#3 lore raw

PATCH 3/12 lmb: Add generic arch_lmb_reserve_generic()

In reply to Marek Vasut

The arc/arm/m68k/microblaze/mips/ppc arch_lmb_reserve() implementations are all mostly the same, except for a couple of details. Implement a generic arch_lmb_reserve_generic() function which can be parametrized enough to cater for those differences between architectures. This can also be parametrized enough so it can handle cases where U-Boot is not relocated to the end of DRAM e.g. because there is some other reserved memory past U-Boot (e.g. unmovable firmware for coprocessor), it is not relocated at all, and other such use cases.

Cc Alexey Brodkin <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Eugeniy Paltsev <[email protected]>
Cc Hai Pham <[email protected]>
Cc Michal Simek <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>
Cc Wolfgang Denk <[email protected]>

---
V2: Reword code comment

---
 include/lmb.h |  1 +
 lib/lmb.c     | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
include/lmb.h +1 -0
index 3c4afdf9f0..1984291132 100644
@@ -122,6 +122,7 @@ lmb_size_bytes(struct lmb_region *type, unsigned long region_nr)
 
 void board_lmb_reserve(struct lmb *lmb);
 void arch_lmb_reserve(struct lmb *lmb);
+void arch_lmb_reserve_generic(struct lmb *lmb, ulong sp, ulong end, ulong align);
 
 /* Low level functions */
 
lib/lmb.c +35 -0
index 7bd1255f7a..793647724c 100644
@@ -12,6 +12,10 @@
 #include <log.h>
 #include <malloc.h>
 
+#include <asm/global_data.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
 #define LMB_ALLOC_ANYWHERE	0
 
 static void lmb_dump_region(struct lmb_region *rgn, char *name)
@@ -113,6 +117,37 @@ void lmb_init(struct lmb *lmb)
 	lmb->reserved.cnt = 0;
 }
 
+void arch_lmb_reserve_generic(struct lmb *lmb, ulong sp, ulong end, ulong align)
+{
+	ulong bank_end;
+	int bank;
+
+	/*
+	 * Reserve memory from aligned address below the bottom of U-Boot stack
+	 * until end of U-Boot area using LMB to prevent U-Boot from overwriting
+	 * that memory.
+	 */
+	debug("## Current stack ends at 0x%08lx ", sp);
+
+	/* adjust sp by 4K to be safe */
+	sp -= align;
+	for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
+		if (!gd->bd->bi_dram[bank].size ||
+		    sp < gd->bd->bi_dram[bank].start)
+			continue;
+		/* Watch out for RAM at end of address space! */
+		bank_end = gd->bd->bi_dram[bank].start +
+			gd->bd->bi_dram[bank].size - 1;
+		if (sp > bank_end)
+			continue;
+		if (bank_end > end)
+			bank_end = end - 1;
+
+		lmb_reserve(lmb, sp, bank_end - sp + 1);
+		break;
+	}
+}
+
 static void lmb_reserve_common(struct lmb *lmb, void *fdt_blob)
 {
 	arch_lmb_reserve(lmb);
Signature · 1 line
2.33.0
Reviewed-by on v1 3/12
#4 lore raw

Re: [PATCH 03/12] lmb: Add generic arch_lmb_reserve_generic()

Quoted 9 lines · Marek Vasut

The arc/arm/m68k/microblaze/mips/ppc arch_lmb_reserve() implementations are all mostly the same, except for a couple of details. Implement a generic arch_lmb_reserve_generic() function which can be parametrized enough to cater for those differences between architectures. This can also be parametrized enough so it can handle cases where U-Boot is not relocated to the end of DRAM e.g. because there is some other reserved memory past U-Boot (e.g. unmovable firmware for coprocessor), it is not relocated at all, and other such use cases.

Quoted 10 lines
Cc Alexey Brodkin <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Eugeniy Paltsev <[email protected]>
Cc Hai Pham <[email protected]>
Cc Michal Simek <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>
Cc Wolfgang Denk <[email protected]>
Signature · 1 line
Tom
#5 lore raw

Re: [PATCH 03/12] lmb: Add generic arch_lmb_reserve_generic()

In reply to Marek Vasut

Am Freitag, dem 10.09.2021 um 22:47 +0200 schrieb Marek Vasut:

Quoted 74 lines

The arc/arm/m68k/microblaze/mips/ppc arch_lmb_reserve() implementations
are all mostly the same, except for a couple of details. Implement a generic arch_lmb_reserve_generic() function which can be parametrized enough to cater for those differences between architectures. This can also be parametrized enough so it can handle cases where U-Boot is not
relocated to the end of DRAM e.g. because there is some other reserved
memory past U-Boot (e.g. unmovable firmware for coprocessor), it is not
relocated at all, and other such use cases.

Cc Alexey Brodkin <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Eugeniy Paltsev <[email protected]>
Cc Hai Pham <[email protected]>
Cc Michal Simek <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>
Cc Wolfgang Denk <[email protected]>

---
V2: Reword code comment

---
 include/lmb.h |  1 +
 lib/lmb.c     | 35 +++++++++++++++++++++++++++++++++++
 2 files changed, 36 insertions(+)
include/lmb.h +1 -0
index 3c4afdf9f0..1984291132 100644
@@ -122,6 +122,7 @@ lmb_size_bytes(struct lmb_region *type, unsigned
 long region_nr)
 
 void board_lmb_reserve(struct lmb *lmb);
 void arch_lmb_reserve(struct lmb *lmb);
+void arch_lmb_reserve_generic(struct lmb *lmb, ulong sp, ulong end,
 ulong align);
 

/* Low level functions */

lib/lmb.c +11 -0
index 7bd1255f7a..793647724c 100644
@@ -12,6 +12,10 @@
 #include <log.h>
 #include <malloc.h>
 
+#include <asm/global_data.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
 #define LMB_ALLOC_ANYWHERE	0
 
 static void lmb_dump_region(struct lmb_region *rgn, char *name)
@@ -113,6 +117,37 @@ void lmb_init(struct lmb *lmb)
 	lmb->reserved.cnt = 0;
 }
 
+void arch_lmb_reserve_generic(struct lmb *lmb, ulong sp, ulong end,
 ulong align)
+{
+	ulong bank_end;
+	int bank;
+
+	/*
+	 * Reserve memory from aligned address below the bottom of U-

Boot stack

lib/lmb.c +1 -0
+	 * until end of U-Boot area using LMB to prevent U-Boot from

overwriting

lib/lmb.c void lmb_init(struct lmb *lmb) · line 132

Quoted 5 lines
lib/lmb.c +5 -0
+	 * that memory.
+	 */
+	debug("## Current stack ends at 0x%08lx ", sp);
+
+	/* adjust sp by 4K to be safe */

nit: comment doesn't fit anymore

lib/lmb.c void lmb_init(struct lmb *lmb) · line 144

Quoted 12 lines
lib/lmb.c +12 -0
+	sp -= align;
+	for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
+		if (!gd->bd->bi_dram[bank].size ||
+		    sp < gd->bd->bi_dram[bank].start)
+			continue;
+		/* Watch out for RAM at end of address space! */
+		bank_end = gd->bd->bi_dram[bank].start +
+			gd->bd->bi_dram[bank].size - 1;
+		if (sp > bank_end)
+			continue;
+		if (bank_end > end)
+			bank_end = end - 1;

isn't that all already taken care of when initializing gd->ram_top as well as gd->relocaddr and gd->start_addr_sp (based on gd->ram_top)? So gd->ram_top is already guaranteed to be less or equal some DRAM bank end address. AFAIK arch_lmb_reserve() should just protect the U-Boot area from gd->start_addr_sp up to gd->ram_top as well as the stack area from the current stack pointer up to the initial stack pointer in gd-

Quoted 1 line

start_addr_sp. Also you changed all callers to always pass gd->ram_top

in "ulong end". Thus I think arch_lmb_reserve_generic() could omit those redundant checks and could be simplified to:

    sp -= align;
    lmb_reserve(lmb, sp, gd->ram_top - sp);

Or am I overlooking something? Is that a valid use case to have U-Boot area and stack area in different memory banks? If yes, shouldn't then lmb_reserve() be called twice by arch_lmb_reserve() to protect stack area AND U-Boot area?

Quoted 9 lines
lib/lmb.c +6 -0
+
+		lmb_reserve(lmb, sp, bank_end - sp + 1);
+		break;
+	}
+}
+
 static void lmb_reserve_common(struct lmb *lmb, void *fdt_blob)
 {
 	arch_lmb_reserve(lmb);
Signature · 1 line
- Daniel
#6 lore raw

Re: [PATCH 03/12] lmb: Add generic arch_lmb_reserve_generic()

On 9/12/21 9:27 PM, Daniel Schwierzeck wrote:

[...]

Quoted 57 lines
Quoted 30 lines
lib/lmb.c +11 -0
index 7bd1255f7a..793647724c 100644
@@ -12,6 +12,10 @@
  #include <log.h>
  #include <malloc.h>
 
+#include <asm/global_data.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
  #define LMB_ALLOC_ANYWHERE	0
 
  static void lmb_dump_region(struct lmb_region *rgn, char *name)
@@ -113,6 +117,37 @@ void lmb_init(struct lmb *lmb)
  	lmb->reserved.cnt = 0;
  }
 
+void arch_lmb_reserve_generic(struct lmb *lmb, ulong sp, ulong end,
 ulong align)
+{
+	ulong bank_end;
+	int bank;
+
+	/*
+	 * Reserve memory from aligned address below the bottom of U-

Boot stack

lib/lmb.c +1 -0
+	 * until end of U-Boot area using LMB to prevent U-Boot from

overwriting

lib/lmb.c void lmb_init(struct lmb *lmb) · line 132

Quoted 5 lines
lib/lmb.c +5 -0
+	 * that memory.
+	 */
+	debug("## Current stack ends at 0x%08lx ", sp);
+
+	/* adjust sp by 4K to be safe */

nit: comment doesn't fit anymore

lib/lmb.c void lmb_init(struct lmb *lmb) · line 144

Quoted 12 lines
lib/lmb.c +12 -0
+	sp -= align;
+	for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
+		if (!gd->bd->bi_dram[bank].size ||
+		    sp < gd->bd->bi_dram[bank].start)
+			continue;
+		/* Watch out for RAM at end of address space! */
+		bank_end = gd->bd->bi_dram[bank].start +
+			gd->bd->bi_dram[bank].size - 1;
+		if (sp > bank_end)
+			continue;
+		if (bank_end > end)
+			bank_end = end - 1;

isn't that all already taken care of when initializing gd->ram_top as well as gd->relocaddr and gd->start_addr_sp (based on gd->ram_top)? So gd->ram_top is already guaranteed to be less or equal some DRAM bank end address. AFAIK arch_lmb_reserve() should just protect the U-Boot area from gd->start_addr_sp up to gd->ram_top as well as the stack area from the current stack pointer up to the initial stack pointer in gd-

Quoted 7 lines
Quoted 1 line

start_addr_sp. Also you changed all callers to always pass gd->ram_top

in "ulong end". Thus I think arch_lmb_reserve_generic() could omit those redundant checks and could be simplified to:

     sp -= align;
     lmb_reserve(lmb, sp, gd->ram_top - sp);

Or am I overlooking something? Is that a valid use case to have U-Boot

This would not allow reserving space at the end of DRAM bank for e.g. DSP firmware which just has to be at the end of DRAM bank. That's why there is this passing of gd->ram_top into this function and it's not part of the function, to prepare for this use case.

Quoted 3 lines

area and stack area in different memory banks? If yes, shouldn't then lmb_reserve() be called twice by arch_lmb_reserve() to protect stack area AND U-Boot area?

The U-Boot stack is below relocated U-Boot, and there is other stuff between those two, so that's why this isn't called twice for stack and U-Boot.

#7 lore raw

Re: [PATCH 03/12] lmb: Add generic arch_lmb_reserve_generic()

In reply to Marek Vasut
Quoted 9 lines · Marek Vasut

The arc/arm/m68k/microblaze/mips/ppc arch_lmb_reserve() implementations are all mostly the same, except for a couple of details. Implement a generic arch_lmb_reserve_generic() function which can be parametrized enough to cater for those differences between architectures. This can also be parametrized enough so it can handle cases where U-Boot is not relocated to the end of DRAM e.g. because there is some other reserved memory past U-Boot (e.g. unmovable firmware for coprocessor), it is not relocated at all, and other such use cases.

Quoted 11 lines
Cc Alexey Brodkin <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Eugeniy Paltsev <[email protected]>
Cc Hai Pham <[email protected]>
Cc Michal Simek <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>
Cc Wolfgang Denk <[email protected]>

Applied to u-boot/next, thanks!

Signature · 1 line
Tom
#8 lore raw

PATCH 4/12 lmb: Switch to generic arch_lmb_reserve_generic()

In reply to Marek Vasut

Switch arc/arm/m68k/microblaze/mips/ppc arch_lmb_reserve() to arch_lmb_reserve_generic().

Cc Alexey Brodkin <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Eugeniy Paltsev <[email protected]>
Cc Hai Pham <[email protected]>
Cc Michal Simek <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>
Cc Wolfgang Denk <[email protected]>

---
V2: Add RB

---
 arch/arc/lib/cache.c        | 18 +-----------------
 arch/arm/lib/stack.c        | 33 +--------------------------------
 arch/m68k/lib/bootm.c       | 18 +-----------------
 arch/microblaze/lib/bootm.c | 28 +---------------------------
 arch/mips/lib/bootm.c       |  9 +--------
 arch/powerpc/lib/bootm.c    | 18 ++----------------
 6 files changed, 7 insertions(+), 117 deletions(-)
arch/arc/lib/cache.c +1 -17
index 4ba180482c..4c696cb53a 100644
@@ -832,21 +832,5 @@ static ulong get_sp(void)
 
 void arch_lmb_reserve(struct lmb *lmb)
 {
-	ulong sp;
-
-	/*
-	 * Booting a (Linux) kernel image
-	 *
-	 * Allocate space for command line and board info - the
-	 * address should be as high as possible within the reach of
-	 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
-	 * memory, which means far enough below the current stack
-	 * pointer.
-	 */
-	sp = get_sp();
-	debug("## Current stack ends at 0x%08lx ", sp);
-
-	/* adjust sp by 4K to be safe */
-	sp -= 4096;
-	lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp));
+	arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);
 }
arch/arm/lib/stack.c +1 -32
index 3f961f4454..52d9f15298 100644
@@ -45,36 +45,5 @@ static ulong get_sp(void)
 
 void arch_lmb_reserve(struct lmb *lmb)
 {
-	ulong sp, bank_end;
-	int bank;
-
-	/*
-	 * Booting a (Linux) kernel image
-	 *
-	 * Allocate space for command line and board info - the
-	 * address should be as high as possible within the reach of
-	 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
-	 * memory, which means far enough below the current stack
-	 * pointer.
-	 */
-	sp = get_sp();
-	debug("## Current stack ends at 0x%08lx ", sp);
-
-	/* adjust sp by 4K to be safe */
-	sp -= 4096;
-	for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
-		if (!gd->bd->bi_dram[bank].size ||
-		    sp < gd->bd->bi_dram[bank].start)
-			continue;
-		/* Watch out for RAM at end of address space! */
-		bank_end = gd->bd->bi_dram[bank].start +
-			gd->bd->bi_dram[bank].size - 1;
-		if (sp > bank_end)
-			continue;
-		if (bank_end > gd->ram_top)
-			bank_end = gd->ram_top - 1;
-
-		lmb_reserve(lmb, sp, bank_end - sp + 1);
-		break;
-	}
+	arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);
 }
arch/m68k/lib/bootm.c +1 -17
index 51a6f93858..27729db67e 100644
@@ -32,23 +32,7 @@ static void set_clocks_in_mhz (struct bd_info *kbd);
 
 void arch_lmb_reserve(struct lmb *lmb)
 {
-	ulong sp;
-
-	/*
-	 * Booting a (Linux) kernel image
-	 *
-	 * Allocate space for command line and board info - the
-	 * address should be as high as possible within the reach of
-	 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
-	 * memory, which means far enough below the current stack
-	 * pointer.
-	 */
-	sp = get_sp();
-	debug ("## Current stack ends at 0x%08lx ", sp);
-
-	/* adjust sp by 1K to be safe */
-	sp -= 1024;
-	lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + gd->ram_size - sp));
+	arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 1024);
 }
 
 int do_bootm_linux(int flag, int argc, char *const argv[],
arch/microblaze/lib/bootm.c +1 -27
index 6695ac63c7..3a6da6e29f 100644
@@ -34,33 +34,7 @@ static ulong get_sp(void)
 
 void arch_lmb_reserve(struct lmb *lmb)
 {
-	ulong sp, bank_end;
-	int bank;
-
-	/*
-	 * Booting a (Linux) kernel image
-	 *
-	 * Allocate space for command line and board info - the
-	 * address should be as high as possible within the reach of
-	 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
-	 * memory, which means far enough below the current stack
-	 * pointer.
-	 */
-	sp = get_sp();
-	debug("## Current stack ends at 0x%08lx ", sp);
-
-	/* adjust sp by 4K to be safe */
-	sp -= 4096;
-	for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
-		if (sp < gd->bd->bi_dram[bank].start)
-			continue;
-		bank_end = gd->bd->bi_dram[bank].start +
-			gd->bd->bi_dram[bank].size;
-		if (sp >= bank_end)
-			continue;
-		lmb_reserve(lmb, sp, bank_end - sp);
-		break;
-	}
+	arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);
 }
 
 static void boot_jump_linux(bootm_headers_t *images, int flag)
arch/mips/lib/bootm.c +1 -8
index fde90fced4..cab8da4860 100644
@@ -39,14 +39,7 @@ static ulong arch_get_sp(void)
 
 void arch_lmb_reserve(struct lmb *lmb)
 {
-	ulong sp;
-
-	sp = arch_get_sp();
-	debug("## Current stack ends at 0x%08lx\n", sp);
-
-	/* adjust sp by 4K to be safe */
-	sp -= 4096;
-	lmb_reserve(lmb, sp, gd->ram_top - sp);
+	arch_lmb_reserve_generic(lmb, arch_get_sp(), gd->ram_top, 4096);
 }
 
 static void linux_cmdline_init(void)
arch/powerpc/lib/bootm.c +2 -16
index 31c17b5bb3..8d65047aa4 100644
@@ -119,7 +119,7 @@ static void boot_jump_linux(bootm_headers_t *images)
 void arch_lmb_reserve(struct lmb *lmb)
 {
 	phys_size_t bootm_size;
-	ulong size, sp, bootmap_base;
+	ulong size, bootmap_base;
 
 	bootmap_base = env_get_bootm_low();
 	bootm_size = env_get_bootm_size();
@@ -141,21 +141,7 @@ void arch_lmb_reserve(struct lmb *lmb)
 		lmb_reserve(lmb, base, bootm_size - size);
 	}
 
-	/*
-	 * Booting a (Linux) kernel image
-	 *
-	 * Allocate space for command line and board info - the
-	 * address should be as high as possible within the reach of
-	 * the kernel (see CONFIG_SYS_BOOTMAPSZ settings), but in unused
-	 * memory, which means far enough below the current stack
-	 * pointer.
-	 */
-	sp = get_sp();
-	debug("## Current stack ends at 0x%08lx\n", sp);
-
-	/* adjust sp by 4K to be safe */
-	sp -= 4096;
-	lmb_reserve(lmb, sp, (CONFIG_SYS_SDRAM_BASE + get_effective_memsize() - sp));
+	arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);
 
 #ifdef CONFIG_MP
 	cpu_mp_lmb_reserve(lmb);
Signature · 1 line
2.33.0
#9 lore raw

Re: [PATCH 04/12] lmb: Switch to generic arch_lmb_reserve_generic()

Quoted 14 lines · Marek Vasut

Switch arc/arm/m68k/microblaze/mips/ppc arch_lmb_reserve() to arch_lmb_reserve_generic().

Cc Alexey Brodkin <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Eugeniy Paltsev <[email protected]>
Cc Hai Pham <[email protected]>
Cc Michal Simek <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>
Cc Wolfgang Denk <[email protected]>

Applied to u-boot/next, thanks!

Signature · 1 line
Tom
#10 lore raw

PATCH 5/12 lmb: arm: Increase LMB alignment to 16k in arch_lmb_reserve_generic()

In reply to Marek Vasut

According to input NXP, the 4k alignment is not always sufficient. Currently iMX works around this problem by implementing board specific LMB reservation, however it is likely this could also occur on other systems. Increase the LMB reservation alignment to 16k by default.

Cc Alexey Brodkin <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Eugeniy Paltsev <[email protected]>
Cc Hai Pham <[email protected]>
Cc Michal Simek <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>
Cc Wolfgang Denk <[email protected]>

---
V2: New patch

---
 arch/arm/lib/stack.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
arch/arm/lib/stack.c +1 -1
index 52d9f15298..656084c7e5 100644
@@ -45,5 +45,5 @@ static ulong get_sp(void)
 
 void arch_lmb_reserve(struct lmb *lmb)
 {
-	arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);
+	arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 16384);
 }
Signature · 1 line
2.33.0
Reviewed-by on v1 5/12
#11 lore raw

Re: [PATCH 05/12] lmb: arm: Increase LMB alignment to 16k in arch_lmb_reserve_generic()

Quoted 5 lines · Marek Vasut

According to input NXP, the 4k alignment is not always sufficient. Currently iMX works around this problem by implementing board specific LMB reservation, however it is likely this could also occur on other systems. Increase the LMB reservation alignment to 16k by default.

Quoted 11 lines
Cc Alexey Brodkin <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Eugeniy Paltsev <[email protected]>
Cc Hai Pham <[email protected]>
Cc Michal Simek <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>
Cc Wolfgang Denk <[email protected]>
Signature · 1 line
Tom
#12 lore raw

Re: [PATCH 05/12] lmb: arm: Increase LMB alignment to 16k in arch_lmb_reserve_generic()

In reply to Marek Vasut
Quoted 5 lines · Marek Vasut

According to input NXP, the 4k alignment is not always sufficient. Currently iMX works around this problem by implementing board specific LMB reservation, however it is likely this could also occur on other systems. Increase the LMB reservation alignment to 16k by default.

Quoted 12 lines
Cc Alexey Brodkin <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Eugeniy Paltsev <[email protected]>
Cc Hai Pham <[email protected]>
Cc Michal Simek <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>
Cc Wolfgang Denk <[email protected]>

Applied to u-boot/next, thanks!

Signature · 1 line
Tom
#13 lore raw

PATCH 6/12 lmb: Remove imx board_lmb_reserve()

In reply to Marek Vasut

This function is clearly architecture specific code, not board specific code. The only difference from the previous arm arch_lmb_reserve() is the extra reservation of 16k of memory below the stack bottom, rather than the 4k. The common code now also uses 16k alignment. Remove this custom implementation, as it now behaves exactly as the common code.

Cc Alexey Brodkin <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Eugeniy Paltsev <[email protected]>
Cc Hai Pham <[email protected]>
Cc Michal Simek <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>
Cc Wolfgang Denk <[email protected]>

---
V2: Drop the custom implementation altogether

---
 arch/arm/mach-imx/misc.c | 30 ------------------------------
 1 file changed, 30 deletions(-)
arch/arm/mach-imx/misc.c +0 -30
index d82efa7f8f..09a758ff6e 100644
@@ -77,33 +77,3 @@ int mxs_reset_block(struct mxs_register_32 *reg)
 
 	return 0;
 }
-
-static ulong get_sp(void)
-{
-	ulong ret;
-
-	asm("mov %0, sp" : "=r"(ret) : );
-	return ret;
-}
-
-void board_lmb_reserve(struct lmb *lmb)
-{
-	ulong sp, bank_end;
-	int bank;
-
-	sp = get_sp();
-	debug("## Current stack ends at 0x%08lx ", sp);
-
-	/* adjust sp by 16K to be safe */
-	sp -= 4096 << 2;
-	for (bank = 0; bank < CONFIG_NR_DRAM_BANKS; bank++) {
-		if (sp < gd->bd->bi_dram[bank].start)
-			continue;
-		bank_end = gd->bd->bi_dram[bank].start +
-			gd->bd->bi_dram[bank].size;
-		if (sp >= bank_end)
-			continue;
-		lmb_reserve(lmb, sp, bank_end - sp);
-		break;
-	}
-}
Signature · 1 line
2.33.0
#14 lore raw

Re: [PATCH 06/12] lmb: Remove imx board_lmb_reserve()

Quoted 6 lines · Marek Vasut

This function is clearly architecture specific code, not board specific code. The only difference from the previous arm arch_lmb_reserve() is the extra reservation of 16k of memory below the stack bottom, rather than the 4k. The common code now also uses 16k alignment. Remove this custom implementation, as it now behaves exactly as the common code.

Quoted 11 lines
Cc Alexey Brodkin <[email protected]>
Cc Angelo Dureghello <[email protected]>
Cc Daniel Schwierzeck <[email protected]>
Cc Eugeniy Paltsev <[email protected]>
Cc Hai Pham <[email protected]>
Cc Michal Simek <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>
Cc Wolfgang Denk <[email protected]>

Applied to u-boot/next, thanks!

Signature · 1 line
Tom
#15 lore raw

PATCH 7/12 lmb: nios2: Add arch_lmb_reserve()

In reply to Marek Vasut

Add arch_lmb_reserve() implemented using arch_lmb_reserve_generic(). It is rather likely this architecture also needs to cover U-Boot with LMB before booting Linux.

Cc Simon Goldschmidt <[email protected]>
Cc Thomas Chou <[email protected]>
Cc Tom Rini <[email protected]>

---
V2: No change

---
 arch/nios2/lib/bootm.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/nios2/lib/bootm.c +16 -0
index 5037467151..3cb59bd977 100644
@@ -10,6 +10,9 @@
 #include <image.h>
 #include <irq_func.h>
 #include <log.h>
+#include <asm/global_data.h>
+
+DECLARE_GLOBAL_DATA_PTR;
 
 #define NIOS_MAGIC 0x534f494e /* enable command line and initrd passing */
 
@@ -60,3 +63,16 @@ int do_bootm_linux(int flag, int argc, char *const argv[],
 
 	return 1;
 }
+
+static ulong get_sp(void)
+{
+	ulong ret;
+
+	asm("mov %0, sp" : "=r"(ret) : );
+	return ret;
+}
+
+void arch_lmb_reserve(struct lmb *lmb)
+{
+	arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);
+}
Signature · 1 line
2.33.0
#17 lore raw

PATCH 8/12 lmb: nds32: Add arch_lmb_reserve()

In reply to Marek Vasut

Add arch_lmb_reserve() implemented using arch_lmb_reserve_generic(). It is rather likely this architecture also needs to cover U-Boot with LMB before booting Linux.

Cc Rick Chen <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>

---
V2: Add RB from Rick

---
 arch/nds32/lib/bootm.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
arch/nds32/lib/bootm.c +13 -0
index 4cb0f530ae..a7c8978f23 100644
@@ -245,3 +245,16 @@ static void setup_end_tag(struct bd_info *bd)
 }
 
 #endif /* CONFIG_SETUP_MEMORY_TAGS || CONFIG_CMDLINE_TAG || CONFIG_INITRD_TAG */
+
+static ulong get_sp(void)
+{
+	ulong ret;
+
+	asm("move %0, $sp" : "=r"(ret) : );
+	return ret;
+}
+
+void arch_lmb_reserve(struct lmb *lmb)
+{
+	arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);
+}
Signature · 1 line
2.33.0
#18 lore raw

Re: [PATCH 08/12] lmb: nds32: Add arch_lmb_reserve()

Quoted 9 lines · Marek Vasut

Add arch_lmb_reserve() implemented using arch_lmb_reserve_generic(). It is rather likely this architecture also needs to cover U-Boot with LMB before booting Linux.

Cc Rick Chen <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>

Applied to u-boot/next, thanks!

Signature · 1 line
Tom
#19 lore raw

PATCH 9/12 lmb: riscv: Add arch_lmb_reserve()

In reply to Marek Vasut

Add arch_lmb_reserve() implemented using arch_lmb_reserve_generic(). It is rather likely this architecture also needs to cover U-Boot with LMB before booting Linux.

Cc Atish Patra <[email protected]>
Cc Rick Chen <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>

---
V2: Add RB from Rick

---
 arch/riscv/lib/bootm.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
arch/riscv/lib/bootm.c +13 -0
index 8dd1820540..ff1bdf7131 100644
@@ -135,3 +135,16 @@ int do_bootm_vxworks(int flag, int argc, char *const argv[],
 {
 	return do_bootm_linux(flag, argc, argv, images);
 }
+
+static ulong get_sp(void)
+{
+	ulong ret;
+
+	asm("mv %0, sp" : "=r"(ret) : );
+	return ret;
+}
+
+void arch_lmb_reserve(struct lmb *lmb)
+{
+	arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);
+}
Signature · 1 line
2.33.0
#20 lore raw

Re: [PATCH 09/12] lmb: riscv: Add arch_lmb_reserve()

Quoted 11 lines · Marek Vasut

Add arch_lmb_reserve() implemented using arch_lmb_reserve_generic(). It is rather likely this architecture also needs to cover U-Boot with LMB before booting Linux.

Cc Atish Patra <[email protected]>
Cc Rick Chen <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>

Applied to u-boot/next, thanks!

Signature · 1 line
Tom
#21 lore raw

PATCH 10/12 lmb: sh: Add arch_lmb_reserve()

In reply to Marek Vasut

Add arch_lmb_reserve() implemented using arch_lmb_reserve_generic(). This architecture also needs to cover U-Boot with LMB before booting Linux.

Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>

---
V2: No change

---
 arch/sh/lib/bootm.c | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)
arch/sh/lib/bootm.c +16 -0
index dc94f83785..9b71424dfe 100644
@@ -12,8 +12,11 @@
 #include <env.h>
 #include <image.h>
 #include <asm/byteorder.h>
+#include <asm/global_data.h>
 #include <asm/zimage.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 #ifdef CONFIG_SYS_DEBUG
 static void hexdump(unsigned char *buf, int len)
 {
@@ -111,3 +114,16 @@ int do_bootm_linux(int flag, int argc, char *const argv[],
 	/* does not return */
 	return 1;
 }
+
+static ulong get_sp(void)
+{
+	ulong ret;
+
+	asm("mov r15, %0" : "=r"(ret) : );
+	return ret;
+}
+
+void arch_lmb_reserve(struct lmb *lmb)
+{
+	arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);
+}
Signature · 1 line
2.33.0
#22 lore raw

Re: [PATCH 10/12] lmb: sh: Add arch_lmb_reserve()

Quoted 7 lines · Marek Vasut

Add arch_lmb_reserve() implemented using arch_lmb_reserve_generic(). This architecture also needs to cover U-Boot with LMB before booting Linux.

Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>

Applied to u-boot/next, thanks!

Signature · 1 line
Tom
#23 lore raw

PATCH 11/12 lmb: xtensa: Add arch_lmb_reserve()

In reply to Marek Vasut

Add arch_lmb_reserve() implemented using arch_lmb_reserve_generic(). It is rather likely this architecture also needs to cover U-Boot with LMB before booting Linux.

Cc Chris Zankel <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>

---
V2: No change

---
 arch/xtensa/lib/bootm.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
arch/xtensa/lib/bootm.c +12 -0
index bb1e2886ab..277af18168 100644
@@ -197,3 +197,15 @@ int do_bootm_linux(int flag, int argc, char *argv[], bootm_headers_t *images)
 	return 1;
 }
 
+static ulong get_sp(void)
+{
+	ulong ret;
+
+	asm("mov %0, a1" : "=r"(ret) : );
+	return ret;
+}
+
+void arch_lmb_reserve(struct lmb *lmb)
+{
+	arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);
+}
Signature · 1 line
2.33.0
#24 lore raw

Re: [PATCH 11/12] lmb: xtensa: Add arch_lmb_reserve()

Quoted 8 lines · Marek Vasut

Add arch_lmb_reserve() implemented using arch_lmb_reserve_generic(). It is rather likely this architecture also needs to cover U-Boot with LMB before booting Linux.

Cc Chris Zankel <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>

Applied to u-boot/next, thanks!

Signature · 1 line
Tom
#25 lore raw

PATCH 12/12 lmb: x86: Add arch_lmb_reserve()

In reply to Marek Vasut

Add arch_lmb_reserve() implemented using arch_lmb_reserve_generic(). It is rather likely this architecture also needs to cover U-Boot with LMB before booting Linux.

Cc Simon Glass <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>

---
V2: No change

---
 arch/x86/lib/bootm.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
arch/x86/lib/bootm.c +18 -0
index 733dd71257..667e5e689e 100644
@@ -223,3 +223,21 @@ int do_bootm_linux(int flag, int argc, char *const argv[],
 
 	return boot_jump_linux(images);
 }
+
+static ulong get_sp(void)
+{
+	ulong ret;
+
+#if CONFIG_IS_ENABLED(X86_64)
+	ret = gd->start_addr_sp;
+#else
+	asm("mov %%esp, %0" : "=r"(ret) : );
+#endif
+
+	return ret;
+}
+
+void arch_lmb_reserve(struct lmb *lmb)
+{
+	arch_lmb_reserve_generic(lmb, get_sp(), gd->ram_top, 4096);
+}
Signature · 1 line
2.33.0
#27 lore raw
In reply to Marek Vasut
Quoted 8 lines · Marek Vasut

The arch_lmb_reserve() is called by lib/lmb.c lmb_reserve_common() even if CMD_BOOT{I,M,Z} is not enabled. However, the arm32/arm64 variant of arch_lmb_reserve() is only compiled in if CMD_BOOT{I,M,Z} is enabled.

This currently does not trigger build error, because there is an empty weak implementation of arch_lmb_reserve(), however that is not the function that should be used on arm32/arm64.

Quoted 8 lines

Fix this by moving the arch_lmb_reserve() implementation into common code and always compile it in.

Cc Simon Glass <[email protected]>
Cc Simon Goldschmidt <[email protected]>
Cc Tom Rini <[email protected]>

Applied to u-boot/next, thanks!

Signature · 1 line
Tom