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