Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _LINUX_IRQDESC_H
0003 #define _LINUX_IRQDESC_H
0004 
0005 #include <linux/rcupdate.h>
0006 #include <linux/kobject.h>
0007 #include <linux/mutex.h>
0008 
0009 /*
0010  * Core internal functions to deal with irq descriptors
0011  */
0012 
0013 struct irq_affinity_notify;
0014 struct proc_dir_entry;
0015 struct module;
0016 struct irq_desc;
0017 struct irq_domain;
0018 struct pt_regs;
0019 
0020 /**
0021  * struct irq_desc - interrupt descriptor
0022  * @irq_common_data:    per irq and chip data passed down to chip functions
0023  * @kstat_irqs:     irq stats per cpu
0024  * @handle_irq:     highlevel irq-events handler
0025  * @action:     the irq action chain
0026  * @status_use_accessors: status information
0027  * @core_internal_state__do_not_mess_with_it: core internal status information
0028  * @depth:      disable-depth, for nested irq_disable() calls
0029  * @wake_depth:     enable depth, for multiple irq_set_irq_wake() callers
0030  * @tot_count:      stats field for non-percpu irqs
0031  * @irq_count:      stats field to detect stalled irqs
0032  * @last_unhandled: aging timer for unhandled count
0033  * @irqs_unhandled: stats field for spurious unhandled interrupts
0034  * @threads_handled:    stats field for deferred spurious detection of threaded handlers
0035  * @threads_handled_last: comparator field for deferred spurious detection of threaded handlers
0036  * @lock:       locking for SMP
0037  * @affinity_hint:  hint to user space for preferred irq affinity
0038  * @affinity_notify:    context for notification of affinity changes
0039  * @pending_mask:   pending rebalanced interrupts
0040  * @threads_oneshot:    bitfield to handle shared oneshot threads
0041  * @threads_active: number of irqaction threads currently running
0042  * @wait_for_threads:   wait queue for sync_irq to wait for threaded handlers
0043  * @nr_actions:     number of installed actions on this descriptor
0044  * @no_suspend_depth:   number of irqactions on a irq descriptor with
0045  *          IRQF_NO_SUSPEND set
0046  * @force_resume_depth: number of irqactions on a irq descriptor with
0047  *          IRQF_FORCE_RESUME set
0048  * @rcu:        rcu head for delayed free
0049  * @kobj:       kobject used to represent this struct in sysfs
0050  * @request_mutex:  mutex to protect request/free before locking desc->lock
0051  * @dir:        /proc/irq/ procfs entry
0052  * @debugfs_file:   dentry for the debugfs file
0053  * @name:       flow handler name for /proc/interrupts output
0054  */
0055 struct irq_desc {
0056     struct irq_common_data  irq_common_data;
0057     struct irq_data     irq_data;
0058     unsigned int __percpu   *kstat_irqs;
0059     irq_flow_handler_t  handle_irq;
0060     struct irqaction    *action;    /* IRQ action list */
0061     unsigned int        status_use_accessors;
0062     unsigned int        core_internal_state__do_not_mess_with_it;
0063     unsigned int        depth;      /* nested irq disables */
0064     unsigned int        wake_depth; /* nested wake enables */
0065     unsigned int        tot_count;
0066     unsigned int        irq_count;  /* For detecting broken IRQs */
0067     unsigned long       last_unhandled; /* Aging timer for unhandled count */
0068     unsigned int        irqs_unhandled;
0069     atomic_t        threads_handled;
0070     int         threads_handled_last;
0071     raw_spinlock_t      lock;
0072     struct cpumask      *percpu_enabled;
0073     const struct cpumask    *percpu_affinity;
0074 #ifdef CONFIG_SMP
0075     const struct cpumask    *affinity_hint;
0076     struct irq_affinity_notify *affinity_notify;
0077 #ifdef CONFIG_GENERIC_PENDING_IRQ
0078     cpumask_var_t       pending_mask;
0079 #endif
0080 #endif
0081     unsigned long       threads_oneshot;
0082     atomic_t        threads_active;
0083     wait_queue_head_t       wait_for_threads;
0084 #ifdef CONFIG_PM_SLEEP
0085     unsigned int        nr_actions;
0086     unsigned int        no_suspend_depth;
0087     unsigned int        cond_suspend_depth;
0088     unsigned int        force_resume_depth;
0089 #endif
0090 #ifdef CONFIG_PROC_FS
0091     struct proc_dir_entry   *dir;
0092 #endif
0093 #ifdef CONFIG_GENERIC_IRQ_DEBUGFS
0094     struct dentry       *debugfs_file;
0095     const char      *dev_name;
0096 #endif
0097 #ifdef CONFIG_SPARSE_IRQ
0098     struct rcu_head     rcu;
0099     struct kobject      kobj;
0100 #endif
0101     struct mutex        request_mutex;
0102     int         parent_irq;
0103     struct module       *owner;
0104     const char      *name;
0105 } ____cacheline_internodealigned_in_smp;
0106 
0107 #ifdef CONFIG_SPARSE_IRQ
0108 extern void irq_lock_sparse(void);
0109 extern void irq_unlock_sparse(void);
0110 #else
0111 static inline void irq_lock_sparse(void) { }
0112 static inline void irq_unlock_sparse(void) { }
0113 extern struct irq_desc irq_desc[NR_IRQS];
0114 #endif
0115 
0116 static inline unsigned int irq_desc_kstat_cpu(struct irq_desc *desc,
0117                           unsigned int cpu)
0118 {
0119     return desc->kstat_irqs ? *per_cpu_ptr(desc->kstat_irqs, cpu) : 0;
0120 }
0121 
0122 static inline struct irq_desc *irq_data_to_desc(struct irq_data *data)
0123 {
0124     return container_of(data->common, struct irq_desc, irq_common_data);
0125 }
0126 
0127 static inline unsigned int irq_desc_get_irq(struct irq_desc *desc)
0128 {
0129     return desc->irq_data.irq;
0130 }
0131 
0132 static inline struct irq_data *irq_desc_get_irq_data(struct irq_desc *desc)
0133 {
0134     return &desc->irq_data;
0135 }
0136 
0137 static inline struct irq_chip *irq_desc_get_chip(struct irq_desc *desc)
0138 {
0139     return desc->irq_data.chip;
0140 }
0141 
0142 static inline void *irq_desc_get_chip_data(struct irq_desc *desc)
0143 {
0144     return desc->irq_data.chip_data;
0145 }
0146 
0147 static inline void *irq_desc_get_handler_data(struct irq_desc *desc)
0148 {
0149     return desc->irq_common_data.handler_data;
0150 }
0151 
0152 /*
0153  * Architectures call this to let the generic IRQ layer
0154  * handle an interrupt.
0155  */
0156 static inline void generic_handle_irq_desc(struct irq_desc *desc)
0157 {
0158     desc->handle_irq(desc);
0159 }
0160 
0161 int handle_irq_desc(struct irq_desc *desc);
0162 int generic_handle_irq(unsigned int irq);
0163 int generic_handle_irq_safe(unsigned int irq);
0164 
0165 #ifdef CONFIG_IRQ_DOMAIN
0166 /*
0167  * Convert a HW interrupt number to a logical one using a IRQ domain,
0168  * and handle the result interrupt number. Return -EINVAL if
0169  * conversion failed.
0170  */
0171 int generic_handle_domain_irq(struct irq_domain *domain, unsigned int hwirq);
0172 int generic_handle_domain_nmi(struct irq_domain *domain, unsigned int hwirq);
0173 #endif
0174 
0175 /* Test to see if a driver has successfully requested an irq */
0176 static inline int irq_desc_has_action(struct irq_desc *desc)
0177 {
0178     return desc && desc->action != NULL;
0179 }
0180 
0181 /**
0182  * irq_set_handler_locked - Set irq handler from a locked region
0183  * @data:   Pointer to the irq_data structure which identifies the irq
0184  * @handler:    Flow control handler function for this interrupt
0185  *
0186  * Sets the handler in the irq descriptor associated to @data.
0187  *
0188  * Must be called with irq_desc locked and valid parameters. Typical
0189  * call site is the irq_set_type() callback.
0190  */
0191 static inline void irq_set_handler_locked(struct irq_data *data,
0192                       irq_flow_handler_t handler)
0193 {
0194     struct irq_desc *desc = irq_data_to_desc(data);
0195 
0196     desc->handle_irq = handler;
0197 }
0198 
0199 /**
0200  * irq_set_chip_handler_name_locked - Set chip, handler and name from a locked region
0201  * @data:   Pointer to the irq_data structure for which the chip is set
0202  * @chip:   Pointer to the new irq chip
0203  * @handler:    Flow control handler function for this interrupt
0204  * @name:   Name of the interrupt
0205  *
0206  * Replace the irq chip at the proper hierarchy level in @data and
0207  * sets the handler and name in the associated irq descriptor.
0208  *
0209  * Must be called with irq_desc locked and valid parameters.
0210  */
0211 static inline void
0212 irq_set_chip_handler_name_locked(struct irq_data *data,
0213                  const struct irq_chip *chip,
0214                  irq_flow_handler_t handler, const char *name)
0215 {
0216     struct irq_desc *desc = irq_data_to_desc(data);
0217 
0218     desc->handle_irq = handler;
0219     desc->name = name;
0220     data->chip = (struct irq_chip *)chip;
0221 }
0222 
0223 bool irq_check_status_bit(unsigned int irq, unsigned int bitmask);
0224 
0225 static inline bool irq_balancing_disabled(unsigned int irq)
0226 {
0227     return irq_check_status_bit(irq, IRQ_NO_BALANCING_MASK);
0228 }
0229 
0230 static inline bool irq_is_percpu(unsigned int irq)
0231 {
0232     return irq_check_status_bit(irq, IRQ_PER_CPU);
0233 }
0234 
0235 static inline bool irq_is_percpu_devid(unsigned int irq)
0236 {
0237     return irq_check_status_bit(irq, IRQ_PER_CPU_DEVID);
0238 }
0239 
0240 void __irq_set_lockdep_class(unsigned int irq, struct lock_class_key *lock_class,
0241                  struct lock_class_key *request_class);
0242 static inline void
0243 irq_set_lockdep_class(unsigned int irq, struct lock_class_key *lock_class,
0244               struct lock_class_key *request_class)
0245 {
0246     if (IS_ENABLED(CONFIG_LOCKDEP))
0247         __irq_set_lockdep_class(irq, lock_class, request_class);
0248 }
0249 
0250 #endif