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