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