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