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