synx_api.h 17 KB

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