irqdomain.c 22 KB

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