1e2be04c7SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ 2607ca46eSDavid Howells /* 3607ca46eSDavid Howells * VFIO API definition 4607ca46eSDavid Howells * 5607ca46eSDavid Howells * Copyright (C) 2012 Red Hat, Inc. All rights reserved. 6607ca46eSDavid Howells * Author: Alex Williamson <alex.williamson@redhat.com> 7607ca46eSDavid Howells * 8607ca46eSDavid Howells * This program is free software; you can redistribute it and/or modify 9607ca46eSDavid Howells * it under the terms of the GNU General Public License version 2 as 10607ca46eSDavid Howells * published by the Free Software Foundation. 11607ca46eSDavid Howells */ 12607ca46eSDavid Howells #ifndef _UAPIVFIO_H 13607ca46eSDavid Howells #define _UAPIVFIO_H 14607ca46eSDavid Howells 15607ca46eSDavid Howells #include <linux/types.h> 16607ca46eSDavid Howells #include <linux/ioctl.h> 17607ca46eSDavid Howells 18607ca46eSDavid Howells #define VFIO_API_VERSION 0 19607ca46eSDavid Howells 20607ca46eSDavid Howells 21607ca46eSDavid Howells /* Kernel & User level defines for VFIO IOCTLs. */ 22607ca46eSDavid Howells 23607ca46eSDavid Howells /* Extensions */ 24607ca46eSDavid Howells 25607ca46eSDavid Howells #define VFIO_TYPE1_IOMMU 1 265ffd229cSAlexey Kardashevskiy #define VFIO_SPAPR_TCE_IOMMU 2 271ef3e2bcSAlex Williamson #define VFIO_TYPE1v2_IOMMU 3 28aa429318SAlex Williamson /* 29aa429318SAlex Williamson * IOMMU enforces DMA cache coherence (ex. PCIe NoSnoop stripping). This 30aa429318SAlex Williamson * capability is subject to change as groups are added or removed. 31aa429318SAlex Williamson */ 32aa429318SAlex Williamson #define VFIO_DMA_CC_IOMMU 4 33607ca46eSDavid Howells 341b69be5eSGavin Shan /* Check if EEH is supported */ 351b69be5eSGavin Shan #define VFIO_EEH 5 361b69be5eSGavin Shan 37f5c9ecebSWill Deacon /* Two-stage IOMMU */ 38f5c9ecebSWill Deacon #define VFIO_TYPE1_NESTING_IOMMU 6 /* Implies v2 */ 39f5c9ecebSWill Deacon 402157e7b8SAlexey Kardashevskiy #define VFIO_SPAPR_TCE_v2_IOMMU 7 412157e7b8SAlexey Kardashevskiy 42607ca46eSDavid Howells /* 4303a76b60SAlex Williamson * The No-IOMMU IOMMU offers no translation or isolation for devices and 4403a76b60SAlex Williamson * supports no ioctls outside of VFIO_CHECK_EXTENSION. Use of VFIO's No-IOMMU 4503a76b60SAlex Williamson * code will taint the host kernel and should be used with extreme caution. 4603a76b60SAlex Williamson */ 4703a76b60SAlex Williamson #define VFIO_NOIOMMU_IOMMU 8 4803a76b60SAlex Williamson 4903a76b60SAlex Williamson /* 50607ca46eSDavid Howells * The IOCTL interface is designed for extensibility by embedding the 51607ca46eSDavid Howells * structure length (argsz) and flags into structures passed between 52607ca46eSDavid Howells * kernel and userspace. We therefore use the _IO() macro for these 53607ca46eSDavid Howells * defines to avoid implicitly embedding a size into the ioctl request. 54607ca46eSDavid Howells * As structure fields are added, argsz will increase to match and flag 55607ca46eSDavid Howells * bits will be defined to indicate additional fields with valid data. 56607ca46eSDavid Howells * It's *always* the caller's responsibility to indicate the size of 57607ca46eSDavid Howells * the structure passed by setting argsz appropriately. 58607ca46eSDavid Howells */ 59607ca46eSDavid Howells 60607ca46eSDavid Howells #define VFIO_TYPE (';') 61607ca46eSDavid Howells #define VFIO_BASE 100 62607ca46eSDavid Howells 63c84982adSAlex Williamson /* 64c84982adSAlex Williamson * For extension of INFO ioctls, VFIO makes use of a capability chain 65c84982adSAlex Williamson * designed after PCI/e capabilities. A flag bit indicates whether 66c84982adSAlex Williamson * this capability chain is supported and a field defined in the fixed 67c84982adSAlex Williamson * structure defines the offset of the first capability in the chain. 68c84982adSAlex Williamson * This field is only valid when the corresponding bit in the flags 69c84982adSAlex Williamson * bitmap is set. This offset field is relative to the start of the 70c84982adSAlex Williamson * INFO buffer, as is the next field within each capability header. 71c84982adSAlex Williamson * The id within the header is a shared address space per INFO ioctl, 72c84982adSAlex Williamson * while the version field is specific to the capability id. The 73c84982adSAlex Williamson * contents following the header are specific to the capability id. 74c84982adSAlex Williamson */ 75c84982adSAlex Williamson struct vfio_info_cap_header { 76c84982adSAlex Williamson __u16 id; /* Identifies capability */ 77c84982adSAlex Williamson __u16 version; /* Version specific to the capability ID */ 78c84982adSAlex Williamson __u32 next; /* Offset of next capability */ 79c84982adSAlex Williamson }; 80c84982adSAlex Williamson 81c84982adSAlex Williamson /* 82c84982adSAlex Williamson * Callers of INFO ioctls passing insufficiently sized buffers will see 83c84982adSAlex Williamson * the capability chain flag bit set, a zero value for the first capability 84c84982adSAlex Williamson * offset (if available within the provided argsz), and argsz will be 85c84982adSAlex Williamson * updated to report the necessary buffer size. For compatibility, the 86c84982adSAlex Williamson * INFO ioctl will not report error in this case, but the capability chain 87c84982adSAlex Williamson * will not be available. 88c84982adSAlex Williamson */ 89c84982adSAlex Williamson 90607ca46eSDavid Howells /* -------- IOCTLs for VFIO file descriptor (/dev/vfio/vfio) -------- */ 91607ca46eSDavid Howells 92607ca46eSDavid Howells /** 93607ca46eSDavid Howells * VFIO_GET_API_VERSION - _IO(VFIO_TYPE, VFIO_BASE + 0) 94607ca46eSDavid Howells * 95607ca46eSDavid Howells * Report the version of the VFIO API. This allows us to bump the entire 96607ca46eSDavid Howells * API version should we later need to add or change features in incompatible 97607ca46eSDavid Howells * ways. 98607ca46eSDavid Howells * Return: VFIO_API_VERSION 99607ca46eSDavid Howells * Availability: Always 100607ca46eSDavid Howells */ 101607ca46eSDavid Howells #define VFIO_GET_API_VERSION _IO(VFIO_TYPE, VFIO_BASE + 0) 102607ca46eSDavid Howells 103607ca46eSDavid Howells /** 104607ca46eSDavid Howells * VFIO_CHECK_EXTENSION - _IOW(VFIO_TYPE, VFIO_BASE + 1, __u32) 105607ca46eSDavid Howells * 106607ca46eSDavid Howells * Check whether an extension is supported. 107607ca46eSDavid Howells * Return: 0 if not supported, 1 (or some other positive integer) if supported. 108607ca46eSDavid Howells * Availability: Always 109607ca46eSDavid Howells */ 110607ca46eSDavid Howells #define VFIO_CHECK_EXTENSION _IO(VFIO_TYPE, VFIO_BASE + 1) 111607ca46eSDavid Howells 112607ca46eSDavid Howells /** 113607ca46eSDavid Howells * VFIO_SET_IOMMU - _IOW(VFIO_TYPE, VFIO_BASE + 2, __s32) 114607ca46eSDavid Howells * 115607ca46eSDavid Howells * Set the iommu to the given type. The type must be supported by an 116607ca46eSDavid Howells * iommu driver as verified by calling CHECK_EXTENSION using the same 117607ca46eSDavid Howells * type. A group must be set to this file descriptor before this 118607ca46eSDavid Howells * ioctl is available. The IOMMU interfaces enabled by this call are 119607ca46eSDavid Howells * specific to the value set. 120607ca46eSDavid Howells * Return: 0 on success, -errno on failure 121607ca46eSDavid Howells * Availability: When VFIO group attached 122607ca46eSDavid Howells */ 123607ca46eSDavid Howells #define VFIO_SET_IOMMU _IO(VFIO_TYPE, VFIO_BASE + 2) 124607ca46eSDavid Howells 125607ca46eSDavid Howells /* -------- IOCTLs for GROUP file descriptors (/dev/vfio/$GROUP) -------- */ 126607ca46eSDavid Howells 127607ca46eSDavid Howells /** 128607ca46eSDavid Howells * VFIO_GROUP_GET_STATUS - _IOR(VFIO_TYPE, VFIO_BASE + 3, 129607ca46eSDavid Howells * struct vfio_group_status) 130607ca46eSDavid Howells * 131607ca46eSDavid Howells * Retrieve information about the group. Fills in provided 132607ca46eSDavid Howells * struct vfio_group_info. Caller sets argsz. 133607ca46eSDavid Howells * Return: 0 on succes, -errno on failure. 134607ca46eSDavid Howells * Availability: Always 135607ca46eSDavid Howells */ 136607ca46eSDavid Howells struct vfio_group_status { 137607ca46eSDavid Howells __u32 argsz; 138607ca46eSDavid Howells __u32 flags; 139607ca46eSDavid Howells #define VFIO_GROUP_FLAGS_VIABLE (1 << 0) 140607ca46eSDavid Howells #define VFIO_GROUP_FLAGS_CONTAINER_SET (1 << 1) 141607ca46eSDavid Howells }; 142607ca46eSDavid Howells #define VFIO_GROUP_GET_STATUS _IO(VFIO_TYPE, VFIO_BASE + 3) 143607ca46eSDavid Howells 144607ca46eSDavid Howells /** 145607ca46eSDavid Howells * VFIO_GROUP_SET_CONTAINER - _IOW(VFIO_TYPE, VFIO_BASE + 4, __s32) 146607ca46eSDavid Howells * 147607ca46eSDavid Howells * Set the container for the VFIO group to the open VFIO file 148607ca46eSDavid Howells * descriptor provided. Groups may only belong to a single 149607ca46eSDavid Howells * container. Containers may, at their discretion, support multiple 150607ca46eSDavid Howells * groups. Only when a container is set are all of the interfaces 151607ca46eSDavid Howells * of the VFIO file descriptor and the VFIO group file descriptor 152607ca46eSDavid Howells * available to the user. 153607ca46eSDavid Howells * Return: 0 on success, -errno on failure. 154607ca46eSDavid Howells * Availability: Always 155607ca46eSDavid Howells */ 156607ca46eSDavid Howells #define VFIO_GROUP_SET_CONTAINER _IO(VFIO_TYPE, VFIO_BASE + 4) 157607ca46eSDavid Howells 158607ca46eSDavid Howells /** 159607ca46eSDavid Howells * VFIO_GROUP_UNSET_CONTAINER - _IO(VFIO_TYPE, VFIO_BASE + 5) 160607ca46eSDavid Howells * 161607ca46eSDavid Howells * Remove the group from the attached container. This is the 162607ca46eSDavid Howells * opposite of the SET_CONTAINER call and returns the group to 163607ca46eSDavid Howells * an initial state. All device file descriptors must be released 164607ca46eSDavid Howells * prior to calling this interface. When removing the last group 165607ca46eSDavid Howells * from a container, the IOMMU will be disabled and all state lost, 166607ca46eSDavid Howells * effectively also returning the VFIO file descriptor to an initial 167607ca46eSDavid Howells * state. 168607ca46eSDavid Howells * Return: 0 on success, -errno on failure. 169607ca46eSDavid Howells * Availability: When attached to container 170607ca46eSDavid Howells */ 171607ca46eSDavid Howells #define VFIO_GROUP_UNSET_CONTAINER _IO(VFIO_TYPE, VFIO_BASE + 5) 172607ca46eSDavid Howells 173607ca46eSDavid Howells /** 174607ca46eSDavid Howells * VFIO_GROUP_GET_DEVICE_FD - _IOW(VFIO_TYPE, VFIO_BASE + 6, char) 175607ca46eSDavid Howells * 176607ca46eSDavid Howells * Return a new file descriptor for the device object described by 177607ca46eSDavid Howells * the provided string. The string should match a device listed in 178607ca46eSDavid Howells * the devices subdirectory of the IOMMU group sysfs entry. The 179607ca46eSDavid Howells * group containing the device must already be added to this context. 180607ca46eSDavid Howells * Return: new file descriptor on success, -errno on failure. 181607ca46eSDavid Howells * Availability: When attached to container 182607ca46eSDavid Howells */ 183607ca46eSDavid Howells #define VFIO_GROUP_GET_DEVICE_FD _IO(VFIO_TYPE, VFIO_BASE + 6) 184607ca46eSDavid Howells 185607ca46eSDavid Howells /* --------------- IOCTLs for DEVICE file descriptors --------------- */ 186607ca46eSDavid Howells 187607ca46eSDavid Howells /** 188607ca46eSDavid Howells * VFIO_DEVICE_GET_INFO - _IOR(VFIO_TYPE, VFIO_BASE + 7, 189607ca46eSDavid Howells * struct vfio_device_info) 190607ca46eSDavid Howells * 191607ca46eSDavid Howells * Retrieve information about the device. Fills in provided 192607ca46eSDavid Howells * struct vfio_device_info. Caller sets argsz. 193607ca46eSDavid Howells * Return: 0 on success, -errno on failure. 194607ca46eSDavid Howells */ 195607ca46eSDavid Howells struct vfio_device_info { 196607ca46eSDavid Howells __u32 argsz; 197607ca46eSDavid Howells __u32 flags; 198607ca46eSDavid Howells #define VFIO_DEVICE_FLAGS_RESET (1 << 0) /* Device supports reset */ 199607ca46eSDavid Howells #define VFIO_DEVICE_FLAGS_PCI (1 << 1) /* vfio-pci device */ 2009df85aaaSAntonios Motakis #define VFIO_DEVICE_FLAGS_PLATFORM (1 << 2) /* vfio-platform device */ 20136fe431fSAntonios Motakis #define VFIO_DEVICE_FLAGS_AMBA (1 << 3) /* vfio-amba device */ 202e01bcdd6SDong Jia Shi #define VFIO_DEVICE_FLAGS_CCW (1 << 4) /* vfio-ccw device */ 203e06670c5STony Krowiak #define VFIO_DEVICE_FLAGS_AP (1 << 5) /* vfio-ap device */ 204607ca46eSDavid Howells __u32 num_regions; /* Max region index + 1 */ 205607ca46eSDavid Howells __u32 num_irqs; /* Max IRQ index + 1 */ 206607ca46eSDavid Howells }; 207607ca46eSDavid Howells #define VFIO_DEVICE_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 7) 208607ca46eSDavid Howells 2092818c6e9SKirti Wankhede /* 2102818c6e9SKirti Wankhede * Vendor driver using Mediated device framework should provide device_api 2112818c6e9SKirti Wankhede * attribute in supported type attribute groups. Device API string should be one 2122818c6e9SKirti Wankhede * of the following corresponding to device flags in vfio_device_info structure. 2132818c6e9SKirti Wankhede */ 2142818c6e9SKirti Wankhede 2152818c6e9SKirti Wankhede #define VFIO_DEVICE_API_PCI_STRING "vfio-pci" 2162818c6e9SKirti Wankhede #define VFIO_DEVICE_API_PLATFORM_STRING "vfio-platform" 2172818c6e9SKirti Wankhede #define VFIO_DEVICE_API_AMBA_STRING "vfio-amba" 218aec390b9SDong Jia Shi #define VFIO_DEVICE_API_CCW_STRING "vfio-ccw" 21965f06713STony Krowiak #define VFIO_DEVICE_API_AP_STRING "vfio-ap" 2202818c6e9SKirti Wankhede 221607ca46eSDavid Howells /** 222607ca46eSDavid Howells * VFIO_DEVICE_GET_REGION_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 8, 223607ca46eSDavid Howells * struct vfio_region_info) 224607ca46eSDavid Howells * 225607ca46eSDavid Howells * Retrieve information about a device region. Caller provides 226607ca46eSDavid Howells * struct vfio_region_info with index value set. Caller sets argsz. 227607ca46eSDavid Howells * Implementation of region mapping is bus driver specific. This is 228607ca46eSDavid Howells * intended to describe MMIO, I/O port, as well as bus specific 229607ca46eSDavid Howells * regions (ex. PCI config space). Zero sized regions may be used 230607ca46eSDavid Howells * to describe unimplemented regions (ex. unimplemented PCI BARs). 231607ca46eSDavid Howells * Return: 0 on success, -errno on failure. 232607ca46eSDavid Howells */ 233607ca46eSDavid Howells struct vfio_region_info { 234607ca46eSDavid Howells __u32 argsz; 235607ca46eSDavid Howells __u32 flags; 236607ca46eSDavid Howells #define VFIO_REGION_INFO_FLAG_READ (1 << 0) /* Region supports read */ 237607ca46eSDavid Howells #define VFIO_REGION_INFO_FLAG_WRITE (1 << 1) /* Region supports write */ 238607ca46eSDavid Howells #define VFIO_REGION_INFO_FLAG_MMAP (1 << 2) /* Region supports mmap */ 239ff63eb63SAlex Williamson #define VFIO_REGION_INFO_FLAG_CAPS (1 << 3) /* Info supports caps */ 240607ca46eSDavid Howells __u32 index; /* Region index */ 241ff63eb63SAlex Williamson __u32 cap_offset; /* Offset within info struct of first cap */ 242607ca46eSDavid Howells __u64 size; /* Region size (bytes) */ 243607ca46eSDavid Howells __u64 offset; /* Region offset from start of device fd */ 244607ca46eSDavid Howells }; 245607ca46eSDavid Howells #define VFIO_DEVICE_GET_REGION_INFO _IO(VFIO_TYPE, VFIO_BASE + 8) 246607ca46eSDavid Howells 247ff63eb63SAlex Williamson /* 248ff63eb63SAlex Williamson * The sparse mmap capability allows finer granularity of specifying areas 249ff63eb63SAlex Williamson * within a region with mmap support. When specified, the user should only 250ff63eb63SAlex Williamson * mmap the offset ranges specified by the areas array. mmaps outside of the 251ff63eb63SAlex Williamson * areas specified may fail (such as the range covering a PCI MSI-X table) or 252ff63eb63SAlex Williamson * may result in improper device behavior. 253ff63eb63SAlex Williamson * 254ff63eb63SAlex Williamson * The structures below define version 1 of this capability. 255ff63eb63SAlex Williamson */ 256ff63eb63SAlex Williamson #define VFIO_REGION_INFO_CAP_SPARSE_MMAP 1 257ff63eb63SAlex Williamson 258ff63eb63SAlex Williamson struct vfio_region_sparse_mmap_area { 259ff63eb63SAlex Williamson __u64 offset; /* Offset of mmap'able area within region */ 260ff63eb63SAlex Williamson __u64 size; /* Size of mmap'able area */ 261ff63eb63SAlex Williamson }; 262ff63eb63SAlex Williamson 263ff63eb63SAlex Williamson struct vfio_region_info_cap_sparse_mmap { 264ff63eb63SAlex Williamson struct vfio_info_cap_header header; 265ff63eb63SAlex Williamson __u32 nr_areas; 266ff63eb63SAlex Williamson __u32 reserved; 267ff63eb63SAlex Williamson struct vfio_region_sparse_mmap_area areas[]; 268ff63eb63SAlex Williamson }; 269ff63eb63SAlex Williamson 270c7bb4cb4SAlex Williamson /* 271c7bb4cb4SAlex Williamson * The device specific type capability allows regions unique to a specific 272c7bb4cb4SAlex Williamson * device or class of devices to be exposed. This helps solve the problem for 273c7bb4cb4SAlex Williamson * vfio bus drivers of defining which region indexes correspond to which region 274c7bb4cb4SAlex Williamson * on the device, without needing to resort to static indexes, as done by 275c7bb4cb4SAlex Williamson * vfio-pci. For instance, if we were to go back in time, we might remove 276c7bb4cb4SAlex Williamson * VFIO_PCI_VGA_REGION_INDEX and let vfio-pci simply define that all indexes 277c7bb4cb4SAlex Williamson * greater than or equal to VFIO_PCI_NUM_REGIONS are device specific and we'd 278c7bb4cb4SAlex Williamson * make a "VGA" device specific type to describe the VGA access space. This 279c7bb4cb4SAlex Williamson * means that non-VGA devices wouldn't need to waste this index, and thus the 280c7bb4cb4SAlex Williamson * address space associated with it due to implementation of device file 281c7bb4cb4SAlex Williamson * descriptor offsets in vfio-pci. 282c7bb4cb4SAlex Williamson * 283c7bb4cb4SAlex Williamson * The current implementation is now part of the user ABI, so we can't use this 284c7bb4cb4SAlex Williamson * for VGA, but there are other upcoming use cases, such as opregions for Intel 285c7bb4cb4SAlex Williamson * IGD devices and framebuffers for vGPU devices. We missed VGA, but we'll 286c7bb4cb4SAlex Williamson * use this for future additions. 287c7bb4cb4SAlex Williamson * 288c7bb4cb4SAlex Williamson * The structure below defines version 1 of this capability. 289c7bb4cb4SAlex Williamson */ 290c7bb4cb4SAlex Williamson #define VFIO_REGION_INFO_CAP_TYPE 2 291c7bb4cb4SAlex Williamson 292c7bb4cb4SAlex Williamson struct vfio_region_info_cap_type { 293c7bb4cb4SAlex Williamson struct vfio_info_cap_header header; 294c7bb4cb4SAlex Williamson __u32 type; /* global per bus driver */ 295c7bb4cb4SAlex Williamson __u32 subtype; /* type specific */ 296c7bb4cb4SAlex Williamson }; 297c7bb4cb4SAlex Williamson 2985846ff54SAlex Williamson #define VFIO_REGION_TYPE_PCI_VENDOR_TYPE (1 << 31) 2995846ff54SAlex Williamson #define VFIO_REGION_TYPE_PCI_VENDOR_MASK (0xffff) 3005846ff54SAlex Williamson 301f572a960SAlex Williamson /* 8086 Vendor sub-types */ 3025846ff54SAlex Williamson #define VFIO_REGION_SUBTYPE_INTEL_IGD_OPREGION (1) 303f572a960SAlex Williamson #define VFIO_REGION_SUBTYPE_INTEL_IGD_HOST_CFG (2) 304f572a960SAlex Williamson #define VFIO_REGION_SUBTYPE_INTEL_IGD_LPC_CFG (3) 3055846ff54SAlex Williamson 3063cdf7525SGerd Hoffmann #define VFIO_REGION_TYPE_GFX (1) 3073cdf7525SGerd Hoffmann #define VFIO_REGION_SUBTYPE_GFX_EDID (1) 3083cdf7525SGerd Hoffmann 3093cdf7525SGerd Hoffmann /** 3103cdf7525SGerd Hoffmann * struct vfio_region_gfx_edid - EDID region layout. 3113cdf7525SGerd Hoffmann * 3123cdf7525SGerd Hoffmann * Set display link state and EDID blob. 3133cdf7525SGerd Hoffmann * 3143cdf7525SGerd Hoffmann * The EDID blob has monitor information such as brand, name, serial 3153cdf7525SGerd Hoffmann * number, physical size, supported video modes and more. 3163cdf7525SGerd Hoffmann * 3173cdf7525SGerd Hoffmann * This special region allows userspace (typically qemu) set a virtual 3183cdf7525SGerd Hoffmann * EDID for the virtual monitor, which allows a flexible display 3193cdf7525SGerd Hoffmann * configuration. 3203cdf7525SGerd Hoffmann * 3213cdf7525SGerd Hoffmann * For the edid blob spec look here: 3223cdf7525SGerd Hoffmann * https://en.wikipedia.org/wiki/Extended_Display_Identification_Data 3233cdf7525SGerd Hoffmann * 3243cdf7525SGerd Hoffmann * On linux systems you can find the EDID blob in sysfs: 3253cdf7525SGerd Hoffmann * /sys/class/drm/${card}/${connector}/edid 3263cdf7525SGerd Hoffmann * 3273cdf7525SGerd Hoffmann * You can use the edid-decode ulility (comes with xorg-x11-utils) to 3283cdf7525SGerd Hoffmann * decode the EDID blob. 3293cdf7525SGerd Hoffmann * 3303cdf7525SGerd Hoffmann * @edid_offset: location of the edid blob, relative to the 3313cdf7525SGerd Hoffmann * start of the region (readonly). 3323cdf7525SGerd Hoffmann * @edid_max_size: max size of the edid blob (readonly). 3333cdf7525SGerd Hoffmann * @edid_size: actual edid size (read/write). 3343cdf7525SGerd Hoffmann * @link_state: display link state (read/write). 3353cdf7525SGerd Hoffmann * VFIO_DEVICE_GFX_LINK_STATE_UP: Monitor is turned on. 3363cdf7525SGerd Hoffmann * VFIO_DEVICE_GFX_LINK_STATE_DOWN: Monitor is turned off. 3373cdf7525SGerd Hoffmann * @max_xres: max display width (0 == no limitation, readonly). 3383cdf7525SGerd Hoffmann * @max_yres: max display height (0 == no limitation, readonly). 3393cdf7525SGerd Hoffmann * 3403cdf7525SGerd Hoffmann * EDID update protocol: 3413cdf7525SGerd Hoffmann * (1) set link-state to down. 3423cdf7525SGerd Hoffmann * (2) update edid blob and size. 3433cdf7525SGerd Hoffmann * (3) set link-state to up. 3443cdf7525SGerd Hoffmann */ 3453cdf7525SGerd Hoffmann struct vfio_region_gfx_edid { 3463cdf7525SGerd Hoffmann __u32 edid_offset; 3473cdf7525SGerd Hoffmann __u32 edid_max_size; 3483cdf7525SGerd Hoffmann __u32 edid_size; 3493cdf7525SGerd Hoffmann __u32 max_xres; 3503cdf7525SGerd Hoffmann __u32 max_yres; 3513cdf7525SGerd Hoffmann __u32 link_state; 3523cdf7525SGerd Hoffmann #define VFIO_DEVICE_GFX_LINK_STATE_UP 1 3533cdf7525SGerd Hoffmann #define VFIO_DEVICE_GFX_LINK_STATE_DOWN 2 3543cdf7525SGerd Hoffmann }; 3553cdf7525SGerd Hoffmann 356a32295c6SAlexey Kardashevskiy /* 357*7f928917SAlexey Kardashevskiy * 10de vendor sub-type 358*7f928917SAlexey Kardashevskiy * 359*7f928917SAlexey Kardashevskiy * NVIDIA GPU NVlink2 RAM is coherent RAM mapped onto the host address space. 360*7f928917SAlexey Kardashevskiy */ 361*7f928917SAlexey Kardashevskiy #define VFIO_REGION_SUBTYPE_NVIDIA_NVLINK2_RAM (1) 362*7f928917SAlexey Kardashevskiy 363*7f928917SAlexey Kardashevskiy /* 364*7f928917SAlexey Kardashevskiy * 1014 vendor sub-type 365*7f928917SAlexey Kardashevskiy * 366*7f928917SAlexey Kardashevskiy * IBM NPU NVlink2 ATSD (Address Translation Shootdown) register of NPU 367*7f928917SAlexey Kardashevskiy * to do TLB invalidation on a GPU. 368*7f928917SAlexey Kardashevskiy */ 369*7f928917SAlexey Kardashevskiy #define VFIO_REGION_SUBTYPE_IBM_NVLINK2_ATSD (1) 370*7f928917SAlexey Kardashevskiy 371*7f928917SAlexey Kardashevskiy /* 372a32295c6SAlexey Kardashevskiy * The MSIX mappable capability informs that MSIX data of a BAR can be mmapped 373a32295c6SAlexey Kardashevskiy * which allows direct access to non-MSIX registers which happened to be within 374a32295c6SAlexey Kardashevskiy * the same system page. 375a32295c6SAlexey Kardashevskiy * 376a32295c6SAlexey Kardashevskiy * Even though the userspace gets direct access to the MSIX data, the existing 377a32295c6SAlexey Kardashevskiy * VFIO_DEVICE_SET_IRQS interface must still be used for MSIX configuration. 378a32295c6SAlexey Kardashevskiy */ 379a32295c6SAlexey Kardashevskiy #define VFIO_REGION_INFO_CAP_MSIX_MAPPABLE 3 380a32295c6SAlexey Kardashevskiy 381*7f928917SAlexey Kardashevskiy /* 382*7f928917SAlexey Kardashevskiy * Capability with compressed real address (aka SSA - small system address) 383*7f928917SAlexey Kardashevskiy * where GPU RAM is mapped on a system bus. Used by a GPU for DMA routing 384*7f928917SAlexey Kardashevskiy * and by the userspace to associate a NVLink bridge with a GPU. 385*7f928917SAlexey Kardashevskiy */ 386*7f928917SAlexey Kardashevskiy #define VFIO_REGION_INFO_CAP_NVLINK2_SSATGT 4 387*7f928917SAlexey Kardashevskiy 388*7f928917SAlexey Kardashevskiy struct vfio_region_info_cap_nvlink2_ssatgt { 389*7f928917SAlexey Kardashevskiy struct vfio_info_cap_header header; 390*7f928917SAlexey Kardashevskiy __u64 tgt; 391*7f928917SAlexey Kardashevskiy }; 392*7f928917SAlexey Kardashevskiy 393*7f928917SAlexey Kardashevskiy /* 394*7f928917SAlexey Kardashevskiy * Capability with an NVLink link speed. The value is read by 395*7f928917SAlexey Kardashevskiy * the NVlink2 bridge driver from the bridge's "ibm,nvlink-speed" 396*7f928917SAlexey Kardashevskiy * property in the device tree. The value is fixed in the hardware 397*7f928917SAlexey Kardashevskiy * and failing to provide the correct value results in the link 398*7f928917SAlexey Kardashevskiy * not working with no indication from the driver why. 399*7f928917SAlexey Kardashevskiy */ 400*7f928917SAlexey Kardashevskiy #define VFIO_REGION_INFO_CAP_NVLINK2_LNKSPD 5 401*7f928917SAlexey Kardashevskiy 402*7f928917SAlexey Kardashevskiy struct vfio_region_info_cap_nvlink2_lnkspd { 403*7f928917SAlexey Kardashevskiy struct vfio_info_cap_header header; 404*7f928917SAlexey Kardashevskiy __u32 link_speed; 405*7f928917SAlexey Kardashevskiy __u32 __pad; 406*7f928917SAlexey Kardashevskiy }; 407*7f928917SAlexey Kardashevskiy 408607ca46eSDavid Howells /** 409607ca46eSDavid Howells * VFIO_DEVICE_GET_IRQ_INFO - _IOWR(VFIO_TYPE, VFIO_BASE + 9, 410607ca46eSDavid Howells * struct vfio_irq_info) 411607ca46eSDavid Howells * 412607ca46eSDavid Howells * Retrieve information about a device IRQ. Caller provides 413607ca46eSDavid Howells * struct vfio_irq_info with index value set. Caller sets argsz. 414607ca46eSDavid Howells * Implementation of IRQ mapping is bus driver specific. Indexes 415607ca46eSDavid Howells * using multiple IRQs are primarily intended to support MSI-like 416607ca46eSDavid Howells * interrupt blocks. Zero count irq blocks may be used to describe 417607ca46eSDavid Howells * unimplemented interrupt types. 418607ca46eSDavid Howells * 419607ca46eSDavid Howells * The EVENTFD flag indicates the interrupt index supports eventfd based 420607ca46eSDavid Howells * signaling. 421607ca46eSDavid Howells * 422607ca46eSDavid Howells * The MASKABLE flags indicates the index supports MASK and UNMASK 423607ca46eSDavid Howells * actions described below. 424607ca46eSDavid Howells * 425607ca46eSDavid Howells * AUTOMASKED indicates that after signaling, the interrupt line is 426607ca46eSDavid Howells * automatically masked by VFIO and the user needs to unmask the line 427607ca46eSDavid Howells * to receive new interrupts. This is primarily intended to distinguish 428607ca46eSDavid Howells * level triggered interrupts. 429607ca46eSDavid Howells * 430607ca46eSDavid Howells * The NORESIZE flag indicates that the interrupt lines within the index 431607ca46eSDavid Howells * are setup as a set and new subindexes cannot be enabled without first 432607ca46eSDavid Howells * disabling the entire index. This is used for interrupts like PCI MSI 433607ca46eSDavid Howells * and MSI-X where the driver may only use a subset of the available 434607ca46eSDavid Howells * indexes, but VFIO needs to enable a specific number of vectors 435607ca46eSDavid Howells * upfront. In the case of MSI-X, where the user can enable MSI-X and 436607ca46eSDavid Howells * then add and unmask vectors, it's up to userspace to make the decision 437607ca46eSDavid Howells * whether to allocate the maximum supported number of vectors or tear 438607ca46eSDavid Howells * down setup and incrementally increase the vectors as each is enabled. 439607ca46eSDavid Howells */ 440607ca46eSDavid Howells struct vfio_irq_info { 441607ca46eSDavid Howells __u32 argsz; 442607ca46eSDavid Howells __u32 flags; 443607ca46eSDavid Howells #define VFIO_IRQ_INFO_EVENTFD (1 << 0) 444607ca46eSDavid Howells #define VFIO_IRQ_INFO_MASKABLE (1 << 1) 445607ca46eSDavid Howells #define VFIO_IRQ_INFO_AUTOMASKED (1 << 2) 446607ca46eSDavid Howells #define VFIO_IRQ_INFO_NORESIZE (1 << 3) 447607ca46eSDavid Howells __u32 index; /* IRQ index */ 448607ca46eSDavid Howells __u32 count; /* Number of IRQs within this index */ 449607ca46eSDavid Howells }; 450607ca46eSDavid Howells #define VFIO_DEVICE_GET_IRQ_INFO _IO(VFIO_TYPE, VFIO_BASE + 9) 451607ca46eSDavid Howells 452607ca46eSDavid Howells /** 453607ca46eSDavid Howells * VFIO_DEVICE_SET_IRQS - _IOW(VFIO_TYPE, VFIO_BASE + 10, struct vfio_irq_set) 454607ca46eSDavid Howells * 455607ca46eSDavid Howells * Set signaling, masking, and unmasking of interrupts. Caller provides 456607ca46eSDavid Howells * struct vfio_irq_set with all fields set. 'start' and 'count' indicate 457607ca46eSDavid Howells * the range of subindexes being specified. 458607ca46eSDavid Howells * 459607ca46eSDavid Howells * The DATA flags specify the type of data provided. If DATA_NONE, the 460607ca46eSDavid Howells * operation performs the specified action immediately on the specified 461607ca46eSDavid Howells * interrupt(s). For example, to unmask AUTOMASKED interrupt [0,0]: 462607ca46eSDavid Howells * flags = (DATA_NONE|ACTION_UNMASK), index = 0, start = 0, count = 1. 463607ca46eSDavid Howells * 464607ca46eSDavid Howells * DATA_BOOL allows sparse support for the same on arrays of interrupts. 465607ca46eSDavid Howells * For example, to mask interrupts [0,1] and [0,3] (but not [0,2]): 466607ca46eSDavid Howells * flags = (DATA_BOOL|ACTION_MASK), index = 0, start = 1, count = 3, 467607ca46eSDavid Howells * data = {1,0,1} 468607ca46eSDavid Howells * 469607ca46eSDavid Howells * DATA_EVENTFD binds the specified ACTION to the provided __s32 eventfd. 470607ca46eSDavid Howells * A value of -1 can be used to either de-assign interrupts if already 471607ca46eSDavid Howells * assigned or skip un-assigned interrupts. For example, to set an eventfd 472607ca46eSDavid Howells * to be trigger for interrupts [0,0] and [0,2]: 473607ca46eSDavid Howells * flags = (DATA_EVENTFD|ACTION_TRIGGER), index = 0, start = 0, count = 3, 474607ca46eSDavid Howells * data = {fd1, -1, fd2} 475607ca46eSDavid Howells * If index [0,1] is previously set, two count = 1 ioctls calls would be 476607ca46eSDavid Howells * required to set [0,0] and [0,2] without changing [0,1]. 477607ca46eSDavid Howells * 478607ca46eSDavid Howells * Once a signaling mechanism is set, DATA_BOOL or DATA_NONE can be used 479607ca46eSDavid Howells * with ACTION_TRIGGER to perform kernel level interrupt loopback testing 480607ca46eSDavid Howells * from userspace (ie. simulate hardware triggering). 481607ca46eSDavid Howells * 482607ca46eSDavid Howells * Setting of an event triggering mechanism to userspace for ACTION_TRIGGER 483607ca46eSDavid Howells * enables the interrupt index for the device. Individual subindex interrupts 484607ca46eSDavid Howells * can be disabled using the -1 value for DATA_EVENTFD or the index can be 485607ca46eSDavid Howells * disabled as a whole with: flags = (DATA_NONE|ACTION_TRIGGER), count = 0. 486607ca46eSDavid Howells * 487607ca46eSDavid Howells * Note that ACTION_[UN]MASK specify user->kernel signaling (irqfds) while 488607ca46eSDavid Howells * ACTION_TRIGGER specifies kernel->user signaling. 489607ca46eSDavid Howells */ 490607ca46eSDavid Howells struct vfio_irq_set { 491607ca46eSDavid Howells __u32 argsz; 492607ca46eSDavid Howells __u32 flags; 493607ca46eSDavid Howells #define VFIO_IRQ_SET_DATA_NONE (1 << 0) /* Data not present */ 494607ca46eSDavid Howells #define VFIO_IRQ_SET_DATA_BOOL (1 << 1) /* Data is bool (u8) */ 495607ca46eSDavid Howells #define VFIO_IRQ_SET_DATA_EVENTFD (1 << 2) /* Data is eventfd (s32) */ 496607ca46eSDavid Howells #define VFIO_IRQ_SET_ACTION_MASK (1 << 3) /* Mask interrupt */ 497607ca46eSDavid Howells #define VFIO_IRQ_SET_ACTION_UNMASK (1 << 4) /* Unmask interrupt */ 498607ca46eSDavid Howells #define VFIO_IRQ_SET_ACTION_TRIGGER (1 << 5) /* Trigger interrupt */ 499607ca46eSDavid Howells __u32 index; 500607ca46eSDavid Howells __u32 start; 501607ca46eSDavid Howells __u32 count; 502607ca46eSDavid Howells __u8 data[]; 503607ca46eSDavid Howells }; 504607ca46eSDavid Howells #define VFIO_DEVICE_SET_IRQS _IO(VFIO_TYPE, VFIO_BASE + 10) 505607ca46eSDavid Howells 506607ca46eSDavid Howells #define VFIO_IRQ_SET_DATA_TYPE_MASK (VFIO_IRQ_SET_DATA_NONE | \ 507607ca46eSDavid Howells VFIO_IRQ_SET_DATA_BOOL | \ 508607ca46eSDavid Howells VFIO_IRQ_SET_DATA_EVENTFD) 509607ca46eSDavid Howells #define VFIO_IRQ_SET_ACTION_TYPE_MASK (VFIO_IRQ_SET_ACTION_MASK | \ 510607ca46eSDavid Howells VFIO_IRQ_SET_ACTION_UNMASK | \ 511607ca46eSDavid Howells VFIO_IRQ_SET_ACTION_TRIGGER) 512607ca46eSDavid Howells /** 513607ca46eSDavid Howells * VFIO_DEVICE_RESET - _IO(VFIO_TYPE, VFIO_BASE + 11) 514607ca46eSDavid Howells * 515607ca46eSDavid Howells * Reset a device. 516607ca46eSDavid Howells */ 517607ca46eSDavid Howells #define VFIO_DEVICE_RESET _IO(VFIO_TYPE, VFIO_BASE + 11) 518607ca46eSDavid Howells 519607ca46eSDavid Howells /* 520607ca46eSDavid Howells * The VFIO-PCI bus driver makes use of the following fixed region and 521607ca46eSDavid Howells * IRQ index mapping. Unimplemented regions return a size of zero. 522607ca46eSDavid Howells * Unimplemented IRQ types return a count of zero. 523607ca46eSDavid Howells */ 524607ca46eSDavid Howells 525607ca46eSDavid Howells enum { 526607ca46eSDavid Howells VFIO_PCI_BAR0_REGION_INDEX, 527607ca46eSDavid Howells VFIO_PCI_BAR1_REGION_INDEX, 528607ca46eSDavid Howells VFIO_PCI_BAR2_REGION_INDEX, 529607ca46eSDavid Howells VFIO_PCI_BAR3_REGION_INDEX, 530607ca46eSDavid Howells VFIO_PCI_BAR4_REGION_INDEX, 531607ca46eSDavid Howells VFIO_PCI_BAR5_REGION_INDEX, 532607ca46eSDavid Howells VFIO_PCI_ROM_REGION_INDEX, 533607ca46eSDavid Howells VFIO_PCI_CONFIG_REGION_INDEX, 53484237a82SAlex Williamson /* 53584237a82SAlex Williamson * Expose VGA regions defined for PCI base class 03, subclass 00. 53684237a82SAlex Williamson * This includes I/O port ranges 0x3b0 to 0x3bb and 0x3c0 to 0x3df 53784237a82SAlex Williamson * as well as the MMIO range 0xa0000 to 0xbffff. Each implemented 53884237a82SAlex Williamson * range is found at it's identity mapped offset from the region 53984237a82SAlex Williamson * offset, for example 0x3b0 is region_info.offset + 0x3b0. Areas 54084237a82SAlex Williamson * between described ranges are unimplemented. 54184237a82SAlex Williamson */ 54284237a82SAlex Williamson VFIO_PCI_VGA_REGION_INDEX, 543c7bb4cb4SAlex Williamson VFIO_PCI_NUM_REGIONS = 9 /* Fixed user ABI, region indexes >=9 use */ 544c7bb4cb4SAlex Williamson /* device specific cap to define content. */ 545607ca46eSDavid Howells }; 546607ca46eSDavid Howells 547607ca46eSDavid Howells enum { 548607ca46eSDavid Howells VFIO_PCI_INTX_IRQ_INDEX, 549607ca46eSDavid Howells VFIO_PCI_MSI_IRQ_INDEX, 550607ca46eSDavid Howells VFIO_PCI_MSIX_IRQ_INDEX, 551dad9f897SVijay Mohan Pandarathil VFIO_PCI_ERR_IRQ_INDEX, 5526140a8f5SAlex Williamson VFIO_PCI_REQ_IRQ_INDEX, 553607ca46eSDavid Howells VFIO_PCI_NUM_IRQS 554607ca46eSDavid Howells }; 555607ca46eSDavid Howells 556e01bcdd6SDong Jia Shi /* 557120e214eSDong Jia Shi * The vfio-ccw bus driver makes use of the following fixed region and 558120e214eSDong Jia Shi * IRQ index mapping. Unimplemented regions return a size of zero. 559120e214eSDong Jia Shi * Unimplemented IRQ types return a count of zero. 560e01bcdd6SDong Jia Shi */ 561e01bcdd6SDong Jia Shi 562e01bcdd6SDong Jia Shi enum { 563e01bcdd6SDong Jia Shi VFIO_CCW_CONFIG_REGION_INDEX, 564e01bcdd6SDong Jia Shi VFIO_CCW_NUM_REGIONS 565e01bcdd6SDong Jia Shi }; 566e01bcdd6SDong Jia Shi 567120e214eSDong Jia Shi enum { 568120e214eSDong Jia Shi VFIO_CCW_IO_IRQ_INDEX, 569120e214eSDong Jia Shi VFIO_CCW_NUM_IRQS 570120e214eSDong Jia Shi }; 571120e214eSDong Jia Shi 5728b27ee60SAlex Williamson /** 5738b27ee60SAlex Williamson * VFIO_DEVICE_GET_PCI_HOT_RESET_INFO - _IORW(VFIO_TYPE, VFIO_BASE + 12, 5748b27ee60SAlex Williamson * struct vfio_pci_hot_reset_info) 5758b27ee60SAlex Williamson * 5768b27ee60SAlex Williamson * Return: 0 on success, -errno on failure: 5778b27ee60SAlex Williamson * -enospc = insufficient buffer, -enodev = unsupported for device. 5788b27ee60SAlex Williamson */ 5798b27ee60SAlex Williamson struct vfio_pci_dependent_device { 5808b27ee60SAlex Williamson __u32 group_id; 5818b27ee60SAlex Williamson __u16 segment; 5828b27ee60SAlex Williamson __u8 bus; 5838b27ee60SAlex Williamson __u8 devfn; /* Use PCI_SLOT/PCI_FUNC */ 5848b27ee60SAlex Williamson }; 5858b27ee60SAlex Williamson 5868b27ee60SAlex Williamson struct vfio_pci_hot_reset_info { 5878b27ee60SAlex Williamson __u32 argsz; 5888b27ee60SAlex Williamson __u32 flags; 5898b27ee60SAlex Williamson __u32 count; 5908b27ee60SAlex Williamson struct vfio_pci_dependent_device devices[]; 5918b27ee60SAlex Williamson }; 5928b27ee60SAlex Williamson 5938b27ee60SAlex Williamson #define VFIO_DEVICE_GET_PCI_HOT_RESET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12) 5948b27ee60SAlex Williamson 5958b27ee60SAlex Williamson /** 5968b27ee60SAlex Williamson * VFIO_DEVICE_PCI_HOT_RESET - _IOW(VFIO_TYPE, VFIO_BASE + 13, 5978b27ee60SAlex Williamson * struct vfio_pci_hot_reset) 5988b27ee60SAlex Williamson * 5998b27ee60SAlex Williamson * Return: 0 on success, -errno on failure. 6008b27ee60SAlex Williamson */ 6018b27ee60SAlex Williamson struct vfio_pci_hot_reset { 6028b27ee60SAlex Williamson __u32 argsz; 6038b27ee60SAlex Williamson __u32 flags; 6048b27ee60SAlex Williamson __u32 count; 6058b27ee60SAlex Williamson __s32 group_fds[]; 6068b27ee60SAlex Williamson }; 6078b27ee60SAlex Williamson 6088b27ee60SAlex Williamson #define VFIO_DEVICE_PCI_HOT_RESET _IO(VFIO_TYPE, VFIO_BASE + 13) 6098b27ee60SAlex Williamson 610e20eaa23STina Zhang /** 611e20eaa23STina Zhang * VFIO_DEVICE_QUERY_GFX_PLANE - _IOW(VFIO_TYPE, VFIO_BASE + 14, 612e20eaa23STina Zhang * struct vfio_device_query_gfx_plane) 613e20eaa23STina Zhang * 614e20eaa23STina Zhang * Set the drm_plane_type and flags, then retrieve the gfx plane info. 615e20eaa23STina Zhang * 616e20eaa23STina Zhang * flags supported: 617e20eaa23STina Zhang * - VFIO_GFX_PLANE_TYPE_PROBE and VFIO_GFX_PLANE_TYPE_DMABUF are set 618e20eaa23STina Zhang * to ask if the mdev supports dma-buf. 0 on support, -EINVAL on no 619e20eaa23STina Zhang * support for dma-buf. 620e20eaa23STina Zhang * - VFIO_GFX_PLANE_TYPE_PROBE and VFIO_GFX_PLANE_TYPE_REGION are set 621e20eaa23STina Zhang * to ask if the mdev supports region. 0 on support, -EINVAL on no 622e20eaa23STina Zhang * support for region. 623e20eaa23STina Zhang * - VFIO_GFX_PLANE_TYPE_DMABUF or VFIO_GFX_PLANE_TYPE_REGION is set 624e20eaa23STina Zhang * with each call to query the plane info. 625e20eaa23STina Zhang * - Others are invalid and return -EINVAL. 626e20eaa23STina Zhang * 627e20eaa23STina Zhang * Note: 628e20eaa23STina Zhang * 1. Plane could be disabled by guest. In that case, success will be 629e20eaa23STina Zhang * returned with zero-initialized drm_format, size, width and height 630e20eaa23STina Zhang * fields. 631e20eaa23STina Zhang * 2. x_hot/y_hot is set to 0xFFFFFFFF if no hotspot information available 632e20eaa23STina Zhang * 633e20eaa23STina Zhang * Return: 0 on success, -errno on other failure. 634e20eaa23STina Zhang */ 635e20eaa23STina Zhang struct vfio_device_gfx_plane_info { 636e20eaa23STina Zhang __u32 argsz; 637e20eaa23STina Zhang __u32 flags; 638e20eaa23STina Zhang #define VFIO_GFX_PLANE_TYPE_PROBE (1 << 0) 639e20eaa23STina Zhang #define VFIO_GFX_PLANE_TYPE_DMABUF (1 << 1) 640e20eaa23STina Zhang #define VFIO_GFX_PLANE_TYPE_REGION (1 << 2) 641e20eaa23STina Zhang /* in */ 642e20eaa23STina Zhang __u32 drm_plane_type; /* type of plane: DRM_PLANE_TYPE_* */ 643e20eaa23STina Zhang /* out */ 644e20eaa23STina Zhang __u32 drm_format; /* drm format of plane */ 645e20eaa23STina Zhang __u64 drm_format_mod; /* tiled mode */ 646e20eaa23STina Zhang __u32 width; /* width of plane */ 647e20eaa23STina Zhang __u32 height; /* height of plane */ 648e20eaa23STina Zhang __u32 stride; /* stride of plane */ 649e20eaa23STina Zhang __u32 size; /* size of plane in bytes, align on page*/ 650e20eaa23STina Zhang __u32 x_pos; /* horizontal position of cursor plane */ 651e20eaa23STina Zhang __u32 y_pos; /* vertical position of cursor plane*/ 652e20eaa23STina Zhang __u32 x_hot; /* horizontal position of cursor hotspot */ 653e20eaa23STina Zhang __u32 y_hot; /* vertical position of cursor hotspot */ 654e20eaa23STina Zhang union { 655e20eaa23STina Zhang __u32 region_index; /* region index */ 656e20eaa23STina Zhang __u32 dmabuf_id; /* dma-buf id */ 657e20eaa23STina Zhang }; 658e20eaa23STina Zhang }; 659e20eaa23STina Zhang 660e20eaa23STina Zhang #define VFIO_DEVICE_QUERY_GFX_PLANE _IO(VFIO_TYPE, VFIO_BASE + 14) 661e20eaa23STina Zhang 662e20eaa23STina Zhang /** 663e20eaa23STina Zhang * VFIO_DEVICE_GET_GFX_DMABUF - _IOW(VFIO_TYPE, VFIO_BASE + 15, __u32) 664e20eaa23STina Zhang * 665e20eaa23STina Zhang * Return a new dma-buf file descriptor for an exposed guest framebuffer 666e20eaa23STina Zhang * described by the provided dmabuf_id. The dmabuf_id is returned from VFIO_ 667e20eaa23STina Zhang * DEVICE_QUERY_GFX_PLANE as a token of the exposed guest framebuffer. 668e20eaa23STina Zhang */ 669e20eaa23STina Zhang 670e20eaa23STina Zhang #define VFIO_DEVICE_GET_GFX_DMABUF _IO(VFIO_TYPE, VFIO_BASE + 15) 671e20eaa23STina Zhang 67230656177SAlex Williamson /** 67330656177SAlex Williamson * VFIO_DEVICE_IOEVENTFD - _IOW(VFIO_TYPE, VFIO_BASE + 16, 67430656177SAlex Williamson * struct vfio_device_ioeventfd) 67530656177SAlex Williamson * 67630656177SAlex Williamson * Perform a write to the device at the specified device fd offset, with 67730656177SAlex Williamson * the specified data and width when the provided eventfd is triggered. 67830656177SAlex Williamson * vfio bus drivers may not support this for all regions, for all widths, 67930656177SAlex Williamson * or at all. vfio-pci currently only enables support for BAR regions, 68030656177SAlex Williamson * excluding the MSI-X vector table. 68130656177SAlex Williamson * 68230656177SAlex Williamson * Return: 0 on success, -errno on failure. 68330656177SAlex Williamson */ 68430656177SAlex Williamson struct vfio_device_ioeventfd { 68530656177SAlex Williamson __u32 argsz; 68630656177SAlex Williamson __u32 flags; 68730656177SAlex Williamson #define VFIO_DEVICE_IOEVENTFD_8 (1 << 0) /* 1-byte write */ 68830656177SAlex Williamson #define VFIO_DEVICE_IOEVENTFD_16 (1 << 1) /* 2-byte write */ 68930656177SAlex Williamson #define VFIO_DEVICE_IOEVENTFD_32 (1 << 2) /* 4-byte write */ 69030656177SAlex Williamson #define VFIO_DEVICE_IOEVENTFD_64 (1 << 3) /* 8-byte write */ 69130656177SAlex Williamson #define VFIO_DEVICE_IOEVENTFD_SIZE_MASK (0xf) 69230656177SAlex Williamson __u64 offset; /* device fd offset of write */ 69330656177SAlex Williamson __u64 data; /* data to be written */ 69430656177SAlex Williamson __s32 fd; /* -1 for de-assignment */ 69530656177SAlex Williamson }; 69630656177SAlex Williamson 69730656177SAlex Williamson #define VFIO_DEVICE_IOEVENTFD _IO(VFIO_TYPE, VFIO_BASE + 16) 69830656177SAlex Williamson 699607ca46eSDavid Howells /* -------- API for Type1 VFIO IOMMU -------- */ 700607ca46eSDavid Howells 701607ca46eSDavid Howells /** 702607ca46eSDavid Howells * VFIO_IOMMU_GET_INFO - _IOR(VFIO_TYPE, VFIO_BASE + 12, struct vfio_iommu_info) 703607ca46eSDavid Howells * 704607ca46eSDavid Howells * Retrieve information about the IOMMU object. Fills in provided 705607ca46eSDavid Howells * struct vfio_iommu_info. Caller sets argsz. 706607ca46eSDavid Howells * 707607ca46eSDavid Howells * XXX Should we do these by CHECK_EXTENSION too? 708607ca46eSDavid Howells */ 709607ca46eSDavid Howells struct vfio_iommu_type1_info { 710607ca46eSDavid Howells __u32 argsz; 711607ca46eSDavid Howells __u32 flags; 712607ca46eSDavid Howells #define VFIO_IOMMU_INFO_PGSIZES (1 << 0) /* supported page sizes info */ 713607ca46eSDavid Howells __u64 iova_pgsizes; /* Bitmap of supported page sizes */ 714607ca46eSDavid Howells }; 715607ca46eSDavid Howells 716607ca46eSDavid Howells #define VFIO_IOMMU_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12) 717607ca46eSDavid Howells 718607ca46eSDavid Howells /** 719607ca46eSDavid Howells * VFIO_IOMMU_MAP_DMA - _IOW(VFIO_TYPE, VFIO_BASE + 13, struct vfio_dma_map) 720607ca46eSDavid Howells * 721607ca46eSDavid Howells * Map process virtual addresses to IO virtual addresses using the 722607ca46eSDavid Howells * provided struct vfio_dma_map. Caller sets argsz. READ &/ WRITE required. 723607ca46eSDavid Howells */ 724607ca46eSDavid Howells struct vfio_iommu_type1_dma_map { 725607ca46eSDavid Howells __u32 argsz; 726607ca46eSDavid Howells __u32 flags; 727607ca46eSDavid Howells #define VFIO_DMA_MAP_FLAG_READ (1 << 0) /* readable from device */ 728607ca46eSDavid Howells #define VFIO_DMA_MAP_FLAG_WRITE (1 << 1) /* writable from device */ 729607ca46eSDavid Howells __u64 vaddr; /* Process virtual address */ 730607ca46eSDavid Howells __u64 iova; /* IO virtual address */ 731607ca46eSDavid Howells __u64 size; /* Size of mapping (bytes) */ 732607ca46eSDavid Howells }; 733607ca46eSDavid Howells 734607ca46eSDavid Howells #define VFIO_IOMMU_MAP_DMA _IO(VFIO_TYPE, VFIO_BASE + 13) 735607ca46eSDavid Howells 736607ca46eSDavid Howells /** 737166fd7d9SAlex Williamson * VFIO_IOMMU_UNMAP_DMA - _IOWR(VFIO_TYPE, VFIO_BASE + 14, 738166fd7d9SAlex Williamson * struct vfio_dma_unmap) 739607ca46eSDavid Howells * 740607ca46eSDavid Howells * Unmap IO virtual addresses using the provided struct vfio_dma_unmap. 741166fd7d9SAlex Williamson * Caller sets argsz. The actual unmapped size is returned in the size 742166fd7d9SAlex Williamson * field. No guarantee is made to the user that arbitrary unmaps of iova 743166fd7d9SAlex Williamson * or size different from those used in the original mapping call will 744166fd7d9SAlex Williamson * succeed. 745607ca46eSDavid Howells */ 746607ca46eSDavid Howells struct vfio_iommu_type1_dma_unmap { 747607ca46eSDavid Howells __u32 argsz; 748607ca46eSDavid Howells __u32 flags; 749607ca46eSDavid Howells __u64 iova; /* IO virtual address */ 750607ca46eSDavid Howells __u64 size; /* Size of mapping (bytes) */ 751607ca46eSDavid Howells }; 752607ca46eSDavid Howells 753607ca46eSDavid Howells #define VFIO_IOMMU_UNMAP_DMA _IO(VFIO_TYPE, VFIO_BASE + 14) 754607ca46eSDavid Howells 7555ffd229cSAlexey Kardashevskiy /* 7565ffd229cSAlexey Kardashevskiy * IOCTLs to enable/disable IOMMU container usage. 7575ffd229cSAlexey Kardashevskiy * No parameters are supported. 7585ffd229cSAlexey Kardashevskiy */ 7595ffd229cSAlexey Kardashevskiy #define VFIO_IOMMU_ENABLE _IO(VFIO_TYPE, VFIO_BASE + 15) 7605ffd229cSAlexey Kardashevskiy #define VFIO_IOMMU_DISABLE _IO(VFIO_TYPE, VFIO_BASE + 16) 7615ffd229cSAlexey Kardashevskiy 7625ffd229cSAlexey Kardashevskiy /* -------- Additional API for SPAPR TCE (Server POWERPC) IOMMU -------- */ 7635ffd229cSAlexey Kardashevskiy 7645ffd229cSAlexey Kardashevskiy /* 765e633bc86SAlexey Kardashevskiy * The SPAPR TCE DDW info struct provides the information about 766e633bc86SAlexey Kardashevskiy * the details of Dynamic DMA window capability. 767e633bc86SAlexey Kardashevskiy * 768e633bc86SAlexey Kardashevskiy * @pgsizes contains a page size bitmask, 4K/64K/16M are supported. 769e633bc86SAlexey Kardashevskiy * @max_dynamic_windows_supported tells the maximum number of windows 770e633bc86SAlexey Kardashevskiy * which the platform can create. 771e633bc86SAlexey Kardashevskiy * @levels tells the maximum number of levels in multi-level IOMMU tables; 772e633bc86SAlexey Kardashevskiy * this allows splitting a table into smaller chunks which reduces 773e633bc86SAlexey Kardashevskiy * the amount of physically contiguous memory required for the table. 774e633bc86SAlexey Kardashevskiy */ 775e633bc86SAlexey Kardashevskiy struct vfio_iommu_spapr_tce_ddw_info { 776e633bc86SAlexey Kardashevskiy __u64 pgsizes; /* Bitmap of supported page sizes */ 777e633bc86SAlexey Kardashevskiy __u32 max_dynamic_windows_supported; 778e633bc86SAlexey Kardashevskiy __u32 levels; 779e633bc86SAlexey Kardashevskiy }; 780e633bc86SAlexey Kardashevskiy 781e633bc86SAlexey Kardashevskiy /* 7825ffd229cSAlexey Kardashevskiy * The SPAPR TCE info struct provides the information about the PCI bus 7835ffd229cSAlexey Kardashevskiy * address ranges available for DMA, these values are programmed into 7845ffd229cSAlexey Kardashevskiy * the hardware so the guest has to know that information. 7855ffd229cSAlexey Kardashevskiy * 7865ffd229cSAlexey Kardashevskiy * The DMA 32 bit window start is an absolute PCI bus address. 7875ffd229cSAlexey Kardashevskiy * The IOVA address passed via map/unmap ioctls are absolute PCI bus 7885ffd229cSAlexey Kardashevskiy * addresses too so the window works as a filter rather than an offset 7895ffd229cSAlexey Kardashevskiy * for IOVA addresses. 7905ffd229cSAlexey Kardashevskiy * 791e633bc86SAlexey Kardashevskiy * Flags supported: 792e633bc86SAlexey Kardashevskiy * - VFIO_IOMMU_SPAPR_INFO_DDW: informs the userspace that dynamic DMA windows 793e633bc86SAlexey Kardashevskiy * (DDW) support is present. @ddw is only supported when DDW is present. 7945ffd229cSAlexey Kardashevskiy */ 7955ffd229cSAlexey Kardashevskiy struct vfio_iommu_spapr_tce_info { 7965ffd229cSAlexey Kardashevskiy __u32 argsz; 797e633bc86SAlexey Kardashevskiy __u32 flags; 798e633bc86SAlexey Kardashevskiy #define VFIO_IOMMU_SPAPR_INFO_DDW (1 << 0) /* DDW supported */ 7995ffd229cSAlexey Kardashevskiy __u32 dma32_window_start; /* 32 bit window start (bytes) */ 8005ffd229cSAlexey Kardashevskiy __u32 dma32_window_size; /* 32 bit window size (bytes) */ 801e633bc86SAlexey Kardashevskiy struct vfio_iommu_spapr_tce_ddw_info ddw; 8025ffd229cSAlexey Kardashevskiy }; 8035ffd229cSAlexey Kardashevskiy 8045ffd229cSAlexey Kardashevskiy #define VFIO_IOMMU_SPAPR_TCE_GET_INFO _IO(VFIO_TYPE, VFIO_BASE + 12) 8055ffd229cSAlexey Kardashevskiy 8061b69be5eSGavin Shan /* 8071b69be5eSGavin Shan * EEH PE operation struct provides ways to: 8081b69be5eSGavin Shan * - enable/disable EEH functionality; 8091b69be5eSGavin Shan * - unfreeze IO/DMA for frozen PE; 8101b69be5eSGavin Shan * - read PE state; 8111b69be5eSGavin Shan * - reset PE; 81268cbbc3aSGavin Shan * - configure PE; 81368cbbc3aSGavin Shan * - inject EEH error. 8141b69be5eSGavin Shan */ 81568cbbc3aSGavin Shan struct vfio_eeh_pe_err { 81668cbbc3aSGavin Shan __u32 type; 81768cbbc3aSGavin Shan __u32 func; 81868cbbc3aSGavin Shan __u64 addr; 81968cbbc3aSGavin Shan __u64 mask; 82068cbbc3aSGavin Shan }; 82168cbbc3aSGavin Shan 8221b69be5eSGavin Shan struct vfio_eeh_pe_op { 8231b69be5eSGavin Shan __u32 argsz; 8241b69be5eSGavin Shan __u32 flags; 8251b69be5eSGavin Shan __u32 op; 82668cbbc3aSGavin Shan union { 82768cbbc3aSGavin Shan struct vfio_eeh_pe_err err; 82868cbbc3aSGavin Shan }; 8291b69be5eSGavin Shan }; 8301b69be5eSGavin Shan 8311b69be5eSGavin Shan #define VFIO_EEH_PE_DISABLE 0 /* Disable EEH functionality */ 8321b69be5eSGavin Shan #define VFIO_EEH_PE_ENABLE 1 /* Enable EEH functionality */ 8331b69be5eSGavin Shan #define VFIO_EEH_PE_UNFREEZE_IO 2 /* Enable IO for frozen PE */ 8341b69be5eSGavin Shan #define VFIO_EEH_PE_UNFREEZE_DMA 3 /* Enable DMA for frozen PE */ 8351b69be5eSGavin Shan #define VFIO_EEH_PE_GET_STATE 4 /* PE state retrieval */ 8361b69be5eSGavin Shan #define VFIO_EEH_PE_STATE_NORMAL 0 /* PE in functional state */ 8371b69be5eSGavin Shan #define VFIO_EEH_PE_STATE_RESET 1 /* PE reset in progress */ 8381b69be5eSGavin Shan #define VFIO_EEH_PE_STATE_STOPPED 2 /* Stopped DMA and IO */ 8391b69be5eSGavin Shan #define VFIO_EEH_PE_STATE_STOPPED_DMA 4 /* Stopped DMA only */ 8401b69be5eSGavin Shan #define VFIO_EEH_PE_STATE_UNAVAIL 5 /* State unavailable */ 8411b69be5eSGavin Shan #define VFIO_EEH_PE_RESET_DEACTIVATE 5 /* Deassert PE reset */ 8421b69be5eSGavin Shan #define VFIO_EEH_PE_RESET_HOT 6 /* Assert hot reset */ 8431b69be5eSGavin Shan #define VFIO_EEH_PE_RESET_FUNDAMENTAL 7 /* Assert fundamental reset */ 8441b69be5eSGavin Shan #define VFIO_EEH_PE_CONFIGURE 8 /* PE configuration */ 84568cbbc3aSGavin Shan #define VFIO_EEH_PE_INJECT_ERR 9 /* Inject EEH error */ 8461b69be5eSGavin Shan 8471b69be5eSGavin Shan #define VFIO_EEH_PE_OP _IO(VFIO_TYPE, VFIO_BASE + 21) 8481b69be5eSGavin Shan 8492157e7b8SAlexey Kardashevskiy /** 8502157e7b8SAlexey Kardashevskiy * VFIO_IOMMU_SPAPR_REGISTER_MEMORY - _IOW(VFIO_TYPE, VFIO_BASE + 17, struct vfio_iommu_spapr_register_memory) 8512157e7b8SAlexey Kardashevskiy * 8522157e7b8SAlexey Kardashevskiy * Registers user space memory where DMA is allowed. It pins 8532157e7b8SAlexey Kardashevskiy * user pages and does the locked memory accounting so 8542157e7b8SAlexey Kardashevskiy * subsequent VFIO_IOMMU_MAP_DMA/VFIO_IOMMU_UNMAP_DMA calls 8552157e7b8SAlexey Kardashevskiy * get faster. 8562157e7b8SAlexey Kardashevskiy */ 8572157e7b8SAlexey Kardashevskiy struct vfio_iommu_spapr_register_memory { 8582157e7b8SAlexey Kardashevskiy __u32 argsz; 8592157e7b8SAlexey Kardashevskiy __u32 flags; 8602157e7b8SAlexey Kardashevskiy __u64 vaddr; /* Process virtual address */ 8612157e7b8SAlexey Kardashevskiy __u64 size; /* Size of mapping (bytes) */ 8622157e7b8SAlexey Kardashevskiy }; 8632157e7b8SAlexey Kardashevskiy #define VFIO_IOMMU_SPAPR_REGISTER_MEMORY _IO(VFIO_TYPE, VFIO_BASE + 17) 8642157e7b8SAlexey Kardashevskiy 8652157e7b8SAlexey Kardashevskiy /** 8662157e7b8SAlexey Kardashevskiy * VFIO_IOMMU_SPAPR_UNREGISTER_MEMORY - _IOW(VFIO_TYPE, VFIO_BASE + 18, struct vfio_iommu_spapr_register_memory) 8672157e7b8SAlexey Kardashevskiy * 8682157e7b8SAlexey Kardashevskiy * Unregisters user space memory registered with 8692157e7b8SAlexey Kardashevskiy * VFIO_IOMMU_SPAPR_REGISTER_MEMORY. 8702157e7b8SAlexey Kardashevskiy * Uses vfio_iommu_spapr_register_memory for parameters. 8712157e7b8SAlexey Kardashevskiy */ 8722157e7b8SAlexey Kardashevskiy #define VFIO_IOMMU_SPAPR_UNREGISTER_MEMORY _IO(VFIO_TYPE, VFIO_BASE + 18) 8732157e7b8SAlexey Kardashevskiy 874e633bc86SAlexey Kardashevskiy /** 875e633bc86SAlexey Kardashevskiy * VFIO_IOMMU_SPAPR_TCE_CREATE - _IOWR(VFIO_TYPE, VFIO_BASE + 19, struct vfio_iommu_spapr_tce_create) 876e633bc86SAlexey Kardashevskiy * 877e633bc86SAlexey Kardashevskiy * Creates an additional TCE table and programs it (sets a new DMA window) 878e633bc86SAlexey Kardashevskiy * to every IOMMU group in the container. It receives page shift, window 879e633bc86SAlexey Kardashevskiy * size and number of levels in the TCE table being created. 880e633bc86SAlexey Kardashevskiy * 881e633bc86SAlexey Kardashevskiy * It allocates and returns an offset on a PCI bus of the new DMA window. 882e633bc86SAlexey Kardashevskiy */ 883e633bc86SAlexey Kardashevskiy struct vfio_iommu_spapr_tce_create { 884e633bc86SAlexey Kardashevskiy __u32 argsz; 885e633bc86SAlexey Kardashevskiy __u32 flags; 886e633bc86SAlexey Kardashevskiy /* in */ 887e633bc86SAlexey Kardashevskiy __u32 page_shift; 88877d6bd47SAlexey Kardashevskiy __u32 __resv1; 889e633bc86SAlexey Kardashevskiy __u64 window_size; 890e633bc86SAlexey Kardashevskiy __u32 levels; 89177d6bd47SAlexey Kardashevskiy __u32 __resv2; 892e633bc86SAlexey Kardashevskiy /* out */ 893e633bc86SAlexey Kardashevskiy __u64 start_addr; 894e633bc86SAlexey Kardashevskiy }; 895e633bc86SAlexey Kardashevskiy #define VFIO_IOMMU_SPAPR_TCE_CREATE _IO(VFIO_TYPE, VFIO_BASE + 19) 896e633bc86SAlexey Kardashevskiy 897e633bc86SAlexey Kardashevskiy /** 898e633bc86SAlexey Kardashevskiy * VFIO_IOMMU_SPAPR_TCE_REMOVE - _IOW(VFIO_TYPE, VFIO_BASE + 20, struct vfio_iommu_spapr_tce_remove) 899e633bc86SAlexey Kardashevskiy * 900e633bc86SAlexey Kardashevskiy * Unprograms a TCE table from all groups in the container and destroys it. 901e633bc86SAlexey Kardashevskiy * It receives a PCI bus offset as a window id. 902e633bc86SAlexey Kardashevskiy */ 903e633bc86SAlexey Kardashevskiy struct vfio_iommu_spapr_tce_remove { 904e633bc86SAlexey Kardashevskiy __u32 argsz; 905e633bc86SAlexey Kardashevskiy __u32 flags; 906e633bc86SAlexey Kardashevskiy /* in */ 907e633bc86SAlexey Kardashevskiy __u64 start_addr; 908e633bc86SAlexey Kardashevskiy }; 909e633bc86SAlexey Kardashevskiy #define VFIO_IOMMU_SPAPR_TCE_REMOVE _IO(VFIO_TYPE, VFIO_BASE + 20) 910e633bc86SAlexey Kardashevskiy 9115ffd229cSAlexey Kardashevskiy /* ***************************************************************** */ 9125ffd229cSAlexey Kardashevskiy 913607ca46eSDavid Howells #endif /* _UAPIVFIO_H */ 914