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