2 * SMP support for power macintosh.
4 * We support both the old "powersurge" SMP architecture
5 * and the current Core99 (G4 PowerMac) machines.
7 * Note that we don't support the very first rev. of
8 * Apple/DayStar 2 CPUs board, the one with the funky
9 * watchdog. Hopefully, none of these should be there except
10 * maybe internally to Apple. I should probably still add some
11 * code to detect this card though and disable SMP. --BenH.
13 * Support Macintosh G4 SMP by Troy Benjegerdes (hozer@drgw.net)
14 * and Ben Herrenschmidt <benh@kernel.crashing.org>.
16 * Support for DayStar quad CPU cards
17 * Copyright (C) XLR8, Inc. 1994-2000
19 * This program is free software; you can redistribute it and/or
20 * modify it under the terms of the GNU General Public License
21 * as published by the Free Software Foundation; either version
22 * 2 of the License, or (at your option) any later version.
24 #include <linux/config.h>
25 #include <linux/kernel.h>
26 #include <linux/sched.h>
27 #include <linux/smp.h>
28 #include <linux/smp_lock.h>
29 #include <linux/interrupt.h>
30 #include <linux/kernel_stat.h>
31 #include <linux/delay.h>
32 #include <linux/init.h>
33 #include <linux/spinlock.h>
34 #include <linux/errno.h>
36 #include <asm/ptrace.h>
37 #include <asm/atomic.h>
40 #include <asm/pgtable.h>
41 #include <asm/hardirq.h>
42 #include <asm/sections.h>
46 #include <asm/machdep.h>
47 #include <asm/pmac_feature.h>
49 #include <asm/cacheflush.h>
50 #include <asm/keylargo.h>
54 extern void pmac_secondary_start_1(void);
55 extern void pmac_secondary_start_2(void);
56 extern void pmac_secondary_start_3(void);
58 extern void smp_openpic_message_pass(int target, int msg);
60 extern struct smp_ops_t *smp_ops;
62 static int __init smp_core99_probe(void)
64 struct device_node *cpus;
67 /* Maybe use systemconfiguration here ? */
68 if (ppc_md.progress) ppc_md.progress("smp_core99_probe", 0x345);
69 cpus = find_type_devices("cpu");
73 while ((cpus = cpus->next) != NULL)
76 printk(KERN_INFO "PowerMac SMP probe found %d cpus\n", ncpus);
79 openpic_request_IPIs();
84 static void __init smp_core99_kick_cpu(int nr)
87 unsigned long new_vector;
89 volatile unsigned int *vector
90 = ((volatile unsigned int *)(KERNELBASE+0x100));
94 if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu", 0x346);
96 local_irq_save(flags);
99 /* Save reset vector */
100 save_vector = *vector;
102 /* Setup fake reset vector that does
103 * b .pmac_secondary_start - KERNELBASE
107 new_vector = (unsigned long)pmac_secondary_start_1;
110 new_vector = (unsigned long)pmac_secondary_start_2;
113 new_vector = (unsigned long)pmac_secondary_start_3;
116 *vector = 0x48000002 + (new_vector - KERNELBASE);
118 /* flush data cache and inval instruction cache */
119 flush_icache_range((unsigned long) vector, (unsigned long) vector + 4);
121 /* Put some life in our friend */
122 pmac_call_feature(PMAC_FTR_RESET_CPU, NULL, nr, 0);
123 paca[nr].xProcStart = 1;
125 /* FIXME: We wait a bit for the CPU to take the exception, I should
126 * instead wait for the entry code to set something for me. Well,
127 * ideally, all that crap will be done in prom.c and the CPU left
128 * in a RAM-based wait loop like CHRP.
132 /* Restore our exception vector */
133 *vector = save_vector;
134 flush_icache_range((unsigned long) vector, (unsigned long) vector + 4);
136 local_irq_restore(flags);
137 if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu done", 0x347);
140 static void __init smp_core99_setup_cpu(int cpu_nr)
143 do_openpic_setup_cpu();
146 extern void g5_phy_disable_cpu1(void);
148 /* If we didn't start the second CPU, we must take
151 if (num_online_cpus() < 2)
152 g5_phy_disable_cpu1();
153 if (ppc_md.progress) ppc_md.progress("core99_setup_cpu 0 done", 0x349);
157 extern void smp_generic_give_timebase(void);
158 extern void smp_generic_take_timebase(void);
160 struct smp_ops_t core99_smp_ops __pmacdata = {
161 .message_pass = smp_openpic_message_pass,
162 .probe = smp_core99_probe,
163 .kick_cpu = smp_core99_kick_cpu,
164 .setup_cpu = smp_core99_setup_cpu,
165 .give_timebase = smp_generic_give_timebase,
166 .take_timebase = smp_generic_take_timebase,
169 void __init pmac_setup_smp(void)
171 smp_ops = &core99_smp_ops;