irqdomain.c 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269
  1. #define pr_fmt(fmt) "irq: " fmt
  2. #include <linux/debugfs.h>
  3. #include <linux/hardirq.h>
  4. #include <linux/interrupt.h>
  5. #include <linux/irq.h>
  6. #include <linux/irqdesc.h>
  7. #include <linux/irqdomain.h>
  8. #include <linux/module.h>
  9. #include <linux/mutex.h>
  10. #include <linux/of.h>
  11. #include <linux/of_address.h>
  12. #include <linux/of_irq.h>
  13. #include <linux/topology.h>
  14. #include <linux/seq_file.h>
  15. #include <linux/slab.h>
  16. #include <linux/smp.h>
  17. #include <linux/fs.h>
  18. static LIST_HEAD(irq_domain_list);
  19. static DEFINE_MUTEX(irq_domain_mutex);
  20. static DEFINE_MUTEX(revmap_trees_mutex);
  21. static struct irq_domain *irq_default_domain;
  22. static int irq_domain_alloc_descs(int virq, unsigned int nr_irqs,
  23. irq_hw_number_t hwirq, int node);
  24. static void irq_domain_check_hierarchy(struct irq_domain *domain);
  25. /**
  26. * __irq_domain_add() - Allocate a new irq_domain data structure
  27. * @of_node: optional device-tree node of the interrupt controller
  28. * @size: Size of linear map; 0 for radix mapping only
  29. * @hwirq_max: Maximum number of interrupts supported by controller
  30. * @direct_max: Maximum value of direct maps; Use ~0 for no limit; 0 for no
  31. * direct mapping
  32. * @ops: domain callbacks
  33. * @host_data: Controller private data pointer
  34. *
  35. * Allocates and initialize and irq_domain structure.
  36. * Returns pointer to IRQ domain, or NULL on failure.
  37. */
  38. struct irq_domain *__irq_domain_add(struct device_node *of_node, int size,
  39. irq_hw_number_t hwirq_max, int direct_max,
  40. const struct irq_domain_ops *ops,
  41. void *host_data)
  42. {
  43. struct irq_domain *domain;
  44. domain = kzalloc_node(sizeof(*domain) + (sizeof(unsigned int) * size),
  45. GFP_KERNEL, of_node_to_nid(of_node));
  46. if (WARN_ON(!domain))
  47. return NULL;
  48. /* Fill structure */
  49. INIT_RADIX_TREE(&domain->revmap_tree, GFP_KERNEL);
  50. domain->ops = ops;
  51. domain->host_data = host_data;
  52. domain->of_node = of_node_get(of_node);
  53. domain->hwirq_max = hwirq_max;
  54. domain->revmap_size = size;
  55. domain->revmap_direct_max_irq = direct_max;
  56. irq_domain_check_hierarchy(domain);
  57. mutex_lock(&irq_domain_mutex);
  58. list_add(&domain->link, &irq_domain_list);
  59. mutex_unlock(&irq_domain_mutex);
  60. pr_debug("Added domain %s\n", domain->name);
  61. return domain;
  62. }
  63. EXPORT_SYMBOL_GPL(__irq_domain_add);
  64. /**
  65. * irq_domain_remove() - Remove an irq domain.
  66. * @domain: domain to remove
  67. *
  68. * This routine is used to remove an irq domain. The caller must ensure
  69. * that all mappings within the domain have been disposed of prior to
  70. * use, depending on the revmap type.
  71. */
  72. void irq_domain_remove(struct irq_domain *domain)
  73. {
  74. mutex_lock(&irq_domain_mutex);
  75. /*
  76. * radix_tree_delete() takes care of destroying the root
  77. * node when all entries are removed. Shout if there are
  78. * any mappings left.
  79. */
  80. WARN_ON(domain->revmap_tree.height);
  81. list_del(&domain->link);
  82. /*
  83. * If the going away domain is the default one, reset it.
  84. */
  85. if (unlikely(irq_default_domain == domain))
  86. irq_set_default_host(NULL);
  87. mutex_unlock(&irq_domain_mutex);
  88. pr_debug("Removed domain %s\n", domain->name);
  89. of_node_put(domain->of_node);
  90. kfree(domain);
  91. }
  92. EXPORT_SYMBOL_GPL(irq_domain_remove);
  93. /**
  94. * irq_domain_add_simple() - Register an irq_domain and optionally map a range of irqs
  95. * @of_node: pointer to interrupt controller's device tree node.
  96. * @size: total number of irqs in mapping
  97. * @first_irq: first number of irq block assigned to the domain,
  98. * pass zero to assign irqs on-the-fly. If first_irq is non-zero, then
  99. * pre-map all of the irqs in the domain to virqs starting at first_irq.
  100. * @ops: domain callbacks
  101. * @host_data: Controller private data pointer
  102. *
  103. * Allocates an irq_domain, and optionally if first_irq is positive then also
  104. * allocate irq_descs and map all of the hwirqs to virqs starting at first_irq.
  105. *
  106. * This is intended to implement the expected behaviour for most
  107. * interrupt controllers. If device tree is used, then first_irq will be 0 and
  108. * irqs get mapped dynamically on the fly. However, if the controller requires
  109. * static virq assignments (non-DT boot) then it will set that up correctly.
  110. */
  111. struct irq_domain *irq_domain_add_simple(struct device_node *of_node,
  112. unsigned int size,
  113. unsigned int first_irq,
  114. const struct irq_domain_ops *ops,
  115. void *host_data)
  116. {
  117. struct irq_domain *domain;
  118. domain = __irq_domain_add(of_node, size, size, 0, ops, host_data);
  119. if (!domain)
  120. return NULL;
  121. if (first_irq > 0) {
  122. if (IS_ENABLED(CONFIG_SPARSE_IRQ)) {
  123. /* attempt to allocated irq_descs */
  124. int rc = irq_alloc_descs(first_irq, first_irq, size,
  125. of_node_to_nid(of_node));
  126. if (rc < 0)
  127. pr_info("Cannot allocate irq_descs @ IRQ%d, assuming pre-allocated\n",
  128. first_irq);
  129. }
  130. irq_domain_associate_many(domain, first_irq, 0, size);
  131. }
  132. return domain;
  133. }
  134. EXPORT_SYMBOL_GPL(irq_domain_add_simple);
  135. /**
  136. * irq_domain_add_legacy() - Allocate and register a legacy revmap irq_domain.
  137. * @of_node: pointer to interrupt controller's device tree node.
  138. * @size: total number of irqs in legacy mapping
  139. * @first_irq: first number of irq block assigned to the domain
  140. * @first_hwirq: first hwirq number to use for the translation. Should normally
  141. * be '0', but a positive integer can be used if the effective
  142. * hwirqs numbering does not begin at zero.
  143. * @ops: map/unmap domain callbacks
  144. * @host_data: Controller private data pointer
  145. *
  146. * Note: the map() callback will be called before this function returns
  147. * for all legacy interrupts except 0 (which is always the invalid irq for
  148. * a legacy controller).
  149. */
  150. struct irq_domain *irq_domain_add_legacy(struct device_node *of_node,
  151. unsigned int size,
  152. unsigned int first_irq,
  153. irq_hw_number_t first_hwirq,
  154. const struct irq_domain_ops *ops,
  155. void *host_data)
  156. {
  157. struct irq_domain *domain;
  158. domain = __irq_domain_add(of_node, first_hwirq + size,
  159. first_hwirq + size, 0, ops, host_data);
  160. if (domain)
  161. irq_domain_associate_many(domain, first_irq, first_hwirq, size);
  162. return domain;
  163. }
  164. EXPORT_SYMBOL_GPL(irq_domain_add_legacy);
  165. /**
  166. * irq_find_matching_host() - Locates a domain for a given device node
  167. * @node: device-tree node of the interrupt controller
  168. * @bus_token: domain-specific data
  169. */
  170. struct irq_domain *irq_find_matching_host(struct device_node *node,
  171. enum irq_domain_bus_token bus_token)
  172. {
  173. struct irq_domain *h, *found = NULL;
  174. int rc;
  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. * bus_token == DOMAIN_BUS_ANY matches any domain, any other
  181. * values must generate an exact match for the domain to be
  182. * selected.
  183. */
  184. mutex_lock(&irq_domain_mutex);
  185. list_for_each_entry(h, &irq_domain_list, link) {
  186. if (h->ops->match)
  187. rc = h->ops->match(h, node, bus_token);
  188. else
  189. rc = ((h->of_node != NULL) && (h->of_node == node) &&
  190. ((bus_token == DOMAIN_BUS_ANY) ||
  191. (h->bus_token == bus_token)));
  192. if (rc) {
  193. found = h;
  194. break;
  195. }
  196. }
  197. mutex_unlock(&irq_domain_mutex);
  198. return found;
  199. }
  200. EXPORT_SYMBOL_GPL(irq_find_matching_host);
  201. /**
  202. * irq_set_default_host() - Set a "default" irq domain
  203. * @domain: default domain pointer
  204. *
  205. * For convenience, it's possible to set a "default" domain that will be used
  206. * whenever NULL is passed to irq_create_mapping(). It makes life easier for
  207. * platforms that want to manipulate a few hard coded interrupt numbers that
  208. * aren't properly represented in the device-tree.
  209. */
  210. void irq_set_default_host(struct irq_domain *domain)
  211. {
  212. pr_debug("Default domain set to @0x%p\n", domain);
  213. irq_default_domain = domain;
  214. }
  215. EXPORT_SYMBOL_GPL(irq_set_default_host);
  216. void irq_domain_disassociate(struct irq_domain *domain, unsigned int irq)
  217. {
  218. struct irq_data *irq_data = irq_get_irq_data(irq);
  219. irq_hw_number_t hwirq;
  220. if (WARN(!irq_data || irq_data->domain != domain,
  221. "virq%i doesn't exist; cannot disassociate\n", irq))
  222. return;
  223. hwirq = irq_data->hwirq;
  224. irq_set_status_flags(irq, IRQ_NOREQUEST);
  225. /* remove chip and handler */
  226. irq_set_chip_and_handler(irq, NULL, NULL);
  227. /* Make sure it's completed */
  228. synchronize_irq(irq);
  229. /* Tell the PIC about it */
  230. if (domain->ops->unmap)
  231. domain->ops->unmap(domain, irq);
  232. smp_mb();
  233. irq_data->domain = NULL;
  234. irq_data->hwirq = 0;
  235. /* Clear reverse map for this hwirq */
  236. if (hwirq < domain->revmap_size) {
  237. domain->linear_revmap[hwirq] = 0;
  238. } else {
  239. mutex_lock(&revmap_trees_mutex);
  240. radix_tree_delete(&domain->revmap_tree, hwirq);
  241. mutex_unlock(&revmap_trees_mutex);
  242. }
  243. }
  244. int irq_domain_associate(struct irq_domain *domain, unsigned int virq,
  245. irq_hw_number_t hwirq)
  246. {
  247. struct irq_data *irq_data = irq_get_irq_data(virq);
  248. int ret;
  249. if (WARN(hwirq >= domain->hwirq_max,
  250. "error: hwirq 0x%x is too large for %s\n", (int)hwirq, domain->name))
  251. return -EINVAL;
  252. if (WARN(!irq_data, "error: virq%i is not allocated", virq))
  253. return -EINVAL;
  254. if (WARN(irq_data->domain, "error: virq%i is already associated", virq))
  255. return -EINVAL;
  256. mutex_lock(&irq_domain_mutex);
  257. irq_data->hwirq = hwirq;
  258. irq_data->domain = domain;
  259. if (domain->ops->map) {
  260. ret = domain->ops->map(domain, virq, hwirq);
  261. if (ret != 0) {
  262. /*
  263. * If map() returns -EPERM, this interrupt is protected
  264. * by the firmware or some other service and shall not
  265. * be mapped. Don't bother telling the user about it.
  266. */
  267. if (ret != -EPERM) {
  268. pr_info("%s didn't like hwirq-0x%lx to VIRQ%i mapping (rc=%d)\n",
  269. domain->name, hwirq, virq, ret);
  270. }
  271. irq_data->domain = NULL;
  272. irq_data->hwirq = 0;
  273. mutex_unlock(&irq_domain_mutex);
  274. return ret;
  275. }
  276. /* If not already assigned, give the domain the chip's name */
  277. if (!domain->name && irq_data->chip)
  278. domain->name = irq_data->chip->name;
  279. }
  280. if (hwirq < domain->revmap_size) {
  281. domain->linear_revmap[hwirq] = virq;
  282. } else {
  283. mutex_lock(&revmap_trees_mutex);
  284. radix_tree_insert(&domain->revmap_tree, hwirq, irq_data);
  285. mutex_unlock(&revmap_trees_mutex);
  286. }
  287. mutex_unlock(&irq_domain_mutex);
  288. irq_clear_status_flags(virq, IRQ_NOREQUEST);
  289. return 0;
  290. }
  291. EXPORT_SYMBOL_GPL(irq_domain_associate);
  292. void irq_domain_associate_many(struct irq_domain *domain, unsigned int irq_base,
  293. irq_hw_number_t hwirq_base, int count)
  294. {
  295. int i;
  296. pr_debug("%s(%s, irqbase=%i, hwbase=%i, count=%i)\n", __func__,
  297. of_node_full_name(domain->of_node), irq_base, (int)hwirq_base, count);
  298. for (i = 0; i < count; i++) {
  299. irq_domain_associate(domain, irq_base + i, hwirq_base + i);
  300. }
  301. }
  302. EXPORT_SYMBOL_GPL(irq_domain_associate_many);
  303. /**
  304. * irq_create_direct_mapping() - Allocate an irq for direct mapping
  305. * @domain: domain to allocate the irq for or NULL for default domain
  306. *
  307. * This routine is used for irq controllers which can choose the hardware
  308. * interrupt numbers they generate. In such a case it's simplest to use
  309. * the linux irq as the hardware interrupt number. It still uses the linear
  310. * or radix tree to store the mapping, but the irq controller can optimize
  311. * the revmap path by using the hwirq directly.
  312. */
  313. unsigned int irq_create_direct_mapping(struct irq_domain *domain)
  314. {
  315. unsigned int virq;
  316. if (domain == NULL)
  317. domain = irq_default_domain;
  318. virq = irq_alloc_desc_from(1, of_node_to_nid(domain->of_node));
  319. if (!virq) {
  320. pr_debug("create_direct virq allocation failed\n");
  321. return 0;
  322. }
  323. if (virq >= domain->revmap_direct_max_irq) {
  324. pr_err("ERROR: no free irqs available below %i maximum\n",
  325. domain->revmap_direct_max_irq);
  326. irq_free_desc(virq);
  327. return 0;
  328. }
  329. pr_debug("create_direct obtained virq %d\n", virq);
  330. if (irq_domain_associate(domain, virq, virq)) {
  331. irq_free_desc(virq);
  332. return 0;
  333. }
  334. return virq;
  335. }
  336. EXPORT_SYMBOL_GPL(irq_create_direct_mapping);
  337. /**
  338. * irq_create_mapping() - Map a hardware interrupt into linux irq space
  339. * @domain: domain owning this hardware interrupt or NULL for default domain
  340. * @hwirq: hardware irq number in that domain space
  341. *
  342. * Only one mapping per hardware interrupt is permitted. Returns a linux
  343. * irq number.
  344. * If the sense/trigger is to be specified, set_irq_type() should be called
  345. * on the number returned from that call.
  346. */
  347. unsigned int irq_create_mapping(struct irq_domain *domain,
  348. irq_hw_number_t hwirq)
  349. {
  350. int virq;
  351. pr_debug("irq_create_mapping(0x%p, 0x%lx)\n", domain, hwirq);
  352. /* Look for default domain if nececssary */
  353. if (domain == NULL)
  354. domain = irq_default_domain;
  355. if (domain == NULL) {
  356. WARN(1, "%s(, %lx) called with NULL domain\n", __func__, hwirq);
  357. return 0;
  358. }
  359. pr_debug("-> using domain @%p\n", domain);
  360. /* Check if mapping already exists */
  361. virq = irq_find_mapping(domain, hwirq);
  362. if (virq) {
  363. pr_debug("-> existing mapping on virq %d\n", virq);
  364. return virq;
  365. }
  366. /* Allocate a virtual interrupt number */
  367. virq = irq_domain_alloc_descs(-1, 1, hwirq,
  368. of_node_to_nid(domain->of_node));
  369. if (virq <= 0) {
  370. pr_debug("-> virq allocation failed\n");
  371. return 0;
  372. }
  373. if (irq_domain_associate(domain, virq, hwirq)) {
  374. irq_free_desc(virq);
  375. return 0;
  376. }
  377. pr_debug("irq %lu on domain %s mapped to virtual irq %u\n",
  378. hwirq, of_node_full_name(domain->of_node), virq);
  379. return virq;
  380. }
  381. EXPORT_SYMBOL_GPL(irq_create_mapping);
  382. /**
  383. * irq_create_strict_mappings() - Map a range of hw irqs to fixed linux irqs
  384. * @domain: domain owning the interrupt range
  385. * @irq_base: beginning of linux IRQ range
  386. * @hwirq_base: beginning of hardware IRQ range
  387. * @count: Number of interrupts to map
  388. *
  389. * This routine is used for allocating and mapping a range of hardware
  390. * irqs to linux irqs where the linux irq numbers are at pre-defined
  391. * locations. For use by controllers that already have static mappings
  392. * to insert in to the domain.
  393. *
  394. * Non-linear users can use irq_create_identity_mapping() for IRQ-at-a-time
  395. * domain insertion.
  396. *
  397. * 0 is returned upon success, while any failure to establish a static
  398. * mapping is treated as an error.
  399. */
  400. int irq_create_strict_mappings(struct irq_domain *domain, unsigned int irq_base,
  401. irq_hw_number_t hwirq_base, int count)
  402. {
  403. int ret;
  404. ret = irq_alloc_descs(irq_base, irq_base, count,
  405. of_node_to_nid(domain->of_node));
  406. if (unlikely(ret < 0))
  407. return ret;
  408. irq_domain_associate_many(domain, irq_base, hwirq_base, count);
  409. return 0;
  410. }
  411. EXPORT_SYMBOL_GPL(irq_create_strict_mappings);
  412. unsigned int irq_create_of_mapping(struct of_phandle_args *irq_data)
  413. {
  414. struct irq_domain *domain;
  415. irq_hw_number_t hwirq;
  416. unsigned int type = IRQ_TYPE_NONE;
  417. int virq;
  418. domain = irq_data->np ? irq_find_host(irq_data->np) : irq_default_domain;
  419. if (!domain) {
  420. pr_warn("no irq domain found for %s !\n",
  421. of_node_full_name(irq_data->np));
  422. return 0;
  423. }
  424. /* If domain has no translation, then we assume interrupt line */
  425. if (domain->ops->xlate == NULL)
  426. hwirq = irq_data->args[0];
  427. else {
  428. if (domain->ops->xlate(domain, irq_data->np, irq_data->args,
  429. irq_data->args_count, &hwirq, &type))
  430. return 0;
  431. }
  432. if (irq_domain_is_hierarchy(domain)) {
  433. /*
  434. * If we've already configured this interrupt,
  435. * don't do it again, or hell will break loose.
  436. */
  437. virq = irq_find_mapping(domain, hwirq);
  438. if (virq)
  439. return virq;
  440. virq = irq_domain_alloc_irqs(domain, 1, NUMA_NO_NODE, irq_data);
  441. if (virq <= 0)
  442. return 0;
  443. } else {
  444. /* Create mapping */
  445. virq = irq_create_mapping(domain, hwirq);
  446. if (!virq)
  447. return virq;
  448. }
  449. /* Set type if specified and different than the current one */
  450. if (type != IRQ_TYPE_NONE &&
  451. type != irq_get_trigger_type(virq))
  452. irq_set_irq_type(virq, type);
  453. return virq;
  454. }
  455. EXPORT_SYMBOL_GPL(irq_create_of_mapping);
  456. /**
  457. * irq_dispose_mapping() - Unmap an interrupt
  458. * @virq: linux irq number of the interrupt to unmap
  459. */
  460. void irq_dispose_mapping(unsigned int virq)
  461. {
  462. struct irq_data *irq_data = irq_get_irq_data(virq);
  463. struct irq_domain *domain;
  464. if (!virq || !irq_data)
  465. return;
  466. domain = irq_data->domain;
  467. if (WARN_ON(domain == NULL))
  468. return;
  469. irq_domain_disassociate(domain, virq);
  470. irq_free_desc(virq);
  471. }
  472. EXPORT_SYMBOL_GPL(irq_dispose_mapping);
  473. /**
  474. * irq_find_mapping() - Find a linux irq from an hw irq number.
  475. * @domain: domain owning this hardware interrupt
  476. * @hwirq: hardware irq number in that domain space
  477. */
  478. unsigned int irq_find_mapping(struct irq_domain *domain,
  479. irq_hw_number_t hwirq)
  480. {
  481. struct irq_data *data;
  482. /* Look for default domain if nececssary */
  483. if (domain == NULL)
  484. domain = irq_default_domain;
  485. if (domain == NULL)
  486. return 0;
  487. if (hwirq < domain->revmap_direct_max_irq) {
  488. data = irq_domain_get_irq_data(domain, hwirq);
  489. if (data && data->hwirq == hwirq)
  490. return hwirq;
  491. }
  492. /* Check if the hwirq is in the linear revmap. */
  493. if (hwirq < domain->revmap_size)
  494. return domain->linear_revmap[hwirq];
  495. rcu_read_lock();
  496. data = radix_tree_lookup(&domain->revmap_tree, hwirq);
  497. rcu_read_unlock();
  498. return data ? data->irq : 0;
  499. }
  500. EXPORT_SYMBOL_GPL(irq_find_mapping);
  501. #ifdef CONFIG_IRQ_DOMAIN_DEBUG
  502. static int virq_debug_show(struct seq_file *m, void *private)
  503. {
  504. unsigned long flags;
  505. struct irq_desc *desc;
  506. struct irq_domain *domain;
  507. struct radix_tree_iter iter;
  508. void *data, **slot;
  509. int i;
  510. seq_printf(m, " %-16s %-6s %-10s %-10s %s\n",
  511. "name", "mapped", "linear-max", "direct-max", "devtree-node");
  512. mutex_lock(&irq_domain_mutex);
  513. list_for_each_entry(domain, &irq_domain_list, link) {
  514. int count = 0;
  515. radix_tree_for_each_slot(slot, &domain->revmap_tree, &iter, 0)
  516. count++;
  517. seq_printf(m, "%c%-16s %6u %10u %10u %s\n",
  518. domain == irq_default_domain ? '*' : ' ', domain->name,
  519. domain->revmap_size + count, domain->revmap_size,
  520. domain->revmap_direct_max_irq,
  521. domain->of_node ? of_node_full_name(domain->of_node) : "");
  522. }
  523. mutex_unlock(&irq_domain_mutex);
  524. seq_printf(m, "%-5s %-7s %-15s %-*s %6s %-14s %s\n", "irq", "hwirq",
  525. "chip name", (int)(2 * sizeof(void *) + 2), "chip data",
  526. "active", "type", "domain");
  527. for (i = 1; i < nr_irqs; i++) {
  528. desc = irq_to_desc(i);
  529. if (!desc)
  530. continue;
  531. raw_spin_lock_irqsave(&desc->lock, flags);
  532. domain = desc->irq_data.domain;
  533. if (domain) {
  534. struct irq_chip *chip;
  535. int hwirq = desc->irq_data.hwirq;
  536. bool direct;
  537. seq_printf(m, "%5d ", i);
  538. seq_printf(m, "0x%05x ", hwirq);
  539. chip = irq_desc_get_chip(desc);
  540. seq_printf(m, "%-15s ", (chip && chip->name) ? chip->name : "none");
  541. data = irq_desc_get_chip_data(desc);
  542. seq_printf(m, data ? "0x%p " : " %p ", data);
  543. seq_printf(m, " %c ", (desc->action && desc->action->handler) ? '*' : ' ');
  544. direct = (i == hwirq) && (i < domain->revmap_direct_max_irq);
  545. seq_printf(m, "%6s%-8s ",
  546. (hwirq < domain->revmap_size) ? "LINEAR" : "RADIX",
  547. direct ? "(DIRECT)" : "");
  548. seq_printf(m, "%s\n", desc->irq_data.domain->name);
  549. }
  550. raw_spin_unlock_irqrestore(&desc->lock, flags);
  551. }
  552. return 0;
  553. }
  554. static int virq_debug_open(struct inode *inode, struct file *file)
  555. {
  556. return single_open(file, virq_debug_show, inode->i_private);
  557. }
  558. static const struct file_operations virq_debug_fops = {
  559. .open = virq_debug_open,
  560. .read = seq_read,
  561. .llseek = seq_lseek,
  562. .release = single_release,
  563. };
  564. static int __init irq_debugfs_init(void)
  565. {
  566. if (debugfs_create_file("irq_domain_mapping", S_IRUGO, NULL,
  567. NULL, &virq_debug_fops) == NULL)
  568. return -ENOMEM;
  569. return 0;
  570. }
  571. __initcall(irq_debugfs_init);
  572. #endif /* CONFIG_IRQ_DOMAIN_DEBUG */
  573. /**
  574. * irq_domain_xlate_onecell() - Generic xlate for direct one cell bindings
  575. *
  576. * Device Tree IRQ specifier translation function which works with one cell
  577. * bindings where the cell value maps directly to the hwirq number.
  578. */
  579. int irq_domain_xlate_onecell(struct irq_domain *d, struct device_node *ctrlr,
  580. const u32 *intspec, unsigned int intsize,
  581. unsigned long *out_hwirq, unsigned int *out_type)
  582. {
  583. if (WARN_ON(intsize < 1))
  584. return -EINVAL;
  585. *out_hwirq = intspec[0];
  586. *out_type = IRQ_TYPE_NONE;
  587. return 0;
  588. }
  589. EXPORT_SYMBOL_GPL(irq_domain_xlate_onecell);
  590. /**
  591. * irq_domain_xlate_twocell() - Generic xlate for direct two cell bindings
  592. *
  593. * Device Tree IRQ specifier translation function which works with two cell
  594. * bindings where the cell values map directly to the hwirq number
  595. * and linux irq flags.
  596. */
  597. int irq_domain_xlate_twocell(struct irq_domain *d, struct device_node *ctrlr,
  598. const u32 *intspec, unsigned int intsize,
  599. irq_hw_number_t *out_hwirq, unsigned int *out_type)
  600. {
  601. if (WARN_ON(intsize < 2))
  602. return -EINVAL;
  603. *out_hwirq = intspec[0];
  604. *out_type = intspec[1] & IRQ_TYPE_SENSE_MASK;
  605. return 0;
  606. }
  607. EXPORT_SYMBOL_GPL(irq_domain_xlate_twocell);
  608. /**
  609. * irq_domain_xlate_onetwocell() - Generic xlate for one or two cell bindings
  610. *
  611. * Device Tree IRQ specifier translation function which works with either one
  612. * or two cell bindings where the cell values map directly to the hwirq number
  613. * and linux irq flags.
  614. *
  615. * Note: don't use this function unless your interrupt controller explicitly
  616. * supports both one and two cell bindings. For the majority of controllers
  617. * the _onecell() or _twocell() variants above should be used.
  618. */
  619. int irq_domain_xlate_onetwocell(struct irq_domain *d,
  620. struct device_node *ctrlr,
  621. const u32 *intspec, unsigned int intsize,
  622. unsigned long *out_hwirq, unsigned int *out_type)
  623. {
  624. if (WARN_ON(intsize < 1))
  625. return -EINVAL;
  626. *out_hwirq = intspec[0];
  627. *out_type = (intsize > 1) ? intspec[1] : IRQ_TYPE_NONE;
  628. return 0;
  629. }
  630. EXPORT_SYMBOL_GPL(irq_domain_xlate_onetwocell);
  631. const struct irq_domain_ops irq_domain_simple_ops = {
  632. .xlate = irq_domain_xlate_onetwocell,
  633. };
  634. EXPORT_SYMBOL_GPL(irq_domain_simple_ops);
  635. static int irq_domain_alloc_descs(int virq, unsigned int cnt,
  636. irq_hw_number_t hwirq, int node)
  637. {
  638. unsigned int hint;
  639. if (virq >= 0) {
  640. virq = irq_alloc_descs(virq, virq, cnt, node);
  641. } else {
  642. hint = hwirq % nr_irqs;
  643. if (hint == 0)
  644. hint++;
  645. virq = irq_alloc_descs_from(hint, cnt, node);
  646. if (virq <= 0 && hint > 1)
  647. virq = irq_alloc_descs_from(1, cnt, node);
  648. }
  649. return virq;
  650. }
  651. #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
  652. /**
  653. * irq_domain_add_hierarchy - Add a irqdomain into the hierarchy
  654. * @parent: Parent irq domain to associate with the new domain
  655. * @flags: Irq domain flags associated to the domain
  656. * @size: Size of the domain. See below
  657. * @node: Optional device-tree node of the interrupt controller
  658. * @ops: Pointer to the interrupt domain callbacks
  659. * @host_data: Controller private data pointer
  660. *
  661. * If @size is 0 a tree domain is created, otherwise a linear domain.
  662. *
  663. * If successful the parent is associated to the new domain and the
  664. * domain flags are set.
  665. * Returns pointer to IRQ domain, or NULL on failure.
  666. */
  667. struct irq_domain *irq_domain_add_hierarchy(struct irq_domain *parent,
  668. unsigned int flags,
  669. unsigned int size,
  670. struct device_node *node,
  671. const struct irq_domain_ops *ops,
  672. void *host_data)
  673. {
  674. struct irq_domain *domain;
  675. if (size)
  676. domain = irq_domain_add_linear(node, size, ops, host_data);
  677. else
  678. domain = irq_domain_add_tree(node, ops, host_data);
  679. if (domain) {
  680. domain->parent = parent;
  681. domain->flags |= flags;
  682. }
  683. return domain;
  684. }
  685. static void irq_domain_insert_irq(int virq)
  686. {
  687. struct irq_data *data;
  688. for (data = irq_get_irq_data(virq); data; data = data->parent_data) {
  689. struct irq_domain *domain = data->domain;
  690. irq_hw_number_t hwirq = data->hwirq;
  691. if (hwirq < domain->revmap_size) {
  692. domain->linear_revmap[hwirq] = virq;
  693. } else {
  694. mutex_lock(&revmap_trees_mutex);
  695. radix_tree_insert(&domain->revmap_tree, hwirq, data);
  696. mutex_unlock(&revmap_trees_mutex);
  697. }
  698. /* If not already assigned, give the domain the chip's name */
  699. if (!domain->name && data->chip)
  700. domain->name = data->chip->name;
  701. }
  702. irq_clear_status_flags(virq, IRQ_NOREQUEST);
  703. }
  704. static void irq_domain_remove_irq(int virq)
  705. {
  706. struct irq_data *data;
  707. irq_set_status_flags(virq, IRQ_NOREQUEST);
  708. irq_set_chip_and_handler(virq, NULL, NULL);
  709. synchronize_irq(virq);
  710. smp_mb();
  711. for (data = irq_get_irq_data(virq); data; data = data->parent_data) {
  712. struct irq_domain *domain = data->domain;
  713. irq_hw_number_t hwirq = data->hwirq;
  714. if (hwirq < domain->revmap_size) {
  715. domain->linear_revmap[hwirq] = 0;
  716. } else {
  717. mutex_lock(&revmap_trees_mutex);
  718. radix_tree_delete(&domain->revmap_tree, hwirq);
  719. mutex_unlock(&revmap_trees_mutex);
  720. }
  721. }
  722. }
  723. static struct irq_data *irq_domain_insert_irq_data(struct irq_domain *domain,
  724. struct irq_data *child)
  725. {
  726. struct irq_data *irq_data;
  727. irq_data = kzalloc_node(sizeof(*irq_data), GFP_KERNEL,
  728. irq_data_get_node(child));
  729. if (irq_data) {
  730. child->parent_data = irq_data;
  731. irq_data->irq = child->irq;
  732. irq_data->common = child->common;
  733. irq_data->node = child->node;
  734. irq_data->domain = domain;
  735. }
  736. return irq_data;
  737. }
  738. static void irq_domain_free_irq_data(unsigned int virq, unsigned int nr_irqs)
  739. {
  740. struct irq_data *irq_data, *tmp;
  741. int i;
  742. for (i = 0; i < nr_irqs; i++) {
  743. irq_data = irq_get_irq_data(virq + i);
  744. tmp = irq_data->parent_data;
  745. irq_data->parent_data = NULL;
  746. irq_data->domain = NULL;
  747. while (tmp) {
  748. irq_data = tmp;
  749. tmp = tmp->parent_data;
  750. kfree(irq_data);
  751. }
  752. }
  753. }
  754. static int irq_domain_alloc_irq_data(struct irq_domain *domain,
  755. unsigned int virq, unsigned int nr_irqs)
  756. {
  757. struct irq_data *irq_data;
  758. struct irq_domain *parent;
  759. int i;
  760. /* The outermost irq_data is embedded in struct irq_desc */
  761. for (i = 0; i < nr_irqs; i++) {
  762. irq_data = irq_get_irq_data(virq + i);
  763. irq_data->domain = domain;
  764. for (parent = domain->parent; parent; parent = parent->parent) {
  765. irq_data = irq_domain_insert_irq_data(parent, irq_data);
  766. if (!irq_data) {
  767. irq_domain_free_irq_data(virq, i + 1);
  768. return -ENOMEM;
  769. }
  770. }
  771. }
  772. return 0;
  773. }
  774. /**
  775. * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain
  776. * @domain: domain to match
  777. * @virq: IRQ number to get irq_data
  778. */
  779. struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
  780. unsigned int virq)
  781. {
  782. struct irq_data *irq_data;
  783. for (irq_data = irq_get_irq_data(virq); irq_data;
  784. irq_data = irq_data->parent_data)
  785. if (irq_data->domain == domain)
  786. return irq_data;
  787. return NULL;
  788. }
  789. /**
  790. * irq_domain_set_hwirq_and_chip - Set hwirq and irqchip of @virq at @domain
  791. * @domain: Interrupt domain to match
  792. * @virq: IRQ number
  793. * @hwirq: The hwirq number
  794. * @chip: The associated interrupt chip
  795. * @chip_data: The associated chip data
  796. */
  797. int irq_domain_set_hwirq_and_chip(struct irq_domain *domain, unsigned int virq,
  798. irq_hw_number_t hwirq, struct irq_chip *chip,
  799. void *chip_data)
  800. {
  801. struct irq_data *irq_data = irq_domain_get_irq_data(domain, virq);
  802. if (!irq_data)
  803. return -ENOENT;
  804. irq_data->hwirq = hwirq;
  805. irq_data->chip = chip ? chip : &no_irq_chip;
  806. irq_data->chip_data = chip_data;
  807. return 0;
  808. }
  809. /**
  810. * irq_domain_set_info - Set the complete data for a @virq in @domain
  811. * @domain: Interrupt domain to match
  812. * @virq: IRQ number
  813. * @hwirq: The hardware interrupt number
  814. * @chip: The associated interrupt chip
  815. * @chip_data: The associated interrupt chip data
  816. * @handler: The interrupt flow handler
  817. * @handler_data: The interrupt flow handler data
  818. * @handler_name: The interrupt handler name
  819. */
  820. void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
  821. irq_hw_number_t hwirq, struct irq_chip *chip,
  822. void *chip_data, irq_flow_handler_t handler,
  823. void *handler_data, const char *handler_name)
  824. {
  825. irq_domain_set_hwirq_and_chip(domain, virq, hwirq, chip, chip_data);
  826. __irq_set_handler(virq, handler, 0, handler_name);
  827. irq_set_handler_data(virq, handler_data);
  828. }
  829. /**
  830. * irq_domain_reset_irq_data - Clear hwirq, chip and chip_data in @irq_data
  831. * @irq_data: The pointer to irq_data
  832. */
  833. void irq_domain_reset_irq_data(struct irq_data *irq_data)
  834. {
  835. irq_data->hwirq = 0;
  836. irq_data->chip = &no_irq_chip;
  837. irq_data->chip_data = NULL;
  838. }
  839. /**
  840. * irq_domain_free_irqs_common - Clear irq_data and free the parent
  841. * @domain: Interrupt domain to match
  842. * @virq: IRQ number to start with
  843. * @nr_irqs: The number of irqs to free
  844. */
  845. void irq_domain_free_irqs_common(struct irq_domain *domain, unsigned int virq,
  846. unsigned int nr_irqs)
  847. {
  848. struct irq_data *irq_data;
  849. int i;
  850. for (i = 0; i < nr_irqs; i++) {
  851. irq_data = irq_domain_get_irq_data(domain, virq + i);
  852. if (irq_data)
  853. irq_domain_reset_irq_data(irq_data);
  854. }
  855. irq_domain_free_irqs_parent(domain, virq, nr_irqs);
  856. }
  857. /**
  858. * irq_domain_free_irqs_top - Clear handler and handler data, clear irqdata and free parent
  859. * @domain: Interrupt domain to match
  860. * @virq: IRQ number to start with
  861. * @nr_irqs: The number of irqs to free
  862. */
  863. void irq_domain_free_irqs_top(struct irq_domain *domain, unsigned int virq,
  864. unsigned int nr_irqs)
  865. {
  866. int i;
  867. for (i = 0; i < nr_irqs; i++) {
  868. irq_set_handler_data(virq + i, NULL);
  869. irq_set_handler(virq + i, NULL);
  870. }
  871. irq_domain_free_irqs_common(domain, virq, nr_irqs);
  872. }
  873. static bool irq_domain_is_auto_recursive(struct irq_domain *domain)
  874. {
  875. return domain->flags & IRQ_DOMAIN_FLAG_AUTO_RECURSIVE;
  876. }
  877. static void irq_domain_free_irqs_recursive(struct irq_domain *domain,
  878. unsigned int irq_base,
  879. unsigned int nr_irqs)
  880. {
  881. domain->ops->free(domain, irq_base, nr_irqs);
  882. if (irq_domain_is_auto_recursive(domain)) {
  883. BUG_ON(!domain->parent);
  884. irq_domain_free_irqs_recursive(domain->parent, irq_base,
  885. nr_irqs);
  886. }
  887. }
  888. static int irq_domain_alloc_irqs_recursive(struct irq_domain *domain,
  889. unsigned int irq_base,
  890. unsigned int nr_irqs, void *arg)
  891. {
  892. int ret = 0;
  893. struct irq_domain *parent = domain->parent;
  894. bool recursive = irq_domain_is_auto_recursive(domain);
  895. BUG_ON(recursive && !parent);
  896. if (recursive)
  897. ret = irq_domain_alloc_irqs_recursive(parent, irq_base,
  898. nr_irqs, arg);
  899. if (ret >= 0)
  900. ret = domain->ops->alloc(domain, irq_base, nr_irqs, arg);
  901. if (ret < 0 && recursive)
  902. irq_domain_free_irqs_recursive(parent, irq_base, nr_irqs);
  903. return ret;
  904. }
  905. /**
  906. * __irq_domain_alloc_irqs - Allocate IRQs from domain
  907. * @domain: domain to allocate from
  908. * @irq_base: allocate specified IRQ nubmer if irq_base >= 0
  909. * @nr_irqs: number of IRQs to allocate
  910. * @node: NUMA node id for memory allocation
  911. * @arg: domain specific argument
  912. * @realloc: IRQ descriptors have already been allocated if true
  913. *
  914. * Allocate IRQ numbers and initialized all data structures to support
  915. * hierarchy IRQ domains.
  916. * Parameter @realloc is mainly to support legacy IRQs.
  917. * Returns error code or allocated IRQ number
  918. *
  919. * The whole process to setup an IRQ has been split into two steps.
  920. * The first step, __irq_domain_alloc_irqs(), is to allocate IRQ
  921. * descriptor and required hardware resources. The second step,
  922. * irq_domain_activate_irq(), is to program hardwares with preallocated
  923. * resources. In this way, it's easier to rollback when failing to
  924. * allocate resources.
  925. */
  926. int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base,
  927. unsigned int nr_irqs, int node, void *arg,
  928. bool realloc)
  929. {
  930. int i, ret, virq;
  931. if (domain == NULL) {
  932. domain = irq_default_domain;
  933. if (WARN(!domain, "domain is NULL; cannot allocate IRQ\n"))
  934. return -EINVAL;
  935. }
  936. if (!domain->ops->alloc) {
  937. pr_debug("domain->ops->alloc() is NULL\n");
  938. return -ENOSYS;
  939. }
  940. if (realloc && irq_base >= 0) {
  941. virq = irq_base;
  942. } else {
  943. virq = irq_domain_alloc_descs(irq_base, nr_irqs, 0, node);
  944. if (virq < 0) {
  945. pr_debug("cannot allocate IRQ(base %d, count %d)\n",
  946. irq_base, nr_irqs);
  947. return virq;
  948. }
  949. }
  950. if (irq_domain_alloc_irq_data(domain, virq, nr_irqs)) {
  951. pr_debug("cannot allocate memory for IRQ%d\n", virq);
  952. ret = -ENOMEM;
  953. goto out_free_desc;
  954. }
  955. mutex_lock(&irq_domain_mutex);
  956. ret = irq_domain_alloc_irqs_recursive(domain, virq, nr_irqs, arg);
  957. if (ret < 0) {
  958. mutex_unlock(&irq_domain_mutex);
  959. goto out_free_irq_data;
  960. }
  961. for (i = 0; i < nr_irqs; i++)
  962. irq_domain_insert_irq(virq + i);
  963. mutex_unlock(&irq_domain_mutex);
  964. return virq;
  965. out_free_irq_data:
  966. irq_domain_free_irq_data(virq, nr_irqs);
  967. out_free_desc:
  968. irq_free_descs(virq, nr_irqs);
  969. return ret;
  970. }
  971. /**
  972. * irq_domain_free_irqs - Free IRQ number and associated data structures
  973. * @virq: base IRQ number
  974. * @nr_irqs: number of IRQs to free
  975. */
  976. void irq_domain_free_irqs(unsigned int virq, unsigned int nr_irqs)
  977. {
  978. struct irq_data *data = irq_get_irq_data(virq);
  979. int i;
  980. if (WARN(!data || !data->domain || !data->domain->ops->free,
  981. "NULL pointer, cannot free irq\n"))
  982. return;
  983. mutex_lock(&irq_domain_mutex);
  984. for (i = 0; i < nr_irqs; i++)
  985. irq_domain_remove_irq(virq + i);
  986. irq_domain_free_irqs_recursive(data->domain, virq, nr_irqs);
  987. mutex_unlock(&irq_domain_mutex);
  988. irq_domain_free_irq_data(virq, nr_irqs);
  989. irq_free_descs(virq, nr_irqs);
  990. }
  991. /**
  992. * irq_domain_alloc_irqs_parent - Allocate interrupts from parent domain
  993. * @irq_base: Base IRQ number
  994. * @nr_irqs: Number of IRQs to allocate
  995. * @arg: Allocation data (arch/domain specific)
  996. *
  997. * Check whether the domain has been setup recursive. If not allocate
  998. * through the parent domain.
  999. */
  1000. int irq_domain_alloc_irqs_parent(struct irq_domain *domain,
  1001. unsigned int irq_base, unsigned int nr_irqs,
  1002. void *arg)
  1003. {
  1004. /* irq_domain_alloc_irqs_recursive() has called parent's alloc() */
  1005. if (irq_domain_is_auto_recursive(domain))
  1006. return 0;
  1007. domain = domain->parent;
  1008. if (domain)
  1009. return irq_domain_alloc_irqs_recursive(domain, irq_base,
  1010. nr_irqs, arg);
  1011. return -ENOSYS;
  1012. }
  1013. /**
  1014. * irq_domain_free_irqs_parent - Free interrupts from parent domain
  1015. * @irq_base: Base IRQ number
  1016. * @nr_irqs: Number of IRQs to free
  1017. *
  1018. * Check whether the domain has been setup recursive. If not free
  1019. * through the parent domain.
  1020. */
  1021. void irq_domain_free_irqs_parent(struct irq_domain *domain,
  1022. unsigned int irq_base, unsigned int nr_irqs)
  1023. {
  1024. /* irq_domain_free_irqs_recursive() will call parent's free */
  1025. if (!irq_domain_is_auto_recursive(domain) && domain->parent)
  1026. irq_domain_free_irqs_recursive(domain->parent, irq_base,
  1027. nr_irqs);
  1028. }
  1029. /**
  1030. * irq_domain_activate_irq - Call domain_ops->activate recursively to activate
  1031. * interrupt
  1032. * @irq_data: outermost irq_data associated with interrupt
  1033. *
  1034. * This is the second step to call domain_ops->activate to program interrupt
  1035. * controllers, so the interrupt could actually get delivered.
  1036. */
  1037. void irq_domain_activate_irq(struct irq_data *irq_data)
  1038. {
  1039. if (irq_data && irq_data->domain) {
  1040. struct irq_domain *domain = irq_data->domain;
  1041. if (irq_data->parent_data)
  1042. irq_domain_activate_irq(irq_data->parent_data);
  1043. if (domain->ops->activate)
  1044. domain->ops->activate(domain, irq_data);
  1045. }
  1046. }
  1047. /**
  1048. * irq_domain_deactivate_irq - Call domain_ops->deactivate recursively to
  1049. * deactivate interrupt
  1050. * @irq_data: outermost irq_data associated with interrupt
  1051. *
  1052. * It calls domain_ops->deactivate to program interrupt controllers to disable
  1053. * interrupt delivery.
  1054. */
  1055. void irq_domain_deactivate_irq(struct irq_data *irq_data)
  1056. {
  1057. if (irq_data && irq_data->domain) {
  1058. struct irq_domain *domain = irq_data->domain;
  1059. if (domain->ops->deactivate)
  1060. domain->ops->deactivate(domain, irq_data);
  1061. if (irq_data->parent_data)
  1062. irq_domain_deactivate_irq(irq_data->parent_data);
  1063. }
  1064. }
  1065. static void irq_domain_check_hierarchy(struct irq_domain *domain)
  1066. {
  1067. /* Hierarchy irq_domains must implement callback alloc() */
  1068. if (domain->ops->alloc)
  1069. domain->flags |= IRQ_DOMAIN_FLAG_HIERARCHY;
  1070. }
  1071. #else /* CONFIG_IRQ_DOMAIN_HIERARCHY */
  1072. /**
  1073. * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain
  1074. * @domain: domain to match
  1075. * @virq: IRQ number to get irq_data
  1076. */
  1077. struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
  1078. unsigned int virq)
  1079. {
  1080. struct irq_data *irq_data = irq_get_irq_data(virq);
  1081. return (irq_data && irq_data->domain == domain) ? irq_data : NULL;
  1082. }
  1083. /**
  1084. * irq_domain_set_info - Set the complete data for a @virq in @domain
  1085. * @domain: Interrupt domain to match
  1086. * @virq: IRQ number
  1087. * @hwirq: The hardware interrupt number
  1088. * @chip: The associated interrupt chip
  1089. * @chip_data: The associated interrupt chip data
  1090. * @handler: The interrupt flow handler
  1091. * @handler_data: The interrupt flow handler data
  1092. * @handler_name: The interrupt handler name
  1093. */
  1094. void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
  1095. irq_hw_number_t hwirq, struct irq_chip *chip,
  1096. void *chip_data, irq_flow_handler_t handler,
  1097. void *handler_data, const char *handler_name)
  1098. {
  1099. irq_set_chip_and_handler_name(virq, chip, handler, handler_name);
  1100. irq_set_chip_data(virq, chip_data);
  1101. irq_set_handler_data(virq, handler_data);
  1102. }
  1103. static void irq_domain_check_hierarchy(struct irq_domain *domain)
  1104. {
  1105. }
  1106. #endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */