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