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/topology.h>
  13. #include <linux/seq_file.h>
  14. #include <linux/slab.h>
  15. #include <linux/smp.h>
  16. #include <linux/fs.h>
  17. static LIST_HEAD(irq_domain_list);
  18. static DEFINE_MUTEX(irq_domain_mutex);
  19. static DEFINE_MUTEX(revmap_trees_mutex);
  20. static struct irq_domain *irq_default_domain;
  21. /**
  22. * __irq_domain_add() - Allocate a new irq_domain data structure
  23. * @of_node: optional device-tree node of the interrupt controller
  24. * @size: Size of linear map; 0 for radix mapping only
  25. * @direct_max: Maximum value of direct maps; Use ~0 for no limit; 0 for no
  26. * direct mapping
  27. * @ops: map/unmap domain callbacks
  28. * @host_data: Controller private data pointer
  29. *
  30. * Allocates and initialize and irq_domain structure. Caller is expected to
  31. * register allocated irq_domain with irq_domain_register(). Returns pointer
  32. * to IRQ domain, or NULL on failure.
  33. */
  34. struct irq_domain *__irq_domain_add(struct device_node *of_node, int size,
  35. irq_hw_number_t hwirq_max, int direct_max,
  36. const struct irq_domain_ops *ops,
  37. void *host_data)
  38. {
  39. struct irq_domain *domain;
  40. domain = kzalloc_node(sizeof(*domain) + (sizeof(unsigned int) * size),
  41. GFP_KERNEL, of_node_to_nid(of_node));
  42. if (WARN_ON(!domain))
  43. return NULL;
  44. /* Fill structure */
  45. INIT_RADIX_TREE(&domain->revmap_tree, GFP_KERNEL);
  46. domain->ops = ops;
  47. domain->host_data = host_data;
  48. domain->of_node = of_node_get(of_node);
  49. domain->hwirq_max = hwirq_max;
  50. domain->revmap_size = size;
  51. domain->revmap_direct_max_irq = direct_max;
  52. mutex_lock(&irq_domain_mutex);
  53. list_add(&domain->link, &irq_domain_list);
  54. mutex_unlock(&irq_domain_mutex);
  55. pr_debug("Added domain %s\n", domain->name);
  56. return domain;
  57. }
  58. EXPORT_SYMBOL_GPL(__irq_domain_add);
  59. /**
  60. * irq_domain_remove() - Remove an irq domain.
  61. * @domain: domain to remove
  62. *
  63. * This routine is used to remove an irq domain. The caller must ensure
  64. * that all mappings within the domain have been disposed of prior to
  65. * use, depending on the revmap type.
  66. */
  67. void irq_domain_remove(struct irq_domain *domain)
  68. {
  69. mutex_lock(&irq_domain_mutex);
  70. /*
  71. * radix_tree_delete() takes care of destroying the root
  72. * node when all entries are removed. Shout if there are
  73. * any mappings left.
  74. */
  75. WARN_ON(domain->revmap_tree.height);
  76. list_del(&domain->link);
  77. /*
  78. * If the going away domain is the default one, reset it.
  79. */
  80. if (unlikely(irq_default_domain == domain))
  81. irq_set_default_host(NULL);
  82. mutex_unlock(&irq_domain_mutex);
  83. pr_debug("Removed domain %s\n", domain->name);
  84. of_node_put(domain->of_node);
  85. kfree(domain);
  86. }
  87. EXPORT_SYMBOL_GPL(irq_domain_remove);
  88. /**
  89. * irq_domain_add_simple() - Register an irq_domain and optionally map a range of irqs
  90. * @of_node: pointer to interrupt controller's device tree node.
  91. * @size: total number of irqs in mapping
  92. * @first_irq: first number of irq block assigned to the domain,
  93. * pass zero to assign irqs on-the-fly. If first_irq is non-zero, then
  94. * pre-map all of the irqs in the domain to virqs starting at first_irq.
  95. * @ops: map/unmap domain callbacks
  96. * @host_data: Controller private data pointer
  97. *
  98. * Allocates an irq_domain, and optionally if first_irq is positive then also
  99. * allocate irq_descs and map all of the hwirqs to virqs starting at first_irq.
  100. *
  101. * This is intended to implement the expected behaviour for most
  102. * interrupt controllers. If device tree is used, then first_irq will be 0 and
  103. * irqs get mapped dynamically on the fly. However, if the controller requires
  104. * static virq assignments (non-DT boot) then it will set that up correctly.
  105. */
  106. struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
  107. unsigned int size,
  108. unsigned int first_irq,
  109. const struct irq_domain_ops *ops,
  110. void *host_data)
  111. {
  112. struct irq_domain *domain;
  113. domain = __irq_domain_add(of_node, size, size, 0, ops, host_data);
  114. if (!domain)
  115. return NULL;
  116. if (first_irq > 0) {
  117. if (IS_ENABLED(CONFIG_SPARSE_IRQ)) {
  118. /* attempt to allocated irq_descs */
  119. int rc = irq_alloc_descs(first_irq, first_irq, size,
  120. of_node_to_nid(of_node));
  121. if (rc < 0)
  122. pr_info("Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n",
  123. first_irq);
  124. }
  125. irq_domain_associate_many(domain, first_irq, 0, size);
  126. }
  127. return domain;
  128. }
  129. EXPORT_SYMBOL_GPL(irq_domain_add_simple);
  130. /**
  131. * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain.
  132. * @of_node: pointer to interrupt controller's device tree node.
  133. * @size: total number of irqs in legacy mapping
  134. * @first_irq: first number of irq block assigned to the domain
  135. * @first_hwirq: first hwirq number to use for the translation. Should normally
  136. * be '0', but a positive integer can be used if the effective
  137. * hwirqs numbering does not begin at zero.
  138. * @ops: map/unmap domain callbacks
  139. * @host_data: Controller private data pointer
  140. *
  141. * Note: the map() callback will be called before this function returns
  142. * for all legacy interrupts except 0 (which is always the invalid irq for
  143. * a legacy controller).
  144. */
  145. struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
  146. unsigned int size,
  147. unsigned int first_irq,
  148. irq_hw_number_t first_hwirq,
  149. const struct irq_domain_ops *ops,
  150. void *host_data)
  151. {
  152. struct irq_domain *domain;
  153. domain = __irq_domain_add(of_node, first_hwirq + size,
  154. first_hwirq + size, 0, ops, host_data);
  155. if (!domain)
  156. return NULL;
  157. irq_domain_associate_many(domain, first_irq, first_hwirq, size);
  158. return domain;
  159. }
  160. EXPORT_SYMBOL_GPL(irq_domain_add_legacy);
  161. /**
  162. * irq_find_host() - Locates a domain for a given device node
  163. * @node: device-tree node of the interrupt controller
  164. */
  165. struct irq_domain *irq_find_host(struct device_node *node)
  166. {
  167. struct irq_domain *h, *found = NULL;
  168. int rc;
  169. /* We might want to match the legacy controller last since
  170. * it might potentially be set to match all interrupts in
  171. * the absence of a device node. This isn't a problem so far
  172. * yet though...
  173. */
  174. mutex_lock(&irq_domain_mutex);
  175. list_for_each_entry(h, &irq_domain_list, link) {
  176. if (h->ops->match)
  177. rc = h->ops->match(h, node);
  178. else
  179. rc = (h->of_node != NULL) && (h->of_node == node);
  180. if (rc) {
  181. found = h;
  182. break;
  183. }
  184. }
  185. mutex_unlock(&irq_domain_mutex);
  186. return found;
  187. }
  188. EXPORT_SYMBOL_GPL(irq_find_host);
  189. /**
  190. * irq_set_default_host() - Set a "default" irq domain
  191. * @domain: default domain pointer
  192. *
  193. * For convenience, it's possible to set a "default" domain that will be used
  194. * whenever NULL is passed to irq_create_mapping(). It makes life easier for
  195. * platforms that want to manipulate a few hard coded interrupt numbers that
  196. * aren't properly represented in the device-tree.
  197. */
  198. void irq_set_default_host(struct irq_domain *domain)
  199. {
  200. pr_debug("Default domain set to @0x%p\n", domain);
  201. irq_default_domain = domain;
  202. }
  203. EXPORT_SYMBOL_GPL(irq_set_default_host);
  204. static void irq_domain_disassociate(struct irq_domain *domain, unsigned int irq)
  205. {
  206. struct irq_data *irq_data = irq_get_irq_data(irq);
  207. irq_hw_number_t hwirq;
  208. if (WARN(!irq_data || irq_data->domain != domain,
  209. "virq%i doesn't exist; cannot disassociate\n", irq))
  210. return;
  211. hwirq = irq_data->hwirq;
  212. irq_set_status_flags(irq, IRQ_NOREQUEST);
  213. /* remove chip and handler */
  214. irq_set_chip_and_handler(irq, NULL, NULL);
  215. /* Make sure it's completed */
  216. synchronize_irq(irq);
  217. /* Tell the PIC about it */
  218. if (domain->ops->unmap)
  219. domain->ops->unmap(domain, irq);
  220. smp_mb();
  221. irq_data->domain = NULL;
  222. irq_data->hwirq = 0;
  223. /* Clear reverse map for this hwirq */
  224. if (hwirq < domain->revmap_size) {
  225. domain->linear_revmap[hwirq] = 0;
  226. } else {
  227. mutex_lock(&revmap_trees_mutex);
  228. radix_tree_delete(&domain->revmap_tree, hwirq);
  229. mutex_unlock(&revmap_trees_mutex);
  230. }
  231. }
  232. int irq_domain_associate(struct irq_domain *domain, unsigned int virq,
  233. irq_hw_number_t hwirq)
  234. {
  235. struct irq_data *irq_data = irq_get_irq_data(virq);
  236. int ret;
  237. if (WARN(hwirq >= domain->hwirq_max,
  238. "error: hwirq 0x%x is too large for %s\n", (int)hwirq, domain->name))
  239. return -EINVAL;
  240. if (WARN(!irq_data, "error: virq%i is not allocated", virq))
  241. return -EINVAL;
  242. if (WARN(irq_data->domain, "error: virq%i is already associated", virq))
  243. return -EINVAL;
  244. mutex_lock(&irq_domain_mutex);
  245. irq_data->hwirq = hwirq;
  246. irq_data->domain = domain;
  247. if (domain->ops->map) {
  248. ret = domain->ops->map(domain, virq, hwirq);
  249. if (ret != 0) {
  250. /*
  251. * If map() returns -EPERM, this interrupt is protected
  252. * by the firmware or some other service and shall not
  253. * be mapped. Don't bother telling the user about it.
  254. */
  255. if (ret != -EPERM) {
  256. pr_info("%s didn't like hwirq-0x%lx to VIRQ%i mapping (rc=%d)\n",
  257. domain->name, hwirq, virq, ret);
  258. }
  259. irq_data->domain = NULL;
  260. irq_data->hwirq = 0;
  261. mutex_unlock(&irq_domain_mutex);
  262. return ret;
  263. }
  264. /* If not already assigned, give the domain the chip's name */
  265. if (!domain->name && irq_data->chip)
  266. domain->name = irq_data->chip->name;
  267. }
  268. if (hwirq < domain->revmap_size) {
  269. domain->linear_revmap[hwirq] = virq;
  270. } else {
  271. mutex_lock(&revmap_trees_mutex);
  272. radix_tree_insert(&domain->revmap_tree, hwirq, irq_data);
  273. mutex_unlock(&revmap_trees_mutex);
  274. }
  275. mutex_unlock(&irq_domain_mutex);
  276. irq_clear_status_flags(virq, IRQ_NOREQUEST);
  277. return 0;
  278. }
  279. EXPORT_SYMBOL_GPL(irq_domain_associate);
  280. void irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,
  281. irq_hw_number_t hwirq_base, int count)
  282. {
  283. int i;
  284. pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__,
  285. of_node_full_name(domain->of_node), irq_base, (int)hwirq_base, count);
  286. for (i = 0; i < count; i++) {
  287. irq_domain_associate(domain, irq_base + i, hwirq_base + i);
  288. }
  289. }
  290. EXPORT_SYMBOL_GPL(irq_domain_associate_many);
  291. /**
  292. * irq_create_direct_mapping() - Allocate an irq for direct mapping
  293. * @domain: domain to allocate the irq for or NULL for default domain
  294. *
  295. * This routine is used for irq controllers which can choose the hardware
  296. * interrupt numbers they generate. In such a case it's simplest to use
  297. * the linux irq as the hardware interrupt number. It still uses the linear
  298. * or radix tree to store the mapping, but the irq controller can optimize
  299. * the revmap path by using the hwirq directly.
  300. */
  301. unsigned int irq_create_direct_mapping(struct irq_domain *domain)
  302. {
  303. unsigned int virq;
  304. if (domain == NULL)
  305. domain = irq_default_domain;
  306. virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
  307. if (!virq) {
  308. pr_debug("create_direct virq allocation failed\n");
  309. return 0;
  310. }
  311. if (virq >= domain->revmap_direct_max_irq) {
  312. pr_err("ERROR: no free irqs available below %i maximum\n",
  313. domain->revmap_direct_max_irq);
  314. irq_free_desc(virq);
  315. return 0;
  316. }
  317. pr_debug("create_direct obtained virq %d\n", virq);
  318. if (irq_domain_associate(domain, virq, virq)) {
  319. irq_free_desc(virq);
  320. return 0;
  321. }
  322. return virq;
  323. }
  324. EXPORT_SYMBOL_GPL(irq_create_direct_mapping);
  325. /**
  326. * irq_create_mapping() - Map a hardware interrupt into linux irq space
  327. * @domain: domain owning this hardware interrupt or NULL for default domain
  328. * @hwirq: hardware irq number in that domain space
  329. *
  330. * Only one mapping per hardware interrupt is permitted. Returns a linux
  331. * irq number.
  332. * If the sense/trigger is to be specified, set_irq_type() should be called
  333. * on the number returned from that call.
  334. */
  335. unsigned int irq_create_mapping(struct irq_domain *domain,
  336. irq_hw_number_t hwirq)
  337. {
  338. unsigned int hint;
  339. int virq;
  340. pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);
  341. /* Look for default domain if nececssary */
  342. if (domain == NULL)
  343. domain = irq_default_domain;
  344. if (domain == NULL) {
  345. WARN(1, "%s(, %lx) called with NULL domain\n", __func__, hwirq);
  346. return 0;
  347. }
  348. pr_debug("-> using domain @%p\n", domain);
  349. /* Check if mapping already exists */
  350. virq = irq_find_mapping(domain, hwirq);
  351. if (virq) {
  352. pr_debug("-> existing mapping on virq %d\n", virq);
  353. return virq;
  354. }
  355. /* Allocate a virtual interrupt number */
  356. hint = hwirq % nr_irqs;
  357. if (hint == 0)
  358. hint++;
  359. virq = irq_alloc_desc_from(hint, of_node_to_nid(domain->of_node));
  360. if (virq <= 0)
  361. virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
  362. if (virq <= 0) {
  363. pr_debug("-> virq allocation failed\n");
  364. return 0;
  365. }
  366. if (irq_domain_associate(domain, virq, hwirq)) {
  367. irq_free_desc(virq);
  368. return 0;
  369. }
  370. pr_debug("irq %lu on domain %s mapped to virtual irq %u\n",
  371. hwirq, of_node_full_name(domain->of_node), virq);
  372. return virq;
  373. }
  374. EXPORT_SYMBOL_GPL(irq_create_mapping);
  375. /**
  376. * irq_create_strict_mappings() - Map a range of hw irqs to fixed linux irqs
  377. * @domain: domain owning the interrupt range
  378. * @irq_base: beginning of linux IRQ range
  379. * @hwirq_base: beginning of hardware IRQ range
  380. * @count: Number of interrupts to map
  381. *
  382. * This routine is used for allocating and mapping a range of hardware
  383. * irqs to linux irqs where the linux irq numbers are at pre-defined
  384. * locations. For use by controllers that already have static mappings
  385. * to insert in to the domain.
  386. *
  387. * Non-linear users can use irq_create_identity_mapping() for IRQ-at-a-time
  388. * domain insertion.
  389. *
  390. * 0 is returned upon success, while any failure to establish a static
  391. * mapping is treated as an error.
  392. */
  393. int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base,
  394. irq_hw_number_t hwirq_base, int count)
  395. {
  396. int ret;
  397. ret = irq_alloc_descs(irq_base, irq_base, count,
  398. of_node_to_nid(domain->of_node));
  399. if (unlikely(ret < 0))
  400. return ret;
  401. irq_domain_associate_many(domain, irq_base, hwirq_base, count);
  402. return 0;
  403. }
  404. EXPORT_SYMBOL_GPL(irq_create_strict_mappings);
  405. unsigned int irq_create_of_mapping(struct device_node *controller,
  406. const u32 *intspec, unsigned int intsize)
  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 = controller ? irq_find_host(controller) : irq_default_domain;
  413. if (!domain) {
  414. pr_warn("no irq domain found for %s !\n",
  415. of_node_full_name(controller));
  416. return 0;
  417. }
  418. /* If domain has no translation, then we assume interrupt line */
  419. if (domain->ops->xlate == NULL)
  420. hwirq = intspec[0];
  421. else {
  422. if (domain->ops->xlate(domain, controller, intspec, intsize,
  423. &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);