]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Library/SmmTcgPhysicalPresenceStorageLib/SmmTcgPhysicalPresenceStorageLib.c
SecurityPkg: Add SmmTcgPhysicalPresenceStorageLib.
[mirror_edk2.git] / SecurityPkg / Library / SmmTcgPhysicalPresenceStorageLib / SmmTcgPhysicalPresenceStorageLib.c
1 /** @file
2 Tcg PP storage library instance that does support any storage specific PPI.
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 #include <PiDxe.h>
15
16 #include <Guid/TcgPhysicalPresenceStorageData.h>
17 #include <IndustryStandard/TcgPhysicalPresence.h>
18
19 #include <Protocol/SmmVariable.h>
20
21
22
23 #include <Library/TcgPhysicalPresenceStorageLib.h>
24 #include <Library/DebugLib.h>
25 #include <Library/SmmServicesTableLib.h>
26
27
28 EFI_SMM_VARIABLE_PROTOCOL *mTcg2PpStorageSmmVariable;
29
30 /**
31 The handler for TPM physical presence function:
32 Submit TPM Operation Request to Pre-OS Environment and
33 Submit TPM Operation Request to Pre-OS Environment 2.
34
35 Caution: This function may receive untrusted input.
36
37 @param[in] OperationRequest TPM physical presence operation request.
38 @param[in] RequestParameter TPM physical presence operation request parameter.
39
40 @return Return Code for Submit TPM Operation Request to Pre-OS Environment and
41 Submit TPM Operation Request to Pre-OS Environment 2.
42 **/
43 UINT32
44 EFIAPI
45 TcgPhysicalPresenceStorageLibSubmitRequestToPreOSFunction (
46 IN UINT32 OperationRequest,
47 IN UINT32 RequestParameter
48 )
49 {
50 ASSERT (FALSE);
51
52 return TCG_PP_RETURN_TPM_OPERATION_RESPONSE_SUCCESS;
53 }
54
55 /**
56 The handler for TPM physical presence function:
57 Return TPM Operation Response to OS Environment.
58
59 @param[out] MostRecentRequest Most recent operation request.
60 @param[out] Response Response to the most recent operation request.
61
62 @return Return Code for Return TPM Operation Response to OS Environment.
63 **/
64 UINT32
65 EFIAPI
66 TcgPhysicalPresenceStorageLibReturnOperationResponseToOsFunction (
67 OUT UINT32 *MostRecentRequest,
68 OUT UINT32 *Response
69 )
70 {
71 ASSERT (FALSE);
72
73 return TCG_PP_RETURN_TPM_OPERATION_RESPONSE_SUCCESS;
74 }
75
76 /**
77 Check if the pending TPM request needs user input to confirm.
78
79 The TPM request may come from OS. This API will check if TPM request exists and need user
80 input to confirmation.
81
82 @retval TRUE TPM needs input to confirm user physical presence.
83 @retval FALSE TPM doesn't need input to confirm user physical presence.
84
85 **/
86 BOOLEAN
87 EFIAPI
88 TcgPhysicalPresenceStorageLibNeedUserConfirm(
89 VOID
90 )
91 {
92 ASSERT (FALSE);
93
94 return FALSE;
95 }
96
97 /**
98 Check and execute the pending TPM request.
99
100 The TPM request may come from OS or BIOS. This API will display request information and wait
101 for user confirmation if TPM request exists. The TPM request will be sent to TPM device after
102 the TPM request is confirmed, and one or more reset may be required to make TPM request to
103 take effect.
104
105 This API should be invoked after console in and console out are all ready as they are required
106 to display request information and get user input to confirm the request.
107
108 @param[in] PlatformAuth platform auth value. NULL means no platform auth change.
109 **/
110 VOID
111 EFIAPI
112 TcgPhysicalPresenceStorageLibProcessRequest (
113 VOID
114 )
115 {
116 ASSERT (FALSE);
117 }
118
119 /**
120 The handler for TPM physical presence function:
121 Return TPM Operation flag variable.
122
123 @return Return Code for Return TPM Operation flag variable.
124 **/
125 UINT32
126 EFIAPI
127 TcgPhysicalPresenceStorageLibReturnStorageFlags (
128 VOID
129 )
130 {
131 UINTN DataSize;
132 EFI_TCG_PHYSICAL_PRESENCE_STORAGE_FLAGS PpiFlags;
133 EFI_STATUS Status;
134
135 //
136 // Get the Physical Presence storage flags
137 //
138 DataSize = sizeof (EFI_TCG_PHYSICAL_PRESENCE_STORAGE_FLAGS);
139 Status = mTcg2PpStorageSmmVariable->SmmGetVariable (
140 TCG_PHYSICAL_PRESENCE_STORAGE_FLAGS_VARIABLE,
141 &gEfiTcgPhysicalPresenceStorageGuid,
142 NULL,
143 &DataSize,
144 &PpiFlags
145 );
146 if (EFI_ERROR (Status)) {
147 DEBUG ((EFI_D_ERROR, "[TPM2] Get PP storage flags failure! Status = %r\n", Status));
148 PpiFlags.PPFlags = TCG_BIOS_STORAGE_MANAGEMENT_FLAG_DEFAULT;
149 }
150
151 return PpiFlags.PPFlags;
152 }
153
154 /**
155
156 Install Boot Manager Menu driver.
157
158 @param ImageHandle The image handle.
159 @param SystemTable The system table.
160
161 @retval EFI_SUCEESS Install Boot manager menu success.
162 @retval Other Return error status.
163
164 **/
165 EFI_STATUS
166 EFIAPI
167 TcgPhysicalPresenceStorageLibConstructor (
168 IN EFI_HANDLE ImageHandle,
169 IN EFI_SYSTEM_TABLE *SystemTable
170 )
171 {
172 EFI_STATUS Status;
173
174 //
175 // Locate SmmVariableProtocol.
176 //
177 Status = gSmst->SmmLocateProtocol (&gEfiSmmVariableProtocolGuid, NULL, (VOID**)&mTcg2PpStorageSmmVariable);
178 ASSERT_EFI_ERROR (Status);
179
180 return EFI_SUCCESS;
181 }