mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 07:43:54 -06:00
vfio/common: Introduce vfio_set_irq_signaling helper
The code used to assign an interrupt index/subindex to an eventfd is duplicated many times. Let's introduce an helper that allows to set/unset the signaling for an ACTION_TRIGGER, ACTION_MASK or ACTION_UNMASK action. In the error message, we now use errno in case of any VFIO_DEVICE_SET_IRQS ioctl failure. Signed-off-by: Eric Auger <eric.auger@redhat.com> Reviewed-by: Cornelia Huck <cohuck@redhat.com> Reviewed-by: Li Qiang <liq3ea@gmail.com> Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
This commit is contained in:
parent
c60807dea5
commit
201a733145
4 changed files with 151 additions and 208 deletions
|
@ -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
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue