From f6a683e01b6053493cd98b9e3a4364ed8d1bde80 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 25 Jan 2016 11:33:37 +0000 Subject: [PATCH] MdeModulePkg/.../IdeMode: correctly report length of returned data For some SCSI commands, notably INQUIRY, it's relatively common for the device to provide less data than we intended to read, and for this reason EFI_EXT_SCSI_PASS_THRU_SCSI_REQUEST_PACKET makes InTransferLength and OutTransferLength read-write. Make ATAPI aware of this. This makes it possible to handle EFI_NOT_READY always, not just for read as done in r19685. I've chosen to use a break statement instead of calling CheckStatusRegister directly; the break statement reaches a pre-existing call the CheckStatusRegister function. This ensures that the assignment to *ByteCount is not missed, and adds a further sanity check to DRQClear. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Paolo Bonzini Tested-by: Laszlo Ersek Reviewed-by: Feng Tian git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19737 6f19259b-4bc3-4df7-8a09-765794883524 --- .../Bus/Ata/AtaAtapiPassThru/IdeMode.c | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c index 320ee90828..6478f7be07 100644 --- a/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c +++ b/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c @@ -1936,7 +1936,7 @@ AtaPacketReadWrite ( IN EFI_PCI_IO_PROTOCOL *PciIo, IN EFI_IDE_REGISTERS *IdeRegisters, IN OUT VOID *Buffer, - IN UINT64 ByteCount, + IN OUT UINT32 *ByteCount, IN BOOLEAN Read, IN UINT64 Timeout ) @@ -1947,17 +1947,18 @@ AtaPacketReadWrite ( EFI_STATUS Status; UINT16 *PtrBuffer; + PtrBuffer = Buffer; + RequiredWordCount = *ByteCount >> 1; + // // No data transfer is premitted. // - if (ByteCount == 0) { + if (RequiredWordCount == 0) { return EFI_SUCCESS; } - PtrBuffer = Buffer; - RequiredWordCount = (UINT32)RShiftU64(ByteCount, 1); // - // ActuralWordCount means the word count of data really transferred. + // ActualWordCount means the word count of data really transferred. // ActualWordCount = 0; @@ -1967,14 +1968,16 @@ AtaPacketReadWrite ( // to see whether indicates device is ready to transfer data. // Status = DRQReady2 (PciIo, IdeRegisters, Timeout); - if ((Status == EFI_NOT_READY) && Read) { - // - // Device provided less data than we intended to read -- exit early. - // - return CheckStatusRegister (PciIo, IdeRegisters); - } if (EFI_ERROR (Status)) { - return Status; + if (Status == EFI_NOT_READY) { + // + // Device provided less data than we intended to read, or wanted less + // data than we intended to write, but it may still be successful. + // + break; + } else { + return Status; + } } // @@ -2040,6 +2043,7 @@ AtaPacketReadWrite ( return EFI_DEVICE_ERROR; } + *ByteCount = ActualWordCount << 1; return Status; } @@ -2138,7 +2142,7 @@ AtaPacketCommandExecute ( PciIo, IdeRegisters, Packet->InDataBuffer, - Packet->InTransferLength, + &Packet->InTransferLength, TRUE, Packet->Timeout ); @@ -2147,7 +2151,7 @@ AtaPacketCommandExecute ( PciIo, IdeRegisters, Packet->OutDataBuffer, - Packet->OutTransferLength, + &Packet->OutTransferLength, FALSE, Packet->Timeout );