mpqemu-link.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. #ifndef MPQEMU_LINK_H
  11. #define MPQEMU_LINK_H
  12. #include "qom/object.h"
  13. #include "qemu/thread.h"
  14. #include "io/channel.h"
  15. #include "exec/hwaddr.h"
  16. #include "io/channel-socket.h"
  17. #include "hw/remote/proxy.h"
  18. #define REMOTE_MAX_FDS 8
  19. #define MPQEMU_MSG_HDR_SIZE offsetof(MPQemuMsg, data.u64)
  20. /**
  21. * MPQemuCmd:
  22. *
  23. * MPQemuCmd enum type to specify the command to be executed on the remote
  24. * device.
  25. *
  26. * This uses a private protocol between QEMU and the remote process. vfio-user
  27. * protocol would supersede this in the future.
  28. *
  29. */
  30. typedef enum {
  31. MPQEMU_CMD_SYNC_SYSMEM,
  32. MPQEMU_CMD_RET,
  33. MPQEMU_CMD_PCI_CFGWRITE,
  34. MPQEMU_CMD_PCI_CFGREAD,
  35. MPQEMU_CMD_BAR_WRITE,
  36. MPQEMU_CMD_BAR_READ,
  37. MPQEMU_CMD_SET_IRQFD,
  38. MPQEMU_CMD_DEVICE_RESET,
  39. MPQEMU_CMD_MAX,
  40. } MPQemuCmd;
  41. typedef struct {
  42. hwaddr gpas[REMOTE_MAX_FDS];
  43. uint64_t sizes[REMOTE_MAX_FDS];
  44. off_t offsets[REMOTE_MAX_FDS];
  45. } SyncSysmemMsg;
  46. typedef struct {
  47. uint32_t addr;
  48. uint32_t val;
  49. int len;
  50. } PciConfDataMsg;
  51. typedef struct {
  52. hwaddr addr;
  53. uint64_t val;
  54. unsigned size;
  55. bool memory;
  56. } BarAccessMsg;
  57. /**
  58. * MPQemuMsg:
  59. * @cmd: The remote command
  60. * @size: Size of the data to be shared
  61. * @data: Structured data
  62. * @fds: File descriptors to be shared with remote device
  63. *
  64. * MPQemuMsg Format of the message sent to the remote device from QEMU.
  65. *
  66. */
  67. typedef struct {
  68. int cmd;
  69. size_t size;
  70. union {
  71. uint64_t u64;
  72. PciConfDataMsg pci_conf_data;
  73. SyncSysmemMsg sync_sysmem;
  74. BarAccessMsg bar_access;
  75. } data;
  76. int fds[REMOTE_MAX_FDS];
  77. int num_fds;
  78. } MPQemuMsg;
  79. bool mpqemu_msg_send(MPQemuMsg *msg, QIOChannel *ioc, Error **errp);
  80. bool mpqemu_msg_recv(MPQemuMsg *msg, QIOChannel *ioc, Error **errp);
  81. uint64_t mpqemu_msg_send_and_await_reply(MPQemuMsg *msg, PCIProxyDev *pdev,
  82. Error **errp);
  83. bool mpqemu_msg_valid(MPQemuMsg *msg);
  84. #endif