interrupt.h 8.07 KB
Newer Older
1
/*-
2
3
 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
 *
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
 * Copyright (c) 1997, Stefan Esser <se@freebsd.org>
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice unmodified, this list of conditions, and the following
 *    disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
Peter Wemm's avatar
Peter Wemm committed
28
 * $FreeBSD$
29
30
 */

31
32
#ifndef _SYS_INTERRUPT_H_
#define _SYS_INTERRUPT_H_
33

34
35
#include <sys/_lock.h>
#include <sys/_mutex.h>
36
#include <sys/ck.h>
37

38
39
struct intr_event;
struct intr_thread;
40
struct trapframe;
41

42
43
44
/*
 * Describe a hardware interrupt handler.
 *
45
 * Multiple interrupt handlers for a specific event can be chained
46
 * together.
47
 */
48
struct intr_handler {
John Baldwin's avatar
John Baldwin committed
49
50
51
	driver_filter_t	*ih_filter;	/* Filter handler function. */
	driver_intr_t	*ih_handler;	/* Threaded handler function. */
	void		*ih_argument;	/* Argument to pass to handlers. */
52
	int		 ih_flags;
53
	char		 ih_name[MAXCOMLEN + 1]; /* Name of handler. */
54
	struct intr_event *ih_event;	/* Event we are connected to. */
55
	int		 ih_need;	/* Needs service. */
56
	CK_SLIST_ENTRY(intr_handler) ih_next; /* Next handler for this event. */
57
58
59
60
	u_char		 ih_pri;	/* Priority of this handler. */
};

/* Interrupt handle flags kept in ih_flags */
61
#define	IH_NET		0x00000001	/* Network. */
62
63
#define	IH_EXCLUSIVE	0x00000002	/* Exclusive interrupt. */
#define	IH_ENTROPY	0x00000004	/* Device is a good entropy source. */
64
#define	IH_DEAD		0x00000008	/* Handler should be removed. */
65
66
#define	IH_SUSP		0x00000010	/* Device is powered down. */
#define	IH_CHANGED	0x40000000	/* Handler state is changed. */
67
#define	IH_MPSAFE	0x80000000	/* Handler does not need Giant. */
68

69
/*
70
 * Describe an interrupt event.  An event holds a list of handlers.
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
 * The 'pre_ithread', 'post_ithread', 'post_filter', and 'assign_cpu'
 * hooks are used to invoke MD code for certain operations.
 *
 * The 'pre_ithread' hook is called when an interrupt thread for
 * handlers without filters is scheduled.  It is responsible for
 * ensuring that 1) the system won't be swamped with an interrupt
 * storm from the associated source while the ithread runs and 2) the
 * current CPU is able to receive interrupts from other interrupt
 * sources.  The first is usually accomplished by disabling
 * level-triggered interrupts until the ithread completes.  The second
 * is accomplished on some platforms by acknowledging the interrupt
 * via an EOI.
 *
 * The 'post_ithread' hook is invoked when an ithread finishes.  It is
 * responsible for ensuring that the associated interrupt source will
 * trigger an interrupt when it is asserted in the future.  Usually
 * this is implemented by enabling a level-triggered interrupt that
 * was previously disabled via the 'pre_ithread' hook.
 *
 * The 'post_filter' hook is invoked when a filter handles an
 * interrupt.  It is responsible for ensuring that the current CPU is
 * able to receive interrupts again.  On some platforms this is done
 * by acknowledging the interrupts via an EOI.
 *
 * The 'assign_cpu' hook is used to bind an interrupt source to a
 * specific CPU.  If the interrupt cannot be bound, this function may
 * return an error.
98
99
100
101
102
103
104
105
106
107
 *
 * Note that device drivers may also use interrupt events to manage
 * multiplexing interrupt interrupt handler into handlers for child
 * devices.  In that case, the above hooks are not used.  The device
 * can create an event for its interrupt resource and register child
 * event handlers with that event.  It can then use
 * intr_event_execute_handlers() to execute non-filter handlers.
 * Currently filter handlers are not supported by this, but that can
 * be added by splitting out the filter loop from intr_event_handle()
 * if desired.
108
 */
