xref: /kvmtool/include/linux/vfio.h (revision b70d1b9fc0a9ac6c47b0b9ef2fe80bf3542b0bb3)
1*b70d1b9fSJean-Philippe Brucker /*
2*b70d1b9fSJean-Philippe Brucker  * VFIO API definition
3*b70d1b9fSJean-Philippe Brucker  *
4*b70d1b9fSJean-Philippe Brucker  * Copyright (C) 2012 Red Hat, Inc.  All rights reserved.
5*b70d1b9fSJean-Philippe Brucker  *     Author: Alex Williamson <alex.williamson@redhat.com>
6*b70d1b9fSJean-Philippe Brucker  *
7*b70d1b9fSJean-Philippe Brucker  * This program is free software; you can redistribute it and/or modify
8*b70d1b9fSJean-Philippe Brucker  * it under the terms of the GNU General Public License version 2 as
9*b70d1b9fSJean-Philippe Brucker  * published by the Free Software Foundation.
10*b70d1b9fSJean-Philippe Brucker  */
11*b70d1b9fSJean-Philippe Brucker #ifndef VFIO_H
12*b70d1b9fSJean-Philippe Brucker #define VFIO_H
13*b70d1b9fSJean-Philippe Brucker 
14*b70d1b9fSJean-Philippe Brucker #include <linux/types.h>
15*b70d1b9fSJean-Philippe Brucker #include <linux/ioctl.h>
16*b70d1b9fSJean-Philippe Brucker 
17*b70d1b9fSJean-Philippe Brucker #define VFIO_API_VERSION	0
18*b70d1b9fSJean-Philippe Brucker 
19*b70d1b9fSJean-Philippe Brucker 
20*b70d1b9fSJean-Philippe Brucker /* Kernel & User level defines for VFIO IOCTLs. */
21*b70d1b9fSJean-Philippe Brucker 
22*b70d1b9fSJean-Philippe Brucker /* Extensions */
23*b70d1b9fSJean-Philippe Brucker 
24*b70d1b9fSJean-Philippe Brucker #define VFIO_TYPE1_IOMMU		1
25*b70d1b9fSJean-Philippe Brucker #define VFIO_SPAPR_TCE_IOMMU		2
26*b70d1b9fSJean-Philippe Brucker #define VFIO_TYPE1v2_IOMMU		3
27*b70d1b9fSJean-Philippe Brucker /*
28*b70d1b9fSJean-Philippe Brucker  * IOMMU enforces DMA cache coherence (ex. PCIe NoSnoop stripping).  This
29*b70d1b9fSJean-Philippe Brucker  * capability is subject to change as groups are added or removed.
30*b70d1b9fSJean-Philippe Brucker  */
31*b70d1b9fSJean-Philippe Brucker #define VFIO_DMA_CC_IOMMU		4
32*b70d1b9fSJean-Philippe Brucker 
33*b70d1b9fSJean-Philippe Brucker /* Check if EEH is supported */
34*b70d1b9fSJean-Philippe Brucker #define VFIO_EEH			5
35*b70d1b9fSJean-Philippe Brucker 
36*b70d1b9fSJean-Philippe Brucker /* Two-stage IOMMU */
37*b70d1b9fSJean-Philippe Brucker #define VFIO_TYPE1_NESTING_IOMMU	6	/* Implies v2 */
38*b70d1b9fSJean-Philippe Brucker 
39*b70d1b9fSJean-Philippe Brucker #define VFIO_SPAPR_TCE_v2_IOMMU		7
40*b70d1b9fSJean-Philippe Brucker 
41*b70d1b9fSJean-Philippe Brucker /*
42*b70d1b9fSJean-Philippe Brucker  * The No-IOMMU IOMMU offers no translation or isolation for devices and
43*b70d1b9fSJean-Philippe Brucker  * supports no ioctls outside of VFIO_CHECK_EXTENSION.  Use of VFIO's No-IOMMU
44*b70d1b9fSJean-Philippe Brucker  * code will taint the host kernel and should be used with extreme caution.
45*b70d1b9fSJean-Philippe Brucker  */
46*b70d1b9fSJean-Philippe Brucker #define VFIO_NOIOMMU_IOMMU		8
47*b70d1b9fSJean-Philippe Brucker 
48*b70d1b9fSJean-Philippe Brucker /*
49*b70d1b9fSJean-Philippe Brucker  * The IOCTL interface is designed for extensibility by embedding the
50*b70d1b9fSJean-Philippe Brucker  * structure length (argsz) and flags into structures passed between
51*b70d1b9fSJean-Philippe Brucker  * kernel and userspace.  We therefore use the _IO() macro for these
52*b70d1b9fSJean-Philippe Brucker  * defines to avoid implicitly embedding a size into the ioctl request.
53*b70d1b9fSJean-Philippe Brucker  * As structure fields are added, argsz will increase to match and flag
54*b70d1b9fSJean-Philippe Brucker  * bits will be defined to indicate additional fields with valid data.
55*b70d1b9fSJean-Philippe Brucker  * It's *always* the caller's responsibility to indicate the size of
56*b70d1b9fSJean-Philippe Brucker  * the structure passed by setting argsz appropriately.
57*b70d1b9fSJean-Philippe Brucker  */
58*b70d1b9fSJean-Philippe Brucker 
59*b70d1b9fSJean-Philippe Brucker #define VFIO_TYPE	(';')
60*b70d1b9fSJean-Philippe Brucker #define VFIO_BASE	100
61*b70d1b9fSJean-Philippe Brucker 
62*b70d1b9fSJean-Philippe Brucker /*
63*b70d1b9fSJean-Philippe Brucker  * For extension of INFO ioctls, VFIO makes use of a capability chain
64*b70d1b9fSJean-Philippe Brucker  * designed after PCI/e capabilities.  A flag bit indicates whether
65*b70d1b9fSJean-Philippe Brucker  * this capability chain is supported and a field defined in the fixed
66*b70d1b9fSJean-Philippe Brucker  * structure defines the offset of the first capability in the chain.
67*b70d1b9fSJean-Philippe Brucker  * This field is only valid when the corresponding bit in the flags
68*b70d1b9fSJean-Philippe Brucker  * bitmap is set.  This offset field is relative to the start of the
69*b70d1b9fSJean-Philippe Brucker  * INFO buffer, as is the next field within each capability header.
70*b70d1b9fSJean-Philippe Brucker  * The id within the header is a shared address space per INFO ioctl,
71*b70d1b9fSJean-Philippe Brucker  * while the version field is specific to the capability id.  The
72*b70d1b9fSJean-Philippe Brucker  * contents following the header are specific to the capability id.
73*b70d1b9fSJean-Philippe Brucker  */
74*b70d1b9fSJean-Philippe Brucker struct vfio_info_cap_header {
75*b70d1b9fSJean-Philippe Brucker 	__u16	id;		/* Identifies capability */
76*b70d1b9fSJean-Philippe Brucker 	__u16	version;	/* Version specific to the capability ID */
77*b70d1b9fSJean-Philippe Brucker 	__u32	next;		/* Offset of next capability */
78*b70d1b9fSJean-Philippe Brucker };
79*b70d1b9fSJean-Philippe Brucker 
80*b70d1b9fSJean-Philippe Brucker /*
81*b70d1b9fSJean-Philippe Brucker  * Callers of INFO ioctls passing insufficiently sized buffers will see
82*b70d1b9fSJean-Philippe Brucker  * the capability chain flag bit set, a zero value for the first capability
83*b70d1b9fSJean-Philippe Brucker  * offset (if available within the provided argsz), and argsz will be
84*b70d1b9fSJean-Philippe Brucker  * updated to report the necessary buffer size.  For compatibility, the
85*b70d1b9fSJean-Philippe Brucker  * INFO ioctl will not report error in this case, but the capability chain
86*b70d1b9fSJean-Philippe Brucker  * will not be available.
87*b70d1b9fSJean-Philippe Brucker  */
88*b70d1b9fSJean-Philippe Brucker 
89*b70d1b9fSJean-Philippe Brucker /* -------- IOCTLs for VFIO file descriptor (/dev/vfio/vfio) -------- */
90*b70d1b9fSJean-Philippe Brucker 
91*b70d1b9fSJean-Philippe Brucker /**
92*b70d1b9fSJean-Philippe Brucker  * VFIO_GET_API_VERSION - _IO(VFIO_TYPE, VFIO_BASE + 0)
93*b70d1b9fSJean-Philippe Brucker  *
94*b70d1b9fSJean-Philippe Brucker  * Report the version of the VFIO API.  This allows us to bump the entire
95*b70d1b9fSJean-Philippe Brucker  * API version should we later need to add or change features in incompatible
96*b70d1b9fSJean-Philippe Brucker  * ways.
97*b70d1b9fSJean-Philippe Brucker  * Return: VFIO_API_VERSION
98*b70d1b9fSJean-Philippe Brucker  * Availability: Always
99*b70d1b9fSJean-Philippe Brucker  */
100*b70d1b9fSJean-Philippe Brucker #define VFIO_GET_API_VERSION		_IO(VFIO_TYPE, VFIO_BASE + 0)
101*b70d1b9fSJean-Philippe Brucker 
102*b70d1b9fSJean-Philippe Brucker /**
103*b70d1b9fSJean-Philippe Brucker  * VFIO_CHECK_EXTENSION - _IOW(VFIO_TYPE, VFIO_BASE + 1, __u32)
104*b70d1b9fSJean-Philippe Brucker  *
105*b70d1b9fSJean-Philippe Brucker  * Check whether an extension is supported.
106*b70d1b9fSJean-Philippe Brucker  * Return: 0 if not supported, 1 (or some other positive integer) if supported.
107*b70d1b9fSJean-Philippe Brucker  * Availability: Always
108*b70d1b9fSJean-Philippe Brucker  */
109*b70d1b9fSJean-Philippe Brucker #define VFIO_CHECK_EXTENSION		_IO(VFIO_TYPE, VFIO_BASE + 1)
110*b70d1b9fSJean-Philippe Brucker 
111*b70d1b9fSJean-Philippe Brucker /**
112*b70d1b9fSJean-Philippe Brucker  * VFIO_SET_IOMMU - _IOW(VFIO_TYPE, VFIO_BASE + 2, __s32)
113*b70d1b9fSJean-Philippe Brucker  *
114*b70d1b9fSJean-Philippe Brucker  * Set the iommu to the given type.  The type must be supported by an
115*b70d1b9fSJean-Philippe Brucker  * iommu driver as verified by calling CHECK_EXTENSION using the same
116*b70d1b9fSJean-Philippe Brucker  * type.  A group must be set to this file descriptor before this
117*b70d1b9fSJean-Philippe Brucker  * ioctl is available.  The IOMMU interfaces enabled by this call are
118*b70d1b9fSJean-Philippe Brucker  * specific to the value set.
119*b70d1b9fSJean-Philippe Brucker  * Return: 0 on success, -errno on failure
120*b70d1b9fSJean-Philippe Brucker  * Availability: When VFIO group attached
121*b70d1b9fSJean-Philippe Brucker  */
122*b70d1b9fSJean-Philippe Brucker #define VFIO_SET_IOMMU			_IO(VFIO_TYPE, VFIO_BASE + 2)
123*b70d1b9fSJean-Philippe Brucker 
124*b70d1b9fSJean-Philippe Brucker /* -------- IOCTLs for GROUP file descriptors (/dev/vfio/$GROUP) -------- */
125*b70d1b9fSJean-Philippe Brucker 
126*b70d1b9fSJean-Philippe Brucker /**
127*b70d1b9fSJean-Philippe Brucker  * VFIO_GROUP_GET_STATUS - _IOR(VFIO_TYPE, VFIO_BASE + 3,
128*b70d1b9fSJean-Philippe Brucker  *						struct vfio_group_status)
129*b70d1b9fSJean-Philippe Brucker  *
130*b70d1b9fSJean-Philippe Brucker  * Retrieve information about the group.  Fills in provided
131*b70d1b9fSJean-Philippe Brucker  * struct vfio_group_info.  Caller sets argsz.
132*b70d1b9fSJean-Philippe Brucker  * Return: 0 on succes, -errno on failure.
133*b70d1b9fSJean-Philippe Brucker  * Availability: Always
134*b70d1b9fSJean-Philippe Brucker  */
135*b70d1b9fSJean-Philippe Brucker struct vfio_group_status {
136*b70d1b9fSJean-Philippe Brucker 	__u32	argsz;
137*b70d1b9fSJean-Philippe Brucker 	__u32	flags;
138*b70d1b9fSJean-Philippe Brucker #define VFIO_GROUP_FLAGS_VIABLE		(1 << 0)
139*b70d1b9fSJean-Philippe Brucker #define VFIO_GROUP_FLAGS_CONTAINER_SET	(1 << 1)
140*b70d1b9fSJean-Philippe Brucker };
141*b70d1b9fSJean-Philippe Brucker #define VFIO_GROUP_GET_STATUS		_IO(VFIO_TYPE, VFIO_BASE + 3)
142*b70d1b9fSJean-Philippe Brucker 
143*b70d1b9fSJean-Philippe Brucker /**
144*b70d1b9fSJean-Philippe Brucker  * VFIO_GROUP_SET_CONTAINER - _IOW(VFIO_TYPE, VFIO_BASE + 4, __s32)
145*b70d1b9fSJean-Philippe Brucker  *
146*b70d1b9fSJean-Philippe Brucker  * Set the container for the VFIO group to the open VFIO file
147*b70d1b9fSJean-Philippe Brucker  * descriptor provided.  Groups may only belong to a single
148*b70d1b9fSJean-Philippe Brucker  * container.  Containers may, at their discretion, support multiple
149*b70d1b9fSJean-Philippe Brucker  * groups.  Only when a container is set are all of the interfaces
150*b70d1b9fSJean-Philippe Brucker  * of the VFIO file descriptor and the VFIO group file descriptor
151*b70d1b9fSJean-Philippe Brucker  * available to the user.
152*b70d1b9fSJean-Philippe Brucker  * Return: 0 on success, -errno on failure.
153*b70d1b9fSJean-Philippe Brucker  * Availability: Always
154*b70d1b9fSJean-Philippe Brucker  */
155*b70d1b9fSJean-Philippe Brucker #define VFIO_GROUP_SET_CONTAINER	_IO(VFIO_TYPE, VFIO_BASE + 4)
156*b70d1b9fSJean-Philippe Brucker 
157*b70d1b9fSJean-Philippe Brucker /**
158*b70d1b9fSJean-Philippe Brucker  * VFIO_GROUP_UNSET_CONTAINER - _IO(VFIO_TYPE, VFIO_BASE + 5)
159*b70d1b9fSJean-Philippe Brucker  *
160*b70d1b9fSJean-Philippe Brucker  * Remove the group from the attached container.  This is the
161*b70d1b9fSJean-Philippe Brucker  * opposite of the SET_CONTAINER call and returns the group to
162*b70d1b9fSJean-Philippe Brucker  * an initial state.  All device file descriptors must be released
163*b70d1b9fSJean-Philippe Brucker  * prior to calling this interface.  When removing the last group
164*b70d1b9fSJean-Philippe Brucker  * from a container, the IOMMU will be disabled and all state lost,
165*b70d1b9fSJean-Philippe Brucker  * effectively also returning the VFIO file descriptor to an initial
166*b70d1b9fSJean-Philippe Brucker  * state.
167*b70d1b9fSJean-Philippe Brucker  * Return: 0 on success, -errno on failure.
168*b70d1b9fSJean-Philippe Brucker  * Availability: When attached to container
169*b70d1b9fSJean-Philippe Brucker  */
170*b70d1b9fSJean-Philippe Brucker #define VFIO_GROUP_UNSET_CONTAINER	_IO(VFIO_TYPE, VFIO_BASE + 5)
171*b70d1b9fSJean-Philippe Brucker 
172*b70d1b9fSJean-Philippe Brucker /**
173*b70d1b9fSJean-Philippe Brucker  * VFIO_GROUP_GET_DEVICE_FD - _IOW(VFIO_TYPE, VFIO_BASE + 6, char)
174*b70d1b9fSJean-Philippe Brucker  *
175*b70d1b9fSJean-Philippe Brucker  * Return a new file descriptor for the device object described by
176*b70d1b9fSJean-Philippe Brucker  * the provided string.  The string should match a device listed in
177*b70d1b9fSJean-Philippe Brucker  * the devices subdirectory of the IOMMU group sysfs entry.  The
178*b70d1b9fSJean-Philippe Brucker  * group containing the device must already be added to this context.
179*b70d1b9fSJean-Philippe Brucker  * Return: new file descriptor on success, -errno on failure.
180*b70d1b9fSJean-Philippe Brucker  * Availability: When attached to container
181*b70d1b9fSJean-Philippe Brucker  */
182*b70d1b9fSJean-Philippe Brucker #define VFIO_GROUP_GET_DEVICE_FD	_IO(VFIO_TYPE, VFIO_BASE + 6)
183*b70d1b9fSJean-Philippe Brucker 
184*b70d1b9fSJean-Philippe Brucker /* --------------- IOCTLs for DEVICE file descriptors --------------- */
185*b70d1b9fSJean-Philippe Brucker 
186*b70d1b9fSJean-Philippe Brucker /**
187*b70d1b9fSJean-Philippe Brucker  * VFIO_DEVICE_GET_INFO - _IOR(VFIO_TYPE, VFIO_BASE + 7,
188*b70d1b9fSJean-Philippe Brucker  *						struct vfio_device_info)
189*b70d1b9fSJean-Philippe Brucker  *
190*b70d1b9fSJean-Philippe Brucker  * Retrieve information about the device.  Fills in provided
191*b70d1b9fSJean-Philippe Brucker  * struct vfio_device_info.  Caller sets argsz.
192*b70d1b9fSJean-Philippe Brucker  * Return: 0 on success, -errno on failure.
193*b70d1b9fSJean-Philippe Brucker  */
194*b70d1b9fSJean-Philippe Brucker struct vfio_device_info {
195*b70d1b9fSJean-Philippe Brucker 	__u32	argsz;
196*b70d1b9fSJean-Philippe Brucker 	__u32	flags;
197*b70d1b9fSJean-Philippe Brucker #define VFIO_DEVICE_FLAGS_RESET	(1 << 0)	/* Device supports reset */
198*b70d1b9fSJean-Philippe Brucker #define VFIO_DEVICE_FLAGS_PCI	(1 << 1)	/* vfio-pci device */
199*b70d1b9fSJean-Philippe Brucker #define VFIO_DEVICE_FLAGS_PLATFORM (1 << 2)	/* vfio-platform device */
200*b70d1b9fSJean-Philippe Brucker #define VFIO_DEVICE_FLAGS_AMBA  (1 << 3)	/* vfio-amba device */
201*b70d1b9fSJean-Philippe Brucker #define VFIO_DEVICE_FLAGS_CCW	(1 << 4)	/* vfio-ccw device */
202*b70d1b9fSJean-Philippe Brucker 	__u32	num_regions;	/* Max region index + 1 */
203*b70d1b9fSJean-Philippe Brucker 	__u32	num_irqs;	/* Max IRQ index + 1 */
204*b70d1b9fSJean-Philippe Brucker };
205*b70d1b9fSJean-Philippe Brucker #define VFIO_DEVICE_GET_INFO		_IO(VFIO_TYPE, VFIO_BASE + 7)
206*b70d1b9fSJean-Philippe Brucker 
207*b70d1b9fSJean-Philippe Brucker /*
208*b70d1b9fSJean-Philippe Brucker  * Vendor driver using Mediated device framework should provide device_api
209*b70d1b9fSJean-Philippe Brucker  * attribute in supported type attribute groups. Device API string should be one
210*b70d1b9fSJean-Philippe Brucker  * of the following corresponding to device flags in vfio_device_info structure.
211*b70d1b9fSJean-Philippe Brucker  */
212*b70d1b9fSJean-Philippe Brucker 
213*b70d1b9fSJean-Philippe Brucker #define VFIO_DEVICE_API_PCI_STRING		"vfio-pci"
214*b70d1b9fSJean-Philippe Brucker #define VFIO_DEVICE_API_PLATFORM_STRING		"vfio-platform"
215*b70d1b9fSJean-Philippe Brucker #define VFIO_DEVICE_API_AMBA_STRING		"vfio-amba"
216*b70d1b9fSJean-Philippe Brucker #define VFIO_DEVICE_API_CCW_STRING		"vfio-ccw"
217*b70d1b9fSJean-Philippe Brucker 
218*b70d1b9fSJean-Philippe Brucker /**
219*b70d1b9fSJean-Philippe Brucker  * VFIO_DEVICE_GET_REGION_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 8,
220*b70d1b9fSJean-Philippe Brucker  *				       struct vfio_region_info)
221*b70d1b9fSJean-Philippe Brucker  *
222*b70d1b9fSJean-Philippe Brucker  * Retrieve information about a device region.  Caller provides
223*b70d1b9fSJean-Philippe Brucker  * struct vfio_region_info with index value set.  Caller sets argsz.
224*b70d1b9fSJean-Philippe Brucker  * Implementation of region mapping is bus driver specific.  This is
225*b70d1b9fSJean-Philippe Brucker  * intended to describe MMIO, I/O port, as well as bus specific
226*b70d1b9fSJean-Philippe Brucker  * regions (ex. PCI config space).  Zero sized regions may be used
227*b70d1b9fSJean-Philippe Brucker  * to describe unimplemented regions (ex. unimplemented PCI BARs).
228*b70d1b9fSJean-Philippe Brucker  * Return: 0 on success, -errno on failure.
229*b70d1b9fSJean-Philippe Brucker  */
230*b70d1b9fSJean-Philippe Brucker struct vfio_region_info {
231*b70d1b9fSJean-Philippe Brucker 	__u32	argsz;
232*b70d1b9fSJean-Philippe Brucker 	__u32	flags;
233*b70d1b9fSJean-Philippe Brucker #define VFIO_REGION_INFO_FLAG_READ	(1 << 0) /* Region supports read */
234*b70d1b9fSJean-Philippe Brucker #define VFIO_REGION_INFO_FLAG_WRITE	(1 << 1) /* Region supports write */
235*b70d1b9fSJean-Philippe Brucker #define VFIO_REGION_INFO_FLAG_MMAP	(1 << 2) /* Region supports mmap */
236*b70d1b9fSJean-Philippe Brucker #define VFIO_REGION_INFO_FLAG_CAPS	(1 << 3) /* Info supports caps */
237*b70d1b9fSJean-Philippe Brucker 	__u32	index;		/* Region index */
238*b70d1b9fSJean-Philippe Brucker 	__u32	cap_offset;	/* Offset within info struct of first cap */
239*b70d1b9fSJean-Philippe Brucker 	__u64	size;		/* Region size (bytes) */
240*b70d1b9fSJean-Philippe Brucker 	__u64	offset;		/* Region offset from start of device fd */
241*b70d1b9fSJean-Philippe Brucker };
242*b70d1b9fSJean-Philippe Brucker #define VFIO_DEVICE_GET_REGION_INFO	_IO(VFIO_TYPE, VFIO_BASE + 8)
243*b70d1b9fSJean-Philippe Brucker 
244*b70d1b9fSJean-Philippe Brucker /*
245*b70d1b9fSJean-Philippe Brucker  * The sparse mmap capability allows finer granularity of specifying areas
246*b70d1b9fSJean-Philippe Brucker  * within a region with mmap support.  When specified, the user should only
247*b70d1b9fSJean-Philippe Brucker  * mmap the offset ranges specified by the areas array.  mmaps outside of the
248*b70d1b9fSJean-Philippe Brucker  * areas specified may fail (such as the range covering a PCI MSI-X table) or
249*b70d1b9fSJean-Philippe Brucker  * may result in improper device behavior.
250*b70d1b9fSJean-Philippe Brucker  *
251*b70d1b9fSJean-Philippe Brucker  * The structures below define version 1 of this capability.
252*b70d1b9fSJean-Philippe Brucker  */
253*b70d1b9fSJean-Philippe Brucker #define VFIO_REGION_INFO_CAP_SPARSE_MMAP	1
254*b70d1b9fSJean-Philippe Brucker 
255*b70d1b9fSJean-Philippe Brucker struct vfio_region_sparse_mmap_area {
256*b70d1b9fSJean-Philippe Brucker 	__u64	offset;	/* Offset of mmap'able area within region */
257*b70d1b9fSJean-Philippe Brucker 	__u64	size;	/* Size of mmap'able area */
258*b70d1b9fSJean-Philippe Brucker };
259*b70d1b9fSJean-Philippe Brucker 
260*b70d1b9fSJean-Philippe Brucker struct vfio_region_info_cap_sparse_mmap {
261*b70d1b9fSJean-Philippe Brucker 	struct vfio_info_cap_header header;
262*b70d1b9fSJean-Philippe Brucker 	__u32	nr_areas;
263*b70d1b9fSJean-Philippe Brucker 	__u32	reserved;
264*b70d1b9fSJean-Philippe Brucker 	struct vfio_region_sparse_mmap_area areas[];
265*b70d1b9fSJean-Philippe Brucker };
266*b70d1b9fSJean-Philippe Brucker 
267*b70d1b9fSJean-Philippe Brucker /*
268*b70d1b9fSJean-Philippe Brucker  * The device specific type capability allows regions unique to a specific
269*b70d1b9fSJean-Philippe Brucker  * device or class of devices to be exposed.  This helps solve the problem for
270*b70d1b9fSJean-Philippe Brucker  * vfio bus drivers of defining which region indexes correspond to which region
271*b70d1b9fSJean-Philippe Brucker  * on the device, without needing to resort to static indexes, as done by
272*b70d1b9fSJean-Philippe Brucker  * vfio-pci.  For instance, if we were to go back in time, we might remove
273*b70d1b9fSJean-Philippe Brucker  * VFIO_PCI_VGA_REGION_INDEX and let vfio-pci simply define that all indexes
274*b70d1b9fSJean-Philippe Brucker  * greater than or equal to VFIO_PCI_NUM_REGIONS are device specific and we'd
275*b70d1b9fSJean-Philippe Brucker  * make a "VGA" device specific type to describe the VGA access space.  This
276*b70d1b9fSJean-Philippe Brucker  * means that non-VGA devices wouldn't need to waste this index, and thus the
277*b70d1b9fSJean-Philippe Brucker  * address space associated with it due to implementation of device file
278*b70d1b9fSJean-Philippe Brucker  * descriptor offsets in vfio-pci.
279*b70d1b9fSJean-Philippe Brucker  *
280*b70d1b9fSJean-Philippe Brucker  * The current implementation is now part of the user ABI, so we can't use this
281*b70d1b9fSJean-Philippe Brucker  * for VGA, but there are other upcoming use cases, such as opregions for Intel
282*b70d1b9fSJean-Philippe Brucker  * IGD devices and framebuffers for vGPU devices.  We missed VGA, but we'll
283*b70d1b9fSJean-Philippe Brucker  * use this for future additions.
284*b70d1b9fSJean-Philippe Brucker  *
285*b70d1b9fSJean-Philippe Brucker  * The structure below defines version 1 of this capability.
286*b70d1b9fSJean-Philippe Brucker  */
287*b70d1b9fSJean-Philippe Brucker #define VFIO_REGION_INFO_CAP_TYPE	2
288*b70d1b9fSJean-Philippe Brucker 
289*b70d1b9fSJean-Philippe Brucker struct vfio_region_info_cap_type {
290*b70d1b9fSJean-Philippe Brucker 	struct vfio_info_cap_header header;
291*b70d1b9fSJean-Philippe Brucker 	__u32 type;	/* global per bus driver */
292*b70d1b9fSJean-Philippe Brucker 	__u32 subtype;	/* type specific */
293*b70d1b9fSJean-Philippe Brucker };
294*b70d1b9fSJean-Philippe Brucker 
295*b70d1b9fSJean-Philippe Brucker #define VFIO_REGION_TYPE_PCI_VENDOR_TYPE	(1 << 31)
296*b70d1b9fSJean-Philippe Brucker #define VFIO_REGION_TYPE_PCI_VENDOR_MASK	(0xffff)
297*b70d1b9fSJean-Philippe Brucker 
298*b70d1b9fSJean-Philippe Brucker /* 8086 Vendor sub-types */
299*b70d1b9fSJean-Philippe Brucker #define VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION	(1)
300*b70d1b9fSJean-Philippe Brucker #define VFIO_REGION_SUBTYPE_INTEL_IGD_HOST_CFG	(2)
301*b70d1b9fSJean-Philippe Brucker #define VFIO_REGION_SUBTYPE_INTEL_IGD_LPC_CFG	(3)
302*b70d1b9fSJean-Philippe Brucker 
303*b70d1b9fSJean-Philippe Brucker /**
304*b70d1b9fSJean-Philippe Brucker  * VFIO_DEVICE_GET_IRQ_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 9,
305*b70d1b9fSJean-Philippe Brucker  *				    struct vfio_irq_info)
306*b70d1b9fSJean-Philippe Brucker  *
307*b70d1b9fSJean-Philippe Brucker  * Retrieve information about a device IRQ.  Caller provides
308*b70d1b9fSJean-Philippe Brucker  * struct vfio_irq_info with index value set.  Caller sets argsz.
309*b70d1b9fSJean-Philippe Brucker  * Implementation of IRQ mapping is bus driver specific.  Indexes
310*b70d1b9fSJean-Philippe Brucker  * using multiple IRQs are primarily intended to support MSI-like
311*b70d1b9fSJean-Philippe Brucker  * interrupt blocks.  Zero count irq blocks may be used to describe
312*b70d1b9fSJean-Philippe Brucker  * unimplemented interrupt types.
313*b70d1b9fSJean-Philippe Brucker  *
314*b70d1b9fSJean-Philippe Brucker  * The EVENTFD flag indicates the interrupt index supports eventfd based
315*b70d1b9fSJean-Philippe Brucker  * signaling.
316*b70d1b9fSJean-Philippe Brucker  *
317*b70d1b9fSJean-Philippe Brucker  * The MASKABLE flags indicates the index supports MASK and UNMASK
318*b70d1b9fSJean-Philippe Brucker  * actions described below.
319*b70d1b9fSJean-Philippe Brucker  *
320*b70d1b9fSJean-Philippe Brucker  * AUTOMASKED indicates that after signaling, the interrupt line is
321*b70d1b9fSJean-Philippe Brucker  * automatically masked by VFIO and the user needs to unmask the line
322*b70d1b9fSJean-Philippe Brucker  * to receive new interrupts.  This is primarily intended to distinguish
323*b70d1b9fSJean-Philippe Brucker  * level triggered interrupts.
324*b70d1b9fSJean-Philippe Brucker  *
325*b70d1b9fSJean-Philippe Brucker  * The NORESIZE flag indicates that the interrupt lines within the index
326*b70d1b9fSJean-Philippe Brucker  * are setup as a set and new subindexes cannot be enabled without first
327*b70d1b9fSJean-Philippe Brucker  * disabling the entire index.  This is used for interrupts like PCI MSI
328*b70d1b9fSJean-Philippe Brucker  * and MSI-X where the driver may only use a subset of the available
329*b70d1b9fSJean-Philippe Brucker  * indexes, but VFIO needs to enable a specific number of vectors
330*b70d1b9fSJean-Philippe Brucker  * upfront.  In the case of MSI-X, where the user can enable MSI-X and
331*b70d1b9fSJean-Philippe Brucker  * then add and unmask vectors, it's up to userspace to make the decision
332*b70d1b9fSJean-Philippe Brucker  * whether to allocate the maximum supported number of vectors or tear
333*b70d1b9fSJean-Philippe Brucker  * down setup and incrementally increase the vectors as each is enabled.
334*b70d1b9fSJean-Philippe Brucker  */
335*b70d1b9fSJean-Philippe Brucker struct vfio_irq_info {
336*b70d1b9fSJean-Philippe Brucker 	__u32	argsz;
337*b70d1b9fSJean-Philippe Brucker 	__u32	flags;
338*b70d1b9fSJean-Philippe Brucker #define VFIO_IRQ_INFO_EVENTFD		(1 << 0)
339*b70d1b9fSJean-Philippe Brucker #define VFIO_IRQ_INFO_MASKABLE		(1 << 1)
340*b70d1b9fSJean-Philippe Brucker #define VFIO_IRQ_INFO_AUTOMASKED	(1 << 2)
341*b70d1b9fSJean-Philippe Brucker #define VFIO_IRQ_INFO_NORESIZE		(1 << 3)
342*b70d1b9fSJean-Philippe Brucker 	__u32	index;		/* IRQ index */
343*b70d1b9fSJean-Philippe Brucker 	__u32	count;		/* Number of IRQs within this index */
344*b70d1b9fSJean-Philippe Brucker };
345*b70d1b9fSJean-Philippe Brucker #define VFIO_DEVICE_GET_IRQ_INFO	_IO(VFIO_TYPE, VFIO_BASE + 9)
346*b70d1b9fSJean-Philippe Brucker 
347*b70d1b9fSJean-Philippe Brucker /**
348*b70d1b9fSJean-Philippe Brucker  * VFIO_DEVICE_SET_IRQS - _IOW(VFIO_TYPE, VFIO_BASE + 10, struct vfio_irq_set)
349*b70d1b9fSJean-Philippe Brucker  *
350*b70d1b9fSJean-Philippe Brucker  * Set signaling, masking, and unmasking of interrupts.  Caller provides
351*b70d1b9fSJean-Philippe Brucker  * struct vfio_irq_set with all fields set.  'start' and 'count' indicate
352*b70d1b9fSJean-Philippe Brucker  * the range of subindexes being specified.
353*b70d1b9fSJean-Philippe Brucker  *
354*b70d1b9fSJean-Philippe Brucker  * The DATA flags specify the type of data provided.  If DATA_NONE, the
355*b70d1b9fSJean-Philippe Brucker  * operation performs the specified action immediately on the specified
356*b70d1b9fSJean-Philippe Brucker  * interrupt(s).  For example, to unmask AUTOMASKED interrupt [0,0]:
357*b70d1b9fSJean-Philippe Brucker  * flags = (DATA_NONE|ACTION_UNMASK), index = 0, start = 0, count = 1.
358*b70d1b9fSJean-Philippe Brucker  *
359*b70d1b9fSJean-Philippe Brucker  * DATA_BOOL allows sparse support for the same on arrays of interrupts.
360*b70d1b9fSJean-Philippe Brucker  * For example, to mask interrupts [0,1] and [0,3] (but not [0,2]):
361*b70d1b9fSJean-Philippe Brucker  * flags = (DATA_BOOL|ACTION_MASK), index = 0, start = 1, count = 3,
362*b70d1b9fSJean-Philippe Brucker  * data = {1,0,1}
363*b70d1b9fSJean-Philippe Brucker  *
364*b70d1b9fSJean-Philippe Brucker  * DATA_EVENTFD binds the specified ACTION to the provided __s32 eventfd.
365*b70d1b9fSJean-Philippe Brucker  * A value of -1 can be used to either de-assign interrupts if already
366*b70d1b9fSJean-Philippe Brucker  * assigned or skip un-assigned interrupts.  For example, to set an eventfd
367*b70d1b9fSJean-Philippe Brucker  * to be trigger for interrupts [0,0] and [0,2]:
368*b70d1b9fSJean-Philippe Brucker  * flags = (DATA_EVENTFD|ACTION_TRIGGER), index = 0, start = 0, count = 3,
369*b70d1b9fSJean-Philippe Brucker  * data = {fd1, -1, fd2}
370*b70d1b9fSJean-Philippe Brucker  * If index [0,1] is previously set, two count = 1 ioctls calls would be
371*b70d1b9fSJean-Philippe Brucker  * required to set [0,0] and [0,2] without changing [0,1].
372*b70d1b9fSJean-Philippe Brucker  *
373*b70d1b9fSJean-Philippe Brucker  * Once a signaling mechanism is set, DATA_BOOL or DATA_NONE can be used
374*b70d1b9fSJean-Philippe Brucker  * with ACTION_TRIGGER to perform kernel level interrupt loopback testing
375*b70d1b9fSJean-Philippe Brucker  * from userspace (ie. simulate hardware triggering).
376*b70d1b9fSJean-Philippe Brucker  *
377*b70d1b9fSJean-Philippe Brucker  * Setting of an event triggering mechanism to userspace for ACTION_TRIGGER
378*b70d1b9fSJean-Philippe Brucker  * enables the interrupt index for the device.  Individual subindex interrupts
379*b70d1b9fSJean-Philippe Brucker  * can be disabled using the -1 value for DATA_EVENTFD or the index can be
380*b70d1b9fSJean-Philippe Brucker  * disabled as a whole with: flags = (DATA_NONE|ACTION_TRIGGER), count = 0.
381*b70d1b9fSJean-Philippe Brucker  *
382*b70d1b9fSJean-Philippe Brucker  * Note that ACTION_[UN]MASK specify user->kernel signaling (irqfds) while
383*b70d1b9fSJean-Philippe Brucker  * ACTION_TRIGGER specifies kernel->user signaling.
384*b70d1b9fSJean-Philippe Brucker  */
385*b70d1b9fSJean-Philippe Brucker struct vfio_irq_set {
386*b70d1b9fSJean-Philippe Brucker 	__u32	argsz;
387*b70d1b9fSJean-Philippe Brucker 	__u32	flags;
388*b70d1b9fSJean-Philippe Brucker #define VFIO_IRQ_SET_DATA_NONE		(1 << 0) /* Data not present */
389*b70d1b9fSJean-Philippe Brucker #define VFIO_IRQ_SET_DATA_BOOL		(1 << 1) /* Data is bool (u8) */
390*b70d1b9fSJean-Philippe Brucker #define VFIO_IRQ_SET_DATA_EVENTFD	(1 << 2) /* Data is eventfd (s32) */
391*b70d1b9fSJean-Philippe Brucker #define VFIO_IRQ_SET_ACTION_MASK	(1 << 3) /* Mask interrupt */
392*b70d1b9fSJean-Philippe Brucker #define VFIO_IRQ_SET_ACTION_UNMASK	(1 << 4) /* Unmask interrupt */
393*b70d1b9fSJean-Philippe Brucker #define VFIO_IRQ_SET_ACTION_TRIGGER	(1 << 5) /* Trigger interrupt */
394*b70d1b9fSJean-Philippe Brucker 	__u32	index;
395*b70d1b9fSJean-Philippe Brucker 	__u32	start;
396*b70d1b9fSJean-Philippe Brucker 	__u32	count;
397*b70d1b9fSJean-Philippe Brucker 	__u8	data[];
398*b70d1b9fSJean-Philippe Brucker };
399*b70d1b9fSJean-Philippe Brucker #define VFIO_DEVICE_SET_IRQS		_IO(VFIO_TYPE, VFIO_BASE + 10)
400*b70d1b9fSJean-Philippe Brucker 
401*b70d1b9fSJean-Philippe Brucker #define VFIO_IRQ_SET_DATA_TYPE_MASK	(VFIO_IRQ_SET_DATA_NONE | \
402*b70d1b9fSJean-Philippe Brucker 					 VFIO_IRQ_SET_DATA_BOOL | \
403*b70d1b9fSJean-Philippe Brucker 					 VFIO_IRQ_SET_DATA_EVENTFD)
404*b70d1b9fSJean-Philippe Brucker #define VFIO_IRQ_SET_ACTION_TYPE_MASK	(VFIO_IRQ_SET_ACTION_MASK | \
405*b70d1b9fSJean-Philippe Brucker 					 VFIO_IRQ_SET_ACTION_UNMASK | \
406*b70d1b9fSJean-Philippe Brucker 					 VFIO_IRQ_SET_ACTION_TRIGGER)
407*b70d1b9fSJean-Philippe Brucker /**
408*b70d1b9fSJean-Philippe Brucker  * VFIO_DEVICE_RESET - _IO(VFIO_TYPE, VFIO_BASE + 11)
409*b70d1b9fSJean-Philippe Brucker  *
410*b70d1b9fSJean-Philippe Brucker  * Reset a device.
411*b70d1b9fSJean-Philippe Brucker  */
412*b70d1b9fSJean-Philippe Brucker #define VFIO_DEVICE_RESET		_IO(VFIO_TYPE, VFIO_BASE + 11)
413*b70d1b9fSJean-Philippe Brucker 
414*b70d1b9fSJean-Philippe Brucker /*
415*b70d1b9fSJean-Philippe Brucker  * The VFIO-PCI bus driver makes use of the following fixed region and
416*b70d1b9fSJean-Philippe Brucker  * IRQ index mapping.  Unimplemented regions return a size of zero.
417*b70d1b9fSJean-Philippe Brucker  * Unimplemented IRQ types return a count of zero.
418*b70d1b9fSJean-Philippe Brucker  */
419*b70d1b9fSJean-Philippe Brucker 
420*b70d1b9fSJean-Philippe Brucker enum {
421*b70d1b9fSJean-Philippe Brucker 	VFIO_PCI_BAR0_REGION_INDEX,
422*b70d1b9fSJean-Philippe Brucker 	VFIO_PCI_BAR1_REGION_INDEX,
423*b70d1b9fSJean-Philippe Brucker 	VFIO_PCI_BAR2_REGION_INDEX,
424*b70d1b9fSJean-Philippe Brucker 	VFIO_PCI_BAR3_REGION_INDEX,
425*b70d1b9fSJean-Philippe Brucker 	VFIO_PCI_BAR4_REGION_INDEX,
426*b70d1b9fSJean-Philippe Brucker 	VFIO_PCI_BAR5_REGION_INDEX,
427*b70d1b9fSJean-Philippe Brucker 	VFIO_PCI_ROM_REGION_INDEX,
428*b70d1b9fSJean-Philippe Brucker 	VFIO_PCI_CONFIG_REGION_INDEX,
429*b70d1b9fSJean-Philippe Brucker 	/*
430*b70d1b9fSJean-Philippe Brucker 	 * Expose VGA regions defined for PCI base class 03, subclass 00.
431*b70d1b9fSJean-Philippe Brucker 	 * This includes I/O port ranges 0x3b0 to 0x3bb and 0x3c0 to 0x3df
432*b70d1b9fSJean-Philippe Brucker 	 * as well as the MMIO range 0xa0000 to 0xbffff.  Each implemented
433*b70d1b9fSJean-Philippe Brucker 	 * range is found at it's identity mapped offset from the region
434*b70d1b9fSJean-Philippe Brucker 	 * offset, for example 0x3b0 is region_info.offset + 0x3b0.  Areas
435*b70d1b9fSJean-Philippe Brucker 	 * between described ranges are unimplemented.
436*b70d1b9fSJean-Philippe Brucker 	 */
437*b70d1b9fSJean-Philippe Brucker 	VFIO_PCI_VGA_REGION_INDEX,
438*b70d1b9fSJean-Philippe Brucker 	VFIO_PCI_NUM_REGIONS = 9 /* Fixed user ABI, region indexes >=9 use */
439*b70d1b9fSJean-Philippe Brucker 				 /* device specific cap to define content. */
440*b70d1b9fSJean-Philippe Brucker };
441*b70d1b9fSJean-Philippe Brucker 
442*b70d1b9fSJean-Philippe Brucker enum {
443*b70d1b9fSJean-Philippe Brucker 	VFIO_PCI_INTX_IRQ_INDEX,
444*b70d1b9fSJean-Philippe Brucker 	VFIO_PCI_MSI_IRQ_INDEX,
445*b70d1b9fSJean-Philippe Brucker 	VFIO_PCI_MSIX_IRQ_INDEX,
446*b70d1b9fSJean-Philippe Brucker 	VFIO_PCI_ERR_IRQ_INDEX,
447*b70d1b9fSJean-Philippe Brucker 	VFIO_PCI_REQ_IRQ_INDEX,
448*b70d1b9fSJean-Philippe Brucker 	VFIO_PCI_NUM_IRQS
449*b70d1b9fSJean-Philippe Brucker };
450*b70d1b9fSJean-Philippe Brucker 
451*b70d1b9fSJean-Philippe Brucker /*
452*b70d1b9fSJean-Philippe Brucker  * The vfio-ccw bus driver makes use of the following fixed region and
453*b70d1b9fSJean-Philippe Brucker  * IRQ index mapping. Unimplemented regions return a size of zero.
454*b70d1b9fSJean-Philippe Brucker  * Unimplemented IRQ types return a count of zero.
455*b70d1b9fSJean-Philippe Brucker  */
456*b70d1b9fSJean-Philippe Brucker 
457*b70d1b9fSJean-Philippe Brucker enum {
458*b70d1b9fSJean-Philippe Brucker 	VFIO_CCW_CONFIG_REGION_INDEX,
459*b70d1b9fSJean-Philippe Brucker 	VFIO_CCW_NUM_REGIONS
460*b70d1b9fSJean-Philippe Brucker };
461*b70d1b9fSJean-Philippe Brucker 
462*b70d1b9fSJean-Philippe Brucker enum {
463*b70d1b9fSJean-Philippe Brucker 	VFIO_CCW_IO_IRQ_INDEX,
464*b70d1b9fSJean-Philippe Brucker 	VFIO_CCW_NUM_IRQS
465*b70d1b9fSJean-Philippe Brucker };
466*b70d1b9fSJean-Philippe Brucker 
467*b70d1b9fSJean-Philippe Brucker /**
468*b70d1b9fSJean-Philippe Brucker  * VFIO_DEVICE_GET_PCI_HOT_RESET_INFO - _IORW(VFIO_TYPE, VFIO_BASE + 12,
469*b70d1b9fSJean-Philippe Brucker  *					      struct vfio_pci_hot_reset_info)
470*b70d1b9fSJean-Philippe Brucker  *
471*b70d1b9fSJean-Philippe Brucker  * Return: 0 on success, -errno on failure:
472*b70d1b9fSJean-Philippe Brucker  *	-enospc = insufficient buffer, -enodev = unsupported for device.
473*b70d1b9fSJean-Philippe Brucker  */
474*b70d1b9fSJean-Philippe Brucker struct vfio_pci_dependent_device {
475*b70d1b9fSJean-Philippe Brucker 	__u32	group_id;
476*b70d1b9fSJean-Philippe Brucker 	__u16	segment;
477*b70d1b9fSJean-Philippe Brucker 	__u8	bus;
478*b70d1b9fSJean-Philippe Brucker 	__u8	devfn; /* Use PCI_SLOT/PCI_FUNC */
479*b70d1b9fSJean-Philippe Brucker };
480*b70d1b9fSJean-Philippe Brucker 
481*b70d1b9fSJean-Philippe Brucker struct vfio_pci_hot_reset_info {
482*b70d1b9fSJean-Philippe Brucker 	__u32	argsz;
483*b70d1b9fSJean-Philippe Brucker 	__u32	flags;
484*b70d1b9fSJean-Philippe Brucker 	__u32	count;
485*b70d1b9fSJean-Philippe Brucker 	struct vfio_pci_dependent_device	devices[];
486*b70d1b9fSJean-Philippe Brucker };
487*b70d1b9fSJean-Philippe Brucker 
488*b70d1b9fSJean-Philippe Brucker #define VFIO_DEVICE_GET_PCI_HOT_RESET_INFO	_IO(VFIO_TYPE, VFIO_BASE + 12)
489*b70d1b9fSJean-Philippe Brucker 
490*b70d1b9fSJean-Philippe Brucker /**
491*b70d1b9fSJean-Philippe Brucker  * VFIO_DEVICE_PCI_HOT_RESET - _IOW(VFIO_TYPE, VFIO_BASE + 13,
492*b70d1b9fSJean-Philippe Brucker  *				    struct vfio_pci_hot_reset)
493*b70d1b9fSJean-Philippe Brucker  *
494*b70d1b9fSJean-Philippe Brucker  * Return: 0 on success, -errno on failure.
495*b70d1b9fSJean-Philippe Brucker  */
496*b70d1b9fSJean-Philippe Brucker struct vfio_pci_hot_reset {
497*b70d1b9fSJean-Philippe Brucker 	__u32	argsz;
498*b70d1b9fSJean-Philippe Brucker 	__u32	flags;
499*b70d1b9fSJean-Philippe Brucker 	__u32	count;
500*b70d1b9fSJean-Philippe Brucker 	__s32	group_fds[];
501*b70d1b9fSJean-Philippe Brucker };
502*b70d1b9fSJean-Philippe Brucker 
503*b70d1b9fSJean-Philippe Brucker #define VFIO_DEVICE_PCI_HOT_RESET	_IO(VFIO_TYPE, VFIO_BASE + 13)
504*b70d1b9fSJean-Philippe Brucker 
505*b70d1b9fSJean-Philippe Brucker /* -------- API for Type1 VFIO IOMMU -------- */
506*b70d1b9fSJean-Philippe Brucker 
507*b70d1b9fSJean-Philippe Brucker /**
508*b70d1b9fSJean-Philippe Brucker  * VFIO_IOMMU_GET_INFO - _IOR(VFIO_TYPE, VFIO_BASE + 12, struct vfio_iommu_info)
509*b70d1b9fSJean-Philippe Brucker  *
510*b70d1b9fSJean-Philippe Brucker  * Retrieve information about the IOMMU object. Fills in provided
511*b70d1b9fSJean-Philippe Brucker  * struct vfio_iommu_info. Caller sets argsz.
512*b70d1b9fSJean-Philippe Brucker  *
513*b70d1b9fSJean-Philippe Brucker  * XXX Should we do these by CHECK_EXTENSION too?
514*b70d1b9fSJean-Philippe Brucker  */
515*b70d1b9fSJean-Philippe Brucker struct vfio_iommu_type1_info {
516*b70d1b9fSJean-Philippe Brucker 	__u32	argsz;
517*b70d1b9fSJean-Philippe Brucker 	__u32	flags;
518*b70d1b9fSJean-Philippe Brucker #define VFIO_IOMMU_INFO_PGSIZES (1 << 0)	/* supported page sizes info */
519*b70d1b9fSJean-Philippe Brucker 	__u64	iova_pgsizes;		/* Bitmap of supported page sizes */
520*b70d1b9fSJean-Philippe Brucker };
521*b70d1b9fSJean-Philippe Brucker 
522*b70d1b9fSJean-Philippe Brucker #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
523*b70d1b9fSJean-Philippe Brucker 
524*b70d1b9fSJean-Philippe Brucker /**
525*b70d1b9fSJean-Philippe Brucker  * VFIO_IOMMU_MAP_DMA - _IOW(VFIO_TYPE, VFIO_BASE + 13, struct vfio_dma_map)
526*b70d1b9fSJean-Philippe Brucker  *
527*b70d1b9fSJean-Philippe Brucker  * Map process virtual addresses to IO virtual addresses using the
528*b70d1b9fSJean-Philippe Brucker  * provided struct vfio_dma_map. Caller sets argsz. READ &/ WRITE required.
529*b70d1b9fSJean-Philippe Brucker  */
530*b70d1b9fSJean-Philippe Brucker struct vfio_iommu_type1_dma_map {
531*b70d1b9fSJean-Philippe Brucker 	__u32	argsz;
532*b70d1b9fSJean-Philippe Brucker 	__u32	flags;
533*b70d1b9fSJean-Philippe Brucker #define VFIO_DMA_MAP_FLAG_READ (1 << 0)		/* readable from device */
534*b70d1b9fSJean-Philippe Brucker #define VFIO_DMA_MAP_FLAG_WRITE (1 << 1)	/* writable from device */
535*b70d1b9fSJean-Philippe Brucker 	__u64	vaddr;				/* Process virtual address */
536*b70d1b9fSJean-Philippe Brucker 	__u64	iova;				/* IO virtual address */
537*b70d1b9fSJean-Philippe Brucker 	__u64	size;				/* Size of mapping (bytes) */
538*b70d1b9fSJean-Philippe Brucker };
539*b70d1b9fSJean-Philippe Brucker 
540*b70d1b9fSJean-Philippe Brucker #define VFIO_IOMMU_MAP_DMA _IO(VFIO_TYPE, VFIO_BASE + 13)
541*b70d1b9fSJean-Philippe Brucker 
542*b70d1b9fSJean-Philippe Brucker /**
543*b70d1b9fSJean-Philippe Brucker  * VFIO_IOMMU_UNMAP_DMA - _IOWR(VFIO_TYPE, VFIO_BASE + 14,
544*b70d1b9fSJean-Philippe Brucker  *							struct vfio_dma_unmap)
545*b70d1b9fSJean-Philippe Brucker  *
546*b70d1b9fSJean-Philippe Brucker  * Unmap IO virtual addresses using the provided struct vfio_dma_unmap.
547*b70d1b9fSJean-Philippe Brucker  * Caller sets argsz.  The actual unmapped size is returned in the size
548*b70d1b9fSJean-Philippe Brucker  * field.  No guarantee is made to the user that arbitrary unmaps of iova
549*b70d1b9fSJean-Philippe Brucker  * or size different from those used in the original mapping call will
550*b70d1b9fSJean-Philippe Brucker  * succeed.
551*b70d1b9fSJean-Philippe Brucker  */
552*b70d1b9fSJean-Philippe Brucker struct vfio_iommu_type1_dma_unmap {
553*b70d1b9fSJean-Philippe Brucker 	__u32	argsz;
554*b70d1b9fSJean-Philippe Brucker 	__u32	flags;
555*b70d1b9fSJean-Philippe Brucker 	__u64	iova;				/* IO virtual address */
556*b70d1b9fSJean-Philippe Brucker 	__u64	size;				/* Size of mapping (bytes) */
557*b70d1b9fSJean-Philippe Brucker };
558*b70d1b9fSJean-Philippe Brucker 
559*b70d1b9fSJean-Philippe Brucker #define VFIO_IOMMU_UNMAP_DMA _IO(VFIO_TYPE, VFIO_BASE + 14)
560*b70d1b9fSJean-Philippe Brucker 
561*b70d1b9fSJean-Philippe Brucker /*
562*b70d1b9fSJean-Philippe Brucker  * IOCTLs to enable/disable IOMMU container usage.
563*b70d1b9fSJean-Philippe Brucker  * No parameters are supported.
564*b70d1b9fSJean-Philippe Brucker  */
565*b70d1b9fSJean-Philippe Brucker #define VFIO_IOMMU_ENABLE	_IO(VFIO_TYPE, VFIO_BASE + 15)
566*b70d1b9fSJean-Philippe Brucker #define VFIO_IOMMU_DISABLE	_IO(VFIO_TYPE, VFIO_BASE + 16)
567*b70d1b9fSJean-Philippe Brucker 
568*b70d1b9fSJean-Philippe Brucker /* -------- Additional API for SPAPR TCE (Server POWERPC) IOMMU -------- */
569*b70d1b9fSJean-Philippe Brucker 
570*b70d1b9fSJean-Philippe Brucker /*
571*b70d1b9fSJean-Philippe Brucker  * The SPAPR TCE DDW info struct provides the information about
572*b70d1b9fSJean-Philippe Brucker  * the details of Dynamic DMA window capability.
573*b70d1b9fSJean-Philippe Brucker  *
574*b70d1b9fSJean-Philippe Brucker  * @pgsizes contains a page size bitmask, 4K/64K/16M are supported.
575*b70d1b9fSJean-Philippe Brucker  * @max_dynamic_windows_supported tells the maximum number of windows
576*b70d1b9fSJean-Philippe Brucker  * which the platform can create.
577*b70d1b9fSJean-Philippe Brucker  * @levels tells the maximum number of levels in multi-level IOMMU tables;
578*b70d1b9fSJean-Philippe Brucker  * this allows splitting a table into smaller chunks which reduces
579*b70d1b9fSJean-Philippe Brucker  * the amount of physically contiguous memory required for the table.
580*b70d1b9fSJean-Philippe Brucker  */
581*b70d1b9fSJean-Philippe Brucker struct vfio_iommu_spapr_tce_ddw_info {
582*b70d1b9fSJean-Philippe Brucker 	__u64 pgsizes;			/* Bitmap of supported page sizes */
583*b70d1b9fSJean-Philippe Brucker 	__u32 max_dynamic_windows_supported;
584*b70d1b9fSJean-Philippe Brucker 	__u32 levels;
585*b70d1b9fSJean-Philippe Brucker };
586*b70d1b9fSJean-Philippe Brucker 
587*b70d1b9fSJean-Philippe Brucker /*
588*b70d1b9fSJean-Philippe Brucker  * The SPAPR TCE info struct provides the information about the PCI bus
589*b70d1b9fSJean-Philippe Brucker  * address ranges available for DMA, these values are programmed into
590*b70d1b9fSJean-Philippe Brucker  * the hardware so the guest has to know that information.
591*b70d1b9fSJean-Philippe Brucker  *
592*b70d1b9fSJean-Philippe Brucker  * The DMA 32 bit window start is an absolute PCI bus address.
593*b70d1b9fSJean-Philippe Brucker  * The IOVA address passed via map/unmap ioctls are absolute PCI bus
594*b70d1b9fSJean-Philippe Brucker  * addresses too so the window works as a filter rather than an offset
595*b70d1b9fSJean-Philippe Brucker  * for IOVA addresses.
596*b70d1b9fSJean-Philippe Brucker  *
597*b70d1b9fSJean-Philippe Brucker  * Flags supported:
598*b70d1b9fSJean-Philippe Brucker  * - VFIO_IOMMU_SPAPR_INFO_DDW: informs the userspace that dynamic DMA windows
599*b70d1b9fSJean-Philippe Brucker  *   (DDW) support is present. @ddw is only supported when DDW is present.
600*b70d1b9fSJean-Philippe Brucker  */
601*b70d1b9fSJean-Philippe Brucker struct vfio_iommu_spapr_tce_info {
602*b70d1b9fSJean-Philippe Brucker 	__u32 argsz;
603*b70d1b9fSJean-Philippe Brucker 	__u32 flags;
604*b70d1b9fSJean-Philippe Brucker #define VFIO_IOMMU_SPAPR_INFO_DDW	(1 << 0)	/* DDW supported */
605*b70d1b9fSJean-Philippe Brucker 	__u32 dma32_window_start;	/* 32 bit window start (bytes) */
606*b70d1b9fSJean-Philippe Brucker 	__u32 dma32_window_size;	/* 32 bit window size (bytes) */
607*b70d1b9fSJean-Philippe Brucker 	struct vfio_iommu_spapr_tce_ddw_info ddw;
608*b70d1b9fSJean-Philippe Brucker };
609*b70d1b9fSJean-Philippe Brucker 
610*b70d1b9fSJean-Philippe Brucker #define VFIO_IOMMU_SPAPR_TCE_GET_INFO	_IO(VFIO_TYPE, VFIO_BASE + 12)
611*b70d1b9fSJean-Philippe Brucker 
612*b70d1b9fSJean-Philippe Brucker /*
613*b70d1b9fSJean-Philippe Brucker  * EEH PE operation struct provides ways to:
614*b70d1b9fSJean-Philippe Brucker  * - enable/disable EEH functionality;
615*b70d1b9fSJean-Philippe Brucker  * - unfreeze IO/DMA for frozen PE;
616*b70d1b9fSJean-Philippe Brucker  * - read PE state;
617*b70d1b9fSJean-Philippe Brucker  * - reset PE;
618*b70d1b9fSJean-Philippe Brucker  * - configure PE;
619*b70d1b9fSJean-Philippe Brucker  * - inject EEH error.
620*b70d1b9fSJean-Philippe Brucker  */
621*b70d1b9fSJean-Philippe Brucker struct vfio_eeh_pe_err {
622*b70d1b9fSJean-Philippe Brucker 	__u32 type;
623*b70d1b9fSJean-Philippe Brucker 	__u32 func;
624*b70d1b9fSJean-Philippe Brucker 	__u64 addr;
625*b70d1b9fSJean-Philippe Brucker 	__u64 mask;
626*b70d1b9fSJean-Philippe Brucker };
627*b70d1b9fSJean-Philippe Brucker 
628*b70d1b9fSJean-Philippe Brucker struct vfio_eeh_pe_op {
629*b70d1b9fSJean-Philippe Brucker 	__u32 argsz;
630*b70d1b9fSJean-Philippe Brucker 	__u32 flags;
631*b70d1b9fSJean-Philippe Brucker 	__u32 op;
632*b70d1b9fSJean-Philippe Brucker 	union {
633*b70d1b9fSJean-Philippe Brucker 		struct vfio_eeh_pe_err err;
634*b70d1b9fSJean-Philippe Brucker 	};
635*b70d1b9fSJean-Philippe Brucker };
636*b70d1b9fSJean-Philippe Brucker 
637*b70d1b9fSJean-Philippe Brucker #define VFIO_EEH_PE_DISABLE		0	/* Disable EEH functionality */
638*b70d1b9fSJean-Philippe Brucker #define VFIO_EEH_PE_ENABLE		1	/* Enable EEH functionality  */
639*b70d1b9fSJean-Philippe Brucker #define VFIO_EEH_PE_UNFREEZE_IO		2	/* Enable IO for frozen PE   */
640*b70d1b9fSJean-Philippe Brucker #define VFIO_EEH_PE_UNFREEZE_DMA	3	/* Enable DMA for frozen PE  */
641*b70d1b9fSJean-Philippe Brucker #define VFIO_EEH_PE_GET_STATE		4	/* PE state retrieval        */
642*b70d1b9fSJean-Philippe Brucker #define  VFIO_EEH_PE_STATE_NORMAL	0	/* PE in functional state    */
643*b70d1b9fSJean-Philippe Brucker #define  VFIO_EEH_PE_STATE_RESET	1	/* PE reset in progress      */
644*b70d1b9fSJean-Philippe Brucker #define  VFIO_EEH_PE_STATE_STOPPED	2	/* Stopped DMA and IO        */
645*b70d1b9fSJean-Philippe Brucker #define  VFIO_EEH_PE_STATE_STOPPED_DMA	4	/* Stopped DMA only          */
646*b70d1b9fSJean-Philippe Brucker #define  VFIO_EEH_PE_STATE_UNAVAIL	5	/* State unavailable         */
647*b70d1b9fSJean-Philippe Brucker #define VFIO_EEH_PE_RESET_DEACTIVATE	5	/* Deassert PE reset         */
648*b70d1b9fSJean-Philippe Brucker #define VFIO_EEH_PE_RESET_HOT		6	/* Assert hot reset          */
649*b70d1b9fSJean-Philippe Brucker #define VFIO_EEH_PE_RESET_FUNDAMENTAL	7	/* Assert fundamental reset  */
650*b70d1b9fSJean-Philippe Brucker #define VFIO_EEH_PE_CONFIGURE		8	/* PE configuration          */
651*b70d1b9fSJean-Philippe Brucker #define VFIO_EEH_PE_INJECT_ERR		9	/* Inject EEH error          */
652*b70d1b9fSJean-Philippe Brucker 
653*b70d1b9fSJean-Philippe Brucker #define VFIO_EEH_PE_OP			_IO(VFIO_TYPE, VFIO_BASE + 21)
654*b70d1b9fSJean-Philippe Brucker 
655*b70d1b9fSJean-Philippe Brucker /**
656*b70d1b9fSJean-Philippe Brucker  * VFIO_IOMMU_SPAPR_REGISTER_MEMORY - _IOW(VFIO_TYPE, VFIO_BASE + 17, struct vfio_iommu_spapr_register_memory)
657*b70d1b9fSJean-Philippe Brucker  *
658*b70d1b9fSJean-Philippe Brucker  * Registers user space memory where DMA is allowed. It pins
659*b70d1b9fSJean-Philippe Brucker  * user pages and does the locked memory accounting so
660*b70d1b9fSJean-Philippe Brucker  * subsequent VFIO_IOMMU_MAP_DMA/VFIO_IOMMU_UNMAP_DMA calls
661*b70d1b9fSJean-Philippe Brucker  * get faster.
662*b70d1b9fSJean-Philippe Brucker  */
663*b70d1b9fSJean-Philippe Brucker struct vfio_iommu_spapr_register_memory {
664*b70d1b9fSJean-Philippe Brucker 	__u32	argsz;
665*b70d1b9fSJean-Philippe Brucker 	__u32	flags;
666*b70d1b9fSJean-Philippe Brucker 	__u64	vaddr;				/* Process virtual address */
667*b70d1b9fSJean-Philippe Brucker 	__u64	size;				/* Size of mapping (bytes) */
668*b70d1b9fSJean-Philippe Brucker };
669*b70d1b9fSJean-Philippe Brucker #define VFIO_IOMMU_SPAPR_REGISTER_MEMORY	_IO(VFIO_TYPE, VFIO_BASE + 17)
670*b70d1b9fSJean-Philippe Brucker 
671*b70d1b9fSJean-Philippe Brucker /**
672*b70d1b9fSJean-Philippe Brucker  * VFIO_IOMMU_SPAPR_UNREGISTER_MEMORY - _IOW(VFIO_TYPE, VFIO_BASE + 18, struct vfio_iommu_spapr_register_memory)
673*b70d1b9fSJean-Philippe Brucker  *
674*b70d1b9fSJean-Philippe Brucker  * Unregisters user space memory registered with
675*b70d1b9fSJean-Philippe Brucker  * VFIO_IOMMU_SPAPR_REGISTER_MEMORY.
676*b70d1b9fSJean-Philippe Brucker  * Uses vfio_iommu_spapr_register_memory for parameters.
677*b70d1b9fSJean-Philippe Brucker  */
678*b70d1b9fSJean-Philippe Brucker #define VFIO_IOMMU_SPAPR_UNREGISTER_MEMORY	_IO(VFIO_TYPE, VFIO_BASE + 18)
679*b70d1b9fSJean-Philippe Brucker 
680*b70d1b9fSJean-Philippe Brucker /**
681*b70d1b9fSJean-Philippe Brucker  * VFIO_IOMMU_SPAPR_TCE_CREATE - _IOWR(VFIO_TYPE, VFIO_BASE + 19, struct vfio_iommu_spapr_tce_create)
682*b70d1b9fSJean-Philippe Brucker  *
683*b70d1b9fSJean-Philippe Brucker  * Creates an additional TCE table and programs it (sets a new DMA window)
684*b70d1b9fSJean-Philippe Brucker  * to every IOMMU group in the container. It receives page shift, window
685*b70d1b9fSJean-Philippe Brucker  * size and number of levels in the TCE table being created.
686*b70d1b9fSJean-Philippe Brucker  *
687*b70d1b9fSJean-Philippe Brucker  * It allocates and returns an offset on a PCI bus of the new DMA window.
688*b70d1b9fSJean-Philippe Brucker  */
689*b70d1b9fSJean-Philippe Brucker struct vfio_iommu_spapr_tce_create {
690*b70d1b9fSJean-Philippe Brucker 	__u32 argsz;
691*b70d1b9fSJean-Philippe Brucker 	__u32 flags;
692*b70d1b9fSJean-Philippe Brucker 	/* in */
693*b70d1b9fSJean-Philippe Brucker 	__u32 page_shift;
694*b70d1b9fSJean-Philippe Brucker 	__u32 __resv1;
695*b70d1b9fSJean-Philippe Brucker 	__u64 window_size;
696*b70d1b9fSJean-Philippe Brucker 	__u32 levels;
697*b70d1b9fSJean-Philippe Brucker 	__u32 __resv2;
698*b70d1b9fSJean-Philippe Brucker 	/* out */
699*b70d1b9fSJean-Philippe Brucker 	__u64 start_addr;
700*b70d1b9fSJean-Philippe Brucker };
701*b70d1b9fSJean-Philippe Brucker #define VFIO_IOMMU_SPAPR_TCE_CREATE	_IO(VFIO_TYPE, VFIO_BASE + 19)
702*b70d1b9fSJean-Philippe Brucker 
703*b70d1b9fSJean-Philippe Brucker /**
704*b70d1b9fSJean-Philippe Brucker  * VFIO_IOMMU_SPAPR_TCE_REMOVE - _IOW(VFIO_TYPE, VFIO_BASE + 20, struct vfio_iommu_spapr_tce_remove)
705*b70d1b9fSJean-Philippe Brucker  *
706*b70d1b9fSJean-Philippe Brucker  * Unprograms a TCE table from all groups in the container and destroys it.
707*b70d1b9fSJean-Philippe Brucker  * It receives a PCI bus offset as a window id.
708*b70d1b9fSJean-Philippe Brucker  */
709*b70d1b9fSJean-Philippe Brucker struct vfio_iommu_spapr_tce_remove {
710*b70d1b9fSJean-Philippe Brucker 	__u32 argsz;
711*b70d1b9fSJean-Philippe Brucker 	__u32 flags;
712*b70d1b9fSJean-Philippe Brucker 	/* in */
713*b70d1b9fSJean-Philippe Brucker 	__u64 start_addr;
714*b70d1b9fSJean-Philippe Brucker };
715*b70d1b9fSJean-Philippe Brucker #define VFIO_IOMMU_SPAPR_TCE_REMOVE	_IO(VFIO_TYPE, VFIO_BASE + 20)
716*b70d1b9fSJean-Philippe Brucker 
717*b70d1b9fSJean-Philippe Brucker /* ***************************************************************** */
718*b70d1b9fSJean-Philippe Brucker 
719*b70d1b9fSJean-Philippe Brucker #endif /* VFIO_H */
720