chip.c 19 KB

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