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