Skip to contentSkip to conversation

AHCI emulation support v8

PATCH In review Alexander Graf 3 participants 28 messages Dec 8, 2010 – Dec 10, 2010 Kbuild

lore
Share & tools
lore
#0 lore raw

cover AHCI emulation support v8

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 id=disk,file=...,if=none -device ahci,id=ahci \
  -device ide-drive,drive=disk,bus=ahci.0

Big endian hosts are still broken due to qemu shortcomings in mmio handing. With the mmio endianness patch set, ahci works there too.

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)

v6 -> v7:

- use bus instead of opaque (stefanha)
- change naming in IDEBusOps (stefanha, kwolf)
- rename IDEBusOps (stefanha)
- improve interrupt injection
- combine tfdata code paths
- update tfdata more often
- reset port registers on port reset
- improve debug output
- add "feature" variable from fis for some extended commands
- always set feature to DMA for atapi
- osx 10.5.0 works as of this version
- use non-raid ich7 ahci (herbszt)
- reflect normal ich7 in pci dump
- stick to new IDEBusOps (stefanha, kwolf)
- stefan's ahci comments

v7 -> v8:

- rewrite ops as DMA offsplit framework
- split bmdma stuff out to pci.c
- generate tfdata on the fly
- reimplement immediate dma rw
- add safety net for busy engine
- adjust ahci code for new DMA framework
- move ide core+pci to pci.mak
- add sebastian's config space patches

Alexander Graf (10):
ide: split ide command interpretation off
ide: fix whitespace gap in ide_exec_cmd
ide: Split out BMDMA code from ATA core
bmdma: split out irq setting
bmdma: move header definitions out
pci: add storage class for sata
pci: add ich7 pci id
ahci: add ahci emulation
config: move ide core and pci to pci.mak
config: add ahci for pci capable machines

Roland Elek (1):
ide: add ncq identify data for ahci sata drives

Sebastian Herbszt (2):
ahci: set SATA Mode Select
ahci: set pci revision id

 Makefile.objs                        |    1 +
 default-configs/arm-softmmu.mak      |    1 -
 default-configs/i386-softmmu.mak     |    3 -
 default-configs/mips-softmmu.mak     |    3 -
 default-configs/mips64-softmmu.mak   |    3 -
 default-configs/mips64el-softmmu.mak |    3 -
 default-configs/mipsel-softmmu.mak   |    3 -
 default-configs/pci.mak              |    4 +
 default-configs/ppc-softmmu.mak      |    3 -
 default-configs/ppc64-softmmu.mak    |    3 -
 default-configs/ppcemb-softmmu.mak   |    3 -
 default-configs/sh4-softmmu.mak      |    1 -
 default-configs/sh4eb-softmmu.mak    |    1 -
 default-configs/sparc64-softmmu.mak  |    3 -
 default-configs/x86_64-softmmu.mak   |    3 -
 hw/ide/ahci.c                        | 1378 ++++++++++++++++++++++++++++++++++
 hw/ide/cmd646.c                      |    6 +-
 hw/ide/core.c                        | 1071 +++++++++++---------------
 hw/ide/internal.h                    |   80 ++-
 hw/ide/pci.c                         |  288 +++++++-
 hw/ide/pci.h                         |   29 +
 hw/ide/piix.c                        |    6 +-
 hw/ide/via.c                         |    6 +-
 hw/pci.h                             |    1 +
 hw/pci_ids.h                         |    1 +
 25 files changed, 2203 insertions(+), 701 deletions(-)
 create mode 100644 hw/ide/ahci.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.

---

v6 -> v7:

- use bus instead of opaque (stefanha)

---
 hw/ide/core.c     |   20 ++++++++++++++------
 hw/ide/internal.h |    2 ++
 2 files changed, 16 insertions(+), 6 deletions(-)
hw/ide/core.c +14 -6
index 430350f..ac4ee71 100644
@@ -1791,9 +1791,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);
@@ -1854,17 +1851,29 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)
     default:
     case 7:
         /* command */
