TianoCore EDK2 master
Loading...
Searching...
No Matches
Tcg2ConfigImpl.c
Go to the documentation of this file.
1
11#include "Tcg2ConfigImpl.h"
12#include <Library/PcdLib.h>
15#include <Library/IoLib.h>
16
17#include <Guid/TpmInstance.h>
18
20
21#define EFI_TCG2_EVENT_LOG_FORMAT_ALL (EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 | EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)
22
23TPM_INSTANCE_ID mTpmInstanceId[TPM_DEVICE_MAX + 1] = TPM_INSTANCE_ID_LIST;
24
25TCG2_CONFIG_PRIVATE_DATA *mTcg2ConfigPrivateDate;
26TCG2_CONFIG_PRIVATE_DATA mTcg2ConfigPrivateDateTemplate = {
27 TCG2_CONFIG_PRIVATE_DATA_SIGNATURE,
28 {
32 }
33};
34
35HII_VENDOR_DEVICE_PATH mTcg2HiiVendorDevicePath = {
36 {
37 {
40 {
41 (UINT8)(sizeof (VENDOR_DEVICE_PATH)),
42 (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)
43 }
44 },
45 TCG2_CONFIG_FORM_SET_GUID
46 },
47 {
48 END_DEVICE_PATH_TYPE,
49 END_ENTIRE_DEVICE_PATH_SUBTYPE,
50 {
51 (UINT8)(END_DEVICE_PATH_LENGTH),
52 (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)
53 }
54 }
55};
56
57UINT8 mCurrentPpRequest;
58
67BOOLEAN
69 IN VOID *Register
70 )
71{
73
74 //
75 // Check interface id
76 //
77 InterfaceId.Uint32 = MmioRead32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId);
78
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))
82 {
83 return TRUE;
84 }
85
86 return FALSE;
87}
88
97BOOLEAN
99 IN VOID *Register
100 )
101{
103
104 //
105 // Check interface id
106 //
107 InterfaceId.Uint32 = MmioRead32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId);
108
109 if (((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB) ||
110 (InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO)) &&
111 (InterfaceId.Bits.CapFIFO != 0))
112 {
113 return TRUE;
114 }
115
116 return FALSE;
117}
118
133 IN VOID *Register,
134 IN UINT8 PtpInterface
135 )
136{
137 TPM2_PTP_INTERFACE_TYPE PtpInterfaceCurrent;
139
140 PtpInterfaceCurrent = PcdGet8 (PcdActiveTpmInterfaceType);
141 if ((PtpInterfaceCurrent != Tpm2PtpInterfaceFifo) &&
142 (PtpInterfaceCurrent != Tpm2PtpInterfaceCrb))
143 {
144 return EFI_UNSUPPORTED;
145 }
146
147 InterfaceId.Uint32 = MmioRead32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId);
148 if (InterfaceId.Bits.IntfSelLock != 0) {
149 return EFI_WRITE_PROTECTED;
150 }
151
152 switch (PtpInterface) {
153 case Tpm2PtpInterfaceFifo:
154 if (InterfaceId.Bits.CapFIFO == 0) {
155 return EFI_UNSUPPORTED;
156 }
157
158 InterfaceId.Bits.InterfaceSelector = PTP_INTERFACE_IDENTIFIER_INTERFACE_SELECTOR_FIFO;
159 MmioWrite32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId, InterfaceId.Uint32);
160 return EFI_SUCCESS;
161 case Tpm2PtpInterfaceCrb:
162 if (InterfaceId.Bits.CapCRB == 0) {
163 return EFI_UNSUPPORTED;
164 }
165
166 InterfaceId.Bits.InterfaceSelector = PTP_INTERFACE_IDENTIFIER_INTERFACE_SELECTOR_CRB;
167 MmioWrite32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId, InterfaceId.Uint32);
168 return EFI_SUCCESS;
169 default:
170 return EFI_INVALID_PARAMETER;
171 }
172}
173
201EFIAPI
204 IN CONST EFI_STRING Request,
205 OUT EFI_STRING *Progress,
206 OUT EFI_STRING *Results
207 )
208{
209 if ((Progress == NULL) || (Results == NULL)) {
210 return EFI_INVALID_PARAMETER;
211 }
212
213 *Progress = Request;
214 return EFI_NOT_FOUND;
215}
216
228 IN UINT8 PpRequest
229 )
230{
231 UINT32 ReturnCode;
232 EFI_STATUS Status;
233
234 ReturnCode = Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (PpRequest, 0);
235 if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {
236 mCurrentPpRequest = PpRequest;
237 Status = EFI_SUCCESS;
238 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE) {
239 Status = EFI_OUT_OF_RESOURCES;
240 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED) {
241 Status = EFI_UNSUPPORTED;
242 } else {
243 Status = EFI_DEVICE_ERROR;
244 }
245
246 return Status;
247}
248
260 IN UINT32 PpRequestParameter
261 )
262{
263 UINT32 ReturnCode;
264 EFI_STATUS Status;
265
266 ReturnCode = Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (mCurrentPpRequest, PpRequestParameter);
267 if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {
268 Status = EFI_SUCCESS;
269 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE) {
270 Status = EFI_OUT_OF_RESOURCES;
271 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED) {
272 Status = EFI_UNSUPPORTED;
273 } else {
274 Status = EFI_DEVICE_ERROR;
275 }
276
277 return Status;
278}
279
292 IN UINTN PCRBankIndex,
293 IN BOOLEAN Enable
294 )
295{
296 UINT32 ReturnCode;
297 EFI_STATUS Status;
298
299 if (Enable) {
300 mTcg2ConfigPrivateDate->PCRBanksDesired |= (0x1 << PCRBankIndex);
301 } else {
302 mTcg2ConfigPrivateDate->PCRBanksDesired &= ~(0x1 << PCRBankIndex);
303 }
304
305 ReturnCode = Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS, mTcg2ConfigPrivateDate->PCRBanksDesired);
306 if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {
307 Status = EFI_SUCCESS;
308 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE) {
309 Status = EFI_OUT_OF_RESOURCES;
310 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED) {
311 Status = EFI_UNSUPPORTED;
312 } else {
313 Status = EFI_DEVICE_ERROR;
314 }
315
316 return Status;
317}
318
338EFIAPI
341 IN CONST EFI_STRING Configuration,
342 OUT EFI_STRING *Progress
343 )
344{
345 if ((Configuration == NULL) || (Progress == NULL)) {
346 return EFI_INVALID_PARAMETER;
347 }
348
349 *Progress = Configuration;
350
351 return EFI_NOT_FOUND;
352}
353
365 CHAR8 *Hid,
366 UINTN Size
367 )
368{
369 EFI_STATUS Status;
370 UINT32 ManufacturerID;
371 UINT32 FirmwareVersion1;
372 UINT32 FirmwareVersion2;
373 BOOLEAN PnpHID;
374
375 PnpHID = TRUE;
376
377 ZeroMem (Hid, Size);
378
379 //
380 // Get Manufacturer ID
381 //
382 Status = Tpm2GetCapabilityManufactureID (&ManufacturerID);
383 if (!EFI_ERROR (Status)) {
384 DEBUG ((DEBUG_INFO, "TPM_PT_MANUFACTURER 0x%08x\n", ManufacturerID));
385 //
386 // ManufacturerID defined in TCG Vendor ID Registry
387 // may tailed with 0x00 or 0x20
388 //
389 if (((ManufacturerID >> 24) == 0x00) || ((ManufacturerID >> 24) == 0x20)) {
390 //
391 // HID containing PNP ID "NNN####"
392 // NNN is uppercase letter for Vendor ID specified by manufacturer
393 //
394 CopyMem (Hid, &ManufacturerID, 3);
395 } else {
396 //
397 // HID containing ACP ID "NNNN####"
398 // NNNN is uppercase letter for Vendor ID specified by manufacturer
399 //
400 CopyMem (Hid, &ManufacturerID, 4);
401 PnpHID = FALSE;
402 }
403 } else {
404 DEBUG ((DEBUG_ERROR, "Get TPM_PT_MANUFACTURER failed %x!\n", Status));
405 ASSERT (FALSE);
406 return Status;
407 }
408
409 Status = Tpm2GetCapabilityFirmwareVersion (&FirmwareVersion1, &FirmwareVersion2);
410 if (!EFI_ERROR (Status)) {
411 DEBUG ((DEBUG_INFO, "TPM_PT_FIRMWARE_VERSION_1 0x%x\n", FirmwareVersion1));
412 DEBUG ((DEBUG_INFO, "TPM_PT_FIRMWARE_VERSION_2 0x%x\n", FirmwareVersion2));
413 //
414 // #### is Firmware Version 1
415 //
416 if (PnpHID) {
417 AsciiSPrint (Hid + 3, TPM_HID_PNP_SIZE - 3, "%02d%02d", ((FirmwareVersion1 & 0xFFFF0000) >> 16), (FirmwareVersion1 & 0x0000FFFF));
418 } else {
419 AsciiSPrint (Hid + 4, TPM_HID_ACPI_SIZE - 4, "%02d%02d", ((FirmwareVersion1 & 0xFFFF0000) >> 16), (FirmwareVersion1 & 0x0000FFFF));
420 }
421 } else {
422 DEBUG ((DEBUG_ERROR, "Get TPM_PT_FIRMWARE_VERSION_X failed %x!\n", Status));
423 ASSERT (FALSE);
424 return Status;
425 }
426
427 return EFI_SUCCESS;
428}
429
448 IN EFI_BROWSER_ACTION Action,
449 IN EFI_QUESTION_ID QuestionId,
450 IN UINT8 Type,
452 )
453{
454 EFI_INPUT_KEY Key;
455 UINT64 PcdTcg2PpiVersion;
456 UINT8 PcdTpm2AcpiTableRev;
457
458 ASSERT (Action == EFI_BROWSER_ACTION_SUBMITTED);
459
460 if (QuestionId == KEY_TCG2_PPI_VERSION) {
461 //
462 // Get the PCD value after EFI_BROWSER_ACTION_SUBMITTED,
463 // the SetVariable to TCG2_VERSION_NAME should have been done.
464 // If the PCD value is not equal to the value set to variable,
465 // the PCD is not DynamicHii type and does not map to the setup option.
466 //
467 PcdTcg2PpiVersion = 0;
468 CopyMem (
469 &PcdTcg2PpiVersion,
470 PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer),
471 AsciiStrSize ((CHAR8 *)PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer))
472 );
473 if (PcdTcg2PpiVersion != Value->u64) {
475 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
476 &Key,
477 L"WARNING: PcdTcgPhysicalPresenceInterfaceVer is not DynamicHii type and does not map to this option!",
478 L"The version configuring by this setup option will not work!",
479 NULL
480 );
481 }
482 } else if (QuestionId == KEY_TPM2_ACPI_REVISION) {
483 //
484 // Get the PCD value after EFI_BROWSER_ACTION_SUBMITTED,
485 // the SetVariable to TCG2_VERSION_NAME should have been done.
486 // If the PCD value is not equal to the value set to variable,
487 // the PCD is not DynamicHii type and does not map to the setup option.
488 //
489 PcdTpm2AcpiTableRev = PcdGet8 (PcdTpm2AcpiTableRev);
490
491 if (PcdTpm2AcpiTableRev != Value->u8) {
493 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
494 &Key,
495 L"WARNING: PcdTpm2AcpiTableRev is not DynamicHii type and does not map to this option!",
496 L"The Revision configuring by this setup option will not work!",
497 NULL
498 );
499 }
500 }
501
502 return EFI_SUCCESS;
503}
504
528EFIAPI
531 IN EFI_BROWSER_ACTION Action,
532 IN EFI_QUESTION_ID QuestionId,
533 IN UINT8 Type,
534 IN EFI_IFR_TYPE_VALUE *Value,
535 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest
536 )
537{
538 EFI_STATUS Status;
539 EFI_INPUT_KEY Key;
540 CHAR8 HidStr[16];
541 CHAR16 UnHidStr[16];
543
544 if ((This == NULL) || (Value == NULL) || (ActionRequest == NULL)) {
545 return EFI_INVALID_PARAMETER;
546 }
547
548 Private = TCG2_CONFIG_PRIVATE_DATA_FROM_THIS (This);
549
550 if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {
551 //
552 // Update TPM2 HID info
553 //
554 if (QuestionId == KEY_TPM_DEVICE) {
555 Status = GetTpm2HID (HidStr, 16);
556
557 if (EFI_ERROR (Status)) {
558 //
559 // Fail to get TPM2 HID
560 //
561 HiiSetString (Private->HiiHandle, STRING_TOKEN (STR_TPM2_ACPI_HID_CONTENT), L"Unknown", NULL);
562 } else {
563 AsciiStrToUnicodeStrS (HidStr, UnHidStr, 16);
564 HiiSetString (Private->HiiHandle, STRING_TOKEN (STR_TPM2_ACPI_HID_CONTENT), UnHidStr, NULL);
565 }
566 }
567
568 return EFI_SUCCESS;
569 }
570
571 if (Action == EFI_BROWSER_ACTION_CHANGING) {
572 if (QuestionId == KEY_TPM_DEVICE_INTERFACE) {
573 Status = SetPtpInterface ((VOID *)(UINTN)PcdGet64 (PcdTpmBaseAddress), Value->u8);
574 if (EFI_ERROR (Status)) {
576 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
577 &Key,
578 L"Error: Fail to set PTP interface!",
579 NULL
580 );
581 return EFI_DEVICE_ERROR;
582 }
583 }
584 }
585
586 if (Action == EFI_BROWSER_ACTION_CHANGED) {
587 if (QuestionId == KEY_TPM_DEVICE) {
588 return EFI_SUCCESS;
589 }
590
591 if (QuestionId == KEY_TPM2_OPERATION) {
592 return SaveTcg2PpRequest (Value->u8);
593 }
594
595 if (QuestionId == KEY_TPM2_OPERATION_PARAMETER) {
596 return SaveTcg2PpRequestParameter (Value->u32);
597 }
598
599 if ((QuestionId >= KEY_TPM2_PCR_BANKS_REQUEST_0) && (QuestionId <= KEY_TPM2_PCR_BANKS_REQUEST_4)) {
600 return SaveTcg2PCRBanksRequest (QuestionId - KEY_TPM2_PCR_BANKS_REQUEST_0, Value->b);
601 }
602 }
603
604 if (Action == EFI_BROWSER_ACTION_SUBMITTED) {
605 if ((QuestionId == KEY_TCG2_PPI_VERSION) || (QuestionId == KEY_TPM2_ACPI_REVISION)) {
606 return Tcg2VersionInfoCallback (Action, QuestionId, Type, Value);
607 }
608 }
609
610 return EFI_UNSUPPORTED;
611}
612
621VOID
623 IN UINT16 *Buffer,
624 IN UINTN BufferSize,
625 IN UINT32 TpmAlgHash
626 )
627{
628 switch (TpmAlgHash) {
629 case TPM_ALG_SHA1:
630 if (Buffer[0] != 0) {
631 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");
632 }
633
634 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA1");
635 break;
636 case TPM_ALG_SHA256:
637 if (Buffer[0] != 0) {
638 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");
639 }
640
641 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA256");
642 break;
643 case TPM_ALG_SHA384:
644 if (Buffer[0] != 0) {
645 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");
646 }
647
648 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA384");
649 break;
650 case TPM_ALG_SHA512:
651 if (Buffer[0] != 0) {
652 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");
653 }
654
655 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA512");
656 break;
657 case TPM_ALG_SM3_256:
658 if (Buffer[0] != 0) {
659 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");
660 }
661
662 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SM3_256");
663 break;
664 }
665}
666
675VOID
677 IN UINT16 *Buffer,
678 IN UINTN BufferSize,
679 IN UINT32 BootHashAlg
680 )
681{
682 Buffer[0] = 0;
683 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SHA1) != 0) {
684 if (Buffer[0] != 0) {
685 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");
686 }
687
688 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA1");
689 }
690
691 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SHA256) != 0) {
692 if (Buffer[0] != 0) {
693 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");
694 }
695
696 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA256");
697 }
698
699 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SHA384) != 0) {
700 if (Buffer[0] != 0) {
701 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");
702 }
703
704 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA384");
705 }
706
707 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SHA512) != 0) {
708 if (Buffer[0] != 0) {
709 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");
710 }
711
712 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA512");
713 }
714
715 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SM3_256) != 0) {
716 if (Buffer[0] != 0) {
717 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");
718 }
719
720 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SM3_256");
721 }
722}
723
732VOID
734 IN OUT TCG2_CONFIGURATION_INFO *Tcg2ConfigInfo,
735 IN UINT32 TpmAlgHash,
736 IN UINT32 Tcg2HashAlgBitmap
737 )
738{
739 switch (TpmAlgHash) {
740 case TPM_ALG_SHA1:
741 if ((Tcg2HashAlgBitmap & HASH_ALG_SHA1) != 0) {
742 Tcg2ConfigInfo->Sha1Supported = TRUE;
743 }
744
745 break;
746 case TPM_ALG_SHA256:
747 if ((Tcg2HashAlgBitmap & HASH_ALG_SHA256) != 0) {
748 Tcg2ConfigInfo->Sha256Supported = TRUE;
749 }
750
751 break;
752 case TPM_ALG_SHA384:
753 if ((Tcg2HashAlgBitmap & HASH_ALG_SHA384) != 0) {
754 Tcg2ConfigInfo->Sha384Supported = TRUE;
755 }
756
757 break;
758 case TPM_ALG_SHA512:
759 if ((Tcg2HashAlgBitmap & HASH_ALG_SHA512) != 0) {
760 Tcg2ConfigInfo->Sha512Supported = TRUE;
761 }
762
763 break;
764 case TPM_ALG_SM3_256:
765 if ((Tcg2HashAlgBitmap & HASH_ALG_SM3_256) != 0) {
766 Tcg2ConfigInfo->Sm3Supported = TRUE;
767 }
768
769 break;
770 }
771}
772
781VOID
783 IN UINT16 *Buffer,
784 IN UINTN BufferSize,
785 IN UINT32 TCG2EventLogFormat
786 )
787{
788 Buffer[0] = 0;
789 if ((TCG2EventLogFormat & EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2) != 0) {
790 if (Buffer[0] != 0) {
791 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");
792 }
793
794 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"TCG_1_2");
795 }
796
797 if ((TCG2EventLogFormat & EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) != 0) {
798 if (Buffer[0] != 0) {
799 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");
800 }
801
802 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"TCG_2");
803 }
804
805 if ((TCG2EventLogFormat & (~EFI_TCG2_EVENT_LOG_FORMAT_ALL)) != 0) {
806 if (Buffer[0] != 0) {
807 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");
808 }
809
810 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"UNKNOWN");
811 }
812}
813
826 IN OUT TCG2_CONFIG_PRIVATE_DATA *PrivateData
827 )
828{
829 EFI_STATUS Status;
830 EFI_HII_HANDLE HiiHandle;
831 EFI_HANDLE DriverHandle;
832 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;
833 UINTN Index;
835 CHAR16 TempBuffer[1024];
836 TCG2_CONFIGURATION_INFO Tcg2ConfigInfo;
837 TPM2_PTP_INTERFACE_TYPE TpmDeviceInterfaceDetected;
838 BOOLEAN IsCmdImp;
839 EFI_TCG2_EVENT_ALGORITHM_BITMAP Tcg2HashAlgorithmBitmap;
840
841 DriverHandle = NULL;
842 ConfigAccess = &PrivateData->ConfigAccess;
843 Status = gBS->InstallMultipleProtocolInterfaces (
844 &DriverHandle,
845 &gEfiDevicePathProtocolGuid,
846 &mTcg2HiiVendorDevicePath,
847 &gEfiHiiConfigAccessProtocolGuid,
848 ConfigAccess,
849 NULL
850 );
851 if (EFI_ERROR (Status)) {
852 return Status;
853 }
854
855 PrivateData->DriverHandle = DriverHandle;
856
857 //
858 // Publish the HII package list
859 //
860 HiiHandle = HiiAddPackages (
861 &gTcg2ConfigFormSetGuid,
862 DriverHandle,
863 Tcg2ConfigDxeStrings,
864 Tcg2ConfigBin,
865 NULL
866 );
867 if (HiiHandle == NULL) {
868 gBS->UninstallMultipleProtocolInterfaces (
869 DriverHandle,
870 &gEfiDevicePathProtocolGuid,
871 &mTcg2HiiVendorDevicePath,
872 &gEfiHiiConfigAccessProtocolGuid,
873 ConfigAccess,
874 NULL
875 );
876
877 return EFI_OUT_OF_RESOURCES;
878 }
879
880 PrivateData->HiiHandle = HiiHandle;
881
882 //
883 // Update static data
884 //
885 switch (PrivateData->TpmDeviceDetected) {
886 case TPM_DEVICE_NULL:
887 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT), L"Not Found", NULL);
888 break;
889 case TPM_DEVICE_1_2:
890 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT), L"TPM 1.2", NULL);
891 break;
892 case TPM_DEVICE_2_0_DTPM:
893 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT), L"TPM 2.0", NULL);
894 break;
895 default:
896 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT), L"Unknown", NULL);
897 break;
898 }
899
900 Tcg2HashAlgorithmBitmap = PcdGet32 (PcdTcg2HashAlgorithmBitmap);
901
902 ZeroMem (&Tcg2ConfigInfo, sizeof (Tcg2ConfigInfo));
903 Status = Tpm2GetCapabilityPcrs (&Pcrs);
904 if (EFI_ERROR (Status)) {
905 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT), L"[Unknown]", NULL);
906 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT), L"[Unknown]", NULL);
907 } else {
908 TempBuffer[0] = 0;
909 for (Index = 0; Index < Pcrs.count; Index++) {
910 if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {
911 AppendBufferWithTpmAlgHash (TempBuffer, sizeof (TempBuffer), Pcrs.pcrSelections[Index].hash);
912 }
913 }
914
915 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT), TempBuffer, NULL);
916
917 TempBuffer[0] = 0;
918 for (Index = 0; Index < Pcrs.count; Index++) {
919 AppendBufferWithTpmAlgHash (TempBuffer, sizeof (TempBuffer), Pcrs.pcrSelections[Index].hash);
920 SetConfigInfo (&Tcg2ConfigInfo, Pcrs.pcrSelections[Index].hash, Tcg2HashAlgorithmBitmap);
921 }
922
923 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT), TempBuffer, NULL);
924 }
925
926 IsCmdImp = FALSE;
927 Status = Tpm2GetCapabilityIsCommandImplemented (TPM_CC_ChangeEPS, &IsCmdImp);
928 if (EFI_ERROR (Status)) {
929 DEBUG ((DEBUG_ERROR, "Tpm2GetCapabilityIsCmdImpl fails %r\n", Status));
930 }
931
932 Tcg2ConfigInfo.ChangeEPSSupported = IsCmdImp;
933
934 FillBufferWithBootHashAlg (TempBuffer, sizeof (TempBuffer), Tcg2HashAlgorithmBitmap);
935 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_BIOS_HASH_ALGO_CONTENT), TempBuffer, NULL);
936
937 //
938 // Tcg2 Capability
939 //
940 FillBufferWithTCG2EventLogFormat (TempBuffer, sizeof (TempBuffer), PrivateData->ProtocolCapability.SupportedEventLogs);
941 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_SUPPORTED_EVENT_LOG_FORMAT_CONTENT), TempBuffer, NULL);
942
943 FillBufferWithBootHashAlg (TempBuffer, sizeof (TempBuffer), PrivateData->ProtocolCapability.HashAlgorithmBitmap);
944 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_HASH_ALGO_BITMAP_CONTENT), TempBuffer, NULL);
945
946 UnicodeSPrint (TempBuffer, sizeof (TempBuffer), L"%d", PrivateData->ProtocolCapability.NumberOfPCRBanks);
947 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_NUMBER_OF_PCR_BANKS_CONTENT), TempBuffer, NULL);
948
949 FillBufferWithBootHashAlg (TempBuffer, sizeof (TempBuffer), PrivateData->ProtocolCapability.ActivePcrBanks);
950 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_ACTIVE_PCR_BANKS_CONTENT), TempBuffer, NULL);
951
952 //
953 // Update TPM device interface type
954 //
955 if (PrivateData->TpmDeviceDetected == TPM_DEVICE_2_0_DTPM) {
956 TpmDeviceInterfaceDetected = PcdGet8 (PcdActiveTpmInterfaceType);
957 switch (TpmDeviceInterfaceDetected) {
958 case Tpm2PtpInterfaceTis:
959 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT), L"TIS", NULL);
960 break;
961 case Tpm2PtpInterfaceFifo:
962 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT), L"PTP FIFO", NULL);
963 break;
964 case Tpm2PtpInterfaceCrb:
965 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT), L"PTP CRB", NULL);
966 break;
967 default:
968 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT), L"Unknown", NULL);
969 break;
970 }
971
972 Tcg2ConfigInfo.TpmDeviceInterfaceAttempt = TpmDeviceInterfaceDetected;
973 switch (TpmDeviceInterfaceDetected) {
974 case Tpm2PtpInterfaceTis:
975 Tcg2ConfigInfo.TpmDeviceInterfacePtpFifoSupported = FALSE;
976 Tcg2ConfigInfo.TpmDeviceInterfacePtpCrbSupported = FALSE;
977 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT), L"TIS", NULL);
978 break;
979 case Tpm2PtpInterfaceFifo:
980 case Tpm2PtpInterfaceCrb:
981 Tcg2ConfigInfo.TpmDeviceInterfacePtpFifoSupported = IsPtpFifoSupported ((VOID *)(UINTN)PcdGet64 (PcdTpmBaseAddress));
982 Tcg2ConfigInfo.TpmDeviceInterfacePtpCrbSupported = IsPtpCrbSupported ((VOID *)(UINTN)PcdGet64 (PcdTpmBaseAddress));
983 TempBuffer[0] = 0;
984 if (Tcg2ConfigInfo.TpmDeviceInterfacePtpFifoSupported) {
985 if (TempBuffer[0] != 0) {
986 StrCatS (TempBuffer, sizeof (TempBuffer) / sizeof (CHAR16), L", ");
987 }
988
989 StrCatS (TempBuffer, sizeof (TempBuffer) / sizeof (CHAR16), L"PTP FIFO");
990 }
991
992 if (Tcg2ConfigInfo.TpmDeviceInterfacePtpCrbSupported) {
993 if (TempBuffer[0] != 0) {
994 StrCatS (TempBuffer, sizeof (TempBuffer) / sizeof (CHAR16), L", ");
995 }
996
997 StrCatS (TempBuffer, sizeof (TempBuffer) / sizeof (CHAR16), L"PTP CRB");
998 }
999
1000 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT), TempBuffer, NULL);
1001 break;
1002 default:
1003 Tcg2ConfigInfo.TpmDeviceInterfacePtpFifoSupported = FALSE;
1004 Tcg2ConfigInfo.TpmDeviceInterfacePtpCrbSupported = FALSE;
1005 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT), L"Unknown", NULL);
1006 break;
1007 }
1008 }
1009
1010 //
1011 // Set ConfigInfo, to control the check box.
1012 //
1013 Status = gRT->SetVariable (
1014 TCG2_STORAGE_INFO_NAME,
1015 &gTcg2ConfigFormSetGuid,
1016 EFI_VARIABLE_BOOTSERVICE_ACCESS,
1017 sizeof (Tcg2ConfigInfo),
1018 &Tcg2ConfigInfo
1019 );
1020 if (EFI_ERROR (Status)) {
1021 DEBUG ((DEBUG_ERROR, "Tcg2ConfigDriver: Fail to set TCG2_STORAGE_INFO_NAME\n"));
1022 }
1023
1024 return EFI_SUCCESS;
1025}
1026
1033VOID
1035 IN OUT TCG2_CONFIG_PRIVATE_DATA *PrivateData
1036 )
1037{
1038 //
1039 // Uninstall HII package list
1040 //
1041 if (PrivateData->HiiHandle != NULL) {
1042 HiiRemovePackages (PrivateData->HiiHandle);
1043 PrivateData->HiiHandle = NULL;
1044 }
1045
1046 //
1047 // Uninstall HII Config Access Protocol
1048 //
1049 if (PrivateData->DriverHandle != NULL) {
1050 gBS->UninstallMultipleProtocolInterfaces (
1051 PrivateData->DriverHandle,
1052 &gEfiDevicePathProtocolGuid,
1053 &mTcg2HiiVendorDevicePath,
1054 &gEfiHiiConfigAccessProtocolGuid,
1055 &PrivateData->ConfigAccess,
1056 NULL
1057 );
1058 PrivateData->DriverHandle = NULL;
1059 }
1060
1061 FreePool (PrivateData);
1062}
UINT64 UINTN
RETURN_STATUS EFIAPI StrCatS(IN OUT CHAR16 *Destination, IN UINTN DestMax, IN CONST CHAR16 *Source)
Definition: SafeString.c:405
RETURN_STATUS EFIAPI AsciiStrToUnicodeStrS(IN CONST CHAR8 *Source, OUT CHAR16 *Destination, IN UINTN DestMax)
Definition: SafeString.c:2873
UINTN EFIAPI AsciiStrSize(IN CONST CHAR8 *String)
Definition: String.c:681
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
BOOLEAN EFIAPI IsZeroBuffer(IN CONST VOID *Buffer, IN UINTN Length)
#define HARDWARE_DEVICE_PATH
Definition: DevicePath.h:68
#define HW_VENDOR_DP
Definition: DevicePath.h:133
VOID EFIAPI FreePool(IN VOID *Buffer)
EFI_HII_HANDLE EFIAPI HiiAddPackages(IN CONST EFI_GUID *PackageListGuid, IN EFI_HANDLE DeviceHandle OPTIONAL,...)
Definition: HiiLib.c:141
EFI_STRING_ID EFIAPI HiiSetString(IN EFI_HII_HANDLE HiiHandle, IN EFI_STRING_ID StringId OPTIONAL, IN CONST EFI_STRING String, IN CONST CHAR8 *SupportedLanguages OPTIONAL)
Definition: HiiString.c:52
VOID EFIAPI HiiRemovePackages(IN EFI_HII_HANDLE HiiHandle)
Definition: HiiLib.c:253
UINT32 EFIAPI MmioRead32(IN UINTN Address)
Definition: IoLib.c:262
UINT32 EFIAPI MmioWrite32(IN UINTN Address, IN UINT32 Value)
Definition: IoLib.c:309
UINTN EFIAPI UnicodeSPrint(OUT CHAR16 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR16 *FormatString,...)
Definition: PrintLib.c:408
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
Definition: PrintLib.c:813
EFI_RUNTIME_SERVICES * gRT
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define DEBUG(Expression)
Definition: DebugLib.h:434
UINT32 EFIAPI Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction(IN UINT32 OperationRequest, IN UINT32 RequestParameter)
#define PcdGet64(TokenName)
Definition: PcdLib.h:375
#define PcdGet8(TokenName)
Definition: PcdLib.h:336
#define PcdGet32(TokenName)
Definition: PcdLib.h:362
#define PcdGetPtr(TokenName)
Definition: PcdLib.h:388
EFI_STATUS EFIAPI Register(IN EFI_PEI_RSC_HANDLER_CALLBACK Callback)
VOID UninstallTcg2ConfigForm(IN OUT TCG2_CONFIG_PRIVATE_DATA *PrivateData)
EFI_STATUS Tcg2VersionInfoCallback(IN EFI_BROWSER_ACTION Action, IN EFI_QUESTION_ID QuestionId, IN UINT8 Type, IN EFI_IFR_TYPE_VALUE *Value)
EFI_STATUS SaveTcg2PCRBanksRequest(IN UINTN PCRBankIndex, IN BOOLEAN Enable)
VOID FillBufferWithTCG2EventLogFormat(IN UINT16 *Buffer, IN UINTN BufferSize, IN UINT32 TCG2EventLogFormat)
BOOLEAN IsPtpFifoSupported(IN VOID *Register)
EFI_STATUS SaveTcg2PpRequest(IN UINT8 PpRequest)
EFI_STATUS GetTpm2HID(CHAR8 *Hid, UINTN Size)
VOID AppendBufferWithTpmAlgHash(IN UINT16 *Buffer, IN UINTN BufferSize, IN UINT32 TpmAlgHash)
EFI_STATUS InstallTcg2ConfigForm(IN OUT TCG2_CONFIG_PRIVATE_DATA *PrivateData)
VOID SetConfigInfo(IN OUT TCG2_CONFIGURATION_INFO *Tcg2ConfigInfo, IN UINT32 TpmAlgHash, IN UINT32 Tcg2HashAlgBitmap)
EFI_STATUS EFIAPI Tcg2ExtractConfig(IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, IN CONST EFI_STRING Request, OUT EFI_STRING *Progress, OUT EFI_STRING *Results)
VOID FillBufferWithBootHashAlg(IN UINT16 *Buffer, IN UINTN BufferSize, IN UINT32 BootHashAlg)
BOOLEAN IsPtpCrbSupported(IN VOID *Register)
EFI_STATUS EFIAPI Tcg2Callback(IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, IN EFI_BROWSER_ACTION Action, IN EFI_QUESTION_ID QuestionId, IN UINT8 Type, IN EFI_IFR_TYPE_VALUE *Value, OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest)
EFI_STATUS EFIAPI Tcg2RouteConfig(IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This, IN CONST EFI_STRING Configuration, OUT EFI_STRING *Progress)
EFI_STATUS SaveTcg2PpRequestParameter(IN UINT32 PpRequestParameter)
EFI_STATUS SetPtpInterface(IN VOID *Register, IN UINT8 PtpInterface)
EFI_STATUS EFIAPI Tpm2GetCapabilityIsCommandImplemented(IN TPM_CC Command, OUT BOOLEAN *IsCmdImpl)
EFI_STATUS EFIAPI Tpm2GetCapabilityFirmwareVersion(OUT UINT32 *FirmwareVersion1, OUT UINT32 *FirmwareVersion2)
EFI_STATUS EFIAPI Tpm2GetCapabilityManufactureID(OUT UINT32 *ManufactureId)
EFI_STATUS EFIAPI Tpm2GetCapabilityPcrs(OUT TPML_PCR_SELECTION *Pcrs)
#define PTP_INTERFACE_IDENTIFIER_INTERFACE_SELECTOR_FIFO
Definition: TpmPtp.h:363
#define PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO
Definition: TpmPtp.h:350
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_BOOT_SERVICES * gBS
#define STRING_TOKEN(t)
VOID * EFI_HII_HANDLE
VOID EFIAPI CreatePopUp(IN UINTN Attribute, OUT EFI_INPUT_KEY *Key OPTIONAL,...)
Definition: Console.c:393