smp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784
  1. /*
  2. * SMP initialisation and IPI support
  3. * Based on arch/arm/kernel/smp.c
  4. *
  5. * Copyright (C) 2012 ARM Ltd.
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #include <linux/acpi.h>
  20. #include <linux/delay.h>
  21. #include <linux/init.h>
  22. #include <linux/spinlock.h>
  23. #include <linux/sched.h>
  24. #include <linux/interrupt.h>
  25. #include <linux/cache.h>
  26. #include <linux/profile.h>
  27. #include <linux/errno.h>
  28. #include <linux/mm.h>
  29. #include <linux/err.h>
  30. #include <linux/cpu.h>
  31. #include <linux/smp.h>
  32. #include <linux/seq_file.h>
  33. #include <linux/irq.h>
  34. #include <linux/percpu.h>
  35. #include <linux/clockchips.h>
  36. #include <linux/completion.h>
  37. #include <linux/of.h>
  38. #include <linux/irq_work.h>
  39. #include <asm/alternative.h>
  40. #include <asm/atomic.h>
  41. #include <asm/cacheflush.h>
  42. #include <asm/cpu.h>
  43. #include <asm/cputype.h>
  44. #include <asm/cpu_ops.h>
  45. #include <asm/mmu_context.h>
  46. #include <asm/pgtable.h>
  47. #include <asm/pgalloc.h>
  48. #include <asm/processor.h>
  49. #include <asm/smp_plat.h>
  50. #include <asm/sections.h>
  51. #include <asm/tlbflush.h>
  52. #include <asm/ptrace.h>
  53. #define CREATE_TRACE_POINTS
  54. #include <trace/events/ipi.h>
  55. /*
  56. * as from 2.5, kernels no longer have an init_tasks structure
  57. * so we need some other way of telling a new secondary core
  58. * where to place its SVC stack
  59. */
  60. struct secondary_data secondary_data;
  61. enum ipi_msg_type {
  62. IPI_RESCHEDULE,
  63. IPI_CALL_FUNC,
  64. IPI_CPU_STOP,
  65. IPI_TIMER,
  66. IPI_IRQ_WORK,
  67. };
  68. /*
  69. * Boot a secondary CPU, and assign it the specified idle task.
  70. * This also gives us the initial stack to use for this CPU.
  71. */
  72. static int boot_secondary(unsigned int cpu, struct task_struct *idle)
  73. {
  74. if (cpu_ops[cpu]->cpu_boot)
  75. return cpu_ops[cpu]->cpu_boot(cpu);
  76. return -EOPNOTSUPP;
  77. }
  78. static DECLARE_COMPLETION(cpu_running);
  79. int __cpu_up(unsigned int cpu, struct task_struct *idle)
  80. {
  81. int ret;
  82. /*
  83. * We need to tell the secondary core where to find its stack and the
  84. * page tables.
  85. */
  86. secondary_data.stack = task_stack_page(idle) + THREAD_START_SP;
  87. __flush_dcache_area(&secondary_data, sizeof(secondary_data));
  88. /*
  89. * Now bring the CPU into our world.
  90. */
  91. ret = boot_secondary(cpu, idle);
  92. if (ret == 0) {
  93. /*
  94. * CPU was successfully started, wait for it to come online or
  95. * time out.
  96. */
  97. wait_for_completion_timeout(&cpu_running,
  98. msecs_to_jiffies(1000));
  99. if (!cpu_online(cpu)) {
  100. pr_crit("CPU%u: failed to come online\n", cpu);
  101. ret = -EIO;
  102. }
  103. } else {
  104. pr_err("CPU%u: failed to boot: %d\n", cpu, ret);
  105. }
  106. secondary_data.stack = NULL;
  107. return ret;
  108. }
  109. static void smp_store_cpu_info(unsigned int cpuid)
  110. {
  111. store_cpu_topology(cpuid);
  112. }
  113. /*
  114. * This is the secondary CPU boot entry. We're using this CPUs
  115. * idle thread stack, but a set of temporary page tables.
  116. */
  117. asmlinkage void secondary_start_kernel(void)
  118. {
  119. struct mm_struct *mm = &init_mm;
  120. unsigned int cpu = smp_processor_id();
  121. /*
  122. * All kernel threads share the same mm context; grab a
  123. * reference and switch to it.
  124. */
  125. atomic_inc(&mm->mm_count);
  126. current->active_mm = mm;
  127. cpumask_set_cpu(cpu, mm_cpumask(mm));
  128. set_my_cpu_offset(per_cpu_offset(smp_processor_id()));
  129. printk("CPU%u: Booted secondary processor\n", cpu);
  130. /*
  131. * TTBR0 is only used for the identity mapping at this stage. Make it
  132. * point to zero page to avoid speculatively fetching new entries.
  133. */
  134. cpu_set_reserved_ttbr0();
  135. flush_tlb_all();
  136. cpu_set_default_tcr_t0sz();
  137. preempt_disable();
  138. trace_hardirqs_off();
  139. if (cpu_ops[cpu]->cpu_postboot)
  140. cpu_ops[cpu]->cpu_postboot();
  141. /*
  142. * Log the CPU info before it is marked online and might get read.
  143. */
  144. cpuinfo_store_cpu();
  145. /*
  146. * Enable GIC and timers.
  147. */
  148. notify_cpu_starting(cpu);
  149. smp_store_cpu_info(cpu);
  150. /*
  151. * OK, now it's safe to let the boot CPU continue. Wait for
  152. * the CPU migration code to notice that the CPU is online
  153. * before we continue.
  154. */
  155. set_cpu_online(cpu, true);
  156. complete(&cpu_running);
  157. local_dbg_enable();
  158. local_irq_enable();
  159. local_async_enable();
  160. /*
  161. * OK, it's off to the idle thread for us
  162. */
  163. cpu_startup_entry(CPUHP_ONLINE);
  164. }
  165. #ifdef CONFIG_HOTPLUG_CPU
  166. static int op_cpu_disable(unsigned int cpu)
  167. {
  168. /*
  169. * If we don't have a cpu_die method, abort before we reach the point
  170. * of no return. CPU0 may not have an cpu_ops, so test for it.
  171. */
  172. if (!cpu_ops[cpu] || !cpu_ops[cpu]->cpu_die)
  173. return -EOPNOTSUPP;
  174. /*
  175. * We may need to abort a hot unplug for some other mechanism-specific
  176. * reason.
  177. */
  178. if (cpu_ops[cpu]->cpu_disable)
  179. return cpu_ops[cpu]->cpu_disable(cpu);
  180. return 0;
  181. }
  182. /*
  183. * __cpu_disable runs on the processor to be shutdown.
  184. */
  185. int __cpu_disable(void)
  186. {
  187. unsigned int cpu = smp_processor_id();
  188. int ret;
  189. ret = op_cpu_disable(cpu);
  190. if (ret)
  191. return ret;
  192. /*
  193. * Take this CPU offline. Once we clear this, we can't return,
  194. * and we must not schedule until we're ready to give up the cpu.
  195. */
  196. set_cpu_online(cpu, false);
  197. /*
  198. * OK - migrate IRQs away from this CPU
  199. */
  200. migrate_irqs();
  201. /*
  202. * Remove this CPU from the vm mask set of all processes.
  203. */
  204. clear_tasks_mm_cpumask(cpu);
  205. return 0;
  206. }
  207. static int op_cpu_kill(unsigned int cpu)
  208. {
  209. /*
  210. * If we have no means of synchronising with the dying CPU, then assume
  211. * that it is really dead. We can only wait for an arbitrary length of
  212. * time and hope that it's dead, so let's skip the wait and just hope.
  213. */
  214. if (!cpu_ops[cpu]->cpu_kill)
  215. return 0;
  216. return cpu_ops[cpu]->cpu_kill(cpu);
  217. }
  218. /*
  219. * called on the thread which is asking for a CPU to be shutdown -
  220. * waits until shutdown has completed, or it is timed out.
  221. */
  222. void __cpu_die(unsigned int cpu)
  223. {
  224. int err;
  225. if (!cpu_wait_death(cpu, 5)) {
  226. pr_crit("CPU%u: cpu didn't die\n", cpu);
  227. return;
  228. }
  229. pr_notice("CPU%u: shutdown\n", cpu);
  230. /*
  231. * Now that the dying CPU is beyond the point of no return w.r.t.
  232. * in-kernel synchronisation, try to get the firwmare to help us to
  233. * verify that it has really left the kernel before we consider
  234. * clobbering anything it might still be using.
  235. */
  236. err = op_cpu_kill(cpu);
  237. if (err)
  238. pr_warn("CPU%d may not have shut down cleanly: %d\n",
  239. cpu, err);
  240. }
  241. /*
  242. * Called from the idle thread for the CPU which has been shutdown.
  243. *
  244. * Note that we disable IRQs here, but do not re-enable them
  245. * before returning to the caller. This is also the behaviour
  246. * of the other hotplug-cpu capable cores, so presumably coming
  247. * out of idle fixes this.
  248. */
  249. void cpu_die(void)
  250. {
  251. unsigned int cpu = smp_processor_id();
  252. idle_task_exit();
  253. local_irq_disable();
  254. /* Tell __cpu_die() that this CPU is now safe to dispose of */
  255. (void)cpu_report_death();
  256. /*
  257. * Actually shutdown the CPU. This must never fail. The specific hotplug
  258. * mechanism must perform all required cache maintenance to ensure that
  259. * no dirty lines are lost in the process of shutting down the CPU.
  260. */
  261. cpu_ops[cpu]->cpu_die(cpu);
  262. BUG();
  263. }
  264. #endif
  265. void __init smp_cpus_done(unsigned int max_cpus)
  266. {
  267. pr_info("SMP: Total of %d processors activated.\n", num_online_cpus());
  268. do_post_cpus_up_work();
  269. }
  270. void __init smp_prepare_boot_cpu(void)
  271. {
  272. set_my_cpu_offset(per_cpu_offset(smp_processor_id()));
  273. }
  274. static u64 __init of_get_cpu_mpidr(struct device_node *dn)
  275. {
  276. const __be32 *cell;
  277. u64 hwid;
  278. /*
  279. * A cpu node with missing "reg" property is
  280. * considered invalid to build a cpu_logical_map
  281. * entry.
  282. */
  283. cell = of_get_property(dn, "reg", NULL);
  284. if (!cell) {
  285. pr_err("%s: missing reg property\n", dn->full_name);
  286. return INVALID_HWID;
  287. }
  288. hwid = of_read_number(cell, of_n_addr_cells(dn));
  289. /*
  290. * Non affinity bits must be set to 0 in the DT
  291. */
  292. if (hwid & ~MPIDR_HWID_BITMASK) {
  293. pr_err("%s: invalid reg property\n", dn->full_name);
  294. return INVALID_HWID;
  295. }
  296. return hwid;
  297. }
  298. /*
  299. * Duplicate MPIDRs are a recipe for disaster. Scan all initialized
  300. * entries and check for duplicates. If any is found just ignore the
  301. * cpu. cpu_logical_map was initialized to INVALID_HWID to avoid
  302. * matching valid MPIDR values.
  303. */
  304. static bool __init is_mpidr_duplicate(unsigned int cpu, u64 hwid)
  305. {
  306. unsigned int i;
  307. for (i = 1; (i < cpu) && (i < NR_CPUS); i++)
  308. if (cpu_logical_map(i) == hwid)
  309. return true;
  310. return false;
  311. }
  312. /*
  313. * Initialize cpu operations for a logical cpu and
  314. * set it in the possible mask on success
  315. */
  316. static int __init smp_cpu_setup(int cpu)
  317. {
  318. if (cpu_read_ops(cpu))
  319. return -ENODEV;
  320. if (cpu_ops[cpu]->cpu_init(cpu))
  321. return -ENODEV;
  322. set_cpu_possible(cpu, true);
  323. return 0;
  324. }
  325. static bool bootcpu_valid __initdata;
  326. static unsigned int cpu_count = 1;
  327. #ifdef CONFIG_ACPI
  328. /*
  329. * acpi_map_gic_cpu_interface - parse processor MADT entry
  330. *
  331. * Carry out sanity checks on MADT processor entry and initialize
  332. * cpu_logical_map on success
  333. */
  334. static void __init
  335. acpi_map_gic_cpu_interface(struct acpi_madt_generic_interrupt *processor)
  336. {
  337. u64 hwid = processor->arm_mpidr;
  338. if (!(processor->flags & ACPI_MADT_ENABLED)) {
  339. pr_debug("skipping disabled CPU entry with 0x%llx MPIDR\n", hwid);
  340. return;
  341. }
  342. if (hwid & ~MPIDR_HWID_BITMASK || hwid == INVALID_HWID) {
  343. pr_err("skipping CPU entry with invalid MPIDR 0x%llx\n", hwid);
  344. return;
  345. }
  346. if (is_mpidr_duplicate(cpu_count, hwid)) {
  347. pr_err("duplicate CPU MPIDR 0x%llx in MADT\n", hwid);
  348. return;
  349. }
  350. /* Check if GICC structure of boot CPU is available in the MADT */
  351. if (cpu_logical_map(0) == hwid) {
  352. if (bootcpu_valid) {
  353. pr_err("duplicate boot CPU MPIDR: 0x%llx in MADT\n",
  354. hwid);
  355. return;
  356. }
  357. bootcpu_valid = true;
  358. return;
  359. }
  360. if (cpu_count >= NR_CPUS)
  361. return;
  362. /* map the logical cpu id to cpu MPIDR */
  363. cpu_logical_map(cpu_count) = hwid;
  364. cpu_count++;
  365. }
  366. static int __init
  367. acpi_parse_gic_cpu_interface(struct acpi_subtable_header *header,
  368. const unsigned long end)
  369. {
  370. struct acpi_madt_generic_interrupt *processor;
  371. processor = (struct acpi_madt_generic_interrupt *)header;
  372. if (BAD_MADT_ENTRY(processor, end))
  373. return -EINVAL;
  374. acpi_table_print_madt_entry(header);
  375. acpi_map_gic_cpu_interface(processor);
  376. return 0;
  377. }
  378. #else
  379. #define acpi_table_parse_madt(...) do { } while (0)
  380. #endif
  381. /*
  382. * Enumerate the possible CPU set from the device tree and build the
  383. * cpu logical map array containing MPIDR values related to logical
  384. * cpus. Assumes that cpu_logical_map(0) has already been initialized.
  385. */
  386. void __init of_parse_and_init_cpus(void)
  387. {
  388. struct device_node *dn = NULL;
  389. while ((dn = of_find_node_by_type(dn, "cpu"))) {
  390. u64 hwid = of_get_cpu_mpidr(dn);
  391. if (hwid == INVALID_HWID)
  392. goto next;
  393. if (is_mpidr_duplicate(cpu_count, hwid)) {
  394. pr_err("%s: duplicate cpu reg properties in the DT\n",
  395. dn->full_name);
  396. goto next;
  397. }
  398. /*
  399. * The numbering scheme requires that the boot CPU
  400. * must be assigned logical id 0. Record it so that
  401. * the logical map built from DT is validated and can
  402. * be used.
  403. */
  404. if (hwid == cpu_logical_map(0)) {
  405. if (bootcpu_valid) {
  406. pr_err("%s: duplicate boot cpu reg property in DT\n",
  407. dn->full_name);
  408. goto next;
  409. }
  410. bootcpu_valid = true;
  411. /*
  412. * cpu_logical_map has already been
  413. * initialized and the boot cpu doesn't need
  414. * the enable-method so continue without
  415. * incrementing cpu.
  416. */
  417. continue;
  418. }
  419. if (cpu_count >= NR_CPUS)
  420. goto next;
  421. pr_debug("cpu logical map 0x%llx\n", hwid);
  422. cpu_logical_map(cpu_count) = hwid;
  423. next:
  424. cpu_count++;
  425. }
  426. }
  427. /*
  428. * Enumerate the possible CPU set from the device tree or ACPI and build the
  429. * cpu logical map array containing MPIDR values related to logical
  430. * cpus. Assumes that cpu_logical_map(0) has already been initialized.
  431. */
  432. void __init smp_init_cpus(void)
  433. {
  434. int i;
  435. if (acpi_disabled)
  436. of_parse_and_init_cpus();
  437. else
  438. /*
  439. * do a walk of MADT to determine how many CPUs
  440. * we have including disabled CPUs, and get information
  441. * we need for SMP init
  442. */
  443. acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT,
  444. acpi_parse_gic_cpu_interface, 0);
  445. if (cpu_count > NR_CPUS)
  446. pr_warn("no. of cores (%d) greater than configured maximum of %d - clipping\n",
  447. cpu_count, NR_CPUS);
  448. if (!bootcpu_valid) {
  449. pr_err("missing boot CPU MPIDR, not enabling secondaries\n");
  450. return;
  451. }
  452. /*
  453. * We need to set the cpu_logical_map entries before enabling
  454. * the cpus so that cpu processor description entries (DT cpu nodes
  455. * and ACPI MADT entries) can be retrieved by matching the cpu hwid
  456. * with entries in cpu_logical_map while initializing the cpus.
  457. * If the cpu set-up fails, invalidate the cpu_logical_map entry.
  458. */
  459. for (i = 1; i < NR_CPUS; i++) {
  460. if (cpu_logical_map(i) != INVALID_HWID) {
  461. if (smp_cpu_setup(i))
  462. cpu_logical_map(i) = INVALID_HWID;
  463. }
  464. }
  465. }
  466. void __init smp_prepare_cpus(unsigned int max_cpus)
  467. {
  468. int err;
  469. unsigned int cpu, ncores = num_possible_cpus();
  470. init_cpu_topology();
  471. smp_store_cpu_info(smp_processor_id());
  472. /*
  473. * are we trying to boot more cores than exist?
  474. */
  475. if (max_cpus > ncores)
  476. max_cpus = ncores;
  477. /* Don't bother if we're effectively UP */
  478. if (max_cpus <= 1)
  479. return;
  480. /*
  481. * Initialise the present map (which describes the set of CPUs
  482. * actually populated at the present time) and release the
  483. * secondaries from the bootloader.
  484. *
  485. * Make sure we online at most (max_cpus - 1) additional CPUs.
  486. */
  487. max_cpus--;
  488. for_each_possible_cpu(cpu) {
  489. if (max_cpus == 0)
  490. break;
  491. if (cpu == smp_processor_id())
  492. continue;
  493. if (!cpu_ops[cpu])
  494. continue;
  495. err = cpu_ops[cpu]->cpu_prepare(cpu);
  496. if (err)
  497. continue;
  498. set_cpu_present(cpu, true);
  499. max_cpus--;
  500. }
  501. }
  502. void (*__smp_cross_call)(const struct cpumask *, unsigned int);
  503. void __init set_smp_cross_call(void (*fn)(const struct cpumask *, unsigned int))
  504. {
  505. __smp_cross_call = fn;
  506. }
  507. static const char *ipi_types[NR_IPI] __tracepoint_string = {
  508. #define S(x,s) [x] = s
  509. S(IPI_RESCHEDULE, "Rescheduling interrupts"),
  510. S(IPI_CALL_FUNC, "Function call interrupts"),
  511. S(IPI_CPU_STOP, "CPU stop interrupts"),
  512. S(IPI_TIMER, "Timer broadcast interrupts"),
  513. S(IPI_IRQ_WORK, "IRQ work interrupts"),
  514. };
  515. static void smp_cross_call(const struct cpumask *target, unsigned int ipinr)
  516. {
  517. trace_ipi_raise(target, ipi_types[ipinr]);
  518. __smp_cross_call(target, ipinr);
  519. }
  520. void show_ipi_list(struct seq_file *p, int prec)
  521. {
  522. unsigned int cpu, i;
  523. for (i = 0; i < NR_IPI; i++) {
  524. seq_printf(p, "%*s%u:%s", prec - 1, "IPI", i,
  525. prec >= 4 ? " " : "");
  526. for_each_online_cpu(cpu)
  527. seq_printf(p, "%10u ",
  528. __get_irq_stat(cpu, ipi_irqs[i]));
  529. seq_printf(p, " %s\n", ipi_types[i]);
  530. }
  531. }
  532. u64 smp_irq_stat_cpu(unsigned int cpu)
  533. {
  534. u64 sum = 0;
  535. int i;
  536. for (i = 0; i < NR_IPI; i++)
  537. sum += __get_irq_stat(cpu, ipi_irqs[i]);
  538. return sum;
  539. }
  540. void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  541. {
  542. smp_cross_call(mask, IPI_CALL_FUNC);
  543. }
  544. void arch_send_call_function_single_ipi(int cpu)
  545. {
  546. smp_cross_call(cpumask_of(cpu), IPI_CALL_FUNC);
  547. }
  548. #ifdef CONFIG_IRQ_WORK
  549. void arch_irq_work_raise(void)
  550. {
  551. if (__smp_cross_call)
  552. smp_cross_call(cpumask_of(smp_processor_id()), IPI_IRQ_WORK);
  553. }
  554. #endif
  555. static DEFINE_RAW_SPINLOCK(stop_lock);
  556. /*
  557. * ipi_cpu_stop - handle IPI from smp_send_stop()
  558. */
  559. static void ipi_cpu_stop(unsigned int cpu)
  560. {
  561. if (system_state == SYSTEM_BOOTING ||
  562. system_state == SYSTEM_RUNNING) {
  563. raw_spin_lock(&stop_lock);
  564. pr_crit("CPU%u: stopping\n", cpu);
  565. dump_stack();
  566. raw_spin_unlock(&stop_lock);
  567. }
  568. set_cpu_online(cpu, false);
  569. local_irq_disable();
  570. while (1)
  571. cpu_relax();
  572. }
  573. /*
  574. * Main handler for inter-processor interrupts
  575. */
  576. void handle_IPI(int ipinr, struct pt_regs *regs)
  577. {
  578. unsigned int cpu = smp_processor_id();
  579. struct pt_regs *old_regs = set_irq_regs(regs);
  580. if ((unsigned)ipinr < NR_IPI) {
  581. trace_ipi_entry_rcuidle(ipi_types[ipinr]);
  582. __inc_irq_stat(cpu, ipi_irqs[ipinr]);
  583. }
  584. switch (ipinr) {
  585. case IPI_RESCHEDULE:
  586. scheduler_ipi();
  587. break;
  588. case IPI_CALL_FUNC:
  589. irq_enter();
  590. generic_smp_call_function_interrupt();
  591. irq_exit();
  592. break;
  593. case IPI_CPU_STOP:
  594. irq_enter();
  595. ipi_cpu_stop(cpu);
  596. irq_exit();
  597. break;
  598. #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  599. case IPI_TIMER:
  600. irq_enter();
  601. tick_receive_broadcast();
  602. irq_exit();
  603. break;
  604. #endif
  605. #ifdef CONFIG_IRQ_WORK
  606. case IPI_IRQ_WORK:
  607. irq_enter();
  608. irq_work_run();
  609. irq_exit();
  610. break;
  611. #endif
  612. default:
  613. pr_crit("CPU%u: Unknown IPI message 0x%x\n", cpu, ipinr);
  614. break;
  615. }
  616. if ((unsigned)ipinr < NR_IPI)
  617. trace_ipi_exit_rcuidle(ipi_types[ipinr]);
  618. set_irq_regs(old_regs);
  619. }
  620. void smp_send_reschedule(int cpu)
  621. {
  622. smp_cross_call(cpumask_of(cpu), IPI_RESCHEDULE);
  623. }
  624. #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  625. void tick_broadcast(const struct cpumask *mask)
  626. {
  627. smp_cross_call(mask, IPI_TIMER);
  628. }
  629. #endif
  630. void smp_send_stop(void)
  631. {
  632. unsigned long timeout;
  633. if (num_online_cpus() > 1) {
  634. cpumask_t mask;
  635. cpumask_copy(&mask, cpu_online_mask);
  636. cpumask_clear_cpu(smp_processor_id(), &mask);
  637. smp_cross_call(&mask, IPI_CPU_STOP);
  638. }
  639. /* Wait up to one second for other CPUs to stop */
  640. timeout = USEC_PER_SEC;
  641. while (num_online_cpus() > 1 && timeout--)
  642. udelay(1);
  643. if (num_online_cpus() > 1)
  644. pr_warning("SMP: failed to stop secondary CPUs\n");
  645. }
  646. /*
  647. * not supported here
  648. */
  649. int setup_profiling_timer(unsigned int multiplier)
  650. {
  651. return -EINVAL;
  652. }