1 /* amdgpu_drm.h -- Public header for the amdgpu driver -*- linux-c -*-
3 * Copyright 2000 Precision Insight, Inc., Cedar Park, Texas.
4 * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
5 * Copyright 2002 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Copyright 2014 Advanced Micro Devices, Inc.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included in
16 * all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
24 * OTHER DEALINGS IN THE SOFTWARE.
27 * Kevin E. Martin <martin@valinux.com>
28 * Gareth Hughes <gareth@valinux.com>
29 * Keith Whitwell <keith@tungstengraphics.com>
32 #ifndef __AMDGPU_DRM_H__
33 #define __AMDGPU_DRM_H__
37 #define DRM_AMDGPU_GEM_CREATE 0x00
38 #define DRM_AMDGPU_GEM_MMAP 0x01
39 #define DRM_AMDGPU_CTX 0x02
40 #define DRM_AMDGPU_BO_LIST 0x03
41 #define DRM_AMDGPU_CS 0x04
42 #define DRM_AMDGPU_INFO 0x05
43 #define DRM_AMDGPU_GEM_METADATA 0x06
44 #define DRM_AMDGPU_GEM_WAIT_IDLE 0x07
45 #define DRM_AMDGPU_GEM_VA 0x08
46 #define DRM_AMDGPU_WAIT_CS 0x09
47 #define DRM_AMDGPU_GEM_OP 0x10
48 #define DRM_AMDGPU_GEM_USERPTR 0x11
50 #define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
51 #define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
52 #define DRM_IOCTL_AMDGPU_CTX DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_CTX, union drm_amdgpu_ctx)
53 #define DRM_IOCTL_AMDGPU_BO_LIST DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_BO_LIST, union drm_amdgpu_bo_list)
54 #define DRM_IOCTL_AMDGPU_CS DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_CS, union drm_amdgpu_cs)
55 #define DRM_IOCTL_AMDGPU_INFO DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_INFO, struct drm_amdgpu_info)
56 #define DRM_IOCTL_AMDGPU_GEM_METADATA DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_METADATA, struct drm_amdgpu_gem_metadata)
57 #define DRM_IOCTL_AMDGPU_GEM_WAIT_IDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_WAIT_IDLE, union drm_amdgpu_gem_wait_idle)
58 #define DRM_IOCTL_AMDGPU_GEM_VA DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_VA, struct drm_amdgpu_gem_va)
59 #define DRM_IOCTL_AMDGPU_WAIT_CS DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_WAIT_CS, union drm_amdgpu_wait_cs)
60 #define DRM_IOCTL_AMDGPU_GEM_OP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_OP, struct drm_amdgpu_gem_op)
61 #define DRM_IOCTL_AMDGPU_GEM_USERPTR DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_USERPTR, struct drm_amdgpu_gem_userptr)
63 #define AMDGPU_GEM_DOMAIN_CPU 0x1
64 #define AMDGPU_GEM_DOMAIN_GTT 0x2
65 #define AMDGPU_GEM_DOMAIN_VRAM 0x4
66 #define AMDGPU_GEM_DOMAIN_GDS 0x8
67 #define AMDGPU_GEM_DOMAIN_GWS 0x10
68 #define AMDGPU_GEM_DOMAIN_OA 0x20
70 /* Flag that CPU access will be required for the case of VRAM domain */
71 #define AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED (1 << 0)
72 /* Flag that CPU access will not work, this VRAM domain is invisible */
73 #define AMDGPU_GEM_CREATE_NO_CPU_ACCESS (1 << 1)
74 /* Flag that USWC attributes should be used for GTT */
75 #define AMDGPU_GEM_CREATE_CPU_GTT_USWC (1 << 2)
76 /* Flag that the memory should be in VRAM and cleared */
77 #define AMDGPU_GEM_CREATE_VRAM_CLEARED (1 << 3)
79 struct drm_amdgpu_gem_create_in {
80 /** the requested memory size */
82 /** physical start_addr alignment in bytes for some HW requirements */
84 /** the requested memory domains */
86 /** allocation flags */
87 uint64_t domain_flags;
90 struct drm_amdgpu_gem_create_out {
91 /** returned GEM object handle */
96 union drm_amdgpu_gem_create {
97 struct drm_amdgpu_gem_create_in in;
98 struct drm_amdgpu_gem_create_out out;
101 /** Opcode to create new residency list. */
102 #define AMDGPU_BO_LIST_OP_CREATE 0
103 /** Opcode to destroy previously created residency list */
104 #define AMDGPU_BO_LIST_OP_DESTROY 1
105 /** Opcode to update resource information in the list */
106 #define AMDGPU_BO_LIST_OP_UPDATE 2
108 struct drm_amdgpu_bo_list_in {
109 /** Type of operation */
111 /** Handle of list or 0 if we want to create one */
112 uint32_t list_handle;
113 /** Number of BOs in list */
115 /** Size of each element describing BO */
116 uint32_t bo_info_size;
117 /** Pointer to array describing BOs */
118 uint64_t bo_info_ptr;
121 struct drm_amdgpu_bo_list_entry {
124 /** New (if specified) BO priority to be used during migration */
125 uint32_t bo_priority;
128 struct drm_amdgpu_bo_list_out {
129 /** Handle of resource list */
130 uint32_t list_handle;
134 union drm_amdgpu_bo_list {
135 struct drm_amdgpu_bo_list_in in;
136 struct drm_amdgpu_bo_list_out out;
139 /* context related */
140 #define AMDGPU_CTX_OP_ALLOC_CTX 1
141 #define AMDGPU_CTX_OP_FREE_CTX 2
142 #define AMDGPU_CTX_OP_QUERY_STATE 3
144 /* GPU reset status */
145 #define AMDGPU_CTX_NO_RESET 0
146 /* this the context caused it */
147 #define AMDGPU_CTX_GUILTY_RESET 1
148 /* some other context caused it */
149 #define AMDGPU_CTX_INNOCENT_RESET 2
151 #define AMDGPU_CTX_UNKNOWN_RESET 3
153 struct drm_amdgpu_ctx_in {
154 /** AMDGPU_CTX_OP_* */
156 /** For future use, no flags defined so far */
162 union drm_amdgpu_ctx_out {
169 /** For future use, no flags defined so far */
171 /** Number of resets caused by this context so far. */
173 /** Reset status since the last call of the ioctl. */
174 uint32_t reset_status;
178 union drm_amdgpu_ctx {
179 struct drm_amdgpu_ctx_in in;
180 union drm_amdgpu_ctx_out out;
184 * This is not a reliable API and you should expect it to fail for any
185 * number of reasons and have fallback path that do not use userptr to
186 * perform any operation.
188 #define AMDGPU_GEM_USERPTR_READONLY (1 << 0)
189 #define AMDGPU_GEM_USERPTR_ANONONLY (1 << 1)
190 #define AMDGPU_GEM_USERPTR_VALIDATE (1 << 2)
191 #define AMDGPU_GEM_USERPTR_REGISTER (1 << 3)
193 struct drm_amdgpu_gem_userptr {
196 /* AMDGPU_GEM_USERPTR_* */
198 /* Resulting GEM handle */
202 /* same meaning as the GB_TILE_MODE and GL_MACRO_TILE_MODE fields */
203 #define AMDGPU_TILING_ARRAY_MODE_SHIFT 0
204 #define AMDGPU_TILING_ARRAY_MODE_MASK 0xf
205 #define AMDGPU_TILING_PIPE_CONFIG_SHIFT 4
206 #define AMDGPU_TILING_PIPE_CONFIG_MASK 0x1f
207 #define AMDGPU_TILING_TILE_SPLIT_SHIFT 9
208 #define AMDGPU_TILING_TILE_SPLIT_MASK 0x7
209 #define AMDGPU_TILING_MICRO_TILE_MODE_SHIFT 12
210 #define AMDGPU_TILING_MICRO_TILE_MODE_MASK 0x7
211 #define AMDGPU_TILING_BANK_WIDTH_SHIFT 15
212 #define AMDGPU_TILING_BANK_WIDTH_MASK 0x3
213 #define AMDGPU_TILING_BANK_HEIGHT_SHIFT 17
214 #define AMDGPU_TILING_BANK_HEIGHT_MASK 0x3
215 #define AMDGPU_TILING_MACRO_TILE_ASPECT_SHIFT 19
216 #define AMDGPU_TILING_MACRO_TILE_ASPECT_MASK 0x3
217 #define AMDGPU_TILING_NUM_BANKS_SHIFT 21
218 #define AMDGPU_TILING_NUM_BANKS_MASK 0x3
220 #define AMDGPU_TILING_SET(field, value) \
221 (((value) & AMDGPU_TILING_##field##_MASK) << AMDGPU_TILING_##field##_SHIFT)
222 #define AMDGPU_TILING_GET(value, field) \
223 (((value) >> AMDGPU_TILING_##field##_SHIFT) & AMDGPU_TILING_##field##_MASK)
225 #define AMDGPU_GEM_METADATA_OP_SET_METADATA 1
226 #define AMDGPU_GEM_METADATA_OP_GET_METADATA 2
228 /** The same structure is shared for input/output */
229 struct drm_amdgpu_gem_metadata {
230 /** GEM Object handle */
232 /** Do we want get or set metadata */
235 /** For future use, no flags defined so far */
237 /** family specific tiling info */
238 uint64_t tiling_info;
239 uint32_t data_size_bytes;
244 struct drm_amdgpu_gem_mmap_in {
245 /** the GEM object handle */
250 struct drm_amdgpu_gem_mmap_out {
251 /** mmap offset from the vma offset manager */
255 union drm_amdgpu_gem_mmap {
256 struct drm_amdgpu_gem_mmap_in in;
257 struct drm_amdgpu_gem_mmap_out out;
260 struct drm_amdgpu_gem_wait_idle_in {
261 /** GEM object handle */
263 /** For future use, no flags defined so far */
265 /** Absolute timeout to wait */
269 struct drm_amdgpu_gem_wait_idle_out {
270 /** BO status: 0 - BO is idle, 1 - BO is busy */
272 /** Returned current memory domain */
276 union drm_amdgpu_gem_wait_idle {
277 struct drm_amdgpu_gem_wait_idle_in in;
278 struct drm_amdgpu_gem_wait_idle_out out;
281 struct drm_amdgpu_wait_cs_in {
282 /** Command submission handle */
284 /** Absolute timeout to wait */
287 uint32_t ip_instance;
292 struct drm_amdgpu_wait_cs_out {
293 /** CS status: 0 - CS completed, 1 - CS still busy */
297 union drm_amdgpu_wait_cs {
298 struct drm_amdgpu_wait_cs_in in;
299 struct drm_amdgpu_wait_cs_out out;
302 #define AMDGPU_GEM_OP_GET_GEM_CREATE_INFO 0
303 #define AMDGPU_GEM_OP_SET_PLACEMENT 1
305 /* Sets or returns a value associated with a buffer. */
306 struct drm_amdgpu_gem_op {
307 /** GEM object handle */
309 /** AMDGPU_GEM_OP_* */
311 /** Input or return value */
315 #define AMDGPU_VA_OP_MAP 1
316 #define AMDGPU_VA_OP_UNMAP 2
318 /* Delay the page table update till the next CS */
319 #define AMDGPU_VM_DELAY_UPDATE (1 << 0)
322 /* readable mapping */
323 #define AMDGPU_VM_PAGE_READABLE (1 << 1)
324 /* writable mapping */
325 #define AMDGPU_VM_PAGE_WRITEABLE (1 << 2)
326 /* executable mapping, new for VI */
327 #define AMDGPU_VM_PAGE_EXECUTABLE (1 << 3)
329 struct drm_amdgpu_gem_va {
330 /** GEM object handle */
333 /** AMDGPU_VA_OP_* */
335 /** AMDGPU_VM_PAGE_* */
337 /** va address to assign . Must be correctly aligned.*/
339 /** Specify offset inside of BO to assign. Must be correctly aligned.*/
340 uint64_t offset_in_bo;
341 /** Specify mapping size. Must be correctly aligned. */
345 #define AMDGPU_HW_IP_GFX 0
346 #define AMDGPU_HW_IP_COMPUTE 1
347 #define AMDGPU_HW_IP_DMA 2
348 #define AMDGPU_HW_IP_UVD 3
349 #define AMDGPU_HW_IP_VCE 4
350 #define AMDGPU_HW_IP_NUM 5
352 #define AMDGPU_HW_IP_INSTANCE_MAX_COUNT 1
354 #define AMDGPU_CHUNK_ID_IB 0x01
355 #define AMDGPU_CHUNK_ID_FENCE 0x02
356 #define AMDGPU_CHUNK_ID_DEPENDENCIES 0x03
358 struct drm_amdgpu_cs_chunk {
364 struct drm_amdgpu_cs_in {
365 /** Rendering context id */
367 /** Handle of resource list associated with CS */
368 uint32_t bo_list_handle;
371 /** this points to uint64_t * which point to cs chunks */
375 struct drm_amdgpu_cs_out {
379 union drm_amdgpu_cs {
380 struct drm_amdgpu_cs_in in;
381 struct drm_amdgpu_cs_out out;
384 /* Specify flags to be used for IB */
386 /* This IB should be submitted to CE */
387 #define AMDGPU_IB_FLAG_CE (1<<0)
390 #define AMDGPU_IB_FLAG_PREAMBLE (1<<1)
392 struct drm_amdgpu_cs_chunk_ib {
394 /** AMDGPU_IB_FLAG_* */
396 /** Virtual address to begin IB execution */
398 /** Size of submission */
400 /** HW IP to submit to */
402 /** HW IP index of the same type to submit to */
403 uint32_t ip_instance;
404 /** Ring index to submit to */
408 struct drm_amdgpu_cs_chunk_dep {
410 uint32_t ip_instance;
416 struct drm_amdgpu_cs_chunk_fence {
421 struct drm_amdgpu_cs_chunk_data {
423 struct drm_amdgpu_cs_chunk_ib ib_data;
424 struct drm_amdgpu_cs_chunk_fence fence_data;
429 * Query h/w info: Flag that this is integrated (a.h.a. fusion) GPU
432 #define AMDGPU_IDS_FLAGS_FUSION 0x1
434 /* indicate if acceleration can be working */
435 #define AMDGPU_INFO_ACCEL_WORKING 0x00
436 /* get the crtc_id from the mode object id? */
437 #define AMDGPU_INFO_CRTC_FROM_ID 0x01
438 /* query hw IP info */
439 #define AMDGPU_INFO_HW_IP_INFO 0x02
440 /* query hw IP instance count for the specified type */
441 #define AMDGPU_INFO_HW_IP_COUNT 0x03
442 /* timestamp for GL_ARB_timer_query */
443 #define AMDGPU_INFO_TIMESTAMP 0x05
444 /* Query the firmware version */
445 #define AMDGPU_INFO_FW_VERSION 0x0e
446 /* Subquery id: Query VCE firmware version */
447 #define AMDGPU_INFO_FW_VCE 0x1
448 /* Subquery id: Query UVD firmware version */
449 #define AMDGPU_INFO_FW_UVD 0x2
450 /* Subquery id: Query GMC firmware version */
451 #define AMDGPU_INFO_FW_GMC 0x03
452 /* Subquery id: Query GFX ME firmware version */
453 #define AMDGPU_INFO_FW_GFX_ME 0x04
454 /* Subquery id: Query GFX PFP firmware version */
455 #define AMDGPU_INFO_FW_GFX_PFP 0x05
456 /* Subquery id: Query GFX CE firmware version */
457 #define AMDGPU_INFO_FW_GFX_CE 0x06
458 /* Subquery id: Query GFX RLC firmware version */
459 #define AMDGPU_INFO_FW_GFX_RLC 0x07
460 /* Subquery id: Query GFX MEC firmware version */
461 #define AMDGPU_INFO_FW_GFX_MEC 0x08
462 /* Subquery id: Query SMC firmware version */
463 #define AMDGPU_INFO_FW_SMC 0x0a
464 /* Subquery id: Query SDMA firmware version */
465 #define AMDGPU_INFO_FW_SDMA 0x0b
466 /* number of bytes moved for TTM migration */
467 #define AMDGPU_INFO_NUM_BYTES_MOVED 0x0f
468 /* the used VRAM size */
469 #define AMDGPU_INFO_VRAM_USAGE 0x10
470 /* the used GTT size */
471 #define AMDGPU_INFO_GTT_USAGE 0x11
472 /* Information about GDS, etc. resource configuration */
473 #define AMDGPU_INFO_GDS_CONFIG 0x13
474 /* Query information about VRAM and GTT domains */
475 #define AMDGPU_INFO_VRAM_GTT 0x14
476 /* Query information about register in MMR address space*/
477 #define AMDGPU_INFO_READ_MMR_REG 0x15
478 /* Query information about device: rev id, family, etc. */
479 #define AMDGPU_INFO_DEV_INFO 0x16
480 /* visible vram usage */
481 #define AMDGPU_INFO_VIS_VRAM_USAGE 0x17
483 #define AMDGPU_INFO_MMR_SE_INDEX_SHIFT 0
484 #define AMDGPU_INFO_MMR_SE_INDEX_MASK 0xff
485 #define AMDGPU_INFO_MMR_SH_INDEX_SHIFT 8
486 #define AMDGPU_INFO_MMR_SH_INDEX_MASK 0xff
488 /* Input structure for the INFO ioctl */
489 struct drm_amdgpu_info {
490 /* Where the return value will be stored */
491 uint64_t return_pointer;
492 /* The size of the return value. Just like "size" in "snprintf",
493 * it limits how many bytes the kernel can write. */
494 uint32_t return_size;
495 /* The query request id. */
505 /** AMDGPU_HW_IP_* */
508 * Index of the IP if there are more IPs of the same
509 * type. Ignored by AMDGPU_INFO_HW_IP_COUNT.
511 uint32_t ip_instance;
515 uint32_t dword_offset;
516 /** number of registers to read */
519 /** For future use, no flags defined so far */
524 /** AMDGPU_INFO_FW_* */
527 * Index of the IP if there are more IPs of
530 uint32_t ip_instance;
532 * Index of the engine. Whether this is used depends
533 * on the firmware type. (e.g. MEC, SDMA)
541 struct drm_amdgpu_info_gds {
542 /** GDS GFX partition size */
543 uint32_t gds_gfx_partition_size;
544 /** GDS compute partition size */
545 uint32_t compute_partition_size;
546 /** total GDS memory size */
547 uint32_t gds_total_size;
548 /** GWS size per GFX partition */
549 uint32_t gws_per_gfx_partition;
550 /** GSW size per compute partition */
551 uint32_t gws_per_compute_partition;
552 /** OA size per GFX partition */
553 uint32_t oa_per_gfx_partition;
554 /** OA size per compute partition */
555 uint32_t oa_per_compute_partition;
559 struct drm_amdgpu_info_vram_gtt {
561 uint64_t vram_cpu_accessible_size;
565 struct drm_amdgpu_info_firmware {
570 #define AMDGPU_VRAM_TYPE_UNKNOWN 0
571 #define AMDGPU_VRAM_TYPE_GDDR1 1
572 #define AMDGPU_VRAM_TYPE_DDR2 2
573 #define AMDGPU_VRAM_TYPE_GDDR3 3
574 #define AMDGPU_VRAM_TYPE_GDDR4 4
575 #define AMDGPU_VRAM_TYPE_GDDR5 5
576 #define AMDGPU_VRAM_TYPE_HBM 6
577 #define AMDGPU_VRAM_TYPE_DDR3 7
579 struct drm_amdgpu_info_device {
582 /** Internal chip revision: A0, A1, etc.) */
584 uint32_t external_rev;
585 /** Revision id in PCI Config space */
588 uint32_t num_shader_engines;
589 uint32_t num_shader_arrays_per_engine;
591 uint32_t gpu_counter_freq;
592 uint64_t max_engine_clock;
593 uint64_t max_memory_clock;
595 uint32_t cu_active_number;
597 uint32_t cu_bitmap[4][4];
598 /** Render backend pipe mask. One render backend is CB+DB. */
599 uint32_t enabled_rb_pipes_mask;
600 uint32_t num_rb_pipes;
601 uint32_t num_hw_gfx_contexts;
604 /** Starting virtual address for UMDs. */
605 uint64_t virtual_address_offset;
606 /** The maximum virtual address */
607 uint64_t virtual_address_max;
608 /** Required alignment of virtual addresses. */
609 uint32_t virtual_address_alignment;
610 /** Page table entry - fragment size */
611 uint32_t pte_fragment_size;
612 uint32_t gart_page_size;
613 /** constant engine ram size*/
614 uint32_t ce_ram_size;
615 /** video memory type info*/
617 /** video memory bit width*/
618 uint32_t vram_bit_width;
619 /* vce harvesting instance */
620 uint32_t vce_harvest_config;
623 struct drm_amdgpu_info_hw_ip {
624 /** Version of h/w IP */
625 uint32_t hw_ip_version_major;
626 uint32_t hw_ip_version_minor;
628 uint64_t capabilities_flags;
629 /** command buffer address start alignment*/
630 uint32_t ib_start_alignment;
631 /** command buffer size alignment*/
632 uint32_t ib_size_alignment;
633 /** Bitmask of available rings. Bit 0 means ring 0, etc. */
634 uint32_t available_rings;
639 * Supported GPU families
641 #define AMDGPU_FAMILY_UNKNOWN 0
642 #define AMDGPU_FAMILY_CI 120 /* Bonaire, Hawaii */
643 #define AMDGPU_FAMILY_KV 125 /* Kaveri, Kabini, Mullins */
644 #define AMDGPU_FAMILY_VI 130 /* Iceland, Tonga */
645 #define AMDGPU_FAMILY_CZ 135 /* Carrizo */