+        ide_exec_cmd(bus, 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:
@@ -2355,7 +2364,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 85f4a16..8617b87 100644
@@ -566,6 +566,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 7 lines · Alexander Graf

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

---

Quoted 7 lines

v6 -> v7:

 - use bus instead of opaque (stefanha)
---
 hw/ide/core.c     |   20 ++++++++++++++------
 hw/ide/internal.h |    2 ++

 2 files changed, 16 insertions(+), 6 deletions(-)
#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 ac4ee71..5e2fcbd 100644
@@ -1864,423 +1864,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; 
@@ -2294,76 +2294,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
Reviewed-by on v1 2/13
#4 lore raw

[Qemu-devel] Re: [PATCH 02/13] ide: fix whitespace gap in ide_exec_cmd

Quoted 8 lines · 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(-)
#5 lore raw

[Qemu-devel] Re: [PATCH 02/13] ide: fix whitespace gap in ide_exec_cmd

In reply to Alexander Graf

Am 08.12.2010 13:13, schrieb Alexander Graf:

Quoted 5 lines

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.

This patch "adds" some trailing whitespace. Can you take the chance to remove it?

Kevin

#6 lore raw

PATCH 3/13 ide: Split out BMDMA code from ATA core

In reply to Alexander Graf

The ATA core is currently heavily intertwined with BMDMA code. Let's loosen that a bit, so we can happily replace the DMA backend with different implementations.

---

v7 -> v8:

- rewrite as DMA ops

---
 hw/ide/cmd646.c   |    6 +-
 hw/ide/core.c     |  322 ++++++++++++-----------------------------------------
 hw/ide/internal.h |   53 +++++++--
 hw/ide/pci.c      |  278 +++++++++++++++++++++++++++++++++++++++++++++-
 hw/ide/pci.h      |    1 +
 hw/ide/piix.c     |    6 +-
 hw/ide/via.c      |    6 +-
 7 files changed, 399 insertions(+), 273 deletions(-)
hw/ide/cmd646.c +3 -3
index dfe6091..ecfa4d6 100644
@@ -167,9 +167,9 @@ static void bmdma_map(PCIDevice *pci_dev, int region_num,
 
     for(i = 0;i < 2; i++) {
         BMDMAState *bm = &d->bmdma[i];
-        d->bus[i].bmdma = bm;
+        bmdma_init(&d->bus[i], bm);
         bm->bus = d->bus+i;
-        qemu_add_vm_change_state_handler(ide_dma_restart_cb, bm);
+        qemu_add_vm_change_state_handler(d->bus[i].dma.ops->restart_cb, bm);
 
         if (i == 0) {
             register_ioport_write(addr, 4, 1, bmdma_writeb_0, d);
@@ -218,7 +218,7 @@ static void cmd646_reset(void *opaque)
 
     for (i = 0; i < 2; i++) {
         ide_bus_reset(&d->bus[i]);
-        ide_dma_reset(&d->bmdma[i]);
+        d->bus[i].dma.ops->reset(&d->bmdma[i]);
     }
 }
 
hw/ide/core.c +73 -249

514 lines not on this page · raw message

hw/ide/internal.h +41 -12

101 lines not on this page · raw message

hw/ide/pci.c +275 -3

301 lines not on this page · raw message

hw/ide/pci.h +1 -0
index b81b26c..1cd7b06 100644
@@ -10,6 +10,7 @@ typedef struct PCIIDEState {
     uint32_t secondary; /* used only for cmd646 */
 } PCIIDEState;
 
+void bmdma_init(IDEBus *bus, BMDMAState *bm);
 void bmdma_cmd_writeb(void *opaque, uint32_t addr, uint32_t val);
 extern const IORangeOps bmdma_addr_ioport_ops;
 void pci_ide_create_devs(PCIDevice *dev, DriveInfo **hd_table);
hw/ide/piix.c +3 -3
index e02b89a..1ab3f7d 100644
@@ -76,9 +76,9 @@ static void bmdma_map(PCIDevice *pci_dev, int region_num,
 
     for(i = 0;i < 2; i++) {
         BMDMAState *bm = &d->bmdma[i];
-        d->bus[i].bmdma = bm;
+        bmdma_init(&d->bus[i], bm);
         bm->bus = d->bus+i;
-        qemu_add_vm_change_state_handler(ide_dma_restart_cb, bm);
+        qemu_add_vm_change_state_handler(d->bus[i].dma.ops->restart_cb, bm);
 
         register_ioport_write(addr, 1, 1, bmdma_cmd_writeb, bm);
 
@@ -99,7 +99,7 @@ static void piix3_reset(void *opaque)
 
     for (i = 0; i < 2; i++) {
         ide_bus_reset(&d->bus[i]);
-        ide_dma_reset(&d->bmdma[i]);
+        d->bus[i].dma.ops->reset(&d->bmdma[i]);
     }
 
     /* TODO: this is the default. do not override. */
hw/ide/via.c +3 -3
index 66be0c4..bae2a4a 100644
@@ -78,9 +78,9 @@ static void bmdma_map(PCIDevice *pci_dev, int region_num,
 
     for(i = 0;i < 2; i++) {
         BMDMAState *bm = &d->bmdma[i];
-        d->bus[i].bmdma = bm;
+        bmdma_init(&d->bus[i], bm);
         bm->bus = d->bus+i;
-        qemu_add_vm_change_state_handler(ide_dma_restart_cb, bm);
+        qemu_add_vm_change_state_handler(d->bus[i].dma.ops->restart_cb, bm);
 
         register_ioport_write(addr, 1, 1, bmdma_cmd_writeb, bm);
 
@@ -101,7 +101,7 @@ static void via_reset(void *opaque)
 
     for (i = 0; i < 2; i++) {
         ide_bus_reset(&d->bus[i]);
-        ide_dma_reset(&d->bmdma[i]);
+        d->bus[i].dma.ops->reset(&d->bmdma[i]);
     }
 
     pci_set_word(pci_conf + PCI_COMMAND, PCI_COMMAND_WAIT);
Signature · 1 line
1.6.0.2
#7 lore raw

[Qemu-devel] Re: [PATCH 03/13] ide: Split out BMDMA code from ATA core

hw/ide/core.c void ide_dma_error(IDEState *s) · line 444

Quoted 8 lines · Alexander Graf
hw/ide/core.c +2 -2
@@ -486,8 +440,8 @@ void ide_dma_error(IDEState *s)
     ide_transfer_stop(s);
     s->error = ABRT_ERR;
     s->status = READY_STAT | ERR_STAT;
-    ide_dma_set_inactive(s->bus->bmdma);
-    s->bus->bmdma->status |= BM_STATUS_INT;
+    ide_set_inactive(s);
+    s->bus->dma.ops->set_status(s->bus->dma.opaque, BM_STATUS_INT);

Is BM_STATUS_INT constant naming appropriate for a general DMA abstraction? Perhaps DMA_STATUS_INT.

Quoted 15 lines
hw/ide/core.c +11 -0
@@ -2717,6 +2586,29 @@ static void ide_init1(IDEBus *bus, int unit)
                                            ide_sector_write_timer_cb, s);
  }
 
+static int ide_nop_start_irq(void *opaque)
+{
+    return 1;
+}
+
+static int ide_nop(void *opaque)
+{
+    return 0;
+}
+
+static const IDEDMAOps ide_dma_nop = {

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

Quoted 10 lines
hw/ide/core.c +10 -0
+    .start_irq      = ide_nop_start_irq,
+    .start_dma      = (void*)ide_nop,
+    .start_transfer = (void*)ide_nop,
+    .prepare_buf    = (void*)ide_nop,
+    .rw_buf         = (void*)ide_nop,
+    .set_unit       = (void*)ide_nop,
+    .set_status     = (void*)ide_nop,
+    .set_inactive   = (void*)ide_nop,
+    .restart_cb     = (void*)ide_nop,
+    .reset          = (void*)ide_nop,

Creative use of void* :). This looks unportable.

ppc and other architectures use function descriptors. There, a function pointer is not sizeof(void*) so the (void*) cast is questionable.

Also, casting to a function with a different signature is unportable. You're relying on the calling convention to make this work.

Instead of fleshing out these functions, how about initializing dma.ops to NULL? The program crashes should anyone try to do DMA before setting a real IDEDMAOps pointer. That's not as robust as limping along with non-working IDE, but should be straightforward to debug if it ever happens. It also requires less code.

Stefan

#8 lore raw

[Qemu-devel] Re: [PATCH 03/13] ide: Split out BMDMA code from ATA core

Quoted 12 lines · Stefan Hajnoczi

hw/ide/core.c void ide_dma_error(IDEState *s) · line 444

Quoted 8 lines · Alexander Graf
hw/ide/core.c +2 -2
@@ -486,8 +440,8 @@ void ide_dma_error(IDEState *s)
    ide_transfer_stop(s);
    s->error = ABRT_ERR;
    s->status = READY_STAT | ERR_STAT;
-    ide_dma_set_inactive(s->bus->bmdma);
-    s->bus->bmdma->status |= BM_STATUS_INT;
+    ide_set_inactive(s);
+    s->bus->dma.ops->set_status(s->bus->dma.opaque, BM_STATUS_INT);

Is BM_STATUS_INT constant naming appropriate for a general DMA abstraction? Perhaps DMA_STATUS_INT.

I was thinking of that too, but then again, why bother? Let's just declare BMDMA status bits the standard and be good sounded the easiest :). Less conversions are good, no? And so far, no other user really needs those bits.

Quoted 29 lines
Quoted 16 lines
hw/ide/core.c +11 -0
@@ -2717,6 +2586,29 @@ static void ide_init1(IDEBus *bus, int unit)
                                           ide_sector_write_timer_cb, s);
 }
 
+static int ide_nop_start_irq(void *opaque)
+{
+    return 1;
+}
+
+static int ide_nop(void *opaque)
+{
+    return 0;
+}
+
+static const IDEDMAOps ide_dma_nop = {

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

Quoted 10 lines
hw/ide/core.c +10 -0
+    .start_irq      = ide_nop_start_irq,
+    .start_dma      = (void*)ide_nop,
+    .start_transfer = (void*)ide_nop,
+    .prepare_buf    = (void*)ide_nop,
+    .rw_buf         = (void*)ide_nop,
+    .set_unit       = (void*)ide_nop,
+    .set_status     = (void*)ide_nop,
+    .set_inactive   = (void*)ide_nop,
+    .restart_cb     = (void*)ide_nop,
+    .reset          = (void*)ide_nop,

Creative use of void* :). This looks unportable.

Quoted 6 lines

ppc and other architectures use function descriptors. There, a function pointer is not sizeof(void*) so the (void*) cast is questionable.

Also, casting to a function with a different signature is unportable. You're relying on the calling convention to make this work.

Hrm, interesting. Maybe I should create one entry for each function type then.

Quoted 6 lines

Instead of fleshing out these functions, how about initializing dma.ops to NULL? The program crashes should anyone try to do DMA before setting a real IDEDMAOps pointer. That's not as robust as limping along with non-working IDE, but should be straightforward to debug if it ever happens. It also requires less code.

Unfortunately, at least reset gets called before the DMA init :(.

Alex

#9 lore raw

[Qemu-devel] Re: [PATCH 03/13] ide: Split out BMDMA code from ATA core

In reply to Stefan Hajnoczi

Am 08.12.2010 15:26, schrieb Stefan Hajnoczi:

Quoted 12 lines · Alexander Graf

hw/ide/core.c void ide_dma_error(IDEState *s) · line 444

Quoted 8 lines
hw/ide/core.c +2 -2
@@ -486,8 +440,8 @@ void ide_dma_error(IDEState *s)
    ide_transfer_stop(s);
    s->error = ABRT_ERR;
    s->status = READY_STAT | ERR_STAT;
-    ide_dma_set_inactive(s->bus->bmdma);
-    s->bus->bmdma->status |= BM_STATUS_INT;
+    ide_set_inactive(s);
+    s->bus->dma.ops->set_status(s->bus->dma.opaque, BM_STATUS_INT);

Is BM_STATUS_INT constant naming appropriate for a general DMA abstraction? Perhaps DMA_STATUS_INT.

BM_STATUS_INT is a bit in the status register of busmaster IDE. So in theory it shouldn't appear in generic ATA code, but I'm not sure how much of this we can fix at this point.

Quoted 5 lines

Instead of fleshing out these functions, how about initializing dma.ops to NULL? The program crashes should anyone try to do DMA before setting a real IDEDMAOps pointer. That's not as robust as limping along with non-working IDE, but should be straightforward to debug if it ever happens. It also requires less code.

Allowing the guest to crash qemu is not an option. We'd have to check for NULL in all commands that initiate a DMA transfer.

Kevin

#10 lore raw

[Qemu-devel] Re: [PATCH 03/13] ide: Split out BMDMA code from ATA core

Quoted 18 lines · Kevin Wolf

Am 08.12.2010 15:26, schrieb Stefan Hajnoczi:

Quoted 12 lines · Alexander Graf

hw/ide/core.c void ide_dma_error(IDEState *s) · line 444

Quoted 8 lines
hw/ide/core.c +2 -2
@@ -486,8 +440,8 @@ void ide_dma_error(IDEState *s)
     ide_transfer_stop(s);
     s->error = ABRT_ERR;
     s->status = READY_STAT | ERR_STAT;
-    ide_dma_set_inactive(s->bus->bmdma);
-    s->bus->bmdma->status |= BM_STATUS_INT;
+    ide_set_inactive(s);
+    s->bus->dma.ops->set_status(s->bus->dma.opaque, BM_STATUS_INT);

Is BM_STATUS_INT constant naming appropriate for a general DMA abstraction?  Perhaps DMA_STATUS_INT.

BM_STATUS_INT is a bit in the status register of busmaster IDE. So in theory it shouldn't appear in generic ATA code, but I'm not sure how much of this we can fix at this point.

Quoted 8 lines
Quoted 5 lines

Instead of fleshing out these functions, how about initializing dma.ops to NULL?  The program crashes should anyone try to do DMA before setting a real IDEDMAOps pointer.  That's not as robust as limping along with non-working IDE, but should be straightforward to debug if it ever happens.  It also requires less code.

Allowing the guest to crash qemu is not an option. We'd have to check for NULL in all commands that initiate a DMA transfer.

You're right, I wasn't aware that the ops gets a chance to execute before we initialize them to BMDMA.

Stefan

#11 lore raw

[Qemu-devel] Re: [PATCH 03/13] ide: Split out BMDMA code from ATA core

Am 08.12.2010 15:40, schrieb Stefan Hajnoczi:

Quoted 25 lines · Kevin Wolf
Quoted 24 lines

Am 08.12.2010 15:26, schrieb Stefan Hajnoczi:

Quoted 12 lines · Alexander Graf

hw/ide/core.c void ide_dma_error(IDEState *s) · line 444

Quoted 8 lines
hw/ide/core.c +2 -2
@@ -486,8 +440,8 @@ void ide_dma_error(IDEState *s)
    ide_transfer_stop(s);
    s->error = ABRT_ERR;
    s->status = READY_STAT | ERR_STAT;
-    ide_dma_set_inactive(s->bus->bmdma);
-    s->bus->bmdma->status |= BM_STATUS_INT;
+    ide_set_inactive(s);
+    s->bus->dma.ops->set_status(s->bus->dma.opaque, BM_STATUS_INT);

Is BM_STATUS_INT constant naming appropriate for a general DMA abstraction? Perhaps DMA_STATUS_INT.

BM_STATUS_INT is a bit in the status register of busmaster IDE. So in theory it shouldn't appear in generic ATA code, but I'm not sure how much of this we can fix at this point.

Quoted 5 lines

Instead of fleshing out these functions, how about initializing dma.ops to NULL? The program crashes should anyone try to do DMA before setting a real IDEDMAOps pointer. That's not as robust as limping along with non-working IDE, but should be straightforward to debug if it ever happens. It also requires less code.

Quoted 5 lines
Quoted 2 lines

Allowing the guest to crash qemu is not an option. We'd have to check for NULL in all commands that initiate a DMA transfer.

You're right, I wasn't aware that the ops gets a chance to execute before we initialize them to BMDMA.

For example with ISA we never intialize it at all.

Kevin

#12 lore raw

[Qemu-devel] Re: [PATCH 03/13] ide: Split out BMDMA code from ATA core

In reply to Alexander Graf

Am 08.12.2010 13:13, schrieb Alexander Graf:

Quoted 23 lines

The ATA core is currently heavily intertwined with BMDMA code. Let's loosen that a bit, so we can happily replace the DMA backend with different implementations.

---

v7 -> v8:

- rewrite as DMA ops

---
 hw/ide/cmd646.c   |    6 +-
 hw/ide/core.c     |  322 ++++++++++++-----------------------------------------
 hw/ide/internal.h |   53 +++++++--
 hw/ide/pci.c      |  278 +++++++++++++++++++++++++++++++++++++++++++++-
 hw/ide/pci.h      |    1 +
 hw/ide/piix.c     |    6 +-
 hw/ide/via.c      |    6 +-
 7 files changed, 399 insertions(+), 273 deletions(-)

hw/ide/internal.h typedef enum { IDE_HD, IDE_CD, IDE_CFATA } IDEDriveKind; · line 377

Quoted 9 lines
hw/ide/internal.h +6 -0
@@ -367,6 +369,17 @@ 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 *);

These two typedefs are unused.

Quoted 17 lines
hw/ide/internal.h +10 -0
+typedef void DMAStartFunc(void *, IDEState *, BlockDriverCompletionFunc *);
+typedef int DMAFunc(void *);
+typedef int DMAIntFunc(void *, int);
+typedef void DMARestartFunc(void *, int, int);
+
 /* NOTE: IDEState represents in fact one drive */
 struct IDEState {
     IDEBus *bus;
@@ -443,12 +456,33 @@ struct IDEState {
     uint8_t *smart_selftest_data;
 };
 
+struct IDEDMAOps {
+    DMAFunc *start_irq;
+    DMAStartFunc *start_dma;
+    DMAFunc *start_transfer;
+    DMAIntFunc *prepare_buf;

hw/ide/internal.h struct IDEState { · line 473

Quoted 10 lines
hw/ide/internal.h +10 -0
+    DMAIntFunc *rw_buf;
+    DMAIntFunc *set_unit;
+    DMAIntFunc *set_status;
+    DMAFunc *set_inactive;
+    DMARestartFunc *restart_cb;
+    DMAFunc *reset;
+};
+
+struct IDEDMA {
+    struct IDEDMAOps const *ops;

Why hiding the const somewhere in the middle?

hw/ide/internal.h struct IDEState { · line 478

Quoted 5 lines
hw/ide/internal.h +5 -0
+    void *opaque;
+    struct iovec iov;
+    QEMUIOVector qiov;
+    BlockDriverAIOCB *aiocb;
+};

I'm wondering if this interface where you pass a void* to all DMA functions is really optimal. You completely lose type safety this way.

Maybe we should use inheritance like in other places in qemu and implement BMDMAState with IDEDMA as its "base class"? This would mean that we need to make IDEBus.dma a pointer rather than embedding the structure, but it's probably worth the changes.

hw/ide/pci.c line 173

Quoted 4 lines
hw/ide/pci.c +4 -0
+static int bmdma_set_status(void *opaque, int status)
+{
+    BMDMAState *bm = opaque;
+    bm->status |= status;

The name of this function is misleading. You're just setting a flag, not setting a new value for the whole status register.

Kevin

#13 lore raw

PATCH 4/13 bmdma: split out irq setting

In reply to Alexander Graf

The IDE core doesn't care about BMDMA blocking IRQs from getting submitted, so let's reflect that in the code and make IRQ blocking fully transparent.

---
 hw/ide/core.c     |    6 ------
 hw/ide/internal.h |    4 ++--
 hw/ide/pci.c      |   44 +++++++++++++++++++++++++++-----------------
 3 files changed, 29 insertions(+), 25 deletions(-)
hw/ide/core.c +0 -6
index fce994f..6284539 100644
@@ -2586,18 +2586,12 @@ static void ide_init1(IDEBus *bus, int unit)
                                            ide_sector_write_timer_cb, s);
 }
 
-static int ide_nop_start_irq(void *opaque)
-{
-    return 1;
-}
-
 static int ide_nop(void *opaque)
 {
     return 0;
 }
 
 static const IDEDMAOps ide_dma_nop = {
-    .start_irq      = ide_nop_start_irq,
     .start_dma      = (void*)ide_nop,
     .start_transfer = (void*)ide_nop,
     .prepare_buf    = (void*)ide_nop,
hw/ide/internal.h +2 -2
index 15ab119..af7e741 100644
@@ -457,7 +457,6 @@ struct IDEState {
 };
 
 struct IDEDMAOps {
-    DMAFunc *start_irq;
     DMAStartFunc *start_dma;
     DMAFunc *start_transfer;
     DMAIntFunc *prepare_buf;
@@ -530,6 +529,7 @@ struct BMDMAState {
     uint32_t nsector;
     IORange addr_ioport;
     QEMUBH *bh;
+    qemu_irq irq;
 };
 
 static inline IDEState *idebus_active_if(IDEBus *bus)
@@ -545,7 +545,7 @@ static inline IDEState *bmdma_active_if(BMDMAState *bmdma)
 
 static inline void ide_set_irq(IDEBus *bus)
 {
-    if (bus->dma.ops->start_irq(bus->dma.opaque)) {
+    if (!(bus->cmd & IDE_CMD_DISABLE_IRQ)) {
         qemu_irq_raise(bus->irq);
     }
 }
hw/ide/pci.c +27 -17

68 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#14 lore raw

PATCH 5/13 bmdma: move header definitions out

In reply to Alexander Graf

The bmdma header definitions currently reside in generic code, but only PCI specific code should know about BMDMA internals. So let's move the definitions and everything using them out to pci.h.

---
 hw/ide/internal.h |   27 ---------------------------
 hw/ide/pci.h      |   28 ++++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 27 deletions(-)
hw/ide/internal.h +0 -27
index af7e741..7e2ba1a 100644
@@ -20,7 +20,6 @@ typedef struct IDEBus IDEBus;
 typedef struct IDEDevice IDEDevice;
 typedef struct IDEDeviceInfo IDEDeviceInfo;
 typedef struct IDEState IDEState;
-typedef struct BMDMAState BMDMAState;
 typedef struct IDEDMA IDEDMA;
 typedef struct IDEDMAOps IDEDMAOps;
 
@@ -512,37 +511,11 @@ struct IDEDeviceInfo {
 #define BM_CMD_START     0x01
 #define BM_CMD_READ      0x08
 
-struct BMDMAState {
-    uint8_t cmd;
-    uint8_t status;
-    uint32_t addr;
-
-    IDEBus *bus;
-    /* current transfer state */
-    uint32_t cur_addr;
-    uint32_t cur_prd_last;
-    uint32_t cur_prd_addr;
-    uint32_t cur_prd_len;
-    uint8_t unit;
-    BlockDriverCompletionFunc *dma_cb;
-    int64_t sector_num;
-    uint32_t nsector;
-    IORange addr_ioport;
-    QEMUBH *bh;
-    qemu_irq irq;
-};
-
 static inline IDEState *idebus_active_if(IDEBus *bus)
 {
     return bus->ifs + bus->unit;
 }
 
-static inline IDEState *bmdma_active_if(BMDMAState *bmdma)
-{
-    assert(bmdma->unit != (uint8_t)-1);
-    return bmdma->bus->ifs + bmdma->unit;
-}
-
 static inline void ide_set_irq(IDEBus *bus)
 {
     if (!(bus->cmd & IDE_CMD_DISABLE_IRQ)) {
hw/ide/pci.h +28 -0
index 1cd7b06..0f96297 100644
@@ -3,6 +3,26 @@
 
 #include <hw/ide/internal.h>
 
+typedef struct BMDMAState {
+    uint8_t cmd;
+    uint8_t status;
+    uint32_t addr;
+
+    IDEBus *bus;
+    /* current transfer state */
+    uint32_t cur_addr;
+    uint32_t cur_prd_last;
+    uint32_t cur_prd_addr;
+    uint32_t cur_prd_len;
+    uint8_t unit;
+    BlockDriverCompletionFunc *dma_cb;
+    int64_t sector_num;
+    uint32_t nsector;
+    IORange addr_ioport;
+    QEMUBH *bh;
+    qemu_irq irq;
+} BMDMAState;
+
 typedef struct PCIIDEState {
     PCIDevice dev;
     IDEBus bus[2];
@@ -10,6 +30,14 @@ typedef struct PCIIDEState {
     uint32_t secondary; /* used only for cmd646 */
 } PCIIDEState;
 
+
+static inline IDEState *bmdma_active_if(BMDMAState *bmdma)
+{
+    assert(bmdma->unit != (uint8_t)-1);
+    return bmdma->bus->ifs + bmdma->unit;
+}
+
+
 void bmdma_init(IDEBus *bus, BMDMAState *bm);
 void bmdma_cmd_writeb(void *opaque, uint32_t addr, uint32_t val);
 extern const IORangeOps bmdma_addr_ioport_ops;
Signature · 1 line
1.6.0.2
#15 lore raw

PATCH 6/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 6284539..a3f8104 100644
@@ -140,6 +140,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 7e2ba1a..414adf5 100644
@@ -453,6 +453,8 @@ struct IDEState {
     int smart_errors;
     uint8_t smart_selftest_count;
     uint8_t *smart_selftest_data;
+    /* AHCI */
+    int ncq_queues;
 };
 
 struct IDEDMAOps {
Signature · 1 line
1.6.0.2
#16 lore raw

PATCH 7/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
#17 lore raw

PATCH 8/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-7 AHCI adapter.

---

v3 -> v4:

- add ICH7 instead of ICH7M (herbszt)

v4 -> v5:

- rename to ICH7_AHCI_RAID (herbszt)

v6 -> v7:

- use non-raid ich7 ahci (herbszt)

---
 hw/pci.h |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/pci.h +1 -0
index 89f7b76..0dce2b0 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    0x27c1
 
 /* Red Hat / Qumranet (for QEMU) -- see pci-ids.txt */
 #define PCI_VENDOR_ID_REDHAT_QUMRANET    0x1af4
Signature · 1 line
1.6.0.2
#18 lore raw

PATCH 9/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

v6 -> v7:

- improve interrupt injection
- combine tfdata code paths
- update tfdata more often
- reset port registers on port reset
- improve debug output
- add "feature" variable from fis for some extended commands
- always set feature to DMA for atapi
- osx 10.5.0 works as of this version
- use non-raid ich7 ahci (herbszt)
- reflect normal ich7 in pci dump
- stick to new IDEBusOps (stefanha, kwolf)
- ahci: stefan's ahci comments

v7 -> v8:
- generate tfdata on the fly
- reimplement immediate dma rw
- add safety net for busy engine
- adjust for new DMA interface

---
 Makefile.objs |    1 +
 hw/ide/ahci.c | 1374 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 1375 insertions(+), 0 deletions(-)
 create mode 100644 hw/ide/ahci.c
Makefile.objs +1 -0
index 04625eb..4f692e4 100644
@@ -238,6 +238,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-$(CONFIG_LSI_SCSI_PCI) += lsi53c895a.o
hw/ide/ahci.c new file +1374 -0

1,374 lines not on this page · raw message

Signature · 1 line
1.6.0.2
#19 lore raw

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

Quoted 10 lines · Alexander Graf

+struct AHCIDevice {
+    IDEBus port;
+    int port_no;
+    uint32_t port_state;
+    uint32_t finished;
+    AHCIPortRegs port_regs;
+    struct AHCIState *hba;
+    uint8_t *lst;
+    uint8_t *res_fis;
+    uint8_t *cmd_fis;

Are these unmapped on reset?

Quoted 5 lines

+    int cmd_fis_len;
+    int dma_status;
+    BlockDriverCompletionFunc *dma_cb;
+    AHCICmdHdr *cur_cmd;
+    NCQTransferState ncq_tfs[AHCI_MAX_CMDS];

Are the ncq_tfs[] elements cleaned up on reset (i.e. cancellation and free sglist)?

hw/ide/ahci.c line 502

Quoted 11 lines
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) {
+        cpu_physical_memory_unmap(*ptr, 1, len, len);

*ptr = NULL;

hw/ide/ahci.c line 899

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

Missing error handling.

Quoted 54 lines
hw/ide/ahci.c new file +54 -0
+static void process_ncq_command(AHCIState *s, int port, uint8_t *cmd_fis,
+                                int slot, QEMUSGList *sg)
+{
+    NCQFrame *ncq_fis = (NCQFrame*)cmd_fis;
+    uint8_t tag = ncq_fis->tag >> 3;
+    NCQTransferState *ncq_tfs = &s->dev[port].ncq_tfs[tag];
+
+    if (ncq_tfs->used) {
+        /* error - already in use */
+        fprintf(stderr, "%s: tag %d already used\n", __FUNCTION__, tag);
+        return;
+    }
+
+    ncq_tfs->used = 1;
+    ncq_tfs->drive = &s->dev[port];
+    ncq_tfs->drive->cmd_fis = cmd_fis;
+    ncq_tfs->drive->cmd_fis_len = 0x20;
+    ncq_tfs->slot = slot;
+    ncq_tfs->lba = ((uint64_t)ncq_fis->lba5 << 40) |
+                   ((uint64_t)ncq_fis->lba4 << 32) |
+                   ((uint64_t)ncq_fis->lba3 << 24) |
+                   ((uint64_t)ncq_fis->lba2 << 16) |
+                   ((uint64_t)ncq_fis->lba1 << 8) |
+                   (uint64_t)ncq_fis->lba0;
+
+    /* Note: We calculate the sector count, but don't currently rely on it.
+     * The total size of the DMA buffer tells us the transfer size instead. */
+    ncq_tfs->sector_count = ((uint16_t)ncq_fis->sector_count_high << 8) |
+                                ncq_fis->sector_count_low;
+
+    DPRINTF(port, "NCQ transfer LBA from %ld to %ld, drive max %ld\n",
+            ncq_tfs->lba, ncq_tfs->lba + ncq_tfs->sector_count - 2,
+            s->dev[port].port.ifs[0].nb_sectors - 1);
+
+    ncq_tfs->sglist = *sg;
+    ncq_tfs->tag = tag;
+
+    switch(ncq_fis->command) {
+        case READ_FPDMA_QUEUED:
+            DPRINTF(port, "NCQ reading %d sectors from LBA %ld, tag %d\n",
+                    ncq_tfs->sector_count-1, ncq_tfs->lba, ncq_tfs->tag);
+            ncq_tfs->is_read = 1;
+
+            /* XXX: The specification is unclear about whether the DMA Setup
+             * FIS here should have the I bit set, but it suggest that it should
+             * not. Linux works without this interrupt, so I disabled it.
+             * If someone knows if it is needed, please tell me, or fix this. */
+
+            /* ahci_trigger_irq(s,s->dev[port],PORT_IRQ_STAT_DSS); */
+            DPRINTF(port, "tag %d aio read %ld\n", ncq_tfs->tag, ncq_tfs->lba);
+            dma_bdrv_read(ncq_tfs->drive->port.ifs[0].bs, &ncq_tfs->sglist,
+                          ncq_tfs->lba, ncq_cb, ncq_tfs);
+            break;
+        case WRITE_FPDMA_QUEUED:

hw/ide/ahci.c line 988

Quoted 10 lines
hw/ide/ahci.c new file +10 -0
+            DPRINTF(port, "NCQ writing %d sectors to LBA %ld, tag %d\n",
+                    ncq_tfs->sector_count-1, ncq_tfs->lba, ncq_tfs->tag);
+            ncq_tfs->is_read = 0;
+            /* ahci_trigger_irq(s,s->dev[port],PORT_IRQ_STAT_DSS); */
+            DPRINTF(port, "tag %d aio write %ld\n", ncq_tfs->tag, ncq_tfs->lba);
+            dma_bdrv_write(ncq_tfs->drive->port.ifs[0].bs, &ncq_tfs->sglist,
+                           ncq_tfs->lba, ncq_cb, ncq_tfs);
+            break;
+        default:
+            hw_error("ahci: tried to process non-NCQ command as NCQ\n");

Guest triggerable abort.

Quoted 21 lines

+            break;
+    }

hw/ide/ahci.c new file +19 -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;
+    uint32_t opts;
+    uint64_t tbl_addr;
+    AHCICmdHdr *cmd;
+    uint8_t *cmd_fis;
+
+    target_phys_addr_t cmd_len;
+    int i;
+
+    if (s->dev[port].port.ifs[0].status & (BUSY_STAT|DRQ_STAT)) {

hw/ide/ahci.c line 1019

Quoted 10 lines
hw/ide/ahci.c new file +10 -0
+        /* Engine currently busy, try again later */
+        DPRINTF(port, "engine busy\n");
+        return -1;
+    }
+
+    pr = &s->dev[port].port_regs;
+    cmd = &((AHCICmdHdr *)s->dev[port].lst)[slot];
+
+    if (!s->dev[port].lst) {
+        hw_error("%s: lst not given but cmd handled", __FUNCTION__);

Guest triggerable abort.

hw/ide/ahci.c line 1027

Quoted 8 lines

+    }

hw/ide/ahci.c new file +7 -0
+
+    opts = le32_to_cpu(cmd->opts);
+    tbl_addr = le64_to_cpu(cmd->tbl_addr);
+
+    sglist_alloc_hint = opts >> AHCI_CMD_HDR_PRDT_LEN;
+    cmd_len = 0x80 + (sglist_alloc_hint * sizeof(AHCI_SG));
+    cmd_fis = cpu_physical_memory_map(tbl_addr, &cmd_len, 1);

NULL dereference later if cpu_physical_memory_map() fails due to invalid address (tbl_addr).

hw/ide/ahci.c line 1033

Quoted 6 lines
hw/ide/ahci.c new file +6 -0
+
+    /* The device we are working for */
+    ide_state = &s->dev[port].port.ifs[0];
+
+    if (!ide_state->bs) {
+        hw_error("%s: guest accessed unused port", __FUNCTION__);

Guest triggerable abort.

Quoted 6 lines

+    }

hw/ide/ahci.c new file +5 -0
+
+    /* Get number of entries in the PRDT, init a qemu sglist accordingly */
+    memset(&sglist, 0, sizeof(sglist));
+
+    if (sglist_alloc_hint > 0) {

hw/ide/ahci.c line 1049

Quoted 10 lines
hw/ide/ahci.c new file +10 -0
+        AHCI_SG *tbl = (AHCI_SG *)(&cmd_fis[0x80]);
+
+        qemu_sglist_init(&sglist, sglist_alloc_hint);
+        /* Parse the PRDs and create qemu sglist entries accordingly */
+        for (i = 0; i < sglist_alloc_hint; i++) {
+            /* flags_size is zero-based */
+            qemu_sglist_add(&sglist, le64_to_cpu(tbl[i].addr),
+                            le32_to_cpu(tbl[i].flags_size) + 1);
+        }
+    }

Only the SATA_FIS_REG_H2D_UPDATE_COMMAND_REGISTER codepath seems to clean up sglist. The guest can leak host memory by setting sglist_alloc_hint > 0 and not using SATA_FIS_REG_H2D_UPDATE_COMMAND_REGISTER.

hw/ide/ahci.c line 1058

Quoted 9 lines
hw/ide/ahci.c new file +9 -0
+
+    debug_print_fis(cmd_fis, (opts & AHCI_CMD_HDR_CMD_FIS_LEN) * 4);
+
+    switch (cmd_fis[0]) {
+        case SATA_FIS_TYPE_REGISTER_H2D:
+            break;
+        default:
+            hw_error("unknown command cmd_fis[0]=%02x cmd_fis[1]=%02x cmd_fis[2]=%02x\n",
+                     cmd_fis[0], cmd_fis[1], cmd_fis[2]);

Guest triggerable abort.

Quoted 11 lines

+            break;
+    }
+
+    switch (cmd_fis[1]) {
+        case SATA_FIS_REG_H2D_UPDATE_COMMAND_REGISTER:
+            break;
+        case 0:
+            break;
+        default:
+            hw_error("unknown command cmd_fis[0]=%02x cmd_fis[1]=%02x cmd_fis[2]=%02x\n",
+                     cmd_fis[0], cmd_fis[1], cmd_fis[2]);

Guest triggerable abort.

Quoted 35 lines

+            break;
+    }

hw/ide/ahci.c new file +33 -0
+
+    switch (s->dev[port].port_state) {
+        case STATE_RUN:
+            if (cmd_fis[15] & ATA_SRST) {
+                s->dev[port].port_state = STATE_RESET;
+            }
+            break;
+        case STATE_RESET:
+            if (!(cmd_fis[15] & ATA_SRST)) {
+                ahci_reset_port(s, port);
+            }
+            break;
+    }
+
+    if (cmd_fis[1] == SATA_FIS_REG_H2D_UPDATE_COMMAND_REGISTER) {
+
+        /* Check for NCQ command */
+        if ((cmd_fis[2] == READ_FPDMA_QUEUED) ||
+            (cmd_fis[2] == WRITE_FPDMA_QUEUED)) {
+            process_ncq_command(s, port, cmd_fis, slot, &sglist);
+            goto out;
+        }
+
+        /* If the command is not NCQ, the sglist is needed in the core */
+        ide_state->sg = sglist;
+
+        /* Decompose the FIS  */
+        ide_state->nsector = (int64_t)((cmd_fis[13] << 8) | cmd_fis[12]);
+        ide_state->feature = cmd_fis[3];
+        if (!ide_state->nsector) {
+            ide_state->nsector = 256;
+        }
+

hw/ide/ahci.c line 1114

Quoted 10 lines
hw/ide/ahci.c new file +10 -0
+        if (ide_state->drive_kind != IDE_CD) {
+            ide_set_sector(ide_state, (cmd_fis[6] << 16) | (cmd_fis[5] << 8) |
+                           cmd_fis[4]);
+        }
+
+        /* Copy the ACMD field (ATAPI packet, if any) from the AHCI command
+         * table to ide_state->io_buffer
+         */
+        if (opts & AHCI_CMD_ATAPI) {
+            atapi_packet_len = ((ide_state->hcyl) << 8) + ide_state->lcyl;

Unused variable.

Quoted 7 lines
hw/ide/ahci.c new file +7 -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,

hw/ide/ahci.c line 1331

Quoted 10 lines
hw/ide/ahci.c new file +10 -0
+                             PCI_DEVICE_ID_INTEL_ICH7_AHCI);
+
+    pci_config_set_class(d->card.config, PCI_CLASS_STORAGE_SATA);
+    pci_config_set_prog_interface(d->card.config, AHCI_PROGMODE_MAJOR_REV_1);
+
+    d->card.config[PCI_CACHE_LINE_SIZE] = 0x08;  /* Cache line size */
+    d->card.config[PCI_LATENCY_TIMER]   = 0x00;  /* Latency timer */
+    pci_config_set_interrupt_pin(d->card.config, 1);
+
+    qemu_register_reset(ahci_reset, d);

Missing qemu_unregister_reset() in pci_ahci_uninit().

Stefan

#20 lore raw

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

Quoted 14 lines · Stefan Hajnoczi

hw/ide/ahci.c line 323

Quoted 11 lines · Alexander Graf
hw/ide/ahci.c new file +10 -0
+struct AHCIDevice {
+    IDEBus port;
+    int port_no;
+    uint32_t port_state;
+    uint32_t finished;
+    AHCIPortRegs port_regs;
+    struct AHCIState *hba;
+    uint8_t *lst;
+    uint8_t *res_fis;
+    uint8_t *cmd_fis;
Quoted 2 lines

Are these unmapped on reset?

On which reset? Port reset sends a d2h fis to the guest, so we still need at least the res mapping. I couldn't find the exact spot where the state of registers after reset is defined.

Quoted 28 lines

hw/ide/ahci.c line 328

Quoted 7 lines
hw/ide/ahci.c new file +5 -0
+    int cmd_fis_len;
+    int dma_status;
+    BlockDriverCompletionFunc *dma_cb;
+    AHCICmdHdr *cur_cmd;
+    NCQTransferState ncq_tfs[AHCI_MAX_CMDS];

Are the ncq_tfs[] elements cleaned up on reset (i.e. cancellation and free sglist)?

hw/ide/ahci.c line 502

Quoted 12 lines
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) {
+        cpu_physical_memory_unmap(*ptr, 1, len, len);

*ptr = NULL;

Quoted 12 lines

hw/ide/ahci.c line 899

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

Missing error handling.

Yes, that's what the XXX stands for :).

Quoted 60 lines
Quoted 60 lines
hw/ide/ahci.c new file +59 -0
+static void process_ncq_command(AHCIState *s, int port, uint8_t *cmd_fis,
+                                int slot, QEMUSGList *sg)
+{
+    NCQFrame *ncq_fis = (NCQFrame*)cmd_fis;
+    uint8_t tag = ncq_fis->tag >> 3;
+    NCQTransferState *ncq_tfs = &s->dev[port].ncq_tfs[tag];
+
+    if (ncq_tfs->used) {
+        /* error - already in use */
+        fprintf(stderr, "%s: tag %d already used\n", __FUNCTION__, tag);
+        return;
+    }
+
+    ncq_tfs->used = 1;
+    ncq_tfs->drive = &s->dev[port];
+    ncq_tfs->drive->cmd_fis = cmd_fis;
+    ncq_tfs->drive->cmd_fis_len = 0x20;
+    ncq_tfs->slot = slot;
+    ncq_tfs->lba = ((uint64_t)ncq_fis->lba5 << 40) |
+                   ((uint64_t)ncq_fis->lba4 << 32) |
+                   ((uint64_t)ncq_fis->lba3 << 24) |
+                   ((uint64_t)ncq_fis->lba2 << 16) |
+                   ((uint64_t)ncq_fis->lba1 << 8) |
+                   (uint64_t)ncq_fis->lba0;
+
+    /* Note: We calculate the sector count, but don't currently rely on it.
+     * The total size of the DMA buffer tells us the transfer size instead. */
+    ncq_tfs->sector_count = ((uint16_t)ncq_fis->sector_count_high << 8) |
+                                ncq_fis->sector_count_low;
+
+    DPRINTF(port, "NCQ transfer LBA from %ld to %ld, drive max %ld\n",
+            ncq_tfs->lba, ncq_tfs->lba + ncq_tfs->sector_count - 2,
+            s->dev[port].port.ifs[0].nb_sectors - 1);
+
+    ncq_tfs->sglist = *sg;
+    ncq_tfs->tag = tag;
+
+    switch(ncq_fis->command) {
+        case READ_FPDMA_QUEUED:
+            DPRINTF(port, "NCQ reading %d sectors from LBA %ld, tag %d\n",
+                    ncq_tfs->sector_count-1, ncq_tfs->lba, ncq_tfs->tag);
+            ncq_tfs->is_read = 1;
+
+            /* XXX: The specification is unclear about whether the DMA Setup
+             * FIS here should have the I bit set, but it suggest that it should
+             * not. Linux works without this interrupt, so I disabled it.
+             * If someone knows if it is needed, please tell me, or fix this. */
+
+            /* ahci_trigger_irq(s,s->dev[port],PORT_IRQ_STAT_DSS); */
+            DPRINTF(port, "tag %d aio read %ld\n", ncq_tfs->tag, ncq_tfs->lba);
+            dma_bdrv_read(ncq_tfs->drive->port.ifs[0].bs, &ncq_tfs->sglist,
+                          ncq_tfs->lba, ncq_cb, ncq_tfs);
+            break;
+        case WRITE_FPDMA_QUEUED:
+            DPRINTF(port, "NCQ writing %d sectors to LBA %ld, tag %d\n",
+                    ncq_tfs->sector_count-1, ncq_tfs->lba, ncq_tfs->tag);
+            ncq_tfs->is_read = 0;
+            /* ahci_trigger_irq(s,s->dev[port],PORT_IRQ_STAT_DSS); */
+            DPRINTF(port, "tag %d aio write %ld\n", ncq_tfs->tag, ncq_tfs->lba);
Quoted 9 lines

hw/ide/ahci.c line 988

Quoted 6 lines
hw/ide/ahci.c new file +5 -0
+            dma_bdrv_write(ncq_tfs->drive->port.ifs[0].bs, &ncq_tfs->sglist,
+                           ncq_tfs->lba, ncq_cb, ncq_tfs);
+            break;
+        default:
+            hw_error("ahci: tried to process non-NCQ command as NCQ\n");

Guest triggerable abort.

Those happen. The guest can shoot itself in the foot. We have more of these in other places. Just check virtio.c and search for abort() :).

Quoted 76 lines
Quoted 23 lines
hw/ide/ahci.c new file +21 -0
+            break;
+    }
+}
+
+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;
+    uint32_t opts;
+    uint64_t tbl_addr;
+    AHCICmdHdr *cmd;
+    uint8_t *cmd_fis;
+
+    target_phys_addr_t cmd_len;
+    int i;
+
+    if (s->dev[port].port.ifs[0].status & (BUSY_STAT|DRQ_STAT)) {

hw/ide/ahci.c line 1019

Quoted 10 lines
hw/ide/ahci.c new file +10 -0
+        /* Engine currently busy, try again later */
+        DPRINTF(port, "engine busy\n");
+        return -1;
+    }
+
+    pr = &s->dev[port].port_regs;
+    cmd = &((AHCICmdHdr *)s->dev[port].lst)[slot];
+
+    if (!s->dev[port].lst) {
+        hw_error("%s: lst not given but cmd handled", __FUNCTION__);

Guest triggerable abort.

hw/ide/ahci.c line 1027

Quoted 9 lines
hw/ide/ahci.c new file +8 -0
+    }
+
+    opts = le32_to_cpu(cmd->opts);
+    tbl_addr = le64_to_cpu(cmd->tbl_addr);
+
+    sglist_alloc_hint = opts >> AHCI_CMD_HDR_PRDT_LEN;
+    cmd_len = 0x80 + (sglist_alloc_hint * sizeof(AHCI_SG));
+    cmd_fis = cpu_physical_memory_map(tbl_addr, &cmd_len, 1);

NULL dereference later if cpu_physical_memory_map() fails due to invalid address (tbl_addr).

hw/ide/ahci.c line 1033

Quoted 7 lines
hw/ide/ahci.c new file +6 -0
+
+    /* The device we are working for */
+    ide_state = &s->dev[port].port.ifs[0];
+
+    if (!ide_state->bs) {
+        hw_error("%s: guest accessed unused port", __FUNCTION__);

Guest triggerable abort.

Quoted 14 lines
hw/ide/ahci.c new file +14 -0
+    }
+
+    /* Get number of entries in the PRDT, init a qemu sglist accordingly */
+    memset(&sglist, 0, sizeof(sglist));
+
+    if (sglist_alloc_hint > 0) {
+        AHCI_SG *tbl = (AHCI_SG *)(&cmd_fis[0x80]);
+
+        qemu_sglist_init(&sglist, sglist_alloc_hint);
+        /* Parse the PRDs and create qemu sglist entries accordingly */
+        for (i = 0; i < sglist_alloc_hint; i++) {
+            /* flags_size is zero-based */
+            qemu_sglist_add(&sglist, le64_to_cpu(tbl[i].addr),
+                            le32_to_cpu(tbl[i].flags_size) + 1);
Quoted 9 lines

Review

Quoted 3 lines
(quoted diff) +2 -0
+        }
+    }

Only the SATA_FIS_REG_H2D_UPDATE_COMMAND_REGISTER codepath seems to clean up sglist. The guest can leak host memory by setting sglist_alloc_hint > 0 and not using SATA_FIS_REG_H2D_UPDATE_COMMAND_REGISTER.

True, the sglist should only be created in dma_prepare (then the core is responsible for cleanup) or ncq command issue.

Alex

#21 lore raw

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

Am 09.12.2010 16:48, schrieb Alexander Graf:

Quoted 13 lines
Quoted 12 lines

hw/ide/ahci.c line 899

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

Missing error handling.

Quoted 1 line

Yes, that's what the XXX stands for :).

I think Stefan wanted to tell us that he thinks this XXX should be addressed. I don't disagree, by the way. ;-)

Quoted 69 lines
Quoted 59 lines
Quoted 59 lines
hw/ide/ahci.c new file +59 -0
+static void process_ncq_command(AHCIState *s, int port, uint8_t *cmd_fis,
+                                int slot, QEMUSGList *sg)
+{
+    NCQFrame *ncq_fis = (NCQFrame*)cmd_fis;
+    uint8_t tag = ncq_fis->tag >> 3;
+    NCQTransferState *ncq_tfs = &s->dev[port].ncq_tfs[tag];
+
+    if (ncq_tfs->used) {
+        /* error - already in use */
+        fprintf(stderr, "%s: tag %d already used\n", __FUNCTION__, tag);
+        return;
+    }
+
+    ncq_tfs->used = 1;
+    ncq_tfs->drive = &s->dev[port];
+    ncq_tfs->drive->cmd_fis = cmd_fis;
+    ncq_tfs->drive->cmd_fis_len = 0x20;
+    ncq_tfs->slot = slot;
+    ncq_tfs->lba = ((uint64_t)ncq_fis->lba5 << 40) |
+                   ((uint64_t)ncq_fis->lba4 << 32) |
+                   ((uint64_t)ncq_fis->lba3 << 24) |
+                   ((uint64_t)ncq_fis->lba2 << 16) |
+                   ((uint64_t)ncq_fis->lba1 << 8) |
+                   (uint64_t)ncq_fis->lba0;
+
+    /* Note: We calculate the sector count, but don't currently rely on it.
+     * The total size of the DMA buffer tells us the transfer size instead. */
+    ncq_tfs->sector_count = ((uint16_t)ncq_fis->sector_count_high << 8) |
+                                ncq_fis->sector_count_low;
+
+    DPRINTF(port, "NCQ transfer LBA from %ld to %ld, drive max %ld\n",
+            ncq_tfs->lba, ncq_tfs->lba + ncq_tfs->sector_count - 2,
+            s->dev[port].port.ifs[0].nb_sectors - 1);
+
+    ncq_tfs->sglist = *sg;
+    ncq_tfs->tag = tag;
+
+    switch(ncq_fis->command) {
+        case READ_FPDMA_QUEUED:
+            DPRINTF(port, "NCQ reading %d sectors from LBA %ld, tag %d\n",
+                    ncq_tfs->sector_count-1, ncq_tfs->lba, ncq_tfs->tag);
+            ncq_tfs->is_read = 1;
+
+            /* XXX: The specification is unclear about whether the DMA Setup
+             * FIS here should have the I bit set, but it suggest that it should
+             * not. Linux works without this interrupt, so I disabled it.
+             * If someone knows if it is needed, please tell me, or fix this. */
+
+            /* ahci_trigger_irq(s,s->dev[port],PORT_IRQ_STAT_DSS); */
+            DPRINTF(port, "tag %d aio read %ld\n", ncq_tfs->tag, ncq_tfs->lba);
+            dma_bdrv_read(ncq_tfs->drive->port.ifs[0].bs, &ncq_tfs->sglist,
+                          ncq_tfs->lba, ncq_cb, ncq_tfs);
+            break;
+        case WRITE_FPDMA_QUEUED:
+            DPRINTF(port, "NCQ writing %d sectors to LBA %ld, tag %d\n",
+                    ncq_tfs->sector_count-1, ncq_tfs->lba, ncq_tfs->tag);
+            ncq_tfs->is_read = 0;
+            /* ahci_trigger_irq(s,s->dev[port],PORT_IRQ_STAT_DSS); */
+            DPRINTF(port, "tag %d aio write %ld\n", ncq_tfs->tag, ncq_tfs->lba);
Quoted 9 lines

hw/ide/ahci.c line 988

Quoted 6 lines
hw/ide/ahci.c new file +5 -0
+            dma_bdrv_write(ncq_tfs->drive->port.ifs[0].bs, &ncq_tfs->sglist,
+                           ncq_tfs->lba, ncq_cb, ncq_tfs);
+            break;
+        default:
+            hw_error("ahci: tried to process non-NCQ command as NCQ\n");

Guest triggerable abort.

Quoted 2 lines

Those happen. The guest can shoot itself in the foot. We have more of these in other places. Just check virtio.c and search for abort() :).

They are bugs which should be fixed in virtio rather than being spread to new code.

Kevin

#22 lore raw

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

Quoted 91 lines · Kevin Wolf

Am 09.12.2010 16:48, schrieb Alexander Graf:

Quoted 13 lines
Quoted 13 lines

hw/ide/ahci.c line 899

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

Missing error handling.

Quoted 2 lines

Yes, that's what the XXX stands for :).

I think Stefan wanted to tell us that he thinks this XXX should be addressed. I don't disagree, by the way. ;-)

Quoted 69 lines
Quoted 69 lines
Quoted 56 lines
hw/ide/ahci.c new file +54 -0
+static void process_ncq_command(AHCIState *s, int port, uint8_t *cmd_fis,
+                                int slot, QEMUSGList *sg)
+{
+    NCQFrame *ncq_fis = (NCQFrame*)cmd_fis;
+    uint8_t tag = ncq_fis->tag >> 3;
+    NCQTransferState *ncq_tfs = &s->dev[port].ncq_tfs[tag];
+
+    if (ncq_tfs->used) {
+        /* error - already in use */
+        fprintf(stderr, "%s: tag %d already used\n", __FUNCTION__, tag);
+        return;
+    }
+
+    ncq_tfs->used = 1;
+    ncq_tfs->drive = &s->dev[port];
+    ncq_tfs->drive->cmd_fis = cmd_fis;
+    ncq_tfs->drive->cmd_fis_len = 0x20;
+    ncq_tfs->slot = slot;
+    ncq_tfs->lba = ((uint64_t)ncq_fis->lba5 << 40) |
+                   ((uint64_t)ncq_fis->lba4 << 32) |
+                   ((uint64_t)ncq_fis->lba3 << 24) |
+                   ((uint64_t)ncq_fis->lba2 << 16) |
+                   ((uint64_t)ncq_fis->lba1 << 8) |
+                   (uint64_t)ncq_fis->lba0;
+
+    /* Note: We calculate the sector count, but don't currently rely on it.
+     * The total size of the DMA buffer tells us the transfer size instead. */
+    ncq_tfs->sector_count = ((uint16_t)ncq_fis->sector_count_high << 8) |
+                                ncq_fis->sector_count_low;
+
+    DPRINTF(port, "NCQ transfer LBA from %ld to %ld, drive max %ld\n",
+            ncq_tfs->lba, ncq_tfs->lba + ncq_tfs->sector_count - 2,
+            s->dev[port].port.ifs[0].nb_sectors - 1);
+
+    ncq_tfs->sglist = *sg;
+    ncq_tfs->tag = tag;
+
+    switch(ncq_fis->command) {
+        case READ_FPDMA_QUEUED:
+            DPRINTF(port, "NCQ reading %d sectors from LBA %ld, tag %d\n",
+                    ncq_tfs->sector_count-1, ncq_tfs->lba, ncq_tfs->tag);
+            ncq_tfs->is_read = 1;
+
+            /* XXX: The specification is unclear about whether the DMA Setup
+             * FIS here should have the I bit set, but it suggest that it should
+             * not. Linux works without this interrupt, so I disabled it.
+             * If someone knows if it is needed, please tell me, or fix this. */
+
+            /* ahci_trigger_irq(s,s->dev[port],PORT_IRQ_STAT_DSS); */
+            DPRINTF(port, "tag %d aio read %ld\n", ncq_tfs->tag, ncq_tfs->lba);
+            dma_bdrv_read(ncq_tfs->drive->port.ifs[0].bs, &ncq_tfs->sglist,
+                          ncq_tfs->lba, ncq_cb, ncq_tfs);
+            break;
+        case WRITE_FPDMA_QUEUED:

hw/ide/ahci.c line 988

Quoted 10 lines
hw/ide/ahci.c new file +10 -0
+            DPRINTF(port, "NCQ writing %d sectors to LBA %ld, tag %d\n",
+                    ncq_tfs->sector_count-1, ncq_tfs->lba, ncq_tfs->tag);
+            ncq_tfs->is_read = 0;
+            /* ahci_trigger_irq(s,s->dev[port],PORT_IRQ_STAT_DSS); */
+            DPRINTF(port, "tag %d aio write %ld\n", ncq_tfs->tag, ncq_tfs->lba);
+            dma_bdrv_write(ncq_tfs->drive->port.ifs[0].bs, &ncq_tfs->sglist,
+                           ncq_tfs->lba, ncq_cb, ncq_tfs);
+            break;
+        default:
+            hw_error("ahci: tried to process non-NCQ command as NCQ\n");

Guest triggerable abort.

Quoted 7 lines
Quoted 3 lines

Those happen. The guest can shoot itself in the foot. We have more of these in other places. Just check virtio.c and search for abort() :).

They are bugs which should be fixed in virtio rather than being spread to new code.

Not sure about that. Would you prefer a broken guest to abort so you can debug it or to have it spew your log files with error messages or to silently ignore errors and never find bugs?

Alex

#23 lore raw

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

Am 09.12.2010 17:18, schrieb Alexander Graf:

Quoted 96 lines
Quoted 95 lines · Kevin Wolf

Am 09.12.2010 16:48, schrieb Alexander Graf:

Quoted 13 lines
Quoted 13 lines

hw/ide/ahci.c line 899

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

Missing error handling.

Quoted 2 lines

Yes, that's what the XXX stands for :).

I think Stefan wanted to tell us that he thinks this XXX should be addressed. I don't disagree, by the way. ;-)

Quoted 72 lines
Quoted 59 lines
Quoted 59 lines
hw/ide/ahci.c new file +59 -0
+static void process_ncq_command(AHCIState *s, int port, uint8_t *cmd_fis,
+                                int slot, QEMUSGList *sg)
+{
+    NCQFrame *ncq_fis = (NCQFrame*)cmd_fis;
+    uint8_t tag = ncq_fis->tag >> 3;
+    NCQTransferState *ncq_tfs = &s->dev[port].ncq_tfs[tag];
+
+    if (ncq_tfs->used) {
+        /* error - already in use */
+        fprintf(stderr, "%s: tag %d already used\n", __FUNCTION__, tag);
+        return;
+    }
+
+    ncq_tfs->used = 1;
+    ncq_tfs->drive = &s->dev[port];
+    ncq_tfs->drive->cmd_fis = cmd_fis;
+    ncq_tfs->drive->cmd_fis_len = 0x20;
+    ncq_tfs->slot = slot;
+    ncq_tfs->lba = ((uint64_t)ncq_fis->lba5 << 40) |
+                   ((uint64_t)ncq_fis->lba4 << 32) |
+                   ((uint64_t)ncq_fis->lba3 << 24) |
+                   ((uint64_t)ncq_fis->lba2 << 16) |
+                   ((uint64_t)ncq_fis->lba1 << 8) |
+                   (uint64_t)ncq_fis->lba0;
+
+    /* Note: We calculate the sector count, but don't currently rely on it.
+     * The total size of the DMA buffer tells us the transfer size instead. */
+    ncq_tfs->sector_count = ((uint16_t)ncq_fis->sector_count_high << 8) |
+                                ncq_fis->sector_count_low;
+
+    DPRINTF(port, "NCQ transfer LBA from %ld to %ld, drive max %ld\n",
+            ncq_tfs->lba, ncq_tfs->lba + ncq_tfs->sector_count - 2,
+            s->dev[port].port.ifs[0].nb_sectors - 1);
+
+    ncq_tfs->sglist = *sg;
+    ncq_tfs->tag = tag;
+
+    switch(ncq_fis->command) {
+        case READ_FPDMA_QUEUED:
+            DPRINTF(port, "NCQ reading %d sectors from LBA %ld, tag %d\n",
+                    ncq_tfs->sector_count-1, ncq_tfs->lba, ncq_tfs->tag);
+            ncq_tfs->is_read = 1;
+
+            /* XXX: The specification is unclear about whether the DMA Setup
+             * FIS here should have the I bit set, but it suggest that it should
+             * not. Linux works without this interrupt, so I disabled it.
+             * If someone knows if it is needed, please tell me, or fix this. */
+
+            /* ahci_trigger_irq(s,s->dev[port],PORT_IRQ_STAT_DSS); */
+            DPRINTF(port, "tag %d aio read %ld\n", ncq_tfs->tag, ncq_tfs->lba);
+            dma_bdrv_read(ncq_tfs->drive->port.ifs[0].bs, &ncq_tfs->sglist,
+                          ncq_tfs->lba, ncq_cb, ncq_tfs);
+            break;
+        case WRITE_FPDMA_QUEUED:
+            DPRINTF(port, "NCQ writing %d sectors to LBA %ld, tag %d\n",
+                    ncq_tfs->sector_count-1, ncq_tfs->lba, ncq_tfs->tag);
+            ncq_tfs->is_read = 0;
+            /* ahci_trigger_irq(s,s->dev[port],PORT_IRQ_STAT_DSS); */
+            DPRINTF(port, "tag %d aio write %ld\n", ncq_tfs->tag, ncq_tfs->lba);
Quoted 10 lines

hw/ide/ahci.c line 988

Quoted 7 lines
hw/ide/ahci.c new file +5 -0
+            dma_bdrv_write(ncq_tfs->drive->port.ifs[0].bs, &ncq_tfs->sglist,
+                           ncq_tfs->lba, ncq_cb, ncq_tfs);
+            break;
+        default:
+            hw_error("ahci: tried to process non-NCQ command as NCQ\n");

Guest triggerable abort.

Those happen. The guest can shoot itself in the foot. We have more of these in other places. Just check virtio.c and search for abort() :).

Quoted 7 lines
Quoted 3 lines

They are bugs which should be fixed in virtio rather than being spread to new code.

Not sure about that. Would you prefer a broken guest to abort so you can debug it or to have it spew your log files with error messages or to silently ignore errors and never find bugs?

If you need it for debugging, maybe have a DPRINTF_ERROR macro that aborts with an error message if DEBUG is defined, and doesn't do anything in normal builds? I'm still not sure if aborting is a good idea there, but I think it would be acceptable.

For normal builds, the preferred behaviour is doing the same as real hardware in such cases. And real hardware doesn't kill the machine when the driver is doing stupid things, but rather sets an error bit in some register or something.

Kevin

#24 lore raw

PATCH 10/13 config: move ide core and pci to pci.mak

In reply to Alexander Graf

Every device that can do PCI should also be able to do IDE. So let's move the IDE definitions over to pci.mak.

---
 default-configs/arm-softmmu.mak      |    1 -
 default-configs/i386-softmmu.mak     |    3 ---
 default-configs/mips-softmmu.mak     |    3 ---
 default-configs/mips64-softmmu.mak   |    3 ---
 default-configs/mips64el-softmmu.mak |    3 ---
 default-configs/mipsel-softmmu.mak   |    3 ---
 default-configs/pci.mak              |    3 +++
 default-configs/ppc-softmmu.mak      |    3 ---
 default-configs/ppc64-softmmu.mak    |    3 ---
 default-configs/ppcemb-softmmu.mak   |    3 ---
 default-configs/sh4-softmmu.mak      |    1 -
 default-configs/sh4eb-softmmu.mak    |    1 -
 default-configs/sparc64-softmmu.mak  |    3 ---
 default-configs/x86_64-softmmu.mak   |    3 ---
 14 files changed, 3 insertions(+), 33 deletions(-)
default-configs/arm-softmmu.mak +0 -1
index ac48dc1..8d1174f 100644
@@ -8,7 +8,6 @@ CONFIG_ECC=y
 CONFIG_SERIAL=y
 CONFIG_PTIMER=y
 CONFIG_SD=y
-CONFIG_IDE_CORE=y
 CONFIG_MAX7310=y
 CONFIG_WM8750=y
 CONFIG_TWL92230=y
default-configs/i386-softmmu.mak +0 -3
index ce905d2..323fafb 100644
@@ -13,9 +13,6 @@ CONFIG_FDC=y
 CONFIG_ACPI=y
 CONFIG_APM=y
 CONFIG_DMA=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_PIIX=y
 CONFIG_NE2000_ISA=y
default-configs/mips-softmmu.mak +0 -3
index 565e611..f524971 100644
@@ -17,9 +17,6 @@ CONFIG_ACPI=y
 CONFIG_APM=y
 CONFIG_DMA=y
 CONFIG_PIIX4=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_PIIX=y
 CONFIG_NE2000_ISA=y
default-configs/mips64-softmmu.mak +0 -3
index 03bd8eb..aeab6b2 100644
@@ -17,9 +17,6 @@ CONFIG_ACPI=y
 CONFIG_APM=y
 CONFIG_DMA=y
 CONFIG_PIIX4=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_PIIX=y
 CONFIG_NE2000_ISA=y
default-configs/mips64el-softmmu.mak +0 -3
index 4661617..8e6511c 100644
@@ -17,9 +17,6 @@ CONFIG_ACPI=y
 CONFIG_APM=y
 CONFIG_DMA=y
 CONFIG_PIIX4=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_PIIX=y
 CONFIG_IDE_VIA=y
default-configs/mipsel-softmmu.mak +0 -3
index 92fc473..a05ac25 100644
@@ -17,9 +17,6 @@ CONFIG_ACPI=y
 CONFIG_APM=y
 CONFIG_DMA=y
 CONFIG_PIIX4=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_PIIX=y
 CONFIG_NE2000_ISA=y
default-configs/pci.mak +3 -0
index c74a99f..d700b3c 100644
@@ -10,3 +10,6 @@ CONFIG_PCNET_COMMON=y
 CONFIG_LSI_SCSI_PCI=y
 CONFIG_RTL8139_PCI=y
 CONFIG_E1000_PCI=y
+CONFIG_IDE_CORE=y
+CONFIG_IDE_QDEV=y
+CONFIG_IDE_PCI=y
default-configs/ppc-softmmu.mak +0 -3
index f1cb99e..4563742 100644
@@ -23,9 +23,6 @@ CONFIG_GRACKLE_PCI=y
 CONFIG_UNIN_PCI=y
 CONFIG_DEC_PCI=y
 CONFIG_PPCE500_PCI=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_CMD646=y
 CONFIG_IDE_MACIO=y
default-configs/ppc64-softmmu.mak +0 -3
index 83cbe97..d5073b3 100644
@@ -23,9 +23,6 @@ CONFIG_GRACKLE_PCI=y
 CONFIG_UNIN_PCI=y
 CONFIG_DEC_PCI=y
 CONFIG_PPCE500_PCI=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_CMD646=y
 CONFIG_IDE_MACIO=y
default-configs/ppcemb-softmmu.mak +0 -3
index 2b52d4a..9f0730c 100644
@@ -23,9 +23,6 @@ CONFIG_GRACKLE_PCI=y
 CONFIG_UNIN_PCI=y
 CONFIG_DEC_PCI=y
 CONFIG_PPCE500_PCI=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_CMD646=y
 CONFIG_IDE_MACIO=y
default-configs/sh4-softmmu.mak +0 -1
index 87247a4..5c69acc 100644
@@ -3,6 +3,5 @@
 include pci.mak
 CONFIG_SERIAL=y
 CONFIG_PTIMER=y
-CONFIG_IDE_CORE=y
 CONFIG_PFLASH_CFI02=y
 CONFIG_ISA_MMIO=y
default-configs/sh4eb-softmmu.mak +0 -1
index 5b8a16e..7cdc122 100644
@@ -3,6 +3,5 @@
 include pci.mak
 CONFIG_SERIAL=y
 CONFIG_PTIMER=y
-CONFIG_IDE_CORE=y
 CONFIG_PFLASH_CFI02=y
 CONFIG_ISA_MMIO=y
default-configs/sparc64-softmmu.mak +0 -3
index ecc3122..d8f17e7 100644
@@ -9,8 +9,5 @@ CONFIG_SERIAL=y
 CONFIG_PARALLEL=y
 CONFIG_PCKBD=y
 CONFIG_FDC=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_CMD646=y
default-configs/x86_64-softmmu.mak +0 -3
index 7f22599..eff26d2 100644
@@ -13,9 +13,6 @@ CONFIG_FDC=y
 CONFIG_ACPI=y
 CONFIG_APM=y
 CONFIG_DMA=y
-CONFIG_IDE_CORE=y
-CONFIG_IDE_QDEV=y
-CONFIG_IDE_PCI=y
 CONFIG_IDE_ISA=y
 CONFIG_IDE_PIIX=y
 CONFIG_NE2000_ISA=y
Signature · 1 line
1.6.0.2
#25 lore raw

PATCH 11/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.mak |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
default-configs/pci.mak +1 -0
index d700b3c..0471efb 100644
@@ -13,3 +13,4 @@ CONFIG_E1000_PCI=y
 CONFIG_IDE_CORE=y
 CONFIG_IDE_QDEV=y
 CONFIG_IDE_PCI=y
+CONFIG_AHCI=y
Signature · 1 line
1.6.0.2
#26 lore raw

PATCH 12/13 ahci: set SATA Mode Select

In reply to Alexander Graf

From: Sebastian Herbszt <[email protected]>

Set SATA Mode Select to AHCI in the Address Map Register.

---
 hw/ide/ahci.c |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)
hw/ide/ahci.c +3 -0
index 7e7aa89..2ef03ed 100644
@@ -1328,6 +1328,9 @@ static int pci_ahci_init(PCIDevice *dev)
     d->card.config[PCI_LATENCY_TIMER]   = 0x00;  /* Latency timer */
     pci_config_set_interrupt_pin(d->card.config, 1);
 
+    /* XXX Software should program this register */
+    d->card.config[0x90]   = 1 << 6; /* Address Map Register - AHCI mode */
+
     qemu_register_reset(ahci_reset, d);
 
     /* XXX BAR size should be 1k, but that breaks, so bump it to 4k for now */
Signature · 1 line
1.6.0.2
#27 lore raw

PATCH 13/13 ahci: set pci revision id

In reply to Alexander Graf

From: Sebastian Herbszt <[email protected]>

Set pci revision id to 0x01.

---
 hw/ide/ahci.c |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)
hw/ide/ahci.c +1 -0
index 2ef03ed..fdfc011 100644
@@ -1322,6 +1322,7 @@ static int pci_ahci_init(PCIDevice *dev)
                              PCI_DEVICE_ID_INTEL_ICH7_AHCI);
 
     pci_config_set_class(d->card.config, PCI_CLASS_STORAGE_SATA);
+    pci_config_set_revision(d->card.config, 0x01);
     pci_config_set_prog_interface(d->card.config, AHCI_PROGMODE_MAJOR_REV_1);
 
     d->card.config[PCI_CACHE_LINE_SIZE] = 0x08;  /* Cache line size */
Signature · 1 line
1.6.0.2