blob: c48af922a48305dee8a40153cbcd6e26f973e5d8 [file] [log] [blame]
Alex Deucher09361392015-04-20 12:04:22 -04001/*
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
40struct 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/**
Alex Deucher09361392015-04-20 12:04:22 -040060 * The special flag to mark that this IB will re-used
61 * by client and should not be automatically return back
62 * to free pool by libdrm_amdgpu when submission is completed.
63 *
64 * \sa amdgpu_cs_ib_info
65*/
66#define AMDGPU_CS_REUSE_IB 0x2
67
68/**
69 * The special resource flag for IB submission.
70 * When VRAM is full, some resources may be moved to GTT to make place
71 * for other resources which want to be in VRAM. This flag affects the order
72 * in which resources are moved back to VRAM until there is no space there.
73 * The resources with the highest priority will be moved first.
74 * The value can be between 0 and 15, inclusive.
75 */
76#define AMDGPU_IB_RESOURCE_PRIORITY(x) ((x) & 0xf)
77
78
79/*--------------------------------------------------------------------------*/
80/* ----------------------------- Enums ------------------------------------ */
81/*--------------------------------------------------------------------------*/
82
83/**
84 * Enum describing possible handle types
85 *
86 * \sa amdgpu_bo_import, amdgpu_bo_export
87 *
88*/
89enum amdgpu_bo_handle_type {
90 /** GEM flink name (needs DRM authentication, used by DRI2) */
91 amdgpu_bo_handle_type_gem_flink_name = 0,
92
93 /** KMS handle which is used by all driver ioctls */
94 amdgpu_bo_handle_type_kms = 1,
95
96 /** DMA-buf fd handle */
97 amdgpu_bo_handle_type_dma_buf_fd = 2
98};
99
100/**
Alex Deucher09361392015-04-20 12:04:22 -0400101 * For performance reasons and to simplify logic libdrm_amdgpu will handle
102 * IBs only some pre-defined sizes.
103 *
104 * \sa amdgpu_cs_alloc_ib()
105 */
106enum amdgpu_cs_ib_size {
107 amdgpu_cs_ib_size_4K = 1,
108 amdgpu_cs_ib_size_16K = 2,
109 amdgpu_cs_ib_size_32K = 3,
110 amdgpu_cs_ib_size_64K = 4,
111 amdgpu_cs_ib_size_128K = 5
112};
113
114/** The number of different IB sizes */
115#define AMDGPU_CS_IB_SIZE_NUM 6
116
117
118/*--------------------------------------------------------------------------*/
119/* -------------------------- Datatypes ----------------------------------- */
120/*--------------------------------------------------------------------------*/
121
122/**
123 * Define opaque pointer to context associated with fd.
124 * This context will be returned as the result of
125 * "initialize" function and should be pass as the first
126 * parameter to any API call
127 */
128typedef struct amdgpu_device *amdgpu_device_handle;
129
130/**
131 * Define GPU Context type as pointer to opaque structure
132 * Example of GPU Context is the "rendering" context associated
133 * with OpenGL context (glCreateContext)
134 */
135typedef struct amdgpu_context *amdgpu_context_handle;
136
137/**
138 * Define handle for amdgpu resources: buffer, GDS, etc.
139 */
140typedef struct amdgpu_bo *amdgpu_bo_handle;
141
142/**
Christian König6dc2eaf2015-04-22 14:52:34 +0200143 * Define handle for list of BOs
144 */
145typedef struct amdgpu_bo_list *amdgpu_bo_list_handle;
146
147/**
Alex Deucher09361392015-04-20 12:04:22 -0400148 * Define handle to be used when dealing with command
149 * buffers (a.k.a. ibs)
150 *
151 */
152typedef struct amdgpu_ib *amdgpu_ib_handle;
153
154
155/*--------------------------------------------------------------------------*/
156/* -------------------------- Structures ---------------------------------- */
157/*--------------------------------------------------------------------------*/
158
159/**
160 * Structure describing memory allocation request
161 *
162 * \sa amdgpu_bo_alloc()
163 *
164*/
165struct amdgpu_bo_alloc_request {
166 /** Allocation request. It must be aligned correctly. */
167 uint64_t alloc_size;
168
169 /**
170 * It may be required to have some specific alignment requirements
171 * for physical back-up storage (e.g. for displayable surface).
172 * If 0 there is no special alignment requirement
173 */
174 uint64_t phys_alignment;
175
176 /**
177 * UMD should specify where to allocate memory and how it
178 * will be accessed by the CPU.
179 */
180 uint32_t preferred_heap;
181
182 /** Additional flags passed on allocation */
183 uint64_t flags;
184};
185
186/**
187 * Structure describing memory allocation request
188 *
189 * \sa amdgpu_bo_alloc()
190*/
191struct amdgpu_bo_alloc_result {
192 /** Assigned virtual MC Base Address */
193 uint64_t virtual_mc_base_address;
194
195 /** Handle of allocated memory to be used by the given process only. */
196 amdgpu_bo_handle buf_handle;
197};
198
199/**
200 * Special UMD specific information associated with buffer.
201 *
202 * It may be need to pass some buffer charactersitic as part
203 * of buffer sharing. Such information are defined UMD and
204 * opaque for libdrm_amdgpu as well for kernel driver.
205 *
206 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info,
207 * amdgpu_bo_import(), amdgpu_bo_export
208 *
209*/
210struct amdgpu_bo_metadata {
211 /** Special flag associated with surface */
212 uint64_t flags;
213
214 /**
215 * ASIC-specific tiling information (also used by DCE).
216 * The encoding is defined by the AMDGPU_TILING_* definitions.
217 */
218 uint64_t tiling_info;
219
220 /** Size of metadata associated with the buffer, in bytes. */
221 uint32_t size_metadata;
222
223 /** UMD specific metadata. Opaque for kernel */
224 uint32_t umd_metadata[64];
225};
226
227/**
228 * Structure describing allocated buffer. Client may need
229 * to query such information as part of 'sharing' buffers mechanism
230 *
231 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info(),
232 * amdgpu_bo_import(), amdgpu_bo_export()
233*/
234struct amdgpu_bo_info {
235 /** Allocated memory size */
236 uint64_t alloc_size;
237
238 /**
239 * It may be required to have some specific alignment requirements
240 * for physical back-up storage.
241 */
242 uint64_t phys_alignment;
243
244 /**
245 * Assigned virtual MC Base Address.
246 * \note This information will be returned only if this buffer was
247 * allocated in the same process otherwise 0 will be returned.
248 */
249 uint64_t virtual_mc_base_address;
250
251 /** Heap where to allocate memory. */
252 uint32_t preferred_heap;
253
254 /** Additional allocation flags. */
255 uint64_t alloc_flags;
256
257 /** Metadata associated with buffer if any. */
258 struct amdgpu_bo_metadata metadata;
259};
260
261/**
262 * Structure with information about "imported" buffer
263 *
264 * \sa amdgpu_bo_import()
265 *
266 */
267struct amdgpu_bo_import_result {
268 /** Handle of memory/buffer to use */
269 amdgpu_bo_handle buf_handle;
270
271 /** Buffer size */
272 uint64_t alloc_size;
273
274 /** Assigned virtual MC Base Address */
275 uint64_t virtual_mc_base_address;
276};
277
278
279/**
280 *
281 * Structure to describe GDS partitioning information.
282 * \note OA and GWS resources are asscoiated with GDS partition
283 *
284 * \sa amdgpu_gpu_resource_query_gds_info
285 *
286*/
287struct amdgpu_gds_resource_info {
288 uint32_t gds_gfx_partition_size;
289 uint32_t compute_partition_size;
290 uint32_t gds_total_size;
291 uint32_t gws_per_gfx_partition;
292 uint32_t gws_per_compute_partition;
293 uint32_t oa_per_gfx_partition;
294 uint32_t oa_per_compute_partition;
295};
296
297
298
299/**
300 * Structure describing result of request to allocate GDS
301 *
302 * \sa amdgpu_gpu_resource_gds_alloc
303 *
304*/
305struct amdgpu_gds_alloc_info {
306 /** Handle assigned to gds allocation */
307 amdgpu_bo_handle resource_handle;
308
309 /** How much was really allocated */
310 uint32_t gds_memory_size;
311
312 /** Number of GWS resources allocated */
313 uint32_t gws;
314
315 /** Number of OA resources allocated */
316 uint32_t oa;
317};
318
319/**
320 * Structure to described allocated command buffer (a.k.a. IB)
321 *
322 * \sa amdgpu_cs_alloc_ib()
323 *
324*/
325struct amdgpu_cs_ib_alloc_result {
326 /** IB allocation handle */
327 amdgpu_ib_handle handle;
328
329 /** Assigned GPU VM MC Address of command buffer */
330 uint64_t mc_address;
331
332 /** Address to be used for CPU access */
333 void *cpu;
334};
335
336/**
337 * Structure describing IB
338 *
339 * \sa amdgpu_cs_request, amdgpu_cs_submit()
340 *
341*/
342struct amdgpu_cs_ib_info {
343 /** Special flags */
344 uint64_t flags;
345
346 /** Handle of command buffer */
347 amdgpu_ib_handle ib_handle;
348
349 /**
350 * Size of Command Buffer to be submitted.
351 * - The size is in units of dwords (4 bytes).
352 * - Must be less or equal to the size of allocated IB
353 * - Could be 0
354 */
355 uint32_t size;
356};
357
358/**
359 * Structure describing submission request
360 *
361 * \note We could have several IBs as packet. e.g. CE, CE, DE case for gfx
362 *
363 * \sa amdgpu_cs_submit()
364*/
365struct amdgpu_cs_request {
366 /** Specify flags with additional information */
367 uint64_t flags;
368
369 /** Specify HW IP block type to which to send the IB. */
370 unsigned ip_type;
371
372 /** IP instance index if there are several IPs of the same type. */
373 unsigned ip_instance;
374
375 /**
376 * Specify ring index of the IP. We could have several rings
377 * in the same IP. E.g. 0 for SDMA0 and 1 for SDMA1.
378 */
379 uint32_t ring;
380
381 /**
Christian König6dc2eaf2015-04-22 14:52:34 +0200382 * List handle with resources used by this request.
Alex Deucher09361392015-04-20 12:04:22 -0400383 */
Christian König6dc2eaf2015-04-22 14:52:34 +0200384 amdgpu_bo_list_handle resources;
Alex Deucher09361392015-04-20 12:04:22 -0400385
386 /** Number of IBs to submit in the field ibs. */
387 uint32_t number_of_ibs;
388
389 /**
390 * IBs to submit. Those IBs will be submit together as single entity
391 */
392 struct amdgpu_cs_ib_info *ibs;
393};
394
395/**
396 * Structure describing request to check submission state using fence
397 *
398 * \sa amdgpu_cs_query_fence_status()
399 *
400*/
401struct amdgpu_cs_query_fence {
402
403 /** In which context IB was sent to execution */
404 amdgpu_context_handle context;
405
406 /** Timeout in nanoseconds. */
407 uint64_t timeout_ns;
408
409 /** To which HW IP type the fence belongs */
410 unsigned ip_type;
411
412 /** IP instance index if there are several IPs of the same type. */
413 unsigned ip_instance;
414
415 /** Ring index of the HW IP */
416 uint32_t ring;
417
418 /** Flags */
419 uint64_t flags;
420
421 /** Specify fence for which we need to check
422 * submission status.*/
423 uint64_t fence;
424};
425
426/**
427 * Structure which provide information about GPU VM MC Address space
428 * alignments requirements
429 *
430 * \sa amdgpu_query_buffer_size_alignment
431 */
432struct amdgpu_buffer_size_alignments {
433 /** Size alignment requirement for allocation in
434 * local memory */
435 uint64_t size_local;
436
437 /**
438 * Size alignment requirement for allocation in remote memory
439 */
440 uint64_t size_remote;
441};
442
443
444/**
445 * Structure which provide information about heap
446 *
447 * \sa amdgpu_query_heap_info()
448 *
449 */
450struct amdgpu_heap_info {
451 /** Theoretical max. available memory in the given heap */
452 uint64_t heap_size;
453
454 /**
455 * Number of bytes allocated in the heap. This includes all processes
456 * and private allocations in the kernel. It changes when new buffers
457 * are allocated, freed, and moved. It cannot be larger than
458 * heap_size.
459 */
460 uint64_t heap_usage;
461
462 /**
463 * Theoretical possible max. size of buffer which
464 * could be allocated in the given heap
465 */
466 uint64_t max_allocation;
467};
468
469
470
471/**
472 * Describe GPU h/w info needed for UMD correct initialization
473 *
474 * \sa amdgpu_query_gpu_info()
475*/
476struct amdgpu_gpu_info {
477 /** Asic id */
478 uint32_t asic_id;
479 /**< Chip revision */
480 uint32_t chip_rev;
481 /** Chip external revision */
482 uint32_t chip_external_rev;
483 /** Family ID */
484 uint32_t family_id;
485 /** Special flags */
486 uint64_t ids_flags;
487 /** max engine clock*/
488 uint64_t max_engine_clk;
489 /** number of shader engines */
490 uint32_t num_shader_engines;
491 /** number of shader arrays per engine */
492 uint32_t num_shader_arrays_per_engine;
493 /** Number of available good shader pipes */
494 uint32_t avail_quad_shader_pipes;
495 /** Max. number of shader pipes.(including good and bad pipes */
496 uint32_t max_quad_shader_pipes;
497 /** Number of parameter cache entries per shader quad pipe */
498 uint32_t cache_entries_per_quad_pipe;
499 /** Number of available graphics context */
500 uint32_t num_hw_gfx_contexts;
501 /** Number of render backend pipes */
502 uint32_t rb_pipes;
Alex Deucher09361392015-04-20 12:04:22 -0400503 /** Enabled render backend pipe mask */
504 uint32_t enabled_rb_pipes_mask;
505 /** Frequency of GPU Counter */
506 uint32_t gpu_counter_freq;
507 /** CC_RB_BACKEND_DISABLE.BACKEND_DISABLE per SE */
508 uint32_t backend_disable[4];
509 /** Value of MC_ARB_RAMCFG register*/
510 uint32_t mc_arb_ramcfg;
511 /** Value of GB_ADDR_CONFIG */
512 uint32_t gb_addr_cfg;
513 /** Values of the GB_TILE_MODE0..31 registers */
514 uint32_t gb_tile_mode[32];
515 /** Values of GB_MACROTILE_MODE0..15 registers */
516 uint32_t gb_macro_tile_mode[16];
517 /** Value of PA_SC_RASTER_CONFIG register per SE */
518 uint32_t pa_sc_raster_cfg[4];
519 /** Value of PA_SC_RASTER_CONFIG_1 register per SE */
520 uint32_t pa_sc_raster_cfg1[4];
521 /* CU info */
522 uint32_t cu_active_number;
523 uint32_t cu_ao_mask;
524 uint32_t cu_bitmap[4][4];
525};
526
527
528/*--------------------------------------------------------------------------*/
529/*------------------------- Functions --------------------------------------*/
530/*--------------------------------------------------------------------------*/
531
532/*
533 * Initialization / Cleanup
534 *
535*/
536
537
538/**
539 *
540 * \param fd - \c [in] File descriptor for AMD GPU device
541 * received previously as the result of
542 * e.g. drmOpen() call.
543 * For legacy fd type, the DRI2/DRI3 authentication
544 * should be done before calling this function.
545 * \param major_version - \c [out] Major version of library. It is assumed
546 * that adding new functionality will cause
547 * increase in major version
548 * \param minor_version - \c [out] Minor version of library
549 * \param device_handle - \c [out] Pointer to opaque context which should
550 * be passed as the first parameter on each
551 * API call
552 *
553 *
554 * \return 0 on success\n
555 * >0 - AMD specific error code\n
556 * <0 - Negative POSIX Error code
557 *
558 *
559 * \sa amdgpu_device_deinitialize()
560*/
561int amdgpu_device_initialize(int fd,
562 uint32_t *major_version,
563 uint32_t *minor_version,
564 amdgpu_device_handle *device_handle);
565
566
567
568/**
569 *
570 * When access to such library does not needed any more the special
571 * function must be call giving opportunity to clean up any
572 * resources if needed.
573 *
574 * \param device_handle - \c [in] Context associated with file
575 * descriptor for AMD GPU device
576 * received previously as the
577 * result e.g. of drmOpen() call.
578 *
579 * \return 0 on success\n
580 * >0 - AMD specific error code\n
581 * <0 - Negative POSIX Error code
582 *
583 * \sa amdgpu_device_initialize()
584 *
585*/
586int amdgpu_device_deinitialize(amdgpu_device_handle device_handle);
587
588
589/*
590 * Memory Management
591 *
592*/
593
594/**
595 * Allocate memory to be used by UMD for GPU related operations
596 *
597 * \param dev - \c [in] Device handle.
598 * See #amdgpu_device_initialize()
599 * \param alloc_buffer - \c [in] Pointer to the structure describing an
600 * allocation request
601 * \param info - \c [out] Pointer to structure which return
602 * information about allocated memory
603 *
604 * \return 0 on success\n
605 * >0 - AMD specific error code\n
606 * <0 - Negative POSIX Error code
607 *
608 * \sa amdgpu_bo_free()
609*/
610int amdgpu_bo_alloc(amdgpu_device_handle dev,
611 struct amdgpu_bo_alloc_request *alloc_buffer,
612 struct amdgpu_bo_alloc_result *info);
613
614/**
615 * Associate opaque data with buffer to be queried by another UMD
616 *
617 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
618 * \param buf_handle - \c [in] Buffer handle
619 * \param info - \c [in] Metadata to associated with buffer
620 *
621 * \return 0 on success\n
622 * >0 - AMD specific error code\n
623 * <0 - Negative POSIX Error code
624*/
625int amdgpu_bo_set_metadata(amdgpu_bo_handle buf_handle,
626 struct amdgpu_bo_metadata *info);
627
628/**
629 * Query buffer information including metadata previusly associated with
630 * buffer.
631 *
632 * \param dev - \c [in] Device handle.
633 * See #amdgpu_device_initialize()
634 * \param buf_handle - \c [in] Buffer handle
635 * \param info - \c [out] Structure describing buffer
636 *
637 * \return 0 on success\n
638 * >0 - AMD specific error code\n
639 * <0 - Negative POSIX Error code
640 *
641 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc()
642*/
643int amdgpu_bo_query_info(amdgpu_bo_handle buf_handle,
644 struct amdgpu_bo_info *info);
645
646/**
647 * Allow others to get access to buffer
648 *
649 * \param dev - \c [in] Device handle.
650 * See #amdgpu_device_initialize()
651 * \param buf_handle - \c [in] Buffer handle
652 * \param type - \c [in] Type of handle requested
653 * \param shared_handle - \c [out] Special "shared" handle
654 *
655 * \return 0 on success\n
656 * >0 - AMD specific error code\n
657 * <0 - Negative POSIX Error code
658 *
659 * \sa amdgpu_bo_import()
660 *
661*/
662int amdgpu_bo_export(amdgpu_bo_handle buf_handle,
663 enum amdgpu_bo_handle_type type,
664 uint32_t *shared_handle);
665
666/**
667 * Request access to "shared" buffer
668 *
669 * \param dev - \c [in] Device handle.
670 * See #amdgpu_device_initialize()
671 * \param type - \c [in] Type of handle requested
672 * \param shared_handle - \c [in] Shared handle received as result "import"
673 * operation
674 * \param output - \c [out] Pointer to structure with information
675 * about imported buffer
676 *
677 * \return 0 on success\n
678 * >0 - AMD specific error code\n
679 * <0 - Negative POSIX Error code
680 *
681 * \note Buffer must be "imported" only using new "fd" (different from
682 * one used by "exporter").
683 *
684 * \sa amdgpu_bo_export()
685 *
686*/
687int amdgpu_bo_import(amdgpu_device_handle dev,
688 enum amdgpu_bo_handle_type type,
689 uint32_t shared_handle,
690 struct amdgpu_bo_import_result *output);
691
692/**
693 * Free previosuly allocated memory
694 *
695 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
696 * \param buf_handle - \c [in] Buffer handle to free
697 *
698 * \return 0 on success\n
699 * >0 - AMD specific error code\n
700 * <0 - Negative POSIX Error code
701 *
702 * \note In the case of memory shared between different applications all
703 * resources will be “physically” freed only all such applications
704 * will be terminated
705 * \note If is UMD responsibility to ‘free’ buffer only when there is no
706 * more GPU access
707 *
708 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc()
709 *
710*/
711int amdgpu_bo_free(amdgpu_bo_handle buf_handle);
712
713/**
714 * Request CPU access to GPU accessable memory
715 *
716 * \param buf_handle - \c [in] Buffer handle
717 * \param cpu - \c [out] CPU address to be used for access
718 *
719 * \return 0 on success\n
720 * >0 - AMD specific error code\n
721 * <0 - Negative POSIX Error code
722 *
723 * \sa amdgpu_bo_cpu_unmap()
724 *
725*/
726int amdgpu_bo_cpu_map(amdgpu_bo_handle buf_handle, void **cpu);
727
728/**
729 * Release CPU access to GPU memory
730 *
731 * \param buf_handle - \c [in] Buffer handle
732 *
733 * \return 0 on success\n
734 * >0 - AMD specific error code\n
735 * <0 - Negative POSIX Error code
736 *
737 * \sa amdgpu_bo_cpu_map()
738 *
739*/
740int amdgpu_bo_cpu_unmap(amdgpu_bo_handle buf_handle);
741
742
743/**
744 * Wait until a buffer is not used by the device.
745 *
746 * \param dev - \c [in] Device handle. See #amdgpu_lib_initialize()
747 * \param buf_handle - \c [in] Buffer handle.
748 * \param timeout_ns - Timeout in nanoseconds.
749 * \param buffer_busy - 0 if buffer is idle, all GPU access was completed
750 * and no GPU access is scheduled.
751 * 1 GPU access is in fly or scheduled
752 *
753 * \return 0 - on success
754 * <0 - AMD specific error code
755 */
756int amdgpu_bo_wait_for_idle(amdgpu_bo_handle buf_handle,
757 uint64_t timeout_ns,
758 bool *buffer_busy);
759
Christian König6dc2eaf2015-04-22 14:52:34 +0200760/**
761 * Creates a BO list handle for command submission.
762 *
763 * \param dev - \c [in] Device handle.
764 * See #amdgpu_device_initialize()
765 * \param number_of_resources - \c [in] Number of BOs in the list
766 * \param resources - \c [in] List of BO handles
767 * \param resource_prios - \c [in] Optional priority for each handle
768 * \param result - \c [out] Created BO list handle
769 *
770 * \return 0 on success\n
771 * >0 - AMD specific error code\n
772 * <0 - Negative POSIX Error code
773 *
774 * \sa amdgpu_bo_list_destroy()
775*/
776int amdgpu_bo_list_create(amdgpu_device_handle dev,
777 uint32_t number_of_resources,
778 amdgpu_bo_handle *resources,
779 uint8_t *resource_prios,
780 amdgpu_bo_list_handle *result);
781
782/**
783 * Destroys a BO list handle.
784 *
785 * \param handle - \c [in] BO list handle.
786 *
787 * \return 0 on success\n
788 * >0 - AMD specific error code\n
789 * <0 - Negative POSIX Error code
790 *
791 * \sa amdgpu_bo_list_create()
792*/
793int amdgpu_bo_list_destroy(amdgpu_bo_list_handle handle);
Alex Deucher09361392015-04-20 12:04:22 -0400794
795/*
796 * Special GPU Resources
797 *
798*/
799
800
801
802/**
803 * Query information about GDS
804 *
805 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
806 * \param gds_info - \c [out] Pointer to structure to get GDS information
807 *
808 * \return 0 on success\n
809 * >0 - AMD specific error code\n
810 * <0 - Negative POSIX Error code
811 *
812*/
813int amdgpu_gpu_resource_query_gds_info(amdgpu_device_handle dev,
814 struct amdgpu_gds_resource_info *
815 gds_info);
816
817
818/**
819 * Allocate GDS partitions
820 *
821 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
822 * \param gds_size - \c [in] Size of gds allocation. Must be aligned
823 * accordingly.
824 * \param alloc_info - \c [out] Pointer to structure to receive information
825 * about allocation
826 *
827 * \return 0 on success\n
828 * >0 - AMD specific error code\n
829 * <0 - Negative POSIX Error code
830 *
831 *
832*/
833int amdgpu_gpu_resource_gds_alloc(amdgpu_device_handle dev,
834 uint32_t gds_size,
835 struct amdgpu_gds_alloc_info *alloc_info);
836
837
838
839
840/**
841 * Release GDS resource. When GDS and associated resources not needed any
842 * more UMD should free them
843 *
844 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
845 * \param handle - \c [in] Handle assigned to GDS allocation
846 *
847 * \return 0 on success\n
848 * >0 - AMD specific error code\n
849 * <0 - Negative POSIX Error code
850 *
851*/
852int amdgpu_gpu_resource_gds_free(amdgpu_bo_handle handle);
853
854
855
856/*
857 * GPU Execution context
858 *
859*/
860
861/**
862 * Create GPU execution Context
863 *
864 * For the purpose of GPU Scheduler and GPU Robustness extensions it is
865 * necessary to have information/identify rendering/compute contexts.
866 * It also may be needed to associate some specific requirements with such
867 * contexts. Kernel driver will guarantee that submission from the same
868 * context will always be executed in order (first come, first serve).
869 *
870 *
871 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize()
872 * \param context - \c [out] GPU Context handle
873 *
874 * \return 0 on success\n
875 * >0 - AMD specific error code\n
876 * <0 - Negative POSIX Error code
877 *
878 * \sa amdgpu_cs_ctx_free()
879 *
880*/
881int amdgpu_cs_ctx_create(amdgpu_device_handle dev,
882 amdgpu_context_handle *context);
883
884/**
885 *
886 * Destroy GPU execution context when not needed any more
887 *
Alex Deucher09361392015-04-20 12:04:22 -0400888 * \param context - \c [in] GPU Context handle
889 *
890 * \return 0 on success\n
891 * >0 - AMD specific error code\n
892 * <0 - Negative POSIX Error code
893 *
894 * \sa amdgpu_cs_ctx_create()
895 *
896*/
Christian König9c2afff2015-04-22 12:21:13 +0200897int amdgpu_cs_ctx_free(amdgpu_context_handle context);
Alex Deucher09361392015-04-20 12:04:22 -0400898
899/**
900 * Query reset state for the specific GPU Context
901 *
Alex Deucher09361392015-04-20 12:04:22 -0400902 * \param context - \c [in] GPU Context handle
Marek Olšák4b39a8e2015-05-05 21:23:02 +0200903 * \param state - \c [out] One of AMDGPU_CTX_*_RESET
904 * \param hangs - \c [out] Number of hangs caused by the context.
Alex Deucher09361392015-04-20 12:04:22 -0400905 *
906 * \return 0 on success\n
907 * >0 - AMD specific error code\n
908 * <0 - Negative POSIX Error code
909 *
910 * \sa amdgpu_cs_ctx_create()
911 *
912*/
Christian König9c2afff2015-04-22 12:21:13 +0200913int amdgpu_cs_query_reset_state(amdgpu_context_handle context,
Marek Olšák4b39a8e2015-05-05 21:23:02 +0200914 uint32_t *state, uint32_t *hangs);
Alex Deucher09361392015-04-20 12:04:22 -0400915
916
917/*
918 * Command Buffers Management
919 *
920*/
921
922
923/**
924 * Allocate memory to be filled with PM4 packets and be served as the first
925 * entry point of execution (a.k.a. Indirect Buffer)
926 *
Alex Deucher09361392015-04-20 12:04:22 -0400927 * \param context - \c [in] GPU Context which will use IB
928 * \param ib_size - \c [in] Size of allocation
929 * \param output - \c [out] Pointer to structure to get information about
930 * allocated IB
931 *
932 * \return 0 on success\n
933 * >0 - AMD specific error code\n
934 * <0 - Negative POSIX Error code
935 *
936 * \sa amdgpu_cs_free_ib()
937 *
938*/
Christian König9c2afff2015-04-22 12:21:13 +0200939int amdgpu_cs_alloc_ib(amdgpu_context_handle context,
Alex Deucher09361392015-04-20 12:04:22 -0400940 enum amdgpu_cs_ib_size ib_size,
941 struct amdgpu_cs_ib_alloc_result *output);
942
943/**
944 * If UMD has allocates IBs which doesn’t need any more than those IBs must
945 * be explicitly freed
946 *
Alex Deucher09361392015-04-20 12:04:22 -0400947 * \param handle - \c [in] IB handle
948 *
949 * \return 0 on success\n
950 * >0 - AMD specific error code\n
951 * <0 - Negative POSIX Error code
952 *
953 * \note Libdrm_amdgpu will guarantee that it will correctly detect when it
954 * is safe to return IB to free pool
955 *
956 * \sa amdgpu_cs_alloc_ib()
957 *
958*/
Christian König9c2afff2015-04-22 12:21:13 +0200959int amdgpu_cs_free_ib(amdgpu_ib_handle handle);
Alex Deucher09361392015-04-20 12:04:22 -0400960
961/**
962 * Send request to submit command buffers to hardware.
963 *
964 * Kernel driver could use GPU Scheduler to make decision when physically
965 * sent this request to the hardware. Accordingly this request could be put
966 * in queue and sent for execution later. The only guarantee is that request
967 * from the same GPU context to the same ip:ip_instance:ring will be executed in
968 * order.
969 *
970 *
971 * \param dev - \c [in] Device handle.
972 * See #amdgpu_device_initialize()
973 * \param context - \c [in] GPU Context
974 * \param flags - \c [in] Global submission flags
975 * \param ibs_request - \c [in] Pointer to submission requests.
976 * We could submit to the several
977 * engines/rings simulteniously as
978 * 'atomic' operation
979 * \param number_of_requests - \c [in] Number of submission requests
980 * \param fences - \c [out] Pointer to array of data to get
981 * fences to identify submission
982 * requests. Timestamps are valid
983 * in this GPU context and could be used
984 * to identify/detect completion of
985 * submission request
986 *
987 * \return 0 on success\n
988 * >0 - AMD specific error code\n
989 * <0 - Negative POSIX Error code
990 *
991 * \note It is assumed that by default IB will be returned to free pool
992 * automatically by libdrm_amdgpu when submission will completed.
993 * It is possible for UMD to make decision to re-use the same IB in
994 * this case it should be explicitly freed.\n
995 * Accordingly, by default, after submission UMD should not touch passed
996 * IBs. If UMD needs to re-use IB then the special flag AMDGPU_CS_REUSE_IB
997 * must be passed.
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*/
Christian König9c2afff2015-04-22 12:21:13 +02001008int amdgpu_cs_submit(amdgpu_context_handle context,
Alex Deucher09361392015-04-20 12:04:22 -04001009 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*/
Christian König9c2afff2015-04-22 12:21:13 +02001034int amdgpu_cs_query_fence_status(struct amdgpu_cs_query_fence *fence,
Alex Deucher09361392015-04-20 12:04:22 -04001035 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*/
1060int 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*/
1081int 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*/
1098int 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*/
1118int 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*/
1140int 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*/
1159int 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*/
1178int 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*/
1199int 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*/
1222int 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*/
1262int 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_ */