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