xref: /illumos-gate/usr/src/uts/common/sys/ddi_intr.h (revision 3d393ee6c37fa10ac512ed6d36109ad616dc7c1a)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 /*
22  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_DDI_INTR_H
27 #define	_SYS_DDI_INTR_H
28 
29 /*
30  * Sun DDI interrupt support definitions
31  */
32 
33 #include <sys/ddipropdefs.h>
34 #include <sys/rwlock.h>
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #ifdef _KERNEL
41 
42 /*
43  * Interrupt related definitions.
44  */
45 
46 /*
47  * Returned by ddi_add_intr or ddi_add_fastintr in order to signal
48  * the the caller requested interrupt number to be added does not
49  * exist.
50  */
51 #define	DDI_INTR_NOTFOUND	1	/* interrupt not found error */
52 
53 /*
54  * For use by driver interrupt service routines to return to the
55  * system whether an interrupt was for the driver or not.
56  */
57 #define	DDI_INTR_CLAIMED	1	/* returned when driver claims intr */
58 #define	DDI_INTR_UNCLAIMED	0	/* returned when driver does not */
59 
60 /* Hardware interrupt types */
61 #define	DDI_INTR_TYPE_FIXED	0x1
62 #define	DDI_INTR_TYPE_MSI	0x2
63 #define	DDI_INTR_TYPE_MSIX	0x4
64 
65 /* Hardware interrupt priority must be a number within these min/max values */
66 #define	DDI_INTR_PRI_MIN	1
67 #define	DDI_INTR_PRI_MAX	12
68 
69 /* Soft priority must be a number within these min/max values */
70 #define	DDI_INTR_SOFTPRI_MIN	1
71 #define	DDI_INTR_SOFTPRI_MAX	9
72 
73 /* Used in calls to allocate soft interrupt priority. */
74 #define	DDI_INTR_SOFTPRI_DEFAULT	DDI_INTR_SOFTPRI_MIN
75 
76 /*
77  * Interrupt flags specify certain capabilities for a given
78  * interrupt (by type and inum).
79  * RO/RW refer to use by ddi_intr_set_cap(9f)
80  *
81  * DDI_INTR_FLAG_MSI64 is an internal flag not exposed to leaf drivers.
82  */
83 #define	DDI_INTR_FLAG_LEVEL	0x0001	/* (RW) level trigger */
84 #define	DDI_INTR_FLAG_EDGE	0x0002	/* (RW) edge triggered */
85 #define	DDI_INTR_FLAG_MASKABLE	0x0010	/* (RO) maskable */
86 #define	DDI_INTR_FLAG_PENDING	0x0020	/* (RO) int pending supported */
87 #define	DDI_INTR_FLAG_BLOCK	0x0100	/* (RO) requires block enable */
88 #define	DDI_INTR_FLAG_MSI64	0x0200	/* (R0) MSI/X supports 64 bit addr */
89 
90 /*
91  * Macro to be used while passing interrupt priority
92  * for lock initialization.
93  */
94 #define	DDI_INTR_PRI(pri)	(void *)((uintptr_t)(pri))
95 
96 /*
97  * Typedef for interrupt handles
98  */
99 typedef struct __ddi_intr_handle *ddi_intr_handle_t;
100 typedef struct __ddi_softint_handle *ddi_softint_handle_t;
101 
102 /*
103  * Definition for behavior flag which is used with ddi_intr_alloc(9f).
104  */
105 #define	DDI_INTR_ALLOC_NORMAL	0	/* Non-strict alloc */
106 #define	DDI_INTR_ALLOC_STRICT	1	/* Strict allocation */
107 
108 /*
109  * Typedef for driver's interrupt handler
110  */
111 typedef uint_t (ddi_intr_handler_t)(caddr_t arg1, caddr_t arg2);
112 
113 #endif	/* _KERNEL */
114 #include <sys/ddi_intr_impl.h>
115 #ifdef _KERNEL
116 
117 /*
118  * DDI interrupt function prototypes.
119  *
120  * New DDI interrupt interfaces.
121  */
122 
123 /*
124  * ddi_intr_get_supported_types:
125  *
126  *	Return, as a bit mask, the hardware interrupt types supported by
127  *	both the device and by the host in the integer pointed
128  *	to be the 'typesp' argument.
129  */
130 int	ddi_intr_get_supported_types(dev_info_t *dip, int *typesp);
131 
132 /*
133  * ddi_intr_get_nintrs:
134  *
135  * 	Return as an integer in the integer pointed to by the argument
136  * 	*nintrsp*, the number of interrupts the device supports for the
137  *	given interrupt type.
138  */
139 int	ddi_intr_get_nintrs(dev_info_t *dip, int type, int *nintrsp);
140 
141 /*
142  * ddi_intr_get_navail:
143  *
144  * 	Return as an integer in the integer pointed to by the argument
145  * 	*navailp*, the number of interrupts currently available for the
146  *	given interrupt type.
147  */
148 int	ddi_intr_get_navail(dev_info_t *dip, int type, int *navailp);
149 
150 /*
151  * Interrupt resource allocate/free functions
152  */
153 int	ddi_intr_alloc(dev_info_t *dip, ddi_intr_handle_t *h_array,
154 	    int type, int inum, int count, int *actualp, int behavior);
155 int	ddi_intr_free(ddi_intr_handle_t h);
156 
157 /*
158  * Interrupt get/set capacity functions
159  */
160 int	ddi_intr_get_cap(ddi_intr_handle_t h, int *flagsp);
161 int	ddi_intr_set_cap(ddi_intr_handle_t h, int flags);
162 
163 /*
164  * Interrupt priority management functions
165  */
166 uint_t	ddi_intr_get_hilevel_pri(void);
167 int	ddi_intr_get_pri(ddi_intr_handle_t h, uint_t *prip);
168 int	ddi_intr_set_pri(ddi_intr_handle_t h, uint_t pri);
169 
170 /*
171  * Interrupt add/duplicate/remove functions
172  */
173 int	ddi_intr_add_handler(ddi_intr_handle_t h,
174 	    ddi_intr_handler_t inthandler, void *arg1, void *arg2);
175 int	ddi_intr_dup_handler(ddi_intr_handle_t org, int vector,
176 	    ddi_intr_handle_t *dup);
177 int	ddi_intr_remove_handler(ddi_intr_handle_t h);
178 
179 /*
180  * Interrupt enable/disable/block_enable/block_disable functions
181  */
182 int	ddi_intr_enable(ddi_intr_handle_t h);
183 int	ddi_intr_disable(ddi_intr_handle_t h);
184 int	ddi_intr_block_enable(ddi_intr_handle_t *h_array, int count);
185 int	ddi_intr_block_disable(ddi_intr_handle_t *h_array, int count);
186 
187 /*
188  * Interrupt set/clr mask functions
189  */
190 int	ddi_intr_set_mask(ddi_intr_handle_t h);
191 int	ddi_intr_clr_mask(ddi_intr_handle_t h);
192 
193 /*
194  * Interrupt get pending function
195  */
196 int	ddi_intr_get_pending(ddi_intr_handle_t h, int *pendingp);
197 
198 /*
199  * Soft interrupt functions
200  */
201 int	ddi_intr_add_softint(dev_info_t *dip, ddi_softint_handle_t *h,
202 	    int soft_pri, ddi_intr_handler_t handler, void *arg1);
203 int	ddi_intr_remove_softint(ddi_softint_handle_t h);
204 int	ddi_intr_trigger_softint(ddi_softint_handle_t h, void *arg2);
205 int	ddi_intr_get_softint_pri(ddi_softint_handle_t h, uint_t *soft_prip);
206 int	ddi_intr_set_softint_pri(ddi_softint_handle_t h, uint_t soft_pri);
207 
208 /*
209  * Interrupt resource management function
210  */
211 int	ddi_intr_set_nreq(dev_info_t *dip, int nreq);
212 
213 /*
214  * Old DDI interrupt interfaces.
215  *
216  * The following DDI interrupt interfaces are obsolete.
217  * Use the above new DDI interrupt interfaces instead.
218  */
219 
220 /*
221  * Return non-zero if the specified interrupt exists and the handler
222  * will be restricted to using only certain functions because the
223  * interrupt level is not blocked by the scheduler.  I.e., it cannot
224  * signal other threads.
225  */
226 int	ddi_intr_hilevel(dev_info_t *dip, uint_t inumber);
227 
228 int	ddi_get_iblock_cookie(dev_info_t *dip, uint_t inumber,
229 	    ddi_iblock_cookie_t *iblock_cookiep);
230 
231 /*
232  * ddi_dev_nintrs
233  *
234  *	If the device has h/w interrupt(s), report
235  *	how many of them that there are into resultp.
236  *	Return DDI_FAILURE if the device has no interrupts.
237  */
238 int	ddi_dev_nintrs(dev_info_t *dev, int *resultp);
239 
240 /*
241  * ddi_add_intr: Add an interrupt to the system.
242  *
243  *	The interrupt number "inumber" determines which interrupt will
244  *	be added. The interrupt number is associated with interrupt
245  *	information provided from self identifying devices or configuration
246  *	information for non-self identifying devices. If only one interrupt
247  *	is associated with the device then the interrupt number should be 0.
248  *
249  *	If successful, "*iblock_cookiep" will contain information necessary
250  *	for initializing locks (mutex_init, cv_init, etc.) as well as for
251  *	possible later removal of the interrupt from the system.
252  *
253  *	If successful, "*idevice_cookiep" will contain the correct programmable
254  *	device interrupt value (see <sys/dditypes.h> in the form of the
255  *	type ddi_idevice_cookie_t).
256  *
257  *	Either cookie pointer may be specified as a NULL pointer
258  *	in which case no value will be returned.
259  *
260  *	The interrupt handler "int_handler" is the address of the routine
261  *	to be called upon receipt of an appropriate interrupt. The
262  *	interrupt handler should return DDI_INTR_CLAIMED if the
263  *	interrupt was claimed, else DDI_INTR_UNCLAIMED. The argument
264  *	"int_handler_arg" will be passed to the "int_handler"
265  *	upon receipt of an appropriate interrupt.
266  *
267  *	If successful ddi_add_intr will return DDI_SUCCESS.
268  *	If the interrupt information cannot be found it will
269  *	return DDI_INTR_NOTFOUND.
270  *
271  */
272 int	ddi_add_intr(dev_info_t *dip, uint_t inumber,
273 	    ddi_iblock_cookie_t *iblock_cookiep,
274 	    ddi_idevice_cookie_t *idevice_cookiep,
275 	    uint_t (*int_handler)(caddr_t int_handler_arg),
276 	    caddr_t int_handler_arg);
277 
278 /*
279  * The following function is for Sun's internal use only at present
280  */
281 int	ddi_add_fastintr(dev_info_t *dip, uint_t inumber,
282 	    ddi_iblock_cookie_t *iblock_cookiep,
283 	    ddi_idevice_cookie_t *idevice_cookiep,
284 	    uint_t (*hi_int_handler)(void));
285 
286 /*
287  * ddi_remove_intr:	Remove interrupt set up by ddi_add_intr.
288  *
289  *	This routine is intended to be used by drivers that are
290  *	preparing to unload themselves "detach" from the system.
291  */
292 void	ddi_remove_intr(dev_info_t *dip, uint_t inum,
293 	    ddi_iblock_cookie_t iblock_cookie);
294 
295 /*
296  * For use by ddi_add_softintr in order to specify a priority preference.
297  */
298 #define	DDI_SOFTINT_FIXED	0	/* Fixed priority soft interrupt */
299 #define	DDI_SOFTINT_LOW		8	/* Low priority soft interrupt */
300 #define	DDI_SOFTINT_MED		128	/* Medium priority soft interrupt */
301 #define	DDI_SOFTINT_HIGH	256	/* High priority soft interrupt */
302 
303 
304 int	ddi_get_soft_iblock_cookie(dev_info_t *dip, int preference,
305 	    ddi_iblock_cookie_t *iblock_cookiep);
306 
307 /*
308  * ddi_add_softintr:	Add a "soft" interrupt to the system.
309  *
310  *	Like ddi_add_intr, only for system interrupts that you can trigger
311  *	yourself. You specify a preference (see above) for the level you
312  *	want. You get an identifier back which you can use to either trigger
313  *	a soft interrupt or, later, remove it.
314  */
315 int	ddi_add_softintr(dev_info_t *dip, int preference, ddi_softintr_t *idp,
316 	    ddi_iblock_cookie_t *iblock_cookiep,
317 	    ddi_idevice_cookie_t *idevice_cookiep,
318 	    uint_t (*int_handler)(caddr_t int_handler_arg),
319 	    caddr_t int_handler_arg);
320 
321 void	ddi_remove_softintr(ddi_softintr_t id);
322 
323 void	ddi_trigger_softintr(ddi_softintr_t id);
324 
325 #endif	/* _KERNEL */
326 
327 #ifdef	__cplusplus
328 }
329 #endif
330 
331 #endif	/* _SYS_DDI_INTR_H */
332