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)
19 debug("Enable interrupts for the whole CPU\n");
23 int disable_interrupts(void)
29 return (msr & 0x2) != 0;
32 static struct irq_action *vecs;
35 /* mapping structure to interrupt controller */
36 microblaze_intc_t *intc;
39 static void def_hdlr(void)
44 static void enable_one_interrupt(int irq)
51 intc->ier = (mask | offset);
53 debug("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask,
55 debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
56 intc->iar, intc->mer);
59 static void disable_one_interrupt(int irq)
66 intc->ier = (mask & ~offset);
68 debug("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask,
70 debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
71 intc->iar, intc->mer);
74 int install_interrupt_handler(int irq, interrupt_handler_t *hdlr, void *arg)
76 struct irq_action *act;
78 /* irq out of range */
79 if ((irq < 0) || (irq > irq_no)) {
80 puts("IRQ out of range\n");
84 if (hdlr) { /* enable */
88 enable_one_interrupt(irq);
93 act->handler = (interrupt_handler_t *)def_hdlr;
94 act->arg = (void *)irq;
95 disable_one_interrupt(irq);
99 /* initialization interrupt controller - hardware */
100 static void intc_init(void)
104 intc->iar = 0xFFFFFFFF;
105 /* XIntc_Start - hw_interrupt enable and all interrupt enable */
108 debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
109 intc->iar, intc->mer);
112 int interrupt_init(void)
116 #if defined(CONFIG_SYS_INTC_0_ADDR) && defined(CONFIG_SYS_INTC_0_NUM)
117 intc = (microblaze_intc_t *)CONFIG_SYS_INTC_0_ADDR;
118 irq_no = CONFIG_SYS_INTC_0_NUM;
121 vecs = calloc(1, sizeof(struct irq_action) * irq_no);
123 puts("Interrupt vector allocation failed\n");
127 /* initialize irq list */
128 for (i = 0; i < irq_no; i++) {
129 vecs[i].handler = (interrupt_handler_t *)def_hdlr;
130 vecs[i].arg = (void *)i;
133 /* initialize intc controller */
137 puts("Undefined interrupt controller\n");
142 void interrupt_handler(void)
144 int irqs = intc->ivr; /* find active interrupt */
147 struct irq_action *act = vecs + irqs;
149 debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
150 intc->iar, intc->mer);
154 debug("Interrupt handler on %x line, r14 %x\n", irqs, value);
156 debug("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n",
157 (u32)act->handler, act->count, (u32)act->arg);
158 act->handler(act->arg);
161 intc->iar = mask << irqs;
163 debug("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr,
164 intc->ier, intc->iar, intc->mer);
168 debug("Interrupt handler on %x line, r14 %x\n", irqs, value);
171 #if defined(CONFIG_CMD_IRQ)
172 int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, const char *argv[])
175 struct irq_action *act = vecs;
178 puts("\nInterrupt-Information:\n\n"
179 "Nr Routine Arg Count\n"
180 "-----------------------------\n");
182 for (i = 0; i < irq_no; i++) {
183 if (act->handler != (interrupt_handler_t *)def_hdlr) {
184 printf("%02d %08x %08x %d\n", i,
185 (int)act->handler, (int)act->arg,
192 puts("Undefined interrupt controller\n");