blob: b6a04d48f457f8e69ddfb9a851914ad232558b20 [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)
Chunming Zhoue7893c42016-07-26 14:13:21 +080082/* Flag that create shadow bo(GTT) while allocating vram bo */
83#define AMDGPU_GEM_CREATE_SHADOW (1 << 4)
Christian König03f48dd2016-08-15 17:00:22 +020084/* Flag that allocating the BO should use linear VRAM */
85#define AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS (1 << 5)
Alex Deucher81629cb2015-04-20 16:42:01 -040086
Alex Deucher81629cb2015-04-20 16:42:01 -040087struct drm_amdgpu_gem_create_in {
88 /** the requested memory size */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +010089 __u64 bo_size;
Alex Deucher81629cb2015-04-20 16:42:01 -040090 /** physical start_addr alignment in bytes for some HW requirements */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +010091 __u64 alignment;
Alex Deucher81629cb2015-04-20 16:42:01 -040092 /** the requested memory domains */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +010093 __u64 domains;
Alex Deucher81629cb2015-04-20 16:42:01 -040094 /** allocation flags */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +010095 __u64 domain_flags;
Alex Deucher81629cb2015-04-20 16:42:01 -040096};
97
98struct drm_amdgpu_gem_create_out {
99 /** returned GEM object handle */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100100 __u32 handle;
101 __u32 _pad;
Alex Deucher81629cb2015-04-20 16:42:01 -0400102};
103
104union drm_amdgpu_gem_create {
105 struct drm_amdgpu_gem_create_in in;
106 struct drm_amdgpu_gem_create_out out;
107};
108
109/** Opcode to create new residency list. */
110#define AMDGPU_BO_LIST_OP_CREATE 0
111/** Opcode to destroy previously created residency list */
112#define AMDGPU_BO_LIST_OP_DESTROY 1
113/** Opcode to update resource information in the list */
114#define AMDGPU_BO_LIST_OP_UPDATE 2
115
116struct drm_amdgpu_bo_list_in {
117 /** Type of operation */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100118 __u32 operation;
Alex Deucher81629cb2015-04-20 16:42:01 -0400119 /** Handle of list or 0 if we want to create one */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100120 __u32 list_handle;
Alex Deucher81629cb2015-04-20 16:42:01 -0400121 /** Number of BOs in list */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100122 __u32 bo_number;
Alex Deucher81629cb2015-04-20 16:42:01 -0400123 /** Size of each element describing BO */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100124 __u32 bo_info_size;
Alex Deucher81629cb2015-04-20 16:42:01 -0400125 /** Pointer to array describing BOs */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100126 __u64 bo_info_ptr;
Alex Deucher81629cb2015-04-20 16:42:01 -0400127};
128
129struct drm_amdgpu_bo_list_entry {
130 /** Handle of BO */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100131 __u32 bo_handle;
Alex Deucher81629cb2015-04-20 16:42:01 -0400132 /** New (if specified) BO priority to be used during migration */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100133 __u32 bo_priority;
Alex Deucher81629cb2015-04-20 16:42:01 -0400134};
135
136struct drm_amdgpu_bo_list_out {
137 /** Handle of resource list */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100138 __u32 list_handle;
139 __u32 _pad;
Alex Deucher81629cb2015-04-20 16:42:01 -0400140};
141
142union drm_amdgpu_bo_list {
143 struct drm_amdgpu_bo_list_in in;
144 struct drm_amdgpu_bo_list_out out;
145};
146
147/* context related */
148#define AMDGPU_CTX_OP_ALLOC_CTX 1
149#define AMDGPU_CTX_OP_FREE_CTX 2
150#define AMDGPU_CTX_OP_QUERY_STATE 3
151
Marek Olšákd94aed52015-05-05 21:13:49 +0200152/* GPU reset status */
153#define AMDGPU_CTX_NO_RESET 0
Christian König675da0d2015-06-09 15:54:37 +0200154/* this the context caused it */
155#define AMDGPU_CTX_GUILTY_RESET 1
156/* some other context caused it */
157#define AMDGPU_CTX_INNOCENT_RESET 2
158/* unknown cause */
159#define AMDGPU_CTX_UNKNOWN_RESET 3
Marek Olšákd94aed52015-05-05 21:13:49 +0200160
Alex Deucher81629cb2015-04-20 16:42:01 -0400161struct drm_amdgpu_ctx_in {
Christian König675da0d2015-06-09 15:54:37 +0200162 /** AMDGPU_CTX_OP_* */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100163 __u32 op;
Christian König675da0d2015-06-09 15:54:37 +0200164 /** For future use, no flags defined so far */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100165 __u32 flags;
166 __u32 ctx_id;
167 __u32 _pad;
Alex Deucher81629cb2015-04-20 16:42:01 -0400168};
169
170union drm_amdgpu_ctx_out {
171 struct {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100172 __u32 ctx_id;
173 __u32 _pad;
Alex Deucher81629cb2015-04-20 16:42:01 -0400174 } alloc;
175
176 struct {
Christian König675da0d2015-06-09 15:54:37 +0200177 /** For future use, no flags defined so far */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100178 __u64 flags;
Marek Olšákd94aed52015-05-05 21:13:49 +0200179 /** Number of resets caused by this context so far. */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100180 __u32 hangs;
Marek Olšákd94aed52015-05-05 21:13:49 +0200181 /** Reset status since the last call of the ioctl. */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100182 __u32 reset_status;
Alex Deucher81629cb2015-04-20 16:42:01 -0400183 } state;
184};
185
186union drm_amdgpu_ctx {
187 struct drm_amdgpu_ctx_in in;
188 union drm_amdgpu_ctx_out out;
189};
190
191/*
192 * This is not a reliable API and you should expect it to fail for any
193 * number of reasons and have fallback path that do not use userptr to
194 * perform any operation.
195 */
196#define AMDGPU_GEM_USERPTR_READONLY (1 << 0)
197#define AMDGPU_GEM_USERPTR_ANONONLY (1 << 1)
198#define AMDGPU_GEM_USERPTR_VALIDATE (1 << 2)
199#define AMDGPU_GEM_USERPTR_REGISTER (1 << 3)
200
201struct drm_amdgpu_gem_userptr {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100202 __u64 addr;
203 __u64 size;
Christian König675da0d2015-06-09 15:54:37 +0200204 /* AMDGPU_GEM_USERPTR_* */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100205 __u32 flags;
Christian König675da0d2015-06-09 15:54:37 +0200206 /* Resulting GEM handle */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100207 __u32 handle;
Alex Deucher81629cb2015-04-20 16:42:01 -0400208};
209
Marek Olšákfbd76d52015-05-14 23:48:26 +0200210/* same meaning as the GB_TILE_MODE and GL_MACRO_TILE_MODE fields */
211#define AMDGPU_TILING_ARRAY_MODE_SHIFT 0
212#define AMDGPU_TILING_ARRAY_MODE_MASK 0xf
213#define AMDGPU_TILING_PIPE_CONFIG_SHIFT 4
214#define AMDGPU_TILING_PIPE_CONFIG_MASK 0x1f
215#define AMDGPU_TILING_TILE_SPLIT_SHIFT 9
216#define AMDGPU_TILING_TILE_SPLIT_MASK 0x7
217#define AMDGPU_TILING_MICRO_TILE_MODE_SHIFT 12
218#define AMDGPU_TILING_MICRO_TILE_MODE_MASK 0x7
219#define AMDGPU_TILING_BANK_WIDTH_SHIFT 15
220#define AMDGPU_TILING_BANK_WIDTH_MASK 0x3
221#define AMDGPU_TILING_BANK_HEIGHT_SHIFT 17
222#define AMDGPU_TILING_BANK_HEIGHT_MASK 0x3
223#define AMDGPU_TILING_MACRO_TILE_ASPECT_SHIFT 19
224#define AMDGPU_TILING_MACRO_TILE_ASPECT_MASK 0x3
225#define AMDGPU_TILING_NUM_BANKS_SHIFT 21
226#define AMDGPU_TILING_NUM_BANKS_MASK 0x3
227
228#define AMDGPU_TILING_SET(field, value) \
229 (((value) & AMDGPU_TILING_##field##_MASK) << AMDGPU_TILING_##field##_SHIFT)
230#define AMDGPU_TILING_GET(value, field) \
231 (((value) >> AMDGPU_TILING_##field##_SHIFT) & AMDGPU_TILING_##field##_MASK)
Alex Deucher81629cb2015-04-20 16:42:01 -0400232
233#define AMDGPU_GEM_METADATA_OP_SET_METADATA 1
234#define AMDGPU_GEM_METADATA_OP_GET_METADATA 2
235
236/** The same structure is shared for input/output */
237struct drm_amdgpu_gem_metadata {
Christian König675da0d2015-06-09 15:54:37 +0200238 /** GEM Object handle */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100239 __u32 handle;
Christian König675da0d2015-06-09 15:54:37 +0200240 /** Do we want get or set metadata */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100241 __u32 op;
Alex Deucher81629cb2015-04-20 16:42:01 -0400242 struct {
Christian König675da0d2015-06-09 15:54:37 +0200243 /** For future use, no flags defined so far */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100244 __u64 flags;
Christian König675da0d2015-06-09 15:54:37 +0200245 /** family specific tiling info */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100246 __u64 tiling_info;
247 __u32 data_size_bytes;
248 __u32 data[64];
Alex Deucher81629cb2015-04-20 16:42:01 -0400249 } data;
250};
251
252struct drm_amdgpu_gem_mmap_in {
Christian König675da0d2015-06-09 15:54:37 +0200253 /** the GEM object handle */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100254 __u32 handle;
255 __u32 _pad;
Alex Deucher81629cb2015-04-20 16:42:01 -0400256};
257
258struct drm_amdgpu_gem_mmap_out {
Christian König675da0d2015-06-09 15:54:37 +0200259 /** mmap offset from the vma offset manager */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100260 __u64 addr_ptr;
Alex Deucher81629cb2015-04-20 16:42:01 -0400261};
262
263union drm_amdgpu_gem_mmap {
264 struct drm_amdgpu_gem_mmap_in in;
265 struct drm_amdgpu_gem_mmap_out out;
266};
267
268struct drm_amdgpu_gem_wait_idle_in {
Christian König675da0d2015-06-09 15:54:37 +0200269 /** GEM object handle */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100270 __u32 handle;
Christian König675da0d2015-06-09 15:54:37 +0200271 /** For future use, no flags defined so far */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100272 __u32 flags;
Christian König675da0d2015-06-09 15:54:37 +0200273 /** Absolute timeout to wait */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100274 __u64 timeout;
Alex Deucher81629cb2015-04-20 16:42:01 -0400275};
276
277struct drm_amdgpu_gem_wait_idle_out {
Christian König675da0d2015-06-09 15:54:37 +0200278 /** BO status: 0 - BO is idle, 1 - BO is busy */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100279 __u32 status;
Christian König675da0d2015-06-09 15:54:37 +0200280 /** Returned current memory domain */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100281 __u32 domain;
Alex Deucher81629cb2015-04-20 16:42:01 -0400282};
283
284union drm_amdgpu_gem_wait_idle {
285 struct drm_amdgpu_gem_wait_idle_in in;
286 struct drm_amdgpu_gem_wait_idle_out out;
287};
288
289struct drm_amdgpu_wait_cs_in {
Christian König675da0d2015-06-09 15:54:37 +0200290 /** Command submission handle */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100291 __u64 handle;
Christian König675da0d2015-06-09 15:54:37 +0200292 /** Absolute timeout to wait */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100293 __u64 timeout;
294 __u32 ip_type;
295 __u32 ip_instance;
296 __u32 ring;
297 __u32 ctx_id;
Alex Deucher81629cb2015-04-20 16:42:01 -0400298};
299
300struct drm_amdgpu_wait_cs_out {
Christian König675da0d2015-06-09 15:54:37 +0200301 /** CS status: 0 - CS completed, 1 - CS still busy */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100302 __u64 status;
Alex Deucher81629cb2015-04-20 16:42:01 -0400303};
304
305union drm_amdgpu_wait_cs {
306 struct drm_amdgpu_wait_cs_in in;
307 struct drm_amdgpu_wait_cs_out out;
308};
309
Marek Olšákd8f65a22015-05-27 14:30:38 +0200310#define AMDGPU_GEM_OP_GET_GEM_CREATE_INFO 0
311#define AMDGPU_GEM_OP_SET_PLACEMENT 1
Alex Deucher81629cb2015-04-20 16:42:01 -0400312
Christian König675da0d2015-06-09 15:54:37 +0200313/* Sets or returns a value associated with a buffer. */
314struct drm_amdgpu_gem_op {
315 /** GEM object handle */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100316 __u32 handle;
Christian König675da0d2015-06-09 15:54:37 +0200317 /** AMDGPU_GEM_OP_* */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100318 __u32 op;
Christian König675da0d2015-06-09 15:54:37 +0200319 /** Input or return value */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100320 __u64 value;
Christian König675da0d2015-06-09 15:54:37 +0200321};
322
Alex Deucher81629cb2015-04-20 16:42:01 -0400323#define AMDGPU_VA_OP_MAP 1
324#define AMDGPU_VA_OP_UNMAP 2
325
Christian Königfc220f62015-06-29 17:12:20 +0200326/* Delay the page table update till the next CS */
327#define AMDGPU_VM_DELAY_UPDATE (1 << 0)
328
Alex Deucher81629cb2015-04-20 16:42:01 -0400329/* Mapping flags */
330/* readable mapping */
331#define AMDGPU_VM_PAGE_READABLE (1 << 1)
332/* writable mapping */
333#define AMDGPU_VM_PAGE_WRITEABLE (1 << 2)
334/* executable mapping, new for VI */
335#define AMDGPU_VM_PAGE_EXECUTABLE (1 << 3)
336
Christian König34b5f6a2015-06-08 15:03:00 +0200337struct drm_amdgpu_gem_va {
Christian König675da0d2015-06-09 15:54:37 +0200338 /** GEM object handle */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100339 __u32 handle;
340 __u32 _pad;
Christian König675da0d2015-06-09 15:54:37 +0200341 /** AMDGPU_VA_OP_* */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100342 __u32 operation;
Christian König675da0d2015-06-09 15:54:37 +0200343 /** AMDGPU_VM_PAGE_* */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100344 __u32 flags;
Christian König675da0d2015-06-09 15:54:37 +0200345 /** va address to assign . Must be correctly aligned.*/
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100346 __u64 va_address;
Christian König675da0d2015-06-09 15:54:37 +0200347 /** Specify offset inside of BO to assign. Must be correctly aligned.*/
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100348 __u64 offset_in_bo;
Christian König675da0d2015-06-09 15:54:37 +0200349 /** Specify mapping size. Must be correctly aligned. */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100350 __u64 map_size;
Alex Deucher81629cb2015-04-20 16:42:01 -0400351};
352
Alex Deucher81629cb2015-04-20 16:42:01 -0400353#define AMDGPU_HW_IP_GFX 0
354#define AMDGPU_HW_IP_COMPUTE 1
355#define AMDGPU_HW_IP_DMA 2
356#define AMDGPU_HW_IP_UVD 3
357#define AMDGPU_HW_IP_VCE 4
358#define AMDGPU_HW_IP_NUM 5
359
360#define AMDGPU_HW_IP_INSTANCE_MAX_COUNT 1
361
362#define AMDGPU_CHUNK_ID_IB 0x01
363#define AMDGPU_CHUNK_ID_FENCE 0x02
Christian König2b48d322015-06-19 17:31:29 +0200364#define AMDGPU_CHUNK_ID_DEPENDENCIES 0x03
Christian König675da0d2015-06-09 15:54:37 +0200365
Alex Deucher81629cb2015-04-20 16:42:01 -0400366struct drm_amdgpu_cs_chunk {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100367 __u32 chunk_id;
368 __u32 length_dw;
369 __u64 chunk_data;
Alex Deucher81629cb2015-04-20 16:42:01 -0400370};
371
372struct drm_amdgpu_cs_in {
373 /** Rendering context id */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100374 __u32 ctx_id;
Alex Deucher81629cb2015-04-20 16:42:01 -0400375 /** Handle of resource list associated with CS */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100376 __u32 bo_list_handle;
377 __u32 num_chunks;
378 __u32 _pad;
379 /** this points to __u64 * which point to cs chunks */
380 __u64 chunks;
Alex Deucher81629cb2015-04-20 16:42:01 -0400381};
382
383struct drm_amdgpu_cs_out {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100384 __u64 handle;
Alex Deucher81629cb2015-04-20 16:42:01 -0400385};
386
387union drm_amdgpu_cs {
Christian König675da0d2015-06-09 15:54:37 +0200388 struct drm_amdgpu_cs_in in;
389 struct drm_amdgpu_cs_out out;
Alex Deucher81629cb2015-04-20 16:42:01 -0400390};
391
392/* Specify flags to be used for IB */
393
394/* This IB should be submitted to CE */
395#define AMDGPU_IB_FLAG_CE (1<<0)
396
Jammy Zhouaa2bdb242015-05-11 23:49:34 +0800397/* CE Preamble */
Jammy Zhoucab6d572015-06-06 04:49:22 +0800398#define AMDGPU_IB_FLAG_PREAMBLE (1<<1)
Jammy Zhouaa2bdb242015-05-11 23:49:34 +0800399
Alex Deucher81629cb2015-04-20 16:42:01 -0400400struct drm_amdgpu_cs_chunk_ib {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100401 __u32 _pad;
Christian König675da0d2015-06-09 15:54:37 +0200402 /** AMDGPU_IB_FLAG_* */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100403 __u32 flags;
Christian König675da0d2015-06-09 15:54:37 +0200404 /** Virtual address to begin IB execution */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100405 __u64 va_start;
Christian König675da0d2015-06-09 15:54:37 +0200406 /** Size of submission */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100407 __u32 ib_bytes;
Christian König675da0d2015-06-09 15:54:37 +0200408 /** HW IP to submit to */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100409 __u32 ip_type;
Christian König675da0d2015-06-09 15:54:37 +0200410 /** HW IP index of the same type to submit to */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100411 __u32 ip_instance;
Christian König675da0d2015-06-09 15:54:37 +0200412 /** Ring index to submit to */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100413 __u32 ring;
Alex Deucher81629cb2015-04-20 16:42:01 -0400414};
415
Christian König2b48d322015-06-19 17:31:29 +0200416struct drm_amdgpu_cs_chunk_dep {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100417 __u32 ip_type;
418 __u32 ip_instance;
419 __u32 ring;
420 __u32 ctx_id;
421 __u64 handle;
Christian König2b48d322015-06-19 17:31:29 +0200422};
423
Alex Deucher81629cb2015-04-20 16:42:01 -0400424struct drm_amdgpu_cs_chunk_fence {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100425 __u32 handle;
426 __u32 offset;
Alex Deucher81629cb2015-04-20 16:42:01 -0400427};
428
429struct drm_amdgpu_cs_chunk_data {
430 union {
431 struct drm_amdgpu_cs_chunk_ib ib_data;
432 struct drm_amdgpu_cs_chunk_fence fence_data;
433 };
434};
435
436/**
437 * Query h/w info: Flag that this is integrated (a.h.a. fusion) GPU
438 *
439 */
440#define AMDGPU_IDS_FLAGS_FUSION 0x1
441
442/* indicate if acceleration can be working */
443#define AMDGPU_INFO_ACCEL_WORKING 0x00
444/* get the crtc_id from the mode object id? */
445#define AMDGPU_INFO_CRTC_FROM_ID 0x01
446/* query hw IP info */
447#define AMDGPU_INFO_HW_IP_INFO 0x02
448/* query hw IP instance count for the specified type */
449#define AMDGPU_INFO_HW_IP_COUNT 0x03
450/* timestamp for GL_ARB_timer_query */
451#define AMDGPU_INFO_TIMESTAMP 0x05
452/* Query the firmware version */
453#define AMDGPU_INFO_FW_VERSION 0x0e
454 /* Subquery id: Query VCE firmware version */
455 #define AMDGPU_INFO_FW_VCE 0x1
456 /* Subquery id: Query UVD firmware version */
457 #define AMDGPU_INFO_FW_UVD 0x2
458 /* Subquery id: Query GMC firmware version */
459 #define AMDGPU_INFO_FW_GMC 0x03
460 /* Subquery id: Query GFX ME firmware version */
461 #define AMDGPU_INFO_FW_GFX_ME 0x04
462 /* Subquery id: Query GFX PFP firmware version */
463 #define AMDGPU_INFO_FW_GFX_PFP 0x05
464 /* Subquery id: Query GFX CE firmware version */
465 #define AMDGPU_INFO_FW_GFX_CE 0x06
466 /* Subquery id: Query GFX RLC firmware version */
467 #define AMDGPU_INFO_FW_GFX_RLC 0x07
468 /* Subquery id: Query GFX MEC firmware version */
469 #define AMDGPU_INFO_FW_GFX_MEC 0x08
470 /* Subquery id: Query SMC firmware version */
471 #define AMDGPU_INFO_FW_SMC 0x0a
472 /* Subquery id: Query SDMA firmware version */
473 #define AMDGPU_INFO_FW_SDMA 0x0b
474/* number of bytes moved for TTM migration */
475#define AMDGPU_INFO_NUM_BYTES_MOVED 0x0f
476/* the used VRAM size */
477#define AMDGPU_INFO_VRAM_USAGE 0x10
478/* the used GTT size */
479#define AMDGPU_INFO_GTT_USAGE 0x11
480/* Information about GDS, etc. resource configuration */
481#define AMDGPU_INFO_GDS_CONFIG 0x13
482/* Query information about VRAM and GTT domains */
483#define AMDGPU_INFO_VRAM_GTT 0x14
484/* Query information about register in MMR address space*/
485#define AMDGPU_INFO_READ_MMR_REG 0x15
486/* Query information about device: rev id, family, etc. */
487#define AMDGPU_INFO_DEV_INFO 0x16
488/* visible vram usage */
489#define AMDGPU_INFO_VIS_VRAM_USAGE 0x17
Marek Olšák83a59b62016-08-17 23:58:58 +0200490/* number of TTM buffer evictions */
491#define AMDGPU_INFO_NUM_EVICTIONS 0x18
Junwei Zhange0adf6c2016-09-29 09:39:10 +0800492/* Query memory about VRAM and GTT domains */
493#define AMDGPU_INFO_MEMORY 0x19
Alex Deucher81629cb2015-04-20 16:42:01 -0400494
495#define AMDGPU_INFO_MMR_SE_INDEX_SHIFT 0
496#define AMDGPU_INFO_MMR_SE_INDEX_MASK 0xff
497#define AMDGPU_INFO_MMR_SH_INDEX_SHIFT 8
498#define AMDGPU_INFO_MMR_SH_INDEX_MASK 0xff
499
Huang Rui000cab92016-06-12 15:44:44 +0800500struct drm_amdgpu_query_fw {
501 /** AMDGPU_INFO_FW_* */
502 __u32 fw_type;
503 /**
504 * Index of the IP if there are more IPs of
505 * the same type.
506 */
507 __u32 ip_instance;
508 /**
509 * Index of the engine. Whether this is used depends
510 * on the firmware type. (e.g. MEC, SDMA)
511 */
512 __u32 index;
513 __u32 _pad;
514};
515
Alex Deucher81629cb2015-04-20 16:42:01 -0400516/* Input structure for the INFO ioctl */
517struct drm_amdgpu_info {
518 /* Where the return value will be stored */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100519 __u64 return_pointer;
Alex Deucher81629cb2015-04-20 16:42:01 -0400520 /* The size of the return value. Just like "size" in "snprintf",
521 * it limits how many bytes the kernel can write. */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100522 __u32 return_size;
Alex Deucher81629cb2015-04-20 16:42:01 -0400523 /* The query request id. */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100524 __u32 query;
Alex Deucher81629cb2015-04-20 16:42:01 -0400525
526 union {
527 struct {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100528 __u32 id;
529 __u32 _pad;
Alex Deucher81629cb2015-04-20 16:42:01 -0400530 } mode_crtc;
531
532 struct {
533 /** AMDGPU_HW_IP_* */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100534 __u32 type;
Alex Deucher81629cb2015-04-20 16:42:01 -0400535 /**
Christian König675da0d2015-06-09 15:54:37 +0200536 * Index of the IP if there are more IPs of the same
537 * type. Ignored by AMDGPU_INFO_HW_IP_COUNT.
Alex Deucher81629cb2015-04-20 16:42:01 -0400538 */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100539 __u32 ip_instance;
Alex Deucher81629cb2015-04-20 16:42:01 -0400540 } query_hw_ip;
541
542 struct {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100543 __u32 dword_offset;
Christian König675da0d2015-06-09 15:54:37 +0200544 /** number of registers to read */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100545 __u32 count;
546 __u32 instance;
Christian König675da0d2015-06-09 15:54:37 +0200547 /** For future use, no flags defined so far */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100548 __u32 flags;
Alex Deucher81629cb2015-04-20 16:42:01 -0400549 } read_mmr_reg;
550
Huang Rui000cab92016-06-12 15:44:44 +0800551 struct drm_amdgpu_query_fw query_fw;
Alex Deucher81629cb2015-04-20 16:42:01 -0400552 };
553};
554
555struct drm_amdgpu_info_gds {
556 /** GDS GFX partition size */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100557 __u32 gds_gfx_partition_size;
Alex Deucher81629cb2015-04-20 16:42:01 -0400558 /** GDS compute partition size */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100559 __u32 compute_partition_size;
Alex Deucher81629cb2015-04-20 16:42:01 -0400560 /** total GDS memory size */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100561 __u32 gds_total_size;
Alex Deucher81629cb2015-04-20 16:42:01 -0400562 /** GWS size per GFX partition */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100563 __u32 gws_per_gfx_partition;
Alex Deucher81629cb2015-04-20 16:42:01 -0400564 /** GSW size per compute partition */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100565 __u32 gws_per_compute_partition;
Alex Deucher81629cb2015-04-20 16:42:01 -0400566 /** OA size per GFX partition */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100567 __u32 oa_per_gfx_partition;
Alex Deucher81629cb2015-04-20 16:42:01 -0400568 /** OA size per compute partition */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100569 __u32 oa_per_compute_partition;
570 __u32 _pad;
Alex Deucher81629cb2015-04-20 16:42:01 -0400571};
572
573struct drm_amdgpu_info_vram_gtt {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100574 __u64 vram_size;
575 __u64 vram_cpu_accessible_size;
576 __u64 gtt_size;
Alex Deucher81629cb2015-04-20 16:42:01 -0400577};
578
Junwei Zhange0adf6c2016-09-29 09:39:10 +0800579struct drm_amdgpu_heap_info {
580 /** max. physical memory */
581 __u64 total_heap_size;
582
583 /** Theoretical max. available memory in the given heap */
584 __u64 usable_heap_size;
585
586 /**
587 * Number of bytes allocated in the heap. This includes all processes
588 * and private allocations in the kernel. It changes when new buffers
589 * are allocated, freed, and moved. It cannot be larger than
590 * heap_size.
591 */
592 __u64 heap_usage;
593
594 /**
595 * Theoretical possible max. size of buffer which
596 * could be allocated in the given heap
597 */
598 __u64 max_allocation;
Junwei Zhang9f6163e2016-09-21 10:17:22 +0800599};
600
Junwei Zhange0adf6c2016-09-29 09:39:10 +0800601struct drm_amdgpu_memory_info {
602 struct drm_amdgpu_heap_info vram;
603 struct drm_amdgpu_heap_info cpu_accessible_vram;
604 struct drm_amdgpu_heap_info gtt;
Junwei Zhangcfa32552016-09-21 10:33:26 +0800605};
606
Alex Deucher81629cb2015-04-20 16:42:01 -0400607struct drm_amdgpu_info_firmware {
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100608 __u32 ver;
609 __u32 feature;
Alex Deucher81629cb2015-04-20 16:42:01 -0400610};
611
Ken Wang81c59f52015-06-03 21:02:01 +0800612#define AMDGPU_VRAM_TYPE_UNKNOWN 0
613#define AMDGPU_VRAM_TYPE_GDDR1 1
614#define AMDGPU_VRAM_TYPE_DDR2 2
615#define AMDGPU_VRAM_TYPE_GDDR3 3
616#define AMDGPU_VRAM_TYPE_GDDR4 4
617#define AMDGPU_VRAM_TYPE_GDDR5 5
618#define AMDGPU_VRAM_TYPE_HBM 6
619#define AMDGPU_VRAM_TYPE_DDR3 7
620
Alex Deucher81629cb2015-04-20 16:42:01 -0400621struct drm_amdgpu_info_device {
622 /** PCI Device ID */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100623 __u32 device_id;
Alex Deucher81629cb2015-04-20 16:42:01 -0400624 /** Internal chip revision: A0, A1, etc.) */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100625 __u32 chip_rev;
626 __u32 external_rev;
Alex Deucher81629cb2015-04-20 16:42:01 -0400627 /** Revision id in PCI Config space */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100628 __u32 pci_rev;
629 __u32 family;
630 __u32 num_shader_engines;
631 __u32 num_shader_arrays_per_engine;
Christian König675da0d2015-06-09 15:54:37 +0200632 /* in KHz */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100633 __u32 gpu_counter_freq;
634 __u64 max_engine_clock;
635 __u64 max_memory_clock;
Alex Deucher81629cb2015-04-20 16:42:01 -0400636 /* cu information */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100637 __u32 cu_active_number;
638 __u32 cu_ao_mask;
639 __u32 cu_bitmap[4][4];
Alex Deucher81629cb2015-04-20 16:42:01 -0400640 /** Render backend pipe mask. One render backend is CB+DB. */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100641 __u32 enabled_rb_pipes_mask;
642 __u32 num_rb_pipes;
643 __u32 num_hw_gfx_contexts;
644 __u32 _pad;
645 __u64 ids_flags;
Alex Deucher81629cb2015-04-20 16:42:01 -0400646 /** Starting virtual address for UMDs. */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100647 __u64 virtual_address_offset;
Jammy Zhou02b70c82015-05-12 22:46:45 +0800648 /** The maximum virtual address */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100649 __u64 virtual_address_max;
Alex Deucher81629cb2015-04-20 16:42:01 -0400650 /** Required alignment of virtual addresses. */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100651 __u32 virtual_address_alignment;
Alex Deucher81629cb2015-04-20 16:42:01 -0400652 /** Page table entry - fragment size */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100653 __u32 pte_fragment_size;
654 __u32 gart_page_size;
Ken Wanga101a892015-06-03 17:47:54 +0800655 /** constant engine ram size*/
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100656 __u32 ce_ram_size;
Jammy Zhoucab6d572015-06-06 04:49:22 +0800657 /** video memory type info*/
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100658 __u32 vram_type;
Ken Wang81c59f52015-06-03 21:02:01 +0800659 /** video memory bit width*/
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100660 __u32 vram_bit_width;
Leo Liufa927542015-07-13 12:46:23 -0400661 /* vce harvesting instance */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100662 __u32 vce_harvest_config;
Alex Deucher81629cb2015-04-20 16:42:01 -0400663};
664
665struct drm_amdgpu_info_hw_ip {
666 /** Version of h/w IP */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100667 __u32 hw_ip_version_major;
668 __u32 hw_ip_version_minor;
Alex Deucher81629cb2015-04-20 16:42:01 -0400669 /** Capabilities */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100670 __u64 capabilities_flags;
Ken Wang71062f42015-06-04 21:26:57 +0800671 /** command buffer address start alignment*/
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100672 __u32 ib_start_alignment;
Ken Wang71062f42015-06-04 21:26:57 +0800673 /** command buffer size alignment*/
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100674 __u32 ib_size_alignment;
Alex Deucher81629cb2015-04-20 16:42:01 -0400675 /** Bitmask of available rings. Bit 0 means ring 0, etc. */
Mikko Rapeli2ce9dde2015-12-02 23:44:33 +0100676 __u32 available_rings;
677 __u32 _pad;
Alex Deucher81629cb2015-04-20 16:42:01 -0400678};
679
680/*
681 * Supported GPU families
682 */
683#define AMDGPU_FAMILY_UNKNOWN 0
Ken Wang295d0da2016-05-24 21:02:53 +0800684#define AMDGPU_FAMILY_SI 110 /* Hainan, Oland, Verde, Pitcairn, Tahiti */
Alex Deucher81629cb2015-04-20 16:42:01 -0400685#define AMDGPU_FAMILY_CI 120 /* Bonaire, Hawaii */
686#define AMDGPU_FAMILY_KV 125 /* Kaveri, Kabini, Mullins */
687#define AMDGPU_FAMILY_VI 130 /* Iceland, Tonga */
Samuel Li39bb0c92015-10-08 16:31:43 -0400688#define AMDGPU_FAMILY_CZ 135 /* Carrizo, Stoney */
Alex Deucher81629cb2015-04-20 16:42:01 -0400689
Emil Velikovcfa71522016-04-07 18:45:18 +0100690#if defined(__cplusplus)
691}
692#endif
693
Alex Deucher81629cb2015-04-20 16:42:01 -0400694#endif