]> git.ipfire.org Git - people/ms/u-boot.git/blob - arch/sparc/cpu/leon3/interrupts.c
Blackfin: Remove
[people/ms/u-boot.git] / arch / sparc / cpu / leon3 / interrupts.c
1 /*
2 * (C) Copyright 2007
3 * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com
4 *
5 * (C) Copyright 2006
6 * Detlev Zundel, DENX Software Engineering, dzu@denx.de
7 *
8 * (C) Copyright -2003
9 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
10 *
11 * (C) Copyright 2001
12 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
13 *
14 * SPDX-License-Identifier: GPL-2.0+
15 */
16
17 #include <asm/stack.h>
18 #include <common.h>
19 #include <asm/io.h>
20 #include <asm/processor.h>
21 #include <command.h>
22 #include <asm/irq.h>
23
24 #include <asm/leon.h>
25 #include <ambapp.h>
26 #include <grlib/irqmp.h>
27 #include <grlib/gptimer.h>
28
29 /* 15 normal irqs and a non maskable interrupt */
30 #define NR_IRQS 15
31
32 struct irq_action {
33 interrupt_handler_t *handler;
34 void *arg;
35 unsigned int count;
36 };
37
38 extern ambapp_dev_irqmp *irqmp;
39 extern ambapp_dev_gptimer *gptimer;
40
41 static struct irq_action irq_handlers[NR_IRQS] = { {0}, };
42 static int spurious_irq_cnt = 0;
43 static int spurious_irq = 0;
44
45 static inline unsigned int irqmp_get_irqmask(unsigned int irq)
46 {
47 if ((irq < 0) || (irq >= NR_IRQS)) {
48 return 0;
49 } else {
50 return (1 << irq);
51 }
52
53 }
54
55 static void leon3_ic_disable(unsigned int irq)
56 {
57 unsigned int mask, pil;
58 if (!irqmp)
59 return;
60
61 pil = intLock();
62
63 /* get mask of interrupt */
64 mask = irqmp_get_irqmask(irq);
65
66 /* set int level */
67 irqmp->cpu_mask[0] = SPARC_NOCACHE_READ(&irqmp->cpu_mask[0]) & (~mask);
68
69 intUnlock(pil);
70 }
71
72 static void leon3_ic_enable(unsigned int irq)
73 {
74 unsigned int mask, pil;
75 if (!irqmp)
76 return;
77
78 pil = intLock();
79
80 /* get mask of interrupt */
81 mask = irqmp_get_irqmask(irq);
82
83 /* set int level */
84 irqmp->cpu_mask[0] = SPARC_NOCACHE_READ(&irqmp->cpu_mask[0]) | mask;
85
86 intUnlock(pil);
87
88 }
89
90 void handler_irq(int irq, struct pt_regs *regs)
91 {
92 if (irq_handlers[irq].handler) {
93 if (((unsigned int)irq_handlers[irq].handler > CONFIG_SYS_RAM_END) ||
94 ((unsigned int)irq_handlers[irq].handler < CONFIG_SYS_RAM_BASE)
95 ) {
96 printf("handler_irq: bad handler: %x, irq number %d\n",
97 (unsigned int)irq_handlers[irq].handler, irq);
98 return;
99 }
100 irq_handlers[irq].handler(irq_handlers[irq].arg);
101 irq_handlers[irq].count++;
102 } else {
103 spurious_irq_cnt++;
104 spurious_irq = irq;
105 }
106 }
107
108 void leon3_force_int(int irq)
109 {
110 if (!irqmp || (irq >= NR_IRQS) || (irq < 0))
111 return;
112 printf("Forcing interrupt %d\n", irq);
113
114 irqmp->iforce = SPARC_NOCACHE_READ(&irqmp->iforce) | (1 << irq);
115 }
116
117 /****************************************************************************/
118
119 int interrupt_init_cpu(void)
120 {
121
122 return (0);
123 }
124
125 /****************************************************************************/
126
127 /*
128 * Install and free a interrupt handler.
129 */
130
131 void irq_install_handler(int irq, interrupt_handler_t * handler, void *arg)
132 {
133 if (irq < 0 || irq >= NR_IRQS) {
134 printf("irq_install_handler: bad irq number %d\n", irq);
135 return;
136 }
137
138 if (irq_handlers[irq].handler != NULL)
139 printf("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
140 (ulong) handler, (ulong) irq_handlers[irq].handler);
141
142 if (((unsigned int)handler > CONFIG_SYS_RAM_END) ||
143 ((unsigned int)handler < CONFIG_SYS_RAM_BASE)
144 ) {
145 printf("irq_install_handler: bad handler: %x, irq number %d\n",
146 (unsigned int)handler, irq);
147 return;
148 }
149 irq_handlers[irq].handler = handler;
150 irq_handlers[irq].arg = arg;
151
152 /* enable irq on IRQMP hardware */
153 leon3_ic_enable(irq);
154
155 }
156
157 void irq_free_handler(int irq)
158 {
159 if (irq < 0 || irq >= NR_IRQS) {
160 printf("irq_free_handler: bad irq number %d\n", irq);
161 return;
162 }
163
164 /* disable irq on IRQMP hardware */
165 leon3_ic_disable(irq);
166
167 irq_handlers[irq].handler = NULL;
168 irq_handlers[irq].arg = NULL;
169 }
170
171 /****************************************************************************/
172
173 #if defined(CONFIG_CMD_IRQ)
174 void do_irqinfo(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char * const argv[])
175 {
176 int irq;
177 unsigned int pil = get_pil();
178 printf("PIL level: %u\n\r", pil);
179 printf("Spurious IRQ: %u, last unknown IRQ: %d\n",
180 spurious_irq_cnt, spurious_irq);
181
182 puts("\nInterrupt-Information:\n" "Nr Routine Arg Count\n");
183
184 for (irq = 0; irq < NR_IRQS; irq++) {
185 if (irq_handlers[irq].handler != NULL) {
186 printf("%02d %p %p %d\n", irq,
187 irq_handlers[irq].handler,
188 irq_handlers[irq].arg,
189 irq_handlers[irq].count);
190 }
191 }
192 }
193 #endif