Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / arch / h8300 / kernel / irq.c
blobfbfce32f923a9f8df32fffde98ea82114c0b1efb
1 /*
2 * linux/arch/h8300/kernel/irq.c
4 * Copyright 2007 Yoshinori Sato <ysato@users.sourceforge.jp>
5 */
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>
17 #include <linux/interrupt.h>
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>
25 /*#define DEBUG*/
27 extern unsigned long *interrupt_redirect_table;
28 extern const int h8300_saved_vectors[];
29 <<<<<<< HEAD:arch/h8300/kernel/irq.c
30 extern const unsigned long h8300_trap_table[];
31 =======
32 extern const h8300_vector h8300_trap_table[];
33 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/h8300/kernel/irq.c
34 int h8300_enable_irq_pin(unsigned int irq);
35 void h8300_disable_irq_pin(unsigned int irq);
37 #define CPU_VECTOR ((unsigned long *)0x000000)
38 #define ADDR_MASK (0xffffff)
40 static inline int is_ext_irq(unsigned int irq)
42 return (irq >= EXT_IRQ0 && irq <= (EXT_IRQ0 + EXT_IRQS));
45 static void h8300_enable_irq(unsigned int irq)
47 if (is_ext_irq(irq))
48 IER_REGS |= 1 << (irq - EXT_IRQ0);
51 static void h8300_disable_irq(unsigned int irq)
53 if (is_ext_irq(irq))
54 IER_REGS &= ~(1 << (irq - EXT_IRQ0));
57 static void h8300_end_irq(unsigned int irq)
61 static unsigned int h8300_startup_irq(unsigned int irq)
63 if (is_ext_irq(irq))
64 return h8300_enable_irq_pin(irq);
65 else
66 return 0;
69 static void h8300_shutdown_irq(unsigned int irq)
71 if (is_ext_irq(irq))
72 h8300_disable_irq_pin(irq);
76 * h8300 interrupt controller implementation
78 struct irq_chip h8300irq_chip = {
79 .name = "H8300-INTC",
80 .startup = h8300_startup_irq,
81 .shutdown = h8300_shutdown_irq,
82 .enable = h8300_enable_irq,
83 .disable = h8300_disable_irq,
84 .ack = NULL,
85 .end = h8300_end_irq,
88 void ack_bad_irq(unsigned int irq)
90 printk("unexpected IRQ trap at vector %02x\n", irq);
93 #if defined(CONFIG_RAMKERNEL)
94 static unsigned long __init *get_vector_address(void)
96 unsigned long *rom_vector = CPU_VECTOR;
97 unsigned long base,tmp;
98 int vec_no;
100 base = rom_vector[EXT_IRQ0] & ADDR_MASK;
102 /* check romvector format */
103 for (vec_no = EXT_IRQ1; vec_no <= EXT_IRQ0+EXT_IRQS; vec_no++) {
104 if ((base+(vec_no - EXT_IRQ0)*4) != (rom_vector[vec_no] & ADDR_MASK))
105 return NULL;
108 /* ramvector base address */
109 base -= EXT_IRQ0*4;
111 /* writerble check */
112 tmp = ~(*(volatile unsigned long *)base);
113 (*(volatile unsigned long *)base) = tmp;
114 if ((*(volatile unsigned long *)base) != tmp)
115 return NULL;
116 return (unsigned long *)base;
119 static void __init setup_vector(void)
121 int i;
122 unsigned long *ramvec,*ramvec_p;
123 <<<<<<< HEAD:arch/h8300/kernel/irq.c
124 const unsigned long *trap_entry;
125 =======
126 const h8300_vector *trap_entry;
127 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:arch/h8300/kernel/irq.c
128 const int *saved_vector;
130 ramvec = get_vector_address();
131 if (ramvec == NULL)
132 panic("interrupt vector serup failed.");
133 else
134 printk(KERN_INFO "virtual vector at 0x%08lx\n",(unsigned long)ramvec);
136 /* create redirect table */
137 ramvec_p = ramvec;
138 trap_entry = h8300_trap_table;
139 saved_vector = h8300_saved_vectors;
140 for ( i = 0; i < NR_IRQS; i++) {
141 if (i == *saved_vector) {
142 ramvec_p++;
143 saved_vector++;
144 } else {
145 if ( i < NR_TRAPS ) {
146 if (*trap_entry)
147 *ramvec_p = VECTOR(*trap_entry);
148 ramvec_p++;
149 trap_entry++;
150 } else
151 *ramvec_p++ = REDIRECT(interrupt_entry);
154 interrupt_redirect_table = ramvec;
155 #ifdef DEBUG
156 ramvec_p = ramvec;
157 for (i = 0; i < NR_IRQS; i++) {
158 if ((i % 8) == 0)
159 printk(KERN_DEBUG "\n%p: ",ramvec_p);
160 printk(KERN_DEBUG "%p ",*ramvec_p);
161 ramvec_p++;
163 printk(KERN_DEBUG "\n");
164 #endif
166 #else
167 #define setup_vector() do { } while(0)
168 #endif
170 void __init init_IRQ(void)
172 int c;
174 setup_vector();
176 for (c = 0; c < NR_IRQS; c++) {
177 irq_desc[c].status = IRQ_DISABLED;
178 irq_desc[c].action = NULL;
179 irq_desc[c].depth = 1;
180 irq_desc[c].chip = &h8300irq_chip;
184 asmlinkage void do_IRQ(int irq)
186 irq_enter();
187 __do_IRQ(irq);
188 irq_exit();
191 #if defined(CONFIG_PROC_FS)
192 int show_interrupts(struct seq_file *p, void *v)
194 int i = *(loff_t *) v, j;
195 struct irqaction * action;
196 unsigned long flags;
198 if (i == 0)
199 seq_puts(p, " CPU0");
201 if (i < NR_IRQS) {
202 spin_lock_irqsave(&irq_desc[i].lock, flags);
203 action = irq_desc[i].action;
204 if (!action)
205 goto unlock;
206 seq_printf(p, "%3d: ",i);
207 seq_printf(p, "%10u ", kstat_cpu(j).irqs[i]);
208 seq_printf(p, " %14s", irq_desc[i].chip->name);
209 seq_printf(p, "-%-8s", irq_desc[i].name);
210 seq_printf(p, " %s", action->name);
212 for (action=action->next; action; action = action->next)
213 seq_printf(p, ", %s", action->name);
214 seq_putc(p, '\n');
215 unlock:
216 spin_unlock_irqrestore(&irq_desc[i].lock, flags);
218 return 0;
220 #endif