]> git.proxmox.com Git - mirror_edk2.git/blame - SecurityPkg/Tcg/Tcg2Config/Tcg2ConfigImpl.c
SecurityPkg: Apply uncrustify changes
[mirror_edk2.git] / SecurityPkg / Tcg / Tcg2Config / Tcg2ConfigImpl.c
CommitLineData
1abfa4ce
JY
1/** @file\r
2 HII Config Access protocol implementation of TCG2 configuration module.\r
3 NOTE: This module is only for reference only, each platform should have its own setup page.\r
4\r
f15cb995 5Copyright (c) 2015 - 2018, Intel Corporation. All rights reserved.<BR>\r
efa5343a 6(C) Copyright 2018 Hewlett Packard Enterprise Development LP<BR>\r
289b714b 7SPDX-License-Identifier: BSD-2-Clause-Patent\r
1abfa4ce
JY
8\r
9**/\r
10\r
11#include "Tcg2ConfigImpl.h"\r
12#include <Library/PcdLib.h>\r
13#include <Library/Tpm2CommandLib.h>\r
f15cb995 14#include <Library/Tpm2DeviceLib.h>\r
518b6f65 15#include <Library/IoLib.h>\r
f15cb995 16\r
1abfa4ce
JY
17#include <Guid/TpmInstance.h>\r
18\r
518b6f65
JY
19#include <IndustryStandard/TpmPtp.h>\r
20\r
c411b485 21#define EFI_TCG2_EVENT_LOG_FORMAT_ALL (EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2 | EFI_TCG2_EVENT_LOG_FORMAT_TCG_2)\r
1abfa4ce
JY
22\r
23TPM_INSTANCE_ID mTpmInstanceId[TPM_DEVICE_MAX + 1] = TPM_INSTANCE_ID_LIST;\r
24\r
c411b485
MK
25TCG2_CONFIG_PRIVATE_DATA *mTcg2ConfigPrivateDate;\r
26TCG2_CONFIG_PRIVATE_DATA mTcg2ConfigPrivateDateTemplate = {\r
1abfa4ce
JY
27 TCG2_CONFIG_PRIVATE_DATA_SIGNATURE,\r
28 {\r
29 Tcg2ExtractConfig,\r
30 Tcg2RouteConfig,\r
31 Tcg2Callback\r
32 }\r
33};\r
34\r
c411b485 35HII_VENDOR_DEVICE_PATH mTcg2HiiVendorDevicePath = {\r
1abfa4ce
JY
36 {\r
37 {\r
38 HARDWARE_DEVICE_PATH,\r
39 HW_VENDOR_DP,\r
40 {\r
c411b485
MK
41 (UINT8)(sizeof (VENDOR_DEVICE_PATH)),\r
42 (UINT8)((sizeof (VENDOR_DEVICE_PATH)) >> 8)\r
1abfa4ce
JY
43 }\r
44 },\r
45 TCG2_CONFIG_FORM_SET_GUID\r
46 },\r
47 {\r
48 END_DEVICE_PATH_TYPE,\r
49 END_ENTIRE_DEVICE_PATH_SUBTYPE,\r
b3548d32 50 {\r
c411b485
MK
51 (UINT8)(END_DEVICE_PATH_LENGTH),\r
52 (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)\r
1abfa4ce
JY
53 }\r
54 }\r
55};\r
56\r
57UINT8 mCurrentPpRequest;\r
58\r
518b6f65
JY
59/**\r
60 Return if PTP CRB is supported.\r
61\r
62 @param[in] Register Pointer to PTP register.\r
b3548d32 63\r
518b6f65
JY
64 @retval TRUE PTP CRB is supported.\r
65 @retval FALSE PTP CRB is unsupported.\r
66**/\r
67BOOLEAN\r
68IsPtpCrbSupported (\r
c411b485 69 IN VOID *Register\r
518b6f65
JY
70 )\r
71{\r
72 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId;\r
73\r
74 //\r
75 // Check interface id\r
76 //\r
77 InterfaceId.Uint32 = MmioRead32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId);\r
78\r
79 if (((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB) ||\r
80 (InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO)) &&\r
c411b485
MK
81 (InterfaceId.Bits.CapCRB != 0))\r
82 {\r
518b6f65
JY
83 return TRUE;\r
84 }\r
c411b485 85\r
518b6f65
JY
86 return FALSE;\r
87}\r
88\r
89/**\r
90 Return if PTP FIFO is supported.\r
91\r
92 @param[in] Register Pointer to PTP register.\r
b3548d32 93\r
518b6f65
JY
94 @retval TRUE PTP FIFO is supported.\r
95 @retval FALSE PTP FIFO is unsupported.\r
96**/\r
97BOOLEAN\r
98IsPtpFifoSupported (\r
c411b485 99 IN VOID *Register\r
518b6f65
JY
100 )\r
101{\r
102 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId;\r
103\r
104 //\r
105 // Check interface id\r
106 //\r
107 InterfaceId.Uint32 = MmioRead32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId);\r
108\r
109 if (((InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_CRB) ||\r
110 (InterfaceId.Bits.InterfaceType == PTP_INTERFACE_IDENTIFIER_INTERFACE_TYPE_FIFO)) &&\r
c411b485
MK
111 (InterfaceId.Bits.CapFIFO != 0))\r
112 {\r
518b6f65
JY
113 return TRUE;\r
114 }\r
c411b485 115\r
518b6f65
JY
116 return FALSE;\r
117}\r
118\r
119/**\r
120 Set PTP interface type.\r
f15cb995 121 Do not update PcdActiveTpmInterfaceType here because interface change only happens on next _TPM_INIT\r
518b6f65
JY
122\r
123 @param[in] Register Pointer to PTP register.\r
124 @param[in] PtpInterface PTP interface type.\r
b3548d32 125\r
518b6f65
JY
126 @retval EFI_SUCCESS PTP interface type is set.\r
127 @retval EFI_INVALID_PARAMETER PTP interface type is invalid.\r
128 @retval EFI_UNSUPPORTED PTP interface type is unsupported.\r
129 @retval EFI_WRITE_PROTECTED PTP interface is locked.\r
130**/\r
131EFI_STATUS\r
132SetPtpInterface (\r
c411b485
MK
133 IN VOID *Register,\r
134 IN UINT8 PtpInterface\r
518b6f65
JY
135 )\r
136{\r
f15cb995 137 TPM2_PTP_INTERFACE_TYPE PtpInterfaceCurrent;\r
518b6f65
JY
138 PTP_CRB_INTERFACE_IDENTIFIER InterfaceId;\r
139\r
c411b485 140 PtpInterfaceCurrent = PcdGet8 (PcdActiveTpmInterfaceType);\r
f15cb995 141 if ((PtpInterfaceCurrent != Tpm2PtpInterfaceFifo) &&\r
c411b485
MK
142 (PtpInterfaceCurrent != Tpm2PtpInterfaceCrb))\r
143 {\r
518b6f65
JY
144 return EFI_UNSUPPORTED;\r
145 }\r
c411b485 146\r
518b6f65
JY
147 InterfaceId.Uint32 = MmioRead32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId);\r
148 if (InterfaceId.Bits.IntfSelLock != 0) {\r
149 return EFI_WRITE_PROTECTED;\r
150 }\r
151\r
152 switch (PtpInterface) {\r
c411b485
MK
153 case Tpm2PtpInterfaceFifo:\r
154 if (InterfaceId.Bits.CapFIFO == 0) {\r
155 return EFI_UNSUPPORTED;\r
156 }\r
157\r
158 InterfaceId.Bits.InterfaceSelector = PTP_INTERFACE_IDENTIFIER_INTERFACE_SELECTOR_FIFO;\r
159 MmioWrite32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId, InterfaceId.Uint32);\r
160 return EFI_SUCCESS;\r
161 case Tpm2PtpInterfaceCrb:\r
162 if (InterfaceId.Bits.CapCRB == 0) {\r
163 return EFI_UNSUPPORTED;\r
164 }\r
165\r
166 InterfaceId.Bits.InterfaceSelector = PTP_INTERFACE_IDENTIFIER_INTERFACE_SELECTOR_CRB;\r
167 MmioWrite32 ((UINTN)&((PTP_CRB_REGISTERS *)Register)->InterfaceId, InterfaceId.Uint32);\r
168 return EFI_SUCCESS;\r
169 default:\r
170 return EFI_INVALID_PARAMETER;\r
518b6f65
JY
171 }\r
172}\r
173\r
1abfa4ce
JY
174/**\r
175 This function allows a caller to extract the current configuration for one\r
176 or more named elements from the target driver.\r
177\r
178 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
179 @param[in] Request A null-terminated Unicode string in\r
180 <ConfigRequest> format.\r
181 @param[out] Progress On return, points to a character in the Request\r
182 string. Points to the string's null terminator if\r
183 request was successful. Points to the most recent\r
184 '&' before the first failing name/value pair (or\r
185 the beginning of the string if the failure is in\r
186 the first name/value pair) if the request was not\r
187 successful.\r
188 @param[out] Results A null-terminated Unicode string in\r
189 <ConfigAltResp> format which has all values filled\r
190 in for the names in the Request string. String to\r
191 be allocated by the called function.\r
192\r
193 @retval EFI_SUCCESS The Results is filled with the requested values.\r
194 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.\r
195 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.\r
196 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r
197 driver.\r
198\r
199**/\r
200EFI_STATUS\r
201EFIAPI\r
202Tcg2ExtractConfig (\r
c411b485
MK
203 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
204 IN CONST EFI_STRING Request,\r
205 OUT EFI_STRING *Progress,\r
206 OUT EFI_STRING *Results\r
1abfa4ce
JY
207 )\r
208{\r
c411b485 209 if ((Progress == NULL) || (Results == NULL)) {\r
1abfa4ce
JY
210 return EFI_INVALID_PARAMETER;\r
211 }\r
212\r
213 *Progress = Request;\r
214 return EFI_NOT_FOUND;\r
215}\r
216\r
217/**\r
218 Save TPM request to variable space.\r
219\r
220 @param[in] PpRequest Physical Presence request command.\r
221\r
222 @retval EFI_SUCCESS The operation is finished successfully.\r
223 @retval Others Other errors as indicated.\r
224\r
225**/\r
226EFI_STATUS\r
227SaveTcg2PpRequest (\r
c411b485 228 IN UINT8 PpRequest\r
1abfa4ce
JY
229 )\r
230{\r
231 UINT32 ReturnCode;\r
232 EFI_STATUS Status;\r
233\r
234 ReturnCode = Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (PpRequest, 0);\r
235 if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {\r
236 mCurrentPpRequest = PpRequest;\r
c411b485 237 Status = EFI_SUCCESS;\r
1abfa4ce
JY
238 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE) {\r
239 Status = EFI_OUT_OF_RESOURCES;\r
240 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED) {\r
241 Status = EFI_UNSUPPORTED;\r
242 } else {\r
243 Status = EFI_DEVICE_ERROR;\r
244 }\r
245\r
246 return Status;\r
247}\r
248\r
249/**\r
250 Save TPM request to variable space.\r
251\r
252 @param[in] PpRequestParameter Physical Presence request parameter.\r
253\r
254 @retval EFI_SUCCESS The operation is finished successfully.\r
255 @retval Others Other errors as indicated.\r
256\r
257**/\r
258EFI_STATUS\r
259SaveTcg2PpRequestParameter (\r
c411b485 260 IN UINT32 PpRequestParameter\r
1abfa4ce
JY
261 )\r
262{\r
263 UINT32 ReturnCode;\r
264 EFI_STATUS Status;\r
265\r
266 ReturnCode = Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (mCurrentPpRequest, PpRequestParameter);\r
267 if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {\r
268 Status = EFI_SUCCESS;\r
269 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE) {\r
270 Status = EFI_OUT_OF_RESOURCES;\r
271 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED) {\r
272 Status = EFI_UNSUPPORTED;\r
273 } else {\r
274 Status = EFI_DEVICE_ERROR;\r
275 }\r
276\r
277 return Status;\r
278}\r
279\r
280/**\r
281 Save Tcg2 PCR Banks request request to variable space.\r
282\r
283 @param[in] PCRBankIndex PCR Bank Index.\r
284 @param[in] Enable Enable or disable this PCR Bank.\r
285\r
286 @retval EFI_SUCCESS The operation is finished successfully.\r
287 @retval Others Other errors as indicated.\r
288\r
289**/\r
290EFI_STATUS\r
291SaveTcg2PCRBanksRequest (\r
c411b485
MK
292 IN UINTN PCRBankIndex,\r
293 IN BOOLEAN Enable\r
1abfa4ce
JY
294 )\r
295{\r
296 UINT32 ReturnCode;\r
297 EFI_STATUS Status;\r
298\r
299 if (Enable) {\r
300 mTcg2ConfigPrivateDate->PCRBanksDesired |= (0x1 << PCRBankIndex);\r
301 } else {\r
302 mTcg2ConfigPrivateDate->PCRBanksDesired &= ~(0x1 << PCRBankIndex);\r
303 }\r
b3548d32 304\r
1abfa4ce
JY
305 ReturnCode = Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (TCG2_PHYSICAL_PRESENCE_SET_PCR_BANKS, mTcg2ConfigPrivateDate->PCRBanksDesired);\r
306 if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS) {\r
307 Status = EFI_SUCCESS;\r
308 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE) {\r
309 Status = EFI_OUT_OF_RESOURCES;\r
310 } else if (ReturnCode == TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED) {\r
311 Status = EFI_UNSUPPORTED;\r
312 } else {\r
313 Status = EFI_DEVICE_ERROR;\r
314 }\r
315\r
316 return Status;\r
317}\r
318\r
319/**\r
320 This function processes the results of changes in configuration.\r
321\r
322 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
323 @param[in] Configuration A null-terminated Unicode string in <ConfigResp>\r
324 format.\r
325 @param[out] Progress A pointer to a string filled in with the offset of\r
326 the most recent '&' before the first failing\r
327 name/value pair (or the beginning of the string if\r
328 the failure is in the first name/value pair) or\r
329 the terminating NULL if all was successful.\r
330\r
331 @retval EFI_SUCCESS The Results is processed successfully.\r
332 @retval EFI_INVALID_PARAMETER Configuration is NULL.\r
333 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this\r
334 driver.\r
335\r
336**/\r
337EFI_STATUS\r
338EFIAPI\r
339Tcg2RouteConfig (\r
c411b485
MK
340 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
341 IN CONST EFI_STRING Configuration,\r
342 OUT EFI_STRING *Progress\r
1abfa4ce
JY
343 )\r
344{\r
c411b485 345 if ((Configuration == NULL) || (Progress == NULL)) {\r
1abfa4ce
JY
346 return EFI_INVALID_PARAMETER;\r
347 }\r
348\r
efa5343a
TP
349 *Progress = Configuration;\r
350\r
1abfa4ce
JY
351 return EFI_NOT_FOUND;\r
352}\r
353\r
a6e0e994
ZC
354/**\r
355 Get HID string of TPM2 ACPI device object\r
356\r
3304abc1 357 @param[in] Hid Points to HID String Buffer.\r
a6e0e994
ZC
358 @param[in] Size HID String size in bytes. Must >= TPM_HID_ACPI_SIZE\r
359\r
360 @return HID String get status.\r
361\r
362**/\r
363EFI_STATUS\r
c411b485
MK
364GetTpm2HID (\r
365 CHAR8 *Hid,\r
366 UINTN Size\r
a6e0e994
ZC
367 )\r
368{\r
369 EFI_STATUS Status;\r
370 UINT32 ManufacturerID;\r
371 UINT32 FirmwareVersion1;\r
372 UINT32 FirmwareVersion2;\r
373 BOOLEAN PnpHID;\r
374\r
375 PnpHID = TRUE;\r
376\r
c411b485 377 ZeroMem (Hid, Size);\r
a6e0e994
ZC
378\r
379 //\r
380 // Get Manufacturer ID\r
381 //\r
c411b485
MK
382 Status = Tpm2GetCapabilityManufactureID (&ManufacturerID);\r
383 if (!EFI_ERROR (Status)) {\r
384 DEBUG ((DEBUG_INFO, "TPM_PT_MANUFACTURER 0x%08x\n", ManufacturerID));\r
a6e0e994
ZC
385 //\r
386 // ManufacturerID defined in TCG Vendor ID Registry\r
387 // may tailed with 0x00 or 0x20\r
388 //\r
c411b485 389 if (((ManufacturerID >> 24) == 0x00) || ((ManufacturerID >> 24) == 0x20)) {\r
a6e0e994
ZC
390 //\r
391 // HID containing PNP ID "NNN####"\r
392 // NNN is uppercase letter for Vendor ID specified by manufacturer\r
393 //\r
c411b485 394 CopyMem (Hid, &ManufacturerID, 3);\r
a6e0e994
ZC
395 } else {\r
396 //\r
397 // HID containing ACP ID "NNNN####"\r
398 // NNNN is uppercase letter for Vendor ID specified by manufacturer\r
399 //\r
c411b485 400 CopyMem (Hid, &ManufacturerID, 4);\r
a6e0e994
ZC
401 PnpHID = FALSE;\r
402 }\r
403 } else {\r
404 DEBUG ((DEBUG_ERROR, "Get TPM_PT_MANUFACTURER failed %x!\n", Status));\r
c411b485 405 ASSERT (FALSE);\r
a6e0e994
ZC
406 return Status;\r
407 }\r
408\r
c411b485
MK
409 Status = Tpm2GetCapabilityFirmwareVersion (&FirmwareVersion1, &FirmwareVersion2);\r
410 if (!EFI_ERROR (Status)) {\r
411 DEBUG ((DEBUG_INFO, "TPM_PT_FIRMWARE_VERSION_1 0x%x\n", FirmwareVersion1));\r
412 DEBUG ((DEBUG_INFO, "TPM_PT_FIRMWARE_VERSION_2 0x%x\n", FirmwareVersion2));\r
a6e0e994
ZC
413 //\r
414 // #### is Firmware Version 1\r
415 //\r
416 if (PnpHID) {\r
c411b485 417 AsciiSPrint (Hid + 3, TPM_HID_PNP_SIZE - 3, "%02d%02d", ((FirmwareVersion1 & 0xFFFF0000) >> 16), (FirmwareVersion1 & 0x0000FFFF));\r
a6e0e994 418 } else {\r
c411b485 419 AsciiSPrint (Hid + 4, TPM_HID_ACPI_SIZE - 4, "%02d%02d", ((FirmwareVersion1 & 0xFFFF0000) >> 16), (FirmwareVersion1 & 0x0000FFFF));\r
a6e0e994 420 }\r
a6e0e994
ZC
421 } else {\r
422 DEBUG ((DEBUG_ERROR, "Get TPM_PT_FIRMWARE_VERSION_X failed %x!\n", Status));\r
c411b485 423 ASSERT (FALSE);\r
a6e0e994
ZC
424 return Status;\r
425 }\r
426\r
427 return EFI_SUCCESS;\r
428}\r
429\r
dd6d0a52
SZ
430/**\r
431 This function processes the results of changes in configuration\r
432 for TCG2 version information.\r
433\r
434 @param[in] Action Specifies the type of action taken by the browser.\r
435 ASSERT if the Action is not EFI_BROWSER_ACTION_SUBMITTED.\r
436 @param[in] QuestionId A unique value which is sent to the original\r
437 exporting driver so that it can identify the type\r
438 of data to expect.\r
439 @param[in] Type The type of value for the question.\r
440 @param[in] Value A pointer to the data being sent to the original\r
441 exporting driver.\r
442\r
443 @retval EFI_SUCCESS The callback successfully handled the action.\r
444\r
445**/\r
446EFI_STATUS\r
447Tcg2VersionInfoCallback (\r
c411b485
MK
448 IN EFI_BROWSER_ACTION Action,\r
449 IN EFI_QUESTION_ID QuestionId,\r
450 IN UINT8 Type,\r
451 IN EFI_IFR_TYPE_VALUE *Value\r
dd6d0a52
SZ
452 )\r
453{\r
c411b485
MK
454 EFI_INPUT_KEY Key;\r
455 UINT64 PcdTcg2PpiVersion;\r
456 UINT8 PcdTpm2AcpiTableRev;\r
dd6d0a52
SZ
457\r
458 ASSERT (Action == EFI_BROWSER_ACTION_SUBMITTED);\r
459\r
460 if (QuestionId == KEY_TCG2_PPI_VERSION) {\r
461 //\r
462 // Get the PCD value after EFI_BROWSER_ACTION_SUBMITTED,\r
463 // the SetVariable to TCG2_VERSION_NAME should have been done.\r
464 // If the PCD value is not equal to the value set to variable,\r
13383485 465 // the PCD is not DynamicHii type and does not map to the setup option.\r
dd6d0a52
SZ
466 //\r
467 PcdTcg2PpiVersion = 0;\r
468 CopyMem (\r
469 &PcdTcg2PpiVersion,\r
470 PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer),\r
c411b485 471 AsciiStrSize ((CHAR8 *)PcdGetPtr (PcdTcgPhysicalPresenceInterfaceVer))\r
dd6d0a52
SZ
472 );\r
473 if (PcdTcg2PpiVersion != Value->u64) {\r
474 CreatePopUp (\r
475 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
476 &Key,\r
13383485 477 L"WARNING: PcdTcgPhysicalPresenceInterfaceVer is not DynamicHii type and does not map to this option!",\r
dd6d0a52
SZ
478 L"The version configuring by this setup option will not work!",\r
479 NULL\r
480 );\r
481 }\r
c411b485 482 } else if (QuestionId == KEY_TPM2_ACPI_REVISION) {\r
fca42289
ZC
483 //\r
484 // Get the PCD value after EFI_BROWSER_ACTION_SUBMITTED,\r
485 // the SetVariable to TCG2_VERSION_NAME should have been done.\r
486 // If the PCD value is not equal to the value set to variable,\r
487 // the PCD is not DynamicHii type and does not map to the setup option.\r
488 //\r
489 PcdTpm2AcpiTableRev = PcdGet8 (PcdTpm2AcpiTableRev);\r
490\r
491 if (PcdTpm2AcpiTableRev != Value->u8) {\r
492 CreatePopUp (\r
493 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
494 &Key,\r
495 L"WARNING: PcdTpm2AcpiTableRev is not DynamicHii type and does not map to this option!",\r
496 L"The Revision configuring by this setup option will not work!",\r
497 NULL\r
498 );\r
499 }\r
dd6d0a52
SZ
500 }\r
501\r
502 return EFI_SUCCESS;\r
503}\r
504\r
1abfa4ce
JY
505/**\r
506 This function processes the results of changes in configuration.\r
507\r
508 @param[in] This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.\r
509 @param[in] Action Specifies the type of action taken by the browser.\r
510 @param[in] QuestionId A unique value which is sent to the original\r
511 exporting driver so that it can identify the type\r
512 of data to expect.\r
513 @param[in] Type The type of value for the question.\r
514 @param[in] Value A pointer to the data being sent to the original\r
515 exporting driver.\r
516 @param[out] ActionRequest On return, points to the action requested by the\r
517 callback function.\r
518\r
519 @retval EFI_SUCCESS The callback successfully handled the action.\r
520 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the\r
521 variable and its data.\r
522 @retval EFI_DEVICE_ERROR The variable could not be saved.\r
523 @retval EFI_UNSUPPORTED The specified Action is not supported by the\r
524 callback.\r
525\r
526**/\r
527EFI_STATUS\r
528EFIAPI\r
529Tcg2Callback (\r
c411b485
MK
530 IN CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,\r
531 IN EFI_BROWSER_ACTION Action,\r
532 IN EFI_QUESTION_ID QuestionId,\r
533 IN UINT8 Type,\r
534 IN EFI_IFR_TYPE_VALUE *Value,\r
535 OUT EFI_BROWSER_ACTION_REQUEST *ActionRequest\r
1abfa4ce
JY
536 )\r
537{\r
c411b485
MK
538 EFI_STATUS Status;\r
539 EFI_INPUT_KEY Key;\r
540 CHAR8 HidStr[16];\r
541 CHAR16 UnHidStr[16];\r
542 TCG2_CONFIG_PRIVATE_DATA *Private;\r
518b6f65 543\r
1abfa4ce
JY
544 if ((This == NULL) || (Value == NULL) || (ActionRequest == NULL)) {\r
545 return EFI_INVALID_PARAMETER;\r
546 }\r
518b6f65 547\r
a6e0e994
ZC
548 Private = TCG2_CONFIG_PRIVATE_DATA_FROM_THIS (This);\r
549\r
550 if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {\r
551 //\r
552 // Update TPM2 HID info\r
553 //\r
554 if (QuestionId == KEY_TPM_DEVICE) {\r
c411b485 555 Status = GetTpm2HID (HidStr, 16);\r
a6e0e994 556\r
c411b485 557 if (EFI_ERROR (Status)) {\r
a6e0e994
ZC
558 //\r
559 // Fail to get TPM2 HID\r
560 //\r
561 HiiSetString (Private->HiiHandle, STRING_TOKEN (STR_TPM2_ACPI_HID_CONTENT), L"Unknown", NULL);\r
562 } else {\r
c411b485 563 AsciiStrToUnicodeStrS (HidStr, UnHidStr, 16);\r
a6e0e994
ZC
564 HiiSetString (Private->HiiHandle, STRING_TOKEN (STR_TPM2_ACPI_HID_CONTENT), UnHidStr, NULL);\r
565 }\r
566 }\r
c411b485 567\r
a6e0e994
ZC
568 return EFI_SUCCESS;\r
569 }\r
570\r
518b6f65
JY
571 if (Action == EFI_BROWSER_ACTION_CHANGING) {\r
572 if (QuestionId == KEY_TPM_DEVICE_INTERFACE) {\r
c411b485 573 Status = SetPtpInterface ((VOID *)(UINTN)PcdGet64 (PcdTpmBaseAddress), Value->u8);\r
518b6f65
JY
574 if (EFI_ERROR (Status)) {\r
575 CreatePopUp (\r
576 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
577 &Key,\r
578 L"Error: Fail to set PTP interface!",\r
579 NULL\r
580 );\r
581 return EFI_DEVICE_ERROR;\r
582 }\r
583 }\r
584 }\r
b3548d32 585\r
1abfa4ce
JY
586 if (Action == EFI_BROWSER_ACTION_CHANGED) {\r
587 if (QuestionId == KEY_TPM_DEVICE) {\r
588 return EFI_SUCCESS;\r
589 }\r
c411b485 590\r
1abfa4ce
JY
591 if (QuestionId == KEY_TPM2_OPERATION) {\r
592 return SaveTcg2PpRequest (Value->u8);\r
593 }\r
c411b485 594\r
1abfa4ce
JY
595 if (QuestionId == KEY_TPM2_OPERATION_PARAMETER) {\r
596 return SaveTcg2PpRequestParameter (Value->u32);\r
597 }\r
c411b485 598\r
1abfa4ce 599 if ((QuestionId >= KEY_TPM2_PCR_BANKS_REQUEST_0) && (QuestionId <= KEY_TPM2_PCR_BANKS_REQUEST_4)) {\r
dd6d0a52
SZ
600 return SaveTcg2PCRBanksRequest (QuestionId - KEY_TPM2_PCR_BANKS_REQUEST_0, Value->b);\r
601 }\r
602 }\r
603\r
604 if (Action == EFI_BROWSER_ACTION_SUBMITTED) {\r
c411b485 605 if ((QuestionId == KEY_TCG2_PPI_VERSION) || (QuestionId == KEY_TPM2_ACPI_REVISION)) {\r
dd6d0a52 606 return Tcg2VersionInfoCallback (Action, QuestionId, Type, Value);\r
1abfa4ce
JY
607 }\r
608 }\r
609\r
610 return EFI_UNSUPPORTED;\r
611}\r
612\r
613/**\r
614 Append Buffer With TpmAlgHash.\r
615\r
616 @param[in] Buffer Buffer to be appended.\r
617 @param[in] BufferSize Size of buffer.\r
618 @param[in] TpmAlgHash TpmAlgHash.\r
619\r
620**/\r
621VOID\r
622AppendBufferWithTpmAlgHash (\r
623 IN UINT16 *Buffer,\r
624 IN UINTN BufferSize,\r
625 IN UINT32 TpmAlgHash\r
626 )\r
627{\r
628 switch (TpmAlgHash) {\r
c411b485
MK
629 case TPM_ALG_SHA1:\r
630 if (Buffer[0] != 0) {\r
631 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
632 }\r
633\r
634 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA1");\r
635 break;\r
636 case TPM_ALG_SHA256:\r
637 if (Buffer[0] != 0) {\r
638 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
639 }\r
640\r
641 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA256");\r
642 break;\r
643 case TPM_ALG_SHA384:\r
644 if (Buffer[0] != 0) {\r
645 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
646 }\r
647\r
648 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA384");\r
649 break;\r
650 case TPM_ALG_SHA512:\r
651 if (Buffer[0] != 0) {\r
652 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
653 }\r
654\r
655 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA512");\r
656 break;\r
657 case TPM_ALG_SM3_256:\r
658 if (Buffer[0] != 0) {\r
659 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
660 }\r
661\r
662 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SM3_256");\r
663 break;\r
1abfa4ce
JY
664 }\r
665}\r
666\r
667/**\r
668 Fill Buffer With BootHashAlg.\r
669\r
670 @param[in] Buffer Buffer to be filled.\r
671 @param[in] BufferSize Size of buffer.\r
672 @param[in] BootHashAlg BootHashAlg.\r
673\r
674**/\r
675VOID\r
676FillBufferWithBootHashAlg (\r
677 IN UINT16 *Buffer,\r
678 IN UINTN BufferSize,\r
679 IN UINT32 BootHashAlg\r
680 )\r
681{\r
682 Buffer[0] = 0;\r
683 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SHA1) != 0) {\r
684 if (Buffer[0] != 0) {\r
d2e8af97 685 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 686 }\r
c411b485 687\r
d2e8af97 688 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA1");\r
1abfa4ce 689 }\r
c411b485 690\r
1abfa4ce
JY
691 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SHA256) != 0) {\r
692 if (Buffer[0] != 0) {\r
d2e8af97 693 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 694 }\r
c411b485 695\r
d2e8af97 696 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA256");\r
1abfa4ce 697 }\r
c411b485 698\r
1abfa4ce
JY
699 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SHA384) != 0) {\r
700 if (Buffer[0] != 0) {\r
d2e8af97 701 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 702 }\r
c411b485 703\r
d2e8af97 704 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA384");\r
1abfa4ce 705 }\r
c411b485 706\r
1abfa4ce
JY
707 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SHA512) != 0) {\r
708 if (Buffer[0] != 0) {\r
d2e8af97 709 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 710 }\r
c411b485 711\r
d2e8af97 712 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SHA512");\r
1abfa4ce 713 }\r
c411b485 714\r
1abfa4ce
JY
715 if ((BootHashAlg & EFI_TCG2_BOOT_HASH_ALG_SM3_256) != 0) {\r
716 if (Buffer[0] != 0) {\r
d2e8af97 717 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 718 }\r
c411b485 719\r
d2e8af97 720 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"SM3_256");\r
1abfa4ce
JY
721 }\r
722}\r
723\r
c41eeb44
JY
724/**\r
725 Set ConfigInfo according to TpmAlgHash.\r
726\r
727 @param[in,out] Tcg2ConfigInfo TCG2 config info.\r
728 @param[in] TpmAlgHash TpmAlgHash.\r
729\r
730**/\r
731VOID\r
732SetConfigInfo (\r
c411b485
MK
733 IN OUT TCG2_CONFIGURATION_INFO *Tcg2ConfigInfo,\r
734 IN UINT32 TpmAlgHash\r
c41eeb44
JY
735 )\r
736{\r
737 switch (TpmAlgHash) {\r
c411b485
MK
738 case TPM_ALG_SHA1:\r
739 Tcg2ConfigInfo->Sha1Supported = TRUE;\r
740 break;\r
741 case TPM_ALG_SHA256:\r
742 Tcg2ConfigInfo->Sha256Supported = TRUE;\r
743 break;\r
744 case TPM_ALG_SHA384:\r
745 Tcg2ConfigInfo->Sha384Supported = TRUE;\r
746 break;\r
747 case TPM_ALG_SHA512:\r
748 Tcg2ConfigInfo->Sha512Supported = TRUE;\r
749 break;\r
750 case TPM_ALG_SM3_256:\r
751 Tcg2ConfigInfo->Sm3Supported = TRUE;\r
752 break;\r
c41eeb44
JY
753 }\r
754}\r
755\r
1abfa4ce
JY
756/**\r
757 Fill Buffer With TCG2EventLogFormat.\r
758\r
759 @param[in] Buffer Buffer to be filled.\r
760 @param[in] BufferSize Size of buffer.\r
761 @param[in] TCG2EventLogFormat TCG2EventLogFormat.\r
762\r
763**/\r
764VOID\r
765FillBufferWithTCG2EventLogFormat (\r
766 IN UINT16 *Buffer,\r
767 IN UINTN BufferSize,\r
768 IN UINT32 TCG2EventLogFormat\r
769 )\r
770{\r
771 Buffer[0] = 0;\r
772 if ((TCG2EventLogFormat & EFI_TCG2_EVENT_LOG_FORMAT_TCG_1_2) != 0) {\r
773 if (Buffer[0] != 0) {\r
d2e8af97 774 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 775 }\r
c411b485 776\r
d2e8af97 777 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"TCG_1_2");\r
1abfa4ce 778 }\r
c411b485 779\r
1abfa4ce
JY
780 if ((TCG2EventLogFormat & EFI_TCG2_EVENT_LOG_FORMAT_TCG_2) != 0) {\r
781 if (Buffer[0] != 0) {\r
d2e8af97 782 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 783 }\r
c411b485 784\r
d2e8af97 785 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"TCG_2");\r
1abfa4ce 786 }\r
c411b485 787\r
1abfa4ce
JY
788 if ((TCG2EventLogFormat & (~EFI_TCG2_EVENT_LOG_FORMAT_ALL)) != 0) {\r
789 if (Buffer[0] != 0) {\r
d2e8af97 790 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L", ");\r
1abfa4ce 791 }\r
c411b485 792\r
d2e8af97 793 StrCatS (Buffer, BufferSize / sizeof (CHAR16), L"UNKNOWN");\r
1abfa4ce
JY
794 }\r
795}\r
796\r
1abfa4ce
JY
797/**\r
798 This function publish the TCG2 configuration Form for TPM device.\r
799\r
800 @param[in, out] PrivateData Points to TCG2 configuration private data.\r
801\r
802 @retval EFI_SUCCESS HII Form is installed for this network device.\r
803 @retval EFI_OUT_OF_RESOURCES Not enough resource for HII Form installation.\r
804 @retval Others Other errors as indicated.\r
805\r
806**/\r
807EFI_STATUS\r
808InstallTcg2ConfigForm (\r
809 IN OUT TCG2_CONFIG_PRIVATE_DATA *PrivateData\r
810 )\r
811{\r
812 EFI_STATUS Status;\r
813 EFI_HII_HANDLE HiiHandle;\r
814 EFI_HANDLE DriverHandle;\r
815 EFI_HII_CONFIG_ACCESS_PROTOCOL *ConfigAccess;\r
816 UINTN Index;\r
817 TPML_PCR_SELECTION Pcrs;\r
818 CHAR16 TempBuffer[1024];\r
c41eeb44 819 TCG2_CONFIGURATION_INFO Tcg2ConfigInfo;\r
f15cb995 820 TPM2_PTP_INTERFACE_TYPE TpmDeviceInterfaceDetected;\r
3887820e 821 BOOLEAN IsCmdImp = FALSE;\r
1abfa4ce
JY
822\r
823 DriverHandle = NULL;\r
824 ConfigAccess = &PrivateData->ConfigAccess;\r
c411b485
MK
825 Status = gBS->InstallMultipleProtocolInterfaces (\r
826 &DriverHandle,\r
827 &gEfiDevicePathProtocolGuid,\r
828 &mTcg2HiiVendorDevicePath,\r
829 &gEfiHiiConfigAccessProtocolGuid,\r
830 ConfigAccess,\r
831 NULL\r
832 );\r
1abfa4ce
JY
833 if (EFI_ERROR (Status)) {\r
834 return Status;\r
835 }\r
836\r
837 PrivateData->DriverHandle = DriverHandle;\r
838\r
839 //\r
840 // Publish the HII package list\r
841 //\r
842 HiiHandle = HiiAddPackages (\r
843 &gTcg2ConfigFormSetGuid,\r
844 DriverHandle,\r
845 Tcg2ConfigDxeStrings,\r
846 Tcg2ConfigBin,\r
847 NULL\r
848 );\r
849 if (HiiHandle == NULL) {\r
850 gBS->UninstallMultipleProtocolInterfaces (\r
851 DriverHandle,\r
852 &gEfiDevicePathProtocolGuid,\r
853 &mTcg2HiiVendorDevicePath,\r
854 &gEfiHiiConfigAccessProtocolGuid,\r
855 ConfigAccess,\r
856 NULL\r
b3548d32 857 );\r
1abfa4ce
JY
858\r
859 return EFI_OUT_OF_RESOURCES;\r
860 }\r
b3548d32 861\r
1abfa4ce
JY
862 PrivateData->HiiHandle = HiiHandle;\r
863\r
864 //\r
865 // Update static data\r
866 //\r
867 switch (PrivateData->TpmDeviceDetected) {\r
c411b485
MK
868 case TPM_DEVICE_NULL:\r
869 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT), L"Not Found", NULL);\r
870 break;\r
871 case TPM_DEVICE_1_2:\r
872 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT), L"TPM 1.2", NULL);\r
873 break;\r
874 case TPM_DEVICE_2_0_DTPM:\r
875 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT), L"TPM 2.0", NULL);\r
876 break;\r
877 default:\r
878 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_STATE_CONTENT), L"Unknown", NULL);\r
879 break;\r
880 }\r
881\r
882 ZeroMem (&Tcg2ConfigInfo, sizeof (Tcg2ConfigInfo));\r
1abfa4ce
JY
883 Status = Tpm2GetCapabilityPcrs (&Pcrs);\r
884 if (EFI_ERROR (Status)) {\r
885 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT), L"[Unknown]", NULL);\r
886 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT), L"[Unknown]", NULL);\r
887 } else {\r
888 TempBuffer[0] = 0;\r
889 for (Index = 0; Index < Pcrs.count; Index++) {\r
72388f9c 890 if (!IsZeroBuffer (Pcrs.pcrSelections[Index].pcrSelect, Pcrs.pcrSelections[Index].sizeofSelect)) {\r
c411b485 891 AppendBufferWithTpmAlgHash (TempBuffer, sizeof (TempBuffer), Pcrs.pcrSelections[Index].hash);\r
1abfa4ce
JY
892 }\r
893 }\r
c411b485 894\r
1abfa4ce
JY
895 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM2_ACTIVE_HASH_ALGO_CONTENT), TempBuffer, NULL);\r
896\r
897 TempBuffer[0] = 0;\r
898 for (Index = 0; Index < Pcrs.count; Index++) {\r
c411b485 899 AppendBufferWithTpmAlgHash (TempBuffer, sizeof (TempBuffer), Pcrs.pcrSelections[Index].hash);\r
c41eeb44 900 SetConfigInfo (&Tcg2ConfigInfo, Pcrs.pcrSelections[Index].hash);\r
1abfa4ce 901 }\r
c411b485 902\r
1abfa4ce
JY
903 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TPM2_SUPPORTED_HASH_ALGO_CONTENT), TempBuffer, NULL);\r
904 }\r
905\r
3887820e
QZ
906 Status = Tpm2GetCapabilityIsCommandImplemented (TPM_CC_ChangeEPS, &IsCmdImp);\r
907 if (EFI_ERROR (Status)) {\r
908 DEBUG ((DEBUG_ERROR, "Tpm2GetCapabilityIsCmdImpl fails %r\n", Status));\r
909 }\r
c411b485 910\r
3887820e
QZ
911 Tcg2ConfigInfo.ChangeEPSSupported = IsCmdImp;\r
912\r
c411b485 913 FillBufferWithBootHashAlg (TempBuffer, sizeof (TempBuffer), PcdGet32 (PcdTcg2HashAlgorithmBitmap));\r
1abfa4ce
JY
914 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_BIOS_HASH_ALGO_CONTENT), TempBuffer, NULL);\r
915\r
916 //\r
917 // Tcg2 Capability\r
918 //\r
c411b485 919 FillBufferWithTCG2EventLogFormat (TempBuffer, sizeof (TempBuffer), PrivateData->ProtocolCapability.SupportedEventLogs);\r
1abfa4ce
JY
920 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_SUPPORTED_EVENT_LOG_FORMAT_CONTENT), TempBuffer, NULL);\r
921\r
c411b485 922 FillBufferWithBootHashAlg (TempBuffer, sizeof (TempBuffer), PrivateData->ProtocolCapability.HashAlgorithmBitmap);\r
1abfa4ce
JY
923 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_HASH_ALGO_BITMAP_CONTENT), TempBuffer, NULL);\r
924\r
925 UnicodeSPrint (TempBuffer, sizeof (TempBuffer), L"%d", PrivateData->ProtocolCapability.NumberOfPCRBanks);\r
926 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_NUMBER_OF_PCR_BANKS_CONTENT), TempBuffer, NULL);\r
927\r
c411b485 928 FillBufferWithBootHashAlg (TempBuffer, sizeof (TempBuffer), PrivateData->ProtocolCapability.ActivePcrBanks);\r
1abfa4ce
JY
929 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_ACTIVE_PCR_BANKS_CONTENT), TempBuffer, NULL);\r
930\r
518b6f65
JY
931 //\r
932 // Update TPM device interface type\r
933 //\r
934 if (PrivateData->TpmDeviceDetected == TPM_DEVICE_2_0_DTPM) {\r
c411b485 935 TpmDeviceInterfaceDetected = PcdGet8 (PcdActiveTpmInterfaceType);\r
518b6f65 936 switch (TpmDeviceInterfaceDetected) {\r
c411b485
MK
937 case Tpm2PtpInterfaceTis:\r
938 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT), L"TIS", NULL);\r
939 break;\r
940 case Tpm2PtpInterfaceFifo:\r
941 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT), L"PTP FIFO", NULL);\r
942 break;\r
943 case Tpm2PtpInterfaceCrb:\r
944 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT), L"PTP CRB", NULL);\r
945 break;\r
946 default:\r
947 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_STATE_CONTENT), L"Unknown", NULL);\r
948 break;\r
518b6f65
JY
949 }\r
950\r
951 Tcg2ConfigInfo.TpmDeviceInterfaceAttempt = TpmDeviceInterfaceDetected;\r
952 switch (TpmDeviceInterfaceDetected) {\r
c411b485
MK
953 case Tpm2PtpInterfaceTis:\r
954 Tcg2ConfigInfo.TpmDeviceInterfacePtpFifoSupported = FALSE;\r
955 Tcg2ConfigInfo.TpmDeviceInterfacePtpCrbSupported = FALSE;\r
956 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT), L"TIS", NULL);\r
957 break;\r
958 case Tpm2PtpInterfaceFifo:\r
959 case Tpm2PtpInterfaceCrb:\r
960 Tcg2ConfigInfo.TpmDeviceInterfacePtpFifoSupported = IsPtpFifoSupported ((VOID *)(UINTN)PcdGet64 (PcdTpmBaseAddress));\r
961 Tcg2ConfigInfo.TpmDeviceInterfacePtpCrbSupported = IsPtpCrbSupported ((VOID *)(UINTN)PcdGet64 (PcdTpmBaseAddress));\r
962 TempBuffer[0] = 0;\r
963 if (Tcg2ConfigInfo.TpmDeviceInterfacePtpFifoSupported) {\r
964 if (TempBuffer[0] != 0) {\r
965 StrCatS (TempBuffer, sizeof (TempBuffer) / sizeof (CHAR16), L", ");\r
966 }\r
967\r
968 StrCatS (TempBuffer, sizeof (TempBuffer) / sizeof (CHAR16), L"PTP FIFO");\r
518b6f65 969 }\r
c411b485
MK
970\r
971 if (Tcg2ConfigInfo.TpmDeviceInterfacePtpCrbSupported) {\r
972 if (TempBuffer[0] != 0) {\r
973 StrCatS (TempBuffer, sizeof (TempBuffer) / sizeof (CHAR16), L", ");\r
974 }\r
975\r
976 StrCatS (TempBuffer, sizeof (TempBuffer) / sizeof (CHAR16), L"PTP CRB");\r
518b6f65 977 }\r
c411b485
MK
978\r
979 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT), TempBuffer, NULL);\r
980 break;\r
981 default:\r
982 Tcg2ConfigInfo.TpmDeviceInterfacePtpFifoSupported = FALSE;\r
983 Tcg2ConfigInfo.TpmDeviceInterfacePtpCrbSupported = FALSE;\r
984 HiiSetString (PrivateData->HiiHandle, STRING_TOKEN (STR_TCG2_DEVICE_INTERFACE_CAPABILITY_CONTENT), L"Unknown", NULL);\r
985 break;\r
518b6f65
JY
986 }\r
987 }\r
988\r
c41eeb44
JY
989 //\r
990 // Set ConfigInfo, to control the check box.\r
991 //\r
992 Status = gRT->SetVariable (\r
993 TCG2_STORAGE_INFO_NAME,\r
994 &gTcg2ConfigFormSetGuid,\r
995 EFI_VARIABLE_BOOTSERVICE_ACCESS,\r
c411b485 996 sizeof (Tcg2ConfigInfo),\r
c41eeb44
JY
997 &Tcg2ConfigInfo\r
998 );\r
999 if (EFI_ERROR (Status)) {\r
e905fbb0 1000 DEBUG ((DEBUG_ERROR, "Tcg2ConfigDriver: Fail to set TCG2_STORAGE_INFO_NAME\n"));\r
c41eeb44 1001 }\r
fca42289 1002\r
b3548d32 1003 return EFI_SUCCESS;\r
1abfa4ce
JY
1004}\r
1005\r
1006/**\r
1007 This function removes TCG2 configuration Form.\r
1008\r
1009 @param[in, out] PrivateData Points to TCG2 configuration private data.\r
1010\r
1011**/\r
1012VOID\r
1013UninstallTcg2ConfigForm (\r
c411b485 1014 IN OUT TCG2_CONFIG_PRIVATE_DATA *PrivateData\r
1abfa4ce
JY
1015 )\r
1016{\r
1017 //\r
1018 // Uninstall HII package list\r
1019 //\r
1020 if (PrivateData->HiiHandle != NULL) {\r
1021 HiiRemovePackages (PrivateData->HiiHandle);\r
1022 PrivateData->HiiHandle = NULL;\r
1023 }\r
1024\r
1025 //\r
1026 // Uninstall HII Config Access Protocol\r
1027 //\r
1028 if (PrivateData->DriverHandle != NULL) {\r
1029 gBS->UninstallMultipleProtocolInterfaces (\r
1030 PrivateData->DriverHandle,\r
1031 &gEfiDevicePathProtocolGuid,\r
1032 &mTcg2HiiVendorDevicePath,\r
1033 &gEfiHiiConfigAccessProtocolGuid,\r
1034 &PrivateData->ConfigAccess,\r
1035 NULL\r
1036 );\r
1037 PrivateData->DriverHandle = NULL;\r
1038 }\r
b3548d32 1039\r
1abfa4ce
JY
1040 FreePool (PrivateData);\r
1041}\r