109
110
struct intr_event {
	TAILQ_ENTRY(intr_event) ie_list;
111
	CK_SLIST_HEAD(, intr_handler) ie_handlers; /* Interrupt handlers. */
112
113
	char		ie_name[MAXCOMLEN + 1]; /* Individual event name. */
	char		ie_fullname[MAXCOMLEN + 1];
114
115
116
	struct mtx	ie_lock;
	void		*ie_source;	/* Cookie used by MD code. */
	struct intr_thread *ie_thread;	/* Thread we are connected to. */
117
118
119
	void		(*ie_pre_ithread)(void *);
	void		(*ie_post_ithread)(void *);
	void		(*ie_post_filter)(void *);
120
	int		(*ie_assign_cpu)(void *, int);
121
	int		ie_flags;
122
	int		ie_hflags;	/* Cumulative flags of all handlers. */
123
	int		ie_count;	/* Loop counter. */
124
125
	int		ie_warncnt;	/* Rate-check interrupt storm warns. */
	struct timeval	ie_warntm;
126
	int		ie_irq;		/* Physical irq number if !SOFT. */
127
	int		ie_cpu;		/* CPU this event is bound to. */
128
129
	volatile int	ie_phase;	/* Switched to establish a barrier. */
	volatile int	ie_active[2];	/* Filters in ISR context. */
130
131
};

132
133
134
/* Interrupt event flags kept in ie_flags. */
#define	IE_SOFT		0x000001	/* Software interrupt. */
#define	IE_ADDING_THREAD 0x000004	/* Currently building an ithread. */
135

136
137
/* Flags to pass to swi_sched. */
#define	SWI_FROMNMI	0x1
138
#define	SWI_DELAY	0x2
139

140
/*
141
142
 * Software interrupt numbers in priority order.  The priority determines
 * the priority of the corresponding interrupt thread.
143
144
145
 */
#define	SWI_TTY		0
#define	SWI_NET		1
146
147
148
149
#define	SWI_CAMBIO	2
#define	SWI_VM		3
#define	SWI_CLOCK	4
#define	SWI_TQ_FAST	5
150
#define	SWI_TQ		6
151
#define	SWI_TQ_GIANT	6
152

153
154
struct proc;

155
extern struct	intr_event *clk_intr_event;
156
extern struct	intr_event *tty_intr_event;
157
extern void	*vm_ih;
158

159
/* Counts and names for statistics (defined in MD code). */
160
161
extern u_long 	*intrcnt;	/* counts for for each device and stray */
extern char 	*intrnames;	/* string table containing device names */
162
163
extern size_t	sintrcnt;	/* size of intrcnt table */
extern size_t	sintrnames;	/* size of intrnames table */
164

165
#ifdef DDB
166
void	db_dump_intr_event(struct intr_event *ie, int handlers);
167
#endif
168
169
u_char	intr_priority(enum intr_type flags);
int	intr_event_add_handler(struct intr_event *ie, const char *name,
170
171
	    driver_filter_t filter, driver_intr_t handler, void *arg, 
	    u_char pri, enum intr_type flags, void **cookiep);	    
172
int	intr_event_bind(struct intr_event *ie, int cpu);
173
174
int	intr_event_bind_irqonly(struct intr_event *ie, int cpu);
int	intr_event_bind_ithread(struct intr_event *ie, int cpu);
175
struct _cpuset;
176
int	intr_event_bind_ithread_cpuset(struct intr_event *ie,
177
	    struct _cpuset *mask);
178
int	intr_event_create(struct intr_event **event, void *source,
179
	    int flags, int irq, void (*pre_ithread)(void *),
180
	    void (*post_ithread)(void *), void (*post_filter)(void *),
181
	    int (*assign_cpu)(void *, int), const char *fmt, ...)
182
	    __printflike(9, 10);
183
184
int	intr_event_describe_handler(struct intr_event *ie, void *cookie,
	    const char *descr);
185
int	intr_event_destroy(struct intr_event *ie);
186
int	intr_event_handle(struct intr_event *ie, struct trapframe *frame);
187
int	intr_event_remove_handler(void *cookie);
188
189
int	intr_event_suspend_handler(void *cookie);
int	intr_event_resume_handler(void *cookie);
190
int	intr_getaffinity(int irq, int mode, void *mask);
191
void	*intr_handler_source(void *cookie);
192
int	intr_setaffinity(int irq, int mode, void *mask);
Hans Petter Selasky's avatar
Hans Petter Selasky committed
193
void	_intr_drain(int irq);  /* LinuxKPI only. */
194
int	swi_add(struct intr_event **eventp, const char *name,
195
	    driver_intr_t handler, void *arg, int pri, enum intr_type flags,
Alfred Perlstein's avatar
Alfred Perlstein committed
196
197
	    void **cookiep);
void	swi_sched(void *cookie, int flags);
198
int	swi_remove(void *cookie);
199
200

#endif