blob: 1a7af576d549c55c06b930bad34eb60c3b383a44 [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>
Simon Glassb93abfc2015-01-27 22:13:36 -07008#include <asm/fsp/fsp_support.h>
Bin Meng08e484c2014-12-17 15:50:36 +08009#include <asm/e820.h>
Bin Meng07793c082015-10-11 21:37:42 -070010#include <asm/mrccache.h>
Bin Meng08e484c2014-12-17 15:50:36 +080011#include <asm/post.h>
12
13DECLARE_GLOBAL_DATA_PTR;
14
15int dram_init(void)
16{
17 phys_size_t ram_size = 0;
Bin Meng2b215982014-12-30 16:02:05 +080018 const struct hob_header *hdr;
19 struct hob_res_desc *res_desc;
Bin Meng08e484c2014-12-17 15:50:36 +080020
Bin Meng2b215982014-12-30 16:02:05 +080021 hdr = gd->arch.hob_list;
22 while (!end_of_hob(hdr)) {
Bin Meng2f848bc2015-01-06 14:04:36 +080023 if (hdr->type == HOB_TYPE_RES_DESC) {
Bin Meng2b215982014-12-30 16:02:05 +080024 res_desc = (struct hob_res_desc *)hdr;
25 if (res_desc->type == RES_SYS_MEM ||
26 res_desc->type == RES_MEM_RESERVED) {
27 ram_size += res_desc->len;
Bin Meng08e484c2014-12-17 15:50:36 +080028 }
29 }
Bin Meng2b215982014-12-30 16:02:05 +080030 hdr = get_next_hob(hdr);
Bin Meng08e484c2014-12-17 15:50:36 +080031 }
32
33 gd->ram_size = ram_size;
34 post_code(POST_DRAM);
35
Bin Meng07793c082015-10-11 21:37:42 -070036#ifdef CONFIG_ENABLE_MRC_CACHE
37 gd->arch.mrc_output = fsp_get_nvs_data(gd->arch.hob_list,
38 &gd->arch.mrc_output_len);
39#endif
40
Bin Meng08e484c2014-12-17 15:50:36 +080041 return 0;
42}
43
Simon Glass2f949c32017-03-31 08:40:32 -060044int dram_init_banksize(void)
Bin Meng08e484c2014-12-17 15:50:36 +080045{
46 gd->bd->bi_dram[0].start = 0;
47 gd->bd->bi_dram[0].size = gd->ram_size;
Simon Glass2f949c32017-03-31 08:40:32 -060048
49 return 0;
Bin Meng08e484c2014-12-17 15:50:36 +080050}
51
52/*
53 * This function looks for the highest region of memory lower than 4GB which
54 * has enough space for U-Boot where U-Boot is aligned on a page boundary.
55 * It overrides the default implementation found elsewhere which simply
56 * picks the end of ram, wherever that may be. The location of the stack,
57 * the relocation address, and how far U-Boot is moved by relocation are
58 * set in the global data structure.
59 */
60ulong board_get_usable_ram_top(ulong total_size)
61{
Bin Mengdb60d862014-12-17 15:50:49 +080062 return fsp_get_usable_lowmem_top(gd->arch.hob_list);
Bin Meng08e484c2014-12-17 15:50:36 +080063}
64
65unsigned install_e820_map(unsigned max_entries, struct e820entry *entries)
66{
67 unsigned num_entries = 0;
Bin Meng2b215982014-12-30 16:02:05 +080068 const struct hob_header *hdr;
69 struct hob_res_desc *res_desc;
Bin Meng08e484c2014-12-17 15:50:36 +080070
Bin Meng2b215982014-12-30 16:02:05 +080071 hdr = gd->arch.hob_list;
Bin Meng08e484c2014-12-17 15:50:36 +080072
Bin Meng2b215982014-12-30 16:02:05 +080073 while (!end_of_hob(hdr)) {
Bin Meng2f848bc2015-01-06 14:04:36 +080074 if (hdr->type == HOB_TYPE_RES_DESC) {
Bin Meng2b215982014-12-30 16:02:05 +080075 res_desc = (struct hob_res_desc *)hdr;
76 entries[num_entries].addr = res_desc->phys_start;
77 entries[num_entries].size = res_desc->len;
Bin Meng08e484c2014-12-17 15:50:36 +080078
Bin Meng2b215982014-12-30 16:02:05 +080079 if (res_desc->type == RES_SYS_MEM)
Bin Meng08e484c2014-12-17 15:50:36 +080080 entries[num_entries].type = E820_RAM;
Bin Meng2b215982014-12-30 16:02:05 +080081 else if (res_desc->type == RES_MEM_RESERVED)
Bin Meng08e484c2014-12-17 15:50:36 +080082 entries[num_entries].type = E820_RESERVED;
Bin Mengc71c4822015-09-28 02:11:59 -070083
84 num_entries++;
Bin Meng08e484c2014-12-17 15:50:36 +080085 }
Bin Meng2b215982014-12-30 16:02:05 +080086 hdr = get_next_hob(hdr);
Bin Meng08e484c2014-12-17 15:50:36 +080087 }
88
Bin Mengcf40bd42015-07-22 01:21:15 -070089 /* Mark PCIe ECAM address range as reserved */
90 entries[num_entries].addr = CONFIG_PCIE_ECAM_BASE;
91 entries[num_entries].size = CONFIG_PCIE_ECAM_SIZE;
92 entries[num_entries].type = E820_RESERVED;
93 num_entries++;
94
Bin Meng212c7b22017-04-21 07:24:34 -070095#ifdef CONFIG_HAVE_ACPI_RESUME
96 /*
97 * Everything between U-Boot's stack and ram top needs to be
98 * reserved in order for ACPI S3 resume to work.
99 */
100 entries[num_entries].addr = gd->start_addr_sp - CONFIG_STACK_SIZE;
101 entries[num_entries].size = gd->ram_top - gd->start_addr_sp + \
102 CONFIG_STACK_SIZE;
103 entries[num_entries].type = E820_RESERVED;
104 num_entries++;
105#endif
106
Bin Meng08e484c2014-12-17 15:50:36 +0800107 return num_entries;
108}