blob: a902a602490be1f862c0083cfd5aec2f46e512dd [file] [log] [blame]
Alex Deucher81629cb2015-04-20 16:42:01 -04001/* 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
Michel Dänzerb3fcf36a2015-07-22 17:29:01 +090035#include "drm.h"
Alex Deucher81629cb2015-04-20 16:42:01 -040036
Emil Velikovcfa71522016-04-07 18:45:18 +010037#if defined(__cplusplus)
38extern "C" {
39#endif
40
Alex Deucher81629cb2015-04-20 16:42:01 -040041#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
54#define DRM_IOCTL_AMDGPU_GEM_CREATE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_CREATE, union drm_amdgpu_gem_create)
55#define DRM_IOCTL_AMDGPU_GEM_MMAP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_MMAP, union drm_amdgpu_gem_mmap)
56#define DRM_IOCTL_AMDGPU_CTX DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_CTX, union drm_amdgpu_ctx)
57#define DRM_IOCTL_AMDGPU_BO_LIST DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_BO_LIST, union drm_amdgpu_bo_list)
58#define DRM_IOCTL_AMDGPU_CS DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_CS, union drm_amdgpu_cs)
59#define DRM_IOCTL_AMDGPU_INFO DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_INFO, struct drm_amdgpu_info)
60#define DRM_IOCTL_AMDGPU_GEM_METADATA DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_METADATA, struct drm_amdgpu_gem_metadata)
61#define DRM_IOCTL_AMDGPU_GEM_WAIT_IDLE DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_WAIT_IDLE, union drm_amdgpu_gem_wait_idle)
Christian König34b5f6a2015-06-08 15:03:00 +020062#define DRM_IOCTL_AMDGPU_GEM_VA DRM_IOW(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_VA, struct drm_amdgpu_gem_va)
Alex Deucher81629cb2015-04-20 16:42:01 -040063#define DRM_IOCTL_AMDGPU_WAIT_CS DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_WAIT_CS, union drm_amdgpu_wait_cs)
64#define DRM_IOCTL_AMDGPU_GEM_OP DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_OP, struct drm_amdgpu_gem_op)
65#define DRM_IOCTL_AMDGPU_GEM_USERPTR DRM_IOWR(DRM_COMMAND_BASE + DRM_AMDGPU_GEM_USERPTR, struct drm_amdgpu_gem_userptr)
66
67#define AMDGPU_GEM_DOMAIN_CPU 0x1
68#define AMDGPU_GEM_DOMAIN_GTT 0x2
69#define AMDGPU_GEM_DOMAIN_VRAM 0x4
70#define AMDGPU_GEM_DOMAIN_GDS 0x8
71#define AMDGPU_GEM_DOMAIN_GWS 0x10
72#define AMDGPU_GEM_DOMAIN_OA 0x20
73
Alex Deucher81629cb2015-04-20 16:42:01 -040074/* Flag that CPU access will be required for the case of VRAM domain */
75#define AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED (1 << 0)
76/* Flag that CPU access will not work, this VRAM domain is invisible */
77#define AMDGPU_GEM_CREATE_NO_CPU_ACCESS (1 << 1)
Alex Deucher81629cb2015-04-20 16:42:01 -040078/* Flag that USWC attributes should be used for GTT */
Jammy Zhou88671282015-05-06 18:44:29 +080079#define AMDGPU_GEM_CREATE_CPU_GTT_USWC (1 << 2)
Flora Cui4fea83f2016-07-20 14:44:38 +080080/* Flag that the memory should be in VRAM and cleared */
81#define AMDGPU_GEM_CREATE_VRAM_CLEARED (1 << 3)
Alex Deucher81629cb2015-04-20 16:42:01 -040082
Alex Deucher81629cb2015-04-20 16:42:01 -040083struct drm_amdgpu_gem_create_in {
84 /** the requested memory size */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +010085 __u64 bo_size;
Alex Deucher81629cb2015-04-20 16:42:01 -040086 /** physical start_addr alignment in bytes for some HW requirements */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +010087 __u64 alignment;
Alex Deucher81629cb2015-04-20 16:42:01 -040088 /** the requested memory domains */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +010089 __u64 domains;
Alex Deucher81629cb2015-04-20 16:42:01 -040090 /** allocation flags */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +010091 __u64 domain_flags;
Alex Deucher81629cb2015-04-20 16:42:01 -040092};
93
94struct drm_amdgpu_gem_create_out {
95 /** returned GEM object handle */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +010096 __u32 handle;
97 __u32 _pad;
Alex Deucher81629cb2015-04-20 16:42:01 -040098};
99
100union drm_amdgpu_gem_create {
101 struct drm_amdgpu_gem_create_in in;
102 struct drm_amdgpu_gem_create_out out;
103};
104
105/** Opcode to create new residency list. */
106#define AMDGPU_BO_LIST_OP_CREATE 0
107/** Opcode to destroy previously created residency list */
108#define AMDGPU_BO_LIST_OP_DESTROY 1
109/** Opcode to update resource information in the list */
110#define AMDGPU_BO_LIST_OP_UPDATE 2
111
112struct drm_amdgpu_bo_list_in {
113 /** Type of operation */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100114 __u32 operation;
Alex Deucher81629cb2015-04-20 16:42:01 -0400115 /** Handle of list or 0 if we want to create one */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100116 __u32 list_handle;
Alex Deucher81629cb2015-04-20 16:42:01 -0400117 /** Number of BOs in list */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100118 __u32 bo_number;
Alex Deucher81629cb2015-04-20 16:42:01 -0400119 /** Size of each element describing BO */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100120 __u32 bo_info_size;
Alex Deucher81629cb2015-04-20 16:42:01 -0400121 /** Pointer to array describing BOs */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100122 __u64 bo_info_ptr;
Alex Deucher81629cb2015-04-20 16:42:01 -0400123};
124
125struct drm_amdgpu_bo_list_entry {
126 /** Handle of BO */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100127 __u32 bo_handle;
Alex Deucher81629cb2015-04-20 16:42:01 -0400128 /** New (if specified) BO priority to be used during migration */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100129 __u32 bo_priority;
Alex Deucher81629cb2015-04-20 16:42:01 -0400130};
131
132struct drm_amdgpu_bo_list_out {
133 /** Handle of resource list */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100134 __u32 list_handle;
135 __u32 _pad;
Alex Deucher81629cb2015-04-20 16:42:01 -0400136};
137
138union drm_amdgpu_bo_list {
139 struct drm_amdgpu_bo_list_in in;
140 struct drm_amdgpu_bo_list_out out;
141};
142
143/* context related */
144#define AMDGPU_CTX_OP_ALLOC_CTX 1
145#define AMDGPU_CTX_OP_FREE_CTX 2
146#define AMDGPU_CTX_OP_QUERY_STATE 3
147
Marek Olšákd94aed52015-05-05 21:13:49 +0200148/* GPU reset status */
149#define AMDGPU_CTX_NO_RESET 0
Christian König675da0d2015-06-09 15:54:37 +0200150/* this the context caused it */
151#define AMDGPU_CTX_GUILTY_RESET 1
152/* some other context caused it */
153#define AMDGPU_CTX_INNOCENT_RESET 2
154/* unknown cause */
155#define AMDGPU_CTX_UNKNOWN_RESET 3
Marek Olšákd94aed52015-05-05 21:13:49 +0200156
Alex Deucher81629cb2015-04-20 16:42:01 -0400157struct drm_amdgpu_ctx_in {
Christian König675da0d2015-06-09 15:54:37 +0200158 /** AMDGPU_CTX_OP_* */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100159 __u32 op;
Christian König675da0d2015-06-09 15:54:37 +0200160 /** For future use, no flags defined so far */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100161 __u32 flags;
162 __u32 ctx_id;
163 __u32 _pad;
Alex Deucher81629cb2015-04-20 16:42:01 -0400164};
165
166union drm_amdgpu_ctx_out {
167 struct {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100168 __u32 ctx_id;
169 __u32 _pad;
Alex Deucher81629cb2015-04-20 16:42:01 -0400170 } alloc;
171
172 struct {
Christian König675da0d2015-06-09 15:54:37 +0200173 /** For future use, no flags defined so far */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100174 __u64 flags;
Marek Olšákd94aed52015-05-05 21:13:49 +0200175 /** Number of resets caused by this context so far. */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100176 __u32 hangs;
Marek Olšákd94aed52015-05-05 21:13:49 +0200177 /** Reset status since the last call of the ioctl. */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100178 __u32 reset_status;
Alex Deucher81629cb2015-04-20 16:42:01 -0400179 } state;
180};
181
182union drm_amdgpu_ctx {
183 struct drm_amdgpu_ctx_in in;
184 union drm_amdgpu_ctx_out out;
185};
186
187/*
188 * This is not a reliable API and you should expect it to fail for any
189 * number of reasons and have fallback path that do not use userptr to
190 * perform any operation.
191 */
192#define AMDGPU_GEM_USERPTR_READONLY (1 << 0)
193#define AMDGPU_GEM_USERPTR_ANONONLY (1 << 1)
194#define AMDGPU_GEM_USERPTR_VALIDATE (1 << 2)
195#define AMDGPU_GEM_USERPTR_REGISTER (1 << 3)
196
197struct drm_amdgpu_gem_userptr {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100198 __u64 addr;
199 __u64 size;
Christian König675da0d2015-06-09 15:54:37 +0200200 /* AMDGPU_GEM_USERPTR_* */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100201 __u32 flags;
Christian König675da0d2015-06-09 15:54:37 +0200202 /* Resulting GEM handle */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100203 __u32 handle;
Alex Deucher81629cb2015-04-20 16:42:01 -0400204};
205
Marek Olšákfbd76d52015-05-14 23:48:26 +0200206/* same meaning as the GB_TILE_MODE and GL_MACRO_TILE_MODE fields */
207#define AMDGPU_TILING_ARRAY_MODE_SHIFT 0
208#define AMDGPU_TILING_ARRAY_MODE_MASK 0xf
209#define AMDGPU_TILING_PIPE_CONFIG_SHIFT 4
210#define AMDGPU_TILING_PIPE_CONFIG_MASK 0x1f
211#define AMDGPU_TILING_TILE_SPLIT_SHIFT 9
212#define AMDGPU_TILING_TILE_SPLIT_MASK 0x7
213#define AMDGPU_TILING_MICRO_TILE_MODE_SHIFT 12
214#define AMDGPU_TILING_MICRO_TILE_MODE_MASK 0x7
215#define AMDGPU_TILING_BANK_WIDTH_SHIFT 15
216#define AMDGPU_TILING_BANK_WIDTH_MASK 0x3
217#define AMDGPU_TILING_BANK_HEIGHT_SHIFT 17
218#define AMDGPU_TILING_BANK_HEIGHT_MASK 0x3
219#define AMDGPU_TILING_MACRO_TILE_ASPECT_SHIFT 19
220#define AMDGPU_TILING_MACRO_TILE_ASPECT_MASK 0x3
221#define AMDGPU_TILING_NUM_BANKS_SHIFT 21
222#define AMDGPU_TILING_NUM_BANKS_MASK 0x3
223
224#define AMDGPU_TILING_SET(field, value) \
225 (((value) & AMDGPU_TILING_##field##_MASK) << AMDGPU_TILING_##field##_SHIFT)
226#define AMDGPU_TILING_GET(value, field) \
227 (((value) >> AMDGPU_TILING_##field##_SHIFT) & AMDGPU_TILING_##field##_MASK)
Alex Deucher81629cb2015-04-20 16:42:01 -0400228
229#define AMDGPU_GEM_METADATA_OP_SET_METADATA 1
230#define AMDGPU_GEM_METADATA_OP_GET_METADATA 2
231
232/** The same structure is shared for input/output */
233struct drm_amdgpu_gem_metadata {
Christian König675da0d2015-06-09 15:54:37 +0200234 /** GEM Object handle */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100235 __u32 handle;
Christian König675da0d2015-06-09 15:54:37 +0200236 /** Do we want get or set metadata */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100237 __u32 op;
Alex Deucher81629cb2015-04-20 16:42:01 -0400238 struct {
Christian König675da0d2015-06-09 15:54:37 +0200239 /** For future use, no flags defined so far */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100240 __u64 flags;
Christian König675da0d2015-06-09 15:54:37 +0200241 /** family specific tiling info */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100242 __u64 tiling_info;
243 __u32 data_size_bytes;
244 __u32 data[64];
Alex Deucher81629cb2015-04-20 16:42:01 -0400245 } data;
246};
247
248struct drm_amdgpu_gem_mmap_in {
Christian König675da0d2015-06-09 15:54:37 +0200249 /** the GEM object handle */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100250 __u32 handle;
251 __u32 _pad;
Alex Deucher81629cb2015-04-20 16:42:01 -0400252};
253
254struct drm_amdgpu_gem_mmap_out {
Christian König675da0d2015-06-09 15:54:37 +0200255 /** mmap offset from the vma offset manager */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100256 __u64 addr_ptr;
Alex Deucher81629cb2015-04-20 16:42:01 -0400257};
258
259union drm_amdgpu_gem_mmap {
260 struct drm_amdgpu_gem_mmap_in in;
261 struct drm_amdgpu_gem_mmap_out out;
262};
263
264struct drm_amdgpu_gem_wait_idle_in {
Christian König675da0d2015-06-09 15:54:37 +0200265 /** GEM object handle */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100266 __u32 handle;
Christian König675da0d2015-06-09 15:54:37 +0200267 /** For future use, no flags defined so far */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100268 __u32 flags;
Christian König675da0d2015-06-09 15:54:37 +0200269 /** Absolute timeout to wait */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100270 __u64 timeout;
Alex Deucher81629cb2015-04-20 16:42:01 -0400271};
272
273struct drm_amdgpu_gem_wait_idle_out {
Christian König675da0d2015-06-09 15:54:37 +0200274 /** BO status: 0 - BO is idle, 1 - BO is busy */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100275 __u32 status;
Christian König675da0d2015-06-09 15:54:37 +0200276 /** Returned current memory domain */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100277 __u32 domain;
Alex Deucher81629cb2015-04-20 16:42:01 -0400278};
279
280union drm_amdgpu_gem_wait_idle {
281 struct drm_amdgpu_gem_wait_idle_in in;
282 struct drm_amdgpu_gem_wait_idle_out out;
283};
284
285struct drm_amdgpu_wait_cs_in {
Christian König675da0d2015-06-09 15:54:37 +0200286 /** Command submission handle */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100287 __u64 handle;
Christian König675da0d2015-06-09 15:54:37 +0200288 /** Absolute timeout to wait */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100289 __u64 timeout;
290 __u32 ip_type;
291 __u32 ip_instance;
292 __u32 ring;
293 __u32 ctx_id;
Alex Deucher81629cb2015-04-20 16:42:01 -0400294};
295
296struct drm_amdgpu_wait_cs_out {
Christian König675da0d2015-06-09 15:54:37 +0200297 /** CS status: 0 - CS completed, 1 - CS still busy */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100298 __u64 status;
Alex Deucher81629cb2015-04-20 16:42:01 -0400299};
300
301union drm_amdgpu_wait_cs {
302 struct drm_amdgpu_wait_cs_in in;
303 struct drm_amdgpu_wait_cs_out out;
304};
305
Marek Olšákd8f65a22015-05-27 14:30:38 +0200306#define AMDGPU_GEM_OP_GET_GEM_CREATE_INFO 0
307#define AMDGPU_GEM_OP_SET_PLACEMENT 1
Alex Deucher81629cb2015-04-20 16:42:01 -0400308
Christian König675da0d2015-06-09 15:54:37 +0200309/* Sets or returns a value associated with a buffer. */
310struct drm_amdgpu_gem_op {
311 /** GEM object handle */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100312 __u32 handle;
Christian König675da0d2015-06-09 15:54:37 +0200313 /** AMDGPU_GEM_OP_* */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100314 __u32 op;
Christian König675da0d2015-06-09 15:54:37 +0200315 /** Input or return value */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100316 __u64 value;
Christian König675da0d2015-06-09 15:54:37 +0200317};
318
Alex Deucher81629cb2015-04-20 16:42:01 -0400319#define AMDGPU_VA_OP_MAP 1
320#define AMDGPU_VA_OP_UNMAP 2
321
Christian Königfc220f62015-06-29 17:12:20 +0200322/* Delay the page table update till the next CS */
323#define AMDGPU_VM_DELAY_UPDATE (1 << 0)
324
Alex Deucher81629cb2015-04-20 16:42:01 -0400325/* Mapping flags */
326/* readable mapping */
327#define AMDGPU_VM_PAGE_READABLE (1 << 1)
328/* writable mapping */
329#define AMDGPU_VM_PAGE_WRITEABLE (1 << 2)
330/* executable mapping, new for VI */
331#define AMDGPU_VM_PAGE_EXECUTABLE (1 << 3)
332
Christian König34b5f6a2015-06-08 15:03:00 +0200333struct drm_amdgpu_gem_va {
Christian König675da0d2015-06-09 15:54:37 +0200334 /** GEM object handle */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100335 __u32 handle;
336 __u32 _pad;
Christian König675da0d2015-06-09 15:54:37 +0200337 /** AMDGPU_VA_OP_* */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100338 __u32 operation;
Christian König675da0d2015-06-09 15:54:37 +0200339 /** AMDGPU_VM_PAGE_* */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100340 __u32 flags;
Christian König675da0d2015-06-09 15:54:37 +0200341 /** va address to assign . Must be correctly aligned.*/
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100342 __u64 va_address;
Christian König675da0d2015-06-09 15:54:37 +0200343 /** Specify offset inside of BO to assign. Must be correctly aligned.*/
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100344 __u64 offset_in_bo;
Christian König675da0d2015-06-09 15:54:37 +0200345 /** Specify mapping size. Must be correctly aligned. */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100346 __u64 map_size;
Alex Deucher81629cb2015-04-20 16:42:01 -0400347};
348
Alex Deucher81629cb2015-04-20 16:42:01 -0400349#define AMDGPU_HW_IP_GFX 0
350#define AMDGPU_HW_IP_COMPUTE 1
351#define AMDGPU_HW_IP_DMA 2
352#define AMDGPU_HW_IP_UVD 3
353#define AMDGPU_HW_IP_VCE 4
354#define AMDGPU_HW_IP_NUM 5
355
356#define AMDGPU_HW_IP_INSTANCE_MAX_COUNT 1
357
358#define AMDGPU_CHUNK_ID_IB 0x01
359#define AMDGPU_CHUNK_ID_FENCE 0x02
Christian König2b48d322015-06-19 17:31:29 +0200360#define AMDGPU_CHUNK_ID_DEPENDENCIES 0x03
Christian König675da0d2015-06-09 15:54:37 +0200361
Alex Deucher81629cb2015-04-20 16:42:01 -0400362struct drm_amdgpu_cs_chunk {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100363 __u32 chunk_id;
364 __u32 length_dw;
365 __u64 chunk_data;
Alex Deucher81629cb2015-04-20 16:42:01 -0400366};
367
368struct drm_amdgpu_cs_in {
369 /** Rendering context id */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100370 __u32 ctx_id;
Alex Deucher81629cb2015-04-20 16:42:01 -0400371 /** Handle of resource list associated with CS */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100372 __u32 bo_list_handle;
373 __u32 num_chunks;
374 __u32 _pad;
375 /** this points to __u64 * which point to cs chunks */
376 __u64 chunks;
Alex Deucher81629cb2015-04-20 16:42:01 -0400377};
378
379struct drm_amdgpu_cs_out {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100380 __u64 handle;
Alex Deucher81629cb2015-04-20 16:42:01 -0400381};
382
383union drm_amdgpu_cs {
Christian König675da0d2015-06-09 15:54:37 +0200384 struct drm_amdgpu_cs_in in;
385 struct drm_amdgpu_cs_out out;
Alex Deucher81629cb2015-04-20 16:42:01 -0400386};
387
388/* Specify flags to be used for IB */
389
390/* This IB should be submitted to CE */
391#define AMDGPU_IB_FLAG_CE (1<<0)
392
Jammy Zhouaa2bdb242015-05-11 23:49:34 +0800393/* CE Preamble */
Jammy Zhoucab6d572015-06-06 04:49:22 +0800394#define AMDGPU_IB_FLAG_PREAMBLE (1<<1)
Jammy Zhouaa2bdb242015-05-11 23:49:34 +0800395
Alex Deucher81629cb2015-04-20 16:42:01 -0400396struct drm_amdgpu_cs_chunk_ib {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100397 __u32 _pad;
Christian König675da0d2015-06-09 15:54:37 +0200398 /** AMDGPU_IB_FLAG_* */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100399 __u32 flags;
Christian König675da0d2015-06-09 15:54:37 +0200400 /** Virtual address to begin IB execution */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100401 __u64 va_start;
Christian König675da0d2015-06-09 15:54:37 +0200402 /** Size of submission */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100403 __u32 ib_bytes;
Christian König675da0d2015-06-09 15:54:37 +0200404 /** HW IP to submit to */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100405 __u32 ip_type;
Christian König675da0d2015-06-09 15:54:37 +0200406 /** HW IP index of the same type to submit to */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100407 __u32 ip_instance;
Christian König675da0d2015-06-09 15:54:37 +0200408 /** Ring index to submit to */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100409 __u32 ring;
Alex Deucher81629cb2015-04-20 16:42:01 -0400410};
411
Christian König2b48d322015-06-19 17:31:29 +0200412struct drm_amdgpu_cs_chunk_dep {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100413 __u32 ip_type;
414 __u32 ip_instance;
415 __u32 ring;
416 __u32 ctx_id;
417 __u64 handle;
Christian König2b48d322015-06-19 17:31:29 +0200418};
419
Alex Deucher81629cb2015-04-20 16:42:01 -0400420struct drm_amdgpu_cs_chunk_fence {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100421 __u32 handle;
422 __u32 offset;
Alex Deucher81629cb2015-04-20 16:42:01 -0400423};
424
425struct drm_amdgpu_cs_chunk_data {
426 union {
427 struct drm_amdgpu_cs_chunk_ib ib_data;
428 struct drm_amdgpu_cs_chunk_fence fence_data;
429 };
430};
431
432/**
433 * Query h/w info: Flag that this is integrated (a.h.a. fusion) GPU
434 *
435 */
436#define AMDGPU_IDS_FLAGS_FUSION 0x1
437
438/* indicate if acceleration can be working */
439#define AMDGPU_INFO_ACCEL_WORKING 0x00
440/* get the crtc_id from the mode object id? */
441#define AMDGPU_INFO_CRTC_FROM_ID 0x01
442/* query hw IP info */
443#define AMDGPU_INFO_HW_IP_INFO 0x02
444/* query hw IP instance count for the specified type */
445#define AMDGPU_INFO_HW_IP_COUNT 0x03
446/* timestamp for GL_ARB_timer_query */
447#define AMDGPU_INFO_TIMESTAMP 0x05
448/* Query the firmware version */
449#define AMDGPU_INFO_FW_VERSION 0x0e
450 /* Subquery id: Query VCE firmware version */
451 #define AMDGPU_INFO_FW_VCE 0x1
452 /* Subquery id: Query UVD firmware version */
453 #define AMDGPU_INFO_FW_UVD 0x2
454 /* Subquery id: Query GMC firmware version */
455 #define AMDGPU_INFO_FW_GMC 0x03
456 /* Subquery id: Query GFX ME firmware version */
457 #define AMDGPU_INFO_FW_GFX_ME 0x04
458 /* Subquery id: Query GFX PFP firmware version */
459 #define AMDGPU_INFO_FW_GFX_PFP 0x05
460 /* Subquery id: Query GFX CE firmware version */
461 #define AMDGPU_INFO_FW_GFX_CE 0x06
462 /* Subquery id: Query GFX RLC firmware version */
463 #define AMDGPU_INFO_FW_GFX_RLC 0x07
464 /* Subquery id: Query GFX MEC firmware version */
465 #define AMDGPU_INFO_FW_GFX_MEC 0x08
466 /* Subquery id: Query SMC firmware version */
467 #define AMDGPU_INFO_FW_SMC 0x0a
468 /* Subquery id: Query SDMA firmware version */
469 #define AMDGPU_INFO_FW_SDMA 0x0b
470/* number of bytes moved for TTM migration */
471#define AMDGPU_INFO_NUM_BYTES_MOVED 0x0f
472/* the used VRAM size */
473#define AMDGPU_INFO_VRAM_USAGE 0x10
474/* the used GTT size */
475#define AMDGPU_INFO_GTT_USAGE 0x11
476/* Information about GDS, etc. resource configuration */
477#define AMDGPU_INFO_GDS_CONFIG 0x13
478/* Query information about VRAM and GTT domains */
479#define AMDGPU_INFO_VRAM_GTT 0x14
480/* Query information about register in MMR address space*/
481#define AMDGPU_INFO_READ_MMR_REG 0x15
482/* Query information about device: rev id, family, etc. */
483#define AMDGPU_INFO_DEV_INFO 0x16
484/* visible vram usage */
485#define AMDGPU_INFO_VIS_VRAM_USAGE 0x17
486
487#define AMDGPU_INFO_MMR_SE_INDEX_SHIFT 0
488#define AMDGPU_INFO_MMR_SE_INDEX_MASK 0xff
489#define AMDGPU_INFO_MMR_SH_INDEX_SHIFT 8
490#define AMDGPU_INFO_MMR_SH_INDEX_MASK 0xff
491
Huang Rui000cab92016-06-12 15:44:44 +0800492struct drm_amdgpu_query_fw {
493 /** AMDGPU_INFO_FW_* */
494 __u32 fw_type;
495 /**
496 * Index of the IP if there are more IPs of
497 * the same type.
498 */
499 __u32 ip_instance;
500 /**
501 * Index of the engine. Whether this is used depends
502 * on the firmware type. (e.g. MEC, SDMA)
503 */
504 __u32 index;
505 __u32 _pad;
506};
507
Alex Deucher81629cb2015-04-20 16:42:01 -0400508/* Input structure for the INFO ioctl */
509struct drm_amdgpu_info {
510 /* Where the return value will be stored */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100511 __u64 return_pointer;
Alex Deucher81629cb2015-04-20 16:42:01 -0400512 /* The size of the return value. Just like "size" in "snprintf",
513 * it limits how many bytes the kernel can write. */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100514 __u32 return_size;
Alex Deucher81629cb2015-04-20 16:42:01 -0400515 /* The query request id. */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100516 __u32 query;
Alex Deucher81629cb2015-04-20 16:42:01 -0400517
518 union {
519 struct {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100520 __u32 id;
521 __u32 _pad;
Alex Deucher81629cb2015-04-20 16:42:01 -0400522 } mode_crtc;
523
524 struct {
525 /** AMDGPU_HW_IP_* */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100526 __u32 type;
Alex Deucher81629cb2015-04-20 16:42:01 -0400527 /**
Christian König675da0d2015-06-09 15:54:37 +0200528 * Index of the IP if there are more IPs of the same
529 * type. Ignored by AMDGPU_INFO_HW_IP_COUNT.
Alex Deucher81629cb2015-04-20 16:42:01 -0400530 */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100531 __u32 ip_instance;
Alex Deucher81629cb2015-04-20 16:42:01 -0400532 } query_hw_ip;
533
534 struct {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100535 __u32 dword_offset;
Christian König675da0d2015-06-09 15:54:37 +0200536 /** number of registers to read */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100537 __u32 count;
538 __u32 instance;
Christian König675da0d2015-06-09 15:54:37 +0200539 /** For future use, no flags defined so far */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100540 __u32 flags;
Alex Deucher81629cb2015-04-20 16:42:01 -0400541 } read_mmr_reg;
542
Huang Rui000cab92016-06-12 15:44:44 +0800543 struct drm_amdgpu_query_fw query_fw;
Alex Deucher81629cb2015-04-20 16:42:01 -0400544 };
545};
546
547struct drm_amdgpu_info_gds {
548 /** GDS GFX partition size */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100549 __u32 gds_gfx_partition_size;
Alex Deucher81629cb2015-04-20 16:42:01 -0400550 /** GDS compute partition size */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100551 __u32 compute_partition_size;
Alex Deucher81629cb2015-04-20 16:42:01 -0400552 /** total GDS memory size */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100553 __u32 gds_total_size;
Alex Deucher81629cb2015-04-20 16:42:01 -0400554 /** GWS size per GFX partition */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100555 __u32 gws_per_gfx_partition;
Alex Deucher81629cb2015-04-20 16:42:01 -0400556 /** GSW size per compute partition */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100557 __u32 gws_per_compute_partition;
Alex Deucher81629cb2015-04-20 16:42:01 -0400558 /** OA size per GFX partition */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100559 __u32 oa_per_gfx_partition;
Alex Deucher81629cb2015-04-20 16:42:01 -0400560 /** OA size per compute partition */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100561 __u32 oa_per_compute_partition;
562 __u32 _pad;
Alex Deucher81629cb2015-04-20 16:42:01 -0400563};
564
565struct drm_amdgpu_info_vram_gtt {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100566 __u64 vram_size;
567 __u64 vram_cpu_accessible_size;
568 __u64 gtt_size;
Alex Deucher81629cb2015-04-20 16:42:01 -0400569};
570
571struct drm_amdgpu_info_firmware {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100572 __u32 ver;
573 __u32 feature;
Alex Deucher81629cb2015-04-20 16:42:01 -0400574};
575
Ken Wang81c59f52015-06-03 21:02:01 +0800576#define AMDGPU_VRAM_TYPE_UNKNOWN 0
577#define AMDGPU_VRAM_TYPE_GDDR1 1
578#define AMDGPU_VRAM_TYPE_DDR2 2
579#define AMDGPU_VRAM_TYPE_GDDR3 3
580#define AMDGPU_VRAM_TYPE_GDDR4 4
581#define AMDGPU_VRAM_TYPE_GDDR5 5
582#define AMDGPU_VRAM_TYPE_HBM 6
583#define AMDGPU_VRAM_TYPE_DDR3 7
584
Alex Deucher81629cb2015-04-20 16:42:01 -0400585struct drm_amdgpu_info_device {
586 /** PCI Device ID */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100587 __u32 device_id;
Alex Deucher81629cb2015-04-20 16:42:01 -0400588 /** Internal chip revision: A0, A1, etc.) */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100589 __u32 chip_rev;
590 __u32 external_rev;
Alex Deucher81629cb2015-04-20 16:42:01 -0400591 /** Revision id in PCI Config space */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100592 __u32 pci_rev;
593 __u32 family;
594 __u32 num_shader_engines;
595 __u32 num_shader_arrays_per_engine;
Christian König675da0d2015-06-09 15:54:37 +0200596 /* in KHz */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100597 __u32 gpu_counter_freq;
598 __u64 max_engine_clock;
599 __u64 max_memory_clock;
Alex Deucher81629cb2015-04-20 16:42:01 -0400600 /* cu information */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100601 __u32 cu_active_number;
602 __u32 cu_ao_mask;
603 __u32 cu_bitmap[4][4];
Alex Deucher81629cb2015-04-20 16:42:01 -0400604 /** Render backend pipe mask. One render backend is CB+DB. */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100605 __u32 enabled_rb_pipes_mask;
606 __u32 num_rb_pipes;
607 __u32 num_hw_gfx_contexts;
608 __u32 _pad;
609 __u64 ids_flags;
Alex Deucher81629cb2015-04-20 16:42:01 -0400610 /** Starting virtual address for UMDs. */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100611 __u64 virtual_address_offset;
Jammy Zhou02b70c82015-05-12 22:46:45 +0800612 /** The maximum virtual address */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100613 __u64 virtual_address_max;
Alex Deucher81629cb2015-04-20 16:42:01 -0400614 /** Required alignment of virtual addresses. */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100615 __u32 virtual_address_alignment;
Alex Deucher81629cb2015-04-20 16:42:01 -0400616 /** Page table entry - fragment size */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100617 __u32 pte_fragment_size;
618 __u32 gart_page_size;
Ken Wanga101a892015-06-03 17:47:54 +0800619 /** constant engine ram size*/
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100620 __u32 ce_ram_size;
Jammy Zhoucab6d572015-06-06 04:49:22 +0800621 /** video memory type info*/
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100622 __u32 vram_type;
Ken Wang81c59f52015-06-03 21:02:01 +0800623 /** video memory bit width*/
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100624 __u32 vram_bit_width;
Leo Liufa927542015-07-13 12:46:23 -0400625 /* vce harvesting instance */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100626 __u32 vce_harvest_config;
Alex Deucher81629cb2015-04-20 16:42:01 -0400627};
628
629struct drm_amdgpu_info_hw_ip {
630 /** Version of h/w IP */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100631 __u32 hw_ip_version_major;
632 __u32 hw_ip_version_minor;
Alex Deucher81629cb2015-04-20 16:42:01 -0400633 /** Capabilities */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100634 __u64 capabilities_flags;
Ken Wang71062f42015-06-04 21:26:57 +0800635 /** command buffer address start alignment*/
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100636 __u32 ib_start_alignment;
Ken Wang71062f42015-06-04 21:26:57 +0800637 /** command buffer size alignment*/
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100638 __u32 ib_size_alignment;
Alex Deucher81629cb2015-04-20 16:42:01 -0400639 /** Bitmask of available rings. Bit 0 means ring 0, etc. */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100640 __u32 available_rings;
641 __u32 _pad;
Alex Deucher81629cb2015-04-20 16:42:01 -0400642};
643
644/*
645 * Supported GPU families
646 */
647#define AMDGPU_FAMILY_UNKNOWN 0
648#define AMDGPU_FAMILY_CI 120 /* Bonaire, Hawaii */
649#define AMDGPU_FAMILY_KV 125 /* Kaveri, Kabini, Mullins */
650#define AMDGPU_FAMILY_VI 130 /* Iceland, Tonga */
Samuel Li39bb0c92015-10-08 16:31:43 -0400651#define AMDGPU_FAMILY_CZ 135 /* Carrizo, Stoney */
Alex Deucher81629cb2015-04-20 16:42:01 -0400652
Emil Velikovcfa71522016-04-07 18:45:18 +0100653#if defined(__cplusplus)
654}
655#endif
656
Alex Deucher81629cb2015-04-20 16:42:01 -0400657#endif