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+
11 #include <asm/arch/sysinfo.h>
12 #include <asm/arch/tables.h>
14 DECLARE_GLOBAL_DATA_PTR;
16 unsigned install_e820_map(unsigned max_entries, struct e820entry *entries)
21 num_entries = min((unsigned)lib_sysinfo.n_memranges, max_entries);
22 if (num_entries < lib_sysinfo.n_memranges) {
23 printf("Warning: Limiting e820 map to %d entries.\n",
26 for (i = 0; i < num_entries; i++) {
27 struct memrange *memrange = &lib_sysinfo.memrange[i];
29 entries[i].addr = memrange->base;
30 entries[i].size = memrange->size;
33 * coreboot has some extensions (type 6 & 16) to the E820 types.
34 * When we detect this, mark it as E820_RESERVED.
36 if (memrange->type == CB_MEM_VENDOR_RSVD ||
37 memrange->type == CB_MEM_TABLE)
38 entries[i].type = E820_RESERVED;
40 entries[i].type = memrange->type;
47 * This function looks for the highest region of memory lower than 4GB which
48 * has enough space for U-Boot where U-Boot is aligned on a page boundary. It
49 * overrides the default implementation found elsewhere which simply picks the
50 * end of ram, wherever that may be. The location of the stack, the relocation
51 * address, and how far U-Boot is moved by relocation are set in the global
54 ulong board_get_usable_ram_top(ulong total_size)
56 uintptr_t dest_addr = 0;
59 for (i = 0; i < lib_sysinfo.n_memranges; i++) {
60 struct memrange *memrange = &lib_sysinfo.memrange[i];
61 /* Force U-Boot to relocate to a page aligned address. */
62 uint64_t start = roundup(memrange->base, 1 << 12);
63 uint64_t end = memrange->base + memrange->size;
65 /* Ignore non-memory regions. */
66 if (memrange->type != CB_MEM_RAM)
69 /* Filter memory over 4GB. */
70 if (end > 0xffffffffULL)
72 /* Skip this region if it's too small. */
73 if (end - start < total_size)
76 /* Use this address if it's the largest so far. */
81 /* If no suitable area was found, return an error. */
83 panic("No available memory found for relocation");
85 return (ulong)dest_addr;
91 phys_size_t ram_size = 0;
93 for (i = 0; i < lib_sysinfo.n_memranges; i++) {
94 struct memrange *memrange = &lib_sysinfo.memrange[i];
95 unsigned long long end = memrange->base + memrange->size;
97 if (memrange->type == CB_MEM_RAM && end > ram_size &&
98 memrange->base < (1ULL << 32))
101 gd->ram_size = ram_size;
108 void dram_init_banksize(void)
112 if (CONFIG_NR_DRAM_BANKS) {
113 for (i = 0, j = 0; i < lib_sysinfo.n_memranges; i++) {
114 struct memrange *memrange = &lib_sysinfo.memrange[i];
116 if (memrange->type == CB_MEM_RAM &&
117 memrange->base < (1ULL << 32)) {
118 gd->bd->bi_dram[j].start = memrange->base;
119 gd->bd->bi_dram[j].size = memrange->size;
121 if (j >= CONFIG_NR_DRAM_BANKS)