Merge tag 'v9.1.0'
[qemu/ar7.git] / include / hw / remote / mpqemu-link.h
blob4ec091588519ba320bbf508f34dca1ddd17cac4d
1 /*
2 * Communication channel between QEMU and remote device process
4 * Copyright © 2018, 2021 Oracle and/or its affiliates.
6 * This work is licensed under the terms of the GNU GPL, version 2 or later.
7 * See the COPYING file in the top-level directory.
9 */
11 #ifndef MPQEMU_LINK_H
12 #define MPQEMU_LINK_H
14 #include "qom/object.h"
15 #include "qemu/thread.h"
16 #include "io/channel.h"
17 #include "exec/hwaddr.h"
18 #include "io/channel-socket.h"
19 #include "hw/remote/proxy.h"
21 #define REMOTE_MAX_FDS 8
23 #define MPQEMU_MSG_HDR_SIZE offsetof(MPQemuMsg, data.u64)
25 /**
26 * MPQemuCmd:
28 * MPQemuCmd enum type to specify the command to be executed on the remote
29 * device.
31 * This uses a private protocol between QEMU and the remote process. vfio-user
32 * protocol would supersede this in the future.
35 typedef enum {
36 MPQEMU_CMD_SYNC_SYSMEM,
37 MPQEMU_CMD_RET,
38 MPQEMU_CMD_PCI_CFGWRITE,
39 MPQEMU_CMD_PCI_CFGREAD,
40 MPQEMU_CMD_BAR_WRITE,
41 MPQEMU_CMD_BAR_READ,
42 MPQEMU_CMD_SET_IRQFD,
43 MPQEMU_CMD_DEVICE_RESET,
44 MPQEMU_CMD_MAX,
45 } MPQemuCmd;
47 typedef struct {
48 hwaddr gpas[REMOTE_MAX_FDS];
49 uint64_t sizes[REMOTE_MAX_FDS];
50 off_t offsets[REMOTE_MAX_FDS];
51 } SyncSysmemMsg;
53 typedef struct {
54 uint32_t addr;
55 uint32_t val;
56 int len;
57 } PciConfDataMsg;
59 typedef struct {
60 hwaddr addr;
61 uint64_t val;
62 unsigned size;
63 bool memory;
64 } BarAccessMsg;
66 /**
67 * MPQemuMsg:
68 * @cmd: The remote command
69 * @size: Size of the data to be shared
70 * @data: Structured data
71 * @fds: File descriptors to be shared with remote device
73 * MPQemuMsg Format of the message sent to the remote device from QEMU.
77 typedef struct {
78 int cmd;
79 size_t size;
81 union {
82 uint64_t u64;
83 PciConfDataMsg pci_conf_data;
84 SyncSysmemMsg sync_sysmem;
85 BarAccessMsg bar_access;
86 } data;
88 int fds[REMOTE_MAX_FDS];
89 int num_fds;
90 } MPQemuMsg;
92 bool mpqemu_msg_send(MPQemuMsg *msg, QIOChannel *ioc, Error **errp);
93 bool mpqemu_msg_recv(MPQemuMsg *msg, QIOChannel *ioc, Error **errp);
95 uint64_t mpqemu_msg_send_and_await_reply(MPQemuMsg *msg, PCIProxyDev *pdev,
96 Error **errp);
97 bool mpqemu_msg_valid(MPQemuMsg *msg);
99 #endif