Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2009 |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 3 | * Graeme Russ, <graeme.russ@gmail.com> |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 4 | * |
| 5 | * (C) Copyright 2007 |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 6 | * Daniel Hellstrom, Gaisler Research, <daniel@gaisler.com> |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 7 | * |
| 8 | * (C) Copyright 2006 |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 9 | * Detlev Zundel, DENX Software Engineering, <dzu@denx.de> |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 10 | * |
| 11 | * (C) Copyright -2003 |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 12 | * Wolfgang Denk, DENX Software Engineering, <wd@denx.de> |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 13 | * |
| 14 | * (C) Copyright 2002 |
Albert ARIBAUD | 60fbc8d | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 15 | * Daniel Engström, Omicron Ceti AB, <daniel@omicron.se> |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 16 | * |
| 17 | * (C) Copyright 2001 |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 18 | * Josh Huber, Mission Critical Linux, Inc, <huber@mclx.com> |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 19 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 20 | * SPDX-License-Identifier: GPL-2.0+ |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 21 | */ |
| 22 | |
| 23 | /* |
| 24 | * This file contains the high-level API for the interrupt sub-system |
Graeme Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 25 | * of the x86 port of U-Boot. Most of the functionality has been |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 26 | * 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 Russ | 45fc1d8 | 2011-04-13 19:43:26 +1000 | [diff] [blame] | 29 | * interrupt handling routines for the x86 port were written by |
Albert ARIBAUD | 60fbc8d | 2011-08-04 18:45:45 +0200 | [diff] [blame] | 30 | * Daniel Engström |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 31 | */ |
| 32 | |
| 33 | #include <common.h> |
| 34 | #include <asm/interrupt.h> |
| 35 | |
| 36 | struct irq_action { |
| 37 | interrupt_handler_t *handler; |
| 38 | void *arg; |
| 39 | unsigned int count; |
| 40 | }; |
| 41 | |
| 42 | static struct irq_action irq_handlers[CONFIG_SYS_NUM_IRQS] = { {0} }; |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 43 | static int spurious_irq_cnt; |
| 44 | static int spurious_irq; |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 45 | |
| 46 | void irq_install_handler(int irq, interrupt_handler_t *handler, void *arg) |
| 47 | { |
| 48 | int status; |
| 49 | |
| 50 | if (irq < 0 || irq >= CONFIG_SYS_NUM_IRQS) { |
| 51 | printf("irq_install_handler: bad irq number %d\n", irq); |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | if (irq_handlers[irq].handler != NULL) |
| 56 | printf("irq_install_handler: 0x%08lx replacing 0x%08lx\n", |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 57 | (ulong) handler, |
| 58 | (ulong) irq_handlers[irq].handler); |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 59 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 60 | status = disable_interrupts(); |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 61 | |
Graeme Russ | 078395c | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 62 | irq_handlers[irq].handler = handler; |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 63 | irq_handlers[irq].arg = arg; |
| 64 | irq_handlers[irq].count = 0; |
| 65 | |
| 66 | unmask_irq(irq); |
| 67 | |
| 68 | if (status) |
| 69 | enable_interrupts(); |
| 70 | |
| 71 | return; |
| 72 | } |
| 73 | |
| 74 | void irq_free_handler(int irq) |
| 75 | { |
| 76 | int status; |
| 77 | |
| 78 | if (irq < 0 || irq >= CONFIG_SYS_NUM_IRQS) { |
| 79 | printf("irq_free_handler: bad irq number %d\n", irq); |
| 80 | return; |
| 81 | } |
| 82 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 83 | status = disable_interrupts(); |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 84 | |
| 85 | mask_irq(irq); |
| 86 | |
| 87 | irq_handlers[irq].handler = NULL; |
| 88 | irq_handlers[irq].arg = NULL; |
| 89 | |
| 90 | if (status) |
| 91 | enable_interrupts(); |
| 92 | |
| 93 | return; |
| 94 | } |
| 95 | |
Graeme Russ | d11b085 | 2009-11-24 20:04:18 +1100 | [diff] [blame] | 96 | void do_irq(int hw_irq) |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 97 | { |
Graeme Russ | d11b085 | 2009-11-24 20:04:18 +1100 | [diff] [blame] | 98 | int irq = hw_irq - 0x20; |
| 99 | |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 100 | if (irq < 0 || irq >= CONFIG_SYS_NUM_IRQS) { |
| 101 | printf("do_irq: bad irq number %d\n", irq); |
| 102 | return; |
| 103 | } |
| 104 | |
| 105 | if (irq_handlers[irq].handler) { |
| 106 | mask_irq(irq); |
| 107 | |
| 108 | irq_handlers[irq].handler(irq_handlers[irq].arg); |
| 109 | irq_handlers[irq].count++; |
| 110 | |
| 111 | unmask_irq(irq); |
| 112 | specific_eoi(irq); |
| 113 | |
| 114 | } else { |
| 115 | if ((irq & 7) != 7) { |
| 116 | spurious_irq_cnt++; |
| 117 | spurious_irq = irq; |
| 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | #if defined(CONFIG_CMD_IRQ) |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 123 | int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]) |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 124 | { |
| 125 | int irq; |
| 126 | |
| 127 | printf("Spurious IRQ: %u, last unknown IRQ: %d\n", |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 128 | spurious_irq_cnt, spurious_irq); |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 129 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 130 | printf("Interrupt-Information:\n"); |
| 131 | printf("Nr Routine Arg Count\n"); |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 132 | |
| 133 | for (irq = 0; irq <= CONFIG_SYS_NUM_IRQS; irq++) { |
| 134 | if (irq_handlers[irq].handler != NULL) { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 135 | printf("%02d %08lx %08lx %d\n", |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 136 | irq, |
| 137 | (ulong)irq_handlers[irq].handler, |
| 138 | (ulong)irq_handlers[irq].arg, |
| 139 | irq_handlers[irq].count); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | return 0; |
| 144 | } |
| 145 | #endif |