]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Bus/Usb/UsbMassStorageDxe/UsbMassBoot.h
MdeModulePkg: Apply uncrustify changes
[mirror_edk2.git] / MdeModulePkg / Bus / Usb / UsbMassStorageDxe / UsbMassBoot.h
index cd66d825ef2e8c9a2d477b7eff134387498fdcd6..6722c3b00321aadff4b8d4ee56d6dec2a12b592a 100644 (file)
   Definition of the command set of USB Mass Storage Specification\r
   for Bootability, Revision 1.0.\r
 \r
-Copyright (c) 2007 - 2008, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
-are licensed and made available under the terms and conditions of the BSD License\r
-which accompanies this distribution.  The full text of the license may be found at\r
-http://opensource.org/licenses/bsd-license.php\r
-\r
-THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
-WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
+Copyright (c) 2007 - 2018, Intel Corporation. All rights reserved.<BR>\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
 \r
 **/\r
 \r
 #ifndef _EFI_USB_MASS_BOOT_H_\r
 #define _EFI_USB_MASS_BOOT_H_\r
 \r
-#include "UsbMass.h"\r
-\r
-typedef enum {\r
-  //\r
-  // The opcodes of various USB boot commands:\r
-  // INQUIRY/REQUEST_SENSE are "No Timeout Commands" as specified\r
-  // by Multi-Media Commands (MMC) set.\r
-  // Others are "Group 1 Timeout Commands". That is,\r
-  // they should be retried if driver is ready. \r
-  //\r
-  USB_BOOT_INQUIRY_OPCODE         = 0x12,\r
-  USB_BOOT_REQUEST_SENSE_OPCODE   = 0x03,\r
-  USB_BOOT_MODE_SENSE10_OPCODE    = 0x5A,\r
-  USB_BOOT_READ_CAPACITY_OPCODE   = 0x25,\r
-  USB_BOOT_TEST_UNIT_READY_OPCODE = 0x00,\r
-  USB_BOOT_READ10_OPCODE          = 0x28,\r
-  USB_BOOT_WRITE10_OPCODE         = 0x2A,\r
-\r
-  USB_SCSI_MODE_SENSE6_OPCODE     = 0x1A,\r
-  \r
-  //\r
-  // The Sense Key part of the sense data. Sense data has three levels:\r
-  // Sense key, Additional Sense Code and Additional Sense Code Qualifier\r
-  //\r
-  USB_BOOT_SENSE_NO_SENSE         = 0x00, ///< No sense key\r
-  USB_BOOT_SENSE_RECOVERED        = 0x01, ///< Last command succeed with recovery actions\r
-  USB_BOOT_SENSE_NOT_READY        = 0x02, ///< Device not ready\r
-  USB_BOOT_SNESE_MEDIUM_ERROR     = 0X03, ///< Failed probably because flaw in the media\r
-  USB_BOOT_SENSE_HARDWARE_ERROR   = 0X04, ///< Non-recoverable hardware failure\r
-  USB_BOOT_SENSE_ILLEGAL_REQUEST  = 0X05, ///< Illegal parameters in the request\r
-  USB_BOOT_SENSE_UNIT_ATTENTION   = 0X06, ///< Removable medium may have been changed\r
-  USB_BOOT_SENSE_DATA_PROTECT     = 0X07, ///< Write protected\r
-  USB_BOOT_SENSE_BLANK_CHECK      = 0X08, ///< Blank/non-blank medium while reading/writing\r
-  USB_BOOT_SENSE_VENDOR           = 0X09, ///< Vendor specific sense key\r
-  USB_BOOT_SENSE_ABORTED          = 0X0B, ///< Command aborted by the device\r
-  USB_BOOT_SENSE_VOLUME_OVERFLOW  = 0x0D, ///< Partition overflow\r
-  USB_BOOT_SENSE_MISCOMPARE       = 0x0E, ///< Source data mis-match while verfying.\r
-\r
-  USB_BOOT_ASC_NOT_READY          = 0x04,\r
-  USB_BOOT_ASC_NO_MEDIA           = 0x3A,\r
-  USB_BOOT_ASC_MEDIA_CHANGE       = 0x28,\r
-\r
-  //\r
-  // Supported PDT codes, or Peripheral Device Type\r
-  //\r
-  USB_PDT_DIRECT_ACCESS           = 0x00,       ///< Direct access device\r
-  USB_PDT_CDROM                   = 0x05,       ///< CDROM\r
-  USB_PDT_OPTICAL                 = 0x07,       ///< Non-CD optical disks\r
-  USB_PDT_SIMPLE_DIRECT           = 0x0E,       ///< Simplified direct access device\r
-  \r
-  //\r
-  // Other parameters, Max carried size is 512B * 128 = 64KB\r
-  //\r
-  USB_BOOT_IO_BLOCKS              = 128,\r
-\r
-  //\r
-  // Retry mass command times, set by experience\r
-  //\r
-  USB_BOOT_COMMAND_RETRY          = 5,\r
-  USB_BOOT_INIT_MEDIA_RETRY       = 5,\r
-\r
-  //\r
-  // Wait for unit ready command, set by experience\r
-  //\r
-  USB_BOOT_RETRY_UNIT_READY_STALL = 500 * USB_MASS_1_MILLISECOND,\r
-\r
-  //\r
-  // Mass command timeout, refers to specification[USB20-9.2.6.1]\r
-  //\r
-  // USB2.0 Spec define the up-limit timeout 5s for all command. USB floppy, \r
-  // USB CD-Rom and iPod devices are much slower than USB key when reponse \r
-  // most of commands, So we set 5s as timeout here.\r
-  // \r
-  USB_BOOT_GENERAL_CMD_TIMEOUT    = 5 * USB_MASS_1_SECOND\r
-}USB_BOOT_OPTCODE;\r
+//\r
+// The opcodes of various USB boot commands:\r
+// INQUIRY/REQUEST_SENSE are "No Timeout Commands" as specified\r
+// by Multi-Media Commands (MMC) set.\r
+// Others are "Group 1 Timeout Commands". That is,\r
+// they should be retried if driver is ready.\r
+//\r
+#define USB_BOOT_INQUIRY_OPCODE          0x12\r
+#define USB_BOOT_REQUEST_SENSE_OPCODE    0x03\r
+#define USB_BOOT_MODE_SENSE10_OPCODE     0x5A\r
+#define USB_BOOT_READ_CAPACITY_OPCODE    0x25\r
+#define USB_BOOT_TEST_UNIT_READY_OPCODE  0x00\r
+#define USB_BOOT_READ10_OPCODE           0x28\r
+#define USB_BOOT_WRITE10_OPCODE          0x2A\r
+\r
+#define USB_SCSI_MODE_SENSE6_OPCODE  0x1A\r
+\r
+//\r
+// The Sense Key part of the sense data. Sense data has three levels:\r
+// Sense key, Additional Sense Code and Additional Sense Code Qualifier\r
+//\r
+#define USB_BOOT_SENSE_NO_SENSE         0x00 ///< No sense key\r
+#define USB_BOOT_SENSE_RECOVERED        0x01 ///< Last command succeed with recovery actions\r
+#define USB_BOOT_SENSE_NOT_READY        0x02 ///< Device not ready\r
+#define USB_BOOT_SNESE_MEDIUM_ERROR     0X03 ///< Failed probably because flaw in the media\r
+#define USB_BOOT_SENSE_HARDWARE_ERROR   0X04 ///< Non-recoverable hardware failure\r
+#define USB_BOOT_SENSE_ILLEGAL_REQUEST  0X05 ///< Illegal parameters in the request\r
+#define USB_BOOT_SENSE_UNIT_ATTENTION   0X06 ///< Removable medium may have been changed\r
+#define USB_BOOT_SENSE_DATA_PROTECT     0X07 ///< Write protected\r
+#define USB_BOOT_SENSE_BLANK_CHECK      0X08 ///< Blank/non-blank medium while reading/writing\r
+#define USB_BOOT_SENSE_VENDOR           0X09 ///< Vendor specific sense key\r
+#define USB_BOOT_SENSE_ABORTED          0X0B ///< Command aborted by the device\r
+#define USB_BOOT_SENSE_VOLUME_OVERFLOW  0x0D ///< Partition overflow\r
+#define USB_BOOT_SENSE_MISCOMPARE       0x0E ///< Source data mis-match while verfying.\r
+\r
+#define USB_BOOT_ASC_NO_ADDITIONAL_SENSE_INFORMATION  0x00\r
+#define USB_BOOT_ASC_NOT_READY                        0x04\r
+#define USB_BOOT_ASC_NO_MEDIA                         0x3A\r
+#define USB_BOOT_ASC_MEDIA_CHANGE                     0x28\r
+\r
+//\r
+// Supported PDT codes, or Peripheral Device Type\r
+//\r
+#define USB_PDT_DIRECT_ACCESS  0x00                ///< Direct access device\r
+#define USB_PDT_CDROM          0x05                ///< CDROM\r
+#define USB_PDT_OPTICAL        0x07                ///< Non-CD optical disks\r
+#define USB_PDT_SIMPLE_DIRECT  0x0E                ///< Simplified direct access device\r
+\r
+//\r
+// Other parameters, Max carried size is 64KB.\r
+//\r
+#define USB_BOOT_MAX_CARRY_SIZE  SIZE_64KB\r
+\r
+//\r
+// Retry mass command times, set by experience\r
+//\r
+#define USB_BOOT_COMMAND_RETRY  5\r
+\r
+//\r
+// Wait for unit ready command, set by experience\r
+//\r
+#define USB_BOOT_RETRY_UNIT_READY_STALL  (500 * USB_MASS_1_MILLISECOND)\r
+\r
+//\r
+// Mass command timeout, refers to specification[USB20-9.2.6.1]\r
+//\r
+// USB2.0 Spec define the up-limit timeout 5s for all command. USB floppy,\r
+// USB CD-Rom and iPod devices are much slower than USB key when response\r
+// most of commands, So we set 5s as timeout here.\r
+//\r
+#define USB_BOOT_GENERAL_CMD_TIMEOUT  (5 * USB_MASS_1_SECOND)\r
 \r
 //\r
 // The required commands are INQUIRY, READ CAPACITY, TEST UNIT READY,\r
 // READ10, WRITE10, and REQUEST SENSE. The BLOCK_IO protocol uses LBA\r
 // so it isn't necessary to issue MODE SENSE / READ FORMAT CAPACITY\r
