pmac_smp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670
  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. #include <linux/hardirq.h>
  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/residual.h>
  46. #include <asm/machdep.h>
  47. #include <asm/pmac_feature.h>
  48. #include <asm/time.h>
  49. #include <asm/open_pic.h>
  50. #include <asm/cacheflush.h>
  51. #include <asm/keylargo.h>
  52. /*
  53. * Powersurge (old powermac SMP) support.
  54. */
  55. extern void __secondary_start_psurge(void);
  56. extern void __secondary_start_psurge2(void); /* Temporary horrible hack */
  57. extern void __secondary_start_psurge3(void); /* Temporary horrible hack */
  58. /* Addresses for powersurge registers */
  59. #define HAMMERHEAD_BASE 0xf8000000
  60. #define HHEAD_CONFIG 0x90
  61. #define HHEAD_SEC_INTR 0xc0
  62. /* register for interrupting the primary processor on the powersurge */
  63. /* N.B. this is actually the ethernet ROM! */
  64. #define PSURGE_PRI_INTR 0xf3019000
  65. /* register for storing the start address for the secondary processor */
  66. /* N.B. this is the PCI config space address register for the 1st bridge */
  67. #define PSURGE_START 0xf2800000
  68. /* Daystar/XLR8 4-CPU card */
  69. #define PSURGE_QUAD_REG_ADDR 0xf8800000
  70. #define PSURGE_QUAD_IRQ_SET 0
  71. #define PSURGE_QUAD_IRQ_CLR 1
  72. #define PSURGE_QUAD_IRQ_PRIMARY 2
  73. #define PSURGE_QUAD_CKSTOP_CTL 3
  74. #define PSURGE_QUAD_PRIMARY_ARB 4
  75. #define PSURGE_QUAD_BOARD_ID 6
  76. #define PSURGE_QUAD_WHICH_CPU 7
  77. #define PSURGE_QUAD_CKSTOP_RDBK 8
  78. #define PSURGE_QUAD_RESET_CTL 11
  79. #define PSURGE_QUAD_OUT(r, v) (out_8(quad_base + ((r) << 4) + 4, (v)))
  80. #define PSURGE_QUAD_IN(r) (in_8(quad_base + ((r) << 4) + 4) & 0x0f)
  81. #define PSURGE_QUAD_BIS(r, v) (PSURGE_QUAD_OUT((r), PSURGE_QUAD_IN(r) | (v)))
  82. #define PSURGE_QUAD_BIC(r, v) (PSURGE_QUAD_OUT((r), PSURGE_QUAD_IN(r) & ~(v)))
  83. /* virtual addresses for the above */
  84. static volatile u8 __iomem *hhead_base;
  85. static volatile u8 __iomem *quad_base;
  86. static volatile u32 __iomem *psurge_pri_intr;
  87. static volatile u8 __iomem *psurge_sec_intr;
  88. static volatile u32 __iomem *psurge_start;
  89. /* values for psurge_type */
  90. #define PSURGE_NONE -1
  91. #define PSURGE_DUAL 0
  92. #define PSURGE_QUAD_OKEE 1
  93. #define PSURGE_QUAD_COTTON 2
  94. #define PSURGE_QUAD_ICEGRASS 3
  95. /* what sort of powersurge board we have */
  96. static int psurge_type = PSURGE_NONE;
  97. /* L2 and L3 cache settings to pass from CPU0 to CPU1 */
  98. volatile static long int core99_l2_cache;
  99. volatile static long int core99_l3_cache;
  100. /* Timebase freeze GPIO */
  101. static unsigned int core99_tb_gpio;
  102. /* Sync flag for HW tb sync */
  103. static volatile int sec_tb_reset = 0;
  104. static unsigned int pri_tb_hi, pri_tb_lo;
  105. static unsigned int pri_tb_stamp;
  106. static void __init core99_init_caches(int cpu)
  107. {
  108. if (!cpu_has_feature(CPU_FTR_L2CR))
  109. return;
  110. if (cpu == 0) {
  111. core99_l2_cache = _get_L2CR();
  112. printk("CPU0: L2CR is %lx\n", core99_l2_cache);
  113. } else {
  114. printk("CPU%d: L2CR was %lx\n", cpu, _get_L2CR());
  115. _set_L2CR(0);
  116. _set_L2CR(core99_l2_cache);
  117. printk("CPU%d: L2CR set to %lx\n", cpu, core99_l2_cache);
  118. }
  119. if (!cpu_has_feature(CPU_FTR_L3CR))
  120. return;
  121. if (cpu == 0){
  122. core99_l3_cache = _get_L3CR();
  123. printk("CPU0: L3CR is %lx\n", core99_l3_cache);
  124. } else {
  125. printk("CPU%d: L3CR was %lx\n", cpu, _get_L3CR());
  126. _set_L3CR(0);
  127. _set_L3CR(core99_l3_cache);
  128. printk("CPU%d: L3CR set to %lx\n", cpu, core99_l3_cache);
  129. }
  130. }
  131. /*
  132. * Set and clear IPIs for powersurge.
  133. */
  134. static inline void psurge_set_ipi(int cpu)
  135. {
  136. if (psurge_type == PSURGE_NONE)
  137. return;
  138. if (cpu == 0)
  139. in_be32(psurge_pri_intr);
  140. else if (psurge_type == PSURGE_DUAL)
  141. out_8(psurge_sec_intr, 0);
  142. else
  143. PSURGE_QUAD_OUT(PSURGE_QUAD_IRQ_SET, 1 << cpu);
  144. }
  145. static inline void psurge_clr_ipi(int cpu)
  146. {
  147. if (cpu > 0) {
  148. switch(psurge_type) {
  149. case PSURGE_DUAL:
  150. out_8(psurge_sec_intr, ~0);
  151. case PSURGE_NONE:
  152. break;
  153. default:
  154. PSURGE_QUAD_OUT(PSURGE_QUAD_IRQ_CLR, 1 << cpu);
  155. }
  156. }
  157. }
  158. /*
  159. * On powersurge (old SMP powermac architecture) we don't have
  160. * separate IPIs for separate messages like openpic does. Instead
  161. * we have a bitmap for each processor, where a 1 bit means that
  162. * the corresponding message is pending for that processor.
  163. * Ideally each cpu's entry would be in a different cache line.
  164. * -- paulus.
  165. */
  166. static unsigned long psurge_smp_message[NR_CPUS];
  167. void __pmac psurge_smp_message_recv(struct pt_regs *regs)
  168. {
  169. int cpu = smp_processor_id();
  170. int msg;
  171. /* clear interrupt */
  172. psurge_clr_ipi(cpu);
  173. if (num_online_cpus() < 2)
  174. return;
  175. /* make sure there is a message there */
  176. for (msg = 0; msg < 4; msg++)
  177. if (test_and_clear_bit(msg, &psurge_smp_message[cpu]))
  178. smp_message_recv(msg, regs);
  179. }
  180. irqreturn_t __pmac psurge_primary_intr(int irq, void *d, struct pt_regs *regs)
  181. {
  182. psurge_smp_message_recv(regs);
  183. return IRQ_HANDLED;
  184. }
  185. static void __pmac smp_psurge_message_pass(int target, int msg, unsigned long data,
  186. int wait)
  187. {
  188. int i;
  189. if (num_online_cpus() < 2)
  190. return;
  191. for (i = 0; i < NR_CPUS; i++) {
  192. if (!cpu_online(i))
  193. continue;
  194. if (target == MSG_ALL
  195. || (target == MSG_ALL_BUT_SELF && i != smp_processor_id())
  196. || target == i) {
  197. set_bit(msg, &psurge_smp_message[i]);
  198. psurge_set_ipi(i);
  199. }
  200. }
  201. }
  202. /*
  203. * Determine a quad card presence. We read the board ID register, we
  204. * force the data bus to change to something else, and we read it again.
  205. * It it's stable, then the register probably exist (ugh !)
  206. */
  207. static int __init psurge_quad_probe(void)
  208. {
  209. int type;
  210. unsigned int i;
  211. type = PSURGE_QUAD_IN(PSURGE_QUAD_BOARD_ID);
  212. if (type < PSURGE_QUAD_OKEE || type > PSURGE_QUAD_ICEGRASS
  213. || type != PSURGE_QUAD_IN(PSURGE_QUAD_BOARD_ID))
  214. return PSURGE_DUAL;
  215. /* looks OK, try a slightly more rigorous test */
  216. /* bogus is not necessarily cacheline-aligned,
  217. though I don't suppose that really matters. -- paulus */
  218. for (i = 0; i < 100; i++) {
  219. volatile u32 bogus[8];
  220. bogus[(0+i)%8] = 0x00000000;
  221. bogus[(1+i)%8] = 0x55555555;
  222. bogus[(2+i)%8] = 0xFFFFFFFF;
  223. bogus[(3+i)%8] = 0xAAAAAAAA;
  224. bogus[(4+i)%8] = 0x33333333;
  225. bogus[(5+i)%8] = 0xCCCCCCCC;
  226. bogus[(6+i)%8] = 0xCCCCCCCC;
  227. bogus[(7+i)%8] = 0x33333333;
  228. wmb();
  229. asm volatile("dcbf 0,%0" : : "r" (bogus) : "memory");
  230. mb();
  231. if (type != PSURGE_QUAD_IN(PSURGE_QUAD_BOARD_ID))
  232. return PSURGE_DUAL;
  233. }
  234. return type;
  235. }
  236. static void __init psurge_quad_init(void)
  237. {
  238. int procbits;
  239. if (ppc_md.progress) ppc_md.progress("psurge_quad_init", 0x351);
  240. procbits = ~PSURGE_QUAD_IN(PSURGE_QUAD_WHICH_CPU);
  241. if (psurge_type == PSURGE_QUAD_ICEGRASS)
  242. PSURGE_QUAD_BIS(PSURGE_QUAD_RESET_CTL, procbits);
  243. else
  244. PSURGE_QUAD_BIC(PSURGE_QUAD_CKSTOP_CTL, procbits);
  245. mdelay(33);
  246. out_8(psurge_sec_intr, ~0);
  247. PSURGE_QUAD_OUT(PSURGE_QUAD_IRQ_CLR, procbits);
  248. PSURGE_QUAD_BIS(PSURGE_QUAD_RESET_CTL, procbits);
  249. if (psurge_type != PSURGE_QUAD_ICEGRASS)
  250. PSURGE_QUAD_BIS(PSURGE_QUAD_CKSTOP_CTL, procbits);
  251. PSURGE_QUAD_BIC(PSURGE_QUAD_PRIMARY_ARB, procbits);
  252. mdelay(33);
  253. PSURGE_QUAD_BIC(PSURGE_QUAD_RESET_CTL, procbits);
  254. mdelay(33);
  255. PSURGE_QUAD_BIS(PSURGE_QUAD_PRIMARY_ARB, procbits);
  256. mdelay(33);
  257. }
  258. static int __init smp_psurge_probe(void)
  259. {
  260. int i, ncpus;
  261. /* We don't do SMP on the PPC601 -- paulus */
  262. if (PVR_VER(mfspr(SPRN_PVR)) == 1)
  263. return 1;
  264. /*
  265. * The powersurge cpu board can be used in the generation
  266. * of powermacs that have a socket for an upgradeable cpu card,
  267. * including the 7500, 8500, 9500, 9600.
  268. * The device tree doesn't tell you if you have 2 cpus because
  269. * OF doesn't know anything about the 2nd processor.
  270. * Instead we look for magic bits in magic registers,
  271. * in the hammerhead memory controller in the case of the
  272. * dual-cpu powersurge board. -- paulus.
  273. */
  274. if (find_devices("hammerhead") == NULL)
  275. return 1;
  276. hhead_base = ioremap(HAMMERHEAD_BASE, 0x800);
  277. quad_base = ioremap(PSURGE_QUAD_REG_ADDR, 1024);
  278. psurge_sec_intr = hhead_base + HHEAD_SEC_INTR;
  279. psurge_type = psurge_quad_probe();
  280. if (psurge_type != PSURGE_DUAL) {
  281. psurge_quad_init();
  282. /* All released cards using this HW design have 4 CPUs */
  283. ncpus = 4;
  284. } else {
  285. iounmap(quad_base);
  286. if ((in_8(hhead_base + HHEAD_CONFIG) & 0x02) == 0) {
  287. /* not a dual-cpu card */
  288. iounmap(hhead_base);
  289. psurge_type = PSURGE_NONE;
  290. return 1;
  291. }
  292. ncpus = 2;
  293. }
  294. psurge_start = ioremap(PSURGE_START, 4);
  295. psurge_pri_intr = ioremap(PSURGE_PRI_INTR, 4);
  296. /* this is not actually strictly necessary -- paulus. */
  297. for (i = 1; i < ncpus; ++i)
  298. smp_hw_index[i] = i;
  299. if (ppc_md.progress) ppc_md.progress("smp_psurge_probe - done", 0x352);
  300. return ncpus;
  301. }
  302. static void __init smp_psurge_kick_cpu(int nr)
  303. {
  304. void (*start)(void) = __secondary_start_psurge;
  305. unsigned long a;
  306. /* may need to flush here if secondary bats aren't setup */
  307. for (a = KERNELBASE; a < KERNELBASE + 0x800000; a += 32)
  308. asm volatile("dcbf 0,%0" : : "r" (a) : "memory");
  309. asm volatile("sync");
  310. if (ppc_md.progress) ppc_md.progress("smp_psurge_kick_cpu", 0x353);
  311. /* setup entry point of secondary processor */
  312. switch (nr) {
  313. case 2:
  314. start = __secondary_start_psurge2;
  315. break;
  316. case 3:
  317. start = __secondary_start_psurge3;
  318. break;
  319. }
  320. out_be32(psurge_start, __pa(start));
  321. mb();
  322. psurge_set_ipi(nr);
  323. udelay(10);
  324. psurge_clr_ipi(nr);
  325. if (ppc_md.progress) ppc_md.progress("smp_psurge_kick_cpu - done", 0x354);
  326. }
  327. /*
  328. * With the dual-cpu powersurge board, the decrementers and timebases
  329. * of both cpus are frozen after the secondary cpu is started up,
  330. * until we give the secondary cpu another interrupt. This routine
  331. * uses this to get the timebases synchronized.
  332. * -- paulus.
  333. */
  334. static void __init psurge_dual_sync_tb(int cpu_nr)
  335. {
  336. int t;
  337. set_dec(tb_ticks_per_jiffy);
  338. set_tb(0, 0);
  339. last_jiffy_stamp(cpu_nr) = 0;
  340. if (cpu_nr > 0) {
  341. mb();
  342. sec_tb_reset = 1;
  343. return;
  344. }
  345. /* wait for the secondary to have reset its TB before proceeding */
  346. for (t = 10000000; t > 0 && !sec_tb_reset; --t)
  347. ;
  348. /* now interrupt the secondary, starting both TBs */
  349. psurge_set_ipi(1);
  350. smp_tb_synchronized = 1;
  351. }
  352. static struct irqaction psurge_irqaction = {
  353. .handler = psurge_primary_intr,
  354. .flags = SA_INTERRUPT,
  355. .mask = CPU_MASK_NONE,
  356. .name = "primary IPI",
  357. };
  358. static void __init smp_psurge_setup_cpu(int cpu_nr)
  359. {
  360. if (cpu_nr == 0) {
  361. /* If we failed to start the second CPU, we should still
  362. * send it an IPI to start the timebase & DEC or we might
  363. * have them stuck.
  364. */
  365. if (num_online_cpus() < 2) {
  366. if (psurge_type == PSURGE_DUAL)
  367. psurge_set_ipi(1);
  368. return;
  369. }
  370. /* reset the entry point so if we get another intr we won't
  371. * try to startup again */
  372. out_be32(psurge_start, 0x100);
  373. if (setup_irq(30, &psurge_irqaction))
  374. printk(KERN_ERR "Couldn't get primary IPI interrupt");
  375. }
  376. if (psurge_type == PSURGE_DUAL)
  377. psurge_dual_sync_tb(cpu_nr);
  378. }
  379. void __init smp_psurge_take_timebase(void)
  380. {
  381. /* Dummy implementation */
  382. }
  383. void __init smp_psurge_give_timebase(void)
  384. {
  385. /* Dummy implementation */
  386. }
  387. static int __init smp_core99_probe(void)
  388. {
  389. #ifdef CONFIG_6xx
  390. extern int powersave_nap;
  391. #endif
  392. struct device_node *cpus, *firstcpu;
  393. int i, ncpus = 0, boot_cpu = -1;
  394. u32 *tbprop = NULL;
  395. if (ppc_md.progress) ppc_md.progress("smp_core99_probe", 0x345);
  396. cpus = firstcpu = find_type_devices("cpu");
  397. while(cpus != NULL) {
  398. u32 *regprop = (u32 *)get_property(cpus, "reg", NULL);
  399. char *stateprop = (char *)get_property(cpus, "state", NULL);
  400. if (regprop != NULL && stateprop != NULL &&
  401. !strncmp(stateprop, "running", 7))
  402. boot_cpu = *regprop;
  403. ++ncpus;
  404. cpus = cpus->next;
  405. }
  406. if (boot_cpu == -1)
  407. printk(KERN_WARNING "Couldn't detect boot CPU !\n");
  408. if (boot_cpu != 0)
  409. printk(KERN_WARNING "Boot CPU is %d, unsupported setup !\n", boot_cpu);
  410. if (machine_is_compatible("MacRISC4")) {
  411. extern struct smp_ops_t core99_smp_ops;
  412. core99_smp_ops.take_timebase = smp_generic_take_timebase;
  413. core99_smp_ops.give_timebase = smp_generic_give_timebase;
  414. } else {
  415. if (firstcpu != NULL)
  416. tbprop = (u32 *)get_property(firstcpu, "timebase-enable", NULL);
  417. if (tbprop)
  418. core99_tb_gpio = *tbprop;
  419. else
  420. core99_tb_gpio = KL_GPIO_TB_ENABLE;
  421. }
  422. if (ncpus > 1) {
  423. openpic_request_IPIs();
  424. for (i = 1; i < ncpus; ++i)
  425. smp_hw_index[i] = i;
  426. #ifdef CONFIG_6xx
  427. powersave_nap = 0;
  428. #endif
  429. core99_init_caches(0);
  430. }
  431. return ncpus;
  432. }
  433. static void __init smp_core99_kick_cpu(int nr)
  434. {
  435. unsigned long save_vector, new_vector;
  436. unsigned long flags;
  437. volatile unsigned long *vector
  438. = ((volatile unsigned long *)(KERNELBASE+0x100));
  439. if (nr < 1 || nr > 3)
  440. return;
  441. if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu", 0x346);
  442. local_irq_save(flags);
  443. local_irq_disable();
  444. /* Save reset vector */
  445. save_vector = *vector;
  446. /* Setup fake reset vector that does
  447. * b __secondary_start_psurge - KERNELBASE
  448. */
  449. switch(nr) {
  450. case 1:
  451. new_vector = (unsigned long)__secondary_start_psurge;
  452. break;
  453. case 2:
  454. new_vector = (unsigned long)__secondary_start_psurge2;
  455. break;
  456. case 3:
  457. new_vector = (unsigned long)__secondary_start_psurge3;
  458. break;
  459. }
  460. *vector = 0x48000002 + new_vector - KERNELBASE;
  461. /* flush data cache and inval instruction cache */
  462. flush_icache_range((unsigned long) vector, (unsigned long) vector + 4);
  463. /* Put some life in our friend */
  464. pmac_call_feature(PMAC_FTR_RESET_CPU, NULL, nr, 0);
  465. /* FIXME: We wait a bit for the CPU to take the exception, I should
  466. * instead wait for the entry code to set something for me. Well,
  467. * ideally, all that crap will be done in prom.c and the CPU left
  468. * in a RAM-based wait loop like CHRP.
  469. */
  470. mdelay(1);
  471. /* Restore our exception vector */
  472. *vector = save_vector;
  473. flush_icache_range((unsigned long) vector, (unsigned long) vector + 4);
  474. local_irq_restore(flags);
  475. if (ppc_md.progress) ppc_md.progress("smp_core99_kick_cpu done", 0x347);
  476. }
  477. static void __init smp_core99_setup_cpu(int cpu_nr)
  478. {
  479. /* Setup L2/L3 */
  480. if (cpu_nr != 0)
  481. core99_init_caches(cpu_nr);
  482. /* Setup openpic */
  483. do_openpic_setup_cpu();
  484. if (cpu_nr == 0) {
  485. #ifdef CONFIG_POWER4
  486. extern void g5_phy_disable_cpu1(void);
  487. /* If we didn't start the second CPU, we must take
  488. * it off the bus
  489. */
  490. if (machine_is_compatible("MacRISC4") &&
  491. num_online_cpus() < 2)
  492. g5_phy_disable_cpu1();
  493. #endif /* CONFIG_POWER4 */
  494. if (ppc_md.progress) ppc_md.progress("core99_setup_cpu 0 done", 0x349);
  495. }
  496. }
  497. /* not __init, called in sleep/wakeup code */
  498. void smp_core99_take_timebase(void)
  499. {
  500. unsigned long flags;
  501. /* tell the primary we're here */
  502. sec_tb_reset = 1;
  503. mb();
  504. /* wait for the primary to set pri_tb_hi/lo */
  505. while (sec_tb_reset < 2)
  506. mb();
  507. /* set our stuff the same as the primary */
  508. local_irq_save(flags);
  509. set_dec(1);
  510. set_tb(pri_tb_hi, pri_tb_lo);
  511. last_jiffy_stamp(smp_processor_id()) = pri_tb_stamp;
  512. mb();
  513. /* tell the primary we're done */
  514. sec_tb_reset = 0;
  515. mb();
  516. local_irq_restore(flags);
  517. }
  518. /* not __init, called in sleep/wakeup code */
  519. void smp_core99_give_timebase(void)
  520. {
  521. unsigned long flags;
  522. unsigned int t;
  523. /* wait for the secondary to be in take_timebase */
  524. for (t = 100000; t > 0 && !sec_tb_reset; --t)
  525. udelay(10);
  526. if (!sec_tb_reset) {
  527. printk(KERN_WARNING "Timeout waiting sync on second CPU\n");
  528. return;
  529. }
  530. /* freeze the timebase and read it */
  531. /* disable interrupts so the timebase is disabled for the
  532. shortest possible time */
  533. local_irq_save(flags);
  534. pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, core99_tb_gpio, 4);
  535. pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, core99_tb_gpio, 0);
  536. mb();
  537. pri_tb_hi = get_tbu();
  538. pri_tb_lo = get_tbl();
  539. pri_tb_stamp = last_jiffy_stamp(smp_processor_id());
  540. mb();
  541. /* tell the secondary we're ready */
  542. sec_tb_reset = 2;
  543. mb();
  544. /* wait for the secondary to have taken it */
  545. for (t = 100000; t > 0 && sec_tb_reset; --t)
  546. udelay(10);
  547. if (sec_tb_reset)
  548. printk(KERN_WARNING "Timeout waiting sync(2) on second CPU\n");
  549. else
  550. smp_tb_synchronized = 1;
  551. /* Now, restart the timebase by leaving the GPIO to an open collector */
  552. pmac_call_feature(PMAC_FTR_WRITE_GPIO, NULL, core99_tb_gpio, 0);
  553. pmac_call_feature(PMAC_FTR_READ_GPIO, NULL, core99_tb_gpio, 0);
  554. local_irq_restore(flags);
  555. }
  556. /* PowerSurge-style Macs */
  557. struct smp_ops_t psurge_smp_ops __pmacdata = {
  558. .message_pass = smp_psurge_message_pass,
  559. .probe = smp_psurge_probe,
  560. .kick_cpu = smp_psurge_kick_cpu,
  561. .setup_cpu = smp_psurge_setup_cpu,
  562. .give_timebase = smp_psurge_give_timebase,
  563. .take_timebase = smp_psurge_take_timebase,
  564. };
  565. /* Core99 Macs (dual G4s) */
  566. struct smp_ops_t core99_smp_ops __pmacdata = {
  567. .message_pass = smp_openpic_message_pass,
  568. .probe = smp_core99_probe,
  569. .kick_cpu = smp_core99_kick_cpu,
  570. .setup_cpu = smp_core99_setup_cpu,
  571. .give_timebase = smp_core99_give_timebase,
  572. .take_timebase = smp_core99_take_timebase,
  573. };