All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andy.shevchenko@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v5 3/8] x86: slimbootloader: Add memory configuration
Date: Mon, 22 Jul 2019 18:33:44 +0300	[thread overview]
Message-ID: <CAHp75VeaLWZtE7E+8YR3gTN6MEhSNuXPhe=QD_+Hr3Z27Vkbkw@mail.gmail.com> (raw)
In-Reply-To: <A1484485FD99714DB2AB2C5EF81E7AC2AA7467F7@ORSMSX116.amr.corp.intel.com>

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

  reply	other threads:[~2019-07-22 15:33 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2019-07-23  5:51   ` Bin Meng
2019-07-23 12:21     ` Andy Shevchenko
2019-07-24  2:53   ` Park, Aiden

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAHp75VeaLWZtE7E+8YR3gTN6MEhSNuXPhe=QD_+Hr3Z27Vkbkw@mail.gmail.com' \
    --to=andy.shevchenko@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.