hw/sd: model a power-up delay, as a workaround for an EDK2 bug
commitdd26eb43337adf53d22b3fda3591e3837bc08b8c
authorAndrew Baumann <Andrew.Baumann@microsoft.com>
Thu, 18 Feb 2016 14:16:20 +0000 (18 14:16 +0000)
committerPeter Maydell <peter.maydell@linaro.org>
Thu, 18 Feb 2016 14:50:50 +0000 (18 14:50 +0000)
tree1e3b05bfce23716c67b2d973b5e4158657cb3b42
parent4481bbc79d2ae6041094797243972efd08b2f6b0
hw/sd: model a power-up delay, as a workaround for an EDK2 bug

The SD spec for ACMD41 says that a zero argument is an "inquiry"
ACMD41, which does not start initialisation and is used only for
retrieving the OCR. However, Tianocore EDK2 (UEFI) has a bug [1]: it
first sends an inquiry (zero) ACMD41. If that first request returns an
OCR value with the power up bit (0x80000000) set, it assumes the card
is ready and continues, leaving the card in the wrong state. (My
assumption is that this works on hardware, because no real card is
immediately powered up upon reset.)

This change models a delay of 0.5ms from the first ACMD41 to the power
being up. However, it also immediately sets the power on upon seeing a
non-zero (non-enquiry) ACMD41. This speeds up UEFI boot, it should
also account for guests that simply delay after card reset and then
issue an ACMD41 that they expect will succeed.

[1] https://github.com/tianocore/edk2/blob/master/EmbeddedPkg/Universal/MmcDxe/MmcIdentification.c#L279
(This is the loop starting with "We need to wait for the MMC or SD
card is ready")

Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Andrew Baumann <Andrew.Baumann@microsoft.com>
Message-id: 1454902521-21164-3-git-send-email-Andrew.Baumann@microsoft.com
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
hw/sd/sd.c