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