2 * Keystone Navigator QMSS driver internal header
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>
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.
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.
19 #ifndef __KNAV_QMSS_H__
20 #define __KNAV_QMSS_H__
22 #define THRESH_GTE BIT(7)
25 #define PDSP_CTRL_PC_MASK 0xffff0000
26 #define PDSP_CTRL_SOFT_RESET BIT(0)
27 #define PDSP_CTRL_ENABLE BIT(1)
28 #define PDSP_CTRL_RUNNING BIT(15)
30 #define ACC_MAX_CHANNEL 48
31 #define ACC_DEFAULT_PERIOD 25 /* usecs */
33 #define ACC_CHANNEL_INT_BASE 2
35 #define ACC_LIST_ENTRY_TYPE 1
36 #define ACC_LIST_ENTRY_WORDS (1 << ACC_LIST_ENTRY_TYPE)
37 #define ACC_LIST_ENTRY_QUEUE_IDX 0
38 #define ACC_LIST_ENTRY_DESC_IDX (ACC_LIST_ENTRY_WORDS - 1)
40 #define ACC_CMD_DISABLE_CHANNEL 0x80
41 #define ACC_CMD_ENABLE_CHANNEL 0x81
42 #define ACC_CFG_MULTI_QUEUE BIT(21)
44 #define ACC_INTD_OFFSET_EOI (0x0010)
45 #define ACC_INTD_OFFSET_COUNT(ch) (0x0300 + 4 * (ch))
46 #define ACC_INTD_OFFSET_STATUS(ch) (0x0200 + 4 * ((ch) / 32))
48 #define RANGE_MAX_IRQS 64
50 #define ACC_DESCS_MAX SZ_1K
51 #define ACC_DESCS_MASK (ACC_DESCS_MAX - 1)
52 #define DESC_SIZE_MASK 0xful
53 #define DESC_PTR_MASK (~DESC_SIZE_MASK)
55 #define KNAV_NAME_SIZE 32
57 enum knav_acc_result
{
60 ACC_RET_INVALID_COMMAND
,
61 ACC_RET_INVALID_CHANNEL
,
62 ACC_RET_INACTIVE_CHANNEL
,
63 ACC_RET_ACTIVE_CHANNEL
,
64 ACC_RET_INVALID_QUEUE
,
68 struct knav_reg_config
{
79 struct knav_reg_region
{
86 struct knav_reg_pdsp_regs
{
93 struct knav_reg_acc_command
{
101 struct knav_link_ram_block
{
107 struct knav_acc_info
{
115 struct knav_pdsp_info
*pdsp
;
118 struct knav_acc_channel
{
123 dma_addr_t list_dma
[2];
124 char name
[KNAV_NAME_SIZE
];
125 atomic_t retrigger_count
;
128 struct knav_pdsp_info
{
130 struct knav_reg_pdsp_regs __iomem
*regs
;
132 void __iomem
*command
;
133 struct knav_reg_acc_command __iomem
*acc_command
;
134 u32 __iomem
*qos_command
;
138 const char *firmware
;
140 struct list_head list
;
143 struct knav_qmgr_info
{
144 unsigned start_queue
;
146 struct knav_reg_config __iomem
*reg_config
;
147 struct knav_reg_region __iomem
*reg_region
;
148 struct knav_reg_queue __iomem
*reg_push
, *reg_pop
, *reg_peek
;
149 void __iomem
*reg_status
;
150 struct list_head list
;
153 #define KNAV_NUM_LINKRAM 2
156 * struct knav_queue_stats: queue statistics
157 * pushes: number of push operations
158 * pops: number of pop operations
159 * push_errors: number of push errors
160 * pop_errors: number of pop errors
161 * notifies: notifier counts
163 struct knav_queue_stats
{
166 atomic_t push_errors
;
172 * struct knav_reg_queue: queue registers
173 * @entry_count: valid entries in the queue
174 * @byte_count: total byte count in thhe queue
175 * @packet_size: packet size for the queue
176 * @ptr_size_thresh: packet pointer size threshold
178 struct knav_reg_queue
{
186 * struct knav_region: qmss region info
187 * @dma_start, dma_end: start and end dma address
188 * @virt_start, virt_end: start and end virtual address
189 * @desc_size: descriptor size
190 * @used_desc: consumed descriptors
192 * @num_desc: total descriptors
193 * @link_index: index of the first descriptor
195 * @list: instance in the device's region list
196 * @pools: list of descriptor pools in the region
199 dma_addr_t dma_start
, dma_end
;
200 void *virt_start
, *virt_end
;
207 struct list_head list
;
208 struct list_head pools
;
212 * struct knav_pool: qmss pools
213 * @dev: device pointer
214 * @region: qmss region info
215 * @queue: queue registers
216 * @kdev: qmss device pointer
217 * @region_offset: offset from the base
218 * @num_desc: total descriptors
219 * @desc_size: descriptor size
220 * @region_id: region number
223 * @region_inst: instance in the region's pool list
227 struct knav_region
*region
;
228 struct knav_queue
*queue
;
229 struct knav_device
*kdev
;
235 struct list_head list
;
236 struct list_head region_inst
;
240 * struct knav_queue_inst: qmss queue instace properties
241 * @descs: descriptor pointer
242 * @desc_head, desc_tail, desc_count: descriptor counters
243 * @acc: accumulator channel pointer
244 * @kdev: qmss device pointer
246 * @qmgr: queue manager info
247 * @id: queue instace id
248 * @irq_num: irq line number
249 * @notify_needed: notifier needed based on queue type
250 * @num_notifiers: total notifiers
251 * @handles: list head
252 * @name: queue instance name
253 * @irq_name: irq line name
255 struct knav_queue_inst
{
257 atomic_t desc_head
, desc_tail
, desc_count
;
258 struct knav_acc_channel
*acc
;
259 struct knav_device
*kdev
;
260 struct knav_range_info
*range
;
261 struct knav_qmgr_info
*qmgr
;
265 atomic_t num_notifiers
;
266 struct list_head handles
;
268 const char *irq_name
;
272 * struct knav_queue: qmss queue properties
273 * @reg_push, reg_pop, reg_peek: push, pop queue registers
274 * @inst: qmss queue instace properties
275 * @notifier_fn: notifier function
276 * @notifier_fn_arg: notifier function argument
277 * @notifier_enabled: notier enabled for a give queue
279 * @flags: queue flags
283 struct knav_reg_queue __iomem
*reg_push
, *reg_pop
, *reg_peek
;
284 struct knav_queue_inst
*inst
;
285 struct knav_queue_stats stats
;
286 knav_queue_notify_fn notifier_fn
;
287 void *notifier_fn_arg
;
288 atomic_t notifier_enabled
;
291 struct list_head list
;
298 unsigned num_queues_in_use
;
300 struct knav_link_ram_block link_rams
[KNAV_NUM_LINKRAM
];
302 struct list_head regions
;
303 struct list_head queue_ranges
;
304 struct list_head pools
;
305 struct list_head pdsps
;
306 struct list_head qmgrs
;
309 struct knav_range_ops
{
310 int (*init_range
)(struct knav_range_info
*range
);
311 int (*free_range
)(struct knav_range_info
*range
);
312 int (*init_queue
)(struct knav_range_info
*range
,
313 struct knav_queue_inst
*inst
);
314 int (*open_queue
)(struct knav_range_info
*range
,
315 struct knav_queue_inst
*inst
, unsigned flags
);
316 int (*close_queue
)(struct knav_range_info
*range
,
317 struct knav_queue_inst
*inst
);
318 int (*set_notify
)(struct knav_range_info
*range
,
319 struct knav_queue_inst
*inst
, bool enabled
);
322 struct knav_irq_info
{
327 struct knav_range_info
{
329 struct knav_device
*kdev
;
332 void *queue_base_inst
;
334 struct list_head list
;
335 struct knav_range_ops
*ops
;
336 struct knav_acc_info acc_info
;
337 struct knav_acc_channel
*acc
;
339 struct knav_irq_info irqs
[RANGE_MAX_IRQS
];
342 #define RANGE_RESERVED BIT(0)
343 #define RANGE_HAS_IRQ BIT(1)
344 #define RANGE_HAS_ACCUMULATOR BIT(2)
345 #define RANGE_MULTI_QUEUE BIT(3)
347 #define for_each_region(kdev, region) \
348 list_for_each_entry(region, &kdev->regions, list)
350 #define first_region(kdev) \
351 list_first_entry_or_null(&kdev->regions, \
352 struct knav_region, list)
354 #define for_each_queue_range(kdev, range) \
355 list_for_each_entry(range, &kdev->queue_ranges, list)
357 #define first_queue_range(kdev) \
358 list_first_entry_or_null(&kdev->queue_ranges, \
359 struct knav_range_info, list)
361 #define for_each_pool(kdev, pool) \
362 list_for_each_entry(pool, &kdev->pools, list)
364 #define for_each_pdsp(kdev, pdsp) \
365 list_for_each_entry(pdsp, &kdev->pdsps, list)
367 #define for_each_qmgr(kdev, qmgr) \
368 list_for_each_entry(qmgr, &kdev->qmgrs, list)
370 static inline struct knav_pdsp_info
*
371 knav_find_pdsp(struct knav_device
*kdev
, unsigned pdsp_id
)
373 struct knav_pdsp_info
*pdsp
;
375 for_each_pdsp(kdev
, pdsp
)
376 if (pdsp_id
== pdsp
->id
)
381 extern int knav_init_acc_range(struct knav_device
*kdev
,
382 struct device_node
*node
,
383 struct knav_range_info
*range
);
384 extern void knav_queue_notify(struct knav_queue_inst
*inst
);
386 #endif /* __KNAV_QMSS_H__ */