blob: daeebbed16f72bcae9e672bb40649a3b9eb9de26 [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 *
22*/
23
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
40struct drm_amdgpu_info_hw_ip;
41
42/*--------------------------------------------------------------------------*/
43/* --------------------------- Defines ------------------------------------ */
44/*--------------------------------------------------------------------------*/
45
46/**
47 * Define max. number of Command Buffers (IB) which could be sent to the single
48 * hardware IP to accommodate CE/DE requirements
49 *
50 * \sa amdgpu_cs_ib_info
51*/
52#define AMDGPU_CS_MAX_IBS_PER_SUBMIT 4
53
54/**
55 *
56 */
57#define AMDGPU_TIMEOUT_INFINITE 0xffffffffffffffffull
58
Alex Deucher09361392015-04-20 12:04:22 -040059
Alex Deucher09361392015-04-20 12:04:22 -040060/*--------------------------------------------------------------------------*/
61/* ----------------------------- Enums ------------------------------------ */
62/*--------------------------------------------------------------------------*/
63
64/**
65 * Enum describing possible handle types
66 *
67 * \sa amdgpu_bo_import, amdgpu_bo_export
68 *
69*/
70enum amdgpu_bo_handle_type {
71 /** GEM flink name (needs DRM authentication, used by DRI2) */
72 amdgpu_bo_handle_type_gem_flink_name = 0,
73
74 /** KMS handle which is used by all driver ioctls */
75 amdgpu_bo_handle_type_kms = 1,
76
77 /** DMA-buf fd handle */
78 amdgpu_bo_handle_type_dma_buf_fd = 2
79};
80
Alex Deucher09361392015-04-20 12:04:22 -040081
82/*--------------------------------------------------------------------------*/
83/* -------------------------- Datatypes ----------------------------------- */
84/*--------------------------------------------------------------------------*/
85
86/**
87 * Define opaque pointer to context associated with fd.
88 * This context will be returned as the result of
89 * "initialize" function and should be pass as the first
90 * parameter to any API call
91 */
92typedef struct amdgpu_device *amdgpu_device_handle;
93
94/**
95 * Define GPU Context type as pointer to opaque structure
96 * Example of GPU Context is the "rendering" context associated
97 * with OpenGL context (glCreateContext)
98 */
99typedef struct amdgpu_context *amdgpu_context_handle;
100
101/**
102 * Define handle for amdgpu resources: buffer, GDS, etc.
103 */
104typedef struct amdgpu_bo *amdgpu_bo_handle;
105
106/**
Christian König6dc2eaf2015-04-22 14:52:34 +0200107 * Define handle for list of BOs
108 */
109typedef struct amdgpu_bo_list *amdgpu_bo_list_handle;
110
Alex Deucher09361392015-04-20 12:04:22 -0400111
112/*--------------------------------------------------------------------------*/
113/* -------------------------- Structures ---------------------------------- */
114/*--------------------------------------------------------------------------*/
115
116/**
117 * Structure describing memory allocation request
118 *
119 * \sa amdgpu_bo_alloc()
120 *
121*/
122struct amdgpu_bo_alloc_request {
123 /** Allocation request. It must be aligned correctly. */
124 uint64_t alloc_size;
125
126 /**
127 * It may be required to have some specific alignment requirements
128 * for physical back-up storage (e.g. for displayable surface).
129 * If 0 there is no special alignment requirement
130 */
131 uint64_t phys_alignment;
132
133 /**
134 * UMD should specify where to allocate memory and how it
135 * will be accessed by the CPU.
136 */
137 uint32_t preferred_heap;
138
139 /** Additional flags passed on allocation */
140 uint64_t flags;
141};
142
143/**
144 * Structure describing memory allocation request
145 *
146 * \sa amdgpu_bo_alloc()
147*/
148struct amdgpu_bo_alloc_result {
149 /** Assigned virtual MC Base Address */
150 uint64_t virtual_mc_base_address;
151
152 /** Handle of allocated memory to be used by the given process only. */
153 amdgpu_bo_handle buf_handle;
154};
155
156/**
157 * Special UMD specific information associated with buffer.
158 *
159 * It may be need to pass some buffer charactersitic as part
160 * of buffer sharing. Such information are defined UMD and
161 * opaque for libdrm_amdgpu as well for kernel driver.
162 *
163 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info,
164 * amdgpu_bo_import(), amdgpu_bo_export
165 *
166*/
167struct amdgpu_bo_metadata {
168 /** Special flag associated with surface */
169 uint64_t flags;
170
171 /**
172 * ASIC-specific tiling information (also used by DCE).
173 * The encoding is defined by the AMDGPU_TILING_* definitions.
174 */
175 uint64_t tiling_info;
176
177 /** Size of metadata associated with the buffer, in bytes. */
178 uint32_t size_metadata;
179
180 /** UMD specific metadata. Opaque for kernel */
181 uint32_t umd_metadata[64];
182};
183
184/**
185 * Structure describing allocated buffer. Client may need
186 * to query such information as part of 'sharing' buffers mechanism
187 *
188 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info(),
189 * amdgpu_bo_import(), amdgpu_bo_export()
190*/
191struct amdgpu_bo_info {
192 /** Allocated memory size */
193 uint64_t alloc_size;
194
195 /**
196 * It may be required to have some specific alignment requirements
197 * for physical back-up storage.
198 */
199 uint64_t phys_alignment;
200
201 /**
202 * Assigned virtual MC Base Address.
203 * \note This information will be returned only if this buffer was
204 * allocated in the same process otherwise 0 will be returned.
205 */
206 uint64_t virtual_mc_base_address;
207
208 /** Heap where to allocate memory. */
209 uint32_t preferred_heap;
210
211 /** Additional allocation flags. */
212 uint64_t alloc_flags;
213
214 /** Metadata associated with buffer if any. */
215 struct amdgpu_bo_metadata metadata;
216};
217
218/**
219 * Structure with information about "imported" buffer
220 *
221 * \sa amdgpu_bo_import()
222 *
223 */
224struct amdgpu_bo_import_result {
225 /** Handle of memory/buffer to use */
Christian König558e1292015-06-30 16:04:44 +0200226 amdgpu_bo_handle buf_handle;
Alex Deucher09361392015-04-20 12:04:22 -0400227
228 /** Buffer size */
229 uint64_t alloc_size;
230
231 /** Assigned virtual MC Base Address */
232 uint64_t virtual_mc_base_address;
233};
234
Alex Deucher09361392015-04-20 12:04:22 -0400235/**
236 *
237 * Structure to describe GDS partitioning information.
238 * \note OA and GWS resources are asscoiated with GDS partition
239 *
240 * \sa amdgpu_gpu_resource_query_gds_info
241 *
242*/
243struct amdgpu_gds_resource_info {
Christian König558e1292015-06-30 16:04:44 +0200244 uint32_t gds_gfx_partition_size;
245 uint32_t compute_partition_size;
246 uint32_t gds_total_size;
247 uint32_t gws_per_gfx_partition;
248 uint32_t gws_per_compute_partition;
249 uint32_t oa_per_gfx_partition;
250 uint32_t oa_per_compute_partition;
Alex Deucher09361392015-04-20 12:04:22 -0400251};
252
Alex Deucher09361392015-04-20 12:04:22 -0400253/**
Christian König0f37bc92015-06-24 14:17:57 +0200254 * Structure describing CS dependency
255 *
256 * \sa amdgpu_cs_request, amdgpu_cs_submit()
257 *
258*/
259struct amdgpu_cs_dep_info {
260 /** Context to which the fence belongs */
Christian König558e1292015-06-30 16:04:44 +0200261 amdgpu_context_handle context;
Christian König0f37bc92015-06-24 14:17:57 +0200262
263 /** To which HW IP type the fence belongs */
Christian König558e1292015-06-30 16:04:44 +0200264 uint32_t ip_type;
Christian König0f37bc92015-06-24 14:17:57 +0200265
266 /** IP instance index if there are several IPs of the same type. */
Christian König558e1292015-06-30 16:04:44 +0200267 uint32_t ip_instance;
Christian König0f37bc92015-06-24 14:17:57 +0200268
269 /** Ring index of the HW IP */
Christian König558e1292015-06-30 16:04:44 +0200270 uint32_t ring;
Christian König0f37bc92015-06-24 14:17:57 +0200271
Christian König558e1292015-06-30 16:04:44 +0200272 /** Specify fence for which we need to check submission status.*/
273 uint64_t fence;
Christian König0f37bc92015-06-24 14:17:57 +0200274};
275
276/**
Alex Deucher09361392015-04-20 12:04:22 -0400277 * Structure describing IB
278 *
279 * \sa amdgpu_cs_request, amdgpu_cs_submit()
280 *
281*/
282struct amdgpu_cs_ib_info {
283 /** Special flags */
Christian König558e1292015-06-30 16:04:44 +0200284 uint64_t flags;
Alex Deucher09361392015-04-20 12:04:22 -0400285
Marek Olšák76af5c22015-06-02 13:05:41 +0200286 /** Virtual MC address of the command buffer */
Christian König558e1292015-06-30 16:04:44 +0200287 uint64_t ib_mc_address;
Alex Deucher09361392015-04-20 12:04:22 -0400288
289 /**
290 * Size of Command Buffer to be submitted.
291 * - The size is in units of dwords (4 bytes).
Alex Deucher09361392015-04-20 12:04:22 -0400292 * - Could be 0
293 */
Christian König558e1292015-06-30 16:04:44 +0200294 uint32_t size;
Alex Deucher09361392015-04-20 12:04:22 -0400295};
296
297/**
298 * Structure describing submission request
299 *
300 * \note We could have several IBs as packet. e.g. CE, CE, DE case for gfx
301 *
302 * \sa amdgpu_cs_submit()
303*/
304struct amdgpu_cs_request {
305 /** Specify flags with additional information */
Christian König558e1292015-06-30 16:04:44 +0200306 uint64_t flags;
Alex Deucher09361392015-04-20 12:04:22 -0400307
308 /** Specify HW IP block type to which to send the IB. */
Christian König558e1292015-06-30 16:04:44 +0200309 unsigned ip_type;
Alex Deucher09361392015-04-20 12:04:22 -0400310
311 /** IP instance index if there are several IPs of the same type. */
Christian König558e1292015-06-30 16:04:44 +0200312 unsigned ip_instance;
Alex Deucher09361392015-04-20 12:04:22 -0400313
314 /**
315 * Specify ring index of the IP. We could have several rings
316 * in the same IP. E.g. 0 for SDMA0 and 1 for SDMA1.
317 */
Christian König558e1292015-06-30 16:04:44 +0200318 uint32_t ring;
Alex Deucher09361392015-04-20 12:04:22 -0400319
320 /**
Christian König6dc2eaf2015-04-22 14:52:34 +0200321 * List handle with resources used by this request.
Alex Deucher09361392015-04-20 12:04:22 -0400322 */
Christian König6dc2eaf2015-04-22 14:52:34 +0200323 amdgpu_bo_list_handle resources;
Alex Deucher09361392015-04-20 12:04:22 -0400324
Christian König0f37bc92015-06-24 14:17:57 +0200325 /**
326 * Number of dependencies this Command submission needs to
327 * wait for before starting execution.
328 */
329 uint32_t number_of_dependencies;
330
331 /**
332 * Array of dependencies which need to be met before
333 * execution can start.
334 */
335 struct amdgpu_cs_dep_info *dependencies;
336
Alex Deucher09361392015-04-20 12:04:22 -0400337 /** Number of IBs to submit in the field ibs. */
338 uint32_t number_of_ibs;
339
340 /**
341 * IBs to submit. Those IBs will be submit together as single entity
342 */
343 struct amdgpu_cs_ib_info *ibs;
344};
345
346/**
347 * Structure describing request to check submission state using fence
348 *
349 * \sa amdgpu_cs_query_fence_status()
350 *
351*/
352struct amdgpu_cs_query_fence {
353
354 /** In which context IB was sent to execution */
Christian König558e1292015-06-30 16:04:44 +0200355 amdgpu_context_handle context;
Alex Deucher09361392015-04-20 12:04:22 -0400356
357 /** Timeout in nanoseconds. */
Christian König558e1292015-06-30 16:04:44 +0200358 uint64_t timeout_ns;
Alex Deucher09361392015-04-20 12:04:22 -0400359
360 /** To which HW IP type the fence belongs */
Christian König558e1292015-06-30 16:04:44 +0200361 unsigned ip_type;
Alex Deucher09361392015-04-20 12:04:22 -0400362
363 /** IP instance index if there are several IPs of the same type. */
364 unsigned ip_instance;
365
366 /** Ring index of the HW IP */
Christian König558e1292015-06-30 16:04:44 +0200367 uint32_t ring;
Alex Deucher09361392015-04-20 12:04:22 -0400368
369 /** Flags */
Christian König558e1292015-06-30 16:04:44 +0200370 uint64_t flags;
Alex Deucher09361392015-04-20 12:04:22 -0400371
Christian König558e1292015-06-30 16:04:44 +0200372 /** Specify fence for which we need to check submission status.*/
373 uint64_t fence;
Alex Deucher09361392015-04-20 12:04:22 -0400374};
375
376/**
377 * 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;
Alex Deucher09361392015-04-20 12:04:22 -0400480};
481
482
483/*--------------------------------------------------------------------------*/
484/*------------------------- Functions --------------------------------------*/
485/*--------------------------------------------------------------------------*/
486
487/*
488 * Initialization / Cleanup
489 *
490*/
491
Alex Deucher09361392015-04-20 12:04:22 -0400492/**
493 *
494 * \param fd - \c [in] File descriptor for AMD GPU device
495 * received previously as the result of
496 * e.g. drmOpen() call.
Christian König558e1292015-06-30 16:04:44 +0200497 * For legacy fd type, the DRI2/DRI3
498 * authentication should be done before
499 * calling this function.
Alex Deucher09361392015-04-20 12:04:22 -0400500 * \param major_version - \c [out] Major version of library. It is assumed
501 * that adding new functionality will cause
502 * increase in major version
503 * \param minor_version - \c [out] Minor version of library
504 * \param device_handle - \c [out] Pointer to opaque context which should
505 * be passed as the first parameter on each
506 * API call
507 *
508 *
509 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400510 * <0 - Negative POSIX Error code
511 *
512 *
513 * \sa amdgpu_device_deinitialize()
514*/
515int amdgpu_device_initialize(int fd,
516 uint32_t *major_version,
517 uint32_t *minor_version,
518 amdgpu_device_handle *device_handle);
519
Alex Deucher09361392015-04-20 12:04:22 -0400520/**
521 *
522 * When access to such library does not needed any more the special
523 * function must be call giving opportunity to clean up any
524 * resources if needed.
525 *
526 * \param device_handle - \c [in] Context associated with file
527 * descriptor for AMD GPU device
528 * received previously as the
529 * result e.g. of drmOpen() call.
530 *
531 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400532 * <0 - Negative POSIX Error code
533 *
534 * \sa amdgpu_device_initialize()
535 *
536*/
537int amdgpu_device_deinitialize(amdgpu_device_handle device_handle);
538
Alex Deucher09361392015-04-20 12:04:22 -0400539/*
540 * Memory Management
541 *
542*/
543
544/**
545 * Allocate memory to be used by UMD for GPU related operations
546 *
547 * \param dev - \c [in] Device handle.
548 * See #amdgpu_device_initialize()
549 * \param alloc_buffer - \c [in] Pointer to the structure describing an
550 * allocation request
551 * \param info - \c [out] Pointer to structure which return
552 * information about allocated memory
553 *
554 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400555 * <0 - Negative POSIX Error code
556 *
557 * \sa amdgpu_bo_free()
558*/
559int amdgpu_bo_alloc(amdgpu_device_handle dev,
560 struct amdgpu_bo_alloc_request *alloc_buffer,
561 struct amdgpu_bo_alloc_result *info);
562
563/**
564 * Associate opaque data with buffer to be queried by another UMD
565 *
566 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
567 * \param buf_handle - \c [in] Buffer handle
568 * \param info - \c [in] Metadata to associated with buffer
569 *
570 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400571 * <0 - Negative POSIX Error code
572*/
573int amdgpu_bo_set_metadata(amdgpu_bo_handle buf_handle,
574 struct amdgpu_bo_metadata *info);
575
576/**
577 * Query buffer information including metadata previusly associated with
578 * buffer.
579 *
580 * \param dev - \c [in] Device handle.
581 * See #amdgpu_device_initialize()
582 * \param buf_handle - \c [in] Buffer handle
583 * \param info - \c [out] Structure describing buffer
584 *
585 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400586 * <0 - Negative POSIX Error code
587 *
588 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc()
589*/
590int amdgpu_bo_query_info(amdgpu_bo_handle buf_handle,
591 struct amdgpu_bo_info *info);
592
593/**
594 * Allow others to get access to buffer
595 *
596 * \param dev - \c [in] Device handle.
597 * See #amdgpu_device_initialize()
598 * \param buf_handle - \c [in] Buffer handle
599 * \param type - \c [in] Type of handle requested
600 * \param shared_handle - \c [out] Special "shared" handle
601 *
602 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400603 * <0 - Negative POSIX Error code
604 *
605 * \sa amdgpu_bo_import()
606 *
607*/
608int amdgpu_bo_export(amdgpu_bo_handle buf_handle,
609 enum amdgpu_bo_handle_type type,
610 uint32_t *shared_handle);
611
612/**
613 * Request access to "shared" buffer
614 *
615 * \param dev - \c [in] Device handle.
616 * See #amdgpu_device_initialize()
617 * \param type - \c [in] Type of handle requested
618 * \param shared_handle - \c [in] Shared handle received as result "import"
619 * operation
620 * \param output - \c [out] Pointer to structure with information
621 * about imported buffer
622 *
623 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400624 * <0 - Negative POSIX Error code
625 *
626 * \note Buffer must be "imported" only using new "fd" (different from
627 * one used by "exporter").
628 *
629 * \sa amdgpu_bo_export()
630 *
631*/
632int amdgpu_bo_import(amdgpu_device_handle dev,
633 enum amdgpu_bo_handle_type type,
634 uint32_t shared_handle,
635 struct amdgpu_bo_import_result *output);
636
637/**
Christian König558e1292015-06-30 16:04:44 +0200638 * Request GPU access to user allocated memory e.g. via "malloc"
639 *
640 * \param dev - [in] Device handle. See #amdgpu_device_initialize()
641 * \param cpu - [in] CPU address of user allocated memory which we
642 * want to map to GPU address space (make GPU accessible)
643 * (This address must be correctly aligned).
644 * \param size - [in] Size of allocation (must be correctly aligned)
645 * \param amdgpu_bo_alloc_result - [out] Handle of allocation to be passed as
646 * resource on submission and be used in other operations.
647 *
648 *
Christian König28462eb2015-06-30 16:27:27 +0200649 * \return 0 on success\n
650 * <0 - Negative POSIX Error code
Christian König558e1292015-06-30 16:04:44 +0200651 *
652 * \note
653 * This call doesn't guarantee that such memory will be persistently
654 * "locked" / make non-pageable. The purpose of this call is to provide
655 * opportunity for GPU get access to this resource during submission.
656 *
657 * The maximum amount of memory which could be mapped in this call depends
658 * if overcommit is disabled or not. If overcommit is disabled than the max.
659 * amount of memory to be pinned will be limited by left "free" size in total
660 * amount of memory which could be locked simultaneously ("GART" size).
661 *
662 * Supported (theoretical) max. size of mapping is restricted only by
663 * "GART" size.
664 *
665 * It is responsibility of caller to correctly specify access rights
666 * on VA assignment.
667*/
668int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev,
669 void *cpu, uint64_t size,
670 struct amdgpu_bo_alloc_result *info);
671
672/**
Alex Deucher09361392015-04-20 12:04:22 -0400673 * Free previosuly allocated memory
674 *
675 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
676 * \param buf_handle - \c [in] Buffer handle to free
677 *
678 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400679 * <0 - Negative POSIX Error code
680 *
681 * \note In the case of memory shared between different applications all
682 * resources will be “physically” freed only all such applications
683 * will be terminated
684 * \note If is UMD responsibility to ‘free’ buffer only when there is no
685 * more GPU access
686 *
687 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc()
688 *
689*/
690int amdgpu_bo_free(amdgpu_bo_handle buf_handle);
691
692/**
693 * Request CPU access to GPU accessable memory
694 *
695 * \param buf_handle - \c [in] Buffer handle
696 * \param cpu - \c [out] CPU address to be used for access
697 *
698 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400699 * <0 - Negative POSIX Error code
700 *
701 * \sa amdgpu_bo_cpu_unmap()
702 *
703*/
704int amdgpu_bo_cpu_map(amdgpu_bo_handle buf_handle, void **cpu);
705
706/**
707 * Release CPU access to GPU memory
708 *
709 * \param buf_handle - \c [in] Buffer handle
710 *
711 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400712 * <0 - Negative POSIX Error code
713 *
714 * \sa amdgpu_bo_cpu_map()
715 *
716*/
717int amdgpu_bo_cpu_unmap(amdgpu_bo_handle buf_handle);
718
Alex Deucher09361392015-04-20 12:04:22 -0400719/**
720 * Wait until a buffer is not used by the device.
721 *
722 * \param dev - \c [in] Device handle. See #amdgpu_lib_initialize()
723 * \param buf_handle - \c [in] Buffer handle.
724 * \param timeout_ns - Timeout in nanoseconds.
725 * \param buffer_busy - 0 if buffer is idle, all GPU access was completed
726 * and no GPU access is scheduled.
727 * 1 GPU access is in fly or scheduled
728 *
729 * \return 0 - on success
Christian König558e1292015-06-30 16:04:44 +0200730 * <0 - Negative POSIX Error code
Alex Deucher09361392015-04-20 12:04:22 -0400731 */
732int amdgpu_bo_wait_for_idle(amdgpu_bo_handle buf_handle,
733 uint64_t timeout_ns,
734 bool *buffer_busy);
735
Christian König6dc2eaf2015-04-22 14:52:34 +0200736/**
737 * Creates a BO list handle for command submission.
738 *
739 * \param dev - \c [in] Device handle.
740 * See #amdgpu_device_initialize()
741 * \param number_of_resources - \c [in] Number of BOs in the list
742 * \param resources - \c [in] List of BO handles
743 * \param resource_prios - \c [in] Optional priority for each handle
744 * \param result - \c [out] Created BO list handle
745 *
746 * \return 0 on success\n
Christian König6dc2eaf2015-04-22 14:52:34 +0200747 * <0 - Negative POSIX Error code
748 *
749 * \sa amdgpu_bo_list_destroy()
750*/
751int amdgpu_bo_list_create(amdgpu_device_handle dev,
752 uint32_t number_of_resources,
753 amdgpu_bo_handle *resources,
754 uint8_t *resource_prios,
755 amdgpu_bo_list_handle *result);
756
757/**
758 * Destroys a BO list handle.
759 *
760 * \param handle - \c [in] BO list handle.
761 *
762 * \return 0 on success\n
Christian König6dc2eaf2015-04-22 14:52:34 +0200763 * <0 - Negative POSIX Error code
764 *
765 * \sa amdgpu_bo_list_create()
766*/
767int amdgpu_bo_list_destroy(amdgpu_bo_list_handle handle);
Alex Deucher09361392015-04-20 12:04:22 -0400768
Jammy Zhou72446982015-05-18 20:27:24 +0800769/**
770 * Update resources for existing BO list
771 *
772 * \param handle - \c [in] BO list handle
773 * \param number_of_resources - \c [in] Number of BOs in the list
774 * \param resources - \c [in] List of BO handles
775 * \param resource_prios - \c [in] Optional priority for each handle
776 *
777 * \return 0 on success\n
Jammy Zhou72446982015-05-18 20:27:24 +0800778 * <0 - Negative POSIX Error code
779 *
780 * \sa amdgpu_bo_list_update()
781*/
782int amdgpu_bo_list_update(amdgpu_bo_list_handle handle,
783 uint32_t number_of_resources,
784 amdgpu_bo_handle *resources,
785 uint8_t *resource_prios);
786
Alex Deucher09361392015-04-20 12:04:22 -0400787/*
Alex Deucher09361392015-04-20 12:04:22 -0400788 * GPU Execution context
789 *
790*/
791
792/**
793 * Create GPU execution Context
794 *
795 * For the purpose of GPU Scheduler and GPU Robustness extensions it is
796 * necessary to have information/identify rendering/compute contexts.
797 * It also may be needed to associate some specific requirements with such
798 * contexts. Kernel driver will guarantee that submission from the same
799 * context will always be executed in order (first come, first serve).
800 *
801 *
802 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
803 * \param context - \c [out] GPU Context handle
804 *
805 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400806 * <0 - Negative POSIX Error code
807 *
808 * \sa amdgpu_cs_ctx_free()
809 *
810*/
811int amdgpu_cs_ctx_create(amdgpu_device_handle dev,
812 amdgpu_context_handle *context);
813
814/**
815 *
816 * Destroy GPU execution context when not needed any more
817 *
Alex Deucher09361392015-04-20 12:04:22 -0400818 * \param context - \c [in] GPU Context handle
819 *
820 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400821 * <0 - Negative POSIX Error code
822 *
823 * \sa amdgpu_cs_ctx_create()
824 *
825*/
Christian König9c2afff2015-04-22 12:21:13 +0200826int amdgpu_cs_ctx_free(amdgpu_context_handle context);
Alex Deucher09361392015-04-20 12:04:22 -0400827
828/**
829 * Query reset state for the specific GPU Context
830 *
Alex Deucher09361392015-04-20 12:04:22 -0400831 * \param context - \c [in] GPU Context handle
Marek Olšák4b39a8e2015-05-05 21:23:02 +0200832 * \param state - \c [out] One of AMDGPU_CTX_*_RESET
833 * \param hangs - \c [out] Number of hangs caused by the context.
Alex Deucher09361392015-04-20 12:04:22 -0400834 *
835 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400836 * <0 - Negative POSIX Error code
837 *
838 * \sa amdgpu_cs_ctx_create()
839 *
840*/
Christian König9c2afff2015-04-22 12:21:13 +0200841int amdgpu_cs_query_reset_state(amdgpu_context_handle context,
Marek Olšák4b39a8e2015-05-05 21:23:02 +0200842 uint32_t *state, uint32_t *hangs);
Alex Deucher09361392015-04-20 12:04:22 -0400843
Alex Deucher09361392015-04-20 12:04:22 -0400844/*
845 * Command Buffers Management
846 *
847*/
848
Alex Deucher09361392015-04-20 12:04:22 -0400849/**
850 * Send request to submit command buffers to hardware.
851 *
852 * Kernel driver could use GPU Scheduler to make decision when physically
853 * sent this request to the hardware. Accordingly this request could be put
854 * in queue and sent for execution later. The only guarantee is that request
855 * from the same GPU context to the same ip:ip_instance:ring will be executed in
856 * order.
857 *
858 *
859 * \param dev - \c [in] Device handle.
860 * See #amdgpu_device_initialize()
861 * \param context - \c [in] GPU Context
862 * \param flags - \c [in] Global submission flags
863 * \param ibs_request - \c [in] Pointer to submission requests.
864 * We could submit to the several
865 * engines/rings simulteniously as
866 * 'atomic' operation
867 * \param number_of_requests - \c [in] Number of submission requests
868 * \param fences - \c [out] Pointer to array of data to get
869 * fences to identify submission
870 * requests. Timestamps are valid
871 * in this GPU context and could be used
872 * to identify/detect completion of
873 * submission request
874 *
875 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400876 * <0 - Negative POSIX Error code
877 *
Alex Deucher09361392015-04-20 12:04:22 -0400878 * \note It is required to pass correct resource list with buffer handles
879 * which will be accessible by command buffers from submission
880 * This will allow kernel driver to correctly implement "paging".
881 * Failure to do so will have unpredictable results.
882 *
883 * \sa amdgpu_command_buffer_alloc(), amdgpu_command_buffer_free(),
884 * amdgpu_cs_query_fence_status()
885 *
886*/
Christian König9c2afff2015-04-22 12:21:13 +0200887int amdgpu_cs_submit(amdgpu_context_handle context,
Alex Deucher09361392015-04-20 12:04:22 -0400888 uint64_t flags,
889 struct amdgpu_cs_request *ibs_request,
890 uint32_t number_of_requests,
891 uint64_t *fences);
892
893/**
894 * Query status of Command Buffer Submission
895 *
896 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
897 * \param fence - \c [in] Structure describing fence to query
898 * \param expired - \c [out] If fence expired or not.\n
899 * 0 – if fence is not expired\n
900 * !0 - otherwise
901 *
902 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400903 * <0 - Negative POSIX Error code
904 *
905 * \note If UMD wants only to check operation status and returned immediately
906 * then timeout value as 0 must be passed. In this case success will be
907 * returned in the case if submission was completed or timeout error
908 * code.
909 *
910 * \sa amdgpu_cs_submit()
911*/
Christian König9c2afff2015-04-22 12:21:13 +0200912int amdgpu_cs_query_fence_status(struct amdgpu_cs_query_fence *fence,
Alex Deucher09361392015-04-20 12:04:22 -0400913 uint32_t *expired);
914
Alex Deucher09361392015-04-20 12:04:22 -0400915/*
916 * Query / Info API
917 *
918*/
919
Alex Deucher09361392015-04-20 12:04:22 -0400920/**
921 * Query allocation size alignments
922 *
923 * UMD should query information about GPU VM MC size alignments requirements
924 * to be able correctly choose required allocation size and implement
925 * internal optimization if needed.
926 *
927 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
928 * \param info - \c [out] Pointer to structure to get size alignment
929 * requirements
930 *
931 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400932 * <0 - Negative POSIX Error code
933 *
934*/
935int amdgpu_query_buffer_size_alignment(amdgpu_device_handle dev,
Christian König558e1292015-06-30 16:04:44 +0200936 struct amdgpu_buffer_size_alignments
937 *info);
Alex Deucher09361392015-04-20 12:04:22 -0400938
939/**
940 * Query firmware versions
941 *
942 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
943 * \param fw_type - \c [in] AMDGPU_INFO_FW_*
944 * \param ip_instance - \c [in] Index of the IP block of the same type.
945 * \param index - \c [in] Index of the engine. (for SDMA and MEC)
946 * \param version - \c [out] Pointer to to the "version" return value
947 * \param feature - \c [out] Pointer to to the "feature" return value
948 *
949 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400950 * <0 - Negative POSIX Error code
951 *
952*/
953int amdgpu_query_firmware_version(amdgpu_device_handle dev, unsigned fw_type,
954 unsigned ip_instance, unsigned index,
955 uint32_t *version, uint32_t *feature);
956
Alex Deucher09361392015-04-20 12:04:22 -0400957/**
958 * Query the number of HW IP instances of a certain type.
959 *
960 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
961 * \param type - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
962 * \param count - \c [out] Pointer to structure to get information
963 *
964 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400965 * <0 - Negative POSIX Error code
966*/
967int amdgpu_query_hw_ip_count(amdgpu_device_handle dev, unsigned type,
968 uint32_t *count);
969
Alex Deucher09361392015-04-20 12:04:22 -0400970/**
971 * Query engine information
972 *
973 * This query allows UMD to query information different engines and their
974 * capabilities.
975 *
976 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
977 * \param type - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
978 * \param ip_instance - \c [in] Index of the IP block of the same type.
979 * \param info - \c [out] Pointer to structure to get information
980 *
981 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400982 * <0 - Negative POSIX Error code
983*/
984int amdgpu_query_hw_ip_info(amdgpu_device_handle dev, unsigned type,
985 unsigned ip_instance,
986 struct drm_amdgpu_info_hw_ip *info);
987
Alex Deucher09361392015-04-20 12:04:22 -0400988/**
989 * Query heap information
990 *
991 * This query allows UMD to query potentially available memory resources and
992 * adjust their logic if necessary.
993 *
994 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
995 * \param heap - \c [in] Heap type
996 * \param info - \c [in] Pointer to structure to get needed information
997 *
998 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -0400999 * <0 - Negative POSIX Error code
1000 *
1001*/
Christian König558e1292015-06-30 16:04:44 +02001002int amdgpu_query_heap_info(amdgpu_device_handle dev, uint32_t heap,
1003 uint32_t flags, struct amdgpu_heap_info *info);
Alex Deucher09361392015-04-20 12:04:22 -04001004
1005/**
1006 * Get the CRTC ID from the mode object ID
1007 *
1008 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1009 * \param id - \c [in] Mode object ID
1010 * \param result - \c [in] Pointer to the CRTC ID
1011 *
1012 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -04001013 * <0 - Negative POSIX Error code
1014 *
1015*/
1016int amdgpu_query_crtc_from_id(amdgpu_device_handle dev, unsigned id,
1017 int32_t *result);
1018
Alex Deucher09361392015-04-20 12:04:22 -04001019/**
1020 * Query GPU H/w Info
1021 *
1022 * Query hardware specific information
1023 *
1024 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1025 * \param heap - \c [in] Heap type
1026 * \param info - \c [in] Pointer to structure to get needed information
1027 *
1028 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -04001029 * <0 - Negative POSIX Error code
1030 *
1031*/
1032int amdgpu_query_gpu_info(amdgpu_device_handle dev,
1033 struct amdgpu_gpu_info *info);
1034
Alex Deucher09361392015-04-20 12:04:22 -04001035/**
1036 * Query hardware or driver information.
1037 *
1038 * The return size is query-specific and depends on the "info_id" parameter.
1039 * No more than "size" bytes is returned.
1040 *
1041 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1042 * \param info_id - \c [in] AMDGPU_INFO_*
1043 * \param size - \c [in] Size of the returned value.
1044 * \param value - \c [out] Pointer to the return value.
1045 *
1046 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -04001047 * <0 - Negative POSIX error code
1048 *
1049*/
1050int amdgpu_query_info(amdgpu_device_handle dev, unsigned info_id,
1051 unsigned size, void *value);
1052
Christian König558e1292015-06-30 16:04:44 +02001053/**
1054 * Query information about GDS
1055 *
1056 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1057 * \param gds_info - \c [out] Pointer to structure to get GDS information
1058 *
1059 * \return 0 on success\n
Christian König558e1292015-06-30 16:04:44 +02001060 * <0 - Negative POSIX Error code
1061 *
1062*/
1063int amdgpu_query_gds_info(amdgpu_device_handle dev,
1064 struct amdgpu_gds_resource_info *gds_info);
Alex Deucher09361392015-04-20 12:04:22 -04001065
1066/**
1067 * Read a set of consecutive memory-mapped registers.
1068 * Not all registers are allowed to be read by userspace.
1069 *
1070 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize(
1071 * \param dword_offset - \c [in] Register offset in dwords
1072 * \param count - \c [in] The number of registers to read starting
1073 * from the offset
1074 * \param instance - \c [in] GRBM_GFX_INDEX selector. It may have other
1075 * uses. Set it to 0xffffffff if unsure.
1076 * \param flags - \c [in] Flags with additional information.
1077 * \param values - \c [out] The pointer to return values.
1078 *
1079 * \return 0 on success\n
Alex Deucher09361392015-04-20 12:04:22 -04001080 * <0 - Negative POSIX error code
1081 *
1082*/
1083int amdgpu_read_mm_registers(amdgpu_device_handle dev, unsigned dword_offset,
1084 unsigned count, uint32_t instance, uint32_t flags,
1085 uint32_t *values);
1086
Alex Deucher09361392015-04-20 12:04:22 -04001087#endif /* #ifdef _AMDGPU_H_ */