amdgpu.h 63 KB

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