The AHCI device can provide both PCI and SysBus AHCI device emulations. For this reason, it wasn't previously converted to use the pci_dma_*() helper functions. Now that we have universal DMA helper functions, this converts AHCI to use them.
The DMAContext is obtained from pci_dma_context() in the PCI case and set to NULL in the SysBus case (i.e. we assume for now that a SysBus AHCI has no IOMMU translation). Cc: Kevin Wolf <kw...@redhat.com> Cc: Michael S. Tsirkin <m...@redhat.com> Signed-off-by: David Gibson <da...@gibson.dropbear.id.au> --- hw/ide/ahci.c | 7 ++++--- hw/ide/ahci.h | 3 ++- hw/ide/ich.c | 2 +- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c index aa05a48..624da69 100644 --- a/hw/ide/ahci.c +++ b/hw/ide/ahci.c @@ -717,7 +717,7 @@ static int ahci_populate_sglist(AHCIDevice *ad, QEMUSGList *sglist) AHCI_SG *tbl = (AHCI_SG *)prdt; /* FIXME: pass the correct DMAContext */ - qemu_sglist_init(sglist, sglist_alloc_hint, NULL); + qemu_sglist_init(sglist, sglist_alloc_hint, ad->hba->dma); for (i = 0; i < sglist_alloc_hint; i++) { /* flags_size is zero-based */ qemu_sglist_add(sglist, le64_to_cpu(tbl[i].addr), @@ -1171,11 +1171,12 @@ static const IDEDMAOps ahci_dma_ops = { .reset = ahci_dma_reset, }; -void ahci_init(AHCIState *s, DeviceState *qdev, int ports) +void ahci_init(AHCIState *s, DeviceState *qdev, DMAContext *dma, int ports) { qemu_irq *irqs; int i; + s->dma = dma; s->ports = ports; s->dev = g_malloc0(sizeof(AHCIDevice) * ports); ahci_reg_init(s); @@ -1238,7 +1239,7 @@ static const VMStateDescription vmstate_sysbus_ahci = { static int sysbus_ahci_init(SysBusDevice *dev) { SysbusAHCIState *s = FROM_SYSBUS(SysbusAHCIState, dev); - ahci_init(&s->ahci, &dev->qdev, s->num_ports); + ahci_init(&s->ahci, &dev->qdev, NULL, s->num_ports); sysbus_init_mmio(dev, &s->ahci.mem); sysbus_init_irq(dev, &s->ahci.irq); diff --git a/hw/ide/ahci.h b/hw/ide/ahci.h index b223d2c..af8c6ef 100644 --- a/hw/ide/ahci.h +++ b/hw/ide/ahci.h @@ -299,6 +299,7 @@ typedef struct AHCIState { uint32_t idp_index; /* Current IDP index */ int ports; qemu_irq irq; + DMAContext *dma; } AHCIState; typedef struct AHCIPCIState { @@ -329,7 +330,7 @@ typedef struct NCQFrame { uint8_t reserved10; } QEMU_PACKED NCQFrame; -void ahci_init(AHCIState *s, DeviceState *qdev, int ports); +void ahci_init(AHCIState *s, DeviceState *qdev, DMAContext *dma, int ports); void ahci_uninit(AHCIState *s); void ahci_reset(void *opaque); diff --git a/hw/ide/ich.c b/hw/ide/ich.c index 560ae37..5354e13 100644 --- a/hw/ide/ich.c +++ b/hw/ide/ich.c @@ -91,7 +91,7 @@ static int pci_ich9_ahci_init(PCIDevice *dev) uint8_t *sata_cap; d = DO_UPCAST(struct AHCIPCIState, card, dev); - ahci_init(&d->ahci, &dev->qdev, 6); + ahci_init(&d->ahci, &dev->qdev, pci_dma_context(dev), 6); pci_config_set_prog_interface(d->card.config, AHCI_PROGMODE_MAJOR_REV_1); -- 1.7.9