drivers/block/drbd/drbd_main.c: fix error path
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / sparc / kernel / leon_kernel.c
blob2d51527d810fc811531dae33c4bafc281b47d924
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 */
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>
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>
23 #include "prom.h"
24 #include "irq.h"
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];
30 int leondebug_irq_disable;
31 int leon_debug_irqout;
32 static int dummy_master_l10_counter;
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]))
38 /* Return the IRQ of the pending IRQ on the extended IRQ controller */
39 int sparc_leon_eirq_get(int eirq, int cpu)
41 return LEON3_BYPASS_LOAD_PA(&leon3_irqctrl_regs->intid[cpu]) & 0x1f;
44 irqreturn_t sparc_leon_eirq_isr(int dummy, void *dev_id)
46 printk(KERN_ERR "sparc_leon_eirq_isr: ERROR EXTENDED IRQ\n");
47 return IRQ_HANDLED;
50 /* The extended IRQ controller has been found, this function registers it */
51 void sparc_leon_eirq_register(int eirq)
53 int irq;
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);
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;
69 static inline unsigned long get_irqmask(unsigned int irq)
71 unsigned long mask;
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);
81 return mask;
84 static void leon_enable_irq(unsigned int irq_nr)
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);
94 static void leon_disable_irq(unsigned int irq_nr)
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);
105 void __init leon_init_timers(irq_handler_t counter_fn)
107 int irq;
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;
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);
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;
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();
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
135 } else {
136 printk(KERN_ERR "No Timer/irqctrl found\n");
137 BUG();
140 irq = request_irq(leon3_gptimer_irq,
141 counter_fn,
142 (IRQF_DISABLED | SA_STATIC_ALLOC), "timer", NULL);
144 if (irq) {
145 printk(KERN_ERR "leon_time_init: unable to attach IRQ%d\n",
146 LEON_INTERRUPT_TIMER1);
147 prom_halt();
150 # ifdef CONFIG_SMP
152 unsigned long flags;
153 struct tt_entry *trap_table = &sparc_ttable[SP_TRAP_IRQ1 + (leon_percpu_timer_dev[0].irq - 1)];
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.
159 local_irq_save(flags);
161 patchme_maybe_smp_msg[0] = 0x01000000; /* NOP out the branch */
163 /* Adjust so that we jump directly to smpleon_ticker */
164 trap_table->inst_three += smpleon_ticker - real_irq_entry;
166 local_flush_cache_all();
167 local_irq_restore(flags);
169 # endif
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);
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
188 void leon_clear_clock_irq(void)
192 void leon_load_profile_irq(int cpu, unsigned int limit)
194 BUG();
200 void __init leon_trans_init(struct device_node *dp)
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);
214 void __initdata (*prom_amba_init)(struct device_node *dp, struct device_node ***nextp) = 0;
216 void __init leon_node_init(struct device_node *dp, struct device_node ***nextp)
218 if (prom_amba_init &&
219 strcmp(dp->type, "ambapp") == 0 &&
220 strcmp(dp->name, "ambapp0") == 0) {
221 prom_amba_init(dp, nextp);
225 #ifdef CONFIG_SMP
227 void leon_set_cpu_int(int cpu, int level)
229 unsigned long mask;
230 mask = get_irqmask(level);
231 LEON3_BYPASS_STORE_PA(&leon3_irqctrl_regs->force[cpu], mask);
234 static void leon_clear_ipi(int cpu, int level)
236 unsigned long mask;
237 mask = get_irqmask(level);
238 LEON3_BYPASS_STORE_PA(&leon3_irqctrl_regs->force[cpu], mask<<16);
241 static void leon_set_udt(int cpu)
245 void leon_clear_profile_irq(int cpu)
249 void leon_enable_irq_cpu(unsigned int irq_nr, unsigned int cpu)
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);
259 #endif
261 void __init leon_init_IRQ(void)
263 sparc_init_timers = leon_init_timers;
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);
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);
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
283 void __init leon_init(void)
285 of_pdt_build_more = &leon_node_init;