TianoCore EDK2 master
Loading...
Searching...
No Matches
Tpm2Generator.c
Go to the documentation of this file.
1
18#include <Library/AcpiLib.h>
19#include <Library/BaseLib.h>
21#include <Library/DebugLib.h>
23#include <Protocol/AcpiTable.h>
24
25// Module specific include files.
26#include <AcpiTableGenerator.h>
31
33
34#define START_METHOD_ACPI_PARAM_SIZE_MIN 4
35#define START_METHOD_CRB_WITH_SMC_PARAM_SIZE 12
36
53 );
54
67 )
68{
69 ASSERT (TpmInfo != NULL);
70
71 if (sizeof (TpmInfo->StartMethodParameters) < TpmInfo->StartMethodParametersSize) {
72 ASSERT (FALSE);
73 return EFI_INVALID_PARAMETER;
74 }
75
76 // LAML and LASA are either both set or both zeros
77 if (((TpmInfo->Laml > 0) && (TpmInfo->Lasa == 0)) ||
78 ((TpmInfo->Laml == 0) && (TpmInfo->Lasa != 0)))
79 {
80 return EFI_INVALID_PARAMETER;
81 }
82
83 // Verify StartMethodParametersSize based on StartMethod
84 switch (TpmInfo->StartMethod) {
85 case EFI_TPM2_ACPI_TABLE_START_METHOD_ACPI:
86 // If the Start Method value is 2, then this field is at least four
87 // bytes in size and the first four bytes must be all zero.
88 if (TpmInfo->StartMethodParametersSize < START_METHOD_ACPI_PARAM_SIZE_MIN) {
89 return EFI_INVALID_PARAMETER;
90 }
91
92 if (((UINT32 *)TpmInfo->StartMethodParameters)[0] != 0) {
93 return EFI_INVALID_PARAMETER;
94 }
95
96 break;
97
98 case EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE_WITH_SMC:
99 // If the Start Method value is 11 then this field is 12 bytes in size
100 if (TpmInfo->StartMethodParametersSize != START_METHOD_CRB_WITH_SMC_PARAM_SIZE) {
101 return EFI_INVALID_PARAMETER;
102 }
103
104 break;
105
106 case EFI_TPM2_ACPI_TABLE_START_METHOD_TIS:
107 case EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE:
108 case EFI_TPM2_ACPI_TABLE_START_METHOD_COMMAND_RESPONSE_BUFFER_INTERFACE_WITH_ACPI:
109 break;
110
111 default:
112 return EFI_INVALID_PARAMETER;
113 break;
114 }
115
116 return EFI_SUCCESS;
117}
118
142STATIC
144EFIAPI
150 )
151{
152 EFI_STATUS Status;
153 UINT32 TableSize;
156 UINT32 *Laml;
157 UINT64 *Lasa;
158
159 *Table = NULL;
160
161 ASSERT (
162 (This != NULL) &&
163 (AcpiTableInfo != NULL) &&
164 (CfgMgrProtocol != NULL) &&
165 (Table != NULL) &&
166 (AcpiTableInfo->TableGeneratorId == This->GeneratorID) &&
167 (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature)
168 );
169
170 if ((AcpiTableInfo->AcpiTableRevision < This->MinAcpiTableRevision) ||
171 (AcpiTableInfo->AcpiTableRevision > This->AcpiTableRevision))
172 {
173 DEBUG ((
174 DEBUG_ERROR,
175 "ERROR: TPM2: Requested table revision = %d is not supported. "
176 "Supported table revisions: Minimum = %d. Maximum = %d\n",
177 AcpiTableInfo->AcpiTableRevision,
178 This->MinAcpiTableRevision,
179 This->AcpiTableRevision
180 ));
181 return EFI_INVALID_PARAMETER;
182 }
183
184 Status = GetEArchCommonObjTpm2InterfaceInfo (
185 CfgMgrProtocol,
187 &TpmInfo,
188 NULL
189 );
190 if (EFI_ERROR (Status)) {
191 DEBUG ((
192 DEBUG_ERROR,
193 "%a: Failed to get TPM interface CM Object %r\n",
194 __func__,
195 Status
196 ));
197 return Status;
198 }
199
200 // Sanity check Start Method Specific Parameters field
201 Status = AcpiTpm2CheckStartMethodParameters (TpmInfo);
202 if (EFI_ERROR (Status)) {
203 DEBUG ((
204 DEBUG_ERROR,
205 "ERROR: TPM2: Unexpected StartMethod %u with parameters size %u\n",
206 TpmInfo->StartMethod,
208 ));
209 return EFI_INVALID_PARAMETER;
210 }
211
212 // Calculate the size of the TPM2 table
213 TableSize = sizeof (EFI_TPM2_ACPI_TABLE);
214 if (TpmInfo->Laml == 0) {
215 TableSize += TpmInfo->StartMethodParametersSize;
216 } else {
217 // If LAML and LASA are present, then StartMethodParameters field would get
218 // max size regardless of StartMethod value
219 TableSize += EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_4;
220 TableSize += sizeof (TpmInfo->Laml) + sizeof (TpmInfo->Lasa);
221 }
222
223 // Allocate the Buffer for TPM2 table
224 *Table = (EFI_ACPI_DESCRIPTION_HEADER *)AllocateZeroPool (TableSize);
225 if (*Table == NULL) {
226 DEBUG ((
227 DEBUG_ERROR,
228 "ERROR: TPM2: Failed to allocate memory for TPM2 Table, Size = %d," \
229 " Status = %r\n",
230 TableSize,
231 Status
232 ));
233 return EFI_OUT_OF_RESOURCES;
234 }
235
236 Tpm2 = (EFI_TPM2_ACPI_TABLE *)*Table;
237
238 Status = AddAcpiHeader (
239 CfgMgrProtocol,
240 This,
241 &Tpm2->Header,
242 AcpiTableInfo,
243 TableSize
244 );
245 if (EFI_ERROR (Status)) {
246 DEBUG ((
247 DEBUG_ERROR,
248 "ERROR: TPM2: Failed to add ACPI header. Status = %r\n",
249 Status
250 ));
251 goto error_handler;
252 }
253
254 Tpm2->Flags = TpmInfo->PlatformClass;
255 Tpm2->AddressOfControlArea = TpmInfo->AddressOfControlArea;
256 Tpm2->StartMethod = TpmInfo->StartMethod;
257
258 CopyMem (
259 Tpm2 + 1,
260 TpmInfo->StartMethodParameters,
262 );
263
264 if (TpmInfo->Laml > 0) {
265 Laml = (UINT32 *)((UINT8 *)Tpm2 + sizeof (EFI_TPM2_ACPI_TABLE) +
266 EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE_REVISION_4);
267 Lasa = (UINT64 *)((UINT8 *)Laml + sizeof (TpmInfo->Laml));
268 *Laml = TpmInfo->Laml;
269 *Lasa = TpmInfo->Lasa;
270 }
271
272 return EFI_SUCCESS;
273
274error_handler:
275
276 if (*Table != NULL) {
277 FreePool (*Table);
278 *Table = NULL;
279 }
280
281 return Status;
282}
283
295STATIC
297EFIAPI
303 )
304{
305 ASSERT (
306 (This != NULL) &&
307 (AcpiTableInfo != NULL) &&
308 (CfgMgrProtocol != NULL) &&
309 (AcpiTableInfo->TableGeneratorId == This->GeneratorID) &&
310 (AcpiTableInfo->AcpiTableSignature == This->AcpiTableSignature)
311 );
312
313 if ((Table == NULL) || (*Table == NULL)) {
314 DEBUG ((DEBUG_ERROR, "ERROR: TPM2: Invalid Table Pointer\n"));
315 return EFI_INVALID_PARAMETER;
316 }
317
318 FreePool (*Table);
319 *Table = NULL;
320
321 return EFI_SUCCESS;
322}
323
326#define TPM2_GENERATOR_REVISION CREATE_REVISION (1, 0)
327
330STATIC
331CONST
333 // Generator ID
335 // Generator Description
336 L"ACPI.STD.TPM2.GENERATOR",
337 // ACPI Table Signature
339 // ACPI Table Revision supported by this Generator
340 EFI_TPM2_ACPI_TABLE_REVISION_4,
341 // Minimum supported ACPI Table Revision
342 EFI_TPM2_ACPI_TABLE_REVISION_4,
343 // Creator ID
345 // Creator Revision
347 // Build Table function
349 // Free Resource function
351 // Extended build function not needed
352 NULL,
353 // Extended build function not implemented by the generator.
354 // Hence extended free resource function is not required.
355 NULL
356};
357
369EFIAPI
371 IN EFI_HANDLE ImageHandle,
372 IN EFI_SYSTEM_TABLE *SystemTable
373 )
374{
375 EFI_STATUS Status;
376
378 DEBUG ((DEBUG_INFO, "TPM2: Register Generator. Status = %r\n", Status));
379 ASSERT_EFI_ERROR (Status);
380 return Status;
381}
382
393EFIAPI
395 IN EFI_HANDLE ImageHandle,
396 IN EFI_SYSTEM_TABLE *SystemTable
397 )
398{
399 EFI_STATUS Status;
400
402 DEBUG ((DEBUG_INFO, "TPM2: Deregister Generator. Status = %r\n", Status));
403 ASSERT_EFI_ERROR (Status);
404 return Status;
405}
#define EFI_ACPI_6_4_TRUSTED_COMPUTING_PLATFORM_2_TABLE_SIGNATURE
Definition: Acpi64.h:3135
EFI_STATUS EFIAPI RegisterAcpiTableGenerator(IN CONST ACPI_TABLE_GENERATOR *CONST Generator)
EFI_STATUS EFIAPI DeregisterAcpiTableGenerator(IN CONST ACPI_TABLE_GENERATOR *CONST Generator)
#define CREATE_STD_ACPI_TABLE_GEN_ID(TableId)
#define TABLE_GENERATOR_CREATOR_ID
@ EStdAcpiTableIdTpm2
TPM2 Generator.
@ EArchCommonObjTpm2InterfaceInfo
26 - TPM Interface Info
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
#define GET_OBJECT_LIST(CmObjectNameSpace, CmObjectId, Type)
@ EObjNameSpaceArchCommon
Arch Common Objects Namespace.
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define STATIC
Definition: Base.h:264
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define CM_NULL_TOKEN
EFI_STATUS EFIAPI AddAcpiHeader(IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, IN CONST ACPI_TABLE_GENERATOR *CONST Generator, IN OUT EFI_ACPI_DESCRIPTION_HEADER *CONST AcpiHeader, IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, IN CONST UINT32 Length)
Definition: TableHelper.c:114
STATIC EFI_STATUS EFIAPI FreeTpm2TableResources(IN CONST ACPI_TABLE_GENERATOR *CONST This, IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, IN OUT EFI_ACPI_DESCRIPTION_HEADER **CONST Table)
STATIC EFI_STATUS EFIAPI BuildTpm2Table(IN CONST ACPI_TABLE_GENERATOR *CONST This, IN CONST CM_STD_OBJ_ACPI_TABLE_INFO *CONST AcpiTableInfo, IN CONST EDKII_CONFIGURATION_MANAGER_PROTOCOL *CONST CfgMgrProtocol, OUT EFI_ACPI_DESCRIPTION_HEADER **CONST Table)
EFI_STATUS EFIAPI AcpiTpm2LibConstructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
STATIC CONST ACPI_TABLE_GENERATOR Tpm2Generator
STATIC EFI_STATUS AcpiTpm2CheckStartMethodParameters(CM_ARCH_COMMON_TPM2_INTERFACE_INFO *TpmInfo)
Definition: Tpm2Generator.c:65
EFI_STATUS EFIAPI AcpiTpm2LibDestructor(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
#define TPM2_GENERATOR_REVISION
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
UINT8 StartMethodParameters[EFI_TPM2_ACPI_TABLE_START_METHOD_SPECIFIC_PARAMETERS_MAX_SIZE]