Lines Matching +full:irqs +full:- +full:map +full:- +full:range

1 // SPDX-License-Identifier: GPL-2.0-only
5 * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com
12 #include <linux/dma-mapping.h>
44 * are to be re-defined
57 (kdev->instances + (idx << kdev->inst_shift))
60 list_for_each_entry_rcu(qh, &inst->handles, list, \
64 for (idx = 0, inst = kdev->instances; \
65 idx < (kdev)->num_queues_in_use; \
84 * @inst: - qmss queue instance like accumulator
95 if (atomic_read(&qh->notifier_enabled) <= 0) in knav_queue_notify()
97 if (WARN_ON(!qh->notifier_fn)) in knav_queue_notify()
99 this_cpu_inc(qh->stats->notifies); in knav_queue_notify()
100 qh->notifier_fn(qh->notifier_fn_arg); in knav_queue_notify()
114 static int knav_queue_setup_irq(struct knav_range_info *range, in knav_queue_setup_irq() argument
117 unsigned queue = inst->id - range->queue_base; in knav_queue_setup_irq()
120 if (range->flags & RANGE_HAS_IRQ) { in knav_queue_setup_irq()
121 irq = range->irqs[queue].irq; in knav_queue_setup_irq()
123 inst->irq_name, inst); in knav_queue_setup_irq()
127 if (range->irqs[queue].cpu_mask) { in knav_queue_setup_irq()
128 ret = irq_set_affinity_hint(irq, range->irqs[queue].cpu_mask); in knav_queue_setup_irq()
130 dev_warn(range->kdev->dev, in knav_queue_setup_irq()
141 struct knav_range_info *range = inst->range; in knav_queue_free_irq() local
142 unsigned queue = inst->id - inst->range->queue_base; in knav_queue_free_irq()
145 if (range->flags & RANGE_HAS_IRQ) { in knav_queue_free_irq()
146 irq = range->irqs[queue].irq; in knav_queue_free_irq()
154 return !list_empty(&inst->handles); in knav_queue_is_busy()
159 return inst->range->flags & RANGE_RESERVED; in knav_queue_is_reserved()
168 if (tmp->flags & KNAV_QUEUE_SHARED) { in knav_queue_is_shared()
181 (inst->range->flags & RANGE_HAS_IRQ)) { in knav_queue_match_type()
184 (inst->range->flags & RANGE_HAS_ACCUMULATOR)) { in knav_queue_match_type()
187 !(inst->range->flags & in knav_queue_match_type()
201 if (inst->id == id) in knav_queue_match_id_to_inst()
209 if (kdev->base_id <= id && in knav_queue_find_by_id()
210 kdev->base_id + kdev->num_queues > id) { in knav_queue_find_by_id()
211 id -= kdev->base_id; in knav_queue_find_by_id()
224 qh = devm_kzalloc(inst->kdev->dev, sizeof(*qh), GFP_KERNEL); in __knav_queue_open()
226 return ERR_PTR(-ENOMEM); in __knav_queue_open()
228 qh->stats = alloc_percpu(struct knav_queue_stats); in __knav_queue_open()
229 if (!qh->stats) { in __knav_queue_open()
230 ret = -ENOMEM; in __knav_queue_open()
234 qh->flags = flags; in __knav_queue_open()
235 qh->inst = inst; in __knav_queue_open()
236 id = inst->id - inst->qmgr->start_queue; in __knav_queue_open()
237 qh->reg_push = &inst->qmgr->reg_push[id]; in __knav_queue_open()
238 qh->reg_pop = &inst->qmgr->reg_pop[id]; in __knav_queue_open()
239 qh->reg_peek = &inst->qmgr->reg_peek[id]; in __knav_queue_open()
243 struct knav_range_info *range = inst->range; in __knav_queue_open() local
245 inst->name = kstrndup(name, KNAV_NAME_SIZE - 1, GFP_KERNEL); in __knav_queue_open()
246 if (range->ops && range->ops->open_queue) in __knav_queue_open()
247 ret = range->ops->open_queue(range, inst, flags); in __knav_queue_open()
252 list_add_tail_rcu(&qh->list, &inst->handles); in __knav_queue_open()
256 if (qh->stats) in __knav_queue_open()
257 free_percpu(qh->stats); in __knav_queue_open()
258 devm_kfree(inst->kdev->dev, qh); in __knav_queue_open()
270 qh = ERR_PTR(-ENODEV); in knav_queue_open_by_id()
275 qh = ERR_PTR(-EEXIST); in knav_queue_open_by_id()
279 qh = ERR_PTR(-EBUSY); in knav_queue_open_by_id()
296 struct knav_queue *qh = ERR_PTR(-EINVAL); in knav_queue_open_by_type()
319 struct knav_range_info *range = inst->range; in knav_queue_set_notify() local
321 if (range->ops && range->ops->set_notify) in knav_queue_set_notify()
322 range->ops->set_notify(range, inst, enabled); in knav_queue_set_notify()
327 struct knav_queue_inst *inst = qh->inst; in knav_queue_enable_notifier()
330 if (WARN_ON(!qh->notifier_fn)) in knav_queue_enable_notifier()
331 return -EINVAL; in knav_queue_enable_notifier()
334 first = (atomic_inc_return(&qh->notifier_enabled) == 1); in knav_queue_enable_notifier()
339 first = (atomic_inc_return(&inst->num_notifiers) == 1); in knav_queue_enable_notifier()
348 struct knav_queue_inst *inst = qh->inst; in knav_queue_disable_notifier()
351 last = (atomic_dec_return(&qh->notifier_enabled) == 0); in knav_queue_disable_notifier()
355 last = (atomic_dec_return(&inst->num_notifiers) == 0); in knav_queue_disable_notifier()
365 knav_queue_notify_fn old_fn = qh->notifier_fn; in knav_queue_set_notifier()
368 return -EINVAL; in knav_queue_set_notifier()
370 if (!(qh->inst->range->flags & (RANGE_HAS_ACCUMULATOR | RANGE_HAS_IRQ))) in knav_queue_set_notifier()
371 return -ENOTSUPP; in knav_queue_set_notifier()
373 if (!cfg->fn && old_fn) in knav_queue_set_notifier()
376 qh->notifier_fn = cfg->fn; in knav_queue_set_notifier()
377 qh->notifier_fn_arg = cfg->fn_arg; in knav_queue_set_notifier()
379 if (cfg->fn && !old_fn) in knav_queue_set_notifier()
385 static int knav_gp_set_notify(struct knav_range_info *range, in knav_gp_set_notify() argument
391 if (range->flags & RANGE_HAS_IRQ) { in knav_gp_set_notify()
392 queue = inst->id - range->queue_base; in knav_gp_set_notify()
394 enable_irq(range->irqs[queue].irq); in knav_gp_set_notify()
396 disable_irq_nosync(range->irqs[queue].irq); in knav_gp_set_notify()
401 static int knav_gp_open_queue(struct knav_range_info *range, in knav_gp_open_queue() argument
404 return knav_queue_setup_irq(range, inst); in knav_gp_open_queue()
407 static int knav_gp_close_queue(struct knav_range_info *range, in knav_gp_close_queue() argument
424 struct knav_queue_inst *inst = qh->inst; in knav_queue_get_count()
426 return readl_relaxed(&qh->reg_peek[0].entry_count) + in knav_queue_get_count()
427 atomic_read(&inst->desc_count); in knav_queue_get_count()
433 struct knav_device *kdev = inst->kdev; in knav_queue_debug_show_instance()
446 kdev->base_id + inst->id, inst->name); in knav_queue_debug_show_instance()
449 pushes += per_cpu_ptr(qh->stats, cpu)->pushes; in knav_queue_debug_show_instance()
450 pops += per_cpu_ptr(qh->stats, cpu)->pops; in knav_queue_debug_show_instance()
451 push_errors += per_cpu_ptr(qh->stats, cpu)->push_errors; in knav_queue_debug_show_instance()
452 pop_errors += per_cpu_ptr(qh->stats, cpu)->pop_errors; in knav_queue_debug_show_instance()
453 notifies += per_cpu_ptr(qh->stats, cpu)->notifies; in knav_queue_debug_show_instance()
473 seq_printf(s, "%s: %u-%u\n", in knav_queue_debug_show()
474 dev_name(kdev->dev), kdev->base_id, in knav_queue_debug_show()
475 kdev->base_id + kdev->num_queues - 1); in knav_queue_debug_show()
500 return val ? -ETIMEDOUT : 0; in knav_queue_pdsp_wait()
506 struct knav_queue_inst *inst = qh->inst; in knav_queue_flush()
507 unsigned id = inst->id - inst->qmgr->start_queue; in knav_queue_flush()
509 atomic_set(&inst->desc_count, 0); in knav_queue_flush()
510 writel_relaxed(0, &inst->qmgr->reg_push[id].ptr_size_thresh); in knav_queue_flush()
515 * knav_queue_open() - open a hardware queue
516 * @name: - name to give the queue handle
517 * @id: - desired queue number if any or specifes the type
519 * @flags: - the following flags are applicable to queues:
520 * KNAV_QUEUE_SHARED - allow the queue to be shared. Queues are
531 struct knav_queue *qh = ERR_PTR(-EINVAL); in knav_queue_open()
549 * knav_queue_close() - close a hardware queue handle
550 * @qhandle: - handle to close
555 struct knav_queue_inst *inst = qh->inst; in knav_queue_close()
557 while (atomic_read(&qh->notifier_enabled) > 0) in knav_queue_close()
561 list_del_rcu(&qh->list); in knav_queue_close()
565 struct knav_range_info *range = inst->range; in knav_queue_close() local
567 if (range->ops && range->ops->close_queue) in knav_queue_close()
568 range->ops->close_queue(range, inst); in knav_queue_close()
570 free_percpu(qh->stats); in knav_queue_close()
571 devm_kfree(inst->kdev->dev, qh); in knav_queue_close()
576 * knav_queue_device_control() - Perform control operations on a queue
577 * @qhandle: - queue handle
578 * @cmd: - control commands
579 * @arg: - command argument
592 ret = qh->inst->kdev->base_id + qh->inst->id; in knav_queue_device_control()
617 ret = -ENOTSUPP; in knav_queue_device_control()
627 * knav_queue_push() - push data (or descriptor) to the tail of a queue
628 * @qhandle: - hardware queue handle
629 * @dma: - DMA data to push
630 * @size: - size of data to push
631 * @flags: - can be used to pass additional information
641 val = (u32)dma | ((size / 16) - 1); in knav_queue_push()
642 writel_relaxed(val, &qh->reg_push[0].ptr_size_thresh); in knav_queue_push()
644 this_cpu_inc(qh->stats->pushes); in knav_queue_push()
650 * knav_queue_pop() - pop data (or descriptor) from the head of a queue
651 * @qhandle: - hardware queue handle
652 * @size: - (optional) size of the data pop'ed.
659 struct knav_queue_inst *inst = qh->inst; in knav_queue_pop()
664 if (inst->descs) { in knav_queue_pop()
665 if (unlikely(atomic_dec_return(&inst->desc_count) < 0)) { in knav_queue_pop()
666 atomic_inc(&inst->desc_count); in knav_queue_pop()
669 idx = atomic_inc_return(&inst->desc_head); in knav_queue_pop()
671 val = inst->descs[idx]; in knav_queue_pop()
673 val = readl_relaxed(&qh->reg_pop[0].ptr_size_thresh); in knav_queue_pop()
682 this_cpu_inc(qh->stats->pops); in knav_queue_pop()
693 region = pool->region; in kdesc_fill_pool()
694 pool->desc_size = region->desc_size; in kdesc_fill_pool()
695 for (i = 0; i < pool->num_desc; i++) { in kdesc_fill_pool()
696 int index = pool->region_offset + i; in kdesc_fill_pool()
699 dma_addr = region->dma_start + (region->desc_size * index); in kdesc_fill_pool()
700 dma_size = ALIGN(pool->desc_size, SMP_CACHE_BYTES); in kdesc_fill_pool()
701 dma_sync_single_for_device(pool->dev, dma_addr, dma_size, in kdesc_fill_pool()
703 knav_queue_push(pool->queue, dma_addr, dma_size, 0); in kdesc_fill_pool()
715 if (!pool->queue) in kdesc_empty_pool()
719 dma = knav_queue_pop(pool->queue, &size); in kdesc_empty_pool()
724 dev_dbg(pool->kdev->dev, in kdesc_empty_pool()
729 WARN_ON(i != pool->num_desc); in kdesc_empty_pool()
730 knav_queue_close(pool->queue); in kdesc_empty_pool()
738 return pool->region->dma_start + (virt - pool->region->virt_start); in knav_pool_desc_virt_to_dma()
745 return pool->region->virt_start + (dma - pool->region->dma_start); in knav_pool_desc_dma_to_virt()
750 * knav_pool_create() - Create a pool of descriptors
751 * @name: - name to give the pool handle
752 * @num_desc: - numbers of descriptors in the pool
753 * @region_id: - QMSS region id from which the descriptors are to be
769 return ERR_PTR(-EPROBE_DEFER); in knav_pool_create()
771 if (!kdev->dev) in knav_pool_create()
772 return ERR_PTR(-ENODEV); in knav_pool_create()
774 pool = devm_kzalloc(kdev->dev, sizeof(*pool), GFP_KERNEL); in knav_pool_create()
776 dev_err(kdev->dev, "out of memory allocating pool\n"); in knav_pool_create()
777 return ERR_PTR(-ENOMEM); in knav_pool_create()
781 if (reg_itr->id != region_id) in knav_pool_create()
788 dev_err(kdev->dev, "region-id(%d) not found\n", region_id); in knav_pool_create()
789 ret = -EINVAL; in knav_pool_create()
793 pool->queue = knav_queue_open(name, KNAV_QUEUE_GP, 0); in knav_pool_create()
794 if (IS_ERR(pool->queue)) { in knav_pool_create()
795 dev_err(kdev->dev, in knav_pool_create()
797 name, PTR_ERR(pool->queue)); in knav_pool_create()
798 ret = PTR_ERR(pool->queue); in knav_pool_create()
802 pool->name = kstrndup(name, KNAV_NAME_SIZE - 1, GFP_KERNEL); in knav_pool_create()
803 pool->kdev = kdev; in knav_pool_create()
804 pool->dev = kdev->dev; in knav_pool_create()
808 if (num_desc > (region->num_desc - region->used_desc)) { in knav_pool_create()
809 dev_err(kdev->dev, "out of descs in region(%d) for pool(%s)\n", in knav_pool_create()
811 ret = -ENOMEM; in knav_pool_create()
820 node = &region->pools; in knav_pool_create()
821 list_for_each_entry(iter, &region->pools, region_inst) { in knav_pool_create()
822 if ((iter->region_offset - last_offset) >= num_desc) { in knav_pool_create()
826 last_offset = iter->region_offset + iter->num_desc; in knav_pool_create()
830 node = &pi->region_inst; in knav_pool_create()
831 pool->region = region; in knav_pool_create()
832 pool->num_desc = num_desc; in knav_pool_create()
833 pool->region_offset = last_offset; in knav_pool_create()
834 region->used_desc += num_desc; in knav_pool_create()
835 list_add_tail(&pool->list, &kdev->pools); in knav_pool_create()
836 list_add_tail(&pool->region_inst, node); in knav_pool_create()
838 dev_err(kdev->dev, "pool(%s) create failed: fragmented desc pool in region(%d)\n", in knav_pool_create()
840 ret = -ENOMEM; in knav_pool_create()
851 kfree(pool->name); in knav_pool_create()
852 devm_kfree(kdev->dev, pool); in knav_pool_create()
858 * knav_pool_destroy() - Free a pool of descriptors
859 * @ph: - pool handle
868 if (!pool->region) in knav_pool_destroy()
874 pool->region->used_desc -= pool->num_desc; in knav_pool_destroy()
875 list_del(&pool->region_inst); in knav_pool_destroy()
876 list_del(&pool->list); in knav_pool_destroy()
879 kfree(pool->name); in knav_pool_destroy()
880 devm_kfree(kdev->dev, pool); in knav_pool_destroy()
886 * knav_pool_desc_get() - Get a descriptor from the pool
887 * @ph: - pool handle
898 dma = knav_queue_pop(pool->queue, &size); in knav_pool_desc_get()
900 return ERR_PTR(-ENOMEM); in knav_pool_desc_get()
907 * knav_pool_desc_put() - return a descriptor to the pool
908 * @ph: - pool handle
909 * @desc: - virtual address
916 knav_queue_push(pool->queue, dma, pool->region->desc_size, 0); in knav_pool_desc_put()
921 * knav_pool_desc_map() - Map descriptor for DMA transfer
922 * @ph: - pool handle
923 * @desc: - address of descriptor to map
924 * @size: - size of descriptor to map
925 * @dma: - DMA address return pointer
926 * @dma_sz: - adjusted return pointer
935 size = min(size, pool->region->desc_size); in knav_pool_desc_map()
938 dma_sync_single_for_device(pool->dev, *dma, size, DMA_TO_DEVICE); in knav_pool_desc_map()
948 * knav_pool_desc_unmap() - Unmap descriptor after DMA transfer
949 * @ph: - pool handle
950 * @dma: - DMA address of descriptor to unmap
951 * @dma_sz: - size of descriptor to unmap
962 desc_sz = min(dma_sz, pool->region->desc_size); in knav_pool_desc_unmap()
964 dma_sync_single_for_cpu(pool->dev, dma, desc_sz, DMA_FROM_DEVICE); in knav_pool_desc_unmap()
971 * knav_pool_count() - Get the number of descriptors in pool.
972 * @ph: - pool handle
978 return knav_queue_get_count(pool->queue); in knav_pool_count()
989 int id = region->id; in knav_queue_setup_region()
993 if (!region->num_desc) { in knav_queue_setup_region()
994 dev_warn(kdev->dev, "unused region %s\n", region->name); in knav_queue_setup_region()
999 hw_num_desc = ilog2(region->num_desc - 1) + 1; in knav_queue_setup_region()
1002 if (region->num_desc < 32) { in knav_queue_setup_region()
1003 region->num_desc = 0; in knav_queue_setup_region()
1004 dev_warn(kdev->dev, "too few descriptors in region %s\n", in knav_queue_setup_region()
1005 region->name); in knav_queue_setup_region()
1009 size = region->num_desc * region->desc_size; in knav_queue_setup_region()
1010 region->virt_start = alloc_pages_exact(size, GFP_KERNEL | GFP_DMA | in knav_queue_setup_region()
1012 if (!region->virt_start) { in knav_queue_setup_region()
1013 region->num_desc = 0; in knav_queue_setup_region()
1014 dev_err(kdev->dev, "memory alloc failed for region %s\n", in knav_queue_setup_region()
1015 region->name); in knav_queue_setup_region()
1018 region->virt_end = region->virt_start + size; in knav_queue_setup_region()
1019 page = virt_to_page(region->virt_start); in knav_queue_setup_region()
1021 region->dma_start = dma_map_page(kdev->dev, page, 0, size, in knav_queue_setup_region()
1023 if (dma_mapping_error(kdev->dev, region->dma_start)) { in knav_queue_setup_region()
1024 dev_err(kdev->dev, "dma map failed for region %s\n", in knav_queue_setup_region()
1025 region->name); in knav_queue_setup_region()
1028 region->dma_end = region->dma_start + size; in knav_queue_setup_region()
1030 pool = devm_kzalloc(kdev->dev, sizeof(*pool), GFP_KERNEL); in knav_queue_setup_region()
1032 dev_err(kdev->dev, "out of memory allocating dummy pool\n"); in knav_queue_setup_region()
1035 pool->num_desc = 0; in knav_queue_setup_region()
1036 pool->region_offset = region->num_desc; in knav_queue_setup_region()
1037 list_add(&pool->region_inst, &region->pools); in knav_queue_setup_region()
1039 dev_dbg(kdev->dev, in knav_queue_setup_region()
1040 "region %s (%d): size:%d, link:%d@%d, dma:%pad-%pad, virt:%p-%p\n", in knav_queue_setup_region()
1041 region->name, id, region->desc_size, region->num_desc, in knav_queue_setup_region()
1042 region->link_index, &region->dma_start, &region->dma_end, in knav_queue_setup_region()
1043 region->virt_start, region->virt_end); in knav_queue_setup_region()
1045 hw_desc_size = (region->desc_size / 16) - 1; in knav_queue_setup_region()
1046 hw_num_desc -= 5; in knav_queue_setup_region()
1049 regs = qmgr->reg_region + id; in knav_queue_setup_region()
1050 writel_relaxed((u32)region->dma_start, &regs->base); in knav_queue_setup_region()
1051 writel_relaxed(region->link_index, &regs->start_index); in knav_queue_setup_region()
1053 &regs->size_count); in knav_queue_setup_region()
1058 if (region->dma_start) in knav_queue_setup_region()
1059 dma_unmap_page(kdev->dev, region->dma_start, size, in knav_queue_setup_region()
1061 if (region->virt_start) in knav_queue_setup_region()
1062 free_pages_exact(region->virt_start, size); in knav_queue_setup_region()
1063 region->num_desc = 0; in knav_queue_setup_region()
1072 name = node->name; in knav_queue_find_name()
1081 struct device *dev = kdev->dev; in knav_queue_setup_regions()
1083 of_get_child_by_name(node, "descriptor-regions"); in knav_queue_setup_regions()
1090 return dev_err_probe(dev, -ENODEV, in knav_queue_setup_regions()
1091 "descriptor-regions not specified\n"); in knav_queue_setup_regions()
1098 return -ENOMEM; in knav_queue_setup_regions()
1101 region->name = knav_queue_find_name(child); in knav_queue_setup_regions()
1102 of_property_read_u32(child, "id", &region->id); in knav_queue_setup_regions()
1103 ret = of_property_read_u32_array(child, "region-spec", temp, 2); in knav_queue_setup_regions()
1105 region->num_desc = temp[0]; in knav_queue_setup_regions()
1106 region->desc_size = temp[1]; in knav_queue_setup_regions()
1108 dev_err(dev, "invalid region info %s\n", region->name); in knav_queue_setup_regions()
1113 ret = of_property_read_u32(child, "link-index", in knav_queue_setup_regions()
1114 &region->link_index); in knav_queue_setup_regions()
1117 region->name); in knav_queue_setup_regions()
1122 INIT_LIST_HEAD(&region->pools); in knav_queue_setup_regions()
1123 list_add_tail(&region->list, &kdev->regions); in knav_queue_setup_regions()
1125 if (list_empty(&kdev->regions)) in knav_queue_setup_regions()
1126 return dev_err_probe(dev, -ENODEV, in knav_queue_setup_regions()
1140 struct platform_device *pdev = to_platform_device(kdev->dev); in knav_get_link_ram()
1141 struct device_node *node = pdev->dev.of_node; in knav_get_link_ram()
1147 * 64-bit entities here. in knav_get_link_ram()
1149 * For example, to specify the internal link ram for Keystone-I class in knav_get_link_ram()
1150 * devices, we would set the linkram0 resource to 0x80000-0x83fff. in knav_get_link_ram()
1153 * if the range specified is 0x0c000000-0x0c003fff (i.e., 16K entries in knav_get_link_ram()
1154 * in MSMC SRAM), the actual memory used is 0x0c000000-0x0c020000, in knav_get_link_ram()
1155 * which accounts for 64-bits per entry, for 16K entries. in knav_get_link_ram()
1161 * link ram WARNING - we do not "reserve" this block in knav_get_link_ram()
1163 block->dma = (dma_addr_t)temp[0]; in knav_get_link_ram()
1164 block->virt = NULL; in knav_get_link_ram()
1165 block->size = temp[1]; in knav_get_link_ram()
1167 block->size = temp[1]; in knav_get_link_ram()
1169 block->virt = dmam_alloc_coherent(kdev->dev, in knav_get_link_ram()
1170 8 * block->size, &block->dma, in knav_get_link_ram()
1172 if (!block->virt) { in knav_get_link_ram()
1173 dev_err(kdev->dev, "failed to alloc linkram\n"); in knav_get_link_ram()
1174 return -ENOMEM; in knav_get_link_ram()
1178 return -ENODEV; in knav_get_link_ram()
1189 block = &kdev->link_rams[0]; in knav_queue_setup_link_ram()
1190 dev_dbg(kdev->dev, "linkram0: dma:%pad, virt:%p, size:%x\n", in knav_queue_setup_link_ram()
1191 &block->dma, block->virt, block->size); in knav_queue_setup_link_ram()
1192 writel_relaxed((u32)block->dma, &qmgr->reg_config->link_ram_base0); in knav_queue_setup_link_ram()
1193 if (kdev->version == QMSS_66AK2G) in knav_queue_setup_link_ram()
1194 writel_relaxed(block->size, in knav_queue_setup_link_ram()
1195 &qmgr->reg_config->link_ram_size0); in knav_queue_setup_link_ram()
1197 writel_relaxed(block->size - 1, in knav_queue_setup_link_ram()
1198 &qmgr->reg_config->link_ram_size0); in knav_queue_setup_link_ram()
1200 if (!block->size) in knav_queue_setup_link_ram()
1203 dev_dbg(kdev->dev, "linkram1: dma:%pad, virt:%p, size:%x\n", in knav_queue_setup_link_ram()
1204 &block->dma, block->virt, block->size); in knav_queue_setup_link_ram()
1205 writel_relaxed(block->dma, &qmgr->reg_config->link_ram_base1); in knav_queue_setup_link_ram()
1214 struct device *dev = kdev->dev; in knav_setup_queue_range()
1215 struct knav_range_info *range; in knav_setup_queue_range() local
1220 range = devm_kzalloc(dev, sizeof(*range), GFP_KERNEL); in knav_setup_queue_range()
1221 if (!range) { in knav_setup_queue_range()
1222 dev_err(dev, "out of memory allocating range\n"); in knav_setup_queue_range()
1223 return -ENOMEM; in knav_setup_queue_range()
1226 range->kdev = kdev; in knav_setup_queue_range()
1227 range->name = knav_queue_find_name(node); in knav_setup_queue_range()
1230 range->queue_base = temp[0] - kdev->base_id; in knav_setup_queue_range()
1231 range->num_queues = temp[1]; in knav_setup_queue_range()
1233 dev_err(dev, "invalid queue range %s\n", range->name); in knav_setup_queue_range()
1234 devm_kfree(dev, range); in knav_setup_queue_range()
1235 return -EINVAL; in knav_setup_queue_range()
1244 range->irqs[i].irq = irq_create_of_mapping(&oirq); in knav_setup_queue_range()
1245 if (range->irqs[i].irq == IRQ_NONE) in knav_setup_queue_range()
1248 range->num_irqs++; in knav_setup_queue_range()
1254 range->irqs[i].cpu_mask = devm_kzalloc(dev, in knav_setup_queue_range()
1256 if (!range->irqs[i].cpu_mask) in knav_setup_queue_range()
1257 return -ENOMEM; in knav_setup_queue_range()
1261 cpumask_set_cpu(bit, range->irqs[i].cpu_mask); in knav_setup_queue_range()
1265 range->num_irqs = min(range->num_irqs, range->num_queues); in knav_setup_queue_range()
1266 if (range->num_irqs) in knav_setup_queue_range()
1267 range->flags |= RANGE_HAS_IRQ; in knav_setup_queue_range()
1269 if (of_property_read_bool(node, "qalloc-by-id")) in knav_setup_queue_range()
1270 range->flags |= RANGE_RESERVED; in knav_setup_queue_range()
1273 ret = knav_init_acc_range(kdev, node, range); in knav_setup_queue_range()
1275 devm_kfree(dev, range); in knav_setup_queue_range()
1279 range->ops = &knav_gp_range_ops; in knav_setup_queue_range()
1284 start = max(qmgr->start_queue, range->queue_base); in knav_setup_queue_range()
1285 end = min(qmgr->start_queue + qmgr->num_queues, in knav_setup_queue_range()
1286 range->queue_base + range->num_queues); in knav_setup_queue_range()
1288 index = id - qmgr->start_queue; in knav_setup_queue_range()
1290 &qmgr->reg_peek[index].ptr_size_thresh); in knav_setup_queue_range()
1292 &qmgr->reg_push[index].ptr_size_thresh); in knav_setup_queue_range()
1296 list_add_tail(&range->list, &kdev->queue_ranges); in knav_setup_queue_range()
1297 dev_dbg(dev, "added range %s: %d-%d, %d irqs%s%s%s\n", in knav_setup_queue_range()
1298 range->name, range->queue_base, in knav_setup_queue_range()
1299 range->queue_base + range->num_queues - 1, in knav_setup_queue_range()
1300 range->num_irqs, in knav_setup_queue_range()
1301 (range->flags & RANGE_HAS_IRQ) ? ", has irq" : "", in knav_setup_queue_range()
1302 (range->flags & RANGE_RESERVED) ? ", reserved" : "", in knav_setup_queue_range()
1303 (range->flags & RANGE_HAS_ACCUMULATOR) ? ", acc" : ""); in knav_setup_queue_range()
1304 kdev->num_queues_in_use += range->num_queues; in knav_setup_queue_range()
1312 of_get_child_by_name(node, "queue-pools"); in knav_setup_queue_pools()
1313 struct device_node *type, *range; in knav_setup_queue_pools() local
1316 return dev_err_probe(kdev->dev, -ENODEV, in knav_setup_queue_pools()
1317 "queue-pools not specified\n"); in knav_setup_queue_pools()
1320 for_each_child_of_node(type, range) { in knav_setup_queue_pools()
1322 knav_setup_queue_range(kdev, range); in knav_setup_queue_pools()
1327 if (list_empty(&kdev->queue_ranges)) in knav_setup_queue_pools()
1328 return dev_err_probe(kdev->dev, -ENODEV, in knav_setup_queue_pools()
1329 "no valid queue range found\n"); in knav_setup_queue_pools()
1334 struct knav_range_info *range) in knav_free_queue_range() argument
1336 if (range->ops && range->ops->free_range) in knav_free_queue_range()
1337 range->ops->free_range(range); in knav_free_queue_range()
1338 list_del(&range->list); in knav_free_queue_range()
1339 devm_kfree(kdev->dev, range); in knav_free_queue_range()
1344 struct knav_range_info *range; in knav_free_queue_ranges() local
1347 range = first_queue_range(kdev); in knav_free_queue_ranges()
1348 if (!range) in knav_free_queue_ranges()
1350 knav_free_queue_range(kdev, range); in knav_free_queue_ranges()
1364 list_for_each_entry_safe(pool, tmp, &region->pools, region_inst) in knav_queue_free_regions()
1367 size = region->virt_end - region->virt_start; in knav_queue_free_regions()
1369 free_pages_exact(region->virt_start, size); in knav_queue_free_regions()
1370 list_del(&region->list); in knav_queue_free_regions()
1371 devm_kfree(kdev->dev, region); in knav_queue_free_regions()
1384 dev_err(kdev->dev, "Can't translate of node(%pOFn) address for index(%d)\n", in knav_queue_map_reg()
1389 regs = devm_ioremap_resource(kdev->dev, &res); in knav_queue_map_reg()
1391 dev_err(kdev->dev, "Failed to map register base for index(%d) node(%pOFn)\n", in knav_queue_map_reg()
1399 struct device *dev = kdev->dev; in knav_queue_init_qmgrs()
1408 return dev_err_probe(dev, -ENODEV, in knav_queue_init_qmgrs()
1416 return -ENOMEM; in knav_queue_init_qmgrs()
1419 ret = of_property_read_u32_array(child, "managed-queues", in knav_queue_init_qmgrs()
1422 qmgr->start_queue = temp[0]; in knav_queue_init_qmgrs()
1423 qmgr->num_queues = temp[1]; in knav_queue_init_qmgrs()
1425 dev_err(dev, "invalid qmgr queue range\n"); in knav_queue_init_qmgrs()
1431 qmgr->start_queue, qmgr->num_queues); in knav_queue_init_qmgrs()
1433 qmgr->reg_peek = in knav_queue_init_qmgrs()
1437 if (kdev->version == QMSS) { in knav_queue_init_qmgrs()
1438 qmgr->reg_status = in knav_queue_init_qmgrs()
1443 qmgr->reg_config = in knav_queue_init_qmgrs()
1445 (kdev->version == QMSS_66AK2G) ? in knav_queue_init_qmgrs()
1448 qmgr->reg_region = in knav_queue_init_qmgrs()
1450 (kdev->version == QMSS_66AK2G) ? in knav_queue_init_qmgrs()
1454 qmgr->reg_push = in knav_queue_init_qmgrs()
1456 (kdev->version == QMSS_66AK2G) ? in knav_queue_init_qmgrs()
1460 if (kdev->version == QMSS) { in knav_queue_init_qmgrs()
1461 qmgr->reg_pop = in knav_queue_init_qmgrs()
1466 if (IS_ERR(qmgr->reg_peek) || in knav_queue_init_qmgrs()
1467 ((kdev->version == QMSS) && in knav_queue_init_qmgrs()
1468 (IS_ERR(qmgr->reg_status) || IS_ERR(qmgr->reg_pop))) || in knav_queue_init_qmgrs()
1469 IS_ERR(qmgr->reg_config) || IS_ERR(qmgr->reg_region) || in knav_queue_init_qmgrs()
1470 IS_ERR(qmgr->reg_push)) { in knav_queue_init_qmgrs()
1471 dev_err(dev, "failed to map qmgr regs\n"); in knav_queue_init_qmgrs()
1472 if (kdev->version == QMSS) { in knav_queue_init_qmgrs()
1473 if (!IS_ERR(qmgr->reg_status)) in knav_queue_init_qmgrs()
1474 devm_iounmap(dev, qmgr->reg_status); in knav_queue_init_qmgrs()
1475 if (!IS_ERR(qmgr->reg_pop)) in knav_queue_init_qmgrs()
1476 devm_iounmap(dev, qmgr->reg_pop); in knav_queue_init_qmgrs()
1478 if (!IS_ERR(qmgr->reg_peek)) in knav_queue_init_qmgrs()
1479 devm_iounmap(dev, qmgr->reg_peek); in knav_queue_init_qmgrs()
1480 if (!IS_ERR(qmgr->reg_config)) in knav_queue_init_qmgrs()
1481 devm_iounmap(dev, qmgr->reg_config); in knav_queue_init_qmgrs()
1482 if (!IS_ERR(qmgr->reg_region)) in knav_queue_init_qmgrs()
1483 devm_iounmap(dev, qmgr->reg_region); in knav_queue_init_qmgrs()
1484 if (!IS_ERR(qmgr->reg_push)) in knav_queue_init_qmgrs()
1485 devm_iounmap(dev, qmgr->reg_push); in knav_queue_init_qmgrs()
1491 if (kdev->version == QMSS_66AK2G) in knav_queue_init_qmgrs()
1492 qmgr->reg_pop = qmgr->reg_push; in knav_queue_init_qmgrs()
1494 list_add_tail(&qmgr->list, &kdev->qmgrs); in knav_queue_init_qmgrs()
1496 qmgr->start_queue, qmgr->num_queues, in knav_queue_init_qmgrs()
1497 qmgr->reg_peek, qmgr->reg_status, in knav_queue_init_qmgrs()
1498 qmgr->reg_config, qmgr->reg_region, in knav_queue_init_qmgrs()
1499 qmgr->reg_push, qmgr->reg_pop); in knav_queue_init_qmgrs()
1507 struct device *dev = kdev->dev; in knav_queue_init_pdsps()
1516 return -ENOMEM; in knav_queue_init_pdsps()
1518 pdsp->name = knav_queue_find_name(child); in knav_queue_init_pdsps()
1519 pdsp->iram = in knav_queue_init_pdsps()
1522 pdsp->regs = in knav_queue_init_pdsps()
1525 pdsp->intd = in knav_queue_init_pdsps()
1528 pdsp->command = in knav_queue_init_pdsps()
1532 if (IS_ERR(pdsp->command) || IS_ERR(pdsp->iram) || in knav_queue_init_pdsps()
1533 IS_ERR(pdsp->regs) || IS_ERR(pdsp->intd)) { in knav_queue_init_pdsps()
1534 dev_err(dev, "failed to map pdsp %s regs\n", in knav_queue_init_pdsps()
1535 pdsp->name); in knav_queue_init_pdsps()
1536 if (!IS_ERR(pdsp->command)) in knav_queue_init_pdsps()
1537 devm_iounmap(dev, pdsp->command); in knav_queue_init_pdsps()
1538 if (!IS_ERR(pdsp->iram)) in knav_queue_init_pdsps()
1539 devm_iounmap(dev, pdsp->iram); in knav_queue_init_pdsps()
1540 if (!IS_ERR(pdsp->regs)) in knav_queue_init_pdsps()
1541 devm_iounmap(dev, pdsp->regs); in knav_queue_init_pdsps()
1542 if (!IS_ERR(pdsp->intd)) in knav_queue_init_pdsps()
1543 devm_iounmap(dev, pdsp->intd); in knav_queue_init_pdsps()
1547 of_property_read_u32(child, "id", &pdsp->id); in knav_queue_init_pdsps()
1548 list_add_tail(&pdsp->list, &kdev->pdsps); in knav_queue_init_pdsps()
1550 pdsp->name, pdsp->command, pdsp->iram, pdsp->regs, in knav_queue_init_pdsps()
1551 pdsp->intd); in knav_queue_init_pdsps()
1562 val = readl_relaxed(&pdsp->regs->control) & ~PDSP_CTRL_ENABLE; in knav_queue_stop_pdsp()
1563 writel_relaxed(val, &pdsp->regs->control); in knav_queue_stop_pdsp()
1564 ret = knav_queue_pdsp_wait(&pdsp->regs->control, timeout, in knav_queue_stop_pdsp()
1567 dev_err(kdev->dev, "timed out on pdsp %s stop\n", pdsp->name); in knav_queue_stop_pdsp()
1570 pdsp->loaded = false; in knav_queue_stop_pdsp()
1571 pdsp->started = false; in knav_queue_stop_pdsp()
1587 kdev->dev); in knav_queue_load_pdsp()
1596 dev_err(kdev->dev, "failed to get firmware for pdsp\n"); in knav_queue_load_pdsp()
1597 return -ENODEV; in knav_queue_load_pdsp()
1600 dev_info(kdev->dev, "firmware file %s downloaded for PDSP\n", in knav_queue_load_pdsp()
1603 writel_relaxed(pdsp->id + 1, pdsp->command + 0x18); in knav_queue_load_pdsp()
1605 fwdata = (u32 *)fw->data; in knav_queue_load_pdsp()
1606 fwlen = (fw->size + sizeof(u32) - 1) / sizeof(u32); in knav_queue_load_pdsp()
1608 writel_relaxed(be32_to_cpu(fwdata[i]), pdsp->iram + i); in knav_queue_load_pdsp()
1621 writel_relaxed(0xffffffff, pdsp->command); in knav_queue_start_pdsp()
1622 while (readl_relaxed(pdsp->command) != 0xffffffff) in knav_queue_start_pdsp()
1626 val = readl_relaxed(&pdsp->regs->control); in knav_queue_start_pdsp()
1628 writel_relaxed(val, &pdsp->regs->control); in knav_queue_start_pdsp()
1631 val = readl_relaxed(&pdsp->regs->control) | PDSP_CTRL_ENABLE; in knav_queue_start_pdsp()
1632 writel_relaxed(val, &pdsp->regs->control); in knav_queue_start_pdsp()
1635 ret = knav_queue_pdsp_wait(pdsp->command, timeout, 0); in knav_queue_start_pdsp()
1637 dev_err(kdev->dev, in knav_queue_start_pdsp()
1639 pdsp->name); in knav_queue_start_pdsp()
1663 * and stated flag and when initialize the acc range, check in knav_queue_start_pdsps()
1664 * it and init the range only if pdsp is started. in knav_queue_start_pdsps()
1669 pdsp->loaded = true; in knav_queue_start_pdsps()
1673 if (pdsp->loaded) { in knav_queue_start_pdsps()
1676 pdsp->started = true; in knav_queue_start_pdsps()
1707 if ((id >= qmgr->start_queue) && in knav_find_qmgr()
1708 (id < qmgr->start_queue + qmgr->num_queues)) in knav_find_qmgr()
1715 struct knav_range_info *range, in knav_queue_init_queue() argument
1720 inst->qmgr = knav_find_qmgr(id); in knav_queue_init_queue()
1721 if (!inst->qmgr) in knav_queue_init_queue()
1722 return -1; in knav_queue_init_queue()
1724 INIT_LIST_HEAD(&inst->handles); in knav_queue_init_queue()
1725 inst->kdev = kdev; in knav_queue_init_queue()
1726 inst->range = range; in knav_queue_init_queue()
1727 inst->irq_num = -1; in knav_queue_init_queue()
1728 inst->id = id; in knav_queue_init_queue()
1729 scnprintf(irq_name, sizeof(irq_name), "hwqueue-%d", id); in knav_queue_init_queue()
1730 inst->irq_name = kstrndup(irq_name, sizeof(irq_name), GFP_KERNEL); in knav_queue_init_queue()
1732 if (range->ops && range->ops->init_queue) in knav_queue_init_queue()
1733 return range->ops->init_queue(range, inst); in knav_queue_init_queue()
1740 struct knav_range_info *range; in knav_queue_init_queues() local
1750 kdev->inst_shift = order_base_2(size); in knav_queue_init_queues()
1751 size = (1 << kdev->inst_shift) * kdev->num_queues_in_use; in knav_queue_init_queues()
1752 kdev->instances = devm_kzalloc(kdev->dev, size, GFP_KERNEL); in knav_queue_init_queues()
1753 if (!kdev->instances) in knav_queue_init_queues()
1754 return -ENOMEM; in knav_queue_init_queues()
1756 for_each_queue_range(kdev, range) { in knav_queue_init_queues()
1757 if (range->ops && range->ops->init_range) in knav_queue_init_queues()
1758 range->ops->init_range(range); in knav_queue_init_queues()
1760 for (id = range->queue_base; in knav_queue_init_queues()
1761 id < range->queue_base + range->num_queues; id++, idx++) { in knav_queue_init_queues()
1762 ret = knav_queue_init_queue(kdev, range, in knav_queue_init_queues()
1767 range->queue_base_inst = in knav_queue_init_queues()
1776 .compatible = "ti,keystone-navigator-qmss",
1779 .compatible = "ti,66ak2g-navss-qm",
1788 struct device_node *node = pdev->dev.of_node; in knav_queue_probe()
1789 struct device *dev = &pdev->dev; in knav_queue_probe()
1795 return -ENODEV; in knav_queue_probe()
1801 return -ENOMEM; in knav_queue_probe()
1805 kdev->version = QMSS_66AK2G; in knav_queue_probe()
1808 kdev->dev = dev; in knav_queue_probe()
1809 INIT_LIST_HEAD(&kdev->queue_ranges); in knav_queue_probe()
1810 INIT_LIST_HEAD(&kdev->qmgrs); in knav_queue_probe()
1811 INIT_LIST_HEAD(&kdev->pools); in knav_queue_probe()
1812 INIT_LIST_HEAD(&kdev->regions); in knav_queue_probe()
1813 INIT_LIST_HEAD(&kdev->pdsps); in knav_queue_probe()
1815 pm_runtime_enable(&pdev->dev); in knav_queue_probe()
1816 ret = pm_runtime_resume_and_get(&pdev->dev); in knav_queue_probe()
1818 pm_runtime_disable(&pdev->dev); in knav_queue_probe()
1823 if (of_property_read_u32_array(node, "queue-range", temp, 2)) { in knav_queue_probe()
1824 dev_err(dev, "queue-range not specified\n"); in knav_queue_probe()
1825 ret = -ENODEV; in knav_queue_probe()
1828 kdev->base_id = temp[0]; in knav_queue_probe()
1829 kdev->num_queues = temp[1]; in knav_queue_probe()
1841 /* get usable queue range values from device tree */ in knav_queue_probe()
1846 ret = knav_get_link_ram(kdev, "linkram0", &kdev->link_rams[0]); in knav_queue_probe()
1848 dev_err(kdev->dev, "could not setup linking ram\n"); in knav_queue_probe()
1852 ret = knav_get_link_ram(kdev, "linkram1", &kdev->link_rams[1]); in knav_queue_probe()
1883 pm_runtime_put_sync(&pdev->dev); in knav_queue_probe()
1884 pm_runtime_disable(&pdev->dev); in knav_queue_probe()
1891 pm_runtime_put_sync(&pdev->dev); in knav_queue_remove()
1892 pm_runtime_disable(&pdev->dev); in knav_queue_remove()
1899 .name = "keystone-navigator-qmss",