]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.h
MdeModulePkg/UsbMass: Fix various typos
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbMassStorageDxe / UsbMassBoot.h
... / ...
CommitLineData
1/** @file\r
2 Definition of the command set of USB Mass Storage Specification\r
3 for Bootability, Revision 1.0.\r
4\r
5Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
6SPDX-License-Identifier: BSD-2-Clause-Patent\r
7\r
8**/\r
9\r
10#ifndef _EFI_USB_MASS_BOOT_H_\r
11#define _EFI_USB_MASS_BOOT_H_\r
12\r
13//\r
14// The opcodes of various USB boot commands:\r
15// INQUIRY/REQUEST_SENSE are "No Timeout Commands" as specified\r
16// by Multi-Media Commands (MMC) set.\r
17// Others are "Group 1 Timeout Commands". That is,\r
18// they should be retried if driver is ready.\r
19//\r
20#define USB_BOOT_INQUIRY_OPCODE 0x12\r
21#define USB_BOOT_REQUEST_SENSE_OPCODE 0x03\r
22#define USB_BOOT_MODE_SENSE10_OPCODE 0x5A\r
23#define USB_BOOT_READ_CAPACITY_OPCODE 0x25\r
24#define USB_BOOT_TEST_UNIT_READY_OPCODE 0x00\r
25#define USB_BOOT_READ10_OPCODE 0x28\r
26#define USB_BOOT_WRITE10_OPCODE 0x2A\r
27\r
28#define USB_SCSI_MODE_SENSE6_OPCODE 0x1A\r
29\r
30//\r
31// The Sense Key part of the sense data. Sense data has three levels:\r
32// Sense key, Additional Sense Code and Additional Sense Code Qualifier\r
33//\r
34#define USB_BOOT_SENSE_NO_SENSE 0x00 ///< No sense key\r
35#define USB_BOOT_SENSE_RECOVERED 0x01 ///< Last command succeed with recovery actions\r
36#define USB_BOOT_SENSE_NOT_READY 0x02 ///< Device not ready\r
37#define USB_BOOT_SNESE_MEDIUM_ERROR 0X03 ///< Failed probably because flaw in the media\r
38#define USB_BOOT_SENSE_HARDWARE_ERROR 0X04 ///< Non-recoverable hardware failure\r
39#define USB_BOOT_SENSE_ILLEGAL_REQUEST 0X05 ///< Illegal parameters in the request\r
40#define USB_BOOT_SENSE_UNIT_ATTENTION 0X06 ///< Removable medium may have been changed\r
41#define USB_BOOT_SENSE_DATA_PROTECT 0X07 ///< Write protected\r
42#define USB_BOOT_SENSE_BLANK_CHECK 0X08 ///< Blank/non-blank medium while reading/writing\r
43#define USB_BOOT_SENSE_VENDOR 0X09 ///< Vendor specific sense key\r
44#define USB_BOOT_SENSE_ABORTED 0X0B ///< Command aborted by the device\r
45#define USB_BOOT_SENSE_VOLUME_OVERFLOW 0x0D ///< Partition overflow\r
46#define USB_BOOT_SENSE_MISCOMPARE 0x0E ///< Source data mis-match while verfying.\r
47\r
48#define USB_BOOT_ASC_NO_ADDITIONAL_SENSE_INFORMATION 0x00\r
49#define USB_BOOT_ASC_NOT_READY 0x04\r
50#define USB_BOOT_ASC_NO_MEDIA 0x3A\r
51#define USB_BOOT_ASC_MEDIA_CHANGE 0x28\r
52\r
53//\r
54// Supported PDT codes, or Peripheral Device Type\r
55//\r
56#define USB_PDT_DIRECT_ACCESS 0x00 ///< Direct access device\r
57#define USB_PDT_CDROM 0x05 ///< CDROM\r
58#define USB_PDT_OPTICAL 0x07 ///< Non-CD optical disks\r
59#define USB_PDT_SIMPLE_DIRECT 0x0E ///< Simplified direct access device\r
60\r
61//\r
62// Other parameters, Max carried size is 64KB.\r
63//\r
64#define USB_BOOT_MAX_CARRY_SIZE SIZE_64KB\r
65\r
66//\r
67// Retry mass command times, set by experience\r
68//\r
69#define USB_BOOT_COMMAND_RETRY 5\r
70\r
71//\r
72// Wait for unit ready command, set by experience\r
73//\r
74#define USB_BOOT_RETRY_UNIT_READY_STALL (500 * USB_MASS_1_MILLISECOND)\r
75\r
76//\r
77// Mass command timeout, refers to specification[USB20-9.2.6.1]\r
78//\r
79// USB2.0 Spec define the up-limit timeout 5s for all command. USB floppy,\r
80// USB CD-Rom and iPod devices are much slower than USB key when response\r
81// most of commands, So we set 5s as timeout here.\r
82//\r
83#define USB_BOOT_GENERAL_CMD_TIMEOUT (5 * USB_MASS_1_SECOND)\r
84\r
85//\r
86// The required commands are INQUIRY, READ CAPACITY, TEST UNIT READY,\r
87// READ10, WRITE10, and REQUEST SENSE. The BLOCK_IO protocol uses LBA\r
88// so it isn't necessary to issue MODE SENSE / READ FORMAT CAPACITY\r
89// command to retrieve the disk gemotrics.\r
90//\r
91#pragma pack(1)\r
92typedef struct {\r
93 UINT8 OpCode;\r
94 UINT8 Lun; ///< Lun (high 3 bits)\r
95 UINT8 Reserved0[2];\r
96 UINT8 AllocLen;\r
97 UINT8 Reserved1;\r
98 UINT8 Pad[6];\r
99} USB_BOOT_INQUIRY_CMD;\r
100\r
101typedef struct {\r
102 UINT8 Pdt; ///< Peripheral Device Type (low 5 bits)\r
103 UINT8 Removable; ///< Removable Media (highest bit)\r
104 UINT8 Reserved0[2];\r
105 UINT8 AddLen; ///< Additional length\r
106 UINT8 Reserved1[3];\r
107 UINT8 VendorID[8];\r
108 UINT8 ProductID[16];\r
109 UINT8 ProductRevision[4];\r
110} USB_BOOT_INQUIRY_DATA;\r
111\r
112typedef struct {\r
113 UINT8 OpCode;\r
114 UINT8 Lun;\r
115 UINT8 Reserved0[8];\r
116 UINT8 Pad[2];\r
117} USB_BOOT_READ_CAPACITY_CMD;\r
118\r
119typedef struct {\r
120 UINT8 LastLba[4];\r
121 UINT8 BlockLen[4];\r
122} USB_BOOT_READ_CAPACITY_DATA;\r
123\r
124typedef struct {\r
125 UINT8 OpCode;\r
126 UINT8 Lun;\r
127 UINT8 Reserved[4];\r
128 UINT8 Pad[6];\r
129} USB_BOOT_TEST_UNIT_READY_CMD;\r
130\r
131typedef struct {\r
132 UINT8 OpCode;\r
133 UINT8 Lun;\r
134 UINT8 PageCode;\r
135 UINT8 Reserved0[4];\r
136 UINT8 ParaListLenMsb;\r
137 UINT8 ParaListLenLsb;\r
138 UINT8 Reserved1;\r
139 UINT8 Pad[2];\r
140} USB_BOOT_MODE_SENSE10_CMD;\r
141\r
142typedef struct {\r
143 UINT8 ModeDataLenMsb;\r
144 UINT8 ModeDataLenLsb;\r
145 UINT8 Reserved0[4];\r
146 UINT8 BlkDesLenMsb;\r
147 UINT8 BlkDesLenLsb;\r
148} USB_BOOT_MODE_SENSE10_PARA_HEADER;\r
149\r
150typedef struct {\r
151 UINT8 OpCode;\r
152 UINT8 Lun; ///< Lun (High 3 bits)\r
153 UINT8 Lba[4]; ///< Logical block address\r
154 UINT8 Reserved0;\r
155 UINT8 TransferLen[2]; ///< Transfer length\r
156 UINT8 Reserverd1;\r
157 UINT8 Pad[2];\r
158} USB_BOOT_READ_WRITE_10_CMD;\r
159\r
160typedef struct {\r
161 UINT8 OpCode;\r
162 UINT8 Lun; ///< Lun (High 3 bits)\r
163 UINT8 Reserved0[2];\r
164 UINT8 AllocLen; ///< Allocation length\r
165 UINT8 Reserved1;\r
166 UINT8 Pad[6];\r
167} USB_BOOT_REQUEST_SENSE_CMD;\r
168\r
169typedef struct {\r
170 UINT8 ErrorCode;\r
171 UINT8 Reserved0;\r
172 UINT8 SenseKey; ///< Sense key (low 4 bits)\r
173 UINT8 Infor[4];\r
174 UINT8 AddLen; ///< Additional Sense length, 10\r
175 UINT8 Reserved1[4];\r
176 UINT8 Asc; ///< Additional Sense Code\r
177 UINT8 Ascq; ///< Additional Sense Code Qualifier\r
178 UINT8 Reserverd2[4];\r
179} USB_BOOT_REQUEST_SENSE_DATA;\r
180\r
181typedef struct {\r
182 UINT8 OpCode;\r
183 UINT8 Lun;\r
184 UINT8 PageCode;\r
185 UINT8 Reserved0;\r
186 UINT8 AllocateLen;\r
187 UINT8 Control;\r
188} USB_SCSI_MODE_SENSE6_CMD;\r
189\r
190typedef struct {\r
191 UINT8 ModeDataLen;\r
192 UINT8 MediumType;\r
193 UINT8 DevicePara;\r
194 UINT8 BlkDesLen;\r
195} USB_SCSI_MODE_SENSE6_PARA_HEADER;\r
196#pragma pack()\r
197\r
198//\r
199// Convert a LUN number to that in the command\r
200//\r
201#define USB_BOOT_LUN(Lun) ((Lun) << 5)\r
202\r
203//\r
204// Get the removable, PDT, and sense key bits from the command data\r
205//\r
206#define USB_BOOT_REMOVABLE(RmbByte) (((RmbByte) & BIT7) != 0)\r
207#define USB_BOOT_PDT(Pdt) ((Pdt) & 0x1f)\r
208#define USB_BOOT_SENSE_KEY(Key) ((Key) & 0x0f)\r
209\r
210/**\r
211 Get the parameters for the USB mass storage media.\r
212\r
213 This function get the parameters for the USB mass storage media,\r
214 It is used both to initialize the media during the Start() phase\r
215 of Driver Binding Protocol and to re-initialize it when the media is\r
216 changed. Although the RemoveableMedia is unlikely to change,\r
217 it is also included here.\r
218\r
219 @param UsbMass The device to retrieve disk gemotric.\r
220\r
221 @retval EFI_SUCCESS The disk gemotric is successfully retrieved.\r
222 @retval Other Failed to get the parameters.\r
223\r
224**/\r
225EFI_STATUS\r
226UsbBootGetParams (\r
227 IN USB_MASS_DEVICE *UsbMass\r
228 );\r
229\r
230/**\r
231 Execute TEST UNIT READY command to check if the device is ready.\r
232\r
233 @param UsbMass The device to test\r
234\r
235 @retval EFI_SUCCESS The device is ready.\r
236 @retval Others Device not ready.\r
237\r
238**/\r
239EFI_STATUS\r
240UsbBootIsUnitReady (\r
241 IN USB_MASS_DEVICE *UsbMass\r
242 );\r
243\r
244/**\r
245 Detect whether the removable media is present and whether it has changed.\r
246\r
247 @param UsbMass The device to check.\r
248\r
249 @retval EFI_SUCCESS The media status is successfully checked.\r
250 @retval Other Failed to detect media.\r
251\r
252**/\r
253EFI_STATUS\r
254UsbBootDetectMedia (\r
255 IN USB_MASS_DEVICE *UsbMass\r
256 );\r
257\r
258/**\r
259 Read some blocks from the device.\r
260\r
261 @param UsbMass The USB mass storage device to read from\r
262 @param Lba The start block number\r
263 @param TotalBlock Total block number to read\r
264 @param Buffer The buffer to read to\r
265\r
266 @retval EFI_SUCCESS Data are read into the buffer\r
267 @retval Others Failed to read all the data\r
268\r
269**/\r
270EFI_STATUS\r
271UsbBootReadBlocks (\r
272 IN USB_MASS_DEVICE *UsbMass,\r
273 IN UINT32 Lba,\r
274 IN UINTN TotalBlock,\r
275 OUT UINT8 *Buffer\r
276 );\r
277\r
278/**\r
279 Read or write some blocks from the device.\r
280\r
281 @param UsbMass The USB mass storage device to access\r
282 @param Write TRUE for write operation.\r
283 @param Lba The start block number\r
284 @param TotalBlock Total block number to read or write\r
285 @param Buffer The buffer to read to or write from\r
286\r
287 @retval EFI_SUCCESS Data are read into the buffer or writen into the device.\r
288 @retval Others Failed to read or write all the data\r
289\r
290**/\r
291EFI_STATUS\r
292UsbBootReadWriteBlocks (\r
293 IN USB_MASS_DEVICE *UsbMass,\r
294 IN BOOLEAN Write,\r
295 IN UINT32 Lba,\r
296 IN UINTN TotalBlock,\r
297 IN OUT UINT8 *Buffer\r
298 );\r
299\r
300/**\r
301 Read or write some blocks from the device by SCSI 16 byte cmd.\r
302\r
303 @param UsbMass The USB mass storage device to access\r
304 @param Write TRUE for write operation.\r
305 @param Lba The start block number\r
306 @param TotalBlock Total block number to read or write\r
307 @param Buffer The buffer to read to or write from\r
308\r
309 @retval EFI_SUCCESS Data are read into the buffer or writen into the device.\r
310 @retval Others Failed to read or write all the data\r
311**/\r
312EFI_STATUS\r
313UsbBootReadWriteBlocks16 (\r
314 IN USB_MASS_DEVICE *UsbMass,\r
315 IN BOOLEAN Write,\r
316 IN UINT64 Lba,\r
317 IN UINTN TotalBlock,\r
318 IN OUT UINT8 *Buffer\r
319 );\r
320\r
321/**\r
322 Use the USB clear feature control transfer to clear the endpoint stall condition.\r
323\r
324 @param UsbIo The USB I/O Protocol instance\r
325 @param EndpointAddr The endpoint to clear stall for\r
326\r
327 @retval EFI_SUCCESS The endpoint stall condition is cleared.\r
328 @retval Others Failed to clear the endpoint stall condition.\r
329\r
330**/\r
331EFI_STATUS\r
332UsbClearEndpointStall (\r
333 IN EFI_USB_IO_PROTOCOL *UsbIo,\r
334 IN UINT8 EndpointAddr\r
335 );\r
336\r
337#endif\r
338\r