irq.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691
  1. /*
  2. * Derived from arch/i386/kernel/irq.c
  3. * Copyright (C) 1992 Linus Torvalds
  4. * Adapted from arch/i386 by Gary Thomas
  5. * Copyright (C) 1995-1996 Gary Thomas (gdt@linuxppc.org)
  6. * Updated and modified by Cort Dougan <cort@fsmlabs.com>
  7. * Copyright (C) 1996-2001 Cort Dougan
  8. * Adapted for Power Macintosh by Paul Mackerras
  9. * Copyright (C) 1996 Paul Mackerras (paulus@cs.anu.edu.au)
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version
  14. * 2 of the License, or (at your option) any later version.
  15. *
  16. * This file contains the code used by various IRQ handling routines:
  17. * asking for different IRQ's should be done through these routines
  18. * instead of just grabbing them. Thus setups with different IRQ numbers
  19. * shouldn't result in any weird surprises, and installing new handlers
  20. * should be easier.
  21. *
  22. * The MPC8xx has an interrupt mask in the SIU. If a bit is set, the
  23. * interrupt is _enabled_. As expected, IRQ0 is bit 0 in the 32-bit
  24. * mask register (of which only 16 are defined), hence the weird shifting
  25. * and complement of the cached_irq_mask. I want to be able to stuff
  26. * this right into the SIU SMASK register.
  27. * Many of the prep/chrp functions are conditional compiled on CONFIG_8xx
  28. * to reduce code space and undefined function references.
  29. */
  30. #undef DEBUG
  31. #include <linux/export.h>
  32. #include <linux/threads.h>
  33. #include <linux/kernel_stat.h>
  34. #include <linux/signal.h>
  35. #include <linux/sched.h>
  36. #include <linux/ptrace.h>
  37. #include <linux/ioport.h>
  38. #include <linux/interrupt.h>
  39. #include <linux/timex.h>
  40. #include <linux/init.h>
  41. #include <linux/slab.h>
  42. #include <linux/delay.h>
  43. #include <linux/irq.h>
  44. #include <linux/seq_file.h>
  45. #include <linux/cpumask.h>
  46. #include <linux/profile.h>
  47. #include <linux/bitops.h>
  48. #include <linux/list.h>
  49. #include <linux/radix-tree.h>
  50. #include <linux/mutex.h>
  51. #include <linux/pci.h>
  52. #include <linux/debugfs.h>
  53. #include <linux/of.h>
  54. #include <linux/of_irq.h>
  55. #include <asm/uaccess.h>
  56. #include <asm/io.h>
  57. #include <asm/pgtable.h>
  58. #include <asm/irq.h>
  59. #include <asm/cache.h>
  60. #include <asm/prom.h>
  61. #include <asm/ptrace.h>
  62. #include <asm/machdep.h>
  63. #include <asm/udbg.h>
  64. #include <asm/smp.h>
  65. #include <asm/debug.h>
  66. #ifdef CONFIG_PPC64
  67. #include <asm/paca.h>
  68. #include <asm/firmware.h>
  69. #include <asm/lv1call.h>
  70. #endif
  71. #define CREATE_TRACE_POINTS
  72. #include <asm/trace.h>
  73. DEFINE_PER_CPU_SHARED_ALIGNED(irq_cpustat_t, irq_stat);
  74. EXPORT_PER_CPU_SYMBOL(irq_stat);
  75. int __irq_offset_value;
  76. #ifdef CONFIG_PPC32
  77. EXPORT_SYMBOL(__irq_offset_value);
  78. atomic_t ppc_n_lost_interrupts;
  79. #ifdef CONFIG_TAU_INT
  80. extern int tau_initialized;
  81. extern int tau_interrupts(int);
  82. #endif
  83. #endif /* CONFIG_PPC32 */
  84. #ifdef CONFIG_PPC64
  85. int distribute_irqs = 1;
  86. static inline notrace unsigned long get_irq_happened(void)
  87. {
  88. unsigned long happened;
  89. __asm__ __volatile__("lbz %0,%1(13)"
  90. : "=r" (happened) : "i" (offsetof(struct paca_struct, irq_happened)));
  91. return happened;
  92. }
  93. static inline notrace void set_soft_enabled(unsigned long enable)
  94. {
  95. __asm__ __volatile__("stb %0,%1(13)"
  96. : : "r" (enable), "i" (offsetof(struct paca_struct, soft_enabled)));
  97. }
  98. static inline notrace int decrementer_check_overflow(void)
  99. {
  100. u64 now = get_tb_or_rtc();
  101. u64 *next_tb = this_cpu_ptr(&decrementers_next_tb);
  102. return now >= *next_tb;
  103. }
  104. /* This is called whenever we are re-enabling interrupts
  105. * and returns either 0 (nothing to do) or 500/900/280/a00/e80 if
  106. * there's an EE, DEC or DBELL to generate.
  107. *
  108. * This is called in two contexts: From arch_local_irq_restore()
  109. * before soft-enabling interrupts, and from the exception exit
  110. * path when returning from an interrupt from a soft-disabled to
  111. * a soft enabled context. In both case we have interrupts hard
  112. * disabled.
  113. *
  114. * We take care of only clearing the bits we handled in the
  115. * PACA irq_happened field since we can only re-emit one at a
  116. * time and we don't want to "lose" one.
  117. */
  118. notrace unsigned int __check_irq_replay(void)
  119. {
  120. /*
  121. * We use local_paca rather than get_paca() to avoid all
  122. * the debug_smp_processor_id() business in this low level
  123. * function
  124. */
  125. unsigned char happened = local_paca->irq_happened;
  126. /* Clear bit 0 which we wouldn't clear otherwise */
  127. local_paca->irq_happened &= ~PACA_IRQ_HARD_DIS;
  128. /*
  129. * Force the delivery of pending soft-disabled interrupts on PS3.
  130. * Any HV call will have this side effect.
  131. */
  132. if (firmware_has_feature(FW_FEATURE_PS3_LV1)) {
  133. u64 tmp, tmp2;
  134. lv1_get_version_info(&tmp, &tmp2);
  135. }
  136. /*
  137. * We may have missed a decrementer interrupt. We check the
  138. * decrementer itself rather than the paca irq_happened field
  139. * in case we also had a rollover while hard disabled
  140. */
  141. local_paca->irq_happened &= ~PACA_IRQ_DEC;
  142. if ((happened & PACA_IRQ_DEC) || decrementer_check_overflow())
  143. return 0x900;
  144. /* Finally check if an external interrupt happened */
  145. local_paca->irq_happened &= ~PACA_IRQ_EE;
  146. if (happened & PACA_IRQ_EE)
  147. return 0x500;
  148. #ifdef CONFIG_PPC_BOOK3E
  149. /* Finally check if an EPR external interrupt happened
  150. * this bit is typically set if we need to handle another
  151. * "edge" interrupt from within the MPIC "EPR" handler
  152. */
  153. local_paca->irq_happened &= ~PACA_IRQ_EE_EDGE;
  154. if (happened & PACA_IRQ_EE_EDGE)
  155. return 0x500;
  156. local_paca->irq_happened &= ~PACA_IRQ_DBELL;
  157. if (happened & PACA_IRQ_DBELL)
  158. return 0x280;
  159. #else
  160. local_paca->irq_happened &= ~PACA_IRQ_DBELL;
  161. if (happened & PACA_IRQ_DBELL) {
  162. if (cpu_has_feature(CPU_FTR_HVMODE))
  163. return 0xe80;
  164. return 0xa00;
  165. }
  166. #endif /* CONFIG_PPC_BOOK3E */
  167. /* Check if an hypervisor Maintenance interrupt happened */
  168. local_paca->irq_happened &= ~PACA_IRQ_HMI;
  169. if (happened & PACA_IRQ_HMI)
  170. return 0xe60;
  171. /* There should be nothing left ! */
  172. BUG_ON(local_paca->irq_happened != 0);
  173. return 0;
  174. }
  175. notrace void arch_local_irq_restore(unsigned long en)
  176. {
  177. unsigned char irq_happened;
  178. unsigned int replay;
  179. /* Write the new soft-enabled value */
  180. set_soft_enabled(en);
  181. if (!en)
  182. return;
  183. /*
  184. * From this point onward, we can take interrupts, preempt,
  185. * etc... unless we got hard-disabled. We check if an event
  186. * happened. If none happened, we know we can just return.
  187. *
  188. * We may have preempted before the check below, in which case
  189. * we are checking the "new" CPU instead of the old one. This
  190. * is only a problem if an event happened on the "old" CPU.
  191. *
  192. * External interrupt events will have caused interrupts to
  193. * be hard-disabled, so there is no problem, we
  194. * cannot have preempted.
  195. */
  196. irq_happened = get_irq_happened();
  197. if (!irq_happened)
  198. return;
  199. /*
  200. * We need to hard disable to get a trusted value from
  201. * __check_irq_replay(). We also need to soft-disable
  202. * again to avoid warnings in there due to the use of
  203. * per-cpu variables.
  204. *
  205. * We know that if the value in irq_happened is exactly 0x01
  206. * then we are already hard disabled (there are other less
  207. * common cases that we'll ignore for now), so we skip the
  208. * (expensive) mtmsrd.
  209. */
  210. if (unlikely(irq_happened != PACA_IRQ_HARD_DIS))
  211. __hard_irq_disable();
  212. #ifdef CONFIG_TRACE_IRQFLAGS
  213. else {
  214. /*
  215. * We should already be hard disabled here. We had bugs
  216. * where that wasn't the case so let's dbl check it and
  217. * warn if we are wrong. Only do that when IRQ tracing
  218. * is enabled as mfmsr() can be costly.
  219. */
  220. if (WARN_ON(mfmsr() & MSR_EE))
  221. __hard_irq_disable();
  222. }
  223. #endif /* CONFIG_TRACE_IRQFLAG */
  224. set_soft_enabled(0);
  225. /*
  226. * Check if anything needs to be re-emitted. We haven't
  227. * soft-enabled yet to avoid warnings in decrementer_check_overflow
  228. * accessing per-cpu variables
  229. */
  230. replay = __check_irq_replay();
  231. /* We can soft-enable now */
  232. set_soft_enabled(1);
  233. /*
  234. * And replay if we have to. This will return with interrupts
  235. * hard-enabled.
  236. */
  237. if (replay) {
  238. __replay_interrupt(replay);
  239. return;
  240. }
  241. /* Finally, let's ensure we are hard enabled */
  242. __hard_irq_enable();
  243. }
  244. EXPORT_SYMBOL(arch_local_irq_restore);
  245. /*
  246. * This is specifically called by assembly code to re-enable interrupts
  247. * if they are currently disabled. This is typically called before
  248. * schedule() or do_signal() when returning to userspace. We do it
  249. * in C to avoid the burden of dealing with lockdep etc...
  250. *
  251. * NOTE: This is called with interrupts hard disabled but not marked
  252. * as such in paca->irq_happened, so we need to resync this.
  253. */
  254. void notrace restore_interrupts(void)
  255. {
  256. if (irqs_disabled()) {
  257. local_paca->irq_happened |= PACA_IRQ_HARD_DIS;
  258. local_irq_enable();
  259. } else
  260. __hard_irq_enable();
  261. }
  262. /*
  263. * This is a helper to use when about to go into idle low-power
  264. * when the latter has the side effect of re-enabling interrupts
  265. * (such as calling H_CEDE under pHyp).
  266. *
  267. * You call this function with interrupts soft-disabled (this is
  268. * already the case when ppc_md.power_save is called). The function
  269. * will return whether to enter power save or just return.
  270. *
  271. * In the former case, it will have notified lockdep of interrupts
  272. * being re-enabled and generally sanitized the lazy irq state,
  273. * and in the latter case it will leave with interrupts hard
  274. * disabled and marked as such, so the local_irq_enable() call
  275. * in arch_cpu_idle() will properly re-enable everything.
  276. */
  277. bool prep_irq_for_idle(void)
  278. {
  279. /*
  280. * First we need to hard disable to ensure no interrupt
  281. * occurs before we effectively enter the low power state
  282. */
  283. hard_irq_disable();
  284. /*
  285. * If anything happened while we were soft-disabled,
  286. * we return now and do not enter the low power state.
  287. */
  288. if (lazy_irq_pending())
  289. return false;
  290. /* Tell lockdep we are about to re-enable */
  291. trace_hardirqs_on();
  292. /*
  293. * Mark interrupts as soft-enabled and clear the
  294. * PACA_IRQ_HARD_DIS from the pending mask since we
  295. * are about to hard enable as well as a side effect
  296. * of entering the low power state.
  297. */
  298. local_paca->irq_happened &= ~PACA_IRQ_HARD_DIS;
  299. local_paca->soft_enabled = 1;
  300. /* Tell the caller to enter the low power state */
  301. return true;
  302. }
  303. #endif /* CONFIG_PPC64 */
  304. int arch_show_interrupts(struct seq_file *p, int prec)
  305. {
  306. int j;
  307. #if defined(CONFIG_PPC32) && defined(CONFIG_TAU_INT)
  308. if (tau_initialized) {
  309. seq_printf(p, "%*s: ", prec, "TAU");
  310. for_each_online_cpu(j)
  311. seq_printf(p, "%10u ", tau_interrupts(j));
  312. seq_puts(p, " PowerPC Thermal Assist (cpu temp)\n");
  313. }
  314. #endif /* CONFIG_PPC32 && CONFIG_TAU_INT */
  315. seq_printf(p, "%*s: ", prec, "LOC");
  316. for_each_online_cpu(j)
  317. seq_printf(p, "%10u ", per_cpu(irq_stat, j).timer_irqs_event);
  318. seq_printf(p, " Local timer interrupts for timer event device\n");
  319. seq_printf(p, "%*s: ", prec, "LOC");
  320. for_each_online_cpu(j)
  321. seq_printf(p, "%10u ", per_cpu(irq_stat, j).timer_irqs_others);
  322. seq_printf(p, " Local timer interrupts for others\n");
  323. seq_printf(p, "%*s: ", prec, "SPU");
  324. for_each_online_cpu(j)
  325. seq_printf(p, "%10u ", per_cpu(irq_stat, j).spurious_irqs);
  326. seq_printf(p, " Spurious interrupts\n");
  327. seq_printf(p, "%*s: ", prec, "PMI");
  328. for_each_online_cpu(j)
  329. seq_printf(p, "%10u ", per_cpu(irq_stat, j).pmu_irqs);
  330. seq_printf(p, " Performance monitoring interrupts\n");
  331. seq_printf(p, "%*s: ", prec, "MCE");
  332. for_each_online_cpu(j)
  333. seq_printf(p, "%10u ", per_cpu(irq_stat, j).mce_exceptions);
  334. seq_printf(p, " Machine check exceptions\n");
  335. if (cpu_has_feature(CPU_FTR_HVMODE)) {
  336. seq_printf(p, "%*s: ", prec, "HMI");
  337. for_each_online_cpu(j)
  338. seq_printf(p, "%10u ",
  339. per_cpu(irq_stat, j).hmi_exceptions);
  340. seq_printf(p, " Hypervisor Maintenance Interrupts\n");
  341. }
  342. #ifdef CONFIG_PPC_DOORBELL
  343. if (cpu_has_feature(CPU_FTR_DBELL)) {
  344. seq_printf(p, "%*s: ", prec, "DBL");
  345. for_each_online_cpu(j)
  346. seq_printf(p, "%10u ", per_cpu(irq_stat, j).doorbell_irqs);
  347. seq_printf(p, " Doorbell interrupts\n");
  348. }
  349. #endif
  350. return 0;
  351. }
  352. /*
  353. * /proc/stat helpers
  354. */
  355. u64 arch_irq_stat_cpu(unsigned int cpu)
  356. {
  357. u64 sum = per_cpu(irq_stat, cpu).timer_irqs_event;
  358. sum += per_cpu(irq_stat, cpu).pmu_irqs;
  359. sum += per_cpu(irq_stat, cpu).mce_exceptions;
  360. sum += per_cpu(irq_stat, cpu).spurious_irqs;
  361. sum += per_cpu(irq_stat, cpu).timer_irqs_others;
  362. sum += per_cpu(irq_stat, cpu).hmi_exceptions;
  363. #ifdef CONFIG_PPC_DOORBELL
  364. sum += per_cpu(irq_stat, cpu).doorbell_irqs;
  365. #endif
  366. return sum;
  367. }
  368. #ifdef CONFIG_HOTPLUG_CPU
  369. void migrate_irqs(void)
  370. {
  371. struct irq_desc *desc;
  372. unsigned int irq;
  373. static int warned;
  374. cpumask_var_t mask;
  375. const struct cpumask *map = cpu_online_mask;
  376. alloc_cpumask_var(&mask, GFP_KERNEL);
  377. for_each_irq_desc(irq, desc) {
  378. struct irq_data *data;
  379. struct irq_chip *chip;
  380. data = irq_desc_get_irq_data(desc);
  381. if (irqd_is_per_cpu(data))
  382. continue;
  383. chip = irq_data_get_irq_chip(data);
  384. cpumask_and(mask, irq_data_get_affinity_mask(data), map);
  385. if (cpumask_any(mask) >= nr_cpu_ids) {
  386. pr_warn("Breaking affinity for irq %i\n", irq);
  387. cpumask_copy(mask, map);
  388. }
  389. if (chip->irq_set_affinity)
  390. chip->irq_set_affinity(data, mask, true);
  391. else if (desc->action && !(warned++))
  392. pr_err("Cannot set affinity for irq %i\n", irq);
  393. }
  394. free_cpumask_var(mask);
  395. local_irq_enable();
  396. mdelay(1);
  397. local_irq_disable();
  398. }
  399. #endif
  400. static inline void check_stack_overflow(void)
  401. {
  402. #ifdef CONFIG_DEBUG_STACKOVERFLOW
  403. long sp;
  404. sp = current_stack_pointer() & (THREAD_SIZE-1);
  405. /* check for stack overflow: is there less than 2KB free? */
  406. if (unlikely(sp < (sizeof(struct thread_info) + 2048))) {
  407. pr_err("do_IRQ: stack overflow: %ld\n",
  408. sp - sizeof(struct thread_info));
  409. dump_stack();
  410. }
  411. #endif
  412. }
  413. void __do_irq(struct pt_regs *regs)
  414. {
  415. unsigned int irq;
  416. irq_enter();
  417. trace_irq_entry(regs);
  418. check_stack_overflow();
  419. /*
  420. * Query the platform PIC for the interrupt & ack it.
  421. *
  422. * This will typically lower the interrupt line to the CPU
  423. */
  424. irq = ppc_md.get_irq();
  425. /* We can hard enable interrupts now to allow perf interrupts */
  426. may_hard_irq_enable();
  427. /* And finally process it */
  428. if (unlikely(irq == NO_IRQ))
  429. __this_cpu_inc(irq_stat.spurious_irqs);
  430. else
  431. generic_handle_irq(irq);
  432. trace_irq_exit(regs);
  433. irq_exit();
  434. }
  435. void do_IRQ(struct pt_regs *regs)
  436. {
  437. struct pt_regs *old_regs = set_irq_regs(regs);
  438. struct thread_info *curtp, *irqtp, *sirqtp;
  439. /* Switch to the irq stack to handle this */
  440. curtp = current_thread_info();
  441. irqtp = hardirq_ctx[raw_smp_processor_id()];
  442. sirqtp = softirq_ctx[raw_smp_processor_id()];
  443. /* Already there ? */
  444. if (unlikely(curtp == irqtp || curtp == sirqtp)) {
  445. __do_irq(regs);
  446. set_irq_regs(old_regs);
  447. return;
  448. }
  449. /* Prepare the thread_info in the irq stack */
  450. irqtp->task = curtp->task;
  451. irqtp->flags = 0;
  452. /* Copy the preempt_count so that the [soft]irq checks work. */
  453. irqtp->preempt_count = curtp->preempt_count;
  454. /* Switch stack and call */
  455. call_do_irq(regs, irqtp);
  456. /* Restore stack limit */
  457. irqtp->task = NULL;
  458. /* Copy back updates to the thread_info */
  459. if (irqtp->flags)
  460. set_bits(irqtp->flags, &curtp->flags);
  461. set_irq_regs(old_regs);
  462. }
  463. void __init init_IRQ(void)
  464. {
  465. if (ppc_md.init_IRQ)
  466. ppc_md.init_IRQ();
  467. exc_lvl_ctx_init();
  468. irq_ctx_init();
  469. }
  470. #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
  471. struct thread_info *critirq_ctx[NR_CPUS] __read_mostly;
  472. struct thread_info *dbgirq_ctx[NR_CPUS] __read_mostly;
  473. struct thread_info *mcheckirq_ctx[NR_CPUS] __read_mostly;
  474. void exc_lvl_ctx_init(void)
  475. {
  476. struct thread_info *tp;
  477. int i, cpu_nr;
  478. for_each_possible_cpu(i) {
  479. #ifdef CONFIG_PPC64
  480. cpu_nr = i;
  481. #else
  482. #ifdef CONFIG_SMP
  483. cpu_nr = get_hard_smp_processor_id(i);
  484. #else
  485. cpu_nr = 0;
  486. #endif
  487. #endif
  488. memset((void *)critirq_ctx[cpu_nr], 0, THREAD_SIZE);
  489. tp = critirq_ctx[cpu_nr];
  490. tp->cpu = cpu_nr;
  491. tp->preempt_count = 0;
  492. #ifdef CONFIG_BOOKE
  493. memset((void *)dbgirq_ctx[cpu_nr], 0, THREAD_SIZE);
  494. tp = dbgirq_ctx[cpu_nr];
  495. tp->cpu = cpu_nr;
  496. tp->preempt_count = 0;
  497. memset((void *)mcheckirq_ctx[cpu_nr], 0, THREAD_SIZE);
  498. tp = mcheckirq_ctx[cpu_nr];
  499. tp->cpu = cpu_nr;
  500. tp->preempt_count = HARDIRQ_OFFSET;
  501. #endif
  502. }
  503. }
  504. #endif
  505. struct thread_info *softirq_ctx[NR_CPUS] __read_mostly;
  506. struct thread_info *hardirq_ctx[NR_CPUS] __read_mostly;
  507. void irq_ctx_init(void)
  508. {
  509. struct thread_info *tp;
  510. int i;
  511. for_each_possible_cpu(i) {
  512. memset((void *)softirq_ctx[i], 0, THREAD_SIZE);
  513. tp = softirq_ctx[i];
  514. tp->cpu = i;
  515. memset((void *)hardirq_ctx[i], 0, THREAD_SIZE);
  516. tp = hardirq_ctx[i];
  517. tp->cpu = i;
  518. }
  519. }
  520. void do_softirq_own_stack(void)
  521. {
  522. struct thread_info *curtp, *irqtp;
  523. curtp = current_thread_info();
  524. irqtp = softirq_ctx[smp_processor_id()];
  525. irqtp->task = curtp->task;
  526. irqtp->flags = 0;
  527. call_do_softirq(irqtp);
  528. irqtp->task = NULL;
  529. /* Set any flag that may have been set on the
  530. * alternate stack
  531. */
  532. if (irqtp->flags)
  533. set_bits(irqtp->flags, &curtp->flags);
  534. }
  535. irq_hw_number_t virq_to_hw(unsigned int virq)
  536. {
  537. struct irq_data *irq_data = irq_get_irq_data(virq);
  538. return WARN_ON(!irq_data) ? 0 : irq_data->hwirq;
  539. }
  540. EXPORT_SYMBOL_GPL(virq_to_hw);
  541. #ifdef CONFIG_SMP
  542. int irq_choose_cpu(const struct cpumask *mask)
  543. {
  544. int cpuid;
  545. if (cpumask_equal(mask, cpu_online_mask)) {
  546. static int irq_rover;
  547. static DEFINE_RAW_SPINLOCK(irq_rover_lock);
  548. unsigned long flags;
  549. /* Round-robin distribution... */
  550. do_round_robin:
  551. raw_spin_lock_irqsave(&irq_rover_lock, flags);
  552. irq_rover = cpumask_next(irq_rover, cpu_online_mask);
  553. if (irq_rover >= nr_cpu_ids)
  554. irq_rover = cpumask_first(cpu_online_mask);
  555. cpuid = irq_rover;
  556. raw_spin_unlock_irqrestore(&irq_rover_lock, flags);
  557. } else {
  558. cpuid = cpumask_first_and(mask, cpu_online_mask);
  559. if (cpuid >= nr_cpu_ids)
  560. goto do_round_robin;
  561. }
  562. return get_hard_smp_processor_id(cpuid);
  563. }
  564. #else
  565. int irq_choose_cpu(const struct cpumask *mask)
  566. {
  567. return hard_smp_processor_id();
  568. }
  569. #endif
  570. int arch_early_irq_init(void)
  571. {
  572. return 0;
  573. }
  574. #ifdef CONFIG_PPC64
  575. static int __init setup_noirqdistrib(char *str)
  576. {
  577. distribute_irqs = 0;
  578. return 1;
  579. }
  580. __setup("noirqdistrib", setup_noirqdistrib);
  581. #endif /* CONFIG_PPC64 */