amdgpu.h 36 KB

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