1 /** @file 2 Implement TPM1.2 Physical Presence related command. 3 4 Copyright (c) 2016, Intel Corporation. All rights reserved. <BR> 5 This program and the accompanying materials 6 are licensed and made available under the terms and conditions of the BSD License 7 which accompanies this distribution. The full text of the license may be found at 8 http://opensource.org/licenses/bsd-license.php 9 10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 12 13 **/ 14 15 #include <PiPei.h> 16 #include <Library/Tpm12CommandLib.h> 17 #include <Library/BaseLib.h> 18 #include <Library/DebugLib.h> 19 #include <Library/Tpm12DeviceLib.h> 20 21 #pragma pack(1) 22 23 typedef struct { 24 TPM_RQU_COMMAND_HDR Hdr; 25 TPM_PHYSICAL_PRESENCE PhysicalPresence; 26 } TPM_CMD_PHYSICAL_PRESENCE; 27 28 #pragma pack() 29 30 /** 31 Send TSC_PhysicalPresence command to TPM. 32 33 @param[in] PhysicalPresence The state to set the TPMs Physical Presence flags. 34 35 @retval EFI_SUCCESS Operation completed successfully. 36 @retval EFI_TIMEOUT The register can't run into the expected status in time. 37 @retval EFI_BUFFER_TOO_SMALL Response data buffer is too small. 38 @retval EFI_DEVICE_ERROR Unexpected device behavior. 39 40 **/ 41 EFI_STATUS 42 EFIAPI Tpm12PhysicalPresence(IN TPM_PHYSICAL_PRESENCE PhysicalPresence)43Tpm12PhysicalPresence ( 44 IN TPM_PHYSICAL_PRESENCE PhysicalPresence 45 ) 46 { 47 EFI_STATUS Status; 48 TPM_CMD_PHYSICAL_PRESENCE Command; 49 TPM_RSP_COMMAND_HDR Response; 50 UINT32 Length; 51 52 // 53 // send Tpm command TSC_ORD_PhysicalPresence 54 // 55 Command.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND); 56 Command.Hdr.paramSize = SwapBytes32 (sizeof (Command)); 57 Command.Hdr.ordinal = SwapBytes32 (TSC_ORD_PhysicalPresence); 58 Command.PhysicalPresence = SwapBytes16 (PhysicalPresence); 59 Length = sizeof (Response); 60 61 Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response); 62 if (EFI_ERROR (Status)) { 63 return Status; 64 } 65 66 if (SwapBytes32(Response.returnCode) != TPM_SUCCESS) { 67 DEBUG ((EFI_D_ERROR, "Tpm12PhysicalPresence: Response Code error! 0x%08x\r\n", SwapBytes32(Response.returnCode))); 68 return EFI_DEVICE_ERROR; 69 } 70 71 return EFI_SUCCESS; 72 } 73