Tpm12DeviceLibTcg.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /** @file
  2. This library is TPM12 TCG protocol lib.
  3. Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <Uefi.h>
  7. #include <Library/BaseLib.h>
  8. #include <Library/BaseMemoryLib.h>
  9. #include <Library/DebugLib.h>
  10. #include <Library/UefiBootServicesTableLib.h>
  11. #include <Library/Tpm12DeviceLib.h>
  12. #include <Protocol/TcgService.h>
  13. #include <IndustryStandard/Tpm12.h>
  14. EFI_TCG_PROTOCOL *mTcgProtocol = NULL;
  15. /**
  16. This service enables the sending of commands to the TPM12.
  17. @param[in] InputParameterBlockSize Size of the TPM12 input parameter block.
  18. @param[in] InputParameterBlock Pointer to the TPM12 input parameter block.
  19. @param[in,out] OutputParameterBlockSize Size of the TPM12 output parameter block.
  20. @param[in] OutputParameterBlock Pointer to the TPM12 output parameter block.
  21. @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
  22. @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
  23. @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
  24. **/
  25. EFI_STATUS
  26. EFIAPI
  27. Tpm12SubmitCommand (
  28. IN UINT32 InputParameterBlockSize,
  29. IN UINT8 *InputParameterBlock,
  30. IN OUT UINT32 *OutputParameterBlockSize,
  31. IN UINT8 *OutputParameterBlock
  32. )
  33. {
  34. EFI_STATUS Status;
  35. TPM_RSP_COMMAND_HDR *Header;
  36. if (mTcgProtocol == NULL) {
  37. Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **)&mTcgProtocol);
  38. if (EFI_ERROR (Status)) {
  39. //
  40. // TCG protocol is not installed. So, TPM12 is not present.
  41. //
  42. DEBUG ((DEBUG_ERROR, "Tpm12SubmitCommand - TCG - %r\n", Status));
  43. return EFI_NOT_FOUND;
  44. }
  45. }
  46. //
  47. // Assume when TCG Protocol is ready, RequestUseTpm already done.
  48. //
  49. Status = mTcgProtocol->PassThroughToTpm (
  50. mTcgProtocol,
  51. InputParameterBlockSize,
  52. InputParameterBlock,
  53. *OutputParameterBlockSize,
  54. OutputParameterBlock
  55. );
  56. if (EFI_ERROR (Status)) {
  57. return Status;
  58. }
  59. Header = (TPM_RSP_COMMAND_HDR *)OutputParameterBlock;
  60. *OutputParameterBlockSize = SwapBytes32 (Header->paramSize);
  61. return EFI_SUCCESS;
  62. }
  63. /**
  64. This service requests use TPM12.
  65. @retval EFI_SUCCESS Get the control of TPM12 chip.
  66. @retval EFI_NOT_FOUND TPM12 not found.
  67. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  68. **/
  69. EFI_STATUS
  70. EFIAPI
  71. Tpm12RequestUseTpm (
  72. VOID
  73. )
  74. {
  75. EFI_STATUS Status;
  76. if (mTcgProtocol == NULL) {
  77. Status = gBS->LocateProtocol (&gEfiTcgProtocolGuid, NULL, (VOID **)&mTcgProtocol);
  78. if (EFI_ERROR (Status)) {
  79. //
  80. // TCG protocol is not installed. So, TPM12 is not present.
  81. //
  82. DEBUG ((DEBUG_ERROR, "Tpm12RequestUseTpm - TCG - %r\n", Status));
  83. return EFI_NOT_FOUND;
  84. }
  85. }
  86. //
  87. // Assume when TCG Protocol is ready, RequestUseTpm already done.
  88. //
  89. return EFI_SUCCESS;
  90. }