/** @file\r
+ Definition of USB Mass Storage Class and its value, USB Mass Transport Protocol,\r
+ and other common definitions.\r
\r
-Copyright (c) 2007, Intel Corporation\r
-All rights reserved. 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
-\r
-Module Name:\r
-\r
- UsbMass.h\r
-\r
-Abstract:\r
-\r
- Defination for the USB mass storage class driver. The USB mass storage\r
- class is specified in two layers: the bottom layer is the transportation\r
- protocol. The top layer is the command set. The transportation layer\r
- provides the transportation of the command, data and result. The command\r
- set defines what the command, data and result. The Bulk-Only-Transport and\r
- Control/Bulk/Interrupt transport are two transportation protocol. USB mass\r
- storage class adopts various industrial standard as its command set.\r
-\r
-Revision History\r
-\r
+Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
\r
#ifndef _EFI_USBMASS_H_\r
#define _EFI_USBMASS_H_\r
\r
-\r
-#include <PiDxe.h>\r
-\r
+#include <Uefi.h>\r
+#include <IndustryStandard/Scsi.h>\r
#include <Protocol/BlockIo.h>\r
#include <Protocol/UsbIo.h>\r
-\r
+#include <Protocol/DevicePath.h>\r
+#include <Protocol/DiskInfo.h>\r
+#include <Library/BaseLib.h>\r
#include <Library/DebugLib.h>\r
#include <Library/BaseMemoryLib.h>\r
#include <Library/UefiDriverEntryPoint.h>\r
#include <Library/UefiBootServicesTableLib.h>\r
#include <Library/UefiLib.h>\r
#include <Library/MemoryAllocationLib.h>\r
+#include <Library/DevicePathLib.h>\r
\r
-#define USB_IS_IN_ENDPOINT(EndPointAddr) (((EndPointAddr) & 0x80) == 0x80)\r
-#define USB_IS_OUT_ENDPOINT(EndPointAddr) (((EndPointAddr) & 0x80) == 0)\r
-#define USB_IS_BULK_ENDPOINT(Attribute) (((Attribute) & 0x03) == 0x02)\r
-#define USB_IS_INTERRUPT_ENDPOINT(Attribute) (((Attribute) & 0x03) == 0x03)\r
+typedef struct _USB_MASS_TRANSPORT USB_MASS_TRANSPORT;\r
+typedef struct _USB_MASS_DEVICE USB_MASS_DEVICE;\r
+\r
+#include "UsbMassBot.h"\r
+#include "UsbMassCbi.h"\r
+#include "UsbMassBoot.h"\r
+#include "UsbMassDiskInfo.h"\r
+#include "UsbMassImpl.h"\r
+\r
+#define USB_IS_IN_ENDPOINT(EndPointAddr) (((EndPointAddr) & BIT7) == BIT7)\r
+#define USB_IS_OUT_ENDPOINT(EndPointAddr) (((EndPointAddr) & BIT7) == 0)\r
+#define USB_IS_BULK_ENDPOINT(Attribute) (((Attribute) & (BIT0 | BIT1)) == USB_ENDPOINT_BULK)\r
+#define USB_IS_INTERRUPT_ENDPOINT(Attribute) (((Attribute) & (BIT0 | BIT1)) == USB_ENDPOINT_INTERRUPT)\r
#define USB_IS_ERROR(Result, Error) (((Result) & (Error)) != 0)\r
\r
-enum {\r
- //\r
- // Usb mass storage class code\r
- //\r
- USB_MASS_STORE_CLASS = 0x08,\r
-\r
- //\r
- // Usb mass storage subclass code, specify the command set used.\r
- //\r
- USB_MASS_STORE_RBC = 0x01, // Reduced Block Commands\r
- USB_MASS_STORE_8020I = 0x02, // SFF-8020i, typically a CD/DVD device\r
- USB_MASS_STORE_QIC = 0x03, // Typically a tape device\r
- USB_MASS_STORE_UFI = 0x04, // Typically a floppy disk driver device\r
- USB_MASS_STORE_8070I = 0x05, // SFF-8070i, typically a floppy disk driver device.\r
- USB_MASS_STORE_SCSI = 0x06, // SCSI transparent command set\r
-\r
- //\r
- // Usb mass storage protocol code, specify the transport protocol\r
- //\r
- USB_MASS_STORE_CBI0 = 0x00, // CBI protocol with command completion interrupt\r
- USB_MASS_STORE_CBI1 = 0x01, // CBI protocol without command completion interrupt\r
- USB_MASS_STORE_BOT = 0x50, // Bulk-Only Transport\r
-\r
- USB_MASS_1_MILLISECOND = 1000,\r
- USB_MASS_1_SECOND = 1000 * USB_MASS_1_MILLISECOND,\r
-\r
- USB_MASS_CMD_SUCCESS = 0,\r
- USB_MASS_CMD_FAIL,\r
- USB_MASS_CMD_PERSISTENT\r
-};\r
+#define USB_MASS_1_MILLISECOND 1000\r
+#define USB_MASS_1_SECOND (1000 * USB_MASS_1_MILLISECOND)\r
+\r
+#define USB_MASS_CMD_SUCCESS 0\r
+#define USB_MASS_CMD_FAIL 1\r
+#define USB_MASS_CMD_PERSISTENT 2\r
+\r
+/**\r
+ Initializes USB transport protocol.\r
\r
+ This function initializes the USB mass storage class transport protocol.\r
+ It will save its context in the Context if Context isn't NULL.\r
+\r
+ @param UsbIo The USB I/O Protocol instance\r
+ @param Context The buffer to save the context to\r
+\r
+ @retval EFI_SUCCESS The device is successfully initialized.\r
+ @retval EFI_UNSUPPORTED The transport protocol doesn't support the device.\r
+ @retval Other The USB transport initialization fails.\r
+\r
+**/\r
typedef\r
EFI_STATUS\r
(*USB_MASS_INIT_TRANSPORT) (\r
- IN EFI_USB_IO_PROTOCOL *Usb,\r
- IN EFI_HANDLE Controller,\r
- OUT VOID **Context OPTIONAL\r
+ IN EFI_USB_IO_PROTOCOL *Usb,\r
+ OUT VOID **Context OPTIONAL\r
);\r
\r
+/**\r
+ Execute USB mass storage command through the transport protocol.\r
+\r
+ @param Context The USB Transport Protocol.\r
+ @param Cmd The command to transfer to device\r
+ @param CmdLen The length of the command\r
+ @param DataDir The direction of data transfer\r
+ @param Data The buffer to hold the data\r
+ @param DataLen The length of the buffer\r
+ @param Lun Should be 0, this field for bot only\r
+ @param Timeout The time to wait\r
+ @param CmdStatus The result of the command execution\r
+\r
+ @retval EFI_SUCCESS The command is executed successfully.\r
+ @retval Other Failed to execute the command\r
+\r
+**/\r
typedef\r
EFI_STATUS\r
(*USB_MASS_EXEC_COMMAND) (\r
IN EFI_USB_DATA_DIRECTION DataDir,\r
IN VOID *Data,\r
IN UINT32 DataLen,\r
+ IN UINT8 Lun,\r
IN UINT32 Timeout,\r
OUT UINT32 *CmdStatus\r
);\r
\r
+/**\r
+ Reset the USB mass storage device by Transport protocol.\r
+\r
+ @param Context The USB Transport Protocol\r
+ @param ExtendedVerification The flag controlling the rule of reset.\r
+ Not used here.\r
+\r
+ @retval EFI_SUCCESS The device is reset.\r
+ @retval Others Failed to reset the device.\r
+\r
+**/\r
typedef\r
EFI_STATUS\r
(*USB_MASS_RESET) (\r
- IN VOID *Context,\r
- IN BOOLEAN ExtendedVerification\r
+ IN VOID *Context,\r
+ IN BOOLEAN ExtendedVerification\r
);\r
\r
+/**\r
+ Get the max LUN (Logical Unit Number) of USB mass storage device.\r
+\r
+ @param Context The context of the transport protocol.\r
+ @param MaxLun Return pointer to the max number of LUN. (e.g. MaxLun=1 means LUN0 and\r
+ LUN1 in all.)\r
+\r
+ @retval EFI_SUCCESS Max LUN is got successfully.\r
+ @retval Others Fail to execute this request.\r
+\r
+**/\r
typedef\r
EFI_STATUS\r
-(*USB_MASS_FINI) (\r
- IN VOID *Context\r
+(*USB_MASS_GET_MAX_LUN) (\r
+ IN VOID *Context,\r
+ IN UINT8 *MaxLun\r
);\r
\r
-//\r
-// This structure contains information necessary to select the\r
-// proper transport protocol. The mass storage class defines\r
-// two transport protocols. One is the CBI, and the other is BOT.\r
-// CBI is being obseleted. The design is made modular by this\r
-// structure so that the CBI protocol can be easily removed when\r
-// it is no longer necessary.\r
-//\r
-typedef struct {\r
- UINT8 Protocol;\r
- USB_MASS_INIT_TRANSPORT Init; // Initialize the mass storage transport protocol\r
- USB_MASS_EXEC_COMMAND ExecCommand; // Transport command to the device then get result\r
- USB_MASS_RESET Reset; // Reset the device\r
- USB_MASS_FINI Fini; // Clean up the resources.\r
-} USB_MASS_TRANSPORT;\r
+/**\r
+ Clean up the transport protocol's resource.\r
+\r
+ @param Context The instance of transport protocol.\r
\r
+ @retval EFI_SUCCESS The resource is cleaned up.\r
\r
+**/\r
+typedef\r
EFI_STATUS\r
-UsbClearEndpointStall (\r
- IN EFI_USB_IO_PROTOCOL *UsbIo,\r
- IN UINT8 EndpointAddress\r
+(*USB_MASS_CLEAN_UP) (\r
+ IN VOID *Context\r
);\r
\r
+///\r
+/// This structure contains information necessary to select the\r
+/// proper transport protocol. The mass storage class defines\r
+/// two transport protocols. One is the CBI, and the other is BOT.\r
+/// CBI is being obseleted. The design is made modular by this\r
+/// structure so that the CBI protocol can be easily removed when\r
+/// it is no longer necessary.\r
+///\r
+struct _USB_MASS_TRANSPORT {\r
+ UINT8 Protocol;\r
+ USB_MASS_INIT_TRANSPORT Init; ///< Initialize the mass storage transport protocol\r
+ USB_MASS_EXEC_COMMAND ExecCommand; ///< Transport command to the device then get result\r
+ USB_MASS_RESET Reset; ///< Reset the device\r
+ USB_MASS_GET_MAX_LUN GetMaxLun; ///< Get max lun, only for bot\r
+ USB_MASS_CLEAN_UP CleanUp; ///< Clean up the resources.\r
+};\r
+\r
+struct _USB_MASS_DEVICE {\r
+ UINT32 Signature;\r
+ EFI_HANDLE Controller;\r
+ EFI_USB_IO_PROTOCOL *UsbIo;\r
+ EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
+ EFI_BLOCK_IO_PROTOCOL BlockIo;\r
+ EFI_BLOCK_IO_MEDIA BlockIoMedia;\r
+ BOOLEAN OpticalStorage;\r
+ UINT8 Lun; ///< Logical Unit Number\r
+ UINT8 Pdt; ///< Peripheral Device Type\r
+ USB_MASS_TRANSPORT *Transport; ///< USB mass storage transport protocol\r
+ VOID *Context;\r
+ EFI_DISK_INFO_PROTOCOL DiskInfo;\r
+ USB_BOOT_INQUIRY_DATA InquiryData;\r
+ BOOLEAN Cdb16Byte;\r
+};\r
+\r
#endif\r