1 /* SPDX-License-Identifier: MIT */ 2 /* Copyright (C) 2023 Collabora ltd. */ 3 #ifndef _PANTHOR_DRM_H_ 4 #define _PANTHOR_DRM_H_ 5 6 #include "drm.h" 7 8 #if defined(__cplusplus) 9 extern "C" { 10 #endif 11 12 /** 13 * DOC: Introduction 14 * 15 * This documentation describes the Panthor IOCTLs. 16 * 17 * Just a few generic rules about the data passed to the Panthor IOCTLs: 18 * 19 * - Structures must be aligned on 64-bit/8-byte. If the object is not 20 * naturally aligned, a padding field must be added. 21 * - Fields must be explicitly aligned to their natural type alignment with 22 * pad[0..N] fields. 23 * - All padding fields will be checked by the driver to make sure they are 24 * zeroed. 25 * - Flags can be added, but not removed/replaced. 26 * - New fields can be added to the main structures (the structures 27 * directly passed to the ioctl). Those fields can be added at the end of 28 * the structure, or replace existing padding fields. Any new field being 29 * added must preserve the behavior that existed before those fields were 30 * added when a value of zero is passed. 31 * - New fields can be added to indirect objects (objects pointed by the 32 * main structure), iff those objects are passed a size to reflect the 33 * size known by the userspace driver (see drm_panthor_obj_array::stride 34 * or drm_panthor_dev_query::size). 35 * - If the kernel driver is too old to know some fields, those will be 36 * ignored if zero, and otherwise rejected (and so will be zero on output). 37 * - If userspace is too old to know some fields, those will be zeroed 38 * (input) before the structure is parsed by the kernel driver. 39 * - Each new flag/field addition must come with a driver version update so 40 * the userspace driver doesn't have to trial and error to know which 41 * flags are supported. 42 * - Structures should not contain unions, as this would defeat the 43 * extensibility of such structures. 44 * - IOCTLs can't be removed or replaced. New IOCTL IDs should be placed 45 * at the end of the drm_panthor_ioctl_id enum. 46 */ 47 48 /** 49 * DOC: MMIO regions exposed to userspace. 50 * 51 * .. c:macro:: DRM_PANTHOR_USER_MMIO_OFFSET 52 * 53 * File offset for all MMIO regions being exposed to userspace. Don't use 54 * this value directly, use DRM_PANTHOR_USER_<name>_OFFSET values instead. 55 * pgoffset passed to mmap2() is an unsigned long, which forces us to use a 56 * different offset on 32-bit and 64-bit systems. 57 * 58 * .. c:macro:: DRM_PANTHOR_USER_FLUSH_ID_MMIO_OFFSET 59 * 60 * File offset for the LATEST_FLUSH_ID register. The Userspace driver controls 61 * GPU cache flushing through CS instructions, but the flush reduction 62 * mechanism requires a flush_id. This flush_id could be queried with an 63 * ioctl, but Arm provides a well-isolated register page containing only this 64 * read-only register, so let's expose this page through a static mmap offset 65 * and allow direct mapping of this MMIO region so we can avoid the 66 * user <-> kernel round-trip. 67 */ 68 #define DRM_PANTHOR_USER_MMIO_OFFSET_32BIT (1ull << 43) 69 #define DRM_PANTHOR_USER_MMIO_OFFSET_64BIT (1ull << 56) 70 #define DRM_PANTHOR_USER_MMIO_OFFSET (sizeof(unsigned long) < 8 ? \ 71 DRM_PANTHOR_USER_MMIO_OFFSET_32BIT : \ 72 DRM_PANTHOR_USER_MMIO_OFFSET_64BIT) 73 #define DRM_PANTHOR_USER_FLUSH_ID_MMIO_OFFSET (DRM_PANTHOR_USER_MMIO_OFFSET | 0) 74 75 /** 76 * DOC: IOCTL IDs 77 * 78 * enum drm_panthor_ioctl_id - IOCTL IDs 79 * 80 * Place new ioctls at the end, don't re-order, don't replace or remove entries. 81 * 82 * These IDs are not meant to be used directly. Use the DRM_IOCTL_PANTHOR_xxx 83 * definitions instead. 84 */ 85 enum drm_panthor_ioctl_id { 86 /** @DRM_PANTHOR_DEV_QUERY: Query device information. */ 87 DRM_PANTHOR_DEV_QUERY = 0, 88 89 /** @DRM_PANTHOR_VM_CREATE: Create a VM. */ 90 DRM_PANTHOR_VM_CREATE, 91 92 /** @DRM_PANTHOR_VM_DESTROY: Destroy a VM. */ 93 DRM_PANTHOR_VM_DESTROY, 94 95 /** @DRM_PANTHOR_VM_BIND: Bind/unbind memory to a VM. */ 96 DRM_PANTHOR_VM_BIND, 97 98 /** @DRM_PANTHOR_VM_GET_STATE: Get VM state. */ 99 DRM_PANTHOR_VM_GET_STATE, 100 101 /** @DRM_PANTHOR_BO_CREATE: Create a buffer object. */ 102 DRM_PANTHOR_BO_CREATE, 103 104 /** 105 * @DRM_PANTHOR_BO_MMAP_OFFSET: Get the file offset to pass to 106 * mmap to map a GEM object. 107 */ 108 DRM_PANTHOR_BO_MMAP_OFFSET, 109 110 /** @DRM_PANTHOR_GROUP_CREATE: Create a scheduling group. */ 111 DRM_PANTHOR_GROUP_CREATE, 112 113 /** @DRM_PANTHOR_GROUP_DESTROY: Destroy a scheduling group. */ 114 DRM_PANTHOR_GROUP_DESTROY, 115 116 /** 117 * @DRM_PANTHOR_GROUP_SUBMIT: Submit jobs to queues belonging 118 * to a specific scheduling group. 119 */ 120 DRM_PANTHOR_GROUP_SUBMIT, 121 122 /** @DRM_PANTHOR_GROUP_GET_STATE: Get the state of a scheduling group. */ 123 DRM_PANTHOR_GROUP_GET_STATE, 124 125 /** @DRM_PANTHOR_TILER_HEAP_CREATE: Create a tiler heap. */ 126 DRM_PANTHOR_TILER_HEAP_CREATE, 127 128 /** @DRM_PANTHOR_TILER_HEAP_DESTROY: Destroy a tiler heap. */ 129 DRM_PANTHOR_TILER_HEAP_DESTROY, 130 131 /** @DRM_PANTHOR_BO_SET_LABEL: Label a BO. */ 132 DRM_PANTHOR_BO_SET_LABEL, 133 }; 134 135 /** 136 * DOC: IOCTL arguments 137 */ 138 139 /** 140 * struct drm_panthor_obj_array - Object array. 141 * 142 * This object is used to pass an array of objects whose size is subject to changes in 143 * future versions of the driver. In order to support this mutability, we pass a stride 144 * describing the size of the object as known by userspace. 145 * 146 * You shouldn't fill drm_panthor_obj_array fields directly. You should instead use 147 * the DRM_PANTHOR_OBJ_ARRAY() macro that takes care of initializing the stride to 148 * the object size. 149 */ 150 struct drm_panthor_obj_array { 151 /** @stride: Stride of object struct. Used for versioning. */ 152 __u32 stride; 153 154 /** @count: Number of objects in the array. */ 155 __u32 count; 156 157 /** @array: User pointer to an array of objects. */ 158 __u64 array; 159 }; 160 161 /** 162 * DRM_PANTHOR_OBJ_ARRAY() - Initialize a drm_panthor_obj_array field. 163 * @cnt: Number of elements in the array. 164 * @ptr: Pointer to the array to pass to the kernel. 165 * 166 * Macro initializing a drm_panthor_obj_array based on the object size as known 167 * by userspace. 168 */ 169 #define DRM_PANTHOR_OBJ_ARRAY(cnt, ptr) \ 170 { .stride = sizeof((ptr)[0]), .count = (cnt), .array = (__u64)(uintptr_t)(ptr) } 171 172 /** 173 * enum drm_panthor_sync_op_flags - Synchronization operation flags. 174 */ 175 enum drm_panthor_sync_op_flags { 176 /** @DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_MASK: Synchronization handle type mask. */ 177 DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_MASK = 0xff, 178 179 /** @DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_SYNCOBJ: Synchronization object type. */ 180 DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_SYNCOBJ = 0, 181 182 /** 183 * @DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_TIMELINE_SYNCOBJ: Timeline synchronization 184 * object type. 185 */ 186 DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_TIMELINE_SYNCOBJ = 1, 187 188 /** @DRM_PANTHOR_SYNC_OP_WAIT: Wait operation. */ 189 DRM_PANTHOR_SYNC_OP_WAIT = 0 << 31, 190 191 /** @DRM_PANTHOR_SYNC_OP_SIGNAL: Signal operation. */ 192 DRM_PANTHOR_SYNC_OP_SIGNAL = (int)(1u << 31), 193 }; 194 195 /** 196 * struct drm_panthor_sync_op - Synchronization operation. 197 */ 198 struct drm_panthor_sync_op { 199 /** @flags: Synchronization operation flags. Combination of DRM_PANTHOR_SYNC_OP values. */ 200 __u32 flags; 201 202 /** @handle: Sync handle. */ 203 __u32 handle; 204 205 /** 206 * @timeline_value: MBZ if 207 * (flags & DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_MASK) != 208 * DRM_PANTHOR_SYNC_OP_HANDLE_TYPE_TIMELINE_SYNCOBJ. 209 */ 210 __u64 timeline_value; 211 }; 212 213 /** 214 * enum drm_panthor_dev_query_type - Query type 215 * 216 * Place new types at the end, don't re-order, don't remove or replace. 217 */ 218 enum drm_panthor_dev_query_type { 219 /** @DRM_PANTHOR_DEV_QUERY_GPU_INFO: Query GPU information. */ 220 DRM_PANTHOR_DEV_QUERY_GPU_INFO = 0, 221 222 /** @DRM_PANTHOR_DEV_QUERY_CSIF_INFO: Query command-stream interface information. */ 223 DRM_PANTHOR_DEV_QUERY_CSIF_INFO, 224 225 /** @DRM_PANTHOR_DEV_QUERY_TIMESTAMP_INFO: Query timestamp information. */ 226 DRM_PANTHOR_DEV_QUERY_TIMESTAMP_INFO, 227 228 /** 229 * @DRM_PANTHOR_DEV_QUERY_GROUP_PRIORITIES_INFO: Query allowed group priorities information. 230 */ 231 DRM_PANTHOR_DEV_QUERY_GROUP_PRIORITIES_INFO, 232 }; 233 234 /** 235 * struct drm_panthor_gpu_info - GPU information 236 * 237 * Structure grouping all queryable information relating to the GPU. 238 */ 239 struct drm_panthor_gpu_info { 240 /** @gpu_id : GPU ID. */ 241 __u32 gpu_id; 242 #define DRM_PANTHOR_ARCH_MAJOR(x) ((x) >> 28) 243 #define DRM_PANTHOR_ARCH_MINOR(x) (((x) >> 24) & 0xf) 244 #define DRM_PANTHOR_ARCH_REV(x) (((x) >> 20) & 0xf) 245 #define DRM_PANTHOR_PRODUCT_MAJOR(x) (((x) >> 16) & 0xf) 246 #define DRM_PANTHOR_VERSION_MAJOR(x) (((x) >> 12) & 0xf) 247 #define DRM_PANTHOR_VERSION_MINOR(x) (((x) >> 4) & 0xff) 248 #define DRM_PANTHOR_VERSION_STATUS(x) ((x) & 0xf) 249 250 /** @gpu_rev: GPU revision. */ 251 __u32 gpu_rev; 252 253 /** @csf_id: Command stream frontend ID. */ 254 __u32 csf_id; 255 #define DRM_PANTHOR_CSHW_MAJOR(x) (((x) >> 26) & 0x3f) 256 #define DRM_PANTHOR_CSHW_MINOR(x) (((x) >> 20) & 0x3f) 257 #define DRM_PANTHOR_CSHW_REV(x) (((x) >> 16) & 0xf) 258 #define DRM_PANTHOR_MCU_MAJOR(x) (((x) >> 10) & 0x3f) 259 #define DRM_PANTHOR_MCU_MINOR(x) (((x) >> 4) & 0x3f) 260 #define DRM_PANTHOR_MCU_REV(x) ((x) & 0xf) 261 262 /** @l2_features: L2-cache features. */ 263 __u32 l2_features; 264 265 /** @tiler_features: Tiler features. */ 266 __u32 tiler_features; 267 268 /** @mem_features: Memory features. */ 269 __u32 mem_features; 270 271 /** @mmu_features: MMU features. */ 272 __u32 mmu_features; 273 #define DRM_PANTHOR_MMU_VA_BITS(x) ((x) & 0xff) 274 275 /** @thread_features: Thread features. */ 276 __u32 thread_features; 277 278 /** @max_threads: Maximum number of threads. */ 279 __u32 max_threads; 280 281 /** @thread_max_workgroup_size: Maximum workgroup size. */ 282 __u32 thread_max_workgroup_size; 283 284 /** 285 * @thread_max_barrier_size: Maximum number of threads that can wait 286 * simultaneously on a barrier. 287 */ 288 __u32 thread_max_barrier_size; 289 290 /** @coherency_features: Coherency features. */ 291 __u32 coherency_features; 292 293 /** @texture_features: Texture features. */ 294 __u32 texture_features[4]; 295 296 /** @as_present: Bitmask encoding the number of address-space exposed by the MMU. */ 297 __u32 as_present; 298 299 /** @shader_present: Bitmask encoding the shader cores exposed by the GPU. */ 300 __u64 shader_present; 301 302 /** @l2_present: Bitmask encoding the L2 caches exposed by the GPU. */ 303 __u64 l2_present; 304 305 /** @tiler_present: Bitmask encoding the tiler units exposed by the GPU. */ 306 __u64 tiler_present; 307 308 /** @core_features: Used to discriminate core variants when they exist. */ 309 __u32 core_features; 310 311 /** @pad: MBZ. */ 312 __u32 pad; 313 }; 314 315 /** 316 * struct drm_panthor_csif_info - Command stream interface information 317 * 318 * Structure grouping all queryable information relating to the command stream interface. 319 */ 320 struct drm_panthor_csif_info { 321 /** @csg_slot_count: Number of command stream group slots exposed by the firmware. */ 322 __u32 csg_slot_count; 323 324 /** @cs_slot_count: Number of command stream slots per group. */ 325 __u32 cs_slot_count; 326 327 /** @cs_reg_count: Number of command stream registers. */ 328 __u32 cs_reg_count; 329 330 /** @scoreboard_slot_count: Number of scoreboard slots. */ 331 __u32 scoreboard_slot_count; 332 333 /** 334 * @unpreserved_cs_reg_count: Number of command stream registers reserved by 335 * the kernel driver to call a userspace command stream. 336 * 337 * All registers can be used by a userspace command stream, but the 338 * [cs_slot_count - unpreserved_cs_reg_count .. cs_slot_count] registers are 339 * used by the kernel when DRM_PANTHOR_IOCTL_GROUP_SUBMIT is called. 340 */ 341 __u32 unpreserved_cs_reg_count; 342 343 /** 344 * @pad: Padding field, set to zero. 345 */ 346 __u32 pad; 347 }; 348 349 /** 350 * struct drm_panthor_timestamp_info - Timestamp information 351 * 352 * Structure grouping all queryable information relating to the GPU timestamp. 353 */ 354 struct drm_panthor_timestamp_info { 355 /** 356 * @timestamp_frequency: The frequency of the timestamp timer or 0 if 357 * unknown. 358 */ 359 __u64 timestamp_frequency; 360 361 /** @current_timestamp: The current timestamp. */ 362 __u64 current_timestamp; 363 364 /** @timestamp_offset: The offset of the timestamp timer. */ 365 __u64 timestamp_offset; 366 }; 367 368 /** 369 * struct drm_panthor_group_priorities_info - Group priorities information 370 * 371 * Structure grouping all queryable information relating to the allowed group priorities. 372 */ 373 struct drm_panthor_group_priorities_info { 374 /** 375 * @allowed_mask: Bitmask of the allowed group priorities. 376 * 377 * Each bit represents a variant of the enum drm_panthor_group_priority. 378 */ 379 __u8 allowed_mask; 380 381 /** @pad: Padding fields, MBZ. */ 382 __u8 pad[3]; 383 }; 384 385 /** 386 * struct drm_panthor_dev_query - Arguments passed to DRM_PANTHOR_IOCTL_DEV_QUERY 387 */ 388 struct drm_panthor_dev_query { 389 /** @type: the query type (see drm_panthor_dev_query_type). */ 390 __u32 type; 391 392 /** 393 * @size: size of the type being queried. 394 * 395 * If pointer is NULL, size is updated by the driver to provide the 396 * output structure size. If pointer is not NULL, the driver will 397 * only copy min(size, actual_structure_size) bytes to the pointer, 398 * and update the size accordingly. This allows us to extend query 399 * types without breaking userspace. 400 */ 401 __u32 size; 402 403 /** 404 * @pointer: user pointer to a query type struct. 405 * 406 * Pointer can be NULL, in which case, nothing is copied, but the 407 * actual structure size is returned. If not NULL, it must point to 408 * a location that's large enough to hold size bytes. 409 */ 410 __u64 pointer; 411 }; 412 413 /** 414 * struct drm_panthor_vm_create - Arguments passed to DRM_PANTHOR_IOCTL_VM_CREATE 415 */ 416 struct drm_panthor_vm_create { 417 /** @flags: VM flags, MBZ. */ 418 __u32 flags; 419 420 /** @id: Returned VM ID. */ 421 __u32 id; 422 423 /** 424 * @user_va_range: Size of the VA space reserved for user objects. 425 * 426 * The kernel will pick the remaining space to map kernel-only objects to the 427 * VM (heap chunks, heap context, ring buffers, kernel synchronization objects, 428 * ...). If the space left for kernel objects is too small, kernel object 429 * allocation will fail further down the road. One can use 430 * drm_panthor_gpu_info::mmu_features to extract the total virtual address 431 * range, and chose a user_va_range that leaves some space to the kernel. 432 * 433 * If user_va_range is zero, the kernel will pick a sensible value based on 434 * TASK_SIZE and the virtual range supported by the GPU MMU (the kernel/user 435 * split should leave enough VA space for userspace processes to support SVM, 436 * while still allowing the kernel to map some amount of kernel objects in 437 * the kernel VA range). The value chosen by the driver will be returned in 438 * @user_va_range. 439 * 440 * User VA space always starts at 0x0, kernel VA space is always placed after 441 * the user VA range. 442 */ 443 __u64 user_va_range; 444 }; 445 446 /** 447 * struct drm_panthor_vm_destroy - Arguments passed to DRM_PANTHOR_IOCTL_VM_DESTROY 448 */ 449 struct drm_panthor_vm_destroy { 450 /** @id: ID of the VM to destroy. */ 451 __u32 id; 452 453 /** @pad: MBZ. */ 454 __u32 pad; 455 }; 456 457 /** 458 * enum drm_panthor_vm_bind_op_flags - VM bind operation flags 459 */ 460 enum drm_panthor_vm_bind_op_flags { 461 /** 462 * @DRM_PANTHOR_VM_BIND_OP_MAP_READONLY: Map the memory read-only. 463 * 464 * Only valid with DRM_PANTHOR_VM_BIND_OP_TYPE_MAP. 465 */ 466 DRM_PANTHOR_VM_BIND_OP_MAP_READONLY = 1 << 0, 467 468 /** 469 * @DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC: Map the memory not-executable. 470 * 471 * Only valid with DRM_PANTHOR_VM_BIND_OP_TYPE_MAP. 472 */ 473 DRM_PANTHOR_VM_BIND_OP_MAP_NOEXEC = 1 << 1, 474 475 /** 476 * @DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED: Map the memory uncached. 477 * 478 * Only valid with DRM_PANTHOR_VM_BIND_OP_TYPE_MAP. 479 */ 480 DRM_PANTHOR_VM_BIND_OP_MAP_UNCACHED = 1 << 2, 481 482 /** 483 * @DRM_PANTHOR_VM_BIND_OP_TYPE_MASK: Mask used to determine the type of operation. 484 */ 485 DRM_PANTHOR_VM_BIND_OP_TYPE_MASK = (int)(0xfu << 28), 486 487 /** @DRM_PANTHOR_VM_BIND_OP_TYPE_MAP: Map operation. */ 488 DRM_PANTHOR_VM_BIND_OP_TYPE_MAP = 0 << 28, 489 490 /** @DRM_PANTHOR_VM_BIND_OP_TYPE_UNMAP: Unmap operation. */ 491 DRM_PANTHOR_VM_BIND_OP_TYPE_UNMAP = 1 << 28, 492 493 /** 494 * @DRM_PANTHOR_VM_BIND_OP_TYPE_SYNC_ONLY: No VM operation. 495 * 496 * Just serves as a synchronization point on a VM queue. 497 * 498 * Only valid if %DRM_PANTHOR_VM_BIND_ASYNC is set in drm_panthor_vm_bind::flags, 499 * and drm_panthor_vm_bind_op::syncs contains at least one element. 500 */ 501 DRM_PANTHOR_VM_BIND_OP_TYPE_SYNC_ONLY = 2 << 28, 502 }; 503 504 /** 505 * struct drm_panthor_vm_bind_op - VM bind operation 506 */ 507 struct drm_panthor_vm_bind_op { 508 /** @flags: Combination of drm_panthor_vm_bind_op_flags flags. */ 509 __u32 flags; 510 511 /** 512 * @bo_handle: Handle of the buffer object to map. 513 * MBZ for unmap or sync-only operations. 514 */ 515 __u32 bo_handle; 516 517 /** 518 * @bo_offset: Buffer object offset. 519 * MBZ for unmap or sync-only operations. 520 */ 521 __u64 bo_offset; 522 523 /** 524 * @va: Virtual address to map/unmap. 525 * MBZ for sync-only operations. 526 */ 527 __u64 va; 528 529 /** 530 * @size: Size to map/unmap. 531 * MBZ for sync-only operations. 532 */ 533 __u64 size; 534 535 /** 536 * @syncs: Array of struct drm_panthor_sync_op synchronization 537 * operations. 538 * 539 * This array must be empty if %DRM_PANTHOR_VM_BIND_ASYNC is not set on 540 * the drm_panthor_vm_bind object containing this VM bind operation. 541 * 542 * This array shall not be empty for sync-only operations. 543 */ 544 struct drm_panthor_obj_array syncs; 545 546 }; 547 548 /** 549 * enum drm_panthor_vm_bind_flags - VM bind flags 550 */ 551 enum drm_panthor_vm_bind_flags { 552 /** 553 * @DRM_PANTHOR_VM_BIND_ASYNC: VM bind operations are queued to the VM 554 * queue instead of being executed synchronously. 555 */ 556 DRM_PANTHOR_VM_BIND_ASYNC = 1 << 0, 557 }; 558 559 /** 560 * struct drm_panthor_vm_bind - Arguments passed to DRM_IOCTL_PANTHOR_VM_BIND 561 */ 562 struct drm_panthor_vm_bind { 563 /** @vm_id: VM targeted by the bind request. */ 564 __u32 vm_id; 565 566 /** @flags: Combination of drm_panthor_vm_bind_flags flags. */ 567 __u32 flags; 568 569 /** @ops: Array of struct drm_panthor_vm_bind_op bind operations. */ 570 struct drm_panthor_obj_array ops; 571 }; 572 573 /** 574 * enum drm_panthor_vm_state - VM states. 575 */ 576 enum drm_panthor_vm_state { 577 /** 578 * @DRM_PANTHOR_VM_STATE_USABLE: VM is usable. 579 * 580 * New VM operations will be accepted on this VM. 581 */ 582 DRM_PANTHOR_VM_STATE_USABLE, 583 584 /** 585 * @DRM_PANTHOR_VM_STATE_UNUSABLE: VM is unusable. 586 * 587 * Something put the VM in an unusable state (like an asynchronous 588 * VM_BIND request failing for any reason). 589 * 590 * Once the VM is in this state, all new MAP operations will be 591 * rejected, and any GPU job targeting this VM will fail. 592 * UNMAP operations are still accepted. 593 * 594 * The only way to recover from an unusable VM is to create a new 595 * VM, and destroy the old one. 596 */ 597 DRM_PANTHOR_VM_STATE_UNUSABLE, 598 }; 599 600 /** 601 * struct drm_panthor_vm_get_state - Get VM state. 602 */ 603 struct drm_panthor_vm_get_state { 604 /** @vm_id: VM targeted by the get_state request. */ 605 __u32 vm_id; 606 607 /** 608 * @state: state returned by the driver. 609 * 610 * Must be one of the enum drm_panthor_vm_state values. 611 */ 612 __u32 state; 613 }; 614 615 /** 616 * enum drm_panthor_bo_flags - Buffer object flags, passed at creation time. 617 */ 618 enum drm_panthor_bo_flags { 619 /** @DRM_PANTHOR_BO_NO_MMAP: The buffer object will never be CPU-mapped in userspace. */ 620 DRM_PANTHOR_BO_NO_MMAP = (1 << 0), 621 }; 622 623 /** 624 * struct drm_panthor_bo_create - Arguments passed to DRM_IOCTL_PANTHOR_BO_CREATE. 625 */ 626 struct drm_panthor_bo_create { 627 /** 628 * @size: Requested size for the object 629 * 630 * The (page-aligned) allocated size for the object will be returned. 631 */ 632 __u64 size; 633 634 /** 635 * @flags: Flags. Must be a combination of drm_panthor_bo_flags flags. 636 */ 637 __u32 flags; 638 639 /** 640 * @exclusive_vm_id: Exclusive VM this buffer object will be mapped to. 641 * 642 * If not zero, the field must refer to a valid VM ID, and implies that: 643 * - the buffer object will only ever be bound to that VM 644 * - cannot be exported as a PRIME fd 645 */ 646 __u32 exclusive_vm_id; 647 648 /** 649 * @handle: Returned handle for the object. 650 * 651 * Object handles are nonzero. 652 */ 653 __u32 handle; 654 655 /** @pad: MBZ. */ 656 __u32 pad; 657 }; 658 659 /** 660 * struct drm_panthor_bo_mmap_offset - Arguments passed to DRM_IOCTL_PANTHOR_BO_MMAP_OFFSET. 661 */ 662 struct drm_panthor_bo_mmap_offset { 663 /** @handle: Handle of the object we want an mmap offset for. */ 664 __u32 handle; 665 666 /** @pad: MBZ. */ 667 __u32 pad; 668 669 /** @offset: The fake offset to use for subsequent mmap calls. */ 670 __u64 offset; 671 }; 672 673 /** 674 * struct drm_panthor_queue_create - Queue creation arguments. 675 */ 676 struct drm_panthor_queue_create { 677 /** 678 * @priority: Defines the priority of queues inside a group. Goes from 0 to 15, 679 * 15 being the highest priority. 680 */ 681 __u8 priority; 682 683 /** @pad: Padding fields, MBZ. */ 684 __u8 pad[3]; 685 686 /** @ringbuf_size: Size of the ring buffer to allocate to this queue. */ 687 __u32 ringbuf_size; 688 }; 689 690 /** 691 * enum drm_panthor_group_priority - Scheduling group priority 692 */ 693 enum drm_panthor_group_priority { 694 /** @PANTHOR_GROUP_PRIORITY_LOW: Low priority group. */ 695 PANTHOR_GROUP_PRIORITY_LOW = 0, 696 697 /** @PANTHOR_GROUP_PRIORITY_MEDIUM: Medium priority group. */ 698 PANTHOR_GROUP_PRIORITY_MEDIUM, 699 700 /** 701 * @PANTHOR_GROUP_PRIORITY_HIGH: High priority group. 702 * 703 * Requires CAP_SYS_NICE or DRM_MASTER. 704 */ 705 PANTHOR_GROUP_PRIORITY_HIGH, 706 707 /** 708 * @PANTHOR_GROUP_PRIORITY_REALTIME: Realtime priority group. 709 * 710 * Requires CAP_SYS_NICE or DRM_MASTER. 711 */ 712 PANTHOR_GROUP_PRIORITY_REALTIME, 713 }; 714 715 /** 716 * struct drm_panthor_group_create - Arguments passed to DRM_IOCTL_PANTHOR_GROUP_CREATE 717 */ 718 struct drm_panthor_group_create { 719 /** @queues: Array of drm_panthor_queue_create elements. */ 720 struct drm_panthor_obj_array queues; 721 722 /** 723 * @max_compute_cores: Maximum number of cores that can be used by compute 724 * jobs across CS queues bound to this group. 725 * 726 * Must be less or equal to the number of bits set in @compute_core_mask. 727 */ 728 __u8 max_compute_cores; 729 730 /** 731 * @max_fragment_cores: Maximum number of cores that can be used by fragment 732 * jobs across CS queues bound to this group. 733 * 734 * Must be less or equal to the number of bits set in @fragment_core_mask. 735 */ 736 __u8 max_fragment_cores; 737 738 /** 739 * @max_tiler_cores: Maximum number of tilers that can be used by tiler jobs 740 * across CS queues bound to this group. 741 * 742 * Must be less or equal to the number of bits set in @tiler_core_mask. 743 */ 744 __u8 max_tiler_cores; 745 746 /** @priority: Group priority (see enum drm_panthor_group_priority). */ 747 __u8 priority; 748 749 /** @pad: Padding field, MBZ. */ 750 __u32 pad; 751 752 /** 753 * @compute_core_mask: Mask encoding cores that can be used for compute jobs. 754 * 755 * This field must have at least @max_compute_cores bits set. 756 * 757 * The bits set here should also be set in drm_panthor_gpu_info::shader_present. 758 */ 759 __u64 compute_core_mask; 760 761 /** 762 * @fragment_core_mask: Mask encoding cores that can be used for fragment jobs. 763 * 764 * This field must have at least @max_fragment_cores bits set. 765 * 766 * The bits set here should also be set in drm_panthor_gpu_info::shader_present. 767 */ 768 __u64 fragment_core_mask; 769 770 /** 771 * @tiler_core_mask: Mask encoding cores that can be used for tiler jobs. 772 * 773 * This field must have at least @max_tiler_cores bits set. 774 * 775 * The bits set here should also be set in drm_panthor_gpu_info::tiler_present. 776 */ 777 __u64 tiler_core_mask; 778 779 /** 780 * @vm_id: VM ID to bind this group to. 781 * 782 * All submission to queues bound to this group will use this VM. 783 */ 784 __u32 vm_id; 785 786 /** 787 * @group_handle: Returned group handle. Passed back when submitting jobs or 788 * destroying a group. 789 */ 790 __u32 group_handle; 791 }; 792 793 /** 794 * struct drm_panthor_group_destroy - Arguments passed to DRM_IOCTL_PANTHOR_GROUP_DESTROY 795 */ 796 struct drm_panthor_group_destroy { 797 /** @group_handle: Group to destroy */ 798 __u32 group_handle; 799 800 /** @pad: Padding field, MBZ. */ 801 __u32 pad; 802 }; 803 804 /** 805 * struct drm_panthor_queue_submit - Job submission arguments. 806 * 807 * This is describing the userspace command stream to call from the kernel 808 * command stream ring-buffer. Queue submission is always part of a group 809 * submission, taking one or more jobs to submit to the underlying queues. 810 */ 811 struct drm_panthor_queue_submit { 812 /** @queue_index: Index of the queue inside a group. */ 813 __u32 queue_index; 814 815 /** 816 * @stream_size: Size of the command stream to execute. 817 * 818 * Must be 64-bit/8-byte aligned (the size of a CS instruction) 819 * 820 * Can be zero if stream_addr is zero too. 821 * 822 * When the stream size is zero, the queue submit serves as a 823 * synchronization point. 824 */ 825 __u32 stream_size; 826 827 /** 828 * @stream_addr: GPU address of the command stream to execute. 829 * 830 * Must be aligned on 64-byte. 831 * 832 * Can be zero is stream_size is zero too. 833 */ 834 __u64 stream_addr; 835 836 /** 837 * @latest_flush: FLUSH_ID read at the time the stream was built. 838 * 839 * This allows cache flush elimination for the automatic 840 * flush+invalidate(all) done at submission time, which is needed to 841 * ensure the GPU doesn't get garbage when reading the indirect command 842 * stream buffers. If you want the cache flush to happen 843 * unconditionally, pass a zero here. 844 * 845 * Ignored when stream_size is zero. 846 */ 847 __u32 latest_flush; 848 849 /** @pad: MBZ. */ 850 __u32 pad; 851 852 /** @syncs: Array of struct drm_panthor_sync_op sync operations. */ 853 struct drm_panthor_obj_array syncs; 854 }; 855 856 /** 857 * struct drm_panthor_group_submit - Arguments passed to DRM_IOCTL_PANTHOR_GROUP_SUBMIT 858 */ 859 struct drm_panthor_group_submit { 860 /** @group_handle: Handle of the group to queue jobs to. */ 861 __u32 group_handle; 862 863 /** @pad: MBZ. */ 864 __u32 pad; 865 866 /** @queue_submits: Array of drm_panthor_queue_submit objects. */ 867 struct drm_panthor_obj_array queue_submits; 868 }; 869 870 /** 871 * enum drm_panthor_group_state_flags - Group state flags 872 */ 873 enum drm_panthor_group_state_flags { 874 /** 875 * @DRM_PANTHOR_GROUP_STATE_TIMEDOUT: Group had unfinished jobs. 876 * 877 * When a group ends up with this flag set, no jobs can be submitted to its queues. 878 */ 879 DRM_PANTHOR_GROUP_STATE_TIMEDOUT = 1 << 0, 880 881 /** 882 * @DRM_PANTHOR_GROUP_STATE_FATAL_FAULT: Group had fatal faults. 883 * 884 * When a group ends up with this flag set, no jobs can be submitted to its queues. 885 */ 886 DRM_PANTHOR_GROUP_STATE_FATAL_FAULT = 1 << 1, 887 888 /** 889 * @DRM_PANTHOR_GROUP_STATE_INNOCENT: Group was killed during a reset caused by other 890 * groups. 891 * 892 * This flag can only be set if DRM_PANTHOR_GROUP_STATE_TIMEDOUT is set and 893 * DRM_PANTHOR_GROUP_STATE_FATAL_FAULT is not. 894 */ 895 DRM_PANTHOR_GROUP_STATE_INNOCENT = 1 << 2, 896 }; 897 898 /** 899 * struct drm_panthor_group_get_state - Arguments passed to DRM_IOCTL_PANTHOR_GROUP_GET_STATE 900 * 901 * Used to query the state of a group and decide whether a new group should be created to 902 * replace it. 903 */ 904 struct drm_panthor_group_get_state { 905 /** @group_handle: Handle of the group to query state on */ 906 __u32 group_handle; 907 908 /** 909 * @state: Combination of DRM_PANTHOR_GROUP_STATE_* flags encoding the 910 * group state. 911 */ 912 __u32 state; 913 914 /** @fatal_queues: Bitmask of queues that faced fatal faults. */ 915 __u32 fatal_queues; 916 917 /** @pad: MBZ */ 918 __u32 pad; 919 }; 920 921 /** 922 * struct drm_panthor_tiler_heap_create - Arguments passed to DRM_IOCTL_PANTHOR_TILER_HEAP_CREATE 923 */ 924 struct drm_panthor_tiler_heap_create { 925 /** @vm_id: VM ID the tiler heap should be mapped to */ 926 __u32 vm_id; 927 928 /** @initial_chunk_count: Initial number of chunks to allocate. Must be at least one. */ 929 __u32 initial_chunk_count; 930 931 /** 932 * @chunk_size: Chunk size. 933 * 934 * Must be page-aligned and lie in the [128k:8M] range. 935 */ 936 __u32 chunk_size; 937 938 /** 939 * @max_chunks: Maximum number of chunks that can be allocated. 940 * 941 * Must be at least @initial_chunk_count. 942 */ 943 __u32 max_chunks; 944 945 /** 946 * @target_in_flight: Maximum number of in-flight render passes. 947 * 948 * If the heap has more than tiler jobs in-flight, the FW will wait for render 949 * passes to finish before queuing new tiler jobs. 950 */ 951 __u32 target_in_flight; 952 953 /** @handle: Returned heap handle. Passed back to DESTROY_TILER_HEAP. */ 954 __u32 handle; 955 956 /** @tiler_heap_ctx_gpu_va: Returned heap GPU virtual address returned */ 957 __u64 tiler_heap_ctx_gpu_va; 958 959 /** 960 * @first_heap_chunk_gpu_va: First heap chunk. 961 * 962 * The tiler heap is formed of heap chunks forming a single-link list. This 963 * is the first element in the list. 964 */ 965 __u64 first_heap_chunk_gpu_va; 966 }; 967 968 /** 969 * struct drm_panthor_tiler_heap_destroy - Arguments passed to DRM_IOCTL_PANTHOR_TILER_HEAP_DESTROY 970 */ 971 struct drm_panthor_tiler_heap_destroy { 972 /** 973 * @handle: Handle of the tiler heap to destroy. 974 * 975 * Must be a valid heap handle returned by DRM_IOCTL_PANTHOR_TILER_HEAP_CREATE. 976 */ 977 __u32 handle; 978 979 /** @pad: Padding field, MBZ. */ 980 __u32 pad; 981 }; 982 983 /** 984 * struct drm_panthor_bo_set_label - Arguments passed to DRM_IOCTL_PANTHOR_BO_SET_LABEL 985 */ 986 struct drm_panthor_bo_set_label { 987 /** @handle: Handle of the buffer object to label. */ 988 __u32 handle; 989 990 /** @pad: MBZ. */ 991 __u32 pad; 992 993 /** 994 * @label: User pointer to a NUL-terminated string 995 * 996 * Length cannot be greater than 4096 997 */ 998 __u64 label; 999 }; 1000 1001 /** 1002 * DRM_IOCTL_PANTHOR() - Build a Panthor IOCTL number 1003 * @__access: Access type. Must be R, W or RW. 1004 * @__id: One of the DRM_PANTHOR_xxx id. 1005 * @__type: Suffix of the type being passed to the IOCTL. 1006 * 1007 * Don't use this macro directly, use the DRM_IOCTL_PANTHOR_xxx 1008 * values instead. 1009 * 1010 * Return: An IOCTL number to be passed to ioctl() from userspace. 1011 */ 1012 #define DRM_IOCTL_PANTHOR(__access, __id, __type) \ 1013 DRM_IO ## __access(DRM_COMMAND_BASE + DRM_PANTHOR_ ## __id, \ 1014 struct drm_panthor_ ## __type) 1015 1016 enum { 1017 DRM_IOCTL_PANTHOR_DEV_QUERY = 1018 DRM_IOCTL_PANTHOR(WR, DEV_QUERY, dev_query), 1019 DRM_IOCTL_PANTHOR_VM_CREATE = 1020 DRM_IOCTL_PANTHOR(WR, VM_CREATE, vm_create), 1021 DRM_IOCTL_PANTHOR_VM_DESTROY = 1022 DRM_IOCTL_PANTHOR(WR, VM_DESTROY, vm_destroy), 1023 DRM_IOCTL_PANTHOR_VM_BIND = 1024 DRM_IOCTL_PANTHOR(WR, VM_BIND, vm_bind), 1025 DRM_IOCTL_PANTHOR_VM_GET_STATE = 1026 DRM_IOCTL_PANTHOR(WR, VM_GET_STATE, vm_get_state), 1027 DRM_IOCTL_PANTHOR_BO_CREATE = 1028 DRM_IOCTL_PANTHOR(WR, BO_CREATE, bo_create), 1029 DRM_IOCTL_PANTHOR_BO_MMAP_OFFSET = 1030 DRM_IOCTL_PANTHOR(WR, BO_MMAP_OFFSET, bo_mmap_offset), 1031 DRM_IOCTL_PANTHOR_GROUP_CREATE = 1032 DRM_IOCTL_PANTHOR(WR, GROUP_CREATE, group_create), 1033 DRM_IOCTL_PANTHOR_GROUP_DESTROY = 1034 DRM_IOCTL_PANTHOR(WR, GROUP_DESTROY, group_destroy), 1035 DRM_IOCTL_PANTHOR_GROUP_SUBMIT = 1036 DRM_IOCTL_PANTHOR(WR, GROUP_SUBMIT, group_submit), 1037 DRM_IOCTL_PANTHOR_GROUP_GET_STATE = 1038 DRM_IOCTL_PANTHOR(WR, GROUP_GET_STATE, group_get_state), 1039 DRM_IOCTL_PANTHOR_TILER_HEAP_CREATE = 1040 DRM_IOCTL_PANTHOR(WR, TILER_HEAP_CREATE, tiler_heap_create), 1041 DRM_IOCTL_PANTHOR_TILER_HEAP_DESTROY = 1042 DRM_IOCTL_PANTHOR(WR, TILER_HEAP_DESTROY, tiler_heap_destroy), 1043 DRM_IOCTL_PANTHOR_BO_SET_LABEL = 1044 DRM_IOCTL_PANTHOR(WR, BO_SET_LABEL, bo_set_label), 1045 }; 1046 1047 #if defined(__cplusplus) 1048 } 1049 #endif 1050 1051 #endif /* _PANTHOR_DRM_H_ */ 1052