2 This module implements Tcg2 Protocol.
4 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
5 (C) Copyright 2016 Hewlett Packard Enterprise Development LP<BR>
6 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include <IndustryStandard/Acpi.h>
18 #include <IndustryStandard/PeImage.h>
19 #include <IndustryStandard/TcpaAcpi.h>
21 #include <Guid/GlobalVariable.h>
22 #include <Guid/HobList.h>
23 #include <Guid/TcgEventHob.h>
24 #include <Guid/EventGroup.h>
25 #include <Guid/EventExitBootServiceFailed.h>
26 #include <Guid/ImageAuthentication.h>
27 #include <Guid/TpmInstance.h>
29 #include <Protocol/DevicePath.h>
30 #include <Protocol/MpService.h>
31 #include <Protocol/VariableWrite.h>
32 #include <Protocol/Tcg2Protocol.h>
33 #include <Protocol/TrEEProtocol.h>
35 #include <Library/DebugLib.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/UefiRuntimeServicesTableLib.h>
38 #include <Library/UefiDriverEntryPoint.h>
39 #include <Library/HobLib.h>
40 #include <Library/UefiBootServicesTableLib.h>
41 #include <Library/BaseLib.h>
42 #include <Library/MemoryAllocationLib.h>
43 #include <Library/PrintLib.h>
44 #include <Library/Tpm2CommandLib.h>
45 #include <Library/PcdLib.h>
46 #include <Library/UefiLib.h>
47 #include <Library/Tpm2DeviceLib.h>
48 #include <Library/HashLib.h>
49 #include <Library/PerformanceLib.h>
50 #include <Library/ReportStatusCodeLib.h>
51 #include <Library/Tcg2PhysicalPresenceLib.h>
53 #define PERF_ID_TCG2_DXE 0x3120
60 #define TCG2_DEFAULT_MAX_COMMAND_SIZE 0x1000
61 #define TCG2_DEFAULT_MAX_RESPONSE_SIZE 0x1000
65 EFI_TCG2_EVENT_LOG_FORMAT LogFormat
;
66 } TCG2_EVENT_INFO_STRUCT
;
68 TCG2_EVENT_INFO_STRUCT mTcg2EventInfo
[] = {
69 {&gTcgEventEntryHobGuid
, EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
},
70 {&gTcgEvent2EntryHobGuid
, EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
},
73 #define TCG_EVENT_LOG_AREA_COUNT_MAX 2
76 EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
;
77 EFI_PHYSICAL_ADDRESS Lasa
;
81 BOOLEAN EventLogStarted
;
82 BOOLEAN EventLogTruncated
;
83 } TCG_EVENT_LOG_AREA_STRUCT
;
85 typedef struct _TCG_DXE_DATA
{
86 EFI_TCG2_BOOT_SERVICE_CAPABILITY BsCap
;
87 TCG_EVENT_LOG_AREA_STRUCT EventLogAreaStruct
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
88 BOOLEAN GetEventLogCalled
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
89 TCG_EVENT_LOG_AREA_STRUCT FinalEventLogAreaStruct
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
90 EFI_TCG2_FINAL_EVENTS_TABLE
*FinalEventsTable
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
93 TCG_DXE_DATA mTcgDxeData
= {
95 sizeof (EFI_TCG2_BOOT_SERVICE_CAPABILITY
), // Size
96 { 1, 1 }, // StructureVersion
97 { 1, 1 }, // ProtocolVersion
98 EFI_TCG2_BOOT_HASH_ALG_SHA1
, // HashAlgorithmBitmap
99 EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
, // SupportedEventLogs
100 TRUE
, // TPMPresentFlag
101 TCG2_DEFAULT_MAX_COMMAND_SIZE
, // MaxCommandSize
102 TCG2_DEFAULT_MAX_RESPONSE_SIZE
, // MaxResponseSize
104 0, // NumberOfPCRBanks
109 UINTN mBootAttempts
= 0;
110 CHAR16 mBootVarName
[] = L
"BootOrder";
112 VARIABLE_TYPE mVariableType
[] = {
113 {EFI_SECURE_BOOT_MODE_NAME
, &gEfiGlobalVariableGuid
},
114 {EFI_PLATFORM_KEY_NAME
, &gEfiGlobalVariableGuid
},
115 {EFI_KEY_EXCHANGE_KEY_NAME
, &gEfiGlobalVariableGuid
},
116 {EFI_IMAGE_SECURITY_DATABASE
, &gEfiImageSecurityDatabaseGuid
},
117 {EFI_IMAGE_SECURITY_DATABASE1
, &gEfiImageSecurityDatabaseGuid
},
120 EFI_HANDLE mImageHandle
;
123 Measure PE image into TPM log based on the authenticode image hashing in
124 PE/COFF Specification 8.0 Appendix A.
126 Caution: This function may receive untrusted input.
127 PE/COFF image is external input, so this function will validate its data structure
128 within this image buffer before use.
130 @param[in] PCRIndex TPM PCR index
131 @param[in] ImageAddress Start address of image buffer.
132 @param[in] ImageSize Image size
133 @param[out] DigestList Digeest list of this image.
135 @retval EFI_SUCCESS Successfully measure image.
136 @retval EFI_OUT_OF_RESOURCES No enough resource to measure image.
137 @retval other error value
140 MeasurePeImageAndExtend (
142 IN EFI_PHYSICAL_ADDRESS ImageAddress
,
144 OUT TPML_DIGEST_VALUES
*DigestList
149 This function dump raw data.
152 @param Size raw data size
162 for (Index
= 0; Index
< Size
; Index
++) {
163 DEBUG ((EFI_D_INFO
, "%02x", (UINTN
)Data
[Index
]));
169 This function dump raw data with colume format.
172 @param Size raw data size
185 #define COLUME_SIZE (16 * 2)
187 Count
= Size
/ COLUME_SIZE
;
188 Left
= Size
% COLUME_SIZE
;
189 for (Index
= 0; Index
< Count
; Index
++) {
190 DEBUG ((EFI_D_INFO
, "%04x: ", Index
* COLUME_SIZE
));
191 InternalDumpData (Data
+ Index
* COLUME_SIZE
, COLUME_SIZE
);
192 DEBUG ((EFI_D_INFO
, "\n"));
196 DEBUG ((EFI_D_INFO
, "%04x: ", Index
* COLUME_SIZE
));
197 InternalDumpData (Data
+ Index
* COLUME_SIZE
, Left
);
198 DEBUG ((EFI_D_INFO
, "\n"));
203 Check if buffer is all zero.
205 @param[in] Buffer Buffer to be checked.
206 @param[in] BufferSize Size of buffer to be checked.
208 @retval TRUE Buffer is all zero.
209 @retval FALSE Buffer is not all zero.
221 for (Index
= 0; Index
< BufferSize
; Index
++) {
222 if (BufferData
[Index
] != 0) {
230 Get All processors EFI_CPU_LOCATION in system. LocationBuf is allocated inside the function
231 Caller is responsible to free LocationBuf.
233 @param[out] LocationBuf Returns Processor Location Buffer.
234 @param[out] Num Returns processor number.
236 @retval EFI_SUCCESS Operation completed successfully.
237 @retval EFI_UNSUPPORTED MpService protocol not found.
241 GetProcessorsCpuLocation (
242 OUT EFI_CPU_PHYSICAL_LOCATION
**LocationBuf
,
247 EFI_MP_SERVICES_PROTOCOL
*MpProtocol
;
249 UINTN EnabledProcessorNum
;
250 EFI_PROCESSOR_INFORMATION ProcessorInfo
;
251 EFI_CPU_PHYSICAL_LOCATION
*ProcessorLocBuf
;
254 Status
= gBS
->LocateProtocol (&gEfiMpServiceProtocolGuid
, NULL
, (VOID
**) &MpProtocol
);
255 if (EFI_ERROR (Status
)) {
257 // MP protocol is not installed
259 return EFI_UNSUPPORTED
;
262 Status
= MpProtocol
->GetNumberOfProcessors(
267 if (EFI_ERROR(Status
)){
271 Status
= gBS
->AllocatePool(
273 sizeof(EFI_CPU_PHYSICAL_LOCATION
) * ProcessorNum
,
274 (VOID
**) &ProcessorLocBuf
276 if (EFI_ERROR(Status
)){
281 // Get each processor Location info
283 for (Index
= 0; Index
< ProcessorNum
; Index
++) {
284 Status
= MpProtocol
->GetProcessorInfo(
289 if (EFI_ERROR(Status
)){
290 FreePool(ProcessorLocBuf
);
295 // Get all Processor Location info & measure
298 &ProcessorLocBuf
[Index
],
299 &ProcessorInfo
.Location
,
300 sizeof(EFI_CPU_PHYSICAL_LOCATION
)
304 *LocationBuf
= ProcessorLocBuf
;
311 The EFI_TCG2_PROTOCOL GetCapability function call provides protocol
312 capability information and state information.
314 @param[in] This Indicates the calling context
315 @param[in, out] ProtocolCapability The caller allocates memory for a EFI_TCG2_BOOT_SERVICE_CAPABILITY
316 structure and sets the size field to the size of the structure allocated.
317 The callee fills in the fields with the EFI protocol capability information
318 and the current EFI TCG2 state information up to the number of fields which
319 fit within the size of the structure passed in.
321 @retval EFI_SUCCESS Operation completed successfully.
322 @retval EFI_DEVICE_ERROR The command was unsuccessful.
323 The ProtocolCapability variable will not be populated.
324 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
325 The ProtocolCapability variable will not be populated.
326 @retval EFI_BUFFER_TOO_SMALL The ProtocolCapability variable is too small to hold the full response.
327 It will be partially populated (required Size field will be set).
332 IN EFI_TCG2_PROTOCOL
*This
,
333 IN OUT EFI_TCG2_BOOT_SERVICE_CAPABILITY
*ProtocolCapability
336 DEBUG ((DEBUG_VERBOSE
, "Tcg2GetCapability ...\n"));
338 if ((This
== NULL
) || (ProtocolCapability
== NULL
)) {
339 return EFI_INVALID_PARAMETER
;
342 DEBUG ((DEBUG_VERBOSE
, "Size - 0x%x\n", ProtocolCapability
->Size
));
343 DEBUG ((DEBUG_VERBOSE
, " 1.1 - 0x%x, 1.0 - 0x%x\n", sizeof(EFI_TCG2_BOOT_SERVICE_CAPABILITY
), sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
)));
345 if (ProtocolCapability
->Size
< mTcgDxeData
.BsCap
.Size
) {
347 // Handle the case that firmware support 1.1 but OS only support 1.0.
349 if ((mTcgDxeData
.BsCap
.ProtocolVersion
.Major
> 0x01) ||
350 ((mTcgDxeData
.BsCap
.ProtocolVersion
.Major
== 0x01) && ((mTcgDxeData
.BsCap
.ProtocolVersion
.Minor
> 0x00)))) {
351 if (ProtocolCapability
->Size
>= sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
)) {
352 CopyMem (ProtocolCapability
, &mTcgDxeData
.BsCap
, sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
));
353 ProtocolCapability
->Size
= sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
);
354 ProtocolCapability
->StructureVersion
.Major
= 1;
355 ProtocolCapability
->StructureVersion
.Minor
= 0;
356 ProtocolCapability
->ProtocolVersion
.Major
= 1;
357 ProtocolCapability
->ProtocolVersion
.Minor
= 0;
358 DEBUG ((EFI_D_ERROR
, "TreeGetCapability (Compatible) - %r\n", EFI_SUCCESS
));
362 ProtocolCapability
->Size
= mTcgDxeData
.BsCap
.Size
;
363 return EFI_BUFFER_TOO_SMALL
;
366 CopyMem (ProtocolCapability
, &mTcgDxeData
.BsCap
, mTcgDxeData
.BsCap
.Size
);
367 DEBUG ((DEBUG_VERBOSE
, "Tcg2GetCapability - %r\n", EFI_SUCCESS
));
372 This function dump PCR event.
374 @param[in] EventHdr TCG PCR event structure.
378 IN TCG_PCR_EVENT_HDR
*EventHdr
383 DEBUG ((EFI_D_INFO
, " Event:\n"));
384 DEBUG ((EFI_D_INFO
, " PCRIndex - %d\n", EventHdr
->PCRIndex
));
385 DEBUG ((EFI_D_INFO
, " EventType - 0x%08x\n", EventHdr
->EventType
));
386 DEBUG ((EFI_D_INFO
, " Digest - "));
387 for (Index
= 0; Index
< sizeof(TCG_DIGEST
); Index
++) {
388 DEBUG ((EFI_D_INFO
, "%02x ", EventHdr
->Digest
.digest
[Index
]));
390 DEBUG ((EFI_D_INFO
, "\n"));
391 DEBUG ((EFI_D_INFO
, " EventSize - 0x%08x\n", EventHdr
->EventSize
));
392 InternalDumpHex ((UINT8
*)(EventHdr
+ 1), EventHdr
->EventSize
);
396 This function dump TCG_EfiSpecIDEventStruct.
398 @param[in] TcgEfiSpecIdEventStruct A pointer to TCG_EfiSpecIDEventStruct.
401 DumpTcgEfiSpecIdEventStruct (
402 IN TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
405 TCG_EfiSpecIdEventAlgorithmSize
*DigestSize
;
407 UINT8
*VendorInfoSize
;
409 UINT32 NumberOfAlgorithms
;
411 DEBUG ((EFI_D_INFO
, " TCG_EfiSpecIDEventStruct:\n"));
412 DEBUG ((EFI_D_INFO
, " signature - '"));
413 for (Index
= 0; Index
< sizeof(TcgEfiSpecIdEventStruct
->signature
); Index
++) {
414 DEBUG ((EFI_D_INFO
, "%c", TcgEfiSpecIdEventStruct
->signature
[Index
]));
416 DEBUG ((EFI_D_INFO
, "'\n"));
417 DEBUG ((EFI_D_INFO
, " platformClass - 0x%08x\n", TcgEfiSpecIdEventStruct
->platformClass
));
418 DEBUG ((EFI_D_INFO
, " specVersion - %d.%d%d\n", TcgEfiSpecIdEventStruct
->specVersionMajor
, TcgEfiSpecIdEventStruct
->specVersionMinor
, TcgEfiSpecIdEventStruct
->specErrata
));
419 DEBUG ((EFI_D_INFO
, " uintnSize - 0x%02x\n", TcgEfiSpecIdEventStruct
->uintnSize
));
421 CopyMem (&NumberOfAlgorithms
, TcgEfiSpecIdEventStruct
+ 1, sizeof(NumberOfAlgorithms
));
422 DEBUG ((EFI_D_INFO
, " NumberOfAlgorithms - 0x%08x\n", NumberOfAlgorithms
));
424 DigestSize
= (TCG_EfiSpecIdEventAlgorithmSize
*)((UINT8
*)TcgEfiSpecIdEventStruct
+ sizeof(*TcgEfiSpecIdEventStruct
) + sizeof(NumberOfAlgorithms
));
425 for (Index
= 0; Index
< NumberOfAlgorithms
; Index
++) {
426 DEBUG ((EFI_D_INFO
, " digest(%d)\n", Index
));
427 DEBUG ((EFI_D_INFO
, " algorithmId - 0x%04x\n", DigestSize
[Index
].algorithmId
));
428 DEBUG ((EFI_D_INFO
, " digestSize - 0x%04x\n", DigestSize
[Index
].digestSize
));
430 VendorInfoSize
= (UINT8
*)&DigestSize
[NumberOfAlgorithms
];
431 DEBUG ((EFI_D_INFO
, " VendorInfoSize - 0x%02x\n", *VendorInfoSize
));
432 VendorInfo
= VendorInfoSize
+ 1;
433 DEBUG ((EFI_D_INFO
, " VendorInfo - "));
434 for (Index
= 0; Index
< *VendorInfoSize
; Index
++) {
435 DEBUG ((EFI_D_INFO
, "%02x ", VendorInfo
[Index
]));
437 DEBUG ((EFI_D_INFO
, "\n"));
441 This function get size of TCG_EfiSpecIDEventStruct.
443 @param[in] TcgEfiSpecIdEventStruct A pointer to TCG_EfiSpecIDEventStruct.
446 GetTcgEfiSpecIdEventStructSize (
447 IN TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
450 TCG_EfiSpecIdEventAlgorithmSize
*DigestSize
;
451 UINT8
*VendorInfoSize
;
452 UINT32 NumberOfAlgorithms
;
454 CopyMem (&NumberOfAlgorithms
, TcgEfiSpecIdEventStruct
+ 1, sizeof(NumberOfAlgorithms
));
456 DigestSize
= (TCG_EfiSpecIdEventAlgorithmSize
*)((UINT8
*)TcgEfiSpecIdEventStruct
+ sizeof(*TcgEfiSpecIdEventStruct
) + sizeof(NumberOfAlgorithms
));
457 VendorInfoSize
= (UINT8
*)&DigestSize
[NumberOfAlgorithms
];
458 return sizeof(TCG_EfiSpecIDEventStruct
) + sizeof(UINT32
) + (NumberOfAlgorithms
* sizeof(TCG_EfiSpecIdEventAlgorithmSize
)) + sizeof(UINT8
) + (*VendorInfoSize
);
462 This function dump PCR event 2.
464 @param[in] TcgPcrEvent2 TCG PCR event 2 structure.
468 IN TCG_PCR_EVENT2
*TcgPcrEvent2
474 TPMI_ALG_HASH HashAlgo
;
480 DEBUG ((EFI_D_INFO
, " Event:\n"));
481 DEBUG ((EFI_D_INFO
, " PCRIndex - %d\n", TcgPcrEvent2
->PCRIndex
));
482 DEBUG ((EFI_D_INFO
, " EventType - 0x%08x\n", TcgPcrEvent2
->EventType
));
484 DEBUG ((EFI_D_INFO
, " DigestCount: 0x%08x\n", TcgPcrEvent2
->Digest
.count
));
486 DigestCount
= TcgPcrEvent2
->Digest
.count
;
487 HashAlgo
= TcgPcrEvent2
->Digest
.digests
[0].hashAlg
;
488 DigestBuffer
= (UINT8
*)&TcgPcrEvent2
->Digest
.digests
[0].digest
;
489 for (DigestIndex
= 0; DigestIndex
< DigestCount
; DigestIndex
++) {
490 DEBUG ((EFI_D_INFO
, " HashAlgo : 0x%04x\n", HashAlgo
));
491 DEBUG ((EFI_D_INFO
, " Digest(%d): ", DigestIndex
));
492 DigestSize
= GetHashSizeFromAlgo (HashAlgo
);
493 for (Index
= 0; Index
< DigestSize
; Index
++) {
494 DEBUG ((EFI_D_INFO
, "%02x ", DigestBuffer
[Index
]));
496 DEBUG ((EFI_D_INFO
, "\n"));
500 CopyMem (&HashAlgo
, DigestBuffer
+ DigestSize
, sizeof(TPMI_ALG_HASH
));
501 DigestBuffer
= DigestBuffer
+ DigestSize
+ sizeof(TPMI_ALG_HASH
);
503 DEBUG ((EFI_D_INFO
, "\n"));
504 DigestBuffer
= DigestBuffer
- sizeof(TPMI_ALG_HASH
);
506 CopyMem (&EventSize
, DigestBuffer
, sizeof(TcgPcrEvent2
->EventSize
));
507 DEBUG ((EFI_D_INFO
, " EventSize - 0x%08x\n", EventSize
));
508 EventBuffer
= DigestBuffer
+ sizeof(TcgPcrEvent2
->EventSize
);
509 InternalDumpHex (EventBuffer
, EventSize
);
513 This function returns size of TCG PCR event 2.
515 @param[in] TcgPcrEvent2 TCG PCR event 2 structure.
517 @return size of TCG PCR event 2.
521 IN TCG_PCR_EVENT2
*TcgPcrEvent2
526 TPMI_ALG_HASH HashAlgo
;
532 DigestCount
= TcgPcrEvent2
->Digest
.count
;
533 HashAlgo
= TcgPcrEvent2
->Digest
.digests
[0].hashAlg
;
534 DigestBuffer
= (UINT8
*)&TcgPcrEvent2
->Digest
.digests
[0].digest
;
535 for (DigestIndex
= 0; DigestIndex
< DigestCount
; DigestIndex
++) {
536 DigestSize
= GetHashSizeFromAlgo (HashAlgo
);
540 CopyMem (&HashAlgo
, DigestBuffer
+ DigestSize
, sizeof(TPMI_ALG_HASH
));
541 DigestBuffer
= DigestBuffer
+ DigestSize
+ sizeof(TPMI_ALG_HASH
);
543 DigestBuffer
= DigestBuffer
- sizeof(TPMI_ALG_HASH
);
545 CopyMem (&EventSize
, DigestBuffer
, sizeof(TcgPcrEvent2
->EventSize
));
546 EventBuffer
= DigestBuffer
+ sizeof(TcgPcrEvent2
->EventSize
);
548 return (UINTN
)EventBuffer
+ EventSize
- (UINTN
)TcgPcrEvent2
;
552 This function dump event log.
554 @param[in] EventLogFormat The type of the event log for which the information is requested.
555 @param[in] EventLogLocation A pointer to the memory address of the event log.
556 @param[in] EventLogLastEntry If the Event Log contains more than one entry, this is a pointer to the
557 address of the start of the last entry in the event log in memory.
558 @param[in] FinalEventsTable A pointer to the memory address of the final event table.
562 IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
,
563 IN EFI_PHYSICAL_ADDRESS EventLogLocation
,
564 IN EFI_PHYSICAL_ADDRESS EventLogLastEntry
,
565 IN EFI_TCG2_FINAL_EVENTS_TABLE
*FinalEventsTable
568 TCG_PCR_EVENT_HDR
*EventHdr
;
569 TCG_PCR_EVENT2
*TcgPcrEvent2
;
570 TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
;
571 UINTN NumberOfEvents
;
573 DEBUG ((EFI_D_INFO
, "EventLogFormat: (0x%x)\n", EventLogFormat
));
575 switch (EventLogFormat
) {
576 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
:
577 EventHdr
= (TCG_PCR_EVENT_HDR
*)(UINTN
)EventLogLocation
;
578 while ((UINTN
)EventHdr
<= EventLogLastEntry
) {
579 DumpEvent (EventHdr
);
580 EventHdr
= (TCG_PCR_EVENT_HDR
*)((UINTN
)EventHdr
+ sizeof(TCG_PCR_EVENT_HDR
) + EventHdr
->EventSize
);
582 if (FinalEventsTable
== NULL
) {
583 DEBUG ((EFI_D_INFO
, "FinalEventsTable: NOT FOUND\n"));
585 DEBUG ((EFI_D_INFO
, "FinalEventsTable: (0x%x)\n", FinalEventsTable
));
586 DEBUG ((EFI_D_INFO
, " Version: (0x%x)\n", FinalEventsTable
->Version
));
587 DEBUG ((EFI_D_INFO
, " NumberOfEvents: (0x%x)\n", FinalEventsTable
->NumberOfEvents
));
589 EventHdr
= (TCG_PCR_EVENT_HDR
*)(UINTN
)(FinalEventsTable
+ 1);
590 for (NumberOfEvents
= 0; NumberOfEvents
< FinalEventsTable
->NumberOfEvents
; NumberOfEvents
++) {
591 DumpEvent (EventHdr
);
592 EventHdr
= (TCG_PCR_EVENT_HDR
*)((UINTN
)EventHdr
+ sizeof(TCG_PCR_EVENT_HDR
) + EventHdr
->EventSize
);
596 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
:
600 EventHdr
= (TCG_PCR_EVENT_HDR
*)(UINTN
)EventLogLocation
;
601 DumpEvent (EventHdr
);
603 TcgEfiSpecIdEventStruct
= (TCG_EfiSpecIDEventStruct
*)(EventHdr
+ 1);
604 DumpTcgEfiSpecIdEventStruct (TcgEfiSpecIdEventStruct
);
606 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)((UINTN
)TcgEfiSpecIdEventStruct
+ GetTcgEfiSpecIdEventStructSize (TcgEfiSpecIdEventStruct
));
607 while ((UINTN
)TcgPcrEvent2
<= EventLogLastEntry
) {
608 DumpEvent2 (TcgPcrEvent2
);
609 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)((UINTN
)TcgPcrEvent2
+ GetPcrEvent2Size (TcgPcrEvent2
));
612 if (FinalEventsTable
== NULL
) {
613 DEBUG ((EFI_D_INFO
, "FinalEventsTable: NOT FOUND\n"));
615 DEBUG ((EFI_D_INFO
, "FinalEventsTable: (0x%x)\n", FinalEventsTable
));
616 DEBUG ((EFI_D_INFO
, " Version: (0x%x)\n", FinalEventsTable
->Version
));
617 DEBUG ((EFI_D_INFO
, " NumberOfEvents: (0x%x)\n", FinalEventsTable
->NumberOfEvents
));
619 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)(UINTN
)(FinalEventsTable
+ 1);
620 for (NumberOfEvents
= 0; NumberOfEvents
< FinalEventsTable
->NumberOfEvents
; NumberOfEvents
++) {
621 DumpEvent2 (TcgPcrEvent2
);
622 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)((UINTN
)TcgPcrEvent2
+ GetPcrEvent2Size (TcgPcrEvent2
));
632 The EFI_TCG2_PROTOCOL Get Event Log function call allows a caller to
633 retrieve the address of a given event log and its last entry.
635 @param[in] This Indicates the calling context
636 @param[in] EventLogFormat The type of the event log for which the information is requested.
637 @param[out] EventLogLocation A pointer to the memory address of the event log.
638 @param[out] EventLogLastEntry If the Event Log contains more than one entry, this is a pointer to the
639 address of the start of the last entry in the event log in memory.
640 @param[out] EventLogTruncated If the Event Log is missing at least one entry because an event would
641 have exceeded the area allocated for events, this value is set to TRUE.
642 Otherwise, the value will be FALSE and the Event Log will be complete.
644 @retval EFI_SUCCESS Operation completed successfully.
645 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect
646 (e.g. asking for an event log whose format is not supported).
651 IN EFI_TCG2_PROTOCOL
*This
,
652 IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
,
653 OUT EFI_PHYSICAL_ADDRESS
*EventLogLocation
,
654 OUT EFI_PHYSICAL_ADDRESS
*EventLogLastEntry
,
655 OUT BOOLEAN
*EventLogTruncated
660 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog ... (0x%x)\n", EventLogFormat
));
663 return EFI_INVALID_PARAMETER
;
666 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
667 if (EventLogFormat
== mTcg2EventInfo
[Index
].LogFormat
) {
672 if (Index
== sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0])) {
673 return EFI_INVALID_PARAMETER
;
676 if ((mTcg2EventInfo
[Index
].LogFormat
& mTcgDxeData
.BsCap
.SupportedEventLogs
) == 0) {
677 return EFI_INVALID_PARAMETER
;
680 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
681 if (EventLogLocation
!= NULL
) {
682 *EventLogLocation
= 0;
684 if (EventLogLastEntry
!= NULL
) {
685 *EventLogLastEntry
= 0;
687 if (EventLogTruncated
!= NULL
) {
688 *EventLogTruncated
= FALSE
;
693 if (EventLogLocation
!= NULL
) {
694 *EventLogLocation
= mTcgDxeData
.EventLogAreaStruct
[Index
].Lasa
;
695 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog (EventLogLocation - %x)\n", *EventLogLocation
));
698 if (EventLogLastEntry
!= NULL
) {
699 if (!mTcgDxeData
.EventLogAreaStruct
[Index
].EventLogStarted
) {
700 *EventLogLastEntry
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)0;
702 *EventLogLastEntry
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)mTcgDxeData
.EventLogAreaStruct
[Index
].LastEvent
;
704 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog (EventLogLastEntry - %x)\n", *EventLogLastEntry
));
707 if (EventLogTruncated
!= NULL
) {
708 *EventLogTruncated
= mTcgDxeData
.EventLogAreaStruct
[Index
].EventLogTruncated
;
709 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog (EventLogTruncated - %x)\n", *EventLogTruncated
));
712 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog - %r\n", EFI_SUCCESS
));
714 // Dump Event Log for debug purpose
715 if ((EventLogLocation
!= NULL
) && (EventLogLastEntry
!= NULL
)) {
716 DumpEventLog (EventLogFormat
, *EventLogLocation
, *EventLogLastEntry
, mTcgDxeData
.FinalEventsTable
[Index
]);
720 // All events generated after the invocation of EFI_TCG2_GET_EVENT_LOG SHALL be stored
721 // in an instance of an EFI_CONFIGURATION_TABLE named by the VendorGuid of EFI_TCG2_FINAL_EVENTS_TABLE_GUID.
723 mTcgDxeData
.GetEventLogCalled
[Index
] = TRUE
;
729 Add a new entry to the Event Log.
731 @param[in, out] EventLogPtr Pointer to the Event Log data.
732 @param[in, out] LogSize Size of the Event Log.
733 @param[in] MaxSize Maximum size of the Event Log.
734 @param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR/TCG_PCR_EVENT_EX data structure.
735 @param[in] NewEventHdrSize New event header size.
736 @param[in] NewEventData Pointer to the new event data.
737 @param[in] NewEventSize New event data size.
739 @retval EFI_SUCCESS The new event log entry was added.
740 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
745 IN OUT UINT8
**EventLogPtr
,
746 IN OUT UINTN
*LogSize
,
748 IN VOID
*NewEventHdr
,
749 IN UINT32 NewEventHdrSize
,
750 IN UINT8
*NewEventData
,
751 IN UINT32 NewEventSize
756 if (NewEventSize
> MAX_ADDRESS
- NewEventHdrSize
) {
757 return EFI_OUT_OF_RESOURCES
;
760 NewLogSize
= NewEventHdrSize
+ NewEventSize
;
762 if (NewLogSize
> MAX_ADDRESS
- *LogSize
) {
763 return EFI_OUT_OF_RESOURCES
;
766 if (NewLogSize
+ *LogSize
> MaxSize
) {
767 DEBUG ((EFI_D_INFO
, " MaxSize - 0x%x\n", MaxSize
));
768 DEBUG ((EFI_D_INFO
, " NewLogSize - 0x%x\n", NewLogSize
));
769 DEBUG ((EFI_D_INFO
, " LogSize - 0x%x\n", *LogSize
));
770 DEBUG ((EFI_D_INFO
, "TcgCommLogEvent - %r\n", EFI_OUT_OF_RESOURCES
));
771 return EFI_OUT_OF_RESOURCES
;
774 *EventLogPtr
+= *LogSize
;
775 *LogSize
+= NewLogSize
;
776 CopyMem (*EventLogPtr
, NewEventHdr
, NewEventHdrSize
);
778 *EventLogPtr
+ NewEventHdrSize
,
786 Add a new entry to the Event Log.
788 @param[in] EventLogFormat The type of the event log for which the information is requested.
789 @param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR/TCG_PCR_EVENT_EX data structure.
790 @param[in] NewEventHdrSize New event header size.
791 @param[in] NewEventData Pointer to the new event data.
792 @param[in] NewEventSize New event data size.
794 @retval EFI_SUCCESS The new event log entry was added.
795 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
800 IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
,
801 IN VOID
*NewEventHdr
,
802 IN UINT32 NewEventHdrSize
,
803 IN UINT8
*NewEventData
,
804 IN UINT32 NewEventSize
809 TCG_EVENT_LOG_AREA_STRUCT
*EventLogAreaStruct
;
811 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
812 if (EventLogFormat
== mTcg2EventInfo
[Index
].LogFormat
) {
817 if (Index
== sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0])) {
818 return EFI_INVALID_PARAMETER
;
822 // Record to normal event log
824 EventLogAreaStruct
= &mTcgDxeData
.EventLogAreaStruct
[Index
];
826 if (EventLogAreaStruct
->EventLogTruncated
) {
827 return EFI_VOLUME_FULL
;
830 EventLogAreaStruct
->LastEvent
= (UINT8
*)(UINTN
)EventLogAreaStruct
->Lasa
;
831 Status
= TcgCommLogEvent (
832 &EventLogAreaStruct
->LastEvent
,
833 &EventLogAreaStruct
->EventLogSize
,
834 (UINTN
)EventLogAreaStruct
->Laml
,
841 if (Status
== EFI_OUT_OF_RESOURCES
) {
842 EventLogAreaStruct
->EventLogTruncated
= TRUE
;
843 return EFI_VOLUME_FULL
;
844 } else if (Status
== EFI_SUCCESS
) {
845 EventLogAreaStruct
->EventLogStarted
= TRUE
;
849 // If GetEventLog is called, record to FinalEventsTable, too.
851 if (mTcgDxeData
.GetEventLogCalled
[Index
]) {
852 if (mTcgDxeData
.FinalEventsTable
[Index
] == NULL
) {
854 // no need for FinalEventsTable
858 EventLogAreaStruct
= &mTcgDxeData
.FinalEventLogAreaStruct
[Index
];
860 if (EventLogAreaStruct
->EventLogTruncated
) {
861 return EFI_VOLUME_FULL
;
864 EventLogAreaStruct
->LastEvent
= (UINT8
*)(UINTN
)EventLogAreaStruct
->Lasa
;
865 Status
= TcgCommLogEvent (
866 &EventLogAreaStruct
->LastEvent
,
867 &EventLogAreaStruct
->EventLogSize
,
868 (UINTN
)EventLogAreaStruct
->Laml
,
874 if (Status
== EFI_OUT_OF_RESOURCES
) {
875 EventLogAreaStruct
->EventLogTruncated
= TRUE
;
876 return EFI_VOLUME_FULL
;
877 } else if (Status
== EFI_SUCCESS
) {
878 EventLogAreaStruct
->EventLogStarted
= TRUE
;
880 // Increase the NumberOfEvents in FinalEventsTable
882 (mTcgDxeData
.FinalEventsTable
[Index
])->NumberOfEvents
++;
883 DEBUG ((EFI_D_INFO
, "FinalEventsTable->NumberOfEvents - 0x%x\n", (mTcgDxeData
.FinalEventsTable
[Index
])->NumberOfEvents
));
884 DEBUG ((EFI_D_INFO
, " Size - 0x%x\n", (UINTN
)EventLogAreaStruct
->LastEvent
- (UINTN
)mTcgDxeData
.FinalEventsTable
[Index
]));
892 This function get digest from digest list.
894 @param HashAlg digest algorithm
895 @param DigestList digest list
898 @retval EFI_SUCCESS Sha1Digest is found and returned.
899 @retval EFI_NOT_FOUND Sha1Digest is not found.
902 Tpm2GetDigestFromDigestList (
903 IN TPMI_ALG_HASH HashAlg
,
904 IN TPML_DIGEST_VALUES
*DigestList
,
911 DigestSize
= GetHashSizeFromAlgo (HashAlg
);
912 for (Index
= 0; Index
< DigestList
->count
; Index
++) {
913 if (DigestList
->digests
[Index
].hashAlg
== HashAlg
) {
916 &DigestList
->digests
[Index
].digest
,
923 return EFI_NOT_FOUND
;
927 Get TPML_DIGEST_VALUES data size.
929 @param[in] DigestList TPML_DIGEST_VALUES data.
931 @return TPML_DIGEST_VALUES data size.
935 IN TPML_DIGEST_VALUES
*DigestList
942 TotalSize
= sizeof(DigestList
->count
);
943 for (Index
= 0; Index
< DigestList
->count
; Index
++) {
944 DigestSize
= GetHashSizeFromAlgo (DigestList
->digests
[Index
].hashAlg
);
945 TotalSize
+= sizeof(DigestList
->digests
[Index
].hashAlg
) + DigestSize
;
952 Get TPML_DIGEST_VALUES compact binary buffer size.
954 @param[in] DigestListBin TPML_DIGEST_VALUES compact binary buffer.
956 @return TPML_DIGEST_VALUES compact binary buffer size.
959 GetDigestListBinSize (
960 IN VOID
*DigestListBin
967 TPMI_ALG_HASH HashAlg
;
969 Count
= ReadUnaligned32 (DigestListBin
);
970 TotalSize
= sizeof(Count
);
971 DigestListBin
= (UINT8
*)DigestListBin
+ sizeof(Count
);
972 for (Index
= 0; Index
< Count
; Index
++) {
973 HashAlg
= ReadUnaligned16 (DigestListBin
);
974 TotalSize
+= sizeof(HashAlg
);
975 DigestListBin
= (UINT8
*)DigestListBin
+ sizeof(HashAlg
);
977 DigestSize
= GetHashSizeFromAlgo (HashAlg
);
978 TotalSize
+= DigestSize
;
979 DigestListBin
= (UINT8
*)DigestListBin
+ DigestSize
;
986 Return if hash alg is supported in TPM PCR bank.
988 @param HashAlg Hash algorithm to be checked.
990 @retval TRUE Hash algorithm is supported.
991 @retval FALSE Hash algorithm is not supported.
994 IsHashAlgSupportedInPcrBank (
995 IN TPMI_ALG_HASH HashAlg
1000 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) != 0) {
1004 case TPM_ALG_SHA256
:
1005 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA256
) != 0) {
1009 case TPM_ALG_SHA384
:
1010 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA384
) != 0) {
1014 case TPM_ALG_SHA512
:
1015 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA512
) != 0) {
1019 case TPM_ALG_SM3_256
:
1020 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SM3_256
) != 0) {
1030 Copy TPML_DIGEST_VALUES into a buffer
1032 @param[in,out] Buffer Buffer to hold TPML_DIGEST_VALUES.
1033 @param[in] DigestList TPML_DIGEST_VALUES to be copied.
1035 @return The end of buffer to hold TPML_DIGEST_VALUES.
1038 CopyDigestListToBuffer (
1039 IN OUT VOID
*Buffer
,
1040 IN TPML_DIGEST_VALUES
*DigestList
1046 CopyMem (Buffer
, &DigestList
->count
, sizeof(DigestList
->count
));
1047 Buffer
= (UINT8
*)Buffer
+ sizeof(DigestList
->count
);
1048 for (Index
= 0; Index
< DigestList
->count
; Index
++) {
1049 if (!IsHashAlgSupportedInPcrBank (DigestList
->digests
[Index
].hashAlg
)) {
1050 DEBUG ((EFI_D_ERROR
, "WARNING: TPM2 Event log has HashAlg unsupported by PCR bank (0x%x)\n", DigestList
->digests
[Index
].hashAlg
));
1053 CopyMem (Buffer
, &DigestList
->digests
[Index
].hashAlg
, sizeof(DigestList
->digests
[Index
].hashAlg
));
1054 Buffer
= (UINT8
*)Buffer
+ sizeof(DigestList
->digests
[Index
].hashAlg
);
1055 DigestSize
= GetHashSizeFromAlgo (DigestList
->digests
[Index
].hashAlg
);
1056 CopyMem (Buffer
, &DigestList
->digests
[Index
].digest
, DigestSize
);
1057 Buffer
= (UINT8
*)Buffer
+ DigestSize
;
1064 Add a new entry to the Event Log.
1066 @param[in] DigestList A list of digest.
1067 @param[in,out] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
1068 @param[in] NewEventData Pointer to the new event data.
1070 @retval EFI_SUCCESS The new event log entry was added.
1071 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
1074 TcgDxeLogHashEvent (
1075 IN TPML_DIGEST_VALUES
*DigestList
,
1076 IN OUT TCG_PCR_EVENT_HDR
*NewEventHdr
,
1077 IN UINT8
*NewEventData
1083 EFI_STATUS RetStatus
;
1084 TCG_PCR_EVENT2 TcgPcrEvent2
;
1085 UINT8
*DigestBuffer
;
1087 DEBUG ((EFI_D_INFO
, "SupportedEventLogs - 0x%08x\n", mTcgDxeData
.BsCap
.SupportedEventLogs
));
1089 RetStatus
= EFI_SUCCESS
;
1090 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1091 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1092 DEBUG ((EFI_D_INFO
, " LogFormat - 0x%08x\n", mTcg2EventInfo
[Index
].LogFormat
));
1093 switch (mTcg2EventInfo
[Index
].LogFormat
) {
1094 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
:
1095 Status
= Tpm2GetDigestFromDigestList (TPM_ALG_SHA1
, DigestList
, &NewEventHdr
->Digest
);
1096 if (!EFI_ERROR (Status
)) {
1098 // Enter critical region
1100 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
1101 Status
= TcgDxeLogEvent (
1102 mTcg2EventInfo
[Index
].LogFormat
,
1104 sizeof(TCG_PCR_EVENT_HDR
),
1106 NewEventHdr
->EventSize
1108 if (Status
!= EFI_SUCCESS
) {
1111 gBS
->RestoreTPL (OldTpl
);
1113 // Exit critical region
1117 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
:
1118 ZeroMem (&TcgPcrEvent2
, sizeof(TcgPcrEvent2
));
1119 TcgPcrEvent2
.PCRIndex
= NewEventHdr
->PCRIndex
;
1120 TcgPcrEvent2
.EventType
= NewEventHdr
->EventType
;
1121 DigestBuffer
= (UINT8
*)&TcgPcrEvent2
.Digest
;
1122 DigestBuffer
= CopyDigestListToBuffer (DigestBuffer
, DigestList
);
1123 CopyMem (DigestBuffer
, &NewEventHdr
->EventSize
, sizeof(NewEventHdr
->EventSize
));
1124 DigestBuffer
= DigestBuffer
+ sizeof(NewEventHdr
->EventSize
);
1127 // Enter critical region
1129 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
1130 Status
= TcgDxeLogEvent (
1131 mTcg2EventInfo
[Index
].LogFormat
,
1133 sizeof(TcgPcrEvent2
.PCRIndex
) + sizeof(TcgPcrEvent2
.EventType
) + GetDigestListSize (DigestList
) + sizeof(TcgPcrEvent2
.EventSize
),
1135 NewEventHdr
->EventSize
1137 if (Status
!= EFI_SUCCESS
) {
1140 gBS
->RestoreTPL (OldTpl
);
1142 // Exit critical region
1153 Do a hash operation on a data buffer, extend a specific TPM PCR with the hash result,
1154 and add an entry to the Event Log.
1156 @param[in] Flags Bitmap providing additional information.
1157 @param[in] HashData Physical address of the start of the data buffer
1158 to be hashed, extended, and logged.
1159 @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData
1160 @param[in, out] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
1161 @param[in] NewEventData Pointer to the new event data.
1163 @retval EFI_SUCCESS Operation completed successfully.
1164 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
1165 @retval EFI_DEVICE_ERROR The command was unsuccessful.
1169 TcgDxeHashLogExtendEvent (
1172 IN UINT64 HashDataLen
,
1173 IN OUT TCG_PCR_EVENT_HDR
*NewEventHdr
,
1174 IN UINT8
*NewEventData
1178 TPML_DIGEST_VALUES DigestList
;
1180 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
1181 return EFI_DEVICE_ERROR
;
1184 Status
= HashAndExtend (
1185 NewEventHdr
->PCRIndex
,
1190 if (!EFI_ERROR (Status
)) {
1191 if ((Flags
& EFI_TCG2_EXTEND_ONLY
) == 0) {
1192 Status
= TcgDxeLogHashEvent (&DigestList
, NewEventHdr
, NewEventData
);
1196 if (Status
== EFI_DEVICE_ERROR
) {
1197 DEBUG ((EFI_D_ERROR
, "TcgDxeHashLogExtendEvent - %r. Disable TPM.\n", Status
));
1198 mTcgDxeData
.BsCap
.TPMPresentFlag
= FALSE
;
1199 REPORT_STATUS_CODE (
1200 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
1201 (PcdGet32 (PcdStatusCodeSubClassTpmDevice
) | EFI_P_EC_INTERFACE_ERROR
)
1209 The EFI_TCG2_PROTOCOL HashLogExtendEvent function call provides callers with
1210 an opportunity to extend and optionally log events without requiring
1211 knowledge of actual TPM commands.
1212 The extend operation will occur even if this function cannot create an event
1213 log entry (e.g. due to the event log being full).
1215 @param[in] This Indicates the calling context
1216 @param[in] Flags Bitmap providing additional information.
1217 @param[in] DataToHash Physical address of the start of the data buffer to be hashed.
1218 @param[in] DataToHashLen The length in bytes of the buffer referenced by DataToHash.
1219 @param[in] Event Pointer to data buffer containing information about the event.
1221 @retval EFI_SUCCESS Operation completed successfully.
1222 @retval EFI_DEVICE_ERROR The command was unsuccessful.
1223 @retval EFI_VOLUME_FULL The extend operation occurred, but the event could not be written to one or more event logs.
1224 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1225 @retval EFI_UNSUPPORTED The PE/COFF image type is not supported.
1229 Tcg2HashLogExtendEvent (
1230 IN EFI_TCG2_PROTOCOL
*This
,
1232 IN EFI_PHYSICAL_ADDRESS DataToHash
,
1233 IN UINT64 DataToHashLen
,
1234 IN EFI_TCG2_EVENT
*Event
1238 TCG_PCR_EVENT_HDR NewEventHdr
;
1239 TPML_DIGEST_VALUES DigestList
;
1241 DEBUG ((DEBUG_VERBOSE
, "Tcg2HashLogExtendEvent ...\n"));
1243 if ((This
== NULL
) || (DataToHash
== 0) || (Event
== NULL
)) {
1244 return EFI_INVALID_PARAMETER
;
1247 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
1248 return EFI_DEVICE_ERROR
;
1251 if (Event
->Size
< Event
->Header
.HeaderSize
+ sizeof(UINT32
)) {
1252 return EFI_INVALID_PARAMETER
;
1255 if (Event
->Header
.PCRIndex
> MAX_PCR_INDEX
) {
1256 return EFI_INVALID_PARAMETER
;
1259 NewEventHdr
.PCRIndex
= Event
->Header
.PCRIndex
;
1260 NewEventHdr
.EventType
= Event
->Header
.EventType
;
1261 NewEventHdr
.EventSize
= Event
->Size
- sizeof(UINT32
) - Event
->Header
.HeaderSize
;
1262 if ((Flags
& PE_COFF_IMAGE
) != 0) {
1263 Status
= MeasurePeImageAndExtend (
1264 NewEventHdr
.PCRIndex
,
1266 (UINTN
)DataToHashLen
,
1269 if (!EFI_ERROR (Status
)) {
1270 if ((Flags
& EFI_TCG2_EXTEND_ONLY
) == 0) {
1271 Status
= TcgDxeLogHashEvent (&DigestList
, &NewEventHdr
, Event
->Event
);
1274 if (Status
== EFI_DEVICE_ERROR
) {
1275 DEBUG ((EFI_D_ERROR
, "MeasurePeImageAndExtend - %r. Disable TPM.\n", Status
));
1276 mTcgDxeData
.BsCap
.TPMPresentFlag
= FALSE
;
1277 REPORT_STATUS_CODE (
1278 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
1279 (PcdGet32 (PcdStatusCodeSubClassTpmDevice
) | EFI_P_EC_INTERFACE_ERROR
)
1283 Status
= TcgDxeHashLogExtendEvent (
1285 (UINT8
*) (UINTN
) DataToHash
,
1291 DEBUG ((DEBUG_VERBOSE
, "Tcg2HashLogExtendEvent - %r\n", Status
));
1296 This service enables the sending of commands to the TPM.
1298 @param[in] This Indicates the calling context
1299 @param[in] InputParameterBlockSize Size of the TPM input parameter block.
1300 @param[in] InputParameterBlock Pointer to the TPM input parameter block.
1301 @param[in] OutputParameterBlockSize Size of the TPM output parameter block.
1302 @param[in] OutputParameterBlock Pointer to the TPM output parameter block.
1304 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
1305 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
1306 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1307 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
1312 IN EFI_TCG2_PROTOCOL
*This
,
1313 IN UINT32 InputParameterBlockSize
,
1314 IN UINT8
*InputParameterBlock
,
1315 IN UINT32 OutputParameterBlockSize
,
1316 IN UINT8
*OutputParameterBlock
1321 DEBUG ((EFI_D_INFO
, "Tcg2SubmitCommand ...\n"));
1323 if ((This
== NULL
) ||
1324 (InputParameterBlockSize
== 0) || (InputParameterBlock
== NULL
) ||
1325 (OutputParameterBlockSize
== 0) || (OutputParameterBlock
== NULL
)) {
1326 return EFI_INVALID_PARAMETER
;
1329 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
1330 return EFI_DEVICE_ERROR
;
1333 if (InputParameterBlockSize
> mTcgDxeData
.BsCap
.MaxCommandSize
) {
1334 return EFI_INVALID_PARAMETER
;
1336 if (OutputParameterBlockSize
> mTcgDxeData
.BsCap
.MaxResponseSize
) {
1337 return EFI_INVALID_PARAMETER
;
1340 Status
= Tpm2SubmitCommand (
1341 InputParameterBlockSize
,
1342 InputParameterBlock
,
1343 &OutputParameterBlockSize
,
1344 OutputParameterBlock
1346 DEBUG ((EFI_D_INFO
, "Tcg2SubmitCommand - %r\n", Status
));
1351 This service returns the currently active PCR banks.
1353 @param[in] This Indicates the calling context
1354 @param[out] ActivePcrBanks Pointer to the variable receiving the bitmap of currently active PCR banks.
1356 @retval EFI_SUCCESS The bitmap of active PCR banks was stored in the ActivePcrBanks parameter.
1357 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1361 Tcg2GetActivePCRBanks (
1362 IN EFI_TCG2_PROTOCOL
*This
,
1363 OUT UINT32
*ActivePcrBanks
1366 if (ActivePcrBanks
== NULL
) {
1367 return EFI_INVALID_PARAMETER
;
1369 *ActivePcrBanks
= mTcgDxeData
.BsCap
.ActivePcrBanks
;
1374 This service sets the currently active PCR banks.
1376 @param[in] This Indicates the calling context
1377 @param[in] ActivePcrBanks Bitmap of the requested active PCR banks. At least one bit SHALL be set.
1379 @retval EFI_SUCCESS The bitmap in ActivePcrBank parameter is already active.
1380 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1384 Tcg2SetActivePCRBanks (
1385 IN EFI_TCG2_PROTOCOL
*This
,
1386 IN UINT32 ActivePcrBanks
1392 DEBUG ((EFI_D_INFO
, "Tcg2SetActivePCRBanks ... (0x%x)\n", ActivePcrBanks
));
1394 if (ActivePcrBanks
== 0) {
1395 return EFI_INVALID_PARAMETER
;
1397 if ((ActivePcrBanks
& (~mTcgDxeData
.BsCap
.HashAlgorithmBitmap
)) != 0) {
1398 return EFI_INVALID_PARAMETER
;
1400 if (ActivePcrBanks
== mTcgDxeData
.BsCap
.ActivePcrBanks
) {
1402 // Need clear previous SET_PCR_BANKS setting
1404 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_NO_ACTION
, 0);
1406 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS
, ActivePcrBanks
);
1409 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
1410 Status
= EFI_SUCCESS
;
1411 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
1412 Status
= EFI_OUT_OF_RESOURCES
;
1413 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
1414 Status
= EFI_UNSUPPORTED
;
1416 Status
= EFI_DEVICE_ERROR
;
1419 DEBUG ((EFI_D_INFO
, "Tcg2SetActivePCRBanks - %r\n", Status
));
1425 This service retrieves the result of a previous invocation of SetActivePcrBanks.
1427 @param[in] This Indicates the calling context
1428 @param[out] OperationPresent Non-zero value to indicate a SetActivePcrBank operation was invoked during the last boot.
1429 @param[out] Response The response from the SetActivePcrBank request.
1431 @retval EFI_SUCCESS The result value could be returned.
1432 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1436 Tcg2GetResultOfSetActivePcrBanks (
1437 IN EFI_TCG2_PROTOCOL
*This
,
1438 OUT UINT32
*OperationPresent
,
1439 OUT UINT32
*Response
1444 if ((OperationPresent
== NULL
) || (Response
== NULL
)) {
1445 return EFI_INVALID_PARAMETER
;
1448 ReturnCode
= Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (OperationPresent
, Response
);
1449 if (ReturnCode
== TCG_PP_RETURN_TPM_OPERATION_RESPONSE_SUCCESS
) {
1452 return EFI_UNSUPPORTED
;
1456 EFI_TCG2_PROTOCOL mTcg2Protocol
= {
1459 Tcg2HashLogExtendEvent
,
1461 Tcg2GetActivePCRBanks
,
1462 Tcg2SetActivePCRBanks
,
1463 Tcg2GetResultOfSetActivePcrBanks
,
1467 Initialize the Event Log and log events passed from the PEI phase.
1469 @retval EFI_SUCCESS Operation completed successfully.
1470 @retval EFI_OUT_OF_RESOURCES Out of memory.
1480 EFI_PEI_HOB_POINTERS GuidHob
;
1481 EFI_PHYSICAL_ADDRESS Lasa
;
1483 UINT32 DigestListBinSize
;
1485 TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
;
1486 UINT8 TempBuf
[sizeof(TCG_EfiSpecIDEventStruct
) + sizeof(UINT32
) + (HASH_COUNT
* sizeof(TCG_EfiSpecIdEventAlgorithmSize
)) + sizeof(UINT8
)];
1487 TCG_PCR_EVENT_HDR FirstPcrEvent
;
1488 TCG_EfiSpecIdEventAlgorithmSize
*DigestSize
;
1489 TCG_EfiSpecIdEventAlgorithmSize
*TempDigestSize
;
1490 UINT8
*VendorInfoSize
;
1491 UINT32 NumberOfAlgorithms
;
1493 DEBUG ((EFI_D_INFO
, "SetupEventLog\n"));
1496 // 1. Create Log Area
1498 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1499 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1500 mTcgDxeData
.EventLogAreaStruct
[Index
].EventLogFormat
= mTcg2EventInfo
[Index
].LogFormat
;
1501 Lasa
= (EFI_PHYSICAL_ADDRESS
) (SIZE_4GB
- 1);
1502 Status
= gBS
->AllocatePages (
1504 EfiBootServicesData
,
1505 EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcgLogAreaMinLen
)),
1508 if (EFI_ERROR (Status
)) {
1511 mTcgDxeData
.EventLogAreaStruct
[Index
].Lasa
= Lasa
;
1512 mTcgDxeData
.EventLogAreaStruct
[Index
].Laml
= PcdGet32 (PcdTcgLogAreaMinLen
);
1514 // To initialize them as 0xFF is recommended
1515 // because the OS can know the last entry for that.
1517 SetMem ((VOID
*)(UINTN
)Lasa
, PcdGet32 (PcdTcgLogAreaMinLen
), 0xFF);
1519 // Create first entry for Log Header Entry Data
1521 if (mTcg2EventInfo
[Index
].LogFormat
!= EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
) {
1523 // TcgEfiSpecIdEventStruct
1525 TcgEfiSpecIdEventStruct
= (TCG_EfiSpecIDEventStruct
*)TempBuf
;
1526 CopyMem (TcgEfiSpecIdEventStruct
->signature
, TCG_EfiSpecIDEventStruct_SIGNATURE_03
, sizeof(TcgEfiSpecIdEventStruct
->signature
));
1527 TcgEfiSpecIdEventStruct
->platformClass
= PcdGet8 (PcdTpmPlatformClass
);
1528 TcgEfiSpecIdEventStruct
->specVersionMajor
= TCG_EfiSpecIDEventStruct_SPEC_VERSION_MAJOR_TPM2
;
1529 TcgEfiSpecIdEventStruct
->specVersionMinor
= TCG_EfiSpecIDEventStruct_SPEC_VERSION_MINOR_TPM2
;
1530 TcgEfiSpecIdEventStruct
->specErrata
= TCG_EfiSpecIDEventStruct_SPEC_ERRATA_TPM2
;
1531 TcgEfiSpecIdEventStruct
->uintnSize
= sizeof(UINTN
)/sizeof(UINT32
);
1532 NumberOfAlgorithms
= 0;
1533 DigestSize
= (TCG_EfiSpecIdEventAlgorithmSize
*)((UINT8
*)TcgEfiSpecIdEventStruct
+ sizeof(*TcgEfiSpecIdEventStruct
) + sizeof(NumberOfAlgorithms
));
1534 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) != 0) {
1535 TempDigestSize
= DigestSize
;
1536 TempDigestSize
+= NumberOfAlgorithms
;
1537 TempDigestSize
->algorithmId
= TPM_ALG_SHA1
;
1538 TempDigestSize
->digestSize
= SHA1_DIGEST_SIZE
;
1539 NumberOfAlgorithms
++;
1541 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA256
) != 0) {
1542 TempDigestSize
= DigestSize
;
1543 TempDigestSize
+= NumberOfAlgorithms
;
1544 TempDigestSize
->algorithmId
= TPM_ALG_SHA256
;
1545 TempDigestSize
->digestSize
= SHA256_DIGEST_SIZE
;
1546 NumberOfAlgorithms
++;
1548 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA384
) != 0) {
1549 TempDigestSize
= DigestSize
;
1550 TempDigestSize
+= NumberOfAlgorithms
;
1551 TempDigestSize
->algorithmId
= TPM_ALG_SHA384
;
1552 TempDigestSize
->digestSize
= SHA384_DIGEST_SIZE
;
1553 NumberOfAlgorithms
++;
1555 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA512
) != 0) {
1556 TempDigestSize
= DigestSize
;
1557 TempDigestSize
+= NumberOfAlgorithms
;
1558 TempDigestSize
->algorithmId
= TPM_ALG_SHA512
;
1559 TempDigestSize
->digestSize
= SHA512_DIGEST_SIZE
;
1560 NumberOfAlgorithms
++;
1562 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SM3_256
) != 0) {
1563 TempDigestSize
= DigestSize
;
1564 TempDigestSize
+= NumberOfAlgorithms
;
1565 TempDigestSize
->algorithmId
= TPM_ALG_SM3_256
;
1566 TempDigestSize
->digestSize
= SM3_256_DIGEST_SIZE
;
1567 NumberOfAlgorithms
++;
1569 CopyMem (TcgEfiSpecIdEventStruct
+ 1, &NumberOfAlgorithms
, sizeof(NumberOfAlgorithms
));
1570 TempDigestSize
= DigestSize
;
1571 TempDigestSize
+= NumberOfAlgorithms
;
1572 VendorInfoSize
= (UINT8
*)TempDigestSize
;
1573 *VendorInfoSize
= 0;
1578 FirstPcrEvent
.PCRIndex
= 0;
1579 FirstPcrEvent
.EventType
= EV_NO_ACTION
;
1580 ZeroMem (&FirstPcrEvent
.Digest
, sizeof(FirstPcrEvent
.Digest
));
1581 FirstPcrEvent
.EventSize
= (UINT32
)GetTcgEfiSpecIdEventStructSize (TcgEfiSpecIdEventStruct
);
1586 Status
= TcgDxeLogEvent (
1587 mTcg2EventInfo
[Index
].LogFormat
,
1589 sizeof(FirstPcrEvent
),
1590 (UINT8
*)TcgEfiSpecIdEventStruct
,
1591 FirstPcrEvent
.EventSize
1598 // 2. Create Final Log Area
1600 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1601 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1602 if (mTcg2EventInfo
[Index
].LogFormat
== EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
) {
1603 Lasa
= (EFI_PHYSICAL_ADDRESS
) (SIZE_4GB
- 1);
1604 Status
= gBS
->AllocatePages (
1607 EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcg2FinalLogAreaLen
)),
1610 if (EFI_ERROR (Status
)) {
1613 SetMem ((VOID
*)(UINTN
)Lasa
, PcdGet32 (PcdTcg2FinalLogAreaLen
), 0xFF);
1618 mTcgDxeData
.FinalEventsTable
[Index
] = (VOID
*)(UINTN
)Lasa
;
1619 (mTcgDxeData
.FinalEventsTable
[Index
])->Version
= EFI_TCG2_FINAL_EVENTS_TABLE_VERSION
;
1620 (mTcgDxeData
.FinalEventsTable
[Index
])->NumberOfEvents
= 0;
1622 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogFormat
= mTcg2EventInfo
[Index
].LogFormat
;
1623 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Lasa
= Lasa
+ sizeof(EFI_TCG2_FINAL_EVENTS_TABLE
);
1624 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Laml
= PcdGet32 (PcdTcg2FinalLogAreaLen
) - sizeof(EFI_TCG2_FINAL_EVENTS_TABLE
);
1625 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogSize
= 0;
1626 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].LastEvent
= (VOID
*)(UINTN
)mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Lasa
;
1627 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogStarted
= FALSE
;
1628 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogTruncated
= FALSE
;
1631 // Install to configuration table for EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
1633 Status
= gBS
->InstallConfigurationTable (&gEfiTcg2FinalEventsTableGuid
, (VOID
*)mTcgDxeData
.FinalEventsTable
[Index
]);
1634 if (EFI_ERROR (Status
)) {
1639 // No need to handle EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
1641 mTcgDxeData
.FinalEventsTable
[Index
] = NULL
;
1642 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogFormat
= mTcg2EventInfo
[Index
].LogFormat
;
1643 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Lasa
= 0;
1644 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Laml
= 0;
1645 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogSize
= 0;
1646 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].LastEvent
= 0;
1647 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogStarted
= FALSE
;
1648 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogTruncated
= FALSE
;
1654 // 3. Sync data from PEI to DXE
1656 Status
= EFI_SUCCESS
;
1657 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1658 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1659 GuidHob
.Raw
= GetHobList ();
1660 Status
= EFI_SUCCESS
;
1661 while (!EFI_ERROR (Status
) &&
1662 (GuidHob
.Raw
= GetNextGuidHob (mTcg2EventInfo
[Index
].EventGuid
, GuidHob
.Raw
)) != NULL
) {
1663 TcgEvent
= GET_GUID_HOB_DATA (GuidHob
.Guid
);
1664 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
1665 switch (mTcg2EventInfo
[Index
].LogFormat
) {
1666 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
:
1667 Status
= TcgDxeLogEvent (
1668 mTcg2EventInfo
[Index
].LogFormat
,
1670 sizeof(TCG_PCR_EVENT_HDR
),
1671 ((TCG_PCR_EVENT
*)TcgEvent
)->Event
,
1672 ((TCG_PCR_EVENT_HDR
*)TcgEvent
)->EventSize
1675 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
:
1676 DigestListBinSize
= GetDigestListBinSize ((UINT8
*)TcgEvent
+ sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
));
1677 CopyMem (&EventSize
, (UINT8
*)TcgEvent
+ sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
) + DigestListBinSize
, sizeof(UINT32
));
1678 Status
= TcgDxeLogEvent (
1679 mTcg2EventInfo
[Index
].LogFormat
,
1681 sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
) + DigestListBinSize
+ sizeof(UINT32
),
1682 (UINT8
*)TcgEvent
+ sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
) + DigestListBinSize
+ sizeof(UINT32
),
1695 Measure and log an action string, and extend the measurement result into PCR[5].
1697 @param[in] String A specific string that indicates an Action event.
1699 @retval EFI_SUCCESS Operation completed successfully.
1700 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1708 TCG_PCR_EVENT_HDR TcgEvent
;
1710 TcgEvent
.PCRIndex
= 5;
1711 TcgEvent
.EventType
= EV_EFI_ACTION
;
1712 TcgEvent
.EventSize
= (UINT32
)AsciiStrLen (String
);
1713 return TcgDxeHashLogExtendEvent (
1723 Measure and log EFI handoff tables, and extend the measurement result into PCR[1].
1725 @retval EFI_SUCCESS Operation completed successfully.
1726 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1730 MeasureHandoffTables (
1735 TCG_PCR_EVENT_HDR TcgEvent
;
1736 EFI_HANDOFF_TABLE_POINTERS HandoffTables
;
1738 EFI_CPU_PHYSICAL_LOCATION
*ProcessorLocBuf
;
1740 ProcessorLocBuf
= NULL
;
1741 Status
= EFI_SUCCESS
;
1743 if (PcdGet8 (PcdTpmPlatformClass
) == TCG_PLATFORM_TYPE_SERVER
) {
1746 // Measure each processor EFI_CPU_PHYSICAL_LOCATION with EV_TABLE_OF_DEVICES to PCR[1]
1748 Status
= GetProcessorsCpuLocation(&ProcessorLocBuf
, &ProcessorNum
);
1750 if (!EFI_ERROR(Status
)){
1751 TcgEvent
.PCRIndex
= 1;
1752 TcgEvent
.EventType
= EV_TABLE_OF_DEVICES
;
1753 TcgEvent
.EventSize
= sizeof (HandoffTables
);
1755 HandoffTables
.NumberOfTables
= 1;
1756 HandoffTables
.TableEntry
[0].VendorGuid
= gEfiMpServiceProtocolGuid
;
1757 HandoffTables
.TableEntry
[0].VendorTable
= ProcessorLocBuf
;
1759 Status
= TcgDxeHashLogExtendEvent (
1761 (UINT8
*)(UINTN
)ProcessorLocBuf
,
1762 sizeof(EFI_CPU_PHYSICAL_LOCATION
) * ProcessorNum
,
1764 (UINT8
*)&HandoffTables
1767 FreePool(ProcessorLocBuf
);
1775 Measure and log Separator event, and extend the measurement result into a specific PCR.
1777 @param[in] PCRIndex PCR index.
1779 @retval EFI_SUCCESS Operation completed successfully.
1780 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1784 MeasureSeparatorEvent (
1785 IN TPM_PCRINDEX PCRIndex
1788 TCG_PCR_EVENT_HDR TcgEvent
;
1791 DEBUG ((EFI_D_INFO
, "MeasureSeparatorEvent Pcr - %x\n", PCRIndex
));
1794 TcgEvent
.PCRIndex
= PCRIndex
;
1795 TcgEvent
.EventType
= EV_SEPARATOR
;
1796 TcgEvent
.EventSize
= (UINT32
)sizeof (EventData
);
1797 return TcgDxeHashLogExtendEvent (
1799 (UINT8
*)&EventData
,
1807 Measure and log an EFI variable, and extend the measurement result into a specific PCR.
1809 @param[in] PCRIndex PCR Index.
1810 @param[in] EventType Event type.
1811 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1812 @param[in] VendorGuid A unique identifier for the vendor.
1813 @param[in] VarData The content of the variable data.
1814 @param[in] VarSize The size of the variable data.
1816 @retval EFI_SUCCESS Operation completed successfully.
1817 @retval EFI_OUT_OF_RESOURCES Out of memory.
1818 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1823 IN TPM_PCRINDEX PCRIndex
,
1824 IN TCG_EVENTTYPE EventType
,
1826 IN EFI_GUID
*VendorGuid
,
1832 TCG_PCR_EVENT_HDR TcgEvent
;
1833 UINTN VarNameLength
;
1834 EFI_VARIABLE_DATA_TREE
*VarLog
;
1836 DEBUG ((EFI_D_INFO
, "Tcg2Dxe: MeasureVariable (Pcr - %x, EventType - %x, ", (UINTN
)PCRIndex
, (UINTN
)EventType
));
1837 DEBUG ((EFI_D_INFO
, "VariableName - %s, VendorGuid - %g)\n", VarName
, VendorGuid
));
1839 VarNameLength
= StrLen (VarName
);
1840 TcgEvent
.PCRIndex
= PCRIndex
;
1841 TcgEvent
.EventType
= EventType
;
1843 TcgEvent
.EventSize
= (UINT32
)(sizeof (*VarLog
) + VarNameLength
* sizeof (*VarName
) + VarSize
1844 - sizeof (VarLog
->UnicodeName
) - sizeof (VarLog
->VariableData
));
1846 VarLog
= (EFI_VARIABLE_DATA_TREE
*)AllocatePool (TcgEvent
.EventSize
);
1847 if (VarLog
== NULL
) {
1848 return EFI_OUT_OF_RESOURCES
;
1851 VarLog
->VariableName
= *VendorGuid
;
1852 VarLog
->UnicodeNameLength
= VarNameLength
;
1853 VarLog
->VariableDataLength
= VarSize
;
1855 VarLog
->UnicodeName
,
1857 VarNameLength
* sizeof (*VarName
)
1859 if (VarSize
!= 0 && VarData
!= NULL
) {
1861 (CHAR16
*)VarLog
->UnicodeName
+ VarNameLength
,
1867 if (EventType
== EV_EFI_VARIABLE_DRIVER_CONFIG
) {
1869 // Digest is the event data (EFI_VARIABLE_DATA)
1871 Status
= TcgDxeHashLogExtendEvent (
1879 Status
= TcgDxeHashLogExtendEvent (
1892 Read then Measure and log an EFI variable, and extend the measurement result into a specific PCR.
1894 @param[in] PCRIndex PCR Index.
1895 @param[in] EventType Event type.
1896 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1897 @param[in] VendorGuid A unique identifier for the vendor.
1898 @param[out] VarSize The size of the variable data.
1899 @param[out] VarData Pointer to the content of the variable.
1901 @retval EFI_SUCCESS Operation completed successfully.
1902 @retval EFI_OUT_OF_RESOURCES Out of memory.
1903 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1907 ReadAndMeasureVariable (
1908 IN TPM_PCRINDEX PCRIndex
,
1909 IN TCG_EVENTTYPE EventType
,
1911 IN EFI_GUID
*VendorGuid
,
1918 Status
= GetVariable2 (VarName
, VendorGuid
, VarData
, VarSize
);
1919 if (EventType
== EV_EFI_VARIABLE_DRIVER_CONFIG
) {
1920 if (EFI_ERROR (Status
)) {
1922 // It is valid case, so we need handle it.
1929 // if status error, VarData is freed and set NULL by GetVariable2
1931 if (EFI_ERROR (Status
)) {
1932 return EFI_NOT_FOUND
;
1936 Status
= MeasureVariable (
1948 Read then Measure and log an EFI boot variable, and extend the measurement result into PCR[5].
1950 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1951 @param[in] VendorGuid A unique identifier for the vendor.
1952 @param[out] VarSize The size of the variable data.
1953 @param[out] VarData Pointer to the content of the variable.
1955 @retval EFI_SUCCESS Operation completed successfully.
1956 @retval EFI_OUT_OF_RESOURCES Out of memory.
1957 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1961 ReadAndMeasureBootVariable (
1963 IN EFI_GUID
*VendorGuid
,
1968 return ReadAndMeasureVariable (
1970 EV_EFI_VARIABLE_BOOT
,
1979 Read then Measure and log an EFI Secure variable, and extend the measurement result into PCR[7].
1981 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1982 @param[in] VendorGuid A unique identifier for the vendor.
1983 @param[out] VarSize The size of the variable data.
1984 @param[out] VarData Pointer to the content of the variable.
1986 @retval EFI_SUCCESS Operation completed successfully.
1987 @retval EFI_OUT_OF_RESOURCES Out of memory.
1988 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1992 ReadAndMeasureSecureVariable (
1994 IN EFI_GUID
*VendorGuid
,
1999 return ReadAndMeasureVariable (
2001 EV_EFI_VARIABLE_DRIVER_CONFIG
,
2010 Measure and log all EFI boot variables, and extend the measurement result into a specific PCR.
2012 The EFI boot variables are BootOrder and Boot#### variables.
2014 @retval EFI_SUCCESS Operation completed successfully.
2015 @retval EFI_OUT_OF_RESOURCES Out of memory.
2016 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
2020 MeasureAllBootVariables (
2031 Status
= ReadAndMeasureBootVariable (
2033 &gEfiGlobalVariableGuid
,
2035 (VOID
**) &BootOrder
2037 if (Status
== EFI_NOT_FOUND
|| BootOrder
== NULL
) {
2041 if (EFI_ERROR (Status
)) {
2043 // BootOrder can't be NULL if status is not EFI_NOT_FOUND
2045 FreePool (BootOrder
);
2049 BootCount
/= sizeof (*BootOrder
);
2050 for (Index
= 0; Index
< BootCount
; Index
++) {
2051 UnicodeSPrint (mBootVarName
, sizeof (mBootVarName
), L
"Boot%04x", BootOrder
[Index
]);
2052 Status
= ReadAndMeasureBootVariable (
2054 &gEfiGlobalVariableGuid
,
2058 if (!EFI_ERROR (Status
)) {
2059 FreePool (BootVarData
);
2063 FreePool (BootOrder
);
2068 Measure and log all EFI Secure variables, and extend the measurement result into a specific PCR.
2070 The EFI boot variables are BootOrder and Boot#### variables.
2072 @retval EFI_SUCCESS Operation completed successfully.
2073 @retval EFI_OUT_OF_RESOURCES Out of memory.
2074 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
2078 MeasureAllSecureVariables (
2087 Status
= EFI_NOT_FOUND
;
2088 for (Index
= 0; Index
< sizeof(mVariableType
)/sizeof(mVariableType
[0]); Index
++) {
2089 Status
= ReadAndMeasureSecureVariable (
2090 mVariableType
[Index
].VariableName
,
2091 mVariableType
[Index
].VendorGuid
,
2095 if (!EFI_ERROR (Status
)) {
2106 Measure and log launch of FirmwareDebugger, and extend the measurement result into a specific PCR.
2108 @retval EFI_SUCCESS Operation completed successfully.
2109 @retval EFI_OUT_OF_RESOURCES Out of memory.
2110 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
2114 MeasureLaunchOfFirmwareDebugger (
2118 TCG_PCR_EVENT_HDR TcgEvent
;
2120 TcgEvent
.PCRIndex
= 7;
2121 TcgEvent
.EventType
= EV_EFI_ACTION
;
2122 TcgEvent
.EventSize
= sizeof(FIRMWARE_DEBUGGER_EVENT_STRING
) - 1;
2123 return TcgDxeHashLogExtendEvent (
2125 (UINT8
*)FIRMWARE_DEBUGGER_EVENT_STRING
,
2126 sizeof(FIRMWARE_DEBUGGER_EVENT_STRING
) - 1,
2128 (UINT8
*)FIRMWARE_DEBUGGER_EVENT_STRING
2133 Measure and log all Secure Boot Policy, and extend the measurement result into a specific PCR.
2135 Platform firmware adhering to the policy must therefore measure the following values into PCR[7]: (in order listed)
2136 - The contents of the SecureBoot variable
2137 - The contents of the PK variable
2138 - The contents of the KEK variable
2139 - The contents of the EFI_IMAGE_SECURITY_DATABASE variable
2140 - The contents of the EFI_IMAGE_SECURITY_DATABASE1 variable
2142 - Entries in the EFI_IMAGE_SECURITY_DATABASE that are used to validate EFI Drivers or EFI Boot Applications in the boot path
2144 NOTE: Because of the above, UEFI variables PK, KEK, EFI_IMAGE_SECURITY_DATABASE,
2145 EFI_IMAGE_SECURITY_DATABASE1 and SecureBoot SHALL NOT be measured into PCR[3].
2147 @param[in] Event Event whose notification function is being invoked
2148 @param[in] Context Pointer to the notification function's context
2152 MeasureSecureBootPolicy (
2160 Status
= gBS
->LocateProtocol (&gEfiVariableWriteArchProtocolGuid
, NULL
, (VOID
**)&Protocol
);
2161 if (EFI_ERROR (Status
)) {
2165 if (PcdGetBool (PcdFirmwareDebuggerInitialized
)) {
2166 Status
= MeasureLaunchOfFirmwareDebugger ();
2167 DEBUG ((EFI_D_INFO
, "MeasureLaunchOfFirmwareDebugger - %r\n", Status
));
2170 Status
= MeasureAllSecureVariables ();
2171 DEBUG ((EFI_D_INFO
, "MeasureAllSecureVariables - %r\n", Status
));
2174 // We need measure Separator(7) here, because this event must be between SecureBootPolicy (Configure)
2175 // and ImageVerification (Authority)
2176 // There might be a case that we need measure UEFI image from DriverOrder, besides BootOrder. So
2177 // the Authority measurement happen before ReadToBoot event.
2179 Status
= MeasureSeparatorEvent (7);
2180 DEBUG ((EFI_D_INFO
, "MeasureSeparatorEvent - %r\n", Status
));
2185 Ready to Boot Event notification handler.
2187 Sequence of OS boot events is measured in this event notification handler.
2189 @param[in] Event Event whose notification function is being invoked
2190 @param[in] Context Pointer to the notification function's context
2201 TPM_PCRINDEX PcrIndex
;
2203 PERF_START_EX (mImageHandle
, "EventRec", "Tcg2Dxe", 0, PERF_ID_TCG2_DXE
);
2204 if (mBootAttempts
== 0) {
2207 // Measure handoff tables.
2209 Status
= MeasureHandoffTables ();
2210 if (EFI_ERROR (Status
)) {
2211 DEBUG ((EFI_D_ERROR
, "HOBs not Measured. Error!\n"));
2215 // Measure BootOrder & Boot#### variables.
2217 Status
= MeasureAllBootVariables ();
2218 if (EFI_ERROR (Status
)) {
2219 DEBUG ((EFI_D_ERROR
, "Boot Variables not Measured. Error!\n"));
2223 // 1. This is the first boot attempt.
2225 Status
= TcgMeasureAction (
2226 EFI_CALLING_EFI_APPLICATION
2228 if (EFI_ERROR (Status
)) {
2229 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_CALLING_EFI_APPLICATION
));
2233 // 2. Draw a line between pre-boot env and entering post-boot env.
2234 // PCR[7] is already done.
2236 for (PcrIndex
= 0; PcrIndex
< 7; PcrIndex
++) {
2237 Status
= MeasureSeparatorEvent (PcrIndex
);
2238 if (EFI_ERROR (Status
)) {
2239 DEBUG ((EFI_D_ERROR
, "Seperator Event not Measured. Error!\n"));
2244 // 3. Measure GPT. It would be done in SAP driver.
2248 // 4. Measure PE/COFF OS loader. It would be done in SAP driver.
2252 // 5. Read & Measure variable. BootOrder already measured.
2256 // 6. Not first attempt, meaning a return from last attempt
2258 Status
= TcgMeasureAction (
2259 EFI_RETURNING_FROM_EFI_APPLICATOIN
2261 if (EFI_ERROR (Status
)) {
2262 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_RETURNING_FROM_EFI_APPLICATOIN
));
2266 DEBUG ((EFI_D_INFO
, "TPM2 Tcg2Dxe Measure Data when ReadyToBoot\n"));
2268 // Increase boot attempt counter.
2271 PERF_END_EX (mImageHandle
, "EventRec", "Tcg2Dxe", 0, PERF_ID_TCG2_DXE
+ 1);
2275 Exit Boot Services Event notification handler.
2277 Measure invocation and success of ExitBootServices.
2279 @param[in] Event Event whose notification function is being invoked
2280 @param[in] Context Pointer to the notification function's context
2285 OnExitBootServices (
2293 // Measure invocation of ExitBootServices,
2295 Status
= TcgMeasureAction (
2296 EFI_EXIT_BOOT_SERVICES_INVOCATION
2298 if (EFI_ERROR (Status
)) {
2299 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_INVOCATION
));
2303 // Measure success of ExitBootServices
2305 Status
= TcgMeasureAction (
2306 EFI_EXIT_BOOT_SERVICES_SUCCEEDED
2308 if (EFI_ERROR (Status
)) {
2309 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_SUCCEEDED
));
2314 Exit Boot Services Failed Event notification handler.
2316 Measure Failure of ExitBootServices.
2318 @param[in] Event Event whose notification function is being invoked
2319 @param[in] Context Pointer to the notification function's context
2324 OnExitBootServicesFailed (
2332 // Measure Failure of ExitBootServices,
2334 Status
= TcgMeasureAction (
2335 EFI_EXIT_BOOT_SERVICES_FAILED
2337 if (EFI_ERROR (Status
)) {
2338 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_FAILED
));
2344 The function install Tcg2 protocol.
2346 @retval EFI_SUCCESS Tcg2 protocol is installed.
2347 @retval other Some error occurs.
2358 Status
= gBS
->InstallMultipleProtocolInterfaces (
2360 &gEfiTcg2ProtocolGuid
,
2368 The driver's entry point. It publishes EFI Tcg2 Protocol.
2370 @param[in] ImageHandle The firmware allocated handle for the EFI image.
2371 @param[in] SystemTable A pointer to the EFI System Table.
2373 @retval EFI_SUCCESS The entry point is executed successfully.
2374 @retval other Some error occurs when executing this entry point.
2379 IN EFI_HANDLE ImageHandle
,
2380 IN EFI_SYSTEM_TABLE
*SystemTable
2386 UINT32 MaxCommandSize
;
2387 UINT32 MaxResponseSize
;
2388 TPML_PCR_SELECTION Pcrs
;
2390 EFI_TCG2_EVENT_ALGORITHM_BITMAP TpmHashAlgorithmBitmap
;
2391 UINT32 ActivePCRBanks
;
2392 UINT32 NumberOfPCRBanks
;
2394 mImageHandle
= ImageHandle
;
2396 if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &gEfiTpmDeviceInstanceNoneGuid
) ||
2397 CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &gEfiTpmDeviceInstanceTpm12Guid
)){
2398 DEBUG ((EFI_D_ERROR
, "No TPM2 instance required!\n"));
2399 return EFI_UNSUPPORTED
;
2402 if (GetFirstGuidHob (&gTpmErrorHobGuid
) != NULL
) {
2403 DEBUG ((EFI_D_ERROR
, "TPM2 error!\n"));
2404 return EFI_DEVICE_ERROR
;
2407 Status
= Tpm2RequestUseTpm ();
2408 if (EFI_ERROR (Status
)) {
2409 DEBUG ((EFI_D_ERROR
, "TPM2 not detected!\n"));
2416 ASSERT (TCG_EVENT_LOG_AREA_COUNT_MAX
== sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]));
2418 mTcgDxeData
.BsCap
.Size
= sizeof(EFI_TCG2_BOOT_SERVICE_CAPABILITY
);
2419 mTcgDxeData
.BsCap
.ProtocolVersion
.Major
= 1;
2420 mTcgDxeData
.BsCap
.ProtocolVersion
.Minor
= 1;
2421 mTcgDxeData
.BsCap
.StructureVersion
.Major
= 1;
2422 mTcgDxeData
.BsCap
.StructureVersion
.Minor
= 1;
2424 DEBUG ((EFI_D_INFO
, "Tcg2.ProtocolVersion - %02x.%02x\n", mTcgDxeData
.BsCap
.ProtocolVersion
.Major
, mTcgDxeData
.BsCap
.ProtocolVersion
.Minor
));
2425 DEBUG ((EFI_D_INFO
, "Tcg2.StructureVersion - %02x.%02x\n", mTcgDxeData
.BsCap
.StructureVersion
.Major
, mTcgDxeData
.BsCap
.StructureVersion
.Minor
));
2427 Status
= Tpm2GetCapabilityManufactureID (&mTcgDxeData
.BsCap
.ManufacturerID
);
2428 if (EFI_ERROR (Status
)) {
2429 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityManufactureID fail!\n"));
2431 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityManufactureID - %08x\n", mTcgDxeData
.BsCap
.ManufacturerID
));
2435 UINT32 FirmwareVersion1
;
2436 UINT32 FirmwareVersion2
;
2438 Status
= Tpm2GetCapabilityFirmwareVersion (&FirmwareVersion1
, &FirmwareVersion2
);
2439 if (EFI_ERROR (Status
)) {
2440 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityFirmwareVersion fail!\n"));
2442 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityFirmwareVersion - %08x %08x\n", FirmwareVersion1
, FirmwareVersion2
));
2446 Status
= Tpm2GetCapabilityMaxCommandResponseSize (&MaxCommandSize
, &MaxResponseSize
);
2447 if (EFI_ERROR (Status
)) {
2448 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityMaxCommandResponseSize fail!\n"));
2450 mTcgDxeData
.BsCap
.MaxCommandSize
= (UINT16
)MaxCommandSize
;
2451 mTcgDxeData
.BsCap
.MaxResponseSize
= (UINT16
)MaxResponseSize
;
2452 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityMaxCommandResponseSize - %08x, %08x\n", MaxCommandSize
, MaxResponseSize
));
2456 // Get supported PCR and current Active PCRs
2458 Status
= Tpm2GetCapabilityPcrs (&Pcrs
);
2459 if (EFI_ERROR (Status
)) {
2460 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityPcrs fail!\n"));
2461 TpmHashAlgorithmBitmap
= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2462 ActivePCRBanks
= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2464 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityPcrs Count - %08x\n", Pcrs
.count
));
2465 TpmHashAlgorithmBitmap
= 0;
2467 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
2468 DEBUG ((EFI_D_INFO
, "hash - %x\n", Pcrs
.pcrSelections
[Index
].hash
));
2469 switch (Pcrs
.pcrSelections
[Index
].hash
) {
2471 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2472 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2473 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2476 case TPM_ALG_SHA256
:
2477 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA256
;
2478 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2479 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA256
;
2482 case TPM_ALG_SHA384
:
2483 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA384
;
2484 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2485 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA384
;
2488 case TPM_ALG_SHA512
:
2489 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA512
;
2490 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2491 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA512
;
2494 case TPM_ALG_SM3_256
:
2495 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SM3_256
;
2496 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2497 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SM3_256
;
2503 mTcgDxeData
.BsCap
.HashAlgorithmBitmap
= TpmHashAlgorithmBitmap
& PcdGet32 (PcdTcg2HashAlgorithmBitmap
);
2504 mTcgDxeData
.BsCap
.ActivePcrBanks
= ActivePCRBanks
& PcdGet32 (PcdTcg2HashAlgorithmBitmap
);
2507 // Need calculate NumberOfPCRBanks here, because HashAlgorithmBitmap might be removed by PCD.
2509 NumberOfPCRBanks
= 0;
2510 for (Index
= 0; Index
< 32; Index
++) {
2511 if ((mTcgDxeData
.BsCap
.HashAlgorithmBitmap
& (1u << Index
)) != 0) {
2516 if (PcdGet32 (PcdTcg2NumberOfPCRBanks
) == 0) {
2517 mTcgDxeData
.BsCap
.NumberOfPCRBanks
= NumberOfPCRBanks
;
2519 mTcgDxeData
.BsCap
.NumberOfPCRBanks
= PcdGet32 (PcdTcg2NumberOfPCRBanks
);
2520 if (PcdGet32 (PcdTcg2NumberOfPCRBanks
) > NumberOfPCRBanks
) {
2521 DEBUG ((EFI_D_ERROR
, "ERROR: PcdTcg2NumberOfPCRBanks(0x%x) > NumberOfPCRBanks(0x%x)\n", PcdGet32 (PcdTcg2NumberOfPCRBanks
), NumberOfPCRBanks
));
2522 mTcgDxeData
.BsCap
.NumberOfPCRBanks
= NumberOfPCRBanks
;
2526 mTcgDxeData
.BsCap
.SupportedEventLogs
= EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
| EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
;
2527 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) == 0) {
2529 // No need to expose TCG1.2 event log if SHA1 bank does not exist.
2531 mTcgDxeData
.BsCap
.SupportedEventLogs
&= ~EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
;
2534 DEBUG ((EFI_D_INFO
, "Tcg2.SupportedEventLogs - 0x%08x\n", mTcgDxeData
.BsCap
.SupportedEventLogs
));
2535 DEBUG ((EFI_D_INFO
, "Tcg2.HashAlgorithmBitmap - 0x%08x\n", mTcgDxeData
.BsCap
.HashAlgorithmBitmap
));
2536 DEBUG ((EFI_D_INFO
, "Tcg2.NumberOfPCRBanks - 0x%08x\n", mTcgDxeData
.BsCap
.NumberOfPCRBanks
));
2537 DEBUG ((EFI_D_INFO
, "Tcg2.ActivePcrBanks - 0x%08x\n", mTcgDxeData
.BsCap
.ActivePcrBanks
));
2539 if (mTcgDxeData
.BsCap
.TPMPresentFlag
) {
2541 // Setup the log area and copy event log from hob list to it
2543 Status
= SetupEventLog ();
2544 ASSERT_EFI_ERROR (Status
);
2547 // Measure handoff tables, Boot#### variables etc.
2549 Status
= EfiCreateEventReadyToBootEx (
2556 Status
= gBS
->CreateEventEx (
2561 &gEfiEventExitBootServicesGuid
,
2566 // Measure Exit Boot Service failed
2568 Status
= gBS
->CreateEventEx (
2571 OnExitBootServicesFailed
,
2573 &gEventExitBootServicesFailedGuid
,
2578 // Create event callback, because we need access variable on SecureBootPolicyVariable
2579 // We should use VariableWriteArch instead of VariableArch, because Variable driver
2580 // may update SecureBoot value based on last setting.
2582 EfiCreateProtocolNotifyEvent (&gEfiVariableWriteArchProtocolGuid
, TPL_CALLBACK
, MeasureSecureBootPolicy
, NULL
, &Registration
);
2586 // Install Tcg2Protocol
2588 Status
= InstallTcg2 ();
2589 DEBUG ((EFI_D_INFO
, "InstallTcg2 - %r\n", Status
));