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#include <asm/stack.h>
34#include <common.h>
35#include <asm/io.h>
36#include <asm/processor.h>
37#include <command.h>
38#include <asm/irq.h>
39
40#include <asm/leon.h>
41
42
43#define NR_IRQS 15
44
45struct irq_action {
46 interrupt_handler_t *handler;
47 void *arg;
48 unsigned int count;
49};
50
51static struct irq_action irq_handlers[NR_IRQS] = { {0}, };
52static int spurious_irq_cnt = 0;
53static int spurious_irq = 0;
54
55static inline unsigned int leon2_get_irqmask(unsigned int irq)
56{
57 if ((irq < 0) || (irq >= NR_IRQS)) {
58 return 0;
59 } else {
60 return (1 << irq);
61 }
62}
63
64static void leon2_ic_disable(unsigned int irq)
65{
66 unsigned int mask, pil;
67 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
68
69 pil = intLock();
70
71
72 mask = leon2_get_irqmask(irq);
73
74
75 leon2->Interrupt_Mask =
76 SPARC_NOCACHE_READ(&leon2->Interrupt_Mask) & (~mask);
77
78 intUnlock(pil);
79}
80
81static void leon2_ic_enable(unsigned int irq)
82{
83 unsigned int mask, pil;
84 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
85
86 pil = intLock();
87
88
89 mask = leon2_get_irqmask(irq);
90
91
92 leon2->Interrupt_Mask =
93 SPARC_NOCACHE_READ(&leon2->Interrupt_Mask) | mask;
94
95 intUnlock(pil);
96}
97
98void handler_irq(int irq, struct pt_regs *regs)
99{
100 if (irq_handlers[irq].handler) {
101 if (((unsigned int)irq_handlers[irq].handler > CONFIG_SYS_RAM_END) ||
102 ((unsigned int)irq_handlers[irq].handler < CONFIG_SYS_RAM_BASE)
103 ) {
104 printf("handler_irq: bad handler: %x, irq number %d\n",
105 (unsigned int)irq_handlers[irq].handler, irq);
106 return;
107 }
108 irq_handlers[irq].handler(irq_handlers[irq].arg);
109 irq_handlers[irq].count++;
110 } else {
111 spurious_irq_cnt++;
112 spurious_irq = irq;
113 }
114}
115
116void leon2_force_int(int irq)
117{
118 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
119
120 if ((irq >= NR_IRQS) || (irq < 0))
121 return;
122 printf("Forcing interrupt %d\n", irq);
123
124 leon2->Interrupt_Force =
125 SPARC_NOCACHE_READ(&leon2->Interrupt_Force) | (1 << irq);
126}
127
128
129
130int interrupt_init_cpu(void)
131{
132 return (0);
133}
134
135
136
137
138void timer_interrupt_cpu(void *arg)
139{
140 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
141
142 leon2->Timer_Control_1 =
143 (LEON2_TIMER_CTRL_EN | LEON2_TIMER_CTRL_RS | LEON2_TIMER_CTRL_LD);
144
145
146 return;
147}
148
149
150
151
152
153
154
155void irq_install_handler(int irq, interrupt_handler_t * handler, void *arg)
156{
157 if (irq < 0 || irq >= NR_IRQS) {
158 printf("irq_install_handler: bad irq number %d\n", irq);
159 return;
160 }
161
162 if (irq_handlers[irq].handler != NULL)
163 printf("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
164 (ulong) handler, (ulong) irq_handlers[irq].handler);
165
166 if (((unsigned int)handler > CONFIG_SYS_RAM_END) ||
167 ((unsigned int)handler < CONFIG_SYS_RAM_BASE)
168 ) {
169 printf("irq_install_handler: bad handler: %x, irq number %d\n",
170 (unsigned int)handler, irq);
171 return;
172 }
173 irq_handlers[irq].handler = handler;
174 irq_handlers[irq].arg = arg;
175
176
177 leon2_ic_enable(irq);
178
179}
180
181void irq_free_handler(int irq)
182{
183 if (irq < 0 || irq >= NR_IRQS) {
184 printf("irq_free_handler: bad irq number %d\n", irq);
185 return;
186 }
187
188
189 leon2_ic_disable(irq);
190
191 irq_handlers[irq].handler = NULL;
192 irq_handlers[irq].arg = NULL;
193}
194
195
196
197#if defined(CONFIG_CMD_IRQ)
198void do_irqinfo(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char *argv[])
199{
200 int irq;
201 unsigned int pil = get_pil();
202 printf("PIL level: %u\n\r", pil);
203 printf("Spurious IRQ: %u, last unknown IRQ: %d\n",
204 spurious_irq_cnt, spurious_irq);
205
206 puts("\nInterrupt-Information:\n" "Nr Routine Arg Count\n");
207
208 for (irq = 0; irq < NR_IRQS; irq++) {
209 if (irq_handlers[irq].handler != NULL) {
210 printf("%02d %08lx %08lx %ld\n", irq,
211 (unsigned int)irq_handlers[irq].handler,
212 (unsigned int)irq_handlers[irq].arg,
213 irq_handlers[irq].count);
214 }
215 }
216}
217#endif
218