xref: /qemu/include/hw/virtio/vhost-backend.h (revision 9a78a5dd272a190d262b5ba5d4721ab93d48c564)
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 <stdbool.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 
26 typedef int (*vhost_call)(struct vhost_dev *dev, unsigned long int request,
27              void *arg);
28 typedef int (*vhost_backend_init)(struct vhost_dev *dev, void *opaque);
29 typedef int (*vhost_backend_cleanup)(struct vhost_dev *dev);
30 typedef int (*vhost_backend_get_vq_index)(struct vhost_dev *dev, int idx);
31 typedef int (*vhost_backend_set_vring_enable)(struct vhost_dev *dev, int enable);
32 typedef int (*vhost_backend_memslots_limit)(struct vhost_dev *dev);
33 
34 typedef int (*vhost_set_log_base_op)(struct vhost_dev *dev, uint64_t base,
35                                      struct vhost_log *log);
36 typedef bool (*vhost_requires_shm_log_op)(struct vhost_dev *dev);
37 
38 typedef struct VhostOps {
39     VhostBackendType backend_type;
40     vhost_call vhost_call;
41     vhost_backend_init vhost_backend_init;
42     vhost_backend_cleanup vhost_backend_cleanup;
43     vhost_backend_get_vq_index vhost_backend_get_vq_index;
44     vhost_backend_set_vring_enable vhost_backend_set_vring_enable;
45     vhost_backend_memslots_limit vhost_backend_memslots_limit;
46     vhost_set_log_base_op vhost_set_log_base;
47     vhost_requires_shm_log_op vhost_requires_shm_log;
48 } VhostOps;
49 
50 extern const VhostOps user_ops;
51 
52 int vhost_set_backend_type(struct vhost_dev *dev,
53                            VhostBackendType backend_type);
54 
55 #endif /* VHOST_BACKEND_H_ */
56