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