2 * Copyright 2014 Advanced Micro Devices, Inc.
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:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
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.
27 * Declare public libdrm_amdgpu API
29 * This file define API exposed by libdrm_amdgpu library.
30 * User wanted to use libdrm_amdgpu functionality must include
40 struct drm_amdgpu_info_hw_ip;
42 /*--------------------------------------------------------------------------*/
43 /* --------------------------- Defines ------------------------------------ */
44 /*--------------------------------------------------------------------------*/
47 * Define max. number of Command Buffers (IB) which could be sent to the single
48 * hardware IP to accommodate CE/DE requirements
50 * \sa amdgpu_cs_ib_info
52 #define AMDGPU_CS_MAX_IBS_PER_SUBMIT 4
57 #define AMDGPU_TIMEOUT_INFINITE 0xffffffffffffffffull
60 * 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.
64 * \sa amdgpu_cs_ib_info
66 #define AMDGPU_CS_REUSE_IB 0x2
69 * The special resource flag for IB submission.
70 * When VRAM is full, some resources may be moved to GTT to make place
71 * for other resources which want to be in VRAM. This flag affects the order
72 * in which resources are moved back to VRAM until there is no space there.
73 * The resources with the highest priority will be moved first.
74 * The value can be between 0 and 15, inclusive.
76 #define AMDGPU_IB_RESOURCE_PRIORITY(x) ((x) & 0xf)
79 /*--------------------------------------------------------------------------*/
80 /* ----------------------------- Enums ------------------------------------ */
81 /*--------------------------------------------------------------------------*/
84 * Enum describing possible handle types
86 * \sa amdgpu_bo_import, amdgpu_bo_export
89 enum amdgpu_bo_handle_type {
90 /** GEM flink name (needs DRM authentication, used by DRI2) */
91 amdgpu_bo_handle_type_gem_flink_name = 0,
93 /** KMS handle which is used by all driver ioctls */
94 amdgpu_bo_handle_type_kms = 1,
96 /** DMA-buf fd handle */
97 amdgpu_bo_handle_type_dma_buf_fd = 2
101 * Enum describing possible context reset states
103 * \sa amdgpu_cs_query_reset_state()
106 enum amdgpu_cs_ctx_reset_state {
107 /** No reset was detected */
108 amdgpu_cs_reset_no_error = 0,
110 /** Reset/TDR was detected and context caused */
111 amdgpu_cs_reset_guilty = 1,
113 /** Reset/TDR was detected caused by other context */
114 amdgpu_cs_reset_innocent = 2,
116 /** Reset TDR was detected by cause of it unknown */
117 amdgpu_cs_reset_unknown = 3
121 * For performance reasons and to simplify logic libdrm_amdgpu will handle
122 * IBs only some pre-defined sizes.
124 * \sa amdgpu_cs_alloc_ib()
126 enum amdgpu_cs_ib_size {
127 amdgpu_cs_ib_size_4K = 1,
128 amdgpu_cs_ib_size_16K = 2,
129 amdgpu_cs_ib_size_32K = 3,
130 amdgpu_cs_ib_size_64K = 4,
131 amdgpu_cs_ib_size_128K = 5
134 /** The number of different IB sizes */
135 #define AMDGPU_CS_IB_SIZE_NUM 6
138 /*--------------------------------------------------------------------------*/
139 /* -------------------------- Datatypes ----------------------------------- */
140 /*--------------------------------------------------------------------------*/
143 * Define opaque pointer to context associated with fd.
144 * This context will be returned as the result of
145 * "initialize" function and should be pass as the first
146 * parameter to any API call
148 typedef struct amdgpu_device *amdgpu_device_handle;
151 * Define GPU Context type as pointer to opaque structure
152 * Example of GPU Context is the "rendering" context associated
153 * with OpenGL context (glCreateContext)
155 typedef struct amdgpu_context *amdgpu_context_handle;
158 * Define handle for amdgpu resources: buffer, GDS, etc.
160 typedef struct amdgpu_bo *amdgpu_bo_handle;
163 * Define handle for list of BOs
165 typedef struct amdgpu_bo_list *amdgpu_bo_list_handle;
168 * Define handle to be used when dealing with command
169 * buffers (a.k.a. ibs)
172 typedef struct amdgpu_ib *amdgpu_ib_handle;
175 /*--------------------------------------------------------------------------*/
176 /* -------------------------- Structures ---------------------------------- */
177 /*--------------------------------------------------------------------------*/
180 * Structure describing memory allocation request
182 * \sa amdgpu_bo_alloc()
185 struct amdgpu_bo_alloc_request {
186 /** Allocation request. It must be aligned correctly. */
190 * It may be required to have some specific alignment requirements
191 * for physical back-up storage (e.g. for displayable surface).
192 * If 0 there is no special alignment requirement
194 uint64_t phys_alignment;
197 * UMD should specify where to allocate memory and how it
198 * will be accessed by the CPU.
200 uint32_t preferred_heap;
202 /** Additional flags passed on allocation */
207 * Structure describing memory allocation request
209 * \sa amdgpu_bo_alloc()
211 struct amdgpu_bo_alloc_result {
212 /** Assigned virtual MC Base Address */
213 uint64_t virtual_mc_base_address;
215 /** Handle of allocated memory to be used by the given process only. */
216 amdgpu_bo_handle buf_handle;
220 * Special UMD specific information associated with buffer.
222 * It may be need to pass some buffer charactersitic as part
223 * of buffer sharing. Such information are defined UMD and
224 * opaque for libdrm_amdgpu as well for kernel driver.
226 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info,
227 * amdgpu_bo_import(), amdgpu_bo_export
230 struct amdgpu_bo_metadata {
231 /** Special flag associated with surface */
235 * ASIC-specific tiling information (also used by DCE).
236 * The encoding is defined by the AMDGPU_TILING_* definitions.
238 uint64_t tiling_info;
240 /** Size of metadata associated with the buffer, in bytes. */
241 uint32_t size_metadata;
243 /** UMD specific metadata. Opaque for kernel */
244 uint32_t umd_metadata[64];
248 * Structure describing allocated buffer. Client may need
249 * to query such information as part of 'sharing' buffers mechanism
251 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info(),
252 * amdgpu_bo_import(), amdgpu_bo_export()
254 struct amdgpu_bo_info {
255 /** Allocated memory size */
259 * It may be required to have some specific alignment requirements
260 * for physical back-up storage.
262 uint64_t phys_alignment;
265 * Assigned virtual MC Base Address.
266 * \note This information will be returned only if this buffer was
267 * allocated in the same process otherwise 0 will be returned.
269 uint64_t virtual_mc_base_address;
271 /** Heap where to allocate memory. */
272 uint32_t preferred_heap;
274 /** Additional allocation flags. */
275 uint64_t alloc_flags;
277 /** Metadata associated with buffer if any. */
278 struct amdgpu_bo_metadata metadata;
282 * Structure with information about "imported" buffer
284 * \sa amdgpu_bo_import()
287 struct amdgpu_bo_import_result {
288 /** Handle of memory/buffer to use */
289 amdgpu_bo_handle buf_handle;
294 /** Assigned virtual MC Base Address */
295 uint64_t virtual_mc_base_address;
301 * Structure to describe GDS partitioning information.
302 * \note OA and GWS resources are asscoiated with GDS partition
304 * \sa amdgpu_gpu_resource_query_gds_info
307 struct amdgpu_gds_resource_info {
308 uint32_t gds_gfx_partition_size;
309 uint32_t compute_partition_size;
310 uint32_t gds_total_size;
311 uint32_t gws_per_gfx_partition;
312 uint32_t gws_per_compute_partition;
313 uint32_t oa_per_gfx_partition;
314 uint32_t oa_per_compute_partition;
320 * Structure describing result of request to allocate GDS
322 * \sa amdgpu_gpu_resource_gds_alloc
325 struct amdgpu_gds_alloc_info {
326 /** Handle assigned to gds allocation */
327 amdgpu_bo_handle resource_handle;
329 /** How much was really allocated */
330 uint32_t gds_memory_size;
332 /** Number of GWS resources allocated */
335 /** Number of OA resources allocated */
340 * Structure to described allocated command buffer (a.k.a. IB)
342 * \sa amdgpu_cs_alloc_ib()
345 struct amdgpu_cs_ib_alloc_result {
346 /** IB allocation handle */
347 amdgpu_ib_handle handle;
349 /** Assigned GPU VM MC Address of command buffer */
352 /** Address to be used for CPU access */
357 * Structure describing IB
359 * \sa amdgpu_cs_request, amdgpu_cs_submit()
362 struct amdgpu_cs_ib_info {
366 /** Handle of command buffer */
367 amdgpu_ib_handle ib_handle;
370 * Size of Command Buffer to be submitted.
371 * - The size is in units of dwords (4 bytes).
372 * - Must be less or equal to the size of allocated IB
379 * Structure describing submission request
381 * \note We could have several IBs as packet. e.g. CE, CE, DE case for gfx
383 * \sa amdgpu_cs_submit()
385 struct amdgpu_cs_request {
386 /** Specify flags with additional information */
389 /** Specify HW IP block type to which to send the IB. */
392 /** IP instance index if there are several IPs of the same type. */
393 unsigned ip_instance;
396 * Specify ring index of the IP. We could have several rings
397 * in the same IP. E.g. 0 for SDMA0 and 1 for SDMA1.
402 * List handle with resources used by this request.
404 amdgpu_bo_list_handle resources;
406 /** Number of IBs to submit in the field ibs. */
407 uint32_t number_of_ibs;
410 * IBs to submit. Those IBs will be submit together as single entity
412 struct amdgpu_cs_ib_info *ibs;
416 * Structure describing request to check submission state using fence
418 * \sa amdgpu_cs_query_fence_status()
421 struct amdgpu_cs_query_fence {
423 /** In which context IB was sent to execution */
424 amdgpu_context_handle context;
426 /** Timeout in nanoseconds. */
429 /** To which HW IP type the fence belongs */
432 /** IP instance index if there are several IPs of the same type. */
433 unsigned ip_instance;
435 /** Ring index of the HW IP */
441 /** Specify fence for which we need to check
442 * submission status.*/
447 * Structure which provide information about GPU VM MC Address space
448 * alignments requirements
450 * \sa amdgpu_query_buffer_size_alignment
452 struct amdgpu_buffer_size_alignments {
453 /** Size alignment requirement for allocation in
458 * Size alignment requirement for allocation in remote memory
460 uint64_t size_remote;
465 * Structure which provide information about heap
467 * \sa amdgpu_query_heap_info()
470 struct amdgpu_heap_info {
471 /** Theoretical max. available memory in the given heap */
475 * Number of bytes allocated in the heap. This includes all processes
476 * and private allocations in the kernel. It changes when new buffers
477 * are allocated, freed, and moved. It cannot be larger than
483 * Theoretical possible max. size of buffer which
484 * could be allocated in the given heap
486 uint64_t max_allocation;
492 * Describe GPU h/w info needed for UMD correct initialization
494 * \sa amdgpu_query_gpu_info()
496 struct amdgpu_gpu_info {
499 /**< Chip revision */
501 /** Chip external revision */
502 uint32_t chip_external_rev;
507 /** max engine clock*/
508 uint64_t max_engine_clk;
509 /** number of shader engines */
510 uint32_t num_shader_engines;
511 /** number of shader arrays per engine */
512 uint32_t num_shader_arrays_per_engine;
513 /** Number of available good shader pipes */
514 uint32_t avail_quad_shader_pipes;
515 /** Max. number of shader pipes.(including good and bad pipes */
516 uint32_t max_quad_shader_pipes;
517 /** Number of parameter cache entries per shader quad pipe */
518 uint32_t cache_entries_per_quad_pipe;
519 /** Number of available graphics context */
520 uint32_t num_hw_gfx_contexts;
521 /** Number of render backend pipes */
523 /** Enabled render backend pipe mask */
524 uint32_t enabled_rb_pipes_mask;
525 /** Frequency of GPU Counter */
526 uint32_t gpu_counter_freq;
527 /** CC_RB_BACKEND_DISABLE.BACKEND_DISABLE per SE */
528 uint32_t backend_disable[4];
529 /** Value of MC_ARB_RAMCFG register*/
530 uint32_t mc_arb_ramcfg;
531 /** Value of GB_ADDR_CONFIG */
532 uint32_t gb_addr_cfg;
533 /** Values of the GB_TILE_MODE0..31 registers */
534 uint32_t gb_tile_mode[32];
535 /** Values of GB_MACROTILE_MODE0..15 registers */
536 uint32_t gb_macro_tile_mode[16];
537 /** Value of PA_SC_RASTER_CONFIG register per SE */
538 uint32_t pa_sc_raster_cfg[4];
539 /** Value of PA_SC_RASTER_CONFIG_1 register per SE */
540 uint32_t pa_sc_raster_cfg1[4];
542 uint32_t cu_active_number;
544 uint32_t cu_bitmap[4][4];
548 /*--------------------------------------------------------------------------*/
549 /*------------------------- Functions --------------------------------------*/
550 /*--------------------------------------------------------------------------*/
553 * Initialization / Cleanup
560 * \param fd - \c [in] File descriptor for AMD GPU device
561 * received previously as the result of
562 * e.g. drmOpen() call.
563 * For legacy fd type, the DRI2/DRI3 authentication
564 * should be done before calling this function.
565 * \param major_version - \c [out] Major version of library. It is assumed
566 * that adding new functionality will cause
567 * increase in major version
568 * \param minor_version - \c [out] Minor version of library
569 * \param device_handle - \c [out] Pointer to opaque context which should
570 * be passed as the first parameter on each
574 * \return 0 on success\n
575 * >0 - AMD specific error code\n
576 * <0 - Negative POSIX Error code
579 * \sa amdgpu_device_deinitialize()
581 int amdgpu_device_initialize(int fd,
582 uint32_t *major_version,
583 uint32_t *minor_version,
584 amdgpu_device_handle *device_handle);
590 * When access to such library does not needed any more the special
591 * function must be call giving opportunity to clean up any
592 * resources if needed.
594 * \param device_handle - \c [in] Context associated with file
595 * descriptor for AMD GPU device
596 * received previously as the
597 * result e.g. of drmOpen() call.
599 * \return 0 on success\n
600 * >0 - AMD specific error code\n
601 * <0 - Negative POSIX Error code
603 * \sa amdgpu_device_initialize()
606 int amdgpu_device_deinitialize(amdgpu_device_handle device_handle);
615 * Allocate memory to be used by UMD for GPU related operations
617 * \param dev - \c [in] Device handle.
618 * See #amdgpu_device_initialize()
619 * \param alloc_buffer - \c [in] Pointer to the structure describing an
621 * \param info - \c [out] Pointer to structure which return
622 * information about allocated memory
624 * \return 0 on success\n
625 * >0 - AMD specific error code\n
626 * <0 - Negative POSIX Error code
628 * \sa amdgpu_bo_free()
630 int amdgpu_bo_alloc(amdgpu_device_handle dev,
631 struct amdgpu_bo_alloc_request *alloc_buffer,
632 struct amdgpu_bo_alloc_result *info);
635 * Associate opaque data with buffer to be queried by another UMD
637 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
638 * \param buf_handle - \c [in] Buffer handle
639 * \param info - \c [in] Metadata to associated with buffer
641 * \return 0 on success\n
642 * >0 - AMD specific error code\n
643 * <0 - Negative POSIX Error code
645 int amdgpu_bo_set_metadata(amdgpu_bo_handle buf_handle,
646 struct amdgpu_bo_metadata *info);
649 * Query buffer information including metadata previusly associated with
652 * \param dev - \c [in] Device handle.
653 * See #amdgpu_device_initialize()
654 * \param buf_handle - \c [in] Buffer handle
655 * \param info - \c [out] Structure describing buffer
657 * \return 0 on success\n
658 * >0 - AMD specific error code\n
659 * <0 - Negative POSIX Error code
661 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc()
663 int amdgpu_bo_query_info(amdgpu_bo_handle buf_handle,
664 struct amdgpu_bo_info *info);
667 * Allow others to get access to buffer
669 * \param dev - \c [in] Device handle.
670 * See #amdgpu_device_initialize()
671 * \param buf_handle - \c [in] Buffer handle
672 * \param type - \c [in] Type of handle requested
673 * \param shared_handle - \c [out] Special "shared" handle
675 * \return 0 on success\n
676 * >0 - AMD specific error code\n
677 * <0 - Negative POSIX Error code
679 * \sa amdgpu_bo_import()
682 int amdgpu_bo_export(amdgpu_bo_handle buf_handle,
683 enum amdgpu_bo_handle_type type,
684 uint32_t *shared_handle);
687 * Request access to "shared" buffer
689 * \param dev - \c [in] Device handle.
690 * See #amdgpu_device_initialize()
691 * \param type - \c [in] Type of handle requested
692 * \param shared_handle - \c [in] Shared handle received as result "import"
694 * \param output - \c [out] Pointer to structure with information
695 * about imported buffer
697 * \return 0 on success\n
698 * >0 - AMD specific error code\n
699 * <0 - Negative POSIX Error code
701 * \note Buffer must be "imported" only using new "fd" (different from
702 * one used by "exporter").
704 * \sa amdgpu_bo_export()
707 int amdgpu_bo_import(amdgpu_device_handle dev,
708 enum amdgpu_bo_handle_type type,
709 uint32_t shared_handle,
710 struct amdgpu_bo_import_result *output);
713 * Free previosuly allocated memory
715 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
716 * \param buf_handle - \c [in] Buffer handle to free
718 * \return 0 on success\n
719 * >0 - AMD specific error code\n
720 * <0 - Negative POSIX Error code
722 * \note In the case of memory shared between different applications all
723 * resources will be “physically” freed only all such applications
725 * \note If is UMD responsibility to ‘free’ buffer only when there is no
728 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc()
731 int amdgpu_bo_free(amdgpu_bo_handle buf_handle);
734 * Request CPU access to GPU accessable memory
736 * \param buf_handle - \c [in] Buffer handle
737 * \param cpu - \c [out] CPU address to be used for access
739 * \return 0 on success\n
740 * >0 - AMD specific error code\n
741 * <0 - Negative POSIX Error code
743 * \sa amdgpu_bo_cpu_unmap()
746 int amdgpu_bo_cpu_map(amdgpu_bo_handle buf_handle, void **cpu);
749 * Release CPU access to GPU memory
751 * \param buf_handle - \c [in] Buffer handle
753 * \return 0 on success\n
754 * >0 - AMD specific error code\n
755 * <0 - Negative POSIX Error code
757 * \sa amdgpu_bo_cpu_map()
760 int amdgpu_bo_cpu_unmap(amdgpu_bo_handle buf_handle);
764 * Wait until a buffer is not used by the device.
766 * \param dev - \c [in] Device handle. See #amdgpu_lib_initialize()
767 * \param buf_handle - \c [in] Buffer handle.
768 * \param timeout_ns - Timeout in nanoseconds.
769 * \param buffer_busy - 0 if buffer is idle, all GPU access was completed
770 * and no GPU access is scheduled.
771 * 1 GPU access is in fly or scheduled
773 * \return 0 - on success
774 * <0 - AMD specific error code
776 int amdgpu_bo_wait_for_idle(amdgpu_bo_handle buf_handle,
781 * Creates a BO list handle for command submission.
783 * \param dev - \c [in] Device handle.
784 * See #amdgpu_device_initialize()
785 * \param number_of_resources - \c [in] Number of BOs in the list
786 * \param resources - \c [in] List of BO handles
787 * \param resource_prios - \c [in] Optional priority for each handle
788 * \param result - \c [out] Created BO list handle
790 * \return 0 on success\n
791 * >0 - AMD specific error code\n
792 * <0 - Negative POSIX Error code
794 * \sa amdgpu_bo_list_destroy()
796 int amdgpu_bo_list_create(amdgpu_device_handle dev,
797 uint32_t number_of_resources,
798 amdgpu_bo_handle *resources,
799 uint8_t *resource_prios,
800 amdgpu_bo_list_handle *result);
803 * Destroys a BO list handle.
805 * \param handle - \c [in] BO list handle.
807 * \return 0 on success\n
808 * >0 - AMD specific error code\n
809 * <0 - Negative POSIX Error code
811 * \sa amdgpu_bo_list_create()
813 int amdgpu_bo_list_destroy(amdgpu_bo_list_handle handle);
816 * Special GPU Resources
823 * Query information about GDS
825 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
826 * \param gds_info - \c [out] Pointer to structure to get GDS information
828 * \return 0 on success\n
829 * >0 - AMD specific error code\n
830 * <0 - Negative POSIX Error code
833 int amdgpu_gpu_resource_query_gds_info(amdgpu_device_handle dev,
834 struct amdgpu_gds_resource_info *
839 * Allocate GDS partitions
841 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
842 * \param gds_size - \c [in] Size of gds allocation. Must be aligned
844 * \param alloc_info - \c [out] Pointer to structure to receive information
847 * \return 0 on success\n
848 * >0 - AMD specific error code\n
849 * <0 - Negative POSIX Error code
853 int amdgpu_gpu_resource_gds_alloc(amdgpu_device_handle dev,
855 struct amdgpu_gds_alloc_info *alloc_info);
861 * Release GDS resource. When GDS and associated resources not needed any
862 * more UMD should free them
864 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
865 * \param handle - \c [in] Handle assigned to GDS allocation
867 * \return 0 on success\n
868 * >0 - AMD specific error code\n
869 * <0 - Negative POSIX Error code
872 int amdgpu_gpu_resource_gds_free(amdgpu_bo_handle handle);
877 * GPU Execution context
882 * Create GPU execution Context
884 * For the purpose of GPU Scheduler and GPU Robustness extensions it is
885 * necessary to have information/identify rendering/compute contexts.
886 * It also may be needed to associate some specific requirements with such
887 * contexts. Kernel driver will guarantee that submission from the same
888 * context will always be executed in order (first come, first serve).
891 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
892 * \param context - \c [out] GPU Context handle
894 * \return 0 on success\n
895 * >0 - AMD specific error code\n
896 * <0 - Negative POSIX Error code
898 * \sa amdgpu_cs_ctx_free()
901 int amdgpu_cs_ctx_create(amdgpu_device_handle dev,
902 amdgpu_context_handle *context);
906 * Destroy GPU execution context when not needed any more
908 * \param context - \c [in] GPU Context handle
910 * \return 0 on success\n
911 * >0 - AMD specific error code\n
912 * <0 - Negative POSIX Error code
914 * \sa amdgpu_cs_ctx_create()
917 int amdgpu_cs_ctx_free(amdgpu_context_handle context);
920 * Query reset state for the specific GPU Context
922 * \param context - \c [in] GPU Context handle
923 * \param state - \c [out] Reset state status
925 * \return 0 on success\n
926 * >0 - AMD specific error code\n
927 * <0 - Negative POSIX Error code
929 * \sa amdgpu_cs_ctx_create()
932 int amdgpu_cs_query_reset_state(amdgpu_context_handle context,
933 enum amdgpu_cs_ctx_reset_state *state);
937 * Command Buffers Management
943 * Allocate memory to be filled with PM4 packets and be served as the first
944 * entry point of execution (a.k.a. Indirect Buffer)
946 * \param context - \c [in] GPU Context which will use IB
947 * \param ib_size - \c [in] Size of allocation
948 * \param output - \c [out] Pointer to structure to get information about
951 * \return 0 on success\n
952 * >0 - AMD specific error code\n
953 * <0 - Negative POSIX Error code
955 * \sa amdgpu_cs_free_ib()
958 int amdgpu_cs_alloc_ib(amdgpu_context_handle context,
959 enum amdgpu_cs_ib_size ib_size,
960 struct amdgpu_cs_ib_alloc_result *output);
963 * If UMD has allocates IBs which doesn’t need any more than those IBs must
964 * be explicitly freed
966 * \param handle - \c [in] IB handle
968 * \return 0 on success\n
969 * >0 - AMD specific error code\n
970 * <0 - Negative POSIX Error code
972 * \note Libdrm_amdgpu will guarantee that it will correctly detect when it
973 * is safe to return IB to free pool
975 * \sa amdgpu_cs_alloc_ib()
978 int amdgpu_cs_free_ib(amdgpu_ib_handle handle);
981 * Send request to submit command buffers to hardware.
983 * Kernel driver could use GPU Scheduler to make decision when physically
984 * sent this request to the hardware. Accordingly this request could be put
985 * in queue and sent for execution later. The only guarantee is that request
986 * from the same GPU context to the same ip:ip_instance:ring will be executed in
990 * \param dev - \c [in] Device handle.
991 * See #amdgpu_device_initialize()
992 * \param context - \c [in] GPU Context
993 * \param flags - \c [in] Global submission flags
994 * \param ibs_request - \c [in] Pointer to submission requests.
995 * We could submit to the several
996 * engines/rings simulteniously as
998 * \param number_of_requests - \c [in] Number of submission requests
999 * \param fences - \c [out] Pointer to array of data to get
1000 * fences to identify submission
1001 * requests. Timestamps are valid
1002 * in this GPU context and could be used
1003 * to identify/detect completion of
1004 * submission request
1006 * \return 0 on success\n
1007 * >0 - AMD specific error code\n
1008 * <0 - Negative POSIX Error code
1010 * \note It is assumed that by default IB will be returned to free pool
1011 * automatically by libdrm_amdgpu when submission will completed.
1012 * It is possible for UMD to make decision to re-use the same IB in
1013 * this case it should be explicitly freed.\n
1014 * Accordingly, by default, after submission UMD should not touch passed
1015 * IBs. If UMD needs to re-use IB then the special flag AMDGPU_CS_REUSE_IB
1018 * \note It is required to pass correct resource list with buffer handles
1019 * which will be accessible by command buffers from submission
1020 * This will allow kernel driver to correctly implement "paging".
1021 * Failure to do so will have unpredictable results.
1023 * \sa amdgpu_command_buffer_alloc(), amdgpu_command_buffer_free(),
1024 * amdgpu_cs_query_fence_status()
1027 int amdgpu_cs_submit(amdgpu_context_handle context,
1029 struct amdgpu_cs_request *ibs_request,
1030 uint32_t number_of_requests,
1034 * Query status of Command Buffer Submission
1036 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1037 * \param fence - \c [in] Structure describing fence to query
1038 * \param expired - \c [out] If fence expired or not.\n
1039 * 0 – if fence is not expired\n
1042 * \return 0 on success\n
1043 * >0 - AMD specific error code\n
1044 * <0 - Negative POSIX Error code
1046 * \note If UMD wants only to check operation status and returned immediately
1047 * then timeout value as 0 must be passed. In this case success will be
1048 * returned in the case if submission was completed or timeout error
1051 * \sa amdgpu_cs_submit()
1053 int amdgpu_cs_query_fence_status(struct amdgpu_cs_query_fence *fence,
1064 * Query allocation size alignments
1066 * UMD should query information about GPU VM MC size alignments requirements
1067 * to be able correctly choose required allocation size and implement
1068 * internal optimization if needed.
1070 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1071 * \param info - \c [out] Pointer to structure to get size alignment
1074 * \return 0 on success\n
1075 * >0 - AMD specific error code\n
1076 * <0 - Negative POSIX Error code
1079 int amdgpu_query_buffer_size_alignment(amdgpu_device_handle dev,
1080 struct amdgpu_buffer_size_alignments
1086 * Query firmware versions
1088 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1089 * \param fw_type - \c [in] AMDGPU_INFO_FW_*
1090 * \param ip_instance - \c [in] Index of the IP block of the same type.
1091 * \param index - \c [in] Index of the engine. (for SDMA and MEC)
1092 * \param version - \c [out] Pointer to to the "version" return value
1093 * \param feature - \c [out] Pointer to to the "feature" return value
1095 * \return 0 on success\n
1096 * >0 - AMD specific error code\n
1097 * <0 - Negative POSIX Error code
1100 int amdgpu_query_firmware_version(amdgpu_device_handle dev, unsigned fw_type,
1101 unsigned ip_instance, unsigned index,
1102 uint32_t *version, uint32_t *feature);
1107 * Query the number of HW IP instances of a certain type.
1109 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1110 * \param type - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
1111 * \param count - \c [out] Pointer to structure to get information
1113 * \return 0 on success\n
1114 * >0 - AMD specific error code\n
1115 * <0 - Negative POSIX Error code
1117 int amdgpu_query_hw_ip_count(amdgpu_device_handle dev, unsigned type,
1123 * Query engine information
1125 * This query allows UMD to query information different engines and their
1128 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1129 * \param type - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
1130 * \param ip_instance - \c [in] Index of the IP block of the same type.
1131 * \param info - \c [out] Pointer to structure to get information
1133 * \return 0 on success\n
1134 * >0 - AMD specific error code\n
1135 * <0 - Negative POSIX Error code
1137 int amdgpu_query_hw_ip_info(amdgpu_device_handle dev, unsigned type,
1138 unsigned ip_instance,
1139 struct drm_amdgpu_info_hw_ip *info);
1145 * Query heap information
1147 * This query allows UMD to query potentially available memory resources and
1148 * adjust their logic if necessary.
1150 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1151 * \param heap - \c [in] Heap type
1152 * \param info - \c [in] Pointer to structure to get needed information
1154 * \return 0 on success\n
1155 * >0 - AMD specific error code\n
1156 * <0 - Negative POSIX Error code
1159 int amdgpu_query_heap_info(amdgpu_device_handle dev,
1162 struct amdgpu_heap_info *info);
1167 * Get the CRTC ID from the mode object ID
1169 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1170 * \param id - \c [in] Mode object ID
1171 * \param result - \c [in] Pointer to the CRTC ID
1173 * \return 0 on success\n
1174 * >0 - AMD specific error code\n
1175 * <0 - Negative POSIX Error code
1178 int amdgpu_query_crtc_from_id(amdgpu_device_handle dev, unsigned id,
1184 * Query GPU H/w Info
1186 * Query hardware specific information
1188 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1189 * \param heap - \c [in] Heap type
1190 * \param info - \c [in] Pointer to structure to get needed information
1192 * \return 0 on success\n
1193 * >0 - AMD specific error code\n
1194 * <0 - Negative POSIX Error code
1197 int amdgpu_query_gpu_info(amdgpu_device_handle dev,
1198 struct amdgpu_gpu_info *info);
1203 * Query hardware or driver information.
1205 * The return size is query-specific and depends on the "info_id" parameter.
1206 * No more than "size" bytes is returned.
1208 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1209 * \param info_id - \c [in] AMDGPU_INFO_*
1210 * \param size - \c [in] Size of the returned value.
1211 * \param value - \c [out] Pointer to the return value.
1213 * \return 0 on success\n
1214 * >0 - AMD specific error code\n
1215 * <0 - Negative POSIX error code
1218 int amdgpu_query_info(amdgpu_device_handle dev, unsigned info_id,
1219 unsigned size, void *value);
1224 * Read a set of consecutive memory-mapped registers.
1225 * Not all registers are allowed to be read by userspace.
1227 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize(
1228 * \param dword_offset - \c [in] Register offset in dwords
1229 * \param count - \c [in] The number of registers to read starting
1231 * \param instance - \c [in] GRBM_GFX_INDEX selector. It may have other
1232 * uses. Set it to 0xffffffff if unsure.
1233 * \param flags - \c [in] Flags with additional information.
1234 * \param values - \c [out] The pointer to return values.
1236 * \return 0 on success\n
1237 * >0 - AMD specific error code\n
1238 * <0 - Negative POSIX error code
1241 int amdgpu_read_mm_registers(amdgpu_device_handle dev, unsigned dword_offset,
1242 unsigned count, uint32_t instance, uint32_t flags,
1248 * Request GPU access to user allocated memory e.g. via "malloc"
1250 * \param dev - [in] Device handle. See #amdgpu_device_initialize()
1251 * \param cpu - [in] CPU address of user allocated memory which we
1252 * want to map to GPU address space (make GPU accessible)
1253 * (This address must be correctly aligned).
1254 * \param size - [in] Size of allocation (must be correctly aligned)
1255 * \param amdgpu_bo_alloc_result - [out] Handle of allocation to be passed as resource
1256 * on submission and be used in other operations.(e.g. for VA submission)
1257 * ( Temporally defined amdgpu_bo_alloc_result as parameter for return mc address. )
1260 * \return 0 on success
1261 * >0 - AMD specific error code
1262 * <0 - Negative POSIX Error code
1266 * This call doesn't guarantee that such memory will be persistently
1267 * "locked" / make non-pageable. The purpose of this call is to provide
1268 * opportunity for GPU get access to this resource during submission.
1270 * The maximum amount of memory which could be mapped in this call depends
1271 * if overcommit is disabled or not. If overcommit is disabled than the max.
1272 * amount of memory to be pinned will be limited by left "free" size in total
1273 * amount of memory which could be locked simultaneously ("GART" size).
1275 * Supported (theoretical) max. size of mapping is restricted only by
1278 * It is responsibility of caller to correctly specify access rights
1281 int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev,
1284 struct amdgpu_bo_alloc_result *info);
1287 #endif /* #ifdef _AMDGPU_H_ */