Skip to content

Commit 7d847d0

Browse files
lulu-github-namemstsirkin
authored andcommitted
virtio: add support for configure interrupt
Add the functions to support the configure interrupt in virtio The function virtio_config_guest_notifier_read will notify the guest if there is an configure interrupt. The function virtio_config_set_guest_notifier_fd_handler is to set the fd hander for the notifier Signed-off-by: Cindy Lu <[email protected]> Message-Id: <[email protected]> Acked-by: Jason Wang <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 259f3ac commit 7d847d0

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

hw/virtio/virtio.c

+29
Original file line numberDiff line numberDiff line change
@@ -3417,7 +3417,14 @@ static void virtio_queue_guest_notifier_read(EventNotifier *n)
34173417
virtio_irq(vq);
34183418
}
34193419
}
3420+
static void virtio_config_guest_notifier_read(EventNotifier *n)
3421+
{
3422+
VirtIODevice *vdev = container_of(n, VirtIODevice, config_notifier);
34203423

3424+
if (event_notifier_test_and_clear(n)) {
3425+
virtio_notify_config(vdev);
3426+
}
3427+
}
34213428
void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign,
34223429
bool with_irqfd)
34233430
{
@@ -3434,6 +3441,23 @@ void virtio_queue_set_guest_notifier_fd_handler(VirtQueue *vq, bool assign,
34343441
}
34353442
}
34363443

3444+
void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev,
3445+
bool assign, bool with_irqfd)
3446+
{
3447+
EventNotifier *n;
3448+
n = &vdev->config_notifier;
3449+
if (assign && !with_irqfd) {
3450+
event_notifier_set_handler(n, virtio_config_guest_notifier_read);
3451+
} else {
3452+
event_notifier_set_handler(n, NULL);
3453+
}
3454+
if (!assign) {
3455+
/* Test and clear notifier before closing it,*/
3456+
/* in case poll callback didn't have time to run. */
3457+
virtio_config_guest_notifier_read(n);
3458+
}
3459+
}
3460+
34373461
EventNotifier *virtio_queue_get_guest_notifier(VirtQueue *vq)
34383462
{
34393463
return &vq->guest_notifier;
@@ -3514,6 +3538,11 @@ EventNotifier *virtio_queue_get_host_notifier(VirtQueue *vq)
35143538
return &vq->host_notifier;
35153539
}
35163540

3541+
EventNotifier *virtio_config_get_guest_notifier(VirtIODevice *vdev)
3542+
{
3543+
return &vdev->config_notifier;
3544+
}
3545+
35173546
void virtio_queue_set_host_notifier_enabled(VirtQueue *vq, bool enabled)
35183547
{
35193548
vq->host_notifier_enabled = enabled;

include/hw/virtio/virtio.h

+4
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ struct VirtIODevice
155155
AddressSpace *dma_as;
156156
QLIST_HEAD(, VirtQueue) *vector_queues;
157157
QTAILQ_ENTRY(VirtIODevice) next;
158+
EventNotifier config_notifier;
158159
};
159160

160161
struct VirtioDeviceClass {
@@ -377,6 +378,9 @@ void virtio_queue_aio_attach_host_notifier_no_poll(VirtQueue *vq, AioContext *ct
377378
void virtio_queue_aio_detach_host_notifier(VirtQueue *vq, AioContext *ctx);
378379
VirtQueue *virtio_vector_first_queue(VirtIODevice *vdev, uint16_t vector);
379380
VirtQueue *virtio_vector_next_queue(VirtQueue *vq);
381+
EventNotifier *virtio_config_get_guest_notifier(VirtIODevice *vdev);
382+
void virtio_config_set_guest_notifier_fd_handler(VirtIODevice *vdev,
383+
bool assign, bool with_irqfd);
380384

381385
static inline void virtio_add_feature(uint64_t *features, unsigned int fbit)
382386
{

0 commit comments

Comments
 (0)