Skip to contentSkip to conversation

ahci: fix device detect emulation.

PATCH In review Gerd Hoffmann 1 participant 2 messages Jun 23, 2011 – Jun 24, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ahci: fix device detect emulation.

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,

---
 hw/ide/ahci.c |    8 +++++---
 hw/ide/ahci.h |    5 +++--
 2 files changed, 8 insertions(+), 5 deletions(-)
hw/ide/ahci.c +5 -3
index 1f008a3..61bfcc7 100644
@@ -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:
hw/ide/ahci.h +3 -2
index dc86951..31b24bc 100644
@@ -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
Signature · 1 line
1.7.1
#1 lore raw
Quoted 11 lines · Gerd Hoffmann

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

Quoted 6 lines

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