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>
|
2014-11-06 20:20:05 +00:00
|
|
|
#include <asm/init_helpers.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>
|
2014-11-06 20:20:08 +00:00
|
|
|
#include <asm/zimage.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;
|
|
|
|
|
linux/kernel.h: sync min, max, min3, max3 macros with Linux
U-Boot has never cared about the type when we get max/min of two
values, but Linux Kernel does. This commit gets min, max, min3, max3
macros synced with the kernel introducing type checks.
Many of references of those macros must be fixed to suppress warnings.
We have two options:
- Use min, max, min3, max3 only when the arguments have the same type
(or add casts to the arguments)
- Use min_t/max_t instead with the appropriate type for the first
argument
Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
Acked-by: Pavel Machek <pavel@denx.de>
Acked-by: Lukasz Majewski <l.majewski@samsung.com>
Tested-by: Lukasz Majewski <l.majewski@samsung.com>
[trini: Fixup arch/blackfin/lib/string.c]
Signed-off-by: Tom Rini <trini@ti.com>
2014-11-06 18:03:31 +00:00
|
|
|
unsigned num_entries = min((unsigned)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;
|
|
|
|
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
|
|
|
}
|
|
|
|
|
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-03-02 19:40:49 +00:00
|
|
|
if (memrange->type == CB_MEM_RAM && end > ram_size &&
|
|
|
|
memrange->base < (1ULL << 32))
|
2011-12-05 12:09:25 +00:00
|
|
|
ram_size = end;
|
|
|
|
}
|
|
|
|
gd->ram_size = ram_size;
|
|
|
|
if (ram_size == 0)
|
|
|
|
return -1;
|
2014-11-06 20:20:05 +00:00
|
|
|
|
|
|
|
return calculate_relocation_address();
|
2011-11-29 18:05:07 +00:00
|
|
|
}
|
|
|
|
|
2014-11-06 20:20:08 +00:00
|
|
|
void 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-03-02 19:40:49 +00:00
|
|
|
if (memrange->type == CB_MEM_RAM &&
|
|
|
|
memrange->base < (1ULL << 32)) {
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-04-15 11:22:49 +00:00
|
|
|
}
|