Skip to contentSkip to conversation

AHCI emulation support v6

PATCH In review Alexander Graf 4 participants 28 messages Nov 26, 2010 – Dec 1, 2010 Kbuild

lore
Share & tools
lore
#0 lore raw

cover AHCI emulation support v6

This patch adds support for AHCI emulation. I have tested and verified it works in Linux, OpenBSD, Windows Vista and Windows 7. This AHCI emulation supports NCQ, so multiple read or write requests can be outstanding at the same time.

The code is however not fully optimized yet. I'm fairly sure that there are low hanging performance fruits to be found still :). In my simple benchmarks I achieved about 2/3rd of virtio performance.

Also, this AHCI emulation layer does not support legacy mode. So if you're using a disk with this emulation, you do not get it exposed using the legacy IDE interfaces.

Another nitpick is CD-ROM support in Windows. Somehow it doesn't detect a CD-ROM drive attached to AHCI. At least it doesn't list it.

To attach an AHCI disk to your VM, please use

-drive file=...,if=sata

This should do the trick for x86. On other platforms, you need to add the ahci host controller using -device and add CONFIG_AHCI to its default config. Big endian hosts are still broken due to qemu shortcomings in mmio handing. Expect patches to follow.

This patch set is based on work done during the Google Summer of Code. I was mentoring a student, Roland Elek, who wrote most of the AHCI emulation code based on a patch from Chong Qiao. A bunch of other people were also involved, so everybody who I didn't mention - thanks a lot!

git://repo.or.cz/qemu/ahci.git ahci

v1 -> v2:

- rename IDEExtender to IDEBusOps and make a pointer (kraxel)
- make dma hooks explicit by putting them into ops struct (stefanha)
- use qdev buses (kraxel)
- minor cleanups
- dprintf overhaul
- add reset function

v2 -> v3:

- add msi support (kraxel)
- use MIN macro (kraxel)
- add msi support (kraxel)
- fix ncq with multiple ports
- zap qdev properties (kraxel)
- redesign legacy IF_SATA hooks (kraxel)
- don't build ahci as part of target
- move to ide/ (kwolf)

v3 -> v4:

- prepare for endianness safety
- add lspci dump (herbszt)
- use ich7 instead of ich7m (herbszt)
- fix lst+fis mapping (kraxel)
- coding style (blue swirl)
- explicit mmio setters/getters (blue swirl)
- split pata code out to pata.c (kwolf)
- only include config-devices.h in machine description (blue swirl)

v4 -> v5:

- s/H2dNcqFis/NCQFrame/g (blue swirl)
- redo -drive magic (blue swirl)
- bump BAR to 4k
- rename ICH7_AHCI to ICH7_AHCI_RAID (herbszt)
- drop device config header (blue swirl)

v5 -> v6:
- PCI config space fixes (isaku)
- remove CONFIG_AHCI from x86 default configs (paul brook)
- use snprintf (blue swirl)
- add generic PCI config file (paul brook)
- build ahci on all PCI platforms (paul brook)

Alexander Graf (11):
ide: split ide command interpretation off
ide: fix whitespace gap in ide_exec_cmd
ide: add DMA hooks to bus ops
pci: add storage class for sata
pci: add ich7 pci id
ahci: add ahci emulation
ahci: add -drive support
ahci: spawn controller on demand
ide: move pata specific parts to pata.c
config: add generic pci config file
config: add ahci for pci capable machines

Roland Elek (2):
ide: add support for ide bus ops
ide: add ncq identify data for ahci sata drives

 Makefile                             |   13 +-
 Makefile.objs                        |    3 +-
 blockdev.c                           |   41 +-
 blockdev.h                           |    2 +
 create_config_mak                    |   19 +
 default-configs/i386-softmmu.mak     |    2 +
 default-configs/mips-softmmu.mak     |    2 +
 default-configs/mips64-softmmu.mak   |    2 +
 default-configs/mips64el-softmmu.mak |    2 +
 default-configs/mipsel-softmmu.mak   |    2 +
 default-configs/pci-devices.mak      |    3 +
 default-configs/ppc-softmmu.mak      |    2 +
 default-configs/ppc64-softmmu.mak    |    2 +
 default-configs/ppcemb-softmmu.mak   |    2 +
 default-configs/sparc64-softmmu.mak  |    2 +
 default-configs/x86_64-softmmu.mak   |    2 +
 hw/ide/ahci.c                        | 1380 ++++++++++++++++++++++++++++++++++
 hw/ide/core.c                        |  874 ++++++++++------------
 hw/ide/internal.h                    |   37 +-
 hw/ide/pata.c                        |  178 +++++
 hw/pci.h                             |    1 +
 hw/pci_ids.h                         |    1 +
 qemu-common.h                        |    2 +-
 vl.c                                 |    2 +
 24 files changed, 2082 insertions(+), 494 deletions(-)
 create mode 100755 create_config_mak
 create mode 100644 default-configs/pci-devices.mak
 create mode 100644 hw/ide/ahci.c
 create mode 100644 hw/ide/pata.c
#1 lore raw

PATCH 1/13 ide: split ide command interpretation off

The ATA command interpretation code can be used for PATA and SATA interfaces alike. So let's split it out into a separate function.

---
 hw/ide/core.c     |   20 ++++++++++++++------
 hw/ide/internal.h |    2 ++
 2 files changed, 16 insertions(+), 6 deletions(-)
hw/ide/core.c +14 -6
index 484e0ca..ee551ac 100644
@@ -1790,9 +1790,6 @@ static void ide_clear_hob(IDEBus *bus)
 void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
 {
     IDEBus *bus = opaque;
-    IDEState *s;
-    int n;
-    int lba48 = 0;
 
 #ifdef DEBUG_IDE
     printf("IDE: write addr=0x%x val=0x%02x\n", addr, val);
@@ -1853,17 +1850,29 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
     default:
     case 7:
         /* command */
+        ide_exec_cmd(opaque, val);
+        break;
+    }
+}
+
+
+void ide_exec_cmd(IDEBus *bus, uint32_t val)
+{
+    IDEState *s;
+    int n;
+    int lba48 = 0;
+
 #if defined(DEBUG_IDE)
         printf("ide: CMD=%02x\n", val);
 #endif
         s = idebus_active_if(bus);
         /* ignore commands to non existant slave */
         if (s != bus->ifs && !s->bs)
-            break;
+            return;
 
         /* Only DEVICE RESET is allowed while BSY or/and DRQ are set */
         if ((s->status & (BUSY_STAT|DRQ_STAT)) && val != WIN_DEVICE_RESET)
-            break;
+            return;
 
         switch(val) {
         case WIN_IDENTIFY:
@@ -2354,7 +2363,6 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
             ide_set_irq(s->bus);
             break;
         }
-    }
 }
 
 uint32_t ide_ioport_read(void *opaque, uint32_t addr1)
hw/ide/internal.h +2 -0
index d652e06..e7e1f80 100644
@@ -564,6 +564,8 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,
                                     DriveInfo *hd1, qemu_irq irq);
 void ide_init_ioport(IDEBus *bus, int iobase, int iobase2);
 
+void ide_exec_cmd(IDEBus *bus, uint32_t val);
+
 /* hw/ide/qdev.c */
 void ide_bus_new(IDEBus *idebus, DeviceState *dev);
 IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive);
Signature · 1 line
1.6.0.2
Reviewed-by on v1 1/13
#2 lore raw

[Qemu-devel] Re: [PATCH 01/13] ide: split ide command interpretation off

Quoted 5 lines · Alexander Graf
(quoted diff) +0 -0
@@ -1853,17 +1850,29 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)

    default:
    case 7:
        /* command */
+        ide_exec_cmd(opaque, val);

Slightly clearer but only worth changing if you need to respin the patch series:
ide_exec_cmd(bus, val);

#3 lore raw

PATCH 2/13 ide: fix whitespace gap in ide_exec_cmd

In reply to Alexander Graf

Now that we have the function split out, we have to reindent it. In order to increase the readability of the actual functional change, this is split out.

---
 hw/ide/core.c |  734 ++++++++++++++++++++++++++++----------------------------
 1 files changed, 367 insertions(+), 367 deletions(-)
hw/ide/core.c +367 -367
index ee551ac..1849069 100644
@@ -1863,423 +1863,423 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
     int lba48 = 0;
 
 #if defined(DEBUG_IDE)
-        printf("ide: CMD=%02x\n", val);
+    printf("ide: CMD=%02x\n", val);
 #endif
-        s = idebus_active_if(bus);
-        /* ignore commands to non existant slave */
-        if (s != bus->ifs && !s->bs)
-            return;
+    s = idebus_active_if(bus);
+    /* ignore commands to non existant slave */
+    if (s != bus->ifs && !s->bs)
+        return;
 
-        /* Only DEVICE RESET is allowed while BSY or/and DRQ are set */
-        if ((s->status & (BUSY_STAT|DRQ_STAT)) && val != WIN_DEVICE_RESET)
-            return;
+    /* Only DEVICE RESET is allowed while BSY or/and DRQ are set */
+    if ((s->status & (BUSY_STAT|DRQ_STAT)) && val != WIN_DEVICE_RESET)
+        return;
 
