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 do the revert action.
516 @retval EFI_SUCCESS Confirmed user want to do the revert action.
519 HiiConfirmRevertAction (
520 IN OPAL_DISK
*OpalDisk
526 CHAR16 ApproveResponse
;
527 CHAR16 RejectResponse
;
530 // When the estimate cost time bigger than MAX_ACCEPTABLE_REVERTING_TIME, pop up dialog to let user confirm
531 // the revert action.
533 if (OpalDisk
->EstimateTimeCost
< MAX_ACCEPTABLE_REVERTING_TIME
) {
537 ApproveResponse
= L
'Y';
538 RejectResponse
= L
'N';
540 UnicodeSPrint(Unicode
, StrSize(L
"WARNING: Revert device needs about ####### seconds"), L
"WARNING: Revert device needs about %d seconds", OpalDisk
->EstimateTimeCost
);
544 EFI_LIGHTGRAY
| EFI_BACKGROUND_BLUE
,
547 L
" System should not be powered off until revert completion ",
549 L
" Press 'Y/y' to continue, press 'N/n' to cancal ",
553 ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) != (ApproveResponse
| UPPER_LOWER_CASE_OFFSET
)) &&
554 ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) != (RejectResponse
| UPPER_LOWER_CASE_OFFSET
))
557 if ((Key
.UnicodeChar
| UPPER_LOWER_CASE_OFFSET
) == (RejectResponse
| UPPER_LOWER_CASE_OFFSET
)) {
565 This function processes the results of changes in configuration.
567 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
568 @param Action Specifies the type of action taken by the browser.
569 @param QuestionId A unique value which is sent to the original
570 exporting driver so that it can identify the type
572 @param Type The type of value for the question.
573 @param Value A pointer to the data being sent to the original
575 @param ActionRequest On return, points to the action requested by the
578 @retval EFI_SUCCESS The callback successfully handled the action.
579 @retval EFI_OUT_OF_RESOURCES Not enough storage is available to hold the
580 variable and its data.
581 @retval EFI_DEVICE_ERROR The variable could not be saved.
582 @retval EFI_UNSUPPORTED The specified Action is not supported by the
589 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
590 EFI_BROWSER_ACTION Action
,
591 EFI_QUESTION_ID QuestionId
,
593 EFI_IFR_TYPE_VALUE
*Value
,
594 EFI_BROWSER_ACTION_REQUEST
*ActionRequest
602 if (ActionRequest
!= NULL
) {
603 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_NONE
;
605 return EFI_INVALID_PARAMETER
;
609 // If QuestionId is an auto-generated key (label, empty line, etc.), ignore it.
611 if ((QuestionId
& HII_KEY_FLAG
) == 0) {
615 HiiKey
.Raw
= QuestionId
;
616 HiiKeyId
= (UINT8
) HiiKey
.KeyBits
.Id
;
618 if (Action
== EFI_BROWSER_ACTION_FORM_OPEN
) {
620 case HII_KEY_ID_VAR_SUPPORTED_DISKS
:
621 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_VAR_SUPPORTED_DISKS\n"));
622 return HiiPopulateMainMenuForm ();
624 case HII_KEY_ID_VAR_SELECTED_DISK_AVAILABLE_ACTIONS
:
625 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_VAR_SELECTED_DISK_AVAILABLE_ACTIONS\n"));
626 return HiiPopulateDiskInfoForm();
628 } else if (Action
== EFI_BROWSER_ACTION_CHANGING
) {
630 case HII_KEY_ID_GOTO_DISK_INFO
:
631 return HiiSelectDisk((UINT8
)HiiKey
.KeyBits
.Index
);
633 case HII_KEY_ID_REVERT
:
634 case HII_KEY_ID_PSID_REVERT
:
635 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
636 if (OpalDisk
!= NULL
) {
637 return HiiConfirmRevertAction (OpalDisk
);
644 } else if (Action
== EFI_BROWSER_ACTION_CHANGED
) {
646 case HII_KEY_ID_BLOCKSID
:
649 PpRequest
= TCG2_PHYSICAL_PRESENCE_NO_ACTION
;
653 PpRequest
= TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID
;
657 PpRequest
= TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID
;
661 PpRequest
= TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_TRUE
;
665 PpRequest
= TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_FALSE
;
669 PpRequest
= TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_TRUE
;
673 PpRequest
= TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_FALSE
;
677 PpRequest
= TCG2_PHYSICAL_PRESENCE_NO_ACTION
;
678 DEBUG ((DEBUG_ERROR
, "Invalid value input!\n"));
681 HiiSetBlockSidAction(PpRequest
);
683 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
686 case HII_KEY_ID_SET_ADMIN_PWD
:
687 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_SET_ADMIN_PWD\n"));
688 gHiiConfiguration
.OpalRequest
.SetAdminPwd
= Value
->b
;
689 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
690 if (OpalDisk
!= NULL
) {
691 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
693 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
696 case HII_KEY_ID_SET_USER_PWD
:
697 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_SET_USER_PWD\n"));
698 gHiiConfiguration
.OpalRequest
.SetUserPwd
= Value
->b
;
699 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
700 if (OpalDisk
!= NULL
) {
701 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
703 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
706 case HII_KEY_ID_SECURE_ERASE
:
707 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_SECURE_ERASE\n"));
708 gHiiConfiguration
.OpalRequest
.SecureErase
= Value
->b
;
709 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
710 if (OpalDisk
!= NULL
) {
711 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
713 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
716 case HII_KEY_ID_REVERT
:
717 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_REVERT\n"));
718 gHiiConfiguration
.OpalRequest
.Revert
= Value
->b
;
719 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
720 if (OpalDisk
!= NULL
) {
721 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
723 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
725 case HII_KEY_ID_KEEP_USER_DATA
:
726 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_KEEP_USER_DATA\n"));
727 gHiiConfiguration
.OpalRequest
.KeepUserData
= Value
->b
;
728 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
729 if (OpalDisk
!= NULL
) {
730 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
732 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
735 case HII_KEY_ID_PSID_REVERT
:
736 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_PSID_REVERT\n"));
737 gHiiConfiguration
.OpalRequest
.PsidRevert
= Value
->b
;
738 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
739 if (OpalDisk
!= NULL
) {
740 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
742 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
745 case HII_KEY_ID_DISABLE_USER
:
746 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_DISABLE_USER\n"));
747 gHiiConfiguration
.OpalRequest
.DisableUser
= Value
->b
;
748 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
749 if (OpalDisk
!= NULL
) {
750 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
752 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
755 case HII_KEY_ID_ENABLE_FEATURE
:
756 DEBUG ((DEBUG_INFO
, "HII_KEY_ID_ENABLE_FEATURE\n"));
757 gHiiConfiguration
.OpalRequest
.EnableFeature
= Value
->b
;
758 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
759 if (OpalDisk
!= NULL
) {
760 SaveOpalRequest (OpalDisk
, gHiiConfiguration
.OpalRequest
);
762 *ActionRequest
= EFI_BROWSER_ACTION_REQUEST_FORM_APPLY
;
770 return EFI_UNSUPPORTED
;
774 Update the global Disk index info.
776 @param Index The input disk index info.
778 @retval EFI_SUCCESS Update the disk index info success.
786 OpalHiiGetBrowserData();
787 gHiiConfiguration
.SelectedDiskIndex
= Index
;
788 OpalHiiSetBrowserData ();
794 Draws the disk info form.
796 @retval EFI_SUCCESS Draw the disk info success.
800 HiiPopulateDiskInfoForm(
805 OPAL_DISK_ACTIONS AvailActions
;
809 OpalHiiGetBrowserData();
811 DiskName
= HiiDiskGetNameCB (gHiiConfiguration
.SelectedDiskIndex
);
812 if (DiskName
== NULL
) {
813 return EFI_UNSUPPORTED
;
815 HiiSetFormString(STRING_TOKEN(STR_DISK_INFO_SELECTED_DISK_NAME
), DiskName
);
817 gHiiConfiguration
.SelectedDiskAvailableActions
= HII_ACTION_NONE
;
818 ZeroMem (&gHiiConfiguration
.OpalRequest
, sizeof (OPAL_REQUEST
));
819 gHiiConfiguration
.KeepUserDataForced
= FALSE
;
821 OpalDisk
= HiiGetOpalDiskCB(gHiiConfiguration
.SelectedDiskIndex
);
823 if (OpalDisk
!= NULL
) {
824 OpalDiskUpdateStatus (OpalDisk
);
825 Ret
= OpalSupportGetAvailableActions(&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
, OpalDisk
->Owner
, &AvailActions
);
826 if (Ret
== TcgResultSuccess
) {
828 // Update actions, always allow PSID Revert
830 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.PsidRevert
== 1) ? HII_ACTION_PSID_REVERT
: HII_ACTION_NONE
;
833 // Always allow unlock to handle device migration
835 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.Unlock
== 1) ? HII_ACTION_UNLOCK
: HII_ACTION_NONE
;
837 if (!OpalFeatureEnabled (&OpalDisk
->SupportedAttributes
, &OpalDisk
->LockingFeature
)) {
838 if (OpalDisk
->Owner
== OpalOwnershipNobody
) {
839 gHiiConfiguration
.SelectedDiskAvailableActions
|= HII_ACTION_ENABLE_FEATURE
;
844 HiiSetFormString( STRING_TOKEN(STR_DISK_INFO_PSID_REVERT
), "PSID Revert to factory default");
846 DEBUG ((DEBUG_INFO
, "Feature disabled but ownership != nobody\n"));
849 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.Revert
== 1) ? HII_ACTION_REVERT
: HII_ACTION_NONE
;
850 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.AdminPass
== 1) ? HII_ACTION_SET_ADMIN_PWD
: HII_ACTION_NONE
;
851 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.UserPass
== 1) ? HII_ACTION_SET_USER_PWD
: HII_ACTION_NONE
;
852 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.SecureErase
== 1) ? HII_ACTION_SECURE_ERASE
: HII_ACTION_NONE
;
853 gHiiConfiguration
.SelectedDiskAvailableActions
|= (AvailActions
.DisableUser
== 1) ? HII_ACTION_DISABLE_USER
: HII_ACTION_NONE
;
855 HiiSetFormString (STRING_TOKEN(STR_DISK_INFO_PSID_REVERT
), "PSID Revert to factory default and Disable");
858 // Determine revert options for disk
859 // Default initialize keep user Data to be true
861 gHiiConfiguration
.OpalRequest
.KeepUserData
= 1;
862 if (AvailActions
.RevertKeepDataForced
) {
863 gHiiConfiguration
.KeepUserDataForced
= TRUE
;
868 GetSavedOpalRequest (OpalDisk
, &gHiiConfiguration
.OpalRequest
);
872 // Pass the current configuration to the BIOS
874 OpalHiiSetBrowserData ();
880 Send BlockSid request through TPM physical presence module.
882 @param PpRequest TPM physical presence operation request.
884 @retval EFI_SUCCESS Do the required action success.
885 @retval Others Other error occur.
889 HiiSetBlockSidAction (
896 ReturnCode
= Tcg2PhysicalPresenceLibSubmitRequestToPreOSFunction (PpRequest
, 0);
897 if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_SUCCESS
) {
898 Status
= EFI_SUCCESS
;
899 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_GENERAL_FAILURE
) {
900 Status
= EFI_OUT_OF_RESOURCES
;
901 } else if (ReturnCode
== TCG_PP_SUBMIT_REQUEST_TO_PREOS_NOT_IMPLEMENTED
) {
902 Status
= EFI_UNSUPPORTED
;
904 Status
= EFI_DEVICE_ERROR
;
911 This function processes the results of changes in configuration.
913 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
914 @param Configuration A null-terminated Unicode string in <ConfigResp>
916 @param Progress A pointer to a string filled in with the offset of
917 the most recent '&' before the first failing
918 name/value pair (or the beginning of the string if
919 the failure is in the first name/value pair) or
920 the terminating NULL if all was successful.
922 @retval EFI_SUCCESS The Results is processed successfully.
923 @retval EFI_INVALID_PARAMETER Configuration is NULL.
924 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
931 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
932 CONST EFI_STRING Configuration
,
936 if (Configuration
== NULL
|| Progress
== NULL
) {
937 return (EFI_INVALID_PARAMETER
);
940 *Progress
= Configuration
;
941 if (!HiiIsConfigHdrMatch (Configuration
, &gHiiSetupVariableGuid
, OpalPasswordStorageName
)) {
942 return EFI_NOT_FOUND
;
945 *Progress
= Configuration
+ StrLen (Configuration
);
951 This function allows a caller to extract the current configuration for one
952 or more named elements from the target driver.
954 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
955 @param Request A null-terminated Unicode string in
956 <ConfigRequest> format.
957 @param Progress On return, points to a character in the Request
958 string. Points to the string's null terminator if
959 request was successful. Points to the most recent
960 '&' before the first failing name/value pair (or
961 the beginning of the string if the failure is in
962 the first name/value pair) if the request was not
964 @param Results A null-terminated Unicode string in
965 <ConfigAltResp> format which has all values filled
966 in for the names in the Request string. String to
967 be allocated by the called function.
969 @retval EFI_SUCCESS The Results is filled with the requested values.
970 @retval EFI_OUT_OF_RESOURCES Not enough memory to store the results.
971 @retval EFI_INVALID_PARAMETER Request is illegal syntax, or unknown name.
972 @retval EFI_NOT_FOUND Routing data doesn't match any storage in this
979 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL
*This
,
980 CONST EFI_STRING Request
,
981 EFI_STRING
*Progress
,
986 EFI_STRING ConfigRequest
;
987 EFI_STRING ConfigRequestHdr
;
990 BOOLEAN AllocatedRequest
;
991 EFI_HANDLE DriverHandle
;
994 // Check for valid parameters
996 if (Progress
== NULL
|| Results
== NULL
) {
997 return (EFI_INVALID_PARAMETER
);
1000 *Progress
= Request
;
1001 if ((Request
!= NULL
) &&
1002 !HiiIsConfigHdrMatch (Request
, &gHiiSetupVariableGuid
, OpalPasswordStorageName
)) {
1003 return EFI_NOT_FOUND
;
1006 AllocatedRequest
= FALSE
;
1007 BufferSize
= sizeof (OPAL_HII_CONFIGURATION
);
1008 ConfigRequest
= Request
;
1009 if ((Request
== NULL
) || (StrStr (Request
, L
"OFFSET") == NULL
)) {
1011 // Request has no request element, construct full request string.
1012 // Allocate and fill a buffer large enough to hold the <ConfigHdr> template
1013 // followed by "&OFFSET=0&WIDTH=WWWWWWWWWWWWWWWW" followed by a Null-terminator
1015 DriverHandle
= HiiGetDriverImageHandleCB();
1016 ConfigRequestHdr
= HiiConstructConfigHdr (&gHiiSetupVariableGuid
, OpalPasswordStorageName
, DriverHandle
);
1017 Size
= (StrLen (ConfigRequestHdr
) + 32 + 1) * sizeof (CHAR16
);
1018 ConfigRequest
= AllocateZeroPool (Size
);
1019 if (ConfigRequest
== NULL
) {
1020 return EFI_OUT_OF_RESOURCES
;
1022 AllocatedRequest
= TRUE
;
1023 UnicodeSPrint (ConfigRequest
, Size
, L
"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr
, (UINT64
)BufferSize
);
1024 FreePool (ConfigRequestHdr
);
1028 // Convert Buffer Data to <ConfigResp> by helper function BlockToConfig( )
1030 Status
= gHiiConfigRouting
->BlockToConfig(
1033 (UINT8
*)&gHiiConfiguration
,
1034 sizeof(OPAL_HII_CONFIGURATION
),
1040 // Free the allocated config request string.
1042 if (AllocatedRequest
) {
1043 FreePool (ConfigRequest
);
1044 ConfigRequest
= NULL
;
1048 // Set Progress string to the original request string.
1050 if (Request
== NULL
) {
1052 } else if (StrStr (Request
, L
"OFFSET") == NULL
) {
1053 *Progress
= Request
+ StrLen (Request
);
1062 Pass the current system state to the bios via the hii_G_Configuration.
1066 OpalHiiSetBrowserData (
1071 &gHiiSetupVariableGuid
,
1072 (CHAR16
*)L
"OpalHiiConfig",
1073 sizeof(gHiiConfiguration
),
1074 (UINT8
*)&gHiiConfiguration
,
1082 Populate the hii_g_Configuraton with the browser Data.
1086 OpalHiiGetBrowserData (
1091 &gHiiSetupVariableGuid
,
1092 (CHAR16
*)L
"OpalHiiConfig",
1093 sizeof(gHiiConfiguration
),
1094 (UINT8
*)&gHiiConfiguration
1099 Set a string Value in a form.
1101 @param DestStringId The stringid which need to update.
1102 @param SrcAsciiStr The string nned to update.
1104 @retval EFI_SUCCESS Do the required action success.
1105 @retval Others Other error occur.
1110 EFI_STRING_ID DestStringId
,
1119 // Determine the Length of the sting
1121 Len
= ( UINT32
)AsciiStrLen( SrcAsciiStr
);
1124 // Allocate space for the unicode string, including terminator
1126 UniSize
= (Len
+ 1) * sizeof(CHAR16
);
1127 UniStr
= (CHAR16
*)AllocateZeroPool(UniSize
);
1130 // Copy into unicode string, then copy into string id
1132 AsciiStrToUnicodeStrS ( SrcAsciiStr
, UniStr
, Len
+ 1);
1135 // Update the string in the form
1137 if (HiiSetString(gHiiPackageListHandle
, DestStringId
, UniStr
, NULL
) == 0) {
1138 DEBUG ((DEBUG_INFO
, "HiiSetFormString( ) failed\n"));
1140 return (EFI_OUT_OF_RESOURCES
);
1148 return (EFI_SUCCESS
);
1152 Initialize the Opal disk base on the hardware info get from device.
1154 @param Dev The Opal device.
1156 @retval EFI_SUCESS Initialize the device success.
1157 @retval EFI_DEVICE_ERROR Get info from device failed.
1161 OpalDiskInitialize (
1162 IN OPAL_DRIVER_DEVICE
*Dev
1165 TCG_RESULT TcgResult
;
1166 OPAL_SESSION Session
;
1167 UINT8 ActiveDataRemovalMechanism
;
1168 UINT32 RemovalMechanishLists
[ResearvedMechanism
];
1170 ZeroMem(&Dev
->OpalDisk
, sizeof(OPAL_DISK
));
1171 Dev
->OpalDisk
.Sscp
= Dev
->Sscp
;
1172 Dev
->OpalDisk
.MediaId
= Dev
->MediaId
;
1173 Dev
->OpalDisk
.OpalDevicePath
= Dev
->OpalDevicePath
;
1175 ZeroMem(&Session
, sizeof(Session
));
1176 Session
.Sscp
= Dev
->Sscp
;
1177 Session
.MediaId
= Dev
->MediaId
;
1179 TcgResult
= OpalGetSupportedAttributesInfo (&Session
, &Dev
->OpalDisk
.SupportedAttributes
, &Dev
->OpalDisk
.OpalBaseComId
);
1180 if (TcgResult
!= TcgResultSuccess
) {
1181 return EFI_DEVICE_ERROR
;
1183 Session
.OpalBaseComId
= Dev
->OpalDisk
.OpalBaseComId
;
1185 TcgResult
= OpalUtilGetMsid (&Session
, Dev
->OpalDisk
.Msid
, OPAL_MSID_LENGHT
, &Dev
->OpalDisk
.MsidLength
);
1186 if (TcgResult
!= TcgResultSuccess
) {
1187 return EFI_DEVICE_ERROR
;
1190 if (Dev
->OpalDisk
.SupportedAttributes
.DataRemoval
) {
1191 TcgResult
= OpalUtilGetDataRemovalMechanismLists (&Session
, RemovalMechanishLists
);
1192 if (TcgResult
!= TcgResultSuccess
) {
1193 return EFI_DEVICE_ERROR
;
1196 TcgResult
= OpalUtilGetActiveDataRemovalMechanism (&Session
, Dev
->OpalDisk
.Msid
, Dev
->OpalDisk
.MsidLength
, &ActiveDataRemovalMechanism
);
1197 if (TcgResult
!= TcgResultSuccess
) {
1198 return EFI_DEVICE_ERROR
;
1201 Dev
->OpalDisk
.EstimateTimeCost
= RemovalMechanishLists
[ActiveDataRemovalMechanism
];
1204 return OpalDiskUpdateStatus (&Dev
->OpalDisk
);
1208 Update the device info.
1210 @param OpalDisk The Opal device.
1212 @retval EFI_SUCESS Initialize the device success.
1213 @retval EFI_DEVICE_ERROR Get info from device failed.
1214 @retval EFI_INVALID_PARAMETER Not get Msid info before get ownership info.
1218 OpalDiskUpdateStatus (
1222 TCG_RESULT TcgResult
;
1223 OPAL_SESSION Session
;
1225 ZeroMem(&Session
, sizeof(Session
));
1226 Session
.Sscp
= OpalDisk
->Sscp
;
1227 Session
.MediaId
= OpalDisk
->MediaId
;
1228 Session
.OpalBaseComId
= OpalDisk
->OpalBaseComId
;
1230 TcgResult
= OpalGetLockingInfo(&Session
, &OpalDisk
->LockingFeature
);
1231 if (TcgResult
!= TcgResultSuccess
) {
1232 return EFI_DEVICE_ERROR
;
1235 if (OpalDisk
->MsidLength
== 0) {
1236 return EFI_INVALID_PARAMETER
;
1239 // Base on the Msid info to get the ownership, so Msid info must get first.
1241 OpalDisk
->Owner
= OpalUtilDetermineOwnership(&Session
, OpalDisk
->Msid
, OpalDisk
->MsidLength
);