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>
|
|
|
|
*
|
2013-07-08 07:37:19 +00:00
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
2011-11-29 18:05:07 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2011-12-05 12:09:25 +00:00
|
|
|
#include <malloc.h>
|
|
|
|
#include <asm/e820.h>
|
2011-11-29 18:05:07 +00:00
|
|
|
#include <asm/u-boot-x86.h>
|
2011-12-05 12:09:25 +00:00
|
|
|
#include <asm/global_data.h>
|
2012-12-03 14:26:08 +00:00
|
|
|
#include <asm/processor.h>
|
2013-03-05 14:39:54 +00:00
|
|
|
#include <asm/sections.h>
|
2012-12-03 14:26:08 +00:00
|
|
|
#include <asm/arch/sysinfo.h>
|
|
|
|
#include <asm/arch/tables.h>
|
2011-11-29 18:05:07 +00:00
|
|
|
|
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2011-12-05 12:09:25 +00:00
|
|
|
unsigned install_e820_map(unsigned max_entries, struct e820entry *entries)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
unsigned num_entries = min(lib_sysinfo.n_memranges, max_entries);
|
|
|
|
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;
|
|
|
|
entries[i].type = memrange->type;
|
|
|
|
}
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2011-11-29 18:05:07 +00:00
|
|
|
int dram_init_f(void)
|
|
|
|
{
|
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;
|
|
|
|
|
|
|
|
if (memrange->type == CB_MEM_RAM && end > ram_size)
|
|
|
|
ram_size = end;
|
|
|
|
}
|
|
|
|
gd->ram_size = ram_size;
|
|
|
|
if (ram_size == 0)
|
|
|
|
return -1;
|
2011-11-29 18:05:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-04-15 11:22:49 +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];
|
|
|
|
|
|
|
|
if (memrange->type == CB_MEM_RAM) {
|
|
|
|
gd->bd->bi_dram[j].start = memrange->base;
|
|
|
|
gd->bd->bi_dram[j].size = memrange->size;
|
|
|
|
j++;
|
|
|
|
if (j >= CONFIG_NR_DRAM_BANKS)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-11-29 18:05:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2013-04-15 11:22:49 +00:00
|
|
|
|
|
|
|
int dram_init(void)
|
|
|
|
{
|
|
|
|
return dram_init_banksize();
|
|
|
|
}
|