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