Patchwork ahci: fix device detect emulation.

login
register
mail settings
Submitter Gerd Hoffmann
Date June 23, 2011, 1:59 p.m.
Message ID <1308837577-15232-1-git-send-email-kraxel@redhat.com>
Download mbox | patch
Permalink /patch/101638/
State New
Headers show

Comments

Gerd Hoffmann - June 23, 2011, 1:59 p.m.
AHCI specs say about the device detection field:

Device Detection (DET): Indicates the interface device detection and Phy
state.

0h - No device detected and Phy communication not established
1h - Device presence detected but Phy communication not established
3h - Device presence detected and Phy communication established
4h - Phy in offline mode as a result of the interface being disabled or
     running in a BIST loopback mode

The "Software Initilaization" section also mentions "If PxSSTS.DET
returns a value of 1h or 3h when read, then system software shall
continue to the next step, ..."

This makes me think that 1h means "tried to detect device but didn't
found one" and 0h means "device detection not finished yet".

Thus qemu should better return 1h instead of 0h when no device is
present on a specific port,

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
---
 hw/ide/ahci.c |    8 +++++---
 hw/ide/ahci.h |    5 +++--
 2 files changed, 8 insertions(+), 5 deletions(-)
Gerd Hoffmann - June 24, 2011, 7:24 a.m.
On 06/23/11 15:59, Gerd Hoffmann wrote:
> AHCI specs say about the device detection field:
>
> Device Detection (DET): Indicates the interface device detection and Phy
> state.
>
> 0h - No device detected and Phy communication not established
> 1h - Device presence detected but Phy communication not established
> 3h - Device presence detected and Phy communication established
> 4h - Phy in offline mode as a result of the interface being disabled or
>       running in a BIST loopback mode
>
> The "Software Initilaization" section also mentions "If PxSSTS.DET
> returns a value of 1h or 3h when read, then system software shall
> continue to the next step, ..."
>
> This makes me think that 1h means "tried to detect device but didn't
> found one" and 0h means "device detection not finished yet".

/me was thinking wrong, scratch that, qemu behavior is fine.

cheers,
   Gerd

Patch

diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index 1f008a3..61bfcc7 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -85,11 +85,13 @@  static uint32_t  ahci_port_read(AHCIState *s, int port, int offset)
         val = pr->sig;
         break;
     case PORT_SCR_STAT:
-        if (s->dev[port].port.ifs[0].bs) {
-            val = SATA_SCR_SSTATUS_DET_DEV_PRESENT_PHY_UP |
+        if (!(pr->cmd & PORT_CMD_SPIN_UP)) {
+            val = SATA_SCR_SSTATUS_DET_DETECT_NOT_DONE;
+        } else if (s->dev[port].port.ifs[0].bs) {
+            val = SATA_SCR_SSTATUS_DET_DETECT_DONE_PHY_UP |
                   SATA_SCR_SSTATUS_SPD_GEN1 | SATA_SCR_SSTATUS_IPM_ACTIVE;
         } else {
-            val = SATA_SCR_SSTATUS_DET_NODEV;
+            val = SATA_SCR_SSTATUS_DET_DETECT_DONE_PHY_DOWN;
         }
         break;
     case PORT_SCR_CTL:
diff --git a/hw/ide/ahci.h b/hw/ide/ahci.h
index dc86951..31b24bc 100644
--- a/hw/ide/ahci.h
+++ b/hw/ide/ahci.h
@@ -165,8 +165,9 @@ 
 #define STATE_RUN                         0
 #define STATE_RESET                       1
 
-#define SATA_SCR_SSTATUS_DET_NODEV        0x0
-#define SATA_SCR_SSTATUS_DET_DEV_PRESENT_PHY_UP 0x3
+#define SATA_SCR_SSTATUS_DET_DETECT_NOT_DONE       0x0
+#define SATA_SCR_SSTATUS_DET_DETECT_DONE_PHY_DOWN  0x1
+#define SATA_SCR_SSTATUS_DET_DETECT_DONE_PHY_UP    0x3
 
 #define SATA_SCR_SSTATUS_SPD_NODEV        0x00
 #define SATA_SCR_SSTATUS_SPD_GEN1         0x10