1438d863fSJohn Levon #ifndef VFIO_USER_PROXY_H 2438d863fSJohn Levon #define VFIO_USER_PROXY_H 3438d863fSJohn Levon 4438d863fSJohn Levon /* 5438d863fSJohn Levon * vfio protocol over a UNIX socket. 6438d863fSJohn Levon * 7438d863fSJohn Levon * Copyright © 2018, 2021 Oracle and/or its affiliates. 8438d863fSJohn Levon * 9438d863fSJohn Levon * SPDX-License-Identifier: GPL-2.0-or-later 10438d863fSJohn Levon */ 11438d863fSJohn Levon 12438d863fSJohn Levon #include "io/channel.h" 13438d863fSJohn Levon #include "io/channel-socket.h" 14438d863fSJohn Levon 15*0b3d881aSJohn Levon #include "qemu/sockets.h" 16*0b3d881aSJohn Levon #include "hw/vfio-user/protocol.h" 17*0b3d881aSJohn Levon 18438d863fSJohn Levon typedef struct { 19438d863fSJohn Levon int send_fds; 20438d863fSJohn Levon int recv_fds; 21438d863fSJohn Levon int *fds; 22438d863fSJohn Levon } VFIOUserFDs; 23438d863fSJohn Levon 24438d863fSJohn Levon enum msg_type { 25438d863fSJohn Levon VFIO_MSG_NONE, 26438d863fSJohn Levon VFIO_MSG_ASYNC, 27438d863fSJohn Levon VFIO_MSG_WAIT, 28438d863fSJohn Levon VFIO_MSG_NOWAIT, 29438d863fSJohn Levon VFIO_MSG_REQ, 30438d863fSJohn Levon }; 31438d863fSJohn Levon 32438d863fSJohn Levon typedef struct VFIOUserMsg { 33438d863fSJohn Levon QTAILQ_ENTRY(VFIOUserMsg) next; 34*0b3d881aSJohn Levon VFIOUserHdr *hdr; 35438d863fSJohn Levon VFIOUserFDs *fds; 36438d863fSJohn Levon uint32_t rsize; 37438d863fSJohn Levon uint32_t id; 38438d863fSJohn Levon QemuCond cv; 39438d863fSJohn Levon bool complete; 40438d863fSJohn Levon enum msg_type type; 41438d863fSJohn Levon } VFIOUserMsg; 42438d863fSJohn Levon 43438d863fSJohn Levon 44438d863fSJohn Levon enum proxy_state { 45438d863fSJohn Levon VFIO_PROXY_CONNECTED = 1, 46438d863fSJohn Levon VFIO_PROXY_ERROR = 2, 47438d863fSJohn Levon VFIO_PROXY_CLOSING = 3, 48438d863fSJohn Levon VFIO_PROXY_CLOSED = 4, 49438d863fSJohn Levon }; 50438d863fSJohn Levon 51438d863fSJohn Levon typedef QTAILQ_HEAD(VFIOUserMsgQ, VFIOUserMsg) VFIOUserMsgQ; 52438d863fSJohn Levon 53438d863fSJohn Levon typedef struct VFIOUserProxy { 54438d863fSJohn Levon QLIST_ENTRY(VFIOUserProxy) next; 55438d863fSJohn Levon char *sockname; 56438d863fSJohn Levon struct QIOChannel *ioc; 57438d863fSJohn Levon void (*request)(void *opaque, VFIOUserMsg *msg); 58438d863fSJohn Levon void *req_arg; 59438d863fSJohn Levon int flags; 60438d863fSJohn Levon QemuCond close_cv; 61438d863fSJohn Levon AioContext *ctx; 62438d863fSJohn Levon QEMUBH *req_bh; 63438d863fSJohn Levon 64438d863fSJohn Levon /* 65438d863fSJohn Levon * above only changed when BQL is held 66438d863fSJohn Levon * below are protected by per-proxy lock 67438d863fSJohn Levon */ 68438d863fSJohn Levon QemuMutex lock; 69438d863fSJohn Levon VFIOUserMsgQ free; 70438d863fSJohn Levon VFIOUserMsgQ pending; 71438d863fSJohn Levon VFIOUserMsgQ incoming; 72438d863fSJohn Levon VFIOUserMsgQ outgoing; 73438d863fSJohn Levon VFIOUserMsg *last_nowait; 74*0b3d881aSJohn Levon VFIOUserMsg *part_recv; 75*0b3d881aSJohn Levon size_t recv_left; 76438d863fSJohn Levon enum proxy_state state; 77438d863fSJohn Levon } VFIOUserProxy; 78438d863fSJohn Levon 79438d863fSJohn Levon /* VFIOProxy flags */ 80438d863fSJohn Levon #define VFIO_PROXY_CLIENT 0x1 81438d863fSJohn Levon 82*0b3d881aSJohn Levon typedef struct VFIODevice VFIODevice; 83*0b3d881aSJohn Levon 84438d863fSJohn Levon VFIOUserProxy *vfio_user_connect_dev(SocketAddress *addr, Error **errp); 85438d863fSJohn Levon void vfio_user_disconnect(VFIOUserProxy *proxy); 86*0b3d881aSJohn Levon void vfio_user_set_handler(VFIODevice *vbasedev, 87*0b3d881aSJohn Levon void (*handler)(void *opaque, VFIOUserMsg *msg), 88*0b3d881aSJohn Levon void *reqarg); 89438d863fSJohn Levon 90438d863fSJohn Levon #endif /* VFIO_USER_PROXY_H */ 91