-/** @file\r
- This library is TPM2 TREE protocol lib.\r
-\r
-Copyright (c) 2013 - 2016, 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/TrEEProtocol.h>\r
-#include <IndustryStandard/Tpm20.h>\r
-\r
-EFI_TREE_PROTOCOL *mTreeProtocol = 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 (mTreeProtocol == NULL) {\r
- Status = gBS->LocateProtocol (&gEfiTrEEProtocolGuid, NULL, (VOID **) &mTreeProtocol);\r
- if (EFI_ERROR (Status)) {\r
- //\r
- // TrEE protocol is not installed. So, TPM2 is not present.\r
- //\r
- DEBUG ((EFI_D_ERROR, "Tpm2SubmitCommand - TrEE - %r\n", Status));\r
- return EFI_NOT_FOUND;\r
- }\r
- }\r
- //\r
- // Assume when TrEE Protocol is ready, RequestUseTpm already done.\r
- //\r
- Status = mTreeProtocol->SubmitCommand (\r
- mTreeProtocol,\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 (mTreeProtocol == NULL) {\r
- Status = gBS->LocateProtocol (&gEfiTrEEProtocolGuid, NULL, (VOID **) &mTreeProtocol);\r
- if (EFI_ERROR (Status)) {\r
- //\r
- // TrEE protocol is not installed. So, TPM2 is not present.\r
- //\r
- DEBUG ((EFI_D_ERROR, "Tpm2RequestUseTpm - TrEE - %r\n", Status));\r
- return EFI_NOT_FOUND;\r
- }\r
- }\r
- //\r
- // Assume when TrEE 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