Tpm2DeviceLibDTpm.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /** @file
  2. This library is TPM2 DTPM device lib.
  3. Choosing this library means platform uses and only uses DTPM device as TPM2 engine.
  4. Copyright (c) 2013 - 2018, Intel Corporation. All rights reserved. <BR>
  5. SPDX-License-Identifier: BSD-2-Clause-Patent
  6. **/
  7. #include <Library/BaseLib.h>
  8. #include <Library/BaseMemoryLib.h>
  9. #include <Library/DebugLib.h>
  10. #include <Library/Tpm2DeviceLib.h>
  11. #include <Library/PcdLib.h>
  12. /**
  13. Return PTP interface type.
  14. @param[in] Register Pointer to PTP register.
  15. @return PTP interface type.
  16. **/
  17. TPM2_PTP_INTERFACE_TYPE
  18. Tpm2GetPtpInterface (
  19. IN VOID *Register
  20. );
  21. /**
  22. Return PTP CRB interface IdleByPass state.
  23. @param[in] Register Pointer to PTP register.
  24. @return PTP CRB interface IdleByPass state.
  25. **/
  26. UINT8
  27. Tpm2GetIdleByPass (
  28. IN VOID *Register
  29. );
  30. /**
  31. This service enables the sending of commands to the TPM2.
  32. @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.
  33. @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.
  34. @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.
  35. @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.
  36. @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
  37. @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
  38. @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
  39. **/
  40. EFI_STATUS
  41. EFIAPI
  42. DTpm2SubmitCommand (
  43. IN UINT32 InputParameterBlockSize,
  44. IN UINT8 *InputParameterBlock,
  45. IN OUT UINT32 *OutputParameterBlockSize,
  46. IN UINT8 *OutputParameterBlock
  47. );
  48. /**
  49. This service requests use TPM2.
  50. @retval EFI_SUCCESS Get the control of TPM2 chip.
  51. @retval EFI_NOT_FOUND TPM2 not found.
  52. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  53. **/
  54. EFI_STATUS
  55. EFIAPI
  56. DTpm2RequestUseTpm (
  57. VOID
  58. );
  59. /**
  60. This service enables the sending of commands to the TPM2.
  61. @param[in] InputParameterBlockSize Size of the TPM2 input parameter block.
  62. @param[in] InputParameterBlock Pointer to the TPM2 input parameter block.
  63. @param[in,out] OutputParameterBlockSize Size of the TPM2 output parameter block.
  64. @param[in] OutputParameterBlock Pointer to the TPM2 output parameter block.
  65. @retval EFI_SUCCESS The command byte stream was successfully sent to the device and a response was successfully received.
  66. @retval EFI_DEVICE_ERROR The command was not successfully sent to the device or a response was not successfully received from the device.
  67. @retval EFI_BUFFER_TOO_SMALL The output parameter block is too small.
  68. **/
  69. EFI_STATUS
  70. EFIAPI
  71. Tpm2SubmitCommand (
  72. IN UINT32 InputParameterBlockSize,
  73. IN UINT8 *InputParameterBlock,
  74. IN OUT UINT32 *OutputParameterBlockSize,
  75. IN UINT8 *OutputParameterBlock
  76. )
  77. {
  78. return DTpm2SubmitCommand (
  79. InputParameterBlockSize,
  80. InputParameterBlock,
  81. OutputParameterBlockSize,
  82. OutputParameterBlock
  83. );
  84. }
  85. /**
  86. This service requests use TPM2.
  87. @retval EFI_SUCCESS Get the control of TPM2 chip.
  88. @retval EFI_NOT_FOUND TPM2 not found.
  89. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  90. **/
  91. EFI_STATUS
  92. EFIAPI
  93. Tpm2RequestUseTpm (
  94. VOID
  95. )
  96. {
  97. return DTpm2RequestUseTpm ();
  98. }
  99. /**
  100. This service register TPM2 device.
  101. @param Tpm2Device TPM2 device
  102. @retval EFI_SUCCESS This TPM2 device is registered successfully.
  103. @retval EFI_UNSUPPORTED System does not support register this TPM2 device.
  104. @retval EFI_ALREADY_STARTED System already register this TPM2 device.
  105. **/
  106. EFI_STATUS
  107. EFIAPI
  108. Tpm2RegisterTpm2DeviceLib (
  109. IN TPM2_DEVICE_INTERFACE *Tpm2Device
  110. )
  111. {
  112. return EFI_UNSUPPORTED;
  113. }
  114. /**
  115. The function caches current active TPM interface type.
  116. @retval EFI_SUCCESS DTPM2.0 instance is registered, or system does not support register DTPM2.0 instance
  117. **/
  118. EFI_STATUS
  119. EFIAPI
  120. Tpm2DeviceLibConstructor (
  121. VOID
  122. )
  123. {
  124. TPM2_PTP_INTERFACE_TYPE PtpInterface;
  125. UINT8 IdleByPass;
  126. //
  127. // Cache current active TpmInterfaceType only when needed
  128. //
  129. if (PcdGet8(PcdActiveTpmInterfaceType) == 0xFF) {
  130. PtpInterface = Tpm2GetPtpInterface ((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
  131. PcdSet8S(PcdActiveTpmInterfaceType, PtpInterface);
  132. }
  133. if (PcdGet8(PcdActiveTpmInterfaceType) == Tpm2PtpInterfaceCrb && PcdGet8(PcdCRBIdleByPass) == 0xFF) {
  134. IdleByPass = Tpm2GetIdleByPass((VOID *) (UINTN) PcdGet64 (PcdTpmBaseAddress));
  135. PcdSet8S(PcdCRBIdleByPass, IdleByPass);
  136. }
  137. return EFI_SUCCESS;
  138. }