1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
|
/*++
Copyright (c) 2004 - 2006, Intel Corporation. All rights reserved.<BR>
This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
hob.c
Abstract:
Support for hob operation
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
#include "PeiHob.h"
#include EFI_GUID_DEFINITION (IoBaseHob)
#include EFI_GUID_DEFINITION (MemoryAllocationHob)
VOID *
GetHob (
IN UINT16 Type,
IN VOID *HobStart
)
/*++
Routine Description:
This function returns the first instance of a HOB type in a HOB list.
Arguments:
Type The HOB type to return.
HobStart The first HOB in the HOB list.
Returns:
HobStart There were no HOBs found with the requested type.
else Returns the first HOB with the matching type.
--*/
{
EFI_PEI_HOB_POINTERS Hob;
Hob.Raw = HobStart;
//
// Return input if not found
//
if (HobStart == NULL) {
return HobStart;
}
//
// Parse the HOB list, stop if end of list or matching type found.
//
while (!END_OF_HOB_LIST (Hob)) {
if (Hob.Header->HobType == Type) {
break;
}
Hob.Raw = GET_NEXT_HOB (Hob);
}
//
// Return input if not found
//
if (END_OF_HOB_LIST (Hob)) {
return HobStart;
}
return (VOID *) (Hob.Raw);
}
UINTN
GetHobListSize (
IN VOID *HobStart
)
/*++
Routine Description:
Get size of hob list.
Arguments:
HobStart - Start pointer of hob list
Returns:
Size of hob list.
--*/
{
EFI_PEI_HOB_POINTERS Hob;
UINTN Size;
Hob.Raw = HobStart;
Size = 0;
while (Hob.Header->HobType != EFI_HOB_TYPE_END_OF_HOB_LIST) {
Size += Hob.Header->HobLength;
Hob.Raw += Hob.Header->HobLength;
}
Size += Hob.Header->HobLength;
return Size;
}
UINT32
GetHobVersion (
IN VOID *HobStart
)
/*++
Routine Description:
Get hob version.
Arguments:
HobStart - Start pointer of hob list
Returns:
Hob version.
--*/
{
EFI_PEI_HOB_POINTERS Hob;
Hob.Raw = HobStart;
return Hob.HandoffInformationTable->Version;
}
EFI_STATUS
GetHobBootMode (
IN VOID *HobStart,
OUT EFI_BOOT_MODE *BootMode
)
/*++
Routine Description:
Get current boot mode.
Arguments:
HobStart - Start pointer of hob list
BootMode - Current boot mode recorded in PHIT hob
Returns:
EFI_NOT_FOUND - Invalid hob header
EFI_SUCCESS - Boot mode found
--*/
{
EFI_PEI_HOB_POINTERS Hob;
Hob.Raw = HobStart;
if (Hob.Header->HobType != EFI_HOB_TYPE_HANDOFF) {
return EFI_NOT_FOUND;
}
*BootMode = Hob.HandoffInformationTable->BootMode;
return EFI_SUCCESS;
}
EFI_STATUS
GetCpuHobInfo (
IN VOID *HobStart,
OUT UINT8 *SizeOfMemorySpace,
OUT UINT8 *SizeOfIoSpace
)
/*++
Routine Description:
Get information recorded in CPU hob (Memory space size, Io space size)
Arguments:
HobStart - Start pointer of hob list
SizeOfMemorySpace - Size of memory size
SizeOfIoSpace - Size of IO size
Returns:
EFI_NOT_FOUND - CPU hob not found
EFI_SUCCESS - CPU hob found and information got.
--*/
{
EFI_PEI_HOB_POINTERS CpuHob;
CpuHob.Raw = HobStart;
CpuHob.Raw = GetHob (EFI_HOB_TYPE_CPU, CpuHob.Raw);
if (CpuHob.Header->HobType != EFI_HOB_TYPE_CPU) {
return EFI_NOT_FOUND;
}
*SizeOfMemorySpace = CpuHob.Cpu->SizeOfMemorySpace;
*SizeOfIoSpace = CpuHob.Cpu->SizeOfIoSpace;
return EFI_SUCCESS;
}
EFI_STATUS
GetDxeCoreHobInfo (
IN VOID *HobStart,
OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
OUT UINT64 *Length,
OUT VOID **EntryPoint,
OUT EFI_GUID **FileName
)
/*++
Routine Description:
Get memory allocation hob created for DXE core and extract its information
Arguments:
HobStart - Start pointer of the hob list
BaseAddress - Start address of memory allocated for DXE core
Length - Length of memory allocated for DXE core
EntryPoint - DXE core file name
FileName - File Name
Returns:
EFI_NOT_FOUND - DxeCoreHob not found
EFI_SUCCESS - DxeCoreHob found and information got
--*/
{
EFI_PEI_HOB_POINTERS DxeCoreHob;
DxeCoreHob.Raw = HobStart;
DxeCoreHob.Raw = GetHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, DxeCoreHob.Raw);
while (DxeCoreHob.Header->HobType == EFI_HOB_TYPE_MEMORY_ALLOCATION &&
!EfiCompareGuid (&DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.Name,
&gEfiHobMemeryAllocModuleGuid)) {
DxeCoreHob.Raw = GET_NEXT_HOB (DxeCoreHob);
DxeCoreHob.Raw = GetHob (EFI_HOB_TYPE_MEMORY_ALLOCATION, DxeCoreHob.Raw);
}
if (DxeCoreHob.Header->HobType != EFI_HOB_TYPE_MEMORY_ALLOCATION) {
return EFI_NOT_FOUND;
}
*BaseAddress = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryBaseAddress;
*Length = DxeCoreHob.MemoryAllocationModule->MemoryAllocationHeader.MemoryLength;
*EntryPoint = (VOID *) (UINTN) DxeCoreHob.MemoryAllocationModule->EntryPoint;
*FileName = &DxeCoreHob.MemoryAllocationModule->ModuleName;
return EFI_SUCCESS;
}
EFI_STATUS
GetNextFirmwareVolumeHob (
IN OUT VOID **HobStart,
OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
OUT UINT64 *Length
)
/*++
Routine Description:
Get next firmware volume hob from HobStart
Arguments:
HobStart - Start pointer of hob list
BaseAddress - Start address of next firmware volume
Length - Length of next firmware volume
Returns:
EFI_NOT_FOUND - Next firmware volume not found
EFI_SUCCESS - Next firmware volume found with address information
--*/
{
EFI_PEI_HOB_POINTERS FirmwareVolumeHob;
FirmwareVolumeHob.Raw = *HobStart;
if (END_OF_HOB_LIST (FirmwareVolumeHob)) {
return EFI_NOT_FOUND;
}
FirmwareVolumeHob.Raw = GetHob (EFI_HOB_TYPE_FV, *HobStart);
if (FirmwareVolumeHob.Header->HobType != EFI_HOB_TYPE_FV) {
return EFI_NOT_FOUND;
}
*BaseAddress = FirmwareVolumeHob.FirmwareVolume->BaseAddress;
*Length = FirmwareVolumeHob.FirmwareVolume->Length;
*HobStart = GET_NEXT_HOB (FirmwareVolumeHob);
return EFI_SUCCESS;
}
#if (PI_SPECIFICATION_VERSION >= 0x00010000)
EFI_STATUS
GetNextFirmwareVolume2Hob (
IN OUT VOID **HobStart,
OUT EFI_PHYSICAL_ADDRESS *BaseAddress,
OUT UINT64 *Length,
OUT EFI_GUID *FileName
)
/*++
Routine Description:
Get next firmware volume2 hob from HobStart
Arguments:
HobStart - Start pointer of hob list
BaseAddress - Start address of next firmware volume
Length - Length of next firmware volume
Returns:
EFI_NOT_FOUND - Next firmware volume not found
EFI_SUCCESS - Next firmware volume found with address information
--*/
{
EFI_PEI_HOB_POINTERS FirmwareVolumeHob;
FirmwareVolumeHob.Raw = *HobStart;
if (END_OF_HOB_LIST (FirmwareVolumeHob)) {
return EFI_NOT_FOUND;
}
FirmwareVolumeHob.Raw = GetHob (EFI_HOB_TYPE_FV2, *HobStart);
if (FirmwareVolumeHob.Header->HobType != EFI_HOB_TYPE_FV2) {
return EFI_NOT_FOUND;
}
*BaseAddress = FirmwareVolumeHob.FirmwareVolume2->BaseAddress;
*Length = FirmwareVolumeHob.FirmwareVolume2->Length;
EfiCommonLibCopyMem(FileName,&FirmwareVolumeHob.FirmwareVolume2->FileName,sizeof(EFI_GUID));
*HobStart = GET_NEXT_HOB (FirmwareVolumeHob);
return EFI_SUCCESS;
}
#endif
EFI_STATUS
GetNextGuidHob (
IN OUT VOID **HobStart,
IN EFI_GUID * Guid,
OUT VOID **Buffer,
OUT UINTN *BufferSize OPTIONAL
)
/*++
Routine Description:
Get the next guid hob.
Arguments:
HobStart A pointer to the start hob.
Guid A pointer to a guid.
Buffer A pointer to the buffer.
BufferSize Buffer size.
Returns:
Status code.
EFI_NOT_FOUND - Next Guid hob not found
EFI_SUCCESS - Next Guid hob found and data for this Guid got
EFI_INVALID_PARAMETER - invalid parameter
--*/
{
EFI_STATUS Status;
EFI_PEI_HOB_POINTERS GuidHob;
if (Buffer == NULL) {
return EFI_INVALID_PARAMETER;
}
for (Status = EFI_NOT_FOUND; EFI_ERROR (Status);) {
GuidHob.Raw = *HobStart;
if (END_OF_HOB_LIST (GuidHob)) {
return EFI_NOT_FOUND;
}
GuidHob.Raw = GetHob (EFI_HOB_TYPE_GUID_EXTENSION, *HobStart);
if (GuidHob.Header->HobType == EFI_HOB_TYPE_GUID_EXTENSION) {
if (EfiCompareGuid (Guid, &GuidHob.Guid->Name)) {
Status = EFI_SUCCESS;
*Buffer = (VOID *) ((UINT8 *) (&GuidHob.Guid->Name) + sizeof (EFI_GUID));
if (BufferSize != NULL) {
*BufferSize = GuidHob.Header->HobLength - sizeof (EFI_HOB_GUID_TYPE);
}
}
}
*HobStart = GET_NEXT_HOB (GuidHob);
}
return Status;
}
#define PAL_ENTRY_HOB {0xe53cb8cc, 0xd62c, 0x4f74, {0xbd, 0xda, 0x31, 0xe5, 0x8d, 0xe5, 0x3e, 0x2}}
EFI_GUID gPalEntryHob = PAL_ENTRY_HOB;
EFI_STATUS
GetPalEntryHobInfo (
IN VOID *HobStart,
OUT EFI_PHYSICAL_ADDRESS *PalEntry
)
/*++
Routine Description:
Get PAL entry from PalEntryHob
Arguments:
HobStart - Start pointer of hob list
PalEntry - Pointer to PAL entry
Returns:
Status code.
--*/
{
VOID *Buffer;
UINTN BufferSize;
EFI_STATUS Status;
VOID *HobStart2;
HobStart2 = HobStart;
Status = GetNextGuidHob (
&HobStart2,
&gPalEntryHob,
&Buffer,
&BufferSize
);
*PalEntry = *((EFI_PHYSICAL_ADDRESS *) Buffer);
return Status;
}
EFI_STATUS
GetIoPortSpaceAddressHobInfo (
IN VOID *HobStart,
OUT EFI_PHYSICAL_ADDRESS *IoPortSpaceAddress
)
/*++
Routine Description:
Get IO port space address from IoBaseHob.
Arguments:
HobStart - Start pointer of hob list
IoPortSpaceAddress - IO port space address
Returns:
Status code
--*/
{
VOID *Buffer;
UINTN BufferSize;
EFI_STATUS Status;
VOID *HobStart2;
HobStart2 = HobStart;
Status = GetNextGuidHob (
&HobStart2,
&gEfiIoBaseHobGuid,
&Buffer,
&BufferSize
);
*IoPortSpaceAddress = *((EFI_PHYSICAL_ADDRESS *) Buffer);
return Status;
}
|