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