[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / arch / h8300 / kernel / ints.c
blobedb3c4170013c417d53fa8258bf9f736eaf45bff
1 /*
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
10 * for more details.
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>
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>
35 * This structure has only 4 elements for speed reasons
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;
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;
62 int vec_no;
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))
69 return NULL;
72 /* ramvector base address */
73 base -= EXT_IRQ0*4;
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;
82 #endif
84 void __init init_IRQ(void)
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;
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);
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);
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++;
125 printk(KERN_DEBUG "\n");
126 #endif
127 #endif
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);
137 return -EINVAL;
140 if (irq_list[irq] || (h8300_enable_irq_pin(irq) == -EBUSY))
141 return -EBUSY;
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);
151 if (irq_handle == NULL)
152 return -ENOMEM;
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);
164 enable_irq(irq);
165 return 0;
168 EXPORT_SYMBOL(request_irq);
170 void free_irq(unsigned int irq, void *dev_id)
172 if (irq >= NR_IRQS)
173 return;
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;
186 EXPORT_SYMBOL(free_irq);
189 * Do we need these probe functions on the m68k?
191 unsigned long probe_irq_on (void)
193 return 0;
196 EXPORT_SYMBOL(probe_irq_on);
198 int probe_irq_off (unsigned long irqs)
200 return 0;
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)
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++;
225 if (irq_list[irq]->flags & SA_SAMPLE_RANDOM)
226 add_interrupt_randomness(irq);
228 } else {
229 BUG();
231 irq_exit();
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);
243 return 0;
246 void init_irq_proc(void)
250 static int __init enable_kmalloc(void)
252 use_kmalloc = 1;
253 return 0;
255 core_initcall(enable_kmalloc);