-        switch(val) {
-        case WIN_IDENTIFY:
-            if (s->bs && s->drive_kind != IDE_CD) {
-                if (s->drive_kind != IDE_CFATA)
-                    ide_identify(s);
-                else
-                    ide_cfata_identify(s);
-                s->status = READY_STAT | SEEK_STAT;
-                ide_transfer_start(s, s->io_buffer, 512, ide_transfer_stop);
-            } else {
-                if (s->drive_kind == IDE_CD) {
-                    ide_set_signature(s);
-                }
-                ide_abort_command(s);
-            }
-            ide_set_irq(s->bus);
-            break;
-        case WIN_SPECIFY:
-        case WIN_RECAL:
-            s->error = 0;
+    switch(val) {
+    case WIN_IDENTIFY:
+        if (s->bs && s->drive_kind != IDE_CD) {
+            if (s->drive_kind != IDE_CFATA)
+                ide_identify(s);
+            else
+                ide_cfata_identify(s);
             s->status = READY_STAT | SEEK_STAT;
-            ide_set_irq(s->bus);
-            break;
-        case WIN_SETMULT:
-            if (s->drive_kind == IDE_CFATA && s->nsector == 0) {
-                /* Disable Read and Write Multiple */
-                s->mult_sectors = 0;
-                s->status = READY_STAT | SEEK_STAT;
-            } else if ((s->nsector & 0xff) != 0 &&
-                ((s->nsector & 0xff) > MAX_MULT_SECTORS ||
-                 (s->nsector & (s->nsector - 1)) != 0)) {
-                ide_abort_command(s);
-            } else {
-                s->mult_sectors = s->nsector & 0xff;
-                s->status = READY_STAT | SEEK_STAT;
+            ide_transfer_start(s, s->io_buffer, 512, ide_transfer_stop);
+        } else {
+            if (s->drive_kind == IDE_CD) {
+                ide_set_signature(s);
             }
-            ide_set_irq(s->bus);
-            break;
-        case WIN_VERIFY_EXT:
-	    lba48 = 1;
-        case WIN_VERIFY:
-        case WIN_VERIFY_ONCE:
-            /* do sector number check ? */
-	    ide_cmd_lba48_transform(s, lba48);
+            ide_abort_command(s);
+        }
+        ide_set_irq(s->bus);
+        break;
+    case WIN_SPECIFY:
+    case WIN_RECAL:
+        s->error = 0;
+        s->status = READY_STAT | SEEK_STAT;
+        ide_set_irq(s->bus);
+        break;
+    case WIN_SETMULT:
+        if (s->drive_kind == IDE_CFATA && s->nsector == 0) {
+            /* Disable Read and Write Multiple */
+            s->mult_sectors = 0;
             s->status = READY_STAT | SEEK_STAT;
-            ide_set_irq(s->bus);
-            break;
+        } else if ((s->nsector & 0xff) != 0 &&
+            ((s->nsector & 0xff) > MAX_MULT_SECTORS ||
+             (s->nsector & (s->nsector - 1)) != 0)) {
+            ide_abort_command(s);
+        } else {
+            s->mult_sectors = s->nsector & 0xff;
+            s->status = READY_STAT | SEEK_STAT;
+        }
+        ide_set_irq(s->bus);
+        break;
+    case WIN_VERIFY_EXT:
+	lba48 = 1;
+    case WIN_VERIFY:
+    case WIN_VERIFY_ONCE:
+        /* do sector number check ? */
+	ide_cmd_lba48_transform(s, lba48);
+        s->status = READY_STAT | SEEK_STAT;
+        ide_set_irq(s->bus);
+        break;
 	case WIN_READ_EXT:
-	    lba48 = 1;
-        case WIN_READ:
-        case WIN_READ_ONCE:
-            if (!s->bs)
-                goto abort_cmd;
-	    ide_cmd_lba48_transform(s, lba48);
-            s->req_nb_sectors = 1;
-            ide_sector_read(s);
-            break;
+	lba48 = 1;
+    case WIN_READ:
+    case WIN_READ_ONCE:
+        if (!s->bs)
+            goto abort_cmd;
+	ide_cmd_lba48_transform(s, lba48);
+        s->req_nb_sectors = 1;
+        ide_sector_read(s);
+        break;
 	case WIN_WRITE_EXT:
-	    lba48 = 1;
-        case WIN_WRITE:
-        case WIN_WRITE_ONCE:
-        case CFA_WRITE_SECT_WO_ERASE:
-        case WIN_WRITE_VERIFY:
-	    ide_cmd_lba48_transform(s, lba48);
-            s->error = 0;
-            s->status = SEEK_STAT | READY_STAT;
-            s->req_nb_sectors = 1;
-            ide_transfer_start(s, s->io_buffer, 512, ide_sector_write);
-            s->media_changed = 1;
-            break;
+	lba48 = 1;
+    case WIN_WRITE:
+    case WIN_WRITE_ONCE:
+    case CFA_WRITE_SECT_WO_ERASE:
+    case WIN_WRITE_VERIFY:
+	ide_cmd_lba48_transform(s, lba48);
+        s->error = 0;
+        s->status = SEEK_STAT | READY_STAT;
+        s->req_nb_sectors = 1;
+        ide_transfer_start(s, s->io_buffer, 512, ide_sector_write);
+        s->media_changed = 1;
+        break;
 	case WIN_MULTREAD_EXT:
-	    lba48 = 1;
-        case WIN_MULTREAD:
-            if (!s->mult_sectors)
-                goto abort_cmd;
-	    ide_cmd_lba48_transform(s, lba48);
-            s->req_nb_sectors = s->mult_sectors;
-            ide_sector_read(s);
-            break;
-        case WIN_MULTWRITE_EXT:
-	    lba48 = 1;
-        case WIN_MULTWRITE:
-        case CFA_WRITE_MULTI_WO_ERASE:
-            if (!s->mult_sectors)
-                goto abort_cmd;
-	    ide_cmd_lba48_transform(s, lba48);
-            s->error = 0;
-            s->status = SEEK_STAT | READY_STAT;
-            s->req_nb_sectors = s->mult_sectors;
-            n = s->nsector;
-            if (n > s->req_nb_sectors)
-                n = s->req_nb_sectors;
-            ide_transfer_start(s, s->io_buffer, 512 * n, ide_sector_write);
-            s->media_changed = 1;
-            break;
+	lba48 = 1;
+    case WIN_MULTREAD:
+        if (!s->mult_sectors)
+            goto abort_cmd;
+	ide_cmd_lba48_transform(s, lba48);
+        s->req_nb_sectors = s->mult_sectors;
+        ide_sector_read(s);
+        break;
+    case WIN_MULTWRITE_EXT:
+	lba48 = 1;
+    case WIN_MULTWRITE:
+    case CFA_WRITE_MULTI_WO_ERASE:
+        if (!s->mult_sectors)
+            goto abort_cmd;
+	ide_cmd_lba48_transform(s, lba48);
+        s->error = 0;
+        s->status = SEEK_STAT | READY_STAT;
+        s->req_nb_sectors = s->mult_sectors;
+        n = s->nsector;
+        if (n > s->req_nb_sectors)
+            n = s->req_nb_sectors;
+        ide_transfer_start(s, s->io_buffer, 512 * n, ide_sector_write);
+        s->media_changed = 1;
+        break;
 	case WIN_READDMA_EXT:
-	    lba48 = 1;
-        case WIN_READDMA:
-        case WIN_READDMA_ONCE:
-            if (!s->bs)
-                goto abort_cmd;
-	    ide_cmd_lba48_transform(s, lba48);
-            ide_sector_read_dma(s);
-            break;
+	lba48 = 1;
+    case WIN_READDMA:
+    case WIN_READDMA_ONCE:
+        if (!s->bs)
+            goto abort_cmd;
+	ide_cmd_lba48_transform(s, lba48);
+        ide_sector_read_dma(s);
+        break;
 	case WIN_WRITEDMA_EXT:
-	    lba48 = 1;
-        case WIN_WRITEDMA:
-        case WIN_WRITEDMA_ONCE:
-            if (!s->bs)
-                goto abort_cmd;
-	    ide_cmd_lba48_transform(s, lba48);
-            ide_sector_write_dma(s);
-            s->media_changed = 1;
-            break;
-        case WIN_READ_NATIVE_MAX_EXT:
-	    lba48 = 1;
-        case WIN_READ_NATIVE_MAX:
-	    ide_cmd_lba48_transform(s, lba48);
-            ide_set_sector(s, s->nb_sectors - 1);
-            s->status = READY_STAT | SEEK_STAT;
-            ide_set_irq(s->bus);
-            break;
-        case WIN_CHECKPOWERMODE1:
-        case WIN_CHECKPOWERMODE2:
-            s->nsector = 0xff; /* device active or idle */
+	lba48 = 1;
+    case WIN_WRITEDMA:
+    case WIN_WRITEDMA_ONCE:
+        if (!s->bs)
+            goto abort_cmd;
+	ide_cmd_lba48_transform(s, lba48);
+        ide_sector_write_dma(s);
+        s->media_changed = 1;
+        break;
+    case WIN_READ_NATIVE_MAX_EXT:
+	lba48 = 1;
+    case WIN_READ_NATIVE_MAX:
+	ide_cmd_lba48_transform(s, lba48);
+        ide_set_sector(s, s->nb_sectors - 1);
+        s->status = READY_STAT | SEEK_STAT;
+        ide_set_irq(s->bus);
+        break;
+    case WIN_CHECKPOWERMODE1:
+    case WIN_CHECKPOWERMODE2:
+        s->nsector = 0xff; /* device active or idle */
+        s->status = READY_STAT | SEEK_STAT;
+        ide_set_irq(s->bus);
+        break;
+    case WIN_SETFEATURES:
+        if (!s->bs)
+            goto abort_cmd;
+        /* XXX: valid for CDROM ? */
+        switch(s->feature) {
+        case 0xcc: /* reverting to power-on defaults enable */
+        case 0x66: /* reverting to power-on defaults disable */
+        case 0x02: /* write cache enable */
+        case 0x82: /* write cache disable */
+        case 0xaa: /* read look-ahead enable */
+        case 0x55: /* read look-ahead disable */
+        case 0x05: /* set advanced power management mode */
+        case 0x85: /* disable advanced power management mode */
+        case 0x69: /* NOP */
+        case 0x67: /* NOP */
+        case 0x96: /* NOP */
+        case 0x9a: /* NOP */
+        case 0x42: /* enable Automatic Acoustic Mode */
+        case 0xc2: /* disable Automatic Acoustic Mode */
             s->status = READY_STAT | SEEK_STAT;
             ide_set_irq(s->bus);
             break;
-        case WIN_SETFEATURES:
-            if (!s->bs)
-                goto abort_cmd;
-            /* XXX: valid for CDROM ? */
-            switch(s->feature) {
-            case 0xcc: /* reverting to power-on defaults enable */
-            case 0x66: /* reverting to power-on defaults disable */
-            case 0x02: /* write cache enable */
-            case 0x82: /* write cache disable */
-            case 0xaa: /* read look-ahead enable */
-            case 0x55: /* read look-ahead disable */
-            case 0x05: /* set advanced power management mode */
-            case 0x85: /* disable advanced power management mode */
-            case 0x69: /* NOP */
-            case 0x67: /* NOP */
-            case 0x96: /* NOP */
-            case 0x9a: /* NOP */
-            case 0x42: /* enable Automatic Acoustic Mode */
-            case 0xc2: /* disable Automatic Acoustic Mode */
-                s->status = READY_STAT | SEEK_STAT;
-                ide_set_irq(s->bus);
-                break;
-            case 0x03: { /* set transfer mode */
+        case 0x03: { /* set transfer mode */
 		uint8_t val = s->nsector & 0x07;
-                uint16_t *identify_data = (uint16_t *)s->identify_data;
+            uint16_t *identify_data = (uint16_t *)s->identify_data;
 
 		switch (s->nsector >> 3) {
-		    case 0x00: /* pio default */
-		    case 0x01: /* pio mode */
+		case 0x00: /* pio default */
+		case 0x01: /* pio mode */
 			put_le16(identify_data + 62,0x07);
 			put_le16(identify_data + 63,0x07);
 			put_le16(identify_data + 88,0x3f);
 			break;
-                    case 0x02: /* sigle word dma mode*/
+                case 0x02: /* sigle word dma mode*/
 			put_le16(identify_data + 62,0x07 | (1 << (val + 8)));
 			put_le16(identify_data + 63,0x07);
 			put_le16(identify_data + 88,0x3f);
 			break;
-		    case 0x04: /* mdma mode */
+		case 0x04: /* mdma mode */
 			put_le16(identify_data + 62,0x07);
 			put_le16(identify_data + 63,0x07 | (1 << (val + 8)));
 			put_le16(identify_data + 88,0x3f);
 			break;
-		    case 0x08: /* udma mode */
+		case 0x08: /* udma mode */
 			put_le16(identify_data + 62,0x07);
 			put_le16(identify_data + 63,0x07);
 			put_le16(identify_data + 88,0x3f | (1 << (val + 8)));
 			break;
-		    default:
+		default:
 			goto abort_cmd;
 		}
-                s->status = READY_STAT | SEEK_STAT;
-                ide_set_irq(s->bus);
-                break;
-	    }
-            default:
-                goto abort_cmd;
-            }
-            break;
-        case WIN_FLUSH_CACHE:
-        case WIN_FLUSH_CACHE_EXT:
-            ide_flush_cache(s);
-            break;
-        case WIN_STANDBY:
-        case WIN_STANDBY2:
-        case WIN_STANDBYNOW1:
-        case WIN_STANDBYNOW2:
-        case WIN_IDLEIMMEDIATE:
-        case CFA_IDLEIMMEDIATE:
-        case WIN_SETIDLE1:
-        case WIN_SETIDLE2:
-        case WIN_SLEEPNOW1:
-        case WIN_SLEEPNOW2:
-            s->status = READY_STAT;
-            ide_set_irq(s->bus);
-            break;
-        case WIN_SEEK:
-            if(s->drive_kind == IDE_CD)
-                goto abort_cmd;
-            /* XXX: Check that seek is within bounds */
             s->status = READY_STAT | SEEK_STAT;
             ide_set_irq(s->bus);
             break;
-            /* ATAPI commands */
-        case WIN_PIDENTIFY:
-            if (s->drive_kind == IDE_CD) {
-                ide_atapi_identify(s);
-                s->status = READY_STAT | SEEK_STAT;
-                ide_transfer_start(s, s->io_buffer, 512, ide_transfer_stop);
-            } else {
-                ide_abort_command(s);
-            }
-            ide_set_irq(s->bus);
-            break;
-        case WIN_DIAGNOSE:
-            ide_set_signature(s);
-            if (s->drive_kind == IDE_CD)
-                s->status = 0; /* ATAPI spec (v6) section 9.10 defines packet
-                                * devices to return a clear status register
-                                * with READY_STAT *not* set. */
-            else
-                s->status = READY_STAT | SEEK_STAT;
-            s->error = 0x01; /* Device 0 passed, Device 1 passed or not
-                              * present. 
-                              */
-            ide_set_irq(s->bus);
-            break;
-        case WIN_SRST:
-            if (s->drive_kind != IDE_CD)
-                goto abort_cmd;
-            ide_set_signature(s);
-            s->status = 0x00; /* NOTE: READY is _not_ set */
-            s->error = 0x01;
-            break;
-        case WIN_PACKETCMD:
-            if (s->drive_kind != IDE_CD)
-                goto abort_cmd;
-            /* overlapping commands not supported */
-            if (s->feature & 0x02)
-                goto abort_cmd;
+	}
+        default:
+            goto abort_cmd;
+        }
+        break;
+    case WIN_FLUSH_CACHE:
+    case WIN_FLUSH_CACHE_EXT:
+        ide_flush_cache(s);
+        break;
+    case WIN_STANDBY:
+    case WIN_STANDBY2:
+    case WIN_STANDBYNOW1:
+    case WIN_STANDBYNOW2:
+    case WIN_IDLEIMMEDIATE:
+    case CFA_IDLEIMMEDIATE:
+    case WIN_SETIDLE1:
+    case WIN_SETIDLE2:
+    case WIN_SLEEPNOW1:
+    case WIN_SLEEPNOW2:
+        s->status = READY_STAT;
+        ide_set_irq(s->bus);
+        break;
+    case WIN_SEEK:
+        if(s->drive_kind == IDE_CD)
+            goto abort_cmd;
+        /* XXX: Check that seek is within bounds */
+        s->status = READY_STAT | SEEK_STAT;
+        ide_set_irq(s->bus);
+        break;
+        /* ATAPI commands */
+    case WIN_PIDENTIFY:
+        if (s->drive_kind == IDE_CD) {
+            ide_atapi_identify(s);
             s->status = READY_STAT | SEEK_STAT;
-            s->atapi_dma = s->feature & 1;
-            s->nsector = 1;
-            ide_transfer_start(s, s->io_buffer, ATAPI_PACKET_SIZE,
-                               ide_atapi_cmd);
-            break;
-        /* CF-ATA commands */
-        case CFA_REQ_EXT_ERROR_CODE:
-            if (s->drive_kind != IDE_CFATA)
-                goto abort_cmd;
-            s->error = 0x09;    /* miscellaneous error */
+            ide_transfer_start(s, s->io_buffer, 512, ide_transfer_stop);
+        } else {
+            ide_abort_command(s);
+        }
+        ide_set_irq(s->bus);
+        break;
+    case WIN_DIAGNOSE:
+        ide_set_signature(s);
+        if (s->drive_kind == IDE_CD)
+            s->status = 0; /* ATAPI spec (v6) section 9.10 defines packet
+                            * devices to return a clear status register
+                            * with READY_STAT *not* set. */
+        else
             s->status = READY_STAT | SEEK_STAT;
-            ide_set_irq(s->bus);
+        s->error = 0x01; /* Device 0 passed, Device 1 passed or not
+                          * present. 
+                          */
+        ide_set_irq(s->bus);
+        break;
+    case WIN_SRST:
+        if (s->drive_kind != IDE_CD)
+            goto abort_cmd;
+        ide_set_signature(s);
+        s->status = 0x00; /* NOTE: READY is _not_ set */
+        s->error = 0x01;
+        break;
+    case WIN_PACKETCMD:
+        if (s->drive_kind != IDE_CD)
+            goto abort_cmd;
+        /* overlapping commands not supported */
+        if (s->feature & 0x02)
+            goto abort_cmd;
+        s->status = READY_STAT | SEEK_STAT;
+        s->atapi_dma = s->feature & 1;
+        s->nsector = 1;
+        ide_transfer_start(s, s->io_buffer, ATAPI_PACKET_SIZE,
+                           ide_atapi_cmd);
+        break;
+    /* CF-ATA commands */
+    case CFA_REQ_EXT_ERROR_CODE:
+        if (s->drive_kind != IDE_CFATA)
+            goto abort_cmd;
+        s->error = 0x09;    /* miscellaneous error */
+        s->status = READY_STAT | SEEK_STAT;
+        ide_set_irq(s->bus);
+        break;
+    case CFA_ERASE_SECTORS:
+    case CFA_WEAR_LEVEL:
+        if (s->drive_kind != IDE_CFATA)
+            goto abort_cmd;
+        if (val == CFA_WEAR_LEVEL)
+            s->nsector = 0;
+        if (val == CFA_ERASE_SECTORS)
+            s->media_changed = 1;
+        s->error = 0x00;
+        s->status = READY_STAT | SEEK_STAT;
+        ide_set_irq(s->bus);
+        break;
+    case CFA_TRANSLATE_SECTOR:
+        if (s->drive_kind != IDE_CFATA)
+            goto abort_cmd;
+        s->error = 0x00;
+        s->status = READY_STAT | SEEK_STAT;
+        memset(s->io_buffer, 0, 0x200);
+        s->io_buffer[0x00] = s->hcyl;			/* Cyl MSB */
+        s->io_buffer[0x01] = s->lcyl;			/* Cyl LSB */
+        s->io_buffer[0x02] = s->select;			/* Head */
+        s->io_buffer[0x03] = s->sector;			/* Sector */
+        s->io_buffer[0x04] = ide_get_sector(s) >> 16;	/* LBA MSB */
+        s->io_buffer[0x05] = ide_get_sector(s) >> 8;	/* LBA */
+        s->io_buffer[0x06] = ide_get_sector(s) >> 0;	/* LBA LSB */
+        s->io_buffer[0x13] = 0x00;				/* Erase flag */
+        s->io_buffer[0x18] = 0x00;				/* Hot count */
+        s->io_buffer[0x19] = 0x00;				/* Hot count */
+        s->io_buffer[0x1a] = 0x01;				/* Hot count */
+        ide_transfer_start(s, s->io_buffer, 0x200, ide_transfer_stop);
+        ide_set_irq(s->bus);
+        break;
+    case CFA_ACCESS_METADATA_STORAGE:
+        if (s->drive_kind != IDE_CFATA)
+            goto abort_cmd;
+        switch (s->feature) {
+        case 0x02:	/* Inquiry Metadata Storage */
+            ide_cfata_metadata_inquiry(s);
             break;
-        case CFA_ERASE_SECTORS:
-        case CFA_WEAR_LEVEL:
-            if (s->drive_kind != IDE_CFATA)
-                goto abort_cmd;
-            if (val == CFA_WEAR_LEVEL)
-                s->nsector = 0;
-            if (val == CFA_ERASE_SECTORS)
-                s->media_changed = 1;
-            s->error = 0x00;
-            s->status = READY_STAT | SEEK_STAT;
-            ide_set_irq(s->bus);
+        case 0x03:	/* Read Metadata Storage */
+            ide_cfata_metadata_read(s);
             break;
-        case CFA_TRANSLATE_SECTOR:
-            if (s->drive_kind != IDE_CFATA)
-                goto abort_cmd;
-            s->error = 0x00;
-            s->status = READY_STAT | SEEK_STAT;
-            memset(s->io_buffer, 0, 0x200);
-            s->io_buffer[0x00] = s->hcyl;			/* Cyl MSB */
-            s->io_buffer[0x01] = s->lcyl;			/* Cyl LSB */
-            s->io_buffer[0x02] = s->select;			/* Head */
-            s->io_buffer[0x03] = s->sector;			/* Sector */
-            s->io_buffer[0x04] = ide_get_sector(s) >> 16;	/* LBA MSB */
-            s->io_buffer[0x05] = ide_get_sector(s) >> 8;	/* LBA */
-            s->io_buffer[0x06] = ide_get_sector(s) >> 0;	/* LBA LSB */
-            s->io_buffer[0x13] = 0x00;				/* Erase flag */
-            s->io_buffer[0x18] = 0x00;				/* Hot count */
-            s->io_buffer[0x19] = 0x00;				/* Hot count */
-            s->io_buffer[0x1a] = 0x01;				/* Hot count */
-            ide_transfer_start(s, s->io_buffer, 0x200, ide_transfer_stop);
-            ide_set_irq(s->bus);
+        case 0x04:	/* Write Metadata Storage */
+            ide_cfata_metadata_write(s);
             break;
-        case CFA_ACCESS_METADATA_STORAGE:
-            if (s->drive_kind != IDE_CFATA)
-                goto abort_cmd;
-            switch (s->feature) {
-            case 0x02:	/* Inquiry Metadata Storage */
-                ide_cfata_metadata_inquiry(s);
-                break;
-            case 0x03:	/* Read Metadata Storage */
-                ide_cfata_metadata_read(s);
-                break;
-            case 0x04:	/* Write Metadata Storage */
-                ide_cfata_metadata_write(s);
-                break;
-            default:
-                goto abort_cmd;
-            }
-            ide_transfer_start(s, s->io_buffer, 0x200, ide_transfer_stop);
-            s->status = 0x00; /* NOTE: READY is _not_ set */
-            ide_set_irq(s->bus);
-            break;
-        case IBM_SENSE_CONDITION:
-            if (s->drive_kind != IDE_CFATA)
-                goto abort_cmd;
-            switch (s->feature) {
-            case 0x01:  /* sense temperature in device */
-                s->nsector = 0x50;      /* +20 C */
-                break;
-            default:
-                goto abort_cmd;
-            }
-            s->status = READY_STAT | SEEK_STAT;
-            ide_set_irq(s->bus);
+        default:
+            goto abort_cmd;
+        }
+        ide_transfer_start(s, s->io_buffer, 0x200, ide_transfer_stop);
+        s->status = 0x00; /* NOTE: READY is _not_ set */
+        ide_set_irq(s->bus);
+        break;
+    case IBM_SENSE_CONDITION:
+        if (s->drive_kind != IDE_CFATA)
+            goto abort_cmd;
+        switch (s->feature) {
+        case 0x01:  /* sense temperature in device */
+            s->nsector = 0x50;      /* +20 C */
             break;
+        default:
+            goto abort_cmd;
+        }
+        s->status = READY_STAT | SEEK_STAT;
+        ide_set_irq(s->bus);
+        break;
 
 	case WIN_SMART:
-	    if (s->drive_kind == IDE_CD)
+	if (s->drive_kind == IDE_CD)
 		goto abort_cmd;
-	    if (s->hcyl != 0xc2 || s->lcyl != 0x4f)
+	if (s->hcyl != 0xc2 || s->lcyl != 0x4f)
 		goto abort_cmd;
-	    if (!s->smart_enabled && s->feature != SMART_ENABLE)
+	if (!s->smart_enabled && s->feature != SMART_ENABLE)
 		goto abort_cmd;
-	    switch (s->feature) {
-	    case SMART_DISABLE:
+	switch (s->feature) {
+	case SMART_DISABLE:
 		s->smart_enabled = 0;
 		s->status = READY_STAT | SEEK_STAT;
 		ide_set_irq(s->bus);
 		break;
-	    case SMART_ENABLE:
+	case SMART_ENABLE:
 		s->smart_enabled = 1;
 		s->status = READY_STAT | SEEK_STAT;
 		ide_set_irq(s->bus);
 		break;
-	    case SMART_ATTR_AUTOSAVE:
+	case SMART_ATTR_AUTOSAVE:
 		switch (s->sector) {
 		case 0x00:
-		    s->smart_autosave = 0;
-		    break;
+		s->smart_autosave = 0;
+		break;
 		case 0xf1:
-		    s->smart_autosave = 1;
-		    break;
+		s->smart_autosave = 1;
+		break;
 		default:
-		    goto abort_cmd;
+		goto abort_cmd;
 		}
 		s->status = READY_STAT | SEEK_STAT;
 		ide_set_irq(s->bus);
 		break;
-	    case SMART_STATUS:
+	case SMART_STATUS:
 		if (!s->smart_errors) {
-		    s->hcyl = 0xc2;
-		    s->lcyl = 0x4f;
+		s->hcyl = 0xc2;
+		s->lcyl = 0x4f;
 		} else {
-		    s->hcyl = 0x2c;
-		    s->lcyl = 0xf4;
+		s->hcyl = 0x2c;
+		s->lcyl = 0xf4;
 		}
 		s->status = READY_STAT | SEEK_STAT;
 		ide_set_irq(s->bus);
 		break;
-	    case SMART_READ_THRESH:
+	case SMART_READ_THRESH:
 		memset(s->io_buffer, 0, 0x200);
 		s->io_buffer[0] = 0x01; /* smart struct version */
 		for (n=0; n<30; n++) {
-		    if (smart_attributes[n][0] == 0)
+		if (smart_attributes[n][0] == 0)
 			break;
-		    s->io_buffer[2+0+(n*12)] = smart_attributes[n][0];
-		    s->io_buffer[2+1+(n*12)] = smart_attributes[n][4];
+		s->io_buffer[2+0+(n*12)] = smart_attributes[n][0];
+		s->io_buffer[2+1+(n*12)] = smart_attributes[n][4];
 		}
 		for (n=0; n<511; n++) /* checksum */
-		    s->io_buffer[511] += s->io_buffer[n];
+		s->io_buffer[511] += s->io_buffer[n];
 		s->io_buffer[511] = 0x100 - s->io_buffer[511];
 		s->status = READY_STAT | SEEK_STAT;
 		ide_transfer_start(s, s->io_buffer, 0x200, ide_transfer_stop);
 		ide_set_irq(s->bus);
 		break;
-	    case SMART_READ_DATA:
+	case SMART_READ_DATA:
 		memset(s->io_buffer, 0, 0x200);
 		s->io_buffer[0] = 0x01; /* smart struct version */
 		for (n=0; n<30; n++) {
-		    if (smart_attributes[n][0] == 0)
+		if (smart_attributes[n][0] == 0)
 			break;
-		    s->io_buffer[2+0+(n*12)] = smart_attributes[n][0];
-		    s->io_buffer[2+1+(n*12)] = smart_attributes[n][1];
-		    s->io_buffer[2+3+(n*12)] = smart_attributes[n][2];
-		    s->io_buffer[2+4+(n*12)] = smart_attributes[n][3];
+		s->io_buffer[2+0+(n*12)] = smart_attributes[n][0];
+		s->io_buffer[2+1+(n*12)] = smart_attributes[n][1];
+		s->io_buffer[2+3+(n*12)] = smart_attributes[n][2];
+		s->io_buffer[2+4+(n*12)] = smart_attributes[n][3];
 		}
 		s->io_buffer[362] = 0x02 | (s->smart_autosave?0x80:0x00);
 		if (s->smart_selftest_count == 0) {
-		    s->io_buffer[363] = 0;
+		s->io_buffer[363] = 0;
 		} else {
-		    s->io_buffer[363] = 
+		s->io_buffer[363] = 
 			s->smart_selftest_data[3 + 
-					       (s->smart_selftest_count - 1) * 
-					       24];
+					   (s->smart_selftest_count - 1) * 
+					   24];
 		}
 		s->io_buffer[364] = 0x20; 
 		s->io_buffer[365] = 0x01; 
@@ -2293,76 +2293,76 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)
 		s->io_buffer[374] = 0x01; /* minutes for poll conveyance */
 
 		for (n=0; n<511; n++) 
-		    s->io_buffer[511] += s->io_buffer[n];
+		s->io_buffer[511] += s->io_buffer[n];
 		s->io_buffer[511] = 0x100 - s->io_buffer[511];
 		s->status = READY_STAT | SEEK_STAT;
 		ide_transfer_start(s, s->io_buffer, 0x200, ide_transfer_stop);
 		ide_set_irq(s->bus);
 		break;
-	    case SMART_READ_LOG:
+	case SMART_READ_LOG:
 		switch (s->sector) {
 		case 0x01: /* summary smart error log */
-		    memset(s->io_buffer, 0, 0x200);
-		    s->io_buffer[0] = 0x01;
-		    s->io_buffer[1] = 0x00; /* no error entries */
-		    s->io_buffer[452] = s->smart_errors & 0xff;
-		    s->io_buffer[453] = (s->smart_errors & 0xff00) >> 8;
+		memset(s->io_buffer, 0, 0x200);
+		s->io_buffer[0] = 0x01;
+		s->io_buffer[1] = 0x00; /* no error entries */
+		s->io_buffer[452] = s->smart_errors & 0xff;
+		s->io_buffer[453] = (s->smart_errors & 0xff00) >> 8;
 
-		    for (n=0; n<511; n++)
+		for (n=0; n<511; n++)
 			s->io_buffer[511] += s->io_buffer[n];
-		    s->io_buffer[511] = 0x100 - s->io_buffer[511];
-		    break;
+		s->io_buffer[511] = 0x100 - s->io_buffer[511];
+		break;
 		case 0x06: /* smart self test log */
-		    memset(s->io_buffer, 0, 0x200);
-		    s->io_buffer[0] = 0x01; 
-		    if (s->smart_selftest_count == 0) {
+		memset(s->io_buffer, 0, 0x200);
+		s->io_buffer[0] = 0x01; 
+		if (s->smart_selftest_count == 0) {
 			s->io_buffer[508] = 0;
-		    } else {
+		} else {
 			s->io_buffer[508] = s->smart_selftest_count;
 			for (n=2; n<506; n++) 
-			    s->io_buffer[n] = s->smart_selftest_data[n];
-		    }		    
-		    for (n=0; n<511; n++)
+			s->io_buffer[n] = s->smart_selftest_data[n];
+		}		    
+		for (n=0; n<511; n++)
 			s->io_buffer[511] += s->io_buffer[n];
-		    s->io_buffer[511] = 0x100 - s->io_buffer[511];
-		    break;
+		s->io_buffer[511] = 0x100 - s->io_buffer[511];
+		break;
 		default:
-		    goto abort_cmd;
+		goto abort_cmd;
 		}
 		s->status = READY_STAT | SEEK_STAT;
 		ide_transfer_start(s, s->io_buffer, 0x200, ide_transfer_stop);
 		ide_set_irq(s->bus);
 		break;
-	    case SMART_EXECUTE_OFFLINE:
+	case SMART_EXECUTE_OFFLINE:
 		switch (s->sector) {
 		case 0: /* off-line routine */
 		case 1: /* short self test */
 		case 2: /* extended self test */
-		    s->smart_selftest_count++;
-		    if(s->smart_selftest_count > 21)
+		s->smart_selftest_count++;
+		if(s->smart_selftest_count > 21)
 			s->smart_selftest_count = 0;
-		    n = 2 + (s->smart_selftest_count - 1) * 24;
-		    s->smart_selftest_data[n] = s->sector;
-		    s->smart_selftest_data[n+1] = 0x00; /* OK and finished */
-		    s->smart_selftest_data[n+2] = 0x34; /* hour count lsb */
-		    s->smart_selftest_data[n+3] = 0x12; /* hour count msb */
-		    s->status = READY_STAT | SEEK_STAT;
-		    ide_set_irq(s->bus);
-		    break;
+		n = 2 + (s->smart_selftest_count - 1) * 24;
+		s->smart_selftest_data[n] = s->sector;
+		s->smart_selftest_data[n+1] = 0x00; /* OK and finished */
+		s->smart_selftest_data[n+2] = 0x34; /* hour count lsb */
+		s->smart_selftest_data[n+3] = 0x12; /* hour count msb */
+		s->status = READY_STAT | SEEK_STAT;
+		ide_set_irq(s->bus);
+		break;
 		default:
-		    goto abort_cmd;
+		goto abort_cmd;
 		}
 		break;
-	    default:
+	default:
 		goto abort_cmd;
-	    }
-	    break;
-        default:
-        abort_cmd:
-            ide_abort_command(s);
-            ide_set_irq(s->bus);
-            break;
-        }
+	}
+	break;
+    default:
+    abort_cmd:
+        ide_abort_command(s);
+        ide_set_irq(s->bus);
+        break;
+    }
 }
 
 uint32_t ide_ioport_read(void *opaque, uint32_t addr1)
