/** @file\r
\r
- Copyright (c) 2014 - 2015, Intel Corporation. All rights reserved.<BR>\r
- This program and the accompanying materials\r
- are licensed and made available under the terms and conditions of the BSD License\r
- which accompanies this distribution. The full text of the license may be found at\r
- http://opensource.org/licenses/bsd-license.php\r
-\r
- THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
- WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+ Copyright (c) 2014 - 2018, Intel Corporation. All rights reserved.<BR>\r
+ SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
#include <Uefi.h>\r
\r
#include <Protocol/ScsiPassThruExt.h>\r
+#include <Protocol/UfsDeviceConfig.h>\r
#include <Protocol/UfsHostController.h>\r
\r
#include <Library/DebugLib.h>\r
#define UFS_PASS_THRU_SIG SIGNATURE_32 ('U', 'F', 'S', 'P')\r
\r
//\r
-// Lun 0~7 is for 8 common luns. \r
+// Lun 0~7 is for 8 common luns.\r
// Lun 8~11 is for those 4 well known luns (Refer to UFS 2.0 spec Table 10.58 for details):\r
// Lun 8: REPORT LUNS\r
// Lun 9: UFS DEVICE\r
UINT16 Rsvd:4;\r
} UFS_EXPOSED_LUNS;\r
\r
-typedef struct _UFS_PASS_THRU_PRIVATE_DATA { \r
+//\r
+// Iterate through the double linked list. This is delete-safe.\r
+// Do not touch NextEntry\r
+//\r
+#define EFI_LIST_FOR_EACH_SAFE(Entry, NextEntry, ListHead) \\r
+ for(Entry = (ListHead)->ForwardLink, NextEntry = Entry->ForwardLink;\\r
+ Entry != (ListHead); Entry = NextEntry, NextEntry = Entry->ForwardLink)\r
+\r
+typedef struct _UFS_PASS_THRU_PRIVATE_DATA {\r
UINT32 Signature;\r
EFI_HANDLE Handle;\r
EFI_EXT_SCSI_PASS_THRU_MODE ExtScsiPassThruMode;\r
EFI_EXT_SCSI_PASS_THRU_PROTOCOL ExtScsiPassThru;\r
+ EFI_UFS_DEVICE_CONFIG_PROTOCOL UfsDevConfig;\r
EDKII_UFS_HOST_CONTROLLER_PROTOCOL *UfsHostController;\r
UINTN UfsHcBase;\r
UINT32 Capabilities;\r
VOID *TmrlMapping;\r
\r
UFS_EXPOSED_LUNS Luns;\r
+\r
+ //\r
+ // For Non-blocking operation.\r
+ //\r
+ EFI_EVENT TimerEvent;\r
+ LIST_ENTRY Queue;\r
} UFS_PASS_THRU_PRIVATE_DATA;\r
\r
+#define UFS_PASS_THRU_TRANS_REQ_SIG SIGNATURE_32 ('U', 'F', 'S', 'T')\r
+\r
+typedef struct {\r
+ UINT32 Signature;\r
+ LIST_ENTRY TransferList;\r
+\r
+ UINT8 Slot;\r
+ UTP_TRD *Trd;\r
+ UINT32 CmdDescSize;\r
+ VOID *CmdDescHost;\r
+ VOID *CmdDescMapping;\r
+ VOID *DataBufMapping;\r
+\r
+ EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet;\r
+ UINT64 TimeoutRemain;\r
+ EFI_EVENT CallerEvent;\r
+} UFS_PASS_THRU_TRANS_REQ;\r
+\r
+#define UFS_PASS_THRU_TRANS_REQ_FROM_THIS(a) \\r
+ CR(a, UFS_PASS_THRU_TRANS_REQ, TransferList, UFS_PASS_THRU_TRANS_REQ_SIG)\r
+\r
#define UFS_TIMEOUT EFI_TIMER_PERIOD_SECONDS(3)\r
+#define UFS_HC_ASYNC_TIMER EFI_TIMER_PERIOD_MILLISECONDS(1)\r
\r
#define ROUNDUP8(x) (((x) % 8 == 0) ? (x) : ((x) / 8 + 1) * 8)\r
\r
UFS_PASS_THRU_SIG \\r
)\r
\r
+#define UFS_PASS_THRU_PRIVATE_DATA_FROM_DEV_CONFIG(a) \\r
+ CR (a, \\r
+ UFS_PASS_THRU_PRIVATE_DATA, \\r
+ UfsDevConfig, \\r
+ UFS_PASS_THRU_SIG \\r
+ )\r
+\r
typedef struct _UFS_DEVICE_MANAGEMENT_REQUEST_PACKET {\r
UINT64 Timeout;\r
- VOID *InDataBuffer;\r
- VOID *OutDataBuffer;\r
+ VOID *DataBuffer;\r
UINT8 Opcode;\r
UINT8 DescId;\r
UINT8 Index;\r
UINT8 Selector;\r
- UINT32 InTransferLength;\r
- UINT32 OutTransferLength;\r
+ UINT32 TransferLength;\r
UINT8 DataDirection;\r
- UINT8 Ocs;\r
} UFS_DEVICE_MANAGEMENT_REQUEST_PACKET;\r
\r
//\r
@param[in] Lun The LUN of the UFS device to send the SCSI Request Packet.\r
@param[in, out] Packet A pointer to the SCSI Request Packet to send to a specified Lun of the\r
UFS device.\r
+ @param[in] Event If nonblocking I/O is not supported then Event is ignored, and blocking\r
+ I/O is performed. If Event is NULL, then blocking I/O is performed. If\r
+ Event is not NULL and non blocking I/O is supported, then\r
+ nonblocking I/O is performed, and Event will be signaled when the\r
+ SCSI Request Packet completes.\r
\r
@retval EFI_SUCCESS The SCSI Request Packet was sent by the host. For bi-directional\r
commands, InTransferLength bytes were transferred from\r
UfsExecScsiCmds (\r
IN UFS_PASS_THRU_PRIVATE_DATA *Private,\r
IN UINT8 Lun,\r
- IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet\r
+ IN OUT EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET *Packet,\r
+ IN EFI_EVENT Event OPTIONAL\r
);\r
\r
/**\r
IN UINT8 FlagId\r
);\r
\r
+/**\r
+ Read specified flag from a UFS device.\r
+\r
+ @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.\r
+ @param[in] FlagId The ID of flag to be read.\r
+ @param[out] Value The flag's value.\r
+\r
+ @retval EFI_SUCCESS The flag was read successfully.\r
+ @retval EFI_DEVICE_ERROR A device error occurred while attempting to read the flag.\r
+ @retval EFI_TIMEOUT A timeout occurred while waiting for the completion of reading the flag.\r
+\r
+**/\r
+EFI_STATUS\r
+UfsReadFlag (\r
+ IN UFS_PASS_THRU_PRIVATE_DATA *Private,\r
+ IN UINT8 FlagId,\r
+ OUT UINT8 *Value\r
+ );\r
+\r
+/**\r
+ Read or write specified flag of a UFS device.\r
+\r
+ @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.\r
+ @param[in] Read The boolean variable to show r/w direction.\r
+ @param[in] FlagId The ID of flag to be read or written.\r
+ @param[in, out] Value The value to set or clear flag.\r
+\r
+ @retval EFI_SUCCESS The flag was read/written successfully.\r
+ @retval EFI_DEVICE_ERROR A device error occurred while attempting to r/w the flag.\r
+ @retval EFI_TIMEOUT A timeout occurred while waiting for the completion of r/w the flag.\r
+\r
+**/\r
+EFI_STATUS\r
+UfsRwFlags (\r
+ IN UFS_PASS_THRU_PRIVATE_DATA *Private,\r
+ IN BOOLEAN Read,\r
+ IN UINT8 FlagId,\r
+ IN OUT UINT8 *Value\r
+ );\r
+\r
/**\r
Read or write specified device descriptor of a UFS device.\r
\r
@param[in] Index The Index of device descriptor.\r
@param[in] Selector The Selector of device descriptor.\r
@param[in, out] Descriptor The buffer of device descriptor to be read or written.\r
- @param[in] DescSize The size of device descriptor buffer.\r
+ @param[in, out] DescSize The size of device descriptor buffer. On input, the size, in bytes,\r
+ of the data buffer specified by Descriptor. On output, the number\r
+ of bytes that were actually transferred.\r
\r
@retval EFI_SUCCESS The device descriptor was read/written successfully.\r
@retval EFI_DEVICE_ERROR A device error occurred while attempting to r/w the device descriptor.\r
IN UINT8 Index,\r
IN UINT8 Selector,\r
IN OUT VOID *Descriptor,\r
- IN UINT32 DescSize\r
+ IN OUT UINT32 *DescSize\r
+ );\r
+\r
+/**\r
+ Read or write specified attribute of a UFS device.\r
+\r
+ @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data structure.\r
+ @param[in] Read The boolean variable to show r/w direction.\r
+ @param[in] AttrId The ID of Attribute.\r
+ @param[in] Index The Index of Attribute.\r
+ @param[in] Selector The Selector of Attribute.\r
+ @param[in, out] Attributes The value of Attribute to be read or written.\r
+\r
+ @retval EFI_SUCCESS The Attribute was read/written successfully.\r
+ @retval EFI_DEVICE_ERROR A device error occurred while attempting to r/w the Attribute.\r
+ @retval EFI_TIMEOUT A timeout occurred while waiting for the completion of r/w the Attribute.\r
+\r
+**/\r
+EFI_STATUS\r
+UfsRwAttributes (\r
+ IN UFS_PASS_THRU_PRIVATE_DATA *Private,\r
+ IN BOOLEAN Read,\r
+ IN UINT8 AttrId,\r
+ IN UINT8 Index,\r
+ IN UINT8 Selector,\r
+ IN OUT UINT32 *Attributes\r
);\r
\r
/**\r
IN UFS_PASS_THRU_PRIVATE_DATA *Private\r
);\r
\r
-extern GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME_PROTOCOL gUfsPassThruComponentName;\r
-extern GLOBAL_REMOVE_IF_UNREFERENCED EFI_COMPONENT_NAME2_PROTOCOL gUfsPassThruComponentName2;\r
-extern EFI_DRIVER_BINDING_PROTOCOL gUfsPassThruDriverBinding;\r
+/**\r
+ Call back function when the timer event is signaled.\r
+\r
+ @param[in] Event The Event this notify function registered to.\r
+ @param[in] Context Pointer to the context data registered to the Event.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+ProcessAsyncTaskList (\r
+ IN EFI_EVENT Event,\r
+ IN VOID *Context\r
+ );\r
+\r
+/**\r
+ Internal helper function which will signal the caller event and clean up\r
+ resources.\r
+\r
+ @param[in] Private The pointer to the UFS_PASS_THRU_PRIVATE_DATA data\r
+ structure.\r
+ @param[in] TransReq The pointer to the UFS_PASS_THRU_TRANS_REQ data\r
+ structure.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+SignalCallerEvent (\r
+ IN UFS_PASS_THRU_PRIVATE_DATA *Private,\r
+ IN UFS_PASS_THRU_TRANS_REQ *TransReq\r
+ );\r
+\r
+/**\r
+ Read or write specified device descriptor of a UFS device.\r
+\r
+ The function is used to read/write UFS device descriptors. The consumer of this API is\r
+ responsible for allocating the data buffer pointed by Descriptor.\r
+\r
+ @param[in] This The pointer to the EFI_UFS_DEVICE_CONFIG_PROTOCOL instance.\r
+ @param[in] Read The boolean variable to show r/w direction.\r
+ @param[in] DescId The ID of device descriptor.\r
+ @param[in] Index The Index of device descriptor.\r
+ @param[in] Selector The Selector of device descriptor.\r
+ @param[in, out] Descriptor The buffer of device descriptor to be read or written.\r
+ @param[in, out] DescSize The size of device descriptor buffer. On input, the size, in bytes,\r
+ of the data buffer specified by Descriptor. On output, the number\r
+ of bytes that were actually transferred.\r
+\r
+ @retval EFI_SUCCESS The device descriptor is read/written successfully.\r
+ @retval EFI_INVALID_PARAMETER This is NULL or Descriptor is NULL or DescSize is NULL.\r
+ DescId, Index and Selector are invalid combination to point to a\r
+ type of UFS device descriptor.\r
+ @retval EFI_DEVICE_ERROR The device descriptor is not read/written successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+UfsRwUfsDescriptor (\r
+ IN EFI_UFS_DEVICE_CONFIG_PROTOCOL *This,\r
+ IN BOOLEAN Read,\r
+ IN UINT8 DescId,\r
+ IN UINT8 Index,\r
+ IN UINT8 Selector,\r
+ IN OUT UINT8 *Descriptor,\r
+ IN OUT UINT32 *DescSize\r
+ );\r
+\r
+/**\r
+ Read or write specified flag of a UFS device.\r
+\r
+ The function is used to read/write UFS flag descriptors. The consumer of this API is responsible\r
+ for allocating the buffer pointed by Flag. The buffer size is 1 byte as UFS flag descriptor is\r
+ just a single Boolean value that represents a TRUE or FALSE, '0' or '1', ON or OFF type of value.\r
+\r
+ @param[in] This The pointer to the EFI_UFS_DEVICE_CONFIG_PROTOCOL instance.\r
+ @param[in] Read The boolean variable to show r/w direction.\r
+ @param[in] FlagId The ID of flag to be read or written.\r
+ @param[in, out] Flag The buffer to set or clear flag.\r
+\r
+ @retval EFI_SUCCESS The flag descriptor is set/clear successfully.\r
+ @retval EFI_INVALID_PARAMETER This is NULL or Flag is NULL.\r
+ FlagId is an invalid UFS flag ID.\r
+ @retval EFI_DEVICE_ERROR The flag is not set/clear successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+UfsRwUfsFlag (\r
+ IN EFI_UFS_DEVICE_CONFIG_PROTOCOL *This,\r
+ IN BOOLEAN Read,\r
+ IN UINT8 FlagId,\r
+ IN OUT UINT8 *Flag\r
+ );\r
+\r
+/**\r
+ Read or write specified attribute of a UFS device.\r
+\r
+ The function is used to read/write UFS attributes. The consumer of this API is responsible for\r
+ allocating the data buffer pointed by Attribute.\r
+\r
+ @param[in] This The pointer to the EFI_UFS_DEVICE_CONFIG_PROTOCOL instance.\r
+ @param[in] Read The boolean variable to show r/w direction.\r
+ @param[in] AttrId The ID of Attribute.\r
+ @param[in] Index The Index of Attribute.\r
+ @param[in] Selector The Selector of Attribute.\r
+ @param[in, out] Attribute The buffer of Attribute to be read or written.\r
+ @param[in, out] AttrSize The size of Attribute buffer. On input, the size, in bytes, of the\r
+ data buffer specified by Attribute. On output, the number of bytes\r
+ that were actually transferred.\r
+\r
+ @retval EFI_SUCCESS The attribute is read/written successfully.\r
+ @retval EFI_INVALID_PARAMETER This is NULL or Attribute is NULL or AttrSize is NULL.\r
+ AttrId, Index and Selector are invalid combination to point to a\r
+ type of UFS attribute.\r
+ @retval EFI_DEVICE_ERROR The attribute is not read/written successfully.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+UfsRwUfsAttribute (\r
+ IN EFI_UFS_DEVICE_CONFIG_PROTOCOL *This,\r
+ IN BOOLEAN Read,\r
+ IN UINT8 AttrId,\r
+ IN UINT8 Index,\r
+ IN UINT8 Selector,\r
+ IN OUT UINT8 *Attribute,\r
+ IN OUT UINT32 *AttrSize\r
+ );\r
+\r
+extern EFI_COMPONENT_NAME_PROTOCOL gUfsPassThruComponentName;\r
+extern EFI_COMPONENT_NAME2_PROTOCOL gUfsPassThruComponentName2;\r
+extern EFI_DRIVER_BINDING_PROTOCOL gUfsPassThruDriverBinding;\r
\r
#endif\r