-// command to retrieve the disk gemotrics. \r
+// command to retrieve the disk gemotrics.\r
 //\r
 #pragma pack(1)\r
 typedef struct {\r
-  UINT8             OpCode;\r
-  UINT8             Lun;            ///< Lun (high 3 bits)\r
-  UINT8             Reserved0[2];\r
-  UINT8             AllocLen;\r
-  UINT8             Reserved1;\r
-  UINT8             Pad[6];\r
+  UINT8    OpCode;\r
+  UINT8    Lun;                     ///< Lun (high 3 bits)\r
+  UINT8    Reserved0[2];\r
+  UINT8    AllocLen;\r
+  UINT8    Reserved1;\r
+  UINT8    Pad[6];\r
 } USB_BOOT_INQUIRY_CMD;\r
 \r
 typedef struct {\r
-  UINT8             Pdt;            ///< Peripheral Device Type (low 5 bits)\r
-  UINT8             Removable;      ///< Removable Media (highest bit)\r
-  UINT8             Reserved0[2];\r
-  UINT8             AddLen;         ///< Additional length\r
-  UINT8             Reserved1[3];\r
-  UINT8             VendorID[8];\r
-  UINT8             ProductID[16];\r
-  UINT8             ProductRevision[4];\r
+  UINT8    Pdt;                     ///< Peripheral Device Type (low 5 bits)\r
+  UINT8    Removable;               ///< Removable Media (highest bit)\r
+  UINT8    Reserved0[2];\r
+  UINT8    AddLen;                  ///< Additional length\r
+  UINT8    Reserved1[3];\r
+  UINT8    VendorID[8];\r
+  UINT8    ProductID[16];\r
+  UINT8    ProductRevision[4];\r
 } USB_BOOT_INQUIRY_DATA;\r
 \r
 typedef struct {\r
-  UINT8             OpCode;\r
-  UINT8             Lun;\r
-  UINT8             Reserved0[8];\r
-  UINT8             Pad[2];\r
+  UINT8    OpCode;\r
+  UINT8    Lun;\r
+  UINT8    Reserved0[8];\r
+  UINT8    Pad[2];\r
 } USB_BOOT_READ_CAPACITY_CMD;\r
 \r
 typedef struct {\r
-  UINT8             LastLba[4];\r
-  UINT8             BlockLen[4];\r
+  UINT8    LastLba[4];\r
+  UINT8    BlockLen[4];\r
 } USB_BOOT_READ_CAPACITY_DATA;\r
 \r
 typedef struct {\r
-  UINT8             OpCode;\r
-  UINT8             Lun;\r
-  UINT8             Reserved[4];\r
-  UINT8             Pad[6];\r
+  UINT8    OpCode;\r
+  UINT8    Lun;\r
+  UINT8    Reserved[4];\r
+  UINT8    Pad[6];\r
 } USB_BOOT_TEST_UNIT_READY_CMD;\r
 \r
 typedef struct {\r
-  UINT8             OpCode;\r
-  UINT8             Lun;\r
-  UINT8             PageCode;\r
-  UINT8             Reserved0[4];\r
-  UINT8             ParaListLenMsb;\r
-  UINT8             ParaListLenLsb;\r
-  UINT8             Reserved1;\r
-  UINT8             Pad[2];\r
+  UINT8    OpCode;\r
+  UINT8    Lun;\r
+  UINT8    PageCode;\r
+  UINT8    Reserved0[4];\r
+  UINT8    ParaListLenMsb;\r
+  UINT8    ParaListLenLsb;\r
+  UINT8    Reserved1;\r
+  UINT8    Pad[2];\r
 } USB_BOOT_MODE_SENSE10_CMD;\r
 \r
 typedef struct {\r
-  UINT8             ModeDataLenMsb;\r
-  UINT8             ModeDataLenLsb;\r
-  UINT8             Reserved0[4];\r
-  UINT8             BlkDesLenMsb;\r
-  UINT8             BlkDesLenLsb;\r
+  UINT8    ModeDataLenMsb;\r
+  UINT8    ModeDataLenLsb;\r
+  UINT8    Reserved0[4];\r
+  UINT8    BlkDesLenMsb;\r
+  UINT8    BlkDesLenLsb;\r
 } USB_BOOT_MODE_SENSE10_PARA_HEADER;\r
 \r
 typedef struct {\r
-  UINT8             OpCode;\r
-  UINT8             Lun;            ///< Lun (High 3 bits)\r
-  UINT8             Lba[4];         ///< Logical block address\r
-  UINT8             Reserved0;\r
-  UINT8             TransferLen[2]; ///< Transfer length\r
-  UINT8             Reserverd1;\r
-  UINT8             Pad[2];\r
-} USB_BOOT_READ10_CMD;\r
-\r
-typedef struct {\r
-  UINT8             OpCode;\r
-  UINT8             Lun;\r
-  UINT8             Lba[4];\r
-  UINT8             Reserved0;\r
-  UINT8             TransferLen[2];\r
-  UINT8             Reserverd1;\r
-  UINT8             Pad[2];\r
-} USB_BOOT_WRITE10_CMD;\r
+  UINT8    OpCode;\r
+  UINT8    Lun;                     ///< Lun (High 3 bits)\r
+  UINT8    Lba[4];                  ///< Logical block address\r
+  UINT8    Reserved0;\r
+  UINT8    TransferLen[2];          ///< Transfer length\r
+  UINT8    Reserverd1;\r
+  UINT8    Pad[2];\r
+} USB_BOOT_READ_WRITE_10_CMD;\r
 \r
 typedef struct {\r
-  UINT8             OpCode;\r
-  UINT8             Lun;            ///< Lun (High 3 bits)\r
-  UINT8             Reserved0[2];\r
-  UINT8             AllocLen;       ///< Allocation length\r
-  UINT8             Reserved1;\r
-  UINT8             Pad[6];\r
+  UINT8    OpCode;\r
+  UINT8    Lun;                     ///< Lun (High 3 bits)\r
+  UINT8    Reserved0[2];\r
+  UINT8    AllocLen;                ///< Allocation length\r
+  UINT8    Reserved1;\r
+  UINT8    Pad[6];\r
 } USB_BOOT_REQUEST_SENSE_CMD;\r
 \r
 typedef struct {\r
-  UINT8             ErrorCode;\r
-  UINT8             Reserved0;\r
-  UINT8             SenseKey;       ///< Sense key (low 4 bits)\r
-  UINT8             Infor[4];\r
-  UINT8             AddLen;         ///< Additional Sense length, 10\r
-  UINT8             Reserved1[4];\r
-  UINT8             ASC;            ///< Additional Sense Code\r
-  UINT8             ASCQ;           ///< Additional Sense Code Qualifier\r
-  UINT8             Reserverd2[4];\r
+  UINT8    ErrorCode;\r
+  UINT8    Reserved0;\r
+  UINT8    SenseKey;                ///< Sense key (low 4 bits)\r
+  UINT8    Infor[4];\r
+  UINT8    AddLen;                  ///< Additional Sense length, 10\r
+  UINT8    Reserved1[4];\r
+  UINT8    Asc;                     ///< Additional Sense Code\r
+  UINT8    Ascq;                    ///< Additional Sense Code Qualifier\r
+  UINT8    Reserverd2[4];\r
 } USB_BOOT_REQUEST_SENSE_DATA;\r
 \r
 typedef struct {\r
-  UINT8             OpCode;\r
-  UINT8             Lun;\r
-  UINT8             PageCode;\r
-  UINT8             Reserved0;\r
-  UINT8             AllocateLen;\r
-  UINT8             Control;\r
+  UINT8    OpCode;\r
+  UINT8    Lun;\r
+  UINT8    PageCode;\r
+  UINT8    Reserved0;\r
+  UINT8    AllocateLen;\r
+  UINT8    Control;\r
 } USB_SCSI_MODE_SENSE6_CMD;\r
 \r
 typedef struct {\r
-  UINT8             ModeDataLen;\r
-  UINT8             MediumType;\r
-  UINT8             DevicePara;\r
-  UINT8             BlkDesLen;\r
+  UINT8    ModeDataLen;\r
+  UINT8    MediumType;\r
+  UINT8    DevicePara;\r
+  UINT8    BlkDesLen;\r
 } USB_SCSI_MODE_SENSE6_PARA_HEADER;\r
 #pragma pack()\r
 \r
 //\r
 // Convert a LUN number to that in the command\r
 //\r