Signature · 1 line
1.6.0.2
#5 lore raw

PATCH 3/13 ide: add support for ide bus ops

In reply to Alexander Graf

From: Roland Elek <[email protected]>

We need to hook into some of the core IDE functionality for AHCI. To do that, the easiest way is to make explicit functions calls be implicit through a function call struct.

---

v1 -> v2:

- rename IDEExtender to IDEBusOps and make a pointer (kraxel)

---
 hw/ide/core.c     |   36 +++++++++++++++++++++++++++++++++++-
 hw/ide/internal.h |   26 +++++++++++++++++++-------
 2 files changed, 54 insertions(+), 8 deletions(-)
hw/ide/core.c +35 -1
index 1849069..c8d7810 100644
@@ -67,6 +67,8 @@ static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret);
 static int ide_handle_rw_error(IDEState *s, int error, int op);
 static void ide_flush_cache(IDEState *s);
 
+static void pata_dma_start(IDEState *s, BlockDriverCompletionFunc *dma_cb);
+
 static void padstr(char *str, const char *src, int len)
 {
     int i, v;
@@ -325,6 +327,12 @@ static inline void ide_dma_submit_check(IDEState *s,
 static void ide_transfer_start(IDEState *s, uint8_t *buf, int size,
                                EndTransferFunc *end_transfer_func)
 {
+    s->bus->ops->transfer_start_fn(s,buf,size,end_transfer_func);
+}
+
+static void pata_transfer_start(IDEState *s, uint8_t *buf, int size,
+                               EndTransferFunc *end_transfer_func)
+{
     s->end_transfer_func = end_transfer_func;
     s->data_ptr = buf;
     s->data_end = buf + size;
@@ -2580,6 +2588,18 @@ static void ide_dummy_transfer_stop(IDEState *s)
     s->io_buffer[3] = 0xff;
 }
 
+static void pata_set_irq(IDEBus *bus)
+{
+    BMDMAState *bm = bus->bmdma;
+
+    if (!(bus->cmd & IDE_CMD_DISABLE_IRQ)) {
+        if (bm) {
+            bm->status |= BM_STATUS_INT;
+        }
+        qemu_irq_raise(bus->irq);
+    }
+}
+
 static void ide_reset(IDEState *s)
 {
 #ifdef DEBUG_IDE
@@ -2716,6 +2736,12 @@ static void ide_init1(IDEBus *bus, int unit)
                                            ide_sector_write_timer_cb, s);
 }
 
+static IDEBusOps ide_bus_ops = {
+    .transfer_start_fn = pata_transfer_start,
+    .irq_set_fn = pata_set_irq,
+    .dma_start_fn = pata_dma_start,
+};
+
 void ide_init2(IDEBus *bus, qemu_irq irq)
 {
     int i;
@@ -2725,6 +2751,7 @@ void ide_init2(IDEBus *bus, qemu_irq irq)
         ide_reset(&bus->ifs[i]);
     }
     bus->irq = irq;
+    bus->ops = &ide_bus_ops;
 }
 
 /* TODO convert users to qdev and remove */
