manage.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. /*
  2. * linux/kernel/irq/manage.c
  3. *
  4. * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
  5. * Copyright (C) 2005-2006 Thomas Gleixner
  6. *
  7. * This file contains driver APIs to the irq subsystem.
  8. */
  9. #include <linux/irq.h>
  10. #include <linux/module.h>
  11. #include <linux/random.h>
  12. #include <linux/interrupt.h>
  13. #include <linux/slab.h>
  14. #include "internals.h"
  15. #ifdef CONFIG_SMP
  16. cpumask_var_t irq_default_affinity;
  17. static int init_irq_default_affinity(void)
  18. {
  19. alloc_cpumask_var(&irq_default_affinity, GFP_KERNEL);
  20. cpumask_setall(irq_default_affinity);
  21. return 0;
  22. }
  23. core_initcall(init_irq_default_affinity);
  24. /**
  25. * synchronize_irq - wait for pending IRQ handlers (on other CPUs)
  26. * @irq: interrupt number to wait for
  27. *
  28. * This function waits for any pending IRQ handlers for this interrupt
  29. * to complete before returning. If you use this function while
  30. * holding a resource the IRQ handler may need you will deadlock.
  31. *
  32. * This function may be called - with care - from IRQ context.
  33. */
  34. void synchronize_irq(unsigned int irq)
  35. {
  36. struct irq_desc *desc = irq_to_desc(irq);
  37. unsigned int status;
  38. if (!desc)
  39. return;
  40. do {
  41. unsigned long flags;
  42. /*
  43. * Wait until we're out of the critical section. This might
  44. * give the wrong answer due to the lack of memory barriers.
  45. */
  46. while (desc->status & IRQ_INPROGRESS)
  47. cpu_relax();
  48. /* Ok, that indicated we're done: double-check carefully. */
  49. spin_lock_irqsave(&desc->lock, flags);
  50. status = desc->status;
  51. spin_unlock_irqrestore(&desc->lock, flags);
  52. /* Oops, that failed? */
  53. } while (status & IRQ_INPROGRESS);
  54. }
  55. EXPORT_SYMBOL(synchronize_irq);
  56. /**
  57. * irq_can_set_affinity - Check if the affinity of a given irq can be set
  58. * @irq: Interrupt to check
  59. *
  60. */
  61. int irq_can_set_affinity(unsigned int irq)
  62. {
  63. struct irq_desc *desc = irq_to_desc(irq);
  64. if (CHECK_IRQ_PER_CPU(desc->status) || !desc->chip ||
  65. !desc->chip->set_affinity)
  66. return 0;
  67. return 1;
  68. }
  69. /**
  70. * irq_set_affinity - Set the irq affinity of a given irq
  71. * @irq: Interrupt to set affinity
  72. * @cpumask: cpumask
  73. *
  74. */
  75. int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask)
  76. {
  77. struct irq_desc *desc = irq_to_desc(irq);
  78. unsigned long flags;
  79. if (!desc->chip->set_affinity)
  80. return -EINVAL;
  81. spin_lock_irqsave(&desc->lock, flags);
  82. #ifdef CONFIG_GENERIC_PENDING_IRQ
  83. if (desc->status & IRQ_MOVE_PCNTXT || desc->status & IRQ_DISABLED) {
  84. cpumask_copy(&desc->affinity, cpumask);
  85. desc->chip->set_affinity(irq, cpumask);
  86. } else {
  87. desc->status |= IRQ_MOVE_PENDING;
  88. cpumask_copy(&desc->pending_mask, cpumask);
  89. }
  90. #else
  91. cpumask_copy(&desc->affinity, cpumask);
  92. desc->chip->set_affinity(irq, cpumask);
  93. #endif
  94. desc->status |= IRQ_AFFINITY_SET;
  95. spin_unlock_irqrestore(&desc->lock, flags);
  96. return 0;
  97. }
  98. #ifndef CONFIG_AUTO_IRQ_AFFINITY
  99. /*
  100. * Generic version of the affinity autoselector.
  101. */
  102. int do_irq_select_affinity(unsigned int irq, struct irq_desc *desc)
  103. {
  104. if (!irq_can_set_affinity(irq))
  105. return 0;
  106. /*
  107. * Preserve an userspace affinity setup, but make sure that
  108. * one of the targets is online.
  109. */
  110. if (desc->status & (IRQ_AFFINITY_SET | IRQ_NO_BALANCING)) {
  111. if (cpumask_any_and(&desc->affinity, cpu_online_mask)
  112. < nr_cpu_ids)
  113. goto set_affinity;
  114. else
  115. desc->status &= ~IRQ_AFFINITY_SET;
  116. }
  117. cpumask_and(&desc->affinity, cpu_online_mask, irq_default_affinity);
  118. set_affinity:
  119. desc->chip->set_affinity(irq, &desc->affinity);
  120. return 0;
  121. }
  122. #else
  123. static inline int do_irq_select_affinity(unsigned int irq, struct irq_desc *d)
  124. {
  125. return irq_select_affinity(irq);
  126. }
  127. #endif
  128. /*
  129. * Called when affinity is set via /proc/irq
  130. */
  131. int irq_select_affinity_usr(unsigned int irq)
  132. {
  133. struct irq_desc *desc = irq_to_desc(irq);
  134. unsigned long flags;
  135. int ret;
  136. spin_lock_irqsave(&desc->lock, flags);
  137. ret = do_irq_select_affinity(irq, desc);
  138. spin_unlock_irqrestore(&desc->lock, flags);
  139. return ret;
  140. }
  141. #else
  142. static inline int do_irq_select_affinity(int irq, struct irq_desc *desc)
  143. {
  144. return 0;
  145. }
  146. #endif
  147. /**
  148. * disable_irq_nosync - disable an irq without waiting
  149. * @irq: Interrupt to disable
  150. *
  151. * Disable the selected interrupt line. Disables and Enables are
  152. * nested.
  153. * Unlike disable_irq(), this function does not ensure existing
  154. * instances of the IRQ handler have completed before returning.
  155. *
  156. * This function may be called from IRQ context.
  157. */
  158. void disable_irq_nosync(unsigned int irq)
  159. {
  160. struct irq_desc *desc = irq_to_desc(irq);
  161. unsigned long flags;
  162. if (!desc)
  163. return;
  164. spin_lock_irqsave(&desc->lock, flags);
  165. if (!desc->depth++) {
  166. desc->status |= IRQ_DISABLED;
  167. desc->chip->disable(irq);
  168. }
  169. spin_unlock_irqrestore(&desc->lock, flags);
  170. }
  171. EXPORT_SYMBOL(disable_irq_nosync);
  172. /**
  173. * disable_irq - disable an irq and wait for completion
  174. * @irq: Interrupt to disable
  175. *
  176. * Disable the selected interrupt line. Enables and Disables are
  177. * nested.
  178. * This function waits for any pending IRQ handlers for this interrupt
  179. * to complete before returning. If you use this function while
  180. * holding a resource the IRQ handler may need you will deadlock.
  181. *
  182. * This function may be called - with care - from IRQ context.
  183. */
  184. void disable_irq(unsigned int irq)
  185. {
  186. struct irq_desc *desc = irq_to_desc(irq);
  187. if (!desc)
  188. return;
  189. disable_irq_nosync(irq);
  190. if (desc->action)
  191. synchronize_irq(irq);
  192. }
  193. EXPORT_SYMBOL(disable_irq);
  194. static void __enable_irq(struct irq_desc *desc, unsigned int irq)
  195. {
  196. switch (desc->depth) {
  197. case 0:
  198. WARN(1, KERN_WARNING "Unbalanced enable for IRQ %d\n", irq);
  199. break;
  200. case 1: {
  201. unsigned int status = desc->status & ~IRQ_DISABLED;
  202. /* Prevent probing on this irq: */
  203. desc->status = status | IRQ_NOPROBE;
  204. check_irq_resend(desc, irq);
  205. /* fall-through */
  206. }
  207. default:
  208. desc->depth--;
  209. }
  210. }
  211. /**
  212. * enable_irq - enable handling of an irq
  213. * @irq: Interrupt to enable
  214. *
  215. * Undoes the effect of one call to disable_irq(). If this
  216. * matches the last disable, processing of interrupts on this
  217. * IRQ line is re-enabled.
  218. *
  219. * This function may be called from IRQ context.
  220. */
  221. void enable_irq(unsigned int irq)
  222. {
  223. struct irq_desc *desc = irq_to_desc(irq);
  224. unsigned long flags;
  225. if (!desc)
  226. return;
  227. spin_lock_irqsave(&desc->lock, flags);
  228. __enable_irq(desc, irq);
  229. spin_unlock_irqrestore(&desc->lock, flags);
  230. }
  231. EXPORT_SYMBOL(enable_irq);
  232. static int set_irq_wake_real(unsigned int irq, unsigned int on)
  233. {
  234. struct irq_desc *desc = irq_to_desc(irq);
  235. int ret = -ENXIO;
  236. if (desc->chip->set_wake)
  237. ret = desc->chip->set_wake(irq, on);
  238. return ret;
  239. }
  240. /**
  241. * set_irq_wake - control irq power management wakeup
  242. * @irq: interrupt to control
  243. * @on: enable/disable power management wakeup
  244. *
  245. * Enable/disable power management wakeup mode, which is
  246. * disabled by default. Enables and disables must match,
  247. * just as they match for non-wakeup mode support.
  248. *
  249. * Wakeup mode lets this IRQ wake the system from sleep
  250. * states like "suspend to RAM".
  251. */
  252. int set_irq_wake(unsigned int irq, unsigned int on)
  253. {
  254. struct irq_desc *desc = irq_to_desc(irq);
  255. unsigned long flags;
  256. int ret = 0;
  257. /* wakeup-capable irqs can be shared between drivers that
  258. * don't need to have the same sleep mode behaviors.
  259. */
  260. spin_lock_irqsave(&desc->lock, flags);
  261. if (on) {
  262. if (desc->wake_depth++ == 0) {
  263. ret = set_irq_wake_real(irq, on);
  264. if (ret)
  265. desc->wake_depth = 0;
  266. else
  267. desc->status |= IRQ_WAKEUP;
  268. }
  269. } else {
  270. if (desc->wake_depth == 0) {
  271. WARN(1, "Unbalanced IRQ %d wake disable\n", irq);
  272. } else if (--desc->wake_depth == 0) {
  273. ret = set_irq_wake_real(irq, on);
  274. if (ret)
  275. desc->wake_depth = 1;
  276. else
  277. desc->status &= ~IRQ_WAKEUP;
  278. }
  279. }
  280. spin_unlock_irqrestore(&desc->lock, flags);
  281. return ret;
  282. }
  283. EXPORT_SYMBOL(set_irq_wake);
  284. /*
  285. * Internal function that tells the architecture code whether a
  286. * particular irq has been exclusively allocated or is available
  287. * for driver use.
  288. */
  289. int can_request_irq(unsigned int irq, unsigned long irqflags)
  290. {
  291. struct irq_desc *desc = irq_to_desc(irq);
  292. struct irqaction *action;
  293. if (!desc)
  294. return 0;
  295. if (desc->status & IRQ_NOREQUEST)
  296. return 0;
  297. action = desc->action;
  298. if (action)
  299. if (irqflags & action->flags & IRQF_SHARED)
  300. action = NULL;
  301. return !action;
  302. }
  303. void compat_irq_chip_set_default_handler(struct irq_desc *desc)
  304. {
  305. /*
  306. * If the architecture still has not overriden
  307. * the flow handler then zap the default. This
  308. * should catch incorrect flow-type setting.
  309. */
  310. if (desc->handle_irq == &handle_bad_irq)
  311. desc->handle_irq = NULL;
  312. }
  313. int __irq_set_trigger(struct irq_desc *desc, unsigned int irq,
  314. unsigned long flags)
  315. {
  316. int ret;
  317. struct irq_chip *chip = desc->chip;
  318. if (!chip || !chip->set_type) {
  319. /*
  320. * IRQF_TRIGGER_* but the PIC does not support multiple
  321. * flow-types?
  322. */
  323. pr_debug("No set_type function for IRQ %d (%s)\n", irq,
  324. chip ? (chip->name ? : "unknown") : "unknown");
  325. return 0;
  326. }
  327. /* caller masked out all except trigger mode flags */
  328. ret = chip->set_type(irq, flags);
  329. if (ret)
  330. pr_err("setting trigger mode %d for irq %u failed (%pF)\n",
  331. (int)flags, irq, chip->set_type);
  332. else {
  333. if (flags & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
  334. flags |= IRQ_LEVEL;
  335. /* note that IRQF_TRIGGER_MASK == IRQ_TYPE_SENSE_MASK */
  336. desc->status &= ~(IRQ_LEVEL | IRQ_TYPE_SENSE_MASK);
  337. desc->status |= flags;
  338. }
  339. return ret;
  340. }
  341. /*
  342. * Internal function to register an irqaction - typically used to
  343. * allocate special interrupts that are part of the architecture.
  344. */
  345. static int
  346. __setup_irq(unsigned int irq, struct irq_desc * desc, struct irqaction *new)
  347. {
  348. struct irqaction *old, **p;
  349. const char *old_name = NULL;
  350. unsigned long flags;
  351. int shared = 0;
  352. int ret;
  353. if (!desc)
  354. return -EINVAL;
  355. if (desc->chip == &no_irq_chip)
  356. return -ENOSYS;
  357. /*
  358. * Some drivers like serial.c use request_irq() heavily,
  359. * so we have to be careful not to interfere with a
  360. * running system.
  361. */
  362. if (new->flags & IRQF_SAMPLE_RANDOM) {
  363. /*
  364. * This function might sleep, we want to call it first,
  365. * outside of the atomic block.
  366. * Yes, this might clear the entropy pool if the wrong
  367. * driver is attempted to be loaded, without actually
  368. * installing a new handler, but is this really a problem,
  369. * only the sysadmin is able to do this.
  370. */
  371. rand_initialize_irq(irq);
  372. }
  373. /*
  374. * The following block of code has to be executed atomically
  375. */
  376. spin_lock_irqsave(&desc->lock, flags);
  377. p = &desc->action;
  378. old = *p;
  379. if (old) {
  380. /*
  381. * Can't share interrupts unless both agree to and are
  382. * the same type (level, edge, polarity). So both flag
  383. * fields must have IRQF_SHARED set and the bits which
  384. * set the trigger type must match.
  385. */
  386. if (!((old->flags & new->flags) & IRQF_SHARED) ||
  387. ((old->flags ^ new->flags) & IRQF_TRIGGER_MASK)) {
  388. old_name = old->name;
  389. goto mismatch;
  390. }
  391. #if defined(CONFIG_IRQ_PER_CPU)
  392. /* All handlers must agree on per-cpuness */
  393. if ((old->flags & IRQF_PERCPU) !=
  394. (new->flags & IRQF_PERCPU))
  395. goto mismatch;
  396. #endif
  397. /* add new interrupt at end of irq queue */
  398. do {
  399. p = &old->next;
  400. old = *p;
  401. } while (old);
  402. shared = 1;
  403. }
  404. if (!shared) {
  405. irq_chip_set_defaults(desc->chip);
  406. /* Setup the type (level, edge polarity) if configured: */
  407. if (new->flags & IRQF_TRIGGER_MASK) {
  408. ret = __irq_set_trigger(desc, irq,
  409. new->flags & IRQF_TRIGGER_MASK);
  410. if (ret) {
  411. spin_unlock_irqrestore(&desc->lock, flags);
  412. return ret;
  413. }
  414. } else
  415. compat_irq_chip_set_default_handler(desc);
  416. #if defined(CONFIG_IRQ_PER_CPU)
  417. if (new->flags & IRQF_PERCPU)
  418. desc->status |= IRQ_PER_CPU;
  419. #endif
  420. desc->status &= ~(IRQ_AUTODETECT | IRQ_WAITING |
  421. IRQ_INPROGRESS | IRQ_SPURIOUS_DISABLED);
  422. if (!(desc->status & IRQ_NOAUTOEN)) {
  423. desc->depth = 0;
  424. desc->status &= ~IRQ_DISABLED;
  425. desc->chip->startup(irq);
  426. } else
  427. /* Undo nested disables: */
  428. desc->depth = 1;
  429. /* Exclude IRQ from balancing if requested */
  430. if (new->flags & IRQF_NOBALANCING)
  431. desc->status |= IRQ_NO_BALANCING;
  432. /* Set default affinity mask once everything is setup */
  433. do_irq_select_affinity(irq, desc);
  434. } else if ((new->flags & IRQF_TRIGGER_MASK)
  435. && (new->flags & IRQF_TRIGGER_MASK)
  436. != (desc->status & IRQ_TYPE_SENSE_MASK)) {
  437. /* hope the handler works with the actual trigger mode... */
  438. pr_warning("IRQ %d uses trigger mode %d; requested %d\n",
  439. irq, (int)(desc->status & IRQ_TYPE_SENSE_MASK),
  440. (int)(new->flags & IRQF_TRIGGER_MASK));
  441. }
  442. *p = new;
  443. /* Reset broken irq detection when installing new handler */
  444. desc->irq_count = 0;
  445. desc->irqs_unhandled = 0;
  446. /*
  447. * Check whether we disabled the irq via the spurious handler
  448. * before. Reenable it and give it another chance.
  449. */
  450. if (shared && (desc->status & IRQ_SPURIOUS_DISABLED)) {
  451. desc->status &= ~IRQ_SPURIOUS_DISABLED;
  452. __enable_irq(desc, irq);
  453. }
  454. spin_unlock_irqrestore(&desc->lock, flags);
  455. new->irq = irq;
  456. register_irq_proc(irq, desc);
  457. new->dir = NULL;
  458. register_handler_proc(irq, new);
  459. return 0;
  460. mismatch:
  461. #ifdef CONFIG_DEBUG_SHIRQ
  462. if (!(new->flags & IRQF_PROBE_SHARED)) {
  463. printk(KERN_ERR "IRQ handler type mismatch for IRQ %d\n", irq);
  464. if (old_name)
  465. printk(KERN_ERR "current handler: %s\n", old_name);
  466. dump_stack();
  467. }
  468. #endif
  469. spin_unlock_irqrestore(&desc->lock, flags);
  470. return -EBUSY;
  471. }
  472. /**
  473. * setup_irq - setup an interrupt
  474. * @irq: Interrupt line to setup
  475. * @act: irqaction for the interrupt
  476. *
  477. * Used to statically setup interrupts in the early boot process.
  478. */
  479. int setup_irq(unsigned int irq, struct irqaction *act)
  480. {
  481. struct irq_desc *desc = irq_to_desc(irq);
  482. return __setup_irq(irq, desc, act);
  483. }
  484. /**
  485. * free_irq - free an interrupt
  486. * @irq: Interrupt line to free
  487. * @dev_id: Device identity to free
  488. *
  489. * Remove an interrupt handler. The handler is removed and if the
  490. * interrupt line is no longer in use by any driver it is disabled.
  491. * On a shared IRQ the caller must ensure the interrupt is disabled
  492. * on the card it drives before calling this function. The function
  493. * does not return until any executing interrupts for this IRQ
  494. * have completed.
  495. *
  496. * This function must not be called from interrupt context.
  497. */
  498. void free_irq(unsigned int irq, void *dev_id)
  499. {
  500. struct irq_desc *desc = irq_to_desc(irq);
  501. struct irqaction **p;
  502. unsigned long flags;
  503. WARN_ON(in_interrupt());
  504. if (!desc)
  505. return;
  506. spin_lock_irqsave(&desc->lock, flags);
  507. p = &desc->action;
  508. for (;;) {
  509. struct irqaction *action = *p;
  510. if (action) {
  511. struct irqaction **pp = p;
  512. p = &action->next;
  513. if (action->dev_id != dev_id)
  514. continue;
  515. /* Found it - now remove it from the list of entries */
  516. *pp = action->next;
  517. /* Currently used only by UML, might disappear one day.*/
  518. #ifdef CONFIG_IRQ_RELEASE_METHOD
  519. if (desc->chip->release)
  520. desc->chip->release(irq, dev_id);
  521. #endif
  522. if (!desc->action) {
  523. desc->status |= IRQ_DISABLED;
  524. if (desc->chip->shutdown)
  525. desc->chip->shutdown(irq);
  526. else
  527. desc->chip->disable(irq);
  528. }
  529. spin_unlock_irqrestore(&desc->lock, flags);
  530. unregister_handler_proc(irq, action);
  531. /* Make sure it's not being used on another CPU */
  532. synchronize_irq(irq);
  533. #ifdef CONFIG_DEBUG_SHIRQ
  534. /*
  535. * It's a shared IRQ -- the driver ought to be
  536. * prepared for it to happen even now it's
  537. * being freed, so let's make sure.... We do
  538. * this after actually deregistering it, to
  539. * make sure that a 'real' IRQ doesn't run in
  540. * parallel with our fake
  541. */
  542. if (action->flags & IRQF_SHARED) {
  543. local_irq_save(flags);
  544. action->handler(irq, dev_id);
  545. local_irq_restore(flags);
  546. }
  547. #endif
  548. kfree(action);
  549. return;
  550. }
  551. printk(KERN_ERR "Trying to free already-free IRQ %d\n", irq);
  552. #ifdef CONFIG_DEBUG_SHIRQ
  553. dump_stack();
  554. #endif
  555. spin_unlock_irqrestore(&desc->lock, flags);
  556. return;
  557. }
  558. }
  559. EXPORT_SYMBOL(free_irq);
  560. /**
  561. * request_irq - allocate an interrupt line
  562. * @irq: Interrupt line to allocate
  563. * @handler: Function to be called when the IRQ occurs
  564. * @irqflags: Interrupt type flags
  565. * @devname: An ascii name for the claiming device
  566. * @dev_id: A cookie passed back to the handler function
  567. *
  568. * This call allocates interrupt resources and enables the
  569. * interrupt line and IRQ handling. From the point this
  570. * call is made your handler function may be invoked. Since
  571. * your handler function must clear any interrupt the board
  572. * raises, you must take care both to initialise your hardware
  573. * and to set up the interrupt handler in the right order.
  574. *
  575. * Dev_id must be globally unique. Normally the address of the
  576. * device data structure is used as the cookie. Since the handler
  577. * receives this value it makes sense to use it.
  578. *
  579. * If your interrupt is shared you must pass a non NULL dev_id
  580. * as this is required when freeing the interrupt.
  581. *
  582. * Flags:
  583. *
  584. * IRQF_SHARED Interrupt is shared
  585. * IRQF_DISABLED Disable local interrupts while processing
  586. * IRQF_SAMPLE_RANDOM The interrupt can be used for entropy
  587. * IRQF_TRIGGER_* Specify active edge(s) or level
  588. *
  589. */
  590. int request_irq(unsigned int irq, irq_handler_t handler,
  591. unsigned long irqflags, const char *devname, void *dev_id)
  592. {
  593. struct irqaction *action;
  594. struct irq_desc *desc;
  595. int retval;
  596. /*
  597. * handle_IRQ_event() always ignores IRQF_DISABLED except for
  598. * the _first_ irqaction (sigh). That can cause oopsing, but
  599. * the behavior is classified as "will not fix" so we need to
  600. * start nudging drivers away from using that idiom.
  601. */
  602. if ((irqflags & (IRQF_SHARED|IRQF_DISABLED))
  603. == (IRQF_SHARED|IRQF_DISABLED))
  604. pr_warning("IRQ %d/%s: IRQF_DISABLED is not "
  605. "guaranteed on shared IRQs\n",
  606. irq, devname);
  607. #ifdef CONFIG_LOCKDEP
  608. /*
  609. * Lockdep wants atomic interrupt handlers:
  610. */
  611. irqflags |= IRQF_DISABLED;
  612. #endif
  613. /*
  614. * Sanity-check: shared interrupts must pass in a real dev-ID,
  615. * otherwise we'll have trouble later trying to figure out
  616. * which interrupt is which (messes up the interrupt freeing
  617. * logic etc).
  618. */
  619. if ((irqflags & IRQF_SHARED) && !dev_id)
  620. return -EINVAL;
  621. desc = irq_to_desc(irq);
  622. if (!desc)
  623. return -EINVAL;
  624. if (desc->status & IRQ_NOREQUEST)
  625. return -EINVAL;
  626. if (!handler)
  627. return -EINVAL;
  628. action = kmalloc(sizeof(struct irqaction), GFP_ATOMIC);
  629. if (!action)
  630. return -ENOMEM;
  631. action->handler = handler;
  632. action->flags = irqflags;
  633. cpus_clear(action->mask);
  634. action->name = devname;
  635. action->next = NULL;
  636. action->dev_id = dev_id;
  637. retval = __setup_irq(irq, desc, action);
  638. if (retval)
  639. kfree(action);
  640. #ifdef CONFIG_DEBUG_SHIRQ
  641. if (irqflags & IRQF_SHARED) {
  642. /*
  643. * It's a shared IRQ -- the driver ought to be prepared for it
  644. * to happen immediately, so let's make sure....
  645. * We disable the irq to make sure that a 'real' IRQ doesn't
  646. * run in parallel with our fake.
  647. */
  648. unsigned long flags;
  649. disable_irq(irq);
  650. local_irq_save(flags);
  651. handler(irq, dev_id);
  652. local_irq_restore(flags);
  653. enable_irq(irq);
  654. }
  655. #endif
  656. return retval;
  657. }
  658. EXPORT_SYMBOL(request_irq);