2 HII Config Access protocol implementation of TCG2 configuration module.
3 NOTE: This module is only for reference only, each platform should have its own setup page.
5 Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>
6 (C) Copyright 2018 Hewlett Packard Enterprise Development LP<BR>
7 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include "Tcg2ConfigImpl.h"
12 #include <Library/PcdLib.h>
13 #include <Library/Tpm2CommandLib.h>
14 #include <Library/Tpm2DeviceLib.h>
15 #include <Library/IoLib.h>
17 #include <Guid/TpmInstance.h>
19 #include <IndustryStandard/TpmPtp.h>
21 #define EFI_TCG2_EVENT_LOG_FORMAT_ALL (EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 | EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
23 TPM_INSTANCE_ID mTpmInstanceId
[TPM_DEVICE_MAX
+ 1] = TPM_INSTANCE_ID_LIST
;
25 TCG2_CONFIG_PRIVATE_DATA
*mTcg2ConfigPrivateDate
;
26 TCG2_CONFIG_PRIVATE_DATA mTcg2ConfigPrivateDateTemplate
= {
27 TCG2_CONFIG_PRIVATE_DATA_SIGNATURE
,
35 HII_VENDOR_DEVICE_PATH mTcg2HiiVendorDevicePath
= {
41 (UINT8
)(sizeof (VENDOR_DEVICE_PATH
)),
42 (UINT8
)((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
45 TCG2_CONFIG_FORM_SET_GUID
49 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
51 (UINT8
)(END_DEVICE_PATH_LENGTH
),
52 (UINT8
)((END_DEVICE_PATH_LENGTH
) >> 8)
57 UINT8 mCurrentPpRequest
;
60 Return if PTP CRB is supported.
62 @param[in] Register Pointer to PTP register.
64 @retval TRUE PTP CRB is supported.
65 @retval FALSE PTP CRB is unsupported.
72 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId
;
77 InterfaceId
.Uint32
= MmioRead32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
);
79 if (((InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB
) ||
80 (InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO
)) &&
81 (InterfaceId
.Bits
.CapCRB
!= 0))
90 Return if PTP FIFO is supported.
92 @param[in] Register Pointer to PTP register.
94 @retval TRUE PTP FIFO is supported.
95 @retval FALSE PTP FIFO is unsupported.
102 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId
;
105 // Check interface id
107 InterfaceId
.Uint32
= MmioRead32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
);
109 if (((InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB
) ||
110 (InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO
)) &&
111 (InterfaceId
.Bits
.CapFIFO
!= 0))
120 Set PTP interface type.
121 Do not update PcdActiveTpmInterfaceType here because interface change only happens on next _TPM_INIT
123 @param[in] Register Pointer to PTP register.
124 @param[in] PtpInterface PTP interface type.
126 @retval EFI_SUCCESS PTP interface type is set.
127 @retval EFI_INVALID_PARAMETER PTP interface type is invalid.
128 @retval EFI_UNSUPPORTED PTP interface type is unsupported.
129 @retval EFI_WRITE_PROTECTED PTP interface is locked.
134 IN UINT8 PtpInterface
137 TPM2_PTP_INTERFACE_TYPE PtpInterfaceCurrent
;
138 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId
;
140 PtpInterfaceCurrent
= PcdGet8 (PcdActiveTpmInterfaceType
);
141 if ((PtpInterfaceCurrent
!= Tpm2PtpInterfaceFifo
) &&
142 (PtpInterfaceCurrent
!= Tpm2PtpInterfaceCrb
))
144 return EFI_UNSUPPORTED
;
147 InterfaceId
.Uint32
= MmioRead32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
);
148 if (InterfaceId
.Bits
.IntfSelLock
!= 0) {
149 return EFI_WRITE_PROTECTED
;
152 switch (PtpInterface
) {
153 case Tpm2PtpInterfaceFifo
:
154 if (InterfaceId
.Bits
.CapFIFO
== 0) {
155 return EFI_UNSUPPORTED
;
158 InterfaceId
.Bits
.InterfaceSelector
= PTP_INTERFACE_IDENTIFIER_INTERFACE_SELECTOR_FIFO
;
159 MmioWrite32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
, InterfaceId
.Uint32
);
161 case Tpm2PtpInterfaceCrb
:
162 if (InterfaceId
.Bits
.CapCRB
== 0) {
163 return EFI_UNSUPPORTED
;
166 InterfaceId
.Bits
.InterfaceSelector
= PTP_INTERFACE_IDENTIFIER_INTERFACE_SELECTOR_CRB
;
167 MmioWrite32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
, InterfaceId
.Uint32
);
170 return EFI_INVALID_PARAMETER
;
175 This function allows a caller to extract the current configuration for one
176 or more named elements from the target driver.
178 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
179 @param[in] Request A null-terminated Unicode string in
180 <ConfigRequest> format.
181 @param[out] Progress On return, points to a character in the Request
182 string. Points to the string's null terminator if
183 request was successful. Points to the most recent
184 '&' before the first failing name/value pair (or
185 the beginning of the string if the failure is in
186 the first name/value pair) if the request was not
188 @param[out] Results A null-terminated Unicode string in
189 <ConfigAltResp> format which has all values filled
190 in for the names in the Request string. String to
191 be allocated by the called function.
193 @retval EFI_SUCCESS The Results is filled with the requested values.
194 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
195 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
196 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
203 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
204 IN CONST EFI_STRING Request
,
205 OUT EFI_STRING
*Progress
,
206 OUT EFI_STRING
*Results
209 if ((Progress
== NULL
) || (Results
== NULL
)) {
210 return EFI_INVALID_PARAMETER
;
214 return EFI_NOT_FOUND
;
218 Save TPM request to variable space.
220 @param[in] PpRequest Physical Presence request command.
222 @retval EFI_SUCCESS The operation is finished successfully.
223 @retval Others Other errors as indicated.
234 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (PpRequest
, 0);
235 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
236 mCurrentPpRequest
= PpRequest
;
237 Status
= EFI_SUCCESS
;
238 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
239 Status
= EFI_OUT_OF_RESOURCES
;
240 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
241 Status
= EFI_UNSUPPORTED
;
243 Status
= EFI_DEVICE_ERROR
;
250 Save TPM request to variable space.
252 @param[in] PpRequestParameter Physical Presence request parameter.
254 @retval EFI_SUCCESS The operation is finished successfully.
255 @retval Others Other errors as indicated.
259 SaveTcg2PpRequestParameter (
260 IN UINT32 PpRequestParameter
266 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (mCurrentPpRequest
, PpRequestParameter
);
267 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
268 Status
= EFI_SUCCESS
;
269 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
270 Status
= EFI_OUT_OF_RESOURCES
;
271 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
272 Status
= EFI_UNSUPPORTED
;
274 Status
= EFI_DEVICE_ERROR
;
281 Save Tcg2 PCR Banks request request to variable space.
283 @param[in] PCRBankIndex PCR Bank Index.
284 @param[in] Enable Enable or disable this PCR Bank.
286 @retval EFI_SUCCESS The operation is finished successfully.
287 @retval Others Other errors as indicated.
291 SaveTcg2PCRBanksRequest (
292 IN UINTN PCRBankIndex
,
300 mTcg2ConfigPrivateDate
->PCRBanksDesired
|= (0x1 << PCRBankIndex
);
302 mTcg2ConfigPrivateDate
->PCRBanksDesired
&= ~(0x1 << PCRBankIndex
);
305 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS
, mTcg2ConfigPrivateDate
->PCRBanksDesired
);
306 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
307 Status
= EFI_SUCCESS
;
308 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
309 Status
= EFI_OUT_OF_RESOURCES
;
310 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
311 Status
= EFI_UNSUPPORTED
;
313 Status
= EFI_DEVICE_ERROR
;
320 This function processes the results of changes in configuration.
322 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
323 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
325 @param[out] Progress A pointer to a string filled in with the offset of
326 the most recent '&' before the first failing
327 name/value pair (or the beginning of the string if
328 the failure is in the first name/value pair) or
329 the terminating NULL if all was successful.
331 @retval EFI_SUCCESS The Results is processed successfully.
332 @retval EFI_INVALID_PARAMETER Configuration is NULL.
333 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
340 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
341 IN CONST EFI_STRING Configuration
,
342 OUT EFI_STRING
*Progress
345 if ((Configuration
== NULL
) || (Progress
== NULL
)) {
346 return EFI_INVALID_PARAMETER
;
349 *Progress
= Configuration
;
351 return EFI_NOT_FOUND
;
355 Get HID string of TPM2 ACPI device object
357 @param[in] Hid Points to HID String Buffer.
358 @param[in] Size HID String size in bytes. Must >= TPM_HID_ACPI_SIZE
360 @return HID String get status.
370 UINT32 ManufacturerID
;
371 UINT32 FirmwareVersion1
;
372 UINT32 FirmwareVersion2
;
380 // Get Manufacturer ID
382 Status
= Tpm2GetCapabilityManufactureID (&ManufacturerID
);
383 if (!EFI_ERROR (Status
)) {
384 DEBUG ((DEBUG_INFO
, "TPM_PT_MANUFACTURER 0x%08x\n", ManufacturerID
));
386 // ManufacturerID defined in TCG Vendor ID Registry
387 // may tailed with 0x00 or 0x20
389 if (((ManufacturerID
>> 24) == 0x00) || ((ManufacturerID
>> 24) == 0x20)) {
391 // HID containing PNP ID "NNN####"
392 // NNN is uppercase letter for Vendor ID specified by manufacturer
394 CopyMem (Hid
, &ManufacturerID
, 3);
397 // HID containing ACP ID "NNNN####"
398 // NNNN is uppercase letter for Vendor ID specified by manufacturer
400 CopyMem (Hid
, &ManufacturerID
, 4);
404 DEBUG ((DEBUG_ERROR
, "Get TPM_PT_MANUFACTURER failed %x!\n", Status
));
409 Status
= Tpm2GetCapabilityFirmwareVersion (&FirmwareVersion1
, &FirmwareVersion2
);
410 if (!EFI_ERROR (Status
)) {
411 DEBUG ((DEBUG_INFO
, "TPM_PT_FIRMWARE_VERSION_1 0x%x\n", FirmwareVersion1
));
412 DEBUG ((DEBUG_INFO
, "TPM_PT_FIRMWARE_VERSION_2 0x%x\n", FirmwareVersion2
));
414 // #### is Firmware Version 1
417 AsciiSPrint (Hid
+ 3, TPM_HID_PNP_SIZE
- 3, "%02d%02d", ((FirmwareVersion1
& 0xFFFF0000) >> 16), (FirmwareVersion1
& 0x0000FFFF));
419 AsciiSPrint (Hid
+ 4, TPM_HID_ACPI_SIZE
- 4, "%02d%02d", ((FirmwareVersion1
& 0xFFFF0000) >> 16), (FirmwareVersion1
& 0x0000FFFF));
422 DEBUG ((DEBUG_ERROR
, "Get TPM_PT_FIRMWARE_VERSION_X failed %x!\n", Status
));
431 This function processes the results of changes in configuration
432 for TCG2 version information.
434 @param[in] Action Specifies the type of action taken by the browser.
435 ASSERT if the Action is not EFI_BROWSER_ACTION_SUBMITTED.
436 @param[in] QuestionId A unique value which is sent to the original
437 exporting driver so that it can identify the type
439 @param[in] Type The type of value for the question.
440 @param[in] Value A pointer to the data being sent to the original
443 @retval EFI_SUCCESS The callback successfully handled the action.
447 Tcg2VersionInfoCallback (
448 IN EFI_BROWSER_ACTION Action
,
449 IN EFI_QUESTION_ID QuestionId
,
451 IN EFI_IFR_TYPE_VALUE
*Value
455 UINT64 PcdTcg2PpiVersion
;
456 UINT8 PcdTpm2AcpiTableRev
;
458 ASSERT (Action
== EFI_BROWSER_ACTION_SUBMITTED
);
460 if (QuestionId
== KEY_TCG2_PPI_VERSION
) {
462 // Get the PCD value after EFI_BROWSER_ACTION_SUBMITTED,
463 // the SetVariable to TCG2_VERSION_NAME should have been done.
464 // If the PCD value is not equal to the value set to variable,
465 // the PCD is not DynamicHii type and does not map to the setup option.
467 PcdTcg2PpiVersion
= 0;
470 PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer
),
471 AsciiStrSize ((CHAR8
*)PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer
))
473 if (PcdTcg2PpiVersion
!= Value
->u64
) {
475 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
477 L
"WARNING: PcdTcgPhysicalPresenceInterfaceVer is not DynamicHii type and does not map to this option!",
478 L
"The version configuring by this setup option will not work!",
482 } else if (QuestionId
== KEY_TPM2_ACPI_REVISION
) {
484 // Get the PCD value after EFI_BROWSER_ACTION_SUBMITTED,
485 // the SetVariable to TCG2_VERSION_NAME should have been done.
486 // If the PCD value is not equal to the value set to variable,
487 // the PCD is not DynamicHii type and does not map to the setup option.
489 PcdTpm2AcpiTableRev
= PcdGet8 (PcdTpm2AcpiTableRev
);
491 if (PcdTpm2AcpiTableRev
!= Value
->u8
) {
493 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
495 L
"WARNING: PcdTpm2AcpiTableRev is not DynamicHii type and does not map to this option!",
496 L
"The Revision configuring by this setup option will not work!",
506 This function processes the results of changes in configuration.
508 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
509 @param[in] Action Specifies the type of action taken by the browser.
510 @param[in] QuestionId A unique value which is sent to the original
511 exporting driver so that it can identify the type
513 @param[in] Type The type of value for the question.
514 @param[in] Value A pointer to the data being sent to the original
516 @param[out] ActionRequest On return, points to the action requested by the
519 @retval EFI_SUCCESS The callback successfully handled the action.
520 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
521 variable and its data.
522 @retval EFI_DEVICE_ERROR The variable could not be saved.
523 @retval EFI_UNSUPPORTED The specified Action is not supported by the
530 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
531 IN EFI_BROWSER_ACTION Action
,
532 IN EFI_QUESTION_ID QuestionId
,
534 IN EFI_IFR_TYPE_VALUE
*Value
,
535 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
542 TCG2_CONFIG_PRIVATE_DATA
*Private
;
544 if ((This
== NULL
) || (Value
== NULL
) || (ActionRequest
== NULL
)) {
545 return EFI_INVALID_PARAMETER
;
548 Private
= TCG2_CONFIG_PRIVATE_DATA_FROM_THIS (This
);
550 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
552 // Update TPM2 HID info
554 if (QuestionId
== KEY_TPM_DEVICE
) {
555 Status
= GetTpm2HID (HidStr
, 16);
557 if (EFI_ERROR (Status
)) {
559 // Fail to get TPM2 HID
561 HiiSetString (Private
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACPI_HID_CONTENT
), L
"Unknown", NULL
);
563 AsciiStrToUnicodeStrS (HidStr
, UnHidStr
, 16);
564 HiiSetString (Private
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACPI_HID_CONTENT
), UnHidStr
, NULL
);
571 if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
572 if (QuestionId
== KEY_TPM_DEVICE_INTERFACE
) {
573 Status
= SetPtpInterface ((VOID
*)(UINTN
)PcdGet64 (PcdTpmBaseAddress
), Value
->u8
);
574 if (EFI_ERROR (Status
)) {
576 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
578 L
"Error: Fail to set PTP interface!",
581 return EFI_DEVICE_ERROR
;
586 if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
587 if (QuestionId
== KEY_TPM_DEVICE
) {
591 if (QuestionId
== KEY_TPM2_OPERATION
) {
592 return SaveTcg2PpRequest (Value
->u8
);
595 if (QuestionId
== KEY_TPM2_OPERATION_PARAMETER
) {
596 return SaveTcg2PpRequestParameter (Value
->u32
);
599 if ((QuestionId
>= KEY_TPM2_PCR_BANKS_REQUEST_0
) && (QuestionId
<= KEY_TPM2_PCR_BANKS_REQUEST_4
)) {
600 return SaveTcg2PCRBanksRequest (QuestionId
- KEY_TPM2_PCR_BANKS_REQUEST_0
, Value
->b
);
604 if (Action
== EFI_BROWSER_ACTION_SUBMITTED
) {
605 if ((QuestionId
== KEY_TCG2_PPI_VERSION
) || (QuestionId
== KEY_TPM2_ACPI_REVISION
)) {
606 return Tcg2VersionInfoCallback (Action
, QuestionId
, Type
, Value
);
610 return EFI_UNSUPPORTED
;
614 Append Buffer With TpmAlgHash.
616 @param[in] Buffer Buffer to be appended.
617 @param[in] BufferSize Size of buffer.
618 @param[in] TpmAlgHash TpmAlgHash.
622 AppendBufferWithTpmAlgHash (
628 switch (TpmAlgHash
) {
630 if (Buffer
[0] != 0) {
631 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
634 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA1");
637 if (Buffer
[0] != 0) {
638 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
641 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA256");
644 if (Buffer
[0] != 0) {
645 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
648 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA384");
651 if (Buffer
[0] != 0) {
652 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
655 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA512");
657 case TPM_ALG_SM3_256
:
658 if (Buffer
[0] != 0) {
659 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
662 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SM3_256");
668 Fill Buffer With BootHashAlg.
670 @param[in] Buffer Buffer to be filled.
671 @param[in] BufferSize Size of buffer.
672 @param[in] BootHashAlg BootHashAlg.
676 FillBufferWithBootHashAlg (
679 IN UINT32 BootHashAlg
683 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) != 0) {
684 if (Buffer
[0] != 0) {
685 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
688 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA1");
691 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA256
) != 0) {
692 if (Buffer
[0] != 0) {
693 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
696 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA256");
699 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA384
) != 0) {
700 if (Buffer
[0] != 0) {
701 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
704 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA384");
707 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA512
) != 0) {
708 if (Buffer
[0] != 0) {
709 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
712 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA512");
715 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SM3_256
) != 0) {
716 if (Buffer
[0] != 0) {
717 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
720 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SM3_256");
725 Set ConfigInfo according to TpmAlgHash.
727 @param[in,out] Tcg2ConfigInfo TCG2 config info.
728 @param[in] TpmAlgHash TpmAlgHash.
733 IN OUT TCG2_CONFIGURATION_INFO
*Tcg2ConfigInfo
,
737 switch (TpmAlgHash
) {
739 Tcg2ConfigInfo
->Sha1Supported
= TRUE
;
742 Tcg2ConfigInfo
->Sha256Supported
= TRUE
;
745 Tcg2ConfigInfo
->Sha384Supported
= TRUE
;
748 Tcg2ConfigInfo
->Sha512Supported
= TRUE
;
750 case TPM_ALG_SM3_256
:
751 Tcg2ConfigInfo
->Sm3Supported
= TRUE
;
757 Fill Buffer With TCG2EventLogFormat.
759 @param[in] Buffer Buffer to be filled.
760 @param[in] BufferSize Size of buffer.
761 @param[in] TCG2EventLogFormat TCG2EventLogFormat.
765 FillBufferWithTCG2EventLogFormat (
768 IN UINT32 TCG2EventLogFormat
772 if ((TCG2EventLogFormat
& EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
) != 0) {
773 if (Buffer
[0] != 0) {
774 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
777 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"TCG_1_2");
780 if ((TCG2EventLogFormat
& EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
) != 0) {
781 if (Buffer
[0] != 0) {
782 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
785 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"TCG_2");
788 if ((TCG2EventLogFormat
& (~EFI_TCG2_EVENT_LOG_FORMAT_ALL
)) != 0) {
789 if (Buffer
[0] != 0) {
790 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
793 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"UNKNOWN");
798 This function publish the TCG2 configuration Form for TPM device.
800 @param[in, out] PrivateData Points to TCG2 configuration private data.
802 @retval EFI_SUCCESS HII Form is installed for this network device.
803 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
804 @retval Others Other errors as indicated.
808 InstallTcg2ConfigForm (
809 IN OUT TCG2_CONFIG_PRIVATE_DATA
*PrivateData
813 EFI_HII_HANDLE HiiHandle
;
814 EFI_HANDLE DriverHandle
;
815 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
817 TPML_PCR_SELECTION Pcrs
;
818 CHAR16 TempBuffer
[1024];
819 TCG2_CONFIGURATION_INFO Tcg2ConfigInfo
;
820 TPM2_PTP_INTERFACE_TYPE TpmDeviceInterfaceDetected
;
821 BOOLEAN IsCmdImp
= FALSE
;
824 ConfigAccess
= &PrivateData
->ConfigAccess
;
825 Status
= gBS
->InstallMultipleProtocolInterfaces (
827 &gEfiDevicePathProtocolGuid
,
828 &mTcg2HiiVendorDevicePath
,
829 &gEfiHiiConfigAccessProtocolGuid
,
833 if (EFI_ERROR (Status
)) {
837 PrivateData
->DriverHandle
= DriverHandle
;
840 // Publish the HII package list
842 HiiHandle
= HiiAddPackages (
843 &gTcg2ConfigFormSetGuid
,
845 Tcg2ConfigDxeStrings
,
849 if (HiiHandle
== NULL
) {
850 gBS
->UninstallMultipleProtocolInterfaces (
852 &gEfiDevicePathProtocolGuid
,
853 &mTcg2HiiVendorDevicePath
,
854 &gEfiHiiConfigAccessProtocolGuid
,
859 return EFI_OUT_OF_RESOURCES
;
862 PrivateData
->HiiHandle
= HiiHandle
;
865 // Update static data
867 switch (PrivateData
->TpmDeviceDetected
) {
868 case TPM_DEVICE_NULL
:
869 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"Not Found", NULL
);
872 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"TPM 1.2", NULL
);
874 case TPM_DEVICE_2_0_DTPM
:
875 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"TPM 2.0", NULL
);
878 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"Unknown", NULL
);
882 ZeroMem (&Tcg2ConfigInfo
, sizeof (Tcg2ConfigInfo
));
883 Status
= Tpm2GetCapabilityPcrs (&Pcrs
);
884 if (EFI_ERROR (Status
)) {
885 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT
), L
"[Unknown]", NULL
);
886 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT
), L
"[Unknown]", NULL
);
889 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
890 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
891 AppendBufferWithTpmAlgHash (TempBuffer
, sizeof (TempBuffer
), Pcrs
.pcrSelections
[Index
].hash
);
895 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
898 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
899 AppendBufferWithTpmAlgHash (TempBuffer
, sizeof (TempBuffer
), Pcrs
.pcrSelections
[Index
].hash
);
900 SetConfigInfo (&Tcg2ConfigInfo
, Pcrs
.pcrSelections
[Index
].hash
);
903 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
906 Status
= Tpm2GetCapabilityIsCommandImplemented (TPM_CC_ChangeEPS
, &IsCmdImp
);
907 if (EFI_ERROR (Status
)) {
908 DEBUG ((DEBUG_ERROR
, "Tpm2GetCapabilityIsCmdImpl fails %r\n", Status
));
911 Tcg2ConfigInfo
.ChangeEPSSupported
= IsCmdImp
;
913 FillBufferWithBootHashAlg (TempBuffer
, sizeof (TempBuffer
), PcdGet32 (PcdTcg2HashAlgorithmBitmap
));
914 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_BIOS_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
919 FillBufferWithTCG2EventLogFormat (TempBuffer
, sizeof (TempBuffer
), PrivateData
->ProtocolCapability
.SupportedEventLogs
);
920 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_SUPPORTED_EVENT_LOG_FORMAT_CONTENT
), TempBuffer
, NULL
);
922 FillBufferWithBootHashAlg (TempBuffer
, sizeof (TempBuffer
), PrivateData
->ProtocolCapability
.HashAlgorithmBitmap
);
923 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_HASH_ALGO_BITMAP_CONTENT
), TempBuffer
, NULL
);
925 UnicodeSPrint (TempBuffer
, sizeof (TempBuffer
), L
"%d", PrivateData
->ProtocolCapability
.NumberOfPCRBanks
);
926 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_NUMBER_OF_PCR_BANKS_CONTENT
), TempBuffer
, NULL
);
928 FillBufferWithBootHashAlg (TempBuffer
, sizeof (TempBuffer
), PrivateData
->ProtocolCapability
.ActivePcrBanks
);
929 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_ACTIVE_PCR_BANKS_CONTENT
), TempBuffer
, NULL
);
932 // Update TPM device interface type
934 if (PrivateData
->TpmDeviceDetected
== TPM_DEVICE_2_0_DTPM
) {
935 TpmDeviceInterfaceDetected
= PcdGet8 (PcdActiveTpmInterfaceType
);
936 switch (TpmDeviceInterfaceDetected
) {
937 case Tpm2PtpInterfaceTis
:
938 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"TIS", NULL
);
940 case Tpm2PtpInterfaceFifo
:
941 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"PTP FIFO", NULL
);
943 case Tpm2PtpInterfaceCrb
:
944 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"PTP CRB", NULL
);
947 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"Unknown", NULL
);
951 Tcg2ConfigInfo
.TpmDeviceInterfaceAttempt
= TpmDeviceInterfaceDetected
;
952 switch (TpmDeviceInterfaceDetected
) {
953 case Tpm2PtpInterfaceTis
:
954 Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
= FALSE
;
955 Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
= FALSE
;
956 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT
), L
"TIS", NULL
);
958 case Tpm2PtpInterfaceFifo
:
959 case Tpm2PtpInterfaceCrb
:
960 Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
= IsPtpFifoSupported ((VOID
*)(UINTN
)PcdGet64 (PcdTpmBaseAddress
));
961 Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
= IsPtpCrbSupported ((VOID
*)(UINTN
)PcdGet64 (PcdTpmBaseAddress
));
963 if (Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
) {
964 if (TempBuffer
[0] != 0) {
965 StrCatS (TempBuffer
, sizeof (TempBuffer
) / sizeof (CHAR16
), L
", ");
968 StrCatS (TempBuffer
, sizeof (TempBuffer
) / sizeof (CHAR16
), L
"PTP FIFO");
971 if (Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
) {
972 if (TempBuffer
[0] != 0) {
973 StrCatS (TempBuffer
, sizeof (TempBuffer
) / sizeof (CHAR16
), L
", ");
976 StrCatS (TempBuffer
, sizeof (TempBuffer
) / sizeof (CHAR16
), L
"PTP CRB");
979 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT
), TempBuffer
, NULL
);
982 Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
= FALSE
;
983 Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
= FALSE
;
984 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT
), L
"Unknown", NULL
);
990 // Set ConfigInfo, to control the check box.
992 Status
= gRT
->SetVariable (
993 TCG2_STORAGE_INFO_NAME
,
994 &gTcg2ConfigFormSetGuid
,
995 EFI_VARIABLE_BOOTSERVICE_ACCESS
,
996 sizeof (Tcg2ConfigInfo
),
999 if (EFI_ERROR (Status
)) {
1000 DEBUG ((DEBUG_ERROR
, "Tcg2ConfigDriver: Fail to set TCG2_STORAGE_INFO_NAME\n"));
1007 This function removes TCG2 configuration Form.
1009 @param[in, out] PrivateData Points to TCG2 configuration private data.
1013 UninstallTcg2ConfigForm (
1014 IN OUT TCG2_CONFIG_PRIVATE_DATA
*PrivateData
1018 // Uninstall HII package list
1020 if (PrivateData
->HiiHandle
!= NULL
) {
1021 HiiRemovePackages (PrivateData
->HiiHandle
);
1022 PrivateData
->HiiHandle
= NULL
;
1026 // Uninstall HII Config Access Protocol
1028 if (PrivateData
->DriverHandle
!= NULL
) {
1029 gBS
->UninstallMultipleProtocolInterfaces (
1030 PrivateData
->DriverHandle
,
1031 &gEfiDevicePathProtocolGuid
,
1032 &mTcg2HiiVendorDevicePath
,
1033 &gEfiHiiConfigAccessProtocolGuid
,
1034 &PrivateData
->ConfigAccess
,
1037 PrivateData
->DriverHandle
= NULL
;
1040 FreePool (PrivateData
);