@@ -2748,6 +2775,7 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0,
         }
     }
     bus->irq = irq;
+    bus->ops = &ide_bus_ops;
 }
 
 void ide_init_ioport(IDEBus *bus, int iobase, int iobase2)
@@ -2919,9 +2947,10 @@ const VMStateDescription vmstate_ide_bus = {
 /***********************************************************/
 /* PCI IDE definitions */
 
-static void ide_dma_start(IDEState *s, BlockDriverCompletionFunc *dma_cb)
+static void pata_dma_start(IDEState *s, BlockDriverCompletionFunc *dma_cb)
 {
     BMDMAState *bm = s->bus->bmdma;
+
     if(!bm)
         return;
     bm->unit = s->unit;
@@ -2936,6 +2965,11 @@ static void ide_dma_start(IDEState *s, BlockDriverCompletionFunc *dma_cb)
     }
 }
 
+static void ide_dma_start(IDEState *s, BlockDriverCompletionFunc *dma_cb)
+{
+    s->bus->ops->dma_start_fn(s,dma_cb);
+}
+
 static void ide_dma_restart(IDEState *s, int is_read)
 {
     BMDMAState *bm = s->bus->bmdma;
hw/ide/internal.h +19 -7
index e7e1f80..ee7e13e 100644
@@ -20,6 +20,7 @@ typedef struct IDEDevice IDEDevice;
 typedef struct IDEDeviceInfo IDEDeviceInfo;
 typedef struct IDEState IDEState;
 typedef struct BMDMAState BMDMAState;
+typedef struct IDEBusOps IDEBusOps;
 
 /* Bits of HD_STATUS */
 #define ERR_STAT		0x01
@@ -366,6 +367,14 @@ typedef enum { IDE_HD, IDE_CD, IDE_CFATA } IDEDriveKind;
 
 typedef void EndTransferFunc(IDEState *);
 
+
+typedef void TransferStartFunc(IDEState *,
+                             uint8_t *,
+                             int,
+                             EndTransferFunc *);
+typedef void IRQSetFunc(IDEBus *);
+typedef void DMAStartFunc(IDEState *, BlockDriverCompletionFunc *);
+
 /* NOTE: IDEState represents in fact one drive */
 struct IDEState {
     IDEBus *bus;
@@ -442,12 +451,21 @@ struct IDEState {
     uint8_t *smart_selftest_data;
 };
 
+/* This struct represents a device that uses an IDE bus, but requires
+ * modifications to how it works. An example is AHCI. */
+struct IDEBusOps {
+    TransferStartFunc *transfer_start_fn;
+    IRQSetFunc *irq_set_fn;
+    DMAStartFunc *dma_start_fn;
+};
+
 struct IDEBus {
     BusState qbus;
     IDEDevice *master;
     IDEDevice *slave;
     BMDMAState *bmdma;
     IDEState ifs[2];
+    IDEBusOps *ops;
     uint8_t unit;
     uint8_t cmd;
     qemu_irq irq;
@@ -512,13 +530,7 @@ static inline IDEState *bmdma_active_if(BMDMAState *bmdma)
 
 static inline void ide_set_irq(IDEBus *bus)
 {
-    BMDMAState *bm = bus->bmdma;
-    if (!(bus->cmd & IDE_CMD_DISABLE_IRQ)) {
-        if (bm) {
-            bm->status |= BM_STATUS_INT;
-        }
-        qemu_irq_raise(bus->irq);
-    }
+    bus->ops->irq_set_fn(bus);
 }
 
 /* hw/ide/core.c */
Signature · 1 line
1.6.0.2
#6 lore raw

[Qemu-devel] Re: [PATCH 03/13] ide: add support for ide bus ops

On Fri, Nov 26, 2010 at 7:17 PM, Alexander Graf <[email protected]> wrote:
Just some cosmetic suggestions.

hw/ide/core.c static void ide_init1(IDEBus *bus, int unit) · line 2739

Quoted 5 lines
hw/ide/core.c +1 -0
@@ -2716,6 +2736,12 @@ static void ide_init1(IDEBus *bus, int unit)
                                            ide_sector_write_timer_cb, s);
  }
 
+static IDEBusOps ide_bus_ops = {

Since the functions are all pata_* I think it makes sense for this to be called pata_bus_ops, not ide_bus_ops.

hw/ide/core.c static void ide_init1(IDEBus *bus, int unit) · line 2741

Quoted 2 lines
hw/ide/core.c +2 -0
+    .transfer_start_fn = pata_transfer_start,
+    .irq_set_fn = pata_set_irq,

irq_set or set_irq? :) Let's consistently go with set_irq.

Stefan

#7 lore raw

[Qemu-devel] Re: [PATCH 03/13] ide: add support for ide bus ops

Am 01.12.2010 14:09, schrieb Stefan Hajnoczi:

Quoted 12 lines · Alexander Graf

Just some cosmetic suggestions.

hw/ide/core.c static void ide_init1(IDEBus *bus, int unit) · line 2739

Quoted 5 lines
hw/ide/core.c +1 -0
@@ -2716,6 +2736,12 @@ static void ide_init1(IDEBus *bus, int unit)
                                           ide_sector_write_timer_cb, s);
 }
 
