knav_qmss.h 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387
  1. /*
  2. * Keystone Navigator QMSS driver internal header
  3. *
  4. * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
  5. * Author: Sandeep Nair <sandeep_n@ti.com>
  6. * Cyril Chemparathy <cyril@ti.com>
  7. * Santosh Shilimkar <santosh.shilimkar@ti.com>
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License
  11. * version 2 as published by the Free Software Foundation.
  12. *
  13. * This program is distributed in the hope that it will be useful, but
  14. * WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  16. * General Public License for more details.
  17. */
  18. #ifndef __KNAV_QMSS_H__
  19. #define __KNAV_QMSS_H__
  20. #define THRESH_GTE BIT(7)
  21. #define THRESH_LT 0
  22. #define PDSP_CTRL_PC_MASK 0xffff0000
  23. #define PDSP_CTRL_SOFT_RESET BIT(0)
  24. #define PDSP_CTRL_ENABLE BIT(1)
  25. #define PDSP_CTRL_RUNNING BIT(15)
  26. #define ACC_MAX_CHANNEL 48
  27. #define ACC_DEFAULT_PERIOD 25 /* usecs */
  28. #define ACC_CHANNEL_INT_BASE 2
  29. #define ACC_LIST_ENTRY_TYPE 1
  30. #define ACC_LIST_ENTRY_WORDS (1 << ACC_LIST_ENTRY_TYPE)
  31. #define ACC_LIST_ENTRY_QUEUE_IDX 0
  32. #define ACC_LIST_ENTRY_DESC_IDX (ACC_LIST_ENTRY_WORDS - 1)
  33. #define ACC_CMD_DISABLE_CHANNEL 0x80
  34. #define ACC_CMD_ENABLE_CHANNEL 0x81
  35. #define ACC_CFG_MULTI_QUEUE BIT(21)
  36. #define ACC_INTD_OFFSET_EOI (0x0010)
  37. #define ACC_INTD_OFFSET_COUNT(ch) (0x0300 + 4 * (ch))
  38. #define ACC_INTD_OFFSET_STATUS(ch) (0x0200 + 4 * ((ch) / 32))
  39. #define RANGE_MAX_IRQS 64
  40. #define ACC_DESCS_MAX SZ_1K
  41. #define ACC_DESCS_MASK (ACC_DESCS_MAX - 1)
  42. #define DESC_SIZE_MASK 0xful
  43. #define DESC_PTR_MASK (~DESC_SIZE_MASK)
  44. #define KNAV_NAME_SIZE 32
  45. enum knav_acc_result {
  46. ACC_RET_IDLE,
  47. ACC_RET_SUCCESS,
  48. ACC_RET_INVALID_COMMAND,
  49. ACC_RET_INVALID_CHANNEL,
  50. ACC_RET_INACTIVE_CHANNEL,
  51. ACC_RET_ACTIVE_CHANNEL,
  52. ACC_RET_INVALID_QUEUE,
  53. ACC_RET_INVALID_RET,
  54. };
  55. struct knav_reg_config {
  56. u32 revision;
  57. u32 __pad1;
  58. u32 divert;
  59. u32 link_ram_base0;
  60. u32 link_ram_size0;
  61. u32 link_ram_base1;
  62. u32 __pad2[2];
  63. u32 starvation[0];
  64. };
  65. struct knav_reg_region {
  66. u32 base;
  67. u32 start_index;
  68. u32 size_count;
  69. u32 __pad;
  70. };
  71. struct knav_reg_pdsp_regs {
  72. u32 control;
  73. u32 status;
  74. u32 cycle_count;
  75. u32 stall_count;
  76. };
  77. struct knav_reg_acc_command {
  78. u32 command;
  79. u32 queue_mask;
  80. u32 list_phys;
  81. u32 queue_num;
  82. u32 timer_config;
  83. };
  84. struct knav_link_ram_block {
  85. dma_addr_t phys;
  86. void *virt;
  87. size_t size;
  88. };
  89. struct knav_acc_info {
  90. u32 pdsp_id;
  91. u32 start_channel;
  92. u32 list_entries;
  93. u32 pacing_mode;
  94. u32 timer_count;
  95. int mem_size;
  96. int list_size;
  97. struct knav_pdsp_info *pdsp;
  98. };
  99. struct knav_acc_channel {
  100. u32 channel;
  101. u32 list_index;
  102. u32 open_mask;
  103. u32 *list_cpu[2];
  104. dma_addr_t list_dma[2];
  105. char name[KNAV_NAME_SIZE];
  106. atomic_t retrigger_count;
  107. };
  108. struct knav_pdsp_info {
  109. const char *name;
  110. struct knav_reg_pdsp_regs __iomem *regs;
  111. union {
  112. void __iomem *command;
  113. struct knav_reg_acc_command __iomem *acc_command;
  114. u32 __iomem *qos_command;
  115. };
  116. void __iomem *intd;
  117. u32 __iomem *iram;
  118. u32 id;
  119. struct list_head list;
  120. bool loaded;
  121. bool started;
  122. };
  123. struct knav_qmgr_info {
  124. unsigned start_queue;
  125. unsigned num_queues;
  126. struct knav_reg_config __iomem *reg_config;
  127. struct knav_reg_region __iomem *reg_region;
  128. struct knav_reg_queue __iomem *reg_push, *reg_pop, *reg_peek;
  129. void __iomem *reg_status;
  130. struct list_head list;
  131. };
  132. #define KNAV_NUM_LINKRAM 2
  133. /**
  134. * struct knav_queue_stats: queue statistics
  135. * pushes: number of push operations
  136. * pops: number of pop operations
  137. * push_errors: number of push errors
  138. * pop_errors: number of pop errors
  139. * notifies: notifier counts
  140. */
  141. struct knav_queue_stats {
  142. atomic_t pushes;
  143. atomic_t pops;
  144. atomic_t push_errors;
  145. atomic_t pop_errors;
  146. atomic_t notifies;
  147. };
  148. /**
  149. * struct knav_reg_queue: queue registers
  150. * @entry_count: valid entries in the queue
  151. * @byte_count: total byte count in thhe queue
  152. * @packet_size: packet size for the queue
  153. * @ptr_size_thresh: packet pointer size threshold
  154. */
  155. struct knav_reg_queue {
  156. u32 entry_count;
  157. u32 byte_count;
  158. u32 packet_size;
  159. u32 ptr_size_thresh;
  160. };
  161. /**
  162. * struct knav_region: qmss region info
  163. * @dma_start, dma_end: start and end dma address
  164. * @virt_start, virt_end: start and end virtual address
  165. * @desc_size: descriptor size
  166. * @used_desc: consumed descriptors
  167. * @id: region number
  168. * @num_desc: total descriptors
  169. * @link_index: index of the first descriptor
  170. * @name: region name
  171. * @list: instance in the device's region list
  172. * @pools: list of descriptor pools in the region
  173. */
  174. struct knav_region {
  175. dma_addr_t dma_start, dma_end;
  176. void *virt_start, *virt_end;
  177. unsigned desc_size;
  178. unsigned used_desc;
  179. unsigned id;
  180. unsigned num_desc;
  181. unsigned link_index;
  182. const char *name;
  183. struct list_head list;
  184. struct list_head pools;
  185. };
  186. /**
  187. * struct knav_pool: qmss pools
  188. * @dev: device pointer
  189. * @region: qmss region info
  190. * @queue: queue registers
  191. * @kdev: qmss device pointer
  192. * @region_offset: offset from the base
  193. * @num_desc: total descriptors
  194. * @desc_size: descriptor size
  195. * @region_id: region number
  196. * @name: pool name
  197. * @list: list head
  198. * @region_inst: instance in the region's pool list
  199. */
  200. struct knav_pool {
  201. struct device *dev;
  202. struct knav_region *region;
  203. struct knav_queue *queue;
  204. struct knav_device *kdev;
  205. int region_offset;
  206. int num_desc;
  207. int desc_size;
  208. int region_id;
  209. const char *name;
  210. struct list_head list;
  211. struct list_head region_inst;
  212. };
  213. /**
  214. * struct knav_queue_inst: qmss queue instace properties
  215. * @descs: descriptor pointer
  216. * @desc_head, desc_tail, desc_count: descriptor counters
  217. * @acc: accumulator channel pointer
  218. * @kdev: qmss device pointer
  219. * @range: range info
  220. * @qmgr: queue manager info
  221. * @id: queue instace id
  222. * @irq_num: irq line number
  223. * @notify_needed: notifier needed based on queue type
  224. * @num_notifiers: total notifiers
  225. * @handles: list head
  226. * @name: queue instance name
  227. * @irq_name: irq line name
  228. */
  229. struct knav_queue_inst {
  230. u32 *descs;
  231. atomic_t desc_head, desc_tail, desc_count;
  232. struct knav_acc_channel *acc;
  233. struct knav_device *kdev;
  234. struct knav_range_info *range;
  235. struct knav_qmgr_info *qmgr;
  236. u32 id;
  237. int irq_num;
  238. int notify_needed;
  239. atomic_t num_notifiers;
  240. struct list_head handles;
  241. const char *name;
  242. const char *irq_name;
  243. };
  244. /**
  245. * struct knav_queue: qmss queue properties
  246. * @reg_push, reg_pop, reg_peek: push, pop queue registers
  247. * @inst: qmss queue instace properties
  248. * @notifier_fn: notifier function
  249. * @notifier_fn_arg: notifier function argument
  250. * @notifier_enabled: notier enabled for a give queue
  251. * @rcu: rcu head
  252. * @flags: queue flags
  253. * @list: list head
  254. */
  255. struct knav_queue {
  256. struct knav_reg_queue __iomem *reg_push, *reg_pop, *reg_peek;
  257. struct knav_queue_inst *inst;
  258. struct knav_queue_stats stats;
  259. knav_queue_notify_fn notifier_fn;
  260. void *notifier_fn_arg;
  261. atomic_t notifier_enabled;
  262. struct rcu_head rcu;
  263. unsigned flags;
  264. struct list_head list;
  265. };
  266. struct knav_device {
  267. struct device *dev;
  268. unsigned base_id;
  269. unsigned num_queues;
  270. unsigned num_queues_in_use;
  271. unsigned inst_shift;
  272. struct knav_link_ram_block link_rams[KNAV_NUM_LINKRAM];
  273. void *instances;
  274. struct list_head regions;
  275. struct list_head queue_ranges;
  276. struct list_head pools;
  277. struct list_head pdsps;
  278. struct list_head qmgrs;
  279. };
  280. struct knav_range_ops {
  281. int (*init_range)(struct knav_range_info *range);
  282. int (*free_range)(struct knav_range_info *range);
  283. int (*init_queue)(struct knav_range_info *range,
  284. struct knav_queue_inst *inst);
  285. int (*open_queue)(struct knav_range_info *range,
  286. struct knav_queue_inst *inst, unsigned flags);
  287. int (*close_queue)(struct knav_range_info *range,
  288. struct knav_queue_inst *inst);
  289. int (*set_notify)(struct knav_range_info *range,
  290. struct knav_queue_inst *inst, bool enabled);
  291. };
  292. struct knav_irq_info {
  293. int irq;
  294. u32 cpu_map;
  295. };
  296. struct knav_range_info {
  297. const char *name;
  298. struct knav_device *kdev;
  299. unsigned queue_base;
  300. unsigned num_queues;
  301. void *queue_base_inst;
  302. unsigned flags;
  303. struct list_head list;
  304. struct knav_range_ops *ops;
  305. struct knav_acc_info acc_info;
  306. struct knav_acc_channel *acc;
  307. unsigned num_irqs;
  308. struct knav_irq_info irqs[RANGE_MAX_IRQS];
  309. };
  310. #define RANGE_RESERVED BIT(0)
  311. #define RANGE_HAS_IRQ BIT(1)
  312. #define RANGE_HAS_ACCUMULATOR BIT(2)
  313. #define RANGE_MULTI_QUEUE BIT(3)
  314. #define for_each_region(kdev, region) \
  315. list_for_each_entry(region, &kdev->regions, list)
  316. #define first_region(kdev) \
  317. list_first_entry_or_null(&kdev->regions, \
  318. struct knav_region, list)
  319. #define for_each_queue_range(kdev, range) \
  320. list_for_each_entry(range, &kdev->queue_ranges, list)
  321. #define first_queue_range(kdev) \
  322. list_first_entry_or_null(&kdev->queue_ranges, \
  323. struct knav_range_info, list)
  324. #define for_each_pool(kdev, pool) \
  325. list_for_each_entry(pool, &kdev->pools, list)
  326. #define for_each_pdsp(kdev, pdsp) \
  327. list_for_each_entry(pdsp, &kdev->pdsps, list)
  328. #define for_each_qmgr(kdev, qmgr) \
  329. list_for_each_entry(qmgr, &kdev->qmgrs, list)
  330. static inline struct knav_pdsp_info *
  331. knav_find_pdsp(struct knav_device *kdev, unsigned pdsp_id)
  332. {
  333. struct knav_pdsp_info *pdsp;
  334. for_each_pdsp(kdev, pdsp)
  335. if (pdsp_id == pdsp->id)
  336. return pdsp;
  337. return NULL;
  338. }
  339. extern int knav_init_acc_range(struct knav_device *kdev,
  340. struct device_node *node,
  341. struct knav_range_info *range);
  342. extern void knav_queue_notify(struct knav_queue_inst *inst);
  343. #endif /* __KNAV_QMSS_H__ */