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