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