synx_api.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2019, 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __SYNX_API_H__
  7. #define __SYNX_API_H__
  8. #include <linux/list.h>
  9. #include <synx_header.h>
  10. #include "synx_err.h"
  11. #define SYNX_NO_TIMEOUT ((u64)-1)
  12. /**
  13. * enum synx_create_flags - Flags passed during synx_create call
  14. *
  15. * SYNX_CREATE_LOCAL_FENCE : Instructs the framework to create local synx object
  16. * SYNX_CREATE_GLOBAL_FENCE : Instructs the framework to create global synx object
  17. * SYNX_CREATE_DMA_FENCE : Create a synx object by wrapping the provided dma fence.
  18. * Need to pass the dma_fence ptr through fence variable
  19. * if this flag is set.
  20. * SYNX_CREATE_CSL_FENCE : Create a synx object with provided csl fence.
  21. * Establishes interop with the csl fence through
  22. * bind operations.
  23. */
  24. enum synx_create_flags {
  25. SYNX_CREATE_LOCAL_FENCE = 0x01,
  26. SYNX_CREATE_GLOBAL_FENCE = 0x02,
  27. SYNX_CREATE_DMA_FENCE = 0x04,
  28. SYNX_CREATE_CSL_FENCE = 0x08,
  29. SYNX_CREATE_MAX_FLAGS = 0x10,
  30. };
  31. /**
  32. * enum synx_init_flags - Session initialization flag
  33. */
  34. enum synx_init_flags {
  35. SYNX_INIT_MAX = 0x01,
  36. };
  37. /**
  38. * enum synx_import_flags - Import flags
  39. *
  40. * SYNX_IMPORT_LOCAL_FENCE : Instructs the framework to create local synx object
  41. * SYNX_IMPORT_GLOBAL_FENCE : Instructs the framework to create global synx object
  42. * SYNX_IMPORT_SYNX_FENCE : Import native Synx handle for synchronization
  43. * Need to pass the Synx handle ptr through fence variable
  44. * if this flag is set.
  45. * SYNX_IMPORT_DMA_FENCE : Import dma fence.and crate Synx handle for interop
  46. * Need to pass the dma_fence ptr through fence variable
  47. * if this flag is set.
  48. * SYNX_IMPORT_EX_RELEASE : Flag to inform relaxed invocation where release call
  49. * need not be called by client on this handle after import.
  50. */
  51. enum synx_import_flags {
  52. SYNX_IMPORT_LOCAL_FENCE = 0x01,
  53. SYNX_IMPORT_GLOBAL_FENCE = 0x02,
  54. SYNX_IMPORT_SYNX_FENCE = 0x04,
  55. SYNX_IMPORT_DMA_FENCE = 0x08,
  56. SYNX_IMPORT_EX_RELEASE = 0x10,
  57. };
  58. /**
  59. * enum synx_signal_status - Signal status
  60. *
  61. * SYNX_STATE_SIGNALED_SUCCESS : Signal success
  62. * SYNX_STATE_SIGNALED_CANCEL : Signal cancellation
  63. * SYNX_STATE_SIGNALED_MAX : Clients can send custom notification
  64. * beyond the max value (only positive)
  65. */
  66. enum synx_signal_status {
  67. SYNX_STATE_SIGNALED_SUCCESS = 2,
  68. SYNX_STATE_SIGNALED_CANCEL = 4,
  69. SYNX_STATE_SIGNALED_MAX = 64,
  70. };
  71. /**
  72. * synx_callback - Callback invoked by external fence
  73. *
  74. * External fence dispatch the registered callback to notify
  75. * signal to synx framework.
  76. */
  77. typedef void (*synx_callback)(s32 sync_obj, int status, void *data);
  78. /**
  79. * synx_user_callback - Callback function registered by clients
  80. *
  81. * User callback registered for non-blocking wait. Dispatched when
  82. * synx object is signaled or timeout has expired.
  83. */
  84. typedef void (*synx_user_callback_t)(u32 h_synx, int status, void *data);
  85. /**
  86. * struct bind_operations - Function pointers that need to be defined
  87. * to achieve bind functionality for external fence with synx obj
  88. *
  89. * @register_callback : Function to register with external sync object
  90. * @deregister_callback : Function to deregister with external sync object
  91. * @enable_signaling : Function to enable the signaling on the external
  92. * sync object (optional)
  93. * @signal : Function to signal the external sync object
  94. */
  95. struct bind_operations {
  96. int (*register_callback)(synx_callback cb_func,
  97. void *userdata, s32 sync_obj);
  98. int (*deregister_callback)(synx_callback cb_func,
  99. void *userdata, s32 sync_obj);
  100. int (*enable_signaling)(s32 sync_obj);
  101. int (*signal)(s32 sync_obj, u32 status);
  102. };
  103. /**
  104. * synx_bind_client_type : External fence supported for bind
  105. *
  106. * SYNX_TYPE_CSL : Camera CSL fence
  107. */
  108. enum synx_bind_client_type {
  109. SYNX_TYPE_CSL = 0,
  110. SYNX_MAX_BIND_TYPES,
  111. };
  112. /**
  113. * struct synx_register_params - External registration parameters
  114. *
  115. * @ops : Bind operations struct
  116. * @name : External client name
  117. * Only first 64 bytes are accepted, rest will be ignored
  118. * @type : Synx bind client type
  119. */
  120. struct synx_register_params {
  121. struct bind_operations ops;
  122. char *name;
  123. enum synx_bind_client_type type;
  124. };
  125. /**
  126. * struct synx_queue_desc - Memory descriptor of the queue allocated by
  127. * the fence driver for each client during
  128. * register.
  129. *
  130. * @vaddr : CPU virtual address of the queue.
  131. * @dev_addr : Physical address of the memory object.
  132. * @size : Size of the memory.
  133. * @mem_data : Internal pointer with the attributes of the allocation.
  134. */
  135. struct synx_queue_desc {
  136. void *vaddr;
  137. u64 dev_addr;
  138. u64 size;
  139. void *mem_data;
  140. };
  141. /**
  142. * enum synx_client_id : Unique identifier of the supported clients
  143. *
  144. * @SYNX_CLIENT_NATIVE : Native Client
  145. * @SYNX_CLIENT_GFX_CTX0 : GFX Client 0
  146. * @SYNX_CLIENT_DPU_CTL0 : DPU Client 0
  147. * @SYNX_CLIENT_DPU_CTL1 : DPU Client 1
  148. * @SYNX_CLIENT_DPU_CTL2 : DPU Client 2
  149. * @SYNX_CLIENT_DPU_CTL3 : DPU Client 3
  150. * @SYNX_CLIENT_DPU_CTL4 : DPU Client 4
  151. * @SYNX_CLIENT_DPU_CTL5 : DPU Client 5
  152. * @SYNX_CLIENT_EVA_CTX0 : EVA Client 0
  153. * @SYNX_CLIENT_VID_CTX0 : Video Client 0
  154. * @SYNX_CLIENT_NSP_CTX0 : NSP Client 0
  155. * @SYNX_CLIENT_IFE_CTX0 : IFE Client 0
  156. * @SYNX_CLIENT_ICP_CTX0 : ICP Client 0
  157. */
  158. enum synx_client_id {
  159. SYNX_CLIENT_NATIVE = 0,
  160. SYNX_CLIENT_GFX_CTX0,
  161. SYNX_CLIENT_DPU_CTL0,
  162. SYNX_CLIENT_DPU_CTL1,
  163. SYNX_CLIENT_DPU_CTL2,
  164. SYNX_CLIENT_DPU_CTL3,
  165. SYNX_CLIENT_DPU_CTL4,
  166. SYNX_CLIENT_DPU_CTL5,
  167. SYNX_CLIENT_EVA_CTX0,
  168. SYNX_CLIENT_VID_CTX0,
  169. SYNX_CLIENT_NSP_CTX0,
  170. SYNX_CLIENT_IFE_CTX0,
  171. SYNX_CLIENT_ICP_CTX0,
  172. SYNX_CLIENT_MAX,
  173. };
  174. /**
  175. * struct synx_session - Client session identifier
  176. *
  177. * @type : Session type
  178. * @client : Pointer to client session
  179. */
  180. struct synx_session {
  181. u32 type;
  182. void *client;
  183. };
  184. /**
  185. * struct synx_initialization_params - Session params
  186. *
  187. * @name : Client session name
  188. * Only first 64 bytes are accepted, rest will be ignored
  189. * @ptr : Pointer to queue descriptor (filled by function)
  190. * @id : Client identifier
  191. * @flags : Synx initialization flags
  192. */
  193. struct synx_initialization_params {
  194. const char *name;
  195. struct synx_queue_desc *ptr;
  196. enum synx_client_id id;
  197. enum synx_init_flags flags;
  198. };
  199. /**
  200. * struct synx_create_params - Synx creation parameters
  201. *
  202. * @name : Optional parameter associating a name with the synx
  203. * object for debug purposes
  204. * Only first 64 bytes are accepted,
  205. * rest will be ignored
  206. * @h_synx : Pointer to synx object handle (filled by function)
  207. * @fence : Pointer to external fence
  208. * @flags : Synx flags for customization (mentioned below)
  209. *
  210. * SYNX_CREATE_GLOBAL_FENCE - Hints the framework to create global synx object
  211. * If flag not set, hints framework to create a local synx object.
  212. * SYNX_CREATE_DMA_FENCE - Wrap synx object with dma fence.
  213. * Need to pass the dma_fence ptr through 'fence' variable if this flag is set.
  214. * SYNX_CREATE_BIND_FENCE - Create a synx object with provided external fence.
  215. * Establishes interop with supported external fence through bind operations.
  216. * Need to fill synx_external_desc structure if this flag is set.
  217. */
  218. struct synx_create_params {
  219. const char *name;
  220. u32 *h_synx;
  221. void *fence;
  222. enum synx_create_flags flags;
  223. };
  224. /**
  225. * enum synx_merge_flags - Handle merge flags
  226. *
  227. * SYNX_MERGE_LOCAL_FENCE : Create local composite object.
  228. * SYNX_MERGE_GLOBAL_FENCE : Create global composite object.
  229. * SYNX_MERGE_NOTIFY_ON_ALL : Notify on signaling of ALL objects
  230. * SYNX_MERGE_NOTIFY_ON_ANY : Notify on signaling of ANY object
  231. */
  232. enum synx_merge_flags {
  233. SYNX_MERGE_LOCAL_FENCE = 0x01,
  234. SYNX_MERGE_GLOBAL_FENCE = 0x02,
  235. SYNX_MERGE_NOTIFY_ON_ALL = 0x04,
  236. SYNX_MERGE_NOTIFY_ON_ANY = 0x08,
  237. };
  238. /*
  239. * struct synx_merge_params - Synx merge parameters
  240. *
  241. * @h_synxs : Pointer to a array of synx handles to be merged
  242. * @flags : Merge flags
  243. * @num_objs : Number of synx objs in the block
  244. * @h_merged_obj : Merged synx object handle (filled by function)
  245. */
  246. struct synx_merge_params {
  247. u32 *h_synxs;
  248. enum synx_merge_flags flags;
  249. u32 num_objs;
  250. u32 *h_merged_obj;
  251. };
  252. /**
  253. * enum synx_import_type - Import type
  254. *
  255. * SYNX_IMPORT_INDV_PARAMS : Import filled with synx_import_indv_params struct
  256. * SYNX_IMPORT_ARR_PARAMS : Import filled with synx_import_arr_params struct
  257. */
  258. enum synx_import_type {
  259. SYNX_IMPORT_INDV_PARAMS = 0x01,
  260. SYNX_IMPORT_ARR_PARAMS = 0x02,
  261. };
  262. /**
  263. * struct synx_import_indv_params - Synx import indv parameters
  264. *
  265. * @new_h_synxs : Pointer to new synx object
  266. * (filled by the function)
  267. * The new handle/s should be used by importing
  268. * process for all synx api operations and
  269. * for sharing with FW cores.
  270. * @flags : Synx flags
  271. * @fence : Pointer to external fence
  272. */
  273. struct synx_import_indv_params {
  274. u32 *new_h_synx;
  275. enum synx_import_flags flags;
  276. void *fence;
  277. };
  278. /**
  279. * struct synx_import_arr_params - Synx import arr parameters
  280. *
  281. * @list : Array of synx_import_indv_params pointers
  282. * @num_fences : No of fences passed to framework
  283. */
  284. struct synx_import_arr_params {
  285. struct synx_import_indv_params *list;
  286. u32 num_fences;
  287. };
  288. /**
  289. * struct synx_import_params - Synx import parameters
  290. *
  291. * @type : Import params type filled by client
  292. * @indv : Params to import an individual handle/fence
  293. * @arr : Params to import an array of handles/fences
  294. */
  295. struct synx_import_params {
  296. enum synx_import_type type;
  297. union {
  298. struct synx_import_indv_params indv;
  299. struct synx_import_arr_params arr;
  300. };
  301. };
  302. /**
  303. * struct synx_callback_params - Synx callback parameters
  304. *
  305. * @h_synx : Synx object handle
  306. * @cb_func : Pointer to callback func to be invoked
  307. * @userdata : Opaque pointer passed back with callback
  308. * @cancel_cb_func : Pointer to callback to ack cancellation (optional)
  309. * @timeout_ms : Timeout in ms. SYNX_NO_TIMEOUT if no timeout.
  310. */
  311. struct synx_callback_params {
  312. u32 h_synx;
  313. synx_user_callback_t cb_func;
  314. void *userdata;
  315. synx_user_callback_t cancel_cb_func;
  316. u64 timeout_ms;
  317. };
  318. /* Kernel APIs */
  319. /* synx_register_ops - Register operations for external synchronization
  320. *
  321. * Register with synx for enabling external synchronization through bind
  322. *
  323. * @param params : Pointer to register params
  324. *
  325. * @return Status of operation. SYNX_SUCCESS in case of success.
  326. * -SYNX_INVALID will be returned if params are invalid.
  327. * -SYNX_NOMEM will be returned if bind ops cannot be registered due to
  328. * insufficient memory.
  329. * -SYNX_ALREADY will be returned if type already in use.
  330. */
  331. int synx_register_ops(const struct synx_register_params *params);
  332. /**
  333. * synx_deregister_ops - De-register external synchronization operations
  334. *
  335. * @param params : Pointer to register params
  336. *
  337. * @return Status of operation. SYNX_SUCCESS in case of success.
  338. * -SYNX_INVALID will be returned if record not found.
  339. */
  340. int synx_deregister_ops(const struct synx_register_params *params);
  341. /**
  342. * synx_initialize - Initializes a new client session
  343. *
  344. * @param params : Pointer to session init params
  345. *
  346. * @return Client session pointer on success. NULL or error in case of failure.
  347. */
  348. struct synx_session *synx_initialize(struct synx_initialization_params *params);
  349. /**
  350. * synx_uninitialize - Destroys the client session
  351. *
  352. * @param session : Session ptr (returned from synx_initialize)
  353. *
  354. * @return Status of operation. SYNX_SUCCESS in case of success.
  355. */
  356. int synx_uninitialize(struct synx_session *session);
  357. /**
  358. * synx_create - Creates a synx object
  359. *
  360. * Creates a new synx obj and returns the handle to client.
  361. *
  362. * @param session : Session ptr (returned from synx_initialize)
  363. * @param params : Pointer to create params
  364. *
  365. * @return Status of operation. SYNX_SUCCESS in case of success.
  366. * -SYNX_INVALID will be returned if params were invalid.
  367. * -SYNX_NOMEM will be returned if the kernel can't allocate space for
  368. * synx object.
  369. */
  370. int synx_create(struct synx_session *session, struct synx_create_params *params);
  371. /**
  372. * synx_async_wait - Registers a callback with a synx object
  373. *
  374. * @param session : Session ptr (returned from synx_initialize)
  375. * @param params : Callback params
  376. *
  377. * @return Status of operation. SYNX_SUCCESS in case of success.
  378. * -SYNX_INVALID will be returned if userdata is invalid.
  379. * -SYNX_NOMEM will be returned if cb_func is invalid.
  380. */
  381. int synx_async_wait(struct synx_session *session, struct synx_callback_params *params);
  382. /**
  383. * synx_cancel_async_wait - De-registers a callback with a synx object
  384. *
  385. * @param session : Session ptr (returned from synx_initialize)
  386. * @param params : Callback params
  387. *
  388. * @return Status of operation. SYNX_SUCCESS in case of success.
  389. * -SYNX_ALREADY if object has already been signaled, and cannot be cancelled.
  390. * -SYNX_INVALID will be returned if userdata is invalid.
  391. * -SYNX_NOMEM will be returned if cb_func is invalid.
  392. */
  393. int synx_cancel_async_wait(struct synx_session *session,
  394. struct synx_callback_params *params);
  395. /**
  396. * synx_signal - Signals a synx object with the status argument.
  397. *
  398. * This function will signal the synx object referenced by h_synx
  399. * and invoke any external binding synx objs.
  400. * The status parameter will indicate whether the entity
  401. * performing the signaling wants to convey an error case or a success case.
  402. *
  403. * @param session : Session ptr (returned from synx_initialize)
  404. * @param h_synx : Synx object handle
  405. * @param status : Status of signaling.
  406. * Clients can send custom signaling status
  407. * beyond SYNX_STATE_SIGNALED_MAX.
  408. *
  409. * @return Status of operation. Negative in case of error. SYNX_SUCCESS otherwise.
  410. */
  411. int synx_signal(struct synx_session *session, u32 h_synx,
  412. enum synx_signal_status status);
  413. /**
  414. * synx_merge - Merges multiple synx objects
  415. *
  416. * This function will merge multiple synx objects into a synx group.
  417. *
  418. * @param session : Session ptr (returned from synx_initialize)
  419. * @param params : Merge params
  420. *
  421. * @return Status of operation. Negative in case of error. SYNX_SUCCESS otherwise.
  422. */
  423. int synx_merge(struct synx_session *session, struct synx_merge_params *params);
  424. /**
  425. * synx_wait - Waits for a synx object synchronously
  426. *
  427. * Does a wait on the synx object identified by h_synx for a maximum
  428. * of timeout_ms milliseconds. Must not be called from interrupt context as
  429. * this API can sleep.
  430. * Will return status if handle was signaled. Status can be from pre-defined
  431. * states (enum synx_signal_status) or custom status sent by producer.
  432. *
  433. * @param session : Session ptr (returned from synx_initialize)
  434. * @param h_synx : Synx object handle to be waited upon
  435. * @param timeout_ms : Timeout in ms
  436. *
  437. * @return Signal status. -SYNX_INVAL if synx object is in bad state or arguments
  438. * are invalid, -SYNX_TIMEOUT if wait times out.
  439. */
  440. int synx_wait(struct synx_session *session, u32 h_synx, u64 timeout_ms);
  441. /**
  442. * synx_get_status - Returns the status of the synx object
  443. *
  444. * @param session : Session ptr (returned from synx_initialize)
  445. * @param h_synx : Synx object handle
  446. *
  447. * @return Status of the synx object.
  448. */
  449. int synx_get_status(struct synx_session *session, u32 h_synx);
  450. /**
  451. * synx_import - Imports (looks up) synx object from given handle/fence
  452. *
  453. * Import subscribes the client session for notification on signal
  454. * of handles/fences.
  455. *
  456. * @param session : Session ptr (returned from synx_initialize)
  457. * @param params : Pointer to import params
  458. *
  459. * @return SYNX_SUCCESS upon success, -SYNX_INVAL if synx object is bad state
  460. */
  461. int synx_import(struct synx_session *session, struct synx_import_params *params);
  462. /**
  463. * synx_get_fence - Get the native fence backing the synx object
  464. *
  465. * Function returns the native fence. Clients need to
  466. * acquire & release additional reference explicitly.
  467. *
  468. * @param session : Session ptr (returned from synx_initialize)
  469. * @param h_synx : Synx object handle
  470. *
  471. * @return Fence pointer upon success, NULL or error in case of failure.
  472. */
  473. void *synx_get_fence(struct synx_session *session, u32 h_synx);
  474. /**
  475. * synx_release - Release the synx object
  476. *
  477. * Decrements refcount of a synx object by 1, and destroys it
  478. * if becomes 0.
  479. *
  480. * @param session : Session ptr (returned from synx_initialize)
  481. * @param h_synx : Synx object handle to be destroyed
  482. *
  483. * @return Status of operation. Negative in case of error. SYNX_SUCCESS otherwise.
  484. */
  485. int synx_release(struct synx_session *session, u32 h_synx);
  486. /**
  487. * synx_recover - Recover any possible handle leaks
  488. *
  489. * Function should be called on HW hang/reset to
  490. * recover the Synx handles shared. This cleans up
  491. * Synx handles held by the rest HW, and avoids
  492. * potential resource leaks.
  493. *
  494. * Function does not destroy the session, but only
  495. * recover synx handles belonging to the session.
  496. * Synx session would still be active and clients
  497. * need to destroy the session explicitly through
  498. * synx_uninitialize API.
  499. *
  500. * @param id : Client ID of core to recover
  501. *
  502. * @return Status of operation. Negative in case of error. SYNX_SUCCESS otherwise.
  503. */
  504. int synx_recover(enum synx_client_id id);
  505. #endif /* __SYNX_API_H__ */