blob: 3fbaef97a1b8d31791e8999bd222e3e1b01c3701 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * ip27-irq.c: Highlevel interrupt handling for IP27 architecture.
3 *
4 * Copyright (C) 1999, 2000 Ralf Baechle (ralf@gnu.org)
5 * Copyright (C) 1999, 2000 Silicon Graphics, Inc.
6 * Copyright (C) 1999 - 2001 Kanoj Sarcar
7 */
Ralf Baechled3ffd082005-08-08 12:42:26 +00008
9#undef DEBUG
10
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/init.h>
12#include <linux/irq.h>
13#include <linux/errno.h>
14#include <linux/signal.h>
15#include <linux/sched.h>
16#include <linux/types.h>
17#include <linux/interrupt.h>
18#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <linux/timex.h>
Ralf Baechle631330f2009-06-19 14:05:26 +010020#include <linux/smp.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/random.h>
Ralf Baechled3ffd082005-08-08 12:42:26 +000022#include <linux/kernel.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include <linux/kernel_stat.h>
24#include <linux/delay.h>
25#include <linux/bitops.h>
26
27#include <asm/bootinfo.h>
28#include <asm/io.h>
29#include <asm/mipsregs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030
Linus Torvalds1da177e2005-04-16 15:20:36 -070031#include <asm/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <asm/sn/addrs.h>
33#include <asm/sn/agent.h>
34#include <asm/sn/arch.h>
35#include <asm/sn/hub.h>
36#include <asm/sn/intr.h>
37
Linus Torvalds1da177e2005-04-16 15:20:36 -070038/*
39 * Linux has a controller-independent x86 interrupt architecture.
40 * every controller has a 'controller-template', that is used
41 * by the main code to do the right thing. Each driver-visible
Lucas De Marchi25985ed2011-03-30 22:57:33 -030042 * interrupt source is transparently wired to the appropriate
Linus Torvalds1da177e2005-04-16 15:20:36 -070043 * controller. Thus drivers need not be aware of the
44 * interrupt-controller.
45 *
46 * Various interrupt controllers we handle: 8259 PIC, SMP IO-APIC,
47 * PIIX4's internal 8259 PIC and SGI's Visual Workstation Cobalt (IO-)APIC.
48 * (IO-APICs assumed to be messaging to Pentium local-APICs)
49 *
50 * the code is designed to be easily extended with new/different
51 * interrupt controllers, without having to do assembly magic.
52 */
53
54extern asmlinkage void ip27_irq(void);
55
Linus Torvalds1da177e2005-04-16 15:20:36 -070056/*
57 * Find first bit set
58 */
59static int ms1bit(unsigned long x)
60{
61 int b = 0, s;
62
63 s = 16; if (x >> 16 == 0) s = 0; b += s; x >>= s;
64 s = 8; if (x >> 8 == 0) s = 0; b += s; x >>= s;
65 s = 4; if (x >> 4 == 0) s = 0; b += s; x >>= s;
66 s = 2; if (x >> 2 == 0) s = 0; b += s; x >>= s;
67 s = 1; if (x >> 1 == 0) s = 0; b += s;
68
69 return b;
70}
71
72/*
Yong Zhang8b5690f2011-11-22 14:38:03 +000073 * This code is unnecessarily complex, because we do
Linus Torvalds1da177e2005-04-16 15:20:36 -070074 * intr enabling. Basically, once we grab the set of intrs we need
75 * to service, we must mask _all_ these interrupts; firstly, to make
76 * sure the same intr does not intr again, causing recursion that
77 * can lead to stack overflow. Secondly, we can not just mask the
78 * one intr we are do_IRQing, because the non-masked intrs in the
79 * first set might intr again, causing multiple servicings of the
80 * same intr. This effect is mostly seen for intercpu intrs.
81 * Kanoj 05.13.00
82 */
83
Ralf Baechle937a8012006-10-07 19:44:33 +010084static void ip27_do_irq_mask0(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070085{
86 int irq, swlevel;
87 hubreg_t pend0, mask0;
88 cpuid_t cpu = smp_processor_id();
89 int pi_int_mask0 =
90 (cputoslice(cpu) == 0) ? PI_INT_MASK0_A : PI_INT_MASK0_B;
91
92 /* copied from Irix intpend0() */
93 pend0 = LOCAL_HUB_L(PI_INT_PEND0);
94 mask0 = LOCAL_HUB_L(pi_int_mask0);
95
96 pend0 &= mask0; /* Pick intrs we should look at */
97 if (!pend0)
98 return;
99
100 swlevel = ms1bit(pend0);
101#ifdef CONFIG_SMP
102 if (pend0 & (1UL << CPU_RESCHED_A_IRQ)) {
103 LOCAL_HUB_CLR_INTR(CPU_RESCHED_A_IRQ);
Peter Zijlstra184748c2011-04-05 17:23:39 +0200104 scheduler_ipi();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 } else if (pend0 & (1UL << CPU_RESCHED_B_IRQ)) {
106 LOCAL_HUB_CLR_INTR(CPU_RESCHED_B_IRQ);
Peter Zijlstra184748c2011-04-05 17:23:39 +0200107 scheduler_ipi();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108 } else if (pend0 & (1UL << CPU_CALL_A_IRQ)) {
109 LOCAL_HUB_CLR_INTR(CPU_CALL_A_IRQ);
110 smp_call_function_interrupt();
111 } else if (pend0 & (1UL << CPU_CALL_B_IRQ)) {
112 LOCAL_HUB_CLR_INTR(CPU_CALL_B_IRQ);
113 smp_call_function_interrupt();
114 } else
115#endif
116 {
117 /* "map" swlevel to irq */
118 struct slice_data *si = cpu_data[cpu].data;
119
120 irq = si->level_to_irq[swlevel];
Ralf Baechle937a8012006-10-07 19:44:33 +0100121 do_IRQ(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 }
123
124 LOCAL_HUB_L(PI_INT_PEND0);
125}
126
Ralf Baechle937a8012006-10-07 19:44:33 +0100127static void ip27_do_irq_mask1(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128{
129 int irq, swlevel;
130 hubreg_t pend1, mask1;
131 cpuid_t cpu = smp_processor_id();
132 int pi_int_mask1 = (cputoslice(cpu) == 0) ? PI_INT_MASK1_A : PI_INT_MASK1_B;
133 struct slice_data *si = cpu_data[cpu].data;
134
135 /* copied from Irix intpend0() */
136 pend1 = LOCAL_HUB_L(PI_INT_PEND1);
137 mask1 = LOCAL_HUB_L(pi_int_mask1);
138
139 pend1 &= mask1; /* Pick intrs we should look at */
140 if (!pend1)
141 return;
142
143 swlevel = ms1bit(pend1);
144 /* "map" swlevel to irq */
145 irq = si->level_to_irq[swlevel];
146 LOCAL_HUB_CLR_INTR(swlevel);
Ralf Baechle937a8012006-10-07 19:44:33 +0100147 do_IRQ(irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 LOCAL_HUB_L(PI_INT_PEND1);
150}
151
Ralf Baechle937a8012006-10-07 19:44:33 +0100152static void ip27_prof_timer(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153{
154 panic("CPU %d got a profiling interrupt", smp_processor_id());
155}
156
Ralf Baechle937a8012006-10-07 19:44:33 +0100157static void ip27_hub_error(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158{
159 panic("CPU %d got a hub error interrupt", smp_processor_id());
160}
161
Ralf Baechle937a8012006-10-07 19:44:33 +0100162asmlinkage void plat_irq_dispatch(void)
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100163{
164 unsigned long pending = read_c0_cause() & read_c0_status();
Ralf Baechlee887b242007-10-18 13:34:12 +0100165 extern unsigned int rt_timer_irq;
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100166
167 if (pending & CAUSEF_IP4)
Ralf Baechlee887b242007-10-18 13:34:12 +0100168 do_IRQ(rt_timer_irq);
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100169 else if (pending & CAUSEF_IP2) /* PI_INT_PEND_0 or CC_PEND_{A|B} */
Ralf Baechle937a8012006-10-07 19:44:33 +0100170 ip27_do_irq_mask0();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100171 else if (pending & CAUSEF_IP3) /* PI_INT_PEND_1 */
Ralf Baechle937a8012006-10-07 19:44:33 +0100172 ip27_do_irq_mask1();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100173 else if (pending & CAUSEF_IP5)
Ralf Baechle937a8012006-10-07 19:44:33 +0100174 ip27_prof_timer();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100175 else if (pending & CAUSEF_IP6)
Ralf Baechle937a8012006-10-07 19:44:33 +0100176 ip27_hub_error();
Ralf Baechlee4ac58a2006-04-03 17:56:36 +0100177}
178
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179void __init arch_init_irq(void)
180{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181}
182
183void install_ipi(void)
184{
185 int slice = LOCAL_HUB_L(PI_CPU_NUM);
186 int cpu = smp_processor_id();
187 struct slice_data *si = cpu_data[cpu].data;
Ralf Baechle4f12bfe2005-03-21 18:59:38 +0000188 struct hub_data *hub = hub_data(cpu_to_node(cpu));
189 int resched, call;
190
191 resched = CPU_RESCHED_A_IRQ + slice;
192 __set_bit(resched, hub->irq_alloc_mask);
193 __set_bit(resched, si->irq_enable_mask);
194 LOCAL_HUB_CLR_INTR(resched);
195
196 call = CPU_CALL_A_IRQ + slice;
197 __set_bit(call, hub->irq_alloc_mask);
198 __set_bit(call, si->irq_enable_mask);
199 LOCAL_HUB_CLR_INTR(call);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
201 if (slice == 0) {
Ralf Baechle4f12bfe2005-03-21 18:59:38 +0000202 LOCAL_HUB_S(PI_INT_MASK0_A, si->irq_enable_mask[0]);
203 LOCAL_HUB_S(PI_INT_MASK1_A, si->irq_enable_mask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 } else {
Ralf Baechle4f12bfe2005-03-21 18:59:38 +0000205 LOCAL_HUB_S(PI_INT_MASK0_B, si->irq_enable_mask[0]);
206 LOCAL_HUB_S(PI_INT_MASK1_B, si->irq_enable_mask[1]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 }
208}