Tpm12PhysicalPresence.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /** @file
  2. Implement TPM1.2 Physical Presence related command.
  3. Copyright (c) 2016, Intel Corporation. All rights reserved. <BR>
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. **/
  6. #include <PiPei.h>
  7. #include <Library/Tpm12CommandLib.h>
  8. #include <Library/BaseLib.h>
  9. #include <Library/DebugLib.h>
  10. #include <Library/Tpm12DeviceLib.h>
  11. #pragma pack(1)
  12. typedef struct {
  13. TPM_RQU_COMMAND_HDR Hdr;
  14. TPM_PHYSICAL_PRESENCE PhysicalPresence;
  15. } TPM_CMD_PHYSICAL_PRESENCE;
  16. #pragma pack()
  17. /**
  18. Send TSC_PhysicalPresence command to TPM.
  19. @param[in] PhysicalPresence The state to set the TPMs Physical Presence flags.
  20. @retval EFI_SUCCESS Operation completed successfully.
  21. @retval EFI_TIMEOUT The register can't run into the expected status in time.
  22. @retval EFI_BUFFER_TOO_SMALL Response data buffer is too small.
  23. @retval EFI_DEVICE_ERROR Unexpected device behavior.
  24. **/
  25. EFI_STATUS
  26. EFIAPI
  27. Tpm12PhysicalPresence (
  28. IN TPM_PHYSICAL_PRESENCE PhysicalPresence
  29. )
  30. {
  31. EFI_STATUS Status;
  32. TPM_CMD_PHYSICAL_PRESENCE Command;
  33. TPM_RSP_COMMAND_HDR Response;
  34. UINT32 Length;
  35. //
  36. // send Tpm command TSC_ORD_PhysicalPresence
  37. //
  38. Command.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
  39. Command.Hdr.paramSize = SwapBytes32 (sizeof (Command));
  40. Command.Hdr.ordinal = SwapBytes32 (TSC_ORD_PhysicalPresence);
  41. Command.PhysicalPresence = SwapBytes16 (PhysicalPresence);
  42. Length = sizeof (Response);
  43. Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);
  44. if (EFI_ERROR (Status)) {
  45. return Status;
  46. }
  47. if (SwapBytes32 (Response.returnCode) != TPM_SUCCESS) {
  48. DEBUG ((DEBUG_ERROR, "Tpm12PhysicalPresence: Response Code error! 0x%08x\r\n", SwapBytes32 (Response.returnCode)));
  49. return EFI_DEVICE_ERROR;
  50. }
  51. return EFI_SUCCESS;
  52. }