Yoshinori Sato | c728d60 | 2007-05-06 14:50:35 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/h8300/kernel/irq.c |
| 3 | * |
| 4 | * Copyright 2007 Yoshinori Sato <ysato@users.sourceforge.jp> |
| 5 | */ |
| 6 | |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/types.h> |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/sched.h> |
| 11 | #include <linux/kernel_stat.h> |
| 12 | #include <linux/seq_file.h> |
| 13 | #include <linux/init.h> |
| 14 | #include <linux/random.h> |
| 15 | #include <linux/bootmem.h> |
| 16 | #include <linux/irq.h> |
Adrian Bunk | f74596d | 2008-02-06 01:36:35 -0800 | [diff] [blame] | 17 | #include <linux/interrupt.h> |
Yoshinori Sato | c728d60 | 2007-05-06 14:50:35 -0700 | [diff] [blame] | 18 | |
| 19 | #include <asm/system.h> |
| 20 | #include <asm/traps.h> |
| 21 | #include <asm/io.h> |
| 22 | #include <asm/setup.h> |
| 23 | #include <asm/errno.h> |
| 24 | |
| 25 | /*#define DEBUG*/ |
| 26 | |
| 27 | extern unsigned long *interrupt_redirect_table; |
| 28 | extern const int h8300_saved_vectors[]; |
Yoshinori Sato | 5cc265a | 2008-02-23 15:23:59 -0800 | [diff] [blame] | 29 | extern const h8300_vector h8300_trap_table[]; |
Yoshinori Sato | c728d60 | 2007-05-06 14:50:35 -0700 | [diff] [blame] | 30 | int h8300_enable_irq_pin(unsigned int irq); |
| 31 | void h8300_disable_irq_pin(unsigned int irq); |
| 32 | |
| 33 | #define CPU_VECTOR ((unsigned long *)0x000000) |
| 34 | #define ADDR_MASK (0xffffff) |
| 35 | |
| 36 | static inline int is_ext_irq(unsigned int irq) |
| 37 | { |
| 38 | return (irq >= EXT_IRQ0 && irq <= (EXT_IRQ0 + EXT_IRQS)); |
| 39 | } |
| 40 | |
| 41 | static void h8300_enable_irq(unsigned int irq) |
| 42 | { |
| 43 | if (is_ext_irq(irq)) |
| 44 | IER_REGS |= 1 << (irq - EXT_IRQ0); |
| 45 | } |
| 46 | |
| 47 | static void h8300_disable_irq(unsigned int irq) |
| 48 | { |
| 49 | if (is_ext_irq(irq)) |
| 50 | IER_REGS &= ~(1 << (irq - EXT_IRQ0)); |
| 51 | } |
| 52 | |
| 53 | static void h8300_end_irq(unsigned int irq) |
| 54 | { |
| 55 | } |
| 56 | |
| 57 | static unsigned int h8300_startup_irq(unsigned int irq) |
| 58 | { |
| 59 | if (is_ext_irq(irq)) |
| 60 | return h8300_enable_irq_pin(irq); |
| 61 | else |
| 62 | return 0; |
| 63 | } |
| 64 | |
| 65 | static void h8300_shutdown_irq(unsigned int irq) |
| 66 | { |
| 67 | if (is_ext_irq(irq)) |
| 68 | h8300_disable_irq_pin(irq); |
| 69 | } |
| 70 | |
| 71 | /* |
Robert P. J. Day | 3a4fa0a | 2007-10-19 23:10:43 +0200 | [diff] [blame] | 72 | * h8300 interrupt controller implementation |
Yoshinori Sato | c728d60 | 2007-05-06 14:50:35 -0700 | [diff] [blame] | 73 | */ |
| 74 | struct irq_chip h8300irq_chip = { |
| 75 | .name = "H8300-INTC", |
| 76 | .startup = h8300_startup_irq, |
| 77 | .shutdown = h8300_shutdown_irq, |
| 78 | .enable = h8300_enable_irq, |
| 79 | .disable = h8300_disable_irq, |
| 80 | .ack = NULL, |
| 81 | .end = h8300_end_irq, |
| 82 | }; |
| 83 | |
Yoshinori Sato | c728d60 | 2007-05-06 14:50:35 -0700 | [diff] [blame] | 84 | #if defined(CONFIG_RAMKERNEL) |
| 85 | static unsigned long __init *get_vector_address(void) |
| 86 | { |
| 87 | unsigned long *rom_vector = CPU_VECTOR; |
| 88 | unsigned long base,tmp; |
| 89 | int vec_no; |
| 90 | |
| 91 | base = rom_vector[EXT_IRQ0] & ADDR_MASK; |
| 92 | |
| 93 | /* check romvector format */ |
| 94 | for (vec_no = EXT_IRQ1; vec_no <= EXT_IRQ0+EXT_IRQS; vec_no++) { |
| 95 | if ((base+(vec_no - EXT_IRQ0)*4) != (rom_vector[vec_no] & ADDR_MASK)) |
| 96 | return NULL; |
| 97 | } |
| 98 | |
| 99 | /* ramvector base address */ |
| 100 | base -= EXT_IRQ0*4; |
| 101 | |
| 102 | /* writerble check */ |
| 103 | tmp = ~(*(volatile unsigned long *)base); |
| 104 | (*(volatile unsigned long *)base) = tmp; |
| 105 | if ((*(volatile unsigned long *)base) != tmp) |
| 106 | return NULL; |
| 107 | return (unsigned long *)base; |
| 108 | } |
| 109 | |
| 110 | static void __init setup_vector(void) |
| 111 | { |
| 112 | int i; |
| 113 | unsigned long *ramvec,*ramvec_p; |
Yoshinori Sato | 5cc265a | 2008-02-23 15:23:59 -0800 | [diff] [blame] | 114 | const h8300_vector *trap_entry; |
Yoshinori Sato | c728d60 | 2007-05-06 14:50:35 -0700 | [diff] [blame] | 115 | const int *saved_vector; |
| 116 | |
| 117 | ramvec = get_vector_address(); |
| 118 | if (ramvec == NULL) |
| 119 | panic("interrupt vector serup failed."); |
| 120 | else |
| 121 | printk(KERN_INFO "virtual vector at 0x%08lx\n",(unsigned long)ramvec); |
| 122 | |
| 123 | /* create redirect table */ |
| 124 | ramvec_p = ramvec; |
| 125 | trap_entry = h8300_trap_table; |
| 126 | saved_vector = h8300_saved_vectors; |
| 127 | for ( i = 0; i < NR_IRQS; i++) { |
| 128 | if (i == *saved_vector) { |
| 129 | ramvec_p++; |
| 130 | saved_vector++; |
| 131 | } else { |
| 132 | if ( i < NR_TRAPS ) { |
| 133 | if (*trap_entry) |
| 134 | *ramvec_p = VECTOR(*trap_entry); |
| 135 | ramvec_p++; |
| 136 | trap_entry++; |
| 137 | } else |
| 138 | *ramvec_p++ = REDIRECT(interrupt_entry); |
| 139 | } |
| 140 | } |
| 141 | interrupt_redirect_table = ramvec; |
| 142 | #ifdef DEBUG |
| 143 | ramvec_p = ramvec; |
| 144 | for (i = 0; i < NR_IRQS; i++) { |
| 145 | if ((i % 8) == 0) |
| 146 | printk(KERN_DEBUG "\n%p: ",ramvec_p); |
| 147 | printk(KERN_DEBUG "%p ",*ramvec_p); |
| 148 | ramvec_p++; |
| 149 | } |
| 150 | printk(KERN_DEBUG "\n"); |
| 151 | #endif |
| 152 | } |
| 153 | #else |
| 154 | #define setup_vector() do { } while(0) |
| 155 | #endif |
| 156 | |
| 157 | void __init init_IRQ(void) |
| 158 | { |
| 159 | int c; |
| 160 | |
| 161 | setup_vector(); |
| 162 | |
| 163 | for (c = 0; c < NR_IRQS; c++) { |
| 164 | irq_desc[c].status = IRQ_DISABLED; |
| 165 | irq_desc[c].action = NULL; |
| 166 | irq_desc[c].depth = 1; |
| 167 | irq_desc[c].chip = &h8300irq_chip; |
| 168 | } |
| 169 | } |
| 170 | |
| 171 | asmlinkage void do_IRQ(int irq) |
| 172 | { |
| 173 | irq_enter(); |
| 174 | __do_IRQ(irq); |
| 175 | irq_exit(); |
| 176 | } |
| 177 | |
| 178 | #if defined(CONFIG_PROC_FS) |
| 179 | int show_interrupts(struct seq_file *p, void *v) |
| 180 | { |
Yinghai Lu | dee4102 | 2009-01-11 00:29:15 -0800 | [diff] [blame] | 181 | int i = *(loff_t *) v; |
Yoshinori Sato | c728d60 | 2007-05-06 14:50:35 -0700 | [diff] [blame] | 182 | struct irqaction * action; |
| 183 | unsigned long flags; |
| 184 | |
| 185 | if (i == 0) |
| 186 | seq_puts(p, " CPU0"); |
| 187 | |
| 188 | if (i < NR_IRQS) { |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 189 | raw_spin_lock_irqsave(&irq_desc[i].lock, flags); |
Yoshinori Sato | c728d60 | 2007-05-06 14:50:35 -0700 | [diff] [blame] | 190 | action = irq_desc[i].action; |
| 191 | if (!action) |
| 192 | goto unlock; |
| 193 | seq_printf(p, "%3d: ",i); |
Yinghai Lu | dee4102 | 2009-01-11 00:29:15 -0800 | [diff] [blame] | 194 | seq_printf(p, "%10u ", kstat_irqs(i)); |
Yoshinori Sato | c728d60 | 2007-05-06 14:50:35 -0700 | [diff] [blame] | 195 | seq_printf(p, " %14s", irq_desc[i].chip->name); |
| 196 | seq_printf(p, "-%-8s", irq_desc[i].name); |
| 197 | seq_printf(p, " %s", action->name); |
| 198 | |
| 199 | for (action=action->next; action; action = action->next) |
| 200 | seq_printf(p, ", %s", action->name); |
| 201 | seq_putc(p, '\n'); |
| 202 | unlock: |
Thomas Gleixner | 239007b | 2009-11-17 16:46:45 +0100 | [diff] [blame] | 203 | raw_spin_unlock_irqrestore(&irq_desc[i].lock, flags); |
Yoshinori Sato | c728d60 | 2007-05-06 14:50:35 -0700 | [diff] [blame] | 204 | } |
| 205 | return 0; |
| 206 | } |
| 207 | #endif |