2 Implementation of the HII for the Opal UEFI Driver.
4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 // Character definitions
19 #define UPPER_LOWER_CASE_OFFSET 0x20
22 // This is the generated IFR binary Data for each formset defined in VFR.
23 // This Data array is ready to be used as input of HiiAddPackages() to
24 // create a packagelist (which contains Form packages, String packages, etc).
26 extern UINT8 OpalPasswordFormBin
[];
29 // This is the generated String package Data for all .UNI files.
30 // This Data array is ready to be used as input of HiiAddPackages() to
31 // create a packagelist (which contains Form packages, String packages, etc).
33 extern UINT8 OpalPasswordDxeStrings
[];
35 CHAR16 OpalPasswordStorageName
[] = L
"OpalHiiConfig";
37 EFI_HII_CONFIG_ACCESS_PROTOCOL gHiiConfigAccessProtocol
;
40 // Handle to the list of HII packages (forms and strings) for this driver
42 EFI_HII_HANDLE gHiiPackageListHandle
= NULL
;
45 // Package List GUID containing all form and string packages
47 const EFI_GUID gHiiPackageListGuid
= PACKAGE_LIST_GUID
;
48 const EFI_GUID gHiiSetupVariableGuid
= SETUP_VARIABLE_GUID
;
51 // Structure that contains state of the HII
52 // This structure is updated by Hii.cpp and its contents
53 // is rendered in the HII.
55 OPAL_HII_CONFIGURATION gHiiConfiguration
;
58 // The device path containing the VENDOR_DEVICE_PATH and EFI_DEVICE_PATH_PROTOCOL
60 HII_VENDOR_DEVICE_PATH gHiiVendorDevicePath
= {
66 (UINT8
)(sizeof(VENDOR_DEVICE_PATH
)),
67 (UINT8
)((sizeof(VENDOR_DEVICE_PATH
)) >> 8)
70 OPAL_PASSWORD_CONFIG_GUID
74 END_ENTIRE_DEVICE_PATH_SUBTYPE
,
76 (UINT8
)(END_DEVICE_PATH_LENGTH
),
77 (UINT8
)((END_DEVICE_PATH_LENGTH
) >> 8)
83 Get saved OPAL request.
85 @param[in] OpalDisk The disk needs to get the saved OPAL request.
86 @param[out] OpalRequest OPAL request got.
91 IN OPAL_DISK
*OpalDisk
,
92 OUT OPAL_REQUEST
*OpalRequest
96 OPAL_REQUEST_VARIABLE
*TempVariable
;
97 OPAL_REQUEST_VARIABLE
*Variable
;
99 EFI_DEVICE_PATH_PROTOCOL
*DevicePathInVariable
;
100 UINTN DevicePathSizeInVariable
;
101 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
102 UINTN DevicePathSize
;
104 DEBUG ((DEBUG_INFO
, "%a() - enter\n", __FUNCTION__
));
109 Status
= GetVariable2 (
110 OPAL_REQUEST_VARIABLE_NAME
,
111 &gHiiSetupVariableGuid
,
115 if (EFI_ERROR (Status
) || (Variable
== NULL
)) {
119 TempVariable
= Variable
;
120 while ((VariableSize
> sizeof (OPAL_REQUEST_VARIABLE
)) &&
121 (VariableSize
>= TempVariable
->Length
) &&
122 (TempVariable
->Length
> sizeof (OPAL_REQUEST_VARIABLE
))) {
123 DevicePathInVariable
= (EFI_DEVICE_PATH_PROTOCOL
*) ((UINTN
) TempVariable
+ sizeof (OPAL_REQUEST_VARIABLE
));
124 DevicePathSizeInVariable
= GetDevicePathSize (DevicePathInVariable
);
125 DevicePath
= OpalDisk
->OpalDevicePath
;
126 DevicePathSize
= GetDevicePathSize (DevicePath
);
127 if ((DevicePathSize
== DevicePathSizeInVariable
) &&
128 (CompareMem (DevicePath
, DevicePathInVariable
, DevicePathSize
) == 0)) {
130 // Found the node for the OPAL device.
131 // Get the OPAL request.
133 CopyMem (OpalRequest
, &TempVariable
->OpalRequest
, sizeof (OPAL_REQUEST
));
136 "OpalRequest got: 0x%x\n",
141 VariableSize
-= TempVariable
->Length
;
142 TempVariable
= (OPAL_REQUEST_VARIABLE
*) ((UINTN
) TempVariable
+ TempVariable
->Length
);
147 DEBUG ((DEBUG_INFO
, "%a() - exit\n", __FUNCTION__
));
153 @param[in] OpalDisk The disk has OPAL request to save.
154 @param[in] OpalRequest OPAL request to save.
159 IN OPAL_DISK
*OpalDisk
,
160 IN OPAL_REQUEST OpalRequest
164 OPAL_REQUEST_VARIABLE
*TempVariable
;
165 UINTN TempVariableSize
;
166 OPAL_REQUEST_VARIABLE
*Variable
;
168 OPAL_REQUEST_VARIABLE
*NewVariable
;
169 UINTN NewVariableSize
;
170 EFI_DEVICE_PATH_PROTOCOL
*DevicePathInVariable
;
171 UINTN DevicePathSizeInVariable
;
172 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
173 UINTN DevicePathSize
;
175 DEBUG ((DEBUG_INFO
, "%a() - enter\n", __FUNCTION__
));
179 "OpalRequest to save: 0x%x\n",
188 Status
= GetVariable2 (
189 OPAL_REQUEST_VARIABLE_NAME
,
190 &gHiiSetupVariableGuid
,
194 if (!EFI_ERROR (Status
) && (Variable
!= NULL
)) {
195 TempVariable
= Variable
;
196 TempVariableSize
= VariableSize
;
197 while ((TempVariableSize
> sizeof (OPAL_REQUEST_VARIABLE
)) &&
198 (TempVariableSize
>= TempVariable
->Length
) &&
199 (TempVariable
->Length
> sizeof (OPAL_REQUEST_VARIABLE
))) {
200 DevicePathInVariable
= (EFI_DEVICE_PATH_PROTOCOL
*) ((UINTN
) TempVariable
+ sizeof (OPAL_REQUEST_VARIABLE
));
201 DevicePathSizeInVariable
= GetDevicePathSize (DevicePathInVariable
);
202 DevicePath
= OpalDisk
->OpalDevicePath
;
203 DevicePathSize
= GetDevicePathSize (DevicePath
);
204 if ((DevicePathSize
== DevicePathSizeInVariable
) &&
205 (CompareMem (DevicePath
, DevicePathInVariable
, DevicePathSize
) == 0)) {
207 // Found the node for the OPAL device.
208 // Update the OPAL request.
210 CopyMem (&TempVariable
->OpalRequest
, &OpalRequest
, sizeof (OPAL_REQUEST
));
211 NewVariable
= Variable
;
212 NewVariableSize
= VariableSize
;
215 TempVariableSize
-= TempVariable
->Length
;
216 TempVariable
= (OPAL_REQUEST_VARIABLE
*) ((UINTN
) TempVariable
+ TempVariable
->Length
);
218 if (NewVariable
== NULL
) {
220 // The node for the OPAL device is not found.
221 // Create node for the OPAL device.
223 DevicePath
= OpalDisk
->OpalDevicePath
;
224 DevicePathSize
= GetDevicePathSize (DevicePath
);
225 NewVariableSize
= VariableSize
+ sizeof (OPAL_REQUEST_VARIABLE
) + DevicePathSize
;
226 NewVariable
= AllocatePool (NewVariableSize
);
227 ASSERT (NewVariable
!= NULL
);
228 CopyMem (NewVariable
, Variable
, VariableSize
);
229 TempVariable
= (OPAL_REQUEST_VARIABLE
*) ((UINTN
) NewVariable
+ VariableSize
);
230 TempVariable
->Length
= (UINT32
) (sizeof (OPAL_REQUEST_VARIABLE
) + DevicePathSize
);
231 CopyMem (&TempVariable
->OpalRequest
, &OpalRequest
, sizeof (OPAL_REQUEST
));
232 DevicePathInVariable
= (EFI_DEVICE_PATH_PROTOCOL
*) ((UINTN
) TempVariable
+ sizeof (OPAL_REQUEST_VARIABLE
));
233 CopyMem (DevicePathInVariable
, DevicePath
, DevicePathSize
);
236 DevicePath
= OpalDisk
->OpalDevicePath
;
237 DevicePathSize
= GetDevicePathSize (DevicePath
);
238 NewVariableSize
= sizeof (OPAL_REQUEST_VARIABLE
) + DevicePathSize
;
239 NewVariable
= AllocatePool (NewVariableSize
);
240 ASSERT (NewVariable
!= NULL
);
241 NewVariable
->Length
= (UINT32
) (sizeof (OPAL_REQUEST_VARIABLE
) + DevicePathSize
);
242 CopyMem (&NewVariable
->OpalRequest
, &OpalRequest
, sizeof (OPAL_REQUEST
));
243 DevicePathInVariable
= (EFI_DEVICE_PATH_PROTOCOL
*) ((UINTN
) NewVariable
+ sizeof (OPAL_REQUEST_VARIABLE
));
244 CopyMem (DevicePathInVariable
, DevicePath
, DevicePathSize
);
246 Status
= gRT
->SetVariable (
247 OPAL_REQUEST_VARIABLE_NAME
,
248 (EFI_GUID
*) &gHiiSetupVariableGuid
,
249 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
,
253 if (EFI_ERROR (Status
)) {
254 DEBUG ((DEBUG_INFO
, "OpalRequest variable set failed (%r)\n", Status
));
256 if (NewVariable
!= Variable
) {
257 FreePool (NewVariable
);
259 if (Variable
!= NULL
) {
263 DEBUG ((DEBUG_INFO
, "%a() - exit\n", __FUNCTION__
));
267 Sets the current system state of global config variables.
271 HiiSetCurrentConfiguration(
275 UINT32 PpStorageFlag
;
276 EFI_STRING NewString
;
278 gHiiConfiguration
.NumDisks
= GetDeviceCount();
281 // Update the BlockSID status string.
283 PpStorageFlag
= Tcg2PhysicalPresenceLibGetManagementFlags ();
285 if ((PpStorageFlag
& TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_ENABLE_BLOCK_SID
) != 0) {
286 NewString
= HiiGetString (gHiiPackageListHandle
, STRING_TOKEN(STR_ENABLED
), NULL
);
287 if (NewString
== NULL
) {
288 DEBUG ((DEBUG_INFO
, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
292 NewString
= HiiGetString (gHiiPackageListHandle
, STRING_TOKEN(STR_DISABLED
), NULL
);
293 if (NewString
== NULL
) {
294 DEBUG ((DEBUG_INFO
, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
298 HiiSetString(gHiiPackageListHandle
, STRING_TOKEN(STR_BLOCKSID_STATUS1
), NewString
, NULL
);
299 FreePool (NewString
);
301 if ((PpStorageFlag
& TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_ENABLE_BLOCK_SID
) != 0) {
302 NewString
= HiiGetString (gHiiPackageListHandle
, STRING_TOKEN(STR_DISK_INFO_ENABLE_BLOCKSID_TRUE
), NULL
);
303 if (NewString
== NULL
) {
304 DEBUG ((DEBUG_INFO
, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
308 NewString
= HiiGetString (gHiiPackageListHandle
, STRING_TOKEN(STR_DISK_INFO_ENABLE_BLOCKSID_FALSE
), NULL
);
309 if (NewString
== NULL
) {
310 DEBUG ((DEBUG_INFO
, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
314 HiiSetString(gHiiPackageListHandle
, STRING_TOKEN(STR_BLOCKSID_STATUS2
), NewString
, NULL
);
315 FreePool (NewString
);
317 if ((PpStorageFlag
& TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_PP_REQUIRED_FOR_DISABLE_BLOCK_SID
) != 0) {
318 NewString
= HiiGetString (gHiiPackageListHandle
, STRING_TOKEN(STR_DISK_INFO_DISABLE_BLOCKSID_TRUE
), NULL
);
319 if (NewString
== NULL
) {
320 DEBUG ((DEBUG_INFO
, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
324 NewString
= HiiGetString (gHiiPackageListHandle
, STRING_TOKEN(STR_DISK_INFO_DISABLE_BLOCKSID_FALSE
), NULL
);
325 if (NewString
== NULL
) {
326 DEBUG ((DEBUG_INFO
, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
330 HiiSetString(gHiiPackageListHandle
, STRING_TOKEN(STR_BLOCKSID_STATUS3
), NewString
, NULL
);
331 FreePool (NewString
);
335 Install the HII related resources.
337 @retval EFI_SUCCESS Install all the resources success.
338 @retval other Error occur when install the resources.
346 EFI_HANDLE DriverHandle
;
349 // Clear the global configuration.
351 ZeroMem(&gHiiConfiguration
, sizeof(gHiiConfiguration
));
354 // Obtain the driver handle that the BIOS assigned us
356 DriverHandle
= HiiGetDriverImageHandleCB();
359 // Populate the config access protocol with the three functions we are publishing
361 gHiiConfigAccessProtocol
.ExtractConfig
= ExtractConfig
;
362 gHiiConfigAccessProtocol
.RouteConfig
= RouteConfig
;
363 gHiiConfigAccessProtocol
.Callback
= DriverCallback
;
366 // Associate the required protocols with our driver handle
368 Status
= gBS
->InstallMultipleProtocolInterfaces(
370 &gEfiHiiConfigAccessProtocolGuid
,
371 &gHiiConfigAccessProtocol
, // HII callback
372 &gEfiDevicePathProtocolGuid
,
373 &gHiiVendorDevicePath
, // required for HII callback allow all disks to be shown in same hii
377 if (EFI_ERROR(Status
)) {
381 return OpalHiiAddPackages();
385 Install the HII form and string packages.
387 @retval EFI_SUCCESS Install all the resources success.
388 @retval EFI_OUT_OF_RESOURCES Out of resource error.
395 EFI_HANDLE DriverHandle
;
398 DriverHandle
= HiiGetDriverImageHandleCB();
401 // Publish the HII form and HII string packages
403 gHiiPackageListHandle
= HiiAddPackages(
404 &gHiiPackageListGuid
,
406 OpalPasswordDxeStrings
,
412 // Make sure the packages installed successfully
414 if (gHiiPackageListHandle
== NULL
) {
415 DEBUG ((DEBUG_INFO
, "OpalHiiAddPackages failed\n"));
416 return EFI_OUT_OF_RESOURCES
;
420 // Update Version String in main window
422 NewString
= HiiGetDriverNameCB ();
423 if (HiiSetString(gHiiPackageListHandle
, STRING_TOKEN(STR_MAIN_OPAL_VERSION
), NewString
, NULL
) == 0) {
424 DEBUG ((DEBUG_INFO
, "OpalHiiAddPackages: HiiSetString( ) failed\n"));
425 return EFI_OUT_OF_RESOURCES
;
432 Uninstall the HII capability.
434 @retval EFI_SUCCESS Uninstall all the resources success.
435 @retval others Other errors occur when unistall the hii resource.
445 // Remove the packages we've provided to the BIOS
447 HiiRemovePackages(gHiiPackageListHandle
);
450 // Remove the protocols from our driver handle
452 Status
= gBS
->UninstallMultipleProtocolInterfaces(
453 HiiGetDriverImageHandleCB(),
454 &gEfiHiiConfigAccessProtocolGuid
,
455 &gHiiConfigAccessProtocol
, // HII callback
456 &gEfiDevicePathProtocolGuid
,
457 &gHiiVendorDevicePath
, // required for HII callback
460 if (EFI_ERROR(Status
)) {
461 DEBUG ((DEBUG_INFO
, "Cannot uninstall Hii Protocols: %r\n", Status
));
468 Updates the main menu form.
470 @retval EFI_SUCCESS update the main form success.
473 HiiPopulateMainMenuForm (
479 EFI_STRING_ID DiskNameId
;
482 HiiSetCurrentConfiguration();
484 gHiiConfiguration
.SupportedDisks
= 0;
486 for (Index
= 0; Index
< gHiiConfiguration
.NumDisks
; Index
++) {
487 OpalDisk
= HiiGetOpalDiskCB (Index
);
488 if ((OpalDisk
!= NULL
) && OpalFeatureSupported (&OpalDisk
->SupportedAttributes
)) {
489 gHiiConfiguration
.SupportedDisks
|= (1 << Index
);
490 DiskNameId
= GetDiskNameStringId (Index
);
491 DiskName
= HiiDiskGetNameCB (Index
);
492 if ((DiskName
== NULL
) || (DiskNameId
== 0)) {
493 return EFI_UNSUPPORTED
;
495 HiiSetFormString(DiskNameId
, DiskName
);
499 OpalHiiSetBrowserData ();
504 Get disk name string id.
506 @param DiskIndex The input disk index info.
508 @retval The disk name string id.
517 case 0: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_0
);
518 case 1: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_1
);
519 case 2: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_2
);
520 case 3: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_3
);
521 case 4: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_4
);
522 case 5: return STRING_TOKEN(STR_MAIN_GOTO_DISK_INFO_5
);
528 Confirm whether user truly want to do the revert action.
530 @param OpalDisk The device which need to do the revert action.
532 @retval EFI_SUCCESS Confirmed user want to do the revert action.
535 HiiConfirmRevertAction (
536 IN OPAL_DISK
*OpalDisk
542 CHAR16 ApproveResponse
;
543 CHAR16 RejectResponse
;
546 // When the estimate cost time bigger than MAX_ACCEPTABLE_REVERTING_TIME, pop up dialog to let user confirm
547 // the revert action.
549 if (OpalDisk
->EstimateTimeCost
< MAX_ACCEPTABLE_REVERTING_TIME
) {
553 ApproveResponse
= L
'Y';
554 RejectResponse
= L
'N';
556 UnicodeSPrint(Unicode
, StrSize(L
"WARNING: Revert device needs about ####### seconds"), L
"WARNING: Revert device needs about %d seconds", OpalDisk
->EstimateTimeCost
);
560 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
563 L
" System should not be powered off until revert completion ",
565 L
" Press 'Y/y' to continue, press 'N/n' to cancal ",
569 ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) != (ApproveResponse
| UPPER_LOWER_CASE_OFFSET
)) &&
570 ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) != (RejectResponse
| UPPER_LOWER_CASE_OFFSET
))
573 if ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) == (RejectResponse
| UPPER_LOWER_CASE_OFFSET
)) {
581 This function processes the results of changes in configuration.
583 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
584 @param Action Specifies the type of action taken by the browser.
585 @param QuestionId A unique value which is sent to the original
586 exporting driver so that it can identify the type
588 @param Type The type of value for the question.
589 @param Value A pointer to the data being sent to the original
591 @param ActionRequest On return, points to the action requested by the
594 @retval EFI_SUCCESS The callback successfully handled the action.
595 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
596 variable and its data.
597 @retval EFI_DEVICE_ERROR The variable could not be saved.
598 @retval EFI_UNSUPPORTED The specified Action is not supported by the
605 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
606 EFI_BROWSER_ACTION Action
,
607 EFI_QUESTION_ID QuestionId
,
609 EFI_IFR_TYPE_VALUE
*Value
,
610 EFI_BROWSER_ACTION_REQUEST
*ActionRequest
618 if (ActionRequest
!= NULL
) {
619 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
621 return EFI_INVALID_PARAMETER
;
625 // If QuestionId is an auto-generated key (label, empty line, etc.), ignore it.
627 if ((QuestionId
& HII_KEY_FLAG
) == 0) {
631 HiiKey
.Raw
= QuestionId
;
632 HiiKeyId
= (UINT8
) HiiKey
.KeyBits
.Id
;
634 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
636 case HII_KEY_ID_VAR_SUPPORTED_DISKS
:
637 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_VAR_SUPPORTED_DISKS\n"));
638 return HiiPopulateMainMenuForm ();
640 case HII_KEY_ID_VAR_SELECTED_DISK_AVAILABLE_ACTIONS
:
641 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_VAR_SELECTED_DISK_AVAILABLE_ACTIONS\n"));
642 return HiiPopulateDiskInfoForm();
644 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
646 case HII_KEY_ID_GOTO_DISK_INFO
:
647 return HiiSelectDisk((UINT8
)HiiKey
.KeyBits
.Index
);
649 case HII_KEY_ID_REVERT
:
650 case HII_KEY_ID_PSID_REVERT
:
651 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
652 if (OpalDisk
!= NULL
) {
653 return HiiConfirmRevertAction (OpalDisk
);
660 } else if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
662 case HII_KEY_ID_BLOCKSID
:
665 PpRequest
= TCG2_PHYSICAL_PRESENCE_NO_ACTION
;
669 PpRequest
= TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID
;
673 PpRequest
= TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID
;
677 PpRequest
= TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_TRUE
;
681 PpRequest
= TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_FALSE
;
685 PpRequest
= TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_TRUE
;
689 PpRequest
= TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_FALSE
;
693 PpRequest
= TCG2_PHYSICAL_PRESENCE_NO_ACTION
;
694 DEBUG ((DEBUG_ERROR
, "Invalid value input!\n"));
697 HiiSetBlockSidAction(PpRequest
);
699 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
702 case HII_KEY_ID_SET_ADMIN_PWD
:
703 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_SET_ADMIN_PWD\n"));
704 gHiiConfiguration
.OpalRequest
.SetAdminPwd
= Value
->b
;
705 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
706 if (OpalDisk
!= NULL
) {
707 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
709 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
712 case HII_KEY_ID_SET_USER_PWD
:
713 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_SET_USER_PWD\n"));
714 gHiiConfiguration
.OpalRequest
.SetUserPwd
= Value
->b
;
715 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
716 if (OpalDisk
!= NULL
) {
717 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
719 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
722 case HII_KEY_ID_SECURE_ERASE
:
723 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_SECURE_ERASE\n"));
724 gHiiConfiguration
.OpalRequest
.SecureErase
= Value
->b
;
725 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
726 if (OpalDisk
!= NULL
) {
727 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
729 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
732 case HII_KEY_ID_REVERT
:
733 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_REVERT\n"));
734 gHiiConfiguration
.OpalRequest
.Revert
= Value
->b
;
735 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
736 if (OpalDisk
!= NULL
) {
737 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
739 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
741 case HII_KEY_ID_KEEP_USER_DATA
:
742 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_KEEP_USER_DATA\n"));
743 gHiiConfiguration
.OpalRequest
.KeepUserData
= Value
->b
;
744 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
745 if (OpalDisk
!= NULL
) {
746 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
748 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
751 case HII_KEY_ID_PSID_REVERT
:
752 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_PSID_REVERT\n"));
753 gHiiConfiguration
.OpalRequest
.PsidRevert
= Value
->b
;
754 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
755 if (OpalDisk
!= NULL
) {
756 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
758 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
761 case HII_KEY_ID_DISABLE_USER
:
762 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_DISABLE_USER\n"));
763 gHiiConfiguration
.OpalRequest
.DisableUser
= Value
->b
;
764 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
765 if (OpalDisk
!= NULL
) {
766 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
768 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
771 case HII_KEY_ID_ENABLE_FEATURE
:
772 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_ENABLE_FEATURE\n"));
773 gHiiConfiguration
.OpalRequest
.EnableFeature
= Value
->b
;
774 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
775 if (OpalDisk
!= NULL
) {
776 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
778 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
786 return EFI_UNSUPPORTED
;
790 Update the global Disk index info.
792 @param Index The input disk index info.
794 @retval EFI_SUCCESS Update the disk index info success.
802 OpalHiiGetBrowserData();
803 gHiiConfiguration
.SelectedDiskIndex
= Index
;
804 OpalHiiSetBrowserData ();
810 Draws the disk info form.
812 @retval EFI_SUCCESS Draw the disk info success.
816 HiiPopulateDiskInfoForm(
821 OPAL_DISK_ACTIONS AvailActions
;
825 OpalHiiGetBrowserData();
827 DiskName
= HiiDiskGetNameCB (gHiiConfiguration
.SelectedDiskIndex
);
828 if (DiskName
== NULL
) {
829 return EFI_UNSUPPORTED
;
831 HiiSetFormString(STRING_TOKEN(STR_DISK_INFO_SELECTED_DISK_NAME
), DiskName
);
833 gHiiConfiguration
.SelectedDiskAvailableActions
= HII_ACTION_NONE
;
834 ZeroMem (&gHiiConfiguration
.OpalRequest
, sizeof (OPAL_REQUEST
));
835 gHiiConfiguration
.KeepUserDataForced
= FALSE
;
837 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
839 if (OpalDisk
!= NULL
) {
840 OpalDiskUpdateStatus (OpalDisk
);
841 Ret
= OpalSupportGetAvailableActions(&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
, OpalDisk
->Owner
, &AvailActions
);
842 if (Ret
== TcgResultSuccess
) {
844 // Update actions, always allow PSID Revert
846 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.PsidRevert
== 1) ? HII_ACTION_PSID_REVERT
: HII_ACTION_NONE
;
849 // Always allow unlock to handle device migration
851 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.Unlock
== 1) ? HII_ACTION_UNLOCK
: HII_ACTION_NONE
;
853 if (!OpalFeatureEnabled (&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
)) {
854 if (OpalDisk
->Owner
== OpalOwnershipNobody
) {
855 gHiiConfiguration
.SelectedDiskAvailableActions
|= HII_ACTION_ENABLE_FEATURE
;
860 HiiSetFormString( STRING_TOKEN(STR_DISK_INFO_PSID_REVERT
), "PSID Revert to factory default");
862 DEBUG ((DEBUG_INFO
, "Feature disabled but ownership != nobody\n"));
865 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.Revert
== 1) ? HII_ACTION_REVERT
: HII_ACTION_NONE
;
866 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.AdminPass
== 1) ? HII_ACTION_SET_ADMIN_PWD
: HII_ACTION_NONE
;
867 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.UserPass
== 1) ? HII_ACTION_SET_USER_PWD
: HII_ACTION_NONE
;
868 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.SecureErase
== 1) ? HII_ACTION_SECURE_ERASE
: HII_ACTION_NONE
;
869 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.DisableUser
== 1) ? HII_ACTION_DISABLE_USER
: HII_ACTION_NONE
;
871 HiiSetFormString (STRING_TOKEN(STR_DISK_INFO_PSID_REVERT
), "PSID Revert to factory default and Disable");
874 // Determine revert options for disk
875 // Default initialize keep user Data to be true
877 gHiiConfiguration
.OpalRequest
.KeepUserData
= 1;
878 if (AvailActions
.RevertKeepDataForced
) {
879 gHiiConfiguration
.KeepUserDataForced
= TRUE
;
884 GetSavedOpalRequest (OpalDisk
, &gHiiConfiguration
.OpalRequest
);
888 // Pass the current configuration to the BIOS
890 OpalHiiSetBrowserData ();
896 Send BlockSid request through TPM physical presence module.
898 @param PpRequest TPM physical presence operation request.
900 @retval EFI_SUCCESS Do the required action success.
901 @retval Others Other error occur.
905 HiiSetBlockSidAction (
912 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (PpRequest
, 0);
913 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
914 Status
= EFI_SUCCESS
;
915 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
916 Status
= EFI_OUT_OF_RESOURCES
;
917 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
918 Status
= EFI_UNSUPPORTED
;
920 Status
= EFI_DEVICE_ERROR
;
927 This function processes the results of changes in configuration.
929 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
930 @param Configuration A null-terminated Unicode string in <ConfigResp>
932 @param Progress A pointer to a string filled in with the offset of
933 the most recent '&' before the first failing
934 name/value pair (or the beginning of the string if
935 the failure is in the first name/value pair) or
936 the terminating NULL if all was successful.
938 @retval EFI_SUCCESS The Results is processed successfully.
939 @retval EFI_INVALID_PARAMETER Configuration is NULL.
940 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
947 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
948 CONST EFI_STRING Configuration
,
952 if (Configuration
== NULL
|| Progress
== NULL
) {
953 return (EFI_INVALID_PARAMETER
);
956 *Progress
= Configuration
;
957 if (!HiiIsConfigHdrMatch (Configuration
, &gHiiSetupVariableGuid
, OpalPasswordStorageName
)) {
958 return EFI_NOT_FOUND
;
961 *Progress
= Configuration
+ StrLen (Configuration
);
967 This function allows a caller to extract the current configuration for one
968 or more named elements from the target driver.
970 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
971 @param Request A null-terminated Unicode string in
972 <ConfigRequest> format.
973 @param Progress On return, points to a character in the Request
974 string. Points to the string's null terminator if
975 request was successful. Points to the most recent
976 '&' before the first failing name/value pair (or
977 the beginning of the string if the failure is in
978 the first name/value pair) if the request was not
980 @param Results A null-terminated Unicode string in
981 <ConfigAltResp> format which has all values filled
982 in for the names in the Request string. String to
983 be allocated by the called function.
985 @retval EFI_SUCCESS The Results is filled with the requested values.
986 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
987 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
988 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
995 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
996 CONST EFI_STRING Request
,
997 EFI_STRING
*Progress
,
1002 EFI_STRING ConfigRequest
;
1003 EFI_STRING ConfigRequestHdr
;
1006 BOOLEAN AllocatedRequest
;
1007 EFI_HANDLE DriverHandle
;
1010 // Check for valid parameters
1012 if (Progress
== NULL
|| Results
== NULL
) {
1013 return (EFI_INVALID_PARAMETER
);
1016 *Progress
= Request
;
1017 if ((Request
!= NULL
) &&
1018 !HiiIsConfigHdrMatch (Request
, &gHiiSetupVariableGuid
, OpalPasswordStorageName
)) {
1019 return EFI_NOT_FOUND
;
1022 AllocatedRequest
= FALSE
;
1023 BufferSize
= sizeof (OPAL_HII_CONFIGURATION
);
1024 ConfigRequest
= Request
;
1025 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
1027 // Request has no request element, construct full request string.
1028 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
1029 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
1031 DriverHandle
= HiiGetDriverImageHandleCB();
1032 ConfigRequestHdr
= HiiConstructConfigHdr (&gHiiSetupVariableGuid
, OpalPasswordStorageName
, DriverHandle
);
1033 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
1034 ConfigRequest
= AllocateZeroPool (Size
);
1035 if (ConfigRequest
== NULL
) {
1036 return EFI_OUT_OF_RESOURCES
;
1038 AllocatedRequest
= TRUE
;
1039 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)BufferSize
);
1040 FreePool (ConfigRequestHdr
);
1044 // Convert Buffer Data to <ConfigResp> by helper function BlockToConfig( )
1046 Status
= gHiiConfigRouting
->BlockToConfig(
1049 (UINT8
*)&gHiiConfiguration
,
1050 sizeof(OPAL_HII_CONFIGURATION
),
1056 // Free the allocated config request string.
1058 if (AllocatedRequest
) {
1059 FreePool (ConfigRequest
);
1060 ConfigRequest
= NULL
;
1064 // Set Progress string to the original request string.
1066 if (Request
== NULL
) {
1068 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
1069 *Progress
= Request
+ StrLen (Request
);
1078 Pass the current system state to the bios via the hii_G_Configuration.
1082 OpalHiiSetBrowserData (
1087 &gHiiSetupVariableGuid
,
1088 (CHAR16
*)L
"OpalHiiConfig",
1089 sizeof(gHiiConfiguration
),
1090 (UINT8
*)&gHiiConfiguration
,
1098 Populate the hii_g_Configuraton with the browser Data.
1102 OpalHiiGetBrowserData (
1107 &gHiiSetupVariableGuid
,
1108 (CHAR16
*)L
"OpalHiiConfig",
1109 sizeof(gHiiConfiguration
),
1110 (UINT8
*)&gHiiConfiguration
1115 Set a string Value in a form.
1117 @param DestStringId The stringid which need to update.
1118 @param SrcAsciiStr The string nned to update.
1120 @retval EFI_SUCCESS Do the required action success.
1121 @retval Others Other error occur.
1126 EFI_STRING_ID DestStringId
,
1135 // Determine the Length of the sting
1137 Len
= ( UINT32
)AsciiStrLen( SrcAsciiStr
);
1140 // Allocate space for the unicode string, including terminator
1142 UniSize
= (Len
+ 1) * sizeof(CHAR16
);
1143 UniStr
= (CHAR16
*)AllocateZeroPool(UniSize
);
1146 // Copy into unicode string, then copy into string id
1148 AsciiStrToUnicodeStrS ( SrcAsciiStr
, UniStr
, Len
+ 1);
1151 // Update the string in the form
1153 if (HiiSetString(gHiiPackageListHandle
, DestStringId
, UniStr
, NULL
) == 0) {
1154 DEBUG ((DEBUG_INFO
, "HiiSetFormString( ) failed\n"));
1156 return (EFI_OUT_OF_RESOURCES
);
1164 return (EFI_SUCCESS
);
1168 Initialize the Opal disk base on the hardware info get from device.
1170 @param Dev The Opal device.
1172 @retval EFI_SUCESS Initialize the device success.
1173 @retval EFI_DEVICE_ERROR Get info from device failed.
1177 OpalDiskInitialize (
1178 IN OPAL_DRIVER_DEVICE
*Dev
1181 TCG_RESULT TcgResult
;
1182 OPAL_SESSION Session
;
1183 UINT8 ActiveDataRemovalMechanism
;
1184 UINT32 RemovalMechanishLists
[ResearvedMechanism
];
1186 ZeroMem(&Dev
->OpalDisk
, sizeof(OPAL_DISK
));
1187 Dev
->OpalDisk
.Sscp
= Dev
->Sscp
;
1188 Dev
->OpalDisk
.MediaId
= Dev
->MediaId
;
1189 Dev
->OpalDisk
.OpalDevicePath
= Dev
->OpalDevicePath
;
1191 ZeroMem(&Session
, sizeof(Session
));
1192 Session
.Sscp
= Dev
->Sscp
;
1193 Session
.MediaId
= Dev
->MediaId
;
1195 TcgResult
= OpalGetSupportedAttributesInfo (&Session
, &Dev
->OpalDisk
.SupportedAttributes
, &Dev
->OpalDisk
.OpalBaseComId
);
1196 if (TcgResult
!= TcgResultSuccess
) {
1197 return EFI_DEVICE_ERROR
;
1199 Session
.OpalBaseComId
= Dev
->OpalDisk
.OpalBaseComId
;
1201 TcgResult
= OpalUtilGetMsid (&Session
, Dev
->OpalDisk
.Msid
, OPAL_MSID_LENGHT
, &Dev
->OpalDisk
.MsidLength
);
1202 if (TcgResult
!= TcgResultSuccess
) {
1203 return EFI_DEVICE_ERROR
;
1206 if (Dev
->OpalDisk
.SupportedAttributes
.DataRemoval
) {
1207 TcgResult
= OpalUtilGetDataRemovalMechanismLists (&Session
, RemovalMechanishLists
);
1208 if (TcgResult
!= TcgResultSuccess
) {
1209 return EFI_DEVICE_ERROR
;
1212 TcgResult
= OpalUtilGetActiveDataRemovalMechanism (&Session
, Dev
->OpalDisk
.Msid
, Dev
->OpalDisk
.MsidLength
, &ActiveDataRemovalMechanism
);
1213 if (TcgResult
!= TcgResultSuccess
) {
1214 return EFI_DEVICE_ERROR
;
1217 Dev
->OpalDisk
.EstimateTimeCost
= RemovalMechanishLists
[ActiveDataRemovalMechanism
];
1220 return OpalDiskUpdateStatus (&Dev
->OpalDisk
);
1224 Update the device info.
1226 @param OpalDisk The Opal device.
1228 @retval EFI_SUCESS Initialize the device success.
1229 @retval EFI_DEVICE_ERROR Get info from device failed.
1230 @retval EFI_INVALID_PARAMETER Not get Msid info before get ownership info.
1234 OpalDiskUpdateStatus (
1238 TCG_RESULT TcgResult
;
1239 OPAL_SESSION Session
;
1241 ZeroMem(&Session
, sizeof(Session
));
1242 Session
.Sscp
= OpalDisk
->Sscp
;
1243 Session
.MediaId
= OpalDisk
->MediaId
;
1244 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
1246 TcgResult
= OpalGetLockingInfo(&Session
, &OpalDisk
->LockingFeature
);
1247 if (TcgResult
!= TcgResultSuccess
) {
1248 return EFI_DEVICE_ERROR
;
1251 if (OpalDisk
->MsidLength
== 0) {
1252 return EFI_INVALID_PARAMETER
;
1255 // Base on the Msid info to get the ownership, so Msid info must get first.
1257 OpalDisk
->Owner
= OpalUtilDetermineOwnership(&Session
, OpalDisk
->Msid
, OpalDisk
->MsidLength
);