Patchwork [03/10] ide: Use IDEState member dev for "device connected" test

login
register
mail settings
Submitter Markus Armbruster
Date Dec. 17, 2012, 2:05 p.m.
Message ID <1355753160-17544-4-git-send-email-armbru@redhat.com>
Download mbox | patch
Permalink /patch/206881/
State New
Headers show

Comments

Markus Armbruster - Dec. 17, 2012, 2:05 p.m.
Testing dev is more obvious than testing bs, in my opinion.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
---
 hw/ide/ahci.c       |  8 ++++----
 hw/ide/core.c       | 56 ++++++++++++++++++++++++++++-------------------------
 hw/ide/microdrive.c |  5 +++--
 hw/ide/qdev.c       |  2 +-
 4 files changed, 38 insertions(+), 33 deletions(-)

Patch

diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index 67562db..4249489 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -86,7 +86,7 @@  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) {
+        if (s->dev[port].port.ifs[0].dev) {
             val = SATA_SCR_SSTATUS_DET_DEV_PRESENT_PHY_UP |
                   SATA_SCR_SSTATUS_SPD_GEN1 | SATA_SCR_SSTATUS_IPM_ACTIVE;
         } else {
@@ -497,7 +497,7 @@  static void ahci_reset_port(AHCIState *s, int port)
     d->init_d2h_sent = 0;
 
     ide_state = &s->dev[port].port.ifs[0];
-    if (!ide_state->bs) {
+    if (!ide_state->dev) {
         return;
     }
 
@@ -523,7 +523,7 @@  static void ahci_reset_port(AHCIState *s, int port)
     }
 
     s->dev[port].port_state = STATE_RUN;
-    if (!ide_state->bs) {
+    if (!ide_state->dev) {
         s->dev[port].port_regs.sig = 0;
         ide_state->status = SEEK_STAT | WRERR_STAT;
     } else if (ide_state->drive_kind == IDE_CD) {
@@ -848,7 +848,7 @@  static int handle_cmd(AHCIState *s, int port, int slot)
     /* The device we are working for */
     ide_state = &s->dev[port].port.ifs[0];
 
-    if (!ide_state->bs) {
+    if (!ide_state->dev) {
         DPRINTF(port, "error: guest accessed unused port");
         goto out;
     }
diff --git a/hw/ide/core.c b/hw/ide/core.c
index 1e94dc4..5876862 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -312,7 +312,7 @@  static void ide_set_signature(IDEState *s)
     if (s->drive_kind == IDE_CD) {
         s->lcyl = 0x14;
         s->hcyl = 0xeb;
-    } else if (s->bs) {
+    } else if (s->dev) {
         s->lcyl = 0;
         s->hcyl = 0;
     } else {
@@ -780,7 +780,7 @@  static void ide_flush_cb(void *opaque, int ret)
 
 void ide_flush_cache(IDEState *s)
 {
-    if (s->bs == NULL) {
+    if (!s->dev) {
         ide_flush_cb(s, 0);
         return;
     }
@@ -1059,8 +1059,9 @@  void ide_exec_cmd(IDEBus *bus, uint32_t val)
 #endif
     s = idebus_active_if(bus);
     /* ignore commands to non existent slave */
-    if (s != bus->ifs && !s->bs)
+    if (s != bus->ifs && !s->dev) {
         return;
+    }
 
     /* Only DEVICE RESET is allowed while BSY or/and DRQ are set */
     if ((s->status & (BUSY_STAT|DRQ_STAT)) && val != WIN_DEVICE_RESET)
@@ -1074,7 +1075,7 @@  void ide_exec_cmd(IDEBus *bus, uint32_t val)
     case WIN_DSM:
         switch (s->feature) {
         case DSM_TRIM:
-            if (!s->bs) {
+            if (!s->dev) {
                 goto abort_cmd;
             }
             ide_sector_start_dma(s, IDE_DMA_TRIM);
@@ -1084,7 +1085,7 @@  void ide_exec_cmd(IDEBus *bus, uint32_t val)
         }
         break;
     case WIN_IDENTIFY:
-        if (s->bs && s->drive_kind != IDE_CD) {
+        if (s->dev && s->drive_kind != IDE_CD) {
             if (s->drive_kind != IDE_CFATA)
                 ide_identify(s);
             else
@@ -1137,7 +1138,7 @@  void ide_exec_cmd(IDEBus *bus, uint32_t val)
             ide_set_signature(s); /* odd, but ATA4 8.27.5.2 requires it */
             goto abort_cmd;
         }
-        if (!s->bs) {
+        if (!s->dev) {
             goto abort_cmd;
         }
 	ide_cmd_lba48_transform(s, lba48);
@@ -1150,7 +1151,7 @@  void ide_exec_cmd(IDEBus *bus, uint32_t val)
     case WIN_WRITE_ONCE:
     case CFA_WRITE_SECT_WO_ERASE:
     case WIN_WRITE_VERIFY:
-        if (!s->bs) {
+        if (!s->dev) {
             goto abort_cmd;
         }
 	ide_cmd_lba48_transform(s, lba48);
@@ -1163,7 +1164,7 @@  void ide_exec_cmd(IDEBus *bus, uint32_t val)
     case WIN_MULTREAD_EXT:
 	lba48 = 1;
     case WIN_MULTREAD:
-        if (!s->bs) {
+        if (!s->dev) {
             goto abort_cmd;
         }
         if (!s->mult_sectors) {
@@ -1177,7 +1178,7 @@  void ide_exec_cmd(IDEBus *bus, uint32_t val)
 	lba48 = 1;
     case WIN_MULTWRITE:
     case CFA_WRITE_MULTI_WO_ERASE:
-        if (!s->bs) {
+        if (!s->dev) {
             goto abort_cmd;
         }
         if (!s->mult_sectors) {
@@ -1197,7 +1198,7 @@  void ide_exec_cmd(IDEBus *bus, uint32_t val)
 	lba48 = 1;
     case WIN_READDMA:
     case WIN_READDMA_ONCE:
-        if (!s->bs) {
+        if (!s->dev) {
             goto abort_cmd;
         }
 	ide_cmd_lba48_transform(s, lba48);
@@ -1207,7 +1208,7 @@  void ide_exec_cmd(IDEBus *bus, uint32_t val)
 	lba48 = 1;
     case WIN_WRITEDMA:
     case WIN_WRITEDMA_ONCE:
-        if (!s->bs) {
+        if (!s->dev) {
             goto abort_cmd;
         }
 	ide_cmd_lba48_transform(s, lba48);
@@ -1230,7 +1231,7 @@  void ide_exec_cmd(IDEBus *bus, uint32_t val)
         ide_set_irq(s->bus);
         break;
     case WIN_SETFEATURES:
-        if (!s->bs)
+        if (!s->dev)
             goto abort_cmd;
         /* XXX: valid for CDROM ? */
         switch(s->feature) {
@@ -1599,8 +1600,8 @@  uint32_t ide_ioport_read(void *opaque, uint32_t addr1)
         ret = 0xff;
         break;
     case 1:
-        if ((!bus->ifs[0].bs && !bus->ifs[1].bs) ||
-            (s != bus->ifs && !s->bs))
+        if ((!bus->ifs[0].dev && !bus->ifs[1].dev) ||
+            (s != bus->ifs && !s->dev))
             ret = 0;
         else if (!hob)
             ret = s->error;
@@ -1608,7 +1609,7 @@  uint32_t ide_ioport_read(void *opaque, uint32_t addr1)
 	    ret = s->hob_feature;
         break;
     case 2:
-        if (!bus->ifs[0].bs && !bus->ifs[1].bs)
+        if (!bus->ifs[0].dev && !bus->ifs[1].dev)
             ret = 0;
         else if (!hob)
             ret = s->nsector & 0xff;
@@ -1616,7 +1617,7 @@  uint32_t ide_ioport_read(void *opaque, uint32_t addr1)
 	    ret = s->hob_nsector;
         break;
     case 3:
-        if (!bus->ifs[0].bs && !bus->ifs[1].bs)
+        if (!bus->ifs[0].dev && !bus->ifs[1].dev)
             ret = 0;
         else if (!hob)
             ret = s->sector;
@@ -1624,7 +1625,7 @@  uint32_t ide_ioport_read(void *opaque, uint32_t addr1)
 	    ret = s->hob_sector;
         break;
     case 4:
-        if (!bus->ifs[0].bs && !bus->ifs[1].bs)
+        if (!bus->ifs[0].dev && !bus->ifs[1].dev)
             ret = 0;
         else if (!hob)
             ret = s->lcyl;
@@ -1632,7 +1633,7 @@  uint32_t ide_ioport_read(void *opaque, uint32_t addr1)
 	    ret = s->hob_lcyl;
         break;
     case 5:
-        if (!bus->ifs[0].bs && !bus->ifs[1].bs)
+        if (!bus->ifs[0].dev && !bus->ifs[1].dev)
             ret = 0;
         else if (!hob)
             ret = s->hcyl;
@@ -1640,18 +1641,20 @@  uint32_t ide_ioport_read(void *opaque, uint32_t addr1)
 	    ret = s->hob_hcyl;
         break;
     case 6:
-        if (!bus->ifs[0].bs && !bus->ifs[1].bs)
+        if (!bus->ifs[0].dev && !bus->ifs[1].dev) {
             ret = 0;
-        else
+        } else {
             ret = s->select;
+        }
         break;
     default:
     case 7:
-        if ((!bus->ifs[0].bs && !bus->ifs[1].bs) ||
-            (s != bus->ifs && !s->bs))
+        if ((!bus->ifs[0].dev && !bus->ifs[1].dev) ||
+            (s != bus->ifs && !s->dev)) {
             ret = 0;
-        else
+        } else {
             ret = s->status;
+        }
         qemu_irq_lower(bus->irq);
         break;
     }
@@ -1667,11 +1670,12 @@  uint32_t ide_status_read(void *opaque, uint32_t addr)
     IDEState *s = idebus_active_if(bus);
     int ret;
 
-    if ((!bus->ifs[0].bs && !bus->ifs[1].bs) ||
-        (s != bus->ifs && !s->bs))
+    if ((!bus->ifs[0].dev && !bus->ifs[1].dev) ||
+        (s != bus->ifs && !s->dev)) {
         ret = 0;
-    else
+    } else {
         ret = s->status;
+    }
 #ifdef DEBUG_IDE
     printf("ide: read status addr=0x%x val=%02x\n", addr, ret);
 #endif
diff --git a/hw/ide/microdrive.c b/hw/ide/microdrive.c
index 9eee5b5..05c5ab1 100644
--- a/hw/ide/microdrive.c
+++ b/hw/ide/microdrive.c
@@ -223,10 +223,11 @@  static uint16_t md_common_read(void *opaque, uint32_t at)
         return ide_ioport_read(&s->bus, 0x1);
     case 0xe:	/* Alternate Status */
         ifs = idebus_active_if(&s->bus);
-        if (ifs->bs)
+        if (ifs->dev) {
             return ifs->status;
-        else
+        } else {
             return 0;
+        }
     case 0xf:	/* Device Address */
         ifs = idebus_active_if(&s->bus);
         return 0xc2 | ((~ifs->select << 2) & 0x3c);
diff --git a/hw/ide/qdev.c b/hw/ide/qdev.c
index e322aea..01bbc74 100644
--- a/hw/ide/qdev.c
+++ b/hw/ide/qdev.c
@@ -111,7 +111,7 @@  int ide_get_geometry(BusState *bus, int unit,
 {
     IDEState *s = &DO_UPCAST(IDEBus, qbus, bus)->ifs[unit];
 
-    if (s->drive_kind != IDE_HD || !s->bs) {
+    if (s->drive_kind != IDE_HD || !s->dev) {
         return -1;
     }