aboutsummaryrefslogtreecommitdiffstats
path: root/arch/sparc
diff options
context:
space:
mode:
authorSam Ravnborg <sam@ravnborg.org>2011-01-28 17:08:21 -0500
committerDavid S. Miller <davem@davemloft.net>2011-03-16 21:19:10 -0400
commite54f8548ff5285f57125c08d8092eec38dd05e0d (patch)
treef57bb3f4e21e61b9a59003042aaf1b7c119af228 /arch/sparc
parentaba20a8295a76310cd062be0736103ba5aee34fa (diff)
sparc32,sun4d: irq, smp files cleanup
- drop filename in file header - drop unused includes - add description of sun4d interrupts (from davem) - add KERN_* to printk - fix spaces => tabs - add spaces after reserved words - fix indent of a whole code block in smp4d_boot_one_cpu() Note: two printk() was updated from debug to KERN_INFO in this code block - drop all externs, they are now in header files This is partly based on a patch from: David Miller <davem@davemloft.net> Signed-off-by: Sam Ravnborg <sam@ravnborg.org> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'arch/sparc')
-rw-r--r--arch/sparc/kernel/sun4d_irq.c195
-rw-r--r--arch/sparc/kernel/sun4d_smp.c176
2 files changed, 174 insertions, 197 deletions
diff --git a/arch/sparc/kernel/sun4d_irq.c b/arch/sparc/kernel/sun4d_irq.c
index 3af649e64f0d..5fc4c220158c 100644
--- a/arch/sparc/kernel/sun4d_irq.c
+++ b/arch/sparc/kernel/sun4d_irq.c
@@ -1,49 +1,48 @@
1/* 1/*
2 * arch/sparc/kernel/sun4d_irq.c: 2 * SS1000/SC2000 interrupt handling.
3 * SS1000/SC2000 interrupt handling.
4 * 3 *
5 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) 4 * Copyright (C) 1997,1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
6 * Heavily based on arch/sparc/kernel/irq.c. 5 * Heavily based on arch/sparc/kernel/irq.c.
7 */ 6 */
8 7
9#include <linux/errno.h>
10#include <linux/linkage.h>
11#include <linux/kernel_stat.h> 8#include <linux/kernel_stat.h>
12#include <linux/signal.h>
13#include <linux/sched.h>
14#include <linux/ptrace.h>
15#include <linux/interrupt.h>
16#include <linux/slab.h>
17#include <linux/random.h>
18#include <linux/init.h>
19#include <linux/smp.h>
20#include <linux/spinlock.h>
21#include <linux/seq_file.h> 9#include <linux/seq_file.h>
22#include <linux/of.h> 10
23#include <linux/of_device.h>
24
25#include <asm/ptrace.h>
26#include <asm/processor.h>
27#include <asm/system.h>
28#include <asm/psr.h>
29#include <asm/smp.h>
30#include <asm/vaddrs.h>
31#include <asm/timer.h> 11#include <asm/timer.h>
32#include <asm/openprom.h>
33#include <asm/oplib.h>
34#include <asm/traps.h> 12#include <asm/traps.h>
35#include <asm/irq.h> 13#include <asm/irq.h>
36#include <asm/io.h> 14#include <asm/io.h>
37#include <asm/pgalloc.h>
38#include <asm/pgtable.h>
39#include <asm/sbi.h> 15#include <asm/sbi.h>
40#include <asm/cacheflush.h> 16#include <asm/cacheflush.h>
41#include <asm/irq_regs.h>
42 17
43#include "kernel.h" 18#include "kernel.h"
44#include "irq.h" 19#include "irq.h"
45 20
46/* If you trust current SCSI layer to handle different SCSI IRQs, enable this. I don't trust it... -jj */ 21/* Sun4d interrupts fall roughly into two categories. SBUS and
22 * cpu local. CPU local interrupts cover the timer interrupts
23 * and whatnot, and we encode those as normal PILs between
24 * 0 and 15.
25 *
26 * SBUS interrupts are encoded integers including the board number
27 * (plus one), the SBUS level, and the SBUS slot number. Sun4D
28 * IRQ dispatch is done by:
29 *
30 * 1) Reading the BW local interrupt table in order to get the bus
31 * interrupt mask.
32 *
33 * This table is indexed by SBUS interrupt level which can be
34 * derived from the PIL we got interrupted on.
35 *
36 * 2) For each bus showing interrupt pending from #1, read the
37 * SBI interrupt state register. This will indicate which slots
38 * have interrupts pending for that SBUS interrupt level.
39 */
40
41/*
42 * If you trust current SCSI layer to handle different
43 * SCSI IRQs, enable this.
44 * I don't trust it... -jj
45 */
47/* #define DISTRIBUTE_IRQS */ 46/* #define DISTRIBUTE_IRQS */
48 47
49struct sun4d_timer_regs { 48struct sun4d_timer_regs {
@@ -59,11 +58,9 @@ static struct sun4d_timer_regs __iomem *sun4d_timers;
59#define TIMER_IRQ 10 58#define TIMER_IRQ 10
60 59
61#define MAX_STATIC_ALLOC 4 60#define MAX_STATIC_ALLOC 4
62extern int static_irq_count;
63static unsigned char sbus_tid[32]; 61static unsigned char sbus_tid[32];
64 62
65static struct irqaction *irq_action[NR_IRQS]; 63static struct irqaction *irq_action[NR_IRQS];
66extern spinlock_t irq_action_lock;
67 64
68static struct sbus_action { 65static struct sbus_action {
69 struct irqaction *action; 66 struct irqaction *action;
@@ -71,11 +68,33 @@ static struct sbus_action {
71} *sbus_actions; 68} *sbus_actions;
72 69
73static int pil_to_sbus[] = { 70static int pil_to_sbus[] = {
74 0, 0, 1, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 0, 71 0,
72 0,
73 1,
74 2,
75 0,
76 3,
77 0,
78 4,
79 0,
80 5,
81 0,
82 6,
83 0,
84 7,
85 0,
86 0,
75}; 87};
76 88
77static int sbus_to_pil[] = { 89static int sbus_to_pil[] = {
78 0, 2, 3, 5, 7, 9, 11, 13, 90 0,
91 2,
92 3,
93 5,
94 7,
95 9,
96 11,
97 13,
79}; 98};
80 99
81static int nsbi; 100static int nsbi;
@@ -86,7 +105,7 @@ DEFINE_SPINLOCK(sun4d_imsk_lock);
86int show_sun4d_interrupts(struct seq_file *p, void *v) 105int show_sun4d_interrupts(struct seq_file *p, void *v)
87{ 106{
88 int i = *(loff_t *) v, j = 0, k = 0, sbusl; 107 int i = *(loff_t *) v, j = 0, k = 0, sbusl;
89 struct irqaction * action; 108 struct irqaction *action;
90 unsigned long flags; 109 unsigned long flags;
91#ifdef CONFIG_SMP 110#ifdef CONFIG_SMP
92 int x; 111 int x;
@@ -96,13 +115,14 @@ int show_sun4d_interrupts(struct seq_file *p, void *v)
96 if (i < NR_IRQS) { 115 if (i < NR_IRQS) {
97 sbusl = pil_to_sbus[i]; 116 sbusl = pil_to_sbus[i];
98 if (!sbusl) { 117 if (!sbusl) {
99 action = *(i + irq_action); 118 action = *(i + irq_action);
100 if (!action) 119 if (!action)
101 goto out_unlock; 120 goto out_unlock;
102 } else { 121 } else {
103 for (j = 0; j < nsbi; j++) { 122 for (j = 0; j < nsbi; j++) {
104 for (k = 0; k < 4; k++) 123 for (k = 0; k < 4; k++)
105 if ((action = sbus_actions [(j << 5) + (sbusl << 2) + k].action)) 124 action = sbus_actions[(j << 5) + (sbusl << 2) + k].action;
125 if (action)
106 goto found_it; 126 goto found_it;
107 } 127 }
108 goto out_unlock; 128 goto out_unlock;
@@ -125,15 +145,17 @@ found_it: seq_printf(p, "%3d: ", i);
125 (action->flags & IRQF_DISABLED) ? " +" : "", 145 (action->flags & IRQF_DISABLED) ? " +" : "",
126 action->name); 146 action->name);
127 } 147 }
128 if (!sbusl) break; 148 if (!sbusl)
149 break;
129 k++; 150 k++;
130 if (k < 4) 151 if (k < 4) {
131 action = sbus_actions [(j << 5) + (sbusl << 2) + k].action; 152 action = sbus_actions[(j << 5) + (sbusl << 2) + k].action;
132 else { 153 } else {
133 j++; 154 j++;
134 if (j == nsbi) break; 155 if (j == nsbi)
156 break;
135 k = 0; 157 k = 0;
136 action = sbus_actions [(j << 5) + (sbusl << 2)].action; 158 action = sbus_actions[(j << 5) + (sbusl << 2)].action;
137 } 159 }
138 } 160 }
139 seq_putc(p, '\n'); 161 seq_putc(p, '\n');
@@ -147,7 +169,7 @@ void sun4d_free_irq(unsigned int irq, void *dev_id)
147{ 169{
148 struct irqaction *action, **actionp; 170 struct irqaction *action, **actionp;
149 struct irqaction *tmp = NULL; 171 struct irqaction *tmp = NULL;
150 unsigned long flags; 172 unsigned long flags;
151 173
152 spin_lock_irqsave(&irq_action_lock, flags); 174 spin_lock_irqsave(&irq_action_lock, flags);
153 if (irq < 15) 175 if (irq < 15)
@@ -156,7 +178,7 @@ void sun4d_free_irq(unsigned int irq, void *dev_id)
156 actionp = &(sbus_actions[irq - (1 << 5)].action); 178 actionp = &(sbus_actions[irq - (1 << 5)].action);
157 action = *actionp; 179 action = *actionp;
158 if (!action) { 180 if (!action) {
159 printk("Trying to free free IRQ%d\n",irq); 181 printk(KERN_ERR "Trying to free free IRQ%d\n", irq);
160 goto out_unlock; 182 goto out_unlock;
161 } 183 }
162 if (dev_id) { 184 if (dev_id) {
@@ -166,23 +188,25 @@ void sun4d_free_irq(unsigned int irq, void *dev_id)
166 tmp = action; 188 tmp = action;
167 } 189 }
168 if (!action) { 190 if (!action) {
169 printk("Trying to free free shared IRQ%d\n",irq); 191 printk(KERN_ERR "Trying to free free shared IRQ%d\n",
192 irq);
170 goto out_unlock; 193 goto out_unlock;
171 } 194 }
172 } else if (action->flags & IRQF_SHARED) { 195 } else if (action->flags & IRQF_SHARED) {
173 printk("Trying to free shared IRQ%d with NULL device ID\n", irq); 196 printk(KERN_ERR "Trying to free shared IRQ%d with NULL device ID\n",
197 irq);
174 goto out_unlock; 198 goto out_unlock;
175 } 199 }
176 if (action->flags & SA_STATIC_ALLOC) 200 if (action->flags & SA_STATIC_ALLOC) {
177 { 201 /*
178 /* This interrupt is marked as specially allocated 202 * This interrupt is marked as specially allocated
179 * so it is a bad idea to free it. 203 * so it is a bad idea to free it.
180 */ 204 */
181 printk("Attempt to free statically allocated IRQ%d (%s)\n", 205 printk(KERN_ERR "Attempt to free statically allocated IRQ%d (%s)\n",
182 irq, action->name); 206 irq, action->name);
183 goto out_unlock; 207 goto out_unlock;
184 } 208 }
185 209
186 if (tmp) 210 if (tmp)
187 tmp->next = action->next; 211 tmp->next = action->next;
188 else 212 else
@@ -203,21 +227,19 @@ out_unlock:
203 spin_unlock_irqrestore(&irq_action_lock, flags); 227 spin_unlock_irqrestore(&irq_action_lock, flags);
204} 228}
205 229
206extern void unexpected_irq(int, void *, struct pt_regs *); 230void sun4d_handler_irq(int pil, struct pt_regs *regs)
207
208void sun4d_handler_irq(int pil, struct pt_regs * regs)
209{ 231{
210 struct pt_regs *old_regs; 232 struct pt_regs *old_regs;
211 struct irqaction * action; 233 struct irqaction *action;
212 int cpu = smp_processor_id(); 234 int cpu = smp_processor_id();
213 /* SBUS IRQ level (1 - 7) */ 235 /* SBUS IRQ level (1 - 7) */
214 int sbusl = pil_to_sbus[pil]; 236 int sbusl = pil_to_sbus[pil];
215 237
216 /* FIXME: Is this necessary?? */ 238 /* FIXME: Is this necessary?? */
217 cc_get_ipen(); 239 cc_get_ipen();
218 240
219 cc_set_iclr(1 << pil); 241 cc_set_iclr(1 << pil);
220 242
221 old_regs = set_irq_regs(regs); 243 old_regs = set_irq_regs(regs);
222 irq_enter(); 244 irq_enter();
223 kstat_cpu(cpu).irqs[pil]++; 245 kstat_cpu(cpu).irqs[pil]++;
@@ -235,9 +257,9 @@ void sun4d_handler_irq(int pil, struct pt_regs * regs)
235 struct sbus_action *actionp; 257 struct sbus_action *actionp;
236 unsigned mask, slot; 258 unsigned mask, slot;
237 int sbil = (sbusl << 2); 259 int sbil = (sbusl << 2);
238 260
239 bw_clear_intr_mask(sbusl, bus_mask); 261 bw_clear_intr_mask(sbusl, bus_mask);
240 262
241 /* Loop for each pending SBI */ 263 /* Loop for each pending SBI */
242 for (sbino = 0; bus_mask; sbino++, bus_mask >>= 1) 264 for (sbino = 0; bus_mask; sbino++, bus_mask >>= 1)
243 if (bus_mask & 1) { 265 if (bus_mask & 1) {
@@ -249,7 +271,7 @@ void sun4d_handler_irq(int pil, struct pt_regs * regs)
249 if (mask & slot) { 271 if (mask & slot) {
250 mask &= ~slot; 272 mask &= ~slot;
251 action = actionp->action; 273 action = actionp->action;
252 274
253 if (!action) 275 if (!action)
254 unexpected_irq(pil, NULL, regs); 276 unexpected_irq(pil, NULL, regs);
255 do { 277 do {
@@ -266,13 +288,13 @@ void sun4d_handler_irq(int pil, struct pt_regs * regs)
266 288
267int sun4d_request_irq(unsigned int irq, 289int sun4d_request_irq(unsigned int irq,
268 irq_handler_t handler, 290 irq_handler_t handler,
269 unsigned long irqflags, const char * devname, void *dev_id) 291 unsigned long irqflags, const char *devname, void *dev_id)
270{ 292{
271 struct irqaction *action, *tmp = NULL, **actionp; 293 struct irqaction *action, *tmp = NULL, **actionp;
272 unsigned long flags; 294 unsigned long flags;
273 int ret; 295 int ret;
274 296
275 if(irq > 14 && irq < (1 << 5)) { 297 if (irq > 14 && irq < (1 << 5)) {
276 ret = -EINVAL; 298 ret = -EINVAL;
277 goto out; 299 goto out;
278 } 300 }
@@ -289,7 +311,7 @@ int sun4d_request_irq(unsigned int irq,
289 else 311 else
290 actionp = irq + irq_action; 312 actionp = irq + irq_action;
291 action = *actionp; 313 action = *actionp;
292 314
293 if (action) { 315 if (action) {
294 if ((action->flags & IRQF_SHARED) && (irqflags & IRQF_SHARED)) { 316 if ((action->flags & IRQF_SHARED) && (irqflags & IRQF_SHARED)) {
295 for (tmp = action; tmp->next; tmp = tmp->next); 317 for (tmp = action; tmp->next; tmp = tmp->next);
@@ -298,7 +320,8 @@ int sun4d_request_irq(unsigned int irq,
298 goto out_unlock; 320 goto out_unlock;
299 } 321 }
300 if ((action->flags & IRQF_DISABLED) ^ (irqflags & IRQF_DISABLED)) { 322 if ((action->flags & IRQF_DISABLED) ^ (irqflags & IRQF_DISABLED)) {
301 printk("Attempt to mix fast and slow interrupts on IRQ%d denied\n", irq); 323 printk(KERN_ERR "Attempt to mix fast and slow interrupts on IRQ%d denied\n",
324 irq);
302 ret = -EBUSY; 325 ret = -EBUSY;
303 goto out_unlock; 326 goto out_unlock;
304 } 327 }
@@ -312,14 +335,14 @@ int sun4d_request_irq(unsigned int irq,
312 if (static_irq_count < MAX_STATIC_ALLOC) 335 if (static_irq_count < MAX_STATIC_ALLOC)
313 action = &static_irqaction[static_irq_count++]; 336 action = &static_irqaction[static_irq_count++];
314 else 337 else
315 printk("Request for IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n", irq, devname); 338 printk(KERN_ERR "Request for IRQ%d (%s) SA_STATIC_ALLOC failed using kmalloc\n",
339 irq, devname);
316 } 340 }
317 341
318 if (action == NULL) 342 if (action == NULL)
319 action = kmalloc(sizeof(struct irqaction), 343 action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
320 GFP_ATOMIC); 344
321 345 if (!action) {
322 if (!action) {
323 ret = -ENOMEM; 346 ret = -ENOMEM;
324 goto out_unlock; 347 goto out_unlock;
325 } 348 }
@@ -334,7 +357,7 @@ int sun4d_request_irq(unsigned int irq,
334 tmp->next = action; 357 tmp->next = action;
335 else 358 else
336 *actionp = action; 359 *actionp = action;
337 360
338 __enable_irq(irq); 361 __enable_irq(irq);
339 362
340 ret = 0; 363 ret = 0;
@@ -348,7 +371,7 @@ static void sun4d_disable_irq(unsigned int irq)
348{ 371{
349 int tid = sbus_tid[(irq >> 5) - 1]; 372 int tid = sbus_tid[(irq >> 5) - 1];
350 unsigned long flags; 373 unsigned long flags;
351 374
352 if (irq < NR_IRQS) 375 if (irq < NR_IRQS)
353 return; 376 return;
354 377
@@ -361,7 +384,7 @@ static void sun4d_enable_irq(unsigned int irq)
361{ 384{
362 int tid = sbus_tid[(irq >> 5) - 1]; 385 int tid = sbus_tid[(irq >> 5) - 1];
363 unsigned long flags; 386 unsigned long flags;
364 387
365 if (irq < NR_IRQS) 388 if (irq < NR_IRQS)
366 return; 389 return;
367 390
@@ -411,7 +434,7 @@ void __init sun4d_distribute_irqs(void)
411 int board = of_getintprop_default(dp, "board#", 0); 434 int board = of_getintprop_default(dp, "board#", 0);
412 if (sbus_tid[board] == 0xff) { 435 if (sbus_tid[board] == 0xff) {
413 int i = 31; 436 int i = 31;
414 437
415 if (cpus_empty(sbus_serving_map)) 438 if (cpus_empty(sbus_serving_map))
416 sbus_serving_map = cpu_present_map; 439 sbus_serving_map = cpu_present_map;
417 while (cpu_isset(i, sbus_serving_map)) 440 while (cpu_isset(i, sbus_serving_map))
@@ -423,7 +446,8 @@ void __init sun4d_distribute_irqs(void)
423 for_each_node_by_name(dp, "sbi") { 446 for_each_node_by_name(dp, "sbi") {
424 int devid = of_getintprop_default(dp, "device-id", 0); 447 int devid = of_getintprop_default(dp, "device-id", 0);
425 int board = of_getintprop_default(dp, "board#", 0); 448 int board = of_getintprop_default(dp, "board#", 0);
426 printk("sbus%d IRQs directed to CPU%d\n", board, sbus_tid[board]); 449 printk(KERN_ERR "sbus%d IRQs directed to CPU%d\n",
450 board, sbus_tid[board]);
427 set_sbi_tid(devid, sbus_tid[board] << 3); 451 set_sbi_tid(devid, sbus_tid[board] << 3);
428 } 452 }
429#else 453#else
@@ -437,11 +461,11 @@ void __init sun4d_distribute_irqs(void)
437 sbus_tid[board] = cpuid; 461 sbus_tid[board] = cpuid;
438 set_sbi_tid(devid, cpuid << 3); 462 set_sbi_tid(devid, cpuid << 3);
439 } 463 }
440 printk("All sbus IRQs directed to CPU%d\n", cpuid); 464 printk(KERN_ERR "All sbus IRQs directed to CPU%d\n", cpuid);
441#endif 465#endif
442} 466}
443#endif 467#endif
444 468
445static void sun4d_clear_clock_irq(void) 469static void sun4d_clear_clock_irq(void)
446{ 470{
447 sbus_readl(&sun4d_timers->l10_timer_limit); 471 sbus_readl(&sun4d_timers->l10_timer_limit);
@@ -466,10 +490,7 @@ static void __init sun4d_fixup_trap_table(void)
466{ 490{
467#ifdef CONFIG_SMP 491#ifdef CONFIG_SMP
468 unsigned long flags; 492 unsigned long flags;
469 extern unsigned long lvl14_save[4];
470 struct tt_entry *trap_table = &sparc_ttable[SP_TRAP_IRQ1 + (14 - 1)]; 493 struct tt_entry *trap_table = &sparc_ttable[SP_TRAP_IRQ1 + (14 - 1)];
471 extern unsigned int real_irq_entry[], smp4d_ticker[];
472 extern unsigned int patchme_maybe_smp_msg[];
473 494
474 /* Adjust so that we jump directly to smp4d_ticker */ 495 /* Adjust so that we jump directly to smp4d_ticker */
475 lvl14_save[2] += smp4d_ticker - real_irq_entry; 496 lvl14_save[2] += smp4d_ticker - real_irq_entry;
@@ -531,7 +552,8 @@ static void __init sun4d_init_timers(irq_handler_t counter_fn)
531 (IRQF_DISABLED | SA_STATIC_ALLOC), 552 (IRQF_DISABLED | SA_STATIC_ALLOC),
532 "timer", NULL); 553 "timer", NULL);
533 if (err) { 554 if (err) {
534 prom_printf("sun4d_init_timers: request_irq() failed with %d\n", err); 555 prom_printf("sun4d_init_timers: request_irq() failed with %d\n",
556 err);
535 prom_halt(); 557 prom_halt();
536 } 558 }
537 sun4d_load_profile_irqs(); 559 sun4d_load_profile_irqs();
@@ -550,7 +572,7 @@ void __init sun4d_init_sbi_irq(void)
550 nsbi = 0; 572 nsbi = 0;
551 for_each_node_by_name(dp, "sbi") 573 for_each_node_by_name(dp, "sbi")
552 nsbi++; 574 nsbi++;
553 sbus_actions = kzalloc (nsbi * 8 * 4 * sizeof(struct sbus_action), GFP_ATOMIC); 575 sbus_actions = kzalloc(nsbi * 8 * 4 * sizeof(struct sbus_action), GFP_ATOMIC);
554 if (!sbus_actions) { 576 if (!sbus_actions) {
555 prom_printf("SUN4D: Cannot allocate sbus_actions, halting.\n"); 577 prom_printf("SUN4D: Cannot allocate sbus_actions, halting.\n");
556 prom_halt(); 578 prom_halt();
@@ -566,7 +588,8 @@ void __init sun4d_init_sbi_irq(void)
566 /* Get rid of pending irqs from PROM */ 588 /* Get rid of pending irqs from PROM */
567 mask = acquire_sbi(devid, 0xffffffff); 589 mask = acquire_sbi(devid, 0xffffffff);
568 if (mask) { 590 if (mask) {
569 printk ("Clearing pending IRQs %08x on SBI %d\n", mask, board); 591 printk(KERN_ERR "Clearing pending IRQs %08x on SBI %d\n",
592 mask, board);
570 release_sbi(devid, mask); 593 release_sbi(devid, mask);
571 } 594 }
572 } 595 }
diff --git a/arch/sparc/kernel/sun4d_smp.c b/arch/sparc/kernel/sun4d_smp.c
index 482f2ab92692..475d50b96cd0 100644
--- a/arch/sparc/kernel/sun4d_smp.c
+++ b/arch/sparc/kernel/sun4d_smp.c
@@ -1,4 +1,4 @@
1/* sun4d_smp.c: Sparc SS1000/SC2000 SMP support. 1/* Sparc SS1000/SC2000 SMP support.
2 * 2 *
3 * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz) 3 * Copyright (C) 1998 Jakub Jelinek (jj@sunsite.mff.cuni.cz)
4 * 4 *
@@ -6,59 +6,23 @@
6 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu) 6 * Copyright (C) 1996 David S. Miller (davem@caip.rutgers.edu)
7 */ 7 */
8 8
9#include <asm/head.h>
10
11#include <linux/kernel.h>
12#include <linux/sched.h>
13#include <linux/threads.h>
14#include <linux/smp.h>
15#include <linux/interrupt.h> 9#include <linux/interrupt.h>
16#include <linux/kernel_stat.h>
17#include <linux/init.h>
18#include <linux/spinlock.h>
19#include <linux/mm.h>
20#include <linux/swap.h>
21#include <linux/profile.h> 10#include <linux/profile.h>
22#include <linux/delay.h> 11#include <linux/delay.h>
23#include <linux/cpu.h> 12#include <linux/cpu.h>
24 13
25#include <asm/ptrace.h>
26#include <asm/atomic.h>
27#include <asm/irq_regs.h>
28
29#include <asm/irq.h>
30#include <asm/page.h>
31#include <asm/pgalloc.h>
32#include <asm/pgtable.h>
33#include <asm/oplib.h>
34#include <asm/sbi.h> 14#include <asm/sbi.h>
15#include <asm/mmu.h>
35#include <asm/tlbflush.h> 16#include <asm/tlbflush.h>
36#include <asm/cacheflush.h> 17#include <asm/cacheflush.h>
37#include <asm/cpudata.h>
38 18
19#include "kernel.h"
39#include "irq.h" 20#include "irq.h"
40#define IRQ_CROSS_CALL 15
41 21
42extern ctxd_t *srmmu_ctx_table_phys; 22#define IRQ_CROSS_CALL 15
43 23
44static volatile int smp_processors_ready = 0; 24static volatile int smp_processors_ready;
45static int smp_highest_cpu; 25static int smp_highest_cpu;
46extern volatile unsigned long cpu_callin_map[NR_CPUS];
47extern cpuinfo_sparc cpu_data[NR_CPUS];
48extern unsigned char boot_cpu_id;
49extern volatile int smp_process_available;
50
51extern cpumask_t smp_commenced_mask;
52
53extern int __smp4d_processor_id(void);
54
55/* #define SMP_DEBUG */
56
57#ifdef SMP_DEBUG
58#define SMP_PRINTK(x) printk x
59#else
60#define SMP_PRINTK(x)
61#endif
62 26
63static inline unsigned long sun4d_swap(volatile unsigned long *ptr, unsigned long val) 27static inline unsigned long sun4d_swap(volatile unsigned long *ptr, unsigned long val)
64{ 28{
@@ -69,8 +33,6 @@ static inline unsigned long sun4d_swap(volatile unsigned long *ptr, unsigned lon
69} 33}
70 34
71static void smp_setup_percpu_timer(void); 35static void smp_setup_percpu_timer(void);
72extern void cpu_probe(void);
73extern void sun4d_distribute_irqs(void);
74 36
75static unsigned char cpu_leds[32]; 37static unsigned char cpu_leds[32];
76 38
@@ -86,9 +48,8 @@ static inline void show_leds(int cpuid)
86void __cpuinit smp4d_callin(void) 48void __cpuinit smp4d_callin(void)
87{ 49{
88 int cpuid = hard_smp4d_processor_id(); 50 int cpuid = hard_smp4d_processor_id();
89 extern spinlock_t sun4d_imsk_lock;
90 unsigned long flags; 51 unsigned long flags;
91 52
92 /* Show we are alive */ 53 /* Show we are alive */
93 cpu_leds[cpuid] = 0x6; 54 cpu_leds[cpuid] = 0x6;
94 show_leds(cpuid); 55 show_leds(cpuid);
@@ -118,15 +79,15 @@ void __cpuinit smp4d_callin(void)
118 sun4d_swap((unsigned long *)&cpu_callin_map[cpuid], 1); 79 sun4d_swap((unsigned long *)&cpu_callin_map[cpuid], 1);
119 local_flush_cache_all(); 80 local_flush_cache_all();
120 local_flush_tlb_all(); 81 local_flush_tlb_all();
121 82
122 cpu_probe(); 83 cpu_probe();
123 84
124 while((unsigned long)current_set[cpuid] < PAGE_OFFSET) 85 while ((unsigned long)current_set[cpuid] < PAGE_OFFSET)
125 barrier(); 86 barrier();
126 87
127 while(current_set[cpuid]->cpu != cpuid) 88 while (current_set[cpuid]->cpu != cpuid)
128 barrier(); 89 barrier();
129 90
130 /* Fix idle thread fields. */ 91 /* Fix idle thread fields. */
131 __asm__ __volatile__("ld [%0], %%g6\n\t" 92 __asm__ __volatile__("ld [%0], %%g6\n\t"
132 : : "r" (&current_set[cpuid]) 93 : : "r" (&current_set[cpuid])
@@ -134,16 +95,16 @@ void __cpuinit smp4d_callin(void)
134 95
135 cpu_leds[cpuid] = 0x9; 96 cpu_leds[cpuid] = 0x9;
136 show_leds(cpuid); 97 show_leds(cpuid);
137 98
138 /* Attach to the address space of init_task. */ 99 /* Attach to the address space of init_task. */
139 atomic_inc(&init_mm.mm_count); 100 atomic_inc(&init_mm.mm_count);
140 current->active_mm = &init_mm; 101 current->active_mm = &init_mm;
141 102
142 local_flush_cache_all(); 103 local_flush_cache_all();
143 local_flush_tlb_all(); 104 local_flush_tlb_all();
144 105
145 local_irq_enable(); /* We don't allow PIL 14 yet */ 106 local_irq_enable(); /* We don't allow PIL 14 yet */
146 107
147 while (!cpu_isset(cpuid, smp_commenced_mask)) 108 while (!cpu_isset(cpuid, smp_commenced_mask))
148 barrier(); 109 barrier();
149 110
@@ -154,15 +115,9 @@ void __cpuinit smp4d_callin(void)
154 115
155} 116}
156 117
157extern void init_IRQ(void);
158extern void cpu_panic(void);
159
160/* 118/*
161 * Cycle through the processors asking the PROM to start each one. 119 * Cycle through the processors asking the PROM to start each one.
162 */ 120 */
163
164extern struct linux_prom_registers smp_penguin_ctable;
165
166void __init smp4d_boot_cpus(void) 121void __init smp4d_boot_cpus(void)
167{ 122{
168 if (boot_cpu_id) 123 if (boot_cpu_id)
@@ -173,43 +128,42 @@ void __init smp4d_boot_cpus(void)
173 128
174int __cpuinit smp4d_boot_one_cpu(int i) 129int __cpuinit smp4d_boot_one_cpu(int i)
175{ 130{
176 extern unsigned long sun4d_cpu_startup; 131 unsigned long *entry = &sun4d_cpu_startup;
177 unsigned long *entry = &sun4d_cpu_startup; 132 struct task_struct *p;
178 struct task_struct *p; 133 int timeout;
179 int timeout; 134 int cpu_node;
180 int cpu_node;
181 135
182 cpu_find_by_instance(i, &cpu_node,NULL); 136 cpu_find_by_instance(i, &cpu_node, NULL);
183 /* Cook up an idler for this guy. */ 137 /* Cook up an idler for this guy. */
184 p = fork_idle(i); 138 p = fork_idle(i);
185 current_set[i] = task_thread_info(p); 139 current_set[i] = task_thread_info(p);
140
141 /*
142 * Initialize the contexts table
143 * Since the call to prom_startcpu() trashes the structure,
144 * we need to re-initialize it for each cpu
145 */
146 smp_penguin_ctable.which_io = 0;
147 smp_penguin_ctable.phys_addr = (unsigned int) srmmu_ctx_table_phys;
148 smp_penguin_ctable.reg_size = 0;
149
150 /* whirrr, whirrr, whirrrrrrrrr... */
151 printk(KERN_INFO "Starting CPU %d at %p\n", i, entry);
152 local_flush_cache_all();
153 prom_startcpu(cpu_node,
154 &smp_penguin_ctable, 0, (char *)entry);
155
156 printk(KERN_INFO "prom_startcpu returned :)\n");
157
158 /* wheee... it's going... */
159 for (timeout = 0; timeout < 10000; timeout++) {
160 if (cpu_callin_map[i])
161 break;
162 udelay(200);
163 }
186 164
187 /*
188 * Initialize the contexts table
189 * Since the call to prom_startcpu() trashes the structure,
190 * we need to re-initialize it for each cpu
191 */
192 smp_penguin_ctable.which_io = 0;
193 smp_penguin_ctable.phys_addr = (unsigned int) srmmu_ctx_table_phys;
194 smp_penguin_ctable.reg_size = 0;
195
196 /* whirrr, whirrr, whirrrrrrrrr... */
197 SMP_PRINTK(("Starting CPU %d at %p\n", i, entry));
198 local_flush_cache_all();
199 prom_startcpu(cpu_node,
200 &smp_penguin_ctable, 0, (char *)entry);
201
202 SMP_PRINTK(("prom_startcpu returned :)\n"));
203
204 /* wheee... it's going... */
205 for(timeout = 0; timeout < 10000; timeout++) {
206 if(cpu_callin_map[i])
207 break;
208 udelay(200);
209 }
210
211 if (!(cpu_callin_map[i])) { 165 if (!(cpu_callin_map[i])) {
212 printk("Processor %d is stuck.\n", i); 166 printk(KERN_ERR "Processor %d is stuck.\n", i);
213 return -ENODEV; 167 return -ENODEV;
214 168
215 } 169 }
@@ -255,14 +209,17 @@ static void smp4d_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
255 unsigned long arg2, unsigned long arg3, 209 unsigned long arg2, unsigned long arg3,
256 unsigned long arg4) 210 unsigned long arg4)
257{ 211{
258 if(smp_processors_ready) { 212 if (smp_processors_ready) {
259 register int high = smp_highest_cpu; 213 register int high = smp_highest_cpu;
260 unsigned long flags; 214 unsigned long flags;
261 215
262 spin_lock_irqsave(&cross_call_lock, flags); 216 spin_lock_irqsave(&cross_call_lock, flags);
263 217
264 { 218 {
265 /* If you make changes here, make sure gcc generates proper code... */ 219 /*
220 * If you make changes here, make sure
221 * gcc generates proper code...
222 */
266 register smpfunc_t f asm("i0") = func; 223 register smpfunc_t f asm("i0") = func;
267 register unsigned long a1 asm("i1") = arg1; 224 register unsigned long a1 asm("i1") = arg1;
268 register unsigned long a2 asm("i2") = arg2; 225 register unsigned long a2 asm("i2") = arg2;
@@ -284,7 +241,7 @@ static void smp4d_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
284 241
285 cpu_clear(smp_processor_id(), mask); 242 cpu_clear(smp_processor_id(), mask);
286 cpus_and(mask, cpu_online_map, mask); 243 cpus_and(mask, cpu_online_map, mask);
287 for(i = 0; i <= high; i++) { 244 for (i = 0; i <= high; i++) {
288 if (cpu_isset(i, mask)) { 245 if (cpu_isset(i, mask)) {
289 ccall_info.processors_in[i] = 0; 246 ccall_info.processors_in[i] = 0;
290 ccall_info.processors_out[i] = 0; 247 ccall_info.processors_out[i] = 0;
@@ -300,17 +257,17 @@ static void smp4d_cross_call(smpfunc_t func, cpumask_t mask, unsigned long arg1,
300 do { 257 do {
301 if (!cpu_isset(i, mask)) 258 if (!cpu_isset(i, mask))
302 continue; 259 continue;
303 while(!ccall_info.processors_in[i]) 260 while (!ccall_info.processors_in[i])
304 barrier(); 261 barrier();
305 } while(++i <= high); 262 } while (++i <= high);
306 263
307 i = 0; 264 i = 0;
308 do { 265 do {
309 if (!cpu_isset(i, mask)) 266 if (!cpu_isset(i, mask))
310 continue; 267 continue;
311 while(!ccall_info.processors_out[i]) 268 while (!ccall_info.processors_out[i])
312 barrier(); 269 barrier();
313 } while(++i <= high); 270 } while (++i <= high);
314 } 271 }
315 272
316 spin_unlock_irqrestore(&cross_call_lock, flags); 273 spin_unlock_irqrestore(&cross_call_lock, flags);
@@ -336,7 +293,7 @@ void smp4d_percpu_timer_interrupt(struct pt_regs *regs)
336 static char led_mask[] = { 0xe, 0xd, 0xb, 0x7, 0xb, 0xd }; 293 static char led_mask[] = { 0xe, 0xd, 0xb, 0x7, 0xb, 0xd };
337 294
338 old_regs = set_irq_regs(regs); 295 old_regs = set_irq_regs(regs);
339 bw_get_prof_limit(cpu); 296 bw_get_prof_limit(cpu);
340 bw_clear_intr_mask(0, 1); /* INTR_TABLE[0] & 1 is Profile IRQ */ 297 bw_clear_intr_mask(0, 1); /* INTR_TABLE[0] & 1 is Profile IRQ */
341 298
342 cpu_tick[cpu]++; 299 cpu_tick[cpu]++;
@@ -349,7 +306,7 @@ void smp4d_percpu_timer_interrupt(struct pt_regs *regs)
349 306
350 profile_tick(CPU_PROFILING); 307 profile_tick(CPU_PROFILING);
351 308
352 if(!--prof_counter(cpu)) { 309 if (!--prof_counter(cpu)) {
353 int user = user_mode(regs); 310 int user = user_mode(regs);
354 311
355 irq_enter(); 312 irq_enter();
@@ -361,8 +318,6 @@ void smp4d_percpu_timer_interrupt(struct pt_regs *regs)
361 set_irq_regs(old_regs); 318 set_irq_regs(old_regs);
362} 319}
363 320
364extern unsigned int lvl14_resolution;
365
366static void __cpuinit smp_setup_percpu_timer(void) 321static void __cpuinit smp_setup_percpu_timer(void)
367{ 322{
368 int cpu = hard_smp4d_processor_id(); 323 int cpu = hard_smp4d_processor_id();
@@ -374,16 +329,16 @@ static void __cpuinit smp_setup_percpu_timer(void)
374void __init smp4d_blackbox_id(unsigned *addr) 329void __init smp4d_blackbox_id(unsigned *addr)
375{ 330{
376 int rd = *addr & 0x3e000000; 331 int rd = *addr & 0x3e000000;
377 332
378 addr[0] = 0xc0800800 | rd; /* lda [%g0] ASI_M_VIKING_TMP1, reg */ 333 addr[0] = 0xc0800800 | rd; /* lda [%g0] ASI_M_VIKING_TMP1, reg */
379 addr[1] = 0x01000000; /* nop */ 334 addr[1] = 0x01000000; /* nop */
380 addr[2] = 0x01000000; /* nop */ 335 addr[2] = 0x01000000; /* nop */
381} 336}
382 337
383void __init smp4d_blackbox_current(unsigned *addr) 338void __init smp4d_blackbox_current(unsigned *addr)
384{ 339{
385 int rd = *addr & 0x3e000000; 340 int rd = *addr & 0x3e000000;
386 341
387 addr[0] = 0xc0800800 | rd; /* lda [%g0] ASI_M_VIKING_TMP1, reg */ 342 addr[0] = 0xc0800800 | rd; /* lda [%g0] ASI_M_VIKING_TMP1, reg */
388 addr[2] = 0x81282002 | rd | (rd >> 11); /* sll reg, 2, reg */ 343 addr[2] = 0x81282002 | rd | (rd >> 11); /* sll reg, 2, reg */
389 addr[4] = 0x01000000; /* nop */ 344 addr[4] = 0x01000000; /* nop */
@@ -392,17 +347,16 @@ void __init smp4d_blackbox_current(unsigned *addr)
392void __init sun4d_init_smp(void) 347void __init sun4d_init_smp(void)
393{ 348{
394 int i; 349 int i;
395 extern unsigned int t_nmi[], linux_trap_ipi15_sun4d[], linux_trap_ipi15_sun4m[];
396 350
397 /* Patch ipi15 trap table */ 351 /* Patch ipi15 trap table */
398 t_nmi[1] = t_nmi[1] + (linux_trap_ipi15_sun4d - linux_trap_ipi15_sun4m); 352 t_nmi[1] = t_nmi[1] + (linux_trap_ipi15_sun4d - linux_trap_ipi15_sun4m);
399 353
400 /* And set btfixup... */ 354 /* And set btfixup... */
401 BTFIXUPSET_BLACKBOX(hard_smp_processor_id, smp4d_blackbox_id); 355 BTFIXUPSET_BLACKBOX(hard_smp_processor_id, smp4d_blackbox_id);
402 BTFIXUPSET_BLACKBOX(load_current, smp4d_blackbox_current); 356 BTFIXUPSET_BLACKBOX(load_current, smp4d_blackbox_current);
403 BTFIXUPSET_CALL(smp_cross_call, smp4d_cross_call, BTFIXUPCALL_NORM); 357 BTFIXUPSET_CALL(smp_cross_call, smp4d_cross_call, BTFIXUPCALL_NORM);
404 BTFIXUPSET_CALL(__hard_smp_processor_id, __smp4d_processor_id, BTFIXUPCALL_NORM); 358 BTFIXUPSET_CALL(__hard_smp_processor_id, __smp4d_processor_id, BTFIXUPCALL_NORM);
405 359
406 for (i = 0; i < NR_CPUS; i++) { 360 for (i = 0; i < NR_CPUS; i++) {
407 ccall_info.processors_in[i] = 1; 361 ccall_info.processors_in[i] = 1;
408 ccall_info.processors_out[i] = 1; 362 ccall_info.processors_out[i] = 1;