smp.c 18 KB

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