smp.c 18 KB

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