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,
42 USB_BOOT_MODE_SENSE10_OPCODE
= 0x5a,
43 USB_BOOT_READ_CAPACITY_OPCODE
= 0x25,
44 USB_BOOT_TEST_UNIT_READY_OPCODE
= 0x00,
45 USB_BOOT_READ10_OPCODE
= 0x28,
46 USB_BOOT_WRITE10_OPCODE
= 0x2a,
49 // The Sense Key part of the sense data. Sense data has three levels:
50 // Sense key, Additional Sense Code and Additional Sense Code Qualifier
52 USB_BOOT_SENSE_NO_SENSE
= 0x00, // No sense key
53 USB_BOOT_SENSE_RECOVERED
= 0x01, // Last command succeed with recovery actions
54 USB_BOOT_SENSE_NOT_READY
= 0x02, // Device not ready
55 USB_BOOT_SNESE_MEDIUM_ERROR
= 0X03, // Failed probably because flaw in the media
56 USB_BOOT_SENSE_HARDWARE_ERROR
= 0X04, // Non-recoverable hardware failure
57 USB_BOOT_SENSE_ILLEGAL_REQUEST
= 0X05, // Illegal parameters in the request
58 USB_BOOT_SENSE_UNIT_ATTENTION
= 0X06, // Removable medium may have been changed
59 USB_BOOT_SNESE_DATA_PROTECT
= 0X07, // Write protected
60 USB_BOOT_SENSE_BLANK_CHECK
= 0X08, // Blank/non-blank medium while reading/writing
61 USB_BOOT_SENSE_VENDOR
= 0X09, // Vendor specific sense key
62 USB_BOOT_SENSE_ABORTED
= 0X0B, // Command aborted by the device
63 USB_BOOT_SENSE_VOLUME_OVERFLOW
= 0x0D, // Partition overflow
64 USB_BOOT_SENSE_MISCOMPARE
= 0x0E, // Source data mis-match while verfying.
66 USB_BOOT_ASC_NOT_READY
= 0x04,
67 USB_BOOT_ASC_MEDIA_UPSIDE_DOWN
= 0x06,
68 USB_BOOT_ASC_NO_MEDIA
= 0x3A,
69 USB_BOOT_ASC_MEDIA_CHANGE
= 0x28,
71 USB_BOOT_ASCQ_IN_PROGRESS
= 0x01,
72 USB_BOOT_ASCQ_DEVICE_BUSY
= 0xFF,
77 USB_BOOT_IO_BLOCKS
= 64,
82 USB_BOOT_COMMAND_RETRY
= 5,
83 USB_BOOT_WAIT_RETRY
= 5,
88 USB_BOOT_UNIT_READY_STALL
= 50 * USB_MASS_STALL_1_MS
,
91 // Boot Transfer timeout
93 USB_BOOT_GENERAL_BLOCK_TIMEOUT
= 200 * USB_MASS_STALL_1_MS
,
94 USB_BOOT_OPTICAL_BLOCK_TIMEOUT
= 1 * USB_MASS_STALL_1_S
,
95 USB_BOOT_GENERAL_CMD_TIMEOUT
= 1 * USB_MASS_STALL_1_S
,
96 USB_BOOT_INQUIRY_CMD_TIMEOUT
= 3 * USB_MASS_STALL_1_S
,
99 // Supported PDT codes, or Peripheral Device Type
101 USB_PDT_DIRECT_ACCESS
= 0x00, // Direct access device
102 USB_PDT_CDROM
= 0x05, // CDROM
103 USB_PDT_OPTICAL
= 0x07, // Non-CD optical disks
104 USB_PDT_SIMPLE_DIRECT
= 0x0E, // Simplified direct access device
108 // The required commands are INQUIRY, READ CAPACITY, TEST UNIT READY,
109 // READ10, WRITE10, and REQUEST SENSE. The BLOCK_IO protocol uses LBA
110 // so it isn't necessary to issue MODE SENSE / READ FORMAT CAPACITY
111 // command to retrieve the disk gemotrics.
116 UINT8 Lun
; // Lun (high 3 bits)
121 } USB_BOOT_INQUIRY_CMD
;
124 UINT8 Pdt
; // Peripheral Device Type (low 5 bits)
125 UINT8 Removable
; // Removable Media (highest bit)
127 UINT8 AddLen
; // Additional length
131 UINT8 ProductRevision
[4];
132 } USB_BOOT_INQUIRY_DATA
;
139 } USB_BOOT_READ_CAPACITY_CMD
;
144 } USB_BOOT_READ_CAPACITY_DATA
;
151 } USB_BOOT_TEST_UNIT_READY_CMD
;
158 UINT8 ParaListLenMsb
;
159 UINT8 ParaListLenLsb
;
162 } USB_BOOT_MODE_SENSE_CMD
;
165 UINT8 ModeDataLenMsb
;
166 UINT8 ModeDataLenLsb
;
170 } USB_BOOT_MODE_PARA_HEADER
;
174 UINT8 Lun
; // Lun (High 3 bits)
175 UINT8 Lba
[4]; // Logical block address
177 UINT8 TransferLen
[2]; // Transfer length
180 } USB_BOOT_READ10_CMD
;
187 UINT8 TransferLen
[2];
190 } USB_BOOT_WRITE10_CMD
;
194 UINT8 Lun
; // Lun (High 3 bits)
196 UINT8 AllocLen
; // Allocation length
199 } USB_BOOT_REQUEST_SENSE_CMD
;
204 UINT8 SenseKey
; // Sense key (low 4 bits)
206 UINT8 AddLen
; // Additional Sense length, 10
208 UINT8 ASC
; // Additional Sense Code
209 UINT8 ASCQ
; // Additional Sense Code Qualifier
211 } USB_BOOT_REQUEST_SENSE_DATA
;
215 // Convert a LUN number to that in the command
217 #define USB_BOOT_LUN(Lun) ((Lun) << 5)
220 // Get the removable, PDT, and sense key bits from the command data
222 #define USB_BOOT_REMOVABLE(RmbByte) (((RmbByte) & 0x80) != 0)
223 #define USB_BOOT_PDT(Pdt) ((Pdt) & 0x1f)
224 #define USB_BOOT_SENSE_KEY(Key) ((Key) & 0x0f)
227 // Swap the byte sequence of a UINT32. Intel CPU uses little endian
228 // in UEFI environment, but USB boot uses big endian.
230 #define USB_BOOT_SWAP32(Data32) \
231 ((((Data32) & 0x000000ff) << 24) | (((Data32) & 0xff000000) >> 24) | \
232 (((Data32) & 0x0000ff00) << 8) | (((Data32) & 0x00ff0000) >> 8))
234 #define USB_BOOT_SWAP16(Data16) \
235 ((((Data16) & 0x00ff) << 8) | (((Data16) & 0xff00) >> 8))
239 IN USB_MASS_DEVICE
*UsbMass
244 IN USB_MASS_DEVICE
*UsbMass
249 IN USB_MASS_DEVICE
*UsbMass
254 IN USB_MASS_DEVICE
*UsbMass
,
262 IN USB_MASS_DEVICE
*UsbMass
,