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>
12 #include <asm/nios2.h>
13 #include <asm/types.h>
15 #include <asm/ptrace.h>
17 /*************************************************************************/
19 interrupt_handler_t *handler;
24 static struct irq_action vecs[32];
26 int disable_interrupts (void)
28 int val = rdctl (CTL_STATUS);
29 wrctl (CTL_STATUS, val & ~STATUS_IE);
30 return (val & STATUS_IE);
33 void enable_interrupts( void )
35 int val = rdctl (CTL_STATUS);
36 wrctl (CTL_STATUS, val | STATUS_IE);
39 void external_interrupt (struct pt_regs *regs)
42 struct irq_action *act;
44 /* Evaluate only irqs that are both enabled AND pending */
45 irqs = rdctl (CTL_IENABLE) & rdctl (CTL_IPENDING);
48 /* Assume (as does the Nios2 HAL) that bit 0 is highest
49 * priority. NOTE: There is ALWAYS a handler assigned
50 * (the default if no other).
54 act->handler (act->arg);
62 static void def_hdlr (void *arg)
64 unsigned irqs = rdctl (CTL_IENABLE);
66 /* Disable the individual interrupt -- with gratuitous
69 irqs &= ~(1 << (int)arg);
70 wrctl (CTL_IENABLE, irqs);
71 printf ("WARNING: Disabling unhandled interrupt: %d\n",
75 /*************************************************************************/
76 void irq_install_handler (int irq, interrupt_handler_t *hdlr, void *arg)
80 struct irq_action *act;
81 unsigned ena = rdctl (CTL_IENABLE);
83 if ((irq < 0) || (irq > 31))
87 flag = disable_interrupts ();
91 ena |= (1 << irq); /* enable */
93 act->handler = def_hdlr;
94 act->arg = (void *)irq;
95 ena &= ~(1 << irq); /* disable */
97 wrctl (CTL_IENABLE, ena);
98 if (flag) enable_interrupts ();
102 int interrupt_init (void)
106 /* Assign the default handler to all */
107 for (i = 0; i < 32; i++) {
108 vecs[i].handler = def_hdlr;
109 vecs[i].arg = (void *)i;
113 enable_interrupts ();
118 /*************************************************************************/
119 #if defined(CONFIG_CMD_IRQ)
120 int do_irqinfo (cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
123 struct irq_action *act = vecs;
125 printf ("\nInterrupt-Information:\n\n");
126 printf ("Nr Routine Arg Count\n");
127 printf ("-----------------------------\n");
129 for (i=0; i<32; i++) {
130 if (act->handler != def_hdlr) {
131 printf ("%02d %08lx %08lx %d\n",