AHCI emulation support v4
cover AHCI emulation support v4
This patch adds support for AHCI emulation. I have tested and verified it works in Linux, OpenBSD, Windows Vista and Windows 7. This AHCI emulation supports NCQ, so multiple read or write requests can be outstanding at the same time.
The code is however not fully optimized yet. I'm fairly sure that there are low hanging performance fruits to be found still :). In my simple benchmarks I achieved about 2/3rd of virtio performance.
Also, this AHCI emulation layer does not support legacy mode. So if you're using a disk with this emulation, you do not get it exposed using the legacy IDE interfaces.
Another nitpick is CD-ROM support in Windows. Somehow it doesn't detect a CD-ROM drive attached to AHCI. At least it doesn't list it.
To attach an AHCI disk to your VM, please use
-drive file=...,if=sata
This should do the trick for x86. On other platforms, you need to add the ahci host controller using -device and add CONFIG_AHCI to its default config. Big endian hosts are still broken due to qemu shortcomings in mmio handing. Expect patches to follow.
This patch set is based on work done during the Google Summer of Code. I was mentoring a student, Roland Elek, who wrote most of the AHCI emulation code based on a patch from Chong Qiao. A bunch of other people were also involved, so everybody who I didn't mention - thanks a lot!
git://repo.or.cz/qemu/ahci.git ahci
v1 -> v2:
- rename IDEExtender to IDEBusOps and make a pointer (kraxel)
- make dma hooks explicit by putting them into ops struct (stefanha)
- use qdev buses (kraxel)
- minor cleanups
- dprintf overhaul
- add reset function
v2 -> v3:
- add msi support (kraxel)
- use MIN macro (kraxel)
- add msi support (kraxel)
- fix ncq with multiple ports
- zap qdev properties (kraxel)
- redesign legacy IF_SATA hooks (kraxel)
- don't build ahci as part of target
- move to ide/ (kwolf)
v3 -> v4:
- prepare for endianness safety
- add lspci dump (herbszt)
- use ich7 instead of ich7m (herbszt)
- fix lst+fis mapping (kraxel)
- coding style (blue swirl)
- explicit mmio setters/getters (blue swirl)
- split pata code out to pata.c (kwolf)
- only include config-devices.h in machine description (blue swirl)
Alex
Alexander Graf (10):
ide: split ide command interpretation off
ide: fix whitespace gap in ide_exec_cmd
ide: add DMA hooks to bus ops
pci: add storage class for sata
pci: add ich7 pci id
ahci: add ahci emulation
ahci: add -drive support
config: Add header file for device config options
ahci: spawn controller on demand
ide: move pata specific parts to pata.c
Roland Elek (2):
ide: add support for ide bus ops
ide: add ncq identify data for ahci sata drives
Makefile.objs | 3 +- Makefile.target | 5 +- blockdev.c | 6 +- blockdev.h | 1 + default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/ide/ahci.c | 1397 ++++++++++++++++++++++++++++++++++++ hw/ide/core.c | 874 ++++++++++------------- hw/ide/internal.h | 37 +- hw/ide/pata.c | 178 +++++ hw/pc.h | 1 + hw/pc_piix.c | 4 + hw/pci.h | 1 + hw/pci_ids.h | 1 + qemu-common.h | 2 +- 15 files changed, 2020 insertions(+), 492 deletions(-) create mode 100644 hw/ide/ahci.c create mode 100644 hw/ide/pata.c
PATCH 1/12 ide: split ide command interpretation off
The ATA command interpretation code can be used for PATA and SATA interfaces alike. So let's split it out into a separate function.
--- hw/ide/core.c | 20 ++++++++++++++------ hw/ide/internal.h | 2 ++ 2 files changed, 16 insertions(+), 6 deletions(-)
hw/ide/core.c +14 -6
@@ -1790,9 +1790,6 @@ static void ide_clear_hob(IDEBus *bus)void ide_ioport_write (void *opaque,uint32_t addr,uint32_t val) {IDEBus *bus = opaque; -IDEState *s; -int n; -int lba48 =0 ;#ifdef DEBUG_IDE printf ("IDE: write addr=0x%x val=0x%02x\n" , addr, val);
@@ -1853,17 +1850,29 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)default :case 7 :/* command */ +ide_exec_cmd (opaque, val); +break ; + } +} + + +void ide_exec_cmd (IDEBus *bus,uint32_t val) +{ +IDEState *s; +int n; +int lba48 =0 ; +#if defined(DEBUG_IDE )printf ("ide: CMD=%02x\n" , val);#endif s =idebus_active_if (bus);/* ignore commands to non existant slave */ if (s != bus->ifs && !s->bs) -break ; +return ;/* Only DEVICE RESET is allowed while BSY or/and DRQ are set */ if ((s->status & (BUSY_STAT |DRQ_STAT )) && val !=WIN_DEVICE_RESET ) -break ; +return ;switch (val) {case WIN_IDENTIFY :
@@ -2354,7 +2363,6 @@ void ide_ioport_write(void *opaque, uint32_t addr, uint32_t val)ide_set_irq (s->bus);break ; } - } }uint32_t ide_ioport_read (void *opaque,uint32_t addr1)
hw/ide/internal.h +2 -0
@@ -564,6 +564,8 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0, DriveInfo *hd1, qemu_irq irq);void ide_init_ioport (IDEBus *bus,int iobase,int iobase2); +void ide_exec_cmd (IDEBus *bus,uint32_t val); +/* hw/ide/qdev.c */ void ide_bus_new (IDEBus *idebus,DeviceState *dev);IDEDevice *ide_create_drive (IDEBus *bus,int unit,DriveInfo *drive);
Signature · 1 line
1.6.0.2
PATCH 2/12 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
@@ -1863,423 +1863,423 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val)int lba48 =0 ;#if defined(DEBUG_IDE ) -printf ("ide: CMD=%02x\n" , val); +printf ("ide: CMD=%02x\n" , val);#endif - s =idebus_active_if (bus); -/* ignore commands to non existant slave */ -if (s != bus->ifs && !s->bs) -return ; + s =idebus_active_if (bus); +/* ignore commands to non existant slave */ +if (s != bus->ifs && !s->bs) +return ; -/* Only DEVICE RESET is allowed while BSY or/and DRQ are set */ -if ((s->status & (BUSY_STAT |DRQ_STAT )) && val !=WIN_DEVICE_RESET ) -return ; +/* Only DEVICE RESET is allowed while BSY or/and DRQ are set */ +if ((s->status & (BUSY_STAT |DRQ_STAT )) && val !=WIN_DEVICE_RESET ) +return ; -switch (val) { -case WIN_IDENTIFY : -if (s->bs && s->drive_kind !=IDE_CD ) { -if (s->drive_kind !=IDE_CFATA ) -ide_identify (s); -else -ide_cfata_identify (s); - s->status =READY_STAT |SEEK_STAT ; -ide_transfer_start (s, s->io_buffer,512 , ide_transfer_stop); - }else { -if (s->drive_kind ==IDE_CD ) { -ide_set_signature (s); - } -ide_abort_command (s); - } -ide_set_irq (s->bus); -break ; -case WIN_SPECIFY : -case WIN_RECAL : - s->error =0 ; +switch (val) { +case WIN_IDENTIFY : +if (s->bs && s->drive_kind !=IDE_CD ) { +if (s->drive_kind !=IDE_CFATA ) +ide_identify (s); +else +ide_cfata_identify (s); s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); -break ; -case WIN_SETMULT : -if (s->drive_kind ==IDE_CFATA && s->nsector ==0 ) { -/* Disable Read and Write Multiple */ - s->mult_sectors =0 ; - s->status =READY_STAT |SEEK_STAT ; - }else if ((s->nsector &0xff ) !=0 && - ((s->nsector &0xff ) >MAX_MULT_SECTORS || - (s->nsector & (s->nsector -1 )) !=0 )) { -ide_abort_command (s); - }else { - s->mult_sectors = s->nsector &0xff ; - s->status =READY_STAT |SEEK_STAT ; +ide_transfer_start (s, s->io_buffer,512 , ide_transfer_stop); + }else { +if (s->drive_kind ==IDE_CD ) { +ide_set_signature (s); } -ide_set_irq (s->bus); -break ; -case WIN_VERIFY_EXT : - lba48 =1 ; -case WIN_VERIFY : -case WIN_VERIFY_ONCE : -/* do sector number check ? */ -ide_cmd_lba48_transform (s, lba48); +ide_abort_command (s); + } +ide_set_irq (s->bus); +break ; +case WIN_SPECIFY : +case WIN_RECAL : + s->error =0 ; + s->status =READY_STAT |SEEK_STAT ; +ide_set_irq (s->bus); +break ; +case WIN_SETMULT : +if (s->drive_kind ==IDE_CFATA && s->nsector ==0 ) { +/* Disable Read and Write Multiple */ + s->mult_sectors =0 ; s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); -break ; + }else if ((s->nsector &0xff ) !=0 && + ((s->nsector &0xff ) >MAX_MULT_SECTORS || + (s->nsector & (s->nsector -1 )) !=0 )) { +ide_abort_command (s); + }else { + s->mult_sectors = s->nsector &0xff ; + s->status =READY_STAT |SEEK_STAT ; + } +ide_set_irq (s->bus); +break ; +case WIN_VERIFY_EXT : + lba48 =1 ; +case WIN_VERIFY : +case WIN_VERIFY_ONCE : +/* do sector number check ? */ +ide_cmd_lba48_transform (s, lba48); + s->status =READY_STAT |SEEK_STAT ; +ide_set_irq (s->bus); +break ;case WIN_READ_EXT : - lba48 =1 ; -case WIN_READ : -case WIN_READ_ONCE : -if (!s->bs) - goto abort_cmd; -ide_cmd_lba48_transform (s, lba48); - s->req_nb_sectors =1 ; -ide_sector_read (s); -break ; + lba48 =1 ; +case WIN_READ : +case WIN_READ_ONCE : +if (!s->bs) + goto abort_cmd; +ide_cmd_lba48_transform (s, lba48); + s->req_nb_sectors =1 ; +ide_sector_read (s); +break ;case WIN_WRITE_EXT : - lba48 =1 ; -case WIN_WRITE : -case WIN_WRITE_ONCE : -case CFA_WRITE_SECT_WO_ERASE : -case WIN_WRITE_VERIFY : -ide_cmd_lba48_transform (s, lba48); - s->error =0 ; - s->status =SEEK_STAT |READY_STAT ; - s->req_nb_sectors =1 ; -ide_transfer_start (s, s->io_buffer,512 , ide_sector_write); - s->media_changed =1 ; -break ; + lba48 =1 ; +case WIN_WRITE : +case WIN_WRITE_ONCE : +case CFA_WRITE_SECT_WO_ERASE : +case WIN_WRITE_VERIFY : +ide_cmd_lba48_transform (s, lba48); + s->error =0 ; + s->status =SEEK_STAT |READY_STAT ; + s->req_nb_sectors =1 ; +ide_transfer_start (s, s->io_buffer,512 , ide_sector_write); + s->media_changed =1 ; +break ;case WIN_MULTREAD_EXT : - lba48 =1 ; -case WIN_MULTREAD : -if (!s->mult_sectors) - goto abort_cmd; -ide_cmd_lba48_transform (s, lba48); - s->req_nb_sectors = s->mult_sectors; -ide_sector_read (s); -break ; -case WIN_MULTWRITE_EXT : - lba48 =1 ; -case WIN_MULTWRITE : -case CFA_WRITE_MULTI_WO_ERASE : -if (!s->mult_sectors) - goto abort_cmd; -ide_cmd_lba48_transform (s, lba48); - s->error =0 ; - s->status =SEEK_STAT |READY_STAT ; - s->req_nb_sectors = s->mult_sectors; - n = s->nsector; -if (n > s->req_nb_sectors) - n = s->req_nb_sectors; -ide_transfer_start (s, s->io_buffer,512 * n, ide_sector_write); - s->media_changed =1 ; -break ; + lba48 =1 ; +case WIN_MULTREAD : +if (!s->mult_sectors) + goto abort_cmd; +ide_cmd_lba48_transform (s, lba48); + s->req_nb_sectors = s->mult_sectors; +ide_sector_read (s); +break ; +case WIN_MULTWRITE_EXT : + lba48 =1 ; +case WIN_MULTWRITE : +case CFA_WRITE_MULTI_WO_ERASE : +if (!s->mult_sectors) + goto abort_cmd; +ide_cmd_lba48_transform (s, lba48); + s->error =0 ; + s->status =SEEK_STAT |READY_STAT ; + s->req_nb_sectors = s->mult_sectors; + n = s->nsector; +if (n > s->req_nb_sectors) + n = s->req_nb_sectors; +ide_transfer_start (s, s->io_buffer,512 * n, ide_sector_write); + s->media_changed =1 ; +break ;case WIN_READDMA_EXT : - lba48 =1 ; -case WIN_READDMA : -case WIN_READDMA_ONCE : -if (!s->bs) - goto abort_cmd; -ide_cmd_lba48_transform (s, lba48); -ide_sector_read_dma (s); -break ; + lba48 =1 ; +case WIN_READDMA : +case WIN_READDMA_ONCE : +if (!s->bs) + goto abort_cmd; +ide_cmd_lba48_transform (s, lba48); +ide_sector_read_dma (s); +break ;case WIN_WRITEDMA_EXT : - lba48 =1 ; -case WIN_WRITEDMA : -case WIN_WRITEDMA_ONCE : -if (!s->bs) - goto abort_cmd; -ide_cmd_lba48_transform (s, lba48); -ide_sector_write_dma (s); - s->media_changed =1 ; -break ; -case WIN_READ_NATIVE_MAX_EXT : - lba48 =1 ; -case WIN_READ_NATIVE_MAX : -ide_cmd_lba48_transform (s, lba48); -ide_set_sector (s, s->nb_sectors -1 ); - s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); -break ; -case WIN_CHECKPOWERMODE1 : -case WIN_CHECKPOWERMODE2 : - s->nsector =0xff ;/* device active or idle */ + lba48 =1 ; +case WIN_WRITEDMA : +case WIN_WRITEDMA_ONCE : +if (!s->bs) + goto abort_cmd; +ide_cmd_lba48_transform (s, lba48); +ide_sector_write_dma (s); + s->media_changed =1 ; +break ; +case WIN_READ_NATIVE_MAX_EXT : + lba48 =1 ; +case WIN_READ_NATIVE_MAX : +ide_cmd_lba48_transform (s, lba48); +ide_set_sector (s, s->nb_sectors -1 ); + s->status =READY_STAT |SEEK_STAT ; +ide_set_irq (s->bus); +break ; +case WIN_CHECKPOWERMODE1 : +case WIN_CHECKPOWERMODE2 : + s->nsector =0xff ;/* device active or idle */ + s->status =READY_STAT |SEEK_STAT ; +ide_set_irq (s->bus); +break ; +case WIN_SETFEATURES : +if (!s->bs) + goto abort_cmd; +/* XXX: valid for CDROM ? */ +switch (s->feature) { +case 0xcc :/* reverting to power-on defaults enable */ +case 0x66 :/* reverting to power-on defaults disable */ +case 0x02 :/* write cache enable */ +case 0x82 :/* write cache disable */ +case 0xaa :/* read look-ahead enable */ +case 0x55 :/* read look-ahead disable */ +case 0x05 :/* set advanced power management mode */ +case 0x85 :/* disable advanced power management mode */ +case 0x69 :/* NOP */ +case 0x67 :/* NOP */ +case 0x96 :/* NOP */ +case 0x9a :/* NOP */ +case 0x42 :/* enable Automatic Acoustic Mode */ +case 0xc2 :/* disable Automatic Acoustic Mode */ s->status =READY_STAT |SEEK_STAT ;ide_set_irq (s->bus);break ; -case WIN_SETFEATURES : -if (!s->bs) - goto abort_cmd; -/* XXX: valid for CDROM ? */ -switch (s->feature) { -case 0xcc :/* reverting to power-on defaults enable */ -case 0x66 :/* reverting to power-on defaults disable */ -case 0x02 :/* write cache enable */ -case 0x82 :/* write cache disable */ -case 0xaa :/* read look-ahead enable */ -case 0x55 :/* read look-ahead disable */ -case 0x05 :/* set advanced power management mode */ -case 0x85 :/* disable advanced power management mode */ -case 0x69 :/* NOP */ -case 0x67 :/* NOP */ -case 0x96 :/* NOP */ -case 0x9a :/* NOP */ -case 0x42 :/* enable Automatic Acoustic Mode */ -case 0xc2 :/* disable Automatic Acoustic Mode */ - s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); -break ; -case 0x03 : {/* set transfer mode */ +case 0x03 : {/* set transfer mode */ uint8_t val = s->nsector &0x07 ; -uint16_t *identify_data = (uint16_t *)s->identify_data; +uint16_t *identify_data = (uint16_t *)s->identify_data;switch (s->nsector >>3 ) { -case 0x00 :/* pio default */ -case 0x01 :/* pio mode */ +case 0x00 :/* pio default */ +case 0x01 :/* pio mode */ put_le16 (identify_data +62 ,0x07 );put_le16 (identify_data +63 ,0x07 );put_le16 (identify_data +88 ,0x3f );break ; -case 0x02 :/* sigle word dma mode*/ +case 0x02 :/* sigle word dma mode*/ put_le16 (identify_data +62 ,0x07 | (1 << (val +8 )));put_le16 (identify_data +63 ,0x07 );put_le16 (identify_data +88 ,0x3f );break ; -case 0x04 :/* mdma mode */ +case 0x04 :/* mdma mode */ put_le16 (identify_data +62 ,0x07 );put_le16 (identify_data +63 ,0x07 | (1 << (val +8 )));put_le16 (identify_data +88 ,0x3f );break ; -case 0x08 :/* udma mode */ +case 0x08 :/* udma mode */ put_le16 (identify_data +62 ,0x07 );put_le16 (identify_data +63 ,0x07 );put_le16 (identify_data +88 ,0x3f | (1 << (val +8 )));break ; -default : +default : goto abort_cmd; } - s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); -break ; - } -default : - goto abort_cmd; - } -break ; -case WIN_FLUSH_CACHE : -case WIN_FLUSH_CACHE_EXT : -ide_flush_cache (s); -break ; -case WIN_STANDBY : -case WIN_STANDBY2 : -case WIN_STANDBYNOW1 : -case WIN_STANDBYNOW2 : -case WIN_IDLEIMMEDIATE : -case CFA_IDLEIMMEDIATE : -case WIN_SETIDLE1 : -case WIN_SETIDLE2 : -case WIN_SLEEPNOW1 : -case WIN_SLEEPNOW2 : - s->status =READY_STAT ; -ide_set_irq (s->bus); -break ; -case WIN_SEEK : -if (s->drive_kind ==IDE_CD ) - goto abort_cmd; -/* XXX: Check that seek is within bounds */ s->status =READY_STAT |SEEK_STAT ;ide_set_irq (s->bus);break ; -/* ATAPI commands */ -case WIN_PIDENTIFY : -if (s->drive_kind ==IDE_CD ) { -ide_atapi_identify (s); - s->status =READY_STAT |SEEK_STAT ; -ide_transfer_start (s, s->io_buffer,512 , ide_transfer_stop); - }else { -ide_abort_command (s); - } -ide_set_irq (s->bus); -break ; -case WIN_DIAGNOSE : -ide_set_signature (s); -if (s->drive_kind ==IDE_CD ) - s->status =0 ;/* ATAPI spec (v6) section 9.10 defines packet -* devices to return a clear status register -* with READY_STAT *not* set. */ -else - s->status =READY_STAT |SEEK_STAT ; - s->error =0x01 ;/* Device 0 passed, Device 1 passed or not -* present. -*/ -ide_set_irq (s->bus); -break ; -case WIN_SRST : -if (s->drive_kind !=IDE_CD ) - goto abort_cmd; -ide_set_signature (s); - s->status =0x00 ;/* NOTE: READY is _not_ set */ - s->error =0x01 ; -break ; -case WIN_PACKETCMD : -if (s->drive_kind !=IDE_CD ) - goto abort_cmd; -/* overlapping commands not supported */ -if (s->feature &0x02 ) - goto abort_cmd; + } +default : + goto abort_cmd; + } +break ; +case WIN_FLUSH_CACHE : +case WIN_FLUSH_CACHE_EXT : +ide_flush_cache (s); +break ; +case WIN_STANDBY : +case WIN_STANDBY2 : +case WIN_STANDBYNOW1 : +case WIN_STANDBYNOW2 : +case WIN_IDLEIMMEDIATE : +case CFA_IDLEIMMEDIATE : +case WIN_SETIDLE1 : +case WIN_SETIDLE2 : +case WIN_SLEEPNOW1 : +case WIN_SLEEPNOW2 : + s->status =READY_STAT ; +ide_set_irq (s->bus); +break ; +case WIN_SEEK : +if (s->drive_kind ==IDE_CD ) + goto abort_cmd; +/* XXX: Check that seek is within bounds */ + s->status =READY_STAT |SEEK_STAT ; +ide_set_irq (s->bus); +break ; +/* ATAPI commands */ +case WIN_PIDENTIFY : +if (s->drive_kind ==IDE_CD ) { +ide_atapi_identify (s); s->status =READY_STAT |SEEK_STAT ; - s->atapi_dma = s->feature &1 ; - s->nsector =1 ; -ide_transfer_start (s, s->io_buffer,ATAPI_PACKET_SIZE , - ide_atapi_cmd); -break ; -/* CF-ATA commands */ -case CFA_REQ_EXT_ERROR_CODE : -if (s->drive_kind !=IDE_CFATA ) - goto abort_cmd; - s->error =0x09 ;/* miscellaneous error */ +ide_transfer_start (s, s->io_buffer,512 , ide_transfer_stop); + }else { +ide_abort_command (s); + } +ide_set_irq (s->bus); +break ; +case WIN_DIAGNOSE : +ide_set_signature (s); +if (s->drive_kind ==IDE_CD ) + s->status =0 ;/* ATAPI spec (v6) section 9.10 defines packet +* devices to return a clear status register +* with READY_STAT *not* set. */ +else s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); + s->error =0x01 ;/* Device 0 passed, Device 1 passed or not +* present. +*/ +ide_set_irq (s->bus); +break ; +case WIN_SRST : +if (s->drive_kind !=IDE_CD ) + goto abort_cmd; +ide_set_signature (s); + s->status =0x00 ;/* NOTE: READY is _not_ set */ + s->error =0x01 ; +break ; +case WIN_PACKETCMD : +if (s->drive_kind !=IDE_CD ) + goto abort_cmd; +/* overlapping commands not supported */ +if (s->feature &0x02 ) + goto abort_cmd; + s->status =READY_STAT |SEEK_STAT ; + s->atapi_dma = s->feature &1 ; + s->nsector =1 ; +ide_transfer_start (s, s->io_buffer,ATAPI_PACKET_SIZE , + ide_atapi_cmd); +break ; +/* CF-ATA commands */ +case CFA_REQ_EXT_ERROR_CODE : +if (s->drive_kind !=IDE_CFATA ) + goto abort_cmd; + s->error =0x09 ;/* miscellaneous error */ + s->status =READY_STAT |SEEK_STAT ; +ide_set_irq (s->bus); +break ; +case CFA_ERASE_SECTORS : +case CFA_WEAR_LEVEL : +if (s->drive_kind !=IDE_CFATA ) + goto abort_cmd; +if (val ==CFA_WEAR_LEVEL ) + s->nsector =0 ; +if (val ==CFA_ERASE_SECTORS ) + s->media_changed =1 ; + s->error =0x00 ; + s->status =READY_STAT |SEEK_STAT ; +ide_set_irq (s->bus); +break ; +case CFA_TRANSLATE_SECTOR : +if (s->drive_kind !=IDE_CFATA ) + goto abort_cmd; + s->error =0x00 ; + s->status =READY_STAT |SEEK_STAT ; +memset (s->io_buffer,0 ,0x200 ); + s->io_buffer[0x00 ] = s->hcyl;/* Cyl MSB */ + s->io_buffer[0x01 ] = s->lcyl;/* Cyl LSB */ + s->io_buffer[0x02 ] = s->select;/* Head */ + s->io_buffer[0x03 ] = s->sector;/* Sector */ + s->io_buffer[0x04 ] =ide_get_sector (s) >>16 ;/* LBA MSB */ + s->io_buffer[0x05 ] =ide_get_sector (s) >>8 ;/* LBA */ + s->io_buffer[0x06 ] =ide_get_sector (s) >>0 ;/* LBA LSB */ + s->io_buffer[0x13 ] =0x00 ;/* Erase flag */ + s->io_buffer[0x18 ] =0x00 ;/* Hot count */ + s->io_buffer[0x19 ] =0x00 ;/* Hot count */ + s->io_buffer[0x1a ] =0x01 ;/* Hot count */ +ide_transfer_start (s, s->io_buffer,0x200 , ide_transfer_stop); +ide_set_irq (s->bus); +break ; +case CFA_ACCESS_METADATA_STORAGE : +if (s->drive_kind !=IDE_CFATA ) + goto abort_cmd; +switch (s->feature) { +case 0x02 :/* Inquiry Metadata Storage */ +ide_cfata_metadata_inquiry (s);break ; -case CFA_ERASE_SECTORS : -case CFA_WEAR_LEVEL : -if (s->drive_kind !=IDE_CFATA ) - goto abort_cmd; -if (val ==CFA_WEAR_LEVEL ) - s->nsector =0 ; -if (val ==CFA_ERASE_SECTORS ) - s->media_changed =1 ; - s->error =0x00 ; - s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); +case 0x03 :/* Read Metadata Storage */ +ide_cfata_metadata_read (s);break ; -case CFA_TRANSLATE_SECTOR : -if (s->drive_kind !=IDE_CFATA ) - goto abort_cmd; - s->error =0x00 ; - s->status =READY_STAT |SEEK_STAT ; -memset (s->io_buffer,0 ,0x200 ); - s->io_buffer[0x00 ] = s->hcyl;/* Cyl MSB */ - s->io_buffer[0x01 ] = s->lcyl;/* Cyl LSB */ - s->io_buffer[0x02 ] = s->select;/* Head */ - s->io_buffer[0x03 ] = s->sector;/* Sector */ - s->io_buffer[0x04 ] =ide_get_sector (s) >>16 ;/* LBA MSB */ - s->io_buffer[0x05 ] =ide_get_sector (s) >>8 ;/* LBA */ - s->io_buffer[0x06 ] =ide_get_sector (s) >>0 ;/* LBA LSB */ - s->io_buffer[0x13 ] =0x00 ;/* Erase flag */ - s->io_buffer[0x18 ] =0x00 ;/* Hot count */ - s->io_buffer[0x19 ] =0x00 ;/* Hot count */ - s->io_buffer[0x1a ] =0x01 ;/* Hot count */ -ide_transfer_start (s, s->io_buffer,0x200 , ide_transfer_stop); -ide_set_irq (s->bus); +case 0x04 :/* Write Metadata Storage */ +ide_cfata_metadata_write (s);break ; -case CFA_ACCESS_METADATA_STORAGE : -if (s->drive_kind !=IDE_CFATA ) - goto abort_cmd; -switch (s->feature) { -case 0x02 :/* Inquiry Metadata Storage */ -ide_cfata_metadata_inquiry (s); -break ; -case 0x03 :/* Read Metadata Storage */ -ide_cfata_metadata_read (s); -break ; -case 0x04 :/* Write Metadata Storage */ -ide_cfata_metadata_write (s); -break ; -default : - goto abort_cmd; - } -ide_transfer_start (s, s->io_buffer,0x200 , ide_transfer_stop); - s->status =0x00 ;/* NOTE: READY is _not_ set */ -ide_set_irq (s->bus); -break ; -case IBM_SENSE_CONDITION : -if (s->drive_kind !=IDE_CFATA ) - goto abort_cmd; -switch (s->feature) { -case 0x01 :/* sense temperature in device */ - s->nsector =0x50 ;/* +20 C */ -break ; -default : - goto abort_cmd; - } - s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); +default : + goto abort_cmd; + } +ide_transfer_start (s, s->io_buffer,0x200 , ide_transfer_stop); + s->status =0x00 ;/* NOTE: READY is _not_ set */ +ide_set_irq (s->bus); +break ; +case IBM_SENSE_CONDITION : +if (s->drive_kind !=IDE_CFATA ) + goto abort_cmd; +switch (s->feature) { +case 0x01 :/* sense temperature in device */ + s->nsector =0x50 ;/* +20 C */ break ; +default : + goto abort_cmd; + } + s->status =READY_STAT |SEEK_STAT ; +ide_set_irq (s->bus); +break ;case WIN_SMART : -if (s->drive_kind ==IDE_CD ) +if (s->drive_kind ==IDE_CD ) goto abort_cmd; -if (s->hcyl !=0xc2 || s->lcyl !=0x4f ) +if (s->hcyl !=0xc2 || s->lcyl !=0x4f ) goto abort_cmd; -if (!s->smart_enabled && s->feature !=SMART_ENABLE ) +if (!s->smart_enabled && s->feature !=SMART_ENABLE ) goto abort_cmd; -switch (s->feature) { -case SMART_DISABLE : +switch (s->feature) { +case SMART_DISABLE : s->smart_enabled =0 ; s->status =READY_STAT |SEEK_STAT ;ide_set_irq (s->bus);break ; -case SMART_ENABLE : +case SMART_ENABLE : s->smart_enabled =1 ; s->status =READY_STAT |SEEK_STAT ;ide_set_irq (s->bus);break ; -case SMART_ATTR_AUTOSAVE : +case SMART_ATTR_AUTOSAVE :switch (s->sector) {case 0x00 : - s->smart_autosave =0 ; -break ; + s->smart_autosave =0 ; +break ;case 0xf1 : - s->smart_autosave =1 ; -break ; + s->smart_autosave =1 ; +break ;default : - goto abort_cmd; + goto abort_cmd; } s->status =READY_STAT |SEEK_STAT ;ide_set_irq (s->bus);break ; -case SMART_STATUS : +case SMART_STATUS :if (!s->smart_errors) { - s->hcyl =0xc2 ; - s->lcyl =0x4f ; + s->hcyl =0xc2 ; + s->lcyl =0x4f ; }else { - s->hcyl =0x2c ; - s->lcyl =0xf4 ; + s->hcyl =0x2c ; + s->lcyl =0xf4 ; } s->status =READY_STAT |SEEK_STAT ;ide_set_irq (s->bus);break ; -case SMART_READ_THRESH : +case SMART_READ_THRESH :memset (s->io_buffer,0 ,0x200 ); s->io_buffer[0 ] =0x01 ;/* smart struct version */ for (n=0 ; n<30 ; n++) { -if (smart_attributes[n][0 ] ==0 ) +if (smart_attributes[n][0 ] ==0 )break ; - s->io_buffer[2 +0 +(n*12 )] = smart_attributes[n][0 ]; - s->io_buffer[2 +1 +(n*12 )] = smart_attributes[n][4 ]; + s->io_buffer[2 +0 +(n*12 )] = smart_attributes[n][0 ]; + s->io_buffer[2 +1 +(n*12 )] = smart_attributes[n][4 ]; }for (n=0 ; n<511 ; n++)/* checksum */ - s->io_buffer[511 ] += s->io_buffer[n]; + s->io_buffer[511 ] += s->io_buffer[n]; s->io_buffer[511 ] =0x100 - s->io_buffer[511 ]; s->status =READY_STAT |SEEK_STAT ;ide_transfer_start (s, s->io_buffer,0x200 , ide_transfer_stop);ide_set_irq (s->bus);break ; -case SMART_READ_DATA : +case SMART_READ_DATA :memset (s->io_buffer,0 ,0x200 ); s->io_buffer[0 ] =0x01 ;/* smart struct version */ for (n=0 ; n<30 ; n++) { -if (smart_attributes[n][0 ] ==0 ) +if (smart_attributes[n][0 ] ==0 )break ; - s->io_buffer[2 +0 +(n*12 )] = smart_attributes[n][0 ]; - s->io_buffer[2 +1 +(n*12 )] = smart_attributes[n][1 ]; - s->io_buffer[2 +3 +(n*12 )] = smart_attributes[n][2 ]; - s->io_buffer[2 +4 +(n*12 )] = smart_attributes[n][3 ]; + s->io_buffer[2 +0 +(n*12 )] = smart_attributes[n][0 ]; + s->io_buffer[2 +1 +(n*12 )] = smart_attributes[n][1 ]; + s->io_buffer[2 +3 +(n*12 )] = smart_attributes[n][2 ]; + s->io_buffer[2 +4 +(n*12 )] = smart_attributes[n][3 ]; } s->io_buffer[362 ] =0x02 | (s->smart_autosave?0x80 :0x00 );if (s->smart_selftest_count ==0 ) { - s->io_buffer[363 ] =0 ; + s->io_buffer[363 ] =0 ; }else { - s->io_buffer[363 ] = + s->io_buffer[363 ] = s->smart_selftest_data[3 + - (s->smart_selftest_count -1 ) * -24 ]; + (s->smart_selftest_count -1 ) * +24 ]; } s->io_buffer[364 ] =0x20 ; s->io_buffer[365 ] =0x01 ;
@@ -2293,76 +2293,76 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val) s->io_buffer[374 ] =0x01 ;/* minutes for poll conveyance */ for (n=0 ; n<511 ; n++) - s->io_buffer[511 ] += s->io_buffer[n]; + s->io_buffer[511 ] += s->io_buffer[n]; s->io_buffer[511 ] =0x100 - s->io_buffer[511 ]; s->status =READY_STAT |SEEK_STAT ;ide_transfer_start (s, s->io_buffer,0x200 , ide_transfer_stop);ide_set_irq (s->bus);break ; -case SMART_READ_LOG : +case SMART_READ_LOG :switch (s->sector) {case 0x01 :/* summary smart error log */ -memset (s->io_buffer,0 ,0x200 ); - s->io_buffer[0 ] =0x01 ; - s->io_buffer[1 ] =0x00 ;/* no error entries */ - s->io_buffer[452 ] = s->smart_errors &0xff ; - s->io_buffer[453 ] = (s->smart_errors &0xff00 ) >>8 ; +memset (s->io_buffer,0 ,0x200 ); + s->io_buffer[0 ] =0x01 ; + s->io_buffer[1 ] =0x00 ;/* no error entries */ + s->io_buffer[452 ] = s->smart_errors &0xff ; + s->io_buffer[453 ] = (s->smart_errors &0xff00 ) >>8 ; -for (n=0 ; n<511 ; n++) +for (n=0 ; n<511 ; n++) s->io_buffer[511 ] += s->io_buffer[n]; - s->io_buffer[511 ] =0x100 - s->io_buffer[511 ]; -break ; + s->io_buffer[511 ] =0x100 - s->io_buffer[511 ]; +break ;case 0x06 :/* smart self test log */ -memset (s->io_buffer,0 ,0x200 ); - s->io_buffer[0 ] =0x01 ; -if (s->smart_selftest_count ==0 ) { +memset (s->io_buffer,0 ,0x200 ); + s->io_buffer[0 ] =0x01 ; +if (s->smart_selftest_count ==0 ) { s->io_buffer[508 ] =0 ; - }else { + }else { s->io_buffer[508 ] = s->smart_selftest_count;for (n=2 ; n<506 ; n++) - s->io_buffer[n] = s->smart_selftest_data[n]; - } -for (n=0 ; n<511 ; n++) + s->io_buffer[n] = s->smart_selftest_data[n]; + } +for (n=0 ; n<511 ; n++) s->io_buffer[511 ] += s->io_buffer[n]; - s->io_buffer[511 ] =0x100 - s->io_buffer[511 ]; -break ; + s->io_buffer[511 ] =0x100 - s->io_buffer[511 ]; +break ;default : - goto abort_cmd; + goto abort_cmd; } s->status =READY_STAT |SEEK_STAT ;ide_transfer_start (s, s->io_buffer,0x200 , ide_transfer_stop);ide_set_irq (s->bus);break ; -case SMART_EXECUTE_OFFLINE : +case SMART_EXECUTE_OFFLINE :switch (s->sector) {case 0 :/* off-line routine */ case 1 :/* short self test */ case 2 :/* extended self test */ - s->smart_selftest_count++; -if (s->smart_selftest_count >21 ) + s->smart_selftest_count++; +if (s->smart_selftest_count >21 ) s->smart_selftest_count =0 ; - n =2 + (s->smart_selftest_count -1 ) *24 ; - s->smart_selftest_data[n] = s->sector; - s->smart_selftest_data[n+1 ] =0x00 ;/* OK and finished */ - s->smart_selftest_data[n+2 ] =0x34 ;/* hour count lsb */ - s->smart_selftest_data[n+3 ] =0x12 ;/* hour count msb */ - s->status =READY_STAT |SEEK_STAT ; -ide_set_irq (s->bus); -break ; + n =2 + (s->smart_selftest_count -1 ) *24 ; + s->smart_selftest_data[n] = s->sector; + s->smart_selftest_data[n+1 ] =0x00 ;/* OK and finished */ + s->smart_selftest_data[n+2 ] =0x34 ;/* hour count lsb */ + s->smart_selftest_data[n+3 ] =0x12 ;/* hour count msb */ + s->status =READY_STAT |SEEK_STAT ; +ide_set_irq (s->bus); +break ;default : - goto abort_cmd; + goto abort_cmd; }break ; -default : +default : goto abort_cmd; - } -break ; -default : - abort_cmd: -ide_abort_command (s); -ide_set_irq (s->bus); -break ; - } + } +break ; +default : + abort_cmd: +ide_abort_command (s); +ide_set_irq (s->bus); +break ; + } }uint32_t ide_ioport_read (void *opaque,uint32_t addr1)
Signature · 1 line
1.6.0.2
PATCH 3/12 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)
--- 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_fn (s,buf,size,end_transfer_func); +} + +static void pata_transfer_start (IDEState *s,uint8_t *buf,int size, +EndTransferFunc *end_transfer_func) +{ s->end_transfer_func = end_transfer_func; s->data_ptr = buf; s->data_end = buf + size;
@@ -2580,6 +2588,18 @@ static void ide_dummy_transfer_stop(IDEState *s) s->io_buffer[3 ] =0xff ; } +static void pata_set_irq (IDEBus *bus) +{ +BMDMAState *bm = bus->bmdma; + +if (!(bus->cmd &IDE_CMD_DISABLE_IRQ )) { +if (bm) { + bm->status |=BM_STATUS_INT ; + } +qemu_irq_raise (bus->irq); + } +} +static void ide_reset (IDEState *s) {#ifdef DEBUG_IDE
@@ -2716,6 +2736,12 @@ static void ide_init1(IDEBus *bus, int unit) ide_sector_write_timer_cb, s); } +static IDEBusOps ide_bus_ops = { + .transfer_start_fn = pata_transfer_start, + .irq_set_fn = pata_set_irq, + .dma_start_fn = pata_dma_start, +}; +void ide_init2 (IDEBus *bus,qemu_irq irq) {int i;
@@ -2725,6 +2751,7 @@ void ide_init2(IDEBus *bus, qemu_irq irq)ide_reset (&bus->ifs[i]); } bus->irq = irq; + bus->ops = &ide_bus_ops; }/* TODO convert users to qdev and remove */
@@ -2748,6 +2775,7 @@ void ide_init2_with_non_qdev_drives(IDEBus *bus, DriveInfo *hd0, } } bus->irq = irq; + bus->ops = &ide_bus_ops; }void ide_init_ioport (IDEBus *bus,int iobase,int iobase2)
@@ -2919,9 +2947,10 @@ const VMStateDescription vmstate_ide_bus = {/***********************************************************/ /* PCI IDE definitions */ -static void ide_dma_start (IDEState *s,BlockDriverCompletionFunc *dma_cb) +static void pata_dma_start (IDEState *s,BlockDriverCompletionFunc *dma_cb) {BMDMAState *bm = s->bus->bmdma; +if (!bm)return ; bm->unit = s->unit;
@@ -2936,6 +2965,11 @@ static void ide_dma_start(IDEState *s, BlockDriverCompletionFunc *dma_cb) } } +static void ide_dma_start (IDEState *s,BlockDriverCompletionFunc *dma_cb) +{ + s->bus->ops->dma_start_fn (s,dma_cb); +} +static void ide_dma_restart (IDEState *s,int is_read) {BMDMAState *bm = s->bus->bmdma;
hw/ide/internal.h +19 -7
@@ -20,6 +20,7 @@ typedef struct IDEDevice IDEDevice;typedef struct IDEDeviceInfo IDEDeviceInfo ;typedef struct IDEState IDEState ;typedef struct BMDMAState BMDMAState ; +typedef struct IDEBusOps IDEBusOps ;/* Bits of HD_STATUS */ #define ERR_STAT 0x01
@@ -366,6 +367,14 @@ typedef enum { IDE_HD, IDE_CD, IDE_CFATA } IDEDriveKind;typedef void EndTransferFunc (IDEState *); + +typedef void TransferStartFunc (IDEState *, +uint8_t *, +int , +EndTransferFunc *); +typedef void IRQSetFunc (IDEBus *); +typedef void DMAStartFunc (IDEState *,BlockDriverCompletionFunc *); +/* NOTE: IDEState represents in fact one drive */ struct IDEState {IDEBus *bus;
@@ -442,12 +451,21 @@ struct IDEState {uint8_t *smart_selftest_data; }; +/* This struct represents a device that uses an IDE bus, but requires +* modifications to how it works. An example is AHCI. */ +struct IDEBusOps { +TransferStartFunc *transfer_start_fn; +IRQSetFunc *irq_set_fn; +DMAStartFunc *dma_start_fn; +}; +struct IDEBus {BusState qbus;IDEDevice *master;IDEDevice *slave;BMDMAState *bmdma;IDEState ifs[2 ]; +IDEBusOps *ops;uint8_t unit;uint8_t cmd;qemu_irq irq;
@@ -512,13 +530,7 @@ static inline IDEState *bmdma_active_if(BMDMAState *bmdma)static inline void ide_set_irq (IDEBus *bus) { -BMDMAState *bm = bus->bmdma; -if (!(bus->cmd &IDE_CMD_DISABLE_IRQ )) { -if (bm) { - bm->status |=BM_STATUS_INT ; - } -qemu_irq_raise (bus->irq); - } + bus->ops->irq_set_fn (bus); }/* hw/ide/core.c */
Signature · 1 line
1.6.0.2
PATCH 4/12 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)
--- hw/ide/core.c | 9 ++++++--- hw/ide/internal.h | 4 ++++ 2 files changed, 10 insertions(+), 3 deletions(-)
hw/ide/core.c +6 -3
@@ -607,7 +607,7 @@ static void ide_read_dma_cb(void *opaque, int ret) n = s->nsector; s->io_buffer_index =0 ; s->io_buffer_size = n *512 ; -if (dma_buf_prepare (bm,1 ) ==0 ) +if (s->bus->ops->dma_prepare_fn (bm,1 ) ==0 ) goto eot;#ifdef DEBUG_AIO printf ("aio_read: sector_num=%" PRId64" n=%d\n" , sector_num, n);
@@ -752,7 +752,7 @@ static void ide_write_dma_cb(void *opaque, int ret) n = s->nsector; s->io_buffer_size = n *512 ;/* launch next transfer */ -if (dma_buf_prepare (bm,0 ) ==0 ) +if (s->bus->ops->dma_prepare_fn (bm,0 ) ==0 ) goto eot;#ifdef DEBUG_AIO printf ("aio_write: sector_num=%" PRId64" n=%d\n" , sector_num, n);
@@ -1060,7 +1060,7 @@ static void ide_atapi_cmd_read_dma_cb(void *opaque, int ret) s->lba += n; } s->packet_transfer_size -= s->io_buffer_size; -if (dma_buf_rw (bm,1 ) ==0 ) +if (s->bus->ops->dma_rw_fn (bm,1 ) ==0 ) goto eot; }
@@ -2715,6 +2715,7 @@ int ide_init_drive(IDEState *s, BlockDriverState *bs, }else {pstrcpy (s->version,sizeof (s->version),QEMU_VERSION ); } +ide_reset (s);bdrv_set_removable (bs, s->drive_kind ==IDE_CD );return 0 ;
@@ -2740,6 +2741,8 @@ static IDEBusOps ide_bus_ops = { .transfer_start_fn = pata_transfer_start, .irq_set_fn = pata_set_irq, .dma_start_fn = pata_dma_start, + .dma_prepare_fn = dma_buf_prepare, + .dma_rw_fn = dma_buf_rw, };void ide_init2 (IDEBus *bus,qemu_irq irq)
hw/ide/internal.h +4 -0
@@ -374,6 +374,8 @@ typedef void TransferStartFunc(IDEState *, EndTransferFunc *);typedef void IRQSetFunc (IDEBus *);typedef void DMAStartFunc (IDEState *,BlockDriverCompletionFunc *); +typedef int DMAPrepareFunc (BMDMAState *,int ); +typedef int DMARWFunc (BMDMAState *,int );/* NOTE: IDEState represents in fact one drive */ struct IDEState {
@@ -457,6 +459,8 @@ struct IDEBusOps {TransferStartFunc *transfer_start_fn;IRQSetFunc *irq_set_fn;DMAStartFunc *dma_start_fn; +DMAPrepareFunc *dma_prepare_fn; +DMARWFunc *dma_rw_fn; };struct IDEBus {
Signature · 1 line
1.6.0.2
PATCH 5/12 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
@@ -451,6 +451,8 @@ struct IDEState {int smart_errors;uint8_t smart_selftest_count;uint8_t *smart_selftest_data; +/* AHCI */ +int ncq_queues; };/* This struct represents a device that uses an IDE bus, but requires
Signature · 1 line
1.6.0.2
PATCH 6/12 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/12 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-7M AHCI adapter.
---
v3 -> v4:
- add ICH7 instead of ICH7M (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 0x27c3/* 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/12 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)
--- Makefile.objs | 1 + default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 + hw/ide/ahci.c | 1397 ++++++++++++++++++++++++++++++++++++ 4 files changed, 1400 insertions(+), 0 deletions(-) create mode 100644 hw/ide/ahci.c
Makefile.objs +1 -0
@@ -229,6 +229,7 @@ hw-obj-$(CONFIG_IDE_PIIX) += ide/piix.o hw-obj-$(CONFIG_IDE_CMD646) += ide/cmd646.o hw-obj-$(CONFIG_IDE_MACIO) += ide/macio.o hw-obj-$(CONFIG_IDE_VIA) += ide/via.o +hw-obj-$(CONFIG_AHCI) += ide/ahci.o # SCSI layer hw-obj-y += lsi53c895a.o
default-configs/i386-softmmu.mak +1 -0
@@ -19,6 +19,7 @@ CONFIG_IDE_QDEV=y CONFIG_IDE_PCI=y CONFIG_IDE_ISA=y CONFIG_IDE_PIIX=y +CONFIG_AHCI=y CONFIG_NE2000_ISA=y CONFIG_PIIX_PCI=y CONFIG_SOUND=y
default-configs/x86_64-softmmu.mak +1 -0
@@ -19,6 +19,7 @@ CONFIG_IDE_QDEV=y CONFIG_IDE_PCI=y CONFIG_IDE_ISA=y CONFIG_IDE_PIIX=y +CONFIG_AHCI=y CONFIG_NE2000_ISA=y CONFIG_PIIX_PCI=y CONFIG_SOUND=y
hw/ide/ahci.c new file +1397 -0
1,397 lines not on this page · raw message
Signature · 1 line
1.6.0.2
Re: [Qemu-devel] [PATCH 08/12] ahci: add ahci emulation
Quoted 3 lines
Makefile.objs | 1 + default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 +
Why are you only enabling this on x86? PCI devices, especially things like SATA controllers, should be completely target independent.
Paul
Re: [Qemu-devel] [PATCH 08/12] ahci: add ahci emulation
Quoted 7 lines · Paul Brook
Quoted 3 lines
Makefile.objs | 1 + default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 +Why are you only enabling this on x86? PCI devices, especially things like SATA controllers, should be completely target independent.
Because without the mmio series it breaks on big endian devices and we have to start somewhere :).
Alex
Re: [Qemu-devel] [PATCH 08/12] ahci: add ahci emulation
Quoted 10 lines · Paul Brook
Quoted 6 lines
Quoted 3 lines
Makefile.objs | 1 + default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 +Why are you only enabling this on x86? PCI devices, especially things like SATA controllers, should be completely target independent.
Because without the mmio series it breaks on big endian devices and we have to start somewhere :).
less than half of the targets are big-endian. If it's broken on big-endian there should be a comment somewhere documenting this, so we know to fix it.
Paul
Re: [Qemu-devel] [PATCH 08/12] ahci: add ahci emulation
Quoted 5 lines · Paul Brook
Quoted 5 lines · Paul Brook
Quoted 4 lines
Quoted 3 lines
Makefile.objs | 1 + default-configs/i386-softmmu.mak | 1 + default-configs/x86_64-softmmu.mak | 1 +
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
Why are you only enabling this on x86? PCI devices, especially things like SATA controllers, should be completely target independent.
Because without the mmio series it breaks on big endian devices and we have to start somewhere :).
less than half of the targets are big-endian. If it's broken on big-endian there should be a comment somewhere documenting this, so we know to fix it.
Well, it's stated in the cover letter and the same is true for almost every PCI device in qemu we have today.
So what would you prefer? Add the device in every default config? Have a pci combination .mak that we can include on all pci capable machines so we don't end up patching 50 files for every device?
Alex
Re: [Qemu-devel] [PATCH 08/12] ahci: add ahci emulation
Quoted 9 lines
Quoted 3 lines
less than half of the targets are big-endian. If it's broken on big-endian there should be a comment somewhere documenting this, so we know to fix it.
Well, it's stated in the cover letter and the same is true for almost every PCI device in qemu we have today. So what would you prefer? Add the device in every default config? Have a pci combination .mak that we can include on all pci capable machines so we don't end up patching 50 files for every device?
Yes, something like that.
Paul
PATCH 9/12 ahci: add -drive support
In reply to Alexander GrafWe need to be able to spawn new AHCI drives, so let's add AHCI support to the -drive option.
--- blockdev.c | 6 +++++- blockdev.h | 1 + qemu-common.h | 2 +- 3 files changed, 7 insertions(+), 2 deletions(-)
blockdev.c +5 -1
@@ -209,6 +209,9 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) }else if (!strcmp (buf,"xen" )) { type =IF_XEN ; max_devs =0 ; + }else if (!strcmp (buf,"sata" )) { + type =IF_SATA ; + max_devs =MAX_SATA_DEVS ; }else if (!strcmp (buf,"none" )) { type =IF_NONE ; max_devs =0 ;
@@ -402,7 +405,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error) }else {/* no id supplied -> create one */ dinfo->id =qemu_mallocz (32 ); -if (type ==IF_IDE || type ==IF_SCSI ) +if (type ==IF_IDE || type ==IF_SCSI || type ==IF_SATA ) mediastr = (media ==MEDIA_CDROM ) ?"-cd" :"-hd" ;if (max_devs) snprintf(dinfo->id, 32, "%s%i%s%i",
@@ -427,6 +430,7 @@ DriveInfo *drive_init(QemuOpts *opts, int default_to_scsi, int *fatal_error)case IF_IDE :case IF_SCSI :case IF_XEN : +case IF_SATA :case IF_NONE :switch (media) {case MEDIA_DISK :
blockdev.h +1 -0
@@ -33,6 +33,7 @@ struct DriveInfo {#define MAX_IDE_DEVS 2#define MAX_SCSI_DEVS 7 +#define MAX_SATA_DEVS 4DriveInfo *drive_get (BlockInterfaceType type,int bus,int unit);int drive_get_max_bus (BlockInterfaceType type);
qemu-common.h +1 -1
@@ -257,7 +257,7 @@ typedef uint64_t pcibus_t;typedef enum {IF_NONE ,IF_IDE ,IF_SCSI ,IF_FLOPPY ,IF_PFLASH ,IF_MTD ,IF_SD ,IF_VIRTIO ,IF_XEN , -IF_COUNT +IF_SATA ,IF_COUNT }BlockInterfaceType ;void cpu_exec_init_all (unsigned long tb_size);
Signature · 1 line
1.6.0.2
PATCH 10/12 config: Add header file for device config options
In reply to Alexander GrafSo far we have C preprocessor defines for target and host config options, but we're lacking any information on which devices are available.
We do need that information at times though, for example in the ahci patch where we need to call a legacy init function depending on whether we have support compiled in or not.
So this patch makes all config-devices options available as header file. Please only include it in machine description code!
---
v3 -> v4:
- config: only include config-devices.h in machine description (blue swirl)
--- Makefile.target | 5 ++++- hw/pc_piix.c | 1 + 2 files changed, 5 insertions(+), 1 deletions(-)
Makefile.target +4 -1
@@ -1,6 +1,6 @@ # -*- Mode: makefile -*- -GENERATED_HEADERS = config-target.h +GENERATED_HEADERS = config-target.h config-devices.h CONFIG_NO_KVM = $(if $(subst n,,$(CONFIG_KVM)),n,y) include ../config-host.mak
@@ -40,6 +40,9 @@ kvm.o kvm-all.o vhost.o vhost_net.o: QEMU_CFLAGS+=$(KVM_CFLAGS) config-target.h: config-target.h-timestamp config-target.h-timestamp: config-target.mak +config-devices.h: config-target.h-timestamp +config-devices.h-timestamp: config-target.mak + all: $(PROGS) # Dummy command so that make thinks it has done something
hw/pc_piix.c +1 -0
@@ -35,6 +35,7 @@#include "sysemu.h" #include "sysbus.h" #include "blockdev.h" +#include "config-devices.h" #define MAX_IDE_BUS 2
Signature · 1 line
1.6.0.2
Re: [Qemu-devel] [PATCH 10/12] config: Add header file for device config options
Quoted 10 lines · Alexander Graf
So far we have C preprocessor defines for target and host config options, but we're lacking any information on which devices are available.
We do need that information at times though, for example in the ahci patch where we need to call a legacy init function depending on whether we have support compiled in or not.
So this patch makes all config-devices options available as header file. Please only include it in machine description code!
How about including config-devices.h from hw/boards.h instead? On the downside, all targets will be recompiled when config-devices.h change, even if they don't have any device dependencies.
Re: [Qemu-devel] [PATCH 10/12] config: Add header file for device config options
Quoted 9 lines · Blue Swirl
Quoted 8 lines · Alexander Graf
So far we have C preprocessor defines for target and host config options, but we're lacking any information on which devices are available.
We do need that information at times though, for example in the ahci patch where we need to call a legacy init function depending on whether we have support compiled in or not.
Quoted 6 lines
Quoted 2 lines
So this patch makes all config-devices options available as header file. Please only include it in machine description code!
How about including
config-devices.hfromhw/boards.hinstead? On the downside, all targets will be recompiled whenconfig-devices.hchange, even if they don't have any device dependencies.
Not sure it makes sense to do this change this time around. If we can avoid dependency on device configuration, we should. So if we can limit the scope this is included in, it's good IMHO.
In fact, maybe the correct solution to the issue would be to move the legacy -drive instantiation to the -drive code, as it is already with virtio-blk. If used with -device and -drive ...,if=none the whole magic isn't necessary anyways.
Alex
[Qemu-devel] Re: [PATCH 10/12] config: Add header file for device config options
In reply to Alexander GrafQuoted 4 lines · Alexander Graf
So far we have C preprocessor defines for target and host config options, but we're lacking any information on which devices are available.
Quoted 8 lines
We do need that information at times though, for example in the ahci patch where we need to call a legacy init function depending on whether we have support compiled in or not.
So this patch makes all config-devices options available as header file. Please only include it in machine description code!
Signed-off-by Alexander Graf <[email protected]>
This already existed in the past, Paul Brook reverted it.
commit a992fe3d0fc185112677286f7a02204d8245b61e
Author: Paul Brook <[email protected]> Date: Sun Nov 22 16:25:30 2009 +0000
Makefile dependencies for device configs
I did the 1st implementation, and I tried to get it back several times. Paul Brook reasoning is that "if you need it, our device model is wrong.
If you show that you want to be able to compile out several devices, ...
Paul Brook: "if you need it, our device model is wrong"
If you don't want to have the abomination of xen-stub.c kvm-stub.c, etc....
Paul Brook: "if you need it, our device model is wrong".
Last time I tried to get it back was to be able to compile out hpet (it didn't worked well at the time).
I let you guess how it ended.
Later, Juan.
[Qemu-devel] Re: [PATCH 10/12] config: Add header file for device config options
Quoted 32 lines · Juan Quintela
Quoted 4 lines · Alexander Graf
So far we have C preprocessor defines for target and host config options, but we're lacking any information on which devices are available.
Quoted 8 lines
We do need that information at times though, for example in the ahci patch where we need to call a legacy init function depending on whether we have support compiled in or not.
So this patch makes all config-devices options available as header file. Please only include it in machine description code!
Signed-off-by Alexander Graf <[email protected]>This already existed in the past, Paul Brook reverted it.
commit
a992fe3d0fc185112677286f7a02204d8245b61eAuthor: Paul Brook <[email protected]> Date: Sun Nov 22 16:25:30 2009 +0000
Makefiledependencies for device configsI did the 1st implementation, and I tried to get it back several times. Paul Brook reasoning is that "if you need it, our device model is wrong.
If you show that you want to be able to compile out several devices, ...
Paul Brook: "if you need it, our device model is wrong"
If you don't want to have the abomination of
xen-stub.ckvm-stub.c, etc....
Quoted 6 lines
Paul Brook: "if you need it, our device model is wrong".
Last time I tried to get it back was to be able to compile out hpet (it didn't worked well at the time).
I let you guess how it ended.
Sure, I only want to keep it in as a temporary solution in cases where overhauling the device model needs a lot of thorough thought and considerations.
As I stated for this particular issue, maybe the way forward is to move all the initialization code over to -drive instead of keeping it close to the device. But I'm not sure yet. Hence this very little intrusive patch.
Alex
Re: [Qemu-devel] Re: [PATCH 10/12] config: Add header file for device config options
Quoted 37 lines · Alexander Graf
Quoted 34 lines · Juan Quintela
Quoted 4 lines · Alexander Graf
So far we have C preprocessor defines for target and host config options, but we're lacking any information on which devices are available.
Quoted 8 lines
We do need that information at times though, for example in the ahci patch where we need to call a legacy init function depending on whether we have support compiled in or not.
So this patch makes all config-devices options available as header file. Please only include it in machine description code!
Signed-off-by Alexander Graf <[email protected]>This already existed in the past, Paul Brook reverted it.
commit
a992fe3d0fc185112677286f7a02204d8245b61e
Author: Paul Brook <[email protected]>
Date: Sun Nov 22 16:25:30 2009 +0000Makefile dependencies for device configs
I did the 1st implementation, and I tried to get it back several times. Paul Brook reasoning is that "if you need it, our device model is wrong.
If you show that you want to be able to compile out several devices, ...
Paul Brook: "if you need it, our device model is wrong"
If you don't want to have the abomination of
xen-stub.ckvm-stub.c, etc....Paul Brook: "if you need it, our device model is wrong".
Quoted 8 lines
Quoted 4 lines
Last time I tried to get it back was to be able to compile out hpet (it didn't worked well at the time).
I let you guess how it ended.
Sure, I only want to keep it in as a temporary solution in cases where overhauling the device model needs a lot of thorough thought and considerations.
As I stated for this particular issue, maybe the way forward is to move all the initialization code over to -drive instead of keeping it close to the device. But I'm not sure yet. Hence this very little intrusive patch.
I read the config-devices.h thread and I agree that it's a bad idea. So, I'm also NACKing this patch. Please adjust the code so that CONFIG_AHCI is no longer needed.
PATCH 11/12 ahci: spawn controller on demand
In reply to Alexander GrafWhen we add a device using -drive to the guest, we also need to create a new SATA bus to handle the device. This patch adds a function call that every machine that likes to have IF_SATA support can call to get full device creation by keeping the actual qdev code clean.
---
v2 -> v3:
- redesign
--- hw/pc.h | 1 + hw/pc_piix.c | 3 +++ 2 files changed, 4 insertions(+), 0 deletions(-)
hw/pc.h +1 -0
@@ -108,6 +108,7 @@ void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size, BusState *ide0, BusState *ide1, FDCtrl *floppy_controller, ISADevice *s);void pc_pci_device_init (PCIBus *pci_bus); +void ahci_create_default_devs (void *pci_bus);typedef void (*cpu_set_smm_t )(int smm,void *arg);void cpu_smm_register (cpu_set_smm_t callback,void *arg);
hw/pc_piix.c +3 -0
@@ -183,6 +183,9 @@ static void pc_init1(ram_addr_t ram_size,if (pci_enabled) {pc_pci_device_init (pci_bus); +#ifdef CONFIG_AHCI +ahci_create_default_devs (pci_bus); +#endif } }
Signature · 1 line
1.6.0.2
PATCH 12/12 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.
--- 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
@@ -221,7 +221,7 @@ hw-obj-$(CONFIG_LAN9118) += lan9118.o hw-obj-$(CONFIG_NE2000_ISA) += ne2000-isa.o # IDE -hw-obj-$(CONFIG_IDE_CORE) += ide/core.o +hw-obj-$(CONFIG_IDE_CORE) += ide/core.o ide/pata.o hw-obj-$(CONFIG_IDE_QDEV) += ide/qdev.o hw-obj-$(CONFIG_IDE_PCI) += ide/pci.o hw-obj-$(CONFIG_IDE_ISA) += ide/isa.o
hw/ide/core.c +2 -142
204 lines not on this page · raw message
hw/ide/internal.h +3 -0
@@ -588,4 +588,7 @@ void ide_exec_cmd(IDEBus *bus, uint32_t val);void ide_bus_new (IDEBus *idebus,DeviceState *dev);IDEDevice *ide_create_drive (IDEBus *bus,int unit,DriveInfo *drive); +/* hw/ide/pata.c */ +void pata_init (IDEBus *bus); +#endif /* HW_IDE_INTERNAL_H */
hw/ide/pata.c new file +178 -0
178 lines not on this page · raw message
Signature · 1 line
1.6.0.2
Quoted 2 lines · Alexander Graf
This patch adds support for AHCI emulation. I have tested and verified it works in Linux, OpenBSD, Windows Vista and Windows 7.
Also seabios ;)
http://cgit.freedesktop.org/~kraxel/seabios/log/?h=ahci
cheers,
Gerd
Quoted 6 lines · Gerd Hoffmann
Quoted 2 lines · Alexander Graf
This patch adds support for AHCI emulation. I have tested and verified it works in Linux, OpenBSD, Windows Vista and Windows 7.
Also seabios ;)
http://cgit.freedesktop.org/~kraxel/seabios/log/?h=ahci
Omg! You're incredible :)
Alex
Quoted 6 lines · Gerd Hoffmann
Quoted 2 lines · Alexander Graf
This patch adds support for AHCI emulation. I have tested and verified it works in Linux, OpenBSD, Windows Vista and Windows 7.
Also seabios ;)
http://cgit.freedesktop.org/~kraxel/seabios/log/?h=ahci
I broke that one with v7 of the ahci patchset apparently. Sorry about that :). Since Linux and Windows still happily boot, it's probably something missing on your side :(.
Alex
Quoted 11 lines · Alexander Graf
Quoted 6 lines · Gerd Hoffmann
Quoted 2 lines · Alexander Graf
This patch adds support for AHCI emulation. I have tested and verified it works in Linux, OpenBSD, Windows Vista and Windows 7.
Also seabios ;)
http://cgit.freedesktop.org/~kraxel/seabios/log/?h=ahciI broke that one with v7 of the ahci patchset apparently. Sorry about that :). Since Linux and Windows still happily boot, it's probably something missing on your side :(.
No. DMA is broken (probably non-ncq only).
Commit c29947bbb0978d312074ec73be968bfab1b6c977 broke your way of kicking dma.
/me papered over it with the attached patch. The RightWay[tm] to fix it is probably to put a "bmdma_cmd_writeb(bm, 0, 0)" to the approximate place. Or refactor ide dma in a way that you don't need to kick it in such a hackish way in the first place.
cheers,
Gerd
hw/ide/ahci.c +1 -0
@@ -1164,6 +1164,7 @@ static void ahci_dma_start(IDEState *s, BlockDriverCompletionFunc *dma_cb) bm->cur_addr =0 ; bm->sector_num =ide_get_sector (s); bm->nsector = s->nsector; + bm->cmd =0 ;bmdma_cmd_writeb (bm,0 ,1 ); }
Quoted 11 lines · Gerd Hoffmann
Quoted 10 lines · Alexander Graf
Quoted 6 lines · Gerd Hoffmann
Quoted 2 lines · Alexander Graf
This patch adds support for AHCI emulation. I have tested and verified it works in Linux, OpenBSD, Windows Vista and Windows 7.
Also seabios ;)
http://cgit.freedesktop.org/~kraxel/seabios/log/?h=ahci
Quoted 7 lines
Quoted 1 line
I broke that one with v7 of the ahci patchset apparently. Sorry about that :). Since Linux and Windows still happily boot, it's probably something missing on your side :(.
No. DMA is broken (probably non-ncq only).
Commit
c29947bbb0978d312074ec73be968bfab1b6c977broke your way of kicking dma./me papered over it with the attached patch. The RightWay[tm] to fix it is probably to put a "
bmdma_cmd_writeb(bm, 0, 0)" to the approximate place. Or refactor ide dma in a way that you don't need to kick it in such a hackish way in the first place.
Ugh. Thanks for digging through that. I agree, the way DMA is handled atm is very bogus and not pretty at all. Maybe we should try to refactor it so dbdma can be used as well? Not sure how all of that works yet though.
Alex