* [U-Boot] [PATCH v5 3/8] x86: slimbootloader: Add memory configuration
@ 2019-07-17 4:41 Park, Aiden
2019-07-22 15:33 ` Andy Shevchenko
0 siblings, 1 reply; 5+ messages in thread
From: Park, Aiden @ 2019-07-17 4:41 UTC (permalink / raw)
To: u-boot
Slim Bootloader provides memory map info thru its HOB list pointer.
Configure memory size and relocation memory from the HOB data, and
provide e820 entries as well.
- Get memory size from the memory map info hob
- Set ram top for U-Boot relocation lower than 4GB
- Provide e820 entries from the memory map info hob
Signed-off-by: Aiden Park <aiden.park@intel.com>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---
Changes in v3:
* Use HOB function from the common HOB library
* Add more description
arch/x86/cpu/slimbootloader/Makefile | 2 +-
arch/x86/cpu/slimbootloader/dram.c | 151 ++++++++++++++++++
.../asm/arch-slimbootloader/slimbootloader.h | 44 +++++
3 files changed, 196 insertions(+), 1 deletion(-)
create mode 100644 arch/x86/cpu/slimbootloader/dram.c
diff --git a/arch/x86/cpu/slimbootloader/Makefile b/arch/x86/cpu/slimbootloader/Makefile
index 627a721e8c..05d0ca4a19 100644
--- a/arch/x86/cpu/slimbootloader/Makefile
+++ b/arch/x86/cpu/slimbootloader/Makefile
@@ -2,4 +2,4 @@
#
# Copyright (C) 2019 Intel Corporation <www.intel.com>
-obj-y += car.o slimbootloader.o
+obj-y += car.o slimbootloader.o dram.o
diff --git a/arch/x86/cpu/slimbootloader/dram.c b/arch/x86/cpu/slimbootloader/dram.c
new file mode 100644
index 0000000000..b52cbe7ec4
--- /dev/null
+++ b/arch/x86/cpu/slimbootloader/dram.c
@@ -0,0 +1,151 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2019 Intel Corporation <www.intel.com>
+ */
+
+#include <common.h>
+#include <linux/sizes.h>
+#include <asm/e820.h>
+#include <asm/arch/slimbootloader.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+/**
+ * This returns a data pointer of memory map info from the guid hob.
+ *
+ * @return: A data pointer of memory map info hob
+ */
+static void *get_memory_map_info(void)
+{
+ const struct efi_guid guid = LOADER_MEMORY_MAP_INFO_GUID;
+
+ if (!gd->arch.hob_list)
+ return NULL;
+
+ return hob_get_guid_hob_data(gd->arch.hob_list, NULL, &guid);
+}
+
+/**
+ * This is to give usable memory region information for u-boot relocation.
+ * so search usable memory region lower than 4GB.
+ * The memory map entries from Slim Bootloader hob are already sorted.
+ *
+ * @total_size: The memory size that u-boot occupies
+ * @return : The top available memory address lower than 4GB
+ */
+ulong board_get_usable_ram_top(ulong total_size)
+{
+ struct memory_map_info *data = NULL;
+ int i = 0;
+ phys_addr_t addr_start = 0;
+ phys_addr_t addr_end = 0;
+ ulong ram_top = 0;
+
+ data = (struct memory_map_info *)get_memory_map_info();
+ if (!data)
+ panic("memory map info hob not found\n");
+
+ /**
+ * sorted memory map entries from Slim Bootloader based on physical
+ * start memory address, from low to high. So do reversed search to
+ * get highest usable, suitable size, 4KB aligned available memory
+ * under 4GB.
+ */
+ for (i = data->count - 1; i >= 0; i--) {
+ if (data->entry[i].type != E820_RAM)
+ continue;
+
+ addr_start = data->entry[i].addr;
+ addr_end = addr_start + data->entry[i].size;
+
+ if (addr_start > SZ_4G)
+ continue;
+
+ if (addr_end > SZ_4G)
+ addr_end = SZ_4G;
+
+ if (addr_end < total_size)
+ continue;
+
+ /* to relocate u-boot@4K aligned memory */
+ addr_end = rounddown(addr_end - total_size, SZ_4K);
+ if (addr_end >= addr_start) {
+ ram_top = (ulong)addr_end + total_size;
+ break;
+ }
+ }
+
+ if (!ram_top)
+ panic("failed to find available memory for relocation!");
+
+ return ram_top;
+}
+
+/**
+ * The memory initialization has already been done in previous Slim Bootloader
+ * stage thru FSP-M. Instead, this sets the ram_size from the memory map info
+ * hob.
+ */
+int dram_init(void)
+{
+ struct memory_map_info *data = NULL;
+ int i = 0;
+ phys_size_t ram_size = 0;
+
+ data = (struct memory_map_info *)get_memory_map_info();
+ if (!data)
+ panic("memory map info hob not found\n");
+
+ /**
+ * sorted memory map entries from Slim Bootloader based on physical
+ * start memory address, from low to high. So do reversed search to
+ * simply get highest usable memory address as ram size
+ */
+ for (i = data->count - 1; i >= 0; i--) {
+ if (data->entry[i].type != E820_RAM)
+ continue;
+
+ /* simply use the highest usable memory address as ram size */
+ ram_size = data->entry[i].addr + data->entry[i].size;
+ break;
+ }
+
+ if (!ram_size)
+ panic("failed to detect memory size");
+
+ gd->ram_size = ram_size;
+ return 0;
+}
+
+int dram_init_banksize(void)
+{
+ /* simply use a single bank to have whole size for now */
+ if (CONFIG_NR_DRAM_BANKS) {
+ gd->bd->bi_dram[0].start = 0;
+ gd->bd->bi_dram[0].size = gd->ram_size;
+ }
+ return 0;
+}
+
+unsigned int install_e820_map(unsigned int max_entries,
+ struct e820_entry *entries)
+{
+ struct memory_map_info *data = NULL;
+ int i = 0;
+ unsigned int num_entries = 0;
+
+ data = (struct memory_map_info *)get_memory_map_info();
+ if (!data) {
+ debug("memory map info hob not found\n");
+ return 0;
+ }
+
+ for (i = 0; i < data->count; i++) {
+ entries[num_entries].addr = data->entry[i].addr;
+ entries[num_entries].size = data->entry[i].size;
+ entries[num_entries].type = data->entry[i].type;
+ num_entries++;
+ }
+
+ return num_entries;
+}
diff --git a/arch/x86/include/asm/arch-slimbootloader/slimbootloader.h b/arch/x86/include/asm/arch-slimbootloader/slimbootloader.h
index 7309a83724..d9265ac534 100644
--- a/arch/x86/include/asm/arch-slimbootloader/slimbootloader.h
+++ b/arch/x86/include/asm/arch-slimbootloader/slimbootloader.h
@@ -7,5 +7,49 @@
#define __SLIMBOOTLOADER_ARCH_H__
#include <common.h>
+#include <asm/hob.h>
+
+/**
+ * A GUID to get MemoryMap info hob which is provided by Slim Bootloader
+ */
+#define LOADER_MEMORY_MAP_INFO_GUID \
+ { \
+ 0xa1ff7424, 0x7a1a, 0x478e, \
+ { 0xa9, 0xe4, 0x92, 0xf3, 0x57, 0xd1, 0x28, 0x32 } \
+ }
+
+/**
+ * A single entry of memory map information
+ *
+ * @addr: start address of a memory map entry
+ * @size: size of a memory map entry
+ * @type: usable:1, reserved:2, acpi:3, nvs:4, unusable:5
+ * @flag: only used in Slim Bootloader
+ * @rsvd: padding for alignment
+ */
+struct memory_map_entry {
+ phys_addr_t addr;
+ phys_size_t size;
+ u8 type;
+ u8 flag;
+ u8 rsvd[6];
+} __packed;
+
+/**
+ * This includes all memory map entries which is sorted based on physical start
+ * address, from low to high, and carved out reserved, acpi nvs, acpi reclaim
+ * and usable memory.
+ *
+ * @rev : revision of memory_map_info structure. currently 1.
+ * @rsvd : padding for alignment
+ * @count: the number of memory map entries
+ * @entry: array of all memory map entries
+ */
+struct memory_map_info {
+ u8 rev;
+ u8 rsvd[3];
+ u32 count;
+ struct memory_map_entry entry[0];
+} __packed;
#endif
--
2.20.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH v5 3/8] x86: slimbootloader: Add memory configuration
2019-07-17 4:41 [U-Boot] [PATCH v5 3/8] x86: slimbootloader: Add memory configuration Park, Aiden
@ 2019-07-22 15:33 ` Andy Shevchenko
2019-07-23 5:51 ` Bin Meng
2019-07-24 2:53 ` Park, Aiden
0 siblings, 2 replies; 5+ messages in thread
From: Andy Shevchenko @ 2019-07-22 15:33 UTC (permalink / raw)
To: u-boot
On Wed, Jul 17, 2019 at 7:41 AM Park, Aiden <aiden.park@intel.com> wrote:
>
> Slim Bootloader provides memory map info thru its HOB list pointer.
> Configure memory size and relocation memory from the HOB data, and
> provide e820 entries as well.
> - Get memory size from the memory map info hob
> - Set ram top for U-Boot relocation lower than 4GB
> - Provide e820 entries from the memory map info hob
> +++ b/arch/x86/cpu/slimbootloader/dram.c
sdram.c is more common name in the sources AFAICS.
> +ulong board_get_usable_ram_top(ulong total_size)
> +{
> + struct memory_map_info *data = NULL;
> + int i = 0;
> + phys_addr_t addr_start = 0;
> + phys_addr_t addr_end = 0;
Unnecessary assignments (check entire series for them).
> + data = (struct memory_map_info *)get_memory_map_info();
Casting from / to void * is redundant. Check entire series.
> + if (!data)
> + panic("memory map info hob not found\n");
> + /**
> + * sorted memory map entries from Slim Bootloader based on physical
> + * start memory address, from low to high. So do reversed search to
> + * get highest usable, suitable size, 4KB aligned available memory
> + * under 4GB.
> + */
> + for (i = data->count - 1; i >= 0; i--) {
Hmm... Maybe
i = data->count;
while (i--) {
...
}
Easier to read.
> + if (data->entry[i].type != E820_RAM)
> + continue;
> +
> + addr_start = data->entry[i].addr;
> + addr_end = addr_start + data->entry[i].size;
> +
> + if (addr_start > SZ_4G)
> + continue;
> +
> + if (addr_end > SZ_4G)
> + addr_end = SZ_4G;
> +
> + if (addr_end < total_size)
> + continue;
> +
> + /* to relocate u-boot at 4K aligned memory */
u-boot -> U-Boot
> + addr_end = rounddown(addr_end - total_size, SZ_4K);
> + if (addr_end >= addr_start) {
> + ram_top = (ulong)addr_end + total_size;
> + break;
> + }
> + }
> +
> + if (!ram_top)
> + panic("failed to find available memory for relocation!");
> +
> + return ram_top;
> +}
> +
> +/**
> + * The memory initialization has already been done in previous Slim Bootloader
> + * stage thru FSP-M. Instead, this sets the ram_size from the memory map info
> + * hob.
> + */
> +int dram_init(void)
> +{
> + struct memory_map_info *data = NULL;
> + int i = 0;
> + phys_size_t ram_size = 0;
> +
> + data = (struct memory_map_info *)get_memory_map_info();
> + if (!data)
> + panic("memory map info hob not found\n");
> +
> + /**
> + * sorted memory map entries from Slim Bootloader based on physical
> + * start memory address, from low to high. So do reversed search to
> + * simply get highest usable memory address as ram size
> + */
> + for (i = data->count - 1; i >= 0; i--) {
> + if (data->entry[i].type != E820_RAM)
> + continue;
Second time?
Perhaps you may do rather macro:
#define for_each_map_info_entry_reversed(...) \
for () \
if (!cond) {} else
> +
> + /* simply use the highest usable memory address as ram size */
ram -> RAM
> + ram_size = data->entry[i].addr + data->entry[i].size;
> + break;
> + }
> +
> + if (!ram_size)
> + panic("failed to detect memory size");
> +
> + gd->ram_size = ram_size;
> + return 0;
> +}
> +int dram_init_banksize(void)
> +{
> + /* simply use a single bank to have whole size for now */
> + if (CONFIG_NR_DRAM_BANKS) {
if (!foo) might be slightly better if ever this code gets modified.
> + gd->bd->bi_dram[0].start = 0;
> + gd->bd->bi_dram[0].size = gd->ram_size;
> + }
> + return 0;
> +}
> +#define LOADER_MEMORY_MAP_INFO_GUID \
> + { \
> + 0xa1ff7424, 0x7a1a, 0x478e, \
> + { 0xa9, 0xe4, 0x92, 0xf3, 0x57, 0xd1, 0x28, 0x32 } \
> + }
EFI_GUID() ?
> +/**
> + * A single entry of memory map information
> + *
> + * @addr: start address of a memory map entry
> + * @size: size of a memory map entry
> + * @type: usable:1, reserved:2, acpi:3, nvs:4, unusable:5
> + * @flag: only used in Slim Bootloader
> + * @rsvd: padding for alignment
> + */
> +struct memory_map_entry {
> + phys_addr_t addr;
> + phys_size_t size;
This is comes from hardware, isn't it? Probably better to use fixed width typo
> + u8 type;
> + u8 flag;
> + u8 rsvd[6];
> +} __packed;
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH v5 3/8] x86: slimbootloader: Add memory configuration
2019-07-22 15:33 ` Andy Shevchenko
@ 2019-07-23 5:51 ` Bin Meng
2019-07-23 12:21 ` Andy Shevchenko
2019-07-24 2:53 ` Park, Aiden
1 sibling, 1 reply; 5+ messages in thread
From: Bin Meng @ 2019-07-23 5:51 UTC (permalink / raw)
To: u-boot
On Mon, Jul 22, 2019 at 11:33 PM Andy Shevchenko
<andy.shevchenko@gmail.com> wrote:
>
> On Wed, Jul 17, 2019 at 7:41 AM Park, Aiden <aiden.park@intel.com> wrote:
> >
> > Slim Bootloader provides memory map info thru its HOB list pointer.
> > Configure memory size and relocation memory from the HOB data, and
> > provide e820 entries as well.
> > - Get memory size from the memory map info hob
> > - Set ram top for U-Boot relocation lower than 4GB
> > - Provide e820 entries from the memory map info hob
>
> > +++ b/arch/x86/cpu/slimbootloader/dram.c
>
> sdram.c is more common name in the sources AFAICS.
Looks we have both sdram.c and dram.c :)
[snip]
Regards,
Bin
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH v5 3/8] x86: slimbootloader: Add memory configuration
2019-07-23 5:51 ` Bin Meng
@ 2019-07-23 12:21 ` Andy Shevchenko
0 siblings, 0 replies; 5+ messages in thread
From: Andy Shevchenko @ 2019-07-23 12:21 UTC (permalink / raw)
To: u-boot
On Tue, Jul 23, 2019 at 8:51 AM Bin Meng <bmeng.cn@gmail.com> wrote:
> On Mon, Jul 22, 2019 at 11:33 PM Andy Shevchenko
> <andy.shevchenko@gmail.com> wrote:
> > On Wed, Jul 17, 2019 at 7:41 AM Park, Aiden <aiden.park@intel.com> wrote:
> > >
> > > Slim Bootloader provides memory map info thru its HOB list pointer.
> > > Configure memory size and relocation memory from the HOB data, and
> > > provide e820 entries as well.
> > > - Get memory size from the memory map info hob
> > > - Set ram top for U-Boot relocation lower than 4GB
> > > - Provide e820 entries from the memory map info hob
> >
> > > +++ b/arch/x86/cpu/slimbootloader/dram.c
> >
> > sdram.c is more common name in the sources AFAICS.
>
> Looks we have both sdram.c and dram.c :)
True, but among x86 platforms sdram is *more* common.
--
With Best Regards,
Andy Shevchenko
^ permalink raw reply [flat|nested] 5+ messages in thread
* [U-Boot] [PATCH v5 3/8] x86: slimbootloader: Add memory configuration
2019-07-22 15:33 ` Andy Shevchenko
2019-07-23 5:51 ` Bin Meng
@ 2019-07-24 2:53 ` Park, Aiden
1 sibling, 0 replies; 5+ messages in thread
From: Park, Aiden @ 2019-07-24 2:53 UTC (permalink / raw)
To: u-boot
Hi Andy,
> -----Original Message-----
> From: Andy Shevchenko [mailto:andy.shevchenko at gmail.com]
> Sent: Monday, July 22, 2019 8:34 AM
> To: Park, Aiden <aiden.park@intel.com>
> Cc: U-Boot Mailing List <u-boot@lists.denx.de>; Simon Glass
> <sjg@chromium.org>; Bin Meng <bmeng.cn@gmail.com>
> Subject: Re: [PATCH v5 3/8] x86: slimbootloader: Add memory configuration
>
> On Wed, Jul 17, 2019 at 7:41 AM Park, Aiden <aiden.park@intel.com> wrote:
> >
> > Slim Bootloader provides memory map info thru its HOB list pointer.
> > Configure memory size and relocation memory from the HOB data, and
> > provide e820 entries as well.
> > - Get memory size from the memory map info hob
> > - Set ram top for U-Boot relocation lower than 4GB
> > - Provide e820 entries from the memory map info hob
>
> > +++ b/arch/x86/cpu/slimbootloader/dram.c
>
> sdram.c is more common name in the sources AFAICS.
>
Okay. let me use sdram.
> > +ulong board_get_usable_ram_top(ulong total_size) {
> > + struct memory_map_info *data = NULL;
> > + int i = 0;
> > + phys_addr_t addr_start = 0;
> > + phys_addr_t addr_end = 0;
>
> Unnecessary assignments (check entire series for them).
>
Okay. let me check this in entire series.
> > + data = (struct memory_map_info *)get_memory_map_info();
>
> Casting from / to void * is redundant. Check entire series.
>
Do you mean casting void * to (struct *)? Anyway, let me remove casting if redundant in entire series.
> > + if (!data)
> > + panic("memory map info hob not found\n");
>
> > + /**
> > + * sorted memory map entries from Slim Bootloader based on physical
> > + * start memory address, from low to high. So do reversed search to
> > + * get highest usable, suitable size, 4KB aligned available memory
> > + * under 4GB.
> > + */
>
> > + for (i = data->count - 1; i >= 0; i--) {
>
> Hmm... Maybe
>
> i = data->count;
> while (i--) {
> ...
> }
>
> Easier to read.
>
Okay. let me change this.
> > + if (data->entry[i].type != E820_RAM)
> > + continue;
> > +
> > + addr_start = data->entry[i].addr;
> > + addr_end = addr_start + data->entry[i].size;
> > +
> > + if (addr_start > SZ_4G)
> > + continue;
> > +
> > + if (addr_end > SZ_4G)
> > + addr_end = SZ_4G;
> > +
> > + if (addr_end < total_size)
> > + continue;
> > +
>
> > + /* to relocate u-boot at 4K aligned memory */
>
> u-boot -> U-Boot
>
Let me change this.
> > + addr_end = rounddown(addr_end - total_size, SZ_4K);
> > + if (addr_end >= addr_start) {
> > + ram_top = (ulong)addr_end + total_size;
> > + break;
> > + }
> > + }
> > +
> > + if (!ram_top)
> > + panic("failed to find available memory for
> > + relocation!");
> > +
> > + return ram_top;
> > +}
> > +
> > +/**
> > + * The memory initialization has already been done in previous Slim
> > +Bootloader
> > + * stage thru FSP-M. Instead, this sets the ram_size from the memory
> > +map info
> > + * hob.
> > + */
> > +int dram_init(void)
> > +{
> > + struct memory_map_info *data = NULL;
> > + int i = 0;
> > + phys_size_t ram_size = 0;
> > +
> > + data = (struct memory_map_info *)get_memory_map_info();
> > + if (!data)
> > + panic("memory map info hob not found\n");
> > +
> > + /**
> > + * sorted memory map entries from Slim Bootloader based on physical
> > + * start memory address, from low to high. So do reversed search to
> > + * simply get highest usable memory address as ram size
> > + */
>
> > + for (i = data->count - 1; i >= 0; i--) {
> > + if (data->entry[i].type != E820_RAM)
> > + continue;
>
> Second time?
>
> Perhaps you may do rather macro:
>
> #define for_each_map_info_entry_reversed(...) \
> for () \
> if (!cond) {} else
>
Okay, let me use macro.
> > +
> > + /* simply use the highest usable memory address as ram
> > + size */
>
> ram -> RAM
>
Let me change this.
> > + ram_size = data->entry[i].addr + data->entry[i].size;
> > + break;
> > + }
> > +
> > + if (!ram_size)
> > + panic("failed to detect memory size");
> > +
> > + gd->ram_size = ram_size;
> > + return 0;
> > +}
>
> > +int dram_init_banksize(void)
> > +{
> > + /* simply use a single bank to have whole size for now */
> > + if (CONFIG_NR_DRAM_BANKS) {
>
> if (!foo) might be slightly better if ever this code gets modified.
>
Okay. Let me change this.
> > + gd->bd->bi_dram[0].start = 0;
> > + gd->bd->bi_dram[0].size = gd->ram_size;
> > + }
> > + return 0;
> > +}
>
> > +#define LOADER_MEMORY_MAP_INFO_GUID \
> > + { \
> > + 0xa1ff7424, 0x7a1a, 0x478e, \
> > + { 0xa9, 0xe4, 0x92, 0xf3, 0x57, 0xd1, 0x28, 0x32 } \
> > + }
>
> EFI_GUID() ?
>
Okay, let me use EFI_GUID.
> > +/**
> > + * A single entry of memory map information
> > + *
> > + * @addr: start address of a memory map entry
> > + * @size: size of a memory map entry
> > + * @type: usable:1, reserved:2, acpi:3, nvs:4, unusable:5
> > + * @flag: only used in Slim Bootloader
> > + * @rsvd: padding for alignment
> > + */
> > +struct memory_map_entry {
>
> > + phys_addr_t addr;
> > + phys_size_t size;
>
> This is comes from hardware, isn't it? Probably better to use fixed width typo
>
Okay, let me use u64 for address and size.
> > + u8 type;
> > + u8 flag;
> > + u8 rsvd[6];
> > +} __packed;
>
> --
> With Best Regards,
> Andy Shevchenko
Best Regards,
Aiden
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2019-07-24 2:53 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-17 4:41 [U-Boot] [PATCH v5 3/8] x86: slimbootloader: Add memory configuration Park, Aiden
2019-07-22 15:33 ` Andy Shevchenko
2019-07-23 5:51 ` Bin Meng
2019-07-23 12:21 ` Andy Shevchenko
2019-07-24 2:53 ` Park, Aiden
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.