OSDN Git Service

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