wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 1 | /* |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 2 | * (C) Copyright 2007 Michal Simek |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 3 | * (C) Copyright 2004 Atmark Techno, Inc. |
| 4 | * |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 5 | * Michal SIMEK <monstr@monstr.eu> |
wdenk | 1249065 | 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 | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
wdenk | 1249065 | 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 | 922ce20 | 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 | 77a1e24 | 2007-05-07 17:22:25 +0200 | [diff] [blame] | 30 | #include <asm/asm.h> |
Michal Simek | 922ce20 | 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 | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 38 | { |
Michal Simek | 98c1979 | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 39 | MSRSET(0x2); |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 40 | } |
| 41 | |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 42 | int disable_interrupts (void) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 43 | { |
Michal Simek | c94f95e | 2010-12-21 08:30:39 +0100 | [diff] [blame] | 44 | unsigned int msr; |
| 45 | |
| 46 | MFS(msr, rmsr); |
Michal Simek | 98c1979 | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 47 | MSRCLR(0x2); |
Michal Simek | c94f95e | 2010-12-21 08:30:39 +0100 | [diff] [blame] | 48 | return (msr & 0x2) != 0; |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 49 | } |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 50 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 51 | #ifdef CONFIG_SYS_INTC_0 |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 52 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 53 | static struct irq_action vecs[CONFIG_SYS_INTC_0_NUM]; |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 54 | |
| 55 | /* mapping structure to interrupt controller */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 56 | microblaze_intc_t *intc = (microblaze_intc_t *) (CONFIG_SYS_INTC_0_ADDR); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 57 | |
| 58 | /* default handler */ |
| 59 | void def_hdlr (void) |
| 60 | { |
| 61 | puts ("def_hdlr\n"); |
| 62 | } |
| 63 | |
| 64 | void enable_one_interrupt (int irq) |
| 65 | { |
| 66 | int mask; |
| 67 | int offset = 1; |
| 68 | offset <<= irq; |
| 69 | mask = intc->ier; |
| 70 | intc->ier = (mask | offset); |
| 71 | #ifdef DEBUG_INT |
| 72 | printf ("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask, |
| 73 | intc->ier); |
| 74 | printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier, |
| 75 | intc->iar, intc->mer); |
| 76 | #endif |
| 77 | } |
| 78 | |
| 79 | void disable_one_interrupt (int irq) |
| 80 | { |
| 81 | int mask; |
| 82 | int offset = 1; |
| 83 | offset <<= irq; |
| 84 | mask = intc->ier; |
| 85 | intc->ier = (mask & ~offset); |
| 86 | #ifdef DEBUG_INT |
| 87 | printf ("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask, |
| 88 | intc->ier); |
| 89 | printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier, |
| 90 | intc->iar, intc->mer); |
| 91 | #endif |
| 92 | } |
| 93 | |
| 94 | /* adding new handler for interrupt */ |
| 95 | void install_interrupt_handler (int irq, interrupt_handler_t * hdlr, void *arg) |
| 96 | { |
| 97 | struct irq_action *act; |
| 98 | /* irq out of range */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 99 | if ((irq < 0) || (irq > CONFIG_SYS_INTC_0_NUM)) { |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 100 | puts ("IRQ out of range\n"); |
| 101 | return; |
| 102 | } |
| 103 | act = &vecs[irq]; |
| 104 | if (hdlr) { /* enable */ |
| 105 | act->handler = hdlr; |
| 106 | act->arg = arg; |
| 107 | act->count = 0; |
| 108 | enable_one_interrupt (irq); |
| 109 | } else { /* disable */ |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 110 | act->handler = (interrupt_handler_t *) def_hdlr; |
| 111 | act->arg = (void *)irq; |
| 112 | disable_one_interrupt (irq); |
| 113 | } |
| 114 | } |
| 115 | |
| 116 | /* initialization interrupt controller - hardware */ |
| 117 | void intc_init (void) |
| 118 | { |
| 119 | intc->mer = 0; |
| 120 | intc->ier = 0; |
| 121 | intc->iar = 0xFFFFFFFF; |
| 122 | /* XIntc_Start - hw_interrupt enable and all interrupt enable */ |
| 123 | intc->mer = 0x3; |
| 124 | #ifdef DEBUG_INT |
| 125 | printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier, |
| 126 | intc->iar, intc->mer); |
| 127 | #endif |
| 128 | } |
| 129 | |
| 130 | int interrupts_init (void) |
| 131 | { |
| 132 | int i; |
| 133 | /* initialize irq list */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 134 | for (i = 0; i < CONFIG_SYS_INTC_0_NUM; i++) { |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 135 | vecs[i].handler = (interrupt_handler_t *) def_hdlr; |
| 136 | vecs[i].arg = (void *)i; |
| 137 | vecs[i].count = 0; |
| 138 | } |
| 139 | /* initialize intc controller */ |
| 140 | intc_init (); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 141 | enable_interrupts (); |
| 142 | return 0; |
| 143 | } |
| 144 | |
| 145 | void interrupt_handler (void) |
| 146 | { |
Michal Simek | 2c00449 | 2010-04-16 11:51:59 +0200 | [diff] [blame] | 147 | int irqs = intc->ivr; /* find active interrupt */ |
| 148 | int mask = 1; |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 149 | #ifdef DEBUG_INT |
Michal Simek | 77a1e24 | 2007-05-07 17:22:25 +0200 | [diff] [blame] | 150 | int value; |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 151 | printf ("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier, |
| 152 | intc->iar, intc->mer); |
Michal Simek | 77a1e24 | 2007-05-07 17:22:25 +0200 | [diff] [blame] | 153 | R14(value); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 154 | printf ("Interrupt handler on %x line, r14 %x\n", irqs, value); |
| 155 | #endif |
Michal Simek | 2c00449 | 2010-04-16 11:51:59 +0200 | [diff] [blame] | 156 | struct irq_action *act = vecs + irqs; |
| 157 | |
| 158 | intc->iar = mask << irqs; |
| 159 | |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 160 | #ifdef DEBUG_INT |
Michal Simek | 2c00449 | 2010-04-16 11:51:59 +0200 | [diff] [blame] | 161 | printf |
| 162 | ("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n", |
| 163 | act->handler, act->count, act->arg); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 164 | #endif |
Michal Simek | 2c00449 | 2010-04-16 11:51:59 +0200 | [diff] [blame] | 165 | act->handler (act->arg); |
| 166 | act->count++; |
Michal Simek | 77a1e24 | 2007-05-07 17:22:25 +0200 | [diff] [blame] | 167 | |
| 168 | #ifdef DEBUG_INT |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 169 | printf ("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr, |
| 170 | intc->ier, intc->iar, intc->mer); |
Michal Simek | 77a1e24 | 2007-05-07 17:22:25 +0200 | [diff] [blame] | 171 | R14(value); |
| 172 | printf ("Interrupt handler on %x line, r14 %x\n", irqs, value); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 173 | #endif |
| 174 | } |
| 175 | #endif |
| 176 | |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 177 | #if defined(CONFIG_CMD_IRQ) |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 178 | #ifdef CONFIG_SYS_INTC_0 |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 179 | int do_irqinfo (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 180 | { |
| 181 | int i; |
| 182 | struct irq_action *act = vecs; |
| 183 | |
| 184 | puts ("\nInterrupt-Information:\n\n" |
| 185 | "Nr Routine Arg Count\n" |
| 186 | "-----------------------------\n"); |
| 187 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 188 | for (i = 0; i < CONFIG_SYS_INTC_0_NUM; i++) { |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 189 | if (act->handler != (interrupt_handler_t*) def_hdlr) { |
Stefan Roese | 3762825 | 2008-08-06 14:05:38 +0200 | [diff] [blame] | 190 | printf ("%02d %08x %08x %d\n", i, |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 191 | (int)act->handler, (int)act->arg, act->count); |
| 192 | } |
| 193 | act++; |
| 194 | } |
| 195 | puts ("\n"); |
| 196 | return (0); |
| 197 | } |
| 198 | #else |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 199 | int do_irqinfo (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[]) |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 200 | { |
| 201 | puts ("Undefined interrupt controller\n"); |
| 202 | } |
| 203 | #endif |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 204 | #endif |