1 // SPDX-License-Identifier: Intel
2 /*
3 * Copyright (C) 2013, Intel Corporation
4 * Copyright (C) 2014, Bin Meng <bmeng.cn@gmail.com>
5 */
6
7 #include <common.h>
8 #include <asm/fsp1/fsp_support.h>
9 #include <asm/post.h>
10
fsp_get_usable_lowmem_top(const void * hob_list)11 u32 fsp_get_usable_lowmem_top(const void *hob_list)
12 {
13 const struct hob_header *hdr;
14 struct hob_res_desc *res_desc;
15 phys_addr_t phys_start;
16 u32 top;
17 #ifdef CONFIG_FSP_BROKEN_HOB
18 struct hob_mem_alloc *res_mem;
19 phys_addr_t mem_base = 0;
20 #endif
21
22 /* Get the HOB list for processing */
23 hdr = hob_list;
24
25 /* * Collect memory ranges */
26 top = FSP_LOWMEM_BASE;
27 while (!end_of_hob(hdr)) {
28 if (hdr->type == HOB_TYPE_RES_DESC) {
29 res_desc = (struct hob_res_desc *)hdr;
30 if (res_desc->type == RES_SYS_MEM) {
31 phys_start = res_desc->phys_start;
32 /* Need memory above 1MB to be collected here */
33 if (phys_start >= FSP_LOWMEM_BASE &&
34 phys_start < (phys_addr_t)FSP_HIGHMEM_BASE)
35 top += (u32)(res_desc->len);
36 }
37 }
38
39 #ifdef CONFIG_FSP_BROKEN_HOB
40 /*
41 * Find out the lowest memory base address allocated by FSP
42 * for the boot service data
43 */
44 if (hdr->type == HOB_TYPE_MEM_ALLOC) {
45 res_mem = (struct hob_mem_alloc *)hdr;
46 if (!mem_base)
47 mem_base = res_mem->mem_base;
48 if (res_mem->mem_base < mem_base)
49 mem_base = res_mem->mem_base;
50 }
51 #endif
52
53 hdr = get_next_hob(hdr);
54 }
55
56 #ifdef CONFIG_FSP_BROKEN_HOB
57 /*
58 * Check whether the memory top address is below the FSP HOB list.
59 * If not, use the lowest memory base address allocated by FSP as
60 * the memory top address. This is to prevent U-Boot relocation
61 * overwrites the important boot service data which is used by FSP,
62 * otherwise the subsequent call to fsp_notify() will fail.
63 */
64 if (top > (u32)hob_list) {
65 debug("Adjust memory top address due to a buggy FSP\n");
66 top = (u32)mem_base;
67 }
68 #endif
69
70 return top;
71 }
72
fsp_get_usable_highmem_top(const void * hob_list)73 u64 fsp_get_usable_highmem_top(const void *hob_list)
74 {
75 const struct hob_header *hdr;
76 struct hob_res_desc *res_desc;
77 phys_addr_t phys_start;
78 u64 top;
79
80 /* Get the HOB list for processing */
81 hdr = hob_list;
82
83 /* Collect memory ranges */
84 top = FSP_HIGHMEM_BASE;
85 while (!end_of_hob(hdr)) {
86 if (hdr->type == HOB_TYPE_RES_DESC) {
87 res_desc = (struct hob_res_desc *)hdr;
88 if (res_desc->type == RES_SYS_MEM) {
89 phys_start = res_desc->phys_start;
90 /* Need memory above 4GB to be collected here */
91 if (phys_start >= (phys_addr_t)FSP_HIGHMEM_BASE)
92 top += (u32)(res_desc->len);
93 }
94 }
95 hdr = get_next_hob(hdr);
96 }
97
98 return top;
99 }
100
fsp_get_reserved_mem_from_guid(const void * hob_list,u64 * len,const efi_guid_t * guid)101 u64 fsp_get_reserved_mem_from_guid(const void *hob_list, u64 *len,
102 const efi_guid_t *guid)
103 {
104 const struct hob_header *hdr;
105 struct hob_res_desc *res_desc;
106
107 /* Get the HOB list for processing */
108 hdr = hob_list;
109
110 /* Collect memory ranges */
111 while (!end_of_hob(hdr)) {
112 if (hdr->type == HOB_TYPE_RES_DESC) {
113 res_desc = (struct hob_res_desc *)hdr;
114 if (res_desc->type == RES_MEM_RESERVED) {
115 if (!guidcmp(&res_desc->owner, guid)) {
116 if (len)
117 *len = (u32)(res_desc->len);
118
119 return (u64)(res_desc->phys_start);
120 }
121 }
122 }
123 hdr = get_next_hob(hdr);
124 }
125
126 return 0;
127 }
128
fsp_get_fsp_reserved_mem(const void * hob_list,u32 * len)129 u32 fsp_get_fsp_reserved_mem(const void *hob_list, u32 *len)
130 {
131 const efi_guid_t guid = FSP_HOB_RESOURCE_OWNER_FSP_GUID;
132 u64 length;
133 u32 base;
134
135 base = (u32)fsp_get_reserved_mem_from_guid(hob_list,
136 &length, &guid);
137 if (len && base)
138 *len = (u32)length;
139
140 return base;
141 }
142
fsp_get_tseg_reserved_mem(const void * hob_list,u32 * len)143 u32 fsp_get_tseg_reserved_mem(const void *hob_list, u32 *len)
144 {
145 const efi_guid_t guid = FSP_HOB_RESOURCE_OWNER_TSEG_GUID;
146 u64 length;
147 u32 base;
148
149 base = (u32)fsp_get_reserved_mem_from_guid(hob_list,
150 &length, &guid);
151 if (len && base)
152 *len = (u32)length;
153
154 return base;
155 }
156
fsp_get_nvs_data(const void * hob_list,u32 * len)157 void *fsp_get_nvs_data(const void *hob_list, u32 *len)
158 {
159 const efi_guid_t guid = FSP_NON_VOLATILE_STORAGE_HOB_GUID;
160
161 return hob_get_guid_hob_data(hob_list, len, &guid);
162 }
163
fsp_get_var_nvs_data(const void * hob_list,u32 * len)164 void *fsp_get_var_nvs_data(const void *hob_list, u32 *len)
165 {
166 const efi_guid_t guid = FSP_VARIABLE_NV_DATA_HOB_GUID;
167
168 return hob_get_guid_hob_data(hob_list, len, &guid);
169 }
170
fsp_get_bootloader_tmp_mem(const void * hob_list,u32 * len)171 void *fsp_get_bootloader_tmp_mem(const void *hob_list, u32 *len)
172 {
173 const efi_guid_t guid = FSP_BOOTLOADER_TEMP_MEM_HOB_GUID;
174
175 return hob_get_guid_hob_data(hob_list, len, &guid);
176 }
177
fsp_get_graphics_info(const void * hob_list,u32 * len)178 void *fsp_get_graphics_info(const void *hob_list, u32 *len)
179 {
180 const efi_guid_t guid = FSP_GRAPHICS_INFO_HOB_GUID;
181
182 return hob_get_guid_hob_data(hob_list, len, &guid);
183 }
184