xref: /qemu/include/hw/virtio/vhost-vdpa.h (revision 4bda8224)
1 /*
2  * vhost-vdpa.h
3  *
4  * Copyright(c) 2017-2018 Intel Corporation.
5  * Copyright(c) 2020 Red Hat, Inc.
6  *
7  * This work is licensed under the terms of the GNU GPL, version 2 or later.
8  * See the COPYING file in the top-level directory.
9  *
10  */
11 
12 #ifndef HW_VIRTIO_VHOST_VDPA_H
13 #define HW_VIRTIO_VHOST_VDPA_H
14 
15 #include <gmodule.h>
16 
17 #include "hw/virtio/vhost-iova-tree.h"
18 #include "hw/virtio/vhost-shadow-virtqueue.h"
19 #include "hw/virtio/virtio.h"
20 #include "standard-headers/linux/vhost_types.h"
21 
22 /*
23  * ASID dedicated to map guest's addresses.  If SVQ is disabled it maps GPA to
24  * qemu's IOVA.  If SVQ is enabled it maps also the SVQ vring here
25  */
26 #define VHOST_VDPA_GUEST_PA_ASID 0
27 
28 typedef struct VhostVDPAHostNotifier {
29     MemoryRegion mr;
30     void *addr;
31 } VhostVDPAHostNotifier;
32 
33 /* Info shared by all vhost_vdpa device models */
34 typedef struct vhost_vdpa_shared {
35     int device_fd;
36     MemoryListener listener;
37     struct vhost_vdpa_iova_range iova_range;
38     QLIST_HEAD(, vdpa_iommu) iommu_list;
39 
40     /* IOVA mapping used by the Shadow Virtqueue */
41     VhostIOVATree *iova_tree;
42 
43     /* Copy of backend features */
44     uint64_t backend_cap;
45 
46     bool iotlb_batch_begin_sent;
47 
48     /* Vdpa must send shadow addresses as IOTLB key for data queues, not GPA */
49     bool shadow_data;
50 } VhostVDPAShared;
51 
52 typedef struct vhost_vdpa {
53     int index;
54     uint32_t address_space_id;
55     uint64_t acked_features;
56     bool shadow_vqs_enabled;
57     /* Device suspended successfully */
58     bool suspended;
59     VhostVDPAShared *shared;
60     GPtrArray *shadow_vqs;
61     const VhostShadowVirtqueueOps *shadow_vq_ops;
62     void *shadow_vq_ops_opaque;
63     struct vhost_dev *dev;
64     Error *migration_blocker;
65     VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX];
66     IOMMUNotifier n;
67 } VhostVDPA;
68 
69 int vhost_vdpa_get_iova_range(int fd, struct vhost_vdpa_iova_range *iova_range);
70 int vhost_vdpa_set_vring_ready(struct vhost_vdpa *v, unsigned idx);
71 
72 int vhost_vdpa_dma_map(VhostVDPAShared *s, uint32_t asid, hwaddr iova,
73                        hwaddr size, void *vaddr, bool readonly);
74 int vhost_vdpa_dma_unmap(VhostVDPAShared *s, uint32_t asid, hwaddr iova,
75                          hwaddr size);
76 
77 typedef struct vdpa_iommu {
78     VhostVDPAShared *dev_shared;
79     IOMMUMemoryRegion *iommu_mr;
80     hwaddr iommu_offset;
81     IOMMUNotifier n;
82     QLIST_ENTRY(vdpa_iommu) iommu_next;
83 } VDPAIOMMUState;
84 
85 
86 #endif
87