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_
15 #include <IndustryStandard/Scsi.h>
16 #include <Protocol/BlockIo.h>
17 #include <Protocol/UsbIo.h>
18 #include <Protocol/DevicePath.h>
19 #include <Protocol/DiskInfo.h>
20 #include <Library/BaseLib.h>
21 #include <Library/DebugLib.h>
22 #include <Library/BaseMemoryLib.h>
23 #include <Library/UefiDriverEntryPoint.h>
24 #include <Library/UefiBootServicesTableLib.h>
25 #include <Library/UefiLib.h>
26 #include <Library/MemoryAllocationLib.h>
27 #include <Library/DevicePathLib.h>
29 typedef struct _USB_MASS_TRANSPORT USB_MASS_TRANSPORT
;
30 typedef struct _USB_MASS_DEVICE USB_MASS_DEVICE
;
32 #include "UsbMassBot.h"
33 #include "UsbMassCbi.h"
34 #include "UsbMassBoot.h"
35 #include "UsbMassDiskInfo.h"
36 #include "UsbMassImpl.h"
38 #define USB_IS_IN_ENDPOINT(EndPointAddr) (((EndPointAddr) & BIT7) == BIT7)
39 #define USB_IS_OUT_ENDPOINT(EndPointAddr) (((EndPointAddr) & BIT7) == 0)
40 #define USB_IS_BULK_ENDPOINT(Attribute) (((Attribute) & (BIT0 | BIT1)) == USB_ENDPOINT_BULK)
41 #define USB_IS_INTERRUPT_ENDPOINT(Attribute) (((Attribute) & (BIT0 | BIT1)) == USB_ENDPOINT_INTERRUPT)
42 #define USB_IS_ERROR(Result, Error) (((Result) & (Error)) != 0)
44 #define USB_MASS_1_MILLISECOND 1000
45 #define USB_MASS_1_SECOND (1000 * USB_MASS_1_MILLISECOND)
47 #define USB_MASS_CMD_SUCCESS 0
48 #define USB_MASS_CMD_FAIL 1
49 #define USB_MASS_CMD_PERSISTENT 2
52 Initializes USB transport protocol.
54 This function initializes the USB mass storage class transport protocol.
55 It will save its context in the Context if Context isn't NULL.
57 @param UsbIo The USB I/O Protocol instance
58 @param Context The buffer to save the context to
60 @retval EFI_SUCCESS The device is successfully initialized.
61 @retval EFI_UNSUPPORTED The transport protocol doesn't support the device.
62 @retval Other The USB transport initialization fails.
67 (*USB_MASS_INIT_TRANSPORT
) (
68 IN EFI_USB_IO_PROTOCOL
*Usb
,
69 OUT VOID
**Context OPTIONAL
73 Execute USB mass storage command through the transport protocol.
75 @param Context The USB Transport Protocol.
76 @param Cmd The command to transfer to device
77 @param CmdLen The length of the command
78 @param DataDir The direction of data transfer
79 @param Data The buffer to hold the data
80 @param DataLen The length of the buffer
81 @param Lun Should be 0, this field for bot only
82 @param Timeout The time to wait
83 @param CmdStatus The result of the command execution
85 @retval EFI_SUCCESS The command is executed successfully.
86 @retval Other Failed to execute the command
91 (*USB_MASS_EXEC_COMMAND
) (
95 IN EFI_USB_DATA_DIRECTION DataDir
,
100 OUT UINT32
*CmdStatus
104 Reset the USB mass storage device by Transport protocol.
106 @param Context The USB Transport Protocol
107 @param ExtendedVerification The flag controlling the rule of reset.
110 @retval EFI_SUCCESS The device is reset.
111 @retval Others Failed to reset the device.
118 IN BOOLEAN ExtendedVerification
122 Get the max LUN (Logical Unit Number) of USB mass storage device.
124 @param Context The context of the transport protocol.
125 @param MaxLun Return pointer to the max number of LUN. (e.g. MaxLun=1 means LUN0 and
128 @retval EFI_SUCCESS Max LUN is got successfully.
129 @retval Others Fail to execute this request.
134 (*USB_MASS_GET_MAX_LUN
) (
140 Clean up the transport protocol's resource.
142 @param Context The instance of transport protocol.
144 @retval EFI_SUCCESS The resource is cleaned up.
149 (*USB_MASS_CLEAN_UP
) (
154 /// This structure contains information necessary to select the
155 /// proper transport protocol. The mass storage class defines
156 /// two transport protocols. One is the CBI, and the other is BOT.
157 /// CBI is being obseleted. The design is made modular by this
158 /// structure so that the CBI protocol can be easily removed when
159 /// it is no longer necessary.
161 struct _USB_MASS_TRANSPORT
{
163 USB_MASS_INIT_TRANSPORT Init
; ///< Initialize the mass storage transport protocol
164 USB_MASS_EXEC_COMMAND ExecCommand
; ///< Transport command to the device then get result
165 USB_MASS_RESET Reset
; ///< Reset the device
166 USB_MASS_GET_MAX_LUN GetMaxLun
; ///< Get max lun, only for bot
167 USB_MASS_CLEAN_UP CleanUp
; ///< Clean up the resources.
170 struct _USB_MASS_DEVICE
{
172 EFI_HANDLE Controller
;
173 EFI_USB_IO_PROTOCOL
*UsbIo
;
174 EFI_DEVICE_PATH_PROTOCOL
*DevicePath
;
175 EFI_BLOCK_IO_PROTOCOL BlockIo
;
176 EFI_BLOCK_IO_MEDIA BlockIoMedia
;
177 BOOLEAN OpticalStorage
;
178 UINT8 Lun
; ///< Logical Unit Number
179 UINT8 Pdt
; ///< Peripheral Device Type
180 USB_MASS_TRANSPORT
*Transport
; ///< USB mass storage transport protocol
182 EFI_DISK_INFO_PROTOCOL DiskInfo
;
183 USB_BOOT_INQUIRY_DATA InquiryData
;