AHCI emulation support v9
cover AHCI emulation support v9
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
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
v8 -> v9:
- make dma providers subclass of idedma (kwolf)
- s/set_status/add_status/g (kwolf)
- cancel and clear ncq queue on reset (stefanha)
- clear ptr on map failure (stefanha)
- potential NULL deref, unregister reset (stefanha)
- add error reporting for ncq (stefanha)
- replace hw_error with DPRINTF (stefanha)
- move sg generation to sg users
- fix off-by-one in sglist interpretation
- make background engine work (queued commands)
- use ICH9 instead of ICH7 (aliguori)
- update to new APIs
Alexander Graf (9):
ide: split ide command interpretation off
ide: fix whitespace gap in ide_exec_cmd
ide: Split out BMDMA code from ATA core
ide: move transfer_start after variable modification
pci: add storage class for sata
pci: add ich9 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 (1):
ahci: set SATA Mode Select
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 | 1527 ++++++++++++++++++++++++++++++++++ hw/ide/cmd646.c | 7 +- hw/ide/core.c | 1098 +++++++++++-------------- hw/ide/internal.h | 73 +- hw/ide/pci.c | 289 +++++++- hw/ide/pci.h | 30 + hw/ide/piix.c | 7 +- hw/ide/via.c | 7 +- hw/pci.h | 1 + hw/pci_ids.h | 1 + 25 files changed, 2373 insertions(+), 705 deletions(-) create mode 100644 hw/ide/ahci.c
PATCH 1/11 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
@@ -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
@@ -567,6 +567,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,int bus_id);IDEDevice *ide_create_drive (IDEBus *bus,int unit,DriveInfo *drive);
Signature · 1 line
1.6.0.2
PATCH 2/11 ide: fix whitespace gap in ide_exec_cmd
In reply to Alexander GrafNow 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
@@ -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
PATCH 3/11 ide: Split out BMDMA code from ATA core
In reply to Alexander GrafThe 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
v8 -> v9:
- fold in: split out irq setting
- fold in: move header definitions out
- make dma providers subclass of idedma (kwolf)
- s/set_status/add_status/g (kwolf)
--- hw/ide/cmd646.c | 7 +- hw/ide/core.c | 335 ++++++++++++++--------------------------------------- hw/ide/internal.h | 69 +++++------ hw/ide/pci.c | 289 +++++++++++++++++++++++++++++++++++++++++++++- hw/ide/pci.h | 30 +++++ hw/ide/piix.c | 7 +- hw/ide/via.c | 7 +- 7 files changed, 446 insertions(+), 298 deletions(-)
hw/ide/cmd646.c +4 -3
@@ -167,9 +167,10 @@ 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->dma);if (i ==0 ) {register_ioport_write (addr,4 ,1 , bmdma_writeb_0, d);
@@ -218,7 +219,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].dma); } }
hw/ide/core.c +86 -249
527 lines not on this page · raw message
hw/ide/internal.h +32 -37
120 lines not on this page · raw message
hw/ide/pci.c +286 -3
312 lines not on this page · raw message
hw/ide/pci.h +30 -0
@@ -3,6 +3,27 @@#include <hw/ide/internal.h> +typedef struct BMDMAState { +IDEDMA dma; +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 +31,15 @@ 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;void pci_ide_create_devs (PCIDevice *dev,DriveInfo **hd_table);
hw/ide/piix.c +4 -3
@@ -76,9 +76,10 @@ 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->dma);register_ioport_write (addr,1 ,1 , bmdma_cmd_writeb, bm);
@@ -99,7 +100,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].dma); }/* TODO: this is the default. do not override. */
hw/ide/via.c +4 -3
@@ -78,9 +78,10 @@ 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->dma);register_ioport_write (addr,1 ,1 , bmdma_cmd_writeb, bm);
@@ -101,7 +102,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].dma); }pci_set_word (pci_conf +PCI_COMMAND ,PCI_COMMAND_WAIT );
Signature · 1 line
1.6.0.2
[Qemu-devel] Re: [PATCH 03/11] ide: Split out BMDMA code from ATA core
Am 14.12.2010 01:34, schrieb Alexander Graf:
Quoted 5 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.
Signed-off-by Alexander Graf <[email protected]>
Something in this patch makes qemu abort with a failed assertion on system_reset.
Kevin
[Qemu-devel] Re: [PATCH 03/11] ide: Split out BMDMA code from ATA core
Quoted 9 lines · Kevin Wolf
Am 14.12.2010 01:34, schrieb Alexander Graf:
Quoted 5 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.
Signed-off-by Alexander Graf <[email protected]>Something in this patch makes qemu abort with a failed assertion on
system_reset.
Ouch. Thanks for catching that. The reset path was just plain wrong :).
Alex
PATCH 4/11 ide: move transfer_start after variable modification
In reply to Alexander GrafWe hook into transfer_start and immediately call the end function for ahci. This means that everything needs to be in place for the end function when we start the transfer, so let's move the function down to where all state is in place.
--- hw/ide/core.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
hw/ide/core.c +4 -4
@@ -814,11 +814,11 @@ static void ide_atapi_cmd_reply_end(IDEState *s) size = s->cd_sector_size - s->io_buffer_index;if (size > s->elementary_transfer_size) size = s->elementary_transfer_size; -ide_transfer_start (s, s->io_buffer + s->io_buffer_index, - size, ide_atapi_cmd_reply_end); s->packet_transfer_size -= size; s->elementary_transfer_size -= size; s->io_buffer_index += size; +ide_transfer_start (s, s->io_buffer + s->io_buffer_index + size, + size, ide_atapi_cmd_reply_end); }else {/* a new transfer is needed */ s->nsector = (s->nsector & ~7 ) |ATAPI_INT_REASON_IO ;
@@ -843,11 +843,11 @@ static void ide_atapi_cmd_reply_end(IDEState *s)if (size > (s->cd_sector_size - s->io_buffer_index)) size = (s->cd_sector_size - s->io_buffer_index); } -ide_transfer_start (s, s->io_buffer + s->io_buffer_index, - size, ide_atapi_cmd_reply_end); s->packet_transfer_size -= size; s->elementary_transfer_size -= size; s->io_buffer_index += size; +ide_transfer_start (s, s->io_buffer + s->io_buffer_index - size, + size, ide_atapi_cmd_reply_end);ide_set_irq (s->bus);#ifdef DEBUG_IDE_ATAPI printf ("status=0x%x\n" , s->status);
Signature · 1 line
1.6.0.2
[Qemu-devel] Re: [PATCH 04/11] ide: move transfer_start after variable modification
Am 14.12.2010 01:34, schrieb Alexander Graf:
Quoted 15 lines
We hook into
transfer_startand immediately call the end function for ahci. This means that everything needs to be in place for the end function when we start the transfer, so let's move the function down to where all state is in place.Signed-off-by Alexander Graf <[email protected]>--- hw/ide/core.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)hw/ide/core.c +0
-0
hw/ide/core.c static void ide_atapi_cmd_reply_end(IDEState *s) · line 820
Quoted 9 lines
hw/ide/core.c +1
-2@@ -814,11 +814,11 @@ static void ide_atapi_cmd_reply_end(IDEState *s) size = s->cd_sector_size - s->io_buffer_index;if (size > s->elementary_transfer_size) size = s->elementary_transfer_size; -ide_transfer_start (s, s->io_buffer + s->io_buffer_index, - size, ide_atapi_cmd_reply_end); s->packet_transfer_size -= size; s->elementary_transfer_size -= size; s->io_buffer_index += size; + ide_transfer_start(s, s->io_buffer + s->io_buffer_index + size,
I think this should be s->io_buffer + s->io_buffer_index - size.
Kevin
Quoted 18 lines
hw/ide/core.c +3
-2+ size, ide_atapi_cmd_reply_end); }else {/* a new transfer is needed */ s->nsector = (s->nsector & ~7 ) |ATAPI_INT_REASON_IO ;@@ -843,11 +843,11 @@ static void ide_atapi_cmd_reply_end(IDEState *s)if (size > (s->cd_sector_size - s->io_buffer_index)) size = (s->cd_sector_size - s->io_buffer_index); } -ide_transfer_start (s, s->io_buffer + s->io_buffer_index, - size, ide_atapi_cmd_reply_end); s->packet_transfer_size -= size; s->elementary_transfer_size -= size; s->io_buffer_index += size; +ide_transfer_start (s, s->io_buffer + s->io_buffer_index - size, + size, ide_atapi_cmd_reply_end);ide_set_irq (s->bus);#ifdef DEBUG_IDE_ATAPI printf ("status=0x%x\n" , s->status);
PATCH 5/11 ide: add ncq identify data for ahci sata drives
In reply to Alexander GrafFrom: 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
@@ -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
@@ -447,6 +447,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
PATCH 6/11 pci: add storage class for sata
In reply to Alexander GrafThis 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
@@ -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
PATCH 7/11 pci: add ich9 pci id
In reply to Alexander GrafWe need a PCI ID for our new AHCI adapter. I just picked an ICH-9 because that's the one in the Q35 chipset.
This patch adds a PCI ID define for an ICH-9 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)
v8 -> v9:
- use ICH9 instead of ICH7
--- hw/pci.h | 1 + 1 files changed, 1 insertions(+), 0 deletions(-)
hw/pci.h +1 -0
@@ -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_82801IR 0x2922/* Red Hat / Qumranet (for QEMU) -- see pci-ids.txt */ #define PCI_VENDOR_ID_REDHAT_QUMRANET 0x1af4
Signature · 1 line
1.6.0.2
PATCH 8/11 ahci: add ahci emulation
In reply to Alexander GrafThis patch adds an emulation layer for an ICH-9 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
v8 -> v9:
- ahci: set pci revision id to 0x02
- make dma providers subclass of idedma (kwolf)
- s/set_status/add_status/g (kwolf)
- cancel and clear ncq queue on reset (stefanha)
- clear ptr on map failure (stefanha)
- potential NULL deref, unregister reset (stefanha)
- add error reporting for ncq (stefanha)
- replace hw_error with DPRINTF (stefanha)
- move sg generation to sg users
- fix off-by-one in sglist interpretation
- make background engine work (queued commands)
- use ICH9 instead of ICH7 (aliguori)
- udpate to new APIs
--- Makefile.objs | 1 + hw/ide/ahci.c | 1524 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1525 insertions(+), 0 deletions(-) create mode 100644 hw/ide/ahci.c
Makefile.objs +1 -0
@@ -241,6 +241,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 +1524 -0
1,524 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 9/11 config: move ide core and pci to pci.mak
In reply to Alexander GrafEvery 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH 10/11 config: add ahci for pci capable machines
In reply to Alexander GrafThis 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
@@ -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
PATCH 11/11 ahci: set SATA Mode Select
In reply to Alexander GrafFrom: 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
@@ -1473,6 +1473,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
[Qemu-devel] [PATCH 12/11] ide: honor ncq for atapi
In reply to Alexander GrafATAPI also can do ncq, so let's expose the capability.
This patch makes CD-ROM support work on Windows 7 for me.
--- hw/ide/core.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-)
hw/ide/core.c +6 -0
@@ -217,6 +217,12 @@ static void ide_atapi_identify(IDEState *s)put_le16 (p +71 ,30 );/* in ns */ put_le16 (p +72 ,30 );/* in ns */ +if (s->ncq_queues) { +put_le16 (p +75 , s->ncq_queues -1 ); +/* NCQ supported */ +put_le16 (p +76 , (1 <<8 )); + } +put_le16 (p +80 ,0x1e );/* support up to ATA/ATAPI-4 */ #ifdef USE_DMA_CDROM put_le16 (p +88 ,0x3f | (1 <<13 ));/* udma5 set and supported */
Signature · 1 line
1.6.0.2
Am 14.12.2010 01:34, schrieb Alexander Graf:
Quoted 20 lines
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
Quoted 6 lines
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.gitahci
I have applied everything but patch 4 (including patch 12/11) to the block branch. Before I can include it in a pull request I need at least a new version of patch 3 and you'll probably want to have a new patch 4 in. There's no need to resend the rest of the patch series.
For the changes needed please see the comments on the individual patches.
Kevin
Quoted 26 lines · Kevin Wolf
Am 14.12.2010 01:34, schrieb Alexander Graf:
Quoted 25 lines
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.0This 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!
Quoted 8 lines
Quoted 1 line
git://repo.or.cz/qemu/ahci.gitahciI have applied everything but patch 4 (including patch 12/11) to the block branch. Before I can include it in a pull request I need at least a new version of patch 3 and you'll probably want to have a new patch 4 in. There's no need to resend the rest of the patch series.
For the changes needed please see the comments on the individual patches.
There you go, all new and shiny (actually working) versions of patch 3 and 4 :). Thanks for pulling this in - let's hope we'll get some happy users with this feature!
One thing that might be worth considering is to have preliminary seabios support for booting. Gerd does have something in the queue there ;).
Alex
Hi,
Quoted 3 lines
One thing that might be worth considering is to have preliminary seabios support for booting. Gerd does have something in the queue there ;).
Not in the queue, it's upstream. Just pull latest seabios. As it didn't got much testing yet it is off by default, so make sure to flip CONFIG_AHCI. Thats it ;)
cheers,
Gerd
Am 15.12.2010 um 09:28 schrieb Gerd Hoffmann <[email protected]>:
Quoted 8 lines
Hi,
Quoted 3 lines
One thing that might be worth considering is to have preliminary seabios support for booting. Gerd does have something in the queue there ;).
Not in the queue, it's upstream. Just pull latest seabios. As it didn't got much testing yet it is off by default, so make sure to flip
CONFIG_AHCI. Thats it ;)
Even better! Could we get that in for 0.14 still? I assume that means we need a stable seabios release.
Alex
Hi,
Quoted 2 lines
Even better! Could we get that in for 0.14 still? I assume that means we need a stable seabios release.
Also for Gleb's bootorder bits we'll need a seabios update. I think for that not all bits are in upstream seabios yet though. A new release once this is settled is probably a good idea, so we don't have to grab a random snapshot.
cheers,
Gerd
PATCH 3/12 ide: Split out BMDMA code from ATA core
In reply to Alexander GrafThe 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
v8 -> v9:
- fold in: split out irq setting
- fold in: move header definitions out
- make dma providers subclass of idedma (kwolf)
- s/set_status/add_status/g (kwolf)
v9 -> v10:
- move dma reset call to generic bus reset
--- hw/ide/cmd646.c | 6 +- hw/ide/core.c | 347 +++++++++++++++-------------------------------------- hw/ide/internal.h | 69 +++++------ hw/ide/pci.c | 280 ++++++++++++++++++++++++++++++++++++++++++- hw/ide/pci.h | 30 +++++ hw/ide/piix.c | 6 +- hw/ide/via.c | 6 +- 7 files changed, 446 insertions(+), 298 deletions(-)
hw/ide/cmd646.c +3 -3
@@ -167,9 +167,10 @@ 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->dma);if (i ==0 ) {register_ioport_write (addr,4 ,1 , bmdma_writeb_0, d);
@@ -218,7 +219,6 @@ static void cmd646_reset(void *opaque)for (i =0 ; i <2 ; i++) {ide_bus_reset (&d->bus[i]); -ide_dma_reset (&d->bmdma[i]); } }
hw/ide/core.c +98 -249
545 lines not on this page · raw message
hw/ide/internal.h +32 -37
120 lines not on this page · raw message
hw/ide/pci.c +277 -3
303 lines not on this page · raw message
hw/ide/pci.h +30 -0
@@ -3,6 +3,27 @@#include <hw/ide/internal.h> +typedef struct BMDMAState { +IDEDMA dma; +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 +31,15 @@ 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;void pci_ide_create_devs (PCIDevice *dev,DriveInfo **hd_table);
hw/ide/piix.c +3 -3
@@ -76,9 +76,10 @@ 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->dma);register_ioport_write (addr,1 ,1 , bmdma_cmd_writeb, bm);
@@ -99,7 +100,6 @@ static void piix3_reset(void *opaque)for (i =0 ; i <2 ; i++) {ide_bus_reset (&d->bus[i]); -ide_dma_reset (&d->bmdma[i]); }/* TODO: this is the default. do not override. */
hw/ide/via.c +3 -3
@@ -78,9 +78,10 @@ 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->dma);register_ioport_write (addr,1 ,1 , bmdma_cmd_writeb, bm);
@@ -101,7 +102,6 @@ static void via_reset(void *opaque)for (i =0 ; i <2 ; i++) {ide_bus_reset (&d->bus[i]); -ide_dma_reset (&d->bmdma[i]); }pci_set_word (pci_conf +PCI_COMMAND ,PCI_COMMAND_WAIT );
Signature · 1 line
1.6.0.2
PATCH 4/12 ide: move transfer_start after variable modification
In reply to Alexander GrafWe hook into transfer_start and immediately call the end function for ahci. This means that everything needs to be in place for the end function when we start the transfer, so let's move the function down to where all state is in place.
---
v9 -> v10:
- fix typo
--- hw/ide/core.c | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-)
hw/ide/core.c +4 -4
@@ -814,11 +814,11 @@ static void ide_atapi_cmd_reply_end(IDEState *s) size = s->cd_sector_size - s->io_buffer_index;if (size > s->elementary_transfer_size) size = s->elementary_transfer_size; -ide_transfer_start (s, s->io_buffer + s->io_buffer_index, - size, ide_atapi_cmd_reply_end); s->packet_transfer_size -= size; s->elementary_transfer_size -= size; s->io_buffer_index += size; +ide_transfer_start (s, s->io_buffer + s->io_buffer_index - size, + size, ide_atapi_cmd_reply_end); }else {/* a new transfer is needed */ s->nsector = (s->nsector & ~7 ) |ATAPI_INT_REASON_IO ;
@@ -843,11 +843,11 @@ static void ide_atapi_cmd_reply_end(IDEState *s)if (size > (s->cd_sector_size - s->io_buffer_index)) size = (s->cd_sector_size - s->io_buffer_index); } -ide_transfer_start (s, s->io_buffer + s->io_buffer_index, - size, ide_atapi_cmd_reply_end); s->packet_transfer_size -= size; s->elementary_transfer_size -= size; s->io_buffer_index += size; +ide_transfer_start (s, s->io_buffer + s->io_buffer_index - size, + size, ide_atapi_cmd_reply_end);ide_set_irq (s->bus);#ifdef DEBUG_IDE_ATAPI printf ("status=0x%x\n" , s->status);
Signature · 1 line
1.6.0.2