1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
9 #include <asm/fsp/fsp_support.h>
11 #include <asm/mrccache.h>
14 DECLARE_GLOBAL_DATA_PTR;
16 int fsp_scan_for_ram_size(void)
18 phys_size_t ram_size = 0;
19 const struct hob_header *hdr;
20 struct hob_res_desc *res_desc;
22 hdr = gd->arch.hob_list;
23 while (!end_of_hob(hdr)) {
24 if (hdr->type == HOB_TYPE_RES_DESC) {
25 res_desc = (struct hob_res_desc *)hdr;
26 if (res_desc->type == RES_SYS_MEM ||
27 res_desc->type == RES_MEM_RESERVED)
28 ram_size += res_desc->len;
30 hdr = get_next_hob(hdr);
33 gd->ram_size = ram_size;
39 int dram_init_banksize(void)
41 const struct hob_header *hdr;
42 struct hob_res_desc *res_desc;
47 for (bank = 1, hdr = gd->arch.hob_list;
48 bank < CONFIG_NR_DRAM_BANKS && !end_of_hob(hdr);
49 hdr = get_next_hob(hdr)) {
50 if (hdr->type != HOB_TYPE_RES_DESC)
52 res_desc = (struct hob_res_desc *)hdr;
53 if (res_desc->type != RES_SYS_MEM &&
54 res_desc->type != RES_MEM_RESERVED)
56 if (res_desc->phys_start < (1ULL << 32)) {
57 low_end = max(low_end,
58 res_desc->phys_start + res_desc->len);
62 gd->bd->bi_dram[bank].start = res_desc->phys_start;
63 gd->bd->bi_dram[bank].size = res_desc->len;
64 log_debug("ram %llx %llx\n", gd->bd->bi_dram[bank].start,
65 gd->bd->bi_dram[bank].size);
68 /* Add the memory below 4GB */
69 gd->bd->bi_dram[0].start = 0;
70 gd->bd->bi_dram[0].size = low_end;
75 unsigned int install_e820_map(unsigned int max_entries,
76 struct e820_entry *entries)
78 unsigned int num_entries = 0;
79 const struct hob_header *hdr;
80 struct hob_res_desc *res_desc;
82 hdr = gd->arch.hob_list;
84 while (!end_of_hob(hdr)) {
85 if (hdr->type == HOB_TYPE_RES_DESC) {
86 res_desc = (struct hob_res_desc *)hdr;
87 entries[num_entries].addr = res_desc->phys_start;
88 entries[num_entries].size = res_desc->len;
90 if (res_desc->type == RES_SYS_MEM)
91 entries[num_entries].type = E820_RAM;
92 else if (res_desc->type == RES_MEM_RESERVED)
93 entries[num_entries].type = E820_RESERVED;
97 hdr = get_next_hob(hdr);
100 /* Mark PCIe ECAM address range as reserved */
101 entries[num_entries].addr = CONFIG_PCIE_ECAM_BASE;
102 entries[num_entries].size = CONFIG_PCIE_ECAM_SIZE;
103 entries[num_entries].type = E820_RESERVED;
106 #ifdef CONFIG_HAVE_ACPI_RESUME
108 * Everything between U-Boot's stack and ram top needs to be
109 * reserved in order for ACPI S3 resume to work.
111 entries[num_entries].addr = gd->start_addr_sp - CONFIG_STACK_SIZE;
112 entries[num_entries].size = gd->ram_top - gd->start_addr_sp +
114 entries[num_entries].type = E820_RESERVED;
121 #if CONFIG_IS_ENABLED(HANDOFF) && IS_ENABLED(CONFIG_USE_HOB)
122 int handoff_arch_save(struct spl_handoff *ho)
124 ho->arch.usable_ram_top = fsp_get_usable_lowmem_top(gd->arch.hob_list);
125 ho->arch.hob_list = gd->arch.hob_list;