smp.c 18 KB

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