xref: /qemu/hw/virtio/vhost-shadow-virtqueue.h (revision 4725a4181b0fd5b646c51f079d7eac753b14b094)
1 /*
2  * vhost shadow virtqueue
3  *
4  * SPDX-FileCopyrightText: Red Hat, Inc. 2021
5  * SPDX-FileContributor: Author: Eugenio Pérez <eperezma@redhat.com>
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  */
9 
10 #ifndef VHOST_SHADOW_VIRTQUEUE_H
11 #define VHOST_SHADOW_VIRTQUEUE_H
12 
13 #include "qemu/event_notifier.h"
14 
15 /* Shadow virtqueue to relay notifications */
16 typedef struct VhostShadowVirtqueue {
17     /* Shadow kick notifier, sent to vhost */
18     EventNotifier hdev_kick;
19     /* Shadow call notifier, sent to vhost */
20     EventNotifier hdev_call;
21 
22     /*
23      * Borrowed virtqueue's guest to host notifier. To borrow it in this event
24      * notifier allows to recover the VhostShadowVirtqueue from the event loop
25      * easily. If we use the VirtQueue's one, we don't have an easy way to
26      * retrieve VhostShadowVirtqueue.
27      *
28      * So shadow virtqueue must not clean it, or we would lose VirtQueue one.
29      */
30     EventNotifier svq_kick;
31 
32     /* Guest's call notifier, where the SVQ calls guest. */
33     EventNotifier svq_call;
34 } VhostShadowVirtqueue;
35 
36 bool vhost_svq_valid_features(uint64_t features, Error **errp);
37 
38 void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd);
39 void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd);
40 
41 void vhost_svq_stop(VhostShadowVirtqueue *svq);
42 
43 VhostShadowVirtqueue *vhost_svq_new(void);
44 
45 void vhost_svq_free(gpointer vq);
46 G_DEFINE_AUTOPTR_CLEANUP_FUNC(VhostShadowVirtqueue, vhost_svq_free);
47 
48 #endif
49