blob: c49e71926a5497145f640ef553daa37684c15b1a [file] [log] [blame]
Paul Mackerras14cf11a2005-09-26 16:04:21 +10001/*
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 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +100024#include <linux/kernel.h>
25#include <linux/sched.h>
26#include <linux/smp.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100027#include <linux/interrupt.h>
28#include <linux/kernel_stat.h>
29#include <linux/delay.h>
30#include <linux/init.h>
31#include <linux/spinlock.h>
32#include <linux/errno.h>
33#include <linux/hardirq.h>
34#include <linux/cpu.h>
Paul Mackerras54c4e6b2005-11-19 21:24:55 +110035#include <linux/compiler.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100036
37#include <asm/ptrace.h>
38#include <asm/atomic.h>
Michael Ellermanaaddd3e2008-06-24 11:32:21 +100039#include <asm/code-patching.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100040#include <asm/irq.h>
41#include <asm/page.h>
42#include <asm/pgtable.h>
43#include <asm/sections.h>
44#include <asm/io.h>
45#include <asm/prom.h>
46#include <asm/smp.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100047#include <asm/machdep.h>
48#include <asm/pmac_feature.h>
49#include <asm/time.h>
Paul Mackerrasc0c0d992005-10-01 13:49:08 +100050#include <asm/mpic.h>
Paul Mackerras14cf11a2005-09-26 16:04:21 +100051#include <asm/cacheflush.h>
52#include <asm/keylargo.h>
Paul Mackerras35499c02005-10-22 16:02:39 +100053#include <asm/pmac_low_i2c.h>
Benjamin Herrenschmidt5b9ca522006-01-07 11:41:02 +110054#include <asm/pmac_pfunc.h>
Paul Mackerras35499c02005-10-22 16:02:39 +100055
Milton Millerabb17f92010-05-19 02:56:29 +000056#include "pmac.h"
57
Benjamin Herrenschmidtc478b582009-01-11 19:03:45 +000058#undef DEBUG
Paul Mackerras35499c02005-10-22 16:02:39 +100059
60#ifdef DEBUG
61#define DBG(fmt...) udbg_printf(fmt)
62#else
63#define DBG(fmt...)
64#endif
65
66extern void __secondary_start_pmac_0(void);
Benjamin Herrenschmidt5b9ca522006-01-07 11:41:02 +110067extern int pmac_pfunc_base_install(void);
Paul Mackerras35499c02005-10-22 16:02:39 +100068
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +000069static void (*pmac_tb_freeze)(int freeze);
70static u64 timebase;
71static int tb_req;
Paul Mackerras35499c02005-10-22 16:02:39 +100072
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +000073#ifdef CONFIG_PPC32
Paul Mackerras14cf11a2005-09-26 16:04:21 +100074
75/*
76 * Powersurge (old powermac SMP) support.
77 */
78
Paul Mackerras14cf11a2005-09-26 16:04:21 +100079/* Addresses for powersurge registers */
80#define HAMMERHEAD_BASE 0xf8000000
81#define HHEAD_CONFIG 0x90
82#define HHEAD_SEC_INTR 0xc0
83
84/* register for interrupting the primary processor on the powersurge */
85/* N.B. this is actually the ethernet ROM! */
86#define PSURGE_PRI_INTR 0xf3019000
87
88/* register for storing the start address for the secondary processor */
89/* N.B. this is the PCI config space address register for the 1st bridge */
90#define PSURGE_START 0xf2800000
91
92/* Daystar/XLR8 4-CPU card */
93#define PSURGE_QUAD_REG_ADDR 0xf8800000
94
95#define PSURGE_QUAD_IRQ_SET 0
96#define PSURGE_QUAD_IRQ_CLR 1
97#define PSURGE_QUAD_IRQ_PRIMARY 2
98#define PSURGE_QUAD_CKSTOP_CTL 3
99#define PSURGE_QUAD_PRIMARY_ARB 4
100#define PSURGE_QUAD_BOARD_ID 6
101#define PSURGE_QUAD_WHICH_CPU 7
102#define PSURGE_QUAD_CKSTOP_RDBK 8
103#define PSURGE_QUAD_RESET_CTL 11
104
105#define PSURGE_QUAD_OUT(r, v) (out_8(quad_base + ((r) << 4) + 4, (v)))
106#define PSURGE_QUAD_IN(r) (in_8(quad_base + ((r) << 4) + 4) & 0x0f)
107#define PSURGE_QUAD_BIS(r, v) (PSURGE_QUAD_OUT((r), PSURGE_QUAD_IN(r) | (v)))
108#define PSURGE_QUAD_BIC(r, v) (PSURGE_QUAD_OUT((r), PSURGE_QUAD_IN(r) & ~(v)))
109
110/* virtual addresses for the above */
111static volatile u8 __iomem *hhead_base;
112static volatile u8 __iomem *quad_base;
113static volatile u32 __iomem *psurge_pri_intr;
114static volatile u8 __iomem *psurge_sec_intr;
115static volatile u32 __iomem *psurge_start;
116
117/* values for psurge_type */
118#define PSURGE_NONE -1
119#define PSURGE_DUAL 0
120#define PSURGE_QUAD_OKEE 1
121#define PSURGE_QUAD_COTTON 2
122#define PSURGE_QUAD_ICEGRASS 3
123
124/* what sort of powersurge board we have */
125static int psurge_type = PSURGE_NONE;
126
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000127/*
128 * Set and clear IPIs for powersurge.
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 * On powersurge (old SMP powermac architecture) we don't have
158 * separate IPIs for separate messages like openpic does. Instead
159 * we have a bitmap for each processor, where a 1 bit means that
160 * the corresponding message is pending for that processor.
161 * Ideally each cpu's entry would be in a different cache line.
162 * -- paulus.
163 */
164static unsigned long psurge_smp_message[NR_CPUS];
165
Olaf Hering35a84c22006-10-07 22:08:26 +1000166void psurge_smp_message_recv(void)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000167{
168 int cpu = smp_processor_id();
169 int msg;
170
171 /* clear interrupt */
172 psurge_clr_ipi(cpu);
173
174 if (num_online_cpus() < 2)
175 return;
176
177 /* make sure there is a message there */
178 for (msg = 0; msg < 4; msg++)
179 if (test_and_clear_bit(msg, &psurge_smp_message[cpu]))
Olaf Hering35a84c22006-10-07 22:08:26 +1000180 smp_message_recv(msg);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000181}
182
Olaf Hering35a84c22006-10-07 22:08:26 +1000183irqreturn_t psurge_primary_intr(int irq, void *d)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000184{
Olaf Hering35a84c22006-10-07 22:08:26 +1000185 psurge_smp_message_recv();
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000186 return IRQ_HANDLED;
187}
188
Milton Millerf1072932011-05-10 19:29:10 +0000189static void smp_psurge_message_pass(int cpu, int msg)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000190{
Milton Millerf1072932011-05-10 19:29:10 +0000191 set_bit(msg, &psurge_smp_message[cpu]);
192 psurge_set_ipi(cpu);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000193}
194
195/*
196 * Determine a quad card presence. We read the board ID register, we
197 * force the data bus to change to something else, and we read it again.
198 * It it's stable, then the register probably exist (ugh !)
199 */
200static int __init psurge_quad_probe(void)
201{
202 int type;
203 unsigned int i;
204
205 type = PSURGE_QUAD_IN(PSURGE_QUAD_BOARD_ID);
206 if (type < PSURGE_QUAD_OKEE || type > PSURGE_QUAD_ICEGRASS
207 || type != PSURGE_QUAD_IN(PSURGE_QUAD_BOARD_ID))
208 return PSURGE_DUAL;
209
210 /* looks OK, try a slightly more rigorous test */
211 /* bogus is not necessarily cacheline-aligned,
212 though I don't suppose that really matters. -- paulus */
213 for (i = 0; i < 100; i++) {
214 volatile u32 bogus[8];
215 bogus[(0+i)%8] = 0x00000000;
216 bogus[(1+i)%8] = 0x55555555;
217 bogus[(2+i)%8] = 0xFFFFFFFF;
218 bogus[(3+i)%8] = 0xAAAAAAAA;
219 bogus[(4+i)%8] = 0x33333333;
220 bogus[(5+i)%8] = 0xCCCCCCCC;
221 bogus[(6+i)%8] = 0xCCCCCCCC;
222 bogus[(7+i)%8] = 0x33333333;
223 wmb();
224 asm volatile("dcbf 0,%0" : : "r" (bogus) : "memory");
225 mb();
226 if (type != PSURGE_QUAD_IN(PSURGE_QUAD_BOARD_ID))
227 return PSURGE_DUAL;
228 }
229 return type;
230}
231
232static void __init psurge_quad_init(void)
233{
234 int procbits;
235
236 if (ppc_md.progress) ppc_md.progress("psurge_quad_init", 0x351);
237 procbits = ~PSURGE_QUAD_IN(PSURGE_QUAD_WHICH_CPU);
238 if (psurge_type == PSURGE_QUAD_ICEGRASS)
239 PSURGE_QUAD_BIS(PSURGE_QUAD_RESET_CTL, procbits);
240 else
241 PSURGE_QUAD_BIC(PSURGE_QUAD_CKSTOP_CTL, procbits);
242 mdelay(33);
243 out_8(psurge_sec_intr, ~0);
244 PSURGE_QUAD_OUT(PSURGE_QUAD_IRQ_CLR, procbits);
245 PSURGE_QUAD_BIS(PSURGE_QUAD_RESET_CTL, procbits);
246 if (psurge_type != PSURGE_QUAD_ICEGRASS)
247 PSURGE_QUAD_BIS(PSURGE_QUAD_CKSTOP_CTL, procbits);
248 PSURGE_QUAD_BIC(PSURGE_QUAD_PRIMARY_ARB, procbits);
249 mdelay(33);
250 PSURGE_QUAD_BIC(PSURGE_QUAD_RESET_CTL, procbits);
251 mdelay(33);
252 PSURGE_QUAD_BIS(PSURGE_QUAD_PRIMARY_ARB, procbits);
253 mdelay(33);
254}
255
256static int __init smp_psurge_probe(void)
257{
258 int i, ncpus;
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000259 struct device_node *dn;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000260
261 /* We don't do SMP on the PPC601 -- paulus */
262 if (PVR_VER(mfspr(SPRN_PVR)) == 1)
263 return 1;
264
265 /*
266 * The powersurge cpu board can be used in the generation
267 * of powermacs that have a socket for an upgradeable cpu card,
268 * including the 7500, 8500, 9500, 9600.
269 * The device tree doesn't tell you if you have 2 cpus because
270 * OF doesn't know anything about the 2nd processor.
271 * Instead we look for magic bits in magic registers,
272 * in the hammerhead memory controller in the case of the
273 * dual-cpu powersurge board. -- paulus.
274 */
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000275 dn = of_find_node_by_name(NULL, "hammerhead");
276 if (dn == NULL)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000277 return 1;
Stephen Rothwell30686ba2007-04-24 13:53:04 +1000278 of_node_put(dn);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000279
280 hhead_base = ioremap(HAMMERHEAD_BASE, 0x800);
281 quad_base = ioremap(PSURGE_QUAD_REG_ADDR, 1024);
282 psurge_sec_intr = hhead_base + HHEAD_SEC_INTR;
283
284 psurge_type = psurge_quad_probe();
285 if (psurge_type != PSURGE_DUAL) {
286 psurge_quad_init();
287 /* All released cards using this HW design have 4 CPUs */
288 ncpus = 4;
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000289 /* No sure how timebase sync works on those, let's use SW */
290 smp_ops->give_timebase = smp_generic_give_timebase;
291 smp_ops->take_timebase = smp_generic_take_timebase;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000292 } else {
293 iounmap(quad_base);
294 if ((in_8(hhead_base + HHEAD_CONFIG) & 0x02) == 0) {
295 /* not a dual-cpu card */
296 iounmap(hhead_base);
297 psurge_type = PSURGE_NONE;
298 return 1;
299 }
300 ncpus = 2;
301 }
302
303 psurge_start = ioremap(PSURGE_START, 4);
304 psurge_pri_intr = ioremap(PSURGE_PRI_INTR, 4);
305
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000306 /* This is necessary because OF doesn't know about the
Paul Mackerras094fe2e2005-11-10 14:26:12 +1100307 * secondary cpu(s), and thus there aren't nodes in the
308 * device tree for them, and smp_setup_cpu_maps hasn't
Anton Blanchard828a6982010-04-26 15:32:44 +0000309 * set their bits in cpu_present_mask.
Paul Mackerras094fe2e2005-11-10 14:26:12 +1100310 */
311 if (ncpus > NR_CPUS)
312 ncpus = NR_CPUS;
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000313 for (i = 1; i < ncpus ; ++i)
Rusty Russellea0f1ca2009-09-24 09:34:48 -0600314 set_cpu_present(i, true);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000315
316 if (ppc_md.progress) ppc_md.progress("smp_psurge_probe - done", 0x352);
317
318 return ncpus;
319}
320
Michael Ellermande300972011-04-11 21:46:19 +0000321static int __init smp_psurge_kick_cpu(int nr)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000322{
323 unsigned long start = __pa(__secondary_start_pmac_0) + nr * 8;
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000324 unsigned long a, flags;
325 int i, j;
326
327 /* Defining this here is evil ... but I prefer hiding that
328 * crap to avoid giving people ideas that they can do the
329 * same.
330 */
331 extern volatile unsigned int cpu_callin_map[NR_CPUS];
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000332
333 /* may need to flush here if secondary bats aren't setup */
334 for (a = KERNELBASE; a < KERNELBASE + 0x800000; a += 32)
335 asm volatile("dcbf 0,%0" : : "r" (a) : "memory");
336 asm volatile("sync");
337
338 if (ppc_md.progress) ppc_md.progress("smp_psurge_kick_cpu", 0x353);
339
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000340 /* This is going to freeze the timeebase, we disable interrupts */
341 local_irq_save(flags);
342
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000343 out_be32(psurge_start, start);
344 mb();
345
346 psurge_set_ipi(nr);
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000347
Paul Mackerrasd6a29252006-10-10 13:51:00 +1000348 /*
349 * We can't use udelay here because the timebase is now frozen.
350 */
351 for (i = 0; i < 2000; ++i)
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000352 asm volatile("nop" : : : "memory");
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000353 psurge_clr_ipi(nr);
354
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000355 /*
356 * Also, because the timebase is frozen, we must not return to the
357 * caller which will try to do udelay's etc... Instead, we wait -here-
358 * for the CPU to callin.
359 */
360 for (i = 0; i < 100000 && !cpu_callin_map[nr]; ++i) {
361 for (j = 1; j < 10000; j++)
362 asm volatile("nop" : : : "memory");
363 asm volatile("sync" : : : "memory");
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000364 }
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000365 if (!cpu_callin_map[nr])
366 goto stuck;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000367
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000368 /* And we do the TB sync here too for standard dual CPU cards */
369 if (psurge_type == PSURGE_DUAL) {
370 while(!tb_req)
371 barrier();
372 tb_req = 0;
373 mb();
374 timebase = get_tb();
375 mb();
376 while (timebase)
377 barrier();
378 mb();
379 }
380 stuck:
381 /* now interrupt the secondary, restarting both TBs */
382 if (psurge_type == PSURGE_DUAL)
383 psurge_set_ipi(1);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000384
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000385 if (ppc_md.progress) ppc_md.progress("smp_psurge_kick_cpu - done", 0x354);
Michael Ellermande300972011-04-11 21:46:19 +0000386
387 return 0;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000388}
389
390static struct irqaction psurge_irqaction = {
391 .handler = psurge_primary_intr,
Thomas Gleixner67144652006-07-01 19:29:22 -0700392 .flags = IRQF_DISABLED,
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000393 .name = "primary IPI",
394};
395
396static void __init smp_psurge_setup_cpu(int cpu_nr)
397{
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000398 if (cpu_nr != 0)
399 return;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000400
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000401 /* reset the entry point so if we get another intr we won't
402 * try to startup again */
403 out_be32(psurge_start, 0x100);
Benjamin Herrenschmidt527b3632009-07-14 20:56:58 +0000404 if (setup_irq(irq_create_mapping(NULL, 30), &psurge_irqaction))
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000405 printk(KERN_ERR "Couldn't get primary IPI interrupt");
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000406}
407
408void __init smp_psurge_take_timebase(void)
409{
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000410 if (psurge_type != PSURGE_DUAL)
411 return;
412
413 tb_req = 1;
414 mb();
415 while (!timebase)
416 barrier();
417 mb();
418 set_tb(timebase >> 32, timebase & 0xffffffff);
419 timebase = 0;
420 mb();
421 set_dec(tb_ticks_per_jiffy/2);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000422}
423
424void __init smp_psurge_give_timebase(void)
425{
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000426 /* Nothing to do here */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000427}
428
Paul Mackerras35499c02005-10-22 16:02:39 +1000429/* PowerSurge-style Macs */
430struct smp_ops_t psurge_smp_ops = {
431 .message_pass = smp_psurge_message_pass,
432 .probe = smp_psurge_probe,
433 .kick_cpu = smp_psurge_kick_cpu,
434 .setup_cpu = smp_psurge_setup_cpu,
435 .give_timebase = smp_psurge_give_timebase,
436 .take_timebase = smp_psurge_take_timebase,
437};
438#endif /* CONFIG_PPC32 - actually powersurge support */
439
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100440/*
441 * Core 99 and later support
442 */
443
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100444
445static void smp_core99_give_timebase(void)
446{
447 unsigned long flags;
448
449 local_irq_save(flags);
450
451 while(!tb_req)
452 barrier();
453 tb_req = 0;
454 (*pmac_tb_freeze)(1);
455 mb();
456 timebase = get_tb();
457 mb();
458 while (timebase)
459 barrier();
460 mb();
461 (*pmac_tb_freeze)(0);
462 mb();
463
464 local_irq_restore(flags);
465}
466
467
468static void __devinit smp_core99_take_timebase(void)
469{
470 unsigned long flags;
471
472 local_irq_save(flags);
473
474 tb_req = 1;
475 mb();
476 while (!timebase)
477 barrier();
478 mb();
479 set_tb(timebase >> 32, timebase & 0xffffffff);
480 timebase = 0;
481 mb();
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100482
483 local_irq_restore(flags);
484}
485
Paul Mackerras35499c02005-10-22 16:02:39 +1000486#ifdef CONFIG_PPC64
487/*
488 * G5s enable/disable the timebase via an i2c-connected clock chip.
489 */
Benjamin Herrenschmidt730745a2006-01-07 11:30:44 +1100490static struct pmac_i2c_bus *pmac_tb_clock_chip_host;
Paul Mackerras35499c02005-10-22 16:02:39 +1000491static u8 pmac_tb_pulsar_addr;
Paul Mackerras35499c02005-10-22 16:02:39 +1000492
493static void smp_core99_cypress_tb_freeze(int freeze)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000494{
Paul Mackerras35499c02005-10-22 16:02:39 +1000495 u8 data;
496 int rc;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000497
Paul Mackerras35499c02005-10-22 16:02:39 +1000498 /* Strangely, the device-tree says address is 0xd2, but darwin
499 * accesses 0xd0 ...
500 */
Benjamin Herrenschmidt730745a2006-01-07 11:30:44 +1100501 pmac_i2c_setmode(pmac_tb_clock_chip_host,
502 pmac_i2c_mode_combined);
503 rc = pmac_i2c_xfer(pmac_tb_clock_chip_host,
504 0xd0 | pmac_i2c_read,
505 1, 0x81, &data, 1);
Paul Mackerras35499c02005-10-22 16:02:39 +1000506 if (rc != 0)
507 goto bail;
508
509 data = (data & 0xf3) | (freeze ? 0x00 : 0x0c);
510
Benjamin Herrenschmidt730745a2006-01-07 11:30:44 +1100511 pmac_i2c_setmode(pmac_tb_clock_chip_host, pmac_i2c_mode_stdsub);
512 rc = pmac_i2c_xfer(pmac_tb_clock_chip_host,
513 0xd0 | pmac_i2c_write,
514 1, 0x81, &data, 1);
Paul Mackerras35499c02005-10-22 16:02:39 +1000515
516 bail:
517 if (rc != 0) {
518 printk("Cypress Timebase %s rc: %d\n",
519 freeze ? "freeze" : "unfreeze", rc);
520 panic("Timebase freeze failed !\n");
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000521 }
Paul Mackerras35499c02005-10-22 16:02:39 +1000522}
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000523
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000524
Paul Mackerras35499c02005-10-22 16:02:39 +1000525static void smp_core99_pulsar_tb_freeze(int freeze)
526{
527 u8 data;
528 int rc;
529
Benjamin Herrenschmidt730745a2006-01-07 11:30:44 +1100530 pmac_i2c_setmode(pmac_tb_clock_chip_host,
531 pmac_i2c_mode_combined);
532 rc = pmac_i2c_xfer(pmac_tb_clock_chip_host,
533 pmac_tb_pulsar_addr | pmac_i2c_read,
534 1, 0x2e, &data, 1);
Paul Mackerras35499c02005-10-22 16:02:39 +1000535 if (rc != 0)
536 goto bail;
537
538 data = (data & 0x88) | (freeze ? 0x11 : 0x22);
539
Benjamin Herrenschmidt730745a2006-01-07 11:30:44 +1100540 pmac_i2c_setmode(pmac_tb_clock_chip_host, pmac_i2c_mode_stdsub);
541 rc = pmac_i2c_xfer(pmac_tb_clock_chip_host,
542 pmac_tb_pulsar_addr | pmac_i2c_write,
543 1, 0x2e, &data, 1);
Paul Mackerras35499c02005-10-22 16:02:39 +1000544 bail:
545 if (rc != 0) {
546 printk(KERN_ERR "Pulsar Timebase %s rc: %d\n",
547 freeze ? "freeze" : "unfreeze", rc);
548 panic("Timebase freeze failed !\n");
549 }
550}
551
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100552static void __init smp_core99_setup_i2c_hwsync(int ncpus)
Paul Mackerras35499c02005-10-22 16:02:39 +1000553{
554 struct device_node *cc = NULL;
555 struct device_node *p;
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100556 const char *name = NULL;
Jeremy Kerr018a3d12006-07-12 15:40:29 +1000557 const u32 *reg;
Paul Mackerras35499c02005-10-22 16:02:39 +1000558 int ok;
559
Paul Mackerras35499c02005-10-22 16:02:39 +1000560 /* Look for the clock chip */
561 while ((cc = of_find_node_by_name(cc, "i2c-hwclock")) != NULL) {
562 p = of_get_parent(cc);
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000563 ok = p && of_device_is_compatible(p, "uni-n-i2c");
Paul Mackerras35499c02005-10-22 16:02:39 +1000564 of_node_put(p);
565 if (!ok)
566 continue;
567
Benjamin Herrenschmidt730745a2006-01-07 11:30:44 +1100568 pmac_tb_clock_chip_host = pmac_i2c_find_bus(cc);
569 if (pmac_tb_clock_chip_host == NULL)
570 continue;
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000571 reg = of_get_property(cc, "reg", NULL);
Paul Mackerras35499c02005-10-22 16:02:39 +1000572 if (reg == NULL)
573 continue;
Paul Mackerras35499c02005-10-22 16:02:39 +1000574 switch (*reg) {
575 case 0xd2:
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000576 if (of_device_is_compatible(cc,"pulsar-legacy-slewing")) {
Paul Mackerras35499c02005-10-22 16:02:39 +1000577 pmac_tb_freeze = smp_core99_pulsar_tb_freeze;
578 pmac_tb_pulsar_addr = 0xd2;
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100579 name = "Pulsar";
Stephen Rothwell55b61fe2007-05-03 17:26:52 +1000580 } else if (of_device_is_compatible(cc, "cy28508")) {
Paul Mackerras35499c02005-10-22 16:02:39 +1000581 pmac_tb_freeze = smp_core99_cypress_tb_freeze;
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100582 name = "Cypress";
Paul Mackerras35499c02005-10-22 16:02:39 +1000583 }
584 break;
585 case 0xd4:
586 pmac_tb_freeze = smp_core99_pulsar_tb_freeze;
587 pmac_tb_pulsar_addr = 0xd4;
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100588 name = "Pulsar";
Paul Mackerras35499c02005-10-22 16:02:39 +1000589 break;
590 }
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100591 if (pmac_tb_freeze != NULL)
Paul Mackerras35499c02005-10-22 16:02:39 +1000592 break;
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100593 }
594 if (pmac_tb_freeze != NULL) {
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100595 /* Open i2c bus for synchronous access */
Benjamin Herrenschmidt730745a2006-01-07 11:30:44 +1100596 if (pmac_i2c_open(pmac_tb_clock_chip_host, 1)) {
597 printk(KERN_ERR "Failed top open i2c bus for clock"
598 " sync, fallback to software sync !\n");
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100599 goto no_i2c_sync;
600 }
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100601 printk(KERN_INFO "Processor timebase sync using %s i2c clock\n",
602 name);
603 return;
Paul Mackerras35499c02005-10-22 16:02:39 +1000604 }
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100605 no_i2c_sync:
606 pmac_tb_freeze = NULL;
Benjamin Herrenschmidt730745a2006-01-07 11:30:44 +1100607 pmac_tb_clock_chip_host = NULL;
Paul Mackerras35499c02005-10-22 16:02:39 +1000608}
609
Paul Mackerras35499c02005-10-22 16:02:39 +1000610
Paul Mackerras35499c02005-10-22 16:02:39 +1000611
612/*
Benjamin Herrenschmidt5b9ca522006-01-07 11:41:02 +1100613 * Newer G5s uses a platform function
614 */
615
616static void smp_core99_pfunc_tb_freeze(int freeze)
617{
618 struct device_node *cpus;
619 struct pmf_args args;
620
621 cpus = of_find_node_by_path("/cpus");
622 BUG_ON(cpus == NULL);
623 args.count = 1;
624 args.u[0].v = !freeze;
625 pmf_call_function(cpus, "cpu-timebase", &args);
626 of_node_put(cpus);
627}
628
629#else /* CONFIG_PPC64 */
630
631/*
632 * SMP G4 use a GPIO to enable/disable the timebase.
Paul Mackerras35499c02005-10-22 16:02:39 +1000633 */
634
635static unsigned int core99_tb_gpio; /* Timebase freeze GPIO */
636
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100637static void smp_core99_gpio_tb_freeze(int freeze)
Paul Mackerras35499c02005-10-22 16:02:39 +1000638{
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100639 if (freeze)
640 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, core99_tb_gpio, 4);
641 else
642 pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, core99_tb_gpio, 0);
Paul Mackerras35499c02005-10-22 16:02:39 +1000643 pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, core99_tb_gpio, 0);
Paul Mackerras35499c02005-10-22 16:02:39 +1000644}
645
Benjamin Herrenschmidt5b9ca522006-01-07 11:41:02 +1100646
647#endif /* !CONFIG_PPC64 */
648
Paul Mackerras35499c02005-10-22 16:02:39 +1000649/* L2 and L3 cache settings to pass from CPU0 to CPU1 on G4 cpus */
650volatile static long int core99_l2_cache;
651volatile static long int core99_l3_cache;
652
653static void __devinit core99_init_caches(int cpu)
654{
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100655#ifndef CONFIG_PPC64
Paul Mackerras35499c02005-10-22 16:02:39 +1000656 if (!cpu_has_feature(CPU_FTR_L2CR))
657 return;
658
659 if (cpu == 0) {
660 core99_l2_cache = _get_L2CR();
661 printk("CPU0: L2CR is %lx\n", core99_l2_cache);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000662 } else {
Paul Mackerras35499c02005-10-22 16:02:39 +1000663 printk("CPU%d: L2CR was %lx\n", cpu, _get_L2CR());
664 _set_L2CR(0);
665 _set_L2CR(core99_l2_cache);
666 printk("CPU%d: L2CR set to %lx\n", cpu, core99_l2_cache);
667 }
668
669 if (!cpu_has_feature(CPU_FTR_L3CR))
670 return;
671
672 if (cpu == 0){
673 core99_l3_cache = _get_L3CR();
674 printk("CPU0: L3CR is %lx\n", core99_l3_cache);
675 } else {
676 printk("CPU%d: L3CR was %lx\n", cpu, _get_L3CR());
677 _set_L3CR(0);
678 _set_L3CR(core99_l3_cache);
679 printk("CPU%d: L3CR set to %lx\n", cpu, core99_l3_cache);
680 }
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100681#endif /* !CONFIG_PPC64 */
Paul Mackerras35499c02005-10-22 16:02:39 +1000682}
683
684static void __init smp_core99_setup(int ncpus)
685{
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100686#ifdef CONFIG_PPC64
Paul Mackerras35499c02005-10-22 16:02:39 +1000687
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100688 /* i2c based HW sync on some G5s */
Grant Likely71a157e2010-02-01 21:34:14 -0700689 if (of_machine_is_compatible("PowerMac7,2") ||
690 of_machine_is_compatible("PowerMac7,3") ||
691 of_machine_is_compatible("RackMac3,1"))
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100692 smp_core99_setup_i2c_hwsync(ncpus);
693
Benjamin Herrenschmidt5b9ca522006-01-07 11:41:02 +1100694 /* pfunc based HW sync on recent G5s */
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100695 if (pmac_tb_freeze == NULL) {
Benjamin Herrenschmidt5b9ca522006-01-07 11:41:02 +1100696 struct device_node *cpus =
697 of_find_node_by_path("/cpus");
698 if (cpus &&
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000699 of_get_property(cpus, "platform-cpu-timebase", NULL)) {
Benjamin Herrenschmidt5b9ca522006-01-07 11:41:02 +1100700 pmac_tb_freeze = smp_core99_pfunc_tb_freeze;
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100701 printk(KERN_INFO "Processor timebase sync using"
Benjamin Herrenschmidt5b9ca522006-01-07 11:41:02 +1100702 " platform function\n");
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100703 }
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000704 }
705
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100706#else /* CONFIG_PPC64 */
707
708 /* GPIO based HW sync on ppc32 Core99 */
Grant Likely71a157e2010-02-01 21:34:14 -0700709 if (pmac_tb_freeze == NULL && !of_machine_is_compatible("MacRISC4")) {
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100710 struct device_node *cpu;
Al Viro13b5aec2006-09-23 16:44:58 +0100711 const u32 *tbprop = NULL;
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100712
713 core99_tb_gpio = KL_GPIO_TB_ENABLE; /* default value */
714 cpu = of_find_node_by_type(NULL, "cpu");
715 if (cpu != NULL) {
Stephen Rothwelle2eb6392007-04-03 22:26:41 +1000716 tbprop = of_get_property(cpu, "timebase-enable", NULL);
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100717 if (tbprop)
718 core99_tb_gpio = *tbprop;
719 of_node_put(cpu);
720 }
721 pmac_tb_freeze = smp_core99_gpio_tb_freeze;
722 printk(KERN_INFO "Processor timebase sync using"
723 " GPIO 0x%02x\n", core99_tb_gpio);
724 }
725
726#endif /* CONFIG_PPC64 */
727
728 /* No timebase sync, fallback to software */
729 if (pmac_tb_freeze == NULL) {
730 smp_ops->give_timebase = smp_generic_give_timebase;
731 smp_ops->take_timebase = smp_generic_take_timebase;
732 printk(KERN_INFO "Processor timebase sync using software\n");
733 }
734
735#ifndef CONFIG_PPC64
736 {
737 int i;
738
739 /* XXX should get this from reg properties */
740 for (i = 1; i < ncpus; ++i)
Nathan Lynch6ff04c52008-12-10 14:28:42 +0000741 set_hard_smp_processor_id(i, i);
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100742 }
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000743#endif
Paul Mackerras35499c02005-10-22 16:02:39 +1000744
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100745 /* 32 bits SMP can't NAP */
Grant Likely71a157e2010-02-01 21:34:14 -0700746 if (!of_machine_is_compatible("MacRISC4"))
Benjamin Herrenschmidt1beb6a72005-12-14 13:10:10 +1100747 powersave_nap = 0;
748}
749
Paul Mackerras35499c02005-10-22 16:02:39 +1000750static int __init smp_core99_probe(void)
751{
752 struct device_node *cpus;
753 int ncpus = 0;
754
755 if (ppc_md.progress) ppc_md.progress("smp_core99_probe", 0x345);
756
757 /* Count CPUs in the device-tree */
758 for (cpus = NULL; (cpus = of_find_node_by_type(cpus, "cpu")) != NULL;)
759 ++ncpus;
760
761 printk(KERN_INFO "PowerMac SMP probe found %d cpus\n", ncpus);
762
763 /* Nothing more to do if less than 2 of them */
764 if (ncpus <= 1)
765 return 1;
766
Benjamin Herrenschmidt730745a2006-01-07 11:30:44 +1100767 /* We need to perform some early initialisations before we can start
768 * setting up SMP as we are running before initcalls
769 */
Benjamin Herrenschmidt5b9ca522006-01-07 11:41:02 +1100770 pmac_pfunc_base_install();
Benjamin Herrenschmidt730745a2006-01-07 11:30:44 +1100771 pmac_i2c_init();
772
773 /* Setup various bits like timebase sync method, ability to nap, ... */
Paul Mackerras35499c02005-10-22 16:02:39 +1000774 smp_core99_setup(ncpus);
Benjamin Herrenschmidt730745a2006-01-07 11:30:44 +1100775
776 /* Install IPIs */
Paul Mackerras35499c02005-10-22 16:02:39 +1000777 mpic_request_ipis();
Benjamin Herrenschmidt730745a2006-01-07 11:30:44 +1100778
779 /* Collect l2cr and l3cr values from CPU 0 */
Paul Mackerras35499c02005-10-22 16:02:39 +1000780 core99_init_caches(0);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000781
782 return ncpus;
783}
784
Michael Ellermande300972011-04-11 21:46:19 +0000785static int __devinit smp_core99_kick_cpu(int nr)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000786{
Paul Mackerras35499c02005-10-22 16:02:39 +1000787 unsigned int save_vector;
Michael Ellerman758438a2005-12-05 15:49:00 -0600788 unsigned long target, flags;
Paul Mackerras549e8152008-08-30 11:43:47 +1000789 unsigned int *vector = (unsigned int *)(PAGE_OFFSET+0x100);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000790
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000791 if (nr < 0 || nr > 3)
Michael Ellermande300972011-04-11 21:46:19 +0000792 return -ENOENT;
Michael Ellerman758438a2005-12-05 15:49:00 -0600793
794 if (ppc_md.progress)
795 ppc_md.progress("smp_core99_kick_cpu", 0x346);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000796
797 local_irq_save(flags);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000798
799 /* Save reset vector */
800 save_vector = *vector;
801
Michael Ellerman758438a2005-12-05 15:49:00 -0600802 /* Setup fake reset vector that does
Paul Mackerras549e8152008-08-30 11:43:47 +1000803 * b __secondary_start_pmac_0 + nr*8
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000804 */
Michael Ellerman758438a2005-12-05 15:49:00 -0600805 target = (unsigned long) __secondary_start_pmac_0 + nr * 8;
Michael Ellermane7a57272008-06-24 11:32:22 +1000806 patch_branch(vector, target, BRANCH_SET_LINK);
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000807
808 /* Put some life in our friend */
809 pmac_call_feature(PMAC_FTR_RESET_CPU, NULL, nr, 0);
810
811 /* FIXME: We wait a bit for the CPU to take the exception, I should
812 * instead wait for the entry code to set something for me. Well,
813 * ideally, all that crap will be done in prom.c and the CPU left
814 * in a RAM-based wait loop like CHRP.
815 */
816 mdelay(1);
817
818 /* Restore our exception vector */
819 *vector = save_vector;
820 flush_icache_range((unsigned long) vector, (unsigned long) vector + 4);
821
822 local_irq_restore(flags);
823 if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu done", 0x347);
Michael Ellermande300972011-04-11 21:46:19 +0000824
825 return 0;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000826}
827
828static void __devinit smp_core99_setup_cpu(int cpu_nr)
829{
830 /* Setup L2/L3 */
831 if (cpu_nr != 0)
832 core99_init_caches(cpu_nr);
833
834 /* Setup openpic */
835 mpic_setup_this_cpu();
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000836}
837
Benjamin Herrenschmidt7b84b292011-04-18 15:46:35 +1000838#ifdef CONFIG_PPC64
Benjamin Herrenschmidt734796f2011-03-08 13:54:50 +1100839#ifdef CONFIG_HOTPLUG_CPU
840static int smp_core99_cpu_notify(struct notifier_block *self,
841 unsigned long action, void *hcpu)
842{
843 int rc;
844
845 switch(action) {
846 case CPU_UP_PREPARE:
847 case CPU_UP_PREPARE_FROZEN:
848 /* Open i2c bus if it was used for tb sync */
849 if (pmac_tb_clock_chip_host) {
850 rc = pmac_i2c_open(pmac_tb_clock_chip_host, 1);
851 if (rc) {
852 pr_err("Failed to open i2c bus for time sync\n");
853 return notifier_from_errno(rc);
854 }
855 }
856 break;
857 case CPU_ONLINE:
858 case CPU_UP_CANCELED:
859 /* Close i2c bus if it was used for tb sync */
860 if (pmac_tb_clock_chip_host)
861 pmac_i2c_close(pmac_tb_clock_chip_host);
862 break;
863 default:
864 break;
865 }
866 return NOTIFY_OK;
867}
868
869static struct notifier_block __cpuinitdata smp_core99_cpu_nb = {
870 .notifier_call = smp_core99_cpu_notify,
871};
872#endif /* CONFIG_HOTPLUG_CPU */
873
874static void __init smp_core99_bringup_done(void)
875{
Benjamin Herrenschmidt734796f2011-03-08 13:54:50 +1100876 extern void g5_phy_disable_cpu1(void);
877
878 /* Close i2c bus if it was used for tb sync */
879 if (pmac_tb_clock_chip_host)
880 pmac_i2c_close(pmac_tb_clock_chip_host);
881
882 /* If we didn't start the second CPU, we must take
883 * it off the bus.
884 */
885 if (of_machine_is_compatible("MacRISC4") &&
886 num_online_cpus() < 2) {
887 set_cpu_present(1, false);
888 g5_phy_disable_cpu1();
889 }
Benjamin Herrenschmidt734796f2011-03-08 13:54:50 +1100890#ifdef CONFIG_HOTPLUG_CPU
891 register_cpu_notifier(&smp_core99_cpu_nb);
892#endif
Benjamin Herrenschmidt7b84b292011-04-18 15:46:35 +1000893
Benjamin Herrenschmidt734796f2011-03-08 13:54:50 +1100894 if (ppc_md.progress)
895 ppc_md.progress("smp_core99_bringup_done", 0x349);
896}
Benjamin Herrenschmidt7b84b292011-04-18 15:46:35 +1000897#endif /* CONFIG_PPC64 */
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000898
Benjamin Herrenschmidt4c6130d92011-02-11 14:03:20 +1100899#ifdef CONFIG_HOTPLUG_CPU
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000900
Benjamin Herrenschmidt45e07fd2011-02-21 16:31:49 +1100901static int smp_core99_cpu_disable(void)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000902{
Benjamin Herrenschmidt45e07fd2011-02-21 16:31:49 +1100903 int rc = generic_cpu_disable();
904 if (rc)
905 return rc;
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000906
Paul Mackerrasc0c0d992005-10-01 13:49:08 +1000907 mpic_cpu_set_priority(0xf);
Benjamin Herrenschmidt45e07fd2011-02-21 16:31:49 +1100908
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000909 return 0;
910}
911
Benjamin Herrenschmidt4c6130d92011-02-11 14:03:20 +1100912#ifdef CONFIG_PPC32
913
914static void pmac_cpu_die(void)
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000915{
Benjamin Herrenschmidt105765f2011-04-01 09:23:37 +1100916 int cpu = smp_processor_id();
917
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000918 local_irq_disable();
Benjamin Herrenschmidtfb49f862011-02-11 14:09:32 +1100919 idle_task_exit();
Benjamin Herrenschmidt105765f2011-04-01 09:23:37 +1100920 pr_debug("CPU%d offline\n", cpu);
921 generic_set_cpu_dead(cpu);
Benjamin Herrenschmidtfb49f862011-02-11 14:09:32 +1100922 smp_wmb();
Paul Mackerras14cf11a2005-09-26 16:04:21 +1000923 mb();
924 low_cpu_die();
925}
926
Benjamin Herrenschmidt4c6130d92011-02-11 14:03:20 +1100927#else /* CONFIG_PPC32 */
928
929static void pmac_cpu_die(void)
930{
Benjamin Herrenschmidt105765f2011-04-01 09:23:37 +1100931 int cpu = smp_processor_id();
932
Benjamin Herrenschmidt4c6130d92011-02-11 14:03:20 +1100933 local_irq_disable();
934 idle_task_exit();
935
936 /*
937 * turn off as much as possible, we'll be
938 * kicked out as this will only be invoked
939 * on core99 platforms for now ...
940 */
941
Benjamin Herrenschmidt105765f2011-04-01 09:23:37 +1100942 printk(KERN_INFO "CPU#%d offline\n", cpu);
943 generic_set_cpu_dead(cpu);
Benjamin Herrenschmidt4c6130d92011-02-11 14:03:20 +1100944 smp_wmb();
945
946 /*
Benjamin Herrenschmidt62cc67b2011-02-21 16:49:58 +1100947 * Re-enable interrupts. The NAP code needs to enable them
948 * anyways, do it now so we deal with the case where one already
949 * happened while soft-disabled.
950 * We shouldn't get any external interrupts, only decrementer, and the
951 * decrementer handler is safe for use on offline CPUs
Benjamin Herrenschmidt4c6130d92011-02-11 14:03:20 +1100952 */
Benjamin Herrenschmidt62cc67b2011-02-21 16:49:58 +1100953 local_irq_enable();
Benjamin Herrenschmidt4c6130d92011-02-11 14:03:20 +1100954
955 while (1) {
956 /* let's not take timer interrupts too often ... */
957 set_dec(0x7fffffff);
958
Benjamin Herrenschmidt62cc67b2011-02-21 16:49:58 +1100959 /* Enter NAP mode */
960 power4_idle();
Benjamin Herrenschmidt4c6130d92011-02-11 14:03:20 +1100961 }
962}
963
964#endif /* else CONFIG_PPC32 */
965#endif /* CONFIG_HOTPLUG_CPU */
Paul Mackerras094fe2e2005-11-10 14:26:12 +1100966
967/* Core99 Macs (dual G4s and G5s) */
968struct smp_ops_t core99_smp_ops = {
969 .message_pass = smp_mpic_message_pass,
970 .probe = smp_core99_probe,
Benjamin Herrenschmidt7b84b292011-04-18 15:46:35 +1000971#ifdef CONFIG_PPC64
Benjamin Herrenschmidt734796f2011-03-08 13:54:50 +1100972 .bringup_done = smp_core99_bringup_done,
Benjamin Herrenschmidt7b84b292011-04-18 15:46:35 +1000973#endif
Paul Mackerras094fe2e2005-11-10 14:26:12 +1100974 .kick_cpu = smp_core99_kick_cpu,
975 .setup_cpu = smp_core99_setup_cpu,
976 .give_timebase = smp_core99_give_timebase,
977 .take_timebase = smp_core99_take_timebase,
Johannes Bergd9333af2007-05-03 06:33:51 +1000978#if defined(CONFIG_HOTPLUG_CPU)
Paul Mackerras094fe2e2005-11-10 14:26:12 +1100979 .cpu_disable = smp_core99_cpu_disable,
Benjamin Herrenschmidtfb49f862011-02-11 14:09:32 +1100980 .cpu_die = generic_cpu_die,
Paul Mackerras094fe2e2005-11-10 14:26:12 +1100981#endif
982};
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +0000983
984void __init pmac_setup_smp(void)
985{
986 struct device_node *np;
987
988 /* Check for Core99 */
989 np = of_find_node_by_name(NULL, "uni-n");
990 if (!np)
991 np = of_find_node_by_name(NULL, "u3");
992 if (!np)
993 np = of_find_node_by_name(NULL, "u4");
994 if (np) {
995 of_node_put(np);
996 smp_ops = &core99_smp_ops;
997 }
998#ifdef CONFIG_PPC32
999 else {
Anton Blanchard828a6982010-04-26 15:32:44 +00001000 /* We have to set bits in cpu_possible_mask here since the
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +00001001 * secondary CPU(s) aren't in the device tree. Various
1002 * things won't be initialized for CPUs not in the possible
1003 * map, so we really need to fix it up here.
1004 */
1005 int cpu;
1006
1007 for (cpu = 1; cpu < 4 && cpu < NR_CPUS; ++cpu)
Rusty Russellea0f1ca2009-09-24 09:34:48 -06001008 set_cpu_possible(cpu, true);
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +00001009 smp_ops = &psurge_smp_ops;
1010 }
1011#endif /* CONFIG_PPC32 */
Benjamin Herrenschmidt4c6130d92011-02-11 14:03:20 +11001012
1013#ifdef CONFIG_HOTPLUG_CPU
1014 ppc_md.cpu_die = pmac_cpu_die;
1015#endif
Benjamin Herrenschmidt7ccbe502009-06-18 23:30:07 +00001016}
1017
Benjamin Herrenschmidt4c6130d92011-02-11 14:03:20 +11001018