synx_private.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  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_PRIVATE_H__
  7. #define __SYNX_PRIVATE_H__
  8. #include <linux/bitmap.h>
  9. #include <linux/cdev.h>
  10. #include <linux/dma-fence.h>
  11. #include <linux/dma-fence-array.h>
  12. #include <linux/hashtable.h>
  13. #include <linux/ktime.h>
  14. #include <linux/workqueue.h>
  15. #include "synx_api.h"
  16. #include "synx_global.h"
  17. #define SYNX_MAX_OBJS SYNX_GLOBAL_MAX_OBJS
  18. #define SYNX_NAME "synx"
  19. #define SYNX_DEVICE_NAME "synx_device"
  20. #define SYNX_WQ_CB_NAME "hiprio_synx_cb_queue"
  21. #define SYNX_WQ_CB_THREADS 4
  22. #define SYNX_WQ_CLEANUP_NAME "hiprio_synx_cleanup_queue"
  23. #define SYNX_WQ_CLEANUP_THREADS 2
  24. #define SYNX_MAX_NUM_BINDINGS 8
  25. #define SYNX_OBJ_HANDLE_SHIFT SYNX_HANDLE_INDEX_BITS
  26. #define SYNX_OBJ_CORE_ID_SHIFT (SYNX_OBJ_HANDLE_SHIFT+SYNX_HANDLE_CORE_BITS)
  27. #define SYNX_OBJ_GLOBAL_FLAG_SHIFT (SYNX_OBJ_CORE_ID_SHIFT+SYNX_HANDLE_GLOBAL_FLAG_BIT)
  28. #define SYNX_OBJ_HANDLE_MASK GENMASK_ULL(SYNX_OBJ_HANDLE_SHIFT-1, 0)
  29. #define SYNX_OBJ_CORE_ID_MASK GENMASK_ULL(SYNX_OBJ_CORE_ID_SHIFT-1, SYNX_OBJ_HANDLE_SHIFT)
  30. #define SYNX_OBJ_GLOBAL_FLAG_MASK \
  31. GENMASK_ULL(SYNX_OBJ_GLOBAL_FLAG_SHIFT-1, SYNX_OBJ_CORE_ID_SHIFT)
  32. #define MAX_TIMESTAMP_SIZE 32
  33. #define SYNX_OBJ_NAME_LEN 64
  34. #define SYNX_PAYLOAD_WORDS 4
  35. #define SYNX_CREATE_IM_EX_RELEASE SYNX_CREATE_MAX_FLAGS
  36. #define SYNX_CREATE_MERGED_FENCE (SYNX_CREATE_MAX_FLAGS << 1)
  37. #define SYNX_MAX_REF_COUNTS 100
  38. struct synx_bind_desc {
  39. struct synx_external_desc_v2 external_desc;
  40. void *external_data;
  41. };
  42. struct error_node {
  43. char timestamp[32];
  44. u64 session;
  45. u32 client_id;
  46. u32 h_synx;
  47. s32 error_code;
  48. struct list_head node;
  49. };
  50. struct synx_entry_32 {
  51. u32 key;
  52. void *data;
  53. struct hlist_node node;
  54. };
  55. struct synx_entry_64 {
  56. u64 key;
  57. u32 data[2];
  58. struct kref refcount;
  59. struct hlist_node node;
  60. };
  61. struct synx_map_entry {
  62. struct synx_coredata *synx_obj;
  63. struct kref refcount;
  64. u32 flags;
  65. u32 key;
  66. struct work_struct dispatch;
  67. struct hlist_node node;
  68. };
  69. struct synx_fence_entry {
  70. u32 g_handle;
  71. u32 l_handle;
  72. u64 key;
  73. struct hlist_node node;
  74. };
  75. struct synx_kernel_payload {
  76. u32 h_synx;
  77. u32 status;
  78. void *data;
  79. synx_user_callback_t cb_func;
  80. synx_user_callback_t cancel_cb_func;
  81. };
  82. struct synx_cb_data {
  83. struct synx_session *session;
  84. u32 idx;
  85. u32 h_synx;
  86. u32 status;
  87. struct timer_list synx_timer;
  88. u64 timeout;
  89. struct work_struct cb_dispatch;
  90. struct list_head node;
  91. };
  92. struct synx_client_cb {
  93. bool is_valid;
  94. u32 idx;
  95. struct synx_client *client;
  96. struct synx_kernel_payload kernel_cb;
  97. struct list_head node;
  98. };
  99. struct synx_registered_ops {
  100. char name[SYNX_OBJ_NAME_LEN];
  101. struct bind_operations ops;
  102. enum synx_bind_client_type type;
  103. bool valid;
  104. };
  105. struct synx_cleanup_cb {
  106. void *data;
  107. struct work_struct cb_dispatch;
  108. };
  109. enum synx_signal_handler {
  110. SYNX_SIGNAL_FROM_CLIENT = 0x1,
  111. SYNX_SIGNAL_FROM_FENCE = 0x2,
  112. SYNX_SIGNAL_FROM_IPC = 0x4,
  113. SYNX_SIGNAL_FROM_CALLBACK = 0x8,
  114. };
  115. struct synx_signal_cb {
  116. u32 handle;
  117. u32 status;
  118. u64 ext_sync_id;
  119. struct synx_coredata *synx_obj;
  120. enum synx_signal_handler flag;
  121. struct dma_fence_cb fence_cb;
  122. struct work_struct cb_dispatch;
  123. };
  124. struct synx_coredata {
  125. char name[SYNX_OBJ_NAME_LEN];
  126. struct dma_fence *fence;
  127. struct mutex obj_lock;
  128. struct kref refcount;
  129. u32 type;
  130. u32 status;
  131. u32 num_bound_synxs;
  132. struct synx_bind_desc bound_synxs[SYNX_MAX_NUM_BINDINGS];
  133. struct list_head reg_cbs_list;
  134. u32 global_idx;
  135. u32 map_count;
  136. struct synx_signal_cb *signal_cb;
  137. };
  138. struct synx_client;
  139. struct synx_device;
  140. struct synx_handle_coredata {
  141. struct synx_client *client;
  142. struct synx_coredata *synx_obj;
  143. void *map_entry;
  144. struct kref refcount;
  145. u32 key;
  146. u32 rel_count;
  147. struct work_struct dispatch;
  148. struct hlist_node node;
  149. };
  150. struct synx_client {
  151. u32 type;
  152. bool active;
  153. struct synx_device *device;
  154. char name[SYNX_OBJ_NAME_LEN];
  155. u64 id;
  156. u64 dma_context;
  157. struct kref refcount;
  158. struct mutex event_q_lock;
  159. struct list_head event_q;
  160. wait_queue_head_t event_wq;
  161. DECLARE_BITMAP(cb_bitmap, SYNX_MAX_OBJS);
  162. struct synx_client_cb cb_table[SYNX_MAX_OBJS];
  163. DECLARE_HASHTABLE(handle_map, 8);
  164. spinlock_t handle_map_lock;
  165. struct work_struct dispatch;
  166. struct hlist_node node;
  167. };
  168. struct synx_native {
  169. spinlock_t metadata_map_lock;
  170. DECLARE_HASHTABLE(client_metadata_map, 8);
  171. spinlock_t fence_map_lock;
  172. DECLARE_HASHTABLE(fence_map, 10);
  173. spinlock_t global_map_lock;
  174. DECLARE_HASHTABLE(global_map, 10);
  175. spinlock_t local_map_lock;
  176. DECLARE_HASHTABLE(local_map, 8);
  177. spinlock_t csl_map_lock;
  178. DECLARE_HASHTABLE(csl_fence_map, 8);
  179. DECLARE_BITMAP(bitmap, SYNX_MAX_OBJS);
  180. };
  181. struct synx_cdsp_ssr {
  182. u64 ssrcnt;
  183. void *handle;
  184. struct notifier_block nb;
  185. };
  186. struct synx_device {
  187. struct cdev cdev;
  188. dev_t dev;
  189. struct class *class;
  190. struct synx_native *native;
  191. struct workqueue_struct *wq_cb;
  192. struct workqueue_struct *wq_cleanup;
  193. struct mutex vtbl_lock;
  194. struct synx_registered_ops bind_vtbl[SYNX_MAX_BIND_TYPES];
  195. struct dentry *debugfs_root;
  196. struct list_head error_list;
  197. struct mutex error_lock;
  198. struct synx_cdsp_ssr cdsp_ssr;
  199. };
  200. int synx_signal_core(struct synx_coredata *synx_obj,
  201. u32 status,
  202. bool cb_signal,
  203. s32 ext_sync_id);
  204. int synx_ipc_callback(uint32_t client_id,
  205. int64_t data, void *priv);
  206. void synx_signal_handler(struct work_struct *cb_dispatch);
  207. int synx_native_release_core(struct synx_client *session,
  208. u32 h_synx);
  209. int synx_bind(struct synx_session *session,
  210. u32 h_synx,
  211. struct synx_external_desc_v2 external_sync);
  212. #endif /* __SYNX_PRIVATE_H__ */