blob: 32bf30e752cb2046bf8d63f2b6651873ae7f18cb [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
59/**
Alex Deucher09361392015-04-20 12:04:22 -040060 * The special flag to mark that this IB will re-used
61 * by client and should not be automatically return back
62 * to free pool by libdrm_amdgpu when submission is completed.
63 *
64 * \sa amdgpu_cs_ib_info
65*/
66#define AMDGPU_CS_REUSE_IB 0x2
67
Alex Deucher09361392015-04-20 12:04:22 -040068/*--------------------------------------------------------------------------*/
69/* ----------------------------- Enums ------------------------------------ */
70/*--------------------------------------------------------------------------*/
71
72/**
73 * Enum describing possible handle types
74 *
75 * \sa amdgpu_bo_import, amdgpu_bo_export
76 *
77*/
78enum amdgpu_bo_handle_type {
79 /** GEM flink name (needs DRM authentication, used by DRI2) */
80 amdgpu_bo_handle_type_gem_flink_name = 0,
81
82 /** KMS handle which is used by all driver ioctls */
83 amdgpu_bo_handle_type_kms = 1,
84
85 /** DMA-buf fd handle */
86 amdgpu_bo_handle_type_dma_buf_fd = 2
87};
88
89/**
Alex Deucher09361392015-04-20 12:04:22 -040090 * For performance reasons and to simplify logic libdrm_amdgpu will handle
91 * IBs only some pre-defined sizes.
92 *
93 * \sa amdgpu_cs_alloc_ib()
94 */
95enum amdgpu_cs_ib_size {
Jammy Zhou8a208ee2015-05-18 19:14:56 +080096 amdgpu_cs_ib_size_4K = 0,
97 amdgpu_cs_ib_size_16K = 1,
98 amdgpu_cs_ib_size_32K = 2,
99 amdgpu_cs_ib_size_64K = 3,
100 amdgpu_cs_ib_size_128K = 4
Alex Deucher09361392015-04-20 12:04:22 -0400101};
102
103/** The number of different IB sizes */
Jammy Zhou8a208ee2015-05-18 19:14:56 +0800104#define AMDGPU_CS_IB_SIZE_NUM 5
Alex Deucher09361392015-04-20 12:04:22 -0400105
106
107/*--------------------------------------------------------------------------*/
108/* -------------------------- Datatypes ----------------------------------- */
109/*--------------------------------------------------------------------------*/
110
111/**
112 * Define opaque pointer to context associated with fd.
113 * This context will be returned as the result of
114 * "initialize" function and should be pass as the first
115 * parameter to any API call
116 */
117typedef struct amdgpu_device *amdgpu_device_handle;
118
119/**
120 * Define GPU Context type as pointer to opaque structure
121 * Example of GPU Context is the "rendering" context associated
122 * with OpenGL context (glCreateContext)
123 */
124typedef struct amdgpu_context *amdgpu_context_handle;
125
126/**
127 * Define handle for amdgpu resources: buffer, GDS, etc.
128 */
129typedef struct amdgpu_bo *amdgpu_bo_handle;
130
131/**
Christian König6dc2eaf2015-04-22 14:52:34 +0200132 * Define handle for list of BOs
133 */
134typedef struct amdgpu_bo_list *amdgpu_bo_list_handle;
135
136/**
Alex Deucher09361392015-04-20 12:04:22 -0400137 * Define handle to be used when dealing with command
138 * buffers (a.k.a. ibs)
139 *
140 */
141typedef struct amdgpu_ib *amdgpu_ib_handle;
142
143
144/*--------------------------------------------------------------------------*/
145/* -------------------------- Structures ---------------------------------- */
146/*--------------------------------------------------------------------------*/
147
148/**
149 * Structure describing memory allocation request
150 *
151 * \sa amdgpu_bo_alloc()
152 *
153*/
154struct amdgpu_bo_alloc_request {
155 /** Allocation request. It must be aligned correctly. */
156 uint64_t alloc_size;
157
158 /**
159 * It may be required to have some specific alignment requirements
160 * for physical back-up storage (e.g. for displayable surface).
161 * If 0 there is no special alignment requirement
162 */
163 uint64_t phys_alignment;
164
165 /**
166 * UMD should specify where to allocate memory and how it
167 * will be accessed by the CPU.
168 */
169 uint32_t preferred_heap;
170
171 /** Additional flags passed on allocation */
172 uint64_t flags;
173};
174
175/**
176 * Structure describing memory allocation request
177 *
178 * \sa amdgpu_bo_alloc()
179*/
180struct amdgpu_bo_alloc_result {
181 /** Assigned virtual MC Base Address */
182 uint64_t virtual_mc_base_address;
183
184 /** Handle of allocated memory to be used by the given process only. */
185 amdgpu_bo_handle buf_handle;
186};
187
188/**
189 * Special UMD specific information associated with buffer.
190 *
191 * It may be need to pass some buffer charactersitic as part
192 * of buffer sharing. Such information are defined UMD and
193 * opaque for libdrm_amdgpu as well for kernel driver.
194 *
195 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info,
196 * amdgpu_bo_import(), amdgpu_bo_export
197 *
198*/
199struct amdgpu_bo_metadata {
200 /** Special flag associated with surface */
201 uint64_t flags;
202
203 /**
204 * ASIC-specific tiling information (also used by DCE).
205 * The encoding is defined by the AMDGPU_TILING_* definitions.
206 */
207 uint64_t tiling_info;
208
209 /** Size of metadata associated with the buffer, in bytes. */
210 uint32_t size_metadata;
211
212 /** UMD specific metadata. Opaque for kernel */
213 uint32_t umd_metadata[64];
214};
215
216/**
217 * Structure describing allocated buffer. Client may need
218 * to query such information as part of 'sharing' buffers mechanism
219 *
220 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info(),
221 * amdgpu_bo_import(), amdgpu_bo_export()
222*/
223struct amdgpu_bo_info {
224 /** Allocated memory size */
225 uint64_t alloc_size;
226
227 /**
228 * It may be required to have some specific alignment requirements
229 * for physical back-up storage.
230 */
231 uint64_t phys_alignment;
232
233 /**
234 * Assigned virtual MC Base Address.
235 * \note This information will be returned only if this buffer was
236 * allocated in the same process otherwise 0 will be returned.
237 */
238 uint64_t virtual_mc_base_address;
239
240 /** Heap where to allocate memory. */
241 uint32_t preferred_heap;
242
243 /** Additional allocation flags. */
244 uint64_t alloc_flags;
245
246 /** Metadata associated with buffer if any. */
247 struct amdgpu_bo_metadata metadata;
248};
249
250/**
251 * Structure with information about "imported" buffer
252 *
253 * \sa amdgpu_bo_import()
254 *
255 */
256struct amdgpu_bo_import_result {
257 /** Handle of memory/buffer to use */
258 amdgpu_bo_handle buf_handle;
259
260 /** Buffer size */
261 uint64_t alloc_size;
262
263 /** Assigned virtual MC Base Address */
264 uint64_t virtual_mc_base_address;
265};
266
267
268/**
269 *
270 * Structure to describe GDS partitioning information.
271 * \note OA and GWS resources are asscoiated with GDS partition
272 *
273 * \sa amdgpu_gpu_resource_query_gds_info
274 *
275*/
276struct amdgpu_gds_resource_info {
277 uint32_t gds_gfx_partition_size;
278 uint32_t compute_partition_size;
279 uint32_t gds_total_size;
280 uint32_t gws_per_gfx_partition;
281 uint32_t gws_per_compute_partition;
282 uint32_t oa_per_gfx_partition;
283 uint32_t oa_per_compute_partition;
284};
285
286
287
288/**
289 * Structure describing result of request to allocate GDS
290 *
291 * \sa amdgpu_gpu_resource_gds_alloc
292 *
293*/
294struct amdgpu_gds_alloc_info {
295 /** Handle assigned to gds allocation */
296 amdgpu_bo_handle resource_handle;
297
298 /** How much was really allocated */
299 uint32_t gds_memory_size;
300
301 /** Number of GWS resources allocated */
302 uint32_t gws;
303
304 /** Number of OA resources allocated */
305 uint32_t oa;
306};
307
308/**
309 * Structure to described allocated command buffer (a.k.a. IB)
310 *
311 * \sa amdgpu_cs_alloc_ib()
312 *
313*/
314struct amdgpu_cs_ib_alloc_result {
315 /** IB allocation handle */
316 amdgpu_ib_handle handle;
317
318 /** Assigned GPU VM MC Address of command buffer */
319 uint64_t mc_address;
320
321 /** Address to be used for CPU access */
322 void *cpu;
323};
324
325/**
326 * Structure describing IB
327 *
328 * \sa amdgpu_cs_request, amdgpu_cs_submit()
329 *
330*/
331struct amdgpu_cs_ib_info {
332 /** Special flags */
333 uint64_t flags;
334
335 /** Handle of command buffer */
336 amdgpu_ib_handle ib_handle;
337
338 /**
339 * Size of Command Buffer to be submitted.
340 * - The size is in units of dwords (4 bytes).
341 * - Must be less or equal to the size of allocated IB
342 * - Could be 0
343 */
344 uint32_t size;
345};
346
347/**
348 * Structure describing submission request
349 *
350 * \note We could have several IBs as packet. e.g. CE, CE, DE case for gfx
351 *
352 * \sa amdgpu_cs_submit()
353*/
354struct amdgpu_cs_request {
355 /** Specify flags with additional information */
356 uint64_t flags;
357
358 /** Specify HW IP block type to which to send the IB. */
359 unsigned ip_type;
360
361 /** IP instance index if there are several IPs of the same type. */
362 unsigned ip_instance;
363
364 /**
365 * Specify ring index of the IP. We could have several rings
366 * in the same IP. E.g. 0 for SDMA0 and 1 for SDMA1.
367 */
368 uint32_t ring;
369
370 /**
Christian König6dc2eaf2015-04-22 14:52:34 +0200371 * List handle with resources used by this request.
Alex Deucher09361392015-04-20 12:04:22 -0400372 */
Christian König6dc2eaf2015-04-22 14:52:34 +0200373 amdgpu_bo_list_handle resources;
Alex Deucher09361392015-04-20 12:04:22 -0400374
375 /** Number of IBs to submit in the field ibs. */
376 uint32_t number_of_ibs;
377
378 /**
379 * IBs to submit. Those IBs will be submit together as single entity
380 */
381 struct amdgpu_cs_ib_info *ibs;
382};
383
384/**
385 * Structure describing request to check submission state using fence
386 *
387 * \sa amdgpu_cs_query_fence_status()
388 *
389*/
390struct amdgpu_cs_query_fence {
391
392 /** In which context IB was sent to execution */
393 amdgpu_context_handle context;
394
395 /** Timeout in nanoseconds. */
396 uint64_t timeout_ns;
397
398 /** To which HW IP type the fence belongs */
399 unsigned ip_type;
400
401 /** IP instance index if there are several IPs of the same type. */
402 unsigned ip_instance;
403
404 /** Ring index of the HW IP */
405 uint32_t ring;
406
407 /** Flags */
408 uint64_t flags;
409
410 /** Specify fence for which we need to check
411 * submission status.*/
412 uint64_t fence;
413};
414
415/**
416 * Structure which provide information about GPU VM MC Address space
417 * alignments requirements
418 *
419 * \sa amdgpu_query_buffer_size_alignment
420 */
421struct amdgpu_buffer_size_alignments {
422 /** Size alignment requirement for allocation in
423 * local memory */
424 uint64_t size_local;
425
426 /**
427 * Size alignment requirement for allocation in remote memory
428 */
429 uint64_t size_remote;
430};
431
432
433/**
434 * Structure which provide information about heap
435 *
436 * \sa amdgpu_query_heap_info()
437 *
438 */
439struct amdgpu_heap_info {
440 /** Theoretical max. available memory in the given heap */
441 uint64_t heap_size;
442
443 /**
444 * Number of bytes allocated in the heap. This includes all processes
445 * and private allocations in the kernel. It changes when new buffers
446 * are allocated, freed, and moved. It cannot be larger than
447 * heap_size.
448 */
449 uint64_t heap_usage;
450
451 /**
452 * Theoretical possible max. size of buffer which
453 * could be allocated in the given heap
454 */
455 uint64_t max_allocation;
456};
457
458
459
460/**
461 * Describe GPU h/w info needed for UMD correct initialization
462 *
463 * \sa amdgpu_query_gpu_info()
464*/
465struct amdgpu_gpu_info {
466 /** Asic id */
467 uint32_t asic_id;
468 /**< Chip revision */
469 uint32_t chip_rev;
470 /** Chip external revision */
471 uint32_t chip_external_rev;
472 /** Family ID */
473 uint32_t family_id;
474 /** Special flags */
475 uint64_t ids_flags;
476 /** max engine clock*/
477 uint64_t max_engine_clk;
478 /** number of shader engines */
479 uint32_t num_shader_engines;
480 /** number of shader arrays per engine */
481 uint32_t num_shader_arrays_per_engine;
482 /** Number of available good shader pipes */
483 uint32_t avail_quad_shader_pipes;
484 /** Max. number of shader pipes.(including good and bad pipes */
485 uint32_t max_quad_shader_pipes;
486 /** Number of parameter cache entries per shader quad pipe */
487 uint32_t cache_entries_per_quad_pipe;
488 /** Number of available graphics context */
489 uint32_t num_hw_gfx_contexts;
490 /** Number of render backend pipes */
491 uint32_t rb_pipes;
Alex Deucher09361392015-04-20 12:04:22 -0400492 /** Enabled render backend pipe mask */
493 uint32_t enabled_rb_pipes_mask;
494 /** Frequency of GPU Counter */
495 uint32_t gpu_counter_freq;
496 /** CC_RB_BACKEND_DISABLE.BACKEND_DISABLE per SE */
497 uint32_t backend_disable[4];
498 /** Value of MC_ARB_RAMCFG register*/
499 uint32_t mc_arb_ramcfg;
500 /** Value of GB_ADDR_CONFIG */
501 uint32_t gb_addr_cfg;
502 /** Values of the GB_TILE_MODE0..31 registers */
503 uint32_t gb_tile_mode[32];
504 /** Values of GB_MACROTILE_MODE0..15 registers */
505 uint32_t gb_macro_tile_mode[16];
506 /** Value of PA_SC_RASTER_CONFIG register per SE */
507 uint32_t pa_sc_raster_cfg[4];
508 /** Value of PA_SC_RASTER_CONFIG_1 register per SE */
509 uint32_t pa_sc_raster_cfg1[4];
510 /* CU info */
511 uint32_t cu_active_number;
512 uint32_t cu_ao_mask;
513 uint32_t cu_bitmap[4][4];
514};
515
516
517/*--------------------------------------------------------------------------*/
518/*------------------------- Functions --------------------------------------*/
519/*--------------------------------------------------------------------------*/
520
521/*
522 * Initialization / Cleanup
523 *
524*/
525
526
527/**
528 *
529 * \param fd - \c [in] File descriptor for AMD GPU device
530 * received previously as the result of
531 * e.g. drmOpen() call.
532 * For legacy fd type, the DRI2/DRI3 authentication
533 * should be done before calling this function.
534 * \param major_version - \c [out] Major version of library. It is assumed
535 * that adding new functionality will cause
536 * increase in major version
537 * \param minor_version - \c [out] Minor version of library
538 * \param device_handle - \c [out] Pointer to opaque context which should
539 * be passed as the first parameter on each
540 * API call
541 *
542 *
543 * \return 0 on success\n
544 * >0 - AMD specific error code\n
545 * <0 - Negative POSIX Error code
546 *
547 *
548 * \sa amdgpu_device_deinitialize()
549*/
550int amdgpu_device_initialize(int fd,
551 uint32_t *major_version,
552 uint32_t *minor_version,
553 amdgpu_device_handle *device_handle);
554
555
556
557/**
558 *
559 * When access to such library does not needed any more the special
560 * function must be call giving opportunity to clean up any
561 * resources if needed.
562 *
563 * \param device_handle - \c [in] Context associated with file
564 * descriptor for AMD GPU device
565 * received previously as the
566 * result e.g. of drmOpen() call.
567 *
568 * \return 0 on success\n
569 * >0 - AMD specific error code\n
570 * <0 - Negative POSIX Error code
571 *
572 * \sa amdgpu_device_initialize()
573 *
574*/
575int amdgpu_device_deinitialize(amdgpu_device_handle device_handle);
576
577
578/*
579 * Memory Management
580 *
581*/
582
583/**
584 * Allocate memory to be used by UMD for GPU related operations
585 *
586 * \param dev - \c [in] Device handle.
587 * See #amdgpu_device_initialize()
588 * \param alloc_buffer - \c [in] Pointer to the structure describing an
589 * allocation request
590 * \param info - \c [out] Pointer to structure which return
591 * information about allocated memory
592 *
593 * \return 0 on success\n
594 * >0 - AMD specific error code\n
595 * <0 - Negative POSIX Error code
596 *
597 * \sa amdgpu_bo_free()
598*/
599int amdgpu_bo_alloc(amdgpu_device_handle dev,
600 struct amdgpu_bo_alloc_request *alloc_buffer,
601 struct amdgpu_bo_alloc_result *info);
602
603/**
604 * Associate opaque data with buffer to be queried by another UMD
605 *
606 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
607 * \param buf_handle - \c [in] Buffer handle
608 * \param info - \c [in] Metadata to associated with buffer
609 *
610 * \return 0 on success\n
611 * >0 - AMD specific error code\n
612 * <0 - Negative POSIX Error code
613*/
614int amdgpu_bo_set_metadata(amdgpu_bo_handle buf_handle,
615 struct amdgpu_bo_metadata *info);
616
617/**
618 * Query buffer information including metadata previusly associated with
619 * buffer.
620 *
621 * \param dev - \c [in] Device handle.
622 * See #amdgpu_device_initialize()
623 * \param buf_handle - \c [in] Buffer handle
624 * \param info - \c [out] Structure describing buffer
625 *
626 * \return 0 on success\n
627 * >0 - AMD specific error code\n
628 * <0 - Negative POSIX Error code
629 *
630 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc()
631*/
632int amdgpu_bo_query_info(amdgpu_bo_handle buf_handle,
633 struct amdgpu_bo_info *info);
634
635/**
636 * Allow others to get access to buffer
637 *
638 * \param dev - \c [in] Device handle.
639 * See #amdgpu_device_initialize()
640 * \param buf_handle - \c [in] Buffer handle
641 * \param type - \c [in] Type of handle requested
642 * \param shared_handle - \c [out] Special "shared" handle
643 *
644 * \return 0 on success\n
645 * >0 - AMD specific error code\n
646 * <0 - Negative POSIX Error code
647 *
648 * \sa amdgpu_bo_import()
649 *
650*/
651int amdgpu_bo_export(amdgpu_bo_handle buf_handle,
652 enum amdgpu_bo_handle_type type,
653 uint32_t *shared_handle);
654
655/**
656 * Request access to "shared" buffer
657 *
658 * \param dev - \c [in] Device handle.
659 * See #amdgpu_device_initialize()
660 * \param type - \c [in] Type of handle requested
661 * \param shared_handle - \c [in] Shared handle received as result "import"
662 * operation
663 * \param output - \c [out] Pointer to structure with information
664 * about imported buffer
665 *
666 * \return 0 on success\n
667 * >0 - AMD specific error code\n
668 * <0 - Negative POSIX Error code
669 *
670 * \note Buffer must be "imported" only using new "fd" (different from
671 * one used by "exporter").
672 *
673 * \sa amdgpu_bo_export()
674 *
675*/
676int amdgpu_bo_import(amdgpu_device_handle dev,
677 enum amdgpu_bo_handle_type type,
678 uint32_t shared_handle,
679 struct amdgpu_bo_import_result *output);
680
681/**
682 * Free previosuly allocated memory
683 *
684 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
685 * \param buf_handle - \c [in] Buffer handle to free
686 *
687 * \return 0 on success\n
688 * >0 - AMD specific error code\n
689 * <0 - Negative POSIX Error code
690 *
691 * \note In the case of memory shared between different applications all
692 * resources will be “physically” freed only all such applications
693 * will be terminated
694 * \note If is UMD responsibility to ‘free’ buffer only when there is no
695 * more GPU access
696 *
697 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc()
698 *
699*/
700int amdgpu_bo_free(amdgpu_bo_handle buf_handle);
701
702/**
703 * Request CPU access to GPU accessable memory
704 *
705 * \param buf_handle - \c [in] Buffer handle
706 * \param cpu - \c [out] CPU address to be used for access
707 *
708 * \return 0 on success\n
709 * >0 - AMD specific error code\n
710 * <0 - Negative POSIX Error code
711 *
712 * \sa amdgpu_bo_cpu_unmap()
713 *
714*/
715int amdgpu_bo_cpu_map(amdgpu_bo_handle buf_handle, void **cpu);
716
717/**
718 * Release CPU access to GPU memory
719 *
720 * \param buf_handle - \c [in] Buffer handle
721 *
722 * \return 0 on success\n
723 * >0 - AMD specific error code\n
724 * <0 - Negative POSIX Error code
725 *
726 * \sa amdgpu_bo_cpu_map()
727 *
728*/
729int amdgpu_bo_cpu_unmap(amdgpu_bo_handle buf_handle);
730
731
732/**
733 * Wait until a buffer is not used by the device.
734 *
735 * \param dev - \c [in] Device handle. See #amdgpu_lib_initialize()
736 * \param buf_handle - \c [in] Buffer handle.
737 * \param timeout_ns - Timeout in nanoseconds.
738 * \param buffer_busy - 0 if buffer is idle, all GPU access was completed
739 * and no GPU access is scheduled.
740 * 1 GPU access is in fly or scheduled
741 *
742 * \return 0 - on success
743 * <0 - AMD specific error code
744 */
745int amdgpu_bo_wait_for_idle(amdgpu_bo_handle buf_handle,
746 uint64_t timeout_ns,
747 bool *buffer_busy);
748
Christian König6dc2eaf2015-04-22 14:52:34 +0200749/**
750 * Creates a BO list handle for command submission.
751 *
752 * \param dev - \c [in] Device handle.
753 * See #amdgpu_device_initialize()
754 * \param number_of_resources - \c [in] Number of BOs in the list
755 * \param resources - \c [in] List of BO handles
756 * \param resource_prios - \c [in] Optional priority for each handle
757 * \param result - \c [out] Created BO list handle
758 *
759 * \return 0 on success\n
760 * >0 - AMD specific error code\n
761 * <0 - Negative POSIX Error code
762 *
763 * \sa amdgpu_bo_list_destroy()
764*/
765int amdgpu_bo_list_create(amdgpu_device_handle dev,
766 uint32_t number_of_resources,
767 amdgpu_bo_handle *resources,
768 uint8_t *resource_prios,
769 amdgpu_bo_list_handle *result);
770
771/**
772 * Destroys a BO list handle.
773 *
774 * \param handle - \c [in] BO list handle.
775 *
776 * \return 0 on success\n
777 * >0 - AMD specific error code\n
778 * <0 - Negative POSIX Error code
779 *
780 * \sa amdgpu_bo_list_create()
781*/
782int amdgpu_bo_list_destroy(amdgpu_bo_list_handle handle);
Alex Deucher09361392015-04-20 12:04:22 -0400783
Jammy Zhou72446982015-05-18 20:27:24 +0800784/**
785 * Update resources for existing BO list
786 *
787 * \param handle - \c [in] BO list handle
788 * \param number_of_resources - \c [in] Number of BOs in the list
789 * \param resources - \c [in] List of BO handles
790 * \param resource_prios - \c [in] Optional priority for each handle
791 *
792 * \return 0 on success\n
793 * >0 - AMD specific error code\n
794 * <0 - Negative POSIX Error code
795 *
796 * \sa amdgpu_bo_list_update()
797*/
798int amdgpu_bo_list_update(amdgpu_bo_list_handle handle,
799 uint32_t number_of_resources,
800 amdgpu_bo_handle *resources,
801 uint8_t *resource_prios);
802
Alex Deucher09361392015-04-20 12:04:22 -0400803/*
804 * Special GPU Resources
805 *
806*/
807
808
809
810/**
811 * Query information about GDS
812 *
813 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
814 * \param gds_info - \c [out] Pointer to structure to get GDS information
815 *
816 * \return 0 on success\n
817 * >0 - AMD specific error code\n
818 * <0 - Negative POSIX Error code
819 *
820*/
821int amdgpu_gpu_resource_query_gds_info(amdgpu_device_handle dev,
822 struct amdgpu_gds_resource_info *
823 gds_info);
824
825
826/**
827 * Allocate GDS partitions
828 *
829 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
830 * \param gds_size - \c [in] Size of gds allocation. Must be aligned
831 * accordingly.
832 * \param alloc_info - \c [out] Pointer to structure to receive information
833 * about allocation
834 *
835 * \return 0 on success\n
836 * >0 - AMD specific error code\n
837 * <0 - Negative POSIX Error code
838 *
839 *
840*/
841int amdgpu_gpu_resource_gds_alloc(amdgpu_device_handle dev,
842 uint32_t gds_size,
843 struct amdgpu_gds_alloc_info *alloc_info);
844
845
846
847
848/**
849 * Release GDS resource. When GDS and associated resources not needed any
850 * more UMD should free them
851 *
852 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
853 * \param handle - \c [in] Handle assigned to GDS allocation
854 *
855 * \return 0 on success\n
856 * >0 - AMD specific error code\n
857 * <0 - Negative POSIX Error code
858 *
859*/
860int amdgpu_gpu_resource_gds_free(amdgpu_bo_handle handle);
861
862
863
864/*
865 * GPU Execution context
866 *
867*/
868
869/**
870 * Create GPU execution Context
871 *
872 * For the purpose of GPU Scheduler and GPU Robustness extensions it is
873 * necessary to have information/identify rendering/compute contexts.
874 * It also may be needed to associate some specific requirements with such
875 * contexts. Kernel driver will guarantee that submission from the same
876 * context will always be executed in order (first come, first serve).
877 *
878 *
879 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
880 * \param context - \c [out] GPU Context handle
881 *
882 * \return 0 on success\n
883 * >0 - AMD specific error code\n
884 * <0 - Negative POSIX Error code
885 *
886 * \sa amdgpu_cs_ctx_free()
887 *
888*/
889int amdgpu_cs_ctx_create(amdgpu_device_handle dev,
890 amdgpu_context_handle *context);
891
892/**
893 *
894 * Destroy GPU execution context when not needed any more
895 *
Alex Deucher09361392015-04-20 12:04:22 -0400896 * \param context - \c [in] GPU Context handle
897 *
898 * \return 0 on success\n
899 * >0 - AMD specific error code\n
900 * <0 - Negative POSIX Error code
901 *
902 * \sa amdgpu_cs_ctx_create()
903 *
904*/
Christian König9c2afff2015-04-22 12:21:13 +0200905int amdgpu_cs_ctx_free(amdgpu_context_handle context);
Alex Deucher09361392015-04-20 12:04:22 -0400906
907/**
908 * Query reset state for the specific GPU Context
909 *
Alex Deucher09361392015-04-20 12:04:22 -0400910 * \param context - \c [in] GPU Context handle
Marek Olšák4b39a8e2015-05-05 21:23:02 +0200911 * \param state - \c [out] One of AMDGPU_CTX_*_RESET
912 * \param hangs - \c [out] Number of hangs caused by the context.
Alex Deucher09361392015-04-20 12:04:22 -0400913 *
914 * \return 0 on success\n
915 * >0 - AMD specific error code\n
916 * <0 - Negative POSIX Error code
917 *
918 * \sa amdgpu_cs_ctx_create()
919 *
920*/
Christian König9c2afff2015-04-22 12:21:13 +0200921int amdgpu_cs_query_reset_state(amdgpu_context_handle context,
Marek Olšák4b39a8e2015-05-05 21:23:02 +0200922 uint32_t *state, uint32_t *hangs);
Alex Deucher09361392015-04-20 12:04:22 -0400923
924
925/*
926 * Command Buffers Management
927 *
928*/
929
930
931/**
932 * Allocate memory to be filled with PM4 packets and be served as the first
933 * entry point of execution (a.k.a. Indirect Buffer)
934 *
Alex Deucher09361392015-04-20 12:04:22 -0400935 * \param context - \c [in] GPU Context which will use IB
936 * \param ib_size - \c [in] Size of allocation
937 * \param output - \c [out] Pointer to structure to get information about
938 * allocated IB
939 *
940 * \return 0 on success\n
941 * >0 - AMD specific error code\n
942 * <0 - Negative POSIX Error code
943 *
944 * \sa amdgpu_cs_free_ib()
945 *
946*/
Christian König9c2afff2015-04-22 12:21:13 +0200947int amdgpu_cs_alloc_ib(amdgpu_context_handle context,
Alex Deucher09361392015-04-20 12:04:22 -0400948 enum amdgpu_cs_ib_size ib_size,
949 struct amdgpu_cs_ib_alloc_result *output);
950
951/**
952 * If UMD has allocates IBs which doesn’t need any more than those IBs must
953 * be explicitly freed
954 *
Alex Deucher09361392015-04-20 12:04:22 -0400955 * \param handle - \c [in] IB handle
956 *
957 * \return 0 on success\n
958 * >0 - AMD specific error code\n
959 * <0 - Negative POSIX Error code
960 *
961 * \note Libdrm_amdgpu will guarantee that it will correctly detect when it
962 * is safe to return IB to free pool
963 *
964 * \sa amdgpu_cs_alloc_ib()
965 *
966*/
Christian König9c2afff2015-04-22 12:21:13 +0200967int amdgpu_cs_free_ib(amdgpu_ib_handle handle);
Alex Deucher09361392015-04-20 12:04:22 -0400968
969/**
970 * Send request to submit command buffers to hardware.
971 *
972 * Kernel driver could use GPU Scheduler to make decision when physically
973 * sent this request to the hardware. Accordingly this request could be put
974 * in queue and sent for execution later. The only guarantee is that request
975 * from the same GPU context to the same ip:ip_instance:ring will be executed in
976 * order.
977 *
978 *
979 * \param dev - \c [in] Device handle.
980 * See #amdgpu_device_initialize()
981 * \param context - \c [in] GPU Context
982 * \param flags - \c [in] Global submission flags
983 * \param ibs_request - \c [in] Pointer to submission requests.
984 * We could submit to the several
985 * engines/rings simulteniously as
986 * 'atomic' operation
987 * \param number_of_requests - \c [in] Number of submission requests
988 * \param fences - \c [out] Pointer to array of data to get
989 * fences to identify submission
990 * requests. Timestamps are valid
991 * in this GPU context and could be used
992 * to identify/detect completion of
993 * submission request
994 *
995 * \return 0 on success\n
996 * >0 - AMD specific error code\n
997 * <0 - Negative POSIX Error code
998 *
999 * \note It is assumed that by default IB will be returned to free pool
1000 * automatically by libdrm_amdgpu when submission will completed.
1001 * It is possible for UMD to make decision to re-use the same IB in
1002 * this case it should be explicitly freed.\n
1003 * Accordingly, by default, after submission UMD should not touch passed
1004 * IBs. If UMD needs to re-use IB then the special flag AMDGPU_CS_REUSE_IB
1005 * must be passed.
1006 *
1007 * \note It is required to pass correct resource list with buffer handles
1008 * which will be accessible by command buffers from submission
1009 * This will allow kernel driver to correctly implement "paging".
1010 * Failure to do so will have unpredictable results.
1011 *
1012 * \sa amdgpu_command_buffer_alloc(), amdgpu_command_buffer_free(),
1013 * amdgpu_cs_query_fence_status()
1014 *
1015*/
Christian König9c2afff2015-04-22 12:21:13 +02001016int amdgpu_cs_submit(amdgpu_context_handle context,
Alex Deucher09361392015-04-20 12:04:22 -04001017 uint64_t flags,
1018 struct amdgpu_cs_request *ibs_request,
1019 uint32_t number_of_requests,
1020 uint64_t *fences);
1021
1022/**
1023 * Query status of Command Buffer Submission
1024 *
1025 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1026 * \param fence - \c [in] Structure describing fence to query
1027 * \param expired - \c [out] If fence expired or not.\n
1028 * 0 – if fence is not expired\n
1029 * !0 - otherwise
1030 *
1031 * \return 0 on success\n
1032 * >0 - AMD specific error code\n
1033 * <0 - Negative POSIX Error code
1034 *
1035 * \note If UMD wants only to check operation status and returned immediately
1036 * then timeout value as 0 must be passed. In this case success will be
1037 * returned in the case if submission was completed or timeout error
1038 * code.
1039 *
1040 * \sa amdgpu_cs_submit()
1041*/
Christian König9c2afff2015-04-22 12:21:13 +02001042int amdgpu_cs_query_fence_status(struct amdgpu_cs_query_fence *fence,
Alex Deucher09361392015-04-20 12:04:22 -04001043 uint32_t *expired);
1044
1045
1046/*
1047 * Query / Info API
1048 *
1049*/
1050
1051
1052/**
1053 * Query allocation size alignments
1054 *
1055 * UMD should query information about GPU VM MC size alignments requirements
1056 * to be able correctly choose required allocation size and implement
1057 * internal optimization if needed.
1058 *
1059 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1060 * \param info - \c [out] Pointer to structure to get size alignment
1061 * requirements
1062 *
1063 * \return 0 on success\n
1064 * >0 - AMD specific error code\n
1065 * <0 - Negative POSIX Error code
1066 *
1067*/
1068int amdgpu_query_buffer_size_alignment(amdgpu_device_handle dev,
1069 struct amdgpu_buffer_size_alignments
1070 *info);
1071
1072
1073
1074/**
1075 * Query firmware versions
1076 *
1077 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1078 * \param fw_type - \c [in] AMDGPU_INFO_FW_*
1079 * \param ip_instance - \c [in] Index of the IP block of the same type.
1080 * \param index - \c [in] Index of the engine. (for SDMA and MEC)
1081 * \param version - \c [out] Pointer to to the "version" return value
1082 * \param feature - \c [out] Pointer to to the "feature" return value
1083 *
1084 * \return 0 on success\n
1085 * >0 - AMD specific error code\n
1086 * <0 - Negative POSIX Error code
1087 *
1088*/
1089int amdgpu_query_firmware_version(amdgpu_device_handle dev, unsigned fw_type,
1090 unsigned ip_instance, unsigned index,
1091 uint32_t *version, uint32_t *feature);
1092
1093
1094
1095/**
1096 * Query the number of HW IP instances of a certain type.
1097 *
1098 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1099 * \param type - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
1100 * \param count - \c [out] Pointer to structure to get information
1101 *
1102 * \return 0 on success\n
1103 * >0 - AMD specific error code\n
1104 * <0 - Negative POSIX Error code
1105*/
1106int amdgpu_query_hw_ip_count(amdgpu_device_handle dev, unsigned type,
1107 uint32_t *count);
1108
1109
1110
1111/**
1112 * Query engine information
1113 *
1114 * This query allows UMD to query information different engines and their
1115 * capabilities.
1116 *
1117 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1118 * \param type - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
1119 * \param ip_instance - \c [in] Index of the IP block of the same type.
1120 * \param info - \c [out] Pointer to structure to get information
1121 *
1122 * \return 0 on success\n
1123 * >0 - AMD specific error code\n
1124 * <0 - Negative POSIX Error code
1125*/
1126int amdgpu_query_hw_ip_info(amdgpu_device_handle dev, unsigned type,
1127 unsigned ip_instance,
1128 struct drm_amdgpu_info_hw_ip *info);
1129
1130
1131
1132
1133/**
1134 * Query heap information
1135 *
1136 * This query allows UMD to query potentially available memory resources and
1137 * adjust their logic if necessary.
1138 *
1139 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1140 * \param heap - \c [in] Heap type
1141 * \param info - \c [in] Pointer to structure to get needed information
1142 *
1143 * \return 0 on success\n
1144 * >0 - AMD specific error code\n
1145 * <0 - Negative POSIX Error code
1146 *
1147*/
1148int amdgpu_query_heap_info(amdgpu_device_handle dev,
1149 uint32_t heap,
1150 uint32_t flags,
1151 struct amdgpu_heap_info *info);
1152
1153
1154
1155/**
1156 * Get the CRTC ID from the mode object ID
1157 *
1158 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1159 * \param id - \c [in] Mode object ID
1160 * \param result - \c [in] Pointer to the CRTC ID
1161 *
1162 * \return 0 on success\n
1163 * >0 - AMD specific error code\n
1164 * <0 - Negative POSIX Error code
1165 *
1166*/
1167int amdgpu_query_crtc_from_id(amdgpu_device_handle dev, unsigned id,
1168 int32_t *result);
1169
1170
1171
1172/**
1173 * Query GPU H/w Info
1174 *
1175 * Query hardware specific information
1176 *
1177 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1178 * \param heap - \c [in] Heap type
1179 * \param info - \c [in] Pointer to structure to get needed information
1180 *
1181 * \return 0 on success\n
1182 * >0 - AMD specific error code\n
1183 * <0 - Negative POSIX Error code
1184 *
1185*/
1186int amdgpu_query_gpu_info(amdgpu_device_handle dev,
1187 struct amdgpu_gpu_info *info);
1188
1189
1190
1191/**
1192 * Query hardware or driver information.
1193 *
1194 * The return size is query-specific and depends on the "info_id" parameter.
1195 * No more than "size" bytes is returned.
1196 *
1197 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1198 * \param info_id - \c [in] AMDGPU_INFO_*
1199 * \param size - \c [in] Size of the returned value.
1200 * \param value - \c [out] Pointer to the return value.
1201 *
1202 * \return 0 on success\n
1203 * >0 - AMD specific error code\n
1204 * <0 - Negative POSIX error code
1205 *
1206*/
1207int amdgpu_query_info(amdgpu_device_handle dev, unsigned info_id,
1208 unsigned size, void *value);
1209
1210
1211
1212/**
1213 * Read a set of consecutive memory-mapped registers.
1214 * Not all registers are allowed to be read by userspace.
1215 *
1216 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize(
1217 * \param dword_offset - \c [in] Register offset in dwords
1218 * \param count - \c [in] The number of registers to read starting
1219 * from the offset
1220 * \param instance - \c [in] GRBM_GFX_INDEX selector. It may have other
1221 * uses. Set it to 0xffffffff if unsure.
1222 * \param flags - \c [in] Flags with additional information.
1223 * \param values - \c [out] The pointer to return values.
1224 *
1225 * \return 0 on success\n
1226 * >0 - AMD specific error code\n
1227 * <0 - Negative POSIX error code
1228 *
1229*/
1230int amdgpu_read_mm_registers(amdgpu_device_handle dev, unsigned dword_offset,
1231 unsigned count, uint32_t instance, uint32_t flags,
1232 uint32_t *values);
1233
1234
1235
1236/**
1237 * Request GPU access to user allocated memory e.g. via "malloc"
1238 *
1239 * \param dev - [in] Device handle. See #amdgpu_device_initialize()
1240 * \param cpu - [in] CPU address of user allocated memory which we
1241 * want to map to GPU address space (make GPU accessible)
1242 * (This address must be correctly aligned).
1243 * \param size - [in] Size of allocation (must be correctly aligned)
1244 * \param amdgpu_bo_alloc_result - [out] Handle of allocation to be passed as resource
1245 * on submission and be used in other operations.(e.g. for VA submission)
1246 * ( Temporally defined amdgpu_bo_alloc_result as parameter for return mc address. )
1247 *
1248 *
1249 * \return 0 on success
1250 * >0 - AMD specific error code
1251 * <0 - Negative POSIX Error code
1252 *
1253 *
1254 * \note
1255 * This call doesn't guarantee that such memory will be persistently
1256 * "locked" / make non-pageable. The purpose of this call is to provide
1257 * opportunity for GPU get access to this resource during submission.
1258 *
1259 * The maximum amount of memory which could be mapped in this call depends
1260 * if overcommit is disabled or not. If overcommit is disabled than the max.
1261 * amount of memory to be pinned will be limited by left "free" size in total
1262 * amount of memory which could be locked simultaneously ("GART" size).
1263 *
1264 * Supported (theoretical) max. size of mapping is restricted only by
1265 * "GART" size.
1266 *
1267 * It is responsibility of caller to correctly specify access rights
1268 * on VA assignment.
1269*/
1270int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev,
1271 void *cpu,
1272 uint64_t size,
1273 struct amdgpu_bo_alloc_result *info);
1274
1275
1276#endif /* #ifdef _AMDGPU_H_ */