| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
|  | 2 | * linux/arch/h8300/platform/h8300h/ints.c | 
|  | 3 | * | 
|  | 4 | * Yoshinori Sato <ysato@users.sourceforge.jp> | 
|  | 5 | * | 
|  | 6 | * Based on linux/arch/$(ARCH)/platform/$(PLATFORM)/ints.c | 
|  | 7 | * | 
|  | 8 | * This file is subject to the terms and conditions of the GNU General Public | 
|  | 9 | * License.  See the file COPYING in the main directory of this archive | 
|  | 10 | * for more details. | 
|  | 11 | * | 
|  | 12 | * Copyright 1996 Roman Zippel | 
|  | 13 | * Copyright 1999 D. Jeff Dionne <jeff@rt-control.com> | 
|  | 14 | */ | 
|  | 15 |  | 
|  | 16 | #include <linux/module.h> | 
|  | 17 | #include <linux/types.h> | 
|  | 18 | #include <linux/kernel.h> | 
|  | 19 | #include <linux/sched.h> | 
|  | 20 | #include <linux/kernel_stat.h> | 
|  | 21 | #include <linux/seq_file.h> | 
|  | 22 | #include <linux/init.h> | 
|  | 23 | #include <linux/random.h> | 
|  | 24 | #include <linux/bootmem.h> | 
|  | 25 | #include <linux/hardirq.h> | 
|  | 26 |  | 
|  | 27 | #include <asm/system.h> | 
|  | 28 | #include <asm/irq.h> | 
|  | 29 | #include <asm/traps.h> | 
|  | 30 | #include <asm/io.h> | 
|  | 31 | #include <asm/setup.h> | 
|  | 32 | #include <asm/errno.h> | 
|  | 33 |  | 
|  | 34 | /* | 
|  | 35 | * This structure has only 4 elements for speed reasons | 
|  | 36 | */ | 
|  | 37 | typedef struct irq_handler { | 
|  | 38 | irqreturn_t (*handler)(int, void *, struct pt_regs *); | 
|  | 39 | int         flags; | 
|  | 40 | int         count; | 
|  | 41 | void	    *dev_id; | 
|  | 42 | const char  *devname; | 
|  | 43 | } irq_handler_t; | 
|  | 44 |  | 
|  | 45 | static irq_handler_t *irq_list[NR_IRQS]; | 
|  | 46 | static int use_kmalloc; | 
|  | 47 |  | 
|  | 48 | extern unsigned long *interrupt_redirect_table; | 
|  | 49 | extern const int h8300_saved_vectors[]; | 
|  | 50 | extern const unsigned long h8300_trap_table[]; | 
|  | 51 | int h8300_enable_irq_pin(unsigned int irq); | 
|  | 52 | void h8300_disable_irq_pin(unsigned int irq); | 
|  | 53 |  | 
|  | 54 | #define CPU_VECTOR ((unsigned long *)0x000000) | 
|  | 55 | #define ADDR_MASK (0xffffff) | 
|  | 56 |  | 
|  | 57 | #if defined(CONFIG_RAMKERNEL) | 
|  | 58 | static unsigned long __init *get_vector_address(void) | 
|  | 59 | { | 
|  | 60 | unsigned long *rom_vector = CPU_VECTOR; | 
|  | 61 | unsigned long base,tmp; | 
|  | 62 | int vec_no; | 
|  | 63 |  | 
|  | 64 | base = rom_vector[EXT_IRQ0] & ADDR_MASK; | 
|  | 65 |  | 
|  | 66 | /* check romvector format */ | 
|  | 67 | for (vec_no = EXT_IRQ1; vec_no <= EXT_IRQ0+EXT_IRQS; vec_no++) { | 
|  | 68 | if ((base+(vec_no - EXT_IRQ0)*4) != (rom_vector[vec_no] & ADDR_MASK)) | 
|  | 69 | return NULL; | 
|  | 70 | } | 
|  | 71 |  | 
|  | 72 | /* ramvector base address */ | 
|  | 73 | base -= EXT_IRQ0*4; | 
|  | 74 |  | 
|  | 75 | /* writerble check */ | 
|  | 76 | tmp = ~(*(volatile unsigned long *)base); | 
|  | 77 | (*(volatile unsigned long *)base) = tmp; | 
|  | 78 | if ((*(volatile unsigned long *)base) != tmp) | 
|  | 79 | return NULL; | 
|  | 80 | return (unsigned long *)base; | 
|  | 81 | } | 
|  | 82 | #endif | 
|  | 83 |  | 
|  | 84 | void __init init_IRQ(void) | 
|  | 85 | { | 
|  | 86 | #if defined(CONFIG_RAMKERNEL) | 
|  | 87 | int i; | 
|  | 88 | unsigned long *ramvec,*ramvec_p; | 
|  | 89 | const unsigned long *trap_entry; | 
|  | 90 | const int *saved_vector; | 
|  | 91 |  | 
|  | 92 | ramvec = get_vector_address(); | 
|  | 93 | if (ramvec == NULL) | 
|  | 94 | panic("interrupt vector serup failed."); | 
|  | 95 | else | 
|  | 96 | printk(KERN_INFO "virtual vector at 0x%08lx\n",(unsigned long)ramvec); | 
|  | 97 |  | 
|  | 98 | /* create redirect table */ | 
|  | 99 | ramvec_p = ramvec; | 
|  | 100 | trap_entry = h8300_trap_table; | 
|  | 101 | saved_vector = h8300_saved_vectors; | 
|  | 102 | for ( i = 0; i < NR_IRQS; i++) { | 
|  | 103 | if (i == *saved_vector) { | 
|  | 104 | ramvec_p++; | 
|  | 105 | saved_vector++; | 
|  | 106 | } else { | 
|  | 107 | if ( i < NR_TRAPS ) { | 
|  | 108 | if (*trap_entry) | 
|  | 109 | *ramvec_p = VECTOR(*trap_entry); | 
|  | 110 | ramvec_p++; | 
|  | 111 | trap_entry++; | 
|  | 112 | } else | 
|  | 113 | *ramvec_p++ = REDIRECT(interrupt_entry); | 
|  | 114 | } | 
|  | 115 | } | 
|  | 116 | interrupt_redirect_table = ramvec; | 
|  | 117 | #ifdef DUMP_VECTOR | 
|  | 118 | ramvec_p = ramvec; | 
|  | 119 | for (i = 0; i < NR_IRQS; i++) { | 
|  | 120 | if ((i % 8) == 0) | 
|  | 121 | printk(KERN_DEBUG "\n%p: ",ramvec_p); | 
|  | 122 | printk(KERN_DEBUG "%p ",*ramvec_p); | 
|  | 123 | ramvec_p++; | 
|  | 124 | } | 
|  | 125 | printk(KERN_DEBUG "\n"); | 
|  | 126 | #endif | 
|  | 127 | #endif | 
|  | 128 | } | 
|  | 129 |  | 
|  | 130 | int request_irq(unsigned int irq, | 
|  | 131 | irqreturn_t (*handler)(int, void *, struct pt_regs *), | 
|  | 132 | unsigned long flags, const char *devname, void *dev_id) | 
|  | 133 | { | 
|  | 134 | irq_handler_t *irq_handle; | 
|  | 135 | if (irq < 0 || irq >= NR_IRQS) { | 
|  | 136 | printk(KERN_ERR "Incorrect IRQ %d from %s\n", irq, devname); | 
|  | 137 | return -EINVAL; | 
|  | 138 | } | 
|  | 139 |  | 
|  | 140 | if (irq_list[irq] || (h8300_enable_irq_pin(irq) == -EBUSY)) | 
|  | 141 | return -EBUSY; | 
|  | 142 |  | 
|  | 143 | if (use_kmalloc) | 
|  | 144 | irq_handle = (irq_handler_t *)kmalloc(sizeof(irq_handler_t), GFP_ATOMIC); | 
|  | 145 | else { | 
|  | 146 | /* use bootmem allocater */ | 
|  | 147 | irq_handle = (irq_handler_t *)alloc_bootmem(sizeof(irq_handler_t)); | 
|  | 148 | irq_handle = (irq_handler_t *)((unsigned long)irq_handle | 0x80000000); | 
|  | 149 | } | 
|  | 150 |  | 
|  | 151 | if (irq_handle == NULL) | 
|  | 152 | return -ENOMEM; | 
|  | 153 |  | 
|  | 154 | irq_handle->handler = handler; | 
|  | 155 | irq_handle->flags   = flags; | 
|  | 156 | irq_handle->count   = 0; | 
|  | 157 | irq_handle->dev_id  = dev_id; | 
|  | 158 | irq_handle->devname = devname; | 
|  | 159 | irq_list[irq] = irq_handle; | 
|  | 160 |  | 
| Thomas Gleixner | b98d339 | 2006-07-01 19:29:15 -0700 | [diff] [blame] | 161 | if (irq_handle->flags & IRQF_SAMPLE_RANDOM) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | rand_initialize_irq(irq); | 
|  | 163 |  | 
|  | 164 | enable_irq(irq); | 
|  | 165 | return 0; | 
|  | 166 | } | 
|  | 167 |  | 
|  | 168 | EXPORT_SYMBOL(request_irq); | 
|  | 169 |  | 
|  | 170 | void free_irq(unsigned int irq, void *dev_id) | 
|  | 171 | { | 
|  | 172 | if (irq >= NR_IRQS) | 
|  | 173 | return; | 
|  | 174 |  | 
|  | 175 | if (!irq_list[irq] || irq_list[irq]->dev_id != dev_id) | 
|  | 176 | printk(KERN_WARNING "Removing probably wrong IRQ %d from %s\n", | 
|  | 177 | irq, irq_list[irq]->devname); | 
|  | 178 | disable_irq(irq); | 
|  | 179 | h8300_disable_irq_pin(irq); | 
|  | 180 | if (((unsigned long)irq_list[irq] & 0x80000000) == 0) { | 
|  | 181 | kfree(irq_list[irq]); | 
|  | 182 | irq_list[irq] = NULL; | 
|  | 183 | } | 
|  | 184 | } | 
|  | 185 |  | 
|  | 186 | EXPORT_SYMBOL(free_irq); | 
|  | 187 |  | 
|  | 188 | /* | 
|  | 189 | * Do we need these probe functions on the m68k? | 
|  | 190 | */ | 
|  | 191 | unsigned long probe_irq_on (void) | 
|  | 192 | { | 
|  | 193 | return 0; | 
|  | 194 | } | 
|  | 195 |  | 
|  | 196 | EXPORT_SYMBOL(probe_irq_on); | 
|  | 197 |  | 
|  | 198 | int probe_irq_off (unsigned long irqs) | 
|  | 199 | { | 
|  | 200 | return 0; | 
|  | 201 | } | 
|  | 202 |  | 
|  | 203 | EXPORT_SYMBOL(probe_irq_off); | 
|  | 204 |  | 
|  | 205 | void enable_irq(unsigned int irq) | 
|  | 206 | { | 
|  | 207 | if (irq >= EXT_IRQ0 && irq <= (EXT_IRQ0 + EXT_IRQS)) | 
|  | 208 | IER_REGS |= 1 << (irq - EXT_IRQ0); | 
|  | 209 | } | 
|  | 210 |  | 
|  | 211 | void disable_irq(unsigned int irq) | 
|  | 212 | { | 
|  | 213 | if (irq >= EXT_IRQ0 && irq <= (EXT_IRQ0 + EXT_IRQS)) | 
|  | 214 | IER_REGS &= ~(1 << (irq - EXT_IRQ0)); | 
|  | 215 | } | 
|  | 216 |  | 
|  | 217 | asmlinkage void process_int(int irq, struct pt_regs *fp) | 
|  | 218 | { | 
|  | 219 | irq_enter(); | 
|  | 220 | h8300_clear_isr(irq); | 
|  | 221 | if (irq >= NR_TRAPS && irq < NR_IRQS) { | 
|  | 222 | if (irq_list[irq]) { | 
|  | 223 | irq_list[irq]->handler(irq, irq_list[irq]->dev_id, fp); | 
|  | 224 | irq_list[irq]->count++; | 
| Thomas Gleixner | b98d339 | 2006-07-01 19:29:15 -0700 | [diff] [blame] | 225 | if (irq_list[irq]->flags & IRQF_SAMPLE_RANDOM) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | add_interrupt_randomness(irq); | 
|  | 227 | } | 
|  | 228 | } else { | 
|  | 229 | BUG(); | 
|  | 230 | } | 
|  | 231 | irq_exit(); | 
|  | 232 | } | 
|  | 233 |  | 
|  | 234 | int show_interrupts(struct seq_file *p, void *v) | 
|  | 235 | { | 
|  | 236 | int i = *(loff_t *) v; | 
|  | 237 |  | 
|  | 238 | if ((i < NR_IRQS) && (irq_list[i]!=NULL)) { | 
|  | 239 | seq_printf(p, "%3d: %10u ",i,irq_list[i]->count); | 
|  | 240 | seq_printf(p, "%s\n", irq_list[i]->devname); | 
|  | 241 | } | 
|  | 242 |  | 
|  | 243 | return 0; | 
|  | 244 | } | 
|  | 245 |  | 
|  | 246 | void init_irq_proc(void) | 
|  | 247 | { | 
|  | 248 | } | 
|  | 249 |  | 
|  | 250 | static int __init enable_kmalloc(void) | 
|  | 251 | { | 
|  | 252 | use_kmalloc = 1; | 
|  | 253 | return 0; | 
|  | 254 | } | 
|  | 255 | core_initcall(enable_kmalloc); |