xref: /qemu/hw/vfio-user/proxy.h (revision 438d863f1f40fbc2b57bf94cc6c998a6445c0932)
1*438d863fSJohn Levon #ifndef VFIO_USER_PROXY_H
2*438d863fSJohn Levon #define VFIO_USER_PROXY_H
3*438d863fSJohn Levon 
4*438d863fSJohn Levon /*
5*438d863fSJohn Levon  * vfio protocol over a UNIX socket.
6*438d863fSJohn Levon  *
7*438d863fSJohn Levon  * Copyright © 2018, 2021 Oracle and/or its affiliates.
8*438d863fSJohn Levon  *
9*438d863fSJohn Levon  * SPDX-License-Identifier: GPL-2.0-or-later
10*438d863fSJohn Levon  */
11*438d863fSJohn Levon 
12*438d863fSJohn Levon #include "io/channel.h"
13*438d863fSJohn Levon #include "io/channel-socket.h"
14*438d863fSJohn Levon 
15*438d863fSJohn Levon typedef struct {
16*438d863fSJohn Levon     int send_fds;
17*438d863fSJohn Levon     int recv_fds;
18*438d863fSJohn Levon     int *fds;
19*438d863fSJohn Levon } VFIOUserFDs;
20*438d863fSJohn Levon 
21*438d863fSJohn Levon enum msg_type {
22*438d863fSJohn Levon     VFIO_MSG_NONE,
23*438d863fSJohn Levon     VFIO_MSG_ASYNC,
24*438d863fSJohn Levon     VFIO_MSG_WAIT,
25*438d863fSJohn Levon     VFIO_MSG_NOWAIT,
26*438d863fSJohn Levon     VFIO_MSG_REQ,
27*438d863fSJohn Levon };
28*438d863fSJohn Levon 
29*438d863fSJohn Levon typedef struct VFIOUserMsg {
30*438d863fSJohn Levon     QTAILQ_ENTRY(VFIOUserMsg) next;
31*438d863fSJohn Levon     VFIOUserFDs *fds;
32*438d863fSJohn Levon     uint32_t rsize;
33*438d863fSJohn Levon     uint32_t id;
34*438d863fSJohn Levon     QemuCond cv;
35*438d863fSJohn Levon     bool complete;
36*438d863fSJohn Levon     enum msg_type type;
37*438d863fSJohn Levon } VFIOUserMsg;
38*438d863fSJohn Levon 
39*438d863fSJohn Levon 
40*438d863fSJohn Levon enum proxy_state {
41*438d863fSJohn Levon     VFIO_PROXY_CONNECTED = 1,
42*438d863fSJohn Levon     VFIO_PROXY_ERROR = 2,
43*438d863fSJohn Levon     VFIO_PROXY_CLOSING = 3,
44*438d863fSJohn Levon     VFIO_PROXY_CLOSED = 4,
45*438d863fSJohn Levon };
46*438d863fSJohn Levon 
47*438d863fSJohn Levon typedef QTAILQ_HEAD(VFIOUserMsgQ, VFIOUserMsg) VFIOUserMsgQ;
48*438d863fSJohn Levon 
49*438d863fSJohn Levon typedef struct VFIOUserProxy {
50*438d863fSJohn Levon     QLIST_ENTRY(VFIOUserProxy) next;
51*438d863fSJohn Levon     char *sockname;
52*438d863fSJohn Levon     struct QIOChannel *ioc;
53*438d863fSJohn Levon     void (*request)(void *opaque, VFIOUserMsg *msg);
54*438d863fSJohn Levon     void *req_arg;
55*438d863fSJohn Levon     int flags;
56*438d863fSJohn Levon     QemuCond close_cv;
57*438d863fSJohn Levon     AioContext *ctx;
58*438d863fSJohn Levon     QEMUBH *req_bh;
59*438d863fSJohn Levon 
60*438d863fSJohn Levon     /*
61*438d863fSJohn Levon      * above only changed when BQL is held
62*438d863fSJohn Levon      * below are protected by per-proxy lock
63*438d863fSJohn Levon      */
64*438d863fSJohn Levon     QemuMutex lock;
65*438d863fSJohn Levon     VFIOUserMsgQ free;
66*438d863fSJohn Levon     VFIOUserMsgQ pending;
67*438d863fSJohn Levon     VFIOUserMsgQ incoming;
68*438d863fSJohn Levon     VFIOUserMsgQ outgoing;
69*438d863fSJohn Levon     VFIOUserMsg *last_nowait;
70*438d863fSJohn Levon     enum proxy_state state;
71*438d863fSJohn Levon } VFIOUserProxy;
72*438d863fSJohn Levon 
73*438d863fSJohn Levon /* VFIOProxy flags */
74*438d863fSJohn Levon #define VFIO_PROXY_CLIENT        0x1
75*438d863fSJohn Levon 
76*438d863fSJohn Levon VFIOUserProxy *vfio_user_connect_dev(SocketAddress *addr, Error **errp);
77*438d863fSJohn Levon void vfio_user_disconnect(VFIOUserProxy *proxy);
78*438d863fSJohn Levon 
79*438d863fSJohn Levon #endif /* VFIO_USER_PROXY_H */
80