audk/MdeModulePkg
Laszlo Ersek 0368497524 MdeModulePkg/.../IdeMode: report early finish of packet read as success
SVN r19611 (git commit 7cac240163), "MdeModulePkg/Ide: return correct
status when DRQ is not ready for ATAPI", changed the behavior of
AtaPacketReadWrite(), when DRQReady2() reported an error. The previous
logic had been to:

(a) terminate the transfer loop,
(b) check the status register with CheckStatusRegister(), and determine
    AtaPacketReadWrite()'s return code directly from that.

Action (a) had been correct, but action (b) had masked genuine errors.

For example, when DRQReady2() reported EFI_TIMEOUT -- because the BSY bit
had not been cleared within the allotted time --, CheckStatusRegister()
would report EFI_SUCCESS, simply *because* BSY was still set, and the rest
of the status bits could not be evaluated.

SVN r19611 (git commit 7cac240163) intended to fix action (b) by directly
propagating the error code of DRQReady2() from AtaPacketReadWrite(),
eliminating the CheckStatusRegister() call. This was the right thing for
most of the errors reported by DRQReady2() -- timeout, command abort,
other device error --, but there was one exception: the "read" sub-case of
EFI_NOT_READY, which stands for "'read' complete, with less data available
than the requested amount".

Regarding the "write" sub-case of EFI_NOT_READY: the
AtaPacketCommandExecute() function programs the full transfer length into
the IDE device before it calls AtaPacketReadWrite(), and
AtaPacketReadWrite() only uses CylinderLsb and CylinderMsb for "chunking"
(as requested by the device). Therefore the device cannot justifiedly
clear DRQ earlier than seeing the entire data, when writing.

However, when reading from the device, a "short read" is a successful
operation. (The actual read length will be decoded by the higher level
protocols.) And "short reads" had been handled correctly by the logic
before git 7cac240163. Namely, when DRQReady2() returns EFI_NOT_READY, the
BSY bit is already clear, and we can call CheckStatusRegister() to
investigate all the other bits it cares about.

Therefore restore the logic from before git 7cac240163, but only for the
"read" sub-case of EFI_NOT_READY.

This problem was encountered with OVMF running on QEMU's i440fx IDE
emulation. Many thanks to John Snow for analyzing QEMU's behavior, and
pointing out that it adhered to the relevant specs.

Cc: Feng Tian <feng.tian@intel.com>
Cc: Star Zeng <star.zeng@intel.com>
Cc: John Snow <jsnow@redhat.com>
Reference: https://github.com/tianocore/edk2/issues/43
Contributed-under: TianoCore Contribution Agreement 1.0
Signed-off-by: Laszlo Ersek <lersek@redhat.com>
Reviewed-by: Feng Tian <feng.tian@intel.com>

git-svn-id: https://svn.code.sf.net/p/edk2/code/trunk/edk2@19685 6f19259b-4bc3-4df7-8a09-765794883524
2016-01-19 10:46:39 +00:00
..
Application MdeModulePkg/BootManagerMenu: Fix bug that boots to undesired option 2015-12-25 02:45:57 +00:00
Bus MdeModulePkg/.../IdeMode: report early finish of packet read as success 2016-01-19 10:46:39 +00:00
Core MdeModulePkg Core/Dxe/Misc: Fix typos in function descriptions 2016-01-06 01:10:40 +00:00
Include MdeModulePkg: Add new library class PciHostBridgeLib 2016-01-18 04:49:22 +00:00
Library MdeModulePkg:Modify related files because of rename action 2016-01-19 03:30:57 +00:00
Logo MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00
Universal MdeModulePkg:Fix the potential memory leak issue in Display Engine 2016-01-15 09:50:40 +00:00
Contributions.txt */Contributions.txt: Update example email address 2015-02-03 17:29:14 +00:00
License.txt Update copyright format 2012-04-24 06:49:39 +00:00
MdeModulePkg.dec MdeModulePkg: Add new library class PciHostBridgeLib 2016-01-18 04:49:22 +00:00
MdeModulePkg.dsc MdeModulePkg: Add NOOPT target in MdeModulePkg.dsc 2016-01-19 04:05:51 +00:00
MdeModulePkg.uni MdeModulePkg: Fix 'accroding' typos in MdeModulePkg.dec/.uni 2016-01-06 01:13:07 +00:00
MdeModulePkgExtra.uni MdeModulePkg: Convert all .uni files to utf-8 2015-12-15 04:56:23 +00:00