]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMass.h
MdeModulePkg: Replace BSD License with BSD+Patent License
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbMassStorageDxe / UsbMass.h
CommitLineData
e237e7ae 1/** @file\r
d1102dba 2 Definition of USB Mass Storage Class and its value, USB Mass Transport Protocol,\r
3e03cb4d 3 and other common definitions.\r
e237e7ae 4\r
d1102dba 5Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
9d510e61 6SPDX-License-Identifier: BSD-2-Clause-Patent\r
e237e7ae 7\r
8**/\r
9\r
10#ifndef _EFI_USBMASS_H_\r
11#define _EFI_USBMASS_H_\r
12\r
ed7748fe 13\r
60c93673 14#include <Uefi.h>\r
99c1725e 15#include <IndustryStandard/Scsi.h>\r
e237e7ae 16#include <Protocol/BlockIo.h>\r
17#include <Protocol/UsbIo.h>\r
c7e39923 18#include <Protocol/DevicePath.h>\r
39840c50 19#include <Protocol/DiskInfo.h>\r
776a705e 20#include <Library/BaseLib.h>\r
e237e7ae 21#include <Library/DebugLib.h>\r
22#include <Library/BaseMemoryLib.h>\r
23#include <Library/UefiDriverEntryPoint.h>\r
24#include <Library/UefiBootServicesTableLib.h>\r
25#include <Library/UefiLib.h>\r
26#include <Library/MemoryAllocationLib.h>\r
c7e39923 27#include <Library/DevicePathLib.h>\r
e237e7ae 28\r
39840c50 29typedef struct _USB_MASS_TRANSPORT USB_MASS_TRANSPORT;\r
30typedef struct _USB_MASS_DEVICE USB_MASS_DEVICE;\r
31\r
32#include "UsbMassBot.h"\r
33#include "UsbMassCbi.h"\r
34#include "UsbMassBoot.h"\r
35#include "UsbMassDiskInfo.h"\r
36#include "UsbMassImpl.h"\r
37\r
d80ed2a7 38#define USB_IS_IN_ENDPOINT(EndPointAddr) (((EndPointAddr) & BIT7) == BIT7)\r
39#define USB_IS_OUT_ENDPOINT(EndPointAddr) (((EndPointAddr) & BIT7) == 0)\r
40#define USB_IS_BULK_ENDPOINT(Attribute) (((Attribute) & (BIT0 | BIT1)) == USB_ENDPOINT_BULK)\r
41#define USB_IS_INTERRUPT_ENDPOINT(Attribute) (((Attribute) & (BIT0 | BIT1)) == USB_ENDPOINT_INTERRUPT)\r
e237e7ae 42#define USB_IS_ERROR(Result, Error) (((Result) & (Error)) != 0)\r
43\r
1ccdbf2a 44#define USB_MASS_1_MILLISECOND 1000\r
45#define USB_MASS_1_SECOND (1000 * USB_MASS_1_MILLISECOND)\r
46\r
47#define USB_MASS_CMD_SUCCESS 0\r
48#define USB_MASS_CMD_FAIL 1\r
49#define USB_MASS_CMD_PERSISTENT 2\r
3e03cb4d 50\r
51/**\r
52 Initializes USB transport protocol.\r
53\r
54 This function initializes the USB mass storage class transport protocol.\r
55 It will save its context in the Context if Context isn't NULL.\r
56\r
57 @param UsbIo The USB I/O Protocol instance\r
58 @param Context The buffer to save the context to\r
e237e7ae 59\r
3e03cb4d 60 @retval EFI_SUCCESS The device is successfully initialized.\r
61 @retval EFI_UNSUPPORTED The transport protocol doesn't support the device.\r
62 @retval Other The USB transport initialization fails.\r
63\r
64**/\r
e237e7ae 65typedef\r
66EFI_STATUS\r
67(*USB_MASS_INIT_TRANSPORT) (\r
68 IN EFI_USB_IO_PROTOCOL *Usb,\r
e237e7ae 69 OUT VOID **Context OPTIONAL\r
70 );\r
71\r
3e03cb4d 72/**\r
73 Execute USB mass storage command through the transport protocol.\r
74\r
75 @param Context The USB Transport Protocol.\r
76 @param Cmd The command to transfer to device\r
77 @param CmdLen The length of the command\r
78 @param DataDir The direction of data transfer\r
79 @param Data The buffer to hold the data\r
80 @param DataLen The length of the buffer\r
81 @param Lun Should be 0, this field for bot only\r
82 @param Timeout The time to wait\r
83 @param CmdStatus The result of the command execution\r
84\r
85 @retval EFI_SUCCESS The command is executed successfully.\r
86 @retval Other Failed to execute the command\r
87\r
88**/\r
e237e7ae 89typedef\r
90EFI_STATUS\r
91(*USB_MASS_EXEC_COMMAND) (\r
92 IN VOID *Context,\r
93 IN VOID *Cmd,\r
94 IN UINT8 CmdLen,\r
95 IN EFI_USB_DATA_DIRECTION DataDir,\r
96 IN VOID *Data,\r
97 IN UINT32 DataLen,\r
c7e39923 98 IN UINT8 Lun,\r
e237e7ae 99 IN UINT32 Timeout,\r
100 OUT UINT32 *CmdStatus\r
101 );\r
102\r
3e03cb4d 103/**\r
104 Reset the USB mass storage device by Transport protocol.\r
105\r
106 @param Context The USB Transport Protocol\r
107 @param ExtendedVerification The flag controlling the rule of reset.\r
108 Not used here.\r
109\r
110 @retval EFI_SUCCESS The device is reset.\r
111 @retval Others Failed to reset the device.\r
112\r
113**/\r
e237e7ae 114typedef\r
115EFI_STATUS\r
116(*USB_MASS_RESET) (\r
117 IN VOID *Context,\r
118 IN BOOLEAN ExtendedVerification\r
119 );\r
120\r
3e03cb4d 121/**\r
122 Get the max LUN (Logical Unit Number) of USB mass storage device.\r
123\r
124 @param Context The context of the transport protocol.\r
125 @param MaxLun Return pointer to the max number of LUN. (e.g. MaxLun=1 means LUN0 and\r
126 LUN1 in all.)\r
127\r
128 @retval EFI_SUCCESS Max LUN is got successfully.\r
129 @retval Others Fail to execute this request.\r
130\r
131**/\r
c7e39923 132typedef\r
133EFI_STATUS\r
134(*USB_MASS_GET_MAX_LUN) (\r
135 IN VOID *Context,\r
136 IN UINT8 *MaxLun\r
137 );\r
138\r
3e03cb4d 139/**\r
140 Clean up the transport protocol's resource.\r
141\r
142 @param Context The instance of transport protocol.\r
143\r
144 @retval EFI_SUCCESS The resource is cleaned up.\r
145\r
146**/\r
e237e7ae 147typedef\r
148EFI_STATUS\r
d80ed2a7 149(*USB_MASS_CLEAN_UP) (\r
e237e7ae 150 IN VOID *Context\r
151 );\r
152\r
d80ed2a7 153///\r
154/// This structure contains information necessary to select the\r
155/// proper transport protocol. The mass storage class defines\r
156/// two transport protocols. One is the CBI, and the other is BOT.\r
157/// CBI is being obseleted. The design is made modular by this\r
158/// structure so that the CBI protocol can be easily removed when\r
159/// it is no longer necessary.\r
160///\r
39840c50 161struct _USB_MASS_TRANSPORT {\r
e237e7ae 162 UINT8 Protocol;\r
d80ed2a7 163 USB_MASS_INIT_TRANSPORT Init; ///< Initialize the mass storage transport protocol\r
164 USB_MASS_EXEC_COMMAND ExecCommand; ///< Transport command to the device then get result\r
165 USB_MASS_RESET Reset; ///< Reset the device\r
166 USB_MASS_GET_MAX_LUN GetMaxLun; ///< Get max lun, only for bot\r
167 USB_MASS_CLEAN_UP CleanUp; ///< Clean up the resources.\r
39840c50 168};\r
e237e7ae 169\r
39840c50 170struct _USB_MASS_DEVICE {\r
3e03cb4d 171 UINT32 Signature;\r
172 EFI_HANDLE Controller;\r
173 EFI_USB_IO_PROTOCOL *UsbIo;\r
174 EFI_DEVICE_PATH_PROTOCOL *DevicePath;\r
175 EFI_BLOCK_IO_PROTOCOL BlockIo;\r
176 EFI_BLOCK_IO_MEDIA BlockIoMedia;\r
177 BOOLEAN OpticalStorage;\r
178 UINT8 Lun; ///< Logical Unit Number\r
179 UINT8 Pdt; ///< Peripheral Device Type\r
180 USB_MASS_TRANSPORT *Transport; ///< USB mass storage transport protocol\r
39840c50 181 VOID *Context;\r
182 EFI_DISK_INFO_PROTOCOL DiskInfo;\r
183 USB_BOOT_INQUIRY_DATA InquiryData;\r
99c1725e 184 BOOLEAN Cdb16Byte;\r
39840c50 185};\r
e237e7ae 186\r
e237e7ae 187#endif\r