1 // SPDX-License-Identifier: GPL-2.0+
3 * (C) Copyright 2000-2002
4 * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
6 * (C) Copyright 2004, Psyent Corporation <www.psyent.com>
7 * Scott McNutt <smcnutt@psyent.com>
13 #include <asm/nios2.h>
14 #include <asm/types.h>
16 #include <asm/ptrace.h>
18 /*************************************************************************/
20 interrupt_handler_t *handler;
25 static struct irq_action vecs[32];
27 int disable_interrupts(void)
29 int val = rdctl (CTL_STATUS);
30 wrctl (CTL_STATUS, val & ~STATUS_IE);
31 return (val & STATUS_IE);
34 void enable_interrupts( void )
36 int val = rdctl (CTL_STATUS);
37 wrctl (CTL_STATUS, val | STATUS_IE);
40 void external_interrupt(struct pt_regs *regs)
43 struct irq_action *act;
45 /* Evaluate only irqs that are both enabled AND pending */
46 irqs = rdctl (CTL_IENABLE) & rdctl (CTL_IPENDING);
49 /* Assume (as does the Nios2 HAL) that bit 0 is highest
50 * priority. NOTE: There is ALWAYS a handler assigned
51 * (the default if no other).
55 act->handler (act->arg);
63 static void def_hdlr (void *arg)
65 unsigned irqs = rdctl (CTL_IENABLE);
67 /* Disable the individual interrupt -- with gratuitous
70 irqs &= ~(1 << (int)arg);
71 wrctl (CTL_IENABLE, irqs);
72 printf ("WARNING: Disabling unhandled interrupt: %d\n",
76 /*************************************************************************/
77 void irq_install_handler(int irq, interrupt_handler_t *hdlr, void *arg)
81 struct irq_action *act;
82 unsigned ena = rdctl (CTL_IENABLE);
84 if ((irq < 0) || (irq > 31))
88 flag = disable_interrupts();
92 ena |= (1 << irq); /* enable */
94 act->handler = def_hdlr;
95 act->arg = (void *)irq;
96 ena &= ~(1 << irq); /* disable */
98 wrctl (CTL_IENABLE, ena);
99 if (flag) enable_interrupts();
103 int interrupt_init(void)
107 /* Assign the default handler to all */
108 for (i = 0; i < 32; i++) {
109 vecs[i].handler = def_hdlr;
110 vecs[i].arg = (void *)i;
119 /*************************************************************************/
120 #if defined(CONFIG_CMD_IRQ)
121 int do_irqinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
124 struct irq_action *act = vecs;
126 printf ("\nInterrupt-Information:\n\n");
127 printf ("Nr Routine Arg Count\n");
128 printf ("-----------------------------\n");
130 for (i=0; i<32; i++) {
131 if (act->handler != def_hdlr) {
132 printf ("%02d %08lx %08lx %d\n",