]> git.proxmox.com Git - mirror_edk2.git/commitdiff
Add Read/Write (16) command to SCSI library.
authorli-elvin <li-elvin@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 28 May 2010 06:57:15 +0000 (06:57 +0000)
committerli-elvin <li-elvin@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 28 May 2010 06:57:15 +0000 (06:57 +0000)
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@10549 6f19259b-4bc3-4df7-8a09-765794883524

MdePkg/Include/IndustryStandard/Scsi.h
MdePkg/Include/Library/UefiScsiLib.h
MdePkg/Library/UefiScsiLib/UefiScsiLib.c

index e9b87dedc019abdb799dcee1370ffdb968b06d50..de10e506f313d2565c053d825702ba32b9539ff9 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   Support for SCSI-2 standard\r
 \r
-  Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
   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
@@ -48,6 +48,7 @@
 #define EFI_SCSI_OP_MEDIA_REMOVAL   0x1e\r
 #define EFI_SCSI_OP_READ6           0x08\r
 #define EFI_SCSI_OP_READ10          0x28\r
+#define EFI_SCSI_OP_READ16          0x88\r
 #define EFI_SCSI_OP_READ_CAPACITY   0x25\r
 #define EFI_SCSI_OP_READ_CAPACITY16 0x9e\r
 #define EFI_SCSI_OP_READ_DEFECT     0x37\r
@@ -67,6 +68,7 @@
 #define EFI_SCSI_OP_VERIFY          0x2f\r
 #define EFI_SCSI_OP_WRITE6          0x0a\r
 #define EFI_SCSI_OP_WRITE10         0x2a\r
+#define EFI_SCSI_OP_WRITE16         0x8a\r
 #define EFI_SCSI_OP_WRITE_VERIFY    0x2e\r
 #define EFI_SCSI_OP_WRITE_LONG      0x3f\r
 #define EFI_SCSI_OP_WRITE_SAME      0x41\r
index bc5414d15b1c3f83859d7e22a881e25390b784a0..c947c6b9e758ecc40c4726aefbfe48641ddd083b 100644 (file)
@@ -5,7 +5,7 @@
   for hard drive, CD and DVD devices that are the most common SCSI boot targets used by UEFI platforms.\r
   This library class depends on SCSI I/O Protocol defined in UEFI Specification and SCSI-2 industry standard.\r
 \r
-Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
 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
@@ -531,5 +531,108 @@ ScsiWrite10Command (
   IN     UINT32                SectorSize\r
   );\r
 \r
