]> git.proxmox.com Git - mirror_edk2.git/blob - SecurityPkg/Tcg/Opal/OpalPassword/OpalHii.c
SecurityPkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / SecurityPkg / Tcg / Opal / OpalPassword / OpalHii.c
1 /** @file
2 Implementation of the HII for the Opal UEFI Driver.
3
4 Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include "OpalHii.h"
10 //
11 // Character definitions
12 //
13 #define UPPER_LOWER_CASE_OFFSET 0x20
14
15 //
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).
19 //
20 extern UINT8 OpalPasswordFormBin[];
21
22 //
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).
26 //
27 extern UINT8 OpalPasswordDxeStrings[];
28
29 CHAR16 OpalPasswordStorageName[] = L"OpalHiiConfig";
30
31 EFI_HII_CONFIG_ACCESS_PROTOCOL gHiiConfigAccessProtocol;
32
33 //
34 // Handle to the list of HII packages (forms and strings) for this driver
35 //
36 EFI_HII_HANDLE gHiiPackageListHandle = NULL;
37
38 //
39 // Package List GUID containing all form and string packages
40 //
41 const EFI_GUID gHiiPackageListGuid = PACKAGE_LIST_GUID;
42 const EFI_GUID gHiiSetupVariableGuid = SETUP_VARIABLE_GUID;
43
44 //
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.
48 //
49 OPAL_HII_CONFIGURATION gHiiConfiguration;
50
51 //
52 // The device path containing the VENDOR_DEVICE_PATH and EFI_DEVICE_PATH_PROTOCOL
53 //
54 HII_VENDOR_DEVICE_PATH gHiiVendorDevicePath = {
55 {
56 {
57 HARDWARE_DEVICE_PATH,
58 HW_VENDOR_DP,
59 {
60 (UINT8)(sizeof(VENDOR_DEVICE_PATH)),
61 (UINT8)((sizeof(VENDOR_DEVICE_PATH)) >> 8)
62 }
63 },
64 OPAL_PASSWORD_CONFIG_GUID
65 },
66 {
67 END_DEVICE_PATH_TYPE,
68 END_ENTIRE_DEVICE_PATH_SUBTYPE,
69 {
70 (UINT8)(END_DEVICE_PATH_LENGTH),
71 (UINT8)((END_DEVICE_PATH_LENGTH) >> 8)
72 }
73 }
74 };
75
76 /**
77 Get saved OPAL request.
78
79 @param[in] OpalDisk The disk needs to get the saved OPAL request.
80 @param[out] OpalRequest OPAL request got.
81
82 **/
83 VOID
84 GetSavedOpalRequest (
85 IN OPAL_DISK *OpalDisk,
86 OUT OPAL_REQUEST *OpalRequest
87 )
88 {
89 EFI_STATUS Status;
90 OPAL_REQUEST_VARIABLE *TempVariable;
91 OPAL_REQUEST_VARIABLE *Variable;
92 UINTN VariableSize;
93 EFI_DEVICE_PATH_PROTOCOL *DevicePathInVariable;
94 UINTN DevicePathSizeInVariable;
95 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
96 UINTN DevicePathSize;
97
98 DEBUG ((DEBUG_INFO, "%a() - enter\n", __FUNCTION__));
99
100 Variable = NULL;
101 VariableSize = 0;
102
103 Status = GetVariable2 (
104 OPAL_REQUEST_VARIABLE_NAME,
105 &gHiiSetupVariableGuid,
106 (VOID **) &Variable,
107 &VariableSize
108 );
109 if (EFI_ERROR (Status) || (Variable == NULL)) {
110 return;
111 }
112
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)) {
123 //
124 // Found the node for the OPAL device.
125 // Get the OPAL request.
126 //
127 CopyMem (OpalRequest, &TempVariable->OpalRequest, sizeof (OPAL_REQUEST));
128 DEBUG ((
129 DEBUG_INFO,
130 "OpalRequest got: 0x%x\n",
131 *OpalRequest
132 ));
133 break;
134 }
135 VariableSize -= TempVariable->Length;
136 TempVariable = (OPAL_REQUEST_VARIABLE *) ((UINTN) TempVariable + TempVariable->Length);
137 }
138
139 FreePool (Variable);
140
141 DEBUG ((DEBUG_INFO, "%a() - exit\n", __FUNCTION__));
142 }
143
144 /**
145 Save OPAL request.
146
147 @param[in] OpalDisk The disk has OPAL request to save.
148 @param[in] OpalRequest OPAL request to save.
149
150 **/
151 VOID
152 SaveOpalRequest (
153 IN OPAL_DISK *OpalDisk,
154 IN OPAL_REQUEST OpalRequest
155 )
156 {
157 EFI_STATUS Status;
158 OPAL_REQUEST_VARIABLE *TempVariable;
159 UINTN TempVariableSize;
160 OPAL_REQUEST_VARIABLE *Variable;
161 UINTN VariableSize;
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;
168
169 DEBUG ((DEBUG_INFO, "%a() - enter\n", __FUNCTION__));
170
171 DEBUG ((
172 DEBUG_INFO,
173 "OpalRequest to save: 0x%x\n",
174 OpalRequest
175 ));
176
177 Variable = NULL;
178 VariableSize = 0;
179 NewVariable = NULL;
180 NewVariableSize = 0;
181
182 Status = GetVariable2 (
183 OPAL_REQUEST_VARIABLE_NAME,
184 &gHiiSetupVariableGuid,
185 (VOID **) &Variable,
186 &VariableSize
187 );
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)) {
200 //
201 // Found the node for the OPAL device.
202 // Update the OPAL request.
203 //
204 CopyMem (&TempVariable->OpalRequest, &OpalRequest, sizeof (OPAL_REQUEST));
205 NewVariable = Variable;
206 NewVariableSize = VariableSize;
207 break;
208 }
209 TempVariableSize -= TempVariable->Length;
210 TempVariable = (OPAL_REQUEST_VARIABLE *) ((UINTN) TempVariable + TempVariable->Length);
211 }
212 if (NewVariable == NULL) {
213 //
214 // The node for the OPAL device is not found.
215 // Create node for the OPAL device.
216 //
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);
228 }
229 } else {
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);
239 }
240 Status = gRT->SetVariable (
241 OPAL_REQUEST_VARIABLE_NAME,
242 (EFI_GUID *) &gHiiSetupVariableGuid,
243 EFI_VARIABLE_NON_VOLATILE | EFI_VARIABLE_BOOTSERVICE_ACCESS,
244 NewVariableSize,
245 NewVariable
246 );
247 if (EFI_ERROR (Status)) {
248 DEBUG ((DEBUG_INFO, "OpalRequest variable set failed (%r)\n", Status));
249 }
250 if (NewVariable != Variable) {
251 FreePool (NewVariable);
252 }
253 if (Variable != NULL) {
254 FreePool (Variable);
255 }
256
257 DEBUG ((DEBUG_INFO, "%a() - exit\n", __FUNCTION__));
258 }
259
260 /**
261 Sets the current system state of global config variables.
262
263 **/
264 VOID
265 HiiSetCurrentConfiguration(
266 VOID
267 )
268 {
269 UINT32 PpStorageFlag;
270 EFI_STRING NewString;
271
272 gHiiConfiguration.NumDisks = GetDeviceCount();
273
274 //
275 // Update the BlockSID status string.
276 //
277 PpStorageFlag = Tcg2PhysicalPresenceLibGetManagementFlags ();
278
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"));
283 return;
284 }
285 } else {
286 NewString = HiiGetString (gHiiPackageListHandle, STRING_TOKEN(STR_DISABLED), NULL);
287 if (NewString == NULL) {
288 DEBUG ((DEBUG_INFO, "HiiSetCurrentConfiguration: HiiGetString( ) failed\n"));
289 return;
290 }
291 }
292 HiiSetString(gHiiPackageListHandle, STRING_TOKEN(STR_BLOCKSID_STATUS1), NewString, NULL);
293 FreePool (NewString);
294
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"));
299 return;
300 }
301 } else {
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"));
305 return;
306 }
307 }
308 HiiSetString(gHiiPackageListHandle, STRING_TOKEN(STR_BLOCKSID_STATUS2), NewString, NULL);
309 FreePool (NewString);
310
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"));
315 return;
316 }
317 } else {
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"));
321 return;
322 }
323 }
324 HiiSetString(gHiiPackageListHandle, STRING_TOKEN(STR_BLOCKSID_STATUS3), NewString, NULL);
325 FreePool (NewString);
326 }
327
328 /**
329 Install the HII related resources.
330
331 @retval EFI_SUCCESS Install all the resources success.
332 @retval other Error occur when install the resources.
333 **/
334 EFI_STATUS
335 HiiInstall(
336 VOID
337 )
338 {
339 EFI_STATUS Status;
340 EFI_HANDLE DriverHandle;
341
342 //
343 // Clear the global configuration.
344 //
345 ZeroMem(&gHiiConfiguration, sizeof(gHiiConfiguration));
346
347 //
348 // Obtain the driver handle that the BIOS assigned us
349 //
350 DriverHandle = HiiGetDriverImageHandleCB();
351
352 //
353 // Populate the config access protocol with the three functions we are publishing
354 //
355 gHiiConfigAccessProtocol.ExtractConfig = ExtractConfig;
356 gHiiConfigAccessProtocol.RouteConfig = RouteConfig;
357 gHiiConfigAccessProtocol.Callback = DriverCallback;
358
359 //
360 // Associate the required protocols with our driver handle
361 //
362 Status = gBS->InstallMultipleProtocolInterfaces(
363 &DriverHandle,
364 &gEfiHiiConfigAccessProtocolGuid,
365 &gHiiConfigAccessProtocol, // HII callback
366 &gEfiDevicePathProtocolGuid,
367 &gHiiVendorDevicePath, // required for HII callback allow all disks to be shown in same hii
368 NULL
369 );
370
371 if (EFI_ERROR(Status)) {
372 return Status;
373 }
374
375 return OpalHiiAddPackages();
376 }
377
378 /**
379 Install the HII form and string packages.
380
381 @retval EFI_SUCCESS Install all the resources success.
382 @retval EFI_OUT_OF_RESOURCES Out of resource error.
383 **/
384 EFI_STATUS
385 OpalHiiAddPackages(
386 VOID
387 )
388 {
389 EFI_HANDLE DriverHandle;
390
391 DriverHandle = HiiGetDriverImageHandleCB();
392
393 //
394 // Publish the HII form and HII string packages
395 //
396 gHiiPackageListHandle = HiiAddPackages(
397 &gHiiPackageListGuid,
398 DriverHandle,
399 OpalPasswordDxeStrings,
400 OpalPasswordFormBin,
401 (VOID*)NULL
402 );
403
404 //
405 // Make sure the packages installed successfully
406 //
407 if (gHiiPackageListHandle == NULL) {
408 DEBUG ((DEBUG_INFO, "OpalHiiAddPackages failed\n"));
409 return EFI_OUT_OF_RESOURCES;
410 }
411
412 return EFI_SUCCESS;
413 }
414
415 /**
416 Uninstall the HII capability.
417
418 @retval EFI_SUCCESS Uninstall all the resources success.
419 @retval others Other errors occur when unistall the hii resource.
420 **/
421 EFI_STATUS
422 HiiUninstall(
423 VOID
424 )
425 {
426 EFI_STATUS Status;
427
428 //
429 // Remove the packages we've provided to the BIOS
430 //
431 HiiRemovePackages(gHiiPackageListHandle);
432
433 //
434 // Remove the protocols from our driver handle
435 //
436 Status = gBS->UninstallMultipleProtocolInterfaces(
437 HiiGetDriverImageHandleCB(),
438 &gEfiHiiConfigAccessProtocolGuid,
439 &gHiiConfigAccessProtocol, // HII callback
440 &gEfiDevicePathProtocolGuid,
441 &gHiiVendorDevicePath, // required for HII callback
442 NULL
443 );
444 if (EFI_ERROR(Status)) {
445 DEBUG ((DEBUG_INFO, "Cannot uninstall Hii Protocols: %r\n", Status));
446 }
447
448 return Status;
449 }
450
451 /**
452 Updates the main menu form.
453
454 @retval EFI_SUCCESS update the main form success.
455 **/
456 EFI_STATUS
457 HiiPopulateMainMenuForm (
458 VOID
459 )
460 {
461 UINT8 Index;
462 CHAR8 *DiskName;
463 EFI_STRING_ID DiskNameId;
464 OPAL_DISK *OpalDisk;
465
466 HiiSetCurrentConfiguration();
467
468 gHiiConfiguration.SupportedDisks = 0;
469
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;
478 }
479 HiiSetFormString(DiskNameId, DiskName);
480 }
481 }
482
483 OpalHiiSetBrowserData ();
484 return EFI_SUCCESS;
485 }
486
487 /**
488 Get disk name string id.
489
490 @param DiskIndex The input disk index info.
491
492 @retval The disk name string id.
493
494 **/
495 EFI_STRING_ID
496 GetDiskNameStringId(
497 UINT8 DiskIndex
498 )
499 {
500 switch (DiskIndex) {
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);
507 }
508 return 0;
509 }
510
511 /**
512 Confirm whether user truly want to do the revert action.
513
514 @param OpalDisk The device which need to do the revert action.
515
516 @retval EFI_SUCCESS Confirmed user want to do the revert action.
517 **/
518 EFI_STATUS
519 HiiConfirmRevertAction (
520 IN OPAL_DISK *OpalDisk
521
522 )
523 {
524 CHAR16 Unicode[512];
525 EFI_INPUT_KEY Key;
526 CHAR16 ApproveResponse;
527 CHAR16 RejectResponse;
528
529 //
530 // When the estimate cost time bigger than MAX_ACCEPTABLE_REVERTING_TIME, pop up dialog to let user confirm
531 // the revert action.
532 //
533 if (OpalDisk->EstimateTimeCost < MAX_ACCEPTABLE_REVERTING_TIME) {
534 return EFI_SUCCESS;
535 }
536
537 ApproveResponse = L'Y';
538 RejectResponse = L'N';
539
540 UnicodeSPrint(Unicode, StrSize(L"WARNING: Revert device needs about ####### seconds"), L"WARNING: Revert device needs about %d seconds", OpalDisk->EstimateTimeCost);
541
542 do {
543 CreatePopUp(
544 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,
545 &Key,
546 Unicode,
547 L" System should not be powered off until revert completion ",
548 L" ",
549 L" Press 'Y/y' to continue, press 'N/n' to cancal ",
550 NULL
551 );
552 } while (
553 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (ApproveResponse | UPPER_LOWER_CASE_OFFSET)) &&
554 ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) != (RejectResponse | UPPER_LOWER_CASE_OFFSET))
555 );
556
557 if ((Key.UnicodeChar | UPPER_LOWER_CASE_OFFSET) == (RejectResponse | UPPER_LOWER_CASE_OFFSET)) {
558 return EFI_ABORTED;
559 }
560
561 return EFI_SUCCESS;
562 }
563
564 /**
565 This function processes the results of changes in configuration.
566
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
571 of data to expect.
572 @param Type The type of value for the question.
573 @param Value A pointer to the data being sent to the original
574 exporting driver.
575 @param ActionRequest On return, points to the action requested by the
576 callback function.
577
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
583 callback.
584
585 **/
586 EFI_STATUS
587 EFIAPI
588 DriverCallback(
589 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
590 EFI_BROWSER_ACTION Action,
591 EFI_QUESTION_ID QuestionId,
592 UINT8 Type,
593 EFI_IFR_TYPE_VALUE *Value,
594 EFI_BROWSER_ACTION_REQUEST *ActionRequest
595 )
596 {
597 HII_KEY HiiKey;
598 UINT8 HiiKeyId;
599 UINT32 PpRequest;
600 OPAL_DISK *OpalDisk;
601
602 if (ActionRequest != NULL) {
603 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_NONE;
604 } else {
605 return EFI_INVALID_PARAMETER;
606 }
607
608 //
609 // If QuestionId is an auto-generated key (label, empty line, etc.), ignore it.
610 //
611 if ((QuestionId & HII_KEY_FLAG) == 0) {
612 return EFI_SUCCESS;
613 }
614
615 HiiKey.Raw = QuestionId;
616 HiiKeyId = (UINT8) HiiKey.KeyBits.Id;
617
618 if (Action == EFI_BROWSER_ACTION_FORM_OPEN) {
619 switch (HiiKeyId) {
620 case HII_KEY_ID_VAR_SUPPORTED_DISKS:
621 DEBUG ((DEBUG_INFO, "HII_KEY_ID_VAR_SUPPORTED_DISKS\n"));
622 return HiiPopulateMainMenuForm ();
623
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();
627 }
628 } else if (Action == EFI_BROWSER_ACTION_CHANGING) {
629 switch (HiiKeyId) {
630 case HII_KEY_ID_GOTO_DISK_INFO:
631 return HiiSelectDisk((UINT8)HiiKey.KeyBits.Index);
632
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);
638 } else {
639 ASSERT (FALSE);
640 return EFI_SUCCESS;
641 }
642
643 }
644 } else if (Action == EFI_BROWSER_ACTION_CHANGED) {
645 switch (HiiKeyId) {
646 case HII_KEY_ID_BLOCKSID:
647 switch (Value->u8) {
648 case 0:
649 PpRequest = TCG2_PHYSICAL_PRESENCE_NO_ACTION;
650 break;
651
652 case 1:
653 PpRequest = TCG2_PHYSICAL_PRESENCE_ENABLE_BLOCK_SID;
654 break;
655
656 case 2:
657 PpRequest = TCG2_PHYSICAL_PRESENCE_DISABLE_BLOCK_SID;
658 break;
659
660 case 3:
661 PpRequest = TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_TRUE;
662 break;
663
664 case 4:
665 PpRequest = TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_ENABLE_BLOCK_SID_FUNC_FALSE;
666 break;
667
668 case 5:
669 PpRequest = TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_TRUE;
670 break;
671
672 case 6:
673 PpRequest = TCG2_PHYSICAL_PRESENCE_SET_PP_REQUIRED_FOR_DISABLE_BLOCK_SID_FUNC_FALSE;
674 break;
675
676 default:
677 PpRequest = TCG2_PHYSICAL_PRESENCE_NO_ACTION;
678 DEBUG ((DEBUG_ERROR, "Invalid value input!\n"));
679 break;
680 }
681 HiiSetBlockSidAction(PpRequest);
682
683 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
684 return EFI_SUCCESS;
685
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);
692 }
693 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
694 return EFI_SUCCESS;
695
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);
702 }
703 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
704 return EFI_SUCCESS;
705
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);
712 }
713 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
714 return EFI_SUCCESS;
715
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);
722 }
723 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
724 return EFI_SUCCESS;
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);
731 }
732 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
733 return EFI_SUCCESS;
734
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);
741 }
742 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
743 return EFI_SUCCESS;
744
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);
751 }
752 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
753 return EFI_SUCCESS;
754
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);
761 }
762 *ActionRequest = EFI_BROWSER_ACTION_REQUEST_FORM_APPLY;
763 return EFI_SUCCESS;
764
765 default:
766 break;
767 }
768 }
769
770 return EFI_UNSUPPORTED;
771 }
772
773 /**
774 Update the global Disk index info.
775
776 @param Index The input disk index info.
777
778 @retval EFI_SUCCESS Update the disk index info success.
779
780 **/
781 EFI_STATUS
782 HiiSelectDisk(
783 UINT8 Index
784 )
785 {
786 OpalHiiGetBrowserData();
787 gHiiConfiguration.SelectedDiskIndex = Index;
788 OpalHiiSetBrowserData ();
789
790 return EFI_SUCCESS;
791 }
792
793 /**
794 Draws the disk info form.
795
796 @retval EFI_SUCCESS Draw the disk info success.
797
798 **/
799 EFI_STATUS
800 HiiPopulateDiskInfoForm(
801 VOID
802 )
803 {
804 OPAL_DISK* OpalDisk;
805 OPAL_DISK_ACTIONS AvailActions;
806 TCG_RESULT Ret;
807 CHAR8 *DiskName;
808
809 OpalHiiGetBrowserData();
810
811 DiskName = HiiDiskGetNameCB (gHiiConfiguration.SelectedDiskIndex);
812 if (DiskName == NULL) {
813 return EFI_UNSUPPORTED;
814 }
815 HiiSetFormString(STRING_TOKEN(STR_DISK_INFO_SELECTED_DISK_NAME), DiskName);
816
817 gHiiConfiguration.SelectedDiskAvailableActions = HII_ACTION_NONE;
818 ZeroMem (&gHiiConfiguration.OpalRequest, sizeof (OPAL_REQUEST));
819 gHiiConfiguration.KeepUserDataForced = FALSE;
820
821 OpalDisk = HiiGetOpalDiskCB(gHiiConfiguration.SelectedDiskIndex);
822
823 if (OpalDisk != NULL) {
824 OpalDiskUpdateStatus (OpalDisk);
825 Ret = OpalSupportGetAvailableActions(&OpalDisk->SupportedAttributes, &OpalDisk->LockingFeature, OpalDisk->Owner, &AvailActions);
826 if (Ret == TcgResultSuccess) {
827 //
828 // Update actions, always allow PSID Revert
829 //
830 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.PsidRevert == 1) ? HII_ACTION_PSID_REVERT : HII_ACTION_NONE;
831
832 //
833 // Always allow unlock to handle device migration
834 //
835 gHiiConfiguration.SelectedDiskAvailableActions |= (AvailActions.Unlock == 1) ? HII_ACTION_UNLOCK : HII_ACTION_NONE;
836
837 if (!OpalFeatureEnabled (&OpalDisk->SupportedAttributes, &OpalDisk->LockingFeature)) {
838 if (OpalDisk->Owner == OpalOwnershipNobody) {
839 gHiiConfiguration.SelectedDiskAvailableActions |= HII_ACTION_ENABLE_FEATURE;
840
841 //
842 // Update strings
843 //
844 HiiSetFormString( STRING_TOKEN(STR_DISK_INFO_PSID_REVERT), "PSID Revert to factory default");
845 } else {
846 DEBUG ((DEBUG_INFO, "Feature disabled but ownership != nobody\n"));
847 }
848 } else {
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;
854
855 HiiSetFormString (STRING_TOKEN(STR_DISK_INFO_PSID_REVERT), "PSID Revert to factory default and Disable");
856
857 //
858 // Determine revert options for disk
859 // Default initialize keep user Data to be true
860 //
861 gHiiConfiguration.OpalRequest.KeepUserData = 1;
862 if (AvailActions.RevertKeepDataForced) {
863 gHiiConfiguration.KeepUserDataForced = TRUE;
864 }
865 }
866 }
867
868 GetSavedOpalRequest (OpalDisk, &gHiiConfiguration.OpalRequest);
869 }
870
871 //
872 // Pass the current configuration to the BIOS
873 //
874 OpalHiiSetBrowserData ();
875
876 return EFI_SUCCESS;
877 }
878
879 /**
880 Send BlockSid request through TPM physical presence module.
881
882 @param PpRequest TPM physical presence operation request.
883
884 @retval EFI_SUCCESS Do the required action success.
885 @retval Others Other error occur.
886
887 **/
888 EFI_STATUS
889 HiiSetBlockSidAction (
890 IN UINT32 PpRequest
891 )
892 {
893 UINT32 ReturnCode;
894 EFI_STATUS Status;
895
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;
903 } else {
904 Status = EFI_DEVICE_ERROR;
905 }
906
907 return Status;
908 }
909
910 /**
911 This function processes the results of changes in configuration.
912
913 @param This Points to the EFI_HII_CONFIG_ACCESS_PROTOCOL.
914 @param Configuration A null-terminated Unicode string in <ConfigResp>
915 format.
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.
921
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
925 driver.
926
927 **/
928 EFI_STATUS
929 EFIAPI
930 RouteConfig(
931 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
932 CONST EFI_STRING Configuration,
933 EFI_STRING *Progress
934 )
935 {
936 if (Configuration == NULL || Progress == NULL) {
937 return (EFI_INVALID_PARAMETER);
938 }
939
940 *Progress = Configuration;
941 if (!HiiIsConfigHdrMatch (Configuration, &gHiiSetupVariableGuid, OpalPasswordStorageName)) {
942 return EFI_NOT_FOUND;
943 }
944
945 *Progress = Configuration + StrLen (Configuration);
946
947 return EFI_SUCCESS;
948 }
949
950 /**
951 This function allows a caller to extract the current configuration for one
952 or more named elements from the target driver.
953
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
963 successful.
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.
968
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
973 driver.
974
975 **/
976 EFI_STATUS
977 EFIAPI
978 ExtractConfig(
979 CONST EFI_HII_CONFIG_ACCESS_PROTOCOL *This,
980 CONST EFI_STRING Request,
981 EFI_STRING *Progress,
982 EFI_STRING *Results
983 )
984 {
985 EFI_STATUS Status;
986 EFI_STRING ConfigRequest;
987 EFI_STRING ConfigRequestHdr;
988 UINTN BufferSize;
989 UINTN Size;
990 BOOLEAN AllocatedRequest;
991 EFI_HANDLE DriverHandle;
992
993 //
994 // Check for valid parameters
995 //
996 if (Progress == NULL || Results == NULL) {
997 return (EFI_INVALID_PARAMETER);
998 }
999
1000 *Progress = Request;
1001 if ((Request != NULL) &&
1002 !HiiIsConfigHdrMatch (Request, &gHiiSetupVariableGuid, OpalPasswordStorageName)) {
1003 return EFI_NOT_FOUND;
1004 }
1005
1006 AllocatedRequest = FALSE;
1007 BufferSize = sizeof (OPAL_HII_CONFIGURATION);
1008 ConfigRequest = Request;
1009 if ((Request == NULL) || (StrStr (Request, L"OFFSET") == NULL)) {
1010 //
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
1014 //
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;
1021 }
1022 AllocatedRequest = TRUE;
1023 UnicodeSPrint (ConfigRequest, Size, L"%s&OFFSET=0&WIDTH=%016LX", ConfigRequestHdr, (UINT64)BufferSize);
1024 FreePool (ConfigRequestHdr);
1025 }
1026
1027 //
1028 // Convert Buffer Data to <ConfigResp> by helper function BlockToConfig( )
1029 //
1030 Status = gHiiConfigRouting->BlockToConfig(
1031 gHiiConfigRouting,
1032 ConfigRequest,
1033 (UINT8*)&gHiiConfiguration,
1034 sizeof(OPAL_HII_CONFIGURATION),
1035 Results,
1036 Progress
1037 );
1038
1039 //
1040 // Free the allocated config request string.
1041 //
1042 if (AllocatedRequest) {
1043 FreePool (ConfigRequest);
1044 ConfigRequest = NULL;
1045 }
1046
1047 //
1048 // Set Progress string to the original request string.
1049 //
1050 if (Request == NULL) {
1051 *Progress = NULL;
1052 } else if (StrStr (Request, L"OFFSET") == NULL) {
1053 *Progress = Request + StrLen (Request);
1054 }
1055
1056 return (Status);
1057 }
1058
1059
1060 /**
1061
1062 Pass the current system state to the bios via the hii_G_Configuration.
1063
1064 **/
1065 VOID
1066 OpalHiiSetBrowserData (
1067 VOID
1068 )
1069 {
1070 HiiSetBrowserData(
1071 &gHiiSetupVariableGuid,
1072 (CHAR16*)L"OpalHiiConfig",
1073 sizeof(gHiiConfiguration),
1074 (UINT8*)&gHiiConfiguration,
1075 NULL
1076 );
1077 }
1078
1079
1080 /**
1081
1082 Populate the hii_g_Configuraton with the browser Data.
1083
1084 **/
1085 VOID
1086 OpalHiiGetBrowserData (
1087 VOID
1088 )
1089 {
1090 HiiGetBrowserData(
1091 &gHiiSetupVariableGuid,
1092 (CHAR16*)L"OpalHiiConfig",
1093 sizeof(gHiiConfiguration),
1094 (UINT8*)&gHiiConfiguration
1095 );
1096 }
1097
1098 /**
1099 Set a string Value in a form.
1100
1101 @param DestStringId The stringid which need to update.
1102 @param SrcAsciiStr The string nned to update.
1103
1104 @retval EFI_SUCCESS Do the required action success.
1105 @retval Others Other error occur.
1106
1107 **/
1108 EFI_STATUS
1109 HiiSetFormString(
1110 EFI_STRING_ID DestStringId,
1111 CHAR8 *SrcAsciiStr
1112 )
1113 {
1114 UINT32 Len;
1115 UINT32 UniSize;
1116 CHAR16* UniStr;
1117
1118 //
1119 // Determine the Length of the sting
1120 //
1121 Len = ( UINT32 )AsciiStrLen( SrcAsciiStr );
1122
1123 //
1124 // Allocate space for the unicode string, including terminator
1125 //
1126 UniSize = (Len + 1) * sizeof(CHAR16);
1127 UniStr = (CHAR16*)AllocateZeroPool(UniSize);
1128
1129 //
1130 // Copy into unicode string, then copy into string id
1131 //
1132 AsciiStrToUnicodeStrS ( SrcAsciiStr, UniStr, Len + 1);
1133
1134 //
1135 // Update the string in the form
1136 //
1137 if (HiiSetString(gHiiPackageListHandle, DestStringId, UniStr, NULL) == 0) {
1138 DEBUG ((DEBUG_INFO, "HiiSetFormString( ) failed\n"));
1139 FreePool(UniStr);
1140 return (EFI_OUT_OF_RESOURCES);
1141 }
1142
1143 //
1144 // Free the memory
1145 //
1146 FreePool(UniStr);
1147
1148 return (EFI_SUCCESS);
1149 }
1150
1151 /**
1152 Initialize the Opal disk base on the hardware info get from device.
1153
1154 @param Dev The Opal device.
1155
1156 @retval EFI_SUCESS Initialize the device success.
1157 @retval EFI_DEVICE_ERROR Get info from device failed.
1158
1159 **/
1160 EFI_STATUS
1161 OpalDiskInitialize (
1162 IN OPAL_DRIVER_DEVICE *Dev
1163 )
1164 {
1165 TCG_RESULT TcgResult;
1166 OPAL_SESSION Session;
1167 UINT8 ActiveDataRemovalMechanism;
1168 UINT32 RemovalMechanishLists[ResearvedMechanism];
1169
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;
1174
1175 ZeroMem(&Session, sizeof(Session));
1176 Session.Sscp = Dev->Sscp;
1177 Session.MediaId = Dev->MediaId;
1178
1179 TcgResult = OpalGetSupportedAttributesInfo (&Session, &Dev->OpalDisk.SupportedAttributes, &Dev->OpalDisk.OpalBaseComId);
1180 if (TcgResult != TcgResultSuccess) {
1181 return EFI_DEVICE_ERROR;
1182 }
1183 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;
1184
1185 TcgResult = OpalUtilGetMsid (&Session, Dev->OpalDisk.Msid, OPAL_MSID_LENGHT, &Dev->OpalDisk.MsidLength);
1186 if (TcgResult != TcgResultSuccess) {
1187 return EFI_DEVICE_ERROR;
1188 }
1189
1190 if (Dev->OpalDisk.SupportedAttributes.DataRemoval) {
1191 TcgResult = OpalUtilGetDataRemovalMechanismLists (&Session, RemovalMechanishLists);
1192 if (TcgResult != TcgResultSuccess) {
1193 return EFI_DEVICE_ERROR;
1194 }
1195
1196 TcgResult = OpalUtilGetActiveDataRemovalMechanism (&Session, Dev->OpalDisk.Msid, Dev->OpalDisk.MsidLength, &ActiveDataRemovalMechanism);
1197 if (TcgResult != TcgResultSuccess) {
1198 return EFI_DEVICE_ERROR;
1199 }
1200
1201 Dev->OpalDisk.EstimateTimeCost = RemovalMechanishLists[ActiveDataRemovalMechanism];
1202 }
1203
1204 return OpalDiskUpdateStatus (&Dev->OpalDisk);
1205 }
1206
1207 /**
1208 Update the device info.
1209
1210 @param OpalDisk The Opal device.
1211
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.
1215
1216 **/
1217 EFI_STATUS
1218 OpalDiskUpdateStatus (
1219 OPAL_DISK *OpalDisk
1220 )
1221 {
1222 TCG_RESULT TcgResult;
1223 OPAL_SESSION Session;
1224
1225 ZeroMem(&Session, sizeof(Session));
1226 Session.Sscp = OpalDisk->Sscp;
1227 Session.MediaId = OpalDisk->MediaId;
1228 Session.OpalBaseComId = OpalDisk->OpalBaseComId;
1229
1230 TcgResult = OpalGetLockingInfo(&Session, &OpalDisk->LockingFeature);
1231 if (TcgResult != TcgResultSuccess) {
1232 return EFI_DEVICE_ERROR;
1233 }
1234
1235 if (OpalDisk->MsidLength == 0) {
1236 return EFI_INVALID_PARAMETER;
1237 } else {
1238 //
1239 // Base on the Msid info to get the ownership, so Msid info must get first.
1240 //
1241 OpalDisk->Owner = OpalUtilDetermineOwnership(&Session, OpalDisk->Msid, OpalDisk->MsidLength);
1242 }
1243
1244 return EFI_SUCCESS;
1245 }
1246