OSDN Git Service

amdgpu: use common fence structure for dependencies as well.
[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 struct drm_amdgpu_info_hw_ip;
41
42 /*--------------------------------------------------------------------------*/
43 /* --------------------------- Defines ------------------------------------ */
44 /*--------------------------------------------------------------------------*/
45
46 /**
47  * Define max. number of Command Buffers (IB) which could be sent to the single
48  * hardware IP to accommodate CE/DE requirements
49  *
50  * \sa amdgpu_cs_ib_info
51 */
52 #define AMDGPU_CS_MAX_IBS_PER_SUBMIT            4
53
54 /**
55  * Special timeout value meaning that the timeout is infinite.
56  */
57 #define AMDGPU_TIMEOUT_INFINITE                 0xffffffffffffffffull
58
59 /**
60  * Used in amdgpu_cs_query_fence_status(), meaning that the given timeout
61  * is absolute.
62  */
63 #define AMDGPU_QUERY_FENCE_TIMEOUT_IS_ABSOLUTE     (1 << 0)
64
65 /*--------------------------------------------------------------------------*/
66 /* ----------------------------- Enums ------------------------------------ */
67 /*--------------------------------------------------------------------------*/
68
69 /**
70  * Enum describing possible handle types
71  *
72  * \sa amdgpu_bo_import, amdgpu_bo_export
73  *
74 */
75 enum amdgpu_bo_handle_type {
76         /** GEM flink name (needs DRM authentication, used by DRI2) */
77         amdgpu_bo_handle_type_gem_flink_name = 0,
78
79         /** KMS handle which is used by all driver ioctls */
80         amdgpu_bo_handle_type_kms = 1,
81
82         /** DMA-buf fd handle */
83         amdgpu_bo_handle_type_dma_buf_fd = 2
84 };
85
86 /** Define known types of GPU VM VA ranges */
87 enum amdgpu_gpu_va_range
88 {
89         /** Allocate from "normal"/general range */
90         amdgpu_gpu_va_range_general = 0
91 };
92
93 /*--------------------------------------------------------------------------*/
94 /* -------------------------- Datatypes ----------------------------------- */
95 /*--------------------------------------------------------------------------*/
96
97 /**
98  * Define opaque pointer to context associated with fd.
99  * This context will be returned as the result of
100  * "initialize" function and should be pass as the first
101  * parameter to any API call
102  */
103 typedef struct amdgpu_device *amdgpu_device_handle;
104
105 /**
106  * Define GPU Context type as pointer to opaque structure
107  * Example of GPU Context is the "rendering" context associated
108  * with OpenGL context (glCreateContext)
109  */
110 typedef struct amdgpu_context *amdgpu_context_handle;
111
112 /**
113  * Define handle for amdgpu resources: buffer, GDS, etc.
114  */
115 typedef struct amdgpu_bo *amdgpu_bo_handle;
116
117 /**
118  * Define handle for list of BOs
119  */
120 typedef struct amdgpu_bo_list *amdgpu_bo_list_handle;
121
122 /**
123  * Define handle to be used to work with VA allocated ranges
124  */
125 typedef struct amdgpu_va *amdgpu_va_handle;
126
127 /*--------------------------------------------------------------------------*/
128 /* -------------------------- Structures ---------------------------------- */
129 /*--------------------------------------------------------------------------*/
130
131 /**
132  * Structure describing memory allocation request
133  *
134  * \sa amdgpu_bo_alloc()
135  *
136 */
137 struct amdgpu_bo_alloc_request {
138         /** Allocation request. It must be aligned correctly. */
139         uint64_t alloc_size;
140
141         /**
142          * It may be required to have some specific alignment requirements
143          * for physical back-up storage (e.g. for displayable surface).
144          * If 0 there is no special alignment requirement
145          */
146         uint64_t phys_alignment;
147
148         /**
149          * UMD should specify where to allocate memory and how it
150          * will be accessed by the CPU.
151          */
152         uint32_t preferred_heap;
153
154         /** Additional flags passed on allocation */
155         uint64_t flags;
156 };
157
158 /**
159  * Structure describing memory allocation request
160  *
161  * \sa amdgpu_bo_alloc()
162 */
163 struct amdgpu_bo_alloc_result {
164         /** Assigned virtual MC Base Address */
165         uint64_t virtual_mc_base_address;
166
167         /** Handle of allocated memory to be used by the given process only. */
168         amdgpu_bo_handle buf_handle;
169 };
170
171 /**
172  * Special UMD specific information associated with buffer.
173  *
174  * It may be need to pass some buffer charactersitic as part
175  * of buffer sharing. Such information are defined UMD and
176  * opaque for libdrm_amdgpu as well for kernel driver.
177  *
178  * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info,
179  *     amdgpu_bo_import(), amdgpu_bo_export
180  *
181 */
182 struct amdgpu_bo_metadata {
183         /** Special flag associated with surface */
184         uint64_t flags;
185
186         /**
187          * ASIC-specific tiling information (also used by DCE).
188          * The encoding is defined by the AMDGPU_TILING_* definitions.
189          */
190         uint64_t tiling_info;
191
192         /** Size of metadata associated with the buffer, in bytes. */
193         uint32_t size_metadata;
194
195         /** UMD specific metadata. Opaque for kernel */
196         uint32_t umd_metadata[64];
197 };
198
199 /**
200  * Structure describing allocated buffer. Client may need
201  * to query such information as part of 'sharing' buffers mechanism
202  *
203  * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info(),
204  *     amdgpu_bo_import(), amdgpu_bo_export()
205 */
206 struct amdgpu_bo_info {
207         /** Allocated memory size */
208         uint64_t alloc_size;
209
210         /**
211          * It may be required to have some specific alignment requirements
212          * for physical back-up storage.
213          */
214         uint64_t phys_alignment;
215
216         /**
217          * Assigned virtual MC Base Address.
218          * \note  This information will be returned only if this buffer was
219          * allocated in the same process otherwise 0 will be returned.
220         */
221         uint64_t virtual_mc_base_address;
222
223         /** Heap where to allocate memory. */
224         uint32_t preferred_heap;
225
226         /** Additional allocation flags. */
227         uint64_t alloc_flags;
228
229         /** Metadata associated with buffer if any. */
230         struct amdgpu_bo_metadata metadata;
231 };
232
233 /**
234  * Structure with information about "imported" buffer
235  *
236  * \sa amdgpu_bo_import()
237  *
238  */
239 struct amdgpu_bo_import_result {
240         /** Handle of memory/buffer to use */
241         amdgpu_bo_handle buf_handle;
242
243          /** Buffer size */
244         uint64_t alloc_size;
245
246          /** Assigned virtual MC Base Address */
247         uint64_t virtual_mc_base_address;
248 };
249
250 /**
251  *
252  * Structure to describe GDS partitioning information.
253  * \note OA and GWS resources are asscoiated with GDS partition
254  *
255  * \sa amdgpu_gpu_resource_query_gds_info
256  *
257 */
258 struct amdgpu_gds_resource_info {
259         uint32_t gds_gfx_partition_size;
260         uint32_t compute_partition_size;
261         uint32_t gds_total_size;
262         uint32_t gws_per_gfx_partition;
263         uint32_t gws_per_compute_partition;
264         uint32_t oa_per_gfx_partition;
265         uint32_t oa_per_compute_partition;
266 };
267
268 /**
269  * Structure describing CS fence
270  *
271  * \sa amdgpu_cs_query_fence_status(), amdgpu_cs_request, amdgpu_cs_submit()
272  *
273 */
274 struct amdgpu_cs_fence {
275
276         /** In which context IB was sent to execution */
277         amdgpu_context_handle context;
278
279         /** To which HW IP type the fence belongs */
280         uint32_t ip_type;
281
282         /** IP instance index if there are several IPs of the same type. */
283         uint32_t ip_instance;
284
285         /** Ring index of the HW IP */
286         uint32_t ring;
287
288         /** Specify fence for which we need to check submission status.*/
289         uint64_t fence;
290 };
291
292 /**
293  * Structure describing IB
294  *
295  * \sa amdgpu_cs_request, amdgpu_cs_submit()
296  *
297 */
298 struct amdgpu_cs_ib_info {
299         /** Special flags */
300         uint64_t flags;
301
302         /** Virtual MC address of the command buffer */
303         uint64_t ib_mc_address;
304
305         /**
306          * Size of Command Buffer to be submitted.
307          *   - The size is in units of dwords (4 bytes).
308          *   - Could be 0
309          */
310         uint32_t size;
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 /**
363  * Structure which provide information about GPU VM MC Address space
364  * alignments requirements
365  *
366  * \sa amdgpu_query_buffer_size_alignment
367  */
368 struct amdgpu_buffer_size_alignments {
369         /** Size alignment requirement for allocation in
370          * local memory */
371         uint64_t size_local;
372
373         /**
374          * Size alignment requirement for allocation in remote memory
375          */
376         uint64_t size_remote;
377 };
378
379 /**
380  * Structure which provide information about heap
381  *
382  * \sa amdgpu_query_heap_info()
383  *
384  */
385 struct amdgpu_heap_info {
386         /** Theoretical max. available memory in the given heap */
387         uint64_t heap_size;
388
389         /**
390          * Number of bytes allocated in the heap. This includes all processes
391          * and private allocations in the kernel. It changes when new buffers
392          * are allocated, freed, and moved. It cannot be larger than
393          * heap_size.
394          */
395         uint64_t heap_usage;
396
397         /**
398          * Theoretical possible max. size of buffer which
399          * could be allocated in the given heap
400          */
401         uint64_t max_allocation;
402 };
403
404 /**
405  * Describe GPU h/w info needed for UMD correct initialization
406  *
407  * \sa amdgpu_query_gpu_info()
408 */
409 struct amdgpu_gpu_info {
410         /** Asic id */
411         uint32_t asic_id;
412         /** Chip revision */
413         uint32_t chip_rev;
414         /** Chip external revision */
415         uint32_t chip_external_rev;
416         /** Family ID */
417         uint32_t family_id;
418         /** Special flags */
419         uint64_t ids_flags;
420         /** max engine clock*/
421         uint64_t max_engine_clk;
422         /** max memory clock */
423         uint64_t max_memory_clk;
424         /** number of shader engines */
425         uint32_t num_shader_engines;
426         /** number of shader arrays per engine */
427         uint32_t num_shader_arrays_per_engine;
428         /**  Number of available good shader pipes */
429         uint32_t avail_quad_shader_pipes;
430         /**  Max. number of shader pipes.(including good and bad pipes  */
431         uint32_t max_quad_shader_pipes;
432         /** Number of parameter cache entries per shader quad pipe */
433         uint32_t cache_entries_per_quad_pipe;
434         /**  Number of available graphics context */
435         uint32_t num_hw_gfx_contexts;
436         /** Number of render backend pipes */
437         uint32_t rb_pipes;
438         /**  Enabled render backend pipe mask */
439         uint32_t enabled_rb_pipes_mask;
440         /** Frequency of GPU Counter */
441         uint32_t gpu_counter_freq;
442         /** CC_RB_BACKEND_DISABLE.BACKEND_DISABLE per SE */
443         uint32_t backend_disable[4];
444         /** Value of MC_ARB_RAMCFG register*/
445         uint32_t mc_arb_ramcfg;
446         /** Value of GB_ADDR_CONFIG */
447         uint32_t gb_addr_cfg;
448         /** Values of the GB_TILE_MODE0..31 registers */
449         uint32_t gb_tile_mode[32];
450         /** Values of GB_MACROTILE_MODE0..15 registers */
451         uint32_t gb_macro_tile_mode[16];
452         /** Value of PA_SC_RASTER_CONFIG register per SE */
453         uint32_t pa_sc_raster_cfg[4];
454         /** Value of PA_SC_RASTER_CONFIG_1 register per SE */
455         uint32_t pa_sc_raster_cfg1[4];
456         /* CU info */
457         uint32_t cu_active_number;
458         uint32_t cu_ao_mask;
459         uint32_t cu_bitmap[4][4];
460         /* video memory type info*/
461         uint32_t vram_type;
462         /* video memory bit width*/
463         uint32_t vram_bit_width;
464         /** constant engine ram size*/
465         uint32_t ce_ram_size;
466 };
467
468
469 /*--------------------------------------------------------------------------*/
470 /*------------------------- Functions --------------------------------------*/
471 /*--------------------------------------------------------------------------*/
472
473 /*
474  * Initialization / Cleanup
475  *
476 */
477
478 /**
479  *
480  * \param   fd            - \c [in]  File descriptor for AMD GPU device
481  *                                   received previously as the result of
482  *                                   e.g. drmOpen() call.
483  *                                   For legacy fd type, the DRI2/DRI3
484  *                                   authentication should be done before
485  *                                   calling this function.
486  * \param   major_version - \c [out] Major version of library. It is assumed
487  *                                   that adding new functionality will cause
488  *                                   increase in major version
489  * \param   minor_version - \c [out] Minor version of library
490  * \param   device_handle - \c [out] Pointer to opaque context which should
491  *                                   be passed as the first parameter on each
492  *                                   API call
493  *
494  *
495  * \return   0 on success\n
496  *          <0 - Negative POSIX Error code
497  *
498  *
499  * \sa amdgpu_device_deinitialize()
500 */
501 int amdgpu_device_initialize(int fd,
502                              uint32_t *major_version,
503                              uint32_t *minor_version,
504                              amdgpu_device_handle *device_handle);
505
506 /**
507  *
508  * When access to such library does not needed any more the special
509  * function must be call giving opportunity to clean up any
510  * resources if needed.
511  *
512  * \param   device_handle - \c [in]  Context associated with file
513  *                                   descriptor for AMD GPU device
514  *                                   received previously as the
515  *                                   result e.g. of drmOpen() call.
516  *
517  * \return  0 on success\n
518  *         <0 - Negative POSIX Error code
519  *
520  * \sa amdgpu_device_initialize()
521  *
522 */
523 int amdgpu_device_deinitialize(amdgpu_device_handle device_handle);
524
525 /*
526  * Memory Management
527  *
528 */
529
530 /**
531  * Allocate memory to be used by UMD for GPU related operations
532  *
533  * \param   dev          - \c [in] Device handle.
534  *                                 See #amdgpu_device_initialize()
535  * \param   alloc_buffer - \c [in] Pointer to the structure describing an
536  *                                 allocation request
537  * \param   info         - \c [out] Pointer to structure which return
538  *                                  information about allocated memory
539  *
540  * \return   0 on success\n
541  *          <0 - Negative POSIX Error code
542  *
543  * \sa amdgpu_bo_free()
544 */
545 int amdgpu_bo_alloc(amdgpu_device_handle dev,
546                     struct amdgpu_bo_alloc_request *alloc_buffer,
547                     struct amdgpu_bo_alloc_result *info);
548
549 /**
550  * Associate opaque data with buffer to be queried by another UMD
551  *
552  * \param   dev        - \c [in] Device handle. See #amdgpu_device_initialize()
553  * \param   buf_handle - \c [in] Buffer handle
554  * \param   info       - \c [in] Metadata to associated with buffer
555  *
556  * \return   0 on success\n
557  *          <0 - Negative POSIX Error code
558 */
559 int amdgpu_bo_set_metadata(amdgpu_bo_handle buf_handle,
560                            struct amdgpu_bo_metadata *info);
561
562 /**
563  * Query buffer information including metadata previusly associated with
564  * buffer.
565  *
566  * \param   dev        - \c [in] Device handle.
567  *                               See #amdgpu_device_initialize()
568  * \param   buf_handle - \c [in]   Buffer handle
569  * \param   info       - \c [out]  Structure describing buffer
570  *
571  * \return   0 on success\n
572  *          <0 - Negative POSIX Error code
573  *
574  * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc()
575 */
576 int amdgpu_bo_query_info(amdgpu_bo_handle buf_handle,
577                          struct amdgpu_bo_info *info);
578
579 /**
580  * Allow others to get access to buffer
581  *
582  * \param   dev           - \c [in] Device handle.
583  *                                  See #amdgpu_device_initialize()
584  * \param   buf_handle    - \c [in] Buffer handle
585  * \param   type          - \c [in] Type of handle requested
586  * \param   shared_handle - \c [out] Special "shared" handle
587  *
588  * \return   0 on success\n
589  *          <0 - Negative POSIX Error code
590  *
591  * \sa amdgpu_bo_import()
592  *
593 */
594 int amdgpu_bo_export(amdgpu_bo_handle buf_handle,
595                      enum amdgpu_bo_handle_type type,
596                      uint32_t *shared_handle);
597
598 /**
599  * Request access to "shared" buffer
600  *
601  * \param   dev           - \c [in] Device handle.
602  *                                  See #amdgpu_device_initialize()
603  * \param   type          - \c [in] Type of handle requested
604  * \param   shared_handle - \c [in] Shared handle received as result "import"
605  *                                   operation
606  * \param   output        - \c [out] Pointer to structure with information
607  *                                   about imported buffer
608  *
609  * \return   0 on success\n
610  *          <0 - Negative POSIX Error code
611  *
612  * \note  Buffer must be "imported" only using new "fd" (different from
613  *        one used by "exporter").
614  *
615  * \sa amdgpu_bo_export()
616  *
617 */
618 int amdgpu_bo_import(amdgpu_device_handle dev,
619                      enum amdgpu_bo_handle_type type,
620                      uint32_t shared_handle,
621                      struct amdgpu_bo_import_result *output);
622
623 /**
624  * Request GPU access to user allocated memory e.g. via "malloc"
625  *
626  * \param dev - [in] Device handle. See #amdgpu_device_initialize()
627  * \param cpu - [in] CPU address of user allocated memory which we
628  * want to map to GPU address space (make GPU accessible)
629  * (This address must be correctly aligned).
630  * \param size - [in] Size of allocation (must be correctly aligned)
631  * \param amdgpu_bo_alloc_result - [out] Handle of allocation to be passed as
632  * resource on submission and be used in other operations.
633  *
634  *
635  * \return   0 on success\n
636  *          <0 - Negative POSIX Error code
637  *
638  * \note
639  * This call doesn't guarantee that such memory will be persistently
640  * "locked" / make non-pageable. The purpose of this call is to provide
641  * opportunity for GPU get access to this resource during submission.
642  *
643  * The maximum amount of memory which could be mapped in this call depends
644  * if overcommit is disabled or not. If overcommit is disabled than the max.
645  * amount of memory to be pinned will be limited by left "free" size in total
646  * amount of memory which could be locked simultaneously ("GART" size).
647  *
648  * Supported (theoretical) max. size of mapping is restricted only by
649  * "GART" size.
650  *
651  * It is responsibility of caller to correctly specify access rights
652  * on VA assignment.
653 */
654 int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev,
655                                     void *cpu, uint64_t size,
656                                     struct amdgpu_bo_alloc_result *info);
657
658 /**
659  * Free previosuly allocated memory
660  *
661  * \param   dev        - \c [in] Device handle. See #amdgpu_device_initialize()
662  * \param   buf_handle - \c [in]  Buffer handle to free
663  *
664  * \return   0 on success\n
665  *          <0 - Negative POSIX Error code
666  *
667  * \note In the case of memory shared between different applications all
668  *       resources will be “physically” freed only all such applications
669  *       will be terminated
670  * \note If is UMD responsibility to ‘free’ buffer only when there is no
671  *       more GPU access
672  *
673  * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc()
674  *
675 */
676 int amdgpu_bo_free(amdgpu_bo_handle buf_handle);
677
678 /**
679  * Request CPU access to GPU accessable memory
680  *
681  * \param   buf_handle - \c [in] Buffer handle
682  * \param   cpu        - \c [out] CPU address to be used for access
683  *
684  * \return   0 on success\n
685  *          <0 - Negative POSIX Error code
686  *
687  * \sa amdgpu_bo_cpu_unmap()
688  *
689 */
690 int amdgpu_bo_cpu_map(amdgpu_bo_handle buf_handle, void **cpu);
691
692 /**
693  * Release CPU access to GPU memory
694  *
695  * \param   buf_handle  - \c [in] Buffer handle
696  *
697  * \return   0 on success\n
698  *          <0 - Negative POSIX Error code
699  *
700  * \sa amdgpu_bo_cpu_map()
701  *
702 */
703 int amdgpu_bo_cpu_unmap(amdgpu_bo_handle buf_handle);
704
705 /**
706  * Wait until a buffer is not used by the device.
707  *
708  * \param   dev           - \c [in] Device handle. See #amdgpu_lib_initialize()
709  * \param   buf_handle    - \c [in] Buffer handle.
710  * \param   timeout_ns    - Timeout in nanoseconds.
711  * \param   buffer_busy   - 0 if buffer is idle, all GPU access was completed
712  *                            and no GPU access is scheduled.
713  *                          1 GPU access is in fly or scheduled
714  *
715  * \return   0 - on success
716  *          <0 - Negative POSIX Error code
717  */
718 int amdgpu_bo_wait_for_idle(amdgpu_bo_handle buf_handle,
719                             uint64_t timeout_ns,
720                             bool *buffer_busy);
721
722 /**
723  * Creates a BO list handle for command submission.
724  *
725  * \param   dev                 - \c [in] Device handle.
726  *                                 See #amdgpu_device_initialize()
727  * \param   number_of_resources - \c [in] Number of BOs in the list
728  * \param   resources           - \c [in] List of BO handles
729  * \param   resource_prios      - \c [in] Optional priority for each handle
730  * \param   result              - \c [out] Created BO list handle
731  *
732  * \return   0 on success\n
733  *          <0 - Negative POSIX Error code
734  *
735  * \sa amdgpu_bo_list_destroy()
736 */
737 int amdgpu_bo_list_create(amdgpu_device_handle dev,
738                           uint32_t number_of_resources,
739                           amdgpu_bo_handle *resources,
740                           uint8_t *resource_prios,
741                           amdgpu_bo_list_handle *result);
742
743 /**
744  * Destroys a BO list handle.
745  *
746  * \param   handle      - \c [in] BO list handle.
747  *
748  * \return   0 on success\n
749  *          <0 - Negative POSIX Error code
750  *
751  * \sa amdgpu_bo_list_create()
752 */
753 int amdgpu_bo_list_destroy(amdgpu_bo_list_handle handle);
754
755 /**
756  * Update resources for existing BO list
757  *
758  * \param   handle              - \c [in] BO list handle
759  * \param   number_of_resources - \c [in] Number of BOs in the list
760  * \param   resources           - \c [in] List of BO handles
761  * \param   resource_prios      - \c [in] Optional priority for each handle
762  *
763  * \return   0 on success\n
764  *          <0 - Negative POSIX Error code
765  *
766  * \sa amdgpu_bo_list_update()
767 */
768 int amdgpu_bo_list_update(amdgpu_bo_list_handle handle,
769                           uint32_t number_of_resources,
770                           amdgpu_bo_handle *resources,
771                           uint8_t *resource_prios);
772
773 /*
774  * GPU Execution context
775  *
776 */
777
778 /**
779  * Create GPU execution Context
780  *
781  * For the purpose of GPU Scheduler and GPU Robustness extensions it is
782  * necessary to have information/identify rendering/compute contexts.
783  * It also may be needed to associate some specific requirements with such
784  * contexts.  Kernel driver will guarantee that submission from the same
785  * context will always be executed in order (first come, first serve).
786  *
787  *
788  * \param   dev     - \c [in] Device handle. See #amdgpu_device_initialize()
789  * \param   context - \c [out] GPU Context handle
790  *
791  * \return   0 on success\n
792  *          <0 - Negative POSIX Error code
793  *
794  * \sa amdgpu_cs_ctx_free()
795  *
796 */
797 int amdgpu_cs_ctx_create(amdgpu_device_handle dev,
798                          amdgpu_context_handle *context);
799
800 /**
801  *
802  * Destroy GPU execution context when not needed any more
803  *
804  * \param   context - \c [in] GPU Context handle
805  *
806  * \return   0 on success\n
807  *          <0 - Negative POSIX Error code
808  *
809  * \sa amdgpu_cs_ctx_create()
810  *
811 */
812 int amdgpu_cs_ctx_free(amdgpu_context_handle context);
813
814 /**
815  * Query reset state for the specific GPU Context
816  *
817  * \param   context - \c [in]  GPU Context handle
818  * \param   state   - \c [out] One of AMDGPU_CTX_*_RESET
819  * \param   hangs   - \c [out] Number of hangs caused by the context.
820  *
821  * \return   0 on success\n
822  *          <0 - Negative POSIX Error code
823  *
824  * \sa amdgpu_cs_ctx_create()
825  *
826 */
827 int amdgpu_cs_query_reset_state(amdgpu_context_handle context,
828                                 uint32_t *state, uint32_t *hangs);
829
830 /*
831  * Command Buffers Management
832  *
833 */
834
835 /**
836  * Send request to submit command buffers to hardware.
837  *
838  * Kernel driver could use GPU Scheduler to make decision when physically
839  * sent this request to the hardware. Accordingly this request could be put
840  * in queue and sent for execution later. The only guarantee is that request
841  * from the same GPU context to the same ip:ip_instance:ring will be executed in
842  * order.
843  *
844  *
845  * \param   dev                - \c [in]  Device handle.
846  *                                        See #amdgpu_device_initialize()
847  * \param   context            - \c [in]  GPU Context
848  * \param   flags              - \c [in]  Global submission flags
849  * \param   ibs_request        - \c [in]  Pointer to submission requests.
850  *                                        We could submit to the several
851  *                                        engines/rings simulteniously as
852  *                                        'atomic' operation
853  * \param   number_of_requests - \c [in]  Number of submission requests
854  * \param   fences             - \c [out] Pointer to array of data to get
855  *                                        fences to identify submission
856  *                                        requests. Timestamps are valid
857  *                                        in this GPU context and could be used
858  *                                        to identify/detect completion of
859  *                                        submission request
860  *
861  * \return   0 on success\n
862  *          <0 - Negative POSIX Error code
863  *
864  * \note It is required to pass correct resource list with buffer handles
865  *       which will be accessible by command buffers from submission
866  *       This will allow kernel driver to correctly implement "paging".
867  *       Failure to do so will have unpredictable results.
868  *
869  * \sa amdgpu_command_buffer_alloc(), amdgpu_command_buffer_free(),
870  *     amdgpu_cs_query_fence_status()
871  *
872 */
873 int amdgpu_cs_submit(amdgpu_context_handle context,
874                      uint64_t flags,
875                      struct amdgpu_cs_request *ibs_request,
876                      uint32_t number_of_requests,
877                      uint64_t *fences);
878
879 /**
880  *  Query status of Command Buffer Submission
881  *
882  * \param   fence   - \c [in] Structure describing fence to query
883  * \param   timeout_ns - \c [in] Timeout value to wait
884  * \param   flags   - \c [in] Flags for the query
885  * \param   expired - \c [out] If fence expired or not.\n
886  *                              0  – if fence is not expired\n
887  *                              !0 - otherwise
888  *
889  * \return   0 on success\n
890  *          <0 - Negative POSIX Error code
891  *
892  * \note If UMD wants only to check operation status and returned immediately
893  *       then timeout value as 0 must be passed. In this case success will be
894  *       returned in the case if submission was completed or timeout error
895  *       code.
896  *
897  * \sa amdgpu_cs_submit()
898 */
899 int amdgpu_cs_query_fence_status(struct amdgpu_cs_fence *fence,
900                                  uint64_t timeout_ns,
901                                  uint64_t flags,
902                                  uint32_t *expired);
903
904 /*
905  * Query / Info API
906  *
907 */
908
909 /**
910  * Query allocation size alignments
911  *
912  * UMD should query information about GPU VM MC size alignments requirements
913  * to be able correctly choose required allocation size and implement
914  * internal optimization if needed.
915  *
916  * \param   dev  - \c [in] Device handle. See #amdgpu_device_initialize()
917  * \param   info - \c [out] Pointer to structure to get size alignment
918  *                        requirements
919  *
920  * \return   0 on success\n
921  *          <0 - Negative POSIX Error code
922  *
923 */
924 int amdgpu_query_buffer_size_alignment(amdgpu_device_handle dev,
925                                        struct amdgpu_buffer_size_alignments
926                                                 *info);
927
928 /**
929  * Query firmware versions
930  *
931  * \param   dev         - \c [in] Device handle. See #amdgpu_device_initialize()
932  * \param   fw_type     - \c [in] AMDGPU_INFO_FW_*
933  * \param   ip_instance - \c [in] Index of the IP block of the same type.
934  * \param   index       - \c [in] Index of the engine. (for SDMA and MEC)
935  * \param   version     - \c [out] Pointer to to the "version" return value
936  * \param   feature     - \c [out] Pointer to to the "feature" return value
937  *
938  * \return   0 on success\n
939  *          <0 - Negative POSIX Error code
940  *
941 */
942 int amdgpu_query_firmware_version(amdgpu_device_handle dev, unsigned fw_type,
943                                   unsigned ip_instance, unsigned index,
944                                   uint32_t *version, uint32_t *feature);
945
946 /**
947  * Query the number of HW IP instances of a certain type.
948  *
949  * \param   dev      - \c [in] Device handle. See #amdgpu_device_initialize()
950  * \param   type     - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
951  * \param   count    - \c [out] Pointer to structure to get information
952  *
953  * \return   0 on success\n
954  *          <0 - Negative POSIX Error code
955 */
956 int amdgpu_query_hw_ip_count(amdgpu_device_handle dev, unsigned type,
957                              uint32_t *count);
958
959 /**
960  * Query engine information
961  *
962  * This query allows UMD to query information different engines and their
963  * capabilities.
964  *
965  * \param   dev         - \c [in] Device handle. See #amdgpu_device_initialize()
966  * \param   type        - \c [in] Hardware IP block type = AMDGPU_HW_IP_*
967  * \param   ip_instance - \c [in] Index of the IP block of the same type.
968  * \param   info        - \c [out] Pointer to structure to get information
969  *
970  * \return   0 on success\n
971  *          <0 - Negative POSIX Error code
972 */
973 int amdgpu_query_hw_ip_info(amdgpu_device_handle dev, unsigned type,
974                             unsigned ip_instance,
975                             struct drm_amdgpu_info_hw_ip *info);
976
977 /**
978  * Query heap information
979  *
980  * This query allows UMD to query potentially available memory resources and
981  * adjust their logic if necessary.
982  *
983  * \param   dev  - \c [in] Device handle. See #amdgpu_device_initialize()
984  * \param   heap - \c [in] Heap type
985  * \param   info - \c [in] Pointer to structure to get needed information
986  *
987  * \return   0 on success\n
988  *          <0 - Negative POSIX Error code
989  *
990 */
991 int amdgpu_query_heap_info(amdgpu_device_handle dev, uint32_t heap,
992                            uint32_t flags, struct amdgpu_heap_info *info);
993
994 /**
995  * Get the CRTC ID from the mode object ID
996  *
997  * \param   dev    - \c [in] Device handle. See #amdgpu_device_initialize()
998  * \param   id     - \c [in] Mode object ID
999  * \param   result - \c [in] Pointer to the CRTC ID
1000  *
1001  * \return   0 on success\n
1002  *          <0 - Negative POSIX Error code
1003  *
1004 */
1005 int amdgpu_query_crtc_from_id(amdgpu_device_handle dev, unsigned id,
1006                               int32_t *result);
1007
1008 /**
1009  * Query GPU H/w Info
1010  *
1011  * Query hardware specific information
1012  *
1013  * \param   dev  - \c [in] Device handle. See #amdgpu_device_initialize()
1014  * \param   heap - \c [in] Heap type
1015  * \param   info - \c [in] Pointer to structure to get needed information
1016  *
1017  * \return   0 on success\n
1018  *          <0 - Negative POSIX Error code
1019  *
1020 */
1021 int amdgpu_query_gpu_info(amdgpu_device_handle dev,
1022                            struct amdgpu_gpu_info *info);
1023
1024 /**
1025  * Query hardware or driver information.
1026  *
1027  * The return size is query-specific and depends on the "info_id" parameter.
1028  * No more than "size" bytes is returned.
1029  *
1030  * \param   dev     - \c [in] Device handle. See #amdgpu_device_initialize()
1031  * \param   info_id - \c [in] AMDGPU_INFO_*
1032  * \param   size    - \c [in] Size of the returned value.
1033  * \param   value   - \c [out] Pointer to the return value.
1034  *
1035  * \return   0 on success\n
1036  *          <0 - Negative POSIX error code
1037  *
1038 */
1039 int amdgpu_query_info(amdgpu_device_handle dev, unsigned info_id,
1040                       unsigned size, void *value);
1041
1042 /**
1043  * Query information about GDS
1044  *
1045  * \param   dev      - \c [in] Device handle. See #amdgpu_device_initialize()
1046  * \param   gds_info - \c [out] Pointer to structure to get GDS information
1047  *
1048  * \return   0 on success\n
1049  *          <0 - Negative POSIX Error code
1050  *
1051 */
1052 int amdgpu_query_gds_info(amdgpu_device_handle dev,
1053                         struct amdgpu_gds_resource_info *gds_info);
1054
1055 /**
1056  * Read a set of consecutive memory-mapped registers.
1057  * Not all registers are allowed to be read by userspace.
1058  *
1059  * \param   dev          - \c [in] Device handle. See #amdgpu_device_initialize(
1060  * \param   dword_offset - \c [in] Register offset in dwords
1061  * \param   count        - \c [in] The number of registers to read starting
1062  *                                 from the offset
1063  * \param   instance     - \c [in] GRBM_GFX_INDEX selector. It may have other
1064  *                                 uses. Set it to 0xffffffff if unsure.
1065  * \param   flags        - \c [in] Flags with additional information.
1066  * \param   values       - \c [out] The pointer to return values.
1067  *
1068  * \return   0 on success\n
1069  *          <0 - Negative POSIX error code
1070  *
1071 */
1072 int amdgpu_read_mm_registers(amdgpu_device_handle dev, unsigned dword_offset,
1073                              unsigned count, uint32_t instance, uint32_t flags,
1074                              uint32_t *values);
1075
1076 /**
1077  * Allocate virtual address range
1078  *
1079  * \param dev - [in] Device handle. See #amdgpu_device_initialize()
1080  * \param va_range_type - \c [in] Type of MC va range from which to allocate
1081  * \param size - \c [in] Size of range. Size must be correctly* aligned.
1082  * It is client responsibility to correctly aligned size based on the future
1083  * usage of allocated range.
1084  * \param va_base_alignment - \c [in] Overwrite base address alignment
1085  * requirement for GPU VM MC virtual
1086  * address assignment. Must be multiple of size alignments received as
1087  * 'amdgpu_buffer_size_alignments'.
1088  * If 0 use the default one.
1089  * \param va_base_required - \c [in] Specified required va base address.
1090  * If 0 then library choose available one.
1091  * If !0 value will be passed and those value already "in use" then
1092  * corresponding error status will be returned.
1093  * \param va_base_allocated - \c [out] On return: Allocated VA base to be used
1094  * by client.
1095  * \param va_range_handle - \c [out] On return: Handle assigned to allocation
1096  *
1097  * \return 0 on success\n
1098  * >0 - AMD specific error code\n
1099  * <0 - Negative POSIX Error code
1100  *
1101  * \notes \n
1102  * It is client responsibility to correctly handle VA assignments and usage.
1103  * Neither kernel driver nor libdrm_amdpgu are able to prevent and
1104  * detect wrong va assignemnt.
1105  *
1106  * It is client responsibility to correctly handle multi-GPU cases and to pass
1107  * the corresponding arrays of all devices handles where corresponding VA will
1108  * be used.
1109  *
1110 */
1111 int amdgpu_va_range_alloc(amdgpu_device_handle dev,
1112                            enum amdgpu_gpu_va_range va_range_type,
1113                            uint64_t size,
1114                            uint64_t va_base_alignment,
1115                            uint64_t va_base_required,
1116                            uint64_t *va_base_allocated,
1117                            amdgpu_va_handle *va_range_handle);
1118
1119 /**
1120  * Free previously allocated virtual address range
1121  *
1122  *
1123  * \param va_range_handle - \c [in] Handle assigned to VA allocation
1124  *
1125  * \return 0 on success\n
1126  * >0 - AMD specific error code\n
1127  * <0 - Negative POSIX Error code
1128  *
1129 */
1130 int amdgpu_va_range_free(amdgpu_va_handle va_range_handle);
1131
1132 /**
1133 * Query virtual address range
1134 *
1135 * UMD can query GPU VM range supported by each device
1136 * to initialize its own VAM accordingly.
1137 *
1138 * \param   dev    - [in] Device handle. See #amdgpu_device_initialize()
1139 * \param   type   - \c [in] Type of virtual address range
1140 * \param   offset - \c [out] Start offset of virtual address range
1141 * \param   size   - \c [out] Size of virtual address range
1142 *
1143 * \return   0 on success\n
1144 *          <0 - Negative POSIX Error code
1145 *
1146 */
1147
1148 int amdgpu_va_range_query(amdgpu_device_handle dev,
1149                           enum amdgpu_gpu_va_range type,
1150                           uint64_t *start,
1151                           uint64_t *end);
1152
1153 #endif /* #ifdef _AMDGPU_H_ */