synx_global.h 8.4 KB

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