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 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "Tcg2ConfigImpl.h"
18 #include <Library/PcdLib.h>
19 #include <Library/Tpm2CommandLib.h>
20 #include <Library/Tpm2DeviceLib.h>
21 #include <Library/IoLib.h>
23 #include <Guid/TpmInstance.h>
25 #include <IndustryStandard/TpmPtp.h>
27 #define EFI_TCG2_EVENT_LOG_FORMAT_ALL (EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 | EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
29 TPM_INSTANCE_ID mTpmInstanceId
[TPM_DEVICE_MAX
+ 1] = TPM_INSTANCE_ID_LIST
;
31 TCG2_CONFIG_PRIVATE_DATA
*mTcg2ConfigPrivateDate
;
32 TCG2_CONFIG_PRIVATE_DATA mTcg2ConfigPrivateDateTemplate
= {
33 TCG2_CONFIG_PRIVATE_DATA_SIGNATURE
,
41 HII_VENDOR_DEVICE_PATH mTcg2HiiVendorDevicePath
= {
47 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
48 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
51 TCG2_CONFIG_FORM_SET_GUID
55 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
57 (UINT8
) (END_DEVICE_PATH_LENGTH
),
58 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
63 UINT8 mCurrentPpRequest
;
66 Return if PTP CRB is supported.
68 @param[in] Register Pointer to PTP register.
70 @retval TRUE PTP CRB is supported.
71 @retval FALSE PTP CRB is unsupported.
78 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId
;
83 InterfaceId
.Uint32
= MmioRead32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
);
85 if (((InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB
) ||
86 (InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO
)) &&
87 (InterfaceId
.Bits
.CapCRB
!= 0)) {
94 Return if PTP FIFO is supported.
96 @param[in] Register Pointer to PTP register.
98 @retval TRUE PTP FIFO is supported.
99 @retval FALSE PTP FIFO is unsupported.
106 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId
;
109 // Check interface id
111 InterfaceId
.Uint32
= MmioRead32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
);
113 if (((InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB
) ||
114 (InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO
)) &&
115 (InterfaceId
.Bits
.CapFIFO
!= 0)) {
122 Set PTP interface type.
123 Do not update PcdActiveTpmInterfaceType here because interface change only happens on next _TPM_INIT
125 @param[in] Register Pointer to PTP register.
126 @param[in] PtpInterface PTP interface type.
128 @retval EFI_SUCCESS PTP interface type is set.
129 @retval EFI_INVALID_PARAMETER PTP interface type is invalid.
130 @retval EFI_UNSUPPORTED PTP interface type is unsupported.
131 @retval EFI_WRITE_PROTECTED PTP interface is locked.
136 IN UINT8 PtpInterface
139 TPM2_PTP_INTERFACE_TYPE PtpInterfaceCurrent
;
140 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId
;
142 PtpInterfaceCurrent
= PcdGet8(PcdActiveTpmInterfaceType
);
143 if ((PtpInterfaceCurrent
!= Tpm2PtpInterfaceFifo
) &&
144 (PtpInterfaceCurrent
!= Tpm2PtpInterfaceCrb
)) {
145 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
;
157 InterfaceId
.Bits
.InterfaceSelector
= PTP_INTERFACE_IDENTIFIER_INTERFACE_SELECTOR_FIFO
;
158 MmioWrite32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
, InterfaceId
.Uint32
);
160 case Tpm2PtpInterfaceCrb
:
161 if (InterfaceId
.Bits
.CapCRB
== 0) {
162 return EFI_UNSUPPORTED
;
164 InterfaceId
.Bits
.InterfaceSelector
= PTP_INTERFACE_IDENTIFIER_INTERFACE_SELECTOR_CRB
;
165 MmioWrite32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
, InterfaceId
.Uint32
);
168 return EFI_INVALID_PARAMETER
;
173 This function allows a caller to extract the current configuration for one
174 or more named elements from the target driver.
176 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
177 @param[in] Request A null-terminated Unicode string in
178 <ConfigRequest> format.
179 @param[out] Progress On return, points to a character in the Request
180 string. Points to the string's null terminator if
181 request was successful. Points to the most recent
182 '&' before the first failing name/value pair (or
183 the beginning of the string if the failure is in
184 the first name/value pair) if the request was not
186 @param[out] Results A null-terminated Unicode string in
187 <ConfigAltResp> format which has all values filled
188 in for the names in the Request string. String to
189 be allocated by the called function.
191 @retval EFI_SUCCESS The Results is filled with the requested values.
192 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
193 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
194 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
201 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
202 IN CONST EFI_STRING Request
,
203 OUT EFI_STRING
*Progress
,
204 OUT EFI_STRING
*Results
207 if (Progress
== NULL
|| Results
== NULL
) {
208 return EFI_INVALID_PARAMETER
;
212 return EFI_NOT_FOUND
;
216 Save TPM request to variable space.
218 @param[in] PpRequest Physical Presence request command.
220 @retval EFI_SUCCESS The operation is finished successfully.
221 @retval Others Other errors as indicated.
232 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (PpRequest
, 0);
233 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
234 mCurrentPpRequest
= PpRequest
;
235 Status
= EFI_SUCCESS
;
236 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
237 Status
= EFI_OUT_OF_RESOURCES
;
238 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
239 Status
= EFI_UNSUPPORTED
;
241 Status
= EFI_DEVICE_ERROR
;
248 Save TPM request to variable space.
250 @param[in] PpRequestParameter Physical Presence request parameter.
252 @retval EFI_SUCCESS The operation is finished successfully.
253 @retval Others Other errors as indicated.
257 SaveTcg2PpRequestParameter (
258 IN UINT32 PpRequestParameter
264 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (mCurrentPpRequest
, PpRequestParameter
);
265 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
266 Status
= EFI_SUCCESS
;
267 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
268 Status
= EFI_OUT_OF_RESOURCES
;
269 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
270 Status
= EFI_UNSUPPORTED
;
272 Status
= EFI_DEVICE_ERROR
;
279 Save Tcg2 PCR Banks request request to variable space.
281 @param[in] PCRBankIndex PCR Bank Index.
282 @param[in] Enable Enable or disable this PCR Bank.
284 @retval EFI_SUCCESS The operation is finished successfully.
285 @retval Others Other errors as indicated.
289 SaveTcg2PCRBanksRequest (
290 IN UINTN PCRBankIndex
,
298 mTcg2ConfigPrivateDate
->PCRBanksDesired
|= (0x1 << PCRBankIndex
);
300 mTcg2ConfigPrivateDate
->PCRBanksDesired
&= ~(0x1 << PCRBankIndex
);
303 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS
, mTcg2ConfigPrivateDate
->PCRBanksDesired
);
304 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
305 Status
= EFI_SUCCESS
;
306 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
307 Status
= EFI_OUT_OF_RESOURCES
;
308 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
309 Status
= EFI_UNSUPPORTED
;
311 Status
= EFI_DEVICE_ERROR
;
318 This function processes the results of changes in configuration.
320 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
321 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
323 @param[out] Progress A pointer to a string filled in with the offset of
324 the most recent '&' before the first failing
325 name/value pair (or the beginning of the string if
326 the failure is in the first name/value pair) or
327 the terminating NULL if all was successful.
329 @retval EFI_SUCCESS The Results is processed successfully.
330 @retval EFI_INVALID_PARAMETER Configuration is NULL.
331 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
338 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
339 IN CONST EFI_STRING Configuration
,
340 OUT EFI_STRING
*Progress
343 if (Configuration
== NULL
|| Progress
== NULL
) {
344 return EFI_INVALID_PARAMETER
;
347 *Progress
= Configuration
;
349 return EFI_NOT_FOUND
;
353 Get HID string of TPM2 ACPI device object
355 @param[in] Hid Points to HID String Buffer.
356 @param[in] Size HID String size in bytes. Must >= TPM_HID_ACPI_SIZE
358 @return HID String get status.
368 UINT32 ManufacturerID
;
369 UINT32 FirmwareVersion1
;
370 UINT32 FirmwareVersion2
;
378 // Get Manufacturer ID
380 Status
= Tpm2GetCapabilityManufactureID(&ManufacturerID
);
381 if (!EFI_ERROR(Status
)) {
382 DEBUG((DEBUG_INFO
, "TPM_PT_MANUFACTURER 0x%08x\n", ManufacturerID
));
384 // ManufacturerID defined in TCG Vendor ID Registry
385 // may tailed with 0x00 or 0x20
387 if ((ManufacturerID
>> 24) == 0x00 || ((ManufacturerID
>> 24) == 0x20)) {
389 // HID containing PNP ID "NNN####"
390 // NNN is uppercase letter for Vendor ID specified by manufacturer
392 CopyMem(Hid
, &ManufacturerID
, 3);
395 // HID containing ACP ID "NNNN####"
396 // NNNN is uppercase letter for Vendor ID specified by manufacturer
398 CopyMem(Hid
, &ManufacturerID
, 4);
402 DEBUG ((DEBUG_ERROR
, "Get TPM_PT_MANUFACTURER failed %x!\n", Status
));
407 Status
= Tpm2GetCapabilityFirmwareVersion(&FirmwareVersion1
, &FirmwareVersion2
);
408 if (!EFI_ERROR(Status
)) {
409 DEBUG((DEBUG_INFO
, "TPM_PT_FIRMWARE_VERSION_1 0x%x\n", FirmwareVersion1
));
410 DEBUG((DEBUG_INFO
, "TPM_PT_FIRMWARE_VERSION_2 0x%x\n", FirmwareVersion2
));
412 // #### is Firmware Version 1
415 AsciiSPrint(Hid
+ 3, TPM_HID_PNP_SIZE
- 3, "%02d%02d", ((FirmwareVersion1
& 0xFFFF0000) >> 16), (FirmwareVersion1
& 0x0000FFFF));
417 AsciiSPrint(Hid
+ 4, TPM_HID_ACPI_SIZE
- 4, "%02d%02d", ((FirmwareVersion1
& 0xFFFF0000) >> 16), (FirmwareVersion1
& 0x0000FFFF));
421 DEBUG ((DEBUG_ERROR
, "Get TPM_PT_FIRMWARE_VERSION_X failed %x!\n", Status
));
430 This function processes the results of changes in configuration
431 for TCG2 version information.
433 @param[in] Action Specifies the type of action taken by the browser.
434 ASSERT if the Action is not EFI_BROWSER_ACTION_SUBMITTED.
435 @param[in] QuestionId A unique value which is sent to the original
436 exporting driver so that it can identify the type
438 @param[in] Type The type of value for the question.
439 @param[in] Value A pointer to the data being sent to the original
442 @retval EFI_SUCCESS The callback successfully handled the action.
446 Tcg2VersionInfoCallback (
447 IN EFI_BROWSER_ACTION Action
,
448 IN EFI_QUESTION_ID QuestionId
,
450 IN EFI_IFR_TYPE_VALUE
*Value
454 UINT64 PcdTcg2PpiVersion
;
455 UINT8 PcdTpm2AcpiTableRev
;
457 ASSERT (Action
== EFI_BROWSER_ACTION_SUBMITTED
);
459 if (QuestionId
== KEY_TCG2_PPI_VERSION
) {
461 // Get the PCD value after EFI_BROWSER_ACTION_SUBMITTED,
462 // the SetVariable to TCG2_VERSION_NAME should have been done.
463 // If the PCD value is not equal to the value set to variable,
464 // the PCD is not DynamicHii type and does not map to the setup option.
466 PcdTcg2PpiVersion
= 0;
469 PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer
),
470 AsciiStrSize ((CHAR8
*) PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer
))
472 if (PcdTcg2PpiVersion
!= Value
->u64
) {
474 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
476 L
"WARNING: PcdTcgPhysicalPresenceInterfaceVer is not DynamicHii type and does not map to this option!",
477 L
"The version configuring by this setup option will not work!",
481 } else if (QuestionId
== KEY_TPM2_ACPI_REVISION
){
483 // Get the PCD value after EFI_BROWSER_ACTION_SUBMITTED,
484 // the SetVariable to TCG2_VERSION_NAME should have been done.
485 // If the PCD value is not equal to the value set to variable,
486 // the PCD is not DynamicHii type and does not map to the setup option.
488 PcdTpm2AcpiTableRev
= PcdGet8 (PcdTpm2AcpiTableRev
);
490 if (PcdTpm2AcpiTableRev
!= Value
->u8
) {
492 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
494 L
"WARNING: PcdTpm2AcpiTableRev is not DynamicHii type and does not map to this option!",
495 L
"The Revision configuring by this setup option will not work!",
505 This function processes the results of changes in configuration.
507 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
508 @param[in] Action Specifies the type of action taken by the browser.
509 @param[in] QuestionId A unique value which is sent to the original
510 exporting driver so that it can identify the type
512 @param[in] Type The type of value for the question.
513 @param[in] Value A pointer to the data being sent to the original
515 @param[out] ActionRequest On return, points to the action requested by the
518 @retval EFI_SUCCESS The callback successfully handled the action.
519 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
520 variable and its data.
521 @retval EFI_DEVICE_ERROR The variable could not be saved.
522 @retval EFI_UNSUPPORTED The specified Action is not supported by the
529 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
530 IN EFI_BROWSER_ACTION Action
,
531 IN EFI_QUESTION_ID QuestionId
,
533 IN EFI_IFR_TYPE_VALUE
*Value
,
534 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
541 TCG2_CONFIG_PRIVATE_DATA
*Private
;
543 if ((This
== NULL
) || (Value
== NULL
) || (ActionRequest
== NULL
)) {
544 return EFI_INVALID_PARAMETER
;
547 Private
= TCG2_CONFIG_PRIVATE_DATA_FROM_THIS (This
);
549 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
551 // Update TPM2 HID info
553 if (QuestionId
== KEY_TPM_DEVICE
) {
554 Status
= GetTpm2HID(HidStr
, 16);
556 if (EFI_ERROR(Status
)) {
558 // Fail to get TPM2 HID
560 HiiSetString (Private
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACPI_HID_CONTENT
), L
"Unknown", NULL
);
562 AsciiStrToUnicodeStrS(HidStr
, UnHidStr
, 16);
563 HiiSetString (Private
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACPI_HID_CONTENT
), UnHidStr
, NULL
);
569 if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
570 if (QuestionId
== KEY_TPM_DEVICE_INTERFACE
) {
571 Status
= SetPtpInterface ((VOID
*) (UINTN
) PcdGet64 (PcdTpmBaseAddress
), Value
->u8
);
572 if (EFI_ERROR (Status
)) {
574 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
576 L
"Error: Fail to set PTP interface!",
579 return EFI_DEVICE_ERROR
;
584 if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
585 if (QuestionId
== KEY_TPM_DEVICE
) {
588 if (QuestionId
== KEY_TPM2_OPERATION
) {
589 return SaveTcg2PpRequest (Value
->u8
);
591 if (QuestionId
== KEY_TPM2_OPERATION_PARAMETER
) {
592 return SaveTcg2PpRequestParameter (Value
->u32
);
594 if ((QuestionId
>= KEY_TPM2_PCR_BANKS_REQUEST_0
) && (QuestionId
<= KEY_TPM2_PCR_BANKS_REQUEST_4
)) {
595 return SaveTcg2PCRBanksRequest (QuestionId
- KEY_TPM2_PCR_BANKS_REQUEST_0
, Value
->b
);
599 if (Action
== EFI_BROWSER_ACTION_SUBMITTED
) {
600 if (QuestionId
== KEY_TCG2_PPI_VERSION
|| QuestionId
== KEY_TPM2_ACPI_REVISION
) {
601 return Tcg2VersionInfoCallback (Action
, QuestionId
, Type
, Value
);
605 return EFI_UNSUPPORTED
;
609 Append Buffer With TpmAlgHash.
611 @param[in] Buffer Buffer to be appended.
612 @param[in] BufferSize Size of buffer.
613 @param[in] TpmAlgHash TpmAlgHash.
617 AppendBufferWithTpmAlgHash (
623 switch (TpmAlgHash
) {
625 if (Buffer
[0] != 0) {
626 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
628 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA1");
631 if (Buffer
[0] != 0) {
632 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
634 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA256");
637 if (Buffer
[0] != 0) {
638 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
640 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA384");
643 if (Buffer
[0] != 0) {
644 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
646 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA512");
648 case TPM_ALG_SM3_256
:
649 if (Buffer
[0] != 0) {
650 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
652 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SM3_256");
658 Fill Buffer With BootHashAlg.
660 @param[in] Buffer Buffer to be filled.
661 @param[in] BufferSize Size of buffer.
662 @param[in] BootHashAlg BootHashAlg.
666 FillBufferWithBootHashAlg (
669 IN UINT32 BootHashAlg
673 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) != 0) {
674 if (Buffer
[0] != 0) {
675 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
677 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA1");
679 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA256
) != 0) {
680 if (Buffer
[0] != 0) {
681 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
683 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA256");
685 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA384
) != 0) {
686 if (Buffer
[0] != 0) {
687 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
689 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA384");
691 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA512
) != 0) {
692 if (Buffer
[0] != 0) {
693 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
695 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA512");
697 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SM3_256
) != 0) {
698 if (Buffer
[0] != 0) {
699 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
701 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SM3_256");
706 Set ConfigInfo according to TpmAlgHash.
708 @param[in,out] Tcg2ConfigInfo TCG2 config info.
709 @param[in] TpmAlgHash TpmAlgHash.
714 IN OUT TCG2_CONFIGURATION_INFO
*Tcg2ConfigInfo
,
718 switch (TpmAlgHash
) {
720 Tcg2ConfigInfo
->Sha1Supported
= TRUE
;
723 Tcg2ConfigInfo
->Sha256Supported
= TRUE
;
726 Tcg2ConfigInfo
->Sha384Supported
= TRUE
;
729 Tcg2ConfigInfo
->Sha512Supported
= TRUE
;
731 case TPM_ALG_SM3_256
:
732 Tcg2ConfigInfo
->Sm3Supported
= TRUE
;
738 Fill Buffer With TCG2EventLogFormat.
740 @param[in] Buffer Buffer to be filled.
741 @param[in] BufferSize Size of buffer.
742 @param[in] TCG2EventLogFormat TCG2EventLogFormat.
746 FillBufferWithTCG2EventLogFormat (
749 IN UINT32 TCG2EventLogFormat
753 if ((TCG2EventLogFormat
& EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
) != 0) {
754 if (Buffer
[0] != 0) {
755 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
757 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"TCG_1_2");
759 if ((TCG2EventLogFormat
& EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
) != 0) {
760 if (Buffer
[0] != 0) {
761 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
763 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"TCG_2");
765 if ((TCG2EventLogFormat
& (~EFI_TCG2_EVENT_LOG_FORMAT_ALL
)) != 0) {
766 if (Buffer
[0] != 0) {
767 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
769 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"UNKNOWN");
774 This function publish the TCG2 configuration Form for TPM device.
776 @param[in, out] PrivateData Points to TCG2 configuration private data.
778 @retval EFI_SUCCESS HII Form is installed for this network device.
779 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
780 @retval Others Other errors as indicated.
784 InstallTcg2ConfigForm (
785 IN OUT TCG2_CONFIG_PRIVATE_DATA
*PrivateData
789 EFI_HII_HANDLE HiiHandle
;
790 EFI_HANDLE DriverHandle
;
791 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
793 TPML_PCR_SELECTION Pcrs
;
794 CHAR16 TempBuffer
[1024];
795 TCG2_CONFIGURATION_INFO Tcg2ConfigInfo
;
796 TPM2_PTP_INTERFACE_TYPE TpmDeviceInterfaceDetected
;
799 ConfigAccess
= &PrivateData
->ConfigAccess
;
800 Status
= gBS
->InstallMultipleProtocolInterfaces (
802 &gEfiDevicePathProtocolGuid
,
803 &mTcg2HiiVendorDevicePath
,
804 &gEfiHiiConfigAccessProtocolGuid
,
808 if (EFI_ERROR (Status
)) {
812 PrivateData
->DriverHandle
= DriverHandle
;
815 // Publish the HII package list
817 HiiHandle
= HiiAddPackages (
818 &gTcg2ConfigFormSetGuid
,
820 Tcg2ConfigDxeStrings
,
824 if (HiiHandle
== NULL
) {
825 gBS
->UninstallMultipleProtocolInterfaces (
827 &gEfiDevicePathProtocolGuid
,
828 &mTcg2HiiVendorDevicePath
,
829 &gEfiHiiConfigAccessProtocolGuid
,
834 return EFI_OUT_OF_RESOURCES
;
837 PrivateData
->HiiHandle
= HiiHandle
;
840 // Update static data
842 switch (PrivateData
->TpmDeviceDetected
) {
843 case TPM_DEVICE_NULL
:
844 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"Not Found", NULL
);
847 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"TPM 1.2", NULL
);
849 case TPM_DEVICE_2_0_DTPM
:
850 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"TPM 2.0", NULL
);
853 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"Unknown", NULL
);
857 ZeroMem (&Tcg2ConfigInfo
, sizeof(Tcg2ConfigInfo
));
858 Status
= Tpm2GetCapabilityPcrs (&Pcrs
);
859 if (EFI_ERROR (Status
)) {
860 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT
), L
"[Unknown]", NULL
);
861 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT
), L
"[Unknown]", NULL
);
864 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
865 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
866 AppendBufferWithTpmAlgHash (TempBuffer
, sizeof(TempBuffer
), Pcrs
.pcrSelections
[Index
].hash
);
869 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
872 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
873 AppendBufferWithTpmAlgHash (TempBuffer
, sizeof(TempBuffer
), Pcrs
.pcrSelections
[Index
].hash
);
874 SetConfigInfo (&Tcg2ConfigInfo
, Pcrs
.pcrSelections
[Index
].hash
);
876 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
879 FillBufferWithBootHashAlg (TempBuffer
, sizeof(TempBuffer
), PcdGet32 (PcdTcg2HashAlgorithmBitmap
));
880 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_BIOS_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
885 FillBufferWithTCG2EventLogFormat (TempBuffer
, sizeof(TempBuffer
), PrivateData
->ProtocolCapability
.SupportedEventLogs
);
886 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_SUPPORTED_EVENT_LOG_FORMAT_CONTENT
), TempBuffer
, NULL
);
888 FillBufferWithBootHashAlg (TempBuffer
, sizeof(TempBuffer
), PrivateData
->ProtocolCapability
.HashAlgorithmBitmap
);
889 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_HASH_ALGO_BITMAP_CONTENT
), TempBuffer
, NULL
);
891 UnicodeSPrint (TempBuffer
, sizeof (TempBuffer
), L
"%d", PrivateData
->ProtocolCapability
.NumberOfPCRBanks
);
892 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_NUMBER_OF_PCR_BANKS_CONTENT
), TempBuffer
, NULL
);
894 FillBufferWithBootHashAlg (TempBuffer
, sizeof(TempBuffer
), PrivateData
->ProtocolCapability
.ActivePcrBanks
);
895 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_ACTIVE_PCR_BANKS_CONTENT
), TempBuffer
, NULL
);
898 // Update TPM device interface type
900 if (PrivateData
->TpmDeviceDetected
== TPM_DEVICE_2_0_DTPM
) {
901 TpmDeviceInterfaceDetected
= PcdGet8(PcdActiveTpmInterfaceType
);
902 switch (TpmDeviceInterfaceDetected
) {
903 case Tpm2PtpInterfaceTis
:
904 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"TIS", NULL
);
906 case Tpm2PtpInterfaceFifo
:
907 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"PTP FIFO", NULL
);
909 case Tpm2PtpInterfaceCrb
:
910 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"PTP CRB", NULL
);
913 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"Unknown", NULL
);
917 Tcg2ConfigInfo
.TpmDeviceInterfaceAttempt
= TpmDeviceInterfaceDetected
;
918 switch (TpmDeviceInterfaceDetected
) {
919 case Tpm2PtpInterfaceTis
:
920 Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
= FALSE
;
921 Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
= FALSE
;
922 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT
), L
"TIS", NULL
);
924 case Tpm2PtpInterfaceFifo
:
925 case Tpm2PtpInterfaceCrb
:
926 Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
= IsPtpFifoSupported((VOID
*) (UINTN
) PcdGet64 (PcdTpmBaseAddress
));
927 Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
= IsPtpCrbSupported((VOID
*) (UINTN
) PcdGet64 (PcdTpmBaseAddress
));
929 if (Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
) {
930 if (TempBuffer
[0] != 0) {
931 StrCatS (TempBuffer
, sizeof(TempBuffer
) / sizeof (CHAR16
), L
", ");
933 StrCatS (TempBuffer
, sizeof(TempBuffer
) / sizeof (CHAR16
), L
"PTP FIFO");
935 if (Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
) {
936 if (TempBuffer
[0] != 0) {
937 StrCatS (TempBuffer
, sizeof(TempBuffer
) / sizeof (CHAR16
), L
", ");
939 StrCatS (TempBuffer
, sizeof(TempBuffer
) / sizeof (CHAR16
), L
"PTP CRB");
941 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT
), TempBuffer
, NULL
);
944 Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
= FALSE
;
945 Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
= FALSE
;
946 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT
), L
"Unknown", NULL
);
952 // Set ConfigInfo, to control the check box.
954 Status
= gRT
->SetVariable (
955 TCG2_STORAGE_INFO_NAME
,
956 &gTcg2ConfigFormSetGuid
,
957 EFI_VARIABLE_BOOTSERVICE_ACCESS
,
958 sizeof(Tcg2ConfigInfo
),
961 if (EFI_ERROR (Status
)) {
962 DEBUG ((EFI_D_ERROR
, "Tcg2ConfigDriver: Fail to set TCG2_STORAGE_INFO_NAME\n"));
969 This function removes TCG2 configuration Form.
971 @param[in, out] PrivateData Points to TCG2 configuration private data.
975 UninstallTcg2ConfigForm (
976 IN OUT TCG2_CONFIG_PRIVATE_DATA
*PrivateData
980 // Uninstall HII package list
982 if (PrivateData
->HiiHandle
!= NULL
) {
983 HiiRemovePackages (PrivateData
->HiiHandle
);
984 PrivateData
->HiiHandle
= NULL
;
988 // Uninstall HII Config Access Protocol
990 if (PrivateData
->DriverHandle
!= NULL
) {
991 gBS
->UninstallMultipleProtocolInterfaces (
992 PrivateData
->DriverHandle
,
993 &gEfiDevicePathProtocolGuid
,
994 &mTcg2HiiVendorDevicePath
,
995 &gEfiHiiConfigAccessProtocolGuid
,
996 &PrivateData
->ConfigAccess
,
999 PrivateData
->DriverHandle
= NULL
;
1002 FreePool (PrivateData
);