include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit...
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / arch / sparc / kernel / leon_kernel.c
1 /*
2 * Copyright (C) 2009 Daniel Hellstrom (daniel@gaisler.com) Aeroflex Gaisler AB
3 * Copyright (C) 2009 Konrad Eisele (konrad@gaisler.com) Aeroflex Gaisler AB
4 */
5
6 #include <linux/kernel.h>
7 #include <linux/module.h>
8 #include <linux/errno.h>
9 #include <linux/mutex.h>
10 #include <linux/of.h>
11 #include <linux/of_platform.h>
12 #include <linux/interrupt.h>
13 #include <linux/of_device.h>
14
15 #include <asm/oplib.h>
16 #include <asm/timer.h>
17 #include <asm/prom.h>
18 #include <asm/leon.h>
19 #include <asm/leon_amba.h>
20 #include <asm/traps.h>
21 #include <asm/cacheflush.h>
22
23 #include "prom.h"
24 #include "irq.h"
25
26 struct leon3_irqctrl_regs_map *leon3_irqctrl_regs; /* interrupt controller base address, initialized by amba_init() */
27 struct leon3_gptimer_regs_map *leon3_gptimer_regs; /* timer controller base address, initialized by amba_init() */
28 struct amba_apb_device leon_percpu_timer_dev[16];
29
30 int leondebug_irq_disable;
31 int leon_debug_irqout;
32 static int dummy_master_l10_counter;
33
34 unsigned long leon3_gptimer_irq; /* interrupt controller irq number, initialized by amba_init() */
35 unsigned int sparc_leon_eirq;
36 #define LEON_IMASK ((&leon3_irqctrl_regs->mask[0]))
37
38 /* Return the IRQ of the pending IRQ on the extended IRQ controller */
39 int sparc_leon_eirq_get(int eirq, int cpu)
40 {
41 return LEON3_BYPASS_LOAD_PA(&leon3_irqctrl_regs->intid[cpu]) & 0x1f;
42 }
43
44 irqreturn_t sparc_leon_eirq_isr(int dummy, void *dev_id)
45 {
46 printk(KERN_ERR "sparc_leon_eirq_isr: ERROR EXTENDED IRQ\n");
47 return IRQ_HANDLED;
48 }
49
50 /* The extended IRQ controller has been found, this function registers it */
51 void sparc_leon_eirq_register(int eirq)
52 {
53 int irq;
54
55 /* Register a "BAD" handler for this interrupt, it should never happen */
56 irq = request_irq(eirq, sparc_leon_eirq_isr,
57 (IRQF_DISABLED | SA_STATIC_ALLOC), "extirq", NULL);
58
59 if (irq) {
60 printk(KERN_ERR
61 "sparc_leon_eirq_register: unable to attach IRQ%d\n",
62 eirq);
63 } else {
64 sparc_leon_eirq = eirq;
65 }
66
67 }
68
69 static inline unsigned long get_irqmask(unsigned int irq)
70 {
71 unsigned long mask;
72
73 if (!irq || ((irq > 0xf) && !sparc_leon_eirq)
74 || ((irq > 0x1f) && sparc_leon_eirq)) {
75 printk(KERN_ERR
76 "leon_get_irqmask: false irq number: %d\n", irq);
77 mask = 0;
78 } else {
79 mask = LEON_HARD_INT(irq);
80 }
81 return mask;
82 }
83
84 static void leon_enable_irq(unsigned int irq_nr)
85 {
86 unsigned long mask, flags;
87 mask = get_irqmask(irq_nr);
88 local_irq_save(flags);
89 LEON3_BYPASS_STORE_PA(LEON_IMASK,
90 (LEON3_BYPASS_LOAD_PA(LEON_IMASK) | (mask)));
91 local_irq_restore(flags);
92 }
93
94 static void leon_disable_irq(unsigned int irq_nr)
95 {
96 unsigned long mask, flags;
97 mask = get_irqmask(irq_nr);
98 local_irq_save(flags);
99 LEON3_BYPASS_STORE_PA(LEON_IMASK,
100 (LEON3_BYPASS_LOAD_PA(LEON_IMASK) & ~(mask)));
101 local_irq_restore(flags);
102
103 }
104
105 void __init leon_init_timers(irq_handler_t counter_fn)
106 {
107 int irq;
108
109 leondebug_irq_disable = 0;
110 leon_debug_irqout = 0;
111 master_l10_counter = (unsigned int *)&dummy_master_l10_counter;
112 dummy_master_l10_counter = 0;
113
114 if (leon3_gptimer_regs && leon3_irqctrl_regs) {
115 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].val, 0);
116 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].rld,
117 (((1000000 / 100) - 1)));
118 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].ctrl, 0);
119
120 #ifdef CONFIG_SMP
121 leon_percpu_timer_dev[0].start = (int)leon3_gptimer_regs;
122 leon_percpu_timer_dev[0].irq = leon3_gptimer_irq+1;
123
124 if (!(LEON3_BYPASS_LOAD_PA(&leon3_gptimer_regs->config) &
125 (1<<LEON3_GPTIMER_SEPIRQ))) {
126 prom_printf("irq timer not configured with separate irqs\n");
127 BUG();
128 }
129
130 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].val, 0);
131 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].rld, (((1000000/100) - 1)));
132 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].ctrl, 0);
133 # endif
134
135 } else {
136 printk(KERN_ERR "No Timer/irqctrl found\n");
137 BUG();
138 }
139
140 irq = request_irq(leon3_gptimer_irq,
141 counter_fn,
142 (IRQF_DISABLED | SA_STATIC_ALLOC), "timer", NULL);
143
144 if (irq) {
145 printk(KERN_ERR "leon_time_init: unable to attach IRQ%d\n",
146 LEON_INTERRUPT_TIMER1);
147 prom_halt();
148 }
149
150 # ifdef CONFIG_SMP
151 {
152 unsigned long flags;
153 struct tt_entry *trap_table = &sparc_ttable[SP_TRAP_IRQ1 + (leon_percpu_timer_dev[0].irq - 1)];
154
155 /* For SMP we use the level 14 ticker, however the bootup code
156 * has copied the firmwares level 14 vector into boot cpu's
157 * trap table, we must fix this now or we get squashed.
158 */
159 local_irq_save(flags);
160
161 patchme_maybe_smp_msg[0] = 0x01000000; /* NOP out the branch */
162
163 /* Adjust so that we jump directly to smpleon_ticker */
164 trap_table->inst_three += smpleon_ticker - real_irq_entry;
165
166 local_flush_cache_all();
167 local_irq_restore(flags);
168 }
169 # endif
170
171 if (leon3_gptimer_regs) {
172 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[0].ctrl,
173 LEON3_GPTIMER_EN |
174 LEON3_GPTIMER_RL |
175 LEON3_GPTIMER_LD | LEON3_GPTIMER_IRQEN);
176
177 #ifdef CONFIG_SMP
178 LEON3_BYPASS_STORE_PA(&leon3_gptimer_regs->e[1].ctrl,
179 LEON3_GPTIMER_EN |
180 LEON3_GPTIMER_RL |
181 LEON3_GPTIMER_LD |
182 LEON3_GPTIMER_IRQEN);
183 #endif
184
185 }
186 }
187
188 void leon_clear_clock_irq(void)
189 {
190 }
191
192 void leon_load_profile_irq(int cpu, unsigned int limit)
193 {
194 BUG();
195 }
196
197
198
199
200 void __init leon_trans_init(struct device_node *dp)
201 {
202 if (strcmp(dp->type, "cpu") == 0 && strcmp(dp->name, "<NULL>") == 0) {
203 struct property *p;
204 p = of_find_property(dp, "mid", (void *)0);
205 if (p) {
206 int mid;
207 dp->name = prom_early_alloc(5 + 1);
208 memcpy(&mid, p->value, p->length);
209 sprintf((char *)dp->name, "cpu%.2d", mid);
210 }
211 }
212 }
213
214 void __initdata (*prom_amba_init)(struct device_node *dp, struct device_node ***nextp) = 0;
215
216 void __init leon_node_init(struct device_node *dp, struct device_node ***nextp)
217 {
218 if (prom_amba_init &&
219 strcmp(dp->type, "ambapp") == 0 &&
220 strcmp(dp->name, "ambapp0") == 0) {
221 prom_amba_init(dp, nextp);
222 }
223 }
224
225 #ifdef CONFIG_SMP
226
227 void leon_set_cpu_int(int cpu, int level)
228 {
229 unsigned long mask;
230 mask = get_irqmask(level);
231 LEON3_BYPASS_STORE_PA(&leon3_irqctrl_regs->force[cpu], mask);
232 }
233
234 static void leon_clear_ipi(int cpu, int level)
235 {
236 unsigned long mask;
237 mask = get_irqmask(level);
238 LEON3_BYPASS_STORE_PA(&leon3_irqctrl_regs->force[cpu], mask<<16);
239 }
240
241 static void leon_set_udt(int cpu)
242 {
243 }
244
245 void leon_clear_profile_irq(int cpu)
246 {
247 }
248
249 void leon_enable_irq_cpu(unsigned int irq_nr, unsigned int cpu)
250 {
251 unsigned long mask, flags, *addr;
252 mask = get_irqmask(irq_nr);
253 local_irq_save(flags);
254 addr = (unsigned long *)&(leon3_irqctrl_regs->mask[cpu]);
255 LEON3_BYPASS_STORE_PA(addr, (LEON3_BYPASS_LOAD_PA(addr) | (mask)));
256 local_irq_restore(flags);
257 }
258
259 #endif
260
261 void __init leon_init_IRQ(void)
262 {
263 sparc_init_timers = leon_init_timers;
264
265 BTFIXUPSET_CALL(enable_irq, leon_enable_irq, BTFIXUPCALL_NORM);
266 BTFIXUPSET_CALL(disable_irq, leon_disable_irq, BTFIXUPCALL_NORM);
267 BTFIXUPSET_CALL(enable_pil_irq, leon_enable_irq, BTFIXUPCALL_NORM);
268 BTFIXUPSET_CALL(disable_pil_irq, leon_disable_irq, BTFIXUPCALL_NORM);
269
270 BTFIXUPSET_CALL(clear_clock_irq, leon_clear_clock_irq,
271 BTFIXUPCALL_NORM);
272 BTFIXUPSET_CALL(load_profile_irq, leon_load_profile_irq,
273 BTFIXUPCALL_NOP);
274
275 #ifdef CONFIG_SMP
276 BTFIXUPSET_CALL(set_cpu_int, leon_set_cpu_int, BTFIXUPCALL_NORM);
277 BTFIXUPSET_CALL(clear_cpu_int, leon_clear_ipi, BTFIXUPCALL_NORM);
278 BTFIXUPSET_CALL(set_irq_udt, leon_set_udt, BTFIXUPCALL_NORM);
279 #endif
280
281 }
282
283 void __init leon_init(void)
284 {
285 prom_build_more = &leon_node_init;
286 }