1 // SPDX-License-Identifier: GPL-2.0+
4 * Graeme Russ, <graeme.russ@gmail.com>
7 * Daniel Hellstrom, Gaisler Research, <daniel@gaisler.com>
10 * Detlev Zundel, DENX Software Engineering, <dzu@denx.de>
13 * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
16 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
19 * Josh Huber, Mission Critical Linux, Inc, <huber@mclx.com>
23 * This file contains the high-level API for the interrupt sub-system
24 * of the x86 port of U-Boot. Most of the functionality has been
25 * shamelessly stolen from the leon2 / leon3 ports of U-Boot.
26 * Daniel Hellstrom, Detlev Zundel, Wolfgang Denk and Josh Huber are
27 * credited for the corresponding work on those ports. The original
28 * interrupt handling routines for the x86 port were written by
34 #include <asm/interrupt.h>
36 #if !CONFIG_IS_ENABLED(X86_64)
39 interrupt_handler_t *handler;
44 static struct irq_action irq_handlers[SYS_NUM_IRQS] = { {0} };
45 static int spurious_irq_cnt;
46 static int spurious_irq;
48 void irq_install_handler(int irq, interrupt_handler_t *handler, void *arg)
52 if (irq < 0 || irq >= SYS_NUM_IRQS) {
53 printf("irq_install_handler: bad irq number %d\n", irq);
57 if (irq_handlers[irq].handler != NULL)
58 printf("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
60 (ulong) irq_handlers[irq].handler);
62 status = disable_interrupts();
64 irq_handlers[irq].handler = handler;
65 irq_handlers[irq].arg = arg;
66 irq_handlers[irq].count = 0;
68 if (CONFIG_IS_ENABLED(I8259_PIC))
77 void irq_free_handler(int irq)
81 if (irq < 0 || irq >= SYS_NUM_IRQS) {
82 printf("irq_free_handler: bad irq number %d\n", irq);
86 status = disable_interrupts();
88 if (CONFIG_IS_ENABLED(I8259_PIC))
91 irq_handlers[irq].handler = NULL;
92 irq_handlers[irq].arg = NULL;
100 void do_irq(int hw_irq)
102 int irq = hw_irq - 0x20;
104 if (irq < 0 || irq >= SYS_NUM_IRQS) {
105 printf("do_irq: bad irq number %d\n", irq);
109 if (irq_handlers[irq].handler) {
110 if (CONFIG_IS_ENABLED(I8259_PIC))
113 irq_handlers[irq].handler(irq_handlers[irq].arg);
114 irq_handlers[irq].count++;
116 if (CONFIG_IS_ENABLED(I8259_PIC)) {
121 if ((irq & 7) != 7) {
129 #if defined(CONFIG_CMD_IRQ)
130 int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
132 #if !CONFIG_IS_ENABLED(X86_64)
135 printf("Spurious IRQ: %u, last unknown IRQ: %d\n",
136 spurious_irq_cnt, spurious_irq);
138 printf("Interrupt-Information:\n");
139 printf("Nr Routine Arg Count\n");
141 for (irq = 0; irq < SYS_NUM_IRQS; irq++) {
142 if (irq_handlers[irq].handler != NULL) {
143 printf("%02d %08lx %08lx %d\n",
145 (ulong)irq_handlers[irq].handler,
146 (ulong)irq_handlers[irq].arg,
147 irq_handlers[irq].count);