]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/Tpm12CommandLib/Tpm12Startup.c
SecurityPkg: Add TPM PTP support in TCG2 SMM.
[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 <PiPei.h>
16 #include <Library/BaseMemoryLib.h>
17 #include <Library/BaseLib.h>
18 #include <Library/Tpm12DeviceLib.h>
19
20 #pragma pack(1)
21
22 typedef struct {
23 TPM_RQU_COMMAND_HDR Hdr;
24 TPM_STARTUP_TYPE TpmSt;
25 } TPM_CMD_START_UP;
26
27 #pragma pack()
28
29 /**
30 Send Startup command to TPM1.2.
31
32 @param TpmSt Startup Type.
33
34 @retval EFI_SUCCESS Operation completed successfully.
35 @retval EFI_DEVICE_ERROR Unexpected device behavior.
36 **/
37 EFI_STATUS
38 EFIAPI
39 Tpm12Startup (
40 IN TPM_STARTUP_TYPE TpmSt
41 )
42 {
43 EFI_STATUS Status;
44 TPM_CMD_START_UP Command;
45 TPM_RSP_COMMAND_HDR Response;
46 UINT32 Length;
47
48 //
49 // send Tpm command TPM_ORD_Startup
50 //
51 Command.Hdr.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
52 Command.Hdr.paramSize = SwapBytes32 (sizeof (Command));
53 Command.Hdr.ordinal = SwapBytes32 (TPM_ORD_Startup);
54 Command.TpmSt = SwapBytes16 (TpmSt);
55 Length = sizeof (Response);
56 Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);
57 if (EFI_ERROR (Status)) {
58 return Status;
59 }
60 switch (SwapBytes32(Response.returnCode)) {
61 case TPM_SUCCESS:
62 case TPM_INVALID_POSTINIT:
63 // In warm reset, TPM may response TPM_INVALID_POSTINIT
64 return EFI_SUCCESS;
65 default:
66 return EFI_DEVICE_ERROR;
67 }
68 }
69
70 /**
71 Send SaveState command to TPM1.2.
72
73 @retval EFI_SUCCESS Operation completed successfully.
74 @retval EFI_DEVICE_ERROR Unexpected device behavior.
75 **/
76 EFI_STATUS
77 EFIAPI
78 Tpm12SaveState (
79 VOID
80 )
81 {
82 EFI_STATUS Status;
83 TPM_RQU_COMMAND_HDR Command;
84 TPM_RSP_COMMAND_HDR Response;
85 UINT32 Length;
86
87 //
88 // send Tpm command TPM_ORD_SaveState
89 //
90 Command.tag = SwapBytes16 (TPM_TAG_RQU_COMMAND);
91 Command.paramSize = SwapBytes32 (sizeof (Command));
92 Command.ordinal = SwapBytes32 (TPM_ORD_SaveState);
93 Length = sizeof (Response);
94 Status = Tpm12SubmitCommand (sizeof (Command), (UINT8 *)&Command, &Length, (UINT8 *)&Response);
95 if (EFI_ERROR (Status)) {
96 return Status;
97 }
98 switch (SwapBytes32 (Response.returnCode)) {
99 case TPM_SUCCESS:
100 return EFI_SUCCESS;
101 default:
102 return EFI_DEVICE_ERROR;
103 }
104 }