drv_md_ipc.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. /* Copyright (C) 2018 RDA Technologies Limited and/or its affiliates("RDA").
  2. * All rights reserved.
  3. *
  4. * This software is supplied "AS IS" without any warranties.
  5. * RDA assumes no responsibility or liability for the use of the software,
  6. * conveys no license or title under any patent, copyright, or mask work
  7. * right to the product. RDA reserves the right to make changes in the
  8. * software without notification. RDA also make no representation or
  9. * warranty that such application will be suitable for the specified use
  10. * without further testing or modification.
  11. */
  12. #ifndef _DRV_MD_IPC_H_
  13. #define _DRV_MD_IPC_H_
  14. #include <stdint.h>
  15. #include <stdbool.h>
  16. #include <stddef.h>
  17. #include "hal_config.h"
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. /**
  22. * @brief IPC channel ID
  23. */
  24. enum smd_ch_id
  25. {
  26. SMD_CH_AT = 1, ///< alias for SMD_CH_AT1
  27. SMD_CH_AT1 = 1, ///< AT1, stream type
  28. SMD_CH_AT2 = 2, ///< AT2, stream type
  29. SMD_CH_PS = 3, ///< PS, packet type
  30. SMD_CH_A2C_CTRL = 4, ///< A2C_CTRL, queue type
  31. #ifdef CONFIG_SOC_8850
  32. SMD_CH_GNSS_LOW = 5, ///< GNSS LowPro, stream type
  33. SMD_CH_GNSS_HIGH = 6, ///< GNSS HighPro, stream type
  34. SMD_CH_WIFI_SCAN = 7, ///< WIFI SCAN, stream type
  35. #else
  36. SMD_CH_AUD_CTRL = 5, ///< AUD_CTRL, command type
  37. #endif
  38. SMD_CH_MAX ///< placeholder for count
  39. };
  40. /**
  41. * @brief channel Event
  42. */
  43. enum smd_ch_flag
  44. {
  45. CH_READ_AVAIL = 0x1, ///< indicate read available
  46. CH_WRITE_AVAIL = 0x2, ///< indicate write available
  47. CH_OPENED = 0x4, ///< flag for channel opened
  48. CH_RW_MASK = (CH_READ_AVAIL | CH_WRITE_AVAIL) ///< read and write mask
  49. };
  50. /**
  51. * PS uplink buffer maximum size
  52. *
  53. * When write to PS IPC channel, the maximum packet size can't exceed
  54. * this.
  55. */
  56. #define IPC_PS_BUF_UL_LEN_B 1568
  57. /**
  58. * PS uplink buffer header size
  59. *
  60. * When copy data to PC uplink buffer, the payload should be copied
  61. * to the allocated buffer with is offset.
  62. */
  63. #define IPC_PS_UL_HDR_LEN 40
  64. /**
  65. * IPC command header
  66. */
  67. struct ipc_cmd
  68. {
  69. uint32_t id; ///< command id
  70. uint32_t para0; ///< 1st parameter
  71. uint32_t para1; ///< 2nd parameter
  72. uint32_t para2; ///< 3rd parameter
  73. };
  74. /**
  75. * IPC PS buf header
  76. */
  77. struct ps_header
  78. {
  79. uint32_t next; ///< next offset (from shared memory) in the chain
  80. uint8_t cid; ///< CID
  81. uint8_t simid; ///< SIM number
  82. uint16_t len; ///< data length
  83. uint8_t rai; ///< NAS RAI Release assistance indication 0 1 2
  84. uint8_t exception_data; ///<
  85. uint16_t flag; ///< BUF_IN_USR or BUF_IN_IDLE
  86. uint32_t buf_size; ///< 300B or 1600B
  87. uint32_t data_off; ///< data offset in buffer
  88. uint32_t id; ///< only for debug
  89. };
  90. struct smd_ch;
  91. /**
  92. * @brief IPC module initialization
  93. */
  94. void ipcInit(void);
  95. /**
  96. * @brief open an IPC channel
  97. *
  98. * Each IPC channel can be opened only once.
  99. *
  100. * It is permitted \p notify to be NULL.
  101. *
  102. * \p notify will be called in ISR context. So, it should follow ISR
  103. * programming guide. In the notify itself, it is not permitted to
  104. * read or write the channel
  105. *
  106. * @param ch_id channel ID
  107. * @param ch output channel pointer
  108. * @param priv channel notify callback first argument
  109. * @param notify channel notify callback
  110. * @return
  111. * - 0 on success
  112. * - -ENODEV/-EPERM on error
  113. */
  114. int ipc_ch_open(int ch_id, struct smd_ch **ch, void *priv,
  115. void (*notify)(void *, uint32_t));
  116. /**
  117. * @brief set IPC channel event mask
  118. *
  119. * Only masked event will invoke the registered \p notify callback.
  120. *
  121. * The default event mask is 0. That is the callback won't be invoked.
  122. *
  123. * @param ch IPC channel, must be valid
  124. * @param event_mask event mask to be set
  125. */
  126. void ipc_ch_set_event_mask(struct smd_ch *ch, uint32_t event_mask);
  127. /**
  128. * @brief read from IPC channel
  129. *
  130. * The read content depends on channel type:
  131. * - stream: read data. The return value is the actual read bytes,
  132. * and may be less than \p len.
  133. * - packet: \p data is the packet offset, \p len is the offset count
  134. * rather than size of \p data. However, the return value is the
  135. * read bytes.
  136. * - command: \p data is the command including header and data,
  137. * the return value is the actual read bytes.
  138. * - queue: \p data is \p ipc_cmd, \p len is the count of \p ipc_cmd,
  139. * the return value is the actual read bytes
  140. *
  141. * @param ch IPC channel, must be valid
  142. * @param data data to be read
  143. * @param len data length
  144. * @return
  145. * - actual read
  146. * - -EINVAL, -EAGAIN on fail
  147. */
  148. int ipc_ch_read(struct smd_ch *ch, void *data, uint32_t len);
  149. /**
  150. * @brief write to IPC channel
  151. *
  152. * The write content depends on channel type:
  153. * - stream: write data. The return value is the actual written bytes,
  154. * and may be less than \p len.
  155. * - packet: \p data is the packet offset, \p len is the offset count
  156. * rather than size of \p data. However, the return value is the
  157. * written bytes.
  158. * - command: write content is command (includes header and data).
  159. * When \p size is 0, the control fifo will be cleared.
  160. * - queue: \p data is \p ipc_cmd, \p len is the count of \p ipc_cmd,
  161. * the return value is the actual read bytes
  162. *
  163. * After write, even partial write, it will set peer's interrupt.
  164. *
  165. * @param ch IPC channel, must be valid
  166. * @param data data to be written
  167. * @param len data length
  168. * @return
  169. * - actual written
  170. * - 0 for no space, and won't set peer's interrupt
  171. * - -ENODEV if the uplink channel is not openned
  172. * - -EINVAL for invalid parameters
  173. */
  174. int ipc_ch_write(struct smd_ch *ch, const void *data, uint32_t len);
  175. /**
  176. * @brief channel available read space
  177. *
  178. * The meaning of the return unit depends on channel type:
  179. * - stream: available bytes
  180. * - packet: available offset count
  181. * - command: available bytes including command header
  182. * - queue: available count of \p ipc_cmd
  183. *
  184. * @param ch IPC channel, must be valid
  185. * @return
  186. * - available
  187. * - 0 for unavailable
  188. */
  189. int ipc_ch_read_avail(struct smd_ch *ch);
  190. /**
  191. * @brief channel available write space
  192. *
  193. * The meaning of return unit depends on channel type:
  194. * - stream: available write bytes
  195. * - packet: available offset write count
  196. * - command: available write bytes of command data (except command header)
  197. * - queue: available count of \p ipc_cmd
  198. *
  199. * @param ch IPC channel, must be valid
  200. * @return
  201. * - available
  202. * - 0 for no space
  203. */
  204. int ipc_ch_write_avail(struct smd_ch *ch);
  205. /**
  206. * @brief free downlink PS buf
  207. *
  208. * Even if the downlink PS buf is in a chain, this will free the
  209. * specified downlink PS buf only. Other buf in the chain is
  210. * untouched.
  211. *
  212. * @param ch the PS IPC channel, must be valid
  213. * @param offset the offset from share memory of the downlink buf
  214. * @return
  215. * - 0 in success, it will never fail
  216. */
  217. int ipc_free_dl_ps_buf(struct smd_ch *ch, uint32_t offset);
  218. /**
  219. * @brief allocate uplink PS buf
  220. *
  221. * The size will be used to decide big buffer or little buffer. It doesn't
  222. * mean that the allocated buffer is large enough for requested \p size.
  223. *
  224. * @param ch the PS IPC channel, must be valid
  225. * @param size request size
  226. * @return
  227. * - uplink buf offset in shared memory
  228. * - -ENOMEM if no available buffer
  229. */
  230. int ipc_alloc_ul_ps_buf(struct smd_ch *ch, uint32_t size);
  231. /**
  232. * @brief notify AP panic to CP
  233. *
  234. * It should be called after AP panic.
  235. */
  236. void ipc_notify_cp_assert(void);
  237. /**
  238. * @brief show CP assert information
  239. */
  240. void ipc_show_cp_assert(void);
  241. /**
  242. * @brief get CP assert information address
  243. */
  244. void *ipc_get_cp_assert_cause(void);
  245. /**
  246. * @brief switch cp trace
  247. *
  248. * @param en enable cp trace or not
  249. */
  250. void ipc_switch_cp_trace(bool en);
  251. /**
  252. * @brief notify sim plug in/out to CP
  253. *
  254. * @param num sim number (1/2)
  255. * @param connect true indicate the sim plug in otherwise plug out
  256. */
  257. void ipc_notify_sim_detect(int num, bool connect);
  258. /**
  259. * @brief zsp audio request notify.
  260. *
  261. * @param handler the notify handler
  262. */
  263. void ipc_register_audio_notify(void (*handler)(void));
  264. /**
  265. * @brief modem trace request notify.
  266. *
  267. * @param handler the notify handler
  268. * @param param caller private data
  269. */
  270. void ipc_register_trace_notify(void (*handler)(uint32_t, void *), void *param);
  271. /**
  272. * @brief modem MOS request notify
  273. *
  274. * @param handler the notify handler
  275. * @param param caller private data
  276. */
  277. void ipc_register_mos_notify(void (*handler)(void *), void *param);
  278. /**
  279. * @brief bt riscv log request notify
  280. *
  281. * @param handler the notify handler
  282. * @param param caller private data
  283. */
  284. void ipc_register_bt_log_notify(void (*handler)(uint32_t, void *), void *param);
  285. /**
  286. * @brief bt riscv sleep request notify
  287. *
  288. * @param handler the notify handler
  289. */
  290. void ipc_register_bt_sleep_notify(void (*handler)(uint32_t));
  291. /**
  292. * @brief bt riscv assert request notify
  293. *
  294. * @param handler the notify handler
  295. */
  296. void ipc_register_bt_assert_notify(void (*handler)(void));
  297. /**
  298. * @brief update shared memory MMU properties
  299. */
  300. void ipc_update_buf_access(void);
  301. /**
  302. * @brief disable ipc channel interrupt
  303. *
  304. * @param ch the smd channel
  305. */
  306. void ipc_disable_ch_irq(struct smd_ch *ch);
  307. /**
  308. * @brief enable ipc channel interrupt
  309. *
  310. * @param ch the smd channel
  311. */
  312. void ipc_enable_ch_irq(struct smd_ch *ch);
  313. /**
  314. * @brief notify function type to be called
  315. *
  316. * It will be called when cp need notify ap to update rf param
  317. */
  318. typedef void (*rfParamNotify_t)(void *ctx1, uint32_t v0, uint32_t v1, uint32_t v2, uint32_t v3, uint32_t v4);
  319. /**
  320. * @brief modem rf param request notify
  321. *
  322. * @param notify notify callback
  323. * @param param caller private data
  324. */
  325. void ipc_register_rfParam_notify(rfParamNotify_t notify, void *param);
  326. /**
  327. * @brief cp rf param init function
  328. *
  329. * @param v0 parameter 0
  330. * @param v1 parameter 1
  331. * @param v2 parameter 2
  332. * @param v3 parameter 3
  333. * @param v4 parameter 4
  334. */
  335. void ipc_cpRfParamInit(uint32_t v0, uint32_t v1, uint32_t v2, uint32_t v3, uint32_t v4);
  336. /**
  337. * @brief ipc get delta nv addr
  338. *
  339. * @return deltanv address
  340. */
  341. uint8_t *ipc_get_deltanv_addr(void);
  342. /**
  343. * @brief ipc get ims nv addr and send sysmail
  344. *
  345. * @return ims nv address
  346. */
  347. uint8_t *ipc_get_ims_nv_addr(void);
  348. /**
  349. * @brief ipc set delta addr and size send sysmail
  350. *
  351. * @param addr address
  352. * @param len length
  353. */
  354. void ipc_set_deltanv_bin(uint32_t addr, uint32_t len);
  355. /**
  356. * @brief cp wake lock (not permit sleep)
  357. */
  358. void ipc_cp_wake_lock(void);
  359. /**
  360. * @brief set rpc patch ctx --> IPC interrupt lost patch for rpc function.
  361. */
  362. void osiRPCPatchCTX(void *ctx);
  363. /**
  364. * @brief EXE rpc patch --> IPC interrupt lost patch for rpc function.
  365. */
  366. void osiRPCPatchHandler(void *ctx);
  367. #if defined(CONFIG_SOC_8850)
  368. void ipc_notify_volte_data(void);
  369. #endif
  370. #ifdef __cplusplus
  371. }
  372. #endif
  373. #endif