2 Implementation of the HII for the Opal UEFI Driver.
4 Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
11 // Character definitions
13 #define UPPER_LOWER_CASE_OFFSET 0x20
16 // This is the generated IFR binary Data for each formset defined in VFR.
17 // This Data array is ready to be used as input of HiiAddPackages() to
18 // create a packagelist (which contains Form packages, String packages, etc).
20 extern UINT8 OpalPasswordFormBin
[];
23 // This is the generated String package Data for all .UNI files.
24 // This Data array is ready to be used as input of HiiAddPackages() to
25 // create a packagelist (which contains Form packages, String packages, etc).
27 extern UINT8 OpalPasswordDxeStrings
[];
29 CHAR16 OpalPasswordStorageName
[] = L
"OpalHiiConfig";
31 EFI_HII_CONFIG_ACCESS_PROTOCOL gHiiConfigAccessProtocol
;
34 // Handle to the list of HII packages (forms and strings) for this driver
36 EFI_HII_HANDLE gHiiPackageListHandle
= NULL
;
39 // Package List GUID containing all form and string packages
41 const EFI_GUID gHiiPackageListGuid
= PACKAGE_LIST_GUID
;
42 const EFI_GUID gHiiSetupVariableGuid
= SETUP_VARIABLE_GUID
;
45 // Structure that contains state of the HII
46 // This structure is updated by Hii.cpp and its contents
47 // is rendered in the HII.
49 OPAL_HII_CONFIGURATION gHiiConfiguration
;
52 // The device path containing the VENDOR_DEVICE_PATH and EFI_DEVICE_PATH_PROTOCOL
54 HII_VENDOR_DEVICE_PATH gHiiVendorDevicePath
= {
60 (UINT8
)(sizeof(VENDOR_DEVICE_PATH
)),
61 (UINT8
)((sizeof(VENDOR_DEVICE_PATH
)) >> 8)
64 OPAL_PASSWORD_CONFIG_GUID
68 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
70 (UINT8
)(END_DEVICE_PATH_LENGTH
),
71 (UINT8
)((END_DEVICE_PATH_LENGTH
) >> 8)
77 Get saved OPAL request.
79 @param[in] OpalDisk The disk needs to get the saved OPAL request.
80 @param[out] OpalRequest OPAL request got.
85 IN OPAL_DISK
*OpalDisk
,
86 OUT OPAL_REQUEST
*OpalRequest
90 OPAL_REQUEST_VARIABLE
*TempVariable
;
91 OPAL_REQUEST_VARIABLE
*Variable
;
93 EFI_DEVICE_PATH_PROTOCOL
*DevicePathInVariable
;
94 UINTN DevicePathSizeInVariable
;
95 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
98 DEBUG ((DEBUG_INFO
, "%a() - enter\n", __FUNCTION__
));
103 Status
= GetVariable2 (
104 OPAL_REQUEST_VARIABLE_NAME
,
105 &gHiiSetupVariableGuid
,
109 if (EFI_ERROR (Status
) || (Variable
== NULL
)) {
113 TempVariable
= Variable
;
114 while ((VariableSize
> sizeof (OPAL_REQUEST_VARIABLE
)) &&
115 (VariableSize
>= TempVariable
->Length
) &&
116 (TempVariable
->Length
> sizeof (OPAL_REQUEST_VARIABLE
))) {
117 DevicePathInVariable
= (EFI_DEVICE_PATH_PROTOCOL
*) ((UINTN
) TempVariable
+ sizeof (OPAL_REQUEST_VARIABLE
));
118 DevicePathSizeInVariable
= GetDevicePathSize (DevicePathInVariable
);
119 DevicePath
= OpalDisk
->OpalDevicePath
;
120 DevicePathSize
= GetDevicePathSize (DevicePath
);
121 if ((DevicePathSize
== DevicePathSizeInVariable
) &&
122 (CompareMem (DevicePath
, DevicePathInVariable
, DevicePathSize
) == 0)) {
124 // Found the node for the OPAL device.
125 // Get the OPAL request.
127 CopyMem (OpalRequest
, &TempVariable
->OpalRequest
, sizeof (OPAL_REQUEST
));
130 "OpalRequest got: 0x%x\n",
135 VariableSize
-= TempVariable
->Length
;
136 TempVariable
= (OPAL_REQUEST_VARIABLE
*) ((UINTN
) TempVariable
+ TempVariable
->Length
);
141 DEBUG ((DEBUG_INFO
, "%a() - exit\n", __FUNCTION__
));
147 @param[in] OpalDisk The disk has OPAL request to save.
148 @param[in] OpalRequest OPAL request to save.
153 IN OPAL_DISK
*OpalDisk
,
154 IN OPAL_REQUEST OpalRequest
158 OPAL_REQUEST_VARIABLE
*TempVariable
;
159 UINTN TempVariableSize
;
160 OPAL_REQUEST_VARIABLE
*Variable
;
162 OPAL_REQUEST_VARIABLE
*NewVariable
;
163 UINTN NewVariableSize
;
164 EFI_DEVICE_PATH_PROTOCOL
*DevicePathInVariable
;
165 UINTN DevicePathSizeInVariable
;
166 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
167 UINTN DevicePathSize
;
169 DEBUG ((DEBUG_INFO
, "%a() - enter\n", __FUNCTION__
));
173 "OpalRequest to save: 0x%x\n",
182 Status
= GetVariable2 (
183 OPAL_REQUEST_VARIABLE_NAME
,
184 &gHiiSetupVariableGuid
,
188 if (!EFI_ERROR (Status
) && (Variable
!= NULL
)) {
189 TempVariable
= Variable
;
190 TempVariableSize
= VariableSize
;
191 while ((TempVariableSize
> sizeof (OPAL_REQUEST_VARIABLE
)) &&
192 (TempVariableSize
>= TempVariable
->Length
) &&
193 (TempVariable
->Length
> sizeof (OPAL_REQUEST_VARIABLE
))) {
194 DevicePathInVariable
= (EFI_DEVICE_PATH_PROTOCOL
*) ((UINTN
) TempVariable
+ sizeof (OPAL_REQUEST_VARIABLE
));
195 DevicePathSizeInVariable
= GetDevicePathSize (DevicePathInVariable
);
196 DevicePath
= OpalDisk
->OpalDevicePath
;
197 DevicePathSize
= GetDevicePathSize (DevicePath
);
198 if ((DevicePathSize
== DevicePathSizeInVariable
) &&
199 (CompareMem (DevicePath
, DevicePathInVariable
, DevicePathSize
) == 0)) {
201 // Found the node for the OPAL device.
202 // Update the OPAL request.
204 CopyMem (&TempVariable
->OpalRequest
, &OpalRequest
, sizeof (OPAL_REQUEST
));
205 NewVariable
= Variable
;
206 NewVariableSize
= VariableSize
;
209 TempVariableSize
-= TempVariable
->Length
;
210 TempVariable
= (OPAL_REQUEST_VARIABLE
*) ((UINTN
) TempVariable
+ TempVariable
->Length
);
212 if (NewVariable
== NULL
) {
214 // The node for the OPAL device is not found.
215 // Create node for the OPAL device.
217 DevicePath
= OpalDisk
->OpalDevicePath
;
218 DevicePathSize
= GetDevicePathSize (DevicePath
);
219 NewVariableSize
= VariableSize
+ sizeof (OPAL_REQUEST_VARIABLE
) + DevicePathSize
;
220 NewVariable
= AllocatePool (NewVariableSize
);
221 ASSERT (NewVariable
!= NULL
);
222 CopyMem (NewVariable
, Variable
, VariableSize
);
223 TempVariable
= (OPAL_REQUEST_VARIABLE
*) ((UINTN
) NewVariable
+ VariableSize
);
224 TempVariable
->Length
= (UINT32
) (sizeof (OPAL_REQUEST_VARIABLE
) + DevicePathSize
);
225 CopyMem (&TempVariable
->OpalRequest
, &OpalRequest
, sizeof (OPAL_REQUEST
));
226 DevicePathInVariable
= (EFI_DEVICE_PATH_PROTOCOL
*) ((UINTN
) TempVariable
+ sizeof (OPAL_REQUEST_VARIABLE
));
227 CopyMem (DevicePathInVariable
, DevicePath
, DevicePathSize
);
230 DevicePath
= OpalDisk
->OpalDevicePath
;
231 DevicePathSize
= GetDevicePathSize (DevicePath
);
232 NewVariableSize
= sizeof (OPAL_REQUEST_VARIABLE
) + DevicePathSize
;
233 NewVariable
= AllocatePool (NewVariableSize
);
234 ASSERT (NewVariable
!= NULL
);
235 NewVariable
->Length
= (UINT32
) (sizeof (OPAL_REQUEST_VARIABLE
) + DevicePathSize
);
236 CopyMem (&NewVariable
->OpalRequest
, &OpalRequest
, sizeof (OPAL_REQUEST
));
237 DevicePathInVariable
= (EFI_DEVICE_PATH_PROTOCOL
*) ((UINTN
) NewVariable
+ sizeof (OPAL_REQUEST_VARIABLE
));
238 CopyMem (DevicePathInVariable
, DevicePath
, DevicePathSize
);
240 Status
= gRT
->SetVariable (
241 OPAL_REQUEST_VARIABLE_NAME
,
242 (EFI_GUID
*) &gHiiSetupVariableGuid
,
243 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
247 if (EFI_ERROR (Status
)) {
248 DEBUG ((DEBUG_INFO
, "OpalRequest variable set failed (%r)\n", Status
));
250 if (NewVariable
!= Variable
) {
251 FreePool (NewVariable
);
253 if (Variable
!= NULL
) {
257 DEBUG ((DEBUG_INFO
, "%a() - exit\n", __FUNCTION__
));
261 Sets the current system state of global config variables.
265 HiiSetCurrentConfiguration(
269 UINT32 PpStorageFlag
;
270 EFI_STRING NewString
;
272 gHiiConfiguration
.NumDisks
= GetDeviceCount();
275 // Update the BlockSID status string.
277 PpStorageFlag
= Tcg2PhysicalPresenceLibGetManagementFlags ();
279 if ((PpStorageFlag
& TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_ENABLE_BLOCK_SID
) != 0) {
280 NewString
= HiiGetString (gHiiPackageListHandle
, STRING_TOKEN(STR_ENABLED
), NULL
);
281 if (NewString
== NULL
) {
282 DEBUG ((DEBUG_INFO
, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
286 NewString
= HiiGetString (gHiiPackageListHandle
, STRING_TOKEN(STR_DISABLED
), NULL
);
287 if (NewString
== NULL
) {
288 DEBUG ((DEBUG_INFO
, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
292 HiiSetString(gHiiPackageListHandle
, STRING_TOKEN(STR_BLOCKSID_STATUS1
), NewString
, NULL
);
293 FreePool (NewString
);
295 if ((PpStorageFlag
& TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_ENABLE_BLOCK_SID
) != 0) {
296 NewString
= HiiGetString (gHiiPackageListHandle
, STRING_TOKEN(STR_DISK_INFO_ENABLE_BLOCKSID_TRUE
), NULL
);
297 if (NewString
== NULL
) {
298 DEBUG ((DEBUG_INFO
, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
302 NewString
= HiiGetString (gHiiPackageListHandle
, STRING_TOKEN(STR_DISK_INFO_ENABLE_BLOCKSID_FALSE
), NULL
);
303 if (NewString
== NULL
) {
304 DEBUG ((DEBUG_INFO
, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
308 HiiSetString(gHiiPackageListHandle
, STRING_TOKEN(STR_BLOCKSID_STATUS2
), NewString
, NULL
);
309 FreePool (NewString
);
311 if ((PpStorageFlag
& TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_DISABLE_BLOCK_SID
) != 0) {
312 NewString
= HiiGetString (gHiiPackageListHandle
, STRING_TOKEN(STR_DISK_INFO_DISABLE_BLOCKSID_TRUE
), NULL
);
313 if (NewString
== NULL
) {
314 DEBUG ((DEBUG_INFO
, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
318 NewString
= HiiGetString (gHiiPackageListHandle
, STRING_TOKEN(STR_DISK_INFO_DISABLE_BLOCKSID_FALSE
), NULL
);
319 if (NewString
== NULL
) {
320 DEBUG ((DEBUG_INFO
, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
324 HiiSetString(gHiiPackageListHandle
, STRING_TOKEN(STR_BLOCKSID_STATUS3
), NewString
, NULL
);
325 FreePool (NewString
);
329 Install the HII related resources.
331 @retval EFI_SUCCESS Install all the resources success.
332 @retval other Error occur when install the resources.
340 EFI_HANDLE DriverHandle
;
343 // Clear the global configuration.
345 ZeroMem(&gHiiConfiguration
, sizeof(gHiiConfiguration
));
348 // Obtain the driver handle that the BIOS assigned us
350 DriverHandle
= HiiGetDriverImageHandleCB();
353 // Populate the config access protocol with the three functions we are publishing
355 gHiiConfigAccessProtocol
.ExtractConfig
= ExtractConfig
;
356 gHiiConfigAccessProtocol
.RouteConfig
= RouteConfig
;
357 gHiiConfigAccessProtocol
.Callback
= DriverCallback
;
360 // Associate the required protocols with our driver handle
362 Status
= gBS
->InstallMultipleProtocolInterfaces(
364 &gEfiHiiConfigAccessProtocolGuid
,
365 &gHiiConfigAccessProtocol
, // HII callback
366 &gEfiDevicePathProtocolGuid
,
367 &gHiiVendorDevicePath
, // required for HII callback allow all disks to be shown in same hii
371 if (EFI_ERROR(Status
)) {
375 return OpalHiiAddPackages();
379 Install the HII form and string packages.
381 @retval EFI_SUCCESS Install all the resources success.
382 @retval EFI_OUT_OF_RESOURCES Out of resource error.
389 EFI_HANDLE DriverHandle
;
391 DriverHandle
= HiiGetDriverImageHandleCB();
394 // Publish the HII form and HII string packages
396 gHiiPackageListHandle
= HiiAddPackages(
397 &gHiiPackageListGuid
,
399 OpalPasswordDxeStrings
,
405 // Make sure the packages installed successfully
407 if (gHiiPackageListHandle
== NULL
) {
408 DEBUG ((DEBUG_INFO
, "OpalHiiAddPackages failed\n"));
409 return EFI_OUT_OF_RESOURCES
;
416 Uninstall the HII capability.
418 @retval EFI_SUCCESS Uninstall all the resources success.
419 @retval others Other errors occur when unistall the hii resource.
429 // Remove the packages we've provided to the BIOS
431 HiiRemovePackages(gHiiPackageListHandle
);
434 // Remove the protocols from our driver handle
436 Status
= gBS
->UninstallMultipleProtocolInterfaces(
437 HiiGetDriverImageHandleCB(),
438 &gEfiHiiConfigAccessProtocolGuid
,
439 &gHiiConfigAccessProtocol
, // HII callback
440 &gEfiDevicePathProtocolGuid
,
441 &gHiiVendorDevicePath
, // required for HII callback
444 if (EFI_ERROR(Status
)) {
445 DEBUG ((DEBUG_INFO
, "Cannot uninstall Hii Protocols: %r\n", Status
));
452 Updates the main menu form.
454 @retval EFI_SUCCESS update the main form success.
457 HiiPopulateMainMenuForm (
463 EFI_STRING_ID DiskNameId
;
466 HiiSetCurrentConfiguration();
468 gHiiConfiguration
.SupportedDisks
= 0;
470 for (Index
= 0; Index
< gHiiConfiguration
.NumDisks
; Index
++) {
471 OpalDisk
= HiiGetOpalDiskCB (Index
);
472 if ((OpalDisk
!= NULL
) && OpalFeatureSupported (&OpalDisk
->SupportedAttributes
)) {
473 gHiiConfiguration
.SupportedDisks
|= (1 << Index
);
474 DiskNameId
= GetDiskNameStringId (Index
);
475 DiskName
= HiiDiskGetNameCB (Index
);
476 if ((DiskName
== NULL
) || (DiskNameId
== 0)) {
477 return EFI_UNSUPPORTED
;
479 HiiSetFormString(DiskNameId
, DiskName
);
483 OpalHiiSetBrowserData ();
488 Get disk name string id.
490 @param DiskIndex The input disk index info.
492 @retval The disk name string id.
501 case 0: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_0
);
502 case 1: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_1
);
503 case 2: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_2
);
504 case 3: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_3
);
505 case 4: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_4
);
506 case 5: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_5
);
512 Confirm whether user truly want to do the revert action.
514 @param OpalDisk The device which need to perform data removal action.
515 @param ActionString Specifies the action name shown on pop up menu.
517 @retval EFI_SUCCESS Confirmed user want to do the revert action.
520 HiiConfirmDataRemovalAction (
521 IN OPAL_DISK
*OpalDisk
,
522 IN CHAR16
*ActionString
528 CHAR16 ApproveResponse
;
529 CHAR16 RejectResponse
;
532 // When the estimate cost time bigger than MAX_ACCEPTABLE_REVERTING_TIME, pop up dialog to let user confirm
533 // the revert action.
535 if (OpalDisk
->EstimateTimeCost
< MAX_ACCEPTABLE_REVERTING_TIME
) {
539 ApproveResponse
= L
'Y';
540 RejectResponse
= L
'N';
542 UnicodeSPrint(Unicode
, StrSize(L
"WARNING: ############# action needs about ####### seconds"), L
"WARNING: %s action needs about %d seconds", ActionString
, OpalDisk
->EstimateTimeCost
);
546 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
549 L
" System should not be powered off until action completion ",
551 L
" Press 'Y/y' to continue, press 'N/n' to cancal ",
555 ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) != (ApproveResponse
| UPPER_LOWER_CASE_OFFSET
)) &&
556 ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) != (RejectResponse
| UPPER_LOWER_CASE_OFFSET
))
559 if ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) == (RejectResponse
| UPPER_LOWER_CASE_OFFSET
)) {
567 This function processes the results of changes in configuration.
569 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
570 @param Action Specifies the type of action taken by the browser.
571 @param QuestionId A unique value which is sent to the original
572 exporting driver so that it can identify the type
574 @param Type The type of value for the question.
575 @param Value A pointer to the data being sent to the original
577 @param ActionRequest On return, points to the action requested by the
580 @retval EFI_SUCCESS The callback successfully handled the action.
581 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
582 variable and its data.
583 @retval EFI_DEVICE_ERROR The variable could not be saved.
584 @retval EFI_UNSUPPORTED The specified Action is not supported by the
591 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
592 EFI_BROWSER_ACTION Action
,
593 EFI_QUESTION_ID QuestionId
,
595 EFI_IFR_TYPE_VALUE
*Value
,
596 EFI_BROWSER_ACTION_REQUEST
*ActionRequest
604 if (ActionRequest
!= NULL
) {
605 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
607 return EFI_INVALID_PARAMETER
;
611 // If QuestionId is an auto-generated key (label, empty line, etc.), ignore it.
613 if ((QuestionId
& HII_KEY_FLAG
) == 0) {
617 HiiKey
.Raw
= QuestionId
;
618 HiiKeyId
= (UINT8
) HiiKey
.KeyBits
.Id
;
620 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
622 case HII_KEY_ID_VAR_SUPPORTED_DISKS
:
623 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_VAR_SUPPORTED_DISKS\n"));
624 return HiiPopulateMainMenuForm ();
626 case HII_KEY_ID_VAR_SELECTED_DISK_AVAILABLE_ACTIONS
:
627 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_VAR_SELECTED_DISK_AVAILABLE_ACTIONS\n"));
628 return HiiPopulateDiskInfoForm();
630 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
632 case HII_KEY_ID_GOTO_DISK_INFO
:
633 return HiiSelectDisk((UINT8
)HiiKey
.KeyBits
.Index
);
635 case HII_KEY_ID_REVERT
:
636 case HII_KEY_ID_PSID_REVERT
:
637 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
638 if (OpalDisk
!= NULL
) {
639 return HiiConfirmDataRemovalAction (OpalDisk
, L
"Revert");
645 case HII_KEY_ID_SECURE_ERASE
:
646 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
647 if (OpalDisk
!= NULL
) {
648 return HiiConfirmDataRemovalAction (OpalDisk
, L
"Secure erase");
655 } else if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
657 case HII_KEY_ID_BLOCKSID
:
660 PpRequest
= TCG2_PHYSICAL_PRESENCE_NO_ACTION
;
664 PpRequest
= TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID
;
668 PpRequest
= TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID
;
672 PpRequest
= TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_TRUE
;
676 PpRequest
= TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_FALSE
;
680 PpRequest
= TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_TRUE
;
684 PpRequest
= TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_FALSE
;
688 PpRequest
= TCG2_PHYSICAL_PRESENCE_NO_ACTION
;
689 DEBUG ((DEBUG_ERROR
, "Invalid value input!\n"));
692 HiiSetBlockSidAction(PpRequest
);
694 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
697 case HII_KEY_ID_SET_ADMIN_PWD
:
698 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_SET_ADMIN_PWD\n"));
699 gHiiConfiguration
.OpalRequest
.SetAdminPwd
= Value
->b
;
700 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
701 if (OpalDisk
!= NULL
) {
702 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
704 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
707 case HII_KEY_ID_SET_USER_PWD
:
708 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_SET_USER_PWD\n"));
709 gHiiConfiguration
.OpalRequest
.SetUserPwd
= Value
->b
;
710 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
711 if (OpalDisk
!= NULL
) {
712 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
714 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
717 case HII_KEY_ID_SECURE_ERASE
:
718 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_SECURE_ERASE\n"));
719 gHiiConfiguration
.OpalRequest
.SecureErase
= Value
->b
;
720 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
721 if (OpalDisk
!= NULL
) {
722 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
724 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
727 case HII_KEY_ID_REVERT
:
728 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_REVERT\n"));
729 gHiiConfiguration
.OpalRequest
.Revert
= Value
->b
;
730 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
731 if (OpalDisk
!= NULL
) {
732 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
734 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
736 case HII_KEY_ID_KEEP_USER_DATA
:
737 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_KEEP_USER_DATA\n"));
738 gHiiConfiguration
.OpalRequest
.KeepUserData
= Value
->b
;
739 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
740 if (OpalDisk
!= NULL
) {
741 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
743 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
746 case HII_KEY_ID_PSID_REVERT
:
747 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_PSID_REVERT\n"));
748 gHiiConfiguration
.OpalRequest
.PsidRevert
= Value
->b
;
749 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
750 if (OpalDisk
!= NULL
) {
751 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
753 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
756 case HII_KEY_ID_DISABLE_USER
:
757 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_DISABLE_USER\n"));
758 gHiiConfiguration
.OpalRequest
.DisableUser
= Value
->b
;
759 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
760 if (OpalDisk
!= NULL
) {
761 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
763 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
766 case HII_KEY_ID_ENABLE_FEATURE
:
767 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_ENABLE_FEATURE\n"));
768 gHiiConfiguration
.OpalRequest
.EnableFeature
= Value
->b
;
769 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
770 if (OpalDisk
!= NULL
) {
771 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
773 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
781 return EFI_UNSUPPORTED
;
785 Update the global Disk index info.
787 @param Index The input disk index info.
789 @retval EFI_SUCCESS Update the disk index info success.
797 OpalHiiGetBrowserData();
798 gHiiConfiguration
.SelectedDiskIndex
= Index
;
799 OpalHiiSetBrowserData ();
805 Draws the disk info form.
807 @retval EFI_SUCCESS Draw the disk info success.
811 HiiPopulateDiskInfoForm(
816 OPAL_DISK_ACTIONS AvailActions
;
820 OpalHiiGetBrowserData();
822 DiskName
= HiiDiskGetNameCB (gHiiConfiguration
.SelectedDiskIndex
);
823 if (DiskName
== NULL
) {
824 return EFI_UNSUPPORTED
;
826 HiiSetFormString(STRING_TOKEN(STR_DISK_INFO_SELECTED_DISK_NAME
), DiskName
);
828 gHiiConfiguration
.SelectedDiskAvailableActions
= HII_ACTION_NONE
;
829 ZeroMem (&gHiiConfiguration
.OpalRequest
, sizeof (OPAL_REQUEST
));
830 gHiiConfiguration
.KeepUserDataForced
= FALSE
;
832 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
834 if (OpalDisk
!= NULL
) {
835 OpalDiskUpdateStatus (OpalDisk
);
836 Ret
= OpalSupportGetAvailableActions(&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
, OpalDisk
->Owner
, &AvailActions
);
837 if (Ret
== TcgResultSuccess
) {
839 // Update actions, always allow PSID Revert
841 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.PsidRevert
== 1) ? HII_ACTION_PSID_REVERT
: HII_ACTION_NONE
;
844 // Always allow unlock to handle device migration
846 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.Unlock
== 1) ? HII_ACTION_UNLOCK
: HII_ACTION_NONE
;
848 if (!OpalFeatureEnabled (&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
)) {
849 if (OpalDisk
->Owner
== OpalOwnershipNobody
) {
850 gHiiConfiguration
.SelectedDiskAvailableActions
|= HII_ACTION_ENABLE_FEATURE
;
855 HiiSetFormString( STRING_TOKEN(STR_DISK_INFO_PSID_REVERT
), "PSID Revert to factory default");
857 DEBUG ((DEBUG_INFO
, "Feature disabled but ownership != nobody\n"));
860 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.Revert
== 1) ? HII_ACTION_REVERT
: HII_ACTION_NONE
;
861 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.AdminPass
== 1) ? HII_ACTION_SET_ADMIN_PWD
: HII_ACTION_NONE
;
862 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.UserPass
== 1) ? HII_ACTION_SET_USER_PWD
: HII_ACTION_NONE
;
863 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.SecureErase
== 1) ? HII_ACTION_SECURE_ERASE
: HII_ACTION_NONE
;
864 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.DisableUser
== 1) ? HII_ACTION_DISABLE_USER
: HII_ACTION_NONE
;
866 HiiSetFormString (STRING_TOKEN(STR_DISK_INFO_PSID_REVERT
), "PSID Revert to factory default and Disable");
869 // Determine revert options for disk
870 // Default initialize keep user Data to be true
872 gHiiConfiguration
.OpalRequest
.KeepUserData
= 1;
873 if (AvailActions
.RevertKeepDataForced
) {
874 gHiiConfiguration
.KeepUserDataForced
= TRUE
;
879 GetSavedOpalRequest (OpalDisk
, &gHiiConfiguration
.OpalRequest
);
883 // Pass the current configuration to the BIOS
885 OpalHiiSetBrowserData ();
891 Send BlockSid request through TPM physical presence module.
893 @param PpRequest TPM physical presence operation request.
895 @retval EFI_SUCCESS Do the required action success.
896 @retval Others Other error occur.
900 HiiSetBlockSidAction (
907 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (PpRequest
, 0);
908 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
909 Status
= EFI_SUCCESS
;
910 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
911 Status
= EFI_OUT_OF_RESOURCES
;
912 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
913 Status
= EFI_UNSUPPORTED
;
915 Status
= EFI_DEVICE_ERROR
;
922 This function processes the results of changes in configuration.
924 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
925 @param Configuration A null-terminated Unicode string in <ConfigResp>
927 @param Progress A pointer to a string filled in with the offset of
928 the most recent '&' before the first failing
929 name/value pair (or the beginning of the string if
930 the failure is in the first name/value pair) or
931 the terminating NULL if all was successful.
933 @retval EFI_SUCCESS The Results is processed successfully.
934 @retval EFI_INVALID_PARAMETER Configuration is NULL.
935 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
942 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
943 CONST EFI_STRING Configuration
,
947 if (Configuration
== NULL
|| Progress
== NULL
) {
948 return (EFI_INVALID_PARAMETER
);
951 *Progress
= Configuration
;
952 if (!HiiIsConfigHdrMatch (Configuration
, &gHiiSetupVariableGuid
, OpalPasswordStorageName
)) {
953 return EFI_NOT_FOUND
;
956 *Progress
= Configuration
+ StrLen (Configuration
);
962 This function allows a caller to extract the current configuration for one
963 or more named elements from the target driver.
965 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
966 @param Request A null-terminated Unicode string in
967 <ConfigRequest> format.
968 @param Progress On return, points to a character in the Request
969 string. Points to the string's null terminator if
970 request was successful. Points to the most recent
971 '&' before the first failing name/value pair (or
972 the beginning of the string if the failure is in
973 the first name/value pair) if the request was not
975 @param Results A null-terminated Unicode string in
976 <ConfigAltResp> format which has all values filled
977 in for the names in the Request string. String to
978 be allocated by the called function.
980 @retval EFI_SUCCESS The Results is filled with the requested values.
981 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
982 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
983 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
990 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
991 CONST EFI_STRING Request
,
992 EFI_STRING
*Progress
,
997 EFI_STRING ConfigRequest
;
998 EFI_STRING ConfigRequestHdr
;
1001 BOOLEAN AllocatedRequest
;
1002 EFI_HANDLE DriverHandle
;
1005 // Check for valid parameters
1007 if (Progress
== NULL
|| Results
== NULL
) {
1008 return (EFI_INVALID_PARAMETER
);
1011 *Progress
= Request
;
1012 if ((Request
!= NULL
) &&
1013 !HiiIsConfigHdrMatch (Request
, &gHiiSetupVariableGuid
, OpalPasswordStorageName
)) {
1014 return EFI_NOT_FOUND
;
1017 AllocatedRequest
= FALSE
;
1018 BufferSize
= sizeof (OPAL_HII_CONFIGURATION
);
1019 ConfigRequest
= Request
;
1020 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
1022 // Request has no request element, construct full request string.
1023 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
1024 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
1026 DriverHandle
= HiiGetDriverImageHandleCB();
1027 ConfigRequestHdr
= HiiConstructConfigHdr (&gHiiSetupVariableGuid
, OpalPasswordStorageName
, DriverHandle
);
1028 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
1029 ConfigRequest
= AllocateZeroPool (Size
);
1030 if (ConfigRequest
== NULL
) {
1031 return EFI_OUT_OF_RESOURCES
;
1033 AllocatedRequest
= TRUE
;
1034 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)BufferSize
);
1035 FreePool (ConfigRequestHdr
);
1039 // Convert Buffer Data to <ConfigResp> by helper function BlockToConfig( )
1041 Status
= gHiiConfigRouting
->BlockToConfig(
1044 (UINT8
*)&gHiiConfiguration
,
1045 sizeof(OPAL_HII_CONFIGURATION
),
1051 // Free the allocated config request string.
1053 if (AllocatedRequest
) {
1054 FreePool (ConfigRequest
);
1055 ConfigRequest
= NULL
;
1059 // Set Progress string to the original request string.
1061 if (Request
== NULL
) {
1063 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
1064 *Progress
= Request
+ StrLen (Request
);
1073 Pass the current system state to the bios via the hii_G_Configuration.
1077 OpalHiiSetBrowserData (
1082 &gHiiSetupVariableGuid
,
1083 (CHAR16
*)L
"OpalHiiConfig",
1084 sizeof(gHiiConfiguration
),
1085 (UINT8
*)&gHiiConfiguration
,
1093 Populate the hii_g_Configuraton with the browser Data.
1097 OpalHiiGetBrowserData (
1102 &gHiiSetupVariableGuid
,
1103 (CHAR16
*)L
"OpalHiiConfig",
1104 sizeof(gHiiConfiguration
),
1105 (UINT8
*)&gHiiConfiguration
1110 Set a string Value in a form.
1112 @param DestStringId The stringid which need to update.
1113 @param SrcAsciiStr The string nned to update.
1115 @retval EFI_SUCCESS Do the required action success.
1116 @retval Others Other error occur.
1121 EFI_STRING_ID DestStringId
,
1130 // Determine the Length of the sting
1132 Len
= ( UINT32
)AsciiStrLen( SrcAsciiStr
);
1135 // Allocate space for the unicode string, including terminator
1137 UniSize
= (Len
+ 1) * sizeof(CHAR16
);
1138 UniStr
= (CHAR16
*)AllocateZeroPool(UniSize
);
1141 // Copy into unicode string, then copy into string id
1143 AsciiStrToUnicodeStrS ( SrcAsciiStr
, UniStr
, Len
+ 1);
1146 // Update the string in the form
1148 if (HiiSetString(gHiiPackageListHandle
, DestStringId
, UniStr
, NULL
) == 0) {
1149 DEBUG ((DEBUG_INFO
, "HiiSetFormString( ) failed\n"));
1151 return (EFI_OUT_OF_RESOURCES
);
1159 return (EFI_SUCCESS
);
1163 Initialize the Opal disk base on the hardware info get from device.
1165 @param Dev The Opal device.
1167 @retval EFI_SUCESS Initialize the device success.
1168 @retval EFI_DEVICE_ERROR Get info from device failed.
1172 OpalDiskInitialize (
1173 IN OPAL_DRIVER_DEVICE
*Dev
1176 TCG_RESULT TcgResult
;
1177 OPAL_SESSION Session
;
1178 UINT8 ActiveDataRemovalMechanism
;
1179 UINT32 RemovalMechanishLists
[ResearvedMechanism
];
1181 ZeroMem(&Dev
->OpalDisk
, sizeof(OPAL_DISK
));
1182 Dev
->OpalDisk
.Sscp
= Dev
->Sscp
;
1183 Dev
->OpalDisk
.MediaId
= Dev
->MediaId
;
1184 Dev
->OpalDisk
.OpalDevicePath
= Dev
->OpalDevicePath
;
1186 ZeroMem(&Session
, sizeof(Session
));
1187 Session
.Sscp
= Dev
->Sscp
;
1188 Session
.MediaId
= Dev
->MediaId
;
1190 TcgResult
= OpalGetSupportedAttributesInfo (&Session
, &Dev
->OpalDisk
.SupportedAttributes
, &Dev
->OpalDisk
.OpalBaseComId
);
1191 if (TcgResult
!= TcgResultSuccess
) {
1192 return EFI_DEVICE_ERROR
;
1194 Session
.OpalBaseComId
= Dev
->OpalDisk
.OpalBaseComId
;
1196 TcgResult
= OpalUtilGetMsid (&Session
, Dev
->OpalDisk
.Msid
, OPAL_MSID_LENGHT
, &Dev
->OpalDisk
.MsidLength
);
1197 if (TcgResult
!= TcgResultSuccess
) {
1198 return EFI_DEVICE_ERROR
;
1201 if (Dev
->OpalDisk
.SupportedAttributes
.DataRemoval
) {
1202 TcgResult
= OpalUtilGetDataRemovalMechanismLists (&Session
, RemovalMechanishLists
);
1203 if (TcgResult
!= TcgResultSuccess
) {
1204 return EFI_DEVICE_ERROR
;
1207 TcgResult
= OpalUtilGetActiveDataRemovalMechanism (&Session
, Dev
->OpalDisk
.Msid
, Dev
->OpalDisk
.MsidLength
, &ActiveDataRemovalMechanism
);
1208 if (TcgResult
!= TcgResultSuccess
) {
1209 return EFI_DEVICE_ERROR
;
1212 Dev
->OpalDisk
.EstimateTimeCost
= RemovalMechanishLists
[ActiveDataRemovalMechanism
];
1215 return OpalDiskUpdateStatus (&Dev
->OpalDisk
);
1219 Update the device info.
1221 @param OpalDisk The Opal device.
1223 @retval EFI_SUCESS Initialize the device success.
1224 @retval EFI_DEVICE_ERROR Get info from device failed.
1225 @retval EFI_INVALID_PARAMETER Not get Msid info before get ownership info.
1229 OpalDiskUpdateStatus (
1233 TCG_RESULT TcgResult
;
1234 OPAL_SESSION Session
;
1236 ZeroMem(&Session
, sizeof(Session
));
1237 Session
.Sscp
= OpalDisk
->Sscp
;
1238 Session
.MediaId
= OpalDisk
->MediaId
;
1239 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
1241 TcgResult
= OpalGetLockingInfo(&Session
, &OpalDisk
->LockingFeature
);
1242 if (TcgResult
!= TcgResultSuccess
) {
1243 return EFI_DEVICE_ERROR
;
1246 if (OpalDisk
->MsidLength
== 0) {
1247 return EFI_INVALID_PARAMETER
;
1250 // Base on the Msid info to get the ownership, so Msid info must get first.
1252 OpalDisk
->Owner
= OpalUtilDetermineOwnership(&Session
, OpalDisk
->Msid
, OpalDisk
->MsidLength
);