diff options
author | Jean-Philippe Brucker <jean-philippe.brucker@arm.com> | 2022-06-07 18:02:31 +0100 |
---|---|---|
committer | Will Deacon <will@kernel.org> | 2022-06-09 13:44:15 +0100 |
commit | f44af23e3a62e46158341807b0d2d132249b96a8 (patch) | |
tree | cf3193c15d05eff8d9040db3081146b61c52145b | |
parent | 484278913807e4e3523eff1b9933c7e86a27b6d2 (diff) | |
download | kvmtool-f44af23e3a62e46158341807b0d2d132249b96a8.tar.gz |
virtio/pci: Factor MSI route creation
The code for creating an MSI route is already duplicated between config
and virtqueue MSI. Modern virtio will need it as well, so move it to a
separate function.
Signed-off-by: Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
Link: https://lore.kernel.org/r/20220607170239.120084-17-jean-philippe.brucker@arm.com
Signed-off-by: Will Deacon <will@kernel.org>
-rw-r--r-- | virtio/pci.c | 60 |
1 files changed, 27 insertions, 33 deletions
diff --git a/virtio/pci.c b/virtio/pci.c index 85018e79..1a549314 100644 --- a/virtio/pci.c +++ b/virtio/pci.c @@ -37,6 +37,29 @@ static u32 virtio_pci__msix_io_addr(struct virtio_pci *vpci) return pci__bar_address(&vpci->pci_hdr, 2); } +static int virtio_pci__add_msix_route(struct virtio_pci *vpci, u32 vec) +{ + int gsi; + struct msi_msg *msg; + + if (vec == VIRTIO_MSI_NO_VECTOR) + return -EINVAL; + + msg = &vpci->msix_table[vec].msg; + gsi = irq__add_msix_route(vpci->kvm, msg, vpci->dev_hdr.dev_num << 3); + /* + * We don't need IRQ routing if we can use + * MSI injection via the KVM_SIGNAL_MSI ioctl. + */ + if (gsi == -ENXIO && vpci->features & VIRTIO_PCI_F_SIGNAL_MSI) + return gsi; + + if (gsi < 0) + die("failed to configure MSIs"); + + return gsi; +} + static void virtio_pci__ioevent_callback(struct kvm *kvm, void *param) { struct virtio_pci_ioevent_param *ioeventfd = param; @@ -219,24 +242,10 @@ static bool virtio_pci__specific_data_out(struct kvm *kvm, struct virtio_device switch (offset) { case VIRTIO_MSI_CONFIG_VECTOR: vec = vpci->config_vector = ioport__read16(data); - if (vec == VIRTIO_MSI_NO_VECTOR) - break; - - gsi = irq__add_msix_route(kvm, - &vpci->msix_table[vec].msg, - vpci->dev_hdr.dev_num << 3); - /* - * We don't need IRQ routing if we can use - * MSI injection via the KVM_SIGNAL_MSI ioctl. - */ - if (gsi == -ENXIO && - vpci->features & VIRTIO_PCI_F_SIGNAL_MSI) - break; - if (gsi < 0) { - die("failed to configure MSIs"); + gsi = virtio_pci__add_msix_route(vpci, vec); + if (gsi < 0) break; - } vpci->config_gsi = gsi; break; @@ -244,24 +253,9 @@ static bool virtio_pci__specific_data_out(struct kvm *kvm, struct virtio_device vec = ioport__read16(data); vpci->vq_vector[vpci->queue_selector] = vec; - if (vec == VIRTIO_MSI_NO_VECTOR) - break; - - gsi = irq__add_msix_route(kvm, - &vpci->msix_table[vec].msg, - vpci->dev_hdr.dev_num << 3); - /* - * We don't need IRQ routing if we can use - * MSI injection via the KVM_SIGNAL_MSI ioctl. - */ - if (gsi == -ENXIO && - vpci->features & VIRTIO_PCI_F_SIGNAL_MSI) - break; - - if (gsi < 0) { - die("failed to configure MSIs"); + gsi = virtio_pci__add_msix_route(vpci, vec); + if (gsi < 0) break; - } vpci->gsis[vpci->queue_selector] = gsi; if (vdev->ops->notify_vq_gsi) |