github.com/sagernet/gvisor@v0.0.0-20240428053021-e691de28565f/pkg/abi/linux/vfio.go (about) 1 // Copyright 2024 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // The package implements VFIOuserspace driver interface. 16 17 package linux 18 19 // For IOCTLs requests from include/uapi/linux/vfio.h. 20 const ( 21 VFIO_TYPE = ';' 22 VFIO_BASE = 100 23 24 // VFIO extensions. 25 VFIO_TYPE1_IOMMU = 1 26 VFIO_SPAPR_TCE_IOMMU = 2 27 VFIO_TYPE1v2_IOMMU = 3 28 ) 29 30 // VFIO device info flags. 31 const ( 32 // Device supports reset. 33 VFIO_DEVICE_FLAGS_RESET = 1 << iota 34 // VFIO-pci device. 35 VFIO_DEVICE_FLAGS_PCI 36 // VFIO-platform device. 37 VFIO_DEVICE_FLAGS_PLATFORM 38 // VFIO-amba device. 39 VFIO_DEVICE_FLAGS_AMBA 40 // VFIO-ccw device. 41 VFIO_DEVICE_FLAGS_CCW 42 // VFIO-ap device. 43 VFIO_DEVICE_FLAGS_AP 44 // VFIO-fsl-mc device. 45 VFIO_DEVICE_FLAGS_FSL_MC 46 // Info supports caps. 47 VFIO_DEVICE_FLAGS_CAPS 48 // VFIO-cdx device. 49 VFIO_DEVICE_FLAGS_CDX 50 ) 51 52 // VFIO region info flags. 53 const ( 54 // Region supports read. 55 VFIO_REGION_INFO_FLAG_READ = 1 << iota 56 // Region supports write. 57 VFIO_REGION_INFO_FLAG_WRITE 58 // Region supports mmap. 59 VFIO_REGION_INFO_FLAG_MMAP 60 // Info supports caps. 61 VFIO_REGION_INFO_FLAG_CAPS 62 ) 63 64 // VFIOIrqInfo flags. 65 const ( 66 VFIO_IRQ_INFO_EVENTFD = 1 << iota 67 VFIO_IRQ_INFO_MASKABLE 68 VFIO_IRQ_INFO_AUTOMASKED 69 VFIO_IRQ_INFO_NORESIZE 70 ) 71 72 // VFIOIrqSet flags. 73 const ( 74 VFIO_IRQ_SET_DATA_NONE = 1 << iota 75 VFIO_IRQ_SET_DATA_BOOL 76 VFIO_IRQ_SET_DATA_EVENTFD 77 VFIO_IRQ_SET_ACTION_MASK 78 VFIO_IRQ_SET_ACTION_UNMASK 79 VFIO_IRQ_SET_ACTION_TRIGGER 80 81 VFIO_IRQ_SET_DATA_TYPE_MASK = VFIO_IRQ_SET_DATA_NONE | 82 VFIO_IRQ_SET_DATA_BOOL | 83 VFIO_IRQ_SET_DATA_EVENTFD 84 VFIO_IRQ_SET_ACTION_TYPE_MASK = VFIO_IRQ_SET_ACTION_MASK | 85 VFIO_IRQ_SET_ACTION_UNMASK | 86 VFIO_IRQ_SET_ACTION_TRIGGER 87 ) 88 89 // VFIOIrqSet index. 90 const ( 91 VFIO_PCI_INTX_IRQ_INDEX = iota 92 VFIO_PCI_MSI_IRQ_INDEX 93 VFIO_PCI_MSIX_IRQ_INDEX 94 VFIO_PCI_ERR_IRQ_INDEX 95 VFIO_PCI_REQ_IRQ_INDEX 96 VFIO_PCI_NUM_IRQS 97 ) 98 99 // VFIOIommuType1DmaMap flags. 100 const ( 101 // Readable from device. 102 VFIO_DMA_MAP_FLAG_READ = 1 << iota 103 // Writable from device. 104 VFIO_DMA_MAP_FLAG_WRITE 105 // Update the device's virtual address. 106 VFIO_DMA_MAP_FLAG_VADDR 107 ) 108 109 const ( 110 VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP = 1 111 ) 112 113 // IOCTLs for VFIO file descriptor from include/uapi/linux/vfio.h. 114 var ( 115 VFIO_CHECK_EXTENSION = IO(VFIO_TYPE, VFIO_BASE+1) 116 VFIO_SET_IOMMU = IO(VFIO_TYPE, VFIO_BASE+2) 117 VFIO_GROUP_SET_CONTAINER = IO(VFIO_TYPE, VFIO_BASE+4) 118 VFIO_GROUP_GET_DEVICE_FD = IO(VFIO_TYPE, VFIO_BASE+6) 119 VFIO_DEVICE_GET_INFO = IO(VFIO_TYPE, VFIO_BASE+7) 120 VFIO_DEVICE_GET_REGION_INFO = IO(VFIO_TYPE, VFIO_BASE+8) 121 VFIO_DEVICE_GET_IRQ_INFO = IO(VFIO_TYPE, VFIO_BASE+9) 122 VFIO_DEVICE_SET_IRQS = IO(VFIO_TYPE, VFIO_BASE+10) 123 VFIO_DEVICE_RESET = IO(VFIO_TYPE, VFIO_BASE+11) 124 VFIO_IOMMU_MAP_DMA = IO(VFIO_TYPE, VFIO_BASE+13) 125 VFIO_IOMMU_UNMAP_DMA = IO(VFIO_TYPE, VFIO_BASE+14) 126 ) 127 128 // VFIODeviceInfo is analogous to vfio_device_info 129 // from include/uapi/linux/vfio.h. 130 // 131 // +marshal 132 type VFIODeviceInfo struct { 133 Argsz uint32 134 Flags uint32 135 // The total amount of regions. 136 NumRegions uint32 137 // The maximum number of IRQ. 138 NumIrqs uint32 139 // Offset within info struct of first cap. 140 CapOffset uint32 141 pad uint32 142 } 143 144 // VFIORegionInfo is analogous to vfio_region_info 145 // from include/uapi/linux/vfio.h. 146 // 147 // +marshal 148 type VFIORegionInfo struct { 149 Argsz uint32 150 Flags uint32 151 Index uint32 152 // Offset within info struct of first cap. 153 capOffset uint32 154 // Region size in bytes. 155 Size uint64 156 // Region offset from start of device fd. 157 Offset uint64 158 } 159 160 // VFIOIrqInfo is analogous to vfio_irq_info 161 // from include/uapi/linux/vfio.h. 162 // 163 // +marshal 164 type VFIOIrqInfo struct { 165 Argsz uint32 166 Flags uint32 167 Index uint32 168 Count uint32 169 } 170 171 // VFIOIrqSet is analogous to vfio_irq_set 172 // from include/uapi/linux/vfio.h. 173 // The last field `data` from vfio_irq_set is omitted which is an 174 // flexible array member. It will be handled separately. 175 // 176 // +marshal 177 type VFIOIrqSet struct { 178 Argsz uint32 179 Flags uint32 180 Index uint32 181 Start uint32 182 Count uint32 183 } 184 185 // VFIOIommuType1DmaMap is analogous to vfio_iommu_type1_dma_map 186 // from include/uapi/linux/vfio.h. 187 // 188 // +marshal 189 type VFIOIommuType1DmaMap struct { 190 Argsz uint32 191 Flags uint32 192 // Process virtual address. 193 Vaddr uint64 194 // IO virtual address. 195 IOVa uint64 196 // Size of mapping in bytes. 197 Size uint64 198 } 199 200 // VFIOIommuType1DmaUnmap is analogous to vfio_iommu_type1_dma_unmap 201 // from include/uapi/linux/vfio.h. 202 // 203 // +marshal 204 type VFIOIommuType1DmaUnmap struct { 205 Argsz uint32 206 Flags uint32 207 // IO virtual address. 208 IOVa uint64 209 // Size of mapping in bytes. 210 Size uint64 211 // The `data` field from vfio_iommu_type1_dma_unmap is omitted. The 212 // field is a flexible array member, and is needed only if the flag 213 // VFIO_DMA_UNMAP_FLAG_GET_DIRTY_BITMAP is enabled. 214 }