xref: /OK3568_Linux_fs/kernel/include/linux/irqdesc.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun #ifndef _LINUX_IRQDESC_H
3*4882a593Smuzhiyun #define _LINUX_IRQDESC_H
4*4882a593Smuzhiyun 
5*4882a593Smuzhiyun #include <linux/rcupdate.h>
6*4882a593Smuzhiyun #include <linux/kobject.h>
7*4882a593Smuzhiyun #include <linux/mutex.h>
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun /*
10*4882a593Smuzhiyun  * Core internal functions to deal with irq descriptors
11*4882a593Smuzhiyun  */
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun struct irq_affinity_notify;
14*4882a593Smuzhiyun struct proc_dir_entry;
15*4882a593Smuzhiyun struct module;
16*4882a593Smuzhiyun struct irq_desc;
17*4882a593Smuzhiyun struct irq_domain;
18*4882a593Smuzhiyun struct pt_regs;
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun /**
21*4882a593Smuzhiyun  * struct irq_desc - interrupt descriptor
22*4882a593Smuzhiyun  * @irq_common_data:	per irq and chip data passed down to chip functions
23*4882a593Smuzhiyun  * @kstat_irqs:		irq stats per cpu
24*4882a593Smuzhiyun  * @handle_irq:		highlevel irq-events handler
25*4882a593Smuzhiyun  * @action:		the irq action chain
26*4882a593Smuzhiyun  * @status_use_accessors: status information
27*4882a593Smuzhiyun  * @core_internal_state__do_not_mess_with_it: core internal status information
28*4882a593Smuzhiyun  * @depth:		disable-depth, for nested irq_disable() calls
29*4882a593Smuzhiyun  * @wake_depth:		enable depth, for multiple irq_set_irq_wake() callers
30*4882a593Smuzhiyun  * @tot_count:		stats field for non-percpu irqs
31*4882a593Smuzhiyun  * @irq_count:		stats field to detect stalled irqs
32*4882a593Smuzhiyun  * @last_unhandled:	aging timer for unhandled count
33*4882a593Smuzhiyun  * @irqs_unhandled:	stats field for spurious unhandled interrupts
34*4882a593Smuzhiyun  * @threads_handled:	stats field for deferred spurious detection of threaded handlers
35*4882a593Smuzhiyun  * @threads_handled_last: comparator field for deferred spurious detection of theraded handlers
36*4882a593Smuzhiyun  * @lock:		locking for SMP
37*4882a593Smuzhiyun  * @affinity_hint:	hint to user space for preferred irq affinity
38*4882a593Smuzhiyun  * @affinity_notify:	context for notification of affinity changes
39*4882a593Smuzhiyun  * @pending_mask:	pending rebalanced interrupts
40*4882a593Smuzhiyun  * @threads_oneshot:	bitfield to handle shared oneshot threads
41*4882a593Smuzhiyun  * @threads_active:	number of irqaction threads currently running
42*4882a593Smuzhiyun  * @wait_for_threads:	wait queue for sync_irq to wait for threaded handlers
43*4882a593Smuzhiyun  * @nr_actions:		number of installed actions on this descriptor
44*4882a593Smuzhiyun  * @no_suspend_depth:	number of irqactions on a irq descriptor with
45*4882a593Smuzhiyun  *			IRQF_NO_SUSPEND set
46*4882a593Smuzhiyun  * @force_resume_depth:	number of irqactions on a irq descriptor with
47*4882a593Smuzhiyun  *			IRQF_FORCE_RESUME set
48*4882a593Smuzhiyun  * @rcu:		rcu head for delayed free
49*4882a593Smuzhiyun  * @kobj:		kobject used to represent this struct in sysfs
50*4882a593Smuzhiyun  * @request_mutex:	mutex to protect request/free before locking desc->lock
51*4882a593Smuzhiyun  * @dir:		/proc/irq/ procfs entry
52*4882a593Smuzhiyun  * @debugfs_file:	dentry for the debugfs file
53*4882a593Smuzhiyun  * @name:		flow handler name for /proc/interrupts output
54*4882a593Smuzhiyun  */
55*4882a593Smuzhiyun struct irq_desc {
56*4882a593Smuzhiyun 	struct irq_common_data	irq_common_data;
57*4882a593Smuzhiyun 	struct irq_data		irq_data;
58*4882a593Smuzhiyun 	unsigned int __percpu	*kstat_irqs;
59*4882a593Smuzhiyun 	irq_flow_handler_t	handle_irq;
60*4882a593Smuzhiyun 	struct irqaction	*action;	/* IRQ action list */
61*4882a593Smuzhiyun 	unsigned int		status_use_accessors;
62*4882a593Smuzhiyun 	unsigned int		core_internal_state__do_not_mess_with_it;
63*4882a593Smuzhiyun 	unsigned int		depth;		/* nested irq disables */
64*4882a593Smuzhiyun 	unsigned int		wake_depth;	/* nested wake enables */
65*4882a593Smuzhiyun 	unsigned int		tot_count;
66*4882a593Smuzhiyun 	unsigned int		irq_count;	/* For detecting broken IRQs */
67*4882a593Smuzhiyun 	unsigned long		last_unhandled;	/* Aging timer for unhandled count */
68*4882a593Smuzhiyun 	unsigned int		irqs_unhandled;
69*4882a593Smuzhiyun 	atomic_t		threads_handled;
70*4882a593Smuzhiyun 	int			threads_handled_last;
71*4882a593Smuzhiyun 	raw_spinlock_t		lock;
72*4882a593Smuzhiyun 	struct cpumask		*percpu_enabled;
73*4882a593Smuzhiyun 	const struct cpumask	*percpu_affinity;
74*4882a593Smuzhiyun #ifdef CONFIG_SMP
75*4882a593Smuzhiyun 	const struct cpumask	*affinity_hint;
76*4882a593Smuzhiyun 	struct irq_affinity_notify *affinity_notify;
77*4882a593Smuzhiyun #ifdef CONFIG_GENERIC_PENDING_IRQ
78*4882a593Smuzhiyun 	cpumask_var_t		pending_mask;
79*4882a593Smuzhiyun #endif
80*4882a593Smuzhiyun #endif
81*4882a593Smuzhiyun 	unsigned long		threads_oneshot;
82*4882a593Smuzhiyun 	atomic_t		threads_active;
83*4882a593Smuzhiyun 	wait_queue_head_t       wait_for_threads;
84*4882a593Smuzhiyun #ifdef CONFIG_PM_SLEEP
85*4882a593Smuzhiyun 	unsigned int		nr_actions;
86*4882a593Smuzhiyun 	unsigned int		no_suspend_depth;
87*4882a593Smuzhiyun 	unsigned int		cond_suspend_depth;
88*4882a593Smuzhiyun 	unsigned int		force_resume_depth;
89*4882a593Smuzhiyun #endif
90*4882a593Smuzhiyun #ifdef CONFIG_PROC_FS
91*4882a593Smuzhiyun 	struct proc_dir_entry	*dir;
92*4882a593Smuzhiyun #endif
93*4882a593Smuzhiyun #ifdef CONFIG_GENERIC_IRQ_DEBUGFS
94*4882a593Smuzhiyun 	struct dentry		*debugfs_file;
95*4882a593Smuzhiyun 	const char		*dev_name;
96*4882a593Smuzhiyun #endif
97*4882a593Smuzhiyun #ifdef CONFIG_SPARSE_IRQ
98*4882a593Smuzhiyun 	struct rcu_head		rcu;
99*4882a593Smuzhiyun 	struct kobject		kobj;
100*4882a593Smuzhiyun #endif
101*4882a593Smuzhiyun 	struct mutex		request_mutex;
102*4882a593Smuzhiyun 	int			parent_irq;
103*4882a593Smuzhiyun 	struct module		*owner;
104*4882a593Smuzhiyun 	const char		*name;
105*4882a593Smuzhiyun } ____cacheline_internodealigned_in_smp;
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun #ifdef CONFIG_SPARSE_IRQ
108*4882a593Smuzhiyun extern void irq_lock_sparse(void);
109*4882a593Smuzhiyun extern void irq_unlock_sparse(void);
110*4882a593Smuzhiyun #else
irq_lock_sparse(void)111*4882a593Smuzhiyun static inline void irq_lock_sparse(void) { }
irq_unlock_sparse(void)112*4882a593Smuzhiyun static inline void irq_unlock_sparse(void) { }
113*4882a593Smuzhiyun extern struct irq_desc irq_desc[NR_IRQS];
114*4882a593Smuzhiyun #endif
115*4882a593Smuzhiyun 
irq_data_to_desc(struct irq_data * data)116*4882a593Smuzhiyun static inline struct irq_desc *irq_data_to_desc(struct irq_data *data)
117*4882a593Smuzhiyun {
118*4882a593Smuzhiyun 	return container_of(data->common, struct irq_desc, irq_common_data);
119*4882a593Smuzhiyun }
120*4882a593Smuzhiyun 
irq_desc_get_irq(struct irq_desc * desc)121*4882a593Smuzhiyun static inline unsigned int irq_desc_get_irq(struct irq_desc *desc)
122*4882a593Smuzhiyun {
123*4882a593Smuzhiyun 	return desc->irq_data.irq;
124*4882a593Smuzhiyun }
125*4882a593Smuzhiyun 
irq_desc_get_irq_data(struct irq_desc * desc)126*4882a593Smuzhiyun static inline struct irq_data *irq_desc_get_irq_data(struct irq_desc *desc)
127*4882a593Smuzhiyun {
128*4882a593Smuzhiyun 	return &desc->irq_data;
129*4882a593Smuzhiyun }
130*4882a593Smuzhiyun 
irq_desc_get_chip(struct irq_desc * desc)131*4882a593Smuzhiyun static inline struct irq_chip *irq_desc_get_chip(struct irq_desc *desc)
132*4882a593Smuzhiyun {
133*4882a593Smuzhiyun 	return desc->irq_data.chip;
134*4882a593Smuzhiyun }
135*4882a593Smuzhiyun 
irq_desc_get_chip_data(struct irq_desc * desc)136*4882a593Smuzhiyun static inline void *irq_desc_get_chip_data(struct irq_desc *desc)
137*4882a593Smuzhiyun {
138*4882a593Smuzhiyun 	return desc->irq_data.chip_data;
139*4882a593Smuzhiyun }
140*4882a593Smuzhiyun 
irq_desc_get_handler_data(struct irq_desc * desc)141*4882a593Smuzhiyun static inline void *irq_desc_get_handler_data(struct irq_desc *desc)
142*4882a593Smuzhiyun {
143*4882a593Smuzhiyun 	return desc->irq_common_data.handler_data;
144*4882a593Smuzhiyun }
145*4882a593Smuzhiyun 
146*4882a593Smuzhiyun /*
147*4882a593Smuzhiyun  * Architectures call this to let the generic IRQ layer
148*4882a593Smuzhiyun  * handle an interrupt.
149*4882a593Smuzhiyun  */
generic_handle_irq_desc(struct irq_desc * desc)150*4882a593Smuzhiyun static inline void generic_handle_irq_desc(struct irq_desc *desc)
151*4882a593Smuzhiyun {
152*4882a593Smuzhiyun 	desc->handle_irq(desc);
153*4882a593Smuzhiyun }
154*4882a593Smuzhiyun 
155*4882a593Smuzhiyun int generic_handle_irq(unsigned int irq);
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun #ifdef CONFIG_HANDLE_DOMAIN_IRQ
158*4882a593Smuzhiyun /*
159*4882a593Smuzhiyun  * Convert a HW interrupt number to a logical one using a IRQ domain,
160*4882a593Smuzhiyun  * and handle the result interrupt number. Return -EINVAL if
161*4882a593Smuzhiyun  * conversion failed. Providing a NULL domain indicates that the
162*4882a593Smuzhiyun  * conversion has already been done.
163*4882a593Smuzhiyun  */
164*4882a593Smuzhiyun int __handle_domain_irq(struct irq_domain *domain, unsigned int hwirq,
165*4882a593Smuzhiyun 			bool lookup, struct pt_regs *regs);
166*4882a593Smuzhiyun 
handle_domain_irq(struct irq_domain * domain,unsigned int hwirq,struct pt_regs * regs)167*4882a593Smuzhiyun static inline int handle_domain_irq(struct irq_domain *domain,
168*4882a593Smuzhiyun 				    unsigned int hwirq, struct pt_regs *regs)
169*4882a593Smuzhiyun {
170*4882a593Smuzhiyun 	return __handle_domain_irq(domain, hwirq, true, regs);
171*4882a593Smuzhiyun }
172*4882a593Smuzhiyun 
173*4882a593Smuzhiyun #ifdef CONFIG_IRQ_DOMAIN
174*4882a593Smuzhiyun int handle_domain_nmi(struct irq_domain *domain, unsigned int hwirq,
175*4882a593Smuzhiyun 		      struct pt_regs *regs);
176*4882a593Smuzhiyun #endif
177*4882a593Smuzhiyun #endif
178*4882a593Smuzhiyun 
179*4882a593Smuzhiyun /* Test to see if a driver has successfully requested an irq */
irq_desc_has_action(struct irq_desc * desc)180*4882a593Smuzhiyun static inline int irq_desc_has_action(struct irq_desc *desc)
181*4882a593Smuzhiyun {
182*4882a593Smuzhiyun 	return desc->action != NULL;
183*4882a593Smuzhiyun }
184*4882a593Smuzhiyun 
irq_has_action(unsigned int irq)185*4882a593Smuzhiyun static inline int irq_has_action(unsigned int irq)
186*4882a593Smuzhiyun {
187*4882a593Smuzhiyun 	return irq_desc_has_action(irq_to_desc(irq));
188*4882a593Smuzhiyun }
189*4882a593Smuzhiyun 
190*4882a593Smuzhiyun /**
191*4882a593Smuzhiyun  * irq_set_handler_locked - Set irq handler from a locked region
192*4882a593Smuzhiyun  * @data:	Pointer to the irq_data structure which identifies the irq
193*4882a593Smuzhiyun  * @handler:	Flow control handler function for this interrupt
194*4882a593Smuzhiyun  *
195*4882a593Smuzhiyun  * Sets the handler in the irq descriptor associated to @data.
196*4882a593Smuzhiyun  *
197*4882a593Smuzhiyun  * Must be called with irq_desc locked and valid parameters. Typical
198*4882a593Smuzhiyun  * call site is the irq_set_type() callback.
199*4882a593Smuzhiyun  */
irq_set_handler_locked(struct irq_data * data,irq_flow_handler_t handler)200*4882a593Smuzhiyun static inline void irq_set_handler_locked(struct irq_data *data,
201*4882a593Smuzhiyun 					  irq_flow_handler_t handler)
202*4882a593Smuzhiyun {
203*4882a593Smuzhiyun 	struct irq_desc *desc = irq_data_to_desc(data);
204*4882a593Smuzhiyun 
205*4882a593Smuzhiyun 	desc->handle_irq = handler;
206*4882a593Smuzhiyun }
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun /**
209*4882a593Smuzhiyun  * irq_set_chip_handler_name_locked - Set chip, handler and name from a locked region
210*4882a593Smuzhiyun  * @data:	Pointer to the irq_data structure for which the chip is set
211*4882a593Smuzhiyun  * @chip:	Pointer to the new irq chip
212*4882a593Smuzhiyun  * @handler:	Flow control handler function for this interrupt
213*4882a593Smuzhiyun  * @name:	Name of the interrupt
214*4882a593Smuzhiyun  *
215*4882a593Smuzhiyun  * Replace the irq chip at the proper hierarchy level in @data and
216*4882a593Smuzhiyun  * sets the handler and name in the associated irq descriptor.
217*4882a593Smuzhiyun  *
218*4882a593Smuzhiyun  * Must be called with irq_desc locked and valid parameters.
219*4882a593Smuzhiyun  */
220*4882a593Smuzhiyun static inline void
irq_set_chip_handler_name_locked(struct irq_data * data,struct irq_chip * chip,irq_flow_handler_t handler,const char * name)221*4882a593Smuzhiyun irq_set_chip_handler_name_locked(struct irq_data *data, struct irq_chip *chip,
222*4882a593Smuzhiyun 				 irq_flow_handler_t handler, const char *name)
223*4882a593Smuzhiyun {
224*4882a593Smuzhiyun 	struct irq_desc *desc = irq_data_to_desc(data);
225*4882a593Smuzhiyun 
226*4882a593Smuzhiyun 	desc->handle_irq = handler;
227*4882a593Smuzhiyun 	desc->name = name;
228*4882a593Smuzhiyun 	data->chip = chip;
229*4882a593Smuzhiyun }
230*4882a593Smuzhiyun 
irq_balancing_disabled(unsigned int irq)231*4882a593Smuzhiyun static inline bool irq_balancing_disabled(unsigned int irq)
232*4882a593Smuzhiyun {
233*4882a593Smuzhiyun 	struct irq_desc *desc;
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun 	desc = irq_to_desc(irq);
236*4882a593Smuzhiyun 	return desc->status_use_accessors & IRQ_NO_BALANCING_MASK;
237*4882a593Smuzhiyun }
238*4882a593Smuzhiyun 
irq_is_percpu(unsigned int irq)239*4882a593Smuzhiyun static inline bool irq_is_percpu(unsigned int irq)
240*4882a593Smuzhiyun {
241*4882a593Smuzhiyun 	struct irq_desc *desc;
242*4882a593Smuzhiyun 
243*4882a593Smuzhiyun 	desc = irq_to_desc(irq);
244*4882a593Smuzhiyun 	return desc->status_use_accessors & IRQ_PER_CPU;
245*4882a593Smuzhiyun }
246*4882a593Smuzhiyun 
irq_is_percpu_devid(unsigned int irq)247*4882a593Smuzhiyun static inline bool irq_is_percpu_devid(unsigned int irq)
248*4882a593Smuzhiyun {
249*4882a593Smuzhiyun 	struct irq_desc *desc;
250*4882a593Smuzhiyun 
251*4882a593Smuzhiyun 	desc = irq_to_desc(irq);
252*4882a593Smuzhiyun 	return desc->status_use_accessors & IRQ_PER_CPU_DEVID;
253*4882a593Smuzhiyun }
254*4882a593Smuzhiyun 
255*4882a593Smuzhiyun static inline void
irq_set_lockdep_class(unsigned int irq,struct lock_class_key * lock_class,struct lock_class_key * request_class)256*4882a593Smuzhiyun irq_set_lockdep_class(unsigned int irq, struct lock_class_key *lock_class,
257*4882a593Smuzhiyun 		      struct lock_class_key *request_class)
258*4882a593Smuzhiyun {
259*4882a593Smuzhiyun 	struct irq_desc *desc = irq_to_desc(irq);
260*4882a593Smuzhiyun 
261*4882a593Smuzhiyun 	if (desc) {
262*4882a593Smuzhiyun 		lockdep_set_class(&desc->lock, lock_class);
263*4882a593Smuzhiyun 		lockdep_set_class(&desc->request_mutex, request_class);
264*4882a593Smuzhiyun 	}
265*4882a593Smuzhiyun }
266*4882a593Smuzhiyun 
267*4882a593Smuzhiyun #endif
268