1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <linux/kernel.h>
21#include <linux/sched.h>
22#include <linux/sched/hotplug.h>
23#include <linux/smp.h>
24#include <linux/interrupt.h>
25#include <linux/kernel_stat.h>
26#include <linux/delay.h>
27#include <linux/init.h>
28#include <linux/spinlock.h>
29#include <linux/errno.h>
30#include <linux/hardirq.h>
31#include <linux/cpu.h>
32#include <linux/compiler.h>
33
34#include <asm/ptrace.h>
35#include <linux/atomic.h>
36#include <asm/code-patching.h>
37#include <asm/irq.h>
38#include <asm/page.h>
39#include <asm/pgtable.h>
40#include <asm/sections.h>
41#include <asm/io.h>
42#include <asm/prom.h>
43#include <asm/smp.h>
44#include <asm/machdep.h>
45#include <asm/pmac_feature.h>
46#include <asm/time.h>
47#include <asm/mpic.h>
48#include <asm/cacheflush.h>
49#include <asm/keylargo.h>
50#include <asm/pmac_low_i2c.h>
51#include <asm/pmac_pfunc.h>
52
53#include "pmac.h"
54
55#undef DEBUG
56
57#ifdef DEBUG
58#define DBG(fmt...) udbg_printf(fmt)
59#else
60#define DBG(fmt...)
61#endif
62
63extern void __secondary_start_pmac_0(void);
64
65static void (*pmac_tb_freeze)(int freeze);
66static u64 timebase;
67static int tb_req;
68
69#ifdef CONFIG_PPC_PMAC32_PSURGE
70
71
72
73
74
75
76#define HAMMERHEAD_BASE 0xf8000000
77#define HHEAD_CONFIG 0x90
78#define HHEAD_SEC_INTR 0xc0
79
80
81
82#define PSURGE_PRI_INTR 0xf3019000
83
84
85
86#define PSURGE_START 0xf2800000
87
88
89#define PSURGE_QUAD_REG_ADDR 0xf8800000
90
91#define PSURGE_QUAD_IRQ_SET 0
92#define PSURGE_QUAD_IRQ_CLR 1
93#define PSURGE_QUAD_IRQ_PRIMARY 2
94#define PSURGE_QUAD_CKSTOP_CTL 3
95#define PSURGE_QUAD_PRIMARY_ARB 4
96#define PSURGE_QUAD_BOARD_ID 6
97#define PSURGE_QUAD_WHICH_CPU 7
98#define PSURGE_QUAD_CKSTOP_RDBK 8
99#define PSURGE_QUAD_RESET_CTL 11
100
101#define PSURGE_QUAD_OUT(r, v) (out_8(quad_base + ((r) << 4) + 4, (v)))
102#define PSURGE_QUAD_IN(r) (in_8(quad_base + ((r) << 4) + 4) & 0x0f)
103#define PSURGE_QUAD_BIS(r, v) (PSURGE_QUAD_OUT((r), PSURGE_QUAD_IN(r) | (v)))
104#define PSURGE_QUAD_BIC(r, v) (PSURGE_QUAD_OUT((r), PSURGE_QUAD_IN(r) & ~(v)))
105
106
107static volatile u8 __iomem *hhead_base;
108static volatile u8 __iomem *quad_base;
109static volatile u32 __iomem *psurge_pri_intr;
110static volatile u8 __iomem *psurge_sec_intr;
111static volatile u32 __iomem *psurge_start;
112
113
114#define PSURGE_NONE -1
115#define PSURGE_DUAL 0
116#define PSURGE_QUAD_OKEE 1
117#define PSURGE_QUAD_COTTON 2
118#define PSURGE_QUAD_ICEGRASS 3
119
120
121static int psurge_type = PSURGE_NONE;
122
123
124static struct irq_domain *psurge_host;
125int psurge_secondary_virq;
126
127
128
129
130static inline void psurge_set_ipi(int cpu)
131{
132 if (psurge_type == PSURGE_NONE)
133 return;
134 if (cpu == 0)
135 in_be32(psurge_pri_intr);
136 else if (psurge_type == PSURGE_DUAL)
137 out_8(psurge_sec_intr, 0);
138 else
139 PSURGE_QUAD_OUT(PSURGE_QUAD_IRQ_SET, 1 << cpu);
140}
141
142static inline void psurge_clr_ipi(int cpu)
143{
144 if (cpu > 0) {
145 switch(psurge_type) {
146 case PSURGE_DUAL:
147 out_8(psurge_sec_intr, ~0);
148 case PSURGE_NONE:
149 break;
150 default:
151 PSURGE_QUAD_OUT(PSURGE_QUAD_IRQ_CLR, 1 << cpu);
152 }
153 }
154}
155
156
157
158
159
160
161
162static irqreturn_t psurge_ipi_intr(int irq, void *d)
163{
164 psurge_clr_ipi(smp_processor_id());
165 smp_ipi_demux();
166
167 return IRQ_HANDLED;
168}
169
170static void smp_psurge_cause_ipi(int cpu)
171{
172 psurge_set_ipi(cpu);
173}
174
175static int psurge_host_map(struct irq_domain *h, unsigned int virq,
176 irq_hw_number_t hw)
177{
178 irq_set_chip_and_handler(virq, &dummy_irq_chip, handle_percpu_irq);
179
180 return 0;
181}
182
183static const struct irq_domain_ops psurge_host_ops = {
184 .map = psurge_host_map,
185};
186
187static int psurge_secondary_ipi_init(void)
188{
189 int rc = -ENOMEM;
190
191 psurge_host = irq_domain_add_nomap(NULL, ~0, &psurge_host_ops, NULL);
192
193 if (psurge_host)
194 psurge_secondary_virq = irq_create_direct_mapping(psurge_host);
195
196 if (psurge_secondary_virq)
197 rc = request_irq(psurge_secondary_virq, psurge_ipi_intr,
198 IRQF_PERCPU | IRQF_NO_THREAD, "IPI", NULL);
199
200 if (rc)
201 pr_err("Failed to setup secondary cpu IPI\n");
202
203 return rc;
204}
205
206
207
208
209
210
211static int __init psurge_quad_probe(void)
212{
213 int type;
214 unsigned int i;
215
216 type = PSURGE_QUAD_IN(PSURGE_QUAD_BOARD_ID);
217 if (type < PSURGE_QUAD_OKEE || type > PSURGE_QUAD_ICEGRASS
218 || type != PSURGE_QUAD_IN(PSURGE_QUAD_BOARD_ID))
219 return PSURGE_DUAL;
220
221
222
223
224 for (i = 0; i < 100; i++) {
225 volatile u32 bogus[8];
226 bogus[(0+i)%8] = 0x00000000;
227 bogus[(1+i)%8] = 0x55555555;
228 bogus[(2+i)%8] = 0xFFFFFFFF;
229 bogus[(3+i)%8] = 0xAAAAAAAA;
230 bogus[(4+i)%8] = 0x33333333;
231 bogus[(5+i)%8] = 0xCCCCCCCC;
232 bogus[(6+i)%8] = 0xCCCCCCCC;
233 bogus[(7+i)%8] = 0x33333333;
234 wmb();
235 asm volatile("dcbf 0,%0" : : "r" (bogus) : "memory");
236 mb();
237 if (type != PSURGE_QUAD_IN(PSURGE_QUAD_BOARD_ID))
238 return PSURGE_DUAL;
239 }
240 return type;
241}
242
243static void __init psurge_quad_init(void)
244{
245 int procbits;
246
247 if (ppc_md.progress) ppc_md.progress("psurge_quad_init", 0x351);
248 procbits = ~PSURGE_QUAD_IN(PSURGE_QUAD_WHICH_CPU);
249 if (psurge_type == PSURGE_QUAD_ICEGRASS)
250 PSURGE_QUAD_BIS(PSURGE_QUAD_RESET_CTL, procbits);
251 else
252 PSURGE_QUAD_BIC(PSURGE_QUAD_CKSTOP_CTL, procbits);
253 mdelay(33);
254 out_8(psurge_sec_intr, ~0);
255 PSURGE_QUAD_OUT(PSURGE_QUAD_IRQ_CLR, procbits);
256 PSURGE_QUAD_BIS(PSURGE_QUAD_RESET_CTL, procbits);
257 if (psurge_type != PSURGE_QUAD_ICEGRASS)
258 PSURGE_QUAD_BIS(PSURGE_QUAD_CKSTOP_CTL, procbits);
259 PSURGE_QUAD_BIC(PSURGE_QUAD_PRIMARY_ARB, procbits);
260 mdelay(33);
261 PSURGE_QUAD_BIC(PSURGE_QUAD_RESET_CTL, procbits);
262 mdelay(33);
263 PSURGE_QUAD_BIS(PSURGE_QUAD_PRIMARY_ARB, procbits);
264 mdelay(33);
265}
266
267static void __init smp_psurge_probe(void)
268{
269 int i, ncpus;
270 struct device_node *dn;
271
272
273 if (PVR_VER(mfspr(SPRN_PVR)) == 1)
274 return;
275
276
277
278
279
280
281
282
283
284
285
286 dn = of_find_node_by_name(NULL, "hammerhead");
287 if (dn == NULL)
288 return;
289 of_node_put(dn);
290
291 hhead_base = ioremap(HAMMERHEAD_BASE, 0x800);
292 quad_base = ioremap(PSURGE_QUAD_REG_ADDR, 1024);
293 psurge_sec_intr = hhead_base + HHEAD_SEC_INTR;
294
295 psurge_type = psurge_quad_probe();
296 if (psurge_type != PSURGE_DUAL) {
297 psurge_quad_init();
298
299 ncpus = 4;
300
301 smp_ops->give_timebase = smp_generic_give_timebase;
302 smp_ops->take_timebase = smp_generic_take_timebase;
303 } else {
304 iounmap(quad_base);
305 if ((in_8(hhead_base + HHEAD_CONFIG) & 0x02) == 0) {
306
307 iounmap(hhead_base);
308 psurge_type = PSURGE_NONE;
309 return;
310 }
311 ncpus = 2;
312 }
313
314 if (psurge_secondary_ipi_init())
315 return;
316
317 psurge_start = ioremap(PSURGE_START, 4);
318 psurge_pri_intr = ioremap(PSURGE_PRI_INTR, 4);
319
320
321
322
323
324
325 if (ncpus > NR_CPUS)
326 ncpus = NR_CPUS;
327 for (i = 1; i < ncpus ; ++i)
328 set_cpu_present(i, true);
329
330 if (ppc_md.progress) ppc_md.progress("smp_psurge_probe - done", 0x352);
331}
332
333static int __init smp_psurge_kick_cpu(int nr)
334{
335 unsigned long start = __pa(__secondary_start_pmac_0) + nr * 8;
336 unsigned long a, flags;
337 int i, j;
338
339
340
341
342
343 extern volatile unsigned int cpu_callin_map[NR_CPUS];
344
345
346 for (a = KERNELBASE; a < KERNELBASE + 0x800000; a += 32)
347 asm volatile("dcbf 0,%0" : : "r" (a) : "memory");
348 asm volatile("sync");
349
350 if (ppc_md.progress) ppc_md.progress("smp_psurge_kick_cpu", 0x353);
351
352
353 local_irq_save(flags);
354
355 out_be32(psurge_start, start);
356 mb();
357
358 psurge_set_ipi(nr);
359
360
361
362
363 for (i = 0; i < 2000; ++i)
364 asm volatile("nop" : : : "memory");
365 psurge_clr_ipi(nr);
366
367
368
369
370
371
372 for (i = 0; i < 100000 && !cpu_callin_map[nr]; ++i) {
373 for (j = 1; j < 10000; j++)
374 asm volatile("nop" : : : "memory");
375 asm volatile("sync" : : : "memory");
376 }
377 if (!cpu_callin_map[nr])
378 goto stuck;
379
380
381 if (psurge_type == PSURGE_DUAL) {
382 while(!tb_req)
383 barrier();
384 tb_req = 0;
385 mb();
386 timebase = get_tb();
387 mb();
388 while (timebase)
389 barrier();
390 mb();
391 }
392 stuck:
393
394 if (psurge_type == PSURGE_DUAL)
395 psurge_set_ipi(1);
396
397 if (ppc_md.progress) ppc_md.progress("smp_psurge_kick_cpu - done", 0x354);
398
399 return 0;
400}
401
402static struct irqaction psurge_irqaction = {
403 .handler = psurge_ipi_intr,
404 .flags = IRQF_PERCPU | IRQF_NO_THREAD,
405 .name = "primary IPI",
406};
407
408static void __init smp_psurge_setup_cpu(int cpu_nr)
409{
410 if (cpu_nr != 0 || !psurge_start)
411 return;
412
413
414
415 out_be32(psurge_start, 0x100);
416 if (setup_irq(irq_create_mapping(NULL, 30), &psurge_irqaction))
417 printk(KERN_ERR "Couldn't get primary IPI interrupt");
418}
419
420void __init smp_psurge_take_timebase(void)
421{
422 if (psurge_type != PSURGE_DUAL)
423 return;
424
425 tb_req = 1;
426 mb();
427 while (!timebase)
428 barrier();
429 mb();
430 set_tb(timebase >> 32, timebase & 0xffffffff);
431 timebase = 0;
432 mb();
433 set_dec(tb_ticks_per_jiffy/2);
434}
435
436void __init smp_psurge_give_timebase(void)
437{
438
439}
440
441
442struct smp_ops_t psurge_smp_ops = {
443 .message_pass = NULL,
444 .cause_ipi = smp_psurge_cause_ipi,
445 .cause_nmi_ipi = NULL,
446 .probe = smp_psurge_probe,
447 .kick_cpu = smp_psurge_kick_cpu,
448 .setup_cpu = smp_psurge_setup_cpu,
449 .give_timebase = smp_psurge_give_timebase,
450 .take_timebase = smp_psurge_take_timebase,
451};
452#endif
453
454
455
456
457
458
459static void smp_core99_give_timebase(void)
460{
461 unsigned long flags;
462
463 local_irq_save(flags);
464
465 while(!tb_req)
466 barrier();
467 tb_req = 0;
468 (*pmac_tb_freeze)(1);
469 mb();
470 timebase = get_tb();
471 mb();
472 while (timebase)
473 barrier();
474 mb();
475 (*pmac_tb_freeze)(0);
476 mb();
477
478 local_irq_restore(flags);
479}
480
481
482static void smp_core99_take_timebase(void)
483{
484 unsigned long flags;
485
486 local_irq_save(flags);
487
488 tb_req = 1;
489 mb();
490 while (!timebase)
491 barrier();
492 mb();
493 set_tb(timebase >> 32, timebase & 0xffffffff);
494 timebase = 0;
495 mb();
496
497 local_irq_restore(flags);
498}
499
500#ifdef CONFIG_PPC64
501
502
503
504static struct pmac_i2c_bus *pmac_tb_clock_chip_host;
505static u8 pmac_tb_pulsar_addr;
506
507static void smp_core99_cypress_tb_freeze(int freeze)
508{
509 u8 data;
510 int rc;
511
512
513
514
515 pmac_i2c_setmode(pmac_tb_clock_chip_host,
516 pmac_i2c_mode_combined);
517 rc = pmac_i2c_xfer(pmac_tb_clock_chip_host,
518 0xd0 | pmac_i2c_read,
519 1, 0x81, &data, 1);
520 if (rc != 0)
521 goto bail;
522
523 data = (data & 0xf3) | (freeze ? 0x00 : 0x0c);
524
525 pmac_i2c_setmode(pmac_tb_clock_chip_host, pmac_i2c_mode_stdsub);
526 rc = pmac_i2c_xfer(pmac_tb_clock_chip_host,
527 0xd0 | pmac_i2c_write,
528 1, 0x81, &data, 1);
529
530 bail:
531 if (rc != 0) {
532 printk("Cypress Timebase %s rc: %d\n",
533 freeze ? "freeze" : "unfreeze", rc);
534 panic("Timebase freeze failed !\n");
535 }
536}
537
538
539static void smp_core99_pulsar_tb_freeze(int freeze)
540{
541 u8 data;
542 int rc;
543
544 pmac_i2c_setmode(pmac_tb_clock_chip_host,
545 pmac_i2c_mode_combined);
546 rc = pmac_i2c_xfer(pmac_tb_clock_chip_host,
547 pmac_tb_pulsar_addr | pmac_i2c_read,
548 1, 0x2e, &data, 1);
549 if (rc != 0)
550 goto bail;
551
552 data = (data & 0x88) | (freeze ? 0x11 : 0x22);
553
554 pmac_i2c_setmode(pmac_tb_clock_chip_host, pmac_i2c_mode_stdsub);
555 rc = pmac_i2c_xfer(pmac_tb_clock_chip_host,
556 pmac_tb_pulsar_addr | pmac_i2c_write,
557 1, 0x2e, &data, 1);
558 bail:
559 if (rc != 0) {
560 printk(KERN_ERR "Pulsar Timebase %s rc: %d\n",
561 freeze ? "freeze" : "unfreeze", rc);
562 panic("Timebase freeze failed !\n");
563 }
564}
565
566static void __init smp_core99_setup_i2c_hwsync(int ncpus)
567{
568 struct device_node *cc = NULL;
569 struct device_node *p;
570 const char *name = NULL;
571 const u32 *reg;
572 int ok;
573
574
575 for_each_node_by_name(cc, "i2c-hwclock") {
576 p = of_get_parent(cc);
577 ok = p && of_device_is_compatible(p, "uni-n-i2c");
578 of_node_put(p);
579 if (!ok)
580 continue;
581
582 pmac_tb_clock_chip_host = pmac_i2c_find_bus(cc);
583 if (pmac_tb_clock_chip_host == NULL)
584 continue;
585 reg = of_get_property(cc, "reg", NULL);
586 if (reg == NULL)
587 continue;
588 switch (*reg) {
589 case 0xd2:
590 if (of_device_is_compatible(cc,"pulsar-legacy-slewing")) {
591 pmac_tb_freeze = smp_core99_pulsar_tb_freeze;
592 pmac_tb_pulsar_addr = 0xd2;
593 name = "Pulsar";
594 } else if (of_device_is_compatible(cc, "cy28508")) {
595 pmac_tb_freeze = smp_core99_cypress_tb_freeze;
596 name = "Cypress";
597 }
598 break;
599 case 0xd4:
600 pmac_tb_freeze = smp_core99_pulsar_tb_freeze;
601 pmac_tb_pulsar_addr = 0xd4;
602 name = "Pulsar";
603 break;
604 }
605 if (pmac_tb_freeze != NULL)
606 break;
607 }
608 if (pmac_tb_freeze != NULL) {
609
610 if (pmac_i2c_open(pmac_tb_clock_chip_host, 1)) {
611 printk(KERN_ERR "Failed top open i2c bus for clock"
612 " sync, fallback to software sync !\n");
613 goto no_i2c_sync;
614 }
615 printk(KERN_INFO "Processor timebase sync using %s i2c clock\n",
616 name);
617 return;
618 }
619 no_i2c_sync:
620 pmac_tb_freeze = NULL;
621 pmac_tb_clock_chip_host = NULL;
622}
623
624
625
626
627
628
629
630static void smp_core99_pfunc_tb_freeze(int freeze)
631{
632 struct device_node *cpus;
633 struct pmf_args args;
634
635 cpus = of_find_node_by_path("/cpus");
636 BUG_ON(cpus == NULL);
637 args.count = 1;
638 args.u[0].v = !freeze;
639 pmf_call_function(cpus, "cpu-timebase", &args);
640 of_node_put(cpus);
641}
642
643#else
644
645
646
647
648
649static unsigned int core99_tb_gpio;
650
651static void smp_core99_gpio_tb_freeze(int freeze)
652{
653 if (freeze)
654 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, core99_tb_gpio, 4);
655 else
656 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, core99_tb_gpio, 0);
657 pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, core99_tb_gpio, 0);
658}
659
660
661#endif
662
663
664volatile static long int core99_l2_cache;
665volatile static long int core99_l3_cache;
666
667static void core99_init_caches(int cpu)
668{
669#ifndef CONFIG_PPC64
670 if (!cpu_has_feature(CPU_FTR_L2CR))
671 return;
672
673 if (cpu == 0) {
674 core99_l2_cache = _get_L2CR();
675 printk("CPU0: L2CR is %lx\n", core99_l2_cache);
676 } else {
677 printk("CPU%d: L2CR was %lx\n", cpu, _get_L2CR());
678 _set_L2CR(0);
679 _set_L2CR(core99_l2_cache);
680 printk("CPU%d: L2CR set to %lx\n", cpu, core99_l2_cache);
681 }
682
683 if (!cpu_has_feature(CPU_FTR_L3CR))
684 return;
685
686 if (cpu == 0){
687 core99_l3_cache = _get_L3CR();
688 printk("CPU0: L3CR is %lx\n", core99_l3_cache);
689 } else {
690 printk("CPU%d: L3CR was %lx\n", cpu, _get_L3CR());
691 _set_L3CR(0);
692 _set_L3CR(core99_l3_cache);
693 printk("CPU%d: L3CR set to %lx\n", cpu, core99_l3_cache);
694 }
695#endif
696}
697
698static void __init smp_core99_setup(int ncpus)
699{
700#ifdef CONFIG_PPC64
701
702
703 if (of_machine_is_compatible("PowerMac7,2") ||
704 of_machine_is_compatible("PowerMac7,3") ||
705 of_machine_is_compatible("RackMac3,1"))
706 smp_core99_setup_i2c_hwsync(ncpus);
707
708
709 if (pmac_tb_freeze == NULL) {
710 struct device_node *cpus =
711 of_find_node_by_path("/cpus");
712 if (cpus &&
713 of_get_property(cpus, "platform-cpu-timebase", NULL)) {
714 pmac_tb_freeze = smp_core99_pfunc_tb_freeze;
715 printk(KERN_INFO "Processor timebase sync using"
716 " platform function\n");
717 }
718 }
719
720#else
721
722
723 if (pmac_tb_freeze == NULL && !of_machine_is_compatible("MacRISC4")) {
724 struct device_node *cpu;
725 const u32 *tbprop = NULL;
726
727 core99_tb_gpio = KL_GPIO_TB_ENABLE;
728 cpu = of_find_node_by_type(NULL, "cpu");
729 if (cpu != NULL) {
730 tbprop = of_get_property(cpu, "timebase-enable", NULL);
731 if (tbprop)
732 core99_tb_gpio = *tbprop;
733 of_node_put(cpu);
734 }
735 pmac_tb_freeze = smp_core99_gpio_tb_freeze;
736 printk(KERN_INFO "Processor timebase sync using"
737 " GPIO 0x%02x\n", core99_tb_gpio);
738 }
739
740#endif
741
742
743 if (pmac_tb_freeze == NULL) {
744 smp_ops->give_timebase = smp_generic_give_timebase;
745 smp_ops->take_timebase = smp_generic_take_timebase;
746 printk(KERN_INFO "Processor timebase sync using software\n");
747 }
748
749#ifndef CONFIG_PPC64
750 {
751 int i;
752
753
754 for (i = 1; i < ncpus; ++i)
755 set_hard_smp_processor_id(i, i);
756 }
757#endif
758
759
760 if (!of_machine_is_compatible("MacRISC4"))
761 powersave_nap = 0;
762}
763
764static void __init smp_core99_probe(void)
765{
766 struct device_node *cpus;
767 int ncpus = 0;
768
769 if (ppc_md.progress) ppc_md.progress("smp_core99_probe", 0x345);
770
771
772 for_each_node_by_type(cpus, "cpu")
773 ++ncpus;
774
775 printk(KERN_INFO "PowerMac SMP probe found %d cpus\n", ncpus);
776
777
778 if (ncpus <= 1)
779 return;
780
781
782
783
784 pmac_pfunc_base_install();
785 pmac_i2c_init();
786
787
788 smp_core99_setup(ncpus);
789
790
791 mpic_request_ipis();
792
793
794 core99_init_caches(0);
795}
796
797static int smp_core99_kick_cpu(int nr)
798{
799 unsigned int save_vector;
800 unsigned long target, flags;
801 unsigned int *vector = (unsigned int *)(PAGE_OFFSET+0x100);
802
803 if (nr < 0 || nr > 3)
804 return -ENOENT;
805
806 if (ppc_md.progress)
807 ppc_md.progress("smp_core99_kick_cpu", 0x346);
808
809 local_irq_save(flags);
810
811
812 save_vector = *vector;
813
814
815
816
817 target = (unsigned long) __secondary_start_pmac_0 + nr * 8;
818 patch_branch(vector, target, BRANCH_SET_LINK);
819
820
821 pmac_call_feature(PMAC_FTR_RESET_CPU, NULL, nr, 0);
822
823
824
825
826
827
828 mdelay(1);
829
830
831 patch_instruction(vector, save_vector);
832
833 local_irq_restore(flags);
834 if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu done", 0x347);
835
836 return 0;
837}
838
839static void smp_core99_setup_cpu(int cpu_nr)
840{
841
842 if (cpu_nr != 0)
843 core99_init_caches(cpu_nr);
844
845
846 mpic_setup_this_cpu();
847}
848
849#ifdef CONFIG_PPC64
850#ifdef CONFIG_HOTPLUG_CPU
851static unsigned int smp_core99_host_open;
852
853static int smp_core99_cpu_prepare(unsigned int cpu)
854{
855 int rc;
856
857
858 if (pmac_tb_clock_chip_host && !smp_core99_host_open) {
859 rc = pmac_i2c_open(pmac_tb_clock_chip_host, 1);
860 if (rc) {
861 pr_err("Failed to open i2c bus for time sync\n");
862 return notifier_from_errno(rc);
863 }
864 smp_core99_host_open = 1;
865 }
866 return 0;
867}
868
869static int smp_core99_cpu_online(unsigned int cpu)
870{
871
872 if (pmac_tb_clock_chip_host && smp_core99_host_open) {
873 pmac_i2c_close(pmac_tb_clock_chip_host);
874 smp_core99_host_open = 0;
875 }
876 return 0;
877}
878#endif
879
880static void __init smp_core99_bringup_done(void)
881{
882 extern void g5_phy_disable_cpu1(void);
883
884
885 if (pmac_tb_clock_chip_host)
886 pmac_i2c_close(pmac_tb_clock_chip_host);
887
888
889
890
891 if (of_machine_is_compatible("MacRISC4") &&
892 num_online_cpus() < 2) {
893 set_cpu_present(1, false);
894 g5_phy_disable_cpu1();
895 }
896#ifdef CONFIG_HOTPLUG_CPU
897 cpuhp_setup_state_nocalls(CPUHP_POWERPC_PMAC_PREPARE,
898 "powerpc/pmac:prepare", smp_core99_cpu_prepare,
899 NULL);
900 cpuhp_setup_state_nocalls(CPUHP_AP_ONLINE_DYN, "powerpc/pmac:online",
901 smp_core99_cpu_online, NULL);
902#endif
903
904 if (ppc_md.progress)
905 ppc_md.progress("smp_core99_bringup_done", 0x349);
906}
907#endif
908
909#ifdef CONFIG_HOTPLUG_CPU
910
911static int smp_core99_cpu_disable(void)
912{
913 int rc = generic_cpu_disable();
914 if (rc)
915 return rc;
916
917 mpic_cpu_set_priority(0xf);
918
919 return 0;
920}
921
922#ifdef CONFIG_PPC32
923
924static void pmac_cpu_die(void)
925{
926 int cpu = smp_processor_id();
927
928 local_irq_disable();
929 idle_task_exit();
930 pr_debug("CPU%d offline\n", cpu);
931 generic_set_cpu_dead(cpu);
932 smp_wmb();
933 mb();
934 low_cpu_die();
935}
936
937#else
938
939static void pmac_cpu_die(void)
940{
941 int cpu = smp_processor_id();
942
943 local_irq_disable();
944 idle_task_exit();
945
946
947
948
949
950
951
952 printk(KERN_INFO "CPU#%d offline\n", cpu);
953 generic_set_cpu_dead(cpu);
954 smp_wmb();
955
956
957
958
959
960
961
962
963 local_irq_enable();
964
965 while (1) {
966
967 set_dec(0x7fffffff);
968
969
970 power4_idle();
971 }
972}
973
974#endif
975#endif
976
977
978static struct smp_ops_t core99_smp_ops = {
979 .message_pass = smp_mpic_message_pass,
980 .probe = smp_core99_probe,
981#ifdef CONFIG_PPC64
982 .bringup_done = smp_core99_bringup_done,
983#endif
984 .kick_cpu = smp_core99_kick_cpu,
985 .setup_cpu = smp_core99_setup_cpu,
986 .give_timebase = smp_core99_give_timebase,
987 .take_timebase = smp_core99_take_timebase,
988#if defined(CONFIG_HOTPLUG_CPU)
989 .cpu_disable = smp_core99_cpu_disable,
990 .cpu_die = generic_cpu_die,
991#endif
992};
993
994void __init pmac_setup_smp(void)
995{
996 struct device_node *np;
997
998
999 np = of_find_node_by_name(NULL, "uni-n");
1000 if (!np)
1001 np = of_find_node_by_name(NULL, "u3");
1002 if (!np)
1003 np = of_find_node_by_name(NULL, "u4");
1004 if (np) {
1005 of_node_put(np);
1006 smp_ops = &core99_smp_ops;
1007 }
1008#ifdef CONFIG_PPC_PMAC32_PSURGE
1009 else {
1010
1011
1012
1013
1014
1015 int cpu;
1016
1017 for (cpu = 1; cpu < 4 && cpu < NR_CPUS; ++cpu)
1018 set_cpu_possible(cpu, true);
1019 smp_ops = &psurge_smp_ops;
1020 }
1021#endif
1022
1023#ifdef CONFIG_HOTPLUG_CPU
1024 ppc_md.cpu_die = pmac_cpu_die;
1025#endif
1026}
1027
1028
1029