TianoCore EDK2 master
Loading...
Searching...
No Matches
Tpm2Startup.c
Go to the documentation of this file.
1
14#include <Library/BaseLib.h>
15#include <Library/DebugLib.h>
16
17#pragma pack(1)
18
19typedef struct {
21 TPM_SU StartupType;
23
24typedef struct {
27
28typedef struct {
30 TPM_SU ShutdownType;
32
33typedef struct {
36
37#pragma pack()
38
48EFIAPI
50 IN TPM_SU StartupType
51 )
52{
53 EFI_STATUS Status;
56 UINT32 ResultBufSize;
57 TPM_RC ResponseCode;
58
59 Cmd.Header.tag = SwapBytes16 (TPM_ST_NO_SESSIONS);
60 Cmd.Header.paramSize = SwapBytes32 (sizeof (Cmd));
61 Cmd.Header.commandCode = SwapBytes32 (TPM_CC_Startup);
62 Cmd.StartupType = SwapBytes16 (StartupType);
63
64 ResultBufSize = sizeof (Res);
65 Status = Tpm2SubmitCommand (sizeof (Cmd), (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);
66 if (EFI_ERROR (Status)) {
67 return Status;
68 }
69
70 ResponseCode = SwapBytes32 (Res.Header.responseCode);
71 switch (ResponseCode) {
72 case TPM_RC_SUCCESS:
73 DEBUG ((DEBUG_INFO, "TPM2Startup: TPM_RC_SUCCESS\n"));
74 return EFI_SUCCESS;
75 case TPM_RC_INITIALIZE:
76 // TPM_RC_INITIALIZE can be returned if Tpm2Startup is not required.
77 DEBUG ((DEBUG_INFO, "TPM2Startup: TPM_RC_INITIALIZE\n"));
78 return EFI_SUCCESS;
79 default:
80 DEBUG ((DEBUG_ERROR, "Tpm2Startup: Response Code error! 0x%08x\r\n", ResponseCode));
81 return EFI_DEVICE_ERROR;
82 }
83}
84
94EFIAPI
96 IN TPM_SU ShutdownType
97 )
98{
99 EFI_STATUS Status;
102 UINT32 ResultBufSize;
103
104 Cmd.Header.tag = SwapBytes16 (TPM_ST_NO_SESSIONS);
105 Cmd.Header.paramSize = SwapBytes32 (sizeof (Cmd));
106 Cmd.Header.commandCode = SwapBytes32 (TPM_CC_Shutdown);
107 Cmd.ShutdownType = SwapBytes16 (ShutdownType);
108
109 ResultBufSize = sizeof (Res);
110 Status = Tpm2SubmitCommand (sizeof (Cmd), (UINT8 *)&Cmd, &ResultBufSize, (UINT8 *)&Res);
111 if (EFI_ERROR (Status)) {
112 return Status;
113 }
114
115 if (SwapBytes32 (Res.Header.responseCode) != TPM_RC_SUCCESS) {
116 DEBUG ((DEBUG_ERROR, "Tpm2Shutdown: Response Code error! 0x%08x\r\n", SwapBytes32 (Res.Header.responseCode)));
117 return EFI_DEVICE_ERROR;
118 }
119
120 return EFI_SUCCESS;
121}
UINT16 EFIAPI SwapBytes16(IN UINT16 Value)
Definition: SwapBytes16.c:25
UINT32 EFIAPI SwapBytes32(IN UINT32 Value)
Definition: SwapBytes32.c:25
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
EFI_STATUS EFIAPI Tpm2SubmitCommand(IN UINT32 InputParameterBlockSize, IN UINT8 *InputParameterBlock, IN OUT UINT32 *OutputParameterBlockSize, IN UINT8 *OutputParameterBlock)
EFI_STATUS EFIAPI Tpm2Startup(IN TPM_SU StartupType)
Definition: Tpm2Startup.c:49
EFI_STATUS EFIAPI Tpm2Shutdown(IN TPM_SU ShutdownType)
Definition: Tpm2Startup.c:95
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112