2 Definition of USB Mass Storage Class and its value, USB Mass Transport Protocol,
3 and other common definitions.
5 Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #ifndef _EFI_USBMASS_H_
11 #define _EFI_USBMASS_H_
14 #include <IndustryStandard/Scsi.h>
15 #include <Protocol/BlockIo.h>
16 #include <Protocol/UsbIo.h>
17 #include <Protocol/DevicePath.h>
18 #include <Protocol/DiskInfo.h>
19 #include <Library/BaseLib.h>
20 #include <Library/DebugLib.h>
21 #include <Library/BaseMemoryLib.h>
22 #include <Library/UefiDriverEntryPoint.h>
23 #include <Library/UefiBootServicesTableLib.h>
24 #include <Library/UefiLib.h>
25 #include <Library/MemoryAllocationLib.h>
26 #include <Library/DevicePathLib.h>
28 typedef struct _USB_MASS_TRANSPORT USB_MASS_TRANSPORT
;
29 typedef struct _USB_MASS_DEVICE USB_MASS_DEVICE
;
31 #include "UsbMassBot.h"
32 #include "UsbMassCbi.h"
33 #include "UsbMassBoot.h"
34 #include "UsbMassDiskInfo.h"
35 #include "UsbMassImpl.h"
37 #define USB_IS_IN_ENDPOINT(EndPointAddr) (((EndPointAddr) & BIT7) == BIT7)
38 #define USB_IS_OUT_ENDPOINT(EndPointAddr) (((EndPointAddr) & BIT7) == 0)
39 #define USB_IS_BULK_ENDPOINT(Attribute) (((Attribute) & (BIT0 | BIT1)) == USB_ENDPOINT_BULK)
40 #define USB_IS_INTERRUPT_ENDPOINT(Attribute) (((Attribute) & (BIT0 | BIT1)) == USB_ENDPOINT_INTERRUPT)
41 #define USB_IS_ERROR(Result, Error) (((Result) & (Error)) != 0)
43 #define USB_MASS_1_MILLISECOND 1000
44 #define USB_MASS_1_SECOND (1000 * USB_MASS_1_MILLISECOND)
46 #define USB_MASS_CMD_SUCCESS 0
47 #define USB_MASS_CMD_FAIL 1
48 #define USB_MASS_CMD_PERSISTENT 2
51 Initializes USB transport protocol.
53 This function initializes the USB mass storage class transport protocol.
54 It will save its context in the Context if Context isn't NULL.
56 @param UsbIo The USB I/O Protocol instance
57 @param Context The buffer to save the context to
59 @retval EFI_SUCCESS The device is successfully initialized.
60 @retval EFI_UNSUPPORTED The transport protocol doesn't support the device.
61 @retval Other The USB transport initialization fails.
66 (*USB_MASS_INIT_TRANSPORT
) (
67 IN EFI_USB_IO_PROTOCOL
*Usb
,
68 OUT VOID
**Context OPTIONAL
72 Execute USB mass storage command through the transport protocol.
74 @param Context The USB Transport Protocol.
75 @param Cmd The command to transfer to device
76 @param CmdLen The length of the command
77 @param DataDir The direction of data transfer
78 @param Data The buffer to hold the data
79 @param DataLen The length of the buffer
80 @param Lun Should be 0, this field for bot only
81 @param Timeout The time to wait
82 @param CmdStatus The result of the command execution
84 @retval EFI_SUCCESS The command is executed successfully.
85 @retval Other Failed to execute the command
90 (*USB_MASS_EXEC_COMMAND
) (
94 IN EFI_USB_DATA_DIRECTION DataDir
,
103 Reset the USB mass storage device by Transport protocol.
105 @param Context The USB Transport Protocol
106 @param ExtendedVerification The flag controlling the rule of reset.
109 @retval EFI_SUCCESS The device is reset.
110 @retval Others Failed to reset the device.
117 IN BOOLEAN ExtendedVerification
121 Get the max LUN (Logical Unit Number) of USB mass storage device.
123 @param Context The context of the transport protocol.
124 @param MaxLun Return pointer to the max number of LUN. (e.g. MaxLun=1 means LUN0 and
127 @retval EFI_SUCCESS Max LUN is got successfully.
128 @retval Others Fail to execute this request.
133 (*USB_MASS_GET_MAX_LUN
) (
139 Clean up the transport protocol's resource.
141 @param Context The instance of transport protocol.
143 @retval EFI_SUCCESS The resource is cleaned up.
148 (*USB_MASS_CLEAN_UP
) (
153 /// This structure contains information necessary to select the
154 /// proper transport protocol. The mass storage class defines
155 /// two transport protocols. One is the CBI, and the other is BOT.
156 /// CBI is being obseleted. The design is made modular by this
157 /// structure so that the CBI protocol can be easily removed when
158 /// it is no longer necessary.
160 struct _USB_MASS_TRANSPORT
{
162 USB_MASS_INIT_TRANSPORT Init
; ///< Initialize the mass storage transport protocol
163 USB_MASS_EXEC_COMMAND ExecCommand
; ///< Transport command to the device then get result
164 USB_MASS_RESET Reset
; ///< Reset the device
165 USB_MASS_GET_MAX_LUN GetMaxLun
; ///< Get max lun, only for bot
166 USB_MASS_CLEAN_UP CleanUp
; ///< Clean up the resources.
169 struct _USB_MASS_DEVICE
{
171 EFI_HANDLE Controller
;
172 EFI_USB_IO_PROTOCOL
*UsbIo
;
173 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
174 EFI_BLOCK_IO_PROTOCOL BlockIo
;
175 EFI_BLOCK_IO_MEDIA BlockIoMedia
;
176 BOOLEAN OpticalStorage
;
177 UINT8 Lun
; ///< Logical Unit Number
178 UINT8 Pdt
; ///< Peripheral Device Type
179 USB_MASS_TRANSPORT
*Transport
; ///< USB mass storage transport protocol
181 EFI_DISK_INFO_PROTOCOL DiskInfo
;
182 USB_BOOT_INQUIRY_DATA InquiryData
;