2 * (C) Copyright 2007 Michal Simek
3 * (C) Copyright 2004 Atmark Techno, Inc.
5 * Michal SIMEK <monstr@monstr.eu>
6 * Yasushi SHOJI <yashi@atmark-techno.com>
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
30 #include <asm/microblaze_intc.h>
35 extern void microblaze_disable_interrupts (void);
36 extern void microblaze_enable_interrupts (void);
38 void enable_interrupts (void)
43 int disable_interrupts (void)
49 return (msr & 0x2) != 0;
52 static struct irq_action *vecs;
55 /* mapping structure to interrupt controller */
56 microblaze_intc_t *intc;
59 static void def_hdlr(void)
64 static void enable_one_interrupt(int irq)
70 intc->ier = (mask | offset);
72 printf ("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask,
74 printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
75 intc->iar, intc->mer);
79 static void disable_one_interrupt(int irq)
85 intc->ier = (mask & ~offset);
87 printf ("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask,
89 printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
90 intc->iar, intc->mer);
94 /* adding new handler for interrupt */
95 void install_interrupt_handler (int irq, interrupt_handler_t * hdlr, void *arg)
97 struct irq_action *act;
98 /* irq out of range */
99 if ((irq < 0) || (irq > irq_no)) {
100 puts ("IRQ out of range\n");
104 if (hdlr) { /* enable */
108 enable_one_interrupt (irq);
109 } else { /* disable */
110 act->handler = (interrupt_handler_t *) def_hdlr;
111 act->arg = (void *)irq;
112 disable_one_interrupt (irq);
116 /* initialization interrupt controller - hardware */
117 static void intc_init(void)
121 intc->iar = 0xFFFFFFFF;
122 /* XIntc_Start - hw_interrupt enable and all interrupt enable */
125 printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
126 intc->iar, intc->mer);
130 int interrupts_init(void)
134 #if defined(CONFIG_SYS_INTC_0_ADDR) && defined(CONFIG_SYS_INTC_0_NUM)
135 intc = (microblaze_intc_t *) (CONFIG_SYS_INTC_0_ADDR);
136 irq_no = CONFIG_SYS_INTC_0_NUM;
139 vecs = calloc(1, sizeof(struct irq_action) * irq_no);
141 puts("Interrupt vector allocation failed\n");
145 /* initialize irq list */
146 for (i = 0; i < irq_no; i++) {
147 vecs[i].handler = (interrupt_handler_t *) def_hdlr;
148 vecs[i].arg = (void *)i;
151 /* initialize intc controller */
155 puts("Undefined interrupt controller\n");
160 void interrupt_handler (void)
162 int irqs = intc->ivr; /* find active interrupt */
166 printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
167 intc->iar, intc->mer);
169 printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
171 struct irq_action *act = vecs + irqs;
175 ("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n",
176 act->handler, act->count, act->arg);
178 act->handler (act->arg);
181 intc->iar = mask << irqs;
184 printf ("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr,
185 intc->ier, intc->iar, intc->mer);
187 printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
191 #if defined(CONFIG_CMD_IRQ)
192 int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, const char *argv[])
195 struct irq_action *act = vecs;
198 puts("\nInterrupt-Information:\n\n"
199 "Nr Routine Arg Count\n"
200 "-----------------------------\n");
202 for (i = 0; i < irq_no; i++) {
203 if (act->handler != (interrupt_handler_t *) def_hdlr) {
204 printf("%02d %08x %08x %d\n", i,
205 (int)act->handler, (int)act->arg,
212 puts("Undefined interrupt controller\n");