-#define USB_BOOT_LUN(Lun) ((Lun) << 5)\r
+#define USB_BOOT_LUN(Lun)  ((Lun) << 5)\r
 \r
 //\r
 // Get the removable, PDT, and sense key bits from the command data\r
 //\r
-#define USB_BOOT_REMOVABLE(RmbByte) (((RmbByte) & BIT7) != 0)\r
-#define USB_BOOT_PDT(Pdt)           ((Pdt) & 0x1f)\r
-#define USB_BOOT_SENSE_KEY(Key)     ((Key) & 0x0f)\r
+#define USB_BOOT_REMOVABLE(RmbByte)  (((RmbByte) & BIT7) != 0)\r
+#define USB_BOOT_PDT(Pdt)            ((Pdt) & 0x1f)\r
+#define USB_BOOT_SENSE_KEY(Key)      ((Key) & 0x0f)\r
 \r
 /**\r
   Get the parameters for the USB mass storage media.\r
@@ -233,7 +213,7 @@ typedef struct {
   This function get the parameters for the USB mass storage media,\r
   It is used both to initialize the media during the Start() phase\r
   of Driver Binding Protocol and to re-initialize it when the media is\r
-  changed. Althought the RemoveableMedia is unlikely to change,\r
+  changed. Although the RemoveableMedia is unlikely to change,\r
   it is also included here.\r
 \r
   @param  UsbMass                The device to retrieve disk gemotric.\r
@@ -244,7 +224,7 @@ typedef struct {
 **/\r
 EFI_STATUS\r
 UsbBootGetParams (\r
-  IN USB_MASS_DEVICE          *UsbMass\r
+  IN USB_MASS_DEVICE  *UsbMass\r
   );\r
 \r
 /**\r
@@ -258,7 +238,7 @@ UsbBootGetParams (
 **/\r
 EFI_STATUS\r
 UsbBootIsUnitReady (\r
-  IN USB_MASS_DEVICE          *UsbMass\r
+  IN USB_MASS_DEVICE  *UsbMass\r
   );\r
 \r
 /**\r
@@ -272,7 +252,7 @@ UsbBootIsUnitReady (
 **/\r
 EFI_STATUS\r
 UsbBootDetectMedia (\r
-  IN  USB_MASS_DEVICE       *UsbMass\r
+  IN  USB_MASS_DEVICE  *UsbMass\r
   );\r
 \r
 /**\r
@@ -289,30 +269,53 @@ UsbBootDetectMedia (
 **/\r
 EFI_STATUS\r
 UsbBootReadBlocks (\r
-  IN  USB_MASS_DEVICE         *UsbMass,\r
-  IN  UINT32                  Lba,\r
-  IN  UINTN                   TotalBlock,\r
-  OUT UINT8                   *Buffer\r
+  IN  USB_MASS_DEVICE  *UsbMass,\r
+  IN  UINT32           Lba,\r
+  IN  UINTN            TotalBlock,\r
+  OUT UINT8            *Buffer\r
   );\r
 \r
 /**\r
-  Write some blocks to the device.\r
+  Read or write some blocks from the device.\r
 \r
-  @param  UsbMass                The USB mass storage device to write to\r
+  @param  UsbMass                The USB mass storage device to access\r
+  @param  Write                  TRUE for write operation.\r
   @param  Lba                    The start block number\r
-  @param  TotalBlock             Total block number to write\r
-  @param  Buffer                 Pointer to the source buffer for the data.\r
+  @param  TotalBlock             Total block number to read or write\r
+  @param  Buffer                 The buffer to read to or write from\r
 \r
-  @retval EFI_SUCCESS            Data are written into the buffer\r
-  @retval Others                 Failed to write all the data\r
+  @retval EFI_SUCCESS            Data are read into the buffer or writen into the device.\r
+  @retval Others                 Failed to read or write all the data\r
 \r
 **/\r
 EFI_STATUS\r
