]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMass.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[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 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #ifndef _EFI_USBMASS_H_
11 #define _EFI_USBMASS_H_
12
13
14 #include <Uefi.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>
28
29 typedef struct _USB_MASS_TRANSPORT USB_MASS_TRANSPORT;
30 typedef struct _USB_MASS_DEVICE USB_MASS_DEVICE;
31
32 #include "UsbMassBot.h"
33 #include "UsbMassCbi.h"
34 #include "UsbMassBoot.h"
35 #include "UsbMassDiskInfo.h"
36 #include "UsbMassImpl.h"
37
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)
43
44 #define USB_MASS_1_MILLISECOND 1000
45 #define USB_MASS_1_SECOND (1000 * USB_MASS_1_MILLISECOND)
46
47 #define USB_MASS_CMD_SUCCESS 0
48 #define USB_MASS_CMD_FAIL 1
49 #define USB_MASS_CMD_PERSISTENT 2
50
51 /**
52 Initializes USB transport protocol.
53
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.
56
57 @param UsbIo The USB I/O Protocol instance
58 @param Context The buffer to save the context to
59
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.
63
64 **/
65 typedef
66 EFI_STATUS
67 (*USB_MASS_INIT_TRANSPORT) (
68 IN EFI_USB_IO_PROTOCOL *Usb,
69 OUT VOID **Context OPTIONAL
70 );
71
72 /**
73 Execute USB mass storage command through the transport protocol.
74
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
84
85 @retval EFI_SUCCESS The command is executed successfully.
86 @retval Other Failed to execute the command
87
88 **/
89 typedef
90 EFI_STATUS
91 (*USB_MASS_EXEC_COMMAND) (
92 IN VOID *Context,
93 IN VOID *Cmd,
94 IN UINT8 CmdLen,
95 IN EFI_USB_DATA_DIRECTION DataDir,
96 IN VOID *Data,
97 IN UINT32 DataLen,
98 IN UINT8 Lun,
99 IN UINT32 Timeout,
100 OUT UINT32 *CmdStatus
101 );
102
103 /**
104 Reset the USB mass storage device by Transport protocol.
105
106 @param Context The USB Transport Protocol
107 @param ExtendedVerification The flag controlling the rule of reset.
108 Not used here.
109
110 @retval EFI_SUCCESS The device is reset.
111 @retval Others Failed to reset the device.
112
113 **/
114 typedef
115 EFI_STATUS
116 (*USB_MASS_RESET) (
117 IN VOID *Context,
118 IN BOOLEAN ExtendedVerification
119 );
120
121 /**
122 Get the max LUN (Logical Unit Number) of USB mass storage device.
123
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
126 LUN1 in all.)
127
128 @retval EFI_SUCCESS Max LUN is got successfully.
129 @retval Others Fail to execute this request.
130
131 **/
132 typedef
133 EFI_STATUS
134 (*USB_MASS_GET_MAX_LUN) (
135 IN VOID *Context,
136 IN UINT8 *MaxLun
137 );
138
139 /**
140 Clean up the transport protocol's resource.
141
142 @param Context The instance of transport protocol.
143
144 @retval EFI_SUCCESS The resource is cleaned up.
145
146 **/
147 typedef
148 EFI_STATUS
149 (*USB_MASS_CLEAN_UP) (
150 IN VOID *Context
151 );
152
153 ///
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.
160 ///
161 struct _USB_MASS_TRANSPORT {
162 UINT8 Protocol;
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.
168 };
169
170 struct _USB_MASS_DEVICE {
171 UINT32 Signature;
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
181 VOID *Context;
182 EFI_DISK_INFO_PROTOCOL DiskInfo;
183 USB_BOOT_INQUIRY_DATA InquiryData;
184 BOOLEAN Cdb16Byte;
185 };
186
187 #endif