xref: /openbmc/qemu/include/hw/virtio/vhost-backend.h (revision 4fe6d78b)
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 typedef enum VhostSetConfigType {
24     VHOST_SET_CONFIG_TYPE_MASTER = 0,
25     VHOST_SET_CONFIG_TYPE_MIGRATION = 1,
26 } VhostSetConfigType;
27 
28 struct vhost_dev;
29 struct vhost_log;
30 struct vhost_memory;
31 struct vhost_vring_file;
32 struct vhost_vring_state;
33 struct vhost_vring_addr;
34 struct vhost_scsi_target;
35 struct vhost_iotlb_msg;
36 
37 typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque);
38 typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev);
39 typedef int (*vhost_backend_memslots_limit)(struct vhost_dev *dev);
40 
41 typedef int (*vhost_net_set_backend_op)(struct vhost_dev *dev,
42                                 struct vhost_vring_file *file);
43 typedef int (*vhost_net_set_mtu_op)(struct vhost_dev *dev, uint16_t mtu);
44 typedef int (*vhost_scsi_set_endpoint_op)(struct vhost_dev *dev,
45                                   struct vhost_scsi_target *target);
46 typedef int (*vhost_scsi_clear_endpoint_op)(struct vhost_dev *dev,
47                                     struct vhost_scsi_target *target);
48 typedef int (*vhost_scsi_get_abi_version_op)(struct vhost_dev *dev,
49                                              int *version);
50 typedef int (*vhost_set_log_base_op)(struct vhost_dev *dev, uint64_t base,
51                                      struct vhost_log *log);
52 typedef int (*vhost_set_mem_table_op)(struct vhost_dev *dev,
53                                       struct vhost_memory *mem);
54 typedef int (*vhost_set_vring_addr_op)(struct vhost_dev *dev,
55                                        struct vhost_vring_addr *addr);
56 typedef int (*vhost_set_vring_endian_op)(struct vhost_dev *dev,
57                                          struct vhost_vring_state *ring);
58 typedef int (*vhost_set_vring_num_op)(struct vhost_dev *dev,
59                                       struct vhost_vring_state *ring);
60 typedef int (*vhost_set_vring_base_op)(struct vhost_dev *dev,
61                                        struct vhost_vring_state *ring);
62 typedef int (*vhost_get_vring_base_op)(struct vhost_dev *dev,
63                                        struct vhost_vring_state *ring);
64 typedef int (*vhost_set_vring_kick_op)(struct vhost_dev *dev,
65                                        struct vhost_vring_file *file);
66 typedef int (*vhost_set_vring_call_op)(struct vhost_dev *dev,
67                                        struct vhost_vring_file *file);
68 typedef int (*vhost_set_vring_busyloop_timeout_op)(struct vhost_dev *dev,
69                                                    struct vhost_vring_state *r);
70 typedef int (*vhost_set_features_op)(struct vhost_dev *dev,
71                                      uint64_t features);
72 typedef int (*vhost_get_features_op)(struct vhost_dev *dev,
73                                      uint64_t *features);
74 typedef int (*vhost_set_owner_op)(struct vhost_dev *dev);
75 typedef int (*vhost_reset_device_op)(struct vhost_dev *dev);
76 typedef int (*vhost_get_vq_index_op)(struct vhost_dev *dev, int idx);
77 typedef int (*vhost_set_vring_enable_op)(struct vhost_dev *dev,
78                                          int enable);
79 typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev);
80 typedef int (*vhost_migration_done_op)(struct vhost_dev *dev,
81                                        char *mac_addr);
82 typedef bool (*vhost_backend_can_merge_op)(struct vhost_dev *dev,
83                                            uint64_t start1, uint64_t size1,
84                                            uint64_t start2, uint64_t size2);
85 typedef int (*vhost_vsock_set_guest_cid_op)(struct vhost_dev *dev,
86                                             uint64_t guest_cid);
87 typedef int (*vhost_vsock_set_running_op)(struct vhost_dev *dev, int start);
88 typedef void (*vhost_set_iotlb_callback_op)(struct vhost_dev *dev,
89                                            int enabled);
90 typedef int (*vhost_send_device_iotlb_msg_op)(struct vhost_dev *dev,
91                                               struct vhost_iotlb_msg *imsg);
92 typedef int (*vhost_set_config_op)(struct vhost_dev *dev, const uint8_t *data,
93                                    uint32_t offset, uint32_t size,
94                                    uint32_t flags);
95 typedef int (*vhost_get_config_op)(struct vhost_dev *dev, uint8_t *config,
96                                    uint32_t config_len);
97 
98 typedef struct VhostOps {
99     VhostBackendType backend_type;
100     vhost_backend_init vhost_backend_init;
101     vhost_backend_cleanup vhost_backend_cleanup;
102     vhost_backend_memslots_limit vhost_backend_memslots_limit;
103     vhost_net_set_backend_op vhost_net_set_backend;
104     vhost_net_set_mtu_op vhost_net_set_mtu;
105     vhost_scsi_set_endpoint_op vhost_scsi_set_endpoint;
106     vhost_scsi_clear_endpoint_op vhost_scsi_clear_endpoint;
107     vhost_scsi_get_abi_version_op vhost_scsi_get_abi_version;
108     vhost_set_log_base_op vhost_set_log_base;
109     vhost_set_mem_table_op vhost_set_mem_table;
110     vhost_set_vring_addr_op vhost_set_vring_addr;
111     vhost_set_vring_endian_op vhost_set_vring_endian;
112     vhost_set_vring_num_op vhost_set_vring_num;
113     vhost_set_vring_base_op vhost_set_vring_base;
114     vhost_get_vring_base_op vhost_get_vring_base;
115     vhost_set_vring_kick_op vhost_set_vring_kick;
116     vhost_set_vring_call_op vhost_set_vring_call;
117     vhost_set_vring_busyloop_timeout_op vhost_set_vring_busyloop_timeout;
118     vhost_set_features_op vhost_set_features;
119     vhost_get_features_op vhost_get_features;
120     vhost_set_owner_op vhost_set_owner;
121     vhost_reset_device_op vhost_reset_device;
122     vhost_get_vq_index_op vhost_get_vq_index;
123     vhost_set_vring_enable_op vhost_set_vring_enable;
124     vhost_requires_shm_log_op vhost_requires_shm_log;
125     vhost_migration_done_op vhost_migration_done;
126     vhost_backend_can_merge_op vhost_backend_can_merge;
127     vhost_vsock_set_guest_cid_op vhost_vsock_set_guest_cid;
128     vhost_vsock_set_running_op vhost_vsock_set_running;
129     vhost_set_iotlb_callback_op vhost_set_iotlb_callback;
130     vhost_send_device_iotlb_msg_op vhost_send_device_iotlb_msg;
131     vhost_get_config_op vhost_get_config;
132     vhost_set_config_op vhost_set_config;
133 } VhostOps;
134 
135 extern const VhostOps user_ops;
136 
137 int vhost_set_backend_type(struct vhost_dev *dev,
138                            VhostBackendType backend_type);
139 
140 int vhost_backend_update_device_iotlb(struct vhost_dev *dev,
141                                              uint64_t iova, uint64_t uaddr,
142                                              uint64_t len,
143                                              IOMMUAccessFlags perm);
144 
145 int vhost_backend_invalidate_device_iotlb(struct vhost_dev *dev,
146                                                  uint64_t iova, uint64_t len);
147 
148 int vhost_backend_handle_iotlb_msg(struct vhost_dev *dev,
149                                           struct vhost_iotlb_msg *imsg);
150 
151 #endif /* VHOST_BACKEND_H */
152