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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 8 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 11 | #include <common.h> |
| 12 | #include <command.h> |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 13 | #include <malloc.h> |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 14 | #include <asm/microblaze_intc.h> |
Michal Simek | 77a1e24 | 2007-05-07 17:22:25 +0200 | [diff] [blame] | 15 | #include <asm/asm.h> |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 16 | |
Michal Simek | 8b4bb3a | 2012-06-29 13:27:28 +0200 | [diff] [blame] | 17 | void enable_interrupts(void) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 18 | { |
Michal Simek | 98c1979 | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 19 | MSRSET(0x2); |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 20 | } |
| 21 | |
Michal Simek | 8b4bb3a | 2012-06-29 13:27:28 +0200 | [diff] [blame] | 22 | int disable_interrupts(void) |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 23 | { |
Michal Simek | c94f95e | 2010-12-21 08:30:39 +0100 | [diff] [blame] | 24 | unsigned int msr; |
| 25 | |
| 26 | MFS(msr, rmsr); |
Michal Simek | 98c1979 | 2007-05-07 23:58:31 +0200 | [diff] [blame] | 27 | MSRCLR(0x2); |
Michal Simek | c94f95e | 2010-12-21 08:30:39 +0100 | [diff] [blame] | 28 | return (msr & 0x2) != 0; |
wdenk | 1249065 | 2004-04-18 21:13:41 +0000 | [diff] [blame] | 29 | } |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 30 | |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 31 | static struct irq_action *vecs; |
| 32 | static u32 irq_no; |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 33 | |
| 34 | /* mapping structure to interrupt controller */ |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 35 | microblaze_intc_t *intc; |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 36 | |
| 37 | /* default handler */ |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 38 | static void def_hdlr(void) |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 39 | { |
Michal Simek | 8b4bb3a | 2012-06-29 13:27:28 +0200 | [diff] [blame] | 40 | puts("def_hdlr\n"); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 41 | } |
| 42 | |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 43 | static void enable_one_interrupt(int irq) |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 44 | { |
| 45 | int mask; |
| 46 | int offset = 1; |
Michal Simek | 8b4bb3a | 2012-06-29 13:27:28 +0200 | [diff] [blame] | 47 | |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 48 | offset <<= irq; |
| 49 | mask = intc->ier; |
| 50 | intc->ier = (mask | offset); |
Michal Simek | baf5175 | 2015-01-26 14:37:52 +0100 | [diff] [blame] | 51 | |
| 52 | debug("Enable one interrupt irq %x - mask %x,ier %x\n", offset, mask, |
| 53 | intc->ier); |
| 54 | debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier, |
| 55 | intc->iar, intc->mer); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 56 | } |
| 57 | |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 58 | static void disable_one_interrupt(int irq) |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 59 | { |
| 60 | int mask; |
| 61 | int offset = 1; |
Michal Simek | 8b4bb3a | 2012-06-29 13:27:28 +0200 | [diff] [blame] | 62 | |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 63 | offset <<= irq; |
| 64 | mask = intc->ier; |
| 65 | intc->ier = (mask & ~offset); |
Michal Simek | baf5175 | 2015-01-26 14:37:52 +0100 | [diff] [blame] | 66 | |
| 67 | debug("Disable one interrupt irq %x - mask %x,ier %x\n", irq, mask, |
| 68 | intc->ier); |
| 69 | debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier, |
| 70 | intc->iar, intc->mer); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 71 | } |
| 72 | |
Michal Simek | e76a06e | 2012-06-29 14:21:52 +0200 | [diff] [blame] | 73 | int install_interrupt_handler(int irq, interrupt_handler_t *hdlr, void *arg) |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 74 | { |
| 75 | struct irq_action *act; |
Michal Simek | 8b4bb3a | 2012-06-29 13:27:28 +0200 | [diff] [blame] | 76 | |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 77 | /* irq out of range */ |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 78 | if ((irq < 0) || (irq > irq_no)) { |
Michal Simek | 8b4bb3a | 2012-06-29 13:27:28 +0200 | [diff] [blame] | 79 | puts("IRQ out of range\n"); |
Michal Simek | e76a06e | 2012-06-29 14:21:52 +0200 | [diff] [blame] | 80 | return -1; |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 81 | } |
| 82 | act = &vecs[irq]; |
| 83 | if (hdlr) { /* enable */ |
| 84 | act->handler = hdlr; |
| 85 | act->arg = arg; |
| 86 | act->count = 0; |
Michal Simek | 5e6c747 | 2015-01-26 14:39:22 +0100 | [diff] [blame^] | 87 | enable_one_interrupt(irq); |
Michal Simek | e76a06e | 2012-06-29 14:21:52 +0200 | [diff] [blame] | 88 | return 0; |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 89 | } |
Michal Simek | e76a06e | 2012-06-29 14:21:52 +0200 | [diff] [blame] | 90 | |
| 91 | /* Disable */ |
Michal Simek | 5e6c747 | 2015-01-26 14:39:22 +0100 | [diff] [blame^] | 92 | act->handler = (interrupt_handler_t *)def_hdlr; |
Michal Simek | e76a06e | 2012-06-29 14:21:52 +0200 | [diff] [blame] | 93 | act->arg = (void *)irq; |
| 94 | disable_one_interrupt(irq); |
| 95 | return 1; |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /* initialization interrupt controller - hardware */ |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 99 | static void intc_init(void) |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 100 | { |
| 101 | intc->mer = 0; |
| 102 | intc->ier = 0; |
| 103 | intc->iar = 0xFFFFFFFF; |
| 104 | /* XIntc_Start - hw_interrupt enable and all interrupt enable */ |
| 105 | intc->mer = 0x3; |
Michal Simek | baf5175 | 2015-01-26 14:37:52 +0100 | [diff] [blame] | 106 | |
| 107 | debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier, |
| 108 | intc->iar, intc->mer); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 109 | } |
| 110 | |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 111 | int interrupts_init(void) |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 112 | { |
| 113 | int i; |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 114 | |
| 115 | #if defined(CONFIG_SYS_INTC_0_ADDR) && defined(CONFIG_SYS_INTC_0_NUM) |
Michal Simek | 5e6c747 | 2015-01-26 14:39:22 +0100 | [diff] [blame^] | 116 | intc = (microblaze_intc_t *)CONFIG_SYS_INTC_0_ADDR; |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 117 | irq_no = CONFIG_SYS_INTC_0_NUM; |
| 118 | #endif |
| 119 | if (irq_no) { |
| 120 | vecs = calloc(1, sizeof(struct irq_action) * irq_no); |
| 121 | if (vecs == NULL) { |
| 122 | puts("Interrupt vector allocation failed\n"); |
| 123 | return -1; |
| 124 | } |
| 125 | |
| 126 | /* initialize irq list */ |
| 127 | for (i = 0; i < irq_no; i++) { |
Michal Simek | 5e6c747 | 2015-01-26 14:39:22 +0100 | [diff] [blame^] | 128 | vecs[i].handler = (interrupt_handler_t *)def_hdlr; |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 129 | vecs[i].arg = (void *)i; |
| 130 | vecs[i].count = 0; |
| 131 | } |
| 132 | /* initialize intc controller */ |
| 133 | intc_init(); |
| 134 | enable_interrupts(); |
| 135 | } else { |
| 136 | puts("Undefined interrupt controller\n"); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 137 | } |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 138 | return 0; |
| 139 | } |
| 140 | |
Michal Simek | 8b4bb3a | 2012-06-29 13:27:28 +0200 | [diff] [blame] | 141 | void interrupt_handler(void) |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 142 | { |
Michal Simek | 2c00449 | 2010-04-16 11:51:59 +0200 | [diff] [blame] | 143 | int irqs = intc->ivr; /* find active interrupt */ |
| 144 | int mask = 1; |
Michal Simek | 77a1e24 | 2007-05-07 17:22:25 +0200 | [diff] [blame] | 145 | int value; |
Michal Simek | 2c00449 | 2010-04-16 11:51:59 +0200 | [diff] [blame] | 146 | struct irq_action *act = vecs + irqs; |
| 147 | |
Michal Simek | baf5175 | 2015-01-26 14:37:52 +0100 | [diff] [blame] | 148 | debug("INTC isr %x, ier %x, iar %x, mer %x\n", intc->isr, intc->ier, |
| 149 | intc->iar, intc->mer); |
| 150 | #ifdef DEBUG |
| 151 | R14(value); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 152 | #endif |
Michal Simek | baf5175 | 2015-01-26 14:37:52 +0100 | [diff] [blame] | 153 | debug("Interrupt handler on %x line, r14 %x\n", irqs, value); |
| 154 | |
| 155 | debug("Jumping to interrupt handler rutine addr %x,count %x,arg %x\n", |
| 156 | (u32)act->handler, act->count, (u32)act->arg); |
Michal Simek | 5e6c747 | 2015-01-26 14:39:22 +0100 | [diff] [blame^] | 157 | act->handler(act->arg); |
Michal Simek | 2c00449 | 2010-04-16 11:51:59 +0200 | [diff] [blame] | 158 | act->count++; |
Michal Simek | 77a1e24 | 2007-05-07 17:22:25 +0200 | [diff] [blame] | 159 | |
Stephan Linz | 5db50d6 | 2012-02-22 19:12:43 +0100 | [diff] [blame] | 160 | intc->iar = mask << irqs; |
| 161 | |
Michal Simek | baf5175 | 2015-01-26 14:37:52 +0100 | [diff] [blame] | 162 | debug("Dump INTC reg, isr %x, ier %x, iar %x, mer %x\n", intc->isr, |
| 163 | intc->ier, intc->iar, intc->mer); |
| 164 | #ifdef DEBUG |
Michal Simek | 77a1e24 | 2007-05-07 17:22:25 +0200 | [diff] [blame] | 165 | R14(value); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 166 | #endif |
Michal Simek | baf5175 | 2015-01-26 14:37:52 +0100 | [diff] [blame] | 167 | debug("Interrupt handler on %x line, r14 %x\n", irqs, value); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 168 | } |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 169 | |
Jon Loeliger | 526e5ce | 2007-07-09 19:06:00 -0500 | [diff] [blame] | 170 | #if defined(CONFIG_CMD_IRQ) |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 171 | int do_irqinfo(cmd_tbl_t *cmdtp, int flag, int argc, const char *argv[]) |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 172 | { |
| 173 | int i; |
| 174 | struct irq_action *act = vecs; |
| 175 | |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 176 | if (irq_no) { |
| 177 | puts("\nInterrupt-Information:\n\n" |
| 178 | "Nr Routine Arg Count\n" |
| 179 | "-----------------------------\n"); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 180 | |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 181 | for (i = 0; i < irq_no; i++) { |
Michal Simek | 5e6c747 | 2015-01-26 14:39:22 +0100 | [diff] [blame^] | 182 | if (act->handler != (interrupt_handler_t *)def_hdlr) { |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 183 | printf("%02d %08x %08x %d\n", i, |
Michal Simek | 5e6c747 | 2015-01-26 14:39:22 +0100 | [diff] [blame^] | 184 | (int)act->handler, (int)act->arg, |
| 185 | act->count); |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 186 | } |
| 187 | act++; |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 188 | } |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 189 | puts("\n"); |
| 190 | } else { |
| 191 | puts("Undefined interrupt controller\n"); |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 192 | } |
Michal Simek | 251ed2c | 2012-07-10 10:31:31 +0200 | [diff] [blame] | 193 | return 0; |
Michal Simek | 922ce20 | 2007-03-11 13:48:24 +0100 | [diff] [blame] | 194 | } |
| 195 | #endif |