irq.c 18 KB

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