1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * linux/arch/h8300/kernel/irq.c
4  *
5  * Copyright 2014-2015 Yoshinori Sato <ysato@users.sourceforge.jp>
6  */
7 
8 #include <linux/init.h>
9 #include <linux/interrupt.h>
10 #include <linux/irq.h>
11 #include <linux/irqchip.h>
12 #include <linux/irqdomain.h>
13 #include <linux/of_irq.h>
14 #include <asm/traps.h>
15 
16 #ifdef CONFIG_RAMKERNEL
17 typedef void (*h8300_vector)(void);
18 
19 static const h8300_vector __initconst trap_table[] = {
20 	0, 0, 0, 0,
21 	_trace_break,
22 	0, 0,
23 	_nmi,
24 	_system_call,
25 	0, 0,
26 	_trace_break,
27 };
28 
get_vector_address(void)29 static unsigned long __init *get_vector_address(void)
30 {
31 	unsigned long *rom_vector = CPU_VECTOR;
32 	unsigned long base, tmp;
33 	int vec_no;
34 
35 	base = rom_vector[EXT_IRQ0] & ADDR_MASK;
36 
37 	/* check romvector format */
38 	for (vec_no = EXT_IRQ0 + 1; vec_no <= EXT_IRQ0+EXT_IRQS; vec_no++) {
39 		if ((base+(vec_no - EXT_IRQ0)*4) !=
40 		    (rom_vector[vec_no] & ADDR_MASK))
41 			return NULL;
42 	}
43 
44 	/* ramvector base address */
45 	base -= EXT_IRQ0*4;
46 
47 	/* writerble? */
48 	tmp = ~(*(volatile unsigned long *)base);
49 	(*(volatile unsigned long *)base) = tmp;
50 	if ((*(volatile unsigned long *)base) != tmp)
51 		return NULL;
52 	return (unsigned long *)base;
53 }
54 
setup_vector(void)55 static void __init setup_vector(void)
56 {
57 	int i;
58 	unsigned long *ramvec, *ramvec_p;
59 	const h8300_vector *trap_entry;
60 
61 	ramvec = get_vector_address();
62 	if (ramvec == NULL)
63 		panic("interrupt vector serup failed.");
64 	else
65 		pr_debug("virtual vector at 0x%p\n", ramvec);
66 
67 	/* create redirect table */
68 	ramvec_p = ramvec;
69 	trap_entry = trap_table;
70 	for (i = 0; i < NR_IRQS; i++) {
71 		if (i < 12) {
72 			if (*trap_entry)
73 				*ramvec_p = VECTOR(*trap_entry);
74 			ramvec_p++;
75 			trap_entry++;
76 		} else
77 			*ramvec_p++ = REDIRECT(_interrupt_entry);
78 	}
79 	_interrupt_redirect_table = ramvec;
80 }
81 #else
setup_vector(void)82 void setup_vector(void)
83 {
84 	/* noting do */
85 }
86 #endif
87 
init_IRQ(void)88 void __init init_IRQ(void)
89 {
90 	setup_vector();
91 	irqchip_init();
92 }
93 
do_IRQ(int irq)94 asmlinkage void do_IRQ(int irq)
95 {
96 	irq_enter();
97 	generic_handle_irq(irq);
98 	irq_exit();
99 }
100