blob: 928b2a68cae5dd4572a93109c24bc2c0322cc62c [file] [log] [blame]
Alex Deucher09361392015-04-20 12:04:22 -04001/*
2 * Copyright 2014 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
Emil Velikova30da8e2015-08-07 17:20:51 +010022 */
Alex Deucher09361392015-04-20 12:04:22 -040023
24/**
25 * \file amdgpu.h
26 *
27 * Declare public libdrm_amdgpu API
28 *
29 * This file define API exposed by libdrm_amdgpu library.
30 * User wanted to use libdrm_amdgpu functionality must include
31 * this file.
32 *
33 */
34#ifndef _AMDGPU_H_
35#define _AMDGPU_H_
36
37#include <stdint.h>
38#include <stdbool.h>
39
Nicolai Hähnle41be41f2017-05-13 23:03:55 +020040#ifdef __cplusplus
41extern "C" {
42#endif
43
Alex Deucher09361392015-04-20 12:04:22 -040044struct drm_amdgpu_info_hw_ip;
45
46/*--------------------------------------------------------------------------*/
47/* --------------------------- Defines ------------------------------------ */
48/*--------------------------------------------------------------------------*/
49
50/**
51 * Define max. number of Command Buffers (IB) which could be sent to the single
52 * hardware IP to accommodate CE/DE requirements
53 *
54 * \sa amdgpu_cs_ib_info
55*/
56#define AMDGPU_CS_MAX_IBS_PER_SUBMIT 4
57
58/**
Marek Olšák67c994f2015-06-26 21:58:17 +020059 * Special timeout value meaning that the timeout is infinite.
Alex Deucher09361392015-04-20 12:04:22 -040060 */
61#define AMDGPU_TIMEOUT_INFINITE 0xffffffffffffffffull
62
Marek Olšák67c994f2015-06-26 21:58:17 +020063/**
Christian König5463d2e2015-07-09 11:48:32 +020064 * Used in amdgpu_cs_query_fence_status(), meaning that the given timeout
Marek Olšák67c994f2015-06-26 21:58:17 +020065 * is absolute.
66 */
67#define AMDGPU_QUERY_FENCE_TIMEOUT_IS_ABSOLUTE (1 << 0)
Alex Deucher09361392015-04-20 12:04:22 -040068
Alex Deucher09361392015-04-20 12:04:22 -040069/*--------------------------------------------------------------------------*/
70/* ----------------------------- Enums ------------------------------------ */
71/*--------------------------------------------------------------------------*/
72
73/**
74 * Enum describing possible handle types
75 *
76 * \sa amdgpu_bo_import, amdgpu_bo_export
77 *
78*/
79enum amdgpu_bo_handle_type {
80 /** GEM flink name (needs DRM authentication, used by DRI2) */
81 amdgpu_bo_handle_type_gem_flink_name = 0,
82
83 /** KMS handle which is used by all driver ioctls */
84 amdgpu_bo_handle_type_kms = 1,
85
86 /** DMA-buf fd handle */
87 amdgpu_bo_handle_type_dma_buf_fd = 2
88};
89
Sabre Shao23fab592015-07-09 13:50:36 +080090/** Define known types of GPU VM VA ranges */
91enum amdgpu_gpu_va_range
92{
93 /** Allocate from "normal"/general range */
94 amdgpu_gpu_va_range_general = 0
95};
Alex Deucher09361392015-04-20 12:04:22 -040096
Marek Olšákad5b7022018-02-02 18:15:00 +010097enum amdgpu_sw_info {
98 amdgpu_sw_info_address32_hi = 0,
99};
100
Alex Deucher09361392015-04-20 12:04:22 -0400101/*--------------------------------------------------------------------------*/
102/* -------------------------- Datatypes ----------------------------------- */
103/*--------------------------------------------------------------------------*/
104
105/**
106 * Define opaque pointer to context associated with fd.
107 * This context will be returned as the result of
108 * "initialize" function and should be pass as the first
109 * parameter to any API call
110 */
111typedef struct amdgpu_device *amdgpu_device_handle;
112
113/**
114 * Define GPU Context type as pointer to opaque structure
115 * Example of GPU Context is the "rendering" context associated
116 * with OpenGL context (glCreateContext)
117 */
118typedef struct amdgpu_context *amdgpu_context_handle;
119
120/**
121 * Define handle for amdgpu resources: buffer, GDS, etc.
122 */
123typedef struct amdgpu_bo *amdgpu_bo_handle;
124
125/**
Christian König6dc2eaf2015-04-22 14:52:34 +0200126 * Define handle for list of BOs
127 */
128typedef struct amdgpu_bo_list *amdgpu_bo_list_handle;
129
Sabre Shao23fab592015-07-09 13:50:36 +0800130/**
131 * Define handle to be used to work with VA allocated ranges
132 */
133typedef struct amdgpu_va *amdgpu_va_handle;
Alex Deucher09361392015-04-20 12:04:22 -0400134
Marek Olšák6afadea2016-01-12 22:13:07 +0100135/**
136 * Define handle for semaphore
137 */
138typedef struct amdgpu_semaphore *amdgpu_semaphore_handle;
139
Alex Deucher09361392015-04-20 12:04:22 -0400140/*--------------------------------------------------------------------------*/
141/* -------------------------- Structures ---------------------------------- */
142/*--------------------------------------------------------------------------*/
143
144/**
145 * Structure describing memory allocation request
146 *
147 * \sa amdgpu_bo_alloc()
148 *
149*/
150struct amdgpu_bo_alloc_request {
151 /** Allocation request. It must be aligned correctly. */
152 uint64_t alloc_size;
153
154 /**
155 * It may be required to have some specific alignment requirements
156 * for physical back-up storage (e.g. for displayable surface).
157 * If 0 there is no special alignment requirement
158 */
159 uint64_t phys_alignment;
160
161 /**
162 * UMD should specify where to allocate memory and how it
163 * will be accessed by the CPU.
164 */
165 uint32_t preferred_heap;
166
167 /** Additional flags passed on allocation */
168 uint64_t flags;
169};
170
171/**
Alex Deucher09361392015-04-20 12:04:22 -0400172 * Special UMD specific information associated with buffer.
173 *
174 * It may be need to pass some buffer charactersitic as part
175 * of buffer sharing. Such information are defined UMD and
176 * opaque for libdrm_amdgpu as well for kernel driver.
177 *
178 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info,
179 * amdgpu_bo_import(), amdgpu_bo_export
180 *
181*/
182struct amdgpu_bo_metadata {
183 /** Special flag associated with surface */
184 uint64_t flags;
185
186 /**
187 * ASIC-specific tiling information (also used by DCE).
188 * The encoding is defined by the AMDGPU_TILING_* definitions.
189 */
190 uint64_t tiling_info;
191
192 /** Size of metadata associated with the buffer, in bytes. */
193 uint32_t size_metadata;
194
195 /** UMD specific metadata. Opaque for kernel */
196 uint32_t umd_metadata[64];
197};
198
199/**
200 * Structure describing allocated buffer. Client may need
201 * to query such information as part of 'sharing' buffers mechanism
202 *
203 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info(),
204 * amdgpu_bo_import(), amdgpu_bo_export()
205*/
206struct amdgpu_bo_info {
207 /** Allocated memory size */
208 uint64_t alloc_size;
209
210 /**
211 * It may be required to have some specific alignment requirements
212 * for physical back-up storage.
213 */
214 uint64_t phys_alignment;
215
Alex Deucher09361392015-04-20 12:04:22 -0400216 /** Heap where to allocate memory. */
217 uint32_t preferred_heap;
218
219 /** Additional allocation flags. */
220 uint64_t alloc_flags;
221
222 /** Metadata associated with buffer if any. */
223 struct amdgpu_bo_metadata metadata;
224};
225
226/**
227 * Structure with information about "imported" buffer
228 *
229 * \sa amdgpu_bo_import()
230 *
231 */
232struct amdgpu_bo_import_result {
233 /** Handle of memory/buffer to use */
Christian König558e1292015-06-30 16:04:44 +0200234 amdgpu_bo_handle buf_handle;
Alex Deucher09361392015-04-20 12:04:22 -0400235
236 /** Buffer size */
237 uint64_t alloc_size;
Alex Deucher09361392015-04-20 12:04:22 -0400238};
239
Alex Deucher09361392015-04-20 12:04:22 -0400240/**
241 *
242 * Structure to describe GDS partitioning information.
243 * \note OA and GWS resources are asscoiated with GDS partition
244 *
245 * \sa amdgpu_gpu_resource_query_gds_info
246 *
247*/
248struct amdgpu_gds_resource_info {
Christian König558e1292015-06-30 16:04:44 +0200249 uint32_t gds_gfx_partition_size;
250 uint32_t compute_partition_size;
251 uint32_t gds_total_size;
252 uint32_t gws_per_gfx_partition;
253 uint32_t gws_per_compute_partition;
254 uint32_t oa_per_gfx_partition;
255 uint32_t oa_per_compute_partition;
Alex Deucher09361392015-04-20 12:04:22 -0400256};
257
Alex Deucher09361392015-04-20 12:04:22 -0400258/**
Christian König5463d2e2015-07-09 11:48:32 +0200259 * Structure describing CS fence
Christian König0f37bc92015-06-24 14:17:57 +0200260 *
Christian König5463d2e2015-07-09 11:48:32 +0200261 * \sa amdgpu_cs_query_fence_status(), amdgpu_cs_request, amdgpu_cs_submit()
Christian König0f37bc92015-06-24 14:17:57 +0200262 *
263*/
Christian König5463d2e2015-07-09 11:48:32 +0200264struct amdgpu_cs_fence {
265
266 /** In which context IB was sent to execution */
Christian König558e1292015-06-30 16:04:44 +0200267 amdgpu_context_handle context;
Christian König0f37bc92015-06-24 14:17:57 +0200268
269 /** To which HW IP type the fence belongs */
Christian König558e1292015-06-30 16:04:44 +0200270 uint32_t ip_type;
Christian König0f37bc92015-06-24 14:17:57 +0200271
272 /** IP instance index if there are several IPs of the same type. */
Christian König558e1292015-06-30 16:04:44 +0200273 uint32_t ip_instance;
Christian König0f37bc92015-06-24 14:17:57 +0200274
275 /** Ring index of the HW IP */
Christian König558e1292015-06-30 16:04:44 +0200276 uint32_t ring;
Christian König0f37bc92015-06-24 14:17:57 +0200277
Christian König558e1292015-06-30 16:04:44 +0200278 /** Specify fence for which we need to check submission status.*/
279 uint64_t fence;
Christian König0f37bc92015-06-24 14:17:57 +0200280};
281
282/**
Alex Deucher09361392015-04-20 12:04:22 -0400283 * Structure describing IB
284 *
285 * \sa amdgpu_cs_request, amdgpu_cs_submit()
286 *
287*/
288struct amdgpu_cs_ib_info {
289 /** Special flags */
Christian König558e1292015-06-30 16:04:44 +0200290 uint64_t flags;
Alex Deucher09361392015-04-20 12:04:22 -0400291
Marek Olšák76af5c22015-06-02 13:05:41 +0200292 /** Virtual MC address of the command buffer */
Christian König558e1292015-06-30 16:04:44 +0200293 uint64_t ib_mc_address;
Alex Deucher09361392015-04-20 12:04:22 -0400294
295 /**
296 * Size of Command Buffer to be submitted.
297 * - The size is in units of dwords (4 bytes).
Alex Deucher09361392015-04-20 12:04:22 -0400298 * - Could be 0
299 */
Christian König558e1292015-06-30 16:04:44 +0200300 uint32_t size;
Alex Deucher09361392015-04-20 12:04:22 -0400301};
302
303/**
Ken Wang926c8052015-07-10 22:22:27 +0800304 * Structure describing fence information
305 *
306 * \sa amdgpu_cs_request, amdgpu_cs_query_fence,
307 * amdgpu_cs_submit(), amdgpu_cs_query_fence_status()
308*/
309struct amdgpu_cs_fence_info {
310 /** buffer object for the fence */
311 amdgpu_bo_handle handle;
312
313 /** fence offset in the unit of sizeof(uint64_t) */
314 uint64_t offset;
315};
316
317/**
Alex Deucher09361392015-04-20 12:04:22 -0400318 * Structure describing submission request
319 *
320 * \note We could have several IBs as packet. e.g. CE, CE, DE case for gfx
321 *
322 * \sa amdgpu_cs_submit()
323*/
324struct amdgpu_cs_request {
325 /** Specify flags with additional information */
Christian König558e1292015-06-30 16:04:44 +0200326 uint64_t flags;
Alex Deucher09361392015-04-20 12:04:22 -0400327
328 /** Specify HW IP block type to which to send the IB. */
Christian König558e1292015-06-30 16:04:44 +0200329 unsigned ip_type;
Alex Deucher09361392015-04-20 12:04:22 -0400330
331 /** IP instance index if there are several IPs of the same type. */
Christian König558e1292015-06-30 16:04:44 +0200332 unsigned ip_instance;
Alex Deucher09361392015-04-20 12:04:22 -0400333
334 /**
335 * Specify ring index of the IP. We could have several rings
336 * in the same IP. E.g. 0 for SDMA0 and 1 for SDMA1.
337 */
Christian König558e1292015-06-30 16:04:44 +0200338 uint32_t ring;
Alex Deucher09361392015-04-20 12:04:22 -0400339
340 /**
Christian König6dc2eaf2015-04-22 14:52:34 +0200341 * List handle with resources used by this request.
Alex Deucher09361392015-04-20 12:04:22 -0400342 */
Christian König6dc2eaf2015-04-22 14:52:34 +0200343 amdgpu_bo_list_handle resources;
Alex Deucher09361392015-04-20 12:04:22 -0400344
Christian König0f37bc92015-06-24 14:17:57 +0200345 /**
346 * Number of dependencies this Command submission needs to
347 * wait for before starting execution.
348 */
349 uint32_t number_of_dependencies;
350
351 /**
352 * Array of dependencies which need to be met before
353 * execution can start.
354 */
Christian König5463d2e2015-07-09 11:48:32 +0200355 struct amdgpu_cs_fence *dependencies;
Christian König0f37bc92015-06-24 14:17:57 +0200356
Alex Deucher09361392015-04-20 12:04:22 -0400357 /** Number of IBs to submit in the field ibs. */
358 uint32_t number_of_ibs;
359
360 /**
361 * IBs to submit. Those IBs will be submit together as single entity
362 */
363 struct amdgpu_cs_ib_info *ibs;
Ken Wang926c8052015-07-10 22:22:27 +0800364
365 /**
366 * The returned sequence number for the command submission
367 */
368 uint64_t seq_no;
369
370 /**
371 * The fence information
372 */
373 struct amdgpu_cs_fence_info fence_info;
Alex Deucher09361392015-04-20 12:04:22 -0400374};
375
376/**
Alex Deucher09361392015-04-20 12:04:22 -0400377 * Structure which provide information about GPU VM MC Address space
378 * alignments requirements
379 *
380 * \sa amdgpu_query_buffer_size_alignment
381 */
382struct amdgpu_buffer_size_alignments {
383 /** Size alignment requirement for allocation in
384 * local memory */
385 uint64_t size_local;
386
387 /**
388 * Size alignment requirement for allocation in remote memory
389 */
390 uint64_t size_remote;
391};
392
Alex Deucher09361392015-04-20 12:04:22 -0400393/**
394 * Structure which provide information about heap
395 *
396 * \sa amdgpu_query_heap_info()
397 *
398 */
399struct amdgpu_heap_info {
400 /** Theoretical max. available memory in the given heap */
Christian König558e1292015-06-30 16:04:44 +0200401 uint64_t heap_size;
Alex Deucher09361392015-04-20 12:04:22 -0400402
403 /**
404 * Number of bytes allocated in the heap. This includes all processes
405 * and private allocations in the kernel. It changes when new buffers
406 * are allocated, freed, and moved. It cannot be larger than
407 * heap_size.
408 */
Christian König558e1292015-06-30 16:04:44 +0200409 uint64_t heap_usage;
Alex Deucher09361392015-04-20 12:04:22 -0400410
411 /**
412 * Theoretical possible max. size of buffer which
413 * could be allocated in the given heap
414 */
Christian König558e1292015-06-30 16:04:44 +0200415 uint64_t max_allocation;
Alex Deucher09361392015-04-20 12:04:22 -0400416};
417
Alex Deucher09361392015-04-20 12:04:22 -0400418/**
419 * Describe GPU h/w info needed for UMD correct initialization
420 *
421 * \sa amdgpu_query_gpu_info()
422*/
423struct amdgpu_gpu_info {
424 /** Asic id */
425 uint32_t asic_id;
Christian König558e1292015-06-30 16:04:44 +0200426 /** Chip revision */
Alex Deucher09361392015-04-20 12:04:22 -0400427 uint32_t chip_rev;
428 /** Chip external revision */
429 uint32_t chip_external_rev;
430 /** Family ID */
431 uint32_t family_id;
432 /** Special flags */
433 uint64_t ids_flags;
434 /** max engine clock*/
435 uint64_t max_engine_clk;
Ken Wangfc9fc7d2015-06-03 17:07:44 +0800436 /** max memory clock */
437 uint64_t max_memory_clk;
Alex Deucher09361392015-04-20 12:04:22 -0400438 /** number of shader engines */
439 uint32_t num_shader_engines;
440 /** number of shader arrays per engine */
441 uint32_t num_shader_arrays_per_engine;
442 /** Number of available good shader pipes */
443 uint32_t avail_quad_shader_pipes;
444 /** Max. number of shader pipes.(including good and bad pipes */
445 uint32_t max_quad_shader_pipes;
446 /** Number of parameter cache entries per shader quad pipe */
447 uint32_t cache_entries_per_quad_pipe;
448 /** Number of available graphics context */
449 uint32_t num_hw_gfx_contexts;
450 /** Number of render backend pipes */
451 uint32_t rb_pipes;
Alex Deucher09361392015-04-20 12:04:22 -0400452 /** Enabled render backend pipe mask */
453 uint32_t enabled_rb_pipes_mask;
454 /** Frequency of GPU Counter */
455 uint32_t gpu_counter_freq;
456 /** CC_RB_BACKEND_DISABLE.BACKEND_DISABLE per SE */
457 uint32_t backend_disable[4];
458 /** Value of MC_ARB_RAMCFG register*/
459 uint32_t mc_arb_ramcfg;
460 /** Value of GB_ADDR_CONFIG */
461 uint32_t gb_addr_cfg;
462 /** Values of the GB_TILE_MODE0..31 registers */
463 uint32_t gb_tile_mode[32];
464 /** Values of GB_MACROTILE_MODE0..15 registers */
465 uint32_t gb_macro_tile_mode[16];
466 /** Value of PA_SC_RASTER_CONFIG register per SE */
467 uint32_t pa_sc_raster_cfg[4];
468 /** Value of PA_SC_RASTER_CONFIG_1 register per SE */
469 uint32_t pa_sc_raster_cfg1[4];
470 /* CU info */
471 uint32_t cu_active_number;
472 uint32_t cu_ao_mask;
473 uint32_t cu_bitmap[4][4];
Ken Wang4bf29412015-06-03 17:15:29 +0800474 /* video memory type info*/
475 uint32_t vram_type;
476 /* video memory bit width*/
477 uint32_t vram_bit_width;
Ken Wangcdd1edc2015-06-03 17:21:27 +0800478 /** constant engine ram size*/
479 uint32_t ce_ram_size;
Leo Liud2cbe9e2015-07-13 12:51:34 -0400480 /* vce harvesting instance */
481 uint32_t vce_harvest_config;
Jammy Zhoud01c3612015-08-03 15:46:42 +0800482 /* PCI revision ID */
483 uint32_t pci_rev_id;
Alex Deucher09361392015-04-20 12:04:22 -0400484};
485
486
487/*--------------------------------------------------------------------------*/
488/*------------------------- Functions --------------------------------------*/
489/*--------------------------------------------------------------------------*/
490
491/*
492 * Initialization / Cleanup
493 *
494*/
495
Alex Deucher09361392015-04-20 12:04:22 -0400496/**
497 *
498 * \param fd - \c [in] File descriptor for AMD GPU device
499 * received previously as the result of
500 * e.g. drmOpen() call.
Christian König558e1292015-06-30 16:04:44 +0200501 * For legacy fd type, the DRI2/DRI3
502 * authentication should be done before
503 * calling this function.
Alex Deucher09361392015-04-20 12:04:22 -0400504 * \param major_version - \c [out] Major version of library. It is assumed
505 * that adding new functionality will cause
506 * increase in major version
507 * \param minor_version - \c [out] Minor version of library
508 * \param device_handle - \c [out] Pointer to opaque context which should
509 * be passed as the first parameter on each
510 * API call
511 *
512 *
513 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400514 * <0 - Negative POSIX Error code
515 *
516 *
517 * \sa amdgpu_device_deinitialize()
518*/
519int amdgpu_device_initialize(int fd,
520 uint32_t *major_version,
521 uint32_t *minor_version,
522 amdgpu_device_handle *device_handle);
523
Alex Deucher09361392015-04-20 12:04:22 -0400524/**
525 *
526 * When access to such library does not needed any more the special
527 * function must be call giving opportunity to clean up any
528 * resources if needed.
529 *
530 * \param device_handle - \c [in] Context associated with file
531 * descriptor for AMD GPU device
532 * received previously as the
533 * result e.g. of drmOpen() call.
534 *
535 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400536 * <0 - Negative POSIX Error code
537 *
538 * \sa amdgpu_device_initialize()
539 *
540*/
541int amdgpu_device_deinitialize(amdgpu_device_handle device_handle);
542
Alex Deucher09361392015-04-20 12:04:22 -0400543/*
544 * Memory Management
545 *
546*/
547
548/**
549 * Allocate memory to be used by UMD for GPU related operations
550 *
551 * \param dev - \c [in] Device handle.
552 * See #amdgpu_device_initialize()
553 * \param alloc_buffer - \c [in] Pointer to the structure describing an
554 * allocation request
Jammy Zhou8aeffcc2015-07-13 20:57:44 +0800555 * \param buf_handle - \c [out] Allocated buffer handle
Alex Deucher09361392015-04-20 12:04:22 -0400556 *
557 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400558 * <0 - Negative POSIX Error code
559 *
560 * \sa amdgpu_bo_free()
561*/
562int amdgpu_bo_alloc(amdgpu_device_handle dev,
563 struct amdgpu_bo_alloc_request *alloc_buffer,
Jammy Zhou8aeffcc2015-07-13 20:57:44 +0800564 amdgpu_bo_handle *buf_handle);
Alex Deucher09361392015-04-20 12:04:22 -0400565
566/**
567 * Associate opaque data with buffer to be queried by another UMD
568 *
569 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
570 * \param buf_handle - \c [in] Buffer handle
571 * \param info - \c [in] Metadata to associated with buffer
572 *
573 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400574 * <0 - Negative POSIX Error code
575*/
576int amdgpu_bo_set_metadata(amdgpu_bo_handle buf_handle,
577 struct amdgpu_bo_metadata *info);
578
579/**
580 * Query buffer information including metadata previusly associated with
581 * buffer.
582 *
583 * \param dev - \c [in] Device handle.
584 * See #amdgpu_device_initialize()
585 * \param buf_handle - \c [in] Buffer handle
586 * \param info - \c [out] Structure describing buffer
587 *
588 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400589 * <0 - Negative POSIX Error code
590 *
591 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc()
592*/
593int amdgpu_bo_query_info(amdgpu_bo_handle buf_handle,
594 struct amdgpu_bo_info *info);
595
596/**
597 * Allow others to get access to buffer
598 *
599 * \param dev - \c [in] Device handle.
600 * See #amdgpu_device_initialize()
601 * \param buf_handle - \c [in] Buffer handle
602 * \param type - \c [in] Type of handle requested
603 * \param shared_handle - \c [out] Special "shared" handle
604 *
605 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400606 * <0 - Negative POSIX Error code
607 *
608 * \sa amdgpu_bo_import()
609 *
610*/
611int amdgpu_bo_export(amdgpu_bo_handle buf_handle,
612 enum amdgpu_bo_handle_type type,
613 uint32_t *shared_handle);
614
615/**
616 * Request access to "shared" buffer
617 *
618 * \param dev - \c [in] Device handle.
619 * See #amdgpu_device_initialize()
620 * \param type - \c [in] Type of handle requested
621 * \param shared_handle - \c [in] Shared handle received as result "import"
622 * operation
623 * \param output - \c [out] Pointer to structure with information
624 * about imported buffer
625 *
626 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400627 * <0 - Negative POSIX Error code
628 *
629 * \note Buffer must be "imported" only using new "fd" (different from
630 * one used by "exporter").
631 *
632 * \sa amdgpu_bo_export()
633 *
634*/
635int amdgpu_bo_import(amdgpu_device_handle dev,
636 enum amdgpu_bo_handle_type type,
637 uint32_t shared_handle,
638 struct amdgpu_bo_import_result *output);
639
640/**
Christian König558e1292015-06-30 16:04:44 +0200641 * Request GPU access to user allocated memory e.g. via "malloc"
642 *
643 * \param dev - [in] Device handle. See #amdgpu_device_initialize()
644 * \param cpu - [in] CPU address of user allocated memory which we
645 * want to map to GPU address space (make GPU accessible)
646 * (This address must be correctly aligned).
647 * \param size - [in] Size of allocation (must be correctly aligned)
Jammy Zhou8aeffcc2015-07-13 20:57:44 +0800648 * \param buf_handle - [out] Buffer handle for the userptr memory
Christian König558e1292015-06-30 16:04:44 +0200649 * resource on submission and be used in other operations.
650 *
651 *
Christian König28462eb2015-06-30 16:27:27 +0200652 * \return 0 on success\n
653 * <0 - Negative POSIX Error code
Christian König558e1292015-06-30 16:04:44 +0200654 *
655 * \note
656 * This call doesn't guarantee that such memory will be persistently
657 * "locked" / make non-pageable. The purpose of this call is to provide
658 * opportunity for GPU get access to this resource during submission.
659 *
660 * The maximum amount of memory which could be mapped in this call depends
661 * if overcommit is disabled or not. If overcommit is disabled than the max.
662 * amount of memory to be pinned will be limited by left "free" size in total
663 * amount of memory which could be locked simultaneously ("GART" size).
664 *
665 * Supported (theoretical) max. size of mapping is restricted only by
666 * "GART" size.
667 *
668 * It is responsibility of caller to correctly specify access rights
669 * on VA assignment.
670*/
671int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev,
672 void *cpu, uint64_t size,
Jammy Zhou8aeffcc2015-07-13 20:57:44 +0800673 amdgpu_bo_handle *buf_handle);
Christian König558e1292015-06-30 16:04:44 +0200674
675/**
Alex Deucher09361392015-04-20 12:04:22 -0400676 * Free previosuly allocated memory
677 *
678 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
679 * \param buf_handle - \c [in] Buffer handle to free
680 *
681 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400682 * <0 - Negative POSIX Error code
683 *
684 * \note In the case of memory shared between different applications all
685 * resources will be “physically” freed only all such applications
686 * will be terminated
687 * \note If is UMD responsibility to ‘free’ buffer only when there is no
688 * more GPU access
689 *
690 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc()
691 *
692*/
693int amdgpu_bo_free(amdgpu_bo_handle buf_handle);
694
695/**
Eric Engestrom0b3f9782016-04-03 19:48:06 +0100696 * Request CPU access to GPU accessible memory
Alex Deucher09361392015-04-20 12:04:22 -0400697 *
698 * \param buf_handle - \c [in] Buffer handle
699 * \param cpu - \c [out] CPU address to be used for access
700 *
701 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400702 * <0 - Negative POSIX Error code
703 *
704 * \sa amdgpu_bo_cpu_unmap()
705 *
706*/
707int amdgpu_bo_cpu_map(amdgpu_bo_handle buf_handle, void **cpu);
708
709/**
710 * Release CPU access to GPU memory
711 *
712 * \param buf_handle - \c [in] Buffer handle
713 *
714 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400715 * <0 - Negative POSIX Error code
716 *
717 * \sa amdgpu_bo_cpu_map()
718 *
719*/
720int amdgpu_bo_cpu_unmap(amdgpu_bo_handle buf_handle);
721
Alex Deucher09361392015-04-20 12:04:22 -0400722/**
723 * Wait until a buffer is not used by the device.
724 *
Emil Velikovc19fa2b2015-08-07 16:48:02 +0100725 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
Alex Deucher09361392015-04-20 12:04:22 -0400726 * \param buf_handle - \c [in] Buffer handle.
727 * \param timeout_ns - Timeout in nanoseconds.
728 * \param buffer_busy - 0 if buffer is idle, all GPU access was completed
729 * and no GPU access is scheduled.
730 * 1 GPU access is in fly or scheduled
731 *
732 * \return 0 - on success
Christian König558e1292015-06-30 16:04:44 +0200733 * <0 - Negative POSIX Error code
Alex Deucher09361392015-04-20 12:04:22 -0400734 */
735int amdgpu_bo_wait_for_idle(amdgpu_bo_handle buf_handle,
736 uint64_t timeout_ns,
737 bool *buffer_busy);
738
Christian König6dc2eaf2015-04-22 14:52:34 +0200739/**
740 * Creates a BO list handle for command submission.
741 *
742 * \param dev - \c [in] Device handle.
743 * See #amdgpu_device_initialize()
744 * \param number_of_resources - \c [in] Number of BOs in the list
745 * \param resources - \c [in] List of BO handles
746 * \param resource_prios - \c [in] Optional priority for each handle
747 * \param result - \c [out] Created BO list handle
748 *
749 * \return 0 on success\n
Christian König6dc2eaf2015-04-22 14:52:34 +0200750 * <0 - Negative POSIX Error code
751 *
752 * \sa amdgpu_bo_list_destroy()
753*/
754int amdgpu_bo_list_create(amdgpu_device_handle dev,
755 uint32_t number_of_resources,
756 amdgpu_bo_handle *resources,
757 uint8_t *resource_prios,
758 amdgpu_bo_list_handle *result);
759
760/**
761 * Destroys a BO list handle.
762 *
763 * \param handle - \c [in] BO list handle.
764 *
765 * \return 0 on success\n
Christian König6dc2eaf2015-04-22 14:52:34 +0200766 * <0 - Negative POSIX Error code
767 *
768 * \sa amdgpu_bo_list_create()
769*/
770int amdgpu_bo_list_destroy(amdgpu_bo_list_handle handle);
Alex Deucher09361392015-04-20 12:04:22 -0400771
Jammy Zhou72446982015-05-18 20:27:24 +0800772/**
773 * Update resources for existing BO list
774 *
775 * \param handle - \c [in] BO list handle
776 * \param number_of_resources - \c [in] Number of BOs in the list
777 * \param resources - \c [in] List of BO handles
778 * \param resource_prios - \c [in] Optional priority for each handle
779 *
780 * \return 0 on success\n
Jammy Zhou72446982015-05-18 20:27:24 +0800781 * <0 - Negative POSIX Error code
782 *
783 * \sa amdgpu_bo_list_update()
784*/
785int amdgpu_bo_list_update(amdgpu_bo_list_handle handle,
786 uint32_t number_of_resources,
787 amdgpu_bo_handle *resources,
788 uint8_t *resource_prios);
789
Alex Deucher09361392015-04-20 12:04:22 -0400790/*
Alex Deucher09361392015-04-20 12:04:22 -0400791 * GPU Execution context
792 *
793*/
794
795/**
796 * Create GPU execution Context
797 *
798 * For the purpose of GPU Scheduler and GPU Robustness extensions it is
799 * necessary to have information/identify rendering/compute contexts.
800 * It also may be needed to associate some specific requirements with such
801 * contexts. Kernel driver will guarantee that submission from the same
802 * context will always be executed in order (first come, first serve).
803 *
804 *
Andres Rodriguez35bc82c2017-10-20 10:57:59 -0400805 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
806 * \param priority - \c [in] Context creation flags. See AMDGPU_CTX_PRIORITY_*
807 * \param context - \c [out] GPU Context handle
Alex Deucher09361392015-04-20 12:04:22 -0400808 *
809 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400810 * <0 - Negative POSIX Error code
811 *
812 * \sa amdgpu_cs_ctx_free()
813 *
814*/
Andres Rodriguez35bc82c2017-10-20 10:57:59 -0400815int amdgpu_cs_ctx_create2(amdgpu_device_handle dev,
816 uint32_t priority,
817 amdgpu_context_handle *context);
818/**
819 * Create GPU execution Context
820 *
821 * Refer to amdgpu_cs_ctx_create2 for full documentation. This call
822 * is missing the priority parameter.
823 *
824 * \sa amdgpu_cs_ctx_create2()
825 *
826*/
Alex Deucher09361392015-04-20 12:04:22 -0400827int amdgpu_cs_ctx_create(amdgpu_device_handle dev,
828 amdgpu_context_handle *context);
829
830/**
831 *
832 * Destroy GPU execution context when not needed any more
833 *
Alex Deucher09361392015-04-20 12:04:22 -0400834 * \param context - \c [in] GPU Context handle
835 *
836 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400837 * <0 - Negative POSIX Error code
838 *
839 * \sa amdgpu_cs_ctx_create()
840 *
841*/
Christian König9c2afff2015-04-22 12:21:13 +0200842int amdgpu_cs_ctx_free(amdgpu_context_handle context);
Alex Deucher09361392015-04-20 12:04:22 -0400843
844/**
845 * Query reset state for the specific GPU Context
846 *
Alex Deucher09361392015-04-20 12:04:22 -0400847 * \param context - \c [in] GPU Context handle
Marek Olšák4b39a8e2015-05-05 21:23:02 +0200848 * \param state - \c [out] One of AMDGPU_CTX_*_RESET
849 * \param hangs - \c [out] Number of hangs caused by the context.
Alex Deucher09361392015-04-20 12:04:22 -0400850 *
851 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400852 * <0 - Negative POSIX Error code
853 *
854 * \sa amdgpu_cs_ctx_create()
855 *
856*/
Christian König9c2afff2015-04-22 12:21:13 +0200857int amdgpu_cs_query_reset_state(amdgpu_context_handle context,
Marek Olšák4b39a8e2015-05-05 21:23:02 +0200858 uint32_t *state, uint32_t *hangs);
Alex Deucher09361392015-04-20 12:04:22 -0400859
Alex Deucher09361392015-04-20 12:04:22 -0400860/*
861 * Command Buffers Management
862 *
863*/
864
Alex Deucher09361392015-04-20 12:04:22 -0400865/**
866 * Send request to submit command buffers to hardware.
867 *
868 * Kernel driver could use GPU Scheduler to make decision when physically
869 * sent this request to the hardware. Accordingly this request could be put
870 * in queue and sent for execution later. The only guarantee is that request
871 * from the same GPU context to the same ip:ip_instance:ring will be executed in
872 * order.
873 *
Ken Wang926c8052015-07-10 22:22:27 +0800874 * The caller can specify the user fence buffer/location with the fence_info in the
Eric Engestrom0b3f9782016-04-03 19:48:06 +0100875 * cs_request.The sequence number is returned via the 'seq_no' parameter
Ken Wang926c8052015-07-10 22:22:27 +0800876 * in ibs_request structure.
877 *
Alex Deucher09361392015-04-20 12:04:22 -0400878 *
879 * \param dev - \c [in] Device handle.
880 * See #amdgpu_device_initialize()
881 * \param context - \c [in] GPU Context
882 * \param flags - \c [in] Global submission flags
Ken Wang926c8052015-07-10 22:22:27 +0800883 * \param ibs_request - \c [in/out] Pointer to submission requests.
Alex Deucher09361392015-04-20 12:04:22 -0400884 * We could submit to the several
885 * engines/rings simulteniously as
886 * 'atomic' operation
887 * \param number_of_requests - \c [in] Number of submission requests
Alex Deucher09361392015-04-20 12:04:22 -0400888 *
889 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400890 * <0 - Negative POSIX Error code
891 *
Alex Deucher09361392015-04-20 12:04:22 -0400892 * \note It is required to pass correct resource list with buffer handles
893 * which will be accessible by command buffers from submission
894 * This will allow kernel driver to correctly implement "paging".
895 * Failure to do so will have unpredictable results.
896 *
897 * \sa amdgpu_command_buffer_alloc(), amdgpu_command_buffer_free(),
898 * amdgpu_cs_query_fence_status()
899 *
900*/
Christian König9c2afff2015-04-22 12:21:13 +0200901int amdgpu_cs_submit(amdgpu_context_handle context,
Alex Deucher09361392015-04-20 12:04:22 -0400902 uint64_t flags,
903 struct amdgpu_cs_request *ibs_request,
Ken Wang926c8052015-07-10 22:22:27 +0800904 uint32_t number_of_requests);
Alex Deucher09361392015-04-20 12:04:22 -0400905
906/**
907 * Query status of Command Buffer Submission
908 *
Alex Deucher09361392015-04-20 12:04:22 -0400909 * \param fence - \c [in] Structure describing fence to query
Jammy Zhouf91b56d2015-07-09 13:51:13 +0800910 * \param timeout_ns - \c [in] Timeout value to wait
911 * \param flags - \c [in] Flags for the query
Alex Deucher09361392015-04-20 12:04:22 -0400912 * \param expired - \c [out] If fence expired or not.\n
913 * 0 – if fence is not expired\n
914 * !0 - otherwise
915 *
916 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400917 * <0 - Negative POSIX Error code
918 *
919 * \note If UMD wants only to check operation status and returned immediately
920 * then timeout value as 0 must be passed. In this case success will be
921 * returned in the case if submission was completed or timeout error
922 * code.
923 *
924 * \sa amdgpu_cs_submit()
925*/
Christian König5463d2e2015-07-09 11:48:32 +0200926int amdgpu_cs_query_fence_status(struct amdgpu_cs_fence *fence,
Jammy Zhouf91b56d2015-07-09 13:51:13 +0800927 uint64_t timeout_ns,
928 uint64_t flags,
Alex Deucher09361392015-04-20 12:04:22 -0400929 uint32_t *expired);
930
Nicolai Hähnled8d45a42017-04-13 16:43:14 +0200931/**
932 * Wait for multiple fences
933 *
934 * \param fences - \c [in] The fence array to wait
935 * \param fence_count - \c [in] The fence count
936 * \param wait_all - \c [in] If true, wait all fences to be signaled,
937 * otherwise, wait at least one fence
938 * \param timeout_ns - \c [in] The timeout to wait, in nanoseconds
939 * \param status - \c [out] '1' for signaled, '0' for timeout
940 * \param first - \c [out] the index of the first signaled fence from @fences
941 *
942 * \return 0 on success
943 * <0 - Negative POSIX Error code
944 *
945 * \note Currently it supports only one amdgpu_device. All fences come from
946 * the same amdgpu_device with the same fd.
947*/
948int amdgpu_cs_wait_fences(struct amdgpu_cs_fence *fences,
949 uint32_t fence_count,
950 bool wait_all,
951 uint64_t timeout_ns,
952 uint32_t *status, uint32_t *first);
953
Alex Deucher09361392015-04-20 12:04:22 -0400954/*
955 * Query / Info API
956 *
957*/
958
Alex Deucher09361392015-04-20 12:04:22 -0400959/**
960 * Query allocation size alignments
961 *
962 * UMD should query information about GPU VM MC size alignments requirements
963 * to be able correctly choose required allocation size and implement
964 * internal optimization if needed.
965 *
966 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
967 * \param info - \c [out] Pointer to structure to get size alignment
968 * requirements
969 *
970 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400971 * <0 - Negative POSIX Error code
972 *
973*/
974int amdgpu_query_buffer_size_alignment(amdgpu_device_handle dev,
Christian König558e1292015-06-30 16:04:44 +0200975 struct amdgpu_buffer_size_alignments
976 *info);
Alex Deucher09361392015-04-20 12:04:22 -0400977
978/**
979 * Query firmware versions
980 *
981 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
982 * \param fw_type - \c [in] AMDGPU_INFO_FW_*
983 * \param ip_instance - \c [in] Index of the IP block of the same type.
984 * \param index - \c [in] Index of the engine. (for SDMA and MEC)
985 * \param version - \c [out] Pointer to to the "version" return value
986 * \param feature - \c [out] Pointer to to the "feature" return value
987 *
988 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400989 * <0 - Negative POSIX Error code
990 *
991*/
992int amdgpu_query_firmware_version(amdgpu_device_handle dev, unsigned fw_type,
993 unsigned ip_instance, unsigned index,
994 uint32_t *version, uint32_t *feature);
995
Alex Deucher09361392015-04-20 12:04:22 -0400996/**
997 * Query the number of HW IP instances of a certain type.
998 *
999 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1000 * \param type - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
1001 * \param count - \c [out] Pointer to structure to get information
1002 *
1003 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -04001004 * <0 - Negative POSIX Error code
1005*/
1006int amdgpu_query_hw_ip_count(amdgpu_device_handle dev, unsigned type,
1007 uint32_t *count);
1008
Alex Deucher09361392015-04-20 12:04:22 -04001009/**
1010 * Query engine information
1011 *
1012 * This query allows UMD to query information different engines and their
1013 * capabilities.
1014 *
1015 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1016 * \param type - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
1017 * \param ip_instance - \c [in] Index of the IP block of the same type.
1018 * \param info - \c [out] Pointer to structure to get information
1019 *
1020 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -04001021 * <0 - Negative POSIX Error code
1022*/
1023int amdgpu_query_hw_ip_info(amdgpu_device_handle dev, unsigned type,
1024 unsigned ip_instance,
1025 struct drm_amdgpu_info_hw_ip *info);
1026
Alex Deucher09361392015-04-20 12:04:22 -04001027/**
1028 * Query heap information
1029 *
1030 * This query allows UMD to query potentially available memory resources and
1031 * adjust their logic if necessary.
1032 *
1033 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1034 * \param heap - \c [in] Heap type
1035 * \param info - \c [in] Pointer to structure to get needed information
1036 *
1037 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -04001038 * <0 - Negative POSIX Error code
1039 *
1040*/
Christian König558e1292015-06-30 16:04:44 +02001041int amdgpu_query_heap_info(amdgpu_device_handle dev, uint32_t heap,
1042 uint32_t flags, struct amdgpu_heap_info *info);
Alex Deucher09361392015-04-20 12:04:22 -04001043
1044/**
1045 * Get the CRTC ID from the mode object ID
1046 *
1047 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1048 * \param id - \c [in] Mode object ID
1049 * \param result - \c [in] Pointer to the CRTC ID
1050 *
1051 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -04001052 * <0 - Negative POSIX Error code
1053 *
1054*/
1055int amdgpu_query_crtc_from_id(amdgpu_device_handle dev, unsigned id,
1056 int32_t *result);
1057
Alex Deucher09361392015-04-20 12:04:22 -04001058/**
1059 * Query GPU H/w Info
1060 *
1061 * Query hardware specific information
1062 *
1063 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1064 * \param heap - \c [in] Heap type
1065 * \param info - \c [in] Pointer to structure to get needed information
1066 *
1067 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -04001068 * <0 - Negative POSIX Error code
1069 *
1070*/
1071int amdgpu_query_gpu_info(amdgpu_device_handle dev,
1072 struct amdgpu_gpu_info *info);
1073
Alex Deucher09361392015-04-20 12:04:22 -04001074/**
1075 * Query hardware or driver information.
1076 *
1077 * The return size is query-specific and depends on the "info_id" parameter.
1078 * No more than "size" bytes is returned.
1079 *
1080 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1081 * \param info_id - \c [in] AMDGPU_INFO_*
1082 * \param size - \c [in] Size of the returned value.
1083 * \param value - \c [out] Pointer to the return value.
1084 *
1085 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -04001086 * <0 - Negative POSIX error code
1087 *
1088*/
1089int amdgpu_query_info(amdgpu_device_handle dev, unsigned info_id,
1090 unsigned size, void *value);
1091
Christian König558e1292015-06-30 16:04:44 +02001092/**
Marek Olšákad5b7022018-02-02 18:15:00 +01001093 * Query hardware or driver information.
1094 *
1095 * The return size is query-specific and depends on the "info_id" parameter.
1096 * No more than "size" bytes is returned.
1097 *
1098 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1099 * \param info - \c [in] amdgpu_sw_info_*
1100 * \param value - \c [out] Pointer to the return value.
1101 *
1102 * \return 0 on success\n
1103 * <0 - Negative POSIX error code
1104 *
1105*/
1106int amdgpu_query_sw_info(amdgpu_device_handle dev, enum amdgpu_sw_info info,
1107 void *value);
1108
1109/**
Christian König558e1292015-06-30 16:04:44 +02001110 * Query information about GDS
1111 *
1112 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1113 * \param gds_info - \c [out] Pointer to structure to get GDS information
1114 *
1115 * \return 0 on success\n
Christian König558e1292015-06-30 16:04:44 +02001116 * <0 - Negative POSIX Error code
1117 *
1118*/
1119int amdgpu_query_gds_info(amdgpu_device_handle dev,
1120 struct amdgpu_gds_resource_info *gds_info);
Alex Deucher09361392015-04-20 12:04:22 -04001121
1122/**
Samuel Pitoiset047aba12017-04-04 16:34:56 +02001123 * Query information about sensor.
1124 *
1125 * The return size is query-specific and depends on the "sensor_type"
1126 * parameter. No more than "size" bytes is returned.
1127 *
1128 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1129 * \param sensor_type - \c [in] AMDGPU_INFO_SENSOR_*
1130 * \param size - \c [in] Size of the returned value.
1131 * \param value - \c [out] Pointer to the return value.
1132 *
1133 * \return 0 on success\n
1134 * <0 - Negative POSIX Error code
1135 *
1136*/
1137int amdgpu_query_sensor_info(amdgpu_device_handle dev, unsigned sensor_type,
1138 unsigned size, void *value);
1139
1140/**
Alex Deucher09361392015-04-20 12:04:22 -04001141 * Read a set of consecutive memory-mapped registers.
1142 * Not all registers are allowed to be read by userspace.
1143 *
1144 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize(
1145 * \param dword_offset - \c [in] Register offset in dwords
1146 * \param count - \c [in] The number of registers to read starting
1147 * from the offset
1148 * \param instance - \c [in] GRBM_GFX_INDEX selector. It may have other
1149 * uses. Set it to 0xffffffff if unsure.
1150 * \param flags - \c [in] Flags with additional information.
1151 * \param values - \c [out] The pointer to return values.
1152 *
1153 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -04001154 * <0 - Negative POSIX error code
1155 *
1156*/
1157int amdgpu_read_mm_registers(amdgpu_device_handle dev, unsigned dword_offset,
1158 unsigned count, uint32_t instance, uint32_t flags,
1159 uint32_t *values);
1160
Sabre Shao23fab592015-07-09 13:50:36 +08001161/**
Jammy Zhouffa305d2015-08-17 11:09:08 +08001162 * Flag to request VA address range in the 32bit address space
1163*/
1164#define AMDGPU_VA_RANGE_32_BIT 0x1
1165
1166/**
Sabre Shao23fab592015-07-09 13:50:36 +08001167 * Allocate virtual address range
1168 *
1169 * \param dev - [in] Device handle. See #amdgpu_device_initialize()
1170 * \param va_range_type - \c [in] Type of MC va range from which to allocate
1171 * \param size - \c [in] Size of range. Size must be correctly* aligned.
1172 * It is client responsibility to correctly aligned size based on the future
1173 * usage of allocated range.
1174 * \param va_base_alignment - \c [in] Overwrite base address alignment
1175 * requirement for GPU VM MC virtual
1176 * address assignment. Must be multiple of size alignments received as
1177 * 'amdgpu_buffer_size_alignments'.
1178 * If 0 use the default one.
1179 * \param va_base_required - \c [in] Specified required va base address.
1180 * If 0 then library choose available one.
1181 * If !0 value will be passed and those value already "in use" then
1182 * corresponding error status will be returned.
1183 * \param va_base_allocated - \c [out] On return: Allocated VA base to be used
1184 * by client.
1185 * \param va_range_handle - \c [out] On return: Handle assigned to allocation
Jammy Zhou95d0f352015-07-16 10:29:58 +08001186 * \param flags - \c [in] flags for special VA range
Sabre Shao23fab592015-07-09 13:50:36 +08001187 *
1188 * \return 0 on success\n
1189 * >0 - AMD specific error code\n
1190 * <0 - Negative POSIX Error code
1191 *
1192 * \notes \n
1193 * It is client responsibility to correctly handle VA assignments and usage.
1194 * Neither kernel driver nor libdrm_amdpgu are able to prevent and
1195 * detect wrong va assignemnt.
1196 *
1197 * It is client responsibility to correctly handle multi-GPU cases and to pass
1198 * the corresponding arrays of all devices handles where corresponding VA will
1199 * be used.
1200 *
1201*/
1202int amdgpu_va_range_alloc(amdgpu_device_handle dev,
1203 enum amdgpu_gpu_va_range va_range_type,
1204 uint64_t size,
1205 uint64_t va_base_alignment,
1206 uint64_t va_base_required,
1207 uint64_t *va_base_allocated,
Jammy Zhou95d0f352015-07-16 10:29:58 +08001208 amdgpu_va_handle *va_range_handle,
1209 uint64_t flags);
Sabre Shao23fab592015-07-09 13:50:36 +08001210
1211/**
1212 * Free previously allocated virtual address range
1213 *
1214 *
1215 * \param va_range_handle - \c [in] Handle assigned to VA allocation
1216 *
1217 * \return 0 on success\n
1218 * >0 - AMD specific error code\n
1219 * <0 - Negative POSIX Error code
1220 *
1221*/
1222int amdgpu_va_range_free(amdgpu_va_handle va_range_handle);
1223
Sabre Shao12802da2015-07-09 13:53:24 +08001224/**
1225* Query virtual address range
1226*
1227* UMD can query GPU VM range supported by each device
1228* to initialize its own VAM accordingly.
1229*
1230* \param dev - [in] Device handle. See #amdgpu_device_initialize()
1231* \param type - \c [in] Type of virtual address range
1232* \param offset - \c [out] Start offset of virtual address range
1233* \param size - \c [out] Size of virtual address range
1234*
1235* \return 0 on success\n
1236* <0 - Negative POSIX Error code
1237*
1238*/
1239
1240int amdgpu_va_range_query(amdgpu_device_handle dev,
1241 enum amdgpu_gpu_va_range type,
1242 uint64_t *start,
1243 uint64_t *end);
1244
Jammy Zhou8aeffcc2015-07-13 20:57:44 +08001245/**
1246 * VA mapping/unmapping for the buffer object
1247 *
1248 * \param bo - \c [in] BO handle
1249 * \param offset - \c [in] Start offset to map
1250 * \param size - \c [in] Size to map
1251 * \param addr - \c [in] Start virtual address.
1252 * \param flags - \c [in] Supported flags for mapping/unmapping
1253 * \param ops - \c [in] AMDGPU_VA_OP_MAP or AMDGPU_VA_OP_UNMAP
1254 *
1255 * \return 0 on success\n
1256 * <0 - Negative POSIX Error code
1257 *
1258*/
1259
1260int amdgpu_bo_va_op(amdgpu_bo_handle bo,
1261 uint64_t offset,
1262 uint64_t size,
1263 uint64_t addr,
1264 uint64_t flags,
1265 uint32_t ops);
1266
Marek Olšák6afadea2016-01-12 22:13:07 +01001267/**
Nicolai Hähnle4e369f22017-02-08 13:02:56 +01001268 * VA mapping/unmapping for a buffer object or PRT region.
1269 *
1270 * This is not a simple drop-in extension for amdgpu_bo_va_op; instead, all
1271 * parameters are treated "raw", i.e. size is not automatically aligned, and
1272 * all flags must be specified explicitly.
1273 *
1274 * \param dev - \c [in] device handle
1275 * \param bo - \c [in] BO handle (may be NULL)
1276 * \param offset - \c [in] Start offset to map
1277 * \param size - \c [in] Size to map
1278 * \param addr - \c [in] Start virtual address.
1279 * \param flags - \c [in] Supported flags for mapping/unmapping
1280 * \param ops - \c [in] AMDGPU_VA_OP_MAP or AMDGPU_VA_OP_UNMAP
1281 *
1282 * \return 0 on success\n
1283 * <0 - Negative POSIX Error code
1284 *
1285*/
1286
1287int amdgpu_bo_va_op_raw(amdgpu_device_handle dev,
1288 amdgpu_bo_handle bo,
1289 uint64_t offset,
1290 uint64_t size,
1291 uint64_t addr,
1292 uint64_t flags,
1293 uint32_t ops);
1294
1295/**
Marek Olšák6afadea2016-01-12 22:13:07 +01001296 * create semaphore
1297 *
1298 * \param sem - \c [out] semaphore handle
1299 *
1300 * \return 0 on success\n
1301 * <0 - Negative POSIX Error code
1302 *
1303*/
1304int amdgpu_cs_create_semaphore(amdgpu_semaphore_handle *sem);
1305
1306/**
1307 * signal semaphore
1308 *
1309 * \param context - \c [in] GPU Context
1310 * \param ip_type - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
1311 * \param ip_instance - \c [in] Index of the IP block of the same type
1312 * \param ring - \c [in] Specify ring index of the IP
1313 * \param sem - \c [in] semaphore handle
1314 *
1315 * \return 0 on success\n
1316 * <0 - Negative POSIX Error code
1317 *
1318*/
1319int amdgpu_cs_signal_semaphore(amdgpu_context_handle ctx,
1320 uint32_t ip_type,
1321 uint32_t ip_instance,
1322 uint32_t ring,
1323 amdgpu_semaphore_handle sem);
1324
1325/**
1326 * wait semaphore
1327 *
1328 * \param context - \c [in] GPU Context
1329 * \param ip_type - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
1330 * \param ip_instance - \c [in] Index of the IP block of the same type
1331 * \param ring - \c [in] Specify ring index of the IP
1332 * \param sem - \c [in] semaphore handle
1333 *
1334 * \return 0 on success\n
1335 * <0 - Negative POSIX Error code
1336 *
1337*/
1338int amdgpu_cs_wait_semaphore(amdgpu_context_handle ctx,
1339 uint32_t ip_type,
1340 uint32_t ip_instance,
1341 uint32_t ring,
1342 amdgpu_semaphore_handle sem);
1343
1344/**
1345 * destroy semaphore
1346 *
1347 * \param sem - \c [in] semaphore handle
1348 *
1349 * \return 0 on success\n
1350 * <0 - Negative POSIX Error code
1351 *
1352*/
1353int amdgpu_cs_destroy_semaphore(amdgpu_semaphore_handle sem);
1354
Junwei Zhang670f1e42016-09-12 11:14:11 -04001355/**
1356 * Get the ASIC marketing name
1357 *
1358 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1359 *
1360 * \return the constant string of the marketing name
1361 * "NULL" means the ASIC is not found
1362*/
1363const char *amdgpu_get_marketing_name(amdgpu_device_handle dev);
1364
Dave Airlie69532d02017-07-16 20:18:40 +01001365/**
1366 * Create kernel sync object
1367 *
David Mao1749d562017-11-28 11:22:26 +08001368 * \param dev - \c [in] device handle
1369 * \param flags - \c [in] flags that affect creation
1370 * \param syncobj - \c [out] sync object handle
1371 *
1372 * \return 0 on success\n
1373 * <0 - Negative POSIX Error code
1374 *
1375*/
1376int amdgpu_cs_create_syncobj2(amdgpu_device_handle dev,
1377 uint32_t flags,
1378 uint32_t *syncobj);
1379
1380/**
1381 * Create kernel sync object
1382 *
Dave Airlie69532d02017-07-16 20:18:40 +01001383 * \param dev - \c [in] device handle
1384 * \param syncobj - \c [out] sync object handle
1385 *
1386 * \return 0 on success\n
1387 * <0 - Negative POSIX Error code
1388 *
1389*/
1390int amdgpu_cs_create_syncobj(amdgpu_device_handle dev,
1391 uint32_t *syncobj);
1392/**
1393 * Destroy kernel sync object
1394 *
1395 * \param dev - \c [in] device handle
1396 * \param syncobj - \c [in] sync object handle
1397 *
1398 * \return 0 on success\n
1399 * <0 - Negative POSIX Error code
1400 *
1401*/
1402int amdgpu_cs_destroy_syncobj(amdgpu_device_handle dev,
1403 uint32_t syncobj);
1404
1405/**
Bas Nieuwenhuizen5889f6b2017-12-17 00:27:10 +01001406 * Reset kernel sync objects to unsignalled state.
1407 *
1408 * \param dev - \c [in] device handle
1409 * \param syncobjs - \c [in] array of sync object handles
1410 * \param syncobj_count - \c [in] number of handles in syncobjs
1411 *
1412 * \return 0 on success\n
1413 * <0 - Negative POSIX Error code
1414 *
1415*/
1416int amdgpu_cs_syncobj_reset(amdgpu_device_handle dev,
1417 const uint32_t *syncobjs, uint32_t syncobj_count);
1418
1419/**
1420 * Signal kernel sync objects.
1421 *
1422 * \param dev - \c [in] device handle
1423 * \param syncobjs - \c [in] array of sync object handles
1424 * \param syncobj_count - \c [in] number of handles in syncobjs
1425 *
1426 * \return 0 on success\n
1427 * <0 - Negative POSIX Error code
1428 *
1429*/
1430int amdgpu_cs_syncobj_signal(amdgpu_device_handle dev,
1431 const uint32_t *syncobjs, uint32_t syncobj_count);
1432
1433/**
Marek Olšák59aa57b2017-09-11 21:58:03 +02001434 * Wait for one or all sync objects to signal.
1435 *
1436 * \param dev - \c [in] self-explanatory
1437 * \param handles - \c [in] array of sync object handles
1438 * \param num_handles - \c [in] self-explanatory
1439 * \param timeout_nsec - \c [in] self-explanatory
1440 * \param flags - \c [in] a bitmask of DRM_SYNCOBJ_WAIT_FLAGS_*
1441 * \param first_signaled - \c [in] self-explanatory
1442 *
1443 * \return 0 on success\n
1444 * -ETIME - Timeout
1445 * <0 - Negative POSIX Error code
1446 *
1447 */
1448int amdgpu_cs_syncobj_wait(amdgpu_device_handle dev,
1449 uint32_t *handles, unsigned num_handles,
1450 int64_t timeout_nsec, unsigned flags,
1451 uint32_t *first_signaled);
1452
1453/**
Dave Airlie69532d02017-07-16 20:18:40 +01001454 * Export kernel sync object to shareable fd.
1455 *
1456 * \param dev - \c [in] device handle
1457 * \param syncobj - \c [in] sync object handle
1458 * \param shared_fd - \c [out] shared file descriptor.
1459 *
1460 * \return 0 on success\n
1461 * <0 - Negative POSIX Error code
1462 *
1463*/
1464int amdgpu_cs_export_syncobj(amdgpu_device_handle dev,
1465 uint32_t syncobj,
1466 int *shared_fd);
1467/**
1468 * Import kernel sync object from shareable fd.
1469 *
1470 * \param dev - \c [in] device handle
1471 * \param shared_fd - \c [in] shared file descriptor.
1472 * \param syncobj - \c [out] sync object handle
1473 *
1474 * \return 0 on success\n
1475 * <0 - Negative POSIX Error code
1476 *
1477*/
1478int amdgpu_cs_import_syncobj(amdgpu_device_handle dev,
1479 int shared_fd,
1480 uint32_t *syncobj);
1481
Dave Airlie22790a62017-07-18 01:31:27 +01001482/**
Marek Olšákb6e24502017-09-11 21:12:12 +02001483 * Export kernel sync object to a sync_file.
1484 *
1485 * \param dev - \c [in] device handle
1486 * \param syncobj - \c [in] sync object handle
1487 * \param sync_file_fd - \c [out] sync_file file descriptor.
1488 *
1489 * \return 0 on success\n
1490 * <0 - Negative POSIX Error code
1491 *
1492 */
1493int amdgpu_cs_syncobj_export_sync_file(amdgpu_device_handle dev,
1494 uint32_t syncobj,
1495 int *sync_file_fd);
1496
1497/**
1498 * Import kernel sync object from a sync_file.
1499 *
1500 * \param dev - \c [in] device handle
1501 * \param syncobj - \c [in] sync object handle
1502 * \param sync_file_fd - \c [in] sync_file file descriptor.
1503 *
1504 * \return 0 on success\n
1505 * <0 - Negative POSIX Error code
1506 *
1507 */
1508int amdgpu_cs_syncobj_import_sync_file(amdgpu_device_handle dev,
1509 uint32_t syncobj,
1510 int sync_file_fd);
1511
1512/**
Marek Olšákc74d4612017-09-08 16:05:54 +02001513 * Export an amdgpu fence as a handle (syncobj or fd).
1514 *
1515 * \param what AMDGPU_FENCE_TO_HANDLE_GET_{SYNCOBJ, FD}
1516 * \param out_handle returned handle
1517 *
1518 * \return 0 on success\n
1519 * <0 - Negative POSIX Error code
1520 */
1521int amdgpu_cs_fence_to_handle(amdgpu_device_handle dev,
1522 struct amdgpu_cs_fence *fence,
1523 uint32_t what,
1524 uint32_t *out_handle);
1525
1526/**
Dave Airlie22790a62017-07-18 01:31:27 +01001527 * Submit raw command submission to kernel
1528 *
1529 * \param dev - \c [in] device handle
1530 * \param context - \c [in] context handle for context id
1531 * \param bo_list_handle - \c [in] request bo list handle (0 for none)
1532 * \param num_chunks - \c [in] number of CS chunks to submit
1533 * \param chunks - \c [in] array of CS chunks
1534 * \param seq_no - \c [out] output sequence number for submission.
1535 *
1536 * \return 0 on success\n
1537 * <0 - Negative POSIX Error code
1538 *
1539 */
1540struct drm_amdgpu_cs_chunk;
1541struct drm_amdgpu_cs_chunk_dep;
1542struct drm_amdgpu_cs_chunk_data;
1543
1544int amdgpu_cs_submit_raw(amdgpu_device_handle dev,
1545 amdgpu_context_handle context,
1546 amdgpu_bo_list_handle bo_list_handle,
1547 int num_chunks,
1548 struct drm_amdgpu_cs_chunk *chunks,
1549 uint64_t *seq_no);
1550
1551void amdgpu_cs_chunk_fence_to_dep(struct amdgpu_cs_fence *fence,
1552 struct drm_amdgpu_cs_chunk_dep *dep);
1553void amdgpu_cs_chunk_fence_info_to_data(struct amdgpu_cs_fence_info *fence_info,
1554 struct drm_amdgpu_cs_chunk_data *data);
1555
Andrey Grodzovsky9b38ea82017-10-27 11:09:10 -04001556/**
1557 * Reserve VMID
1558 * \param context - \c [in] GPU Context
1559 * \param flags - \c [in] TBD
1560 *
1561 * \return 0 on success otherwise POSIX Error code
1562*/
Andrey Grodzovskyf3091ba2017-11-02 10:29:55 -04001563int amdgpu_vm_reserve_vmid(amdgpu_device_handle dev, uint32_t flags);
Andrey Grodzovsky9b38ea82017-10-27 11:09:10 -04001564
1565/**
1566 * Free reserved VMID
1567 * \param context - \c [in] GPU Context
1568 * \param flags - \c [in] TBD
1569 *
1570 * \return 0 on success otherwise POSIX Error code
1571*/
Andrey Grodzovskyf3091ba2017-11-02 10:29:55 -04001572int amdgpu_vm_unreserve_vmid(amdgpu_device_handle dev, uint32_t flags);
Andrey Grodzovsky9b38ea82017-10-27 11:09:10 -04001573
Nicolai Hähnle41be41f2017-05-13 23:03:55 +02001574#ifdef __cplusplus
1575}
1576#endif
Alex Deucher09361392015-04-20 12:04:22 -04001577#endif /* #ifdef _AMDGPU_H_ */