xref: /qemu/include/hw/virtio/vhost-user.h (revision 503e355465ba0eafad49c2e174995d2e234ed288)
14d0cf552STiwei Bie /*
24d0cf552STiwei Bie  * Copyright (c) 2017-2018 Intel Corporation
34d0cf552STiwei Bie  *
44d0cf552STiwei Bie  * This work is licensed under the terms of the GNU GPL, version 2.
54d0cf552STiwei Bie  * See the COPYING file in the top-level directory.
64d0cf552STiwei Bie  */
74d0cf552STiwei Bie 
84d0cf552STiwei Bie #ifndef HW_VIRTIO_VHOST_USER_H
94d0cf552STiwei Bie #define HW_VIRTIO_VHOST_USER_H
104d0cf552STiwei Bie 
114d0cf552STiwei Bie #include "chardev/char-fe.h"
1244866521STiwei Bie #include "hw/virtio/virtio.h"
1344866521STiwei Bie 
14*503e3554SAlex Bennée /**
15*503e3554SAlex Bennée  * VhostUserHostNotifier - notifier information for one queue
16*503e3554SAlex Bennée  * @rcu: rcu_head for cleanup
17*503e3554SAlex Bennée  * @mr: memory region of notifier
18*503e3554SAlex Bennée  * @addr: current mapped address
19*503e3554SAlex Bennée  * @unmap_addr: address to be un-mapped
20*503e3554SAlex Bennée  * @idx: virtioqueue index
21*503e3554SAlex Bennée  *
22*503e3554SAlex Bennée  * The VhostUserHostNotifier entries are re-used. When an old mapping
23*503e3554SAlex Bennée  * is to be released it is moved to @unmap_addr and @addr is replaced.
24*503e3554SAlex Bennée  * Once the RCU process has completed the unmap @unmap_addr is
25*503e3554SAlex Bennée  * cleared.
26*503e3554SAlex Bennée  */
2744866521STiwei Bie typedef struct VhostUserHostNotifier {
280b0af4d6SXueming Li     struct rcu_head rcu;
2944866521STiwei Bie     MemoryRegion mr;
3044866521STiwei Bie     void *addr;
310b0af4d6SXueming Li     void *unmap_addr;
32*503e3554SAlex Bennée     int idx;
3344866521STiwei Bie } VhostUserHostNotifier;
344d0cf552STiwei Bie 
35*503e3554SAlex Bennée /**
36*503e3554SAlex Bennée  * VhostUserState - shared state for all vhost-user devices
37*503e3554SAlex Bennée  * @chr: the character backend for the socket
38*503e3554SAlex Bennée  * @notifiers: GPtrArray of @VhostUserHostnotifier
39*503e3554SAlex Bennée  * @memory_slots:
40*503e3554SAlex Bennée  */
414d0cf552STiwei Bie typedef struct VhostUserState {
424d0cf552STiwei Bie     CharBackend *chr;
43*503e3554SAlex Bennée     GPtrArray *notifiers;
446b0eff1aSRaphael Norwitz     int memory_slots;
4556534930SAlex Bennée     bool supports_config;
464d0cf552STiwei Bie } VhostUserState;
474d0cf552STiwei Bie 
48*503e3554SAlex Bennée /**
49*503e3554SAlex Bennée  * vhost_user_init() - initialise shared vhost_user state
50*503e3554SAlex Bennée  * @user: allocated area for storing shared state
51*503e3554SAlex Bennée  * @chr: the chardev for the vhost socket
52*503e3554SAlex Bennée  * @errp: error handle
53*503e3554SAlex Bennée  *
54*503e3554SAlex Bennée  * User can either directly g_new() space for the state or embed
55*503e3554SAlex Bennée  * VhostUserState in their larger device structure and just point to
56*503e3554SAlex Bennée  * it.
57*503e3554SAlex Bennée  *
58*503e3554SAlex Bennée  * Return: true on success, false on error while setting errp.
59*503e3554SAlex Bennée  */
600b99f224SMarc-André Lureau bool vhost_user_init(VhostUserState *user, CharBackend *chr, Error **errp);
61*503e3554SAlex Bennée 
62*503e3554SAlex Bennée /**
63*503e3554SAlex Bennée  * vhost_user_cleanup() - cleanup state
64*503e3554SAlex Bennée  * @user: ptr to use state
65*503e3554SAlex Bennée  *
66*503e3554SAlex Bennée  * Cleans up shared state and notifiers, callee is responsible for
67*503e3554SAlex Bennée  * freeing the @VhostUserState memory itself.
68*503e3554SAlex Bennée  */
694d0cf552STiwei Bie void vhost_user_cleanup(VhostUserState *user);
704d0cf552STiwei Bie 
714d0cf552STiwei Bie #endif
72