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 #include "qemu/sockets.h" 16 #include "hw/vfio-user/protocol.h" 17 18 typedef struct { 19 int send_fds; 20 int recv_fds; 21 int *fds; 22 } VFIOUserFDs; 23 24 enum msg_type { 25 VFIO_MSG_NONE, 26 VFIO_MSG_ASYNC, 27 VFIO_MSG_WAIT, 28 VFIO_MSG_NOWAIT, 29 VFIO_MSG_REQ, 30 }; 31 32 typedef struct VFIOUserMsg { 33 QTAILQ_ENTRY(VFIOUserMsg) next; 34 VFIOUserHdr *hdr; 35 VFIOUserFDs *fds; 36 uint32_t rsize; 37 uint32_t id; 38 QemuCond cv; 39 bool complete; 40 enum msg_type type; 41 } VFIOUserMsg; 42 43 44 enum proxy_state { 45 VFIO_PROXY_CONNECTED = 1, 46 VFIO_PROXY_ERROR = 2, 47 VFIO_PROXY_CLOSING = 3, 48 VFIO_PROXY_CLOSED = 4, 49 }; 50 51 typedef QTAILQ_HEAD(VFIOUserMsgQ, VFIOUserMsg) VFIOUserMsgQ; 52 53 typedef struct VFIOUserProxy { 54 QLIST_ENTRY(VFIOUserProxy) next; 55 char *sockname; 56 struct QIOChannel *ioc; 57 void (*request)(void *opaque, VFIOUserMsg *msg); 58 void *req_arg; 59 int flags; 60 QemuCond close_cv; 61 AioContext *ctx; 62 QEMUBH *req_bh; 63 64 /* 65 * above only changed when BQL is held 66 * below are protected by per-proxy lock 67 */ 68 QemuMutex lock; 69 VFIOUserMsgQ free; 70 VFIOUserMsgQ pending; 71 VFIOUserMsgQ incoming; 72 VFIOUserMsgQ outgoing; 73 VFIOUserMsg *last_nowait; 74 VFIOUserMsg *part_recv; 75 size_t recv_left; 76 enum proxy_state state; 77 } VFIOUserProxy; 78 79 /* VFIOProxy flags */ 80 #define VFIO_PROXY_CLIENT 0x1 81 82 typedef struct VFIODevice VFIODevice; 83 84 VFIOUserProxy *vfio_user_connect_dev(SocketAddress *addr, Error **errp); 85 void vfio_user_disconnect(VFIOUserProxy *proxy); 86 void vfio_user_set_handler(VFIODevice *vbasedev, 87 void (*handler)(void *opaque, VFIOUserMsg *msg), 88 void *reqarg); 89 90 #endif /* VFIO_USER_PROXY_H */ 91