irqdesc.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  1. /*
  2. * Copyright (C) 1992, 1998-2006 Linus Torvalds, Ingo Molnar
  3. * Copyright (C) 2005-2006, Thomas Gleixner, Russell King
  4. *
  5. * This file contains the interrupt descriptor management code
  6. *
  7. * Detailed information is available in Documentation/DocBook/genericirq
  8. *
  9. */
  10. #include <linux/irq.h>
  11. #include <linux/slab.h>
  12. #include <linux/export.h>
  13. #include <linux/interrupt.h>
  14. #include <linux/kernel_stat.h>
  15. #include <linux/radix-tree.h>
  16. #include <linux/bitmap.h>
  17. #include <linux/irqdomain.h>
  18. #include "internals.h"
  19. /*
  20. * lockdep: we want to handle all irq_desc locks as a single lock-class:
  21. */
  22. static struct lock_class_key irq_desc_lock_class;
  23. #if defined(CONFIG_SMP)
  24. static int __init irq_affinity_setup(char *str)
  25. {
  26. zalloc_cpumask_var(&irq_default_affinity, GFP_NOWAIT);
  27. cpulist_parse(str, irq_default_affinity);
  28. /*
  29. * Set at least the boot cpu. We don't want to end up with
  30. * bugreports caused by random comandline masks
  31. */
  32. cpumask_set_cpu(smp_processor_id(), irq_default_affinity);
  33. return 1;
  34. }
  35. __setup("irqaffinity=", irq_affinity_setup);
  36. static void __init init_irq_default_affinity(void)
  37. {
  38. #ifdef CONFIG_CPUMASK_OFFSTACK
  39. if (!irq_default_affinity)
  40. zalloc_cpumask_var(&irq_default_affinity, GFP_NOWAIT);
  41. #endif
  42. if (cpumask_empty(irq_default_affinity))
  43. cpumask_setall(irq_default_affinity);
  44. }
  45. #else
  46. static void __init init_irq_default_affinity(void)
  47. {
  48. }
  49. #endif
  50. #ifdef CONFIG_SMP
  51. static int alloc_masks(struct irq_desc *desc, gfp_t gfp, int node)
  52. {
  53. if (!zalloc_cpumask_var_node(&desc->irq_common_data.affinity,
  54. gfp, node))
  55. return -ENOMEM;
  56. #ifdef CONFIG_GENERIC_PENDING_IRQ
  57. if (!zalloc_cpumask_var_node(&desc->pending_mask, gfp, node)) {
  58. free_cpumask_var(desc->irq_common_data.affinity);
  59. return -ENOMEM;
  60. }
  61. #endif
  62. return 0;
  63. }
  64. static void desc_smp_init(struct irq_desc *desc, int node,
  65. const struct cpumask *affinity)
  66. {
  67. if (!affinity)
  68. affinity = irq_default_affinity;
  69. cpumask_copy(desc->irq_common_data.affinity, affinity);
  70. #ifdef CONFIG_GENERIC_PENDING_IRQ
  71. cpumask_clear(desc->pending_mask);
  72. #endif
  73. #ifdef CONFIG_NUMA
  74. desc->irq_common_data.node = node;
  75. #endif
  76. }
  77. #else
  78. static inline int
  79. alloc_masks(struct irq_desc *desc, gfp_t gfp, int node) { return 0; }
  80. static inline void
  81. desc_smp_init(struct irq_desc *desc, int node, const struct cpumask *affinity) { }
  82. #endif
  83. static void desc_set_defaults(unsigned int irq, struct irq_desc *desc, int node,
  84. const struct cpumask *affinity, struct module *owner)
  85. {
  86. int cpu;
  87. desc->irq_common_data.handler_data = NULL;
  88. desc->irq_common_data.msi_desc = NULL;
  89. desc->irq_data.common = &desc->irq_common_data;
  90. desc->irq_data.irq = irq;
  91. desc->irq_data.chip = &no_irq_chip;
  92. desc->irq_data.chip_data = NULL;
  93. irq_settings_clr_and_set(desc, ~0, _IRQ_DEFAULT_INIT_FLAGS);
  94. irqd_set(&desc->irq_data, IRQD_IRQ_DISABLED);
  95. desc->handle_irq = handle_bad_irq;
  96. desc->depth = 1;
  97. desc->irq_count = 0;
  98. desc->irqs_unhandled = 0;
  99. desc->name = NULL;
  100. desc->owner = owner;
  101. for_each_possible_cpu(cpu)
  102. *per_cpu_ptr(desc->kstat_irqs, cpu) = 0;
  103. desc_smp_init(desc, node, affinity);
  104. }
  105. int nr_irqs = NR_IRQS;
  106. EXPORT_SYMBOL_GPL(nr_irqs);
  107. static DEFINE_MUTEX(sparse_irq_lock);
  108. static DECLARE_BITMAP(allocated_irqs, IRQ_BITMAP_BITS);
  109. #ifdef CONFIG_SPARSE_IRQ
  110. static RADIX_TREE(irq_desc_tree, GFP_KERNEL);
  111. static void irq_insert_desc(unsigned int irq, struct irq_desc *desc)
  112. {
  113. radix_tree_insert(&irq_desc_tree, irq, desc);
  114. }
  115. struct irq_desc *irq_to_desc(unsigned int irq)
  116. {
  117. return radix_tree_lookup(&irq_desc_tree, irq);
  118. }
  119. EXPORT_SYMBOL(irq_to_desc);
  120. static void delete_irq_desc(unsigned int irq)
  121. {
  122. radix_tree_delete(&irq_desc_tree, irq);
  123. }
  124. #ifdef CONFIG_SMP
  125. static void free_masks(struct irq_desc *desc)
  126. {
  127. #ifdef CONFIG_GENERIC_PENDING_IRQ
  128. free_cpumask_var(desc->pending_mask);
  129. #endif
  130. free_cpumask_var(desc->irq_common_data.affinity);
  131. }
  132. #else
  133. static inline void free_masks(struct irq_desc *desc) { }
  134. #endif
  135. void irq_lock_sparse(void)
  136. {
  137. mutex_lock(&sparse_irq_lock);
  138. }
  139. void irq_unlock_sparse(void)
  140. {
  141. mutex_unlock(&sparse_irq_lock);
  142. }
  143. static struct irq_desc *alloc_desc(int irq, int node, unsigned int flags,
  144. const struct cpumask *affinity,
  145. struct module *owner)
  146. {
  147. struct irq_desc *desc;
  148. gfp_t gfp = GFP_KERNEL;
  149. desc = kzalloc_node(sizeof(*desc), gfp, node);
  150. if (!desc)
  151. return NULL;
  152. /* allocate based on nr_cpu_ids */
  153. desc->kstat_irqs = alloc_percpu(unsigned int);
  154. if (!desc->kstat_irqs)
  155. goto err_desc;
  156. if (alloc_masks(desc, gfp, node))
  157. goto err_kstat;
  158. raw_spin_lock_init(&desc->lock);
  159. lockdep_set_class(&desc->lock, &irq_desc_lock_class);
  160. init_rcu_head(&desc->rcu);
  161. desc_set_defaults(irq, desc, node, affinity, owner);
  162. irqd_set(&desc->irq_data, flags);
  163. return desc;
  164. err_kstat:
  165. free_percpu(desc->kstat_irqs);
  166. err_desc:
  167. kfree(desc);
  168. return NULL;
  169. }
  170. static void delayed_free_desc(struct rcu_head *rhp)
  171. {
  172. struct irq_desc *desc = container_of(rhp, struct irq_desc, rcu);
  173. free_masks(desc);
  174. free_percpu(desc->kstat_irqs);
  175. kfree(desc);
  176. }
  177. static void free_desc(unsigned int irq)
  178. {
  179. struct irq_desc *desc = irq_to_desc(irq);
  180. unregister_irq_proc(irq, desc);
  181. /*
  182. * sparse_irq_lock protects also show_interrupts() and
  183. * kstat_irq_usr(). Once we deleted the descriptor from the
  184. * sparse tree we can free it. Access in proc will fail to
  185. * lookup the descriptor.
  186. */
  187. mutex_lock(&sparse_irq_lock);
  188. delete_irq_desc(irq);
  189. mutex_unlock(&sparse_irq_lock);
  190. /*
  191. * We free the descriptor, masks and stat fields via RCU. That
  192. * allows demultiplex interrupts to do rcu based management of
  193. * the child interrupts.
  194. */
  195. call_rcu(&desc->rcu, delayed_free_desc);
  196. }
  197. static int alloc_descs(unsigned int start, unsigned int cnt, int node,
  198. const struct cpumask *affinity, struct module *owner)
  199. {
  200. const struct cpumask *mask = NULL;
  201. struct irq_desc *desc;
  202. unsigned int flags;
  203. int i, cpu = -1;
  204. if (affinity && cpumask_empty(affinity))
  205. return -EINVAL;
  206. flags = affinity ? IRQD_AFFINITY_MANAGED : 0;
  207. for (i = 0; i < cnt; i++) {
  208. if (affinity) {
  209. cpu = cpumask_next(cpu, affinity);
  210. if (cpu >= nr_cpu_ids)
  211. cpu = cpumask_first(affinity);
  212. node = cpu_to_node(cpu);
  213. /*
  214. * For single allocations we use the caller provided
  215. * mask otherwise we use the mask of the target cpu
  216. */
  217. mask = cnt == 1 ? affinity : cpumask_of(cpu);
  218. }
  219. desc = alloc_desc(start + i, node, flags, mask, owner);
  220. if (!desc)
  221. goto err;
  222. mutex_lock(&sparse_irq_lock);
  223. irq_insert_desc(start + i, desc);
  224. mutex_unlock(&sparse_irq_lock);
  225. }
  226. return start;
  227. err:
  228. for (i--; i >= 0; i--)
  229. free_desc(start + i);
  230. mutex_lock(&sparse_irq_lock);
  231. bitmap_clear(allocated_irqs, start, cnt);
  232. mutex_unlock(&sparse_irq_lock);
  233. return -ENOMEM;
  234. }
  235. static int irq_expand_nr_irqs(unsigned int nr)
  236. {
  237. if (nr > IRQ_BITMAP_BITS)
  238. return -ENOMEM;
  239. nr_irqs = nr;
  240. return 0;
  241. }
  242. int __init early_irq_init(void)
  243. {
  244. int i, initcnt, node = first_online_node;
  245. struct irq_desc *desc;
  246. init_irq_default_affinity();
  247. /* Let arch update nr_irqs and return the nr of preallocated irqs */
  248. initcnt = arch_probe_nr_irqs();
  249. printk(KERN_INFO "NR_IRQS:%d nr_irqs:%d %d\n", NR_IRQS, nr_irqs, initcnt);
  250. if (WARN_ON(nr_irqs > IRQ_BITMAP_BITS))
  251. nr_irqs = IRQ_BITMAP_BITS;
  252. if (WARN_ON(initcnt > IRQ_BITMAP_BITS))
  253. initcnt = IRQ_BITMAP_BITS;
  254. if (initcnt > nr_irqs)
  255. nr_irqs = initcnt;
  256. for (i = 0; i < initcnt; i++) {
  257. desc = alloc_desc(i, node, 0, NULL, NULL);
  258. set_bit(i, allocated_irqs);
  259. irq_insert_desc(i, desc);
  260. }
  261. return arch_early_irq_init();
  262. }
  263. #else /* !CONFIG_SPARSE_IRQ */
  264. struct irq_desc irq_desc[NR_IRQS] __cacheline_aligned_in_smp = {
  265. [0 ... NR_IRQS-1] = {
  266. .handle_irq = handle_bad_irq,
  267. .depth = 1,
  268. .lock = __RAW_SPIN_LOCK_UNLOCKED(irq_desc->lock),
  269. }
  270. };
  271. int __init early_irq_init(void)
  272. {
  273. int count, i, node = first_online_node;
  274. struct irq_desc *desc;
  275. init_irq_default_affinity();
  276. printk(KERN_INFO "NR_IRQS:%d\n", NR_IRQS);
  277. desc = irq_desc;
  278. count = ARRAY_SIZE(irq_desc);
  279. for (i = 0; i < count; i++) {
  280. desc[i].kstat_irqs = alloc_percpu(unsigned int);
  281. alloc_masks(&desc[i], GFP_KERNEL, node);
  282. raw_spin_lock_init(&desc[i].lock);
  283. lockdep_set_class(&desc[i].lock, &irq_desc_lock_class);
  284. desc_set_defaults(i, &desc[i], node, NULL, NULL);
  285. }
  286. return arch_early_irq_init();
  287. }
  288. struct irq_desc *irq_to_desc(unsigned int irq)
  289. {
  290. return (irq < NR_IRQS) ? irq_desc + irq : NULL;
  291. }
  292. EXPORT_SYMBOL(irq_to_desc);
  293. static void free_desc(unsigned int irq)
  294. {
  295. struct irq_desc *desc = irq_to_desc(irq);
  296. unsigned long flags;
  297. raw_spin_lock_irqsave(&desc->lock, flags);
  298. desc_set_defaults(irq, desc, irq_desc_get_node(desc), NULL, NULL);
  299. raw_spin_unlock_irqrestore(&desc->lock, flags);
  300. }
  301. static inline int alloc_descs(unsigned int start, unsigned int cnt, int node,
  302. const struct cpumask *affinity,
  303. struct module *owner)
  304. {
  305. u32 i;
  306. for (i = 0; i < cnt; i++) {
  307. struct irq_desc *desc = irq_to_desc(start + i);
  308. desc->owner = owner;
  309. }
  310. return start;
  311. }
  312. static int irq_expand_nr_irqs(unsigned int nr)
  313. {
  314. return -ENOMEM;
  315. }
  316. void irq_mark_irq(unsigned int irq)
  317. {
  318. mutex_lock(&sparse_irq_lock);
  319. bitmap_set(allocated_irqs, irq, 1);
  320. mutex_unlock(&sparse_irq_lock);
  321. }
  322. #ifdef CONFIG_GENERIC_IRQ_LEGACY
  323. void irq_init_desc(unsigned int irq)
  324. {
  325. free_desc(irq);
  326. }
  327. #endif
  328. #endif /* !CONFIG_SPARSE_IRQ */
  329. /**
  330. * generic_handle_irq - Invoke the handler for a particular irq
  331. * @irq: The irq number to handle
  332. *
  333. */
  334. int generic_handle_irq(unsigned int irq)
  335. {
  336. struct irq_desc *desc = irq_to_desc(irq);
  337. if (!desc)
  338. return -EINVAL;
  339. generic_handle_irq_desc(desc);
  340. return 0;
  341. }
  342. EXPORT_SYMBOL_GPL(generic_handle_irq);
  343. #ifdef CONFIG_HANDLE_DOMAIN_IRQ
  344. /**
  345. * __handle_domain_irq - Invoke the handler for a HW irq belonging to a domain
  346. * @domain: The domain where to perform the lookup
  347. * @hwirq: The HW irq number to convert to a logical one
  348. * @lookup: Whether to perform the domain lookup or not
  349. * @regs: Register file coming from the low-level handling code
  350. *
  351. * Returns: 0 on success, or -EINVAL if conversion has failed
  352. */
  353. int __handle_domain_irq(struct irq_domain *domain, unsigned int hwirq,
  354. bool lookup, struct pt_regs *regs)
  355. {
  356. struct pt_regs *old_regs = set_irq_regs(regs);
  357. unsigned int irq = hwirq;
  358. int ret = 0;
  359. irq_enter();
  360. #ifdef CONFIG_IRQ_DOMAIN
  361. if (lookup)
  362. irq = irq_find_mapping(domain, hwirq);
  363. #endif
  364. /*
  365. * Some hardware gives randomly wrong interrupts. Rather
  366. * than crashing, do something sensible.
  367. */
  368. if (unlikely(!irq || irq >= nr_irqs)) {
  369. ack_bad_irq(irq);
  370. ret = -EINVAL;
  371. } else {
  372. generic_handle_irq(irq);
  373. }
  374. irq_exit();
  375. set_irq_regs(old_regs);
  376. return ret;
  377. }
  378. #endif
  379. /* Dynamic interrupt handling */
  380. /**
  381. * irq_free_descs - free irq descriptors
  382. * @from: Start of descriptor range
  383. * @cnt: Number of consecutive irqs to free
  384. */
  385. void irq_free_descs(unsigned int from, unsigned int cnt)
  386. {
  387. int i;
  388. if (from >= nr_irqs || (from + cnt) > nr_irqs)
  389. return;
  390. for (i = 0; i < cnt; i++)
  391. free_desc(from + i);
  392. mutex_lock(&sparse_irq_lock);
  393. bitmap_clear(allocated_irqs, from, cnt);
  394. mutex_unlock(&sparse_irq_lock);
  395. }
  396. EXPORT_SYMBOL_GPL(irq_free_descs);
  397. /**
  398. * irq_alloc_descs - allocate and initialize a range of irq descriptors
  399. * @irq: Allocate for specific irq number if irq >= 0
  400. * @from: Start the search from this irq number
  401. * @cnt: Number of consecutive irqs to allocate.
  402. * @node: Preferred node on which the irq descriptor should be allocated
  403. * @owner: Owning module (can be NULL)
  404. * @affinity: Optional pointer to an affinity mask which hints where the
  405. * irq descriptors should be allocated and which default
  406. * affinities to use
  407. *
  408. * Returns the first irq number or error code
  409. */
  410. int __ref
  411. __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
  412. struct module *owner, const struct cpumask *affinity)
  413. {
  414. int start, ret;
  415. if (!cnt)
  416. return -EINVAL;
  417. if (irq >= 0) {
  418. if (from > irq)
  419. return -EINVAL;
  420. from = irq;
  421. } else {
  422. /*
  423. * For interrupts which are freely allocated the
  424. * architecture can force a lower bound to the @from
  425. * argument. x86 uses this to exclude the GSI space.
  426. */
  427. from = arch_dynirq_lower_bound(from);
  428. }
  429. mutex_lock(&sparse_irq_lock);
  430. start = bitmap_find_next_zero_area(allocated_irqs, IRQ_BITMAP_BITS,
  431. from, cnt, 0);
  432. ret = -EEXIST;
  433. if (irq >=0 && start != irq)
  434. goto err;
  435. if (start + cnt > nr_irqs) {
  436. ret = irq_expand_nr_irqs(start + cnt);
  437. if (ret)
  438. goto err;
  439. }
  440. bitmap_set(allocated_irqs, start, cnt);
  441. mutex_unlock(&sparse_irq_lock);
  442. return alloc_descs(start, cnt, node, affinity, owner);
  443. err:
  444. mutex_unlock(&sparse_irq_lock);
  445. return ret;
  446. }
  447. EXPORT_SYMBOL_GPL(__irq_alloc_descs);
  448. #ifdef CONFIG_GENERIC_IRQ_LEGACY_ALLOC_HWIRQ
  449. /**
  450. * irq_alloc_hwirqs - Allocate an irq descriptor and initialize the hardware
  451. * @cnt: number of interrupts to allocate
  452. * @node: node on which to allocate
  453. *
  454. * Returns an interrupt number > 0 or 0, if the allocation fails.
  455. */
  456. unsigned int irq_alloc_hwirqs(int cnt, int node)
  457. {
  458. int i, irq = __irq_alloc_descs(-1, 0, cnt, node, NULL, NULL);
  459. if (irq < 0)
  460. return 0;
  461. for (i = irq; cnt > 0; i++, cnt--) {
  462. if (arch_setup_hwirq(i, node))
  463. goto err;
  464. irq_clear_status_flags(i, _IRQ_NOREQUEST);
  465. }
  466. return irq;
  467. err:
  468. for (i--; i >= irq; i--) {
  469. irq_set_status_flags(i, _IRQ_NOREQUEST | _IRQ_NOPROBE);
  470. arch_teardown_hwirq(i);
  471. }
  472. irq_free_descs(irq, cnt);
  473. return 0;
  474. }
  475. EXPORT_SYMBOL_GPL(irq_alloc_hwirqs);
  476. /**
  477. * irq_free_hwirqs - Free irq descriptor and cleanup the hardware
  478. * @from: Free from irq number
  479. * @cnt: number of interrupts to free
  480. *
  481. */
  482. void irq_free_hwirqs(unsigned int from, int cnt)
  483. {
  484. int i, j;
  485. for (i = from, j = cnt; j > 0; i++, j--) {
  486. irq_set_status_flags(i, _IRQ_NOREQUEST | _IRQ_NOPROBE);
  487. arch_teardown_hwirq(i);
  488. }
  489. irq_free_descs(from, cnt);
  490. }
  491. EXPORT_SYMBOL_GPL(irq_free_hwirqs);
  492. #endif
  493. /**
  494. * irq_get_next_irq - get next allocated irq number
  495. * @offset: where to start the search
  496. *
  497. * Returns next irq number after offset or nr_irqs if none is found.
  498. */
  499. unsigned int irq_get_next_irq(unsigned int offset)
  500. {
  501. return find_next_bit(allocated_irqs, nr_irqs, offset);
  502. }
  503. struct irq_desc *
  504. __irq_get_desc_lock(unsigned int irq, unsigned long *flags, bool bus,
  505. unsigned int check)
  506. {
  507. struct irq_desc *desc = irq_to_desc(irq);
  508. if (desc) {
  509. if (check & _IRQ_DESC_CHECK) {
  510. if ((check & _IRQ_DESC_PERCPU) &&
  511. !irq_settings_is_per_cpu_devid(desc))
  512. return NULL;
  513. if (!(check & _IRQ_DESC_PERCPU) &&
  514. irq_settings_is_per_cpu_devid(desc))
  515. return NULL;
  516. }
  517. if (bus)
  518. chip_bus_lock(desc);
  519. raw_spin_lock_irqsave(&desc->lock, *flags);
  520. }
  521. return desc;
  522. }
  523. void __irq_put_desc_unlock(struct irq_desc *desc, unsigned long flags, bool bus)
  524. {
  525. raw_spin_unlock_irqrestore(&desc->lock, flags);
  526. if (bus)
  527. chip_bus_sync_unlock(desc);
  528. }
  529. int irq_set_percpu_devid_partition(unsigned int irq,
  530. const struct cpumask *affinity)
  531. {
  532. struct irq_desc *desc = irq_to_desc(irq);
  533. if (!desc)
  534. return -EINVAL;
  535. if (desc->percpu_enabled)
  536. return -EINVAL;
  537. desc->percpu_enabled = kzalloc(sizeof(*desc->percpu_enabled), GFP_KERNEL);
  538. if (!desc->percpu_enabled)
  539. return -ENOMEM;
  540. if (affinity)
  541. desc->percpu_affinity = affinity;
  542. else
  543. desc->percpu_affinity = cpu_possible_mask;
  544. irq_set_percpu_devid_flags(irq);
  545. return 0;
  546. }
  547. int irq_set_percpu_devid(unsigned int irq)
  548. {
  549. return irq_set_percpu_devid_partition(irq, NULL);
  550. }
  551. int irq_get_percpu_devid_partition(unsigned int irq, struct cpumask *affinity)
  552. {
  553. struct irq_desc *desc = irq_to_desc(irq);
  554. if (!desc || !desc->percpu_enabled)
  555. return -EINVAL;
  556. if (affinity)
  557. cpumask_copy(affinity, desc->percpu_affinity);
  558. return 0;
  559. }
  560. void kstat_incr_irq_this_cpu(unsigned int irq)
  561. {
  562. kstat_incr_irqs_this_cpu(irq_to_desc(irq));
  563. }
  564. /**
  565. * kstat_irqs_cpu - Get the statistics for an interrupt on a cpu
  566. * @irq: The interrupt number
  567. * @cpu: The cpu number
  568. *
  569. * Returns the sum of interrupt counts on @cpu since boot for
  570. * @irq. The caller must ensure that the interrupt is not removed
  571. * concurrently.
  572. */
  573. unsigned int kstat_irqs_cpu(unsigned int irq, int cpu)
  574. {
  575. struct irq_desc *desc = irq_to_desc(irq);
  576. return desc && desc->kstat_irqs ?
  577. *per_cpu_ptr(desc->kstat_irqs, cpu) : 0;
  578. }
  579. /**
  580. * kstat_irqs - Get the statistics for an interrupt
  581. * @irq: The interrupt number
  582. *
  583. * Returns the sum of interrupt counts on all cpus since boot for
  584. * @irq. The caller must ensure that the interrupt is not removed
  585. * concurrently.
  586. */
  587. unsigned int kstat_irqs(unsigned int irq)
  588. {
  589. struct irq_desc *desc = irq_to_desc(irq);
  590. int cpu;
  591. unsigned int sum = 0;
  592. if (!desc || !desc->kstat_irqs)
  593. return 0;
  594. for_each_possible_cpu(cpu)
  595. sum += *per_cpu_ptr(desc->kstat_irqs, cpu);
  596. return sum;
  597. }
  598. /**
  599. * kstat_irqs_usr - Get the statistics for an interrupt
  600. * @irq: The interrupt number
  601. *
  602. * Returns the sum of interrupt counts on all cpus since boot for
  603. * @irq. Contrary to kstat_irqs() this can be called from any
  604. * preemptible context. It's protected against concurrent removal of
  605. * an interrupt descriptor when sparse irqs are enabled.
  606. */
  607. unsigned int kstat_irqs_usr(unsigned int irq)
  608. {
  609. unsigned int sum;
  610. irq_lock_sparse();
  611. sum = kstat_irqs(irq);
  612. irq_unlock_sparse();
  613. return sum;
  614. }