irqdomain.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  1. #include <linux/debugfs.h>
  2. #include <linux/hardirq.h>
  3. #include <linux/interrupt.h>
  4. #include <linux/irq.h>
  5. #include <linux/irqdesc.h>
  6. #include <linux/irqdomain.h>
  7. #include <linux/module.h>
  8. #include <linux/mutex.h>
  9. #include <linux/of.h>
  10. #include <linux/of_address.h>
  11. #include <linux/seq_file.h>
  12. #include <linux/slab.h>
  13. #include <linux/smp.h>
  14. #include <linux/fs.h>
  15. #define IRQ_DOMAIN_MAP_LEGACY 0 /* driver allocated fixed range of irqs.
  16. * ie. legacy 8259, gets irqs 1..15 */
  17. #define IRQ_DOMAIN_MAP_NOMAP 1 /* no fast reverse mapping */
  18. #define IRQ_DOMAIN_MAP_LINEAR 2 /* linear map of interrupts */
  19. #define IRQ_DOMAIN_MAP_TREE 3 /* radix tree */
  20. static LIST_HEAD(irq_domain_list);
  21. static DEFINE_MUTEX(irq_domain_mutex);
  22. static DEFINE_MUTEX(revmap_trees_mutex);
  23. static struct irq_domain *irq_default_domain;
  24. /**
  25. * irq_domain_alloc() - Allocate a new irq_domain data structure
  26. * @of_node: optional device-tree node of the interrupt controller
  27. * @revmap_type: type of reverse mapping to use
  28. * @ops: map/unmap domain callbacks
  29. * @host_data: Controller private data pointer
  30. *
  31. * Allocates and initialize and irq_domain structure. Caller is expected to
  32. * register allocated irq_domain with irq_domain_register(). Returns pointer
  33. * to IRQ domain, or NULL on failure.
  34. */
  35. static struct irq_domain *irq_domain_alloc(struct device_node *of_node,
  36. unsigned int revmap_type,
  37. const struct irq_domain_ops *ops,
  38. void *host_data)
  39. {
  40. struct irq_domain *domain;
  41. domain = kzalloc(sizeof(*domain), GFP_KERNEL);
  42. if (WARN_ON(!domain))
  43. return NULL;
  44. /* Fill structure */
  45. domain->revmap_type = revmap_type;
  46. domain->ops = ops;
  47. domain->host_data = host_data;
  48. domain->of_node = of_node_get(of_node);
  49. return domain;
  50. }
  51. static void irq_domain_add(struct irq_domain *domain)
  52. {
  53. mutex_lock(&irq_domain_mutex);
  54. list_add(&domain->link, &irq_domain_list);
  55. mutex_unlock(&irq_domain_mutex);
  56. pr_debug("irq: Allocated domain of type %d @0x%p\n",
  57. domain->revmap_type, domain);
  58. }
  59. static unsigned int irq_domain_legacy_revmap(struct irq_domain *domain,
  60. irq_hw_number_t hwirq)
  61. {
  62. irq_hw_number_t first_hwirq = domain->revmap_data.legacy.first_hwirq;
  63. int size = domain->revmap_data.legacy.size;
  64. if (WARN_ON(hwirq < first_hwirq || hwirq >= first_hwirq + size))
  65. return 0;
  66. return hwirq - first_hwirq + domain->revmap_data.legacy.first_irq;
  67. }
  68. /**
  69. * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain.
  70. * @of_node: pointer to interrupt controller's device tree node.
  71. * @size: total number of irqs in legacy mapping
  72. * @first_irq: first number of irq block assigned to the domain
  73. * @first_hwirq: first hwirq number to use for the translation. Should normally
  74. * be '0', but a positive integer can be used if the effective
  75. * hwirqs numbering does not begin at zero.
  76. * @ops: map/unmap domain callbacks
  77. * @host_data: Controller private data pointer
  78. *
  79. * Note: the map() callback will be called before this function returns
  80. * for all legacy interrupts except 0 (which is always the invalid irq for
  81. * a legacy controller).
  82. */
  83. struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
  84. unsigned int size,
  85. unsigned int first_irq,
  86. irq_hw_number_t first_hwirq,
  87. const struct irq_domain_ops *ops,
  88. void *host_data)
  89. {
  90. struct irq_domain *domain;
  91. unsigned int i;
  92. domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LEGACY, ops, host_data);
  93. if (!domain)
  94. return NULL;
  95. domain->revmap_data.legacy.first_irq = first_irq;
  96. domain->revmap_data.legacy.first_hwirq = first_hwirq;
  97. domain->revmap_data.legacy.size = size;
  98. mutex_lock(&irq_domain_mutex);
  99. /* Verify that all the irqs are available */
  100. for (i = 0; i < size; i++) {
  101. int irq = first_irq + i;
  102. struct irq_data *irq_data = irq_get_irq_data(irq);
  103. if (WARN_ON(!irq_data || irq_data->domain)) {
  104. mutex_unlock(&irq_domain_mutex);
  105. of_node_put(domain->of_node);
  106. kfree(domain);
  107. return NULL;
  108. }
  109. }
  110. /* Claim all of the irqs before registering a legacy domain */
  111. for (i = 0; i < size; i++) {
  112. struct irq_data *irq_data = irq_get_irq_data(first_irq + i);
  113. irq_data->hwirq = first_hwirq + i;
  114. irq_data->domain = domain;
  115. }
  116. mutex_unlock(&irq_domain_mutex);
  117. for (i = 0; i < size; i++) {
  118. int irq = first_irq + i;
  119. int hwirq = first_hwirq + i;
  120. /* IRQ0 gets ignored */
  121. if (!irq)
  122. continue;
  123. /* Legacy flags are left to default at this point,
  124. * one can then use irq_create_mapping() to
  125. * explicitly change them
  126. */
  127. ops->map(domain, irq, hwirq);
  128. /* Clear norequest flags */
  129. irq_clear_status_flags(irq, IRQ_NOREQUEST);
  130. }
  131. irq_domain_add(domain);
  132. return domain;
  133. }
  134. /**
  135. * irq_domain_add_linear() - Allocate and register a legacy revmap irq_domain.
  136. * @of_node: pointer to interrupt controller's device tree node.
  137. * @ops: map/unmap domain callbacks
  138. * @host_data: Controller private data pointer
  139. */
  140. struct irq_domain *irq_domain_add_linear(struct device_node *of_node,
  141. unsigned int size,
  142. const struct irq_domain_ops *ops,
  143. void *host_data)
  144. {
  145. struct irq_domain *domain;
  146. unsigned int *revmap;
  147. revmap = kzalloc(sizeof(*revmap) * size, GFP_KERNEL);
  148. if (WARN_ON(!revmap))
  149. return NULL;
  150. domain = irq_domain_alloc(of_node, IRQ_DOMAIN_MAP_LINEAR, ops, host_data);
  151. if (!domain) {
  152. kfree(revmap);
  153. return NULL;
  154. }
  155. domain->revmap_data.linear.size = size;
  156. domain->revmap_data.linear.revmap = revmap;
  157. irq_domain_add(domain);
  158. return domain;
  159. }
  160. struct irq_domain *irq_domain_add_nomap(struct device_node *of_node,
  161. unsigned int max_irq,
  162. const struct irq_domain_ops *ops,
  163. void *host_data)
  164. {
  165. struct irq_domain *domain = irq_domain_alloc(of_node,
  166. IRQ_DOMAIN_MAP_NOMAP, ops, host_data);
  167. if (domain) {
  168. domain->revmap_data.nomap.max_irq = max_irq ? max_irq : ~0;
  169. irq_domain_add(domain);
  170. }
  171. return domain;
  172. }
  173. /**
  174. * irq_domain_add_tree()
  175. * @of_node: pointer to interrupt controller's device tree node.
  176. * @ops: map/unmap domain callbacks
  177. *
  178. * Note: The radix tree will be allocated later during boot automatically
  179. * (the reverse mapping will use the slow path until that happens).
  180. */
  181. struct irq_domain *irq_domain_add_tree(struct device_node *of_node,
  182. const struct irq_domain_ops *ops,
  183. void *host_data)
  184. {
  185. struct irq_domain *domain = irq_domain_alloc(of_node,
  186. IRQ_DOMAIN_MAP_TREE, ops, host_data);
  187. if (domain) {
  188. INIT_RADIX_TREE(&domain->revmap_data.tree, GFP_KERNEL);
  189. irq_domain_add(domain);
  190. }
  191. return domain;
  192. }
  193. /**
  194. * irq_find_host() - Locates a domain for a given device node
  195. * @node: device-tree node of the interrupt controller
  196. */
  197. struct irq_domain *irq_find_host(struct device_node *node)
  198. {
  199. struct irq_domain *h, *found = NULL;
  200. int rc;
  201. /* We might want to match the legacy controller last since
  202. * it might potentially be set to match all interrupts in
  203. * the absence of a device node. This isn't a problem so far
  204. * yet though...
  205. */
  206. mutex_lock(&irq_domain_mutex);
  207. list_for_each_entry(h, &irq_domain_list, link) {
  208. if (h->ops->match)
  209. rc = h->ops->match(h, node);
  210. else
  211. rc = (h->of_node != NULL) && (h->of_node == node);
  212. if (rc) {
  213. found = h;
  214. break;
  215. }
  216. }
  217. mutex_unlock(&irq_domain_mutex);
  218. return found;
  219. }
  220. EXPORT_SYMBOL_GPL(irq_find_host);
  221. /**
  222. * irq_set_default_host() - Set a "default" irq domain
  223. * @domain: default domain pointer
  224. *
  225. * For convenience, it's possible to set a "default" domain that will be used
  226. * whenever NULL is passed to irq_create_mapping(). It makes life easier for
  227. * platforms that want to manipulate a few hard coded interrupt numbers that
  228. * aren't properly represented in the device-tree.
  229. */
  230. void irq_set_default_host(struct irq_domain *domain)
  231. {
  232. pr_debug("irq: Default domain set to @0x%p\n", domain);
  233. irq_default_domain = domain;
  234. }
  235. static int irq_setup_virq(struct irq_domain *domain, unsigned int virq,
  236. irq_hw_number_t hwirq)
  237. {
  238. struct irq_data *irq_data = irq_get_irq_data(virq);
  239. irq_data->hwirq = hwirq;
  240. irq_data->domain = domain;
  241. if (domain->ops->map(domain, virq, hwirq)) {
  242. pr_debug("irq: -> mapping failed, freeing\n");
  243. irq_data->domain = NULL;
  244. irq_data->hwirq = 0;
  245. return -1;
  246. }
  247. irq_clear_status_flags(virq, IRQ_NOREQUEST);
  248. return 0;
  249. }
  250. /**
  251. * irq_create_direct_mapping() - Allocate an irq for direct mapping
  252. * @domain: domain to allocate the irq for or NULL for default domain
  253. *
  254. * This routine is used for irq controllers which can choose the hardware
  255. * interrupt numbers they generate. In such a case it's simplest to use
  256. * the linux irq as the hardware interrupt number.
  257. */
  258. unsigned int irq_create_direct_mapping(struct irq_domain *domain)
  259. {
  260. unsigned int virq;
  261. if (domain == NULL)
  262. domain = irq_default_domain;
  263. BUG_ON(domain == NULL);
  264. WARN_ON(domain->revmap_type != IRQ_DOMAIN_MAP_NOMAP);
  265. virq = irq_alloc_desc_from(1, 0);
  266. if (!virq) {
  267. pr_debug("irq: create_direct virq allocation failed\n");
  268. return 0;
  269. }
  270. if (virq >= domain->revmap_data.nomap.max_irq) {
  271. pr_err("ERROR: no free irqs available below %i maximum\n",
  272. domain->revmap_data.nomap.max_irq);
  273. irq_free_desc(virq);
  274. return 0;
  275. }
  276. pr_debug("irq: create_direct obtained virq %d\n", virq);
  277. if (irq_setup_virq(domain, virq, virq)) {
  278. irq_free_desc(virq);
  279. return 0;
  280. }
  281. return virq;
  282. }
  283. /**
  284. * irq_create_mapping() - Map a hardware interrupt into linux irq space
  285. * @domain: domain owning this hardware interrupt or NULL for default domain
  286. * @hwirq: hardware irq number in that domain space
  287. *
  288. * Only one mapping per hardware interrupt is permitted. Returns a linux
  289. * irq number.
  290. * If the sense/trigger is to be specified, set_irq_type() should be called
  291. * on the number returned from that call.
  292. */
  293. unsigned int irq_create_mapping(struct irq_domain *domain,
  294. irq_hw_number_t hwirq)
  295. {
  296. unsigned int hint;
  297. int virq;
  298. pr_debug("irq: irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);
  299. /* Look for default domain if nececssary */
  300. if (domain == NULL)
  301. domain = irq_default_domain;
  302. if (domain == NULL) {
  303. printk(KERN_WARNING "irq_create_mapping called for"
  304. " NULL domain, hwirq=%lx\n", hwirq);
  305. WARN_ON(1);
  306. return 0;
  307. }
  308. pr_debug("irq: -> using domain @%p\n", domain);
  309. /* Check if mapping already exists */
  310. virq = irq_find_mapping(domain, hwirq);
  311. if (virq) {
  312. pr_debug("irq: -> existing mapping on virq %d\n", virq);
  313. return virq;
  314. }
  315. /* Get a virtual interrupt number */
  316. if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
  317. return irq_domain_legacy_revmap(domain, hwirq);
  318. /* Allocate a virtual interrupt number */
  319. hint = hwirq % nr_irqs;
  320. if (hint == 0)
  321. hint++;
  322. virq = irq_alloc_desc_from(hint, 0);
  323. if (virq <= 0)
  324. virq = irq_alloc_desc_from(1, 0);
  325. if (virq <= 0) {
  326. pr_debug("irq: -> virq allocation failed\n");
  327. return 0;
  328. }
  329. if (irq_setup_virq(domain, virq, hwirq)) {
  330. if (domain->revmap_type != IRQ_DOMAIN_MAP_LEGACY)
  331. irq_free_desc(virq);
  332. return 0;
  333. }
  334. pr_debug("irq: irq %lu on domain %s mapped to virtual irq %u\n",
  335. hwirq, domain->of_node ? domain->of_node->full_name : "null", virq);
  336. return virq;
  337. }
  338. EXPORT_SYMBOL_GPL(irq_create_mapping);
  339. unsigned int irq_create_of_mapping(struct device_node *controller,
  340. const u32 *intspec, unsigned int intsize)
  341. {
  342. struct irq_domain *domain;
  343. irq_hw_number_t hwirq;
  344. unsigned int type = IRQ_TYPE_NONE;
  345. unsigned int virq;
  346. domain = controller ? irq_find_host(controller) : irq_default_domain;
  347. if (!domain) {
  348. #ifdef CONFIG_MIPS
  349. /*
  350. * Workaround to avoid breaking interrupt controller drivers
  351. * that don't yet register an irq_domain. This is temporary
  352. * code. ~~~gcl, Feb 24, 2012
  353. *
  354. * Scheduled for removal in Linux v3.6. That should be enough
  355. * time.
  356. */
  357. if (intsize > 0)
  358. return intspec[0];
  359. #endif
  360. printk(KERN_WARNING "irq: no irq domain found for %s !\n",
  361. controller->full_name);
  362. return 0;
  363. }
  364. /* If domain has no translation, then we assume interrupt line */
  365. if (domain->ops->xlate == NULL)
  366. hwirq = intspec[0];
  367. else {
  368. if (domain->ops->xlate(domain, controller, intspec, intsize,
  369. &hwirq, &type))
  370. return 0;
  371. }
  372. /* Create mapping */
  373. virq = irq_create_mapping(domain, hwirq);
  374. if (!virq)
  375. return virq;
  376. /* Set type if specified and different than the current one */
  377. if (type != IRQ_TYPE_NONE &&
  378. type != (irqd_get_trigger_type(irq_get_irq_data(virq))))
  379. irq_set_irq_type(virq, type);
  380. return virq;
  381. }
  382. EXPORT_SYMBOL_GPL(irq_create_of_mapping);
  383. /**
  384. * irq_dispose_mapping() - Unmap an interrupt
  385. * @virq: linux irq number of the interrupt to unmap
  386. */
  387. void irq_dispose_mapping(unsigned int virq)
  388. {
  389. struct irq_data *irq_data = irq_get_irq_data(virq);
  390. struct irq_domain *domain;
  391. irq_hw_number_t hwirq;
  392. if (!virq || !irq_data)
  393. return;
  394. domain = irq_data->domain;
  395. if (WARN_ON(domain == NULL))
  396. return;
  397. /* Never unmap legacy interrupts */
  398. if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
  399. return;
  400. irq_set_status_flags(virq, IRQ_NOREQUEST);
  401. /* remove chip and handler */
  402. irq_set_chip_and_handler(virq, NULL, NULL);
  403. /* Make sure it's completed */
  404. synchronize_irq(virq);
  405. /* Tell the PIC about it */
  406. if (domain->ops->unmap)
  407. domain->ops->unmap(domain, virq);
  408. smp_mb();
  409. /* Clear reverse map */
  410. hwirq = irq_data->hwirq;
  411. switch(domain->revmap_type) {
  412. case IRQ_DOMAIN_MAP_LINEAR:
  413. if (hwirq < domain->revmap_data.linear.size)
  414. domain->revmap_data.linear.revmap[hwirq] = 0;
  415. break;
  416. case IRQ_DOMAIN_MAP_TREE:
  417. mutex_lock(&revmap_trees_mutex);
  418. radix_tree_delete(&domain->revmap_data.tree, hwirq);
  419. mutex_unlock(&revmap_trees_mutex);
  420. break;
  421. }
  422. irq_free_desc(virq);
  423. }
  424. EXPORT_SYMBOL_GPL(irq_dispose_mapping);
  425. /**
  426. * irq_find_mapping() - Find a linux irq from an hw irq number.
  427. * @domain: domain owning this hardware interrupt
  428. * @hwirq: hardware irq number in that domain space
  429. *
  430. * This is a slow path, for use by generic code. It's expected that an
  431. * irq controller implementation directly calls the appropriate low level
  432. * mapping function.
  433. */
  434. unsigned int irq_find_mapping(struct irq_domain *domain,
  435. irq_hw_number_t hwirq)
  436. {
  437. unsigned int i;
  438. unsigned int hint = hwirq % nr_irqs;
  439. /* Look for default domain if nececssary */
  440. if (domain == NULL)
  441. domain = irq_default_domain;
  442. if (domain == NULL)
  443. return 0;
  444. /* legacy -> bail early */
  445. if (domain->revmap_type == IRQ_DOMAIN_MAP_LEGACY)
  446. return irq_domain_legacy_revmap(domain, hwirq);
  447. /* Slow path does a linear search of the map */
  448. if (hint == 0)
  449. hint = 1;
  450. i = hint;
  451. do {
  452. struct irq_data *data = irq_get_irq_data(i);
  453. if (data && (data->domain == domain) && (data->hwirq == hwirq))
  454. return i;
  455. i++;
  456. if (i >= nr_irqs)
  457. i = 1;
  458. } while(i != hint);
  459. return 0;
  460. }
  461. EXPORT_SYMBOL_GPL(irq_find_mapping);
  462. /**
  463. * irq_radix_revmap_lookup() - Find a linux irq from a hw irq number.
  464. * @domain: domain owning this hardware interrupt
  465. * @hwirq: hardware irq number in that domain space
  466. *
  467. * This is a fast path, for use by irq controller code that uses radix tree
  468. * revmaps
  469. */
  470. unsigned int irq_radix_revmap_lookup(struct irq_domain *domain,
  471. irq_hw_number_t hwirq)
  472. {
  473. struct irq_data *irq_data;
  474. if (WARN_ON_ONCE(domain->revmap_type != IRQ_DOMAIN_MAP_TREE))
  475. return irq_find_mapping(domain, hwirq);
  476. /*
  477. * Freeing an irq can delete nodes along the path to
  478. * do the lookup via call_rcu.
  479. */
  480. rcu_read_lock();
  481. irq_data = radix_tree_lookup(&domain->revmap_data.tree, hwirq);
  482. rcu_read_unlock();
  483. /*
  484. * If found in radix tree, then fine.
  485. * Else fallback to linear lookup - this should not happen in practice
  486. * as it means that we failed to insert the node in the radix tree.
  487. */
  488. return irq_data ? irq_data->irq : irq_find_mapping(domain, hwirq);
  489. }
  490. /**
  491. * irq_radix_revmap_insert() - Insert a hw irq to linux irq number mapping.
  492. * @domain: domain owning this hardware interrupt
  493. * @virq: linux irq number
  494. * @hwirq: hardware irq number in that domain space
  495. *
  496. * This is for use by irq controllers that use a radix tree reverse
  497. * mapping for fast lookup.
  498. */
  499. void irq_radix_revmap_insert(struct irq_domain *domain, unsigned int virq,
  500. irq_hw_number_t hwirq)
  501. {
  502. struct irq_data *irq_data = irq_get_irq_data(virq);
  503. if (WARN_ON(domain->revmap_type != IRQ_DOMAIN_MAP_TREE))
  504. return;
  505. if (virq) {
  506. mutex_lock(&revmap_trees_mutex);
  507. radix_tree_insert(&domain->revmap_data.tree, hwirq, irq_data);
  508. mutex_unlock(&revmap_trees_mutex);
  509. }
  510. }
  511. /**
  512. * irq_linear_revmap() - Find a linux irq from a hw irq number.
  513. * @domain: domain owning this hardware interrupt
  514. * @hwirq: hardware irq number in that domain space
  515. *
  516. * This is a fast path, for use by irq controller code that uses linear
  517. * revmaps. It does fallback to the slow path if the revmap doesn't exist
  518. * yet and will create the revmap entry with appropriate locking
  519. */
  520. unsigned int irq_linear_revmap(struct irq_domain *domain,
  521. irq_hw_number_t hwirq)
  522. {
  523. unsigned int *revmap;
  524. if (WARN_ON_ONCE(domain->revmap_type != IRQ_DOMAIN_MAP_LINEAR))
  525. return irq_find_mapping(domain, hwirq);
  526. /* Check revmap bounds */
  527. if (unlikely(hwirq >= domain->revmap_data.linear.size))
  528. return irq_find_mapping(domain, hwirq);
  529. /* Check if revmap was allocated */
  530. revmap = domain->revmap_data.linear.revmap;
  531. if (unlikely(revmap == NULL))
  532. return irq_find_mapping(domain, hwirq);
  533. /* Fill up revmap with slow path if no mapping found */
  534. if (unlikely(!revmap[hwirq]))
  535. revmap[hwirq] = irq_find_mapping(domain, hwirq);
  536. return revmap[hwirq];
  537. }
  538. #ifdef CONFIG_IRQ_DOMAIN_DEBUG
  539. static int virq_debug_show(struct seq_file *m, void *private)
  540. {
  541. unsigned long flags;
  542. struct irq_desc *desc;
  543. const char *p;
  544. static const char none[] = "none";
  545. void *data;
  546. int i;
  547. seq_printf(m, "%-5s %-7s %-15s %-*s %s\n", "irq", "hwirq",
  548. "chip name", (int)(2 * sizeof(void *) + 2), "chip data",
  549. "domain name");
  550. for (i = 1; i < nr_irqs; i++) {
  551. desc = irq_to_desc(i);
  552. if (!desc)
  553. continue;
  554. raw_spin_lock_irqsave(&desc->lock, flags);
  555. if (desc->action && desc->action->handler) {
  556. struct irq_chip *chip;
  557. seq_printf(m, "%5d ", i);
  558. seq_printf(m, "0x%05lx ", desc->irq_data.hwirq);
  559. chip = irq_desc_get_chip(desc);
  560. if (chip && chip->name)
  561. p = chip->name;
  562. else
  563. p = none;
  564. seq_printf(m, "%-15s ", p);
  565. data = irq_desc_get_chip_data(desc);
  566. seq_printf(m, data ? "0x%p " : " %p ", data);
  567. if (desc->irq_data.domain && desc->irq_data.domain->of_node)
  568. p = desc->irq_data.domain->of_node->full_name;
  569. else
  570. p = none;
  571. seq_printf(m, "%s\n", p);
  572. }
  573. raw_spin_unlock_irqrestore(&desc->lock, flags);
  574. }
  575. return 0;
  576. }
  577. static int virq_debug_open(struct inode *inode, struct file *file)
  578. {
  579. return single_open(file, virq_debug_show, inode->i_private);
  580. }
  581. static const struct file_operations virq_debug_fops = {
  582. .open = virq_debug_open,
  583. .read = seq_read,
  584. .llseek = seq_lseek,
  585. .release = single_release,
  586. };
  587. static int __init irq_debugfs_init(void)
  588. {
  589. if (debugfs_create_file("irq_domain_mapping", S_IRUGO, NULL,
  590. NULL, &virq_debug_fops) == NULL)
  591. return -ENOMEM;
  592. return 0;
  593. }
  594. __initcall(irq_debugfs_init);
  595. #endif /* CONFIG_IRQ_DOMAIN_DEBUG */
  596. int irq_domain_simple_map(struct irq_domain *d, unsigned int irq,
  597. irq_hw_number_t hwirq)
  598. {
  599. return 0;
  600. }
  601. /**
  602. * irq_domain_xlate_onecell() - Generic xlate for direct one cell bindings
  603. *
  604. * Device Tree IRQ specifier translation function which works with one cell
  605. * bindings where the cell value maps directly to the hwirq number.
  606. */
  607. int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr,
  608. const u32 *intspec, unsigned int intsize,
  609. unsigned long *out_hwirq, unsigned int *out_type)
  610. {
  611. if (WARN_ON(intsize < 1))
  612. return -EINVAL;
  613. *out_hwirq = intspec[0];
  614. *out_type = IRQ_TYPE_NONE;
  615. return 0;
  616. }
  617. EXPORT_SYMBOL_GPL(irq_domain_xlate_onecell);
  618. /**
  619. * irq_domain_xlate_twocell() - Generic xlate for direct two cell bindings
  620. *
  621. * Device Tree IRQ specifier translation function which works with two cell
  622. * bindings where the cell values map directly to the hwirq number
  623. * and linux irq flags.
  624. */
  625. int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
  626. const u32 *intspec, unsigned int intsize,
  627. irq_hw_number_t *out_hwirq, unsigned int *out_type)
  628. {
  629. if (WARN_ON(intsize < 2))
  630. return -EINVAL;
  631. *out_hwirq = intspec[0];
  632. *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
  633. return 0;
  634. }
  635. EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell);
  636. /**
  637. * irq_domain_xlate_onetwocell() - Generic xlate for one or two cell bindings
  638. *
  639. * Device Tree IRQ specifier translation function which works with either one
  640. * or two cell bindings where the cell values map directly to the hwirq number
  641. * and linux irq flags.
  642. *
  643. * Note: don't use this function unless your interrupt controller explicitly
  644. * supports both one and two cell bindings. For the majority of controllers
  645. * the _onecell() or _twocell() variants above should be used.
  646. */
  647. int irq_domain_xlate_onetwocell(struct irq_domain *d,
  648. struct device_node *ctrlr,
  649. const u32 *intspec, unsigned int intsize,
  650. unsigned long *out_hwirq, unsigned int *out_type)
  651. {
  652. if (WARN_ON(intsize < 1))
  653. return -EINVAL;
  654. *out_hwirq = intspec[0];
  655. *out_type = (intsize > 1) ? intspec[1] : IRQ_TYPE_NONE;
  656. return 0;
  657. }
  658. EXPORT_SYMBOL_GPL(irq_domain_xlate_onetwocell);
  659. const struct irq_domain_ops irq_domain_simple_ops = {
  660. .map = irq_domain_simple_map,
  661. .xlate = irq_domain_xlate_onetwocell,
  662. };
  663. EXPORT_SYMBOL_GPL(irq_domain_simple_ops);
  664. #ifdef CONFIG_OF_IRQ
  665. void irq_domain_generate_simple(const struct of_device_id *match,
  666. u64 phys_base, unsigned int irq_start)
  667. {
  668. struct device_node *node;
  669. pr_debug("looking for phys_base=%llx, irq_start=%i\n",
  670. (unsigned long long) phys_base, (int) irq_start);
  671. node = of_find_matching_node_by_address(NULL, match, phys_base);
  672. if (node)
  673. irq_domain_add_legacy(node, 32, irq_start, 0,
  674. &irq_domain_simple_ops, NULL);
  675. }
  676. EXPORT_SYMBOL_GPL(irq_domain_generate_simple);
  677. #endif