2 * Copyright (c) 2011 The Chromium OS Authors.
3 * (C) Copyright 2010,2011
4 * Graeme Russ, <graeme.russ@gmail.com>
6 * SPDX-License-Identifier: GPL-2.0+
12 #include <asm/u-boot-x86.h>
13 #include <asm/global_data.h>
14 #include <asm/processor.h>
15 #include <asm/sections.h>
16 #include <asm/arch/sysinfo.h>
17 #include <asm/arch/tables.h>
19 DECLARE_GLOBAL_DATA_PTR;
21 unsigned install_e820_map(unsigned max_entries, struct e820entry *entries)
25 unsigned num_entries = min(lib_sysinfo.n_memranges, max_entries);
26 if (num_entries < lib_sysinfo.n_memranges) {
27 printf("Warning: Limiting e820 map to %d entries.\n",
30 for (i = 0; i < num_entries; i++) {
31 struct memrange *memrange = &lib_sysinfo.memrange[i];
33 entries[i].addr = memrange->base;
34 entries[i].size = memrange->size;
35 entries[i].type = memrange->type;
41 * This function looks for the highest region of memory lower than 4GB which
42 * has enough space for U-Boot where U-Boot is aligned on a page boundary. It
43 * overrides the default implementation found elsewhere which simply picks the
44 * end of ram, wherever that may be. The location of the stack, the relocation
45 * address, and how far U-Boot is moved by relocation are set in the global
48 ulong board_get_usable_ram_top(ulong total_size)
50 uintptr_t dest_addr = 0;
53 for (i = 0; i < lib_sysinfo.n_memranges; i++) {
54 struct memrange *memrange = &lib_sysinfo.memrange[i];
55 /* Force U-Boot to relocate to a page aligned address. */
56 uint64_t start = roundup(memrange->base, 1 << 12);
57 uint64_t end = memrange->base + memrange->size;
59 /* Ignore non-memory regions. */
60 if (memrange->type != CB_MEM_RAM)
63 /* Filter memory over 4GB. */
64 if (end > 0xffffffffULL)
66 /* Skip this region if it's too small. */
67 if (end - start < total_size)
70 /* Use this address if it's the largest so far. */
75 /* If no suitable area was found, return an error. */
77 panic("No available memory found for relocation");
79 return (ulong)dest_addr;
85 phys_size_t ram_size = 0;
87 for (i = 0; i < lib_sysinfo.n_memranges; i++) {
88 struct memrange *memrange = &lib_sysinfo.memrange[i];
89 unsigned long long end = memrange->base + memrange->size;
91 if (memrange->type == CB_MEM_RAM && end > ram_size)
94 gd->ram_size = ram_size;
100 int dram_init_banksize(void)
104 if (CONFIG_NR_DRAM_BANKS) {
105 for (i = 0, j = 0; i < lib_sysinfo.n_memranges; i++) {
106 struct memrange *memrange = &lib_sysinfo.memrange[i];
108 if (memrange->type == CB_MEM_RAM) {
109 gd->bd->bi_dram[j].start = memrange->base;
110 gd->bd->bi_dram[j].size = memrange->size;
112 if (j >= CONFIG_NR_DRAM_BANKS)
122 return dram_init_banksize();