irq.c 19 KB

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