From a02e796b5edcdd538c6052b8b65798eb77436504 Mon Sep 17 00:00:00 2001 From: klu2 Date: Fri, 29 Jun 2007 03:27:28 +0000 Subject: [PATCH] 1) Modify ScsiIo protocol according to UEFI specification 2) Add UefiScsiLib library instance. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@2875 6f19259b-4bc3-4df7-8a09-765794883524 --- MdePkg/Include/IndustryStandard/Scsi.h | 5 + MdePkg/Include/Protocol/ScsiIo.h | 2 +- MdePkg/Library/UefiScsiLib/EdkScsiLib.msa | 43 ++ MdePkg/Library/UefiScsiLib/UefiScsiLib.c | 677 +++++++++++++++++++++ MdePkg/Library/UefiScsiLib/UefiScsiLib.inf | 79 +++ MdePkg/MdePkg.dsc | 2 +- 6 files changed, 806 insertions(+), 2 deletions(-) create mode 100644 MdePkg/Library/UefiScsiLib/EdkScsiLib.msa create mode 100644 MdePkg/Library/UefiScsiLib/UefiScsiLib.c create mode 100644 MdePkg/Library/UefiScsiLib/UefiScsiLib.inf diff --git a/MdePkg/Include/IndustryStandard/Scsi.h b/MdePkg/Include/IndustryStandard/Scsi.h index b8cca5fb8b..86f454f1f2 100644 --- a/MdePkg/Include/IndustryStandard/Scsi.h +++ b/MdePkg/Include/IndustryStandard/Scsi.h @@ -277,4 +277,9 @@ typedef struct { // #define EFI_SCSI_ASCQ_IN_PROGRESS (0x01) +// +// Max bytes needed to represent ID of a SCSI device +// +#define EFI_SCSI_TARGET_MAX_BYTES (0x10) + #endif diff --git a/MdePkg/Include/Protocol/ScsiIo.h b/MdePkg/Include/Protocol/ScsiIo.h index d20f9539ef..1e03705906 100644 --- a/MdePkg/Include/Protocol/ScsiIo.h +++ b/MdePkg/Include/Protocol/ScsiIo.h @@ -222,7 +222,7 @@ struct _EFI_SCSI_IO_PROTOCOL { EFI_SCSI_IO_PROTOCOL_GET_DEVICE_LOCATION GetDeviceLocation; EFI_SCSI_IO_PROTOCOL_RESET_BUS ResetBus; EFI_SCSI_IO_PROTOCOL_RESET_DEVICE ResetDevice; - EFI_SCSI_IO_PROTOCOL_EXEC_SCSI_COMMAND ExecuteSCSICommand; + EFI_SCSI_IO_PROTOCOL_EXEC_SCSI_COMMAND ExecuteScsiCommand; UINT32 IoAlign; }; diff --git a/MdePkg/Library/UefiScsiLib/EdkScsiLib.msa b/MdePkg/Library/UefiScsiLib/EdkScsiLib.msa new file mode 100644 index 0000000000..1135e4af27 --- /dev/null +++ b/MdePkg/Library/UefiScsiLib/EdkScsiLib.msa @@ -0,0 +1,43 @@ + + + + EdkScsiLib + DXE_DRIVER + 46c9adef-aee6-410c-99e4-240e3af18d8b + 1.0 + Component description file for Scsi Dxe Library. + this Libarary implements Scsi command. + Copyright (c) 2006, Intel Corporation. + All rights reserved. This program and the accompanying materials + are licensed and made available under the terms and conditions of the BSD License + which accompanies this distribution. The full text of the license may be found at + http://opensource.org/licenses/bsd-license.php + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + FRAMEWORK_BUILD_PACKAGING_SPECIFICATION 0x00000052 + + + IA32 X64 IPF EBC + false + EdkScsiLib + + + + EdkScsiLib + + + BaseMemoryLib + + + + ScsiLib.c + + + + + + + EFI_SPECIFICATION_VERSION 0x00010010 + EDK_RELEASE_VERSION 0x00020000 + + \ No newline at end of file diff --git a/MdePkg/Library/UefiScsiLib/UefiScsiLib.c b/MdePkg/Library/UefiScsiLib/UefiScsiLib.c new file mode 100644 index 0000000000..ef6a4ebd88 --- /dev/null +++ b/MdePkg/Library/UefiScsiLib/UefiScsiLib.c @@ -0,0 +1,677 @@ +/*++ + +Copyright (c) 2006, Intel Corporation +All rights reserved. This program and the accompanying materials +are licensed and made available under the terms and conditions of the BSD License +which accompanies this distribution. The full text of the license may be found at +http://opensource.org/licenses/bsd-license.php + +THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + +Module Name: + + ScsiLib.c + +Abstract: + + +Revision History +--*/ + +// +// The package level header files this module uses +// +#include + +// +// The protocols, PPI and GUID defintions for this module +// +// +// The Library classes this module consumes +// +#include +#include + +#include + +EFI_STATUS +SubmitTestUnitReadyCommand ( + IN EFI_SCSI_IO_PROTOCOL *ScsiIo, + IN UINT64 Timeout, + OUT VOID *SenseData, + OUT UINT8 *SenseDataLength, + OUT UINT8 *HostAdapterStatus, + OUT UINT8 *TargetStatus + ) +/*++ + +Routine Description: + Function tests the ready status of SCSI unit. + +Arguments: + ScsiIo - A pointer to SCSI IO protocol. + Timeout - The length of timeout period. + SenseData - A pointer to output sense data. + SenseDataLength - The length of output sense data. + HostAdapterStatus - The status of Host Adapter. + TargetStatus - The status of the target. + +Returns: + + Returns: + EFI_SUCCESS - The status of the unit is tested successfully. + EFI_BAD_BUFFER_SIZE - The SCSI Request Packet was executed, + but the entire DataBuffer could not be transferred. + The actual number of bytes transferred is returned + in InTransferLength. + EFI_NOT_READY - The SCSI Request Packet could not be sent because + there are too many SCSI Command Packets already + queued. + EFI_DEVICE_ERROR - A device error occurred while attempting to send + the SCSI Request Packet. + EFI_INVALID_PARAMETER - The contents of CommandPacket are invalid. + EFI_UNSUPPORTED - The command described by the SCSI Request Packet + is not supported by the SCSI initiator(i.e., SCSI + Host Controller). + EFI_TIMEOUT - A timeout occurred while waiting for the SCSI + Request Packet to execute. + +--*/ +{ + EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket; + UINT64 Lun; + UINT8 *Target; + UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES]; + EFI_STATUS Status; + UINT8 Cdb[6]; + + + ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET)); + ZeroMem (Cdb, 6); + + CommandPacket.Timeout = Timeout; + CommandPacket.InDataBuffer = NULL; + CommandPacket.InTransferLength= 0; + CommandPacket.OutDataBuffer = NULL; + CommandPacket.OutTransferLength= 0; + CommandPacket.SenseData = SenseData; + CommandPacket.Cdb = Cdb; + // + // Fill Cdb for Test Unit Ready Command + // + Target = &TargetArray[0]; + ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun); + + Cdb[0] = EFI_SCSI_OP_TEST_UNIT_READY; + Cdb[1] = (UINT8) (Lun & 0xe0); + CommandPacket.CdbLength = (UINT8) 6; + CommandPacket.SenseDataLength = *SenseDataLength; + + Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL); + + *HostAdapterStatus = CommandPacket.HostAdapterStatus; + *TargetStatus = CommandPacket.TargetStatus; + *SenseDataLength = CommandPacket.SenseDataLength; + + return Status; +} + +EFI_STATUS +SubmitInquiryCommand ( + IN EFI_SCSI_IO_PROTOCOL *ScsiIo, + IN UINT64 Timeout, + IN VOID *SenseData, + IN OUT UINT8 *SenseDataLength, + OUT UINT8 *HostAdapterStatus, + OUT UINT8 *TargetStatus, + IN OUT VOID *InquiryDataBuffer, + IN OUT UINT32 *InquiryDataLength, + IN BOOLEAN EnableVitalProductData + ) +/*++ + +Routine Description: + Function to submit SCSI inquiry command. + +Arguments: + ScsiIo - A pointer to SCSI IO protocol. + Timeout - The length of timeout period. + SenseData - A pointer to output sense data. + SenseDataLength - The length of output sense data. + HostAdapterStatus - The status of Host Adapter. + TargetStatus - The status of the target. + InquiryDataBuffer - A pointer to inquiry data buffer. + InquiryDataLength - The length of inquiry data buffer. + EnableVitalProductData - Boolean to enable Vital Product Data. + +Returns: + + Returns: + EFI_SUCCESS - The status of the unit is tested successfully. + EFI_BAD_BUFFER_SIZE - The SCSI Request Packet was executed, + but the entire DataBuffer could not be transferred. + The actual number of bytes transferred is returned + in TransferLength. + EFI_NOT_READY - The SCSI Request Packet could not be sent because + there are too many SCSI Command Packets already + queued. + EFI_DEVICE_ERROR - A device error occurred while attempting to send + the SCSI Request Packet. + EFI_INVALID_PARAMETER - The contents of CommandPacket are invalid. + EFI_UNSUPPORTED - The command described by the SCSI Request Packet + is not supported by the SCSI initiator(i.e., SCSI + Host Controller). + EFI_TIMEOUT - A timeout occurred while waiting for the SCSI + Request Packet to execute. + +--*/ +{ + EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket; + UINT64 Lun; + UINT8 *Target; + UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES]; + EFI_STATUS Status; + UINT8 Cdb[6]; + + ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET)); + ZeroMem (Cdb, 6); + + CommandPacket.Timeout = Timeout; + CommandPacket.InDataBuffer = InquiryDataBuffer; + CommandPacket.InTransferLength= *InquiryDataLength; + CommandPacket.SenseData = SenseData; + CommandPacket.SenseDataLength = *SenseDataLength; + CommandPacket.Cdb = Cdb; + + Target = &TargetArray[0]; + ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun); + + Cdb[0] = EFI_SCSI_OP_INQUIRY; + Cdb[1] = (UINT8) (Lun & 0xe0); + if (EnableVitalProductData) { + Cdb[1] |= 0x01; + } + + if (*InquiryDataLength > 0xff) { + *InquiryDataLength = 0xff; + } + + Cdb[4] = (UINT8) (*InquiryDataLength); + CommandPacket.CdbLength = (UINT8) 6; + CommandPacket.DataDirection = EFI_SCSI_DATA_IN; + + Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL); + + *HostAdapterStatus = CommandPacket.HostAdapterStatus; + *TargetStatus = CommandPacket.TargetStatus; + *SenseDataLength = CommandPacket.SenseDataLength; + *InquiryDataLength = CommandPacket.InTransferLength; + + return Status; +} + +EFI_STATUS +SubmitModeSense10Command ( + IN EFI_SCSI_IO_PROTOCOL *ScsiIo, + IN UINT64 Timeout, + IN VOID *SenseData, + IN OUT UINT8 *SenseDataLength, + OUT UINT8 *HostAdapterStatus, + OUT UINT8 *TargetStatus, + IN VOID *DataBuffer, + IN OUT UINT32 *DataLength, + IN UINT8 DBDField, OPTIONAL + IN UINT8 PageControl, + IN UINT8 PageCode + ) +/*++ + +Routine Description: + Function to submit SCSI mode sense 10 command. + +Arguments: + ScsiIo - A pointer to SCSI IO protocol. + Timeout - The length of timeout period. + SenseData - A pointer to output sense data. + SenseDataLength - The length of output sense data. + HostAdapterStatus - The status of Host Adapter. + TargetStatus - The status of the target. + DataBuffer - A pointer to input data buffer. + DataLength - The length of input data buffer. + DBDField - The DBD Field (Optional). + PageControl - Page Control. + PageCode - Page code. + +Returns: + + Returns: + EFI_SUCCESS - The status of the unit is tested successfully. + EFI_WARN_BUFFER_TOO_SMALL - The SCSI Request Packet was executed, + but the entire DataBuffer could not be transferred. + The actual number of bytes transferred is returned + in TransferLength. + EFI_NOT_READY - The SCSI Request Packet could not be sent because + there are too many SCSI Command Packets already + queued. + EFI_DEVICE_ERROR - A device error occurred while attempting to send + the SCSI Request Packet. + EFI_INVALID_PARAMETER - The contents of CommandPacket are invalid. + EFI_UNSUPPORTED - The command described by the SCSI Request Packet + is not supported by the SCSI initiator(i.e., SCSI + Host Controller). + EFI_TIMEOUT - A timeout occurred while waiting for the SCSI + Request Packet to execute. + +--*/ +{ + EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket; + UINT64 Lun; + UINT8 *Target; + UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES]; + EFI_STATUS Status; + UINT8 Cdb[10]; + + ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET)); + ZeroMem (Cdb, 10); + + CommandPacket.Timeout = Timeout; + CommandPacket.InDataBuffer = DataBuffer; + CommandPacket.SenseData = SenseData; + CommandPacket.InTransferLength= *DataLength; + CommandPacket.Cdb = Cdb; + // + // Fill Cdb for Mode Sense (10) Command + // + Target = &TargetArray[0]; + ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun); + + Cdb[0] = EFI_SCSI_OP_MODE_SEN10; + Cdb[1] = (UINT8) (Lun & 0xe0 + (DBDField << 3) & 0x08); + Cdb[2] = (UINT8) ((PageControl & 0xc0) | (PageCode & 0x3f)); + Cdb[7] = (UINT8) (*DataLength >> 8); + Cdb[8] = (UINT8) (*DataLength); + + CommandPacket.CdbLength = 10; + CommandPacket.DataDirection = EFI_SCSI_DATA_IN; + CommandPacket.SenseDataLength = *SenseDataLength; + + Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL); + + *HostAdapterStatus = CommandPacket.HostAdapterStatus; + *TargetStatus = CommandPacket.TargetStatus; + *SenseDataLength = CommandPacket.SenseDataLength; + *DataLength = CommandPacket.InTransferLength; + + return Status; +} + +EFI_STATUS +SubmitRequestSenseCommand ( + IN EFI_SCSI_IO_PROTOCOL *ScsiIo, + IN UINT64 Timeout, + IN VOID *SenseData, + IN OUT UINT8 *SenseDataLength, + OUT UINT8 *HostAdapterStatus, + OUT UINT8 *TargetStatus + ) +/*++ + +Routine Description: + Function to submit SCSI request sense command. + +Arguments: + ScsiIo - A pointer to SCSI IO protocol. + Timeout - The length of timeout period. + SenseData - A pointer to output sense data. + SenseDataLength - The length of output sense data. + HostAdapterStatus - The status of Host Adapter. + TargetStatus - The status of the target. + +Returns: + + Returns: + EFI_SUCCESS - The status of the unit is tested successfully. + EFI_WARN_BUFFER_TOO_SMALL - The SCSI Request Packet was executed, + but the entire DataBuffer could not be transferred. + The actual number of bytes transferred is returned + in TransferLength. + EFI_NOT_READY - The SCSI Request Packet could not be sent because + there are too many SCSI Command Packets already + queued. + EFI_DEVICE_ERROR - A device error occurred while attempting to send + the SCSI Request Packet. + EFI_INVALID_PARAMETER - The contents of CommandPacket are invalid. + EFI_UNSUPPORTED - The command described by the SCSI Request Packet + is not supported by the SCSI initiator(i.e., SCSI + Host Controller). + EFI_TIMEOUT - A timeout occurred while waiting for the SCSI + Request Packet to execute. + +--*/ +{ + EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket; + UINT64 Lun; + UINT8 *Target; + UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES]; + EFI_STATUS Status; + UINT8 Cdb[6]; + + ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET)); + ZeroMem (Cdb, 6); + + CommandPacket.Timeout = Timeout; + CommandPacket.InDataBuffer = SenseData; + CommandPacket.SenseData = NULL; + CommandPacket.InTransferLength= *SenseDataLength; + CommandPacket.Cdb = Cdb; + // + // Fill Cdb for Request Sense Command + // + Target = &TargetArray[0]; + ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun); + + Cdb[0] = EFI_SCSI_OP_REQUEST_SENSE; + Cdb[1] = (UINT8) (Lun & 0xe0); + Cdb[4] = (UINT8) (*SenseDataLength); + + CommandPacket.CdbLength = (UINT8) 6; + CommandPacket.DataDirection = EFI_SCSI_DATA_IN; + CommandPacket.SenseDataLength = 0; + + Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL); + + *HostAdapterStatus = CommandPacket.HostAdapterStatus; + *TargetStatus = CommandPacket.TargetStatus; + *SenseDataLength = (UINT8) CommandPacket.InTransferLength; + + return Status; +} + +EFI_STATUS +SubmitReadCapacityCommand ( + IN EFI_SCSI_IO_PROTOCOL *ScsiIo, + IN UINT64 Timeout, + IN VOID *SenseData, + IN OUT UINT8 *SenseDataLength, + OUT UINT8 *HostAdapterStatus, + OUT UINT8 *TargetStatus, + OUT VOID *DataBuffer, + IN OUT UINT32 *DataLength, + IN BOOLEAN PMI + ) +/*++ + +Routine Description: + Function to submit read capacity command. + +Arguments: + ScsiIo - A pointer to SCSI IO protocol. + Timeout - The length of timeout period. + SenseData - A pointer to output sense data. + SenseDataLength - The length of output sense data. + HostAdapterStatus - The status of Host Adapter. + TargetStatus - The status of the target. + DataBuffer - A pointer to a data buffer. + DataLength - The length of data buffer. + PMI - Partial medium indicator. + +Returns: + + Returns: + EFI_SUCCESS - The status of the unit is tested successfully. + EFI_WARN_BUFFER_TOO_SMALL - The SCSI Request Packet was executed, + but the entire DataBuffer could not be transferred. + The actual number of bytes transferred is returned + in TransferLength. + EFI_NOT_READY - The SCSI Request Packet could not be sent because + there are too many SCSI Command Packets already + queued. + EFI_DEVICE_ERROR - A device error occurred while attempting to send + the SCSI Request Packet. + EFI_INVALID_PARAMETER - The contents of CommandPacket are invalid. + EFI_UNSUPPORTED - The command described by the SCSI Request Packet + is not supported by the SCSI initiator(i.e., SCSI + Host Controller). + EFI_TIMEOUT - A timeout occurred while waiting for the SCSI + Request Packet to execute. + +--*/ +{ + EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket; + UINT64 Lun; + UINT8 *Target; + UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES]; + EFI_STATUS Status; + UINT8 Cdb[10]; + + ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET)); + ZeroMem (Cdb, 10); + + CommandPacket.Timeout = Timeout; + CommandPacket.InDataBuffer = DataBuffer; + CommandPacket.SenseData = SenseData; + CommandPacket.InTransferLength= *DataLength; + CommandPacket.Cdb = Cdb; + // + // Fill Cdb for Read Capacity Command + // + Target = &TargetArray[0]; + ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun); + + Cdb[0] = EFI_SCSI_OP_READ_CAPACITY; + Cdb[1] = (UINT8) (Lun & 0xe0); + if (!PMI) { + // + // Partial medium indicator,if PMI is FALSE, the Cdb.2 ~ Cdb.5 MUST BE ZERO. + // + ZeroMem ((Cdb + 2), 4); + } else { + Cdb[8] |= 0x01; + } + + CommandPacket.CdbLength = 10; + CommandPacket.DataDirection = EFI_SCSI_DATA_IN; + CommandPacket.SenseDataLength = *SenseDataLength; + + Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL); + + *HostAdapterStatus = CommandPacket.HostAdapterStatus; + *TargetStatus = CommandPacket.TargetStatus; + *SenseDataLength = CommandPacket.SenseDataLength; + *DataLength = CommandPacket.InTransferLength; + + return Status; +} + +EFI_STATUS +SubmitRead10Command ( + IN EFI_SCSI_IO_PROTOCOL *ScsiIo, + IN UINT64 Timeout, + IN VOID *SenseData, + IN OUT UINT8 *SenseDataLength, + OUT UINT8 *HostAdapterStatus, + OUT UINT8 *TargetStatus, + OUT VOID *DataBuffer, + IN OUT UINT32 *DataLength, + IN UINT32 StartLba, + IN UINT32 SectorSize + ) +/*++ + +Routine Description: + Function to submit read 10 command. + +Arguments: + ScsiIo - A pointer to SCSI IO protocol. + Timeout - The length of timeout period. + SenseData - A pointer to output sense data. + SenseDataLength - The length of output sense data. + HostAdapterStatus - The status of Host Adapter. + TargetStatus - The status of the target. + DataBuffer - A pointer to a data buffer. + DataLength - The length of data buffer. + StartLba - The start address of LBA. + SectorSize - The sector size. + +Returns: + + Returns: + EFI_SUCCESS - The status of the unit is tested successfully. + EFI_WARN_BUFFER_TOO_SMALL - The SCSI Request Packet was executed, + but the entire DataBuffer could not be transferred. + The actual number of bytes transferred is returned + in TransferLength. + EFI_NOT_READY - The SCSI Request Packet could not be sent because + there are too many SCSI Command Packets already + queued. + EFI_DEVICE_ERROR - A device error occurred while attempting to send + the SCSI Request Packet. + EFI_INVALID_PARAMETER - The contents of CommandPacket are invalid. + EFI_UNSUPPORTED - The command described by the SCSI Request Packet + is not supported by the SCSI initiator(i.e., SCSI + Host Controller). + EFI_TIMEOUT - A timeout occurred while waiting for the SCSI + Request Packet to execute. + +--*/ +{ + EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket; + UINT64 Lun; + UINT8 *Target; + UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES]; + EFI_STATUS Status; + UINT8 Cdb[10]; + + ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET)); + ZeroMem (Cdb, 10); + + CommandPacket.Timeout = Timeout; + CommandPacket.InDataBuffer = DataBuffer; + CommandPacket.SenseData = SenseData; + CommandPacket.InTransferLength= *DataLength; + CommandPacket.Cdb = Cdb; + // + // Fill Cdb for Read (10) Command + // + Target = &TargetArray[0]; + ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun); + + Cdb[0] = EFI_SCSI_OP_READ10; + Cdb[1] = (UINT8) (Lun & 0xe0); + Cdb[2] = (UINT8) (StartLba >> 24); + Cdb[3] = (UINT8) (StartLba >> 16); + Cdb[4] = (UINT8) (StartLba >> 8); + Cdb[5] = (UINT8) (StartLba & 0xff); + Cdb[7] = (UINT8) (SectorSize >> 8); + Cdb[8] = (UINT8) (SectorSize & 0xff); + + CommandPacket.CdbLength = 10; + CommandPacket.DataDirection = EFI_SCSI_DATA_IN; + CommandPacket.SenseDataLength = *SenseDataLength; + + Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL); + + *HostAdapterStatus = CommandPacket.HostAdapterStatus; + *TargetStatus = CommandPacket.TargetStatus; + *SenseDataLength = CommandPacket.SenseDataLength; + *DataLength = CommandPacket.InTransferLength; + + return Status; +} + +EFI_STATUS +SubmitWrite10Command ( + IN EFI_SCSI_IO_PROTOCOL *ScsiIo, + IN UINT64 Timeout, + IN VOID *SenseData, + IN OUT UINT8 *SenseDataLength, + OUT UINT8 *HostAdapterStatus, + OUT UINT8 *TargetStatus, + OUT VOID *DataBuffer, + IN OUT UINT32 *DataLength, + IN UINT32 StartLba, + IN UINT32 SectorSize + ) +/*++ + +Routine Description: + Function to submit SCSI write 10 command. + +Arguments: + ScsiIo - A pointer to SCSI IO protocol. + Timeout - The length of timeout period. + SenseData - A pointer to output sense data. + SenseDataLength - The length of output sense data. + HostAdapterStatus - The status of Host Adapter. + TargetStatus - The status of the target. + DataBuffer - A pointer to a data buffer. + DataLength - The length of data buffer. + StartLba - The start address of LBA. + SectorSize - The sector size. + +Returns: + + Returns: + EFI_SUCCESS - The status of the unit is tested successfully. + EFI_WARN_BUFFER_TOO_SMALL - The SCSI Request Packet was executed, + but the entire DataBuffer could not be transferred. + The actual number of bytes transferred is returned + in InTransferLength. + EFI_NOT_READY - The SCSI Request Packet could not be sent because + there are too many SCSI Command Packets already + queued. + EFI_DEVICE_ERROR - A device error occurred while attempting to send + the SCSI Request Packet. + EFI_INVALID_PARAMETER - The contents of CommandPacket are invalid. + EFI_UNSUPPORTED - The command described by the SCSI Request Packet + is not supported by the SCSI initiator(i.e., SCSI + Host Controller). + EFI_TIMEOUT - A timeout occurred while waiting for the SCSI + Request Packet to execute. + +--*/ +{ + EFI_SCSI_IO_SCSI_REQUEST_PACKET CommandPacket; + UINT64 Lun; + UINT8 *Target; + UINT8 TargetArray[EFI_SCSI_TARGET_MAX_BYTES]; + EFI_STATUS Status; + UINT8 Cdb[10]; + + ZeroMem (&CommandPacket, sizeof (EFI_SCSI_IO_SCSI_REQUEST_PACKET)); + ZeroMem (Cdb, 10); + + CommandPacket.Timeout = Timeout; + CommandPacket.OutDataBuffer = DataBuffer; + CommandPacket.SenseData = SenseData; + CommandPacket.OutTransferLength= *DataLength; + CommandPacket.Cdb = Cdb; + // + // Fill Cdb for Write (10) Command + // + Target = &TargetArray[0]; + ScsiIo->GetDeviceLocation (ScsiIo, &Target, &Lun); + + Cdb[0] = EFI_SCSI_OP_WRITE10; + Cdb[1] = (UINT8) (Lun & 0xe0); + Cdb[2] = (UINT8) (StartLba >> 24); + Cdb[3] = (UINT8) (StartLba >> 16); + Cdb[4] = (UINT8) (StartLba >> 8); + Cdb[5] = (UINT8) StartLba; + Cdb[7] = (UINT8) (SectorSize >> 8); + Cdb[8] = (UINT8) SectorSize; + + CommandPacket.CdbLength = 10; + CommandPacket.DataDirection = EFI_SCSI_DATA_OUT; + CommandPacket.SenseDataLength = *SenseDataLength; + + Status = ScsiIo->ExecuteScsiCommand (ScsiIo, &CommandPacket, NULL); + + *HostAdapterStatus = CommandPacket.HostAdapterStatus; + *TargetStatus = CommandPacket.TargetStatus; + *SenseDataLength = CommandPacket.SenseDataLength; + *DataLength = CommandPacket.InTransferLength; + + return Status; +} diff --git a/MdePkg/Library/UefiScsiLib/UefiScsiLib.inf b/MdePkg/Library/UefiScsiLib/UefiScsiLib.inf new file mode 100644 index 0000000000..2119b4632b --- /dev/null +++ b/MdePkg/Library/UefiScsiLib/UefiScsiLib.inf @@ -0,0 +1,79 @@ +#/** @file +# Component description file for Scsi Dxe Library. +# +# this Libarary implements Scsi command. +# Copyright (c) 2006, Intel Corporation. +# +# All rights reserved. This program and the accompanying materials +# are licensed and made available under the terms and conditions of the BSD License +# which accompanies this distribution. The full text of the license may be found at +# http://opensource.org/licenses/bsd-license.php +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. +# +# +#**/ + +################################################################################ +# +# Defines Section - statements that will be processed to create a Makefile. +# +################################################################################ +[Defines] + INF_VERSION = 0x00010005 + BASE_NAME = UefiScsiLib + FILE_GUID = 280E42C3-826E-4573-9772-B74EF1086D95 + MODULE_TYPE = DXE_DRIVER + VERSION_STRING = 1.0 + LIBRARY_CLASS = ScsiLib|DXE_DRIVER DXE_RUNTIME_DRIVER DXE_SAL_DRIVER DXE_SMM_DRIVER UEFI_APPLICATION UEFI_DRIVER + EDK_RELEASE_VERSION = 0x00020000 + EFI_SPECIFICATION_VERSION = 0x00020000 + + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = IA32 X64 IPF EBC +# + +################################################################################ +# +# Sources Section - list of files that are required for the build to succeed. +# +################################################################################ + +[Sources.common] + UefiScsiLib.c + +################################################################################ +# +# Includes Section - list of Include locations that are required for +# this module. +# +################################################################################ + +[Includes] + $(WORKSPACE)/MdePkg/Include/Library + +################################################################################ +# +# Package Dependency Section - list of Package files that are required for +# this module. +# +################################################################################ + +[Packages] + MdePkg/MdePkg.dec + + +################################################################################ +# +# Library Class Section - list of Library Classes that are required for +# this module. +# +################################################################################ + +[LibraryClasses] + BaseMemoryLib + + diff --git a/MdePkg/MdePkg.dsc b/MdePkg/MdePkg.dsc index 5839888bd7..24ffbc4ff8 100644 --- a/MdePkg/MdePkg.dsc +++ b/MdePkg/MdePkg.dsc @@ -119,7 +119,7 @@ ${WORKSPACE}\MdePkg\Library/UefiLib/UefiLib.inf ${WORKSPACE}\MdePkg\Library/UefiRuntimeLib/UefiRuntimeLib.inf ${WORKSPACE}\MdePkg\Library/UefiRuntimeServicesTableLib/UefiRuntimeServicesTableLib.inf - + ${WORKSPACE}\MdePkg\Library/UefiScsiLib/UefiScsiLib.inf [Components.IA32] ${WORKSPACE}\MdePkg\Library/BaseMemoryLibSse2/BaseMemoryLibSse2.inf