Daniel Hellstrom | 207e695 | 2008-03-28 10:00:33 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Daniel Hellstrom, Gaisler Research, daniel@gaisler.com |
| 4 | * |
| 5 | * (C) Copyright 2006 |
| 6 | * Detlev Zundel, DENX Software Engineering, dzu@denx.de |
| 7 | * |
| 8 | * (C) Copyright -2003 |
| 9 | * Wolfgang Denk, DENX Software Engineering, wd@denx.de. |
| 10 | * |
| 11 | * (C) Copyright 2001 |
| 12 | * Josh Huber <huber@mclx.com>, Mission Critical Linux, Inc. |
| 13 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 14 | * SPDX-License-Identifier: GPL-2.0+ |
Daniel Hellstrom | 207e695 | 2008-03-28 10:00:33 +0100 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <asm/stack.h> |
| 18 | #include <common.h> |
| 19 | #include <asm/io.h> |
| 20 | #include <asm/processor.h> |
| 21 | #include <command.h> |
| 22 | #include <asm/irq.h> |
| 23 | |
| 24 | #include <asm/leon.h> |
| 25 | |
| 26 | /* 15 normal irqs and a non maskable interrupt */ |
| 27 | #define NR_IRQS 15 |
| 28 | |
| 29 | struct irq_action { |
| 30 | interrupt_handler_t *handler; |
| 31 | void *arg; |
| 32 | unsigned int count; |
| 33 | }; |
| 34 | |
| 35 | static struct irq_action irq_handlers[NR_IRQS] = { {0}, }; |
| 36 | static int spurious_irq_cnt = 0; |
| 37 | static int spurious_irq = 0; |
| 38 | |
| 39 | static inline unsigned int leon2_get_irqmask(unsigned int irq) |
| 40 | { |
| 41 | if ((irq < 0) || (irq >= NR_IRQS)) { |
| 42 | return 0; |
| 43 | } else { |
| 44 | return (1 << irq); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | static void leon2_ic_disable(unsigned int irq) |
| 49 | { |
| 50 | unsigned int mask, pil; |
| 51 | LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS; |
| 52 | |
| 53 | pil = intLock(); |
| 54 | |
| 55 | /* get mask of interrupt */ |
| 56 | mask = leon2_get_irqmask(irq); |
| 57 | |
| 58 | /* set int level */ |
| 59 | leon2->Interrupt_Mask = |
| 60 | SPARC_NOCACHE_READ(&leon2->Interrupt_Mask) & (~mask); |
| 61 | |
| 62 | intUnlock(pil); |
| 63 | } |
| 64 | |
| 65 | static void leon2_ic_enable(unsigned int irq) |
| 66 | { |
| 67 | unsigned int mask, pil; |
| 68 | LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS; |
| 69 | |
| 70 | pil = intLock(); |
| 71 | |
| 72 | /* get mask of interrupt */ |
| 73 | mask = leon2_get_irqmask(irq); |
| 74 | |
| 75 | /* set int level */ |
| 76 | leon2->Interrupt_Mask = |
| 77 | SPARC_NOCACHE_READ(&leon2->Interrupt_Mask) | mask; |
| 78 | |
| 79 | intUnlock(pil); |
| 80 | } |
| 81 | |
| 82 | void handler_irq(int irq, struct pt_regs *regs) |
| 83 | { |
| 84 | if (irq_handlers[irq].handler) { |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 85 | if (((unsigned int)irq_handlers[irq].handler > CONFIG_SYS_RAM_END) || |
| 86 | ((unsigned int)irq_handlers[irq].handler < CONFIG_SYS_RAM_BASE) |
Daniel Hellstrom | 207e695 | 2008-03-28 10:00:33 +0100 | [diff] [blame] | 87 | ) { |
| 88 | printf("handler_irq: bad handler: %x, irq number %d\n", |
| 89 | (unsigned int)irq_handlers[irq].handler, irq); |
| 90 | return; |
| 91 | } |
| 92 | irq_handlers[irq].handler(irq_handlers[irq].arg); |
| 93 | irq_handlers[irq].count++; |
| 94 | } else { |
| 95 | spurious_irq_cnt++; |
| 96 | spurious_irq = irq; |
| 97 | } |
| 98 | } |
| 99 | |
| 100 | void leon2_force_int(int irq) |
| 101 | { |
| 102 | LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS; |
| 103 | |
| 104 | if ((irq >= NR_IRQS) || (irq < 0)) |
| 105 | return; |
| 106 | printf("Forcing interrupt %d\n", irq); |
| 107 | |
| 108 | leon2->Interrupt_Force = |
| 109 | SPARC_NOCACHE_READ(&leon2->Interrupt_Force) | (1 << irq); |
| 110 | } |
| 111 | |
| 112 | /****************************************************************************/ |
| 113 | |
| 114 | int interrupt_init_cpu(void) |
| 115 | { |
| 116 | return (0); |
| 117 | } |
| 118 | |
| 119 | /****************************************************************************/ |
| 120 | |
| 121 | /* Handle Timer 0 IRQ */ |
| 122 | void timer_interrupt_cpu(void *arg) |
| 123 | { |
| 124 | LEON2_regs *leon2 = (LEON2_regs *) LEON2_PREGS; |
| 125 | |
| 126 | leon2->Timer_Control_1 = |
| 127 | (LEON2_TIMER_CTRL_EN | LEON2_TIMER_CTRL_RS | LEON2_TIMER_CTRL_LD); |
| 128 | |
| 129 | /* nothing to do here */ |
| 130 | return; |
| 131 | } |
| 132 | |
| 133 | /****************************************************************************/ |
| 134 | |
| 135 | /* |
| 136 | * Install and free a interrupt handler. |
| 137 | */ |
| 138 | |
| 139 | void irq_install_handler(int irq, interrupt_handler_t * handler, void *arg) |
| 140 | { |
| 141 | if (irq < 0 || irq >= NR_IRQS) { |
| 142 | printf("irq_install_handler: bad irq number %d\n", irq); |
| 143 | return; |
| 144 | } |
| 145 | |
| 146 | if (irq_handlers[irq].handler != NULL) |
| 147 | printf("irq_install_handler: 0x%08lx replacing 0x%08lx\n", |
| 148 | (ulong) handler, (ulong) irq_handlers[irq].handler); |
| 149 | |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 150 | if (((unsigned int)handler > CONFIG_SYS_RAM_END) || |
| 151 | ((unsigned int)handler < CONFIG_SYS_RAM_BASE) |
Daniel Hellstrom | 207e695 | 2008-03-28 10:00:33 +0100 | [diff] [blame] | 152 | ) { |
| 153 | printf("irq_install_handler: bad handler: %x, irq number %d\n", |
| 154 | (unsigned int)handler, irq); |
| 155 | return; |
| 156 | } |
| 157 | irq_handlers[irq].handler = handler; |
| 158 | irq_handlers[irq].arg = arg; |
| 159 | |
| 160 | /* enable irq on LEON2 hardware */ |
| 161 | leon2_ic_enable(irq); |
| 162 | |
| 163 | } |
| 164 | |
| 165 | void irq_free_handler(int irq) |
| 166 | { |
| 167 | if (irq < 0 || irq >= NR_IRQS) { |
| 168 | printf("irq_free_handler: bad irq number %d\n", irq); |
| 169 | return; |
| 170 | } |
| 171 | |
| 172 | /* disable irq on LEON2 hardware */ |
| 173 | leon2_ic_disable(irq); |
| 174 | |
| 175 | irq_handlers[irq].handler = NULL; |
| 176 | irq_handlers[irq].arg = NULL; |
| 177 | } |
| 178 | |
| 179 | /****************************************************************************/ |
| 180 | |
| 181 | #if defined(CONFIG_CMD_IRQ) |
Wolfgang Denk | 6262d021 | 2010-06-28 22:00:46 +0200 | [diff] [blame] | 182 | void do_irqinfo(cmd_tbl_t * cmdtp, bd_t * bd, int flag, int argc, char * const argv[]) |
Daniel Hellstrom | 207e695 | 2008-03-28 10:00:33 +0100 | [diff] [blame] | 183 | { |
| 184 | int irq; |
| 185 | unsigned int pil = get_pil(); |
| 186 | printf("PIL level: %u\n\r", pil); |
| 187 | printf("Spurious IRQ: %u, last unknown IRQ: %d\n", |
| 188 | spurious_irq_cnt, spurious_irq); |
| 189 | |
| 190 | puts("\nInterrupt-Information:\n" "Nr Routine Arg Count\n"); |
| 191 | |
| 192 | for (irq = 0; irq < NR_IRQS; irq++) { |
| 193 | if (irq_handlers[irq].handler != NULL) { |
Marek Vasut | 032b080 | 2012-07-27 08:04:34 +0000 | [diff] [blame] | 194 | printf("%02d %p %p %d\n", irq, |
| 195 | irq_handlers[irq].handler, |
| 196 | irq_handlers[irq].arg, |
Daniel Hellstrom | 207e695 | 2008-03-28 10:00:33 +0100 | [diff] [blame] | 197 | irq_handlers[irq].count); |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | #endif |