]> git.proxmox.com Git - mirror_edk2.git/blobdiff - SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.c
Add TPM2 support defined in trusted computing group.
[mirror_edk2.git] / SecurityPkg / Library / Tpm2DeviceLibTcg2 / Tpm2DeviceLibTcg2.c
diff --git a/SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.c b/SecurityPkg/Library/Tpm2DeviceLibTcg2/Tpm2DeviceLibTcg2.c
new file mode 100644 (file)
index 0000000..e1a92c3
--- /dev/null
@@ -0,0 +1,125 @@
+/** @file\r
+  Ihis library is TPM2 TCG2 protocol lib.\r
+\r
+Copyright (c) 2013, Intel Corporation. All rights reserved. <BR>\r
+This program and the accompanying materials\r
+are licensed and made available under the terms and conditions of the BSD License\r
+which accompanies this distribution.  The full text of the license may be found at\r
+http://opensource.org/licenses/bsd-license.php\r
+\r
+THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
+WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+\r
+**/\r
+\r
+#include <Library/BaseLib.h>\r
+#include <Library/BaseMemoryLib.h>\r
+#include <Library/DebugLib.h>\r
+#include <Library/UefiBootServicesTableLib.h>\r
+#include <Library/Tpm2DeviceLib.h>\r
+#include <Protocol/Tcg2Protocol.h>\r
+#include <IndustryStandard/Tpm20.h>\r
+\r
+EFI_TCG2_PROTOCOL  *mTcg2Protocol = NULL; \r
+\r
+/**\r
+  This service enables the sending of commands to the TPM2.\r
+\r
+  @param[in]      InputParameterBlockSize  Size of the TPM2 input parameter block.\r
+  @param[in]      InputParameterBlock      Pointer to the TPM2 input parameter block.\r
+  @param[in,out]  OutputParameterBlockSize Size of the TPM2 output parameter block.\r
+  @param[in]      OutputParameterBlock     Pointer to the TPM2 output parameter block.\r
+\r
+  @retval EFI_SUCCESS            The command byte stream was successfully sent to the device and a response was successfully received.\r
+  @retval EFI_DEVICE_ERROR       The command was not successfully sent to the device or a response was not successfully received from the device.\r
+  @retval EFI_BUFFER_TOO_SMALL   The output parameter block is too small. \r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Tpm2SubmitCommand (\r
+  IN UINT32            InputParameterBlockSize,\r
+  IN UINT8             *InputParameterBlock,\r
+  IN OUT UINT32        *OutputParameterBlockSize,\r
+  IN UINT8             *OutputParameterBlock\r
+  )\r
+{\r
+  EFI_STATUS                Status;\r
+  TPM2_RESPONSE_HEADER      *Header;\r
+\r
+  if (mTcg2Protocol == NULL) {\r
+    Status = gBS->LocateProtocol (&gEfiTcg2ProtocolGuid, NULL, (VOID **) &mTcg2Protocol);\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Tcg2 protocol is not installed. So, TPM2 is not present.\r
+      //\r
+      DEBUG ((EFI_D_ERROR, "Tpm2SubmitCommand - Tcg2 - %r\n", Status));\r
+      return EFI_NOT_FOUND;\r
+    }\r
+  }\r
+  //\r
+  // Assume when Tcg2 Protocol is ready, RequestUseTpm already done.\r
+  //\r
+  Status = mTcg2Protocol->SubmitCommand (\r
+                            mTcg2Protocol,\r
+                            InputParameterBlockSize,\r
+                            InputParameterBlock,\r
+                            *OutputParameterBlockSize,\r
+                            OutputParameterBlock\r
+                            );\r
+  if (EFI_ERROR (Status)) {\r
+    return Status;\r
+  }\r
+  Header = (TPM2_RESPONSE_HEADER *)OutputParameterBlock;\r
+  *OutputParameterBlockSize = SwapBytes32 (Header->paramSize);\r
+\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This service requests use TPM2.\r
+\r
+  @retval EFI_SUCCESS      Get the control of TPM2 chip.\r
+  @retval EFI_NOT_FOUND    TPM2 not found.\r
+  @retval EFI_DEVICE_ERROR Unexpected device behavior.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Tpm2RequestUseTpm (\r
+  VOID\r
+  )\r
+{\r
+  EFI_STATUS   Status;\r
+\r
+  if (mTcg2Protocol == NULL) {\r
+    Status = gBS->LocateProtocol (&gEfiTcg2ProtocolGuid, NULL, (VOID **) &mTcg2Protocol);\r
+    if (EFI_ERROR (Status)) {\r
+      //\r
+      // Tcg2 protocol is not installed. So, TPM2 is not present.\r
+      //\r
+      DEBUG ((EFI_D_ERROR, "Tpm2RequestUseTpm - Tcg2 - %r\n", Status));\r
+      return EFI_NOT_FOUND;\r
+    }\r
+  }\r
+  //\r
+  // Assume when Tcg2 Protocol is ready, RequestUseTpm already done.\r
+  //\r
+  return EFI_SUCCESS;\r
+}\r
+\r
+/**\r
+  This service register TPM2 device.\r
+\r
+  @param Tpm2Device  TPM2 device\r
+\r
+  @retval EFI_SUCCESS          This TPM2 device is registered successfully.\r
+  @retval EFI_UNSUPPORTED      System does not support register this TPM2 device.\r
+  @retval EFI_ALREADY_STARTED  System already register this TPM2 device.\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+Tpm2RegisterTpm2DeviceLib (\r
+  IN TPM2_DEVICE_INTERFACE   *Tpm2Device\r
+  )\r
+{\r
+  return EFI_UNSUPPORTED;\r
+}\r