blob: 4187cce20ffdc9cd0997b276e2f5e8dc020e2519 [file] [log] [blame]
Paul Mundt2be6bb0c2010-10-05 22:10:30 +09001/*
2 * Dynamic IRQ management
3 *
4 * Copyright (C) 2010 Paul Mundt
5 *
6 * Modelled after arch/x86/kernel/apic/io_apic.c
7 *
8 * This file is subject to the terms and conditions of the GNU General Public
9 * License. See the file "COPYING" in the main directory of this archive
10 * for more details.
11 */
12#define pr_fmt(fmt) "intc: " fmt
13
14#include <linux/irq.h>
15#include <linux/bitmap.h>
16#include <linux/spinlock.h>
17#include "internals.h" /* only for activate_irq() damage.. */
18
19/*
Paul Mundt38ab1342010-10-26 16:05:08 +090020 * The IRQ bitmap provides a global map of bound IRQ vectors for a
Paul Mundt2be6bb0c2010-10-05 22:10:30 +090021 * given platform. Allocation of IRQs are either static through the CPU
22 * vector map, or dynamic in the case of board mux vectors or MSI.
23 *
24 * As this is a central point for all IRQ controllers on the system,
25 * each of the available sources are mapped out here. This combined with
26 * sparseirq makes it quite trivial to keep the vector map tightly packed
27 * when dynamically creating IRQs, as well as tying in to otherwise
28 * unused irq_desc positions in the sparse array.
29 */
Paul Mundt2be6bb0c2010-10-05 22:10:30 +090030
31/*
32 * Dynamic IRQ allocation and deallocation
33 */
34unsigned int create_irq_nr(unsigned int irq_want, int node)
35{
Paul Mundt38ab1342010-10-26 16:05:08 +090036 int irq = irq_alloc_desc_at(irq_want, node);
37 if (irq < 0)
Thomas Gleixnerc4318ba2010-10-12 02:03:09 +090038 return 0;
Paul Mundt2be6bb0c2010-10-05 22:10:30 +090039
Thomas Gleixnerc4318ba2010-10-12 02:03:09 +090040 activate_irq(irq);
Paul Mundt38ab1342010-10-26 16:05:08 +090041 return irq;
Paul Mundt2be6bb0c2010-10-05 22:10:30 +090042}
43
44int create_irq(void)
45{
Paul Mundt38ab1342010-10-26 16:05:08 +090046 int irq = irq_alloc_desc(numa_node_id());
47 if (irq >= 0)
48 activate_irq(irq);
Paul Mundt2be6bb0c2010-10-05 22:10:30 +090049
50 return irq;
51}
52
53void destroy_irq(unsigned int irq)
54{
Thomas Gleixnerc4318ba2010-10-12 02:03:09 +090055 irq_free_desc(irq);
Paul Mundt2be6bb0c2010-10-05 22:10:30 +090056}
57
58void reserve_intc_vectors(struct intc_vect *vectors, unsigned int nr_vecs)
59{
Paul Mundt2be6bb0c2010-10-05 22:10:30 +090060 int i;
61
Paul Mundt2be6bb0c2010-10-05 22:10:30 +090062 for (i = 0; i < nr_vecs; i++)
Paul Mundt38ab1342010-10-26 16:05:08 +090063 irq_reserve_irqs(evt2irq(vectors[i].vect), 1);
Paul Mundt2be6bb0c2010-10-05 22:10:30 +090064}