Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vfio.h
Go to the documentation of this file.
1 /*
2  * VFIO API definition
3  *
4  * Copyright (C) 2012 Red Hat, Inc. All rights reserved.
5  * Author: Alex Williamson <[email protected]>
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  */
11 #ifndef _UAPIVFIO_H
12 #define _UAPIVFIO_H
13 
14 #include <linux/types.h>
15 #include <linux/ioctl.h>
16 
17 #define VFIO_API_VERSION 0
18 
19 
20 /* Kernel & User level defines for VFIO IOCTLs. */
21 
22 /* Extensions */
23 
24 #define VFIO_TYPE1_IOMMU 1
25 
26 /*
27  * The IOCTL interface is designed for extensibility by embedding the
28  * structure length (argsz) and flags into structures passed between
29  * kernel and userspace. We therefore use the _IO() macro for these
30  * defines to avoid implicitly embedding a size into the ioctl request.
31  * As structure fields are added, argsz will increase to match and flag
32  * bits will be defined to indicate additional fields with valid data.
33  * It's *always* the caller's responsibility to indicate the size of
34  * the structure passed by setting argsz appropriately.
35  */
36 
37 #define VFIO_TYPE (';')
38 #define VFIO_BASE 100
39 
40 /* -------- IOCTLs for VFIO file descriptor (/dev/vfio/vfio) -------- */
41 
51 #define VFIO_GET_API_VERSION _IO(VFIO_TYPE, VFIO_BASE + 0)
52 
60 #define VFIO_CHECK_EXTENSION _IO(VFIO_TYPE, VFIO_BASE + 1)
61 
73 #define VFIO_SET_IOMMU _IO(VFIO_TYPE, VFIO_BASE + 2)
74 
75 /* -------- IOCTLs for GROUP file descriptors (/dev/vfio/$GROUP) -------- */
76 
89 #define VFIO_GROUP_FLAGS_VIABLE (1 << 0)
90 #define VFIO_GROUP_FLAGS_CONTAINER_SET (1 << 1)
91 };
92 #define VFIO_GROUP_GET_STATUS _IO(VFIO_TYPE, VFIO_BASE + 3)
93 
106 #define VFIO_GROUP_SET_CONTAINER _IO(VFIO_TYPE, VFIO_BASE + 4)
107 
121 #define VFIO_GROUP_UNSET_CONTAINER _IO(VFIO_TYPE, VFIO_BASE + 5)
122 
133 #define VFIO_GROUP_GET_DEVICE_FD _IO(VFIO_TYPE, VFIO_BASE + 6)
134 
135 /* --------------- IOCTLs for DEVICE file descriptors --------------- */
136 
148 #define VFIO_DEVICE_FLAGS_RESET (1 << 0) /* Device supports reset */
149 #define VFIO_DEVICE_FLAGS_PCI (1 << 1) /* vfio-pci device */
150  __u32 num_regions; /* Max region index + 1 */
151  __u32 num_irqs; /* Max IRQ index + 1 */
152 };
153 #define VFIO_DEVICE_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 7)
154 
170 #define VFIO_REGION_INFO_FLAG_READ (1 << 0) /* Region supports read */
171 #define VFIO_REGION_INFO_FLAG_WRITE (1 << 1) /* Region supports write */
172 #define VFIO_REGION_INFO_FLAG_MMAP (1 << 2) /* Region supports mmap */
173  __u32 index; /* Region index */
174  __u32 resv; /* Reserved for alignment */
175  __u64 size; /* Region size (bytes) */
176  __u64 offset; /* Region offset from start of device fd */
177 };
178 #define VFIO_DEVICE_GET_REGION_INFO _IO(VFIO_TYPE, VFIO_BASE + 8)
179 
215 #define VFIO_IRQ_INFO_EVENTFD (1 << 0)
216 #define VFIO_IRQ_INFO_MASKABLE (1 << 1)
217 #define VFIO_IRQ_INFO_AUTOMASKED (1 << 2)
218 #define VFIO_IRQ_INFO_NORESIZE (1 << 3)
219  __u32 index; /* IRQ index */
220  __u32 count; /* Number of IRQs within this index */
221 };
222 #define VFIO_DEVICE_GET_IRQ_INFO _IO(VFIO_TYPE, VFIO_BASE + 9)
223 
262 struct vfio_irq_set {
265 #define VFIO_IRQ_SET_DATA_NONE (1 << 0) /* Data not present */
266 #define VFIO_IRQ_SET_DATA_BOOL (1 << 1) /* Data is bool (u8) */
267 #define VFIO_IRQ_SET_DATA_EVENTFD (1 << 2) /* Data is eventfd (s32) */
268 #define VFIO_IRQ_SET_ACTION_MASK (1 << 3) /* Mask interrupt */
269 #define VFIO_IRQ_SET_ACTION_UNMASK (1 << 4) /* Unmask interrupt */
270 #define VFIO_IRQ_SET_ACTION_TRIGGER (1 << 5) /* Trigger interrupt */
275 };
276 #define VFIO_DEVICE_SET_IRQS _IO(VFIO_TYPE, VFIO_BASE + 10)
277 
278 #define VFIO_IRQ_SET_DATA_TYPE_MASK (VFIO_IRQ_SET_DATA_NONE | \
279  VFIO_IRQ_SET_DATA_BOOL | \
280  VFIO_IRQ_SET_DATA_EVENTFD)
281 #define VFIO_IRQ_SET_ACTION_TYPE_MASK (VFIO_IRQ_SET_ACTION_MASK | \
282  VFIO_IRQ_SET_ACTION_UNMASK | \
283  VFIO_IRQ_SET_ACTION_TRIGGER)
284 
289 #define VFIO_DEVICE_RESET _IO(VFIO_TYPE, VFIO_BASE + 11)
290 
291 /*
292  * The VFIO-PCI bus driver makes use of the following fixed region and
293  * IRQ index mapping. Unimplemented regions return a size of zero.
294  * Unimplemented IRQ types return a count of zero.
295  */
296 
297 enum {
307 };
308 
309 enum {
314 };
315 
316 /* -------- API for Type1 VFIO IOMMU -------- */
317 
329 #define VFIO_IOMMU_INFO_PGSIZES (1 << 0) /* supported page sizes info */
330  __u64 iova_pgsizes; /* Bitmap of supported page sizes */
331 };
332 
333 #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
334 
344 #define VFIO_DMA_MAP_FLAG_READ (1 << 0) /* readable from device */
345 #define VFIO_DMA_MAP_FLAG_WRITE (1 << 1) /* writable from device */
346  __u64 vaddr; /* Process virtual address */
347  __u64 iova; /* IO virtual address */
348  __u64 size; /* Size of mapping (bytes) */
349 };
350 
351 #define VFIO_IOMMU_MAP_DMA _IO(VFIO_TYPE, VFIO_BASE + 13)
352 
362  __u64 iova; /* IO virtual address */
363  __u64 size; /* Size of mapping (bytes) */
364 };
365 
366 #define VFIO_IOMMU_UNMAP_DMA _IO(VFIO_TYPE, VFIO_BASE + 14)
367 
368 #endif /* _UAPIVFIO_H */