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