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 | |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 32 | #include <command.h> |
Simon Glass | 9b61c7c | 2019-11-14 12:57:41 -0700 | [diff] [blame] | 33 | #include <irq_func.h> |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 34 | #include <asm/interrupt.h> |
| 35 | |
Simon Glass | f5156f0 | 2017-01-16 07:04:14 -0700 | [diff] [blame] | 36 | #if !CONFIG_IS_ENABLED(X86_64) |
| 37 | |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 38 | struct irq_action { |
| 39 | interrupt_handler_t *handler; |
| 40 | void *arg; |
| 41 | unsigned int count; |
| 42 | }; |
| 43 | |
Bin Meng | e7a76e5 | 2015-10-22 19:13:26 -0700 | [diff] [blame] | 44 | static struct irq_action irq_handlers[SYS_NUM_IRQS] = { {0} }; |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 45 | static int spurious_irq_cnt; |
| 46 | static int spurious_irq; |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 47 | |
| 48 | void irq_install_handler(int irq, interrupt_handler_t *handler, void *arg) |
| 49 | { |
| 50 | int status; |
| 51 | |
Bin Meng | e7a76e5 | 2015-10-22 19:13:26 -0700 | [diff] [blame] | 52 | if (irq < 0 || irq >= SYS_NUM_IRQS) { |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 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", |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 59 | (ulong) handler, |
| 60 | (ulong) irq_handlers[irq].handler); |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 61 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 62 | status = disable_interrupts(); |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 63 | |
Graeme Russ | 078395c | 2009-11-24 20:04:21 +1100 | [diff] [blame] | 64 | irq_handlers[irq].handler = handler; |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 65 | irq_handlers[irq].arg = arg; |
| 66 | irq_handlers[irq].count = 0; |
| 67 | |
Bin Meng | 465c710 | 2018-11-29 19:57:21 -0800 | [diff] [blame] | 68 | if (CONFIG_IS_ENABLED(I8259_PIC)) |
| 69 | unmask_irq(irq); |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 70 | |
| 71 | if (status) |
| 72 | enable_interrupts(); |
| 73 | |
| 74 | return; |
| 75 | } |
| 76 | |
| 77 | void irq_free_handler(int irq) |
| 78 | { |
| 79 | int status; |
| 80 | |
Bin Meng | e7a76e5 | 2015-10-22 19:13:26 -0700 | [diff] [blame] | 81 | if (irq < 0 || irq >= SYS_NUM_IRQS) { |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 82 | printf("irq_free_handler: bad irq number %d\n", irq); |
| 83 | return; |
| 84 | } |
| 85 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 86 | status = disable_interrupts(); |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 87 | |
Bin Meng | 465c710 | 2018-11-29 19:57:21 -0800 | [diff] [blame] | 88 | if (CONFIG_IS_ENABLED(I8259_PIC)) |
| 89 | mask_irq(irq); |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 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 | |
Graeme Russ | d11b085 | 2009-11-24 20:04:18 +1100 | [diff] [blame] | 100 | void do_irq(int hw_irq) |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 101 | { |
Graeme Russ | d11b085 | 2009-11-24 20:04:18 +1100 | [diff] [blame] | 102 | int irq = hw_irq - 0x20; |
| 103 | |
Bin Meng | e7a76e5 | 2015-10-22 19:13:26 -0700 | [diff] [blame] | 104 | if (irq < 0 || irq >= SYS_NUM_IRQS) { |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 105 | printf("do_irq: bad irq number %d\n", irq); |
| 106 | return; |
| 107 | } |
| 108 | |
| 109 | if (irq_handlers[irq].handler) { |
Bin Meng | 465c710 | 2018-11-29 19:57:21 -0800 | [diff] [blame] | 110 | if (CONFIG_IS_ENABLED(I8259_PIC)) |
| 111 | mask_irq(irq); |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 112 | |
| 113 | irq_handlers[irq].handler(irq_handlers[irq].arg); |
| 114 | irq_handlers[irq].count++; |
| 115 | |
Bin Meng | 465c710 | 2018-11-29 19:57:21 -0800 | [diff] [blame] | 116 | if (CONFIG_IS_ENABLED(I8259_PIC)) { |
| 117 | unmask_irq(irq); |
| 118 | specific_eoi(irq); |
| 119 | } |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 120 | } else { |
| 121 | if ((irq & 7) != 7) { |
| 122 | spurious_irq_cnt++; |
| 123 | spurious_irq = irq; |
| 124 | } |
| 125 | } |
| 126 | } |
Simon Glass | f5156f0 | 2017-01-16 07:04:14 -0700 | [diff] [blame] | 127 | #endif |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 128 | |
| 129 | #if defined(CONFIG_CMD_IRQ) |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 130 | int do_irqinfo(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]) |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 131 | { |
Simon Glass | f5156f0 | 2017-01-16 07:04:14 -0700 | [diff] [blame] | 132 | #if !CONFIG_IS_ENABLED(X86_64) |
Simon Glass | 495afca | 2020-11-04 09:57:28 -0700 | [diff] [blame] | 133 | struct idt_ptr ptr; |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 134 | int irq; |
| 135 | |
Simon Glass | 495afca | 2020-11-04 09:57:28 -0700 | [diff] [blame] | 136 | interrupt_read_idt(&ptr); |
| 137 | printf("IDT at %lx, size %x\n", ptr.address, ptr.size); |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 138 | printf("Spurious IRQ: %u, last unknown IRQ: %d\n", |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 139 | spurious_irq_cnt, spurious_irq); |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 140 | |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 141 | printf("Interrupt-Information:\n"); |
| 142 | printf("Nr Routine Arg Count\n"); |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 143 | |
Bin Meng | e7a76e5 | 2015-10-22 19:13:26 -0700 | [diff] [blame] | 144 | for (irq = 0; irq < SYS_NUM_IRQS; irq++) { |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 145 | if (irq_handlers[irq].handler != NULL) { |
Graeme Russ | 883c603 | 2011-11-08 02:33:15 +0000 | [diff] [blame] | 146 | printf("%02d %08lx %08lx %d\n", |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 147 | irq, |
| 148 | (ulong)irq_handlers[irq].handler, |
| 149 | (ulong)irq_handlers[irq].arg, |
| 150 | irq_handlers[irq].count); |
| 151 | } |
| 152 | } |
Simon Glass | f5156f0 | 2017-01-16 07:04:14 -0700 | [diff] [blame] | 153 | #endif |
Graeme Russ | 77290ee | 2009-02-24 21:13:40 +1100 | [diff] [blame] | 154 | |
| 155 | return 0; |
| 156 | } |
| 157 | #endif |