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