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 Notes: PE/COFF image is checked by BasePeCoffLib PeCoffLoaderGetImageInfo().
132 @param[in] PCRIndex TPM PCR index
133 @param[in] ImageAddress Start address of image buffer.
134 @param[in] ImageSize Image size
135 @param[out] DigestList Digeest list of this image.
137 @retval EFI_SUCCESS Successfully measure image.
138 @retval EFI_OUT_OF_RESOURCES No enough resource to measure image.
139 @retval other error value
142 MeasurePeImageAndExtend (
144 IN EFI_PHYSICAL_ADDRESS ImageAddress
,
146 OUT TPML_DIGEST_VALUES
*DigestList
151 This function dump raw data.
154 @param Size raw data size
164 for (Index
= 0; Index
< Size
; Index
++) {
165 DEBUG ((EFI_D_INFO
, "%02x", (UINTN
)Data
[Index
]));
171 This function dump raw data with colume format.
174 @param Size raw data size
187 #define COLUME_SIZE (16 * 2)
189 Count
= Size
/ COLUME_SIZE
;
190 Left
= Size
% COLUME_SIZE
;
191 for (Index
= 0; Index
< Count
; Index
++) {
192 DEBUG ((EFI_D_INFO
, "%04x: ", Index
* COLUME_SIZE
));
193 InternalDumpData (Data
+ Index
* COLUME_SIZE
, COLUME_SIZE
);
194 DEBUG ((EFI_D_INFO
, "\n"));
198 DEBUG ((EFI_D_INFO
, "%04x: ", Index
* COLUME_SIZE
));
199 InternalDumpData (Data
+ Index
* COLUME_SIZE
, Left
);
200 DEBUG ((EFI_D_INFO
, "\n"));
205 Get All processors EFI_CPU_LOCATION in system. LocationBuf is allocated inside the function
206 Caller is responsible to free LocationBuf.
208 @param[out] LocationBuf Returns Processor Location Buffer.
209 @param[out] Num Returns processor number.
211 @retval EFI_SUCCESS Operation completed successfully.
212 @retval EFI_UNSUPPORTED MpService protocol not found.
216 GetProcessorsCpuLocation (
217 OUT EFI_CPU_PHYSICAL_LOCATION
**LocationBuf
,
222 EFI_MP_SERVICES_PROTOCOL
*MpProtocol
;
224 UINTN EnabledProcessorNum
;
225 EFI_PROCESSOR_INFORMATION ProcessorInfo
;
226 EFI_CPU_PHYSICAL_LOCATION
*ProcessorLocBuf
;
229 Status
= gBS
->LocateProtocol (&gEfiMpServiceProtocolGuid
, NULL
, (VOID
**) &MpProtocol
);
230 if (EFI_ERROR (Status
)) {
232 // MP protocol is not installed
234 return EFI_UNSUPPORTED
;
237 Status
= MpProtocol
->GetNumberOfProcessors(
242 if (EFI_ERROR(Status
)){
246 Status
= gBS
->AllocatePool(
248 sizeof(EFI_CPU_PHYSICAL_LOCATION
) * ProcessorNum
,
249 (VOID
**) &ProcessorLocBuf
251 if (EFI_ERROR(Status
)){
256 // Get each processor Location info
258 for (Index
= 0; Index
< ProcessorNum
; Index
++) {
259 Status
= MpProtocol
->GetProcessorInfo(
264 if (EFI_ERROR(Status
)){
265 FreePool(ProcessorLocBuf
);
270 // Get all Processor Location info & measure
273 &ProcessorLocBuf
[Index
],
274 &ProcessorInfo
.Location
,
275 sizeof(EFI_CPU_PHYSICAL_LOCATION
)
279 *LocationBuf
= ProcessorLocBuf
;
286 The EFI_TCG2_PROTOCOL GetCapability function call provides protocol
287 capability information and state information.
289 @param[in] This Indicates the calling context
290 @param[in, out] ProtocolCapability The caller allocates memory for a EFI_TCG2_BOOT_SERVICE_CAPABILITY
291 structure and sets the size field to the size of the structure allocated.
292 The callee fills in the fields with the EFI protocol capability information
293 and the current EFI TCG2 state information up to the number of fields which
294 fit within the size of the structure passed in.
296 @retval EFI_SUCCESS Operation completed successfully.
297 @retval EFI_DEVICE_ERROR The command was unsuccessful.
298 The ProtocolCapability variable will not be populated.
299 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
300 The ProtocolCapability variable will not be populated.
301 @retval EFI_BUFFER_TOO_SMALL The ProtocolCapability variable is too small to hold the full response.
302 It will be partially populated (required Size field will be set).
307 IN EFI_TCG2_PROTOCOL
*This
,
308 IN OUT EFI_TCG2_BOOT_SERVICE_CAPABILITY
*ProtocolCapability
311 DEBUG ((DEBUG_VERBOSE
, "Tcg2GetCapability ...\n"));
313 if ((This
== NULL
) || (ProtocolCapability
== NULL
)) {
314 return EFI_INVALID_PARAMETER
;
317 DEBUG ((DEBUG_VERBOSE
, "Size - 0x%x\n", ProtocolCapability
->Size
));
318 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
)));
320 if (ProtocolCapability
->Size
< mTcgDxeData
.BsCap
.Size
) {
322 // Handle the case that firmware support 1.1 but OS only support 1.0.
324 if ((mTcgDxeData
.BsCap
.ProtocolVersion
.Major
> 0x01) ||
325 ((mTcgDxeData
.BsCap
.ProtocolVersion
.Major
== 0x01) && ((mTcgDxeData
.BsCap
.ProtocolVersion
.Minor
> 0x00)))) {
326 if (ProtocolCapability
->Size
>= sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
)) {
327 CopyMem (ProtocolCapability
, &mTcgDxeData
.BsCap
, sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
));
328 ProtocolCapability
->Size
= sizeof(TREE_BOOT_SERVICE_CAPABILITY_1_0
);
329 ProtocolCapability
->StructureVersion
.Major
= 1;
330 ProtocolCapability
->StructureVersion
.Minor
= 0;
331 ProtocolCapability
->ProtocolVersion
.Major
= 1;
332 ProtocolCapability
->ProtocolVersion
.Minor
= 0;
333 DEBUG ((EFI_D_ERROR
, "TreeGetCapability (Compatible) - %r\n", EFI_SUCCESS
));
337 ProtocolCapability
->Size
= mTcgDxeData
.BsCap
.Size
;
338 return EFI_BUFFER_TOO_SMALL
;
341 CopyMem (ProtocolCapability
, &mTcgDxeData
.BsCap
, mTcgDxeData
.BsCap
.Size
);
342 DEBUG ((DEBUG_VERBOSE
, "Tcg2GetCapability - %r\n", EFI_SUCCESS
));
347 This function dump PCR event.
349 @param[in] EventHdr TCG PCR event structure.
353 IN TCG_PCR_EVENT_HDR
*EventHdr
358 DEBUG ((EFI_D_INFO
, " Event:\n"));
359 DEBUG ((EFI_D_INFO
, " PCRIndex - %d\n", EventHdr
->PCRIndex
));
360 DEBUG ((EFI_D_INFO
, " EventType - 0x%08x\n", EventHdr
->EventType
));
361 DEBUG ((EFI_D_INFO
, " Digest - "));
362 for (Index
= 0; Index
< sizeof(TCG_DIGEST
); Index
++) {
363 DEBUG ((EFI_D_INFO
, "%02x ", EventHdr
->Digest
.digest
[Index
]));
365 DEBUG ((EFI_D_INFO
, "\n"));
366 DEBUG ((EFI_D_INFO
, " EventSize - 0x%08x\n", EventHdr
->EventSize
));
367 InternalDumpHex ((UINT8
*)(EventHdr
+ 1), EventHdr
->EventSize
);
371 This function dump TCG_EfiSpecIDEventStruct.
373 @param[in] TcgEfiSpecIdEventStruct A pointer to TCG_EfiSpecIDEventStruct.
376 DumpTcgEfiSpecIdEventStruct (
377 IN TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
380 TCG_EfiSpecIdEventAlgorithmSize
*DigestSize
;
382 UINT8
*VendorInfoSize
;
384 UINT32 NumberOfAlgorithms
;
386 DEBUG ((EFI_D_INFO
, " TCG_EfiSpecIDEventStruct:\n"));
387 DEBUG ((EFI_D_INFO
, " signature - '"));
388 for (Index
= 0; Index
< sizeof(TcgEfiSpecIdEventStruct
->signature
); Index
++) {
389 DEBUG ((EFI_D_INFO
, "%c", TcgEfiSpecIdEventStruct
->signature
[Index
]));
391 DEBUG ((EFI_D_INFO
, "'\n"));
392 DEBUG ((EFI_D_INFO
, " platformClass - 0x%08x\n", TcgEfiSpecIdEventStruct
->platformClass
));
393 DEBUG ((EFI_D_INFO
, " specVersion - %d.%d%d\n", TcgEfiSpecIdEventStruct
->specVersionMajor
, TcgEfiSpecIdEventStruct
->specVersionMinor
, TcgEfiSpecIdEventStruct
->specErrata
));
394 DEBUG ((EFI_D_INFO
, " uintnSize - 0x%02x\n", TcgEfiSpecIdEventStruct
->uintnSize
));
396 CopyMem (&NumberOfAlgorithms
, TcgEfiSpecIdEventStruct
+ 1, sizeof(NumberOfAlgorithms
));
397 DEBUG ((EFI_D_INFO
, " NumberOfAlgorithms - 0x%08x\n", NumberOfAlgorithms
));
399 DigestSize
= (TCG_EfiSpecIdEventAlgorithmSize
*)((UINT8
*)TcgEfiSpecIdEventStruct
+ sizeof(*TcgEfiSpecIdEventStruct
) + sizeof(NumberOfAlgorithms
));
400 for (Index
= 0; Index
< NumberOfAlgorithms
; Index
++) {
401 DEBUG ((EFI_D_INFO
, " digest(%d)\n", Index
));
402 DEBUG ((EFI_D_INFO
, " algorithmId - 0x%04x\n", DigestSize
[Index
].algorithmId
));
403 DEBUG ((EFI_D_INFO
, " digestSize - 0x%04x\n", DigestSize
[Index
].digestSize
));
405 VendorInfoSize
= (UINT8
*)&DigestSize
[NumberOfAlgorithms
];
406 DEBUG ((EFI_D_INFO
, " VendorInfoSize - 0x%02x\n", *VendorInfoSize
));
407 VendorInfo
= VendorInfoSize
+ 1;
408 DEBUG ((EFI_D_INFO
, " VendorInfo - "));
409 for (Index
= 0; Index
< *VendorInfoSize
; Index
++) {
410 DEBUG ((EFI_D_INFO
, "%02x ", VendorInfo
[Index
]));
412 DEBUG ((EFI_D_INFO
, "\n"));
416 This function get size of TCG_EfiSpecIDEventStruct.
418 @param[in] TcgEfiSpecIdEventStruct A pointer to TCG_EfiSpecIDEventStruct.
421 GetTcgEfiSpecIdEventStructSize (
422 IN TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
425 TCG_EfiSpecIdEventAlgorithmSize
*DigestSize
;
426 UINT8
*VendorInfoSize
;
427 UINT32 NumberOfAlgorithms
;
429 CopyMem (&NumberOfAlgorithms
, TcgEfiSpecIdEventStruct
+ 1, sizeof(NumberOfAlgorithms
));
431 DigestSize
= (TCG_EfiSpecIdEventAlgorithmSize
*)((UINT8
*)TcgEfiSpecIdEventStruct
+ sizeof(*TcgEfiSpecIdEventStruct
) + sizeof(NumberOfAlgorithms
));
432 VendorInfoSize
= (UINT8
*)&DigestSize
[NumberOfAlgorithms
];
433 return sizeof(TCG_EfiSpecIDEventStruct
) + sizeof(UINT32
) + (NumberOfAlgorithms
* sizeof(TCG_EfiSpecIdEventAlgorithmSize
)) + sizeof(UINT8
) + (*VendorInfoSize
);
437 This function dump PCR event 2.
439 @param[in] TcgPcrEvent2 TCG PCR event 2 structure.
443 IN TCG_PCR_EVENT2
*TcgPcrEvent2
449 TPMI_ALG_HASH HashAlgo
;
455 DEBUG ((EFI_D_INFO
, " Event:\n"));
456 DEBUG ((EFI_D_INFO
, " PCRIndex - %d\n", TcgPcrEvent2
->PCRIndex
));
457 DEBUG ((EFI_D_INFO
, " EventType - 0x%08x\n", TcgPcrEvent2
->EventType
));
459 DEBUG ((EFI_D_INFO
, " DigestCount: 0x%08x\n", TcgPcrEvent2
->Digest
.count
));
461 DigestCount
= TcgPcrEvent2
->Digest
.count
;
462 HashAlgo
= TcgPcrEvent2
->Digest
.digests
[0].hashAlg
;
463 DigestBuffer
= (UINT8
*)&TcgPcrEvent2
->Digest
.digests
[0].digest
;
464 for (DigestIndex
= 0; DigestIndex
< DigestCount
; DigestIndex
++) {
465 DEBUG ((EFI_D_INFO
, " HashAlgo : 0x%04x\n", HashAlgo
));
466 DEBUG ((EFI_D_INFO
, " Digest(%d): ", DigestIndex
));
467 DigestSize
= GetHashSizeFromAlgo (HashAlgo
);
468 for (Index
= 0; Index
< DigestSize
; Index
++) {
469 DEBUG ((EFI_D_INFO
, "%02x ", DigestBuffer
[Index
]));
471 DEBUG ((EFI_D_INFO
, "\n"));
475 CopyMem (&HashAlgo
, DigestBuffer
+ DigestSize
, sizeof(TPMI_ALG_HASH
));
476 DigestBuffer
= DigestBuffer
+ DigestSize
+ sizeof(TPMI_ALG_HASH
);
478 DEBUG ((EFI_D_INFO
, "\n"));
479 DigestBuffer
= DigestBuffer
- sizeof(TPMI_ALG_HASH
);
481 CopyMem (&EventSize
, DigestBuffer
, sizeof(TcgPcrEvent2
->EventSize
));
482 DEBUG ((EFI_D_INFO
, " EventSize - 0x%08x\n", EventSize
));
483 EventBuffer
= DigestBuffer
+ sizeof(TcgPcrEvent2
->EventSize
);
484 InternalDumpHex (EventBuffer
, EventSize
);
488 This function returns size of TCG PCR event 2.
490 @param[in] TcgPcrEvent2 TCG PCR event 2 structure.
492 @return size of TCG PCR event 2.
496 IN TCG_PCR_EVENT2
*TcgPcrEvent2
501 TPMI_ALG_HASH HashAlgo
;
507 DigestCount
= TcgPcrEvent2
->Digest
.count
;
508 HashAlgo
= TcgPcrEvent2
->Digest
.digests
[0].hashAlg
;
509 DigestBuffer
= (UINT8
*)&TcgPcrEvent2
->Digest
.digests
[0].digest
;
510 for (DigestIndex
= 0; DigestIndex
< DigestCount
; DigestIndex
++) {
511 DigestSize
= GetHashSizeFromAlgo (HashAlgo
);
515 CopyMem (&HashAlgo
, DigestBuffer
+ DigestSize
, sizeof(TPMI_ALG_HASH
));
516 DigestBuffer
= DigestBuffer
+ DigestSize
+ sizeof(TPMI_ALG_HASH
);
518 DigestBuffer
= DigestBuffer
- sizeof(TPMI_ALG_HASH
);
520 CopyMem (&EventSize
, DigestBuffer
, sizeof(TcgPcrEvent2
->EventSize
));
521 EventBuffer
= DigestBuffer
+ sizeof(TcgPcrEvent2
->EventSize
);
523 return (UINTN
)EventBuffer
+ EventSize
- (UINTN
)TcgPcrEvent2
;
527 This function dump event log.
529 @param[in] EventLogFormat The type of the event log for which the information is requested.
530 @param[in] EventLogLocation A pointer to the memory address of the event log.
531 @param[in] EventLogLastEntry If the Event Log contains more than one entry, this is a pointer to the
532 address of the start of the last entry in the event log in memory.
533 @param[in] FinalEventsTable A pointer to the memory address of the final event table.
537 IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
,
538 IN EFI_PHYSICAL_ADDRESS EventLogLocation
,
539 IN EFI_PHYSICAL_ADDRESS EventLogLastEntry
,
540 IN EFI_TCG2_FINAL_EVENTS_TABLE
*FinalEventsTable
543 TCG_PCR_EVENT_HDR
*EventHdr
;
544 TCG_PCR_EVENT2
*TcgPcrEvent2
;
545 TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
;
546 UINTN NumberOfEvents
;
548 DEBUG ((EFI_D_INFO
, "EventLogFormat: (0x%x)\n", EventLogFormat
));
550 switch (EventLogFormat
) {
551 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
:
552 EventHdr
= (TCG_PCR_EVENT_HDR
*)(UINTN
)EventLogLocation
;
553 while ((UINTN
)EventHdr
<= EventLogLastEntry
) {
554 DumpEvent (EventHdr
);
555 EventHdr
= (TCG_PCR_EVENT_HDR
*)((UINTN
)EventHdr
+ sizeof(TCG_PCR_EVENT_HDR
) + EventHdr
->EventSize
);
557 if (FinalEventsTable
== NULL
) {
558 DEBUG ((EFI_D_INFO
, "FinalEventsTable: NOT FOUND\n"));
560 DEBUG ((EFI_D_INFO
, "FinalEventsTable: (0x%x)\n", FinalEventsTable
));
561 DEBUG ((EFI_D_INFO
, " Version: (0x%x)\n", FinalEventsTable
->Version
));
562 DEBUG ((EFI_D_INFO
, " NumberOfEvents: (0x%x)\n", FinalEventsTable
->NumberOfEvents
));
564 EventHdr
= (TCG_PCR_EVENT_HDR
*)(UINTN
)(FinalEventsTable
+ 1);
565 for (NumberOfEvents
= 0; NumberOfEvents
< FinalEventsTable
->NumberOfEvents
; NumberOfEvents
++) {
566 DumpEvent (EventHdr
);
567 EventHdr
= (TCG_PCR_EVENT_HDR
*)((UINTN
)EventHdr
+ sizeof(TCG_PCR_EVENT_HDR
) + EventHdr
->EventSize
);
571 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
:
575 EventHdr
= (TCG_PCR_EVENT_HDR
*)(UINTN
)EventLogLocation
;
576 DumpEvent (EventHdr
);
578 TcgEfiSpecIdEventStruct
= (TCG_EfiSpecIDEventStruct
*)(EventHdr
+ 1);
579 DumpTcgEfiSpecIdEventStruct (TcgEfiSpecIdEventStruct
);
581 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)((UINTN
)TcgEfiSpecIdEventStruct
+ GetTcgEfiSpecIdEventStructSize (TcgEfiSpecIdEventStruct
));
582 while ((UINTN
)TcgPcrEvent2
<= EventLogLastEntry
) {
583 DumpEvent2 (TcgPcrEvent2
);
584 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)((UINTN
)TcgPcrEvent2
+ GetPcrEvent2Size (TcgPcrEvent2
));
587 if (FinalEventsTable
== NULL
) {
588 DEBUG ((EFI_D_INFO
, "FinalEventsTable: NOT FOUND\n"));
590 DEBUG ((EFI_D_INFO
, "FinalEventsTable: (0x%x)\n", FinalEventsTable
));
591 DEBUG ((EFI_D_INFO
, " Version: (0x%x)\n", FinalEventsTable
->Version
));
592 DEBUG ((EFI_D_INFO
, " NumberOfEvents: (0x%x)\n", FinalEventsTable
->NumberOfEvents
));
594 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)(UINTN
)(FinalEventsTable
+ 1);
595 for (NumberOfEvents
= 0; NumberOfEvents
< FinalEventsTable
->NumberOfEvents
; NumberOfEvents
++) {
596 DumpEvent2 (TcgPcrEvent2
);
597 TcgPcrEvent2
= (TCG_PCR_EVENT2
*)((UINTN
)TcgPcrEvent2
+ GetPcrEvent2Size (TcgPcrEvent2
));
607 The EFI_TCG2_PROTOCOL Get Event Log function call allows a caller to
608 retrieve the address of a given event log and its last entry.
610 @param[in] This Indicates the calling context
611 @param[in] EventLogFormat The type of the event log for which the information is requested.
612 @param[out] EventLogLocation A pointer to the memory address of the event log.
613 @param[out] EventLogLastEntry If the Event Log contains more than one entry, this is a pointer to the
614 address of the start of the last entry in the event log in memory.
615 @param[out] EventLogTruncated If the Event Log is missing at least one entry because an event would
616 have exceeded the area allocated for events, this value is set to TRUE.
617 Otherwise, the value will be FALSE and the Event Log will be complete.
619 @retval EFI_SUCCESS Operation completed successfully.
620 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect
621 (e.g. asking for an event log whose format is not supported).
626 IN EFI_TCG2_PROTOCOL
*This
,
627 IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
,
628 OUT EFI_PHYSICAL_ADDRESS
*EventLogLocation
,
629 OUT EFI_PHYSICAL_ADDRESS
*EventLogLastEntry
,
630 OUT BOOLEAN
*EventLogTruncated
635 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog ... (0x%x)\n", EventLogFormat
));
638 return EFI_INVALID_PARAMETER
;
641 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
642 if (EventLogFormat
== mTcg2EventInfo
[Index
].LogFormat
) {
647 if (Index
== sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0])) {
648 return EFI_INVALID_PARAMETER
;
651 if ((mTcg2EventInfo
[Index
].LogFormat
& mTcgDxeData
.BsCap
.SupportedEventLogs
) == 0) {
652 return EFI_INVALID_PARAMETER
;
655 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
656 if (EventLogLocation
!= NULL
) {
657 *EventLogLocation
= 0;
659 if (EventLogLastEntry
!= NULL
) {
660 *EventLogLastEntry
= 0;
662 if (EventLogTruncated
!= NULL
) {
663 *EventLogTruncated
= FALSE
;
668 if (EventLogLocation
!= NULL
) {
669 *EventLogLocation
= mTcgDxeData
.EventLogAreaStruct
[Index
].Lasa
;
670 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog (EventLogLocation - %x)\n", *EventLogLocation
));
673 if (EventLogLastEntry
!= NULL
) {
674 if (!mTcgDxeData
.EventLogAreaStruct
[Index
].EventLogStarted
) {
675 *EventLogLastEntry
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)0;
677 *EventLogLastEntry
= (EFI_PHYSICAL_ADDRESS
)(UINTN
)mTcgDxeData
.EventLogAreaStruct
[Index
].LastEvent
;
679 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog (EventLogLastEntry - %x)\n", *EventLogLastEntry
));
682 if (EventLogTruncated
!= NULL
) {
683 *EventLogTruncated
= mTcgDxeData
.EventLogAreaStruct
[Index
].EventLogTruncated
;
684 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog (EventLogTruncated - %x)\n", *EventLogTruncated
));
687 DEBUG ((EFI_D_INFO
, "Tcg2GetEventLog - %r\n", EFI_SUCCESS
));
689 // Dump Event Log for debug purpose
690 if ((EventLogLocation
!= NULL
) && (EventLogLastEntry
!= NULL
)) {
691 DumpEventLog (EventLogFormat
, *EventLogLocation
, *EventLogLastEntry
, mTcgDxeData
.FinalEventsTable
[Index
]);
695 // All events generated after the invocation of EFI_TCG2_GET_EVENT_LOG SHALL be stored
696 // in an instance of an EFI_CONFIGURATION_TABLE named by the VendorGuid of EFI_TCG2_FINAL_EVENTS_TABLE_GUID.
698 mTcgDxeData
.GetEventLogCalled
[Index
] = TRUE
;
704 Add a new entry to the Event Log.
706 @param[in, out] EventLogPtr Pointer to the Event Log data.
707 @param[in, out] LogSize Size of the Event Log.
708 @param[in] MaxSize Maximum size of the Event Log.
709 @param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR/TCG_PCR_EVENT_EX data structure.
710 @param[in] NewEventHdrSize New event header size.
711 @param[in] NewEventData Pointer to the new event data.
712 @param[in] NewEventSize New event data size.
714 @retval EFI_SUCCESS The new event log entry was added.
715 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
720 IN OUT UINT8
**EventLogPtr
,
721 IN OUT UINTN
*LogSize
,
723 IN VOID
*NewEventHdr
,
724 IN UINT32 NewEventHdrSize
,
725 IN UINT8
*NewEventData
,
726 IN UINT32 NewEventSize
731 if (NewEventSize
> MAX_ADDRESS
- NewEventHdrSize
) {
732 return EFI_OUT_OF_RESOURCES
;
735 NewLogSize
= NewEventHdrSize
+ NewEventSize
;
737 if (NewLogSize
> MAX_ADDRESS
- *LogSize
) {
738 return EFI_OUT_OF_RESOURCES
;
741 if (NewLogSize
+ *LogSize
> MaxSize
) {
742 DEBUG ((EFI_D_INFO
, " MaxSize - 0x%x\n", MaxSize
));
743 DEBUG ((EFI_D_INFO
, " NewLogSize - 0x%x\n", NewLogSize
));
744 DEBUG ((EFI_D_INFO
, " LogSize - 0x%x\n", *LogSize
));
745 DEBUG ((EFI_D_INFO
, "TcgCommLogEvent - %r\n", EFI_OUT_OF_RESOURCES
));
746 return EFI_OUT_OF_RESOURCES
;
749 *EventLogPtr
+= *LogSize
;
750 *LogSize
+= NewLogSize
;
751 CopyMem (*EventLogPtr
, NewEventHdr
, NewEventHdrSize
);
753 *EventLogPtr
+ NewEventHdrSize
,
761 Add a new entry to the Event Log.
763 @param[in] EventLogFormat The type of the event log for which the information is requested.
764 @param[in] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR/TCG_PCR_EVENT_EX data structure.
765 @param[in] NewEventHdrSize New event header size.
766 @param[in] NewEventData Pointer to the new event data.
767 @param[in] NewEventSize New event data size.
769 @retval EFI_SUCCESS The new event log entry was added.
770 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
775 IN EFI_TCG2_EVENT_LOG_FORMAT EventLogFormat
,
776 IN VOID
*NewEventHdr
,
777 IN UINT32 NewEventHdrSize
,
778 IN UINT8
*NewEventData
,
779 IN UINT32 NewEventSize
784 TCG_EVENT_LOG_AREA_STRUCT
*EventLogAreaStruct
;
786 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
787 if (EventLogFormat
== mTcg2EventInfo
[Index
].LogFormat
) {
792 if (Index
== sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0])) {
793 return EFI_INVALID_PARAMETER
;
797 // Record to normal event log
799 EventLogAreaStruct
= &mTcgDxeData
.EventLogAreaStruct
[Index
];
801 if (EventLogAreaStruct
->EventLogTruncated
) {
802 return EFI_VOLUME_FULL
;
805 EventLogAreaStruct
->LastEvent
= (UINT8
*)(UINTN
)EventLogAreaStruct
->Lasa
;
806 Status
= TcgCommLogEvent (
807 &EventLogAreaStruct
->LastEvent
,
808 &EventLogAreaStruct
->EventLogSize
,
809 (UINTN
)EventLogAreaStruct
->Laml
,
816 if (Status
== EFI_OUT_OF_RESOURCES
) {
817 EventLogAreaStruct
->EventLogTruncated
= TRUE
;
818 return EFI_VOLUME_FULL
;
819 } else if (Status
== EFI_SUCCESS
) {
820 EventLogAreaStruct
->EventLogStarted
= TRUE
;
824 // If GetEventLog is called, record to FinalEventsTable, too.
826 if (mTcgDxeData
.GetEventLogCalled
[Index
]) {
827 if (mTcgDxeData
.FinalEventsTable
[Index
] == NULL
) {
829 // no need for FinalEventsTable
833 EventLogAreaStruct
= &mTcgDxeData
.FinalEventLogAreaStruct
[Index
];
835 if (EventLogAreaStruct
->EventLogTruncated
) {
836 return EFI_VOLUME_FULL
;
839 EventLogAreaStruct
->LastEvent
= (UINT8
*)(UINTN
)EventLogAreaStruct
->Lasa
;
840 Status
= TcgCommLogEvent (
841 &EventLogAreaStruct
->LastEvent
,
842 &EventLogAreaStruct
->EventLogSize
,
843 (UINTN
)EventLogAreaStruct
->Laml
,
849 if (Status
== EFI_OUT_OF_RESOURCES
) {
850 EventLogAreaStruct
->EventLogTruncated
= TRUE
;
851 return EFI_VOLUME_FULL
;
852 } else if (Status
== EFI_SUCCESS
) {
853 EventLogAreaStruct
->EventLogStarted
= TRUE
;
855 // Increase the NumberOfEvents in FinalEventsTable
857 (mTcgDxeData
.FinalEventsTable
[Index
])->NumberOfEvents
++;
858 DEBUG ((EFI_D_INFO
, "FinalEventsTable->NumberOfEvents - 0x%x\n", (mTcgDxeData
.FinalEventsTable
[Index
])->NumberOfEvents
));
859 DEBUG ((EFI_D_INFO
, " Size - 0x%x\n", (UINTN
)EventLogAreaStruct
->LastEvent
- (UINTN
)mTcgDxeData
.FinalEventsTable
[Index
]));
867 Get TPML_DIGEST_VALUES data size.
869 @param[in] DigestList TPML_DIGEST_VALUES data.
871 @return TPML_DIGEST_VALUES data size.
875 IN TPML_DIGEST_VALUES
*DigestList
882 TotalSize
= sizeof(DigestList
->count
);
883 for (Index
= 0; Index
< DigestList
->count
; Index
++) {
884 DigestSize
= GetHashSizeFromAlgo (DigestList
->digests
[Index
].hashAlg
);
885 TotalSize
+= sizeof(DigestList
->digests
[Index
].hashAlg
) + DigestSize
;
892 Get TPML_DIGEST_VALUES compact binary buffer size.
894 @param[in] DigestListBin TPML_DIGEST_VALUES compact binary buffer.
896 @return TPML_DIGEST_VALUES compact binary buffer size.
899 GetDigestListBinSize (
900 IN VOID
*DigestListBin
907 TPMI_ALG_HASH HashAlg
;
909 Count
= ReadUnaligned32 (DigestListBin
);
910 TotalSize
= sizeof(Count
);
911 DigestListBin
= (UINT8
*)DigestListBin
+ sizeof(Count
);
912 for (Index
= 0; Index
< Count
; Index
++) {
913 HashAlg
= ReadUnaligned16 (DigestListBin
);
914 TotalSize
+= sizeof(HashAlg
);
915 DigestListBin
= (UINT8
*)DigestListBin
+ sizeof(HashAlg
);
917 DigestSize
= GetHashSizeFromAlgo (HashAlg
);
918 TotalSize
+= DigestSize
;
919 DigestListBin
= (UINT8
*)DigestListBin
+ DigestSize
;
926 Return if hash alg is supported in TPM PCR bank.
928 @param HashAlg Hash algorithm to be checked.
930 @retval TRUE Hash algorithm is supported.
931 @retval FALSE Hash algorithm is not supported.
934 IsHashAlgSupportedInPcrBank (
935 IN TPMI_ALG_HASH HashAlg
940 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) != 0) {
945 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA256
) != 0) {
950 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA384
) != 0) {
955 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA512
) != 0) {
959 case TPM_ALG_SM3_256
:
960 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SM3_256
) != 0) {
970 Copy TPML_DIGEST_VALUES into a buffer
972 @param[in,out] Buffer Buffer to hold TPML_DIGEST_VALUES.
973 @param[in] DigestList TPML_DIGEST_VALUES to be copied.
975 @return The end of buffer to hold TPML_DIGEST_VALUES.
978 CopyDigestListToBuffer (
980 IN TPML_DIGEST_VALUES
*DigestList
986 CopyMem (Buffer
, &DigestList
->count
, sizeof(DigestList
->count
));
987 Buffer
= (UINT8
*)Buffer
+ sizeof(DigestList
->count
);
988 for (Index
= 0; Index
< DigestList
->count
; Index
++) {
989 if (!IsHashAlgSupportedInPcrBank (DigestList
->digests
[Index
].hashAlg
)) {
990 DEBUG ((EFI_D_ERROR
, "WARNING: TPM2 Event log has HashAlg unsupported by PCR bank (0x%x)\n", DigestList
->digests
[Index
].hashAlg
));
993 CopyMem (Buffer
, &DigestList
->digests
[Index
].hashAlg
, sizeof(DigestList
->digests
[Index
].hashAlg
));
994 Buffer
= (UINT8
*)Buffer
+ sizeof(DigestList
->digests
[Index
].hashAlg
);
995 DigestSize
= GetHashSizeFromAlgo (DigestList
->digests
[Index
].hashAlg
);
996 CopyMem (Buffer
, &DigestList
->digests
[Index
].digest
, DigestSize
);
997 Buffer
= (UINT8
*)Buffer
+ DigestSize
;
1004 Add a new entry to the Event Log.
1006 @param[in] DigestList A list of digest.
1007 @param[in,out] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
1008 @param[in] NewEventData Pointer to the new event data.
1010 @retval EFI_SUCCESS The new event log entry was added.
1011 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
1014 TcgDxeLogHashEvent (
1015 IN TPML_DIGEST_VALUES
*DigestList
,
1016 IN OUT TCG_PCR_EVENT_HDR
*NewEventHdr
,
1017 IN UINT8
*NewEventData
1023 EFI_STATUS RetStatus
;
1024 TCG_PCR_EVENT2 TcgPcrEvent2
;
1025 UINT8
*DigestBuffer
;
1027 DEBUG ((EFI_D_INFO
, "SupportedEventLogs - 0x%08x\n", mTcgDxeData
.BsCap
.SupportedEventLogs
));
1029 RetStatus
= EFI_SUCCESS
;
1030 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1031 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1032 DEBUG ((EFI_D_INFO
, " LogFormat - 0x%08x\n", mTcg2EventInfo
[Index
].LogFormat
));
1033 switch (mTcg2EventInfo
[Index
].LogFormat
) {
1034 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
:
1035 Status
= GetDigestFromDigestList (TPM_ALG_SHA1
, DigestList
, &NewEventHdr
->Digest
);
1036 if (!EFI_ERROR (Status
)) {
1038 // Enter critical region
1040 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
1041 Status
= TcgDxeLogEvent (
1042 mTcg2EventInfo
[Index
].LogFormat
,
1044 sizeof(TCG_PCR_EVENT_HDR
),
1046 NewEventHdr
->EventSize
1048 if (Status
!= EFI_SUCCESS
) {
1051 gBS
->RestoreTPL (OldTpl
);
1053 // Exit critical region
1057 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
:
1058 ZeroMem (&TcgPcrEvent2
, sizeof(TcgPcrEvent2
));
1059 TcgPcrEvent2
.PCRIndex
= NewEventHdr
->PCRIndex
;
1060 TcgPcrEvent2
.EventType
= NewEventHdr
->EventType
;
1061 DigestBuffer
= (UINT8
*)&TcgPcrEvent2
.Digest
;
1062 DigestBuffer
= CopyDigestListToBuffer (DigestBuffer
, DigestList
);
1063 CopyMem (DigestBuffer
, &NewEventHdr
->EventSize
, sizeof(NewEventHdr
->EventSize
));
1064 DigestBuffer
= DigestBuffer
+ sizeof(NewEventHdr
->EventSize
);
1067 // Enter critical region
1069 OldTpl
= gBS
->RaiseTPL (TPL_HIGH_LEVEL
);
1070 Status
= TcgDxeLogEvent (
1071 mTcg2EventInfo
[Index
].LogFormat
,
1073 sizeof(TcgPcrEvent2
.PCRIndex
) + sizeof(TcgPcrEvent2
.EventType
) + GetDigestListSize (DigestList
) + sizeof(TcgPcrEvent2
.EventSize
),
1075 NewEventHdr
->EventSize
1077 if (Status
!= EFI_SUCCESS
) {
1080 gBS
->RestoreTPL (OldTpl
);
1082 // Exit critical region
1093 Do a hash operation on a data buffer, extend a specific TPM PCR with the hash result,
1094 and add an entry to the Event Log.
1096 @param[in] Flags Bitmap providing additional information.
1097 @param[in] HashData Physical address of the start of the data buffer
1098 to be hashed, extended, and logged.
1099 @param[in] HashDataLen The length, in bytes, of the buffer referenced by HashData
1100 @param[in, out] NewEventHdr Pointer to a TCG_PCR_EVENT_HDR data structure.
1101 @param[in] NewEventData Pointer to the new event data.
1103 @retval EFI_SUCCESS Operation completed successfully.
1104 @retval EFI_OUT_OF_RESOURCES No enough memory to log the new event.
1105 @retval EFI_DEVICE_ERROR The command was unsuccessful.
1109 TcgDxeHashLogExtendEvent (
1112 IN UINT64 HashDataLen
,
1113 IN OUT TCG_PCR_EVENT_HDR
*NewEventHdr
,
1114 IN UINT8
*NewEventData
1118 TPML_DIGEST_VALUES DigestList
;
1120 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
1121 return EFI_DEVICE_ERROR
;
1124 Status
= HashAndExtend (
1125 NewEventHdr
->PCRIndex
,
1130 if (!EFI_ERROR (Status
)) {
1131 if ((Flags
& EFI_TCG2_EXTEND_ONLY
) == 0) {
1132 Status
= TcgDxeLogHashEvent (&DigestList
, NewEventHdr
, NewEventData
);
1136 if (Status
== EFI_DEVICE_ERROR
) {
1137 DEBUG ((EFI_D_ERROR
, "TcgDxeHashLogExtendEvent - %r. Disable TPM.\n", Status
));
1138 mTcgDxeData
.BsCap
.TPMPresentFlag
= FALSE
;
1139 REPORT_STATUS_CODE (
1140 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
1141 (PcdGet32 (PcdStatusCodeSubClassTpmDevice
) | EFI_P_EC_INTERFACE_ERROR
)
1149 The EFI_TCG2_PROTOCOL HashLogExtendEvent function call provides callers with
1150 an opportunity to extend and optionally log events without requiring
1151 knowledge of actual TPM commands.
1152 The extend operation will occur even if this function cannot create an event
1153 log entry (e.g. due to the event log being full).
1155 @param[in] This Indicates the calling context
1156 @param[in] Flags Bitmap providing additional information.
1157 @param[in] DataToHash Physical address of the start of the data buffer to be hashed.
1158 @param[in] DataToHashLen The length in bytes of the buffer referenced by DataToHash.
1159 @param[in] Event Pointer to data buffer containing information about the event.
1161 @retval EFI_SUCCESS Operation completed successfully.
1162 @retval EFI_DEVICE_ERROR The command was unsuccessful.
1163 @retval EFI_VOLUME_FULL The extend operation occurred, but the event could not be written to one or more event logs.
1164 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1165 @retval EFI_UNSUPPORTED The PE/COFF image type is not supported.
1169 Tcg2HashLogExtendEvent (
1170 IN EFI_TCG2_PROTOCOL
*This
,
1172 IN EFI_PHYSICAL_ADDRESS DataToHash
,
1173 IN UINT64 DataToHashLen
,
1174 IN EFI_TCG2_EVENT
*Event
1178 TCG_PCR_EVENT_HDR NewEventHdr
;
1179 TPML_DIGEST_VALUES DigestList
;
1181 DEBUG ((DEBUG_VERBOSE
, "Tcg2HashLogExtendEvent ...\n"));
1183 if ((This
== NULL
) || (DataToHash
== 0) || (Event
== NULL
)) {
1184 return EFI_INVALID_PARAMETER
;
1187 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
1188 return EFI_DEVICE_ERROR
;
1191 if (Event
->Size
< Event
->Header
.HeaderSize
+ sizeof(UINT32
)) {
1192 return EFI_INVALID_PARAMETER
;
1195 if (Event
->Header
.PCRIndex
> MAX_PCR_INDEX
) {
1196 return EFI_INVALID_PARAMETER
;
1199 NewEventHdr
.PCRIndex
= Event
->Header
.PCRIndex
;
1200 NewEventHdr
.EventType
= Event
->Header
.EventType
;
1201 NewEventHdr
.EventSize
= Event
->Size
- sizeof(UINT32
) - Event
->Header
.HeaderSize
;
1202 if ((Flags
& PE_COFF_IMAGE
) != 0) {
1203 Status
= MeasurePeImageAndExtend (
1204 NewEventHdr
.PCRIndex
,
1206 (UINTN
)DataToHashLen
,
1209 if (!EFI_ERROR (Status
)) {
1210 if ((Flags
& EFI_TCG2_EXTEND_ONLY
) == 0) {
1211 Status
= TcgDxeLogHashEvent (&DigestList
, &NewEventHdr
, Event
->Event
);
1214 if (Status
== EFI_DEVICE_ERROR
) {
1215 DEBUG ((EFI_D_ERROR
, "MeasurePeImageAndExtend - %r. Disable TPM.\n", Status
));
1216 mTcgDxeData
.BsCap
.TPMPresentFlag
= FALSE
;
1217 REPORT_STATUS_CODE (
1218 EFI_ERROR_CODE
| EFI_ERROR_MINOR
,
1219 (PcdGet32 (PcdStatusCodeSubClassTpmDevice
) | EFI_P_EC_INTERFACE_ERROR
)
1223 Status
= TcgDxeHashLogExtendEvent (
1225 (UINT8
*) (UINTN
) DataToHash
,
1231 DEBUG ((DEBUG_VERBOSE
, "Tcg2HashLogExtendEvent - %r\n", Status
));
1236 This service enables the sending of commands to the TPM.
1238 @param[in] This Indicates the calling context
1239 @param[in] InputParameterBlockSize Size of the TPM input parameter block.
1240 @param[in] InputParameterBlock Pointer to the TPM input parameter block.
1241 @param[in] OutputParameterBlockSize Size of the TPM output parameter block.
1242 @param[in] OutputParameterBlock Pointer to the TPM output parameter block.
1244 @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
1245 @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
1246 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1247 @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
1252 IN EFI_TCG2_PROTOCOL
*This
,
1253 IN UINT32 InputParameterBlockSize
,
1254 IN UINT8
*InputParameterBlock
,
1255 IN UINT32 OutputParameterBlockSize
,
1256 IN UINT8
*OutputParameterBlock
1261 DEBUG ((EFI_D_INFO
, "Tcg2SubmitCommand ...\n"));
1263 if ((This
== NULL
) ||
1264 (InputParameterBlockSize
== 0) || (InputParameterBlock
== NULL
) ||
1265 (OutputParameterBlockSize
== 0) || (OutputParameterBlock
== NULL
)) {
1266 return EFI_INVALID_PARAMETER
;
1269 if (!mTcgDxeData
.BsCap
.TPMPresentFlag
) {
1270 return EFI_DEVICE_ERROR
;
1273 if (InputParameterBlockSize
> mTcgDxeData
.BsCap
.MaxCommandSize
) {
1274 return EFI_INVALID_PARAMETER
;
1276 if (OutputParameterBlockSize
> mTcgDxeData
.BsCap
.MaxResponseSize
) {
1277 return EFI_INVALID_PARAMETER
;
1280 Status
= Tpm2SubmitCommand (
1281 InputParameterBlockSize
,
1282 InputParameterBlock
,
1283 &OutputParameterBlockSize
,
1284 OutputParameterBlock
1286 DEBUG ((EFI_D_INFO
, "Tcg2SubmitCommand - %r\n", Status
));
1291 This service returns the currently active PCR banks.
1293 @param[in] This Indicates the calling context
1294 @param[out] ActivePcrBanks Pointer to the variable receiving the bitmap of currently active PCR banks.
1296 @retval EFI_SUCCESS The bitmap of active PCR banks was stored in the ActivePcrBanks parameter.
1297 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1301 Tcg2GetActivePCRBanks (
1302 IN EFI_TCG2_PROTOCOL
*This
,
1303 OUT UINT32
*ActivePcrBanks
1306 if (ActivePcrBanks
== NULL
) {
1307 return EFI_INVALID_PARAMETER
;
1309 *ActivePcrBanks
= mTcgDxeData
.BsCap
.ActivePcrBanks
;
1314 This service sets the currently active PCR banks.
1316 @param[in] This Indicates the calling context
1317 @param[in] ActivePcrBanks Bitmap of the requested active PCR banks. At least one bit SHALL be set.
1319 @retval EFI_SUCCESS The bitmap in ActivePcrBank parameter is already active.
1320 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1324 Tcg2SetActivePCRBanks (
1325 IN EFI_TCG2_PROTOCOL
*This
,
1326 IN UINT32 ActivePcrBanks
1332 DEBUG ((EFI_D_INFO
, "Tcg2SetActivePCRBanks ... (0x%x)\n", ActivePcrBanks
));
1334 if (ActivePcrBanks
== 0) {
1335 return EFI_INVALID_PARAMETER
;
1337 if ((ActivePcrBanks
& (~mTcgDxeData
.BsCap
.HashAlgorithmBitmap
)) != 0) {
1338 return EFI_INVALID_PARAMETER
;
1340 if (ActivePcrBanks
== mTcgDxeData
.BsCap
.ActivePcrBanks
) {
1342 // Need clear previous SET_PCR_BANKS setting
1344 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_NO_ACTION
, 0);
1346 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS
, ActivePcrBanks
);
1349 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
1350 Status
= EFI_SUCCESS
;
1351 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
1352 Status
= EFI_OUT_OF_RESOURCES
;
1353 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
1354 Status
= EFI_UNSUPPORTED
;
1356 Status
= EFI_DEVICE_ERROR
;
1359 DEBUG ((EFI_D_INFO
, "Tcg2SetActivePCRBanks - %r\n", Status
));
1365 This service retrieves the result of a previous invocation of SetActivePcrBanks.
1367 @param[in] This Indicates the calling context
1368 @param[out] OperationPresent Non-zero value to indicate a SetActivePcrBank operation was invoked during the last boot.
1369 @param[out] Response The response from the SetActivePcrBank request.
1371 @retval EFI_SUCCESS The result value could be returned.
1372 @retval EFI_INVALID_PARAMETER One or more of the parameters are incorrect.
1376 Tcg2GetResultOfSetActivePcrBanks (
1377 IN EFI_TCG2_PROTOCOL
*This
,
1378 OUT UINT32
*OperationPresent
,
1379 OUT UINT32
*Response
1384 if ((OperationPresent
== NULL
) || (Response
== NULL
)) {
1385 return EFI_INVALID_PARAMETER
;
1388 ReturnCode
= Tcg2PhysicalPresenceLibReturnOperationResponseToOsFunction (OperationPresent
, Response
);
1389 if (ReturnCode
== TCG_PP_RETURN_TPM_OPERATION_RESPONSE_SUCCESS
) {
1392 return EFI_UNSUPPORTED
;
1396 EFI_TCG2_PROTOCOL mTcg2Protocol
= {
1399 Tcg2HashLogExtendEvent
,
1401 Tcg2GetActivePCRBanks
,
1402 Tcg2SetActivePCRBanks
,
1403 Tcg2GetResultOfSetActivePcrBanks
,
1407 Initialize the Event Log and log events passed from the PEI phase.
1409 @retval EFI_SUCCESS Operation completed successfully.
1410 @retval EFI_OUT_OF_RESOURCES Out of memory.
1420 EFI_PEI_HOB_POINTERS GuidHob
;
1421 EFI_PHYSICAL_ADDRESS Lasa
;
1423 UINT32 DigestListBinSize
;
1425 TCG_EfiSpecIDEventStruct
*TcgEfiSpecIdEventStruct
;
1426 UINT8 TempBuf
[sizeof(TCG_EfiSpecIDEventStruct
) + sizeof(UINT32
) + (HASH_COUNT
* sizeof(TCG_EfiSpecIdEventAlgorithmSize
)) + sizeof(UINT8
)];
1427 TCG_PCR_EVENT_HDR FirstPcrEvent
;
1428 TCG_EfiSpecIdEventAlgorithmSize
*DigestSize
;
1429 TCG_EfiSpecIdEventAlgorithmSize
*TempDigestSize
;
1430 UINT8
*VendorInfoSize
;
1431 UINT32 NumberOfAlgorithms
;
1433 DEBUG ((EFI_D_INFO
, "SetupEventLog\n"));
1436 // 1. Create Log Area
1438 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1439 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1440 mTcgDxeData
.EventLogAreaStruct
[Index
].EventLogFormat
= mTcg2EventInfo
[Index
].LogFormat
;
1441 Lasa
= (EFI_PHYSICAL_ADDRESS
) (SIZE_4GB
- 1);
1442 Status
= gBS
->AllocatePages (
1444 EfiBootServicesData
,
1445 EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcgLogAreaMinLen
)),
1448 if (EFI_ERROR (Status
)) {
1451 mTcgDxeData
.EventLogAreaStruct
[Index
].Lasa
= Lasa
;
1452 mTcgDxeData
.EventLogAreaStruct
[Index
].Laml
= PcdGet32 (PcdTcgLogAreaMinLen
);
1454 // To initialize them as 0xFF is recommended
1455 // because the OS can know the last entry for that.
1457 SetMem ((VOID
*)(UINTN
)Lasa
, PcdGet32 (PcdTcgLogAreaMinLen
), 0xFF);
1459 // Create first entry for Log Header Entry Data
1461 if (mTcg2EventInfo
[Index
].LogFormat
!= EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
) {
1463 // TcgEfiSpecIdEventStruct
1465 TcgEfiSpecIdEventStruct
= (TCG_EfiSpecIDEventStruct
*)TempBuf
;
1466 CopyMem (TcgEfiSpecIdEventStruct
->signature
, TCG_EfiSpecIDEventStruct_SIGNATURE_03
, sizeof(TcgEfiSpecIdEventStruct
->signature
));
1467 TcgEfiSpecIdEventStruct
->platformClass
= PcdGet8 (PcdTpmPlatformClass
);
1468 TcgEfiSpecIdEventStruct
->specVersionMajor
= TCG_EfiSpecIDEventStruct_SPEC_VERSION_MAJOR_TPM2
;
1469 TcgEfiSpecIdEventStruct
->specVersionMinor
= TCG_EfiSpecIDEventStruct_SPEC_VERSION_MINOR_TPM2
;
1470 TcgEfiSpecIdEventStruct
->specErrata
= TCG_EfiSpecIDEventStruct_SPEC_ERRATA_TPM2
;
1471 TcgEfiSpecIdEventStruct
->uintnSize
= sizeof(UINTN
)/sizeof(UINT32
);
1472 NumberOfAlgorithms
= 0;
1473 DigestSize
= (TCG_EfiSpecIdEventAlgorithmSize
*)((UINT8
*)TcgEfiSpecIdEventStruct
+ sizeof(*TcgEfiSpecIdEventStruct
) + sizeof(NumberOfAlgorithms
));
1474 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) != 0) {
1475 TempDigestSize
= DigestSize
;
1476 TempDigestSize
+= NumberOfAlgorithms
;
1477 TempDigestSize
->algorithmId
= TPM_ALG_SHA1
;
1478 TempDigestSize
->digestSize
= SHA1_DIGEST_SIZE
;
1479 NumberOfAlgorithms
++;
1481 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA256
) != 0) {
1482 TempDigestSize
= DigestSize
;
1483 TempDigestSize
+= NumberOfAlgorithms
;
1484 TempDigestSize
->algorithmId
= TPM_ALG_SHA256
;
1485 TempDigestSize
->digestSize
= SHA256_DIGEST_SIZE
;
1486 NumberOfAlgorithms
++;
1488 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA384
) != 0) {
1489 TempDigestSize
= DigestSize
;
1490 TempDigestSize
+= NumberOfAlgorithms
;
1491 TempDigestSize
->algorithmId
= TPM_ALG_SHA384
;
1492 TempDigestSize
->digestSize
= SHA384_DIGEST_SIZE
;
1493 NumberOfAlgorithms
++;
1495 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA512
) != 0) {
1496 TempDigestSize
= DigestSize
;
1497 TempDigestSize
+= NumberOfAlgorithms
;
1498 TempDigestSize
->algorithmId
= TPM_ALG_SHA512
;
1499 TempDigestSize
->digestSize
= SHA512_DIGEST_SIZE
;
1500 NumberOfAlgorithms
++;
1502 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SM3_256
) != 0) {
1503 TempDigestSize
= DigestSize
;
1504 TempDigestSize
+= NumberOfAlgorithms
;
1505 TempDigestSize
->algorithmId
= TPM_ALG_SM3_256
;
1506 TempDigestSize
->digestSize
= SM3_256_DIGEST_SIZE
;
1507 NumberOfAlgorithms
++;
1509 CopyMem (TcgEfiSpecIdEventStruct
+ 1, &NumberOfAlgorithms
, sizeof(NumberOfAlgorithms
));
1510 TempDigestSize
= DigestSize
;
1511 TempDigestSize
+= NumberOfAlgorithms
;
1512 VendorInfoSize
= (UINT8
*)TempDigestSize
;
1513 *VendorInfoSize
= 0;
1518 FirstPcrEvent
.PCRIndex
= 0;
1519 FirstPcrEvent
.EventType
= EV_NO_ACTION
;
1520 ZeroMem (&FirstPcrEvent
.Digest
, sizeof(FirstPcrEvent
.Digest
));
1521 FirstPcrEvent
.EventSize
= (UINT32
)GetTcgEfiSpecIdEventStructSize (TcgEfiSpecIdEventStruct
);
1526 Status
= TcgDxeLogEvent (
1527 mTcg2EventInfo
[Index
].LogFormat
,
1529 sizeof(FirstPcrEvent
),
1530 (UINT8
*)TcgEfiSpecIdEventStruct
,
1531 FirstPcrEvent
.EventSize
1538 // 2. Create Final Log Area
1540 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1541 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1542 if (mTcg2EventInfo
[Index
].LogFormat
== EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
) {
1543 Lasa
= (EFI_PHYSICAL_ADDRESS
) (SIZE_4GB
- 1);
1544 Status
= gBS
->AllocatePages (
1547 EFI_SIZE_TO_PAGES (PcdGet32 (PcdTcg2FinalLogAreaLen
)),
1550 if (EFI_ERROR (Status
)) {
1553 SetMem ((VOID
*)(UINTN
)Lasa
, PcdGet32 (PcdTcg2FinalLogAreaLen
), 0xFF);
1558 mTcgDxeData
.FinalEventsTable
[Index
] = (VOID
*)(UINTN
)Lasa
;
1559 (mTcgDxeData
.FinalEventsTable
[Index
])->Version
= EFI_TCG2_FINAL_EVENTS_TABLE_VERSION
;
1560 (mTcgDxeData
.FinalEventsTable
[Index
])->NumberOfEvents
= 0;
1562 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogFormat
= mTcg2EventInfo
[Index
].LogFormat
;
1563 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Lasa
= Lasa
+ sizeof(EFI_TCG2_FINAL_EVENTS_TABLE
);
1564 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Laml
= PcdGet32 (PcdTcg2FinalLogAreaLen
) - sizeof(EFI_TCG2_FINAL_EVENTS_TABLE
);
1565 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogSize
= 0;
1566 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].LastEvent
= (VOID
*)(UINTN
)mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Lasa
;
1567 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogStarted
= FALSE
;
1568 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogTruncated
= FALSE
;
1571 // Install to configuration table for EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
1573 Status
= gBS
->InstallConfigurationTable (&gEfiTcg2FinalEventsTableGuid
, (VOID
*)mTcgDxeData
.FinalEventsTable
[Index
]);
1574 if (EFI_ERROR (Status
)) {
1579 // No need to handle EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
1581 mTcgDxeData
.FinalEventsTable
[Index
] = NULL
;
1582 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogFormat
= mTcg2EventInfo
[Index
].LogFormat
;
1583 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Lasa
= 0;
1584 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].Laml
= 0;
1585 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogSize
= 0;
1586 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].LastEvent
= 0;
1587 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogStarted
= FALSE
;
1588 mTcgDxeData
.FinalEventLogAreaStruct
[Index
].EventLogTruncated
= FALSE
;
1594 // 3. Sync data from PEI to DXE
1596 Status
= EFI_SUCCESS
;
1597 for (Index
= 0; Index
< sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]); Index
++) {
1598 if ((mTcgDxeData
.BsCap
.SupportedEventLogs
& mTcg2EventInfo
[Index
].LogFormat
) != 0) {
1599 GuidHob
.Raw
= GetHobList ();
1600 Status
= EFI_SUCCESS
;
1601 while (!EFI_ERROR (Status
) &&
1602 (GuidHob
.Raw
= GetNextGuidHob (mTcg2EventInfo
[Index
].EventGuid
, GuidHob
.Raw
)) != NULL
) {
1603 TcgEvent
= GET_GUID_HOB_DATA (GuidHob
.Guid
);
1604 GuidHob
.Raw
= GET_NEXT_HOB (GuidHob
);
1605 switch (mTcg2EventInfo
[Index
].LogFormat
) {
1606 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
:
1607 Status
= TcgDxeLogEvent (
1608 mTcg2EventInfo
[Index
].LogFormat
,
1610 sizeof(TCG_PCR_EVENT_HDR
),
1611 ((TCG_PCR_EVENT
*)TcgEvent
)->Event
,
1612 ((TCG_PCR_EVENT_HDR
*)TcgEvent
)->EventSize
1615 case EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
:
1616 DigestListBinSize
= GetDigestListBinSize ((UINT8
*)TcgEvent
+ sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
));
1617 CopyMem (&EventSize
, (UINT8
*)TcgEvent
+ sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
) + DigestListBinSize
, sizeof(UINT32
));
1618 Status
= TcgDxeLogEvent (
1619 mTcg2EventInfo
[Index
].LogFormat
,
1621 sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
) + DigestListBinSize
+ sizeof(UINT32
),
1622 (UINT8
*)TcgEvent
+ sizeof(TCG_PCRINDEX
) + sizeof(TCG_EVENTTYPE
) + DigestListBinSize
+ sizeof(UINT32
),
1635 Measure and log an action string, and extend the measurement result into PCR[5].
1637 @param[in] String A specific string that indicates an Action event.
1639 @retval EFI_SUCCESS Operation completed successfully.
1640 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1648 TCG_PCR_EVENT_HDR TcgEvent
;
1650 TcgEvent
.PCRIndex
= 5;
1651 TcgEvent
.EventType
= EV_EFI_ACTION
;
1652 TcgEvent
.EventSize
= (UINT32
)AsciiStrLen (String
);
1653 return TcgDxeHashLogExtendEvent (
1663 Measure and log EFI handoff tables, and extend the measurement result into PCR[1].
1665 @retval EFI_SUCCESS Operation completed successfully.
1666 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1670 MeasureHandoffTables (
1675 TCG_PCR_EVENT_HDR TcgEvent
;
1676 EFI_HANDOFF_TABLE_POINTERS HandoffTables
;
1678 EFI_CPU_PHYSICAL_LOCATION
*ProcessorLocBuf
;
1680 ProcessorLocBuf
= NULL
;
1681 Status
= EFI_SUCCESS
;
1683 if (PcdGet8 (PcdTpmPlatformClass
) == TCG_PLATFORM_TYPE_SERVER
) {
1686 // Measure each processor EFI_CPU_PHYSICAL_LOCATION with EV_TABLE_OF_DEVICES to PCR[1]
1688 Status
= GetProcessorsCpuLocation(&ProcessorLocBuf
, &ProcessorNum
);
1690 if (!EFI_ERROR(Status
)){
1691 TcgEvent
.PCRIndex
= 1;
1692 TcgEvent
.EventType
= EV_TABLE_OF_DEVICES
;
1693 TcgEvent
.EventSize
= sizeof (HandoffTables
);
1695 HandoffTables
.NumberOfTables
= 1;
1696 HandoffTables
.TableEntry
[0].VendorGuid
= gEfiMpServiceProtocolGuid
;
1697 HandoffTables
.TableEntry
[0].VendorTable
= ProcessorLocBuf
;
1699 Status
= TcgDxeHashLogExtendEvent (
1701 (UINT8
*)(UINTN
)ProcessorLocBuf
,
1702 sizeof(EFI_CPU_PHYSICAL_LOCATION
) * ProcessorNum
,
1704 (UINT8
*)&HandoffTables
1707 FreePool(ProcessorLocBuf
);
1715 Measure and log Separator event, and extend the measurement result into a specific PCR.
1717 @param[in] PCRIndex PCR index.
1719 @retval EFI_SUCCESS Operation completed successfully.
1720 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1724 MeasureSeparatorEvent (
1725 IN TPM_PCRINDEX PCRIndex
1728 TCG_PCR_EVENT_HDR TcgEvent
;
1731 DEBUG ((EFI_D_INFO
, "MeasureSeparatorEvent Pcr - %x\n", PCRIndex
));
1734 TcgEvent
.PCRIndex
= PCRIndex
;
1735 TcgEvent
.EventType
= EV_SEPARATOR
;
1736 TcgEvent
.EventSize
= (UINT32
)sizeof (EventData
);
1737 return TcgDxeHashLogExtendEvent (
1739 (UINT8
*)&EventData
,
1747 Measure and log an EFI variable, and extend the measurement result into a specific PCR.
1749 @param[in] PCRIndex PCR Index.
1750 @param[in] EventType Event type.
1751 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1752 @param[in] VendorGuid A unique identifier for the vendor.
1753 @param[in] VarData The content of the variable data.
1754 @param[in] VarSize The size of the variable data.
1756 @retval EFI_SUCCESS Operation completed successfully.
1757 @retval EFI_OUT_OF_RESOURCES Out of memory.
1758 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1763 IN TPM_PCRINDEX PCRIndex
,
1764 IN TCG_EVENTTYPE EventType
,
1766 IN EFI_GUID
*VendorGuid
,
1772 TCG_PCR_EVENT_HDR TcgEvent
;
1773 UINTN VarNameLength
;
1774 EFI_VARIABLE_DATA_TREE
*VarLog
;
1776 DEBUG ((EFI_D_INFO
, "Tcg2Dxe: MeasureVariable (Pcr - %x, EventType - %x, ", (UINTN
)PCRIndex
, (UINTN
)EventType
));
1777 DEBUG ((EFI_D_INFO
, "VariableName - %s, VendorGuid - %g)\n", VarName
, VendorGuid
));
1779 VarNameLength
= StrLen (VarName
);
1780 TcgEvent
.PCRIndex
= PCRIndex
;
1781 TcgEvent
.EventType
= EventType
;
1783 TcgEvent
.EventSize
= (UINT32
)(sizeof (*VarLog
) + VarNameLength
* sizeof (*VarName
) + VarSize
1784 - sizeof (VarLog
->UnicodeName
) - sizeof (VarLog
->VariableData
));
1786 VarLog
= (EFI_VARIABLE_DATA_TREE
*)AllocatePool (TcgEvent
.EventSize
);
1787 if (VarLog
== NULL
) {
1788 return EFI_OUT_OF_RESOURCES
;
1791 VarLog
->VariableName
= *VendorGuid
;
1792 VarLog
->UnicodeNameLength
= VarNameLength
;
1793 VarLog
->VariableDataLength
= VarSize
;
1795 VarLog
->UnicodeName
,
1797 VarNameLength
* sizeof (*VarName
)
1799 if (VarSize
!= 0 && VarData
!= NULL
) {
1801 (CHAR16
*)VarLog
->UnicodeName
+ VarNameLength
,
1807 if (EventType
== EV_EFI_VARIABLE_DRIVER_CONFIG
) {
1809 // Digest is the event data (EFI_VARIABLE_DATA)
1811 Status
= TcgDxeHashLogExtendEvent (
1819 Status
= TcgDxeHashLogExtendEvent (
1832 Read then Measure and log an EFI variable, and extend the measurement result into a specific PCR.
1834 @param[in] PCRIndex PCR Index.
1835 @param[in] EventType Event type.
1836 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1837 @param[in] VendorGuid A unique identifier for the vendor.
1838 @param[out] VarSize The size of the variable data.
1839 @param[out] VarData Pointer to the content of the variable.
1841 @retval EFI_SUCCESS Operation completed successfully.
1842 @retval EFI_OUT_OF_RESOURCES Out of memory.
1843 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1847 ReadAndMeasureVariable (
1848 IN TPM_PCRINDEX PCRIndex
,
1849 IN TCG_EVENTTYPE EventType
,
1851 IN EFI_GUID
*VendorGuid
,
1858 Status
= GetVariable2 (VarName
, VendorGuid
, VarData
, VarSize
);
1859 if (EventType
== EV_EFI_VARIABLE_DRIVER_CONFIG
) {
1860 if (EFI_ERROR (Status
)) {
1862 // It is valid case, so we need handle it.
1869 // if status error, VarData is freed and set NULL by GetVariable2
1871 if (EFI_ERROR (Status
)) {
1872 return EFI_NOT_FOUND
;
1876 Status
= MeasureVariable (
1888 Read then Measure and log an EFI boot variable, and extend the measurement result into PCR[5].
1890 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1891 @param[in] VendorGuid A unique identifier for the vendor.
1892 @param[out] VarSize The size of the variable data.
1893 @param[out] VarData Pointer to the content of the variable.
1895 @retval EFI_SUCCESS Operation completed successfully.
1896 @retval EFI_OUT_OF_RESOURCES Out of memory.
1897 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1901 ReadAndMeasureBootVariable (
1903 IN EFI_GUID
*VendorGuid
,
1908 return ReadAndMeasureVariable (
1910 EV_EFI_VARIABLE_BOOT
,
1919 Read then Measure and log an EFI Secure variable, and extend the measurement result into PCR[7].
1921 @param[in] VarName A Null-terminated string that is the name of the vendor's variable.
1922 @param[in] VendorGuid A unique identifier for the vendor.
1923 @param[out] VarSize The size of the variable data.
1924 @param[out] VarData Pointer to the content of the variable.
1926 @retval EFI_SUCCESS Operation completed successfully.
1927 @retval EFI_OUT_OF_RESOURCES Out of memory.
1928 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
1932 ReadAndMeasureSecureVariable (
1934 IN EFI_GUID
*VendorGuid
,
1939 return ReadAndMeasureVariable (
1941 EV_EFI_VARIABLE_DRIVER_CONFIG
,
1950 Measure and log all EFI boot variables, and extend the measurement result into a specific PCR.
1952 The EFI boot variables are BootOrder and Boot#### variables.
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 MeasureAllBootVariables (
1971 Status
= ReadAndMeasureBootVariable (
1973 &gEfiGlobalVariableGuid
,
1975 (VOID
**) &BootOrder
1977 if (Status
== EFI_NOT_FOUND
|| BootOrder
== NULL
) {
1981 if (EFI_ERROR (Status
)) {
1983 // BootOrder can't be NULL if status is not EFI_NOT_FOUND
1985 FreePool (BootOrder
);
1989 BootCount
/= sizeof (*BootOrder
);
1990 for (Index
= 0; Index
< BootCount
; Index
++) {
1991 UnicodeSPrint (mBootVarName
, sizeof (mBootVarName
), L
"Boot%04x", BootOrder
[Index
]);
1992 Status
= ReadAndMeasureBootVariable (
1994 &gEfiGlobalVariableGuid
,
1998 if (!EFI_ERROR (Status
)) {
1999 FreePool (BootVarData
);
2003 FreePool (BootOrder
);
2008 Measure and log all EFI Secure variables, and extend the measurement result into a specific PCR.
2010 The EFI boot variables are BootOrder and Boot#### variables.
2012 @retval EFI_SUCCESS Operation completed successfully.
2013 @retval EFI_OUT_OF_RESOURCES Out of memory.
2014 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
2018 MeasureAllSecureVariables (
2027 Status
= EFI_NOT_FOUND
;
2028 for (Index
= 0; Index
< sizeof(mVariableType
)/sizeof(mVariableType
[0]); Index
++) {
2029 Status
= ReadAndMeasureSecureVariable (
2030 mVariableType
[Index
].VariableName
,
2031 mVariableType
[Index
].VendorGuid
,
2035 if (!EFI_ERROR (Status
)) {
2046 Measure and log launch of FirmwareDebugger, and extend the measurement result into a specific PCR.
2048 @retval EFI_SUCCESS Operation completed successfully.
2049 @retval EFI_OUT_OF_RESOURCES Out of memory.
2050 @retval EFI_DEVICE_ERROR The operation was unsuccessful.
2054 MeasureLaunchOfFirmwareDebugger (
2058 TCG_PCR_EVENT_HDR TcgEvent
;
2060 TcgEvent
.PCRIndex
= 7;
2061 TcgEvent
.EventType
= EV_EFI_ACTION
;
2062 TcgEvent
.EventSize
= sizeof(FIRMWARE_DEBUGGER_EVENT_STRING
) - 1;
2063 return TcgDxeHashLogExtendEvent (
2065 (UINT8
*)FIRMWARE_DEBUGGER_EVENT_STRING
,
2066 sizeof(FIRMWARE_DEBUGGER_EVENT_STRING
) - 1,
2068 (UINT8
*)FIRMWARE_DEBUGGER_EVENT_STRING
2073 Measure and log all Secure Boot Policy, and extend the measurement result into a specific PCR.
2075 Platform firmware adhering to the policy must therefore measure the following values into PCR[7]: (in order listed)
2076 - The contents of the SecureBoot variable
2077 - The contents of the PK variable
2078 - The contents of the KEK variable
2079 - The contents of the EFI_IMAGE_SECURITY_DATABASE variable
2080 - The contents of the EFI_IMAGE_SECURITY_DATABASE1 variable
2082 - Entries in the EFI_IMAGE_SECURITY_DATABASE that are used to validate EFI Drivers or EFI Boot Applications in the boot path
2084 NOTE: Because of the above, UEFI variables PK, KEK, EFI_IMAGE_SECURITY_DATABASE,
2085 EFI_IMAGE_SECURITY_DATABASE1 and SecureBoot SHALL NOT be measured into PCR[3].
2087 @param[in] Event Event whose notification function is being invoked
2088 @param[in] Context Pointer to the notification function's context
2092 MeasureSecureBootPolicy (
2100 Status
= gBS
->LocateProtocol (&gEfiVariableWriteArchProtocolGuid
, NULL
, (VOID
**)&Protocol
);
2101 if (EFI_ERROR (Status
)) {
2105 if (PcdGetBool (PcdFirmwareDebuggerInitialized
)) {
2106 Status
= MeasureLaunchOfFirmwareDebugger ();
2107 DEBUG ((EFI_D_INFO
, "MeasureLaunchOfFirmwareDebugger - %r\n", Status
));
2110 Status
= MeasureAllSecureVariables ();
2111 DEBUG ((EFI_D_INFO
, "MeasureAllSecureVariables - %r\n", Status
));
2114 // We need measure Separator(7) here, because this event must be between SecureBootPolicy (Configure)
2115 // and ImageVerification (Authority)
2116 // There might be a case that we need measure UEFI image from DriverOrder, besides BootOrder. So
2117 // the Authority measurement happen before ReadToBoot event.
2119 Status
= MeasureSeparatorEvent (7);
2120 DEBUG ((EFI_D_INFO
, "MeasureSeparatorEvent - %r\n", Status
));
2125 Ready to Boot Event notification handler.
2127 Sequence of OS boot events is measured in this event notification handler.
2129 @param[in] Event Event whose notification function is being invoked
2130 @param[in] Context Pointer to the notification function's context
2141 TPM_PCRINDEX PcrIndex
;
2143 PERF_START_EX (mImageHandle
, "EventRec", "Tcg2Dxe", 0, PERF_ID_TCG2_DXE
);
2144 if (mBootAttempts
== 0) {
2147 // Measure handoff tables.
2149 Status
= MeasureHandoffTables ();
2150 if (EFI_ERROR (Status
)) {
2151 DEBUG ((EFI_D_ERROR
, "HOBs not Measured. Error!\n"));
2155 // Measure BootOrder & Boot#### variables.
2157 Status
= MeasureAllBootVariables ();
2158 if (EFI_ERROR (Status
)) {
2159 DEBUG ((EFI_D_ERROR
, "Boot Variables not Measured. Error!\n"));
2163 // 1. This is the first boot attempt.
2165 Status
= TcgMeasureAction (
2166 EFI_CALLING_EFI_APPLICATION
2168 if (EFI_ERROR (Status
)) {
2169 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_CALLING_EFI_APPLICATION
));
2173 // 2. Draw a line between pre-boot env and entering post-boot env.
2174 // PCR[7] is already done.
2176 for (PcrIndex
= 0; PcrIndex
< 7; PcrIndex
++) {
2177 Status
= MeasureSeparatorEvent (PcrIndex
);
2178 if (EFI_ERROR (Status
)) {
2179 DEBUG ((EFI_D_ERROR
, "Seperator Event not Measured. Error!\n"));
2184 // 3. Measure GPT. It would be done in SAP driver.
2188 // 4. Measure PE/COFF OS loader. It would be done in SAP driver.
2192 // 5. Read & Measure variable. BootOrder already measured.
2196 // 6. Not first attempt, meaning a return from last attempt
2198 Status
= TcgMeasureAction (
2199 EFI_RETURNING_FROM_EFI_APPLICATOIN
2201 if (EFI_ERROR (Status
)) {
2202 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_RETURNING_FROM_EFI_APPLICATOIN
));
2206 DEBUG ((EFI_D_INFO
, "TPM2 Tcg2Dxe Measure Data when ReadyToBoot\n"));
2208 // Increase boot attempt counter.
2211 PERF_END_EX (mImageHandle
, "EventRec", "Tcg2Dxe", 0, PERF_ID_TCG2_DXE
+ 1);
2215 Exit Boot Services Event notification handler.
2217 Measure invocation and success of ExitBootServices.
2219 @param[in] Event Event whose notification function is being invoked
2220 @param[in] Context Pointer to the notification function's context
2225 OnExitBootServices (
2233 // Measure invocation of ExitBootServices,
2235 Status
= TcgMeasureAction (
2236 EFI_EXIT_BOOT_SERVICES_INVOCATION
2238 if (EFI_ERROR (Status
)) {
2239 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_INVOCATION
));
2243 // Measure success of ExitBootServices
2245 Status
= TcgMeasureAction (
2246 EFI_EXIT_BOOT_SERVICES_SUCCEEDED
2248 if (EFI_ERROR (Status
)) {
2249 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_SUCCEEDED
));
2254 Exit Boot Services Failed Event notification handler.
2256 Measure Failure of ExitBootServices.
2258 @param[in] Event Event whose notification function is being invoked
2259 @param[in] Context Pointer to the notification function's context
2264 OnExitBootServicesFailed (
2272 // Measure Failure of ExitBootServices,
2274 Status
= TcgMeasureAction (
2275 EFI_EXIT_BOOT_SERVICES_FAILED
2277 if (EFI_ERROR (Status
)) {
2278 DEBUG ((EFI_D_ERROR
, "%a not Measured. Error!\n", EFI_EXIT_BOOT_SERVICES_FAILED
));
2284 The function install Tcg2 protocol.
2286 @retval EFI_SUCCESS Tcg2 protocol is installed.
2287 @retval other Some error occurs.
2298 Status
= gBS
->InstallMultipleProtocolInterfaces (
2300 &gEfiTcg2ProtocolGuid
,
2308 The driver's entry point. It publishes EFI Tcg2 Protocol.
2310 @param[in] ImageHandle The firmware allocated handle for the EFI image.
2311 @param[in] SystemTable A pointer to the EFI System Table.
2313 @retval EFI_SUCCESS The entry point is executed successfully.
2314 @retval other Some error occurs when executing this entry point.
2319 IN EFI_HANDLE ImageHandle
,
2320 IN EFI_SYSTEM_TABLE
*SystemTable
2326 UINT32 MaxCommandSize
;
2327 UINT32 MaxResponseSize
;
2328 TPML_PCR_SELECTION Pcrs
;
2330 EFI_TCG2_EVENT_ALGORITHM_BITMAP TpmHashAlgorithmBitmap
;
2331 UINT32 ActivePCRBanks
;
2332 UINT32 NumberOfPCRBanks
;
2334 mImageHandle
= ImageHandle
;
2336 if (CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &gEfiTpmDeviceInstanceNoneGuid
) ||
2337 CompareGuid (PcdGetPtr(PcdTpmInstanceGuid
), &gEfiTpmDeviceInstanceTpm12Guid
)){
2338 DEBUG ((EFI_D_ERROR
, "No TPM2 instance required!\n"));
2339 return EFI_UNSUPPORTED
;
2342 if (GetFirstGuidHob (&gTpmErrorHobGuid
) != NULL
) {
2343 DEBUG ((EFI_D_ERROR
, "TPM2 error!\n"));
2344 return EFI_DEVICE_ERROR
;
2347 Status
= Tpm2RequestUseTpm ();
2348 if (EFI_ERROR (Status
)) {
2349 DEBUG ((EFI_D_ERROR
, "TPM2 not detected!\n"));
2356 ASSERT (TCG_EVENT_LOG_AREA_COUNT_MAX
== sizeof(mTcg2EventInfo
)/sizeof(mTcg2EventInfo
[0]));
2358 mTcgDxeData
.BsCap
.Size
= sizeof(EFI_TCG2_BOOT_SERVICE_CAPABILITY
);
2359 mTcgDxeData
.BsCap
.ProtocolVersion
.Major
= 1;
2360 mTcgDxeData
.BsCap
.ProtocolVersion
.Minor
= 1;
2361 mTcgDxeData
.BsCap
.StructureVersion
.Major
= 1;
2362 mTcgDxeData
.BsCap
.StructureVersion
.Minor
= 1;
2364 DEBUG ((EFI_D_INFO
, "Tcg2.ProtocolVersion - %02x.%02x\n", mTcgDxeData
.BsCap
.ProtocolVersion
.Major
, mTcgDxeData
.BsCap
.ProtocolVersion
.Minor
));
2365 DEBUG ((EFI_D_INFO
, "Tcg2.StructureVersion - %02x.%02x\n", mTcgDxeData
.BsCap
.StructureVersion
.Major
, mTcgDxeData
.BsCap
.StructureVersion
.Minor
));
2367 Status
= Tpm2GetCapabilityManufactureID (&mTcgDxeData
.BsCap
.ManufacturerID
);
2368 if (EFI_ERROR (Status
)) {
2369 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityManufactureID fail!\n"));
2371 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityManufactureID - %08x\n", mTcgDxeData
.BsCap
.ManufacturerID
));
2375 UINT32 FirmwareVersion1
;
2376 UINT32 FirmwareVersion2
;
2378 Status
= Tpm2GetCapabilityFirmwareVersion (&FirmwareVersion1
, &FirmwareVersion2
);
2379 if (EFI_ERROR (Status
)) {
2380 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityFirmwareVersion fail!\n"));
2382 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityFirmwareVersion - %08x %08x\n", FirmwareVersion1
, FirmwareVersion2
));
2386 Status
= Tpm2GetCapabilityMaxCommandResponseSize (&MaxCommandSize
, &MaxResponseSize
);
2387 if (EFI_ERROR (Status
)) {
2388 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityMaxCommandResponseSize fail!\n"));
2390 mTcgDxeData
.BsCap
.MaxCommandSize
= (UINT16
)MaxCommandSize
;
2391 mTcgDxeData
.BsCap
.MaxResponseSize
= (UINT16
)MaxResponseSize
;
2392 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityMaxCommandResponseSize - %08x, %08x\n", MaxCommandSize
, MaxResponseSize
));
2396 // Get supported PCR and current Active PCRs
2398 Status
= Tpm2GetCapabilityPcrs (&Pcrs
);
2399 if (EFI_ERROR (Status
)) {
2400 DEBUG ((EFI_D_ERROR
, "Tpm2GetCapabilityPcrs fail!\n"));
2401 TpmHashAlgorithmBitmap
= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2402 ActivePCRBanks
= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2404 DEBUG ((EFI_D_INFO
, "Tpm2GetCapabilityPcrs Count - %08x\n", Pcrs
.count
));
2405 TpmHashAlgorithmBitmap
= 0;
2407 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
2408 DEBUG ((EFI_D_INFO
, "hash - %x\n", Pcrs
.pcrSelections
[Index
].hash
));
2409 switch (Pcrs
.pcrSelections
[Index
].hash
) {
2411 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2412 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2413 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA1
;
2416 case TPM_ALG_SHA256
:
2417 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA256
;
2418 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2419 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA256
;
2422 case TPM_ALG_SHA384
:
2423 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA384
;
2424 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2425 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA384
;
2428 case TPM_ALG_SHA512
:
2429 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SHA512
;
2430 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2431 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SHA512
;
2434 case TPM_ALG_SM3_256
:
2435 TpmHashAlgorithmBitmap
|= EFI_TCG2_BOOT_HASH_ALG_SM3_256
;
2436 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
2437 ActivePCRBanks
|= EFI_TCG2_BOOT_HASH_ALG_SM3_256
;
2443 mTcgDxeData
.BsCap
.HashAlgorithmBitmap
= TpmHashAlgorithmBitmap
& PcdGet32 (PcdTcg2HashAlgorithmBitmap
);
2444 mTcgDxeData
.BsCap
.ActivePcrBanks
= ActivePCRBanks
& PcdGet32 (PcdTcg2HashAlgorithmBitmap
);
2447 // Need calculate NumberOfPCRBanks here, because HashAlgorithmBitmap might be removed by PCD.
2449 NumberOfPCRBanks
= 0;
2450 for (Index
= 0; Index
< 32; Index
++) {
2451 if ((mTcgDxeData
.BsCap
.HashAlgorithmBitmap
& (1u << Index
)) != 0) {
2456 if (PcdGet32 (PcdTcg2NumberOfPCRBanks
) == 0) {
2457 mTcgDxeData
.BsCap
.NumberOfPCRBanks
= NumberOfPCRBanks
;
2459 mTcgDxeData
.BsCap
.NumberOfPCRBanks
= PcdGet32 (PcdTcg2NumberOfPCRBanks
);
2460 if (PcdGet32 (PcdTcg2NumberOfPCRBanks
) > NumberOfPCRBanks
) {
2461 DEBUG ((EFI_D_ERROR
, "ERROR: PcdTcg2NumberOfPCRBanks(0x%x) > NumberOfPCRBanks(0x%x)\n", PcdGet32 (PcdTcg2NumberOfPCRBanks
), NumberOfPCRBanks
));
2462 mTcgDxeData
.BsCap
.NumberOfPCRBanks
= NumberOfPCRBanks
;
2466 mTcgDxeData
.BsCap
.SupportedEventLogs
= EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
| EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
;
2467 if ((mTcgDxeData
.BsCap
.ActivePcrBanks
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) == 0) {
2469 // No need to expose TCG1.2 event log if SHA1 bank does not exist.
2471 mTcgDxeData
.BsCap
.SupportedEventLogs
&= ~EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
;
2474 DEBUG ((EFI_D_INFO
, "Tcg2.SupportedEventLogs - 0x%08x\n", mTcgDxeData
.BsCap
.SupportedEventLogs
));
2475 DEBUG ((EFI_D_INFO
, "Tcg2.HashAlgorithmBitmap - 0x%08x\n", mTcgDxeData
.BsCap
.HashAlgorithmBitmap
));
2476 DEBUG ((EFI_D_INFO
, "Tcg2.NumberOfPCRBanks - 0x%08x\n", mTcgDxeData
.BsCap
.NumberOfPCRBanks
));
2477 DEBUG ((EFI_D_INFO
, "Tcg2.ActivePcrBanks - 0x%08x\n", mTcgDxeData
.BsCap
.ActivePcrBanks
));
2479 if (mTcgDxeData
.BsCap
.TPMPresentFlag
) {
2481 // Setup the log area and copy event log from hob list to it
2483 Status
= SetupEventLog ();
2484 ASSERT_EFI_ERROR (Status
);
2487 // Measure handoff tables, Boot#### variables etc.
2489 Status
= EfiCreateEventReadyToBootEx (
2496 Status
= gBS
->CreateEventEx (
2501 &gEfiEventExitBootServicesGuid
,
2506 // Measure Exit Boot Service failed
2508 Status
= gBS
->CreateEventEx (
2511 OnExitBootServicesFailed
,
2513 &gEventExitBootServicesFailedGuid
,
2518 // Create event callback, because we need access variable on SecureBootPolicyVariable
2519 // We should use VariableWriteArch instead of VariableArch, because Variable driver
2520 // may update SecureBoot value based on last setting.
2522 EfiCreateProtocolNotifyEvent (&gEfiVariableWriteArchProtocolGuid
, TPL_CALLBACK
, MeasureSecureBootPolicy
, NULL
, &Registration
);
2526 // Install Tcg2Protocol
2528 Status
= InstallTcg2 ();
2529 DEBUG ((EFI_D_INFO
, "InstallTcg2 - %r\n", Status
));