2 * linux/arch/h8300/kernel/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/interrupt.h>
23 #include <linux/init.h>
24 #include <linux/random.h>
25 #include <linux/bootmem.h>
26 #include <linux/hardirq.h>
28 #include <asm/system.h>
30 #include <asm/traps.h>
32 #include <asm/setup.h>
33 #include <asm/errno.h>
36 * This structure has only 4 elements for speed reasons
38 typedef struct irq_handler
{
39 irqreturn_t (*handler
)(int, void *, struct pt_regs
*);
46 static irq_handler_t
*irq_list
[NR_IRQS
];
47 static int use_kmalloc
;
49 extern unsigned long *interrupt_redirect_table
;
50 extern const int h8300_saved_vectors
[];
51 extern const unsigned long h8300_trap_table
[];
52 int h8300_enable_irq_pin(unsigned int irq
);
53 void h8300_disable_irq_pin(unsigned int irq
);
55 #define CPU_VECTOR ((unsigned long *)0x000000)
56 #define ADDR_MASK (0xffffff)
58 #if defined(CONFIG_RAMKERNEL)
59 static unsigned long __init
*get_vector_address(void)
61 unsigned long *rom_vector
= CPU_VECTOR
;
62 unsigned long base
,tmp
;
65 base
= rom_vector
[EXT_IRQ0
] & ADDR_MASK
;
67 /* check romvector format */
68 for (vec_no
= EXT_IRQ1
; vec_no
<= EXT_IRQ0
+EXT_IRQS
; vec_no
++) {
69 if ((base
+(vec_no
- EXT_IRQ0
)*4) != (rom_vector
[vec_no
] & ADDR_MASK
))
73 /* ramvector base address */
77 tmp
= ~(*(volatile unsigned long *)base
);
78 (*(volatile unsigned long *)base
) = tmp
;
79 if ((*(volatile unsigned long *)base
) != tmp
)
81 return (unsigned long *)base
;
85 void __init
init_IRQ(void)
87 #if defined(CONFIG_RAMKERNEL)
89 unsigned long *ramvec
,*ramvec_p
;
90 const unsigned long *trap_entry
;
91 const int *saved_vector
;
93 ramvec
= get_vector_address();
95 panic("interrupt vector serup failed.");
97 printk(KERN_INFO
"virtual vector at 0x%08lx\n",(unsigned long)ramvec
);
99 /* create redirect table */
101 trap_entry
= h8300_trap_table
;
102 saved_vector
= h8300_saved_vectors
;
103 for ( i
= 0; i
< NR_IRQS
; i
++) {
104 if (i
== *saved_vector
) {
108 if ( i
< NR_TRAPS
) {
110 *ramvec_p
= VECTOR(*trap_entry
);
114 *ramvec_p
++ = REDIRECT(interrupt_entry
);
117 interrupt_redirect_table
= ramvec
;
120 for (i
= 0; i
< NR_IRQS
; i
++) {
122 printk(KERN_DEBUG
"\n%p: ",ramvec_p
);
123 printk(KERN_DEBUG
"%p ",*ramvec_p
);
126 printk(KERN_DEBUG
"\n");
131 int request_irq(unsigned int irq
,
132 irqreturn_t (*handler
)(int, void *, struct pt_regs
*),
133 unsigned long flags
, const char *devname
, void *dev_id
)
135 irq_handler_t
*irq_handle
;
136 if (irq
< 0 || irq
>= NR_IRQS
) {
137 printk(KERN_ERR
"Incorrect IRQ %d from %s\n", irq
, devname
);
141 if (irq_list
[irq
] || (h8300_enable_irq_pin(irq
) == -EBUSY
))
145 irq_handle
= kmalloc(sizeof(irq_handler_t
), GFP_ATOMIC
);
147 /* use bootmem allocater */
148 irq_handle
= (irq_handler_t
*)alloc_bootmem(sizeof(irq_handler_t
));
149 irq_handle
= (irq_handler_t
*)((unsigned long)irq_handle
| 0x80000000);
152 if (irq_handle
== NULL
)
155 irq_handle
->handler
= handler
;
156 irq_handle
->flags
= flags
;
157 irq_handle
->count
= 0;
158 irq_handle
->dev_id
= dev_id
;
159 irq_handle
->devname
= devname
;
160 irq_list
[irq
] = irq_handle
;
162 if (irq_handle
->flags
& IRQF_SAMPLE_RANDOM
)
163 rand_initialize_irq(irq
);
169 EXPORT_SYMBOL(request_irq
);
171 void free_irq(unsigned int irq
, void *dev_id
)
176 if (!irq_list
[irq
] || irq_list
[irq
]->dev_id
!= dev_id
)
177 printk(KERN_WARNING
"Removing probably wrong IRQ %d from %s\n",
178 irq
, irq_list
[irq
]->devname
);
180 h8300_disable_irq_pin(irq
);
181 if (((unsigned long)irq_list
[irq
] & 0x80000000) == 0) {
182 kfree(irq_list
[irq
]);
183 irq_list
[irq
] = NULL
;
187 EXPORT_SYMBOL(free_irq
);
190 * Do we need these probe functions on the m68k?
192 unsigned long probe_irq_on (void)
197 EXPORT_SYMBOL(probe_irq_on
);
199 int probe_irq_off (unsigned long irqs
)
204 EXPORT_SYMBOL(probe_irq_off
);
206 void enable_irq(unsigned int irq
)
208 if (irq
>= EXT_IRQ0
&& irq
<= (EXT_IRQ0
+ EXT_IRQS
))
209 IER_REGS
|= 1 << (irq
- EXT_IRQ0
);
212 void disable_irq(unsigned int irq
)
214 if (irq
>= EXT_IRQ0
&& irq
<= (EXT_IRQ0
+ EXT_IRQS
))
215 IER_REGS
&= ~(1 << (irq
- EXT_IRQ0
));
218 asmlinkage
void process_int(int irq
, struct pt_regs
*fp
)
221 h8300_clear_isr(irq
);
222 if (irq
>= NR_TRAPS
&& irq
< NR_IRQS
) {
224 irq_list
[irq
]->handler(irq
, irq_list
[irq
]->dev_id
, fp
);
225 irq_list
[irq
]->count
++;
226 if (irq_list
[irq
]->flags
& IRQF_SAMPLE_RANDOM
)
227 add_interrupt_randomness(irq
);
235 int show_interrupts(struct seq_file
*p
, void *v
)
237 int i
= *(loff_t
*) v
;
239 if ((i
< NR_IRQS
) && (irq_list
[i
]!=NULL
)) {
240 seq_printf(p
, "%3d: %10u ",i
,irq_list
[i
]->count
);
241 seq_printf(p
, "%s\n", irq_list
[i
]->devname
);
247 void init_irq_proc(void)
251 static int __init
enable_kmalloc(void)
256 core_initcall(enable_kmalloc
);