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