+static IDEBusOps ide_bus_ops = {

Since the functions are all pata_* I think it makes sense for this to be called pata_bus_ops, not ide_bus_ops.

Quoted 4 lines

hw/ide/core.c static void ide_init1(IDEBus *bus, int unit) · line 2741

Quoted 2 lines
hw/ide/core.c +2 -0
+    .transfer_start_fn = pata_transfer_start,
+    .irq_set_fn = pata_set_irq,

irq_set or set_irq? :) Let's consistently go with set_irq.

And drop the _fn suffix? It's really obvious that these are functions (if this is what it's meant to say).

Kevin

#8 lore raw

[Qemu-devel] Re: [PATCH 03/13] ide: add support for ide bus ops

Quoted 13 lines · Kevin Wolf

Am 01.12.2010 14:09, schrieb Stefan Hajnoczi:

Quoted 12 lines · Alexander Graf

Just some cosmetic suggestions.

hw/ide/core.c static void ide_init1(IDEBus *bus, int unit) · line 2739

Quoted 5 lines
hw/ide/core.c +1 -0
@@ -2716,6 +2736,12 @@ static void ide_init1(IDEBus *bus, int unit)
                                          ide_sector_write_timer_cb, s);
 }
 
+static IDEBusOps ide_bus_ops = {

Since the functions are all pata_* I think it makes sense for this to be called pata_bus_ops, not ide_bus_ops.

Quoted 7 lines
Quoted 4 lines

hw/ide/core.c static void ide_init1(IDEBus *bus, int unit) · line 2741

Quoted 2 lines
hw/ide/core.c +2 -0
+    .transfer_start_fn = pata_transfer_start,
+    .irq_set_fn = pata_set_irq,

irq_set or set_irq? :) Let's consistently go with set_irq.

And drop the _fn suffix? It's really obvious that these are functions (if this is what it's meant to say).

Good points :)

Alex

#9 lore raw

PATCH 4/13 ide: add DMA hooks to bus ops

In reply to Alexander Graf

For DMA operations, we need to hook into even more IDE functionality.

This patch adds the respective hooking points, allowing us to handle SG lists ourselves in the AHCI code.

