qemu/include/hw/remote/mpqemu-link.h
<<
>>
Prefs
   1/*
   2 * Communication channel between QEMU and remote device process
   3 *
   4 * Copyright © 2018, 2021 Oracle and/or its affiliates.
   5 *
   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.
   8 *
   9 */
  10
  11#ifndef MPQEMU_LINK_H
  12#define MPQEMU_LINK_H
  13
  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"
  20
  21#define REMOTE_MAX_FDS 8
  22
  23#define MPQEMU_MSG_HDR_SIZE offsetof(MPQemuMsg, data.u64)
  24
  25/**
  26 * MPQemuCmd:
  27 *
  28 * MPQemuCmd enum type to specify the command to be executed on the remote
  29 * device.
  30 *
  31 * This uses a private protocol between QEMU and the remote process. vfio-user
  32 * protocol would supersede this in the future.
  33 *
  34 */
  35typedef 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;
  46
  47typedef struct {
  48    hwaddr gpas[REMOTE_MAX_FDS];
  49    uint64_t sizes[REMOTE_MAX_FDS];
  50    off_t offsets[REMOTE_MAX_FDS];
  51} SyncSysmemMsg;
  52
  53typedef struct {
  54    uint32_t addr;
  55    uint32_t val;
  56    int len;
  57} PciConfDataMsg;
  58
  59typedef struct {
  60    hwaddr addr;
  61    uint64_t val;
  62    unsigned size;
  63    bool memory;
  64} BarAccessMsg;
  65
  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
  72 *
  73 * MPQemuMsg Format of the message sent to the remote device from QEMU.
  74 *
  75 */
  76
  77typedef struct {
  78    int cmd;
  79    size_t size;
  80
  81    union {
  82        uint64_t u64;
  83        PciConfDataMsg pci_conf_data;
  84        SyncSysmemMsg sync_sysmem;
  85        BarAccessMsg bar_access;
  86    } data;
  87
  88    int fds[REMOTE_MAX_FDS];
  89    int num_fds;
  90} MPQemuMsg;
  91
  92bool mpqemu_msg_send(MPQemuMsg *msg, QIOChannel *ioc, Error **errp);
  93bool mpqemu_msg_recv(MPQemuMsg *msg, QIOChannel *ioc, Error **errp);
  94
  95uint64_t mpqemu_msg_send_and_await_reply(MPQemuMsg *msg, PCIProxyDev *pdev,
  96                                         Error **errp);
  97bool mpqemu_msg_valid(MPQemuMsg *msg);
  98
  99#endif
 100