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