irq.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _LINUX_IRQ_H
  3. #define _LINUX_IRQ_H
  4. /*
  5. * Please do not include this file in generic code. There is currently
  6. * no requirement for any architecture to implement anything held
  7. * within this file.
  8. *
  9. * Thanks. --rmk
  10. */
  11. #include <linux/cache.h>
  12. #include <linux/spinlock.h>
  13. #include <linux/cpumask.h>
  14. #include <linux/irqhandler.h>
  15. #include <linux/irqreturn.h>
  16. #include <linux/irqnr.h>
  17. #include <linux/topology.h>
  18. #include <linux/io.h>
  19. #include <linux/slab.h>
  20. #include <asm/irq.h>
  21. #include <asm/ptrace.h>
  22. #include <asm/irq_regs.h>
  23. struct seq_file;
  24. struct module;
  25. struct msi_msg;
  26. struct irq_affinity_desc;
  27. enum irqchip_irq_state;
  28. /*
  29. * IRQ line status.
  30. *
  31. * Bits 0-7 are the same as the IRQF_* bits in linux/interrupt.h
  32. *
  33. * IRQ_TYPE_NONE - default, unspecified type
  34. * IRQ_TYPE_EDGE_RISING - rising edge triggered
  35. * IRQ_TYPE_EDGE_FALLING - falling edge triggered
  36. * IRQ_TYPE_EDGE_BOTH - rising and falling edge triggered
  37. * IRQ_TYPE_LEVEL_HIGH - high level triggered
  38. * IRQ_TYPE_LEVEL_LOW - low level triggered
  39. * IRQ_TYPE_LEVEL_MASK - Mask to filter out the level bits
  40. * IRQ_TYPE_SENSE_MASK - Mask for all the above bits
  41. * IRQ_TYPE_DEFAULT - For use by some PICs to ask irq_set_type
  42. * to setup the HW to a sane default (used
  43. * by irqdomain map() callbacks to synchronize
  44. * the HW state and SW flags for a newly
  45. * allocated descriptor).
  46. *
  47. * IRQ_TYPE_PROBE - Special flag for probing in progress
  48. *
  49. * Bits which can be modified via irq_set/clear/modify_status_flags()
  50. * IRQ_LEVEL - Interrupt is level type. Will be also
  51. * updated in the code when the above trigger
  52. * bits are modified via irq_set_irq_type()
  53. * IRQ_PER_CPU - Mark an interrupt PER_CPU. Will protect
  54. * it from affinity setting
  55. * IRQ_NOPROBE - Interrupt cannot be probed by autoprobing
  56. * IRQ_NOREQUEST - Interrupt cannot be requested via
  57. * request_irq()
  58. * IRQ_NOTHREAD - Interrupt cannot be threaded
  59. * IRQ_NOAUTOEN - Interrupt is not automatically enabled in
  60. * request/setup_irq()
  61. * IRQ_NO_BALANCING - Interrupt cannot be balanced (affinity set)
  62. * IRQ_MOVE_PCNTXT - Interrupt can be migrated from process context
  63. * IRQ_NESTED_THREAD - Interrupt nests into another thread
  64. * IRQ_PER_CPU_DEVID - Dev_id is a per-cpu variable
  65. * IRQ_IS_POLLED - Always polled by another interrupt. Exclude
  66. * it from the spurious interrupt detection
  67. * mechanism and from core side polling.
  68. * IRQ_DISABLE_UNLAZY - Disable lazy irq disable
  69. * IRQ_HIDDEN - Don't show up in /proc/interrupts
  70. * IRQ_NO_DEBUG - Exclude from note_interrupt() debugging
  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. IRQ_HIDDEN = (1 << 20),
  96. IRQ_NO_DEBUG = (1 << 21),
  97. };
  98. #define IRQF_MODIFY_MASK \
  99. (IRQ_TYPE_SENSE_MASK | IRQ_NOPROBE | IRQ_NOREQUEST | \
  100. IRQ_NOAUTOEN | IRQ_MOVE_PCNTXT | IRQ_LEVEL | IRQ_NO_BALANCING | \
  101. IRQ_PER_CPU | IRQ_NESTED_THREAD | IRQ_NOTHREAD | IRQ_PER_CPU_DEVID | \
  102. IRQ_IS_POLLED | IRQ_DISABLE_UNLAZY | IRQ_HIDDEN)
  103. #define IRQ_NO_BALANCING_MASK (IRQ_PER_CPU | IRQ_NO_BALANCING)
  104. /*
  105. * Return value for chip->irq_set_affinity()
  106. *
  107. * IRQ_SET_MASK_OK - OK, core updates irq_common_data.affinity
  108. * IRQ_SET_MASK_NOCPY - OK, chip did update irq_common_data.affinity
  109. * IRQ_SET_MASK_OK_DONE - Same as IRQ_SET_MASK_OK for core. Special code to
  110. * support stacked irqchips, which indicates skipping
  111. * all descendant irqchips.
  112. */
  113. enum {
  114. IRQ_SET_MASK_OK = 0,
  115. IRQ_SET_MASK_OK_NOCOPY,
  116. IRQ_SET_MASK_OK_DONE,
  117. };
  118. struct msi_desc;
  119. struct irq_domain;
  120. /**
  121. * struct irq_common_data - per irq data shared by all irqchips
  122. * @state_use_accessors: status information for irq chip functions.
  123. * Use accessor functions to deal with it
  124. * @node: node index useful for balancing
  125. * @handler_data: per-IRQ data for the irq_chip methods
  126. * @affinity: IRQ affinity on SMP. If this is an IPI
  127. * related irq, then this is the mask of the
  128. * CPUs to which an IPI can be sent.
  129. * @effective_affinity: The effective IRQ affinity on SMP as some irq
  130. * chips do not allow multi CPU destinations.
  131. * A subset of @affinity.
  132. * @msi_desc: MSI descriptor
  133. * @ipi_offset: Offset of first IPI target cpu in @affinity. Optional.
  134. */
  135. struct irq_common_data {
  136. unsigned int __private state_use_accessors;
  137. #ifdef CONFIG_NUMA
  138. unsigned int node;
  139. #endif
  140. void *handler_data;
  141. struct msi_desc *msi_desc;
  142. #ifdef CONFIG_SMP
  143. cpumask_var_t affinity;
  144. #endif
  145. #ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
  146. cpumask_var_t effective_affinity;
  147. #endif
  148. #ifdef CONFIG_GENERIC_IRQ_IPI
  149. unsigned int ipi_offset;
  150. #endif
  151. };
  152. /**
  153. * struct irq_data - per irq chip data passed down to chip functions
  154. * @mask: precomputed bitmask for accessing the chip registers
  155. * @irq: interrupt number
  156. * @hwirq: hardware interrupt number, local to the interrupt domain
  157. * @common: point to data shared by all irqchips
  158. * @chip: low level interrupt hardware access
  159. * @domain: Interrupt translation domain; responsible for mapping
  160. * between hwirq number and linux irq number.
  161. * @parent_data: pointer to parent struct irq_data to support hierarchy
  162. * irq_domain
  163. * @chip_data: platform-specific per-chip private data for the chip
  164. * methods, to allow shared chip implementations
  165. */
  166. struct irq_data {
  167. u32 mask;
  168. unsigned int irq;
  169. unsigned long hwirq;
  170. struct irq_common_data *common;
  171. struct irq_chip *chip;
  172. struct irq_domain *domain;
  173. #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
  174. struct irq_data *parent_data;
  175. #endif
  176. void *chip_data;
  177. };
  178. /*
  179. * Bit masks for irq_common_data.state_use_accessors
  180. *
  181. * IRQD_TRIGGER_MASK - Mask for the trigger type bits
  182. * IRQD_SETAFFINITY_PENDING - Affinity setting is pending
  183. * IRQD_ACTIVATED - Interrupt has already been activated
  184. * IRQD_NO_BALANCING - Balancing disabled for this IRQ
  185. * IRQD_PER_CPU - Interrupt is per cpu
  186. * IRQD_AFFINITY_SET - Interrupt affinity was set
  187. * IRQD_LEVEL - Interrupt is level triggered
  188. * IRQD_WAKEUP_STATE - Interrupt is configured for wakeup
  189. * from suspend
  190. * IRQD_MOVE_PCNTXT - Interrupt can be moved in process
  191. * context
  192. * IRQD_IRQ_DISABLED - Disabled state of the interrupt
  193. * IRQD_IRQ_MASKED - Masked state of the interrupt
  194. * IRQD_IRQ_INPROGRESS - In progress state of the interrupt
  195. * IRQD_WAKEUP_ARMED - Wakeup mode armed
  196. * IRQD_FORWARDED_TO_VCPU - The interrupt is forwarded to a VCPU
  197. * IRQD_AFFINITY_MANAGED - Affinity is auto-managed by the kernel
  198. * IRQD_IRQ_STARTED - Startup state of the interrupt
  199. * IRQD_MANAGED_SHUTDOWN - Interrupt was shutdown due to empty affinity
  200. * mask. Applies only to affinity managed irqs.
  201. * IRQD_SINGLE_TARGET - IRQ allows only a single affinity target
  202. * IRQD_DEFAULT_TRIGGER_SET - Expected trigger already been set
  203. * IRQD_CAN_RESERVE - Can use reservation mode
  204. * IRQD_HANDLE_ENFORCE_IRQCTX - Enforce that handle_irq_*() is only invoked
  205. * from actual interrupt context.
  206. * IRQD_AFFINITY_ON_ACTIVATE - Affinity is set on activation. Don't call
  207. * irq_chip::irq_set_affinity() when deactivated.
  208. * IRQD_IRQ_ENABLED_ON_SUSPEND - Interrupt is enabled on suspend by irq pm if
  209. * irqchip have flag IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND set.
  210. */
  211. enum {
  212. IRQD_TRIGGER_MASK = 0xf,
  213. IRQD_SETAFFINITY_PENDING = (1 << 8),
  214. IRQD_ACTIVATED = (1 << 9),
  215. IRQD_NO_BALANCING = (1 << 10),
  216. IRQD_PER_CPU = (1 << 11),
  217. IRQD_AFFINITY_SET = (1 << 12),
  218. IRQD_LEVEL = (1 << 13),
  219. IRQD_WAKEUP_STATE = (1 << 14),
  220. IRQD_MOVE_PCNTXT = (1 << 15),
  221. IRQD_IRQ_DISABLED = (1 << 16),
  222. IRQD_IRQ_MASKED = (1 << 17),
  223. IRQD_IRQ_INPROGRESS = (1 << 18),
  224. IRQD_WAKEUP_ARMED = (1 << 19),
  225. IRQD_FORWARDED_TO_VCPU = (1 << 20),
  226. IRQD_AFFINITY_MANAGED = (1 << 21),
  227. IRQD_IRQ_STARTED = (1 << 22),
  228. IRQD_MANAGED_SHUTDOWN = (1 << 23),
  229. IRQD_SINGLE_TARGET = (1 << 24),
  230. IRQD_DEFAULT_TRIGGER_SET = (1 << 25),
  231. IRQD_CAN_RESERVE = (1 << 26),
  232. IRQD_HANDLE_ENFORCE_IRQCTX = (1 << 27),
  233. IRQD_AFFINITY_ON_ACTIVATE = (1 << 28),
  234. IRQD_IRQ_ENABLED_ON_SUSPEND = (1 << 29),
  235. };
  236. #define __irqd_to_state(d) ACCESS_PRIVATE((d)->common, state_use_accessors)
  237. static inline bool irqd_is_setaffinity_pending(struct irq_data *d)
  238. {
  239. return __irqd_to_state(d) & IRQD_SETAFFINITY_PENDING;
  240. }
  241. static inline bool irqd_is_per_cpu(struct irq_data *d)
  242. {
  243. return __irqd_to_state(d) & IRQD_PER_CPU;
  244. }
  245. static inline bool irqd_can_balance(struct irq_data *d)
  246. {
  247. return !(__irqd_to_state(d) & (IRQD_PER_CPU | IRQD_NO_BALANCING));
  248. }
  249. static inline bool irqd_affinity_was_set(struct irq_data *d)
  250. {
  251. return __irqd_to_state(d) & IRQD_AFFINITY_SET;
  252. }
  253. static inline void irqd_mark_affinity_was_set(struct irq_data *d)
  254. {
  255. __irqd_to_state(d) |= IRQD_AFFINITY_SET;
  256. }
  257. static inline bool irqd_trigger_type_was_set(struct irq_data *d)
  258. {
  259. return __irqd_to_state(d) & IRQD_DEFAULT_TRIGGER_SET;
  260. }
  261. static inline u32 irqd_get_trigger_type(struct irq_data *d)
  262. {
  263. return __irqd_to_state(d) & IRQD_TRIGGER_MASK;
  264. }
  265. /*
  266. * Must only be called inside irq_chip.irq_set_type() functions or
  267. * from the DT/ACPI setup code.
  268. */
  269. static inline void irqd_set_trigger_type(struct irq_data *d, u32 type)
  270. {
  271. __irqd_to_state(d) &= ~IRQD_TRIGGER_MASK;
  272. __irqd_to_state(d) |= type & IRQD_TRIGGER_MASK;
  273. __irqd_to_state(d) |= IRQD_DEFAULT_TRIGGER_SET;
  274. }
  275. static inline bool irqd_is_level_type(struct irq_data *d)
  276. {
  277. return __irqd_to_state(d) & IRQD_LEVEL;
  278. }
  279. /*
  280. * Must only be called of irqchip.irq_set_affinity() or low level
  281. * hierarchy domain allocation functions.
  282. */
  283. static inline void irqd_set_single_target(struct irq_data *d)
  284. {
  285. __irqd_to_state(d) |= IRQD_SINGLE_TARGET;
  286. }
  287. static inline bool irqd_is_single_target(struct irq_data *d)
  288. {
  289. return __irqd_to_state(d) & IRQD_SINGLE_TARGET;
  290. }
  291. static inline void irqd_set_handle_enforce_irqctx(struct irq_data *d)
  292. {
  293. __irqd_to_state(d) |= IRQD_HANDLE_ENFORCE_IRQCTX;
  294. }
  295. static inline bool irqd_is_handle_enforce_irqctx(struct irq_data *d)
  296. {
  297. return __irqd_to_state(d) & IRQD_HANDLE_ENFORCE_IRQCTX;
  298. }
  299. static inline bool irqd_is_enabled_on_suspend(struct irq_data *d)
  300. {
  301. return __irqd_to_state(d) & IRQD_IRQ_ENABLED_ON_SUSPEND;
  302. }
  303. static inline bool irqd_is_wakeup_set(struct irq_data *d)
  304. {
  305. return __irqd_to_state(d) & IRQD_WAKEUP_STATE;
  306. }
  307. static inline bool irqd_can_move_in_process_context(struct irq_data *d)
  308. {
  309. return __irqd_to_state(d) & IRQD_MOVE_PCNTXT;
  310. }
  311. static inline bool irqd_irq_disabled(struct irq_data *d)
  312. {
  313. return __irqd_to_state(d) & IRQD_IRQ_DISABLED;
  314. }
  315. static inline bool irqd_irq_masked(struct irq_data *d)
  316. {
  317. return __irqd_to_state(d) & IRQD_IRQ_MASKED;
  318. }
  319. static inline bool irqd_irq_inprogress(struct irq_data *d)
  320. {
  321. return __irqd_to_state(d) & IRQD_IRQ_INPROGRESS;
  322. }
  323. static inline bool irqd_is_wakeup_armed(struct irq_data *d)
  324. {
  325. return __irqd_to_state(d) & IRQD_WAKEUP_ARMED;
  326. }
  327. static inline bool irqd_is_forwarded_to_vcpu(struct irq_data *d)
  328. {
  329. return __irqd_to_state(d) & IRQD_FORWARDED_TO_VCPU;
  330. }
  331. static inline void irqd_set_forwarded_to_vcpu(struct irq_data *d)
  332. {
  333. __irqd_to_state(d) |= IRQD_FORWARDED_TO_VCPU;
  334. }
  335. static inline void irqd_clr_forwarded_to_vcpu(struct irq_data *d)
  336. {
  337. __irqd_to_state(d) &= ~IRQD_FORWARDED_TO_VCPU;
  338. }
  339. static inline bool irqd_affinity_is_managed(struct irq_data *d)
  340. {
  341. return __irqd_to_state(d) & IRQD_AFFINITY_MANAGED;
  342. }
  343. static inline bool irqd_is_activated(struct irq_data *d)
  344. {
  345. return __irqd_to_state(d) & IRQD_ACTIVATED;
  346. }
  347. static inline void irqd_set_activated(struct irq_data *d)
  348. {
  349. __irqd_to_state(d) |= IRQD_ACTIVATED;
  350. }
  351. static inline void irqd_clr_activated(struct irq_data *d)
  352. {
  353. __irqd_to_state(d) &= ~IRQD_ACTIVATED;
  354. }
  355. static inline bool irqd_is_started(struct irq_data *d)
  356. {
  357. return __irqd_to_state(d) & IRQD_IRQ_STARTED;
  358. }
  359. static inline bool irqd_is_managed_and_shutdown(struct irq_data *d)
  360. {
  361. return __irqd_to_state(d) & IRQD_MANAGED_SHUTDOWN;
  362. }
  363. static inline void irqd_set_can_reserve(struct irq_data *d)
  364. {
  365. __irqd_to_state(d) |= IRQD_CAN_RESERVE;
  366. }
  367. static inline void irqd_clr_can_reserve(struct irq_data *d)
  368. {
  369. __irqd_to_state(d) &= ~IRQD_CAN_RESERVE;
  370. }
  371. static inline bool irqd_can_reserve(struct irq_data *d)
  372. {
  373. return __irqd_to_state(d) & IRQD_CAN_RESERVE;
  374. }
  375. static inline void irqd_set_affinity_on_activate(struct irq_data *d)
  376. {
  377. __irqd_to_state(d) |= IRQD_AFFINITY_ON_ACTIVATE;
  378. }
  379. static inline bool irqd_affinity_on_activate(struct irq_data *d)
  380. {
  381. return __irqd_to_state(d) & IRQD_AFFINITY_ON_ACTIVATE;
  382. }
  383. #undef __irqd_to_state
  384. static inline irq_hw_number_t irqd_to_hwirq(struct irq_data *d)
  385. {
  386. return d->hwirq;
  387. }
  388. /**
  389. * struct irq_chip - hardware interrupt chip descriptor
  390. *
  391. * @name: name for /proc/interrupts
  392. * @irq_startup: start up the interrupt (defaults to ->enable if NULL)
  393. * @irq_shutdown: shut down the interrupt (defaults to ->disable if NULL)
  394. * @irq_enable: enable the interrupt (defaults to chip->unmask if NULL)
  395. * @irq_disable: disable the interrupt
  396. * @irq_ack: start of a new interrupt
  397. * @irq_mask: mask an interrupt source
  398. * @irq_mask_ack: ack and mask an interrupt source
  399. * @irq_unmask: unmask an interrupt source
  400. * @irq_eoi: end of interrupt
  401. * @irq_set_affinity: Set the CPU affinity on SMP machines. If the force
  402. * argument is true, it tells the driver to
  403. * unconditionally apply the affinity setting. Sanity
  404. * checks against the supplied affinity mask are not
  405. * required. This is used for CPU hotplug where the
  406. * target CPU is not yet set in the cpu_online_mask.
  407. * @irq_retrigger: resend an IRQ to the CPU
  408. * @irq_set_type: set the flow type (IRQ_TYPE_LEVEL/etc.) of an IRQ
  409. * @irq_set_wake: enable/disable power-management wake-on of an IRQ
  410. * @irq_bus_lock: function to lock access to slow bus (i2c) chips
  411. * @irq_bus_sync_unlock:function to sync and unlock slow bus (i2c) chips
  412. * @irq_cpu_online: configure an interrupt source for a secondary CPU
  413. * @irq_cpu_offline: un-configure an interrupt source for a secondary CPU
  414. * @irq_suspend: function called from core code on suspend once per
  415. * chip, when one or more interrupts are installed
  416. * @irq_resume: function called from core code on resume once per chip,
  417. * when one ore more interrupts are installed
  418. * @irq_pm_shutdown: function called from core code on shutdown once per chip
  419. * @irq_calc_mask: Optional function to set irq_data.mask for special cases
  420. * @irq_print_chip: optional to print special chip info in show_interrupts
  421. * @irq_request_resources: optional to request resources before calling
  422. * any other callback related to this irq
  423. * @irq_release_resources: optional to release resources acquired with
  424. * irq_request_resources
  425. * @irq_compose_msi_msg: optional to compose message content for MSI
  426. * @irq_write_msi_msg: optional to write message content for MSI
  427. * @irq_get_irqchip_state: return the internal state of an interrupt
  428. * @irq_set_irqchip_state: set the internal state of a interrupt
  429. * @irq_set_vcpu_affinity: optional to target a vCPU in a virtual machine
  430. * @ipi_send_single: send a single IPI to destination cpus
  431. * @ipi_send_mask: send an IPI to destination cpus in cpumask
  432. * @irq_nmi_setup: function called from core code before enabling an NMI
  433. * @irq_nmi_teardown: function called from core code after disabling an NMI
  434. * @flags: chip specific flags
  435. */
  436. struct irq_chip {
  437. const char *name;
  438. unsigned int (*irq_startup)(struct irq_data *data);
  439. void (*irq_shutdown)(struct irq_data *data);
  440. void (*irq_enable)(struct irq_data *data);
  441. void (*irq_disable)(struct irq_data *data);
  442. void (*irq_ack)(struct irq_data *data);
  443. void (*irq_mask)(struct irq_data *data);
  444. void (*irq_mask_ack)(struct irq_data *data);
  445. void (*irq_unmask)(struct irq_data *data);
  446. void (*irq_eoi)(struct irq_data *data);
  447. int (*irq_set_affinity)(struct irq_data *data, const struct cpumask *dest, bool force);
  448. int (*irq_retrigger)(struct irq_data *data);
  449. int (*irq_set_type)(struct irq_data *data, unsigned int flow_type);
  450. int (*irq_set_wake)(struct irq_data *data, unsigned int on);
  451. void (*irq_bus_lock)(struct irq_data *data);
  452. void (*irq_bus_sync_unlock)(struct irq_data *data);
  453. #ifdef CONFIG_DEPRECATED_IRQ_CPU_ONOFFLINE
  454. void (*irq_cpu_online)(struct irq_data *data);
  455. void (*irq_cpu_offline)(struct irq_data *data);
  456. #endif
  457. void (*irq_suspend)(struct irq_data *data);
  458. void (*irq_resume)(struct irq_data *data);
  459. void (*irq_pm_shutdown)(struct irq_data *data);
  460. void (*irq_calc_mask)(struct irq_data *data);
  461. void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
  462. int (*irq_request_resources)(struct irq_data *data);
  463. void (*irq_release_resources)(struct irq_data *data);
  464. void (*irq_compose_msi_msg)(struct irq_data *data, struct msi_msg *msg);
  465. void (*irq_write_msi_msg)(struct irq_data *data, struct msi_msg *msg);
  466. int (*irq_get_irqchip_state)(struct irq_data *data, enum irqchip_irq_state which, bool *state);
  467. int (*irq_set_irqchip_state)(struct irq_data *data, enum irqchip_irq_state which, bool state);
  468. int (*irq_set_vcpu_affinity)(struct irq_data *data, void *vcpu_info);
  469. void (*ipi_send_single)(struct irq_data *data, unsigned int cpu);
  470. void (*ipi_send_mask)(struct irq_data *data, const struct cpumask *dest);
  471. int (*irq_nmi_setup)(struct irq_data *data);
  472. void (*irq_nmi_teardown)(struct irq_data *data);
  473. unsigned long flags;
  474. };
  475. /*
  476. * irq_chip specific flags
  477. *
  478. * IRQCHIP_SET_TYPE_MASKED: Mask before calling chip.irq_set_type()
  479. * IRQCHIP_EOI_IF_HANDLED: Only issue irq_eoi() when irq was handled
  480. * IRQCHIP_MASK_ON_SUSPEND: Mask non wake irqs in the suspend path
  481. * IRQCHIP_ONOFFLINE_ENABLED: Only call irq_on/off_line callbacks
  482. * when irq enabled
  483. * IRQCHIP_SKIP_SET_WAKE: Skip chip.irq_set_wake(), for this irq chip
  484. * IRQCHIP_ONESHOT_SAFE: One shot does not require mask/unmask
  485. * IRQCHIP_EOI_THREADED: Chip requires eoi() on unmask in threaded mode
  486. * IRQCHIP_SUPPORTS_LEVEL_MSI: Chip can provide two doorbells for Level MSIs
  487. * IRQCHIP_SUPPORTS_NMI: Chip can deliver NMIs, only for root irqchips
  488. * IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND: Invokes __enable_irq()/__disable_irq() for wake irqs
  489. * in the suspend path if they are in disabled state
  490. * IRQCHIP_AFFINITY_PRE_STARTUP: Default affinity update before startup
  491. * IRQCHIP_IMMUTABLE: Don't ever change anything in this chip
  492. */
  493. enum {
  494. IRQCHIP_SET_TYPE_MASKED = (1 << 0),
  495. IRQCHIP_EOI_IF_HANDLED = (1 << 1),
  496. IRQCHIP_MASK_ON_SUSPEND = (1 << 2),
  497. IRQCHIP_ONOFFLINE_ENABLED = (1 << 3),
  498. IRQCHIP_SKIP_SET_WAKE = (1 << 4),
  499. IRQCHIP_ONESHOT_SAFE = (1 << 5),
  500. IRQCHIP_EOI_THREADED = (1 << 6),
  501. IRQCHIP_SUPPORTS_LEVEL_MSI = (1 << 7),
  502. IRQCHIP_SUPPORTS_NMI = (1 << 8),
  503. IRQCHIP_ENABLE_WAKEUP_ON_SUSPEND = (1 << 9),
  504. IRQCHIP_AFFINITY_PRE_STARTUP = (1 << 10),
  505. IRQCHIP_IMMUTABLE = (1 << 11),
  506. };
  507. #include <linux/irqdesc.h>
  508. /*
  509. * Pick up the arch-dependent methods:
  510. */
  511. #include <asm/hw_irq.h>
  512. #ifndef NR_IRQS_LEGACY
  513. # define NR_IRQS_LEGACY 0
  514. #endif
  515. #ifndef ARCH_IRQ_INIT_FLAGS
  516. # define ARCH_IRQ_INIT_FLAGS 0
  517. #endif
  518. #define IRQ_DEFAULT_INIT_FLAGS ARCH_IRQ_INIT_FLAGS
  519. struct irqaction;
  520. extern int setup_percpu_irq(unsigned int irq, struct irqaction *new);
  521. extern void remove_percpu_irq(unsigned int irq, struct irqaction *act);
  522. #ifdef CONFIG_DEPRECATED_IRQ_CPU_ONOFFLINE
  523. extern void irq_cpu_online(void);
  524. extern void irq_cpu_offline(void);
  525. #endif
  526. extern int irq_set_affinity_locked(struct irq_data *data,
  527. const struct cpumask *cpumask, bool force);
  528. extern int irq_set_vcpu_affinity(unsigned int irq, void *vcpu_info);
  529. #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_IRQ_MIGRATION)
  530. extern void irq_migrate_all_off_this_cpu(void);
  531. extern int irq_affinity_online_cpu(unsigned int cpu);
  532. #else
  533. # define irq_affinity_online_cpu NULL
  534. #endif
  535. #if defined(CONFIG_SMP) && defined(CONFIG_GENERIC_PENDING_IRQ)
  536. void __irq_move_irq(struct irq_data *data);
  537. static inline void irq_move_irq(struct irq_data *data)
  538. {
  539. if (unlikely(irqd_is_setaffinity_pending(data)))
  540. __irq_move_irq(data);
  541. }
  542. void irq_move_masked_irq(struct irq_data *data);
  543. void irq_force_complete_move(struct irq_desc *desc);
  544. #else
  545. static inline void irq_move_irq(struct irq_data *data) { }
  546. static inline void irq_move_masked_irq(struct irq_data *data) { }
  547. static inline void irq_force_complete_move(struct irq_desc *desc) { }
  548. #endif
  549. extern int no_irq_affinity;
  550. #ifdef CONFIG_HARDIRQS_SW_RESEND
  551. int irq_set_parent(int irq, int parent_irq);
  552. #else
  553. static inline int irq_set_parent(int irq, int parent_irq)
  554. {
  555. return 0;
  556. }
  557. #endif
  558. /*
  559. * Built-in IRQ handlers for various IRQ types,
  560. * callable via desc->handle_irq()
  561. */
  562. extern void handle_level_irq(struct irq_desc *desc);
  563. extern void handle_fasteoi_irq(struct irq_desc *desc);
  564. extern void handle_edge_irq(struct irq_desc *desc);
  565. extern void handle_edge_eoi_irq(struct irq_desc *desc);
  566. extern void handle_simple_irq(struct irq_desc *desc);
  567. extern void handle_untracked_irq(struct irq_desc *desc);
  568. extern void handle_percpu_irq(struct irq_desc *desc);
  569. extern void handle_percpu_devid_irq(struct irq_desc *desc);
  570. extern void handle_bad_irq(struct irq_desc *desc);
  571. extern void handle_nested_irq(unsigned int irq);
  572. extern void handle_fasteoi_nmi(struct irq_desc *desc);
  573. extern void handle_percpu_devid_fasteoi_nmi(struct irq_desc *desc);
  574. extern int irq_chip_compose_msi_msg(struct irq_data *data, struct msi_msg *msg);
  575. extern int irq_chip_pm_get(struct irq_data *data);
  576. extern int irq_chip_pm_put(struct irq_data *data);
  577. #ifdef CONFIG_IRQ_DOMAIN_HIERARCHY
  578. extern void handle_fasteoi_ack_irq(struct irq_desc *desc);
  579. extern void handle_fasteoi_mask_irq(struct irq_desc *desc);
  580. extern int irq_chip_set_parent_state(struct irq_data *data,
  581. enum irqchip_irq_state which,
  582. bool val);
  583. extern int irq_chip_get_parent_state(struct irq_data *data,
  584. enum irqchip_irq_state which,
  585. bool *state);
  586. extern void irq_chip_enable_parent(struct irq_data *data);
  587. extern void irq_chip_disable_parent(struct irq_data *data);
  588. extern void irq_chip_ack_parent(struct irq_data *data);
  589. extern int irq_chip_retrigger_hierarchy(struct irq_data *data);
  590. extern void irq_chip_mask_parent(struct irq_data *data);
  591. extern void irq_chip_mask_ack_parent(struct irq_data *data);
  592. extern void irq_chip_unmask_parent(struct irq_data *data);
  593. extern void irq_chip_eoi_parent(struct irq_data *data);
  594. extern int irq_chip_set_affinity_parent(struct irq_data *data,
  595. const struct cpumask *dest,
  596. bool force);
  597. extern int irq_chip_set_wake_parent(struct irq_data *data, unsigned int on);
  598. extern int irq_chip_set_vcpu_affinity_parent(struct irq_data *data,
  599. void *vcpu_info);
  600. extern int irq_chip_set_type_parent(struct irq_data *data, unsigned int type);
  601. extern int irq_chip_request_resources_parent(struct irq_data *data);
  602. extern void irq_chip_release_resources_parent(struct irq_data *data);
  603. #endif
  604. /* Handling of unhandled and spurious interrupts: */
  605. extern void note_interrupt(struct irq_desc *desc, irqreturn_t action_ret);
  606. /* Enable/disable irq debugging output: */
  607. extern int noirqdebug_setup(char *str);
  608. /* Checks whether the interrupt can be requested by request_irq(): */
  609. extern int can_request_irq(unsigned int irq, unsigned long irqflags);
  610. /* Dummy irq-chip implementations: */
  611. extern struct irq_chip no_irq_chip;
  612. extern struct irq_chip dummy_irq_chip;
  613. extern void
  614. irq_set_chip_and_handler_name(unsigned int irq, const struct irq_chip *chip,
  615. irq_flow_handler_t handle, const char *name);
  616. static inline void irq_set_chip_and_handler(unsigned int irq,
  617. const struct irq_chip *chip,
  618. irq_flow_handler_t handle)
  619. {
  620. irq_set_chip_and_handler_name(irq, chip, handle, NULL);
  621. }
  622. extern int irq_set_percpu_devid(unsigned int irq);
  623. extern int irq_set_percpu_devid_partition(unsigned int irq,
  624. const struct cpumask *affinity);
  625. extern int irq_get_percpu_devid_partition(unsigned int irq,
  626. struct cpumask *affinity);
  627. extern void
  628. __irq_set_handler(unsigned int irq, irq_flow_handler_t handle, int is_chained,
  629. const char *name);
  630. static inline void
  631. irq_set_handler(unsigned int irq, irq_flow_handler_t handle)
  632. {
  633. __irq_set_handler(irq, handle, 0, NULL);
  634. }
  635. /*
  636. * Set a highlevel chained flow handler for a given IRQ.
  637. * (a chained handler is automatically enabled and set to
  638. * IRQ_NOREQUEST, IRQ_NOPROBE, and IRQ_NOTHREAD)
  639. */
  640. static inline void
  641. irq_set_chained_handler(unsigned int irq, irq_flow_handler_t handle)
  642. {
  643. __irq_set_handler(irq, handle, 1, NULL);
  644. }
  645. /*
  646. * Set a highlevel chained flow handler and its data for a given IRQ.
  647. * (a chained handler is automatically enabled and set to
  648. * IRQ_NOREQUEST, IRQ_NOPROBE, and IRQ_NOTHREAD)
  649. */
  650. void
  651. irq_set_chained_handler_and_data(unsigned int irq, irq_flow_handler_t handle,
  652. void *data);
  653. void irq_modify_status(unsigned int irq, unsigned long clr, unsigned long set);
  654. static inline void irq_set_status_flags(unsigned int irq, unsigned long set)
  655. {
  656. irq_modify_status(irq, 0, set);
  657. }
  658. static inline void irq_clear_status_flags(unsigned int irq, unsigned long clr)
  659. {
  660. irq_modify_status(irq, clr, 0);
  661. }
  662. static inline void irq_set_noprobe(unsigned int irq)
  663. {
  664. irq_modify_status(irq, 0, IRQ_NOPROBE);
  665. }
  666. static inline void irq_set_probe(unsigned int irq)
  667. {
  668. irq_modify_status(irq, IRQ_NOPROBE, 0);
  669. }
  670. static inline void irq_set_nothread(unsigned int irq)
  671. {
  672. irq_modify_status(irq, 0, IRQ_NOTHREAD);
  673. }
  674. static inline void irq_set_thread(unsigned int irq)
  675. {
  676. irq_modify_status(irq, IRQ_NOTHREAD, 0);
  677. }
  678. static inline void irq_set_nested_thread(unsigned int irq, bool nest)
  679. {
  680. if (nest)
  681. irq_set_status_flags(irq, IRQ_NESTED_THREAD);
  682. else
  683. irq_clear_status_flags(irq, IRQ_NESTED_THREAD);
  684. }
  685. static inline void irq_set_percpu_devid_flags(unsigned int irq)
  686. {
  687. irq_set_status_flags(irq,
  688. IRQ_NOAUTOEN | IRQ_PER_CPU | IRQ_NOTHREAD |
  689. IRQ_NOPROBE | IRQ_PER_CPU_DEVID);
  690. }
  691. /* Set/get chip/data for an IRQ: */
  692. extern int irq_set_chip(unsigned int irq, const struct irq_chip *chip);
  693. extern int irq_set_handler_data(unsigned int irq, void *data);
  694. extern int irq_set_chip_data(unsigned int irq, void *data);
  695. extern int irq_set_irq_type(unsigned int irq, unsigned int type);
  696. extern int irq_set_msi_desc(unsigned int irq, struct msi_desc *entry);
  697. extern int irq_set_msi_desc_off(unsigned int irq_base, unsigned int irq_offset,
  698. struct msi_desc *entry);
  699. extern struct irq_data *irq_get_irq_data(unsigned int irq);
  700. static inline struct irq_chip *irq_get_chip(unsigned int irq)
  701. {
  702. struct irq_data *d = irq_get_irq_data(irq);
  703. return d ? d->chip : NULL;
  704. }
  705. static inline struct irq_chip *irq_data_get_irq_chip(struct irq_data *d)
  706. {
  707. return d->chip;
  708. }
  709. static inline void *irq_get_chip_data(unsigned int irq)
  710. {
  711. struct irq_data *d = irq_get_irq_data(irq);
  712. return d ? d->chip_data : NULL;
  713. }
  714. static inline void *irq_data_get_irq_chip_data(struct irq_data *d)
  715. {
  716. return d->chip_data;
  717. }
  718. static inline void *irq_get_handler_data(unsigned int irq)
  719. {
  720. struct irq_data *d = irq_get_irq_data(irq);
  721. return d ? d->common->handler_data : NULL;
  722. }
  723. static inline void *irq_data_get_irq_handler_data(struct irq_data *d)
  724. {
  725. return d->common->handler_data;
  726. }
  727. static inline struct msi_desc *irq_get_msi_desc(unsigned int irq)
  728. {
  729. struct irq_data *d = irq_get_irq_data(irq);
  730. return d ? d->common->msi_desc : NULL;
  731. }
  732. static inline struct msi_desc *irq_data_get_msi_desc(struct irq_data *d)
  733. {
  734. return d->common->msi_desc;
  735. }
  736. static inline u32 irq_get_trigger_type(unsigned int irq)
  737. {
  738. struct irq_data *d = irq_get_irq_data(irq);
  739. return d ? irqd_get_trigger_type(d) : 0;
  740. }
  741. static inline int irq_common_data_get_node(struct irq_common_data *d)
  742. {
  743. #ifdef CONFIG_NUMA
  744. return d->node;
  745. #else
  746. return 0;
  747. #endif
  748. }
  749. static inline int irq_data_get_node(struct irq_data *d)
  750. {
  751. return irq_common_data_get_node(d->common);
  752. }
  753. static inline
  754. const struct cpumask *irq_data_get_affinity_mask(struct irq_data *d)
  755. {
  756. #ifdef CONFIG_SMP
  757. return d->common->affinity;
  758. #else
  759. return cpumask_of(0);
  760. #endif
  761. }
  762. static inline void irq_data_update_affinity(struct irq_data *d,
  763. const struct cpumask *m)
  764. {
  765. #ifdef CONFIG_SMP
  766. cpumask_copy(d->common->affinity, m);
  767. #endif
  768. }
  769. static inline const struct cpumask *irq_get_affinity_mask(int irq)
  770. {
  771. struct irq_data *d = irq_get_irq_data(irq);
  772. return d ? irq_data_get_affinity_mask(d) : NULL;
  773. }
  774. #ifdef CONFIG_GENERIC_IRQ_EFFECTIVE_AFF_MASK
  775. static inline
  776. const struct cpumask *irq_data_get_effective_affinity_mask(struct irq_data *d)
  777. {
  778. return d->common->effective_affinity;
  779. }
  780. static inline void irq_data_update_effective_affinity(struct irq_data *d,
  781. const struct cpumask *m)
  782. {
  783. cpumask_copy(d->common->effective_affinity, m);
  784. }
  785. #else
  786. static inline void irq_data_update_effective_affinity(struct irq_data *d,
  787. const struct cpumask *m)
  788. {
  789. }
  790. static inline
  791. const struct cpumask *irq_data_get_effective_affinity_mask(struct irq_data *d)
  792. {
  793. return irq_data_get_affinity_mask(d);
  794. }
  795. #endif
  796. static inline
  797. const struct cpumask *irq_get_effective_affinity_mask(unsigned int irq)
  798. {
  799. struct irq_data *d = irq_get_irq_data(irq);
  800. return d ? irq_data_get_effective_affinity_mask(d) : NULL;
  801. }
  802. unsigned int arch_dynirq_lower_bound(unsigned int from);
  803. int __irq_alloc_descs(int irq, unsigned int from, unsigned int cnt, int node,
  804. struct module *owner,
  805. const struct irq_affinity_desc *affinity);
  806. int __devm_irq_alloc_descs(struct device *dev, int irq, unsigned int from,
  807. unsigned int cnt, int node, struct module *owner,
  808. const struct irq_affinity_desc *affinity);
  809. /* use macros to avoid needing export.h for THIS_MODULE */
  810. #define irq_alloc_descs(irq, from, cnt, node) \
  811. __irq_alloc_descs(irq, from, cnt, node, THIS_MODULE, NULL)
  812. #define irq_alloc_desc(node) \
  813. irq_alloc_descs(-1, 1, 1, node)
  814. #define irq_alloc_desc_at(at, node) \
  815. irq_alloc_descs(at, at, 1, node)
  816. #define irq_alloc_desc_from(from, node) \
  817. irq_alloc_descs(-1, from, 1, node)
  818. #define irq_alloc_descs_from(from, cnt, node) \
  819. irq_alloc_descs(-1, from, cnt, node)
  820. #define devm_irq_alloc_descs(dev, irq, from, cnt, node) \
  821. __devm_irq_alloc_descs(dev, irq, from, cnt, node, THIS_MODULE, NULL)
  822. #define devm_irq_alloc_desc(dev, node) \
  823. devm_irq_alloc_descs(dev, -1, 1, 1, node)
  824. #define devm_irq_alloc_desc_at(dev, at, node) \
  825. devm_irq_alloc_descs(dev, at, at, 1, node)
  826. #define devm_irq_alloc_desc_from(dev, from, node) \
  827. devm_irq_alloc_descs(dev, -1, from, 1, node)
  828. #define devm_irq_alloc_descs_from(dev, from, cnt, node) \
  829. devm_irq_alloc_descs(dev, -1, from, cnt, node)
  830. void irq_free_descs(unsigned int irq, unsigned int cnt);
  831. static inline void irq_free_desc(unsigned int irq)
  832. {
  833. irq_free_descs(irq, 1);
  834. }
  835. #ifdef CONFIG_GENERIC_IRQ_LEGACY
  836. void irq_init_desc(unsigned int irq);
  837. #endif
  838. /**
  839. * struct irq_chip_regs - register offsets for struct irq_gci
  840. * @enable: Enable register offset to reg_base
  841. * @disable: Disable register offset to reg_base
  842. * @mask: Mask register offset to reg_base
  843. * @ack: Ack register offset to reg_base
  844. * @eoi: Eoi register offset to reg_base
  845. * @type: Type configuration register offset to reg_base
  846. * @polarity: Polarity configuration register offset to reg_base
  847. */
  848. struct irq_chip_regs {
  849. unsigned long enable;
  850. unsigned long disable;
  851. unsigned long mask;
  852. unsigned long ack;
  853. unsigned long eoi;
  854. unsigned long type;
  855. unsigned long polarity;
  856. };
  857. /**
  858. * struct irq_chip_type - Generic interrupt chip instance for a flow type
  859. * @chip: The real interrupt chip which provides the callbacks
  860. * @regs: Register offsets for this chip
  861. * @handler: Flow handler associated with this chip
  862. * @type: Chip can handle these flow types
  863. * @mask_cache_priv: Cached mask register private to the chip type
  864. * @mask_cache: Pointer to cached mask register
  865. *
  866. * A irq_generic_chip can have several instances of irq_chip_type when
  867. * it requires different functions and register offsets for different
  868. * flow types.
  869. */
  870. struct irq_chip_type {
  871. struct irq_chip chip;
  872. struct irq_chip_regs regs;
  873. irq_flow_handler_t handler;
  874. u32 type;
  875. u32 mask_cache_priv;
  876. u32 *mask_cache;
  877. };
  878. /**
  879. * struct irq_chip_generic - Generic irq chip data structure
  880. * @lock: Lock to protect register and cache data access
  881. * @reg_base: Register base address (virtual)
  882. * @reg_readl: Alternate I/O accessor (defaults to readl if NULL)
  883. * @reg_writel: Alternate I/O accessor (defaults to writel if NULL)
  884. * @suspend: Function called from core code on suspend once per
  885. * chip; can be useful instead of irq_chip::suspend to
  886. * handle chip details even when no interrupts are in use
  887. * @resume: Function called from core code on resume once per chip;
  888. * can be useful instead of irq_chip::suspend to handle
  889. * chip details even when no interrupts are in use
  890. * @irq_base: Interrupt base nr for this chip
  891. * @irq_cnt: Number of interrupts handled by this chip
  892. * @mask_cache: Cached mask register shared between all chip types
  893. * @type_cache: Cached type register
  894. * @polarity_cache: Cached polarity register
  895. * @wake_enabled: Interrupt can wakeup from suspend
  896. * @wake_active: Interrupt is marked as an wakeup from suspend source
  897. * @num_ct: Number of available irq_chip_type instances (usually 1)
  898. * @private: Private data for non generic chip callbacks
  899. * @installed: bitfield to denote installed interrupts
  900. * @unused: bitfield to denote unused interrupts
  901. * @domain: irq domain pointer
  902. * @list: List head for keeping track of instances
  903. * @chip_types: Array of interrupt irq_chip_types
  904. *
  905. * Note, that irq_chip_generic can have multiple irq_chip_type
  906. * implementations which can be associated to a particular irq line of
  907. * an irq_chip_generic instance. That allows to share and protect
  908. * state in an irq_chip_generic instance when we need to implement
  909. * different flow mechanisms (level/edge) for it.
  910. */
  911. struct irq_chip_generic {
  912. raw_spinlock_t lock;
  913. void __iomem *reg_base;
  914. u32 (*reg_readl)(void __iomem *addr);
  915. void (*reg_writel)(u32 val, void __iomem *addr);
  916. void (*suspend)(struct irq_chip_generic *gc);
  917. void (*resume)(struct irq_chip_generic *gc);
  918. unsigned int irq_base;
  919. unsigned int irq_cnt;
  920. u32 mask_cache;
  921. u32 type_cache;
  922. u32 polarity_cache;
  923. u32 wake_enabled;
  924. u32 wake_active;
  925. unsigned int num_ct;
  926. void *private;
  927. unsigned long installed;
  928. unsigned long unused;
  929. struct irq_domain *domain;
  930. struct list_head list;
  931. struct irq_chip_type chip_types[];
  932. };
  933. /**
  934. * enum irq_gc_flags - Initialization flags for generic irq chips
  935. * @IRQ_GC_INIT_MASK_CACHE: Initialize the mask_cache by reading mask reg
  936. * @IRQ_GC_INIT_NESTED_LOCK: Set the lock class of the irqs to nested for
  937. * irq chips which need to call irq_set_wake() on
  938. * the parent irq. Usually GPIO implementations
  939. * @IRQ_GC_MASK_CACHE_PER_TYPE: Mask cache is chip type private
  940. * @IRQ_GC_NO_MASK: Do not calculate irq_data->mask
  941. * @IRQ_GC_BE_IO: Use big-endian register accesses (default: LE)
  942. */
  943. enum irq_gc_flags {
  944. IRQ_GC_INIT_MASK_CACHE = 1 << 0,
  945. IRQ_GC_INIT_NESTED_LOCK = 1 << 1,
  946. IRQ_GC_MASK_CACHE_PER_TYPE = 1 << 2,
  947. IRQ_GC_NO_MASK = 1 << 3,
  948. IRQ_GC_BE_IO = 1 << 4,
  949. };
  950. /*
  951. * struct irq_domain_chip_generic - Generic irq chip data structure for irq domains
  952. * @irqs_per_chip: Number of interrupts per chip
  953. * @num_chips: Number of chips
  954. * @irq_flags_to_set: IRQ* flags to set on irq setup
  955. * @irq_flags_to_clear: IRQ* flags to clear on irq setup
  956. * @gc_flags: Generic chip specific setup flags
  957. * @gc: Array of pointers to generic interrupt chips
  958. */
  959. struct irq_domain_chip_generic {
  960. unsigned int irqs_per_chip;
  961. unsigned int num_chips;
  962. unsigned int irq_flags_to_clear;
  963. unsigned int irq_flags_to_set;
  964. enum irq_gc_flags gc_flags;
  965. struct irq_chip_generic *gc[];
  966. };
  967. /* Generic chip callback functions */
  968. void irq_gc_noop(struct irq_data *d);
  969. void irq_gc_mask_disable_reg(struct irq_data *d);
  970. void irq_gc_mask_set_bit(struct irq_data *d);
  971. void irq_gc_mask_clr_bit(struct irq_data *d);
  972. void irq_gc_unmask_enable_reg(struct irq_data *d);
  973. void irq_gc_ack_set_bit(struct irq_data *d);
  974. void irq_gc_ack_clr_bit(struct irq_data *d);
  975. void irq_gc_mask_disable_and_ack_set(struct irq_data *d);
  976. void irq_gc_eoi(struct irq_data *d);
  977. int irq_gc_set_wake(struct irq_data *d, unsigned int on);
  978. /* Setup functions for irq_chip_generic */
  979. int irq_map_generic_chip(struct irq_domain *d, unsigned int virq,
  980. irq_hw_number_t hw_irq);
  981. void irq_unmap_generic_chip(struct irq_domain *d, unsigned int virq);
  982. struct irq_chip_generic *
  983. irq_alloc_generic_chip(const char *name, int nr_ct, unsigned int irq_base,
  984. void __iomem *reg_base, irq_flow_handler_t handler);
  985. void irq_setup_generic_chip(struct irq_chip_generic *gc, u32 msk,
  986. enum irq_gc_flags flags, unsigned int clr,
  987. unsigned int set);
  988. int irq_setup_alt_chip(struct irq_data *d, unsigned int type);
  989. void irq_remove_generic_chip(struct irq_chip_generic *gc, u32 msk,
  990. unsigned int clr, unsigned int set);
  991. struct irq_chip_generic *
  992. devm_irq_alloc_generic_chip(struct device *dev, const char *name, int num_ct,
  993. unsigned int irq_base, void __iomem *reg_base,
  994. irq_flow_handler_t handler);
  995. int devm_irq_setup_generic_chip(struct device *dev, struct irq_chip_generic *gc,
  996. u32 msk, enum irq_gc_flags flags,
  997. unsigned int clr, unsigned int set);
  998. struct irq_chip_generic *irq_get_domain_generic_chip(struct irq_domain *d, unsigned int hw_irq);
  999. int __irq_alloc_domain_generic_chips(struct irq_domain *d, int irqs_per_chip,
  1000. int num_ct, const char *name,
  1001. irq_flow_handler_t handler,
  1002. unsigned int clr, unsigned int set,
  1003. enum irq_gc_flags flags);
  1004. #define irq_alloc_domain_generic_chips(d, irqs_per_chip, num_ct, name, \
  1005. handler, clr, set, flags) \
  1006. ({ \
  1007. MAYBE_BUILD_BUG_ON(irqs_per_chip > 32); \
  1008. __irq_alloc_domain_generic_chips(d, irqs_per_chip, num_ct, name,\
  1009. handler, clr, set, flags); \
  1010. })
  1011. static inline void irq_free_generic_chip(struct irq_chip_generic *gc)
  1012. {
  1013. kfree(gc);
  1014. }
  1015. static inline void irq_destroy_generic_chip(struct irq_chip_generic *gc,
  1016. u32 msk, unsigned int clr,
  1017. unsigned int set)
  1018. {
  1019. irq_remove_generic_chip(gc, msk, clr, set);
  1020. irq_free_generic_chip(gc);
  1021. }
  1022. static inline struct irq_chip_type *irq_data_get_chip_type(struct irq_data *d)
  1023. {
  1024. return container_of(d->chip, struct irq_chip_type, chip);
  1025. }
  1026. #define IRQ_MSK(n) (u32)((n) < 32 ? ((1 << (n)) - 1) : UINT_MAX)
  1027. #ifdef CONFIG_SMP
  1028. static inline void irq_gc_lock(struct irq_chip_generic *gc)
  1029. {
  1030. raw_spin_lock(&gc->lock);
  1031. }
  1032. static inline void irq_gc_unlock(struct irq_chip_generic *gc)
  1033. {
  1034. raw_spin_unlock(&gc->lock);
  1035. }
  1036. #else
  1037. static inline void irq_gc_lock(struct irq_chip_generic *gc) { }
  1038. static inline void irq_gc_unlock(struct irq_chip_generic *gc) { }
  1039. #endif
  1040. /*
  1041. * The irqsave variants are for usage in non interrupt code. Do not use
  1042. * them in irq_chip callbacks. Use irq_gc_lock() instead.
  1043. */
  1044. #define irq_gc_lock_irqsave(gc, flags) \
  1045. raw_spin_lock_irqsave(&(gc)->lock, flags)
  1046. #define irq_gc_unlock_irqrestore(gc, flags) \
  1047. raw_spin_unlock_irqrestore(&(gc)->lock, flags)
  1048. static inline void irq_reg_writel(struct irq_chip_generic *gc,
  1049. u32 val, int reg_offset)
  1050. {
  1051. if (gc->reg_writel)
  1052. gc->reg_writel(val, gc->reg_base + reg_offset);
  1053. else
  1054. writel(val, gc->reg_base + reg_offset);
  1055. }
  1056. static inline u32 irq_reg_readl(struct irq_chip_generic *gc,
  1057. int reg_offset)
  1058. {
  1059. if (gc->reg_readl)
  1060. return gc->reg_readl(gc->reg_base + reg_offset);
  1061. else
  1062. return readl(gc->reg_base + reg_offset);
  1063. }
  1064. struct irq_matrix;
  1065. struct irq_matrix *irq_alloc_matrix(unsigned int matrix_bits,
  1066. unsigned int alloc_start,
  1067. unsigned int alloc_end);
  1068. void irq_matrix_online(struct irq_matrix *m);
  1069. void irq_matrix_offline(struct irq_matrix *m);
  1070. void irq_matrix_assign_system(struct irq_matrix *m, unsigned int bit, bool replace);
  1071. int irq_matrix_reserve_managed(struct irq_matrix *m, const struct cpumask *msk);
  1072. void irq_matrix_remove_managed(struct irq_matrix *m, const struct cpumask *msk);
  1073. int irq_matrix_alloc_managed(struct irq_matrix *m, const struct cpumask *msk,
  1074. unsigned int *mapped_cpu);
  1075. void irq_matrix_reserve(struct irq_matrix *m);
  1076. void irq_matrix_remove_reserved(struct irq_matrix *m);
  1077. int irq_matrix_alloc(struct irq_matrix *m, const struct cpumask *msk,
  1078. bool reserved, unsigned int *mapped_cpu);
  1079. void irq_matrix_free(struct irq_matrix *m, unsigned int cpu,
  1080. unsigned int bit, bool managed);
  1081. void irq_matrix_assign(struct irq_matrix *m, unsigned int bit);
  1082. unsigned int irq_matrix_available(struct irq_matrix *m, bool cpudown);
  1083. unsigned int irq_matrix_allocated(struct irq_matrix *m);
  1084. unsigned int irq_matrix_reserved(struct irq_matrix *m);
  1085. void irq_matrix_debug_show(struct seq_file *sf, struct irq_matrix *m, int ind);
  1086. /* Contrary to Linux irqs, for hardware irqs the irq number 0 is valid */
  1087. #define INVALID_HWIRQ (~0UL)
  1088. irq_hw_number_t ipi_get_hwirq(unsigned int irq, unsigned int cpu);
  1089. int __ipi_send_single(struct irq_desc *desc, unsigned int cpu);
  1090. int __ipi_send_mask(struct irq_desc *desc, const struct cpumask *dest);
  1091. int ipi_send_single(unsigned int virq, unsigned int cpu);
  1092. int ipi_send_mask(unsigned int virq, const struct cpumask *dest);
  1093. #ifdef CONFIG_GENERIC_IRQ_MULTI_HANDLER
  1094. /*
  1095. * Registers a generic IRQ handling function as the top-level IRQ handler in
  1096. * the system, which is generally the first C code called from an assembly
  1097. * architecture-specific interrupt handler.
  1098. *
  1099. * Returns 0 on success, or -EBUSY if an IRQ handler has already been
  1100. * registered.
  1101. */
  1102. int __init set_handle_irq(void (*handle_irq)(struct pt_regs *));
  1103. /*
  1104. * Allows interrupt handlers to find the irqchip that's been registered as the
  1105. * top-level IRQ handler.
  1106. */
  1107. extern void (*handle_arch_irq)(struct pt_regs *) __ro_after_init;
  1108. asmlinkage void generic_handle_arch_irq(struct pt_regs *regs);
  1109. #else
  1110. #ifndef set_handle_irq
  1111. #define set_handle_irq(handle_irq) \
  1112. do { \
  1113. (void)handle_irq; \
  1114. WARN_ON(1); \
  1115. } while (0)
  1116. #endif
  1117. #endif
  1118. #endif /* _LINUX_IRQ_H */