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 void enable_interrupts(void)
40 int disable_interrupts(void)
46 return (msr & 0x2) != 0;
49 static struct irq_action *vecs;
52 /* mapping structure to interrupt controller */
53 microblaze_intc_t *intc;
56 static void def_hdlr(void)
61 static void enable_one_interrupt(int irq)
68 intc->ier = (mask | offset);
70 printf("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask,
72 printf("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
73 intc->iar, intc->mer);
77 static void disable_one_interrupt(int irq)
84 intc->ier = (mask & ~offset);
86 printf("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask,
88 printf("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
89 intc->iar, intc->mer);
93 int install_interrupt_handler(int irq, interrupt_handler_t *hdlr, void *arg)
95 struct irq_action *act;
97 /* irq out of range */
98 if ((irq < 0) || (irq > irq_no)) {
99 puts("IRQ out of range\n");
103 if (hdlr) { /* enable */
107 enable_one_interrupt (irq);
112 act->handler = (interrupt_handler_t *) def_hdlr;
113 act->arg = (void *)irq;
114 disable_one_interrupt(irq);
118 /* initialization interrupt controller - hardware */
119 static void intc_init(void)
123 intc->iar = 0xFFFFFFFF;
124 /* XIntc_Start - hw_interrupt enable and all interrupt enable */
127 printf("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
128 intc->iar, intc->mer);
132 int interrupts_init(void)
136 #if defined(CONFIG_SYS_INTC_0_ADDR) && defined(CONFIG_SYS_INTC_0_NUM)
137 intc = (microblaze_intc_t *) (CONFIG_SYS_INTC_0_ADDR);
138 irq_no = CONFIG_SYS_INTC_0_NUM;
141 vecs = calloc(1, sizeof(struct irq_action) * irq_no);
143 puts("Interrupt vector allocation failed\n");
147 /* initialize irq list */
148 for (i = 0; i < irq_no; i++) {
149 vecs[i].handler = (interrupt_handler_t *) def_hdlr;
150 vecs[i].arg = (void *)i;
153 /* initialize intc controller */
157 puts("Undefined interrupt controller\n");
162 void interrupt_handler(void)
164 int irqs = intc->ivr; /* find active interrupt */
168 printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
169 intc->iar, intc->mer);
171 printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
173 struct irq_action *act = vecs + irqs;
177 ("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n",
178 act->handler, act->count, act->arg);
180 act->handler (act->arg);
183 intc->iar = mask << irqs;
186 printf ("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr,
187 intc->ier, intc->iar, intc->mer);
189 printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
193 #if defined(CONFIG_CMD_IRQ)
194 int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, const char *argv[])
197 struct irq_action *act = vecs;
200 puts("\nInterrupt-Information:\n\n"
201 "Nr Routine Arg Count\n"
202 "-----------------------------\n");
204 for (i = 0; i < irq_no; i++) {
205 if (act->handler != (interrupt_handler_t *) def_hdlr) {
206 printf("%02d %08x %08x %d\n", i,
207 (int)act->handler, (int)act->arg,
214 puts("Undefined interrupt controller\n");