2
0

vhost.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
  2. #ifndef _LINUX_VHOST_H
  3. #define _LINUX_VHOST_H
  4. /* Userspace interface for in-kernel virtio accelerators. */
  5. /* vhost is used to reduce the number of system calls involved in virtio.
  6. *
  7. * Existing virtio net code is used in the guest without modification.
  8. *
  9. * This header includes interface used by userspace hypervisor for
  10. * device configuration.
  11. */
  12. #include <linux/vhost_types.h>
  13. #include <linux/types.h>
  14. #include <linux/ioctl.h>
  15. #define VHOST_FILE_UNBIND -1
  16. /* ioctls */
  17. #define VHOST_VIRTIO 0xAF
  18. /* Features bitmask for forward compatibility. Transport bits are used for
  19. * vhost specific features. */
  20. #define VHOST_GET_FEATURES _IOR(VHOST_VIRTIO, 0x00, __u64)
  21. #define VHOST_SET_FEATURES _IOW(VHOST_VIRTIO, 0x00, __u64)
  22. /* Set current process as the (exclusive) owner of this file descriptor. This
  23. * must be called before any other vhost command. Further calls to
  24. * VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */
  25. #define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01)
  26. /* Give up ownership, and reset the device to default values.
  27. * Allows subsequent call to VHOST_OWNER_SET to succeed. */
  28. #define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02)
  29. /* Set up/modify memory layout */
  30. #define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory)
  31. /* Write logging setup. */
  32. /* Memory writes can optionally be logged by setting bit at an offset
  33. * (calculated from the physical address) from specified log base.
  34. * The bit is set using an atomic 32 bit operation. */
  35. /* Set base address for logging. */
  36. #define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64)
  37. /* Specify an eventfd file descriptor to signal on log write. */
  38. #define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int)
  39. /* Ring setup. */
  40. /* Set number of descriptors in ring. This parameter can not
  41. * be modified while ring is running (bound to a device). */
  42. #define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state)
  43. /* Set addresses for the ring. */
  44. #define VHOST_SET_VRING_ADDR _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr)
  45. /* Base value where queue looks for available descriptors */
  46. #define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
  47. /* Get accessor: reads index, writes value in num */
  48. #define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x12, struct vhost_vring_state)
  49. /* Set the vring byte order in num. Valid values are VHOST_VRING_LITTLE_ENDIAN
  50. * or VHOST_VRING_BIG_ENDIAN (other values return -EINVAL).
  51. * The byte order cannot be changed while the device is active: trying to do so
  52. * returns -EBUSY.
  53. * This is a legacy only API that is simply ignored when VIRTIO_F_VERSION_1 is
  54. * set.
  55. * Not all kernel configurations support this ioctl, but all configurations that
  56. * support SET also support GET.
  57. */
  58. #define VHOST_VRING_LITTLE_ENDIAN 0
  59. #define VHOST_VRING_BIG_ENDIAN 1
  60. #define VHOST_SET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x13, struct vhost_vring_state)
  61. #define VHOST_GET_VRING_ENDIAN _IOW(VHOST_VIRTIO, 0x14, struct vhost_vring_state)
  62. /* The following ioctls use eventfd file descriptors to signal and poll
  63. * for events. */
  64. /* Set eventfd to poll for added buffers */
  65. #define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file)
  66. /* Set eventfd to signal when buffers have beed used */
  67. #define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file)
  68. /* Set eventfd to signal an error */
  69. #define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file)
  70. /* Set busy loop timeout (in us) */
  71. #define VHOST_SET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x23, \
  72. struct vhost_vring_state)
  73. /* Get busy loop timeout (in us) */
  74. #define VHOST_GET_VRING_BUSYLOOP_TIMEOUT _IOW(VHOST_VIRTIO, 0x24, \
  75. struct vhost_vring_state)
  76. /* Set or get vhost backend capability */
  77. /* Use message type V2 */
  78. #define VHOST_BACKEND_F_IOTLB_MSG_V2 0x1
  79. /* IOTLB can accept batching hints */
  80. #define VHOST_BACKEND_F_IOTLB_BATCH 0x2
  81. #define VHOST_SET_BACKEND_FEATURES _IOW(VHOST_VIRTIO, 0x25, __u64)
  82. #define VHOST_GET_BACKEND_FEATURES _IOR(VHOST_VIRTIO, 0x26, __u64)
  83. /* VHOST_NET specific defines */
  84. /* Attach virtio net ring to a raw socket, or tap device.
  85. * The socket must be already bound to an ethernet device, this device will be
  86. * used for transmit. Pass fd -1 to unbind from the socket and the transmit
  87. * device. This can be used to stop the ring (e.g. for migration). */
  88. #define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file)
  89. /* VHOST_SCSI specific defines */
  90. #define VHOST_SCSI_SET_ENDPOINT _IOW(VHOST_VIRTIO, 0x40, struct vhost_scsi_target)
  91. #define VHOST_SCSI_CLEAR_ENDPOINT _IOW(VHOST_VIRTIO, 0x41, struct vhost_scsi_target)
  92. /* Changing this breaks userspace. */
  93. #define VHOST_SCSI_GET_ABI_VERSION _IOW(VHOST_VIRTIO, 0x42, int)
  94. /* Set and get the events missed flag */
  95. #define VHOST_SCSI_SET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x43, __u32)
  96. #define VHOST_SCSI_GET_EVENTS_MISSED _IOW(VHOST_VIRTIO, 0x44, __u32)
  97. /* VHOST_VSOCK specific defines */
  98. #define VHOST_VSOCK_SET_GUEST_CID _IOW(VHOST_VIRTIO, 0x60, __u64)
  99. #define VHOST_VSOCK_SET_RUNNING _IOW(VHOST_VIRTIO, 0x61, int)
  100. /* VHOST_VDPA specific defines */
  101. /* Get the device id. The device ids follow the same definition of
  102. * the device id defined in virtio-spec.
  103. */
  104. #define VHOST_VDPA_GET_DEVICE_ID _IOR(VHOST_VIRTIO, 0x70, __u32)
  105. /* Get and set the status. The status bits follow the same definition
  106. * of the device status defined in virtio-spec.
  107. */
  108. #define VHOST_VDPA_GET_STATUS _IOR(VHOST_VIRTIO, 0x71, __u8)
  109. #define VHOST_VDPA_SET_STATUS _IOW(VHOST_VIRTIO, 0x72, __u8)
  110. /* Get and set the device config. The device config follows the same
  111. * definition of the device config defined in virtio-spec.
  112. */
  113. #define VHOST_VDPA_GET_CONFIG _IOR(VHOST_VIRTIO, 0x73, \
  114. struct vhost_vdpa_config)
  115. #define VHOST_VDPA_SET_CONFIG _IOW(VHOST_VIRTIO, 0x74, \
  116. struct vhost_vdpa_config)
  117. /* Enable/disable the ring. */
  118. #define VHOST_VDPA_SET_VRING_ENABLE _IOW(VHOST_VIRTIO, 0x75, \
  119. struct vhost_vring_state)
  120. /* Get the max ring size. */
  121. #define VHOST_VDPA_GET_VRING_NUM _IOR(VHOST_VIRTIO, 0x76, __u16)
  122. /* Set event fd for config interrupt*/
  123. #define VHOST_VDPA_SET_CONFIG_CALL _IOW(VHOST_VIRTIO, 0x77, int)
  124. #endif