xref: /titanic_50/usr/src/uts/common/sys/ddi_intr.h (revision 554ff184129088135ad2643c1c9832174a17be88)
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  * Typedef for interrupt handles
95  */
96 typedef struct __ddi_intr_handle *ddi_intr_handle_t;
97 typedef struct __ddi_softint_handle *ddi_softint_handle_t;
98 
99 /*
100  * Definition for behavior flag which is used with ddi_intr_alloc(9f).
101  */
102 #define	DDI_INTR_ALLOC_NORMAL	0	/* Non-strict alloc */
103 #define	DDI_INTR_ALLOC_STRICT	1	/* Strict allocation */
104 
105 /*
106  * Typedef for driver's interrupt handler
107  */
108 typedef uint_t (ddi_intr_handler_t)(caddr_t arg1, caddr_t arg2);
109 
110 #endif	/* _KERNEL */
111 #include <sys/ddi_intr_impl.h>
112 #ifdef _KERNEL
113 
114 /*
115  * DDI interrupt function prototypes.
116  *
117  * New DDI interrupt interfaces.
118  */
119 
120 /*
121  * ddi_intr_get_supported_types:
122  *
123  *	Return, as a bit mask, the hardware interrupt types supported by
124  *	both the device and by the host in the integer pointed
125  *	to be the 'typesp' argument.
126  */
127 int	ddi_intr_get_supported_types(dev_info_t *dip, int *typesp);
128 
129 /*
130  * ddi_intr_get_nintrs:
131  *
132  * 	Return as an integer in the integer pointed to by the argument
133  * 	*nintrsp*, the number of interrupts the device supports for the
134  *	given interrupt type.
135  */
136 int	ddi_intr_get_nintrs(dev_info_t *dip, int type, int *nintrsp);
137 
138 /*
139  * ddi_intr_get_navail:
140  *
141  * 	Return as an integer in the integer pointed to by the argument
142  * 	*navailp*, the number of interrupts currently available for the
143  *	given interrupt type.
144  */
145 int	ddi_intr_get_navail(dev_info_t *dip, int type, int *navailp);
146 
147 /*
148  * Interrupt resource allocate/free functions
149  */
150 int	ddi_intr_alloc(dev_info_t *dip, ddi_intr_handle_t *h_array,
151 	    int type, int inum, int count, int *actualp, int behavior);
152 int	ddi_intr_free(ddi_intr_handle_t h);
153 
154 /*
155  * Interrupt get/set capacity functions
156  */
157 int	ddi_intr_get_cap(ddi_intr_handle_t h, int *flagsp);
158 int	ddi_intr_set_cap(ddi_intr_handle_t h, int flags);
159 
160 /*
161  * Interrupt priority management functions
162  */
163 uint_t	ddi_intr_get_hilevel_pri(void);
164 int	ddi_intr_get_pri(ddi_intr_handle_t h, uint_t *prip);
165 int	ddi_intr_set_pri(ddi_intr_handle_t h, uint_t pri);
166 
167 /*
168  * Interrupt add/duplicate/remove functions
169  */
170 int	ddi_intr_add_handler(ddi_intr_handle_t h,
171 	    ddi_intr_handler_t inthandler, void *arg1, void *arg2);
172 int	ddi_intr_dup_handler(ddi_intr_handle_t org, int vector,
173 	    ddi_intr_handle_t *dup);
174 int	ddi_intr_remove_handler(ddi_intr_handle_t h);
175 
176 /*
177  * Interrupt enable/disable/block_enable/block_disable functions
178  */
179 int	ddi_intr_enable(ddi_intr_handle_t h);
180 int	ddi_intr_disable(ddi_intr_handle_t h);
181 int	ddi_intr_block_enable(ddi_intr_handle_t *h_array, int count);
182 int	ddi_intr_block_disable(ddi_intr_handle_t *h_array, int count);
183 
184 /*
185  * Interrupt set/clr mask functions
186  */
187 int	ddi_intr_set_mask(ddi_intr_handle_t h);
188 int	ddi_intr_clr_mask(ddi_intr_handle_t h);
189 
190 /*
191  * Interrupt get pending function
192  */
193 int	ddi_intr_get_pending(ddi_intr_handle_t h, int *pendingp);
194 
195 /*
196  * Soft interrupt functions
197  */
198 int	ddi_intr_add_softint(dev_info_t *dip, ddi_softint_handle_t *h,
199 	    int soft_pri, ddi_intr_handler_t handler, void *arg1);
200 int	ddi_intr_remove_softint(ddi_softint_handle_t h);
201 int	ddi_intr_trigger_softint(ddi_softint_handle_t h, void *arg2);
202 int	ddi_intr_get_softint_pri(ddi_softint_handle_t h, uint_t *soft_prip);
203 int	ddi_intr_set_softint_pri(ddi_softint_handle_t h, uint_t soft_pri);
204 
205 
206 /*
207  * Old DDI interrupt interfaces.
208  */
209 
210 /*
211  * Return non-zero if the specified interrupt exists and the handler
212  * will be restricted to using only certain functions because the
213  * interrupt level is not blocked by the scheduler.  I.e., it cannot
214  * signal other threads.
215  */
216 int	ddi_intr_hilevel(dev_info_t *dip, uint_t inumber);
217 
218 int	ddi_get_iblock_cookie(dev_info_t *dip, uint_t inumber,
219 	    ddi_iblock_cookie_t *iblock_cookiep);
220 
221 /*
222  * ddi_dev_nintrs
223  *
224  *	If the device has h/w interrupt(s), report
225  *	how many of them that there are into resultp.
226  *	Return DDI_FAILURE if the device has no interrupts.
227  */
228 int	ddi_dev_nintrs(dev_info_t *dev, int *resultp);
229 
230 /*
231  * ddi_add_intr: Add an interrupt to the system.
232  *
233  *	The interrupt number "inumber" determines which interrupt will
234  *	be added. The interrupt number is associated with interrupt
235  *	information provided from self identifying devices or configuration
236  *	information for non-self identifying devices. If only one interrupt
237  *	is associated with the device then the interrupt number should be 0.
238  *
239  *	If successful, "*iblock_cookiep" will contain information necessary
240  *	for initializing locks (mutex_init, cv_init, etc.) as well as for
241  *	possible later removal of the interrupt from the system.
242  *
243  *	If successful, "*idevice_cookiep" will contain the correct programmable
244  *	device interrupt value (see <sys/dditypes.h> in the form of the
245  *	type ddi_idevice_cookie_t).
246  *
247  *	Either cookie pointer may be specified as a NULL pointer
248  *	in which case no value will be returned.
249  *
250  *	The interrupt handler "int_handler" is the address of the routine
251  *	to be called upon receipt of an appropriate interrupt. The
252  *	interrupt handler should return DDI_INTR_CLAIMED if the
253  *	interrupt was claimed, else DDI_INTR_UNCLAIMED. The argument
254  *	"int_handler_arg" will be passed to the "int_handler"
255  *	upon receipt of an appropriate interrupt.
256  *
257  *	If successful ddi_add_intr will return DDI_SUCCESS.
258  *	If the interrupt information cannot be found it will
259  *	return DDI_INTR_NOTFOUND.
260  *
261  */
262 int	ddi_add_intr(dev_info_t *dip, uint_t inumber,
263 	    ddi_iblock_cookie_t *iblock_cookiep,
264 	    ddi_idevice_cookie_t *idevice_cookiep,
265 	    uint_t (*int_handler)(caddr_t int_handler_arg),
266 	    caddr_t int_handler_arg);
267 
268 /*
269  * The following function is for Sun's internal use only at present
270  */
271 int	ddi_add_fastintr(dev_info_t *dip, uint_t inumber,
272 	    ddi_iblock_cookie_t *iblock_cookiep,
273 	    ddi_idevice_cookie_t *idevice_cookiep,
274 	    uint_t (*hi_int_handler)(void));
275 
276 /*
277  * ddi_remove_intr:	Remove interrupt set up by ddi_add_intr.
278  *
279  *	This routine is intended to be used by drivers that are
280  *	preparing to unload themselves "detach" from the system.
281  */
282 void	ddi_remove_intr(dev_info_t *dip, uint_t inum,
283 	    ddi_iblock_cookie_t iblock_cookie);
284 
285 /*
286  * For use by ddi_add_softintr in order to specify a priority preference.
287  */
288 #define	DDI_SOFTINT_FIXED	0	/* Fixed priority soft interrupt */
289 #define	DDI_SOFTINT_LOW		8	/* Low priority soft interrupt */
290 #define	DDI_SOFTINT_MED		128	/* Medium priority soft interrupt */
291 #define	DDI_SOFTINT_HIGH	256	/* High priority soft interrupt */
292 
293 
294 int	ddi_get_soft_iblock_cookie(dev_info_t *dip, int preference,
295 	    ddi_iblock_cookie_t *iblock_cookiep);
296 
297 /*
298  * ddi_add_softintr:	Add a "soft" interrupt to the system.
299  *
300  *	Like ddi_add_intr, only for system interrupts that you can trigger
301  *	yourself. You specify a preference (see above) for the level you
302  *	want. You get an identifier back which you can use to either trigger
303  *	a soft interrupt or, later, remove it.
304  */
305 int	ddi_add_softintr(dev_info_t *dip, int preference, ddi_softintr_t *idp,
306 	    ddi_iblock_cookie_t *iblock_cookiep,
307 	    ddi_idevice_cookie_t *idevice_cookiep,
308 	    uint_t (*int_handler)(caddr_t int_handler_arg),
309 	    caddr_t int_handler_arg);
310 
311 void	ddi_remove_softintr(ddi_softintr_t id);
312 
313 void	ddi_trigger_softintr(ddi_softintr_t id);
314 
315 #endif	/* _KERNEL */
316 
317 #ifdef	__cplusplus
318 }
319 #endif
320 
321 #endif	/* _SYS_DDI_INTR_H */
322