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>
19 void enable_interrupts(void)
24 int disable_interrupts(void)
30 return (msr & 0x2) != 0;
33 static struct irq_action *vecs;
36 /* mapping structure to interrupt controller */
37 microblaze_intc_t *intc;
40 static void def_hdlr(void)
45 static void enable_one_interrupt(int irq)
52 intc->ier = (mask | offset);
54 printf("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask,
56 printf("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
57 intc->iar, intc->mer);
61 static void disable_one_interrupt(int irq)
68 intc->ier = (mask & ~offset);
70 printf("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask,
72 printf("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
73 intc->iar, intc->mer);
77 int install_interrupt_handler(int irq, interrupt_handler_t *hdlr, void *arg)
79 struct irq_action *act;
81 /* irq out of range */
82 if ((irq < 0) || (irq > irq_no)) {
83 puts("IRQ out of range\n");
87 if (hdlr) { /* enable */
91 enable_one_interrupt (irq);
96 act->handler = (interrupt_handler_t *) def_hdlr;
97 act->arg = (void *)irq;
98 disable_one_interrupt(irq);
102 /* initialization interrupt controller - hardware */
103 static void intc_init(void)
107 intc->iar = 0xFFFFFFFF;
108 /* XIntc_Start - hw_interrupt enable and all interrupt enable */
111 printf("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
112 intc->iar, intc->mer);
116 int interrupts_init(void)
120 #if defined(CONFIG_SYS_INTC_0_ADDR) && defined(CONFIG_SYS_INTC_0_NUM)
121 intc = (microblaze_intc_t *) (CONFIG_SYS_INTC_0_ADDR);
122 irq_no = CONFIG_SYS_INTC_0_NUM;
125 vecs = calloc(1, sizeof(struct irq_action) * irq_no);
127 puts("Interrupt vector allocation failed\n");
131 /* initialize irq list */
132 for (i = 0; i < irq_no; i++) {
133 vecs[i].handler = (interrupt_handler_t *) def_hdlr;
134 vecs[i].arg = (void *)i;
137 /* initialize intc controller */
141 puts("Undefined interrupt controller\n");
146 void interrupt_handler(void)
148 int irqs = intc->ivr; /* find active interrupt */
152 printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier,
153 intc->iar, intc->mer);
155 printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
157 struct irq_action *act = vecs + irqs;
161 ("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n",
162 act->handler, act->count, act->arg);
164 act->handler (act->arg);
167 intc->iar = mask << irqs;
170 printf ("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr,
171 intc->ier, intc->iar, intc->mer);
173 printf ("Interrupt handler on %x line, r14 %x\n", irqs, value);
177 #if defined(CONFIG_CMD_IRQ)
178 int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, const char *argv[])
181 struct irq_action *act = vecs;
184 puts("\nInterrupt-Information:\n\n"
185 "Nr Routine Arg Count\n"
186 "-----------------------------\n");
188 for (i = 0; i < irq_no; i++) {
189 if (act->handler != (interrupt_handler_t *) def_hdlr) {
190 printf("%02d %08x %08x %d\n", i,
191 (int)act->handler, (int)act->arg,
198 puts("Undefined interrupt controller\n");