irq.h 38 KB

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