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 150b3d881aSJohn Levon #include "qemu/sockets.h" 160b3d881aSJohn Levon #include "hw/vfio-user/protocol.h" 170b3d881aSJohn 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; 340b3d881aSJohn 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; 40*36227628SJohn Levon bool pending; 41438d863fSJohn Levon enum msg_type type; 42438d863fSJohn Levon } VFIOUserMsg; 43438d863fSJohn Levon 44438d863fSJohn Levon 45438d863fSJohn Levon enum proxy_state { 46438d863fSJohn Levon VFIO_PROXY_CONNECTED = 1, 47438d863fSJohn Levon VFIO_PROXY_ERROR = 2, 48438d863fSJohn Levon VFIO_PROXY_CLOSING = 3, 49438d863fSJohn Levon VFIO_PROXY_CLOSED = 4, 50438d863fSJohn Levon }; 51438d863fSJohn Levon 52438d863fSJohn Levon typedef QTAILQ_HEAD(VFIOUserMsgQ, VFIOUserMsg) VFIOUserMsgQ; 53438d863fSJohn Levon 54438d863fSJohn Levon typedef struct VFIOUserProxy { 55438d863fSJohn Levon QLIST_ENTRY(VFIOUserProxy) next; 56438d863fSJohn Levon char *sockname; 57438d863fSJohn Levon struct QIOChannel *ioc; 58438d863fSJohn Levon void (*request)(void *opaque, VFIOUserMsg *msg); 59438d863fSJohn Levon void *req_arg; 60*36227628SJohn Levon uint64_t max_xfer_size; 61*36227628SJohn Levon uint64_t max_send_fds; 62*36227628SJohn Levon uint64_t max_dma; 63*36227628SJohn Levon uint64_t dma_pgsizes; 64*36227628SJohn Levon uint64_t max_bitmap; 65*36227628SJohn Levon uint64_t migr_pgsize; 66438d863fSJohn Levon int flags; 67438d863fSJohn Levon QemuCond close_cv; 68438d863fSJohn Levon AioContext *ctx; 69438d863fSJohn Levon QEMUBH *req_bh; 70438d863fSJohn Levon 71438d863fSJohn Levon /* 72438d863fSJohn Levon * above only changed when BQL is held 73438d863fSJohn Levon * below are protected by per-proxy lock 74438d863fSJohn Levon */ 75438d863fSJohn Levon QemuMutex lock; 76438d863fSJohn Levon VFIOUserMsgQ free; 77438d863fSJohn Levon VFIOUserMsgQ pending; 78438d863fSJohn Levon VFIOUserMsgQ incoming; 79438d863fSJohn Levon VFIOUserMsgQ outgoing; 80438d863fSJohn Levon VFIOUserMsg *last_nowait; 810b3d881aSJohn Levon VFIOUserMsg *part_recv; 820b3d881aSJohn Levon size_t recv_left; 83438d863fSJohn Levon enum proxy_state state; 84438d863fSJohn Levon } VFIOUserProxy; 85438d863fSJohn Levon 86438d863fSJohn Levon /* VFIOProxy flags */ 87438d863fSJohn Levon #define VFIO_PROXY_CLIENT 0x1 88*36227628SJohn Levon #define VFIO_PROXY_FORCE_QUEUED 0x4 89438d863fSJohn Levon 900b3d881aSJohn Levon typedef struct VFIODevice VFIODevice; 910b3d881aSJohn Levon 92438d863fSJohn Levon VFIOUserProxy *vfio_user_connect_dev(SocketAddress *addr, Error **errp); 93438d863fSJohn Levon void vfio_user_disconnect(VFIOUserProxy *proxy); 940b3d881aSJohn Levon void vfio_user_set_handler(VFIODevice *vbasedev, 950b3d881aSJohn Levon void (*handler)(void *opaque, VFIOUserMsg *msg), 960b3d881aSJohn Levon void *reqarg); 97*36227628SJohn Levon bool vfio_user_validate_version(VFIOUserProxy *proxy, Error **errp); 98438d863fSJohn Levon 99438d863fSJohn Levon #endif /* VFIO_USER_PROXY_H */ 100