blob: 5fea1ee8799afed9a7a028450df90e6c897060e1 [file] [log] [blame]
Paul Mundt2be6bb02010-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>
Paul Gortmakerdb4e8392011-07-31 19:18:02 -040017#include <linux/module.h>
Paul Mundt2be6bb02010-10-05 22:10:30 +090018#include "internals.h" /* only for activate_irq() damage.. */
19
20/*
Paul Mundt38ab1342010-10-26 16:05:08 +090021 * The IRQ bitmap provides a global map of bound IRQ vectors for a
Paul Mundt2be6bb02010-10-05 22:10:30 +090022 * given platform. Allocation of IRQs are either static through the CPU
23 * vector map, or dynamic in the case of board mux vectors or MSI.
24 *
25 * As this is a central point for all IRQ controllers on the system,
26 * each of the available sources are mapped out here. This combined with
27 * sparseirq makes it quite trivial to keep the vector map tightly packed
28 * when dynamically creating IRQs, as well as tying in to otherwise
29 * unused irq_desc positions in the sparse array.
30 */
Paul Mundt2be6bb02010-10-05 22:10:30 +090031
32/*
33 * Dynamic IRQ allocation and deallocation
34 */
35unsigned int create_irq_nr(unsigned int irq_want, int node)
36{
Paul Mundt38ab1342010-10-26 16:05:08 +090037 int irq = irq_alloc_desc_at(irq_want, node);
38 if (irq < 0)
Thomas Gleixnerc4318ba2010-10-12 02:03:09 +090039 return 0;
Paul Mundt2be6bb02010-10-05 22:10:30 +090040
Thomas Gleixnerc4318ba2010-10-12 02:03:09 +090041 activate_irq(irq);
Paul Mundt38ab1342010-10-26 16:05:08 +090042 return irq;
Paul Mundt2be6bb02010-10-05 22:10:30 +090043}
44
45int create_irq(void)
46{
Paul Mundt38ab1342010-10-26 16:05:08 +090047 int irq = irq_alloc_desc(numa_node_id());
48 if (irq >= 0)
49 activate_irq(irq);
Paul Mundt2be6bb02010-10-05 22:10:30 +090050
51 return irq;
52}
53
54void destroy_irq(unsigned int irq)
55{
Thomas Gleixnerc4318ba2010-10-12 02:03:09 +090056 irq_free_desc(irq);
Paul Mundt2be6bb02010-10-05 22:10:30 +090057}
58
59void reserve_intc_vectors(struct intc_vect *vectors, unsigned int nr_vecs)
60{
Paul Mundt2be6bb02010-10-05 22:10:30 +090061 int i;
62
Paul Mundt2be6bb02010-10-05 22:10:30 +090063 for (i = 0; i < nr_vecs; i++)
Paul Mundt20f95e02010-11-01 16:10:48 -040064 irq_reserve_irq(evt2irq(vectors[i].vect));
Paul Mundt2be6bb02010-10-05 22:10:30 +090065}