summaryrefslogtreecommitdiff
path: root/target/linux/ramips/patches-4.3/0053-gic.patch
blob: c20cedf48e12a2490216320f044ef76e64499747 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
From 7b042645c1bd6407b1f7d9aa5785868e7e14b860 Mon Sep 17 00:00:00 2001
From: John Crispin <blogic@openwrt.org>
Date: Mon, 7 Dec 2015 18:40:16 +0100
Subject: [PATCH 53/53] gic

---
 arch/mips/ralink/Kconfig   |    1 +
 arch/mips/ralink/Makefile  |    2 +-
 arch/mips/ralink/irq-gic.c |  212 ++------------------------------------------
 3 files changed, 11 insertions(+), 204 deletions(-)

--- a/arch/mips/ralink/Kconfig
+++ b/arch/mips/ralink/Kconfig
@@ -51,9 +51,9 @@
 		select SYS_SUPPORTS_MULTITHREADING
 		select SYS_SUPPORTS_SMP
 		select SYS_SUPPORTS_MIPS_CMP
+		select MIPS_GIC
 		select IRQ_GIC
 		select HW_HAS_PCI
-
 endchoice
 
 choice
--- a/arch/mips/ralink/Makefile
+++ b/arch/mips/ralink/Makefile
@@ -13,7 +13,7 @@
 obj-$(CONFIG_RALINK_ILL_ACC) += ill_acc.o
 
 obj-$(CONFIG_IRQ_INTC) += irq.o
-obj-$(CONFIG_IRQ_GIC) += irq-gic.o
+obj-$(CONFIG_MIPS_GIC_IPI) += irq-gic.o
 obj-$(CONFIG_MIPS_MT_SMP) += malta-amon.o
 
 obj-$(CONFIG_SOC_RT288X) += rt288x.o
--- a/arch/mips/ralink/irq-gic.c
+++ b/arch/mips/ralink/irq-gic.c
@@ -16,248 +16,22 @@
 #include <asm/irq.h>
 #include <asm/setup.h>
 
-#include <asm/gic.h>
+#include <asm/mips-cm.h>
+#include <linux/irqchip/mips-gic.h>
 
 #include <asm/mach-ralink/mt7621.h>
-#define GIC_BASE_ADDR			0x1fbc0000
 
-unsigned long _gcmp_base;
-static int gic_resched_int_base = 56;
-static int gic_call_int_base = 60;
-static struct irq_chip *irq_gic;
-static struct gic_intr_map gic_intr_map[GIC_NUM_INTRS];
-
-#if defined(CONFIG_MIPS_MT_SMP)
-static int gic_resched_int_base;
-static int gic_call_int_base;
+extern int __init gic_of_init(struct device_node *node,
+			      struct device_node *parent);
 
