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 - 2017, 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/IoLib.h>
21 #include <Guid/TpmInstance.h>
23 #include <IndustryStandard/TpmPtp.h>
25 #define EFI_TCG2_EVENT_LOG_FORMAT_ALL (EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 | EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
27 TPM_INSTANCE_ID mTpmInstanceId
[TPM_DEVICE_MAX
+ 1] = TPM_INSTANCE_ID_LIST
;
29 TCG2_CONFIG_PRIVATE_DATA
*mTcg2ConfigPrivateDate
;
30 TCG2_CONFIG_PRIVATE_DATA mTcg2ConfigPrivateDateTemplate
= {
31 TCG2_CONFIG_PRIVATE_DATA_SIGNATURE
,
39 HII_VENDOR_DEVICE_PATH mTcg2HiiVendorDevicePath
= {
45 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
46 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
49 TCG2_CONFIG_FORM_SET_GUID
53 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
55 (UINT8
) (END_DEVICE_PATH_LENGTH
),
56 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
61 UINT8 mCurrentPpRequest
;
64 Return PTP interface type.
66 @param[in] Register Pointer to PTP register.
68 @return PTP interface type.
75 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId
;
76 PTP_FIFO_INTERFACE_CAPABILITY InterfaceCapability
;
81 InterfaceId
.Uint32
= MmioRead32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
);
82 InterfaceCapability
.Uint32
= MmioRead32 ((UINTN
)&((PTP_FIFO_REGISTERS
*)Register
)->InterfaceCapability
);
84 if ((InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB
) &&
85 (InterfaceId
.Bits
.InterfaceVersion
== PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_CRB
) &&
86 (InterfaceId
.Bits
.CapCRB
!= 0)) {
87 return TPM_DEVICE_INTERFACE_PTP_CRB
;
89 if ((InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO
) &&
90 (InterfaceId
.Bits
.InterfaceVersion
== PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_FIFO
) &&
91 (InterfaceId
.Bits
.CapFIFO
!= 0) &&
92 (InterfaceCapability
.Bits
.InterfaceVersion
== INTERFACE_CAPABILITY_INTERFACE_VERSION_PTP
)) {
93 return TPM_DEVICE_INTERFACE_PTP_FIFO
;
95 return TPM_DEVICE_INTERFACE_TIS
;
99 Return if PTP CRB is supported.
101 @param[in] Register Pointer to PTP register.
103 @retval TRUE PTP CRB is supported.
104 @retval FALSE PTP CRB is unsupported.
111 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId
;
114 // Check interface id
116 InterfaceId
.Uint32
= MmioRead32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
);
118 if (((InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB
) ||
119 (InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO
)) &&
120 (InterfaceId
.Bits
.CapCRB
!= 0)) {
127 Return if PTP FIFO is supported.
129 @param[in] Register Pointer to PTP register.
131 @retval TRUE PTP FIFO is supported.
132 @retval FALSE PTP FIFO is unsupported.
139 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId
;
142 // Check interface id
144 InterfaceId
.Uint32
= MmioRead32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
);
146 if (((InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB
) ||
147 (InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO
)) &&
148 (InterfaceId
.Bits
.CapFIFO
!= 0)) {
155 Set PTP interface type.
157 @param[in] Register Pointer to PTP register.
158 @param[in] PtpInterface PTP interface type.
160 @retval EFI_SUCCESS PTP interface type is set.
161 @retval EFI_INVALID_PARAMETER PTP interface type is invalid.
162 @retval EFI_UNSUPPORTED PTP interface type is unsupported.
163 @retval EFI_WRITE_PROTECTED PTP interface is locked.
168 IN UINT8 PtpInterface
171 UINT8 PtpInterfaceCurrent
;
172 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId
;
174 PtpInterfaceCurrent
= GetPtpInterface (Register
);
175 if ((PtpInterfaceCurrent
!= TPM_DEVICE_INTERFACE_PTP_FIFO
) &&
176 (PtpInterfaceCurrent
!= TPM_DEVICE_INTERFACE_PTP_CRB
)) {
177 return EFI_UNSUPPORTED
;
179 InterfaceId
.Uint32
= MmioRead32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
);
180 if (InterfaceId
.Bits
.IntfSelLock
!= 0) {
181 return EFI_WRITE_PROTECTED
;
184 switch (PtpInterface
) {
185 case TPM_DEVICE_INTERFACE_PTP_FIFO
:
186 if (InterfaceId
.Bits
.CapFIFO
== 0) {
187 return EFI_UNSUPPORTED
;
189 InterfaceId
.Bits
.InterfaceSelector
= PTP_INTERFACE_IDENTIFIER_INTERFACE_SELECTOR_FIFO
;
190 MmioWrite32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
, InterfaceId
.Uint32
);
192 case TPM_DEVICE_INTERFACE_PTP_CRB
:
193 if (InterfaceId
.Bits
.CapCRB
== 0) {
194 return EFI_UNSUPPORTED
;
196 InterfaceId
.Bits
.InterfaceSelector
= PTP_INTERFACE_IDENTIFIER_INTERFACE_SELECTOR_CRB
;
197 MmioWrite32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
, InterfaceId
.Uint32
);
200 return EFI_INVALID_PARAMETER
;
205 This function allows a caller to extract the current configuration for one
206 or more named elements from the target driver.
208 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
209 @param[in] Request A null-terminated Unicode string in
210 <ConfigRequest> format.
211 @param[out] Progress On return, points to a character in the Request
212 string. Points to the string's null terminator if
213 request was successful. Points to the most recent
214 '&' before the first failing name/value pair (or
215 the beginning of the string if the failure is in
216 the first name/value pair) if the request was not
218 @param[out] Results A null-terminated Unicode string in
219 <ConfigAltResp> format which has all values filled
220 in for the names in the Request string. String to
221 be allocated by the called function.
223 @retval EFI_SUCCESS The Results is filled with the requested values.
224 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
225 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
226 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
233 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
234 IN CONST EFI_STRING Request
,
235 OUT EFI_STRING
*Progress
,
236 OUT EFI_STRING
*Results
239 if (Progress
== NULL
|| Results
== NULL
) {
240 return EFI_INVALID_PARAMETER
;
244 return EFI_NOT_FOUND
;
248 Save TPM request to variable space.
250 @param[in] PpRequest Physical Presence request command.
252 @retval EFI_SUCCESS The operation is finished successfully.
253 @retval Others Other errors as indicated.
264 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (PpRequest
, 0);
265 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
266 mCurrentPpRequest
= PpRequest
;
267 Status
= EFI_SUCCESS
;
268 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
269 Status
= EFI_OUT_OF_RESOURCES
;
270 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
271 Status
= EFI_UNSUPPORTED
;
273 Status
= EFI_DEVICE_ERROR
;
280 Save TPM request to variable space.
282 @param[in] PpRequestParameter Physical Presence request parameter.
284 @retval EFI_SUCCESS The operation is finished successfully.
285 @retval Others Other errors as indicated.
289 SaveTcg2PpRequestParameter (
290 IN UINT32 PpRequestParameter
296 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (mCurrentPpRequest
, PpRequestParameter
);
297 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
298 Status
= EFI_SUCCESS
;
299 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
300 Status
= EFI_OUT_OF_RESOURCES
;
301 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
302 Status
= EFI_UNSUPPORTED
;
304 Status
= EFI_DEVICE_ERROR
;
311 Save Tcg2 PCR Banks request request to variable space.
313 @param[in] PCRBankIndex PCR Bank Index.
314 @param[in] Enable Enable or disable this PCR Bank.
316 @retval EFI_SUCCESS The operation is finished successfully.
317 @retval Others Other errors as indicated.
321 SaveTcg2PCRBanksRequest (
322 IN UINTN PCRBankIndex
,
330 mTcg2ConfigPrivateDate
->PCRBanksDesired
|= (0x1 << PCRBankIndex
);
332 mTcg2ConfigPrivateDate
->PCRBanksDesired
&= ~(0x1 << PCRBankIndex
);
335 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS
, mTcg2ConfigPrivateDate
->PCRBanksDesired
);
336 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
337 Status
= EFI_SUCCESS
;
338 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
339 Status
= EFI_OUT_OF_RESOURCES
;
340 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
341 Status
= EFI_UNSUPPORTED
;
343 Status
= EFI_DEVICE_ERROR
;
350 This function processes the results of changes in configuration.
352 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
353 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
355 @param[out] Progress A pointer to a string filled in with the offset of
356 the most recent '&' before the first failing
357 name/value pair (or the beginning of the string if
358 the failure is in the first name/value pair) or
359 the terminating NULL if all was successful.
361 @retval EFI_SUCCESS The Results is processed successfully.
362 @retval EFI_INVALID_PARAMETER Configuration is NULL.
363 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
370 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
371 IN CONST EFI_STRING Configuration
,
372 OUT EFI_STRING
*Progress
375 if (Configuration
== NULL
|| Progress
== NULL
) {
376 return EFI_INVALID_PARAMETER
;
379 *Progress
= Configuration
;
381 return EFI_NOT_FOUND
;
385 Get HID string of TPM2 ACPI device object
387 @param[in] Hid Points to HID String Buffer.
388 @param[in] Size HID String size in bytes. Must >= TPM_HID_ACPI_SIZE
390 @return HID String get status.
400 UINT32 ManufacturerID
;
401 UINT32 FirmwareVersion1
;
402 UINT32 FirmwareVersion2
;
410 // Get Manufacturer ID
412 Status
= Tpm2GetCapabilityManufactureID(&ManufacturerID
);
413 if (!EFI_ERROR(Status
)) {
414 DEBUG((DEBUG_INFO
, "TPM_PT_MANUFACTURER 0x%08x\n", ManufacturerID
));
416 // ManufacturerID defined in TCG Vendor ID Registry
417 // may tailed with 0x00 or 0x20
419 if ((ManufacturerID
>> 24) == 0x00 || ((ManufacturerID
>> 24) == 0x20)) {
421 // HID containing PNP ID "NNN####"
422 // NNN is uppercase letter for Vendor ID specified by manufacturer
424 CopyMem(Hid
, &ManufacturerID
, 3);
427 // HID containing ACP ID "NNNN####"
428 // NNNN is uppercase letter for Vendor ID specified by manufacturer
430 CopyMem(Hid
, &ManufacturerID
, 4);
434 DEBUG ((DEBUG_ERROR
, "Get TPM_PT_MANUFACTURER failed %x!\n", Status
));
439 Status
= Tpm2GetCapabilityFirmwareVersion(&FirmwareVersion1
, &FirmwareVersion2
);
440 if (!EFI_ERROR(Status
)) {
441 DEBUG((DEBUG_INFO
, "TPM_PT_FIRMWARE_VERSION_1 0x%x\n", FirmwareVersion1
));
442 DEBUG((DEBUG_INFO
, "TPM_PT_FIRMWARE_VERSION_2 0x%x\n", FirmwareVersion2
));
444 // #### is Firmware Version 1
447 AsciiSPrint(Hid
+ 3, TPM_HID_PNP_SIZE
- 3, "%02d%02d", ((FirmwareVersion1
& 0xFFFF0000) >> 16), (FirmwareVersion1
& 0x0000FFFF));
449 AsciiSPrint(Hid
+ 4, TPM_HID_ACPI_SIZE
- 4, "%02d%02d", ((FirmwareVersion1
& 0xFFFF0000) >> 16), (FirmwareVersion1
& 0x0000FFFF));
453 DEBUG ((DEBUG_ERROR
, "Get TPM_PT_FIRMWARE_VERSION_X failed %x!\n", Status
));
462 This function processes the results of changes in configuration
463 for TCG2 version information.
465 @param[in] Action Specifies the type of action taken by the browser.
466 ASSERT if the Action is not EFI_BROWSER_ACTION_SUBMITTED.
467 @param[in] QuestionId A unique value which is sent to the original
468 exporting driver so that it can identify the type
470 @param[in] Type The type of value for the question.
471 @param[in] Value A pointer to the data being sent to the original
474 @retval EFI_SUCCESS The callback successfully handled the action.
478 Tcg2VersionInfoCallback (
479 IN EFI_BROWSER_ACTION Action
,
480 IN EFI_QUESTION_ID QuestionId
,
482 IN EFI_IFR_TYPE_VALUE
*Value
486 UINT64 PcdTcg2PpiVersion
;
487 UINT8 PcdTpm2AcpiTableRev
;
489 ASSERT (Action
== EFI_BROWSER_ACTION_SUBMITTED
);
491 if (QuestionId
== KEY_TCG2_PPI_VERSION
) {
493 // Get the PCD value after EFI_BROWSER_ACTION_SUBMITTED,
494 // the SetVariable to TCG2_VERSION_NAME should have been done.
495 // If the PCD value is not equal to the value set to variable,
496 // the PCD is not DynamicHii type and does not map to the setup option.
498 PcdTcg2PpiVersion
= 0;
501 PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer
),
502 AsciiStrSize ((CHAR8
*) PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer
))
504 if (PcdTcg2PpiVersion
!= Value
->u64
) {
506 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
508 L
"WARNING: PcdTcgPhysicalPresenceInterfaceVer is not DynamicHii type and does not map to this option!",
509 L
"The version configuring by this setup option will not work!",
513 } else if (QuestionId
== KEY_TPM2_ACPI_REVISION
){
515 // Get the PCD value after EFI_BROWSER_ACTION_SUBMITTED,
516 // the SetVariable to TCG2_VERSION_NAME should have been done.
517 // If the PCD value is not equal to the value set to variable,
518 // the PCD is not DynamicHii type and does not map to the setup option.
520 PcdTpm2AcpiTableRev
= PcdGet8 (PcdTpm2AcpiTableRev
);
522 if (PcdTpm2AcpiTableRev
!= Value
->u8
) {
524 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
526 L
"WARNING: PcdTpm2AcpiTableRev is not DynamicHii type and does not map to this option!",
527 L
"The Revision configuring by this setup option will not work!",
537 This function processes the results of changes in configuration.
539 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
540 @param[in] Action Specifies the type of action taken by the browser.
541 @param[in] QuestionId A unique value which is sent to the original
542 exporting driver so that it can identify the type
544 @param[in] Type The type of value for the question.
545 @param[in] Value A pointer to the data being sent to the original
547 @param[out] ActionRequest On return, points to the action requested by the
550 @retval EFI_SUCCESS The callback successfully handled the action.
551 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
552 variable and its data.
553 @retval EFI_DEVICE_ERROR The variable could not be saved.
554 @retval EFI_UNSUPPORTED The specified Action is not supported by the
561 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
562 IN EFI_BROWSER_ACTION Action
,
563 IN EFI_QUESTION_ID QuestionId
,
565 IN EFI_IFR_TYPE_VALUE
*Value
,
566 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
573 TCG2_CONFIG_PRIVATE_DATA
*Private
;
575 if ((This
== NULL
) || (Value
== NULL
) || (ActionRequest
== NULL
)) {
576 return EFI_INVALID_PARAMETER
;
579 Private
= TCG2_CONFIG_PRIVATE_DATA_FROM_THIS (This
);
581 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
583 // Update TPM2 HID info
585 if (QuestionId
== KEY_TPM_DEVICE
) {
586 Status
= GetTpm2HID(HidStr
, 16);
588 if (EFI_ERROR(Status
)) {
590 // Fail to get TPM2 HID
592 HiiSetString (Private
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACPI_HID_CONTENT
), L
"Unknown", NULL
);
594 AsciiStrToUnicodeStrS(HidStr
, UnHidStr
, 16);
595 HiiSetString (Private
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACPI_HID_CONTENT
), UnHidStr
, NULL
);
601 if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
602 if (QuestionId
== KEY_TPM_DEVICE_INTERFACE
) {
603 Status
= SetPtpInterface ((VOID
*) (UINTN
) PcdGet64 (PcdTpmBaseAddress
), Value
->u8
);
604 if (EFI_ERROR (Status
)) {
606 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
608 L
"Error: Fail to set PTP interface!",
611 return EFI_DEVICE_ERROR
;
616 if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
617 if (QuestionId
== KEY_TPM_DEVICE
) {
620 if (QuestionId
== KEY_TPM2_OPERATION
) {
621 return SaveTcg2PpRequest (Value
->u8
);
623 if (QuestionId
== KEY_TPM2_OPERATION_PARAMETER
) {
624 return SaveTcg2PpRequestParameter (Value
->u32
);
626 if ((QuestionId
>= KEY_TPM2_PCR_BANKS_REQUEST_0
) && (QuestionId
<= KEY_TPM2_PCR_BANKS_REQUEST_4
)) {
627 return SaveTcg2PCRBanksRequest (QuestionId
- KEY_TPM2_PCR_BANKS_REQUEST_0
, Value
->b
);
631 if (Action
== EFI_BROWSER_ACTION_SUBMITTED
) {
632 if (QuestionId
== KEY_TCG2_PPI_VERSION
|| QuestionId
== KEY_TPM2_ACPI_REVISION
) {
633 return Tcg2VersionInfoCallback (Action
, QuestionId
, Type
, Value
);
637 return EFI_UNSUPPORTED
;
641 Append Buffer With TpmAlgHash.
643 @param[in] Buffer Buffer to be appended.
644 @param[in] BufferSize Size of buffer.
645 @param[in] TpmAlgHash TpmAlgHash.
649 AppendBufferWithTpmAlgHash (
655 switch (TpmAlgHash
) {
657 if (Buffer
[0] != 0) {
658 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
660 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA1");
663 if (Buffer
[0] != 0) {
664 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
666 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA256");
669 if (Buffer
[0] != 0) {
670 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
672 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA384");
675 if (Buffer
[0] != 0) {
676 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
678 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA512");
680 case TPM_ALG_SM3_256
:
681 if (Buffer
[0] != 0) {
682 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
684 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SM3_256");
690 Fill Buffer With BootHashAlg.
692 @param[in] Buffer Buffer to be filled.
693 @param[in] BufferSize Size of buffer.
694 @param[in] BootHashAlg BootHashAlg.
698 FillBufferWithBootHashAlg (
701 IN UINT32 BootHashAlg
705 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) != 0) {
706 if (Buffer
[0] != 0) {
707 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
709 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA1");
711 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA256
) != 0) {
712 if (Buffer
[0] != 0) {
713 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
715 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA256");
717 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA384
) != 0) {
718 if (Buffer
[0] != 0) {
719 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
721 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA384");
723 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA512
) != 0) {
724 if (Buffer
[0] != 0) {
725 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
727 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA512");
729 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SM3_256
) != 0) {
730 if (Buffer
[0] != 0) {
731 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
733 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SM3_256");
738 Set ConfigInfo according to TpmAlgHash.
740 @param[in,out] Tcg2ConfigInfo TCG2 config info.
741 @param[in] TpmAlgHash TpmAlgHash.
746 IN OUT TCG2_CONFIGURATION_INFO
*Tcg2ConfigInfo
,
750 switch (TpmAlgHash
) {
752 Tcg2ConfigInfo
->Sha1Supported
= TRUE
;
755 Tcg2ConfigInfo
->Sha256Supported
= TRUE
;
758 Tcg2ConfigInfo
->Sha384Supported
= TRUE
;
761 Tcg2ConfigInfo
->Sha512Supported
= TRUE
;
763 case TPM_ALG_SM3_256
:
764 Tcg2ConfigInfo
->Sm3Supported
= TRUE
;
770 Fill Buffer With TCG2EventLogFormat.
772 @param[in] Buffer Buffer to be filled.
773 @param[in] BufferSize Size of buffer.
774 @param[in] TCG2EventLogFormat TCG2EventLogFormat.
778 FillBufferWithTCG2EventLogFormat (
781 IN UINT32 TCG2EventLogFormat
785 if ((TCG2EventLogFormat
& EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
) != 0) {
786 if (Buffer
[0] != 0) {
787 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
789 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"TCG_1_2");
791 if ((TCG2EventLogFormat
& EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
) != 0) {
792 if (Buffer
[0] != 0) {
793 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
795 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"TCG_2");
797 if ((TCG2EventLogFormat
& (~EFI_TCG2_EVENT_LOG_FORMAT_ALL
)) != 0) {
798 if (Buffer
[0] != 0) {
799 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
801 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"UNKNOWN");
806 This function publish the TCG2 configuration Form for TPM device.
808 @param[in, out] PrivateData Points to TCG2 configuration private data.
810 @retval EFI_SUCCESS HII Form is installed for this network device.
811 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
812 @retval Others Other errors as indicated.
816 InstallTcg2ConfigForm (
817 IN OUT TCG2_CONFIG_PRIVATE_DATA
*PrivateData
821 EFI_HII_HANDLE HiiHandle
;
822 EFI_HANDLE DriverHandle
;
823 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
825 TPML_PCR_SELECTION Pcrs
;
826 CHAR16 TempBuffer
[1024];
827 TCG2_CONFIGURATION_INFO Tcg2ConfigInfo
;
828 UINT8 TpmDeviceInterfaceDetected
;
831 ConfigAccess
= &PrivateData
->ConfigAccess
;
832 Status
= gBS
->InstallMultipleProtocolInterfaces (
834 &gEfiDevicePathProtocolGuid
,
835 &mTcg2HiiVendorDevicePath
,
836 &gEfiHiiConfigAccessProtocolGuid
,
840 if (EFI_ERROR (Status
)) {
844 PrivateData
->DriverHandle
= DriverHandle
;
847 // Publish the HII package list
849 HiiHandle
= HiiAddPackages (
850 &gTcg2ConfigFormSetGuid
,
852 Tcg2ConfigDxeStrings
,
856 if (HiiHandle
== NULL
) {
857 gBS
->UninstallMultipleProtocolInterfaces (
859 &gEfiDevicePathProtocolGuid
,
860 &mTcg2HiiVendorDevicePath
,
861 &gEfiHiiConfigAccessProtocolGuid
,
866 return EFI_OUT_OF_RESOURCES
;
869 PrivateData
->HiiHandle
= HiiHandle
;
872 // Update static data
874 switch (PrivateData
->TpmDeviceDetected
) {
875 case TPM_DEVICE_NULL
:
876 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"Not Found", NULL
);
879 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"TPM 1.2", NULL
);
881 case TPM_DEVICE_2_0_DTPM
:
882 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"TPM 2.0", NULL
);
885 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"Unknown", NULL
);
889 ZeroMem (&Tcg2ConfigInfo
, sizeof(Tcg2ConfigInfo
));
890 Status
= Tpm2GetCapabilityPcrs (&Pcrs
);
891 if (EFI_ERROR (Status
)) {
892 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT
), L
"[Unknown]", NULL
);
893 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT
), L
"[Unknown]", NULL
);
896 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
897 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
898 AppendBufferWithTpmAlgHash (TempBuffer
, sizeof(TempBuffer
), Pcrs
.pcrSelections
[Index
].hash
);
901 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
904 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
905 AppendBufferWithTpmAlgHash (TempBuffer
, sizeof(TempBuffer
), Pcrs
.pcrSelections
[Index
].hash
);
906 SetConfigInfo (&Tcg2ConfigInfo
, Pcrs
.pcrSelections
[Index
].hash
);
908 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
911 FillBufferWithBootHashAlg (TempBuffer
, sizeof(TempBuffer
), PcdGet32 (PcdTcg2HashAlgorithmBitmap
));
912 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_BIOS_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
917 FillBufferWithTCG2EventLogFormat (TempBuffer
, sizeof(TempBuffer
), PrivateData
->ProtocolCapability
.SupportedEventLogs
);
918 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_SUPPORTED_EVENT_LOG_FORMAT_CONTENT
), TempBuffer
, NULL
);
920 FillBufferWithBootHashAlg (TempBuffer
, sizeof(TempBuffer
), PrivateData
->ProtocolCapability
.HashAlgorithmBitmap
);
921 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_HASH_ALGO_BITMAP_CONTENT
), TempBuffer
, NULL
);
923 UnicodeSPrint (TempBuffer
, sizeof (TempBuffer
), L
"%d", PrivateData
->ProtocolCapability
.NumberOfPCRBanks
);
924 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_NUMBER_OF_PCR_BANKS_CONTENT
), TempBuffer
, NULL
);
926 FillBufferWithBootHashAlg (TempBuffer
, sizeof(TempBuffer
), PrivateData
->ProtocolCapability
.ActivePcrBanks
);
927 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_ACTIVE_PCR_BANKS_CONTENT
), TempBuffer
, NULL
);
930 // Update TPM device interface type
932 if (PrivateData
->TpmDeviceDetected
== TPM_DEVICE_2_0_DTPM
) {
933 TpmDeviceInterfaceDetected
= GetPtpInterface ((VOID
*) (UINTN
) PcdGet64 (PcdTpmBaseAddress
));
934 switch (TpmDeviceInterfaceDetected
) {
935 case TPM_DEVICE_INTERFACE_TIS
:
936 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"TIS", NULL
);
938 case TPM_DEVICE_INTERFACE_PTP_FIFO
:
939 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"PTP FIFO", NULL
);
941 case TPM_DEVICE_INTERFACE_PTP_CRB
:
942 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"PTP CRB", NULL
);
945 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"Unknown", NULL
);
949 Tcg2ConfigInfo
.TpmDeviceInterfaceAttempt
= TpmDeviceInterfaceDetected
;
950 switch (TpmDeviceInterfaceDetected
) {
951 case TPM_DEVICE_INTERFACE_TIS
:
952 Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
= FALSE
;
953 Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
= FALSE
;
954 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT
), L
"TIS", NULL
);
956 case TPM_DEVICE_INTERFACE_PTP_FIFO
:
957 case TPM_DEVICE_INTERFACE_PTP_CRB
:
958 Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
= IsPtpFifoSupported((VOID
*) (UINTN
) PcdGet64 (PcdTpmBaseAddress
));
959 Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
= IsPtpCrbSupported((VOID
*) (UINTN
) PcdGet64 (PcdTpmBaseAddress
));
961 if (Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
) {
962 if (TempBuffer
[0] != 0) {
963 StrCatS (TempBuffer
, sizeof(TempBuffer
) / sizeof (CHAR16
), L
", ");
965 StrCatS (TempBuffer
, sizeof(TempBuffer
) / sizeof (CHAR16
), L
"PTP FIFO");
967 if (Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
) {
968 if (TempBuffer
[0] != 0) {
969 StrCatS (TempBuffer
, sizeof(TempBuffer
) / sizeof (CHAR16
), L
", ");
971 StrCatS (TempBuffer
, sizeof(TempBuffer
) / sizeof (CHAR16
), L
"PTP CRB");
973 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT
), TempBuffer
, NULL
);
976 Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
= FALSE
;
977 Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
= FALSE
;
978 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT
), L
"Unknown", NULL
);
984 // Set ConfigInfo, to control the check box.
986 Status
= gRT
->SetVariable (
987 TCG2_STORAGE_INFO_NAME
,
988 &gTcg2ConfigFormSetGuid
,
989 EFI_VARIABLE_BOOTSERVICE_ACCESS
,
990 sizeof(Tcg2ConfigInfo
),
993 if (EFI_ERROR (Status
)) {
994 DEBUG ((EFI_D_ERROR
, "Tcg2ConfigDriver: Fail to set TCG2_STORAGE_INFO_NAME\n"));
1001 This function removes TCG2 configuration Form.
1003 @param[in, out] PrivateData Points to TCG2 configuration private data.
1007 UninstallTcg2ConfigForm (
1008 IN OUT TCG2_CONFIG_PRIVATE_DATA
*PrivateData
1012 // Uninstall HII package list
1014 if (PrivateData
->HiiHandle
!= NULL
) {
1015 HiiRemovePackages (PrivateData
->HiiHandle
);
1016 PrivateData
->HiiHandle
= NULL
;
1020 // Uninstall HII Config Access Protocol
1022 if (PrivateData
->DriverHandle
!= NULL
) {
1023 gBS
->UninstallMultipleProtocolInterfaces (
1024 PrivateData
->DriverHandle
,
1025 &gEfiDevicePathProtocolGuid
,
1026 &mTcg2HiiVendorDevicePath
,
1027 &gEfiHiiConfigAccessProtocolGuid
,
1028 &PrivateData
->ConfigAccess
,
1031 PrivateData
->DriverHandle
= NULL
;
1034 FreePool (PrivateData
);