]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/Tpm12CommandLib/Tpm12Startup.c
Add TPM2 implementation.
[mirror_edk2.git] / SecurityPkg / Library / Tpm12CommandLib / Tpm12Startup.c
1 /** @file
2 Implement TPM1.2 Startup related command.
3
4 Copyright (c) 2013, 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 <Uefi.h>
16 #include <IndustryStandard/Tpm12.h>
17 #include <Library/BaseMemoryLib.h>
18 #include <Library/BaseLib.h>
19 #include <Library/Tpm12DeviceLib.h>
20
21 #pragma pack(1)
22
23 typedef struct {
24 TPM_RQU_COMMAND_HDR Hdr;
25 TPM_STARTUP_TYPE TpmSt;
26 } TPM_CMD_START_UP;
27
28 typedef struct {
29 TPM_RSP_COMMAND_HDR Hdr;
30 } TPM_RSP_START_UP;
31
32 #pragma pack()
33
34 /**
35 Send Startup command to TPM1.2.
36
37 @param TpmSt Startup Type.
38
39 @retval EFI_SUCCESS Operation completed successfully.
40 @retval EFI_DEVICE_ERROR Unexpected device behavior.
41 **/
42 EFI_STATUS
43 EFIAPI
44 Tpm12Startup (
45 IN TPM_STARTUP_TYPE TpmSt
46 )
47 {
48 EFI_STATUS Status;
49 UINT32 TpmRecvSize;
50 UINT32 TpmSendSize;
51 TPM_CMD_START_UP SendBuffer;
52 TPM_RSP_START_UP RecvBuffer;
53 UINT32 ReturnCode;
54
55 //
56 // send Tpm command TPM_ORD_Startup
57 //
58 TpmRecvSize = sizeof (TPM_RSP_START_UP);
59 TpmSendSize = sizeof (TPM_CMD_START_UP);
60 SendBuffer.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
61 SendBuffer.Hdr.paramSize = SwapBytes32 (TpmSendSize);
62 SendBuffer.Hdr.ordinal = SwapBytes32 (TPM_ORD_Startup);
63 SendBuffer.TpmSt = SwapBytes16 (TpmSt);
64
65 Status = Tpm12SubmitCommand (TpmSendSize, (UINT8 *)&SendBuffer, &TpmRecvSize, (UINT8 *)&RecvBuffer);
66 if (EFI_ERROR (Status)) {
67 return Status;
68 }
69 ReturnCode = SwapBytes32(RecvBuffer.Hdr.returnCode);
70 switch (ReturnCode) {
71 case TPM_SUCCESS:
72 case TPM_INVALID_POSTINIT:
73 // In warm reset, TPM may response TPM_INVALID_POSTINIT
74 return EFI_SUCCESS;
75 default:
76 return EFI_DEVICE_ERROR;
77 }
78 }