aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/sh
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/sh')
-rw-r--r--drivers/sh/intc.c84
1 files changed, 83 insertions, 1 deletions
diff --git a/drivers/sh/intc.c b/drivers/sh/intc.c
index 94e6e46ff82c..4789df43c0f9 100644
--- a/drivers/sh/intc.c
+++ b/drivers/sh/intc.c
@@ -2,6 +2,7 @@
2 * Shared interrupt handling code for IPR and INTC2 types of IRQs. 2 * Shared interrupt handling code for IPR and INTC2 types of IRQs.
3 * 3 *
4 * Copyright (C) 2007, 2008 Magnus Damm 4 * Copyright (C) 2007, 2008 Magnus Damm
5 * Copyright (C) 2009 Paul Mundt
5 * 6 *
6 * Based on intc2.c and ipr.c 7 * Based on intc2.c and ipr.c
7 * 8 *
@@ -24,6 +25,7 @@
24#include <linux/sysdev.h> 25#include <linux/sysdev.h>
25#include <linux/list.h> 26#include <linux/list.h>
26#include <linux/topology.h> 27#include <linux/topology.h>
28#include <linux/bitmap.h>
27 29
28#define _INTC_MK(fn, mode, addr_e, addr_d, width, shift) \ 30#define _INTC_MK(fn, mode, addr_e, addr_d, width, shift) \
29 ((shift) | ((width) << 5) | ((fn) << 9) | ((mode) << 13) | \ 31 ((shift) | ((width) << 5) | ((fn) << 9) | ((mode) << 13) | \
@@ -59,6 +61,20 @@ struct intc_desc_int {
59 61
60static LIST_HEAD(intc_list); 62static LIST_HEAD(intc_list);
61 63
64/*
65 * The intc_irq_map provides a global map of bound IRQ vectors for a
66 * given platform. Allocation of IRQs are either static through the CPU
67 * vector map, or dynamic in the case of board mux vectors or MSI.
68 *
69 * As this is a central point for all IRQ controllers on the system,
70 * each of the available sources are mapped out here. This combined with
71 * sparseirq makes it quite trivial to keep the vector map tightly packed
72 * when dynamically creating IRQs, as well as tying in to otherwise
73 * unused irq_desc positions in the sparse array.
74 */
75static DECLARE_BITMAP(intc_irq_map, NR_IRQS);
76static DEFINE_SPINLOCK(vector_lock);
77
62#ifdef CONFIG_SMP 78#ifdef CONFIG_SMP
63#define IS_SMP(x) x.smp 79#define IS_SMP(x) x.smp
64#define INTC_REG(d, x, c) (d->reg[(x)] + ((d->smp[(x)] & 0xff) * c)) 80#define INTC_REG(d, x, c) (d->reg[(x)] + ((d->smp[(x)] & 0xff) * c))
@@ -566,6 +582,11 @@ static void __init intc_register_irq(struct intc_desc *desc,
566 struct intc_handle_int *hp; 582 struct intc_handle_int *hp;
567 unsigned int data[2], primary; 583 unsigned int data[2], primary;
568 584
585 /*
586 * Register the IRQ position with the global IRQ map
587 */
588 set_bit(irq, intc_irq_map);
589
569 /* Prefer single interrupt source bitmap over other combinations: 590 /* Prefer single interrupt source bitmap over other combinations:
570 * 1. bitmap, single interrupt source 591 * 1. bitmap, single interrupt source
571 * 2. priority, single interrupt source 592 * 2. priority, single interrupt source
@@ -844,5 +865,66 @@ static int __init register_intc_sysdevs(void)
844 865
845 return error; 866 return error;
846} 867}
847
848device_initcall(register_intc_sysdevs); 868device_initcall(register_intc_sysdevs);
869
870/*
871 * Dynamic IRQ allocation and deallocation
872 */
873static unsigned int create_irq_on_node(unsigned int irq_want, int node)
874{
875 unsigned int irq = 0, new;
876 unsigned long flags;
877 struct irq_desc *desc;
878
879 spin_lock_irqsave(&vector_lock, flags);
880
881 /*
882 * First try the wanted IRQ, then scan.
883 */
884 if (test_and_set_bit(irq_want, intc_irq_map)) {
885 new = find_first_zero_bit(intc_irq_map, nr_irqs);
886 if (unlikely(new == nr_irqs))
887 goto out_unlock;
888
889 desc = irq_to_desc_alloc_node(new, node);
890 if (unlikely(!desc)) {
891 pr_info("can't get irq_desc for %d\n", new);
892 goto out_unlock;
893 }
894
895 desc = move_irq_desc(desc, node);
896 __set_bit(new, intc_irq_map);
897 irq = new;
898 }
899
900out_unlock:
901 spin_unlock_irqrestore(&vector_lock, flags);
902
903 if (irq > 0)
904 dynamic_irq_init(irq);
905
906 return irq;
907}
908
909int create_irq(void)
910{
911 int nid = cpu_to_node(smp_processor_id());
912 int irq;
913
914 irq = create_irq_on_node(NR_IRQS_LEGACY, nid);
915 if (irq == 0)
916 irq = -1;
917
918 return irq;
919}
920
921void destroy_irq(unsigned int irq)
922{
923 unsigned long flags;
924
925 dynamic_irq_cleanup(irq);
926
927 spin_lock_irqsave(&vector_lock, flags);
928 __clear_bit(irq, intc_irq_map);
929 spin_unlock_irqrestore(&vector_lock, flags);
930}