]> git.proxmox.com Git - mirror_edk2.git/blame - MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.h
fixed memcpy link issue.
[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
42 USB_BOOT_MODE_SENSE10_OPCODE = 0x5a,\r
43 USB_BOOT_READ_CAPACITY_OPCODE = 0x25,\r
44 USB_BOOT_TEST_UNIT_READY_OPCODE = 0x00,\r
45 USB_BOOT_READ10_OPCODE = 0x28,\r
46 USB_BOOT_WRITE10_OPCODE = 0x2a,\r
47\r
48 //\r
49 // The Sense Key part of the sense data. Sense data has three levels:\r
50 // Sense key, Additional Sense Code and Additional Sense Code Qualifier\r
51 //\r
52 USB_BOOT_SENSE_NO_SENSE = 0x00, // No sense key\r
53 USB_BOOT_SENSE_RECOVERED = 0x01, // Last command succeed with recovery actions\r
54 USB_BOOT_SENSE_NOT_READY = 0x02, // Device not ready\r
55 USB_BOOT_SNESE_MEDIUM_ERROR = 0X03, // Failed probably because flaw in the media\r
56 USB_BOOT_SENSE_HARDWARE_ERROR = 0X04, // Non-recoverable hardware failure\r
57 USB_BOOT_SENSE_ILLEGAL_REQUEST = 0X05, // Illegal parameters in the request\r
58 USB_BOOT_SENSE_UNIT_ATTENTION = 0X06, // Removable medium may have been changed\r
59 USB_BOOT_SNESE_DATA_PROTECT = 0X07, // Write protected\r
60 USB_BOOT_SENSE_BLANK_CHECK = 0X08, // Blank/non-blank medium while reading/writing\r
61 USB_BOOT_SENSE_VENDOR = 0X09, // Vendor specific sense key\r
62 USB_BOOT_SENSE_ABORTED = 0X0B, // Command aborted by the device\r
63 USB_BOOT_SENSE_VOLUME_OVERFLOW = 0x0D, // Partition overflow\r
64 USB_BOOT_SENSE_MISCOMPARE = 0x0E, // Source data mis-match while verfying.\r
65\r
66 USB_BOOT_ASC_NOT_READY = 0x04,\r
67 USB_BOOT_ASC_MEDIA_UPSIDE_DOWN = 0x06,\r
68 USB_BOOT_ASC_NO_MEDIA = 0x3A,\r
69 USB_BOOT_ASC_MEDIA_CHANGE = 0x28,\r
70\r
71 USB_BOOT_ASCQ_IN_PROGRESS = 0x01,\r
72 USB_BOOT_ASCQ_DEVICE_BUSY = 0xFF,\r
73\r
74 //\r
75 // Other parameters\r
76 //\r
77 USB_BOOT_IO_BLOCKS = 64,\r
78\r
79 //\r
80 // Boot Retry times\r
81 //\r
82 USB_BOOT_COMMAND_RETRY = 5,\r
83 USB_BOOT_WAIT_RETRY = 5,\r
84\r
85 //\r
86 // Boot Stall time\r
87 //\r
88 USB_BOOT_UNIT_READY_STALL = 50 * USB_MASS_STALL_1_MS,\r
89\r
90 //\r
91 // Boot Transfer timeout\r
92 //\r
93 USB_BOOT_GENERAL_BLOCK_TIMEOUT = 200 * USB_MASS_STALL_1_MS,\r
94 USB_BOOT_OPTICAL_BLOCK_TIMEOUT = 1 * USB_MASS_STALL_1_S,\r
95 USB_BOOT_GENERAL_CMD_TIMEOUT = 1 * USB_MASS_STALL_1_S,\r
96 USB_BOOT_INQUIRY_CMD_TIMEOUT = 3 * USB_MASS_STALL_1_S,\r
97\r
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
104 USB_PDT_SIMPLE_DIRECT = 0x0E, // Simplified direct access device\r
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
162} USB_BOOT_MODE_SENSE_CMD;\r
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
170} USB_BOOT_MODE_PARA_HEADER;\r
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
212#pragma pack()\r
213\r
214//\r
215// Convert a LUN number to that in the command\r
216//\r
217#define USB_BOOT_LUN(Lun) ((Lun) << 5)\r
218\r
219//\r
220// Get the removable, PDT, and sense key bits from the command data\r
221//\r
222#define USB_BOOT_REMOVABLE(RmbByte) (((RmbByte) & 0x80) != 0)\r
223#define USB_BOOT_PDT(Pdt) ((Pdt) & 0x1f)\r
224#define USB_BOOT_SENSE_KEY(Key) ((Key) & 0x0f)\r
225\r
226//\r
227// Swap the byte sequence of a UINT32. Intel CPU uses little endian\r
228// in UEFI environment, but USB boot uses big endian.\r
229//\r
230#define USB_BOOT_SWAP32(Data32) \\r
231 ((((Data32) & 0x000000ff) << 24) | (((Data32) & 0xff000000) >> 24) | \\r
232 (((Data32) & 0x0000ff00) << 8) | (((Data32) & 0x00ff0000) >> 8))\r
233\r
234#define USB_BOOT_SWAP16(Data16) \\r
235 ((((Data16) & 0x00ff) << 8) | (((Data16) & 0xff00) >> 8))\r
236\r
237EFI_STATUS\r
238UsbBootGetParams (\r
239 IN USB_MASS_DEVICE *UsbMass\r
240 );\r
241\r
242EFI_STATUS\r
243UsbBootIsUnitReady (\r
244 IN USB_MASS_DEVICE *UsbMass\r
245 );\r
246\r
247EFI_STATUS\r
248UsbBootDetectMedia (\r
249 IN USB_MASS_DEVICE *UsbMass\r
250 );\r
251\r
252EFI_STATUS\r
253UsbBootReadBlocks (\r
254 IN USB_MASS_DEVICE *UsbMass,\r
255 IN UINT32 Lba,\r
256 IN UINTN TotalBlock,\r
257 OUT UINT8 *Buffer\r
258 );\r
259\r
260EFI_STATUS\r
261UsbBootWriteBlocks (\r
262 IN USB_MASS_DEVICE *UsbMass,\r
263 IN UINT32 Lba,\r
264 IN UINTN TotalBlock,\r
265 OUT UINT8 *Buffer\r
266 );\r
267#endif\r
268\r