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