blob: 00c3288774fbab5ac166b3ca02a2a190eb318257 [file] [log] [blame]
Daniel Hellstromb552dbe2008-03-26 22:51:29 +01001/*
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 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +020014 * SPDX-License-Identifier: GPL-2.0+
Daniel Hellstromb552dbe2008-03-26 22:51:29 +010015 */
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>
Daniel Hellstrom9d59af92010-01-21 16:09:37 +010026#include <grlib/irqmp.h>
27#include <grlib/gptimer.h>
Daniel Hellstromb552dbe2008-03-26 22:51:29 +010028
29/* 15 normal irqs and a non maskable interrupt */
30#define NR_IRQS 15
31
32struct irq_action {
33 interrupt_handler_t *handler;
34 void *arg;
35 unsigned int count;
36};
37
38extern ambapp_dev_irqmp *irqmp;
39extern ambapp_dev_gptimer *gptimer;
40
41static struct irq_action irq_handlers[NR_IRQS] = { {0}, };
42static int spurious_irq_cnt = 0;
43static int spurious_irq = 0;
44
45static 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
55static 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
72static 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
90void handler_irq(int irq, struct pt_regs *regs)
91{
92 if (irq_handlers[irq].handler) {
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +020093 if (((unsigned int)irq_handlers[irq].handler > CONFIG_SYS_RAM_END) ||
94 ((unsigned int)irq_handlers[irq].handler < CONFIG_SYS_RAM_BASE)
Daniel Hellstromb552dbe2008-03-26 22:51:29 +010095 ) {
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
108void 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
119int interrupt_init_cpu(void)
120{
121
122 return (0);
123}
124
125/****************************************************************************/
126
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100127/*
128 * Install and free a interrupt handler.
129 */
130
131void 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
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200142 if (((unsigned int)handler > CONFIG_SYS_RAM_END) ||
143 ((unsigned int)handler < CONFIG_SYS_RAM_BASE)
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100144 ) {
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
157void 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)
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200174void do_irqinfo(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char * const argv[])
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100175{
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) {
Marek Vasut032b0802012-07-27 08:04:34 +0000186 printf("%02d %p %p %d\n", irq,
187 irq_handlers[irq].handler,
188 irq_handlers[irq].arg,
Daniel Hellstromb552dbe2008-03-26 22:51:29 +0100189 irq_handlers[irq].count);
190 }
191 }
192}
193#endif