1 /* SPDX-License-Identifier: MIT */ 2 /* 3 * Copyright © 2023 Intel Corporation 4 */ 5 6 #ifndef _UAPI_XE_DRM_H_ 7 #define _UAPI_XE_DRM_H_ 8 9 #include "drm.h" 10 11 #if defined(__cplusplus) 12 extern "C" { 13 #endif 14 15 /* 16 * Please note that modifications to all structs defined here are 17 * subject to backwards-compatibility constraints. 18 * Sections in this file are organized as follows: 19 * 1. IOCTL definition 20 * 2. Extension definition and helper structs 21 * 3. IOCTL's Query structs in the order of the Query's entries. 22 * 4. The rest of IOCTL structs in the order of IOCTL declaration. 23 */ 24 25 /** 26 * DOC: Xe Device Block Diagram 27 * 28 * The diagram below represents a high-level simplification of a discrete 29 * GPU supported by the Xe driver. It shows some device components which 30 * are necessary to understand this API, as well as how their relations 31 * to each other. This diagram does not represent real hardware:: 32 * 33 * ┌──────────────────────────────────────────────────────────────────┐ 34 * │ ┌──────────────────────────────────────────────────┐ ┌─────────┐ │ 35 * │ │ ┌───────────────────────┐ ┌─────┐ │ │ ┌─────┐ │ │ 36 * │ │ │ VRAM0 ├───┤ ... │ │ │ │VRAM1│ │ │ 37 * │ │ └───────────┬───────────┘ └─GT1─┘ │ │ └──┬──┘ │ │ 38 * │ │ ┌──────────────────┴───────────────────────────┐ │ │ ┌──┴──┐ │ │ 39 * │ │ │ ┌─────────────────────┐ ┌─────────────────┐ │ │ │ │ │ │ │ 40 * │ │ │ │ ┌──┐ ┌──┐ ┌──┐ ┌──┐ │ │ ┌─────┐ ┌─────┐ │ │ │ │ │ │ │ │ 41 * │ │ │ │ │EU│ │EU│ │EU│ │EU│ │ │ │RCS0 │ │BCS0 │ │ │ │ │ │ │ │ │ 42 * │ │ │ │ └──┘ └──┘ └──┘ └──┘ │ │ └─────┘ └─────┘ │ │ │ │ │ │ │ │ 43 * │ │ │ │ ┌──┐ ┌──┐ ┌──┐ ┌──┐ │ │ ┌─────┐ ┌─────┐ │ │ │ │ │ │ │ │ 44 * │ │ │ │ │EU│ │EU│ │EU│ │EU│ │ │ │VCS0 │ │VCS1 │ │ │ │ │ │ │ │ │ 45 * │ │ │ │ └──┘ └──┘ └──┘ └──┘ │ │ └─────┘ └─────┘ │ │ │ │ │ │ │ │ 46 * │ │ │ │ ┌──┐ ┌──┐ ┌──┐ ┌──┐ │ │ ┌─────┐ ┌─────┐ │ │ │ │ │ │ │ │ 47 * │ │ │ │ │EU│ │EU│ │EU│ │EU│ │ │ │VECS0│ │VECS1│ │ │ │ │ │ ... │ │ │ 48 * │ │ │ │ └──┘ └──┘ └──┘ └──┘ │ │ └─────┘ └─────┘ │ │ │ │ │ │ │ │ 49 * │ │ │ │ ┌──┐ ┌──┐ ┌──┐ ┌──┐ │ │ ┌─────┐ ┌─────┐ │ │ │ │ │ │ │ │ 50 * │ │ │ │ │EU│ │EU│ │EU│ │EU│ │ │ │CCS0 │ │CCS1 │ │ │ │ │ │ │ │ │ 51 * │ │ │ │ └──┘ └──┘ └──┘ └──┘ │ │ └─────┘ └─────┘ │ │ │ │ │ │ │ │ 52 * │ │ │ └─────────DSS─────────┘ │ ┌─────┐ ┌─────┐ │ │ │ │ │ │ │ │ 53 * │ │ │ │ │CCS2 │ │CCS3 │ │ │ │ │ │ │ │ │ 54 * │ │ │ ┌─────┐ ┌─────┐ ┌─────┐ │ └─────┘ └─────┘ │ │ │ │ │ │ │ │ 55 * │ │ │ │ ... │ │ ... │ │ ... │ │ │ │ │ │ │ │ │ │ 56 * │ │ │ └─DSS─┘ └─DSS─┘ └─DSS─┘ └─────Engines─────┘ │ │ │ │ │ │ │ 57 * │ │ └───────────────────────────GT0────────────────┘ │ │ └─GT2─┘ │ │ 58 * │ └────────────────────────────Tile0─────────────────┘ └─ Tile1──┘ │ 59 * └─────────────────────────────Device0───────┬──────────────────────┘ 60 * │ 61 * ───────────────────────┴────────── PCI bus 62 */ 63 64 /** 65 * DOC: Xe uAPI Overview 66 * 67 * This section aims to describe the Xe's IOCTL entries, its structs, and other 68 * Xe related uAPI such as uevents and PMU (Platform Monitoring Unit) related 69 * entries and usage. 70 * 71 * List of supported IOCTLs: 72 * - &DRM_IOCTL_XE_DEVICE_QUERY 73 * - &DRM_IOCTL_XE_GEM_CREATE 74 * - &DRM_IOCTL_XE_GEM_MMAP_OFFSET 75 * - &DRM_IOCTL_XE_VM_CREATE 76 * - &DRM_IOCTL_XE_VM_DESTROY 77 * - &DRM_IOCTL_XE_VM_BIND 78 * - &DRM_IOCTL_XE_EXEC_QUEUE_CREATE 79 * - &DRM_IOCTL_XE_EXEC_QUEUE_DESTROY 80 * - &DRM_IOCTL_XE_EXEC_QUEUE_GET_PROPERTY 81 * - &DRM_IOCTL_XE_EXEC 82 * - &DRM_IOCTL_XE_WAIT_USER_FENCE 83 * - &DRM_IOCTL_XE_OBSERVATION 84 * - &DRM_IOCTL_XE_MADVISE 85 * - &DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS 86 */ 87 88 /* 89 * xe specific ioctls. 90 * 91 * The device specific ioctl range is [DRM_COMMAND_BASE, DRM_COMMAND_END) ie 92 * [0x40, 0xa0) (a0 is excluded). The numbers below are defined as offset 93 * against DRM_COMMAND_BASE and should be between [0x0, 0x60). 94 */ 95 #define DRM_XE_DEVICE_QUERY 0x00 96 #define DRM_XE_GEM_CREATE 0x01 97 #define DRM_XE_GEM_MMAP_OFFSET 0x02 98 #define DRM_XE_VM_CREATE 0x03 99 #define DRM_XE_VM_DESTROY 0x04 100 #define DRM_XE_VM_BIND 0x05 101 #define DRM_XE_EXEC_QUEUE_CREATE 0x06 102 #define DRM_XE_EXEC_QUEUE_DESTROY 0x07 103 #define DRM_XE_EXEC_QUEUE_GET_PROPERTY 0x08 104 #define DRM_XE_EXEC 0x09 105 #define DRM_XE_WAIT_USER_FENCE 0x0a 106 #define DRM_XE_OBSERVATION 0x0b 107 #define DRM_XE_MADVISE 0x0c 108 #define DRM_XE_VM_QUERY_MEM_RANGE_ATTRS 0x0d 109 110 /* Must be kept compact -- no holes */ 111 112 #define DRM_IOCTL_XE_DEVICE_QUERY DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_DEVICE_QUERY, struct drm_xe_device_query) 113 #define DRM_IOCTL_XE_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_GEM_CREATE, struct drm_xe_gem_create) 114 #define DRM_IOCTL_XE_GEM_MMAP_OFFSET DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_GEM_MMAP_OFFSET, struct drm_xe_gem_mmap_offset) 115 #define DRM_IOCTL_XE_VM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_VM_CREATE, struct drm_xe_vm_create) 116 #define DRM_IOCTL_XE_VM_DESTROY DRM_IOW(DRM_COMMAND_BASE + DRM_XE_VM_DESTROY, struct drm_xe_vm_destroy) 117 #define DRM_IOCTL_XE_VM_BIND DRM_IOW(DRM_COMMAND_BASE + DRM_XE_VM_BIND, struct drm_xe_vm_bind) 118 #define DRM_IOCTL_XE_EXEC_QUEUE_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_EXEC_QUEUE_CREATE, struct drm_xe_exec_queue_create) 119 #define DRM_IOCTL_XE_EXEC_QUEUE_DESTROY DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC_QUEUE_DESTROY, struct drm_xe_exec_queue_destroy) 120 #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) 121 #define DRM_IOCTL_XE_EXEC DRM_IOW(DRM_COMMAND_BASE + DRM_XE_EXEC, struct drm_xe_exec) 122 #define DRM_IOCTL_XE_WAIT_USER_FENCE DRM_IOWR(DRM_COMMAND_BASE + DRM_XE_WAIT_USER_FENCE, struct drm_xe_wait_user_fence) 123 #define DRM_IOCTL_XE_OBSERVATION DRM_IOW(DRM_COMMAND_BASE + DRM_XE_OBSERVATION, struct drm_xe_observation_param) 124 #define DRM_IOCTL_XE_MADVISE DRM_IOW(DRM_COMMAND_BASE + DRM_XE_MADVISE, struct drm_xe_madvise) 125 #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) 126 127 /** 128 * DOC: Xe IOCTL Extensions 129 * 130 * Before detailing the IOCTLs and its structs, it is important to highlight 131 * that every IOCTL in Xe is extensible. 132 * 133 * Many interfaces need to grow over time. In most cases we can simply 134 * extend the struct and have userspace pass in more data. Another option, 135 * as demonstrated by Vulkan's approach to providing extensions for forward 136 * and backward compatibility, is to use a list of optional structs to 137 * provide those extra details. 138 * 139 * The key advantage to using an extension chain is that it allows us to 140 * redefine the interface more easily than an ever growing struct of 141 * increasing complexity, and for large parts of that interface to be 142 * entirely optional. The downside is more pointer chasing; chasing across 143 * the __user boundary with pointers encapsulated inside u64. 144 * 145 * Example chaining: 146 * 147 * .. code-block:: C 148 * 149 * struct drm_xe_user_extension ext3 { 150 * .next_extension = 0, // end 151 * .name = ..., 152 * }; 153 * struct drm_xe_user_extension ext2 { 154 * .next_extension = (uintptr_t)&ext3, 155 * .name = ..., 156 * }; 157 * struct drm_xe_user_extension ext1 { 158 * .next_extension = (uintptr_t)&ext2, 159 * .name = ..., 160 * }; 161 * 162 * Typically the struct drm_xe_user_extension would be embedded in some uAPI 163 * struct, and in this case we would feed it the head of the chain(i.e ext1), 164 * which would then apply all of the above extensions. 165 */ 166 167 /** 168 * struct drm_xe_user_extension - Base class for defining a chain of extensions 169 */ 170 struct drm_xe_user_extension { 171 /** 172 * @next_extension: 173 * 174 * Pointer to the next struct drm_xe_user_extension, or zero if the end. 175 */ 176 __u64 next_extension; 177 178 /** 179 * @name: Name of the extension. 180 * 181 * Note that the name here is just some integer. 182 * 183 * Also note that the name space for this is not global for the whole 184 * driver, but rather its scope/meaning is limited to the specific piece 185 * of uAPI which has embedded the struct drm_xe_user_extension. 186 */ 187 __u32 name; 188 189 /** 190 * @pad: MBZ 191 * 192 * All undefined bits must be zero. 193 */ 194 __u32 pad; 195 }; 196 197 /** 198 * struct drm_xe_ext_set_property - Generic set property extension 199 * 200 * A generic struct that allows any of the Xe's IOCTL to be extended 201 * with a set_property operation. 202 */ 203 struct drm_xe_ext_set_property { 204 /** @base: base user extension */ 205 struct drm_xe_user_extension base; 206 207 /** @property: property to set */ 208 __u32 property; 209 210 /** @pad: MBZ */ 211 __u32 pad; 212 213 /** @value: property value */ 214 __u64 value; 215 216 /** @reserved: Reserved */ 217 __u64 reserved[2]; 218 }; 219 220 /** 221 * struct drm_xe_engine_class_instance - instance of an engine class 222 * 223 * It is returned as part of the @drm_xe_engine, but it also is used as 224 * the input of engine selection for both @drm_xe_exec_queue_create and 225 * @drm_xe_query_engine_cycles 226 * 227 * The @engine_class can be: 228 * - %DRM_XE_ENGINE_CLASS_RENDER 229 * - %DRM_XE_ENGINE_CLASS_COPY 230 * - %DRM_XE_ENGINE_CLASS_VIDEO_DECODE 231 * - %DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE 232 * - %DRM_XE_ENGINE_CLASS_COMPUTE 233 * - %DRM_XE_ENGINE_CLASS_VM_BIND - Kernel only classes (not actual 234 * hardware engine class). Used for creating ordered queues of VM 235 * bind operations. 236 */ 237 struct drm_xe_engine_class_instance { 238 #define DRM_XE_ENGINE_CLASS_RENDER 0 239 #define DRM_XE_ENGINE_CLASS_COPY 1 240 #define DRM_XE_ENGINE_CLASS_VIDEO_DECODE 2 241 #define DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE 3 242 #define DRM_XE_ENGINE_CLASS_COMPUTE 4 243 #define DRM_XE_ENGINE_CLASS_VM_BIND 5 244 /** @engine_class: engine class id */ 245 __u16 engine_class; 246 /** @engine_instance: engine instance id */ 247 __u16 engine_instance; 248 /** @gt_id: Unique ID of this GT within the PCI Device */ 249 __u16 gt_id; 250 /** @pad: MBZ */ 251 __u16 pad; 252 }; 253 254 /** 255 * struct drm_xe_engine - describe hardware engine 256 */ 257 struct drm_xe_engine { 258 /** @instance: The @drm_xe_engine_class_instance */ 259 struct drm_xe_engine_class_instance instance; 260 261 /** @reserved: Reserved */ 262 __u64 reserved[3]; 263 }; 264 265 /** 266 * struct drm_xe_query_engines - describe engines 267 * 268 * If a query is made with a struct @drm_xe_device_query where .query 269 * is equal to %DRM_XE_DEVICE_QUERY_ENGINES, then the reply uses an array of 270 * struct @drm_xe_query_engines in .data. 271 */ 272 struct drm_xe_query_engines { 273 /** @num_engines: number of engines returned in @engines */ 274 __u32 num_engines; 275 /** @pad: MBZ */ 276 __u32 pad; 277 /** @engines: The returned engines for this device */ 278 struct drm_xe_engine engines[]; 279 }; 280 281 /** 282 * enum drm_xe_memory_class - Supported memory classes. 283 */ 284 enum drm_xe_memory_class { 285 /** @DRM_XE_MEM_REGION_CLASS_SYSMEM: Represents system memory. */ 286 DRM_XE_MEM_REGION_CLASS_SYSMEM = 0, 287 /** 288 * @DRM_XE_MEM_REGION_CLASS_VRAM: On discrete platforms, this 289 * represents the memory that is local to the device, which we 290 * call VRAM. Not valid on integrated platforms. 291 */ 292 DRM_XE_MEM_REGION_CLASS_VRAM 293 }; 294 295 /** 296 * struct drm_xe_mem_region - Describes some region as known to 297 * the driver. 298 */ 299 struct drm_xe_mem_region { 300 /** 301 * @mem_class: The memory class describing this region. 302 * 303 * See enum drm_xe_memory_class for supported values. 304 */ 305 __u16 mem_class; 306 /** 307 * @instance: The unique ID for this region, which serves as the 308 * index in the placement bitmask used as argument for 309 * &DRM_IOCTL_XE_GEM_CREATE 310 */ 311 __u16 instance; 312 /** 313 * @min_page_size: Min page-size in bytes for this region. 314 * 315 * When the kernel allocates memory for this region, the 316 * underlying pages will be at least @min_page_size in size. 317 * Buffer objects with an allowable placement in this region must be 318 * created with a size aligned to this value. 319 * GPU virtual address mappings of (parts of) buffer objects that 320 * may be placed in this region must also have their GPU virtual 321 * address and range aligned to this value. 322 * Affected IOCTLS will return %-EINVAL if alignment restrictions are 323 * not met. 324 */ 325 __u32 min_page_size; 326 /** 327 * @total_size: The usable size in bytes for this region. 328 */ 329 __u64 total_size; 330 /** 331 * @used: Estimate of the memory used in bytes for this region. 332 * 333 * Requires CAP_PERFMON or CAP_SYS_ADMIN to get reliable 334 * accounting. Without this the value here will always equal 335 * zero. 336 */ 337 __u64 used; 338 /** 339 * @cpu_visible_size: How much of this region can be CPU 340 * accessed, in bytes. 341 * 342 * This will always be <= @total_size, and the remainder (if 343 * any) will not be CPU accessible. If the CPU accessible part 344 * is smaller than @total_size then this is referred to as a 345 * small BAR system. 346 * 347 * On systems without small BAR (full BAR), the probed_size will 348 * always equal the @total_size, since all of it will be CPU 349 * accessible. 350 * 351 * Note this is only tracked for DRM_XE_MEM_REGION_CLASS_VRAM 352 * regions (for other types the value here will always equal 353 * zero). 354 */ 355 __u64 cpu_visible_size; 356 /** 357 * @cpu_visible_used: Estimate of CPU visible memory used, in 358 * bytes. 359 * 360 * Requires CAP_PERFMON or CAP_SYS_ADMIN to get reliable 361 * accounting. Without this the value here will always equal 362 * zero. Note this is only currently tracked for 363 * DRM_XE_MEM_REGION_CLASS_VRAM regions (for other types the value 364 * here will always be zero). 365 */ 366 __u64 cpu_visible_used; 367 /** @reserved: Reserved */ 368 __u64 reserved[6]; 369 }; 370 371 /** 372 * struct drm_xe_query_mem_regions - describe memory regions 373 * 374 * If a query is made with a struct drm_xe_device_query where .query 375 * is equal to DRM_XE_DEVICE_QUERY_MEM_REGIONS, then the reply uses 376 * struct drm_xe_query_mem_regions in .data. 377 */ 378 struct drm_xe_query_mem_regions { 379 /** @num_mem_regions: number of memory regions returned in @mem_regions */ 380 __u32 num_mem_regions; 381 /** @pad: MBZ */ 382 __u32 pad; 383 /** @mem_regions: The returned memory regions for this device */ 384 struct drm_xe_mem_region mem_regions[]; 385 }; 386 387 /** 388 * struct drm_xe_query_config - describe the device configuration 389 * 390 * If a query is made with a struct drm_xe_device_query where .query 391 * is equal to DRM_XE_DEVICE_QUERY_CONFIG, then the reply uses 392 * struct drm_xe_query_config in .data. 393 * 394 * The index in @info can be: 395 * - %DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID - Device ID (lower 16 bits) 396 * and the device revision (next 8 bits) 397 * - %DRM_XE_QUERY_CONFIG_FLAGS - Flags describing the device 398 * configuration, see list below 399 * 400 * - %DRM_XE_QUERY_CONFIG_FLAG_HAS_VRAM - Flag is set if the device 401 * has usable VRAM 402 * - %DRM_XE_QUERY_CONFIG_FLAG_HAS_LOW_LATENCY - Flag is set if the device 403 * has low latency hint support 404 * - %DRM_XE_QUERY_CONFIG_FLAG_HAS_CPU_ADDR_MIRROR - Flag is set if the 405 * device has CPU address mirroring support 406 * - %DRM_XE_QUERY_CONFIG_MIN_ALIGNMENT - Minimal memory alignment 407 * required by this device, typically SZ_4K or SZ_64K 408 * - %DRM_XE_QUERY_CONFIG_VA_BITS - Maximum bits of a virtual address 409 * - %DRM_XE_QUERY_CONFIG_MAX_EXEC_QUEUE_PRIORITY - Value of the highest 410 * available exec queue priority 411 */ 412 struct drm_xe_query_config { 413 /** @num_params: number of parameters returned in info */ 414 __u32 num_params; 415 416 /** @pad: MBZ */ 417 __u32 pad; 418 419 #define DRM_XE_QUERY_CONFIG_REV_AND_DEVICE_ID 0 420 #define DRM_XE_QUERY_CONFIG_FLAGS 1 421 #define DRM_XE_QUERY_CONFIG_FLAG_HAS_VRAM (1 << 0) 422 #define DRM_XE_QUERY_CONFIG_FLAG_HAS_LOW_LATENCY (1 << 1) 423 #define DRM_XE_QUERY_CONFIG_FLAG_HAS_CPU_ADDR_MIRROR (1 << 2) 424 #define DRM_XE_QUERY_CONFIG_MIN_ALIGNMENT 2 425 #define DRM_XE_QUERY_CONFIG_VA_BITS 3 426 #define DRM_XE_QUERY_CONFIG_MAX_EXEC_QUEUE_PRIORITY 4 427 /** @info: array of elements containing the config info */ 428 __u64 info[]; 429 }; 430 431 /** 432 * struct drm_xe_gt - describe an individual GT. 433 * 434 * To be used with drm_xe_query_gt_list, which will return a list with all the 435 * existing GT individual descriptions. 436 * Graphics Technology (GT) is a subset of a GPU/tile that is responsible for 437 * implementing graphics and/or media operations. 438 * 439 * The index in @type can be: 440 * - %DRM_XE_QUERY_GT_TYPE_MAIN 441 * - %DRM_XE_QUERY_GT_TYPE_MEDIA 442 */ 443 struct drm_xe_gt { 444 #define DRM_XE_QUERY_GT_TYPE_MAIN 0 445 #define DRM_XE_QUERY_GT_TYPE_MEDIA 1 446 /** @type: GT type: Main or Media */ 447 __u16 type; 448 /** @tile_id: Tile ID where this GT lives (Information only) */ 449 __u16 tile_id; 450 /** @gt_id: Unique ID of this GT within the PCI Device */ 451 __u16 gt_id; 452 /** @pad: MBZ */ 453 __u16 pad[3]; 454 /** @reference_clock: A clock frequency for timestamp */ 455 __u32 reference_clock; 456 /** 457 * @near_mem_regions: Bit mask of instances from 458 * drm_xe_query_mem_regions that are nearest to the current engines 459 * of this GT. 460 * Each index in this mask refers directly to the struct 461 * drm_xe_query_mem_regions' instance, no assumptions should 462 * be made about order. The type of each region is described 463 * by struct drm_xe_query_mem_regions' mem_class. 464 */ 465 __u64 near_mem_regions; 466 /** 467 * @far_mem_regions: Bit mask of instances from 468 * drm_xe_query_mem_regions that are far from the engines of this GT. 469 * In general, they have extra indirections when compared to the 470 * @near_mem_regions. For a discrete device this could mean system 471 * memory and memory living in a different tile. 472 * Each index in this mask refers directly to the struct 473 * drm_xe_query_mem_regions' instance, no assumptions should 474 * be made about order. The type of each region is described 475 * by struct drm_xe_query_mem_regions' mem_class. 476 */ 477 __u64 far_mem_regions; 478 /** @ip_ver_major: Graphics/media IP major version on GMD_ID platforms */ 479 __u16 ip_ver_major; 480 /** @ip_ver_minor: Graphics/media IP minor version on GMD_ID platforms */ 481 __u16 ip_ver_minor; 482 /** @ip_ver_rev: Graphics/media IP revision version on GMD_ID platforms */ 483 __u16 ip_ver_rev; 484 /** @pad2: MBZ */ 485 __u16 pad2; 486 /** @reserved: Reserved */ 487 __u64 reserved[7]; 488 }; 489 490 /** 491 * struct drm_xe_query_gt_list - A list with GT description items. 492 * 493 * If a query is made with a struct drm_xe_device_query where .query 494 * is equal to DRM_XE_DEVICE_QUERY_GT_LIST, then the reply uses struct 495 * drm_xe_query_gt_list in .data. 496 */ 497 struct drm_xe_query_gt_list { 498 /** @num_gt: number of GT items returned in gt_list */ 499 __u32 num_gt; 500 /** @pad: MBZ */ 501 __u32 pad; 502 /** @gt_list: The GT list returned for this device */ 503 struct drm_xe_gt gt_list[]; 504 }; 505 506 /** 507 * struct drm_xe_query_topology_mask - describe the topology mask of a GT 508 * 509 * This is the hardware topology which reflects the internal physical 510 * structure of the GPU. 511 * 512 * If a query is made with a struct drm_xe_device_query where .query 513 * is equal to DRM_XE_DEVICE_QUERY_GT_TOPOLOGY, then the reply uses 514 * struct drm_xe_query_topology_mask in .data. 515 * 516 * The @type can be: 517 * - %DRM_XE_TOPO_DSS_GEOMETRY - To query the mask of Dual Sub Slices 518 * (DSS) available for geometry operations. For example a query response 519 * containing the following in mask: 520 * ``DSS_GEOMETRY ff ff ff ff 00 00 00 00`` 521 * means 32 DSS are available for geometry. 522 * - %DRM_XE_TOPO_DSS_COMPUTE - To query the mask of Dual Sub Slices 523 * (DSS) available for compute operations. For example a query response 524 * containing the following in mask: 525 * ``DSS_COMPUTE ff ff ff ff 00 00 00 00`` 526 * means 32 DSS are available for compute. 527 * - %DRM_XE_TOPO_L3_BANK - To query the mask of enabled L3 banks. This type 528 * may be omitted if the driver is unable to query the mask from the 529 * hardware. 530 * - %DRM_XE_TOPO_EU_PER_DSS - To query the mask of Execution Units (EU) 531 * available per Dual Sub Slices (DSS). For example a query response 532 * containing the following in mask: 533 * ``EU_PER_DSS ff ff 00 00 00 00 00 00`` 534 * means each DSS has 16 SIMD8 EUs. This type may be omitted if device 535 * doesn't have SIMD8 EUs. 536 * - %DRM_XE_TOPO_SIMD16_EU_PER_DSS - To query the mask of SIMD16 Execution 537 * Units (EU) available per Dual Sub Slices (DSS). For example a query 538 * response containing the following in mask: 539 * ``SIMD16_EU_PER_DSS ff ff 00 00 00 00 00 00`` 540 * means each DSS has 16 SIMD16 EUs. This type may be omitted if device 541 * doesn't have SIMD16 EUs. 542 */ 543 struct drm_xe_query_topology_mask { 544 /** @gt_id: GT ID the mask is associated with */ 545 __u16 gt_id; 546 547 #define DRM_XE_TOPO_DSS_GEOMETRY 1 548 #define DRM_XE_TOPO_DSS_COMPUTE 2 549 #define DRM_XE_TOPO_L3_BANK 3 550 #define DRM_XE_TOPO_EU_PER_DSS 4 551 #define DRM_XE_TOPO_SIMD16_EU_PER_DSS 5 552 /** @type: type of mask */ 553 __u16 type; 554 555 /** @num_bytes: number of bytes in requested mask */ 556 __u32 num_bytes; 557 558 /** @mask: little-endian mask of @num_bytes */ 559 __u8 mask[]; 560 }; 561 562 /** 563 * struct drm_xe_query_engine_cycles - correlate CPU and GPU timestamps 564 * 565 * If a query is made with a struct drm_xe_device_query where .query is equal to 566 * DRM_XE_DEVICE_QUERY_ENGINE_CYCLES, then the reply uses struct drm_xe_query_engine_cycles 567 * in .data. struct drm_xe_query_engine_cycles is allocated by the user and 568 * .data points to this allocated structure. 569 * 570 * The query returns the engine cycles, which along with GT's @reference_clock, 571 * can be used to calculate the engine timestamp. In addition the 572 * query returns a set of cpu timestamps that indicate when the command 573 * streamer cycle count was captured. 574 */ 575 struct drm_xe_query_engine_cycles { 576 /** 577 * @eci: This is input by the user and is the engine for which command 578 * streamer cycles is queried. 579 */ 580 struct drm_xe_engine_class_instance eci; 581 582 /** 583 * @clockid: This is input by the user and is the reference clock id for 584 * CPU timestamp. For definition, see clock_gettime(2) and 585 * perf_event_open(2). Supported clock ids are CLOCK_MONOTONIC, 586 * CLOCK_MONOTONIC_RAW, CLOCK_REALTIME, CLOCK_BOOTTIME, CLOCK_TAI. 587 */ 588 __s32 clockid; 589 590 /** @width: Width of the engine cycle counter in bits. */ 591 __u32 width; 592 593 /** 594 * @engine_cycles: Engine cycles as read from its register 595 * at 0x358 offset. 596 */ 597 __u64 engine_cycles; 598 599 /** 600 * @cpu_timestamp: CPU timestamp in ns. The timestamp is captured before 601 * reading the engine_cycles register using the reference clockid set by the 602 * user. 603 */ 604 __u64 cpu_timestamp; 605 606 /** 607 * @cpu_delta: Time delta in ns captured around reading the lower dword 608 * of the engine_cycles register. 609 */ 610 __u64 cpu_delta; 611 }; 612 613 /** 614 * struct drm_xe_query_uc_fw_version - query a micro-controller firmware version 615 * 616 * Given a uc_type this will return the branch, major, minor and patch version 617 * of the micro-controller firmware. 618 */ 619 struct drm_xe_query_uc_fw_version { 620 /** @uc_type: The micro-controller type to query firmware version */ 621 #define XE_QUERY_UC_TYPE_GUC_SUBMISSION 0 622 #define XE_QUERY_UC_TYPE_HUC 1 623 __u16 uc_type; 624 625 /** @pad: MBZ */ 626 __u16 pad; 627 628 /** @branch_ver: branch uc fw version */ 629 __u32 branch_ver; 630 /** @major_ver: major uc fw version */ 631 __u32 major_ver; 632 /** @minor_ver: minor uc fw version */ 633 __u32 minor_ver; 634 /** @patch_ver: patch uc fw version */ 635 __u32 patch_ver; 636 637 /** @pad2: MBZ */ 638 __u32 pad2; 639 640 /** @reserved: Reserved */ 641 __u64 reserved; 642 }; 643 644 /** 645 * struct drm_xe_query_pxp_status - query if PXP is ready 646 * 647 * If PXP is enabled and no fatal error has occurred, the status will be set to 648 * one of the following values: 649 * 0: PXP init still in progress 650 * 1: PXP init complete 651 * 652 * If PXP is not enabled or something has gone wrong, the query will be failed 653 * with one of the following error codes: 654 * -ENODEV: PXP not supported or disabled; 655 * -EIO: fatal error occurred during init, so PXP will never be enabled; 656 * -EINVAL: incorrect value provided as part of the query; 657 * -EFAULT: error copying the memory between kernel and userspace. 658 * 659 * The status can only be 0 in the first few seconds after driver load. If 660 * everything works as expected, the status will transition to init complete in 661 * less than 1 second, while in case of errors the driver might take longer to 662 * start returning an error code, but it should still take less than 10 seconds. 663 * 664 * The supported session type bitmask is based on the values in 665 * enum drm_xe_pxp_session_type. TYPE_NONE is always supported and therefore 666 * is not reported in the bitmask. 667 * 668 */ 669 struct drm_xe_query_pxp_status { 670 /** @status: current PXP status */ 671 __u32 status; 672 673 /** @supported_session_types: bitmask of supported PXP session types */ 674 __u32 supported_session_types; 675 }; 676 677 /** 678 * struct drm_xe_device_query - Input of &DRM_IOCTL_XE_DEVICE_QUERY - main 679 * structure to query device information 680 * 681 * The user selects the type of data to query among DRM_XE_DEVICE_QUERY_* 682 * and sets the value in the query member. This determines the type of 683 * the structure provided by the driver in data, among struct drm_xe_query_*. 684 * 685 * The @query can be: 686 * - %DRM_XE_DEVICE_QUERY_ENGINES 687 * - %DRM_XE_DEVICE_QUERY_MEM_REGIONS 688 * - %DRM_XE_DEVICE_QUERY_CONFIG 689 * - %DRM_XE_DEVICE_QUERY_GT_LIST 690 * - %DRM_XE_DEVICE_QUERY_HWCONFIG - Query type to retrieve the hardware 691 * configuration of the device such as information on slices, memory, 692 * caches, and so on. It is provided as a table of key / value 693 * attributes. 694 * - %DRM_XE_DEVICE_QUERY_GT_TOPOLOGY 695 * - %DRM_XE_DEVICE_QUERY_ENGINE_CYCLES 696 * - %DRM_XE_DEVICE_QUERY_PXP_STATUS 697 * 698 * If size is set to 0, the driver fills it with the required size for 699 * the requested type of data to query. If size is equal to the required 700 * size, the queried information is copied into data. If size is set to 701 * a value different from 0 and different from the required size, the 702 * IOCTL call returns -EINVAL. 703 * 704 * For example the following code snippet allows retrieving and printing 705 * information about the device engines with DRM_XE_DEVICE_QUERY_ENGINES: 706 * 707 * .. code-block:: C 708 * 709 * struct drm_xe_query_engines *engines; 710 * struct drm_xe_device_query query = { 711 * .extensions = 0, 712 * .query = DRM_XE_DEVICE_QUERY_ENGINES, 713 * .size = 0, 714 * .data = 0, 715 * }; 716 * ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query); 717 * engines = malloc(query.size); 718 * query.data = (uintptr_t)engines; 719 * ioctl(fd, DRM_IOCTL_XE_DEVICE_QUERY, &query); 720 * for (int i = 0; i < engines->num_engines; i++) { 721 * printf("Engine %d: %s\n", i, 722 * engines->engines[i].instance.engine_class == 723 * DRM_XE_ENGINE_CLASS_RENDER ? "RENDER": 724 * engines->engines[i].instance.engine_class == 725 * DRM_XE_ENGINE_CLASS_COPY ? "COPY": 726 * engines->engines[i].instance.engine_class == 727 * DRM_XE_ENGINE_CLASS_VIDEO_DECODE ? "VIDEO_DECODE": 728 * engines->engines[i].instance.engine_class == 729 * DRM_XE_ENGINE_CLASS_VIDEO_ENHANCE ? "VIDEO_ENHANCE": 730 * engines->engines[i].instance.engine_class == 731 * DRM_XE_ENGINE_CLASS_COMPUTE ? "COMPUTE": 732 * "UNKNOWN"); 733 * } 734 * free(engines); 735 */ 736 struct drm_xe_device_query { 737 /** @extensions: Pointer to the first extension struct, if any */ 738 __u64 extensions; 739 740 #define DRM_XE_DEVICE_QUERY_ENGINES 0 741 #define DRM_XE_DEVICE_QUERY_MEM_REGIONS 1 742 #define DRM_XE_DEVICE_QUERY_CONFIG 2 743 #define DRM_XE_DEVICE_QUERY_GT_LIST 3 744 #define DRM_XE_DEVICE_QUERY_HWCONFIG 4 745 #define DRM_XE_DEVICE_QUERY_GT_TOPOLOGY 5 746 #define DRM_XE_DEVICE_QUERY_ENGINE_CYCLES 6 747 #define DRM_XE_DEVICE_QUERY_UC_FW_VERSION 7 748 #define DRM_XE_DEVICE_QUERY_OA_UNITS 8 749 #define DRM_XE_DEVICE_QUERY_PXP_STATUS 9 750 #define DRM_XE_DEVICE_QUERY_EU_STALL 10 751 /** @query: The type of data to query */ 752 __u32 query; 753 754 /** @size: Size of the queried data */ 755 __u32 size; 756 757 /** @data: Queried data is placed here */ 758 __u64 data; 759 760 /** @reserved: Reserved */ 761 __u64 reserved[2]; 762 }; 763 764 /** 765 * struct drm_xe_gem_create - Input of &DRM_IOCTL_XE_GEM_CREATE - A structure for 766 * gem creation 767 * 768 * The @flags can be: 769 * - %DRM_XE_GEM_CREATE_FLAG_DEFER_BACKING - Modify the GEM object 770 * allocation strategy by deferring physical memory allocation 771 * until the object is either bound to a virtual memory region via 772 * VM_BIND or accessed by the CPU. As a result, no backing memory is 773 * reserved at the time of GEM object creation. 774 * - %DRM_XE_GEM_CREATE_FLAG_SCANOUT 775 * - %DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM - When using VRAM as a 776 * possible placement, ensure that the corresponding VRAM allocation 777 * will always use the CPU accessible part of VRAM. This is important 778 * for small-bar systems (on full-bar systems this gets turned into a 779 * noop). 780 * Note1: System memory can be used as an extra placement if the kernel 781 * should spill the allocation to system memory, if space can't be made 782 * available in the CPU accessible part of VRAM (giving the same 783 * behaviour as the i915 interface, see 784 * I915_GEM_CREATE_EXT_FLAG_NEEDS_CPU_ACCESS). 785 * Note2: For clear-color CCS surfaces the kernel needs to read the 786 * clear-color value stored in the buffer, and on discrete platforms we 787 * need to use VRAM for display surfaces, therefore the kernel requires 788 * setting this flag for such objects, otherwise an error is thrown on 789 * small-bar systems. 790 * 791 * @cpu_caching supports the following values: 792 * - %DRM_XE_GEM_CPU_CACHING_WB - Allocate the pages with write-back 793 * caching. On iGPU this can't be used for scanout surfaces. Currently 794 * not allowed for objects placed in VRAM. 795 * - %DRM_XE_GEM_CPU_CACHING_WC - Allocate the pages as write-combined. This 796 * is uncached. Scanout surfaces should likely use this. All objects 797 * that can be placed in VRAM must use this. 798 * 799 * This ioctl supports setting the following properties via the 800 * %DRM_XE_GEM_CREATE_EXTENSION_SET_PROPERTY extension, which uses the 801 * generic @drm_xe_ext_set_property struct: 802 * 803 * - %DRM_XE_GEM_CREATE_SET_PROPERTY_PXP_TYPE - set the type of PXP session 804 * this object will be used with. Valid values are listed in enum 805 * drm_xe_pxp_session_type. %DRM_XE_PXP_TYPE_NONE is the default behavior, so 806 * there is no need to explicitly set that. Objects used with session of type 807 * %DRM_XE_PXP_TYPE_HWDRM will be marked as invalid if a PXP invalidation 808 * event occurs after their creation. Attempting to flip an invalid object 809 * will cause a black frame to be displayed instead. Submissions with invalid 810 * objects mapped in the VM will be rejected. 811 */ 812 struct drm_xe_gem_create { 813 #define DRM_XE_GEM_CREATE_EXTENSION_SET_PROPERTY 0 814 #define DRM_XE_GEM_CREATE_SET_PROPERTY_PXP_TYPE 0 815 /** @extensions: Pointer to the first extension struct, if any */ 816 __u64 extensions; 817 818 /** 819 * @size: Size of the object to be created, must match region 820 * (system or vram) minimum alignment (&min_page_size). 821 */ 822 __u64 size; 823 824 /** 825 * @placement: A mask of memory instances of where BO can be placed. 826 * Each index in this mask refers directly to the struct 827 * drm_xe_query_mem_regions' instance, no assumptions should 828 * be made about order. The type of each region is described 829 * by struct drm_xe_query_mem_regions' mem_class. 830 */ 831 __u32 placement; 832 833 #define DRM_XE_GEM_CREATE_FLAG_DEFER_BACKING (1 << 0) 834 #define DRM_XE_GEM_CREATE_FLAG_SCANOUT (1 << 1) 835 #define DRM_XE_GEM_CREATE_FLAG_NEEDS_VISIBLE_VRAM (1 << 2) 836 /** 837 * @flags: Flags, currently a mask of memory instances of where BO can 838 * be placed 839 */ 840 __u32 flags; 841 842 /** 843 * @vm_id: Attached VM, if any 844 * 845 * If a VM is specified, this BO must: 846 * 847 * 1. Only ever be bound to that VM. 848 * 2. Cannot be exported as a PRIME fd. 849 */ 850 __u32 vm_id; 851 852 /** 853 * @handle: Returned handle for the object. 854 * 855 * Object handles are nonzero. 856 */ 857 __u32 handle; 858 859 #define DRM_XE_GEM_CPU_CACHING_WB 1 860 #define DRM_XE_GEM_CPU_CACHING_WC 2 861 /** 862 * @cpu_caching: The CPU caching mode to select for this object. If 863 * mmaping the object the mode selected here will also be used. The 864 * exception is when mapping system memory (including data evicted 865 * to system) on discrete GPUs. The caching mode selected will 866 * then be overridden to DRM_XE_GEM_CPU_CACHING_WB, and coherency 867 * between GPU- and CPU is guaranteed. The caching mode of 868 * existing CPU-mappings will be updated transparently to 869 * user-space clients. 870 */ 871 __u16 cpu_caching; 872 /** @pad: MBZ */ 873 __u16 pad[3]; 874 875 /** @reserved: Reserved */ 876 __u64 reserved[2]; 877 }; 878 879 /** 880 * struct drm_xe_gem_mmap_offset - Input of &DRM_IOCTL_XE_GEM_MMAP_OFFSET 881 * 882 * The @flags can be: 883 * - %DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER - For user to query special offset 884 * for use in mmap ioctl. Writing to the returned mmap address will generate a 885 * PCI memory barrier with low overhead (avoiding IOCTL call as well as writing 886 * to VRAM which would also add overhead), acting like an MI_MEM_FENCE 887 * instruction. 888 * 889 * Note: The mmap size can be at most 4K, due to HW limitations. As a result 890 * this interface is only supported on CPU architectures that support 4K page 891 * size. The mmap_offset ioctl will detect this and gracefully return an 892 * error, where userspace is expected to have a different fallback method for 893 * triggering a barrier. 894 * 895 * Roughly the usage would be as follows: 896 * 897 * .. code-block:: C 898 * 899 * struct drm_xe_gem_mmap_offset mmo = { 900 * .handle = 0, // must be set to 0 901 * .flags = DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER, 902 * }; 903 * 904 * err = ioctl(fd, DRM_IOCTL_XE_GEM_MMAP_OFFSET, &mmo); 905 * map = mmap(NULL, size, PROT_WRITE, MAP_SHARED, fd, mmo.offset); 906 * map[i] = 0xdeadbeaf; // issue barrier 907 */ 908 struct drm_xe_gem_mmap_offset { 909 /** @extensions: Pointer to the first extension struct, if any */ 910 __u64 extensions; 911 912 /** @handle: Handle for the object being mapped. */ 913 __u32 handle; 914 915 #define DRM_XE_MMAP_OFFSET_FLAG_PCI_BARRIER (1 << 0) 916 /** @flags: Flags */ 917 __u32 flags; 918 919 /** @offset: The fake offset to use for subsequent mmap call */ 920 __u64 offset; 921 922 /** @reserved: Reserved */ 923 __u64 reserved[2]; 924 }; 925 926 /** 927 * struct drm_xe_vm_create - Input of &DRM_IOCTL_XE_VM_CREATE 928 * 929 * The @flags can be: 930 * - %DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE - Map the whole virtual address 931 * space of the VM to scratch page. A vm_bind would overwrite the scratch 932 * page mapping. This flag is mutually exclusive with the 933 * %DRM_XE_VM_CREATE_FLAG_FAULT_MODE flag, with an exception of on x2 and 934 * xe3 platform. 935 * - %DRM_XE_VM_CREATE_FLAG_LR_MODE - An LR, or Long Running VM accepts 936 * exec submissions to its exec_queues that don't have an upper time 937 * limit on the job execution time. But exec submissions to these 938 * don't allow any of the sync types DRM_XE_SYNC_TYPE_SYNCOBJ, 939 * DRM_XE_SYNC_TYPE_TIMELINE_SYNCOBJ, used as out-syncobjs, that is, 940 * together with sync flag DRM_XE_SYNC_FLAG_SIGNAL. 941 * LR VMs can be created in recoverable page-fault mode using 942 * DRM_XE_VM_CREATE_FLAG_FAULT_MODE, if the device supports it. 943 * If that flag is omitted, the UMD can not rely on the slightly 944 * different per-VM overcommit semantics that are enabled by 945 * DRM_XE_VM_CREATE_FLAG_FAULT_MODE (see below), but KMD may 946 * still enable recoverable pagefaults if supported by the device. 947 * - %DRM_XE_VM_CREATE_FLAG_FAULT_MODE - Requires also 948 * DRM_XE_VM_CREATE_FLAG_LR_MODE. It allows memory to be allocated on 949 * demand when accessed, and also allows per-VM overcommit of memory. 950 * The xe driver internally uses recoverable pagefaults to implement 951 * this. 952 */ 953 struct drm_xe_vm_create { 954 /** @extensions: Pointer to the first extension struct, if any */ 955 __u64 extensions; 956 957 #define DRM_XE_VM_CREATE_FLAG_SCRATCH_PAGE (1 << 0) 958 #define DRM_XE_VM_CREATE_FLAG_LR_MODE (1 << 1) 959 #define DRM_XE_VM_CREATE_FLAG_FAULT_MODE (1 << 2) 960 /** @flags: Flags */ 961 __u32 flags; 962 963 /** @vm_id: Returned VM ID */ 964 __u32 vm_id; 965 966 /** @reserved: Reserved */ 967 __u64 reserved[2]; 968 }; 969 970 /** 971 * struct drm_xe_vm_destroy - Input of &DRM_IOCTL_XE_VM_DESTROY 972 */ 973 struct drm_xe_vm_destroy { 974 /** @vm_id: VM ID */ 975 __u32 vm_id; 976 977 /** @pad: MBZ */ 978 __u32 pad; 979 980 /** @reserved: Reserved */ 981 __u64 reserved[2]; 982 }; 983 984 /** 985 * struct drm_xe_vm_bind_op - run bind operations 986 * 987 * The @op can be: 988 * - %DRM_XE_VM_BIND_OP_MAP 989 * - %DRM_XE_VM_BIND_OP_UNMAP 990 * - %DRM_XE_VM_BIND_OP_MAP_USERPTR 991 * - %DRM_XE_VM_BIND_OP_UNMAP_ALL 992 * - %DRM_XE_VM_BIND_OP_PREFETCH 993 * 994 * and the @flags can be: 995 * - %DRM_XE_VM_BIND_FLAG_READONLY - Setup the page tables as read-only 996 * to ensure write protection 997 * - %DRM_XE_VM_BIND_FLAG_IMMEDIATE - On a faulting VM, do the 998 * MAP operation immediately rather than deferring the MAP to the page 999 * fault handler. This is implied on a non-faulting VM as there is no 1000 * fault handler to defer to. 1001 * - %DRM_XE_VM_BIND_FLAG_NULL - When the NULL flag is set, the page 1002 * tables are setup with a special bit which indicates writes are 1003 * dropped and all reads return zero. In the future, the NULL flags 1004 * will only be valid for DRM_XE_VM_BIND_OP_MAP operations, the BO 1005 * handle MBZ, and the BO offset MBZ. This flag is intended to 1006 * implement VK sparse bindings. 1007 * - %DRM_XE_VM_BIND_FLAG_CHECK_PXP - If the object is encrypted via PXP, 1008 * reject the binding if the encryption key is no longer valid. This 1009 * flag has no effect on BOs that are not marked as using PXP. 1010 * - %DRM_XE_VM_BIND_FLAG_CPU_ADDR_MIRROR - When the CPU address mirror flag is 1011 * set, no mappings are created rather the range is reserved for CPU address 1012 * mirroring which will be populated on GPU page faults or prefetches. Only 1013 * valid on VMs with DRM_XE_VM_CREATE_FLAG_FAULT_MODE set. The CPU address 1014 * mirror flag are only valid for DRM_XE_VM_BIND_OP_MAP operations, the BO 1015 * handle MBZ, and the BO offset MBZ. 1016 * - %DRM_XE_VM_BIND_FLAG_MADVISE_AUTORESET - Can be used in combination with 1017 * %DRM_XE_VM_BIND_FLAG_CPU_ADDR_MIRROR to reset madvises when the underlying 1018 * CPU address space range is unmapped (typically with munmap(2) or brk(2)). 1019 * The madvise values set with &DRM_IOCTL_XE_MADVISE are reset to the values 1020 * that were present immediately after the &DRM_IOCTL_XE_VM_BIND. 1021 * The reset GPU virtual address range is the intersection of the range bound 1022 * using &DRM_IOCTL_XE_VM_BIND and the virtual CPU address space range 1023 * unmapped. 1024 * This functionality is present to mimic the behaviour of CPU address space 1025 * madvises set using madvise(2), which are typically reset on unmap. 1026 * Note: free(3) may or may not call munmap(2) and/or brk(2), and may thus 1027 * not invoke autoreset. Neither will stack variables going out of scope. 1028 * Therefore it's recommended to always explicitly reset the madvises when 1029 * freeing the memory backing a region used in a &DRM_IOCTL_XE_MADVISE call. 1030 * 1031 * The @prefetch_mem_region_instance for %DRM_XE_VM_BIND_OP_PREFETCH can also be: 1032 * - %DRM_XE_CONSULT_MEM_ADVISE_PREF_LOC, which ensures prefetching occurs in 1033 * the memory region advised by madvise. 1034 */ 1035 struct drm_xe_vm_bind_op { 1036 /** @extensions: Pointer to the first extension struct, if any */ 1037 __u64 extensions; 1038 1039 /** 1040 * @obj: GEM object to operate on, MBZ for MAP_USERPTR, MBZ for UNMAP 1041 */ 1042 __u32 obj; 1043 1044 /** 1045 * @pat_index: The platform defined @pat_index to use for this mapping. 1046 * The index basically maps to some predefined memory attributes, 1047 * including things like caching, coherency, compression etc. The exact 1048 * meaning of the pat_index is platform specific and defined in the 1049 * Bspec and PRMs. When the KMD sets up the binding the index here is 1050 * encoded into the ppGTT PTE. 1051 * 1052 * For coherency the @pat_index needs to be at least 1way coherent when 1053 * drm_xe_gem_create.cpu_caching is DRM_XE_GEM_CPU_CACHING_WB. The KMD 1054 * will extract the coherency mode from the @pat_index and reject if 1055 * there is a mismatch (see note below for pre-MTL platforms). 1056 * 1057 * Note: On pre-MTL platforms there is only a caching mode and no 1058 * explicit coherency mode, but on such hardware there is always a 1059 * shared-LLC (or is dgpu) so all GT memory accesses are coherent with 1060 * CPU caches even with the caching mode set as uncached. It's only the 1061 * display engine that is incoherent (on dgpu it must be in VRAM which 1062 * is always mapped as WC on the CPU). However to keep the uapi somewhat 1063 * consistent with newer platforms the KMD groups the different cache 1064 * levels into the following coherency buckets on all pre-MTL platforms: 1065 * 1066 * ppGTT UC -> COH_NONE 1067 * ppGTT WC -> COH_NONE 1068 * ppGTT WT -> COH_NONE 1069 * ppGTT WB -> COH_AT_LEAST_1WAY 1070 * 1071 * In practice UC/WC/WT should only ever used for scanout surfaces on 1072 * such platforms (or perhaps in general for dma-buf if shared with 1073 * another device) since it is only the display engine that is actually 1074 * incoherent. Everything else should typically use WB given that we 1075 * have a shared-LLC. On MTL+ this completely changes and the HW 1076 * defines the coherency mode as part of the @pat_index, where 1077 * incoherent GT access is possible. 1078 * 1079 * Note: For userptr and externally imported dma-buf the kernel expects 1080 * either 1WAY or 2WAY for the @pat_index. 1081 * 1082 * For DRM_XE_VM_BIND_FLAG_NULL bindings there are no KMD restrictions 1083 * on the @pat_index. For such mappings there is no actual memory being 1084 * mapped (the address in the PTE is invalid), so the various PAT memory 1085 * attributes likely do not apply. Simply leaving as zero is one 1086 * option (still a valid pat_index). Same applies to 1087 * DRM_XE_VM_BIND_FLAG_CPU_ADDR_MIRROR bindings as for such mapping 1088 * there is no actual memory being mapped. 1089 */ 1090 __u16 pat_index; 1091 1092 /** @pad: MBZ */ 1093 __u16 pad; 1094 1095 union { 1096 /** 1097 * @obj_offset: Offset into the object, MBZ for CLEAR_RANGE, 1098 * ignored for unbind 1099 */ 1100 __u64 obj_offset; 1101 1102 /** @userptr: user pointer to bind on */ 1103 __u64 userptr; 1104 1105 /** 1106 * @cpu_addr_mirror_offset: Offset from GPU @addr to create 1107 * CPU address mirror mappings. MBZ with current level of 1108 * support (e.g. 1 to 1 mapping between GPU and CPU mappings 1109 * only supported). 1110 */ 1111 __s64 cpu_addr_mirror_offset; 1112 }; 1113 1114 /** 1115 * @range: Number of bytes from the object to bind to addr, MBZ for UNMAP_ALL 1116 */ 1117 __u64 range; 1118 1119 /** @addr: Address to operate on, MBZ for UNMAP_ALL */ 1120 __u64 addr; 1121 1122 #define DRM_XE_VM_BIND_OP_MAP 0x0 1123 #define DRM_XE_VM_BIND_OP_UNMAP 0x1 1124 #define DRM_XE_VM_BIND_OP_MAP_USERPTR 0x2 1125 #define DRM_XE_VM_BIND_OP_UNMAP_ALL 0x3 1126 #define DRM_XE_VM_BIND_OP_PREFETCH 0x4 1127 /** @op: Bind operation to perform */ 1128 __u32 op; 1129 1130 #define DRM_XE_VM_BIND_FLAG_READONLY (1 << 0) 1131 #define DRM_XE_VM_BIND_FLAG_IMMEDIATE (1 << 1) 1132 #define DRM_XE_VM_BIND_FLAG_NULL (1 << 2) 1133 #define DRM_XE_VM_BIND_FLAG_DUMPABLE (1 << 3) 1134 #define DRM_XE_VM_BIND_FLAG_CHECK_PXP (1 << 4) 1135 #define DRM_XE_VM_BIND_FLAG_CPU_ADDR_MIRROR (1 << 5) 1136 #define DRM_XE_VM_BIND_FLAG_MADVISE_AUTORESET (1 << 6) 1137 /** @flags: Bind flags */ 1138 __u32 flags; 1139 1140 #define DRM_XE_CONSULT_MEM_ADVISE_PREF_LOC -1 1141 /** 1142 * @prefetch_mem_region_instance: Memory region to prefetch VMA to. 1143 * It is a region instance, not a mask. 1144 * To be used only with %DRM_XE_VM_BIND_OP_PREFETCH operation. 1145 */ 1146 __u32 prefetch_mem_region_instance; 1147 1148 /** @pad2: MBZ */ 1149 __u32 pad2; 1150 1151 /** @reserved: Reserved */ 1152 __u64 reserved[3]; 1153 }; 1154 1155 /** 1156 * struct drm_xe_vm_bind - Input of &DRM_IOCTL_XE_VM_BIND 1157 * 1158 * Below is an example of a minimal use of @drm_xe_vm_bind to 1159 * asynchronously bind the buffer `data` at address `BIND_ADDRESS` to 1160 * illustrate `userptr`. It can be synchronized by using the example 1161 * provided for @drm_xe_sync. 1162 * 1163 * .. code-block:: C 1164 * 1165 * data = aligned_alloc(ALIGNMENT, BO_SIZE); 1166 * struct drm_xe_vm_bind bind = { 1167 * .vm_id = vm, 1168 * .num_binds = 1, 1169 * .bind.obj = 0, 1170 * .bind.obj_offset = to_user_pointer(data), 1171 * .bind.range = BO_SIZE, 1172 * .bind.addr = BIND_ADDRESS, 1173 * .bind.op = DRM_XE_VM_BIND_OP_MAP_USERPTR, 1174 * .bind.flags = 0, 1175 * .num_syncs = 1, 1176 * .syncs = &sync, 1177 * .exec_queue_id = 0, 1178 * }; 1179 * ioctl(fd, DRM_IOCTL_XE_VM_BIND, &bind); 1180 * 1181 */ 1182 struct drm_xe_vm_bind { 1183 /** @extensions: Pointer to the first extension struct, if any */ 1184 __u64 extensions; 1185 1186 /** @vm_id: The ID of the VM to bind to */ 1187 __u32 vm_id; 1188 1189 /** 1190 * @exec_queue_id: exec_queue_id, must be of class DRM_XE_ENGINE_CLASS_VM_BIND 1191 * and exec queue must have same vm_id. If zero, the default VM bind engine 1192 * is used. 1193 */ 1194 __u32 exec_queue_id; 1195 1196 /** @pad: MBZ */ 1197 __u32 pad; 1198 1199 /** @num_binds: number of binds in this IOCTL */ 1200 __u32 num_binds; 1201 1202 union { 1203 /** @bind: used if num_binds == 1 */ 1204 struct drm_xe_vm_bind_op bind; 1205 1206 /** 1207 * @vector_of_binds: userptr to array of struct 1208 * drm_xe_vm_bind_op if num_binds > 1 1209 */ 1210 __u64 vector_of_binds; 1211 }; 1212 1213 /** @pad2: MBZ */ 1214 __u32 pad2; 1215 1216 /** @num_syncs: amount of syncs to wait on */ 1217 __u32 num_syncs; 1218 1219 /** @syncs: pointer to struct drm_xe_sync array */ 1220 __u64 syncs; 1221 1222 /** @reserved: Reserved */ 1223 __u64 reserved[2]; 1224 }; 1225 1226 /** 1227 * struct drm_xe_exec_queue_create - Input of &DRM_IOCTL_XE_EXEC_QUEUE_CREATE 1228 * 1229 * This ioctl supports setting the following properties via the 1230 * %DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY extension, which uses the 1231 * generic @drm_xe_ext_set_property struct: 1232 * 1233 * - %DRM_XE_EXEC_QUEUE_SET_PROPERTY_PRIORITY - set the queue priority. 1234 * CAP_SYS_NICE is required to set a value above normal. 1235 * - %DRM_XE_EXEC_QUEUE_SET_PROPERTY_TIMESLICE - set the queue timeslice 1236 * duration in microseconds. 1237 * - %DRM_XE_EXEC_QUEUE_SET_PROPERTY_PXP_TYPE - set the type of PXP session 1238 * this queue will be used with. Valid values are listed in enum 1239 * drm_xe_pxp_session_type. %DRM_XE_PXP_TYPE_NONE is the default behavior, so 1240 * there is no need to explicitly set that. When a queue of type 1241 * %DRM_XE_PXP_TYPE_HWDRM is created, the PXP default HWDRM session 1242 * (%XE_PXP_HWDRM_DEFAULT_SESSION) will be started, if isn't already running. 1243 * The user is expected to query the PXP status via the query ioctl (see 1244 * %DRM_XE_DEVICE_QUERY_PXP_STATUS) and to wait for PXP to be ready before 1245 * attempting to create a queue with this property. When a queue is created 1246 * before PXP is ready, the ioctl will return -EBUSY if init is still in 1247 * progress or -EIO if init failed. 1248 * Given that going into a power-saving state kills PXP HWDRM sessions, 1249 * runtime PM will be blocked while queues of this type are alive. 1250 * All PXP queues will be killed if a PXP invalidation event occurs. 1251 * 1252 * The example below shows how to use @drm_xe_exec_queue_create to create 1253 * a simple exec_queue (no parallel submission) of class 1254 * &DRM_XE_ENGINE_CLASS_RENDER. 1255 * 1256 * .. code-block:: C 1257 * 1258 * struct drm_xe_engine_class_instance instance = { 1259 * .engine_class = DRM_XE_ENGINE_CLASS_RENDER, 1260 * }; 1261 * struct drm_xe_exec_queue_create exec_queue_create = { 1262 * .extensions = 0, 1263 * .vm_id = vm, 1264 * .num_bb_per_exec = 1, 1265 * .num_eng_per_bb = 1, 1266 * .instances = to_user_pointer(&instance), 1267 * }; 1268 * ioctl(fd, DRM_IOCTL_XE_EXEC_QUEUE_CREATE, &exec_queue_create); 1269 * 1270 * Allow users to provide a hint to kernel for cases demanding low latency 1271 * profile. Please note it will have impact on power consumption. User can 1272 * indicate low latency hint with flag while creating exec queue as 1273 * mentioned below, 1274 * 1275 * struct drm_xe_exec_queue_create exec_queue_create = { 1276 * .flags = DRM_XE_EXEC_QUEUE_LOW_LATENCY_HINT, 1277 * .extensions = 0, 1278 * .vm_id = vm, 1279 * .num_bb_per_exec = 1, 1280 * .num_eng_per_bb = 1, 1281 * .instances = to_user_pointer(&instance), 1282 * }; 1283 * ioctl(fd, DRM_IOCTL_XE_EXEC_QUEUE_CREATE, &exec_queue_create); 1284 * 1285 */ 1286 struct drm_xe_exec_queue_create { 1287 #define DRM_XE_EXEC_QUEUE_EXTENSION_SET_PROPERTY 0 1288 #define DRM_XE_EXEC_QUEUE_SET_PROPERTY_PRIORITY 0 1289 #define DRM_XE_EXEC_QUEUE_SET_PROPERTY_TIMESLICE 1 1290 #define DRM_XE_EXEC_QUEUE_SET_PROPERTY_PXP_TYPE 2 1291 /** @extensions: Pointer to the first extension struct, if any */ 1292 __u64 extensions; 1293 1294 /** @width: submission width (number BB per exec) for this exec queue */ 1295 __u16 width; 1296 1297 /** @num_placements: number of valid placements for this exec queue */ 1298 __u16 num_placements; 1299 1300 /** @vm_id: VM to use for this exec queue */ 1301 __u32 vm_id; 1302 1303 #define DRM_XE_EXEC_QUEUE_LOW_LATENCY_HINT (1 << 0) 1304 /** @flags: flags to use for this exec queue */ 1305 __u32 flags; 1306 1307 /** @exec_queue_id: Returned exec queue ID */ 1308 __u32 exec_queue_id; 1309 1310 /** 1311 * @instances: user pointer to a 2-d array of struct 1312 * drm_xe_engine_class_instance 1313 * 1314 * length = width (i) * num_placements (j) 1315 * index = j + i * width 1316 */ 1317 __u64 instances; 1318 1319 /** @reserved: Reserved */ 1320 __u64 reserved[2]; 1321 }; 1322 1323 /** 1324 * struct drm_xe_exec_queue_destroy - Input of &DRM_IOCTL_XE_EXEC_QUEUE_DESTROY 1325 */ 1326 struct drm_xe_exec_queue_destroy { 1327 /** @exec_queue_id: Exec queue ID */ 1328 __u32 exec_queue_id; 1329 1330 /** @pad: MBZ */ 1331 __u32 pad; 1332 1333 /** @reserved: Reserved */ 1334 __u64 reserved[2]; 1335 }; 1336 1337 /** 1338 * struct drm_xe_exec_queue_get_property - Input of &DRM_IOCTL_XE_EXEC_QUEUE_GET_PROPERTY 1339 * 1340 * The @property can be: 1341 * - %DRM_XE_EXEC_QUEUE_GET_PROPERTY_BAN 1342 */ 1343 struct drm_xe_exec_queue_get_property { 1344 /** @extensions: Pointer to the first extension struct, if any */ 1345 __u64 extensions; 1346 1347 /** @exec_queue_id: Exec queue ID */ 1348 __u32 exec_queue_id; 1349 1350 #define DRM_XE_EXEC_QUEUE_GET_PROPERTY_BAN 0 1351 /** @property: property to get */ 1352 __u32 property; 1353 1354 /** @value: property value */ 1355 __u64 value; 1356 1357 /** @reserved: Reserved */ 1358 __u64 reserved[2]; 1359 }; 1360 1361 /** 1362 * struct drm_xe_sync - sync object 1363 * 1364 * The @type can be: 1365 * - %DRM_XE_SYNC_TYPE_SYNCOBJ 1366 * - %DRM_XE_SYNC_TYPE_TIMELINE_SYNCOBJ 1367 * - %DRM_XE_SYNC_TYPE_USER_FENCE 1368 * 1369 * and the @flags can be: 1370 * - %DRM_XE_SYNC_FLAG_SIGNAL 1371 * 1372 * A minimal use of @drm_xe_sync looks like this: 1373 * 1374 * .. code-block:: C 1375 * 1376 * struct drm_xe_sync sync = { 1377 * .flags = DRM_XE_SYNC_FLAG_SIGNAL, 1378 * .type = DRM_XE_SYNC_TYPE_SYNCOBJ, 1379 * }; 1380 * struct drm_syncobj_create syncobj_create = { 0 }; 1381 * ioctl(fd, DRM_IOCTL_SYNCOBJ_CREATE, &syncobj_create); 1382 * sync.handle = syncobj_create.handle; 1383 * ... 1384 * use of &sync in drm_xe_exec or drm_xe_vm_bind 1385 * ... 1386 * struct drm_syncobj_wait wait = { 1387 * .handles = &sync.handle, 1388 * .timeout_nsec = INT64_MAX, 1389 * .count_handles = 1, 1390 * .flags = 0, 1391 * .first_signaled = 0, 1392 * .pad = 0, 1393 * }; 1394 * ioctl(fd, DRM_IOCTL_SYNCOBJ_WAIT, &wait); 1395 */ 1396 struct drm_xe_sync { 1397 /** @extensions: Pointer to the first extension struct, if any */ 1398 __u64 extensions; 1399 1400 #define DRM_XE_SYNC_TYPE_SYNCOBJ 0x0 1401 #define DRM_XE_SYNC_TYPE_TIMELINE_SYNCOBJ 0x1 1402 #define DRM_XE_SYNC_TYPE_USER_FENCE 0x2 1403 /** @type: Type of the this sync object */ 1404 __u32 type; 1405 1406 #define DRM_XE_SYNC_FLAG_SIGNAL (1 << 0) 1407 /** @flags: Sync Flags */ 1408 __u32 flags; 1409 1410 union { 1411 /** @handle: Handle for the object */ 1412 __u32 handle; 1413 1414 /** 1415 * @addr: Address of user fence. When sync is passed in via exec 1416 * IOCTL this is a GPU address in the VM. When sync passed in via 1417 * VM bind IOCTL this is a user pointer. In either case, it is 1418 * the users responsibility that this address is present and 1419 * mapped when the user fence is signalled. Must be qword 1420 * aligned. 1421 */ 1422 __u64 addr; 1423 }; 1424 1425 /** 1426 * @timeline_value: Input for the timeline sync object. Needs to be 1427 * different than 0 when used with %DRM_XE_SYNC_TYPE_TIMELINE_SYNCOBJ. 1428 */ 1429 __u64 timeline_value; 1430 1431 /** @reserved: Reserved */ 1432 __u64 reserved[2]; 1433 }; 1434 1435 /** 1436 * struct drm_xe_exec - Input of &DRM_IOCTL_XE_EXEC 1437 * 1438 * This is an example to use @drm_xe_exec for execution of the object 1439 * at BIND_ADDRESS (see example in @drm_xe_vm_bind) by an exec_queue 1440 * (see example in @drm_xe_exec_queue_create). It can be synchronized 1441 * by using the example provided for @drm_xe_sync. 1442 * 1443 * .. code-block:: C 1444 * 1445 * struct drm_xe_exec exec = { 1446 * .exec_queue_id = exec_queue, 1447 * .syncs = &sync, 1448 * .num_syncs = 1, 1449 * .address = BIND_ADDRESS, 1450 * .num_batch_buffer = 1, 1451 * }; 1452 * ioctl(fd, DRM_IOCTL_XE_EXEC, &exec); 1453 * 1454 */ 1455 struct drm_xe_exec { 1456 /** @extensions: Pointer to the first extension struct, if any */ 1457 __u64 extensions; 1458 1459 /** @exec_queue_id: Exec queue ID for the batch buffer */ 1460 __u32 exec_queue_id; 1461 1462 /** @num_syncs: Amount of struct drm_xe_sync in array. */ 1463 __u32 num_syncs; 1464 1465 /** @syncs: Pointer to struct drm_xe_sync array. */ 1466 __u64 syncs; 1467 1468 /** 1469 * @address: address of batch buffer if num_batch_buffer == 1 or an 1470 * array of batch buffer addresses 1471 */ 1472 __u64 address; 1473 1474 /** 1475 * @num_batch_buffer: number of batch buffer in this exec, must match 1476 * the width of the engine 1477 */ 1478 __u16 num_batch_buffer; 1479 1480 /** @pad: MBZ */ 1481 __u16 pad[3]; 1482 1483 /** @reserved: Reserved */ 1484 __u64 reserved[2]; 1485 }; 1486 1487 /** 1488 * struct drm_xe_wait_user_fence - Input of &DRM_IOCTL_XE_WAIT_USER_FENCE 1489 * 1490 * Wait on user fence, XE will wake-up on every HW engine interrupt in the 1491 * instances list and check if user fence is complete:: 1492 * 1493 * (*addr & MASK) OP (VALUE & MASK) 1494 * 1495 * Returns to user on user fence completion or timeout. 1496 * 1497 * The @op can be: 1498 * - %DRM_XE_UFENCE_WAIT_OP_EQ 1499 * - %DRM_XE_UFENCE_WAIT_OP_NEQ 1500 * - %DRM_XE_UFENCE_WAIT_OP_GT 1501 * - %DRM_XE_UFENCE_WAIT_OP_GTE 1502 * - %DRM_XE_UFENCE_WAIT_OP_LT 1503 * - %DRM_XE_UFENCE_WAIT_OP_LTE 1504 * 1505 * and the @flags can be: 1506 * - %DRM_XE_UFENCE_WAIT_FLAG_ABSTIME 1507 * - %DRM_XE_UFENCE_WAIT_FLAG_SOFT_OP 1508 * 1509 * The @mask values can be for example: 1510 * - 0xffu for u8 1511 * - 0xffffu for u16 1512 * - 0xffffffffu for u32 1513 * - 0xffffffffffffffffu for u64 1514 */ 1515 struct drm_xe_wait_user_fence { 1516 /** @extensions: Pointer to the first extension struct, if any */ 1517 __u64 extensions; 1518 1519 /** 1520 * @addr: user pointer address to wait on, must qword aligned 1521 */ 1522 __u64 addr; 1523 1524 #define DRM_XE_UFENCE_WAIT_OP_EQ 0x0 1525 #define DRM_XE_UFENCE_WAIT_OP_NEQ 0x1 1526 #define DRM_XE_UFENCE_WAIT_OP_GT 0x2 1527 #define DRM_XE_UFENCE_WAIT_OP_GTE 0x3 1528 #define DRM_XE_UFENCE_WAIT_OP_LT 0x4 1529 #define DRM_XE_UFENCE_WAIT_OP_LTE 0x5 1530 /** @op: wait operation (type of comparison) */ 1531 __u16 op; 1532 1533 #define DRM_XE_UFENCE_WAIT_FLAG_ABSTIME (1 << 0) 1534 /** @flags: wait flags */ 1535 __u16 flags; 1536 1537 /** @pad: MBZ */ 1538 __u32 pad; 1539 1540 /** @value: compare value */ 1541 __u64 value; 1542 1543 /** @mask: comparison mask */ 1544 __u64 mask; 1545 1546 /** 1547 * @timeout: how long to wait before bailing, value in nanoseconds. 1548 * Without DRM_XE_UFENCE_WAIT_FLAG_ABSTIME flag set (relative timeout) 1549 * it contains timeout expressed in nanoseconds to wait (fence will 1550 * expire at now() + timeout). 1551 * When DRM_XE_UFENCE_WAIT_FLAG_ABSTIME flat is set (absolute timeout) wait 1552 * will end at timeout (uses system MONOTONIC_CLOCK). 1553 * Passing negative timeout leads to neverending wait. 1554 * 1555 * On relative timeout this value is updated with timeout left 1556 * (for restarting the call in case of signal delivery). 1557 * On absolute timeout this value stays intact (restarted call still 1558 * expire at the same point of time). 1559 */ 1560 __s64 timeout; 1561 1562 /** @exec_queue_id: exec_queue_id returned from xe_exec_queue_create_ioctl */ 1563 __u32 exec_queue_id; 1564 1565 /** @pad2: MBZ */ 1566 __u32 pad2; 1567 1568 /** @reserved: Reserved */ 1569 __u64 reserved[2]; 1570 }; 1571 1572 /** 1573 * enum drm_xe_observation_type - Observation stream types 1574 */ 1575 enum drm_xe_observation_type { 1576 /** @DRM_XE_OBSERVATION_TYPE_OA: OA observation stream type */ 1577 DRM_XE_OBSERVATION_TYPE_OA, 1578 /** @DRM_XE_OBSERVATION_TYPE_EU_STALL: EU stall sampling observation stream type */ 1579 DRM_XE_OBSERVATION_TYPE_EU_STALL, 1580 }; 1581 1582 /** 1583 * enum drm_xe_observation_op - Observation stream ops 1584 */ 1585 enum drm_xe_observation_op { 1586 /** @DRM_XE_OBSERVATION_OP_STREAM_OPEN: Open an observation stream */ 1587 DRM_XE_OBSERVATION_OP_STREAM_OPEN, 1588 1589 /** @DRM_XE_OBSERVATION_OP_ADD_CONFIG: Add observation stream config */ 1590 DRM_XE_OBSERVATION_OP_ADD_CONFIG, 1591 1592 /** @DRM_XE_OBSERVATION_OP_REMOVE_CONFIG: Remove observation stream config */ 1593 DRM_XE_OBSERVATION_OP_REMOVE_CONFIG, 1594 }; 1595 1596 /** 1597 * struct drm_xe_observation_param - Input of &DRM_XE_OBSERVATION 1598 * 1599 * The observation layer enables multiplexing observation streams of 1600 * multiple types. The actual params for a particular stream operation are 1601 * supplied via the @param pointer (use __copy_from_user to get these 1602 * params). 1603 */ 1604 struct drm_xe_observation_param { 1605 /** @extensions: Pointer to the first extension struct, if any */ 1606 __u64 extensions; 1607 /** @observation_type: observation stream type, of enum @drm_xe_observation_type */ 1608 __u64 observation_type; 1609 /** @observation_op: observation stream op, of enum @drm_xe_observation_op */ 1610 __u64 observation_op; 1611 /** @param: Pointer to actual stream params */ 1612 __u64 param; 1613 }; 1614 1615 /** 1616 * enum drm_xe_observation_ioctls - Observation stream fd ioctl's 1617 * 1618 * Information exchanged between userspace and kernel for observation fd 1619 * ioctl's is stream type specific 1620 */ 1621 enum drm_xe_observation_ioctls { 1622 /** @DRM_XE_OBSERVATION_IOCTL_ENABLE: Enable data capture for an observation stream */ 1623 DRM_XE_OBSERVATION_IOCTL_ENABLE = _IO('i', 0x0), 1624 1625 /** @DRM_XE_OBSERVATION_IOCTL_DISABLE: Disable data capture for a observation stream */ 1626 DRM_XE_OBSERVATION_IOCTL_DISABLE = _IO('i', 0x1), 1627 1628 /** @DRM_XE_OBSERVATION_IOCTL_CONFIG: Change observation stream configuration */ 1629 DRM_XE_OBSERVATION_IOCTL_CONFIG = _IO('i', 0x2), 1630 1631 /** @DRM_XE_OBSERVATION_IOCTL_STATUS: Return observation stream status */ 1632 DRM_XE_OBSERVATION_IOCTL_STATUS = _IO('i', 0x3), 1633 1634 /** @DRM_XE_OBSERVATION_IOCTL_INFO: Return observation stream info */ 1635 DRM_XE_OBSERVATION_IOCTL_INFO = _IO('i', 0x4), 1636 }; 1637 1638 /** 1639 * enum drm_xe_oa_unit_type - OA unit types 1640 */ 1641 enum drm_xe_oa_unit_type { 1642 /** 1643 * @DRM_XE_OA_UNIT_TYPE_OAG: OAG OA unit. OAR/OAC are considered 1644 * sub-types of OAG. For OAR/OAC, use OAG. 1645 */ 1646 DRM_XE_OA_UNIT_TYPE_OAG, 1647 1648 /** @DRM_XE_OA_UNIT_TYPE_OAM: OAM OA unit */ 1649 DRM_XE_OA_UNIT_TYPE_OAM, 1650 1651 /** @DRM_XE_OA_UNIT_TYPE_OAM_SAG: OAM_SAG OA unit */ 1652 DRM_XE_OA_UNIT_TYPE_OAM_SAG, 1653 }; 1654 1655 /** 1656 * struct drm_xe_oa_unit - describe OA unit 1657 */ 1658 struct drm_xe_oa_unit { 1659 /** @extensions: Pointer to the first extension struct, if any */ 1660 __u64 extensions; 1661 1662 /** @oa_unit_id: OA unit ID */ 1663 __u32 oa_unit_id; 1664 1665 /** @oa_unit_type: OA unit type of @drm_xe_oa_unit_type */ 1666 __u32 oa_unit_type; 1667 1668 /** @capabilities: OA capabilities bit-mask */ 1669 __u64 capabilities; 1670 #define DRM_XE_OA_CAPS_BASE (1 << 0) 1671 #define DRM_XE_OA_CAPS_SYNCS (1 << 1) 1672 #define DRM_XE_OA_CAPS_OA_BUFFER_SIZE (1 << 2) 1673 #define DRM_XE_OA_CAPS_WAIT_NUM_REPORTS (1 << 3) 1674 #define DRM_XE_OA_CAPS_OAM (1 << 4) 1675 1676 /** @oa_timestamp_freq: OA timestamp freq */ 1677 __u64 oa_timestamp_freq; 1678 1679 /** @reserved: MBZ */ 1680 __u64 reserved[4]; 1681 1682 /** @num_engines: number of engines in @eci array */ 1683 __u64 num_engines; 1684 1685 /** @eci: engines attached to this OA unit */ 1686 struct drm_xe_engine_class_instance eci[]; 1687 }; 1688 1689 /** 1690 * struct drm_xe_query_oa_units - describe OA units 1691 * 1692 * If a query is made with a struct drm_xe_device_query where .query 1693 * is equal to DRM_XE_DEVICE_QUERY_OA_UNITS, then the reply uses struct 1694 * drm_xe_query_oa_units in .data. 1695 * 1696 * OA unit properties for all OA units can be accessed using a code block 1697 * such as the one below: 1698 * 1699 * .. code-block:: C 1700 * 1701 * struct drm_xe_query_oa_units *qoa; 1702 * struct drm_xe_oa_unit *oau; 1703 * u8 *poau; 1704 * 1705 * // malloc qoa and issue DRM_XE_DEVICE_QUERY_OA_UNITS. Then: 1706 * poau = (u8 *)&qoa->oa_units[0]; 1707 * for (int i = 0; i < qoa->num_oa_units; i++) { 1708 * oau = (struct drm_xe_oa_unit *)poau; 1709 * // Access 'struct drm_xe_oa_unit' fields here 1710 * poau += sizeof(*oau) + oau->num_engines * sizeof(oau->eci[0]); 1711 * } 1712 */ 1713 struct drm_xe_query_oa_units { 1714 /** @extensions: Pointer to the first extension struct, if any */ 1715 __u64 extensions; 1716 /** @num_oa_units: number of OA units returned in oau[] */ 1717 __u32 num_oa_units; 1718 /** @pad: MBZ */ 1719 __u32 pad; 1720 /** 1721 * @oa_units: struct @drm_xe_oa_unit array returned for this device. 1722 * Written below as a u64 array to avoid problems with nested flexible 1723 * arrays with some compilers 1724 */ 1725 __u64 oa_units[]; 1726 }; 1727 1728 /** 1729 * enum drm_xe_oa_format_type - OA format types as specified in PRM/Bspec 1730 * 52198/60942 1731 */ 1732 enum drm_xe_oa_format_type { 1733 /** @DRM_XE_OA_FMT_TYPE_OAG: OAG report format */ 1734 DRM_XE_OA_FMT_TYPE_OAG, 1735 /** @DRM_XE_OA_FMT_TYPE_OAR: OAR report format */ 1736 DRM_XE_OA_FMT_TYPE_OAR, 1737 /** @DRM_XE_OA_FMT_TYPE_OAM: OAM report format */ 1738 DRM_XE_OA_FMT_TYPE_OAM, 1739 /** @DRM_XE_OA_FMT_TYPE_OAC: OAC report format */ 1740 DRM_XE_OA_FMT_TYPE_OAC, 1741 /** @DRM_XE_OA_FMT_TYPE_OAM_MPEC: OAM SAMEDIA or OAM MPEC report format */ 1742 DRM_XE_OA_FMT_TYPE_OAM_MPEC, 1743 /** @DRM_XE_OA_FMT_TYPE_PEC: PEC report format */ 1744 DRM_XE_OA_FMT_TYPE_PEC, 1745 }; 1746 1747 /** 1748 * enum drm_xe_oa_property_id - OA stream property id's 1749 * 1750 * Stream params are specified as a chain of @drm_xe_ext_set_property 1751 * struct's, with @property values from enum @drm_xe_oa_property_id and 1752 * @drm_xe_user_extension base.name set to @DRM_XE_OA_EXTENSION_SET_PROPERTY. 1753 * @param field in struct @drm_xe_observation_param points to the first 1754 * @drm_xe_ext_set_property struct. 1755 * 1756 * Exactly the same mechanism is also used for stream reconfiguration using the 1757 * @DRM_XE_OBSERVATION_IOCTL_CONFIG observation stream fd ioctl, though only a 1758 * subset of properties below can be specified for stream reconfiguration. 1759 */ 1760 enum drm_xe_oa_property_id { 1761 #define DRM_XE_OA_EXTENSION_SET_PROPERTY 0 1762 /** 1763 * @DRM_XE_OA_PROPERTY_OA_UNIT_ID: ID of the OA unit on which to open 1764 * the OA stream, see @oa_unit_id in 'struct 1765 * drm_xe_query_oa_units'. Defaults to 0 if not provided. 1766 */ 1767 DRM_XE_OA_PROPERTY_OA_UNIT_ID = 1, 1768 1769 /** 1770 * @DRM_XE_OA_PROPERTY_SAMPLE_OA: A value of 1 requests inclusion of raw 1771 * OA unit reports or stream samples in a global buffer attached to an 1772 * OA unit. 1773 */ 1774 DRM_XE_OA_PROPERTY_SAMPLE_OA, 1775 1776 /** 1777 * @DRM_XE_OA_PROPERTY_OA_METRIC_SET: OA metrics defining contents of OA 1778 * reports, previously added via @DRM_XE_OBSERVATION_OP_ADD_CONFIG. 1779 */ 1780 DRM_XE_OA_PROPERTY_OA_METRIC_SET, 1781 1782 /** @DRM_XE_OA_PROPERTY_OA_FORMAT: OA counter report format */ 1783 DRM_XE_OA_PROPERTY_OA_FORMAT, 1784 /* 1785 * OA_FORMAT's are specified the same way as in PRM/Bspec 52198/60942, 1786 * in terms of the following quantities: a. enum @drm_xe_oa_format_type 1787 * b. Counter select c. Counter size and d. BC report. Also refer to the 1788 * oa_formats array in drivers/gpu/drm/xe/xe_oa.c. 1789 */ 1790 #define DRM_XE_OA_FORMAT_MASK_FMT_TYPE (0xffu << 0) 1791 #define DRM_XE_OA_FORMAT_MASK_COUNTER_SEL (0xffu << 8) 1792 #define DRM_XE_OA_FORMAT_MASK_COUNTER_SIZE (0xffu << 16) 1793 #define DRM_XE_OA_FORMAT_MASK_BC_REPORT (0xffu << 24) 1794 1795 /** 1796 * @DRM_XE_OA_PROPERTY_OA_PERIOD_EXPONENT: Requests periodic OA unit 1797 * sampling with sampling frequency proportional to 2^(period_exponent + 1) 1798 */ 1799 DRM_XE_OA_PROPERTY_OA_PERIOD_EXPONENT, 1800 1801 /** 1802 * @DRM_XE_OA_PROPERTY_OA_DISABLED: A value of 1 will open the OA 1803 * stream in a DISABLED state (see @DRM_XE_OBSERVATION_IOCTL_ENABLE). 1804 */ 1805 DRM_XE_OA_PROPERTY_OA_DISABLED, 1806 1807 /** 1808 * @DRM_XE_OA_PROPERTY_EXEC_QUEUE_ID: Open the stream for a specific 1809 * @exec_queue_id. OA queries can be executed on this exec queue. 1810 */ 1811 DRM_XE_OA_PROPERTY_EXEC_QUEUE_ID, 1812 1813 /** 1814 * @DRM_XE_OA_PROPERTY_OA_ENGINE_INSTANCE: Optional engine instance to 1815 * pass along with @DRM_XE_OA_PROPERTY_EXEC_QUEUE_ID or will default to 0. 1816 */ 1817 DRM_XE_OA_PROPERTY_OA_ENGINE_INSTANCE, 1818 1819 /** 1820 * @DRM_XE_OA_PROPERTY_NO_PREEMPT: Allow preemption and timeslicing 1821 * to be disabled for the stream exec queue. 1822 */ 1823 DRM_XE_OA_PROPERTY_NO_PREEMPT, 1824 1825 /** 1826 * @DRM_XE_OA_PROPERTY_NUM_SYNCS: Number of syncs in the sync array 1827 * specified in @DRM_XE_OA_PROPERTY_SYNCS 1828 */ 1829 DRM_XE_OA_PROPERTY_NUM_SYNCS, 1830 1831 /** 1832 * @DRM_XE_OA_PROPERTY_SYNCS: Pointer to struct @drm_xe_sync array 1833 * with array size specified via @DRM_XE_OA_PROPERTY_NUM_SYNCS. OA 1834 * configuration will wait till input fences signal. Output fences 1835 * will signal after the new OA configuration takes effect. For 1836 * @DRM_XE_SYNC_TYPE_USER_FENCE, @addr is a user pointer, similar 1837 * to the VM bind case. 1838 */ 1839 DRM_XE_OA_PROPERTY_SYNCS, 1840 1841 /** 1842 * @DRM_XE_OA_PROPERTY_OA_BUFFER_SIZE: Size of OA buffer to be 1843 * allocated by the driver in bytes. Supported sizes are powers of 1844 * 2 from 128 KiB to 128 MiB. When not specified, a 16 MiB OA 1845 * buffer is allocated by default. 1846 */ 1847 DRM_XE_OA_PROPERTY_OA_BUFFER_SIZE, 1848 1849 /** 1850 * @DRM_XE_OA_PROPERTY_WAIT_NUM_REPORTS: Number of reports to wait 1851 * for before unblocking poll or read 1852 */ 1853 DRM_XE_OA_PROPERTY_WAIT_NUM_REPORTS, 1854 }; 1855 1856 /** 1857 * struct drm_xe_oa_config - OA metric configuration 1858 * 1859 * Multiple OA configs can be added using @DRM_XE_OBSERVATION_OP_ADD_CONFIG. A 1860 * particular config can be specified when opening an OA stream using 1861 * @DRM_XE_OA_PROPERTY_OA_METRIC_SET property. 1862 */ 1863 struct drm_xe_oa_config { 1864 /** @extensions: Pointer to the first extension struct, if any */ 1865 __u64 extensions; 1866 1867 /** @uuid: String formatted like "%\08x-%\04x-%\04x-%\04x-%\012x" */ 1868 char uuid[36]; 1869 1870 /** @n_regs: Number of regs in @regs_ptr */ 1871 __u32 n_regs; 1872 1873 /** 1874 * @regs_ptr: Pointer to (register address, value) pairs for OA config 1875 * registers. Expected length of buffer is: (2 * sizeof(u32) * @n_regs). 1876 */ 1877 __u64 regs_ptr; 1878 }; 1879 1880 /** 1881 * struct drm_xe_oa_stream_status - OA stream status returned from 1882 * @DRM_XE_OBSERVATION_IOCTL_STATUS observation stream fd ioctl. Userspace can 1883 * call the ioctl to query stream status in response to EIO errno from 1884 * observation fd read(). 1885 */ 1886 struct drm_xe_oa_stream_status { 1887 /** @extensions: Pointer to the first extension struct, if any */ 1888 __u64 extensions; 1889 1890 /** @oa_status: OA stream status (see Bspec 46717/61226) */ 1891 __u64 oa_status; 1892 #define DRM_XE_OASTATUS_MMIO_TRG_Q_FULL (1 << 3) 1893 #define DRM_XE_OASTATUS_COUNTER_OVERFLOW (1 << 2) 1894 #define DRM_XE_OASTATUS_BUFFER_OVERFLOW (1 << 1) 1895 #define DRM_XE_OASTATUS_REPORT_LOST (1 << 0) 1896 1897 /** @reserved: reserved for future use */ 1898 __u64 reserved[3]; 1899 }; 1900 1901 /** 1902 * struct drm_xe_oa_stream_info - OA stream info returned from 1903 * @DRM_XE_OBSERVATION_IOCTL_INFO observation stream fd ioctl 1904 */ 1905 struct drm_xe_oa_stream_info { 1906 /** @extensions: Pointer to the first extension struct, if any */ 1907 __u64 extensions; 1908 1909 /** @oa_buf_size: OA buffer size */ 1910 __u64 oa_buf_size; 1911 1912 /** @reserved: reserved for future use */ 1913 __u64 reserved[3]; 1914 }; 1915 1916 /** 1917 * enum drm_xe_pxp_session_type - Supported PXP session types. 1918 * 1919 * We currently only support HWDRM sessions, which are used for protected 1920 * content that ends up being displayed, but the HW supports multiple types, so 1921 * we might extend support in the future. 1922 */ 1923 enum drm_xe_pxp_session_type { 1924 /** @DRM_XE_PXP_TYPE_NONE: PXP not used */ 1925 DRM_XE_PXP_TYPE_NONE = 0, 1926 /** 1927 * @DRM_XE_PXP_TYPE_HWDRM: HWDRM sessions are used for content that ends 1928 * up on the display. 1929 */ 1930 DRM_XE_PXP_TYPE_HWDRM = 1, 1931 }; 1932 1933 /* ID of the protected content session managed by Xe when PXP is active */ 1934 #define DRM_XE_PXP_HWDRM_DEFAULT_SESSION 0xf 1935 1936 /** 1937 * enum drm_xe_eu_stall_property_id - EU stall sampling input property ids. 1938 * 1939 * These properties are passed to the driver at open as a chain of 1940 * @drm_xe_ext_set_property structures with @property set to these 1941 * properties' enums and @value set to the corresponding values of these 1942 * properties. @drm_xe_user_extension base.name should be set to 1943 * @DRM_XE_EU_STALL_EXTENSION_SET_PROPERTY. 1944 * 1945 * With the file descriptor obtained from open, user space must enable 1946 * the EU stall stream fd with @DRM_XE_OBSERVATION_IOCTL_ENABLE before 1947 * calling read(). EIO errno from read() indicates HW dropped data 1948 * due to full buffer. 1949 */ 1950 enum drm_xe_eu_stall_property_id { 1951 #define DRM_XE_EU_STALL_EXTENSION_SET_PROPERTY 0 1952 /** 1953 * @DRM_XE_EU_STALL_PROP_GT_ID: @gt_id of the GT on which 1954 * EU stall data will be captured. 1955 */ 1956 DRM_XE_EU_STALL_PROP_GT_ID = 1, 1957 1958 /** 1959 * @DRM_XE_EU_STALL_PROP_SAMPLE_RATE: Sampling rate in 1960 * GPU cycles from @sampling_rates in struct @drm_xe_query_eu_stall 1961 */ 1962 DRM_XE_EU_STALL_PROP_SAMPLE_RATE, 1963 1964 /** 1965 * @DRM_XE_EU_STALL_PROP_WAIT_NUM_REPORTS: Minimum number of 1966 * EU stall data reports to be present in the kernel buffer 1967 * before unblocking a blocked poll or read. 1968 */ 1969 DRM_XE_EU_STALL_PROP_WAIT_NUM_REPORTS, 1970 }; 1971 1972 /** 1973 * struct drm_xe_query_eu_stall - Information about EU stall sampling. 1974 * 1975 * If a query is made with a struct @drm_xe_device_query where .query 1976 * is equal to @DRM_XE_DEVICE_QUERY_EU_STALL, then the reply uses 1977 * struct @drm_xe_query_eu_stall in .data. 1978 */ 1979 struct drm_xe_query_eu_stall { 1980 /** @extensions: Pointer to the first extension struct, if any */ 1981 __u64 extensions; 1982 1983 /** @capabilities: EU stall capabilities bit-mask */ 1984 __u64 capabilities; 1985 #define DRM_XE_EU_STALL_CAPS_BASE (1 << 0) 1986 1987 /** @record_size: size of each EU stall data record */ 1988 __u64 record_size; 1989 1990 /** @per_xecore_buf_size: internal per XeCore buffer size */ 1991 __u64 per_xecore_buf_size; 1992 1993 /** @reserved: Reserved */ 1994 __u64 reserved[5]; 1995 1996 /** @num_sampling_rates: Number of sampling rates in @sampling_rates array */ 1997 __u64 num_sampling_rates; 1998 1999 /** 2000 * @sampling_rates: Flexible array of sampling rates 2001 * sorted in the fastest to slowest order. 2002 * Sampling rates are specified in GPU clock cycles. 2003 */ 2004 __u64 sampling_rates[]; 2005 }; 2006 2007 /** 2008 * struct drm_xe_madvise - Input of &DRM_IOCTL_XE_MADVISE 2009 * 2010 * This structure is used to set memory attributes for a virtual address range 2011 * in a VM. The type of attribute is specified by @type, and the corresponding 2012 * union member is used to provide additional parameters for @type. 2013 * 2014 * Supported attribute types: 2015 * - DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC: Set preferred memory location. 2016 * - DRM_XE_MEM_RANGE_ATTR_ATOMIC: Set atomic access policy. 2017 * - DRM_XE_MEM_RANGE_ATTR_PAT: Set page attribute table index. 2018 * 2019 * Example: 2020 * 2021 * .. code-block:: C 2022 * 2023 * struct drm_xe_madvise madvise = { 2024 * .vm_id = vm_id, 2025 * .start = 0x100000, 2026 * .range = 0x2000, 2027 * .type = DRM_XE_MEM_RANGE_ATTR_ATOMIC, 2028 * .atomic_val = DRM_XE_ATOMIC_DEVICE, 2029 * }; 2030 * 2031 * ioctl(fd, DRM_IOCTL_XE_MADVISE, &madvise); 2032 * 2033 */ 2034 struct drm_xe_madvise { 2035 /** @extensions: Pointer to the first extension struct, if any */ 2036 __u64 extensions; 2037 2038 /** @start: start of the virtual address range */ 2039 __u64 start; 2040 2041 /** @range: size of the virtual address range */ 2042 __u64 range; 2043 2044 /** @vm_id: vm_id of the virtual range */ 2045 __u32 vm_id; 2046 2047 #define DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC 0 2048 #define DRM_XE_MEM_RANGE_ATTR_ATOMIC 1 2049 #define DRM_XE_MEM_RANGE_ATTR_PAT 2 2050 /** @type: type of attribute */ 2051 __u32 type; 2052 2053 union { 2054 /** 2055 * @preferred_mem_loc: preferred memory location 2056 * 2057 * Used when @type == DRM_XE_MEM_RANGE_ATTR_PREFERRED_LOC 2058 * 2059 * Supported values for @preferred_mem_loc.devmem_fd: 2060 * - DRM_XE_PREFERRED_LOC_DEFAULT_DEVICE: set vram of fault tile as preferred loc 2061 * - DRM_XE_PREFERRED_LOC_DEFAULT_SYSTEM: set smem as preferred loc 2062 * 2063 * Supported values for @preferred_mem_loc.migration_policy: 2064 * - DRM_XE_MIGRATE_ALL_PAGES 2065 * - DRM_XE_MIGRATE_ONLY_SYSTEM_PAGES 2066 */ 2067 struct { 2068 #define DRM_XE_PREFERRED_LOC_DEFAULT_DEVICE 0 2069 #define DRM_XE_PREFERRED_LOC_DEFAULT_SYSTEM -1 2070 /** @preferred_mem_loc.devmem_fd: fd for preferred loc */ 2071 __u32 devmem_fd; 2072 2073 #define DRM_XE_MIGRATE_ALL_PAGES 0 2074 #define DRM_XE_MIGRATE_ONLY_SYSTEM_PAGES 1 2075 /** @preferred_mem_loc.migration_policy: Page migration policy */ 2076 __u16 migration_policy; 2077 2078 /** @preferred_mem_loc.pad : MBZ */ 2079 __u16 pad; 2080 2081 /** @preferred_mem_loc.reserved : Reserved */ 2082 __u64 reserved; 2083 } preferred_mem_loc; 2084 2085 /** 2086 * @atomic: Atomic access policy 2087 * 2088 * Used when @type == DRM_XE_MEM_RANGE_ATTR_ATOMIC. 2089 * 2090 * Supported values for @atomic.val: 2091 * - DRM_XE_ATOMIC_UNDEFINED: Undefined or default behaviour. 2092 * Support both GPU and CPU atomic operations for system allocator. 2093 * Support GPU atomic operations for normal(bo) allocator. 2094 * - DRM_XE_ATOMIC_DEVICE: Support GPU atomic operations. 2095 * - DRM_XE_ATOMIC_GLOBAL: Support both GPU and CPU atomic operations. 2096 * - DRM_XE_ATOMIC_CPU: Support CPU atomic only, no GPU atomics supported. 2097 */ 2098 struct { 2099 #define DRM_XE_ATOMIC_UNDEFINED 0 2100 #define DRM_XE_ATOMIC_DEVICE 1 2101 #define DRM_XE_ATOMIC_GLOBAL 2 2102 #define DRM_XE_ATOMIC_CPU 3 2103 /** @atomic.val: value of atomic operation */ 2104 __u32 val; 2105 2106 /** @atomic.pad: MBZ */ 2107 __u32 pad; 2108 2109 /** @atomic.reserved: Reserved */ 2110 __u64 reserved; 2111 } atomic; 2112 2113 /** 2114 * @pat_index: Page attribute table index 2115 * 2116 * Used when @type == DRM_XE_MEM_RANGE_ATTR_PAT. 2117 */ 2118 struct { 2119 /** @pat_index.val: PAT index value */ 2120 __u32 val; 2121 2122 /** @pat_index.pad: MBZ */ 2123 __u32 pad; 2124 2125 /** @pat_index.reserved: Reserved */ 2126 __u64 reserved; 2127 } pat_index; 2128 }; 2129 2130 /** @reserved: Reserved */ 2131 __u64 reserved[2]; 2132 }; 2133 2134 /** 2135 * struct drm_xe_mem_range_attr - Output of &DRM_IOCTL_XE_VM_QUERY_MEM_RANGES_ATTRS 2136 * 2137 * This structure is provided by userspace and filled by KMD in response to the 2138 * DRM_IOCTL_XE_VM_QUERY_MEM_RANGES_ATTRS ioctl. It describes memory attributes of 2139 * a memory ranges within a user specified address range in a VM. 2140 * 2141 * The structure includes information such as atomic access policy, 2142 * page attribute table (PAT) index, and preferred memory location. 2143 * Userspace allocates an array of these structures and passes a pointer to the 2144 * ioctl to retrieve attributes for each memory ranges 2145 * 2146 * @extensions: Pointer to the first extension struct, if any 2147 * @start: Start address of the memory range 2148 * @end: End address of the virtual memory range 2149 * 2150 */ 2151 struct drm_xe_mem_range_attr { 2152 /** @extensions: Pointer to the first extension struct, if any */ 2153 __u64 extensions; 2154 2155 /** @start: start of the memory range */ 2156 __u64 start; 2157 2158 /** @end: end of the memory range */ 2159 __u64 end; 2160 2161 /** @preferred_mem_loc: preferred memory location */ 2162 struct { 2163 /** @preferred_mem_loc.devmem_fd: fd for preferred loc */ 2164 __u32 devmem_fd; 2165 2166 /** @preferred_mem_loc.migration_policy: Page migration policy */ 2167 __u32 migration_policy; 2168 } preferred_mem_loc; 2169 2170 /** @atomic: Atomic access policy */ 2171 struct { 2172 /** @atomic.val: atomic attribute */ 2173 __u32 val; 2174 2175 /** @atomic.reserved: Reserved */ 2176 __u32 reserved; 2177 } atomic; 2178 2179 /** @pat_index: Page attribute table index */ 2180 struct { 2181 /** @pat_index.val: PAT index */ 2182 __u32 val; 2183 2184 /** @pat_index.reserved: Reserved */ 2185 __u32 reserved; 2186 } pat_index; 2187 2188 /** @reserved: Reserved */ 2189 __u64 reserved[2]; 2190 }; 2191 2192 /** 2193 * struct drm_xe_vm_query_mem_range_attr - Input of &DRM_IOCTL_XE_VM_QUERY_MEM_ATTRIBUTES 2194 * 2195 * This structure is used to query memory attributes of memory regions 2196 * within a user specified address range in a VM. It provides detailed 2197 * information about each memory range, including atomic access policy, 2198 * page attribute table (PAT) index, and preferred memory location. 2199 * 2200 * Userspace first calls the ioctl with @num_mem_ranges = 0, 2201 * @sizeof_mem_ranges_attr = 0 and @vector_of_vma_mem_attr = NULL to retrieve 2202 * the number of memory regions and size of each memory range attribute. 2203 * Then, it allocates a buffer of that size and calls the ioctl again to fill 2204 * the buffer with memory range attributes. 2205 * 2206 * If second call fails with -ENOSPC, it means memory ranges changed between 2207 * first call and now, retry IOCTL again with @num_mem_ranges = 0, 2208 * @sizeof_mem_ranges_attr = 0 and @vector_of_vma_mem_attr = NULL followed by 2209 * Second ioctl call. 2210 * 2211 * Example: 2212 * 2213 * .. code-block:: C 2214 * 2215 * struct drm_xe_vm_query_mem_range_attr query = { 2216 * .vm_id = vm_id, 2217 * .start = 0x100000, 2218 * .range = 0x2000, 2219 * }; 2220 * 2221 * // First ioctl call to get num of mem regions and sizeof each attribute 2222 * ioctl(fd, DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS, &query); 2223 * 2224 * // Allocate buffer for the memory region attributes 2225 * void *ptr = malloc(query.num_mem_ranges * query.sizeof_mem_range_attr); 2226 * void *ptr_start = ptr; 2227 * 2228 * query.vector_of_mem_attr = (uintptr_t)ptr; 2229 * 2230 * // Second ioctl call to actually fill the memory attributes 2231 * ioctl(fd, DRM_IOCTL_XE_VM_QUERY_MEM_RANGE_ATTRS, &query); 2232 * 2233 * // Iterate over the returned memory region attributes 2234 * for (unsigned int i = 0; i < query.num_mem_ranges; ++i) { 2235 * struct drm_xe_mem_range_attr *attr = (struct drm_xe_mem_range_attr *)ptr; 2236 * 2237 * // Do something with attr 2238 * 2239 * // Move pointer by one entry 2240 * ptr += query.sizeof_mem_range_attr; 2241 * } 2242 * 2243 * free(ptr_start); 2244 */ 2245 struct drm_xe_vm_query_mem_range_attr { 2246 /** @extensions: Pointer to the first extension struct, if any */ 2247 __u64 extensions; 2248 2249 /** @vm_id: vm_id of the virtual range */ 2250 __u32 vm_id; 2251 2252 /** @num_mem_ranges: number of mem_ranges in range */ 2253 __u32 num_mem_ranges; 2254 2255 /** @start: start of the virtual address range */ 2256 __u64 start; 2257 2258 /** @range: size of the virtual address range */ 2259 __u64 range; 2260 2261 /** @sizeof_mem_range_attr: size of struct drm_xe_mem_range_attr */ 2262 __u64 sizeof_mem_range_attr; 2263 2264 /** @vector_of_mem_attr: userptr to array of struct drm_xe_mem_range_attr */ 2265 __u64 vector_of_mem_attr; 2266 2267 /** @reserved: Reserved */ 2268 __u64 reserved[2]; 2269 2270 }; 2271 2272 #if defined(__cplusplus) 2273 } 2274 #endif 2275 2276 #endif /* _UAPI_XE_DRM_H_ */ 2277