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 This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "Tcg2ConfigImpl.h"
17 #include <Library/PcdLib.h>
18 #include <Library/Tpm2CommandLib.h>
19 #include <Library/IoLib.h>
20 #include <Guid/TpmInstance.h>
22 #include <IndustryStandard/TpmPtp.h>
24 #define EFI_TCG2_EVENT_LOG_FORMAT_ALL (EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 | EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
26 TPM_INSTANCE_ID mTpmInstanceId
[TPM_DEVICE_MAX
+ 1] = TPM_INSTANCE_ID_LIST
;
28 TCG2_CONFIG_PRIVATE_DATA
*mTcg2ConfigPrivateDate
;
29 TCG2_CONFIG_PRIVATE_DATA mTcg2ConfigPrivateDateTemplate
= {
30 TCG2_CONFIG_PRIVATE_DATA_SIGNATURE
,
38 HII_VENDOR_DEVICE_PATH mTcg2HiiVendorDevicePath
= {
44 (UINT8
) (sizeof (VENDOR_DEVICE_PATH
)),
45 (UINT8
) ((sizeof (VENDOR_DEVICE_PATH
)) >> 8)
48 TCG2_CONFIG_FORM_SET_GUID
52 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
54 (UINT8
) (END_DEVICE_PATH_LENGTH
),
55 (UINT8
) ((END_DEVICE_PATH_LENGTH
) >> 8)
60 UINT8 mCurrentPpRequest
;
63 Return PTP interface type.
65 @param[in] Register Pointer to PTP register.
67 @return PTP interface type.
74 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId
;
75 PTP_FIFO_INTERFACE_CAPABILITY InterfaceCapability
;
80 InterfaceId
.Uint32
= MmioRead32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
);
81 InterfaceCapability
.Uint32
= MmioRead32 ((UINTN
)&((PTP_FIFO_REGISTERS
*)Register
)->InterfaceCapability
);
83 if ((InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB
) &&
84 (InterfaceId
.Bits
.InterfaceVersion
== PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_CRB
) &&
85 (InterfaceId
.Bits
.CapCRB
!= 0)) {
86 return TPM_DEVICE_INTERFACE_PTP_CRB
;
88 if ((InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO
) &&
89 (InterfaceId
.Bits
.InterfaceVersion
== PTP_INTERFACE_IDENTIFIER_INTERFACE_VERSION_FIFO
) &&
90 (InterfaceId
.Bits
.CapFIFO
!= 0) &&
91 (InterfaceCapability
.Bits
.InterfaceVersion
== INTERFACE_CAPABILITY_INTERFACE_VERSION_PTP
)) {
92 return TPM_DEVICE_INTERFACE_PTP_FIFO
;
94 return TPM_DEVICE_INTERFACE_TIS
;
98 Return if PTP CRB is supported.
100 @param[in] Register Pointer to PTP register.
102 @retval TRUE PTP CRB is supported.
103 @retval FALSE PTP CRB is unsupported.
110 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId
;
113 // Check interface id
115 InterfaceId
.Uint32
= MmioRead32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
);
117 if (((InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB
) ||
118 (InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO
)) &&
119 (InterfaceId
.Bits
.CapCRB
!= 0)) {
126 Return if PTP FIFO is supported.
128 @param[in] Register Pointer to PTP register.
130 @retval TRUE PTP FIFO is supported.
131 @retval FALSE PTP FIFO is unsupported.
138 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId
;
141 // Check interface id
143 InterfaceId
.Uint32
= MmioRead32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
);
145 if (((InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB
) ||
146 (InterfaceId
.Bits
.InterfaceType
== PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO
)) &&
147 (InterfaceId
.Bits
.CapFIFO
!= 0)) {
154 Set PTP interface type.
156 @param[in] Register Pointer to PTP register.
157 @param[in] PtpInterface PTP interface type.
159 @retval EFI_SUCCESS PTP interface type is set.
160 @retval EFI_INVALID_PARAMETER PTP interface type is invalid.
161 @retval EFI_UNSUPPORTED PTP interface type is unsupported.
162 @retval EFI_WRITE_PROTECTED PTP interface is locked.
167 IN UINT8 PtpInterface
170 UINT8 PtpInterfaceCurrent
;
171 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId
;
173 PtpInterfaceCurrent
= GetPtpInterface (Register
);
174 if ((PtpInterfaceCurrent
!= TPM_DEVICE_INTERFACE_PTP_FIFO
) &&
175 (PtpInterfaceCurrent
!= TPM_DEVICE_INTERFACE_PTP_CRB
)) {
176 return EFI_UNSUPPORTED
;
178 InterfaceId
.Uint32
= MmioRead32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
);
179 if (InterfaceId
.Bits
.IntfSelLock
!= 0) {
180 return EFI_WRITE_PROTECTED
;
183 switch (PtpInterface
) {
184 case TPM_DEVICE_INTERFACE_PTP_FIFO
:
185 if (InterfaceId
.Bits
.CapFIFO
== 0) {
186 return EFI_UNSUPPORTED
;
188 InterfaceId
.Bits
.InterfaceSelector
= PTP_INTERFACE_IDENTIFIER_INTERFACE_SELECTOR_FIFO
;
189 MmioWrite32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
, InterfaceId
.Uint32
);
191 case TPM_DEVICE_INTERFACE_PTP_CRB
:
192 if (InterfaceId
.Bits
.CapCRB
== 0) {
193 return EFI_UNSUPPORTED
;
195 InterfaceId
.Bits
.InterfaceSelector
= PTP_INTERFACE_IDENTIFIER_INTERFACE_SELECTOR_CRB
;
196 MmioWrite32 ((UINTN
)&((PTP_CRB_REGISTERS
*)Register
)->InterfaceId
, InterfaceId
.Uint32
);
199 return EFI_INVALID_PARAMETER
;
204 This function allows a caller to extract the current configuration for one
205 or more named elements from the target driver.
207 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
208 @param[in] Request A null-terminated Unicode string in
209 <ConfigRequest> format.
210 @param[out] Progress On return, points to a character in the Request
211 string. Points to the string's null terminator if
212 request was successful. Points to the most recent
213 '&' before the first failing name/value pair (or
214 the beginning of the string if the failure is in
215 the first name/value pair) if the request was not
217 @param[out] Results A null-terminated Unicode string in
218 <ConfigAltResp> format which has all values filled
219 in for the names in the Request string. String to
220 be allocated by the called function.
222 @retval EFI_SUCCESS The Results is filled with the requested values.
223 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
224 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
225 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
232 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
233 IN CONST EFI_STRING Request
,
234 OUT EFI_STRING
*Progress
,
235 OUT EFI_STRING
*Results
238 if (Progress
== NULL
|| Results
== NULL
) {
239 return EFI_INVALID_PARAMETER
;
243 return EFI_NOT_FOUND
;
247 Save TPM request to variable space.
249 @param[in] PpRequest Physical Presence request command.
251 @retval EFI_SUCCESS The operation is finished successfully.
252 @retval Others Other errors as indicated.
263 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (PpRequest
, 0);
264 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
265 mCurrentPpRequest
= PpRequest
;
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 TPM request to variable space.
281 @param[in] PpRequestParameter Physical Presence request parameter.
283 @retval EFI_SUCCESS The operation is finished successfully.
284 @retval Others Other errors as indicated.
288 SaveTcg2PpRequestParameter (
289 IN UINT32 PpRequestParameter
295 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (mCurrentPpRequest
, PpRequestParameter
);
296 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
297 Status
= EFI_SUCCESS
;
298 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
299 Status
= EFI_OUT_OF_RESOURCES
;
300 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
301 Status
= EFI_UNSUPPORTED
;
303 Status
= EFI_DEVICE_ERROR
;
310 Save Tcg2 PCR Banks request request to variable space.
312 @param[in] PCRBankIndex PCR Bank Index.
313 @param[in] Enable Enable or disable this PCR Bank.
315 @retval EFI_SUCCESS The operation is finished successfully.
316 @retval Others Other errors as indicated.
320 SaveTcg2PCRBanksRequest (
321 IN UINTN PCRBankIndex
,
329 mTcg2ConfigPrivateDate
->PCRBanksDesired
|= (0x1 << PCRBankIndex
);
331 mTcg2ConfigPrivateDate
->PCRBanksDesired
&= ~(0x1 << PCRBankIndex
);
334 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS
, mTcg2ConfigPrivateDate
->PCRBanksDesired
);
335 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
336 Status
= EFI_SUCCESS
;
337 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
338 Status
= EFI_OUT_OF_RESOURCES
;
339 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
340 Status
= EFI_UNSUPPORTED
;
342 Status
= EFI_DEVICE_ERROR
;
349 This function processes the results of changes in configuration.
351 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
352 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>
354 @param[out] Progress A pointer to a string filled in with the offset of
355 the most recent '&' before the first failing
356 name/value pair (or the beginning of the string if
357 the failure is in the first name/value pair) or
358 the terminating NULL if all was successful.
360 @retval EFI_SUCCESS The Results is processed successfully.
361 @retval EFI_INVALID_PARAMETER Configuration is NULL.
362 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
369 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
370 IN CONST EFI_STRING Configuration
,
371 OUT EFI_STRING
*Progress
374 if (Configuration
== NULL
|| Progress
== NULL
) {
375 return EFI_INVALID_PARAMETER
;
378 return EFI_NOT_FOUND
;
382 Get HID string of TPM2 ACPI device object
384 @param[in] Hid Points to HID String Buffer.
385 @param[in] Size HID String size in bytes. Must >= TPM_HID_ACPI_SIZE
387 @return HID String get status.
397 UINT32 ManufacturerID
;
398 UINT32 FirmwareVersion1
;
399 UINT32 FirmwareVersion2
;
407 // Get Manufacturer ID
409 Status
= Tpm2GetCapabilityManufactureID(&ManufacturerID
);
410 if (!EFI_ERROR(Status
)) {
411 DEBUG((DEBUG_INFO
, "TPM_PT_MANUFACTURER 0x%08x\n", ManufacturerID
));
413 // ManufacturerID defined in TCG Vendor ID Registry
414 // may tailed with 0x00 or 0x20
416 if ((ManufacturerID
>> 24) == 0x00 || ((ManufacturerID
>> 24) == 0x20)) {
418 // HID containing PNP ID "NNN####"
419 // NNN is uppercase letter for Vendor ID specified by manufacturer
421 CopyMem(Hid
, &ManufacturerID
, 3);
424 // HID containing ACP ID "NNNN####"
425 // NNNN is uppercase letter for Vendor ID specified by manufacturer
427 CopyMem(Hid
, &ManufacturerID
, 4);
431 DEBUG ((DEBUG_ERROR
, "Get TPM_PT_MANUFACTURER failed %x!\n", Status
));
436 Status
= Tpm2GetCapabilityFirmwareVersion(&FirmwareVersion1
, &FirmwareVersion2
);
437 if (!EFI_ERROR(Status
)) {
438 DEBUG((DEBUG_INFO
, "TPM_PT_FIRMWARE_VERSION_1 0x%x\n", FirmwareVersion1
));
439 DEBUG((DEBUG_INFO
, "TPM_PT_FIRMWARE_VERSION_2 0x%x\n", FirmwareVersion2
));
441 // #### is Firmware Version 1
444 AsciiSPrint(Hid
+ 3, TPM_HID_PNP_SIZE
- 3, "%02d%02d", ((FirmwareVersion1
& 0xFFFF0000) >> 16), (FirmwareVersion1
& 0x0000FFFF));
446 AsciiSPrint(Hid
+ 4, TPM_HID_ACPI_SIZE
- 4, "%02d%02d", ((FirmwareVersion1
& 0xFFFF0000) >> 16), (FirmwareVersion1
& 0x0000FFFF));
450 DEBUG ((DEBUG_ERROR
, "Get TPM_PT_FIRMWARE_VERSION_X failed %x!\n", Status
));
459 This function processes the results of changes in configuration
460 for TCG2 version information.
462 @param[in] Action Specifies the type of action taken by the browser.
463 ASSERT if the Action is not EFI_BROWSER_ACTION_SUBMITTED.
464 @param[in] QuestionId A unique value which is sent to the original
465 exporting driver so that it can identify the type
467 @param[in] Type The type of value for the question.
468 @param[in] Value A pointer to the data being sent to the original
471 @retval EFI_SUCCESS The callback successfully handled the action.
475 Tcg2VersionInfoCallback (
476 IN EFI_BROWSER_ACTION Action
,
477 IN EFI_QUESTION_ID QuestionId
,
479 IN EFI_IFR_TYPE_VALUE
*Value
483 UINT64 PcdTcg2PpiVersion
;
484 UINT8 PcdTpm2AcpiTableRev
;
486 ASSERT (Action
== EFI_BROWSER_ACTION_SUBMITTED
);
488 if (QuestionId
== KEY_TCG2_PPI_VERSION
) {
490 // Get the PCD value after EFI_BROWSER_ACTION_SUBMITTED,
491 // the SetVariable to TCG2_VERSION_NAME should have been done.
492 // If the PCD value is not equal to the value set to variable,
493 // the PCD is not DynamicHii type and does not map to the setup option.
495 PcdTcg2PpiVersion
= 0;
498 PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer
),
499 AsciiStrSize ((CHAR8
*) PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer
))
501 if (PcdTcg2PpiVersion
!= Value
->u64
) {
503 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
505 L
"WARNING: PcdTcgPhysicalPresenceInterfaceVer is not DynamicHii type and does not map to this option!",
506 L
"The version configuring by this setup option will not work!",
510 } else if (QuestionId
== KEY_TPM2_ACPI_REVISION
){
512 // Get the PCD value after EFI_BROWSER_ACTION_SUBMITTED,
513 // the SetVariable to TCG2_VERSION_NAME should have been done.
514 // If the PCD value is not equal to the value set to variable,
515 // the PCD is not DynamicHii type and does not map to the setup option.
517 PcdTpm2AcpiTableRev
= PcdGet8 (PcdTpm2AcpiTableRev
);
519 if (PcdTpm2AcpiTableRev
!= Value
->u8
) {
521 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
523 L
"WARNING: PcdTpm2AcpiTableRev is not DynamicHii type and does not map to this option!",
524 L
"The Revision configuring by this setup option will not work!",
534 This function processes the results of changes in configuration.
536 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
537 @param[in] Action Specifies the type of action taken by the browser.
538 @param[in] QuestionId A unique value which is sent to the original
539 exporting driver so that it can identify the type
541 @param[in] Type The type of value for the question.
542 @param[in] Value A pointer to the data being sent to the original
544 @param[out] ActionRequest On return, points to the action requested by the
547 @retval EFI_SUCCESS The callback successfully handled the action.
548 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
549 variable and its data.
550 @retval EFI_DEVICE_ERROR The variable could not be saved.
551 @retval EFI_UNSUPPORTED The specified Action is not supported by the
558 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
559 IN EFI_BROWSER_ACTION Action
,
560 IN EFI_QUESTION_ID QuestionId
,
562 IN EFI_IFR_TYPE_VALUE
*Value
,
563 OUT EFI_BROWSER_ACTION_REQUEST
*ActionRequest
570 TCG2_CONFIG_PRIVATE_DATA
*Private
;
572 if ((This
== NULL
) || (Value
== NULL
) || (ActionRequest
== NULL
)) {
573 return EFI_INVALID_PARAMETER
;
576 Private
= TCG2_CONFIG_PRIVATE_DATA_FROM_THIS (This
);
578 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
580 // Update TPM2 HID info
582 if (QuestionId
== KEY_TPM_DEVICE
) {
583 Status
= GetTpm2HID(HidStr
, 16);
585 if (EFI_ERROR(Status
)) {
587 // Fail to get TPM2 HID
589 HiiSetString (Private
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACPI_HID_CONTENT
), L
"Unknown", NULL
);
591 AsciiStrToUnicodeStrS(HidStr
, UnHidStr
, 16);
592 HiiSetString (Private
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACPI_HID_CONTENT
), UnHidStr
, NULL
);
598 if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
599 if (QuestionId
== KEY_TPM_DEVICE_INTERFACE
) {
600 Status
= SetPtpInterface ((VOID
*) (UINTN
) PcdGet64 (PcdTpmBaseAddress
), Value
->u8
);
601 if (EFI_ERROR (Status
)) {
603 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
605 L
"Error: Fail to set PTP interface!",
608 return EFI_DEVICE_ERROR
;
613 if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
614 if (QuestionId
== KEY_TPM_DEVICE
) {
617 if (QuestionId
== KEY_TPM2_OPERATION
) {
618 return SaveTcg2PpRequest (Value
->u8
);
620 if (QuestionId
== KEY_TPM2_OPERATION_PARAMETER
) {
621 return SaveTcg2PpRequestParameter (Value
->u32
);
623 if ((QuestionId
>= KEY_TPM2_PCR_BANKS_REQUEST_0
) && (QuestionId
<= KEY_TPM2_PCR_BANKS_REQUEST_4
)) {
624 return SaveTcg2PCRBanksRequest (QuestionId
- KEY_TPM2_PCR_BANKS_REQUEST_0
, Value
->b
);
628 if (Action
== EFI_BROWSER_ACTION_SUBMITTED
) {
629 if (QuestionId
== KEY_TCG2_PPI_VERSION
|| QuestionId
== KEY_TPM2_ACPI_REVISION
) {
630 return Tcg2VersionInfoCallback (Action
, QuestionId
, Type
, Value
);
634 return EFI_UNSUPPORTED
;
638 Append Buffer With TpmAlgHash.
640 @param[in] Buffer Buffer to be appended.
641 @param[in] BufferSize Size of buffer.
642 @param[in] TpmAlgHash TpmAlgHash.
646 AppendBufferWithTpmAlgHash (
652 switch (TpmAlgHash
) {
654 if (Buffer
[0] != 0) {
655 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
657 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA1");
660 if (Buffer
[0] != 0) {
661 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
663 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA256");
666 if (Buffer
[0] != 0) {
667 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
669 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA384");
672 if (Buffer
[0] != 0) {
673 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
675 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA512");
677 case TPM_ALG_SM3_256
:
678 if (Buffer
[0] != 0) {
679 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
681 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SM3_256");
687 Fill Buffer With BootHashAlg.
689 @param[in] Buffer Buffer to be filled.
690 @param[in] BufferSize Size of buffer.
691 @param[in] BootHashAlg BootHashAlg.
695 FillBufferWithBootHashAlg (
698 IN UINT32 BootHashAlg
702 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA1
) != 0) {
703 if (Buffer
[0] != 0) {
704 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
706 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA1");
708 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA256
) != 0) {
709 if (Buffer
[0] != 0) {
710 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
712 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA256");
714 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA384
) != 0) {
715 if (Buffer
[0] != 0) {
716 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
718 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA384");
720 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SHA512
) != 0) {
721 if (Buffer
[0] != 0) {
722 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
724 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SHA512");
726 if ((BootHashAlg
& EFI_TCG2_BOOT_HASH_ALG_SM3_256
) != 0) {
727 if (Buffer
[0] != 0) {
728 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
730 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"SM3_256");
735 Set ConfigInfo according to TpmAlgHash.
737 @param[in,out] Tcg2ConfigInfo TCG2 config info.
738 @param[in] TpmAlgHash TpmAlgHash.
743 IN OUT TCG2_CONFIGURATION_INFO
*Tcg2ConfigInfo
,
747 switch (TpmAlgHash
) {
749 Tcg2ConfigInfo
->Sha1Supported
= TRUE
;
752 Tcg2ConfigInfo
->Sha256Supported
= TRUE
;
755 Tcg2ConfigInfo
->Sha384Supported
= TRUE
;
758 Tcg2ConfigInfo
->Sha512Supported
= TRUE
;
760 case TPM_ALG_SM3_256
:
761 Tcg2ConfigInfo
->Sm3Supported
= TRUE
;
767 Fill Buffer With TCG2EventLogFormat.
769 @param[in] Buffer Buffer to be filled.
770 @param[in] BufferSize Size of buffer.
771 @param[in] TCG2EventLogFormat TCG2EventLogFormat.
775 FillBufferWithTCG2EventLogFormat (
778 IN UINT32 TCG2EventLogFormat
782 if ((TCG2EventLogFormat
& EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2
) != 0) {
783 if (Buffer
[0] != 0) {
784 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
786 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"TCG_1_2");
788 if ((TCG2EventLogFormat
& EFI_TCG2_EVENT_LOG_FORMAT_TCG_2
) != 0) {
789 if (Buffer
[0] != 0) {
790 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
792 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"TCG_2");
794 if ((TCG2EventLogFormat
& (~EFI_TCG2_EVENT_LOG_FORMAT_ALL
)) != 0) {
795 if (Buffer
[0] != 0) {
796 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
", ");
798 StrCatS (Buffer
, BufferSize
/ sizeof (CHAR16
), L
"UNKNOWN");
803 This function publish the TCG2 configuration Form for TPM device.
805 @param[in, out] PrivateData Points to TCG2 configuration private data.
807 @retval EFI_SUCCESS HII Form is installed for this network device.
808 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.
809 @retval Others Other errors as indicated.
813 InstallTcg2ConfigForm (
814 IN OUT TCG2_CONFIG_PRIVATE_DATA
*PrivateData
818 EFI_HII_HANDLE HiiHandle
;
819 EFI_HANDLE DriverHandle
;
820 EFI_HII_CONFIG_ACCESS_PROTOCOL
*ConfigAccess
;
822 TPML_PCR_SELECTION Pcrs
;
823 CHAR16 TempBuffer
[1024];
824 TCG2_CONFIGURATION_INFO Tcg2ConfigInfo
;
825 UINT8 TpmDeviceInterfaceDetected
;
828 ConfigAccess
= &PrivateData
->ConfigAccess
;
829 Status
= gBS
->InstallMultipleProtocolInterfaces (
831 &gEfiDevicePathProtocolGuid
,
832 &mTcg2HiiVendorDevicePath
,
833 &gEfiHiiConfigAccessProtocolGuid
,
837 if (EFI_ERROR (Status
)) {
841 PrivateData
->DriverHandle
= DriverHandle
;
844 // Publish the HII package list
846 HiiHandle
= HiiAddPackages (
847 &gTcg2ConfigFormSetGuid
,
849 Tcg2ConfigDxeStrings
,
853 if (HiiHandle
== NULL
) {
854 gBS
->UninstallMultipleProtocolInterfaces (
856 &gEfiDevicePathProtocolGuid
,
857 &mTcg2HiiVendorDevicePath
,
858 &gEfiHiiConfigAccessProtocolGuid
,
863 return EFI_OUT_OF_RESOURCES
;
866 PrivateData
->HiiHandle
= HiiHandle
;
869 // Update static data
871 switch (PrivateData
->TpmDeviceDetected
) {
872 case TPM_DEVICE_NULL
:
873 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"Not Found", NULL
);
876 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"TPM 1.2", NULL
);
878 case TPM_DEVICE_2_0_DTPM
:
879 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"TPM 2.0", NULL
);
882 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT
), L
"Unknown", NULL
);
886 ZeroMem (&Tcg2ConfigInfo
, sizeof(Tcg2ConfigInfo
));
887 Status
= Tpm2GetCapabilityPcrs (&Pcrs
);
888 if (EFI_ERROR (Status
)) {
889 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT
), L
"[Unknown]", NULL
);
890 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT
), L
"[Unknown]", NULL
);
893 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
894 if (!IsZeroBuffer (Pcrs
.pcrSelections
[Index
].pcrSelect
, Pcrs
.pcrSelections
[Index
].sizeofSelect
)) {
895 AppendBufferWithTpmAlgHash (TempBuffer
, sizeof(TempBuffer
), Pcrs
.pcrSelections
[Index
].hash
);
898 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
901 for (Index
= 0; Index
< Pcrs
.count
; Index
++) {
902 AppendBufferWithTpmAlgHash (TempBuffer
, sizeof(TempBuffer
), Pcrs
.pcrSelections
[Index
].hash
);
903 SetConfigInfo (&Tcg2ConfigInfo
, Pcrs
.pcrSelections
[Index
].hash
);
905 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
908 FillBufferWithBootHashAlg (TempBuffer
, sizeof(TempBuffer
), PcdGet32 (PcdTcg2HashAlgorithmBitmap
));
909 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_BIOS_HASH_ALGO_CONTENT
), TempBuffer
, NULL
);
914 FillBufferWithTCG2EventLogFormat (TempBuffer
, sizeof(TempBuffer
), PrivateData
->ProtocolCapability
.SupportedEventLogs
);
915 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_SUPPORTED_EVENT_LOG_FORMAT_CONTENT
), TempBuffer
, NULL
);
917 FillBufferWithBootHashAlg (TempBuffer
, sizeof(TempBuffer
), PrivateData
->ProtocolCapability
.HashAlgorithmBitmap
);
918 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_HASH_ALGO_BITMAP_CONTENT
), TempBuffer
, NULL
);
920 UnicodeSPrint (TempBuffer
, sizeof (TempBuffer
), L
"%d", PrivateData
->ProtocolCapability
.NumberOfPCRBanks
);
921 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_NUMBER_OF_PCR_BANKS_CONTENT
), TempBuffer
, NULL
);
923 FillBufferWithBootHashAlg (TempBuffer
, sizeof(TempBuffer
), PrivateData
->ProtocolCapability
.ActivePcrBanks
);
924 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_ACTIVE_PCR_BANKS_CONTENT
), TempBuffer
, NULL
);
927 // Update TPM device interface type
929 if (PrivateData
->TpmDeviceDetected
== TPM_DEVICE_2_0_DTPM
) {
930 TpmDeviceInterfaceDetected
= GetPtpInterface ((VOID
*) (UINTN
) PcdGet64 (PcdTpmBaseAddress
));
931 switch (TpmDeviceInterfaceDetected
) {
932 case TPM_DEVICE_INTERFACE_TIS
:
933 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"TIS", NULL
);
935 case TPM_DEVICE_INTERFACE_PTP_FIFO
:
936 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"PTP FIFO", NULL
);
938 case TPM_DEVICE_INTERFACE_PTP_CRB
:
939 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"PTP CRB", NULL
);
942 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT
), L
"Unknown", NULL
);
946 Tcg2ConfigInfo
.TpmDeviceInterfaceAttempt
= TpmDeviceInterfaceDetected
;
947 switch (TpmDeviceInterfaceDetected
) {
948 case TPM_DEVICE_INTERFACE_TIS
:
949 Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
= FALSE
;
950 Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
= FALSE
;
951 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT
), L
"TIS", NULL
);
953 case TPM_DEVICE_INTERFACE_PTP_FIFO
:
954 case TPM_DEVICE_INTERFACE_PTP_CRB
:
955 Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
= IsPtpFifoSupported((VOID
*) (UINTN
) PcdGet64 (PcdTpmBaseAddress
));
956 Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
= IsPtpCrbSupported((VOID
*) (UINTN
) PcdGet64 (PcdTpmBaseAddress
));
958 if (Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
) {
959 if (TempBuffer
[0] != 0) {
960 StrCatS (TempBuffer
, sizeof(TempBuffer
) / sizeof (CHAR16
), L
", ");
962 StrCatS (TempBuffer
, sizeof(TempBuffer
) / sizeof (CHAR16
), L
"PTP FIFO");
964 if (Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
) {
965 if (TempBuffer
[0] != 0) {
966 StrCatS (TempBuffer
, sizeof(TempBuffer
) / sizeof (CHAR16
), L
", ");
968 StrCatS (TempBuffer
, sizeof(TempBuffer
) / sizeof (CHAR16
), L
"PTP CRB");
970 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT
), TempBuffer
, NULL
);
973 Tcg2ConfigInfo
.TpmDeviceInterfacePtpFifoSupported
= FALSE
;
974 Tcg2ConfigInfo
.TpmDeviceInterfacePtpCrbSupported
= FALSE
;
975 HiiSetString (PrivateData
->HiiHandle
, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT
), L
"Unknown", NULL
);
981 // Set ConfigInfo, to control the check box.
983 Status
= gRT
->SetVariable (
984 TCG2_STORAGE_INFO_NAME
,
985 &gTcg2ConfigFormSetGuid
,
986 EFI_VARIABLE_BOOTSERVICE_ACCESS
,
987 sizeof(Tcg2ConfigInfo
),
990 if (EFI_ERROR (Status
)) {
991 DEBUG ((EFI_D_ERROR
, "Tcg2ConfigDriver: Fail to set TCG2_STORAGE_INFO_NAME\n"));
998 This function removes TCG2 configuration Form.
1000 @param[in, out] PrivateData Points to TCG2 configuration private data.
1004 UninstallTcg2ConfigForm (
1005 IN OUT TCG2_CONFIG_PRIVATE_DATA
*PrivateData
1009 // Uninstall HII package list
1011 if (PrivateData
->HiiHandle
!= NULL
) {
1012 HiiRemovePackages (PrivateData
->HiiHandle
);
1013 PrivateData
->HiiHandle
= NULL
;
1017 // Uninstall HII Config Access Protocol
1019 if (PrivateData
->DriverHandle
!= NULL
) {
1020 gBS
->UninstallMultipleProtocolInterfaces (
1021 PrivateData
->DriverHandle
,
1022 &gEfiDevicePathProtocolGuid
,
1023 &mTcg2HiiVendorDevicePath
,
1024 &gEfiHiiConfigAccessProtocolGuid
,
1025 &PrivateData
->ConfigAccess
,
1028 PrivateData
->DriverHandle
= NULL
;
1031 FreePool (PrivateData
);