synx_api.h 17 KB

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