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