xref: /openbmc/qemu/include/hw/virtio/vhost-backend.h (revision 5b262bb6)
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 typedef enum VhostBackendType {
15     VHOST_BACKEND_TYPE_NONE = 0,
16     VHOST_BACKEND_TYPE_KERNEL = 1,
17     VHOST_BACKEND_TYPE_USER = 2,
18     VHOST_BACKEND_TYPE_MAX = 3,
19 } VhostBackendType;
20 
21 struct vhost_dev;
22 struct vhost_log;
23 struct vhost_memory;
24 struct vhost_vring_file;
25 struct vhost_vring_state;
26 struct vhost_vring_addr;
27 struct vhost_scsi_target;
28 
29 typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque);
30 typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev);
31 typedef int (*vhost_backend_memslots_limit)(struct vhost_dev *dev);
32 
33 typedef int (*vhost_net_set_backend_op)(struct vhost_dev *dev,
34                                 struct vhost_vring_file *file);
35 typedef int (*vhost_scsi_set_endpoint_op)(struct vhost_dev *dev,
36                                   struct vhost_scsi_target *target);
37 typedef int (*vhost_scsi_clear_endpoint_op)(struct vhost_dev *dev,
38                                     struct vhost_scsi_target *target);
39 typedef int (*vhost_scsi_get_abi_version_op)(struct vhost_dev *dev,
40                                              int *version);
41 typedef int (*vhost_set_log_base_op)(struct vhost_dev *dev, uint64_t base,
42                                      struct vhost_log *log);
43 typedef int (*vhost_set_mem_table_op)(struct vhost_dev *dev,
44                                       struct vhost_memory *mem);
45 typedef int (*vhost_set_vring_addr_op)(struct vhost_dev *dev,
46                                        struct vhost_vring_addr *addr);
47 typedef int (*vhost_set_vring_endian_op)(struct vhost_dev *dev,
48                                          struct vhost_vring_state *ring);
49 typedef int (*vhost_set_vring_num_op)(struct vhost_dev *dev,
50                                       struct vhost_vring_state *ring);
51 typedef int (*vhost_set_vring_base_op)(struct vhost_dev *dev,
52                                        struct vhost_vring_state *ring);
53 typedef int (*vhost_get_vring_base_op)(struct vhost_dev *dev,
54                                        struct vhost_vring_state *ring);
55 typedef int (*vhost_set_vring_kick_op)(struct vhost_dev *dev,
56                                        struct vhost_vring_file *file);
57 typedef int (*vhost_set_vring_call_op)(struct vhost_dev *dev,
58                                        struct vhost_vring_file *file);
59 typedef int (*vhost_set_vring_busyloop_timeout_op)(struct vhost_dev *dev,
60                                                    struct vhost_vring_state *r);
61 typedef int (*vhost_set_features_op)(struct vhost_dev *dev,
62                                      uint64_t features);
63 typedef int (*vhost_get_features_op)(struct vhost_dev *dev,
64                                      uint64_t *features);
65 typedef int (*vhost_set_owner_op)(struct vhost_dev *dev);
66 typedef int (*vhost_reset_device_op)(struct vhost_dev *dev);
67 typedef int (*vhost_get_vq_index_op)(struct vhost_dev *dev, int idx);
68 typedef int (*vhost_set_vring_enable_op)(struct vhost_dev *dev,
69                                          int enable);
70 typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev);
71 typedef int (*vhost_migration_done_op)(struct vhost_dev *dev,
72                                        char *mac_addr);
73 typedef bool (*vhost_backend_can_merge_op)(struct vhost_dev *dev,
74                                            uint64_t start1, uint64_t size1,
75                                            uint64_t start2, uint64_t size2);
76 typedef int (*vhost_vsock_set_guest_cid_op)(struct vhost_dev *dev,
77                                             uint64_t guest_cid);
78 typedef int (*vhost_vsock_set_running_op)(struct vhost_dev *dev, int start);
79 
80 typedef struct VhostOps {
81     VhostBackendType backend_type;
82     vhost_backend_init vhost_backend_init;
83     vhost_backend_cleanup vhost_backend_cleanup;
84     vhost_backend_memslots_limit vhost_backend_memslots_limit;
85     vhost_net_set_backend_op vhost_net_set_backend;
86     vhost_scsi_set_endpoint_op vhost_scsi_set_endpoint;
87     vhost_scsi_clear_endpoint_op vhost_scsi_clear_endpoint;
88     vhost_scsi_get_abi_version_op vhost_scsi_get_abi_version;
89     vhost_set_log_base_op vhost_set_log_base;
90     vhost_set_mem_table_op vhost_set_mem_table;
91     vhost_set_vring_addr_op vhost_set_vring_addr;
92     vhost_set_vring_endian_op vhost_set_vring_endian;
93     vhost_set_vring_num_op vhost_set_vring_num;
94     vhost_set_vring_base_op vhost_set_vring_base;
95     vhost_get_vring_base_op vhost_get_vring_base;
96     vhost_set_vring_kick_op vhost_set_vring_kick;
97     vhost_set_vring_call_op vhost_set_vring_call;
98     vhost_set_vring_busyloop_timeout_op vhost_set_vring_busyloop_timeout;
99     vhost_set_features_op vhost_set_features;
100     vhost_get_features_op vhost_get_features;
101     vhost_set_owner_op vhost_set_owner;
102     vhost_reset_device_op vhost_reset_device;
103     vhost_get_vq_index_op vhost_get_vq_index;
104     vhost_set_vring_enable_op vhost_set_vring_enable;
105     vhost_requires_shm_log_op vhost_requires_shm_log;
106     vhost_migration_done_op vhost_migration_done;
107     vhost_backend_can_merge_op vhost_backend_can_merge;
108     vhost_vsock_set_guest_cid_op vhost_vsock_set_guest_cid;
109     vhost_vsock_set_running_op vhost_vsock_set_running;
110 } VhostOps;
111 
112 extern const VhostOps user_ops;
113 
114 int vhost_set_backend_type(struct vhost_dev *dev,
115                            VhostBackendType backend_type);
116 
117 #endif /* VHOST_BACKEND_H */
118