From 15b2bd1847239fe0b4a1041b69a631741d2e273a Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Thu, 5 Jul 2012 17:16:30 +0200 Subject: virtio: move common irqfd handling out of virtio-pci All transports can use the same event handler for the irqfd, though the exact mechanics of the assignment will be specific. Note that there are three states: handled by the kernel, handled in userspace, disabled. This also lets virtio use event_notifier_set_handler. Signed-off-by: Paolo Bonzini Signed-off-by: Avi Kivity --- hw/virtio.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'hw/virtio.c') diff --git a/hw/virtio.c b/hw/virtio.c index 197edf0..d146f86 100644 --- a/hw/virtio.c +++ b/hw/virtio.c @@ -984,6 +984,30 @@ VirtQueue *virtio_get_queue(VirtIODevice *vdev, int n) return vdev->vq + n; } +static void virtio_queue_guest_notifier_read(EventNotifier *n) +{ + VirtQueue *vq = container_of(n, VirtQueue, guest_notifier); + if (event_notifier_test_and_clear(n)) { + virtio_irq(vq); + } +} + +void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign, + bool with_irqfd) +{ + if (assign && !with_irqfd) { + event_notifier_set_handler(&vq->guest_notifier, + virtio_queue_guest_notifier_read); + } else { + event_notifier_set_handler(&vq->guest_notifier, NULL); + } + if (!assign) { + /* Test and clear notifier before closing it, + * in case poll callback didn't have time to run. */ + virtio_queue_guest_notifier_read(&vq->guest_notifier); + } +} + EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq) { return &vq->guest_notifier; -- cgit v1.1