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