]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/Source/TianoTools/Common/PeiLib/Hob/Hob.c
Add <FrameworkModules> in EdkModulePkg-All-Archs.fpd and MdePkg-All-Archs.fpd file...
[mirror_edk2.git] / Tools / Source / TianoTools / Common / PeiLib / Hob / Hob.c
CommitLineData
878ddf1f 1\r
2/*++\r
3\r
4Copyright (c) 2004, Intel Corporation \r
5All rights reserved. This program and the accompanying materials \r
6are licensed and made available under the terms and conditions of the BSD License \r
7which accompanies this distribution. The full text of the license may be found at \r
8http://opensource.org/licenses/bsd-license.php \r
9 \r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, \r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. \r
12\r
13Module Name:\r
14\r
15 hob.c\r
16\r
17Abstract:\r
18\r
19 PEI Library Functions\r
20 \r
21--*/\r
22\r
23#include "Tiano.h"\r
24#include "Pei.h"\r
25#include "peilib.h"\r
26#include EFI_GUID_DEFINITION (MemoryAllocationHob)\r
27\r
28\r
29EFI_STATUS\r
30PeiBuildHobModule (\r
31 IN EFI_PEI_SERVICES **PeiServices,\r
32 IN EFI_GUID *ModuleName,\r
33 IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule,\r
34 IN UINT64 ModuleLength,\r
35 IN EFI_PHYSICAL_ADDRESS EntryPoint\r
36 )\r
37/*++\r
38\r
39Routine Description:\r
40\r
41 Builds a HOB for a loaded PE32 module\r
42\r
43Arguments:\r
44\r
45 PeiServices - The PEI core services table.\r
46 ModuleName - The GUID File Name of the module\r
47 MemoryAllocationModule - The 64 bit physical address of the module\r
48 ModuleLength - The length of the module in bytes\r
49 EntryPoint - The 64 bit physical address of the entry point\r
50 to the module\r
51\r
52Returns:\r
53\r
54 EFI_SUCCESS - Hob is successfully built.\r
55 Others - Errors occur while creating new Hob\r
56\r
57--*/\r
58{\r
59 EFI_STATUS Status; \r
60 EFI_HOB_MEMORY_ALLOCATION_MODULE *Hob;\r
61\r
62 Status = (*PeiServices)->CreateHob (\r
63 PeiServices,\r
64 EFI_HOB_TYPE_GUID_EXTENSION,\r
65 sizeof (EFI_HOB_MEMORY_ALLOCATION_MODULE),\r
66 &Hob\r
67 );\r
68 if (EFI_ERROR (Status)) {\r
69 return Status;\r
70 }\r
71\r
72 Hob->MemoryAllocationHeader.Name = gEfiHobMemeryAllocModuleGuid;\r
73 Hob->MemoryAllocationHeader.MemoryBaseAddress = MemoryAllocationModule;\r
74 Hob->MemoryAllocationHeader.MemoryLength = ModuleLength;\r
75 Hob->MemoryAllocationHeader.MemoryType = EfiBootServicesCode;\r
76\r
77 Hob->ModuleName = *ModuleName;\r
78 Hob->EntryPoint = EntryPoint;\r
79\r
80 return EFI_SUCCESS;\r
81}\r
82\r
83\r
84EFI_STATUS\r
85PeiBuildHobResourceDescriptor (\r
86 IN EFI_PEI_SERVICES **PeiServices,\r
87 IN EFI_RESOURCE_TYPE ResourceType,\r
88 IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute,\r
89 IN EFI_PHYSICAL_ADDRESS PhysicalStart,\r
90 IN UINT64 NumberOfBytes\r
91 )\r
92/*++\r
93\r
94Routine Description:\r
95\r
96 Builds a HOB that describes a chunck of system memory\r
97\r
98Arguments:\r
99\r
100 PeiServices - The PEI core services table.\r
101 \r
102 ResourceType - The type of resource described by this HOB\r
103\r
104 ResourceAttribute - The resource attributes of the memory described by this HOB\r
105\r
106 PhysicalStart - The 64 bit physical address of memory described by this HOB\r
107\r
108 NumberOfBytes - The length of the memoty described by this HOB in bytes\r
109\r
110Returns:\r
111\r
112 EFI_SUCCESS - Hob is successfully built.\r
113 Others - Errors occur while creating new Hob\r
114\r
115--*/\r
116{\r
117 EFI_STATUS Status; \r
118 EFI_HOB_RESOURCE_DESCRIPTOR *Hob;\r
119\r
120 Status = (*PeiServices)->CreateHob (\r
121 PeiServices,\r
122 EFI_HOB_TYPE_RESOURCE_DESCRIPTOR,\r
123 sizeof (EFI_HOB_RESOURCE_DESCRIPTOR),\r
124 &Hob\r
125 );\r
126 if (EFI_ERROR (Status)) {\r
127 return Status;\r
128 }\r
129\r
130 Hob->ResourceType = ResourceType;\r
131 Hob->ResourceAttribute = ResourceAttribute;\r
132 Hob->PhysicalStart = PhysicalStart;\r
133 Hob->ResourceLength = NumberOfBytes;\r
134\r
135 return EFI_SUCCESS;\r
136}\r
137\r
138\r
139EFI_STATUS\r
140PeiBuildHobGuid (\r
141 IN EFI_PEI_SERVICES **PeiServices,\r
142 IN EFI_GUID *Guid,\r
143 IN UINTN DataLength,\r
144 IN OUT VOID **Hob\r
145 )\r
146/*++\r
147\r
148Routine Description:\r
149\r
150 Builds a custom HOB that is tagged with a GUID for identification\r
151\r
152Arguments:\r
153\r
154 PeiServices - The PEI core services table.\r
155\r
156 Guid - The GUID of the custome HOB type\r
157\r
158 DataLength - The size of the data payload for the GUIDed HOB\r
159\r
160 Hob - Pointer to the Hob\r
161\r
162Returns:\r
163\r
164 EFI_SUCCESS - Hob is successfully built.\r
165 Others - Errors occur while creating new Hob\r
166\r
167--*/\r
168{\r
169 EFI_STATUS Status;\r
170\r
171 Status = (*PeiServices)->CreateHob (\r
172 PeiServices,\r
173 EFI_HOB_TYPE_GUID_EXTENSION,\r
174 (UINT16) (sizeof (EFI_HOB_GUID_TYPE) + DataLength),\r
175 Hob\r
176 );\r
177 if (EFI_ERROR (Status)) {\r
178 return Status;\r
179 }\r
180\r
181 ((EFI_HOB_GUID_TYPE *)(*Hob))->Name = *Guid;\r
182 \r
183 return EFI_SUCCESS;\r
184}\r
185\r
186\r
187EFI_STATUS\r
188PeiBuildHobGuidData (\r
189 IN EFI_PEI_SERVICES **PeiServices,\r
190 IN EFI_GUID *Guid,\r
191 IN VOID *Data,\r
192 IN UINTN DataLength\r
193 )\r
194/*++\r
195\r
196Routine Description:\r
197\r
198 Builds a custom HOB that is tagged with a GUID for identification\r
199\r
200Arguments:\r
201\r
202 PeiServices - The PEI core services table.\r
203\r
204 Guid - The GUID of the custome HOB type\r
205\r
206 Data - The data to be copied into the GUIDed HOB data field.\r
207\r
208 DataLength - The data field length.\r
209\r
210Returns:\r
211\r
212 EFI_SUCCESS - Hob is successfully built.\r
213 Others - Errors occur while creating new Hob\r
214\r
215--*/\r
216{\r
217 EFI_STATUS Status;\r
218 \r
219 EFI_HOB_GUID_TYPE *Hob;\r
220\r
221 Status = PeiBuildHobGuid (\r
222 PeiServices,\r
223 Guid,\r
224 DataLength,\r
225 &Hob\r
226 );\r
227\r
228 if (EFI_ERROR (Status)) {\r
229 return Status;\r
230 } \r
231\r
232 Hob++;\r
233 (*PeiServices)->CopyMem (Hob, Data, DataLength);\r
234 \r
235 return EFI_SUCCESS;\r
236}\r
237\r
238\r
239EFI_STATUS\r
240PeiBuildHobFv (\r
241 IN EFI_PEI_SERVICES **PeiServices,\r
242 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
243 IN UINT64 Length\r
244 )\r
245/*++\r
246\r
247Routine Description:\r
248\r
249 Builds a Firmware Volume HOB\r
250\r
251Arguments:\r
252\r
253 PeiServices - The PEI core services table.\r
254\r
255 BaseAddress - The base address of the Firmware Volume\r
256\r
257 Length - The size of the Firmware Volume in bytes\r
258\r
259Returns:\r
260\r
261 EFI_SUCCESS - Hob is successfully built.\r
262 Others - Errors occur while creating new Hob\r
263\r
264--*/\r
265{\r
266 EFI_STATUS Status; \r
267 EFI_HOB_FIRMWARE_VOLUME *Hob;\r
268\r
269 Status = (*PeiServices)->CreateHob (\r
270 PeiServices,\r
271 EFI_HOB_TYPE_FV,\r
272 sizeof (EFI_HOB_FIRMWARE_VOLUME),\r
273 &Hob\r
274 );\r
275 if (EFI_ERROR (Status)) {\r
276 return Status;\r
277 }\r
278\r
279 Hob->BaseAddress = BaseAddress;\r
280 Hob->Length = Length;\r
281\r
282 return EFI_SUCCESS;\r
283}\r
284\r
285\r
286EFI_STATUS\r
287PeiBuildHobCpu (\r
288 IN EFI_PEI_SERVICES **PeiServices,\r
289 IN UINT8 SizeOfMemorySpace,\r
290 IN UINT8 SizeOfIoSpace\r
291 )\r
292/*++\r
293\r
294Routine Description:\r
295\r
296 Builds a HOB for the CPU\r
297\r
298Arguments:\r
299\r
300 PeiServices - The PEI core services table.\r
301\r
302 SizeOfMemorySpace - Identifies the maximum \r
303 physical memory addressibility of the processor.\r
304\r
305 SizeOfIoSpace - Identifies the maximum physical I/O addressibility \r
306 of the processor.\r
307\r
308Returns:\r
309\r
310 EFI_SUCCESS - Hob is successfully built.\r
311 Others - Errors occur while creating new Hob\r
312\r
313--*/\r
314{\r
315 EFI_STATUS Status; \r
316 EFI_HOB_CPU *Hob;\r
317\r
318 Status = (*PeiServices)->CreateHob (\r
319 PeiServices,\r
320 EFI_HOB_TYPE_CPU,\r
321 sizeof (EFI_HOB_CPU),\r
322 &Hob\r
323 );\r
324 if (EFI_ERROR (Status)) {\r
325 return Status;\r
326 }\r
327\r
328 Hob->SizeOfMemorySpace = SizeOfMemorySpace;\r
329 Hob->SizeOfIoSpace = SizeOfIoSpace;\r
330\r
331 return EFI_SUCCESS;\r
332}\r
333\r
334\r
335\r
336EFI_STATUS\r
337PeiBuildHobStack (\r
338 IN EFI_PEI_SERVICES **PeiServices,\r
339 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
340 IN UINT64 Length\r
341 )\r
342/*++\r
343\r
344Routine Description:\r
345\r
346 Builds a HOB for the Stack\r
347\r
348Arguments:\r
349\r
350 PeiServices - The PEI core services table.\r
351\r
352 BaseAddress - The 64 bit physical address of the Stack\r
353\r
354 Length - The length of the stack in bytes\r
355\r
356Returns:\r
357\r
358 EFI_SUCCESS - Hob is successfully built.\r
359 Others - Errors occur while creating new Hob\r
360\r
361--*/\r
362{\r
363 EFI_STATUS Status; \r
364 EFI_HOB_MEMORY_ALLOCATION_STACK *Hob;\r
365\r
366 Status = (*PeiServices)->CreateHob (\r
367 PeiServices,\r
368 EFI_HOB_TYPE_MEMORY_ALLOCATION,\r
369 sizeof (EFI_HOB_MEMORY_ALLOCATION_STACK),\r
370 &Hob\r
371 );\r
372 if (EFI_ERROR (Status)) {\r
373 return Status;\r
374 }\r
375 \r
376 Hob->AllocDescriptor.Name = gEfiHobMemeryAllocStackGuid;\r
377 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
378 Hob->AllocDescriptor.MemoryLength = Length;\r
379 Hob->AllocDescriptor.MemoryType = EfiConventionalMemory;\r
380\r
381 return EFI_SUCCESS;\r
382}\r
383\r
384\r
385\r
386EFI_STATUS\r
387PeiBuildHobBspStore (\r
388 IN EFI_PEI_SERVICES **PeiServices,\r
389 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
390 IN UINT64 Length,\r
391 IN EFI_MEMORY_TYPE MemoryType\r
392 )\r
393/*++\r
394\r
395Routine Description:\r
396\r
397 Builds a HOB for the bsp store\r
398\r
399Arguments:\r
400\r
401 PeiServices - The PEI core services table.\r
402\r
403 BaseAddress - The 64 bit physical address of the bsp\r
404\r
405 Length - The length of the bsp store in bytes\r
406\r
407 MemoryType - Memory type\r
408\r
409Returns:\r
410\r
411 EFI_SUCCESS - Hob is successfully built.\r
412 Others - Errors occur while creating new Hob\r
413\r
414--*/\r
415{\r
416 EFI_STATUS Status; \r
417 EFI_HOB_MEMORY_ALLOCATION_BSP_STORE *Hob;\r
418\r
419 Status = (*PeiServices)->CreateHob (\r
420 PeiServices,\r
421 EFI_HOB_TYPE_MEMORY_ALLOCATION,\r
422 sizeof (EFI_HOB_MEMORY_ALLOCATION_BSP_STORE),\r
423 &Hob\r
424 );\r
425 if (EFI_ERROR (Status)) {\r
426 return Status;\r
427 }\r
428 \r
429 Hob->AllocDescriptor.Name = gEfiHobMemeryAllocBspStoreGuid;\r
430 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
431 Hob->AllocDescriptor.MemoryLength = Length;\r
432 Hob->AllocDescriptor.MemoryType = MemoryType;\r
433\r
434 return EFI_SUCCESS;\r
435}\r
436\r
437\r
438EFI_STATUS\r
439PeiBuildHobMemoryAllocation (\r
440 IN EFI_PEI_SERVICES **PeiServices,\r
441 IN EFI_PHYSICAL_ADDRESS BaseAddress,\r
442 IN UINT64 Length,\r
443 IN EFI_GUID *Name,\r
444 IN EFI_MEMORY_TYPE MemoryType\r
445 )\r
446/*++\r
447\r
448Routine Description:\r
449\r
450 Builds a HOB for the memory allocation.\r
451\r
452Arguments:\r
453\r
454 PeiServices - The PEI core services table.\r
455\r
456 BaseAddress - The 64 bit physical address of the memory\r
457\r
458 Length - The length of the memory allocation in bytes\r
459\r
460 Name - Name for Hob\r
461\r
462 MemoryType - Memory type\r
463\r
464Returns:\r
465\r
466 EFI_SUCCESS - Hob is successfully built.\r
467 Others - Errors occur while creating new Hob\r
468\r
469--*/\r
470{\r
471 EFI_STATUS Status; \r
472 EFI_HOB_MEMORY_ALLOCATION *Hob;\r
473\r
474 Status = (*PeiServices)->CreateHob (\r
475 PeiServices,\r
476 EFI_HOB_TYPE_MEMORY_ALLOCATION,\r
477 sizeof (EFI_HOB_MEMORY_ALLOCATION),\r
478 &Hob\r
479 );\r
480 if (EFI_ERROR (Status)) {\r
481 return Status;\r
482 }\r
483\r
484 if (Name != NULL) {\r
485 Hob->AllocDescriptor.Name = *Name;\r
486 } else {\r
487 (*PeiServices)->SetMem(&(Hob->AllocDescriptor.Name), sizeof (EFI_GUID), 0);\r
488 }\r
489\r
490 Hob->AllocDescriptor.MemoryBaseAddress = BaseAddress;\r
491 Hob->AllocDescriptor.MemoryLength = Length;\r
492 Hob->AllocDescriptor.MemoryType = MemoryType;\r
493\r
494 return EFI_SUCCESS;\r
495}\r