2 This module implements Tcg2 Protocol.
4 Copyright (c) 2015 - 2016, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include <IndustryStandard/Acpi.h>
17 #include <IndustryStandard/PeImage.h>
18 #include <IndustryStandard/TcpaAcpi.h>
20 #include <Guid/GlobalVariable.h>
21 #include <Guid/HobList.h>
22 #include <Guid/TcgEventHob.h>
23 #include <Guid/EventGroup.h>
24 #include <Guid/EventExitBootServiceFailed.h>
25 #include <Guid/ImageAuthentication.h>
26 #include <Guid/TpmInstance.h>
28 #include <Protocol/DevicePath.h>
29 #include <Protocol/MpService.h>
30 #include <Protocol/VariableWrite.h>
31 #include <Protocol/Tcg2Protocol.h>
32 #include <Protocol/TrEEProtocol.h>
34 #include <Library/DebugLib.h>
35 #include <Library/BaseMemoryLib.h>
36 #include <Library/UefiRuntimeServicesTableLib.h>
37 #include <Library/UefiDriverEntryPoint.h>
38 #include <Library/HobLib.h>
39 #include <Library/UefiBootServicesTableLib.h>
40 #include <Library/BaseLib.h>
41 #include <Library/MemoryAllocationLib.h>
42 #include <Library/PrintLib.h>
43 #include <Library/Tpm2CommandLib.h>
44 #include <Library/PcdLib.h>
45 #include <Library/UefiLib.h>
46 #include <Library/Tpm2DeviceLib.h>
47 #include <Library/HashLib.h>
48 #include <Library/PerformanceLib.h>
49 #include <Library/ReportStatusCodeLib.h>
50 #include <Library/Tcg2PhysicalPresenceLib.h>
52 #define PERF_ID_TCG2_DXE 0x3120
59 #define TCG2_DEFAULT_MAX_COMMAND_SIZE 0x1000
60 #define TCG2_DEFAULT_MAX_RESPONSE_SIZE 0x1000
64 EFI_TCG2_EVENT_LOG_FORMAT LogFormat
;
65 } TCG2_EVENT_INFO_STRUCT
;
67 TCG2_EVENT_INFO_STRUCT mTcg2EventInfo
[] = {
68 {&gTcgEventEntryHobGuid
, EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
},
69 {&gTcgEvent2EntryHobGuid
, EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
},
72 #define TCG_EVENT_LOG_AREA_COUNT_MAX 2
75 EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
;
76 EFI_PHYSICAL_ADDRESS Lasa
;
80 BOOLEAN EventLogStarted
;
81 BOOLEAN EventLogTruncated
;
82 } TCG_EVENT_LOG_AREA_STRUCT
;
84 typedef struct _TCG_DXE_DATA
{
85 EFI_TCG2_BOOT_SERVICE_CAPABILITY BsCap
;
86 TCG_EVENT_LOG_AREA_STRUCT EventLogAreaStruct
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
87 BOOLEAN GetEventLogCalled
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
88 TCG_EVENT_LOG_AREA_STRUCT FinalEventLogAreaStruct
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
89 EFI_TCG2_FINAL_EVENTS_TABLE
*FinalEventsTable
[TCG_EVENT_LOG_AREA_COUNT_MAX
];
92 TCG_DXE_DATA mTcgDxeData
= {
94 sizeof (EFI_TCG2_BOOT_SERVICE_CAPABILITY
), // Size
95 { 1, 1 }, // StructureVersion
96 { 1, 1 }, // ProtocolVersion
97 EFI_TCG2_BOOT_HASH_ALG_SHA1
, // HashAlgorithmBitmap
98 EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
, // SupportedEventLogs
99 TRUE
, // TPMPresentFlag
100 TCG2_DEFAULT_MAX_COMMAND_SIZE
, // MaxCommandSize
101 TCG2_DEFAULT_MAX_RESPONSE_SIZE
, // MaxResponseSize
103 0, // NumberOfPCRBanks
108 UINTN mBootAttempts
= 0;
109 CHAR16 mBootVarName
[] = L
"BootOrder";
111 VARIABLE_TYPE mVariableType
[] = {
112 {EFI_SECURE_BOOT_MODE_NAME
, &gEfiGlobalVariableGuid
},
113 {EFI_PLATFORM_KEY_NAME
, &gEfiGlobalVariableGuid
},
114 {EFI_KEY_EXCHANGE_KEY_NAME
, &gEfiGlobalVariableGuid
},
115 {EFI_IMAGE_SECURITY_DATABASE
, &gEfiImageSecurityDatabaseGuid
},
116 {EFI_IMAGE_SECURITY_DATABASE1
, &gEfiImageSecurityDatabaseGuid
},
119 EFI_HANDLE mImageHandle
;
122 Measure PE image into TPM log based on the authenticode image hashing in
123 PE/COFF Specification 8.0 Appendix A.
125 Caution: This function may receive untrusted input.
126 PE/COFF image is external input, so this function will validate its data structure
127 within this image buffer before use.
129 @param[in] PCRIndex TPM PCR index
130 @param[in] ImageAddress Start address of image buffer.
131 @param[in] ImageSize Image size
132 @param[out] DigestList Digeest list of this image.
134 @retval EFI_SUCCESS Successfully measure image.
135 @retval EFI_OUT_OF_RESOURCES No enough resource to measure image.
136 @retval other error value
139 MeasurePeImageAndExtend (
141 IN EFI_PHYSICAL_ADDRESS ImageAddress
,
143 OUT TPML_DIGEST_VALUES
*DigestList
148 This function dump raw data.
151 @param Size raw data size
161 for (Index
= 0; Index
< Size
; Index
++) {
162 DEBUG ((EFI_D_INFO
, "%02x", (UINTN
)Data
[Index
]));
168 This function dump raw data with colume format.
171 @param Size raw data size
184 #define COLUME_SIZE (16 * 2)
186 Count
= Size
/ COLUME_SIZE
;
187 Left
= Size
% COLUME_SIZE
;
188 for (Index
= 0; Index
< Count
; Index
++) {
189 DEBUG ((EFI_D_INFO
, "%04x: ", Index
* COLUME_SIZE
));
190 InternalDumpData (Data
+ Index
* COLUME_SIZE
, COLUME_SIZE
);
191 DEBUG ((EFI_D_INFO
, "\n"));
195 DEBUG ((EFI_D_INFO
, "%04x: ", Index
* COLUME_SIZE
));
196 InternalDumpData (Data
+ Index
* COLUME_SIZE
, Left
);
197 DEBUG ((EFI_D_INFO
, "\n"));
202 Check if buffer is all zero.
204 @param[in] Buffer Buffer to be checked.
205 @param[in] BufferSize Size of buffer to be checked.
207 @retval TRUE Buffer is all zero.
208 @retval FALSE Buffer is not all zero.
220 for (Index
= 0; Index
< BufferSize
; Index
++) {
221 if (BufferData
[Index
] != 0) {
229 Get All processors EFI_CPU_LOCATION in system. LocationBuf is allocated inside the function
230 Caller is responsible to free LocationBuf.
232 @param[out] LocationBuf Returns Processor Location Buffer.
233 @param[out] Num Returns processor number.
235 @retval EFI_SUCCESS Operation completed successfully.
236 @retval EFI_UNSUPPORTED MpService protocol not found.
240 GetProcessorsCpuLocation (
241 OUT EFI_CPU_PHYSICAL_LOCATION
**LocationBuf
,
246 EFI_MP_SERVICES_PROTOCOL
*MpProtocol
;
248 UINTN EnabledProcessorNum
;
249 EFI_PROCESSOR_INFORMATION ProcessorInfo
;
250 EFI_CPU_PHYSICAL_LOCATION
*ProcessorLocBuf
;
253 Status
= gBS
->LocateProtocol (&gEfiMpServiceProtocolGuid
, NULL
, (VOID
**) &MpProtocol
);
254 if (EFI_ERROR (Status
)) {
256 // MP protocol is not installed
258 return EFI_UNSUPPORTED
;
261 Status
= MpProtocol
->GetNumberOfProcessors(
266 if (EFI_ERROR(Status
)){
270 Status
= gBS
->AllocatePool(
272 sizeof(EFI_CPU_PHYSICAL_LOCATION
) * ProcessorNum
,
273 (VOID
**) &ProcessorLocBuf
275 if (EFI_ERROR(Status
)){
280 // Get each processor Location info
282 for (Index
= 0; Index
< ProcessorNum
; Index
++) {
283 Status
= MpProtocol
->GetProcessorInfo(
288 if (EFI_ERROR(Status
)){
289 FreePool(ProcessorLocBuf
);
294 // Get all Processor Location info & measure
297 &ProcessorLocBuf
[Index
],
298 &ProcessorInfo
.Location
,
299 sizeof(EFI_CPU_PHYSICAL_LOCATION
)
303 *LocationBuf
= ProcessorLocBuf
;
310 The EFI_TCG2_PROTOCOL GetCapability function call provides protocol
311 capability information and state information.
313 @param[in] This Indicates the calling context
314 @param[in, out] ProtocolCapability The caller allocates memory for a EFI_TCG2_BOOT_SERVICE_CAPABILITY
315 structure and sets the size field to the size of the structure allocated.
316 The callee fills in the fields with the EFI protocol capability information
317 and the current EFI TCG2 state information up to the number of fields which
318 fit within the size of the structure passed in.
320 @retval EFI_SUCCESS Operation completed successfully.
321 @retval EFI_DEVICE_ERROR The command was unsuccessful.
322 The ProtocolCapability variable will not be populated.
323 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
324 The ProtocolCapability variable will not be populated.
325 @retval EFI_BUFFER_TOO_SMALL The ProtocolCapability variable is too small to hold the full response.
326 It will be partially populated (required Size field will be set).
331 IN EFI_TCG2_PROTOCOL
*This
,
332 IN OUT EFI_TCG2_BOOT_SERVICE_CAPABILITY
*ProtocolCapability
335 DEBUG ((EFI_D_INFO
, "Tcg2GetCapability ...\n"));
337 if ((This
== NULL
) || (ProtocolCapability
== NULL
)) {
338 return EFI_INVALID_PARAMETER
;
341 DEBUG ((EFI_D_INFO
, "Size - 0x%x\n", ProtocolCapability
->Size
));
342 DEBUG ((EFI_D_INFO
, " 1.1 - 0x%x, 1.0 - 0x%x\n", sizeof(EFI_TCG2_BOOT_SERVICE_CAPABILITY
), sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
)));
344 if (ProtocolCapability
->Size
< mTcgDxeData
.BsCap
.Size
) {
346 // Handle the case that firmware support 1.1 but OS only support 1.0.
348 if ((mTcgDxeData
.BsCap
.ProtocolVersion
.Major
> 0x01) ||
349 ((mTcgDxeData
.BsCap
.ProtocolVersion
.Major
== 0x01) && ((mTcgDxeData
.BsCap
.ProtocolVersion
.Minor
> 0x00)))) {
350 if (ProtocolCapability
->Size
>= sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
)) {
351 CopyMem (ProtocolCapability
, &mTcgDxeData
.BsCap
, sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
));
352 ProtocolCapability
->Size
= sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
);
353 ProtocolCapability
->StructureVersion
.Major
= 1;
354 ProtocolCapability
->StructureVersion
.Minor
= 0;
355 ProtocolCapability
->ProtocolVersion
.Major
= 1;
356 ProtocolCapability
->ProtocolVersion
.Minor
= 0;
357 DEBUG ((EFI_D_ERROR
, "TreeGetCapability (Compatible) - %r\n", EFI_SUCCESS
));
361 ProtocolCapability
->Size
= mTcgDxeData
.BsCap
.Size
;
362 return EFI_BUFFER_TOO_SMALL
;
365 CopyMem (ProtocolCapability
, &mTcgDxeData
.BsCap
, mTcgDxeData
.BsCap
.Size
);
366 DEBUG ((EFI_D_INFO
, "Tcg2GetCapability - %r\n", EFI_SUCCESS
));
371 This function dump PCR event.
373 @param[in] EventHdr TCG PCR event structure.
377 IN TCG_PCR_EVENT_HDR
*EventHdr
382 DEBUG ((EFI_D_INFO
, " Event:\n"));
383 DEBUG ((EFI_D_INFO
, " PCRIndex - %d\n", EventHdr
->PCRIndex
));
384 DEBUG ((EFI_D_INFO
, " EventType - 0x%08x\n", EventHdr
->EventType
));
385 DEBUG ((EFI_D_INFO
, " Digest - "));
386 for (Index
= 0; Index
< sizeof(TCG_DIGEST
); Index
++) {
387 DEBUG ((EFI_D_INFO
, "%02x ", EventHdr
->Digest
.digest
[Index
]));
389 DEBUG ((EFI_D_INFO
, "\n"));
390 DEBUG ((EFI_D_INFO
, " EventSize - 0x%08x\n", EventHdr
->EventSize
));
391 InternalDumpHex ((UINT8
*)(EventHdr
+ 1), EventHdr
->EventSize
);
395 This function dump TCG_EfiSpecIDEventStruct.
397 @param[in] TcgEfiSpecIdEventStruct A pointer to TCG_EfiSpecIDEventStruct.
400 DumpTcgEfiSpecIdEventStruct (
401 IN TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
404 TCG_EfiSpecIdEventAlgorithmSize
*DigestSize
;
406 UINT8
*VendorInfoSize
;
408 UINT32 NumberOfAlgorithms
;
410 DEBUG ((EFI_D_INFO
, " TCG_EfiSpecIDEventStruct:\n"));
411 DEBUG ((EFI_D_INFO
, " signature - '"));
412 for (Index
= 0; Index
< sizeof(TcgEfiSpecIdEventStruct
->signature
); Index
++) {
413 DEBUG ((EFI_D_INFO
, "%c", TcgEfiSpecIdEventStruct
->signature
[Index
]));
415 DEBUG ((EFI_D_INFO
, "'\n"));
416 DEBUG ((EFI_D_INFO
, " platformClass - 0x%08x\n", TcgEfiSpecIdEventStruct
->platformClass
));
417 DEBUG ((EFI_D_INFO
, " specVersion - %d.%d%d\n", TcgEfiSpecIdEventStruct
->specVersionMajor
, TcgEfiSpecIdEventStruct
->specVersionMinor
, TcgEfiSpecIdEventStruct
->specErrata
));
418 DEBUG ((EFI_D_INFO
, " uintnSize - 0x%02x\n", TcgEfiSpecIdEventStruct
->uintnSize
));
420 CopyMem (&NumberOfAlgorithms
, TcgEfiSpecIdEventStruct
+ 1, sizeof(NumberOfAlgorithms
));
421 DEBUG ((EFI_D_INFO
, " NumberOfAlgorithms - 0x%08x\n", NumberOfAlgorithms
));
423 DigestSize
= (TCG_EfiSpecIdEventAlgorithmSize
*)((UINT8
*)TcgEfiSpecIdEventStruct
+ sizeof(*TcgEfiSpecIdEventStruct
) + sizeof(NumberOfAlgorithms
));
424 for (Index
= 0; Index
< NumberOfAlgorithms
; Index
++) {
425 DEBUG ((EFI_D_INFO
, " digest(%d)\n", Index
));
426 DEBUG ((EFI_D_INFO
, " algorithmId - 0x%04x\n", DigestSize
[Index
].algorithmId
));
427 DEBUG ((EFI_D_INFO
, " digestSize - 0x%04x\n", DigestSize
[Index
].digestSize
));
429 VendorInfoSize
= (UINT8
*)&DigestSize
[NumberOfAlgorithms
];
430 DEBUG ((EFI_D_INFO
, " VendorInfoSize - 0x%02x\n", *VendorInfoSize
));
431 VendorInfo
= VendorInfoSize
+ 1;
432 DEBUG ((EFI_D_INFO
, " VendorInfo - "));
433 for (Index
= 0; Index
< *VendorInfoSize
; Index
++) {
434 DEBUG ((EFI_D_INFO
, "%02x ", VendorInfo
[Index
]));
436 DEBUG ((EFI_D_INFO
, "\n"));
440 This function get size of TCG_EfiSpecIDEventStruct.
442 @param[in] TcgEfiSpecIdEventStruct A pointer to TCG_EfiSpecIDEventStruct.
445 GetTcgEfiSpecIdEventStructSize (
446 IN TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
449 TCG_EfiSpecIdEventAlgorithmSize
*DigestSize
;
450 UINT8
*VendorInfoSize
;
451 UINT32 NumberOfAlgorithms
;
453 CopyMem (&NumberOfAlgorithms
, TcgEfiSpecIdEventStruct
+ 1, sizeof(NumberOfAlgorithms
));
455 DigestSize
= (TCG_EfiSpecIdEventAlgorithmSize
*)((UINT8
*)TcgEfiSpecIdEventStruct
+ sizeof(*TcgEfiSpecIdEventStruct
) + sizeof(NumberOfAlgorithms
));
456 VendorInfoSize
= (UINT8
*)&DigestSize
[NumberOfAlgorithms
];
457 return sizeof(TCG_EfiSpecIDEventStruct
) + sizeof(UINT32
) + (NumberOfAlgorithms
* sizeof(TCG_EfiSpecIdEventAlgorithmSize
)) + sizeof(UINT8
) + (*VendorInfoSize
);
461 This function dump PCR event 2.
463 @param[in] TcgPcrEvent2 TCG PCR event 2 structure.
467 IN TCG_PCR_EVENT2
*TcgPcrEvent2
473 TPMI_ALG_HASH HashAlgo
;
479 DEBUG ((EFI_D_INFO
, " Event:\n"));
480 DEBUG ((EFI_D_INFO
, " PCRIndex - %d\n", TcgPcrEvent2
->PCRIndex
));
481 DEBUG ((EFI_D_INFO
, " EventType - 0x%08x\n", TcgPcrEvent2
->EventType
));
483 DEBUG ((EFI_D_INFO
, " DigestCount: 0x%08x\n", TcgPcrEvent2
->Digest
.count
));
485 DigestCount
= TcgPcrEvent2
->Digest
.count
;
486 HashAlgo
= TcgPcrEvent2
->Digest
.digests
[0].hashAlg
;
487 DigestBuffer
= (UINT8
*)&TcgPcrEvent2
->Digest
.digests
[0].digest
;
488 for (DigestIndex
= 0; DigestIndex
< DigestCount
; DigestIndex
++) {
489 DEBUG ((EFI_D_INFO
, " HashAlgo : 0x%04x\n", HashAlgo
));
490 DEBUG ((EFI_D_INFO
, " Digest(%d): ", DigestIndex
));
491 DigestSize
= GetHashSizeFromAlgo (HashAlgo
);
492 for (Index
= 0; Index
< DigestSize
; Index
++) {
493 DEBUG ((EFI_D_INFO
, "%02x ", DigestBuffer
[Index
]));
495 DEBUG ((EFI_D_INFO
, "\n"));
499 CopyMem (&HashAlgo
, DigestBuffer
+ DigestSize
, sizeof(TPMI_ALG_HASH
));
500 DigestBuffer
= DigestBuffer
+ DigestSize
+ sizeof(TPMI_ALG_HASH
);
502 DEBUG ((EFI_D_INFO
, "\n"));
503 DigestBuffer
= DigestBuffer
- sizeof(TPMI_ALG_HASH
);
505 CopyMem (&EventSize
, DigestBuffer
, sizeof(TcgPcrEvent2
->EventSize
));
506 DEBUG ((EFI_D_INFO
, " EventSize - 0x%08x\n", EventSize
));
507 EventBuffer
= DigestBuffer
+ sizeof(TcgPcrEvent2
->EventSize
);
508 InternalDumpHex (EventBuffer
, EventSize
);
512 This function returns size of TCG PCR event 2.
514 @param[in] TcgPcrEvent2 TCG PCR event 2 structure.
516 @return size of TCG PCR event 2.
520 IN TCG_PCR_EVENT2
*TcgPcrEvent2
525 TPMI_ALG_HASH HashAlgo
;
531 DigestCount
= TcgPcrEvent2
->Digest
.count
;
532 HashAlgo
= TcgPcrEvent2
->Digest
.digests
[0].hashAlg
;
533 DigestBuffer
= (UINT8
*)&TcgPcrEvent2
->Digest
.digests
[0].digest
;
534 for (DigestIndex
= 0; DigestIndex
< DigestCount
; DigestIndex
++) {
535 DigestSize
= GetHashSizeFromAlgo (HashAlgo
);
539 CopyMem (&HashAlgo
, DigestBuffer
+ DigestSize
, sizeof(TPMI_ALG_HASH
));
540 DigestBuffer
= DigestBuffer
+ DigestSize
+ sizeof(TPMI_ALG_HASH
);
542 DigestBuffer
= DigestBuffer
- sizeof(TPMI_ALG_HASH
);
544 CopyMem (&EventSize
, DigestBuffer
, sizeof(TcgPcrEvent2
->EventSize
));
545 EventBuffer
= DigestBuffer
+ sizeof(TcgPcrEvent2
->EventSize
);
547 return (UINTN
)EventBuffer
+ EventSize
- (UINTN
)TcgPcrEvent2
;
551 This function dump event log.
553 @param[in] EventLogFormat The type of the event log for which the information is requested.
554 @param[in] EventLogLocation A pointer to the memory address of the event log.
555 @param[in] EventLogLastEntry If the Event Log contains more than one entry, this is a pointer to the
556 address of the start of the last entry in the event log in memory.
557 @param[in] FinalEventsTable A pointer to the memory address of the final event table.
561 IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
,
562 IN EFI_PHYSICAL_ADDRESS EventLogLocation
,
563 IN EFI_PHYSICAL_ADDRESS EventLogLastEntry
,
564 IN EFI_TCG2_FINAL_EVENTS_TABLE
*FinalEventsTable
567 TCG_PCR_EVENT_HDR
*EventHdr
;
568 TCG_PCR_EVENT2
*TcgPcrEvent2
;
569 TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
;
570 UINTN NumberOfEvents
;
572 DEBUG ((EFI_D_INFO
, "EventLogFormat: (0x%x)\n", EventLogFormat
));
574 switch (EventLogFormat
) {
575 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
:
576 EventHdr
= (TCG_PCR_EVENT_HDR
*)(UINTN
)EventLogLocation
;
577 while ((UINTN
)EventHdr
<= EventLogLastEntry
) {
578 DumpEvent (EventHdr
);
579 EventHdr
= (TCG_PCR_EVENT_HDR
*)((UINTN
)EventHdr
+ sizeof(TCG_PCR_EVENT_HDR
) + EventHdr
->EventSize
);
581 if (FinalEventsTable
== NULL
) {
582 DEBUG ((EFI_D_INFO
, "FinalEventsTable: NOT FOUND\n"));
584 DEBUG ((EFI_D_INFO
, "FinalEventsTable: (0x%x)\n", FinalEventsTable
));
585 DEBUG ((EFI_D_INFO
, " Version: (0x%x)\n", FinalEventsTable
->Version
));
586 DEBUG ((EFI_D_INFO
, " NumberOfEvents: (0x%x)\n", FinalEventsTable
->NumberOfEvents
));
588 EventHdr
= (TCG_PCR_EVENT_HDR
*)(UINTN
)(FinalEventsTable
+ 1);
589 for (NumberOfEvents
= 0; NumberOfEvents
< FinalEventsTable
->NumberOfEvents
; NumberOfEvents
++) {
590 DumpEvent (EventHdr
);
591 EventHdr
= (TCG_PCR_EVENT_HDR
*)((UINTN
)EventHdr
+ sizeof(TCG_PCR_EVENT_HDR
) + EventHdr
->EventSize
);
595 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
:
599 EventHdr
= (TCG_PCR_EVENT_HDR
*)(UINTN
)EventLogLocation
;
600 DumpEvent (EventHdr
);
602 TcgEfiSpecIdEventStruct
= (TCG_EfiSpecIDEventStruct
*)(EventHdr
+ 1);
603 DumpTcgEfiSpecIdEventStruct (TcgEfiSpecIdEventStruct
);
605 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)((UINTN
)TcgEfiSpecIdEventStruct
+ GetTcgEfiSpecIdEventStructSize (TcgEfiSpecIdEventStruct
));
606 while ((UINTN
)TcgPcrEvent2
<= EventLogLastEntry
) {
607 DumpEvent2 (TcgPcrEvent2
);
608 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)((UINTN
)TcgPcrEvent2
+ GetPcrEvent2Size (TcgPcrEvent2
));
611 if (FinalEventsTable
== NULL
) {
612 DEBUG ((EFI_D_INFO
, "FinalEventsTable: NOT FOUND\n"));
614 DEBUG ((EFI_D_INFO
, "FinalEventsTable: (0x%x)\n", FinalEventsTable
));
615 DEBUG ((EFI_D_INFO
, " Version: (0x%x)\n", FinalEventsTable
->Version
));
616 DEBUG ((EFI_D_INFO
, " NumberOfEvents: (0x%x)\n", FinalEventsTable
->NumberOfEvents
));
618 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)(UINTN
)(FinalEventsTable
+ 1);
619 for (NumberOfEvents
= 0; NumberOfEvents
< FinalEventsTable
->NumberOfEvents
; NumberOfEvents
++) {
620 DumpEvent2 (TcgPcrEvent2
);
621 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)((UINTN
)TcgPcrEvent2
+ GetPcrEvent2Size (TcgPcrEvent2
));
631 The EFI_TCG2_PROTOCOL Get Event Log function call allows a caller to
632 retrieve the address of a given event log and its last entry.
634 @param[in] This Indicates the calling context
635 @param[in] EventLogFormat The type of the event log for which the information is requested.
636 @param[out] EventLogLocation A pointer to the memory address of the event log.
637 @param[out] EventLogLastEntry If the Event Log contains more than one entry, this is a pointer to the
638 address of the start of the last entry in the event log in memory.
639 @param[out] EventLogTruncated If the Event Log is missing at least one entry because an event would
640 have exceeded the area allocated for events, this value is set to TRUE.
641 Otherwise, the value will be FALSE and the Event Log will be complete.
643 @retval EFI_SUCCESS Operation completed successfully.
644 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect
645 (e.g. asking for an event log whose format is not supported).
650 IN EFI_TCG2_PROTOCOL
*This
,
651 IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
,
652 OUT EFI_PHYSICAL_ADDRESS
*EventLogLocation
,
653 OUT EFI_PHYSICAL_ADDRESS
*EventLogLastEntry
,
654 OUT BOOLEAN
*EventLogTruncated
659 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog ... (0x%x)\n", EventLogFormat
));
662 return EFI_INVALID_PARAMETER
;
665 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
666 if (EventLogFormat
== mTcg2EventInfo
[Index
].LogFormat
) {
671 if (Index
== sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0])) {
672 return EFI_INVALID_PARAMETER
;
675 if ((mTcg2EventInfo
[Index
].LogFormat
& mTcgDxeData
.BsCap
.SupportedEventLogs
) == 0) {
676 return EFI_INVALID_PARAMETER
;
679 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
680 if (EventLogLocation
!= NULL
) {
681 *EventLogLocation
= 0;
683 if (EventLogLastEntry
!= NULL
) {
684 *EventLogLastEntry
= 0;
686 if (EventLogTruncated
!= NULL
) {
687 *EventLogTruncated
= FALSE
;
692 if (EventLogLocation
!= NULL
) {
693 *EventLogLocation
= mTcgDxeData
.EventLogAreaStruct
[Index
].Lasa
;
694 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog (EventLogLocation - %x)\n", *EventLogLocation
));
697 if (EventLogLastEntry
!= NULL
) {
698 if (!mTcgDxeData
.EventLogAreaStruct
[Index
].EventLogStarted
) {
699 *EventLogLastEntry
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)0;
701 *EventLogLastEntry
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)mTcgDxeData
.EventLogAreaStruct
[Index
].LastEvent
;
703 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog (EventLogLastEntry - %x)\n", *EventLogLastEntry
));
706 if (EventLogTruncated
!= NULL
) {
707 *EventLogTruncated
= mTcgDxeData
.EventLogAreaStruct
[Index
].EventLogTruncated
;
708 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog (EventLogTruncated - %x)\n", *EventLogTruncated
));
711 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog - %r\n", EFI_SUCCESS
));
713 // Dump Event Log for debug purpose
714 if ((EventLogLocation
!= NULL
) && (EventLogLastEntry
!= NULL
)) {
715 DumpEventLog (EventLogFormat
, *EventLogLocation
, *EventLogLastEntry
, mTcgDxeData
.FinalEventsTable
[Index
]);
719 // All events generated after the invocation of EFI_TCG2_GET_EVENT_LOG SHALL be stored
720 // in an instance of an EFI_CONFIGURATION_TABLE named by the VendorGuid of EFI_TCG2_FINAL_EVENTS_TABLE_GUID.
722 mTcgDxeData
.GetEventLogCalled
[Index
] = TRUE
;
728 Add a new entry to the Event Log.
730 @param[in, out] EventLogPtr Pointer to the Event Log data.
731 @param[in, out] LogSize Size of the Event Log.
732 @param[in] MaxSize Maximum size of the Event Log.
733 @param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR/TCG_PCR_EVENT_EX data structure.
734 @param[in] NewEventHdrSize New event header size.
735 @param[in] NewEventData Pointer to the new event data.
736 @param[in] NewEventSize New event data size.
738 @retval EFI_SUCCESS The new event log entry was added.
739 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
744 IN OUT UINT8
**EventLogPtr
,
745 IN OUT UINTN
*LogSize
,
747 IN VOID
*NewEventHdr
,
748 IN UINT32 NewEventHdrSize
,
749 IN UINT8
*NewEventData
,
750 IN UINT32 NewEventSize
755 if (NewEventSize
> MAX_ADDRESS
- NewEventHdrSize
) {
756 return EFI_OUT_OF_RESOURCES
;
759 NewLogSize
= NewEventHdrSize
+ NewEventSize
;
761 if (NewLogSize
> MAX_ADDRESS
- *LogSize
) {
762 return EFI_OUT_OF_RESOURCES
;
765 if (NewLogSize
+ *LogSize
> MaxSize
) {
766 DEBUG ((EFI_D_INFO
, " MaxSize - 0x%x\n", MaxSize
));
767 DEBUG ((EFI_D_INFO
, " NewLogSize - 0x%x\n", NewLogSize
));
768 DEBUG ((EFI_D_INFO
, " LogSize - 0x%x\n", *LogSize
));
769 DEBUG ((EFI_D_INFO
, "TcgCommLogEvent - %r\n", EFI_OUT_OF_RESOURCES
));
770 return EFI_OUT_OF_RESOURCES
;
773 *EventLogPtr
+= *LogSize
;
774 *LogSize
+= NewLogSize
;
775 CopyMem (*EventLogPtr
, NewEventHdr
, NewEventHdrSize
);
777 *EventLogPtr
+ NewEventHdrSize
,
785 Add a new entry to the Event Log.
787 @param[in] EventLogFormat The type of the event log for which the information is requested.
788 @param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR/TCG_PCR_EVENT_EX data structure.
789 @param[in] NewEventHdrSize New event header size.
790 @param[in] NewEventData Pointer to the new event data.
791 @param[in] NewEventSize New event data size.
793 @retval EFI_SUCCESS The new event log entry was added.
794 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
799 IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
,
800 IN VOID
*NewEventHdr
,
801 IN UINT32 NewEventHdrSize
,
802 IN UINT8
*NewEventData
,
803 IN UINT32 NewEventSize
808 TCG_EVENT_LOG_AREA_STRUCT
*EventLogAreaStruct
;
810 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
811 if (EventLogFormat
== mTcg2EventInfo
[Index
].LogFormat
) {
816 if (Index
== sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0])) {
817 return EFI_INVALID_PARAMETER
;
821 // Record to normal event log
823 EventLogAreaStruct
= &mTcgDxeData
.EventLogAreaStruct
[Index
];
825 if (EventLogAreaStruct
->EventLogTruncated
) {
826 return EFI_VOLUME_FULL
;
829 EventLogAreaStruct
->LastEvent
= (UINT8
*)(UINTN
)EventLogAreaStruct
->Lasa
;
830 Status
= TcgCommLogEvent (
831 &EventLogAreaStruct
->LastEvent
,
832 &EventLogAreaStruct
->EventLogSize
,
833 (UINTN
)EventLogAreaStruct
->Laml
,
840 if (Status
== EFI_OUT_OF_RESOURCES
) {
841 EventLogAreaStruct
->EventLogTruncated
= TRUE
;
842 return EFI_VOLUME_FULL
;
843 } else if (Status
== EFI_SUCCESS
) {
844 EventLogAreaStruct
->EventLogStarted
= TRUE
;
848 // If GetEventLog is called, record to FinalEventsTable, too.
850 if (mTcgDxeData
.GetEventLogCalled
[Index
]) {
851 if (mTcgDxeData
.FinalEventsTable
[Index
] == NULL
) {
853 // no need for FinalEventsTable
857 EventLogAreaStruct
= &mTcgDxeData
.FinalEventLogAreaStruct
[Index
];
859 if (EventLogAreaStruct
->EventLogTruncated
) {
860 return EFI_VOLUME_FULL
;
863 EventLogAreaStruct
->LastEvent
= (UINT8
*)(UINTN
)EventLogAreaStruct
->Lasa
;
864 Status
= TcgCommLogEvent (
865 &EventLogAreaStruct
->LastEvent
,
866 &EventLogAreaStruct
->EventLogSize
,
867 (UINTN
)EventLogAreaStruct
->Laml
,
873 if (Status
== EFI_OUT_OF_RESOURCES
) {
874 EventLogAreaStruct
->EventLogTruncated
= TRUE
;
875 return EFI_VOLUME_FULL
;
876 } else if (Status
== EFI_SUCCESS
) {
877 EventLogAreaStruct
->EventLogStarted
= TRUE
;
879 // Increase the NumberOfEvents in FinalEventsTable
881 (mTcgDxeData
.FinalEventsTable
[Index
])->NumberOfEvents
++;
882 DEBUG ((EFI_D_INFO
, "FinalEventsTable->NumberOfEvents - 0x%x\n", (mTcgDxeData
.FinalEventsTable
[Index
])->NumberOfEvents
));
883 DEBUG ((EFI_D_INFO
, " Size - 0x%x\n", (UINTN
)EventLogAreaStruct
->LastEvent
- (UINTN
)mTcgDxeData
.FinalEventsTable
[Index
]));
891 This function get digest from digest list.
893 @param HashAlg digest algorithm
894 @param DigestList digest list
897 @retval EFI_SUCCESS Sha1Digest is found and returned.
898 @retval EFI_NOT_FOUND Sha1Digest is not found.
901 Tpm2GetDigestFromDigestList (
902 IN TPMI_ALG_HASH HashAlg
,
903 IN TPML_DIGEST_VALUES
*DigestList
,
910 DigestSize
= GetHashSizeFromAlgo (HashAlg
);
911 for (Index
= 0; Index
< DigestList
->count
; Index
++) {
912 if (DigestList
->digests
[Index
].hashAlg
== HashAlg
) {
915 &DigestList
->digests
[Index
].digest
,
922 return EFI_NOT_FOUND
;
926 Get TPML_DIGEST_VALUES data size.
928 @param[in] DigestList TPML_DIGEST_VALUES data.
930 @return TPML_DIGEST_VALUES data size.
934 IN TPML_DIGEST_VALUES
*DigestList
941 TotalSize
= sizeof(DigestList
->count
);
942 for (Index
= 0; Index
< DigestList
->count
; Index
++) {
943 DigestSize
= GetHashSizeFromAlgo (DigestList
->digests
[Index
].hashAlg
);
944 TotalSize
+= sizeof(DigestList
->digests
[Index
].hashAlg
) + DigestSize
;
951 Get TPML_DIGEST_VALUES compact binary buffer size.
953 @param[in] DigestListBin TPML_DIGEST_VALUES compact binary buffer.
955 @return TPML_DIGEST_VALUES compact binary buffer size.
958 GetDigestListBinSize (
959 IN VOID
*DigestListBin
966 TPMI_ALG_HASH HashAlg
;
968 Count
= ReadUnaligned32 (DigestListBin
);
969 TotalSize
= sizeof(Count
);
970 DigestListBin
= (UINT8
*)DigestListBin
+ sizeof(Count
);
971 for (Index
= 0; Index
< Count
; Index
++) {
972 HashAlg
= ReadUnaligned16 (DigestListBin
);
973 TotalSize
+= sizeof(HashAlg
);
974 DigestListBin
= (UINT8
*)DigestListBin
+ sizeof(HashAlg
);
976 DigestSize
= GetHashSizeFromAlgo (HashAlg
);
977 TotalSize
+= DigestSize
;
978 DigestListBin
= (UINT8
*)DigestListBin
+ DigestSize
;
985 Return if hash alg is supported in TPM PCR bank.
987 @param HashAlg Hash algorithm to be checked.
989 @retval TRUE Hash algorithm is supported.
990 @retval FALSE Hash algorithm is not supported.
993 IsHashAlgSupportedInPcrBank (
994 IN TPMI_ALG_HASH HashAlg
999 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) != 0) {
1003 case TPM_ALG_SHA256
:
1004 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA256
) != 0) {
1008 case TPM_ALG_SHA384
:
1009 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA384
) != 0) {
1013 case TPM_ALG_SHA512
:
1014 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA512
) != 0) {
1018 case TPM_ALG_SM3_256
:
1019 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SM3_256
) != 0) {
1029 Copy TPML_DIGEST_VALUES into a buffer
1031 @param[in,out] Buffer Buffer to hold TPML_DIGEST_VALUES.
1032 @param[in] DigestList TPML_DIGEST_VALUES to be copied.
1034 @return The end of buffer to hold TPML_DIGEST_VALUES.
1037 CopyDigestListToBuffer (
1038 IN OUT VOID
*Buffer
,
1039 IN TPML_DIGEST_VALUES
*DigestList
1045 CopyMem (Buffer
, &DigestList
->count
, sizeof(DigestList
->count
));
1046 Buffer
= (UINT8
*)Buffer
+ sizeof(DigestList
->count
);
1047 for (Index
= 0; Index
< DigestList
->count
; Index
++) {
1048 if (!IsHashAlgSupportedInPcrBank (DigestList
->digests
[Index
].hashAlg
)) {
1049 DEBUG ((EFI_D_ERROR
, "WARNING: TPM2 Event log has HashAlg unsupported by PCR bank (0x%x)\n", DigestList
->digests
[Index
].hashAlg
));
1052 CopyMem (Buffer
, &DigestList
->digests
[Index
].hashAlg
, sizeof(DigestList
->digests
[Index
].hashAlg
));
1053 Buffer
= (UINT8
*)Buffer
+ sizeof(DigestList
->digests
[Index
].hashAlg
);
1054 DigestSize
= GetHashSizeFromAlgo (DigestList
->digests
[Index
].hashAlg
);
1055 CopyMem (Buffer
, &DigestList
->digests
[Index
].digest
, DigestSize
);
1056 Buffer
= (UINT8
*)Buffer
+ DigestSize
;
1063 Add a new entry to the Event Log.
1065 @param[in] DigestList A list of digest.
1066 @param[in,out] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
1067 @param[in] NewEventData Pointer to the new event data.
1069 @retval EFI_SUCCESS The new event log entry was added.
1070 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
1073 TcgDxeLogHashEvent (
1074 IN TPML_DIGEST_VALUES
*DigestList
,
1075 IN OUT TCG_PCR_EVENT_HDR
*NewEventHdr
,
1076 IN UINT8
*NewEventData
1082 EFI_STATUS RetStatus
;
1083 TCG_PCR_EVENT2 TcgPcrEvent2
;
1084 UINT8
*DigestBuffer
;
1086 DEBUG ((EFI_D_INFO
, "SupportedEventLogs - 0x%08x\n", mTcgDxeData
.BsCap
.SupportedEventLogs
));
1088 RetStatus
= EFI_SUCCESS
;
1089 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1090 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1091 DEBUG ((EFI_D_INFO
, " LogFormat - 0x%08x\n", mTcg2EventInfo
[Index
].LogFormat
));
1092 switch (mTcg2EventInfo
[Index
].LogFormat
) {
1093 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
:
1094 Status
= Tpm2GetDigestFromDigestList (TPM_ALG_SHA1
, DigestList
, &NewEventHdr
->Digest
);
1095 if (!EFI_ERROR (Status
)) {
1097 // Enter critical region
1099 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
1100 Status
= TcgDxeLogEvent (
1101 mTcg2EventInfo
[Index
].LogFormat
,
1103 sizeof(TCG_PCR_EVENT_HDR
),
1105 NewEventHdr
->EventSize
1107 if (Status
!= EFI_SUCCESS
) {
1110 gBS
->RestoreTPL (OldTpl
);
1112 // Exit critical region
1116 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
:
1117 ZeroMem (&TcgPcrEvent2
, sizeof(TcgPcrEvent2
));
1118 TcgPcrEvent2
.PCRIndex
= NewEventHdr
->PCRIndex
;
1119 TcgPcrEvent2
.EventType
= NewEventHdr
->EventType
;
1120 DigestBuffer
= (UINT8
*)&TcgPcrEvent2
.Digest
;
1121 DigestBuffer
= CopyDigestListToBuffer (DigestBuffer
, DigestList
);
1122 CopyMem (DigestBuffer
, &NewEventHdr
->EventSize
, sizeof(NewEventHdr
->EventSize
));
1123 DigestBuffer
= DigestBuffer
+ sizeof(NewEventHdr
->EventSize
);
1126 // Enter critical region
1128 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
1129 Status
= TcgDxeLogEvent (
1130 mTcg2EventInfo
[Index
].LogFormat
,
1132 sizeof(TcgPcrEvent2
.PCRIndex
) + sizeof(TcgPcrEvent2
.EventType
) + GetDigestListSize (DigestList
) + sizeof(TcgPcrEvent2
.EventSize
),
1134 NewEventHdr
->EventSize
1136 if (Status
!= EFI_SUCCESS
) {
1139 gBS
->RestoreTPL (OldTpl
);
1141 // Exit critical region
1152 Do a hash operation on a data buffer, extend a specific TPM PCR with the hash result,
1153 and add an entry to the Event Log.
1155 @param[in] Flags Bitmap providing additional information.
1156 @param[in] HashData Physical address of the start of the data buffer
1157 to be hashed, extended, and logged.
1158 @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData
1159 @param[in, out] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
1160 @param[in] NewEventData Pointer to the new event data.
1162 @retval EFI_SUCCESS Operation completed successfully.
1163 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
1164 @retval EFI_DEVICE_ERROR The command was unsuccessful.
1168 TcgDxeHashLogExtendEvent (
1171 IN UINT64 HashDataLen
,
1172 IN OUT TCG_PCR_EVENT_HDR
*NewEventHdr
,
1173 IN UINT8
*NewEventData
1177 TPML_DIGEST_VALUES DigestList
;
1179 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
1180 return EFI_DEVICE_ERROR
;
1183 Status
= HashAndExtend (
1184 NewEventHdr
->PCRIndex
,
1189 if (!EFI_ERROR (Status
)) {
1190 if ((Flags
& EFI_TCG2_EXTEND_ONLY
) == 0) {
1191 Status
= TcgDxeLogHashEvent (&DigestList
, NewEventHdr
, NewEventData
);
1195 if (Status
== EFI_DEVICE_ERROR
) {
1196 DEBUG ((EFI_D_ERROR
, "TcgDxeHashLogExtendEvent - %r. Disable TPM.\n", Status
));
1197 mTcgDxeData
.BsCap
.TPMPresentFlag
= FALSE
;
1198 REPORT_STATUS_CODE (
1199 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
1200 (PcdGet32 (PcdStatusCodeSubClassTpmDevice
) | EFI_P_EC_INTERFACE_ERROR
)
1208 The EFI_TCG2_PROTOCOL HashLogExtendEvent function call provides callers with
1209 an opportunity to extend and optionally log events without requiring
1210 knowledge of actual TPM commands.
1211 The extend operation will occur even if this function cannot create an event
1212 log entry (e.g. due to the event log being full).
1214 @param[in] This Indicates the calling context
1215 @param[in] Flags Bitmap providing additional information.
1216 @param[in] DataToHash Physical address of the start of the data buffer to be hashed.
1217 @param[in] DataToHashLen The length in bytes of the buffer referenced by DataToHash.
1218 @param[in] Event Pointer to data buffer containing information about the event.
1220 @retval EFI_SUCCESS Operation completed successfully.
1221 @retval EFI_DEVICE_ERROR The command was unsuccessful.
1222 @retval EFI_VOLUME_FULL The extend operation occurred, but the event could not be written to one or more event logs.
1223 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1224 @retval EFI_UNSUPPORTED The PE/COFF image type is not supported.
1228 Tcg2HashLogExtendEvent (
1229 IN EFI_TCG2_PROTOCOL
*This
,
1231 IN EFI_PHYSICAL_ADDRESS DataToHash
,
1232 IN UINT64 DataToHashLen
,
1233 IN EFI_TCG2_EVENT
*Event
1237 TCG_PCR_EVENT_HDR NewEventHdr
;
1238 TPML_DIGEST_VALUES DigestList
;
1240 DEBUG ((EFI_D_INFO
, "Tcg2HashLogExtendEvent ...\n"));
1242 if ((This
== NULL
) || (DataToHash
== 0) || (Event
== NULL
)) {
1243 return EFI_INVALID_PARAMETER
;
1246 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
1247 return EFI_DEVICE_ERROR
;
1250 if (Event
->Size
< Event
->Header
.HeaderSize
+ sizeof(UINT32
)) {
1251 return EFI_INVALID_PARAMETER
;
1254 if (Event
->Header
.PCRIndex
> MAX_PCR_INDEX
) {
1255 return EFI_INVALID_PARAMETER
;
1258 NewEventHdr
.PCRIndex
= Event
->Header
.PCRIndex
;
1259 NewEventHdr
.EventType
= Event
->Header
.EventType
;
1260 NewEventHdr
.EventSize
= Event
->Size
- sizeof(UINT32
) - Event
->Header
.HeaderSize
;
1261 if ((Flags
& PE_COFF_IMAGE
) != 0) {
1262 Status
= MeasurePeImageAndExtend (
1263 NewEventHdr
.PCRIndex
,
1265 (UINTN
)DataToHashLen
,
1268 if (!EFI_ERROR (Status
)) {
1269 if ((Flags
& EFI_TCG2_EXTEND_ONLY
) == 0) {
1270 Status
= TcgDxeLogHashEvent (&DigestList
, &NewEventHdr
, Event
->Event
);
1273 if (Status
== EFI_DEVICE_ERROR
) {
1274 DEBUG ((EFI_D_ERROR
, "MeasurePeImageAndExtend - %r. Disable TPM.\n", Status
));
1275 mTcgDxeData
.BsCap
.TPMPresentFlag
= FALSE
;
1276 REPORT_STATUS_CODE (
1277 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
1278 (PcdGet32 (PcdStatusCodeSubClassTpmDevice
) | EFI_P_EC_INTERFACE_ERROR
)
1282 Status
= TcgDxeHashLogExtendEvent (
1284 (UINT8
*) (UINTN
) DataToHash
,
1290 DEBUG ((EFI_D_INFO
, "Tcg2HashLogExtendEvent - %r\n", Status
));
1295 This service enables the sending of commands to the TPM.
1297 @param[in] This Indicates the calling context
1298 @param[in] InputParameterBlockSize Size of the TPM input parameter block.
1299 @param[in] InputParameterBlock Pointer to the TPM input parameter block.
1300 @param[in] OutputParameterBlockSize Size of the TPM output parameter block.
1301 @param[in] OutputParameterBlock Pointer to the TPM output parameter block.
1303 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
1304 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
1305 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1306 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
1311 IN EFI_TCG2_PROTOCOL
*This
,
1312 IN UINT32 InputParameterBlockSize
,
1313 IN UINT8
*InputParameterBlock
,
1314 IN UINT32 OutputParameterBlockSize
,
1315 IN UINT8
*OutputParameterBlock
1320 DEBUG ((EFI_D_INFO
, "Tcg2SubmitCommand ...\n"));
1322 if ((This
== NULL
) ||
1323 (InputParameterBlockSize
== 0) || (InputParameterBlock
== NULL
) ||
1324 (OutputParameterBlockSize
== 0) || (OutputParameterBlock
== NULL
)) {
1325 return EFI_INVALID_PARAMETER
;
1328 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
1329 return EFI_DEVICE_ERROR
;
1332 if (InputParameterBlockSize
>= mTcgDxeData
.BsCap
.MaxCommandSize
) {
1333 return EFI_INVALID_PARAMETER
;
1335 if (OutputParameterBlockSize
>= mTcgDxeData
.BsCap
.MaxResponseSize
) {
1336 return EFI_INVALID_PARAMETER
;
1339 Status
= Tpm2SubmitCommand (
1340 InputParameterBlockSize
,
1341 InputParameterBlock
,
1342 &OutputParameterBlockSize
,
1343 OutputParameterBlock
1345 DEBUG ((EFI_D_INFO
, "Tcg2SubmitCommand - %r\n", Status
));
1350 This service returns the currently active PCR banks.
1352 @param[in] This Indicates the calling context
1353 @param[out] ActivePcrBanks Pointer to the variable receiving the bitmap of currently active PCR banks.
1355 @retval EFI_SUCCESS The bitmap of active PCR banks was stored in the ActivePcrBanks parameter.
1356 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1360 Tcg2GetActivePCRBanks (
1361 IN EFI_TCG2_PROTOCOL
*This
,
1362 OUT UINT32
*ActivePcrBanks
1365 if (ActivePcrBanks
== NULL
) {
1366 return EFI_INVALID_PARAMETER
;
1368 *ActivePcrBanks
= mTcgDxeData
.BsCap
.ActivePcrBanks
;
1373 This service sets the currently active PCR banks.
1375 @param[in] This Indicates the calling context
1376 @param[in] ActivePcrBanks Bitmap of the requested active PCR banks. At least one bit SHALL be set.
1378 @retval EFI_SUCCESS The bitmap in ActivePcrBank parameter is already active.
1379 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1383 Tcg2SetActivePCRBanks (
1384 IN EFI_TCG2_PROTOCOL
*This
,
1385 IN UINT32 ActivePcrBanks
1391 DEBUG ((EFI_D_INFO
, "Tcg2SetActivePCRBanks ... (0x%x)\n", ActivePcrBanks
));
1393 if (ActivePcrBanks
== 0) {
1394 return EFI_INVALID_PARAMETER
;
1396 if ((ActivePcrBanks
& (~mTcgDxeData
.BsCap
.HashAlgorithmBitmap
)) != 0) {
1397 return EFI_INVALID_PARAMETER
;
1399 if (ActivePcrBanks
== mTcgDxeData
.BsCap
.ActivePcrBanks
) {
1401 // Need clear previous SET_PCR_BANKS setting
1403 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_NO_ACTION
, 0);
1405 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS
, ActivePcrBanks
);
1408 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
1409 Status
= EFI_SUCCESS
;
1410 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
1411 Status
= EFI_OUT_OF_RESOURCES
;
1412 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
1413 Status
= EFI_UNSUPPORTED
;
1415 Status
= EFI_DEVICE_ERROR
;
1418 DEBUG ((EFI_D_INFO
, "Tcg2SetActivePCRBanks - %r\n", Status
));
1424 This service retrieves the result of a previous invocation of SetActivePcrBanks.
1426 @param[in] This Indicates the calling context
1427 @param[out] OperationPresent Non-zero value to indicate a SetActivePcrBank operation was invoked during the last boot.
1428 @param[out] Response The response from the SetActivePcrBank request.
1430 @retval EFI_SUCCESS The result value could be returned.
1431 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1435 Tcg2GetResultOfSetActivePcrBanks (
1436 IN EFI_TCG2_PROTOCOL
*This
,
1437 OUT UINT32
*OperationPresent
,
1438 OUT UINT32
*Response
1443 if ((OperationPresent
== NULL
) || (Response
== NULL
)) {
1444 return EFI_INVALID_PARAMETER
;
1447 ReturnCode
= Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (OperationPresent
, Response
);
1448 if (ReturnCode
== TCG_PP_RETURN_TPM_OPERATION_RESPONSE_SUCCESS
) {
1451 return EFI_UNSUPPORTED
;
1455 EFI_TCG2_PROTOCOL mTcg2Protocol
= {
1458 Tcg2HashLogExtendEvent
,
1460 Tcg2GetActivePCRBanks
,
1461 Tcg2SetActivePCRBanks
,
1462 Tcg2GetResultOfSetActivePcrBanks
,
1466 Initialize the Event Log and log events passed from the PEI phase.
1468 @retval EFI_SUCCESS Operation completed successfully.
1469 @retval EFI_OUT_OF_RESOURCES Out of memory.
1479 EFI_PEI_HOB_POINTERS GuidHob
;
1480 EFI_PHYSICAL_ADDRESS Lasa
;
1482 UINT32 DigestListBinSize
;
1484 TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
;
1485 UINT8 TempBuf
[sizeof(TCG_EfiSpecIDEventStruct
) + sizeof(UINT32
) + (HASH_COUNT
* sizeof(TCG_EfiSpecIdEventAlgorithmSize
)) + sizeof(UINT8
)];
1486 TCG_PCR_EVENT_HDR FirstPcrEvent
;
1487 TCG_EfiSpecIdEventAlgorithmSize
*DigestSize
;
1488 TCG_EfiSpecIdEventAlgorithmSize
*TempDigestSize
;
1489 UINT8
*VendorInfoSize
;
1490 UINT32 NumberOfAlgorithms
;
1492 DEBUG ((EFI_D_INFO
, "SetupEventLog\n"));
1495 // 1. Create Log Area
1497 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1498 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1499 mTcgDxeData
.EventLogAreaStruct
[Index
].EventLogFormat
= mTcg2EventInfo
[Index
].LogFormat
;
1500 Lasa
= (EFI_PHYSICAL_ADDRESS
) (SIZE_4GB
- 1);
1501 Status
= gBS
->AllocatePages (
1503 EfiBootServicesData
,
1504 EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcgLogAreaMinLen
)),
1507 if (EFI_ERROR (Status
)) {
1510 mTcgDxeData
.EventLogAreaStruct
[Index
].Lasa
= Lasa
;
1511 mTcgDxeData
.EventLogAreaStruct
[Index
].Laml
= PcdGet32 (PcdTcgLogAreaMinLen
);
1513 // To initialize them as 0xFF is recommended
1514 // because the OS can know the last entry for that.
1516 SetMem ((VOID
*)(UINTN
)Lasa
, PcdGet32 (PcdTcgLogAreaMinLen
), 0xFF);
1518 // Create first entry for Log Header Entry Data
1520 if (mTcg2EventInfo
[Index
].LogFormat
!= EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
) {
1522 // TcgEfiSpecIdEventStruct
1524 TcgEfiSpecIdEventStruct
= (TCG_EfiSpecIDEventStruct
*)TempBuf
;
1525 CopyMem (TcgEfiSpecIdEventStruct
->signature
, TCG_EfiSpecIDEventStruct_SIGNATURE_03
, sizeof(TcgEfiSpecIdEventStruct
->signature
));
1526 TcgEfiSpecIdEventStruct
->platformClass
= PcdGet8 (PcdTpmPlatformClass
);
1527 TcgEfiSpecIdEventStruct
->specVersionMajor
= TCG_EfiSpecIDEventStruct_SPEC_VERSION_MAJOR_TPM2
;
1528 TcgEfiSpecIdEventStruct
->specVersionMinor
= TCG_EfiSpecIDEventStruct_SPEC_VERSION_MINOR_TPM2
;
1529 TcgEfiSpecIdEventStruct
->specErrata
= TCG_EfiSpecIDEventStruct_SPEC_ERRATA_TPM2
;
1530 TcgEfiSpecIdEventStruct
->uintnSize
= sizeof(UINTN
)/sizeof(UINT32
);
1531 NumberOfAlgorithms
= 0;
1532 DigestSize
= (TCG_EfiSpecIdEventAlgorithmSize
*)((UINT8
*)TcgEfiSpecIdEventStruct
+ sizeof(*TcgEfiSpecIdEventStruct
) + sizeof(NumberOfAlgorithms
));
1533 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) != 0) {
1534 TempDigestSize
= DigestSize
;
1535 TempDigestSize
+= NumberOfAlgorithms
;
1536 TempDigestSize
->algorithmId
= TPM_ALG_SHA1
;
1537 TempDigestSize
->digestSize
= SHA1_DIGEST_SIZE
;
1538 NumberOfAlgorithms
++;
1540 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA256
) != 0) {
1541 TempDigestSize
= DigestSize
;
1542 TempDigestSize
+= NumberOfAlgorithms
;
1543 TempDigestSize
->algorithmId
= TPM_ALG_SHA256
;
1544 TempDigestSize
->digestSize
= SHA256_DIGEST_SIZE
;
1545 NumberOfAlgorithms
++;
1547 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA384
) != 0) {
1548 TempDigestSize
= DigestSize
;
1549 TempDigestSize
+= NumberOfAlgorithms
;
1550 TempDigestSize
->algorithmId
= TPM_ALG_SHA384
;
1551 TempDigestSize
->digestSize
= SHA384_DIGEST_SIZE
;
1552 NumberOfAlgorithms
++;
1554 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA512
) != 0) {
1555 TempDigestSize
= DigestSize
;
1556 TempDigestSize
+= NumberOfAlgorithms
;
1557 TempDigestSize
->algorithmId
= TPM_ALG_SHA512
;
1558 TempDigestSize
->digestSize
= SHA512_DIGEST_SIZE
;
1559 NumberOfAlgorithms
++;
1561 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SM3_256
) != 0) {
1562 TempDigestSize
= DigestSize
;
1563 TempDigestSize
+= NumberOfAlgorithms
;
1564 TempDigestSize
->algorithmId
= TPM_ALG_SM3_256
;
1565 TempDigestSize
->digestSize
= SM3_256_DIGEST_SIZE
;
1566 NumberOfAlgorithms
++;
1568 CopyMem (TcgEfiSpecIdEventStruct
+ 1, &NumberOfAlgorithms
, sizeof(NumberOfAlgorithms
));
1569 TempDigestSize
= DigestSize
;
1570 TempDigestSize
+= NumberOfAlgorithms
;
1571 VendorInfoSize
= (UINT8
*)TempDigestSize
;
1572 *VendorInfoSize
= 0;
1577 FirstPcrEvent
.PCRIndex
= 0;
1578 FirstPcrEvent
.EventType
= EV_NO_ACTION
;
1579 ZeroMem (&FirstPcrEvent
.Digest
, sizeof(FirstPcrEvent
.Digest
));
1580 FirstPcrEvent
.EventSize
= (UINT32
)GetTcgEfiSpecIdEventStructSize (TcgEfiSpecIdEventStruct
);
1585 Status
= TcgDxeLogEvent (
1586 mTcg2EventInfo
[Index
].LogFormat
,
1588 sizeof(FirstPcrEvent
),
1589 (UINT8
*)TcgEfiSpecIdEventStruct
,
1590 FirstPcrEvent
.EventSize
1597 // 2. Create Final Log Area
1599 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1600 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1601 if (mTcg2EventInfo
[Index
].LogFormat
== EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
) {
1602 Lasa
= (EFI_PHYSICAL_ADDRESS
) (SIZE_4GB
- 1);
1603 Status
= gBS
->AllocatePages (
1606 EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcg2FinalLogAreaLen
)),
1609 if (EFI_ERROR (Status
)) {
1612 SetMem ((VOID
*)(UINTN
)Lasa
, PcdGet32 (PcdTcg2FinalLogAreaLen
), 0xFF);
1617 mTcgDxeData
.FinalEventsTable
[Index
] = (VOID
*)(UINTN
)Lasa
;
1618 (mTcgDxeData
.FinalEventsTable
[Index
])->Version
= EFI_TCG2_FINAL_EVENTS_TABLE_VERSION
;
1619 (mTcgDxeData
.FinalEventsTable
[Index
])->NumberOfEvents
= 0;
1621 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogFormat
= mTcg2EventInfo
[Index
].LogFormat
;
1622 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Lasa
= Lasa
+ sizeof(EFI_TCG2_FINAL_EVENTS_TABLE
);
1623 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Laml
= PcdGet32 (PcdTcg2FinalLogAreaLen
) - sizeof(EFI_TCG2_FINAL_EVENTS_TABLE
);
1624 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogSize
= 0;
1625 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].LastEvent
= (VOID
*)(UINTN
)mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Lasa
;
1626 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogStarted
= FALSE
;
1627 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogTruncated
= FALSE
;
1630 // Install to configuration table for EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
1632 Status
= gBS
->InstallConfigurationTable (&gEfiTcg2FinalEventsTableGuid
, (VOID
*)mTcgDxeData
.FinalEventsTable
[Index
]);
1633 if (EFI_ERROR (Status
)) {
1638 // No need to handle EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
1640 mTcgDxeData
.FinalEventsTable
[Index
] = NULL
;
1641 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogFormat
= mTcg2EventInfo
[Index
].LogFormat
;
1642 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Lasa
= 0;
1643 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Laml
= 0;
1644 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogSize
= 0;
1645 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].LastEvent
= 0;
1646 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogStarted
= FALSE
;
1647 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogTruncated
= FALSE
;
1653 // 3. Sync data from PEI to DXE
1655 Status
= EFI_SUCCESS
;
1656 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1657 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1658 GuidHob
.Raw
= GetHobList ();
1659 Status
= EFI_SUCCESS
;
1660 while (!EFI_ERROR (Status
) &&
1661 (GuidHob
.Raw
= GetNextGuidHob (mTcg2EventInfo
[Index
].EventGuid
, GuidHob
.Raw
)) != NULL
) {
1662 TcgEvent
= GET_GUID_HOB_DATA (GuidHob
.Guid
);
1663 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
1664 switch (mTcg2EventInfo
[Index
].LogFormat
) {
1665 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
:
1666 Status
= TcgDxeLogEvent (
1667 mTcg2EventInfo
[Index
].LogFormat
,
1669 sizeof(TCG_PCR_EVENT_HDR
),
1670 ((TCG_PCR_EVENT
*)TcgEvent
)->Event
,
1671 ((TCG_PCR_EVENT_HDR
*)TcgEvent
)->EventSize
1674 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
:
1675 DigestListBinSize
= GetDigestListBinSize ((UINT8
*)TcgEvent
+ sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
));
1676 CopyMem (&EventSize
, (UINT8
*)TcgEvent
+ sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
) + DigestListBinSize
, sizeof(UINT32
));
1677 Status
= TcgDxeLogEvent (
1678 mTcg2EventInfo
[Index
].LogFormat
,
1680 sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
) + DigestListBinSize
+ sizeof(UINT32
),
1681 (UINT8
*)TcgEvent
+ sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
) + DigestListBinSize
+ sizeof(UINT32
),
1694 Measure and log an action string, and extend the measurement result into PCR[5].
1696 @param[in] String A specific string that indicates an Action event.
1698 @retval EFI_SUCCESS Operation completed successfully.
1699 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1707 TCG_PCR_EVENT_HDR TcgEvent
;
1709 TcgEvent
.PCRIndex
= 5;
1710 TcgEvent
.EventType
= EV_EFI_ACTION
;
1711 TcgEvent
.EventSize
= (UINT32
)AsciiStrLen (String
);
1712 return TcgDxeHashLogExtendEvent (
1722 Measure and log EFI handoff tables, and extend the measurement result into PCR[1].
1724 @retval EFI_SUCCESS Operation completed successfully.
1725 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1729 MeasureHandoffTables (
1734 TCG_PCR_EVENT_HDR TcgEvent
;
1735 EFI_HANDOFF_TABLE_POINTERS HandoffTables
;
1737 EFI_CPU_PHYSICAL_LOCATION
*ProcessorLocBuf
;
1739 ProcessorLocBuf
= NULL
;
1740 Status
= EFI_SUCCESS
;
1742 if (PcdGet8 (PcdTpmPlatformClass
) == TCG_PLATFORM_TYPE_SERVER
) {
1745 // Measure each processor EFI_CPU_PHYSICAL_LOCATION with EV_TABLE_OF_DEVICES to PCR[1]
1747 Status
= GetProcessorsCpuLocation(&ProcessorLocBuf
, &ProcessorNum
);
1749 if (!EFI_ERROR(Status
)){
1750 TcgEvent
.PCRIndex
= 1;
1751 TcgEvent
.EventType
= EV_TABLE_OF_DEVICES
;
1752 TcgEvent
.EventSize
= sizeof (HandoffTables
);
1754 HandoffTables
.NumberOfTables
= 1;
1755 HandoffTables
.TableEntry
[0].VendorGuid
= gEfiMpServiceProtocolGuid
;
1756 HandoffTables
.TableEntry
[0].VendorTable
= ProcessorLocBuf
;
1758 Status
= TcgDxeHashLogExtendEvent (
1760 (UINT8
*)(UINTN
)ProcessorLocBuf
,
1761 sizeof(EFI_CPU_PHYSICAL_LOCATION
) * ProcessorNum
,
1763 (UINT8
*)&HandoffTables
1766 FreePool(ProcessorLocBuf
);
1774 Measure and log Separator event, and extend the measurement result into a specific PCR.
1776 @param[in] PCRIndex PCR index.
1778 @retval EFI_SUCCESS Operation completed successfully.
1779 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1783 MeasureSeparatorEvent (
1784 IN TPM_PCRINDEX PCRIndex
1787 TCG_PCR_EVENT_HDR TcgEvent
;
1790 DEBUG ((EFI_D_INFO
, "MeasureSeparatorEvent Pcr - %x\n", PCRIndex
));
1793 TcgEvent
.PCRIndex
= PCRIndex
;
1794 TcgEvent
.EventType
= EV_SEPARATOR
;
1795 TcgEvent
.EventSize
= (UINT32
)sizeof (EventData
);
1796 return TcgDxeHashLogExtendEvent (
1798 (UINT8
*)&EventData
,
1806 Measure and log an EFI variable, and extend the measurement result into a specific PCR.
1808 @param[in] PCRIndex PCR Index.
1809 @param[in] EventType Event type.
1810 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1811 @param[in] VendorGuid A unique identifier for the vendor.
1812 @param[in] VarData The content of the variable data.
1813 @param[in] VarSize The size of the variable data.
1815 @retval EFI_SUCCESS Operation completed successfully.
1816 @retval EFI_OUT_OF_RESOURCES Out of memory.
1817 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1822 IN TPM_PCRINDEX PCRIndex
,
1823 IN TCG_EVENTTYPE EventType
,
1825 IN EFI_GUID
*VendorGuid
,
1831 TCG_PCR_EVENT_HDR TcgEvent
;
1832 UINTN VarNameLength
;
1833 EFI_VARIABLE_DATA_TREE
*VarLog
;
1835 DEBUG ((EFI_D_INFO
, "Tcg2Dxe: MeasureVariable (Pcr - %x, EventType - %x, ", (UINTN
)PCRIndex
, (UINTN
)EventType
));
1836 DEBUG ((EFI_D_INFO
, "VariableName - %s, VendorGuid - %g)\n", VarName
, VendorGuid
));
1838 VarNameLength
= StrLen (VarName
);
1839 TcgEvent
.PCRIndex
= PCRIndex
;
1840 TcgEvent
.EventType
= EventType
;
1842 TcgEvent
.EventSize
= (UINT32
)(sizeof (*VarLog
) + VarNameLength
* sizeof (*VarName
) + VarSize
1843 - sizeof (VarLog
->UnicodeName
) - sizeof (VarLog
->VariableData
));
1845 VarLog
= (EFI_VARIABLE_DATA_TREE
*)AllocatePool (TcgEvent
.EventSize
);
1846 if (VarLog
== NULL
) {
1847 return EFI_OUT_OF_RESOURCES
;
1850 VarLog
->VariableName
= *VendorGuid
;
1851 VarLog
->UnicodeNameLength
= VarNameLength
;
1852 VarLog
->VariableDataLength
= VarSize
;
1854 VarLog
->UnicodeName
,
1856 VarNameLength
* sizeof (*VarName
)
1858 if (VarSize
!= 0 && VarData
!= NULL
) {
1860 (CHAR16
*)VarLog
->UnicodeName
+ VarNameLength
,
1866 if (EventType
== EV_EFI_VARIABLE_DRIVER_CONFIG
) {
1868 // Digest is the event data (EFI_VARIABLE_DATA)
1870 Status
= TcgDxeHashLogExtendEvent (
1878 Status
= TcgDxeHashLogExtendEvent (
1891 Read then Measure and log an EFI variable, and extend the measurement result into a specific PCR.
1893 @param[in] PCRIndex PCR Index.
1894 @param[in] EventType Event type.
1895 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1896 @param[in] VendorGuid A unique identifier for the vendor.
1897 @param[out] VarSize The size of the variable data.
1898 @param[out] VarData Pointer to the content of the variable.
1900 @retval EFI_SUCCESS Operation completed successfully.
1901 @retval EFI_OUT_OF_RESOURCES Out of memory.
1902 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1906 ReadAndMeasureVariable (
1907 IN TPM_PCRINDEX PCRIndex
,
1908 IN TCG_EVENTTYPE EventType
,
1910 IN EFI_GUID
*VendorGuid
,
1917 Status
= GetVariable2 (VarName
, VendorGuid
, VarData
, VarSize
);
1918 if (EventType
== EV_EFI_VARIABLE_DRIVER_CONFIG
) {
1919 if (EFI_ERROR (Status
)) {
1921 // It is valid case, so we need handle it.
1928 // if status error, VarData is freed and set NULL by GetVariable2
1930 if (EFI_ERROR (Status
)) {
1931 return EFI_NOT_FOUND
;
1935 Status
= MeasureVariable (
1947 Read then Measure and log an EFI boot variable, and extend the measurement result into PCR[5].
1949 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1950 @param[in] VendorGuid A unique identifier for the vendor.
1951 @param[out] VarSize The size of the variable data.
1952 @param[out] VarData Pointer to the content of the variable.
1954 @retval EFI_SUCCESS Operation completed successfully.
1955 @retval EFI_OUT_OF_RESOURCES Out of memory.
1956 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1960 ReadAndMeasureBootVariable (
1962 IN EFI_GUID
*VendorGuid
,
1967 return ReadAndMeasureVariable (
1969 EV_EFI_VARIABLE_BOOT
,
1978 Read then Measure and log an EFI Secure variable, and extend the measurement result into PCR[7].
1980 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1981 @param[in] VendorGuid A unique identifier for the vendor.
1982 @param[out] VarSize The size of the variable data.
1983 @param[out] VarData Pointer to the content of the variable.
1985 @retval EFI_SUCCESS Operation completed successfully.
1986 @retval EFI_OUT_OF_RESOURCES Out of memory.
1987 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1991 ReadAndMeasureSecureVariable (
1993 IN EFI_GUID
*VendorGuid
,
1998 return ReadAndMeasureVariable (
2000 EV_EFI_VARIABLE_DRIVER_CONFIG
,
2009 Measure and log all EFI boot variables, and extend the measurement result into a specific PCR.
2011 The EFI boot variables are BootOrder and Boot#### variables.
2013 @retval EFI_SUCCESS Operation completed successfully.
2014 @retval EFI_OUT_OF_RESOURCES Out of memory.
2015 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
2019 MeasureAllBootVariables (
2030 Status
= ReadAndMeasureBootVariable (
2032 &gEfiGlobalVariableGuid
,
2034 (VOID
**) &BootOrder
2036 if (Status
== EFI_NOT_FOUND
|| BootOrder
== NULL
) {
2040 if (EFI_ERROR (Status
)) {
2042 // BootOrder can't be NULL if status is not EFI_NOT_FOUND
2044 FreePool (BootOrder
);
2048 BootCount
/= sizeof (*BootOrder
);
2049 for (Index
= 0; Index
< BootCount
; Index
++) {
2050 UnicodeSPrint (mBootVarName
, sizeof (mBootVarName
), L
"Boot%04x", BootOrder
[Index
]);
2051 Status
= ReadAndMeasureBootVariable (
2053 &gEfiGlobalVariableGuid
,
2057 if (!EFI_ERROR (Status
)) {
2058 FreePool (BootVarData
);
2062 FreePool (BootOrder
);
2067 Measure and log all EFI Secure variables, and extend the measurement result into a specific PCR.
2069 The EFI boot variables are BootOrder and Boot#### variables.
2071 @retval EFI_SUCCESS Operation completed successfully.
2072 @retval EFI_OUT_OF_RESOURCES Out of memory.
2073 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
2077 MeasureAllSecureVariables (
2086 Status
= EFI_NOT_FOUND
;
2087 for (Index
= 0; Index
< sizeof(mVariableType
)/sizeof(mVariableType
[0]); Index
++) {
2088 Status
= ReadAndMeasureSecureVariable (
2089 mVariableType
[Index
].VariableName
,
2090 mVariableType
[Index
].VendorGuid
,
2094 if (!EFI_ERROR (Status
)) {
2105 Measure and log launch of FirmwareDebugger, and extend the measurement result into a specific PCR.
2107 @retval EFI_SUCCESS Operation completed successfully.
2108 @retval EFI_OUT_OF_RESOURCES Out of memory.
2109 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
2113 MeasureLaunchOfFirmwareDebugger (
2117 TCG_PCR_EVENT_HDR TcgEvent
;
2119 TcgEvent
.PCRIndex
= 7;
2120 TcgEvent
.EventType
= EV_EFI_ACTION
;
2121 TcgEvent
.EventSize
= sizeof(FIRMWARE_DEBUGGER_EVENT_STRING
) - 1;
2122 return TcgDxeHashLogExtendEvent (
2124 (UINT8
*)FIRMWARE_DEBUGGER_EVENT_STRING
,
2125 sizeof(FIRMWARE_DEBUGGER_EVENT_STRING
) - 1,
2127 (UINT8
*)FIRMWARE_DEBUGGER_EVENT_STRING
2132 Measure and log all Secure Boot Policy, and extend the measurement result into a specific PCR.
2134 Platform firmware adhering to the policy must therefore measure the following values into PCR[7]: (in order listed)
2135 - The contents of the SecureBoot variable
2136 - The contents of the PK variable
2137 - The contents of the KEK variable
2138 - The contents of the EFI_IMAGE_SECURITY_DATABASE variable
2139 - The contents of the EFI_IMAGE_SECURITY_DATABASE1 variable
2141 - Entries in the EFI_IMAGE_SECURITY_DATABASE that are used to validate EFI Drivers or EFI Boot Applications in the boot path
2143 NOTE: Because of the above, UEFI variables PK, KEK, EFI_IMAGE_SECURITY_DATABASE,
2144 EFI_IMAGE_SECURITY_DATABASE1 and SecureBoot SHALL NOT be measured into PCR[3].
2146 @param[in] Event Event whose notification function is being invoked
2147 @param[in] Context Pointer to the notification function's context
2151 MeasureSecureBootPolicy (
2159 Status
= gBS
->LocateProtocol (&gEfiVariableWriteArchProtocolGuid
, NULL
, (VOID
**)&Protocol
);
2160 if (EFI_ERROR (Status
)) {
2164 if (PcdGetBool (PcdFirmwareDebuggerInitialized
)) {
2165 Status
= MeasureLaunchOfFirmwareDebugger ();
2166 DEBUG ((EFI_D_INFO
, "MeasureLaunchOfFirmwareDebugger - %r\n", Status
));
2169 Status
= MeasureAllSecureVariables ();
2170 DEBUG ((EFI_D_INFO
, "MeasureAllSecureVariables - %r\n", Status
));
2173 // We need measure Separator(7) here, because this event must be between SecureBootPolicy (Configure)
2174 // and ImageVerification (Authority)
2175 // There might be a case that we need measure UEFI image from DriverOrder, besides BootOrder. So
2176 // the Authority measurement happen before ReadToBoot event.
2178 Status
= MeasureSeparatorEvent (7);
2179 DEBUG ((EFI_D_INFO
, "MeasureSeparatorEvent - %r\n", Status
));
2184 Ready to Boot Event notification handler.
2186 Sequence of OS boot events is measured in this event notification handler.
2188 @param[in] Event Event whose notification function is being invoked
2189 @param[in] Context Pointer to the notification function's context
2200 TPM_PCRINDEX PcrIndex
;
2202 PERF_START_EX (mImageHandle
, "EventRec", "Tcg2Dxe", 0, PERF_ID_TCG2_DXE
);
2203 if (mBootAttempts
== 0) {
2206 // Measure handoff tables.
2208 Status
= MeasureHandoffTables ();
2209 if (EFI_ERROR (Status
)) {
2210 DEBUG ((EFI_D_ERROR
, "HOBs not Measured. Error!\n"));
2214 // Measure BootOrder & Boot#### variables.
2216 Status
= MeasureAllBootVariables ();
2217 if (EFI_ERROR (Status
)) {
2218 DEBUG ((EFI_D_ERROR
, "Boot Variables not Measured. Error!\n"));
2222 // 1. This is the first boot attempt.
2224 Status
= TcgMeasureAction (
2225 EFI_CALLING_EFI_APPLICATION
2227 if (EFI_ERROR (Status
)) {
2228 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_CALLING_EFI_APPLICATION
));
2232 // 2. Draw a line between pre-boot env and entering post-boot env.
2233 // PCR[7] is already done.
2235 for (PcrIndex
= 0; PcrIndex
< 7; PcrIndex
++) {
2236 Status
= MeasureSeparatorEvent (PcrIndex
);
2237 if (EFI_ERROR (Status
)) {
2238 DEBUG ((EFI_D_ERROR
, "Seperator Event not Measured. Error!\n"));
2243 // 3. Measure GPT. It would be done in SAP driver.
2247 // 4. Measure PE/COFF OS loader. It would be done in SAP driver.
2251 // 5. Read & Measure variable. BootOrder already measured.
2255 // 6. Not first attempt, meaning a return from last attempt
2257 Status
= TcgMeasureAction (
2258 EFI_RETURNING_FROM_EFI_APPLICATOIN
2260 if (EFI_ERROR (Status
)) {
2261 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_RETURNING_FROM_EFI_APPLICATOIN
));
2265 DEBUG ((EFI_D_INFO
, "TPM2 Tcg2Dxe Measure Data when ReadyToBoot\n"));
2267 // Increase boot attempt counter.
2270 PERF_END_EX (mImageHandle
, "EventRec", "Tcg2Dxe", 0, PERF_ID_TCG2_DXE
+ 1);
2274 Exit Boot Services Event notification handler.
2276 Measure invocation and success of ExitBootServices.
2278 @param[in] Event Event whose notification function is being invoked
2279 @param[in] Context Pointer to the notification function's context
2284 OnExitBootServices (
2292 // Measure invocation of ExitBootServices,
2294 Status
= TcgMeasureAction (
2295 EFI_EXIT_BOOT_SERVICES_INVOCATION
2297 if (EFI_ERROR (Status
)) {
2298 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_INVOCATION
));
2302 // Measure success of ExitBootServices
2304 Status
= TcgMeasureAction (
2305 EFI_EXIT_BOOT_SERVICES_SUCCEEDED
2307 if (EFI_ERROR (Status
)) {
2308 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_SUCCEEDED
));
2313 Exit Boot Services Failed Event notification handler.
2315 Measure Failure of ExitBootServices.
2317 @param[in] Event Event whose notification function is being invoked
2318 @param[in] Context Pointer to the notification function's context
2323 OnExitBootServicesFailed (
2331 // Measure Failure of ExitBootServices,
2333 Status
= TcgMeasureAction (
2334 EFI_EXIT_BOOT_SERVICES_FAILED
2336 if (EFI_ERROR (Status
)) {
2337 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_FAILED
));
2343 The function install Tcg2 protocol.
2345 @retval EFI_SUCCESS Tcg2 protocol is installed.
2346 @retval other Some error occurs.
2357 Status
= gBS
->InstallMultipleProtocolInterfaces (
2359 &gEfiTcg2ProtocolGuid
,
2367 The driver's entry point. It publishes EFI Tcg2 Protocol.
2369 @param[in] ImageHandle The firmware allocated handle for the EFI image.
2370 @param[in] SystemTable A pointer to the EFI System Table.
2372 @retval EFI_SUCCESS The entry point is executed successfully.
2373 @retval other Some error occurs when executing this entry point.
2378 IN EFI_HANDLE ImageHandle
,
2379 IN EFI_SYSTEM_TABLE
*SystemTable
2385 UINT32 MaxCommandSize
;
2386 UINT32 MaxResponseSize
;
2387 TPML_PCR_SELECTION Pcrs
;
2389 EFI_TCG2_EVENT_ALGORITHM_BITMAP TpmHashAlgorithmBitmap
;
2390 UINT32 ActivePCRBanks
;
2391 UINT32 NumberOfPCRBanks
;
2393 mImageHandle
= ImageHandle
;
2395 if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &gEfiTpmDeviceInstanceNoneGuid
) ||
2396 CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &gEfiTpmDeviceInstanceTpm12Guid
)){
2397 DEBUG ((EFI_D_ERROR
, "No TPM2 instance required!\n"));
2398 return EFI_UNSUPPORTED
;
2401 if (GetFirstGuidHob (&gTpmErrorHobGuid
) != NULL
) {
2402 DEBUG ((EFI_D_ERROR
, "TPM2 error!\n"));
2403 return EFI_DEVICE_ERROR
;
2406 Status
= Tpm2RequestUseTpm ();
2407 if (EFI_ERROR (Status
)) {
2408 DEBUG ((EFI_D_ERROR
, "TPM2 not detected!\n"));
2415 ASSERT (TCG_EVENT_LOG_AREA_COUNT_MAX
== sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]));
2417 mTcgDxeData
.BsCap
.Size
= sizeof(EFI_TCG2_BOOT_SERVICE_CAPABILITY
);
2418 mTcgDxeData
.BsCap
.ProtocolVersion
.Major
= 1;
2419 mTcgDxeData
.BsCap
.ProtocolVersion
.Minor
= 1;
2420 mTcgDxeData
.BsCap
.StructureVersion
.Major
= 1;
2421 mTcgDxeData
.BsCap
.StructureVersion
.Minor
= 1;
2423 DEBUG ((EFI_D_INFO
, "Tcg2.ProtocolVersion - %02x.%02x\n", mTcgDxeData
.BsCap
.ProtocolVersion
.Major
, mTcgDxeData
.BsCap
.ProtocolVersion
.Minor
));
2424 DEBUG ((EFI_D_INFO
, "Tcg2.StructureVersion - %02x.%02x\n", mTcgDxeData
.BsCap
.StructureVersion
.Major
, mTcgDxeData
.BsCap
.StructureVersion
.Minor
));
2426 Status
= Tpm2GetCapabilityManufactureID (&mTcgDxeData
.BsCap
.ManufacturerID
);
2427 if (EFI_ERROR (Status
)) {
2428 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityManufactureID fail!\n"));
2430 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityManufactureID - %08x\n", mTcgDxeData
.BsCap
.ManufacturerID
));
2434 UINT32 FirmwareVersion1
;
2435 UINT32 FirmwareVersion2
;
2437 Status
= Tpm2GetCapabilityFirmwareVersion (&FirmwareVersion1
, &FirmwareVersion2
);
2438 if (EFI_ERROR (Status
)) {
2439 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityFirmwareVersion fail!\n"));
2441 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityFirmwareVersion - %08x %08x\n", FirmwareVersion1
, FirmwareVersion2
));
2445 Status
= Tpm2GetCapabilityMaxCommandResponseSize (&MaxCommandSize
, &MaxResponseSize
);
2446 if (EFI_ERROR (Status
)) {
2447 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityMaxCommandResponseSize fail!\n"));
2449 mTcgDxeData
.BsCap
.MaxCommandSize
= (UINT16
)MaxCommandSize
;
2450 mTcgDxeData
.BsCap
.MaxResponseSize
= (UINT16
)MaxResponseSize
;
2451 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityMaxCommandResponseSize - %08x, %08x\n", MaxCommandSize
, MaxResponseSize
));
2455 // Get supported PCR and current Active PCRs
2457 Status
= Tpm2GetCapabilityPcrs (&Pcrs
);
2458 if (EFI_ERROR (Status
)) {
2459 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityPcrs fail!\n"));
2460 TpmHashAlgorithmBitmap
= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2461 ActivePCRBanks
= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2463 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityPcrs Count - %08x\n", Pcrs
.count
));
2464 TpmHashAlgorithmBitmap
= 0;
2466 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
2467 DEBUG ((EFI_D_INFO
, "hash - %x\n", Pcrs
.pcrSelections
[Index
].hash
));
2468 switch (Pcrs
.pcrSelections
[Index
].hash
) {
2470 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2471 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2472 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2475 case TPM_ALG_SHA256
:
2476 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA256
;
2477 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2478 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA256
;
2481 case TPM_ALG_SHA384
:
2482 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA384
;
2483 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2484 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA384
;
2487 case TPM_ALG_SHA512
:
2488 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA512
;
2489 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2490 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA512
;
2493 case TPM_ALG_SM3_256
:
2494 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SM3_256
;
2495 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2496 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SM3_256
;
2502 mTcgDxeData
.BsCap
.HashAlgorithmBitmap
= TpmHashAlgorithmBitmap
& PcdGet32 (PcdTcg2HashAlgorithmBitmap
);
2503 mTcgDxeData
.BsCap
.ActivePcrBanks
= ActivePCRBanks
& PcdGet32 (PcdTcg2HashAlgorithmBitmap
);
2506 // Need calculate NumberOfPCRBanks here, because HashAlgorithmBitmap might be removed by PCD.
2508 NumberOfPCRBanks
= 0;
2509 for (Index
= 0; Index
< 32; Index
++) {
2510 if ((mTcgDxeData
.BsCap
.HashAlgorithmBitmap
& (1u << Index
)) != 0) {
2515 if (PcdGet32 (PcdTcg2NumberOfPCRBanks
) == 0) {
2516 mTcgDxeData
.BsCap
.NumberOfPCRBanks
= NumberOfPCRBanks
;
2518 mTcgDxeData
.BsCap
.NumberOfPCRBanks
= PcdGet32 (PcdTcg2NumberOfPCRBanks
);
2519 if (PcdGet32 (PcdTcg2NumberOfPCRBanks
) > NumberOfPCRBanks
) {
2520 DEBUG ((EFI_D_ERROR
, "ERROR: PcdTcg2NumberOfPCRBanks(0x%x) > NumberOfPCRBanks(0x%x)\n", PcdGet32 (PcdTcg2NumberOfPCRBanks
), NumberOfPCRBanks
));
2521 mTcgDxeData
.BsCap
.NumberOfPCRBanks
= NumberOfPCRBanks
;
2525 mTcgDxeData
.BsCap
.SupportedEventLogs
= EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
| EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
;
2526 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) == 0) {
2528 // No need to expose TCG1.2 event log if SHA1 bank does not exist.
2530 mTcgDxeData
.BsCap
.SupportedEventLogs
&= ~EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
;
2533 DEBUG ((EFI_D_INFO
, "Tcg2.SupportedEventLogs - 0x%08x\n", mTcgDxeData
.BsCap
.SupportedEventLogs
));
2534 DEBUG ((EFI_D_INFO
, "Tcg2.HashAlgorithmBitmap - 0x%08x\n", mTcgDxeData
.BsCap
.HashAlgorithmBitmap
));
2535 DEBUG ((EFI_D_INFO
, "Tcg2.NumberOfPCRBanks - 0x%08x\n", mTcgDxeData
.BsCap
.NumberOfPCRBanks
));
2536 DEBUG ((EFI_D_INFO
, "Tcg2.ActivePcrBanks - 0x%08x\n", mTcgDxeData
.BsCap
.ActivePcrBanks
));
2538 if (mTcgDxeData
.BsCap
.TPMPresentFlag
) {
2540 // Setup the log area and copy event log from hob list to it
2542 Status
= SetupEventLog ();
2543 ASSERT_EFI_ERROR (Status
);
2546 // Measure handoff tables, Boot#### variables etc.
2548 Status
= EfiCreateEventReadyToBootEx (
2555 Status
= gBS
->CreateEventEx (
2560 &gEfiEventExitBootServicesGuid
,
2565 // Measure Exit Boot Service failed
2567 Status
= gBS
->CreateEventEx (
2570 OnExitBootServicesFailed
,
2572 &gEventExitBootServicesFailedGuid
,
2577 // Create event callback, because we need access variable on SecureBootPolicyVariable
2578 // We should use VariableWriteArch instead of VariableArch, because Variable driver
2579 // may update SecureBoot value based on last setting.
2581 EfiCreateProtocolNotifyEvent (&gEfiVariableWriteArchProtocolGuid
, TPL_CALLBACK
, MeasureSecureBootPolicy
, NULL
, &Registration
);
2585 // Install Tcg2Protocol
2587 Status
= InstallTcg2 ();
2588 DEBUG ((EFI_D_INFO
, "InstallTcg2 - %r\n", Status
));