knav_qmss.h 9.7 KB

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