smp.c 18 KB

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