/* SPDX-License-Identifier: MIT */1/*2* Copyright © 2023 Intel Corporation3*/45#ifndef _UAPI_XE_DRM_H_6#define _UAPI_XE_DRM_H_78#include "drm.h"910#if defined(__cplusplus)11extern "C" {12#endif1314/*15* Please note that modifications to all structs defined here are16* subject to backwards-compatibility constraints.17* Sections in this file are organized as follows:18* 1. IOCTL definition19* 2. Extension definition and helper structs20* 3. IOCTL's Query structs in the order of the Query's entries.21* 4. The rest of IOCTL structs in the order of IOCTL declaration.22*/2324/**25* DOC: Xe Device Block Diagram26*27* The diagram below represents a high-level simplification of a discrete28* GPU supported by the Xe driver. It shows some device components which29* are necessary to understand this API, as well as how their relations30* to each other. This diagram does not represent real hardware::31*32* ┌──────────────────────────────────────────────────────────────────┐33* │ ┌──────────────────────────────────────────────────┐ ┌─────────┐ │34* │ │ ┌───────────────────────┐ ┌─────┐ │ │ ┌─────┐ │ │35* │ │ │ VRAM0 ├───┤ ... │ │ │ │VRAM1│ │ │36* │ │ └───────────┬───────────┘ └─GT1─┘ │ │ └──┬──┘ │ │37* │ │ ┌──────────────────┴───────────────────────────┐ │ │ ┌──┴──┐ │ │38* │ │ │ ┌─────────────────────┐ ┌─────────────────┐ │ │ │ │ │ │ │39* │ │ │ │ ┌──┐ ┌──┐ ┌──┐ ┌──┐ │ │ ┌─────┐ ┌─────┐ │ │ │ │ │ │ │ │40* │ │ │ │ │EU│ │EU│ │EU│ │EU│ │ │ │RCS0 │ │BCS0 │ │ │ │ │ │ │ │ │41* │ │ │ │ └──┘ └──┘ └──┘ └──┘ │ │ └─────┘ └─────┘ │ │ │ │ │ │ │ │42* │ │ │ │ ┌──┐ ┌──┐ ┌──┐ ┌──┐ │ │ ┌─────┐ ┌─────┐ │ │ │ │ │ │ │ │43* │ │ │ │ │EU│ │EU│ │EU│ │EU│ │ │ │VCS0 │ │VCS1 │ │ │ │ │ │ │ │ │44* │ │ │ │ └──┘ └──┘ └──┘ └──┘ │ │ └─────┘ └─────┘ │ │ │ │ │ │ │ │45* │ │ │ │ ┌──┐ ┌──┐ ┌──┐ ┌──┐ │ │ ┌─────┐ ┌─────┐ │ │ │ │ │ │ │ │46* │ │ │ │ │EU│ │EU│ │EU│ │EU│ │ │ │VECS0│ │VECS1│ │ │ │ │ │ ... │ │ │47* │ │ │ │ └──┘ └──┘ └──┘ └──┘ │ │ └─────┘ └─────┘ │ │ │ │ │ │ │ │48* │ │ │ │ ┌──┐ ┌──┐ ┌──┐ ┌──┐ │ │ ┌─────┐ ┌─────┐ │ │ │ │ │ │ │ │49* │ │ │ │ │EU│ │EU│ │EU│ │EU│ │ │ │CCS0 │ │CCS1 │ │ │ │ │ │ │ │ │50* │ │ │ │ └──┘ └──┘ └──┘ └──┘ │ │ └─────┘ └─────┘ │ │ │ │ │ │ │ │51* │ │ │ └─────────DSS─────────┘ │ ┌─────┐ ┌─────┐ │ │ │ │ │ │ │ │52* │ │ │ │ │CCS2 │ │CCS3 │ │ │ │ │ │ │ │ │53* │ │ │ ┌─────┐ ┌─────┐ ┌─────┐ │ └─────┘ └─────┘ │ │ │ │ │ │ │ │54* │ │ │ │ ... │ │ ... │ │ ... │ │ │ │ │ │ │ │ │ │55* │ │ │ └─DSS─┘ └─DSS─┘ └─DSS─┘ └─────Engines─────┘ │ │ │ │ │ │ │56* │ │ └───────────────────────────GT0────────────────┘ │ │ └─GT2─┘ │ │57* │ └────────────────────────────Tile0─────────────────┘ └─ Tile1──┘ │58* └─────────────────────────────Device0───────┬──────────────────────┘59* │60* ───────────────────────┴────────── PCI bus61*/6263/**64* DOC: Xe uAPI Overview65*66* This section aims to describe the Xe's IOCTL entries, its structs, and other67* Xe related uAPI such as uevents and PMU (Platform Monitoring Unit) related68* entries and usage.69*70* List of supported IOCTLs:71* - &DRM_IOCTL_XE_DEVICE_QUERY72* - &DRM_IOCTL_XE_GEM_CREATE73* - &DRM_IOCTL_XE_GEM_MMAP_OFFSET74* - &DRM_IOCTL_XE_VM_CREATE75* - &DRM_IOCTL_XE_VM_DESTROY76* - &DRM_IOCTL_XE_VM_BIND77* - &DRM_IOCTL_XE_EXEC_QUEUE_CREATE78* - &DRM_IOCTL_XE_EXEC_QUEUE_DESTROY79* - &DRM_IOCTL_XE_EXEC_QUEUE_GET_PROPERTY80* - &DRM_IOCTL_XE_EXEC81* - &DRM_IOCTL_XE_WAIT_USER_FENCE82* - &DRM_IOCTL_XE_OBSERVATION83* - &DRM_IOCTL_XE_MADVISE84* - &DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS85*/8687/*88* xe specific ioctls.89*90* The device specific ioctl range is [DRM_COMMAND_BASE, DRM_COMMAND_END) ie91* [0x40, 0xa0) (a0 is excluded). The numbers below are defined as offset92* against DRM_COMMAND_BASE and should be between [0x0, 0x60).93*/94#define DRM_XE_DEVICE_QUERY 0x0095#define DRM_XE_GEM_CREATE 0x0196#define DRM_XE_GEM_MMAP_OFFSET 0x0297#define DRM_XE_VM_CREATE 0x0398#define DRM_XE_VM_DESTROY 0x0499#define DRM_XE_VM_BIND 0x05100#define DRM_XE_EXEC_QUEUE_CREATE 0x06101#define DRM_XE_EXEC_QUEUE_DESTROY 0x07102#define DRM_XE_EXEC_QUEUE_GET_PROPERTY 0x08103#define DRM_XE_EXEC 0x09104#define DRM_XE_WAIT_USER_FENCE 0x0a105#define DRM_XE_OBSERVATION 0x0b106#define DRM_XE_MADVISE 0x0c107#define DRM_XE_VM_QUERY_MEM_RANGE_ATTRS 0x0d108109/* Must be kept compact -- no holes */110111#define DRM_IOCTL_XE_DEVICE_QUERY DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_DEVICE_QUERY, struct drm_xe_device_query)112#define DRM_IOCTL_XE_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_GEM_CREATE, struct drm_xe_gem_create)113#define DRM_IOCTL_XE_GEM_MMAP_OFFSET DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_GEM_MMAP_OFFSET, struct drm_xe_gem_mmap_offset)114#define DRM_IOCTL_XE_VM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_VM_CREATE, struct drm_xe_vm_create)115#define DRM_IOCTL_XE_VM_DESTROY DRM_IOW(DRM_COMMAND_BASE + DRM_XE_VM_DESTROY, struct drm_xe_vm_destroy)116#define DRM_IOCTL_XE_VM_BIND DRM_IOW(DRM_COMMAND_BASE + DRM_XE_VM_BIND, struct drm_xe_vm_bind)117#define DRM_IOCTL_XE_EXEC_QUEUE_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_EXEC_QUEUE_CREATE, struct drm_xe_exec_queue_create)118#define DRM_IOCTL_XE_EXEC_QUEUE_DESTROY DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC_QUEUE_DESTROY, struct drm_xe_exec_queue_destroy)119#define DRM_IOCTL_XE_EXEC_QUEUE_GET_PROPERTY DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_EXEC_QUEUE_GET_PROPERTY, struct drm_xe_exec_queue_get_property)120#define DRM_IOCTL_XE_EXEC DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC, struct drm_xe_exec)121#define DRM_IOCTL_XE_WAIT_USER_FENCE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_WAIT_USER_FENCE, struct drm_xe_wait_user_fence)122#define DRM_IOCTL_XE_OBSERVATION DRM_IOW(DRM_COMMAND_BASE + DRM_XE_OBSERVATION, struct drm_xe_observation_param)123#define DRM_IOCTL_XE_MADVISE DRM_IOW(DRM_COMMAND_BASE + DRM_XE_MADVISE, struct drm_xe_madvise)124#define DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_VM_QUERY_MEM_RANGE_ATTRS, struct drm_xe_vm_query_mem_range_attr)125126/**127* DOC: Xe IOCTL Extensions128*129* Before detailing the IOCTLs and its structs, it is important to highlight130* that every IOCTL in Xe is extensible.131*132* Many interfaces need to grow over time. In most cases we can simply133* extend the struct and have userspace pass in more data. Another option,134* as demonstrated by Vulkan's approach to providing extensions for forward135* and backward compatibility, is to use a list of optional structs to136* provide those extra details.137*138* The key advantage to using an extension chain is that it allows us to139* redefine the interface more easily than an ever growing struct of140* increasing complexity, and for large parts of that interface to be141* entirely optional. The downside is more pointer chasing; chasing across142* the __user boundary with pointers encapsulated inside u64.143*144* Example chaining:145*146* .. code-block:: C147*148* struct drm_xe_user_extension ext3 {149* .next_extension = 0, // end150* .name = ...,151* };152* struct drm_xe_user_extension ext2 {153* .next_extension = (uintptr_t)&ext3,154* .name = ...,155* };156* struct drm_xe_user_extension ext1 {157* .next_extension = (uintptr_t)&ext2,158* .name = ...,159* };160*161* Typically the struct drm_xe_user_extension would be embedded in some uAPI162* struct, and in this case we would feed it the head of the chain(i.e ext1),163* which would then apply all of the above extensions.164*/165166/**167* struct drm_xe_user_extension - Base class for defining a chain of extensions168*/169struct drm_xe_user_extension {170/**171* @next_extension:172*173* Pointer to the next struct drm_xe_user_extension, or zero if the end.174*/175__u64 next_extension;176177/**178* @name: Name of the extension.179*180* Note that the name here is just some integer.181*182* Also note that the name space for this is not global for the whole183* driver, but rather its scope/meaning is limited to the specific piece184* of uAPI which has embedded the struct drm_xe_user_extension.185*/186__u32 name;187188/**189* @pad: MBZ190*191* All undefined bits must be zero.192*/193__u32 pad;194};195196/**197* struct drm_xe_ext_set_property - Generic set property extension198*199* A generic struct that allows any of the Xe's IOCTL to be extended200* with a set_property operation.201*/202struct drm_xe_ext_set_property {203/** @base: base user extension */204struct drm_xe_user_extension base;205206/** @property: property to set */207__u32 property;208209/** @pad: MBZ */210__u32 pad;211212/** @value: property value */213__u64 value;214215/** @reserved: Reserved */216__u64 reserved[2];217};218219/**220* struct drm_xe_engine_class_instance - instance of an engine class221*222* It is returned as part of the @drm_xe_engine, but it also is used as223* the input of engine selection for both @drm_xe_exec_queue_create and224* @drm_xe_query_engine_cycles225*226* The @engine_class can be:227* - %DRM_XE_ENGINE_CLASS_RENDER228* - %DRM_XE_ENGINE_CLASS_COPY229* - %DRM_XE_ENGINE_CLASS_VIDEO_DECODE230* - %DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE231* - %DRM_XE_ENGINE_CLASS_COMPUTE232* - %DRM_XE_ENGINE_CLASS_VM_BIND - Kernel only classes (not actual233* hardware engine class). Used for creating ordered queues of VM234* bind operations.235*/236struct drm_xe_engine_class_instance {237#define DRM_XE_ENGINE_CLASS_RENDER 0238#define DRM_XE_ENGINE_CLASS_COPY 1239#define DRM_XE_ENGINE_CLASS_VIDEO_DECODE 2240#define DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE 3241#define DRM_XE_ENGINE_CLASS_COMPUTE 4242#define DRM_XE_ENGINE_CLASS_VM_BIND 5243/** @engine_class: engine class id */244__u16 engine_class;245/** @engine_instance: engine instance id */246__u16 engine_instance;247/** @gt_id: Unique ID of this GT within the PCI Device */248__u16 gt_id;249/** @pad: MBZ */250__u16 pad;251};252253/**254* struct drm_xe_engine - describe hardware engine255*/256struct drm_xe_engine {257/** @instance: The @drm_xe_engine_class_instance */258struct drm_xe_engine_class_instance instance;259260/** @reserved: Reserved */261__u64 reserved[3];262};263264/**265* struct drm_xe_query_engines - describe engines266*267* If a query is made with a struct @drm_xe_device_query where .query268* is equal to %DRM_XE_DEVICE_QUERY_ENGINES, then the reply uses an array of269* struct @drm_xe_query_engines in .data.270*/271struct drm_xe_query_engines {272/** @num_engines: number of engines returned in @engines */273__u32 num_engines;274/** @pad: MBZ */275__u32 pad;276/** @engines: The returned engines for this device */277struct drm_xe_engine engines[];278};279280/**281* enum drm_xe_memory_class - Supported memory classes.282*/283enum drm_xe_memory_class {284/** @DRM_XE_MEM_REGION_CLASS_SYSMEM: Represents system memory. */285DRM_XE_MEM_REGION_CLASS_SYSMEM = 0,286/**287* @DRM_XE_MEM_REGION_CLASS_VRAM: On discrete platforms, this288* represents the memory that is local to the device, which we289* call VRAM. Not valid on integrated platforms.290*/291DRM_XE_MEM_REGION_CLASS_VRAM292};293294/**295* struct drm_xe_mem_region - Describes some region as known to296* the driver.297*/298struct drm_xe_mem_region {299/**300* @mem_class: The memory class describing this region.301*302* See enum drm_xe_memory_class for supported values.303*/304__u16 mem_class;305/**306* @instance: The unique ID for this region, which serves as the307* index in the placement bitmask used as argument for308* &DRM_IOCTL_XE_GEM_CREATE309*/310__u16 instance;311/**312* @min_page_size: Min page-size in bytes for this region.313*314* When the kernel allocates memory for this region, the315* underlying pages will be at least @min_page_size in size.316* Buffer objects with an allowable placement in this region must be317* created with a size aligned to this value.318* GPU virtual address mappings of (parts of) buffer objects that319* may be placed in this region must also have their GPU virtual320* address and range aligned to this value.321* Affected IOCTLS will return %-EINVAL if alignment restrictions are322* not met.323*/324__u32 min_page_size;325/**326* @total_size: The usable size in bytes for this region.327*/328__u64 total_size;329/**330* @used: Estimate of the memory used in bytes for this region.331*332* Requires CAP_PERFMON or CAP_SYS_ADMIN to get reliable333* accounting. Without this the value here will always equal334* zero.335*/336__u64 used;337/**338* @cpu_visible_size: How much of this region can be CPU339* accessed, in bytes.340*341* This will always be <= @total_size, and the remainder (if342* any) will not be CPU accessible. If the CPU accessible part343* is smaller than @total_size then this is referred to as a344* small BAR system.345*346* On systems without small BAR (full BAR), the probed_size will347* always equal the @total_size, since all of it will be CPU348* accessible.349*350* Note this is only tracked for DRM_XE_MEM_REGION_CLASS_VRAM351* regions (for other types the value here will always equal352* zero).353*/354__u64 cpu_visible_size;355/**356* @cpu_visible_used: Estimate of CPU visible memory used, in357* bytes.358*359* Requires CAP_PERFMON or CAP_SYS_ADMIN to get reliable360* accounting. Without this the value here will always equal361* zero. Note this is only currently tracked for362* DRM_XE_MEM_REGION_CLASS_VRAM regions (for other types the value363* here will always be zero).364*/365__u64 cpu_visible_used;366/** @reserved: Reserved */367__u64 reserved[6];368};369370/**371* struct drm_xe_query_mem_regions - describe memory regions372*373* If a query is made with a struct drm_xe_device_query where .query374* is equal to DRM_XE_DEVICE_QUERY_MEM_REGIONS, then the reply uses375* struct drm_xe_query_mem_regions in .data.376*/377struct drm_xe_query_mem_regions {378/** @num_mem_regions: number of memory regions returned in @mem_regions */379__u32 num_mem_regions;380/** @pad: MBZ */381__u32 pad;382/** @mem_regions: The returned memory regions for this device */383struct drm_xe_mem_region mem_regions[];384};385386/**387* struct drm_xe_query_config - describe the device configuration388*389* If a query is made with a struct drm_xe_device_query where .query390* is equal to DRM_XE_DEVICE_QUERY_CONFIG, then the reply uses391* struct drm_xe_query_config in .data.392*393* The index in @info can be:394* - %DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID - Device ID (lower 16 bits)395* and the device revision (next 8 bits)396* - %DRM_XE_QUERY_CONFIG_FLAGS - Flags describing the device397* configuration, see list below398*399* - %DRM_XE_QUERY_CONFIG_FLAG_HAS_VRAM - Flag is set if the device400* has usable VRAM401* - %DRM_XE_QUERY_CONFIG_FLAG_HAS_LOW_LATENCY - Flag is set if the device402* has low latency hint support403* - %DRM_XE_QUERY_CONFIG_FLAG_HAS_CPU_ADDR_MIRROR - Flag is set if the404* device has CPU address mirroring support405* - %DRM_XE_QUERY_CONFIG_MIN_ALIGNMENT - Minimal memory alignment406* required by this device, typically SZ_4K or SZ_64K407* - %DRM_XE_QUERY_CONFIG_VA_BITS - Maximum bits of a virtual address408* - %DRM_XE_QUERY_CONFIG_MAX_EXEC_QUEUE_PRIORITY - Value of the highest409* available exec queue priority410*/411struct drm_xe_query_config {412/** @num_params: number of parameters returned in info */413__u32 num_params;414415/** @pad: MBZ */416__u32 pad;417418#define DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID 0419#define DRM_XE_QUERY_CONFIG_FLAGS 1420#define DRM_XE_QUERY_CONFIG_FLAG_HAS_VRAM (1 << 0)421#define DRM_XE_QUERY_CONFIG_FLAG_HAS_LOW_LATENCY (1 << 1)422#define DRM_XE_QUERY_CONFIG_FLAG_HAS_CPU_ADDR_MIRROR (1 << 2)423#define DRM_XE_QUERY_CONFIG_MIN_ALIGNMENT 2424#define DRM_XE_QUERY_CONFIG_VA_BITS 3425#define DRM_XE_QUERY_CONFIG_MAX_EXEC_QUEUE_PRIORITY 4426/** @info: array of elements containing the config info */427__u64 info[];428};429430/**431* struct drm_xe_gt - describe an individual GT.432*433* To be used with drm_xe_query_gt_list, which will return a list with all the434* existing GT individual descriptions.435* Graphics Technology (GT) is a subset of a GPU/tile that is responsible for436* implementing graphics and/or media operations.437*438* The index in @type can be:439* - %DRM_XE_QUERY_GT_TYPE_MAIN440* - %DRM_XE_QUERY_GT_TYPE_MEDIA441*/442struct drm_xe_gt {443#define DRM_XE_QUERY_GT_TYPE_MAIN 0444#define DRM_XE_QUERY_GT_TYPE_MEDIA 1445/** @type: GT type: Main or Media */446__u16 type;447/** @tile_id: Tile ID where this GT lives (Information only) */448__u16 tile_id;449/** @gt_id: Unique ID of this GT within the PCI Device */450__u16 gt_id;451/** @pad: MBZ */452__u16 pad[3];453/** @reference_clock: A clock frequency for timestamp */454__u32 reference_clock;455/**456* @near_mem_regions: Bit mask of instances from457* drm_xe_query_mem_regions that are nearest to the current engines458* of this GT.459* Each index in this mask refers directly to the struct460* drm_xe_query_mem_regions' instance, no assumptions should461* be made about order. The type of each region is described462* by struct drm_xe_query_mem_regions' mem_class.463*/464__u64 near_mem_regions;465/**466* @far_mem_regions: Bit mask of instances from467* drm_xe_query_mem_regions that are far from the engines of this GT.468* In general, they have extra indirections when compared to the469* @near_mem_regions. For a discrete device this could mean system470* memory and memory living in a different tile.471* Each index in this mask refers directly to the struct472* drm_xe_query_mem_regions' instance, no assumptions should473* be made about order. The type of each region is described474* by struct drm_xe_query_mem_regions' mem_class.475*/476__u64 far_mem_regions;477/** @ip_ver_major: Graphics/media IP major version on GMD_ID platforms */478__u16 ip_ver_major;479/** @ip_ver_minor: Graphics/media IP minor version on GMD_ID platforms */480__u16 ip_ver_minor;481/** @ip_ver_rev: Graphics/media IP revision version on GMD_ID platforms */482__u16 ip_ver_rev;483/** @pad2: MBZ */484__u16 pad2;485/** @reserved: Reserved */486__u64 reserved[7];487};488489/**490* struct drm_xe_query_gt_list - A list with GT description items.491*492* If a query is made with a struct drm_xe_device_query where .query493* is equal to DRM_XE_DEVICE_QUERY_GT_LIST, then the reply uses struct494* drm_xe_query_gt_list in .data.495*/496struct drm_xe_query_gt_list {497/** @num_gt: number of GT items returned in gt_list */498__u32 num_gt;499/** @pad: MBZ */500__u32 pad;501/** @gt_list: The GT list returned for this device */502struct drm_xe_gt gt_list[];503};504505/**506* struct drm_xe_query_topology_mask - describe the topology mask of a GT507*508* This is the hardware topology which reflects the internal physical509* structure of the GPU.510*511* If a query is made with a struct drm_xe_device_query where .query512* is equal to DRM_XE_DEVICE_QUERY_GT_TOPOLOGY, then the reply uses513* struct drm_xe_query_topology_mask in .data.514*515* The @type can be:516* - %DRM_XE_TOPO_DSS_GEOMETRY - To query the mask of Dual Sub Slices517* (DSS) available for geometry operations. For example a query response518* containing the following in mask:519* ``DSS_GEOMETRY ff ff ff ff 00 00 00 00``520* means 32 DSS are available for geometry.521* - %DRM_XE_TOPO_DSS_COMPUTE - To query the mask of Dual Sub Slices522* (DSS) available for compute operations. For example a query response523* containing the following in mask:524* ``DSS_COMPUTE ff ff ff ff 00 00 00 00``525* means 32 DSS are available for compute.526* - %DRM_XE_TOPO_L3_BANK - To query the mask of enabled L3 banks. This type527* may be omitted if the driver is unable to query the mask from the528* hardware.529* - %DRM_XE_TOPO_EU_PER_DSS - To query the mask of Execution Units (EU)530* available per Dual Sub Slices (DSS). For example a query response531* containing the following in mask:532* ``EU_PER_DSS ff ff 00 00 00 00 00 00``533* means each DSS has 16 SIMD8 EUs. This type may be omitted if device534* doesn't have SIMD8 EUs.535* - %DRM_XE_TOPO_SIMD16_EU_PER_DSS - To query the mask of SIMD16 Execution536* Units (EU) available per Dual Sub Slices (DSS). For example a query537* response containing the following in mask:538* ``SIMD16_EU_PER_DSS ff ff 00 00 00 00 00 00``539* means each DSS has 16 SIMD16 EUs. This type may be omitted if device540* doesn't have SIMD16 EUs.541*/542struct drm_xe_query_topology_mask {543/** @gt_id: GT ID the mask is associated with */544__u16 gt_id;545546#define DRM_XE_TOPO_DSS_GEOMETRY 1547#define DRM_XE_TOPO_DSS_COMPUTE 2548#define DRM_XE_TOPO_L3_BANK 3549#define DRM_XE_TOPO_EU_PER_DSS 4550#define DRM_XE_TOPO_SIMD16_EU_PER_DSS 5551/** @type: type of mask */552__u16 type;553554/** @num_bytes: number of bytes in requested mask */555__u32 num_bytes;556557/** @mask: little-endian mask of @num_bytes */558__u8 mask[];559};560561/**562* struct drm_xe_query_engine_cycles - correlate CPU and GPU timestamps563*564* If a query is made with a struct drm_xe_device_query where .query is equal to565* DRM_XE_DEVICE_QUERY_ENGINE_CYCLES, then the reply uses struct drm_xe_query_engine_cycles566* in .data. struct drm_xe_query_engine_cycles is allocated by the user and567* .data points to this allocated structure.568*569* The query returns the engine cycles, which along with GT's @reference_clock,570* can be used to calculate the engine timestamp. In addition the571* query returns a set of cpu timestamps that indicate when the command572* streamer cycle count was captured.573*/574struct drm_xe_query_engine_cycles {575/**576* @eci: This is input by the user and is the engine for which command577* streamer cycles is queried.578*/579struct drm_xe_engine_class_instance eci;580581/**582* @clockid: This is input by the user and is the reference clock id for583* CPU timestamp. For definition, see clock_gettime(2) and584* perf_event_open(2). Supported clock ids are CLOCK_MONOTONIC,585* CLOCK_MONOTONIC_RAW, CLOCK_REALTIME, CLOCK_BOOTTIME, CLOCK_TAI.586*/587__s32 clockid;588589/** @width: Width of the engine cycle counter in bits. */590__u32 width;591592/**593* @engine_cycles: Engine cycles as read from its register594* at 0x358 offset.595*/596__u64 engine_cycles;597598/**599* @cpu_timestamp: CPU timestamp in ns. The timestamp is captured before600* reading the engine_cycles register using the reference clockid set by the601* user.602*/603__u64 cpu_timestamp;604605/**606* @cpu_delta: Time delta in ns captured around reading the lower dword607* of the engine_cycles register.608*/609__u64 cpu_delta;610};611612/**613* struct drm_xe_query_uc_fw_version - query a micro-controller firmware version614*615* Given a uc_type this will return the branch, major, minor and patch version616* of the micro-controller firmware.617*/618struct drm_xe_query_uc_fw_version {619/** @uc_type: The micro-controller type to query firmware version */620#define XE_QUERY_UC_TYPE_GUC_SUBMISSION 0621#define XE_QUERY_UC_TYPE_HUC 1622__u16 uc_type;623624/** @pad: MBZ */625__u16 pad;626627/** @branch_ver: branch uc fw version */628__u32 branch_ver;629/** @major_ver: major uc fw version */630__u32 major_ver;631/** @minor_ver: minor uc fw version */632__u32 minor_ver;633/** @patch_ver: patch uc fw version */634__u32 patch_ver;635636/** @pad2: MBZ */637__u32 pad2;638639/** @reserved: Reserved */640__u64 reserved;641};642643/**644* struct drm_xe_query_pxp_status - query if PXP is ready645*646* If PXP is enabled and no fatal error has occurred, the status will be set to647* one of the following values:648* 0: PXP init still in progress649* 1: PXP init complete650*651* If PXP is not enabled or something has gone wrong, the query will be failed652* with one of the following error codes:653* -ENODEV: PXP not supported or disabled;654* -EIO: fatal error occurred during init, so PXP will never be enabled;655* -EINVAL: incorrect value provided as part of the query;656* -EFAULT: error copying the memory between kernel and userspace.657*658* The status can only be 0 in the first few seconds after driver load. If659* everything works as expected, the status will transition to init complete in660* less than 1 second, while in case of errors the driver might take longer to661* start returning an error code, but it should still take less than 10 seconds.662*663* The supported session type bitmask is based on the values in664* enum drm_xe_pxp_session_type. TYPE_NONE is always supported and therefore665* is not reported in the bitmask.666*667*/668struct drm_xe_query_pxp_status {669/** @status: current PXP status */670__u32 status;671672/** @supported_session_types: bitmask of supported PXP session types */673__u32 supported_session_types;674};675676/**677* struct drm_xe_device_query - Input of &DRM_IOCTL_XE_DEVICE_QUERY - main678* structure to query device information679*680* The user selects the type of data to query among DRM_XE_DEVICE_QUERY_*681* and sets the value in the query member. This determines the type of682* the structure provided by the driver in data, among struct drm_xe_query_*.683*684* The @query can be:685* - %DRM_XE_DEVICE_QUERY_ENGINES686* - %DRM_XE_DEVICE_QUERY_MEM_REGIONS687* - %DRM_XE_DEVICE_QUERY_CONFIG688* - %DRM_XE_DEVICE_QUERY_GT_LIST689* - %DRM_XE_DEVICE_QUERY_HWCONFIG - Query type to retrieve the hardware690* configuration of the device such as information on slices, memory,691* caches, and so on. It is provided as a table of key / value692* attributes.693* - %DRM_XE_DEVICE_QUERY_GT_TOPOLOGY694* - %DRM_XE_DEVICE_QUERY_ENGINE_CYCLES695* - %DRM_XE_DEVICE_QUERY_PXP_STATUS696*697* If size is set to 0, the driver fills it with the required size for698* the requested type of data to query. If size is equal to the required699* size, the queried information is copied into data. If size is set to700* a value different from 0 and different from the required size, the701* IOCTL call returns -EINVAL.702*703* For example the following code snippet allows retrieving and printing704* information about the device engines with DRM_XE_DEVICE_QUERY_ENGINES:705*706* .. code-block:: C707*708* struct drm_xe_query_engines *engines;709* struct drm_xe_device_query query = {710* .extensions = 0,711* .query = DRM_XE_DEVICE_QUERY_ENGINES,712* .size = 0,713* .data = 0,714* };715* ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query);716* engines = malloc(query.size);717* query.data = (uintptr_t)engines;718* ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query);719* for (int i = 0; i < engines->num_engines; i++) {720* printf("Engine %d: %s\n", i,721* engines->engines[i].instance.engine_class ==722* DRM_XE_ENGINE_CLASS_RENDER ? "RENDER":723* engines->engines[i].instance.engine_class ==724* DRM_XE_ENGINE_CLASS_COPY ? "COPY":725* engines->engines[i].instance.engine_class ==726* DRM_XE_ENGINE_CLASS_VIDEO_DECODE ? "VIDEO_DECODE":727* engines->engines[i].instance.engine_class ==728* DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE ? "VIDEO_ENHANCE":729* engines->engines[i].instance.engine_class ==730* DRM_XE_ENGINE_CLASS_COMPUTE ? "COMPUTE":731* "UNKNOWN");732* }733* free(engines);734*/735struct drm_xe_device_query {736/** @extensions: Pointer to the first extension struct, if any */737__u64 extensions;738739#define DRM_XE_DEVICE_QUERY_ENGINES 0740#define DRM_XE_DEVICE_QUERY_MEM_REGIONS 1741#define DRM_XE_DEVICE_QUERY_CONFIG 2742#define DRM_XE_DEVICE_QUERY_GT_LIST 3743#define DRM_XE_DEVICE_QUERY_HWCONFIG 4744#define DRM_XE_DEVICE_QUERY_GT_TOPOLOGY 5745#define DRM_XE_DEVICE_QUERY_ENGINE_CYCLES 6746#define DRM_XE_DEVICE_QUERY_UC_FW_VERSION 7747#define DRM_XE_DEVICE_QUERY_OA_UNITS 8748#define DRM_XE_DEVICE_QUERY_PXP_STATUS 9749#define DRM_XE_DEVICE_QUERY_EU_STALL 10750/** @query: The type of data to query */751__u32 query;752753/** @size: Size of the queried data */754__u32 size;755756/** @data: Queried data is placed here */757__u64 data;758759/** @reserved: Reserved */760__u64 reserved[2];761};762763/**764* struct drm_xe_gem_create - Input of &DRM_IOCTL_XE_GEM_CREATE - A structure for765* gem creation766*767* The @flags can be:768* - %DRM_XE_GEM_CREATE_FLAG_DEFER_BACKING - Modify the GEM object769* allocation strategy by deferring physical memory allocation770* until the object is either bound to a virtual memory region via771* VM_BIND or accessed by the CPU. As a result, no backing memory is772* reserved at the time of GEM object creation.773* - %DRM_XE_GEM_CREATE_FLAG_SCANOUT774* - %DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM - When using VRAM as a775* possible placement, ensure that the corresponding VRAM allocation776* will always use the CPU accessible part of VRAM. This is important777* for small-bar systems (on full-bar systems this gets turned into a778* noop).779* Note1: System memory can be used as an extra placement if the kernel780* should spill the allocation to system memory, if space can't be made781* available in the CPU accessible part of VRAM (giving the same782* behaviour as the i915 interface, see783* I915_GEM_CREATE_EXT_FLAG_NEEDS_CPU_ACCESS).784* Note2: For clear-color CCS surfaces the kernel needs to read the785* clear-color value stored in the buffer, and on discrete platforms we786* need to use VRAM for display surfaces, therefore the kernel requires787* setting this flag for such objects, otherwise an error is thrown on788* small-bar systems.789*790* @cpu_caching supports the following values:791* - %DRM_XE_GEM_CPU_CACHING_WB - Allocate the pages with write-back792* caching. On iGPU this can't be used for scanout surfaces. Currently793* not allowed for objects placed in VRAM.794* - %DRM_XE_GEM_CPU_CACHING_WC - Allocate the pages as write-combined. This795* is uncached. Scanout surfaces should likely use this. All objects796* that can be placed in VRAM must use this.797*798* This ioctl supports setting the following properties via the799* %DRM_XE_GEM_CREATE_EXTENSION_SET_PROPERTY extension, which uses the800* generic @drm_xe_ext_set_property struct:801*802* - %DRM_XE_GEM_CREATE_SET_PROPERTY_PXP_TYPE - set the type of PXP session803* this object will be used with. Valid values are listed in enum804* drm_xe_pxp_session_type. %DRM_XE_PXP_TYPE_NONE is the default behavior, so805* there is no need to explicitly set that. Objects used with session of type806* %DRM_XE_PXP_TYPE_HWDRM will be marked as invalid if a PXP invalidation807* event occurs after their creation. Attempting to flip an invalid object808* will cause a black frame to be displayed instead. Submissions with invalid809* objects mapped in the VM will be rejected.810*/811struct drm_xe_gem_create {812#define DRM_XE_GEM_CREATE_EXTENSION_SET_PROPERTY 0813#define DRM_XE_GEM_CREATE_SET_PROPERTY_PXP_TYPE 0814/** @extensions: Pointer to the first extension struct, if any */815__u64 extensions;816817/**818* @size: Size of the object to be created, must match region819* (system or vram) minimum alignment (&min_page_size).820*/821__u64 size;822823/**824* @placement: A mask of memory instances of where BO can be placed.825* Each index in this mask refers directly to the struct826* drm_xe_query_mem_regions' instance, no assumptions should827* be made about order. The type of each region is described828* by struct drm_xe_query_mem_regions' mem_class.829*/830__u32 placement;831832#define DRM_XE_GEM_CREATE_FLAG_DEFER_BACKING (1 << 0)833#define DRM_XE_GEM_CREATE_FLAG_SCANOUT (1 << 1)834#define DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM (1 << 2)835/**836* @flags: Flags, currently a mask of memory instances of where BO can837* be placed838*/839__u32 flags;840841/**842* @vm_id: Attached VM, if any843*844* If a VM is specified, this BO must:845*846* 1. Only ever be bound to that VM.847* 2. Cannot be exported as a PRIME fd.848*/849__u32 vm_id;850851/**852* @handle: Returned handle for the object.853*854* Object handles are nonzero.855*/856__u32 handle;857858#define DRM_XE_GEM_CPU_CACHING_WB 1859#define DRM_XE_GEM_CPU_CACHING_WC 2860/**861* @cpu_caching: The CPU caching mode to select for this object. If862* mmaping the object the mode selected here will also be used. The863* exception is when mapping system memory (including data evicted864* to system) on discrete GPUs. The caching mode selected will865* then be overridden to DRM_XE_GEM_CPU_CACHING_WB, and coherency866* between GPU- and CPU is guaranteed. The caching mode of867* existing CPU-mappings will be updated transparently to868* user-space clients.869*/870__u16 cpu_caching;871/** @pad: MBZ */872__u16 pad[3];873874/** @reserved: Reserved */875__u64 reserved[2];876};877878/**879* struct drm_xe_gem_mmap_offset - Input of &DRM_IOCTL_XE_GEM_MMAP_OFFSET880*881* The @flags can be:882* - %DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER - For user to query special offset883* for use in mmap ioctl. Writing to the returned mmap address will generate a884* PCI memory barrier with low overhead (avoiding IOCTL call as well as writing885* to VRAM which would also add overhead), acting like an MI_MEM_FENCE886* instruction.887*888* Note: The mmap size can be at most 4K, due to HW limitations. As a result889* this interface is only supported on CPU architectures that support 4K page890* size. The mmap_offset ioctl will detect this and gracefully return an891* error, where userspace is expected to have a different fallback method for892* triggering a barrier.893*894* Roughly the usage would be as follows:895*896* .. code-block:: C897*898* struct drm_xe_gem_mmap_offset mmo = {899* .handle = 0, // must be set to 0900* .flags = DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER,901* };902*903* err = ioctl(fd, DRM_IOCTL_XE_GEM_MMAP_OFFSET, &mmo);904* map = mmap(NULL, size, PROT_WRITE, MAP_SHARED, fd, mmo.offset);905* map[i] = 0xdeadbeaf; // issue barrier906*/907struct drm_xe_gem_mmap_offset {908/** @extensions: Pointer to the first extension struct, if any */909__u64 extensions;910911/** @handle: Handle for the object being mapped. */912__u32 handle;913914#define DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER (1 << 0)915/** @flags: Flags */916__u32 flags;917918/** @offset: The fake offset to use for subsequent mmap call */919__u64 offset;920921/** @reserved: Reserved */922__u64 reserved[2];923};924925/**926* struct drm_xe_vm_create - Input of &DRM_IOCTL_XE_VM_CREATE927*928* The @flags can be:929* - %DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE - Map the whole virtual address930* space of the VM to scratch page. A vm_bind would overwrite the scratch931* page mapping. This flag is mutually exclusive with the932* %DRM_XE_VM_CREATE_FLAG_FAULT_MODE flag, with an exception of on x2 and933* xe3 platform.934* - %DRM_XE_VM_CREATE_FLAG_LR_MODE - An LR, or Long Running VM accepts935* exec submissions to its exec_queues that don't have an upper time936* limit on the job execution time. But exec submissions to these937* don't allow any of the sync types DRM_XE_SYNC_TYPE_SYNCOBJ,938* DRM_XE_SYNC_TYPE_TIMELINE_SYNCOBJ, used as out-syncobjs, that is,939* together with sync flag DRM_XE_SYNC_FLAG_SIGNAL.940* LR VMs can be created in recoverable page-fault mode using941* DRM_XE_VM_CREATE_FLAG_FAULT_MODE, if the device supports it.942* If that flag is omitted, the UMD can not rely on the slightly943* different per-VM overcommit semantics that are enabled by944* DRM_XE_VM_CREATE_FLAG_FAULT_MODE (see below), but KMD may945* still enable recoverable pagefaults if supported by the device.946* - %DRM_XE_VM_CREATE_FLAG_FAULT_MODE - Requires also947* DRM_XE_VM_CREATE_FLAG_LR_MODE. It allows memory to be allocated on948* demand when accessed, and also allows per-VM overcommit of memory.949* The xe driver internally uses recoverable pagefaults to implement950* this.951*/952struct drm_xe_vm_create {953/** @extensions: Pointer to the first extension struct, if any */954__u64 extensions;955956#define DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE (1 << 0)957#define DRM_XE_VM_CREATE_FLAG_LR_MODE (1 << 1)958#define DRM_XE_VM_CREATE_FLAG_FAULT_MODE (1 << 2)959/** @flags: Flags */960__u32 flags;961962/** @vm_id: Returned VM ID */963__u32 vm_id;964965/** @reserved: Reserved */966__u64 reserved[2];967};968969/**970* struct drm_xe_vm_destroy - Input of &DRM_IOCTL_XE_VM_DESTROY971*/972struct drm_xe_vm_destroy {973/** @vm_id: VM ID */974__u32 vm_id;975976/** @pad: MBZ */977__u32 pad;978979/** @reserved: Reserved */980__u64 reserved[2];981};982983/**984* struct drm_xe_vm_bind_op - run bind operations985*986* The @op can be:987* - %DRM_XE_VM_BIND_OP_MAP988* - %DRM_XE_VM_BIND_OP_UNMAP989* - %DRM_XE_VM_BIND_OP_MAP_USERPTR990* - %DRM_XE_VM_BIND_OP_UNMAP_ALL991* - %DRM_XE_VM_BIND_OP_PREFETCH992*993* and the @flags can be:994* - %DRM_XE_VM_BIND_FLAG_READONLY - Setup the page tables as read-only995* to ensure write protection996* - %DRM_XE_VM_BIND_FLAG_IMMEDIATE - On a faulting VM, do the997* MAP operation immediately rather than deferring the MAP to the page998* fault handler. This is implied on a non-faulting VM as there is no999* fault handler to defer to.1000* - %DRM_XE_VM_BIND_FLAG_NULL - When the NULL flag is set, the page1001* tables are setup with a special bit which indicates writes are1002* dropped and all reads return zero. In the future, the NULL flags1003* will only be valid for DRM_XE_VM_BIND_OP_MAP operations, the BO1004* handle MBZ, and the BO offset MBZ. This flag is intended to1005* implement VK sparse bindings.1006* - %DRM_XE_VM_BIND_FLAG_CHECK_PXP - If the object is encrypted via PXP,1007* reject the binding if the encryption key is no longer valid. This1008* flag has no effect on BOs that are not marked as using PXP.1009* - %DRM_XE_VM_BIND_FLAG_CPU_ADDR_MIRROR - When the CPU address mirror flag is1010* set, no mappings are created rather the range is reserved for CPU address1011* mirroring which will be populated on GPU page faults or prefetches. Only1012* valid on VMs with DRM_XE_VM_CREATE_FLAG_FAULT_MODE set. The CPU address1013* mirror flag are only valid for DRM_XE_VM_BIND_OP_MAP operations, the BO1014* handle MBZ, and the BO offset MBZ.1015*1016* The @prefetch_mem_region_instance for %DRM_XE_VM_BIND_OP_PREFETCH can also be:1017* - %DRM_XE_CONSULT_MEM_ADVISE_PREF_LOC, which ensures prefetching occurs in1018* the memory region advised by madvise.1019*/1020struct drm_xe_vm_bind_op {1021/** @extensions: Pointer to the first extension struct, if any */1022__u64 extensions;10231024/**1025* @obj: GEM object to operate on, MBZ for MAP_USERPTR, MBZ for UNMAP1026*/1027__u32 obj;10281029/**1030* @pat_index: The platform defined @pat_index to use for this mapping.1031* The index basically maps to some predefined memory attributes,1032* including things like caching, coherency, compression etc. The exact1033* meaning of the pat_index is platform specific and defined in the1034* Bspec and PRMs. When the KMD sets up the binding the index here is1035* encoded into the ppGTT PTE.1036*1037* For coherency the @pat_index needs to be at least 1way coherent when1038* drm_xe_gem_create.cpu_caching is DRM_XE_GEM_CPU_CACHING_WB. The KMD1039* will extract the coherency mode from the @pat_index and reject if1040* there is a mismatch (see note below for pre-MTL platforms).1041*1042* Note: On pre-MTL platforms there is only a caching mode and no1043* explicit coherency mode, but on such hardware there is always a1044* shared-LLC (or is dgpu) so all GT memory accesses are coherent with1045* CPU caches even with the caching mode set as uncached. It's only the1046* display engine that is incoherent (on dgpu it must be in VRAM which1047* is always mapped as WC on the CPU). However to keep the uapi somewhat1048* consistent with newer platforms the KMD groups the different cache1049* levels into the following coherency buckets on all pre-MTL platforms:1050*1051* ppGTT UC -> COH_NONE1052* ppGTT WC -> COH_NONE1053* ppGTT WT -> COH_NONE1054* ppGTT WB -> COH_AT_LEAST_1WAY1055*1056* In practice UC/WC/WT should only ever used for scanout surfaces on1057* such platforms (or perhaps in general for dma-buf if shared with1058* another device) since it is only the display engine that is actually1059* incoherent. Everything else should typically use WB given that we1060* have a shared-LLC. On MTL+ this completely changes and the HW1061* defines the coherency mode as part of the @pat_index, where1062* incoherent GT access is possible.1063*1064* Note: For userptr and externally imported dma-buf the kernel expects1065* either 1WAY or 2WAY for the @pat_index.1066*1067* For DRM_XE_VM_BIND_FLAG_NULL bindings there are no KMD restrictions1068* on the @pat_index. For such mappings there is no actual memory being1069* mapped (the address in the PTE is invalid), so the various PAT memory1070* attributes likely do not apply. Simply leaving as zero is one1071* option (still a valid pat_index). Same applies to1072* DRM_XE_VM_BIND_FLAG_CPU_ADDR_MIRROR bindings as for such mapping1073* there is no actual memory being mapped.1074*/1075__u16 pat_index;10761077/** @pad: MBZ */1078__u16 pad;10791080union {1081/**1082* @obj_offset: Offset into the object, MBZ for CLEAR_RANGE,1083* ignored for unbind1084*/1085__u64 obj_offset;10861087/** @userptr: user pointer to bind on */1088__u64 userptr;10891090/**1091* @cpu_addr_mirror_offset: Offset from GPU @addr to create1092* CPU address mirror mappings. MBZ with current level of1093* support (e.g. 1 to 1 mapping between GPU and CPU mappings1094* only supported).1095*/1096__s64 cpu_addr_mirror_offset;1097};10981099/**1100* @range: Number of bytes from the object to bind to addr, MBZ for UNMAP_ALL1101*/1102__u64 range;11031104/** @addr: Address to operate on, MBZ for UNMAP_ALL */1105__u64 addr;11061107#define DRM_XE_VM_BIND_OP_MAP 0x01108#define DRM_XE_VM_BIND_OP_UNMAP 0x11109#define DRM_XE_VM_BIND_OP_MAP_USERPTR 0x21110#define DRM_XE_VM_BIND_OP_UNMAP_ALL 0x31111#define DRM_XE_VM_BIND_OP_PREFETCH 0x41112/** @op: Bind operation to perform */1113__u32 op;11141115#define DRM_XE_VM_BIND_FLAG_READONLY (1 << 0)1116#define DRM_XE_VM_BIND_FLAG_IMMEDIATE (1 << 1)1117#define DRM_XE_VM_BIND_FLAG_NULL (1 << 2)1118#define DRM_XE_VM_BIND_FLAG_DUMPABLE (1 << 3)1119#define DRM_XE_VM_BIND_FLAG_CHECK_PXP (1 << 4)1120#define DRM_XE_VM_BIND_FLAG_CPU_ADDR_MIRROR (1 << 5)1121/** @flags: Bind flags */1122__u32 flags;11231124#define DRM_XE_CONSULT_MEM_ADVISE_PREF_LOC -11125/**1126* @prefetch_mem_region_instance: Memory region to prefetch VMA to.1127* It is a region instance, not a mask.1128* To be used only with %DRM_XE_VM_BIND_OP_PREFETCH operation.1129*/1130__u32 prefetch_mem_region_instance;11311132/** @pad2: MBZ */1133__u32 pad2;11341135/** @reserved: Reserved */1136__u64 reserved[3];1137};11381139/**1140* struct drm_xe_vm_bind - Input of &DRM_IOCTL_XE_VM_BIND1141*1142* Below is an example of a minimal use of @drm_xe_vm_bind to1143* asynchronously bind the buffer `data` at address `BIND_ADDRESS` to1144* illustrate `userptr`. It can be synchronized by using the example1145* provided for @drm_xe_sync.1146*1147* .. code-block:: C1148*1149* data = aligned_alloc(ALIGNMENT, BO_SIZE);1150* struct drm_xe_vm_bind bind = {1151* .vm_id = vm,1152* .num_binds = 1,1153* .bind.obj = 0,1154* .bind.obj_offset = to_user_pointer(data),1155* .bind.range = BO_SIZE,1156* .bind.addr = BIND_ADDRESS,1157* .bind.op = DRM_XE_VM_BIND_OP_MAP_USERPTR,1158* .bind.flags = 0,1159* .num_syncs = 1,1160* .syncs = &sync,1161* .exec_queue_id = 0,1162* };1163* ioctl(fd, DRM_IOCTL_XE_VM_BIND, &bind);1164*1165*/1166struct drm_xe_vm_bind {1167/** @extensions: Pointer to the first extension struct, if any */1168__u64 extensions;11691170/** @vm_id: The ID of the VM to bind to */1171__u32 vm_id;11721173/**1174* @exec_queue_id: exec_queue_id, must be of class DRM_XE_ENGINE_CLASS_VM_BIND1175* and exec queue must have same vm_id. If zero, the default VM bind engine1176* is used.1177*/1178__u32 exec_queue_id;11791180/** @pad: MBZ */1181__u32 pad;11821183/** @num_binds: number of binds in this IOCTL */1184__u32 num_binds;11851186union {1187/** @bind: used if num_binds == 1 */1188struct drm_xe_vm_bind_op bind;11891190/**1191* @vector_of_binds: userptr to array of struct1192* drm_xe_vm_bind_op if num_binds > 11193*/1194__u64 vector_of_binds;1195};11961197/** @pad2: MBZ */1198__u32 pad2;11991200/** @num_syncs: amount of syncs to wait on */1201__u32 num_syncs;12021203/** @syncs: pointer to struct drm_xe_sync array */1204__u64 syncs;12051206/** @reserved: Reserved */1207__u64 reserved[2];1208};12091210/**1211* struct drm_xe_exec_queue_create - Input of &DRM_IOCTL_XE_EXEC_QUEUE_CREATE1212*1213* This ioctl supports setting the following properties via the1214* %DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY extension, which uses the1215* generic @drm_xe_ext_set_property struct:1216*1217* - %DRM_XE_EXEC_QUEUE_SET_PROPERTY_PRIORITY - set the queue priority.1218* CAP_SYS_NICE is required to set a value above normal.1219* - %DRM_XE_EXEC_QUEUE_SET_PROPERTY_TIMESLICE - set the queue timeslice1220* duration in microseconds.1221* - %DRM_XE_EXEC_QUEUE_SET_PROPERTY_PXP_TYPE - set the type of PXP session1222* this queue will be used with. Valid values are listed in enum1223* drm_xe_pxp_session_type. %DRM_XE_PXP_TYPE_NONE is the default behavior, so1224* there is no need to explicitly set that. When a queue of type1225* %DRM_XE_PXP_TYPE_HWDRM is created, the PXP default HWDRM session1226* (%XE_PXP_HWDRM_DEFAULT_SESSION) will be started, if isn't already running.1227* The user is expected to query the PXP status via the query ioctl (see1228* %DRM_XE_DEVICE_QUERY_PXP_STATUS) and to wait for PXP to be ready before1229* attempting to create a queue with this property. When a queue is created1230* before PXP is ready, the ioctl will return -EBUSY if init is still in1231* progress or -EIO if init failed.1232* Given that going into a power-saving state kills PXP HWDRM sessions,1233* runtime PM will be blocked while queues of this type are alive.1234* All PXP queues will be killed if a PXP invalidation event occurs.1235*1236* The example below shows how to use @drm_xe_exec_queue_create to create1237* a simple exec_queue (no parallel submission) of class1238* &DRM_XE_ENGINE_CLASS_RENDER.1239*1240* .. code-block:: C1241*1242* struct drm_xe_engine_class_instance instance = {1243* .engine_class = DRM_XE_ENGINE_CLASS_RENDER,1244* };1245* struct drm_xe_exec_queue_create exec_queue_create = {1246* .extensions = 0,1247* .vm_id = vm,1248* .num_bb_per_exec = 1,1249* .num_eng_per_bb = 1,1250* .instances = to_user_pointer(&instance),1251* };1252* ioctl(fd, DRM_IOCTL_XE_EXEC_QUEUE_CREATE, &exec_queue_create);1253*1254* Allow users to provide a hint to kernel for cases demanding low latency1255* profile. Please note it will have impact on power consumption. User can1256* indicate low latency hint with flag while creating exec queue as1257* mentioned below,1258*1259* struct drm_xe_exec_queue_create exec_queue_create = {1260* .flags = DRM_XE_EXEC_QUEUE_LOW_LATENCY_HINT,1261* .extensions = 0,1262* .vm_id = vm,1263* .num_bb_per_exec = 1,1264* .num_eng_per_bb = 1,1265* .instances = to_user_pointer(&instance),1266* };1267* ioctl(fd, DRM_IOCTL_XE_EXEC_QUEUE_CREATE, &exec_queue_create);1268*1269*/1270struct drm_xe_exec_queue_create {1271#define DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY 01272#define DRM_XE_EXEC_QUEUE_SET_PROPERTY_PRIORITY 01273#define DRM_XE_EXEC_QUEUE_SET_PROPERTY_TIMESLICE 11274#define DRM_XE_EXEC_QUEUE_SET_PROPERTY_PXP_TYPE 21275/** @extensions: Pointer to the first extension struct, if any */1276__u64 extensions;12771278/** @width: submission width (number BB per exec) for this exec queue */1279__u16 width;12801281/** @num_placements: number of valid placements for this exec queue */1282__u16 num_placements;12831284/** @vm_id: VM to use for this exec queue */1285__u32 vm_id;12861287#define DRM_XE_EXEC_QUEUE_LOW_LATENCY_HINT (1 << 0)1288/** @flags: flags to use for this exec queue */1289__u32 flags;12901291/** @exec_queue_id: Returned exec queue ID */1292__u32 exec_queue_id;12931294/**1295* @instances: user pointer to a 2-d array of struct1296* drm_xe_engine_class_instance1297*1298* length = width (i) * num_placements (j)1299* index = j + i * width1300*/1301__u64 instances;13021303/** @reserved: Reserved */1304__u64 reserved[2];1305};13061307/**1308* struct drm_xe_exec_queue_destroy - Input of &DRM_IOCTL_XE_EXEC_QUEUE_DESTROY1309*/1310struct drm_xe_exec_queue_destroy {1311/** @exec_queue_id: Exec queue ID */1312__u32 exec_queue_id;13131314/** @pad: MBZ */1315__u32 pad;13161317/** @reserved: Reserved */1318__u64 reserved[2];1319};13201321/**1322* struct drm_xe_exec_queue_get_property - Input of &DRM_IOCTL_XE_EXEC_QUEUE_GET_PROPERTY1323*1324* The @property can be:1325* - %DRM_XE_EXEC_QUEUE_GET_PROPERTY_BAN1326*/1327struct drm_xe_exec_queue_get_property {1328/** @extensions: Pointer to the first extension struct, if any */1329__u64 extensions;13301331/** @exec_queue_id: Exec queue ID */1332__u32 exec_queue_id;13331334#define DRM_XE_EXEC_QUEUE_GET_PROPERTY_BAN 01335/** @property: property to get */1336__u32 property;13371338/** @value: property value */1339__u64 value;13401341/** @reserved: Reserved */1342__u64 reserved[2];1343};13441345/**1346* struct drm_xe_sync - sync object1347*1348* The @type can be:1349* - %DRM_XE_SYNC_TYPE_SYNCOBJ1350* - %DRM_XE_SYNC_TYPE_TIMELINE_SYNCOBJ1351* - %DRM_XE_SYNC_TYPE_USER_FENCE1352*1353* and the @flags can be:1354* - %DRM_XE_SYNC_FLAG_SIGNAL1355*1356* A minimal use of @drm_xe_sync looks like this:1357*1358* .. code-block:: C1359*1360* struct drm_xe_sync sync = {1361* .flags = DRM_XE_SYNC_FLAG_SIGNAL,1362* .type = DRM_XE_SYNC_TYPE_SYNCOBJ,1363* };1364* struct drm_syncobj_create syncobj_create = { 0 };1365* ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &syncobj_create);1366* sync.handle = syncobj_create.handle;1367* ...1368* use of &sync in drm_xe_exec or drm_xe_vm_bind1369* ...1370* struct drm_syncobj_wait wait = {1371* .handles = &sync.handle,1372* .timeout_nsec = INT64_MAX,1373* .count_handles = 1,1374* .flags = 0,1375* .first_signaled = 0,1376* .pad = 0,1377* };1378* ioctl(fd, DRM_IOCTL_SYNCOBJ_WAIT, &wait);1379*/1380struct drm_xe_sync {1381/** @extensions: Pointer to the first extension struct, if any */1382__u64 extensions;13831384#define DRM_XE_SYNC_TYPE_SYNCOBJ 0x01385#define DRM_XE_SYNC_TYPE_TIMELINE_SYNCOBJ 0x11386#define DRM_XE_SYNC_TYPE_USER_FENCE 0x21387/** @type: Type of the this sync object */1388__u32 type;13891390#define DRM_XE_SYNC_FLAG_SIGNAL (1 << 0)1391/** @flags: Sync Flags */1392__u32 flags;13931394union {1395/** @handle: Handle for the object */1396__u32 handle;13971398/**1399* @addr: Address of user fence. When sync is passed in via exec1400* IOCTL this is a GPU address in the VM. When sync passed in via1401* VM bind IOCTL this is a user pointer. In either case, it is1402* the users responsibility that this address is present and1403* mapped when the user fence is signalled. Must be qword1404* aligned.1405*/1406__u64 addr;1407};14081409/**1410* @timeline_value: Input for the timeline sync object. Needs to be1411* different than 0 when used with %DRM_XE_SYNC_TYPE_TIMELINE_SYNCOBJ.1412*/1413__u64 timeline_value;14141415/** @reserved: Reserved */1416__u64 reserved[2];1417};14181419/**1420* struct drm_xe_exec - Input of &DRM_IOCTL_XE_EXEC1421*1422* This is an example to use @drm_xe_exec for execution of the object1423* at BIND_ADDRESS (see example in @drm_xe_vm_bind) by an exec_queue1424* (see example in @drm_xe_exec_queue_create). It can be synchronized1425* by using the example provided for @drm_xe_sync.1426*1427* .. code-block:: C1428*1429* struct drm_xe_exec exec = {1430* .exec_queue_id = exec_queue,1431* .syncs = &sync,1432* .num_syncs = 1,1433* .address = BIND_ADDRESS,1434* .num_batch_buffer = 1,1435* };1436* ioctl(fd, DRM_IOCTL_XE_EXEC, &exec);1437*1438*/1439struct drm_xe_exec {1440/** @extensions: Pointer to the first extension struct, if any */1441__u64 extensions;14421443/** @exec_queue_id: Exec queue ID for the batch buffer */1444__u32 exec_queue_id;14451446/** @num_syncs: Amount of struct drm_xe_sync in array. */1447__u32 num_syncs;14481449/** @syncs: Pointer to struct drm_xe_sync array. */1450__u64 syncs;14511452/**1453* @address: address of batch buffer if num_batch_buffer == 1 or an1454* array of batch buffer addresses1455*/1456__u64 address;14571458/**1459* @num_batch_buffer: number of batch buffer in this exec, must match1460* the width of the engine1461*/1462__u16 num_batch_buffer;14631464/** @pad: MBZ */1465__u16 pad[3];14661467/** @reserved: Reserved */1468__u64 reserved[2];1469};14701471/**1472* struct drm_xe_wait_user_fence - Input of &DRM_IOCTL_XE_WAIT_USER_FENCE1473*1474* Wait on user fence, XE will wake-up on every HW engine interrupt in the1475* instances list and check if user fence is complete::1476*1477* (*addr & MASK) OP (VALUE & MASK)1478*1479* Returns to user on user fence completion or timeout.1480*1481* The @op can be:1482* - %DRM_XE_UFENCE_WAIT_OP_EQ1483* - %DRM_XE_UFENCE_WAIT_OP_NEQ1484* - %DRM_XE_UFENCE_WAIT_OP_GT1485* - %DRM_XE_UFENCE_WAIT_OP_GTE1486* - %DRM_XE_UFENCE_WAIT_OP_LT1487* - %DRM_XE_UFENCE_WAIT_OP_LTE1488*1489* and the @flags can be:1490* - %DRM_XE_UFENCE_WAIT_FLAG_ABSTIME1491* - %DRM_XE_UFENCE_WAIT_FLAG_SOFT_OP1492*1493* The @mask values can be for example:1494* - 0xffu for u81495* - 0xffffu for u161496* - 0xffffffffu for u321497* - 0xffffffffffffffffu for u641498*/1499struct drm_xe_wait_user_fence {1500/** @extensions: Pointer to the first extension struct, if any */1501__u64 extensions;15021503/**1504* @addr: user pointer address to wait on, must qword aligned1505*/1506__u64 addr;15071508#define DRM_XE_UFENCE_WAIT_OP_EQ 0x01509#define DRM_XE_UFENCE_WAIT_OP_NEQ 0x11510#define DRM_XE_UFENCE_WAIT_OP_GT 0x21511#define DRM_XE_UFENCE_WAIT_OP_GTE 0x31512#define DRM_XE_UFENCE_WAIT_OP_LT 0x41513#define DRM_XE_UFENCE_WAIT_OP_LTE 0x51514/** @op: wait operation (type of comparison) */1515__u16 op;15161517#define DRM_XE_UFENCE_WAIT_FLAG_ABSTIME (1 << 0)1518/** @flags: wait flags */1519__u16 flags;15201521/** @pad: MBZ */1522__u32 pad;15231524/** @value: compare value */1525__u64 value;15261527/** @mask: comparison mask */1528__u64 mask;15291530/**1531* @timeout: how long to wait before bailing, value in nanoseconds.1532* Without DRM_XE_UFENCE_WAIT_FLAG_ABSTIME flag set (relative timeout)1533* it contains timeout expressed in nanoseconds to wait (fence will1534* expire at now() + timeout).1535* When DRM_XE_UFENCE_WAIT_FLAG_ABSTIME flat is set (absolute timeout) wait1536* will end at timeout (uses system MONOTONIC_CLOCK).1537* Passing negative timeout leads to neverending wait.1538*1539* On relative timeout this value is updated with timeout left1540* (for restarting the call in case of signal delivery).1541* On absolute timeout this value stays intact (restarted call still1542* expire at the same point of time).1543*/1544__s64 timeout;15451546/** @exec_queue_id: exec_queue_id returned from xe_exec_queue_create_ioctl */1547__u32 exec_queue_id;15481549/** @pad2: MBZ */1550__u32 pad2;15511552/** @reserved: Reserved */1553__u64 reserved[2];1554};15551556/**1557* enum drm_xe_observation_type - Observation stream types1558*/1559enum drm_xe_observation_type {1560/** @DRM_XE_OBSERVATION_TYPE_OA: OA observation stream type */1561DRM_XE_OBSERVATION_TYPE_OA,1562/** @DRM_XE_OBSERVATION_TYPE_EU_STALL: EU stall sampling observation stream type */1563DRM_XE_OBSERVATION_TYPE_EU_STALL,1564};15651566/**1567* enum drm_xe_observation_op - Observation stream ops1568*/1569enum drm_xe_observation_op {1570/** @DRM_XE_OBSERVATION_OP_STREAM_OPEN: Open an observation stream */1571DRM_XE_OBSERVATION_OP_STREAM_OPEN,15721573/** @DRM_XE_OBSERVATION_OP_ADD_CONFIG: Add observation stream config */1574DRM_XE_OBSERVATION_OP_ADD_CONFIG,15751576/** @DRM_XE_OBSERVATION_OP_REMOVE_CONFIG: Remove observation stream config */1577DRM_XE_OBSERVATION_OP_REMOVE_CONFIG,1578};15791580/**1581* struct drm_xe_observation_param - Input of &DRM_XE_OBSERVATION1582*1583* The observation layer enables multiplexing observation streams of1584* multiple types. The actual params for a particular stream operation are1585* supplied via the @param pointer (use __copy_from_user to get these1586* params).1587*/1588struct drm_xe_observation_param {1589/** @extensions: Pointer to the first extension struct, if any */1590__u64 extensions;1591/** @observation_type: observation stream type, of enum @drm_xe_observation_type */1592__u64 observation_type;1593/** @observation_op: observation stream op, of enum @drm_xe_observation_op */1594__u64 observation_op;1595/** @param: Pointer to actual stream params */1596__u64 param;1597};15981599/**1600* enum drm_xe_observation_ioctls - Observation stream fd ioctl's1601*1602* Information exchanged between userspace and kernel for observation fd1603* ioctl's is stream type specific1604*/1605enum drm_xe_observation_ioctls {1606/** @DRM_XE_OBSERVATION_IOCTL_ENABLE: Enable data capture for an observation stream */1607DRM_XE_OBSERVATION_IOCTL_ENABLE = _IO('i', 0x0),16081609/** @DRM_XE_OBSERVATION_IOCTL_DISABLE: Disable data capture for a observation stream */1610DRM_XE_OBSERVATION_IOCTL_DISABLE = _IO('i', 0x1),16111612/** @DRM_XE_OBSERVATION_IOCTL_CONFIG: Change observation stream configuration */1613DRM_XE_OBSERVATION_IOCTL_CONFIG = _IO('i', 0x2),16141615/** @DRM_XE_OBSERVATION_IOCTL_STATUS: Return observation stream status */1616DRM_XE_OBSERVATION_IOCTL_STATUS = _IO('i', 0x3),16171618/** @DRM_XE_OBSERVATION_IOCTL_INFO: Return observation stream info */1619DRM_XE_OBSERVATION_IOCTL_INFO = _IO('i', 0x4),1620};16211622/**1623* enum drm_xe_oa_unit_type - OA unit types1624*/1625enum drm_xe_oa_unit_type {1626/**1627* @DRM_XE_OA_UNIT_TYPE_OAG: OAG OA unit. OAR/OAC are considered1628* sub-types of OAG. For OAR/OAC, use OAG.1629*/1630DRM_XE_OA_UNIT_TYPE_OAG,16311632/** @DRM_XE_OA_UNIT_TYPE_OAM: OAM OA unit */1633DRM_XE_OA_UNIT_TYPE_OAM,16341635/** @DRM_XE_OA_UNIT_TYPE_OAM_SAG: OAM_SAG OA unit */1636DRM_XE_OA_UNIT_TYPE_OAM_SAG,1637};16381639/**1640* struct drm_xe_oa_unit - describe OA unit1641*/1642struct drm_xe_oa_unit {1643/** @extensions: Pointer to the first extension struct, if any */1644__u64 extensions;16451646/** @oa_unit_id: OA unit ID */1647__u32 oa_unit_id;16481649/** @oa_unit_type: OA unit type of @drm_xe_oa_unit_type */1650__u32 oa_unit_type;16511652/** @capabilities: OA capabilities bit-mask */1653__u64 capabilities;1654#define DRM_XE_OA_CAPS_BASE (1 << 0)1655#define DRM_XE_OA_CAPS_SYNCS (1 << 1)1656#define DRM_XE_OA_CAPS_OA_BUFFER_SIZE (1 << 2)1657#define DRM_XE_OA_CAPS_WAIT_NUM_REPORTS (1 << 3)1658#define DRM_XE_OA_CAPS_OAM (1 << 4)16591660/** @oa_timestamp_freq: OA timestamp freq */1661__u64 oa_timestamp_freq;16621663/** @reserved: MBZ */1664__u64 reserved[4];16651666/** @num_engines: number of engines in @eci array */1667__u64 num_engines;16681669/** @eci: engines attached to this OA unit */1670struct drm_xe_engine_class_instance eci[];1671};16721673/**1674* struct drm_xe_query_oa_units - describe OA units1675*1676* If a query is made with a struct drm_xe_device_query where .query1677* is equal to DRM_XE_DEVICE_QUERY_OA_UNITS, then the reply uses struct1678* drm_xe_query_oa_units in .data.1679*1680* OA unit properties for all OA units can be accessed using a code block1681* such as the one below:1682*1683* .. code-block:: C1684*1685* struct drm_xe_query_oa_units *qoa;1686* struct drm_xe_oa_unit *oau;1687* u8 *poau;1688*1689* // malloc qoa and issue DRM_XE_DEVICE_QUERY_OA_UNITS. Then:1690* poau = (u8 *)&qoa->oa_units[0];1691* for (int i = 0; i < qoa->num_oa_units; i++) {1692* oau = (struct drm_xe_oa_unit *)poau;1693* // Access 'struct drm_xe_oa_unit' fields here1694* poau += sizeof(*oau) + oau->num_engines * sizeof(oau->eci[0]);1695* }1696*/1697struct drm_xe_query_oa_units {1698/** @extensions: Pointer to the first extension struct, if any */1699__u64 extensions;1700/** @num_oa_units: number of OA units returned in oau[] */1701__u32 num_oa_units;1702/** @pad: MBZ */1703__u32 pad;1704/**1705* @oa_units: struct @drm_xe_oa_unit array returned for this device.1706* Written below as a u64 array to avoid problems with nested flexible1707* arrays with some compilers1708*/1709__u64 oa_units[];1710};17111712/**1713* enum drm_xe_oa_format_type - OA format types as specified in PRM/Bspec1714* 52198/609421715*/1716enum drm_xe_oa_format_type {1717/** @DRM_XE_OA_FMT_TYPE_OAG: OAG report format */1718DRM_XE_OA_FMT_TYPE_OAG,1719/** @DRM_XE_OA_FMT_TYPE_OAR: OAR report format */1720DRM_XE_OA_FMT_TYPE_OAR,1721/** @DRM_XE_OA_FMT_TYPE_OAM: OAM report format */1722DRM_XE_OA_FMT_TYPE_OAM,1723/** @DRM_XE_OA_FMT_TYPE_OAC: OAC report format */1724DRM_XE_OA_FMT_TYPE_OAC,1725/** @DRM_XE_OA_FMT_TYPE_OAM_MPEC: OAM SAMEDIA or OAM MPEC report format */1726DRM_XE_OA_FMT_TYPE_OAM_MPEC,1727/** @DRM_XE_OA_FMT_TYPE_PEC: PEC report format */1728DRM_XE_OA_FMT_TYPE_PEC,1729};17301731/**1732* enum drm_xe_oa_property_id - OA stream property id's1733*1734* Stream params are specified as a chain of @drm_xe_ext_set_property1735* struct's, with @property values from enum @drm_xe_oa_property_id and1736* @drm_xe_user_extension base.name set to @DRM_XE_OA_EXTENSION_SET_PROPERTY.1737* @param field in struct @drm_xe_observation_param points to the first1738* @drm_xe_ext_set_property struct.1739*1740* Exactly the same mechanism is also used for stream reconfiguration using the1741* @DRM_XE_OBSERVATION_IOCTL_CONFIG observation stream fd ioctl, though only a1742* subset of properties below can be specified for stream reconfiguration.1743*/1744enum drm_xe_oa_property_id {1745#define DRM_XE_OA_EXTENSION_SET_PROPERTY 01746/**1747* @DRM_XE_OA_PROPERTY_OA_UNIT_ID: ID of the OA unit on which to open1748* the OA stream, see @oa_unit_id in 'struct1749* drm_xe_query_oa_units'. Defaults to 0 if not provided.1750*/1751DRM_XE_OA_PROPERTY_OA_UNIT_ID = 1,17521753/**1754* @DRM_XE_OA_PROPERTY_SAMPLE_OA: A value of 1 requests inclusion of raw1755* OA unit reports or stream samples in a global buffer attached to an1756* OA unit.1757*/1758DRM_XE_OA_PROPERTY_SAMPLE_OA,17591760/**1761* @DRM_XE_OA_PROPERTY_OA_METRIC_SET: OA metrics defining contents of OA1762* reports, previously added via @DRM_XE_OBSERVATION_OP_ADD_CONFIG.1763*/1764DRM_XE_OA_PROPERTY_OA_METRIC_SET,17651766/** @DRM_XE_OA_PROPERTY_OA_FORMAT: OA counter report format */1767DRM_XE_OA_PROPERTY_OA_FORMAT,1768/*1769* OA_FORMAT's are specified the same way as in PRM/Bspec 52198/60942,1770* in terms of the following quantities: a. enum @drm_xe_oa_format_type1771* b. Counter select c. Counter size and d. BC report. Also refer to the1772* oa_formats array in drivers/gpu/drm/xe/xe_oa.c.1773*/1774#define DRM_XE_OA_FORMAT_MASK_FMT_TYPE (0xffu << 0)1775#define DRM_XE_OA_FORMAT_MASK_COUNTER_SEL (0xffu << 8)1776#define DRM_XE_OA_FORMAT_MASK_COUNTER_SIZE (0xffu << 16)1777#define DRM_XE_OA_FORMAT_MASK_BC_REPORT (0xffu << 24)17781779/**1780* @DRM_XE_OA_PROPERTY_OA_PERIOD_EXPONENT: Requests periodic OA unit1781* sampling with sampling frequency proportional to 2^(period_exponent + 1)1782*/1783DRM_XE_OA_PROPERTY_OA_PERIOD_EXPONENT,17841785/**1786* @DRM_XE_OA_PROPERTY_OA_DISABLED: A value of 1 will open the OA1787* stream in a DISABLED state (see @DRM_XE_OBSERVATION_IOCTL_ENABLE).1788*/1789DRM_XE_OA_PROPERTY_OA_DISABLED,17901791/**1792* @DRM_XE_OA_PROPERTY_EXEC_QUEUE_ID: Open the stream for a specific1793* @exec_queue_id. OA queries can be executed on this exec queue.1794*/1795DRM_XE_OA_PROPERTY_EXEC_QUEUE_ID,17961797/**1798* @DRM_XE_OA_PROPERTY_OA_ENGINE_INSTANCE: Optional engine instance to1799* pass along with @DRM_XE_OA_PROPERTY_EXEC_QUEUE_ID or will default to 0.1800*/1801DRM_XE_OA_PROPERTY_OA_ENGINE_INSTANCE,18021803/**1804* @DRM_XE_OA_PROPERTY_NO_PREEMPT: Allow preemption and timeslicing1805* to be disabled for the stream exec queue.1806*/1807DRM_XE_OA_PROPERTY_NO_PREEMPT,18081809/**1810* @DRM_XE_OA_PROPERTY_NUM_SYNCS: Number of syncs in the sync array1811* specified in @DRM_XE_OA_PROPERTY_SYNCS1812*/1813DRM_XE_OA_PROPERTY_NUM_SYNCS,18141815/**1816* @DRM_XE_OA_PROPERTY_SYNCS: Pointer to struct @drm_xe_sync array1817* with array size specified via @DRM_XE_OA_PROPERTY_NUM_SYNCS. OA1818* configuration will wait till input fences signal. Output fences1819* will signal after the new OA configuration takes effect. For1820* @DRM_XE_SYNC_TYPE_USER_FENCE, @addr is a user pointer, similar1821* to the VM bind case.1822*/1823DRM_XE_OA_PROPERTY_SYNCS,18241825/**1826* @DRM_XE_OA_PROPERTY_OA_BUFFER_SIZE: Size of OA buffer to be1827* allocated by the driver in bytes. Supported sizes are powers of1828* 2 from 128 KiB to 128 MiB. When not specified, a 16 MiB OA1829* buffer is allocated by default.1830*/1831DRM_XE_OA_PROPERTY_OA_BUFFER_SIZE,18321833/**1834* @DRM_XE_OA_PROPERTY_WAIT_NUM_REPORTS: Number of reports to wait1835* for before unblocking poll or read1836*/1837DRM_XE_OA_PROPERTY_WAIT_NUM_REPORTS,1838};18391840/**1841* struct drm_xe_oa_config - OA metric configuration1842*1843* Multiple OA configs can be added using @DRM_XE_OBSERVATION_OP_ADD_CONFIG. A1844* particular config can be specified when opening an OA stream using1845* @DRM_XE_OA_PROPERTY_OA_METRIC_SET property.1846*/1847struct drm_xe_oa_config {1848/** @extensions: Pointer to the first extension struct, if any */1849__u64 extensions;18501851/** @uuid: String formatted like "%\08x-%\04x-%\04x-%\04x-%\012x" */1852char uuid[36];18531854/** @n_regs: Number of regs in @regs_ptr */1855__u32 n_regs;18561857/**1858* @regs_ptr: Pointer to (register address, value) pairs for OA config1859* registers. Expected length of buffer is: (2 * sizeof(u32) * @n_regs).1860*/1861__u64 regs_ptr;1862};18631864/**1865* struct drm_xe_oa_stream_status - OA stream status returned from1866* @DRM_XE_OBSERVATION_IOCTL_STATUS observation stream fd ioctl. Userspace can1867* call the ioctl to query stream status in response to EIO errno from1868* observation fd read().1869*/1870struct drm_xe_oa_stream_status {1871/** @extensions: Pointer to the first extension struct, if any */1872__u64 extensions;18731874/** @oa_status: OA stream status (see Bspec 46717/61226) */1875__u64 oa_status;1876#define DRM_XE_OASTATUS_MMIO_TRG_Q_FULL (1 << 3)1877#define DRM_XE_OASTATUS_COUNTER_OVERFLOW (1 << 2)1878#define DRM_XE_OASTATUS_BUFFER_OVERFLOW (1 << 1)1879#define DRM_XE_OASTATUS_REPORT_LOST (1 << 0)18801881/** @reserved: reserved for future use */1882__u64 reserved[3];1883};18841885/**1886* struct drm_xe_oa_stream_info - OA stream info returned from1887* @DRM_XE_OBSERVATION_IOCTL_INFO observation stream fd ioctl1888*/1889struct drm_xe_oa_stream_info {1890/** @extensions: Pointer to the first extension struct, if any */1891__u64 extensions;18921893/** @oa_buf_size: OA buffer size */1894__u64 oa_buf_size;18951896/** @reserved: reserved for future use */1897__u64 reserved[3];1898};18991900/**1901* enum drm_xe_pxp_session_type - Supported PXP session types.1902*1903* We currently only support HWDRM sessions, which are used for protected1904* content that ends up being displayed, but the HW supports multiple types, so1905* we might extend support in the future.1906*/1907enum drm_xe_pxp_session_type {1908/** @DRM_XE_PXP_TYPE_NONE: PXP not used */1909DRM_XE_PXP_TYPE_NONE = 0,1910/**1911* @DRM_XE_PXP_TYPE_HWDRM: HWDRM sessions are used for content that ends1912* up on the display.1913*/1914DRM_XE_PXP_TYPE_HWDRM = 1,1915};19161917/* ID of the protected content session managed by Xe when PXP is active */1918#define DRM_XE_PXP_HWDRM_DEFAULT_SESSION 0xf19191920/**1921* enum drm_xe_eu_stall_property_id - EU stall sampling input property ids.1922*1923* These properties are passed to the driver at open as a chain of1924* @drm_xe_ext_set_property structures with @property set to these1925* properties' enums and @value set to the corresponding values of these1926* properties. @drm_xe_user_extension base.name should be set to1927* @DRM_XE_EU_STALL_EXTENSION_SET_PROPERTY.1928*1929* With the file descriptor obtained from open, user space must enable1930* the EU stall stream fd with @DRM_XE_OBSERVATION_IOCTL_ENABLE before1931* calling read(). EIO errno from read() indicates HW dropped data1932* due to full buffer.1933*/1934enum drm_xe_eu_stall_property_id {1935#define DRM_XE_EU_STALL_EXTENSION_SET_PROPERTY 01936/**1937* @DRM_XE_EU_STALL_PROP_GT_ID: @gt_id of the GT on which1938* EU stall data will be captured.1939*/1940DRM_XE_EU_STALL_PROP_GT_ID = 1,19411942/**1943* @DRM_XE_EU_STALL_PROP_SAMPLE_RATE: Sampling rate in1944* GPU cycles from @sampling_rates in struct @drm_xe_query_eu_stall1945*/1946DRM_XE_EU_STALL_PROP_SAMPLE_RATE,19471948/**1949* @DRM_XE_EU_STALL_PROP_WAIT_NUM_REPORTS: Minimum number of1950* EU stall data reports to be present in the kernel buffer1951* before unblocking a blocked poll or read.1952*/1953DRM_XE_EU_STALL_PROP_WAIT_NUM_REPORTS,1954};19551956/**1957* struct drm_xe_query_eu_stall - Information about EU stall sampling.1958*1959* If a query is made with a struct @drm_xe_device_query where .query1960* is equal to @DRM_XE_DEVICE_QUERY_EU_STALL, then the reply uses1961* struct @drm_xe_query_eu_stall in .data.1962*/1963struct drm_xe_query_eu_stall {1964/** @extensions: Pointer to the first extension struct, if any */1965__u64 extensions;19661967/** @capabilities: EU stall capabilities bit-mask */1968__u64 capabilities;1969#define DRM_XE_EU_STALL_CAPS_BASE (1 << 0)19701971/** @record_size: size of each EU stall data record */1972__u64 record_size;19731974/** @per_xecore_buf_size: internal per XeCore buffer size */1975__u64 per_xecore_buf_size;19761977/** @reserved: Reserved */1978__u64 reserved[5];19791980/** @num_sampling_rates: Number of sampling rates in @sampling_rates array */1981__u64 num_sampling_rates;19821983/**1984* @sampling_rates: Flexible array of sampling rates1985* sorted in the fastest to slowest order.1986* Sampling rates are specified in GPU clock cycles.1987*/1988__u64 sampling_rates[];1989};19901991/**1992* struct drm_xe_madvise - Input of &DRM_IOCTL_XE_MADVISE1993*1994* This structure is used to set memory attributes for a virtual address range1995* in a VM. The type of attribute is specified by @type, and the corresponding1996* union member is used to provide additional parameters for @type.1997*1998* Supported attribute types:1999* - DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC: Set preferred memory location.2000* - DRM_XE_MEM_RANGE_ATTR_ATOMIC: Set atomic access policy.2001* - DRM_XE_MEM_RANGE_ATTR_PAT: Set page attribute table index.2002*2003* Example:2004*2005* .. code-block:: C2006*2007* struct drm_xe_madvise madvise = {2008* .vm_id = vm_id,2009* .start = 0x100000,2010* .range = 0x2000,2011* .type = DRM_XE_MEM_RANGE_ATTR_ATOMIC,2012* .atomic_val = DRM_XE_ATOMIC_DEVICE,2013* };2014*2015* ioctl(fd, DRM_IOCTL_XE_MADVISE, &madvise);2016*2017*/2018struct drm_xe_madvise {2019/** @extensions: Pointer to the first extension struct, if any */2020__u64 extensions;20212022/** @start: start of the virtual address range */2023__u64 start;20242025/** @range: size of the virtual address range */2026__u64 range;20272028/** @vm_id: vm_id of the virtual range */2029__u32 vm_id;20302031#define DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC 02032#define DRM_XE_MEM_RANGE_ATTR_ATOMIC 12033#define DRM_XE_MEM_RANGE_ATTR_PAT 22034/** @type: type of attribute */2035__u32 type;20362037union {2038/**2039* @preferred_mem_loc: preferred memory location2040*2041* Used when @type == DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC2042*2043* Supported values for @preferred_mem_loc.devmem_fd:2044* - DRM_XE_PREFERRED_LOC_DEFAULT_DEVICE: set vram of fault tile as preferred loc2045* - DRM_XE_PREFERRED_LOC_DEFAULT_SYSTEM: set smem as preferred loc2046*2047* Supported values for @preferred_mem_loc.migration_policy:2048* - DRM_XE_MIGRATE_ALL_PAGES2049* - DRM_XE_MIGRATE_ONLY_SYSTEM_PAGES2050*/2051struct {2052#define DRM_XE_PREFERRED_LOC_DEFAULT_DEVICE 02053#define DRM_XE_PREFERRED_LOC_DEFAULT_SYSTEM -12054/** @preferred_mem_loc.devmem_fd: fd for preferred loc */2055__u32 devmem_fd;20562057#define DRM_XE_MIGRATE_ALL_PAGES 02058#define DRM_XE_MIGRATE_ONLY_SYSTEM_PAGES 12059/** @preferred_mem_loc.migration_policy: Page migration policy */2060__u16 migration_policy;20612062/** @preferred_mem_loc.pad : MBZ */2063__u16 pad;20642065/** @preferred_mem_loc.reserved : Reserved */2066__u64 reserved;2067} preferred_mem_loc;20682069/**2070* @atomic: Atomic access policy2071*2072* Used when @type == DRM_XE_MEM_RANGE_ATTR_ATOMIC.2073*2074* Supported values for @atomic.val:2075* - DRM_XE_ATOMIC_UNDEFINED: Undefined or default behaviour.2076* Support both GPU and CPU atomic operations for system allocator.2077* Support GPU atomic operations for normal(bo) allocator.2078* - DRM_XE_ATOMIC_DEVICE: Support GPU atomic operations.2079* - DRM_XE_ATOMIC_GLOBAL: Support both GPU and CPU atomic operations.2080* - DRM_XE_ATOMIC_CPU: Support CPU atomic only, no GPU atomics supported.2081*/2082struct {2083#define DRM_XE_ATOMIC_UNDEFINED 02084#define DRM_XE_ATOMIC_DEVICE 12085#define DRM_XE_ATOMIC_GLOBAL 22086#define DRM_XE_ATOMIC_CPU 32087/** @atomic.val: value of atomic operation */2088__u32 val;20892090/** @atomic.pad: MBZ */2091__u32 pad;20922093/** @atomic.reserved: Reserved */2094__u64 reserved;2095} atomic;20962097/**2098* @pat_index: Page attribute table index2099*2100* Used when @type == DRM_XE_MEM_RANGE_ATTR_PAT.2101*/2102struct {2103/** @pat_index.val: PAT index value */2104__u32 val;21052106/** @pat_index.pad: MBZ */2107__u32 pad;21082109/** @pat_index.reserved: Reserved */2110__u64 reserved;2111} pat_index;2112};21132114/** @reserved: Reserved */2115__u64 reserved[2];2116};21172118/**2119* struct drm_xe_mem_range_attr - Output of &DRM_IOCTL_XE_VM_QUERY_MEM_RANGES_ATTRS2120*2121* This structure is provided by userspace and filled by KMD in response to the2122* DRM_IOCTL_XE_VM_QUERY_MEM_RANGES_ATTRS ioctl. It describes memory attributes of2123* a memory ranges within a user specified address range in a VM.2124*2125* The structure includes information such as atomic access policy,2126* page attribute table (PAT) index, and preferred memory location.2127* Userspace allocates an array of these structures and passes a pointer to the2128* ioctl to retrieve attributes for each memory ranges2129*2130* @extensions: Pointer to the first extension struct, if any2131* @start: Start address of the memory range2132* @end: End address of the virtual memory range2133*2134*/2135struct drm_xe_mem_range_attr {2136/** @extensions: Pointer to the first extension struct, if any */2137__u64 extensions;21382139/** @start: start of the memory range */2140__u64 start;21412142/** @end: end of the memory range */2143__u64 end;21442145/** @preferred_mem_loc: preferred memory location */2146struct {2147/** @preferred_mem_loc.devmem_fd: fd for preferred loc */2148__u32 devmem_fd;21492150/** @preferred_mem_loc.migration_policy: Page migration policy */2151__u32 migration_policy;2152} preferred_mem_loc;21532154/** @atomic: Atomic access policy */2155struct {2156/** @atomic.val: atomic attribute */2157__u32 val;21582159/** @atomic.reserved: Reserved */2160__u32 reserved;2161} atomic;21622163/** @pat_index: Page attribute table index */2164struct {2165/** @pat_index.val: PAT index */2166__u32 val;21672168/** @pat_index.reserved: Reserved */2169__u32 reserved;2170} pat_index;21712172/** @reserved: Reserved */2173__u64 reserved[2];2174};21752176/**2177* struct drm_xe_vm_query_mem_range_attr - Input of &DRM_IOCTL_XE_VM_QUERY_MEM_ATTRIBUTES2178*2179* This structure is used to query memory attributes of memory regions2180* within a user specified address range in a VM. It provides detailed2181* information about each memory range, including atomic access policy,2182* page attribute table (PAT) index, and preferred memory location.2183*2184* Userspace first calls the ioctl with @num_mem_ranges = 0,2185* @sizeof_mem_ranges_attr = 0 and @vector_of_vma_mem_attr = NULL to retrieve2186* the number of memory regions and size of each memory range attribute.2187* Then, it allocates a buffer of that size and calls the ioctl again to fill2188* the buffer with memory range attributes.2189*2190* If second call fails with -ENOSPC, it means memory ranges changed between2191* first call and now, retry IOCTL again with @num_mem_ranges = 0,2192* @sizeof_mem_ranges_attr = 0 and @vector_of_vma_mem_attr = NULL followed by2193* Second ioctl call.2194*2195* Example:2196*2197* .. code-block:: C2198*2199* struct drm_xe_vm_query_mem_range_attr query = {2200* .vm_id = vm_id,2201* .start = 0x100000,2202* .range = 0x2000,2203* };2204*2205* // First ioctl call to get num of mem regions and sizeof each attribute2206* ioctl(fd, DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS, &query);2207*2208* // Allocate buffer for the memory region attributes2209* void *ptr = malloc(query.num_mem_ranges * query.sizeof_mem_range_attr);2210* void *ptr_start = ptr;2211*2212* query.vector_of_mem_attr = (uintptr_t)ptr;2213*2214* // Second ioctl call to actually fill the memory attributes2215* ioctl(fd, DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS, &query);2216*2217* // Iterate over the returned memory region attributes2218* for (unsigned int i = 0; i < query.num_mem_ranges; ++i) {2219* struct drm_xe_mem_range_attr *attr = (struct drm_xe_mem_range_attr *)ptr;2220*2221* // Do something with attr2222*2223* // Move pointer by one entry2224* ptr += query.sizeof_mem_range_attr;2225* }2226*2227* free(ptr_start);2228*/2229struct drm_xe_vm_query_mem_range_attr {2230/** @extensions: Pointer to the first extension struct, if any */2231__u64 extensions;22322233/** @vm_id: vm_id of the virtual range */2234__u32 vm_id;22352236/** @num_mem_ranges: number of mem_ranges in range */2237__u32 num_mem_ranges;22382239/** @start: start of the virtual address range */2240__u64 start;22412242/** @range: size of the virtual address range */2243__u64 range;22442245/** @sizeof_mem_range_attr: size of struct drm_xe_mem_range_attr */2246__u64 sizeof_mem_range_attr;22472248/** @vector_of_mem_attr: userptr to array of struct drm_xe_mem_range_attr */2249__u64 vector_of_mem_attr;22502251/** @reserved: Reserved */2252__u64 reserved[2];22532254};22552256#if defined(__cplusplus)2257}2258#endif22592260#endif /* _UAPI_XE_DRM_H_ */226122622263