vserver 1.9.3
[linux-2.6.git] / arch / ppc64 / kernel / pmac_smp.c
1 /*
2  * SMP support for power macintosh.
3  *
4  * We support both the old "powersurge" SMP architecture
5  * and the current Core99 (G4 PowerMac) machines.
6  *
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.
12  *
13  * Support Macintosh G4 SMP by Troy Benjegerdes (hozer@drgw.net)
14  * and Ben Herrenschmidt <benh@kernel.crashing.org>.
15  *
16  * Support for DayStar quad CPU cards
17  * Copyright (C) XLR8, Inc. 1994-2000
18  *
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.
23  */
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>
35
36 #include <asm/ptrace.h>
37 #include <asm/atomic.h>
38 #include <asm/irq.h>
39 #include <asm/page.h>
40 #include <asm/pgtable.h>
41 #include <asm/sections.h>
42 #include <asm/io.h>
43 #include <asm/prom.h>
44 #include <asm/smp.h>
45 #include <asm/machdep.h>
46 #include <asm/pmac_feature.h>
47 #include <asm/time.h>
48 #include <asm/cacheflush.h>
49 #include <asm/keylargo.h>
50
51 #include "open_pic.h"
52
53 extern void pmac_secondary_start_1(void);
54 extern void pmac_secondary_start_2(void);
55 extern void pmac_secondary_start_3(void);
56
57 extern void smp_openpic_message_pass(int target, int msg);
58
59 extern struct smp_ops_t *smp_ops;
60
61 static int __init smp_core99_probe(void)
62 {
63         struct device_node *cpus;
64         int ncpus = 1;
65
66         /* Maybe use systemconfiguration here ? */
67         if (ppc_md.progress) ppc_md.progress("smp_core99_probe", 0x345);
68         cpus = find_type_devices("cpu");
69         if (cpus == NULL)
70                 return 0;
71
72         while ((cpus = cpus->next) != NULL)
73                 ++ncpus;
74
75         printk(KERN_INFO "PowerMac SMP probe found %d cpus\n", ncpus);
76
77         if (ncpus > 1)
78                 openpic_request_IPIs();
79
80         return ncpus;
81 }
82
83 static void __init smp_core99_kick_cpu(int nr)
84 {
85         int save_vector;
86         unsigned long new_vector;
87         unsigned long flags;
88         volatile unsigned int *vector
89                  = ((volatile unsigned int *)(KERNELBASE+0x100));
90
91         if (nr < 1 || nr > 3)
92                 return;
93         if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu", 0x346);
94
95         local_irq_save(flags);
96         local_irq_disable();
97
98         /* Save reset vector */
99         save_vector = *vector;
100
101         /* Setup fake reset vector that does    
102          *   b .pmac_secondary_start - KERNELBASE
103          */
104         switch(nr) {
105                 case 1:
106                         new_vector = (unsigned long)pmac_secondary_start_1;
107                         break;
108                 case 2:
109                         new_vector = (unsigned long)pmac_secondary_start_2;
110                         break;
111                 case 3:
112                         new_vector = (unsigned long)pmac_secondary_start_3;
113                         break;
114         }
115         *vector = 0x48000002 + (new_vector - KERNELBASE);
116
117         /* flush data cache and inval instruction cache */
118         flush_icache_range((unsigned long) vector, (unsigned long) vector + 4);
119
120         /* Put some life in our friend */
121         pmac_call_feature(PMAC_FTR_RESET_CPU, NULL, nr, 0);
122         paca[nr].cpu_start = 1;
123
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.
128          */
129         mdelay(1);
130
131         /* Restore our exception vector */
132         *vector = save_vector;
133         flush_icache_range((unsigned long) vector, (unsigned long) vector + 4);
134
135         local_irq_restore(flags);
136         if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu done", 0x347);
137 }
138
139 static void __init smp_core99_setup_cpu(int cpu_nr)
140 {
141         /* Setup openpic */
142         do_openpic_setup_cpu();
143
144         if (cpu_nr == 0) {
145                 extern void g5_phy_disable_cpu1(void);
146
147                 /* If we didn't start the second CPU, we must take
148                  * it off the bus
149                  */
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);
153         }
154 }
155
156 extern void smp_generic_give_timebase(void);
157 extern void smp_generic_take_timebase(void);
158
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,
166 };
167
168 void __init pmac_setup_smp(void)
169 {
170         smp_ops = &core99_smp_ops;
171 }