1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) 2011 The Chromium OS Authors.
4 * (C) Copyright 2010,2011
5 * Graeme Russ, <graeme.russ@gmail.com>
11 #include <asm/cb_sysinfo.h>
12 #include <asm/global_data.h>
14 DECLARE_GLOBAL_DATA_PTR;
16 unsigned int install_e820_map(unsigned int max_entries,
17 struct e820_entry *entries)
19 return cb_install_e820_map(max_entries, entries);
23 * This function looks for the highest region of memory lower than 4GB which
24 * has enough space for U-Boot where U-Boot is aligned on a page boundary. It
25 * overrides the default implementation found elsewhere which simply picks the
26 * end of ram, wherever that may be. The location of the stack, the relocation
27 * address, and how far U-Boot is moved by relocation are set in the global
30 phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
32 uintptr_t dest_addr = 0;
35 for (i = 0; i < lib_sysinfo.n_memranges; i++) {
36 struct memrange *memrange = &lib_sysinfo.memrange[i];
37 /* Force U-Boot to relocate to a page aligned address. */
38 uint64_t start = roundup(memrange->base, 1 << 12);
39 uint64_t end = memrange->base + memrange->size;
41 /* Ignore non-memory regions. */
42 if (memrange->type != CB_MEM_RAM)
45 /* Filter memory over 4GB. */
46 if (end > 0xffffffffULL)
48 /* Skip this region if it's too small. */
49 if (end - start < total_size)
52 /* Use this address if it's the largest so far. */
57 /* If no suitable area was found, return an error. */
59 panic("No available memory found for relocation");
61 return (ulong)dest_addr;
67 phys_size_t ram_size = 0;
69 for (i = 0; i < lib_sysinfo.n_memranges; i++) {
70 struct memrange *memrange = &lib_sysinfo.memrange[i];
71 unsigned long long end = memrange->base + memrange->size;
73 if (memrange->type == CB_MEM_RAM && end > ram_size)
74 ram_size += memrange->size;
77 gd->ram_size = ram_size;
84 int dram_init_banksize(void)
88 if (CONFIG_NR_DRAM_BANKS) {
89 for (i = 0, j = 0; i < lib_sysinfo.n_memranges; i++) {
90 struct memrange *memrange = &lib_sysinfo.memrange[i];
92 if (memrange->type == CB_MEM_RAM) {
93 gd->bd->bi_dram[j].start = memrange->base;
94 gd->bd->bi_dram[j].size = memrange->size;
96 if (j >= CONFIG_NR_DRAM_BANKS)