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
68 /*--------------------------------------------------------------------------*/
69 /* ----------------------------- Enums ------------------------------------ */
70 /*--------------------------------------------------------------------------*/
73 * Enum describing possible handle types
75 * \sa amdgpu_bo_import, amdgpu_bo_export
78 enum amdgpu_bo_handle_type {
79 /** GEM flink name (needs DRM authentication, used by DRI2) */
80 amdgpu_bo_handle_type_gem_flink_name = 0,
82 /** KMS handle which is used by all driver ioctls */
83 amdgpu_bo_handle_type_kms = 1,
85 /** DMA-buf fd handle */
86 amdgpu_bo_handle_type_dma_buf_fd = 2
90 * For performance reasons and to simplify logic libdrm_amdgpu will handle
91 * IBs only some pre-defined sizes.
93 * \sa amdgpu_cs_alloc_ib()
95 enum amdgpu_cs_ib_size {
96 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
103 /** The number of different IB sizes */
104 #define AMDGPU_CS_IB_SIZE_NUM 5
107 /*--------------------------------------------------------------------------*/
108 /* -------------------------- Datatypes ----------------------------------- */
109 /*--------------------------------------------------------------------------*/
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
117 typedef struct amdgpu_device *amdgpu_device_handle;
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)
124 typedef struct amdgpu_context *amdgpu_context_handle;
127 * Define handle for amdgpu resources: buffer, GDS, etc.
129 typedef struct amdgpu_bo *amdgpu_bo_handle;
132 * Define handle for list of BOs
134 typedef struct amdgpu_bo_list *amdgpu_bo_list_handle;
137 * Define handle to be used when dealing with command
138 * buffers (a.k.a. ibs)
141 typedef struct amdgpu_ib *amdgpu_ib_handle;
144 /*--------------------------------------------------------------------------*/
145 /* -------------------------- Structures ---------------------------------- */
146 /*--------------------------------------------------------------------------*/
149 * Structure describing memory allocation request
151 * \sa amdgpu_bo_alloc()
154 struct amdgpu_bo_alloc_request {
155 /** Allocation request. It must be aligned correctly. */
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
163 uint64_t phys_alignment;
166 * UMD should specify where to allocate memory and how it
167 * will be accessed by the CPU.
169 uint32_t preferred_heap;
171 /** Additional flags passed on allocation */
176 * Structure describing memory allocation request
178 * \sa amdgpu_bo_alloc()
180 struct amdgpu_bo_alloc_result {
181 /** Assigned virtual MC Base Address */
182 uint64_t virtual_mc_base_address;
184 /** Handle of allocated memory to be used by the given process only. */
185 amdgpu_bo_handle buf_handle;
189 * Special UMD specific information associated with buffer.
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.
195 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info,
196 * amdgpu_bo_import(), amdgpu_bo_export
199 struct amdgpu_bo_metadata {
200 /** Special flag associated with surface */
204 * ASIC-specific tiling information (also used by DCE).
205 * The encoding is defined by the AMDGPU_TILING_* definitions.
207 uint64_t tiling_info;
209 /** Size of metadata associated with the buffer, in bytes. */
210 uint32_t size_metadata;
212 /** UMD specific metadata. Opaque for kernel */
213 uint32_t umd_metadata[64];
217 * Structure describing allocated buffer. Client may need
218 * to query such information as part of 'sharing' buffers mechanism
220 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info(),
221 * amdgpu_bo_import(), amdgpu_bo_export()
223 struct amdgpu_bo_info {
224 /** Allocated memory size */
228 * It may be required to have some specific alignment requirements
229 * for physical back-up storage.
231 uint64_t phys_alignment;
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.
238 uint64_t virtual_mc_base_address;
240 /** Heap where to allocate memory. */
241 uint32_t preferred_heap;
243 /** Additional allocation flags. */
244 uint64_t alloc_flags;
246 /** Metadata associated with buffer if any. */
247 struct amdgpu_bo_metadata metadata;
251 * Structure with information about "imported" buffer
253 * \sa amdgpu_bo_import()
256 struct amdgpu_bo_import_result {
257 /** Handle of memory/buffer to use */
258 amdgpu_bo_handle buf_handle;
263 /** Assigned virtual MC Base Address */
264 uint64_t virtual_mc_base_address;
270 * Structure to describe GDS partitioning information.
271 * \note OA and GWS resources are asscoiated with GDS partition
273 * \sa amdgpu_gpu_resource_query_gds_info
276 struct 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;
289 * Structure describing result of request to allocate GDS
291 * \sa amdgpu_gpu_resource_gds_alloc
294 struct amdgpu_gds_alloc_info {
295 /** Handle assigned to gds allocation */
296 amdgpu_bo_handle resource_handle;
298 /** How much was really allocated */
299 uint32_t gds_memory_size;
301 /** Number of GWS resources allocated */
304 /** Number of OA resources allocated */
309 * Structure to described allocated command buffer (a.k.a. IB)
311 * \sa amdgpu_cs_alloc_ib()
314 struct amdgpu_cs_ib_alloc_result {
315 /** IB allocation handle */
316 amdgpu_ib_handle handle;
318 /** Assigned GPU VM MC Address of command buffer */
321 /** Address to be used for CPU access */
326 * Structure describing IB
328 * \sa amdgpu_cs_request, amdgpu_cs_submit()
331 struct amdgpu_cs_ib_info {
335 /** Handle of command buffer */
336 amdgpu_ib_handle ib_handle;
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
346 /** Offset in the IB buffer object (in unit of dwords) */
351 * Structure describing submission request
353 * \note We could have several IBs as packet. e.g. CE, CE, DE case for gfx
355 * \sa amdgpu_cs_submit()
357 struct amdgpu_cs_request {
358 /** Specify flags with additional information */
361 /** Specify HW IP block type to which to send the IB. */
364 /** IP instance index if there are several IPs of the same type. */
365 unsigned ip_instance;
368 * Specify ring index of the IP. We could have several rings
369 * in the same IP. E.g. 0 for SDMA0 and 1 for SDMA1.
374 * List handle with resources used by this request.
376 amdgpu_bo_list_handle resources;
378 /** Number of IBs to submit in the field ibs. */
379 uint32_t number_of_ibs;
382 * IBs to submit. Those IBs will be submit together as single entity
384 struct amdgpu_cs_ib_info *ibs;
388 * Structure describing request to check submission state using fence
390 * \sa amdgpu_cs_query_fence_status()
393 struct amdgpu_cs_query_fence {
395 /** In which context IB was sent to execution */
396 amdgpu_context_handle context;
398 /** Timeout in nanoseconds. */
401 /** To which HW IP type the fence belongs */
404 /** IP instance index if there are several IPs of the same type. */
405 unsigned ip_instance;
407 /** Ring index of the HW IP */
413 /** Specify fence for which we need to check
414 * submission status.*/
419 * Structure which provide information about GPU VM MC Address space
420 * alignments requirements
422 * \sa amdgpu_query_buffer_size_alignment
424 struct amdgpu_buffer_size_alignments {
425 /** Size alignment requirement for allocation in
430 * Size alignment requirement for allocation in remote memory
432 uint64_t size_remote;
437 * Structure which provide information about heap
439 * \sa amdgpu_query_heap_info()
442 struct amdgpu_heap_info {
443 /** Theoretical max. available memory in the given heap */
447 * Number of bytes allocated in the heap. This includes all processes
448 * and private allocations in the kernel. It changes when new buffers
449 * are allocated, freed, and moved. It cannot be larger than
455 * Theoretical possible max. size of buffer which
456 * could be allocated in the given heap
458 uint64_t max_allocation;
464 * Describe GPU h/w info needed for UMD correct initialization
466 * \sa amdgpu_query_gpu_info()
468 struct amdgpu_gpu_info {
471 /**< Chip revision */
473 /** Chip external revision */
474 uint32_t chip_external_rev;
479 /** max engine clock*/
480 uint64_t max_engine_clk;
481 /** max memory clock */
482 uint64_t max_memory_clk;
483 /** number of shader engines */
484 uint32_t num_shader_engines;
485 /** number of shader arrays per engine */
486 uint32_t num_shader_arrays_per_engine;
487 /** Number of available good shader pipes */
488 uint32_t avail_quad_shader_pipes;
489 /** Max. number of shader pipes.(including good and bad pipes */
490 uint32_t max_quad_shader_pipes;
491 /** Number of parameter cache entries per shader quad pipe */
492 uint32_t cache_entries_per_quad_pipe;
493 /** Number of available graphics context */
494 uint32_t num_hw_gfx_contexts;
495 /** Number of render backend pipes */
497 /** Enabled render backend pipe mask */
498 uint32_t enabled_rb_pipes_mask;
499 /** Frequency of GPU Counter */
500 uint32_t gpu_counter_freq;
501 /** CC_RB_BACKEND_DISABLE.BACKEND_DISABLE per SE */
502 uint32_t backend_disable[4];
503 /** Value of MC_ARB_RAMCFG register*/
504 uint32_t mc_arb_ramcfg;
505 /** Value of GB_ADDR_CONFIG */
506 uint32_t gb_addr_cfg;
507 /** Values of the GB_TILE_MODE0..31 registers */
508 uint32_t gb_tile_mode[32];
509 /** Values of GB_MACROTILE_MODE0..15 registers */
510 uint32_t gb_macro_tile_mode[16];
511 /** Value of PA_SC_RASTER_CONFIG register per SE */
512 uint32_t pa_sc_raster_cfg[4];
513 /** Value of PA_SC_RASTER_CONFIG_1 register per SE */
514 uint32_t pa_sc_raster_cfg1[4];
516 uint32_t cu_active_number;
518 uint32_t cu_bitmap[4][4];
519 /* video memory type info*/
521 /* video memory bit width*/
522 uint32_t vram_bit_width;
526 /*--------------------------------------------------------------------------*/
527 /*------------------------- Functions --------------------------------------*/
528 /*--------------------------------------------------------------------------*/
531 * Initialization / Cleanup
538 * \param fd - \c [in] File descriptor for AMD GPU device
539 * received previously as the result of
540 * e.g. drmOpen() call.
541 * For legacy fd type, the DRI2/DRI3 authentication
542 * should be done before calling this function.
543 * \param major_version - \c [out] Major version of library. It is assumed
544 * that adding new functionality will cause
545 * increase in major version
546 * \param minor_version - \c [out] Minor version of library
547 * \param device_handle - \c [out] Pointer to opaque context which should
548 * be passed as the first parameter on each
552 * \return 0 on success\n
553 * >0 - AMD specific error code\n
554 * <0 - Negative POSIX Error code
557 * \sa amdgpu_device_deinitialize()
559 int amdgpu_device_initialize(int fd,
560 uint32_t *major_version,
561 uint32_t *minor_version,
562 amdgpu_device_handle *device_handle);
568 * When access to such library does not needed any more the special
569 * function must be call giving opportunity to clean up any
570 * resources if needed.
572 * \param device_handle - \c [in] Context associated with file
573 * descriptor for AMD GPU device
574 * received previously as the
575 * result e.g. of drmOpen() call.
577 * \return 0 on success\n
578 * >0 - AMD specific error code\n
579 * <0 - Negative POSIX Error code
581 * \sa amdgpu_device_initialize()
584 int amdgpu_device_deinitialize(amdgpu_device_handle device_handle);
593 * Allocate memory to be used by UMD for GPU related operations
595 * \param dev - \c [in] Device handle.
596 * See #amdgpu_device_initialize()
597 * \param alloc_buffer - \c [in] Pointer to the structure describing an
599 * \param info - \c [out] Pointer to structure which return
600 * information about allocated memory
602 * \return 0 on success\n
603 * >0 - AMD specific error code\n
604 * <0 - Negative POSIX Error code
606 * \sa amdgpu_bo_free()
608 int amdgpu_bo_alloc(amdgpu_device_handle dev,
609 struct amdgpu_bo_alloc_request *alloc_buffer,
610 struct amdgpu_bo_alloc_result *info);
613 * Associate opaque data with buffer to be queried by another UMD
615 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
616 * \param buf_handle - \c [in] Buffer handle
617 * \param info - \c [in] Metadata to associated with buffer
619 * \return 0 on success\n
620 * >0 - AMD specific error code\n
621 * <0 - Negative POSIX Error code
623 int amdgpu_bo_set_metadata(amdgpu_bo_handle buf_handle,
624 struct amdgpu_bo_metadata *info);
627 * Query buffer information including metadata previusly associated with
630 * \param dev - \c [in] Device handle.
631 * See #amdgpu_device_initialize()
632 * \param buf_handle - \c [in] Buffer handle
633 * \param info - \c [out] Structure describing buffer
635 * \return 0 on success\n
636 * >0 - AMD specific error code\n
637 * <0 - Negative POSIX Error code
639 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc()
641 int amdgpu_bo_query_info(amdgpu_bo_handle buf_handle,
642 struct amdgpu_bo_info *info);
645 * Allow others to get access to buffer
647 * \param dev - \c [in] Device handle.
648 * See #amdgpu_device_initialize()
649 * \param buf_handle - \c [in] Buffer handle
650 * \param type - \c [in] Type of handle requested
651 * \param shared_handle - \c [out] Special "shared" handle
653 * \return 0 on success\n
654 * >0 - AMD specific error code\n
655 * <0 - Negative POSIX Error code
657 * \sa amdgpu_bo_import()
660 int amdgpu_bo_export(amdgpu_bo_handle buf_handle,
661 enum amdgpu_bo_handle_type type,
662 uint32_t *shared_handle);
665 * Request access to "shared" buffer
667 * \param dev - \c [in] Device handle.
668 * See #amdgpu_device_initialize()
669 * \param type - \c [in] Type of handle requested
670 * \param shared_handle - \c [in] Shared handle received as result "import"
672 * \param output - \c [out] Pointer to structure with information
673 * about imported buffer
675 * \return 0 on success\n
676 * >0 - AMD specific error code\n
677 * <0 - Negative POSIX Error code
679 * \note Buffer must be "imported" only using new "fd" (different from
680 * one used by "exporter").
682 * \sa amdgpu_bo_export()
685 int amdgpu_bo_import(amdgpu_device_handle dev,
686 enum amdgpu_bo_handle_type type,
687 uint32_t shared_handle,
688 struct amdgpu_bo_import_result *output);
691 * Free previosuly allocated memory
693 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
694 * \param buf_handle - \c [in] Buffer handle to free
696 * \return 0 on success\n
697 * >0 - AMD specific error code\n
698 * <0 - Negative POSIX Error code
700 * \note In the case of memory shared between different applications all
701 * resources will be “physically” freed only all such applications
703 * \note If is UMD responsibility to ‘free’ buffer only when there is no
706 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc()
709 int amdgpu_bo_free(amdgpu_bo_handle buf_handle);
712 * Request CPU access to GPU accessable memory
714 * \param buf_handle - \c [in] Buffer handle
715 * \param cpu - \c [out] CPU address to be used for access
717 * \return 0 on success\n
718 * >0 - AMD specific error code\n
719 * <0 - Negative POSIX Error code
721 * \sa amdgpu_bo_cpu_unmap()
724 int amdgpu_bo_cpu_map(amdgpu_bo_handle buf_handle, void **cpu);
727 * Release CPU access to GPU memory
729 * \param buf_handle - \c [in] Buffer handle
731 * \return 0 on success\n
732 * >0 - AMD specific error code\n
733 * <0 - Negative POSIX Error code
735 * \sa amdgpu_bo_cpu_map()
738 int amdgpu_bo_cpu_unmap(amdgpu_bo_handle buf_handle);
742 * Wait until a buffer is not used by the device.
744 * \param dev - \c [in] Device handle. See #amdgpu_lib_initialize()
745 * \param buf_handle - \c [in] Buffer handle.
746 * \param timeout_ns - Timeout in nanoseconds.
747 * \param buffer_busy - 0 if buffer is idle, all GPU access was completed
748 * and no GPU access is scheduled.
749 * 1 GPU access is in fly or scheduled
751 * \return 0 - on success
752 * <0 - AMD specific error code
754 int amdgpu_bo_wait_for_idle(amdgpu_bo_handle buf_handle,
759 * Creates a BO list handle for command submission.
761 * \param dev - \c [in] Device handle.
762 * See #amdgpu_device_initialize()
763 * \param number_of_resources - \c [in] Number of BOs in the list
764 * \param resources - \c [in] List of BO handles
765 * \param resource_prios - \c [in] Optional priority for each handle
766 * \param result - \c [out] Created BO list handle
768 * \return 0 on success\n
769 * >0 - AMD specific error code\n
770 * <0 - Negative POSIX Error code
772 * \sa amdgpu_bo_list_destroy()
774 int amdgpu_bo_list_create(amdgpu_device_handle dev,
775 uint32_t number_of_resources,
776 amdgpu_bo_handle *resources,
777 uint8_t *resource_prios,
778 amdgpu_bo_list_handle *result);
781 * Destroys a BO list handle.
783 * \param handle - \c [in] BO list handle.
785 * \return 0 on success\n
786 * >0 - AMD specific error code\n
787 * <0 - Negative POSIX Error code
789 * \sa amdgpu_bo_list_create()
791 int amdgpu_bo_list_destroy(amdgpu_bo_list_handle handle);
794 * Update resources for existing BO list
796 * \param handle - \c [in] BO list handle
797 * \param number_of_resources - \c [in] Number of BOs in the list
798 * \param resources - \c [in] List of BO handles
799 * \param resource_prios - \c [in] Optional priority for each handle
801 * \return 0 on success\n
802 * >0 - AMD specific error code\n
803 * <0 - Negative POSIX Error code
805 * \sa amdgpu_bo_list_update()
807 int amdgpu_bo_list_update(amdgpu_bo_list_handle handle,
808 uint32_t number_of_resources,
809 amdgpu_bo_handle *resources,
810 uint8_t *resource_prios);
813 * Special GPU Resources
820 * Query information about GDS
822 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
823 * \param gds_info - \c [out] Pointer to structure to get GDS information
825 * \return 0 on success\n
826 * >0 - AMD specific error code\n
827 * <0 - Negative POSIX Error code
830 int amdgpu_gpu_resource_query_gds_info(amdgpu_device_handle dev,
831 struct amdgpu_gds_resource_info *
836 * Allocate GDS partitions
838 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
839 * \param gds_size - \c [in] Size of gds allocation. Must be aligned
841 * \param alloc_info - \c [out] Pointer to structure to receive information
844 * \return 0 on success\n
845 * >0 - AMD specific error code\n
846 * <0 - Negative POSIX Error code
850 int amdgpu_gpu_resource_gds_alloc(amdgpu_device_handle dev,
852 struct amdgpu_gds_alloc_info *alloc_info);
858 * Release GDS resource. When GDS and associated resources not needed any
859 * more UMD should free them
861 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
862 * \param handle - \c [in] Handle assigned to GDS allocation
864 * \return 0 on success\n
865 * >0 - AMD specific error code\n
866 * <0 - Negative POSIX Error code
869 int amdgpu_gpu_resource_gds_free(amdgpu_bo_handle handle);
874 * GPU Execution context
879 * Create GPU execution Context
881 * For the purpose of GPU Scheduler and GPU Robustness extensions it is
882 * necessary to have information/identify rendering/compute contexts.
883 * It also may be needed to associate some specific requirements with such
884 * contexts. Kernel driver will guarantee that submission from the same
885 * context will always be executed in order (first come, first serve).
888 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
889 * \param context - \c [out] GPU Context handle
891 * \return 0 on success\n
892 * >0 - AMD specific error code\n
893 * <0 - Negative POSIX Error code
895 * \sa amdgpu_cs_ctx_free()
898 int amdgpu_cs_ctx_create(amdgpu_device_handle dev,
899 amdgpu_context_handle *context);
903 * Destroy GPU execution context when not needed any more
905 * \param context - \c [in] GPU Context handle
907 * \return 0 on success\n
908 * >0 - AMD specific error code\n
909 * <0 - Negative POSIX Error code
911 * \sa amdgpu_cs_ctx_create()
914 int amdgpu_cs_ctx_free(amdgpu_context_handle context);
917 * Query reset state for the specific GPU Context
919 * \param context - \c [in] GPU Context handle
920 * \param state - \c [out] One of AMDGPU_CTX_*_RESET
921 * \param hangs - \c [out] Number of hangs caused by the context.
923 * \return 0 on success\n
924 * >0 - AMD specific error code\n
925 * <0 - Negative POSIX Error code
927 * \sa amdgpu_cs_ctx_create()
930 int amdgpu_cs_query_reset_state(amdgpu_context_handle context,
931 uint32_t *state, uint32_t *hangs);
935 * Command Buffers Management
941 * Allocate memory to be filled with PM4 packets and be served as the first
942 * entry point of execution (a.k.a. Indirect Buffer)
944 * \param context - \c [in] GPU Context which will use IB
945 * \param ib_size - \c [in] Size of allocation
946 * \param output - \c [out] Pointer to structure to get information about
949 * \return 0 on success\n
950 * >0 - AMD specific error code\n
951 * <0 - Negative POSIX Error code
953 * \sa amdgpu_cs_free_ib()
956 int amdgpu_cs_alloc_ib(amdgpu_context_handle context,
957 enum amdgpu_cs_ib_size ib_size,
958 struct amdgpu_cs_ib_alloc_result *output);
961 * If UMD has allocates IBs which doesn’t need any more than those IBs must
962 * be explicitly freed
964 * \param handle - \c [in] IB handle
966 * \return 0 on success\n
967 * >0 - AMD specific error code\n
968 * <0 - Negative POSIX Error code
970 * \note Libdrm_amdgpu will guarantee that it will correctly detect when it
971 * is safe to return IB to free pool
973 * \sa amdgpu_cs_alloc_ib()
976 int amdgpu_cs_free_ib(amdgpu_ib_handle handle);
979 * Send request to submit command buffers to hardware.
981 * Kernel driver could use GPU Scheduler to make decision when physically
982 * sent this request to the hardware. Accordingly this request could be put
983 * in queue and sent for execution later. The only guarantee is that request
984 * from the same GPU context to the same ip:ip_instance:ring will be executed in
988 * \param dev - \c [in] Device handle.
989 * See #amdgpu_device_initialize()
990 * \param context - \c [in] GPU Context
991 * \param flags - \c [in] Global submission flags
992 * \param ibs_request - \c [in] Pointer to submission requests.
993 * We could submit to the several
994 * engines/rings simulteniously as
996 * \param number_of_requests - \c [in] Number of submission requests
997 * \param fences - \c [out] Pointer to array of data to get
998 * fences to identify submission
999 * requests. Timestamps are valid
1000 * in this GPU context and could be used
1001 * to identify/detect completion of
1002 * submission request
1004 * \return 0 on success\n
1005 * >0 - AMD specific error code\n
1006 * <0 - Negative POSIX Error code
1008 * \note It is assumed that by default IB will be returned to free pool
1009 * automatically by libdrm_amdgpu when submission will completed.
1010 * It is possible for UMD to make decision to re-use the same IB in
1011 * this case it should be explicitly freed.\n
1012 * Accordingly, by default, after submission UMD should not touch passed
1013 * IBs. If UMD needs to re-use IB then the special flag AMDGPU_CS_REUSE_IB
1016 * \note It is required to pass correct resource list with buffer handles
1017 * which will be accessible by command buffers from submission
1018 * This will allow kernel driver to correctly implement "paging".
1019 * Failure to do so will have unpredictable results.
1021 * \sa amdgpu_command_buffer_alloc(), amdgpu_command_buffer_free(),
1022 * amdgpu_cs_query_fence_status()
1025 int amdgpu_cs_submit(amdgpu_context_handle context,
1027 struct amdgpu_cs_request *ibs_request,
1028 uint32_t number_of_requests,
1032 * Query status of Command Buffer Submission
1034 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1035 * \param fence - \c [in] Structure describing fence to query
1036 * \param expired - \c [out] If fence expired or not.\n
1037 * 0 – if fence is not expired\n
1040 * \return 0 on success\n
1041 * >0 - AMD specific error code\n
1042 * <0 - Negative POSIX Error code
1044 * \note If UMD wants only to check operation status and returned immediately
1045 * then timeout value as 0 must be passed. In this case success will be
1046 * returned in the case if submission was completed or timeout error
1049 * \sa amdgpu_cs_submit()
1051 int amdgpu_cs_query_fence_status(struct amdgpu_cs_query_fence *fence,
1062 * Query allocation size alignments
1064 * UMD should query information about GPU VM MC size alignments requirements
1065 * to be able correctly choose required allocation size and implement
1066 * internal optimization if needed.
1068 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1069 * \param info - \c [out] Pointer to structure to get size alignment
1072 * \return 0 on success\n
1073 * >0 - AMD specific error code\n
1074 * <0 - Negative POSIX Error code
1077 int amdgpu_query_buffer_size_alignment(amdgpu_device_handle dev,
1078 struct amdgpu_buffer_size_alignments
1084 * Query firmware versions
1086 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1087 * \param fw_type - \c [in] AMDGPU_INFO_FW_*
1088 * \param ip_instance - \c [in] Index of the IP block of the same type.
1089 * \param index - \c [in] Index of the engine. (for SDMA and MEC)
1090 * \param version - \c [out] Pointer to to the "version" return value
1091 * \param feature - \c [out] Pointer to to the "feature" return value
1093 * \return 0 on success\n
1094 * >0 - AMD specific error code\n
1095 * <0 - Negative POSIX Error code
1098 int amdgpu_query_firmware_version(amdgpu_device_handle dev, unsigned fw_type,
1099 unsigned ip_instance, unsigned index,
1100 uint32_t *version, uint32_t *feature);
1105 * Query the number of HW IP instances of a certain type.
1107 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1108 * \param type - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
1109 * \param count - \c [out] Pointer to structure to get information
1111 * \return 0 on success\n
1112 * >0 - AMD specific error code\n
1113 * <0 - Negative POSIX Error code
1115 int amdgpu_query_hw_ip_count(amdgpu_device_handle dev, unsigned type,
1121 * Query engine information
1123 * This query allows UMD to query information different engines and their
1126 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1127 * \param type - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
1128 * \param ip_instance - \c [in] Index of the IP block of the same type.
1129 * \param info - \c [out] Pointer to structure to get information
1131 * \return 0 on success\n
1132 * >0 - AMD specific error code\n
1133 * <0 - Negative POSIX Error code
1135 int amdgpu_query_hw_ip_info(amdgpu_device_handle dev, unsigned type,
1136 unsigned ip_instance,
1137 struct drm_amdgpu_info_hw_ip *info);
1143 * Query heap information
1145 * This query allows UMD to query potentially available memory resources and
1146 * adjust their logic if necessary.
1148 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1149 * \param heap - \c [in] Heap type
1150 * \param info - \c [in] Pointer to structure to get needed information
1152 * \return 0 on success\n
1153 * >0 - AMD specific error code\n
1154 * <0 - Negative POSIX Error code
1157 int amdgpu_query_heap_info(amdgpu_device_handle dev,
1160 struct amdgpu_heap_info *info);
1165 * Get the CRTC ID from the mode object ID
1167 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1168 * \param id - \c [in] Mode object ID
1169 * \param result - \c [in] Pointer to the CRTC ID
1171 * \return 0 on success\n
1172 * >0 - AMD specific error code\n
1173 * <0 - Negative POSIX Error code
1176 int amdgpu_query_crtc_from_id(amdgpu_device_handle dev, unsigned id,
1182 * Query GPU H/w Info
1184 * Query hardware specific information
1186 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1187 * \param heap - \c [in] Heap type
1188 * \param info - \c [in] Pointer to structure to get needed information
1190 * \return 0 on success\n
1191 * >0 - AMD specific error code\n
1192 * <0 - Negative POSIX Error code
1195 int amdgpu_query_gpu_info(amdgpu_device_handle dev,
1196 struct amdgpu_gpu_info *info);
1201 * Query hardware or driver information.
1203 * The return size is query-specific and depends on the "info_id" parameter.
1204 * No more than "size" bytes is returned.
1206 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1207 * \param info_id - \c [in] AMDGPU_INFO_*
1208 * \param size - \c [in] Size of the returned value.
1209 * \param value - \c [out] Pointer to the return value.
1211 * \return 0 on success\n
1212 * >0 - AMD specific error code\n
1213 * <0 - Negative POSIX error code
1216 int amdgpu_query_info(amdgpu_device_handle dev, unsigned info_id,
1217 unsigned size, void *value);
1222 * Read a set of consecutive memory-mapped registers.
1223 * Not all registers are allowed to be read by userspace.
1225 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize(
1226 * \param dword_offset - \c [in] Register offset in dwords
1227 * \param count - \c [in] The number of registers to read starting
1229 * \param instance - \c [in] GRBM_GFX_INDEX selector. It may have other
1230 * uses. Set it to 0xffffffff if unsure.
1231 * \param flags - \c [in] Flags with additional information.
1232 * \param values - \c [out] The pointer to return values.
1234 * \return 0 on success\n
1235 * >0 - AMD specific error code\n
1236 * <0 - Negative POSIX error code
1239 int amdgpu_read_mm_registers(amdgpu_device_handle dev, unsigned dword_offset,
1240 unsigned count, uint32_t instance, uint32_t flags,
1246 * Request GPU access to user allocated memory e.g. via "malloc"
1248 * \param dev - [in] Device handle. See #amdgpu_device_initialize()
1249 * \param cpu - [in] CPU address of user allocated memory which we
1250 * want to map to GPU address space (make GPU accessible)
1251 * (This address must be correctly aligned).
1252 * \param size - [in] Size of allocation (must be correctly aligned)
1253 * \param amdgpu_bo_alloc_result - [out] Handle of allocation to be passed as resource
1254 * on submission and be used in other operations.(e.g. for VA submission)
1255 * ( Temporally defined amdgpu_bo_alloc_result as parameter for return mc address. )
1258 * \return 0 on success
1259 * >0 - AMD specific error code
1260 * <0 - Negative POSIX Error code
1264 * This call doesn't guarantee that such memory will be persistently
1265 * "locked" / make non-pageable. The purpose of this call is to provide
1266 * opportunity for GPU get access to this resource during submission.
1268 * The maximum amount of memory which could be mapped in this call depends
1269 * if overcommit is disabled or not. If overcommit is disabled than the max.
1270 * amount of memory to be pinned will be limited by left "free" size in total
1271 * amount of memory which could be locked simultaneously ("GART" size).
1273 * Supported (theoretical) max. size of mapping is restricted only by
1276 * It is responsibility of caller to correctly specify access rights
1279 int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev,
1282 struct amdgpu_bo_alloc_result *info);
1285 #endif /* #ifdef _AMDGPU_H_ */