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 * SPDX-License-Identifier: GPL-2.0+
14 #include <asm/microblaze_intc.h>
17 void enable_interrupts(void)
22 int disable_interrupts(void)
28 return (msr & 0x2) != 0;
31 static struct irq_action *vecs;
34 /* mapping structure to interrupt controller */
35 microblaze_intc_t *intc;
38 static void def_hdlr(void)
43 static void enable_one_interrupt(int irq)
50 intc->ier = (mask | offset);
52 debug("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask,
54 debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
55 intc->iar, intc->mer);
58 static void disable_one_interrupt(int irq)
65 intc->ier = (mask & ~offset);
67 debug("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask,
69 debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
70 intc->iar, intc->mer);
73 int install_interrupt_handler(int irq, interrupt_handler_t *hdlr, void *arg)
75 struct irq_action *act;
77 /* irq out of range */
78 if ((irq < 0) || (irq > irq_no)) {
79 puts("IRQ out of range\n");
83 if (hdlr) { /* enable */
87 enable_one_interrupt (irq);
92 act->handler = (interrupt_handler_t *) def_hdlr;
93 act->arg = (void *)irq;
94 disable_one_interrupt(irq);
98 /* initialization interrupt controller - hardware */
99 static void intc_init(void)
103 intc->iar = 0xFFFFFFFF;
104 /* XIntc_Start - hw_interrupt enable and all interrupt enable */
107 debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
108 intc->iar, intc->mer);
111 int interrupts_init(void)
115 #if defined(CONFIG_SYS_INTC_0_ADDR) && defined(CONFIG_SYS_INTC_0_NUM)
116 intc = (microblaze_intc_t *) (CONFIG_SYS_INTC_0_ADDR);
117 irq_no = CONFIG_SYS_INTC_0_NUM;
120 vecs = calloc(1, sizeof(struct irq_action) * irq_no);
122 puts("Interrupt vector allocation failed\n");
126 /* initialize irq list */
127 for (i = 0; i < irq_no; i++) {
128 vecs[i].handler = (interrupt_handler_t *) def_hdlr;
129 vecs[i].arg = (void *)i;
132 /* initialize intc controller */
136 puts("Undefined interrupt controller\n");
141 void interrupt_handler(void)
143 int irqs = intc->ivr; /* find active interrupt */
146 struct irq_action *act = vecs + irqs;
148 debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
149 intc->iar, intc->mer);
153 debug("Interrupt handler on %x line, r14 %x\n", irqs, value);
155 debug("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n",
156 (u32)act->handler, act->count, (u32)act->arg);
157 act->handler (act->arg);
160 intc->iar = mask << irqs;
162 debug("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr,
163 intc->ier, intc->iar, intc->mer);
167 debug("Interrupt handler on %x line, r14 %x\n", irqs, value);
170 #if defined(CONFIG_CMD_IRQ)
171 int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, const char *argv[])
174 struct irq_action *act = vecs;
177 puts("\nInterrupt-Information:\n\n"
178 "Nr Routine Arg Count\n"
179 "-----------------------------\n");
181 for (i = 0; i < irq_no; i++) {
182 if (act->handler != (interrupt_handler_t *) def_hdlr) {
183 printf("%02d %08x %08x %d\n", i,
184 (int)act->handler, (int)act->arg,
191 puts("Undefined interrupt controller\n");