int virtio_bus_start_ioeventfd(VirtioBusState *bus) { VirtioBusClass *k = VIRTIO_BUS_GET_CLASS(bus); DeviceState *proxy = DEVICE(BUS(bus)->parent); VirtIODevice *vdev = virtio_bus_get_device(bus); VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev); int r; if (!k->ioeventfd_assign || !k->ioeventfd_enabled(proxy)) { return -ENOSYS; } if (bus->ioeventfd_started) { return 0; } /* Only set our notifier if we have ownership. */ if (!bus->ioeventfd_grabbed) { r = vdc->start_ioeventfd(vdev); if (r < 0) { error_report("%s: failed. Fallback to userspace (slower).", __func__); return r; } } bus->ioeventfd_started = true; return 0; }
static int virtio_mmio_set_guest_notifier(DeviceState *d, int n, bool assign, bool with_irqfd) { VirtIOMMIOProxy *proxy = VIRTIO_MMIO(d); VirtIODevice *vdev = virtio_bus_get_device(&proxy->bus); VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev); VirtQueue *vq = virtio_get_queue(vdev, n); EventNotifier *notifier = virtio_queue_get_guest_notifier(vq); if (assign) { int r = event_notifier_init(notifier, 0); if (r < 0) { return r; } virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd); } else { virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd); event_notifier_cleanup(notifier); } if (vdc->guest_notifier_mask && vdev->use_guest_notifier_mask) { vdc->guest_notifier_mask(vdev, n, !assign); } return 0; }
/* Get config of the plugged device. */ void virtio_bus_get_vdev_config(VirtioBusState *bus, uint8_t *config) { VirtioDeviceClass *k; assert(bus->vdev != NULL); k = VIRTIO_DEVICE_GET_CLASS(bus->vdev); if (k->get_config != NULL) { k->get_config(bus->vdev, config); } }
/* Get the features of the plugged device. */ uint32_t virtio_bus_get_vdev_features(VirtioBusState *bus, uint32_t requested_features) { VirtioDeviceClass *k; assert(bus->vdev != NULL); k = VIRTIO_DEVICE_GET_CLASS(bus->vdev); assert(k->get_features != NULL); return k->get_features(bus->vdev, requested_features); }
/* Set config of the plugged device. */ void virtio_bus_set_vdev_config(VirtioBusState *bus, uint8_t *config) { VirtIODevice *vdev = virtio_bus_get_device(bus); VirtioDeviceClass *k; assert(vdev != NULL); k = VIRTIO_DEVICE_GET_CLASS(vdev); if (k->set_config != NULL) { k->set_config(vdev, config); } }
/* Get bad features of the plugged device. */ uint32_t virtio_bus_get_vdev_bad_features(VirtioBusState *bus) { VirtioDeviceClass *k; assert(bus->vdev != NULL); k = VIRTIO_DEVICE_GET_CLASS(bus->vdev); if (k->bad_features != NULL) { return k->bad_features(bus->vdev); } else { return 0; } }
/* Set the features of the plugged device. */ void virtio_bus_set_vdev_features(VirtioBusState *bus, uint32_t requested_features) { VirtIODevice *vdev = virtio_bus_get_device(bus); VirtioDeviceClass *k; assert(vdev != NULL); k = VIRTIO_DEVICE_GET_CLASS(vdev); if (k->set_features != NULL) { k->set_features(vdev, requested_features); } }
void virtio_bus_stop_ioeventfd(VirtioBusState *bus) { VirtIODevice *vdev; VirtioDeviceClass *vdc; if (!bus->ioeventfd_started) { return; } vdev = virtio_bus_get_device(bus); vdc = VIRTIO_DEVICE_GET_CLASS(vdev); vdc->stop_ioeventfd(vdev); bus->ioeventfd_started = false; }
void virtio_bus_stop_ioeventfd(VirtioBusState *bus) { VirtIODevice *vdev; VirtioDeviceClass *vdc; if (!bus->ioeventfd_started) { return; } /* Only remove our notifier if we have ownership. */ if (!bus->ioeventfd_grabbed) { vdev = virtio_bus_get_device(bus); vdc = VIRTIO_DEVICE_GET_CLASS(vdev); vdc->stop_ioeventfd(vdev); } bus->ioeventfd_started = false; }
/* A VirtIODevice is being plugged */ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp) { DeviceState *qdev = DEVICE(vdev); BusState *qbus = BUS(qdev_get_parent_bus(qdev)); VirtioBusState *bus = VIRTIO_BUS(qbus); VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus); VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev); bool has_iommu = virtio_host_has_feature(vdev, VIRTIO_F_IOMMU_PLATFORM); Error *local_err = NULL; DPRINTF("%s: plug device.\n", qbus->name); if (klass->pre_plugged != NULL) { klass->pre_plugged(qbus->parent, &local_err); if (local_err) { error_propagate(errp, local_err); return; } } /* Get the features of the plugged device. */ assert(vdc->get_features != NULL); vdev->host_features = vdc->get_features(vdev, vdev->host_features, &local_err); if (local_err) { error_propagate(errp, local_err); return; } if (klass->device_plugged != NULL) { klass->device_plugged(qbus->parent, &local_err); } if (local_err) { error_propagate(errp, local_err); return; } if (klass->get_dma_as != NULL && has_iommu) { virtio_add_feature(&vdev->host_features, VIRTIO_F_IOMMU_PLATFORM); vdev->dma_as = klass->get_dma_as(qbus->parent); } else { vdev->dma_as = &address_space_memory; } }
/* A VirtIODevice is being plugged */ void virtio_bus_device_plugged(VirtIODevice *vdev, Error **errp) { DeviceState *qdev = DEVICE(vdev); BusState *qbus = BUS(qdev_get_parent_bus(qdev)); VirtioBusState *bus = VIRTIO_BUS(qbus); VirtioBusClass *klass = VIRTIO_BUS_GET_CLASS(bus); VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(vdev); DPRINTF("%s: plug device.\n", qbus->name); if (klass->device_plugged != NULL) { klass->device_plugged(qbus->parent, errp); } /* Get the features of the plugged device. */ assert(vdc->get_features != NULL); vdev->host_features = vdc->get_features(vdev, vdev->host_features, errp); if (klass->post_plugged != NULL) { klass->post_plugged(qbus->parent, errp); } }
static int virtio_ccw_set_guest_notifier(VirtioCcwDevice *dev, int n, bool assign, bool with_irqfd) { VirtQueue *vq = virtio_get_queue(dev->vdev, n); EventNotifier *notifier = virtio_queue_get_guest_notifier(vq); VirtioDeviceClass *k = VIRTIO_DEVICE_GET_CLASS(dev->vdev); if (assign) { int r = event_notifier_init(notifier, 0); if (r < 0) { return r; } virtio_queue_set_guest_notifier_fd_handler(vq, true, with_irqfd); /* We do not support irqfd for classic I/O interrupts, because the * classic interrupts are intermixed with the subchannel status, that * is queried with test subchannel. We want to use vhost, though. * Lets make sure to have vhost running and wire up the irq fd to * land in qemu (and only the irq fd) in this code. */ if (k->guest_notifier_mask) { k->guest_notifier_mask(dev->vdev, n, false); } /* get lost events and re-inject */ if (k->guest_notifier_pending && k->guest_notifier_pending(dev->vdev, n)) { event_notifier_set(notifier); } } else { if (k->guest_notifier_mask) { k->guest_notifier_mask(dev->vdev, n, true); } virtio_queue_set_guest_notifier_fd_handler(vq, false, with_irqfd); event_notifier_cleanup(notifier); } return 0; }