AHCI emulation support v7
cover AHCI emulation support v7
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
Alexander Graf (8):
ide: split ide command interpretation off
ide: fix whitespace gap in ide_exec_cmd
ide: add DMA hooks to bus ops
pci: add storage class for sata
pci: add ich7 pci id
ahci: add ahci emulation
ide: move pata specific parts to pata.c
config: add ahci for pci capable machines
Roland Elek (2):
ide: add support for ide bus ops
ide: add ncq identify data for ahci sata drives
Makefile.objs | 3 +- default-configs/pci.mak | 1 + hw/ide/ahci.c | 1375 +++++++++++++++++++++++++++++++++++++++++++++++ hw/ide/core.c | 874 ++++++++++++++----------------- hw/ide/internal.h | 37 +- hw/ide/pata.c | 178 ++++++ hw/pci.h | 1 + hw/pci_ids.h | 1 + 8 files changed, 1981 insertions(+), 489 deletions(-) create mode 100644 hw/ide/ahci.c create mode 100644 hw/ide/pata.c
PATCH 1/10 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
@@ -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
[Qemu-devel] Re: [PATCH 01/10] 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.
Signed-off-by Alexander Graf <[email protected]>---
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(-)
PATCH 2/10 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
[Qemu-devel] Re: [PATCH 02/10] 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.
Signed-off-by Alexander Graf <[email protected]>---
hw/ide/core.c | 734 ++++++++++++++++++++++++++++----------------------------1 files changed, 367 insertions(+), 367 deletions(-)
PATCH 3/10 ide: add support for ide bus ops
In reply to Alexander GrafFrom: Roland Elek <[email protected]>
We need to hook into some of the core IDE functionality for AHCI. To do that, the easiest way is to make explicit functions calls be implicit through a function call struct.
---
v1 -> v2:
- rename IDEExtender to IDEBusOps and make a pointer (kraxel)
v6 -> v7:
- change naming in IDEBusOps (stefanha, kwolf)
--- hw/ide/core.c | 36 +++++++++++++++++++++++++++++++++++- hw/ide/internal.h | 26 +++++++++++++++++++------- 2 files changed, 54 insertions(+), 8 deletions(-)
hw/ide/core.c +35 -1
@@ -67,6 +67,8 @@ static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret);static int ide_handle_rw_error (IDEState *s,int error,int op);static void ide_flush_cache (IDEState *s); +static void pata_dma_start (IDEState *s,BlockDriverCompletionFunc *dma_cb); +static void padstr (char *str,const char *src,int len) {int i, v;
@@ -325,6 +327,12 @@ static inline void ide_dma_submit_check(IDEState *s,static void ide_transfer_start (IDEState *s,uint8_t *buf,int size,EndTransferFunc *end_transfer_func) { + s->bus->ops->transfer_start (s,buf,size,end_transfer_func); +} + +static void pata_transfer_start (IDEState *s,uint8_t *buf,int size, +EndTransferFunc *end_transfer_func) +{ s->end_transfer_func = end_transfer_func; s->data_ptr = buf; s->data_end = buf + size;
@@ -2581,6 +2589,18 @@ static void ide_dummy_transfer_stop(IDEState *s) s->io_buffer[3 ] =0xff ; } +static void pata_set_irq (IDEBus *bus) +{ +BMDMAState *bm = bus->bmdma; + +if (!(bus->cmd &IDE_CMD_DISABLE_IRQ )) { +if (bm) { + bm->status |=BM_STATUS_INT ; + } +qemu_irq_raise (bus->irq); + } +} +static void ide_reset (IDEState *s) {#ifdef DEBUG_IDE
@@ -2717,6 +2737,12 @@ static void ide_init1(IDEBus *bus, int unit) ide_sector_write_timer_cb, s); } +static IDEBusOps pata_bus_ops = { + .transfer_start = pata_transfer_start, + .set_irq = pata_set_irq, + .dma_start = pata_dma_start, +}; +void ide_init2 (IDEBus *bus,qemu_irq irq) {int i;
@@ -2726,6 +2752,7 @@ void ide_init2(IDEBus *bus, qemu_irq irq)ide_reset (&bus->ifs[i]); } bus->irq = irq; + bus->ops = &pata_bus_ops; }/* TODO convert users to qdev and remove */
@@ -2749,6 +2776,7 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0, } } bus->irq = irq; + bus->ops = &pata_bus_ops; }void ide_init_ioport (IDEBus *bus,int iobase,int iobase2)
@@ -2920,9 +2948,10 @@ const VMStateDescription vmstate_ide_bus = {/***********************************************************/ /* PCI IDE definitions */ -static void ide_dma_start (IDEState *s,BlockDriverCompletionFunc *dma_cb) +static void pata_dma_start (IDEState *s,BlockDriverCompletionFunc *dma_cb) {BMDMAState *bm = s->bus->bmdma; +if (!bm)return ; bm->unit = s->unit;
@@ -2937,6 +2966,11 @@ static void ide_dma_start(IDEState *s, BlockDriverCompletionFunc *dma_cb) } } +static void ide_dma_start (IDEState *s,BlockDriverCompletionFunc *dma_cb) +{ + s->bus->ops->dma_start (s,dma_cb); +} +static void ide_dma_restart (IDEState *s,int is_read) {BMDMAState *bm = s->bus->bmdma;
hw/ide/internal.h +19 -7
@@ -21,6 +21,7 @@ typedef struct IDEDevice IDEDevice;typedef struct IDEDeviceInfo IDEDeviceInfo ;typedef struct IDEState IDEState ;typedef struct BMDMAState BMDMAState ; +typedef struct IDEBusOps IDEBusOps ;/* Bits of HD_STATUS */ #define ERR_STAT 0x01
@@ -367,6 +368,14 @@ typedef enum { IDE_HD, IDE_CD, IDE_CFATA } IDEDriveKind;typedef void EndTransferFunc (IDEState *); + +typedef void TransferStartFunc (IDEState *, +uint8_t *, +int , +EndTransferFunc *); +typedef void IRQSetFunc (IDEBus *); +typedef void DMAStartFunc (IDEState *,BlockDriverCompletionFunc *); +/* NOTE: IDEState represents in fact one drive */ struct IDEState {IDEBus *bus;
@@ -443,12 +452,21 @@ struct IDEState {uint8_t *smart_selftest_data; }; +/* This struct represents a device that uses an IDE bus, but requires +* modifications to how it works. An example is AHCI. */ +struct IDEBusOps { +TransferStartFunc *transfer_start; +IRQSetFunc *set_irq; +DMAStartFunc *dma_start; +}; +struct IDEBus {BusState qbus;IDEDevice *master;IDEDevice *slave;BMDMAState *bmdma;IDEState ifs[2 ]; +IDEBusOps *ops;uint8_t unit;uint8_t cmd;qemu_irq irq;
@@ -514,13 +532,7 @@ static inline IDEState *bmdma_active_if(BMDMAState *bmdma)static inline void ide_set_irq (IDEBus *bus) { -BMDMAState *bm = bus->bmdma; -if (!(bus->cmd &IDE_CMD_DISABLE_IRQ )) { -if (bm) { - bm->status |=BM_STATUS_INT ; - } -qemu_irq_raise (bus->irq); - } + bus->ops->set_irq (bus); }/* hw/ide/core.c */
Signature · 1 line
1.6.0.2
PATCH 4/10 ide: add DMA hooks to bus ops
In reply to Alexander GrafFor DMA operations, we need to hook into even more IDE functionality.
This patch adds the respective hooking points, allowing us to handle SG lists ourselves in the AHCI code.
---
v1 -> v2:
- make dma hooks explicit by putting them into ops struct (stefanha)
v6 -> v7:
- rename IDEBusOps (stefanha)
--- hw/ide/core.c | 9 ++++++--- hw/ide/internal.h | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-)
hw/ide/core.c +6 -3
@@ -614,7 +614,7 @@ static void ide_read_dma_cb(void *opaque, int ret) n = s->nsector; s->io_buffer_index =0 ; s->io_buffer_size = n *512 ; -if (dma_buf_prepare (bm,1 ) ==0 ) +if (s->bus->ops->dma_prepare (bm,1 ) ==0 ) goto eot;#ifdef DEBUG_AIO printf ("aio_read: sector_num=%" PRId64" n=%d\n" , sector_num, n);
@@ -756,7 +756,7 @@ static void ide_write_dma_cb(void *opaque, int ret) n = s->nsector; s->io_buffer_size = n *512 ;/* launch next transfer */ -if (dma_buf_prepare (bm,0 ) ==0 ) +if (s->bus->ops->dma_prepare (bm,0 ) ==0 ) goto eot;#ifdef DEBUG_AIO printf ("aio_write: sector_num=%" PRId64" n=%d\n" , sector_num, n);
@@ -1064,7 +1064,7 @@ static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret) s->lba += n; } s->packet_transfer_size -= s->io_buffer_size; -if (dma_buf_rw (bm,1 ) ==0 ) +if (s->bus->ops->dma_rw (bm,1 ) ==0 ) goto eot; }
@@ -2716,6 +2716,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, }else {pstrcpy (s->version,sizeof (s->version),QEMU_VERSION ); } +ide_reset (s);bdrv_set_removable (bs, s->drive_kind ==IDE_CD );return 0 ;
@@ -2741,6 +2742,8 @@ static IDEBusOps pata_bus_ops = { .transfer_start = pata_transfer_start, .set_irq = pata_set_irq, .dma_start = pata_dma_start, + .dma_prepare = dma_buf_prepare, + .dma_rw = dma_buf_rw, };void ide_init2 (IDEBus *bus,qemu_irq irq)
hw/ide/internal.h +4 -0
@@ -375,6 +375,8 @@ typedef void TransferStartFunc(IDEState *, EndTransferFunc *);typedef void IRQSetFunc (IDEBus *);typedef void DMAStartFunc (IDEState *,BlockDriverCompletionFunc *); +typedef int DMAPrepareFunc (BMDMAState *,int ); +typedef int DMARWFunc (BMDMAState *,int );/* NOTE: IDEState represents in fact one drive */ struct IDEState {
@@ -458,6 +460,8 @@ struct IDEBusOps {TransferStartFunc *transfer_start;IRQSetFunc *set_irq;DMAStartFunc *dma_start; +DMAPrepareFunc *dma_prepare; +DMARWFunc *dma_rw; };struct IDEBus {
Signature · 1 line
1.6.0.2
[Qemu-devel] Re: [PATCH 04/10] ide: add DMA hooks to bus ops
Quoted 14 lines · Alexander Graf
For DMA operations, we need to hook into even more IDE functionality.
This patch adds the respective hooking points, allowing us to handle SG lists ourselves in the AHCI code.
Signed-off-by Roland Elek <[email protected]>Signed-off-by Alexander Graf <[email protected]>---
v1 -> v2:
- make dma hooks explicit by putting them into ops struct (stefanha)
Quoted 7 lines
v6 -> v7:
- rename IDEBusOps (stefanha)
---
hw/ide/core.c | 9 ++++++---
hw/ide/internal.h | 4 ++++2 files changed, 10 insertions(+), 3 deletions(-)
PATCH 5/10 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
@@ -147,6 +147,13 @@ static void ide_identify(IDEState *s)put_le16 (p +66 ,120 );put_le16 (p +67 ,120 );put_le16 (p +68 ,120 ); + +if (s->ncq_queues) { +put_le16 (p +75 , s->ncq_queues -1 ); +/* NCQ supported */ +put_le16 (p +76 , (1 <<8 )); + } +put_le16 (p +80 ,0xf0 );/* ata3 -> ata6 supported */ put_le16 (p +81 ,0x16 );/* conforms to ata5 */ /* 14=NOP supported, 5=WCACHE supported, 0=SMART supported */
hw/ide/internal.h +2 -0
@@ -452,6 +452,8 @@ struct IDEState {int smart_errors;uint8_t smart_selftest_count;uint8_t *smart_selftest_data; +/* AHCI */ +int ncq_queues; };/* This struct represents a device that uses an IDE bus, but requires
Signature · 1 line
1.6.0.2
[Qemu-devel] Re: [PATCH 05/10] ide: add ncq identify data for ahci sata drives
Quoted 11 lines · Alexander Graf
From: Roland Elek <[email protected]>
I modified
ide_identify()to include the zero-based queue length value in word 75, and set bit 8 in word 76 to signal NCQ support in the identify data for AHCI SATA drives.Signed-off-by Roland Elek <[email protected]>---
hw/ide/core.c | 7 +++++++
hw/ide/internal.h | 2 ++2 files changed, 9 insertions(+), 0 deletions(-)
PATCH 6/10 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
[Qemu-devel] Re: [PATCH 06/10] pci: add storage class for sata
Quoted 6 lines · Alexander Graf
This patch adds the storage sata class id.
Signed-off-by Alexander Graf <[email protected]>---
hw/pci_ids.h | 1 +1 files changed, 1 insertions(+), 0 deletions(-)
PATCH 7/10 pci: add ich7 pci id
In reply to Alexander GrafWe 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
@@ -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
[Qemu-devel] Re: [PATCH 07/10] pci: add ich7 pci id
Quoted 15 lines · Alexander Graf
We need a PCI ID for our new AHCI adapter. I just picked an ICH-7M because that's the one built into the first Macbooks.
This patch adds a PCI ID define for an ICH-7 AHCI adapter.
Signed-off-by Alexander Graf <[email protected]>---
v3 -> v4:
- add ICH7 instead of ICH7M (herbszt)
v4 -> v5:
Quoted 8 lines
- 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(-)
PATCH 8/10 ahci: add ahci emulation
In reply to Alexander GrafThis 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
--- Makefile.objs | 1 + hw/ide/ahci.c | 1375 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1376 insertions(+), 0 deletions(-) create mode 100644 hw/ide/ahci.c
Makefile.objs +1 -0
@@ -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 +1375 -0
1,375 lines not on this page · raw message
Signature · 1 line
1.6.0.2
PATCH 9/10 ide: move pata specific parts to pata.c
In reply to Alexander GrafDue to popular request, this patch moves pieces that are successfully identified as PATA only to a new file called pata.c.
---
v6 -> v7:
- stick to new IDEBusOps (stefanha, kwolf)
--- Makefile.objs | 2 +- hw/ide/core.c | 144 +------------------------------------------ hw/ide/internal.h | 3 + hw/ide/pata.c | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 184 insertions(+), 143 deletions(-) create mode 100644 hw/ide/pata.c
Makefile.objs +1 -1
@@ -230,7 +230,7 @@ hw-obj-$(CONFIG_LAN9118) += lan9118.o hw-obj-$(CONFIG_NE2000_ISA) += ne2000-isa.o # IDE -hw-obj-$(CONFIG_IDE_CORE) += ide/core.o +hw-obj-$(CONFIG_IDE_CORE) += ide/core.o ide/pata.o hw-obj-$(CONFIG_IDE_QDEV) += ide/qdev.o hw-obj-$(CONFIG_IDE_PCI) += ide/pci.o hw-obj-$(CONFIG_IDE_ISA) += ide/isa.o
hw/ide/core.c +2 -142
204 lines not on this page · raw message
hw/ide/internal.h +3 -0
@@ -590,4 +590,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val);void ide_bus_new (IDEBus *idebus,DeviceState *dev);IDEDevice *ide_create_drive (IDEBus *bus,int unit,DriveInfo *drive); +/* hw/ide/pata.c */ +void pata_init (IDEBus *bus); +#endif /* HW_IDE_INTERNAL_H */
hw/ide/pata.c new file +178 -0
178 lines not on this page · raw message
Signature · 1 line
1.6.0.2
[Qemu-devel] Re: [PATCH 09/10] ide: move pata specific parts to pata.c
Quoted 9 lines · Alexander Graf
Due to popular request, this patch moves pieces that are successfully identified as PATA only to a new file called
pata.c.Signed-off-by Alexander Graf <[email protected]>---
v6 -> v7:
Quoted 8 lines
- stick to new IDEBusOps (stefanha, kwolf)
---
Makefile.objs | 2 +-
hw/ide/core.c | 144 +------------------------------------------hw/ide/internal.h| 3 +
hw/ide/pata.c | 178 +++++++++++++++++++++++++++++++++++++++++++++++++++++4 files changed, 184 insertions(+), 143 deletions(-)create mode 100644
hw/ide/pata.c
PATCH 10/10 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
@@ -10,3 +10,4 @@ CONFIG_PCNET_COMMON=y CONFIG_LSI_SCSI_PCI=y CONFIG_RTL8139_PCI=y CONFIG_E1000_PCI=y +CONFIG_AHCI=y
Signature · 1 line
1.6.0.2