xref: /openbmc/qemu/include/hw/virtio/vhost-backend.h (revision 80e5db30)
1 /*
2  * vhost-backend
3  *
4  * Copyright (c) 2013 Virtual Open Systems Sarl.
5  *
6  * This work is licensed under the terms of the GNU GPL, version 2 or later.
7  * See the COPYING file in the top-level directory.
8  *
9  */
10 
11 #ifndef VHOST_BACKEND_H
12 #define VHOST_BACKEND_H
13 
14 #include "exec/memory.h"
15 
16 typedef enum VhostBackendType {
17     VHOST_BACKEND_TYPE_NONE = 0,
18     VHOST_BACKEND_TYPE_KERNEL = 1,
19     VHOST_BACKEND_TYPE_USER = 2,
20     VHOST_BACKEND_TYPE_MAX = 3,
21 } VhostBackendType;
22 
23 struct vhost_dev;
24 struct vhost_log;
25 struct vhost_memory;
26 struct vhost_vring_file;
27 struct vhost_vring_state;
28 struct vhost_vring_addr;
29 struct vhost_scsi_target;
30 
31 typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque);
32 typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev);
33 typedef int (*vhost_backend_memslots_limit)(struct vhost_dev *dev);
34 
35 typedef int (*vhost_net_set_backend_op)(struct vhost_dev *dev,
36                                 struct vhost_vring_file *file);
37 typedef int (*vhost_net_set_mtu_op)(struct vhost_dev *dev, uint16_t mtu);
38 typedef int (*vhost_scsi_set_endpoint_op)(struct vhost_dev *dev,
39                                   struct vhost_scsi_target *target);
40 typedef int (*vhost_scsi_clear_endpoint_op)(struct vhost_dev *dev,
41                                     struct vhost_scsi_target *target);
42 typedef int (*vhost_scsi_get_abi_version_op)(struct vhost_dev *dev,
43                                              int *version);
44 typedef int (*vhost_set_log_base_op)(struct vhost_dev *dev, uint64_t base,
45                                      struct vhost_log *log);
46 typedef int (*vhost_set_mem_table_op)(struct vhost_dev *dev,
47                                       struct vhost_memory *mem);
48 typedef int (*vhost_set_vring_addr_op)(struct vhost_dev *dev,
49                                        struct vhost_vring_addr *addr);
50 typedef int (*vhost_set_vring_endian_op)(struct vhost_dev *dev,
51                                          struct vhost_vring_state *ring);
52 typedef int (*vhost_set_vring_num_op)(struct vhost_dev *dev,
53                                       struct vhost_vring_state *ring);
54 typedef int (*vhost_set_vring_base_op)(struct vhost_dev *dev,
55                                        struct vhost_vring_state *ring);
56 typedef int (*vhost_get_vring_base_op)(struct vhost_dev *dev,
57                                        struct vhost_vring_state *ring);
58 typedef int (*vhost_set_vring_kick_op)(struct vhost_dev *dev,
59                                        struct vhost_vring_file *file);
60 typedef int (*vhost_set_vring_call_op)(struct vhost_dev *dev,
61                                        struct vhost_vring_file *file);
62 typedef int (*vhost_set_vring_busyloop_timeout_op)(struct vhost_dev *dev,
63                                                    struct vhost_vring_state *r);
64 typedef int (*vhost_set_features_op)(struct vhost_dev *dev,
65                                      uint64_t features);
66 typedef int (*vhost_get_features_op)(struct vhost_dev *dev,
67                                      uint64_t *features);
68 typedef int (*vhost_set_owner_op)(struct vhost_dev *dev);
69 typedef int (*vhost_reset_device_op)(struct vhost_dev *dev);
70 typedef int (*vhost_get_vq_index_op)(struct vhost_dev *dev, int idx);
71 typedef int (*vhost_set_vring_enable_op)(struct vhost_dev *dev,
72                                          int enable);
73 typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev);
74 typedef int (*vhost_migration_done_op)(struct vhost_dev *dev,
75                                        char *mac_addr);
76 typedef bool (*vhost_backend_can_merge_op)(struct vhost_dev *dev,
77                                            uint64_t start1, uint64_t size1,
78                                            uint64_t start2, uint64_t size2);
79 typedef int (*vhost_vsock_set_guest_cid_op)(struct vhost_dev *dev,
80                                             uint64_t guest_cid);
81 typedef int (*vhost_vsock_set_running_op)(struct vhost_dev *dev, int start);
82 typedef void (*vhost_set_iotlb_callback_op)(struct vhost_dev *dev,
83                                            int enabled);
84 typedef int (*vhost_update_device_iotlb_op)(struct vhost_dev *dev,
85                                             uint64_t iova, uint64_t uaddr,
86                                             uint64_t len,
87                                             IOMMUAccessFlags perm);
88 typedef int (*vhost_invalidate_device_iotlb_op)(struct vhost_dev *dev,
89                                                 uint64_t iova, uint64_t len);
90 
91 typedef struct VhostOps {
92     VhostBackendType backend_type;
93     vhost_backend_init vhost_backend_init;
94     vhost_backend_cleanup vhost_backend_cleanup;
95     vhost_backend_memslots_limit vhost_backend_memslots_limit;
96     vhost_net_set_backend_op vhost_net_set_backend;
97     vhost_net_set_mtu_op vhost_net_set_mtu;
98     vhost_scsi_set_endpoint_op vhost_scsi_set_endpoint;
99     vhost_scsi_clear_endpoint_op vhost_scsi_clear_endpoint;
100     vhost_scsi_get_abi_version_op vhost_scsi_get_abi_version;
101     vhost_set_log_base_op vhost_set_log_base;
102     vhost_set_mem_table_op vhost_set_mem_table;
103     vhost_set_vring_addr_op vhost_set_vring_addr;
104     vhost_set_vring_endian_op vhost_set_vring_endian;
105     vhost_set_vring_num_op vhost_set_vring_num;
106     vhost_set_vring_base_op vhost_set_vring_base;
107     vhost_get_vring_base_op vhost_get_vring_base;
108     vhost_set_vring_kick_op vhost_set_vring_kick;
109     vhost_set_vring_call_op vhost_set_vring_call;
110     vhost_set_vring_busyloop_timeout_op vhost_set_vring_busyloop_timeout;
111     vhost_set_features_op vhost_set_features;
112     vhost_get_features_op vhost_get_features;
113     vhost_set_owner_op vhost_set_owner;
114     vhost_reset_device_op vhost_reset_device;
115     vhost_get_vq_index_op vhost_get_vq_index;
116     vhost_set_vring_enable_op vhost_set_vring_enable;
117     vhost_requires_shm_log_op vhost_requires_shm_log;
118     vhost_migration_done_op vhost_migration_done;
119     vhost_backend_can_merge_op vhost_backend_can_merge;
120     vhost_vsock_set_guest_cid_op vhost_vsock_set_guest_cid;
121     vhost_vsock_set_running_op vhost_vsock_set_running;
122     vhost_set_iotlb_callback_op vhost_set_iotlb_callback;
123     vhost_update_device_iotlb_op vhost_update_device_iotlb;
124     vhost_invalidate_device_iotlb_op vhost_invalidate_device_iotlb;
125 } VhostOps;
126 
127 extern const VhostOps user_ops;
128 
129 int vhost_set_backend_type(struct vhost_dev *dev,
130                            VhostBackendType backend_type);
131 
132 #endif /* VHOST_BACKEND_H */
133