diff mbox series

[v1] x86: tangier: Find proper memory region for relocation

Message ID 20201127124048.11843-1-andriy.shevchenko@linux.intel.com
State Accepted
Commit 21096c0af3733b63c1e9ee7772d95a0551b4fc85
Delegated to: Bin Meng
Headers show
Series [v1] x86: tangier: Find proper memory region for relocation | expand

Commit Message

Andy Shevchenko Nov. 27, 2020, 12:40 p.m. UTC
It appears that U-Boot works by luck on Intel Edison board because the amount
of RAM is less than 1 GB and standard way of calculating the top of it work
for this configuration. However, this won't work if the amount of RAM is
different and split differently in address space. We have to fine the suitable
window correctly.

Find proper memory region for relocation by scanning MMAP SFI table in
board_get_usable_ram_top() callback.

According to the address map documentation the Main Memory is guaranteed to lie
in the 0..2 GB range, that's why we limit search by this range.

Fixes: e71de54a4943 ("x86: Add Intel Tangier support")
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 arch/x86/cpu/tangier/sdram.c | 43 ++++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)

Comments

Simon Glass Nov. 30, 2020, 8:12 p.m. UTC | #1
On Fri, 27 Nov 2020 at 05:40, Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> It appears that U-Boot works by luck on Intel Edison board because the amount
> of RAM is less than 1 GB and standard way of calculating the top of it work
> for this configuration. However, this won't work if the amount of RAM is
> different and split differently in address space. We have to fine the suitable
> window correctly.
>
> Find proper memory region for relocation by scanning MMAP SFI table in
> board_get_usable_ram_top() callback.
>
> According to the address map documentation the Main Memory is guaranteed to lie
> in the 0..2 GB range, that's why we limit search by this range.
>
> Fixes: e71de54a4943 ("x86: Add Intel Tangier support")
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  arch/x86/cpu/tangier/sdram.c | 43 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>
Andy Shevchenko Dec. 15, 2020, 10:05 a.m. UTC | #2
On Mon, Nov 30, 2020 at 01:12:17PM -0700, Simon Glass wrote:
> On Fri, 27 Nov 2020 at 05:40, Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > It appears that U-Boot works by luck on Intel Edison board because the amount
> > of RAM is less than 1 GB and standard way of calculating the top of it work
> > for this configuration. However, this won't work if the amount of RAM is
> > different and split differently in address space. We have to fine the suitable
> > window correctly.
> >
> > Find proper memory region for relocation by scanning MMAP SFI table in
> > board_get_usable_ram_top() callback.
> >
> > According to the address map documentation the Main Memory is guaranteed to lie
> > in the 0..2 GB range, that's why we limit search by this range.
> >
> > Fixes: e71de54a4943 ("x86: Add Intel Tangier support")
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > ---
> >  arch/x86/cpu/tangier/sdram.c | 43 ++++++++++++++++++++++++++++++++++++
> >  1 file changed, 43 insertions(+)
> 
> Reviewed-by: Simon Glass <sjg@chromium.org>

Thanks!

Bin, can we get this, somehow important fix, into v2021.01 release?
And any comments about the rest tangier/edison patches?
Bin Meng Dec. 15, 2020, 1:09 p.m. UTC | #3
Hi Andy,

On Tue, Dec 15, 2020 at 6:04 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> On Mon, Nov 30, 2020 at 01:12:17PM -0700, Simon Glass wrote:
> > On Fri, 27 Nov 2020 at 05:40, Andy Shevchenko
> > <andriy.shevchenko@linux.intel.com> wrote:
> > >
> > > It appears that U-Boot works by luck on Intel Edison board because the amount
> > > of RAM is less than 1 GB and standard way of calculating the top of it work
> > > for this configuration. However, this won't work if the amount of RAM is
> > > different and split differently in address space. We have to fine the suitable
> > > window correctly.
> > >
> > > Find proper memory region for relocation by scanning MMAP SFI table in
> > > board_get_usable_ram_top() callback.
> > >
> > > According to the address map documentation the Main Memory is guaranteed to lie
> > > in the 0..2 GB range, that's why we limit search by this range.
> > >
> > > Fixes: e71de54a4943 ("x86: Add Intel Tangier support")
> > > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > > ---
> > >  arch/x86/cpu/tangier/sdram.c | 43 ++++++++++++++++++++++++++++++++++++
> > >  1 file changed, 43 insertions(+)
> >
> > Reviewed-by: Simon Glass <sjg@chromium.org>
>
> Thanks!
>
> Bin, can we get this, somehow important fix, into v2021.01 release?
> And any comments about the rest tangier/edison patches?
>

