Revision: 19737
          http://sourceforge.net/p/edk2/code/19737
Author:   lersek
Date:     2016-01-25 11:33:37 +0000 (Mon, 25 Jan 2016)
Log Message:
-----------
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 <[email protected]>
Tested-by: Laszlo Ersek <[email protected]>
Reviewed-by: Feng Tian <[email protected]>

Revision Links:
--------------
    http://sourceforge.net/p/edk2/code/19685

Modified Paths:
--------------
    trunk/edk2/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c

Modified: trunk/edk2/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c
===================================================================
--- trunk/edk2/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c  2016-01-25 
04:45:55 UTC (rev 19736)
+++ trunk/edk2/MdeModulePkg/Bus/Ata/AtaAtapiPassThru/IdeMode.c  2016-01-25 
11:33:37 UTC (rev 19737)
@@ -1936,7 +1936,7 @@
   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 @@
   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 @@
     // 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 @@
     return EFI_DEVICE_ERROR;
   }
 
+  *ByteCount = ActualWordCount << 1;
   return Status;
 }
 
@@ -2138,7 +2142,7 @@
                PciIo,
                IdeRegisters,
                Packet->InDataBuffer,
-               Packet->InTransferLength,
+               &Packet->InTransferLength,
                TRUE,
                Packet->Timeout
                );
@@ -2147,7 +2151,7 @@
                PciIo,
                IdeRegisters,
                Packet->OutDataBuffer,
-               Packet->OutTransferLength,
+               &Packet->OutTransferLength,
                FALSE,
                Packet->Timeout
                );


------------------------------------------------------------------------------
Site24x7 APM Insight: Get Deep Visibility into Application Performance
APM + Mobile APM + RUM: Monitor 3 App instances at just $35/Month
Monitor end-to-end web transactions and take corrective actions now
Troubleshoot faster and improve end-user experience. Signup Now!
http://pubads.g.doubleclick.net/gampad/clk?id=267308311&iu=/4140
_______________________________________________
edk2-commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/edk2-commits

Reply via email to