smp.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796
  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. cpumask_set_cpu(cpu, mm_cpumask(mm));
  129. set_my_cpu_offset(per_cpu_offset(smp_processor_id()));
  130. printk("CPU%u: Booted secondary processor\n", cpu);
  131. /*
  132. * TTBR0 is only used for the identity mapping at this stage. Make it
  133. * point to zero page to avoid speculatively fetching new entries.
  134. */
  135. cpu_set_reserved_ttbr0();
  136. flush_tlb_all();
  137. cpu_set_default_tcr_t0sz();
  138. preempt_disable();
  139. trace_hardirqs_off();
  140. if (cpu_ops[cpu]->cpu_postboot)
  141. cpu_ops[cpu]->cpu_postboot();
  142. /*
  143. * Log the CPU info before it is marked online and might get read.
  144. */
  145. cpuinfo_store_cpu();
  146. /*
  147. * Enable GIC and timers.
  148. */
  149. notify_cpu_starting(cpu);
  150. smp_store_cpu_info(cpu);
  151. /*
  152. * OK, now it's safe to let the boot CPU continue. Wait for
  153. * the CPU migration code to notice that the CPU is online
  154. * before we continue.
  155. */
  156. set_cpu_online(cpu, true);
  157. complete(&cpu_running);
  158. local_dbg_enable();
  159. local_irq_enable();
  160. local_async_enable();
  161. /*
  162. * OK, it's off to the idle thread for us
  163. */
  164. cpu_startup_entry(CPUHP_ONLINE);
  165. }
  166. #ifdef CONFIG_HOTPLUG_CPU
  167. static int op_cpu_disable(unsigned int cpu)
  168. {
  169. /*
  170. * If we don't have a cpu_die method, abort before we reach the point
  171. * of no return. CPU0 may not have an cpu_ops, so test for it.
  172. */
  173. if (!cpu_ops[cpu] || !cpu_ops[cpu]->cpu_die)
  174. return -EOPNOTSUPP;
  175. /*
  176. * We may need to abort a hot unplug for some other mechanism-specific
  177. * reason.
  178. */
  179. if (cpu_ops[cpu]->cpu_disable)
  180. return cpu_ops[cpu]->cpu_disable(cpu);
  181. return 0;
  182. }
  183. /*
  184. * __cpu_disable runs on the processor to be shutdown.
  185. */
  186. int __cpu_disable(void)
  187. {
  188. unsigned int cpu = smp_processor_id();
  189. int ret;
  190. ret = op_cpu_disable(cpu);
  191. if (ret)
  192. return ret;
  193. /*
  194. * Take this CPU offline. Once we clear this, we can't return,
  195. * and we must not schedule until we're ready to give up the cpu.
  196. */
  197. set_cpu_online(cpu, false);
  198. /*
  199. * OK - migrate IRQs away from this CPU
  200. */
  201. migrate_irqs();
  202. /*
  203. * Remove this CPU from the vm mask set of all processes.
  204. */
  205. clear_tasks_mm_cpumask(cpu);
  206. return 0;
  207. }
  208. static int op_cpu_kill(unsigned int cpu)
  209. {
  210. /*
  211. * If we have no means of synchronising with the dying CPU, then assume
  212. * that it is really dead. We can only wait for an arbitrary length of
  213. * time and hope that it's dead, so let's skip the wait and just hope.
  214. */
  215. if (!cpu_ops[cpu]->cpu_kill)
  216. return 0;
  217. return cpu_ops[cpu]->cpu_kill(cpu);
  218. }
  219. /*
  220. * called on the thread which is asking for a CPU to be shutdown -
  221. * waits until shutdown has completed, or it is timed out.
  222. */
  223. void __cpu_die(unsigned int cpu)
  224. {
  225. int err;
  226. if (!cpu_wait_death(cpu, 5)) {
  227. pr_crit("CPU%u: cpu didn't die\n", cpu);
  228. return;
  229. }
  230. pr_notice("CPU%u: shutdown\n", cpu);
  231. /*
  232. * Now that the dying CPU is beyond the point of no return w.r.t.
  233. * in-kernel synchronisation, try to get the firwmare to help us to
  234. * verify that it has really left the kernel before we consider
  235. * clobbering anything it might still be using.
  236. */
  237. err = op_cpu_kill(cpu);
  238. if (err)
  239. pr_warn("CPU%d may not have shut down cleanly: %d\n",
  240. cpu, err);
  241. }
  242. /*
  243. * Called from the idle thread for the CPU which has been shutdown.
  244. *
  245. * Note that we disable IRQs here, but do not re-enable them
  246. * before returning to the caller. This is also the behaviour
  247. * of the other hotplug-cpu capable cores, so presumably coming
  248. * out of idle fixes this.
  249. */
  250. void cpu_die(void)
  251. {
  252. unsigned int cpu = smp_processor_id();
  253. idle_task_exit();
  254. local_irq_disable();
  255. /* Tell __cpu_die() that this CPU is now safe to dispose of */
  256. (void)cpu_report_death();
  257. /*
  258. * Actually shutdown the CPU. This must never fail. The specific hotplug
  259. * mechanism must perform all required cache maintenance to ensure that
  260. * no dirty lines are lost in the process of shutting down the CPU.
  261. */
  262. cpu_ops[cpu]->cpu_die(cpu);
  263. BUG();
  264. }
  265. #endif
  266. static void __init hyp_mode_check(void)
  267. {
  268. if (is_hyp_mode_available())
  269. pr_info("CPU: All CPU(s) started at EL2\n");
  270. else if (is_hyp_mode_mismatched())
  271. WARN_TAINT(1, TAINT_CPU_OUT_OF_SPEC,
  272. "CPU: CPUs started in inconsistent modes");
  273. else
  274. pr_info("CPU: All CPU(s) started at EL1\n");
  275. }
  276. void __init smp_cpus_done(unsigned int max_cpus)
  277. {
  278. pr_info("SMP: Total of %d processors activated.\n", num_online_cpus());
  279. hyp_mode_check();
  280. apply_alternatives_all();
  281. }
  282. void __init smp_prepare_boot_cpu(void)
  283. {
  284. set_my_cpu_offset(per_cpu_offset(smp_processor_id()));
  285. }
  286. static u64 __init of_get_cpu_mpidr(struct device_node *dn)
  287. {
  288. const __be32 *cell;
  289. u64 hwid;
  290. /*
  291. * A cpu node with missing "reg" property is
  292. * considered invalid to build a cpu_logical_map
  293. * entry.
  294. */
  295. cell = of_get_property(dn, "reg", NULL);
  296. if (!cell) {
  297. pr_err("%s: missing reg property\n", dn->full_name);
  298. return INVALID_HWID;
  299. }
  300. hwid = of_read_number(cell, of_n_addr_cells(dn));
  301. /*
  302. * Non affinity bits must be set to 0 in the DT
  303. */
  304. if (hwid & ~MPIDR_HWID_BITMASK) {
  305. pr_err("%s: invalid reg property\n", dn->full_name);
  306. return INVALID_HWID;
  307. }
  308. return hwid;
  309. }
  310. /*
  311. * Duplicate MPIDRs are a recipe for disaster. Scan all initialized
  312. * entries and check for duplicates. If any is found just ignore the
  313. * cpu. cpu_logical_map was initialized to INVALID_HWID to avoid
  314. * matching valid MPIDR values.
  315. */
  316. static bool __init is_mpidr_duplicate(unsigned int cpu, u64 hwid)
  317. {
  318. unsigned int i;
  319. for (i = 1; (i < cpu) && (i < NR_CPUS); i++)
  320. if (cpu_logical_map(i) == hwid)
  321. return true;
  322. return false;
  323. }
  324. /*
  325. * Initialize cpu operations for a logical cpu and
  326. * set it in the possible mask on success
  327. */
  328. static int __init smp_cpu_setup(int cpu)
  329. {
  330. if (cpu_read_ops(cpu))
  331. return -ENODEV;
  332. if (cpu_ops[cpu]->cpu_init(cpu))
  333. return -ENODEV;
  334. set_cpu_possible(cpu, true);
  335. return 0;
  336. }
  337. static bool bootcpu_valid __initdata;
  338. static unsigned int cpu_count = 1;
  339. #ifdef CONFIG_ACPI
  340. /*
  341. * acpi_map_gic_cpu_interface - parse processor MADT entry
  342. *
  343. * Carry out sanity checks on MADT processor entry and initialize
  344. * cpu_logical_map on success
  345. */
  346. static void __init
  347. acpi_map_gic_cpu_interface(struct acpi_madt_generic_interrupt *processor)
  348. {
  349. u64 hwid = processor->arm_mpidr;
  350. if (!(processor->flags & ACPI_MADT_ENABLED)) {
  351. pr_debug("skipping disabled CPU entry with 0x%llx MPIDR\n", hwid);
  352. return;
  353. }
  354. if (hwid & ~MPIDR_HWID_BITMASK || hwid == INVALID_HWID) {
  355. pr_err("skipping CPU entry with invalid MPIDR 0x%llx\n", hwid);
  356. return;
  357. }
  358. if (is_mpidr_duplicate(cpu_count, hwid)) {
  359. pr_err("duplicate CPU MPIDR 0x%llx in MADT\n", hwid);
  360. return;
  361. }
  362. /* Check if GICC structure of boot CPU is available in the MADT */
  363. if (cpu_logical_map(0) == hwid) {
  364. if (bootcpu_valid) {
  365. pr_err("duplicate boot CPU MPIDR: 0x%llx in MADT\n",
  366. hwid);
  367. return;
  368. }
  369. bootcpu_valid = true;
  370. return;
  371. }
  372. if (cpu_count >= NR_CPUS)
  373. return;
  374. /* map the logical cpu id to cpu MPIDR */
  375. cpu_logical_map(cpu_count) = hwid;
  376. cpu_count++;
  377. }
  378. static int __init
  379. acpi_parse_gic_cpu_interface(struct acpi_subtable_header *header,
  380. const unsigned long end)
  381. {
  382. struct acpi_madt_generic_interrupt *processor;
  383. processor = (struct acpi_madt_generic_interrupt *)header;
  384. if (BAD_MADT_GICC_ENTRY(processor, end))
  385. return -EINVAL;
  386. acpi_table_print_madt_entry(header);
  387. acpi_map_gic_cpu_interface(processor);
  388. return 0;
  389. }
  390. #else
  391. #define acpi_table_parse_madt(...) do { } while (0)
  392. #endif
  393. /*
  394. * Enumerate the possible CPU set from the device tree and build the
  395. * cpu logical map array containing MPIDR values related to logical
  396. * cpus. Assumes that cpu_logical_map(0) has already been initialized.
  397. */
  398. void __init of_parse_and_init_cpus(void)
  399. {
  400. struct device_node *dn = NULL;
  401. while ((dn = of_find_node_by_type(dn, "cpu"))) {
  402. u64 hwid = of_get_cpu_mpidr(dn);
  403. if (hwid == INVALID_HWID)
  404. goto next;
  405. if (is_mpidr_duplicate(cpu_count, hwid)) {
  406. pr_err("%s: duplicate cpu reg properties in the DT\n",
  407. dn->full_name);
  408. goto next;
  409. }
  410. /*
  411. * The numbering scheme requires that the boot CPU
  412. * must be assigned logical id 0. Record it so that
  413. * the logical map built from DT is validated and can
  414. * be used.
  415. */
  416. if (hwid == cpu_logical_map(0)) {
  417. if (bootcpu_valid) {
  418. pr_err("%s: duplicate boot cpu reg property in DT\n",
  419. dn->full_name);
  420. goto next;
  421. }
  422. bootcpu_valid = true;
  423. /*
  424. * cpu_logical_map has already been
  425. * initialized and the boot cpu doesn't need
  426. * the enable-method so continue without
  427. * incrementing cpu.
  428. */
  429. continue;
  430. }
  431. if (cpu_count >= NR_CPUS)
  432. goto next;
  433. pr_debug("cpu logical map 0x%llx\n", hwid);
  434. cpu_logical_map(cpu_count) = hwid;
  435. next:
  436. cpu_count++;
  437. }
  438. }
  439. /*
  440. * Enumerate the possible CPU set from the device tree or ACPI and build the
  441. * cpu logical map array containing MPIDR values related to logical
  442. * cpus. Assumes that cpu_logical_map(0) has already been initialized.
  443. */
  444. void __init smp_init_cpus(void)
  445. {
  446. int i;
  447. if (acpi_disabled)
  448. of_parse_and_init_cpus();
  449. else
  450. /*
  451. * do a walk of MADT to determine how many CPUs
  452. * we have including disabled CPUs, and get information
  453. * we need for SMP init
  454. */
  455. acpi_table_parse_madt(ACPI_MADT_TYPE_GENERIC_INTERRUPT,
  456. acpi_parse_gic_cpu_interface, 0);
  457. if (cpu_count > NR_CPUS)
  458. pr_warn("no. of cores (%d) greater than configured maximum of %d - clipping\n",
  459. cpu_count, NR_CPUS);
  460. if (!bootcpu_valid) {
  461. pr_err("missing boot CPU MPIDR, not enabling secondaries\n");
  462. return;
  463. }
  464. /*
  465. * We need to set the cpu_logical_map entries before enabling
  466. * the cpus so that cpu processor description entries (DT cpu nodes
  467. * and ACPI MADT entries) can be retrieved by matching the cpu hwid
  468. * with entries in cpu_logical_map while initializing the cpus.
  469. * If the cpu set-up fails, invalidate the cpu_logical_map entry.
  470. */
  471. for (i = 1; i < NR_CPUS; i++) {
  472. if (cpu_logical_map(i) != INVALID_HWID) {
  473. if (smp_cpu_setup(i))
  474. cpu_logical_map(i) = INVALID_HWID;
  475. }
  476. }
  477. }
  478. void __init smp_prepare_cpus(unsigned int max_cpus)
  479. {
  480. int err;
  481. unsigned int cpu, ncores = num_possible_cpus();
  482. init_cpu_topology();
  483. smp_store_cpu_info(smp_processor_id());
  484. /*
  485. * are we trying to boot more cores than exist?
  486. */
  487. if (max_cpus > ncores)
  488. max_cpus = ncores;
  489. /* Don't bother if we're effectively UP */
  490. if (max_cpus <= 1)
  491. return;
  492. /*
  493. * Initialise the present map (which describes the set of CPUs
  494. * actually populated at the present time) and release the
  495. * secondaries from the bootloader.
  496. *
  497. * Make sure we online at most (max_cpus - 1) additional CPUs.
  498. */
  499. max_cpus--;
  500. for_each_possible_cpu(cpu) {
  501. if (max_cpus == 0)
  502. break;
  503. if (cpu == smp_processor_id())
  504. continue;
  505. if (!cpu_ops[cpu])
  506. continue;
  507. err = cpu_ops[cpu]->cpu_prepare(cpu);
  508. if (err)
  509. continue;
  510. set_cpu_present(cpu, true);
  511. max_cpus--;
  512. }
  513. }
  514. void (*__smp_cross_call)(const struct cpumask *, unsigned int);
  515. void __init set_smp_cross_call(void (*fn)(const struct cpumask *, unsigned int))
  516. {
  517. __smp_cross_call = fn;
  518. }
  519. static const char *ipi_types[NR_IPI] __tracepoint_string = {
  520. #define S(x,s) [x] = s
  521. S(IPI_RESCHEDULE, "Rescheduling interrupts"),
  522. S(IPI_CALL_FUNC, "Function call interrupts"),
  523. S(IPI_CPU_STOP, "CPU stop interrupts"),
  524. S(IPI_TIMER, "Timer broadcast interrupts"),
  525. S(IPI_IRQ_WORK, "IRQ work interrupts"),
  526. };
  527. static void smp_cross_call(const struct cpumask *target, unsigned int ipinr)
  528. {
  529. trace_ipi_raise(target, ipi_types[ipinr]);
  530. __smp_cross_call(target, ipinr);
  531. }
  532. void show_ipi_list(struct seq_file *p, int prec)
  533. {
  534. unsigned int cpu, i;
  535. for (i = 0; i < NR_IPI; i++) {
  536. seq_printf(p, "%*s%u:%s", prec - 1, "IPI", i,
  537. prec >= 4 ? " " : "");
  538. for_each_online_cpu(cpu)
  539. seq_printf(p, "%10u ",
  540. __get_irq_stat(cpu, ipi_irqs[i]));
  541. seq_printf(p, " %s\n", ipi_types[i]);
  542. }
  543. }
  544. u64 smp_irq_stat_cpu(unsigned int cpu)
  545. {
  546. u64 sum = 0;
  547. int i;
  548. for (i = 0; i < NR_IPI; i++)
  549. sum += __get_irq_stat(cpu, ipi_irqs[i]);
  550. return sum;
  551. }
  552. void arch_send_call_function_ipi_mask(const struct cpumask *mask)
  553. {
  554. smp_cross_call(mask, IPI_CALL_FUNC);
  555. }
  556. void arch_send_call_function_single_ipi(int cpu)
  557. {
  558. smp_cross_call(cpumask_of(cpu), IPI_CALL_FUNC);
  559. }
  560. #ifdef CONFIG_IRQ_WORK
  561. void arch_irq_work_raise(void)
  562. {
  563. if (__smp_cross_call)
  564. smp_cross_call(cpumask_of(smp_processor_id()), IPI_IRQ_WORK);
  565. }
  566. #endif
  567. static DEFINE_RAW_SPINLOCK(stop_lock);
  568. /*
  569. * ipi_cpu_stop - handle IPI from smp_send_stop()
  570. */
  571. static void ipi_cpu_stop(unsigned int cpu)
  572. {
  573. if (system_state == SYSTEM_BOOTING ||
  574. system_state == SYSTEM_RUNNING) {
  575. raw_spin_lock(&stop_lock);
  576. pr_crit("CPU%u: stopping\n", cpu);
  577. dump_stack();
  578. raw_spin_unlock(&stop_lock);
  579. }
  580. set_cpu_online(cpu, false);
  581. local_irq_disable();
  582. while (1)
  583. cpu_relax();
  584. }
  585. /*
  586. * Main handler for inter-processor interrupts
  587. */
  588. void handle_IPI(int ipinr, struct pt_regs *regs)
  589. {
  590. unsigned int cpu = smp_processor_id();
  591. struct pt_regs *old_regs = set_irq_regs(regs);
  592. if ((unsigned)ipinr < NR_IPI) {
  593. trace_ipi_entry_rcuidle(ipi_types[ipinr]);
  594. __inc_irq_stat(cpu, ipi_irqs[ipinr]);
  595. }
  596. switch (ipinr) {
  597. case IPI_RESCHEDULE:
  598. scheduler_ipi();
  599. break;
  600. case IPI_CALL_FUNC:
  601. irq_enter();
  602. generic_smp_call_function_interrupt();
  603. irq_exit();
  604. break;
  605. case IPI_CPU_STOP:
  606. irq_enter();
  607. ipi_cpu_stop(cpu);
  608. irq_exit();
  609. break;
  610. #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  611. case IPI_TIMER:
  612. irq_enter();
  613. tick_receive_broadcast();
  614. irq_exit();
  615. break;
  616. #endif
  617. #ifdef CONFIG_IRQ_WORK
  618. case IPI_IRQ_WORK:
  619. irq_enter();
  620. irq_work_run();
  621. irq_exit();
  622. break;
  623. #endif
  624. default:
  625. pr_crit("CPU%u: Unknown IPI message 0x%x\n", cpu, ipinr);
  626. break;
  627. }
  628. if ((unsigned)ipinr < NR_IPI)
  629. trace_ipi_exit_rcuidle(ipi_types[ipinr]);
  630. set_irq_regs(old_regs);
  631. }
  632. void smp_send_reschedule(int cpu)
  633. {
  634. smp_cross_call(cpumask_of(cpu), IPI_RESCHEDULE);
  635. }
  636. #ifdef CONFIG_GENERIC_CLOCKEVENTS_BROADCAST
  637. void tick_broadcast(const struct cpumask *mask)
  638. {
  639. smp_cross_call(mask, IPI_TIMER);
  640. }
  641. #endif
  642. void smp_send_stop(void)
  643. {
  644. unsigned long timeout;
  645. if (num_online_cpus() > 1) {
  646. cpumask_t mask;
  647. cpumask_copy(&mask, cpu_online_mask);
  648. cpumask_clear_cpu(smp_processor_id(), &mask);
  649. smp_cross_call(&mask, IPI_CPU_STOP);
  650. }
  651. /* Wait up to one second for other CPUs to stop */
  652. timeout = USEC_PER_SEC;
  653. while (num_online_cpus() > 1 && timeout--)
  654. udelay(1);
  655. if (num_online_cpus() > 1)
  656. pr_warning("SMP: failed to stop secondary CPUs\n");
  657. }
  658. /*
  659. * not supported here
  660. */
  661. int setup_profiling_timer(unsigned int multiplier)
  662. {
  663. return -EINVAL;
  664. }