2eb03bf150ec4a998442b892d49fbb16bbdeea72
[platform/upstream/libdrm.git] / amdgpu / amdgpu.h
1 /*
2  * Copyright 2014 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  */
23
24 /**
25  * \file amdgpu.h
26  *
27  * Declare public libdrm_amdgpu API
28  *
29  * This file define API exposed by libdrm_amdgpu library.
30  * User wanted to use libdrm_amdgpu functionality must include
31  * this file.
32  *
33  */
34 #ifndef _AMDGPU_H_
35 #define _AMDGPU_H_
36
37 #include <stdint.h>
38 #include <stdbool.h>
39
40 #ifdef __cplusplus
41 extern "C" {
42 #endif
43
44 struct drm_amdgpu_info_hw_ip;
45
46 /*--------------------------------------------------------------------------*/
47 /* --------------------------- Defines ------------------------------------ */
48 /*--------------------------------------------------------------------------*/
49
50 /**
51  * Define max. number of Command Buffers (IB) which could be sent to the single
52  * hardware IP to accommodate CE/DE requirements
53  *
54  * \sa amdgpu_cs_ib_info
55 */
56 #define AMDGPU_CS_MAX_IBS_PER_SUBMIT            4
57
58 /**
59  * Special timeout value meaning that the timeout is infinite.
60  */
61 #define AMDGPU_TIMEOUT_INFINITE                 0xffffffffffffffffull
62
63 /**
64  * Used in amdgpu_cs_query_fence_status(), meaning that the given timeout
65  * is absolute.
66  */
67 #define AMDGPU_QUERY_FENCE_TIMEOUT_IS_ABSOLUTE     (1 << 0)
68
69 /*--------------------------------------------------------------------------*/
70 /* ----------------------------- Enums ------------------------------------ */
71 /*--------------------------------------------------------------------------*/
72
73 /**
74  * Enum describing possible handle types
75  *
76  * \sa amdgpu_bo_import, amdgpu_bo_export
77  *
78 */
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,
82
83         /** KMS handle which is used by all driver ioctls */
84         amdgpu_bo_handle_type_kms = 1,
85
86         /** DMA-buf fd handle */
87         amdgpu_bo_handle_type_dma_buf_fd = 2
88 };
89
90 /** Define known types of GPU VM VA ranges */
91 enum amdgpu_gpu_va_range
92 {
93         /** Allocate from "normal"/general range */
94         amdgpu_gpu_va_range_general = 0
95 };
96
97 /*--------------------------------------------------------------------------*/
98 /* -------------------------- Datatypes ----------------------------------- */
99 /*--------------------------------------------------------------------------*/
100
101 /**
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
106  */
107 typedef struct amdgpu_device *amdgpu_device_handle;
108
109 /**
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)
113  */
114 typedef struct amdgpu_context *amdgpu_context_handle;
115
116 /**
117  * Define handle for amdgpu resources: buffer, GDS, etc.
118  */
119 typedef struct amdgpu_bo *amdgpu_bo_handle;
120
121 /**
122  * Define handle for list of BOs
123  */
124 typedef struct amdgpu_bo_list *amdgpu_bo_list_handle;
125
126 /**
127  * Define handle to be used to work with VA allocated ranges
128  */
129 typedef struct amdgpu_va *amdgpu_va_handle;
130
131 /**
132  * Define handle for semaphore
133  */
134 typedef struct amdgpu_semaphore *amdgpu_semaphore_handle;
135
136 /*--------------------------------------------------------------------------*/
137 /* -------------------------- Structures ---------------------------------- */
138 /*--------------------------------------------------------------------------*/
139
140 /**
141  * Structure describing memory allocation request
142  *
143  * \sa amdgpu_bo_alloc()
144  *
145 */
146 struct amdgpu_bo_alloc_request {
147         /** Allocation request. It must be aligned correctly. */
148         uint64_t alloc_size;
149
150         /**
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
154          */
155         uint64_t phys_alignment;
156
157         /**
158          * UMD should specify where to allocate memory and how it
159          * will be accessed by the CPU.
160          */
161         uint32_t preferred_heap;
162
163         /** Additional flags passed on allocation */
164         uint64_t flags;
165 };
166
167 /**
168  * Special UMD specific information associated with buffer.
169  *
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.
173  *
174  * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info,
175  *     amdgpu_bo_import(), amdgpu_bo_export
176  *
177 */
178 struct amdgpu_bo_metadata {
179         /** Special flag associated with surface */
180         uint64_t flags;
181
182         /**
183          * ASIC-specific tiling information (also used by DCE).
184          * The encoding is defined by the AMDGPU_TILING_* definitions.
185          */
186         uint64_t tiling_info;
187
188         /** Size of metadata associated with the buffer, in bytes. */
189         uint32_t size_metadata;
190
191         /** UMD specific metadata. Opaque for kernel */
192         uint32_t umd_metadata[64];
193 };
194
195 /**
196  * Structure describing allocated buffer. Client may need
197  * to query such information as part of 'sharing' buffers mechanism
198  *
199  * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info(),
200  *     amdgpu_bo_import(), amdgpu_bo_export()
201 */
202 struct amdgpu_bo_info {
203         /** Allocated memory size */
204         uint64_t alloc_size;
205
206         /**
207          * It may be required to have some specific alignment requirements
208          * for physical back-up storage.
209          */
210         uint64_t phys_alignment;
211
212         /** Heap where to allocate memory. */
213         uint32_t preferred_heap;
214
215         /** Additional allocation flags. */
216         uint64_t alloc_flags;
217
218         /** Metadata associated with buffer if any. */
219         struct amdgpu_bo_metadata metadata;
220 };
221
222 /**
223  * Structure with information about "imported" buffer
224  *
225  * \sa amdgpu_bo_import()
226  *
227  */
228 struct amdgpu_bo_import_result {
229         /** Handle of memory/buffer to use */
230         amdgpu_bo_handle buf_handle;
231
232          /** Buffer size */
233         uint64_t alloc_size;
234 };
235
236 /**
237  *
238  * Structure to describe GDS partitioning information.
239  * \note OA and GWS resources are asscoiated with GDS partition
240  *
241  * \sa amdgpu_gpu_resource_query_gds_info
242  *
243 */
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;
252 };
253
254 /**
255  * Structure describing CS fence
256  *
257  * \sa amdgpu_cs_query_fence_status(), amdgpu_cs_request, amdgpu_cs_submit()
258  *
259 */
260 struct amdgpu_cs_fence {
261
262         /** In which context IB was sent to execution */
263         amdgpu_context_handle context;
264
265         /** To which HW IP type the fence belongs */
266         uint32_t ip_type;
267
268         /** IP instance index if there are several IPs of the same type. */
269         uint32_t ip_instance;
270
271         /** Ring index of the HW IP */
272         uint32_t ring;
273
274         /** Specify fence for which we need to check submission status.*/
275         uint64_t fence;
276 };
277
278 /**
279  * Structure describing IB
280  *
281  * \sa amdgpu_cs_request, amdgpu_cs_submit()
282  *
283 */
284 struct amdgpu_cs_ib_info {
285         /** Special flags */
286         uint64_t flags;
287
288         /** Virtual MC address of the command buffer */
289         uint64_t ib_mc_address;
290
291         /**
292          * Size of Command Buffer to be submitted.
293          *   - The size is in units of dwords (4 bytes).
294          *   - Could be 0
295          */
296         uint32_t size;
297 };
298
299 /**
300  * Structure describing fence information
301  *
302  * \sa amdgpu_cs_request, amdgpu_cs_query_fence,
303  *     amdgpu_cs_submit(), amdgpu_cs_query_fence_status()
304 */
305 struct amdgpu_cs_fence_info {
306         /** buffer object for the fence */
307         amdgpu_bo_handle handle;
308
309         /** fence offset in the unit of sizeof(uint64_t) */
310         uint64_t offset;
311 };
312
313 /**
314  * Structure describing submission request
315  *
316  * \note We could have several IBs as packet. e.g. CE, CE, DE case for gfx
317  *
318  * \sa amdgpu_cs_submit()
319 */
320 struct amdgpu_cs_request {
321         /** Specify flags with additional information */
322         uint64_t flags;
323
324         /** Specify HW IP block type to which to send the IB. */
325         unsigned ip_type;
326
327         /** IP instance index if there are several IPs of the same type. */
328         unsigned ip_instance;
329
330         /**
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.
333          */
334         uint32_t ring;
335
336         /**
337          * List handle with resources used by this request.
338          */
339         amdgpu_bo_list_handle resources;
340
341         /**
342          * Number of dependencies this Command submission needs to
343          * wait for before starting execution.
344          */
345         uint32_t number_of_dependencies;
346
347         /**
348          * Array of dependencies which need to be met before
349          * execution can start.
350          */
351         struct amdgpu_cs_fence *dependencies;
352
353         /** Number of IBs to submit in the field ibs. */
354         uint32_t number_of_ibs;
355
356         /**
357          * IBs to submit. Those IBs will be submit together as single entity
358          */
359         struct amdgpu_cs_ib_info *ibs;
360
361         /**
362          * The returned sequence number for the command submission 
363          */
364         uint64_t seq_no;
365
366         /**
367          * The fence information
368          */
369         struct amdgpu_cs_fence_info fence_info;
370 };
371
372 /**
373  * Structure which provide information about GPU VM MC Address space
374  * alignments requirements
375  *
376  * \sa amdgpu_query_buffer_size_alignment
377  */
378 struct amdgpu_buffer_size_alignments {
379         /** Size alignment requirement for allocation in
380          * local memory */
381         uint64_t size_local;
382
383         /**
384          * Size alignment requirement for allocation in remote memory
385          */
386         uint64_t size_remote;
387 };
388
389 /**
390  * Structure which provide information about heap
391  *
392  * \sa amdgpu_query_heap_info()
393  *
394  */
395 struct amdgpu_heap_info {
396         /** Theoretical max. available memory in the given heap */
397         uint64_t heap_size;
398
399         /**
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
403          * heap_size.
404          */
405         uint64_t heap_usage;
406
407         /**
408          * Theoretical possible max. size of buffer which
409          * could be allocated in the given heap
410          */
411         uint64_t max_allocation;
412 };
413
414 /**
415  * Describe GPU h/w info needed for UMD correct initialization
416  *
417  * \sa amdgpu_query_gpu_info()
418 */
419 struct amdgpu_gpu_info {
420         /** Asic id */
421         uint32_t asic_id;
422         /** Chip revision */
423         uint32_t chip_rev;
424         /** Chip external revision */
425         uint32_t chip_external_rev;
426         /** Family ID */
427         uint32_t family_id;
428         /** Special flags */
429         uint64_t ids_flags;
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 */
447         uint32_t rb_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];
466         /* CU info */
467         uint32_t cu_active_number;
468         uint32_t cu_ao_mask;
469         uint32_t cu_bitmap[4][4];
470         /* video memory type info*/
471         uint32_t vram_type;
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 */
479         uint32_t pci_rev_id;
480 };
481
482
483 /*--------------------------------------------------------------------------*/
484 /*------------------------- Functions --------------------------------------*/
485 /*--------------------------------------------------------------------------*/
486
487 /*
488  * Initialization / Cleanup
489  *
490 */
491
492 /**
493  *
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
506  *                                   API call
507  *
508  *
509  * \return   0 on success\n
510  *          <0 - Negative POSIX Error code
511  *
512  *
513  * \sa amdgpu_device_deinitialize()
514 */
515 int amdgpu_device_initialize(int fd,
516                              uint32_t *major_version,
517                              uint32_t *minor_version,
518                              amdgpu_device_handle *device_handle);
519
520 /**
521  *
522  * When access to such library does not needed any more the special
523  * function must be call giving opportunity to clean up any
524  * resources if needed.
525  *
526  * \param   device_handle - \c [in]  Context associated with file
527  *                                   descriptor for AMD GPU device
528  *                                   received previously as the
529  *                                   result e.g. of drmOpen() call.
530  *
531  * \return  0 on success\n
532  *         <0 - Negative POSIX Error code
533  *
534  * \sa amdgpu_device_initialize()
535  *
536 */
537 int amdgpu_device_deinitialize(amdgpu_device_handle device_handle);
538
539 /*
540  * Memory Management
541  *
542 */
543
544 /**
545  * Allocate memory to be used by UMD for GPU related operations
546  *
547  * \param   dev          - \c [in] Device handle.
548  *                                 See #amdgpu_device_initialize()
549  * \param   alloc_buffer - \c [in] Pointer to the structure describing an
550  *                                 allocation request
551  * \param   buf_handle  - \c [out] Allocated buffer handle
552  *
553  * \return   0 on success\n
554  *          <0 - Negative POSIX Error code
555  *
556  * \sa amdgpu_bo_free()
557 */
558 int amdgpu_bo_alloc(amdgpu_device_handle dev,
559                     struct amdgpu_bo_alloc_request *alloc_buffer,
560                     amdgpu_bo_handle *buf_handle);
561
562 /**
563  * Associate opaque data with buffer to be queried by another UMD
564  *
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
568  *
569  * \return   0 on success\n
570  *          <0 - Negative POSIX Error code
571 */
572 int amdgpu_bo_set_metadata(amdgpu_bo_handle buf_handle,
573                            struct amdgpu_bo_metadata *info);
574
575 /**
576  * Query buffer information including metadata previusly associated with
577  * buffer.
578  *
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
583  *
584  * \return   0 on success\n
585  *          <0 - Negative POSIX Error code
586  *
587  * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc()
588 */
589 int amdgpu_bo_query_info(amdgpu_bo_handle buf_handle,
590                          struct amdgpu_bo_info *info);
591
592 /**
593  * Allow others to get access to buffer
594  *
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
600  *
601  * \return   0 on success\n
602  *          <0 - Negative POSIX Error code
603  *
604  * \sa amdgpu_bo_import()
605  *
606 */
607 int amdgpu_bo_export(amdgpu_bo_handle buf_handle,
608                      enum amdgpu_bo_handle_type type,
609                      uint32_t *shared_handle);
610
611 /**
612  * Request access to "shared" buffer
613  *
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"
618  *                                   operation
619  * \param   output        - \c [out] Pointer to structure with information
620  *                                   about imported buffer
621  *
622  * \return   0 on success\n
623  *          <0 - Negative POSIX Error code
624  *
625  * \note  Buffer must be "imported" only using new "fd" (different from
626  *        one used by "exporter").
627  *
628  * \sa amdgpu_bo_export()
629  *
630 */
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);
635
636 /**
637  * Request GPU access to user allocated memory e.g. via "malloc"
638  *
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.
646  *
647  *
648  * \return   0 on success\n
649  *          <0 - Negative POSIX Error code
650  *
651  * \note
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.
655  *
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).
660  *
661  * Supported (theoretical) max. size of mapping is restricted only by
662  * "GART" size.
663  *
664  * It is responsibility of caller to correctly specify access rights
665  * on VA assignment.
666 */
667 int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev,
668                                     void *cpu, uint64_t size,
669                                     amdgpu_bo_handle *buf_handle);
670
671 /**
672  * Free previosuly allocated memory
673  *
674  * \param   dev        - \c [in] Device handle. See #amdgpu_device_initialize()
675  * \param   buf_handle - \c [in]  Buffer handle to free
676  *
677  * \return   0 on success\n
678  *          <0 - Negative POSIX Error code
679  *
680  * \note In the case of memory shared between different applications all
681  *       resources will be “physically” freed only all such applications
682  *       will be terminated
683  * \note If is UMD responsibility to ‘free’ buffer only when there is no
684  *       more GPU access
685  *
686  * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc()
687  *
688 */
689 int amdgpu_bo_free(amdgpu_bo_handle buf_handle);
690
691 /**
692  * Request CPU access to GPU accessible memory
693  *
694  * \param   buf_handle - \c [in] Buffer handle
695  * \param   cpu        - \c [out] CPU address to be used for access
696  *
697  * \return   0 on success\n
698  *          <0 - Negative POSIX Error code
699  *
700  * \sa amdgpu_bo_cpu_unmap()
701  *
702 */
703 int amdgpu_bo_cpu_map(amdgpu_bo_handle buf_handle, void **cpu);
704
705 /**
706  * Release CPU access to GPU memory
707  *
708  * \param   buf_handle  - \c [in] Buffer handle
709  *
710  * \return   0 on success\n
711  *          <0 - Negative POSIX Error code
712  *
713  * \sa amdgpu_bo_cpu_map()
714  *
715 */
716 int amdgpu_bo_cpu_unmap(amdgpu_bo_handle buf_handle);
717
718 /**
719  * Wait until a buffer is not used by the device.
720  *
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
727  *
728  * \return   0 - on success
729  *          <0 - Negative POSIX Error code
730  */
731 int amdgpu_bo_wait_for_idle(amdgpu_bo_handle buf_handle,
732                             uint64_t timeout_ns,
733                             bool *buffer_busy);
734
735 /**
736  * Creates a BO list handle for command submission.
737  *
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
744  *
745  * \return   0 on success\n
746  *          <0 - Negative POSIX Error code
747  *
748  * \sa amdgpu_bo_list_destroy()
749 */
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);
755
756 /**
757  * Destroys a BO list handle.
758  *
759  * \param   handle      - \c [in] BO list handle.
760  *
761  * \return   0 on success\n
762  *          <0 - Negative POSIX Error code
763  *
764  * \sa amdgpu_bo_list_create()
765 */
766 int amdgpu_bo_list_destroy(amdgpu_bo_list_handle handle);
767
768 /**
769  * Update resources for existing BO list
770  *
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
775  *
776  * \return   0 on success\n
777  *          <0 - Negative POSIX Error code
778  *
779  * \sa amdgpu_bo_list_update()
780 */
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);
785
786 /*
787  * GPU Execution context
788  *
789 */
790
791 /**
792  * Create GPU execution Context
793  *
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).
799  *
800  *
801  * \param   dev      - \c [in] Device handle. See #amdgpu_device_initialize()
802  * \param   priority - \c [in] Context creation flags. See AMDGPU_CTX_PRIORITY_*
803  * \param   context  - \c [out] GPU Context handle
804  *
805  * \return   0 on success\n
806  *          <0 - Negative POSIX Error code
807  *
808  * \sa amdgpu_cs_ctx_free()
809  *
810 */
811 int amdgpu_cs_ctx_create2(amdgpu_device_handle dev,
812                          uint32_t priority,
813                          amdgpu_context_handle *context);
814 /**
815  * Create GPU execution Context
816  *
817  * Refer to amdgpu_cs_ctx_create2 for full documentation. This call
818  * is missing the priority parameter.
819  *
820  * \sa amdgpu_cs_ctx_create2()
821  *
822 */
823 int amdgpu_cs_ctx_create(amdgpu_device_handle dev,
824                          amdgpu_context_handle *context);
825
826 /**
827  *
828  * Destroy GPU execution context when not needed any more
829  *
830  * \param   context - \c [in] GPU Context handle
831  *
832  * \return   0 on success\n
833  *          <0 - Negative POSIX Error code
834  *
835  * \sa amdgpu_cs_ctx_create()
836  *
837 */
838 int amdgpu_cs_ctx_free(amdgpu_context_handle context);
839
840 /**
841  * Query reset state for the specific GPU Context
842  *
843  * \param   context - \c [in]  GPU Context handle
844  * \param   state   - \c [out] One of AMDGPU_CTX_*_RESET
845  * \param   hangs   - \c [out] Number of hangs caused by the context.
846  *
847  * \return   0 on success\n
848  *          <0 - Negative POSIX Error code
849  *
850  * \sa amdgpu_cs_ctx_create()
851  *
852 */
853 int amdgpu_cs_query_reset_state(amdgpu_context_handle context,
854                                 uint32_t *state, uint32_t *hangs);
855
856 /*
857  * Command Buffers Management
858  *
859 */
860
861 /**
862  * Send request to submit command buffers to hardware.
863  *
864  * Kernel driver could use GPU Scheduler to make decision when physically
865  * sent this request to the hardware. Accordingly this request could be put
866  * in queue and sent for execution later. The only guarantee is that request
867  * from the same GPU context to the same ip:ip_instance:ring will be executed in
868  * order.
869  *
870  * The caller can specify the user fence buffer/location with the fence_info in the
871  * cs_request.The sequence number is returned via the 'seq_no' parameter
872  * in ibs_request structure.
873  *
874  *
875  * \param   dev                - \c [in]  Device handle.
876  *                                        See #amdgpu_device_initialize()
877  * \param   context            - \c [in]  GPU Context
878  * \param   flags              - \c [in]  Global submission flags
879  * \param   ibs_request        - \c [in/out] Pointer to submission requests.
880  *                                        We could submit to the several
881  *                                        engines/rings simulteniously as
882  *                                        'atomic' operation
883  * \param   number_of_requests - \c [in]  Number of submission requests
884  *
885  * \return   0 on success\n
886  *          <0 - Negative POSIX Error code
887  *
888  * \note It is required to pass correct resource list with buffer handles
889  *       which will be accessible by command buffers from submission
890  *       This will allow kernel driver to correctly implement "paging".
891  *       Failure to do so will have unpredictable results.
892  *
893  * \sa amdgpu_command_buffer_alloc(), amdgpu_command_buffer_free(),
894  *     amdgpu_cs_query_fence_status()
895  *
896 */
897 int amdgpu_cs_submit(amdgpu_context_handle context,
898                      uint64_t flags,
899                      struct amdgpu_cs_request *ibs_request,
900                      uint32_t number_of_requests);
901
902 /**
903  *  Query status of Command Buffer Submission
904  *
905  * \param   fence   - \c [in] Structure describing fence to query
906  * \param   timeout_ns - \c [in] Timeout value to wait
907  * \param   flags   - \c [in] Flags for the query
908  * \param   expired - \c [out] If fence expired or not.\n
909  *                              0  – if fence is not expired\n
910  *                              !0 - otherwise
911  *
912  * \return   0 on success\n
913  *          <0 - Negative POSIX Error code
914  *
915  * \note If UMD wants only to check operation status and returned immediately
916  *       then timeout value as 0 must be passed. In this case success will be
917  *       returned in the case if submission was completed or timeout error
918  *       code.
919  *
920  * \sa amdgpu_cs_submit()
921 */
922 int amdgpu_cs_query_fence_status(struct amdgpu_cs_fence *fence,
923                                  uint64_t timeout_ns,
924                                  uint64_t flags,
925                                  uint32_t *expired);
926
927 /**
928  *  Wait for multiple fences
929  *
930  * \param   fences      - \c [in] The fence array to wait
931  * \param   fence_count - \c [in] The fence count
932  * \param   wait_all    - \c [in] If true, wait all fences to be signaled,
933  *                                otherwise, wait at least one fence
934  * \param   timeout_ns  - \c [in] The timeout to wait, in nanoseconds
935  * \param   status      - \c [out] '1' for signaled, '0' for timeout
936  * \param   first       - \c [out] the index of the first signaled fence from @fences
937  *
938  * \return  0 on success
939  *          <0 - Negative POSIX Error code
940  *
941  * \note    Currently it supports only one amdgpu_device. All fences come from
942  *          the same amdgpu_device with the same fd.
943 */
944 int amdgpu_cs_wait_fences(struct amdgpu_cs_fence *fences,
945                           uint32_t fence_count,
946                           bool wait_all,
947                           uint64_t timeout_ns,
948                           uint32_t *status, uint32_t *first);
949
950 /*
951  * Query / Info API
952  *
953 */
954
955 /**
956  * Query allocation size alignments
957  *
958  * UMD should query information about GPU VM MC size alignments requirements
959  * to be able correctly choose required allocation size and implement
960  * internal optimization if needed.
961  *
962  * \param   dev  - \c [in] Device handle. See #amdgpu_device_initialize()
963  * \param   info - \c [out] Pointer to structure to get size alignment
964  *                        requirements
965  *
966  * \return   0 on success\n
967  *          <0 - Negative POSIX Error code
968  *
969 */
970 int amdgpu_query_buffer_size_alignment(amdgpu_device_handle dev,
971                                        struct amdgpu_buffer_size_alignments
972                                                 *info);
973
974 /**
975  * Query firmware versions
976  *
977  * \param   dev         - \c [in] Device handle. See #amdgpu_device_initialize()
978  * \param   fw_type     - \c [in] AMDGPU_INFO_FW_*
979  * \param   ip_instance - \c [in] Index of the IP block of the same type.
980  * \param   index       - \c [in] Index of the engine. (for SDMA and MEC)
981  * \param   version     - \c [out] Pointer to to the "version" return value
982  * \param   feature     - \c [out] Pointer to to the "feature" return value
983  *
984  * \return   0 on success\n
985  *          <0 - Negative POSIX Error code
986  *
987 */
988 int amdgpu_query_firmware_version(amdgpu_device_handle dev, unsigned fw_type,
989                                   unsigned ip_instance, unsigned index,
990                                   uint32_t *version, uint32_t *feature);
991
992 /**
993  * Query the number of HW IP instances of a certain type.
994  *
995  * \param   dev      - \c [in] Device handle. See #amdgpu_device_initialize()
996  * \param   type     - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
997  * \param   count    - \c [out] Pointer to structure to get information
998  *
999  * \return   0 on success\n
1000  *          <0 - Negative POSIX Error code
1001 */
1002 int amdgpu_query_hw_ip_count(amdgpu_device_handle dev, unsigned type,
1003                              uint32_t *count);
1004
1005 /**
1006  * Query engine information
1007  *
1008  * This query allows UMD to query information different engines and their
1009  * capabilities.
1010  *
1011  * \param   dev         - \c [in] Device handle. See #amdgpu_device_initialize()
1012  * \param   type        - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
1013  * \param   ip_instance - \c [in] Index of the IP block of the same type.
1014  * \param   info        - \c [out] Pointer to structure to get information
1015  *
1016  * \return   0 on success\n
1017  *          <0 - Negative POSIX Error code
1018 */
1019 int amdgpu_query_hw_ip_info(amdgpu_device_handle dev, unsigned type,
1020                             unsigned ip_instance,
1021                             struct drm_amdgpu_info_hw_ip *info);
1022
1023 /**
1024  * Query heap information
1025  *
1026  * This query allows UMD to query potentially available memory resources and
1027  * adjust their logic if necessary.
1028  *
1029  * \param   dev  - \c [in] Device handle. See #amdgpu_device_initialize()
1030  * \param   heap - \c [in] Heap type
1031  * \param   info - \c [in] Pointer to structure to get needed information
1032  *
1033  * \return   0 on success\n
1034  *          <0 - Negative POSIX Error code
1035  *
1036 */
1037 int amdgpu_query_heap_info(amdgpu_device_handle dev, uint32_t heap,
1038                            uint32_t flags, struct amdgpu_heap_info *info);
1039
1040 /**
1041  * Get the CRTC ID from the mode object ID
1042  *
1043  * \param   dev    - \c [in] Device handle. See #amdgpu_device_initialize()
1044  * \param   id     - \c [in] Mode object ID
1045  * \param   result - \c [in] Pointer to the CRTC ID
1046  *
1047  * \return   0 on success\n
1048  *          <0 - Negative POSIX Error code
1049  *
1050 */
1051 int amdgpu_query_crtc_from_id(amdgpu_device_handle dev, unsigned id,
1052                               int32_t *result);
1053
1054 /**
1055  * Query GPU H/w Info
1056  *
1057  * Query hardware specific information
1058  *
1059  * \param   dev  - \c [in] Device handle. See #amdgpu_device_initialize()
1060  * \param   heap - \c [in] Heap type
1061  * \param   info - \c [in] Pointer to structure to get needed information
1062  *
1063  * \return   0 on success\n
1064  *          <0 - Negative POSIX Error code
1065  *
1066 */
1067 int amdgpu_query_gpu_info(amdgpu_device_handle dev,
1068                            struct amdgpu_gpu_info *info);
1069
1070 /**
1071  * Query hardware or driver information.
1072  *
1073  * The return size is query-specific and depends on the "info_id" parameter.
1074  * No more than "size" bytes is returned.
1075  *
1076  * \param   dev     - \c [in] Device handle. See #amdgpu_device_initialize()
1077  * \param   info_id - \c [in] AMDGPU_INFO_*
1078  * \param   size    - \c [in] Size of the returned value.
1079  * \param   value   - \c [out] Pointer to the return value.
1080  *
1081  * \return   0 on success\n
1082  *          <0 - Negative POSIX error code
1083  *
1084 */
1085 int amdgpu_query_info(amdgpu_device_handle dev, unsigned info_id,
1086                       unsigned size, void *value);
1087
1088 /**
1089  * Query information about GDS
1090  *
1091  * \param   dev      - \c [in] Device handle. See #amdgpu_device_initialize()
1092  * \param   gds_info - \c [out] Pointer to structure to get GDS information
1093  *
1094  * \return   0 on success\n
1095  *          <0 - Negative POSIX Error code
1096  *
1097 */
1098 int amdgpu_query_gds_info(amdgpu_device_handle dev,
1099                         struct amdgpu_gds_resource_info *gds_info);
1100
1101 /**
1102  * Query information about sensor.
1103  *
1104  * The return size is query-specific and depends on the "sensor_type"
1105  * parameter. No more than "size" bytes is returned.
1106  *
1107  * \param   dev         - \c [in] Device handle. See #amdgpu_device_initialize()
1108  * \param   sensor_type - \c [in] AMDGPU_INFO_SENSOR_*
1109  * \param   size        - \c [in] Size of the returned value.
1110  * \param   value       - \c [out] Pointer to the return value.
1111  *
1112  * \return   0 on success\n
1113  *          <0 - Negative POSIX Error code
1114  *
1115 */
1116 int amdgpu_query_sensor_info(amdgpu_device_handle dev, unsigned sensor_type,
1117                              unsigned size, void *value);
1118
1119 /**
1120  * Read a set of consecutive memory-mapped registers.
1121  * Not all registers are allowed to be read by userspace.
1122  *
1123  * \param   dev          - \c [in] Device handle. See #amdgpu_device_initialize(
1124  * \param   dword_offset - \c [in] Register offset in dwords
1125  * \param   count        - \c [in] The number of registers to read starting
1126  *                                 from the offset
1127  * \param   instance     - \c [in] GRBM_GFX_INDEX selector. It may have other
1128  *                                 uses. Set it to 0xffffffff if unsure.
1129  * \param   flags        - \c [in] Flags with additional information.
1130  * \param   values       - \c [out] The pointer to return values.
1131  *
1132  * \return   0 on success\n
1133  *          <0 - Negative POSIX error code
1134  *
1135 */
1136 int amdgpu_read_mm_registers(amdgpu_device_handle dev, unsigned dword_offset,
1137                              unsigned count, uint32_t instance, uint32_t flags,
1138                              uint32_t *values);
1139
1140 /**
1141  * Flag to request VA address range in the 32bit address space
1142 */
1143 #define AMDGPU_VA_RANGE_32_BIT          0x1
1144
1145 /**
1146  * Allocate virtual address range
1147  *
1148  * \param dev - [in] Device handle. See #amdgpu_device_initialize()
1149  * \param va_range_type - \c [in] Type of MC va range from which to allocate
1150  * \param size - \c [in] Size of range. Size must be correctly* aligned.
1151  * It is client responsibility to correctly aligned size based on the future
1152  * usage of allocated range.
1153  * \param va_base_alignment - \c [in] Overwrite base address alignment
1154  * requirement for GPU VM MC virtual
1155  * address assignment. Must be multiple of size alignments received as
1156  * 'amdgpu_buffer_size_alignments'.
1157  * If 0 use the default one.
1158  * \param va_base_required - \c [in] Specified required va base address.
1159  * If 0 then library choose available one.
1160  * If !0 value will be passed and those value already "in use" then
1161  * corresponding error status will be returned.
1162  * \param va_base_allocated - \c [out] On return: Allocated VA base to be used
1163  * by client.
1164  * \param va_range_handle - \c [out] On return: Handle assigned to allocation
1165  * \param flags - \c [in] flags for special VA range
1166  *
1167  * \return 0 on success\n
1168  * >0 - AMD specific error code\n
1169  * <0 - Negative POSIX Error code
1170  *
1171  * \notes \n
1172  * It is client responsibility to correctly handle VA assignments and usage.
1173  * Neither kernel driver nor libdrm_amdpgu are able to prevent and
1174  * detect wrong va assignemnt.
1175  *
1176  * It is client responsibility to correctly handle multi-GPU cases and to pass
1177  * the corresponding arrays of all devices handles where corresponding VA will
1178  * be used.
1179  *
1180 */
1181 int amdgpu_va_range_alloc(amdgpu_device_handle dev,
1182                            enum amdgpu_gpu_va_range va_range_type,
1183                            uint64_t size,
1184                            uint64_t va_base_alignment,
1185                            uint64_t va_base_required,
1186                            uint64_t *va_base_allocated,
1187                            amdgpu_va_handle *va_range_handle,
1188                            uint64_t flags);
1189
1190 /**
1191  * Free previously allocated virtual address range
1192  *
1193  *
1194  * \param va_range_handle - \c [in] Handle assigned to VA allocation
1195  *
1196  * \return 0 on success\n
1197  * >0 - AMD specific error code\n
1198  * <0 - Negative POSIX Error code
1199  *
1200 */
1201 int amdgpu_va_range_free(amdgpu_va_handle va_range_handle);
1202
1203 /**
1204 * Query virtual address range
1205 *
1206 * UMD can query GPU VM range supported by each device
1207 * to initialize its own VAM accordingly.
1208 *
1209 * \param   dev    - [in] Device handle. See #amdgpu_device_initialize()
1210 * \param   type   - \c [in] Type of virtual address range
1211 * \param   offset - \c [out] Start offset of virtual address range
1212 * \param   size   - \c [out] Size of virtual address range
1213 *
1214 * \return   0 on success\n
1215 *          <0 - Negative POSIX Error code
1216 *
1217 */
1218
1219 int amdgpu_va_range_query(amdgpu_device_handle dev,
1220                           enum amdgpu_gpu_va_range type,
1221                           uint64_t *start,
1222                           uint64_t *end);
1223
1224 /**
1225  *  VA mapping/unmapping for the buffer object
1226  *
1227  * \param  bo           - \c [in] BO handle
1228  * \param  offset       - \c [in] Start offset to map
1229  * \param  size         - \c [in] Size to map
1230  * \param  addr         - \c [in] Start virtual address.
1231  * \param  flags        - \c [in] Supported flags for mapping/unmapping
1232  * \param  ops          - \c [in] AMDGPU_VA_OP_MAP or AMDGPU_VA_OP_UNMAP
1233  *
1234  * \return   0 on success\n
1235  *          <0 - Negative POSIX Error code
1236  *
1237 */
1238
1239 int amdgpu_bo_va_op(amdgpu_bo_handle bo,
1240                     uint64_t offset,
1241                     uint64_t size,
1242                     uint64_t addr,
1243                     uint64_t flags,
1244                     uint32_t ops);
1245
1246 /**
1247  *  VA mapping/unmapping for a buffer object or PRT region.
1248  *
1249  * This is not a simple drop-in extension for amdgpu_bo_va_op; instead, all
1250  * parameters are treated "raw", i.e. size is not automatically aligned, and
1251  * all flags must be specified explicitly.
1252  *
1253  * \param  dev          - \c [in] device handle
1254  * \param  bo           - \c [in] BO handle (may be NULL)
1255  * \param  offset       - \c [in] Start offset to map
1256  * \param  size         - \c [in] Size to map
1257  * \param  addr         - \c [in] Start virtual address.
1258  * \param  flags        - \c [in] Supported flags for mapping/unmapping
1259  * \param  ops          - \c [in] AMDGPU_VA_OP_MAP or AMDGPU_VA_OP_UNMAP
1260  *
1261  * \return   0 on success\n
1262  *          <0 - Negative POSIX Error code
1263  *
1264 */
1265
1266 int amdgpu_bo_va_op_raw(amdgpu_device_handle dev,
1267                         amdgpu_bo_handle bo,
1268                         uint64_t offset,
1269                         uint64_t size,
1270                         uint64_t addr,
1271                         uint64_t flags,
1272                         uint32_t ops);
1273
1274 /**
1275  *  create semaphore
1276  *
1277  * \param   sem    - \c [out] semaphore handle
1278  *
1279  * \return   0 on success\n
1280  *          <0 - Negative POSIX Error code
1281  *
1282 */
1283 int amdgpu_cs_create_semaphore(amdgpu_semaphore_handle *sem);
1284
1285 /**
1286  *  signal semaphore
1287  *
1288  * \param   context        - \c [in] GPU Context
1289  * \param   ip_type        - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
1290  * \param   ip_instance    - \c [in] Index of the IP block of the same type
1291  * \param   ring           - \c [in] Specify ring index of the IP
1292  * \param   sem            - \c [in] semaphore handle
1293  *
1294  * \return   0 on success\n
1295  *          <0 - Negative POSIX Error code
1296  *
1297 */
1298 int amdgpu_cs_signal_semaphore(amdgpu_context_handle ctx,
1299                                uint32_t ip_type,
1300                                uint32_t ip_instance,
1301                                uint32_t ring,
1302                                amdgpu_semaphore_handle sem);
1303
1304 /**
1305  *  wait semaphore
1306  *
1307  * \param   context        - \c [in] GPU Context
1308  * \param   ip_type        - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
1309  * \param   ip_instance    - \c [in] Index of the IP block of the same type
1310  * \param   ring           - \c [in] Specify ring index of the IP
1311  * \param   sem            - \c [in] semaphore handle
1312  *
1313  * \return   0 on success\n
1314  *          <0 - Negative POSIX Error code
1315  *
1316 */
1317 int amdgpu_cs_wait_semaphore(amdgpu_context_handle ctx,
1318                              uint32_t ip_type,
1319                              uint32_t ip_instance,
1320                              uint32_t ring,
1321                              amdgpu_semaphore_handle sem);
1322
1323 /**
1324  *  destroy semaphore
1325  *
1326  * \param   sem     - \c [in] semaphore handle
1327  *
1328  * \return   0 on success\n
1329  *          <0 - Negative POSIX Error code
1330  *
1331 */
1332 int amdgpu_cs_destroy_semaphore(amdgpu_semaphore_handle sem);
1333
1334 /**
1335  *  Get the ASIC marketing name
1336  *
1337  * \param   dev         - \c [in] Device handle. See #amdgpu_device_initialize()
1338  *
1339  * \return  the constant string of the marketing name
1340  *          "NULL" means the ASIC is not found
1341 */
1342 const char *amdgpu_get_marketing_name(amdgpu_device_handle dev);
1343
1344 /**
1345  *  Create kernel sync object
1346  *
1347  * \param   dev         - \c [in]  device handle
1348  * \param   flags       - \c [in]  flags that affect creation
1349  * \param   syncobj     - \c [out] sync object handle
1350  *
1351  * \return   0 on success\n
1352  *          <0 - Negative POSIX Error code
1353  *
1354 */
1355 int amdgpu_cs_create_syncobj2(amdgpu_device_handle dev,
1356                               uint32_t  flags,
1357                               uint32_t *syncobj);
1358
1359 /**
1360  *  Create kernel sync object
1361  *
1362  * \param   dev       - \c [in]  device handle
1363  * \param   syncobj   - \c [out] sync object handle
1364  *
1365  * \return   0 on success\n
1366  *          <0 - Negative POSIX Error code
1367  *
1368 */
1369 int amdgpu_cs_create_syncobj(amdgpu_device_handle dev,
1370                              uint32_t *syncobj);
1371 /**
1372  *  Destroy kernel sync object
1373  *
1374  * \param   dev     - \c [in] device handle
1375  * \param   syncobj - \c [in] sync object handle
1376  *
1377  * \return   0 on success\n
1378  *          <0 - Negative POSIX Error code
1379  *
1380 */
1381 int amdgpu_cs_destroy_syncobj(amdgpu_device_handle dev,
1382                               uint32_t syncobj);
1383
1384 /**
1385  * Reset kernel sync objects to unsignalled state.
1386  *
1387  * \param dev           - \c [in] device handle
1388  * \param syncobjs      - \c [in] array of sync object handles
1389  * \param syncobj_count - \c [in] number of handles in syncobjs
1390  *
1391  * \return   0 on success\n
1392  *          <0 - Negative POSIX Error code
1393  *
1394 */
1395 int amdgpu_cs_syncobj_reset(amdgpu_device_handle dev,
1396                             const uint32_t *syncobjs, uint32_t syncobj_count);
1397
1398 /**
1399  * Signal kernel sync objects.
1400  *
1401  * \param dev           - \c [in] device handle
1402  * \param syncobjs      - \c [in] array of sync object handles
1403  * \param syncobj_count - \c [in] number of handles in syncobjs
1404  *
1405  * \return   0 on success\n
1406  *          <0 - Negative POSIX Error code
1407  *
1408 */
1409 int amdgpu_cs_syncobj_signal(amdgpu_device_handle dev,
1410                              const uint32_t *syncobjs, uint32_t syncobj_count);
1411
1412 /**
1413  *  Wait for one or all sync objects to signal.
1414  *
1415  * \param   dev     - \c [in] self-explanatory
1416  * \param   handles - \c [in] array of sync object handles
1417  * \param   num_handles - \c [in] self-explanatory
1418  * \param   timeout_nsec - \c [in] self-explanatory
1419  * \param   flags   - \c [in] a bitmask of DRM_SYNCOBJ_WAIT_FLAGS_*
1420  * \param   first_signaled - \c [in] self-explanatory
1421  *
1422  * \return   0 on success\n
1423  *          -ETIME - Timeout
1424  *          <0 - Negative POSIX Error code
1425  *
1426  */
1427 int amdgpu_cs_syncobj_wait(amdgpu_device_handle dev,
1428                            uint32_t *handles, unsigned num_handles,
1429                            int64_t timeout_nsec, unsigned flags,
1430                            uint32_t *first_signaled);
1431
1432 /**
1433  *  Export kernel sync object to shareable fd.
1434  *
1435  * \param   dev        - \c [in] device handle
1436  * \param   syncobj    - \c [in] sync object handle
1437  * \param   shared_fd  - \c [out] shared file descriptor.
1438  *
1439  * \return   0 on success\n
1440  *          <0 - Negative POSIX Error code
1441  *
1442 */
1443 int amdgpu_cs_export_syncobj(amdgpu_device_handle dev,
1444                              uint32_t syncobj,
1445                              int *shared_fd);
1446 /**
1447  *  Import kernel sync object from shareable fd.
1448  *
1449  * \param   dev        - \c [in] device handle
1450  * \param   shared_fd  - \c [in] shared file descriptor.
1451  * \param   syncobj    - \c [out] sync object handle
1452  *
1453  * \return   0 on success\n
1454  *          <0 - Negative POSIX Error code
1455  *
1456 */
1457 int amdgpu_cs_import_syncobj(amdgpu_device_handle dev,
1458                              int shared_fd,
1459                              uint32_t *syncobj);
1460
1461 /**
1462  *  Export kernel sync object to a sync_file.
1463  *
1464  * \param   dev        - \c [in] device handle
1465  * \param   syncobj    - \c [in] sync object handle
1466  * \param   sync_file_fd - \c [out] sync_file file descriptor.
1467  *
1468  * \return   0 on success\n
1469  *          <0 - Negative POSIX Error code
1470  *
1471  */
1472 int amdgpu_cs_syncobj_export_sync_file(amdgpu_device_handle dev,
1473                                        uint32_t syncobj,
1474                                        int *sync_file_fd);
1475
1476 /**
1477  *  Import kernel sync object from a sync_file.
1478  *
1479  * \param   dev        - \c [in] device handle
1480  * \param   syncobj    - \c [in] sync object handle
1481  * \param   sync_file_fd - \c [in] sync_file file descriptor.
1482  *
1483  * \return   0 on success\n
1484  *          <0 - Negative POSIX Error code
1485  *
1486  */
1487 int amdgpu_cs_syncobj_import_sync_file(amdgpu_device_handle dev,
1488                                        uint32_t syncobj,
1489                                        int sync_file_fd);
1490
1491 /**
1492  * Export an amdgpu fence as a handle (syncobj or fd).
1493  *
1494  * \param what          AMDGPU_FENCE_TO_HANDLE_GET_{SYNCOBJ, FD}
1495  * \param out_handle    returned handle
1496  *
1497  * \return   0 on success\n
1498  *          <0 - Negative POSIX Error code
1499  */
1500 int amdgpu_cs_fence_to_handle(amdgpu_device_handle dev,
1501                               struct amdgpu_cs_fence *fence,
1502                               uint32_t what,
1503                               uint32_t *out_handle);
1504
1505 /**
1506  *  Submit raw command submission to kernel
1507  *
1508  * \param   dev        - \c [in] device handle
1509  * \param   context    - \c [in] context handle for context id
1510  * \param   bo_list_handle - \c [in] request bo list handle (0 for none)
1511  * \param   num_chunks - \c [in] number of CS chunks to submit
1512  * \param   chunks     - \c [in] array of CS chunks
1513  * \param   seq_no     - \c [out] output sequence number for submission.
1514  *
1515  * \return   0 on success\n
1516  *          <0 - Negative POSIX Error code
1517  *
1518  */
1519 struct drm_amdgpu_cs_chunk;
1520 struct drm_amdgpu_cs_chunk_dep;
1521 struct drm_amdgpu_cs_chunk_data;
1522
1523 int amdgpu_cs_submit_raw(amdgpu_device_handle dev,
1524                          amdgpu_context_handle context,
1525                          amdgpu_bo_list_handle bo_list_handle,
1526                          int num_chunks,
1527                          struct drm_amdgpu_cs_chunk *chunks,
1528                          uint64_t *seq_no);
1529
1530 void amdgpu_cs_chunk_fence_to_dep(struct amdgpu_cs_fence *fence,
1531                                   struct drm_amdgpu_cs_chunk_dep *dep);
1532 void amdgpu_cs_chunk_fence_info_to_data(struct amdgpu_cs_fence_info *fence_info,
1533                                         struct drm_amdgpu_cs_chunk_data *data);
1534
1535 /**
1536  * Reserve VMID
1537  * \param   context - \c [in]  GPU Context
1538  * \param   flags - \c [in]  TBD
1539  *
1540  * \return  0 on success otherwise POSIX Error code
1541 */
1542 int amdgpu_vm_reserve_vmid(amdgpu_device_handle dev, uint32_t flags);
1543
1544 /**
1545  * Free reserved VMID
1546  * \param   context - \c [in]  GPU Context
1547  * \param   flags - \c [in]  TBD
1548  *
1549  * \return  0 on success otherwise POSIX Error code
1550 */
1551 int amdgpu_vm_unreserve_vmid(amdgpu_device_handle dev, uint32_t flags);
1552
1553 #ifdef __cplusplus
1554 }
1555 #endif
1556 #endif /* #ifdef _AMDGPU_H_ */