Lines Matching +full:irqs +full:- +full:map +full:- +full:range
1 // SPDX-License-Identifier: GPL-2.0
5 * Copyright (C) 2018-2019 Texas Instruments Incorporated - https://www.ti.com/
24 #include <asm-generic/msi.h>
44 * struct ti_sci_inta_event_desc - Description of an event coming to
59 * struct ti_sci_inta_vint_desc - Description of a virtual interrupt coming out
78 * struct ti_sci_inta_irq_domain - Structure representing a TISCI based
87 * @ti_sci_id: TI-SCI device identifier
89 * @unmapped_dev_ids: Pointer to an array of TI-SCI device identifiers of
91 * Unmapped Events are not part of the Global Event Map and
95 * generating Unmapped Event, we must use the INTA's TI-SCI
123 if (inta->unmapped_cnt == 0) in ti_sci_inta_get_dev_id()
127 * For devices sending Unmapped Events we must use the INTA's TI-SCI in ti_sci_inta_get_dev_id()
129 * and map it to an interrupt. in ti_sci_inta_get_dev_id()
131 for (i = 0; i < inta->unmapped_cnt; i++) { in ti_sci_inta_get_dev_id()
132 if (dev_id == inta->unmapped_dev_ids[i]) { in ti_sci_inta_get_dev_id()
133 dev_id = inta->ti_sci_id; in ti_sci_inta_get_dev_id()
142 * ti_sci_inta_irq_handler() - Chained IRQ handler for the vint irqs
154 domain = vint_desc->domain; in ti_sci_inta_irq_handler()
155 inta = domain->host_data; in ti_sci_inta_irq_handler()
159 val = readq_relaxed(inta->base + vint_desc->vint_id * 0x1000 + in ti_sci_inta_irq_handler()
163 generic_handle_domain_irq(domain, vint_desc->events[bit].hwirq); in ti_sci_inta_irq_handler()
169 * ti_sci_inta_xlate_irq() - Translate hwirq to parent's hwirq.
173 * Return parent irq number if translation is available else -ENOENT.
178 struct device_node *np = dev_of_node(&inta->pdev->dev); in ti_sci_inta_xlate_irq()
180 const __be32 *range; in ti_sci_inta_xlate_irq() local
183 range = of_get_property(np, "ti,interrupt-ranges", &len); in ti_sci_inta_xlate_irq()
184 if (!range) in ti_sci_inta_xlate_irq()
187 for (len /= sizeof(*range); len >= 3; len -= 3) { in ti_sci_inta_xlate_irq()
188 base = be32_to_cpu(*range++); in ti_sci_inta_xlate_irq()
189 parent_base = be32_to_cpu(*range++); in ti_sci_inta_xlate_irq()
190 size = be32_to_cpu(*range++); in ti_sci_inta_xlate_irq()
193 return vint_id - base + parent_base; in ti_sci_inta_xlate_irq()
196 return -ENOENT; in ti_sci_inta_xlate_irq()
200 * ti_sci_inta_alloc_parent_irq() - Allocate parent irq to Interrupt aggregator
207 struct ti_sci_inta_irq_domain *inta = domain->host_data; in ti_sci_inta_alloc_parent_irq()
215 vint_id = ti_sci_get_free_resource(inta->vint); in ti_sci_inta_alloc_parent_irq()
217 return ERR_PTR(-EINVAL); in ti_sci_inta_alloc_parent_irq()
227 ret = -ENOMEM; in ti_sci_inta_alloc_parent_irq()
231 vint_desc->domain = domain; in ti_sci_inta_alloc_parent_irq()
232 vint_desc->vint_id = vint_id; in ti_sci_inta_alloc_parent_irq()
233 INIT_LIST_HEAD(&vint_desc->list); in ti_sci_inta_alloc_parent_irq()
235 parent_node = of_irq_find_parent(dev_of_node(&inta->pdev->dev)); in ti_sci_inta_alloc_parent_irq()
238 if (of_device_is_compatible(parent_node, "arm,gic-v3")) { in ti_sci_inta_alloc_parent_irq()
242 parent_fwspec.param[1] = p_hwirq - 32; in ti_sci_inta_alloc_parent_irq()
252 dev_err(&inta->pdev->dev, "Parent IRQ allocation failed\n"); in ti_sci_inta_alloc_parent_irq()
253 ret = -EINVAL; in ti_sci_inta_alloc_parent_irq()
257 vint_desc->parent_virq = parent_virq; in ti_sci_inta_alloc_parent_irq()
259 list_add_tail(&vint_desc->list, &inta->vint_list); in ti_sci_inta_alloc_parent_irq()
260 irq_set_chained_handler_and_data(vint_desc->parent_virq, in ti_sci_inta_alloc_parent_irq()
267 ti_sci_release_resource(inta->vint, vint_id); in ti_sci_inta_alloc_parent_irq()
272 * ti_sci_inta_alloc_event() - Attach an event to a IA vint.
283 struct ti_sci_inta_irq_domain *inta = vint_desc->domain->host_data; in ti_sci_inta_alloc_event()
291 event_desc = &vint_desc->events[free_bit]; in ti_sci_inta_alloc_event()
292 event_desc->hwirq = hwirq; in ti_sci_inta_alloc_event()
293 event_desc->vint_bit = free_bit; in ti_sci_inta_alloc_event()
294 event_desc->global_event = ti_sci_get_free_resource(inta->global_event); in ti_sci_inta_alloc_event()
295 if (event_desc->global_event == TI_SCI_RESOURCE_NULL) in ti_sci_inta_alloc_event()
296 return ERR_PTR(-EINVAL); in ti_sci_inta_alloc_event()
298 err = inta->sci->ops.rm_irq_ops.set_event_map(inta->sci, in ti_sci_inta_alloc_event()
300 inta->ti_sci_id, in ti_sci_inta_alloc_event()
301 vint_desc->vint_id, in ti_sci_inta_alloc_event()
302 event_desc->global_event, in ti_sci_inta_alloc_event()
309 ti_sci_release_resource(inta->global_event, event_desc->global_event); in ti_sci_inta_alloc_event()
314 * ti_sci_inta_alloc_irq() - Allocate an irq within INTA domain
319 * - Find a free bit available in any of the vints available in the list.
320 * - If not found, allocate a vint from the vint pool
321 * - Attach the free bit to input hwirq.
327 struct ti_sci_inta_irq_domain *inta = domain->host_data; in ti_sci_inta_alloc_irq()
332 mutex_lock(&inta->vint_mutex); in ti_sci_inta_alloc_irq()
333 list_for_each_entry(vint_desc, &inta->vint_list, list) { in ti_sci_inta_alloc_irq()
334 free_bit = find_first_zero_bit(vint_desc->event_map, in ti_sci_inta_alloc_irq()
337 set_bit(free_bit, vint_desc->event_map); in ti_sci_inta_alloc_irq()
349 free_bit = find_first_zero_bit(vint_desc->event_map, in ti_sci_inta_alloc_irq()
351 set_bit(free_bit, vint_desc->event_map); in ti_sci_inta_alloc_irq()
356 clear_bit(free_bit, vint_desc->event_map); in ti_sci_inta_alloc_irq()
359 mutex_unlock(&inta->vint_mutex); in ti_sci_inta_alloc_irq()
364 * ti_sci_inta_free_parent_irq() - Free a parent irq to INTA
371 if (find_first_bit(vint_desc->event_map, MAX_EVENTS_PER_VINT) == MAX_EVENTS_PER_VINT) { in ti_sci_inta_free_parent_irq()
372 list_del(&vint_desc->list); in ti_sci_inta_free_parent_irq()
373 ti_sci_release_resource(inta->vint, vint_desc->vint_id); in ti_sci_inta_free_parent_irq()
374 irq_dispose_mapping(vint_desc->parent_virq); in ti_sci_inta_free_parent_irq()
380 * ti_sci_inta_free_irq() - Free an IRQ within INTA domain
391 vint_desc = to_vint_desc(event_desc, event_desc->vint_bit); in ti_sci_inta_free_irq()
392 inta = vint_desc->domain->host_data; in ti_sci_inta_free_irq()
395 mutex_lock(&inta->vint_mutex); in ti_sci_inta_free_irq()
396 inta->sci->ops.rm_irq_ops.free_event_map(inta->sci, in ti_sci_inta_free_irq()
398 inta->ti_sci_id, in ti_sci_inta_free_irq()
399 vint_desc->vint_id, in ti_sci_inta_free_irq()
400 event_desc->global_event, in ti_sci_inta_free_irq()
401 event_desc->vint_bit); in ti_sci_inta_free_irq()
403 clear_bit(event_desc->vint_bit, vint_desc->event_map); in ti_sci_inta_free_irq()
404 ti_sci_release_resource(inta->global_event, event_desc->global_event); in ti_sci_inta_free_irq()
405 event_desc->global_event = TI_SCI_RESOURCE_NULL; in ti_sci_inta_free_irq()
406 event_desc->hwirq = 0; in ti_sci_inta_free_irq()
409 mutex_unlock(&inta->vint_mutex); in ti_sci_inta_free_irq()
413 * ti_sci_inta_request_resources() - Allocate resources for input irq
427 event_desc = ti_sci_inta_alloc_irq(data->domain, data->hwirq); in ti_sci_inta_request_resources()
431 data->chip_data = event_desc; in ti_sci_inta_request_resources()
437 * ti_sci_inta_release_resources - Release resources for input irq
441 * of parent vint irqs happens in this api.
448 ti_sci_inta_free_irq(event_desc, data->hwirq); in ti_sci_inta_release_resources()
452 * ti_sci_inta_manage_event() - Control the event based on the offset
463 vint_desc = to_vint_desc(event_desc, event_desc->vint_bit); in ti_sci_inta_manage_event()
464 inta = data->domain->host_data; in ti_sci_inta_manage_event()
466 writeq_relaxed(BIT(event_desc->vint_bit), in ti_sci_inta_manage_event()
467 inta->base + vint_desc->vint_id * 0x1000 + offset); in ti_sci_inta_manage_event()
471 * ti_sci_inta_mask_irq() - Mask an event
480 * ti_sci_inta_unmask_irq() - Unmask an event
489 * ti_sci_inta_ack_irq() - Ack an event
505 return -EINVAL; in ti_sci_inta_set_affinity()
509 * ti_sci_inta_set_type() - Update the trigger type of the irq.
530 return -EINVAL; in ti_sci_inta_set_type()
546 * ti_sci_inta_irq_domain_free() - Free an IRQ from the IRQ domain
547 * @domain: Domain to which the irqs belong
549 * @nr_irqs: Number of continuous irqs to be freed
560 * ti_sci_inta_irq_domain_alloc() - Allocate Interrupt aggregator IRQs
563 * @nr_irqs: Continuous irqs to be allocated
576 irq_domain_set_info(domain, virq, arg->hwirq, &ti_sci_inta_irq_chip, in ti_sci_inta_irq_domain_alloc()
588 .name = "MSI-INTA",
595 struct platform_device *pdev = to_platform_device(desc->dev); in ti_sci_inta_msi_set_desc()
597 arg->desc = desc; in ti_sci_inta_msi_set_desc()
598 arg->hwirq = TO_HWIRQ(pdev->id, desc->msi_index); in ti_sci_inta_msi_set_desc()
614 struct device *dev = &inta->pdev->dev; in ti_sci_inta_get_unmapped_sources()
619 count = of_count_phandle_with_args(node, "ti,unmapped-event-sources", NULL); in ti_sci_inta_get_unmapped_sources()
623 inta->unmapped_dev_ids = devm_kcalloc(dev, count, in ti_sci_inta_get_unmapped_sources()
624 sizeof(*inta->unmapped_dev_ids), in ti_sci_inta_get_unmapped_sources()
626 if (!inta->unmapped_dev_ids) in ti_sci_inta_get_unmapped_sources()
627 return -ENOMEM; in ti_sci_inta_get_unmapped_sources()
630 of_for_each_phandle(&it, err, node, "ti,unmapped-event-sources", NULL, 0) { in ti_sci_inta_get_unmapped_sources()
633 ret = of_property_read_u32(it.node, "ti,sci-dev-id", &dev_id); in ti_sci_inta_get_unmapped_sources()
635 dev_err(dev, "ti,sci-dev-id read failure for %pOFf\n", it.node); in ti_sci_inta_get_unmapped_sources()
639 inta->unmapped_dev_ids[i++] = dev_id; in ti_sci_inta_get_unmapped_sources()
642 inta->unmapped_cnt = count; in ti_sci_inta_get_unmapped_sources()
652 struct device *dev = &pdev->dev; in ti_sci_inta_irq_domain_probe()
659 return -ENODEV; in ti_sci_inta_irq_domain_probe()
664 return -EPROBE_DEFER; in ti_sci_inta_irq_domain_probe()
668 return -ENOMEM; in ti_sci_inta_irq_domain_probe()
670 inta->pdev = pdev; in ti_sci_inta_irq_domain_probe()
671 inta->sci = devm_ti_sci_get_by_phandle(dev, "ti,sci"); in ti_sci_inta_irq_domain_probe()
672 if (IS_ERR(inta->sci)) in ti_sci_inta_irq_domain_probe()
673 return dev_err_probe(dev, PTR_ERR(inta->sci), in ti_sci_inta_irq_domain_probe()
676 ret = of_property_read_u32(dev->of_node, "ti,sci-dev-id", &inta->ti_sci_id); in ti_sci_inta_irq_domain_probe()
678 dev_err(dev, "missing 'ti,sci-dev-id' property\n"); in ti_sci_inta_irq_domain_probe()
679 return -EINVAL; in ti_sci_inta_irq_domain_probe()
682 inta->vint = devm_ti_sci_get_resource(inta->sci, dev, inta->ti_sci_id, in ti_sci_inta_irq_domain_probe()
684 if (IS_ERR(inta->vint)) { in ti_sci_inta_irq_domain_probe()
686 return PTR_ERR(inta->vint); in ti_sci_inta_irq_domain_probe()
689 inta->global_event = devm_ti_sci_get_resource(inta->sci, dev, inta->ti_sci_id, in ti_sci_inta_irq_domain_probe()
691 if (IS_ERR(inta->global_event)) { in ti_sci_inta_irq_domain_probe()
693 return PTR_ERR(inta->global_event); in ti_sci_inta_irq_domain_probe()
696 inta->base = devm_platform_ioremap_resource(pdev, 0); in ti_sci_inta_irq_domain_probe()
697 if (IS_ERR(inta->base)) in ti_sci_inta_irq_domain_probe()
698 return PTR_ERR(inta->base); in ti_sci_inta_irq_domain_probe()
705 ti_sci_get_num_resources(inta->vint), in ti_sci_inta_irq_domain_probe()
709 return -ENOMEM; in ti_sci_inta_irq_domain_probe()
718 return -ENOMEM; in ti_sci_inta_irq_domain_probe()
721 INIT_LIST_HEAD(&inta->vint_list); in ti_sci_inta_irq_domain_probe()
722 mutex_init(&inta->vint_mutex); in ti_sci_inta_irq_domain_probe()
724 dev_info(dev, "Interrupt Aggregator domain %d created\n", inta->ti_sci_id); in ti_sci_inta_irq_domain_probe()
730 { .compatible = "ti,sci-inta", },
738 .name = "ti-sci-inta",