blob: 58b0aa813e85e512542a23a3e593561682ce1401 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/ppc/kernel/mv64360_pic.c
3 *
4 * Interrupt controller support for Marvell's MV64360.
5 *
6 * Author: Rabeeh Khoury <rabeeh@galileo.co.il>
7 * Based on MV64360 PIC written by
8 * Chris Zankel <chris@mvista.com>
9 * Mark A. Greer <mgreer@mvista.com>
10 *
11 * Copyright 2004 MontaVista Software, Inc.
12 *
13 * This program is free software; you can redistribute it and/or modify it
14 * under the terms of the GNU General Public License as published by the
15 * Free Software Foundation; either version 2 of the License, or (at your
16 * option) any later version.
17 */
18
19/*
20 * This file contains the specific functions to support the MV64360
21 * interrupt controller.
22 *
23 * The MV64360 has two main interrupt registers (high and low) that
24 * summarizes the interrupts generated by the units of the MV64360.
25 * Each bit is assigned to an interrupt number, where the low register
26 * are assigned from IRQ0 to IRQ31 and the high cause register
27 * from IRQ32 to IRQ63
28 * The GPP (General Purpose Pins) interrupts are assigned from IRQ64 (GPP0)
29 * to IRQ95 (GPP31).
30 * get_irq() returns the lowest interrupt number that is currently asserted.
31 *
32 * Note:
33 * - This driver does not initialize the GPP when used as an interrupt
34 * input.
35 */
36
37#include <linux/stddef.h>
38#include <linux/init.h>
39#include <linux/sched.h>
40#include <linux/signal.h>
41#include <linux/stddef.h>
42#include <linux/delay.h>
43#include <linux/irq.h>
44#include <linux/interrupt.h>
45
46#include <asm/io.h>
47#include <asm/processor.h>
48#include <asm/system.h>
49#include <asm/irq.h>
50#include <asm/mv64x60.h>
Paul Mackerrasfd582ec2005-10-11 22:08:12 +100051#include <asm/machdep.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53#ifdef CONFIG_IRQ_ALL_CPUS
54#error "The mv64360 does not support distribution of IRQs on all CPUs"
55#endif
56/* ========================== forward declaration ========================== */
57
58static void mv64360_unmask_irq(unsigned int);
59static void mv64360_mask_irq(unsigned int);
60static irqreturn_t mv64360_cpu_error_int_handler(int, void *, struct pt_regs *);
61static irqreturn_t mv64360_sram_error_int_handler(int, void *,
62 struct pt_regs *);
63static irqreturn_t mv64360_pci_error_int_handler(int, void *, struct pt_regs *);
64
65/* ========================== local declarations =========================== */
66
67struct hw_interrupt_type mv64360_pic = {
68 .typename = " mv64360 ",
69 .enable = mv64360_unmask_irq,
70 .disable = mv64360_mask_irq,
71 .ack = mv64360_mask_irq,
72 .end = mv64360_unmask_irq,
73};
74
75#define CPU_INTR_STR "mv64360 cpu interface error"
76#define SRAM_INTR_STR "mv64360 internal sram error"
77#define PCI0_INTR_STR "mv64360 pci 0 error"
78#define PCI1_INTR_STR "mv64360 pci 1 error"
79
80static struct mv64x60_handle bh;
81
82u32 mv64360_irq_base = 0; /* MV64360 handles the next 96 IRQs from here */
83
84/* mv64360_init_irq()
85 *
86 * This function initializes the interrupt controller. It assigns
87 * all interrupts from IRQ0 to IRQ95 to the mv64360 interrupt controller.
88 *
89 * Input Variable(s):
90 * None.
91 *
92 * Outpu. Variable(s):
93 * None.
94 *
95 * Returns:
96 * void
97 *
98 * Note:
99 * We register all GPP inputs as interrupt source, but disable them.
100 */
101void __init
102mv64360_init_irq(void)
103{
104 int i;
105
106 if (ppc_md.progress)
107 ppc_md.progress("mv64360_init_irq: enter", 0x0);
108
109 bh.v_base = mv64x60_get_bridge_vbase();
110
111 ppc_cached_irq_mask[0] = 0;
112 ppc_cached_irq_mask[1] = 0x0f000000; /* Enable GPP intrs */
113 ppc_cached_irq_mask[2] = 0;
114
115 /* disable all interrupts and clear current interrupts */
116 mv64x60_write(&bh, MV64x60_GPP_INTR_CAUSE, 0);
117 mv64x60_write(&bh, MV64x60_GPP_INTR_MASK, ppc_cached_irq_mask[2]);
118 mv64x60_write(&bh, MV64360_IC_CPU0_INTR_MASK_LO,ppc_cached_irq_mask[0]);
119 mv64x60_write(&bh, MV64360_IC_CPU0_INTR_MASK_HI,ppc_cached_irq_mask[1]);
120
121 /* All interrupts are level interrupts */
122 for (i = mv64360_irq_base; i < (mv64360_irq_base + 96); i++) {
123 irq_desc[i].status |= IRQ_LEVEL;
124 irq_desc[i].handler = &mv64360_pic;
125 }
126
127 if (ppc_md.progress)
128 ppc_md.progress("mv64360_init_irq: exit", 0x0);
129}
130
131/* mv64360_get_irq()
132 *
133 * This function returns the lowest interrupt number of all interrupts that
134 * are currently asserted.
135 *
136 * Input Variable(s):
137 * struct pt_regs* not used
138 *
139 * Output Variable(s):
140 * None.
141 *
142 * Returns:
143 * int <interrupt number> or -2 (bogus interrupt)
144 *
145 */
146int
147mv64360_get_irq(struct pt_regs *regs)
148{
149 int irq;
150 int irq_gpp;
151
152#ifdef CONFIG_SMP
153 /*
154 * Second CPU gets only doorbell (message) interrupts.
155 * The doorbell interrupt is BIT28 in the main interrupt low cause reg.
156 */
157 int cpu_nr = smp_processor_id();
158 if (cpu_nr == 1) {
159 if (!(mv64x60_read(&bh, MV64360_IC_MAIN_CAUSE_LO) &
160 (1 << MV64x60_IRQ_DOORBELL)))
161 return -1;
162 return mv64360_irq_base + MV64x60_IRQ_DOORBELL;
163 }
164#endif
165
166 irq = mv64x60_read(&bh, MV64360_IC_MAIN_CAUSE_LO);
167 irq = __ilog2((irq & 0x3dfffffe) & ppc_cached_irq_mask[0]);
168
169 if (irq == -1) {
170 irq = mv64x60_read(&bh, MV64360_IC_MAIN_CAUSE_HI);
171 irq = __ilog2((irq & 0x1f0003f7) & ppc_cached_irq_mask[1]);
172
173 if (irq == -1)
174 irq = -2; /* bogus interrupt, should never happen */
175 else {
176 if ((irq >= 24) && (irq < MV64x60_IRQ_DOORBELL)) {
177 irq_gpp = mv64x60_read(&bh,
178 MV64x60_GPP_INTR_CAUSE);
179 irq_gpp = __ilog2(irq_gpp &
180 ppc_cached_irq_mask[2]);
181
182 if (irq_gpp == -1)
183 irq = -2;
184 else {
185 irq = irq_gpp + 64;
186 mv64x60_write(&bh,
187 MV64x60_GPP_INTR_CAUSE,
188 ~(1 << (irq - 64)));
189 }
190 }
191 else
192 irq += 32;
193 }
194 }
195
196 (void)mv64x60_read(&bh, MV64x60_GPP_INTR_CAUSE);
197
198 if (irq < 0)
199 return (irq);
200 else
201 return (mv64360_irq_base + irq);
202}
203
204/* mv64360_unmask_irq()
205 *
206 * This function enables an interrupt.
207 *
208 * Input Variable(s):
209 * unsigned int interrupt number (IRQ0...IRQ95).
210 *
211 * Output Variable(s):
212 * None.
213 *
214 * Returns:
215 * void
216 */
217static void
218mv64360_unmask_irq(unsigned int irq)
219{
220#ifdef CONFIG_SMP
221 /* second CPU gets only doorbell interrupts */
222 if ((irq - mv64360_irq_base) == MV64x60_IRQ_DOORBELL) {
223 mv64x60_set_bits(&bh, MV64360_IC_CPU1_INTR_MASK_LO,
224 (1 << MV64x60_IRQ_DOORBELL));
225 return;
226 }
227#endif
228 irq -= mv64360_irq_base;
229
230 if (irq > 31) {
231 if (irq > 63) /* unmask GPP irq */
232 mv64x60_write(&bh, MV64x60_GPP_INTR_MASK,
233 ppc_cached_irq_mask[2] |= (1 << (irq - 64)));
234 else /* mask high interrupt register */
235 mv64x60_write(&bh, MV64360_IC_CPU0_INTR_MASK_HI,
236 ppc_cached_irq_mask[1] |= (1 << (irq - 32)));
237 }
238 else /* mask low interrupt register */
239 mv64x60_write(&bh, MV64360_IC_CPU0_INTR_MASK_LO,
240 ppc_cached_irq_mask[0] |= (1 << irq));
241
242 (void)mv64x60_read(&bh, MV64x60_GPP_INTR_MASK);
243 return;
244}
245
246/* mv64360_mask_irq()
247 *
248 * This function disables the requested interrupt.
249 *
250 * Input Variable(s):
251 * unsigned int interrupt number (IRQ0...IRQ95).
252 *
253 * Output Variable(s):
254 * None.
255 *
256 * Returns:
257 * void
258 */
259static void
260mv64360_mask_irq(unsigned int irq)
261{
262#ifdef CONFIG_SMP
263 if ((irq - mv64360_irq_base) == MV64x60_IRQ_DOORBELL) {
264 mv64x60_clr_bits(&bh, MV64360_IC_CPU1_INTR_MASK_LO,
265 (1 << MV64x60_IRQ_DOORBELL));
266 return;
267 }
268#endif
269 irq -= mv64360_irq_base;
270
271 if (irq > 31) {
272 if (irq > 63) /* mask GPP irq */
273 mv64x60_write(&bh, MV64x60_GPP_INTR_MASK,
274 ppc_cached_irq_mask[2] &= ~(1 << (irq - 64)));
275 else /* mask high interrupt register */
276 mv64x60_write(&bh, MV64360_IC_CPU0_INTR_MASK_HI,
277 ppc_cached_irq_mask[1] &= ~(1 << (irq - 32)));
278 }
279 else /* mask low interrupt register */
280 mv64x60_write(&bh, MV64360_IC_CPU0_INTR_MASK_LO,
281 ppc_cached_irq_mask[0] &= ~(1 << irq));
282
283 (void)mv64x60_read(&bh, MV64x60_GPP_INTR_MASK);
284 return;
285}
286
287static irqreturn_t
288mv64360_cpu_error_int_handler(int irq, void *dev_id, struct pt_regs *regs)
289{
290 printk(KERN_ERR "mv64360_cpu_error_int_handler: %s 0x%08x\n",
291 "Error on CPU interface - Cause regiser",
292 mv64x60_read(&bh, MV64x60_CPU_ERR_CAUSE));
293 printk(KERN_ERR "\tCPU error register dump:\n");
294 printk(KERN_ERR "\tAddress low 0x%08x\n",
295 mv64x60_read(&bh, MV64x60_CPU_ERR_ADDR_LO));
296 printk(KERN_ERR "\tAddress high 0x%08x\n",
297 mv64x60_read(&bh, MV64x60_CPU_ERR_ADDR_HI));
298 printk(KERN_ERR "\tData low 0x%08x\n",
299 mv64x60_read(&bh, MV64x60_CPU_ERR_DATA_LO));
300 printk(KERN_ERR "\tData high 0x%08x\n",
301 mv64x60_read(&bh, MV64x60_CPU_ERR_DATA_HI));
302 printk(KERN_ERR "\tParity 0x%08x\n",
303 mv64x60_read(&bh, MV64x60_CPU_ERR_PARITY));
304 mv64x60_write(&bh, MV64x60_CPU_ERR_CAUSE, 0);
305 return IRQ_HANDLED;
306}
307
308static irqreturn_t
309mv64360_sram_error_int_handler(int irq, void *dev_id, struct pt_regs *regs)
310{
311 printk(KERN_ERR "mv64360_sram_error_int_handler: %s 0x%08x\n",
312 "Error in internal SRAM - Cause register",
313 mv64x60_read(&bh, MV64360_SRAM_ERR_CAUSE));
314 printk(KERN_ERR "\tSRAM error register dump:\n");
315 printk(KERN_ERR "\tAddress Low 0x%08x\n",
316 mv64x60_read(&bh, MV64360_SRAM_ERR_ADDR_LO));
317 printk(KERN_ERR "\tAddress High 0x%08x\n",
318 mv64x60_read(&bh, MV64360_SRAM_ERR_ADDR_HI));
319 printk(KERN_ERR "\tData Low 0x%08x\n",
320 mv64x60_read(&bh, MV64360_SRAM_ERR_DATA_LO));
321 printk(KERN_ERR "\tData High 0x%08x\n",
322 mv64x60_read(&bh, MV64360_SRAM_ERR_DATA_HI));
323 printk(KERN_ERR "\tParity 0x%08x\n",
324 mv64x60_read(&bh, MV64360_SRAM_ERR_PARITY));
325 mv64x60_write(&bh, MV64360_SRAM_ERR_CAUSE, 0);
326 return IRQ_HANDLED;
327}
328
329static irqreturn_t
330mv64360_pci_error_int_handler(int irq, void *dev_id, struct pt_regs *regs)
331{
332 u32 val;
333 unsigned int pci_bus = (unsigned int)dev_id;
334
335 if (pci_bus == 0) { /* Error on PCI 0 */
336 val = mv64x60_read(&bh, MV64x60_PCI0_ERR_CAUSE);
337 printk(KERN_ERR "%s: Error in PCI %d Interface\n",
338 "mv64360_pci_error_int_handler", pci_bus);
339 printk(KERN_ERR "\tPCI %d error register dump:\n", pci_bus);
340 printk(KERN_ERR "\tCause register 0x%08x\n", val);
341 printk(KERN_ERR "\tAddress Low 0x%08x\n",
342 mv64x60_read(&bh, MV64x60_PCI0_ERR_ADDR_LO));
343 printk(KERN_ERR "\tAddress High 0x%08x\n",
344 mv64x60_read(&bh, MV64x60_PCI0_ERR_ADDR_HI));
345 printk(KERN_ERR "\tAttribute 0x%08x\n",
346 mv64x60_read(&bh, MV64x60_PCI0_ERR_DATA_LO));
347 printk(KERN_ERR "\tCommand 0x%08x\n",
348 mv64x60_read(&bh, MV64x60_PCI0_ERR_CMD));
349 mv64x60_write(&bh, MV64x60_PCI0_ERR_CAUSE, ~val);
350 }
351 if (pci_bus == 1) { /* Error on PCI 1 */
352 val = mv64x60_read(&bh, MV64x60_PCI1_ERR_CAUSE);
353 printk(KERN_ERR "%s: Error in PCI %d Interface\n",
354 "mv64360_pci_error_int_handler", pci_bus);
355 printk(KERN_ERR "\tPCI %d error register dump:\n", pci_bus);
356 printk(KERN_ERR "\tCause register 0x%08x\n", val);
357 printk(KERN_ERR "\tAddress Low 0x%08x\n",
358 mv64x60_read(&bh, MV64x60_PCI1_ERR_ADDR_LO));
359 printk(KERN_ERR "\tAddress High 0x%08x\n",
360 mv64x60_read(&bh, MV64x60_PCI1_ERR_ADDR_HI));
361 printk(KERN_ERR "\tAttribute 0x%08x\n",
362 mv64x60_read(&bh, MV64x60_PCI1_ERR_DATA_LO));
363 printk(KERN_ERR "\tCommand 0x%08x\n",
364 mv64x60_read(&bh, MV64x60_PCI1_ERR_CMD));
365 mv64x60_write(&bh, MV64x60_PCI1_ERR_CAUSE, ~val);
366 }
367 return IRQ_HANDLED;
368}
369
Mark A. Greerd01c08c2005-09-03 15:55:56 -0700370/*
371 * Bit 0 of MV64x60_PCIx_ERR_MASK does not exist on the 64360 and because of
372 * errata FEr-#11 and FEr-##16 for the 64460, it should be 0 on that chip as
373 * well. IOW, don't set bit 0.
374 */
375#define MV64360_PCI0_ERR_MASK_VAL 0x00a50c24
376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377static int __init
378mv64360_register_hdlrs(void)
379{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 int rc;
381
382 /* Clear old errors and register CPU interface error intr handler */
383 mv64x60_write(&bh, MV64x60_CPU_ERR_CAUSE, 0);
384 if ((rc = request_irq(MV64x60_IRQ_CPU_ERR + mv64360_irq_base,
385 mv64360_cpu_error_int_handler, SA_INTERRUPT, CPU_INTR_STR, 0)))
386 printk(KERN_WARNING "Can't register cpu error handler: %d", rc);
387
388 mv64x60_write(&bh, MV64x60_CPU_ERR_MASK, 0);
389 mv64x60_write(&bh, MV64x60_CPU_ERR_MASK, 0x000000ff);
390
391 /* Clear old errors and register internal SRAM error intr handler */
392 mv64x60_write(&bh, MV64360_SRAM_ERR_CAUSE, 0);
393 if ((rc = request_irq(MV64360_IRQ_SRAM_PAR_ERR + mv64360_irq_base,
394 mv64360_sram_error_int_handler,SA_INTERRUPT,SRAM_INTR_STR, 0)))
395 printk(KERN_WARNING "Can't register SRAM error handler: %d",rc);
396
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397 /* Clear old errors and register PCI 0 error intr handler */
398 mv64x60_write(&bh, MV64x60_PCI0_ERR_CAUSE, 0);
399 if ((rc = request_irq(MV64360_IRQ_PCI0 + mv64360_irq_base,
400 mv64360_pci_error_int_handler,
401 SA_INTERRUPT, PCI0_INTR_STR, (void *)0)))
402 printk(KERN_WARNING "Can't register pci 0 error handler: %d",
403 rc);
404
405 mv64x60_write(&bh, MV64x60_PCI0_ERR_MASK, 0);
Mark A. Greerd01c08c2005-09-03 15:55:56 -0700406 mv64x60_write(&bh, MV64x60_PCI0_ERR_MASK, MV64360_PCI0_ERR_MASK_VAL);
407
408 /* Erratum FEr PCI-#16 says to clear bit 0 of PCI SERRn Mask reg. */
409 mv64x60_write(&bh, MV64x60_PCI0_ERR_SERR_MASK,
410 mv64x60_read(&bh, MV64x60_PCI0_ERR_SERR_MASK) & ~0x1UL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411
412 /* Clear old errors and register PCI 1 error intr handler */
413 mv64x60_write(&bh, MV64x60_PCI1_ERR_CAUSE, 0);
414 if ((rc = request_irq(MV64360_IRQ_PCI1 + mv64360_irq_base,
415 mv64360_pci_error_int_handler,
416 SA_INTERRUPT, PCI1_INTR_STR, (void *)1)))
417 printk(KERN_WARNING "Can't register pci 1 error handler: %d",
418 rc);
419
420 mv64x60_write(&bh, MV64x60_PCI1_ERR_MASK, 0);
Mark A. Greerd01c08c2005-09-03 15:55:56 -0700421 mv64x60_write(&bh, MV64x60_PCI1_ERR_MASK, MV64360_PCI0_ERR_MASK_VAL);
422
423 /* Erratum FEr PCI-#16 says to clear bit 0 of PCI Intr Mask reg. */
424 mv64x60_write(&bh, MV64x60_PCI1_ERR_SERR_MASK,
425 mv64x60_read(&bh, MV64x60_PCI1_ERR_SERR_MASK) & ~0x1UL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
427 return 0;
428}
429
430arch_initcall(mv64360_register_hdlrs);