irqdomain.c 36 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268
  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->domain = domain;
  734. }
  735. return irq_data;
  736. }
  737. static void irq_domain_free_irq_data(unsigned int virq, unsigned int nr_irqs)
  738. {
  739. struct irq_data *irq_data, *tmp;
  740. int i;
  741. for (i = 0; i < nr_irqs; i++) {
  742. irq_data = irq_get_irq_data(virq + i);
  743. tmp = irq_data->parent_data;
  744. irq_data->parent_data = NULL;
  745. irq_data->domain = NULL;
  746. while (tmp) {
  747. irq_data = tmp;
  748. tmp = tmp->parent_data;
  749. kfree(irq_data);
  750. }
  751. }
  752. }
  753. static int irq_domain_alloc_irq_data(struct irq_domain *domain,
  754. unsigned int virq, unsigned int nr_irqs)
  755. {
  756. struct irq_data *irq_data;
  757. struct irq_domain *parent;
  758. int i;
  759. /* The outermost irq_data is embedded in struct irq_desc */
  760. for (i = 0; i < nr_irqs; i++) {
  761. irq_data = irq_get_irq_data(virq + i);
  762. irq_data->domain = domain;
  763. for (parent = domain->parent; parent; parent = parent->parent) {
  764. irq_data = irq_domain_insert_irq_data(parent, irq_data);
  765. if (!irq_data) {
  766. irq_domain_free_irq_data(virq, i + 1);
  767. return -ENOMEM;
  768. }
  769. }
  770. }
  771. return 0;
  772. }
  773. /**
  774. * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain
  775. * @domain: domain to match
  776. * @virq: IRQ number to get irq_data
  777. */
  778. struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
  779. unsigned int virq)
  780. {
  781. struct irq_data *irq_data;
  782. for (irq_data = irq_get_irq_data(virq); irq_data;
  783. irq_data = irq_data->parent_data)
  784. if (irq_data->domain == domain)
  785. return irq_data;
  786. return NULL;
  787. }
  788. /**
  789. * irq_domain_set_hwirq_and_chip - Set hwirq and irqchip of @virq at @domain
  790. * @domain: Interrupt domain to match
  791. * @virq: IRQ number
  792. * @hwirq: The hwirq number
  793. * @chip: The associated interrupt chip
  794. * @chip_data: The associated chip data
  795. */
  796. int irq_domain_set_hwirq_and_chip(struct irq_domain *domain, unsigned int virq,
  797. irq_hw_number_t hwirq, struct irq_chip *chip,
  798. void *chip_data)
  799. {
  800. struct irq_data *irq_data = irq_domain_get_irq_data(domain, virq);
  801. if (!irq_data)
  802. return -ENOENT;
  803. irq_data->hwirq = hwirq;
  804. irq_data->chip = chip ? chip : &no_irq_chip;
  805. irq_data->chip_data = chip_data;
  806. return 0;
  807. }
  808. /**
  809. * irq_domain_set_info - Set the complete data for a @virq in @domain
  810. * @domain: Interrupt domain to match
  811. * @virq: IRQ number
  812. * @hwirq: The hardware interrupt number
  813. * @chip: The associated interrupt chip
  814. * @chip_data: The associated interrupt chip data
  815. * @handler: The interrupt flow handler
  816. * @handler_data: The interrupt flow handler data
  817. * @handler_name: The interrupt handler name
  818. */
  819. void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
  820. irq_hw_number_t hwirq, struct irq_chip *chip,
  821. void *chip_data, irq_flow_handler_t handler,
  822. void *handler_data, const char *handler_name)
  823. {
  824. irq_domain_set_hwirq_and_chip(domain, virq, hwirq, chip, chip_data);
  825. __irq_set_handler(virq, handler, 0, handler_name);
  826. irq_set_handler_data(virq, handler_data);
  827. }
  828. /**
  829. * irq_domain_reset_irq_data - Clear hwirq, chip and chip_data in @irq_data
  830. * @irq_data: The pointer to irq_data
  831. */
  832. void irq_domain_reset_irq_data(struct irq_data *irq_data)
  833. {
  834. irq_data->hwirq = 0;
  835. irq_data->chip = &no_irq_chip;
  836. irq_data->chip_data = NULL;
  837. }
  838. /**
  839. * irq_domain_free_irqs_common - Clear irq_data and free the parent
  840. * @domain: Interrupt domain to match
  841. * @virq: IRQ number to start with
  842. * @nr_irqs: The number of irqs to free
  843. */
  844. void irq_domain_free_irqs_common(struct irq_domain *domain, unsigned int virq,
  845. unsigned int nr_irqs)
  846. {
  847. struct irq_data *irq_data;
  848. int i;
  849. for (i = 0; i < nr_irqs; i++) {
  850. irq_data = irq_domain_get_irq_data(domain, virq + i);
  851. if (irq_data)
  852. irq_domain_reset_irq_data(irq_data);
  853. }
  854. irq_domain_free_irqs_parent(domain, virq, nr_irqs);
  855. }
  856. /**
  857. * irq_domain_free_irqs_top - Clear handler and handler data, clear irqdata and free parent
  858. * @domain: Interrupt domain to match
  859. * @virq: IRQ number to start with
  860. * @nr_irqs: The number of irqs to free
  861. */
  862. void irq_domain_free_irqs_top(struct irq_domain *domain, unsigned int virq,
  863. unsigned int nr_irqs)
  864. {
  865. int i;
  866. for (i = 0; i < nr_irqs; i++) {
  867. irq_set_handler_data(virq + i, NULL);
  868. irq_set_handler(virq + i, NULL);
  869. }
  870. irq_domain_free_irqs_common(domain, virq, nr_irqs);
  871. }
  872. static bool irq_domain_is_auto_recursive(struct irq_domain *domain)
  873. {
  874. return domain->flags & IRQ_DOMAIN_FLAG_AUTO_RECURSIVE;
  875. }
  876. static void irq_domain_free_irqs_recursive(struct irq_domain *domain,
  877. unsigned int irq_base,
  878. unsigned int nr_irqs)
  879. {
  880. domain->ops->free(domain, irq_base, nr_irqs);
  881. if (irq_domain_is_auto_recursive(domain)) {
  882. BUG_ON(!domain->parent);
  883. irq_domain_free_irqs_recursive(domain->parent, irq_base,
  884. nr_irqs);
  885. }
  886. }
  887. static int irq_domain_alloc_irqs_recursive(struct irq_domain *domain,
  888. unsigned int irq_base,
  889. unsigned int nr_irqs, void *arg)
  890. {
  891. int ret = 0;
  892. struct irq_domain *parent = domain->parent;
  893. bool recursive = irq_domain_is_auto_recursive(domain);
  894. BUG_ON(recursive && !parent);
  895. if (recursive)
  896. ret = irq_domain_alloc_irqs_recursive(parent, irq_base,
  897. nr_irqs, arg);
  898. if (ret >= 0)
  899. ret = domain->ops->alloc(domain, irq_base, nr_irqs, arg);
  900. if (ret < 0 && recursive)
  901. irq_domain_free_irqs_recursive(parent, irq_base, nr_irqs);
  902. return ret;
  903. }
  904. /**
  905. * __irq_domain_alloc_irqs - Allocate IRQs from domain
  906. * @domain: domain to allocate from
  907. * @irq_base: allocate specified IRQ nubmer if irq_base >= 0
  908. * @nr_irqs: number of IRQs to allocate
  909. * @node: NUMA node id for memory allocation
  910. * @arg: domain specific argument
  911. * @realloc: IRQ descriptors have already been allocated if true
  912. *
  913. * Allocate IRQ numbers and initialized all data structures to support
  914. * hierarchy IRQ domains.
  915. * Parameter @realloc is mainly to support legacy IRQs.
  916. * Returns error code or allocated IRQ number
  917. *
  918. * The whole process to setup an IRQ has been split into two steps.
  919. * The first step, __irq_domain_alloc_irqs(), is to allocate IRQ
  920. * descriptor and required hardware resources. The second step,
  921. * irq_domain_activate_irq(), is to program hardwares with preallocated
  922. * resources. In this way, it's easier to rollback when failing to
  923. * allocate resources.
  924. */
  925. int __irq_domain_alloc_irqs(struct irq_domain *domain, int irq_base,
  926. unsigned int nr_irqs, int node, void *arg,
  927. bool realloc)
  928. {
  929. int i, ret, virq;
  930. if (domain == NULL) {
  931. domain = irq_default_domain;
  932. if (WARN(!domain, "domain is NULL; cannot allocate IRQ\n"))
  933. return -EINVAL;
  934. }
  935. if (!domain->ops->alloc) {
  936. pr_debug("domain->ops->alloc() is NULL\n");
  937. return -ENOSYS;
  938. }
  939. if (realloc && irq_base >= 0) {
  940. virq = irq_base;
  941. } else {
  942. virq = irq_domain_alloc_descs(irq_base, nr_irqs, 0, node);
  943. if (virq < 0) {
  944. pr_debug("cannot allocate IRQ(base %d, count %d)\n",
  945. irq_base, nr_irqs);
  946. return virq;
  947. }
  948. }
  949. if (irq_domain_alloc_irq_data(domain, virq, nr_irqs)) {
  950. pr_debug("cannot allocate memory for IRQ%d\n", virq);
  951. ret = -ENOMEM;
  952. goto out_free_desc;
  953. }
  954. mutex_lock(&irq_domain_mutex);
  955. ret = irq_domain_alloc_irqs_recursive(domain, virq, nr_irqs, arg);
  956. if (ret < 0) {
  957. mutex_unlock(&irq_domain_mutex);
  958. goto out_free_irq_data;
  959. }
  960. for (i = 0; i < nr_irqs; i++)
  961. irq_domain_insert_irq(virq + i);
  962. mutex_unlock(&irq_domain_mutex);
  963. return virq;
  964. out_free_irq_data:
  965. irq_domain_free_irq_data(virq, nr_irqs);
  966. out_free_desc:
  967. irq_free_descs(virq, nr_irqs);
  968. return ret;
  969. }
  970. /**
  971. * irq_domain_free_irqs - Free IRQ number and associated data structures
  972. * @virq: base IRQ number
  973. * @nr_irqs: number of IRQs to free
  974. */
  975. void irq_domain_free_irqs(unsigned int virq, unsigned int nr_irqs)
  976. {
  977. struct irq_data *data = irq_get_irq_data(virq);
  978. int i;
  979. if (WARN(!data || !data->domain || !data->domain->ops->free,
  980. "NULL pointer, cannot free irq\n"))
  981. return;
  982. mutex_lock(&irq_domain_mutex);
  983. for (i = 0; i < nr_irqs; i++)
  984. irq_domain_remove_irq(virq + i);
  985. irq_domain_free_irqs_recursive(data->domain, virq, nr_irqs);
  986. mutex_unlock(&irq_domain_mutex);
  987. irq_domain_free_irq_data(virq, nr_irqs);
  988. irq_free_descs(virq, nr_irqs);
  989. }
  990. /**
  991. * irq_domain_alloc_irqs_parent - Allocate interrupts from parent domain
  992. * @irq_base: Base IRQ number
  993. * @nr_irqs: Number of IRQs to allocate
  994. * @arg: Allocation data (arch/domain specific)
  995. *
  996. * Check whether the domain has been setup recursive. If not allocate
  997. * through the parent domain.
  998. */
  999. int irq_domain_alloc_irqs_parent(struct irq_domain *domain,
  1000. unsigned int irq_base, unsigned int nr_irqs,
  1001. void *arg)
  1002. {
  1003. /* irq_domain_alloc_irqs_recursive() has called parent's alloc() */
  1004. if (irq_domain_is_auto_recursive(domain))
  1005. return 0;
  1006. domain = domain->parent;
  1007. if (domain)
  1008. return irq_domain_alloc_irqs_recursive(domain, irq_base,
  1009. nr_irqs, arg);
  1010. return -ENOSYS;
  1011. }
  1012. /**
  1013. * irq_domain_free_irqs_parent - Free interrupts from parent domain
  1014. * @irq_base: Base IRQ number
  1015. * @nr_irqs: Number of IRQs to free
  1016. *
  1017. * Check whether the domain has been setup recursive. If not free
  1018. * through the parent domain.
  1019. */
  1020. void irq_domain_free_irqs_parent(struct irq_domain *domain,
  1021. unsigned int irq_base, unsigned int nr_irqs)
  1022. {
  1023. /* irq_domain_free_irqs_recursive() will call parent's free */
  1024. if (!irq_domain_is_auto_recursive(domain) && domain->parent)
  1025. irq_domain_free_irqs_recursive(domain->parent, irq_base,
  1026. nr_irqs);
  1027. }
  1028. /**
  1029. * irq_domain_activate_irq - Call domain_ops->activate recursively to activate
  1030. * interrupt
  1031. * @irq_data: outermost irq_data associated with interrupt
  1032. *
  1033. * This is the second step to call domain_ops->activate to program interrupt
  1034. * controllers, so the interrupt could actually get delivered.
  1035. */
  1036. void irq_domain_activate_irq(struct irq_data *irq_data)
  1037. {
  1038. if (irq_data && irq_data->domain) {
  1039. struct irq_domain *domain = irq_data->domain;
  1040. if (irq_data->parent_data)
  1041. irq_domain_activate_irq(irq_data->parent_data);
  1042. if (domain->ops->activate)
  1043. domain->ops->activate(domain, irq_data);
  1044. }
  1045. }
  1046. /**
  1047. * irq_domain_deactivate_irq - Call domain_ops->deactivate recursively to
  1048. * deactivate interrupt
  1049. * @irq_data: outermost irq_data associated with interrupt
  1050. *
  1051. * It calls domain_ops->deactivate to program interrupt controllers to disable
  1052. * interrupt delivery.
  1053. */
  1054. void irq_domain_deactivate_irq(struct irq_data *irq_data)
  1055. {
  1056. if (irq_data && irq_data->domain) {
  1057. struct irq_domain *domain = irq_data->domain;
  1058. if (domain->ops->deactivate)
  1059. domain->ops->deactivate(domain, irq_data);
  1060. if (irq_data->parent_data)
  1061. irq_domain_deactivate_irq(irq_data->parent_data);
  1062. }
  1063. }
  1064. static void irq_domain_check_hierarchy(struct irq_domain *domain)
  1065. {
  1066. /* Hierarchy irq_domains must implement callback alloc() */
  1067. if (domain->ops->alloc)
  1068. domain->flags |= IRQ_DOMAIN_FLAG_HIERARCHY;
  1069. }
  1070. #else /* CONFIG_IRQ_DOMAIN_HIERARCHY */
  1071. /**
  1072. * irq_domain_get_irq_data - Get irq_data associated with @virq and @domain
  1073. * @domain: domain to match
  1074. * @virq: IRQ number to get irq_data
  1075. */
  1076. struct irq_data *irq_domain_get_irq_data(struct irq_domain *domain,
  1077. unsigned int virq)
  1078. {
  1079. struct irq_data *irq_data = irq_get_irq_data(virq);
  1080. return (irq_data && irq_data->domain == domain) ? irq_data : NULL;
  1081. }
  1082. /**
  1083. * irq_domain_set_info - Set the complete data for a @virq in @domain
  1084. * @domain: Interrupt domain to match
  1085. * @virq: IRQ number
  1086. * @hwirq: The hardware interrupt number
  1087. * @chip: The associated interrupt chip
  1088. * @chip_data: The associated interrupt chip data
  1089. * @handler: The interrupt flow handler
  1090. * @handler_data: The interrupt flow handler data
  1091. * @handler_name: The interrupt handler name
  1092. */
  1093. void irq_domain_set_info(struct irq_domain *domain, unsigned int virq,
  1094. irq_hw_number_t hwirq, struct irq_chip *chip,
  1095. void *chip_data, irq_flow_handler_t handler,
  1096. void *handler_data, const char *handler_name)
  1097. {
  1098. irq_set_chip_and_handler_name(virq, chip, handler, handler_name);
  1099. irq_set_chip_data(virq, chip_data);
  1100. irq_set_handler_data(virq, handler_data);
  1101. }
  1102. static void irq_domain_check_hierarchy(struct irq_domain *domain)
  1103. {
  1104. }
  1105. #endif /* CONFIG_IRQ_DOMAIN_HIERARCHY */