2 * linux/arch/h8300/platform/h8300h/ints.c
4 * Yoshinori Sato <ysato@users.sourceforge.jp>
6 * Based on linux/arch/$(ARCH)/platform/$(PLATFORM)/ints.c
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
12 * Copyright 1996 Roman Zippel
13 * Copyright 1999 D. Jeff Dionne <jeff@rt-control.com>
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>
27 #include <asm/system.h>
29 #include <asm/traps.h>
31 #include <asm/setup.h>
32 #include <asm/errno.h>
35 * This structure has only 4 elements for speed reasons
37 typedef struct irq_handler {
38 irqreturn_t (*handler)(int, void *, struct pt_regs *);
45 static irq_handler_t *irq_list[NR_IRQS];
46 static int use_kmalloc;
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);
54 #define CPU_VECTOR ((unsigned long *)0x000000)
55 #define ADDR_MASK (0xffffff)
57 #if defined(CONFIG_RAMKERNEL)
58 static unsigned long __init *get_vector_address(void)
60 unsigned long *rom_vector = CPU_VECTOR;
61 unsigned long base,tmp;
64 base = rom_vector[EXT_IRQ0] & ADDR_MASK;
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))
72 /* ramvector base address */
76 tmp = ~(*(volatile unsigned long *)base);
77 (*(volatile unsigned long *)base) = tmp;
78 if ((*(volatile unsigned long *)base) != tmp)
80 return (unsigned long *)base;
84 void __init init_IRQ(void)
86 #if defined(CONFIG_RAMKERNEL)
88 unsigned long *ramvec,*ramvec_p;
89 const unsigned long *trap_entry;
90 const int *saved_vector;
92 ramvec = get_vector_address();
94 panic("interrupt vector serup failed.");
96 printk(KERN_INFO "virtual vector at 0x%08lx\n",(unsigned long)ramvec);
98 /* create redirect table */
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) {
107 if ( i < NR_TRAPS ) {
109 *ramvec_p = VECTOR(*trap_entry);
113 *ramvec_p++ = REDIRECT(interrupt_entry);
116 interrupt_redirect_table = ramvec;
119 for (i = 0; i < NR_IRQS; i++) {
121 printk(KERN_DEBUG "\n%p: ",ramvec_p);
122 printk(KERN_DEBUG "%p ",*ramvec_p);
125 printk(KERN_DEBUG "\n");
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)
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);
140 if (irq_list[irq] || (h8300_enable_irq_pin(irq) == -EBUSY))
144 irq_handle = (irq_handler_t *)kmalloc(sizeof(irq_handler_t), GFP_ATOMIC);
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);
151 if (irq_handle == NULL)
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;
161 if (irq_handle->flags & SA_SAMPLE_RANDOM)
162 rand_initialize_irq(irq);
168 EXPORT_SYMBOL(request_irq);
170 void free_irq(unsigned int irq, void *dev_id)
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);
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;
186 EXPORT_SYMBOL(free_irq);
189 * Do we need these probe functions on the m68k?
191 unsigned long probe_irq_on (void)
196 EXPORT_SYMBOL(probe_irq_on);
198 int probe_irq_off (unsigned long irqs)
203 EXPORT_SYMBOL(probe_irq_off);
205 void enable_irq(unsigned int irq)
207 if (irq >= EXT_IRQ0 && irq <= (EXT_IRQ0 + EXT_IRQS))
208 IER_REGS |= 1 << (irq - EXT_IRQ0);
211 void disable_irq(unsigned int irq)
213 if (irq >= EXT_IRQ0 && irq <= (EXT_IRQ0 + EXT_IRQS))
214 IER_REGS &= ~(1 << (irq - EXT_IRQ0));
217 asmlinkage void process_int(int irq, struct pt_regs *fp)
220 h8300_clear_isr(irq);
221 if (irq >= NR_TRAPS && irq < NR_IRQS) {
223 irq_list[irq]->handler(irq, irq_list[irq]->dev_id, fp);
224 irq_list[irq]->count++;
225 if (irq_list[irq]->flags & SA_SAMPLE_RANDOM)
226 add_interrupt_randomness(irq);
234 int show_interrupts(struct seq_file *p, void *v)
236 int i = *(loff_t *) v;
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);
246 void init_irq_proc(void)
250 static int __init enable_kmalloc(void)
255 core_initcall(enable_kmalloc);