ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[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/hardirq.h>
42 #include <asm/sections.h>
43 #include <asm/io.h>
44 #include <asm/prom.h>
45 #include <asm/smp.h>
46 #include <asm/machdep.h>
47 #include <asm/pmac_feature.h>
48 #include <asm/time.h>
49 #include <asm/cacheflush.h>
50 #include <asm/keylargo.h>
51
52 #include "open_pic.h"
53
54 extern void pmac_secondary_start_1(void);
55 extern void pmac_secondary_start_2(void);
56 extern void pmac_secondary_start_3(void);
57
58 extern void smp_openpic_message_pass(int target, int msg);
59
60 extern struct smp_ops_t *smp_ops;
61
62 static int __init smp_core99_probe(void)
63 {
64         struct device_node *cpus;
65         int ncpus = 1;
66
67         /* Maybe use systemconfiguration here ? */
68         if (ppc_md.progress) ppc_md.progress("smp_core99_probe", 0x345);
69         cpus = find_type_devices("cpu");
70         if (cpus == NULL)
71                 return 0;
72
73         while ((cpus = cpus->next) != NULL)
74                 ++ncpus;
75
76         printk(KERN_INFO "PowerMac SMP probe found %d cpus\n", ncpus);
77
78         if (ncpus > 1)
79                 openpic_request_IPIs();
80
81         return ncpus;
82 }
83
84 static void __init smp_core99_kick_cpu(int nr)
85 {
86         int save_vector;
87         unsigned long new_vector;
88         unsigned long flags;
89         volatile unsigned int *vector
90                  = ((volatile unsigned int *)(KERNELBASE+0x100));
91
92         if (nr < 1 || nr > 3)
93                 return;
94         if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu", 0x346);
95
96         local_irq_save(flags);
97         local_irq_disable();
98
99         /* Save reset vector */
100         save_vector = *vector;
101
102         /* Setup fake reset vector that does    
103          *   b .pmac_secondary_start - KERNELBASE
104          */
105         switch(nr) {
106                 case 1:
107                         new_vector = (unsigned long)pmac_secondary_start_1;
108                         break;
109                 case 2:
110                         new_vector = (unsigned long)pmac_secondary_start_2;
111                         break;
112                 case 3:
113                         new_vector = (unsigned long)pmac_secondary_start_3;
114                         break;
115         }
116         *vector = 0x48000002 + (new_vector - KERNELBASE);
117
118         /* flush data cache and inval instruction cache */
119         flush_icache_range((unsigned long) vector, (unsigned long) vector + 4);
120
121         /* Put some life in our friend */
122         pmac_call_feature(PMAC_FTR_RESET_CPU, NULL, nr, 0);
123         paca[nr].xProcStart = 1;
124
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.
129          */
130         mdelay(1);
131
132         /* Restore our exception vector */
133         *vector = save_vector;
134         flush_icache_range((unsigned long) vector, (unsigned long) vector + 4);
135
136         local_irq_restore(flags);
137         if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu done", 0x347);
138 }
139
140 static void __init smp_core99_setup_cpu(int cpu_nr)
141 {
142         /* Setup openpic */
143         do_openpic_setup_cpu();
144
145         if (cpu_nr == 0) {
146                 extern void g5_phy_disable_cpu1(void);
147
148                 /* If we didn't start the second CPU, we must take
149                  * it off the bus
150                  */
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);
154         }
155 }
156
157 extern void smp_generic_give_timebase(void);
158 extern void smp_generic_take_timebase(void);
159
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,
167 };
168
169 void __init pmac_setup_smp(void)
170 {
171         smp_ops = &core99_smp_ops;
172 }