]> git.ipfire.org Git - people/ms/u-boot.git/blob - arch/sparc/cpu/leon2/interrupts.c
Blackfin: Remove
[people/ms/u-boot.git] / arch / sparc / cpu / leon2 / 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
26 /* 15 normal irqs and a non maskable interrupt */
27 #define NR_IRQS 15
28
29 struct irq_action {
30 interrupt_handler_t *handler;
31 void *arg;
32 unsigned int count;
33 };
34
35 static struct irq_action irq_handlers[NR_IRQS] = { {0}, };
36 static int spurious_irq_cnt = 0;
37 static int spurious_irq = 0;
38
39 static inline unsigned int leon2_get_irqmask(unsigned int irq)
40 {
41 if ((irq < 0) || (irq >= NR_IRQS)) {
42 return 0;
43 } else {
44 return (1 << irq);
45 }
46 }
47
48 static void leon2_ic_disable(unsigned int irq)
49 {
50 unsigned int mask, pil;
51 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
52
53 pil = intLock();
54
55 /* get mask of interrupt */
56 mask = leon2_get_irqmask(irq);
57
58 /* set int level */
59 leon2->Interrupt_Mask =
60 SPARC_NOCACHE_READ(&leon2->Interrupt_Mask) & (~mask);
61
62 intUnlock(pil);
63 }
64
65 static void leon2_ic_enable(unsigned int irq)
66 {
67 unsigned int mask, pil;
68 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
69
70 pil = intLock();
71
72 /* get mask of interrupt */
73 mask = leon2_get_irqmask(irq);
74
75 /* set int level */
76 leon2->Interrupt_Mask =
77 SPARC_NOCACHE_READ(&leon2->Interrupt_Mask) | mask;
78
79 intUnlock(pil);
80 }
81
82 void handler_irq(int irq, struct pt_regs *regs)
83 {
84 if (irq_handlers[irq].handler) {
85 if (((unsigned int)irq_handlers[irq].handler > CONFIG_SYS_RAM_END) ||
86 ((unsigned int)irq_handlers[irq].handler < CONFIG_SYS_RAM_BASE)
87 ) {
88 printf("handler_irq: bad handler: %x, irq number %d\n",
89 (unsigned int)irq_handlers[irq].handler, irq);
90 return;
91 }
92 irq_handlers[irq].handler(irq_handlers[irq].arg);
93 irq_handlers[irq].count++;
94 } else {
95 spurious_irq_cnt++;
96 spurious_irq = irq;
97 }
98 }
99
100 void leon2_force_int(int irq)
101 {
102 LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS;
103
104 if ((irq >= NR_IRQS) || (irq < 0))
105 return;
106 printf("Forcing interrupt %d\n", irq);
107
108 leon2->Interrupt_Force =
109 SPARC_NOCACHE_READ(&leon2->Interrupt_Force) | (1 << irq);
110 }
111
112 /****************************************************************************/
113
114 int interrupt_init_cpu(void)
115 {
116 return (0);
117 }
118
119 /****************************************************************************/
120
121 /*
122 * Install and free a interrupt handler.
123 */
124
125 void irq_install_handler(int irq, interrupt_handler_t * handler, void *arg)
126 {
127 if (irq < 0 || irq >= NR_IRQS) {
128 printf("irq_install_handler: bad irq number %d\n", irq);
129 return;
130 }
131
132 if (irq_handlers[irq].handler != NULL)
133 printf("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
134 (ulong) handler, (ulong) irq_handlers[irq].handler);
135
136 if (((unsigned int)handler > CONFIG_SYS_RAM_END) ||
137 ((unsigned int)handler < CONFIG_SYS_RAM_BASE)
138 ) {
139 printf("irq_install_handler: bad handler: %x, irq number %d\n",
140 (unsigned int)handler, irq);
141 return;
142 }
143 irq_handlers[irq].handler = handler;
144 irq_handlers[irq].arg = arg;
145
146 /* enable irq on LEON2 hardware */
147 leon2_ic_enable(irq);
148
149 }
150
151 void irq_free_handler(int irq)
152 {
153 if (irq < 0 || irq >= NR_IRQS) {
154 printf("irq_free_handler: bad irq number %d\n", irq);
155 return;
156 }
157
158 /* disable irq on LEON2 hardware */
159 leon2_ic_disable(irq);
160
161 irq_handlers[irq].handler = NULL;
162 irq_handlers[irq].arg = NULL;
163 }
164
165 /****************************************************************************/
166
167 #if defined(CONFIG_CMD_IRQ)
168 void do_irqinfo(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char * const argv[])
169 {
170 int irq;
171 unsigned int pil = get_pil();
172 printf("PIL level: %u\n\r", pil);
173 printf("Spurious IRQ: %u, last unknown IRQ: %d\n",
174 spurious_irq_cnt, spurious_irq);
175
176 puts("\nInterrupt-Information:\n" "Nr Routine Arg Count\n");
177
178 for (irq = 0; irq < NR_IRQS; irq++) {
179 if (irq_handlers[irq].handler != NULL) {
180 printf("%02d %p %p %d\n", irq,
181 irq_handlers[irq].handler,
182 irq_handlers[irq].arg,
183 irq_handlers[irq].count);
184 }
185 }
186 }
187 #endif