---

v1 -> v2:

- make dma hooks explicit by putting them into ops struct (stefanha)

---
 hw/ide/core.c     |    9 ++++++---
 hw/ide/internal.h |    4 ++++
 2 files changed, 10 insertions(+), 3 deletions(-)
hw/ide/core.c +6 -3
index c8d7810..04190d2 100644
@@ -607,7 +607,7 @@ static void ide_read_dma_cb(void *opaque, int ret)
     n = s->nsector;
     s->io_buffer_index = 0;
     s->io_buffer_size = n * 512;
-    if (dma_buf_prepare(bm, 1) == 0)
+    if (s->bus->ops->dma_prepare_fn(bm, 1) == 0)
         goto eot;
 #ifdef DEBUG_AIO
     printf("aio_read: sector_num=%" PRId64 " n=%d\n", sector_num, n);
@@ -752,7 +752,7 @@ static void ide_write_dma_cb(void *opaque, int ret)
     n = s->nsector;
     s->io_buffer_size = n * 512;
     /* launch next transfer */
-    if (dma_buf_prepare(bm, 0) == 0)
+    if (s->bus->ops->dma_prepare_fn(bm, 0) == 0)
         goto eot;
 #ifdef DEBUG_AIO
     printf("aio_write: sector_num=%" PRId64 " n=%d\n", sector_num, n);
@@ -1060,7 +1060,7 @@ static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret)
 	    s->lba += n;
 	}
         s->packet_transfer_size -= s->io_buffer_size;
-        if (dma_buf_rw(bm, 1) == 0)
+        if (s->bus->ops->dma_rw_fn(bm, 1) == 0)
             goto eot;
     }
 
@@ -2715,6 +2715,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs,
     } else {
         pstrcpy(s->version, sizeof(s->version), QEMU_VERSION);
     }
+
     ide_reset(s);
     bdrv_set_removable(bs, s->drive_kind == IDE_CD);
     return 0;
@@ -2740,6 +2741,8 @@ static IDEBusOps ide_bus_ops = {
     .transfer_start_fn = pata_transfer_start,
     .irq_set_fn = pata_set_irq,
     .dma_start_fn = pata_dma_start,
+    .dma_prepare_fn = dma_buf_prepare,
+    .dma_rw_fn = dma_buf_rw,
 };
 
 void ide_init2(IDEBus *bus, qemu_irq irq)
hw/ide/internal.h +4 -0
index ee7e13e..4bee636 100644
@@ -374,6 +374,8 @@ typedef void TransferStartFunc(IDEState *,
                              EndTransferFunc *);
 typedef void IRQSetFunc(IDEBus *);
 typedef void DMAStartFunc(IDEState *, BlockDriverCompletionFunc *);
