2 Values defined and used by the Opal UEFI Driver.
4 Copyright (c) 2016 - 2018, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #ifndef _OPAL_DRIVER_H_
16 #define _OPAL_DRIVER_H_
20 #include <IndustryStandard/Pci.h>
22 #include <Protocol/PciIo.h>
23 #include <Protocol/SmmCommunication.h>
24 #include <Protocol/BlockIo.h>
25 #include <Protocol/LoadedImage.h>
26 #include <Protocol/DevicePath.h>
27 #include <Protocol/DevicePathToText.h>
28 #include <Protocol/StorageSecurityCommand.h>
30 #include <Guid/EventGroup.h>
32 #include <Library/UefiLib.h>
33 #include <Library/UefiBootServicesTableLib.h>
34 #include <Library/UefiRuntimeServicesTableLib.h>
35 #include <Library/DxeServicesTableLib.h>
36 #include <Library/BaseMemoryLib.h>
37 #include <Library/MemoryAllocationLib.h>
38 #include <Library/BaseLib.h>
39 #include <Library/PrintLib.h>
40 #include <Library/DebugLib.h>
41 #include <Library/DevicePathLib.h>
42 #include <Library/HiiLib.h>
43 #include <Library/UefiHiiServicesLib.h>
44 #include <Library/PciLib.h>
45 #include <Library/S3BootScriptLib.h>
46 #include <Library/LockBoxLib.h>
47 #include <Library/TcgStorageOpalLib.h>
48 #include <Library/Tcg2PhysicalPresenceLib.h>
50 #include "OpalPasswordCommon.h"
51 #include "OpalHiiFormValues.h"
53 #define EFI_DRIVER_NAME_UNICODE L"1.0 UEFI Opal Driver"
56 #define LANGUAGE_RFC_3066_ENGLISH ((CHAR8*)"en")
59 #define LANGUAGE_ISO_639_2_ENGLISH ((CHAR8*)"eng")
61 #define CONCAT_(x, y) x ## y
62 #define CONCAT(x, y) CONCAT_(x, y)
64 #define UNICODE_STR(x) CONCAT( L, x )
66 extern EFI_DRIVER_BINDING_PROTOCOL gOpalDriverBinding
;
67 extern EFI_COMPONENT_NAME_PROTOCOL gOpalComponentName
;
68 extern EFI_COMPONENT_NAME2_PROTOCOL gOpalComponentName2
;
70 #define OPAL_MSID_LENGHT 128
72 #define MAX_PASSWORD_TRY_COUNT 5
75 #define PSID_CHARACTER_LENGTH 0x20
76 #define MAX_PSID_TRY_COUNT 5
81 // Structure that is used to represent the available actions for an OpalDisk.
82 // The data can then be utilized to expose/hide certain actions available to an end user
83 // by the consumer of this library.
87 // Indicates if the disk can support PSID Revert action. should verify disk supports PSID authority
89 UINT16 PsidRevert
: 1;
92 // Indicates if the disk can support Revert action
97 // Indicates if the user must keep data for revert action. It is true if no media encryption is supported.
99 UINT16 RevertKeepDataForced
: 1;
102 // Indicates if the disk can support set Admin password
104 UINT16 AdminPass
: 1;
107 // Indicates if the disk can support set User password. This action requires that a user
108 // password is first enabled.
113 // Indicates if unlock action is available. Requires disk to be currently locked.
118 // Indicates if Secure Erase action is available. Action requires admin credentials and media encryption support.
120 UINT16 SecureErase
: 1;
123 // Indicates if Disable User action is available. Action requires admin credentials.
125 UINT16 DisableUser
: 1;
129 // Structure that is used to represent an OPAL_DISK.
132 UINT32 MsidLength
; // Byte length of MSID Pin for device
133 UINT8 Msid
[OPAL_MSID_LENGHT
]; // MSID Pin for device
134 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*Sscp
;
135 UINT32 MediaId
; // MediaId is used by Ssc Protocol.
136 EFI_DEVICE_PATH_PROTOCOL
*OpalDevicePath
;
137 UINT16 OpalBaseComId
; // Opal SSC 1 base com id.
138 OPAL_OWNER_SHIP Owner
;
139 OPAL_DISK_SUPPORT_ATTRIBUTE SupportedAttributes
;
140 TCG_LOCKING_FEATURE_DESCRIPTOR LockingFeature
; // Locking Feature Descriptor retrieved from performing a Level 0 Discovery
141 UINT8 PasswordLength
;
142 UINT8 Password
[OPAL_MAX_PASSWORD_SIZE
];
146 // Device with block IO protocol
148 typedef struct _OPAL_DRIVER_DEVICE OPAL_DRIVER_DEVICE
;
150 struct _OPAL_DRIVER_DEVICE
{
151 OPAL_DRIVER_DEVICE
*Next
; ///< Linked list pointer
152 EFI_HANDLE Handle
; ///< Device handle
153 OPAL_DISK OpalDisk
; ///< User context
154 CHAR16
*Name16
; ///< Allocated/freed by UEFI Filter Driver at device creation/removal
155 CHAR8
*NameZ
; ///< Allocated/freed by UEFI Filter Driver at device creation/removal
156 UINT32 MediaId
; ///< Required parameter for EFI_STORAGE_SECURITY_COMMAND_PROTOCOL, from BLOCK_IO_MEDIA
158 EFI_STORAGE_SECURITY_COMMAND_PROTOCOL
*Sscp
; /// Device protocols consumed
159 EFI_DEVICE_PATH_PROTOCOL
*OpalDevicePath
;
163 // Opal Driver UEFI Driver Model
166 EFI_HANDLE Handle
; ///< Driver image handle
167 OPAL_DRIVER_DEVICE
*DeviceList
; ///< Linked list of controllers owned by this Driver
173 // Retrieves a OPAL_DRIVER_DEVICE based on the pointer to its StorageSecurity protocol.
175 #define DRIVER_DEVICE_FROM_OPALDISK(OpalDiskPointer) (OPAL_DRIVER_DEVICE*)(BASE_CR(OpalDiskPointer, OPAL_DRIVER_DEVICE, OpalDisk))
178 Get devcie list info.
180 @retval return the device list pointer.
183 OpalDriverGetDeviceList(
188 Get devcie name through the component name protocol.
190 @param[in] Dev The device which need to get name.
192 @retval TRUE Find the name for this device.
193 @retval FALSE Not found the name for this device.
196 OpalDriverGetDriverDeviceName(
197 OPAL_DRIVER_DEVICE
*Dev
201 Get current device count.
203 @retval return the current created device count.
212 Update password for the Opal disk.
214 @param[in, out] OpalDisk The disk to update password.
215 @param[in] Password The input password.
216 @param[in] PasswordLength The input password length.
220 OpalSupportUpdatePassword (
221 IN OUT OPAL_DISK
*OpalDisk
,
223 IN UINT32 PasswordLength
228 The function performs determines the available actions for the OPAL_DISK provided.
230 @param[in] SupportedAttributes The support attribute for the device.
231 @param[in] LockingFeature The locking status for the device.
232 @param[in] OwnerShip The ownership for the device.
233 @param[out] AvalDiskActions Pointer to fill-out with appropriate disk actions.
238 OpalSupportGetAvailableActions(
239 IN OPAL_DISK_SUPPORT_ATTRIBUTE
*SupportedAttributes
,
240 IN TCG_LOCKING_FEATURE_DESCRIPTOR
*LockingFeature
,
242 OUT OPAL_DISK_ACTIONS
*AvalDiskActions
246 Enable Opal Feature for the input device.
248 @param[in] Session The opal session for the opal device.
250 @param[in] MsidLength Msid Length
251 @param[in] Password Admin password
252 @param[in] PassLength Length of password in bytes
257 OpalSupportEnableOpalFeature (
258 IN OPAL_SESSION
*Session
,
260 IN UINT32 MsidLength
,
266 Unloads UEFI Driver. Very useful for debugging and testing.
268 @param ImageHandle Image handle this driver.
270 @retval EFI_SUCCESS This function always complete successfully.
271 @retval EFI_INVALID_PARAMETER The input ImageHandle is not valid.
276 EFI_HANDLE ImageHandle
281 Test to see if this driver supports Controller.
283 @param This Protocol instance pointer.
284 @param ControllerHandle Handle of device to test
285 @param RemainingDevicePath Optional parameter use to pick a specific child
288 @retval EFI_SUCCESS This driver supports this device.
289 @retval EFI_ALREADY_STARTED This driver is already running on this device.
290 @retval other This driver does not support this device.
295 OpalEfiDriverBindingSupported(
296 EFI_DRIVER_BINDING_PROTOCOL
* This
,
297 EFI_HANDLE Controller
,
298 EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath
302 Enables Opal Management on a supported device if available.
304 The start function is designed to be called after the Opal UEFI Driver has confirmed the
305 "controller", which is a child handle, contains the EF_STORAGE_SECURITY_COMMAND protocols.
306 This function will complete the other necessary checks, such as verifying the device supports
307 the correct version of Opal. Upon verification, it will add the device to the
308 Opal HII list in order to expose Opal managmeent options.
310 @param[in] This A pointer to the EFI_DRIVER_BINDING_PROTOCOL instance.
311 @param[in] ControllerHandle The handle of the controller to start. This handle
312 must support a protocol interface that supplies
313 an I/O abstraction to the driver.
314 @param[in] RemainingDevicePath A pointer to the remaining portion of a device path. This
315 parameter is ignored by device drivers, and is optional for bus
316 drivers. For a bus driver, if this parameter is NULL, then handles
317 for all the children of Controller are created by this driver.
318 If this parameter is not NULL and the first Device Path Node is
319 not the End of Device Path Node, then only the handle for the
320 child device specified by the first Device Path Node of
321 RemainingDevicePath is created by this driver.
322 If the first Device Path Node of RemainingDevicePath is
323 the End of Device Path Node, no child handle is created by this
326 @retval EFI_SUCCESS Opal management was enabled.
327 @retval EFI_DEVICE_ERROR The device could not be started due to a device error.Currently not implemented.
328 @retval EFI_OUT_OF_RESOURCES The request could not be completed due to a lack of resources.
329 @retval Others The driver failed to start the device.
334 OpalEfiDriverBindingStart(
335 EFI_DRIVER_BINDING_PROTOCOL
* This
,
336 EFI_HANDLE Controller
,
337 EFI_DEVICE_PATH_PROTOCOL
* RemainingDevicePath
341 Stop this driver on Controller.
343 @param This Protocol instance pointer.
344 @param Controller Handle of device to stop driver on
345 @param NumberOfChildren Number of Handles in ChildHandleBuffer. If number of
346 children is zero stop the entire bus driver.
347 @param ChildHandleBuffer List of Child Handles to Stop.
349 @retval EFI_SUCCESS This driver is removed Controller.
350 @retval other This driver could not be removed from this device.
355 OpalEfiDriverBindingStop(
356 EFI_DRIVER_BINDING_PROTOCOL
* This
,
357 EFI_HANDLE Controller
,
358 UINTN NumberOfChildren
,
359 EFI_HANDLE
* ChildHandleBuffer
363 Retrieves a Unicode string that is the user readable name of the driver.
365 This function retrieves the user readable name of a driver in the form of a
366 Unicode string. If the driver specified by This has a user readable name in
367 the language specified by Language, then a pointer to the driver name is
368 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
369 by This does not support the language specified by Language,
370 then EFI_UNSUPPORTED is returned.
372 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
373 EFI_COMPONENT_NAME_PROTOCOL instance.
375 @param Language[in] A pointer to a Null-terminated ASCII string
376 array indicating the language. This is the
377 language of the driver name that the caller is
378 requesting, and it must match one of the
379 languages specified in SupportedLanguages. The
380 number of languages supported by a driver is up
381 to the driver writer. Language is specified
382 in RFC 4646 or ISO 639-2 language code format.
384 @param DriverName[out] A pointer to the Unicode string to return.
385 This Unicode string is the name of the
386 driver specified by This in the language
387 specified by Language.
389 @retval EFI_SUCCESS The Unicode string for the Driver specified by
390 This and the language specified by Language was
391 returned in DriverName.
393 @retval EFI_INVALID_PARAMETER Language is NULL.
395 @retval EFI_INVALID_PARAMETER DriverName is NULL.
397 @retval EFI_UNSUPPORTED The driver specified by This does not support
398 the language specified by Language.
403 OpalEfiDriverComponentNameGetDriverName(
404 EFI_COMPONENT_NAME_PROTOCOL
* This
,
410 Retrieves a Unicode string that is the user readable name of the controller
411 that is being managed by a driver.
413 This function retrieves the user readable name of the controller specified by
414 ControllerHandle and ChildHandle in the form of a Unicode string. If the
415 driver specified by This has a user readable name in the language specified by
416 Language, then a pointer to the controller name is returned in ControllerName,
417 and EFI_SUCCESS is returned. If the driver specified by This is not currently
418 managing the controller specified by ControllerHandle and ChildHandle,
419 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
420 support the language specified by Language, then EFI_UNSUPPORTED is returned.
422 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
423 EFI_COMPONENT_NAME_PROTOCOL instance.
425 @param ControllerHandle[in] The handle of a controller that the driver
426 specified by This is managing. This handle
427 specifies the controller whose name is to be
430 @param ChildHandle[in] The handle of the child controller to retrieve
431 the name of. This is an optional parameter that
432 may be NULL. It will be NULL for device
433 drivers. It will also be NULL for a bus drivers
434 that wish to retrieve the name of the bus
435 controller. It will not be NULL for a bus
436 driver that wishes to retrieve the name of a
439 @param Language[in] A pointer to a Null-terminated ASCII string
440 array indicating the language. This is the
441 language of the driver name that the caller is
442 requesting, and it must match one of the
443 languages specified in SupportedLanguages. The
444 number of languages supported by a driver is up
445 to the driver writer. Language is specified in
446 RFC 4646 or ISO 639-2 language code format.
448 @param ControllerName[out] A pointer to the Unicode string to return.
449 This Unicode string is the name of the
450 controller specified by ControllerHandle and
451 ChildHandle in the language specified by
452 Language from the point of view of the driver
455 @retval EFI_SUCCESS The Unicode string for the user readable name in
456 the language specified by Language for the
457 driver specified by This was returned in
460 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
462 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
465 @retval EFI_INVALID_PARAMETER Language is NULL.
467 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
469 @retval EFI_UNSUPPORTED The driver specified by This is not currently
470 managing the controller specified by
471 ControllerHandle and ChildHandle.
473 @retval EFI_UNSUPPORTED The driver specified by This does not support
474 the language specified by Language.
479 OpalEfiDriverComponentNameGetControllerName(
480 EFI_COMPONENT_NAME_PROTOCOL
* This
,
481 EFI_HANDLE ControllerHandle
,
482 EFI_HANDLE ChildHandle
,
484 CHAR16
** ControllerName
488 Retrieves a Unicode string that is the user readable name of the driver.
490 This function retrieves the user readable name of a driver in the form of a
491 Unicode string. If the driver specified by This has a user readable name in
492 the language specified by Language, then a pointer to the driver name is
493 returned in DriverName, and EFI_SUCCESS is returned. If the driver specified
494 by This does not support the language specified by Language,
495 then EFI_UNSUPPORTED is returned.
497 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
498 EFI_COMPONENT_NAME_PROTOCOL instance.
500 @param Language[in] A pointer to a Null-terminated ASCII string
501 array indicating the language. This is the
502 language of the driver name that the caller is
503 requesting, and it must match one of the
504 languages specified in SupportedLanguages. The
505 number of languages supported by a driver is up
506 to the driver writer. Language is specified
507 in RFC 4646 or ISO 639-2 language code format.
509 @param DriverName[out] A pointer to the Unicode string to return.
510 This Unicode string is the name of the
511 driver specified by This in the language
512 specified by Language.
514 @retval EFI_SUCCESS The Unicode string for the Driver specified by
515 This and the language specified by Language was
516 returned in DriverName.
518 @retval EFI_INVALID_PARAMETER Language is NULL.
520 @retval EFI_INVALID_PARAMETER DriverName is NULL.
522 @retval EFI_UNSUPPORTED The driver specified by This does not support
523 the language specified by Language.
528 OpalEfiDriverComponentName2GetDriverName(
529 EFI_COMPONENT_NAME2_PROTOCOL
* This
,
535 Retrieves a Unicode string that is the user readable name of the controller
536 that is being managed by a driver.
538 This function retrieves the user readable name of the controller specified by
539 ControllerHandle and ChildHandle in the form of a Unicode string. If the
540 driver specified by This has a user readable name in the language specified by
541 Language, then a pointer to the controller name is returned in ControllerName,
542 and EFI_SUCCESS is returned. If the driver specified by This is not currently
543 managing the controller specified by ControllerHandle and ChildHandle,
544 then EFI_UNSUPPORTED is returned. If the driver specified by This does not
545 support the language specified by Language, then EFI_UNSUPPORTED is returned.
547 @param This[in] A pointer to the EFI_COMPONENT_NAME2_PROTOCOL or
548 EFI_COMPONENT_NAME_PROTOCOL instance.
550 @param ControllerHandle[in] The handle of a controller that the driver
551 specified by This is managing. This handle
552 specifies the controller whose name is to be
555 @param ChildHandle[in] The handle of the child controller to retrieve
556 the name of. This is an optional parameter that
557 may be NULL. It will be NULL for device
558 drivers. It will also be NULL for a bus drivers
559 that wish to retrieve the name of the bus
560 controller. It will not be NULL for a bus
561 driver that wishes to retrieve the name of a
564 @param Language[in] A pointer to a Null-terminated ASCII string
565 array indicating the language. This is the
566 language of the driver name that the caller is
567 requesting, and it must match one of the
568 languages specified in SupportedLanguages. The
569 number of languages supported by a driver is up
570 to the driver writer. Language is specified in
571 RFC 4646 or ISO 639-2 language code format.
573 @param ControllerName[out] A pointer to the Unicode string to return.
574 This Unicode string is the name of the
575 controller specified by ControllerHandle and
576 ChildHandle in the language specified by
577 Language from the point of view of the driver
580 @retval EFI_SUCCESS The Unicode string for the user readable name in
581 the language specified by Language for the
582 driver specified by This was returned in
585 @retval EFI_INVALID_PARAMETER ControllerHandle is NULL.
587 @retval EFI_INVALID_PARAMETER ChildHandle is not NULL and it is not a valid
590 @retval EFI_INVALID_PARAMETER Language is NULL.
592 @retval EFI_INVALID_PARAMETER ControllerName is NULL.
594 @retval EFI_UNSUPPORTED The driver specified by This is not currently
595 managing the controller specified by
596 ControllerHandle and ChildHandle.
598 @retval EFI_UNSUPPORTED The driver specified by This does not support
599 the language specified by Language.
604 OpalEfiDriverComponentName2GetControllerName(
605 EFI_COMPONENT_NAME2_PROTOCOL
* This
,
606 EFI_HANDLE ControllerHandle
,
607 EFI_HANDLE ChildHandle
,
609 CHAR16
** ControllerName
612 #endif //_OPAL_DRIVER_H_