-UsbBootWriteBlocks (\r
-  IN  USB_MASS_DEVICE         *UsbMass,\r
-  IN  UINT32                  Lba,\r
-  IN  UINTN                   TotalBlock,\r
-  IN  UINT8                   *Buffer\r
+UsbBootReadWriteBlocks (\r
+  IN  USB_MASS_DEVICE  *UsbMass,\r
+  IN  BOOLEAN          Write,\r
+  IN  UINT32           Lba,\r
+  IN  UINTN            TotalBlock,\r
+  IN OUT UINT8         *Buffer\r
+  );\r
+\r
+/**\r
+  Read or write some blocks from the device by SCSI 16 byte cmd.\r
+\r
+  @param  UsbMass                The USB mass storage device to access\r
+  @param  Write                  TRUE for write operation.\r
+  @param  Lba                    The start block number\r
+  @param  TotalBlock             Total block number to read or write\r
+  @param  Buffer                 The buffer to read to or write from\r
+\r
+  @retval EFI_SUCCESS            Data are read into the buffer or writen into the device.\r
+  @retval Others                 Failed to read or write all the data\r
+**/\r
+EFI_STATUS\r
+UsbBootReadWriteBlocks16 (\r
+  IN  USB_MASS_DEVICE  *UsbMass,\r
+  IN  BOOLEAN          Write,\r
+  IN  UINT64           Lba,\r
+  IN  UINTN            TotalBlock,\r
+  IN OUT UINT8         *Buffer\r
   );\r
 \r
 /**\r
@@ -327,9 +330,8 @@ UsbBootWriteBlocks (
 **/\r
 EFI_STATUS\r
 UsbClearEndpointStall (\r
-  IN EFI_USB_IO_PROTOCOL    *UsbIo,\r
-  IN UINT8                  EndpointAddr\r
+  IN EFI_USB_IO_PROTOCOL  *UsbIo,\r
+  IN UINT8                EndpointAddr\r
   );\r
 \r
 #endif\r
-\r