TianoCore EDK2 master
Loading...
Searching...
No Matches
SmbiosMeasurementDxe.c
Go to the documentation of this file.
1
9#include <PiDxe.h>
10
11#include <Protocol/Smbios.h>
14#include <Guid/EventGroup.h>
15#include <Guid/SmBios.h>
16#include <Library/DebugLib.h>
18#include <Library/UefiLib.h>
19#include <Library/BaseLib.h>
23#include <Library/PcdLib.h>
25
26#define FIELD_SIZE_OF(TYPE, Field) ((UINTN)sizeof(((TYPE *)0)->Field))
27
28typedef struct {
29 UINT8 Type;
30 UINTN Offset;
31 UINTN Size;
32 UINT32 Flags;
34#define SMBIOS_FILTER_TABLE_FLAG_IS_STRING BIT0
35
36typedef struct {
37 UINT8 Type;
38 SMBIOS_FILTER_TABLE *Filter; // NULL means all fields
39 UINTN FilterCount;
41
42//
43// Platform Specific Policy
44//
45SMBIOS_FILTER_TABLE mSmbiosFilterType1BlackList[] = {
46 { 0x01, OFFSET_OF (SMBIOS_TABLE_TYPE1, SerialNumber), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE1, SerialNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING },
47 { 0x01, OFFSET_OF (SMBIOS_TABLE_TYPE1, Uuid), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE1, Uuid), 0 },
48 { 0x01, OFFSET_OF (SMBIOS_TABLE_TYPE1, WakeUpType), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE1, WakeUpType), 0 },
49};
50SMBIOS_FILTER_TABLE mSmbiosFilterType2BlackList[] = {
51 { 0x02, OFFSET_OF (SMBIOS_TABLE_TYPE2, SerialNumber), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE2, SerialNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING },
52 { 0x02, OFFSET_OF (SMBIOS_TABLE_TYPE2, LocationInChassis), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE2, LocationInChassis), SMBIOS_FILTER_TABLE_FLAG_IS_STRING },
53};
54SMBIOS_FILTER_TABLE mSmbiosFilterType3BlackList[] = {
55 { 0x03, OFFSET_OF (SMBIOS_TABLE_TYPE3, SerialNumber), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE3, SerialNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING },
56 { 0x03, OFFSET_OF (SMBIOS_TABLE_TYPE3, AssetTag), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE3, AssetTag), SMBIOS_FILTER_TABLE_FLAG_IS_STRING },
57};
58SMBIOS_FILTER_TABLE mSmbiosFilterType4BlackList[] = {
59 { 0x04, OFFSET_OF (SMBIOS_TABLE_TYPE4, SerialNumber), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE4, SerialNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING },
60 { 0x04, OFFSET_OF (SMBIOS_TABLE_TYPE4, AssetTag), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE4, AssetTag), SMBIOS_FILTER_TABLE_FLAG_IS_STRING },
61 { 0x04, OFFSET_OF (SMBIOS_TABLE_TYPE4, PartNumber), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE4, PartNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING },
62 { 0x04, OFFSET_OF (SMBIOS_TABLE_TYPE4, CoreCount), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE4, CoreCount), 0 },
63 { 0x04, OFFSET_OF (SMBIOS_TABLE_TYPE4, EnabledCoreCount), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE4, EnabledCoreCount), 0 },
64 { 0x04, OFFSET_OF (SMBIOS_TABLE_TYPE4, ThreadCount), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE4, ThreadCount), 0 },
65 { 0x04, OFFSET_OF (SMBIOS_TABLE_TYPE4, CoreCount2), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE4, CoreCount2), 0 },
66 { 0x04, OFFSET_OF (SMBIOS_TABLE_TYPE4, EnabledCoreCount2), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE4, EnabledCoreCount2), 0 },
67 { 0x04, OFFSET_OF (SMBIOS_TABLE_TYPE4, ThreadCount2), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE4, ThreadCount2), 0 },
68 { 0x04, OFFSET_OF (SMBIOS_TABLE_TYPE4, Voltage), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE4, Voltage), 0 },
69 { 0x04, OFFSET_OF (SMBIOS_TABLE_TYPE4, CurrentSpeed), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE4, CurrentSpeed), 0 },
70};
71SMBIOS_FILTER_TABLE mSmbiosFilterType17BlackList[] = {
72 { 0x11, OFFSET_OF (SMBIOS_TABLE_TYPE17, SerialNumber), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE17, SerialNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING },
73 { 0x11, OFFSET_OF (SMBIOS_TABLE_TYPE17, AssetTag), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE17, AssetTag), SMBIOS_FILTER_TABLE_FLAG_IS_STRING },
74 { 0x11, OFFSET_OF (SMBIOS_TABLE_TYPE17, PartNumber), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE17, PartNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING },
75};
76SMBIOS_FILTER_TABLE mSmbiosFilterType22BlackList[] = {
77 { 0x16, OFFSET_OF (SMBIOS_TABLE_TYPE22, SerialNumber), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE22, SerialNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING },
78 { 0x16, OFFSET_OF (SMBIOS_TABLE_TYPE22, SBDSSerialNumber), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE22, SBDSSerialNumber), 0 },
79 { 0x16, OFFSET_OF (SMBIOS_TABLE_TYPE22, SBDSManufactureDate), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE22, SBDSManufactureDate), 0 },
80};
81SMBIOS_FILTER_TABLE mSmbiosFilterType23BlackList[] = {
82 { 0x17, OFFSET_OF (SMBIOS_TABLE_TYPE23, ResetCount), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE23, ResetCount), 0 },
83};
84SMBIOS_FILTER_TABLE mSmbiosFilterType27BlackList[] = {
85 { 0x1B, OFFSET_OF (SMBIOS_TABLE_TYPE27, NominalSpeed), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE27, NominalSpeed), 0 },
86};
87SMBIOS_FILTER_TABLE mSmbiosFilterType39BlackList[] = {
88 { 0x27, OFFSET_OF (SMBIOS_TABLE_TYPE39, SerialNumber), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE39, SerialNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING },
89 { 0x27, OFFSET_OF (SMBIOS_TABLE_TYPE39, AssetTagNumber), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE39, AssetTagNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING },
90 { 0x27, OFFSET_OF (SMBIOS_TABLE_TYPE39, ModelPartNumber), FIELD_SIZE_OF (SMBIOS_TABLE_TYPE39, ModelPartNumber), SMBIOS_FILTER_TABLE_FLAG_IS_STRING },
91};
92
93SMBIOS_FILTER_STRUCT mSmbiosFilterStandardTableBlackList[] = {
94 { 0x01, mSmbiosFilterType1BlackList, sizeof (mSmbiosFilterType1BlackList)/sizeof (mSmbiosFilterType1BlackList[0]) },
95 { 0x02, mSmbiosFilterType2BlackList, sizeof (mSmbiosFilterType2BlackList)/sizeof (mSmbiosFilterType2BlackList[0]) },
96 { 0x03, mSmbiosFilterType3BlackList, sizeof (mSmbiosFilterType3BlackList)/sizeof (mSmbiosFilterType3BlackList[0]) },
97 { 0x04, mSmbiosFilterType4BlackList, sizeof (mSmbiosFilterType4BlackList)/sizeof (mSmbiosFilterType4BlackList[0]) },
98 { 0x0B, NULL, 0 },
99 { 0x0F, NULL, 0 },
100 { 0x11, mSmbiosFilterType17BlackList, sizeof (mSmbiosFilterType17BlackList)/sizeof (mSmbiosFilterType17BlackList[0]) },
101 { 0x12, NULL, 0 },
102 { 0x16, mSmbiosFilterType22BlackList, sizeof (mSmbiosFilterType22BlackList)/sizeof (mSmbiosFilterType22BlackList[0]) },
103 { 0x17, mSmbiosFilterType23BlackList, sizeof (mSmbiosFilterType23BlackList)/sizeof (mSmbiosFilterType23BlackList[0]) },
104 { 0x1B, mSmbiosFilterType27BlackList, sizeof (mSmbiosFilterType27BlackList)/sizeof (mSmbiosFilterType27BlackList[0]) },
105 { 0x1F, NULL, 0 },
106 { 0x21, NULL, 0 },
107 { 0x27, mSmbiosFilterType39BlackList, sizeof (mSmbiosFilterType39BlackList)/sizeof (mSmbiosFilterType39BlackList[0]) },
108};
109
110EFI_SMBIOS_PROTOCOL *mSmbios;
111UINTN mMaxLen;
112
113#pragma pack (1)
114
115#define SMBIOS_HANDOFF_TABLE_DESC "SmbiosTable"
116typedef struct {
117 UINT8 TableDescriptionSize;
118 UINT8 TableDescription[sizeof (SMBIOS_HANDOFF_TABLE_DESC)];
119 UINT64 NumberOfTables;
120 EFI_CONFIGURATION_TABLE TableEntry[1];
122
123#pragma pack ()
124
133VOID
135 IN UINT8 *Data,
136 IN UINTN Size
137 )
138{
139 UINTN Index;
140
141 for (Index = 0; Index < Size; Index++) {
142 DEBUG ((DEBUG_VERBOSE, "%02x", (UINTN)Data[Index]));
143 }
144}
145
154VOID
156 IN UINT8 *Data,
157 IN UINTN Size
158 )
159{
160 UINTN Index;
161 UINTN Count;
162 UINTN Left;
163
164 #define COLUME_SIZE (16 * 2)
165
166 Count = Size / COLUME_SIZE;
167 Left = Size % COLUME_SIZE;
168 for (Index = 0; Index < Count; Index++) {
169 DEBUG ((DEBUG_VERBOSE, "%04x: ", Index * COLUME_SIZE));
170 InternalDumpData (Data + Index * COLUME_SIZE, COLUME_SIZE);
171 DEBUG ((DEBUG_VERBOSE, "\n"));
172 }
173
174 if (Left != 0) {
175 DEBUG ((DEBUG_VERBOSE, "%04x: ", Index * COLUME_SIZE));
176 InternalDumpData (Data + Index * COLUME_SIZE, Left);
177 DEBUG ((DEBUG_VERBOSE, "\n"));
178 }
179}
180
190 IN UINT8 Type
191 )
192{
193 UINTN Index;
194
195 for (Index = 0; Index < sizeof (mSmbiosFilterStandardTableBlackList)/sizeof (mSmbiosFilterStandardTableBlackList[0]); Index++) {
196 if (mSmbiosFilterStandardTableBlackList[Index].Type == Type) {
197 return &mSmbiosFilterStandardTableBlackList[Index];
198 }
199 }
200
201 return NULL;
202}
203
214CHAR8 *
217 IN SMBIOS_TABLE_STRING StringId,
218 OUT UINTN *StringLen
219 )
220{
221 UINTN Size;
223 CHAR8 *CharInStr;
224 UINTN StringsNumber;
225 CHAR8 *String;
226
227 CharInStr = (CHAR8 *)Head + Head->Length;
228 Size = Head->Length;
229 StringsNumber = 0;
230 StrLen = 0;
231 //
232 // look for the two consecutive zeros, check the string limit by the way.
233 //
234 String = NULL;
235 while (*CharInStr != 0 || *(CharInStr+1) != 0) {
236 if (*CharInStr == 0) {
237 Size += 1;
238 CharInStr++;
239 }
240
241 String = CharInStr;
242
243 for (StrLen = 0; StrLen < mMaxLen; StrLen++) {
244 if (*(CharInStr+StrLen) == 0) {
245 break;
246 }
247 }
248
249 *StringLen = StrLen;
250
251 if (StrLen == mMaxLen) {
252 return NULL;
253 }
254
255 //
256 // forward the pointer
257 //
258 CharInStr += StrLen;
259 Size += StrLen;
260 StringsNumber += 1;
261 if (StringsNumber == StringId) {
262 break;
263 }
264 }
265
266 return String;
267}
268
277VOID
279 IN OUT VOID *TableEntry,
280 IN UINTN TableEntrySize
281 )
282{
283 SMBIOS_FILTER_STRUCT *FilterStruct;
284 SMBIOS_FILTER_TABLE *Filter;
285 UINTN Index;
286 SMBIOS_TABLE_STRING StringId;
287 CHAR8 *String;
288 UINTN StringLen;
289
290 DEBUG ((DEBUG_INFO, "Smbios Table (Type - %d):\n", ((SMBIOS_STRUCTURE *)TableEntry)->Type));
291 DEBUG_CODE (
292 InternalDumpHex (TableEntry, TableEntrySize);
293 );
294
295 //
296 // Skip measurement for OEM types.
297 //
298 if (((SMBIOS_STRUCTURE *)TableEntry)->Type >= SMBIOS_OEM_BEGIN) {
299 // zero all table fields, except header
300 ZeroMem ((UINT8 *)TableEntry + sizeof (SMBIOS_STRUCTURE), TableEntrySize - sizeof (SMBIOS_STRUCTURE));
301 } else {
302 FilterStruct = GetFilterStructByType (((SMBIOS_STRUCTURE *)TableEntry)->Type);
303 if (FilterStruct != NULL) {
304 if ((FilterStruct->Filter == NULL) || (FilterStruct->FilterCount == 0)) {
305 // zero all table fields, except header
306 ZeroMem ((UINT8 *)TableEntry + sizeof (SMBIOS_STRUCTURE), TableEntrySize - sizeof (SMBIOS_STRUCTURE));
307 } else {
308 Filter = FilterStruct->Filter;
309 for (Index = 0; Index < FilterStruct->FilterCount; Index++) {
310 if (((SMBIOS_STRUCTURE *)TableEntry)->Length >= (Filter[Index].Offset + Filter[Index].Size)) {
311 //
312 // The field is present in the SMBIOS entry.
313 //
314 if ((Filter[Index].Flags & SMBIOS_FILTER_TABLE_FLAG_IS_STRING) != 0) {
315 CopyMem (&StringId, (UINT8 *)TableEntry + Filter[Index].Offset, sizeof (StringId));
316 if (StringId != 0) {
317 // set ' ' for string field
318 String = GetSmbiosStringById (TableEntry, StringId, &StringLen);
319 ASSERT (String != NULL);
320 // DEBUG ((DEBUG_INFO,"StrId(0x%x)-%a(%d)\n", StringId, String, StringLen));
321 SetMem (String, StringLen, ' ');
322 }
323 }
324
325 // zero non-string field
326 ZeroMem ((UINT8 *)TableEntry + Filter[Index].Offset, Filter[Index].Size);
327 }
328 }
329 }
330 }
331 }
332
333 DEBUG ((DEBUG_INFO, "Filter Smbios Table (Type - %d):\n", ((SMBIOS_STRUCTURE *)TableEntry)->Type));
334 DEBUG_CODE (
335 InternalDumpHex (TableEntry, TableEntrySize);
336 );
337}
338
348UINTN
351 OUT UINTN *NumberOfStrings
352 )
353{
354 UINTN Size;
356 CHAR8 *CharInStr;
357 UINTN StringsNumber;
358
359 CharInStr = (CHAR8 *)Head + Head->Length;
360 Size = Head->Length;
361 StringsNumber = 0;
362 StrLen = 0;
363 //
364 // look for the two consecutive zeros, check the string limit by the way.
365 //
366 while (*CharInStr != 0 || *(CharInStr+1) != 0) {
367 if (*CharInStr == 0) {
368 Size += 1;
369 CharInStr++;
370 }
371
372 for (StrLen = 0; StrLen < mMaxLen; StrLen++) {
373 if (*(CharInStr+StrLen) == 0) {
374 break;
375 }
376 }
377
378 if (StrLen == mMaxLen) {
379 return 0;
380 }
381
382 //
383 // forward the pointer
384 //
385 CharInStr += StrLen;
386 Size += StrLen;
387 StringsNumber += 1;
388 }
389
390 //
391 // count ending two zeros.
392 //
393 Size += 2;
394
395 if (NumberOfStrings != NULL) {
396 *NumberOfStrings = StringsNumber;
397 }
398
399 return Size;
400}
401
412UINTN
414 IN VOID *TableAddress,
415 IN UINTN TableMaximumSize
416 )
417{
418 VOID *TableEntry;
419 VOID *TableAddressEnd;
420 UINTN TableEntryLength;
421
422 TableAddressEnd = (VOID *)((UINTN)TableAddress + TableMaximumSize);
423 TableEntry = TableAddress;
424 while (TableEntry < TableAddressEnd) {
425 TableEntryLength = GetSmbiosStructureSize (TableEntry, NULL);
426 if (TableEntryLength == 0) {
427 break;
428 }
429
430 if (((SMBIOS_STRUCTURE *)TableEntry)->Type == 127) {
431 TableEntry = (VOID *)((UINTN)TableEntry + TableEntryLength);
432 break;
433 }
434
435 TableEntry = (VOID *)((UINTN)TableEntry + TableEntryLength);
436 }
437
438 return ((UINTN)TableEntry - (UINTN)TableAddress);
439}
440
449VOID
451 IN OUT VOID *TableAddress,
452 IN UINTN TableLength
453 )
454{
455 VOID *TableAddressEnd;
456 VOID *TableEntry;
457 UINTN TableEntryLength;
458
459 TableEntry = TableAddress;
460 TableAddressEnd = (VOID *)((UINTN)TableAddress + TableLength);
461 while ((UINTN)TableEntry < (UINTN)TableAddressEnd) {
462 TableEntryLength = GetSmbiosStructureSize (TableEntry, NULL);
463 if (TableEntryLength == 0) {
464 break;
465 }
466
467 FilterSmbiosEntry (TableEntry, TableEntryLength);
468
469 TableEntry = (VOID *)((UINTN)TableEntry + TableEntryLength);
470 }
471}
472
480VOID
481EFIAPI
483 IN EFI_EVENT Event,
484 IN VOID *Context
485 )
486{
487 EFI_STATUS Status;
488 EFI_HANDOFF_TABLE_POINTERS HandoffTables;
489 SMBIOS_HANDOFF_TABLE_POINTERS2 SmbiosHandoffTables2;
490 UINT32 EventType;
491 VOID *EventLog;
492 UINT32 EventLogSize;
493 SMBIOS_TABLE_ENTRY_POINT *SmbiosTable;
494 SMBIOS_TABLE_3_0_ENTRY_POINT *Smbios3Table;
495 VOID *SmbiosTableAddress;
496 VOID *TableAddress;
497 UINTN TableLength;
498
499 SmbiosTable = NULL;
500 Smbios3Table = NULL;
501 SmbiosTableAddress = NULL;
502 TableLength = 0;
503
504 if (mSmbios->MajorVersion >= 3) {
506 &gEfiSmbios3TableGuid,
507 (VOID **)&Smbios3Table
508 );
509 if (!EFI_ERROR (Status)) {
510 DEBUG ((DEBUG_INFO, "Smbios3Table:\n"));
511 DEBUG ((
512 DEBUG_INFO,
513 " AnchorString - '%c%c%c%c%c'\n",
514 Smbios3Table->AnchorString[0],
515 Smbios3Table->AnchorString[1],
516 Smbios3Table->AnchorString[2],
517 Smbios3Table->AnchorString[3],
518 Smbios3Table->AnchorString[4]
519 ));
520 DEBUG ((DEBUG_INFO, " EntryPointStructureChecksum - 0x%02x\n", Smbios3Table->EntryPointStructureChecksum));
521 DEBUG ((DEBUG_INFO, " EntryPointLength - 0x%02x\n", Smbios3Table->EntryPointLength));
522 DEBUG ((DEBUG_INFO, " MajorVersion - 0x%02x\n", Smbios3Table->MajorVersion));
523 DEBUG ((DEBUG_INFO, " MinorVersion - 0x%02x\n", Smbios3Table->MinorVersion));
524 DEBUG ((DEBUG_INFO, " DocRev - 0x%02x\n", Smbios3Table->DocRev));
525 DEBUG ((DEBUG_INFO, " EntryPointRevision - 0x%02x\n", Smbios3Table->EntryPointRevision));
526 DEBUG ((DEBUG_INFO, " TableMaximumSize - 0x%08x\n", Smbios3Table->TableMaximumSize));
527 DEBUG ((DEBUG_INFO, " TableAddress - 0x%016lx\n", Smbios3Table->TableAddress));
528 }
529 }
530
531 if (Smbios3Table == NULL) {
533 &gEfiSmbiosTableGuid,
534 (VOID **)&SmbiosTable
535 );
536 if (!EFI_ERROR (Status)) {
537 DEBUG ((DEBUG_INFO, "SmbiosTable:\n"));
538 DEBUG ((
539 DEBUG_INFO,
540 " AnchorString - '%c%c%c%c'\n",
541 SmbiosTable->AnchorString[0],
542 SmbiosTable->AnchorString[1],
543 SmbiosTable->AnchorString[2],
544 SmbiosTable->AnchorString[3]
545 ));
546 DEBUG ((DEBUG_INFO, " EntryPointStructureChecksum - 0x%02x\n", SmbiosTable->EntryPointStructureChecksum));
547 DEBUG ((DEBUG_INFO, " EntryPointLength - 0x%02x\n", SmbiosTable->EntryPointLength));
548 DEBUG ((DEBUG_INFO, " MajorVersion - 0x%02x\n", SmbiosTable->MajorVersion));
549 DEBUG ((DEBUG_INFO, " MinorVersion - 0x%02x\n", SmbiosTable->MinorVersion));
550 DEBUG ((DEBUG_INFO, " MaxStructureSize - 0x%08x\n", SmbiosTable->MaxStructureSize));
551 DEBUG ((DEBUG_INFO, " EntryPointRevision - 0x%02x\n", SmbiosTable->EntryPointRevision));
552 DEBUG ((
553 DEBUG_INFO,
554 " FormattedArea - '%c%c%c%c%c'\n",
555 SmbiosTable->FormattedArea[0],
556 SmbiosTable->FormattedArea[1],
557 SmbiosTable->FormattedArea[2],
558 SmbiosTable->FormattedArea[3],
559 SmbiosTable->FormattedArea[4]
560 ));
561 DEBUG ((
562 DEBUG_INFO,
563 " IntermediateAnchorString - '%c%c%c%c%c'\n",
564 SmbiosTable->IntermediateAnchorString[0],
565 SmbiosTable->IntermediateAnchorString[1],
566 SmbiosTable->IntermediateAnchorString[2],
567 SmbiosTable->IntermediateAnchorString[3],
568 SmbiosTable->IntermediateAnchorString[4]
569 ));
570 DEBUG ((DEBUG_INFO, " IntermediateChecksum - 0x%02x\n", SmbiosTable->IntermediateChecksum));
571 DEBUG ((DEBUG_INFO, " TableLength - 0x%04x\n", SmbiosTable->TableLength));
572 DEBUG ((DEBUG_INFO, " TableAddress - 0x%08x\n", SmbiosTable->TableAddress));
573 DEBUG ((DEBUG_INFO, " NumberOfSmbiosStructures - 0x%04x\n", SmbiosTable->NumberOfSmbiosStructures));
574 DEBUG ((DEBUG_INFO, " SmbiosBcdRevision - 0x%02x\n", SmbiosTable->SmbiosBcdRevision));
575 }
576 }
577
578 if (Smbios3Table != NULL) {
579 SmbiosTableAddress = (VOID *)(UINTN)Smbios3Table->TableAddress;
580 TableLength = GetSmbiosTableLength (SmbiosTableAddress, Smbios3Table->TableMaximumSize);
581 } else if (SmbiosTable != NULL) {
582 SmbiosTableAddress = (VOID *)(UINTN)SmbiosTable->TableAddress;
583 TableLength = SmbiosTable->TableLength;
584 }
585
586 if (SmbiosTableAddress != NULL) {
587 DEBUG ((DEBUG_INFO, "The Smbios Table starts at: 0x%x\n", SmbiosTableAddress));
588 DEBUG ((DEBUG_INFO, "The Smbios Table size: 0x%x\n", TableLength));
589 DEBUG_CODE (
590 InternalDumpHex ((UINT8 *)(UINTN)SmbiosTableAddress, TableLength);
591 );
592
593 TableAddress = AllocateCopyPool ((UINTN)TableLength, (VOID *)(UINTN)SmbiosTableAddress);
594 if (TableAddress == NULL) {
595 return;
596 }
597
598 FilterSmbiosTable (TableAddress, TableLength);
599
600 DEBUG ((DEBUG_INFO, "The final Smbios Table starts at: 0x%x\n", TableAddress));
601 DEBUG ((DEBUG_INFO, "The final Smbios Table size: 0x%x\n", TableLength));
602 DEBUG_CODE (
603 InternalDumpHex (TableAddress, TableLength);
604 );
605
606 HandoffTables.NumberOfTables = 1;
607 if (Smbios3Table != NULL) {
608 CopyGuid (&(HandoffTables.TableEntry[0].VendorGuid), &gEfiSmbios3TableGuid);
609 HandoffTables.TableEntry[0].VendorTable = Smbios3Table;
610 } else {
611 CopyGuid (&(HandoffTables.TableEntry[0].VendorGuid), &gEfiSmbiosTableGuid);
612 HandoffTables.TableEntry[0].VendorTable = SmbiosTable;
613 }
614
615 EventType = EV_EFI_HANDOFF_TABLES;
616 EventLog = &HandoffTables;
617 EventLogSize = sizeof (HandoffTables);
618
619 if (PcdGet32 (PcdTcgPfpMeasurementRevision) >= TCG_EfiSpecIDEventStruct_SPEC_ERRATA_TPM2_REV_105) {
620 SmbiosHandoffTables2.TableDescriptionSize = sizeof (SmbiosHandoffTables2.TableDescription);
621 CopyMem (SmbiosHandoffTables2.TableDescription, SMBIOS_HANDOFF_TABLE_DESC, sizeof (SmbiosHandoffTables2.TableDescription));
622 SmbiosHandoffTables2.NumberOfTables = HandoffTables.NumberOfTables;
623 CopyMem (&(SmbiosHandoffTables2.TableEntry[0]), &(HandoffTables.TableEntry[0]), sizeof (SmbiosHandoffTables2.TableEntry[0]));
624 EventType = EV_EFI_HANDOFF_TABLES2;
625 EventLog = &SmbiosHandoffTables2;
626 EventLogSize = sizeof (SmbiosHandoffTables2);
627 }
628
629 Status = TpmMeasureAndLogData (
630 1, // PCRIndex
631 EventType, // EventType
632 EventLog, // EventLog
633 EventLogSize, // LogLen
634 TableAddress, // HashData
635 TableLength // HashDataLen
636 );
637 if (!EFI_ERROR (Status)) {
638 gBS->CloseEvent (Event);
639 }
640 }
641
642 return;
643}
644
656EFIAPI
658 IN EFI_HANDLE ImageHandle,
659 IN EFI_SYSTEM_TABLE *SystemTable
660 )
661{
662 EFI_STATUS Status;
663 EFI_EVENT Event;
664
665 Status = gBS->LocateProtocol (&gEfiSmbiosProtocolGuid, NULL, (VOID **)&mSmbios);
666 ASSERT_EFI_ERROR (Status);
667 DEBUG ((DEBUG_INFO, "The Smbios Table Version: %x.%x\n", mSmbios->MajorVersion, mSmbios->MinorVersion));
668
669 if ((mSmbios->MajorVersion < 2) || ((mSmbios->MajorVersion == 2) && (mSmbios->MinorVersion < 7))) {
670 mMaxLen = SMBIOS_STRING_MAX_LENGTH;
671 } else if (mSmbios->MajorVersion < 3) {
672 //
673 // Reference SMBIOS 2.7, chapter 6.1.3, it will have no limit on the length of each individual text string.
674 // However, the length of the entire structure table (including all strings) must be reported
675 // in the Structure Table Length field of the SMBIOS Structure Table Entry Point,
676 // which is a WORD field limited to 65,535 bytes.
677 //
678 mMaxLen = SMBIOS_TABLE_MAX_LENGTH;
679 } else {
680 //
681 // SMBIOS 3.0 defines the Structure table maximum size as DWORD field limited to 0xFFFFFFFF bytes.
682 // Locate the end of string as long as possible.
683 //
684 mMaxLen = SMBIOS_3_0_TABLE_MAX_LENGTH;
685 }
686
687 //
688 // Measure Smbios tables
689 //
691 TPL_CALLBACK,
693 NULL,
694 &Event
695 );
696
697 return Status;
698}
UINT64 UINTN
UINTN EFIAPI StrLen(IN CONST CHAR16 *String)
Definition: String.c:30
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
Definition: SetMemWrapper.c:38
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
Definition: MemLibGuid.c:39
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
VOID *EFIAPI AllocateCopyPool(IN UINTN AllocationSize, IN CONST VOID *Buffer)
UINT8 SMBIOS_TABLE_STRING
Definition: SmBios.h:208
#define SMBIOS_STRING_MAX_LENGTH
Definition: SmBios.h:37
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define OFFSET_OF(TYPE, Field)
Definition: Base.h:758
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define DEBUG_CODE(Expression)
Definition: DebugLib.h:590
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
VOID InternalDumpData(IN UINT8 *Data, IN UINTN Size)
UINTN GetSmbiosTableLength(IN VOID *TableAddress, IN UINTN TableMaximumSize)
VOID EFIAPI MeasureSmbiosTable(IN EFI_EVENT Event, IN VOID *Context)
UINTN GetSmbiosStructureSize(IN EFI_SMBIOS_TABLE_HEADER *Head, OUT UINTN *NumberOfStrings)
EFI_STATUS EFIAPI SmbiosMeasurementDriverEntryPoint(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
VOID InternalDumpHex(IN UINT8 *Data, IN UINTN Size)
CHAR8 * GetSmbiosStringById(IN EFI_SMBIOS_TABLE_HEADER *Head, IN SMBIOS_TABLE_STRING StringId, OUT UINTN *StringLen)
VOID FilterSmbiosEntry(IN OUT VOID *TableEntry, IN UINTN TableEntrySize)
VOID FilterSmbiosTable(IN OUT VOID *TableAddress, IN UINTN TableLength)
SMBIOS_FILTER_STRUCT * GetFilterStructByType(IN UINT8 Type)
EFI_STATUS EFIAPI TpmMeasureAndLogData(IN UINT32 PcrIndex, IN UINT32 EventType, IN VOID *EventLog, IN UINT32 LogLen, IN VOID *HashData, IN UINT64 HashDataLen)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_EVENT
Definition: UefiBaseType.h:37
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI EfiGetSystemConfigurationTable(IN EFI_GUID *TableGuid, OUT VOID **Table)
Definition: UefiLib.c:82
EFI_STATUS EFIAPI EfiCreateEventReadyToBootEx(IN EFI_TPL NotifyTpl, IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL, IN VOID *NotifyContext OPTIONAL, OUT EFI_EVENT *ReadyToBootEvent)
Definition: UefiNotTiano.c:164
UINT8 MajorVersion
The major revision of the SMBIOS specification supported.
Definition: Smbios.h:205
UINT8 MinorVersion
The minor revision of the SMBIOS specification supported.
Definition: Smbios.h:206