irq.h 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. #ifdef __KERNEL__
  2. #ifndef _ASM_POWERPC_IRQ_H
  3. #define _ASM_POWERPC_IRQ_H
  4. /*
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU General Public License
  7. * as published by the Free Software Foundation; either version
  8. * 2 of the License, or (at your option) any later version.
  9. */
  10. #include <linux/irqdomain.h>
  11. #include <linux/threads.h>
  12. #include <linux/list.h>
  13. #include <linux/radix-tree.h>
  14. #include <asm/types.h>
  15. #include <linux/atomic.h>
  16. /* Define a way to iterate across irqs. */
  17. #define for_each_irq(i) \
  18. for ((i) = 0; (i) < NR_IRQS; ++(i))
  19. extern atomic_t ppc_n_lost_interrupts;
  20. /* This number is used when no interrupt has been assigned */
  21. #define NO_IRQ (0)
  22. /* This is a special irq number to return from get_irq() to tell that
  23. * no interrupt happened _and_ ignore it (don't count it as bad). Some
  24. * platforms like iSeries rely on that.
  25. */
  26. #define NO_IRQ_IGNORE ((unsigned int)-1)
  27. /* Total number of virq in the platform */
  28. #define NR_IRQS CONFIG_NR_IRQS
  29. /* Number of irqs reserved for the legacy controller */
  30. #define NUM_ISA_INTERRUPTS 16
  31. /* Same thing, used by the generic IRQ code */
  32. #define NR_IRQS_LEGACY NUM_ISA_INTERRUPTS
  33. /*
  34. * The host code and data structures are fairly agnostic to the fact that
  35. * we use an open firmware device-tree. We do have references to struct
  36. * device_node in two places: in irq_find_host() to find the host matching
  37. * a given interrupt controller node, and of course as an argument to its
  38. * counterpart host->ops->match() callback. However, those are treated as
  39. * generic pointers by the core and the fact that it's actually a device-node
  40. * pointer is purely a convention between callers and implementation. This
  41. * code could thus be used on other architectures by replacing those two
  42. * by some sort of arch-specific void * "token" used to identify interrupt
  43. * controllers.
  44. */
  45. struct irq_data;
  46. extern irq_hw_number_t irqd_to_hwirq(struct irq_data *d);
  47. extern irq_hw_number_t virq_to_hw(unsigned int virq);
  48. extern bool virq_is_host(unsigned int virq, struct irq_domain *host);
  49. /**
  50. * irq_alloc_host - Allocate a new irq_domain data structure
  51. * @of_node: optional device-tree node of the interrupt controller
  52. * @revmap_type: type of reverse mapping to use
  53. * @revmap_arg: for IRQ_DOMAIN_MAP_LINEAR linear only: size of the map
  54. * @ops: map/unmap host callbacks
  55. * @inval_irq: provide a hw number in that host space that is always invalid
  56. *
  57. * Allocates and initialize and irq_domain structure. Note that in the case of
  58. * IRQ_DOMAIN_MAP_LEGACY, the map() callback will be called before this returns
  59. * for all legacy interrupts except 0 (which is always the invalid irq for
  60. * a legacy controller). For a IRQ_DOMAIN_MAP_LINEAR, the map is allocated by
  61. * this call as well. For a IRQ_DOMAIN_MAP_TREE, the radix tree will be allocated
  62. * later during boot automatically (the reverse mapping will use the slow path
  63. * until that happens).
  64. */
  65. extern struct irq_domain *irq_alloc_host(struct device_node *of_node,
  66. unsigned int revmap_type,
  67. unsigned int revmap_arg,
  68. struct irq_domain_ops *ops,
  69. irq_hw_number_t inval_irq);
  70. /**
  71. * irq_find_host - Locates a host for a given device node
  72. * @node: device-tree node of the interrupt controller
  73. */
  74. extern struct irq_domain *irq_find_host(struct device_node *node);
  75. /**
  76. * irq_set_default_host - Set a "default" host
  77. * @host: default host pointer
  78. *
  79. * For convenience, it's possible to set a "default" host that will be used
  80. * whenever NULL is passed to irq_create_mapping(). It makes life easier for
  81. * platforms that want to manipulate a few hard coded interrupt numbers that
  82. * aren't properly represented in the device-tree.
  83. */
  84. extern void irq_set_default_host(struct irq_domain *host);
  85. /**
  86. * irq_set_virq_count - Set the maximum number of virt irqs
  87. * @count: number of linux virtual irqs, capped with NR_IRQS
  88. *
  89. * This is mainly for use by platforms like iSeries who want to program
  90. * the virtual irq number in the controller to avoid the reverse mapping
  91. */
  92. extern void irq_set_virq_count(unsigned int count);
  93. /**
  94. * irq_create_mapping - Map a hardware interrupt into linux virq space
  95. * @host: host owning this hardware interrupt or NULL for default host
  96. * @hwirq: hardware irq number in that host space
  97. *
  98. * Only one mapping per hardware interrupt is permitted. Returns a linux
  99. * virq number.
  100. * If the sense/trigger is to be specified, set_irq_type() should be called
  101. * on the number returned from that call.
  102. */
  103. extern unsigned int irq_create_mapping(struct irq_domain *host,
  104. irq_hw_number_t hwirq);
  105. /**
  106. * irq_dispose_mapping - Unmap an interrupt
  107. * @virq: linux virq number of the interrupt to unmap
  108. */
  109. extern void irq_dispose_mapping(unsigned int virq);
  110. /**
  111. * irq_find_mapping - Find a linux virq from an hw irq number.
  112. * @host: host owning this hardware interrupt
  113. * @hwirq: hardware irq number in that host space
  114. *
  115. * This is a slow path, for use by generic code. It's expected that an
  116. * irq controller implementation directly calls the appropriate low level
  117. * mapping function.
  118. */
  119. extern unsigned int irq_find_mapping(struct irq_domain *host,
  120. irq_hw_number_t hwirq);
  121. /**
  122. * irq_create_direct_mapping - Allocate a virq for direct mapping
  123. * @host: host to allocate the virq for or NULL for default host
  124. *
  125. * This routine is used for irq controllers which can choose the hardware
  126. * interrupt numbers they generate. In such a case it's simplest to use
  127. * the linux virq as the hardware interrupt number.
  128. */
  129. extern unsigned int irq_create_direct_mapping(struct irq_domain *host);
  130. /**
  131. * irq_radix_revmap_insert - Insert a hw irq to linux virq number mapping.
  132. * @host: host owning this hardware interrupt
  133. * @virq: linux irq number
  134. * @hwirq: hardware irq number in that host space
  135. *
  136. * This is for use by irq controllers that use a radix tree reverse
  137. * mapping for fast lookup.
  138. */
  139. extern void irq_radix_revmap_insert(struct irq_domain *host, unsigned int virq,
  140. irq_hw_number_t hwirq);
  141. /**
  142. * irq_radix_revmap_lookup - Find a linux virq from a hw irq number.
  143. * @host: host owning this hardware interrupt
  144. * @hwirq: hardware irq number in that host space
  145. *
  146. * This is a fast path, for use by irq controller code that uses radix tree
  147. * revmaps
  148. */
  149. extern unsigned int irq_radix_revmap_lookup(struct irq_domain *host,
  150. irq_hw_number_t hwirq);
  151. /**
  152. * irq_linear_revmap - Find a linux virq from a hw irq number.
  153. * @host: host owning this hardware interrupt
  154. * @hwirq: hardware irq number in that host space
  155. *
  156. * This is a fast path, for use by irq controller code that uses linear
  157. * revmaps. It does fallback to the slow path if the revmap doesn't exist
  158. * yet and will create the revmap entry with appropriate locking
  159. */
  160. extern unsigned int irq_linear_revmap(struct irq_domain *host,
  161. irq_hw_number_t hwirq);
  162. /**
  163. * irq_alloc_virt - Allocate virtual irq numbers
  164. * @host: host owning these new virtual irqs
  165. * @count: number of consecutive numbers to allocate
  166. * @hint: pass a hint number, the allocator will try to use a 1:1 mapping
  167. *
  168. * This is a low level function that is used internally by irq_create_mapping()
  169. * and that can be used by some irq controllers implementations for things
  170. * like allocating ranges of numbers for MSIs. The revmaps are left untouched.
  171. */
  172. extern unsigned int irq_alloc_virt(struct irq_domain *host,
  173. unsigned int count,
  174. unsigned int hint);
  175. /**
  176. * irq_free_virt - Free virtual irq numbers
  177. * @virq: virtual irq number of the first interrupt to free
  178. * @count: number of interrupts to free
  179. *
  180. * This function is the opposite of irq_alloc_virt. It will not clear reverse
  181. * maps, this should be done previously by unmap'ing the interrupt. In fact,
  182. * all interrupts covered by the range being freed should have been unmapped
  183. * prior to calling this.
  184. */
  185. extern void irq_free_virt(unsigned int virq, unsigned int count);
  186. /**
  187. * irq_early_init - Init irq remapping subsystem
  188. */
  189. extern void irq_early_init(void);
  190. static __inline__ int irq_canonicalize(int irq)
  191. {
  192. return irq;
  193. }
  194. extern int distribute_irqs;
  195. struct irqaction;
  196. struct pt_regs;
  197. #define __ARCH_HAS_DO_SOFTIRQ
  198. #if defined(CONFIG_BOOKE) || defined(CONFIG_40x)
  199. /*
  200. * Per-cpu stacks for handling critical, debug and machine check
  201. * level interrupts.
  202. */
  203. extern struct thread_info *critirq_ctx[NR_CPUS];
  204. extern struct thread_info *dbgirq_ctx[NR_CPUS];
  205. extern struct thread_info *mcheckirq_ctx[NR_CPUS];
  206. extern void exc_lvl_ctx_init(void);
  207. #else
  208. #define exc_lvl_ctx_init()
  209. #endif
  210. /*
  211. * Per-cpu stacks for handling hard and soft interrupts.
  212. */
  213. extern struct thread_info *hardirq_ctx[NR_CPUS];
  214. extern struct thread_info *softirq_ctx[NR_CPUS];
  215. extern void irq_ctx_init(void);
  216. extern void call_do_softirq(struct thread_info *tp);
  217. extern int call_handle_irq(int irq, void *p1,
  218. struct thread_info *tp, void *func);
  219. extern void do_IRQ(struct pt_regs *regs);
  220. int irq_choose_cpu(const struct cpumask *mask);
  221. #endif /* _ASM_IRQ_H */
  222. #endif /* __KERNEL__ */