+/**\r
+  Execute Read(16) SCSI command on a specific SCSI target.\r
+\r
+  Executes the SCSI Read(16) command on the SCSI target specified by ScsiIo.\r
+  If Timeout is zero, then this function waits indefinitely for the command to complete.\r
+  If Timeout is greater than zero, then the command is executed and will timeout\r
+  after Timeout 100 ns units.  The StartLba and SectorSize parameters are used to\r
+  construct the CDB for this SCSI command.\r
+  If ScsiIo is NULL, then ASSERT().\r
+  If SenseDataLength is NULL, then ASSERT().\r
+  If HostAdapterStatus is NULL, then ASSERT().\r
+  If TargetStatus is NULL, then ASSERT().\r
+  If DataLength is NULL, then ASSERT().\r
+\r
+\r
+  @param[in]      ScsiIo               A pointer to SCSI IO protocol.\r
+  @param[in]      Timeout              The length of timeout period.\r
+  @param[in, out] SenseData            A pointer to output sense data.\r
+  @param[in, out] SenseDataLength      The length of output sense data.\r
+  @param[out]     HostAdapterStatus    The status of Host Adapter.\r
+  @param[out]     TargetStatus         The status of the target.\r
+  @param[in, out] DataBuffer           Read 16 command data.\r
+  @param[in, out] DataLength           The length of data buffer.\r
+  @param[in]      StartLba             The start address of LBA.\r
+  @param[in]      SectorSize           The sector size.\r
+\r
+  @retval  EFI_SUCCESS          Command is executed successfully.\r
+  @retval  EFI_BAD_BUFFER_SIZE  The SCSI Request Packet was executed, but the entire DataBuffer could\r
+                                not be transferred. The actual number of bytes transferred is returned in DataLength.\r
+  @retval  EFI_NOT_READY        The SCSI Request Packet could not be sent because there are too many \r
+                                SCSI Command Packets already queued.\r
+  @retval  EFI_DEVICE_ERROR     A device error occurred while attempting to send SCSI Request Packet.\r
+  @retval  EFI_UNSUPPORTED      The command described by the SCSI Request Packet is not supported by \r
+                                the SCSI initiator(i.e., SCSI  Host Controller)\r
+  @retval  EFI_TIMEOUT          A timeout occurred while waiting for the SCSI Request Packet to execute.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ScsiRead16Command (\r
+  IN     EFI_SCSI_IO_PROTOCOL  *ScsiIo,\r
+  IN     UINT64                Timeout,\r
+  IN OUT VOID                  *SenseData,   OPTIONAL\r
+  IN OUT UINT8                 *SenseDataLength,\r
+     OUT UINT8                 *HostAdapterStatus,\r
+     OUT UINT8                 *TargetStatus,\r
+  IN OUT VOID                  *DataBuffer,  OPTIONAL\r
+  IN OUT UINT32                *DataLength,\r
+  IN     UINT64                StartLba,\r
+  IN     UINT32                SectorSize\r
+  );\r
+\r
+\r
+/**\r
+  Execute Write(16) SCSI command on a specific SCSI target.\r
+\r
+  Executes the SCSI Write(16) command on the SCSI target specified by ScsiIo.\r
+  If Timeout is zero, then this function waits indefinitely for the command to complete.\r
+  If Timeout is greater than zero, then the command is executed and will timeout after\r
+  Timeout 100 ns units.  The StartLba and SectorSize parameters are used to construct\r
+  the CDB for this SCSI command.\r
+  If ScsiIo is NULL, then ASSERT().\r
+  If SenseDataLength is NULL, then ASSERT().\r
+  If HostAdapterStatus is NULL, then ASSERT().\r
+  If TargetStatus is NULL, then ASSERT().\r
+  If DataLength is NULL, then ASSERT().\r
+\r
+  @param[in]      ScsiIo               SCSI IO Protocol to use\r
+  @param[in]      Timeout              The length of timeout period.\r
+  @param[in, out] SenseData            A pointer to output sense data.\r
+  @param[in, out] SenseDataLength      The length of output sense data.\r
+  @param[out]     HostAdapterStatus    The status of Host Adapter.\r
+  @param[out]     TargetStatus         The status of the target.\r
+  @param[in, out] DataBuffer           A pointer to a data buffer.\r
+  @param[in, out] DataLength           The length of data buffer.\r
+  @param[in]      StartLba             The start address of LBA.\r
+  @param[in]      SectorSize           The sector size.\r
+\r
+  @retval  EFI_SUCCESS          Command is executed successfully.\r
+  @retval  EFI_BAD_BUFFER_SIZE  The SCSI Request Packet was executed, but the entire DataBuffer could\r
+                                not be transferred. The actual number of bytes transferred is returned in DataLength.\r
+  @retval  EFI_NOT_READY        The SCSI Request Packet could not be sent because there are too many \r
+                                SCSI Command Packets already queued.\r
+  @retval  EFI_DEVICE_ERROR     A device error occurred while attempting to send SCSI Request Packet.\r
+  @retval  EFI_UNSUPPORTED      The command described by the SCSI Request Packet is not supported by \r
+                                the SCSI initiator(i.e., SCSI  Host Controller)\r
+  @retval  EFI_TIMEOUT          A timeout occurred while waiting for the SCSI Request Packet to execute.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ScsiWrite16Command (\r
+  IN     EFI_SCSI_IO_PROTOCOL  *ScsiIo,\r
+  IN     UINT64                Timeout,\r
+  IN OUT VOID                  *SenseData,   OPTIONAL\r
+  IN OUT UINT8                 *SenseDataLength,\r
+     OUT UINT8                 *HostAdapterStatus,\r
+     OUT UINT8                 *TargetStatus,\r
+  IN OUT VOID                  *DataBuffer,  OPTIONAL\r
+  IN OUT UINT32                *DataLength,\r
+  IN     UINT64                StartLba,\r
+  IN     UINT32                SectorSize\r
+  );\r
 \r
 #endif\r
index f9dbdb63e02fa51797fa54b7551af3779e44cdb1..9715a192dd8e7f44c866ee570f7d85da62497ae4 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   UEFI SCSI Library implementation\r
 \r
-  Copyright (c) 2006 - 2008, Intel Corporation. All rights reserved.<BR>\r
+  Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>\r
   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
 #define EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK 0xe0\r
   \r
   //\r
-  // Scsi Command Length six or ten\r
+  // Scsi Command Length\r
   //\r
-#define EFI_SCSI_OP_LENGTH_SIX 0x6\r
-#define EFI_SCSI_OP_LENGTH_TEN 0xa\r
+#define EFI_SCSI_OP_LENGTH_SIX      0x6\r
+#define EFI_SCSI_OP_LENGTH_TEN      0xa\r
+#define EFI_SCSI_OP_LENGTH_SIXTEEN  0x10\r
 \r
 \r
 \r
@@ -820,12 +821,8 @@ ScsiRead10Command (
 \r
   Cdb[0]                        = EFI_SCSI_OP_READ10;\r
   Cdb[1]                        = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
-  Cdb[2]                        = (UINT8) (StartLba >> 24);\r
-  Cdb[3]                        = (UINT8) (StartLba >> 16);\r
-  Cdb[4]                        = (UINT8) (StartLba >> 8);\r
-  Cdb[5]                        = (UINT8) (StartLba & 0xff);\r
-  Cdb[7]                        = (UINT8) (SectorSize >> 8);\r
-  Cdb[8]                        = (UINT8) (SectorSize & 0xff);\r
+  WriteUnaligned32 ((UINT32 *)&Cdb[2], SwapBytes32 (StartLba));\r
+  WriteUnaligned16 ((UINT16 *)&Cdb[7], SwapBytes16 ((UINT16) SectorSize));\r
 \r
   CommandPacket.CdbLength       = EFI_SCSI_OP_LENGTH_TEN;\r
   CommandPacket.DataDirection   = EFI_SCSI_DATA_IN;\r
@@ -922,12 +919,8 @@ ScsiWrite10Command (
 \r
   Cdb[0]                        = EFI_SCSI_OP_WRITE10;\r
   Cdb[1]                        = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
-  Cdb[2]                        = (UINT8) (StartLba >> 24);\r
-  Cdb[3]                        = (UINT8) (StartLba >> 16);\r
-  Cdb[4]                        = (UINT8) (StartLba >> 8);\r
-  Cdb[5]                        = (UINT8) StartLba;\r
-  Cdb[7]                        = (UINT8) (SectorSize >> 8);\r
-  Cdb[8]                        = (UINT8) SectorSize;\r
+  WriteUnaligned32 ((UINT32 *)&Cdb[2], SwapBytes32 (StartLba));\r
+  WriteUnaligned16 ((UINT16 *)&Cdb[7], SwapBytes16 ((UINT16) SectorSize));\r
 \r
   CommandPacket.CdbLength       = EFI_SCSI_OP_LENGTH_TEN;\r
   CommandPacket.DataDirection   = EFI_SCSI_DATA_OUT;\r
@@ -943,3 +936,198 @@ ScsiWrite10Command (
   return Status;\r
 }\r
 \r
+/**\r
+  Execute Read(16) SCSI command on a specific SCSI target.\r
+\r
+  Executes the SCSI Read(16) command on the SCSI target specified by ScsiIo.\r
+  If Timeout is zero, then this function waits indefinitely for the command to complete.\r
+  If Timeout is greater than zero, then the command is executed and will timeout\r
+  after Timeout 100 ns units.  The StartLba and SectorSize parameters are used to\r
+  construct the CDB for this SCSI command.\r
+  If ScsiIo is NULL, then ASSERT().\r
+  If SenseDataLength is NULL, then ASSERT().\r
+  If HostAdapterStatus is NULL, then ASSERT().\r
+  If TargetStatus is NULL, then ASSERT().\r
+  If DataLength is NULL, then ASSERT().\r
+\r
+\r
+  @param[in]      ScsiIo               A pointer to SCSI IO protocol.\r
+  @param[in]      Timeout              The length of timeout period.\r
+  @param[in, out] SenseData            A pointer to output sense data.\r
+  @param[in, out] SenseDataLength      The length of output sense data.\r
+  @param[out]     HostAdapterStatus    The status of Host Adapter.\r
+  @param[out]     TargetStatus         The status of the target.\r
+  @param[in, out] DataBuffer           Read 16 command data.\r
+  @param[in, out] DataLength           The length of data buffer.\r
+  @param[in]      StartLba             The start address of LBA.\r
+  @param[in]      SectorSize           The sector size.\r
+\r
+  @retval  EFI_SUCCESS          Command is executed successfully.\r
+  @retval  EFI_BAD_BUFFER_SIZE  The SCSI Request Packet was executed, but the entire DataBuffer could\r
+                                not be transferred. The actual number of bytes transferred is returned in DataLength.\r
+  @retval  EFI_NOT_READY        The SCSI Request Packet could not be sent because there are too many \r
+                                SCSI Command Packets already queued.\r
+  @retval  EFI_DEVICE_ERROR     A device error occurred while attempting to send SCSI Request Packet.\r
+  @retval  EFI_UNSUPPORTED      The command described by the SCSI Request Packet is not supported by \r
+                                the SCSI initiator(i.e., SCSI  Host Controller)\r
+  @retval  EFI_TIMEOUT          A timeout occurred while waiting for the SCSI Request Packet to execute.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ScsiRead16Command (\r
+  IN     EFI_SCSI_IO_PROTOCOL  *ScsiIo,\r
+  IN     UINT64                Timeout,\r
+  IN OUT VOID                  *SenseData,   OPTIONAL\r
+  IN OUT UINT8                 *SenseDataLength,\r
+     OUT UINT8                 *HostAdapterStatus,\r
+     OUT UINT8                 *TargetStatus,\r
+  IN OUT VOID                  *DataBuffer,  OPTIONAL\r
+  IN OUT UINT32                *DataLength,\r
+  IN     UINT64                StartLba,\r
+  IN     UINT32                SectorSize\r
+  )\r
+{\r
+  EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r
+  UINT64                          Lun;\r
+  UINT8                           *Target;\r
+  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
+  EFI_STATUS                      Status;\r
+  UINT8                           Cdb[EFI_SCSI_OP_LENGTH_SIXTEEN];\r
+\r
+  ASSERT (SenseDataLength != NULL);\r
+  ASSERT (HostAdapterStatus != NULL);\r
+  ASSERT (TargetStatus != NULL);\r
+  ASSERT (DataLength != NULL);\r
+  ASSERT (ScsiIo != NULL);\r
+\r
+  ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r
+  ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIXTEEN);\r
+\r
+  CommandPacket.Timeout          = Timeout;\r
+  CommandPacket.InDataBuffer     = DataBuffer;\r
+  CommandPacket.SenseData        = SenseData;\r
+  CommandPacket.InTransferLength = *DataLength;\r
+  CommandPacket.Cdb              = Cdb;\r
+  //\r
+  // Fill Cdb for Read (16) Command\r
+  //\r
+  Target = &TargetArray[0];\r
+  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
+\r
+  Cdb[0]                        = EFI_SCSI_OP_READ16;\r
+  Cdb[1]                        = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
+  WriteUnaligned64 ((UINT64 *)&Cdb[2], SwapBytes64 (StartLba));\r
+  WriteUnaligned32 ((UINT32 *)&Cdb[10], SwapBytes32 (SectorSize));\r
+\r
+  CommandPacket.CdbLength       = EFI_SCSI_OP_LENGTH_SIXTEEN;\r
+  CommandPacket.DataDirection   = EFI_SCSI_DATA_IN;\r
+  CommandPacket.SenseDataLength = *SenseDataLength;\r
+\r
+  Status                        = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);\r
+\r
+  *HostAdapterStatus            = CommandPacket.HostAdapterStatus;\r
+  *TargetStatus                 = CommandPacket.TargetStatus;\r
+  *SenseDataLength              = CommandPacket.SenseDataLength;\r
+  *DataLength                   = CommandPacket.InTransferLength;\r
+\r
+  return Status;\r
+}\r
+\r
+\r
+/**\r
+  Execute Write(16) SCSI command on a specific SCSI target.\r
+\r
+  Executes the SCSI Write(16) command on the SCSI target specified by ScsiIo.\r
+  If Timeout is zero, then this function waits indefinitely for the command to complete.\r
+  If Timeout is greater than zero, then the command is executed and will timeout after\r
+  Timeout 100 ns units.  The StartLba and SectorSize parameters are used to construct\r
+  the CDB for this SCSI command.\r
+  If ScsiIo is NULL, then ASSERT().\r
+  If SenseDataLength is NULL, then ASSERT().\r
+  If HostAdapterStatus is NULL, then ASSERT().\r
+  If TargetStatus is NULL, then ASSERT().\r
+  If DataLength is NULL, then ASSERT().\r
+\r
+  @param[in]      ScsiIo               SCSI IO Protocol to use\r
+  @param[in]      Timeout              The length of timeout period.\r
+  @param[in, out] SenseData            A pointer to output sense data.\r
+  @param[in, out] SenseDataLength      The length of output sense data.\r
+  @param[out]     HostAdapterStatus    The status of Host Adapter.\r
+  @param[out]     TargetStatus         The status of the target.\r
+  @param[in, out] DataBuffer           A pointer to a data buffer.\r
+  @param[in, out] DataLength           The length of data buffer.\r
+  @param[in]      StartLba             The start address of LBA.\r
+  @param[in]      SectorSize           The sector size.\r
+\r
+  @retval  EFI_SUCCESS          Command is executed successfully.\r
+  @retval  EFI_BAD_BUFFER_SIZE  The SCSI Request Packet was executed, but the entire DataBuffer could\r
+                                not be transferred. The actual number of bytes transferred is returned in DataLength.\r
+  @retval  EFI_NOT_READY        The SCSI Request Packet could not be sent because there are too many \r
+                                SCSI Command Packets already queued.\r
+  @retval  EFI_DEVICE_ERROR     A device error occurred while attempting to send SCSI Request Packet.\r
+  @retval  EFI_UNSUPPORTED      The command described by the SCSI Request Packet is not supported by \r
+                                the SCSI initiator(i.e., SCSI  Host Controller)\r
+  @retval  EFI_TIMEOUT          A timeout occurred while waiting for the SCSI Request Packet to execute.\r
+\r
+**/\r
+EFI_STATUS\r
+EFIAPI\r
+ScsiWrite16Command (\r
+  IN     EFI_SCSI_IO_PROTOCOL  *ScsiIo,\r
+  IN     UINT64                Timeout,\r
+  IN OUT VOID                  *SenseData,   OPTIONAL\r
+  IN OUT UINT8                 *SenseDataLength,\r
+     OUT UINT8                 *HostAdapterStatus,\r
+     OUT UINT8                 *TargetStatus,\r
+  IN OUT VOID                  *DataBuffer,  OPTIONAL\r
+  IN OUT UINT32                *DataLength,\r
+  IN     UINT64                StartLba,\r
+  IN     UINT32                SectorSize\r
+  )\r
+{\r
+  EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket;\r
+  UINT64                          Lun;\r
+  UINT8                           *Target;\r
+  UINT8                           TargetArray[EFI_SCSI_TARGET_MAX_BYTES];\r
+  EFI_STATUS                      Status;\r
+  UINT8                           Cdb[EFI_SCSI_OP_LENGTH_SIXTEEN];\r
+\r
+  ASSERT (SenseDataLength != NULL);\r
+  ASSERT (HostAdapterStatus != NULL);\r
+  ASSERT (TargetStatus != NULL);\r
+  ASSERT (DataLength != NULL);\r
+  ASSERT (ScsiIo != NULL);\r
+\r
+  ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET));\r
+  ZeroMem (Cdb, EFI_SCSI_OP_LENGTH_SIXTEEN);\r
+\r
+  CommandPacket.Timeout           = Timeout;\r
+  CommandPacket.OutDataBuffer     = DataBuffer;\r
+  CommandPacket.SenseData         = SenseData;\r
+  CommandPacket.OutTransferLength = *DataLength;\r
+  CommandPacket.Cdb               = Cdb;\r
+  //\r
+  // Fill Cdb for Write (16) Command\r
+  //\r
+  Target = &TargetArray[0];\r
+  ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun);\r
+\r
+  Cdb[0]                        = EFI_SCSI_OP_WRITE16;\r
+  Cdb[1]                        = (UINT8) (LShiftU64 (Lun, 5) & EFI_SCSI_LOGICAL_UNIT_NUMBER_MASK);\r
+  WriteUnaligned64 ((UINT64 *)&Cdb[2], SwapBytes64 (StartLba));\r
+  WriteUnaligned32 ((UINT32 *)&Cdb[10], SwapBytes32 (SectorSize));\r
+\r
+  CommandPacket.CdbLength       = EFI_SCSI_OP_LENGTH_SIXTEEN;\r
+  CommandPacket.DataDirection   = EFI_SCSI_DATA_OUT;\r
+  CommandPacket.SenseDataLength = *SenseDataLength;\r
+\r
+  Status                        = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL);\r
+\r
+  *HostAdapterStatus            = CommandPacket.HostAdapterStatus;\r
+  *TargetStatus                 = CommandPacket.TargetStatus;\r
+  *SenseDataLength              = CommandPacket.SenseDataLength;\r
+  *DataLength                   = CommandPacket.OutTransferLength;\r
+\r
+  return Status;\r
+}\r