irq.h 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010
  1. #ifndef _LINUX_IRQ_H
  2. #define _LINUX_IRQ_H
  3. /*
  4. * Please do not include this file in generic code. There is currently
  5. * no requirement for any architecture to implement anything held
  6. * within this file.
  7. *
  8. * Thanks. --rmk
  9. */
  10. #include <linux/smp.h>
  11. #include <linux/linkage.h>
  12. #include <linux/cache.h>
  13. #include <linux/spinlock.h>
  14. #include <linux/cpumask.h>
  15. #include <linux/gfp.h>
  16. #include <linux/irqhandler.h>
  17. #include <linux/irqreturn.h>
  18. #include <linux/irqnr.h>
  19. #include <linux/errno.h>
  20. #include <linux/topology.h>
  21. #include <linux/wait.h>
  22. #include <linux/io.h>
  23. #include <asm/irq.h>
  24. #include <asm/ptrace.h>
  25. #include <asm/irq_regs.h>
  26. struct seq_file;
  27. struct module;
  28. struct msi_msg;
  29. enum irqchip_irq_state;
  30. /*
  31. * IRQ line status.
  32. *
  33. * Bits 0-7 are the same as the IRQF_* bits in linux/interrupt.h
  34. *
  35. * IRQ_TYPE_NONE - default, unspecified type
  36. * IRQ_TYPE_EDGE_RISING - rising edge triggered
  37. * IRQ_TYPE_EDGE_FALLING - falling edge triggered
  38. * IRQ_TYPE_EDGE_BOTH - rising and falling edge triggered
  39. * IRQ_TYPE_LEVEL_HIGH - high level triggered
  40. * IRQ_TYPE_LEVEL_LOW - low level triggered
  41. * IRQ_TYPE_LEVEL_MASK - Mask to filter out the level bits
  42. * IRQ_TYPE_SENSE_MASK - Mask for all the above bits
  43. * IRQ_TYPE_DEFAULT - For use by some PICs to ask irq_set_type
  44. * to setup the HW to a sane default (used
  45. * by irqdomain map() callbacks to synchronize
  46. * the HW state and SW flags for a newly
  47. * allocated descriptor).
  48. *
  49. * IRQ_TYPE_PROBE - Special flag for probing in progress
  50. *
  51. * Bits which can be modified via irq_set/clear/modify_status_flags()
  52. * IRQ_LEVEL - Interrupt is level type. Will be also
  53. * updated in the code when the above trigger
  54. * bits are modified via irq_set_irq_type()
  55. * IRQ_PER_CPU - Mark an interrupt PER_CPU. Will protect
  56. * it from affinity setting
  57. * IRQ_NOPROBE - Interrupt cannot be probed by autoprobing
  58. * IRQ_NOREQUEST - Interrupt cannot be requested via
  59. * request_irq()
  60. * IRQ_NOTHREAD - Interrupt cannot be threaded
  61. * IRQ_NOAUTOEN - Interrupt is not automatically enabled in
  62. * request/setup_irq()
  63. * IRQ_NO_BALANCING - Interrupt cannot be balanced (affinity set)
  64. * IRQ_MOVE_PCNTXT - Interrupt can be migrated from process context
  65. * IRQ_NESTED_THREAD - Interrupt nests into another thread
  66. * IRQ_PER_CPU_DEVID - Dev_id is a per-cpu variable
  67. * IRQ_IS_POLLED - Always polled by another interrupt. Exclude
  68. * it from the spurious interrupt detection
  69. * mechanism and from core side polling.
  70. * IRQ_DISABLE_UNLAZY - Disable lazy irq disable
  71. */
  72. enum {
  73. IRQ_TYPE_NONE = 0x00000000,
  74. IRQ_TYPE_EDGE_RISING = 0x00000001,
  75. IRQ_TYPE_EDGE_FALLING = 0x00000002,
  76. IRQ_TYPE_EDGE_BOTH = (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING),
  77. IRQ_TYPE_LEVEL_HIGH = 0x00000004,
  78. IRQ_TYPE_LEVEL_LOW = 0x00000008,
  79. IRQ_TYPE_LEVEL_MASK = (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH),
  80. IRQ_TYPE_SENSE_MASK = 0x0000000f,
  81. IRQ_TYPE_DEFAULT = IRQ_TYPE_SENSE_MASK,
  82. IRQ_TYPE_PROBE = 0x00000010,
  83. IRQ_LEVEL = (1 << 8),
  84. IRQ_PER_CPU = (1 << 9),
  85. IRQ_NOPROBE = (1 << 10),
  86. IRQ_NOREQUEST = (1 << 11),
  87. IRQ_NOAUTOEN = (1 << 12),
  88. IRQ_NO_BALANCING = (1 << 13),
  89. IRQ_MOVE_PCNTXT = (1 << 14),
  90. IRQ_NESTED_THREAD = (1 << 15),
  91. IRQ_NOTHREAD = (1 << 16),
  92. IRQ_PER_CPU_DEVID = (1 << 17),
  93. IRQ_IS_POLLED = (1 << 18),
  94. IRQ_DISABLE_UNLAZY = (1 << 19),
  95. };
  96. #define IRQF_MODIFY_MASK \
  97. (IRQ_TYPE_SENSE_MASK | IRQ_NOPROBE | IRQ_NOREQUEST | \
  98. IRQ_NOAUTOEN | IRQ_MOVE_PCNTXT | IRQ_LEVEL | IRQ_NO_BALANCING | \
  99. IRQ_PER_CPU | IRQ_NESTED_THREAD | IRQ_NOTHREAD | IRQ_PER_CPU_DEVID | \
  100. IRQ_IS_POLLED | IRQ_DISABLE_UNLAZY)
  101. #define IRQ_NO_BALANCING_MASK (IRQ_PER_CPU | IRQ_NO_BALANCING)
  102. /*
  103. * Return value for chip->irq_set_affinity()
  104. *
  105. * IRQ_SET_MASK_OK - OK, core updates irq_common_data.affinity
  106. * IRQ_SET_MASK_NOCPY - OK, chip did update irq_common_data.affinity
  107. * IRQ_SET_MASK_OK_DONE - Same as IRQ_SET_MASK_OK for core. Special code to
  108. * support stacked irqchips, which indicates skipping
  109. * all descendent irqchips.
  110. */
  111. enum {
  112. IRQ_SET_MASK_OK = 0,
  113. IRQ_SET_MASK_OK_NOCOPY,
  114. IRQ_SET_MASK_OK_DONE,
  115. };
  116. struct msi_desc;
  117. struct irq_domain;
  118. /**
  119. * struct irq_common_data - per irq data shared by all irqchips
  120. * @state_use_accessors: status information for irq chip functions.
  121. * Use accessor functions to deal with it
  122. * @node: node index useful for balancing
  123. * @handler_data: per-IRQ data for the irq_chip methods
  124. * @affinity: IRQ affinity on SMP. If this is an IPI
  125. * related irq, then this is the mask of the
  126. * CPUs to which an IPI can be sent.
  127. * @msi_desc: MSI descriptor
  128. * @ipi_offset: Offset of first IPI target cpu in @affinity. Optional.
  129. */
  130. struct irq_common_data {
  131. unsigned int __private state_use_accessors;
  132. #ifdef CONFIG_NUMA
  133. unsigned int node;
  134. #endif
  135. void *handler_data;
  136. struct msi_desc *msi_desc;
  137. cpumask_var_t affinity;
  138. #ifdef CONFIG_GENERIC_IRQ_IPI
  139. unsigned int ipi_offset;
  140. #endif
  141. };
  142. /**
  143. * struct irq_data - per irq chip data passed down to chip functions
  144. * @mask: precomputed bitmask for accessing the chip registers
  145. * @irq: interrupt number
  146. * @hwirq: hardware interrupt number, local to the interrupt domain
  147. * @common: point to data shared by all irqchips
  148. * @chip: low level interrupt hardware access
  149. * @domain: Interrupt translation domain; responsible for mapping
  150. * between hwirq number and linux irq number.
  151. * @parent_data: pointer to parent struct irq_data to support hierarchy
  152. * irq_domain
  153. * @chip_data: platform-specific per-chip private data for the chip
  154. * methods, to allow shared chip implementations
  155. */
  156. struct irq_data {
  157. u32 mask;
  158. unsigned int irq;
  159. unsigned long hwirq;
  160. struct irq_common_data *common;
  161. struct irq_chip *chip;
  162. struct irq_domain *domain;
  163. #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
  164. struct irq_data *parent_data;
  165. #endif
  166. void *chip_data;
  167. };
  168. /*
  169. * Bit masks for irq_common_data.state_use_accessors
  170. *
  171. * IRQD_TRIGGER_MASK - Mask for the trigger type bits
  172. * IRQD_SETAFFINITY_PENDING - Affinity setting is pending
  173. * IRQD_ACTIVATED - Interrupt has already been activated
  174. * IRQD_NO_BALANCING - Balancing disabled for this IRQ
  175. * IRQD_PER_CPU - Interrupt is per cpu
  176. * IRQD_AFFINITY_SET - Interrupt affinity was set
  177. * IRQD_LEVEL - Interrupt is level triggered
  178. * IRQD_WAKEUP_STATE - Interrupt is configured for wakeup
  179. * from suspend
  180. * IRDQ_MOVE_PCNTXT - Interrupt can be moved in process
  181. * context
  182. * IRQD_IRQ_DISABLED - Disabled state of the interrupt
  183. * IRQD_IRQ_MASKED - Masked state of the interrupt
  184. * IRQD_IRQ_INPROGRESS - In progress state of the interrupt
  185. * IRQD_WAKEUP_ARMED - Wakeup mode armed
  186. * IRQD_FORWARDED_TO_VCPU - The interrupt is forwarded to a VCPU
  187. * IRQD_AFFINITY_MANAGED - Affinity is auto-managed by the kernel
  188. */
  189. enum {
  190. IRQD_TRIGGER_MASK = 0xf,
  191. IRQD_SETAFFINITY_PENDING = (1 << 8),
  192. IRQD_ACTIVATED = (1 << 9),
  193. IRQD_NO_BALANCING = (1 << 10),
  194. IRQD_PER_CPU = (1 << 11),
  195. IRQD_AFFINITY_SET = (1 << 12),
  196. IRQD_LEVEL = (1 << 13),
  197. IRQD_WAKEUP_STATE = (1 << 14),
  198. IRQD_MOVE_PCNTXT = (1 << 15),
  199. IRQD_IRQ_DISABLED = (1 << 16),
  200. IRQD_IRQ_MASKED = (1 << 17),
  201. IRQD_IRQ_INPROGRESS = (1 << 18),
  202. IRQD_WAKEUP_ARMED = (1 << 19),
  203. IRQD_FORWARDED_TO_VCPU = (1 << 20),
  204. IRQD_AFFINITY_MANAGED = (1 << 21),
  205. };
  206. #define __irqd_to_state(d) ACCESS_PRIVATE((d)->common, state_use_accessors)
  207. static inline bool irqd_is_setaffinity_pending(struct irq_data *d)
  208. {
  209. return __irqd_to_state(d) & IRQD_SETAFFINITY_PENDING;
  210. }
  211. static inline bool irqd_is_per_cpu(struct irq_data *d)
  212. {
  213. return __irqd_to_state(d) & IRQD_PER_CPU;
  214. }
  215. static inline bool irqd_can_balance(struct irq_data *d)
  216. {
  217. return !(__irqd_to_state(d) & (IRQD_PER_CPU | IRQD_NO_BALANCING));
  218. }
  219. static inline bool irqd_affinity_was_set(struct irq_data *d)
  220. {
  221. return __irqd_to_state(d) & IRQD_AFFINITY_SET;
  222. }
  223. static inline void irqd_mark_affinity_was_set(struct irq_data *d)
  224. {
  225. __irqd_to_state(d) |= IRQD_AFFINITY_SET;
  226. }
  227. static inline u32 irqd_get_trigger_type(struct irq_data *d)
  228. {
  229. return __irqd_to_state(d) & IRQD_TRIGGER_MASK;
  230. }
  231. /*
  232. * Must only be called inside irq_chip.irq_set_type() functions.
  233. */
  234. static inline void irqd_set_trigger_type(struct irq_data *d, u32 type)
  235. {
  236. __irqd_to_state(d) &= ~IRQD_TRIGGER_MASK;
  237. __irqd_to_state(d) |= type & IRQD_TRIGGER_MASK;
  238. }
  239. static inline bool irqd_is_level_type(struct irq_data *d)
  240. {
  241. return __irqd_to_state(d) & IRQD_LEVEL;
  242. }
  243. static inline bool irqd_is_wakeup_set(struct irq_data *d)
  244. {
  245. return __irqd_to_state(d) & IRQD_WAKEUP_STATE;
  246. }
  247. static inline bool irqd_can_move_in_process_context(struct irq_data *d)
  248. {
  249. return __irqd_to_state(d) & IRQD_MOVE_PCNTXT;
  250. }
  251. static inline bool irqd_irq_disabled(struct irq_data *d)
  252. {
  253. return __irqd_to_state(d) & IRQD_IRQ_DISABLED;
  254. }
  255. static inline bool irqd_irq_masked(struct irq_data *d)
  256. {
  257. return __irqd_to_state(d) & IRQD_IRQ_MASKED;
  258. }
  259. static inline bool irqd_irq_inprogress(struct irq_data *d)
  260. {
  261. return __irqd_to_state(d) & IRQD_IRQ_INPROGRESS;
  262. }
  263. static inline bool irqd_is_wakeup_armed(struct irq_data *d)
  264. {
  265. return __irqd_to_state(d) & IRQD_WAKEUP_ARMED;
  266. }
  267. static inline bool irqd_is_forwarded_to_vcpu(struct irq_data *d)
  268. {
  269. return __irqd_to_state(d) & IRQD_FORWARDED_TO_VCPU;
  270. }
  271. static inline void irqd_set_forwarded_to_vcpu(struct irq_data *d)
  272. {
  273. __irqd_to_state(d) |= IRQD_FORWARDED_TO_VCPU;
  274. }
  275. static inline void irqd_clr_forwarded_to_vcpu(struct irq_data *d)
  276. {
  277. __irqd_to_state(d) &= ~IRQD_FORWARDED_TO_VCPU;
  278. }
  279. static inline bool irqd_affinity_is_managed(struct irq_data *d)
  280. {
  281. return __irqd_to_state(d) & IRQD_AFFINITY_MANAGED;
  282. }
  283. static inline bool irqd_is_activated(struct irq_data *d)
  284. {
  285. return __irqd_to_state(d) & IRQD_ACTIVATED;
  286. }
  287. static inline void irqd_set_activated(struct irq_data *d)
  288. {
  289. __irqd_to_state(d) |= IRQD_ACTIVATED;
  290. }
  291. static inline void irqd_clr_activated(struct irq_data *d)
  292. {
  293. __irqd_to_state(d) &= ~IRQD_ACTIVATED;
  294. }
  295. #undef __irqd_to_state
  296. static inline irq_hw_number_t irqd_to_hwirq(struct irq_data *d)
  297. {
  298. return d->hwirq;
  299. }
  300. /**
  301. * struct irq_chip - hardware interrupt chip descriptor
  302. *
  303. * @parent_device: pointer to parent device for irqchip
  304. * @name: name for /proc/interrupts
  305. * @irq_startup: start up the interrupt (defaults to ->enable if NULL)
  306. * @irq_shutdown: shut down the interrupt (defaults to ->disable if NULL)
  307. * @irq_enable: enable the interrupt (defaults to chip->unmask if NULL)
  308. * @irq_disable: disable the interrupt
  309. * @irq_ack: start of a new interrupt
  310. * @irq_mask: mask an interrupt source
  311. * @irq_mask_ack: ack and mask an interrupt source
  312. * @irq_unmask: unmask an interrupt source
  313. * @irq_eoi: end of interrupt
  314. * @irq_set_affinity: set the CPU affinity on SMP machines
  315. * @irq_retrigger: resend an IRQ to the CPU
  316. * @irq_set_type: set the flow type (IRQ_TYPE_LEVEL/etc.) of an IRQ
  317. * @irq_set_wake: enable/disable power-management wake-on of an IRQ
  318. * @irq_bus_lock: function to lock access to slow bus (i2c) chips
  319. * @irq_bus_sync_unlock:function to sync and unlock slow bus (i2c) chips
  320. * @irq_cpu_online: configure an interrupt source for a secondary CPU
  321. * @irq_cpu_offline: un-configure an interrupt source for a secondary CPU
  322. * @irq_suspend: function called from core code on suspend once per
  323. * chip, when one or more interrupts are installed
  324. * @irq_resume: function called from core code on resume once per chip,
  325. * when one ore more interrupts are installed
  326. * @irq_pm_shutdown: function called from core code on shutdown once per chip
  327. * @irq_calc_mask: Optional function to set irq_data.mask for special cases
  328. * @irq_print_chip: optional to print special chip info in show_interrupts
  329. * @irq_request_resources: optional to request resources before calling
  330. * any other callback related to this irq
  331. * @irq_release_resources: optional to release resources acquired with
  332. * irq_request_resources
  333. * @irq_compose_msi_msg: optional to compose message content for MSI
  334. * @irq_write_msi_msg: optional to write message content for MSI
  335. * @irq_get_irqchip_state: return the internal state of an interrupt
  336. * @irq_set_irqchip_state: set the internal state of a interrupt
  337. * @irq_set_vcpu_affinity: optional to target a vCPU in a virtual machine
  338. * @ipi_send_single: send a single IPI to destination cpus
  339. * @ipi_send_mask: send an IPI to destination cpus in cpumask
  340. * @flags: chip specific flags
  341. */
  342. struct irq_chip {
  343. struct device *parent_device;
  344. const char *name;
  345. unsigned int (*irq_startup)(struct irq_data *data);
  346. void (*irq_shutdown)(struct irq_data *data);
  347. void (*irq_enable)(struct irq_data *data);
  348. void (*irq_disable)(struct irq_data *data);
  349. void (*irq_ack)(struct irq_data *data);
  350. void (*irq_mask)(struct irq_data *data);
  351. void (*irq_mask_ack)(struct irq_data *data);
  352. void (*irq_unmask)(struct irq_data *data);
  353. void (*irq_eoi)(struct irq_data *data);
  354. int (*irq_set_affinity)(struct irq_data *data, const struct cpumask *dest, bool force);
  355. int (*irq_retrigger)(struct irq_data *data);
  356. int (*irq_set_type)(struct irq_data *data, unsigned int flow_type);
  357. int (*irq_set_wake)(struct irq_data *data, unsigned int on);
  358. void (*irq_bus_lock)(struct irq_data *data);
  359. void (*irq_bus_sync_unlock)(struct irq_data *data);
  360. void (*irq_cpu_online)(struct irq_data *data);
  361. void (*irq_cpu_offline)(struct irq_data *data);
  362. void (*irq_suspend)(struct irq_data *data);
  363. void (*irq_resume)(struct irq_data *data);
  364. void (*irq_pm_shutdown)(struct irq_data *data);
  365. void (*irq_calc_mask)(struct irq_data *data);
  366. void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
  367. int (*irq_request_resources)(struct irq_data *data);
  368. void (*irq_release_resources)(struct irq_data *data);
  369. void (*irq_compose_msi_msg)(struct irq_data *data, struct msi_msg *msg);
  370. void (*irq_write_msi_msg)(struct irq_data *data, struct msi_msg *msg);
  371. int (*irq_get_irqchip_state)(struct irq_data *data, enum irqchip_irq_state which, bool *state);
  372. int (*irq_set_irqchip_state)(struct irq_data *data, enum irqchip_irq_state which, bool state);
  373. int (*irq_set_vcpu_affinity)(struct irq_data *data, void *vcpu_info);
  374. void (*ipi_send_single)(struct irq_data *data, unsigned int cpu);
  375. void (*ipi_send_mask)(struct irq_data *data, const struct cpumask *dest);
  376. unsigned long flags;
  377. };
  378. /*
  379. * irq_chip specific flags
  380. *
  381. * IRQCHIP_SET_TYPE_MASKED: Mask before calling chip.irq_set_type()
  382. * IRQCHIP_EOI_IF_HANDLED: Only issue irq_eoi() when irq was handled
  383. * IRQCHIP_MASK_ON_SUSPEND: Mask non wake irqs in the suspend path
  384. * IRQCHIP_ONOFFLINE_ENABLED: Only call irq_on/off_line callbacks
  385. * when irq enabled
  386. * IRQCHIP_SKIP_SET_WAKE: Skip chip.irq_set_wake(), for this irq chip
  387. * IRQCHIP_ONESHOT_SAFE: One shot does not require mask/unmask
  388. * IRQCHIP_EOI_THREADED: Chip requires eoi() on unmask in threaded mode
  389. */
  390. enum {
  391. IRQCHIP_SET_TYPE_MASKED = (1 << 0),
  392. IRQCHIP_EOI_IF_HANDLED = (1 << 1),
  393. IRQCHIP_MASK_ON_SUSPEND = (1 << 2),
  394. IRQCHIP_ONOFFLINE_ENABLED = (1 << 3),
  395. IRQCHIP_SKIP_SET_WAKE = (1 << 4),
  396. IRQCHIP_ONESHOT_SAFE = (1 << 5),
  397. IRQCHIP_EOI_THREADED = (1 << 6),
  398. };
  399. #include <linux/irqdesc.h>
  400. /*
  401. * Pick up the arch-dependent methods:
  402. */
  403. #include <asm/hw_irq.h>
  404. #ifndef NR_IRQS_LEGACY
  405. # define NR_IRQS_LEGACY 0
  406. #endif
  407. #ifndef ARCH_IRQ_INIT_FLAGS
  408. # define ARCH_IRQ_INIT_FLAGS 0
  409. #endif
  410. #define IRQ_DEFAULT_INIT_FLAGS ARCH_IRQ_INIT_FLAGS
  411. struct irqaction;
  412. extern int setup_irq(unsigned int irq, struct irqaction *new);
  413. extern void remove_irq(unsigned int irq, struct irqaction *act);
  414. extern int setup_percpu_irq(unsigned int irq, struct irqaction *new);
  415. extern void remove_percpu_irq(unsigned int irq, struct irqaction *act);
  416. extern void irq_cpu_online(void);
  417. extern void irq_cpu_offline(void);
  418. extern int irq_set_affinity_locked(struct irq_data *data,
  419. const struct cpumask *cpumask, bool force);
  420. extern int irq_set_vcpu_affinity(unsigned int irq, void *vcpu_info);
  421. extern void irq_migrate_all_off_this_cpu(void);
  422. #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_PENDING_IRQ)
  423. void irq_move_irq(struct irq_data *data);
  424. void irq_move_masked_irq(struct irq_data *data);
  425. #else
  426. static inline void irq_move_irq(struct irq_data *data) { }
  427. static inline void irq_move_masked_irq(struct irq_data *data) { }
  428. #endif
  429. extern int no_irq_affinity;
  430. #ifdef CONFIG_HARDIRQS_SW_RESEND
  431. int irq_set_parent(int irq, int parent_irq);
  432. #else
  433. static inline int irq_set_parent(int irq, int parent_irq)
  434. {
  435. return 0;
  436. }
  437. #endif
  438. /*
  439. * Built-in IRQ handlers for various IRQ types,
  440. * callable via desc->handle_irq()
  441. */
  442. extern void handle_level_irq(struct irq_desc *desc);
  443. extern void handle_fasteoi_irq(struct irq_desc *desc);
  444. extern void handle_edge_irq(struct irq_desc *desc);
  445. extern void handle_edge_eoi_irq(struct irq_desc *desc);
  446. extern void handle_simple_irq(struct irq_desc *desc);
  447. extern void handle_untracked_irq(struct irq_desc *desc);
  448. extern void handle_percpu_irq(struct irq_desc *desc);
  449. extern void handle_percpu_devid_irq(struct irq_desc *desc);
  450. extern void handle_bad_irq(struct irq_desc *desc);
  451. extern void handle_nested_irq(unsigned int irq);
  452. extern int irq_chip_compose_msi_msg(struct irq_data *data, struct msi_msg *msg);
  453. extern int irq_chip_pm_get(struct irq_data *data);
  454. extern int irq_chip_pm_put(struct irq_data *data);
  455. #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
  456. extern void irq_chip_enable_parent(struct irq_data *data);
  457. extern void irq_chip_disable_parent(struct irq_data *data);
  458. extern void irq_chip_ack_parent(struct irq_data *data);
  459. extern int irq_chip_retrigger_hierarchy(struct irq_data *data);
  460. extern void irq_chip_mask_parent(struct irq_data *data);
  461. extern void irq_chip_unmask_parent(struct irq_data *data);
  462. extern void irq_chip_eoi_parent(struct irq_data *data);
  463. extern int irq_chip_set_affinity_parent(struct irq_data *data,
  464. const struct cpumask *dest,
  465. bool force);
  466. extern int irq_chip_set_wake_parent(struct irq_data *data, unsigned int on);
  467. extern int irq_chip_set_vcpu_affinity_parent(struct irq_data *data,
  468. void *vcpu_info);
  469. extern int irq_chip_set_type_parent(struct irq_data *data, unsigned int type);
  470. #endif
  471. /* Handling of unhandled and spurious interrupts: */
  472. extern void note_interrupt(struct irq_desc *desc, irqreturn_t action_ret);
  473. /* Enable/disable irq debugging output: */
  474. extern int noirqdebug_setup(char *str);
  475. /* Checks whether the interrupt can be requested by request_irq(): */
  476. extern int can_request_irq(unsigned int irq, unsigned long irqflags);
  477. /* Dummy irq-chip implementations: */
  478. extern struct irq_chip no_irq_chip;
  479. extern struct irq_chip dummy_irq_chip;
  480. extern void
  481. irq_set_chip_and_handler_name(unsigned int irq, struct irq_chip *chip,
  482. irq_flow_handler_t handle, const char *name);
  483. static inline void irq_set_chip_and_handler(unsigned int irq, struct irq_chip *chip,
  484. irq_flow_handler_t handle)
  485. {
  486. irq_set_chip_and_handler_name(irq, chip, handle, NULL);
  487. }
  488. extern int irq_set_percpu_devid(unsigned int irq);
  489. extern int irq_set_percpu_devid_partition(unsigned int irq,
  490. const struct cpumask *affinity);
  491. extern int irq_get_percpu_devid_partition(unsigned int irq,
  492. struct cpumask *affinity);
  493. extern void
  494. __irq_set_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
  495. const char *name);
  496. static inline void
  497. irq_set_handler(unsigned int irq, irq_flow_handler_t handle)
  498. {
  499. __irq_set_handler(irq, handle, 0, NULL);
  500. }
  501. /*
  502. * Set a highlevel chained flow handler for a given IRQ.
  503. * (a chained handler is automatically enabled and set to
  504. * IRQ_NOREQUEST, IRQ_NOPROBE, and IRQ_NOTHREAD)
  505. */
  506. static inline void
  507. irq_set_chained_handler(unsigned int irq, irq_flow_handler_t handle)
  508. {
  509. __irq_set_handler(irq, handle, 1, NULL);
  510. }
  511. /*
  512. * Set a highlevel chained flow handler and its data for a given IRQ.
  513. * (a chained handler is automatically enabled and set to
  514. * IRQ_NOREQUEST, IRQ_NOPROBE, and IRQ_NOTHREAD)
  515. */
  516. void
  517. irq_set_chained_handler_and_data(unsigned int irq, irq_flow_handler_t handle,
  518. void *data);
  519. void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set);
  520. static inline void irq_set_status_flags(unsigned int irq, unsigned long set)
  521. {
  522. irq_modify_status(irq, 0, set);
  523. }
  524. static inline void irq_clear_status_flags(unsigned int irq, unsigned long clr)
  525. {
  526. irq_modify_status(irq, clr, 0);
  527. }
  528. static inline void irq_set_noprobe(unsigned int irq)
  529. {
  530. irq_modify_status(irq, 0, IRQ_NOPROBE);
  531. }
  532. static inline void irq_set_probe(unsigned int irq)
  533. {
  534. irq_modify_status(irq, IRQ_NOPROBE, 0);
  535. }
  536. static inline void irq_set_nothread(unsigned int irq)
  537. {
  538. irq_modify_status(irq, 0, IRQ_NOTHREAD);
  539. }
  540. static inline void irq_set_thread(unsigned int irq)
  541. {
  542. irq_modify_status(irq, IRQ_NOTHREAD, 0);
  543. }
  544. static inline void irq_set_nested_thread(unsigned int irq, bool nest)
  545. {
  546. if (nest)
  547. irq_set_status_flags(irq, IRQ_NESTED_THREAD);
  548. else
  549. irq_clear_status_flags(irq, IRQ_NESTED_THREAD);
  550. }
  551. static inline void irq_set_percpu_devid_flags(unsigned int irq)
  552. {
  553. irq_set_status_flags(irq,
  554. IRQ_NOAUTOEN | IRQ_PER_CPU | IRQ_NOTHREAD |
  555. IRQ_NOPROBE | IRQ_PER_CPU_DEVID);
  556. }
  557. /* Set/get chip/data for an IRQ: */
  558. extern int irq_set_chip(unsigned int irq, struct irq_chip *chip);
  559. extern int irq_set_handler_data(unsigned int irq, void *data);
  560. extern int irq_set_chip_data(unsigned int irq, void *data);
  561. extern int irq_set_irq_type(unsigned int irq, unsigned int type);
  562. extern int irq_set_msi_desc(unsigned int irq, struct msi_desc *entry);
  563. extern int irq_set_msi_desc_off(unsigned int irq_base, unsigned int irq_offset,
  564. struct msi_desc *entry);
  565. extern struct irq_data *irq_get_irq_data(unsigned int irq);
  566. static inline struct irq_chip *irq_get_chip(unsigned int irq)
  567. {
  568. struct irq_data *d = irq_get_irq_data(irq);
  569. return d ? d->chip : NULL;
  570. }
  571. static inline struct irq_chip *irq_data_get_irq_chip(struct irq_data *d)
  572. {
  573. return d->chip;
  574. }
  575. static inline void *irq_get_chip_data(unsigned int irq)
  576. {
  577. struct irq_data *d = irq_get_irq_data(irq);
  578. return d ? d->chip_data : NULL;
  579. }
  580. static inline void *irq_data_get_irq_chip_data(struct irq_data *d)
  581. {
  582. return d->chip_data;
  583. }
  584. static inline void *irq_get_handler_data(unsigned int irq)
  585. {
  586. struct irq_data *d = irq_get_irq_data(irq);
  587. return d ? d->common->handler_data : NULL;
  588. }
  589. static inline void *irq_data_get_irq_handler_data(struct irq_data *d)
  590. {
  591. return d->common->handler_data;
  592. }
  593. static inline struct msi_desc *irq_get_msi_desc(unsigned int irq)
  594. {
  595. struct irq_data *d = irq_get_irq_data(irq);
  596. return d ? d->common->msi_desc : NULL;
  597. }
  598. static inline struct msi_desc *irq_data_get_msi_desc(struct irq_data *d)
  599. {
  600. return d->common->msi_desc;
  601. }
  602. static inline u32 irq_get_trigger_type(unsigned int irq)
  603. {
  604. struct irq_data *d = irq_get_irq_data(irq);
  605. return d ? irqd_get_trigger_type(d) : 0;
  606. }
  607. static inline int irq_common_data_get_node(struct irq_common_data *d)
  608. {
  609. #ifdef CONFIG_NUMA
  610. return d->node;
  611. #else
  612. return 0;
  613. #endif
  614. }
  615. static inline int irq_data_get_node(struct irq_data *d)
  616. {
  617. return irq_common_data_get_node(d->common);
  618. }
  619. static inline struct cpumask *irq_get_affinity_mask(int irq)
  620. {
  621. struct irq_data *d = irq_get_irq_data(irq);
  622. return d ? d->common->affinity : NULL;
  623. }
  624. static inline struct cpumask *irq_data_get_affinity_mask(struct irq_data *d)
  625. {
  626. return d->common->affinity;
  627. }
  628. unsigned int arch_dynirq_lower_bound(unsigned int from);
  629. int __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
  630. struct module *owner, const struct cpumask *affinity);
  631. /* use macros to avoid needing export.h for THIS_MODULE */
  632. #define irq_alloc_descs(irq, from, cnt, node) \
  633. __irq_alloc_descs(irq, from, cnt, node, THIS_MODULE, NULL)
  634. #define irq_alloc_desc(node) \
  635. irq_alloc_descs(-1, 0, 1, node)
  636. #define irq_alloc_desc_at(at, node) \
  637. irq_alloc_descs(at, at, 1, node)
  638. #define irq_alloc_desc_from(from, node) \
  639. irq_alloc_descs(-1, from, 1, node)
  640. #define irq_alloc_descs_from(from, cnt, node) \
  641. irq_alloc_descs(-1, from, cnt, node)
  642. void irq_free_descs(unsigned int irq, unsigned int cnt);
  643. static inline void irq_free_desc(unsigned int irq)
  644. {
  645. irq_free_descs(irq, 1);
  646. }
  647. #ifdef CONFIG_GENERIC_IRQ_LEGACY_ALLOC_HWIRQ
  648. unsigned int irq_alloc_hwirqs(int cnt, int node);
  649. static inline unsigned int irq_alloc_hwirq(int node)
  650. {
  651. return irq_alloc_hwirqs(1, node);
  652. }
  653. void irq_free_hwirqs(unsigned int from, int cnt);
  654. static inline void irq_free_hwirq(unsigned int irq)
  655. {
  656. return irq_free_hwirqs(irq, 1);
  657. }
  658. int arch_setup_hwirq(unsigned int irq, int node);
  659. void arch_teardown_hwirq(unsigned int irq);
  660. #endif
  661. #ifdef CONFIG_GENERIC_IRQ_LEGACY
  662. void irq_init_desc(unsigned int irq);
  663. #endif
  664. /**
  665. * struct irq_chip_regs - register offsets for struct irq_gci
  666. * @enable: Enable register offset to reg_base
  667. * @disable: Disable register offset to reg_base
  668. * @mask: Mask register offset to reg_base
  669. * @ack: Ack register offset to reg_base
  670. * @eoi: Eoi register offset to reg_base
  671. * @type: Type configuration register offset to reg_base
  672. * @polarity: Polarity configuration register offset to reg_base
  673. */
  674. struct irq_chip_regs {
  675. unsigned long enable;
  676. unsigned long disable;
  677. unsigned long mask;
  678. unsigned long ack;
  679. unsigned long eoi;
  680. unsigned long type;
  681. unsigned long polarity;
  682. };
  683. /**
  684. * struct irq_chip_type - Generic interrupt chip instance for a flow type
  685. * @chip: The real interrupt chip which provides the callbacks
  686. * @regs: Register offsets for this chip
  687. * @handler: Flow handler associated with this chip
  688. * @type: Chip can handle these flow types
  689. * @mask_cache_priv: Cached mask register private to the chip type
  690. * @mask_cache: Pointer to cached mask register
  691. *
  692. * A irq_generic_chip can have several instances of irq_chip_type when
  693. * it requires different functions and register offsets for different
  694. * flow types.
  695. */
  696. struct irq_chip_type {
  697. struct irq_chip chip;
  698. struct irq_chip_regs regs;
  699. irq_flow_handler_t handler;
  700. u32 type;
  701. u32 mask_cache_priv;
  702. u32 *mask_cache;
  703. };
  704. /**
  705. * struct irq_chip_generic - Generic irq chip data structure
  706. * @lock: Lock to protect register and cache data access
  707. * @reg_base: Register base address (virtual)
  708. * @reg_readl: Alternate I/O accessor (defaults to readl if NULL)
  709. * @reg_writel: Alternate I/O accessor (defaults to writel if NULL)
  710. * @suspend: Function called from core code on suspend once per
  711. * chip; can be useful instead of irq_chip::suspend to
  712. * handle chip details even when no interrupts are in use
  713. * @resume: Function called from core code on resume once per chip;
  714. * can be useful instead of irq_chip::suspend to handle
  715. * chip details even when no interrupts are in use
  716. * @irq_base: Interrupt base nr for this chip
  717. * @irq_cnt: Number of interrupts handled by this chip
  718. * @mask_cache: Cached mask register shared between all chip types
  719. * @type_cache: Cached type register
  720. * @polarity_cache: Cached polarity register
  721. * @wake_enabled: Interrupt can wakeup from suspend
  722. * @wake_active: Interrupt is marked as an wakeup from suspend source
  723. * @num_ct: Number of available irq_chip_type instances (usually 1)
  724. * @private: Private data for non generic chip callbacks
  725. * @installed: bitfield to denote installed interrupts
  726. * @unused: bitfield to denote unused interrupts
  727. * @domain: irq domain pointer
  728. * @list: List head for keeping track of instances
  729. * @chip_types: Array of interrupt irq_chip_types
  730. *
  731. * Note, that irq_chip_generic can have multiple irq_chip_type
  732. * implementations which can be associated to a particular irq line of
  733. * an irq_chip_generic instance. That allows to share and protect
  734. * state in an irq_chip_generic instance when we need to implement
  735. * different flow mechanisms (level/edge) for it.
  736. */
  737. struct irq_chip_generic {
  738. raw_spinlock_t lock;
  739. void __iomem *reg_base;
  740. u32 (*reg_readl)(void __iomem *addr);
  741. void (*reg_writel)(u32 val, void __iomem *addr);
  742. void (*suspend)(struct irq_chip_generic *gc);
  743. void (*resume)(struct irq_chip_generic *gc);
  744. unsigned int irq_base;
  745. unsigned int irq_cnt;
  746. u32 mask_cache;
  747. u32 type_cache;
  748. u32 polarity_cache;
  749. u32 wake_enabled;
  750. u32 wake_active;
  751. unsigned int num_ct;
  752. void *private;
  753. unsigned long installed;
  754. unsigned long unused;
  755. struct irq_domain *domain;
  756. struct list_head list;
  757. struct irq_chip_type chip_types[0];
  758. };
  759. /**
  760. * enum irq_gc_flags - Initialization flags for generic irq chips
  761. * @IRQ_GC_INIT_MASK_CACHE: Initialize the mask_cache by reading mask reg
  762. * @IRQ_GC_INIT_NESTED_LOCK: Set the lock class of the irqs to nested for
  763. * irq chips which need to call irq_set_wake() on
  764. * the parent irq. Usually GPIO implementations
  765. * @IRQ_GC_MASK_CACHE_PER_TYPE: Mask cache is chip type private
  766. * @IRQ_GC_NO_MASK: Do not calculate irq_data->mask
  767. * @IRQ_GC_BE_IO: Use big-endian register accesses (default: LE)
  768. */
  769. enum irq_gc_flags {
  770. IRQ_GC_INIT_MASK_CACHE = 1 << 0,
  771. IRQ_GC_INIT_NESTED_LOCK = 1 << 1,
  772. IRQ_GC_MASK_CACHE_PER_TYPE = 1 << 2,
  773. IRQ_GC_NO_MASK = 1 << 3,
  774. IRQ_GC_BE_IO = 1 << 4,
  775. };
  776. /*
  777. * struct irq_domain_chip_generic - Generic irq chip data structure for irq domains
  778. * @irqs_per_chip: Number of interrupts per chip
  779. * @num_chips: Number of chips
  780. * @irq_flags_to_set: IRQ* flags to set on irq setup
  781. * @irq_flags_to_clear: IRQ* flags to clear on irq setup
  782. * @gc_flags: Generic chip specific setup flags
  783. * @gc: Array of pointers to generic interrupt chips
  784. */
  785. struct irq_domain_chip_generic {
  786. unsigned int irqs_per_chip;
  787. unsigned int num_chips;
  788. unsigned int irq_flags_to_clear;
  789. unsigned int irq_flags_to_set;
  790. enum irq_gc_flags gc_flags;
  791. struct irq_chip_generic *gc[0];
  792. };
  793. /* Generic chip callback functions */
  794. void irq_gc_noop(struct irq_data *d);
  795. void irq_gc_mask_disable_reg(struct irq_data *d);
  796. void irq_gc_mask_set_bit(struct irq_data *d);
  797. void irq_gc_mask_clr_bit(struct irq_data *d);
  798. void irq_gc_unmask_enable_reg(struct irq_data *d);
  799. void irq_gc_ack_set_bit(struct irq_data *d);
  800. void irq_gc_ack_clr_bit(struct irq_data *d);
  801. void irq_gc_mask_disable_reg_and_ack(struct irq_data *d);
  802. void irq_gc_eoi(struct irq_data *d);
  803. int irq_gc_set_wake(struct irq_data *d, unsigned int on);
  804. /* Setup functions for irq_chip_generic */
  805. int irq_map_generic_chip(struct irq_domain *d, unsigned int virq,
  806. irq_hw_number_t hw_irq);
  807. struct irq_chip_generic *
  808. irq_alloc_generic_chip(const char *name, int nr_ct, unsigned int irq_base,
  809. void __iomem *reg_base, irq_flow_handler_t handler);
  810. void irq_setup_generic_chip(struct irq_chip_generic *gc, u32 msk,
  811. enum irq_gc_flags flags, unsigned int clr,
  812. unsigned int set);
  813. int irq_setup_alt_chip(struct irq_data *d, unsigned int type);
  814. void irq_remove_generic_chip(struct irq_chip_generic *gc, u32 msk,
  815. unsigned int clr, unsigned int set);
  816. struct irq_chip_generic *irq_get_domain_generic_chip(struct irq_domain *d, unsigned int hw_irq);
  817. int __irq_alloc_domain_generic_chips(struct irq_domain *d, int irqs_per_chip,
  818. int num_ct, const char *name,
  819. irq_flow_handler_t handler,
  820. unsigned int clr, unsigned int set,
  821. enum irq_gc_flags flags);
  822. #define irq_alloc_domain_generic_chips(d, irqs_per_chip, num_ct, name, \
  823. handler, clr, set, flags) \
  824. ({ \
  825. MAYBE_BUILD_BUG_ON(irqs_per_chip > 32); \
  826. __irq_alloc_domain_generic_chips(d, irqs_per_chip, num_ct, name,\
  827. handler, clr, set, flags); \
  828. })
  829. static inline struct irq_chip_type *irq_data_get_chip_type(struct irq_data *d)
  830. {
  831. return container_of(d->chip, struct irq_chip_type, chip);
  832. }
  833. #define IRQ_MSK(n) (u32)((n) < 32 ? ((1 << (n)) - 1) : UINT_MAX)
  834. #ifdef CONFIG_SMP
  835. static inline void irq_gc_lock(struct irq_chip_generic *gc)
  836. {
  837. raw_spin_lock(&gc->lock);
  838. }
  839. static inline void irq_gc_unlock(struct irq_chip_generic *gc)
  840. {
  841. raw_spin_unlock(&gc->lock);
  842. }
  843. #else
  844. static inline void irq_gc_lock(struct irq_chip_generic *gc) { }
  845. static inline void irq_gc_unlock(struct irq_chip_generic *gc) { }
  846. #endif
  847. /*
  848. * The irqsave variants are for usage in non interrupt code. Do not use
  849. * them in irq_chip callbacks. Use irq_gc_lock() instead.
  850. */
  851. #define irq_gc_lock_irqsave(gc, flags) \
  852. raw_spin_lock_irqsave(&(gc)->lock, flags)
  853. #define irq_gc_unlock_irqrestore(gc, flags) \
  854. raw_spin_unlock_irqrestore(&(gc)->lock, flags)
  855. static inline void irq_reg_writel(struct irq_chip_generic *gc,
  856. u32 val, int reg_offset)
  857. {
  858. if (gc->reg_writel)
  859. gc->reg_writel(val, gc->reg_base + reg_offset);
  860. else
  861. writel(val, gc->reg_base + reg_offset);
  862. }
  863. static inline u32 irq_reg_readl(struct irq_chip_generic *gc,
  864. int reg_offset)
  865. {
  866. if (gc->reg_readl)
  867. return gc->reg_readl(gc->reg_base + reg_offset);
  868. else
  869. return readl(gc->reg_base + reg_offset);
  870. }
  871. /* Contrary to Linux irqs, for hardware irqs the irq number 0 is valid */
  872. #define INVALID_HWIRQ (~0UL)
  873. irq_hw_number_t ipi_get_hwirq(unsigned int irq, unsigned int cpu);
  874. int __ipi_send_single(struct irq_desc *desc, unsigned int cpu);
  875. int __ipi_send_mask(struct irq_desc *desc, const struct cpumask *dest);
  876. int ipi_send_single(unsigned int virq, unsigned int cpu);
  877. int ipi_send_mask(unsigned int virq, const struct cpumask *dest);
  878. #endif /* _LINUX_IRQ_H */