SecurityPkg/OpalPassword: Fixed input correct password not works issue
[mirror_edk2.git] / SecurityPkg / Tcg / Opal / OpalPassword / OpalDriver.c
CommitLineData
112e584b
SZ
1/** @file\r
2 Entrypoint of Opal UEFI Driver and contains all the logic to\r
3 register for new Opal device instances.\r
4\r
5Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>\r
6This program and the accompanying materials\r
7are licensed and made available under the terms and conditions of the BSD License\r
8which accompanies this distribution. The full text of the license may be found at\r
9http://opensource.org/licenses/bsd-license.php\r
10\r
11THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
12WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
13\r
14**/\r
15\r
16// This UEFI driver consumes EFI_STORAGE_SECURITY_PROTOCOL instances and installs an\r
17// HII GUI to manage Opal features if the device is Opal capable\r
18// If the Opal device is being managed by the UEFI Driver, it shall provide a popup\r
19// window during boot requesting a user password\r
20\r
21#include "OpalDriver.h"\r
22#include "OpalHii.h"\r
23\r
24EFI_GUID mOpalDeviceAtaGuid = OPAL_DEVICE_ATA_GUID;\r
25EFI_GUID mOpalDeviceNvmeGuid = OPAL_DEVICE_NVME_GUID;\r
26\r
27BOOLEAN mOpalEndOfDxe = FALSE;\r
28OPAL_REQUEST_VARIABLE *mOpalRequestVariable = NULL;\r
29UINTN mOpalRequestVariableSize = 0;\r
aa085730 30CHAR16 mPopUpString[100];\r
112e584b
SZ
31\r
32typedef struct {\r
33 UINT32 Address;\r
34 S3_BOOT_SCRIPT_LIB_WIDTH Width;\r
35} OPAL_HC_PCI_REGISTER_SAVE;\r
36\r
37//\r
38// To unlock the Intel SATA controller at S3 Resume, restored the following registers.\r
39//\r
40const OPAL_HC_PCI_REGISTER_SAVE mSataHcRegisterSaveTemplate[] = {\r
41 {0x9, S3BootScriptWidthUint8},\r
42 {0x10, S3BootScriptWidthUint32},\r
43 {0x14, S3BootScriptWidthUint32},\r
44 {0x18, S3BootScriptWidthUint32},\r
45 {0x1C, S3BootScriptWidthUint32},\r
46 {0x20, S3BootScriptWidthUint32},\r
47 {0x24, S3BootScriptWidthUint32},\r
48 {0x3c, S3BootScriptWidthUint8},\r
49 {0x3d, S3BootScriptWidthUint8},\r
50 {0x40, S3BootScriptWidthUint16},\r
51 {0x42, S3BootScriptWidthUint16},\r
52 {0x92, S3BootScriptWidthUint16},\r
53 {0x94, S3BootScriptWidthUint32},\r
54 {0x9C, S3BootScriptWidthUint32},\r
55 {0x4, S3BootScriptWidthUint16},\r
56};\r
57\r
58OPAL_DRIVER mOpalDriver;\r
59\r
60//\r
61// Globals\r
62//\r
63EFI_DRIVER_BINDING_PROTOCOL gOpalDriverBinding = {\r
64 OpalEfiDriverBindingSupported,\r
65 OpalEfiDriverBindingStart,\r
66 OpalEfiDriverBindingStop,\r
67 0x1b,\r
68 NULL,\r
69 NULL\r
70};\r
71\r
72/**\r
73\r
74 The function determines the available actions for the OPAL_DISK provided.\r
75\r
76 @param[in] SupportedAttributes The supported attributes for the device.\r
77 @param[in] LockingFeature The locking status for the device.\r
78 @param[in] OwnerShip The ownership for the device.\r
79 @param[out] AvalDiskActions Pointer to fill-out with appropriate disk actions.\r
80\r
81**/\r
82TCG_RESULT\r
83EFIAPI\r
84OpalSupportGetAvailableActions(\r
85 IN OPAL_DISK_SUPPORT_ATTRIBUTE *SupportedAttributes,\r
86 IN TCG_LOCKING_FEATURE_DESCRIPTOR *LockingFeature,\r
87 IN UINT16 OwnerShip,\r
88 OUT OPAL_DISK_ACTIONS *AvalDiskActions\r
89 )\r
90{\r
91 BOOLEAN ExistingPassword;\r
92\r
93 NULL_CHECK(AvalDiskActions);\r
94\r
95 AvalDiskActions->AdminPass = 1;\r
96 AvalDiskActions->UserPass = 0;\r
97 AvalDiskActions->DisableUser = 0;\r
98 AvalDiskActions->Unlock = 0;\r
99\r
100 //\r
101 // Revert is performed on locking sp, so only allow if locking sp is enabled\r
102 //\r
103 if (LockingFeature->LockingEnabled) {\r
104 AvalDiskActions->Revert = 1;\r
105 }\r
106\r
107 //\r
40d32e79 108 // Psid revert is available for any device with media encryption support or pyrite 2.0 type support.\r
112e584b 109 //\r
40d32e79 110 if (SupportedAttributes->PyriteSscV2 || SupportedAttributes->MediaEncryption) {\r
112e584b
SZ
111\r
112 //\r
40d32e79 113 // Only allow psid revert if media encryption is enabled or pyrite 2.0 type support..\r
112e584b
SZ
114 // Otherwise, someone who steals a disk can psid revert the disk and the user Data is still\r
115 // intact and accessible\r
116 //\r
117 AvalDiskActions->PsidRevert = 1;\r
118 AvalDiskActions->RevertKeepDataForced = 0;\r
119\r
120 //\r
121 // Secure erase is performed by generating a new encryption key\r
122 // this is only available if encryption is supported\r
123 //\r
124 AvalDiskActions->SecureErase = 1;\r
125 } else {\r
126 AvalDiskActions->PsidRevert = 0;\r
127 AvalDiskActions->SecureErase = 0;\r
128\r
129 //\r
130 // If no media encryption is supported, then a revert (using password) will not\r
131 // erase the Data (since you can't generate a new encryption key)\r
132 //\r
133 AvalDiskActions->RevertKeepDataForced = 1;\r
134 }\r
135\r
136 if (LockingFeature->Locked) {\r
137 AvalDiskActions->Unlock = 1;\r
138 } else {\r
139 AvalDiskActions->Unlock = 0;\r
140 }\r
141\r
142 //\r
143 // Only allow user to set password if an admin password exists\r
144 //\r
145 ExistingPassword = OpalUtilAdminPasswordExists(OwnerShip, LockingFeature);\r
146 AvalDiskActions->UserPass = ExistingPassword;\r
147\r
148 //\r
149 // This will still show up even if there isn't a user, which is fine\r
150 //\r
151 AvalDiskActions->DisableUser = ExistingPassword;\r
152\r
153 return TcgResultSuccess;\r
154}\r
155\r
156/**\r
157 Enable Opal Feature for the input device.\r
158\r
159 @param[in] Session The opal session for the opal device.\r
160 @param[in] Msid Msid\r
161 @param[in] MsidLength Msid Length\r
162 @param[in] Password Admin password\r
163 @param[in] PassLength Length of password in bytes\r
164\r
165**/\r
166TCG_RESULT\r
167EFIAPI\r
168OpalSupportEnableOpalFeature (\r
169 IN OPAL_SESSION *Session,\r
170 IN VOID *Msid,\r
171 IN UINT32 MsidLength,\r
172 IN VOID *Password,\r
173 IN UINT32 PassLength\r
174 )\r
175{\r
176 TCG_RESULT Ret;\r
177\r
178 NULL_CHECK(Session);\r
179 NULL_CHECK(Msid);\r
180 NULL_CHECK(Password);\r
181\r
182 Ret = OpalUtilSetAdminPasswordAsSid(\r
183 Session,\r
184 Msid,\r
185 MsidLength,\r
186 Password,\r
187 PassLength\r
188 );\r
189 if (Ret == TcgResultSuccess) {\r
190 //\r
191 // Enable global locking range\r
192 //\r
193 Ret = OpalUtilSetOpalLockingRange(\r
194 Session,\r
195 Password,\r
196 PassLength,\r
197 OPAL_LOCKING_SP_LOCKING_GLOBALRANGE,\r
198 0,\r
199 0,\r
200 TRUE,\r
201 TRUE,\r
202 FALSE,\r
203 FALSE\r
204 );\r
205 }\r
206\r
207 return Ret;\r
208}\r
209\r
210/**\r
211 Update password for the Opal disk.\r
212\r
213 @param[in, out] OpalDisk The disk to update password.\r
214 @param[in] Password The input password.\r
215 @param[in] PasswordLength The input password length.\r
216\r
217**/\r
218VOID\r
219OpalSupportUpdatePassword (\r
220 IN OUT OPAL_DISK *OpalDisk,\r
221 IN VOID *Password,\r
222 IN UINT32 PasswordLength\r
223 )\r
224{\r
225 CopyMem (OpalDisk->Password, Password, PasswordLength);\r
226 OpalDisk->PasswordLength = (UINT8) PasswordLength;\r
227}\r
228\r
229/**\r
230 Extract device info from the device path.\r
231\r
232 @param[in] DevicePath Device path info for the device.\r
233 @param[out] DevInfoLength Device information length needed.\r
234 @param[out] DevInfo Device information extracted.\r
235\r
236 @return Device type.\r
237\r
238**/\r
239UINT8\r
240ExtractDeviceInfoFromDevicePath (\r
241 IN EFI_DEVICE_PATH_PROTOCOL *DevicePath,\r
242 OUT UINT16 *DevInfoLength,\r
243 OUT OPAL_DEVICE_COMMON *DevInfo OPTIONAL\r
244 )\r
245{\r
246 EFI_DEVICE_PATH_PROTOCOL *TmpDevPath;\r
247 EFI_DEVICE_PATH_PROTOCOL *TmpDevPath2;\r
248 PCI_DEVICE_PATH *PciDevPath;\r
249 UINT8 DeviceType;\r
250 UINT8 BusNum;\r
251 OPAL_PCI_DEVICE *PciDevice;\r
252 OPAL_DEVICE_ATA *DevInfoAta;\r
253 OPAL_DEVICE_NVME *DevInfoNvme;\r
254 SATA_DEVICE_PATH *SataDevPath;\r
255 NVME_NAMESPACE_DEVICE_PATH *NvmeDevPath;\r
256\r
257 ASSERT (DevicePath != NULL);\r
258 ASSERT (DevInfoLength != NULL);\r
259\r
260 DeviceType = OPAL_DEVICE_TYPE_UNKNOWN;\r
261 *DevInfoLength = 0;\r
262\r
263 TmpDevPath = DevicePath;\r
264\r
265 //\r
266 // Get device type.\r
267 //\r
268 while (!IsDevicePathEnd (TmpDevPath)) {\r
269 if (TmpDevPath->Type == MESSAGING_DEVICE_PATH && TmpDevPath->SubType == MSG_SATA_DP) {\r
270 //\r
271 // SATA\r
272 //\r
273 if (DevInfo != NULL) {\r
274 SataDevPath = (SATA_DEVICE_PATH *) TmpDevPath;\r
275 DevInfoAta = (OPAL_DEVICE_ATA *) DevInfo;\r
276 DevInfoAta->Port = SataDevPath->HBAPortNumber;\r
277 DevInfoAta->PortMultiplierPort = SataDevPath->PortMultiplierPortNumber;\r
278 }\r
279 DeviceType = OPAL_DEVICE_TYPE_ATA;\r
280 *DevInfoLength = sizeof (OPAL_DEVICE_ATA);\r
281 break;\r
282 } else if (TmpDevPath->Type == MESSAGING_DEVICE_PATH && TmpDevPath->SubType == MSG_NVME_NAMESPACE_DP) {\r
283 //\r
284 // NVMe\r
285 //\r
286 if (DevInfo != NULL) {\r
287 NvmeDevPath = (NVME_NAMESPACE_DEVICE_PATH *) TmpDevPath;\r
288 DevInfoNvme = (OPAL_DEVICE_NVME *) DevInfo;\r
289 DevInfoNvme->NvmeNamespaceId = NvmeDevPath->NamespaceId;\r
290 }\r
291 DeviceType = OPAL_DEVICE_TYPE_NVME;\r
292 *DevInfoLength = sizeof (OPAL_DEVICE_NVME);\r
293 break;\r
294 }\r
295 TmpDevPath = NextDevicePathNode (TmpDevPath);\r
296 }\r
297\r
298 //\r
299 // Get device info.\r
300 //\r
301 BusNum = 0;\r
302 TmpDevPath = DevicePath;\r
303 TmpDevPath2 = NextDevicePathNode (DevicePath);\r
304 while (!IsDevicePathEnd (TmpDevPath2)) {\r
305 if (TmpDevPath->Type == HARDWARE_DEVICE_PATH && TmpDevPath->SubType == HW_PCI_DP) {\r
306 PciDevPath = (PCI_DEVICE_PATH *) TmpDevPath;\r
307 if ((TmpDevPath2->Type == MESSAGING_DEVICE_PATH && TmpDevPath2->SubType == MSG_NVME_NAMESPACE_DP)||\r
308 (TmpDevPath2->Type == MESSAGING_DEVICE_PATH && TmpDevPath2->SubType == MSG_SATA_DP)) {\r
309 if (DevInfo != NULL) {\r
310 PciDevice = &DevInfo->Device;\r
311 PciDevice->Segment = 0;\r
312 PciDevice->Bus = BusNum;\r
313 PciDevice->Device = PciDevPath->Device;\r
314 PciDevice->Function = PciDevPath->Function;\r
315 }\r
316 } else {\r
317 if (DevInfo != NULL) {\r
318 PciDevice = (OPAL_PCI_DEVICE *) ((UINTN) DevInfo + *DevInfoLength);\r
319 PciDevice->Segment = 0;\r
320 PciDevice->Bus = BusNum;\r
321 PciDevice->Device = PciDevPath->Device;\r
322 PciDevice->Function = PciDevPath->Function;\r
323 }\r
324 *DevInfoLength += sizeof (OPAL_PCI_DEVICE);\r
325 if (TmpDevPath2->Type == HARDWARE_DEVICE_PATH && TmpDevPath2->SubType == HW_PCI_DP) {\r
326 BusNum = PciRead8 (PCI_LIB_ADDRESS (BusNum, PciDevPath->Device, PciDevPath->Function, PCI_BRIDGE_SECONDARY_BUS_REGISTER_OFFSET));\r
327 }\r
328 }\r
329 }\r
330\r
331 TmpDevPath = NextDevicePathNode (TmpDevPath);\r
332 TmpDevPath2 = NextDevicePathNode (TmpDevPath2);\r
333 }\r
334\r
335 ASSERT (DeviceType != OPAL_DEVICE_TYPE_UNKNOWN);\r
336 return DeviceType;\r
337}\r
338\r
339/**\r
340 Save boot script for ATA OPAL device.\r
341\r
342 @param[in] DevInfo Pointer to ATA Opal device information.\r
343\r
344 **/\r
345VOID\r
346OpalDeviceAtaSaveBootScript (\r
347 IN OPAL_DEVICE_ATA *DevInfo\r
348 )\r
349{\r
350 UINTN Bus;\r
351 UINTN Device;\r
352 UINTN Function;\r
353 UINTN Index;\r
354 EFI_STATUS Status;\r
355 UINTN Offset;\r
356 UINT64 Address;\r
357 S3_BOOT_SCRIPT_LIB_WIDTH Width;\r
358 UINT32 Data;\r
359 OPAL_HC_PCI_REGISTER_SAVE *HcRegisterSaveListPtr;\r
360 UINTN Count;\r
361\r
362 Data = 0;\r
363\r
364 Bus = DevInfo->Device.Bus;\r
365 Device = DevInfo->Device.Device;\r
366 Function = DevInfo->Device.Function;\r
367\r
368 HcRegisterSaveListPtr = (OPAL_HC_PCI_REGISTER_SAVE *) mSataHcRegisterSaveTemplate;\r
369 Count = sizeof (mSataHcRegisterSaveTemplate) / sizeof (OPAL_HC_PCI_REGISTER_SAVE);\r
370\r
371 for (Index = 0; Index < Count; Index++) {\r
372 Offset = HcRegisterSaveListPtr[Index].Address;\r
373 Width = HcRegisterSaveListPtr[Index].Width;\r
374\r
375 switch (Width) {\r
376 case S3BootScriptWidthUint8:\r
377 Data = (UINT32)PciRead8 (PCI_LIB_ADDRESS(Bus,Device,Function,Offset));\r
378 break;\r
379 case S3BootScriptWidthUint16:\r
380 Data = (UINT32)PciRead16 (PCI_LIB_ADDRESS(Bus,Device,Function,Offset));\r
381 break;\r
382 case S3BootScriptWidthUint32:\r
383 Data = PciRead32 (PCI_LIB_ADDRESS(Bus,Device,Function,Offset));\r
384 break;\r
385 default:\r
386 ASSERT (FALSE);\r
387 break;\r
388 }\r
389\r
390 Address = S3_BOOT_SCRIPT_LIB_PCI_ADDRESS (Bus, Device, Function, Offset);\r
391 Status = S3BootScriptSavePciCfgWrite (Width, Address, 1, &Data);\r
392 ASSERT_EFI_ERROR (Status);\r
393 }\r
394}\r
395\r
396/**\r
397 Build ATA OPAL device info and save them to LockBox.\r
398\r
399 @param[in] BarAddr Bar address allocated.\r
400\r
401 **/\r
402VOID\r
403BuildOpalDeviceInfoAta (\r
404 IN UINT32 BarAddr\r
405 )\r
406{\r
407 EFI_STATUS Status;\r
408 UINT8 DeviceType;\r
409 OPAL_DEVICE_ATA *DevInfoAta;\r
410 OPAL_DEVICE_ATA *TempDevInfoAta;\r
411 UINTN DevInfoLengthAta;\r
412 UINT16 DevInfoLength;\r
413 OPAL_DRIVER_DEVICE *TmpDev;\r
414\r
415 //\r
416 // Build ATA OPAL device info and save them to LockBox.\r
417 //\r
418 DevInfoLengthAta = 0;\r
419 TmpDev = mOpalDriver.DeviceList;\r
420 while (TmpDev != NULL) {\r
421 DeviceType = ExtractDeviceInfoFromDevicePath (\r
422 TmpDev->OpalDisk.OpalDevicePath,\r
423 &DevInfoLength,\r
424 NULL\r
425 );\r
426 if (DeviceType == OPAL_DEVICE_TYPE_ATA) {\r
427 DevInfoLengthAta += DevInfoLength;\r
428 }\r
429\r
430 TmpDev = TmpDev->Next;\r
431 }\r
432\r
433 if (DevInfoLengthAta == 0) {\r
434 return;\r
435 }\r
436\r
437 DevInfoAta = AllocateZeroPool (DevInfoLengthAta);\r
438 ASSERT (DevInfoAta != NULL);\r
439\r
440 TempDevInfoAta = DevInfoAta;\r
441 TmpDev = mOpalDriver.DeviceList;\r
442 while (TmpDev != NULL) {\r
443 DeviceType = ExtractDeviceInfoFromDevicePath (\r
444 TmpDev->OpalDisk.OpalDevicePath,\r
445 &DevInfoLength,\r
446 NULL\r
447 );\r
448 if (DeviceType == OPAL_DEVICE_TYPE_ATA) {\r
449 ExtractDeviceInfoFromDevicePath (\r
450 TmpDev->OpalDisk.OpalDevicePath,\r
451 &DevInfoLength,\r
452 (OPAL_DEVICE_COMMON *) TempDevInfoAta\r
453 );\r
454 TempDevInfoAta->Length = DevInfoLength;\r
455 TempDevInfoAta->OpalBaseComId = TmpDev->OpalDisk.OpalBaseComId;\r
456 TempDevInfoAta->BarAddr = BarAddr;\r
457 CopyMem (\r
458 TempDevInfoAta->Password,\r
459 TmpDev->OpalDisk.Password,\r
460 TmpDev->OpalDisk.PasswordLength\r
461 );\r
462 TempDevInfoAta->PasswordLength = TmpDev->OpalDisk.PasswordLength;\r
463 OpalDeviceAtaSaveBootScript (TempDevInfoAta);\r
464 TempDevInfoAta = (OPAL_DEVICE_ATA *) ((UINTN) TempDevInfoAta + DevInfoLength);\r
465 }\r
466\r
467 TmpDev = TmpDev->Next;\r
468 }\r
469\r
470 Status = SaveLockBox (\r
471 &mOpalDeviceAtaGuid,\r
472 DevInfoAta,\r
473 DevInfoLengthAta\r
474 );\r
475 ASSERT_EFI_ERROR (Status);\r
476\r
477 Status = SetLockBoxAttributes (\r
478 &mOpalDeviceAtaGuid,\r
479 LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY\r
480 );\r
481 ASSERT_EFI_ERROR (Status);\r
482\r
483 ZeroMem (DevInfoAta, DevInfoLengthAta);\r
484 FreePool (DevInfoAta);\r
485}\r
486\r
487/**\r
488 Build NVMe OPAL device info and save them to LockBox.\r
489\r
490 @param[in] BarAddr Bar address allocated.\r
491\r
492 **/\r
493VOID\r
494BuildOpalDeviceInfoNvme (\r
495 IN UINT32 BarAddr\r
496 )\r
497{\r
498 EFI_STATUS Status;\r
499 UINT8 DeviceType;\r
500 OPAL_DEVICE_NVME *DevInfoNvme;\r
501 OPAL_DEVICE_NVME *TempDevInfoNvme;\r
502 UINTN DevInfoLengthNvme;\r
503 UINT16 DevInfoLength;\r
504 OPAL_DRIVER_DEVICE *TmpDev;\r
505\r
506 //\r
507 // Build NVMe OPAL device info and save them to LockBox.\r
508 //\r
509 DevInfoLengthNvme = 0;\r
510 TmpDev = mOpalDriver.DeviceList;\r
511 while (TmpDev != NULL) {\r
512 DeviceType = ExtractDeviceInfoFromDevicePath (\r
513 TmpDev->OpalDisk.OpalDevicePath,\r
514 &DevInfoLength,\r
515 NULL\r
516 );\r
517 if (DeviceType == OPAL_DEVICE_TYPE_NVME) {\r
518 DevInfoLengthNvme += DevInfoLength;\r
519 }\r
520\r
521 TmpDev = TmpDev->Next;\r
522 }\r
523\r
524 if (DevInfoLengthNvme == 0) {\r
525 return;\r
526 }\r
527\r
528 DevInfoNvme = AllocateZeroPool (DevInfoLengthNvme);\r
529 ASSERT (DevInfoNvme != NULL);\r
530\r
531 TempDevInfoNvme = DevInfoNvme;\r
532 TmpDev = mOpalDriver.DeviceList;\r
533 while (TmpDev != NULL) {\r
534 DeviceType = ExtractDeviceInfoFromDevicePath (\r
535 TmpDev->OpalDisk.OpalDevicePath,\r
536 &DevInfoLength,\r
537 NULL\r
538 );\r
539 if (DeviceType == OPAL_DEVICE_TYPE_NVME) {\r
540 ExtractDeviceInfoFromDevicePath (\r
541 TmpDev->OpalDisk.OpalDevicePath,\r
542 &DevInfoLength,\r
543 (OPAL_DEVICE_COMMON *) TempDevInfoNvme\r
544 );\r
545 TempDevInfoNvme->Length = DevInfoLength;\r
546 TempDevInfoNvme->OpalBaseComId = TmpDev->OpalDisk.OpalBaseComId;\r
547 TempDevInfoNvme->BarAddr = BarAddr;\r
548 CopyMem (\r
549 TempDevInfoNvme->Password,\r
550 TmpDev->OpalDisk.Password,\r
551 TmpDev->OpalDisk.PasswordLength\r
552 );\r
553 TempDevInfoNvme->PasswordLength = TmpDev->OpalDisk.PasswordLength;\r
554 TempDevInfoNvme = (OPAL_DEVICE_NVME *) ((UINTN) TempDevInfoNvme + DevInfoLength);\r
555 }\r
556\r
557 TmpDev = TmpDev->Next;\r
558 }\r
559\r
560 Status = SaveLockBox (\r
561 &mOpalDeviceNvmeGuid,\r
562 DevInfoNvme,\r
563 DevInfoLengthNvme\r
564 );\r
565 ASSERT_EFI_ERROR (Status);\r
566\r
567 Status = SetLockBoxAttributes (\r
568 &mOpalDeviceNvmeGuid,\r
569 LOCK_BOX_ATTRIBUTE_RESTORE_IN_S3_ONLY\r
570 );\r
571 ASSERT_EFI_ERROR (Status);\r
572\r
573 ZeroMem (DevInfoNvme, DevInfoLengthNvme);\r
574 FreePool (DevInfoNvme);\r
575}\r
576\r
577/**\r
578 Notification function of EFI_END_OF_DXE_EVENT_GROUP_GUID event group.\r
579\r
580 This is a notification function registered on EFI_END_OF_DXE_EVENT_GROUP_GUID event group.\r
581\r
582 @param Event Event whose notification function is being invoked.\r
583 @param Context Pointer to the notification function's context.\r
584\r
585**/\r
586VOID\r
587EFIAPI\r
588OpalEndOfDxeEventNotify (\r
589 EFI_EVENT Event,\r
590 VOID *Context\r
591 )\r
592{\r
593 EFI_STATUS Status;\r
594 EFI_PHYSICAL_ADDRESS Address;\r
595 UINT64 Length;\r
596 OPAL_DRIVER_DEVICE *TmpDev;\r
597\r
598 DEBUG ((DEBUG_INFO, "%a() - enter\n", __FUNCTION__));\r
599\r
600 mOpalEndOfDxe = TRUE;\r
601\r
602 if (mOpalRequestVariable != NULL) {\r
603 //\r
604 // Free the OPAL request variable buffer here\r
605 // as the OPAL requests should have been processed.\r
606 //\r
607 FreePool (mOpalRequestVariable);\r
608 mOpalRequestVariable = NULL;\r
609 mOpalRequestVariableSize = 0;\r
610 }\r
611\r
fbe1328a
SZ
612 //\r
613 // If no any device, return directly.\r
614 //\r
615 if (mOpalDriver.DeviceList == NULL) {\r
616 gBS->CloseEvent (Event);\r
617 return;\r
618 }\r
619\r
112e584b
SZ
620 //\r
621 // Assume 64K size and alignment are enough.\r
622 //\r
623 Length = 0x10000;\r
624 Address = 0xFFFFFFFF;\r
625 Status = gDS->AllocateMemorySpace (\r
626 EfiGcdAllocateMaxAddressSearchBottomUp,\r
627 EfiGcdMemoryTypeMemoryMappedIo,\r
628 16, // 2^16: 64K Alignment\r
629 Length,\r
630 &Address,\r
631 gImageHandle,\r
632 NULL\r
633 );\r
634 ASSERT_EFI_ERROR (Status);\r
635\r
636 BuildOpalDeviceInfoAta ((UINT32) Address);\r
637 BuildOpalDeviceInfoNvme ((UINT32) Address);\r
638\r
639 //\r
640 // Zero passsword.\r
641 //\r
642 TmpDev = mOpalDriver.DeviceList;\r
643 while (TmpDev != NULL) {\r
644 ZeroMem (TmpDev->OpalDisk.Password, TmpDev->OpalDisk.PasswordLength);\r
645 TmpDev = TmpDev->Next;\r
646 }\r
647\r
648 DEBUG ((DEBUG_INFO, "%a() - exit\n", __FUNCTION__));\r
649\r
650 gBS->CloseEvent (Event);\r
651}\r
652\r
653/**\r
654 Get Psid input from the popup window.\r
655\r
656 @param[in] Dev The device which need Psid to process Psid Revert\r
657 OPAL request.\r
658 @param[in] PopUpString Pop up string.\r
40d32e79
ED
659 @param[in] PopUpString2 Pop up string in line 2.\r
660\r
112e584b
SZ
661 @param[out] PressEsc Whether user escape function through Press ESC.\r
662\r
aa085730 663 @retval Psid string if success. NULL if failed.\r
112e584b
SZ
664\r
665**/\r
666CHAR8 *\r
667OpalDriverPopUpPsidInput (\r
668 IN OPAL_DRIVER_DEVICE *Dev,\r
669 IN CHAR16 *PopUpString,\r
40d32e79 670 IN CHAR16 *PopUpString2,\r
112e584b
SZ
671 OUT BOOLEAN *PressEsc\r
672 )\r
673{\r
674 EFI_INPUT_KEY InputKey;\r
675 UINTN InputLength;\r
676 CHAR16 Mask[PSID_CHARACTER_LENGTH + 1];\r
677 CHAR16 Unicode[PSID_CHARACTER_LENGTH + 1];\r
678 CHAR8 *Ascii;\r
679\r
680 ZeroMem(Unicode, sizeof(Unicode));\r
681 ZeroMem(Mask, sizeof(Mask));\r
682\r
683 *PressEsc = FALSE;\r
684\r
685 gST->ConOut->ClearScreen(gST->ConOut);\r
686\r
687 InputLength = 0;\r
688 while (TRUE) {\r
689 Mask[InputLength] = L'_';\r
63c76537
ED
690 if (PopUpString2 == NULL) {\r
691 CreatePopUp (\r
692 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
693 &InputKey,\r
694 PopUpString,\r
695 L"---------------------",\r
696 Mask,\r
697 NULL\r
698 );\r
699 } else {\r
700 CreatePopUp (\r
701 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
702 &InputKey,\r
703 PopUpString,\r
704 PopUpString2,\r
705 L"---------------------",\r
706 Mask,\r
707 NULL\r
708 );\r
709 }\r
112e584b
SZ
710\r
711 //\r
712 // Check key.\r
713 //\r
714 if (InputKey.ScanCode == SCAN_NULL) {\r
715 //\r
716 // password finished\r
717 //\r
718 if (InputKey.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
719 //\r
720 // Add the null terminator.\r
721 //\r
722 Unicode[InputLength] = 0;\r
723 Mask[InputLength] = 0;\r
724 break;\r
725 } else if ((InputKey.UnicodeChar == CHAR_NULL) ||\r
726 (InputKey.UnicodeChar == CHAR_TAB) ||\r
727 (InputKey.UnicodeChar == CHAR_LINEFEED)\r
728 ) {\r
729 continue;\r
730 } else {\r
731 //\r
732 // delete last key entered\r
733 //\r
734 if (InputKey.UnicodeChar == CHAR_BACKSPACE) {\r
735 if (InputLength > 0) {\r
736 Unicode[InputLength] = 0;\r
737 Mask[InputLength] = 0;\r
738 InputLength--;\r
739 }\r
740 } else {\r
741 //\r
742 // add Next key entry\r
743 //\r
744 Unicode[InputLength] = InputKey.UnicodeChar;\r
745 Mask[InputLength] = InputKey.UnicodeChar;\r
746 InputLength++;\r
747 if (InputLength == PSID_CHARACTER_LENGTH) {\r
748 //\r
749 // Add the null terminator.\r
750 //\r
751 Unicode[InputLength] = 0;\r
752 Mask[InputLength] = 0;\r
753 break;\r
754 }\r
755 }\r
756 }\r
757 }\r
758\r
759 //\r
760 // exit on ESC\r
761 //\r
762 if (InputKey.ScanCode == SCAN_ESC) {\r
763 *PressEsc = TRUE;\r
764 break;\r
765 }\r
766 }\r
767\r
768 gST->ConOut->ClearScreen(gST->ConOut);\r
769\r
770 if (InputLength == 0 || InputKey.ScanCode == SCAN_ESC) {\r
771 ZeroMem (Unicode, sizeof (Unicode));\r
772 ZeroMem (Mask, sizeof (Mask));\r
773 return NULL;\r
774 }\r
775\r
776 Ascii = AllocateZeroPool (PSID_CHARACTER_LENGTH + 1);\r
777 if (Ascii == NULL) {\r
778 ZeroMem (Unicode, sizeof (Unicode));\r
779 ZeroMem (Mask, sizeof (Mask));\r
780 return NULL;\r
781 }\r
782\r
783 UnicodeStrToAsciiStrS (Unicode, Ascii, PSID_CHARACTER_LENGTH + 1);\r
784 ZeroMem (Unicode, sizeof (Unicode));\r
785 ZeroMem (Mask, sizeof (Mask));\r
786\r
787 return Ascii;\r
788}\r
789\r
790\r
791/**\r
792 Get password input from the popup window.\r
793\r
794 @param[in] Dev The device which need password to unlock or\r
795 process OPAL request.\r
796 @param[in] PopUpString1 Pop up string 1.\r
797 @param[in] PopUpString2 Pop up string 2.\r
798 @param[out] PressEsc Whether user escape function through Press ESC.\r
799\r
800 @retval Password string if success. NULL if failed.\r
801\r
802**/\r
803CHAR8 *\r
804OpalDriverPopUpPasswordInput (\r
805 IN OPAL_DRIVER_DEVICE *Dev,\r
806 IN CHAR16 *PopUpString1,\r
807 IN CHAR16 *PopUpString2,\r
808 OUT BOOLEAN *PressEsc\r
809 )\r
810{\r
811 EFI_INPUT_KEY InputKey;\r
812 UINTN InputLength;\r
813 CHAR16 Mask[OPAL_MAX_PASSWORD_SIZE + 1];\r
814 CHAR16 Unicode[OPAL_MAX_PASSWORD_SIZE + 1];\r
815 CHAR8 *Ascii;\r
816\r
817 ZeroMem(Unicode, sizeof(Unicode));\r
818 ZeroMem(Mask, sizeof(Mask));\r
819\r
820 *PressEsc = FALSE;\r
821\r
822 gST->ConOut->ClearScreen(gST->ConOut);\r
823\r
824 InputLength = 0;\r
825 while (TRUE) {\r
826 Mask[InputLength] = L'_';\r
827 if (PopUpString2 == NULL) {\r
828 CreatePopUp (\r
829 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
830 &InputKey,\r
831 PopUpString1,\r
832 L"---------------------",\r
833 Mask,\r
834 NULL\r
835 );\r
836 } else {\r
837 CreatePopUp (\r
838 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
839 &InputKey,\r
840 PopUpString1,\r
841 PopUpString2,\r
842 L"---------------------",\r
843 Mask,\r
844 NULL\r
845 );\r
846 }\r
847\r
848 //\r
849 // Check key.\r
850 //\r
851 if (InputKey.ScanCode == SCAN_NULL) {\r
852 //\r
853 // password finished\r
854 //\r
855 if (InputKey.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
856 //\r
857 // Add the null terminator.\r
858 //\r
859 Unicode[InputLength] = 0;\r
860 Mask[InputLength] = 0;\r
861 break;\r
862 } else if ((InputKey.UnicodeChar == CHAR_NULL) ||\r
863 (InputKey.UnicodeChar == CHAR_TAB) ||\r
864 (InputKey.UnicodeChar == CHAR_LINEFEED)\r
865 ) {\r
866 continue;\r
867 } else {\r
868 //\r
869 // delete last key entered\r
870 //\r
871 if (InputKey.UnicodeChar == CHAR_BACKSPACE) {\r
872 if (InputLength > 0) {\r
873 Unicode[InputLength] = 0;\r
874 Mask[InputLength] = 0;\r
875 InputLength--;\r
876 }\r
877 } else {\r
878 //\r
879 // add Next key entry\r
880 //\r
881 Unicode[InputLength] = InputKey.UnicodeChar;\r
882 Mask[InputLength] = L'*';\r
883 InputLength++;\r
884 if (InputLength == OPAL_MAX_PASSWORD_SIZE) {\r
885 //\r
886 // Add the null terminator.\r
887 //\r
888 Unicode[InputLength] = 0;\r
889 Mask[InputLength] = 0;\r
890 break;\r
891 }\r
892 }\r
893 }\r
894 }\r
895\r
896 //\r
897 // exit on ESC\r
898 //\r
899 if (InputKey.ScanCode == SCAN_ESC) {\r
900 *PressEsc = TRUE;\r
901 break;\r
902 }\r
903 }\r
904\r
905 gST->ConOut->ClearScreen(gST->ConOut);\r
906\r
907 if (InputLength == 0 || InputKey.ScanCode == SCAN_ESC) {\r
908 ZeroMem (Unicode, sizeof (Unicode));\r
909 return NULL;\r
910 }\r
911\r
912 Ascii = AllocateZeroPool (OPAL_MAX_PASSWORD_SIZE + 1);\r
913 if (Ascii == NULL) {\r
914 ZeroMem (Unicode, sizeof (Unicode));\r
915 return NULL;\r
916 }\r
917\r
918 UnicodeStrToAsciiStrS (Unicode, Ascii, OPAL_MAX_PASSWORD_SIZE + 1);\r
919 ZeroMem (Unicode, sizeof (Unicode));\r
920\r
921 return Ascii;\r
922}\r
923\r
924/**\r
aa085730 925 Get pop up string.\r
112e584b 926\r
aa085730 927 @param[in] Dev The OPAL device.\r
112e584b
SZ
928 @param[in] RequestString Request string.\r
929\r
aa085730
SZ
930 @return Pop up string.\r
931\r
112e584b
SZ
932**/\r
933CHAR16 *\r
934OpalGetPopUpString (\r
935 IN OPAL_DRIVER_DEVICE *Dev,\r
936 IN CHAR16 *RequestString\r
937 )\r
938{\r
112e584b 939 if (Dev->Name16 == NULL) {\r
aa085730 940 UnicodeSPrint (mPopUpString, sizeof (mPopUpString), L"%s Disk", RequestString);\r
112e584b 941 } else {\r
aa085730 942 UnicodeSPrint (mPopUpString, sizeof (mPopUpString), L"%s %s", RequestString, Dev->Name16);\r
112e584b
SZ
943 }\r
944\r
945 return mPopUpString;\r
946}\r
947\r
948/**\r
949 Check if disk is locked, show popup window and ask for password if it is.\r
950\r
951 @param[in] Dev The device which need to be unlocked.\r
952 @param[in] RequestString Request string.\r
953\r
954**/\r
955VOID\r
956OpalDriverRequestPassword (\r
957 IN OPAL_DRIVER_DEVICE *Dev,\r
958 IN CHAR16 *RequestString\r
959 )\r
960{\r
961 UINT8 Count;\r
962 BOOLEAN IsEnabled;\r
963 BOOLEAN IsLocked;\r
964 CHAR8 *Password;\r
965 UINT32 PasswordLen;\r
966 OPAL_SESSION Session;\r
967 BOOLEAN PressEsc;\r
968 EFI_INPUT_KEY Key;\r
969 TCG_RESULT Ret;\r
970 CHAR16 *PopUpString;\r
971\r
972 if (Dev == NULL) {\r
973 return;\r
974 }\r
975\r
976 DEBUG ((DEBUG_INFO, "%a()\n", __FUNCTION__));\r
977\r
978 PopUpString = OpalGetPopUpString (Dev, RequestString);\r
979\r
980 Count = 0;\r
981\r
982 IsEnabled = OpalFeatureEnabled (&Dev->OpalDisk.SupportedAttributes, &Dev->OpalDisk.LockingFeature);\r
983 if (IsEnabled) {\r
984 ZeroMem(&Session, sizeof(Session));\r
985 Session.Sscp = Dev->OpalDisk.Sscp;\r
986 Session.MediaId = Dev->OpalDisk.MediaId;\r
987 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;\r
988\r
989 IsLocked = OpalDeviceLocked (&Dev->OpalDisk.SupportedAttributes, &Dev->OpalDisk.LockingFeature);\r
990\r
991 while (Count < MAX_PASSWORD_TRY_COUNT) {\r
992 Password = OpalDriverPopUpPasswordInput (Dev, PopUpString, NULL, &PressEsc);\r
993 if (PressEsc) {\r
994 if (IsLocked) {\r
995 //\r
996 // Current device in the lock status and\r
997 // User not input password and press ESC,\r
998 // keep device in lock status and continue boot.\r
999 //\r
1000 do {\r
1001 CreatePopUp (\r
1002 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1003 &Key,\r
1004 L"Press ENTER to skip the request and continue boot,",\r
1005 L"Press ESC to input password again",\r
1006 NULL\r
1007 );\r
1008 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
1009\r
1010 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
1011 gST->ConOut->ClearScreen(gST->ConOut);\r
1012 //\r
1013 // Keep lock and continue boot.\r
1014 //\r
1015 return;\r
1016 } else {\r
1017 //\r
1018 // Let user input password again.\r
1019 //\r
1020 continue;\r
1021 }\r
1022 } else {\r
1023 //\r
1024 // Current device in the unlock status and\r
1025 // User not input password and press ESC,\r
1026 // Shutdown the device.\r
1027 //\r
1028 do {\r
1029 CreatePopUp (\r
1030 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1031 &Key,\r
1032 L"Press ENTER to shutdown, Press ESC to input password again",\r
1033 NULL\r
1034 );\r
1035 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
1036\r
1037 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
1038 gRT->ResetSystem (EfiResetShutdown, EFI_SUCCESS, 0, NULL);\r
1039 } else {\r
1040 //\r
1041 // Let user input password again.\r
1042 //\r
1043 continue;\r
1044 }\r
1045 }\r
1046 }\r
1047\r
1048 if (Password == NULL) {\r
1049 Count ++;\r
1050 continue;\r
1051 }\r
1052 PasswordLen = (UINT32) AsciiStrLen(Password);\r
1053\r
1054 if (IsLocked) {\r
1055 Ret = OpalUtilUpdateGlobalLockingRange(&Session, Password, PasswordLen, FALSE, FALSE);\r
1056 } else {\r
1057 Ret = OpalUtilUpdateGlobalLockingRange(&Session, Password, PasswordLen, TRUE, TRUE);\r
1058 if (Ret == TcgResultSuccess) {\r
1059 Ret = OpalUtilUpdateGlobalLockingRange(&Session, Password, PasswordLen, FALSE, FALSE);\r
1060 }\r
1061 }\r
1062\r
1063 if (Ret == TcgResultSuccess) {\r
1064 OpalSupportUpdatePassword (&Dev->OpalDisk, Password, PasswordLen);\r
1065 DEBUG ((DEBUG_INFO, "%s Success\n", RequestString));\r
1066 } else {\r
1067 DEBUG ((DEBUG_INFO, "%s Failure\n", RequestString));\r
1068 }\r
1069\r
1070 if (Password != NULL) {\r
1071 ZeroMem (Password, PasswordLen);\r
1072 FreePool (Password);\r
1073 }\r
1074\r
1075 if (Ret == TcgResultSuccess) {\r
1076 break;\r
1077 }\r
1078\r
e4e314b1
ED
1079 //\r
1080 // Check whether opal device's Tries value has reach the TryLimit value, if yes, force a shutdown\r
1081 // before accept new password.\r
1082 //\r
1083 if (Ret == TcgResultFailureInvalidType) {\r
1084 Count = MAX_PASSWORD_TRY_COUNT;\r
1085 break;\r
1086 }\r
1087\r
112e584b
SZ
1088 Count++;\r
1089\r
1090 do {\r
1091 CreatePopUp (\r
1092 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1093 &Key,\r
1094 L"Invalid password.",\r
1095 L"Press ENTER to retry",\r
1096 NULL\r
1097 );\r
1098 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
1099 }\r
1100\r
1101 if (Count >= MAX_PASSWORD_TRY_COUNT) {\r
1102 do {\r
1103 CreatePopUp (\r
1104 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1105 &Key,\r
1106 L"Opal password retry count exceeds the limit. Must shutdown!",\r
1107 L"Press ENTER to shutdown",\r
1108 NULL\r
1109 );\r
1110 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
1111\r
1112 gRT->ResetSystem (EfiResetShutdown, EFI_SUCCESS, 0, NULL);\r
1113 }\r
1114 }\r
1115}\r
1116\r
1117/**\r
1118 Process Enable Feature OPAL request.\r
1119\r
1120 @param[in] Dev The device which has Enable Feature OPAL request.\r
1121 @param[in] RequestString Request string.\r
1122\r
1123**/\r
1124VOID\r
1125ProcessOpalRequestEnableFeature (\r
1126 IN OPAL_DRIVER_DEVICE *Dev,\r
1127 IN CHAR16 *RequestString\r
1128 )\r
1129{\r
1130 UINT8 Count;\r
1131 CHAR8 *Password;\r
1132 UINT32 PasswordLen;\r
1133 CHAR8 *PasswordConfirm;\r
1134 UINT32 PasswordLenConfirm;\r
1135 OPAL_SESSION Session;\r
1136 BOOLEAN PressEsc;\r
1137 EFI_INPUT_KEY Key;\r
1138 TCG_RESULT Ret;\r
1139 CHAR16 *PopUpString;\r
1140\r
1141 if (Dev == NULL) {\r
1142 return;\r
1143 }\r
1144\r
1145 DEBUG ((DEBUG_INFO, "%a()\n", __FUNCTION__));\r
1146\r
1147 PopUpString = OpalGetPopUpString (Dev, RequestString);\r
1148\r
1149 Count = 0;\r
1150\r
1151 ZeroMem(&Session, sizeof(Session));\r
1152 Session.Sscp = Dev->OpalDisk.Sscp;\r
1153 Session.MediaId = Dev->OpalDisk.MediaId;\r
1154 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;\r
1155\r
1156 while (Count < MAX_PASSWORD_TRY_COUNT) {\r
1157 Password = OpalDriverPopUpPasswordInput (Dev, PopUpString, L"Please type in your new password", &PressEsc);\r
1158 if (PressEsc) {\r
1159 do {\r
1160 CreatePopUp (\r
1161 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1162 &Key,\r
1163 L"Press ENTER to skip the request and continue boot,",\r
1164 L"Press ESC to input password again",\r
1165 NULL\r
1166 );\r
1167 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
1168\r
1169 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
1170 gST->ConOut->ClearScreen(gST->ConOut);\r
1171 return;\r
1172 } else {\r
1173 //\r
1174 // Let user input password again.\r
1175 //\r
1176 continue;\r
1177 }\r
1178 }\r
1179\r
1180 if (Password == NULL) {\r
1181 Count ++;\r
1182 continue;\r
1183 }\r
1184 PasswordLen = (UINT32) AsciiStrLen(Password);\r
1185\r
1186 PasswordConfirm = OpalDriverPopUpPasswordInput (Dev, PopUpString, L"Please confirm your new password", &PressEsc);\r
1187 if (PasswordConfirm == NULL) {\r
1188 ZeroMem (Password, PasswordLen);\r
1189 FreePool (Password);\r
1190 Count ++;\r
1191 continue;\r
1192 }\r
1193 PasswordLenConfirm = (UINT32) AsciiStrLen(PasswordConfirm);\r
1194 if ((PasswordLen != PasswordLenConfirm) ||\r
1195 (CompareMem (Password, PasswordConfirm, PasswordLen) != 0)) {\r
1196 ZeroMem (Password, PasswordLen);\r
1197 FreePool (Password);\r
1198 ZeroMem (PasswordConfirm, PasswordLenConfirm);\r
1199 FreePool (PasswordConfirm);\r
1200 do {\r
1201 CreatePopUp (\r
1202 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1203 &Key,\r
1204 L"Passwords are not the same.",\r
1205 L"Press ENTER to retry",\r
1206 NULL\r
1207 );\r
1208 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
1209 Count ++;\r
1210 continue;\r
1211 }\r
1212\r
1213 if (PasswordConfirm != NULL) {\r
1214 ZeroMem (PasswordConfirm, PasswordLenConfirm);\r
1215 FreePool (PasswordConfirm);\r
1216 }\r
1217\r
1218 Ret = OpalSupportEnableOpalFeature (&Session, Dev->OpalDisk.Msid, Dev->OpalDisk.MsidLength, Password, PasswordLen);\r
1219 if (Ret == TcgResultSuccess) {\r
1220 OpalSupportUpdatePassword (&Dev->OpalDisk, Password, PasswordLen);\r
1221 DEBUG ((DEBUG_INFO, "%s Success\n", RequestString));\r
1222 } else {\r
1223 DEBUG ((DEBUG_INFO, "%s Failure\n", RequestString));\r
1224 }\r
1225\r
1226 if (Password != NULL) {\r
1227 ZeroMem (Password, PasswordLen);\r
1228 FreePool (Password);\r
1229 }\r
1230\r
1231 if (Ret == TcgResultSuccess) {\r
1232 break;\r
1233 }\r
1234\r
1235 Count++;\r
1236\r
1237 do {\r
1238 CreatePopUp (\r
1239 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1240 &Key,\r
1241 L"Request failed.",\r
1242 L"Press ENTER to retry",\r
1243 NULL\r
1244 );\r
1245 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
1246 }\r
1247\r
1248 if (Count >= MAX_PASSWORD_TRY_COUNT) {\r
1249 do {\r
1250 CreatePopUp (\r
1251 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1252 &Key,\r
1253 L"Opal password retry count exceeds the limit.",\r
1254 L"Press ENTER to skip the request and continue boot",\r
1255 NULL\r
1256 );\r
1257 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
1258 gST->ConOut->ClearScreen(gST->ConOut);\r
1259 }\r
1260}\r
1261\r
1262/**\r
1263 Process Disable User OPAL request.\r
1264\r
1265 @param[in] Dev The device which has Disable User OPAL request.\r
1266 @param[in] RequestString Request string.\r
1267\r
1268**/\r
1269VOID\r
1270ProcessOpalRequestDisableUser (\r
1271 IN OPAL_DRIVER_DEVICE *Dev,\r
1272 IN CHAR16 *RequestString\r
1273 )\r
1274{\r
1275 UINT8 Count;\r
1276 CHAR8 *Password;\r
1277 UINT32 PasswordLen;\r
1278 OPAL_SESSION Session;\r
1279 BOOLEAN PressEsc;\r
1280 EFI_INPUT_KEY Key;\r
1281 TCG_RESULT Ret;\r
1282 BOOLEAN PasswordFailed;\r
1283 CHAR16 *PopUpString;\r
1284\r
1285 if (Dev == NULL) {\r
1286 return;\r
1287 }\r
1288\r
1289 DEBUG ((DEBUG_INFO, "%a()\n", __FUNCTION__));\r
1290\r
1291 PopUpString = OpalGetPopUpString (Dev, RequestString);\r
1292\r
1293 Count = 0;\r
1294\r
1295 ZeroMem(&Session, sizeof(Session));\r
1296 Session.Sscp = Dev->OpalDisk.Sscp;\r
1297 Session.MediaId = Dev->OpalDisk.MediaId;\r
1298 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;\r
1299\r
1300 while (Count < MAX_PASSWORD_TRY_COUNT) {\r
1301 Password = OpalDriverPopUpPasswordInput (Dev, PopUpString, NULL, &PressEsc);\r
1302 if (PressEsc) {\r
1303 do {\r
1304 CreatePopUp (\r
1305 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1306 &Key,\r
1307 L"Press ENTER to skip the request and continue boot,",\r
1308 L"Press ESC to input password again",\r
1309 NULL\r
1310 );\r
1311 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
1312\r
1313 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
1314 gST->ConOut->ClearScreen(gST->ConOut);\r
1315 return;\r
1316 } else {\r
1317 //\r
1318 // Let user input password again.\r
1319 //\r
1320 continue;\r
1321 }\r
1322 }\r
1323\r
1324 if (Password == NULL) {\r
1325 Count ++;\r
1326 continue;\r
1327 }\r
1328 PasswordLen = (UINT32) AsciiStrLen(Password);\r
1329\r
1330 Ret = OpalUtilDisableUser(&Session, Password, PasswordLen, &PasswordFailed);\r
1331 if (Ret == TcgResultSuccess) {\r
1332 OpalSupportUpdatePassword (&Dev->OpalDisk, Password, PasswordLen);\r
1333 DEBUG ((DEBUG_INFO, "%s Success\n", RequestString));\r
1334 } else {\r
1335 DEBUG ((DEBUG_INFO, "%s Failure\n", RequestString));\r
1336 }\r
1337\r
1338 if (Password != NULL) {\r
1339 ZeroMem (Password, PasswordLen);\r
1340 FreePool (Password);\r
1341 }\r
1342\r
1343 if (Ret == TcgResultSuccess) {\r
1344 break;\r
1345 }\r
1346\r
1347 Count++;\r
1348\r
1349 do {\r
1350 CreatePopUp (\r
1351 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1352 &Key,\r
1353 L"Invalid password, request failed.",\r
1354 L"Press ENTER to retry",\r
1355 NULL\r
1356 );\r
1357 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
1358 }\r
1359\r
1360 if (Count >= MAX_PASSWORD_TRY_COUNT) {\r
1361 do {\r
1362 CreatePopUp (\r
1363 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1364 &Key,\r
1365 L"Opal password retry count exceeds the limit.",\r
1366 L"Press ENTER to skip the request and continue boot",\r
1367 NULL\r
1368 );\r
1369 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
1370 gST->ConOut->ClearScreen(gST->ConOut);\r
1371 }\r
1372}\r
1373\r
1374/**\r
1375 Process Psid Revert OPAL request.\r
1376\r
1377 @param[in] Dev The device which has Psid Revert OPAL request.\r
1378 @param[in] RequestString Request string.\r
1379\r
1380**/\r
1381VOID\r
1382ProcessOpalRequestPsidRevert (\r
1383 IN OPAL_DRIVER_DEVICE *Dev,\r
1384 IN CHAR16 *RequestString\r
1385 )\r
1386{\r
1387 UINT8 Count;\r
1388 CHAR8 *Psid;\r
1389 UINT32 PsidLen;\r
1390 OPAL_SESSION Session;\r
1391 BOOLEAN PressEsc;\r
1392 EFI_INPUT_KEY Key;\r
1393 TCG_RESULT Ret;\r
1394 CHAR16 *PopUpString;\r
40d32e79
ED
1395 CHAR16 *PopUpString2;\r
1396 UINTN BufferSize;\r
112e584b
SZ
1397\r
1398 if (Dev == NULL) {\r
1399 return;\r
1400 }\r
1401\r
1402 DEBUG ((DEBUG_INFO, "%a()\n", __FUNCTION__));\r
1403\r
1404 PopUpString = OpalGetPopUpString (Dev, RequestString);\r
1405\r
40d32e79
ED
1406 if (Dev->OpalDisk.EstimateTimeCost > MAX_ACCEPTABLE_REVERTING_TIME) {\r
1407 BufferSize = StrSize (L"Warning: Revert action will take about ####### seconds, DO NOT power off system during the revert action!");\r
1408 PopUpString2 = AllocateZeroPool (BufferSize);\r
1409 ASSERT (PopUpString2 != NULL);\r
1410 UnicodeSPrint (\r
1411 PopUpString2,\r
1412 BufferSize,\r
1413 L"WARNING: Revert action will take about %d seconds, DO NOT power off system during the revert action!",\r
1414 Dev->OpalDisk.EstimateTimeCost\r
1415 );\r
1416 } else {\r
1417 PopUpString2 = NULL;\r
1418 }\r
1419\r
112e584b
SZ
1420 Count = 0;\r
1421\r
1422 ZeroMem(&Session, sizeof(Session));\r
1423 Session.Sscp = Dev->OpalDisk.Sscp;\r
1424 Session.MediaId = Dev->OpalDisk.MediaId;\r
1425 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;\r
1426\r
1427 while (Count < MAX_PSID_TRY_COUNT) {\r
40d32e79 1428 Psid = OpalDriverPopUpPsidInput (Dev, PopUpString, PopUpString2, &PressEsc);\r
112e584b
SZ
1429 if (PressEsc) {\r
1430 do {\r
1431 CreatePopUp (\r
1432 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1433 &Key,\r
1434 L"Press ENTER to skip the request and continue boot,",\r
1435 L"Press ESC to input Psid again",\r
1436 NULL\r
1437 );\r
1438 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
1439\r
1440 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
1441 gST->ConOut->ClearScreen(gST->ConOut);\r
40d32e79 1442 goto Done;\r
112e584b
SZ
1443 } else {\r
1444 //\r
1445 // Let user input Psid again.\r
1446 //\r
1447 continue;\r
1448 }\r
1449 }\r
1450\r
1451 if (Psid == NULL) {\r
1452 Count ++;\r
1453 continue;\r
1454 }\r
1455 PsidLen = (UINT32) AsciiStrLen(Psid);\r
1456\r
1457 Ret = OpalUtilPsidRevert(&Session, Psid, PsidLen);\r
1458 if (Ret == TcgResultSuccess) {\r
1459 DEBUG ((DEBUG_INFO, "%s Success\n", RequestString));\r
1460 } else {\r
1461 DEBUG ((DEBUG_INFO, "%s Failure\n", RequestString));\r
1462 }\r
1463\r
1464 if (Psid != NULL) {\r
1465 ZeroMem (Psid, PsidLen);\r
1466 FreePool (Psid);\r
1467 }\r
1468\r
1469 if (Ret == TcgResultSuccess) {\r
1470 break;\r
1471 }\r
1472\r
1473 Count++;\r
1474\r
1475 do {\r
1476 CreatePopUp (\r
1477 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1478 &Key,\r
1479 L"Invalid Psid, request failed.",\r
1480 L"Press ENTER to retry",\r
1481 NULL\r
1482 );\r
1483 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
1484 }\r
1485\r
1486 if (Count >= MAX_PSID_TRY_COUNT) {\r
1487 do {\r
1488 CreatePopUp (\r
1489 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1490 &Key,\r
1491 L"Opal Psid retry count exceeds the limit.",\r
1492 L"Press ENTER to skip the request and continue boot",\r
1493 NULL\r
1494 );\r
1495 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
1496 gST->ConOut->ClearScreen(gST->ConOut);\r
1497 }\r
40d32e79
ED
1498\r
1499Done:\r
1500 if (PopUpString2 != NULL) {\r
1501 FreePool (PopUpString2);\r
1502 }\r
112e584b
SZ
1503}\r
1504\r
1505/**\r
1506 Process Admin Revert OPAL request.\r
1507\r
1508 @param[in] Dev The device which has Revert OPAL request.\r
1509 @param[in] KeepUserData Whether to keep user data or not.\r
1510 @param[in] RequestString Request string.\r
1511\r
1512**/\r
1513VOID\r
1514ProcessOpalRequestRevert (\r
1515 IN OPAL_DRIVER_DEVICE *Dev,\r
1516 IN BOOLEAN KeepUserData,\r
1517 IN CHAR16 *RequestString\r
1518 )\r
1519{\r
1520 UINT8 Count;\r
1521 CHAR8 *Password;\r
1522 UINT32 PasswordLen;\r
1523 OPAL_SESSION Session;\r
1524 BOOLEAN PressEsc;\r
1525 EFI_INPUT_KEY Key;\r
1526 TCG_RESULT Ret;\r
1527 BOOLEAN PasswordFailed;\r
1528 CHAR16 *PopUpString;\r
40d32e79
ED
1529 CHAR16 *PopUpString2;\r
1530 UINTN BufferSize;\r
112e584b
SZ
1531\r
1532 if (Dev == NULL) {\r
1533 return;\r
1534 }\r
1535\r
1536 DEBUG ((DEBUG_INFO, "%a()\n", __FUNCTION__));\r
1537\r
1538 PopUpString = OpalGetPopUpString (Dev, RequestString);\r
1539\r
40d32e79
ED
1540 if (Dev->OpalDisk.EstimateTimeCost > MAX_ACCEPTABLE_REVERTING_TIME) {\r
1541 BufferSize = StrSize (L"Warning: Revert action will take about ####### seconds, DO NOT power off system during the revert action!");\r
1542 PopUpString2 = AllocateZeroPool (BufferSize);\r
1543 ASSERT (PopUpString2 != NULL);\r
1544 UnicodeSPrint (\r
1545 PopUpString2,\r
1546 BufferSize,\r
1547 L"WARNING: Revert action will take about %d seconds, DO NOT power off system during the revert action!",\r
1548 Dev->OpalDisk.EstimateTimeCost\r
1549 );\r
1550 } else {\r
1551 PopUpString2 = NULL;\r
1552 }\r
1553\r
112e584b
SZ
1554 Count = 0;\r
1555\r
1556 ZeroMem(&Session, sizeof(Session));\r
1557 Session.Sscp = Dev->OpalDisk.Sscp;\r
1558 Session.MediaId = Dev->OpalDisk.MediaId;\r
1559 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;\r
1560\r
1561 while (Count < MAX_PASSWORD_TRY_COUNT) {\r
40d32e79 1562 Password = OpalDriverPopUpPasswordInput (Dev, PopUpString, PopUpString2, &PressEsc);\r
112e584b
SZ
1563 if (PressEsc) {\r
1564 do {\r
1565 CreatePopUp (\r
1566 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1567 &Key,\r
1568 L"Press ENTER to skip the request and continue boot,",\r
1569 L"Press ESC to input password again",\r
1570 NULL\r
1571 );\r
1572 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
1573\r
1574 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
1575 gST->ConOut->ClearScreen(gST->ConOut);\r
40d32e79 1576 goto Done;\r
112e584b
SZ
1577 } else {\r
1578 //\r
1579 // Let user input password again.\r
1580 //\r
1581 continue;\r
1582 }\r
1583 }\r
1584\r
1585 if (Password == NULL) {\r
1586 Count ++;\r
1587 continue;\r
1588 }\r
1589 PasswordLen = (UINT32) AsciiStrLen(Password);\r
1590\r
1591 if ((Dev->OpalDisk.SupportedAttributes.PyriteSsc == 1) &&\r
1592 (Dev->OpalDisk.LockingFeature.MediaEncryption == 0)) {\r
1593 //\r
1594 // For pyrite type device which does not support media encryption,\r
1595 // it does not accept "Keep User Data" parameter.\r
1596 // So here hardcode a FALSE for this case.\r
1597 //\r
1598 Ret = OpalUtilRevert(\r
1599 &Session,\r
1600 FALSE,\r
1601 Password,\r
1602 PasswordLen,\r
1603 &PasswordFailed,\r
1604 Dev->OpalDisk.Msid,\r
1605 Dev->OpalDisk.MsidLength\r
1606 );\r
1607 } else {\r
1608 Ret = OpalUtilRevert(\r
1609 &Session,\r
1610 KeepUserData,\r
1611 Password,\r
1612 PasswordLen,\r
1613 &PasswordFailed,\r
1614 Dev->OpalDisk.Msid,\r
1615 Dev->OpalDisk.MsidLength\r
1616 );\r
1617 }\r
1618 if (Ret == TcgResultSuccess) {\r
1619 OpalSupportUpdatePassword (&Dev->OpalDisk, Password, PasswordLen);\r
1620 DEBUG ((DEBUG_INFO, "%s Success\n", RequestString));\r
1621 } else {\r
1622 DEBUG ((DEBUG_INFO, "%s Failure\n", RequestString));\r
1623 }\r
1624\r
1625 if (Password != NULL) {\r
1626 ZeroMem (Password, PasswordLen);\r
1627 FreePool (Password);\r
1628 }\r
1629\r
1630 if (Ret == TcgResultSuccess) {\r
1631 break;\r
1632 }\r
1633\r
1634 Count++;\r
1635\r
1636 do {\r
1637 CreatePopUp (\r
1638 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1639 &Key,\r
1640 L"Invalid password, request failed.",\r
1641 L"Press ENTER to retry",\r
1642 NULL\r
1643 );\r
1644 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
1645 }\r
1646\r
1647 if (Count >= MAX_PASSWORD_TRY_COUNT) {\r
1648 do {\r
1649 CreatePopUp (\r
1650 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1651 &Key,\r
1652 L"Opal password retry count exceeds the limit.",\r
1653 L"Press ENTER to skip the request and continue boot",\r
1654 NULL\r
1655 );\r
1656 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
1657 gST->ConOut->ClearScreen(gST->ConOut);\r
1658 }\r
40d32e79
ED
1659\r
1660Done:\r
1661 if (PopUpString2 != NULL) {\r
1662 FreePool (PopUpString2);\r
1663 }\r
112e584b
SZ
1664}\r
1665\r
1666/**\r
1667 Process Secure Erase OPAL request.\r
1668\r
1669 @param[in] Dev The device which has Secure Erase OPAL request.\r
1670 @param[in] RequestString Request string.\r
1671\r
1672**/\r
1673VOID\r
1674ProcessOpalRequestSecureErase (\r
1675 IN OPAL_DRIVER_DEVICE *Dev,\r
1676 IN CHAR16 *RequestString\r
1677 )\r
1678{\r
1679 UINT8 Count;\r
1680 CHAR8 *Password;\r
1681 UINT32 PasswordLen;\r
1682 OPAL_SESSION Session;\r
1683 BOOLEAN PressEsc;\r
1684 EFI_INPUT_KEY Key;\r
1685 TCG_RESULT Ret;\r
1686 BOOLEAN PasswordFailed;\r
1687 CHAR16 *PopUpString;\r
1688\r
1689 if (Dev == NULL) {\r
1690 return;\r
1691 }\r
1692\r
1693 DEBUG ((DEBUG_INFO, "%a()\n", __FUNCTION__));\r
1694\r
1695 PopUpString = OpalGetPopUpString (Dev, RequestString);\r
1696\r
1697 Count = 0;\r
1698\r
1699 ZeroMem(&Session, sizeof(Session));\r
1700 Session.Sscp = Dev->OpalDisk.Sscp;\r
1701 Session.MediaId = Dev->OpalDisk.MediaId;\r
1702 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;\r
1703\r
1704 while (Count < MAX_PASSWORD_TRY_COUNT) {\r
1705 Password = OpalDriverPopUpPasswordInput (Dev, PopUpString, NULL, &PressEsc);\r
1706 if (PressEsc) {\r
1707 do {\r
1708 CreatePopUp (\r
1709 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1710 &Key,\r
1711 L"Press ENTER to skip the request and continue boot,",\r
1712 L"Press ESC to input password again",\r
1713 NULL\r
1714 );\r
1715 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
1716\r
1717 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
1718 gST->ConOut->ClearScreen(gST->ConOut);\r
1719 return;\r
1720 } else {\r
1721 //\r
1722 // Let user input password again.\r
1723 //\r
1724 continue;\r
1725 }\r
1726 }\r
1727\r
1728 if (Password == NULL) {\r
1729 Count ++;\r
1730 continue;\r
1731 }\r
1732 PasswordLen = (UINT32) AsciiStrLen(Password);\r
1733\r
1734 Ret = OpalUtilSecureErase(&Session, Password, PasswordLen, &PasswordFailed);\r
1735 if (Ret == TcgResultSuccess) {\r
1736 OpalSupportUpdatePassword (&Dev->OpalDisk, Password, PasswordLen);\r
1737 DEBUG ((DEBUG_INFO, "%s Success\n", RequestString));\r
1738 } else {\r
1739 DEBUG ((DEBUG_INFO, "%s Failure\n", RequestString));\r
1740 }\r
1741\r
1742 if (Password != NULL) {\r
1743 ZeroMem (Password, PasswordLen);\r
1744 FreePool (Password);\r
1745 }\r
1746\r
1747 if (Ret == TcgResultSuccess) {\r
1748 break;\r
1749 }\r
1750\r
1751 Count++;\r
1752\r
1753 do {\r
1754 CreatePopUp (\r
1755 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1756 &Key,\r
1757 L"Invalid password, request failed.",\r
1758 L"Press ENTER to retry",\r
1759 NULL\r
1760 );\r
1761 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
1762 }\r
1763\r
1764 if (Count >= MAX_PASSWORD_TRY_COUNT) {\r
1765 do {\r
1766 CreatePopUp (\r
1767 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1768 &Key,\r
1769 L"Opal password retry count exceeds the limit.",\r
1770 L"Press ENTER to skip the request and continue boot",\r
1771 NULL\r
1772 );\r
1773 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
1774 gST->ConOut->ClearScreen(gST->ConOut);\r
1775 }\r
1776}\r
1777\r
1778/**\r
1779 Process Set Admin Pwd OPAL request.\r
1780\r
1781 @param[in] Dev The device which has Set Admin Pwd Feature OPAL request.\r
1782 @param[in] RequestString Request string.\r
1783\r
1784**/\r
1785VOID\r
1786ProcessOpalRequestSetUserPwd (\r
1787 IN OPAL_DRIVER_DEVICE *Dev,\r
1788 IN CHAR16 *RequestString\r
1789 )\r
1790{\r
1791 UINT8 Count;\r
1792 CHAR8 *OldPassword;\r
1793 UINT32 OldPasswordLen;\r
1794 CHAR8 *Password;\r
1795 UINT32 PasswordLen;\r
1796 CHAR8 *PasswordConfirm;\r
1797 UINT32 PasswordLenConfirm;\r
1798 OPAL_SESSION Session;\r
1799 BOOLEAN PressEsc;\r
1800 EFI_INPUT_KEY Key;\r
1801 TCG_RESULT Ret;\r
1802 CHAR16 *PopUpString;\r
1803\r
1804 if (Dev == NULL) {\r
1805 return;\r
1806 }\r
1807\r
1808 DEBUG ((DEBUG_INFO, "%a()\n", __FUNCTION__));\r
1809\r
1810 PopUpString = OpalGetPopUpString (Dev, RequestString);\r
1811\r
1812 Count = 0;\r
1813\r
1814 while (Count < MAX_PASSWORD_TRY_COUNT) {\r
1815 OldPassword = OpalDriverPopUpPasswordInput (Dev, PopUpString, L"Please type in your password", &PressEsc);\r
1816 if (PressEsc) {\r
1817 do {\r
1818 CreatePopUp (\r
1819 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1820 &Key,\r
1821 L"Press ENTER to skip the request and continue boot,",\r
1822 L"Press ESC to input password again",\r
1823 NULL\r
1824 );\r
1825 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
1826\r
1827 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
1828 gST->ConOut->ClearScreen(gST->ConOut);\r
1829 return;\r
1830 } else {\r
1831 //\r
1832 // Let user input password again.\r
1833 //\r
1834 continue;\r
1835 }\r
1836 }\r
1837\r
1838 if (OldPassword == NULL) {\r
1839 Count ++;\r
1840 continue;\r
1841 }\r
1842 OldPasswordLen = (UINT32) AsciiStrLen(OldPassword);\r
1843\r
1844 ZeroMem(&Session, sizeof(Session));\r
1845 Session.Sscp = Dev->OpalDisk.Sscp;\r
1846 Session.MediaId = Dev->OpalDisk.MediaId;\r
1847 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;\r
1848 Ret = OpalUtilVerifyPassword (&Session, OldPassword, OldPasswordLen, OPAL_LOCKING_SP_USER1_AUTHORITY);\r
1849 if (Ret == TcgResultSuccess) {\r
1850 DEBUG ((DEBUG_INFO, "Verify with USER1 authority : Success\n"));\r
1851 } else {\r
1852 Ret = OpalUtilVerifyPassword (&Session, OldPassword, OldPasswordLen, OPAL_LOCKING_SP_ADMIN1_AUTHORITY);\r
1853 if (Ret == TcgResultSuccess) {\r
1854 DEBUG ((DEBUG_INFO, "Verify with ADMIN1 authority: Success\n"));\r
1855 } else {\r
1856 ZeroMem (OldPassword, OldPasswordLen);\r
1857 FreePool (OldPassword);\r
1858 DEBUG ((DEBUG_INFO, "Verify: Failure\n"));\r
1859 do {\r
1860 CreatePopUp (\r
1861 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1862 &Key,\r
1863 L"Incorrect password.",\r
1864 L"Press ENTER to retry",\r
1865 NULL\r
1866 );\r
1867 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
1868 Count ++;\r
1869 continue;\r
1870 }\r
1871 }\r
1872\r
1873 Password = OpalDriverPopUpPasswordInput (Dev, PopUpString, L"Please type in your new password", &PressEsc);\r
1874 if (Password == NULL) {\r
1875 ZeroMem (OldPassword, OldPasswordLen);\r
1876 FreePool (OldPassword);\r
1877 Count ++;\r
1878 continue;\r
1879 }\r
1880 PasswordLen = (UINT32) AsciiStrLen(Password);\r
1881\r
1882 PasswordConfirm = OpalDriverPopUpPasswordInput (Dev, PopUpString, L"Please confirm your new password", &PressEsc);\r
1883 if (PasswordConfirm == NULL) {\r
1884 ZeroMem (OldPassword, OldPasswordLen);\r
1885 FreePool (OldPassword);\r
1886 ZeroMem (Password, PasswordLen);\r
1887 FreePool (Password);\r
1888 Count ++;\r
1889 continue;\r
1890 }\r
1891 PasswordLenConfirm = (UINT32) AsciiStrLen(PasswordConfirm);\r
1892 if ((PasswordLen != PasswordLenConfirm) ||\r
1893 (CompareMem (Password, PasswordConfirm, PasswordLen) != 0)) {\r
1894 ZeroMem (OldPassword, OldPasswordLen);\r
1895 FreePool (OldPassword);\r
1896 ZeroMem (Password, PasswordLen);\r
1897 FreePool (Password);\r
1898 ZeroMem (PasswordConfirm, PasswordLenConfirm);\r
1899 FreePool (PasswordConfirm);\r
1900 do {\r
1901 CreatePopUp (\r
1902 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1903 &Key,\r
1904 L"Passwords are not the same.",\r
1905 L"Press ENTER to retry",\r
1906 NULL\r
1907 );\r
1908 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
1909 Count ++;\r
1910 continue;\r
1911 }\r
1912\r
1913 if (PasswordConfirm != NULL) {\r
1914 ZeroMem (PasswordConfirm, PasswordLenConfirm);\r
1915 FreePool (PasswordConfirm);\r
1916 }\r
1917\r
1918 ZeroMem(&Session, sizeof(Session));\r
1919 Session.Sscp = Dev->OpalDisk.Sscp;\r
1920 Session.MediaId = Dev->OpalDisk.MediaId;\r
1921 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;\r
1922 Ret = OpalUtilSetUserPassword(\r
1923 &Session,\r
1924 OldPassword,\r
1925 OldPasswordLen,\r
1926 Password,\r
1927 PasswordLen\r
1928 );\r
1929 if (Ret == TcgResultSuccess) {\r
1930 OpalSupportUpdatePassword (&Dev->OpalDisk, Password, PasswordLen);\r
1931 DEBUG ((DEBUG_INFO, "%s Success\n", RequestString));\r
1932 } else {\r
1933 DEBUG ((DEBUG_INFO, "%s Failure\n", RequestString));\r
1934 }\r
1935\r
1936 if (OldPassword != NULL) {\r
1937 ZeroMem (OldPassword, OldPasswordLen);\r
1938 FreePool (OldPassword);\r
1939 }\r
1940\r
1941 if (Password != NULL) {\r
1942 ZeroMem (Password, PasswordLen);\r
1943 FreePool (Password);\r
1944 }\r
1945\r
1946 if (Ret == TcgResultSuccess) {\r
1947 break;\r
1948 }\r
1949\r
1950 Count++;\r
1951\r
1952 do {\r
1953 CreatePopUp (\r
1954 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1955 &Key,\r
1956 L"Request failed.",\r
1957 L"Press ENTER to retry",\r
1958 NULL\r
1959 );\r
1960 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
1961 }\r
1962\r
1963 if (Count >= MAX_PASSWORD_TRY_COUNT) {\r
1964 do {\r
1965 CreatePopUp (\r
1966 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
1967 &Key,\r
1968 L"Opal password retry count exceeds the limit.",\r
1969 L"Press ENTER to skip the request and continue boot",\r
1970 NULL\r
1971 );\r
1972 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
1973 gST->ConOut->ClearScreen(gST->ConOut);\r
1974 }\r
1975}\r
1976\r
1977/**\r
1978 Process Set Admin Pwd OPAL request.\r
1979\r
1980 @param[in] Dev The device which has Set Admin Pwd Feature OPAL request.\r
1981 @param[in] RequestString Request string.\r
1982\r
1983**/\r
1984VOID\r
1985ProcessOpalRequestSetAdminPwd (\r
1986 IN OPAL_DRIVER_DEVICE *Dev,\r
1987 IN CHAR16 *RequestString\r
1988 )\r
1989{\r
1990 UINT8 Count;\r
1991 CHAR8 *OldPassword;\r
1992 UINT32 OldPasswordLen;\r
1993 CHAR8 *Password;\r
1994 UINT32 PasswordLen;\r
1995 CHAR8 *PasswordConfirm;\r
1996 UINT32 PasswordLenConfirm;\r
1997 OPAL_SESSION Session;\r
1998 BOOLEAN PressEsc;\r
1999 EFI_INPUT_KEY Key;\r
2000 TCG_RESULT Ret;\r
2001 CHAR16 *PopUpString;\r
2002\r
2003 if (Dev == NULL) {\r
2004 return;\r
2005 }\r
2006\r
2007 DEBUG ((DEBUG_INFO, "%a()\n", __FUNCTION__));\r
2008\r
2009 PopUpString = OpalGetPopUpString (Dev, RequestString);\r
2010\r
2011 Count = 0;\r
2012\r
2013 while (Count < MAX_PASSWORD_TRY_COUNT) {\r
2014 OldPassword = OpalDriverPopUpPasswordInput (Dev, PopUpString, L"Please type in your password", &PressEsc);\r
2015 if (PressEsc) {\r
2016 do {\r
2017 CreatePopUp (\r
2018 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
2019 &Key,\r
2020 L"Press ENTER to skip the request and continue boot,",\r
2021 L"Press ESC to input password again",\r
2022 NULL\r
2023 );\r
2024 } while ((Key.ScanCode != SCAN_ESC) && (Key.UnicodeChar != CHAR_CARRIAGE_RETURN));\r
2025\r
2026 if (Key.UnicodeChar == CHAR_CARRIAGE_RETURN) {\r
2027 gST->ConOut->ClearScreen(gST->ConOut);\r
2028 return;\r
2029 } else {\r
2030 //\r
2031 // Let user input password again.\r
2032 //\r
2033 continue;\r
2034 }\r
2035 }\r
2036\r
2037 if (OldPassword == NULL) {\r
2038 Count ++;\r
2039 continue;\r
2040 }\r
2041 OldPasswordLen = (UINT32) AsciiStrLen(OldPassword);\r
2042\r
2043 ZeroMem(&Session, sizeof(Session));\r
2044 Session.Sscp = Dev->OpalDisk.Sscp;\r
2045 Session.MediaId = Dev->OpalDisk.MediaId;\r
2046 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;\r
2047 Ret = OpalUtilVerifyPassword (&Session, OldPassword, OldPasswordLen, OPAL_LOCKING_SP_ADMIN1_AUTHORITY);\r
2048 if (Ret == TcgResultSuccess) {\r
2049 DEBUG ((DEBUG_INFO, "Verify: Success\n"));\r
2050 } else {\r
2051 ZeroMem (OldPassword, OldPasswordLen);\r
2052 FreePool (OldPassword);\r
2053 DEBUG ((DEBUG_INFO, "Verify: Failure\n"));\r
2054 do {\r
2055 CreatePopUp (\r
2056 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
2057 &Key,\r
2058 L"Incorrect password.",\r
2059 L"Press ENTER to retry",\r
2060 NULL\r
2061 );\r
2062 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
2063 Count ++;\r
2064 continue;\r
2065 }\r
2066\r
2067 Password = OpalDriverPopUpPasswordInput (Dev, PopUpString, L"Please type in your new password", &PressEsc);\r
2068 if (Password == NULL) {\r
2069 ZeroMem (OldPassword, OldPasswordLen);\r
2070 FreePool (OldPassword);\r
2071 Count ++;\r
2072 continue;\r
2073 }\r
2074 PasswordLen = (UINT32) AsciiStrLen(Password);\r
2075\r
2076 PasswordConfirm = OpalDriverPopUpPasswordInput (Dev, PopUpString, L"Please confirm your new password", &PressEsc);\r
2077 if (PasswordConfirm == NULL) {\r
2078 ZeroMem (OldPassword, OldPasswordLen);\r
2079 FreePool (OldPassword);\r
2080 ZeroMem (Password, PasswordLen);\r
2081 FreePool (Password);\r
2082 Count ++;\r
2083 continue;\r
2084 }\r
2085 PasswordLenConfirm = (UINT32) AsciiStrLen(PasswordConfirm);\r
2086 if ((PasswordLen != PasswordLenConfirm) ||\r
2087 (CompareMem (Password, PasswordConfirm, PasswordLen) != 0)) {\r
2088 ZeroMem (OldPassword, OldPasswordLen);\r
2089 FreePool (OldPassword);\r
2090 ZeroMem (Password, PasswordLen);\r
2091 FreePool (Password);\r
2092 ZeroMem (PasswordConfirm, PasswordLenConfirm);\r
2093 FreePool (PasswordConfirm);\r
2094 do {\r
2095 CreatePopUp (\r
2096 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
2097 &Key,\r
2098 L"Passwords are not the same.",\r
2099 L"Press ENTER to retry",\r
2100 NULL\r
2101 );\r
2102 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
2103 Count ++;\r
2104 continue;\r
2105 }\r
2106\r
2107 if (PasswordConfirm != NULL) {\r
2108 ZeroMem (PasswordConfirm, PasswordLenConfirm);\r
2109 FreePool (PasswordConfirm);\r
2110 }\r
2111\r
2112\r
2113 ZeroMem(&Session, sizeof(Session));\r
2114 Session.Sscp = Dev->OpalDisk.Sscp;\r
2115 Session.MediaId = Dev->OpalDisk.MediaId;\r
2116 Session.OpalBaseComId = Dev->OpalDisk.OpalBaseComId;\r
2117 Ret = OpalUtilSetAdminPassword(\r
2118 &Session,\r
2119 OldPassword,\r
2120 OldPasswordLen,\r
2121 Password,\r
2122 PasswordLen\r
2123 );\r
2124 if (Ret == TcgResultSuccess) {\r
2125 OpalSupportUpdatePassword (&Dev->OpalDisk, Password, PasswordLen);\r
2126 DEBUG ((DEBUG_INFO, "%s Success\n", RequestString));\r
2127 } else {\r
2128 DEBUG ((DEBUG_INFO, "%s Failure\n", RequestString));\r
2129 }\r
2130\r
2131 if (OldPassword != NULL) {\r
2132 ZeroMem (OldPassword, OldPasswordLen);\r
2133 FreePool (OldPassword);\r
2134 }\r
2135\r
2136 if (Password != NULL) {\r
2137 ZeroMem (Password, PasswordLen);\r
2138 FreePool (Password);\r
2139 }\r
2140\r
2141 if (Ret == TcgResultSuccess) {\r
2142 break;\r
2143 }\r
2144\r
2145 Count++;\r
2146\r
2147 do {\r
2148 CreatePopUp (\r
2149 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
2150 &Key,\r
2151 L"Request failed.",\r
2152 L"Press ENTER to retry",\r
2153 NULL\r
2154 );\r
2155 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
2156 }\r
2157\r
2158 if (Count >= MAX_PASSWORD_TRY_COUNT) {\r
2159 do {\r
2160 CreatePopUp (\r
2161 EFI_LIGHTGRAY | EFI_BACKGROUND_BLUE,\r
2162 &Key,\r
2163 L"Opal password retry count exceeds the limit.",\r
2164 L"Press ENTER to skip the request and continue boot",\r
2165 NULL\r
2166 );\r
2167 } while (Key.UnicodeChar != CHAR_CARRIAGE_RETURN);\r
2168 gST->ConOut->ClearScreen(gST->ConOut);\r
2169 }\r
2170}\r
2171\r
2172/**\r
2173 Process OPAL request.\r
2174\r
2175 @param[in] Dev The device which has OPAL request.\r
2176\r
2177**/\r
2178VOID\r
2179ProcessOpalRequest (\r
2180 IN OPAL_DRIVER_DEVICE *Dev\r
2181 )\r
2182{\r
2183 EFI_STATUS Status;\r
2184 OPAL_REQUEST_VARIABLE *TempVariable;\r
2185 OPAL_REQUEST_VARIABLE *Variable;\r
2186 UINTN VariableSize;\r
2187 EFI_DEVICE_PATH_PROTOCOL *DevicePathInVariable;\r
2188 UINTN DevicePathSizeInVariable;\r
2189 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
2190 UINTN DevicePathSize;\r
2191 BOOLEAN KeepUserData;\r
2192\r
2193 DEBUG ((DEBUG_INFO, "%a() - enter\n", __FUNCTION__));\r
2194\r
2195 if (mOpalRequestVariable == NULL) {\r
2196 Status = GetVariable2 (\r
2197 OPAL_REQUEST_VARIABLE_NAME,\r
2198 &gHiiSetupVariableGuid,\r
2199 (VOID **) &Variable,\r
2200 &VariableSize\r
2201 );\r
2202 if (EFI_ERROR (Status) || (Variable == NULL)) {\r
2203 return;\r
2204 }\r
2205 mOpalRequestVariable = Variable;\r
2206 mOpalRequestVariableSize = VariableSize;\r
2207\r
2208 //\r
2209 // Delete the OPAL request variable.\r
2210 //\r
2211 Status = gRT->SetVariable (\r
2212 OPAL_REQUEST_VARIABLE_NAME,\r
2213 (EFI_GUID *) &gHiiSetupVariableGuid,\r
2214 0,\r
2215 0,\r
2216 NULL\r
2217 );\r
2218 ASSERT_EFI_ERROR (Status);\r
2219 } else {\r
2220 Variable = mOpalRequestVariable;\r
2221 VariableSize = mOpalRequestVariableSize;\r
2222 }\r
2223\r
2224 //\r
2225 // Process the OPAL requests.\r
2226 //\r
2227 TempVariable = Variable;\r
2228 while ((VariableSize > sizeof (OPAL_REQUEST_VARIABLE)) &&\r
2229 (VariableSize >= TempVariable->Length) &&\r
2230 (TempVariable->Length > sizeof (OPAL_REQUEST_VARIABLE))) {\r
2231 DevicePathInVariable = (EFI_DEVICE_PATH_PROTOCOL *) ((UINTN) TempVariable + sizeof (OPAL_REQUEST_VARIABLE));\r
2232 DevicePathSizeInVariable = GetDevicePathSize (DevicePathInVariable);\r
2233 DevicePath = Dev->OpalDisk.OpalDevicePath;\r
2234 DevicePathSize = GetDevicePathSize (DevicePath);\r
2235 if ((DevicePathSize == DevicePathSizeInVariable) &&\r
2236 (CompareMem (DevicePath, DevicePathInVariable, DevicePathSize) == 0)) {\r
2237 //\r
2238 // Found the node for the OPAL device.\r
2239 //\r
2240 if (TempVariable->OpalRequest.SetAdminPwd != 0) {\r
2241 ProcessOpalRequestSetAdminPwd (Dev, L"Update Admin Pwd:");\r
2242 }\r
2243 if (TempVariable->OpalRequest.SetUserPwd != 0) {\r
2244 ProcessOpalRequestSetUserPwd (Dev, L"Set User Pwd:");\r
2245 }\r
2246 if (TempVariable->OpalRequest.SecureErase!= 0) {\r
2247 ProcessOpalRequestSecureErase (Dev, L"Secure Erase:");\r
2248 }\r
2249 if (TempVariable->OpalRequest.Revert != 0) {\r
2250 KeepUserData = (BOOLEAN) TempVariable->OpalRequest.KeepUserData;\r
2251 ProcessOpalRequestRevert (\r
2252 Dev,\r
2253 KeepUserData,\r
2254 KeepUserData ? L"Admin Revert(keep):" : L"Admin Revert:"\r
2255 );\r
2256 }\r
2257 if (TempVariable->OpalRequest.PsidRevert != 0) {\r
2258 ProcessOpalRequestPsidRevert (Dev, L"Psid Revert:");\r
2259 }\r
2260 if (TempVariable->OpalRequest.DisableUser != 0) {\r
2261 ProcessOpalRequestDisableUser (Dev, L"Disable User:");\r
2262 }\r
2263 if (TempVariable->OpalRequest.EnableFeature != 0) {\r
2264 ProcessOpalRequestEnableFeature (Dev, L"Enable Feature:");\r
2265 }\r
2266\r
2267 break;\r
2268 }\r
2269\r
2270 VariableSize -= TempVariable->Length;\r
2271 TempVariable = (OPAL_REQUEST_VARIABLE *) ((UINTN) TempVariable + TempVariable->Length);\r
2272 }\r
2273\r
2274 DEBUG ((DEBUG_INFO, "%a() - exit\n", __FUNCTION__));\r
2275}\r
2276\r
2277/**\r
2278 Add new device to the global device list.\r
2279\r
2280 @param Dev New create device.\r
2281\r
2282**/\r
2283VOID\r
2284AddDeviceToTail(\r
2285 IN OPAL_DRIVER_DEVICE *Dev\r
2286 )\r
2287{\r
2288 OPAL_DRIVER_DEVICE *TmpDev;\r
2289\r
2290 if (mOpalDriver.DeviceList == NULL) {\r
2291 mOpalDriver.DeviceList = Dev;\r
2292 } else {\r
2293 TmpDev = mOpalDriver.DeviceList;\r
2294 while (TmpDev->Next != NULL) {\r
2295 TmpDev = TmpDev->Next;\r
2296 }\r
2297\r
2298 TmpDev->Next = Dev;\r
2299 }\r
2300}\r
2301\r
2302/**\r
2303 Remove one device in the global device list.\r
2304\r
2305 @param Dev The device need to be removed.\r
2306\r
2307**/\r
2308VOID\r
2309RemoveDevice (\r
2310 IN OPAL_DRIVER_DEVICE *Dev\r
2311 )\r
2312{\r
2313 OPAL_DRIVER_DEVICE *TmpDev;\r
2314\r
2315 if (mOpalDriver.DeviceList == NULL) {\r
2316 return;\r
2317 }\r
2318\r
2319 if (mOpalDriver.DeviceList == Dev) {\r
2320 mOpalDriver.DeviceList = NULL;\r
2321 return;\r
2322 }\r
2323\r
2324 TmpDev = mOpalDriver.DeviceList;\r
2325 while (TmpDev->Next != NULL) {\r
2326 if (TmpDev->Next == Dev) {\r
2327 TmpDev->Next = Dev->Next;\r
2328 break;\r
2329 }\r
2330 }\r
2331}\r
2332\r
2333/**\r
2334 Get current device count.\r
2335\r
2336 @retval return the current created device count.\r
2337\r
2338**/\r
2339UINT8\r
2340GetDeviceCount (\r
2341 VOID\r
2342 )\r
2343{\r
2344 UINT8 Count;\r
2345 OPAL_DRIVER_DEVICE *TmpDev;\r
2346\r
2347 Count = 0;\r
2348 TmpDev = mOpalDriver.DeviceList;\r
2349\r
2350 while (TmpDev != NULL) {\r
2351 Count++;\r
2352 TmpDev = TmpDev->Next;\r
2353 }\r
2354\r
2355 return Count;\r
2356}\r
2357\r
2358/**\r
2359 Get devcie list info.\r
2360\r
2361 @retval return the device list pointer.\r
2362**/\r
2363OPAL_DRIVER_DEVICE*\r
2364OpalDriverGetDeviceList(\r
2365 VOID\r
2366 )\r
2367{\r
2368 return mOpalDriver.DeviceList;\r
2369}\r
2370\r
2371/**\r
2372 ReadyToBoot callback to send BlockSid command.\r
2373\r
2374 @param Event Pointer to this event\r
2375 @param Context Event handler private Data\r
2376\r
2377**/\r
2378VOID\r
2379EFIAPI\r
2380ReadyToBootCallback (\r
2381 IN EFI_EVENT Event,\r
2382 IN VOID *Context\r
2383 )\r
2384{\r
2385 OPAL_DRIVER_DEVICE *Itr;\r
2386 TCG_RESULT Result;\r
2387 OPAL_SESSION Session;\r
2388 UINT32 PpStorageFlag;\r
2389\r
2390 gBS->CloseEvent (Event);\r
2391\r
2392 PpStorageFlag = Tcg2PhysicalPresenceLibGetManagementFlags ();\r
2393 if ((PpStorageFlag & TCG2_BIOS_STORAGE_MANAGEMENT_FLAG_ENABLE_BLOCK_SID) != 0) {\r
2394 //\r
2395 // Send BlockSID command to each Opal disk\r
2396 //\r
2397 Itr = mOpalDriver.DeviceList;\r
2398 while (Itr != NULL) {\r
2399 if (Itr->OpalDisk.SupportedAttributes.BlockSid) {\r
2400 ZeroMem(&Session, sizeof(Session));\r
2401 Session.Sscp = Itr->OpalDisk.Sscp;\r
2402 Session.MediaId = Itr->OpalDisk.MediaId;\r
2403 Session.OpalBaseComId = Itr->OpalDisk.OpalBaseComId;\r
2404\r
40d32e79 2405 DEBUG ((DEBUG_INFO, "OpalPassword: ReadyToBoot point, send BlockSid command to device!\n"));\r
112e584b
SZ
2406 Result = OpalBlockSid (&Session, TRUE); // HardwareReset must always be TRUE\r
2407 if (Result != TcgResultSuccess) {\r
2408 DEBUG ((DEBUG_ERROR, "OpalBlockSid fail\n"));\r
2409 break;\r
2410 }\r
2411 }\r
2412\r
2413 Itr = Itr->Next;\r
2414 }\r
2415 }\r
2416}\r
2417\r
2418/**\r
2419 Stop this Controller.\r
2420\r
2421 @param Dev The device need to be stopped.\r
2422\r
2423**/\r
2424VOID\r
2425OpalDriverStopDevice (\r
2426 OPAL_DRIVER_DEVICE *Dev\r
2427 )\r
2428{\r
2429 //\r
2430 // free each name\r
2431 //\r
2432 FreePool(Dev->Name16);\r
2433\r
2434 //\r
2435 // remove OPAL_DRIVER_DEVICE from the list\r
2436 // it updates the controllerList pointer\r
2437 //\r
2438 RemoveDevice(Dev);\r
2439\r
2440 //\r
2441 // close protocols that were opened\r
2442 //\r
2443 gBS->CloseProtocol(\r
2444 Dev->Handle,\r
2445 &gEfiStorageSecurityCommandProtocolGuid,\r
2446 gOpalDriverBinding.DriverBindingHandle,\r
2447 Dev->Handle\r
2448 );\r
2449\r
2450 gBS->CloseProtocol(\r
2451 Dev->Handle,\r
2452 &gEfiBlockIoProtocolGuid,\r
2453 gOpalDriverBinding.DriverBindingHandle,\r
2454 Dev->Handle\r
2455 );\r
2456\r
2457 FreePool(Dev);\r
2458}\r
2459\r
2460/**\r
2461 Get devcie name through the component name protocol.\r
2462\r
2463 @param[in] AllHandlesBuffer The handle buffer for current system.\r
2464 @param[in] NumAllHandles The number of handles for the handle buffer.\r
2465 @param[in] Dev The device which need to get name.\r
2466 @param[in] UseComp1 Whether use component name or name2 protocol.\r
2467\r
2468 @retval TRUE Find the name for this device.\r
2469 @retval FALSE Not found the name for this device.\r
2470**/\r
2471BOOLEAN\r
2472OpalDriverGetDeviceNameByProtocol(\r
2473 EFI_HANDLE *AllHandlesBuffer,\r
2474 UINTN NumAllHandles,\r
2475 OPAL_DRIVER_DEVICE *Dev,\r
2476 BOOLEAN UseComp1\r
2477 )\r
2478{\r
2479 EFI_HANDLE* ProtocolHandlesBuffer;\r
2480 UINTN NumProtocolHandles;\r
2481 EFI_STATUS Status;\r
2482 EFI_COMPONENT_NAME2_PROTOCOL* Cnp1_2; // efi component name and componentName2 have same layout\r
2483 EFI_GUID Protocol;\r
2484 UINTN StrLength;\r
2485 EFI_DEVICE_PATH_PROTOCOL* TmpDevPath;\r
2486 UINTN Index1;\r
2487 UINTN Index2;\r
2488 EFI_HANDLE TmpHandle;\r
2489 CHAR16 *DevName;\r
2490\r
2491 if (Dev == NULL || AllHandlesBuffer == NULL || NumAllHandles == 0) {\r
2492 return FALSE;\r
2493 }\r
2494\r
2495 Protocol = UseComp1 ? gEfiComponentNameProtocolGuid : gEfiComponentName2ProtocolGuid;\r
2496\r
2497 //\r
2498 // Find all EFI_HANDLES with protocol\r
2499 //\r
2500 Status = gBS->LocateHandleBuffer(\r
2501 ByProtocol,\r
2502 &Protocol,\r
2503 NULL,\r
2504 &NumProtocolHandles,\r
2505 &ProtocolHandlesBuffer\r
2506 );\r
2507 if (EFI_ERROR(Status)) {\r
2508 return FALSE;\r
2509 }\r
2510\r
2511\r
2512 //\r
2513 // Exit early if no supported devices\r
2514 //\r
2515 if (NumProtocolHandles == 0) {\r
2516 return FALSE;\r
2517 }\r
2518\r
2519 //\r
2520 // Get printable name by iterating through all protocols\r
2521 // using the handle as the child, and iterate through all handles for the controller\r
2522 // exit loop early once found, if not found, then delete device\r
2523 // storage security protocol instances already exist, add them to internal list\r
2524 //\r
2525 Status = EFI_DEVICE_ERROR;\r
2526 for (Index1 = 0; Index1 < NumProtocolHandles; Index1++) {\r
2527 DevName = NULL;\r
2528\r
2529 if (Dev->Name16 != NULL) {\r
2530 return TRUE;\r
2531 }\r
2532\r
2533 TmpHandle = ProtocolHandlesBuffer[Index1];\r
2534\r
2535 Status = gBS->OpenProtocol(\r
2536 TmpHandle,\r
2537 &Protocol,\r
2538 (VOID**)&Cnp1_2,\r
2539 gImageHandle,\r
2540 NULL,\r
2541 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
2542 );\r
2543 if (EFI_ERROR(Status) || Cnp1_2 == NULL) {\r
2544 continue;\r
2545 }\r
2546\r
2547 //\r
2548 // Use all handles array as controller handle\r
2549 //\r
2550 for (Index2 = 0; Index2 < NumAllHandles; Index2++) {\r
2551 Status = Cnp1_2->GetControllerName(\r
2552 Cnp1_2,\r
2553 AllHandlesBuffer[Index2],\r
2554 Dev->Handle,\r
2555 LANGUAGE_ISO_639_2_ENGLISH,\r
2556 &DevName\r
2557 );\r
2558 if (EFI_ERROR(Status)) {\r
2559 Status = Cnp1_2->GetControllerName(\r
2560 Cnp1_2,\r
2561 AllHandlesBuffer[Index2],\r
2562 Dev->Handle,\r
2563 LANGUAGE_RFC_3066_ENGLISH,\r
2564 &DevName\r
2565 );\r
2566 }\r
2567 if (!EFI_ERROR(Status) && DevName != NULL) {\r
2568 StrLength = StrLen(DevName) + 1; // Add one for NULL terminator\r
2569 Dev->Name16 = AllocateZeroPool(StrLength * sizeof (CHAR16));\r
2570 ASSERT (Dev->Name16 != NULL);\r
2571 StrCpyS (Dev->Name16, StrLength, DevName);\r
2572 Dev->NameZ = (CHAR8*)AllocateZeroPool(StrLength);\r
2573 UnicodeStrToAsciiStrS (DevName, Dev->NameZ, StrLength);\r
2574\r
2575 //\r
2576 // Retrieve bridge BDF info and port number or namespace depending on type\r
2577 //\r
2578 TmpDevPath = NULL;\r
2579 Status = gBS->OpenProtocol(\r
2580 Dev->Handle,\r
2581 &gEfiDevicePathProtocolGuid,\r
2582 (VOID**)&TmpDevPath,\r
2583 gImageHandle,\r
2584 NULL,\r
2585 EFI_OPEN_PROTOCOL_GET_PROTOCOL\r
2586 );\r
2587 if (!EFI_ERROR(Status)) {\r
2588 Dev->OpalDevicePath = DuplicateDevicePath (TmpDevPath);\r
2589 return TRUE;\r
2590 }\r
2591\r
2592 if (Dev->Name16 != NULL) {\r
2593 FreePool(Dev->Name16);\r
2594 Dev->Name16 = NULL;\r
2595 }\r
2596 if (Dev->NameZ != NULL) {\r
2597 FreePool(Dev->NameZ);\r
2598 Dev->NameZ = NULL;\r
2599 }\r
2600 }\r
2601 }\r
2602 }\r
2603\r
2604 return FALSE;\r
2605}\r
2606\r
2607/**\r
2608 Get devcie name through the component name protocol.\r
2609\r
2610 @param[in] Dev The device which need to get name.\r
2611\r
2612 @retval TRUE Find the name for this device.\r
2613 @retval FALSE Not found the name for this device.\r
2614**/\r
2615BOOLEAN\r
2616OpalDriverGetDriverDeviceName(\r
2617 OPAL_DRIVER_DEVICE *Dev\r
2618 )\r
2619{\r
2620 EFI_HANDLE* AllHandlesBuffer;\r
2621 UINTN NumAllHandles;\r
2622 EFI_STATUS Status;\r
2623\r
2624 if (Dev == NULL) {\r
2625 DEBUG((DEBUG_ERROR | DEBUG_INIT, "OpalDriverGetDriverDeviceName Exiting, Dev=NULL\n"));\r
2626 return FALSE;\r
2627 }\r
2628\r
2629 //\r
2630 // Iterate through ComponentName2 handles to get name, if fails, try ComponentName\r
2631 //\r
2632 if (Dev->Name16 == NULL) {\r
2633 DEBUG((DEBUG_ERROR | DEBUG_INIT, "Name is null, update it\n"));\r
2634 //\r
2635 // Find all EFI_HANDLES\r
2636 //\r
2637 Status = gBS->LocateHandleBuffer(\r
2638 AllHandles,\r
2639 NULL,\r
2640 NULL,\r
2641 &NumAllHandles,\r
2642 &AllHandlesBuffer\r
2643 );\r
2644 if (EFI_ERROR(Status)) {\r
2645 DEBUG ((DEBUG_INFO, "LocateHandleBuffer for AllHandles failed %r\n", Status ));\r
2646 return FALSE;\r
2647 }\r
2648\r
2649 //\r
2650 // Try component Name2\r
2651 //\r
2652 if (!OpalDriverGetDeviceNameByProtocol(AllHandlesBuffer, NumAllHandles, Dev, FALSE)) {\r
2653 DEBUG((DEBUG_ERROR | DEBUG_INIT, "ComponentName2 failed to get device name, try ComponentName\n"));\r
2654 if (!OpalDriverGetDeviceNameByProtocol(AllHandlesBuffer, NumAllHandles, Dev, TRUE)) {\r
2655 DEBUG((DEBUG_ERROR | DEBUG_INIT, "ComponentName failed to get device name, skip device\n"));\r
2656 return FALSE;\r
2657 }\r
2658 }\r
2659 }\r
2660\r
2661 return TRUE;\r
2662}\r
2663\r
2664/**\r
2665 Main entry for this driver.\r
2666\r
2667 @param ImageHandle Image Handle this driver.\r
2668 @param SystemTable Pointer to SystemTable.\r
2669\r
2670 @retval EFI_SUCESS This function always complete successfully.\r
2671**/\r
2672EFI_STATUS\r
2673EFIAPI\r
2674EfiDriverEntryPoint(\r
2675 IN EFI_HANDLE ImageHandle,\r
2676 IN EFI_SYSTEM_TABLE* SystemTable\r
2677 )\r
2678{\r
2679 EFI_STATUS Status;\r
2680 EFI_EVENT ReadyToBootEvent;\r
2681 EFI_EVENT EndOfDxeEvent;\r
2682\r
2683 Status = EfiLibInstallDriverBindingComponentName2 (\r
2684 ImageHandle,\r
2685 SystemTable,\r
2686 &gOpalDriverBinding,\r
2687 ImageHandle,\r
2688 &gOpalComponentName,\r
2689 &gOpalComponentName2\r
2690 );\r
2691\r
2692 if (EFI_ERROR(Status)) {\r
2693 DEBUG((DEBUG_ERROR, "Install protocols to Opal driver Handle failed\n"));\r
2694 return Status ;\r
2695 }\r
2696\r
2697 //\r
2698 // Initialize Driver object\r
2699 //\r
2700 ZeroMem(&mOpalDriver, sizeof(mOpalDriver));\r
2701 mOpalDriver.Handle = ImageHandle;\r
2702\r
2703 Status = gBS->CreateEventEx (\r
2704 EVT_NOTIFY_SIGNAL,\r
2705 TPL_CALLBACK,\r
2706 OpalEndOfDxeEventNotify,\r
2707 NULL,\r
2708 &gEfiEndOfDxeEventGroupGuid,\r
2709 &EndOfDxeEvent\r
2710 );\r
2711 ASSERT_EFI_ERROR (Status);\r
2712\r
2713 //\r
2714 // register a ReadyToBoot event callback for sending BlockSid command\r
2715 //\r
2716 Status = EfiCreateEventReadyToBootEx (\r
2717 TPL_CALLBACK,\r
2718 ReadyToBootCallback,\r
2719 (VOID *) &ImageHandle,\r
2720 &ReadyToBootEvent\r
2721 );\r
2722\r
2723 //\r
2724 // Install Hii packages.\r
2725 //\r
2726 HiiInstall();\r
2727\r
2728 return Status;\r
2729}\r
2730\r
2731/**\r
2732 Tests to see if this driver supports a given controller.\r
2733\r
2734 This function checks to see if the controller contains an instance of the\r
2735 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL and the EFI_BLOCK_IO_PROTOCL\r
2736 and returns EFI_SUCCESS if it does.\r
2737\r
2738 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
2739 @param[in] ControllerHandle The Handle of the controller to test. This Handle\r
2740 must support a protocol interface that supplies\r
2741 an I/O abstraction to the driver.\r
2742 @param[in] RemainingDevicePath This parameter is ignored.\r
2743\r
2744 @retval EFI_SUCCESS The device contains required protocols\r
2745 @retval EFI_ALREADY_STARTED The device specified by ControllerHandle and\r
2746 RemainingDevicePath is already being managed by the driver\r
2747 specified by This.\r
2748 @retval EFI_ACCESS_DENIED The device specified by ControllerHandle and\r
2749 RemainingDevicePath is already being managed by a different\r
2750 driver or an application that requires exclusive access.\r
2751 Currently not implemented.\r
2752 @retval EFI_UNSUPPORTED The device does not contain requires protocols\r
2753\r
2754**/\r
2755EFI_STATUS\r
2756EFIAPI\r
2757OpalEfiDriverBindingSupported(\r
2758 IN EFI_DRIVER_BINDING_PROTOCOL* This,\r
2759 IN EFI_HANDLE Controller,\r
2760 IN EFI_DEVICE_PATH_PROTOCOL* RemainingDevicePath\r
2761 )\r
2762{\r
2763 EFI_STATUS Status;\r
2764 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL* SecurityCommand;\r
2765 EFI_BLOCK_IO_PROTOCOL* BlkIo;\r
2766\r
2767 if (mOpalEndOfDxe) {\r
2768 return EFI_UNSUPPORTED;\r
2769 }\r
2770\r
2771 //\r
2772 // Test EFI_STORAGE_SECURITY_COMMAND_PROTOCOL on controller Handle.\r
2773 //\r
2774 Status = gBS->OpenProtocol(\r
2775 Controller,\r
2776 &gEfiStorageSecurityCommandProtocolGuid,\r
2777 ( VOID ** )&SecurityCommand,\r
2778 This->DriverBindingHandle,\r
2779 Controller,\r
2780 EFI_OPEN_PROTOCOL_BY_DRIVER\r
2781 );\r
2782\r
2783 if (Status == EFI_ALREADY_STARTED) {\r
2784 return EFI_SUCCESS;\r
2785 }\r
2786\r
2787 if (EFI_ERROR(Status)) {\r
2788 return Status;\r
2789 }\r
2790\r
2791 //\r
2792 // Close protocol and reopen in Start call\r
2793 //\r
2794 gBS->CloseProtocol(\r
2795 Controller,\r
2796 &gEfiStorageSecurityCommandProtocolGuid,\r
2797 This->DriverBindingHandle,\r
2798 Controller\r
2799 );\r
2800\r
2801 //\r
2802 // Test EFI_BLOCK_IO_PROTOCOL on controller Handle, required by EFI_STORAGE_SECURITY_COMMAND_PROTOCOL\r
2803 // function APIs\r
2804 //\r
2805 Status = gBS->OpenProtocol(\r
2806 Controller,\r
2807 &gEfiBlockIoProtocolGuid,\r
2808 (VOID **)&BlkIo,\r
2809 This->DriverBindingHandle,\r
2810 Controller,\r
2811 EFI_OPEN_PROTOCOL_BY_DRIVER\r
2812 );\r
2813\r
2814 if (EFI_ERROR(Status)) {\r
2815 DEBUG((DEBUG_INFO, "No EFI_BLOCK_IO_PROTOCOL on controller\n"));\r
2816 return Status;\r
2817 }\r
2818\r
2819 //\r
2820 // Close protocol and reopen in Start call\r
2821 //\r
2822 gBS->CloseProtocol(\r
2823 Controller,\r
2824 &gEfiBlockIoProtocolGuid,\r
2825 This->DriverBindingHandle,\r
2826 Controller\r
2827 );\r
2828\r
2829 return EFI_SUCCESS;\r
2830}\r
2831\r
2832/**\r
2833 Enables Opal Management on a supported device if available.\r
2834\r
2835 The start function is designed to be called after the Opal UEFI Driver has confirmed the\r
2836 "controller", which is a child Handle, contains the EF_STORAGE_SECURITY_COMMAND protocols.\r
2837 This function will complete the other necessary checks, such as verifying the device supports\r
2838 the correct version of Opal. Upon verification, it will add the device to the\r
2839 Opal HII list in order to expose Opal managmeent options.\r
2840\r
2841 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.\r
2842 @param[in] ControllerHandle The Handle of the controller to start. This Handle\r
2843 must support a protocol interface that supplies\r
2844 an I/O abstraction to the driver.\r
2845 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This\r
2846 parameter is ignored by device drivers, and is optional for bus\r
2847 drivers. For a bus driver, if this parameter is NULL, then handles\r
2848 for all the children of Controller are created by this driver.\r
2849 If this parameter is not NULL and the first Device Path Node is\r
2850 not the End of Device Path Node, then only the Handle for the\r
2851 child device specified by the first Device Path Node of\r
2852 RemainingDevicePath is created by this driver.\r
2853 If the first Device Path Node of RemainingDevicePath is\r
2854 the End of Device Path Node, no child Handle is created by this\r
2855 driver.\r
2856\r
2857 @retval EFI_SUCCESS Opal management was enabled.\r
2858 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.\r
2859 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.\r
2860 @retval Others The driver failed to start the device.\r
2861\r
2862**/\r
2863EFI_STATUS\r
2864EFIAPI\r
2865OpalEfiDriverBindingStart(\r
2866 IN EFI_DRIVER_BINDING_PROTOCOL* This,\r
2867 IN EFI_HANDLE Controller,\r
2868 IN EFI_DEVICE_PATH_PROTOCOL* RemainingDevicePath\r
2869 )\r
2870{\r
2871 EFI_STATUS Status;\r
2872 EFI_BLOCK_IO_PROTOCOL *BlkIo;\r
2873 OPAL_DRIVER_DEVICE *Dev;\r
2874 OPAL_DRIVER_DEVICE *Itr;\r
2875 BOOLEAN Result;\r
2876\r
2877 Itr = mOpalDriver.DeviceList;\r
2878 while (Itr != NULL) {\r
2879 if (Controller == Itr->Handle) {\r
2880 return EFI_SUCCESS;\r
2881 }\r
2882 Itr = Itr->Next;\r
2883 }\r
2884\r
2885 //\r
2886 // Create internal device for tracking. This allows all disks to be tracked\r
2887 // by same HII form\r
2888 //\r
2889 Dev = (OPAL_DRIVER_DEVICE*)AllocateZeroPool(sizeof(OPAL_DRIVER_DEVICE));\r
2890 if (Dev == NULL) {\r
2891 return EFI_OUT_OF_RESOURCES;\r
2892 }\r
2893 Dev->Handle = Controller;\r
2894\r
2895 //\r
2896 // Open EFI_STORAGE_SECURITY_COMMAND_PROTOCOL to perform Opal supported checks\r
2897 //\r
2898 Status = gBS->OpenProtocol(\r
2899 Controller,\r
2900 &gEfiStorageSecurityCommandProtocolGuid,\r
2901 (VOID **)&Dev->Sscp,\r
2902 This->DriverBindingHandle,\r
2903 Controller,\r
2904 EFI_OPEN_PROTOCOL_BY_DRIVER\r
2905 );\r
2906 if (EFI_ERROR(Status)) {\r
2907 FreePool(Dev);\r
2908 return Status;\r
2909 }\r
2910\r
2911 //\r
2912 // Open EFI_BLOCK_IO_PROTOCOL on controller Handle, required by EFI_STORAGE_SECURITY_COMMAND_PROTOCOL\r
2913 // function APIs\r
2914 //\r
2915 Status = gBS->OpenProtocol(\r
2916 Controller,\r
2917 &gEfiBlockIoProtocolGuid,\r
2918 (VOID **)&BlkIo,\r
2919 This->DriverBindingHandle,\r
2920 Controller,\r
2921 EFI_OPEN_PROTOCOL_BY_DRIVER\r
2922 );\r
2923 if (EFI_ERROR(Status)) {\r
2924 //\r
2925 // Close storage security that was opened\r
2926 //\r
2927 gBS->CloseProtocol(\r
2928 Controller,\r
2929 &gEfiStorageSecurityCommandProtocolGuid,\r
2930 This->DriverBindingHandle,\r
2931 Controller\r
2932 );\r
2933\r
2934 FreePool(Dev);\r
2935 return Status;\r
2936 }\r
2937\r
2938 //\r
2939 // Save mediaId\r
2940 //\r
2941 Dev->MediaId = BlkIo->Media->MediaId;\r
2942\r
2943 gBS->CloseProtocol(\r
2944 Controller,\r
2945 &gEfiBlockIoProtocolGuid,\r
2946 This->DriverBindingHandle,\r
2947 Controller\r
2948 );\r
2949\r
2950 //\r
2951 // Acquire Ascii printable name of child, if not found, then ignore device\r
2952 //\r
2953 Result = OpalDriverGetDriverDeviceName (Dev);\r
2954 if (!Result) {\r
2955 goto Done;\r
2956 }\r
2957\r
2958 Status = OpalDiskInitialize (Dev);\r
2959 if (EFI_ERROR (Status)) {\r
2960 goto Done;\r
2961 }\r
2962\r
2963 AddDeviceToTail(Dev);\r
2964\r
2965 //\r
2966 // Check if device is locked and prompt for password.\r
2967 //\r
2968 OpalDriverRequestPassword (Dev, L"Unlock:");\r
2969\r
2970 //\r
2971 // Process OPAL request from last boot.\r
2972 //\r
2973 ProcessOpalRequest (Dev);\r
2974\r
2975 return EFI_SUCCESS;\r
2976\r
2977Done:\r
2978 //\r
2979 // free device, close protocols and exit\r
2980 //\r
2981 gBS->CloseProtocol(\r
2982 Controller,\r
2983 &gEfiStorageSecurityCommandProtocolGuid,\r
2984 This->DriverBindingHandle,\r
2985 Controller\r
2986 );\r
2987\r
2988 FreePool(Dev);\r
2989\r
2990 return EFI_DEVICE_ERROR;\r
2991}\r
2992\r
2993/**\r
2994 Stop this driver on Controller.\r
2995\r
2996 @param This Protocol instance pointer.\r
2997 @param Controller Handle of device to stop driver on\r
2998 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of\r
2999 children is zero stop the entire bus driver.\r
3000 @param ChildHandleBuffer List of Child Handles to Stop.\r
3001\r
3002 @retval EFI_SUCCESS This driver is removed Controller.\r
3003 @retval other This driver could not be removed from this device.\r
3004\r
3005**/\r
3006EFI_STATUS\r
3007EFIAPI\r
3008OpalEfiDriverBindingStop(\r
3009 EFI_DRIVER_BINDING_PROTOCOL* This,\r
3010 EFI_HANDLE Controller,\r
3011 UINTN NumberOfChildren,\r
3012 EFI_HANDLE* ChildHandleBuffer\r
3013 )\r
3014{\r
3015 OPAL_DRIVER_DEVICE* Itr;\r
3016\r
3017 Itr = mOpalDriver.DeviceList;\r
3018\r
3019 //\r
3020 // does Controller match any of the devices we are managing for Opal\r
3021 //\r
3022 while (Itr != NULL) {\r
3023 if (Itr->Handle == Controller) {\r
3024 OpalDriverStopDevice (Itr);\r
3025 return EFI_SUCCESS;\r
3026 }\r
3027\r
3028 Itr = Itr->Next;\r
3029 }\r
3030\r
3031 return EFI_NOT_FOUND;\r
3032}\r
3033\r
3034\r
3035/**\r
3036 Unloads UEFI Driver. Very useful for debugging and testing.\r
3037\r
3038 @param ImageHandle Image Handle this driver.\r
3039\r
3040 @retval EFI_SUCCESS This function always complete successfully.\r
3041 @retval EFI_INVALID_PARAMETER The input ImageHandle is not valid.\r
3042**/\r
3043EFI_STATUS\r
3044EFIAPI\r
3045OpalEfiDriverUnload (\r
3046 IN EFI_HANDLE ImageHandle\r
3047 )\r
3048{\r
3049 EFI_STATUS Status;\r
3050 OPAL_DRIVER_DEVICE *Itr;\r
3051\r
3052 Status = EFI_SUCCESS;\r
3053\r
3054 if (ImageHandle != gImageHandle) {\r
3055 return (EFI_INVALID_PARAMETER);\r
3056 }\r
3057\r
3058 //\r
3059 // Uninstall any interface added to each device by us\r
3060 //\r
3061 while (mOpalDriver.DeviceList) {\r
3062 Itr = mOpalDriver.DeviceList;\r
3063 //\r
3064 // Remove OPAL_DRIVER_DEVICE from the list\r
3065 // it updates the controllerList pointer\r
3066 //\r
3067 OpalDriverStopDevice(Itr);\r
3068 }\r
3069\r
3070 //\r
3071 // Uninstall the HII capability\r
3072 //\r
3073 Status = HiiUninstall();\r
3074\r
3075 return Status;\r
3076}\r
3077\r