synx_global.h 8.4 KB

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