2 Values defined and used by the Opal UEFI Driver.
4 Copyright (c) 2016 - 2019, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #ifndef _OPAL_DRIVER_H_
10 #define _OPAL_DRIVER_H_
14 #include <IndustryStandard/Pci.h>
16 #include <Protocol/PciIo.h>
17 #include <Protocol/SmmCommunication.h>
18 #include <Protocol/BlockIo.h>
19 #include <Protocol/LoadedImage.h>
20 #include <Protocol/DevicePath.h>
21 #include <Protocol/DevicePathToText.h>
22 #include <Protocol/StorageSecurityCommand.h>
24 #include <Guid/EventGroup.h>
25 #include <Guid/S3StorageDeviceInitList.h>
27 #include <Library/UefiLib.h>
28 #include <Library/UefiBootServicesTableLib.h>
29 #include <Library/UefiRuntimeServicesTableLib.h>
30 #include <Library/DxeServicesTableLib.h>
31 #include <Library/BaseMemoryLib.h>
32 #include <Library/MemoryAllocationLib.h>
33 #include <Library/BaseLib.h>
34 #include <Library/PrintLib.h>
35 #include <Library/DebugLib.h>
36 #include <Library/DevicePathLib.h>
37 #include <Library/HiiLib.h>
38 #include <Library/UefiHiiServicesLib.h>
39 #include <Library/PciLib.h>
40 #include <Library/LockBoxLib.h>
41 #include <Library/TcgStorageOpalLib.h>
42 #include <Library/Tcg2PhysicalPresenceLib.h>
44 #include "OpalPasswordCommon.h"
45 #include "OpalHiiFormValues.h"
47 #define EFI_DRIVER_NAME_UNICODE L"1.0 UEFI Opal Driver"
50 #define LANGUAGE_RFC_3066_ENGLISH ((CHAR8*)"en")
53 #define LANGUAGE_ISO_639_2_ENGLISH ((CHAR8*)"eng")
55 #define CONCAT_(x, y) x ## y
56 #define CONCAT(x, y) CONCAT_(x, y)
58 #define UNICODE_STR(x) CONCAT( L, x )
60 extern EFI_DRIVER_BINDING_PROTOCOL gOpalDriverBinding
;
61 extern EFI_COMPONENT_NAME_PROTOCOL gOpalComponentName
;
62 extern EFI_COMPONENT_NAME2_PROTOCOL gOpalComponentName2
;
64 #define OPAL_MSID_LENGHT 128
66 #define MAX_PASSWORD_TRY_COUNT 5
69 #define PSID_CHARACTER_LENGTH 0x20
70 #define MAX_PSID_TRY_COUNT 5
73 // The max timeout value assume the user can wait for the revert action. The unit of this macro is second.
74 // If the revert time value bigger than this one, driver needs to popup a dialog to let user confirm the
77 #define MAX_ACCEPTABLE_REVERTING_TIME 10
82 // Structure that is used to represent the available actions for an OpalDisk.
83 // The data can then be utilized to expose/hide certain actions available to an end user
84 // by the consumer of this library.
88 // Indicates if the disk can support PSID Revert action. should verify disk supports PSID authority
90 UINT16 PsidRevert
: 1;
93 // Indicates if the disk can support Revert action
98 // Indicates if the user must keep data for revert action. It is true if no media encryption is supported.
100 UINT16 RevertKeepDataForced
: 1;
103 // Indicates if the disk can support set Admin password
105 UINT16 AdminPass
: 1;
108 // Indicates if the disk can support set User password. This action requires that a user
109 // password is first enabled.
114 // Indicates if unlock action is available. Requires disk to be currently locked.
119 // Indicates if Secure Erase action is available. Action requires admin credentials and media encryption support.
121 UINT16 SecureErase
: 1;
124 // Indicates if Disable User action is available. Action requires admin credentials.
126 UINT16 DisableUser
: 1;
130 // Structure that is used to represent an OPAL_DISK.
133 UINT32 MsidLength
; // Byte length of MSID Pin for device
134 UINT8 Msid
[OPAL_MSID_LENGHT
]; // MSID Pin for device
135 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*Sscp
;
136 UINT32 MediaId
; // MediaId is used by Ssc Protocol.
137 EFI_DEVICE_PATH_PROTOCOL
*OpalDevicePath
;
138 UINT16 OpalBaseComId
; // Opal SSC 1 base com id.
139 OPAL_OWNER_SHIP Owner
;
140 OPAL_DISK_SUPPORT_ATTRIBUTE SupportedAttributes
;
141 TCG_LOCKING_FEATURE_DESCRIPTOR LockingFeature
; // Locking Feature Descriptor retrieved from performing a Level 0 Discovery
142 UINT8 PasswordLength
;
143 UINT8 Password
[OPAL_MAX_PASSWORD_SIZE
];
145 UINT32 EstimateTimeCost
;
146 BOOLEAN SentBlockSID
; // Check whether BlockSid command has been sent.
150 // Device with block IO protocol
152 typedef struct _OPAL_DRIVER_DEVICE OPAL_DRIVER_DEVICE
;
154 struct _OPAL_DRIVER_DEVICE
{
155 OPAL_DRIVER_DEVICE
*Next
; ///< Linked list pointer
156 EFI_HANDLE Handle
; ///< Device handle
157 OPAL_DISK OpalDisk
; ///< User context
158 CHAR16
*Name16
; ///< Allocated/freed by UEFI Filter Driver at device creation/removal
159 CHAR8
*NameZ
; ///< Allocated/freed by UEFI Filter Driver at device creation/removal
160 UINT32 MediaId
; ///< Required parameter for EFI_STORAGE_SECURITY_COMMAND_PROTOCOL, from BLOCK_IO_MEDIA
162 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*Sscp
; /// Device protocols consumed
163 EFI_DEVICE_PATH_PROTOCOL
*OpalDevicePath
;
167 // Opal Driver UEFI Driver Model
170 EFI_HANDLE Handle
; ///< Driver image handle
171 OPAL_DRIVER_DEVICE
*DeviceList
; ///< Linked list of controllers owned by this Driver
177 // Retrieves a OPAL_DRIVER_DEVICE based on the pointer to its StorageSecurity protocol.
179 #define DRIVER_DEVICE_FROM_OPALDISK(OpalDiskPointer) (OPAL_DRIVER_DEVICE*)(BASE_CR(OpalDiskPointer, OPAL_DRIVER_DEVICE, OpalDisk))
182 Get devcie list info.
184 @retval return the device list pointer.
187 OpalDriverGetDeviceList(
192 Get devcie name through the component name protocol.
194 @param[in] Dev The device which need to get name.
196 @retval TRUE Find the name for this device.
197 @retval FALSE Not found the name for this device.
200 OpalDriverGetDriverDeviceName(
201 OPAL_DRIVER_DEVICE
*Dev
205 Get current device count.
207 @retval return the current created device count.
216 Update password for the Opal disk.
218 @param[in, out] OpalDisk The disk to update password.
219 @param[in] Password The input password.
220 @param[in] PasswordLength The input password length.
224 OpalSupportUpdatePassword (
225 IN OUT OPAL_DISK
*OpalDisk
,
227 IN UINT32 PasswordLength
232 The function performs determines the available actions for the OPAL_DISK provided.
234 @param[in] SupportedAttributes The support attribute for the device.
235 @param[in] LockingFeature The locking status for the device.
236 @param[in] OwnerShip The ownership for the device.
237 @param[out] AvalDiskActions Pointer to fill-out with appropriate disk actions.
242 OpalSupportGetAvailableActions(
243 IN OPAL_DISK_SUPPORT_ATTRIBUTE
*SupportedAttributes
,
244 IN TCG_LOCKING_FEATURE_DESCRIPTOR
*LockingFeature
,
246 OUT OPAL_DISK_ACTIONS
*AvalDiskActions
250 Enable Opal Feature for the input device.
252 @param[in] Session The opal session for the opal device.
254 @param[in] MsidLength Msid Length
255 @param[in] Password Admin password
256 @param[in] PassLength Length of password in bytes
261 OpalSupportEnableOpalFeature (
262 IN OPAL_SESSION
*Session
,
264 IN UINT32 MsidLength
,
270 Unloads UEFI Driver. Very useful for debugging and testing.
272 @param ImageHandle Image handle this driver.
274 @retval EFI_SUCCESS This function always complete successfully.
275 @retval EFI_INVALID_PARAMETER The input ImageHandle is not valid.
280 EFI_HANDLE ImageHandle
285 Test to see if this driver supports Controller.
287 @param This Protocol instance pointer.
288 @param ControllerHandle Handle of device to test
289 @param RemainingDevicePath Optional parameter use to pick a specific child
292 @retval EFI_SUCCESS This driver supports this device.
293 @retval EFI_ALREADY_STARTED This driver is already running on this device.
294 @retval other This driver does not support this device.
299 OpalEfiDriverBindingSupported(
300 EFI_DRIVER_BINDING_PROTOCOL
* This
,
301 EFI_HANDLE Controller
,
302 EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath
306 Enables Opal Management on a supported device if available.
308 The start function is designed to be called after the Opal UEFI Driver has confirmed the
309 "controller", which is a child handle, contains the EF_STORAGE_SECURITY_COMMAND protocols.
310 This function will complete the other necessary checks, such as verifying the device supports
311 the correct version of Opal. Upon verification, it will add the device to the
312 Opal HII list in order to expose Opal managmeent options.
314 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
315 @param[in] ControllerHandle The handle of the controller to start. This handle
316 must support a protocol interface that supplies
317 an I/O abstraction to the driver.
318 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
319 parameter is ignored by device drivers, and is optional for bus
320 drivers. For a bus driver, if this parameter is NULL, then handles
321 for all the children of Controller are created by this driver.
322 If this parameter is not NULL and the first Device Path Node is
323 not the End of Device Path Node, then only the handle for the
324 child device specified by the first Device Path Node of
325 RemainingDevicePath is created by this driver.
326 If the first Device Path Node of RemainingDevicePath is
327 the End of Device Path Node, no child handle is created by this
330 @retval EFI_SUCCESS Opal management was enabled.
331 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
332 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
333 @retval Others The driver failed to start the device.
338 OpalEfiDriverBindingStart(
339 EFI_DRIVER_BINDING_PROTOCOL
* This
,
340 EFI_HANDLE Controller
,
341 EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath
345 Stop this driver on Controller.
347 @param This Protocol instance pointer.
348 @param Controller Handle of device to stop driver on
349 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
350 children is zero stop the entire bus driver.
351 @param ChildHandleBuffer List of Child Handles to Stop.
353 @retval EFI_SUCCESS This driver is removed Controller.
354 @retval other This driver could not be removed from this device.
359 OpalEfiDriverBindingStop(
360 EFI_DRIVER_BINDING_PROTOCOL
* This
,
361 EFI_HANDLE Controller
,
362 UINTN NumberOfChildren
,
363 EFI_HANDLE
* ChildHandleBuffer
367 Retrieves a Unicode string that is the user readable name of the driver.
369 This function retrieves the user readable name of a driver in the form of a
370 Unicode string. If the driver specified by This has a user readable name in
371 the language specified by Language, then a pointer to the driver name is
372 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
373 by This does not support the language specified by Language,
374 then EFI_UNSUPPORTED is returned.
376 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
377 EFI_COMPONENT_NAME_PROTOCOL instance.
379 @param Language[in] A pointer to a Null-terminated ASCII string
380 array indicating the language. This is the
381 language of the driver name that the caller is
382 requesting, and it must match one of the
383 languages specified in SupportedLanguages. The
384 number of languages supported by a driver is up
385 to the driver writer. Language is specified
386 in RFC 4646 or ISO 639-2 language code format.
388 @param DriverName[out] A pointer to the Unicode string to return.
389 This Unicode string is the name of the
390 driver specified by This in the language
391 specified by Language.
393 @retval EFI_SUCCESS The Unicode string for the Driver specified by
394 This and the language specified by Language was
395 returned in DriverName.
397 @retval EFI_INVALID_PARAMETER Language is NULL.
399 @retval EFI_INVALID_PARAMETER DriverName is NULL.
401 @retval EFI_UNSUPPORTED The driver specified by This does not support
402 the language specified by Language.
407 OpalEfiDriverComponentNameGetDriverName(
408 EFI_COMPONENT_NAME_PROTOCOL
* This
,
414 Retrieves a Unicode string that is the user readable name of the controller
415 that is being managed by a driver.
417 This function retrieves the user readable name of the controller specified by
418 ControllerHandle and ChildHandle in the form of a Unicode string. If the
419 driver specified by This has a user readable name in the language specified by
420 Language, then a pointer to the controller name is returned in ControllerName,
421 and EFI_SUCCESS is returned. If the driver specified by This is not currently
422 managing the controller specified by ControllerHandle and ChildHandle,
423 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
424 support the language specified by Language, then EFI_UNSUPPORTED is returned.
426 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
427 EFI_COMPONENT_NAME_PROTOCOL instance.
429 @param ControllerHandle[in] The handle of a controller that the driver
430 specified by This is managing. This handle
431 specifies the controller whose name is to be
434 @param ChildHandle[in] The handle of the child controller to retrieve
435 the name of. This is an optional parameter that
436 may be NULL. It will be NULL for device
437 drivers. It will also be NULL for a bus drivers
438 that wish to retrieve the name of the bus
439 controller. It will not be NULL for a bus
440 driver that wishes to retrieve the name of a
443 @param Language[in] A pointer to a Null-terminated ASCII string
444 array indicating the language. This is the
445 language of the driver name that the caller is
446 requesting, and it must match one of the
447 languages specified in SupportedLanguages. The
448 number of languages supported by a driver is up
449 to the driver writer. Language is specified in
450 RFC 4646 or ISO 639-2 language code format.
452 @param ControllerName[out] A pointer to the Unicode string to return.
453 This Unicode string is the name of the
454 controller specified by ControllerHandle and
455 ChildHandle in the language specified by
456 Language from the point of view of the driver
459 @retval EFI_SUCCESS The Unicode string for the user readable name in
460 the language specified by Language for the
461 driver specified by This was returned in
464 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
466 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
469 @retval EFI_INVALID_PARAMETER Language is NULL.
471 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
473 @retval EFI_UNSUPPORTED The driver specified by This is not currently
474 managing the controller specified by
475 ControllerHandle and ChildHandle.
477 @retval EFI_UNSUPPORTED The driver specified by This does not support
478 the language specified by Language.
483 OpalEfiDriverComponentNameGetControllerName(
484 EFI_COMPONENT_NAME_PROTOCOL
* This
,
485 EFI_HANDLE ControllerHandle
,
486 EFI_HANDLE ChildHandle
,
488 CHAR16
** ControllerName
492 Retrieves a Unicode string that is the user readable name of the driver.
494 This function retrieves the user readable name of a driver in the form of a
495 Unicode string. If the driver specified by This has a user readable name in
496 the language specified by Language, then a pointer to the driver name is
497 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
498 by This does not support the language specified by Language,
499 then EFI_UNSUPPORTED is returned.
501 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
502 EFI_COMPONENT_NAME_PROTOCOL instance.
504 @param Language[in] A pointer to a Null-terminated ASCII string
505 array indicating the language. This is the
506 language of the driver name that the caller is
507 requesting, and it must match one of the
508 languages specified in SupportedLanguages. The
509 number of languages supported by a driver is up
510 to the driver writer. Language is specified
511 in RFC 4646 or ISO 639-2 language code format.
513 @param DriverName[out] A pointer to the Unicode string to return.
514 This Unicode string is the name of the
515 driver specified by This in the language
516 specified by Language.
518 @retval EFI_SUCCESS The Unicode string for the Driver specified by
519 This and the language specified by Language was
520 returned in DriverName.
522 @retval EFI_INVALID_PARAMETER Language is NULL.
524 @retval EFI_INVALID_PARAMETER DriverName is NULL.
526 @retval EFI_UNSUPPORTED The driver specified by This does not support
527 the language specified by Language.
532 OpalEfiDriverComponentName2GetDriverName(
533 EFI_COMPONENT_NAME2_PROTOCOL
* This
,
539 Retrieves a Unicode string that is the user readable name of the controller
540 that is being managed by a driver.
542 This function retrieves the user readable name of the controller specified by
543 ControllerHandle and ChildHandle in the form of a Unicode string. If the
544 driver specified by This has a user readable name in the language specified by
545 Language, then a pointer to the controller name is returned in ControllerName,
546 and EFI_SUCCESS is returned. If the driver specified by This is not currently
547 managing the controller specified by ControllerHandle and ChildHandle,
548 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
549 support the language specified by Language, then EFI_UNSUPPORTED is returned.
551 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
552 EFI_COMPONENT_NAME_PROTOCOL instance.
554 @param ControllerHandle[in] The handle of a controller that the driver
555 specified by This is managing. This handle
556 specifies the controller whose name is to be
559 @param ChildHandle[in] The handle of the child controller to retrieve
560 the name of. This is an optional parameter that
561 may be NULL. It will be NULL for device
562 drivers. It will also be NULL for a bus drivers
563 that wish to retrieve the name of the bus
564 controller. It will not be NULL for a bus
565 driver that wishes to retrieve the name of a
568 @param Language[in] A pointer to a Null-terminated ASCII string
569 array indicating the language. This is the
570 language of the driver name that the caller is
571 requesting, and it must match one of the
572 languages specified in SupportedLanguages. The
573 number of languages supported by a driver is up
574 to the driver writer. Language is specified in
575 RFC 4646 or ISO 639-2 language code format.
577 @param ControllerName[out] A pointer to the Unicode string to return.
578 This Unicode string is the name of the
579 controller specified by ControllerHandle and
580 ChildHandle in the language specified by
581 Language from the point of view of the driver
584 @retval EFI_SUCCESS The Unicode string for the user readable name in
585 the language specified by Language for the
586 driver specified by This was returned in
589 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
591 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
594 @retval EFI_INVALID_PARAMETER Language is NULL.
596 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
598 @retval EFI_UNSUPPORTED The driver specified by This is not currently
599 managing the controller specified by
600 ControllerHandle and ChildHandle.
602 @retval EFI_UNSUPPORTED The driver specified by This does not support
603 the language specified by Language.
608 OpalEfiDriverComponentName2GetControllerName(
609 EFI_COMPONENT_NAME2_PROTOCOL
* This
,
610 EFI_HANDLE ControllerHandle
,
611 EFI_HANDLE ChildHandle
,
613 CHAR16
** ControllerName
616 #endif //_OPAL_DRIVER_H_