diff options
author | Peter Maydell <peter.maydell@linaro.org> | 2019-06-14 09:33:55 +0100 |
---|---|---|
committer | Peter Maydell <peter.maydell@linaro.org> | 2019-06-14 09:33:55 +0100 |
commit | 5ec2eca83dc478ddf24077e02a8b34dd26cd3ff9 (patch) | |
tree | af310ae59f9d697ba784c8b745df4575d54ec8ef /hw/vfio/common.c | |
parent | d1bf88e56f46c75d472dc60c02bbbc7b474519f9 (diff) | |
parent | 201a733145751aa691e7e3b9c0f263f0c92db0c5 (diff) |
Merge remote-tracking branch 'remotes/awilliam/tags/vfio-updates-20190613.0' into staging
VFIO updates 2019-06-13
- Hide resizable BAR capability to prevent false guest resizing
(Alex Williamson)
- Allow relocation to fix bogus MSI-X hardware (Alex Williamson)
- Condense IRQ setup into a common helper (Eric Auger)
# gpg: Signature made Thu 13 Jun 2019 18:24:43 BST
# gpg: using RSA key 239B9B6E3BB08B22
# gpg: Good signature from "Alex Williamson <alex.williamson@redhat.com>" [full]
# gpg: aka "Alex Williamson <alex@shazbot.org>" [full]
# gpg: aka "Alex Williamson <alwillia@redhat.com>" [full]
# gpg: aka "Alex Williamson <alex.l.williamson@gmail.com>" [full]
# Primary key fingerprint: 42F6 C04E 540B D1A9 9E7B 8A90 239B 9B6E 3BB0 8B22
* remotes/awilliam/tags/vfio-updates-20190613.0:
vfio/common: Introduce vfio_set_irq_signaling helper
vfio/pci: Allow MSI-X relocation to fixup bogus PBA
vfio/pci: Hide Resizable BAR capability
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Diffstat (limited to 'hw/vfio/common.c')
-rw-r--r-- | hw/vfio/common.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/hw/vfio/common.c b/hw/vfio/common.c index 4374cc6176..a859298fda 100644 --- a/hw/vfio/common.c +++ b/hw/vfio/common.c @@ -95,6 +95,84 @@ void vfio_mask_single_irqindex(VFIODevice *vbasedev, int index) ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, &irq_set); } +static inline const char *action_to_str(int action) +{ + switch (action) { + case VFIO_IRQ_SET_ACTION_MASK: + return "MASK"; + case VFIO_IRQ_SET_ACTION_UNMASK: + return "UNMASK"; + case VFIO_IRQ_SET_ACTION_TRIGGER: + return "TRIGGER"; + default: + return "UNKNOWN ACTION"; + } +} + +static const char *index_to_str(VFIODevice *vbasedev, int index) +{ + if (vbasedev->type != VFIO_DEVICE_TYPE_PCI) { + return NULL; + } + + switch (index) { + case VFIO_PCI_INTX_IRQ_INDEX: + return "INTX"; + case VFIO_PCI_MSI_IRQ_INDEX: + return "MSI"; + case VFIO_PCI_MSIX_IRQ_INDEX: + return "MSIX"; + case VFIO_PCI_ERR_IRQ_INDEX: + return "ERR"; + case VFIO_PCI_REQ_IRQ_INDEX: + return "REQ"; + default: + return NULL; + } +} + +int vfio_set_irq_signaling(VFIODevice *vbasedev, int index, int subindex, + int action, int fd, Error **errp) +{ + struct vfio_irq_set *irq_set; + int argsz, ret = 0; + const char *name; + int32_t *pfd; + + argsz = sizeof(*irq_set) + sizeof(*pfd); + + irq_set = g_malloc0(argsz); + irq_set->argsz = argsz; + irq_set->flags = VFIO_IRQ_SET_DATA_EVENTFD | action; + irq_set->index = index; + irq_set->start = subindex; + irq_set->count = 1; + pfd = (int32_t *)&irq_set->data; + *pfd = fd; + + if (ioctl(vbasedev->fd, VFIO_DEVICE_SET_IRQS, irq_set)) { + ret = -errno; + } + g_free(irq_set); + + if (!ret) { + return 0; + } + + error_setg_errno(errp, -ret, "VFIO_DEVICE_SET_IRQS failure"); + + name = index_to_str(vbasedev, index); + if (name) { + error_prepend(errp, "%s-%d: ", name, subindex); + } else { + error_prepend(errp, "index %d-%d: ", index, subindex); + } + error_prepend(errp, + "Failed to %s %s eventfd signaling for interrupt ", + fd < 0 ? "tear down" : "set up", action_to_str(action)); + return ret; +} + /* * IO Port/MMIO - Beware of the endians, VFIO is always little endian */ |