]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Library/DxeCoreHobLib/HobLib.c
Enhanced the <Build_Library> macro to check OBJECTS property in case it's empty
[mirror_edk2.git] / MdePkg / Library / DxeCoreHobLib / HobLib.c
CommitLineData
878ddf1f 1/** @file\r
2 HOB Library.\r
3\r
4 Copyright (c) 2006, Intel Corporation<BR>\r
5 All rights reserved. This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13 Module Name: HobLib.c\r
14\r
15**/\r
16\r
17\r
18\r
19extern VOID *gHobList;\r
20\r
5f10fa01 21\r
878ddf1f 22/**\r
23 Returns the pointer to the HOB list.\r
24\r
5f10fa01 25 This function returns the pointer to first HOB in the list.\r
26\r
878ddf1f 27 @return The pointer to the HOB list.\r
28\r
29**/\r
30VOID *\r
31EFIAPI\r
32GetHobList (\r
33 VOID\r
34 )\r
35{\r
36 return gHobList;\r
37}\r
38\r
39/**\r
5f10fa01 40 Returns the next instance of a HOB type from the starting HOB.\r
41\r
878ddf1f 42 This function searches the first instance of a HOB type from the starting HOB pointer. \r
5f10fa01 43 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.\r
44 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
45 unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
46 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
47 If HobStart is NULL, then ASSERT().\r
878ddf1f 48\r
5f10fa01 49 @param Type The HOB type to return.\r
50 @param HobStart The starting HOB pointer to search from.\r
878ddf1f 51\r
52 @return The next instance of a HOB type from the starting HOB.\r
53\r
54**/\r
55VOID *\r
56EFIAPI\r
57GetNextHob (\r
58 IN UINT16 Type,\r
59 IN CONST VOID *HobStart\r
60 )\r
61{\r
62 EFI_PEI_HOB_POINTERS Hob;\r
63\r
64 ASSERT (HobStart != NULL);\r
65 \r
66 Hob.Raw = (UINT8 *) HobStart;\r
67 //\r
5f10fa01 68 // Parse the HOB list until end of list or matching type is found.\r
878ddf1f 69 //\r
70 while (!END_OF_HOB_LIST (Hob)) {\r
71 if (Hob.Header->HobType == Type) {\r
72 return Hob.Raw;\r
73 }\r
74 Hob.Raw = GET_NEXT_HOB (Hob);\r
75 }\r
76 return NULL;\r
77}\r
78\r
79/**\r
5f10fa01 80 Returns the first instance of a HOB type among the whole HOB list.\r
81\r
878ddf1f 82 This function searches the first instance of a HOB type among the whole HOB list. \r
83 If there does not exist such HOB type in the HOB list, it will return NULL. \r
84\r
5f10fa01 85 @param Type The HOB type to return.\r
878ddf1f 86\r
87 @return The next instance of a HOB type from the starting HOB.\r
88\r
89**/\r
90VOID *\r
91EFIAPI\r
92GetFirstHob (\r
93 IN UINT16 Type\r
94 )\r
95{\r
96 VOID *HobList;\r
97\r
98 HobList = GetHobList ();\r
99 return GetNextHob (Type, HobList);\r
100}\r
101\r
102/**\r
103 This function searches the first instance of a HOB from the starting HOB pointer. \r
104 Such HOB should satisfy two conditions: \r
105 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid. \r
106 If there does not exist such HOB from the starting HOB pointer, it will return NULL. \r
5f10fa01 107 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
108 to extract the data section and its size info respectively.\r
109 In contrast with macro GET_NEXT_HOB(), this function does not skip the starting HOB pointer\r
110 unconditionally: it returns HobStart back if HobStart itself meets the requirement;\r
111 caller is required to use GET_NEXT_HOB() if it wishes to skip current HobStart.\r
112 If Guid is NULL, then ASSERT().\r
113 If HobStart is NULL, then ASSERT().\r
878ddf1f 114\r
5f10fa01 115 @param Guid The GUID to match with in the HOB list.\r
116 @param HobStart A pointer to a Guid.\r
878ddf1f 117\r
118 @return The next instance of the matched GUID HOB from the starting HOB.\r
119\r
120**/\r
121VOID *\r
122EFIAPI\r
123GetNextGuidHob (\r
124 IN CONST EFI_GUID *Guid,\r
125 IN CONST VOID *HobStart\r
126 )\r
127{\r
128 EFI_PEI_HOB_POINTERS GuidHob;\r
129\r
130 GuidHob.Raw = (UINT8 *) HobStart;\r
131 while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {\r
132 if (CompareGuid (Guid, &GuidHob.Guid->Name)) {\r
133 break;\r
134 }\r
135 GuidHob.Raw = GET_NEXT_HOB (GuidHob);\r
136 }\r
137 return GuidHob.Raw;\r
138}\r
139\r
140/**\r
141 This function searches the first instance of a HOB among the whole HOB list. \r
142 Such HOB should satisfy two conditions:\r
143 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.\r
144 If there does not exist such HOB from the starting HOB pointer, it will return NULL.\r
5f10fa01 145 Caller is required to apply GET_GUID_HOB_DATA () and GET_GUID_HOB_DATA_SIZE ()\r
146 to extract the data section and its size info respectively.\r
147 If Guid is NULL, then ASSERT().\r
878ddf1f 148\r
5f10fa01 149 @param Guid The GUID to match with in the HOB list.\r
878ddf1f 150\r
151 @return The first instance of the matched GUID HOB among the whole HOB list.\r
152\r
153**/\r
154VOID *\r
155EFIAPI\r
156GetFirstGuidHob (\r
157 IN CONST EFI_GUID *Guid\r
158 )\r
159{\r
160 VOID *HobList;\r
161\r
162 HobList = GetHobList ();\r
163 return GetNextGuidHob (Guid, HobList);\r
164}\r
165\r
166/**\r
5f10fa01 167 Builds a HOB for a loaded PE32 module.\r
168\r
878ddf1f 169 This function builds a HOB for a loaded PE32 module.\r
5f10fa01 170 It can only be invoked during PEI phase;\r
171 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
172 If ModuleName is NULL, then ASSERT().\r
173 If there is no additional space for HOB creation, then ASSERT().\r
878ddf1f 174\r
5f10fa01 175 @param ModuleName The GUID File Name of the module.\r
176 @param MemoryAllocationModule The 64 bit physical address of the module.\r
177 @param ModuleLength The length of the module in bytes.\r
511710d6 178 @param EntryPoint The 64 bit physical address of the module's entry point.\r
878ddf1f 179\r
180**/\r
181VOID\r
182EFIAPI\r
183BuildModuleHob (\r
184 IN CONST EFI_GUID *ModuleName,\r
185 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,\r
186 IN UINT64 ModuleLength,\r
187 IN EFI_PHYSICAL_ADDRESS EntryPoint\r
188 )\r
189{\r
190 //\r
191 // PEI HOB is read only for DXE phase\r
192 //\r
193 ASSERT (FALSE);\r
194}\r
195\r
196/**\r
197 Builds a HOB that describes a chunk of system memory.\r
198\r
5f10fa01 199 This function builds a HOB that describes a chunk of system memory.\r
200 It can only be invoked during PEI phase;\r
201 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
202 If there is no additional space for HOB creation, then ASSERT().\r
203\r
204 @param ResourceType The type of resource described by this HOB.\r
205 @param ResourceAttribute The resource attributes of the memory described by this HOB.\r
206 @param PhysicalStart The 64 bit physical address of memory described by this HOB.\r
207 @param NumberOfBytes The length of the memory described by this HOB in bytes.\r
878ddf1f 208\r
209**/\r
210VOID\r
211EFIAPI\r
212BuildResourceDescriptorHob (\r
213 IN EFI_RESOURCE_TYPE ResourceType,\r
214 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r
215 IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r
216 IN UINT64 NumberOfBytes\r
217 )\r
218{\r
219 //\r
220 // PEI HOB is read only for DXE phase\r
221 //\r
222 ASSERT (FALSE);\r
223}\r
224\r
225/**\r
5f10fa01 226 Builds a GUID HOB with a certain data length.\r
227\r
878ddf1f 228 This function builds a customized HOB tagged with a GUID for identification \r
229 and returns the start address of GUID HOB data so that caller can fill the customized data. \r
5f10fa01 230 The HOB Header and Name field is already stripped.\r
231 It can only be invoked during PEI phase;\r
232 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
233 If Guid is NULL, then ASSERT().\r
234 If there is no additional space for HOB creation, then ASSERT().\r
533f039e 235 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
878ddf1f 236\r
5f10fa01 237 @param Guid The GUID to tag the customized HOB.\r
238 @param DataLength The size of the data payload for the GUID HOB.\r
878ddf1f 239\r
240 @return The start address of GUID HOB data.\r
241\r
242**/\r
243VOID *\r
244EFIAPI\r
245BuildGuidHob (\r
246 IN CONST EFI_GUID *Guid,\r
247 IN UINTN DataLength\r
248 )\r
249{\r
250 //\r
251 // PEI HOB is read only for DXE phase\r
252 //\r
253 ASSERT (FALSE);\r
254 return NULL;\r
255}\r
256\r
257/**\r
5f10fa01 258 Copies a data buffer to a newly-built HOB.\r
259\r
260 This function builds a customized HOB tagged with a GUID for identification,\r
261 copies the input data to the HOB data field and returns the start address of the GUID HOB data.\r
262 The HOB Header and Name field is already stripped.\r
263 It can only be invoked during PEI phase;\r
264 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
265 If Guid is NULL, then ASSERT().\r
266 If Data is NULL and DataLength > 0, then ASSERT().\r
267 If there is no additional space for HOB creation, then ASSERT().\r
533f039e 268 If DataLength >= (0x10000 - sizeof (EFI_HOB_GUID_TYPE)), then ASSERT().\r
5f10fa01 269\r
270 @param Guid The GUID to tag the customized HOB.\r
271 @param Data The data to be copied into the data field of the GUID HOB.\r
272 @param DataLength The size of the data payload for the GUID HOB.\r
878ddf1f 273\r
274 @return The start address of GUID HOB data.\r
275\r
276**/\r
277VOID *\r
278EFIAPI\r
279BuildGuidDataHob (\r
280 IN CONST EFI_GUID *Guid,\r
281 IN VOID *Data,\r
282 IN UINTN DataLength\r
283 )\r
284{\r
285 //\r
286 // PEI HOB is read only for DXE phase\r
287 //\r
288 ASSERT (FALSE);\r
289 return NULL;\r
290}\r
291\r
292/**\r
293 Builds a Firmware Volume HOB.\r
294\r
5f10fa01 295 This function builds a Firmware Volume HOB.\r
296 It can only be invoked during PEI phase;\r
297 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
298 If there is no additional space for HOB creation, then ASSERT().\r
299\r
300 @param BaseAddress The base address of the Firmware Volume.\r
301 @param Length The size of the Firmware Volume in bytes.\r
878ddf1f 302\r
303**/\r
304VOID\r
305EFIAPI\r
306BuildFvHob (\r
307 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
308 IN UINT64 Length\r
309 )\r
310{\r
311 //\r
312 // PEI HOB is read only for DXE phase\r
313 //\r
314 ASSERT (FALSE);\r
315}\r
316\r
317/**\r
318 Builds a Capsule Volume HOB.\r
319\r
5f10fa01 320 This function builds a Capsule Volume HOB.\r
321 It can only be invoked during PEI phase;\r
322 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
323 If there is no additional space for HOB creation, then ASSERT().\r
324\r
325 @param BaseAddress The base address of the Capsule Volume.\r
326 @param Length The size of the Capsule Volume in bytes.\r
878ddf1f 327\r
328**/\r
329VOID\r
330EFIAPI\r
331BuildCvHob (\r
332 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
333 IN UINT64 Length\r
334 )\r
335{\r
336 //\r
337 // PEI HOB is read only for DXE phase\r
338 //\r
339 ASSERT (FALSE);\r
340}\r
341\r
342/**\r
343 Builds a HOB for the CPU.\r
344\r
5f10fa01 345 This function builds a HOB for the CPU.\r
346 It can only be invoked during PEI phase;\r
347 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
348 If there is no additional space for HOB creation, then ASSERT().\r
349\r
350 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.\r
351 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.\r
878ddf1f 352\r
353**/\r
354VOID\r
355EFIAPI\r
356BuildCpuHob (\r
357 IN UINT8 SizeOfMemorySpace,\r
358 IN UINT8 SizeOfIoSpace\r
359 )\r
360{\r
361 //\r
362 // PEI HOB is read only for DXE phase\r
363 //\r
364 ASSERT (FALSE);\r
365}\r
366\r
367/**\r
368 Builds a HOB for the Stack.\r
369\r
5f10fa01 370 This function builds a HOB for the stack.\r
371 It can only be invoked during PEI phase;\r
372 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
373 If there is no additional space for HOB creation, then ASSERT().\r
374\r
375 @param BaseAddress The 64 bit physical address of the Stack.\r
376 @param Length The length of the stack in bytes.\r
878ddf1f 377\r
378**/\r
379VOID\r
380EFIAPI\r
381BuildStackHob (\r
382 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
383 IN UINT64 Length\r
384 )\r
385{\r
386 //\r
387 // PEI HOB is read only for DXE phase\r
388 //\r
389 ASSERT (FALSE);\r
390}\r
391\r
392/**\r
393 Builds a HOB for the BSP store.\r
394\r
5f10fa01 395 This function builds a HOB for BSP store.\r
396 It can only be invoked during PEI phase;\r
397 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
398 If there is no additional space for HOB creation, then ASSERT().\r
399\r
400 @param BaseAddress The 64 bit physical address of the BSP.\r
401 @param Length The length of the BSP store in bytes.\r
402 @param MemoryType Type of memory allocated by this HOB.\r
878ddf1f 403\r
404**/\r
405VOID\r
406EFIAPI\r
407BuildBspStoreHob (\r
408 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
409 IN UINT64 Length,\r
410 IN EFI_MEMORY_TYPE MemoryType\r
411 )\r
412{\r
413 //\r
414 // PEI HOB is read only for DXE phase\r
415 //\r
416 ASSERT (FALSE);\r
417}\r
418\r
419/**\r
420 Builds a HOB for the memory allocation.\r
421\r
5f10fa01 422 This function builds a HOB for the memory allocation.\r
423 It can only be invoked during PEI phase;\r
424 for DXE phase, it will ASSERT() since PEI HOB is read-only for DXE phase.\r
425 If there is no additional space for HOB creation, then ASSERT().\r
426\r
427 @param BaseAddress The 64 bit physical address of the memory.\r
428 @param Length The length of the memory allocation in bytes.\r
429 @param MemoryType Type of memory allocated by this HOB.\r
878ddf1f 430\r
431**/\r
432VOID\r
433EFIAPI\r
434BuildMemoryAllocationHob (\r
435 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
436 IN UINT64 Length,\r
437 IN EFI_MEMORY_TYPE MemoryType\r
438 )\r
439{\r
440 //\r
441 // PEI HOB is read only for DXE phase\r
442 //\r
443 ASSERT (FALSE);\r
444}\r