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