blob: dbc17102da5c828c5f6df3a66c0ec6ce9daa6538 [file] [log] [blame]
Bin Mengb2e02d22014-12-17 15:50:36 +08001/*
2 * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <asm/arch/fsp/fsp_support.h>
9#include <asm/e820.h>
10#include <asm/post.h>
11
12DECLARE_GLOBAL_DATA_PTR;
13
14int dram_init(void)
15{
16 phys_size_t ram_size = 0;
17 union hob_pointers_t hob;
18
19 hob.raw = gd->arch.hob_list;
20 while (!END_OF_HOB(hob)) {
21 if (hob.hdr->type == HOB_TYPE_RES_DESC) {
22 if (hob.res_desc->type == RES_SYS_MEM ||
23 hob.res_desc->type == RES_MEM_RESERVED) {
24 ram_size += hob.res_desc->len;
25 }
26 }
27 hob.raw = GET_NEXT_HOB(hob);
28 }
29
30 gd->ram_size = ram_size;
31 post_code(POST_DRAM);
32
33 return 0;
34}
35
36void dram_init_banksize(void)
37{
38 gd->bd->bi_dram[0].start = 0;
39 gd->bd->bi_dram[0].size = gd->ram_size;
40}
41
42/*
43 * This function looks for the highest region of memory lower than 4GB which
44 * has enough space for U-Boot where U-Boot is aligned on a page boundary.
45 * It overrides the default implementation found elsewhere which simply
46 * picks the end of ram, wherever that may be. The location of the stack,
47 * the relocation address, and how far U-Boot is moved by relocation are
48 * set in the global data structure.
49 */
50ulong board_get_usable_ram_top(ulong total_size)
51{
52 return get_usable_lowmem_top(gd->arch.hob_list);
53}
54
55unsigned install_e820_map(unsigned max_entries, struct e820entry *entries)
56{
57 unsigned num_entries = 0;
58
59 union hob_pointers_t hob;
60
61 hob.raw = gd->arch.hob_list;
62
63 while (!END_OF_HOB(hob)) {
64 if (hob.hdr->type == HOB_TYPE_RES_DESC) {
65 entries[num_entries].addr = hob.res_desc->phys_start;
66 entries[num_entries].size = hob.res_desc->len;
67
68 if (hob.res_desc->type == RES_SYS_MEM)
69 entries[num_entries].type = E820_RAM;
70 else if (hob.res_desc->type == RES_MEM_RESERVED)
71 entries[num_entries].type = E820_RESERVED;
72 }
73 hob.raw = GET_NEXT_HOB(hob);
74 num_entries++;
75 }
76
77 return num_entries;
78}