]> git.proxmox.com Git - mirror_edk2.git/blob - MdePkg/Library/DxeHobLib/HobLib.c
Initial import.
[mirror_edk2.git] / MdePkg / Library / DxeHobLib / HobLib.c
1 /** @file
2 HOB Library.
3
4 Copyright (c) 2006, 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 Module Name: HobLib.c
14
15 **/
16
17
18
19 STATIC VOID *mHobList = NULL;
20
21 /**
22 The constructor function caches the pointer to HOB list.
23
24 The constructor function gets the start address of HOB list from system configuration table.
25 It will ASSERT() if that operation fails and it will always return EFI_SUCCESS.
26
27 @param ImageHandle The firmware allocated handle for the EFI image.
28 @param SystemTable A pointer to the EFI System Table.
29
30 @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
31
32 **/
33 EFI_STATUS
34 EFIAPI
35 HobLibConstructor (
36 IN EFI_HANDLE ImageHandle,
37 IN EFI_SYSTEM_TABLE *SystemTable
38 )
39 {
40 EFI_STATUS Status;
41
42 Status = EfiGetSystemConfigurationTable (&gEfiHobListGuid, &mHobList);
43 ASSERT_EFI_ERROR (Status);
44 ASSERT (mHobList != NULL);
45 return Status;
46 }
47
48 /**
49 Returns the pointer to the HOB list.
50
51 None.
52
53 The pointer to the HOB list.
54
55 **/
56 VOID *
57 EFIAPI
58 GetHobList (
59 VOID
60 )
61 {
62 return mHobList;
63 }
64
65 /**
66 This function searches the first instance of a HOB type from the starting HOB pointer.
67 If there does not exist such HOB type from the starting HOB pointer, it will return NULL.
68
69 @param Type The HOB type to return.
70 @param HobStart The starting HOB pointer to search from.
71
72 @return The next instance of a HOB type from the starting HOB.
73
74 **/
75 VOID *
76 EFIAPI
77 GetNextHob (
78 IN UINT16 Type,
79 IN CONST VOID *HobStart
80 )
81 {
82 EFI_PEI_HOB_POINTERS Hob;
83
84 ASSERT (HobStart != NULL);
85
86 Hob.Raw = (UINT8 *) HobStart;
87 //
88 // Parse the HOB list, stop if end of list or matching type found.
89 //
90 while (!END_OF_HOB_LIST (Hob)) {
91 if (Hob.Header->HobType == Type) {
92 return Hob.Raw;
93 }
94 Hob.Raw = GET_NEXT_HOB (Hob);
95 }
96 return NULL;
97 }
98
99 /**
100 This function searches the first instance of a HOB type among the whole HOB list.
101 If there does not exist such HOB type in the HOB list, it will return NULL.
102
103 @param Type The HOB type to return.
104
105 @return The next instance of a HOB type from the starting HOB.
106
107 **/
108 VOID *
109 EFIAPI
110 GetFirstHob (
111 IN UINT16 Type
112 )
113 {
114 VOID *HobList;
115
116 HobList = GetHobList ();
117 return GetNextHob (Type, HobList);
118 }
119
120 /**
121 This function searches the first instance of a HOB from the starting HOB pointer.
122 Such HOB should satisfy two conditions:
123 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
124 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
125
126 @param Guid The GUID to match with in the HOB list.
127 @param HobStart A pointer to a Guid.
128
129 @return The next instance of the matched GUID HOB from the starting HOB.
130
131 **/
132 VOID *
133 EFIAPI
134 GetNextGuidHob (
135 IN CONST EFI_GUID *Guid,
136 IN CONST VOID *HobStart
137 )
138 {
139 EFI_PEI_HOB_POINTERS GuidHob;
140
141 GuidHob.Raw = (UINT8 *) HobStart;
142 while ((GuidHob.Raw = GetNextHob (EFI_HOB_TYPE_GUID_EXTENSION, GuidHob.Raw)) != NULL) {
143 if (CompareGuid (Guid, &GuidHob.Guid->Name)) {
144 break;
145 }
146 GuidHob.Raw = GET_NEXT_HOB (GuidHob);
147 }
148 return GuidHob.Raw;
149 }
150
151 /**
152 This function searches the first instance of a HOB among the whole HOB list.
153 Such HOB should satisfy two conditions:
154 its HOB type is EFI_HOB_TYPE_GUID_EXTENSION and its GUID Name equals to the input Guid.
155 If there does not exist such HOB from the starting HOB pointer, it will return NULL.
156
157 @param Guid The GUID to match with in the HOB list.
158
159 @return The first instance of the matched GUID HOB among the whole HOB list.
160
161 **/
162 VOID *
163 EFIAPI
164 GetFirstGuidHob (
165 IN CONST EFI_GUID *Guid
166 )
167 {
168 VOID *HobList;
169
170 HobList = GetHobList ();
171 return GetNextGuidHob (Guid, HobList);
172 }
173
174 /**
175 This function builds a HOB for a loaded PE32 module.
176
177 @param ModuleName The GUID File Name of the module.
178 @param MemoryAllocationModule The 64 bit physical address of the module.
179 @param ModuleLength The length of the module in bytes.
180 @param EntryPoint The 64 bit physical address of the module\92s entry point.
181
182 **/
183 VOID
184 EFIAPI
185 BuildModuleHob (
186 IN CONST EFI_GUID *ModuleName,
187 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,
188 IN UINT64 ModuleLength,
189 IN EFI_PHYSICAL_ADDRESS EntryPoint
190 )
191 {
192 //
193 // PEI HOB is read only for DXE phase
194 //
195 ASSERT (FALSE);
196 }
197
198 /**
199 Builds a HOB that describes a chunk of system memory.
200
201 @param ResourceType The type of resource described by this HOB.
202 @param ResourceAttribute The resource attributes of the memory described by this HOB.
203 @param PhysicalStart The 64 bit physical address of memory described by this HOB.
204 @param NumberOfBytes The length of the memory described by this HOB in bytes.
205
206 **/
207 VOID
208 EFIAPI
209 BuildResourceDescriptorHob (
210 IN EFI_RESOURCE_TYPE ResourceType,
211 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,
212 IN EFI_PHYSICAL_ADDRESS PhysicalStart,
213 IN UINT64 NumberOfBytes
214 )
215 {
216 //
217 // PEI HOB is read only for DXE phase
218 //
219 ASSERT (FALSE);
220 }
221
222 /**
223 This function builds a customized HOB tagged with a GUID for identification
224 and returns the start address of GUID HOB data so that caller can fill the customized data.
225
226 @param Guid The GUID to tag the customized HOB.
227 @param DataLength The size of the data payload for the GUID HOB.
228
229 @return The start address of GUID HOB data.
230
231 **/
232 VOID *
233 EFIAPI
234 BuildGuidHob (
235 IN CONST EFI_GUID *Guid,
236 IN UINTN DataLength
237 )
238 {
239 //
240 // PEI HOB is read only for DXE phase
241 //
242 ASSERT (FALSE);
243 return NULL;
244 }
245
246 /**
247 This function builds a customized HOB tagged with a GUID for identification,
248 copies the input data to the HOB data field, and returns the start address of GUID HOB data.
249
250 @param Guid The GUID to tag the customized HOB.
251 @param Data The data to be copied into the data field of the GUID HOB.
252 @param DataLength The size of the data payload for the GUID HOB.
253
254 @return The start address of GUID HOB data.
255
256 **/
257 VOID *
258 EFIAPI
259 BuildGuidDataHob (
260 IN CONST EFI_GUID *Guid,
261 IN VOID *Data,
262 IN UINTN DataLength
263 )
264 {
265 //
266 // PEI HOB is read only for DXE phase
267 //
268 ASSERT (FALSE);
269 return NULL;
270 }
271
272 /**
273 Builds a Firmware Volume HOB.
274
275 @param BaseAddress The base address of the Firmware Volume.
276 @param Length The size of the Firmware Volume in bytes.
277
278 **/
279 VOID
280 EFIAPI
281 BuildFvHob (
282 IN EFI_PHYSICAL_ADDRESS BaseAddress,
283 IN UINT64 Length
284 )
285 {
286 //
287 // PEI HOB is read only for DXE phase
288 //
289 ASSERT (FALSE);
290 }
291
292 /**
293 Builds a Capsule Volume HOB.
294
295 @param BaseAddress The base address of the Capsule Volume.
296 @param Length The size of the Capsule Volume in bytes.
297
298 **/
299 VOID
300 EFIAPI
301 BuildCvHob (
302 IN EFI_PHYSICAL_ADDRESS BaseAddress,
303 IN UINT64 Length
304 )
305 {
306 //
307 // PEI HOB is read only for DXE phase
308 //
309 ASSERT (FALSE);
310 }
311
312 /**
313 Builds a HOB for the CPU.
314
315 @param SizeOfMemorySpace The maximum physical memory addressability of the processor.
316 @param SizeOfIoSpace The maximum physical I/O addressability of the processor.
317
318 **/
319 VOID
320 EFIAPI
321 BuildCpuHob (
322 IN UINT8 SizeOfMemorySpace,
323 IN UINT8 SizeOfIoSpace
324 )
325 {
326 //
327 // PEI HOB is read only for DXE phase
328 //
329 ASSERT (FALSE);
330 }
331
332 /**
333 Builds a HOB for the Stack.
334
335 @param BaseAddress The 64 bit physical address of the Stack.
336 @param Length The length of the stack in bytes.
337
338 **/
339 VOID
340 EFIAPI
341 BuildStackHob (
342 IN EFI_PHYSICAL_ADDRESS BaseAddress,
343 IN UINT64 Length
344 )
345 {
346 //
347 // PEI HOB is read only for DXE phase
348 //
349 ASSERT (FALSE);
350 }
351
352 /**
353 Builds a HOB for the BSP store.
354
355 @param BaseAddress The 64 bit physical address of the BSP.
356 @param Length The length of the BSP store in bytes.
357 @param MemoryType Type of memory allocated by this HOB.
358
359 **/
360 VOID
361 EFIAPI
362 BuildBspStoreHob (
363 IN EFI_PHYSICAL_ADDRESS BaseAddress,
364 IN UINT64 Length,
365 IN EFI_MEMORY_TYPE MemoryType
366 )
367 {
368 //
369 // PEI HOB is read only for DXE phase
370 //
371 ASSERT (FALSE);
372 }
373
374 /**
375 Builds a HOB for the memory allocation.
376
377 @param BaseAddress The 64 bit physical address of the memory.
378 @param Length The length of the memory allocation in bytes.
379 @param MemoryType Type of memory allocated by this HOB.
380
381 **/
382 VOID
383 EFIAPI
384 BuildMemoryAllocationHob (
385 IN EFI_PHYSICAL_ADDRESS BaseAddress,
386 IN UINT64 Length,
387 IN EFI_MEMORY_TYPE MemoryType
388 )
389 {
390 //
391 // PEI HOB is read only for DXE phase
392 //
393 ASSERT (FALSE);
394 }