]>
git.ipfire.org Git - people/ms/u-boot.git/blob - arch/x86/cpu/coreboot/sdram.c
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>
13 DECLARE_GLOBAL_DATA_PTR
;
15 unsigned install_e820_map(unsigned max_entries
, struct e820entry
*entries
)
20 num_entries
= min((unsigned)lib_sysinfo
.n_memranges
, max_entries
);
21 if (num_entries
< lib_sysinfo
.n_memranges
) {
22 printf("Warning: Limiting e820 map to %d entries.\n",
25 for (i
= 0; i
< num_entries
; i
++) {
26 struct memrange
*memrange
= &lib_sysinfo
.memrange
[i
];
28 entries
[i
].addr
= memrange
->base
;
29 entries
[i
].size
= memrange
->size
;
32 * coreboot has some extensions (type 6 & 16) to the E820 types.
33 * When we detect this, mark it as E820_RESERVED.
35 if (memrange
->type
== CB_MEM_VENDOR_RSVD
||
36 memrange
->type
== CB_MEM_TABLE
)
37 entries
[i
].type
= E820_RESERVED
;
39 entries
[i
].type
= memrange
->type
;
46 * This function looks for the highest region of memory lower than 4GB which
47 * has enough space for U-Boot where U-Boot is aligned on a page boundary. It
48 * overrides the default implementation found elsewhere which simply picks the
49 * end of ram, wherever that may be. The location of the stack, the relocation
50 * address, and how far U-Boot is moved by relocation are set in the global
53 ulong
board_get_usable_ram_top(ulong total_size
)
55 uintptr_t dest_addr
= 0;
58 for (i
= 0; i
< lib_sysinfo
.n_memranges
; i
++) {
59 struct memrange
*memrange
= &lib_sysinfo
.memrange
[i
];
60 /* Force U-Boot to relocate to a page aligned address. */
61 uint64_t start
= roundup(memrange
->base
, 1 << 12);
62 uint64_t end
= memrange
->base
+ memrange
->size
;
64 /* Ignore non-memory regions. */
65 if (memrange
->type
!= CB_MEM_RAM
)
68 /* Filter memory over 4GB. */
69 if (end
> 0xffffffffULL
)
71 /* Skip this region if it's too small. */
72 if (end
- start
< total_size
)
75 /* Use this address if it's the largest so far. */
80 /* If no suitable area was found, return an error. */
82 panic("No available memory found for relocation");
84 return (ulong
)dest_addr
;
90 phys_size_t ram_size
= 0;
92 for (i
= 0; i
< lib_sysinfo
.n_memranges
; i
++) {
93 struct memrange
*memrange
= &lib_sysinfo
.memrange
[i
];
94 unsigned long long end
= memrange
->base
+ memrange
->size
;
96 if (memrange
->type
== CB_MEM_RAM
&& end
> ram_size
)
97 ram_size
+= memrange
->size
;
100 gd
->ram_size
= ram_size
;
107 int dram_init_banksize(void)
111 if (CONFIG_NR_DRAM_BANKS
) {
112 for (i
= 0, j
= 0; i
< lib_sysinfo
.n_memranges
; i
++) {
113 struct memrange
*memrange
= &lib_sysinfo
.memrange
[i
];
115 if (memrange
->type
== CB_MEM_RAM
) {
116 gd
->bd
->bi_dram
[j
].start
= memrange
->base
;
117 gd
->bd
->bi_dram
[j
].size
= memrange
->size
;
119 if (j
>= CONFIG_NR_DRAM_BANKS
)