OSDN Git Service

fa56499f94de8988ef321a1a41146ba6af31841a
[android-x86/external-libdrm.git] / include / drm / amdgpu_drm.h
1 /* amdgpu_drm.h -- Public header for the amdgpu driver -*- linux-c -*-
2  *
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.
7  *
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:
14  *
15  * The above copyright notice and this permission notice shall be included in
16  * all copies or substantial portions of the Software.
17  *
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.
25  *
26  * Authors:
27  *    Kevin E. Martin <martin@valinux.com>
28  *    Gareth Hughes <gareth@valinux.com>
29  *    Keith Whitwell <keith@tungstengraphics.com>
30  */
31
32 #ifndef __AMDGPU_DRM_H__
33 #define __AMDGPU_DRM_H__
34
35 #include "drm.h"
36
37 #if defined(__cplusplus)
38 extern "C" {
39 #endif
40
41 #define DRM_AMDGPU_GEM_CREATE           0x00
42 #define DRM_AMDGPU_GEM_MMAP             0x01
43 #define DRM_AMDGPU_CTX                  0x02
44 #define DRM_AMDGPU_BO_LIST              0x03
45 #define DRM_AMDGPU_CS                   0x04
46 #define DRM_AMDGPU_INFO                 0x05
47 #define DRM_AMDGPU_GEM_METADATA         0x06
48 #define DRM_AMDGPU_GEM_WAIT_IDLE        0x07
49 #define DRM_AMDGPU_GEM_VA               0x08
50 #define DRM_AMDGPU_WAIT_CS              0x09
51 #define DRM_AMDGPU_GEM_OP               0x10
52 #define DRM_AMDGPU_GEM_USERPTR          0x11
53 #define DRM_AMDGPU_WAIT_FENCES          0x12
54
55 #define DRM_IOCTL_AMDGPU_GEM_CREATE     DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
56 #define DRM_IOCTL_AMDGPU_GEM_MMAP       DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
57 #define DRM_IOCTL_AMDGPU_CTX            DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_CTX, union drm_amdgpu_ctx)
58 #define DRM_IOCTL_AMDGPU_BO_LIST        DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_BO_LIST, union drm_amdgpu_bo_list)
59 #define DRM_IOCTL_AMDGPU_CS             DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_CS, union drm_amdgpu_cs)
60 #define DRM_IOCTL_AMDGPU_INFO           DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_INFO, struct drm_amdgpu_info)
61 #define DRM_IOCTL_AMDGPU_GEM_METADATA   DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_METADATA, struct drm_amdgpu_gem_metadata)
62 #define DRM_IOCTL_AMDGPU_GEM_WAIT_IDLE  DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_WAIT_IDLE, union drm_amdgpu_gem_wait_idle)
63 #define DRM_IOCTL_AMDGPU_GEM_VA         DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_VA, struct drm_amdgpu_gem_va)
64 #define DRM_IOCTL_AMDGPU_WAIT_CS        DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_WAIT_CS, union drm_amdgpu_wait_cs)
65 #define DRM_IOCTL_AMDGPU_GEM_OP         DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_OP, struct drm_amdgpu_gem_op)
66 #define DRM_IOCTL_AMDGPU_GEM_USERPTR    DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_USERPTR, struct drm_amdgpu_gem_userptr)
67 #define DRM_IOCTL_AMDGPU_WAIT_FENCES    DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_WAIT_FENCES, union drm_amdgpu_wait_fences)
68
69 #define AMDGPU_GEM_DOMAIN_CPU           0x1
70 #define AMDGPU_GEM_DOMAIN_GTT           0x2
71 #define AMDGPU_GEM_DOMAIN_VRAM          0x4
72 #define AMDGPU_GEM_DOMAIN_GDS           0x8
73 #define AMDGPU_GEM_DOMAIN_GWS           0x10
74 #define AMDGPU_GEM_DOMAIN_OA            0x20
75
76 /* Flag that CPU access will be required for the case of VRAM domain */
77 #define AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED   (1 << 0)
78 /* Flag that CPU access will not work, this VRAM domain is invisible */
79 #define AMDGPU_GEM_CREATE_NO_CPU_ACCESS         (1 << 1)
80 /* Flag that USWC attributes should be used for GTT */
81 #define AMDGPU_GEM_CREATE_CPU_GTT_USWC          (1 << 2)
82 /* Flag that the memory should be in VRAM and cleared */
83 #define AMDGPU_GEM_CREATE_VRAM_CLEARED          (1 << 3)
84 /* Flag that create shadow bo(GTT) while allocating vram bo */
85 #define AMDGPU_GEM_CREATE_SHADOW                (1 << 4)
86 /* Flag that allocating the BO should use linear VRAM */
87 #define AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS       (1 << 5)
88
89 struct drm_amdgpu_gem_create_in  {
90         /** the requested memory size */
91         __u64 bo_size;
92         /** physical start_addr alignment in bytes for some HW requirements */
93         __u64 alignment;
94         /** the requested memory domains */
95         __u64 domains;
96         /** allocation flags */
97         __u64 domain_flags;
98 };
99
100 struct drm_amdgpu_gem_create_out  {
101         /** returned GEM object handle */
102         __u32 handle;
103         __u32 _pad;
104 };
105
106 union drm_amdgpu_gem_create {
107         struct drm_amdgpu_gem_create_in         in;
108         struct drm_amdgpu_gem_create_out        out;
109 };
110
111 /** Opcode to create new residency list.  */
112 #define AMDGPU_BO_LIST_OP_CREATE        0
113 /** Opcode to destroy previously created residency list */
114 #define AMDGPU_BO_LIST_OP_DESTROY       1
115 /** Opcode to update resource information in the list */
116 #define AMDGPU_BO_LIST_OP_UPDATE        2
117
118 struct drm_amdgpu_bo_list_in {
119         /** Type of operation */
120         __u32 operation;
121         /** Handle of list or 0 if we want to create one */
122         __u32 list_handle;
123         /** Number of BOs in list  */
124         __u32 bo_number;
125         /** Size of each element describing BO */
126         __u32 bo_info_size;
127         /** Pointer to array describing BOs */
128         __u64 bo_info_ptr;
129 };
130
131 struct drm_amdgpu_bo_list_entry {
132         /** Handle of BO */
133         __u32 bo_handle;
134         /** New (if specified) BO priority to be used during migration */
135         __u32 bo_priority;
136 };
137
138 struct drm_amdgpu_bo_list_out {
139         /** Handle of resource list  */
140         __u32 list_handle;
141         __u32 _pad;
142 };
143
144 union drm_amdgpu_bo_list {
145         struct drm_amdgpu_bo_list_in in;
146         struct drm_amdgpu_bo_list_out out;
147 };
148
149 /* context related */
150 #define AMDGPU_CTX_OP_ALLOC_CTX 1
151 #define AMDGPU_CTX_OP_FREE_CTX  2
152 #define AMDGPU_CTX_OP_QUERY_STATE       3
153
154 /* GPU reset status */
155 #define AMDGPU_CTX_NO_RESET             0
156 /* this the context caused it */
157 #define AMDGPU_CTX_GUILTY_RESET         1
158 /* some other context caused it */
159 #define AMDGPU_CTX_INNOCENT_RESET       2
160 /* unknown cause */
161 #define AMDGPU_CTX_UNKNOWN_RESET        3
162
163 struct drm_amdgpu_ctx_in {
164         /** AMDGPU_CTX_OP_* */
165         __u32   op;
166         /** For future use, no flags defined so far */
167         __u32   flags;
168         __u32   ctx_id;
169         __u32   _pad;
170 };
171
172 union drm_amdgpu_ctx_out {
173                 struct {
174                         __u32   ctx_id;
175                         __u32   _pad;
176                 } alloc;
177
178                 struct {
179                         /** For future use, no flags defined so far */
180                         __u64   flags;
181                         /** Number of resets caused by this context so far. */
182                         __u32   hangs;
183                         /** Reset status since the last call of the ioctl. */
184                         __u32   reset_status;
185                 } state;
186 };
187
188 union drm_amdgpu_ctx {
189         struct drm_amdgpu_ctx_in in;
190         union drm_amdgpu_ctx_out out;
191 };
192
193 /*
194  * This is not a reliable API and you should expect it to fail for any
195  * number of reasons and have fallback path that do not use userptr to
196  * perform any operation.
197  */
198 #define AMDGPU_GEM_USERPTR_READONLY     (1 << 0)
199 #define AMDGPU_GEM_USERPTR_ANONONLY     (1 << 1)
200 #define AMDGPU_GEM_USERPTR_VALIDATE     (1 << 2)
201 #define AMDGPU_GEM_USERPTR_REGISTER     (1 << 3)
202
203 struct drm_amdgpu_gem_userptr {
204         __u64           addr;
205         __u64           size;
206         /* AMDGPU_GEM_USERPTR_* */
207         __u32           flags;
208         /* Resulting GEM handle */
209         __u32           handle;
210 };
211
212 /* SI-CI-VI: */
213 /* same meaning as the GB_TILE_MODE and GL_MACRO_TILE_MODE fields */
214 #define AMDGPU_TILING_ARRAY_MODE_SHIFT                  0
215 #define AMDGPU_TILING_ARRAY_MODE_MASK                   0xf
216 #define AMDGPU_TILING_PIPE_CONFIG_SHIFT                 4
217 #define AMDGPU_TILING_PIPE_CONFIG_MASK                  0x1f
218 #define AMDGPU_TILING_TILE_SPLIT_SHIFT                  9
219 #define AMDGPU_TILING_TILE_SPLIT_MASK                   0x7
220 #define AMDGPU_TILING_MICRO_TILE_MODE_SHIFT             12
221 #define AMDGPU_TILING_MICRO_TILE_MODE_MASK              0x7
222 #define AMDGPU_TILING_BANK_WIDTH_SHIFT                  15
223 #define AMDGPU_TILING_BANK_WIDTH_MASK                   0x3
224 #define AMDGPU_TILING_BANK_HEIGHT_SHIFT                 17
225 #define AMDGPU_TILING_BANK_HEIGHT_MASK                  0x3
226 #define AMDGPU_TILING_MACRO_TILE_ASPECT_SHIFT           19
227 #define AMDGPU_TILING_MACRO_TILE_ASPECT_MASK            0x3
228 #define AMDGPU_TILING_NUM_BANKS_SHIFT                   21
229 #define AMDGPU_TILING_NUM_BANKS_MASK                    0x3
230
231 /* GFX9 and later: */
232 #define AMDGPU_TILING_SWIZZLE_MODE_SHIFT                0
233 #define AMDGPU_TILING_SWIZZLE_MODE_MASK                 0x1f
234
235 #define AMDGPU_TILING_SET(field, value) \
236         (((__u64)(value) & AMDGPU_TILING_##field##_MASK) << AMDGPU_TILING_##field##_SHIFT)
237 #define AMDGPU_TILING_GET(value, field) \
238         (((__u64)(value) >> AMDGPU_TILING_##field##_SHIFT) & AMDGPU_TILING_##field##_MASK)
239
240 #define AMDGPU_GEM_METADATA_OP_SET_METADATA                  1
241 #define AMDGPU_GEM_METADATA_OP_GET_METADATA                  2
242
243 /** The same structure is shared for input/output */
244 struct drm_amdgpu_gem_metadata {
245         /** GEM Object handle */
246         __u32   handle;
247         /** Do we want get or set metadata */
248         __u32   op;
249         struct {
250                 /** For future use, no flags defined so far */
251                 __u64   flags;
252                 /** family specific tiling info */
253                 __u64   tiling_info;
254                 __u32   data_size_bytes;
255                 __u32   data[64];
256         } data;
257 };
258
259 struct drm_amdgpu_gem_mmap_in {
260         /** the GEM object handle */
261         __u32 handle;
262         __u32 _pad;
263 };
264
265 struct drm_amdgpu_gem_mmap_out {
266         /** mmap offset from the vma offset manager */
267         __u64 addr_ptr;
268 };
269
270 union drm_amdgpu_gem_mmap {
271         struct drm_amdgpu_gem_mmap_in   in;
272         struct drm_amdgpu_gem_mmap_out out;
273 };
274
275 struct drm_amdgpu_gem_wait_idle_in {
276         /** GEM object handle */
277         __u32 handle;
278         /** For future use, no flags defined so far */
279         __u32 flags;
280         /** Absolute timeout to wait */
281         __u64 timeout;
282 };
283
284 struct drm_amdgpu_gem_wait_idle_out {
285         /** BO status:  0 - BO is idle, 1 - BO is busy */
286         __u32 status;
287         /** Returned current memory domain */
288         __u32 domain;
289 };
290
291 union drm_amdgpu_gem_wait_idle {
292         struct drm_amdgpu_gem_wait_idle_in  in;
293         struct drm_amdgpu_gem_wait_idle_out out;
294 };
295
296 struct drm_amdgpu_wait_cs_in {
297         /** Command submission handle */
298         __u64 handle;
299         /** Absolute timeout to wait */
300         __u64 timeout;
301         __u32 ip_type;
302         __u32 ip_instance;
303         __u32 ring;
304         __u32 ctx_id;
305 };
306
307 struct drm_amdgpu_wait_cs_out {
308         /** CS status:  0 - CS completed, 1 - CS still busy */
309         __u64 status;
310 };
311
312 union drm_amdgpu_wait_cs {
313         struct drm_amdgpu_wait_cs_in in;
314         struct drm_amdgpu_wait_cs_out out;
315 };
316
317 struct drm_amdgpu_fence {
318         __u32 ctx_id;
319         __u32 ip_type;
320         __u32 ip_instance;
321         __u32 ring;
322         __u64 seq_no;
323 };
324
325 struct drm_amdgpu_wait_fences_in {
326         /** This points to uint64_t * which points to fences */
327         __u64 fences;
328         __u32 fence_count;
329         __u32 wait_all;
330         __u64 timeout_ns;
331 };
332
333 struct drm_amdgpu_wait_fences_out {
334         __u32 status;
335         __u32 first_signaled;
336 };
337
338 union drm_amdgpu_wait_fences {
339         struct drm_amdgpu_wait_fences_in in;
340         struct drm_amdgpu_wait_fences_out out;
341 };
342
343 #define AMDGPU_GEM_OP_GET_GEM_CREATE_INFO       0
344 #define AMDGPU_GEM_OP_SET_PLACEMENT             1
345
346 /* Sets or returns a value associated with a buffer. */
347 struct drm_amdgpu_gem_op {
348         /** GEM object handle */
349         __u32   handle;
350         /** AMDGPU_GEM_OP_* */
351         __u32   op;
352         /** Input or return value */
353         __u64   value;
354 };
355
356 #define AMDGPU_VA_OP_MAP                        1
357 #define AMDGPU_VA_OP_UNMAP                      2
358
359 /* Delay the page table update till the next CS */
360 #define AMDGPU_VM_DELAY_UPDATE          (1 << 0)
361
362 /* Mapping flags */
363 /* readable mapping */
364 #define AMDGPU_VM_PAGE_READABLE         (1 << 1)
365 /* writable mapping */
366 #define AMDGPU_VM_PAGE_WRITEABLE        (1 << 2)
367 /* executable mapping, new for VI */
368 #define AMDGPU_VM_PAGE_EXECUTABLE       (1 << 3)
369
370 struct drm_amdgpu_gem_va {
371         /** GEM object handle */
372         __u32 handle;
373         __u32 _pad;
374         /** AMDGPU_VA_OP_* */
375         __u32 operation;
376         /** AMDGPU_VM_PAGE_* */
377         __u32 flags;
378         /** va address to assign . Must be correctly aligned.*/
379         __u64 va_address;
380         /** Specify offset inside of BO to assign. Must be correctly aligned.*/
381         __u64 offset_in_bo;
382         /** Specify mapping size. Must be correctly aligned. */
383         __u64 map_size;
384 };
385
386 #define AMDGPU_HW_IP_GFX          0
387 #define AMDGPU_HW_IP_COMPUTE      1
388 #define AMDGPU_HW_IP_DMA          2
389 #define AMDGPU_HW_IP_UVD          3
390 #define AMDGPU_HW_IP_VCE          4
391 #define AMDGPU_HW_IP_UVD_ENC      5
392 #define AMDGPU_HW_IP_NUM          6
393
394 #define AMDGPU_HW_IP_INSTANCE_MAX_COUNT 1
395
396 #define AMDGPU_CHUNK_ID_IB              0x01
397 #define AMDGPU_CHUNK_ID_FENCE           0x02
398 #define AMDGPU_CHUNK_ID_DEPENDENCIES    0x03
399
400 struct drm_amdgpu_cs_chunk {
401         __u32           chunk_id;
402         __u32           length_dw;
403         __u64           chunk_data;
404 };
405
406 struct drm_amdgpu_cs_in {
407         /** Rendering context id */
408         __u32           ctx_id;
409         /**  Handle of resource list associated with CS */
410         __u32           bo_list_handle;
411         __u32           num_chunks;
412         __u32           _pad;
413         /** this points to __u64 * which point to cs chunks */
414         __u64           chunks;
415 };
416
417 struct drm_amdgpu_cs_out {
418         __u64 handle;
419 };
420
421 union drm_amdgpu_cs {
422         struct drm_amdgpu_cs_in in;
423         struct drm_amdgpu_cs_out out;
424 };
425
426 /* Specify flags to be used for IB */
427
428 /* This IB should be submitted to CE */
429 #define AMDGPU_IB_FLAG_CE       (1<<0)
430
431 /* CE Preamble */
432 #define AMDGPU_IB_FLAG_PREAMBLE (1<<1)
433
434 struct drm_amdgpu_cs_chunk_ib {
435         __u32 _pad;
436         /** AMDGPU_IB_FLAG_* */
437         __u32 flags;
438         /** Virtual address to begin IB execution */
439         __u64 va_start;
440         /** Size of submission */
441         __u32 ib_bytes;
442         /** HW IP to submit to */
443         __u32 ip_type;
444         /** HW IP index of the same type to submit to  */
445         __u32 ip_instance;
446         /** Ring index to submit to */
447         __u32 ring;
448 };
449
450 struct drm_amdgpu_cs_chunk_dep {
451         __u32 ip_type;
452         __u32 ip_instance;
453         __u32 ring;
454         __u32 ctx_id;
455         __u64 handle;
456 };
457
458 struct drm_amdgpu_cs_chunk_fence {
459         __u32 handle;
460         __u32 offset;
461 };
462
463 struct drm_amdgpu_cs_chunk_data {
464         union {
465                 struct drm_amdgpu_cs_chunk_ib           ib_data;
466                 struct drm_amdgpu_cs_chunk_fence        fence_data;
467         };
468 };
469
470 /**
471  *  Query h/w info: Flag that this is integrated (a.h.a. fusion) GPU
472  *
473  */
474 #define AMDGPU_IDS_FLAGS_FUSION         0x1
475 #define AMDGPU_IDS_FLAGS_PREEMPTION     0x2
476
477 /* indicate if acceleration can be working */
478 #define AMDGPU_INFO_ACCEL_WORKING               0x00
479 /* get the crtc_id from the mode object id? */
480 #define AMDGPU_INFO_CRTC_FROM_ID                0x01
481 /* query hw IP info */
482 #define AMDGPU_INFO_HW_IP_INFO                  0x02
483 /* query hw IP instance count for the specified type */
484 #define AMDGPU_INFO_HW_IP_COUNT                 0x03
485 /* timestamp for GL_ARB_timer_query */
486 #define AMDGPU_INFO_TIMESTAMP                   0x05
487 /* Query the firmware version */
488 #define AMDGPU_INFO_FW_VERSION                  0x0e
489         /* Subquery id: Query VCE firmware version */
490         #define AMDGPU_INFO_FW_VCE              0x1
491         /* Subquery id: Query UVD firmware version */
492         #define AMDGPU_INFO_FW_UVD              0x2
493         /* Subquery id: Query GMC firmware version */
494         #define AMDGPU_INFO_FW_GMC              0x03
495         /* Subquery id: Query GFX ME firmware version */
496         #define AMDGPU_INFO_FW_GFX_ME           0x04
497         /* Subquery id: Query GFX PFP firmware version */
498         #define AMDGPU_INFO_FW_GFX_PFP          0x05
499         /* Subquery id: Query GFX CE firmware version */
500         #define AMDGPU_INFO_FW_GFX_CE           0x06
501         /* Subquery id: Query GFX RLC firmware version */
502         #define AMDGPU_INFO_FW_GFX_RLC          0x07
503         /* Subquery id: Query GFX MEC firmware version */
504         #define AMDGPU_INFO_FW_GFX_MEC          0x08
505         /* Subquery id: Query SMC firmware version */
506         #define AMDGPU_INFO_FW_SMC              0x0a
507         /* Subquery id: Query SDMA firmware version */
508         #define AMDGPU_INFO_FW_SDMA             0x0b
509 /* number of bytes moved for TTM migration */
510 #define AMDGPU_INFO_NUM_BYTES_MOVED             0x0f
511 /* the used VRAM size */
512 #define AMDGPU_INFO_VRAM_USAGE                  0x10
513 /* the used GTT size */
514 #define AMDGPU_INFO_GTT_USAGE                   0x11
515 /* Information about GDS, etc. resource configuration */
516 #define AMDGPU_INFO_GDS_CONFIG                  0x13
517 /* Query information about VRAM and GTT domains */
518 #define AMDGPU_INFO_VRAM_GTT                    0x14
519 /* Query information about register in MMR address space*/
520 #define AMDGPU_INFO_READ_MMR_REG                0x15
521 /* Query information about device: rev id, family, etc. */
522 #define AMDGPU_INFO_DEV_INFO                    0x16
523 /* visible vram usage */
524 #define AMDGPU_INFO_VIS_VRAM_USAGE              0x17
525 /* number of TTM buffer evictions */
526 #define AMDGPU_INFO_NUM_EVICTIONS               0x18
527 /* Query memory about VRAM and GTT domains */
528 #define AMDGPU_INFO_MEMORY                      0x19
529 /* Query vce clock table */
530 #define AMDGPU_INFO_VCE_CLOCK_TABLE             0x1A
531 /* Query vbios related information */
532 #define AMDGPU_INFO_VBIOS                       0x1B
533         /* Subquery id: Query vbios size */
534         #define AMDGPU_INFO_VBIOS_SIZE          0x1
535         /* Subquery id: Query vbios image */
536         #define AMDGPU_INFO_VBIOS_IMAGE         0x2
537 /* Query UVD handles */
538 #define AMDGPU_INFO_NUM_HANDLES                 0x1C
539
540 #define AMDGPU_INFO_MMR_SE_INDEX_SHIFT  0
541 #define AMDGPU_INFO_MMR_SE_INDEX_MASK   0xff
542 #define AMDGPU_INFO_MMR_SH_INDEX_SHIFT  8
543 #define AMDGPU_INFO_MMR_SH_INDEX_MASK   0xff
544
545 struct drm_amdgpu_query_fw {
546         /** AMDGPU_INFO_FW_* */
547         __u32 fw_type;
548         /**
549          * Index of the IP if there are more IPs of
550          * the same type.
551          */
552         __u32 ip_instance;
553         /**
554          * Index of the engine. Whether this is used depends
555          * on the firmware type. (e.g. MEC, SDMA)
556          */
557         __u32 index;
558         __u32 _pad;
559 };
560
561 /* Input structure for the INFO ioctl */
562 struct drm_amdgpu_info {
563         /* Where the return value will be stored */
564         __u64 return_pointer;
565         /* The size of the return value. Just like "size" in "snprintf",
566          * it limits how many bytes the kernel can write. */
567         __u32 return_size;
568         /* The query request id. */
569         __u32 query;
570
571         union {
572                 struct {
573                         __u32 id;
574                         __u32 _pad;
575                 } mode_crtc;
576
577                 struct {
578                         /** AMDGPU_HW_IP_* */
579                         __u32 type;
580                         /**
581                          * Index of the IP if there are more IPs of the same
582                          * type. Ignored by AMDGPU_INFO_HW_IP_COUNT.
583                          */
584                         __u32 ip_instance;
585                 } query_hw_ip;
586
587                 struct {
588                         __u32 dword_offset;
589                         /** number of registers to read */
590                         __u32 count;
591                         __u32 instance;
592                         /** For future use, no flags defined so far */
593                         __u32 flags;
594                 } read_mmr_reg;
595
596                 struct drm_amdgpu_query_fw query_fw;
597
598                 struct {
599                         __u32 type;
600                         __u32 offset;
601                 } vbios_info;
602         };
603 };
604
605 struct drm_amdgpu_info_gds {
606         /** GDS GFX partition size */
607         __u32 gds_gfx_partition_size;
608         /** GDS compute partition size */
609         __u32 compute_partition_size;
610         /** total GDS memory size */
611         __u32 gds_total_size;
612         /** GWS size per GFX partition */
613         __u32 gws_per_gfx_partition;
614         /** GSW size per compute partition */
615         __u32 gws_per_compute_partition;
616         /** OA size per GFX partition */
617         __u32 oa_per_gfx_partition;
618         /** OA size per compute partition */
619         __u32 oa_per_compute_partition;
620         __u32 _pad;
621 };
622
623 struct drm_amdgpu_info_vram_gtt {
624         __u64 vram_size;
625         __u64 vram_cpu_accessible_size;
626         __u64 gtt_size;
627 };
628
629 struct drm_amdgpu_heap_info {
630         /** max. physical memory */
631         __u64 total_heap_size;
632
633         /** Theoretical max. available memory in the given heap */
634         __u64 usable_heap_size;
635
636         /**
637          * Number of bytes allocated in the heap. This includes all processes
638          * and private allocations in the kernel. It changes when new buffers
639          * are allocated, freed, and moved. It cannot be larger than
640          * heap_size.
641          */
642         __u64 heap_usage;
643
644         /**
645          * Theoretical possible max. size of buffer which
646          * could be allocated in the given heap
647          */
648         __u64 max_allocation;
649 };
650
651 struct drm_amdgpu_memory_info {
652         struct drm_amdgpu_heap_info vram;
653         struct drm_amdgpu_heap_info cpu_accessible_vram;
654         struct drm_amdgpu_heap_info gtt;
655 };
656
657 struct drm_amdgpu_info_firmware {
658         __u32 ver;
659         __u32 feature;
660 };
661
662 #define AMDGPU_VRAM_TYPE_UNKNOWN 0
663 #define AMDGPU_VRAM_TYPE_GDDR1 1
664 #define AMDGPU_VRAM_TYPE_DDR2  2
665 #define AMDGPU_VRAM_TYPE_GDDR3 3
666 #define AMDGPU_VRAM_TYPE_GDDR4 4
667 #define AMDGPU_VRAM_TYPE_GDDR5 5
668 #define AMDGPU_VRAM_TYPE_HBM   6
669 #define AMDGPU_VRAM_TYPE_DDR3  7
670
671 struct drm_amdgpu_info_device {
672         /** PCI Device ID */
673         __u32 device_id;
674         /** Internal chip revision: A0, A1, etc.) */
675         __u32 chip_rev;
676         __u32 external_rev;
677         /** Revision id in PCI Config space */
678         __u32 pci_rev;
679         __u32 family;
680         __u32 num_shader_engines;
681         __u32 num_shader_arrays_per_engine;
682         /* in KHz */
683         __u32 gpu_counter_freq;
684         __u64 max_engine_clock;
685         __u64 max_memory_clock;
686         /* cu information */
687         __u32 cu_active_number;
688         __u32 cu_ao_mask;
689         __u32 cu_bitmap[4][4];
690         /** Render backend pipe mask. One render backend is CB+DB. */
691         __u32 enabled_rb_pipes_mask;
692         __u32 num_rb_pipes;
693         __u32 num_hw_gfx_contexts;
694         __u32 _pad;
695         __u64 ids_flags;
696         /** Starting virtual address for UMDs. */
697         __u64 virtual_address_offset;
698         /** The maximum virtual address */
699         __u64 virtual_address_max;
700         /** Required alignment of virtual addresses. */
701         __u32 virtual_address_alignment;
702         /** Page table entry - fragment size */
703         __u32 pte_fragment_size;
704         __u32 gart_page_size;
705         /** constant engine ram size*/
706         __u32 ce_ram_size;
707         /** video memory type info*/
708         __u32 vram_type;
709         /** video memory bit width*/
710         __u32 vram_bit_width;
711         /* vce harvesting instance */
712         __u32 vce_harvest_config;
713 };
714
715 struct drm_amdgpu_info_hw_ip {
716         /** Version of h/w IP */
717         __u32  hw_ip_version_major;
718         __u32  hw_ip_version_minor;
719         /** Capabilities */
720         __u64  capabilities_flags;
721         /** command buffer address start alignment*/
722         __u32  ib_start_alignment;
723         /** command buffer size alignment*/
724         __u32  ib_size_alignment;
725         /** Bitmask of available rings. Bit 0 means ring 0, etc. */
726         __u32  available_rings;
727         __u32  _pad;
728 };
729
730 struct drm_amdgpu_info_num_handles {
731         /** Max handles as supported by firmware for UVD */
732         __u32  uvd_max_handles;
733         /** Handles currently in use for UVD */
734         __u32  uvd_used_handles;
735 };
736
737 #define AMDGPU_VCE_CLOCK_TABLE_ENTRIES          6
738
739 struct drm_amdgpu_info_vce_clock_table_entry {
740         /** System clock */
741         __u32 sclk;
742         /** Memory clock */
743         __u32 mclk;
744         /** VCE clock */
745         __u32 eclk;
746         __u32 pad;
747 };
748
749 struct drm_amdgpu_info_vce_clock_table {
750         struct drm_amdgpu_info_vce_clock_table_entry entries[AMDGPU_VCE_CLOCK_TABLE_ENTRIES];
751         __u32 num_valid_entries;
752         __u32 pad;
753 };
754
755 /*
756  * Supported GPU families
757  */
758 #define AMDGPU_FAMILY_UNKNOWN                   0
759 #define AMDGPU_FAMILY_SI                        110 /* Hainan, Oland, Verde, Pitcairn, Tahiti */
760 #define AMDGPU_FAMILY_CI                        120 /* Bonaire, Hawaii */
761 #define AMDGPU_FAMILY_KV                        125 /* Kaveri, Kabini, Mullins */
762 #define AMDGPU_FAMILY_VI                        130 /* Iceland, Tonga */
763 #define AMDGPU_FAMILY_CZ                        135 /* Carrizo, Stoney */
764 #define AMDGPU_FAMILY_AI                        141 /* Vega10 */
765
766 #if defined(__cplusplus)
767 }
768 #endif
769
770 #endif