]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMass.h
Produce DiskInfo for usb mass storage device
[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 - 2011, Intel Corporation. All rights reserved.<BR>
6 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 #include <Protocol/DiskInfo.h>
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 typedef struct _USB_MASS_TRANSPORT USB_MASS_TRANSPORT;
36 typedef struct _USB_MASS_DEVICE USB_MASS_DEVICE;
37
38 #include "UsbMassBot.h"
39 #include "UsbMassCbi.h"
40 #include "UsbMassBoot.h"
41 #include "UsbMassDiskInfo.h"
42 #include "UsbMassImpl.h"
43
44 #define USB_IS_IN_ENDPOINT(EndPointAddr) (((EndPointAddr) & BIT7) == BIT7)
45 #define USB_IS_OUT_ENDPOINT(EndPointAddr) (((EndPointAddr) & BIT7) == 0)
46 #define USB_IS_BULK_ENDPOINT(Attribute) (((Attribute) & (BIT0 | BIT1)) == USB_ENDPOINT_BULK)
47 #define USB_IS_INTERRUPT_ENDPOINT(Attribute) (((Attribute) & (BIT0 | BIT1)) == USB_ENDPOINT_INTERRUPT)
48 #define USB_IS_ERROR(Result, Error) (((Result) & (Error)) != 0)
49
50 //
51 // Usb mass storage class code
52 //
53 #define USB_MASS_STORE_CLASS 0x08
54
55 //
56 // Usb mass storage subclass code, specify the command set used.
57 //
58 #define USB_MASS_STORE_RBC 0x01 ///< Reduced Block Commands
59 #define USB_MASS_STORE_8020I 0x02 ///< SFF-8020i, typically a CD/DVD device
60 #define USB_MASS_STORE_QIC 0x03 ///< Typically a tape device
61 #define USB_MASS_STORE_UFI 0x04 ///< Typically a floppy disk driver device
62 #define USB_MASS_STORE_8070I 0x05 ///< SFF-8070i, typically a floppy disk driver device.
63 #define USB_MASS_STORE_SCSI 0x06 ///< SCSI transparent command set
64
65 //
66 // Usb mass storage protocol code, specify the transport protocol
67 //
68 #define USB_MASS_STORE_CBI0 0x00 ///< CBI protocol with command completion interrupt
69 #define USB_MASS_STORE_CBI1 0x01 ///< CBI protocol without command completion interrupt
70 #define USB_MASS_STORE_BOT 0x50 ///< Bulk-Only Transport
71
72 #define USB_MASS_1_MILLISECOND 1000
73 #define USB_MASS_1_SECOND (1000 * USB_MASS_1_MILLISECOND)
74
75 #define USB_MASS_CMD_SUCCESS 0
76 #define USB_MASS_CMD_FAIL 1
77 #define USB_MASS_CMD_PERSISTENT 2
78
79 /**
80 Initializes USB transport protocol.
81
82 This function initializes the USB mass storage class transport protocol.
83 It will save its context in the Context if Context isn't NULL.
84
85 @param UsbIo The USB I/O Protocol instance
86 @param Context The buffer to save the context to
87
88 @retval EFI_SUCCESS The device is successfully initialized.
89 @retval EFI_UNSUPPORTED The transport protocol doesn't support the device.
90 @retval Other The USB transport initialization fails.
91
92 **/
93 typedef
94 EFI_STATUS
95 (*USB_MASS_INIT_TRANSPORT) (
96 IN EFI_USB_IO_PROTOCOL *Usb,
97 OUT VOID **Context OPTIONAL
98 );
99
100 /**
101 Execute USB mass storage command through the transport protocol.
102
103 @param Context The USB Transport Protocol.
104 @param Cmd The command to transfer to device
105 @param CmdLen The length of the command
106 @param DataDir The direction of data transfer
107 @param Data The buffer to hold the data
108 @param DataLen The length of the buffer
109 @param Lun Should be 0, this field for bot only
110 @param Timeout The time to wait
111 @param CmdStatus The result of the command execution
112
113 @retval EFI_SUCCESS The command is executed successfully.
114 @retval Other Failed to execute the command
115
116 **/
117 typedef
118 EFI_STATUS
119 (*USB_MASS_EXEC_COMMAND) (
120 IN VOID *Context,
121 IN VOID *Cmd,
122 IN UINT8 CmdLen,
123 IN EFI_USB_DATA_DIRECTION DataDir,
124 IN VOID *Data,
125 IN UINT32 DataLen,
126 IN UINT8 Lun,
127 IN UINT32 Timeout,
128 OUT UINT32 *CmdStatus
129 );
130
131 /**
132 Reset the USB mass storage device by Transport protocol.
133
134 @param Context The USB Transport Protocol
135 @param ExtendedVerification The flag controlling the rule of reset.
136 Not used here.
137
138 @retval EFI_SUCCESS The device is reset.
139 @retval Others Failed to reset the device.
140
141 **/
142 typedef
143 EFI_STATUS
144 (*USB_MASS_RESET) (
145 IN VOID *Context,
146 IN BOOLEAN ExtendedVerification
147 );
148
149 /**
150 Get the max LUN (Logical Unit Number) of USB mass storage device.
151
152 @param Context The context of the transport protocol.
153 @param MaxLun Return pointer to the max number of LUN. (e.g. MaxLun=1 means LUN0 and
154 LUN1 in all.)
155
156 @retval EFI_SUCCESS Max LUN is got successfully.
157 @retval Others Fail to execute this request.
158
159 **/
160 typedef
161 EFI_STATUS
162 (*USB_MASS_GET_MAX_LUN) (
163 IN VOID *Context,
164 IN UINT8 *MaxLun
165 );
166
167 /**
168 Clean up the transport protocol's resource.
169
170 @param Context The instance of transport protocol.
171
172 @retval EFI_SUCCESS The resource is cleaned up.
173
174 **/
175 typedef
176 EFI_STATUS
177 (*USB_MASS_CLEAN_UP) (
178 IN VOID *Context
179 );
180
181 ///
182 /// This structure contains information necessary to select the
183 /// proper transport protocol. The mass storage class defines
184 /// two transport protocols. One is the CBI, and the other is BOT.
185 /// CBI is being obseleted. The design is made modular by this
186 /// structure so that the CBI protocol can be easily removed when
187 /// it is no longer necessary.
188 ///
189 struct _USB_MASS_TRANSPORT {
190 UINT8 Protocol;
191 USB_MASS_INIT_TRANSPORT Init; ///< Initialize the mass storage transport protocol
192 USB_MASS_EXEC_COMMAND ExecCommand; ///< Transport command to the device then get result
193 USB_MASS_RESET Reset; ///< Reset the device
194 USB_MASS_GET_MAX_LUN GetMaxLun; ///< Get max lun, only for bot
195 USB_MASS_CLEAN_UP CleanUp; ///< Clean up the resources.
196 };
197
198 struct _USB_MASS_DEVICE {
199 UINT32 Signature;
200 EFI_HANDLE Controller;
201 EFI_USB_IO_PROTOCOL *UsbIo;
202 EFI_DEVICE_PATH_PROTOCOL *DevicePath;
203 EFI_BLOCK_IO_PROTOCOL BlockIo;
204 EFI_BLOCK_IO_MEDIA BlockIoMedia;
205 BOOLEAN OpticalStorage;
206 UINT8 Lun; ///< Logical Unit Number
207 UINT8 Pdt; ///< Peripheral Device Type
208 USB_MASS_TRANSPORT *Transport; ///< USB mass storage transport protocol
209 VOID *Context;
210 EFI_DISK_INFO_PROTOCOL DiskInfo;
211 USB_BOOT_INQUIRY_DATA InquiryData;
212 };
213
214 #endif