wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 1 | /* |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 2 | * (C) Copyright 2007 Michal Simek |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 3 | * (C) Copyright 2004 Atmark Techno, Inc. |
| 4 | * |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 5 | * Michal SIMEK <monstr@monstr.eu> |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 6 | * Yasushi SHOJI <yashi@atmark-techno.com> |
| 7 | * |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 27 | #include <common.h> |
| 28 | #include <command.h> |
| 29 | #include <asm/microblaze_intc.h> |
Michal Simek | 42efed6 | 2007-05-07 17:22:25 +0200 | [diff] [blame] | 30 | #include <asm/asm.h> |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 31 | |
| 32 | #undef DEBUG_INT |
| 33 | |
| 34 | extern void microblaze_disable_interrupts (void); |
| 35 | extern void microblaze_enable_interrupts (void); |
| 36 | |
| 37 | void enable_interrupts (void) |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 38 | { |
Michal Simek | fb05f6d | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 39 | MSRSET(0x2); |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 42 | int disable_interrupts (void) |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 43 | { |
Michal Simek | fb05f6d | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 44 | MSRCLR(0x2); |
wdenk | 507bbe3 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 45 | return 0; |
| 46 | } |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 47 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 48 | #ifdef CONFIG_SYS_INTC_0 |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 49 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 50 | static struct irq_action vecs[CONFIG_SYS_INTC_0_NUM]; |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 51 | |
| 52 | /* mapping structure to interrupt controller */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 53 | microblaze_intc_t *intc = (microblaze_intc_t *) (CONFIG_SYS_INTC_0_ADDR); |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 54 | |
| 55 | /* default handler */ |
| 56 | void def_hdlr (void) |
| 57 | { |
| 58 | puts ("def_hdlr\n"); |
| 59 | } |
| 60 | |
| 61 | void enable_one_interrupt (int irq) |
| 62 | { |
| 63 | int mask; |
| 64 | int offset = 1; |
| 65 | offset <<= irq; |
| 66 | mask = intc->ier; |
| 67 | intc->ier = (mask | offset); |
| 68 | #ifdef DEBUG_INT |
| 69 | printf ("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask, |
| 70 | intc->ier); |
| 71 | printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier, |
| 72 | intc->iar, intc->mer); |
| 73 | #endif |
| 74 | } |
| 75 | |
| 76 | void disable_one_interrupt (int irq) |
| 77 | { |
| 78 | int mask; |
| 79 | int offset = 1; |
| 80 | offset <<= irq; |
| 81 | mask = intc->ier; |
| 82 | intc->ier = (mask & ~offset); |
| 83 | #ifdef DEBUG_INT |
| 84 | printf ("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask, |
| 85 | intc->ier); |
| 86 | printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier, |
| 87 | intc->iar, intc->mer); |
| 88 | #endif |
| 89 | } |
| 90 | |
| 91 | /* adding new handler for interrupt */ |
| 92 | void install_interrupt_handler (int irq, interrupt_handler_t * hdlr, void *arg) |
| 93 | { |
| 94 | struct irq_action *act; |
| 95 | /* irq out of range */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 96 | if ((irq < 0) || (irq > CONFIG_SYS_INTC_0_NUM)) { |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 97 | puts ("IRQ out of range\n"); |
| 98 | return; |
| 99 | } |
| 100 | act = &vecs[irq]; |
| 101 | if (hdlr) { /* enable */ |
| 102 | act->handler = hdlr; |
| 103 | act->arg = arg; |
| 104 | act->count = 0; |
| 105 | enable_one_interrupt (irq); |
| 106 | } else { /* disable */ |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 107 | act->handler = (interrupt_handler_t *) def_hdlr; |
| 108 | act->arg = (void *)irq; |
| 109 | disable_one_interrupt (irq); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | /* initialization interrupt controller - hardware */ |
| 114 | void intc_init (void) |
| 115 | { |
| 116 | intc->mer = 0; |
| 117 | intc->ier = 0; |
| 118 | intc->iar = 0xFFFFFFFF; |
| 119 | /* XIntc_Start - hw_interrupt enable and all interrupt enable */ |
| 120 | intc->mer = 0x3; |
| 121 | #ifdef DEBUG_INT |
| 122 | printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier, |
| 123 | intc->iar, intc->mer); |
| 124 | #endif |
| 125 | } |
| 126 | |
| 127 | int interrupts_init (void) |
| 128 | { |
| 129 | int i; |
| 130 | /* initialize irq list */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 131 | for (i = 0; i < CONFIG_SYS_INTC_0_NUM; i++) { |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 132 | vecs[i].handler = (interrupt_handler_t *) def_hdlr; |
| 133 | vecs[i].arg = (void *)i; |
| 134 | vecs[i].count = 0; |
| 135 | } |
| 136 | /* initialize intc controller */ |
| 137 | intc_init (); |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 138 | enable_interrupts (); |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | void interrupt_handler (void) |
| 143 | { |
Michal Simek | 8125c98 | 2010-04-16 11:51:59 +0200 | [diff] [blame] | 144 | int irqs = intc->ivr; /* find active interrupt */ |
| 145 | int mask = 1; |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 146 | #ifdef DEBUG_INT |
Michal Simek | 42efed6 | 2007-05-07 17:22:25 +0200 | [diff] [blame] | 147 | int value; |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 148 | printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier, |
| 149 | intc->iar, intc->mer); |
Michal Simek | 42efed6 | 2007-05-07 17:22:25 +0200 | [diff] [blame] | 150 | R14(value); |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 151 | printf ("Interrupt handler on %x line, r14 %x\n", irqs, value); |
| 152 | #endif |
Michal Simek | 8125c98 | 2010-04-16 11:51:59 +0200 | [diff] [blame] | 153 | struct irq_action *act = vecs + irqs; |
| 154 | |
| 155 | intc->iar = mask << irqs; |
| 156 | |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 157 | #ifdef DEBUG_INT |
Michal Simek | 8125c98 | 2010-04-16 11:51:59 +0200 | [diff] [blame] | 158 | printf |
| 159 | ("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n", |
| 160 | act->handler, act->count, act->arg); |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 161 | #endif |
Michal Simek | 8125c98 | 2010-04-16 11:51:59 +0200 | [diff] [blame] | 162 | act->handler (act->arg); |
| 163 | act->count++; |
Michal Simek | 42efed6 | 2007-05-07 17:22:25 +0200 | [diff] [blame] | 164 | |
| 165 | #ifdef DEBUG_INT |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 166 | printf ("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr, |
| 167 | intc->ier, intc->iar, intc->mer); |
Michal Simek | 42efed6 | 2007-05-07 17:22:25 +0200 | [diff] [blame] | 168 | R14(value); |
| 169 | printf ("Interrupt handler on %x line, r14 %x\n", irqs, value); |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 170 | #endif |
| 171 | } |
| 172 | #endif |
| 173 | |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 174 | #if defined(CONFIG_CMD_IRQ) |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 175 | #ifdef CONFIG_SYS_INTC_0 |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 176 | int do_irqinfo (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 177 | { |
| 178 | int i; |
| 179 | struct irq_action *act = vecs; |
| 180 | |
| 181 | puts ("\nInterrupt-Information:\n\n" |
| 182 | "Nr Routine Arg Count\n" |
| 183 | "-----------------------------\n"); |
| 184 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 185 | for (i = 0; i < CONFIG_SYS_INTC_0_NUM; i++) { |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 186 | if (act->handler != (interrupt_handler_t*) def_hdlr) { |
Stefan Roese | f2302d4 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 187 | printf ("%02d %08x %08x %d\n", i, |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 188 | (int)act->handler, (int)act->arg, act->count); |
| 189 | } |
| 190 | act++; |
| 191 | } |
| 192 | puts ("\n"); |
| 193 | return (0); |
| 194 | } |
| 195 | #else |
Wolfgang Denk | 54841ab | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 196 | int do_irqinfo (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
Michal Simek | cfc6711 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 197 | { |
| 198 | puts ("Undefined interrupt controller\n"); |
| 199 | } |
| 200 | #endif |
Jon Loeliger | 4431283 | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 201 | #endif |