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