chip.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820
  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 <trace/events/irq.h>
  18. #include "internals.h"
  19. /**
  20. * irq_set_chip - set the irq chip for an irq
  21. * @irq: irq number
  22. * @chip: pointer to irq chip description structure
  23. */
  24. int irq_set_chip(unsigned int irq, struct irq_chip *chip)
  25. {
  26. unsigned long flags;
  27. struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
  28. if (!desc)
  29. return -EINVAL;
  30. if (!chip)
  31. chip = &no_irq_chip;
  32. desc->irq_data.chip = chip;
  33. irq_put_desc_unlock(desc, flags);
  34. /*
  35. * For !CONFIG_SPARSE_IRQ make the irq show up in
  36. * allocated_irqs. For the CONFIG_SPARSE_IRQ case, it is
  37. * already marked, and this call is harmless.
  38. */
  39. irq_reserve_irq(irq);
  40. return 0;
  41. }
  42. EXPORT_SYMBOL(irq_set_chip);
  43. /**
  44. * irq_set_type - set the irq trigger type for an irq
  45. * @irq: irq number
  46. * @type: IRQ_TYPE_{LEVEL,EDGE}_* value - see include/linux/irq.h
  47. */
  48. int irq_set_irq_type(unsigned int irq, unsigned int type)
  49. {
  50. unsigned long flags;
  51. struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, IRQ_GET_DESC_CHECK_GLOBAL);
  52. int ret = 0;
  53. if (!desc)
  54. return -EINVAL;
  55. type &= IRQ_TYPE_SENSE_MASK;
  56. ret = __irq_set_trigger(desc, irq, type);
  57. irq_put_desc_busunlock(desc, flags);
  58. return ret;
  59. }
  60. EXPORT_SYMBOL(irq_set_irq_type);
  61. /**
  62. * irq_set_handler_data - set irq handler data for an irq
  63. * @irq: Interrupt number
  64. * @data: Pointer to interrupt specific data
  65. *
  66. * Set the hardware irq controller data for an irq
  67. */
  68. int irq_set_handler_data(unsigned int irq, void *data)
  69. {
  70. unsigned long flags;
  71. struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
  72. if (!desc)
  73. return -EINVAL;
  74. desc->irq_data.handler_data = data;
  75. irq_put_desc_unlock(desc, flags);
  76. return 0;
  77. }
  78. EXPORT_SYMBOL(irq_set_handler_data);
  79. /**
  80. * irq_set_msi_desc_off - set MSI descriptor data for an irq at offset
  81. * @irq_base: Interrupt number base
  82. * @irq_offset: Interrupt number offset
  83. * @entry: Pointer to MSI descriptor data
  84. *
  85. * Set the MSI descriptor entry for an irq at offset
  86. */
  87. int irq_set_msi_desc_off(unsigned int irq_base, unsigned int irq_offset,
  88. struct msi_desc *entry)
  89. {
  90. unsigned long flags;
  91. struct irq_desc *desc = irq_get_desc_lock(irq_base + irq_offset, &flags, IRQ_GET_DESC_CHECK_GLOBAL);
  92. if (!desc)
  93. return -EINVAL;
  94. desc->irq_data.msi_desc = entry;
  95. if (entry && !irq_offset)
  96. entry->irq = irq_base;
  97. irq_put_desc_unlock(desc, flags);
  98. return 0;
  99. }
  100. /**
  101. * irq_set_msi_desc - set MSI descriptor data for an irq
  102. * @irq: Interrupt number
  103. * @entry: Pointer to MSI descriptor data
  104. *
  105. * Set the MSI descriptor entry for an irq
  106. */
  107. int irq_set_msi_desc(unsigned int irq, struct msi_desc *entry)
  108. {
  109. return irq_set_msi_desc_off(irq, 0, entry);
  110. }
  111. /**
  112. * irq_set_chip_data - set irq chip data for an irq
  113. * @irq: Interrupt number
  114. * @data: Pointer to chip specific data
  115. *
  116. * Set the hardware irq chip data for an irq
  117. */
  118. int irq_set_chip_data(unsigned int irq, void *data)
  119. {
  120. unsigned long flags;
  121. struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
  122. if (!desc)
  123. return -EINVAL;
  124. desc->irq_data.chip_data = data;
  125. irq_put_desc_unlock(desc, flags);
  126. return 0;
  127. }
  128. EXPORT_SYMBOL(irq_set_chip_data);
  129. struct irq_data *irq_get_irq_data(unsigned int irq)
  130. {
  131. struct irq_desc *desc = irq_to_desc(irq);
  132. return desc ? &desc->irq_data : NULL;
  133. }
  134. EXPORT_SYMBOL_GPL(irq_get_irq_data);
  135. static void irq_state_clr_disabled(struct irq_desc *desc)
  136. {
  137. irqd_clear(&desc->irq_data, IRQD_IRQ_DISABLED);
  138. }
  139. static void irq_state_set_disabled(struct irq_desc *desc)
  140. {
  141. irqd_set(&desc->irq_data, IRQD_IRQ_DISABLED);
  142. }
  143. static void irq_state_clr_masked(struct irq_desc *desc)
  144. {
  145. irqd_clear(&desc->irq_data, IRQD_IRQ_MASKED);
  146. }
  147. static void irq_state_set_masked(struct irq_desc *desc)
  148. {
  149. irqd_set(&desc->irq_data, IRQD_IRQ_MASKED);
  150. }
  151. int irq_startup(struct irq_desc *desc, bool resend)
  152. {
  153. int ret = 0;
  154. irq_state_clr_disabled(desc);
  155. desc->depth = 0;
  156. if (desc->irq_data.chip->irq_startup) {
  157. ret = desc->irq_data.chip->irq_startup(&desc->irq_data);
  158. irq_state_clr_masked(desc);
  159. } else {
  160. irq_enable(desc);
  161. }
  162. if (resend)
  163. check_irq_resend(desc, desc->irq_data.irq);
  164. return ret;
  165. }
  166. void irq_shutdown(struct irq_desc *desc)
  167. {
  168. irq_state_set_disabled(desc);
  169. desc->depth = 1;
  170. if (desc->irq_data.chip->irq_shutdown)
  171. desc->irq_data.chip->irq_shutdown(&desc->irq_data);
  172. else if (desc->irq_data.chip->irq_disable)
  173. desc->irq_data.chip->irq_disable(&desc->irq_data);
  174. else
  175. desc->irq_data.chip->irq_mask(&desc->irq_data);
  176. irq_state_set_masked(desc);
  177. }
  178. void irq_enable(struct irq_desc *desc)
  179. {
  180. irq_state_clr_disabled(desc);
  181. if (desc->irq_data.chip->irq_enable)
  182. desc->irq_data.chip->irq_enable(&desc->irq_data);
  183. else
  184. desc->irq_data.chip->irq_unmask(&desc->irq_data);
  185. irq_state_clr_masked(desc);
  186. }
  187. /**
  188. * irq_disable - Mark interrupt disabled
  189. * @desc: irq descriptor which should be disabled
  190. *
  191. * If the chip does not implement the irq_disable callback, we
  192. * use a lazy disable approach. That means we mark the interrupt
  193. * disabled, but leave the hardware unmasked. That's an
  194. * optimization because we avoid the hardware access for the
  195. * common case where no interrupt happens after we marked it
  196. * disabled. If an interrupt happens, then the interrupt flow
  197. * handler masks the line at the hardware level and marks it
  198. * pending.
  199. */
  200. void irq_disable(struct irq_desc *desc)
  201. {
  202. irq_state_set_disabled(desc);
  203. if (desc->irq_data.chip->irq_disable) {
  204. desc->irq_data.chip->irq_disable(&desc->irq_data);
  205. irq_state_set_masked(desc);
  206. }
  207. }
  208. void irq_percpu_enable(struct irq_desc *desc, unsigned int cpu)
  209. {
  210. if (desc->irq_data.chip->irq_enable)
  211. desc->irq_data.chip->irq_enable(&desc->irq_data);
  212. else
  213. desc->irq_data.chip->irq_unmask(&desc->irq_data);
  214. cpumask_set_cpu(cpu, desc->percpu_enabled);
  215. }
  216. void irq_percpu_disable(struct irq_desc *desc, unsigned int cpu)
  217. {
  218. if (desc->irq_data.chip->irq_disable)
  219. desc->irq_data.chip->irq_disable(&desc->irq_data);
  220. else
  221. desc->irq_data.chip->irq_mask(&desc->irq_data);
  222. cpumask_clear_cpu(cpu, desc->percpu_enabled);
  223. }
  224. static inline void mask_ack_irq(struct irq_desc *desc)
  225. {
  226. if (desc->irq_data.chip->irq_mask_ack)
  227. desc->irq_data.chip->irq_mask_ack(&desc->irq_data);
  228. else {
  229. desc->irq_data.chip->irq_mask(&desc->irq_data);
  230. if (desc->irq_data.chip->irq_ack)
  231. desc->irq_data.chip->irq_ack(&desc->irq_data);
  232. }
  233. irq_state_set_masked(desc);
  234. }
  235. void mask_irq(struct irq_desc *desc)
  236. {
  237. if (desc->irq_data.chip->irq_mask) {
  238. desc->irq_data.chip->irq_mask(&desc->irq_data);
  239. irq_state_set_masked(desc);
  240. }
  241. }
  242. void unmask_irq(struct irq_desc *desc)
  243. {
  244. if (desc->irq_data.chip->irq_unmask) {
  245. desc->irq_data.chip->irq_unmask(&desc->irq_data);
  246. irq_state_clr_masked(desc);
  247. }
  248. }
  249. void unmask_threaded_irq(struct irq_desc *desc)
  250. {
  251. struct irq_chip *chip = desc->irq_data.chip;
  252. if (chip->flags & IRQCHIP_EOI_THREADED)
  253. chip->irq_eoi(&desc->irq_data);
  254. if (chip->irq_unmask) {
  255. chip->irq_unmask(&desc->irq_data);
  256. irq_state_clr_masked(desc);
  257. }
  258. }
  259. /*
  260. * handle_nested_irq - Handle a nested irq from a irq thread
  261. * @irq: the interrupt number
  262. *
  263. * Handle interrupts which are nested into a threaded interrupt
  264. * handler. The handler function is called inside the calling
  265. * threads context.
  266. */
  267. void handle_nested_irq(unsigned int irq)
  268. {
  269. struct irq_desc *desc = irq_to_desc(irq);
  270. struct irqaction *action;
  271. irqreturn_t action_ret;
  272. might_sleep();
  273. raw_spin_lock_irq(&desc->lock);
  274. desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
  275. kstat_incr_irqs_this_cpu(irq, desc);
  276. action = desc->action;
  277. if (unlikely(!action || irqd_irq_disabled(&desc->irq_data))) {
  278. desc->istate |= IRQS_PENDING;
  279. goto out_unlock;
  280. }
  281. irqd_set(&desc->irq_data, IRQD_IRQ_INPROGRESS);
  282. raw_spin_unlock_irq(&desc->lock);
  283. action_ret = action->thread_fn(action->irq, action->dev_id);
  284. if (!noirqdebug)
  285. note_interrupt(irq, desc, action_ret);
  286. raw_spin_lock_irq(&desc->lock);
  287. irqd_clear(&desc->irq_data, IRQD_IRQ_INPROGRESS);
  288. out_unlock:
  289. raw_spin_unlock_irq(&desc->lock);
  290. }
  291. EXPORT_SYMBOL_GPL(handle_nested_irq);
  292. static bool irq_check_poll(struct irq_desc *desc)
  293. {
  294. if (!(desc->istate & IRQS_POLL_INPROGRESS))
  295. return false;
  296. return irq_wait_for_poll(desc);
  297. }
  298. /**
  299. * handle_simple_irq - Simple and software-decoded IRQs.
  300. * @irq: the interrupt number
  301. * @desc: the interrupt description structure for this irq
  302. *
  303. * Simple interrupts are either sent from a demultiplexing interrupt
  304. * handler or come from hardware, where no interrupt hardware control
  305. * is necessary.
  306. *
  307. * Note: The caller is expected to handle the ack, clear, mask and
  308. * unmask issues if necessary.
  309. */
  310. void
  311. handle_simple_irq(unsigned int irq, struct irq_desc *desc)
  312. {
  313. raw_spin_lock(&desc->lock);
  314. if (unlikely(irqd_irq_inprogress(&desc->irq_data)))
  315. if (!irq_check_poll(desc))
  316. goto out_unlock;
  317. desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
  318. kstat_incr_irqs_this_cpu(irq, desc);
  319. if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
  320. desc->istate |= IRQS_PENDING;
  321. goto out_unlock;
  322. }
  323. handle_irq_event(desc);
  324. out_unlock:
  325. raw_spin_unlock(&desc->lock);
  326. }
  327. EXPORT_SYMBOL_GPL(handle_simple_irq);
  328. /*
  329. * Called unconditionally from handle_level_irq() and only for oneshot
  330. * interrupts from handle_fasteoi_irq()
  331. */
  332. static void cond_unmask_irq(struct irq_desc *desc)
  333. {
  334. /*
  335. * We need to unmask in the following cases:
  336. * - Standard level irq (IRQF_ONESHOT is not set)
  337. * - Oneshot irq which did not wake the thread (caused by a
  338. * spurious interrupt or a primary handler handling it
  339. * completely).
  340. */
  341. if (!irqd_irq_disabled(&desc->irq_data) &&
  342. irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot)
  343. unmask_irq(desc);
  344. }
  345. /**
  346. * handle_level_irq - Level type irq handler
  347. * @irq: the interrupt number
  348. * @desc: the interrupt description structure for this irq
  349. *
  350. * Level type interrupts are active as long as the hardware line has
  351. * the active level. This may require to mask the interrupt and unmask
  352. * it after the associated handler has acknowledged the device, so the
  353. * interrupt line is back to inactive.
  354. */
  355. void
  356. handle_level_irq(unsigned int irq, struct irq_desc *desc)
  357. {
  358. raw_spin_lock(&desc->lock);
  359. mask_ack_irq(desc);
  360. if (unlikely(irqd_irq_inprogress(&desc->irq_data)))
  361. if (!irq_check_poll(desc))
  362. goto out_unlock;
  363. desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
  364. kstat_incr_irqs_this_cpu(irq, desc);
  365. /*
  366. * If its disabled or no action available
  367. * keep it masked and get out of here
  368. */
  369. if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
  370. desc->istate |= IRQS_PENDING;
  371. goto out_unlock;
  372. }
  373. handle_irq_event(desc);
  374. cond_unmask_irq(desc);
  375. out_unlock:
  376. raw_spin_unlock(&desc->lock);
  377. }
  378. EXPORT_SYMBOL_GPL(handle_level_irq);
  379. #ifdef CONFIG_IRQ_PREFLOW_FASTEOI
  380. static inline void preflow_handler(struct irq_desc *desc)
  381. {
  382. if (desc->preflow_handler)
  383. desc->preflow_handler(&desc->irq_data);
  384. }
  385. #else
  386. static inline void preflow_handler(struct irq_desc *desc) { }
  387. #endif
  388. static void cond_unmask_eoi_irq(struct irq_desc *desc, struct irq_chip *chip)
  389. {
  390. if (!(desc->istate & IRQS_ONESHOT)) {
  391. chip->irq_eoi(&desc->irq_data);
  392. return;
  393. }
  394. /*
  395. * We need to unmask in the following cases:
  396. * - Oneshot irq which did not wake the thread (caused by a
  397. * spurious interrupt or a primary handler handling it
  398. * completely).
  399. */
  400. if (!irqd_irq_disabled(&desc->irq_data) &&
  401. irqd_irq_masked(&desc->irq_data) && !desc->threads_oneshot) {
  402. chip->irq_eoi(&desc->irq_data);
  403. unmask_irq(desc);
  404. } else if (!(chip->flags & IRQCHIP_EOI_THREADED)) {
  405. chip->irq_eoi(&desc->irq_data);
  406. }
  407. }
  408. /**
  409. * handle_fasteoi_irq - irq handler for transparent controllers
  410. * @irq: the interrupt number
  411. * @desc: the interrupt description structure for this irq
  412. *
  413. * Only a single callback will be issued to the chip: an ->eoi()
  414. * call when the interrupt has been serviced. This enables support
  415. * for modern forms of interrupt handlers, which handle the flow
  416. * details in hardware, transparently.
  417. */
  418. void
  419. handle_fasteoi_irq(unsigned int irq, struct irq_desc *desc)
  420. {
  421. struct irq_chip *chip = desc->irq_data.chip;
  422. raw_spin_lock(&desc->lock);
  423. if (unlikely(irqd_irq_inprogress(&desc->irq_data)))
  424. if (!irq_check_poll(desc))
  425. goto out;
  426. desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
  427. kstat_incr_irqs_this_cpu(irq, desc);
  428. /*
  429. * If its disabled or no action available
  430. * then mask it and get out of here:
  431. */
  432. if (unlikely(!desc->action || irqd_irq_disabled(&desc->irq_data))) {
  433. desc->istate |= IRQS_PENDING;
  434. mask_irq(desc);
  435. goto out;
  436. }
  437. if (desc->istate & IRQS_ONESHOT)
  438. mask_irq(desc);
  439. preflow_handler(desc);
  440. handle_irq_event(desc);
  441. cond_unmask_eoi_irq(desc, chip);
  442. raw_spin_unlock(&desc->lock);
  443. return;
  444. out:
  445. if (!(chip->flags & IRQCHIP_EOI_IF_HANDLED))
  446. chip->irq_eoi(&desc->irq_data);
  447. raw_spin_unlock(&desc->lock);
  448. }
  449. /**
  450. * handle_edge_irq - edge type IRQ handler
  451. * @irq: the interrupt number
  452. * @desc: the interrupt description structure for this irq
  453. *
  454. * Interrupt occures on the falling and/or rising edge of a hardware
  455. * signal. The occurrence is latched into the irq controller hardware
  456. * and must be acked in order to be reenabled. After the ack another
  457. * interrupt can happen on the same source even before the first one
  458. * is handled by the associated event handler. If this happens it
  459. * might be necessary to disable (mask) the interrupt depending on the
  460. * controller hardware. This requires to reenable the interrupt inside
  461. * of the loop which handles the interrupts which have arrived while
  462. * the handler was running. If all pending interrupts are handled, the
  463. * loop is left.
  464. */
  465. void
  466. handle_edge_irq(unsigned int irq, struct irq_desc *desc)
  467. {
  468. raw_spin_lock(&desc->lock);
  469. desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
  470. /*
  471. * If we're currently running this IRQ, or its disabled,
  472. * we shouldn't process the IRQ. Mark it pending, handle
  473. * the necessary masking and go out
  474. */
  475. if (unlikely(irqd_irq_disabled(&desc->irq_data) ||
  476. irqd_irq_inprogress(&desc->irq_data) || !desc->action)) {
  477. if (!irq_check_poll(desc)) {
  478. desc->istate |= IRQS_PENDING;
  479. mask_ack_irq(desc);
  480. goto out_unlock;
  481. }
  482. }
  483. kstat_incr_irqs_this_cpu(irq, desc);
  484. /* Start handling the irq */
  485. desc->irq_data.chip->irq_ack(&desc->irq_data);
  486. do {
  487. if (unlikely(!desc->action)) {
  488. mask_irq(desc);
  489. goto out_unlock;
  490. }
  491. /*
  492. * When another irq arrived while we were handling
  493. * one, we could have masked the irq.
  494. * Renable it, if it was not disabled in meantime.
  495. */
  496. if (unlikely(desc->istate & IRQS_PENDING)) {
  497. if (!irqd_irq_disabled(&desc->irq_data) &&
  498. irqd_irq_masked(&desc->irq_data))
  499. unmask_irq(desc);
  500. }
  501. handle_irq_event(desc);
  502. } while ((desc->istate & IRQS_PENDING) &&
  503. !irqd_irq_disabled(&desc->irq_data));
  504. out_unlock:
  505. raw_spin_unlock(&desc->lock);
  506. }
  507. EXPORT_SYMBOL(handle_edge_irq);
  508. #ifdef CONFIG_IRQ_EDGE_EOI_HANDLER
  509. /**
  510. * handle_edge_eoi_irq - edge eoi type IRQ handler
  511. * @irq: the interrupt number
  512. * @desc: the interrupt description structure for this irq
  513. *
  514. * Similar as the above handle_edge_irq, but using eoi and w/o the
  515. * mask/unmask logic.
  516. */
  517. void handle_edge_eoi_irq(unsigned int irq, struct irq_desc *desc)
  518. {
  519. struct irq_chip *chip = irq_desc_get_chip(desc);
  520. raw_spin_lock(&desc->lock);
  521. desc->istate &= ~(IRQS_REPLAY | IRQS_WAITING);
  522. /*
  523. * If we're currently running this IRQ, or its disabled,
  524. * we shouldn't process the IRQ. Mark it pending, handle
  525. * the necessary masking and go out
  526. */
  527. if (unlikely(irqd_irq_disabled(&desc->irq_data) ||
  528. irqd_irq_inprogress(&desc->irq_data) || !desc->action)) {
  529. if (!irq_check_poll(desc)) {
  530. desc->istate |= IRQS_PENDING;
  531. goto out_eoi;
  532. }
  533. }
  534. kstat_incr_irqs_this_cpu(irq, desc);
  535. do {
  536. if (unlikely(!desc->action))
  537. goto out_eoi;
  538. handle_irq_event(desc);
  539. } while ((desc->istate & IRQS_PENDING) &&
  540. !irqd_irq_disabled(&desc->irq_data));
  541. out_eoi:
  542. chip->irq_eoi(&desc->irq_data);
  543. raw_spin_unlock(&desc->lock);
  544. }
  545. #endif
  546. /**
  547. * handle_percpu_irq - Per CPU local irq handler
  548. * @irq: the interrupt number
  549. * @desc: the interrupt description structure for this irq
  550. *
  551. * Per CPU interrupts on SMP machines without locking requirements
  552. */
  553. void
  554. handle_percpu_irq(unsigned int irq, struct irq_desc *desc)
  555. {
  556. struct irq_chip *chip = irq_desc_get_chip(desc);
  557. kstat_incr_irqs_this_cpu(irq, desc);
  558. if (chip->irq_ack)
  559. chip->irq_ack(&desc->irq_data);
  560. handle_irq_event_percpu(desc, desc->action);
  561. if (chip->irq_eoi)
  562. chip->irq_eoi(&desc->irq_data);
  563. }
  564. /**
  565. * handle_percpu_devid_irq - Per CPU local irq handler with per cpu dev ids
  566. * @irq: the interrupt number
  567. * @desc: the interrupt description structure for this irq
  568. *
  569. * Per CPU interrupts on SMP machines without locking requirements. Same as
  570. * handle_percpu_irq() above but with the following extras:
  571. *
  572. * action->percpu_dev_id is a pointer to percpu variables which
  573. * contain the real device id for the cpu on which this handler is
  574. * called
  575. */
  576. void handle_percpu_devid_irq(unsigned int irq, struct irq_desc *desc)
  577. {
  578. struct irq_chip *chip = irq_desc_get_chip(desc);
  579. struct irqaction *action = desc->action;
  580. void *dev_id = __this_cpu_ptr(action->percpu_dev_id);
  581. irqreturn_t res;
  582. kstat_incr_irqs_this_cpu(irq, desc);
  583. if (chip->irq_ack)
  584. chip->irq_ack(&desc->irq_data);
  585. trace_irq_handler_entry(irq, action);
  586. res = action->handler(irq, dev_id);
  587. trace_irq_handler_exit(irq, action, res);
  588. if (chip->irq_eoi)
  589. chip->irq_eoi(&desc->irq_data);
  590. }
  591. void
  592. __irq_set_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
  593. const char *name)
  594. {
  595. unsigned long flags;
  596. struct irq_desc *desc = irq_get_desc_buslock(irq, &flags, 0);
  597. if (!desc)
  598. return;
  599. if (!handle) {
  600. handle = handle_bad_irq;
  601. } else {
  602. if (WARN_ON(desc->irq_data.chip == &no_irq_chip))
  603. goto out;
  604. }
  605. /* Uninstall? */
  606. if (handle == handle_bad_irq) {
  607. if (desc->irq_data.chip != &no_irq_chip)
  608. mask_ack_irq(desc);
  609. irq_state_set_disabled(desc);
  610. desc->depth = 1;
  611. }
  612. desc->handle_irq = handle;
  613. desc->name = name;
  614. if (handle != handle_bad_irq && is_chained) {
  615. irq_settings_set_noprobe(desc);
  616. irq_settings_set_norequest(desc);
  617. irq_settings_set_nothread(desc);
  618. irq_startup(desc, true);
  619. }
  620. out:
  621. irq_put_desc_busunlock(desc, flags);
  622. }
  623. EXPORT_SYMBOL_GPL(__irq_set_handler);
  624. void
  625. irq_set_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
  626. irq_flow_handler_t handle, const char *name)
  627. {
  628. irq_set_chip(irq, chip);
  629. __irq_set_handler(irq, handle, 0, name);
  630. }
  631. EXPORT_SYMBOL_GPL(irq_set_chip_and_handler_name);
  632. void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set)
  633. {
  634. unsigned long flags;
  635. struct irq_desc *desc = irq_get_desc_lock(irq, &flags, 0);
  636. if (!desc)
  637. return;
  638. irq_settings_clr_and_set(desc, clr, set);
  639. irqd_clear(&desc->irq_data, IRQD_NO_BALANCING | IRQD_PER_CPU |
  640. IRQD_TRIGGER_MASK | IRQD_LEVEL | IRQD_MOVE_PCNTXT);
  641. if (irq_settings_has_no_balance_set(desc))
  642. irqd_set(&desc->irq_data, IRQD_NO_BALANCING);
  643. if (irq_settings_is_per_cpu(desc))
  644. irqd_set(&desc->irq_data, IRQD_PER_CPU);
  645. if (irq_settings_can_move_pcntxt(desc))
  646. irqd_set(&desc->irq_data, IRQD_MOVE_PCNTXT);
  647. if (irq_settings_is_level(desc))
  648. irqd_set(&desc->irq_data, IRQD_LEVEL);
  649. irqd_set(&desc->irq_data, irq_settings_get_trigger_mask(desc));
  650. irq_put_desc_unlock(desc, flags);
  651. }
  652. EXPORT_SYMBOL_GPL(irq_modify_status);
  653. /**
  654. * irq_cpu_online - Invoke all irq_cpu_online functions.
  655. *
  656. * Iterate through all irqs and invoke the chip.irq_cpu_online()
  657. * for each.
  658. */
  659. void irq_cpu_online(void)
  660. {
  661. struct irq_desc *desc;
  662. struct irq_chip *chip;
  663. unsigned long flags;
  664. unsigned int irq;
  665. for_each_active_irq(irq) {
  666. desc = irq_to_desc(irq);
  667. if (!desc)
  668. continue;
  669. raw_spin_lock_irqsave(&desc->lock, flags);
  670. chip = irq_data_get_irq_chip(&desc->irq_data);
  671. if (chip && chip->irq_cpu_online &&
  672. (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) ||
  673. !irqd_irq_disabled(&desc->irq_data)))
  674. chip->irq_cpu_online(&desc->irq_data);
  675. raw_spin_unlock_irqrestore(&desc->lock, flags);
  676. }
  677. }
  678. /**
  679. * irq_cpu_offline - Invoke all irq_cpu_offline functions.
  680. *
  681. * Iterate through all irqs and invoke the chip.irq_cpu_offline()
  682. * for each.
  683. */
  684. void irq_cpu_offline(void)
  685. {
  686. struct irq_desc *desc;
  687. struct irq_chip *chip;
  688. unsigned long flags;
  689. unsigned int irq;
  690. for_each_active_irq(irq) {
  691. desc = irq_to_desc(irq);
  692. if (!desc)
  693. continue;
  694. raw_spin_lock_irqsave(&desc->lock, flags);
  695. chip = irq_data_get_irq_chip(&desc->irq_data);
  696. if (chip && chip->irq_cpu_offline &&
  697. (!(chip->flags & IRQCHIP_ONOFFLINE_ENABLED) ||
  698. !irqd_irq_disabled(&desc->irq_data)))
  699. chip->irq_cpu_offline(&desc->irq_data);
  700. raw_spin_unlock_irqrestore(&desc->lock, flags);
  701. }
  702. }