1607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/*
2607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * VFIO API definition
3607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
4607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Copyright (C) 2012 Red Hat, Inc.  All rights reserved.
5607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *     Author: Alex Williamson <alex.williamson@redhat.com>
6607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
7607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * This program is free software; you can redistribute it and/or modify
8607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * it under the terms of the GNU General Public License version 2 as
9607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * published by the Free Software Foundation.
10607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells */
11607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#ifndef _UAPIVFIO_H
12607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define _UAPIVFIO_H
13607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
14607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#include <linux/types.h>
15607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#include <linux/ioctl.h>
16607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
17607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_API_VERSION	0
18607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
19607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
20607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/* Kernel & User level defines for VFIO IOCTLs. */
21607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
22607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/* Extensions */
23607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
24607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_TYPE1_IOMMU		1
255ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy#define VFIO_SPAPR_TCE_IOMMU		2
261ef3e2bc04223ff956dc62abaf2dff1f3322a431Alex Williamson#define VFIO_TYPE1v2_IOMMU		3
27aa429318279b90192f35a97e9ccdc1e83b3a9624Alex Williamson/*
28aa429318279b90192f35a97e9ccdc1e83b3a9624Alex Williamson * IOMMU enforces DMA cache coherence (ex. PCIe NoSnoop stripping).  This
29aa429318279b90192f35a97e9ccdc1e83b3a9624Alex Williamson * capability is subject to change as groups are added or removed.
30aa429318279b90192f35a97e9ccdc1e83b3a9624Alex Williamson */
31aa429318279b90192f35a97e9ccdc1e83b3a9624Alex Williamson#define VFIO_DMA_CC_IOMMU		4
32607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
331b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan/* Check if EEH is supported */
341b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan#define VFIO_EEH			5
351b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan
36f5c9ecebaf2a2c9381973798e389cc019dd983e0Will Deacon/* Two-stage IOMMU */
37f5c9ecebaf2a2c9381973798e389cc019dd983e0Will Deacon#define VFIO_TYPE1_NESTING_IOMMU	6	/* Implies v2 */
38f5c9ecebaf2a2c9381973798e389cc019dd983e0Will Deacon
39607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/*
40607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * The IOCTL interface is designed for extensibility by embedding the
41607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * structure length (argsz) and flags into structures passed between
42607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * kernel and userspace.  We therefore use the _IO() macro for these
43607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * defines to avoid implicitly embedding a size into the ioctl request.
44607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * As structure fields are added, argsz will increase to match and flag
45607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * bits will be defined to indicate additional fields with valid data.
46607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * It's *always* the caller's responsibility to indicate the size of
47607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * the structure passed by setting argsz appropriately.
48607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells */
49607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
50607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_TYPE	(';')
51607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_BASE	100
52607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
53607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/* -------- IOCTLs for VFIO file descriptor (/dev/vfio/vfio) -------- */
54607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
55607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/**
56607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * VFIO_GET_API_VERSION - _IO(VFIO_TYPE, VFIO_BASE + 0)
57607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
58607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Report the version of the VFIO API.  This allows us to bump the entire
59607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * API version should we later need to add or change features in incompatible
60607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * ways.
61607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Return: VFIO_API_VERSION
62607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Availability: Always
63607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells */
64607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_GET_API_VERSION		_IO(VFIO_TYPE, VFIO_BASE + 0)
65607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
66607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/**
67607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * VFIO_CHECK_EXTENSION - _IOW(VFIO_TYPE, VFIO_BASE + 1, __u32)
68607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
69607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Check whether an extension is supported.
70607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Return: 0 if not supported, 1 (or some other positive integer) if supported.
71607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Availability: Always
72607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells */
73607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_CHECK_EXTENSION		_IO(VFIO_TYPE, VFIO_BASE + 1)
74607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
75607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/**
76607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * VFIO_SET_IOMMU - _IOW(VFIO_TYPE, VFIO_BASE + 2, __s32)
77607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
78607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Set the iommu to the given type.  The type must be supported by an
79607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * iommu driver as verified by calling CHECK_EXTENSION using the same
80607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * type.  A group must be set to this file descriptor before this
81607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * ioctl is available.  The IOMMU interfaces enabled by this call are
82607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * specific to the value set.
83607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Return: 0 on success, -errno on failure
84607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Availability: When VFIO group attached
85607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells */
86607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_SET_IOMMU			_IO(VFIO_TYPE, VFIO_BASE + 2)
87607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
88607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/* -------- IOCTLs for GROUP file descriptors (/dev/vfio/$GROUP) -------- */
89607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
90607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/**
91607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * VFIO_GROUP_GET_STATUS - _IOR(VFIO_TYPE, VFIO_BASE + 3,
92607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *						struct vfio_group_status)
93607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
94607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Retrieve information about the group.  Fills in provided
95607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * struct vfio_group_info.  Caller sets argsz.
96607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Return: 0 on succes, -errno on failure.
97607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Availability: Always
98607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells */
99607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howellsstruct vfio_group_status {
100607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	argsz;
101607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	flags;
102607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_GROUP_FLAGS_VIABLE		(1 << 0)
103607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_GROUP_FLAGS_CONTAINER_SET	(1 << 1)
104607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells};
105607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_GROUP_GET_STATUS		_IO(VFIO_TYPE, VFIO_BASE + 3)
106607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
107607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/**
108607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * VFIO_GROUP_SET_CONTAINER - _IOW(VFIO_TYPE, VFIO_BASE + 4, __s32)
109607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
110607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Set the container for the VFIO group to the open VFIO file
111607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * descriptor provided.  Groups may only belong to a single
112607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * container.  Containers may, at their discretion, support multiple
113607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * groups.  Only when a container is set are all of the interfaces
114607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * of the VFIO file descriptor and the VFIO group file descriptor
115607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * available to the user.
116607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Return: 0 on success, -errno on failure.
117607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Availability: Always
118607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells */
119607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_GROUP_SET_CONTAINER	_IO(VFIO_TYPE, VFIO_BASE + 4)
120607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
121607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/**
122607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * VFIO_GROUP_UNSET_CONTAINER - _IO(VFIO_TYPE, VFIO_BASE + 5)
123607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
124607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Remove the group from the attached container.  This is the
125607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * opposite of the SET_CONTAINER call and returns the group to
126607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * an initial state.  All device file descriptors must be released
127607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * prior to calling this interface.  When removing the last group
128607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * from a container, the IOMMU will be disabled and all state lost,
129607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * effectively also returning the VFIO file descriptor to an initial
130607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * state.
131607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Return: 0 on success, -errno on failure.
132607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Availability: When attached to container
133607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells */
134607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_GROUP_UNSET_CONTAINER	_IO(VFIO_TYPE, VFIO_BASE + 5)
135607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
136607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/**
137607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * VFIO_GROUP_GET_DEVICE_FD - _IOW(VFIO_TYPE, VFIO_BASE + 6, char)
138607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
139607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Return a new file descriptor for the device object described by
140607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * the provided string.  The string should match a device listed in
141607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * the devices subdirectory of the IOMMU group sysfs entry.  The
142607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * group containing the device must already be added to this context.
143607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Return: new file descriptor on success, -errno on failure.
144607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Availability: When attached to container
145607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells */
146607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_GROUP_GET_DEVICE_FD	_IO(VFIO_TYPE, VFIO_BASE + 6)
147607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
148607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/* --------------- IOCTLs for DEVICE file descriptors --------------- */
149607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
150607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/**
151607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * VFIO_DEVICE_GET_INFO - _IOR(VFIO_TYPE, VFIO_BASE + 7,
152607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *						struct vfio_device_info)
153607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
154607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Retrieve information about the device.  Fills in provided
155607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * struct vfio_device_info.  Caller sets argsz.
156607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Return: 0 on success, -errno on failure.
157607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells */
158607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howellsstruct vfio_device_info {
159607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	argsz;
160607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	flags;
161607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_DEVICE_FLAGS_RESET	(1 << 0)	/* Device supports reset */
162607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_DEVICE_FLAGS_PCI	(1 << 1)	/* vfio-pci device */
163607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	num_regions;	/* Max region index + 1 */
164607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	num_irqs;	/* Max IRQ index + 1 */
165607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells};
166607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_DEVICE_GET_INFO		_IO(VFIO_TYPE, VFIO_BASE + 7)
167607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
168607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/**
169607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * VFIO_DEVICE_GET_REGION_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 8,
170607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *				       struct vfio_region_info)
171607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
172607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Retrieve information about a device region.  Caller provides
173607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * struct vfio_region_info with index value set.  Caller sets argsz.
174607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Implementation of region mapping is bus driver specific.  This is
175607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * intended to describe MMIO, I/O port, as well as bus specific
176607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * regions (ex. PCI config space).  Zero sized regions may be used
177607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * to describe unimplemented regions (ex. unimplemented PCI BARs).
178607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Return: 0 on success, -errno on failure.
179607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells */
180607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howellsstruct vfio_region_info {
181607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	argsz;
182607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	flags;
183607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_REGION_INFO_FLAG_READ	(1 << 0) /* Region supports read */
184607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_REGION_INFO_FLAG_WRITE	(1 << 1) /* Region supports write */
185607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_REGION_INFO_FLAG_MMAP	(1 << 2) /* Region supports mmap */
186607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	index;		/* Region index */
187607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	resv;		/* Reserved for alignment */
188607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u64	size;		/* Region size (bytes) */
189607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u64	offset;		/* Region offset from start of device fd */
190607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells};
191607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_DEVICE_GET_REGION_INFO	_IO(VFIO_TYPE, VFIO_BASE + 8)
192607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
193607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/**
194607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * VFIO_DEVICE_GET_IRQ_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 9,
195607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *				    struct vfio_irq_info)
196607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
197607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Retrieve information about a device IRQ.  Caller provides
198607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * struct vfio_irq_info with index value set.  Caller sets argsz.
199607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Implementation of IRQ mapping is bus driver specific.  Indexes
200607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * using multiple IRQs are primarily intended to support MSI-like
201607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * interrupt blocks.  Zero count irq blocks may be used to describe
202607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * unimplemented interrupt types.
203607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
204607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * The EVENTFD flag indicates the interrupt index supports eventfd based
205607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * signaling.
206607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
207607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * The MASKABLE flags indicates the index supports MASK and UNMASK
208607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * actions described below.
209607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
210607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * AUTOMASKED indicates that after signaling, the interrupt line is
211607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * automatically masked by VFIO and the user needs to unmask the line
212607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * to receive new interrupts.  This is primarily intended to distinguish
213607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * level triggered interrupts.
214607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
215607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * The NORESIZE flag indicates that the interrupt lines within the index
216607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * are setup as a set and new subindexes cannot be enabled without first
217607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * disabling the entire index.  This is used for interrupts like PCI MSI
218607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * and MSI-X where the driver may only use a subset of the available
219607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * indexes, but VFIO needs to enable a specific number of vectors
220607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * upfront.  In the case of MSI-X, where the user can enable MSI-X and
221607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * then add and unmask vectors, it's up to userspace to make the decision
222607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * whether to allocate the maximum supported number of vectors or tear
223607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * down setup and incrementally increase the vectors as each is enabled.
224607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells */
225607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howellsstruct vfio_irq_info {
226607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	argsz;
227607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	flags;
228607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_IRQ_INFO_EVENTFD		(1 << 0)
229607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_IRQ_INFO_MASKABLE		(1 << 1)
230607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_IRQ_INFO_AUTOMASKED	(1 << 2)
231607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_IRQ_INFO_NORESIZE		(1 << 3)
232607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	index;		/* IRQ index */
233607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	count;		/* Number of IRQs within this index */
234607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells};
235607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_DEVICE_GET_IRQ_INFO	_IO(VFIO_TYPE, VFIO_BASE + 9)
236607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
237607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/**
238607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * VFIO_DEVICE_SET_IRQS - _IOW(VFIO_TYPE, VFIO_BASE + 10, struct vfio_irq_set)
239607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
240607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Set signaling, masking, and unmasking of interrupts.  Caller provides
241607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * struct vfio_irq_set with all fields set.  'start' and 'count' indicate
242607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * the range of subindexes being specified.
243607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
244607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * The DATA flags specify the type of data provided.  If DATA_NONE, the
245607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * operation performs the specified action immediately on the specified
246607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * interrupt(s).  For example, to unmask AUTOMASKED interrupt [0,0]:
247607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * flags = (DATA_NONE|ACTION_UNMASK), index = 0, start = 0, count = 1.
248607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
249607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * DATA_BOOL allows sparse support for the same on arrays of interrupts.
250607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * For example, to mask interrupts [0,1] and [0,3] (but not [0,2]):
251607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * flags = (DATA_BOOL|ACTION_MASK), index = 0, start = 1, count = 3,
252607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * data = {1,0,1}
253607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
254607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * DATA_EVENTFD binds the specified ACTION to the provided __s32 eventfd.
255607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * A value of -1 can be used to either de-assign interrupts if already
256607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * assigned or skip un-assigned interrupts.  For example, to set an eventfd
257607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * to be trigger for interrupts [0,0] and [0,2]:
258607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * flags = (DATA_EVENTFD|ACTION_TRIGGER), index = 0, start = 0, count = 3,
259607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * data = {fd1, -1, fd2}
260607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * If index [0,1] is previously set, two count = 1 ioctls calls would be
261607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * required to set [0,0] and [0,2] without changing [0,1].
262607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
263607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Once a signaling mechanism is set, DATA_BOOL or DATA_NONE can be used
264607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * with ACTION_TRIGGER to perform kernel level interrupt loopback testing
265607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * from userspace (ie. simulate hardware triggering).
266607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
267607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Setting of an event triggering mechanism to userspace for ACTION_TRIGGER
268607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * enables the interrupt index for the device.  Individual subindex interrupts
269607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * can be disabled using the -1 value for DATA_EVENTFD or the index can be
270607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * disabled as a whole with: flags = (DATA_NONE|ACTION_TRIGGER), count = 0.
271607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
272607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Note that ACTION_[UN]MASK specify user->kernel signaling (irqfds) while
273607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * ACTION_TRIGGER specifies kernel->user signaling.
274607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells */
275607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howellsstruct vfio_irq_set {
276607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	argsz;
277607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	flags;
278607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_IRQ_SET_DATA_NONE		(1 << 0) /* Data not present */
279607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_IRQ_SET_DATA_BOOL		(1 << 1) /* Data is bool (u8) */
280607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_IRQ_SET_DATA_EVENTFD	(1 << 2) /* Data is eventfd (s32) */
281607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_IRQ_SET_ACTION_MASK	(1 << 3) /* Mask interrupt */
282607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_IRQ_SET_ACTION_UNMASK	(1 << 4) /* Unmask interrupt */
283607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_IRQ_SET_ACTION_TRIGGER	(1 << 5) /* Trigger interrupt */
284607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	index;
285607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	start;
286607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	count;
287607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u8	data[];
288607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells};
289607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_DEVICE_SET_IRQS		_IO(VFIO_TYPE, VFIO_BASE + 10)
290607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
291607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_IRQ_SET_DATA_TYPE_MASK	(VFIO_IRQ_SET_DATA_NONE | \
292607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells					 VFIO_IRQ_SET_DATA_BOOL | \
293607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells					 VFIO_IRQ_SET_DATA_EVENTFD)
294607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_IRQ_SET_ACTION_TYPE_MASK	(VFIO_IRQ_SET_ACTION_MASK | \
295607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells					 VFIO_IRQ_SET_ACTION_UNMASK | \
296607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells					 VFIO_IRQ_SET_ACTION_TRIGGER)
297607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/**
298607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * VFIO_DEVICE_RESET - _IO(VFIO_TYPE, VFIO_BASE + 11)
299607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
300607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Reset a device.
301607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells */
302607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_DEVICE_RESET		_IO(VFIO_TYPE, VFIO_BASE + 11)
303607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
304607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/*
305607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * The VFIO-PCI bus driver makes use of the following fixed region and
306607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * IRQ index mapping.  Unimplemented regions return a size of zero.
307607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Unimplemented IRQ types return a count of zero.
308607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells */
309607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
310607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howellsenum {
311607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	VFIO_PCI_BAR0_REGION_INDEX,
312607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	VFIO_PCI_BAR1_REGION_INDEX,
313607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	VFIO_PCI_BAR2_REGION_INDEX,
314607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	VFIO_PCI_BAR3_REGION_INDEX,
315607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	VFIO_PCI_BAR4_REGION_INDEX,
316607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	VFIO_PCI_BAR5_REGION_INDEX,
317607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	VFIO_PCI_ROM_REGION_INDEX,
318607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	VFIO_PCI_CONFIG_REGION_INDEX,
31984237a826b261de7ddd3d09ee53ee68cb4138937Alex Williamson	/*
32084237a826b261de7ddd3d09ee53ee68cb4138937Alex Williamson	 * Expose VGA regions defined for PCI base class 03, subclass 00.
32184237a826b261de7ddd3d09ee53ee68cb4138937Alex Williamson	 * This includes I/O port ranges 0x3b0 to 0x3bb and 0x3c0 to 0x3df
32284237a826b261de7ddd3d09ee53ee68cb4138937Alex Williamson	 * as well as the MMIO range 0xa0000 to 0xbffff.  Each implemented
32384237a826b261de7ddd3d09ee53ee68cb4138937Alex Williamson	 * range is found at it's identity mapped offset from the region
32484237a826b261de7ddd3d09ee53ee68cb4138937Alex Williamson	 * offset, for example 0x3b0 is region_info.offset + 0x3b0.  Areas
32584237a826b261de7ddd3d09ee53ee68cb4138937Alex Williamson	 * between described ranges are unimplemented.
32684237a826b261de7ddd3d09ee53ee68cb4138937Alex Williamson	 */
32784237a826b261de7ddd3d09ee53ee68cb4138937Alex Williamson	VFIO_PCI_VGA_REGION_INDEX,
328607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	VFIO_PCI_NUM_REGIONS
329607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells};
330607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
331607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howellsenum {
332607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	VFIO_PCI_INTX_IRQ_INDEX,
333607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	VFIO_PCI_MSI_IRQ_INDEX,
334607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	VFIO_PCI_MSIX_IRQ_INDEX,
335dad9f8972e04cd081a028d8fb1249d746d97fc03Vijay Mohan Pandarathil	VFIO_PCI_ERR_IRQ_INDEX,
336607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	VFIO_PCI_NUM_IRQS
337607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells};
338607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
3398b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson/**
3408b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson * VFIO_DEVICE_GET_PCI_HOT_RESET_INFO - _IORW(VFIO_TYPE, VFIO_BASE + 12,
3418b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson *					      struct vfio_pci_hot_reset_info)
3428b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson *
3438b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson * Return: 0 on success, -errno on failure:
3448b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson *	-enospc = insufficient buffer, -enodev = unsupported for device.
3458b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson */
3468b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamsonstruct vfio_pci_dependent_device {
3478b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson	__u32	group_id;
3488b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson	__u16	segment;
3498b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson	__u8	bus;
3508b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson	__u8	devfn; /* Use PCI_SLOT/PCI_FUNC */
3518b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson};
3528b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson
3538b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamsonstruct vfio_pci_hot_reset_info {
3548b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson	__u32	argsz;
3558b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson	__u32	flags;
3568b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson	__u32	count;
3578b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson	struct vfio_pci_dependent_device	devices[];
3588b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson};
3598b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson
3608b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson#define VFIO_DEVICE_GET_PCI_HOT_RESET_INFO	_IO(VFIO_TYPE, VFIO_BASE + 12)
3618b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson
3628b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson/**
3638b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson * VFIO_DEVICE_PCI_HOT_RESET - _IOW(VFIO_TYPE, VFIO_BASE + 13,
3648b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson *				    struct vfio_pci_hot_reset)
3658b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson *
3668b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson * Return: 0 on success, -errno on failure.
3678b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson */
3688b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamsonstruct vfio_pci_hot_reset {
3698b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson	__u32	argsz;
3708b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson	__u32	flags;
3718b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson	__u32	count;
3728b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson	__s32	group_fds[];
3738b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson};
3748b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson
3758b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson#define VFIO_DEVICE_PCI_HOT_RESET	_IO(VFIO_TYPE, VFIO_BASE + 13)
3768b27ee60bfd6bbb84d2df28fa706c5c5081066caAlex Williamson
377607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/* -------- API for Type1 VFIO IOMMU -------- */
378607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
379607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/**
380607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * VFIO_IOMMU_GET_INFO - _IOR(VFIO_TYPE, VFIO_BASE + 12, struct vfio_iommu_info)
381607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
382607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Retrieve information about the IOMMU object. Fills in provided
383607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * struct vfio_iommu_info. Caller sets argsz.
384607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
385607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * XXX Should we do these by CHECK_EXTENSION too?
386607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells */
387607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howellsstruct vfio_iommu_type1_info {
388607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	argsz;
389607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	flags;
390607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_IOMMU_INFO_PGSIZES (1 << 0)	/* supported page sizes info */
391607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u64	iova_pgsizes;		/* Bitmap of supported page sizes */
392607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells};
393607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
394607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12)
395607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
396607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/**
397607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * VFIO_IOMMU_MAP_DMA - _IOW(VFIO_TYPE, VFIO_BASE + 13, struct vfio_dma_map)
398607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
399607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Map process virtual addresses to IO virtual addresses using the
400607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * provided struct vfio_dma_map. Caller sets argsz. READ &/ WRITE required.
401607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells */
402607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howellsstruct vfio_iommu_type1_dma_map {
403607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	argsz;
404607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	flags;
405607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_DMA_MAP_FLAG_READ (1 << 0)		/* readable from device */
406607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_DMA_MAP_FLAG_WRITE (1 << 1)	/* writable from device */
407607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u64	vaddr;				/* Process virtual address */
408607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u64	iova;				/* IO virtual address */
409607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u64	size;				/* Size of mapping (bytes) */
410607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells};
411607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
412607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_IOMMU_MAP_DMA _IO(VFIO_TYPE, VFIO_BASE + 13)
413607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
414607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells/**
415166fd7d94afdac040b28c473e45241820ca522a2Alex Williamson * VFIO_IOMMU_UNMAP_DMA - _IOWR(VFIO_TYPE, VFIO_BASE + 14,
416166fd7d94afdac040b28c473e45241820ca522a2Alex Williamson *							struct vfio_dma_unmap)
417607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells *
418607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells * Unmap IO virtual addresses using the provided struct vfio_dma_unmap.
419166fd7d94afdac040b28c473e45241820ca522a2Alex Williamson * Caller sets argsz.  The actual unmapped size is returned in the size
420166fd7d94afdac040b28c473e45241820ca522a2Alex Williamson * field.  No guarantee is made to the user that arbitrary unmaps of iova
421166fd7d94afdac040b28c473e45241820ca522a2Alex Williamson * or size different from those used in the original mapping call will
422166fd7d94afdac040b28c473e45241820ca522a2Alex Williamson * succeed.
423607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells */
424607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howellsstruct vfio_iommu_type1_dma_unmap {
425607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	argsz;
426607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u32	flags;
427607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u64	iova;				/* IO virtual address */
428607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells	__u64	size;				/* Size of mapping (bytes) */
429607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells};
430607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
431607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#define VFIO_IOMMU_UNMAP_DMA _IO(VFIO_TYPE, VFIO_BASE + 14)
432607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells
4335ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy/*
4345ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy * IOCTLs to enable/disable IOMMU container usage.
4355ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy * No parameters are supported.
4365ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy */
4375ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy#define VFIO_IOMMU_ENABLE	_IO(VFIO_TYPE, VFIO_BASE + 15)
4385ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy#define VFIO_IOMMU_DISABLE	_IO(VFIO_TYPE, VFIO_BASE + 16)
4395ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy
4405ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy/* -------- Additional API for SPAPR TCE (Server POWERPC) IOMMU -------- */
4415ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy
4425ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy/*
4435ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy * The SPAPR TCE info struct provides the information about the PCI bus
4445ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy * address ranges available for DMA, these values are programmed into
4455ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy * the hardware so the guest has to know that information.
4465ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy *
4475ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy * The DMA 32 bit window start is an absolute PCI bus address.
4485ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy * The IOVA address passed via map/unmap ioctls are absolute PCI bus
4495ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy * addresses too so the window works as a filter rather than an offset
4505ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy * for IOVA addresses.
4515ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy *
4525ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy * A flag will need to be added if other page sizes are supported,
4535ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy * so as defined here, it is always 4k.
4545ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy */
4555ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiystruct vfio_iommu_spapr_tce_info {
4565ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy	__u32 argsz;
4575ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy	__u32 flags;			/* reserved for future use */
4585ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy	__u32 dma32_window_start;	/* 32 bit window start (bytes) */
4595ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy	__u32 dma32_window_size;	/* 32 bit window size (bytes) */
4605ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy};
4615ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy
4625ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy#define VFIO_IOMMU_SPAPR_TCE_GET_INFO	_IO(VFIO_TYPE, VFIO_BASE + 12)
4635ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy
4641b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan/*
4651b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan * EEH PE operation struct provides ways to:
4661b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan * - enable/disable EEH functionality;
4671b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan * - unfreeze IO/DMA for frozen PE;
4681b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan * - read PE state;
4691b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan * - reset PE;
4701b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan * - configure PE.
4711b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan */
4721b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shanstruct vfio_eeh_pe_op {
4731b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan	__u32 argsz;
4741b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan	__u32 flags;
4751b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan	__u32 op;
4761b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan};
4771b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan
4781b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan#define VFIO_EEH_PE_DISABLE		0	/* Disable EEH functionality */
4791b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan#define VFIO_EEH_PE_ENABLE		1	/* Enable EEH functionality  */
4801b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan#define VFIO_EEH_PE_UNFREEZE_IO		2	/* Enable IO for frozen PE   */
4811b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan#define VFIO_EEH_PE_UNFREEZE_DMA	3	/* Enable DMA for frozen PE  */
4821b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan#define VFIO_EEH_PE_GET_STATE		4	/* PE state retrieval        */
4831b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan#define  VFIO_EEH_PE_STATE_NORMAL	0	/* PE in functional state    */
4841b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan#define  VFIO_EEH_PE_STATE_RESET	1	/* PE reset in progress      */
4851b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan#define  VFIO_EEH_PE_STATE_STOPPED	2	/* Stopped DMA and IO        */
4861b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan#define  VFIO_EEH_PE_STATE_STOPPED_DMA	4	/* Stopped DMA only          */
4871b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan#define  VFIO_EEH_PE_STATE_UNAVAIL	5	/* State unavailable         */
4881b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan#define VFIO_EEH_PE_RESET_DEACTIVATE	5	/* Deassert PE reset         */
4891b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan#define VFIO_EEH_PE_RESET_HOT		6	/* Assert hot reset          */
4901b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan#define VFIO_EEH_PE_RESET_FUNDAMENTAL	7	/* Assert fundamental reset  */
4911b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan#define VFIO_EEH_PE_CONFIGURE		8	/* PE configuration          */
4921b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan
4931b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan#define VFIO_EEH_PE_OP			_IO(VFIO_TYPE, VFIO_BASE + 21)
4941b69be5e8afc634f39ad695a6ab6aad0cf0975c7Gavin Shan
4955ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy/* ***************************************************************** */
4965ffd229c02731a91d08ca21e76b503c5bbb5c095Alexey Kardashevskiy
497607ca46e97a1b6594b29647d98a32d545c24bdffDavid Howells#endif /* _UAPIVFIO_H */
498