1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49#include <common.h>
50#include <asm/interrupt.h>
51
52struct irq_action {
53 interrupt_handler_t *handler;
54 void *arg;
55 unsigned int count;
56};
57
58static struct irq_action irq_handlers[CONFIG_SYS_NUM_IRQS] = { {0} };
59static int spurious_irq_cnt = 0;
60static int spurious_irq = 0;
61
62void irq_install_handler(int irq, interrupt_handler_t *handler, void *arg)
63{
64 int status;
65
66 if (irq < 0 || irq >= CONFIG_SYS_NUM_IRQS) {
67 printf("irq_install_handler: bad irq number %d\n", irq);
68 return;
69 }
70
71 if (irq_handlers[irq].handler != NULL)
72 printf("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
73 (ulong) handler,
74 (ulong) irq_handlers[irq].handler);
75
76 status = disable_interrupts ();
77
78 irq_handlers[irq].handler = handler;
79 irq_handlers[irq].arg = arg;
80 irq_handlers[irq].count = 0;
81
82 unmask_irq(irq);
83
84 if (status)
85 enable_interrupts();
86
87 return;
88}
89
90void irq_free_handler(int irq)
91{
92 int status;
93
94 if (irq < 0 || irq >= CONFIG_SYS_NUM_IRQS) {
95 printf("irq_free_handler: bad irq number %d\n", irq);
96 return;
97 }
98
99 status = disable_interrupts ();
100
101 mask_irq(irq);
102
103 irq_handlers[irq].handler = NULL;
104 irq_handlers[irq].arg = NULL;
105
106 if (status)
107 enable_interrupts();
108
109 return;
110}
111
112void do_irq(int hw_irq)
113{
114 int irq = hw_irq - 0x20;
115
116 if (irq < 0 || irq >= CONFIG_SYS_NUM_IRQS) {
117 printf("do_irq: bad irq number %d\n", irq);
118 return;
119 }
120
121 if (irq_handlers[irq].handler) {
122 mask_irq(irq);
123
124 irq_handlers[irq].handler(irq_handlers[irq].arg);
125 irq_handlers[irq].count++;
126
127 unmask_irq(irq);
128 specific_eoi(irq);
129
130 } else {
131 if ((irq & 7) != 7) {
132 spurious_irq_cnt++;
133 spurious_irq = irq;
134 }
135 }
136}
137
138#if defined(CONFIG_CMD_IRQ)
139int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
140{
141 int irq;
142
143 printf("Spurious IRQ: %u, last unknown IRQ: %d\n",
144 spurious_irq_cnt, spurious_irq);
145
146 printf ("Interrupt-Information:\n");
147 printf ("Nr Routine Arg Count\n");
148
149 for (irq = 0; irq <= CONFIG_SYS_NUM_IRQS; irq++) {
150 if (irq_handlers[irq].handler != NULL) {
151 printf ("%02d %08lx %08lx %d\n",
152 irq,
153 (ulong)irq_handlers[irq].handler,
154 (ulong)irq_handlers[irq].arg,
155 irq_handlers[irq].count);
156 }
157 }
158
159 return 0;
160}
161#endif
162