hgsl.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. /* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
  2. /*
  3. * Copyright (c) 2019-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _UAPI_MSM_HGSL_H
  7. #define _UAPI_MSM_HGSL_H
  8. #include <linux/types.h>
  9. #include <linux/ioctl.h>
  10. #define HGSL_SYNC_TYPE_HSYNC 1
  11. #define HGSL_SYNC_TYPE_ISYNC 2
  12. struct hgsl_ibdesc {
  13. __u64 gpuaddr;
  14. __u64 sizedwords;
  15. };
  16. struct hgsl_mem_object {
  17. __u64 gpuaddr;
  18. __u64 sizedwords;
  19. };
  20. #define HGSL_IOCTL_BASE 'h'
  21. #define HGSL_IORW(n, t) _IOWR(HGSL_IOCTL_BASE, n, t)
  22. #define HGSL_IOW(n, t) _IOW(HGSL_IOCTL_BASE, n, t)
  23. /**
  24. * return current status of Doorbell system
  25. */
  26. #define DB_STATE_Q_MASK 0xffff
  27. #define DB_STATE_Q_UNINIT 1
  28. #define DB_STATE_Q_INIT_DONE 2
  29. #define DB_STATE_Q_FAULT 3
  30. #define HGSL_IOCTL_DBQ_GETSTATE HGSL_IORW(0x01, __s32)
  31. /**
  32. * struct hgsl_db_queue_inf - initialize Doorbell
  33. * @fd: File descriptor of DB queue
  34. * @head_dwords: Size of DB queue header
  35. * @head_off_dwords: offset of DB queue header
  36. * @queue_dwords: size of DB queue
  37. * @queue_off_dwords: offset of DB queue
  38. * @db_signal: DB signal type, One of DB_SIGNAL_* values
  39. *
  40. **/
  41. struct hgsl_db_queue_inf {
  42. __s32 fd;
  43. __u32 head_dwords;
  44. __s32 head_off_dwords;
  45. __u32 queue_dwords;
  46. __s32 queue_off_dwords;
  47. __u32 db_signal;
  48. };
  49. #define DB_SIGNAL_INVALID 0
  50. #define DB_SIGNAL_GLOBAL_0 1
  51. #define DB_SIGNAL_GLOBAL_1 2
  52. #define DB_SIGNAL_LOCAL 3
  53. #define DB_SIGNAL_MAX DB_SIGNAL_LOCAL
  54. #define HGSL_IOCTL_DBQ_INIT \
  55. HGSL_IORW(0x02, struct hgsl_db_queue_inf)
  56. /**
  57. * Assign a DB to current instance, input is DB index.
  58. */
  59. #define HGSL_IOCTL_DBQ_ASSIGN HGSL_IORW(0x03, __u32)
  60. /**
  61. * struct hgsl_dbq_release_info - release DB queue
  62. * @ref_count; userspace could inform PVM to do cleanup
  63. * if this param is zero
  64. * @ctxt_id: Current context
  65. */
  66. struct hgsl_dbq_release_info {
  67. __u32 ref_count;
  68. __u32 ctxt_id;
  69. };
  70. #define HGSL_IOCTL_DBQ_RELEASE \
  71. HGSL_IORW(0x04, struct hgsl_dbq_release_info)
  72. /**
  73. * struct hgsl_fhi_issud_cmds - submit cmds to DB queue
  74. * @ibs: db commands list
  75. * @num_ibs: Number of db commands
  76. * @bos: buffer objects list
  77. * @num_bos: Number of buffer objects
  78. * @context_id: Current context for these cmds
  79. * @flags: reserved
  80. * @timestamp: Userspace time stamp
  81. */
  82. struct hgsl_fhi_issud_cmds {
  83. __u64 ibs;
  84. __u32 num_ibs;
  85. __u64 bos;
  86. __u32 num_bos;
  87. __u32 context_id;
  88. __u32 flags;
  89. __u32 timestamp;
  90. __u32 padding;
  91. };
  92. #define HGSL_IOCTL_ISSUE_CMDS \
  93. HGSL_IORW(0x05, struct hgsl_fhi_issud_cmds)
  94. /**
  95. * struct hgsl_ctxt_create_info - create a DB context
  96. * @context_id: Current context for these cmds
  97. * @shadow_fd: File descriptor of time stamp buffer
  98. * @shadow_sop_offset: Offset for start timestamp written
  99. * by GPU before cmds
  100. * @shadow_eop_offset: Offset for end timestamp written
  101. * by GPU after cmds
  102. */
  103. struct hgsl_ctxt_create_info {
  104. __u32 context_id;
  105. __s32 shadow_fd;
  106. __u32 shadow_sop_offset;
  107. __u32 shadow_eop_offset;
  108. };
  109. struct hgsl_ioctl_ctxt_create_params {
  110. __u32 devhandle;
  111. __u32 type;
  112. __u32 flags;
  113. __u32 ctxthandle;
  114. __u32 sync_type;
  115. __u32 padding;
  116. };
  117. #define HGSL_IOCTL_CTXT_CREATE HGSL_IOW(0x10, \
  118. struct hgsl_ioctl_ctxt_create_params)
  119. struct hgsl_ioctl_ctxt_destroy_params {
  120. __u32 devhandle;
  121. __u32 ctxthandle;
  122. __u32 rval;
  123. __u32 padding;
  124. };
  125. #define HGSL_IOCTL_CTXT_DESTROY HGSL_IOW(0x11, \
  126. struct hgsl_ioctl_ctxt_destroy_params)
  127. /**
  128. * struct hgsl_wait_ts_info - wait a timestamp to be retired
  129. * @timestamp: The user timestamp to wait
  130. * @timeout: Expiry timeout
  131. */
  132. struct hgsl_wait_ts_info {
  133. __u32 context_id;
  134. __u32 timestamp;
  135. __u32 timeout;
  136. __u32 padding;
  137. __u32 devhandle;
  138. __u32 channel_id;
  139. };
  140. #define HGSL_IOCTL_WAIT_TIMESTAMP \
  141. HGSL_IOW(0x12, struct hgsl_wait_ts_info)
  142. /**
  143. * struct hgsl_ioctl_issueib_params - submit cmds to GPU
  144. * @ibs: db commands list
  145. * @devhandle: GPU device handle
  146. * @ctxthandle: Current context handle for the cmds
  147. * @timestamp: Userspace time stamp
  148. * @flags: reserved
  149. * @num_ibs: Number of ib cmds
  150. * @rval: return value from host
  151. * @channel_id: hab channel id
  152. */
  153. struct hgsl_ioctl_issueib_params {
  154. __u64 ibs;
  155. __u32 devhandle;
  156. __u32 ctxthandle;
  157. __u32 timestamp;
  158. __u32 flags;
  159. __u32 num_ibs;
  160. __u32 rval;
  161. __u32 channel_id;
  162. __u32 padding;
  163. };
  164. #define HGSL_IOCTL_ISSUE_IB \
  165. HGSL_IORW(0x20, struct hgsl_ioctl_issueib_params)
  166. struct hgsl_ioctl_issueib_with_alloc_list_params {
  167. __u64 rpc_syncobj;
  168. __u64 ibs;
  169. __u64 allocations;
  170. __u64 be_data;
  171. __u32 devhandle;
  172. __u32 ctxthandle;
  173. __u32 timestamp;
  174. __u32 flags;
  175. __u32 num_ibs;
  176. __u32 num_allocations;
  177. __u32 rval;
  178. __u32 channel_id;
  179. };
  180. #define HGSL_IOCTL_ISSUIB_WITH_ALLOC_LIST \
  181. HGSL_IORW(0x21, struct hgsl_ioctl_issueib_with_alloc_list_params)
  182. #define HGSL_HYP_GENERAL_MAX_SEND_NUM 2
  183. #define HGSL_HYP_GENERAL_MAX_REPLY_NUM 1
  184. struct hgsl_ioctl_hyp_generic_transaction_params {
  185. __u64 send_data[HGSL_HYP_GENERAL_MAX_SEND_NUM];
  186. __u64 reply_data[HGSL_HYP_GENERAL_MAX_REPLY_NUM];
  187. __u32 send_size[HGSL_HYP_GENERAL_MAX_SEND_NUM];
  188. __u32 reply_size[HGSL_HYP_GENERAL_MAX_REPLY_NUM];
  189. __u32 send_num;
  190. __u32 reply_num;
  191. __u32 cmd_id;
  192. __u64 ret_value;
  193. };
  194. #define HGSL_IOCTL_HYP_GENERIC_TRANSACTION \
  195. HGSL_IORW(0x22, struct hgsl_ioctl_hyp_generic_transaction_params)
  196. struct hgsl_ioctl_get_shadowts_mem_params {
  197. __u64 size;
  198. __u32 device_id;
  199. __u32 ctxthandle;
  200. __u32 flags;
  201. __s32 fd;
  202. };
  203. #define HGSL_IOCTL_GET_SHADOWTS_MEM \
  204. HGSL_IORW(0x23, struct hgsl_ioctl_get_shadowts_mem_params)
  205. struct hgsl_ioctl_put_shadowts_mem_params {
  206. __u32 ctxthandle;
  207. __u32 padding;
  208. };
  209. #define HGSL_IOCTL_PUT_SHADOWTS_MEM \
  210. HGSL_IOW(0x24, struct hgsl_ioctl_put_shadowts_mem_params)
  211. struct hgsl_ioctl_mem_alloc_params {
  212. __u64 memdesc;
  213. __u32 sizebytes;
  214. __u32 flags;
  215. __s32 fd;
  216. __u32 padding;
  217. };
  218. #define HGSL_IOCTL_MEM_ALLOC \
  219. HGSL_IORW(0x25, struct hgsl_ioctl_mem_alloc_params)
  220. struct hgsl_ioctl_mem_free_params {
  221. __u64 memdesc;
  222. };
  223. #define HGSL_IOCTL_MEM_FREE \
  224. HGSL_IORW(0x26, struct hgsl_ioctl_mem_free_params)
  225. struct hgsl_ioctl_mem_map_smmu_params {
  226. __u64 size;
  227. __u64 offset;
  228. __u64 uva;
  229. __u64 memdesc;
  230. __s32 fd;
  231. __u32 memtype;
  232. __u32 flags;
  233. __u32 padding;
  234. };
  235. #define HGSL_IOCTL_MEM_MAP_SMMU \
  236. HGSL_IORW(0x27, struct hgsl_ioctl_mem_map_smmu_params)
  237. struct hgsl_ioctl_mem_unmap_smmu_params {
  238. __u64 gpuaddr;
  239. __u64 size;
  240. __u32 memtype;
  241. __u32 padding;
  242. };
  243. #define HGSL_IOCTL_MEM_UNMAP_SMMU \
  244. HGSL_IOW(0x28, struct hgsl_ioctl_mem_unmap_smmu_params)
  245. struct hgsl_ioctl_mem_cache_operation_params {
  246. __u64 offsetbytes;
  247. __u64 sizebytes;
  248. __u64 gpuaddr;
  249. __u32 operation;
  250. __u32 padding;
  251. };
  252. #define HGSL_IOCTL_MEM_CACHE_OPERATION \
  253. HGSL_IORW(0x29, struct hgsl_ioctl_mem_cache_operation_params)
  254. struct hgsl_ioctl_read_ts_params {
  255. __u32 devhandle;
  256. __u32 ctxthandle;
  257. __u32 type;
  258. __u32 timestamp;
  259. };
  260. #define HGSL_IOCTL_READ_TIMESTAMP \
  261. HGSL_IORW(0x2A, struct hgsl_ioctl_read_ts_params)
  262. struct hgsl_ioctl_check_ts_params {
  263. __u32 devhandle;
  264. __u32 ctxthandle;
  265. __u32 type;
  266. __u32 timestamp;
  267. __u32 rval;
  268. __u32 padding;
  269. };
  270. #define HGSL_IOCTL_CHECK_TIMESTAMP \
  271. HGSL_IORW(0x2B, struct hgsl_ioctl_check_ts_params)
  272. struct hgsl_ioctl_syncobj_wait_multiple_params {
  273. __u64 num_syncobjs;
  274. __u64 rpc_syncobj;
  275. __u64 status;
  276. __u32 timeout_ms;
  277. __u32 result;
  278. };
  279. #define HGSL_IOCTL_SYNCOBJ_WAIT_MULTIPLE \
  280. HGSL_IORW(0x2C, struct hgsl_ioctl_syncobj_wait_multiple_params)
  281. struct hgsl_ioctl_set_metainfo_params {
  282. __u64 memdesc_priv;
  283. __u64 metainfo;
  284. __u32 flags;
  285. __u32 metainfo_len;
  286. };
  287. #define HGSL_IOCTL_SET_METAINFO \
  288. HGSL_IORW(0x2D, struct hgsl_ioctl_set_metainfo_params)
  289. #define HGSL_IOCTL_GET_SYSTEM_TIME \
  290. HGSL_IORW(0x2E, __u64)
  291. struct hgsl_ioctl_perfcounter_select_params {
  292. __u64 groups;
  293. __u64 counter_ids;
  294. __u64 counter_val_regs;
  295. __u64 counter_val_hi_regs;
  296. __u32 devhandle;
  297. __u32 ctxthandle;
  298. __u32 num_counters;
  299. __u32 rval;
  300. };
  301. #define HGSL_IOCTL_PERFCOUNTER_SELECT \
  302. HGSL_IORW(0x30, struct hgsl_ioctl_perfcounter_select_params)
  303. struct hgsl_ioctl_perfcounter_deselect_params {
  304. __u64 groups;
  305. __u64 counter_ids;
  306. __u32 devhandle;
  307. __u32 ctxthandle;
  308. __u32 timestamp;
  309. __u32 num_counters;
  310. };
  311. #define HGSL_IOCTL_PERFCOUNTER_DESELECT \
  312. HGSL_IOW(0x31, struct hgsl_ioctl_perfcounter_deselect_params)
  313. struct hgsl_ioctl_perfcounter_query_selections_params {
  314. __u64 selections;
  315. __u32 devhandle;
  316. __u32 ctxthandle;
  317. __u32 num_counters;
  318. __u32 group;
  319. __u32 max_counters;
  320. __u32 padding;
  321. };
  322. #define HGSL_IOCTL_PERFCOUNTER_QUERY_SELECTION \
  323. HGSL_IORW(0x32, struct hgsl_ioctl_perfcounter_query_selections_params)
  324. struct hgsl_ioctl_perfcounter_read_params {
  325. __u64 value;
  326. __u32 devhandle;
  327. __u32 group;
  328. __u32 counter;
  329. __u32 rval;
  330. };
  331. #define HGSL_IOCTL_PERFCOUNTER_READ \
  332. HGSL_IORW(0x33, struct hgsl_ioctl_perfcounter_read_params)
  333. /**
  334. * struct hgsl_hsync_fence_create - wait a h-sync fence
  335. * @timestamp: The user timestamp attached to the fence
  336. * @context_id; The conext to create fence
  337. * @fence_fd: File descriptor of the new created fence
  338. */
  339. struct hgsl_hsync_fence_create {
  340. __u32 timestamp;
  341. __u32 padding;
  342. __s32 context_id;
  343. __s32 fence_fd;
  344. };
  345. #define HGSL_IOCTL_HSYNC_FENCE_CREATE \
  346. HGSL_IOW(0x13, struct hgsl_hsync_fence_create)
  347. /**
  348. * Create an i-fence timeline - param is id of the new timeline
  349. */
  350. #define HGSL_IOCTL_ISYNC_TIMELINE_CREATE \
  351. HGSL_IOW(0x14, __u32)
  352. /**
  353. * Destroy an i-fence timeline - param is id of timeline to be released
  354. */
  355. #define HGSL_IOCTL_ISYNC_TIMELINE_DESTROY \
  356. HGSL_IOW(0x15, __u32)
  357. /* Use padding field to tell if ts is valid when create isync fence */
  358. #define HGSL_ISYNC_FENCE_CREATE_USE_TS 1
  359. /**
  360. * struct hgsl_isync_create_fence - wait an i-sync fence
  361. * @timeline_id: The timestamp for the new fence
  362. * @fence_id: id of new created fence
  363. * @ts: option, should set it if want to use isync forward
  364. */
  365. struct hgsl_isync_create_fence {
  366. __u32 timeline_id;
  367. __s32 fence_id;
  368. __u32 ts;
  369. __u32 padding;
  370. };
  371. #define HGSL_IOCTL_ISYNC_FENCE_CREATE \
  372. HGSL_IOW(0x16, \
  373. struct hgsl_isync_create_fence)
  374. /**
  375. * struct hgsl_isync_signal_fence - signal an i-sync fence
  376. * @timeline_id: The timestamp for current fence
  377. * @fence_id: id of fence to be signalled
  378. */
  379. struct hgsl_isync_signal_fence {
  380. __u32 timeline_id;
  381. __s32 fence_id;
  382. };
  383. #define HGSL_IOCTL_ISYNC_FENCE_SIGNAL \
  384. HGSL_IOW(0x17, \
  385. struct hgsl_isync_signal_fence)
  386. /**
  387. * struct hgsl_isync_signal_fence - signal an i-sync fence
  388. * @timeline_id: The timestamp for current fence
  389. * @fence_id: id of fence to be signalled
  390. */
  391. struct hgsl_isync_forward {
  392. __u32 timeline_id;
  393. __s32 ts;
  394. };
  395. #define HGSL_IOCTL_ISYNC_FORWARD \
  396. HGSL_IOW(0x18, \
  397. struct hgsl_isync_forward)
  398. /**
  399. * struct hgsl_isync_timeline_create64 - create a isync timeline with 64 or 32bits timestamp
  400. * @initial_ts: The initial timestamp value.
  401. * @timeline_id: The timestamp for current fence
  402. * @flags: flags used to timeline
  403. */
  404. struct hgsl_timeline_create {
  405. __u64 initial_ts;
  406. __u32 timeline_id;
  407. __s32 flags;
  408. };
  409. #define HGSL_IOCTL_TIMELINE_CREATE \
  410. HGSL_IORW(0x19, struct hgsl_timeline_create)
  411. /**
  412. * struct hgsl_timeline_val - A container to store a timeline/sequence number
  413. * pair.
  414. * @timepoint: timepoint to signal/query/wait
  415. * @timeline: The timeline identifier to signal/query/wait
  416. *
  417. * A container to store a timeline/timepoint pair used by the query, signal and wait
  418. * ioctls.
  419. */
  420. struct hgsl_timeline_val {
  421. __u64 timepoint;
  422. __u32 timeline_id;
  423. __u32 padding;
  424. };
  425. /**
  426. * struct hgsl_timeline_query - query multiple timelines
  427. * @timelines: Address of an array of &struct hgsl_timeline_val entries
  428. * @count: Number of entries in @timeline
  429. * @timelines_size: Size of each entry in @timelines
  430. */
  431. struct hgsl_timeline_query {
  432. __u64 timelines;
  433. __u32 count;
  434. __u32 timelines_size;
  435. };
  436. #define HGSL_IOCTL_TIMELINE_QUERY \
  437. HGSL_IORW(0x1A, struct hgsl_timeline_query)
  438. /**
  439. * struct hgsl_timeline_signal - signal multiple timelines
  440. * @timelines: Address of an array of &struct hgsl_timeline_val entries
  441. * @count: Number of entries in @timeline
  442. * @timelines_size: Size of each entry in @timelines
  443. */
  444. struct hgsl_timeline_signal {
  445. __u64 timelines;
  446. __u32 count;
  447. __u32 timelines_size;
  448. };
  449. #define HGSL_IOCTL_TIMELINE_SIGNAL \
  450. HGSL_IOW(0x1B, struct hgsl_timeline_signal)
  451. #define HGSL_TIMELINE_WAIT_ALL 1
  452. #define HGSL_TIMELINE_WAIT_ANY 2
  453. /**
  454. * struct hgsl_timeline_wait - wait multiple timelines
  455. * @timeout_nanosec: Number of nanoseconds to wait for the signal
  456. * @timelines: Address of an array of &struct hgsl_timeline_val entries
  457. * @count: Number of entries in @timeline
  458. * @timelines_size: Size of each entry in @timelines
  459. * @flags: One of HGSL_TIMELINE_WAIT_ALL or HGSL_TIMELINE_WAIT_ANY
  460. */
  461. struct hgsl_timeline_wait {
  462. __u64 timeout_nanosec;
  463. __u64 timelines;
  464. __u32 count;
  465. __u32 timelines_size;
  466. __u32 flags;
  467. /* private: padding for 64 bit compatibility */
  468. __u32 padding;
  469. };
  470. #define HGSL_IOCTL_TIMELINE_WAIT \
  471. HGSL_IOW(0x1C, struct hgsl_timeline_wait)
  472. /**
  473. * struct hgsl_ioctl_mem_get_fd_params - get fd from memdesc
  474. * @memdesc: According to memdesc to find the mem node
  475. * @fd: The fd of dmabuf mem node
  476. */
  477. struct hgsl_ioctl_mem_get_fd_params {
  478. __u64 memdesc;
  479. __s32 fd;
  480. };
  481. #define HGSL_IOCTL_MEM_GET_FD \
  482. HGSL_IORW(0x1D, struct hgsl_ioctl_mem_get_fd_params)
  483. #endif /* _UAPI_MSM_HGSL_H */