2020-07-01 22:55:37 +08:00
|
|
|
/*
|
|
|
|
* vhost-vdpa.h
|
|
|
|
*
|
|
|
|
* Copyright(c) 2017-2018 Intel Corporation.
|
|
|
|
* Copyright(c) 2020 Red Hat, Inc.
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef HW_VIRTIO_VHOST_VDPA_H
|
|
|
|
#define HW_VIRTIO_VHOST_VDPA_H
|
|
|
|
|
2022-03-14 18:34:42 +01:00
|
|
|
#include <gmodule.h>
|
|
|
|
|
2022-03-14 18:34:51 +01:00
|
|
|
#include "hw/virtio/vhost-iova-tree.h"
|
2022-07-20 08:59:42 +02:00
|
|
|
#include "hw/virtio/vhost-shadow-virtqueue.h"
|
2020-07-01 22:55:37 +08:00
|
|
|
#include "hw/virtio/virtio.h"
|
2021-10-14 16:12:36 +02:00
|
|
|
#include "standard-headers/linux/vhost_types.h"
|
2020-07-01 22:55:37 +08:00
|
|
|
|
2022-12-15 12:31:41 +01:00
|
|
|
/*
|
|
|
|
* ASID dedicated to map guest's addresses. If SVQ is disabled it maps GPA to
|
|
|
|
* qemu's IOVA. If SVQ is enabled it maps also the SVQ vring here
|
|
|
|
*/
|
|
|
|
#define VHOST_VDPA_GUEST_PA_ASID 0
|
|
|
|
|
2021-04-15 15:33:56 +08:00
|
|
|
typedef struct VhostVDPAHostNotifier {
|
|
|
|
MemoryRegion mr;
|
|
|
|
void *addr;
|
|
|
|
} VhostVDPAHostNotifier;
|
|
|
|
|
2024-02-14 03:28:00 -08:00
|
|
|
typedef enum SVQTransitionState {
|
|
|
|
SVQ_TSTATE_DISABLING = -1,
|
|
|
|
SVQ_TSTATE_DONE,
|
|
|
|
SVQ_TSTATE_ENABLING
|
|
|
|
} SVQTransitionState;
|
|
|
|
|
2023-12-21 18:43:10 +01:00
|
|
|
/* Info shared by all vhost_vdpa device models */
|
|
|
|
typedef struct vhost_vdpa_shared {
|
2023-12-21 18:43:15 +01:00
|
|
|
int device_fd;
|
2023-12-21 18:43:22 +01:00
|
|
|
MemoryListener listener;
|
2023-12-21 18:43:12 +01:00
|
|
|
struct vhost_vdpa_iova_range iova_range;
|
2023-12-21 18:43:19 +01:00
|
|
|
QLIST_HEAD(, vdpa_iommu) iommu_list;
|
2023-12-21 18:43:12 +01:00
|
|
|
|
2023-12-21 18:43:11 +01:00
|
|
|
/* IOVA mapping used by the Shadow Virtqueue */
|
|
|
|
VhostIOVATree *iova_tree;
|
2023-12-21 18:43:13 +01:00
|
|
|
|
2023-12-21 18:43:17 +01:00
|
|
|
/* Copy of backend features */
|
|
|
|
uint64_t backend_cap;
|
|
|
|
|
2023-12-21 18:43:16 +01:00
|
|
|
bool iotlb_batch_begin_sent;
|
|
|
|
|
2023-12-21 18:43:13 +01:00
|
|
|
/* Vdpa must send shadow addresses as IOTLB key for data queues, not GPA */
|
|
|
|
bool shadow_data;
|
2024-02-14 03:28:00 -08:00
|
|
|
|
|
|
|
/* SVQ switching is in progress, or already completed? */
|
|
|
|
SVQTransitionState svq_switching;
|
2023-12-21 18:43:10 +01:00
|
|
|
} VhostVDPAShared;
|
|
|
|
|
2020-07-01 22:55:37 +08:00
|
|
|
typedef struct vhost_vdpa {
|
2021-10-20 12:55:52 +08:00
|
|
|
int index;
|
2022-12-15 12:31:41 +01:00
|
|
|
uint32_t address_space_id;
|
2022-03-14 18:34:54 +01:00
|
|
|
uint64_t acked_features;
|
2022-03-14 18:34:42 +01:00
|
|
|
bool shadow_vqs_enabled;
|
2023-03-03 18:24:36 +01:00
|
|
|
/* Device suspended successfully */
|
|
|
|
bool suspended;
|
2023-12-21 18:43:10 +01:00
|
|
|
VhostVDPAShared *shared;
|
2022-03-14 18:34:42 +01:00
|
|
|
GPtrArray *shadow_vqs;
|
2022-07-20 08:59:42 +02:00
|
|
|
const VhostShadowVirtqueueOps *shadow_vq_ops;
|
|
|
|
void *shadow_vq_ops_opaque;
|
2020-09-07 18:49:03 +08:00
|
|
|
struct vhost_dev *dev;
|
2023-03-03 18:24:41 +01:00
|
|
|
Error *migration_blocker;
|
2021-04-15 15:33:56 +08:00
|
|
|
VhostVDPAHostNotifier notifier[VIRTIO_QUEUE_MAX];
|
2023-05-10 13:46:31 +08:00
|
|
|
IOMMUNotifier n;
|
2020-07-01 22:55:37 +08:00
|
|
|
} VhostVDPA;
|
|
|
|
|
2022-12-24 19:48:47 +08:00
|
|
|
int vhost_vdpa_get_iova_range(int fd, struct vhost_vdpa_iova_range *iova_range);
|
2023-08-22 10:53:27 +02:00
|
|
|
int vhost_vdpa_set_vring_ready(struct vhost_vdpa *v, unsigned idx);
|
2022-12-24 19:48:47 +08:00
|
|
|
|
2023-12-21 18:43:20 +01:00
|
|
|
int vhost_vdpa_dma_map(VhostVDPAShared *s, uint32_t asid, hwaddr iova,
|
2022-12-15 12:31:41 +01:00
|
|
|
hwaddr size, void *vaddr, bool readonly);
|
2023-12-21 18:43:20 +01:00
|
|
|
int vhost_vdpa_dma_unmap(VhostVDPAShared *s, uint32_t asid, hwaddr iova,
|
2022-12-15 12:31:41 +01:00
|
|
|
hwaddr size);
|
2022-07-20 08:59:40 +02:00
|
|
|
|
2023-05-10 13:46:31 +08:00
|
|
|
typedef struct vdpa_iommu {
|
2023-12-21 18:43:21 +01:00
|
|
|
VhostVDPAShared *dev_shared;
|
2023-05-10 13:46:31 +08:00
|
|
|
IOMMUMemoryRegion *iommu_mr;
|
|
|
|
hwaddr iommu_offset;
|
|
|
|
IOMMUNotifier n;
|
|
|
|
QLIST_ENTRY(vdpa_iommu) iommu_next;
|
|
|
|
} VDPAIOMMUState;
|
|
|
|
|
|
|
|
|
2020-07-01 22:55:37 +08:00
|
|
|
#endif
|