]>
Commit | Line | Data |
---|---|---|
10857ec0 EP |
1 | /* |
2 | * vhost shadow virtqueue | |
3 | * | |
4 | * SPDX-FileCopyrightText: Red Hat, Inc. 2021 | |
5 | * SPDX-FileContributor: Author: Eugenio Pérez <[email protected]> | |
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" | |
dafb34c9 EP |
14 | #include "hw/virtio/virtio.h" |
15 | #include "standard-headers/linux/vhost_types.h" | |
34e3c94e | 16 | #include "hw/virtio/vhost-iova-tree.h" |
10857ec0 EP |
17 | |
18 | /* Shadow virtqueue to relay notifications */ | |
19 | typedef struct VhostShadowVirtqueue { | |
dafb34c9 EP |
20 | /* Shadow vring */ |
21 | struct vring vring; | |
22 | ||
10857ec0 EP |
23 | /* Shadow kick notifier, sent to vhost */ |
24 | EventNotifier hdev_kick; | |
25 | /* Shadow call notifier, sent to vhost */ | |
26 | EventNotifier hdev_call; | |
dff4426f EP |
27 | |
28 | /* | |
29 | * Borrowed virtqueue's guest to host notifier. To borrow it in this event | |
30 | * notifier allows to recover the VhostShadowVirtqueue from the event loop | |
31 | * easily. If we use the VirtQueue's one, we don't have an easy way to | |
32 | * retrieve VhostShadowVirtqueue. | |
33 | * | |
34 | * So shadow virtqueue must not clean it, or we would lose VirtQueue one. | |
35 | */ | |
36 | EventNotifier svq_kick; | |
a8ac8858 EP |
37 | |
38 | /* Guest's call notifier, where the SVQ calls guest. */ | |
39 | EventNotifier svq_call; | |
100890f7 EP |
40 | |
41 | /* Virtio queue shadowing */ | |
42 | VirtQueue *vq; | |
43 | ||
44 | /* Virtio device */ | |
45 | VirtIODevice *vdev; | |
46 | ||
34e3c94e EP |
47 | /* IOVA mapping */ |
48 | VhostIOVATree *iova_tree; | |
49 | ||
100890f7 EP |
50 | /* Map for use the guest's descriptors */ |
51 | VirtQueueElement **ring_id_maps; | |
52 | ||
53 | /* Next VirtQueue element that guest made available */ | |
54 | VirtQueueElement *next_guest_avail_elem; | |
55 | ||
495fe3a7 EP |
56 | /* |
57 | * Backup next field for each descriptor so we can recover securely, not | |
58 | * needing to trust the device access. | |
59 | */ | |
60 | uint16_t *desc_next; | |
61 | ||
100890f7 EP |
62 | /* Next head to expose to the device */ |
63 | uint16_t shadow_avail_idx; | |
64 | ||
65 | /* Next free descriptor */ | |
66 | uint16_t free_head; | |
67 | ||
68 | /* Last seen used idx */ | |
69 | uint16_t shadow_used_idx; | |
70 | ||
71 | /* Next head to consume from the device */ | |
72 | uint16_t last_used_idx; | |
10857ec0 EP |
73 | } VhostShadowVirtqueue; |
74 | ||
4725a418 EP |
75 | bool vhost_svq_valid_features(uint64_t features, Error **errp); |
76 | ||
dff4426f | 77 | void vhost_svq_set_svq_kick_fd(VhostShadowVirtqueue *svq, int svq_kick_fd); |
a8ac8858 | 78 | void vhost_svq_set_svq_call_fd(VhostShadowVirtqueue *svq, int call_fd); |
dafb34c9 EP |
79 | void vhost_svq_get_vring_addr(const VhostShadowVirtqueue *svq, |
80 | struct vhost_vring_addr *addr); | |
81 | size_t vhost_svq_driver_area_size(const VhostShadowVirtqueue *svq); | |
82 | size_t vhost_svq_device_area_size(const VhostShadowVirtqueue *svq); | |
dff4426f | 83 | |
100890f7 EP |
84 | void vhost_svq_start(VhostShadowVirtqueue *svq, VirtIODevice *vdev, |
85 | VirtQueue *vq); | |
dff4426f EP |
86 | void vhost_svq_stop(VhostShadowVirtqueue *svq); |
87 | ||
34e3c94e | 88 | VhostShadowVirtqueue *vhost_svq_new(VhostIOVATree *iova_tree); |
10857ec0 EP |
89 | |
90 | void vhost_svq_free(gpointer vq); | |
91 | G_DEFINE_AUTOPTR_CLEANUP_FUNC(VhostShadowVirtqueue, vhost_svq_free); | |
92 | ||
93 | #endif |