Use pci_bar_map() and post_map_func instead of a mapping function. Remove unused msix_mmio_map().
Signed-off-by: Blue Swirl <blauwir...@gmail.com> --- hw/msix.c | 21 +-------------------- hw/msix.h | 3 --- hw/virtio-pci.c | 47 +++++++++++++++++++++++++++++++---------------- 3 files changed, 32 insertions(+), 39 deletions(-) diff --git a/hw/msix.c b/hw/msix.c index d99403a..71ed728 100644 --- a/hw/msix.c +++ b/hw/msix.c @@ -201,25 +201,6 @@ static CPUReadMemoryFunc * const msix_mmio_read[] = { msix_mmio_read_unallowed, msix_mmio_read_unallowed, msix_mmio_readl }; -/* Should be called from device's map method. */ -void msix_mmio_map(PCIDevice *d, int region_num, - pcibus_t addr, pcibus_t size, int type) -{ - uint8_t *config = d->config + d->msix_cap; - uint32_t table = pci_get_long(config + MSIX_TABLE_OFFSET); - uint32_t offset = table & ~(MSIX_PAGE_SIZE - 1); - /* TODO: for assigned devices, we'll want to make it possible to map - * pending bits separately in case they are in a separate bar. */ - int table_bir = table & PCI_MSIX_FLAGS_BIRMASK; - - if (table_bir != region_num) - return; - if (size <= offset) - return; - cpu_register_physical_memory(addr + offset, size - offset, - d->msix_mmio_index); -} - static void msix_mask_all(struct PCIDevice *dev, unsigned nentries) { int vector; @@ -261,7 +242,7 @@ int msix_init(struct PCIDevice *dev, unsigned short nentries, goto err_config; dev->cap_present |= QEMU_PCI_CAP_MSIX; - return 0; + return dev->msix_mmio_index; err_config: dev->msix_entries_nr = 0; diff --git a/hw/msix.h b/hw/msix.h index a9f7993..93b0c26 100644 --- a/hw/msix.h +++ b/hw/msix.h @@ -10,9 +10,6 @@ int msix_init(PCIDevice *pdev, unsigned short nentries, void msix_write_config(PCIDevice *pci_dev, uint32_t address, uint32_t val, int len); -void msix_mmio_map(PCIDevice *pci_dev, int region_num, - pcibus_t addr, pcibus_t size, int type); - int msix_uninit(PCIDevice *d); void msix_save(PCIDevice *dev, QEMUFile *f); diff --git a/hw/virtio-pci.c b/hw/virtio-pci.c index 781d83c..7e33932 100644 --- a/hw/virtio-pci.c +++ b/hw/virtio-pci.c @@ -379,21 +379,25 @@ static void virtio_map(PCIDevice *pci_dev, int region_num, { VirtIOPCIProxy *proxy = container_of(pci_dev, VirtIOPCIProxy, pci_dev); VirtIODevice *vdev = proxy->vdev; - unsigned config_len = VIRTIO_PCI_REGION_SIZE(pci_dev) + vdev->config_len; proxy->addr = addr; - register_ioport_write(addr, config_len, 1, virtio_pci_config_writeb, proxy); - register_ioport_write(addr, config_len, 2, virtio_pci_config_writew, proxy); - register_ioport_write(addr, config_len, 4, virtio_pci_config_writel, proxy); - register_ioport_read(addr, config_len, 1, virtio_pci_config_readb, proxy); - register_ioport_read(addr, config_len, 2, virtio_pci_config_readw, proxy); - register_ioport_read(addr, config_len, 4, virtio_pci_config_readl, proxy); - if (vdev->config_len) vdev->get_config(vdev, vdev->config); } +static IOPortWriteFunc * const virtio_pci_config_io_writes[] = { + virtio_pci_config_writeb, + virtio_pci_config_writew, + virtio_pci_config_writel, +}; + +static IOPortReadFunc * const virtio_pci_config_io_reads[] = { + virtio_pci_config_readb, + virtio_pci_config_readw, + virtio_pci_config_readl, +}; + static void virtio_write_config(PCIDevice *pci_dev, uint32_t address, uint32_t val, int len) { @@ -495,6 +499,7 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev, { uint8_t *config; uint32_t size; + int io_index; proxy->vdev = vdev; @@ -514,13 +519,19 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev, config[0x3d] = 1; - if (vdev->nvectors && !msix_init(&proxy->pci_dev, vdev->nvectors, 1, 0)) { - pci_register_bar(&proxy->pci_dev, 1, - msix_bar_size(&proxy->pci_dev), - PCI_BASE_ADDRESS_SPACE_MEMORY, - msix_mmio_map, NULL); - } else - vdev->nvectors = 0; + if (vdev->nvectors) { + io_index = msix_init(&proxy->pci_dev, vdev->nvectors, 1, 0); + if (io_index < 0) { + vdev->nvectors = 0; + } else { + pci_register_bar(&proxy->pci_dev, 1, + msix_bar_size(&proxy->pci_dev), + PCI_BASE_ADDRESS_SPACE_MEMORY, + NULL, NULL); + pci_bar_map(&proxy->pci_dev, 1, 0, 0, + msix_bar_size(&proxy->pci_dev), io_index); + } + } proxy->pci_dev.config_write = virtio_write_config; @@ -529,7 +540,11 @@ static void virtio_init_pci(VirtIOPCIProxy *proxy, VirtIODevice *vdev, size = 1 << qemu_fls(size); pci_register_bar(&proxy->pci_dev, 0, size, PCI_BASE_ADDRESS_SPACE_IO, - virtio_map, NULL); + NULL, virtio_map); + io_index = cpu_register_io(virtio_pci_config_io_reads, + virtio_pci_config_io_writes, + size, &proxy->pci_dev); + pci_bar_map(&proxy->pci_dev, 0, 0, 0, size, io_index); virtio_bind_device(vdev, &virtio_pci_bindings, proxy); proxy->host_features |= 0x1 << VIRTIO_F_NOTIFY_ON_EMPTY; -- 1.6.2.4