1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (C) 2020 Intel Corporation. 3 * All rights reserved. 4 */ 5 6 #ifndef _VFIO_USER_SPEC_H 7 #define _VFIO_USER_SPEC_H 8 9 #include "spdk/stdinc.h" 10 11 #ifdef __cplusplus 12 extern "C" { 13 #endif 14 15 enum vfio_user_command { 16 VFIO_USER_VERSION = 1, 17 VFIO_USER_DMA_MAP = 2, 18 VFIO_USER_DMA_UNMAP = 3, 19 VFIO_USER_DEVICE_GET_INFO = 4, 20 VFIO_USER_DEVICE_GET_REGION_INFO = 5, 21 VFIO_USER_DEVICE_GET_REGION_IO_FDS = 6, 22 VFIO_USER_DEVICE_GET_IRQ_INFO = 7, 23 VFIO_USER_DEVICE_SET_IRQS = 8, 24 VFIO_USER_REGION_READ = 9, 25 VFIO_USER_REGION_WRITE = 10, 26 VFIO_USER_DMA_READ = 11, 27 VFIO_USER_DMA_WRITE = 12, 28 VFIO_USER_DEVICE_RESET = 13, 29 VFIO_USER_DIRTY_PAGES = 14, 30 VFIO_USER_MAX, 31 }; 32 33 enum vfio_user_message_type { 34 VFIO_USER_MESSAGE_COMMAND = 0, 35 VFIO_USER_MESSAGE_REPLY = 1, 36 }; 37 38 #define VFIO_USER_FLAGS_NO_REPLY (0x1) 39 40 struct vfio_user_header { 41 uint16_t msg_id; 42 uint16_t cmd; 43 uint32_t msg_size; 44 struct { 45 uint32_t type : 4; 46 #define VFIO_USER_F_TYPE_COMMAND 0 47 #define VFIO_USER_F_TYPE_REPLY 1 48 uint32_t no_reply : 1; 49 uint32_t error : 1; 50 uint32_t resvd : 26; 51 } flags; 52 uint32_t error_no; 53 } __attribute__((packed)); 54 55 struct vfio_user_version { 56 uint16_t major; 57 uint16_t minor; 58 uint8_t data[]; 59 } __attribute__((packed)); 60 61 /* 62 * Similar to vfio_device_info, but without caps (yet). 63 */ 64 struct vfio_user_device_info { 65 uint32_t argsz; 66 /* VFIO_DEVICE_FLAGS_* */ 67 uint32_t flags; 68 uint32_t num_regions; 69 uint32_t num_irqs; 70 } __attribute__((packed)); 71 72 /* based on struct vfio_bitmap */ 73 struct vfio_user_bitmap { 74 uint64_t pgsize; 75 uint64_t size; 76 char data[]; 77 } __attribute__((packed)); 78 79 /* based on struct vfio_iommu_type1_dma_map */ 80 struct vfio_user_dma_map { 81 uint32_t argsz; 82 #define VFIO_USER_F_DMA_REGION_READ (1 << 0) 83 #define VFIO_USER_F_DMA_REGION_WRITE (1 << 1) 84 uint32_t flags; 85 uint64_t offset; 86 uint64_t addr; 87 uint64_t size; 88 } __attribute__((packed)); 89 90 /* based on struct vfio_iommu_type1_dma_unmap */ 91 struct vfio_user_dma_unmap { 92 uint32_t argsz; 93 #ifndef VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP 94 #define VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP (1 << 0) 95 #endif 96 uint32_t flags; 97 uint64_t addr; 98 uint64_t size; 99 struct vfio_user_bitmap bitmap[]; 100 }; 101 102 struct vfio_user_region_access { 103 uint64_t offset; 104 uint32_t region; 105 uint32_t count; 106 uint8_t data[]; 107 } __attribute__((packed)); 108 109 struct vfio_user_dma_region_access { 110 uint64_t addr; 111 uint64_t count; 112 uint8_t data[]; 113 } __attribute__((packed)); 114 115 struct vfio_user_irq_info { 116 uint32_t subindex; 117 } __attribute__((packed)); 118 119 /* based on struct vfio_iommu_type1_dirty_bitmap_get */ 120 struct vfio_user_bitmap_range { 121 uint64_t iova; 122 uint64_t size; 123 struct vfio_user_bitmap bitmap; 124 } __attribute__((packed)); 125 126 127 #ifdef __cplusplus 128 } 129 #endif 130 131 #endif 132