Sure, I will take a look soon.

Regards,
Bin
Bin Meng Dec. 16, 2020, 3:32 a.m. UTC | #4
On Fri, Nov 27, 2020 at 8:40 PM Andy Shevchenko
<andriy.shevchenko@linux.intel.com> wrote:
>
> It appears that U-Boot works by luck on Intel Edison board because the amount
> of RAM is less than 1 GB and standard way of calculating the top of it work
> for this configuration. However, this won't work if the amount of RAM is
> different and split differently in address space. We have to fine the suitable

fine -> find

I can fix this when applying

> window correctly.
>
> Find proper memory region for relocation by scanning MMAP SFI table in
> board_get_usable_ram_top() callback.
>
> According to the address map documentation the Main Memory is guaranteed to lie
> in the 0..2 GB range, that's why we limit search by this range.
>
> Fixes: e71de54a4943 ("x86: Add Intel Tangier support")
> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> ---
>  arch/x86/cpu/tangier/sdram.c | 43 ++++++++++++++++++++++++++++++++++++
>  1 file changed, 43 insertions(+)
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Bin Meng Dec. 16, 2020, 5:52 a.m. UTC | #5
On Wed, Dec 16, 2020 at 11:32 AM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> On Fri, Nov 27, 2020 at 8:40 PM Andy Shevchenko
> <andriy.shevchenko@linux.intel.com> wrote:
> >
> > It appears that U-Boot works by luck on Intel Edison board because the amount
> > of RAM is less than 1 GB and standard way of calculating the top of it work
> > for this configuration. However, this won't work if the amount of RAM is
> > different and split differently in address space. We have to fine the suitable
>
> fine -> find
>
> I can fix this when applying

Fixed this, and

>
> > window correctly.
> >
> > Find proper memory region for relocation by scanning MMAP SFI table in
> > board_get_usable_ram_top() callback.
> >
> > According to the address map documentation the Main Memory is guaranteed to lie
> > in the 0..2 GB range, that's why we limit search by this range.
> >
> > Fixes: e71de54a4943 ("x86: Add Intel Tangier support")
> > Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
> > ---
> >  arch/x86/cpu/tangier/sdram.c | 43 ++++++++++++++++++++++++++++++++++++
> >  1 file changed, 43 insertions(+)
> >
>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

applied to u-boot-x86, thanks!
diff mbox series

Patch

diff --git a/arch/x86/cpu/tangier/sdram.c b/arch/x86/cpu/tangier/sdram.c
index df3b9e4ec975..afb08476ed3b 100644
--- a/arch/x86/cpu/tangier/sdram.c
+++ b/arch/x86/cpu/tangier/sdram.c
@@ -196,6 +196,49 @@  unsigned int install_e820_map(unsigned int max_entries,
 	return sfi_setup_e820(max_entries, entries);
 }
 
+/*
+ * This function looks for the highest region of memory lower than 2GB which
+ * has enough space for U-Boot where U-Boot is aligned on a page boundary. It
+ * overrides the default implementation found elsewhere which simply picks the
+ * end of RAM, wherever that may be. The location of the stack, the relocation
+ * address, and how far U-Boot is moved by relocation are set in the global
+ * data structure.
+ */
+ulong board_get_usable_ram_top(ulong total_size)
+{
+	struct sfi_table_simple *sb;
+	struct sfi_mem_entry *mentry;
+	ulong dest_addr = 0;
+	u32 i;
+
+	sb = sfi_search_mmap();
+	if (!sb)
+		panic("No available memory found for relocation");
+
+	sfi_for_each_mentry(i, sb, mentry) {
+		unsigned long long start, end;
+
+		if (mentry->type != SFI_MEM_CONV)
+			continue;
+
+		start = mentry->phys_start;
+		end = start + (mentry->pages << 12);
+
+		/* Filter memory over 2GB. */
+		if (end > 0x7fffffffULL)
+			end = 0x80000000ULL;
+		/* Skip this region if it's too small. */
+		if (end - start < total_size)
+			continue;
+
+		/* Use this address if it's the largest so far. */
+		if (end > dest_addr)
+			dest_addr = end;
+	}
+
+	return dest_addr;
+}
+
 int dram_init_banksize(void)
 {
 	sfi_get_bank_size();