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