xref: /openbmc/qemu/include/hw/virtio/vhost-user.h (revision d6cd3ae0)
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 /**
15  * VhostUserHostNotifier - notifier information for one queue
16  * @rcu: rcu_head for cleanup
17  * @mr: memory region of notifier
18  * @addr: current mapped address
19  * @unmap_addr: address to be un-mapped
20  * @idx: virtioqueue index
21  *
22  * The VhostUserHostNotifier entries are re-used. When an old mapping
23  * is to be released it is moved to @unmap_addr and @addr is replaced.
24  * Once the RCU process has completed the unmap @unmap_addr is
25  * cleared.
26  */
27 typedef struct VhostUserHostNotifier {
28     struct rcu_head rcu;
29     MemoryRegion mr;
30     void *addr;
31     void *unmap_addr;
32     int idx;
33 } VhostUserHostNotifier;
34 
35 /**
36  * VhostUserState - shared state for all vhost-user devices
37  * @chr: the character backend for the socket
38  * @notifiers: GPtrArray of @VhostUserHostnotifier
39  * @memory_slots:
40  */
41 typedef struct VhostUserState {
42     CharBackend *chr;
43     GPtrArray *notifiers;
44     int memory_slots;
45     bool supports_config;
46 } VhostUserState;
47 
48 /**
49  * vhost_user_init() - initialise shared vhost_user state
50  * @user: allocated area for storing shared state
51  * @chr: the chardev for the vhost socket
52  * @errp: error handle
53  *
54  * User can either directly g_new() space for the state or embed
55  * VhostUserState in their larger device structure and just point to
56  * it.
57  *
58  * Return: true on success, false on error while setting errp.
59  */
60 bool vhost_user_init(VhostUserState *user, CharBackend *chr, Error **errp);
61 
62 /**
63  * vhost_user_cleanup() - cleanup state
64  * @user: ptr to use state
65  *
66  * Cleans up shared state and notifiers, callee is responsible for
67  * freeing the @VhostUserState memory itself.
68  */
69 void vhost_user_cleanup(VhostUserState *user);
70 
71 #endif
72