1 // SPDX-License-Identifier: Intel
3 * Copyright (C) 2013, Intel Corporation
4 * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
9 #include <asm/fsp/fsp_support.h>
12 u32 fsp_get_usable_lowmem_top(const void *hob_list)
14 const struct hob_header *hdr;
15 struct hob_res_desc *res_desc;
16 phys_addr_t phys_start;
18 #ifdef CONFIG_FSP_BROKEN_HOB
19 struct hob_mem_alloc *res_mem;
20 phys_addr_t mem_base = 0;
23 /* Get the HOB list for processing */
26 /* * Collect memory ranges */
27 top = FSP_LOWMEM_BASE;
28 while (!end_of_hob(hdr)) {
29 if (hdr->type == HOB_TYPE_RES_DESC) {
30 res_desc = (struct hob_res_desc *)hdr;
31 if (res_desc->type == RES_SYS_MEM) {
32 phys_start = res_desc->phys_start;
33 /* Need memory above 1MB to be collected here */
34 if (phys_start >= FSP_LOWMEM_BASE &&
35 phys_start < (phys_addr_t)FSP_HIGHMEM_BASE)
36 top += (u32)(res_desc->len);
40 #ifdef CONFIG_FSP_BROKEN_HOB
42 * Find out the lowest memory base address allocated by FSP
43 * for the boot service data
45 if (hdr->type == HOB_TYPE_MEM_ALLOC) {
46 res_mem = (struct hob_mem_alloc *)hdr;
48 mem_base = res_mem->mem_base;
49 if (res_mem->mem_base < mem_base)
50 mem_base = res_mem->mem_base;
54 hdr = get_next_hob(hdr);
57 #ifdef CONFIG_FSP_BROKEN_HOB
59 * Check whether the memory top address is below the FSP HOB list.
60 * If not, use the lowest memory base address allocated by FSP as
61 * the memory top address. This is to prevent U-Boot relocation
62 * overwrites the important boot service data which is used by FSP,
63 * otherwise the subsequent call to fsp_notify() will fail.
65 if (top > (u32)hob_list) {
66 debug("Adjust memory top address due to a buggy FSP\n");
74 u64 fsp_get_usable_highmem_top(const void *hob_list)
76 const struct hob_header *hdr;
77 struct hob_res_desc *res_desc;
78 phys_addr_t phys_start;
81 /* Get the HOB list for processing */
84 /* Collect memory ranges */
85 top = FSP_HIGHMEM_BASE;
86 while (!end_of_hob(hdr)) {
87 if (hdr->type == HOB_TYPE_RES_DESC) {
88 res_desc = (struct hob_res_desc *)hdr;
89 if (res_desc->type == RES_SYS_MEM) {
90 phys_start = res_desc->phys_start;
91 /* Need memory above 4GB to be collected here */
92 if (phys_start >= (phys_addr_t)FSP_HIGHMEM_BASE)
93 top += (u32)(res_desc->len);
96 hdr = get_next_hob(hdr);
102 u64 fsp_get_reserved_mem_from_guid(const void *hob_list, u64 *len,
103 const efi_guid_t *guid)
105 const struct hob_header *hdr;
106 struct hob_res_desc *res_desc;
108 /* Get the HOB list for processing */
111 /* Collect memory ranges */
112 while (!end_of_hob(hdr)) {
113 if (hdr->type == HOB_TYPE_RES_DESC) {
114 res_desc = (struct hob_res_desc *)hdr;
115 if (res_desc->type == RES_MEM_RESERVED) {
116 if (!guidcmp(&res_desc->owner, guid)) {
118 *len = (u32)(res_desc->len);
120 return (u64)(res_desc->phys_start);
124 hdr = get_next_hob(hdr);
130 u32 fsp_get_fsp_reserved_mem(const void *hob_list, u32 *len)
132 const efi_guid_t guid = FSP_HOB_RESOURCE_OWNER_FSP_GUID;
136 base = (u32)fsp_get_reserved_mem_from_guid(hob_list,
144 u32 fsp_get_tseg_reserved_mem(const void *hob_list, u32 *len)
146 const efi_guid_t guid = FSP_HOB_RESOURCE_OWNER_TSEG_GUID;
150 base = (u32)fsp_get_reserved_mem_from_guid(hob_list,
158 void *fsp_get_nvs_data(const void *hob_list, u32 *len)
160 const efi_guid_t guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID;
162 return hob_get_guid_hob_data(hob_list, len, &guid);
165 void *fsp_get_var_nvs_data(const void *hob_list, u32 *len)
167 const efi_guid_t guid = FSP_VARIABLE_NV_DATA_HOB_GUID;
169 return hob_get_guid_hob_data(hob_list, len, &guid);
172 void *fsp_get_bootloader_tmp_mem(const void *hob_list, u32 *len)
174 const efi_guid_t guid = FSP_BOOTLOADER_TEMP_MEM_HOB_GUID;
176 return hob_get_guid_hob_data(hob_list, len, &guid);
179 void *fsp_get_graphics_info(const void *hob_list, u32 *len)
181 const efi_guid_t guid = FSP_GRAPHICS_INFO_HOB_GUID;
183 return hob_get_guid_hob_data(hob_list, len, &guid);