master
h 122 lines 4 KB
Raw
1 /*
2 * Copyright (c) 2017-2018 Intel Corporation
3 *
4 * This work is licensed under the terms of the GNU GPL, version 2.
5 * See the COPYING file in the top-level directory.
6 */
7
8 #ifndef HW_VIRTIO_VHOST_USER_H
9 #define HW_VIRTIO_VHOST_USER_H
10
11 #include "chardev/char-fe.h"
12 #include "hw/virtio/virtio.h"
13 #include "qapi/qapi-types-virtio.h"
14
15 enum VhostUserProtocolFeature {
16 VHOST_USER_PROTOCOL_F_MQ = 0,
17 VHOST_USER_PROTOCOL_F_LOG_SHMFD = 1,
18 VHOST_USER_PROTOCOL_F_RARP = 2,
19 VHOST_USER_PROTOCOL_F_REPLY_ACK = 3,
20 VHOST_USER_PROTOCOL_F_NET_MTU = 4,
21 VHOST_USER_PROTOCOL_F_BACKEND_REQ = 5,
22 VHOST_USER_PROTOCOL_F_CROSS_ENDIAN = 6,
23 VHOST_USER_PROTOCOL_F_CRYPTO_SESSION = 7,
24 VHOST_USER_PROTOCOL_F_PAGEFAULT = 8,
25 VHOST_USER_PROTOCOL_F_CONFIG = 9,
26 VHOST_USER_PROTOCOL_F_BACKEND_SEND_FD = 10,
27 VHOST_USER_PROTOCOL_F_HOST_NOTIFIER = 11,
28 VHOST_USER_PROTOCOL_F_INFLIGHT_SHMFD = 12,
29 VHOST_USER_PROTOCOL_F_RESET_DEVICE = 13,
30 VHOST_USER_PROTOCOL_F_INBAND_NOTIFICATIONS = 14,
31 VHOST_USER_PROTOCOL_F_CONFIGURE_MEM_SLOTS = 15,
32 VHOST_USER_PROTOCOL_F_STATUS = 16,
33 /* Feature 17 reserved for VHOST_USER_PROTOCOL_F_XEN_MMAP. */
34 VHOST_USER_PROTOCOL_F_SHARED_OBJECT = 18,
35 VHOST_USER_PROTOCOL_F_DEVICE_STATE = 19,
36 VHOST_USER_PROTOCOL_F_GET_VRING_BASE_INFLIGHT = 20,
37 VHOST_USER_PROTOCOL_F_GPA_ADDRESSES = 21,
38 VHOST_USER_PROTOCOL_F_SHMEM = 22,
39 VHOST_USER_PROTOCOL_F_MAX
40 };
41
42 /**
43 * VhostUserHostNotifier - notifier information for one queue
44 * @rcu: rcu_head for cleanup
45 * @mr: memory region of notifier
46 * @addr: current mapped address
47 * @unmap_addr: address to be un-mapped
48 * @idx: virtioqueue index
49 *
50 * The VhostUserHostNotifier entries are re-used. When an old mapping
51 * is to be released it is moved to @unmap_addr and @addr is replaced.
52 * Once the RCU process has completed the unmap @unmap_addr is
53 * cleared.
54 */
55 typedef struct VhostUserHostNotifier {
56 struct rcu_head rcu;
57 MemoryRegion mr;
58 void *addr;
59 void *unmap_addr;
60 int idx;
61 bool destroy;
62 } VhostUserHostNotifier;
63
64 /**
65 * VhostUserState - shared state for all vhost-user devices
66 * @chr: the character backend for the socket
67 * @notifiers: GPtrArray of @VhostUserHostnotifier
68 * @memory_slots:
69 */
70 typedef struct VhostUserState {
71 CharFrontend *chr;
72 GPtrArray *notifiers;
73 int memory_slots;
74 bool supports_config;
75 bool supports_inflight_migration;
76 } VhostUserState;
77
78 /**
79 * vhost_user_init() - initialise shared vhost_user state
80 * @user: allocated area for storing shared state
81 * @chr: the chardev for the vhost socket
82 * @errp: error handle
83 *
84 * User can either directly g_new() space for the state or embed
85 * VhostUserState in their larger device structure and just point to
86 * it.
87 *
88 * Return: true on success, false on error while setting errp.
89 */
90 bool vhost_user_init(VhostUserState *user, CharFrontend *chr, Error **errp);
91
92 /**
93 * vhost_user_cleanup() - cleanup state
94 * @user: ptr to use state
95 *
96 * Cleans up shared state and notifiers, callee is responsible for
97 * freeing the @VhostUserState memory itself.
98 */
99 void vhost_user_cleanup(VhostUserState *user);
100
101 /**
102 * vhost_user_async_close() - cleanup vhost-user post connection drop
103 * @d: DeviceState for the associated device (passed to callback)
104 * @chardev: the CharFrontend associated with the connection
105 * @vhost: the common vhost device
106 * @cb: the user callback function to complete the clean-up
107 *
108 * This function is used to handle the shutdown of a vhost-user
109 * connection to a backend. We handle this centrally to make sure we
110 * do all the steps and handle potential races due to VM shutdowns.
111 * Once the connection is disabled we call a backhalf to ensure
112 */
113 typedef void (*vu_async_close_fn)(DeviceState *cb);
114
115 void vhost_user_async_close(DeviceState *d,
116 CharFrontend *chardev, struct vhost_dev *vhost,
117 vu_async_close_fn cb);
118
119 void vhost_user_qmp_status(struct vhost_dev *dev, VirtioStatus *status);
120 bool vhost_user_has_protocol_feature(struct vhost_dev *dev, uint64_t feature);
121
122 #endif