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
44 struct drm_amdgpu_info_hw_ip;
46 /*--------------------------------------------------------------------------*/
47 /* --------------------------- Defines ------------------------------------ */
48 /*--------------------------------------------------------------------------*/
51 * Define max. number of Command Buffers (IB) which could be sent to the single
52 * hardware IP to accommodate CE/DE requirements
54 * \sa amdgpu_cs_ib_info
56 #define AMDGPU_CS_MAX_IBS_PER_SUBMIT 4
59 * Special timeout value meaning that the timeout is infinite.
61 #define AMDGPU_TIMEOUT_INFINITE 0xffffffffffffffffull
64 * Used in amdgpu_cs_query_fence_status(), meaning that the given timeout
67 #define AMDGPU_QUERY_FENCE_TIMEOUT_IS_ABSOLUTE (1 << 0)
69 /*--------------------------------------------------------------------------*/
70 /* ----------------------------- Enums ------------------------------------ */
71 /*--------------------------------------------------------------------------*/
74 * Enum describing possible handle types
76 * \sa amdgpu_bo_import, amdgpu_bo_export
79 enum amdgpu_bo_handle_type {
80 /** GEM flink name (needs DRM authentication, used by DRI2) */
81 amdgpu_bo_handle_type_gem_flink_name = 0,
83 /** KMS handle which is used by all driver ioctls */
84 amdgpu_bo_handle_type_kms = 1,
86 /** DMA-buf fd handle */
87 amdgpu_bo_handle_type_dma_buf_fd = 2
90 /** Define known types of GPU VM VA ranges */
91 enum amdgpu_gpu_va_range
93 /** Allocate from "normal"/general range */
94 amdgpu_gpu_va_range_general = 0
97 /*--------------------------------------------------------------------------*/
98 /* -------------------------- Datatypes ----------------------------------- */
99 /*--------------------------------------------------------------------------*/
102 * Define opaque pointer to context associated with fd.
103 * This context will be returned as the result of
104 * "initialize" function and should be pass as the first
105 * parameter to any API call
107 typedef struct amdgpu_device *amdgpu_device_handle;
110 * Define GPU Context type as pointer to opaque structure
111 * Example of GPU Context is the "rendering" context associated
112 * with OpenGL context (glCreateContext)
114 typedef struct amdgpu_context *amdgpu_context_handle;
117 * Define handle for amdgpu resources: buffer, GDS, etc.
119 typedef struct amdgpu_bo *amdgpu_bo_handle;
122 * Define handle for list of BOs
124 typedef struct amdgpu_bo_list *amdgpu_bo_list_handle;
127 * Define handle to be used to work with VA allocated ranges
129 typedef struct amdgpu_va *amdgpu_va_handle;
132 * Define handle for semaphore
134 typedef struct amdgpu_semaphore *amdgpu_semaphore_handle;
136 /*--------------------------------------------------------------------------*/
137 /* -------------------------- Structures ---------------------------------- */
138 /*--------------------------------------------------------------------------*/
141 * Structure describing memory allocation request
143 * \sa amdgpu_bo_alloc()
146 struct amdgpu_bo_alloc_request {
147 /** Allocation request. It must be aligned correctly. */
151 * It may be required to have some specific alignment requirements
152 * for physical back-up storage (e.g. for displayable surface).
153 * If 0 there is no special alignment requirement
155 uint64_t phys_alignment;
158 * UMD should specify where to allocate memory and how it
159 * will be accessed by the CPU.
161 uint32_t preferred_heap;
163 /** Additional flags passed on allocation */
168 * Special UMD specific information associated with buffer.
170 * It may be need to pass some buffer charactersitic as part
171 * of buffer sharing. Such information are defined UMD and
172 * opaque for libdrm_amdgpu as well for kernel driver.
174 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info,
175 * amdgpu_bo_import(), amdgpu_bo_export
178 struct amdgpu_bo_metadata {
179 /** Special flag associated with surface */
183 * ASIC-specific tiling information (also used by DCE).
184 * The encoding is defined by the AMDGPU_TILING_* definitions.
186 uint64_t tiling_info;
188 /** Size of metadata associated with the buffer, in bytes. */
189 uint32_t size_metadata;
191 /** UMD specific metadata. Opaque for kernel */
192 uint32_t umd_metadata[64];
196 * Structure describing allocated buffer. Client may need
197 * to query such information as part of 'sharing' buffers mechanism
199 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info(),
200 * amdgpu_bo_import(), amdgpu_bo_export()
202 struct amdgpu_bo_info {
203 /** Allocated memory size */
207 * It may be required to have some specific alignment requirements
208 * for physical back-up storage.
210 uint64_t phys_alignment;
212 /** Heap where to allocate memory. */
213 uint32_t preferred_heap;
215 /** Additional allocation flags. */
216 uint64_t alloc_flags;
218 /** Metadata associated with buffer if any. */
219 struct amdgpu_bo_metadata metadata;
223 * Structure with information about "imported" buffer
225 * \sa amdgpu_bo_import()
228 struct amdgpu_bo_import_result {
229 /** Handle of memory/buffer to use */
230 amdgpu_bo_handle buf_handle;
238 * Structure to describe GDS partitioning information.
239 * \note OA and GWS resources are asscoiated with GDS partition
241 * \sa amdgpu_gpu_resource_query_gds_info
244 struct amdgpu_gds_resource_info {
245 uint32_t gds_gfx_partition_size;
246 uint32_t compute_partition_size;
247 uint32_t gds_total_size;
248 uint32_t gws_per_gfx_partition;
249 uint32_t gws_per_compute_partition;
250 uint32_t oa_per_gfx_partition;
251 uint32_t oa_per_compute_partition;
255 * Structure describing CS fence
257 * \sa amdgpu_cs_query_fence_status(), amdgpu_cs_request, amdgpu_cs_submit()
260 struct amdgpu_cs_fence {
262 /** In which context IB was sent to execution */
263 amdgpu_context_handle context;
265 /** To which HW IP type the fence belongs */
268 /** IP instance index if there are several IPs of the same type. */
269 uint32_t ip_instance;
271 /** Ring index of the HW IP */
274 /** Specify fence for which we need to check submission status.*/
279 * Structure describing IB
281 * \sa amdgpu_cs_request, amdgpu_cs_submit()
284 struct amdgpu_cs_ib_info {
288 /** Virtual MC address of the command buffer */
289 uint64_t ib_mc_address;
292 * Size of Command Buffer to be submitted.
293 * - The size is in units of dwords (4 bytes).
300 * Structure describing fence information
302 * \sa amdgpu_cs_request, amdgpu_cs_query_fence,
303 * amdgpu_cs_submit(), amdgpu_cs_query_fence_status()
305 struct amdgpu_cs_fence_info {
306 /** buffer object for the fence */
307 amdgpu_bo_handle handle;
309 /** fence offset in the unit of sizeof(uint64_t) */
314 * Structure describing submission request
316 * \note We could have several IBs as packet. e.g. CE, CE, DE case for gfx
318 * \sa amdgpu_cs_submit()
320 struct amdgpu_cs_request {
321 /** Specify flags with additional information */
324 /** Specify HW IP block type to which to send the IB. */
327 /** IP instance index if there are several IPs of the same type. */
328 unsigned ip_instance;
331 * Specify ring index of the IP. We could have several rings
332 * in the same IP. E.g. 0 for SDMA0 and 1 for SDMA1.
337 * List handle with resources used by this request.
339 amdgpu_bo_list_handle resources;
342 * Number of dependencies this Command submission needs to
343 * wait for before starting execution.
345 uint32_t number_of_dependencies;
348 * Array of dependencies which need to be met before
349 * execution can start.
351 struct amdgpu_cs_fence *dependencies;
353 /** Number of IBs to submit in the field ibs. */
354 uint32_t number_of_ibs;
357 * IBs to submit. Those IBs will be submit together as single entity
359 struct amdgpu_cs_ib_info *ibs;
362 * The returned sequence number for the command submission
367 * The fence information
369 struct amdgpu_cs_fence_info fence_info;
373 * Structure which provide information about GPU VM MC Address space
374 * alignments requirements
376 * \sa amdgpu_query_buffer_size_alignment
378 struct amdgpu_buffer_size_alignments {
379 /** Size alignment requirement for allocation in
384 * Size alignment requirement for allocation in remote memory
386 uint64_t size_remote;
390 * Structure which provide information about heap
392 * \sa amdgpu_query_heap_info()
395 struct amdgpu_heap_info {
396 /** Theoretical max. available memory in the given heap */
400 * Number of bytes allocated in the heap. This includes all processes
401 * and private allocations in the kernel. It changes when new buffers
402 * are allocated, freed, and moved. It cannot be larger than
408 * Theoretical possible max. size of buffer which
409 * could be allocated in the given heap
411 uint64_t max_allocation;
415 * Describe GPU h/w info needed for UMD correct initialization
417 * \sa amdgpu_query_gpu_info()
419 struct amdgpu_gpu_info {
424 /** Chip external revision */
425 uint32_t chip_external_rev;
430 /** max engine clock*/
431 uint64_t max_engine_clk;
432 /** max memory clock */
433 uint64_t max_memory_clk;
434 /** number of shader engines */
435 uint32_t num_shader_engines;
436 /** number of shader arrays per engine */
437 uint32_t num_shader_arrays_per_engine;
438 /** Number of available good shader pipes */
439 uint32_t avail_quad_shader_pipes;
440 /** Max. number of shader pipes.(including good and bad pipes */
441 uint32_t max_quad_shader_pipes;
442 /** Number of parameter cache entries per shader quad pipe */
443 uint32_t cache_entries_per_quad_pipe;
444 /** Number of available graphics context */
445 uint32_t num_hw_gfx_contexts;
446 /** Number of render backend pipes */
448 /** Enabled render backend pipe mask */
449 uint32_t enabled_rb_pipes_mask;
450 /** Frequency of GPU Counter */
451 uint32_t gpu_counter_freq;
452 /** CC_RB_BACKEND_DISABLE.BACKEND_DISABLE per SE */
453 uint32_t backend_disable[4];
454 /** Value of MC_ARB_RAMCFG register*/
455 uint32_t mc_arb_ramcfg;
456 /** Value of GB_ADDR_CONFIG */
457 uint32_t gb_addr_cfg;
458 /** Values of the GB_TILE_MODE0..31 registers */
459 uint32_t gb_tile_mode[32];
460 /** Values of GB_MACROTILE_MODE0..15 registers */
461 uint32_t gb_macro_tile_mode[16];
462 /** Value of PA_SC_RASTER_CONFIG register per SE */
463 uint32_t pa_sc_raster_cfg[4];
464 /** Value of PA_SC_RASTER_CONFIG_1 register per SE */
465 uint32_t pa_sc_raster_cfg1[4];
467 uint32_t cu_active_number;
469 uint32_t cu_bitmap[4][4];
470 /* video memory type info*/
472 /* video memory bit width*/
473 uint32_t vram_bit_width;
474 /** constant engine ram size*/
475 uint32_t ce_ram_size;
476 /* vce harvesting instance */
477 uint32_t vce_harvest_config;
478 /* PCI revision ID */
483 /*--------------------------------------------------------------------------*/
484 /*------------------------- Functions --------------------------------------*/
485 /*--------------------------------------------------------------------------*/
488 * Initialization / Cleanup
494 * \param fd - \c [in] File descriptor for AMD GPU device
495 * received previously as the result of
496 * e.g. drmOpen() call.
497 * For legacy fd type, the DRI2/DRI3
498 * authentication should be done before
499 * calling this function.
500 * \param major_version - \c [out] Major version of library. It is assumed
501 * that adding new functionality will cause
502 * increase in major version
503 * \param minor_version - \c [out] Minor version of library
504 * \param device_handle - \c [out] Pointer to opaque context which should
505 * be passed as the first parameter on each
509 * \return 0 on success\n
510 * <0 - Negative POSIX Error code
513 * \sa amdgpu_device_deinitialize()
515 int amdgpu_device_initialize(int fd,
516 uint32_t *major_version,
517 uint32_t *minor_version,
518 amdgpu_device_handle *device_handle);
522 * When access to such library does not needed any more the special
523 * function must be call giving opportunity to clean up any
524 * resources if needed.
526 * \param device_handle - \c [in] Context associated with file
527 * descriptor for AMD GPU device
528 * received previously as the
529 * result e.g. of drmOpen() call.
531 * \return 0 on success\n
532 * <0 - Negative POSIX Error code
534 * \sa amdgpu_device_initialize()
537 int amdgpu_device_deinitialize(amdgpu_device_handle device_handle);
545 * Allocate memory to be used by UMD for GPU related operations
547 * \param dev - \c [in] Device handle.
548 * See #amdgpu_device_initialize()
549 * \param alloc_buffer - \c [in] Pointer to the structure describing an
551 * \param buf_handle - \c [out] Allocated buffer handle
553 * \return 0 on success\n
554 * <0 - Negative POSIX Error code
556 * \sa amdgpu_bo_free()
558 int amdgpu_bo_alloc(amdgpu_device_handle dev,
559 struct amdgpu_bo_alloc_request *alloc_buffer,
560 amdgpu_bo_handle *buf_handle);
563 * Associate opaque data with buffer to be queried by another UMD
565 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
566 * \param buf_handle - \c [in] Buffer handle
567 * \param info - \c [in] Metadata to associated with buffer
569 * \return 0 on success\n
570 * <0 - Negative POSIX Error code
572 int amdgpu_bo_set_metadata(amdgpu_bo_handle buf_handle,
573 struct amdgpu_bo_metadata *info);
576 * Query buffer information including metadata previusly associated with
579 * \param dev - \c [in] Device handle.
580 * See #amdgpu_device_initialize()
581 * \param buf_handle - \c [in] Buffer handle
582 * \param info - \c [out] Structure describing buffer
584 * \return 0 on success\n
585 * <0 - Negative POSIX Error code
587 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc()
589 int amdgpu_bo_query_info(amdgpu_bo_handle buf_handle,
590 struct amdgpu_bo_info *info);
593 * Allow others to get access to buffer
595 * \param dev - \c [in] Device handle.
596 * See #amdgpu_device_initialize()
597 * \param buf_handle - \c [in] Buffer handle
598 * \param type - \c [in] Type of handle requested
599 * \param shared_handle - \c [out] Special "shared" handle
601 * \return 0 on success\n
602 * <0 - Negative POSIX Error code
604 * \sa amdgpu_bo_import()
607 int amdgpu_bo_export(amdgpu_bo_handle buf_handle,
608 enum amdgpu_bo_handle_type type,
609 uint32_t *shared_handle);
612 * Request access to "shared" buffer
614 * \param dev - \c [in] Device handle.
615 * See #amdgpu_device_initialize()
616 * \param type - \c [in] Type of handle requested
617 * \param shared_handle - \c [in] Shared handle received as result "import"
619 * \param output - \c [out] Pointer to structure with information
620 * about imported buffer
622 * \return 0 on success\n
623 * <0 - Negative POSIX Error code
625 * \note Buffer must be "imported" only using new "fd" (different from
626 * one used by "exporter").
628 * \sa amdgpu_bo_export()
631 int amdgpu_bo_import(amdgpu_device_handle dev,
632 enum amdgpu_bo_handle_type type,
633 uint32_t shared_handle,
634 struct amdgpu_bo_import_result *output);
637 * Request GPU access to user allocated memory e.g. via "malloc"
639 * \param dev - [in] Device handle. See #amdgpu_device_initialize()
640 * \param cpu - [in] CPU address of user allocated memory which we
641 * want to map to GPU address space (make GPU accessible)
642 * (This address must be correctly aligned).
643 * \param size - [in] Size of allocation (must be correctly aligned)
644 * \param buf_handle - [out] Buffer handle for the userptr memory
645 * resource on submission and be used in other operations.
648 * \return 0 on success\n
649 * <0 - Negative POSIX Error code
652 * This call doesn't guarantee that such memory will be persistently
653 * "locked" / make non-pageable. The purpose of this call is to provide
654 * opportunity for GPU get access to this resource during submission.
656 * The maximum amount of memory which could be mapped in this call depends
657 * if overcommit is disabled or not. If overcommit is disabled than the max.
658 * amount of memory to be pinned will be limited by left "free" size in total
659 * amount of memory which could be locked simultaneously ("GART" size).
661 * Supported (theoretical) max. size of mapping is restricted only by
664 * It is responsibility of caller to correctly specify access rights
667 int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev,
668 void *cpu, uint64_t size,
669 amdgpu_bo_handle *buf_handle);
672 * Free previosuly allocated memory
674 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
675 * \param buf_handle - \c [in] Buffer handle to free
677 * \return 0 on success\n
678 * <0 - Negative POSIX Error code
680 * \note In the case of memory shared between different applications all
681 * resources will be “physically” freed only all such applications
683 * \note If is UMD responsibility to ‘free’ buffer only when there is no
686 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc()
689 int amdgpu_bo_free(amdgpu_bo_handle buf_handle);
692 * Request CPU access to GPU accessible memory
694 * \param buf_handle - \c [in] Buffer handle
695 * \param cpu - \c [out] CPU address to be used for access
697 * \return 0 on success\n
698 * <0 - Negative POSIX Error code
700 * \sa amdgpu_bo_cpu_unmap()
703 int amdgpu_bo_cpu_map(amdgpu_bo_handle buf_handle, void **cpu);
706 * Release CPU access to GPU memory
708 * \param buf_handle - \c [in] Buffer handle
710 * \return 0 on success\n
711 * <0 - Negative POSIX Error code
713 * \sa amdgpu_bo_cpu_map()
716 int amdgpu_bo_cpu_unmap(amdgpu_bo_handle buf_handle);
719 * Wait until a buffer is not used by the device.
721 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
722 * \param buf_handle - \c [in] Buffer handle.
723 * \param timeout_ns - Timeout in nanoseconds.
724 * \param buffer_busy - 0 if buffer is idle, all GPU access was completed
725 * and no GPU access is scheduled.
726 * 1 GPU access is in fly or scheduled
728 * \return 0 - on success
729 * <0 - Negative POSIX Error code
731 int amdgpu_bo_wait_for_idle(amdgpu_bo_handle buf_handle,
736 * Creates a BO list handle for command submission.
738 * \param dev - \c [in] Device handle.
739 * See #amdgpu_device_initialize()
740 * \param number_of_resources - \c [in] Number of BOs in the list
741 * \param resources - \c [in] List of BO handles
742 * \param resource_prios - \c [in] Optional priority for each handle
743 * \param result - \c [out] Created BO list handle
745 * \return 0 on success\n
746 * <0 - Negative POSIX Error code
748 * \sa amdgpu_bo_list_destroy()
750 int amdgpu_bo_list_create(amdgpu_device_handle dev,
751 uint32_t number_of_resources,
752 amdgpu_bo_handle *resources,
753 uint8_t *resource_prios,
754 amdgpu_bo_list_handle *result);
757 * Destroys a BO list handle.
759 * \param handle - \c [in] BO list handle.
761 * \return 0 on success\n
762 * <0 - Negative POSIX Error code
764 * \sa amdgpu_bo_list_create()
766 int amdgpu_bo_list_destroy(amdgpu_bo_list_handle handle);
769 * Update resources for existing BO list
771 * \param handle - \c [in] BO list handle
772 * \param number_of_resources - \c [in] Number of BOs in the list
773 * \param resources - \c [in] List of BO handles
774 * \param resource_prios - \c [in] Optional priority for each handle
776 * \return 0 on success\n
777 * <0 - Negative POSIX Error code
779 * \sa amdgpu_bo_list_update()
781 int amdgpu_bo_list_update(amdgpu_bo_list_handle handle,
782 uint32_t number_of_resources,
783 amdgpu_bo_handle *resources,
784 uint8_t *resource_prios);
787 * GPU Execution context
792 * Create GPU execution Context
794 * For the purpose of GPU Scheduler and GPU Robustness extensions it is
795 * necessary to have information/identify rendering/compute contexts.
796 * It also may be needed to associate some specific requirements with such
797 * contexts. Kernel driver will guarantee that submission from the same
798 * context will always be executed in order (first come, first serve).
801 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
802 * \param context - \c [out] GPU Context handle
804 * \return 0 on success\n
805 * <0 - Negative POSIX Error code
807 * \sa amdgpu_cs_ctx_free()
810 int amdgpu_cs_ctx_create(amdgpu_device_handle dev,
811 amdgpu_context_handle *context);
815 * Destroy GPU execution context when not needed any more
817 * \param context - \c [in] GPU Context handle
819 * \return 0 on success\n
820 * <0 - Negative POSIX Error code
822 * \sa amdgpu_cs_ctx_create()
825 int amdgpu_cs_ctx_free(amdgpu_context_handle context);
828 * Query reset state for the specific GPU Context
830 * \param context - \c [in] GPU Context handle
831 * \param state - \c [out] One of AMDGPU_CTX_*_RESET
832 * \param hangs - \c [out] Number of hangs caused by the context.
834 * \return 0 on success\n
835 * <0 - Negative POSIX Error code
837 * \sa amdgpu_cs_ctx_create()
840 int amdgpu_cs_query_reset_state(amdgpu_context_handle context,
841 uint32_t *state, uint32_t *hangs);
844 * Command Buffers Management
849 * Send request to submit command buffers to hardware.
851 * Kernel driver could use GPU Scheduler to make decision when physically
852 * sent this request to the hardware. Accordingly this request could be put
853 * in queue and sent for execution later. The only guarantee is that request
854 * from the same GPU context to the same ip:ip_instance:ring will be executed in
857 * The caller can specify the user fence buffer/location with the fence_info in the
858 * cs_request.The sequence number is returned via the 'seq_no' parameter
859 * in ibs_request structure.
862 * \param dev - \c [in] Device handle.
863 * See #amdgpu_device_initialize()
864 * \param context - \c [in] GPU Context
865 * \param flags - \c [in] Global submission flags
866 * \param ibs_request - \c [in/out] Pointer to submission requests.
867 * We could submit to the several
868 * engines/rings simulteniously as
870 * \param number_of_requests - \c [in] Number of submission requests
872 * \return 0 on success\n
873 * <0 - Negative POSIX Error code
875 * \note It is required to pass correct resource list with buffer handles
876 * which will be accessible by command buffers from submission
877 * This will allow kernel driver to correctly implement "paging".
878 * Failure to do so will have unpredictable results.
880 * \sa amdgpu_command_buffer_alloc(), amdgpu_command_buffer_free(),
881 * amdgpu_cs_query_fence_status()
884 int amdgpu_cs_submit(amdgpu_context_handle context,
886 struct amdgpu_cs_request *ibs_request,
887 uint32_t number_of_requests);
890 * Query status of Command Buffer Submission
892 * \param fence - \c [in] Structure describing fence to query
893 * \param timeout_ns - \c [in] Timeout value to wait
894 * \param flags - \c [in] Flags for the query
895 * \param expired - \c [out] If fence expired or not.\n
896 * 0 – if fence is not expired\n
899 * \return 0 on success\n
900 * <0 - Negative POSIX Error code
902 * \note If UMD wants only to check operation status and returned immediately
903 * then timeout value as 0 must be passed. In this case success will be
904 * returned in the case if submission was completed or timeout error
907 * \sa amdgpu_cs_submit()
909 int amdgpu_cs_query_fence_status(struct amdgpu_cs_fence *fence,
915 * Wait for multiple fences
917 * \param fences - \c [in] The fence array to wait
918 * \param fence_count - \c [in] The fence count
919 * \param wait_all - \c [in] If true, wait all fences to be signaled,
920 * otherwise, wait at least one fence
921 * \param timeout_ns - \c [in] The timeout to wait, in nanoseconds
922 * \param status - \c [out] '1' for signaled, '0' for timeout
923 * \param first - \c [out] the index of the first signaled fence from @fences
925 * \return 0 on success
926 * <0 - Negative POSIX Error code
928 * \note Currently it supports only one amdgpu_device. All fences come from
929 * the same amdgpu_device with the same fd.
931 int amdgpu_cs_wait_fences(struct amdgpu_cs_fence *fences,
932 uint32_t fence_count,
935 uint32_t *status, uint32_t *first);
943 * Query allocation size alignments
945 * UMD should query information about GPU VM MC size alignments requirements
946 * to be able correctly choose required allocation size and implement
947 * internal optimization if needed.
949 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
950 * \param info - \c [out] Pointer to structure to get size alignment
953 * \return 0 on success\n
954 * <0 - Negative POSIX Error code
957 int amdgpu_query_buffer_size_alignment(amdgpu_device_handle dev,
958 struct amdgpu_buffer_size_alignments
962 * Query firmware versions
964 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
965 * \param fw_type - \c [in] AMDGPU_INFO_FW_*
966 * \param ip_instance - \c [in] Index of the IP block of the same type.
967 * \param index - \c [in] Index of the engine. (for SDMA and MEC)
968 * \param version - \c [out] Pointer to to the "version" return value
969 * \param feature - \c [out] Pointer to to the "feature" return value
971 * \return 0 on success\n
972 * <0 - Negative POSIX Error code
975 int amdgpu_query_firmware_version(amdgpu_device_handle dev, unsigned fw_type,
976 unsigned ip_instance, unsigned index,
977 uint32_t *version, uint32_t *feature);
980 * Query the number of HW IP instances of a certain type.
982 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
983 * \param type - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
984 * \param count - \c [out] Pointer to structure to get information
986 * \return 0 on success\n
987 * <0 - Negative POSIX Error code
989 int amdgpu_query_hw_ip_count(amdgpu_device_handle dev, unsigned type,
993 * Query engine information
995 * This query allows UMD to query information different engines and their
998 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
999 * \param type - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
1000 * \param ip_instance - \c [in] Index of the IP block of the same type.
1001 * \param info - \c [out] Pointer to structure to get information
1003 * \return 0 on success\n
1004 * <0 - Negative POSIX Error code
1006 int amdgpu_query_hw_ip_info(amdgpu_device_handle dev, unsigned type,
1007 unsigned ip_instance,
1008 struct drm_amdgpu_info_hw_ip *info);
1011 * Query heap information
1013 * This query allows UMD to query potentially available memory resources and
1014 * adjust their logic if necessary.
1016 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1017 * \param heap - \c [in] Heap type
1018 * \param info - \c [in] Pointer to structure to get needed information
1020 * \return 0 on success\n
1021 * <0 - Negative POSIX Error code
1024 int amdgpu_query_heap_info(amdgpu_device_handle dev, uint32_t heap,
1025 uint32_t flags, struct amdgpu_heap_info *info);
1028 * Get the CRTC ID from the mode object ID
1030 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1031 * \param id - \c [in] Mode object ID
1032 * \param result - \c [in] Pointer to the CRTC ID
1034 * \return 0 on success\n
1035 * <0 - Negative POSIX Error code
1038 int amdgpu_query_crtc_from_id(amdgpu_device_handle dev, unsigned id,
1042 * Query GPU H/w Info
1044 * Query hardware specific information
1046 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1047 * \param heap - \c [in] Heap type
1048 * \param info - \c [in] Pointer to structure to get needed information
1050 * \return 0 on success\n
1051 * <0 - Negative POSIX Error code
1054 int amdgpu_query_gpu_info(amdgpu_device_handle dev,
1055 struct amdgpu_gpu_info *info);
1058 * Query hardware or driver information.
1060 * The return size is query-specific and depends on the "info_id" parameter.
1061 * No more than "size" bytes is returned.
1063 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1064 * \param info_id - \c [in] AMDGPU_INFO_*
1065 * \param size - \c [in] Size of the returned value.
1066 * \param value - \c [out] Pointer to the return value.
1068 * \return 0 on success\n
1069 * <0 - Negative POSIX error code
1072 int amdgpu_query_info(amdgpu_device_handle dev, unsigned info_id,
1073 unsigned size, void *value);
1076 * Query information about GDS
1078 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1079 * \param gds_info - \c [out] Pointer to structure to get GDS information
1081 * \return 0 on success\n
1082 * <0 - Negative POSIX Error code
1085 int amdgpu_query_gds_info(amdgpu_device_handle dev,
1086 struct amdgpu_gds_resource_info *gds_info);
1089 * Query information about sensor.
1091 * The return size is query-specific and depends on the "sensor_type"
1092 * parameter. No more than "size" bytes is returned.
1094 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1095 * \param sensor_type - \c [in] AMDGPU_INFO_SENSOR_*
1096 * \param size - \c [in] Size of the returned value.
1097 * \param value - \c [out] Pointer to the return value.
1099 * \return 0 on success\n
1100 * <0 - Negative POSIX Error code
1103 int amdgpu_query_sensor_info(amdgpu_device_handle dev, unsigned sensor_type,
1104 unsigned size, void *value);
1107 * Read a set of consecutive memory-mapped registers.
1108 * Not all registers are allowed to be read by userspace.
1110 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize(
1111 * \param dword_offset - \c [in] Register offset in dwords
1112 * \param count - \c [in] The number of registers to read starting
1114 * \param instance - \c [in] GRBM_GFX_INDEX selector. It may have other
1115 * uses. Set it to 0xffffffff if unsure.
1116 * \param flags - \c [in] Flags with additional information.
1117 * \param values - \c [out] The pointer to return values.
1119 * \return 0 on success\n
1120 * <0 - Negative POSIX error code
1123 int amdgpu_read_mm_registers(amdgpu_device_handle dev, unsigned dword_offset,
1124 unsigned count, uint32_t instance, uint32_t flags,
1128 * Flag to request VA address range in the 32bit address space
1130 #define AMDGPU_VA_RANGE_32_BIT 0x1
1133 * Allocate virtual address range
1135 * \param dev - [in] Device handle. See #amdgpu_device_initialize()
1136 * \param va_range_type - \c [in] Type of MC va range from which to allocate
1137 * \param size - \c [in] Size of range. Size must be correctly* aligned.
1138 * It is client responsibility to correctly aligned size based on the future
1139 * usage of allocated range.
1140 * \param va_base_alignment - \c [in] Overwrite base address alignment
1141 * requirement for GPU VM MC virtual
1142 * address assignment. Must be multiple of size alignments received as
1143 * 'amdgpu_buffer_size_alignments'.
1144 * If 0 use the default one.
1145 * \param va_base_required - \c [in] Specified required va base address.
1146 * If 0 then library choose available one.
1147 * If !0 value will be passed and those value already "in use" then
1148 * corresponding error status will be returned.
1149 * \param va_base_allocated - \c [out] On return: Allocated VA base to be used
1151 * \param va_range_handle - \c [out] On return: Handle assigned to allocation
1152 * \param flags - \c [in] flags for special VA range
1154 * \return 0 on success\n
1155 * >0 - AMD specific error code\n
1156 * <0 - Negative POSIX Error code
1159 * It is client responsibility to correctly handle VA assignments and usage.
1160 * Neither kernel driver nor libdrm_amdpgu are able to prevent and
1161 * detect wrong va assignemnt.
1163 * It is client responsibility to correctly handle multi-GPU cases and to pass
1164 * the corresponding arrays of all devices handles where corresponding VA will
1168 int amdgpu_va_range_alloc(amdgpu_device_handle dev,
1169 enum amdgpu_gpu_va_range va_range_type,
1171 uint64_t va_base_alignment,
1172 uint64_t va_base_required,
1173 uint64_t *va_base_allocated,
1174 amdgpu_va_handle *va_range_handle,
1178 * Free previously allocated virtual address range
1181 * \param va_range_handle - \c [in] Handle assigned to VA allocation
1183 * \return 0 on success\n
1184 * >0 - AMD specific error code\n
1185 * <0 - Negative POSIX Error code
1188 int amdgpu_va_range_free(amdgpu_va_handle va_range_handle);
1191 * Query virtual address range
1193 * UMD can query GPU VM range supported by each device
1194 * to initialize its own VAM accordingly.
1196 * \param dev - [in] Device handle. See #amdgpu_device_initialize()
1197 * \param type - \c [in] Type of virtual address range
1198 * \param offset - \c [out] Start offset of virtual address range
1199 * \param size - \c [out] Size of virtual address range
1201 * \return 0 on success\n
1202 * <0 - Negative POSIX Error code
1206 int amdgpu_va_range_query(amdgpu_device_handle dev,
1207 enum amdgpu_gpu_va_range type,
1212 * VA mapping/unmapping for the buffer object
1214 * \param bo - \c [in] BO handle
1215 * \param offset - \c [in] Start offset to map
1216 * \param size - \c [in] Size to map
1217 * \param addr - \c [in] Start virtual address.
1218 * \param flags - \c [in] Supported flags for mapping/unmapping
1219 * \param ops - \c [in] AMDGPU_VA_OP_MAP or AMDGPU_VA_OP_UNMAP
1221 * \return 0 on success\n
1222 * <0 - Negative POSIX Error code
1226 int amdgpu_bo_va_op(amdgpu_bo_handle bo,
1234 * VA mapping/unmapping for a buffer object or PRT region.
1236 * This is not a simple drop-in extension for amdgpu_bo_va_op; instead, all
1237 * parameters are treated "raw", i.e. size is not automatically aligned, and
1238 * all flags must be specified explicitly.
1240 * \param dev - \c [in] device handle
1241 * \param bo - \c [in] BO handle (may be NULL)
1242 * \param offset - \c [in] Start offset to map
1243 * \param size - \c [in] Size to map
1244 * \param addr - \c [in] Start virtual address.
1245 * \param flags - \c [in] Supported flags for mapping/unmapping
1246 * \param ops - \c [in] AMDGPU_VA_OP_MAP or AMDGPU_VA_OP_UNMAP
1248 * \return 0 on success\n
1249 * <0 - Negative POSIX Error code
1253 int amdgpu_bo_va_op_raw(amdgpu_device_handle dev,
1254 amdgpu_bo_handle bo,
1264 * \param sem - \c [out] semaphore handle
1266 * \return 0 on success\n
1267 * <0 - Negative POSIX Error code
1270 int amdgpu_cs_create_semaphore(amdgpu_semaphore_handle *sem);
1275 * \param context - \c [in] GPU Context
1276 * \param ip_type - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
1277 * \param ip_instance - \c [in] Index of the IP block of the same type
1278 * \param ring - \c [in] Specify ring index of the IP
1279 * \param sem - \c [in] semaphore handle
1281 * \return 0 on success\n
1282 * <0 - Negative POSIX Error code
1285 int amdgpu_cs_signal_semaphore(amdgpu_context_handle ctx,
1287 uint32_t ip_instance,
1289 amdgpu_semaphore_handle sem);
1294 * \param context - \c [in] GPU Context
1295 * \param ip_type - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
1296 * \param ip_instance - \c [in] Index of the IP block of the same type
1297 * \param ring - \c [in] Specify ring index of the IP
1298 * \param sem - \c [in] semaphore handle
1300 * \return 0 on success\n
1301 * <0 - Negative POSIX Error code
1304 int amdgpu_cs_wait_semaphore(amdgpu_context_handle ctx,
1306 uint32_t ip_instance,
1308 amdgpu_semaphore_handle sem);
1313 * \param sem - \c [in] semaphore handle
1315 * \return 0 on success\n
1316 * <0 - Negative POSIX Error code
1319 int amdgpu_cs_destroy_semaphore(amdgpu_semaphore_handle sem);
1322 * Get the ASIC marketing name
1324 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
1326 * \return the constant string of the marketing name
1327 * "NULL" means the ASIC is not found
1329 const char *amdgpu_get_marketing_name(amdgpu_device_handle dev);
1335 #endif /* #ifdef _AMDGPU_H_ */