blob: df79a39dd8e1eb901e05d199c8c5f965510e2c10 [file] [log] [blame]
Bin Meng08e484c2014-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;
Bin Meng2b215982014-12-30 16:02:05 +080017 const struct hob_header *hdr;
18 struct hob_res_desc *res_desc;
Bin Meng08e484c2014-12-17 15:50:36 +080019
Bin Meng2b215982014-12-30 16:02:05 +080020 hdr = gd->arch.hob_list;
21 while (!end_of_hob(hdr)) {
Bin Meng2f848bc2015-01-06 14:04:36 +080022 if (hdr->type == HOB_TYPE_RES_DESC) {
Bin Meng2b215982014-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 Meng08e484c2014-12-17 15:50:36 +080027 }
28 }
Bin Meng2b215982014-12-30 16:02:05 +080029 hdr = get_next_hob(hdr);
Bin Meng08e484c2014-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 Mengdb60d862014-12-17 15:50:49 +080054 return fsp_get_usable_lowmem_top(gd->arch.hob_list);
Bin Meng08e484c2014-12-17 15:50:36 +080055}
56
57unsigned install_e820_map(unsigned max_entries, struct e820entry *entries)
58{
59 unsigned num_entries = 0;
Bin Meng2b215982014-12-30 16:02:05 +080060 const struct hob_header *hdr;
61 struct hob_res_desc *res_desc;
Bin Meng08e484c2014-12-17 15:50:36 +080062
Bin Meng2b215982014-12-30 16:02:05 +080063 hdr = gd->arch.hob_list;
Bin Meng08e484c2014-12-17 15:50:36 +080064
Bin Meng2b215982014-12-30 16:02:05 +080065 while (!end_of_hob(hdr)) {
Bin Meng2f848bc2015-01-06 14:04:36 +080066 if (hdr->type == HOB_TYPE_RES_DESC) {
Bin Meng2b215982014-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 Meng08e484c2014-12-17 15:50:36 +080070
Bin Meng2b215982014-12-30 16:02:05 +080071 if (res_desc->type == RES_SYS_MEM)
Bin Meng08e484c2014-12-17 15:50:36 +080072 entries[num_entries].type = E820_RAM;
Bin Meng2b215982014-12-30 16:02:05 +080073 else if (res_desc->type == RES_MEM_RESERVED)
Bin Meng08e484c2014-12-17 15:50:36 +080074 entries[num_entries].type = E820_RESERVED;
75 }
Bin Meng2b215982014-12-30 16:02:05 +080076 hdr = get_next_hob(hdr);
Bin Meng08e484c2014-12-17 15:50:36 +080077 num_entries++;
78 }
79
80 return num_entries;
81}