2 * Copyright 2001 MontaVista Software Inc.
3 * Author: MontaVista Software, Inc.
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
10 * Copyright (C) 2000-2001 Toshiba Corporation
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
20 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * You should have received a copy of the GNU General Public License along
29 * with this program; if not, write to the Free Software Foundation, Inc.,
30 * 675 Mass Ave, Cambridge, MA 02139, USA.
32 #include <linux/config.h>
33 #include <linux/init.h>
35 #include <linux/errno.h>
36 #include <linux/irq.h>
37 #include <linux/kernel_stat.h>
38 #include <linux/signal.h>
39 #include <linux/sched.h>
40 #include <linux/types.h>
41 #include <linux/interrupt.h>
42 #include <linux/ioport.h>
43 #include <linux/timex.h>
44 #include <linux/slab.h>
45 #include <linux/random.h>
46 #include <linux/smp.h>
47 #include <linux/smp_lock.h>
48 #include <linux/bitops.h>
51 #include <asm/mipsregs.h>
52 #include <asm/system.h>
54 #include <asm/ptrace.h>
55 #include <asm/processor.h>
56 #include <asm/jmr3927/irq.h>
57 #include <asm/debug.h>
58 #include <asm/jmr3927/jmr3927.h>
60 #if JMR3927_IRQ_END > NR_IRQS
61 #error JMR3927_IRQ_END > NR_IRQS
64 struct tb_irq_space* tb_irq_spaces;
66 static int jmr3927_irq_base = -1;
69 static int jmr3927_gen_iack(void)
71 /* generate ACK cycle */
73 return (tx3927_pcicptr->iiadp >> 24) & 0xff;
75 return tx3927_pcicptr->iiadp & 0xff;
80 extern asmlinkage void jmr3927_IRQ(void);
85 static unsigned char irc_level[TX3927_NUM_IR] = {
86 5, 5, 5, 5, 5, 5, /* INT[5:0] */
88 5, 5, 5, 0, 0, /* DMA, PIO, PCI */
92 static void jmr3927_irq_disable(unsigned int irq_nr);
93 static void jmr3927_irq_enable(unsigned int irq_nr);
95 static DEFINE_SPINLOCK(jmr3927_irq_lock);
97 static unsigned int jmr3927_irq_startup(unsigned int irq)
99 jmr3927_irq_enable(irq);
104 #define jmr3927_irq_shutdown jmr3927_irq_disable
106 static void jmr3927_irq_ack(unsigned int irq)
108 if (irq == JMR3927_IRQ_IRC_TMR0)
109 jmr3927_tmrptr->tisr = 0; /* ack interrupt */
111 jmr3927_irq_disable(irq);
114 static void jmr3927_irq_end(unsigned int irq)
116 jmr3927_irq_enable(irq);
119 static void jmr3927_irq_disable(unsigned int irq_nr)
121 struct tb_irq_space* sp;
124 spinlock_irqsave(&jmr3927_irq_lock, flags);
125 for (sp = tb_irq_spaces; sp; sp = sp->next) {
126 if (sp->start_irqno <= irq_nr &&
127 irq_nr < sp->start_irqno + sp->nr_irqs) {
129 sp->mask_func(irq_nr - sp->start_irqno,
134 spinlock_irqrestore(&jmr3927_irq_lock, flags);
137 static void jmr3927_irq_enable(unsigned int irq_nr)
139 struct tb_irq_space* sp;
142 spinlock_irqsave(&jmr3927_irq_lock, flags);
143 for (sp = tb_irq_spaces; sp; sp = sp->next) {
144 if (sp->start_irqno <= irq_nr &&
145 irq_nr < sp->start_irqno + sp->nr_irqs) {
147 sp->unmask_func(irq_nr - sp->start_irqno,
152 spinlock_irqrestore(&jmr3927_irq_lock, flags);
156 * CP0_STATUS is a thread's resource (saved/restored on context switch).
157 * So disable_irq/enable_irq MUST handle IOC/ISAC/IRC registers.
159 static void mask_irq_isac(int irq_nr, int space_id)
162 unsigned char imask =
163 jmr3927_isac_reg_in(JMR3927_ISAC_INTM_ADDR);
164 unsigned int bit = 1 << irq_nr;
165 jmr3927_isac_reg_out(imask & ~bit, JMR3927_ISAC_INTM_ADDR);
166 /* flush write buffer */
167 (void)jmr3927_ioc_reg_in(JMR3927_IOC_REV_ADDR);
169 static void unmask_irq_isac(int irq_nr, int space_id)
172 unsigned char imask = jmr3927_isac_reg_in(JMR3927_ISAC_INTM_ADDR);
173 unsigned int bit = 1 << irq_nr;
174 jmr3927_isac_reg_out(imask | bit, JMR3927_ISAC_INTM_ADDR);
175 /* flush write buffer */
176 (void)jmr3927_ioc_reg_in(JMR3927_IOC_REV_ADDR);
179 static void mask_irq_ioc(int irq_nr, int space_id)
182 unsigned char imask = jmr3927_ioc_reg_in(JMR3927_IOC_INTM_ADDR);
183 unsigned int bit = 1 << irq_nr;
184 jmr3927_ioc_reg_out(imask & ~bit, JMR3927_IOC_INTM_ADDR);
185 /* flush write buffer */
186 (void)jmr3927_ioc_reg_in(JMR3927_IOC_REV_ADDR);
188 static void unmask_irq_ioc(int irq_nr, int space_id)
191 unsigned char imask = jmr3927_ioc_reg_in(JMR3927_IOC_INTM_ADDR);
192 unsigned int bit = 1 << irq_nr;
193 jmr3927_ioc_reg_out(imask | bit, JMR3927_IOC_INTM_ADDR);
194 /* flush write buffer */
195 (void)jmr3927_ioc_reg_in(JMR3927_IOC_REV_ADDR);
198 static void mask_irq_irc(int irq_nr, int space_id)
200 volatile unsigned long *ilrp = &tx3927_ircptr->ilr[irq_nr / 2];
202 *ilrp = (*ilrp & 0x00ff) | (irc_dlevel << 8);
204 *ilrp = (*ilrp & 0xff00) | irc_dlevel;
206 tx3927_ircptr->imr = 0;
207 tx3927_ircptr->imr = irc_elevel;
209 static void unmask_irq_irc(int irq_nr, int space_id)
211 volatile unsigned long *ilrp = &tx3927_ircptr->ilr[irq_nr / 2];
213 *ilrp = (*ilrp & 0x00ff) | (irc_level[irq_nr] << 8);
215 *ilrp = (*ilrp & 0xff00) | irc_level[irq_nr];
217 tx3927_ircptr->imr = 0;
218 tx3927_ircptr->imr = irc_elevel;
221 struct tb_irq_space jmr3927_isac_irqspace = {
223 .start_irqno = JMR3927_IRQ_ISAC,
224 nr_irqs : JMR3927_NR_IRQ_ISAC,
225 .mask_func = mask_irq_isac,
226 .unmask_func = unmask_irq_isac,
231 struct tb_irq_space jmr3927_ioc_irqspace = {
233 .start_irqno = JMR3927_IRQ_IOC,
234 nr_irqs : JMR3927_NR_IRQ_IOC,
235 .mask_func = mask_irq_ioc,
236 .unmask_func = unmask_irq_ioc,
241 struct tb_irq_space jmr3927_irc_irqspace = {
243 .start_irqno = JMR3927_IRQ_IRC,
244 nr_irqs : JMR3927_NR_IRQ_IRC,
245 .mask_func = mask_irq_irc,
246 .unmask_func = unmask_irq_irc,
252 void jmr3927_spurious(struct pt_regs *regs)
254 #ifdef CONFIG_TX_BRANCH_LIKELY_BUG_WORKAROUND
255 tx_branch_likely_bug_fixup(regs);
257 printk(KERN_WARNING "spurious interrupt (cause 0x%lx, pc 0x%lx, ra 0x%lx).\n",
258 regs->cp0_cause, regs->cp0_epc, regs->regs[31]);
261 void jmr3927_irc_irqdispatch(struct pt_regs *regs)
265 #ifdef CONFIG_TX_BRANCH_LIKELY_BUG_WORKAROUND
266 tx_branch_likely_bug_fixup(regs);
268 if ((regs->cp0_cause & CAUSEF_IP7) == 0) {
270 jmr3927_spurious(regs);
274 irq = (regs->cp0_cause >> CAUSEB_IP2) & 0x0f;
276 do_IRQ(irq + JMR3927_IRQ_IRC, regs);
279 static void jmr3927_ioc_interrupt(int irq, void *dev_id, struct pt_regs *regs)
281 unsigned char istat = jmr3927_ioc_reg_in(JMR3927_IOC_INTS2_ADDR);
284 for (i = 0; i < JMR3927_NR_IRQ_IOC; i++) {
285 if (istat & (1 << i)) {
286 irq = JMR3927_IRQ_IOC + i;
292 static struct irqaction ioc_action = {
293 jmr3927_ioc_interrupt, 0, CPU_MASK_NONE, "IOC", NULL, NULL,
296 static void jmr3927_isac_interrupt(int irq, void *dev_id, struct pt_regs *regs)
298 unsigned char istat = jmr3927_isac_reg_in(JMR3927_ISAC_INTS2_ADDR);
301 for (i = 0; i < JMR3927_NR_IRQ_ISAC; i++) {
302 if (istat & (1 << i)) {
303 irq = JMR3927_IRQ_ISAC + i;
309 static struct irqaction isac_action = {
310 jmr3927_isac_interrupt, 0, CPU_MASK_NONE, "ISAC", NULL, NULL,
314 static void jmr3927_isaerr_interrupt(int irq, void * dev_id, struct pt_regs * regs)
316 printk(KERN_WARNING "ISA error interrupt (irq 0x%x).\n", irq);
318 static struct irqaction isaerr_action = {
319 jmr3927_isaerr_interrupt, 0, CPU_MASK_NONE, "ISA error", NULL, NULL,
322 static void jmr3927_pcierr_interrupt(int irq, void * dev_id, struct pt_regs * regs)
324 printk(KERN_WARNING "PCI error interrupt (irq 0x%x).\n", irq);
325 printk(KERN_WARNING "pcistat:%02x, lbstat:%04lx\n",
326 tx3927_pcicptr->pcistat, tx3927_pcicptr->lbstat);
328 static struct irqaction pcierr_action = {
329 jmr3927_pcierr_interrupt, 0, CPU_MASK_NONE, "PCI error", NULL, NULL,
332 int jmr3927_ether1_irq = 0;
334 void jmr3927_irq_init(u32 irq_base);
336 void __init arch_init_irq(void)
338 /* look for io board's presence */
339 int have_isac = jmr3927_have_isac();
341 /* Now, interrupt control disabled, */
342 /* all IRC interrupts are masked, */
343 /* all IRC interrupt mode are Low Active. */
347 /* ETHER1 (NE2000 compatible 10M-Ether) parameter setup */
348 /* temporary enable interrupt control */
349 tx3927_ircptr->cer = 1;
350 /* ETHER1 Int. Is High-Active. */
351 if (tx3927_ircptr->ssr & (1 << 0))
352 jmr3927_ether1_irq = JMR3927_IRQ_IRC_INT0;
353 #if 0 /* INT3 may be asserted by ether0 (even after reboot...) */
354 else if (tx3927_ircptr->ssr & (1 << 3))
355 jmr3927_ether1_irq = JMR3927_IRQ_IRC_INT3;
357 /* disable interrupt control */
358 tx3927_ircptr->cer = 0;
360 /* Ether1: High Active */
361 if (jmr3927_ether1_irq) {
362 int ether1_irc = jmr3927_ether1_irq - JMR3927_IRQ_IRC;
363 tx3927_ircptr->cr[ether1_irc / 8] |=
364 TX3927_IRCR_HIGH << ((ether1_irc % 8) * 2);
368 /* mask all IOC interrupts */
369 jmr3927_ioc_reg_out(0, JMR3927_IOC_INTM_ADDR);
370 /* setup IOC interrupt mode (SOFT:High Active, Others:Low Active) */
371 jmr3927_ioc_reg_out(JMR3927_IOC_INTF_SOFT, JMR3927_IOC_INTP_ADDR);
374 /* mask all ISAC interrupts */
375 jmr3927_isac_reg_out(0, JMR3927_ISAC_INTM_ADDR);
376 /* setup ISAC interrupt mode (ISAIRQ3,ISAIRQ5:Low Active ???) */
377 jmr3927_isac_reg_out(JMR3927_ISAC_INTF_IRQ3|JMR3927_ISAC_INTF_IRQ5, JMR3927_ISAC_INTP_ADDR);
380 /* clear PCI Soft interrupts */
381 jmr3927_ioc_reg_out(0, JMR3927_IOC_INTS1_ADDR);
382 /* clear PCI Reset interrupts */
383 jmr3927_ioc_reg_out(0, JMR3927_IOC_RESET_ADDR);
385 /* enable interrupt control */
386 tx3927_ircptr->cer = TX3927_IRCER_ICE;
387 tx3927_ircptr->imr = irc_elevel;
389 jmr3927_irq_init(NR_ISA_IRQS);
391 set_except_vector(0, jmr3927_IRQ);
393 /* setup irq space */
394 add_tb_irq_space(&jmr3927_isac_irqspace);
395 add_tb_irq_space(&jmr3927_ioc_irqspace);
396 add_tb_irq_space(&jmr3927_irc_irqspace);
398 /* setup IOC interrupt 1 (PCI, MODEM) */
399 setup_irq(JMR3927_IRQ_IOCINT, &ioc_action);
402 setup_irq(JMR3927_IRQ_ISACINT, &isac_action);
403 setup_irq(JMR3927_IRQ_ISAC_ISAER, &isaerr_action);
407 setup_irq(JMR3927_IRQ_IRC_PCI, &pcierr_action);
410 /* enable all CPU interrupt bits. */
411 set_c0_status(ST0_IM); /* IE bit is still 0. */
414 static hw_irq_controller jmr3927_irq_controller = {
415 .typename = "jmr3927_irq",
416 .startup = jmr3927_irq_startup,
417 .shutdown = jmr3927_irq_shutdown,
418 .enable = jmr3927_irq_enable,
419 .disable = jmr3927_irq_disable,
420 .ack = jmr3927_irq_ack,
421 .end = jmr3927_irq_end,
424 void jmr3927_irq_init(u32 irq_base)
428 for (i= irq_base; i< irq_base + JMR3927_NR_IRQ_IRC + JMR3927_NR_IRQ_IOC; i++) {
429 irq_desc[i].status = IRQ_DISABLED;
430 irq_desc[i].action = NULL;
431 irq_desc[i].depth = 1;
432 irq_desc[i].handler = &jmr3927_irq_controller;
435 jmr3927_irq_base = irq_base;
438 #ifdef CONFIG_TX_BRANCH_LIKELY_BUG_WORKAROUND
439 static int tx_branch_likely_bug_count = 0;
440 static int have_tx_branch_likely_bug = 0;
441 void tx_branch_likely_bug_fixup(struct pt_regs *regs)
443 /* TX39/49-BUG: Under this condition, the insn in delay slot
444 of the branch likely insn is executed (not nullified) even
445 the branch condition is false. */
446 if (!have_tx_branch_likely_bug)
448 if ((regs->cp0_epc & 0xfff) == 0xffc &&
449 KSEGX(regs->cp0_epc) != KSEG0 &&
450 KSEGX(regs->cp0_epc) != KSEG1) {
451 unsigned int insn = *(unsigned int*)(regs->cp0_epc - 4);
452 /* beql,bnel,blezl,bgtzl */
453 /* bltzl,bgezl,blezall,bgezall */
455 if ((insn & 0xf0000000) == 0x50000000 ||
456 (insn & 0xfc0e0000) == 0x04020000 ||
457 (insn & 0xf3fe0000) == 0x41020000) {
459 tx_branch_likely_bug_count++;
461 "fix branch-likery bug in %s (insn %08x)\n",
462 current->comm, insn);