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