blob: 4c0a7c82ca22923a0874f1bc8ee4c7cecdee6a8c [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>
Simon Glass1021af42015-01-27 22:13:36 -07008#include <asm/fsp/fsp_support.h>
Bin Mengb2e02d22014-12-17 15:50:36 +08009#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;
Bin Meng949dbc12014-12-30 16:02:05 +080017 const struct hob_header *hdr;
18 struct hob_res_desc *res_desc;
Bin Mengb2e02d22014-12-17 15:50:36 +080019
Bin Meng949dbc12014-12-30 16:02:05 +080020 hdr = gd->arch.hob_list;
21 while (!end_of_hob(hdr)) {
Bin Mengb2439ae2015-01-06 14:04:36 +080022 if (hdr->type == HOB_TYPE_RES_DESC) {
Bin Meng949dbc12014-12-30 16:02:05 +080023 res_desc = (struct hob_res_desc *)hdr;
24 if (res_desc->type == RES_SYS_MEM ||
25 res_desc->type == RES_MEM_RESERVED) {
26 ram_size += res_desc->len;
Bin Mengb2e02d22014-12-17 15:50:36 +080027 }
28 }
Bin Meng949dbc12014-12-30 16:02:05 +080029 hdr = get_next_hob(hdr);
Bin Mengb2e02d22014-12-17 15:50:36 +080030 }
31
32 gd->ram_size = ram_size;
33 post_code(POST_DRAM);
34
35 return 0;
36}
37
38void dram_init_banksize(void)
39{
40 gd->bd->bi_dram[0].start = 0;
41 gd->bd->bi_dram[0].size = gd->ram_size;
42}
43
44/*
45 * This function looks for the highest region of memory lower than 4GB which
46 * has enough space for U-Boot where U-Boot is aligned on a page boundary.
47 * It overrides the default implementation found elsewhere which simply
48 * picks the end of ram, wherever that may be. The location of the stack,
49 * the relocation address, and how far U-Boot is moved by relocation are
50 * set in the global data structure.
51 */
52ulong board_get_usable_ram_top(ulong total_size)
53{
Bin Meng255fd5c2014-12-17 15:50:49 +080054 return fsp_get_usable_lowmem_top(gd->arch.hob_list);
Bin Mengb2e02d22014-12-17 15:50:36 +080055}
56
57unsigned install_e820_map(unsigned max_entries, struct e820entry *entries)
58{
59 unsigned num_entries = 0;
Bin Meng949dbc12014-12-30 16:02:05 +080060 const struct hob_header *hdr;
61 struct hob_res_desc *res_desc;
Bin Mengb2e02d22014-12-17 15:50:36 +080062
Bin Meng949dbc12014-12-30 16:02:05 +080063 hdr = gd->arch.hob_list;
Bin Mengb2e02d22014-12-17 15:50:36 +080064
Bin Meng949dbc12014-12-30 16:02:05 +080065 while (!end_of_hob(hdr)) {
Bin Mengb2439ae2015-01-06 14:04:36 +080066 if (hdr->type == HOB_TYPE_RES_DESC) {
Bin Meng949dbc12014-12-30 16:02:05 +080067 res_desc = (struct hob_res_desc *)hdr;
68 entries[num_entries].addr = res_desc->phys_start;
69 entries[num_entries].size = res_desc->len;
Bin Mengb2e02d22014-12-17 15:50:36 +080070
Bin Meng949dbc12014-12-30 16:02:05 +080071 if (res_desc->type == RES_SYS_MEM)
Bin Mengb2e02d22014-12-17 15:50:36 +080072 entries[num_entries].type = E820_RAM;
Bin Meng949dbc12014-12-30 16:02:05 +080073 else if (res_desc->type == RES_MEM_RESERVED)
Bin Mengb2e02d22014-12-17 15:50:36 +080074 entries[num_entries].type = E820_RESERVED;
75 }
Bin Meng949dbc12014-12-30 16:02:05 +080076 hdr = get_next_hob(hdr);
Bin Mengb2e02d22014-12-17 15:50:36 +080077 num_entries++;
78 }
79
80 return num_entries;
81}