2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2011-11-29 18:05:07 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2011 The Chromium OS Authors.
|
|
|
|
* (C) Copyright 2010,2011
|
|
|
|
* Graeme Russ, <graeme.russ@gmail.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2019-11-14 19:57:45 +00:00
|
|
|
#include <init.h>
|
2011-12-05 12:09:25 +00:00
|
|
|
#include <asm/e820.h>
|
2012-12-03 14:26:08 +00:00
|
|
|
#include <asm/arch/sysinfo.h>
|
2011-11-29 18:05:07 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2018-04-12 05:02:10 +00:00
|
|
|
unsigned int install_e820_map(unsigned int max_entries,
|
2018-04-12 05:02:11 +00:00
|
|
|
struct e820_entry *entries)
|
2011-12-05 12:09:25 +00:00
|
|
|
{
|
2018-04-12 05:02:10 +00:00
|
|
|
unsigned int num_entries;
|
2011-12-05 12:09:25 +00:00
|
|
|
int i;
|
|
|
|
|
2018-04-12 05:02:10 +00:00
|
|
|
num_entries = min((unsigned int)lib_sysinfo.n_memranges, max_entries);
|
2011-12-05 12:09:25 +00:00
|
|
|
if (num_entries < lib_sysinfo.n_memranges) {
|
|
|
|
printf("Warning: Limiting e820 map to %d entries.\n",
|
|
|
|
num_entries);
|
|
|
|
}
|
|
|
|
for (i = 0; i < num_entries; i++) {
|
|
|
|
struct memrange *memrange = &lib_sysinfo.memrange[i];
|
|
|
|
|
|
|
|
entries[i].addr = memrange->base;
|
|
|
|
entries[i].size = memrange->size;
|
2015-08-13 07:29:09 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* coreboot has some extensions (type 6 & 16) to the E820 types.
|
|
|
|
* When we detect this, mark it as E820_RESERVED.
|
|
|
|
*/
|
|
|
|
if (memrange->type == CB_MEM_VENDOR_RSVD ||
|
|
|
|
memrange->type == CB_MEM_TABLE)
|
|
|
|
entries[i].type = E820_RESERVED;
|
|
|
|
else
|
|
|
|
entries[i].type = memrange->type;
|
2011-12-05 12:09:25 +00:00
|
|
|
}
|
2015-08-13 07:29:09 +00:00
|
|
|
|
2011-12-05 12:09:25 +00:00
|
|
|
return num_entries;
|
|
|
|
}
|
|
|
|
|
2012-12-03 14:26:08 +00:00
|
|
|
/*
|
|
|
|
* This function looks for the highest region of memory lower than 4GB which
|
|
|
|
* has enough space for U-Boot where U-Boot is aligned on a page boundary. It
|
|
|
|
* overrides the default implementation found elsewhere which simply picks the
|
|
|
|
* end of ram, wherever that may be. The location of the stack, the relocation
|
|
|
|
* address, and how far U-Boot is moved by relocation are set in the global
|
|
|
|
* data structure.
|
|
|
|
*/
|
2013-02-28 19:26:10 +00:00
|
|
|
ulong board_get_usable_ram_top(ulong total_size)
|
2012-12-03 14:26:08 +00:00
|
|
|
{
|
|
|
|
uintptr_t dest_addr = 0;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < lib_sysinfo.n_memranges; i++) {
|
|
|
|
struct memrange *memrange = &lib_sysinfo.memrange[i];
|
|
|
|
/* Force U-Boot to relocate to a page aligned address. */
|
|
|
|
uint64_t start = roundup(memrange->base, 1 << 12);
|
|
|
|
uint64_t end = memrange->base + memrange->size;
|
|
|
|
|
|
|
|
/* Ignore non-memory regions. */
|
|
|
|
if (memrange->type != CB_MEM_RAM)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Filter memory over 4GB. */
|
|
|
|
if (end > 0xffffffffULL)
|
|
|
|
end = 0x100000000ULL;
|
|
|
|
/* Skip this region if it's too small. */
|
|
|
|
if (end - start < total_size)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Use this address if it's the largest so far. */
|
2013-02-28 19:26:10 +00:00
|
|
|
if (end > dest_addr)
|
2012-12-03 14:26:08 +00:00
|
|
|
dest_addr = end;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If no suitable area was found, return an error. */
|
|
|
|
if (!dest_addr)
|
2013-02-28 19:26:10 +00:00
|
|
|
panic("No available memory found for relocation");
|
2012-12-03 14:26:08 +00:00
|
|
|
|
2013-02-28 19:26:10 +00:00
|
|
|
return (ulong)dest_addr;
|
2012-12-03 14:26:08 +00:00
|
|
|
}
|
|
|
|
|
2014-11-06 20:20:05 +00:00
|
|
|
int dram_init(void)
|
2011-11-29 18:05:07 +00:00
|
|
|
{
|
2011-12-05 12:09:25 +00:00
|
|
|
int i;
|
|
|
|
phys_size_t ram_size = 0;
|
|
|
|
|
|
|
|
for (i = 0; i < lib_sysinfo.n_memranges; i++) {
|
|
|
|
struct memrange *memrange = &lib_sysinfo.memrange[i];
|
|
|
|
unsigned long long end = memrange->base + memrange->size;
|
|
|
|
|
2015-08-13 07:29:11 +00:00
|
|
|
if (memrange->type == CB_MEM_RAM && end > ram_size)
|
|
|
|
ram_size += memrange->size;
|
2011-12-05 12:09:25 +00:00
|
|
|
}
|
2015-08-13 07:29:11 +00:00
|
|
|
|
2011-12-05 12:09:25 +00:00
|
|
|
gd->ram_size = ram_size;
|
|
|
|
if (ram_size == 0)
|
|
|
|
return -1;
|
2014-11-06 20:20:05 +00:00
|
|
|
|
2015-08-13 07:29:10 +00:00
|
|
|
return 0;
|
2011-11-29 18:05:07 +00:00
|
|
|
}
|
|
|
|
|
2017-03-31 14:40:32 +00:00
|
|
|
int dram_init_banksize(void)
|
2011-11-29 18:05:07 +00:00
|
|
|
{
|
2012-10-23 18:04:35 +00:00
|
|
|
int i, j;
|
|
|
|
|
|
|
|
if (CONFIG_NR_DRAM_BANKS) {
|
|
|
|
for (i = 0, j = 0; i < lib_sysinfo.n_memranges; i++) {
|
|
|
|
struct memrange *memrange = &lib_sysinfo.memrange[i];
|
|
|
|
|
2015-08-13 07:29:11 +00:00
|
|
|
if (memrange->type == CB_MEM_RAM) {
|
2012-10-23 18:04:35 +00:00
|
|
|
gd->bd->bi_dram[j].start = memrange->base;
|
|
|
|
gd->bd->bi_dram[j].size = memrange->size;
|
|
|
|
j++;
|
|
|
|
if (j >= CONFIG_NR_DRAM_BANKS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-03-31 14:40:32 +00:00
|
|
|
|
|
|
|
return 0;
|
2013-04-15 11:22:49 +00:00
|
|
|
}
|