interrupt.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /* interrupt.h */
  3. #ifndef _LINUX_INTERRUPT_H
  4. #define _LINUX_INTERRUPT_H
  5. #include <stdio.h>
  6. #include <stdint.h>
  7. #include <stddef.h>
  8. #include <string.h>
  9. #include <stdbool.h>
  10. #define NR_CPUS 1
  11. #define NR_IRQS (207)
  12. #define BITS_PER_BYTE 8
  13. #define __KERNEL_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
  14. #define BITS_PER_TYPE(type) (sizeof(type) * BITS_PER_BYTE)
  15. //#define DIV_ROUND_UP __KERNEL_DIV_ROUND_UP
  16. #ifndef BITS_TO_LONGS
  17. #define BITS_TO_LONGS(nr) __KERNEL_DIV_ROUND_UP(nr, BITS_PER_TYPE(long))
  18. #endif
  19. #define DECLARE_BITMAP(name,bits) \
  20. unsigned long name[BITS_TO_LONGS(bits)]
  21. /* Don't assign or return these: may not be this big! */
  22. typedef struct cpumask
  23. {
  24. DECLARE_BITMAP(bits, NR_CPUS);
  25. } cpumask_t;
  26. /*
  27. * These correspond to the IORESOURCE_IRQ_* defines in
  28. * linux/ioport.h to select the interrupt line behaviour. When
  29. * requesting an interrupt without specifying a IRQF_TRIGGER, the
  30. * setting should be assumed to be "as already configured", which
  31. * may be as per machine or firmware initialisation.
  32. */
  33. #define IRQF_TRIGGER_NONE 0x00000000
  34. #define IRQF_TRIGGER_RISING 0x00000001
  35. #define IRQF_TRIGGER_FALLING 0x00000002
  36. #define IRQF_TRIGGER_HIGH 0x00000004
  37. #define IRQF_TRIGGER_LOW 0x00000008
  38. #define IRQF_TRIGGER_MASK (IRQF_TRIGGER_HIGH | IRQF_TRIGGER_LOW | \
  39. IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING)
  40. #define IRQF_TRIGGER_PROBE 0x00000010
  41. /*
  42. * These flags used only by the kernel as part of the
  43. * irq handling routines.
  44. *
  45. * IRQF_SHARED - allow sharing the irq among several devices
  46. * IRQF_PROBE_SHARED - set by callers when they expect sharing mismatches to occur
  47. * IRQF_TIMER - Flag to mark this interrupt as timer interrupt
  48. * IRQF_PERCPU - Interrupt is per cpu
  49. * IRQF_NOBALANCING - Flag to exclude this interrupt from irq balancing
  50. * IRQF_IRQPOLL - Interrupt is used for polling (only the interrupt that is
  51. * registered first in a shared interrupt is considered for
  52. * performance reasons)
  53. * IRQF_ONESHOT - Interrupt is not reenabled after the hardirq handler finished.
  54. * Used by threaded interrupts which need to keep the
  55. * irq line disabled until the threaded handler has been run.
  56. * IRQF_NO_SUSPEND - Do not disable this IRQ during suspend. Does not guarantee
  57. * that this interrupt will wake the system from a suspended
  58. * state. See Documentation/power/suspend-and-interrupts.rst
  59. * IRQF_FORCE_RESUME - Force enable it on resume even if IRQF_NO_SUSPEND is set
  60. * IRQF_NO_THREAD - Interrupt cannot be threaded
  61. * IRQF_EARLY_RESUME - Resume IRQ early during syscore instead of at device
  62. * resume time.
  63. * IRQF_COND_SUSPEND - If the IRQ is shared with a NO_SUSPEND user, execute this
  64. * interrupt handler after suspending interrupts. For system
  65. * wakeup devices users need to implement wakeup detection in
  66. * their interrupt handlers.
  67. */
  68. #define IRQF_SHARED 0x00000080
  69. #define IRQF_PROBE_SHARED 0x00000100
  70. #define __IRQF_TIMER 0x00000200
  71. #define IRQF_PERCPU 0x00000400
  72. #define IRQF_NOBALANCING 0x00000800
  73. #define IRQF_IRQPOLL 0x00001000
  74. #define IRQF_ONESHOT 0x00002000
  75. #define IRQF_NO_SUSPEND 0x00004000
  76. #define IRQF_FORCE_RESUME 0x00008000
  77. #define IRQF_NO_THREAD 0x00010000
  78. #define IRQF_EARLY_RESUME 0x00020000
  79. #define IRQF_COND_SUSPEND 0x00040000
  80. #define IRQF_TIMER (__IRQF_TIMER | IRQF_NO_SUSPEND | IRQF_NO_THREAD)
  81. #define __must_check __attribute__((__warn_unused_result__))
  82. /*
  83. * These values can be returned by request_any_context_irq() and
  84. * describe the context the interrupt will be run in.
  85. *
  86. * IRQC_IS_HARDIRQ - interrupt runs in hardirq context
  87. * IRQC_IS_NESTED - interrupt runs in a nested threaded context
  88. */
  89. enum
  90. {
  91. IRQC_IS_HARDIRQ = 0,
  92. IRQC_IS_NESTED,
  93. };
  94. /**
  95. * enum irqreturn
  96. * @IRQ_NONE interrupt was not from this device or was not handled
  97. * @IRQ_HANDLED interrupt was handled by this device
  98. * @IRQ_WAKE_THREAD handler requests to wake the handler thread
  99. */
  100. enum irqreturn
  101. {
  102. IRQ_NONE = (0 << 0),
  103. IRQ_HANDLED = (1 << 0),
  104. IRQ_WAKE_THREAD = (1 << 1),
  105. };
  106. #define IRQACTION_NAME_MAX 16
  107. typedef enum irqreturn irqreturn_t;
  108. #define IRQ_RETVAL(x) ((x) ? IRQ_HANDLED : IRQ_NONE)
  109. typedef irqreturn_t (*irq_handler_t)(int, void *);
  110. /**
  111. * struct irqaction - per interrupt action descriptor
  112. * @handler: interrupt handler function
  113. * @name: name of the device
  114. * @dev_id: cookie to identify the device
  115. * @percpu_dev_id: cookie to identify the device
  116. * @next: pointer to the next irqaction for shared interrupts
  117. * @irq: interrupt number
  118. * @flags: flags (see IRQF_* above)
  119. * @thread_fn: interrupt handler function for threaded interrupts
  120. * @thread: thread pointer for threaded interrupts
  121. * @secondary: pointer to secondary irqaction (force threading)
  122. * @thread_flags: flags related to @thread
  123. * @thread_mask: bitmask for keeping track of @thread activity
  124. * @dir: pointer to the proc/irq/NN/name entry
  125. */
  126. struct irqaction
  127. {
  128. irq_handler_t handler;
  129. void *dev_id;
  130. struct irqaction *next;
  131. struct irqaction *secondary;
  132. unsigned int irq;
  133. unsigned int flags;
  134. unsigned long thread_flags;
  135. unsigned long thread_mask;
  136. unsigned long irq_nums;
  137. const char name[IRQACTION_NAME_MAX];
  138. };
  139. extern irqreturn_t no_action(int cpl, void *dev_id);
  140. /*
  141. * If a (PCI) device interrupt is not connected we set dev->irq to
  142. * IRQ_NOTCONNECTED. This causes request_irq() to fail with -ENOTCONN, so we
  143. * can distingiush that case from other error returns.
  144. *
  145. * 0x80000000 is guaranteed to be outside the available range of interrupts
  146. * and easy to distinguish from other possible incorrect values.
  147. */
  148. #define IRQ_NOTCONNECTED (1U << 31)
  149. extern int __must_check
  150. request_threaded_irq(unsigned int irq, irq_handler_t handler,
  151. irq_handler_t thread_fn,
  152. unsigned long flags, const char *name, void *dev);
  153. static inline int __must_check request_irq(unsigned int irq, irq_handler_t handler, unsigned long flags,
  154. const char *name, void *dev)
  155. {
  156. return request_threaded_irq(irq, handler, NULL, flags, name, dev);
  157. }
  158. extern int __must_check
  159. request_any_context_irq(unsigned int irq, irq_handler_t handler,
  160. unsigned long flags, const char *name, void *dev_id);
  161. /*
  162. *extern int __must_check
  163. *__request_percpu_irq(unsigned int irq, irq_handler_t handler,
  164. * unsigned long flags, const char *devname,
  165. * void __percpu *percpu_dev_id);
  166. */
  167. extern int __must_check
  168. request_nmi(unsigned int irq, irq_handler_t handler, unsigned long flags,
  169. const char *name, void *dev);
  170. /*
  171. *static inline int __must_check
  172. *request_percpu_irq(unsigned int irq, irq_handler_t handler,
  173. * const char *devname, void __percpu *percpu_dev_id)
  174. *{
  175. * return __request_percpu_irq(irq, handler, 0,
  176. * devname, percpu_dev_id);
  177. *}
  178. *
  179. */
  180. /*
  181. *extern int __must_check
  182. *request_percpu_nmi(unsigned int irq, irq_handler_t handler,
  183. * const char *devname, void __percpu *dev);
  184. */
  185. extern const void *free_irq(unsigned int, void *);
  186. //extern void free_percpu_irq(unsigned int, void __percpu *);
  187. extern const void *free_nmi(unsigned int irq, void *dev_id);
  188. //extern void free_percpu_nmi(unsigned int irq, void __percpu *percpu_dev_id);
  189. //struct device;
  190. /*
  191. *extern int __must_check
  192. *devm_request_threaded_irq(struct device *dev, unsigned int irq,
  193. * irq_handler_t handler, irq_handler_t thread_fn,
  194. * unsigned long irqflags, const char *devname,
  195. * void *dev_id);
  196. */
  197. /*
  198. *static inline int __must_check
  199. *devm_request_irq(struct device *dev, unsigned int irq, irq_handler_t handler,
  200. * unsigned long irqflags, const char *devname, void *dev_id)
  201. *{
  202. * return devm_request_threaded_irq(dev, irq, handler, NULL, irqflags,
  203. * devname, dev_id);
  204. *}
  205. */
  206. /*
  207. *extern int __must_check
  208. *devm_request_any_context_irq(struct device *dev, unsigned int irq,
  209. * irq_handler_t handler, unsigned long irqflags,
  210. * const char *devname, void *dev_id);
  211. */
  212. //extern void devm_free_irq(struct device *dev, unsigned int irq, void *dev_id);
  213. /*
  214. * On lockdep we dont want to enable hardirqs in hardirq
  215. * context. Use local_irq_enable_in_hardirq() to annotate
  216. * kernel code that has to do this nevertheless (pretty much
  217. * the only valid case is for old/broken hardware that is
  218. * insanely slow).
  219. *
  220. * NOTE: in theory this might break fragile code that relies
  221. * on hardirq delivery - in practice we dont seem to have such
  222. * places left. So the only effect should be slightly increased
  223. * irqs-off latencies.
  224. */
  225. #ifdef CONFIG_LOCKDEP
  226. # define local_irq_enable_in_hardirq() do { } while (0)
  227. #else
  228. # define local_irq_enable_in_hardirq() local_irq_enable()
  229. #endif
  230. extern void disable_irq_nosync(unsigned int irq);
  231. extern bool disable_hardirq(unsigned int irq);
  232. extern void disable_irq(unsigned int irq);
  233. extern void disable_percpu_irq(unsigned int irq);
  234. extern void enable_irq(unsigned int irq);
  235. extern void enable_percpu_irq(unsigned int irq, unsigned int type);
  236. extern bool irq_percpu_is_enabled(unsigned int irq);
  237. extern void irq_wake_thread(unsigned int irq, void *dev_id);
  238. extern void disable_nmi_nosync(unsigned int irq);
  239. extern void disable_percpu_nmi(unsigned int irq);
  240. extern void enable_nmi(unsigned int irq);
  241. extern void enable_percpu_nmi(unsigned int irq, unsigned int type);
  242. extern int prepare_percpu_nmi(unsigned int irq);
  243. extern void teardown_percpu_nmi(unsigned int irq);
  244. /* The following three functions are for the core kernel use only. */
  245. extern void suspend_device_irqs(void);
  246. extern void resume_device_irqs(void);
  247. /**
  248. * struct irq_affinity_notify - context for notification of IRQ affinity changes
  249. * @irq: Interrupt to which notification applies
  250. * @kref: Reference count, for internal use
  251. * @work: Work item, for internal use
  252. * @notify: Function to be called on change. This will be
  253. * called in process context.
  254. * @release: Function to be called on release. This will be
  255. * called in process context. Once registered, the
  256. * structure must only be freed when this function is
  257. * called or later.
  258. */
  259. struct irq_affinity_notify
  260. {
  261. unsigned int irq;
  262. //struct kref kref;
  263. //struct work_struct work;
  264. //void (*notify)(struct irq_affinity_notify *, const cpumask_t *mask);
  265. //void (*release)(struct kref *ref);
  266. };
  267. #define IRQ_AFFINITY_MAX_SETS 4
  268. /**
  269. * struct irq_affinity - Description for automatic irq affinity assignements
  270. * @pre_vectors: Don't apply affinity to @pre_vectors at beginning of
  271. * the MSI(-X) vector space
  272. * @post_vectors: Don't apply affinity to @post_vectors at end of
  273. * the MSI(-X) vector space
  274. * @nr_sets: The number of interrupt sets for which affinity
  275. * spreading is required
  276. * @set_size: Array holding the size of each interrupt set
  277. * @calc_sets: Callback for calculating the number and size
  278. * of interrupt sets
  279. * @priv: Private data for usage by @calc_sets, usually a
  280. * pointer to driver/device specific data.
  281. */
  282. struct irq_affinity
  283. {
  284. unsigned int pre_vectors;
  285. unsigned int post_vectors;
  286. unsigned int nr_sets;
  287. //unsigned int set_size[IRQ_AFFINITY_MAX_SETS];
  288. //void (*calc_sets)(struct irq_affinity *, unsigned int nvecs);
  289. void *priv;
  290. };
  291. /**
  292. * struct irq_affinity_desc - Interrupt affinity descriptor
  293. * @mask: cpumask to hold the affinity assignment
  294. * @is_managed: 1 if the interrupt is managed internally
  295. */
  296. /*
  297. *struct irq_affinity_desc {
  298. * struct cpumask mask;
  299. * unsigned int is_managed : 1;
  300. *};
  301. */
  302. #if (0) /*defined(CONFIG_SMP)*/
  303. extern cpumask_var_t irq_default_affinity;
  304. /* Internal implementation. Use the helpers below */
  305. extern int __irq_set_affinity(unsigned int irq, const struct cpumask *cpumask,
  306. bool force);
  307. /**
  308. * irq_set_affinity - Set the irq affinity of a given irq
  309. * @irq: Interrupt to set affinity
  310. * @cpumask: cpumask
  311. *
  312. * Fails if cpumask does not contain an online CPU
  313. */
  314. static inline int irq_set_affinity(unsigned int irq, const struct cpumask *cpumask)
  315. {
  316. return __irq_set_affinity(irq, cpumask, false);
  317. }
  318. /**
  319. * irq_force_affinity - Force the irq affinity of a given irq
  320. * @irq: Interrupt to set affinity
  321. * @cpumask: cpumask
  322. *
  323. * Same as irq_set_affinity, but without checking the mask against
  324. * online cpus.
  325. *
  326. * Solely for low level cpu hotplug code, where we need to make per
  327. * cpu interrupts affine before the cpu becomes online.
  328. */
  329. static inline int irq_force_affinity(unsigned int irq, const struct cpumask *cpumask)
  330. {
  331. return __irq_set_affinity(irq, cpumask, true);
  332. }
  333. extern int irq_can_set_affinity(unsigned int irq);
  334. extern int irq_select_affinity(unsigned int irq);
  335. extern int irq_set_affinity_hint(unsigned int irq, const struct cpumask *m);
  336. extern int
  337. irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify);
  338. struct irq_affinity_desc *
  339. irq_create_affinity_masks(unsigned int nvec, struct irq_affinity *affd);
  340. unsigned int irq_calc_affinity_vectors(unsigned int minvec, unsigned int maxvec,
  341. const struct irq_affinity *affd);
  342. #else /* CONFIG_SMP */
  343. static inline int irq_set_affinity(unsigned int irq, const struct cpumask *m)
  344. {
  345. return -1;
  346. }
  347. static inline int irq_force_affinity(unsigned int irq, const struct cpumask *cpumask)
  348. {
  349. return 0;
  350. }
  351. static inline int irq_can_set_affinity(unsigned int irq)
  352. {
  353. return 0;
  354. }
  355. static inline int irq_select_affinity(unsigned int irq)
  356. {
  357. return 0;
  358. }
  359. static inline int irq_set_affinity_hint(unsigned int irq,
  360. const struct cpumask *m)
  361. {
  362. return -1;
  363. }
  364. /*
  365. *static inline int
  366. *irq_set_affinity_notifier(unsigned int irq, struct irq_affinity_notify *notify)
  367. *{
  368. * return 0;
  369. *}
  370. */
  371. /*
  372. *static inline struct irq_affinity_desc *
  373. *irq_create_affinity_masks(unsigned int nvec, struct irq_affinity *affd)
  374. *{
  375. * return NULL;
  376. *}
  377. */
  378. /*
  379. *static inline unsigned int
  380. *irq_calc_affinity_vectors(unsigned int minvec, unsigned int maxvec,
  381. * const struct irq_affinity *affd)
  382. *{
  383. * return maxvec;
  384. *}
  385. */
  386. #endif /* CONFIG_SMP */
  387. /*
  388. * Special lockdep variants of irq disabling/enabling.
  389. * These should be used for locking constructs that
  390. * know that a particular irq context which is disabled,
  391. * and which is the only irq-context user of a lock,
  392. * that it's safe to take the lock in the irq-disabled
  393. * section without disabling hardirqs.
  394. *
  395. * On !CONFIG_LOCKDEP they are equivalent to the normal
  396. * irq disable/enable methods.
  397. */
  398. static inline void disable_irq_nosync_lockdep(unsigned int irq)
  399. {
  400. disable_irq_nosync(irq);
  401. #ifdef CONFIG_LOCKDEP
  402. local_irq_disable();
  403. #endif
  404. }
  405. static inline void disable_irq_nosync_lockdep_irqsave(unsigned int irq, unsigned long *flags)
  406. {
  407. disable_irq_nosync(irq);
  408. #ifdef CONFIG_LOCKDEP
  409. local_irq_save(*flags);
  410. #endif
  411. }
  412. static inline void disable_irq_lockdep(unsigned int irq)
  413. {
  414. disable_irq(irq);
  415. #ifdef CONFIG_LOCKDEP
  416. local_irq_disable();
  417. #endif
  418. }
  419. static inline void enable_irq_lockdep(unsigned int irq)
  420. {
  421. #ifdef CONFIG_LOCKDEP
  422. local_irq_enable();
  423. #endif
  424. enable_irq(irq);
  425. }
  426. static inline void enable_irq_lockdep_irqrestore(unsigned int irq, unsigned long *flags)
  427. {
  428. #ifdef CONFIG_LOCKDEP
  429. local_irq_restore(*flags);
  430. #endif
  431. enable_irq(irq);
  432. }
  433. /* IRQ wakeup (PM) control: */
  434. extern int irq_set_irq_wake(unsigned int irq, unsigned int on);
  435. static inline int enable_irq_wake(unsigned int irq)
  436. {
  437. return irq_set_irq_wake(irq, 1);
  438. }
  439. static inline int disable_irq_wake(unsigned int irq)
  440. {
  441. return irq_set_irq_wake(irq, 0);
  442. }
  443. /*
  444. * irq_get_irqchip_state/irq_set_irqchip_state specific flags
  445. */
  446. enum irqchip_irq_state
  447. {
  448. IRQCHIP_STATE_PENDING, /* Is interrupt pending? */
  449. IRQCHIP_STATE_ACTIVE, /* Is interrupt in progress? */
  450. IRQCHIP_STATE_MASKED, /* Is interrupt masked? */
  451. IRQCHIP_STATE_LINE_LEVEL, /* Is IRQ line high? */
  452. };
  453. extern int irq_get_irqchip_state(unsigned int irq, enum irqchip_irq_state which,
  454. bool *state);
  455. extern int irq_set_irqchip_state(unsigned int irq, enum irqchip_irq_state which,
  456. bool state);
  457. #ifdef CONFIG_IRQ_FORCED_THREADING
  458. extern bool force_irqthreads;
  459. #else
  460. #define force_irqthreads (0)
  461. #endif
  462. #ifndef local_softirq_pending
  463. #ifndef local_softirq_pending_ref
  464. //#define local_softirq_pending_ref irq_stat.__softirq_pending
  465. #endif
  466. //#define local_softirq_pending() (__this_cpu_read(local_softirq_pending_ref))
  467. //#define set_softirq_pending(x) (__this_cpu_write(local_softirq_pending_ref, (x)))
  468. //#define or_softirq_pending(x) (__this_cpu_or(local_softirq_pending_ref, (x)))
  469. #endif /* local_softirq_pending */
  470. /* Some architectures might implement lazy enabling/disabling of
  471. * interrupts. In some cases, such as stop_machine, we might want
  472. * to ensure that after a local_irq_disable(), interrupts have
  473. * really been disabled in hardware. Such architectures need to
  474. * implement the following hook.
  475. */
  476. #ifndef hard_irq_disable
  477. #define hard_irq_disable() do { } while(0)
  478. #endif
  479. /* PLEASE, avoid to allocate new softirqs, if you need not _really_ high
  480. frequency threaded job scheduling. For almost all the purposes
  481. tasklets are more than enough. F.e. all serial device BHs et
  482. al. should be converted to tasklets, not to softirqs.
  483. */
  484. enum
  485. {
  486. HI_SOFTIRQ = 0,
  487. TIMER_SOFTIRQ,
  488. NET_TX_SOFTIRQ,
  489. NET_RX_SOFTIRQ,
  490. BLOCK_SOFTIRQ,
  491. IRQ_POLL_SOFTIRQ,
  492. TASKLET_SOFTIRQ,
  493. SCHED_SOFTIRQ,
  494. HRTIMER_SOFTIRQ, /* Unused, but kept as tools rely on the
  495. numbering. Sigh! */
  496. RCU_SOFTIRQ, /* Preferable RCU should always be the last softirq */
  497. NR_SOFTIRQS
  498. };
  499. #define SOFTIRQ_STOP_IDLE_MASK (~(1 << RCU_SOFTIRQ))
  500. /* map softirq index to softirq name. update 'softirq_to_name' in
  501. * kernel/softirq.c when adding a new softirq.
  502. */
  503. extern const char *const softirq_to_name[NR_SOFTIRQS];
  504. /* softirq mask and active fields moved to irq_cpustat_t in
  505. * asm/hardirq.h to get better cache usage. KAO
  506. */
  507. struct softirq_action
  508. {
  509. void (*action)(struct softirq_action *);
  510. };
  511. //asmlinkage void do_softirq(void);
  512. //asmlinkage void __do_softirq(void);
  513. #ifdef __ARCH_HAS_DO_SOFTIRQ
  514. void do_softirq_own_stack(void);
  515. #else
  516. static inline void do_softirq_own_stack(void)
  517. {
  518. //__do_softirq();
  519. }
  520. #endif
  521. extern void open_softirq(int nr, void (*action)(struct softirq_action *));
  522. extern void softirq_init(void);
  523. extern void __raise_softirq_irqoff(unsigned int nr);
  524. extern void raise_softirq_irqoff(unsigned int nr);
  525. extern void raise_softirq(unsigned int nr);
  526. //DECLARE_PER_CPU(struct task_struct *, ksoftirqd);
  527. /*
  528. *static inline struct task_struct *this_cpu_ksoftirqd(void)
  529. *{
  530. * return this_cpu_read(ksoftirqd);
  531. *}
  532. */
  533. /* Tasklets --- multithreaded analogue of BHs.
  534. Main feature differing them of generic softirqs: tasklet
  535. is running only on one CPU simultaneously.
  536. Main feature differing them of BHs: different tasklets
  537. may be run simultaneously on different CPUs.
  538. Properties:
  539. * If tasklet_schedule() is called, then tasklet is guaranteed
  540. to be executed on some cpu at least once after this.
  541. * If the tasklet is already scheduled, but its execution is still not
  542. started, it will be executed only once.
  543. * If this tasklet is already running on another CPU (or schedule is called
  544. from tasklet itself), it is rescheduled for later.
  545. * Tasklet is strictly serialized wrt itself, but not
  546. wrt another tasklets. If client needs some intertask synchronization,
  547. he makes it with spinlocks.
  548. */
  549. /*
  550. *struct tasklet_struct
  551. *{
  552. * struct tasklet_struct *next;
  553. * unsigned long state;
  554. * atomic_t count;
  555. * void (*func)(unsigned long);
  556. * unsigned long data;
  557. *};
  558. */
  559. /*
  560. *#define DECLARE_TASKLET(name, func, data) \
  561. *struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(0), func, data }
  562. */
  563. /*
  564. *#define DECLARE_TASKLET_DISABLED(name, func, data) \
  565. *struct tasklet_struct name = { NULL, 0, ATOMIC_INIT(1), func, data }
  566. */
  567. enum
  568. {
  569. TASKLET_STATE_SCHED, /* Tasklet is scheduled for execution */
  570. TASKLET_STATE_RUN /* Tasklet is running (SMP only) */
  571. };
  572. //#ifdef CONFIG_SMP
  573. #if 0
  574. static inline int tasklet_trylock(struct tasklet_struct *t)
  575. {
  576. return !test_and_set_bit(TASKLET_STATE_RUN, &(t)->state);
  577. }
  578. static inline void tasklet_unlock(struct tasklet_struct *t)
  579. {
  580. smp_mb__before_atomic();
  581. clear_bit(TASKLET_STATE_RUN, &(t)->state);
  582. }
  583. static inline void tasklet_unlock_wait(struct tasklet_struct *t)
  584. {
  585. while (test_bit(TASKLET_STATE_RUN, &(t)->state))
  586. {
  587. barrier();
  588. }
  589. }
  590. #else
  591. #define tasklet_trylock(t) 1
  592. #define tasklet_unlock_wait(t) do { } while (0)
  593. #define tasklet_unlock(t) do { } while (0)
  594. #endif
  595. //extern void __tasklet_schedule(struct tasklet_struct *t);
  596. /*
  597. *static inline void tasklet_schedule(struct tasklet_struct *t)
  598. *{
  599. * if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
  600. * __tasklet_schedule(t);
  601. *}
  602. *
  603. *extern void __tasklet_hi_schedule(struct tasklet_struct *t);
  604. *
  605. *static inline void tasklet_hi_schedule(struct tasklet_struct *t)
  606. *{
  607. * if (!test_and_set_bit(TASKLET_STATE_SCHED, &t->state))
  608. * __tasklet_hi_schedule(t);
  609. *}
  610. *
  611. *static inline void tasklet_disable_nosync(struct tasklet_struct *t)
  612. *{
  613. * atomic_inc(&t->count);
  614. * smp_mb__after_atomic();
  615. *}
  616. *
  617. *static inline void tasklet_disable(struct tasklet_struct *t)
  618. *{
  619. * tasklet_disable_nosync(t);
  620. * tasklet_unlock_wait(t);
  621. * smp_mb();
  622. *}
  623. *
  624. *static inline void tasklet_enable(struct tasklet_struct *t)
  625. *{
  626. * smp_mb__before_atomic();
  627. * atomic_dec(&t->count);
  628. *}
  629. *
  630. *extern void tasklet_kill(struct tasklet_struct *t);
  631. *extern void tasklet_kill_immediate(struct tasklet_struct *t, unsigned int cpu);
  632. *extern void tasklet_init(struct tasklet_struct *t,
  633. * void (*func)(unsigned long), unsigned long data);
  634. */
  635. /*
  636. * Autoprobing for irqs:
  637. *
  638. * probe_irq_on() and probe_irq_off() provide robust primitives
  639. * for accurate IRQ probing during kernel initialization. They are
  640. * reasonably simple to use, are not "fooled" by spurious interrupts,
  641. * and, unlike other attempts at IRQ probing, they do not get hung on
  642. * stuck interrupts (such as unused PS2 mouse interfaces on ASUS boards).
  643. *
  644. * For reasonably foolproof probing, use them as follows:
  645. *
  646. * 1. clear and/or mask the device's internal interrupt.
  647. * 2. sti();
  648. * 3. irqs = probe_irq_on(); // "take over" all unassigned idle IRQs
  649. * 4. enable the device and cause it to trigger an interrupt.
  650. * 5. wait for the device to interrupt, using non-intrusive polling or a delay.
  651. * 6. irq = probe_irq_off(irqs); // get IRQ number, 0=none, negative=multiple
  652. * 7. service the device to clear its pending interrupt.
  653. * 8. loop again if paranoia is required.
  654. *
  655. * probe_irq_on() returns a mask of allocated irq's.
  656. *
  657. * probe_irq_off() takes the mask as a parameter,
  658. * and returns the irq number which occurred,
  659. * or zero if none occurred, or a negative irq number
  660. * if more than one irq occurred.
  661. */
  662. #if !defined(CONFIG_GENERIC_IRQ_PROBE)
  663. static inline unsigned long probe_irq_on(void)
  664. {
  665. return 0;
  666. }
  667. static inline int probe_irq_off(unsigned long val)
  668. {
  669. return 0;
  670. }
  671. static inline unsigned int probe_irq_mask(unsigned long val)
  672. {
  673. return 0;
  674. }
  675. #else
  676. extern unsigned long probe_irq_on(void); /* returns 0 on failure */
  677. extern int probe_irq_off(unsigned long); /* returns 0 or negative on failure */
  678. extern unsigned int probe_irq_mask(unsigned long); /* returns mask of ISA interrupts */
  679. #endif
  680. #ifdef CONFIG_PROC_FS
  681. /* Initialize /proc/irq/ */
  682. extern void init_irq_proc(void);
  683. #else
  684. static inline void init_irq_proc(void)
  685. {
  686. }
  687. #endif
  688. #ifdef CONFIG_IRQ_TIMINGS
  689. void irq_timings_enable(void);
  690. void irq_timings_disable(void);
  691. uint64_t irq_timings_next_event(uint64_t now);
  692. #endif
  693. /*
  694. *struct seq_file;
  695. *int show_interrupts(struct seq_file *p, void *v);
  696. *int arch_show_interrupts(struct seq_file *p, int prec);
  697. *
  698. */
  699. extern int early_irq_init(void);
  700. extern int arch_probe_nr_irqs(void);
  701. extern int arch_early_irq_init(void);
  702. /*
  703. * We want to know which function is an entrypoint of a hardirq or a softirq.
  704. */
  705. #define __irq_entry __attribute__((__section__(".irqentry.text")))
  706. #define __softirq_entry \
  707. __attribute__((__section__(".softirqentry.text")))
  708. #endif