2 * Copyright (C) 2003, Axis Communications AB.
7 #include <linux/interrupt.h>
9 #include <linux/config.h>
10 #include <linux/kernel.h>
11 #include <linux/errno.h>
12 #include <linux/init.h>
13 #include <linux/profile.h>
14 #include <linux/proc_fs.h>
15 #include <linux/seq_file.h>
16 #include <linux/threads.h>
17 #include <linux/spinlock.h>
18 #include <linux/kernel_stat.h>
19 #include <asm/arch/hwregs/reg_map.h>
20 #include <asm/arch/hwregs/reg_rdwr.h>
21 #include <asm/arch/hwregs/intr_vect.h>
22 #include <asm/arch/hwregs/intr_vect_defs.h>
26 /* IRQ masks (refer to comment for crisv32_do_multiple) */
27 #define TIMER_MASK (1 << (TIMER_INTR_VECT - FIRST_IRQ))
28 #ifdef CONFIG_ETRAX_KGDB
29 #if defined(CONFIG_ETRAX_KGDB_PORT0)
30 #define IGNOREMASK (1 << (SER0_INTR_VECT - FIRST_IRQ))
31 #elif defined(CONFIG_ETRAX_KGDB_PORT1)
32 #define IGNOREMASK (1 << (SER1_INTR_VECT - FIRST_IRQ))
33 #elif defined(CONFIG_ETRAX_KGB_PORT2)
34 #define IGNOREMASK (1 << (SER2_INTR_VECT - FIRST_IRQ))
35 #elif defined(CONFIG_ETRAX_KGDB_PORT3)
36 #define IGNOREMASK (1 << (SER3_INTR_VECT - FIRST_IRQ))
40 DEFINE_SPINLOCK(irq_lock
);
42 struct cris_irq_allocation
44 int cpu
; /* The CPU to which the IRQ is currently allocated. */
45 cpumask_t mask
; /* The CPUs to which the IRQ may be allocated. */
48 struct cris_irq_allocation irq_allocations
[NR_IRQS
] =
49 {[0 ... NR_IRQS
- 1] = {0, CPU_MASK_ALL
}};
51 static unsigned long irq_regs
[NR_CPUS
] =
59 unsigned long cpu_irq_counters
[NR_CPUS
];
60 unsigned long irq_counters
[NR_REAL_IRQS
];
63 extern void weird_irq(void);
66 extern void system_call(void);
67 extern void nmi_interrupt(void);
68 extern void multiple_interrupt(void);
69 extern void gdb_handle_exception(void);
70 extern void i_mmu_refill(void);
71 extern void i_mmu_invalid(void);
72 extern void i_mmu_access(void);
73 extern void i_mmu_execute(void);
74 extern void d_mmu_refill(void);
75 extern void d_mmu_invalid(void);
76 extern void d_mmu_access(void);
77 extern void d_mmu_write(void);
80 extern void kgdb_init(void);
81 extern void breakpoint(void);
84 * Build the IRQ handler stubs using macros from irq.h. First argument is the
85 * IRQ number, the second argument is the corresponding bit in
86 * intr_rw_vect_mask found in asm/arch/hwregs/intr_vect_defs.h.
88 BUILD_IRQ(0x31, (1 << 0)) /* memarb */
89 BUILD_IRQ(0x32, (1 << 1)) /* gen_io */
90 BUILD_IRQ(0x33, (1 << 2)) /* iop0 */
91 BUILD_IRQ(0x34, (1 << 3)) /* iop1 */
92 BUILD_IRQ(0x35, (1 << 4)) /* iop2 */
93 BUILD_IRQ(0x36, (1 << 5)) /* iop3 */
94 BUILD_IRQ(0x37, (1 << 6)) /* dma0 */
95 BUILD_IRQ(0x38, (1 << 7)) /* dma1 */
96 BUILD_IRQ(0x39, (1 << 8)) /* dma2 */
97 BUILD_IRQ(0x3a, (1 << 9)) /* dma3 */
98 BUILD_IRQ(0x3b, (1 << 10)) /* dma4 */
99 BUILD_IRQ(0x3c, (1 << 11)) /* dma5 */
100 BUILD_IRQ(0x3d, (1 << 12)) /* dma6 */
101 BUILD_IRQ(0x3e, (1 << 13)) /* dma7 */
102 BUILD_IRQ(0x3f, (1 << 14)) /* dma8 */
103 BUILD_IRQ(0x40, (1 << 15)) /* dma9 */
104 BUILD_IRQ(0x41, (1 << 16)) /* ata */
105 BUILD_IRQ(0x42, (1 << 17)) /* sser0 */
106 BUILD_IRQ(0x43, (1 << 18)) /* sser1 */
107 BUILD_IRQ(0x44, (1 << 19)) /* ser0 */
108 BUILD_IRQ(0x45, (1 << 20)) /* ser1 */
109 BUILD_IRQ(0x46, (1 << 21)) /* ser2 */
110 BUILD_IRQ(0x47, (1 << 22)) /* ser3 */
111 BUILD_IRQ(0x48, (1 << 23))
112 BUILD_IRQ(0x49, (1 << 24)) /* eth0 */
113 BUILD_IRQ(0x4a, (1 << 25)) /* eth1 */
114 BUILD_TIMER_IRQ(0x4b, (1 << 26))/* timer */
115 BUILD_IRQ(0x4c, (1 << 27)) /* bif_arb */
116 BUILD_IRQ(0x4d, (1 << 28)) /* bif_dma */
117 BUILD_IRQ(0x4e, (1 << 29)) /* ext */
118 BUILD_IRQ(0x4f, (1 << 29)) /* ipi */
120 /* Pointers to the low-level handlers. */
121 static void (*interrupt
[NR_IRQS
])(void) = {
122 IRQ0x31_interrupt
, IRQ0x32_interrupt
, IRQ0x33_interrupt
,
123 IRQ0x34_interrupt
, IRQ0x35_interrupt
, IRQ0x36_interrupt
,
124 IRQ0x37_interrupt
, IRQ0x38_interrupt
, IRQ0x39_interrupt
,
125 IRQ0x3a_interrupt
, IRQ0x3b_interrupt
, IRQ0x3c_interrupt
,
126 IRQ0x3d_interrupt
, IRQ0x3e_interrupt
, IRQ0x3f_interrupt
,
127 IRQ0x40_interrupt
, IRQ0x41_interrupt
, IRQ0x42_interrupt
,
128 IRQ0x43_interrupt
, IRQ0x44_interrupt
, IRQ0x45_interrupt
,
129 IRQ0x46_interrupt
, IRQ0x47_interrupt
, IRQ0x48_interrupt
,
130 IRQ0x49_interrupt
, IRQ0x4a_interrupt
, IRQ0x4b_interrupt
,
131 IRQ0x4c_interrupt
, IRQ0x4d_interrupt
, IRQ0x4e_interrupt
,
136 block_irq(int irq
, int cpu
)
141 spin_lock_irqsave(&irq_lock
, flags
);
142 intr_mask
= REG_RD_INT(intr_vect
, irq_regs
[cpu
], rw_mask
);
144 /* Remember; 1 let thru, 0 block. */
145 intr_mask
&= ~(1 << (irq
- FIRST_IRQ
));
147 REG_WR_INT(intr_vect
, irq_regs
[cpu
], rw_mask
, intr_mask
);
148 spin_unlock_irqrestore(&irq_lock
, flags
);
152 unblock_irq(int irq
, int cpu
)
157 spin_lock_irqsave(&irq_lock
, flags
);
158 intr_mask
= REG_RD_INT(intr_vect
, irq_regs
[cpu
], rw_mask
);
160 /* Remember; 1 let thru, 0 block. */
161 intr_mask
|= (1 << (irq
- FIRST_IRQ
));
163 REG_WR_INT(intr_vect
, irq_regs
[cpu
], rw_mask
, intr_mask
);
164 spin_unlock_irqrestore(&irq_lock
, flags
);
167 /* Find out which CPU the irq should be allocated to. */
168 static int irq_cpu(int irq
)
173 spin_lock_irqsave(&irq_lock
, flags
);
174 cpu
= irq_allocations
[irq
- FIRST_IRQ
].cpu
;
176 /* Fixed interrupts stay on the local CPU. */
177 if (cpu
== CPU_FIXED
)
179 spin_unlock_irqrestore(&irq_lock
, flags
);
180 return smp_processor_id();
184 /* Let the interrupt stay if possible */
185 if (cpu_isset(cpu
, irq_allocations
[irq
- FIRST_IRQ
].mask
))
188 /* IRQ must be moved to another CPU. */
189 cpu
= first_cpu(irq_allocations
[irq
- FIRST_IRQ
].mask
);
190 irq_allocations
[irq
- FIRST_IRQ
].cpu
= cpu
;
192 spin_unlock_irqrestore(&irq_lock
, flags
);
201 for (cpu
= 0; cpu
< NR_CPUS
; cpu
++)
208 unblock_irq(irq
, irq_cpu(irq
));
212 static unsigned int startup_crisv32_irq(unsigned int irq
)
218 static void shutdown_crisv32_irq(unsigned int irq
)
223 static void enable_crisv32_irq(unsigned int irq
)
228 static void disable_crisv32_irq(unsigned int irq
)
233 static void ack_crisv32_irq(unsigned int irq
)
237 static void end_crisv32_irq(unsigned int irq
)
241 void set_affinity_crisv32_irq(unsigned int irq
, cpumask_t dest
)
244 spin_lock_irqsave(&irq_lock
, flags
);
245 irq_allocations
[irq
- FIRST_IRQ
].mask
= dest
;
246 spin_unlock_irqrestore(&irq_lock
, flags
);
249 static struct hw_interrupt_type crisv32_irq_type
= {
250 .typename
= "CRISv32",
251 .startup
= startup_crisv32_irq
,
252 .shutdown
= shutdown_crisv32_irq
,
253 .enable
= enable_crisv32_irq
,
254 .disable
= disable_crisv32_irq
,
255 .ack
= ack_crisv32_irq
,
256 .end
= end_crisv32_irq
,
257 .set_affinity
= set_affinity_crisv32_irq
261 set_exception_vector(int n
, irqvectptr addr
)
263 etrax_irv
->v
[n
] = (irqvectptr
) addr
;
266 extern void do_IRQ(int irq
, struct pt_regs
* regs
);
269 crisv32_do_IRQ(int irq
, int block
, struct pt_regs
* regs
)
271 /* Interrupts that may not be moved to another CPU and
272 * are SA_INTERRUPT may skip blocking. This is currently
273 * only valid for the timer IRQ and the IPI and is used
274 * for the timer interrupt to avoid watchdog starvation.
281 block_irq(irq
, smp_processor_id());
284 unblock_irq(irq
, irq_cpu(irq
));
287 /* If multiple interrupts occur simultaneously we get a multiple
288 * interrupt from the CPU and software has to sort out which
289 * interrupts that happened. There are two special cases here:
291 * 1. Timer interrupts may never be blocked because of the
292 * watchdog (refer to comment in include/asr/arch/irq.h)
293 * 2. GDB serial port IRQs are unhandled here and will be handled
294 * as a single IRQ when it strikes again because the GDB
295 * stubb wants to save the registers in its own fashion.
298 crisv32_do_multiple(struct pt_regs
* regs
)
305 cpu
= smp_processor_id();
307 /* An extra irq_enter here to prevent softIRQs to run after
308 * each do_IRQ. This will decrease the interrupt latency.
312 /* Get which IRQs that happend. */
313 masked
= REG_RD_INT(intr_vect
, irq_regs
[cpu
], r_masked_vect
);
315 /* Calculate new IRQ mask with these IRQs disabled. */
316 mask
= REG_RD_INT(intr_vect
, irq_regs
[cpu
], rw_mask
);
319 /* Timer IRQ is never masked */
320 if (masked
& TIMER_MASK
)
323 /* Block all the IRQs */
324 REG_WR_INT(intr_vect
, irq_regs
[cpu
], rw_mask
, mask
);
326 /* Check for timer IRQ and handle it special. */
327 if (masked
& TIMER_MASK
) {
328 masked
&= ~TIMER_MASK
;
329 do_IRQ(TIMER_INTR_VECT
, regs
);
333 /* Remove IRQs that can't be handled as multiple. */
334 masked
&= ~IGNORE_MASK
;
337 /* Handle the rest of the IRQs. */
338 for (bit
= 0; bit
< 32; bit
++)
340 if (masked
& (1 << bit
))
341 do_IRQ(bit
+ FIRST_IRQ
, regs
);
344 /* Unblock all the IRQs. */
345 mask
= REG_RD_INT(intr_vect
, irq_regs
[cpu
], rw_mask
);
347 REG_WR_INT(intr_vect
, irq_regs
[cpu
], rw_mask
, mask
);
349 /* This irq_exit() will trigger the soft IRQs. */
354 * This is called by start_kernel. It fixes the IRQ masks and setup the
355 * interrupt vector table to point to bad_interrupt pointers.
362 reg_intr_vect_rw_mask vect_mask
= {0};
364 /* Clear all interrupts masks. */
365 REG_WR(intr_vect
, regi_irq
, rw_mask
, vect_mask
);
367 for (i
= 0; i
< 256; i
++)
368 etrax_irv
->v
[i
] = weird_irq
;
370 /* Point all IRQ's to bad handlers. */
371 for (i
= FIRST_IRQ
, j
= 0; j
< NR_IRQS
; i
++, j
++) {
372 irq_desc
[j
].handler
= &crisv32_irq_type
;
373 set_exception_vector(i
, interrupt
[j
]);
376 /* Mark Timer and IPI IRQs as CPU local */
377 irq_allocations
[TIMER_INTR_VECT
- FIRST_IRQ
].cpu
= CPU_FIXED
;
378 irq_desc
[TIMER_INTR_VECT
].status
|= IRQ_PER_CPU
;
379 irq_allocations
[IPI_INTR_VECT
- FIRST_IRQ
].cpu
= CPU_FIXED
;
380 irq_desc
[IPI_INTR_VECT
].status
|= IRQ_PER_CPU
;
382 set_exception_vector(0x00, nmi_interrupt
);
383 set_exception_vector(0x30, multiple_interrupt
);
385 /* Set up handler for various MMU bus faults. */
386 set_exception_vector(0x04, i_mmu_refill
);
387 set_exception_vector(0x05, i_mmu_invalid
);
388 set_exception_vector(0x06, i_mmu_access
);
389 set_exception_vector(0x07, i_mmu_execute
);
390 set_exception_vector(0x08, d_mmu_refill
);
391 set_exception_vector(0x09, d_mmu_invalid
);
392 set_exception_vector(0x0a, d_mmu_access
);
393 set_exception_vector(0x0b, d_mmu_write
);
395 /* The system-call trap is reached by "break 13". */
396 set_exception_vector(0x1d, system_call
);
398 /* Exception handlers for debugging, both user-mode and kernel-mode. */
401 set_exception_vector(0x18, gdb_handle_exception
);
402 /* Hardware single step. */
403 set_exception_vector(0x3, gdb_handle_exception
);
404 /* Hardware breakpoint. */
405 set_exception_vector(0xc, gdb_handle_exception
);
407 #ifdef CONFIG_ETRAX_KGDB
409 /* Everything is set up; now trap the kernel. */