synx_api.h 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2019, 2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022, 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. */
  156. enum synx_client_id {
  157. SYNX_CLIENT_NATIVE = 0,
  158. SYNX_CLIENT_GFX_CTX0,
  159. SYNX_CLIENT_DPU_CTL0,
  160. SYNX_CLIENT_DPU_CTL1,
  161. SYNX_CLIENT_DPU_CTL2,
  162. SYNX_CLIENT_DPU_CTL3,
  163. SYNX_CLIENT_DPU_CTL4,
  164. SYNX_CLIENT_DPU_CTL5,
  165. SYNX_CLIENT_EVA_CTX0,
  166. SYNX_CLIENT_VID_CTX0,
  167. SYNX_CLIENT_NSP_CTX0,
  168. SYNX_CLIENT_IFE_CTX0,
  169. SYNX_CLIENT_MAX,
  170. };
  171. /**
  172. * struct synx_session - Client session identifier
  173. *
  174. * @type : Session type
  175. * @client : Pointer to client session
  176. */
  177. struct synx_session {
  178. u32 type;
  179. void *client;
  180. };
  181. /**
  182. * struct synx_initialization_params - Session params
  183. *
  184. * @name : Client session name
  185. * Only first 64 bytes are accepted, rest will be ignored
  186. * @ptr : Pointer to queue descriptor (filled by function)
  187. * @id : Client identifier
  188. * @flags : Synx initialization flags
  189. */
  190. struct synx_initialization_params {
  191. const char *name;
  192. struct synx_queue_desc *ptr;
  193. enum synx_client_id id;
  194. enum synx_init_flags flags;
  195. };
  196. /**
  197. * struct synx_create_params - Synx creation parameters
  198. *
  199. * @name : Optional parameter associating a name with the synx
  200. * object for debug purposes
  201. * Only first 64 bytes are accepted,
  202. * rest will be ignored
  203. * @h_synx : Pointer to synx object handle (filled by function)
  204. * @fence : Pointer to external fence
  205. * @flags : Synx flags for customization (mentioned below)
  206. *
  207. * SYNX_CREATE_GLOBAL_FENCE - Hints the framework to create global synx object
  208. * If flag not set, hints framework to create a local synx object.
  209. * SYNX_CREATE_DMA_FENCE - Wrap synx object with dma fence.
  210. * Need to pass the dma_fence ptr through 'fence' variable if this flag is set.
  211. * SYNX_CREATE_BIND_FENCE - Create a synx object with provided external fence.
  212. * Establishes interop with supported external fence through bind operations.
  213. * Need to fill synx_external_desc structure if this flag is set.
  214. */
  215. struct synx_create_params {
  216. const char *name;
  217. u32 *h_synx;
  218. void *fence;
  219. enum synx_create_flags flags;
  220. };
  221. /**
  222. * enum synx_merge_flags - Handle merge flags
  223. *
  224. * SYNX_MERGE_LOCAL_FENCE : Create local composite object.
  225. * SYNX_MERGE_GLOBAL_FENCE : Create global composite object.
  226. * SYNX_MERGE_NOTIFY_ON_ALL : Notify on signaling of ALL objects
  227. * SYNX_MERGE_NOTIFY_ON_ANY : Notify on signaling of ANY object
  228. */
  229. enum synx_merge_flags {
  230. SYNX_MERGE_LOCAL_FENCE = 0x01,
  231. SYNX_MERGE_GLOBAL_FENCE = 0x02,
  232. SYNX_MERGE_NOTIFY_ON_ALL = 0x04,
  233. SYNX_MERGE_NOTIFY_ON_ANY = 0x08,
  234. };
  235. /*
  236. * struct synx_merge_params - Synx merge parameters
  237. *
  238. * @h_synxs : Pointer to a array of synx handles to be merged
  239. * @flags : Merge flags
  240. * @num_objs : Number of synx objs in the block
  241. * @h_merged_obj : Merged synx object handle (filled by function)
  242. */
  243. struct synx_merge_params {
  244. u32 *h_synxs;
  245. enum synx_merge_flags flags;
  246. u32 num_objs;
  247. u32 *h_merged_obj;
  248. };
  249. /**
  250. * enum synx_import_type - Import type
  251. *
  252. * SYNX_IMPORT_INDV_PARAMS : Import filled with synx_import_indv_params struct
  253. * SYNX_IMPORT_ARR_PARAMS : Import filled with synx_import_arr_params struct
  254. */
  255. enum synx_import_type {
  256. SYNX_IMPORT_INDV_PARAMS = 0x01,
  257. SYNX_IMPORT_ARR_PARAMS = 0x02,
  258. };
  259. /**
  260. * struct synx_import_indv_params - Synx import indv parameters
  261. *
  262. * @new_h_synxs : Pointer to new synx object
  263. * (filled by the function)
  264. * The new handle/s should be used by importing
  265. * process for all synx api operations and
  266. * for sharing with FW cores.
  267. * @flags : Synx flags
  268. * @fence : Pointer to external fence
  269. */
  270. struct synx_import_indv_params {
  271. u32 *new_h_synx;
  272. enum synx_import_flags flags;
  273. void *fence;
  274. };
  275. /**
  276. * struct synx_import_arr_params - Synx import arr parameters
  277. *
  278. * @list : Array of synx_import_indv_params pointers
  279. * @num_fences : No of fences passed to framework
  280. */
  281. struct synx_import_arr_params {
  282. struct synx_import_indv_params *list;
  283. u32 num_fences;
  284. };
  285. /**
  286. * struct synx_import_params - Synx import parameters
  287. *
  288. * @type : Import params type filled by client
  289. * @indv : Params to import an individual handle/fence
  290. * @arr : Params to import an array of handles/fences
  291. */
  292. struct synx_import_params {
  293. enum synx_import_type type;
  294. union {
  295. struct synx_import_indv_params indv;
  296. struct synx_import_arr_params arr;
  297. };
  298. };
  299. /**
  300. * struct synx_callback_params - Synx callback parameters
  301. *
  302. * @h_synx : Synx object handle
  303. * @cb_func : Pointer to callback func to be invoked
  304. * @userdata : Opaque pointer passed back with callback
  305. * @cancel_cb_func : Pointer to callback to ack cancellation (optional)
  306. */
  307. struct synx_callback_params {
  308. u32 h_synx;
  309. synx_user_callback_t cb_func;
  310. void *userdata;
  311. synx_user_callback_t cancel_cb_func;
  312. };
  313. /* Kernel APIs */
  314. /* synx_register_ops - Register operations for external synchronization
  315. *
  316. * Register with synx for enabling external synchronization through bind
  317. *
  318. * @param params : Pointer to register params
  319. *
  320. * @return Status of operation. SYNX_SUCCESS in case of success.
  321. * -SYNX_INVALID will be returned if params are invalid.
  322. * -SYNX_NOMEM will be returned if bind ops cannot be registered due to
  323. * insufficient memory.
  324. * -SYNX_ALREADY will be returned if type already in use.
  325. */
  326. int synx_register_ops(const struct synx_register_params *params);
  327. /**
  328. * synx_deregister_ops - De-register external synchronization operations
  329. *
  330. * @param params : Pointer to register params
  331. *
  332. * @return Status of operation. SYNX_SUCCESS in case of success.
  333. * -SYNX_INVALID will be returned if record not found.
  334. */
  335. int synx_deregister_ops(const struct synx_register_params *params);
  336. /**
  337. * synx_initialize - Initializes a new client session
  338. *
  339. * @param params : Pointer to session init params
  340. *
  341. * @return Client session pointer on success. NULL or error in case of failure.
  342. */
  343. struct synx_session *synx_initialize(struct synx_initialization_params *params);
  344. /**
  345. * synx_uninitialize - Destroys the client session
  346. *
  347. * @param session : Session ptr (returned from synx_initialize)
  348. *
  349. * @return Status of operation. SYNX_SUCCESS in case of success.
  350. */
  351. int synx_uninitialize(struct synx_session *session);
  352. /**
  353. * synx_create - Creates a synx object
  354. *
  355. * Creates a new synx obj and returns the handle to client.
  356. *
  357. * @param session : Session ptr (returned from synx_initialize)
  358. * @param params : Pointer to create params
  359. *
  360. * @return Status of operation. SYNX_SUCCESS in case of success.
  361. * -SYNX_INVALID will be returned if params were invalid.
  362. * -SYNX_NOMEM will be returned if the kernel can't allocate space for
  363. * synx object.
  364. */
  365. int synx_create(struct synx_session *session, struct synx_create_params *params);
  366. /**
  367. * synx_async_wait - Registers a callback with a synx object
  368. *
  369. * @param session : Session ptr (returned from synx_initialize)
  370. * @param params : Callback params
  371. *
  372. * @return Status of operation. SYNX_SUCCESS in case of success.
  373. * -SYNX_INVALID will be returned if userdata is invalid.
  374. * -SYNX_NOMEM will be returned if cb_func is invalid.
  375. */
  376. int synx_async_wait(struct synx_session *session, struct synx_callback_params *params);
  377. /**
  378. * synx_cancel_async_wait - De-registers a callback with a synx object
  379. *
  380. * @param session : Session ptr (returned from synx_initialize)
  381. * @param params : Callback params
  382. *
  383. * @return Status of operation. SYNX_SUCCESS in case of success.
  384. * -SYNX_ALREADY if object has already been signaled, and cannot be cancelled.
  385. * -SYNX_INVALID will be returned if userdata is invalid.
  386. * -SYNX_NOMEM will be returned if cb_func is invalid.
  387. */
  388. int synx_cancel_async_wait(struct synx_session *session,
  389. struct synx_callback_params *params);
  390. /**
  391. * synx_signal - Signals a synx object with the status argument.
  392. *
  393. * This function will signal the synx object referenced by h_synx
  394. * and invoke any external binding synx objs.
  395. * The status parameter will indicate whether the entity
  396. * performing the signaling wants to convey an error case or a success case.
  397. *
  398. * @param session : Session ptr (returned from synx_initialize)
  399. * @param h_synx : Synx object handle
  400. * @param status : Status of signaling.
  401. * Clients can send custom signaling status
  402. * beyond SYNX_STATE_SIGNALED_MAX.
  403. *
  404. * @return Status of operation. Negative in case of error. SYNX_SUCCESS otherwise.
  405. */
  406. int synx_signal(struct synx_session *session, u32 h_synx,
  407. enum synx_signal_status status);
  408. /**
  409. * synx_merge - Merges multiple synx objects
  410. *
  411. * This function will merge multiple synx objects into a synx group.
  412. *
  413. * @param session : Session ptr (returned from synx_initialize)
  414. * @param params : Merge params
  415. *
  416. * @return Status of operation. Negative in case of error. SYNX_SUCCESS otherwise.
  417. */
  418. int synx_merge(struct synx_session *session, struct synx_merge_params *params);
  419. /**
  420. * synx_wait - Waits for a synx object synchronously
  421. *
  422. * Does a wait on the synx object identified by h_synx for a maximum
  423. * of timeout_ms milliseconds. Must not be called from interrupt context as
  424. * this API can sleep.
  425. * Will return status if handle was signaled. Status can be from pre-defined
  426. * states (enum synx_signal_status) or custom status sent by producer.
  427. *
  428. * @param session : Session ptr (returned from synx_initialize)
  429. * @param h_synx : Synx object handle to be waited upon
  430. * @param timeout_ms : Timeout in ms
  431. *
  432. * @return Signal status. -SYNX_INVAL if synx object is in bad state or arguments
  433. * are invalid, -SYNX_TIMEOUT if wait times out.
  434. */
  435. int synx_wait(struct synx_session *session, u32 h_synx, u64 timeout_ms);
  436. /**
  437. * synx_get_status - Returns the status of the synx object
  438. *
  439. * @param session : Session ptr (returned from synx_initialize)
  440. * @param h_synx : Synx object handle
  441. *
  442. * @return Status of the synx object.
  443. */
  444. int synx_get_status(struct synx_session *session, u32 h_synx);
  445. /**
  446. * synx_import - Imports (looks up) synx object from given handle/fence
  447. *
  448. * Import subscribes the client session for notification on signal
  449. * of handles/fences.
  450. *
  451. * @param session : Session ptr (returned from synx_initialize)
  452. * @param params : Pointer to import params
  453. *
  454. * @return SYNX_SUCCESS upon success, -SYNX_INVAL if synx object is bad state
  455. */
  456. int synx_import(struct synx_session *session, struct synx_import_params *params);
  457. /**
  458. * synx_get_fence - Get the native fence backing the synx object
  459. *
  460. * Function returns the native fence. Clients need to
  461. * acquire & release additional reference explicitly.
  462. *
  463. * @param session : Session ptr (returned from synx_initialize)
  464. * @param h_synx : Synx object handle
  465. *
  466. * @return Fence pointer upon success, NULL or error in case of failure.
  467. */
  468. void *synx_get_fence(struct synx_session *session, u32 h_synx);
  469. /**
  470. * synx_release - Release the synx object
  471. *
  472. * Decrements refcount of a synx object by 1, and destroys it
  473. * if becomes 0.
  474. *
  475. * @param session : Session ptr (returned from synx_initialize)
  476. * @param h_synx : Synx object handle to be destroyed
  477. *
  478. * @return Status of operation. Negative in case of error. SYNX_SUCCESS otherwise.
  479. */
  480. int synx_release(struct synx_session *session, u32 h_synx);
  481. /**
  482. * synx_recover - Recover any possible handle leaks
  483. *
  484. * Function should be called on HW hang/reset to
  485. * recover the Synx handles shared. This cleans up
  486. * Synx handles held by the rest HW, and avoids
  487. * potential resource leaks.
  488. *
  489. * Function does not destroy the session, but only
  490. * recover synx handles belonging to the session.
  491. * Synx session would still be active and clients
  492. * need to destroy the session explicitly through
  493. * synx_uninitialize API.
  494. *
  495. * @param id : Client ID of core to recover
  496. *
  497. * @return Status of operation. Negative in case of error. SYNX_SUCCESS otherwise.
  498. */
  499. int synx_recover(enum synx_client_id id);
  500. #endif /* __SYNX_API_H__ */