synx_global.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #ifndef __SYNX_SHARED_MEM_H__
  6. #define __SYNX_SHARED_MEM_H__
  7. #include "synx_err.h"
  8. #include "ipclite_client.h"
  9. #include <synx_header.h>
  10. /**
  11. * enum synx_core_id - Synx core IDs
  12. *
  13. * SYNX_CORE_APSS : APSS core
  14. * SYNX_CORE_NSP : NSP core
  15. * SYNX_CORE_EVA : EVA core
  16. * SYNX_CORE_IRIS : IRIS core
  17. * SYNX_CORE_ICP : ICP core
  18. */
  19. enum synx_core_id {
  20. SYNX_CORE_APSS = 0,
  21. SYNX_CORE_NSP,
  22. SYNX_CORE_EVA,
  23. SYNX_CORE_IRIS,
  24. SYNX_CORE_ICP,
  25. SYNX_CORE_MAX,
  26. };
  27. /* synx handle encoding */
  28. #define SYNX_HANDLE_INDEX_BITS 16
  29. #define SYNX_HANDLE_CORE_BITS 4
  30. #define SYNX_HANDLE_GLOBAL_FLAG_BIT 1
  31. #define SYNX_GLOBAL_SHARED_LOCKS 1
  32. #define SYNX_GLOBAL_MAX_OBJS 4096
  33. #define SYNX_GLOBAL_MAX_PARENTS 4
  34. #define SYNX_HANDLE_INDEX_MASK ((1UL<<SYNX_HANDLE_INDEX_BITS)-1)
  35. #define SHRD_MEM_DUMP_NUM_BMAP_WORDS 10
  36. #define NUM_CHAR_BIT 8
  37. /* spin lock timeout (ms) */
  38. #define SYNX_HWSPIN_TIMEOUT 500
  39. #define SYNX_HWSPIN_ID 10
  40. /* internal signal states */
  41. #define SYNX_STATE_INVALID 0
  42. #define SYNX_STATE_ACTIVE 1
  43. #define SYNX_STATE_SIGNALED_ERROR 3
  44. #define SYNX_STATE_SIGNALED_EXTERNAL 5
  45. #define SYNX_STATE_SIGNALED_SSR 6
  46. #define SYNX_STATE_TIMEOUT 7
  47. /* dma fence states */
  48. #define SYNX_DMA_FENCE_STATE_MAX 4096
  49. /**
  50. * struct synx_global_coredata - Synx global object, used for book keeping
  51. * of all metadata associated with each individual global entry
  52. *
  53. * @status : Synx signaling status
  54. * @handle : Handle of global entry
  55. * @refcount : References owned by each core
  56. * @num_child : Count of children pending signal (for composite handle)
  57. * @subscribers : Cores owning reference on this object
  58. * @waiters : Cores waiting for notification
  59. * @parents : Composite global coredata index of parent entities
  60. * Can be part of SYNX_GLOBAL_MAX_PARENTS composite entries.
  61. */
  62. struct synx_global_coredata {
  63. u32 status;
  64. u32 handle;
  65. u16 refcount;
  66. u16 num_child;
  67. u16 subscribers;
  68. u16 waiters;
  69. u16 parents[SYNX_GLOBAL_MAX_PARENTS];
  70. };
  71. /**
  72. * struct synx_shared_mem - Synx global shared memory descriptor
  73. *
  74. * @bitmap : Bitmap for allocating entries form table
  75. * @locks : Array of locks for exclusive access to table entries
  76. * @table : Array of Synx global entries
  77. */
  78. struct synx_shared_mem {
  79. u32 *bitmap;
  80. u32 *locks;
  81. struct synx_global_coredata *table;
  82. };
  83. static inline bool synx_is_valid_idx(u32 idx)
  84. {
  85. if (idx < SYNX_GLOBAL_MAX_OBJS)
  86. return true;
  87. return false;
  88. }
  89. /**
  90. * synx_global_mem_init - Initialize global shared memory
  91. *
  92. * @return Zero on success, negative error on failure.
  93. */
  94. int synx_global_mem_init(void);
  95. /**
  96. * synx_global_map_core_id - Map Synx core ID to IPC Lite host
  97. *
  98. * @param id : Core Id to map
  99. *
  100. * @return IPC host ID.
  101. */
  102. u32 synx_global_map_core_id(enum synx_core_id id);
  103. /**
  104. * synx_global_alloc_index - Allocate new global entry
  105. *
  106. * @param idx : Pointer to global table index (filled by function)
  107. *
  108. * @return SYNX_SUCCESS on success. Negative error on failure.
  109. */
  110. int synx_global_alloc_index(u32 *idx);
  111. /**
  112. * synx_global_init_coredata - Allocate new global entry
  113. *
  114. * @param h_synx : Synx global handle
  115. *
  116. * @return SYNX_SUCCESS on success. Negative error on failure.
  117. */
  118. int synx_global_init_coredata(u32 h_synx);
  119. /**
  120. * synx_global_get_waiting_cores - Get list of all the waiting core on global entry
  121. *
  122. * Will fill the cores array with TRUE if core is waiting, and
  123. * false if not. Indexed through enum synx_core_id.
  124. *
  125. * @param idx : Global entry index
  126. * @param cores : Array of boolean variables, one each for supported core.
  127. * Array should contain SYNX_CORE_MAX entries.
  128. *
  129. * @return SYNX_SUCCESS on success. Negative error on failure.
  130. */
  131. int synx_global_get_waiting_cores(u32 idx, bool *cores);
  132. /**
  133. * synx_global_set_waiting_core - Set core as a waiting core on global entry
  134. *
  135. * @param idx : Global entry index
  136. * @param id : Core to be set as waiter
  137. *
  138. * @return SYNX_SUCCESS on success. Negative error on failure.
  139. */
  140. int synx_global_set_waiting_core(u32 idx, enum synx_core_id id);
  141. /**
  142. * synx_global_get_subscribed_cores - Get list of all the subscribed core on global entry
  143. *
  144. * Will fill the cores array with TRUE if core is subscribed, and
  145. * false if not. Indexed through enum synx_core_id.
  146. *
  147. * @param idx : Global entry index
  148. * @param cores : Array of boolean variables, one each for supported core.
  149. * Array should contain SYNX_CORE_MAX entries.
  150. *
  151. * @return SYNX_SUCCESS on success. Negative error on failure.
  152. */
  153. int synx_global_get_subscribed_cores(u32 idx, bool *cores);
  154. /**
  155. * synx_global_set_subscribed_core - Set core as a subscriber core on global entry
  156. *
  157. * @param idx : Global entry index
  158. * @param id : Core to be added as subscriber
  159. *
  160. * @return SYNX_SUCCESS on success. Negative error on failure.
  161. */
  162. int synx_global_set_subscribed_core(u32 idx, enum synx_core_id id);
  163. /**
  164. * synx_global_clear_subscribed_core - Clear core as a subscriber core on global entry
  165. *
  166. * @param idx : Global entry index
  167. * @param id : Core to be added as subscriber
  168. *
  169. * @return SYNX_SUCCESS on success. Negative error on failure.
  170. */
  171. int synx_global_clear_subscribed_core(u32 idx, enum synx_core_id id);
  172. /**
  173. * synx_global_get_status - Get status of the global entry
  174. *
  175. * @param idx : Global entry index
  176. *
  177. * @return Global entry status
  178. */
  179. u32 synx_global_get_status(u32 idx);
  180. /**
  181. * synx_global_test_status_set_wait - Check status and add core as waiter is not signaled
  182. *
  183. * This tests and adds the waiter in one atomic operation, to avoid
  184. * race with signal which can miss sending the IPC signal if
  185. * check status and set as done as two different operations
  186. * (signal coming in between the two ops).
  187. *
  188. * @param idx : Global entry index
  189. * @param id : Core to be set as waiter (if unsignaled)
  190. *
  191. * @return Status of global entry idx.
  192. */
  193. u32 synx_global_test_status_set_wait(u32 idx,
  194. enum synx_core_id id);
  195. /**
  196. * synx_global_update_status - Update status of the global entry
  197. *
  198. * Function also updates the parent composite handles
  199. * about the signaling.
  200. *
  201. * @param idx : Global entry index
  202. * @param status : Signaling status
  203. *
  204. * @return SYNX_SUCCESS on success. Negative error on failure.
  205. */
  206. int synx_global_update_status(u32 idx, u32 status);
  207. /**
  208. * synx_global_get_ref - Get additional reference on global entry
  209. *
  210. * @param idx : Global entry index
  211. *
  212. * @return SYNX_SUCCESS on success. Negative error on failure.
  213. */
  214. int synx_global_get_ref(u32 idx);
  215. /**
  216. * synx_global_put_ref - Release reference on global entry
  217. *
  218. * @param idx : Global entry index
  219. */
  220. void synx_global_put_ref(u32 idx);
  221. /**
  222. * synx_global_get_parents - Get the global entry index of all composite parents
  223. *
  224. * @param idx : Global entry index whose parents are requested
  225. * @param parents : Array of global entry index of composite handles
  226. * Filled by the function. Array should contain atleast
  227. * SYNX_GLOBAL_MAX_PARENTS entries.
  228. *
  229. * @return SYNX_SUCCESS on success. Negative error on failure.
  230. */
  231. int synx_global_get_parents(u32 idx, u32 *parents);
  232. /**
  233. * synx_global_merge - Merge handles to form global handle
  234. *
  235. * Is essential for merge functionality.
  236. *
  237. * @param idx_list : List of global indexes to merge
  238. * @param num_list : Number of handles in the list to merge
  239. * @params p_idx : Global entry index allocated for composite handle
  240. *
  241. * @return SYNX_SUCCESS on success. Negative error on failure.
  242. */
  243. int synx_global_merge(u32 *idx_list, u32 num_list, u32 p_idx);
  244. /**
  245. * synx_global_recover - Recover handles subscribed by specific core
  246. *
  247. * @param id : Core ID to clean up
  248. *
  249. * @return SYNX_SUCCESS on success. Negative error on failure.
  250. */
  251. int synx_global_recover(enum synx_core_id id);
  252. /**
  253. * synx_global_clean_cdsp_mem - Release handles created/used by CDSP
  254. *
  255. * @return SYNX_SUCCESS on success. Negative error on failure.
  256. */
  257. int synx_global_clean_cdsp_mem(void);
  258. /**
  259. * synx_global_dump_shared_memory - Prints the top entries of
  260. * bitmap and table in global shared memory.
  261. *
  262. * @return SYNX_SUCCESS on success. Negative error on failure.
  263. */
  264. int synx_global_dump_shared_memory(void);
  265. /**
  266. * synx_global_fetch_handle_details - Fetches the synx handle from
  267. * global shared memory.
  268. *
  269. * @param idx : Global entry index whose handle is requested.
  270. *
  271. * @return SYNX_SUCCESS on success. Negative error on failure.
  272. */
  273. int synx_global_fetch_handle_details(u32 idx, u32 *h_synx);
  274. #endif /* __SYNX_SHARED_MEM_H__ */