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 struct vhost_vdpa_iova_range iova_range; 37 38 /* IOVA mapping used by the Shadow Virtqueue */ 39 VhostIOVATree *iova_tree; 40 41 /* Vdpa must send shadow addresses as IOTLB key for data queues, not GPA */ 42 bool shadow_data; 43 } VhostVDPAShared; 44 45 typedef struct vhost_vdpa { 46 int index; 47 uint32_t msg_type; 48 bool iotlb_batch_begin_sent; 49 uint32_t address_space_id; 50 MemoryListener listener; 51 uint64_t acked_features; 52 bool shadow_vqs_enabled; 53 /* Device suspended successfully */ 54 bool suspended; 55 VhostVDPAShared *shared; 56 GPtrArray *shadow_vqs; 57 const VhostShadowVirtqueueOps *shadow_vq_ops; 58 void *shadow_vq_ops_opaque; 59 struct vhost_dev *dev; 60 Error *migration_blocker; 61 VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX]; 62 QLIST_HEAD(, vdpa_iommu) iommu_list; 63 IOMMUNotifier n; 64 } VhostVDPA; 65 66 int vhost_vdpa_get_iova_range(int fd, struct vhost_vdpa_iova_range *iova_range); 67 int vhost_vdpa_set_vring_ready(struct vhost_vdpa *v, unsigned idx); 68 69 int vhost_vdpa_dma_map(struct vhost_vdpa *v, uint32_t asid, hwaddr iova, 70 hwaddr size, void *vaddr, bool readonly); 71 int vhost_vdpa_dma_unmap(struct vhost_vdpa *v, uint32_t asid, hwaddr iova, 72 hwaddr size); 73 74 typedef struct vdpa_iommu { 75 struct vhost_vdpa *dev; 76 IOMMUMemoryRegion *iommu_mr; 77 hwaddr iommu_offset; 78 IOMMUNotifier n; 79 QLIST_ENTRY(vdpa_iommu) iommu_next; 80 } VDPAIOMMUState; 81 82 83 #endif 84