]> Git Repo - J-u-boot.git/blame - arch/x86/lib/interrupts.c
command: Remove the cmd_tbl_t typedef
[J-u-boot.git] / arch / x86 / lib / interrupts.c
CommitLineData
83d290c5 1// SPDX-License-Identifier: GPL-2.0+
abf0cd3d
GR
2/*
3 * (C) Copyright 2009
dbf7115a 4 * Graeme Russ, <[email protected]>
abf0cd3d
GR
5 *
6 * (C) Copyright 2007
dbf7115a 7 * Daniel Hellstrom, Gaisler Research, <[email protected]>
abf0cd3d
GR
8 *
9 * (C) Copyright 2006
dbf7115a 10 * Detlev Zundel, DENX Software Engineering, <[email protected]>
abf0cd3d
GR
11 *
12 * (C) Copyright -2003
dbf7115a 13 * Wolfgang Denk, DENX Software Engineering, <[email protected]>
abf0cd3d
GR
14 *
15 * (C) Copyright 2002
fa82f871 16 * Daniel Engström, Omicron Ceti AB, <[email protected]>
abf0cd3d
GR
17 *
18 * (C) Copyright 2001
dbf7115a 19 * Josh Huber, Mission Critical Linux, Inc, <[email protected]>
abf0cd3d
GR
20 */
21
22/*
23 * This file contains the high-level API for the interrupt sub-system
dbf7115a 24 * of the x86 port of U-Boot. Most of the functionality has been
abf0cd3d
GR
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
dbf7115a 28 * interrupt handling routines for the x86 port were written by
fa82f871 29 * Daniel Engström
abf0cd3d
GR
30 */
31
32#include <common.h>
c30b7adb 33#include <irq_func.h>
abf0cd3d
GR
34#include <asm/interrupt.h>
35
c2bf0dfa
SG
36#if !CONFIG_IS_ENABLED(X86_64)
37
abf0cd3d
GR
38struct irq_action {
39 interrupt_handler_t *handler;
40 void *arg;
41 unsigned int count;
42};
43
6c505271 44static struct irq_action irq_handlers[SYS_NUM_IRQS] = { {0} };
83088afb
GR
45static int spurious_irq_cnt;
46static int spurious_irq;
abf0cd3d
GR
47
48void irq_install_handler(int irq, interrupt_handler_t *handler, void *arg)
49{
50 int status;
51
6c505271 52 if (irq < 0 || irq >= SYS_NUM_IRQS) {
abf0cd3d
GR
53 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",
83088afb
GR
59 (ulong) handler,
60 (ulong) irq_handlers[irq].handler);
abf0cd3d 61
83088afb 62 status = disable_interrupts();
abf0cd3d 63
1c409bc7 64 irq_handlers[irq].handler = handler;
abf0cd3d
GR
65 irq_handlers[irq].arg = arg;
66 irq_handlers[irq].count = 0;
67
c6410104
BM
68 if (CONFIG_IS_ENABLED(I8259_PIC))
69 unmask_irq(irq);
abf0cd3d
GR
70
71 if (status)
72 enable_interrupts();
73
74 return;
75}
76
77void irq_free_handler(int irq)
78{
79 int status;
80
6c505271 81 if (irq < 0 || irq >= SYS_NUM_IRQS) {
abf0cd3d
GR
82 printf("irq_free_handler: bad irq number %d\n", irq);
83 return;
84 }
85
83088afb 86 status = disable_interrupts();
abf0cd3d 87
c6410104
BM
88 if (CONFIG_IS_ENABLED(I8259_PIC))
89 mask_irq(irq);
abf0cd3d
GR
90
91 irq_handlers[irq].handler = NULL;
92 irq_handlers[irq].arg = NULL;
93
94 if (status)
95 enable_interrupts();
96
97 return;
98}
99
564a9984 100void do_irq(int hw_irq)
abf0cd3d 101{
564a9984
GR
102 int irq = hw_irq - 0x20;
103
6c505271 104 if (irq < 0 || irq >= SYS_NUM_IRQS) {
abf0cd3d
GR
105 printf("do_irq: bad irq number %d\n", irq);
106 return;
107 }
108
109 if (irq_handlers[irq].handler) {
c6410104
BM
110 if (CONFIG_IS_ENABLED(I8259_PIC))
111 mask_irq(irq);
abf0cd3d
GR
112
113 irq_handlers[irq].handler(irq_handlers[irq].arg);
114 irq_handlers[irq].count++;
115
c6410104
BM
116 if (CONFIG_IS_ENABLED(I8259_PIC)) {
117 unmask_irq(irq);
118 specific_eoi(irq);
119 }
abf0cd3d
GR
120 } else {
121 if ((irq & 7) != 7) {
122 spurious_irq_cnt++;
123 spurious_irq = irq;
124 }
125 }
126}
c2bf0dfa 127#endif
abf0cd3d
GR
128
129#if defined(CONFIG_CMD_IRQ)
09140113 130int do_irqinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
abf0cd3d 131{
c2bf0dfa 132#if !CONFIG_IS_ENABLED(X86_64)
abf0cd3d
GR
133 int irq;
134
135 printf("Spurious IRQ: %u, last unknown IRQ: %d\n",
83088afb 136 spurious_irq_cnt, spurious_irq);
abf0cd3d 137
83088afb
GR
138 printf("Interrupt-Information:\n");
139 printf("Nr Routine Arg Count\n");
abf0cd3d 140
6c505271 141 for (irq = 0; irq < SYS_NUM_IRQS; irq++) {
abf0cd3d 142 if (irq_handlers[irq].handler != NULL) {
83088afb 143 printf("%02d %08lx %08lx %d\n",
abf0cd3d
GR
144 irq,
145 (ulong)irq_handlers[irq].handler,
146 (ulong)irq_handlers[irq].arg,
147 irq_handlers[irq].count);
148 }
149 }
c2bf0dfa 150#endif
abf0cd3d
GR
151
152 return 0;
153}
154#endif
This page took 0.449376 seconds and 4 git commands to generate.