smp.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  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 = &__get_cpu_var(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_mach_cpu_die(void)
  367. {
  368. unsigned int cpu;
  369. local_irq_disable();
  370. idle_task_exit();
  371. cpu = smp_processor_id();
  372. printk(KERN_DEBUG "CPU%d offline\n", cpu);
  373. __get_cpu_var(cpu_state) = CPU_DEAD;
  374. smp_wmb();
  375. while (__get_cpu_var(cpu_state) != CPU_UP_PREPARE)
  376. cpu_relax();
  377. }
  378. void generic_set_cpu_dead(unsigned int cpu)
  379. {
  380. per_cpu(cpu_state, cpu) = CPU_DEAD;
  381. }
  382. /*
  383. * The cpu_state should be set to CPU_UP_PREPARE in kick_cpu(), otherwise
  384. * the cpu_state is always CPU_DEAD after calling generic_set_cpu_dead(),
  385. * which makes the delay in generic_cpu_die() not happen.
  386. */
  387. void generic_set_cpu_up(unsigned int cpu)
  388. {
  389. per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
  390. }
  391. int generic_check_cpu_restart(unsigned int cpu)
  392. {
  393. return per_cpu(cpu_state, cpu) == CPU_UP_PREPARE;
  394. }
  395. static bool secondaries_inhibited(void)
  396. {
  397. return kvm_hv_mode_active();
  398. }
  399. #else /* HOTPLUG_CPU */
  400. #define secondaries_inhibited() 0
  401. #endif
  402. static void cpu_idle_thread_init(unsigned int cpu, struct task_struct *idle)
  403. {
  404. struct thread_info *ti = task_thread_info(idle);
  405. #ifdef CONFIG_PPC64
  406. paca[cpu].__current = idle;
  407. paca[cpu].kstack = (unsigned long)ti + THREAD_SIZE - STACK_FRAME_OVERHEAD;
  408. #endif
  409. ti->cpu = cpu;
  410. secondary_ti = current_set[cpu] = ti;
  411. }
  412. int __cpu_up(unsigned int cpu, struct task_struct *tidle)
  413. {
  414. int rc, c;
  415. /*
  416. * Don't allow secondary threads to come online if inhibited
  417. */
  418. if (threads_per_core > 1 && secondaries_inhibited() &&
  419. cpu_thread_in_subcore(cpu))
  420. return -EBUSY;
  421. if (smp_ops == NULL ||
  422. (smp_ops->cpu_bootable && !smp_ops->cpu_bootable(cpu)))
  423. return -EINVAL;
  424. cpu_idle_thread_init(cpu, tidle);
  425. /* Make sure callin-map entry is 0 (can be leftover a CPU
  426. * hotplug
  427. */
  428. cpu_callin_map[cpu] = 0;
  429. /* The information for processor bringup must
  430. * be written out to main store before we release
  431. * the processor.
  432. */
  433. smp_mb();
  434. /* wake up cpus */
  435. DBG("smp: kicking cpu %d\n", cpu);
  436. rc = smp_ops->kick_cpu(cpu);
  437. if (rc) {
  438. pr_err("smp: failed starting cpu %d (rc %d)\n", cpu, rc);
  439. return rc;
  440. }
  441. /*
  442. * wait to see if the cpu made a callin (is actually up).
  443. * use this value that I found through experimentation.
  444. * -- Cort
  445. */
  446. if (system_state < SYSTEM_RUNNING)
  447. for (c = 50000; c && !cpu_callin_map[cpu]; c--)
  448. udelay(100);
  449. #ifdef CONFIG_HOTPLUG_CPU
  450. else
  451. /*
  452. * CPUs can take much longer to come up in the
  453. * hotplug case. Wait five seconds.
  454. */
  455. for (c = 5000; c && !cpu_callin_map[cpu]; c--)
  456. msleep(1);
  457. #endif
  458. if (!cpu_callin_map[cpu]) {
  459. printk(KERN_ERR "Processor %u is stuck.\n", cpu);
  460. return -ENOENT;
  461. }
  462. DBG("Processor %u found.\n", cpu);
  463. if (smp_ops->give_timebase)
  464. smp_ops->give_timebase();
  465. /* Wait until cpu puts itself in the online map */
  466. while (!cpu_online(cpu))
  467. cpu_relax();
  468. return 0;
  469. }
  470. /* Return the value of the reg property corresponding to the given
  471. * logical cpu.
  472. */
  473. int cpu_to_core_id(int cpu)
  474. {
  475. struct device_node *np;
  476. const __be32 *reg;
  477. int id = -1;
  478. np = of_get_cpu_node(cpu, NULL);
  479. if (!np)
  480. goto out;
  481. reg = of_get_property(np, "reg", NULL);
  482. if (!reg)
  483. goto out;
  484. id = be32_to_cpup(reg);
  485. out:
  486. of_node_put(np);
  487. return id;
  488. }
  489. /* Helper routines for cpu to core mapping */
  490. int cpu_core_index_of_thread(int cpu)
  491. {
  492. return cpu >> threads_shift;
  493. }
  494. EXPORT_SYMBOL_GPL(cpu_core_index_of_thread);
  495. int cpu_first_thread_of_core(int core)
  496. {
  497. return core << threads_shift;
  498. }
  499. EXPORT_SYMBOL_GPL(cpu_first_thread_of_core);
  500. static void traverse_siblings_chip_id(int cpu, bool add, int chipid)
  501. {
  502. const struct cpumask *mask;
  503. struct device_node *np;
  504. int i, plen;
  505. const __be32 *prop;
  506. mask = add ? cpu_online_mask : cpu_present_mask;
  507. for_each_cpu(i, mask) {
  508. np = of_get_cpu_node(i, NULL);
  509. if (!np)
  510. continue;
  511. prop = of_get_property(np, "ibm,chip-id", &plen);
  512. if (prop && plen == sizeof(int) &&
  513. of_read_number(prop, 1) == chipid) {
  514. if (add) {
  515. cpumask_set_cpu(cpu, cpu_core_mask(i));
  516. cpumask_set_cpu(i, cpu_core_mask(cpu));
  517. } else {
  518. cpumask_clear_cpu(cpu, cpu_core_mask(i));
  519. cpumask_clear_cpu(i, cpu_core_mask(cpu));
  520. }
  521. }
  522. of_node_put(np);
  523. }
  524. }
  525. /* Must be called when no change can occur to cpu_present_mask,
  526. * i.e. during cpu online or offline.
  527. */
  528. static struct device_node *cpu_to_l2cache(int cpu)
  529. {
  530. struct device_node *np;
  531. struct device_node *cache;
  532. if (!cpu_present(cpu))
  533. return NULL;
  534. np = of_get_cpu_node(cpu, NULL);
  535. if (np == NULL)
  536. return NULL;
  537. cache = of_find_next_cache_node(np);
  538. of_node_put(np);
  539. return cache;
  540. }
  541. static void traverse_core_siblings(int cpu, bool add)
  542. {
  543. struct device_node *l2_cache, *np;
  544. const struct cpumask *mask;
  545. int i, chip, plen;
  546. const __be32 *prop;
  547. /* First see if we have ibm,chip-id properties in cpu nodes */
  548. np = of_get_cpu_node(cpu, NULL);
  549. if (np) {
  550. chip = -1;
  551. prop = of_get_property(np, "ibm,chip-id", &plen);
  552. if (prop && plen == sizeof(int))
  553. chip = of_read_number(prop, 1);
  554. of_node_put(np);
  555. if (chip >= 0) {
  556. traverse_siblings_chip_id(cpu, add, chip);
  557. return;
  558. }
  559. }
  560. l2_cache = cpu_to_l2cache(cpu);
  561. mask = add ? cpu_online_mask : cpu_present_mask;
  562. for_each_cpu(i, mask) {
  563. np = cpu_to_l2cache(i);
  564. if (!np)
  565. continue;
  566. if (np == l2_cache) {
  567. if (add) {
  568. cpumask_set_cpu(cpu, cpu_core_mask(i));
  569. cpumask_set_cpu(i, cpu_core_mask(cpu));
  570. } else {
  571. cpumask_clear_cpu(cpu, cpu_core_mask(i));
  572. cpumask_clear_cpu(i, cpu_core_mask(cpu));
  573. }
  574. }
  575. of_node_put(np);
  576. }
  577. of_node_put(l2_cache);
  578. }
  579. /* Activate a secondary processor. */
  580. void start_secondary(void *unused)
  581. {
  582. unsigned int cpu = smp_processor_id();
  583. int i, base;
  584. atomic_inc(&init_mm.mm_count);
  585. current->active_mm = &init_mm;
  586. smp_store_cpu_info(cpu);
  587. set_dec(tb_ticks_per_jiffy);
  588. preempt_disable();
  589. cpu_callin_map[cpu] = 1;
  590. if (smp_ops->setup_cpu)
  591. smp_ops->setup_cpu(cpu);
  592. if (smp_ops->take_timebase)
  593. smp_ops->take_timebase();
  594. secondary_cpu_time_init();
  595. #ifdef CONFIG_PPC64
  596. if (system_state == SYSTEM_RUNNING)
  597. vdso_data->processorCount++;
  598. vdso_getcpu_init();
  599. #endif
  600. /* Update sibling maps */
  601. base = cpu_first_thread_sibling(cpu);
  602. for (i = 0; i < threads_per_core; i++) {
  603. if (cpu_is_offline(base + i) && (cpu != base + i))
  604. continue;
  605. cpumask_set_cpu(cpu, cpu_sibling_mask(base + i));
  606. cpumask_set_cpu(base + i, cpu_sibling_mask(cpu));
  607. /* cpu_core_map should be a superset of
  608. * cpu_sibling_map even if we don't have cache
  609. * information, so update the former here, too.
  610. */
  611. cpumask_set_cpu(cpu, cpu_core_mask(base + i));
  612. cpumask_set_cpu(base + i, cpu_core_mask(cpu));
  613. }
  614. traverse_core_siblings(cpu, true);
  615. set_numa_node(numa_cpu_lookup_table[cpu]);
  616. set_numa_mem(local_memory_node(numa_cpu_lookup_table[cpu]));
  617. smp_wmb();
  618. notify_cpu_starting(cpu);
  619. set_cpu_online(cpu, true);
  620. local_irq_enable();
  621. cpu_startup_entry(CPUHP_ONLINE);
  622. BUG();
  623. }
  624. int setup_profiling_timer(unsigned int multiplier)
  625. {
  626. return 0;
  627. }
  628. #ifdef CONFIG_SCHED_SMT
  629. /* cpumask of CPUs with asymetric SMT dependancy */
  630. static int powerpc_smt_flags(void)
  631. {
  632. int flags = SD_SHARE_CPUCAPACITY | SD_SHARE_PKG_RESOURCES;
  633. if (cpu_has_feature(CPU_FTR_ASYM_SMT)) {
  634. printk_once(KERN_INFO "Enabling Asymmetric SMT scheduling\n");
  635. flags |= SD_ASYM_PACKING;
  636. }
  637. return flags;
  638. }
  639. #endif
  640. static struct sched_domain_topology_level powerpc_topology[] = {
  641. #ifdef CONFIG_SCHED_SMT
  642. { cpu_smt_mask, powerpc_smt_flags, SD_INIT_NAME(SMT) },
  643. #endif
  644. { cpu_cpu_mask, SD_INIT_NAME(DIE) },
  645. { NULL, },
  646. };
  647. void __init smp_cpus_done(unsigned int max_cpus)
  648. {
  649. cpumask_var_t old_mask;
  650. /* We want the setup_cpu() here to be called from CPU 0, but our
  651. * init thread may have been "borrowed" by another CPU in the meantime
  652. * se we pin us down to CPU 0 for a short while
  653. */
  654. alloc_cpumask_var(&old_mask, GFP_NOWAIT);
  655. cpumask_copy(old_mask, tsk_cpus_allowed(current));
  656. set_cpus_allowed_ptr(current, cpumask_of(boot_cpuid));
  657. if (smp_ops && smp_ops->setup_cpu)
  658. smp_ops->setup_cpu(boot_cpuid);
  659. set_cpus_allowed_ptr(current, old_mask);
  660. free_cpumask_var(old_mask);
  661. if (smp_ops && smp_ops->bringup_done)
  662. smp_ops->bringup_done();
  663. dump_numa_cpu_topology();
  664. set_sched_topology(powerpc_topology);
  665. }
  666. #ifdef CONFIG_HOTPLUG_CPU
  667. int __cpu_disable(void)
  668. {
  669. int cpu = smp_processor_id();
  670. int base, i;
  671. int err;
  672. if (!smp_ops->cpu_disable)
  673. return -ENOSYS;
  674. err = smp_ops->cpu_disable();
  675. if (err)
  676. return err;
  677. /* Update sibling maps */
  678. base = cpu_first_thread_sibling(cpu);
  679. for (i = 0; i < threads_per_core; i++) {
  680. cpumask_clear_cpu(cpu, cpu_sibling_mask(base + i));
  681. cpumask_clear_cpu(base + i, cpu_sibling_mask(cpu));
  682. cpumask_clear_cpu(cpu, cpu_core_mask(base + i));
  683. cpumask_clear_cpu(base + i, cpu_core_mask(cpu));
  684. }
  685. traverse_core_siblings(cpu, false);
  686. return 0;
  687. }
  688. void __cpu_die(unsigned int cpu)
  689. {
  690. if (smp_ops->cpu_die)
  691. smp_ops->cpu_die(cpu);
  692. }
  693. void cpu_die(void)
  694. {
  695. if (ppc_md.cpu_die)
  696. ppc_md.cpu_die();
  697. /* If we return, we re-enter start_secondary */
  698. start_secondary_resume();
  699. }
  700. #endif