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