blob: 297067df71052b8098569fe695433f7fc4543361 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Graeme Russ77290ee2009-02-24 21:13:40 +11002/*
3 * (C) Copyright 2009
Graeme Russ45fc1d82011-04-13 19:43:26 +10004 * Graeme Russ, <graeme.russ@gmail.com>
Graeme Russ77290ee2009-02-24 21:13:40 +11005 *
6 * (C) Copyright 2007
Graeme Russ45fc1d82011-04-13 19:43:26 +10007 * Daniel Hellstrom, Gaisler Research, <daniel@gaisler.com>
Graeme Russ77290ee2009-02-24 21:13:40 +11008 *
9 * (C) Copyright 2006
Graeme Russ45fc1d82011-04-13 19:43:26 +100010 * Detlev Zundel, DENX Software Engineering, <dzu@denx.de>
Graeme Russ77290ee2009-02-24 21:13:40 +110011 *
12 * (C) Copyright -2003
Graeme Russ45fc1d82011-04-13 19:43:26 +100013 * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
Graeme Russ77290ee2009-02-24 21:13:40 +110014 *
15 * (C) Copyright 2002
Albert ARIBAUD60fbc8d2011-08-04 18:45:45 +020016 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
Graeme Russ77290ee2009-02-24 21:13:40 +110017 *
18 * (C) Copyright 2001
Graeme Russ45fc1d82011-04-13 19:43:26 +100019 * Josh Huber, Mission Critical Linux, Inc, <huber@mclx.com>
Graeme Russ77290ee2009-02-24 21:13:40 +110020 */
21
22/*
23 * This file contains the high-level API for the interrupt sub-system
Graeme Russ45fc1d82011-04-13 19:43:26 +100024 * of the x86 port of U-Boot. Most of the functionality has been
Graeme Russ77290ee2009-02-24 21:13:40 +110025 * 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
Graeme Russ45fc1d82011-04-13 19:43:26 +100028 * interrupt handling routines for the x86 port were written by
Albert ARIBAUD60fbc8d2011-08-04 18:45:45 +020029 * Daniel Engström
Graeme Russ77290ee2009-02-24 21:13:40 +110030 */
31
32#include <common.h>
33#include <asm/interrupt.h>
34
Simon Glassf5156f02017-01-16 07:04:14 -070035#if !CONFIG_IS_ENABLED(X86_64)
36
Graeme Russ77290ee2009-02-24 21:13:40 +110037struct irq_action {
38 interrupt_handler_t *handler;
39 void *arg;
40 unsigned int count;
41};
42
Bin Menge7a76e52015-10-22 19:13:26 -070043static struct irq_action irq_handlers[SYS_NUM_IRQS] = { {0} };
Graeme Russ883c6032011-11-08 02:33:15 +000044static int spurious_irq_cnt;
45static int spurious_irq;
Graeme Russ77290ee2009-02-24 21:13:40 +110046
47void irq_install_handler(int irq, interrupt_handler_t *handler, void *arg)
48{
49 int status;
50
Bin Menge7a76e52015-10-22 19:13:26 -070051 if (irq < 0 || irq >= SYS_NUM_IRQS) {
Graeme Russ77290ee2009-02-24 21:13:40 +110052 printf("irq_install_handler: bad irq number %d\n", irq);
53 return;
54 }
55
56 if (irq_handlers[irq].handler != NULL)
57 printf("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
Graeme Russ883c6032011-11-08 02:33:15 +000058 (ulong) handler,
59 (ulong) irq_handlers[irq].handler);
Graeme Russ77290ee2009-02-24 21:13:40 +110060
Graeme Russ883c6032011-11-08 02:33:15 +000061 status = disable_interrupts();
Graeme Russ77290ee2009-02-24 21:13:40 +110062
Graeme Russ078395c2009-11-24 20:04:21 +110063 irq_handlers[irq].handler = handler;
Graeme Russ77290ee2009-02-24 21:13:40 +110064 irq_handlers[irq].arg = arg;
65 irq_handlers[irq].count = 0;
66
67 unmask_irq(irq);
68
69 if (status)
70 enable_interrupts();
71
72 return;
73}
74
75void irq_free_handler(int irq)
76{
77 int status;
78
Bin Menge7a76e52015-10-22 19:13:26 -070079 if (irq < 0 || irq >= SYS_NUM_IRQS) {
Graeme Russ77290ee2009-02-24 21:13:40 +110080 printf("irq_free_handler: bad irq number %d\n", irq);
81 return;
82 }
83
Graeme Russ883c6032011-11-08 02:33:15 +000084 status = disable_interrupts();
Graeme Russ77290ee2009-02-24 21:13:40 +110085
86 mask_irq(irq);
87
88 irq_handlers[irq].handler = NULL;
89 irq_handlers[irq].arg = NULL;
90
91 if (status)
92 enable_interrupts();
93
94 return;
95}
96
Graeme Russd11b0852009-11-24 20:04:18 +110097void do_irq(int hw_irq)
Graeme Russ77290ee2009-02-24 21:13:40 +110098{
Graeme Russd11b0852009-11-24 20:04:18 +110099 int irq = hw_irq - 0x20;
100
Bin Menge7a76e52015-10-22 19:13:26 -0700101 if (irq < 0 || irq >= SYS_NUM_IRQS) {
Graeme Russ77290ee2009-02-24 21:13:40 +1100102 printf("do_irq: bad irq number %d\n", irq);
103 return;
104 }
105
106 if (irq_handlers[irq].handler) {
107 mask_irq(irq);
108
109 irq_handlers[irq].handler(irq_handlers[irq].arg);
110 irq_handlers[irq].count++;
111
112 unmask_irq(irq);
113 specific_eoi(irq);
114
115 } else {
116 if ((irq & 7) != 7) {
117 spurious_irq_cnt++;
118 spurious_irq = irq;
119 }
120 }
121}
Simon Glassf5156f02017-01-16 07:04:14 -0700122#endif
Graeme Russ77290ee2009-02-24 21:13:40 +1100123
124#if defined(CONFIG_CMD_IRQ)
Wolfgang Denk6262d0212010-06-28 22:00:46 +0200125int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Graeme Russ77290ee2009-02-24 21:13:40 +1100126{
Simon Glassf5156f02017-01-16 07:04:14 -0700127#if !CONFIG_IS_ENABLED(X86_64)
Graeme Russ77290ee2009-02-24 21:13:40 +1100128 int irq;
129
130 printf("Spurious IRQ: %u, last unknown IRQ: %d\n",
Graeme Russ883c6032011-11-08 02:33:15 +0000131 spurious_irq_cnt, spurious_irq);
Graeme Russ77290ee2009-02-24 21:13:40 +1100132
Graeme Russ883c6032011-11-08 02:33:15 +0000133 printf("Interrupt-Information:\n");
134 printf("Nr Routine Arg Count\n");
Graeme Russ77290ee2009-02-24 21:13:40 +1100135
Bin Menge7a76e52015-10-22 19:13:26 -0700136 for (irq = 0; irq < SYS_NUM_IRQS; irq++) {
Graeme Russ77290ee2009-02-24 21:13:40 +1100137 if (irq_handlers[irq].handler != NULL) {
Graeme Russ883c6032011-11-08 02:33:15 +0000138 printf("%02d %08lx %08lx %d\n",
Graeme Russ77290ee2009-02-24 21:13:40 +1100139 irq,
140 (ulong)irq_handlers[irq].handler,
141 (ulong)irq_handlers[irq].arg,
142 irq_handlers[irq].count);
143 }
144 }
Simon Glassf5156f02017-01-16 07:04:14 -0700145#endif
Graeme Russ77290ee2009-02-24 21:13:40 +1100146
147 return 0;
148}
149#endif