smp.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  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. #include <asm/virt.h>
  54. #define CREATE_TRACE_POINTS
  55. #include <trace/events/ipi.h>
  56. /*
  57. * as from 2.5, kernels no longer have an init_tasks structure
  58. * so we need some other way of telling a new secondary core
  59. * where to place its SVC stack
  60. */
  61. struct secondary_data secondary_data;
  62. enum ipi_msg_type {
  63. IPI_RESCHEDULE,
  64. IPI_CALL_FUNC,
  65. IPI_CPU_STOP,
  66. IPI_TIMER,
  67. IPI_IRQ_WORK,
  68. };
  69. /*
  70. * Boot a secondary CPU, and assign it the specified idle task.
  71. * This also gives us the initial stack to use for this CPU.
  72. */
  73. static int boot_secondary(unsigned int cpu, struct task_struct *idle)
  74. {
  75. if (cpu_ops[cpu]->cpu_boot)
  76. return cpu_ops[cpu]->cpu_boot(cpu);
  77. return -EOPNOTSUPP;
  78. }
  79. static DECLARE_COMPLETION(cpu_running);
  80. int __cpu_up(unsigned int cpu, struct task_struct *idle)
  81. {
  82. int ret;
  83. /*
  84. * We need to tell the secondary core where to find its stack and the
  85. * page tables.
  86. */
  87. secondary_data.stack = task_stack_page(idle) + THREAD_START_SP;
  88. __flush_dcache_area(&secondary_data, sizeof(secondary_data));
  89. /*
  90. * Now bring the CPU into our world.
  91. */
  92. ret = boot_secondary(cpu, idle);
  93. if (ret == 0) {
  94. /*
  95. * CPU was successfully started, wait for it to come online or
  96. * time out.
  97. */
  98. wait_for_completion_timeout(&cpu_running,
  99. msecs_to_jiffies(1000));
  100. if (!cpu_online(cpu)) {
  101. pr_crit("CPU%u: failed to come online\n", cpu);
  102. ret = -EIO;
  103. }
  104. } else {
  105. pr_err("CPU%u: failed to boot: %d\n", cpu, ret);
  106. }
  107. secondary_data.stack = NULL;
  108. return ret;
  109. }
  110. static void smp_store_cpu_info(unsigned int cpuid)
  111. {
  112. store_cpu_topology(cpuid);
  113. }
  114. /*
  115. * This is the secondary CPU boot entry. We're using this CPUs
  116. * idle thread stack, but a set of temporary page tables.
  117. */
  118. asmlinkage void secondary_start_kernel(void)
  119. {
  120. struct mm_struct *mm = &init_mm;
  121. unsigned int cpu = smp_processor_id();
  122. /*
  123. * All kernel threads share the same mm context; grab a
  124. * reference and switch to it.
  125. */
  126. atomic_inc(&mm->mm_count);
  127. current->active_mm = 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. local_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. irq_migrate_all_off_this_cpu();
  201. return 0;
  202. }
  203. static int op_cpu_kill(unsigned int cpu)
  204. {
  205. /*
  206. * If we have no means of synchronising with the dying CPU, then assume
  207. * that it is really dead. We can only wait for an arbitrary length of
  208. * time and hope that it's dead, so let's skip the wait and just hope.
  209. */
  210. if (!cpu_ops[cpu]->cpu_kill)
  211. return 0;
  212. return cpu_ops[cpu]->cpu_kill(cpu);
  213. }
  214. /*
  215. * called on the thread which is asking for a CPU to be shutdown -
  216. * waits until shutdown has completed, or it is timed out.
  217. */
  218. void __cpu_die(unsigned int cpu)
  219. {
  220. int err;
  221. if (!cpu_wait_death(cpu, 5)) {
  222. pr_crit("CPU%u: cpu didn't die\n", cpu);
  223. return;
  224. }
  225. pr_notice("CPU%u: shutdown\n", cpu);
  226. /*
  227. * Now that the dying CPU is beyond the point of no return w.r.t.
  228. * in-kernel synchronisation, try to get the firwmare to help us to
  229. * verify that it has really left the kernel before we consider
  230. * clobbering anything it might still be using.
  231. */
  232. err = op_cpu_kill(cpu);
  233. if (err)
  234. pr_warn("CPU%d may not have shut down cleanly: %d\n",
  235. cpu, err);
  236. }
  237. /*
  238. * Called from the idle thread for the CPU which has been shutdown.
  239. *
  240. * Note that we disable IRQs here, but do not re-enable them
  241. * before returning to the caller. This is also the behaviour
  242. * of the other hotplug-cpu capable cores, so presumably coming
  243. * out of idle fixes this.
  244. */
  245. void cpu_die(void)
  246. {
  247. unsigned int cpu = smp_processor_id();
  248. idle_task_exit();
  249. local_irq_disable();
  250. /* Tell __cpu_die() that this CPU is now safe to dispose of */
  251. (void)cpu_report_death();
  252. /*
  253. * Actually shutdown the CPU. This must never fail. The specific hotplug
  254. * mechanism must perform all required cache maintenance to ensure that
  255. * no dirty lines are lost in the process of shutting down the CPU.
  256. */
  257. cpu_ops[cpu]->cpu_die(cpu);
  258. BUG();
  259. }
  260. #endif
  261. static void __init hyp_mode_check(void)
  262. {
  263. if (is_hyp_mode_available())
  264. pr_info("CPU: All CPU(s) started at EL2\n");
  265. else if (is_hyp_mode_mismatched())
  266. WARN_TAINT(1, TAINT_CPU_OUT_OF_SPEC,
  267. "CPU: CPUs started in inconsistent modes");
  268. else
  269. pr_info("CPU: All CPU(s) started at EL1\n");
  270. }
  271. void __init smp_cpus_done(unsigned int max_cpus)
  272. {
  273. pr_info("SMP: Total of %d processors activated.\n", num_online_cpus());
  274. hyp_mode_check();
  275. apply_alternatives_all();
  276. }
  277. void __init smp_prepare_boot_cpu(void)
  278. {
  279. set_my_cpu_offset(per_cpu_offset(smp_processor_id()));
  280. }
  281. static u64 __init of_get_cpu_mpidr(struct device_node *dn)
  282. {
  283. const __be32 *cell;
  284. u64 hwid;
  285. /*
  286. * A cpu node with missing "reg" property is
  287. * considered invalid to build a cpu_logical_map
  288. * entry.
  289. */
  290. cell = of_get_property(dn, "reg", NULL);
  291. if (!cell) {
  292. pr_err("%s: missing reg property\n", dn->full_name);
  293. return INVALID_HWID;
  294. }
  295. hwid = of_read_number(cell, of_n_addr_cells(dn));
  296. /*
  297. * Non affinity bits must be set to 0 in the DT
  298. */
  299. if (hwid & ~MPIDR_HWID_BITMASK) {
  300. pr_err("%s: invalid reg property\n", dn->full_name);
  301. return INVALID_HWID;
  302. }
  303. return hwid;
  304. }
  305. /*
  306. * Duplicate MPIDRs are a recipe for disaster. Scan all initialized
  307. * entries and check for duplicates. If any is found just ignore the
  308. * cpu. cpu_logical_map was initialized to INVALID_HWID to avoid
  309. * matching valid MPIDR values.
  310. */
  311. static bool __init is_mpidr_duplicate(unsigned int cpu, u64 hwid)
  312. {
  313. unsigned int i;
  314. for (i = 1; (i < cpu) && (i < NR_CPUS); i++)
  315. if (cpu_logical_map(i) == hwid)
  316. return true;
  317. return false;
  318. }
  319. /*
  320. * Initialize cpu operations for a logical cpu and
  321. * set it in the possible mask on success
  322. */
  323. static int __init smp_cpu_setup(int cpu)
  324. {
  325. if (cpu_read_ops(cpu))
  326. return -ENODEV;
  327. if (cpu_ops[cpu]->cpu_init(cpu))
  328. return -ENODEV;
  329. set_cpu_possible(cpu, true);
  330. return 0;
  331. }
  332. static bool bootcpu_valid __initdata;
  333. static unsigned int cpu_count = 1;
  334. #ifdef CONFIG_ACPI
  335. /*
  336. * acpi_map_gic_cpu_interface - parse processor MADT entry
  337. *
  338. * Carry out sanity checks on MADT processor entry and initialize
  339. * cpu_logical_map on success
  340. */
  341. static void __init
  342. acpi_map_gic_cpu_interface(struct acpi_madt_generic_interrupt *processor)
  343. {
  344. u64 hwid = processor->arm_mpidr;
  345. if (!(processor->flags & ACPI_MADT_ENABLED)) {
  346. pr_debug("skipping disabled CPU entry with 0x%llx MPIDR\n", hwid);
  347. return;
  348. }
  349. if (hwid & ~MPIDR_HWID_BITMASK || hwid == INVALID_HWID) {
  350. pr_err("skipping CPU entry with invalid MPIDR 0x%llx\n", hwid);
  351. return;
  352. }
  353. if (is_mpidr_duplicate(cpu_count, hwid)) {
  354. pr_err("duplicate CPU MPIDR 0x%llx in MADT\n", hwid);
  355. return;
  356. }
  357. /* Check if GICC structure of boot CPU is available in the MADT */
  358. if (cpu_logical_map(0) == hwid) {
  359. if (bootcpu_valid) {
  360. pr_err("duplicate boot CPU MPIDR: 0x%llx in MADT\n",
  361. hwid);
  362. return;
  363. }
  364. bootcpu_valid = true;
  365. return;
  366. }
  367. if (cpu_count >= NR_CPUS)
  368. return;
  369. /* map the logical cpu id to cpu MPIDR */
  370. cpu_logical_map(cpu_count) = hwid;
  371. cpu_count++;
  372. }
  373. static int __init
  374. acpi_parse_gic_cpu_interface(struct acpi_subtable_header *header,
  375. const unsigned long end)
  376. {
  377. struct acpi_madt_generic_interrupt *processor;
  378. processor = (struct acpi_madt_generic_interrupt *)header;
  379. if (BAD_MADT_GICC_ENTRY(processor, end))
  380. return -EINVAL;
  381. acpi_table_print_madt_entry(header);
  382. acpi_map_gic_cpu_interface(processor);
  383. return 0;
  384. }
  385. #else
  386. #define acpi_table_parse_madt(...) do { } while (0)
  387. #endif
  388. /*
  389. * Enumerate the possible CPU set from the device tree and build the
  390. * cpu logical map array containing MPIDR values related to logical
  391. * cpus. Assumes that cpu_logical_map(0) has already been initialized.
  392. */
  393. void __init of_parse_and_init_cpus(void)
  394. {
  395. struct device_node *dn = NULL;
  396. while ((dn = of_find_node_by_type(dn, "cpu"))) {
  397. u64 hwid = of_get_cpu_mpidr(dn);
  398. if (hwid == INVALID_HWID)
  399. goto next;
  400. if (is_mpidr_duplicate(cpu_count, hwid)) {
  401. pr_err("%s: duplicate cpu reg properties in the DT\n",
  402. dn->full_name);
  403. goto next;
  404. }
  405. /*
  406. * The numbering scheme requires that the boot CPU
  407. * must be assigned logical id 0. Record it so that
  408. * the logical map built from DT is validated and can
  409. * be used.
  410. */
  411. if (hwid == cpu_logical_map(0)) {
  412. if (bootcpu_valid) {
  413. pr_err("%s: duplicate boot cpu reg property in DT\n",
  414. dn->full_name);
  415. goto next;
  416. }
  417. bootcpu_valid = true;
  418. /*
  419. * cpu_logical_map has already been
  420. * initialized and the boot cpu doesn't need
  421. * the enable-method so continue without
  422. * incrementing cpu.
  423. */
  424. continue;
  425. }
  426. if (cpu_count >= NR_CPUS)
  427. goto next;
  428. pr_debug("cpu logical map 0x%llx\n", hwid);
  429. cpu_logical_map(cpu_count) = hwid;
  430. next:
  431. cpu_count++;
  432. }
  433. }
  434. /*
  435. * Enumerate the possible CPU set from the device tree or ACPI and build the
  436. * cpu logical map array containing MPIDR values related to logical
  437. * cpus. Assumes that cpu_logical_map(0) has already been initialized.
  438. */
  439. void __init smp_init_cpus(void)
  440. {
  441. int i;
  442. if (acpi_disabled)
  443. of_parse_and_init_cpus();
  444. else
  445. /*
  446. * do a walk of MADT to determine how many CPUs
  447. * we have including disabled CPUs, and get information
  448. * we need for SMP init
  449. */
  450. acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT,
  451. acpi_parse_gic_cpu_interface, 0);
  452. if (cpu_count > NR_CPUS)
  453. pr_warn("no. of cores (%d) greater than configured maximum of %d - clipping\n",
  454. cpu_count, NR_CPUS);
  455. if (!bootcpu_valid) {
  456. pr_err("missing boot CPU MPIDR, not enabling secondaries\n");
  457. return;
  458. }
  459. /*
  460. * We need to set the cpu_logical_map entries before enabling
  461. * the cpus so that cpu processor description entries (DT cpu nodes
  462. * and ACPI MADT entries) can be retrieved by matching the cpu hwid
  463. * with entries in cpu_logical_map while initializing the cpus.
  464. * If the cpu set-up fails, invalidate the cpu_logical_map entry.
  465. */
  466. for (i = 1; i < NR_CPUS; i++) {
  467. if (cpu_logical_map(i) != INVALID_HWID) {
  468. if (smp_cpu_setup(i))
  469. cpu_logical_map(i) = INVALID_HWID;
  470. }
  471. }
  472. }
  473. void __init smp_prepare_cpus(unsigned int max_cpus)
  474. {
  475. int err;
  476. unsigned int cpu, ncores = num_possible_cpus();
  477. init_cpu_topology();
  478. smp_store_cpu_info(smp_processor_id());
  479. /*
  480. * are we trying to boot more cores than exist?
  481. */
  482. if (max_cpus > ncores)
  483. max_cpus = ncores;
  484. /* Don't bother if we're effectively UP */
  485. if (max_cpus <= 1)
  486. return;
  487. /*
  488. * Initialise the present map (which describes the set of CPUs
  489. * actually populated at the present time) and release the
  490. * secondaries from the bootloader.
  491. *
  492. * Make sure we online at most (max_cpus - 1) additional CPUs.
  493. */
  494. max_cpus--;
  495. for_each_possible_cpu(cpu) {
  496. if (max_cpus == 0)
  497. break;
  498. if (cpu == smp_processor_id())
  499. continue;
  500. if (!cpu_ops[cpu])
  501. continue;
  502. err = cpu_ops[cpu]->cpu_prepare(cpu);
  503. if (err)
  504. continue;
  505. set_cpu_present(cpu, true);
  506. max_cpus--;
  507. }
  508. }
  509. void (*__smp_cross_call)(const struct cpumask *, unsigned int);
  510. void __init set_smp_cross_call(void (*fn)(const struct cpumask *, unsigned int))
  511. {
  512. __smp_cross_call = fn;
  513. }
  514. static const char *ipi_types[NR_IPI] __tracepoint_string = {
  515. #define S(x,s) [x] = s
  516. S(IPI_RESCHEDULE, "Rescheduling interrupts"),
  517. S(IPI_CALL_FUNC, "Function call interrupts"),
  518. S(IPI_CPU_STOP, "CPU stop interrupts"),
  519. S(IPI_TIMER, "Timer broadcast interrupts"),
  520. S(IPI_IRQ_WORK, "IRQ work interrupts"),
  521. };
  522. static void smp_cross_call(const struct cpumask *target, unsigned int ipinr)
  523. {
  524. trace_ipi_raise(target, ipi_types[ipinr]);
  525. __smp_cross_call(target, ipinr);
  526. }
  527. void show_ipi_list(struct seq_file *p, int prec)
  528. {
  529. unsigned int cpu, i;
  530. for (i = 0; i < NR_IPI; i++) {
  531. seq_printf(p, "%*s%u:%s", prec - 1, "IPI", i,
  532. prec >= 4 ? " " : "");
  533. for_each_online_cpu(cpu)
  534. seq_printf(p, "%10u ",
  535. __get_irq_stat(cpu, ipi_irqs[i]));
  536. seq_printf(p, " %s\n", ipi_types[i]);
  537. }
  538. }
  539. u64 smp_irq_stat_cpu(unsigned int cpu)
  540. {
  541. u64 sum = 0;
  542. int i;
  543. for (i = 0; i < NR_IPI; i++)
  544. sum += __get_irq_stat(cpu, ipi_irqs[i]);
  545. return sum;
  546. }
  547. void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  548. {
  549. smp_cross_call(mask, IPI_CALL_FUNC);
  550. }
  551. void arch_send_call_function_single_ipi(int cpu)
  552. {
  553. smp_cross_call(cpumask_of(cpu), IPI_CALL_FUNC);
  554. }
  555. #ifdef CONFIG_IRQ_WORK
  556. void arch_irq_work_raise(void)
  557. {
  558. if (__smp_cross_call)
  559. smp_cross_call(cpumask_of(smp_processor_id()), IPI_IRQ_WORK);
  560. }
  561. #endif
  562. static DEFINE_RAW_SPINLOCK(stop_lock);
  563. /*
  564. * ipi_cpu_stop - handle IPI from smp_send_stop()
  565. */
  566. static void ipi_cpu_stop(unsigned int cpu)
  567. {
  568. if (system_state == SYSTEM_BOOTING ||
  569. system_state == SYSTEM_RUNNING) {
  570. raw_spin_lock(&stop_lock);
  571. pr_crit("CPU%u: stopping\n", cpu);
  572. dump_stack();
  573. raw_spin_unlock(&stop_lock);
  574. }
  575. set_cpu_online(cpu, false);
  576. local_irq_disable();
  577. while (1)
  578. cpu_relax();
  579. }
  580. /*
  581. * Main handler for inter-processor interrupts
  582. */
  583. void handle_IPI(int ipinr, struct pt_regs *regs)
  584. {
  585. unsigned int cpu = smp_processor_id();
  586. struct pt_regs *old_regs = set_irq_regs(regs);
  587. if ((unsigned)ipinr < NR_IPI) {
  588. trace_ipi_entry_rcuidle(ipi_types[ipinr]);
  589. __inc_irq_stat(cpu, ipi_irqs[ipinr]);
  590. }
  591. switch (ipinr) {
  592. case IPI_RESCHEDULE:
  593. scheduler_ipi();
  594. break;
  595. case IPI_CALL_FUNC:
  596. irq_enter();
  597. generic_smp_call_function_interrupt();
  598. irq_exit();
  599. break;
  600. case IPI_CPU_STOP:
  601. irq_enter();
  602. ipi_cpu_stop(cpu);
  603. irq_exit();
  604. break;
  605. #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  606. case IPI_TIMER:
  607. irq_enter();
  608. tick_receive_broadcast();
  609. irq_exit();
  610. break;
  611. #endif
  612. #ifdef CONFIG_IRQ_WORK
  613. case IPI_IRQ_WORK:
  614. irq_enter();
  615. irq_work_run();
  616. irq_exit();
  617. break;
  618. #endif
  619. default:
  620. pr_crit("CPU%u: Unknown IPI message 0x%x\n", cpu, ipinr);
  621. break;
  622. }
  623. if ((unsigned)ipinr < NR_IPI)
  624. trace_ipi_exit_rcuidle(ipi_types[ipinr]);
  625. set_irq_regs(old_regs);
  626. }
  627. void smp_send_reschedule(int cpu)
  628. {
  629. smp_cross_call(cpumask_of(cpu), IPI_RESCHEDULE);
  630. }
  631. #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  632. void tick_broadcast(const struct cpumask *mask)
  633. {
  634. smp_cross_call(mask, IPI_TIMER);
  635. }
  636. #endif
  637. void smp_send_stop(void)
  638. {
  639. unsigned long timeout;
  640. if (num_online_cpus() > 1) {
  641. cpumask_t mask;
  642. cpumask_copy(&mask, cpu_online_mask);
  643. cpumask_clear_cpu(smp_processor_id(), &mask);
  644. smp_cross_call(&mask, IPI_CPU_STOP);
  645. }
  646. /* Wait up to one second for other CPUs to stop */
  647. timeout = USEC_PER_SEC;
  648. while (num_online_cpus() > 1 && timeout--)
  649. udelay(1);
  650. if (num_online_cpus() > 1)
  651. pr_warning("SMP: failed to stop secondary CPUs\n");
  652. }
  653. /*
  654. * not supported here
  655. */
  656. int setup_profiling_timer(unsigned int multiplier)
  657. {
  658. return -EINVAL;
  659. }