amdgpu.h revision 48246ce7
1/* 2 * Copyright 2014 Advanced Micro Devices, Inc. 3 * 4 * Permission is hereby granted, free of charge, to any person obtaining a 5 * copy of this software and associated documentation files (the "Software"), 6 * to deal in the Software without restriction, including without limitation 7 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 * and/or sell copies of the Software, and to permit persons to whom the 9 * Software is furnished to do so, subject to the following conditions: 10 * 11 * The above copyright notice and this permission notice shall be included in 12 * all copies or substantial portions of the Software. 13 * 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 * OTHER DEALINGS IN THE SOFTWARE. 21 * 22 */ 23 24/** 25 * \file amdgpu.h 26 * 27 * Declare public libdrm_amdgpu API 28 * 29 * This file define API exposed by libdrm_amdgpu library. 30 * User wanted to use libdrm_amdgpu functionality must include 31 * this file. 32 * 33 */ 34#ifndef _AMDGPU_H_ 35#define _AMDGPU_H_ 36 37#include <stdint.h> 38#include <stdbool.h> 39 40#ifdef __cplusplus 41extern "C" { 42#endif 43 44struct drm_amdgpu_info_hw_ip; 45struct drm_amdgpu_bo_list_entry; 46 47/*--------------------------------------------------------------------------*/ 48/* --------------------------- Defines ------------------------------------ */ 49/*--------------------------------------------------------------------------*/ 50 51/** 52 * Define max. number of Command Buffers (IB) which could be sent to the single 53 * hardware IP to accommodate CE/DE requirements 54 * 55 * \sa amdgpu_cs_ib_info 56*/ 57#define AMDGPU_CS_MAX_IBS_PER_SUBMIT 4 58 59/** 60 * Special timeout value meaning that the timeout is infinite. 61 */ 62#define AMDGPU_TIMEOUT_INFINITE 0xffffffffffffffffull 63 64/** 65 * Used in amdgpu_cs_query_fence_status(), meaning that the given timeout 66 * is absolute. 67 */ 68#define AMDGPU_QUERY_FENCE_TIMEOUT_IS_ABSOLUTE (1 << 0) 69 70/*--------------------------------------------------------------------------*/ 71/* ----------------------------- Enums ------------------------------------ */ 72/*--------------------------------------------------------------------------*/ 73 74/** 75 * Enum describing possible handle types 76 * 77 * \sa amdgpu_bo_import, amdgpu_bo_export 78 * 79*/ 80enum amdgpu_bo_handle_type { 81 /** GEM flink name (needs DRM authentication, used by DRI2) */ 82 amdgpu_bo_handle_type_gem_flink_name = 0, 83 84 /** KMS handle which is used by all driver ioctls */ 85 amdgpu_bo_handle_type_kms = 1, 86 87 /** DMA-buf fd handle */ 88 amdgpu_bo_handle_type_dma_buf_fd = 2, 89 90 /** Deprecated in favour of and same behaviour as 91 * amdgpu_bo_handle_type_kms, use that instead of this 92 */ 93 amdgpu_bo_handle_type_kms_noimport = 3, 94}; 95 96/** Define known types of GPU VM VA ranges */ 97enum amdgpu_gpu_va_range 98{ 99 /** Allocate from "normal"/general range */ 100 amdgpu_gpu_va_range_general = 0 101}; 102 103enum amdgpu_sw_info { 104 amdgpu_sw_info_address32_hi = 0, 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#ifndef AMDGPU_DEVICE_TYPEDEF 118#define AMDGPU_DEVICE_TYPEDEF 119typedef struct amdgpu_device *amdgpu_device_handle; 120#endif 121 122/** 123 * Define GPU Context type as pointer to opaque structure 124 * Example of GPU Context is the "rendering" context associated 125 * with OpenGL context (glCreateContext) 126 */ 127typedef struct amdgpu_context *amdgpu_context_handle; 128 129/** 130 * Define handle for amdgpu resources: buffer, GDS, etc. 131 */ 132typedef struct amdgpu_bo *amdgpu_bo_handle; 133 134/** 135 * Define handle for list of BOs 136 */ 137typedef struct amdgpu_bo_list *amdgpu_bo_list_handle; 138 139/** 140 * Define handle to be used to work with VA allocated ranges 141 */ 142typedef struct amdgpu_va *amdgpu_va_handle; 143 144/** 145 * Define handle dealing with VA allocation. An amdgpu_device 146 * owns one of these, but they can also be used without a device. 147 */ 148typedef struct amdgpu_va_manager *amdgpu_va_manager_handle; 149 150/** 151 * Define handle for semaphore 152 */ 153typedef struct amdgpu_semaphore *amdgpu_semaphore_handle; 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 * Special UMD specific information associated with buffer. 188 * 189 * It may be need to pass some buffer charactersitic as part 190 * of buffer sharing. Such information are defined UMD and 191 * opaque for libdrm_amdgpu as well for kernel driver. 192 * 193 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info, 194 * amdgpu_bo_import(), amdgpu_bo_export 195 * 196*/ 197struct amdgpu_bo_metadata { 198 /** Special flag associated with surface */ 199 uint64_t flags; 200 201 /** 202 * ASIC-specific tiling information (also used by DCE). 203 * The encoding is defined by the AMDGPU_TILING_* definitions. 204 */ 205 uint64_t tiling_info; 206 207 /** Size of metadata associated with the buffer, in bytes. */ 208 uint32_t size_metadata; 209 210 /** UMD specific metadata. Opaque for kernel */ 211 uint32_t umd_metadata[64]; 212}; 213 214/** 215 * Structure describing allocated buffer. Client may need 216 * to query such information as part of 'sharing' buffers mechanism 217 * 218 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_query_info(), 219 * amdgpu_bo_import(), amdgpu_bo_export() 220*/ 221struct amdgpu_bo_info { 222 /** Allocated memory size */ 223 uint64_t alloc_size; 224 225 /** 226 * It may be required to have some specific alignment requirements 227 * for physical back-up storage. 228 */ 229 uint64_t phys_alignment; 230 231 /** Heap where to allocate memory. */ 232 uint32_t preferred_heap; 233 234 /** Additional allocation flags. */ 235 uint64_t alloc_flags; 236 237 /** Metadata associated with buffer if any. */ 238 struct amdgpu_bo_metadata metadata; 239}; 240 241/** 242 * Structure with information about "imported" buffer 243 * 244 * \sa amdgpu_bo_import() 245 * 246 */ 247struct amdgpu_bo_import_result { 248 /** Handle of memory/buffer to use */ 249 amdgpu_bo_handle buf_handle; 250 251 /** Buffer size */ 252 uint64_t alloc_size; 253}; 254 255/** 256 * 257 * Structure to describe GDS partitioning information. 258 * \note OA and GWS resources are asscoiated with GDS partition 259 * 260 * \sa amdgpu_gpu_resource_query_gds_info 261 * 262*/ 263struct amdgpu_gds_resource_info { 264 uint32_t gds_gfx_partition_size; 265 uint32_t compute_partition_size; 266 uint32_t gds_total_size; 267 uint32_t gws_per_gfx_partition; 268 uint32_t gws_per_compute_partition; 269 uint32_t oa_per_gfx_partition; 270 uint32_t oa_per_compute_partition; 271}; 272 273/** 274 * Structure describing CS fence 275 * 276 * \sa amdgpu_cs_query_fence_status(), amdgpu_cs_request, amdgpu_cs_submit() 277 * 278*/ 279struct amdgpu_cs_fence { 280 281 /** In which context IB was sent to execution */ 282 amdgpu_context_handle context; 283 284 /** To which HW IP type the fence belongs */ 285 uint32_t ip_type; 286 287 /** IP instance index if there are several IPs of the same type. */ 288 uint32_t ip_instance; 289 290 /** Ring index of the HW IP */ 291 uint32_t ring; 292 293 /** Specify fence for which we need to check submission status.*/ 294 uint64_t fence; 295}; 296 297/** 298 * Structure describing IB 299 * 300 * \sa amdgpu_cs_request, amdgpu_cs_submit() 301 * 302*/ 303struct amdgpu_cs_ib_info { 304 /** Special flags */ 305 uint64_t flags; 306 307 /** Virtual MC address of the command buffer */ 308 uint64_t ib_mc_address; 309 310 /** 311 * Size of Command Buffer to be submitted. 312 * - The size is in units of dwords (4 bytes). 313 * - Could be 0 314 */ 315 uint32_t size; 316}; 317 318/** 319 * Structure describing fence information 320 * 321 * \sa amdgpu_cs_request, amdgpu_cs_query_fence, 322 * amdgpu_cs_submit(), amdgpu_cs_query_fence_status() 323*/ 324struct amdgpu_cs_fence_info { 325 /** buffer object for the fence */ 326 amdgpu_bo_handle handle; 327 328 /** fence offset in the unit of sizeof(uint64_t) */ 329 uint64_t offset; 330}; 331 332/** 333 * Structure describing submission request 334 * 335 * \note We could have several IBs as packet. e.g. CE, CE, DE case for gfx 336 * 337 * \sa amdgpu_cs_submit() 338*/ 339struct amdgpu_cs_request { 340 /** Specify flags with additional information */ 341 uint64_t flags; 342 343 /** Specify HW IP block type to which to send the IB. */ 344 unsigned ip_type; 345 346 /** IP instance index if there are several IPs of the same type. */ 347 unsigned ip_instance; 348 349 /** 350 * Specify ring index of the IP. We could have several rings 351 * in the same IP. E.g. 0 for SDMA0 and 1 for SDMA1. 352 */ 353 uint32_t ring; 354 355 /** 356 * List handle with resources used by this request. 357 */ 358 amdgpu_bo_list_handle resources; 359 360 /** 361 * Number of dependencies this Command submission needs to 362 * wait for before starting execution. 363 */ 364 uint32_t number_of_dependencies; 365 366 /** 367 * Array of dependencies which need to be met before 368 * execution can start. 369 */ 370 struct amdgpu_cs_fence *dependencies; 371 372 /** Number of IBs to submit in the field ibs. */ 373 uint32_t number_of_ibs; 374 375 /** 376 * IBs to submit. Those IBs will be submit together as single entity 377 */ 378 struct amdgpu_cs_ib_info *ibs; 379 380 /** 381 * The returned sequence number for the command submission 382 */ 383 uint64_t seq_no; 384 385 /** 386 * The fence information 387 */ 388 struct amdgpu_cs_fence_info fence_info; 389}; 390 391/** 392 * Structure which provide information about GPU VM MC Address space 393 * alignments requirements 394 * 395 * \sa amdgpu_query_buffer_size_alignment 396 */ 397struct amdgpu_buffer_size_alignments { 398 /** Size alignment requirement for allocation in 399 * local memory */ 400 uint64_t size_local; 401 402 /** 403 * Size alignment requirement for allocation in remote memory 404 */ 405 uint64_t size_remote; 406}; 407 408/** 409 * Structure which provide information about heap 410 * 411 * \sa amdgpu_query_heap_info() 412 * 413 */ 414struct amdgpu_heap_info { 415 /** Theoretical max. available memory in the given heap */ 416 uint64_t heap_size; 417 418 /** 419 * Number of bytes allocated in the heap. This includes all processes 420 * and private allocations in the kernel. It changes when new buffers 421 * are allocated, freed, and moved. It cannot be larger than 422 * heap_size. 423 */ 424 uint64_t heap_usage; 425 426 /** 427 * Theoretical possible max. size of buffer which 428 * could be allocated in the given heap 429 */ 430 uint64_t max_allocation; 431}; 432 433/** 434 * Describe GPU h/w info needed for UMD correct initialization 435 * 436 * \sa amdgpu_query_gpu_info() 437*/ 438struct amdgpu_gpu_info { 439 /** Asic id */ 440 uint32_t asic_id; 441 /** Chip revision */ 442 uint32_t chip_rev; 443 /** Chip external revision */ 444 uint32_t chip_external_rev; 445 /** Family ID */ 446 uint32_t family_id; 447 /** Special flags */ 448 uint64_t ids_flags; 449 /** max engine clock*/ 450 uint64_t max_engine_clk; 451 /** max memory clock */ 452 uint64_t max_memory_clk; 453 /** number of shader engines */ 454 uint32_t num_shader_engines; 455 /** number of shader arrays per engine */ 456 uint32_t num_shader_arrays_per_engine; 457 /** Number of available good shader pipes */ 458 uint32_t avail_quad_shader_pipes; 459 /** Max. number of shader pipes.(including good and bad pipes */ 460 uint32_t max_quad_shader_pipes; 461 /** Number of parameter cache entries per shader quad pipe */ 462 uint32_t cache_entries_per_quad_pipe; 463 /** Number of available graphics context */ 464 uint32_t num_hw_gfx_contexts; 465 /** Number of render backend pipes */ 466 uint32_t rb_pipes; 467 /** Enabled render backend pipe mask */ 468 uint32_t enabled_rb_pipes_mask; 469 /** Frequency of GPU Counter */ 470 uint32_t gpu_counter_freq; 471 /** CC_RB_BACKEND_DISABLE.BACKEND_DISABLE per SE */ 472 uint32_t backend_disable[4]; 473 /** Value of MC_ARB_RAMCFG register*/ 474 uint32_t mc_arb_ramcfg; 475 /** Value of GB_ADDR_CONFIG */ 476 uint32_t gb_addr_cfg; 477 /** Values of the GB_TILE_MODE0..31 registers */ 478 uint32_t gb_tile_mode[32]; 479 /** Values of GB_MACROTILE_MODE0..15 registers */ 480 uint32_t gb_macro_tile_mode[16]; 481 /** Value of PA_SC_RASTER_CONFIG register per SE */ 482 uint32_t pa_sc_raster_cfg[4]; 483 /** Value of PA_SC_RASTER_CONFIG_1 register per SE */ 484 uint32_t pa_sc_raster_cfg1[4]; 485 /* CU info */ 486 uint32_t cu_active_number; 487 uint32_t cu_ao_mask; 488 uint32_t cu_bitmap[4][4]; 489 /* video memory type info*/ 490 uint32_t vram_type; 491 /* video memory bit width*/ 492 uint32_t vram_bit_width; 493 /** constant engine ram size*/ 494 uint32_t ce_ram_size; 495 /* vce harvesting instance */ 496 uint32_t vce_harvest_config; 497 /* PCI revision ID */ 498 uint32_t pci_rev_id; 499}; 500 501 502/*--------------------------------------------------------------------------*/ 503/*------------------------- Functions --------------------------------------*/ 504/*--------------------------------------------------------------------------*/ 505 506/* 507 * Initialization / Cleanup 508 * 509*/ 510 511/** 512 * 513 * \param fd - \c [in] File descriptor for AMD GPU device 514 * received previously as the result of 515 * e.g. drmOpen() call. 516 * For legacy fd type, the DRI2/DRI3 517 * authentication should be done before 518 * calling this function. 519 * \param major_version - \c [out] Major version of library. It is assumed 520 * that adding new functionality will cause 521 * increase in major version 522 * \param minor_version - \c [out] Minor version of library 523 * \param device_handle - \c [out] Pointer to opaque context which should 524 * be passed as the first parameter on each 525 * API call 526 * 527 * 528 * \return 0 on success\n 529 * <0 - Negative POSIX Error code 530 * 531 * 532 * \sa amdgpu_device_deinitialize() 533*/ 534int amdgpu_device_initialize(int fd, 535 uint32_t *major_version, 536 uint32_t *minor_version, 537 amdgpu_device_handle *device_handle); 538 539/** 540 * Same as amdgpu_device_initialize() except when deduplicate_device 541 * is false *and* fd points to a device that was already initialized. 542 * In this case, amdgpu_device_initialize would return the same 543 * amdgpu_device_handle while here amdgpu_device_initialize2 would 544 * return a new handle. 545 * amdgpu_device_initialize() should be preferred in most situations; 546 * the only use-case where not-deduplicating devices make sense is 547 * when one wants to have isolated device handles in the same process. 548 */ 549int amdgpu_device_initialize2(int fd, bool deduplicate_device, 550 uint32_t *major_version, 551 uint32_t *minor_version, 552 amdgpu_device_handle *device_handle); 553/** 554 * 555 * When access to such library does not needed any more the special 556 * function must be call giving opportunity to clean up any 557 * resources if needed. 558 * 559 * \param device_handle - \c [in] Context associated with file 560 * descriptor for AMD GPU device 561 * received previously as the 562 * result e.g. of drmOpen() call. 563 * 564 * \return 0 on success\n 565 * <0 - Negative POSIX Error code 566 * 567 * \sa amdgpu_device_initialize() 568 * 569*/ 570int amdgpu_device_deinitialize(amdgpu_device_handle device_handle); 571 572/** 573 * 574 * /param device_handle - \c [in] Device handle. 575 * See #amdgpu_device_initialize() 576 * 577 * \return Returns the drm fd used for operations on this 578 * device. This is still owned by the library and hence 579 * should not be closed. Guaranteed to be valid until 580 * #amdgpu_device_deinitialize gets called. 581 * 582*/ 583int amdgpu_device_get_fd(amdgpu_device_handle device_handle); 584 585/* 586 * Memory Management 587 * 588*/ 589 590/** 591 * Allocate memory to be used by UMD for GPU related operations 592 * 593 * \param dev - \c [in] Device handle. 594 * See #amdgpu_device_initialize() 595 * \param alloc_buffer - \c [in] Pointer to the structure describing an 596 * allocation request 597 * \param buf_handle - \c [out] Allocated buffer handle 598 * 599 * \return 0 on success\n 600 * <0 - Negative POSIX Error code 601 * 602 * \sa amdgpu_bo_free() 603*/ 604int amdgpu_bo_alloc(amdgpu_device_handle dev, 605 struct amdgpu_bo_alloc_request *alloc_buffer, 606 amdgpu_bo_handle *buf_handle); 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 - Negative POSIX Error code 617*/ 618int amdgpu_bo_set_metadata(amdgpu_bo_handle buf_handle, 619 struct amdgpu_bo_metadata *info); 620 621/** 622 * Query buffer information including metadata previusly associated with 623 * buffer. 624 * 625 * \param dev - \c [in] Device handle. 626 * See #amdgpu_device_initialize() 627 * \param buf_handle - \c [in] Buffer handle 628 * \param info - \c [out] Structure describing buffer 629 * 630 * \return 0 on success\n 631 * <0 - Negative POSIX Error code 632 * 633 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc() 634*/ 635int 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 - Negative POSIX Error code 649 * 650 * \sa amdgpu_bo_import() 651 * 652*/ 653int amdgpu_bo_export(amdgpu_bo_handle buf_handle, 654 enum amdgpu_bo_handle_type type, 655 uint32_t *shared_handle); 656 657/** 658 * Request access to "shared" buffer 659 * 660 * \param dev - \c [in] Device handle. 661 * See #amdgpu_device_initialize() 662 * \param type - \c [in] Type of handle requested 663 * \param shared_handle - \c [in] Shared handle received as result "import" 664 * operation 665 * \param output - \c [out] Pointer to structure with information 666 * about imported buffer 667 * 668 * \return 0 on success\n 669 * <0 - Negative POSIX Error code 670 * 671 * \note Buffer must be "imported" only using new "fd" (different from 672 * one used by "exporter"). 673 * 674 * \sa amdgpu_bo_export() 675 * 676*/ 677int amdgpu_bo_import(amdgpu_device_handle dev, 678 enum amdgpu_bo_handle_type type, 679 uint32_t shared_handle, 680 struct amdgpu_bo_import_result *output); 681 682/** 683 * Request GPU access to user allocated memory e.g. via "malloc" 684 * 685 * \param dev - [in] Device handle. See #amdgpu_device_initialize() 686 * \param cpu - [in] CPU address of user allocated memory which we 687 * want to map to GPU address space (make GPU accessible) 688 * (This address must be correctly aligned). 689 * \param size - [in] Size of allocation (must be correctly aligned) 690 * \param buf_handle - [out] Buffer handle for the userptr memory 691 * resource on submission and be used in other operations. 692 * 693 * 694 * \return 0 on success\n 695 * <0 - Negative POSIX Error code 696 * 697 * \note 698 * This call doesn't guarantee that such memory will be persistently 699 * "locked" / make non-pageable. The purpose of this call is to provide 700 * opportunity for GPU get access to this resource during submission. 701 * 702 * The maximum amount of memory which could be mapped in this call depends 703 * if overcommit is disabled or not. If overcommit is disabled than the max. 704 * amount of memory to be pinned will be limited by left "free" size in total 705 * amount of memory which could be locked simultaneously ("GART" size). 706 * 707 * Supported (theoretical) max. size of mapping is restricted only by 708 * "GART" size. 709 * 710 * It is responsibility of caller to correctly specify access rights 711 * on VA assignment. 712*/ 713int amdgpu_create_bo_from_user_mem(amdgpu_device_handle dev, 714 void *cpu, uint64_t size, 715 amdgpu_bo_handle *buf_handle); 716 717/** 718 * Validate if the user memory comes from BO 719 * 720 * \param dev - [in] Device handle. See #amdgpu_device_initialize() 721 * \param cpu - [in] CPU address of user allocated memory which we 722 * want to map to GPU address space (make GPU accessible) 723 * (This address must be correctly aligned). 724 * \param size - [in] Size of allocation (must be correctly aligned) 725 * \param buf_handle - [out] Buffer handle for the userptr memory 726 * if the user memory is not from BO, the buf_handle will be NULL. 727 * \param offset_in_bo - [out] offset in this BO for this user memory 728 * 729 * 730 * \return 0 on success\n 731 * <0 - Negative POSIX Error code 732 * 733*/ 734int amdgpu_find_bo_by_cpu_mapping(amdgpu_device_handle dev, 735 void *cpu, 736 uint64_t size, 737 amdgpu_bo_handle *buf_handle, 738 uint64_t *offset_in_bo); 739 740/** 741 * Free previously allocated memory 742 * 743 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize() 744 * \param buf_handle - \c [in] Buffer handle to free 745 * 746 * \return 0 on success\n 747 * <0 - Negative POSIX Error code 748 * 749 * \note In the case of memory shared between different applications all 750 * resources will be “physically” freed only all such applications 751 * will be terminated 752 * \note If is UMD responsibility to ‘free’ buffer only when there is no 753 * more GPU access 754 * 755 * \sa amdgpu_bo_set_metadata(), amdgpu_bo_alloc() 756 * 757*/ 758int amdgpu_bo_free(amdgpu_bo_handle buf_handle); 759 760/** 761 * Increase the reference count of a buffer object 762 * 763 * \param bo - \c [in] Buffer object handle to increase the reference count 764 * 765 * \sa amdgpu_bo_alloc(), amdgpu_bo_free() 766 * 767*/ 768void amdgpu_bo_inc_ref(amdgpu_bo_handle bo); 769 770/** 771 * Request CPU access to GPU accessible memory 772 * 773 * \param buf_handle - \c [in] Buffer handle 774 * \param cpu - \c [out] CPU address to be used for access 775 * 776 * \return 0 on success\n 777 * <0 - Negative POSIX Error code 778 * 779 * \sa amdgpu_bo_cpu_unmap() 780 * 781*/ 782int amdgpu_bo_cpu_map(amdgpu_bo_handle buf_handle, void **cpu); 783 784/** 785 * Release CPU access to GPU memory 786 * 787 * \param buf_handle - \c [in] Buffer handle 788 * 789 * \return 0 on success\n 790 * <0 - Negative POSIX Error code 791 * 792 * \sa amdgpu_bo_cpu_map() 793 * 794*/ 795int amdgpu_bo_cpu_unmap(amdgpu_bo_handle buf_handle); 796 797/** 798 * Wait until a buffer is not used by the device. 799 * 800 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize() 801 * \param buf_handle - \c [in] Buffer handle. 802 * \param timeout_ns - Timeout in nanoseconds. 803 * \param buffer_busy - 0 if buffer is idle, all GPU access was completed 804 * and no GPU access is scheduled. 805 * 1 GPU access is in fly or scheduled 806 * 807 * \return 0 - on success 808 * <0 - Negative POSIX Error code 809 */ 810int amdgpu_bo_wait_for_idle(amdgpu_bo_handle buf_handle, 811 uint64_t timeout_ns, 812 bool *buffer_busy); 813 814/** 815 * Creates a BO list handle for command submission. 816 * 817 * \param dev - \c [in] Device handle. 818 * See #amdgpu_device_initialize() 819 * \param number_of_buffers - \c [in] Number of BOs in the list 820 * \param buffers - \c [in] List of BO handles 821 * \param result - \c [out] Created BO list handle 822 * 823 * \return 0 on success\n 824 * <0 - Negative POSIX Error code 825 * 826 * \sa amdgpu_bo_list_destroy_raw(), amdgpu_cs_submit_raw2() 827*/ 828int amdgpu_bo_list_create_raw(amdgpu_device_handle dev, 829 uint32_t number_of_buffers, 830 struct drm_amdgpu_bo_list_entry *buffers, 831 uint32_t *result); 832 833/** 834 * Destroys a BO list handle. 835 * 836 * \param bo_list - \c [in] BO list handle. 837 * 838 * \return 0 on success\n 839 * <0 - Negative POSIX Error code 840 * 841 * \sa amdgpu_bo_list_create_raw(), amdgpu_cs_submit_raw2() 842*/ 843int amdgpu_bo_list_destroy_raw(amdgpu_device_handle dev, uint32_t bo_list); 844 845/** 846 * Creates a BO list handle for command submission. 847 * 848 * \param dev - \c [in] Device handle. 849 * See #amdgpu_device_initialize() 850 * \param number_of_resources - \c [in] Number of BOs in the list 851 * \param resources - \c [in] List of BO handles 852 * \param resource_prios - \c [in] Optional priority for each handle 853 * \param result - \c [out] Created BO list handle 854 * 855 * \return 0 on success\n 856 * <0 - Negative POSIX Error code 857 * 858 * \sa amdgpu_bo_list_destroy() 859*/ 860int amdgpu_bo_list_create(amdgpu_device_handle dev, 861 uint32_t number_of_resources, 862 amdgpu_bo_handle *resources, 863 uint8_t *resource_prios, 864 amdgpu_bo_list_handle *result); 865 866/** 867 * Destroys a BO list handle. 868 * 869 * \param handle - \c [in] BO list handle. 870 * 871 * \return 0 on success\n 872 * <0 - Negative POSIX Error code 873 * 874 * \sa amdgpu_bo_list_create() 875*/ 876int amdgpu_bo_list_destroy(amdgpu_bo_list_handle handle); 877 878/** 879 * Update resources for existing BO list 880 * 881 * \param handle - \c [in] BO list handle 882 * \param number_of_resources - \c [in] Number of BOs in the list 883 * \param resources - \c [in] List of BO handles 884 * \param resource_prios - \c [in] Optional priority for each handle 885 * 886 * \return 0 on success\n 887 * <0 - Negative POSIX Error code 888 * 889 * \sa amdgpu_bo_list_update() 890*/ 891int amdgpu_bo_list_update(amdgpu_bo_list_handle handle, 892 uint32_t number_of_resources, 893 amdgpu_bo_handle *resources, 894 uint8_t *resource_prios); 895 896/* 897 * GPU Execution context 898 * 899*/ 900 901/** 902 * Create GPU execution Context 903 * 904 * For the purpose of GPU Scheduler and GPU Robustness extensions it is 905 * necessary to have information/identify rendering/compute contexts. 906 * It also may be needed to associate some specific requirements with such 907 * contexts. Kernel driver will guarantee that submission from the same 908 * context will always be executed in order (first come, first serve). 909 * 910 * 911 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize() 912 * \param priority - \c [in] Context creation flags. See AMDGPU_CTX_PRIORITY_* 913 * \param context - \c [out] GPU Context handle 914 * 915 * \return 0 on success\n 916 * <0 - Negative POSIX Error code 917 * 918 * \sa amdgpu_cs_ctx_free() 919 * 920*/ 921int amdgpu_cs_ctx_create2(amdgpu_device_handle dev, 922 uint32_t priority, 923 amdgpu_context_handle *context); 924/** 925 * Create GPU execution Context 926 * 927 * Refer to amdgpu_cs_ctx_create2 for full documentation. This call 928 * is missing the priority parameter. 929 * 930 * \sa amdgpu_cs_ctx_create2() 931 * 932*/ 933int amdgpu_cs_ctx_create(amdgpu_device_handle dev, 934 amdgpu_context_handle *context); 935 936/** 937 * 938 * Destroy GPU execution context when not needed any more 939 * 940 * \param context - \c [in] GPU Context handle 941 * 942 * \return 0 on success\n 943 * <0 - Negative POSIX Error code 944 * 945 * \sa amdgpu_cs_ctx_create() 946 * 947*/ 948int amdgpu_cs_ctx_free(amdgpu_context_handle context); 949 950/** 951 * Override the submission priority for the given context using a master fd. 952 * 953 * \param dev - \c [in] device handle 954 * \param context - \c [in] context handle for context id 955 * \param master_fd - \c [in] The master fd to authorize the override. 956 * \param priority - \c [in] The priority to assign to the context. 957 * 958 * \return 0 on success or a a negative Posix error code on failure. 959 */ 960int amdgpu_cs_ctx_override_priority(amdgpu_device_handle dev, 961 amdgpu_context_handle context, 962 int master_fd, 963 unsigned priority); 964 965/** 966 * Set or query the stable power state for GPU profiling. 967 * 968 * \param dev - \c [in] device handle 969 * \param op - \c [in] AMDGPU_CTX_OP_{GET,SET}_STABLE_PSTATE 970 * \param flags - \c [in] AMDGPU_CTX_STABLE_PSTATE_* 971 * \param out_flags - \c [out] output current stable pstate 972 * 973 * \return 0 on success otherwise POSIX Error code. 974 */ 975int amdgpu_cs_ctx_stable_pstate(amdgpu_context_handle context, 976 uint32_t op, 977 uint32_t flags, 978 uint32_t *out_flags); 979 980/** 981 * Query reset state for the specific GPU Context 982 * 983 * \param context - \c [in] GPU Context handle 984 * \param state - \c [out] One of AMDGPU_CTX_*_RESET 985 * \param hangs - \c [out] Number of hangs caused by the context. 986 * 987 * \return 0 on success\n 988 * <0 - Negative POSIX Error code 989 * 990 * \sa amdgpu_cs_ctx_create() 991 * 992*/ 993int amdgpu_cs_query_reset_state(amdgpu_context_handle context, 994 uint32_t *state, uint32_t *hangs); 995 996/** 997 * Query reset state for the specific GPU Context. 998 * 999 * \param context - \c [in] GPU Context handle 1000 * \param flags - \c [out] A combination of AMDGPU_CTX_QUERY2_FLAGS_* 1001 * 1002 * \return 0 on success\n 1003 * <0 - Negative POSIX Error code 1004 * 1005 * \sa amdgpu_cs_ctx_create() 1006 * 1007*/ 1008int amdgpu_cs_query_reset_state2(amdgpu_context_handle context, 1009 uint64_t *flags); 1010 1011/* 1012 * Command Buffers Management 1013 * 1014*/ 1015 1016/** 1017 * Send request to submit command buffers to hardware. 1018 * 1019 * Kernel driver could use GPU Scheduler to make decision when physically 1020 * sent this request to the hardware. Accordingly this request could be put 1021 * in queue and sent for execution later. The only guarantee is that request 1022 * from the same GPU context to the same ip:ip_instance:ring will be executed in 1023 * order. 1024 * 1025 * The caller can specify the user fence buffer/location with the fence_info in the 1026 * cs_request.The sequence number is returned via the 'seq_no' parameter 1027 * in ibs_request structure. 1028 * 1029 * 1030 * \param dev - \c [in] Device handle. 1031 * See #amdgpu_device_initialize() 1032 * \param context - \c [in] GPU Context 1033 * \param flags - \c [in] Global submission flags 1034 * \param ibs_request - \c [in/out] Pointer to submission requests. 1035 * We could submit to the several 1036 * engines/rings simulteniously as 1037 * 'atomic' operation 1038 * \param number_of_requests - \c [in] Number of submission requests 1039 * 1040 * \return 0 on success\n 1041 * <0 - Negative POSIX Error code 1042 * 1043 * \note It is required to pass correct resource list with buffer handles 1044 * which will be accessible by command buffers from submission 1045 * This will allow kernel driver to correctly implement "paging". 1046 * Failure to do so will have unpredictable results. 1047 * 1048 * \sa amdgpu_command_buffer_alloc(), amdgpu_command_buffer_free(), 1049 * amdgpu_cs_query_fence_status() 1050 * 1051*/ 1052int amdgpu_cs_submit(amdgpu_context_handle context, 1053 uint64_t flags, 1054 struct amdgpu_cs_request *ibs_request, 1055 uint32_t number_of_requests); 1056 1057/** 1058 * Query status of Command Buffer Submission 1059 * 1060 * \param fence - \c [in] Structure describing fence to query 1061 * \param timeout_ns - \c [in] Timeout value to wait 1062 * \param flags - \c [in] Flags for the query 1063 * \param expired - \c [out] If fence expired or not.\n 1064 * 0 – if fence is not expired\n 1065 * !0 - otherwise 1066 * 1067 * \return 0 on success\n 1068 * <0 - Negative POSIX Error code 1069 * 1070 * \note If UMD wants only to check operation status and returned immediately 1071 * then timeout value as 0 must be passed. In this case success will be 1072 * returned in the case if submission was completed or timeout error 1073 * code. 1074 * 1075 * \sa amdgpu_cs_submit() 1076*/ 1077int amdgpu_cs_query_fence_status(struct amdgpu_cs_fence *fence, 1078 uint64_t timeout_ns, 1079 uint64_t flags, 1080 uint32_t *expired); 1081 1082/** 1083 * Wait for multiple fences 1084 * 1085 * \param fences - \c [in] The fence array to wait 1086 * \param fence_count - \c [in] The fence count 1087 * \param wait_all - \c [in] If true, wait all fences to be signaled, 1088 * otherwise, wait at least one fence 1089 * \param timeout_ns - \c [in] The timeout to wait, in nanoseconds 1090 * \param status - \c [out] '1' for signaled, '0' for timeout 1091 * \param first - \c [out] the index of the first signaled fence from @fences 1092 * 1093 * \return 0 on success 1094 * <0 - Negative POSIX Error code 1095 * 1096 * \note Currently it supports only one amdgpu_device. All fences come from 1097 * the same amdgpu_device with the same fd. 1098*/ 1099int amdgpu_cs_wait_fences(struct amdgpu_cs_fence *fences, 1100 uint32_t fence_count, 1101 bool wait_all, 1102 uint64_t timeout_ns, 1103 uint32_t *status, uint32_t *first); 1104 1105/* 1106 * Query / Info API 1107 * 1108*/ 1109 1110/** 1111 * Query allocation size alignments 1112 * 1113 * UMD should query information about GPU VM MC size alignments requirements 1114 * to be able correctly choose required allocation size and implement 1115 * internal optimization if needed. 1116 * 1117 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize() 1118 * \param info - \c [out] Pointer to structure to get size alignment 1119 * requirements 1120 * 1121 * \return 0 on success\n 1122 * <0 - Negative POSIX Error code 1123 * 1124*/ 1125int amdgpu_query_buffer_size_alignment(amdgpu_device_handle dev, 1126 struct amdgpu_buffer_size_alignments 1127 *info); 1128 1129/** 1130 * Query firmware versions 1131 * 1132 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize() 1133 * \param fw_type - \c [in] AMDGPU_INFO_FW_* 1134 * \param ip_instance - \c [in] Index of the IP block of the same type. 1135 * \param index - \c [in] Index of the engine. (for SDMA and MEC) 1136 * \param version - \c [out] Pointer to to the "version" return value 1137 * \param feature - \c [out] Pointer to to the "feature" return value 1138 * 1139 * \return 0 on success\n 1140 * <0 - Negative POSIX Error code 1141 * 1142*/ 1143int amdgpu_query_firmware_version(amdgpu_device_handle dev, unsigned fw_type, 1144 unsigned ip_instance, unsigned index, 1145 uint32_t *version, uint32_t *feature); 1146 1147/** 1148 * Query the number of HW IP instances of a certain type. 1149 * 1150 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize() 1151 * \param type - \c [in] Hardware IP block type = AMDGPU_HW_IP_* 1152 * \param count - \c [out] Pointer to structure to get information 1153 * 1154 * \return 0 on success\n 1155 * <0 - Negative POSIX Error code 1156*/ 1157int amdgpu_query_hw_ip_count(amdgpu_device_handle dev, unsigned type, 1158 uint32_t *count); 1159 1160/** 1161 * Query engine information 1162 * 1163 * This query allows UMD to query information different engines and their 1164 * capabilities. 1165 * 1166 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize() 1167 * \param type - \c [in] Hardware IP block type = AMDGPU_HW_IP_* 1168 * \param ip_instance - \c [in] Index of the IP block of the same type. 1169 * \param info - \c [out] Pointer to structure to get information 1170 * 1171 * \return 0 on success\n 1172 * <0 - Negative POSIX Error code 1173*/ 1174int amdgpu_query_hw_ip_info(amdgpu_device_handle dev, unsigned type, 1175 unsigned ip_instance, 1176 struct drm_amdgpu_info_hw_ip *info); 1177 1178/** 1179 * Query heap information 1180 * 1181 * This query allows UMD to query potentially available memory resources and 1182 * adjust their logic if necessary. 1183 * 1184 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize() 1185 * \param heap - \c [in] Heap type 1186 * \param info - \c [in] Pointer to structure to get needed information 1187 * 1188 * \return 0 on success\n 1189 * <0 - Negative POSIX Error code 1190 * 1191*/ 1192int amdgpu_query_heap_info(amdgpu_device_handle dev, uint32_t heap, 1193 uint32_t flags, struct amdgpu_heap_info *info); 1194 1195/** 1196 * Get the CRTC ID from the mode object ID 1197 * 1198 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize() 1199 * \param id - \c [in] Mode object ID 1200 * \param result - \c [in] Pointer to the CRTC ID 1201 * 1202 * \return 0 on success\n 1203 * <0 - Negative POSIX Error code 1204 * 1205*/ 1206int amdgpu_query_crtc_from_id(amdgpu_device_handle dev, unsigned id, 1207 int32_t *result); 1208 1209/** 1210 * Query GPU H/w Info 1211 * 1212 * Query hardware specific information 1213 * 1214 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize() 1215 * \param heap - \c [in] Heap type 1216 * \param info - \c [in] Pointer to structure to get needed information 1217 * 1218 * \return 0 on success\n 1219 * <0 - Negative POSIX Error code 1220 * 1221*/ 1222int amdgpu_query_gpu_info(amdgpu_device_handle dev, 1223 struct amdgpu_gpu_info *info); 1224 1225/** 1226 * Query hardware or driver information. 1227 * 1228 * The return size is query-specific and depends on the "info_id" parameter. 1229 * No more than "size" bytes is returned. 1230 * 1231 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize() 1232 * \param info_id - \c [in] AMDGPU_INFO_* 1233 * \param size - \c [in] Size of the returned value. 1234 * \param value - \c [out] Pointer to the return value. 1235 * 1236 * \return 0 on success\n 1237 * <0 - Negative POSIX error code 1238 * 1239*/ 1240int amdgpu_query_info(amdgpu_device_handle dev, unsigned info_id, 1241 unsigned size, void *value); 1242 1243/** 1244 * Query hardware or driver information. 1245 * 1246 * The return size is query-specific and depends on the "info_id" parameter. 1247 * No more than "size" bytes is returned. 1248 * 1249 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize() 1250 * \param info - \c [in] amdgpu_sw_info_* 1251 * \param value - \c [out] Pointer to the return value. 1252 * 1253 * \return 0 on success\n 1254 * <0 - Negative POSIX error code 1255 * 1256*/ 1257int amdgpu_query_sw_info(amdgpu_device_handle dev, enum amdgpu_sw_info info, 1258 void *value); 1259 1260/** 1261 * Query information about GDS 1262 * 1263 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize() 1264 * \param gds_info - \c [out] Pointer to structure to get GDS information 1265 * 1266 * \return 0 on success\n 1267 * <0 - Negative POSIX Error code 1268 * 1269*/ 1270int amdgpu_query_gds_info(amdgpu_device_handle dev, 1271 struct amdgpu_gds_resource_info *gds_info); 1272 1273/** 1274 * Query information about sensor. 1275 * 1276 * The return size is query-specific and depends on the "sensor_type" 1277 * parameter. No more than "size" bytes is returned. 1278 * 1279 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize() 1280 * \param sensor_type - \c [in] AMDGPU_INFO_SENSOR_* 1281 * \param size - \c [in] Size of the returned value. 1282 * \param value - \c [out] Pointer to the return value. 1283 * 1284 * \return 0 on success\n 1285 * <0 - Negative POSIX Error code 1286 * 1287*/ 1288int amdgpu_query_sensor_info(amdgpu_device_handle dev, unsigned sensor_type, 1289 unsigned size, void *value); 1290 1291/** 1292 * Query information about video capabilities 1293 * 1294 * The return sizeof(struct drm_amdgpu_info_video_caps) 1295 * 1296 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize() 1297 * \param caps_type - \c [in] AMDGPU_INFO_VIDEO_CAPS_DECODE(ENCODE) 1298 * \param size - \c [in] Size of the returned value. 1299 * \param value - \c [out] Pointer to the return value. 1300 * 1301 * \return 0 on success\n 1302 * <0 - Negative POSIX Error code 1303 * 1304*/ 1305int amdgpu_query_video_caps_info(amdgpu_device_handle dev, unsigned cap_type, 1306 unsigned size, void *value); 1307 1308/** 1309 * Query information about VM faults 1310 * 1311 * The return sizeof(struct drm_amdgpu_info_gpuvm_fault) 1312 * 1313 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize() 1314 * \param size - \c [in] Size of the returned value. 1315 * \param value - \c [out] Pointer to the return value. 1316 * 1317 * \return 0 on success\n 1318 * <0 - Negative POSIX Error code 1319 * 1320*/ 1321int amdgpu_query_gpuvm_fault_info(amdgpu_device_handle dev, unsigned size, 1322 void *value); 1323 1324/** 1325 * Read a set of consecutive memory-mapped registers. 1326 * Not all registers are allowed to be read by userspace. 1327 * 1328 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize( 1329 * \param dword_offset - \c [in] Register offset in dwords 1330 * \param count - \c [in] The number of registers to read starting 1331 * from the offset 1332 * \param instance - \c [in] GRBM_GFX_INDEX selector. It may have other 1333 * uses. Set it to 0xffffffff if unsure. 1334 * \param flags - \c [in] Flags with additional information. 1335 * \param values - \c [out] The pointer to return values. 1336 * 1337 * \return 0 on success\n 1338 * <0 - Negative POSIX error code 1339 * 1340*/ 1341int amdgpu_read_mm_registers(amdgpu_device_handle dev, unsigned dword_offset, 1342 unsigned count, uint32_t instance, uint32_t flags, 1343 uint32_t *values); 1344 1345/** 1346 * Flag to request VA address range in the 32bit address space 1347*/ 1348#define AMDGPU_VA_RANGE_32_BIT 0x1 1349#define AMDGPU_VA_RANGE_HIGH 0x2 1350#define AMDGPU_VA_RANGE_REPLAYABLE 0x4 1351 1352/** 1353 * Allocate virtual address range 1354 * 1355 * \param dev - [in] Device handle. See #amdgpu_device_initialize() 1356 * \param va_range_type - \c [in] Type of MC va range from which to allocate 1357 * \param size - \c [in] Size of range. Size must be correctly* aligned. 1358 * It is client responsibility to correctly aligned size based on the future 1359 * usage of allocated range. 1360 * \param va_base_alignment - \c [in] Overwrite base address alignment 1361 * requirement for GPU VM MC virtual 1362 * address assignment. Must be multiple of size alignments received as 1363 * 'amdgpu_buffer_size_alignments'. 1364 * If 0 use the default one. 1365 * \param va_base_required - \c [in] Specified required va base address. 1366 * If 0 then library choose available one. 1367 * If !0 value will be passed and those value already "in use" then 1368 * corresponding error status will be returned. 1369 * \param va_base_allocated - \c [out] On return: Allocated VA base to be used 1370 * by client. 1371 * \param va_range_handle - \c [out] On return: Handle assigned to allocation 1372 * \param flags - \c [in] flags for special VA range 1373 * 1374 * \return 0 on success\n 1375 * >0 - AMD specific error code\n 1376 * <0 - Negative POSIX Error code 1377 * 1378 * \notes \n 1379 * It is client responsibility to correctly handle VA assignments and usage. 1380 * Neither kernel driver nor libdrm_amdpgu are able to prevent and 1381 * detect wrong va assignment. 1382 * 1383 * It is client responsibility to correctly handle multi-GPU cases and to pass 1384 * the corresponding arrays of all devices handles where corresponding VA will 1385 * be used. 1386 * 1387*/ 1388int amdgpu_va_range_alloc(amdgpu_device_handle dev, 1389 enum amdgpu_gpu_va_range va_range_type, 1390 uint64_t size, 1391 uint64_t va_base_alignment, 1392 uint64_t va_base_required, 1393 uint64_t *va_base_allocated, 1394 amdgpu_va_handle *va_range_handle, 1395 uint64_t flags); 1396 1397/** 1398 * Free previously allocated virtual address range 1399 * 1400 * 1401 * \param va_range_handle - \c [in] Handle assigned to VA allocation 1402 * 1403 * \return 0 on success\n 1404 * >0 - AMD specific error code\n 1405 * <0 - Negative POSIX Error code 1406 * 1407*/ 1408int amdgpu_va_range_free(amdgpu_va_handle va_range_handle); 1409 1410/** 1411 * Return the starting address of the allocated virtual address range. 1412 */ 1413uint64_t amdgpu_va_get_start_addr(amdgpu_va_handle va_handle); 1414 1415/** 1416* Query virtual address range 1417* 1418* UMD can query GPU VM range supported by each device 1419* to initialize its own VAM accordingly. 1420* 1421* \param dev - [in] Device handle. See #amdgpu_device_initialize() 1422* \param type - \c [in] Type of virtual address range 1423* \param offset - \c [out] Start offset of virtual address range 1424* \param size - \c [out] Size of virtual address range 1425* 1426* \return 0 on success\n 1427* <0 - Negative POSIX Error code 1428* 1429*/ 1430 1431int amdgpu_va_range_query(amdgpu_device_handle dev, 1432 enum amdgpu_gpu_va_range type, 1433 uint64_t *start, 1434 uint64_t *end); 1435 1436/** 1437 * Allocate a amdgpu_va_manager object. 1438 * The returned object has be initialized with the amdgpu_va_manager_init 1439 * before use. 1440 * On release, amdgpu_va_manager_deinit needs to be called, then the memory 1441 * can be released using free(). 1442 */ 1443amdgpu_va_manager_handle amdgpu_va_manager_alloc(void); 1444 1445void amdgpu_va_manager_init(amdgpu_va_manager_handle va_mgr, 1446 uint64_t low_va_offset, uint64_t low_va_max, 1447 uint64_t high_va_offset, uint64_t high_va_max, 1448 uint32_t virtual_address_alignment); 1449 1450void amdgpu_va_manager_deinit(amdgpu_va_manager_handle va_mgr); 1451 1452/** 1453 * Similar to #amdgpu_va_range_alloc() but allocates VA 1454 * directly from an amdgpu_va_manager_handle instead of using 1455 * the manager from an amdgpu_device. 1456 */ 1457 1458int amdgpu_va_range_alloc2(amdgpu_va_manager_handle va_mgr, 1459 enum amdgpu_gpu_va_range va_range_type, 1460 uint64_t size, 1461 uint64_t va_base_alignment, 1462 uint64_t va_base_required, 1463 uint64_t *va_base_allocated, 1464 amdgpu_va_handle *va_range_handle, 1465 uint64_t flags); 1466 1467/** 1468 * VA mapping/unmapping for the buffer object 1469 * 1470 * \param bo - \c [in] BO handle 1471 * \param offset - \c [in] Start offset to map 1472 * \param size - \c [in] Size to map 1473 * \param addr - \c [in] Start virtual address. 1474 * \param flags - \c [in] Supported flags for mapping/unmapping 1475 * \param ops - \c [in] AMDGPU_VA_OP_MAP or AMDGPU_VA_OP_UNMAP 1476 * 1477 * \return 0 on success\n 1478 * <0 - Negative POSIX Error code 1479 * 1480*/ 1481 1482int amdgpu_bo_va_op(amdgpu_bo_handle bo, 1483 uint64_t offset, 1484 uint64_t size, 1485 uint64_t addr, 1486 uint64_t flags, 1487 uint32_t ops); 1488 1489/** 1490 * VA mapping/unmapping for a buffer object or PRT region. 1491 * 1492 * This is not a simple drop-in extension for amdgpu_bo_va_op; instead, all 1493 * parameters are treated "raw", i.e. size is not automatically aligned, and 1494 * all flags must be specified explicitly. 1495 * 1496 * \param dev - \c [in] device handle 1497 * \param bo - \c [in] BO handle (may be NULL) 1498 * \param offset - \c [in] Start offset to map 1499 * \param size - \c [in] Size to map 1500 * \param addr - \c [in] Start virtual address. 1501 * \param flags - \c [in] Supported flags for mapping/unmapping 1502 * \param ops - \c [in] AMDGPU_VA_OP_MAP or AMDGPU_VA_OP_UNMAP 1503 * 1504 * \return 0 on success\n 1505 * <0 - Negative POSIX Error code 1506 * 1507*/ 1508 1509int amdgpu_bo_va_op_raw(amdgpu_device_handle dev, 1510 amdgpu_bo_handle bo, 1511 uint64_t offset, 1512 uint64_t size, 1513 uint64_t addr, 1514 uint64_t flags, 1515 uint32_t ops); 1516 1517/** 1518 * create semaphore 1519 * 1520 * \param sem - \c [out] semaphore handle 1521 * 1522 * \return 0 on success\n 1523 * <0 - Negative POSIX Error code 1524 * 1525*/ 1526int amdgpu_cs_create_semaphore(amdgpu_semaphore_handle *sem); 1527 1528/** 1529 * signal semaphore 1530 * 1531 * \param context - \c [in] GPU Context 1532 * \param ip_type - \c [in] Hardware IP block type = AMDGPU_HW_IP_* 1533 * \param ip_instance - \c [in] Index of the IP block of the same type 1534 * \param ring - \c [in] Specify ring index of the IP 1535 * \param sem - \c [in] semaphore handle 1536 * 1537 * \return 0 on success\n 1538 * <0 - Negative POSIX Error code 1539 * 1540*/ 1541int amdgpu_cs_signal_semaphore(amdgpu_context_handle ctx, 1542 uint32_t ip_type, 1543 uint32_t ip_instance, 1544 uint32_t ring, 1545 amdgpu_semaphore_handle sem); 1546 1547/** 1548 * wait semaphore 1549 * 1550 * \param context - \c [in] GPU Context 1551 * \param ip_type - \c [in] Hardware IP block type = AMDGPU_HW_IP_* 1552 * \param ip_instance - \c [in] Index of the IP block of the same type 1553 * \param ring - \c [in] Specify ring index of the IP 1554 * \param sem - \c [in] semaphore handle 1555 * 1556 * \return 0 on success\n 1557 * <0 - Negative POSIX Error code 1558 * 1559*/ 1560int amdgpu_cs_wait_semaphore(amdgpu_context_handle ctx, 1561 uint32_t ip_type, 1562 uint32_t ip_instance, 1563 uint32_t ring, 1564 amdgpu_semaphore_handle sem); 1565 1566/** 1567 * destroy semaphore 1568 * 1569 * \param sem - \c [in] semaphore handle 1570 * 1571 * \return 0 on success\n 1572 * <0 - Negative POSIX Error code 1573 * 1574*/ 1575int amdgpu_cs_destroy_semaphore(amdgpu_semaphore_handle sem); 1576 1577/** 1578 * Get the ASIC marketing name 1579 * 1580 * \param dev - \c [in] Device handle. See #amdgpu_device_initialize() 1581 * 1582 * \return the constant string of the marketing name 1583 * "NULL" means the ASIC is not found 1584*/ 1585const char *amdgpu_get_marketing_name(amdgpu_device_handle dev); 1586 1587/** 1588 * Create kernel sync object 1589 * 1590 * \param dev - \c [in] device handle 1591 * \param flags - \c [in] flags that affect creation 1592 * \param syncobj - \c [out] sync object handle 1593 * 1594 * \return 0 on success\n 1595 * <0 - Negative POSIX Error code 1596 * 1597*/ 1598int amdgpu_cs_create_syncobj2(amdgpu_device_handle dev, 1599 uint32_t flags, 1600 uint32_t *syncobj); 1601 1602/** 1603 * Create kernel sync object 1604 * 1605 * \param dev - \c [in] device handle 1606 * \param syncobj - \c [out] sync object handle 1607 * 1608 * \return 0 on success\n 1609 * <0 - Negative POSIX Error code 1610 * 1611*/ 1612int amdgpu_cs_create_syncobj(amdgpu_device_handle dev, 1613 uint32_t *syncobj); 1614/** 1615 * Destroy kernel sync object 1616 * 1617 * \param dev - \c [in] device handle 1618 * \param syncobj - \c [in] sync object handle 1619 * 1620 * \return 0 on success\n 1621 * <0 - Negative POSIX Error code 1622 * 1623*/ 1624int amdgpu_cs_destroy_syncobj(amdgpu_device_handle dev, 1625 uint32_t syncobj); 1626 1627/** 1628 * Reset kernel sync objects to unsignalled state. 1629 * 1630 * \param dev - \c [in] device handle 1631 * \param syncobjs - \c [in] array of sync object handles 1632 * \param syncobj_count - \c [in] number of handles in syncobjs 1633 * 1634 * \return 0 on success\n 1635 * <0 - Negative POSIX Error code 1636 * 1637*/ 1638int amdgpu_cs_syncobj_reset(amdgpu_device_handle dev, 1639 const uint32_t *syncobjs, uint32_t syncobj_count); 1640 1641/** 1642 * Signal kernel sync objects. 1643 * 1644 * \param dev - \c [in] device handle 1645 * \param syncobjs - \c [in] array of sync object handles 1646 * \param syncobj_count - \c [in] number of handles in syncobjs 1647 * 1648 * \return 0 on success\n 1649 * <0 - Negative POSIX Error code 1650 * 1651*/ 1652int amdgpu_cs_syncobj_signal(amdgpu_device_handle dev, 1653 const uint32_t *syncobjs, uint32_t syncobj_count); 1654 1655/** 1656 * Signal kernel timeline sync objects. 1657 * 1658 * \param dev - \c [in] device handle 1659 * \param syncobjs - \c [in] array of sync object handles 1660 * \param points - \c [in] array of timeline points 1661 * \param syncobj_count - \c [in] number of handles in syncobjs 1662 * 1663 * \return 0 on success\n 1664 * <0 - Negative POSIX Error code 1665 * 1666*/ 1667int amdgpu_cs_syncobj_timeline_signal(amdgpu_device_handle dev, 1668 const uint32_t *syncobjs, 1669 uint64_t *points, 1670 uint32_t syncobj_count); 1671 1672/** 1673 * Wait for one or all sync objects to signal. 1674 * 1675 * \param dev - \c [in] self-explanatory 1676 * \param handles - \c [in] array of sync object handles 1677 * \param num_handles - \c [in] self-explanatory 1678 * \param timeout_nsec - \c [in] self-explanatory 1679 * \param flags - \c [in] a bitmask of DRM_SYNCOBJ_WAIT_FLAGS_* 1680 * \param first_signaled - \c [in] self-explanatory 1681 * 1682 * \return 0 on success\n 1683 * -ETIME - Timeout 1684 * <0 - Negative POSIX Error code 1685 * 1686 */ 1687int amdgpu_cs_syncobj_wait(amdgpu_device_handle dev, 1688 uint32_t *handles, unsigned num_handles, 1689 int64_t timeout_nsec, unsigned flags, 1690 uint32_t *first_signaled); 1691 1692/** 1693 * Wait for one or all sync objects on their points to signal. 1694 * 1695 * \param dev - \c [in] self-explanatory 1696 * \param handles - \c [in] array of sync object handles 1697 * \param points - \c [in] array of sync points to wait 1698 * \param num_handles - \c [in] self-explanatory 1699 * \param timeout_nsec - \c [in] self-explanatory 1700 * \param flags - \c [in] a bitmask of DRM_SYNCOBJ_WAIT_FLAGS_* 1701 * \param first_signaled - \c [in] self-explanatory 1702 * 1703 * \return 0 on success\n 1704 * -ETIME - Timeout 1705 * <0 - Negative POSIX Error code 1706 * 1707 */ 1708int amdgpu_cs_syncobj_timeline_wait(amdgpu_device_handle dev, 1709 uint32_t *handles, uint64_t *points, 1710 unsigned num_handles, 1711 int64_t timeout_nsec, unsigned flags, 1712 uint32_t *first_signaled); 1713/** 1714 * Query sync objects payloads. 1715 * 1716 * \param dev - \c [in] self-explanatory 1717 * \param handles - \c [in] array of sync object handles 1718 * \param points - \c [out] array of sync points returned, which presents 1719 * syncobj payload. 1720 * \param num_handles - \c [in] self-explanatory 1721 * 1722 * \return 0 on success\n 1723 * -ETIME - Timeout 1724 * <0 - Negative POSIX Error code 1725 * 1726 */ 1727int amdgpu_cs_syncobj_query(amdgpu_device_handle dev, 1728 uint32_t *handles, uint64_t *points, 1729 unsigned num_handles); 1730/** 1731 * Query sync objects last signaled or submitted point. 1732 * 1733 * \param dev - \c [in] self-explanatory 1734 * \param handles - \c [in] array of sync object handles 1735 * \param points - \c [out] array of sync points returned, which presents 1736 * syncobj payload. 1737 * \param num_handles - \c [in] self-explanatory 1738 * \param flags - \c [in] a bitmask of DRM_SYNCOBJ_QUERY_FLAGS_* 1739 * 1740 * \return 0 on success\n 1741 * -ETIME - Timeout 1742 * <0 - Negative POSIX Error code 1743 * 1744 */ 1745int amdgpu_cs_syncobj_query2(amdgpu_device_handle dev, 1746 uint32_t *handles, uint64_t *points, 1747 unsigned num_handles, uint32_t flags); 1748 1749/** 1750 * Export kernel sync object to shareable fd. 1751 * 1752 * \param dev - \c [in] device handle 1753 * \param syncobj - \c [in] sync object handle 1754 * \param shared_fd - \c [out] shared file descriptor. 1755 * 1756 * \return 0 on success\n 1757 * <0 - Negative POSIX Error code 1758 * 1759*/ 1760int amdgpu_cs_export_syncobj(amdgpu_device_handle dev, 1761 uint32_t syncobj, 1762 int *shared_fd); 1763/** 1764 * Import kernel sync object from shareable fd. 1765 * 1766 * \param dev - \c [in] device handle 1767 * \param shared_fd - \c [in] shared file descriptor. 1768 * \param syncobj - \c [out] sync object handle 1769 * 1770 * \return 0 on success\n 1771 * <0 - Negative POSIX Error code 1772 * 1773*/ 1774int amdgpu_cs_import_syncobj(amdgpu_device_handle dev, 1775 int shared_fd, 1776 uint32_t *syncobj); 1777 1778/** 1779 * Export kernel sync object to a sync_file. 1780 * 1781 * \param dev - \c [in] device handle 1782 * \param syncobj - \c [in] sync object handle 1783 * \param sync_file_fd - \c [out] sync_file file descriptor. 1784 * 1785 * \return 0 on success\n 1786 * <0 - Negative POSIX Error code 1787 * 1788 */ 1789int amdgpu_cs_syncobj_export_sync_file(amdgpu_device_handle dev, 1790 uint32_t syncobj, 1791 int *sync_file_fd); 1792 1793/** 1794 * Import kernel sync object from a sync_file. 1795 * 1796 * \param dev - \c [in] device handle 1797 * \param syncobj - \c [in] sync object handle 1798 * \param sync_file_fd - \c [in] sync_file file descriptor. 1799 * 1800 * \return 0 on success\n 1801 * <0 - Negative POSIX Error code 1802 * 1803 */ 1804int amdgpu_cs_syncobj_import_sync_file(amdgpu_device_handle dev, 1805 uint32_t syncobj, 1806 int sync_file_fd); 1807/** 1808 * Export kernel timeline sync object to a sync_file. 1809 * 1810 * \param dev - \c [in] device handle 1811 * \param syncobj - \c [in] sync object handle 1812 * \param point - \c [in] timeline point 1813 * \param flags - \c [in] flags 1814 * \param sync_file_fd - \c [out] sync_file file descriptor. 1815 * 1816 * \return 0 on success\n 1817 * <0 - Negative POSIX Error code 1818 * 1819 */ 1820int amdgpu_cs_syncobj_export_sync_file2(amdgpu_device_handle dev, 1821 uint32_t syncobj, 1822 uint64_t point, 1823 uint32_t flags, 1824 int *sync_file_fd); 1825 1826/** 1827 * Import kernel timeline sync object from a sync_file. 1828 * 1829 * \param dev - \c [in] device handle 1830 * \param syncobj - \c [in] sync object handle 1831 * \param point - \c [in] timeline point 1832 * \param sync_file_fd - \c [in] sync_file file descriptor. 1833 * 1834 * \return 0 on success\n 1835 * <0 - Negative POSIX Error code 1836 * 1837 */ 1838int amdgpu_cs_syncobj_import_sync_file2(amdgpu_device_handle dev, 1839 uint32_t syncobj, 1840 uint64_t point, 1841 int sync_file_fd); 1842 1843/** 1844 * transfer between syncbojs. 1845 * 1846 * \param dev - \c [in] device handle 1847 * \param dst_handle - \c [in] sync object handle 1848 * \param dst_point - \c [in] timeline point, 0 presents dst is binary 1849 * \param src_handle - \c [in] sync object handle 1850 * \param src_point - \c [in] timeline point, 0 presents src is binary 1851 * \param flags - \c [in] flags 1852 * 1853 * \return 0 on success\n 1854 * <0 - Negative POSIX Error code 1855 * 1856 */ 1857int amdgpu_cs_syncobj_transfer(amdgpu_device_handle dev, 1858 uint32_t dst_handle, 1859 uint64_t dst_point, 1860 uint32_t src_handle, 1861 uint64_t src_point, 1862 uint32_t flags); 1863 1864/** 1865 * Export an amdgpu fence as a handle (syncobj or fd). 1866 * 1867 * \param what AMDGPU_FENCE_TO_HANDLE_GET_{SYNCOBJ, FD} 1868 * \param out_handle returned handle 1869 * 1870 * \return 0 on success\n 1871 * <0 - Negative POSIX Error code 1872 */ 1873int amdgpu_cs_fence_to_handle(amdgpu_device_handle dev, 1874 struct amdgpu_cs_fence *fence, 1875 uint32_t what, 1876 uint32_t *out_handle); 1877 1878/** 1879 * Submit raw command submission to kernel 1880 * 1881 * \param dev - \c [in] device handle 1882 * \param context - \c [in] context handle for context id 1883 * \param bo_list_handle - \c [in] request bo list handle (0 for none) 1884 * \param num_chunks - \c [in] number of CS chunks to submit 1885 * \param chunks - \c [in] array of CS chunks 1886 * \param seq_no - \c [out] output sequence number for submission. 1887 * 1888 * \return 0 on success\n 1889 * <0 - Negative POSIX Error code 1890 * 1891 */ 1892struct drm_amdgpu_cs_chunk; 1893struct drm_amdgpu_cs_chunk_dep; 1894struct drm_amdgpu_cs_chunk_data; 1895 1896int amdgpu_cs_submit_raw(amdgpu_device_handle dev, 1897 amdgpu_context_handle context, 1898 amdgpu_bo_list_handle bo_list_handle, 1899 int num_chunks, 1900 struct drm_amdgpu_cs_chunk *chunks, 1901 uint64_t *seq_no); 1902 1903/** 1904 * Submit raw command submission to the kernel with a raw BO list handle. 1905 * 1906 * \param dev - \c [in] device handle 1907 * \param context - \c [in] context handle for context id 1908 * \param bo_list_handle - \c [in] raw bo list handle (0 for none) 1909 * \param num_chunks - \c [in] number of CS chunks to submit 1910 * \param chunks - \c [in] array of CS chunks 1911 * \param seq_no - \c [out] output sequence number for submission. 1912 * 1913 * \return 0 on success\n 1914 * <0 - Negative POSIX Error code 1915 * 1916 * \sa amdgpu_bo_list_create_raw(), amdgpu_bo_list_destroy_raw() 1917 */ 1918int amdgpu_cs_submit_raw2(amdgpu_device_handle dev, 1919 amdgpu_context_handle context, 1920 uint32_t bo_list_handle, 1921 int num_chunks, 1922 struct drm_amdgpu_cs_chunk *chunks, 1923 uint64_t *seq_no); 1924 1925void amdgpu_cs_chunk_fence_to_dep(struct amdgpu_cs_fence *fence, 1926 struct drm_amdgpu_cs_chunk_dep *dep); 1927void amdgpu_cs_chunk_fence_info_to_data(struct amdgpu_cs_fence_info *fence_info, 1928 struct drm_amdgpu_cs_chunk_data *data); 1929 1930/** 1931 * Reserve VMID 1932 * \param context - \c [in] GPU Context 1933 * \param flags - \c [in] TBD 1934 * 1935 * \return 0 on success otherwise POSIX Error code 1936*/ 1937int amdgpu_vm_reserve_vmid(amdgpu_device_handle dev, uint32_t flags); 1938 1939/** 1940 * Free reserved VMID 1941 * \param context - \c [in] GPU Context 1942 * \param flags - \c [in] TBD 1943 * 1944 * \return 0 on success otherwise POSIX Error code 1945*/ 1946int amdgpu_vm_unreserve_vmid(amdgpu_device_handle dev, uint32_t flags); 1947 1948#ifdef __cplusplus 1949} 1950#endif 1951#endif /* #ifdef _AMDGPU_H_ */ 1952