spsi.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419
  1. /* Copyright (c) 2011-2014, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. /**
  13. * Smart-Peripheral-Switch (SPS) internal API.
  14. */
  15. #ifndef _SPSI_H_
  16. #define _SPSI_H_
  17. #include <linux/types.h> /* u32 */
  18. #include <linux/list.h> /* list_head */
  19. #include <linux/kernel.h> /* pr_info() */
  20. #include <linux/compiler.h>
  21. #include <linux/ratelimit.h>
  22. #include <linux/msm-sps.h>
  23. #include "sps_map.h"
  24. #ifdef CONFIG_ARM_LPAE
  25. #define SPS_LPAE (true)
  26. #else
  27. #define SPS_LPAE (false)
  28. #endif
  29. #define BAM_MAX_PIPES 31
  30. #define BAM_MAX_P_LOCK_GROUP_NUM 31
  31. /* Adjust for offset of struct sps_q_event */
  32. #define SPS_EVENT_INDEX(e) ((e) - 1)
  33. #define SPS_ERROR -1
  34. /* BAM identifier used in log messages */
  35. #define BAM_ID(dev) (&(dev)->props.phys_addr)
  36. /* "Clear" value for the connection parameter struct */
  37. #define SPSRM_CLEAR 0xccccccccUL
  38. #define SPSRM_ADDR_CLR \
  39. ((sizeof(int) == sizeof(long)) ? 0 : (SPSRM_CLEAR << 32))
  40. #define MAX_MSG_LEN 80
  41. extern u32 d_type;
  42. extern bool enhd_pipe;
  43. extern bool imem;
  44. extern enum sps_bam_type bam_type;
  45. #ifdef CONFIG_DEBUG_FS
  46. extern u8 debugfs_record_enabled;
  47. extern u8 logging_option;
  48. extern u8 debug_level_option;
  49. extern u8 print_limit_option;
  50. #define SPS_ERR(msg, args...) do { \
  51. if (logging_option != 1) { \
  52. if (unlikely(print_limit_option > 2)) \
  53. pr_err_ratelimited(msg, ##args); \
  54. else \
  55. pr_err(msg, ##args); \
  56. } \
  57. } while (0)
  58. #define SPS_INFO(msg, args...) do { \
  59. if (logging_option != 1) { \
  60. if (unlikely(print_limit_option > 1)) \
  61. pr_info_ratelimited(msg, ##args); \
  62. else \
  63. pr_info(msg, ##args); \
  64. } \
  65. } while (0)
  66. #define SPS_DBG(msg, args...) do { \
  67. if ((unlikely(logging_option > 1)) \
  68. && (unlikely(debug_level_option > 3))) {\
  69. if (unlikely(print_limit_option > 0)) \
  70. pr_info_ratelimited(msg, ##args); \
  71. else \
  72. pr_info(msg, ##args); \
  73. } else \
  74. pr_debug(msg, ##args); \
  75. } while (0)
  76. #define SPS_DBG1(msg, args...) do { \
  77. if ((unlikely(logging_option > 1)) \
  78. && (unlikely(debug_level_option > 2))) {\
  79. if (unlikely(print_limit_option > 0)) \
  80. pr_info_ratelimited(msg, ##args); \
  81. else \
  82. pr_info(msg, ##args); \
  83. } else \
  84. pr_debug(msg, ##args); \
  85. } while (0)
  86. #define SPS_DBG2(msg, args...) do { \
  87. if ((unlikely(logging_option > 1)) \
  88. && (unlikely(debug_level_option > 1))) {\
  89. if (unlikely(print_limit_option > 0)) \
  90. pr_info_ratelimited(msg, ##args); \
  91. else \
  92. pr_info(msg, ##args); \
  93. } else \
  94. pr_debug(msg, ##args); \
  95. } while (0)
  96. #define SPS_DBG3(msg, args...) do { \
  97. if ((unlikely(logging_option > 1)) \
  98. && (unlikely(debug_level_option > 0))) {\
  99. if (unlikely(print_limit_option > 0)) \
  100. pr_info_ratelimited(msg, ##args); \
  101. else \
  102. pr_info(msg, ##args); \
  103. } else \
  104. pr_debug(msg, ##args); \
  105. } while (0)
  106. #else
  107. #define SPS_DBG3(x...) pr_debug(x)
  108. #define SPS_DBG2(x...) pr_debug(x)
  109. #define SPS_DBG1(x...) pr_debug(x)
  110. #define SPS_DBG(x...) pr_debug(x)
  111. #define SPS_INFO(x...) pr_info(x)
  112. #define SPS_ERR(x...) pr_err(x)
  113. #endif
  114. /* End point parameters */
  115. struct sps_conn_end_pt {
  116. unsigned long dev; /* Device handle of BAM */
  117. phys_addr_t bam_phys; /* Physical address of BAM. */
  118. u32 pipe_index; /* Pipe index */
  119. u32 event_threshold; /* Pipe event threshold */
  120. u32 lock_group; /* The lock group this pipe belongs to */
  121. void *bam;
  122. };
  123. /* Connection bookkeeping descriptor struct */
  124. struct sps_connection {
  125. struct list_head list;
  126. /* Source end point parameters */
  127. struct sps_conn_end_pt src;
  128. /* Destination end point parameters */
  129. struct sps_conn_end_pt dest;
  130. /* Resource parameters */
  131. struct sps_mem_buffer desc; /* Descriptor FIFO */
  132. struct sps_mem_buffer data; /* Data FIFO (BAM-to-BAM mode only) */
  133. u32 config; /* Client specified connection configuration */
  134. /* Connection state */
  135. void *client_src;
  136. void *client_dest;
  137. int refs; /* Reference counter */
  138. /* Dynamically allocated resouces, if required */
  139. u32 alloc_src_pipe; /* Source pipe index */
  140. u32 alloc_dest_pipe; /* Destination pipe index */
  141. /* Physical address of descriptor FIFO */
  142. phys_addr_t alloc_desc_base;
  143. phys_addr_t alloc_data_base; /* Physical address of data FIFO */
  144. };
  145. /* Event bookkeeping descriptor struct */
  146. struct sps_q_event {
  147. struct list_head list;
  148. /* Event payload data */
  149. struct sps_event_notify notify;
  150. };
  151. /* Memory heap statistics */
  152. struct sps_mem_stats {
  153. u32 base_addr;
  154. u32 size;
  155. u32 blocks_used;
  156. u32 bytes_used;
  157. u32 max_bytes_used;
  158. };
  159. enum sps_bam_type {
  160. SPS_BAM_LEGACY,
  161. SPS_BAM_NDP,
  162. SPS_BAM_NDP_4K
  163. };
  164. #ifdef CONFIG_DEBUG_FS
  165. /* record debug info for debugfs */
  166. void sps_debugfs_record(const char *);
  167. #endif
  168. /* output the content of BAM-level registers */
  169. void print_bam_reg(void *);
  170. /* output the content of BAM pipe registers */
  171. void print_bam_pipe_reg(void *, u32);
  172. /* output the content of selected BAM-level registers */
  173. void print_bam_selected_reg(void *, u32);
  174. /* output the content of selected BAM pipe registers */
  175. void print_bam_pipe_selected_reg(void *, u32);
  176. /* output descriptor FIFO of a pipe */
  177. void print_bam_pipe_desc_fifo(void *, u32, u32);
  178. /* output BAM_TEST_BUS_REG */
  179. void print_bam_test_bus_reg(void *, u32);
  180. /* halt and un-halt a pipe */
  181. void bam_pipe_halt(void *, u32, bool);
  182. /**
  183. * Translate physical to virtual address
  184. *
  185. * This Function translates physical to virtual address.
  186. *
  187. * @phys_addr - physical address to translate
  188. *
  189. * @return virtual memory pointer
  190. *
  191. */
  192. void *spsi_get_mem_ptr(phys_addr_t phys_addr);
  193. /**
  194. * Allocate I/O (pipe) memory
  195. *
  196. * This function allocates target I/O (pipe) memory.
  197. *
  198. * @bytes - number of bytes to allocate
  199. *
  200. * @return physical address of allocated memory, or SPS_ADDR_INVALID on error
  201. */
  202. phys_addr_t sps_mem_alloc_io(u32 bytes);
  203. /**
  204. * Free I/O (pipe) memory
  205. *
  206. * This function frees target I/O (pipe) memory.
  207. *
  208. * @phys_addr - physical address of memory to free
  209. *
  210. * @bytes - number of bytes to free.
  211. */
  212. void sps_mem_free_io(phys_addr_t phys_addr, u32 bytes);
  213. /**
  214. * Find matching connection mapping
  215. *
  216. * This function searches for a connection mapping that matches the
  217. * parameters supplied by the client. If a match is found, the client's
  218. * parameter struct is updated with the values specified in the mapping.
  219. *
  220. * @connect - pointer to client connection parameters
  221. *
  222. * @return 0 if match is found, negative value otherwise
  223. *
  224. */
  225. int sps_map_find(struct sps_connect *connect);
  226. /**
  227. * Allocate a BAM DMA pipe
  228. *
  229. * This function allocates a BAM DMA pipe, and is intended to be called
  230. * internally from the BAM resource manager. Allocation implies that
  231. * the pipe has been referenced by a client Connect() and is in use.
  232. *
  233. * BAM DMA is permissive with activations, and allows a pipe to be allocated
  234. * with or without a client-initiated allocation. This allows the client to
  235. * specify exactly which pipe should be used directly through the Connect() API.
  236. * sps_dma_alloc_chan() does not allow the client to specify the pipes/channel.
  237. *
  238. * @bam - pointer to BAM device descriptor
  239. *
  240. * @pipe_index - pipe index
  241. *
  242. * @dir - pipe direction
  243. *
  244. * @return 0 on success, negative value on error
  245. */
  246. int sps_dma_pipe_alloc(void *bam, u32 pipe_index, enum sps_mode dir);
  247. /**
  248. * Enable a BAM DMA pipe
  249. *
  250. * This function enables the channel associated with a BAM DMA pipe, and
  251. * is intended to be called internally from the BAM resource manager.
  252. * Enable must occur *after* the pipe has been enabled so that proper
  253. * sequencing between pipe and DMA channel enables can be enforced.
  254. *
  255. * @bam - pointer to BAM device descriptor
  256. *
  257. * @pipe_index - pipe index
  258. *
  259. * @return 0 on success, negative value on error
  260. *
  261. */
  262. int sps_dma_pipe_enable(void *bam, u32 pipe_index);
  263. /**
  264. * Free a BAM DMA pipe
  265. *
  266. * This function disables and frees a BAM DMA pipe, and is intended to be
  267. * called internally from the BAM resource manager. This must occur *after*
  268. * the pipe has been disabled/reset so that proper sequencing between pipe and
  269. * DMA channel resets can be enforced.
  270. *
  271. * @bam_arg - pointer to BAM device descriptor
  272. *
  273. * @pipe_index - pipe index
  274. *
  275. * @return 0 on success, negative value on error
  276. *
  277. */
  278. int sps_dma_pipe_free(void *bam, u32 pipe_index);
  279. /**
  280. * Initialize driver memory module
  281. *
  282. * This function initializes the driver memory module.
  283. *
  284. * @pipemem_phys_base - Pipe-Memory physical base.
  285. *
  286. * @pipemem_size - Pipe-Memory size.
  287. *
  288. * @return 0 on success, negative value on error
  289. *
  290. */
  291. int sps_mem_init(phys_addr_t pipemem_phys_base, u32 pipemem_size);
  292. /**
  293. * De-initialize driver memory module
  294. *
  295. * This function de-initializes the driver memory module.
  296. *
  297. * @return 0 on success, negative value on error
  298. *
  299. */
  300. int sps_mem_de_init(void);
  301. /**
  302. * Initialize BAM DMA module
  303. *
  304. * This function initializes the BAM DMA module.
  305. *
  306. * @bam_props - pointer to BAM DMA devices BSP configuration properties
  307. *
  308. * @return 0 on success, negative value on error
  309. *
  310. */
  311. int sps_dma_init(const struct sps_bam_props *bam_props);
  312. /**
  313. * De-initialize BAM DMA module
  314. *
  315. * This function de-initializes the SPS BAM DMA module.
  316. *
  317. */
  318. void sps_dma_de_init(void);
  319. /**
  320. * Initialize BAM DMA device
  321. *
  322. * This function initializes a BAM DMA device.
  323. *
  324. * @h - BAM handle
  325. *
  326. * @return 0 on success, negative value on error
  327. *
  328. */
  329. int sps_dma_device_init(unsigned long h);
  330. /**
  331. * De-initialize BAM DMA device
  332. *
  333. * This function de-initializes a BAM DMA device.
  334. *
  335. * @h - BAM handle
  336. *
  337. * @return 0 on success, negative value on error
  338. *
  339. */
  340. int sps_dma_device_de_init(unsigned long h);
  341. /**
  342. * Initialize connection mapping module
  343. *
  344. * This function initializes the SPS connection mapping module.
  345. *
  346. * @map_props - pointer to connection mapping BSP configuration properties
  347. *
  348. * @options - driver options bitflags (see SPS_OPT_*)
  349. *
  350. * @return 0 on success, negative value on error
  351. *
  352. */
  353. int sps_map_init(const struct sps_map *map_props, u32 options);
  354. /**
  355. * De-initialize connection mapping module
  356. *
  357. * This function de-initializes the SPS connection mapping module.
  358. *
  359. */
  360. void sps_map_de_init(void);
  361. /*
  362. * bam_pipe_reset - reset a BAM pipe.
  363. * @base: BAM virtual address
  364. * @pipe: pipe index
  365. *
  366. * This function resets a BAM pipe.
  367. */
  368. void bam_pipe_reset(void *base, u32 pipe);
  369. #endif /* _SPSI_H_ */