smp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785
  1. /*
  2. * SMP support for ppc.
  3. *
  4. * Written by Cort Dougan (cort@cs.nmt.edu) borrowing a great
  5. * deal of code from the sparc and intel versions.
  6. *
  7. * Copyright (C) 1999 Cort Dougan <cort@cs.nmt.edu>
  8. *
  9. * PowerPC-64 Support added by Dave Engebretsen, Peter Bergner, and
  10. * Mike Corrigan {engebret|bergner|mikec}@us.ibm.com
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version
  15. * 2 of the License, or (at your option) any later version.
  16. */
  17. #undef DEBUG
  18. #include <linux/kernel.h>
  19. #include <linux/export.h>
  20. #include <linux/sched.h>
  21. #include <linux/smp.h>
  22. #include <linux/interrupt.h>
  23. #include <linux/delay.h>
  24. #include <linux/init.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/cache.h>
  27. #include <linux/err.h>
  28. #include <linux/device.h>
  29. #include <linux/cpu.h>
  30. #include <linux/notifier.h>
  31. #include <linux/topology.h>
  32. #include <asm/ptrace.h>
  33. #include <linux/atomic.h>
  34. #include <asm/irq.h>
  35. #include <asm/page.h>
  36. #include <asm/pgtable.h>
  37. #include <asm/prom.h>
  38. #include <asm/smp.h>
  39. #include <asm/time.h>
  40. #include <asm/machdep.h>
  41. #include <asm/cputhreads.h>
  42. #include <asm/cputable.h>
  43. #include <asm/mpic.h>
  44. #include <asm/vdso_datapage.h>
  45. #ifdef CONFIG_PPC64
  46. #include <asm/paca.h>
  47. #endif
  48. #include <asm/vdso.h>
  49. #include <asm/debug.h>
  50. #ifdef DEBUG
  51. #include <asm/udbg.h>
  52. #define DBG(fmt...) udbg_printf(fmt)
  53. #else
  54. #define DBG(fmt...)
  55. #endif
  56. #ifdef CONFIG_HOTPLUG_CPU
  57. /* State of each CPU during hotplug phases */
  58. static DEFINE_PER_CPU(int, cpu_state) = { 0 };
  59. #endif
  60. struct thread_info *secondary_ti;
  61. DEFINE_PER_CPU(cpumask_var_t, cpu_sibling_map);
  62. DEFINE_PER_CPU(cpumask_var_t, cpu_core_map);
  63. EXPORT_PER_CPU_SYMBOL(cpu_sibling_map);
  64. EXPORT_PER_CPU_SYMBOL(cpu_core_map);
  65. /* SMP operations for this machine */
  66. struct smp_ops_t *smp_ops;
  67. /* Can't be static due to PowerMac hackery */
  68. volatile unsigned int cpu_callin_map[NR_CPUS];
  69. int smt_enabled_at_boot = 1;
  70. static void (*crash_ipi_function_ptr)(struct pt_regs *) = NULL;
  71. #ifdef CONFIG_PPC64
  72. int smp_generic_kick_cpu(int nr)
  73. {
  74. BUG_ON(nr < 0 || nr >= NR_CPUS);
  75. /*
  76. * The processor is currently spinning, waiting for the
  77. * cpu_start field to become non-zero After we set cpu_start,
  78. * the processor will continue on to secondary_start
  79. */
  80. if (!paca[nr].cpu_start) {
  81. paca[nr].cpu_start = 1;
  82. smp_mb();
  83. return 0;
  84. }
  85. #ifdef CONFIG_HOTPLUG_CPU
  86. /*
  87. * Ok it's not there, so it might be soft-unplugged, let's
  88. * try to bring it back
  89. */
  90. generic_set_cpu_up(nr);
  91. smp_wmb();
  92. smp_send_reschedule(nr);
  93. #endif /* CONFIG_HOTPLUG_CPU */
  94. return 0;
  95. }
  96. #endif /* CONFIG_PPC64 */
  97. static irqreturn_t call_function_action(int irq, void *data)
  98. {
  99. generic_smp_call_function_interrupt();
  100. return IRQ_HANDLED;
  101. }
  102. static irqreturn_t reschedule_action(int irq, void *data)
  103. {
  104. scheduler_ipi();
  105. return IRQ_HANDLED;
  106. }
  107. static irqreturn_t call_function_single_action(int irq, void *data)
  108. {
  109. generic_smp_call_function_single_interrupt();
  110. return IRQ_HANDLED;
  111. }
  112. static irqreturn_t debug_ipi_action(int irq, void *data)
  113. {
  114. if (crash_ipi_function_ptr) {
  115. crash_ipi_function_ptr(get_irq_regs());
  116. return IRQ_HANDLED;
  117. }
  118. #ifdef CONFIG_DEBUGGER
  119. debugger_ipi(get_irq_regs());
  120. #endif /* CONFIG_DEBUGGER */
  121. return IRQ_HANDLED;
  122. }
  123. static irq_handler_t smp_ipi_action[] = {
  124. [PPC_MSG_CALL_FUNCTION] = call_function_action,
  125. [PPC_MSG_RESCHEDULE] = reschedule_action,
  126. [PPC_MSG_CALL_FUNC_SINGLE] = call_function_single_action,
  127. [PPC_MSG_DEBUGGER_BREAK] = debug_ipi_action,
  128. };
  129. const char *smp_ipi_name[] = {
  130. [PPC_MSG_CALL_FUNCTION] = "ipi call function",
  131. [PPC_MSG_RESCHEDULE] = "ipi reschedule",
  132. [PPC_MSG_CALL_FUNC_SINGLE] = "ipi call function single",
  133. [PPC_MSG_DEBUGGER_BREAK] = "ipi debugger",
  134. };
  135. /* optional function to request ipi, for controllers with >= 4 ipis */
  136. int smp_request_message_ipi(int virq, int msg)
  137. {
  138. int err;
  139. if (msg < 0 || msg > PPC_MSG_DEBUGGER_BREAK) {
  140. return -EINVAL;
  141. }
  142. #if !defined(CONFIG_DEBUGGER) && !defined(CONFIG_KEXEC)
  143. if (msg == PPC_MSG_DEBUGGER_BREAK) {
  144. return 1;
  145. }
  146. #endif
  147. err = request_irq(virq, smp_ipi_action[msg],
  148. IRQF_PERCPU | IRQF_NO_THREAD | IRQF_NO_SUSPEND,
  149. smp_ipi_name[msg], 0);
  150. WARN(err < 0, "unable to request_irq %d for %s (rc %d)\n",
  151. virq, smp_ipi_name[msg], err);
  152. return err;
  153. }
  154. #ifdef CONFIG_PPC_SMP_MUXED_IPI
  155. struct cpu_messages {
  156. int messages; /* current messages */
  157. unsigned long data; /* data for cause ipi */
  158. };
  159. static DEFINE_PER_CPU_SHARED_ALIGNED(struct cpu_messages, ipi_message);
  160. void smp_muxed_ipi_set_data(int cpu, unsigned long data)
  161. {
  162. struct cpu_messages *info = &per_cpu(ipi_message, cpu);
  163. info->data = data;
  164. }
  165. void smp_muxed_ipi_message_pass(int cpu, int msg)
  166. {
  167. struct cpu_messages *info = &per_cpu(ipi_message, cpu);
  168. char *message = (char *)&info->messages;
  169. /*
  170. * Order previous accesses before accesses in the IPI handler.
  171. */
  172. smp_mb();
  173. message[msg] = 1;
  174. /*
  175. * cause_ipi functions are required to include a full barrier
  176. * before doing whatever causes the IPI.
  177. */
  178. smp_ops->cause_ipi(cpu, info->data);
  179. }
  180. irqreturn_t smp_ipi_demux(void)
  181. {
  182. struct cpu_messages *info = &__get_cpu_var(ipi_message);
  183. unsigned int all;
  184. mb(); /* order any irq clear */
  185. do {
  186. all = xchg(&info->messages, 0);
  187. #ifdef __BIG_ENDIAN
  188. if (all & (1 << (24 - 8 * PPC_MSG_CALL_FUNCTION)))
  189. generic_smp_call_function_interrupt();
  190. if (all & (1 << (24 - 8 * PPC_MSG_RESCHEDULE)))
  191. scheduler_ipi();
  192. if (all & (1 << (24 - 8 * PPC_MSG_CALL_FUNC_SINGLE)))
  193. generic_smp_call_function_single_interrupt();
  194. if (all & (1 << (24 - 8 * PPC_MSG_DEBUGGER_BREAK)))
  195. debug_ipi_action(0, NULL);
  196. #else
  197. #error Unsupported ENDIAN
  198. #endif
  199. } while (info->messages);
  200. return IRQ_HANDLED;
  201. }
  202. #endif /* CONFIG_PPC_SMP_MUXED_IPI */
  203. static inline void do_message_pass(int cpu, int msg)
  204. {
  205. if (smp_ops->message_pass)
  206. smp_ops->message_pass(cpu, msg);
  207. #ifdef CONFIG_PPC_SMP_MUXED_IPI
  208. else
  209. smp_muxed_ipi_message_pass(cpu, msg);
  210. #endif
  211. }
  212. void smp_send_reschedule(int cpu)
  213. {
  214. if (likely(smp_ops))
  215. do_message_pass(cpu, PPC_MSG_RESCHEDULE);
  216. }
  217. EXPORT_SYMBOL_GPL(smp_send_reschedule);
  218. void arch_send_call_function_single_ipi(int cpu)
  219. {
  220. do_message_pass(cpu, PPC_MSG_CALL_FUNC_SINGLE);
  221. }
  222. void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  223. {
  224. unsigned int cpu;
  225. for_each_cpu(cpu, mask)
  226. do_message_pass(cpu, PPC_MSG_CALL_FUNCTION);
  227. }
  228. #if defined(CONFIG_DEBUGGER) || defined(CONFIG_KEXEC)
  229. void smp_send_debugger_break(void)
  230. {
  231. int cpu;
  232. int me = raw_smp_processor_id();
  233. if (unlikely(!smp_ops))
  234. return;
  235. for_each_online_cpu(cpu)
  236. if (cpu != me)
  237. do_message_pass(cpu, PPC_MSG_DEBUGGER_BREAK);
  238. }
  239. #endif
  240. #ifdef CONFIG_KEXEC
  241. void crash_send_ipi(void (*crash_ipi_callback)(struct pt_regs *))
  242. {
  243. crash_ipi_function_ptr = crash_ipi_callback;
  244. if (crash_ipi_callback) {
  245. mb();
  246. smp_send_debugger_break();
  247. }
  248. }
  249. #endif
  250. static void stop_this_cpu(void *dummy)
  251. {
  252. /* Remove this CPU */
  253. set_cpu_online(smp_processor_id(), false);
  254. local_irq_disable();
  255. while (1)
  256. ;
  257. }
  258. void smp_send_stop(void)
  259. {
  260. smp_call_function(stop_this_cpu, NULL, 0);
  261. }
  262. struct thread_info *current_set[NR_CPUS];
  263. static void smp_store_cpu_info(int id)
  264. {
  265. per_cpu(cpu_pvr, id) = mfspr(SPRN_PVR);
  266. #ifdef CONFIG_PPC_FSL_BOOK3E
  267. per_cpu(next_tlbcam_idx, id)
  268. = (mfspr(SPRN_TLB1CFG) & TLBnCFG_N_ENTRY) - 1;
  269. #endif
  270. }
  271. void __init smp_prepare_cpus(unsigned int max_cpus)
  272. {
  273. unsigned int cpu;
  274. DBG("smp_prepare_cpus\n");
  275. /*
  276. * setup_cpu may need to be called on the boot cpu. We havent
  277. * spun any cpus up but lets be paranoid.
  278. */
  279. BUG_ON(boot_cpuid != smp_processor_id());
  280. /* Fixup boot cpu */
  281. smp_store_cpu_info(boot_cpuid);
  282. cpu_callin_map[boot_cpuid] = 1;
  283. for_each_possible_cpu(cpu) {
  284. zalloc_cpumask_var_node(&per_cpu(cpu_sibling_map, cpu),
  285. GFP_KERNEL, cpu_to_node(cpu));
  286. zalloc_cpumask_var_node(&per_cpu(cpu_core_map, cpu),
  287. GFP_KERNEL, cpu_to_node(cpu));
  288. }
  289. cpumask_set_cpu(boot_cpuid, cpu_sibling_mask(boot_cpuid));
  290. cpumask_set_cpu(boot_cpuid, cpu_core_mask(boot_cpuid));
  291. if (smp_ops)
  292. if (smp_ops->probe)
  293. max_cpus = smp_ops->probe();
  294. else
  295. max_cpus = NR_CPUS;
  296. else
  297. max_cpus = 1;
  298. }
  299. void smp_prepare_boot_cpu(void)
  300. {
  301. BUG_ON(smp_processor_id() != boot_cpuid);
  302. #ifdef CONFIG_PPC64
  303. paca[boot_cpuid].__current = current;
  304. #endif
  305. current_set[boot_cpuid] = task_thread_info(current);
  306. }
  307. #ifdef CONFIG_HOTPLUG_CPU
  308. int generic_cpu_disable(void)
  309. {
  310. unsigned int cpu = smp_processor_id();
  311. if (cpu == boot_cpuid)
  312. return -EBUSY;
  313. set_cpu_online(cpu, false);
  314. #ifdef CONFIG_PPC64
  315. vdso_data->processorCount--;
  316. #endif
  317. migrate_irqs();
  318. return 0;
  319. }
  320. void generic_cpu_die(unsigned int cpu)
  321. {
  322. int i;
  323. for (i = 0; i < 100; i++) {
  324. smp_rmb();
  325. if (per_cpu(cpu_state, cpu) == CPU_DEAD)
  326. return;
  327. msleep(100);
  328. }
  329. printk(KERN_ERR "CPU%d didn't die...\n", cpu);
  330. }
  331. void generic_mach_cpu_die(void)
  332. {
  333. unsigned int cpu;
  334. local_irq_disable();
  335. idle_task_exit();
  336. cpu = smp_processor_id();
  337. printk(KERN_DEBUG "CPU%d offline\n", cpu);
  338. __get_cpu_var(cpu_state) = CPU_DEAD;
  339. smp_wmb();
  340. while (__get_cpu_var(cpu_state) != CPU_UP_PREPARE)
  341. cpu_relax();
  342. }
  343. void generic_set_cpu_dead(unsigned int cpu)
  344. {
  345. per_cpu(cpu_state, cpu) = CPU_DEAD;
  346. }
  347. /*
  348. * The cpu_state should be set to CPU_UP_PREPARE in kick_cpu(), otherwise
  349. * the cpu_state is always CPU_DEAD after calling generic_set_cpu_dead(),
  350. * which makes the delay in generic_cpu_die() not happen.
  351. */
  352. void generic_set_cpu_up(unsigned int cpu)
  353. {
  354. per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
  355. }
  356. int generic_check_cpu_restart(unsigned int cpu)
  357. {
  358. return per_cpu(cpu_state, cpu) == CPU_UP_PREPARE;
  359. }
  360. static atomic_t secondary_inhibit_count;
  361. /*
  362. * Don't allow secondary CPU threads to come online
  363. */
  364. void inhibit_secondary_onlining(void)
  365. {
  366. /*
  367. * This makes secondary_inhibit_count stable during cpu
  368. * online/offline operations.
  369. */
  370. get_online_cpus();
  371. atomic_inc(&secondary_inhibit_count);
  372. put_online_cpus();
  373. }
  374. EXPORT_SYMBOL_GPL(inhibit_secondary_onlining);
  375. /*
  376. * Allow secondary CPU threads to come online again
  377. */
  378. void uninhibit_secondary_onlining(void)
  379. {
  380. get_online_cpus();
  381. atomic_dec(&secondary_inhibit_count);
  382. put_online_cpus();
  383. }
  384. EXPORT_SYMBOL_GPL(uninhibit_secondary_onlining);
  385. static int secondaries_inhibited(void)
  386. {
  387. return atomic_read(&secondary_inhibit_count);
  388. }
  389. #else /* HOTPLUG_CPU */
  390. #define secondaries_inhibited() 0
  391. #endif
  392. static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle)
  393. {
  394. struct thread_info *ti = task_thread_info(idle);
  395. #ifdef CONFIG_PPC64
  396. paca[cpu].__current = idle;
  397. paca[cpu].kstack = (unsigned long)ti + THREAD_SIZE - STACK_FRAME_OVERHEAD;
  398. #endif
  399. ti->cpu = cpu;
  400. secondary_ti = current_set[cpu] = ti;
  401. }
  402. int __cpuinit __cpu_up(unsigned int cpu, struct task_struct *tidle)
  403. {
  404. int rc, c;
  405. /*
  406. * Don't allow secondary threads to come online if inhibited
  407. */
  408. if (threads_per_core > 1 && secondaries_inhibited() &&
  409. cpu % threads_per_core != 0)
  410. return -EBUSY;
  411. if (smp_ops == NULL ||
  412. (smp_ops->cpu_bootable && !smp_ops->cpu_bootable(cpu)))
  413. return -EINVAL;
  414. cpu_idle_thread_init(cpu, tidle);
  415. /* Make sure callin-map entry is 0 (can be leftover a CPU
  416. * hotplug
  417. */
  418. cpu_callin_map[cpu] = 0;
  419. /* The information for processor bringup must
  420. * be written out to main store before we release
  421. * the processor.
  422. */
  423. smp_mb();
  424. /* wake up cpus */
  425. DBG("smp: kicking cpu %d\n", cpu);
  426. rc = smp_ops->kick_cpu(cpu);
  427. if (rc) {
  428. pr_err("smp: failed starting cpu %d (rc %d)\n", cpu, rc);
  429. return rc;
  430. }
  431. /*
  432. * wait to see if the cpu made a callin (is actually up).
  433. * use this value that I found through experimentation.
  434. * -- Cort
  435. */
  436. if (system_state < SYSTEM_RUNNING)
  437. for (c = 50000; c && !cpu_callin_map[cpu]; c--)
  438. udelay(100);
  439. #ifdef CONFIG_HOTPLUG_CPU
  440. else
  441. /*
  442. * CPUs can take much longer to come up in the
  443. * hotplug case. Wait five seconds.
  444. */
  445. for (c = 5000; c && !cpu_callin_map[cpu]; c--)
  446. msleep(1);
  447. #endif
  448. if (!cpu_callin_map[cpu]) {
  449. printk(KERN_ERR "Processor %u is stuck.\n", cpu);
  450. return -ENOENT;
  451. }
  452. DBG("Processor %u found.\n", cpu);
  453. if (smp_ops->give_timebase)
  454. smp_ops->give_timebase();
  455. /* Wait until cpu puts itself in the online map */
  456. while (!cpu_online(cpu))
  457. cpu_relax();
  458. return 0;
  459. }
  460. /* Return the value of the reg property corresponding to the given
  461. * logical cpu.
  462. */
  463. int cpu_to_core_id(int cpu)
  464. {
  465. struct device_node *np;
  466. const int *reg;
  467. int id = -1;
  468. np = of_get_cpu_node(cpu, NULL);
  469. if (!np)
  470. goto out;
  471. reg = of_get_property(np, "reg", NULL);
  472. if (!reg)
  473. goto out;
  474. id = *reg;
  475. out:
  476. of_node_put(np);
  477. return id;
  478. }
  479. /* Helper routines for cpu to core mapping */
  480. int cpu_core_index_of_thread(int cpu)
  481. {
  482. return cpu >> threads_shift;
  483. }
  484. EXPORT_SYMBOL_GPL(cpu_core_index_of_thread);
  485. int cpu_first_thread_of_core(int core)
  486. {
  487. return core << threads_shift;
  488. }
  489. EXPORT_SYMBOL_GPL(cpu_first_thread_of_core);
  490. /* Must be called when no change can occur to cpu_present_mask,
  491. * i.e. during cpu online or offline.
  492. */
  493. static struct device_node *cpu_to_l2cache(int cpu)
  494. {
  495. struct device_node *np;
  496. struct device_node *cache;
  497. if (!cpu_present(cpu))
  498. return NULL;
  499. np = of_get_cpu_node(cpu, NULL);
  500. if (np == NULL)
  501. return NULL;
  502. cache = of_find_next_cache_node(np);
  503. of_node_put(np);
  504. return cache;
  505. }
  506. /* Activate a secondary processor. */
  507. __cpuinit void start_secondary(void *unused)
  508. {
  509. unsigned int cpu = smp_processor_id();
  510. struct device_node *l2_cache;
  511. int i, base;
  512. atomic_inc(&init_mm.mm_count);
  513. current->active_mm = &init_mm;
  514. smp_store_cpu_info(cpu);
  515. set_dec(tb_ticks_per_jiffy);
  516. preempt_disable();
  517. cpu_callin_map[cpu] = 1;
  518. if (smp_ops->setup_cpu)
  519. smp_ops->setup_cpu(cpu);
  520. if (smp_ops->take_timebase)
  521. smp_ops->take_timebase();
  522. secondary_cpu_time_init();
  523. #ifdef CONFIG_PPC64
  524. if (system_state == SYSTEM_RUNNING)
  525. vdso_data->processorCount++;
  526. vdso_getcpu_init();
  527. #endif
  528. notify_cpu_starting(cpu);
  529. set_cpu_online(cpu, true);
  530. /* Update sibling maps */
  531. base = cpu_first_thread_sibling(cpu);
  532. for (i = 0; i < threads_per_core; i++) {
  533. if (cpu_is_offline(base + i))
  534. continue;
  535. cpumask_set_cpu(cpu, cpu_sibling_mask(base + i));
  536. cpumask_set_cpu(base + i, cpu_sibling_mask(cpu));
  537. /* cpu_core_map should be a superset of
  538. * cpu_sibling_map even if we don't have cache
  539. * information, so update the former here, too.
  540. */
  541. cpumask_set_cpu(cpu, cpu_core_mask(base + i));
  542. cpumask_set_cpu(base + i, cpu_core_mask(cpu));
  543. }
  544. l2_cache = cpu_to_l2cache(cpu);
  545. for_each_online_cpu(i) {
  546. struct device_node *np = cpu_to_l2cache(i);
  547. if (!np)
  548. continue;
  549. if (np == l2_cache) {
  550. cpumask_set_cpu(cpu, cpu_core_mask(i));
  551. cpumask_set_cpu(i, cpu_core_mask(cpu));
  552. }
  553. of_node_put(np);
  554. }
  555. of_node_put(l2_cache);
  556. local_irq_enable();
  557. cpu_startup_entry(CPUHP_ONLINE);
  558. BUG();
  559. }
  560. int setup_profiling_timer(unsigned int multiplier)
  561. {
  562. return 0;
  563. }
  564. void __init smp_cpus_done(unsigned int max_cpus)
  565. {
  566. cpumask_var_t old_mask;
  567. /* We want the setup_cpu() here to be called from CPU 0, but our
  568. * init thread may have been "borrowed" by another CPU in the meantime
  569. * se we pin us down to CPU 0 for a short while
  570. */
  571. alloc_cpumask_var(&old_mask, GFP_NOWAIT);
  572. cpumask_copy(old_mask, tsk_cpus_allowed(current));
  573. set_cpus_allowed_ptr(current, cpumask_of(boot_cpuid));
  574. if (smp_ops && smp_ops->setup_cpu)
  575. smp_ops->setup_cpu(boot_cpuid);
  576. set_cpus_allowed_ptr(current, old_mask);
  577. free_cpumask_var(old_mask);
  578. if (smp_ops && smp_ops->bringup_done)
  579. smp_ops->bringup_done();
  580. dump_numa_cpu_topology();
  581. }
  582. int arch_sd_sibling_asym_packing(void)
  583. {
  584. if (cpu_has_feature(CPU_FTR_ASYM_SMT)) {
  585. printk_once(KERN_INFO "Enabling Asymmetric SMT scheduling\n");
  586. return SD_ASYM_PACKING;
  587. }
  588. return 0;
  589. }
  590. #ifdef CONFIG_HOTPLUG_CPU
  591. int __cpu_disable(void)
  592. {
  593. struct device_node *l2_cache;
  594. int cpu = smp_processor_id();
  595. int base, i;
  596. int err;
  597. if (!smp_ops->cpu_disable)
  598. return -ENOSYS;
  599. err = smp_ops->cpu_disable();
  600. if (err)
  601. return err;
  602. /* Update sibling maps */
  603. base = cpu_first_thread_sibling(cpu);
  604. for (i = 0; i < threads_per_core; i++) {
  605. cpumask_clear_cpu(cpu, cpu_sibling_mask(base + i));
  606. cpumask_clear_cpu(base + i, cpu_sibling_mask(cpu));
  607. cpumask_clear_cpu(cpu, cpu_core_mask(base + i));
  608. cpumask_clear_cpu(base + i, cpu_core_mask(cpu));
  609. }
  610. l2_cache = cpu_to_l2cache(cpu);
  611. for_each_present_cpu(i) {
  612. struct device_node *np = cpu_to_l2cache(i);
  613. if (!np)
  614. continue;
  615. if (np == l2_cache) {
  616. cpumask_clear_cpu(cpu, cpu_core_mask(i));
  617. cpumask_clear_cpu(i, cpu_core_mask(cpu));
  618. }
  619. of_node_put(np);
  620. }
  621. of_node_put(l2_cache);
  622. return 0;
  623. }
  624. void __cpu_die(unsigned int cpu)
  625. {
  626. if (smp_ops->cpu_die)
  627. smp_ops->cpu_die(cpu);
  628. }
  629. static DEFINE_MUTEX(powerpc_cpu_hotplug_driver_mutex);
  630. void cpu_hotplug_driver_lock()
  631. {
  632. mutex_lock(&powerpc_cpu_hotplug_driver_mutex);
  633. }
  634. void cpu_hotplug_driver_unlock()
  635. {
  636. mutex_unlock(&powerpc_cpu_hotplug_driver_mutex);
  637. }
  638. void cpu_die(void)
  639. {
  640. if (ppc_md.cpu_die)
  641. ppc_md.cpu_die();
  642. /* If we return, we re-enter start_secondary */
  643. start_secondary_resume();
  644. }
  645. #endif