blob: d3ae6d9694aaf0d0e074a1fef74568f6a78a507b [file] [log] [blame]
Graeme Russabf0cd32009-02-24 21:13:40 +11001/*
2 * (C) Copyright 2009
Graeme Russdbf71152011-04-13 19:43:26 +10003 * Graeme Russ, <graeme.russ@gmail.com>
Graeme Russabf0cd32009-02-24 21:13:40 +11004 *
5 * (C) Copyright 2007
Graeme Russdbf71152011-04-13 19:43:26 +10006 * Daniel Hellstrom, Gaisler Research, <daniel@gaisler.com>
Graeme Russabf0cd32009-02-24 21:13:40 +11007 *
8 * (C) Copyright 2006
Graeme Russdbf71152011-04-13 19:43:26 +10009 * Detlev Zundel, DENX Software Engineering, <dzu@denx.de>
Graeme Russabf0cd32009-02-24 21:13:40 +110010 *
11 * (C) Copyright -2003
Graeme Russdbf71152011-04-13 19:43:26 +100012 * Wolfgang Denk, DENX Software Engineering, <wd@denx.de>
Graeme Russabf0cd32009-02-24 21:13:40 +110013 *
14 * (C) Copyright 2002
Albert ARIBAUDfa82f872011-08-04 18:45:45 +020015 * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se>
Graeme Russabf0cd32009-02-24 21:13:40 +110016 *
17 * (C) Copyright 2001
Graeme Russdbf71152011-04-13 19:43:26 +100018 * Josh Huber, Mission Critical Linux, Inc, <huber@mclx.com>
Graeme Russabf0cd32009-02-24 21:13:40 +110019 *
Wolfgang Denk1a459662013-07-08 09:37:19 +020020 * SPDX-License-Identifier: GPL-2.0+
Graeme Russabf0cd32009-02-24 21:13:40 +110021 */
22
23/*
24 * This file contains the high-level API for the interrupt sub-system
Graeme Russdbf71152011-04-13 19:43:26 +100025 * of the x86 port of U-Boot. Most of the functionality has been
Graeme Russabf0cd32009-02-24 21:13:40 +110026 * shamelessly stolen from the leon2 / leon3 ports of U-Boot.
27 * Daniel Hellstrom, Detlev Zundel, Wolfgang Denk and Josh Huber are
28 * credited for the corresponding work on those ports. The original
Graeme Russdbf71152011-04-13 19:43:26 +100029 * interrupt handling routines for the x86 port were written by
Albert ARIBAUDfa82f872011-08-04 18:45:45 +020030 * Daniel Engström
Graeme Russabf0cd32009-02-24 21:13:40 +110031 */
32
33#include <common.h>
34#include <asm/interrupt.h>
35
Simon Glassc2bf0df2017-01-16 07:04:14 -070036#if !CONFIG_IS_ENABLED(X86_64)
37
Graeme Russabf0cd32009-02-24 21:13:40 +110038struct irq_action {
39 interrupt_handler_t *handler;
40 void *arg;
41 unsigned int count;
42};
43
Bin Meng6c505272015-10-22 19:13:26 -070044static struct irq_action irq_handlers[SYS_NUM_IRQS] = { {0} };
Graeme Russ83088af2011-11-08 02:33:15 +000045static int spurious_irq_cnt;
46static int spurious_irq;
Graeme Russabf0cd32009-02-24 21:13:40 +110047
48void irq_install_handler(int irq, interrupt_handler_t *handler, void *arg)
49{
50 int status;
51
Bin Meng6c505272015-10-22 19:13:26 -070052 if (irq < 0 || irq >= SYS_NUM_IRQS) {
Graeme Russabf0cd32009-02-24 21:13:40 +110053 printf("irq_install_handler: bad irq number %d\n", irq);
54 return;
55 }
56
57 if (irq_handlers[irq].handler != NULL)
58 printf("irq_install_handler: 0x%08lx replacing 0x%08lx\n",
Graeme Russ83088af2011-11-08 02:33:15 +000059 (ulong) handler,
60 (ulong) irq_handlers[irq].handler);
Graeme Russabf0cd32009-02-24 21:13:40 +110061
Graeme Russ83088af2011-11-08 02:33:15 +000062 status = disable_interrupts();
Graeme Russabf0cd32009-02-24 21:13:40 +110063
Graeme Russ1c409bc2009-11-24 20:04:21 +110064 irq_handlers[irq].handler = handler;
Graeme Russabf0cd32009-02-24 21:13:40 +110065 irq_handlers[irq].arg = arg;
66 irq_handlers[irq].count = 0;
67
68 unmask_irq(irq);
69
70 if (status)
71 enable_interrupts();
72
73 return;
74}
75
76void irq_free_handler(int irq)
77{
78 int status;
79
Bin Meng6c505272015-10-22 19:13:26 -070080 if (irq < 0 || irq >= SYS_NUM_IRQS) {
Graeme Russabf0cd32009-02-24 21:13:40 +110081 printf("irq_free_handler: bad irq number %d\n", irq);
82 return;
83 }
84
Graeme Russ83088af2011-11-08 02:33:15 +000085 status = disable_interrupts();
Graeme Russabf0cd32009-02-24 21:13:40 +110086
87 mask_irq(irq);
88
89 irq_handlers[irq].handler = NULL;
90 irq_handlers[irq].arg = NULL;
91
92 if (status)
93 enable_interrupts();
94
95 return;
96}
97
Graeme Russ564a9982009-11-24 20:04:18 +110098void do_irq(int hw_irq)
Graeme Russabf0cd32009-02-24 21:13:40 +110099{
Graeme Russ564a9982009-11-24 20:04:18 +1100100 int irq = hw_irq - 0x20;
101
Bin Meng6c505272015-10-22 19:13:26 -0700102 if (irq < 0 || irq >= SYS_NUM_IRQS) {
Graeme Russabf0cd32009-02-24 21:13:40 +1100103 printf("do_irq: bad irq number %d\n", irq);
104 return;
105 }
106
107 if (irq_handlers[irq].handler) {
108 mask_irq(irq);
109
110 irq_handlers[irq].handler(irq_handlers[irq].arg);
111 irq_handlers[irq].count++;
112
113 unmask_irq(irq);
114 specific_eoi(irq);
115
116 } else {
117 if ((irq & 7) != 7) {
118 spurious_irq_cnt++;
119 spurious_irq = irq;
120 }
121 }
122}
Simon Glassc2bf0df2017-01-16 07:04:14 -0700123#endif
Graeme Russabf0cd32009-02-24 21:13:40 +1100124
125#if defined(CONFIG_CMD_IRQ)
Wolfgang Denk54841ab2010-06-28 22:00:46 +0200126int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
Graeme Russabf0cd32009-02-24 21:13:40 +1100127{
Simon Glassc2bf0df2017-01-16 07:04:14 -0700128#if !CONFIG_IS_ENABLED(X86_64)
Graeme Russabf0cd32009-02-24 21:13:40 +1100129 int irq;
130
131 printf("Spurious IRQ: %u, last unknown IRQ: %d\n",
Graeme Russ83088af2011-11-08 02:33:15 +0000132 spurious_irq_cnt, spurious_irq);
Graeme Russabf0cd32009-02-24 21:13:40 +1100133
Graeme Russ83088af2011-11-08 02:33:15 +0000134 printf("Interrupt-Information:\n");
135 printf("Nr Routine Arg Count\n");
Graeme Russabf0cd32009-02-24 21:13:40 +1100136
Bin Meng6c505272015-10-22 19:13:26 -0700137 for (irq = 0; irq < SYS_NUM_IRQS; irq++) {
Graeme Russabf0cd32009-02-24 21:13:40 +1100138 if (irq_handlers[irq].handler != NULL) {
Graeme Russ83088af2011-11-08 02:33:15 +0000139 printf("%02d %08lx %08lx %d\n",
Graeme Russabf0cd32009-02-24 21:13:40 +1100140 irq,
141 (ulong)irq_handlers[irq].handler,
142 (ulong)irq_handlers[irq].arg,
143 irq_handlers[irq].count);
144 }
145 }
Simon Glassc2bf0df2017-01-16 07:04:14 -0700146#endif
Graeme Russabf0cd32009-02-24 21:13:40 +1100147
148 return 0;
149}
150#endif