]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.h
Sync USB modules with main trunk.
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbMassStorageDxe / UsbMassBoot.h
CommitLineData
e237e7ae 1/** @file\r
2\r
3Copyright (c) 2007, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 UsbMassBoot.h\r
15\r
16Abstract:\r
17\r
18 The definition of command and data of the USB mass storage for\r
19 bootability command set.\r
20\r
21Revision History\r
22\r
23\r
24**/\r
25\r
26#ifndef _EFI_USB_MASS_BOOT_H_\r
27#define _EFI_USB_MASS_BOOT_H_\r
28\r
29enum {\r
30 //\r
31 // The opcodes of various usb boot commands:\r
32 // INQUIRY/REQUEST_SENSE are "No Timeout Commands" as specified\r
33 // by MMC command set. Others are "Group 1 Timeout Commands". That\r
34 // is they should be retried if driver is ready.\r
35 // We can't use the Peripheral Device Type in Inquiry data to\r
36 // determine the timeout used. For example, both floppy and flash\r
37 // are likely set their PDT to 0, or Direct Access Device.\r
38 //\r
39 USB_BOOT_INQUIRY_OPCODE = 0x12,\r
40 USB_BOOT_REQUEST_SENSE_OPCODE = 0x03,\r
41\r
50fa1b3a 42 USB_BOOT_MODE_SENSE10_OPCODE = 0x5A,\r
e237e7ae 43 USB_BOOT_READ_CAPACITY_OPCODE = 0x25,\r
44 USB_BOOT_TEST_UNIT_READY_OPCODE = 0x00,\r
45 USB_BOOT_READ10_OPCODE = 0x28,\r
50fa1b3a 46 USB_BOOT_WRITE10_OPCODE = 0x2A,\r
e237e7ae 47\r
50fa1b3a 48 USB_SCSI_MODE_SENSE6_OPCODE = 0x1A,\r
49 \r
e237e7ae 50 //\r
51 // The Sense Key part of the sense data. Sense data has three levels:\r
52 // Sense key, Additional Sense Code and Additional Sense Code Qualifier\r
53 //\r
54 USB_BOOT_SENSE_NO_SENSE = 0x00, // No sense key\r
55 USB_BOOT_SENSE_RECOVERED = 0x01, // Last command succeed with recovery actions\r
56 USB_BOOT_SENSE_NOT_READY = 0x02, // Device not ready\r
57 USB_BOOT_SNESE_MEDIUM_ERROR = 0X03, // Failed probably because flaw in the media\r
58 USB_BOOT_SENSE_HARDWARE_ERROR = 0X04, // Non-recoverable hardware failure\r
59 USB_BOOT_SENSE_ILLEGAL_REQUEST = 0X05, // Illegal parameters in the request\r
60 USB_BOOT_SENSE_UNIT_ATTENTION = 0X06, // Removable medium may have been changed\r
61 USB_BOOT_SNESE_DATA_PROTECT = 0X07, // Write protected\r
62 USB_BOOT_SENSE_BLANK_CHECK = 0X08, // Blank/non-blank medium while reading/writing\r
63 USB_BOOT_SENSE_VENDOR = 0X09, // Vendor specific sense key\r
64 USB_BOOT_SENSE_ABORTED = 0X0B, // Command aborted by the device\r
65 USB_BOOT_SENSE_VOLUME_OVERFLOW = 0x0D, // Partition overflow\r
66 USB_BOOT_SENSE_MISCOMPARE = 0x0E, // Source data mis-match while verfying.\r
67\r
68 USB_BOOT_ASC_NOT_READY = 0x04,\r
e237e7ae 69 USB_BOOT_ASC_NO_MEDIA = 0x3A,\r
70 USB_BOOT_ASC_MEDIA_CHANGE = 0x28,\r
71\r
e237e7ae 72 //\r
73 // Other parameters\r
74 //\r
75 USB_BOOT_IO_BLOCKS = 64,\r
76\r
77 //\r
78 // Boot Retry times\r
79 //\r
80 USB_BOOT_COMMAND_RETRY = 5,\r
81 USB_BOOT_WAIT_RETRY = 5,\r
82\r
83 //\r
84 // Boot Stall time\r
85 //\r
86 USB_BOOT_UNIT_READY_STALL = 50 * USB_MASS_STALL_1_MS,\r
87\r
88 //\r
89 // Boot Transfer timeout\r
90 //\r
50fa1b3a 91 // USB2.0 Spec define the up-limit timeout 5s for all command. USB floppy, \r
92 // USB CD-Rom and iPod devices are much slower than USB key when reponse \r
93 // most of commands, So we set 5s as timeout here.\r
94 // \r
95 //\r
96 USB_BOOT_GENERAL_CMD_TIMEOUT = 5 * USB_MASS_STALL_1_S,\r
97 \r
e237e7ae 98 //\r
99 // Supported PDT codes, or Peripheral Device Type\r
100 //\r
101 USB_PDT_DIRECT_ACCESS = 0x00, // Direct access device\r
102 USB_PDT_CDROM = 0x05, // CDROM\r
103 USB_PDT_OPTICAL = 0x07, // Non-CD optical disks\r
c52fa98c 104 USB_PDT_SIMPLE_DIRECT = 0x0E // Simplified direct access device\r
e237e7ae 105};\r
106\r
107//\r
108// The required commands are INQUIRY, READ CAPACITY, TEST UNIT READY,\r
109// READ10, WRITE10, and REQUEST SENSE. The BLOCK_IO protocol uses LBA\r
110// so it isn't necessary to issue MODE SENSE / READ FORMAT CAPACITY\r
111// command to retrieve the disk gemotrics.\r
112//\r
113#pragma pack(1)\r
114typedef struct {\r
115 UINT8 OpCode;\r
116 UINT8 Lun; // Lun (high 3 bits)\r
117 UINT8 Reserved0[2];\r
118 UINT8 AllocLen;\r
119 UINT8 Reserved1;\r
120 UINT8 Pad[6];\r
121} USB_BOOT_INQUIRY_CMD;\r
122\r
123typedef struct {\r
124 UINT8 Pdt; // Peripheral Device Type (low 5 bits)\r
125 UINT8 Removable; // Removable Media (highest bit)\r
126 UINT8 Reserved0[2];\r
127 UINT8 AddLen; // Additional length\r
128 UINT8 Reserved1[3];\r
129 UINT8 VendorID[8];\r
130 UINT8 ProductID[16];\r
131 UINT8 ProductRevision[4];\r
132} USB_BOOT_INQUIRY_DATA;\r
133\r
134typedef struct {\r
135 UINT8 OpCode;\r
136 UINT8 Lun;\r
137 UINT8 Reserved0[8];\r
138 UINT8 Pad[2];\r
139} USB_BOOT_READ_CAPACITY_CMD;\r
140\r
141typedef struct {\r
142 UINT8 LastLba[4];\r
143 UINT8 BlockLen[4];\r
144} USB_BOOT_READ_CAPACITY_DATA;\r
145\r
146typedef struct {\r
147 UINT8 OpCode;\r
148 UINT8 Lun;\r
149 UINT8 Reserved[4];\r
150 UINT8 Pad[6];\r
151} USB_BOOT_TEST_UNIT_READY_CMD;\r
152\r
153typedef struct {\r
154 UINT8 OpCode;\r
155 UINT8 Lun;\r
156 UINT8 PageCode;\r
157 UINT8 Reserved0[4];\r
158 UINT8 ParaListLenMsb;\r
159 UINT8 ParaListLenLsb;\r
160 UINT8 Reserved1;\r
161 UINT8 Pad[2];\r
50fa1b3a 162} USB_BOOT_MODE_SENSE10_CMD;\r
e237e7ae 163\r
164typedef struct {\r
165 UINT8 ModeDataLenMsb;\r
166 UINT8 ModeDataLenLsb;\r
167 UINT8 Reserved0[4];\r
168 UINT8 BlkDesLenMsb;\r
169 UINT8 BlkDesLenLsb;\r
50fa1b3a 170} USB_BOOT_MODE_SENSE10_PARA_HEADER;\r
e237e7ae 171\r
172typedef struct {\r
173 UINT8 OpCode;\r
174 UINT8 Lun; // Lun (High 3 bits)\r
175 UINT8 Lba[4]; // Logical block address\r
176 UINT8 Reserved0;\r
177 UINT8 TransferLen[2]; // Transfer length\r
178 UINT8 Reserverd1;\r
179 UINT8 Pad[2];\r
180} USB_BOOT_READ10_CMD;\r
181\r
182typedef struct {\r
183 UINT8 OpCode;\r
184 UINT8 Lun;\r
185 UINT8 Lba[4];\r
186 UINT8 Reserved0;\r
187 UINT8 TransferLen[2];\r
188 UINT8 Reserverd1;\r
189 UINT8 Pad[2];\r
190} USB_BOOT_WRITE10_CMD;\r
191\r
192typedef struct {\r
193 UINT8 OpCode;\r
194 UINT8 Lun; // Lun (High 3 bits)\r
195 UINT8 Reserved0[2];\r
196 UINT8 AllocLen; // Allocation length\r
197 UINT8 Reserved1;\r
198 UINT8 Pad[6];\r
199} USB_BOOT_REQUEST_SENSE_CMD;\r
200\r
201typedef struct {\r
202 UINT8 ErrorCode;\r
203 UINT8 Reserved0;\r
204 UINT8 SenseKey; // Sense key (low 4 bits)\r
205 UINT8 Infor[4];\r
206 UINT8 AddLen; // Additional Sense length, 10\r
207 UINT8 Reserved1[4];\r
208 UINT8 ASC; // Additional Sense Code\r
209 UINT8 ASCQ; // Additional Sense Code Qualifier\r
210 UINT8 Reserverd2[4];\r
211} USB_BOOT_REQUEST_SENSE_DATA;\r
50fa1b3a 212\r
213typedef struct {\r
214 UINT8 OpCode;\r
215 UINT8 Lun;\r
216 UINT8 PageCode;\r
217 UINT8 Reserved0;\r
218 UINT8 AllocateLen;\r
219 UINT8 Control;\r
220} USB_SCSI_MODE_SENSE6_CMD;\r
221\r
222typedef struct {\r
223 UINT8 ModeDataLen;\r
224 UINT8 MediumType;\r
225 UINT8 DevicePara;\r
226 UINT8 BlkDesLen;\r
227} USB_SCSI_MODE_SENSE6_PARA_HEADER;\r
e237e7ae 228#pragma pack()\r
229\r
230//\r
231// Convert a LUN number to that in the command\r
232//\r
233#define USB_BOOT_LUN(Lun) ((Lun) << 5)\r
234\r
235//\r
236// Get the removable, PDT, and sense key bits from the command data\r
237//\r
238#define USB_BOOT_REMOVABLE(RmbByte) (((RmbByte) & 0x80) != 0)\r
239#define USB_BOOT_PDT(Pdt) ((Pdt) & 0x1f)\r
240#define USB_BOOT_SENSE_KEY(Key) ((Key) & 0x0f)\r
241\r
242//\r
243// Swap the byte sequence of a UINT32. Intel CPU uses little endian\r
244// in UEFI environment, but USB boot uses big endian.\r
245//\r
246#define USB_BOOT_SWAP32(Data32) \\r
247 ((((Data32) & 0x000000ff) << 24) | (((Data32) & 0xff000000) >> 24) | \\r
248 (((Data32) & 0x0000ff00) << 8) | (((Data32) & 0x00ff0000) >> 8))\r
249\r
250#define USB_BOOT_SWAP16(Data16) \\r
251 ((((Data16) & 0x00ff) << 8) | (((Data16) & 0xff00) >> 8))\r
252\r
253EFI_STATUS\r
254UsbBootGetParams (\r
255 IN USB_MASS_DEVICE *UsbMass\r
256 );\r
257\r
258EFI_STATUS\r
259UsbBootIsUnitReady (\r
260 IN USB_MASS_DEVICE *UsbMass\r
261 );\r
262\r
263EFI_STATUS\r
264UsbBootDetectMedia (\r
265 IN USB_MASS_DEVICE *UsbMass\r
266 );\r
267\r
268EFI_STATUS\r
269UsbBootReadBlocks (\r
270 IN USB_MASS_DEVICE *UsbMass,\r
271 IN UINT32 Lba,\r
272 IN UINTN TotalBlock,\r
273 OUT UINT8 *Buffer\r
274 );\r
275\r
276EFI_STATUS\r
277UsbBootWriteBlocks (\r
278 IN USB_MASS_DEVICE *UsbMass,\r
279 IN UINT32 Lba,\r
280 IN UINTN TotalBlock,\r
281 OUT UINT8 *Buffer\r
282 );\r
283#endif\r
284\r