+typedef int DMAPrepareFunc(BMDMAState *, int);
+typedef int DMARWFunc(BMDMAState *, int);
 
 /* NOTE: IDEState represents in fact one drive */
 struct IDEState {
@@ -457,6 +459,8 @@ struct IDEBusOps {
     TransferStartFunc *transfer_start_fn;
     IRQSetFunc *irq_set_fn;
     DMAStartFunc *dma_start_fn;
+    DMAPrepareFunc *dma_prepare_fn;
+    DMARWFunc *dma_rw_fn;
 };
 
 struct IDEBus {
Signature · 1 line
1.6.0.2
Reviewed-by on v1 4/13
#10 lore raw

[Qemu-devel] Re: [PATCH 04/13] ide: add DMA hooks to bus ops

Quoted 10 lines · Alexander Graf

For DMA operations, we need to hook into even more IDE functionality.

This patch adds the respective hooking points, allowing us to handle SG lists ourselves in the AHCI code.

---

Quoted 7 lines

v1 -> v2:

 - make dma hooks explicit by putting them into ops struct (stefanha)
---
 hw/ide/core.c     |    9 ++++++---
 hw/ide/internal.h |    4 ++++

 2 files changed, 10 insertions(+), 3 deletions(-)
#11 lore raw

PATCH 5/13 ide: add ncq identify data for ahci sata drives

In reply to Alexander Graf

From: Roland Elek <[email protected]>

I modified ide_identify() to include the zero-based queue length value in word 75, and set bit 8 in word 76 to signal NCQ support in the identify data for AHCI SATA drives.

---
 hw/ide/core.c     |    7 +++++++
 hw/ide/internal.h |    2 ++
 2 files changed, 9 insertions(+), 0 deletions(-)
hw/ide/core.c +7 -0
index 04190d2..073c038 100644
@@ -147,6 +147,13 @@ static void ide_identify(IDEState *s)
     put_le16(p + 66, 120);
     put_le16(p + 67, 120);
     put_le16(p + 68, 120);
+
+    if (s->ncq_queues) {
+        put_le16(p + 75, s->ncq_queues - 1);
+        /* NCQ supported */
+        put_le16(p + 76, (1 << 8));
+    }
+
     put_le16(p + 80, 0xf0); /* ata3 -> ata6 supported */
     put_le16(p + 81, 0x16); /* conforms to ata5 */
     /* 14=NOP supported, 5=WCACHE supported, 0=SMART supported */
hw/ide/internal.h +2 -0
index 4bee636..1261eea 100644
@@ -451,6 +451,8 @@ struct IDEState {
     int smart_errors;
     uint8_t smart_selftest_count;
     uint8_t *smart_selftest_data;
+    /* AHCI */
+    int ncq_queues;
 };
 
 /* This struct represents a device that uses an IDE bus, but requires
Signature · 1 line
1.6.0.2
Reviewed-by on v1 5/13
#12 lore raw

[Qemu-devel] Re: [PATCH 05/13] ide: add ncq identify data for ahci sata drives

Quoted 11 lines · Alexander Graf

From: Roland Elek <[email protected]>

I modified ide_identify() to include the zero-based queue length value in word 75, and set bit 8 in word 76 to signal NCQ support in the identify data for AHCI SATA drives.

---
 hw/ide/core.c     |    7 +++++++
 hw/ide/internal.h |    2 ++

 2 files changed, 9 insertions(+), 0 deletions(-)
#13 lore raw

PATCH 6/13 pci: add storage class for sata

In reply to Alexander Graf

This patch adds the storage sata class id.

---
 hw/pci_ids.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/pci_ids.h +1 -0
index 82cba7e..ea3418c 100644
@@ -15,6 +15,7 @@
 
 #define PCI_CLASS_STORAGE_SCSI           0x0100
 #define PCI_CLASS_STORAGE_IDE            0x0101
+#define PCI_CLASS_STORAGE_SATA           0x0106
 #define PCI_CLASS_STORAGE_OTHER          0x0180
 
 #define PCI_CLASS_NETWORK_ETHERNET       0x0200
Signature · 1 line
1.6.0.2
#15 lore raw

PATCH 7/13 pci: add ich7 pci id

In reply to Alexander Graf

We need a PCI ID for our new AHCI adapter. I just picked an ICH-7M because that's the one built into the first Macbooks.

This patch adds a PCI ID define for an ICH-7M AHCI adapter.

---

v3 -> v4:

- add ICH7 instead of ICH7M (herbszt)

v4 -> v5:

- rename to ICH7_AHCI_RAID (herbszt)

---
 hw/pci.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/pci.h +1 -0
index 09b3e4c..f9d798b 100644
@@ -62,6 +62,7 @@
 /* Intel (0x8086) */
 #define PCI_DEVICE_ID_INTEL_82551IT      0x1209
 #define PCI_DEVICE_ID_INTEL_82557        0x1229
+#define PCI_DEVICE_ID_INTEL_ICH7_AHCI_RAID 0x27c3
 
 /* Red Hat / Qumranet (for QEMU) -- see pci-ids.txt */
 #define PCI_VENDOR_ID_REDHAT_QUMRANET    0x1af4
Signature · 1 line
1.6.0.2
Reviewed-by on v1 7/13
#16 lore raw

[Qemu-devel] Re: [PATCH 07/13] pci: add ich7 pci id

Quoted 11 lines · Alexander Graf

We need a PCI ID for our new AHCI adapter. I just picked an ICH-7M because that's the one built into the first Macbooks.

This patch adds a PCI ID define for an ICH-7M AHCI adapter.

---

v3 -> v4:

Quoted 8 lines

 - add ICH7 instead of ICH7M (herbszt)

v4 -> v5:

 - rename to ICH7_AHCI_RAID (herbszt)
---
 hw/pci.h |    1 +

 1 files changed, 1 insertions(+), 0 deletions(-)
#17 lore raw

PATCH 8/13 ahci: add ahci emulation

In reply to Alexander Graf

This patch adds an emulation layer for an ICH-7M AHCI controller. For now this controller does not do IDE legacy emulation. It is a pure AHCI controller.

---

v1 -> v2:

- rename IDEExtender to IDEBusOps and make a pointer (kraxel)
- make dma hooks explicit by putting them into ops struct (stefanha)
- use qdev buses (kraxel)
- minor cleanups
- dprintf overhaul
- add reset function

v2 -> v3:

- add msi support (kraxel)
- use MIN macro (kraxel)
- add msi support (kraxel)
- fix ncq with multiple ports
- zap qdev properties (kraxel)
- redesign legacy IF_SATA hooks (kraxel)
- don't build ahci as part of target
- move to ide/ (kwolf)

v3 -> v4:

- prepare for endianness safety
- add lspci dump (herbszt)
- use ich7 instead of ich7m (herbszt)
- fix lst+fis mapping (kraxel)
- coding style (blue swirl)
- explicit mmio setters/getters (blue swirl)

v4 -> v5:

- s/H2dNcqFis/NCQFrame/g (blue swirl)
- redo -drive magic (blue swirl)
- bump BAR to 4k
- ahci.c: rename to ICH7_AHCI_RAID (herbszt)

v5 -> v6:
- PCI config space fixes (isaku)
- remove CONFIG_AHCI from default configs

---
 Makefile.objs |    1 +
 hw/ide/ahci.c | 1380 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 1381 insertions(+), 0 deletions(-)
 create mode 100644 hw/ide/ahci.c
Makefile.objs +1 -0
index 23b17ce..b1035c8 100644
@@ -229,6 +229,7 @@ hw-obj-$(CONFIG_IDE_PIIX) += ide/piix.o
 hw-obj-$(CONFIG_IDE_CMD646) += ide/cmd646.o
 hw-obj-$(CONFIG_IDE_MACIO) += ide/macio.o
 hw-obj-$(CONFIG_IDE_VIA) += ide/via.o
+hw-obj-$(CONFIG_AHCI) += ide/ahci.o
 
 # SCSI layer
 hw-obj-y += lsi53c895a.o
hw/ide/ahci.c new file +1380 -0

1,380 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#18 lore raw

[Qemu-devel] Re: [PATCH 08/13] ahci: add ahci emulation

hw/ide/ahci.c line 510

Quoted 11 lines · Alexander Graf
hw/ide/ahci.c new file +11 -0
+static void map_page(uint8_t **ptr, uint64_t addr, uint32_t wanted)
+{
+    target_phys_addr_t len = wanted;
+
+    if (*ptr) {
+        cpu_physical_memory_unmap(*ptr, 1, len, len);
+    }
+
+    *ptr = cpu_physical_memory_map(addr, &len, 1);
+    if (len < wanted) {
+        *ptr = NULL;

We need to unmap the subset of the requested range.

hw/ide/ahci.c line 886

Quoted 7 lines
hw/ide/ahci.c new file +7 -0
+static void ncq_cb(void *opaque, int ret)
+{
+    NCQTransferState *ncq_tfs = (NCQTransferState *)opaque;
+    IDEState *ide_state;
+
+    if (ret < 0) {
+        /* error */

Error handling missing.

Quoted 8 lines
hw/ide/ahci.c new file +8 -0
+static int handle_cmd(AHCIState *s, int port, int slot)
+{
+    IDEState *ide_state;
+
+    int sglist_alloc_hint;
+    QEMUSGList sglist;
+    int atapi_packet_len = 0;
+    AHCIPortRegs *pr;

hw/ide/ahci.c line 998

Quoted 10 lines
hw/ide/ahci.c new file +10 -0
+    uint32_t opts;
+    uint64_t tbl_addr;
+    AHCICmdHdr *cmd;
+    uint8_t *cmd_fis;
+
+    target_phys_addr_t cmd_len;
+    int i;
+
+    pr = &s->dev[port].port_regs;
+    cmd = (AHCICmdHdr *)&s->dev[port].lst[slot * 32];

This isn't much easier to read but gets rid of the sizeof(AHCICmdHdr) scaling:
cmd = &((AHCICmdHdr *)s->dev[port].lst)[slot];

hw/ide/ahci.c line 1325

Quoted 11 lines
hw/ide/ahci.c new file +11 -0
+static int pci_ahci_init(PCIDevice *dev)
+{
+    struct AHCIPCIState *d;
+    d = DO_UPCAST(struct AHCIPCIState, card, dev);
+
+    pci_config_set_vendor_id(d->card.config, PCI_VENDOR_ID_INTEL);
+    pci_config_set_device_id(d->card.config,
+                             PCI_DEVICE_ID_INTEL_ICH7_AHCI_RAID);
+    pci_set_word(d->card.config + PCI_COMMAND, PCI_COMMAND_IO |
+                                               PCI_COMMAND_MEMORY |
+                                               PCI_COMMAND_MASTER);

We are enabling IO and memory space decode, as well as bus master here. According to the AHCI spec 1.3, PCI_COMMAND_MEMORY and PCI_COMMAND_MASTER should be 0 on reset ("2.1.2 Offset 04h: CMD - Command"). I thought the guest's firmware or operating system would set these bits when initializing PCI devices?

hw/ide/ahci.c line 1355

Quoted 8 lines
hw/ide/ahci.c new file +8 -0
+static int pci_ahci_uninit(PCIDevice *dev)
+{
+    struct AHCIPCIState *d;
+    d = DO_UPCAST(struct AHCIPCIState, card, dev);
+
+    if (msi_enabled(&d->card)) {
+        msi_uninit(dev);
+    }

It looks like d and &d->card are not needed, we already have dev.

Stefan

#19 lore raw

PATCH 9/13 ahci: add -drive support

In reply to Alexander Graf

We need to be able to spawn new AHCI drives, so let's add AHCI support to the -drive option.

---
 blockdev.c    |    6 +++++-
 blockdev.h    |    1 +
 qemu-common.h |    2 +-
 3 files changed, 7 insertions(+), 2 deletions(-)
blockdev.c +5 -1
index 6cb179a..5ce90cc 100644
@@ -209,6 +209,9 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)
 	} else if (!strcmp(buf, "xen")) {
 	    type = IF_XEN;
             max_devs = 0;
+        } else if (!strcmp(buf, "sata")) {
+            type = IF_SATA;
+            max_devs = MAX_SATA_DEVS;
 	} else if (!strcmp(buf, "none")) {
 	    type = IF_NONE;
             max_devs = 0;
@@ -402,7 +405,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)
     } else {
         /* no id supplied -> create one */
         dinfo->id = qemu_mallocz(32);
-        if (type == IF_IDE || type == IF_SCSI)
+        if (type == IF_IDE || type == IF_SCSI || type == IF_SATA)
             mediastr = (media == MEDIA_CDROM) ? "-cd" : "-hd";
         if (max_devs)
             snprintf(dinfo->id, 32, "%s%i%s%i",
@@ -427,6 +430,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)
     case IF_IDE:
     case IF_SCSI:
     case IF_XEN:
+    case IF_SATA:
     case IF_NONE:
         switch(media) {
 	case MEDIA_DISK:
blockdev.h +1 -0
index 653affc..f50a15e 100644
@@ -33,6 +33,7 @@ struct DriveInfo {
 
 #define MAX_IDE_DEVS	2
 #define MAX_SCSI_DEVS	7
+#define MAX_SATA_DEVS   4
 
 DriveInfo *drive_get(BlockInterfaceType type, int bus, int unit);
 int drive_get_max_bus(BlockInterfaceType type);
qemu-common.h +1 -1
index b3957f1..ae1cfca 100644
@@ -257,7 +257,7 @@ typedef uint64_t pcibus_t;
 typedef enum {
     IF_NONE,
     IF_IDE, IF_SCSI, IF_FLOPPY, IF_PFLASH, IF_MTD, IF_SD, IF_VIRTIO, IF_XEN,
-    IF_COUNT
+    IF_SATA, IF_COUNT
 } BlockInterfaceType;
 
 void cpu_exec_init_all(unsigned long tb_size);
Signature · 1 line
1.6.0.2
Reviewed-by on v1 9/13
#20 lore raw

[Qemu-devel] Re: [PATCH 09/13] ahci: add -drive support

Quoted 9 lines · Alexander Graf

We need to be able to spawn new AHCI drives, so let's add AHCI support to the -drive option.

---
 blockdev.c    |    6 +++++-
 blockdev.h    |    1 +
 qemu-common.h |    2 +-

 3 files changed, 7 insertions(+), 2 deletions(-)
#21 lore raw

PATCH 10/13 ahci: spawn controller on demand

In reply to Alexander Graf

When we add a device using -drive to the guest, we also need to create a new SATA bus to handle the device. This patch adds a function call that every machine that likes to have IF_SATA support can call to get full device creation by keeping the actual qdev code clean.

---

v2 -> v3:

- redesign

v4 -> v5:

- redesign to only use qdev in generic parts, get rid of CONFIG_AHCI

v5 -> v6:

- use snprintf (blue swirl)

---
 blockdev.c |   35 +++++++++++++++++++++++++++++++++++
 blockdev.h |    1 +
 vl.c       |    2 ++
 3 files changed, 38 insertions(+), 0 deletions(-)
blockdev.c +35 -0
index 5ce90cc..ba71177 100644
@@ -499,6 +499,41 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)
     return dinfo;
 }
 
+static void ahci_post_init(void)
+{
+    int max_bus;
+    int bus, i;
+    QemuOpts *opts;
+    char name[32];
+
+    max_bus = drive_get_max_bus(IF_SATA);
+    for (bus = 0; bus <= max_bus; bus++) {
+        snprintf(name, sizeof(name), "ahci-%d", bus);
+        opts = qemu_opts_create(qemu_find_opts("device"), name, 1);
+        qemu_opt_set(opts, "driver", "ahci");
+
+        for (i = 0; i < MAX_SATA_DEVS; i++) {
+            DriveInfo *dinfo = drive_get(IF_SATA, bus, i);
+
+            if (!dinfo) {
+               continue;
+            }
+
+            snprintf(name, sizeof(name), "ahci-%d.%d", bus, i);
+            opts = qemu_opts_create(qemu_find_opts("device"), NULL, 0);
+            qemu_opt_set(opts, "driver", "ide-drive");
+            qemu_opt_set(opts, "unit", "0");
+            qemu_opt_set(opts, "bus", name);
+            qemu_opt_set(opts, "drive", dinfo->id);
+        }
+    }
+}
+
+void drive_post_init(void)
+{
+    ahci_post_init();
+}
+
 void do_commit(Monitor *mon, const QDict *qdict)
 {
     const char *device = qdict_get_str(qdict, "device");
blockdev.h +1 -0
index f50a15e..6db229a 100644
@@ -42,6 +42,7 @@ DriveInfo *drive_get_by_blockdev(BlockDriverState *bs);
 
 QemuOpts *drive_add(const char *file, const char *fmt, ...) GCC_FMT_ATTR(2, 3);
 DriveInfo *drive_init(QemuOpts *arg, int default_to_scsi, int *fatal_error);
+void drive_post_init(void);
 
 /* device-hotplug */
 
vl.c +2 -0
index 805e11f..1f6e289 100644
@@ -2799,6 +2799,8 @@ int main(int argc, char **argv, char **envp)
     if (qemu_opts_foreach(qemu_find_opts("drive"), drive_init_func, &machine->use_scsi, 1) != 0)
         exit(1);
 
+    drive_post_init();
+
     register_savevm_live(NULL, "ram", 0, 4, NULL, ram_save_live, NULL,
                          ram_load, NULL);
 
Signature · 1 line
1.6.0.2
#22 lore raw

PATCH 11/13 ide: move pata specific parts to pata.c

In reply to Alexander Graf

Due to popular request, this patch moves pieces that are successfully identified as PATA only to a new file called pata.c.

---
 Makefile.objs     |    2 +-
 hw/ide/core.c     |  144 +------------------------------------------
 hw/ide/internal.h |    3 +
 hw/ide/pata.c     |  178 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 184 insertions(+), 143 deletions(-)
 create mode 100644 hw/ide/pata.c
Makefile.objs +1 -1
index b1035c8..07281b2 100644
@@ -221,7 +221,7 @@ hw-obj-$(CONFIG_LAN9118) += lan9118.o
 hw-obj-$(CONFIG_NE2000_ISA) += ne2000-isa.o
 
 # IDE
-hw-obj-$(CONFIG_IDE_CORE) += ide/core.o
+hw-obj-$(CONFIG_IDE_CORE) += ide/core.o ide/pata.o
 hw-obj-$(CONFIG_IDE_QDEV) += ide/qdev.o
 hw-obj-$(CONFIG_IDE_PCI) += ide/pci.o
 hw-obj-$(CONFIG_IDE_ISA) += ide/isa.o
hw/ide/core.c +2 -142

204 lines not on this page · raw message

hw/ide/internal.h +3 -0
index 1261eea..dc69a1f 100644
@@ -588,4 +588,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val);
 void ide_bus_new(IDEBus *idebus, DeviceState *dev);
 IDEDevice *ide_create_drive(IDEBus *bus, int unit, DriveInfo *drive);
 
+/* hw/ide/pata.c */
+void pata_init(IDEBus *bus);
+
 #endif /* HW_IDE_INTERNAL_H */
hw/ide/pata.c new file +178 -0

178 lines not on this page · raw message

Signature · 1 line
1.6.0.2
Reviewed-by on v1 11/13
#23 lore raw

[Qemu-devel] Re: [PATCH 11/13] ide: move pata specific parts to pata.c

Quoted 11 lines · Alexander Graf

Due to popular request, this patch moves pieces that are successfully identified as PATA only to a new file called pata.c.

---
 Makefile.objs     |    2 +-
 hw/ide/core.c     |  144 +------------------------------------------ hw/ide/internal.h |    3 +
 hw/ide/pata.c     |  178 +++++++++++++++++++++++++++++++++++++++++++++++++++++

 4 files changed, 184 insertions(+), 143 deletions(-)

 create mode 100644 hw/ide/pata.c

#24 lore raw

PATCH 12/13 config: add generic pci config file

In reply to Alexander Graf

Currently we list PCI devices in every PCI capable architecture individually. This is cumbersome when adding new devices and prone to failure because one might miss out on one.

So let's instead have a generic PCI configuration file where people can throw in their cross-platform compatible PCI devices and thus make it available to ever architecture that supports PCI too.

---
 Makefile                             |   13 ++++++++++---
 create_config_mak                    |   19 +++++++++++++++++++
 default-configs/i386-softmmu.mak     |    2 ++
 default-configs/mips-softmmu.mak     |    2 ++
 default-configs/mips64-softmmu.mak   |    2 ++
 default-configs/mips64el-softmmu.mak |    2 ++
 default-configs/mipsel-softmmu.mak   |    2 ++
 default-configs/pci-devices.mak      |    2 ++
 default-configs/ppc-softmmu.mak      |    2 ++
 default-configs/ppc64-softmmu.mak    |    2 ++
 default-configs/ppcemb-softmmu.mak   |    2 ++
 default-configs/sparc64-softmmu.mak  |    2 ++
 default-configs/x86_64-softmmu.mak   |    2 ++
 13 files changed, 51 insertions(+), 3 deletions(-)
 create mode 100755 create_config_mak
 create mode 100644 default-configs/pci-devices.mak
Makefile +10 -3
index 4e120a2..a4fa965 100644
@@ -39,9 +39,16 @@ endif
 
 SUBDIR_MAKEFLAGS=$(if $(V),,--no-print-directory)
 SUBDIR_DEVICES_MAK=$(patsubst %, %/config-devices.mak, $(TARGET_DIRS))
+PCI_DEVICES_MAK=$(patsubst %, %/pci-devices.mak, $(TARGET_DIRS))
 
-config-all-devices.mak: $(SUBDIR_DEVICES_MAK)
-	$(call quiet-command,cat $(SUBDIR_DEVICES_MAK) | grep =y | sort -u > $@,"  GEN   $@")
+config-all-devices.mak: $(SUBDIR_DEVICES_MAK) $(PCI_DEVICES_MAK)
+	$(call quiet-command,sh $(SRC_PATH)/create_config_mak $(SUBDIR_DEVICES_MAK) | sort -u > $@,"  GEN   $@")
+
+%-softmmu/pci-devices.mak: default-configs/pci-devices.mak
+	$(call quiet-command,cat $< > $@, "  GEN   $@")
+
+%-user/pci-devices.mak:
+	$(call quiet-command,echo > $@, "  GEN   $@")
 
 %/config-devices.mak: default-configs/%.mak
 	$(call quiet-command,cat $< > [email protected], "  GEN   $@")
@@ -66,7 +73,7 @@ config-all-devices.mak: $(SUBDIR_DEVICES_MAK)
 	 fi
 
 defconfig:
-	rm -f config-all-devices.mak $(SUBDIR_DEVICES_MAK)
+	rm -f config-all-devices.mak $(SUBDIR_DEVICES_MAK) $(PCI_DEVICES_MAK)
 
 -include config-all-devices.mak
 
create_config_mak new file +19 -0
new file mode 100755
index 0000000..3dddb95
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+echo "# Automatically generated by create_config_mak - do not modify"
+
+for CONF in "$@"; do
+  DIR=$(dirname "$CONF")
+  cat "$CONF" | while read line; do
+    case $line in
+      include*)
+        $0 $DIR/${line#* }
+        ;;
+      CONFIG_*=y)
+        name=${line%=*}
+        echo "$line"
+        ;;
+    esac
+  done
+done
+
default-configs/i386-softmmu.mak +2 -0
index ed00471..14d156e 100644
@@ -23,3 +23,5 @@ CONFIG_NE2000_ISA=y
 CONFIG_PIIX_PCI=y
 CONFIG_SOUND=y
 CONFIG_VIRTIO_PCI=y
+
+include pci-devices.mak
default-configs/mips-softmmu.mak +2 -0
index 3d0af83..41303c9 100644
@@ -30,3 +30,5 @@ CONFIG_DP8393X=y
 CONFIG_DS1225Y=y
 CONFIG_MIPSNET=y
 CONFIG_PFLASH_CFI01=y
+
+include pci-devices.mak
default-configs/mips64-softmmu.mak +2 -0
index 0030de4..5920d28 100644
@@ -30,3 +30,5 @@ CONFIG_DP8393X=y
 CONFIG_DS1225Y=y
 CONFIG_MIPSNET=y
 CONFIG_PFLASH_CFI01=y
+
+include pci-devices.mak
default-configs/mips64el-softmmu.mak +2 -0
index fa2a3ff..9724b33 100644
@@ -32,3 +32,5 @@ CONFIG_DS1225Y=y
 CONFIG_MIPSNET=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_FULONG=y
+
+include pci-devices.mak
default-configs/mipsel-softmmu.mak +2 -0
index 238b73a..8587baf 100644
@@ -30,3 +30,5 @@ CONFIG_DP8393X=y
 CONFIG_DS1225Y=y
 CONFIG_MIPSNET=y
 CONFIG_PFLASH_CFI01=y
+
+include pci-devices.mak
default-configs/pci-devices.mak new file +2 -0
new file mode 100644
index 0000000..b3a55bf
@@ -0,0 +1,2 @@
+# Default configuration options for PCI capable machines
+
default-configs/ppc-softmmu.mak +2 -0
index 940f4bf..732db30 100644
@@ -35,3 +35,5 @@ CONFIG_VIRTIO_PCI=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_PFLASH_CFI02=y
 CONFIG_PTIMER=y
+
+include pci-devices.mak
default-configs/ppc64-softmmu.mak +2 -0
index e1bc6b8..b98bf88 100644
@@ -35,3 +35,5 @@ CONFIG_VIRTIO_PCI=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_PFLASH_CFI02=y
 CONFIG_PTIMER=y
+
+include pci-devices.mak
default-configs/ppcemb-softmmu.mak +2 -0
index 8f1cc09..02e1fec 100644
@@ -35,3 +35,5 @@ CONFIG_VIRTIO_PCI=y
 CONFIG_PFLASH_CFI01=y
 CONFIG_PFLASH_CFI02=y
 CONFIG_PTIMER=y
+
+include pci-devices.mak
default-configs/sparc64-softmmu.mak +2 -0
index 1cc3f13..810d1c5 100644
@@ -14,3 +14,5 @@ CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_CMD646=y
 CONFIG_VIRTIO_PCI=y
+
+include pci-devices.mak
default-configs/x86_64-softmmu.mak +2 -0
index 5183203..d2be175 100644
@@ -23,3 +23,5 @@ CONFIG_NE2000_ISA=y
 CONFIG_PIIX_PCI=y
 CONFIG_SOUND=y
 CONFIG_VIRTIO_PCI=y
+
+include pci-devices.mak
Signature · 1 line
1.6.0.2
#25 lore raw

[Qemu-devel] Re: [PATCH 12/13] config: add generic pci config file

Quoted 7 lines

Currently we list PCI devices in every PCI capable architecture individually. This is cumbersome when adding new devices and prone to failure because one might miss out on one.

So let's instead have a generic PCI configuration file where people can throw in their cross-platform compatible PCI devices and thus make it available to ever architecture that supports PCI too.

I'm pretty sure this will overwrite user-edited $target/pci-devices.mak every time default-configs/pci-devices.mak is modified. It also requires that the makefile be modified every time a new include file is added.

I've comitted a solution that fixes these issues.

Paul

#26 lore raw

[Qemu-devel] Re: [PATCH 12/13] config: add generic pci config file

Quoted 8 lines · Paul Brook
Quoted 7 lines

Currently we list PCI devices in every PCI capable architecture individually. This is cumbersome when adding new devices and prone to failure because one might miss out on one.

So let's instead have a generic PCI configuration file where people can throw in their cross-platform compatible PCI devices and thus make it available to ever architecture that supports PCI too.

Quoted 5 lines

I'm pretty sure this will overwrite user-edited $target/pci-devices.mak every time default-configs/pci-devices.mak is modified. It also requires that the makefile be modified every time a new include file is added.

I've comitted a solution that fixes these issues.

I updated the git tree to reflect this. I ripped out the whole pci makefile stuff and moved the CONFIG_AHCI=y to pci.mak. The actual ahci emulation is still the same.

It contains the following patches now:

Alexander Graf (10):
ide: split ide command interpretation off
ide: fix whitespace gap in ide_exec_cmd
ide: add DMA hooks to bus ops
pci: add storage class for sata
pci: add ich7 pci id
ahci: add ahci emulation
ahci: add -drive support
ahci: spawn controller on demand
ide: move pata specific parts to pata.c
config: add ahci for pci capable machines

Roland Elek (2):
ide: add support for ide bus ops
ide: add ncq identify data for ahci sata drives

 Makefile.objs           |    3 +-
 blockdev.c              |   41 ++-
 blockdev.h              |    2 +
 default-configs/pci.mak |    1 +
 hw/ide/ahci.c           | 1380 +++++++++++++++++++++++++++++++++++++++++++++++
 hw/ide/core.c           |  874 ++++++++++++++-----------------
 hw/ide/internal.h       |   37 +-
 hw/ide/pata.c           |  178 ++++++
 hw/pci.h                |    1 +
 hw/pci_ids.h            |    1 +
 qemu-common.h           |    2 +-
 vl.c                    |    2 +
 12 files changed, 2031 insertions(+), 491 deletions(-)
 create mode 100644 hw/ide/ahci.c
 create mode 100644 hw/ide/pata.c
#27 lore raw

PATCH 13/13 config: add ahci for pci capable machines

In reply to Alexander Graf

This patch enables AHCI for all machines supporting PCI.

---
 default-configs/pci-devices.mak |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
default-configs/pci-devices.mak +1 -0
index b3a55bf..9dac2b4 100644
@@ -1,2 +1,3 @@
 # Default configuration options for PCI capable machines
 
+CONFIG_AHCI=y
Signature · 1 line
1.6.0.2