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