#include <Library/DebugLib.h>\r
#include <Library/PeiServicesLib.h>\r
#include <Library/Tpm2DeviceLib.h>\r
+#include <Library/Tpm12DeviceLib.h>\r
+#include <Library/Tpm12CommandLib.h>\r
#include <Ppi/TpmInitialized.h>\r
\r
STATIC CONST EFI_PEI_PPI_DESCRIPTOR mTpmSelectedPpi = {\r
NULL\r
};\r
\r
+#pragma pack (1)\r
+\r
+typedef struct {\r
+ TPM_RSP_COMMAND_HDR Hdr;\r
+ TPM_CURRENT_TICKS CurrentTicks;\r
+} TPM_RSP_GET_TICKS;\r
+\r
+#pragma pack ()\r
+\r
+/**\r
+ Probe for the TPM for 1.2 version, by sending TPM1.2 GetTicks\r
+\r
+ Sending a TPM1.2 command to a TPM2 should return a TPM1.2\r
+ header (tag = 0xc4) and error code (TPM_BADTAG = 0x1e)\r
+**/\r
+static\r
+EFI_STATUS\r
+TestTpm12 (\r
+ )\r
+{\r
+ EFI_STATUS Status;\r
+ TPM_RQU_COMMAND_HDR Command;\r
+ TPM_RSP_GET_TICKS Response;\r
+ UINT32 Length;\r
+\r
+ Command.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);\r
+ Command.paramSize = SwapBytes32 (sizeof (Command));\r
+ Command.ordinal = SwapBytes32 (TPM_ORD_GetTicks);\r
+\r
+ Length = sizeof (Response);\r
+ Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);\r
+ if (EFI_ERROR (Status)) {\r
+ return Status;\r
+ }\r
+\r
+ return EFI_SUCCESS;\r
+}\r
+\r
/**\r
The entry point for Tcg2 configuration driver.\r
\r
\r
DEBUG ((DEBUG_INFO, "%a\n", __FUNCTION__));\r
\r
- Status = Tpm2RequestUseTpm ();\r
- if (!EFI_ERROR (Status)) {\r
- DEBUG ((DEBUG_INFO, "%a: TPM2 detected\n", __FUNCTION__));\r
- Size = sizeof (gEfiTpmDeviceInstanceTpm20DtpmGuid);\r
+ Status = Tpm12RequestUseTpm ();\r
+ if (!EFI_ERROR (Status) && !EFI_ERROR (TestTpm12 ())) {\r
+ DEBUG ((DEBUG_INFO, "%a: TPM1.2 detected\n", __FUNCTION__));\r
+ Size = sizeof (gEfiTpmDeviceInstanceTpm12Guid);\r
Status = PcdSetPtrS (\r
PcdTpmInstanceGuid,\r
&Size,\r
- &gEfiTpmDeviceInstanceTpm20DtpmGuid\r
+ &gEfiTpmDeviceInstanceTpm12Guid\r
);\r
ASSERT_EFI_ERROR (Status);\r
} else {\r
- DEBUG ((DEBUG_INFO, "%a: no TPM2 detected\n", __FUNCTION__));\r
- //\r
- // If no TPM2 was detected, we still need to install\r
- // TpmInitializationDonePpi. Namely, Tcg2Pei will exit early upon seeing\r
- // the default (all-bits-zero) contents of PcdTpmInstanceGuid, thus we have\r
- // to install the PPI in its place, in order to unblock any dependent\r
- // PEIMs.\r
- //\r
- Status = PeiServicesInstallPpi (&mTpmInitializationDonePpiList);\r
- ASSERT_EFI_ERROR (Status);\r
+ Status = Tpm2RequestUseTpm ();\r
+ if (!EFI_ERROR (Status)) {\r
+ DEBUG ((DEBUG_INFO, "%a: TPM2 detected\n", __FUNCTION__));\r
+ Size = sizeof (gEfiTpmDeviceInstanceTpm20DtpmGuid);\r
+ Status = PcdSetPtrS (\r
+ PcdTpmInstanceGuid,\r
+ &Size,\r
+ &gEfiTpmDeviceInstanceTpm20DtpmGuid\r
+ );\r
+ ASSERT_EFI_ERROR (Status);\r
+ } else {\r
+ DEBUG ((DEBUG_INFO, "%a: no TPM detected\n", __FUNCTION__));\r
+ //\r
+ // If no TPM2 was detected, we still need to install\r
+ // TpmInitializationDonePpi. Namely, Tcg2Pei will exit early upon seeing\r
+ // the default (all-bits-zero) contents of PcdTpmInstanceGuid, thus we have\r
+ // to install the PPI in its place, in order to unblock any dependent\r
+ // PEIMs.\r
+ //\r
+ Status = PeiServicesInstallPpi (&mTpmInitializationDonePpiList);\r
+ ASSERT_EFI_ERROR (Status);\r
+ }\r
}\r
\r
//\r