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)) {
88 Return if PTP FIFO is supported.
90 @param[in] Register Pointer to PTP register.
92 @retval TRUE PTP FIFO is supported.
93 @retval FALSE PTP FIFO is unsupported.
100 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId
;
103 // Check interface id
105 InterfaceId
.Uint32
= MmioRead32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
);
107 if (((InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB
) ||
108 (InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO
)) &&
109 (InterfaceId
.Bits
.CapFIFO
!= 0)) {
116 Set PTP interface type.
117 Do not update PcdActiveTpmInterfaceType here because interface change only happens on next _TPM_INIT
119 @param[in] Register Pointer to PTP register.
120 @param[in] PtpInterface PTP interface type.
122 @retval EFI_SUCCESS PTP interface type is set.
123 @retval EFI_INVALID_PARAMETER PTP interface type is invalid.
124 @retval EFI_UNSUPPORTED PTP interface type is unsupported.
125 @retval EFI_WRITE_PROTECTED PTP interface is locked.
130 IN UINT8 PtpInterface
133 TPM2_PTP_INTERFACE_TYPE PtpInterfaceCurrent
;
134 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId
;
136 PtpInterfaceCurrent
= PcdGet8(PcdActiveTpmInterfaceType
);
137 if ((PtpInterfaceCurrent
!= Tpm2PtpInterfaceFifo
) &&
138 (PtpInterfaceCurrent
!= Tpm2PtpInterfaceCrb
)) {
139 return EFI_UNSUPPORTED
;
141 InterfaceId
.Uint32
= MmioRead32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
);
142 if (InterfaceId
.Bits
.IntfSelLock
!= 0) {
143 return EFI_WRITE_PROTECTED
;
146 switch (PtpInterface
) {
147 case Tpm2PtpInterfaceFifo
:
148 if (InterfaceId
.Bits
.CapFIFO
== 0) {
149 return EFI_UNSUPPORTED
;
151 InterfaceId
.Bits
.InterfaceSelector
= PTP_INTERFACE_IDENTIFIER_INTERFACE_SELECTOR_FIFO
;
152 MmioWrite32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
, InterfaceId
.Uint32
);
154 case Tpm2PtpInterfaceCrb
:
155 if (InterfaceId
.Bits
.CapCRB
== 0) {
156 return EFI_UNSUPPORTED
;
158 InterfaceId
.Bits
.InterfaceSelector
= PTP_INTERFACE_IDENTIFIER_INTERFACE_SELECTOR_CRB
;
159 MmioWrite32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
, InterfaceId
.Uint32
);
162 return EFI_INVALID_PARAMETER
;
167 This function allows a caller to extract the current configuration for one
168 or more named elements from the target driver.
170 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
171 @param[in] Request A null-terminated Unicode string in
172 <ConfigRequest> format.
173 @param[out] Progress On return, points to a character in the Request
174 string. Points to the string's null terminator if
175 request was successful. Points to the most recent
176 '&' before the first failing name/value pair (or
177 the beginning of the string if the failure is in
178 the first name/value pair) if the request was not
180 @param[out] Results A null-terminated Unicode string in
181 <ConfigAltResp> format which has all values filled
182 in for the names in the Request string. String to
183 be allocated by the called function.
185 @retval EFI_SUCCESS The Results is filled with the requested values.
186 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
187 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
188 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
195 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
196 IN CONST EFI_STRING Request
,
197 OUT EFI_STRING
*Progress
,
198 OUT EFI_STRING
*Results
201 if (Progress
== NULL
|| Results
== NULL
) {
202 return EFI_INVALID_PARAMETER
;
206 return EFI_NOT_FOUND
;
210 Save TPM request to variable space.
212 @param[in] PpRequest Physical Presence request command.
214 @retval EFI_SUCCESS The operation is finished successfully.
215 @retval Others Other errors as indicated.
226 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (PpRequest
, 0);
227 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
228 mCurrentPpRequest
= PpRequest
;
229 Status
= EFI_SUCCESS
;
230 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
231 Status
= EFI_OUT_OF_RESOURCES
;
232 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
233 Status
= EFI_UNSUPPORTED
;
235 Status
= EFI_DEVICE_ERROR
;
242 Save TPM request to variable space.
244 @param[in] PpRequestParameter Physical Presence request parameter.
246 @retval EFI_SUCCESS The operation is finished successfully.
247 @retval Others Other errors as indicated.
251 SaveTcg2PpRequestParameter (
252 IN UINT32 PpRequestParameter
258 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (mCurrentPpRequest
, PpRequestParameter
);
259 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
260 Status
= EFI_SUCCESS
;
261 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
262 Status
= EFI_OUT_OF_RESOURCES
;
263 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
264 Status
= EFI_UNSUPPORTED
;
266 Status
= EFI_DEVICE_ERROR
;
273 Save Tcg2 PCR Banks request request to variable space.
275 @param[in] PCRBankIndex PCR Bank Index.
276 @param[in] Enable Enable or disable this PCR Bank.
278 @retval EFI_SUCCESS The operation is finished successfully.
279 @retval Others Other errors as indicated.
283 SaveTcg2PCRBanksRequest (
284 IN UINTN PCRBankIndex
,
292 mTcg2ConfigPrivateDate
->PCRBanksDesired
|= (0x1 << PCRBankIndex
);
294 mTcg2ConfigPrivateDate
->PCRBanksDesired
&= ~(0x1 << PCRBankIndex
);
297 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS
, mTcg2ConfigPrivateDate
->PCRBanksDesired
);
298 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
299 Status
= EFI_SUCCESS
;
300 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
301 Status
= EFI_OUT_OF_RESOURCES
;
302 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
303 Status
= EFI_UNSUPPORTED
;
305 Status
= EFI_DEVICE_ERROR
;
312 This function processes the results of changes in configuration.
314 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
315 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
317 @param[out] Progress A pointer to a string filled in with the offset of
318 the most recent '&' before the first failing
319 name/value pair (or the beginning of the string if
320 the failure is in the first name/value pair) or
321 the terminating NULL if all was successful.
323 @retval EFI_SUCCESS The Results is processed successfully.
324 @retval EFI_INVALID_PARAMETER Configuration is NULL.
325 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
332 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
333 IN CONST EFI_STRING Configuration
,
334 OUT EFI_STRING
*Progress
337 if (Configuration
== NULL
|| Progress
== NULL
) {
338 return EFI_INVALID_PARAMETER
;
341 *Progress
= Configuration
;
343 return EFI_NOT_FOUND
;
347 Get HID string of TPM2 ACPI device object
349 @param[in] Hid Points to HID String Buffer.
350 @param[in] Size HID String size in bytes. Must >= TPM_HID_ACPI_SIZE
352 @return HID String get status.
362 UINT32 ManufacturerID
;
363 UINT32 FirmwareVersion1
;
364 UINT32 FirmwareVersion2
;
372 // Get Manufacturer ID
374 Status
= Tpm2GetCapabilityManufactureID(&ManufacturerID
);
375 if (!EFI_ERROR(Status
)) {
376 DEBUG((DEBUG_INFO
, "TPM_PT_MANUFACTURER 0x%08x\n", ManufacturerID
));
378 // ManufacturerID defined in TCG Vendor ID Registry
379 // may tailed with 0x00 or 0x20
381 if ((ManufacturerID
>> 24) == 0x00 || ((ManufacturerID
>> 24) == 0x20)) {
383 // HID containing PNP ID "NNN####"
384 // NNN is uppercase letter for Vendor ID specified by manufacturer
386 CopyMem(Hid
, &ManufacturerID
, 3);
389 // HID containing ACP ID "NNNN####"
390 // NNNN is uppercase letter for Vendor ID specified by manufacturer
392 CopyMem(Hid
, &ManufacturerID
, 4);
396 DEBUG ((DEBUG_ERROR
, "Get TPM_PT_MANUFACTURER failed %x!\n", Status
));
401 Status
= Tpm2GetCapabilityFirmwareVersion(&FirmwareVersion1
, &FirmwareVersion2
);
402 if (!EFI_ERROR(Status
)) {
403 DEBUG((DEBUG_INFO
, "TPM_PT_FIRMWARE_VERSION_1 0x%x\n", FirmwareVersion1
));
404 DEBUG((DEBUG_INFO
, "TPM_PT_FIRMWARE_VERSION_2 0x%x\n", FirmwareVersion2
));
406 // #### is Firmware Version 1
409 AsciiSPrint(Hid
+ 3, TPM_HID_PNP_SIZE
- 3, "%02d%02d", ((FirmwareVersion1
& 0xFFFF0000) >> 16), (FirmwareVersion1
& 0x0000FFFF));
411 AsciiSPrint(Hid
+ 4, TPM_HID_ACPI_SIZE
- 4, "%02d%02d", ((FirmwareVersion1
& 0xFFFF0000) >> 16), (FirmwareVersion1
& 0x0000FFFF));
415 DEBUG ((DEBUG_ERROR
, "Get TPM_PT_FIRMWARE_VERSION_X failed %x!\n", Status
));
424 This function processes the results of changes in configuration
425 for TCG2 version information.
427 @param[in] Action Specifies the type of action taken by the browser.
428 ASSERT if the Action is not EFI_BROWSER_ACTION_SUBMITTED.
429 @param[in] QuestionId A unique value which is sent to the original
430 exporting driver so that it can identify the type
432 @param[in] Type The type of value for the question.
433 @param[in] Value A pointer to the data being sent to the original
436 @retval EFI_SUCCESS The callback successfully handled the action.
440 Tcg2VersionInfoCallback (
441 IN EFI_BROWSER_ACTION Action
,
442 IN EFI_QUESTION_ID QuestionId
,
444 IN EFI_IFR_TYPE_VALUE
*Value
448 UINT64 PcdTcg2PpiVersion
;
449 UINT8 PcdTpm2AcpiTableRev
;
451 ASSERT (Action
== EFI_BROWSER_ACTION_SUBMITTED
);
453 if (QuestionId
== KEY_TCG2_PPI_VERSION
) {
455 // Get the PCD value after EFI_BROWSER_ACTION_SUBMITTED,
456 // the SetVariable to TCG2_VERSION_NAME should have been done.
457 // If the PCD value is not equal to the value set to variable,
458 // the PCD is not DynamicHii type and does not map to the setup option.
460 PcdTcg2PpiVersion
= 0;
463 PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer
),
464 AsciiStrSize ((CHAR8
*) PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer
))
466 if (PcdTcg2PpiVersion
!= Value
->u64
) {
468 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
470 L
"WARNING: PcdTcgPhysicalPresenceInterfaceVer is not DynamicHii type and does not map to this option!",
471 L
"The version configuring by this setup option will not work!",
475 } else if (QuestionId
== KEY_TPM2_ACPI_REVISION
){
477 // Get the PCD value after EFI_BROWSER_ACTION_SUBMITTED,
478 // the SetVariable to TCG2_VERSION_NAME should have been done.
479 // If the PCD value is not equal to the value set to variable,
480 // the PCD is not DynamicHii type and does not map to the setup option.
482 PcdTpm2AcpiTableRev
= PcdGet8 (PcdTpm2AcpiTableRev
);
484 if (PcdTpm2AcpiTableRev
!= Value
->u8
) {
486 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
488 L
"WARNING: PcdTpm2AcpiTableRev is not DynamicHii type and does not map to this option!",
489 L
"The Revision configuring by this setup option will not work!",
499 This function processes the results of changes in configuration.
501 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
502 @param[in] Action Specifies the type of action taken by the browser.
503 @param[in] QuestionId A unique value which is sent to the original
504 exporting driver so that it can identify the type
506 @param[in] Type The type of value for the question.
507 @param[in] Value A pointer to the data being sent to the original
509 @param[out] ActionRequest On return, points to the action requested by the
512 @retval EFI_SUCCESS The callback successfully handled the action.
513 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
514 variable and its data.
515 @retval EFI_DEVICE_ERROR The variable could not be saved.
516 @retval EFI_UNSUPPORTED The specified Action is not supported by the
523 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
524 IN EFI_BROWSER_ACTION Action
,
525 IN EFI_QUESTION_ID QuestionId
,
527 IN EFI_IFR_TYPE_VALUE
*Value
,
528 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
535 TCG2_CONFIG_PRIVATE_DATA
*Private
;
537 if ((This
== NULL
) || (Value
== NULL
) || (ActionRequest
== NULL
)) {
538 return EFI_INVALID_PARAMETER
;
541 Private
= TCG2_CONFIG_PRIVATE_DATA_FROM_THIS (This
);
543 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
545 // Update TPM2 HID info
547 if (QuestionId
== KEY_TPM_DEVICE
) {
548 Status
= GetTpm2HID(HidStr
, 16);
550 if (EFI_ERROR(Status
)) {
552 // Fail to get TPM2 HID
554 HiiSetString (Private
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACPI_HID_CONTENT
), L
"Unknown", NULL
);
556 AsciiStrToUnicodeStrS(HidStr
, UnHidStr
, 16);
557 HiiSetString (Private
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACPI_HID_CONTENT
), UnHidStr
, NULL
);
563 if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
564 if (QuestionId
== KEY_TPM_DEVICE_INTERFACE
) {
565 Status
= SetPtpInterface ((VOID
*) (UINTN
) PcdGet64 (PcdTpmBaseAddress
), Value
->u8
);
566 if (EFI_ERROR (Status
)) {
568 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
570 L
"Error: Fail to set PTP interface!",
573 return EFI_DEVICE_ERROR
;
578 if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
579 if (QuestionId
== KEY_TPM_DEVICE
) {
582 if (QuestionId
== KEY_TPM2_OPERATION
) {
583 return SaveTcg2PpRequest (Value
->u8
);
585 if (QuestionId
== KEY_TPM2_OPERATION_PARAMETER
) {
586 return SaveTcg2PpRequestParameter (Value
->u32
);
588 if ((QuestionId
>= KEY_TPM2_PCR_BANKS_REQUEST_0
) && (QuestionId
<= KEY_TPM2_PCR_BANKS_REQUEST_4
)) {
589 return SaveTcg2PCRBanksRequest (QuestionId
- KEY_TPM2_PCR_BANKS_REQUEST_0
, Value
->b
);
593 if (Action
== EFI_BROWSER_ACTION_SUBMITTED
) {
594 if (QuestionId
== KEY_TCG2_PPI_VERSION
|| QuestionId
== KEY_TPM2_ACPI_REVISION
) {
595 return Tcg2VersionInfoCallback (Action
, QuestionId
, Type
, Value
);
599 return EFI_UNSUPPORTED
;
603 Append Buffer With TpmAlgHash.
605 @param[in] Buffer Buffer to be appended.
606 @param[in] BufferSize Size of buffer.
607 @param[in] TpmAlgHash TpmAlgHash.
611 AppendBufferWithTpmAlgHash (
617 switch (TpmAlgHash
) {
619 if (Buffer
[0] != 0) {
620 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
622 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA1");
625 if (Buffer
[0] != 0) {
626 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
628 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA256");
631 if (Buffer
[0] != 0) {
632 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
634 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA384");
637 if (Buffer
[0] != 0) {
638 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
640 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA512");
642 case TPM_ALG_SM3_256
:
643 if (Buffer
[0] != 0) {
644 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
646 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SM3_256");
652 Fill Buffer With BootHashAlg.
654 @param[in] Buffer Buffer to be filled.
655 @param[in] BufferSize Size of buffer.
656 @param[in] BootHashAlg BootHashAlg.
660 FillBufferWithBootHashAlg (
663 IN UINT32 BootHashAlg
667 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) != 0) {
668 if (Buffer
[0] != 0) {
669 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
671 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA1");
673 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA256
) != 0) {
674 if (Buffer
[0] != 0) {
675 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
677 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA256");
679 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA384
) != 0) {
680 if (Buffer
[0] != 0) {
681 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
683 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA384");
685 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA512
) != 0) {
686 if (Buffer
[0] != 0) {
687 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
689 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA512");
691 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SM3_256
) != 0) {
692 if (Buffer
[0] != 0) {
693 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
695 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SM3_256");
700 Set ConfigInfo according to TpmAlgHash.
702 @param[in,out] Tcg2ConfigInfo TCG2 config info.
703 @param[in] TpmAlgHash TpmAlgHash.
708 IN OUT TCG2_CONFIGURATION_INFO
*Tcg2ConfigInfo
,
712 switch (TpmAlgHash
) {
714 Tcg2ConfigInfo
->Sha1Supported
= TRUE
;
717 Tcg2ConfigInfo
->Sha256Supported
= TRUE
;
720 Tcg2ConfigInfo
->Sha384Supported
= TRUE
;
723 Tcg2ConfigInfo
->Sha512Supported
= TRUE
;
725 case TPM_ALG_SM3_256
:
726 Tcg2ConfigInfo
->Sm3Supported
= TRUE
;
732 Fill Buffer With TCG2EventLogFormat.
734 @param[in] Buffer Buffer to be filled.
735 @param[in] BufferSize Size of buffer.
736 @param[in] TCG2EventLogFormat TCG2EventLogFormat.
740 FillBufferWithTCG2EventLogFormat (
743 IN UINT32 TCG2EventLogFormat
747 if ((TCG2EventLogFormat
& EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
) != 0) {
748 if (Buffer
[0] != 0) {
749 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
751 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"TCG_1_2");
753 if ((TCG2EventLogFormat
& EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
) != 0) {
754 if (Buffer
[0] != 0) {
755 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
757 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"TCG_2");
759 if ((TCG2EventLogFormat
& (~EFI_TCG2_EVENT_LOG_FORMAT_ALL
)) != 0) {
760 if (Buffer
[0] != 0) {
761 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
763 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"UNKNOWN");
768 This function publish the TCG2 configuration Form for TPM device.
770 @param[in, out] PrivateData Points to TCG2 configuration private data.
772 @retval EFI_SUCCESS HII Form is installed for this network device.
773 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
774 @retval Others Other errors as indicated.
778 InstallTcg2ConfigForm (
779 IN OUT TCG2_CONFIG_PRIVATE_DATA
*PrivateData
783 EFI_HII_HANDLE HiiHandle
;
784 EFI_HANDLE DriverHandle
;
785 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
787 TPML_PCR_SELECTION Pcrs
;
788 CHAR16 TempBuffer
[1024];
789 TCG2_CONFIGURATION_INFO Tcg2ConfigInfo
;
790 TPM2_PTP_INTERFACE_TYPE TpmDeviceInterfaceDetected
;
793 ConfigAccess
= &PrivateData
->ConfigAccess
;
794 Status
= gBS
->InstallMultipleProtocolInterfaces (
796 &gEfiDevicePathProtocolGuid
,
797 &mTcg2HiiVendorDevicePath
,
798 &gEfiHiiConfigAccessProtocolGuid
,
802 if (EFI_ERROR (Status
)) {
806 PrivateData
->DriverHandle
= DriverHandle
;
809 // Publish the HII package list
811 HiiHandle
= HiiAddPackages (
812 &gTcg2ConfigFormSetGuid
,
814 Tcg2ConfigDxeStrings
,
818 if (HiiHandle
== NULL
) {
819 gBS
->UninstallMultipleProtocolInterfaces (
821 &gEfiDevicePathProtocolGuid
,
822 &mTcg2HiiVendorDevicePath
,
823 &gEfiHiiConfigAccessProtocolGuid
,
828 return EFI_OUT_OF_RESOURCES
;
831 PrivateData
->HiiHandle
= HiiHandle
;
834 // Update static data
836 switch (PrivateData
->TpmDeviceDetected
) {
837 case TPM_DEVICE_NULL
:
838 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"Not Found", NULL
);
841 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"TPM 1.2", NULL
);
843 case TPM_DEVICE_2_0_DTPM
:
844 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"TPM 2.0", NULL
);
847 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"Unknown", NULL
);
851 ZeroMem (&Tcg2ConfigInfo
, sizeof(Tcg2ConfigInfo
));
852 Status
= Tpm2GetCapabilityPcrs (&Pcrs
);
853 if (EFI_ERROR (Status
)) {
854 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT
), L
"[Unknown]", NULL
);
855 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT
), L
"[Unknown]", NULL
);
858 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
859 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
860 AppendBufferWithTpmAlgHash (TempBuffer
, sizeof(TempBuffer
), Pcrs
.pcrSelections
[Index
].hash
);
863 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
866 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
867 AppendBufferWithTpmAlgHash (TempBuffer
, sizeof(TempBuffer
), Pcrs
.pcrSelections
[Index
].hash
);
868 SetConfigInfo (&Tcg2ConfigInfo
, Pcrs
.pcrSelections
[Index
].hash
);
870 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
873 FillBufferWithBootHashAlg (TempBuffer
, sizeof(TempBuffer
), PcdGet32 (PcdTcg2HashAlgorithmBitmap
));
874 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_BIOS_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
879 FillBufferWithTCG2EventLogFormat (TempBuffer
, sizeof(TempBuffer
), PrivateData
->ProtocolCapability
.SupportedEventLogs
);
880 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_SUPPORTED_EVENT_LOG_FORMAT_CONTENT
), TempBuffer
, NULL
);
882 FillBufferWithBootHashAlg (TempBuffer
, sizeof(TempBuffer
), PrivateData
->ProtocolCapability
.HashAlgorithmBitmap
);
883 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_HASH_ALGO_BITMAP_CONTENT
), TempBuffer
, NULL
);
885 UnicodeSPrint (TempBuffer
, sizeof (TempBuffer
), L
"%d", PrivateData
->ProtocolCapability
.NumberOfPCRBanks
);
886 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_NUMBER_OF_PCR_BANKS_CONTENT
), TempBuffer
, NULL
);
888 FillBufferWithBootHashAlg (TempBuffer
, sizeof(TempBuffer
), PrivateData
->ProtocolCapability
.ActivePcrBanks
);
889 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_ACTIVE_PCR_BANKS_CONTENT
), TempBuffer
, NULL
);
892 // Update TPM device interface type
894 if (PrivateData
->TpmDeviceDetected
== TPM_DEVICE_2_0_DTPM
) {
895 TpmDeviceInterfaceDetected
= PcdGet8(PcdActiveTpmInterfaceType
);
896 switch (TpmDeviceInterfaceDetected
) {
897 case Tpm2PtpInterfaceTis
:
898 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"TIS", NULL
);
900 case Tpm2PtpInterfaceFifo
:
901 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"PTP FIFO", NULL
);
903 case Tpm2PtpInterfaceCrb
:
904 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"PTP CRB", NULL
);
907 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"Unknown", NULL
);
911 Tcg2ConfigInfo
.TpmDeviceInterfaceAttempt
= TpmDeviceInterfaceDetected
;
912 switch (TpmDeviceInterfaceDetected
) {
913 case Tpm2PtpInterfaceTis
:
914 Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
= FALSE
;
915 Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
= FALSE
;
916 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT
), L
"TIS", NULL
);
918 case Tpm2PtpInterfaceFifo
:
919 case Tpm2PtpInterfaceCrb
:
920 Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
= IsPtpFifoSupported((VOID
*) (UINTN
) PcdGet64 (PcdTpmBaseAddress
));
921 Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
= IsPtpCrbSupported((VOID
*) (UINTN
) PcdGet64 (PcdTpmBaseAddress
));
923 if (Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
) {
924 if (TempBuffer
[0] != 0) {
925 StrCatS (TempBuffer
, sizeof(TempBuffer
) / sizeof (CHAR16
), L
", ");
927 StrCatS (TempBuffer
, sizeof(TempBuffer
) / sizeof (CHAR16
), L
"PTP FIFO");
929 if (Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
) {
930 if (TempBuffer
[0] != 0) {
931 StrCatS (TempBuffer
, sizeof(TempBuffer
) / sizeof (CHAR16
), L
", ");
933 StrCatS (TempBuffer
, sizeof(TempBuffer
) / sizeof (CHAR16
), L
"PTP CRB");
935 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT
), TempBuffer
, NULL
);
938 Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
= FALSE
;
939 Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
= FALSE
;
940 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT
), L
"Unknown", NULL
);
946 // Set ConfigInfo, to control the check box.
948 Status
= gRT
->SetVariable (
949 TCG2_STORAGE_INFO_NAME
,
950 &gTcg2ConfigFormSetGuid
,
951 EFI_VARIABLE_BOOTSERVICE_ACCESS
,
952 sizeof(Tcg2ConfigInfo
),
955 if (EFI_ERROR (Status
)) {
956 DEBUG ((EFI_D_ERROR
, "Tcg2ConfigDriver: Fail to set TCG2_STORAGE_INFO_NAME\n"));
963 This function removes TCG2 configuration Form.
965 @param[in, out] PrivateData Points to TCG2 configuration private data.
969 UninstallTcg2ConfigForm (
970 IN OUT TCG2_CONFIG_PRIVATE_DATA
*PrivateData
974 // Uninstall HII package list
976 if (PrivateData
->HiiHandle
!= NULL
) {
977 HiiRemovePackages (PrivateData
->HiiHandle
);
978 PrivateData
->HiiHandle
= NULL
;
982 // Uninstall HII Config Access Protocol
984 if (PrivateData
->DriverHandle
!= NULL
) {
985 gBS
->UninstallMultipleProtocolInterfaces (
986 PrivateData
->DriverHandle
,
987 &gEfiDevicePathProtocolGuid
,
988 &mTcg2HiiVendorDevicePath
,
989 &gEfiHiiConfigAccessProtocolGuid
,
990 &PrivateData
->ConfigAccess
,
993 PrivateData
->DriverHandle
= NULL
;
996 FreePool (PrivateData
);