]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMass.h
b89014a8129989b0960f0241bbf3b0396a754f84
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbMassStorageDxe / UsbMass.h
1 /** @file
2 Definition of USB Mass Storage Class and its value, USB Mass Transport Protocol,
3 and other common definitions.
4
5 Copyright (c) 2007 - 2010, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16 #ifndef _EFI_USBMASS_H_
17 #define _EFI_USBMASS_H_
18
19
20 #include <Uefi.h>
21
22 #include <Protocol/BlockIo.h>
23 #include <Protocol/UsbIo.h>
24 #include <Protocol/DevicePath.h>
25
26 #include <Library/BaseLib.h>
27 #include <Library/DebugLib.h>
28 #include <Library/BaseMemoryLib.h>
29 #include <Library/UefiDriverEntryPoint.h>
30 #include <Library/UefiBootServicesTableLib.h>
31 #include <Library/UefiLib.h>
32 #include <Library/MemoryAllocationLib.h>
33 #include <Library/DevicePathLib.h>
34
35 #define USB_IS_IN_ENDPOINT(EndPointAddr) (((EndPointAddr) & BIT7) == BIT7)
36 #define USB_IS_OUT_ENDPOINT(EndPointAddr) (((EndPointAddr) & BIT7) == 0)
37 #define USB_IS_BULK_ENDPOINT(Attribute) (((Attribute) & (BIT0 | BIT1)) == USB_ENDPOINT_BULK)
38 #define USB_IS_INTERRUPT_ENDPOINT(Attribute) (((Attribute) & (BIT0 | BIT1)) == USB_ENDPOINT_INTERRUPT)
39 #define USB_IS_ERROR(Result, Error) (((Result) & (Error)) != 0)
40
41 //
42 // Usb mass storage class code
43 //
44 #define USB_MASS_STORE_CLASS 0x08
45
46 //
47 // Usb mass storage subclass code, specify the command set used.
48 //
49 #define USB_MASS_STORE_RBC 0x01 ///< Reduced Block Commands
50 #define USB_MASS_STORE_8020I 0x02 ///< SFF-8020i, typically a CD/DVD device
51 #define USB_MASS_STORE_QIC 0x03 ///< Typically a tape device
52 #define USB_MASS_STORE_UFI 0x04 ///< Typically a floppy disk driver device
53 #define USB_MASS_STORE_8070I 0x05 ///< SFF-8070i, typically a floppy disk driver device.
54 #define USB_MASS_STORE_SCSI 0x06 ///< SCSI transparent command set
55
56 //
57 // Usb mass storage protocol code, specify the transport protocol
58 //
59 #define USB_MASS_STORE_CBI0 0x00 ///< CBI protocol with command completion interrupt
60 #define USB_MASS_STORE_CBI1 0x01 ///< CBI protocol without command completion interrupt
61 #define USB_MASS_STORE_BOT 0x50 ///< Bulk-Only Transport
62
63 #define USB_MASS_1_MILLISECOND 1000
64 #define USB_MASS_1_SECOND (1000 * USB_MASS_1_MILLISECOND)
65
66 #define USB_MASS_CMD_SUCCESS 0
67 #define USB_MASS_CMD_FAIL 1
68 #define USB_MASS_CMD_PERSISTENT 2
69
70 /**
71 Initializes USB transport protocol.
72
73 This function initializes the USB mass storage class transport protocol.
74 It will save its context in the Context if Context isn't NULL.
75
76 @param UsbIo The USB I/O Protocol instance
77 @param Context The buffer to save the context to
78
79 @retval EFI_SUCCESS The device is successfully initialized.
80 @retval EFI_UNSUPPORTED The transport protocol doesn't support the device.
81 @retval Other The USB transport initialization fails.
82
83 **/
84 typedef
85 EFI_STATUS
86 (*USB_MASS_INIT_TRANSPORT) (
87 IN EFI_USB_IO_PROTOCOL *Usb,
88 OUT VOID **Context OPTIONAL
89 );
90
91 /**
92 Execute USB mass storage command through the transport protocol.
93
94 @param Context The USB Transport Protocol.
95 @param Cmd The command to transfer to device
96 @param CmdLen The length of the command
97 @param DataDir The direction of data transfer
98 @param Data The buffer to hold the data
99 @param DataLen The length of the buffer
100 @param Lun Should be 0, this field for bot only
101 @param Timeout The time to wait
102 @param CmdStatus The result of the command execution
103
104 @retval EFI_SUCCESS The command is executed successfully.
105 @retval Other Failed to execute the command
106
107 **/
108 typedef
109 EFI_STATUS
110 (*USB_MASS_EXEC_COMMAND) (
111 IN VOID *Context,
112 IN VOID *Cmd,
113 IN UINT8 CmdLen,
114 IN EFI_USB_DATA_DIRECTION DataDir,
115 IN VOID *Data,
116 IN UINT32 DataLen,
117 IN UINT8 Lun,
118 IN UINT32 Timeout,
119 OUT UINT32 *CmdStatus
120 );
121
122 /**
123 Reset the USB mass storage device by Transport protocol.
124
125 @param Context The USB Transport Protocol
126 @param ExtendedVerification The flag controlling the rule of reset.
127 Not used here.
128
129 @retval EFI_SUCCESS The device is reset.
130 @retval Others Failed to reset the device.
131
132 **/
133 typedef
134 EFI_STATUS
135 (*USB_MASS_RESET) (
136 IN VOID *Context,
137 IN BOOLEAN ExtendedVerification
138 );
139
140 /**
141 Get the max LUN (Logical Unit Number) of USB mass storage device.
142
143 @param Context The context of the transport protocol.
144 @param MaxLun Return pointer to the max number of LUN. (e.g. MaxLun=1 means LUN0 and
145 LUN1 in all.)
146
147 @retval EFI_SUCCESS Max LUN is got successfully.
148 @retval Others Fail to execute this request.
149
150 **/
151 typedef
152 EFI_STATUS
153 (*USB_MASS_GET_MAX_LUN) (
154 IN VOID *Context,
155 IN UINT8 *MaxLun
156 );
157
158 /**
159 Clean up the transport protocol's resource.
160
161 @param Context The instance of transport protocol.
162
163 @retval EFI_SUCCESS The resource is cleaned up.
164
165 **/
166 typedef
167 EFI_STATUS
168 (*USB_MASS_CLEAN_UP) (
169 IN VOID *Context
170 );
171
172 ///
173 /// This structure contains information necessary to select the
174 /// proper transport protocol. The mass storage class defines
175 /// two transport protocols. One is the CBI, and the other is BOT.
176 /// CBI is being obseleted. The design is made modular by this
177 /// structure so that the CBI protocol can be easily removed when
178 /// it is no longer necessary.
179 ///
180 typedef struct {
181 UINT8 Protocol;
182 USB_MASS_INIT_TRANSPORT Init; ///< Initialize the mass storage transport protocol
183 USB_MASS_EXEC_COMMAND ExecCommand; ///< Transport command to the device then get result
184 USB_MASS_RESET Reset; ///< Reset the device
185 USB_MASS_GET_MAX_LUN GetMaxLun; ///< Get max lun, only for bot
186 USB_MASS_CLEAN_UP CleanUp; ///< Clean up the resources.
187 } USB_MASS_TRANSPORT;
188
189 typedef struct {
190 UINT32 Signature;
191 EFI_HANDLE Controller;
192 EFI_USB_IO_PROTOCOL *UsbIo;
193 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
194 EFI_BLOCK_IO_PROTOCOL BlockIo;
195 EFI_BLOCK_IO_MEDIA BlockIoMedia;
196 BOOLEAN OpticalStorage;
197 UINT8 Lun; ///< Logical Unit Number
198 UINT8 Pdt; ///< Peripheral Device Type
199 USB_MASS_TRANSPORT *Transport; ///< USB mass storage transport protocol
200 VOID *Context;
201 } USB_MASS_DEVICE;
202
203 #endif