smp.c 18 KB

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