-#define GIC_RESCHED_INT(cpu) (gic_resched_int_base+(cpu))
-#define GIC_CALL_INT(cpu) (gic_call_int_base+(cpu))
-
-static irqreturn_t ipi_resched_interrupt(int irq, void *dev_id)
-{
-	scheduler_ipi();
-
-	return IRQ_HANDLED;
-}
-
-static irqreturn_t
-ipi_call_interrupt(int irq, void *dev_id)
-{
-	smp_call_function_interrupt();
-
-	return IRQ_HANDLED;
-}
-
-static struct irqaction irq_resched = {
-        .handler        = ipi_resched_interrupt,
-        .flags          = IRQF_DISABLED|IRQF_PERCPU,
-        .name           = "ipi resched"
-};
-
-static struct irqaction irq_call = {
-        .handler        = ipi_call_interrupt,
-        .flags          = IRQF_DISABLED|IRQF_PERCPU,
-        .name           = "ipi call"
-};
-
-#endif
-
-static void __init
-gic_fill_map(void)
-{
-	int i;
-
-	for (i = 0; i < ARRAY_SIZE(gic_intr_map); i++) {
-		gic_intr_map[i].cpunum = 0;
-		gic_intr_map[i].pin = GIC_CPU_INT0;
-		gic_intr_map[i].polarity = GIC_POL_POS;
-		gic_intr_map[i].trigtype = GIC_TRIG_LEVEL;
-		gic_intr_map[i].flags = 0;
-	}
-
-#if defined(CONFIG_MIPS_MT_SMP)
-	{
-		int cpu;
-
-		gic_call_int_base = ARRAY_SIZE(gic_intr_map) - nr_cpu_ids;
-		gic_resched_int_base = gic_call_int_base - nr_cpu_ids;
-
-		i = gic_resched_int_base;
-
-		for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
-			gic_intr_map[i + cpu].cpunum = cpu;
-			gic_intr_map[i + cpu].pin = GIC_CPU_INT1;
-			gic_intr_map[i + cpu].trigtype = GIC_TRIG_EDGE;
-
-			gic_intr_map[i + cpu + nr_cpu_ids].cpunum = cpu;
-			gic_intr_map[i + cpu + nr_cpu_ids].pin = GIC_CPU_INT2;
-			gic_intr_map[i + cpu + nr_cpu_ids].trigtype = GIC_TRIG_EDGE;
-		}
-	}
-#endif
-}
-
-void
-gic_irq_ack(struct irq_data *d)
-{
-	int irq = (d->irq - gic_irq_base);
-
-	GIC_CLR_INTR_MASK(irq);
-
-	if (gic_irq_flags[irq] & GIC_TRIG_EDGE)
-		GICWRITE(GIC_REG(SHARED, GIC_SH_WEDGE), irq);
-}
-
-void
-gic_finish_irq(struct irq_data *d)
-{
-	GIC_SET_INTR_MASK(d->irq - gic_irq_base);
-}
-
-void __init
-gic_platform_init(int irqs, struct irq_chip *irq_controller)
-{
-	irq_gic = irq_controller;
-}
-
-static void
-gic_irqdispatch(void)
-{
-	unsigned int irq = gic_get_int();
-
-	if (likely(irq < GIC_NUM_INTRS))
-		do_IRQ(MIPS_GIC_IRQ_BASE + irq);
-	else {
-		pr_debug("Spurious GIC Interrupt!\n");
-		spurious_interrupt();
-	}
-
-}
-
-static void
-vi_timer_irqdispatch(void)
-{
-	do_IRQ(cp0_compare_irq);
-}
-
-#if defined(CONFIG_MIPS_MT_SMP)
-unsigned int
-plat_ipi_call_int_xlate(unsigned int cpu)
-{
-	return GIC_CALL_INT(cpu);
-}
-
-unsigned int
-plat_ipi_resched_int_xlate(unsigned int cpu)
-{
-	return GIC_RESCHED_INT(cpu);
-}
-#endif
-
-asmlinkage void
-plat_irq_dispatch(void)
-{
-	unsigned int pending = read_c0_status() & read_c0_cause() & ST0_IM;
-
-	if (unlikely(!pending)) {
-		pr_err("Spurious CP0 Interrupt!\n");
-		spurious_interrupt();
-	} else {
-		if (pending & CAUSEF_IP7)
-			do_IRQ(cp0_compare_irq);
-
-		if (pending & (CAUSEF_IP4 | CAUSEF_IP3 | CAUSEF_IP2))
-			gic_irqdispatch();
-	}
-}
-
-unsigned int __cpuinit
-get_c0_compare_int(void)
-{
-	return CP0_LEGACY_COMPARE_IRQ;
-}
-
-static int
-gic_map(struct irq_domain *d, unsigned int irq, irq_hw_number_t hw)
-{
-	irq_set_chip_and_handler(irq, irq_gic,
-#if defined(CONFIG_MIPS_MT_SMP)
-		(hw >= gic_resched_int_base) ?
-			handle_percpu_irq :
-#endif
-			handle_level_irq);
-
-	return 0;
-}
-
-static const struct irq_domain_ops irq_domain_ops = {
-	.xlate = irq_domain_xlate_onecell,
-	.map = gic_map,
-};
-
-static int __init
-of_gic_init(struct device_node *node,
-				struct device_node *parent)
+unsigned int get_c0_compare_int(void)
 {
-	struct irq_domain *domain;
-	struct resource gcmp = { 0 }, gic = { 0 };
-	unsigned int gic_rev;
-	int i;
-
-	if (of_address_to_resource(node, 0, &gic))
-		panic("Failed to get gic memory range");
-	if (request_mem_region(gic.start, resource_size(&gic),
-				gic.name) < 0)
-		panic("Failed to request gic memory");
-	if (of_address_to_resource(node, 2, &gcmp))
-		panic("Failed to get gic memory range");
-	if (request_mem_region(gcmp.start, resource_size(&gcmp),
-				gcmp.name) < 0)
-		panic("Failed to request gcmp memory");
-
-	_gcmp_base = (unsigned long) ioremap_nocache(gcmp.start, resource_size(&gcmp));
-	if (!_gcmp_base)
-		panic("Failed to remap gcmp memory\n");
-
-	/* tell the gcmp where to find the gic */
-	write_gcr_gic_base(GIC_BASE_ADDR | CM_GCR_GIC_BASE_GICEN_MSK);
-	gic_present = 1;
-	if (cpu_has_vint) {
-		set_vi_handler(2, gic_irqdispatch);
-		set_vi_handler(3, gic_irqdispatch);
-		set_vi_handler(4, gic_irqdispatch);
-		set_vi_handler(7, vi_timer_irqdispatch);
-	}
-
-	gic_fill_map();
-
-	gic_init(gic.start, resource_size(&gic), gic_intr_map,
-		ARRAY_SIZE(gic_intr_map), MIPS_GIC_IRQ_BASE);
-
-	GICREAD(GIC_REG(SHARED, GIC_SH_REVISIONID), gic_rev);
-	pr_info("gic: revision %d.%d\n", (gic_rev >> 8) & 0xff, gic_rev & 0xff);
-
-	domain = irq_domain_add_legacy(node, GIC_NUM_INTRS, MIPS_GIC_IRQ_BASE,
-			0, &irq_domain_ops, NULL);
-	if (!domain)
-		panic("Failed to add irqdomain");
-
-#if defined(CONFIG_MIPS_MT_SMP)
-	for (i = 0; i < nr_cpu_ids; i++) {
-		setup_irq(MIPS_GIC_IRQ_BASE + GIC_RESCHED_INT(i), &irq_resched);
-		setup_irq(MIPS_GIC_IRQ_BASE + GIC_CALL_INT(i), &irq_call);
-	}
-#endif
-
-	change_c0_status(ST0_IM, STATUSF_IP7 | STATUSF_IP4 | STATUSF_IP3 |
-				STATUSF_IP2);
-	return 0;
+	return gic_get_c0_compare_int();
 }
 
 static struct of_device_id __initdata of_irq_ids[] = {
-	{ .compatible = "mti,cpu-interrupt-controller", .data = mips_cpu_intc_init },
-	{ .compatible = "ralink,mt7621-gic", .data = of_gic_init },
+	{ .compatible = "mti,cpu-interrupt-controller", .data = mips_cpu_irq_of_init },
+	{ .compatible = "mti,gic", .data = gic_of_init },
 	{},
 };
 
--- a/drivers/irqchip/irq-mips-gic.c
+++ b/drivers/irqchip/irq-mips-gic.c
@@ -864,7 +864,7 @@
 	__gic_init(gic_base_addr, gic_addrspace_size, cpu_vec, irqbase, NULL);
 }
 
-static int __init gic_of_init(struct device_node *node,
+int __init gic_of_init(struct device_node *node,
 			      struct device_node *parent)
 {
 	struct resource res;