chip.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776
  1. /*
  2. * linux/kernel/irq/chip.c
  3. *
  4. * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
  5. * Copyright (C) 2005-2006, Thomas Gleixner, Russell King
  6. *
  7. * This file contains the core interrupt handling code, for irq-chip
  8. * based architectures.
  9. *
  10. * Detailed information is available in Documentation/DocBook/genericirq
  11. */
  12. #include <linux/irq.h>
  13. #include <linux/msi.h>
  14. #include <linux/module.h>
  15. #include <linux/interrupt.h>
  16. #include <linux/kernel_stat.h>
  17. #include "internals.h"
  18. /**
  19. * set_irq_chip - set the irq chip for an irq
  20. * @irq: irq number
  21. * @chip: pointer to irq chip description structure
  22. */
  23. int set_irq_chip(unsigned int irq, struct irq_chip *chip)
  24. {
  25. struct irq_desc *desc = irq_to_desc(irq);
  26. unsigned long flags;
  27. if (!desc) {
  28. WARN(1, KERN_ERR "Trying to install chip for IRQ%d\n", irq);
  29. return -EINVAL;
  30. }
  31. if (!chip)
  32. chip = &no_irq_chip;
  33. raw_spin_lock_irqsave(&desc->lock, flags);
  34. irq_chip_set_defaults(chip);
  35. desc->irq_data.chip = chip;
  36. raw_spin_unlock_irqrestore(&desc->lock, flags);
  37. return 0;
  38. }
  39. EXPORT_SYMBOL(set_irq_chip);
  40. /**
  41. * set_irq_type - set the irq trigger type for an irq
  42. * @irq: irq number
  43. * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h
  44. */
  45. int set_irq_type(unsigned int irq, unsigned int type)
  46. {
  47. struct irq_desc *desc = irq_to_desc(irq);
  48. unsigned long flags;
  49. int ret = -ENXIO;
  50. if (!desc) {
  51. printk(KERN_ERR "Trying to set irq type for IRQ%d\n", irq);
  52. return -ENODEV;
  53. }
  54. type &= IRQ_TYPE_SENSE_MASK;
  55. if (type == IRQ_TYPE_NONE)
  56. return 0;
  57. raw_spin_lock_irqsave(&desc->lock, flags);
  58. ret = __irq_set_trigger(desc, irq, type);
  59. raw_spin_unlock_irqrestore(&desc->lock, flags);
  60. return ret;
  61. }
  62. EXPORT_SYMBOL(set_irq_type);
  63. /**
  64. * set_irq_data - set irq type data for an irq
  65. * @irq: Interrupt number
  66. * @data: Pointer to interrupt specific data
  67. *
  68. * Set the hardware irq controller data for an irq
  69. */
  70. int set_irq_data(unsigned int irq, void *data)
  71. {
  72. struct irq_desc *desc = irq_to_desc(irq);
  73. unsigned long flags;
  74. if (!desc) {
  75. printk(KERN_ERR
  76. "Trying to install controller data for IRQ%d\n", irq);
  77. return -EINVAL;
  78. }
  79. raw_spin_lock_irqsave(&desc->lock, flags);
  80. desc->irq_data.handler_data = data;
  81. raw_spin_unlock_irqrestore(&desc->lock, flags);
  82. return 0;
  83. }
  84. EXPORT_SYMBOL(set_irq_data);
  85. /**
  86. * set_irq_msi - set MSI descriptor data for an irq
  87. * @irq: Interrupt number
  88. * @entry: Pointer to MSI descriptor data
  89. *
  90. * Set the MSI descriptor entry for an irq
  91. */
  92. int set_irq_msi(unsigned int irq, struct msi_desc *entry)
  93. {
  94. struct irq_desc *desc = irq_to_desc(irq);
  95. unsigned long flags;
  96. if (!desc) {
  97. printk(KERN_ERR
  98. "Trying to install msi data for IRQ%d\n", irq);
  99. return -EINVAL;
  100. }
  101. raw_spin_lock_irqsave(&desc->lock, flags);
  102. desc->irq_data.msi_desc = entry;
  103. if (entry)
  104. entry->irq = irq;
  105. raw_spin_unlock_irqrestore(&desc->lock, flags);
  106. return 0;
  107. }
  108. /**
  109. * set_irq_chip_data - set irq chip data for an irq
  110. * @irq: Interrupt number
  111. * @data: Pointer to chip specific data
  112. *
  113. * Set the hardware irq chip data for an irq
  114. */
  115. int set_irq_chip_data(unsigned int irq, void *data)
  116. {
  117. struct irq_desc *desc = irq_to_desc(irq);
  118. unsigned long flags;
  119. if (!desc) {
  120. printk(KERN_ERR
  121. "Trying to install chip data for IRQ%d\n", irq);
  122. return -EINVAL;
  123. }
  124. if (!desc->irq_data.chip) {
  125. printk(KERN_ERR "BUG: bad set_irq_chip_data(IRQ#%d)\n", irq);
  126. return -EINVAL;
  127. }
  128. raw_spin_lock_irqsave(&desc->lock, flags);
  129. desc->irq_data.chip_data = data;
  130. raw_spin_unlock_irqrestore(&desc->lock, flags);
  131. return 0;
  132. }
  133. EXPORT_SYMBOL(set_irq_chip_data);
  134. struct irq_data *irq_get_irq_data(unsigned int irq)
  135. {
  136. struct irq_desc *desc = irq_to_desc(irq);
  137. return desc ? &desc->irq_data : NULL;
  138. }
  139. EXPORT_SYMBOL_GPL(irq_get_irq_data);
  140. /**
  141. * set_irq_nested_thread - Set/Reset the IRQ_NESTED_THREAD flag of an irq
  142. *
  143. * @irq: Interrupt number
  144. * @nest: 0 to clear / 1 to set the IRQ_NESTED_THREAD flag
  145. *
  146. * The IRQ_NESTED_THREAD flag indicates that on
  147. * request_threaded_irq() no separate interrupt thread should be
  148. * created for the irq as the handler are called nested in the
  149. * context of a demultiplexing interrupt handler thread.
  150. */
  151. void set_irq_nested_thread(unsigned int irq, int nest)
  152. {
  153. struct irq_desc *desc = irq_to_desc(irq);
  154. unsigned long flags;
  155. if (!desc)
  156. return;
  157. raw_spin_lock_irqsave(&desc->lock, flags);
  158. if (nest)
  159. desc->status |= IRQ_NESTED_THREAD;
  160. else
  161. desc->status &= ~IRQ_NESTED_THREAD;
  162. raw_spin_unlock_irqrestore(&desc->lock, flags);
  163. }
  164. EXPORT_SYMBOL_GPL(set_irq_nested_thread);
  165. /*
  166. * default enable function
  167. */
  168. static void default_enable(struct irq_data *data)
  169. {
  170. struct irq_desc *desc = irq_data_to_desc(data);
  171. desc->irq_data.chip->irq_unmask(&desc->irq_data);
  172. desc->status &= ~IRQ_MASKED;
  173. }
  174. /*
  175. * default disable function
  176. */
  177. static void default_disable(struct irq_data *data)
  178. {
  179. }
  180. /*
  181. * default startup function
  182. */
  183. static unsigned int default_startup(struct irq_data *data)
  184. {
  185. struct irq_desc *desc = irq_data_to_desc(data);
  186. desc->irq_data.chip->irq_enable(data);
  187. return 0;
  188. }
  189. /*
  190. * default shutdown function
  191. */
  192. static void default_shutdown(struct irq_data *data)
  193. {
  194. struct irq_desc *desc = irq_data_to_desc(data);
  195. desc->irq_data.chip->irq_mask(&desc->irq_data);
  196. desc->status |= IRQ_MASKED;
  197. }
  198. #ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
  199. /* Temporary migration helpers */
  200. static void compat_irq_mask(struct irq_data *data)
  201. {
  202. data->chip->mask(data->irq);
  203. }
  204. static void compat_irq_unmask(struct irq_data *data)
  205. {
  206. data->chip->unmask(data->irq);
  207. }
  208. static void compat_irq_ack(struct irq_data *data)
  209. {
  210. data->chip->ack(data->irq);
  211. }
  212. static void compat_irq_mask_ack(struct irq_data *data)
  213. {
  214. data->chip->mask_ack(data->irq);
  215. }
  216. static void compat_irq_eoi(struct irq_data *data)
  217. {
  218. data->chip->eoi(data->irq);
  219. }
  220. static void compat_irq_enable(struct irq_data *data)
  221. {
  222. data->chip->enable(data->irq);
  223. }
  224. static void compat_irq_disable(struct irq_data *data)
  225. {
  226. data->chip->disable(data->irq);
  227. }
  228. static void compat_irq_shutdown(struct irq_data *data)
  229. {
  230. data->chip->shutdown(data->irq);
  231. }
  232. static unsigned int compat_irq_startup(struct irq_data *data)
  233. {
  234. return data->chip->startup(data->irq);
  235. }
  236. static int compat_irq_set_affinity(struct irq_data *data,
  237. const struct cpumask *dest, bool force)
  238. {
  239. return data->chip->set_affinity(data->irq, dest);
  240. }
  241. static int compat_irq_set_type(struct irq_data *data, unsigned int type)
  242. {
  243. return data->chip->set_type(data->irq, type);
  244. }
  245. static int compat_irq_set_wake(struct irq_data *data, unsigned int on)
  246. {
  247. return data->chip->set_wake(data->irq, on);
  248. }
  249. static int compat_irq_retrigger(struct irq_data *data)
  250. {
  251. return data->chip->retrigger(data->irq);
  252. }
  253. static void compat_bus_lock(struct irq_data *data)
  254. {
  255. data->chip->bus_lock(data->irq);
  256. }
  257. static void compat_bus_sync_unlock(struct irq_data *data)
  258. {
  259. data->chip->bus_sync_unlock(data->irq);
  260. }
  261. #endif
  262. /*
  263. * Fixup enable/disable function pointers
  264. */
  265. void irq_chip_set_defaults(struct irq_chip *chip)
  266. {
  267. #ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
  268. /*
  269. * Compat fixup functions need to be before we set the
  270. * defaults for enable/disable/startup/shutdown
  271. */
  272. if (chip->enable)
  273. chip->irq_enable = compat_irq_enable;
  274. if (chip->disable)
  275. chip->irq_disable = compat_irq_disable;
  276. if (chip->shutdown)
  277. chip->irq_shutdown = compat_irq_shutdown;
  278. if (chip->startup)
  279. chip->irq_startup = compat_irq_startup;
  280. #endif
  281. /*
  282. * The real defaults
  283. */
  284. if (!chip->irq_enable)
  285. chip->irq_enable = default_enable;
  286. if (!chip->irq_disable)
  287. chip->irq_disable = default_disable;
  288. if (!chip->irq_startup)
  289. chip->irq_startup = default_startup;
  290. /*
  291. * We use chip->irq_disable, when the user provided its own. When
  292. * we have default_disable set for chip->irq_disable, then we need
  293. * to use default_shutdown, otherwise the irq line is not
  294. * disabled on free_irq():
  295. */
  296. if (!chip->irq_shutdown)
  297. chip->irq_shutdown = chip->irq_disable != default_disable ?
  298. chip->irq_disable : default_shutdown;
  299. #ifndef CONFIG_GENERIC_HARDIRQS_NO_DEPRECATED
  300. if (!chip->end)
  301. chip->end = dummy_irq_chip.end;
  302. /*
  303. * Now fix up the remaining compat handlers
  304. */
  305. if (chip->bus_lock)
  306. chip->irq_bus_lock = compat_bus_lock;
  307. if (chip->bus_sync_unlock)
  308. chip->irq_bus_sync_unlock = compat_bus_sync_unlock;
  309. if (chip->mask)
  310. chip->irq_mask = compat_irq_mask;
  311. if (chip->unmask)
  312. chip->irq_unmask = compat_irq_unmask;
  313. if (chip->ack)
  314. chip->irq_ack = compat_irq_ack;
  315. if (chip->mask_ack)
  316. chip->irq_mask_ack = compat_irq_mask_ack;
  317. if (chip->eoi)
  318. chip->irq_eoi = compat_irq_eoi;
  319. if (chip->set_affinity)
  320. chip->irq_set_affinity = compat_irq_set_affinity;
  321. if (chip->set_type)
  322. chip->irq_set_type = compat_irq_set_type;
  323. if (chip->set_wake)
  324. chip->irq_set_wake = compat_irq_set_wake;
  325. if (chip->retrigger)
  326. chip->irq_retrigger = compat_irq_retrigger;
  327. #endif
  328. }
  329. static inline void mask_ack_irq(struct irq_desc *desc)
  330. {
  331. if (desc->irq_data.chip->irq_mask_ack)
  332. desc->irq_data.chip->irq_mask_ack(&desc->irq_data);
  333. else {
  334. desc->irq_data.chip->irq_mask(&desc->irq_data);
  335. if (desc->irq_data.chip->irq_ack)
  336. desc->irq_data.chip->irq_ack(&desc->irq_data);
  337. }
  338. desc->status |= IRQ_MASKED;
  339. }
  340. static inline void mask_irq(struct irq_desc *desc)
  341. {
  342. if (desc->irq_data.chip->irq_mask) {
  343. desc->irq_data.chip->irq_mask(&desc->irq_data);
  344. desc->status |= IRQ_MASKED;
  345. }
  346. }
  347. static inline void unmask_irq(struct irq_desc *desc)
  348. {
  349. if (desc->irq_data.chip->irq_unmask) {
  350. desc->irq_data.chip->irq_unmask(&desc->irq_data);
  351. desc->status &= ~IRQ_MASKED;
  352. }
  353. }
  354. /*
  355. * handle_nested_irq - Handle a nested irq from a irq thread
  356. * @irq: the interrupt number
  357. *
  358. * Handle interrupts which are nested into a threaded interrupt
  359. * handler. The handler function is called inside the calling
  360. * threads context.
  361. */
  362. void handle_nested_irq(unsigned int irq)
  363. {
  364. struct irq_desc *desc = irq_to_desc(irq);
  365. struct irqaction *action;
  366. irqreturn_t action_ret;
  367. might_sleep();
  368. raw_spin_lock_irq(&desc->lock);
  369. kstat_incr_irqs_this_cpu(irq, desc);
  370. action = desc->action;
  371. if (unlikely(!action || (desc->status & IRQ_DISABLED)))
  372. goto out_unlock;
  373. desc->status |= IRQ_INPROGRESS;
  374. raw_spin_unlock_irq(&desc->lock);
  375. action_ret = action->thread_fn(action->irq, action->dev_id);
  376. if (!noirqdebug)
  377. note_interrupt(irq, desc, action_ret);
  378. raw_spin_lock_irq(&desc->lock);
  379. desc->status &= ~IRQ_INPROGRESS;
  380. out_unlock:
  381. raw_spin_unlock_irq(&desc->lock);
  382. }
  383. EXPORT_SYMBOL_GPL(handle_nested_irq);
  384. /**
  385. * handle_simple_irq - Simple and software-decoded IRQs.
  386. * @irq: the interrupt number
  387. * @desc: the interrupt description structure for this irq
  388. *
  389. * Simple interrupts are either sent from a demultiplexing interrupt
  390. * handler or come from hardware, where no interrupt hardware control
  391. * is necessary.
  392. *
  393. * Note: The caller is expected to handle the ack, clear, mask and
  394. * unmask issues if necessary.
  395. */
  396. void
  397. handle_simple_irq(unsigned int irq, struct irq_desc *desc)
  398. {
  399. struct irqaction *action;
  400. irqreturn_t action_ret;
  401. raw_spin_lock(&desc->lock);
  402. if (unlikely(desc->status & IRQ_INPROGRESS))
  403. goto out_unlock;
  404. desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
  405. kstat_incr_irqs_this_cpu(irq, desc);
  406. action = desc->action;
  407. if (unlikely(!action || (desc->status & IRQ_DISABLED)))
  408. goto out_unlock;
  409. desc->status |= IRQ_INPROGRESS;
  410. raw_spin_unlock(&desc->lock);
  411. action_ret = handle_IRQ_event(irq, action);
  412. if (!noirqdebug)
  413. note_interrupt(irq, desc, action_ret);
  414. raw_spin_lock(&desc->lock);
  415. desc->status &= ~IRQ_INPROGRESS;
  416. out_unlock:
  417. raw_spin_unlock(&desc->lock);
  418. }
  419. /**
  420. * handle_level_irq - Level type irq handler
  421. * @irq: the interrupt number
  422. * @desc: the interrupt description structure for this irq
  423. *
  424. * Level type interrupts are active as long as the hardware line has
  425. * the active level. This may require to mask the interrupt and unmask
  426. * it after the associated handler has acknowledged the device, so the
  427. * interrupt line is back to inactive.
  428. */
  429. void
  430. handle_level_irq(unsigned int irq, struct irq_desc *desc)
  431. {
  432. struct irqaction *action;
  433. irqreturn_t action_ret;
  434. raw_spin_lock(&desc->lock);
  435. mask_ack_irq(desc);
  436. if (unlikely(desc->status & IRQ_INPROGRESS))
  437. goto out_unlock;
  438. desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
  439. kstat_incr_irqs_this_cpu(irq, desc);
  440. /*
  441. * If its disabled or no action available
  442. * keep it masked and get out of here
  443. */
  444. action = desc->action;
  445. if (unlikely(!action || (desc->status & IRQ_DISABLED)))
  446. goto out_unlock;
  447. desc->status |= IRQ_INPROGRESS;
  448. raw_spin_unlock(&desc->lock);
  449. action_ret = handle_IRQ_event(irq, action);
  450. if (!noirqdebug)
  451. note_interrupt(irq, desc, action_ret);
  452. raw_spin_lock(&desc->lock);
  453. desc->status &= ~IRQ_INPROGRESS;
  454. if (!(desc->status & (IRQ_DISABLED | IRQ_ONESHOT)))
  455. unmask_irq(desc);
  456. out_unlock:
  457. raw_spin_unlock(&desc->lock);
  458. }
  459. EXPORT_SYMBOL_GPL(handle_level_irq);
  460. /**
  461. * handle_fasteoi_irq - irq handler for transparent controllers
  462. * @irq: the interrupt number
  463. * @desc: the interrupt description structure for this irq
  464. *
  465. * Only a single callback will be issued to the chip: an ->eoi()
  466. * call when the interrupt has been serviced. This enables support
  467. * for modern forms of interrupt handlers, which handle the flow
  468. * details in hardware, transparently.
  469. */
  470. void
  471. handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
  472. {
  473. struct irqaction *action;
  474. irqreturn_t action_ret;
  475. raw_spin_lock(&desc->lock);
  476. if (unlikely(desc->status & IRQ_INPROGRESS))
  477. goto out;
  478. desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
  479. kstat_incr_irqs_this_cpu(irq, desc);
  480. /*
  481. * If its disabled or no action available
  482. * then mask it and get out of here:
  483. */
  484. action = desc->action;
  485. if (unlikely(!action || (desc->status & IRQ_DISABLED))) {
  486. desc->status |= IRQ_PENDING;
  487. mask_irq(desc);
  488. goto out;
  489. }
  490. desc->status |= IRQ_INPROGRESS;
  491. desc->status &= ~IRQ_PENDING;
  492. raw_spin_unlock(&desc->lock);
  493. action_ret = handle_IRQ_event(irq, action);
  494. if (!noirqdebug)
  495. note_interrupt(irq, desc, action_ret);
  496. raw_spin_lock(&desc->lock);
  497. desc->status &= ~IRQ_INPROGRESS;
  498. out:
  499. desc->irq_data.chip->irq_eoi(&desc->irq_data);
  500. raw_spin_unlock(&desc->lock);
  501. }
  502. /**
  503. * handle_edge_irq - edge type IRQ handler
  504. * @irq: the interrupt number
  505. * @desc: the interrupt description structure for this irq
  506. *
  507. * Interrupt occures on the falling and/or rising edge of a hardware
  508. * signal. The occurence is latched into the irq controller hardware
  509. * and must be acked in order to be reenabled. After the ack another
  510. * interrupt can happen on the same source even before the first one
  511. * is handled by the associated event handler. If this happens it
  512. * might be necessary to disable (mask) the interrupt depending on the
  513. * controller hardware. This requires to reenable the interrupt inside
  514. * of the loop which handles the interrupts which have arrived while
  515. * the handler was running. If all pending interrupts are handled, the
  516. * loop is left.
  517. */
  518. void
  519. handle_edge_irq(unsigned int irq, struct irq_desc *desc)
  520. {
  521. raw_spin_lock(&desc->lock);
  522. desc->status &= ~(IRQ_REPLAY | IRQ_WAITING);
  523. /*
  524. * If we're currently running this IRQ, or its disabled,
  525. * we shouldn't process the IRQ. Mark it pending, handle
  526. * the necessary masking and go out
  527. */
  528. if (unlikely((desc->status & (IRQ_INPROGRESS | IRQ_DISABLED)) ||
  529. !desc->action)) {
  530. desc->status |= (IRQ_PENDING | IRQ_MASKED);
  531. mask_ack_irq(desc);
  532. goto out_unlock;
  533. }
  534. kstat_incr_irqs_this_cpu(irq, desc);
  535. /* Start handling the irq */
  536. desc->irq_data.chip->irq_ack(&desc->irq_data);
  537. /* Mark the IRQ currently in progress.*/
  538. desc->status |= IRQ_INPROGRESS;
  539. do {
  540. struct irqaction *action = desc->action;
  541. irqreturn_t action_ret;
  542. if (unlikely(!action)) {
  543. mask_irq(desc);
  544. goto out_unlock;
  545. }
  546. /*
  547. * When another irq arrived while we were handling
  548. * one, we could have masked the irq.
  549. * Renable it, if it was not disabled in meantime.
  550. */
  551. if (unlikely((desc->status &
  552. (IRQ_PENDING | IRQ_MASKED | IRQ_DISABLED)) ==
  553. (IRQ_PENDING | IRQ_MASKED))) {
  554. unmask_irq(desc);
  555. }
  556. desc->status &= ~IRQ_PENDING;
  557. raw_spin_unlock(&desc->lock);
  558. action_ret = handle_IRQ_event(irq, action);
  559. if (!noirqdebug)
  560. note_interrupt(irq, desc, action_ret);
  561. raw_spin_lock(&desc->lock);
  562. } while ((desc->status & (IRQ_PENDING | IRQ_DISABLED)) == IRQ_PENDING);
  563. desc->status &= ~IRQ_INPROGRESS;
  564. out_unlock:
  565. raw_spin_unlock(&desc->lock);
  566. }
  567. /**
  568. * handle_percpu_irq - Per CPU local irq handler
  569. * @irq: the interrupt number
  570. * @desc: the interrupt description structure for this irq
  571. *
  572. * Per CPU interrupts on SMP machines without locking requirements
  573. */
  574. void
  575. handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
  576. {
  577. irqreturn_t action_ret;
  578. kstat_incr_irqs_this_cpu(irq, desc);
  579. if (desc->irq_data.chip->irq_ack)
  580. desc->irq_data.chip->irq_ack(&desc->irq_data);
  581. action_ret = handle_IRQ_event(irq, desc->action);
  582. if (!noirqdebug)
  583. note_interrupt(irq, desc, action_ret);
  584. if (desc->irq_data.chip->irq_eoi)
  585. desc->irq_data.chip->irq_eoi(&desc->irq_data);
  586. }
  587. void
  588. __set_irq_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
  589. const char *name)
  590. {
  591. struct irq_desc *desc = irq_to_desc(irq);
  592. unsigned long flags;
  593. if (!desc) {
  594. printk(KERN_ERR
  595. "Trying to install type control for IRQ%d\n", irq);
  596. return;
  597. }
  598. if (!handle)
  599. handle = handle_bad_irq;
  600. else if (desc->irq_data.chip == &no_irq_chip) {
  601. printk(KERN_WARNING "Trying to install %sinterrupt handler "
  602. "for IRQ%d\n", is_chained ? "chained " : "", irq);
  603. /*
  604. * Some ARM implementations install a handler for really dumb
  605. * interrupt hardware without setting an irq_chip. This worked
  606. * with the ARM no_irq_chip but the check in setup_irq would
  607. * prevent us to setup the interrupt at all. Switch it to
  608. * dummy_irq_chip for easy transition.
  609. */
  610. desc->irq_data.chip = &dummy_irq_chip;
  611. }
  612. chip_bus_lock(desc);
  613. raw_spin_lock_irqsave(&desc->lock, flags);
  614. /* Uninstall? */
  615. if (handle == handle_bad_irq) {
  616. if (desc->irq_data.chip != &no_irq_chip)
  617. mask_ack_irq(desc);
  618. desc->status |= IRQ_DISABLED;
  619. desc->depth = 1;
  620. }
  621. desc->handle_irq = handle;
  622. desc->name = name;
  623. if (handle != handle_bad_irq && is_chained) {
  624. desc->status &= ~IRQ_DISABLED;
  625. desc->status |= IRQ_NOREQUEST | IRQ_NOPROBE;
  626. desc->depth = 0;
  627. desc->irq_data.chip->irq_startup(&desc->irq_data);
  628. }
  629. raw_spin_unlock_irqrestore(&desc->lock, flags);
  630. chip_bus_sync_unlock(desc);
  631. }
  632. EXPORT_SYMBOL_GPL(__set_irq_handler);
  633. void
  634. set_irq_chip_and_handler(unsigned int irq, struct irq_chip *chip,
  635. irq_flow_handler_t handle)
  636. {
  637. set_irq_chip(irq, chip);
  638. __set_irq_handler(irq, handle, 0, NULL);
  639. }
  640. void
  641. set_irq_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
  642. irq_flow_handler_t handle, const char *name)
  643. {
  644. set_irq_chip(irq, chip);
  645. __set_irq_handler(irq, handle, 0, name);
  646. }
  647. void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set)
  648. {
  649. struct irq_desc *desc = irq_to_desc(irq);
  650. unsigned long flags;
  651. if (!desc)
  652. return;
  653. /* Sanitize flags */
  654. set &= IRQF_MODIFY_MASK;
  655. clr &= IRQF_MODIFY_MASK;
  656. raw_spin_lock_irqsave(&desc->lock, flags);
  657. desc->status &= ~clr;
  658. desc->status |= set;
  659. raw_spin_unlock_irqrestore(&desc->lock, flags);
  660. }