irqdomain.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711
  1. #define pr_fmt(fmt) "irq: " fmt
  2. #include <linux/debugfs.h>
  3. #include <linux/hardirq.h>
  4. #include <linux/interrupt.h>
  5. #include <linux/irq.h>
  6. #include <linux/irqdesc.h>
  7. #include <linux/irqdomain.h>
  8. #include <linux/module.h>
  9. #include <linux/mutex.h>
  10. #include <linux/of.h>
  11. #include <linux/of_address.h>
  12. #include <linux/of_irq.h>
  13. #include <linux/topology.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/slab.h>
  16. #include <linux/smp.h>
  17. #include <linux/fs.h>
  18. static LIST_HEAD(irq_domain_list);
  19. static DEFINE_MUTEX(irq_domain_mutex);
  20. static DEFINE_MUTEX(revmap_trees_mutex);
  21. static struct irq_domain *irq_default_domain;
  22. /**
  23. * __irq_domain_add() - Allocate a new irq_domain data structure
  24. * @of_node: optional device-tree node of the interrupt controller
  25. * @size: Size of linear map; 0 for radix mapping only
  26. * @hwirq_max: Maximum number of interrupts supported by controller
  27. * @direct_max: Maximum value of direct maps; Use ~0 for no limit; 0 for no
  28. * direct mapping
  29. * @ops: map/unmap domain callbacks
  30. * @host_data: Controller private data pointer
  31. *
  32. * Allocates and initialize and irq_domain structure.
  33. * Returns pointer to IRQ domain, or NULL on failure.
  34. */
  35. struct irq_domain *__irq_domain_add(struct device_node *of_node, int size,
  36. irq_hw_number_t hwirq_max, int direct_max,
  37. const struct irq_domain_ops *ops,
  38. void *host_data)
  39. {
  40. struct irq_domain *domain;
  41. domain = kzalloc_node(sizeof(*domain) + (sizeof(unsigned int) * size),
  42. GFP_KERNEL, of_node_to_nid(of_node));
  43. if (WARN_ON(!domain))
  44. return NULL;
  45. /* Fill structure */
  46. INIT_RADIX_TREE(&domain->revmap_tree, GFP_KERNEL);
  47. domain->ops = ops;
  48. domain->host_data = host_data;
  49. domain->of_node = of_node_get(of_node);
  50. domain->hwirq_max = hwirq_max;
  51. domain->revmap_size = size;
  52. domain->revmap_direct_max_irq = direct_max;
  53. mutex_lock(&irq_domain_mutex);
  54. list_add(&domain->link, &irq_domain_list);
  55. mutex_unlock(&irq_domain_mutex);
  56. pr_debug("Added domain %s\n", domain->name);
  57. return domain;
  58. }
  59. EXPORT_SYMBOL_GPL(__irq_domain_add);
  60. /**
  61. * irq_domain_remove() - Remove an irq domain.
  62. * @domain: domain to remove
  63. *
  64. * This routine is used to remove an irq domain. The caller must ensure
  65. * that all mappings within the domain have been disposed of prior to
  66. * use, depending on the revmap type.
  67. */
  68. void irq_domain_remove(struct irq_domain *domain)
  69. {
  70. mutex_lock(&irq_domain_mutex);
  71. /*
  72. * radix_tree_delete() takes care of destroying the root
  73. * node when all entries are removed. Shout if there are
  74. * any mappings left.
  75. */
  76. WARN_ON(domain->revmap_tree.height);
  77. list_del(&domain->link);
  78. /*
  79. * If the going away domain is the default one, reset it.
  80. */
  81. if (unlikely(irq_default_domain == domain))
  82. irq_set_default_host(NULL);
  83. mutex_unlock(&irq_domain_mutex);
  84. pr_debug("Removed domain %s\n", domain->name);
  85. of_node_put(domain->of_node);
  86. kfree(domain);
  87. }
  88. EXPORT_SYMBOL_GPL(irq_domain_remove);
  89. /**
  90. * irq_domain_add_simple() - Register an irq_domain and optionally map a range of irqs
  91. * @of_node: pointer to interrupt controller's device tree node.
  92. * @size: total number of irqs in mapping
  93. * @first_irq: first number of irq block assigned to the domain,
  94. * pass zero to assign irqs on-the-fly. If first_irq is non-zero, then
  95. * pre-map all of the irqs in the domain to virqs starting at first_irq.
  96. * @ops: map/unmap domain callbacks
  97. * @host_data: Controller private data pointer
  98. *
  99. * Allocates an irq_domain, and optionally if first_irq is positive then also
  100. * allocate irq_descs and map all of the hwirqs to virqs starting at first_irq.
  101. *
  102. * This is intended to implement the expected behaviour for most
  103. * interrupt controllers. If device tree is used, then first_irq will be 0 and
  104. * irqs get mapped dynamically on the fly. However, if the controller requires
  105. * static virq assignments (non-DT boot) then it will set that up correctly.
  106. */
  107. struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
  108. unsigned int size,
  109. unsigned int first_irq,
  110. const struct irq_domain_ops *ops,
  111. void *host_data)
  112. {
  113. struct irq_domain *domain;
  114. domain = __irq_domain_add(of_node, size, size, 0, ops, host_data);
  115. if (!domain)
  116. return NULL;
  117. if (first_irq > 0) {
  118. if (IS_ENABLED(CONFIG_SPARSE_IRQ)) {
  119. /* attempt to allocated irq_descs */
  120. int rc = irq_alloc_descs(first_irq, first_irq, size,
  121. of_node_to_nid(of_node));
  122. if (rc < 0)
  123. pr_info("Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n",
  124. first_irq);
  125. }
  126. irq_domain_associate_many(domain, first_irq, 0, size);
  127. }
  128. return domain;
  129. }
  130. EXPORT_SYMBOL_GPL(irq_domain_add_simple);
  131. /**
  132. * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain.
  133. * @of_node: pointer to interrupt controller's device tree node.
  134. * @size: total number of irqs in legacy mapping
  135. * @first_irq: first number of irq block assigned to the domain
  136. * @first_hwirq: first hwirq number to use for the translation. Should normally
  137. * be '0', but a positive integer can be used if the effective
  138. * hwirqs numbering does not begin at zero.
  139. * @ops: map/unmap domain callbacks
  140. * @host_data: Controller private data pointer
  141. *
  142. * Note: the map() callback will be called before this function returns
  143. * for all legacy interrupts except 0 (which is always the invalid irq for
  144. * a legacy controller).
  145. */
  146. struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
  147. unsigned int size,
  148. unsigned int first_irq,
  149. irq_hw_number_t first_hwirq,
  150. const struct irq_domain_ops *ops,
  151. void *host_data)
  152. {
  153. struct irq_domain *domain;
  154. domain = __irq_domain_add(of_node, first_hwirq + size,
  155. first_hwirq + size, 0, ops, host_data);
  156. if (!domain)
  157. return NULL;
  158. irq_domain_associate_many(domain, first_irq, first_hwirq, size);
  159. return domain;
  160. }
  161. EXPORT_SYMBOL_GPL(irq_domain_add_legacy);
  162. /**
  163. * irq_find_host() - Locates a domain for a given device node
  164. * @node: device-tree node of the interrupt controller
  165. */
  166. struct irq_domain *irq_find_host(struct device_node *node)
  167. {
  168. struct irq_domain *h, *found = NULL;
  169. int rc;
  170. /* We might want to match the legacy controller last since
  171. * it might potentially be set to match all interrupts in
  172. * the absence of a device node. This isn't a problem so far
  173. * yet though...
  174. */
  175. mutex_lock(&irq_domain_mutex);
  176. list_for_each_entry(h, &irq_domain_list, link) {
  177. if (h->ops->match)
  178. rc = h->ops->match(h, node);
  179. else
  180. rc = (h->of_node != NULL) && (h->of_node == node);
  181. if (rc) {
  182. found = h;
  183. break;
  184. }
  185. }
  186. mutex_unlock(&irq_domain_mutex);
  187. return found;
  188. }
  189. EXPORT_SYMBOL_GPL(irq_find_host);
  190. /**
  191. * irq_set_default_host() - Set a "default" irq domain
  192. * @domain: default domain pointer
  193. *
  194. * For convenience, it's possible to set a "default" domain that will be used
  195. * whenever NULL is passed to irq_create_mapping(). It makes life easier for
  196. * platforms that want to manipulate a few hard coded interrupt numbers that
  197. * aren't properly represented in the device-tree.
  198. */
  199. void irq_set_default_host(struct irq_domain *domain)
  200. {
  201. pr_debug("Default domain set to @0x%p\n", domain);
  202. irq_default_domain = domain;
  203. }
  204. EXPORT_SYMBOL_GPL(irq_set_default_host);
  205. void irq_domain_disassociate(struct irq_domain *domain, unsigned int irq)
  206. {
  207. struct irq_data *irq_data = irq_get_irq_data(irq);
  208. irq_hw_number_t hwirq;
  209. if (WARN(!irq_data || irq_data->domain != domain,
  210. "virq%i doesn't exist; cannot disassociate\n", irq))
  211. return;
  212. hwirq = irq_data->hwirq;
  213. irq_set_status_flags(irq, IRQ_NOREQUEST);
  214. /* remove chip and handler */
  215. irq_set_chip_and_handler(irq, NULL, NULL);
  216. /* Make sure it's completed */
  217. synchronize_irq(irq);
  218. /* Tell the PIC about it */
  219. if (domain->ops->unmap)
  220. domain->ops->unmap(domain, irq);
  221. smp_mb();
  222. irq_data->domain = NULL;
  223. irq_data->hwirq = 0;
  224. /* Clear reverse map for this hwirq */
  225. if (hwirq < domain->revmap_size) {
  226. domain->linear_revmap[hwirq] = 0;
  227. } else {
  228. mutex_lock(&revmap_trees_mutex);
  229. radix_tree_delete(&domain->revmap_tree, hwirq);
  230. mutex_unlock(&revmap_trees_mutex);
  231. }
  232. }
  233. int irq_domain_associate(struct irq_domain *domain, unsigned int virq,
  234. irq_hw_number_t hwirq)
  235. {
  236. struct irq_data *irq_data = irq_get_irq_data(virq);
  237. int ret;
  238. if (WARN(hwirq >= domain->hwirq_max,
  239. "error: hwirq 0x%x is too large for %s\n", (int)hwirq, domain->name))
  240. return -EINVAL;
  241. if (WARN(!irq_data, "error: virq%i is not allocated", virq))
  242. return -EINVAL;
  243. if (WARN(irq_data->domain, "error: virq%i is already associated", virq))
  244. return -EINVAL;
  245. mutex_lock(&irq_domain_mutex);
  246. irq_data->hwirq = hwirq;
  247. irq_data->domain = domain;
  248. if (domain->ops->map) {
  249. ret = domain->ops->map(domain, virq, hwirq);
  250. if (ret != 0) {
  251. /*
  252. * If map() returns -EPERM, this interrupt is protected
  253. * by the firmware or some other service and shall not
  254. * be mapped. Don't bother telling the user about it.
  255. */
  256. if (ret != -EPERM) {
  257. pr_info("%s didn't like hwirq-0x%lx to VIRQ%i mapping (rc=%d)\n",
  258. domain->name, hwirq, virq, ret);
  259. }
  260. irq_data->domain = NULL;
  261. irq_data->hwirq = 0;
  262. mutex_unlock(&irq_domain_mutex);
  263. return ret;
  264. }
  265. /* If not already assigned, give the domain the chip's name */
  266. if (!domain->name && irq_data->chip)
  267. domain->name = irq_data->chip->name;
  268. }
  269. if (hwirq < domain->revmap_size) {
  270. domain->linear_revmap[hwirq] = virq;
  271. } else {
  272. mutex_lock(&revmap_trees_mutex);
  273. radix_tree_insert(&domain->revmap_tree, hwirq, irq_data);
  274. mutex_unlock(&revmap_trees_mutex);
  275. }
  276. mutex_unlock(&irq_domain_mutex);
  277. irq_clear_status_flags(virq, IRQ_NOREQUEST);
  278. return 0;
  279. }
  280. EXPORT_SYMBOL_GPL(irq_domain_associate);
  281. void irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,
  282. irq_hw_number_t hwirq_base, int count)
  283. {
  284. int i;
  285. pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__,
  286. of_node_full_name(domain->of_node), irq_base, (int)hwirq_base, count);
  287. for (i = 0; i < count; i++) {
  288. irq_domain_associate(domain, irq_base + i, hwirq_base + i);
  289. }
  290. }
  291. EXPORT_SYMBOL_GPL(irq_domain_associate_many);
  292. /**
  293. * irq_create_direct_mapping() - Allocate an irq for direct mapping
  294. * @domain: domain to allocate the irq for or NULL for default domain
  295. *
  296. * This routine is used for irq controllers which can choose the hardware
  297. * interrupt numbers they generate. In such a case it's simplest to use
  298. * the linux irq as the hardware interrupt number. It still uses the linear
  299. * or radix tree to store the mapping, but the irq controller can optimize
  300. * the revmap path by using the hwirq directly.
  301. */
  302. unsigned int irq_create_direct_mapping(struct irq_domain *domain)
  303. {
  304. unsigned int virq;
  305. if (domain == NULL)
  306. domain = irq_default_domain;
  307. virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
  308. if (!virq) {
  309. pr_debug("create_direct virq allocation failed\n");
  310. return 0;
  311. }
  312. if (virq >= domain->revmap_direct_max_irq) {
  313. pr_err("ERROR: no free irqs available below %i maximum\n",
  314. domain->revmap_direct_max_irq);
  315. irq_free_desc(virq);
  316. return 0;
  317. }
  318. pr_debug("create_direct obtained virq %d\n", virq);
  319. if (irq_domain_associate(domain, virq, virq)) {
  320. irq_free_desc(virq);
  321. return 0;
  322. }
  323. return virq;
  324. }
  325. EXPORT_SYMBOL_GPL(irq_create_direct_mapping);
  326. /**
  327. * irq_create_mapping() - Map a hardware interrupt into linux irq space
  328. * @domain: domain owning this hardware interrupt or NULL for default domain
  329. * @hwirq: hardware irq number in that domain space
  330. *
  331. * Only one mapping per hardware interrupt is permitted. Returns a linux
  332. * irq number.
  333. * If the sense/trigger is to be specified, set_irq_type() should be called
  334. * on the number returned from that call.
  335. */
  336. unsigned int irq_create_mapping(struct irq_domain *domain,
  337. irq_hw_number_t hwirq)
  338. {
  339. unsigned int hint;
  340. int virq;
  341. pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);
  342. /* Look for default domain if nececssary */
  343. if (domain == NULL)
  344. domain = irq_default_domain;
  345. if (domain == NULL) {
  346. WARN(1, "%s(, %lx) called with NULL domain\n", __func__, hwirq);
  347. return 0;
  348. }
  349. pr_debug("-> using domain @%p\n", domain);
  350. /* Check if mapping already exists */
  351. virq = irq_find_mapping(domain, hwirq);
  352. if (virq) {
  353. pr_debug("-> existing mapping on virq %d\n", virq);
  354. return virq;
  355. }
  356. /* Allocate a virtual interrupt number */
  357. hint = hwirq % nr_irqs;
  358. if (hint == 0)
  359. hint++;
  360. virq = irq_alloc_desc_from(hint, of_node_to_nid(domain->of_node));
  361. if (virq <= 0)
  362. virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
  363. if (virq <= 0) {
  364. pr_debug("-> virq allocation failed\n");
  365. return 0;
  366. }
  367. if (irq_domain_associate(domain, virq, hwirq)) {
  368. irq_free_desc(virq);
  369. return 0;
  370. }
  371. pr_debug("irq %lu on domain %s mapped to virtual irq %u\n",
  372. hwirq, of_node_full_name(domain->of_node), virq);
  373. return virq;
  374. }
  375. EXPORT_SYMBOL_GPL(irq_create_mapping);
  376. /**
  377. * irq_create_strict_mappings() - Map a range of hw irqs to fixed linux irqs
  378. * @domain: domain owning the interrupt range
  379. * @irq_base: beginning of linux IRQ range
  380. * @hwirq_base: beginning of hardware IRQ range
  381. * @count: Number of interrupts to map
  382. *
  383. * This routine is used for allocating and mapping a range of hardware
  384. * irqs to linux irqs where the linux irq numbers are at pre-defined
  385. * locations. For use by controllers that already have static mappings
  386. * to insert in to the domain.
  387. *
  388. * Non-linear users can use irq_create_identity_mapping() for IRQ-at-a-time
  389. * domain insertion.
  390. *
  391. * 0 is returned upon success, while any failure to establish a static
  392. * mapping is treated as an error.
  393. */
  394. int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base,
  395. irq_hw_number_t hwirq_base, int count)
  396. {
  397. int ret;
  398. ret = irq_alloc_descs(irq_base, irq_base, count,
  399. of_node_to_nid(domain->of_node));
  400. if (unlikely(ret < 0))
  401. return ret;
  402. irq_domain_associate_many(domain, irq_base, hwirq_base, count);
  403. return 0;
  404. }
  405. EXPORT_SYMBOL_GPL(irq_create_strict_mappings);
  406. unsigned int irq_create_of_mapping(struct of_phandle_args *irq_data)
  407. {
  408. struct irq_domain *domain;
  409. irq_hw_number_t hwirq;
  410. unsigned int type = IRQ_TYPE_NONE;
  411. unsigned int virq;
  412. domain = irq_data->np ? irq_find_host(irq_data->np) : irq_default_domain;
  413. if (!domain) {
  414. pr_warn("no irq domain found for %s !\n",
  415. of_node_full_name(irq_data->np));
  416. return 0;
  417. }
  418. /* If domain has no translation, then we assume interrupt line */
  419. if (domain->ops->xlate == NULL)
  420. hwirq = irq_data->args[0];
  421. else {
  422. if (domain->ops->xlate(domain, irq_data->np, irq_data->args,
  423. irq_data->args_count, &hwirq, &type))
  424. return 0;
  425. }
  426. /* Create mapping */
  427. virq = irq_create_mapping(domain, hwirq);
  428. if (!virq)
  429. return virq;
  430. /* Set type if specified and different than the current one */
  431. if (type != IRQ_TYPE_NONE &&
  432. type != irq_get_trigger_type(virq))
  433. irq_set_irq_type(virq, type);
  434. return virq;
  435. }
  436. EXPORT_SYMBOL_GPL(irq_create_of_mapping);
  437. /**
  438. * irq_dispose_mapping() - Unmap an interrupt
  439. * @virq: linux irq number of the interrupt to unmap
  440. */
  441. void irq_dispose_mapping(unsigned int virq)
  442. {
  443. struct irq_data *irq_data = irq_get_irq_data(virq);
  444. struct irq_domain *domain;
  445. if (!virq || !irq_data)
  446. return;
  447. domain = irq_data->domain;
  448. if (WARN_ON(domain == NULL))
  449. return;
  450. irq_domain_disassociate(domain, virq);
  451. irq_free_desc(virq);
  452. }
  453. EXPORT_SYMBOL_GPL(irq_dispose_mapping);
  454. /**
  455. * irq_find_mapping() - Find a linux irq from an hw irq number.
  456. * @domain: domain owning this hardware interrupt
  457. * @hwirq: hardware irq number in that domain space
  458. */
  459. unsigned int irq_find_mapping(struct irq_domain *domain,
  460. irq_hw_number_t hwirq)
  461. {
  462. struct irq_data *data;
  463. /* Look for default domain if nececssary */
  464. if (domain == NULL)
  465. domain = irq_default_domain;
  466. if (domain == NULL)
  467. return 0;
  468. if (hwirq < domain->revmap_direct_max_irq) {
  469. data = irq_get_irq_data(hwirq);
  470. if (data && (data->domain == domain) && (data->hwirq == hwirq))
  471. return hwirq;
  472. }
  473. /* Check if the hwirq is in the linear revmap. */
  474. if (hwirq < domain->revmap_size)
  475. return domain->linear_revmap[hwirq];
  476. rcu_read_lock();
  477. data = radix_tree_lookup(&domain->revmap_tree, hwirq);
  478. rcu_read_unlock();
  479. return data ? data->irq : 0;
  480. }
  481. EXPORT_SYMBOL_GPL(irq_find_mapping);
  482. #ifdef CONFIG_IRQ_DOMAIN_DEBUG
  483. static int virq_debug_show(struct seq_file *m, void *private)
  484. {
  485. unsigned long flags;
  486. struct irq_desc *desc;
  487. struct irq_domain *domain;
  488. struct radix_tree_iter iter;
  489. void *data, **slot;
  490. int i;
  491. seq_printf(m, " %-16s %-6s %-10s %-10s %s\n",
  492. "name", "mapped", "linear-max", "direct-max", "devtree-node");
  493. mutex_lock(&irq_domain_mutex);
  494. list_for_each_entry(domain, &irq_domain_list, link) {
  495. int count = 0;
  496. radix_tree_for_each_slot(slot, &domain->revmap_tree, &iter, 0)
  497. count++;
  498. seq_printf(m, "%c%-16s %6u %10u %10u %s\n",
  499. domain == irq_default_domain ? '*' : ' ', domain->name,
  500. domain->revmap_size + count, domain->revmap_size,
  501. domain->revmap_direct_max_irq,
  502. domain->of_node ? of_node_full_name(domain->of_node) : "");
  503. }
  504. mutex_unlock(&irq_domain_mutex);
  505. seq_printf(m, "%-5s %-7s %-15s %-*s %6s %-14s %s\n", "irq", "hwirq",
  506. "chip name", (int)(2 * sizeof(void *) + 2), "chip data",
  507. "active", "type", "domain");
  508. for (i = 1; i < nr_irqs; i++) {
  509. desc = irq_to_desc(i);
  510. if (!desc)
  511. continue;
  512. raw_spin_lock_irqsave(&desc->lock, flags);
  513. domain = desc->irq_data.domain;
  514. if (domain) {
  515. struct irq_chip *chip;
  516. int hwirq = desc->irq_data.hwirq;
  517. bool direct;
  518. seq_printf(m, "%5d ", i);
  519. seq_printf(m, "0x%05x ", hwirq);
  520. chip = irq_desc_get_chip(desc);
  521. seq_printf(m, "%-15s ", (chip && chip->name) ? chip->name : "none");
  522. data = irq_desc_get_chip_data(desc);
  523. seq_printf(m, data ? "0x%p " : " %p ", data);
  524. seq_printf(m, " %c ", (desc->action && desc->action->handler) ? '*' : ' ');
  525. direct = (i == hwirq) && (i < domain->revmap_direct_max_irq);
  526. seq_printf(m, "%6s%-8s ",
  527. (hwirq < domain->revmap_size) ? "LINEAR" : "RADIX",
  528. direct ? "(DIRECT)" : "");
  529. seq_printf(m, "%s\n", desc->irq_data.domain->name);
  530. }
  531. raw_spin_unlock_irqrestore(&desc->lock, flags);
  532. }
  533. return 0;
  534. }
  535. static int virq_debug_open(struct inode *inode, struct file *file)
  536. {
  537. return single_open(file, virq_debug_show, inode->i_private);
  538. }
  539. static const struct file_operations virq_debug_fops = {
  540. .open = virq_debug_open,
  541. .read = seq_read,
  542. .llseek = seq_lseek,
  543. .release = single_release,
  544. };
  545. static int __init irq_debugfs_init(void)
  546. {
  547. if (debugfs_create_file("irq_domain_mapping", S_IRUGO, NULL,
  548. NULL, &virq_debug_fops) == NULL)
  549. return -ENOMEM;
  550. return 0;
  551. }
  552. __initcall(irq_debugfs_init);
  553. #endif /* CONFIG_IRQ_DOMAIN_DEBUG */
  554. /**
  555. * irq_domain_xlate_onecell() - Generic xlate for direct one cell bindings
  556. *
  557. * Device Tree IRQ specifier translation function which works with one cell
  558. * bindings where the cell value maps directly to the hwirq number.
  559. */
  560. int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr,
  561. const u32 *intspec, unsigned int intsize,
  562. unsigned long *out_hwirq, unsigned int *out_type)
  563. {
  564. if (WARN_ON(intsize < 1))
  565. return -EINVAL;
  566. *out_hwirq = intspec[0];
  567. *out_type = IRQ_TYPE_NONE;
  568. return 0;
  569. }
  570. EXPORT_SYMBOL_GPL(irq_domain_xlate_onecell);
  571. /**
  572. * irq_domain_xlate_twocell() - Generic xlate for direct two cell bindings
  573. *
  574. * Device Tree IRQ specifier translation function which works with two cell
  575. * bindings where the cell values map directly to the hwirq number
  576. * and linux irq flags.
  577. */
  578. int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
  579. const u32 *intspec, unsigned int intsize,
  580. irq_hw_number_t *out_hwirq, unsigned int *out_type)
  581. {
  582. if (WARN_ON(intsize < 2))
  583. return -EINVAL;
  584. *out_hwirq = intspec[0];
  585. *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
  586. return 0;
  587. }
  588. EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell);
  589. /**
  590. * irq_domain_xlate_onetwocell() - Generic xlate for one or two cell bindings
  591. *
  592. * Device Tree IRQ specifier translation function which works with either one
  593. * or two cell bindings where the cell values map directly to the hwirq number
  594. * and linux irq flags.
  595. *
  596. * Note: don't use this function unless your interrupt controller explicitly
  597. * supports both one and two cell bindings. For the majority of controllers
  598. * the _onecell() or _twocell() variants above should be used.
  599. */
  600. int irq_domain_xlate_onetwocell(struct irq_domain *d,
  601. struct device_node *ctrlr,
  602. const u32 *intspec, unsigned int intsize,
  603. unsigned long *out_hwirq, unsigned int *out_type)
  604. {
  605. if (WARN_ON(intsize < 1))
  606. return -EINVAL;
  607. *out_hwirq = intspec[0];
  608. *out_type = (intsize > 1) ? intspec[1] : IRQ_TYPE_NONE;
  609. return 0;
  610. }
  611. EXPORT_SYMBOL_GPL(irq_domain_xlate_onetwocell);
  612. const struct irq_domain_ops irq_domain_simple_ops = {
  613. .xlate = irq_domain_xlate_onetwocell,
  614. };
  615. EXPORT_SYMBOL_GPL(irq_domain_simple_ops);