PageRenderTime 56ms CodeModel.GetById 28ms RepoModel.GetById 1ms app.codeStats 0ms

/drivers/platform/msm/sps/sps_bam.h

https://gitlab.com/SerenityS/msm8974_G2_render_kernel
C Header | 570 lines | 156 code | 65 blank | 349 comment | 0 complexity | b8854bb6af0163534e3332fea632d53b MD5 | raw file
  1. /* Copyright (c) 2011-2013, 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. * Function and data structure declarations for SPS BAM handling.
  14. */
  15. #ifndef _SPSBAM_H_
  16. #define _SPSBAM_H_
  17. #include <linux/types.h>
  18. #include <linux/completion.h>
  19. #include <linux/list.h>
  20. #include <linux/mutex.h>
  21. #include <linux/spinlock.h>
  22. #include "spsi.h"
  23. #define BAM_HANDLE_INVALID 0
  24. enum bam_irq {
  25. BAM_DEV_IRQ_RDY_TO_SLEEP = 0x00000001,
  26. BAM_DEV_IRQ_HRESP_ERROR = 0x00000002,
  27. BAM_DEV_IRQ_ERROR = 0x00000004,
  28. BAM_DEV_IRQ_TIMER = 0x00000010,
  29. };
  30. /* Pipe interrupt mask */
  31. enum bam_pipe_irq {
  32. /* BAM finishes descriptor which has INT bit selected */
  33. BAM_PIPE_IRQ_DESC_INT = 0x00000001,
  34. /* Inactivity timer Expires */
  35. BAM_PIPE_IRQ_TIMER = 0x00000002,
  36. /* Wakeup peripheral (i.e. USB) */
  37. BAM_PIPE_IRQ_WAKE = 0x00000004,
  38. /* Producer - no free space for adding a descriptor */
  39. /* Consumer - no descriptors for processing */
  40. BAM_PIPE_IRQ_OUT_OF_DESC = 0x00000008,
  41. /* Pipe Error interrupt */
  42. BAM_PIPE_IRQ_ERROR = 0x00000010,
  43. /* End-Of-Transfer */
  44. BAM_PIPE_IRQ_EOT = 0x00000020,
  45. /* Pipe RESET unsuccessful */
  46. BAM_PIPE_IRQ_RST_ERROR = 0x00000040,
  47. /* Errorneous Hresponse by AHB MASTER */
  48. BAM_PIPE_IRQ_HRESP_ERROR = 0x00000080,
  49. };
  50. /* Halt Type */
  51. enum bam_halt {
  52. BAM_HALT_OFF = 0,
  53. BAM_HALT_ON = 1,
  54. };
  55. /* Threshold values of the DMA channels */
  56. enum bam_dma_thresh_dma {
  57. BAM_DMA_THRESH_512 = 0x3,
  58. BAM_DMA_THRESH_256 = 0x2,
  59. BAM_DMA_THRESH_128 = 0x1,
  60. BAM_DMA_THRESH_64 = 0x0,
  61. };
  62. /* Weight values of the DMA channels */
  63. enum bam_dma_weight_dma {
  64. BAM_DMA_WEIGHT_HIGH = 7,
  65. BAM_DMA_WEIGHT_MED = 3,
  66. BAM_DMA_WEIGHT_LOW = 1,
  67. BAM_DMA_WEIGHT_DEFAULT = BAM_DMA_WEIGHT_LOW,
  68. BAM_DMA_WEIGHT_DISABLE = 0,
  69. };
  70. /* Invalid pipe index value */
  71. #define SPS_BAM_PIPE_INVALID ((u32)(-1))
  72. /* Parameters for sps_bam_pipe_connect() */
  73. struct sps_bam_connect_param {
  74. /* which end point must be initialized */
  75. enum sps_mode mode;
  76. /* OR'd connection end point options (see SPS_O defines) */
  77. u32 options;
  78. /* SETPEND/MTI interrupt generation parameters */
  79. u32 irq_gen_addr;
  80. u32 irq_gen_data;
  81. };
  82. /* Event registration struct */
  83. struct sps_bam_event_reg {
  84. /* Client's event object handle */
  85. struct completion *xfer_done;
  86. void (*callback)(struct sps_event_notify *notify);
  87. /* Event trigger mode */
  88. enum sps_trigger mode;
  89. /* User pointer that will be provided in event payload data */
  90. void *user;
  91. };
  92. /* Descriptor FIFO cache entry */
  93. struct sps_bam_desc_cache {
  94. struct sps_iovec iovec;
  95. void *user; /* User pointer registered with this transfer */
  96. };
  97. /* Forward declaration */
  98. struct sps_bam;
  99. /* System mode control */
  100. struct sps_bam_sys_mode {
  101. /* Descriptor FIFO control */
  102. u8 *desc_buf; /* Descriptor FIFO for BAM pipe */
  103. u32 desc_offset; /* Next new descriptor to be written to hardware */
  104. u32 acked_offset; /* Next descriptor to be retired by software */
  105. /* Descriptor cache control (!no_queue only) */
  106. u8 *desc_cache; /* Software cache of descriptor FIFO contents */
  107. u32 cache_offset; /* Next descriptor to be cached (ack_xfers only) */
  108. /* User pointers associated with cached descriptors */
  109. void **user_ptrs;
  110. /* Event handling */
  111. struct sps_bam_event_reg event_regs[SPS_EVENT_INDEX(SPS_EVENT_MAX)];
  112. struct list_head events_q;
  113. struct sps_q_event event; /* Temp storage for event creation */
  114. int no_queue; /* Whether events are queued */
  115. int ack_xfers; /* Whether client must ACK all descriptors */
  116. int handler_eot; /* Whether EOT handling is in progress (debug) */
  117. /* Statistics */
  118. #ifdef SPS_BAM_STATISTICS
  119. u32 desc_wr_count;
  120. u32 desc_rd_count;
  121. u32 user_ptrs_count;
  122. u32 user_found;
  123. u32 int_flags;
  124. u32 eot_flags;
  125. u32 callback_events;
  126. u32 wait_events;
  127. u32 queued_events;
  128. u32 get_events;
  129. u32 get_iovecs;
  130. #endif /* SPS_BAM_STATISTICS */
  131. };
  132. /* BAM pipe descriptor */
  133. struct sps_pipe {
  134. struct list_head list;
  135. /* Client state */
  136. u32 client_state;
  137. struct sps_bam *bam;
  138. struct sps_connect connect;
  139. const struct sps_connection *map;
  140. /* Pipe parameters */
  141. u32 state;
  142. u32 pipe_index;
  143. u32 pipe_index_mask;
  144. u32 irq_mask;
  145. int polled;
  146. int hybrid;
  147. u32 irq_gen_addr;
  148. enum sps_mode mode;
  149. u32 num_descs; /* Size (number of elements) of descriptor FIFO */
  150. u32 desc_size; /* Size (bytes) of descriptor FIFO */
  151. int wake_up_is_one_shot; /* Whether WAKEUP event is a one-shot or not */
  152. /* System mode control */
  153. struct sps_bam_sys_mode sys;
  154. };
  155. /* BAM device descriptor */
  156. struct sps_bam {
  157. struct list_head list;
  158. /* BAM device properties, including connection defaults */
  159. struct sps_bam_props props;
  160. /* BAM device state */
  161. u32 state;
  162. struct mutex lock;
  163. void *base; /* BAM virtual base address */
  164. u32 version;
  165. spinlock_t isr_lock;
  166. spinlock_t connection_lock;
  167. unsigned long irqsave_flags;
  168. /* Pipe state */
  169. u32 pipe_active_mask;
  170. u32 pipe_remote_mask;
  171. struct sps_pipe *pipes[BAM_MAX_PIPES];
  172. struct list_head pipes_q;
  173. /* Statistics */
  174. u32 irq_from_disabled_pipe;
  175. u32 event_trigger_failures;
  176. };
  177. /**
  178. * BAM driver initialization
  179. *
  180. * This function initializes the BAM driver.
  181. *
  182. * @options - driver options bitflags (see SPS_OPT_*)
  183. *
  184. * @return 0 on success, negative value on error
  185. *
  186. */
  187. int sps_bam_driver_init(u32 options);
  188. /**
  189. * BAM device initialization
  190. *
  191. * This function initializes a BAM device.
  192. *
  193. * @dev - pointer to BAM device descriptor
  194. *
  195. * @return 0 on success, negative value on error
  196. *
  197. */
  198. int sps_bam_device_init(struct sps_bam *dev);
  199. /**
  200. * BAM device de-initialization
  201. *
  202. * This function de-initializes a BAM device.
  203. *
  204. * @dev - pointer to BAM device descriptor
  205. *
  206. * @return 0 on success, negative value on error
  207. *
  208. */
  209. int sps_bam_device_de_init(struct sps_bam *dev);
  210. /**
  211. * BAM device reset
  212. *
  213. * This Function resets a BAM device.
  214. *
  215. * @dev - pointer to BAM device descriptor
  216. *
  217. * @return 0 on success, negative value on error
  218. *
  219. */
  220. int sps_bam_reset(struct sps_bam *dev);
  221. /**
  222. * BAM device enable
  223. *
  224. * This function enables a BAM device.
  225. *
  226. * @dev - pointer to BAM device descriptor
  227. *
  228. * @return 0 on success, negative value on error
  229. *
  230. */
  231. int sps_bam_enable(struct sps_bam *dev);
  232. /**
  233. * BAM device disable
  234. *
  235. * This Function disables a BAM device.
  236. *
  237. * @dev - pointer to BAM device descriptor
  238. *
  239. * @return 0 on success, negative value on error
  240. *
  241. */
  242. int sps_bam_disable(struct sps_bam *dev);
  243. /**
  244. * Allocate a BAM pipe
  245. *
  246. * This function allocates a BAM pipe.
  247. *
  248. * @dev - pointer to BAM device descriptor
  249. *
  250. * @pipe_index - client-specified pipe index, or SPS_BAM_PIPE_INVALID if
  251. * any available pipe is acceptable
  252. *
  253. * @return - allocated pipe index, or SPS_BAM_PIPE_INVALID on error
  254. *
  255. */
  256. u32 sps_bam_pipe_alloc(struct sps_bam *dev, u32 pipe_index);
  257. /**
  258. * Free a BAM pipe
  259. *
  260. * This function frees a BAM pipe.
  261. *
  262. * @dev - pointer to BAM device descriptor
  263. *
  264. * @pipe_index - pipe index
  265. *
  266. */
  267. void sps_bam_pipe_free(struct sps_bam *dev, u32 pipe_index);
  268. /**
  269. * Establish BAM pipe connection
  270. *
  271. * This function establishes a connection for a BAM pipe (end point).
  272. *
  273. * @client - pointer to client pipe state struct
  274. *
  275. * @params - connection parameters
  276. *
  277. * @return 0 on success, negative value on error
  278. *
  279. */
  280. int sps_bam_pipe_connect(struct sps_pipe *client,
  281. const struct sps_bam_connect_param *params);
  282. /**
  283. * Disconnect a BAM pipe connection
  284. *
  285. * This function disconnects a connection for a BAM pipe (end point).
  286. *
  287. * @dev - pointer to BAM device descriptor
  288. *
  289. * @pipe_index - pipe index
  290. *
  291. * @return 0 on success, negative value on error
  292. *
  293. */
  294. int sps_bam_pipe_disconnect(struct sps_bam *dev, u32 pipe_index);
  295. /**
  296. * Set BAM pipe parameters
  297. *
  298. * This function sets parameters for a BAM pipe.
  299. *
  300. * @dev - pointer to BAM device descriptor
  301. *
  302. * @pipe_index - pipe index
  303. *
  304. * @options - bitflag options (see SPS_O_*)
  305. *
  306. * @return 0 on success, negative value on error
  307. *
  308. */
  309. int sps_bam_pipe_set_params(struct sps_bam *dev, u32 pipe_index, u32 options);
  310. /**
  311. * Enable a BAM pipe
  312. *
  313. * This function enables a BAM pipe. Note that this function
  314. * is separate from the pipe connect function to allow proper
  315. * sequencing of consumer enable followed by producer enable.
  316. *
  317. * @dev - pointer to BAM device descriptor
  318. *
  319. * @pipe_index - pipe index
  320. *
  321. * @return 0 on success, negative value on error
  322. *
  323. */
  324. int sps_bam_pipe_enable(struct sps_bam *dev, u32 pipe_index);
  325. /**
  326. * Disable a BAM pipe
  327. *
  328. * This function disables a BAM pipe.
  329. *
  330. * @dev - pointer to BAM device descriptor
  331. *
  332. * @pipe_index - pipe index
  333. *
  334. * @return 0 on success, negative value on error
  335. *
  336. */
  337. int sps_bam_pipe_disable(struct sps_bam *dev, u32 pipe_index);
  338. /**
  339. * Register an event for a BAM pipe
  340. *
  341. * This function registers an event for a BAM pipe.
  342. *
  343. * @dev - pointer to BAM device descriptor
  344. *
  345. * @pipe_index - pipe index
  346. *
  347. * @reg - pointer to event registration struct
  348. *
  349. * @return 0 on success, negative value on error
  350. *
  351. */
  352. int sps_bam_pipe_reg_event(struct sps_bam *dev, u32 pipe_index,
  353. struct sps_register_event *reg);
  354. /**
  355. * Submit a transfer of a single buffer to a BAM pipe
  356. *
  357. * This function submits a transfer of a single buffer to a BAM pipe.
  358. *
  359. * @dev - pointer to BAM device descriptor
  360. *
  361. * @pipe_index - pipe index
  362. *
  363. * @addr - physical address of buffer to transfer
  364. *
  365. * @size - number of bytes to transfer
  366. *
  367. * @user - user pointer to register for event
  368. *
  369. * @flags - descriptor flags (see SPS_IOVEC_FLAG defines)
  370. *
  371. * @return 0 on success, negative value on error
  372. *
  373. */
  374. int sps_bam_pipe_transfer_one(struct sps_bam *dev, u32 pipe_index, u32 addr,
  375. u32 size, void *user, u32 flags);
  376. /**
  377. * Submit a transfer to a BAM pipe
  378. *
  379. * This function submits a transfer to a BAM pipe.
  380. *
  381. * @dev - pointer to BAM device descriptor
  382. *
  383. * @pipe_index - pipe index
  384. *
  385. * @transfer - pointer to transfer struct
  386. *
  387. * @return 0 on success, negative value on error
  388. *
  389. */
  390. int sps_bam_pipe_transfer(struct sps_bam *dev, u32 pipe_index,
  391. struct sps_transfer *transfer);
  392. /**
  393. * Get a BAM pipe event
  394. *
  395. * This function polls for a BAM pipe event.
  396. *
  397. * @dev - pointer to BAM device descriptor
  398. *
  399. * @pipe_index - pipe index
  400. *
  401. * @notify - pointer to event notification struct
  402. *
  403. * @return 0 on success, negative value on error
  404. *
  405. */
  406. int sps_bam_pipe_get_event(struct sps_bam *dev, u32 pipe_index,
  407. struct sps_event_notify *notify);
  408. /**
  409. * Get processed I/O vector
  410. *
  411. * This function fetches the next processed I/O vector.
  412. *
  413. * @dev - pointer to BAM device descriptor
  414. *
  415. * @pipe_index - pipe index
  416. *
  417. * @iovec - Pointer to I/O vector struct (output).
  418. * This struct will be zeroed if there are no more processed I/O vectors.
  419. *
  420. * @return 0 on success, negative value on error
  421. */
  422. int sps_bam_pipe_get_iovec(struct sps_bam *dev, u32 pipe_index,
  423. struct sps_iovec *iovec);
  424. /**
  425. * Determine whether a BAM pipe descriptor FIFO is empty
  426. *
  427. * This function returns the empty state of a BAM pipe descriptor FIFO.
  428. *
  429. * The pipe mutex must be locked before calling this function.
  430. *
  431. * @dev - pointer to BAM device descriptor
  432. *
  433. * @pipe_index - pipe index
  434. *
  435. * @empty - pointer to client's empty status word (boolean)
  436. *
  437. * @return 0 on success, negative value on error
  438. *
  439. */
  440. int sps_bam_pipe_is_empty(struct sps_bam *dev, u32 pipe_index, u32 *empty);
  441. /**
  442. * Get number of free slots in a BAM pipe descriptor FIFO
  443. *
  444. * This function returns the number of free slots in a BAM pipe descriptor FIFO.
  445. *
  446. * The pipe mutex must be locked before calling this function.
  447. *
  448. * @dev - pointer to BAM device descriptor
  449. *
  450. * @pipe_index - pipe index
  451. *
  452. * @count - pointer to count status
  453. *
  454. * @return 0 on success, negative value on error
  455. *
  456. */
  457. int sps_bam_get_free_count(struct sps_bam *dev, u32 pipe_index, u32 *count);
  458. /**
  459. * Set BAM pipe to satellite ownership
  460. *
  461. * This function sets the BAM pipe to satellite ownership.
  462. *
  463. * @dev - pointer to BAM device descriptor
  464. *
  465. * @pipe_index - pipe index
  466. *
  467. * @return 0 on success, negative value on error
  468. *
  469. */
  470. int sps_bam_set_satellite(struct sps_bam *dev, u32 pipe_index);
  471. /**
  472. * Perform BAM pipe timer control
  473. *
  474. * This function performs BAM pipe timer control operations.
  475. *
  476. * @dev - pointer to BAM device descriptor
  477. *
  478. * @pipe_index - pipe index
  479. *
  480. * @timer_ctrl - Pointer to timer control specification
  481. *
  482. * @timer_result - Pointer to buffer for timer operation result.
  483. * This argument can be NULL if no result is expected for the operation.
  484. * If non-NULL, the current timer value will always provided.
  485. *
  486. * @return 0 on success, negative value on error
  487. *
  488. */
  489. int sps_bam_pipe_timer_ctrl(struct sps_bam *dev, u32 pipe_index,
  490. struct sps_timer_ctrl *timer_ctrl,
  491. struct sps_timer_result *timer_result);
  492. /**
  493. * Get the number of unused descriptors in the descriptor FIFO
  494. * of a pipe
  495. *
  496. * @dev - pointer to BAM device descriptor
  497. *
  498. * @pipe_index - pipe index
  499. *
  500. * @desc_num - number of unused descriptors
  501. *
  502. */
  503. int sps_bam_pipe_get_unused_desc_num(struct sps_bam *dev, u32 pipe_index,
  504. u32 *desc_num);
  505. #endif /* _SPSBAM_H_ */