smp.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840
  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. cpumask_set_cpu(boot_cpuid, cpu_sibling_mask(boot_cpuid));
  320. cpumask_set_cpu(boot_cpuid, cpu_core_mask(boot_cpuid));
  321. if (smp_ops && smp_ops->probe)
  322. smp_ops->probe();
  323. }
  324. void smp_prepare_boot_cpu(void)
  325. {
  326. BUG_ON(smp_processor_id() != boot_cpuid);
  327. #ifdef CONFIG_PPC64
  328. paca[boot_cpuid].__current = current;
  329. #endif
  330. set_numa_node(numa_cpu_lookup_table[boot_cpuid]);
  331. current_set[boot_cpuid] = task_thread_info(current);
  332. }
  333. #ifdef CONFIG_HOTPLUG_CPU
  334. int generic_cpu_disable(void)
  335. {
  336. unsigned int cpu = smp_processor_id();
  337. if (cpu == boot_cpuid)
  338. return -EBUSY;
  339. set_cpu_online(cpu, false);
  340. #ifdef CONFIG_PPC64
  341. vdso_data->processorCount--;
  342. #endif
  343. migrate_irqs();
  344. return 0;
  345. }
  346. void generic_cpu_die(unsigned int cpu)
  347. {
  348. int i;
  349. for (i = 0; i < 100; i++) {
  350. smp_rmb();
  351. if (per_cpu(cpu_state, cpu) == CPU_DEAD)
  352. return;
  353. msleep(100);
  354. }
  355. printk(KERN_ERR "CPU%d didn't die...\n", cpu);
  356. }
  357. void generic_mach_cpu_die(void)
  358. {
  359. unsigned int cpu;
  360. local_irq_disable();
  361. idle_task_exit();
  362. cpu = smp_processor_id();
  363. printk(KERN_DEBUG "CPU%d offline\n", cpu);
  364. __get_cpu_var(cpu_state) = CPU_DEAD;
  365. smp_wmb();
  366. while (__get_cpu_var(cpu_state) != CPU_UP_PREPARE)
  367. cpu_relax();
  368. }
  369. void generic_set_cpu_dead(unsigned int cpu)
  370. {
  371. per_cpu(cpu_state, cpu) = CPU_DEAD;
  372. }
  373. /*
  374. * The cpu_state should be set to CPU_UP_PREPARE in kick_cpu(), otherwise
  375. * the cpu_state is always CPU_DEAD after calling generic_set_cpu_dead(),
  376. * which makes the delay in generic_cpu_die() not happen.
  377. */
  378. void generic_set_cpu_up(unsigned int cpu)
  379. {
  380. per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
  381. }
  382. int generic_check_cpu_restart(unsigned int cpu)
  383. {
  384. return per_cpu(cpu_state, cpu) == CPU_UP_PREPARE;
  385. }
  386. static bool secondaries_inhibited(void)
  387. {
  388. return kvm_hv_mode_active();
  389. }
  390. #else /* HOTPLUG_CPU */
  391. #define secondaries_inhibited() 0
  392. #endif
  393. static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle)
  394. {
  395. struct thread_info *ti = task_thread_info(idle);
  396. #ifdef CONFIG_PPC64
  397. paca[cpu].__current = idle;
  398. paca[cpu].kstack = (unsigned long)ti + THREAD_SIZE - STACK_FRAME_OVERHEAD;
  399. #endif
  400. ti->cpu = cpu;
  401. secondary_ti = current_set[cpu] = ti;
  402. }
  403. int __cpu_up(unsigned int cpu, struct task_struct *tidle)
  404. {
  405. int rc, c;
  406. /*
  407. * Don't allow secondary threads to come online if inhibited
  408. */
  409. if (threads_per_core > 1 && secondaries_inhibited() &&
  410. cpu_thread_in_subcore(cpu))
  411. return -EBUSY;
  412. if (smp_ops == NULL ||
  413. (smp_ops->cpu_bootable && !smp_ops->cpu_bootable(cpu)))
  414. return -EINVAL;
  415. cpu_idle_thread_init(cpu, tidle);
  416. /* Make sure callin-map entry is 0 (can be leftover a CPU
  417. * hotplug
  418. */
  419. cpu_callin_map[cpu] = 0;
  420. /* The information for processor bringup must
  421. * be written out to main store before we release
  422. * the processor.
  423. */
  424. smp_mb();
  425. /* wake up cpus */
  426. DBG("smp: kicking cpu %d\n", cpu);
  427. rc = smp_ops->kick_cpu(cpu);
  428. if (rc) {
  429. pr_err("smp: failed starting cpu %d (rc %d)\n", cpu, rc);
  430. return rc;
  431. }
  432. /*
  433. * wait to see if the cpu made a callin (is actually up).
  434. * use this value that I found through experimentation.
  435. * -- Cort
  436. */
  437. if (system_state < SYSTEM_RUNNING)
  438. for (c = 50000; c && !cpu_callin_map[cpu]; c--)
  439. udelay(100);
  440. #ifdef CONFIG_HOTPLUG_CPU
  441. else
  442. /*
  443. * CPUs can take much longer to come up in the
  444. * hotplug case. Wait five seconds.
  445. */
  446. for (c = 5000; c && !cpu_callin_map[cpu]; c--)
  447. msleep(1);
  448. #endif
  449. if (!cpu_callin_map[cpu]) {
  450. printk(KERN_ERR "Processor %u is stuck.\n", cpu);
  451. return -ENOENT;
  452. }
  453. DBG("Processor %u found.\n", cpu);
  454. if (smp_ops->give_timebase)
  455. smp_ops->give_timebase();
  456. /* Wait until cpu puts itself in the online map */
  457. while (!cpu_online(cpu))
  458. cpu_relax();
  459. return 0;
  460. }
  461. /* Return the value of the reg property corresponding to the given
  462. * logical cpu.
  463. */
  464. int cpu_to_core_id(int cpu)
  465. {
  466. struct device_node *np;
  467. const __be32 *reg;
  468. int id = -1;
  469. np = of_get_cpu_node(cpu, NULL);
  470. if (!np)
  471. goto out;
  472. reg = of_get_property(np, "reg", NULL);
  473. if (!reg)
  474. goto out;
  475. id = be32_to_cpup(reg);
  476. out:
  477. of_node_put(np);
  478. return id;
  479. }
  480. /* Helper routines for cpu to core mapping */
  481. int cpu_core_index_of_thread(int cpu)
  482. {
  483. return cpu >> threads_shift;
  484. }
  485. EXPORT_SYMBOL_GPL(cpu_core_index_of_thread);
  486. int cpu_first_thread_of_core(int core)
  487. {
  488. return core << threads_shift;
  489. }
  490. EXPORT_SYMBOL_GPL(cpu_first_thread_of_core);
  491. static void traverse_siblings_chip_id(int cpu, bool add, int chipid)
  492. {
  493. const struct cpumask *mask;
  494. struct device_node *np;
  495. int i, plen;
  496. const __be32 *prop;
  497. mask = add ? cpu_online_mask : cpu_present_mask;
  498. for_each_cpu(i, mask) {
  499. np = of_get_cpu_node(i, NULL);
  500. if (!np)
  501. continue;
  502. prop = of_get_property(np, "ibm,chip-id", &plen);
  503. if (prop && plen == sizeof(int) &&
  504. of_read_number(prop, 1) == chipid) {
  505. if (add) {
  506. cpumask_set_cpu(cpu, cpu_core_mask(i));
  507. cpumask_set_cpu(i, cpu_core_mask(cpu));
  508. } else {
  509. cpumask_clear_cpu(cpu, cpu_core_mask(i));
  510. cpumask_clear_cpu(i, cpu_core_mask(cpu));
  511. }
  512. }
  513. of_node_put(np);
  514. }
  515. }
  516. /* Must be called when no change can occur to cpu_present_mask,
  517. * i.e. during cpu online or offline.
  518. */
  519. static struct device_node *cpu_to_l2cache(int cpu)
  520. {
  521. struct device_node *np;
  522. struct device_node *cache;
  523. if (!cpu_present(cpu))
  524. return NULL;
  525. np = of_get_cpu_node(cpu, NULL);
  526. if (np == NULL)
  527. return NULL;
  528. cache = of_find_next_cache_node(np);
  529. of_node_put(np);
  530. return cache;
  531. }
  532. static void traverse_core_siblings(int cpu, bool add)
  533. {
  534. struct device_node *l2_cache, *np;
  535. const struct cpumask *mask;
  536. int i, chip, plen;
  537. const __be32 *prop;
  538. /* First see if we have ibm,chip-id properties in cpu nodes */
  539. np = of_get_cpu_node(cpu, NULL);
  540. if (np) {
  541. chip = -1;
  542. prop = of_get_property(np, "ibm,chip-id", &plen);
  543. if (prop && plen == sizeof(int))
  544. chip = of_read_number(prop, 1);
  545. of_node_put(np);
  546. if (chip >= 0) {
  547. traverse_siblings_chip_id(cpu, add, chip);
  548. return;
  549. }
  550. }
  551. l2_cache = cpu_to_l2cache(cpu);
  552. mask = add ? cpu_online_mask : cpu_present_mask;
  553. for_each_cpu(i, mask) {
  554. np = cpu_to_l2cache(i);
  555. if (!np)
  556. continue;
  557. if (np == l2_cache) {
  558. if (add) {
  559. cpumask_set_cpu(cpu, cpu_core_mask(i));
  560. cpumask_set_cpu(i, cpu_core_mask(cpu));
  561. } else {
  562. cpumask_clear_cpu(cpu, cpu_core_mask(i));
  563. cpumask_clear_cpu(i, cpu_core_mask(cpu));
  564. }
  565. }
  566. of_node_put(np);
  567. }
  568. of_node_put(l2_cache);
  569. }
  570. /* Activate a secondary processor. */
  571. void start_secondary(void *unused)
  572. {
  573. unsigned int cpu = smp_processor_id();
  574. int i, base;
  575. atomic_inc(&init_mm.mm_count);
  576. current->active_mm = &init_mm;
  577. smp_store_cpu_info(cpu);
  578. set_dec(tb_ticks_per_jiffy);
  579. preempt_disable();
  580. cpu_callin_map[cpu] = 1;
  581. if (smp_ops->setup_cpu)
  582. smp_ops->setup_cpu(cpu);
  583. if (smp_ops->take_timebase)
  584. smp_ops->take_timebase();
  585. secondary_cpu_time_init();
  586. #ifdef CONFIG_PPC64
  587. if (system_state == SYSTEM_RUNNING)
  588. vdso_data->processorCount++;
  589. vdso_getcpu_init();
  590. #endif
  591. /* Update sibling maps */
  592. base = cpu_first_thread_sibling(cpu);
  593. for (i = 0; i < threads_per_core; i++) {
  594. if (cpu_is_offline(base + i) && (cpu != base + i))
  595. continue;
  596. cpumask_set_cpu(cpu, cpu_sibling_mask(base + i));
  597. cpumask_set_cpu(base + i, cpu_sibling_mask(cpu));
  598. /* cpu_core_map should be a superset of
  599. * cpu_sibling_map even if we don't have cache
  600. * information, so update the former here, too.
  601. */
  602. cpumask_set_cpu(cpu, cpu_core_mask(base + i));
  603. cpumask_set_cpu(base + i, cpu_core_mask(cpu));
  604. }
  605. traverse_core_siblings(cpu, true);
  606. /*
  607. * numa_node_id() works after this.
  608. */
  609. set_numa_node(numa_cpu_lookup_table[cpu]);
  610. set_numa_mem(local_memory_node(numa_cpu_lookup_table[cpu]));
  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