OSDN Git Service

amdgpu: add missing extern "C" headers
[android-x86/external-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   context - \c [out] GPU Context handle
803  *
804  * \return   0 on success\n
805  *          <0 - Negative POSIX Error code
806  *
807  * \sa amdgpu_cs_ctx_free()
808  *
809 */
810 int amdgpu_cs_ctx_create(amdgpu_device_handle dev,
811                          amdgpu_context_handle *context);
812
813 /**
814  *
815  * Destroy GPU execution context when not needed any more
816  *
817  * \param   context - \c [in] GPU Context handle
818  *
819  * \return   0 on success\n
820  *          <0 - Negative POSIX Error code
821  *
822  * \sa amdgpu_cs_ctx_create()
823  *
824 */
825 int amdgpu_cs_ctx_free(amdgpu_context_handle context);
826
827 /**
828  * Query reset state for the specific GPU Context
829  *
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.
833  *
834  * \return   0 on success\n
835  *          <0 - Negative POSIX Error code
836  *
837  * \sa amdgpu_cs_ctx_create()
838  *
839 */
840 int amdgpu_cs_query_reset_state(amdgpu_context_handle context,
841                                 uint32_t *state, uint32_t *hangs);
842
843 /*
844  * Command Buffers Management
845  *
846 */
847
848 /**
849  * Send request to submit command buffers to hardware.
850  *
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
855  * order.
856  *
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.
860  *
861  *
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
869  *                                        'atomic' operation
870  * \param   number_of_requests - \c [in]  Number of submission requests
871  *
872  * \return   0 on success\n
873  *          <0 - Negative POSIX Error code
874  *
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.
879  *
880  * \sa amdgpu_command_buffer_alloc(), amdgpu_command_buffer_free(),
881  *     amdgpu_cs_query_fence_status()
882  *
883 */
884 int amdgpu_cs_submit(amdgpu_context_handle context,
885                      uint64_t flags,
886                      struct amdgpu_cs_request *ibs_request,
887                      uint32_t number_of_requests);
888
889 /**
890  *  Query status of Command Buffer Submission
891  *
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
897  *                              !0 - otherwise
898  *
899  * \return   0 on success\n
900  *          <0 - Negative POSIX Error code
901  *
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
905  *       code.
906  *
907  * \sa amdgpu_cs_submit()
908 */
909 int amdgpu_cs_query_fence_status(struct amdgpu_cs_fence *fence,
910                                  uint64_t timeout_ns,
911                                  uint64_t flags,
912                                  uint32_t *expired);
913
914 /**
915  *  Wait for multiple fences
916  *
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
924  *
925  * \return  0 on success
926  *          <0 - Negative POSIX Error code
927  *
928  * \note    Currently it supports only one amdgpu_device. All fences come from
929  *          the same amdgpu_device with the same fd.
930 */
931 int amdgpu_cs_wait_fences(struct amdgpu_cs_fence *fences,
932                           uint32_t fence_count,
933                           bool wait_all,
934                           uint64_t timeout_ns,
935                           uint32_t *status, uint32_t *first);
936
937 /*
938  * Query / Info API
939  *
940 */
941
942 /**
943  * Query allocation size alignments
944  *
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.
948  *
949  * \param   dev  - \c [in] Device handle. See #amdgpu_device_initialize()
950  * \param   info - \c [out] Pointer to structure to get size alignment
951  *                        requirements
952  *
953  * \return   0 on success\n
954  *          <0 - Negative POSIX Error code
955  *
956 */
957 int amdgpu_query_buffer_size_alignment(amdgpu_device_handle dev,
958                                        struct amdgpu_buffer_size_alignments
959                                                 *info);
960
961 /**
962  * Query firmware versions
963  *
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
970  *
971  * \return   0 on success\n
972  *          <0 - Negative POSIX Error code
973  *
974 */
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);
978
979 /**
980  * Query the number of HW IP instances of a certain type.
981  *
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
985  *
986  * \return   0 on success\n
987  *          <0 - Negative POSIX Error code
988 */
989 int amdgpu_query_hw_ip_count(amdgpu_device_handle dev, unsigned type,
990                              uint32_t *count);
991
992 /**
993  * Query engine information
994  *
995  * This query allows UMD to query information different engines and their
996  * capabilities.
997  *
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
1002  *
1003  * \return   0 on success\n
1004  *          <0 - Negative POSIX Error code
1005 */
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);
1009
1010 /**
1011  * Query heap information
1012  *
1013  * This query allows UMD to query potentially available memory resources and
1014  * adjust their logic if necessary.
1015  *
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
1019  *
1020  * \return   0 on success\n
1021  *          <0 - Negative POSIX Error code
1022  *
1023 */
1024 int amdgpu_query_heap_info(amdgpu_device_handle dev, uint32_t heap,
1025                            uint32_t flags, struct amdgpu_heap_info *info);
1026
1027 /**
1028  * Get the CRTC ID from the mode object ID
1029  *
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
1033  *
1034  * \return   0 on success\n
1035  *          <0 - Negative POSIX Error code
1036  *
1037 */
1038 int amdgpu_query_crtc_from_id(amdgpu_device_handle dev, unsigned id,
1039                               int32_t *result);
1040
1041 /**
1042  * Query GPU H/w Info
1043  *
1044  * Query hardware specific information
1045  *
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
1049  *
1050  * \return   0 on success\n
1051  *          <0 - Negative POSIX Error code
1052  *
1053 */
1054 int amdgpu_query_gpu_info(amdgpu_device_handle dev,
1055                            struct amdgpu_gpu_info *info);
1056
1057 /**
1058  * Query hardware or driver information.
1059  *
1060  * The return size is query-specific and depends on the "info_id" parameter.
1061  * No more than "size" bytes is returned.
1062  *
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.
1067  *
1068  * \return   0 on success\n
1069  *          <0 - Negative POSIX error code
1070  *
1071 */
1072 int amdgpu_query_info(amdgpu_device_handle dev, unsigned info_id,
1073                       unsigned size, void *value);
1074
1075 /**
1076  * Query information about GDS
1077  *
1078  * \param   dev      - \c [in] Device handle. See #amdgpu_device_initialize()
1079  * \param   gds_info - \c [out] Pointer to structure to get GDS information
1080  *
1081  * \return   0 on success\n
1082  *          <0 - Negative POSIX Error code
1083  *
1084 */
1085 int amdgpu_query_gds_info(amdgpu_device_handle dev,
1086                         struct amdgpu_gds_resource_info *gds_info);
1087
1088 /**
1089  * Query information about sensor.
1090  *
1091  * The return size is query-specific and depends on the "sensor_type"
1092  * parameter. No more than "size" bytes is returned.
1093  *
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.
1098  *
1099  * \return   0 on success\n
1100  *          <0 - Negative POSIX Error code
1101  *
1102 */
1103 int amdgpu_query_sensor_info(amdgpu_device_handle dev, unsigned sensor_type,
1104                              unsigned size, void *value);
1105
1106 /**
1107  * Read a set of consecutive memory-mapped registers.
1108  * Not all registers are allowed to be read by userspace.
1109  *
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
1113  *                                 from the offset
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.
1118  *
1119  * \return   0 on success\n
1120  *          <0 - Negative POSIX error code
1121  *
1122 */
1123 int amdgpu_read_mm_registers(amdgpu_device_handle dev, unsigned dword_offset,
1124                              unsigned count, uint32_t instance, uint32_t flags,
1125                              uint32_t *values);
1126
1127 /**
1128  * Flag to request VA address range in the 32bit address space
1129 */
1130 #define AMDGPU_VA_RANGE_32_BIT          0x1
1131
1132 /**
1133  * Allocate virtual address range
1134  *
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
1150  * by client.
1151  * \param va_range_handle - \c [out] On return: Handle assigned to allocation
1152  * \param flags - \c [in] flags for special VA range
1153  *
1154  * \return 0 on success\n
1155  * >0 - AMD specific error code\n
1156  * <0 - Negative POSIX Error code
1157  *
1158  * \notes \n
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.
1162  *
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
1165  * be used.
1166  *
1167 */
1168 int amdgpu_va_range_alloc(amdgpu_device_handle dev,
1169                            enum amdgpu_gpu_va_range va_range_type,
1170                            uint64_t size,
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,
1175                            uint64_t flags);
1176
1177 /**
1178  * Free previously allocated virtual address range
1179  *
1180  *
1181  * \param va_range_handle - \c [in] Handle assigned to VA allocation
1182  *
1183  * \return 0 on success\n
1184  * >0 - AMD specific error code\n
1185  * <0 - Negative POSIX Error code
1186  *
1187 */
1188 int amdgpu_va_range_free(amdgpu_va_handle va_range_handle);
1189
1190 /**
1191 * Query virtual address range
1192 *
1193 * UMD can query GPU VM range supported by each device
1194 * to initialize its own VAM accordingly.
1195 *
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
1200 *
1201 * \return   0 on success\n
1202 *          <0 - Negative POSIX Error code
1203 *
1204 */
1205
1206 int amdgpu_va_range_query(amdgpu_device_handle dev,
1207                           enum amdgpu_gpu_va_range type,
1208                           uint64_t *start,
1209                           uint64_t *end);
1210
1211 /**
1212  *  VA mapping/unmapping for the buffer object
1213  *
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
1220  *
1221  * \return   0 on success\n
1222  *          <0 - Negative POSIX Error code
1223  *
1224 */
1225
1226 int amdgpu_bo_va_op(amdgpu_bo_handle bo,
1227                     uint64_t offset,
1228                     uint64_t size,
1229                     uint64_t addr,
1230                     uint64_t flags,
1231                     uint32_t ops);
1232
1233 /**
1234  *  VA mapping/unmapping for a buffer object or PRT region.
1235  *
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.
1239  *
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
1247  *
1248  * \return   0 on success\n
1249  *          <0 - Negative POSIX Error code
1250  *
1251 */
1252
1253 int amdgpu_bo_va_op_raw(amdgpu_device_handle dev,
1254                         amdgpu_bo_handle bo,
1255                         uint64_t offset,
1256                         uint64_t size,
1257                         uint64_t addr,
1258                         uint64_t flags,
1259                         uint32_t ops);
1260
1261 /**
1262  *  create semaphore
1263  *
1264  * \param   sem    - \c [out] semaphore handle
1265  *
1266  * \return   0 on success\n
1267  *          <0 - Negative POSIX Error code
1268  *
1269 */
1270 int amdgpu_cs_create_semaphore(amdgpu_semaphore_handle *sem);
1271
1272 /**
1273  *  signal semaphore
1274  *
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
1280  *
1281  * \return   0 on success\n
1282  *          <0 - Negative POSIX Error code
1283  *
1284 */
1285 int amdgpu_cs_signal_semaphore(amdgpu_context_handle ctx,
1286                                uint32_t ip_type,
1287                                uint32_t ip_instance,
1288                                uint32_t ring,
1289                                amdgpu_semaphore_handle sem);
1290
1291 /**
1292  *  wait semaphore
1293  *
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
1299  *
1300  * \return   0 on success\n
1301  *          <0 - Negative POSIX Error code
1302  *
1303 */
1304 int amdgpu_cs_wait_semaphore(amdgpu_context_handle ctx,
1305                              uint32_t ip_type,
1306                              uint32_t ip_instance,
1307                              uint32_t ring,
1308                              amdgpu_semaphore_handle sem);
1309
1310 /**
1311  *  destroy semaphore
1312  *
1313  * \param   sem     - \c [in] semaphore handle
1314  *
1315  * \return   0 on success\n
1316  *          <0 - Negative POSIX Error code
1317  *
1318 */
1319 int amdgpu_cs_destroy_semaphore(amdgpu_semaphore_handle sem);
1320
1321 /**
1322  *  Get the ASIC marketing name
1323  *
1324  * \param   dev         - \c [in] Device handle. See #amdgpu_device_initialize()
1325  *
1326  * \return  the constant string of the marketing name
1327  *          "NULL" means the ASIC is not found
1328 */
1329 const char *amdgpu_get_marketing_name(amdgpu_device_handle dev);
1330
1331 #ifdef __cplusplus
1332 }
1333 #endif
1334
1335 #endif /* #ifdef _AMDGPU_H_ */