1 /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */ 2 /* 3 * Copyright (C) 2020-2026 Intel Corporation 4 */ 5 6 #ifndef __UAPI_IVPU_DRM_H__ 7 #define __UAPI_IVPU_DRM_H__ 8 9 #include "drm.h" 10 11 #if defined(__cplusplus) 12 extern "C" { 13 #endif 14 15 #define DRM_IVPU_GET_PARAM 0x00 16 #define DRM_IVPU_SET_PARAM 0x01 17 #define DRM_IVPU_BO_CREATE 0x02 18 #define DRM_IVPU_BO_INFO 0x03 19 #define DRM_IVPU_SUBMIT 0x05 20 #define DRM_IVPU_BO_WAIT 0x06 21 #define DRM_IVPU_METRIC_STREAMER_START 0x07 22 #define DRM_IVPU_METRIC_STREAMER_STOP 0x08 23 #define DRM_IVPU_METRIC_STREAMER_GET_DATA 0x09 24 #define DRM_IVPU_METRIC_STREAMER_GET_INFO 0x0a 25 #define DRM_IVPU_CMDQ_CREATE 0x0b 26 #define DRM_IVPU_CMDQ_DESTROY 0x0c 27 #define DRM_IVPU_CMDQ_SUBMIT 0x0d 28 #define DRM_IVPU_BO_CREATE_FROM_USERPTR 0x0e 29 30 #define DRM_IOCTL_IVPU_GET_PARAM \ 31 DRM_IOWR(DRM_COMMAND_BASE + DRM_IVPU_GET_PARAM, struct drm_ivpu_param) 32 33 #define DRM_IOCTL_IVPU_SET_PARAM \ 34 DRM_IOW(DRM_COMMAND_BASE + DRM_IVPU_SET_PARAM, struct drm_ivpu_param) 35 36 #define DRM_IOCTL_IVPU_BO_CREATE \ 37 DRM_IOWR(DRM_COMMAND_BASE + DRM_IVPU_BO_CREATE, struct drm_ivpu_bo_create) 38 39 #define DRM_IOCTL_IVPU_BO_INFO \ 40 DRM_IOWR(DRM_COMMAND_BASE + DRM_IVPU_BO_INFO, struct drm_ivpu_bo_info) 41 42 #define DRM_IOCTL_IVPU_SUBMIT \ 43 DRM_IOW(DRM_COMMAND_BASE + DRM_IVPU_SUBMIT, struct drm_ivpu_submit) 44 45 #define DRM_IOCTL_IVPU_BO_WAIT \ 46 DRM_IOWR(DRM_COMMAND_BASE + DRM_IVPU_BO_WAIT, struct drm_ivpu_bo_wait) 47 48 #define DRM_IOCTL_IVPU_METRIC_STREAMER_START \ 49 DRM_IOWR(DRM_COMMAND_BASE + DRM_IVPU_METRIC_STREAMER_START, \ 50 struct drm_ivpu_metric_streamer_start) 51 52 #define DRM_IOCTL_IVPU_METRIC_STREAMER_STOP \ 53 DRM_IOW(DRM_COMMAND_BASE + DRM_IVPU_METRIC_STREAMER_STOP, \ 54 struct drm_ivpu_metric_streamer_stop) 55 56 #define DRM_IOCTL_IVPU_METRIC_STREAMER_GET_DATA \ 57 DRM_IOWR(DRM_COMMAND_BASE + DRM_IVPU_METRIC_STREAMER_GET_DATA, \ 58 struct drm_ivpu_metric_streamer_get_data) 59 60 #define DRM_IOCTL_IVPU_METRIC_STREAMER_GET_INFO \ 61 DRM_IOWR(DRM_COMMAND_BASE + DRM_IVPU_METRIC_STREAMER_GET_INFO, \ 62 struct drm_ivpu_metric_streamer_get_data) 63 64 #define DRM_IOCTL_IVPU_CMDQ_CREATE \ 65 DRM_IOWR(DRM_COMMAND_BASE + DRM_IVPU_CMDQ_CREATE, struct drm_ivpu_cmdq_create) 66 67 #define DRM_IOCTL_IVPU_CMDQ_DESTROY \ 68 DRM_IOW(DRM_COMMAND_BASE + DRM_IVPU_CMDQ_DESTROY, struct drm_ivpu_cmdq_destroy) 69 70 #define DRM_IOCTL_IVPU_CMDQ_SUBMIT \ 71 DRM_IOW(DRM_COMMAND_BASE + DRM_IVPU_CMDQ_SUBMIT, struct drm_ivpu_cmdq_submit) 72 73 #define DRM_IOCTL_IVPU_BO_CREATE_FROM_USERPTR \ 74 DRM_IOWR(DRM_COMMAND_BASE + DRM_IVPU_BO_CREATE_FROM_USERPTR, \ 75 struct drm_ivpu_bo_create_from_userptr) 76 77 /** 78 * DOC: contexts 79 * 80 * VPU contexts have private virtual address space, job queues and priority. 81 * Each context is identified by an unique ID. Context is created on open(). 82 */ 83 84 #define DRM_IVPU_PARAM_DEVICE_ID 0 85 #define DRM_IVPU_PARAM_DEVICE_REVISION 1 86 #define DRM_IVPU_PARAM_PLATFORM_TYPE 2 87 #define DRM_IVPU_PARAM_CORE_CLOCK_RATE 3 88 #define DRM_IVPU_PARAM_NUM_CONTEXTS 4 89 #define DRM_IVPU_PARAM_CONTEXT_BASE_ADDRESS 5 90 #define DRM_IVPU_PARAM_CONTEXT_PRIORITY 6 /* Deprecated */ 91 #define DRM_IVPU_PARAM_CONTEXT_ID 7 92 #define DRM_IVPU_PARAM_FW_API_VERSION 8 93 #define DRM_IVPU_PARAM_ENGINE_HEARTBEAT 9 94 #define DRM_IVPU_PARAM_UNIQUE_INFERENCE_ID 10 95 #define DRM_IVPU_PARAM_TILE_CONFIG 11 96 #define DRM_IVPU_PARAM_SKU 12 97 #define DRM_IVPU_PARAM_CAPABILITIES 13 98 #define DRM_IVPU_PARAM_PREEMPT_BUFFER_SIZE 14 99 #define DRM_IVPU_PARAM_CMDQ_PRIORITY 15 100 101 #define DRM_IVPU_PLATFORM_TYPE_SILICON 0 102 103 /* Deprecated, use DRM_IVPU_JOB_PRIORITY */ 104 #define DRM_IVPU_CONTEXT_PRIORITY_IDLE 0 105 #define DRM_IVPU_CONTEXT_PRIORITY_NORMAL 1 106 #define DRM_IVPU_CONTEXT_PRIORITY_FOCUS 2 107 #define DRM_IVPU_CONTEXT_PRIORITY_REALTIME 3 108 109 #define DRM_IVPU_JOB_PRIORITY_DEFAULT 0 110 #define DRM_IVPU_JOB_PRIORITY_IDLE 1 111 #define DRM_IVPU_JOB_PRIORITY_NORMAL 2 112 #define DRM_IVPU_JOB_PRIORITY_FOCUS 3 113 #define DRM_IVPU_JOB_PRIORITY_REALTIME 4 114 115 /** 116 * DRM_IVPU_CAP_METRIC_STREAMER 117 * 118 * Metric streamer support. Provides sampling of various hardware performance 119 * metrics like DMA bandwidth and cache miss/hits. Can be used for profiling. 120 */ 121 #define DRM_IVPU_CAP_METRIC_STREAMER 1 122 /** 123 * DRM_IVPU_CAP_DMA_MEMORY_RANGE 124 * 125 * Driver has capability to allocate separate memory range 126 * accessible by hardware DMA. 127 */ 128 #define DRM_IVPU_CAP_DMA_MEMORY_RANGE 2 129 /** 130 * DRM_IVPU_CAP_MANAGE_CMDQ 131 * 132 * Driver supports explicit command queue operations like command queue create, 133 * command queue destroy and submit job on specific command queue. 134 */ 135 #define DRM_IVPU_CAP_MANAGE_CMDQ 3 136 /** 137 * DRM_IVPU_CAP_BO_CREATE_FROM_USERPTR 138 * 139 * Driver supports creating buffer objects from user space memory pointers. 140 * This allows creating GEM buffers from existing user memory regions. 141 */ 142 #define DRM_IVPU_CAP_BO_CREATE_FROM_USERPTR 4 143 144 /** 145 * DRM_IVPU_CAP_CMDQ_SET_PRIORITY 146 * 147 * Driver supports DRM_IVPU_PARAM_CMDQ_PRIORITY parameter to get/set command 148 * queue priority. 149 * This allows changing command queue priority after creation. 150 */ 151 #define DRM_IVPU_CAP_CMDQ_SET_PRIORITY 5 152 153 /** 154 * struct drm_ivpu_param - Get/Set VPU parameters 155 */ 156 struct drm_ivpu_param { 157 /** 158 * @param: 159 * 160 * Supported params: 161 * 162 * %DRM_IVPU_PARAM_DEVICE_ID: 163 * PCI Device ID of the VPU device (read-only) 164 * 165 * %DRM_IVPU_PARAM_DEVICE_REVISION: 166 * VPU device revision (read-only) 167 * 168 * %DRM_IVPU_PARAM_PLATFORM_TYPE: 169 * Returns %DRM_IVPU_PLATFORM_TYPE_SILICON on real hardware or device specific 170 * platform type when executing on a simulator or emulator (read-only) 171 * 172 * %DRM_IVPU_PARAM_CORE_CLOCK_RATE: 173 * Maximum frequency of the NPU data processing unit clock (read-only) 174 * 175 * %DRM_IVPU_PARAM_NUM_CONTEXTS: 176 * Maximum number of simultaneously existing contexts (read-only) 177 * 178 * %DRM_IVPU_PARAM_CONTEXT_BASE_ADDRESS: 179 * Lowest VPU virtual address available in the current context (read-only) 180 * 181 * %DRM_IVPU_PARAM_CONTEXT_ID: 182 * Current context ID, always greater than 0 (read-only) 183 * 184 * %DRM_IVPU_PARAM_FW_API_VERSION: 185 * Firmware API version array (read-only) 186 * 187 * %DRM_IVPU_PARAM_ENGINE_HEARTBEAT: 188 * Heartbeat value from an engine (read-only). 189 * Engine ID (i.e. DRM_IVPU_ENGINE_COMPUTE) is given via index. 190 * 191 * %DRM_IVPU_PARAM_UNIQUE_INFERENCE_ID: 192 * Device-unique inference ID (read-only) 193 * 194 * %DRM_IVPU_PARAM_TILE_CONFIG: 195 * VPU tile configuration (read-only) 196 * 197 * %DRM_IVPU_PARAM_SKU: 198 * VPU SKU ID (read-only) 199 * 200 * %DRM_IVPU_PARAM_CAPABILITIES: 201 * Supported capabilities (read-only) 202 * 203 * %DRM_IVPU_PARAM_PREEMPT_BUFFER_SIZE: 204 * Size of the preemption buffer (read-only) 205 * 206 * %DRM_IVPU_PARAM_CMDQ_PRIORITY: 207 * Get/Set command queue priority (see DRM_IVPU_JOB_PRIORITY_*). 208 * DRM_IVPU_JOB_PRIORITY_DEFAULT is treated as DRM_IVPU_JOB_PRIORITY_NORMAL. 209 * Command queue ID is given via drm_ivpu_param.index. 210 */ 211 __u32 param; 212 213 /** @index: Index for params that have multiple instances */ 214 __u32 index; 215 216 /** @value: Param value */ 217 __u64 value; 218 }; 219 220 #define DRM_IVPU_BO_SHAVE_MEM 0x00000001 221 #define DRM_IVPU_BO_HIGH_MEM DRM_IVPU_BO_SHAVE_MEM 222 #define DRM_IVPU_BO_MAPPABLE 0x00000002 223 #define DRM_IVPU_BO_DMA_MEM 0x00000004 224 #define DRM_IVPU_BO_READ_ONLY 0x00000008 225 226 #define DRM_IVPU_BO_CACHED 0x00000000 227 #define DRM_IVPU_BO_UNCACHED 0x00010000 228 #define DRM_IVPU_BO_WC 0x00020000 229 #define DRM_IVPU_BO_CACHE_MASK 0x00030000 230 231 #define DRM_IVPU_BO_FLAGS \ 232 (DRM_IVPU_BO_HIGH_MEM | \ 233 DRM_IVPU_BO_MAPPABLE | \ 234 DRM_IVPU_BO_DMA_MEM | \ 235 DRM_IVPU_BO_READ_ONLY | \ 236 DRM_IVPU_BO_CACHE_MASK) 237 238 /** 239 * struct drm_ivpu_bo_create - Create BO backed by SHMEM 240 * 241 * Create GEM buffer object allocated in SHMEM memory. 242 */ 243 struct drm_ivpu_bo_create { 244 /** @size: The size in bytes of the allocated memory */ 245 __u64 size; 246 247 /** 248 * @flags: 249 * 250 * Supported flags: 251 * 252 * %DRM_IVPU_BO_HIGH_MEM: 253 * 254 * Allocate VPU address from >4GB range. 255 * Buffer object with vpu address >4GB can be always accessed by the 256 * VPU DMA engine, but some HW generation may not be able to access 257 * this memory from then firmware running on the VPU management processor. 258 * Suitable for input, output and some scratch buffers. 259 * 260 * %DRM_IVPU_BO_MAPPABLE: 261 * 262 * Buffer object can be mapped using mmap(). 263 * 264 * %DRM_IVPU_BO_CACHED: 265 * 266 * Allocated BO will be cached on host side (WB) and snooped on the VPU side. 267 * This is the default caching mode. 268 * 269 * %DRM_IVPU_BO_UNCACHED: 270 * 271 * Not supported. Use DRM_IVPU_BO_WC instead. 272 * 273 * %DRM_IVPU_BO_WC: 274 * 275 * Allocated BO will use write combining buffer for writes but reads will be 276 * uncached. 277 */ 278 __u32 flags; 279 280 /** @handle: Returned GEM object handle */ 281 __u32 handle; 282 283 /** @vpu_addr: Returned VPU virtual address */ 284 __u64 vpu_addr; 285 }; 286 287 /** 288 * struct drm_ivpu_bo_create_from_userptr - Create dma-buf from user pointer 289 * 290 * Create a GEM buffer object from a user pointer to a memory region. 291 */ 292 struct drm_ivpu_bo_create_from_userptr { 293 /** @user_ptr: User pointer to memory region (must be page aligned) */ 294 __u64 user_ptr; 295 296 /** @size: Size of the memory region in bytes (must be page aligned) */ 297 __u64 size; 298 299 /** 300 * @flags: 301 * 302 * Supported flags: 303 * 304 * %DRM_IVPU_BO_HIGH_MEM: 305 * 306 * Allocate VPU address from >4GB range. 307 * 308 * %DRM_IVPU_BO_DMA_MEM: 309 * 310 * Allocate from DMA memory range accessible by hardware DMA. 311 * 312 * %DRM_IVPU_BO_READ_ONLY: 313 * 314 * Allocate as a read-only buffer object. 315 */ 316 __u32 flags; 317 318 /** @handle: Returned GEM object handle */ 319 __u32 handle; 320 321 /** @vpu_addr: Returned VPU virtual address */ 322 __u64 vpu_addr; 323 }; 324 325 /** 326 * struct drm_ivpu_bo_info - Query buffer object info 327 */ 328 struct drm_ivpu_bo_info { 329 /** @handle: Handle of the queried BO */ 330 __u32 handle; 331 332 /** @flags: Returned flags used to create the BO */ 333 __u32 flags; 334 335 /** @vpu_addr: Returned VPU virtual address */ 336 __u64 vpu_addr; 337 338 /** 339 * @mmap_offset: 340 * 341 * Returned offset to be used in mmap(). 0 in case the BO is not mappable. 342 */ 343 __u64 mmap_offset; 344 345 /** @size: Returned GEM object size, aligned to PAGE_SIZE */ 346 __u64 size; 347 }; 348 349 /* drm_ivpu_submit engines */ 350 #define DRM_IVPU_ENGINE_COMPUTE 0 351 #define DRM_IVPU_ENGINE_COPY 1 /* Deprecated */ 352 353 /** 354 * struct drm_ivpu_submit - Submit commands to the VPU 355 * 356 * Execute a single command buffer on a given VPU engine. 357 * Handles to all referenced buffer objects have to be provided in @buffers_ptr. 358 * 359 * User space may wait on job completion using %DRM_IVPU_BO_WAIT ioctl. 360 */ 361 struct drm_ivpu_submit { 362 /** 363 * @buffers_ptr: 364 * 365 * A pointer to an u32 array of GEM handles of the BOs required for this job. 366 * The number of elements in the array must be equal to the value given by @buffer_count. 367 * 368 * The first BO is the command buffer. The rest of array has to contain all 369 * BOs referenced from the command buffer. 370 */ 371 __u64 buffers_ptr; 372 373 /** @buffer_count: Number of elements in the @buffers_ptr */ 374 __u32 buffer_count; 375 376 /** 377 * @engine: Select the engine this job should be executed on 378 * 379 * %DRM_IVPU_ENGINE_COMPUTE: 380 * 381 * Performs Deep Learning Neural Compute Inference Operations 382 */ 383 __u32 engine; 384 385 /** @flags: Reserved for future use - must be zero */ 386 __u32 flags; 387 388 /** 389 * @commands_offset: 390 * 391 * Offset inside the first buffer in @buffers_ptr containing commands 392 * to be executed. The offset has to be 8-byte aligned. 393 */ 394 __u32 commands_offset; 395 396 /** 397 * @priority: 398 * 399 * Priority to be set for related job command queue, can be one of the following: 400 * %DRM_IVPU_JOB_PRIORITY_DEFAULT 401 * %DRM_IVPU_JOB_PRIORITY_IDLE 402 * %DRM_IVPU_JOB_PRIORITY_NORMAL 403 * %DRM_IVPU_JOB_PRIORITY_FOCUS 404 * %DRM_IVPU_JOB_PRIORITY_REALTIME 405 */ 406 __u32 priority; 407 }; 408 409 /** 410 * struct drm_ivpu_cmdq_submit - Submit commands to the VPU using explicit command queue 411 * 412 * Execute a single command buffer on a given command queue. 413 * Handles to all referenced buffer objects have to be provided in @buffers_ptr. 414 * 415 * User space may wait on job completion using %DRM_IVPU_BO_WAIT ioctl. 416 */ 417 struct drm_ivpu_cmdq_submit { 418 /** 419 * @buffers_ptr: 420 * 421 * A pointer to an u32 array of GEM handles of the BOs required for this job. 422 * The number of elements in the array must be equal to the value given by @buffer_count. 423 * 424 * The first BO is the command buffer. The rest of array has to contain all 425 * BOs referenced from the command buffer. 426 */ 427 __u64 buffers_ptr; 428 429 /** @buffer_count: Number of elements in the @buffers_ptr */ 430 __u32 buffer_count; 431 432 /** @cmdq_id: ID for the command queue where job will be submitted */ 433 __u32 cmdq_id; 434 435 /** @flags: Reserved for future use - must be zero */ 436 __u32 flags; 437 438 /** 439 * @commands_offset: 440 * 441 * Offset inside the first buffer in @buffers_ptr containing commands 442 * to be executed. The offset has to be 8-byte aligned. 443 */ 444 __u32 commands_offset; 445 /** 446 * @preempt_buffer_index: 447 * 448 * Index of the preemption buffer in the buffers_ptr array. 449 */ 450 __u32 preempt_buffer_index; 451 __u32 reserved; 452 }; 453 454 /* drm_ivpu_bo_wait job status codes */ 455 #define DRM_IVPU_JOB_STATUS_SUCCESS 0 456 #define DRM_IVPU_JOB_STATUS_ABORTED 256 457 458 /** 459 * struct drm_ivpu_bo_wait - Wait for BO to become inactive 460 * 461 * Blocks until a given buffer object becomes inactive. 462 * With @timeout_ms set to 0 returns immediately. 463 */ 464 struct drm_ivpu_bo_wait { 465 /** @handle: Handle to the buffer object to be waited on */ 466 __u32 handle; 467 468 /** @flags: Reserved for future use - must be zero */ 469 __u32 flags; 470 471 /** @timeout_ns: Absolute timeout in nanoseconds (may be zero) */ 472 __s64 timeout_ns; 473 474 /** 475 * @job_status: 476 * 477 * Job status code which is updated after the job is completed. 478 * &DRM_IVPU_JOB_STATUS_SUCCESS or device specific error otherwise. 479 * Valid only if @handle points to a command buffer. 480 */ 481 __u32 job_status; 482 483 /** @pad: Padding - must be zero */ 484 __u32 pad; 485 }; 486 487 /** 488 * struct drm_ivpu_metric_streamer_start - Start collecting metric data 489 */ 490 struct drm_ivpu_metric_streamer_start { 491 /** @metric_group_mask: Indicates metric streamer instance */ 492 __u64 metric_group_mask; 493 /** @sampling_period_ns: Sampling period in nanoseconds */ 494 __u64 sampling_period_ns; 495 /** 496 * @read_period_samples: 497 * 498 * Number of samples after which user space will try to read the data. 499 * Reading the data after significantly longer period may cause data loss. 500 */ 501 __u32 read_period_samples; 502 /** @sample_size: Returned size of a single sample in bytes */ 503 __u32 sample_size; 504 /** @max_data_size: Returned max @data_size from %DRM_IOCTL_IVPU_METRIC_STREAMER_GET_DATA */ 505 __u32 max_data_size; 506 }; 507 508 /** 509 * struct drm_ivpu_metric_streamer_get_data - Copy collected metric data 510 */ 511 struct drm_ivpu_metric_streamer_get_data { 512 /** @metric_group_mask: Indicates metric streamer instance */ 513 __u64 metric_group_mask; 514 /** @buffer_ptr: A pointer to a destination for the copied data */ 515 __u64 buffer_ptr; 516 /** @buffer_size: Size of the destination buffer */ 517 __u64 buffer_size; 518 /** 519 * @data_size: Returned size of copied metric data 520 * 521 * If the @buffer_size is zero, returns the amount of data ready to be copied. 522 */ 523 __u64 data_size; 524 }; 525 526 /* Command queue flags */ 527 #define DRM_IVPU_CMDQ_FLAG_TURBO 0x00000001 528 529 /** 530 * struct drm_ivpu_cmdq_create - Create command queue for job submission 531 */ 532 struct drm_ivpu_cmdq_create { 533 /** @cmdq_id: Returned ID of created command queue */ 534 __u32 cmdq_id; 535 /** 536 * @priority: 537 * 538 * Priority to be set for related job command queue, can be one of the following: 539 * %DRM_IVPU_JOB_PRIORITY_DEFAULT 540 * %DRM_IVPU_JOB_PRIORITY_IDLE 541 * %DRM_IVPU_JOB_PRIORITY_NORMAL 542 * %DRM_IVPU_JOB_PRIORITY_FOCUS 543 * %DRM_IVPU_JOB_PRIORITY_REALTIME 544 */ 545 __u32 priority; 546 /** 547 * @flags: 548 * 549 * Supported flags: 550 * 551 * %DRM_IVPU_CMDQ_FLAG_TURBO 552 * 553 * Enable low-latency mode for the command queue. The NPU will maximize performance 554 * when executing jobs from such queue at the cost of increased power usage. 555 */ 556 __u32 flags; 557 }; 558 559 /** 560 * struct drm_ivpu_cmdq_destroy - Destroy a command queue 561 */ 562 struct drm_ivpu_cmdq_destroy { 563 /** @cmdq_id: ID of command queue to destroy */ 564 __u32 cmdq_id; 565 }; 566 567 /** 568 * struct drm_ivpu_metric_streamer_stop - Stop collecting metric data 569 */ 570 struct drm_ivpu_metric_streamer_stop { 571 /** @metric_group_mask: Indicates metric streamer instance */ 572 __u64 metric_group_mask; 573 }; 574 575 #if defined(__cplusplus) 576 } 577 #endif 578 579 #endif /* __UAPI_IVPU_DRM_H__ */ 580