3 * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com
6 * Detlev Zundel, DENX Software Engineering, dzu@denx.de
9 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
12 * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc.
14 * SPDX-License-Identifier: GPL-2.0+
17 #include <asm/stack.h>
20 #include <asm/processor.h>
26 #include <grlib/irqmp.h>
27 #include <grlib/gptimer.h>
29 /* 15 normal irqs and a non maskable interrupt */
33 interrupt_handler_t *handler;
38 extern ambapp_dev_irqmp *irqmp;
39 extern ambapp_dev_gptimer *gptimer;
41 static struct irq_action irq_handlers[NR_IRQS] = { {0}, };
42 static int spurious_irq_cnt = 0;
43 static int spurious_irq = 0;
45 static inline unsigned int irqmp_get_irqmask(unsigned int irq)
47 if ((irq < 0) || (irq >= NR_IRQS)) {
55 static void leon3_ic_disable(unsigned int irq)
57 unsigned int mask, pil;
63 /* get mask of interrupt */
64 mask = irqmp_get_irqmask(irq);
67 irqmp->cpu_mask[0] = SPARC_NOCACHE_READ(&irqmp->cpu_mask[0]) & (~mask);
72 static void leon3_ic_enable(unsigned int irq)
74 unsigned int mask, pil;
80 /* get mask of interrupt */
81 mask = irqmp_get_irqmask(irq);
84 irqmp->cpu_mask[0] = SPARC_NOCACHE_READ(&irqmp->cpu_mask[0]) | mask;
90 void handler_irq(int irq, struct pt_regs *regs)
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)
96 printf("handler_irq: bad handler: %x, irq number %d\n",
97 (unsigned int)irq_handlers[irq].handler, irq);
100 irq_handlers[irq].handler(irq_handlers[irq].arg);
101 irq_handlers[irq].count++;
108 void leon3_force_int(int irq)
110 if (!irqmp || (irq >= NR_IRQS) || (irq < 0))
112 printf("Forcing interrupt %d\n", irq);
114 irqmp->iforce = SPARC_NOCACHE_READ(&irqmp->iforce) | (1 << irq);
117 /****************************************************************************/
119 int interrupt_init_cpu(void)
125 /****************************************************************************/
127 /* Handle Timer 0 IRQ */
128 void timer_interrupt_cpu(void *arg)
130 gptimer->e[0].ctrl = (GPTIMER_CTRL_EN | GPTIMER_CTRL_RS |
131 GPTIMER_CTRL_LD | GPTIMER_CTRL_IE);
132 /* nothing to do here */
136 /****************************************************************************/
139 * Install and free a interrupt handler.
142 void irq_install_handler(int irq, interrupt_handler_t * handler, void *arg)
144 if (irq < 0 || irq >= NR_IRQS) {
145 printf("irq_install_handler: bad irq number %d\n", irq);
149 if (irq_handlers[irq].handler != NULL)
150 printf("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
151 (ulong) handler, (ulong) irq_handlers[irq].handler);
153 if (((unsigned int)handler > CONFIG_SYS_RAM_END) ||
154 ((unsigned int)handler < CONFIG_SYS_RAM_BASE)
156 printf("irq_install_handler: bad handler: %x, irq number %d\n",
157 (unsigned int)handler, irq);
160 irq_handlers[irq].handler = handler;
161 irq_handlers[irq].arg = arg;
163 /* enable irq on IRQMP hardware */
164 leon3_ic_enable(irq);
168 void irq_free_handler(int irq)
170 if (irq < 0 || irq >= NR_IRQS) {
171 printf("irq_free_handler: bad irq number %d\n", irq);
175 /* disable irq on IRQMP hardware */
176 leon3_ic_disable(irq);
178 irq_handlers[irq].handler = NULL;
179 irq_handlers[irq].arg = NULL;
182 /****************************************************************************/
184 #if defined(CONFIG_CMD_IRQ)
185 void do_irqinfo(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char * const argv[])
188 unsigned int pil = get_pil();
189 printf("PIL level: %u\n\r", pil);
190 printf("Spurious IRQ: %u, last unknown IRQ: %d\n",
191 spurious_irq_cnt, spurious_irq);
193 puts("\nInterrupt-Information:\n" "Nr Routine Arg Count\n");
195 for (irq = 0; irq < NR_IRQS; irq++) {
196 if (irq_handlers[irq].handler != NULL) {
197 printf("%02d %p %p %d\n", irq,
198 irq_handlers[irq].handler,
199 irq_handlers[irq].arg,
200 irq_handlers[irq].count);