3 Copyright (c) 2007, Intel Corporation
4 All rights reserved. This program and the accompanying materials
5 are licensed and made available under the terms and conditions of the BSD License
6 which accompanies this distribution. The full text of the license may be found at
7 http://opensource.org/licenses/bsd-license.php
9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 The definition of command and data of the USB mass storage for
19 bootability command set.
26 #ifndef _EFI_USB_MASS_BOOT_H_
27 #define _EFI_USB_MASS_BOOT_H_
31 // The opcodes of various usb boot commands:
32 // INQUIRY/REQUEST_SENSE are "No Timeout Commands" as specified
33 // by MMC command set. Others are "Group 1 Timeout Commands". That
34 // is they should be retried if driver is ready.
35 // We can't use the Peripheral Device Type in Inquiry data to
36 // determine the timeout used. For example, both floppy and flash
37 // are likely set their PDT to 0, or Direct Access Device.
39 USB_BOOT_INQUIRY_OPCODE
= 0x12,
40 USB_BOOT_REQUEST_SENSE_OPCODE
= 0x03,
41 USB_BOOT_MODE_SENSE10_OPCODE
= 0x5A,
42 USB_BOOT_READ_CAPACITY_OPCODE
= 0x25,
43 USB_BOOT_TEST_UNIT_READY_OPCODE
= 0x00,
44 USB_BOOT_READ10_OPCODE
= 0x28,
45 USB_BOOT_WRITE10_OPCODE
= 0x2A,
47 USB_SCSI_MODE_SENSE6_OPCODE
= 0x1A,
50 // The Sense Key part of the sense data. Sense data has three levels:
51 // Sense key, Additional Sense Code and Additional Sense Code Qualifier
53 USB_BOOT_SENSE_NO_SENSE
= 0x00, // No sense key
54 USB_BOOT_SENSE_RECOVERED
= 0x01, // Last command succeed with recovery actions
55 USB_BOOT_SENSE_NOT_READY
= 0x02, // Device not ready
56 USB_BOOT_SNESE_MEDIUM_ERROR
= 0X03, // Failed probably because flaw in the media
57 USB_BOOT_SENSE_HARDWARE_ERROR
= 0X04, // Non-recoverable hardware failure
58 USB_BOOT_SENSE_ILLEGAL_REQUEST
= 0X05, // Illegal parameters in the request
59 USB_BOOT_SENSE_UNIT_ATTENTION
= 0X06, // Removable medium may have been changed
60 USB_BOOT_SNESE_DATA_PROTECT
= 0X07, // Write protected
61 USB_BOOT_SENSE_BLANK_CHECK
= 0X08, // Blank/non-blank medium while reading/writing
62 USB_BOOT_SENSE_VENDOR
= 0X09, // Vendor specific sense key
63 USB_BOOT_SENSE_ABORTED
= 0X0B, // Command aborted by the device
64 USB_BOOT_SENSE_VOLUME_OVERFLOW
= 0x0D, // Partition overflow
65 USB_BOOT_SENSE_MISCOMPARE
= 0x0E, // Source data mis-match while verfying.
67 USB_BOOT_ASC_NOT_READY
= 0x04,
68 USB_BOOT_ASC_NO_MEDIA
= 0x3A,
69 USB_BOOT_ASC_MEDIA_CHANGE
= 0x28,
72 // Supported PDT codes, or Peripheral Device Type
74 USB_PDT_DIRECT_ACCESS
= 0x00, // Direct access device
75 USB_PDT_CDROM
= 0x05, // CDROM
76 USB_PDT_OPTICAL
= 0x07, // Non-CD optical disks
77 USB_PDT_SIMPLE_DIRECT
= 0x0E, // Simplified direct access device
80 // Other parameters, Max carried size is 512B * 128 = 64KB
82 USB_BOOT_IO_BLOCKS
= 128,
85 // Retry mass command times, set by experience
87 USB_BOOT_COMMAND_RETRY
= 5,
88 USB_BOOT_INIT_MEDIA_RETRY
= 5,
91 // Wait for unit ready command, set by experience
93 USB_BOOT_RETRY_UNIT_READY_STALL
= 500 * USB_MASS_1_MILLISECOND
,
96 // Mass command timeout, refers to specification[USB20-9.2.6.1]
98 // USB2.0 Spec define the up-limit timeout 5s for all command. USB floppy,
99 // USB CD-Rom and iPod devices are much slower than USB key when reponse
100 // most of commands, So we set 5s as timeout here.
103 USB_BOOT_GENERAL_CMD_TIMEOUT
= 5 * USB_MASS_1_SECOND
107 // The required commands are INQUIRY, READ CAPACITY, TEST UNIT READY,
108 // READ10, WRITE10, and REQUEST SENSE. The BLOCK_IO protocol uses LBA
109 // so it isn't necessary to issue MODE SENSE / READ FORMAT CAPACITY
110 // command to retrieve the disk gemotrics.
115 UINT8 Lun
; // Lun (high 3 bits)
120 } USB_BOOT_INQUIRY_CMD
;
123 UINT8 Pdt
; // Peripheral Device Type (low 5 bits)
124 UINT8 Removable
; // Removable Media (highest bit)
126 UINT8 AddLen
; // Additional length
130 UINT8 ProductRevision
[4];
131 } USB_BOOT_INQUIRY_DATA
;
138 } USB_BOOT_READ_CAPACITY_CMD
;
143 } USB_BOOT_READ_CAPACITY_DATA
;
150 } USB_BOOT_TEST_UNIT_READY_CMD
;
157 UINT8 ParaListLenMsb
;
158 UINT8 ParaListLenLsb
;
161 } USB_BOOT_MODE_SENSE10_CMD
;
164 UINT8 ModeDataLenMsb
;
165 UINT8 ModeDataLenLsb
;
169 } USB_BOOT_MODE_SENSE10_PARA_HEADER
;
173 UINT8 Lun
; // Lun (High 3 bits)
174 UINT8 Lba
[4]; // Logical block address
176 UINT8 TransferLen
[2]; // Transfer length
179 } USB_BOOT_READ10_CMD
;
186 UINT8 TransferLen
[2];
189 } USB_BOOT_WRITE10_CMD
;
193 UINT8 Lun
; // Lun (High 3 bits)
195 UINT8 AllocLen
; // Allocation length
198 } USB_BOOT_REQUEST_SENSE_CMD
;
203 UINT8 SenseKey
; // Sense key (low 4 bits)
205 UINT8 AddLen
; // Additional Sense length, 10
207 UINT8 ASC
; // Additional Sense Code
208 UINT8 ASCQ
; // Additional Sense Code Qualifier
210 } USB_BOOT_REQUEST_SENSE_DATA
;
219 } USB_SCSI_MODE_SENSE6_CMD
;
226 } USB_SCSI_MODE_SENSE6_PARA_HEADER
;
230 // Convert a LUN number to that in the command
232 #define USB_BOOT_LUN(Lun) ((Lun) << 5)
235 // Get the removable, PDT, and sense key bits from the command data
237 #define USB_BOOT_REMOVABLE(RmbByte) (((RmbByte) & 0x80) != 0)
238 #define USB_BOOT_PDT(Pdt) ((Pdt) & 0x1f)
239 #define USB_BOOT_SENSE_KEY(Key) ((Key) & 0x0f)
242 // Swap the byte sequence of a UINT32. Intel CPU uses little endian
243 // in UEFI environment, but USB boot uses big endian.
245 #define USB_BOOT_SWAP32(Data32) \
246 ((((Data32) & 0x000000ff) << 24) | (((Data32) & 0xff000000) >> 24) | \
247 (((Data32) & 0x0000ff00) << 8) | (((Data32) & 0x00ff0000) >> 8))
249 #define USB_BOOT_SWAP16(Data16) \
250 ((((Data16) & 0x00ff) << 8) | (((Data16) & 0xff00) >> 8))
254 IN USB_MASS_DEVICE
*UsbMass
259 IN USB_MASS_DEVICE
*UsbMass
264 IN USB_MASS_DEVICE
*UsbMass
269 IN USB_MASS_DEVICE
*UsbMass
,
277 IN USB_MASS_DEVICE
*UsbMass
,