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/sections.h>
45 #include <asm/machdep.h>
46 #include <asm/pmac_feature.h>
48 #include <asm/cacheflush.h>
49 #include <asm/keylargo.h>
53 extern void pmac_secondary_start_1(void);
54 extern void pmac_secondary_start_2(void);
55 extern void pmac_secondary_start_3(void);
57 extern void smp_openpic_message_pass(int target, int msg);
59 extern struct smp_ops_t *smp_ops;
61 static int __init smp_core99_probe(void)
63 struct device_node *cpus;
66 /* Maybe use systemconfiguration here ? */
67 if (ppc_md.progress) ppc_md.progress("smp_core99_probe", 0x345);
68 cpus = find_type_devices("cpu");
72 while ((cpus = cpus->next) != NULL)
75 printk(KERN_INFO "PowerMac SMP probe found %d cpus\n", ncpus);
78 openpic_request_IPIs();
83 static void __init smp_core99_kick_cpu(int nr)
86 unsigned long new_vector;
88 volatile unsigned int *vector
89 = ((volatile unsigned int *)(KERNELBASE+0x100));
93 if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu", 0x346);
95 local_irq_save(flags);
98 /* Save reset vector */
99 save_vector = *vector;
101 /* Setup fake reset vector that does
102 * b .pmac_secondary_start - KERNELBASE
106 new_vector = (unsigned long)pmac_secondary_start_1;
109 new_vector = (unsigned long)pmac_secondary_start_2;
112 new_vector = (unsigned long)pmac_secondary_start_3;
115 *vector = 0x48000002 + (new_vector - KERNELBASE);
117 /* flush data cache and inval instruction cache */
118 flush_icache_range((unsigned long) vector, (unsigned long) vector + 4);
120 /* Put some life in our friend */
121 pmac_call_feature(PMAC_FTR_RESET_CPU, NULL, nr, 0);
122 paca[nr].cpu_start = 1;
124 /* FIXME: We wait a bit for the CPU to take the exception, I should
125 * instead wait for the entry code to set something for me. Well,
126 * ideally, all that crap will be done in prom.c and the CPU left
127 * in a RAM-based wait loop like CHRP.
131 /* Restore our exception vector */
132 *vector = save_vector;
133 flush_icache_range((unsigned long) vector, (unsigned long) vector + 4);
135 local_irq_restore(flags);
136 if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu done", 0x347);
139 static void __init smp_core99_setup_cpu(int cpu_nr)
142 do_openpic_setup_cpu();
145 extern void g5_phy_disable_cpu1(void);
147 /* If we didn't start the second CPU, we must take
150 if (num_online_cpus() < 2)
151 g5_phy_disable_cpu1();
152 if (ppc_md.progress) ppc_md.progress("core99_setup_cpu 0 done", 0x349);
156 extern void smp_generic_give_timebase(void);
157 extern void smp_generic_take_timebase(void);
159 struct smp_ops_t core99_smp_ops __pmacdata = {
160 .message_pass = smp_openpic_message_pass,
161 .probe = smp_core99_probe,
162 .kick_cpu = smp_core99_kick_cpu,
163 .setup_cpu = smp_core99_setup_cpu,
164 .give_timebase = smp_generic_give_timebase,
165 .take_timebase = smp_generic_take_timebase,
168 void __init pmac_setup_smp(void)
170 smp_ops = &core99_smp_ops;