xref: /titanic_44/usr/src/uts/common/sys/ddi_intr_impl.h (revision c28749e97052f09388969427adf7df641cdcdc22)
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_IMPL_H
28 #define	_SYS_DDI_INTR_IMPL_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 /*
33  * Sun DDI interrupt implementation specific definitions
34  */
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #ifdef _KERNEL
41 
42 /*
43  * Typedef for interrupt ops
44  */
45 typedef enum {
46 	DDI_INTROP_SUPPORTED_TYPES = 1,	/* 1 get supported interrupts types */
47 	DDI_INTROP_NINTRS,		/* 2 get num of interrupts supported */
48 	DDI_INTROP_ALLOC,		/* 3 allocate interrupt handle */
49 	DDI_INTROP_GETPRI,		/* 4 get priority */
50 	DDI_INTROP_SETPRI,		/* 5 set priority */
51 	DDI_INTROP_ADDISR,		/* 6 add interrupt handler */
52 	DDI_INTROP_DUPVEC,		/* 7 duplicate interrupt handler */
53 	DDI_INTROP_ENABLE,		/* 8 enable interrupt */
54 	DDI_INTROP_BLOCKENABLE,		/* 9 block enable interrupts */
55 	DDI_INTROP_BLOCKDISABLE,	/* 10 block disable interrupts */
56 	DDI_INTROP_DISABLE,		/* 11 disable interrupt */
57 	DDI_INTROP_REMISR,		/* 12 remove interrupt handler */
58 	DDI_INTROP_FREE,		/* 13 free interrupt handle */
59 	DDI_INTROP_GETCAP,		/* 14 get capacity */
60 	DDI_INTROP_SETCAP,		/* 15 set capacity */
61 	DDI_INTROP_SETMASK,		/* 16 set mask */
62 	DDI_INTROP_CLRMASK,		/* 17 clear mask */
63 	DDI_INTROP_GETPENDING,		/* 18 get pending interrupt */
64 	DDI_INTROP_NAVAIL		/* 19 get num of available interrupts */
65 } ddi_intr_op_t;
66 
67 /* Version number used in the handles */
68 #define	DDI_INTR_VERSION_1	1
69 #define	DDI_INTR_VERSION	DDI_INTR_VERSION_1
70 
71 /*
72  * One such data structure is allocated per ddi_intr_handle_t
73  * This is the incore copy of the regular interrupt info.
74  */
75 typedef struct ddi_intr_handle_impl {
76 	dev_info_t		*ih_dip;	/* dip associated with handle */
77 	uint16_t		ih_type;	/* interrupt type being used */
78 	ushort_t		ih_inum;	/* interrupt number */
79 	uint32_t		ih_vector;	/* vector number */
80 	uint16_t		ih_ver;		/* Version */
81 	uint_t			ih_state;	/* interrupt handle state */
82 	uint_t			ih_cap;		/* interrupt capabilities */
83 	uint_t			ih_pri;		/* priority - bus dependent */
84 	krwlock_t		ih_rwlock;	/* read/write lock per handle */
85 
86 	uint_t			(*ih_cb_func)(caddr_t, caddr_t);
87 	void			*ih_cb_arg1;
88 	void			*ih_cb_arg2;
89 
90 	/*
91 	 * The next set of members are for 'scratch' purpose only.
92 	 * The DDI interrupt framework uses them internally and their
93 	 * interpretation is left to the framework. For now,
94 	 *	scratch1	- used to send NINTRs information
95 	 *			  to various nexus drivers.
96 	 *	scratch2	- used to send 'behavior' flag
97 	 *			  information to the nexus drivers
98 	 *			  from ddi_intr_alloc()
99 	 *	private		- used by the DDI framework to
100 	 *			  pass back and forth 'vector' information
101 	 *			  It is extensively used on the SPARC side
102 	 *			  to temporarily hold the 'ddi_ispec_t'
103 	 */
104 	void			*ih_private;	/* Platform specific data */
105 	uint_t			ih_scratch1;	/* Scratch1: #interrupts */
106 	uint_t			ih_scratch2;	/* Scratch2: flag */
107 } ddi_intr_handle_impl_t;
108 
109 /* values for ih_state (strictly for interrupt handle) */
110 #define	DDI_IHDL_STATE_ALLOC	0x01	/* Allocated. ddi_intr_alloc() called */
111 #define	DDI_IHDL_STATE_ADDED	0x02	/* Added interrupt handler */
112 					/* ddi_intr_add_handler() called */
113 #define	DDI_IHDL_STATE_ENABLE	0x04	/* Enabled. ddi_intr_enable() called */
114 
115 #define	DDI_INTR_IS_MSI_OR_MSIX(type) \
116 	((type) == DDI_INTR_TYPE_MSI || (type) == DDI_INTR_TYPE_MSIX)
117 
118 #define	DDI_INTR_SUP_TYPES	DDI_INTR_TYPE_FIXED|DDI_INTR_TYPE_MSI|\
119 				DDI_INTR_TYPE_MSIX
120 
121 /*
122  * One such data structure is allocated per ddi_soft_intr_handle
123  * This is the incore copy of the softint info.
124  */
125 typedef struct ddi_softint_hdl_impl {
126 	dev_info_t	*ih_dip;		/* dip associated with handle */
127 	uint_t		ih_pri;			/* priority - bus dependent */
128 	krwlock_t	ih_rwlock;		/* read/write lock per handle */
129 	uint_t		ih_pending;		/* whether softint is pending */
130 
131 	uint_t		(*ih_cb_func)(caddr_t, caddr_t);
132 						/* cb function for soft ints */
133 	void		*ih_cb_arg1;		/* arg1 of callback function */
134 	void		*ih_cb_arg2;		/* arg2 passed to "trigger" */
135 
136 	/*
137 	 * The next member is for 'scratch' purpose only.
138 	 * The DDI interrupt framework uses it internally and its
139 	 * interpretation is left to the framework.
140 	 *	private		- used by the DDI framework to pass back
141 	 *			  and forth 'softid' information on SPARC
142 	 *			  side only. Not used on X86 platform.
143 	 */
144 	void		*ih_private;		/* Platform specific data */
145 } ddi_softint_hdl_impl_t;
146 
147 /* Softint internal implementation defines */
148 #define	DDI_SOFT_INTR_PRI_M	4
149 #define	DDI_SOFT_INTR_PRI_H	6
150 
151 /*
152  * One such data structure is allocated for MSI-X enabled
153  * device. If no MSI-X is enabled then it is NULL
154  */
155 typedef struct ddi_intr_msix {
156 	uint_t			msix_intrs_in_use;	/* MSI-X intrs in use */
157 
158 	/* MSI-X Table related information */
159 	ddi_acc_handle_t	msix_tbl_hdl;		/* MSI-X table handle */
160 	caddr_t			msix_tbl_addr;		/* MSI-X table addr */
161 	offset_t		msix_tbl_offset;	/* MSI-X table offset */
162 
163 	/* MSI-X PBA Table related information */
164 	ddi_acc_handle_t	msix_pba_hdl;		/* MSI-X PBA handle */
165 	caddr_t			msix_pba_addr;		/* MSI-X PBA addr */
166 	offset_t		msix_pba_offset;	/* MSI-X PBA offset */
167 
168 	ddi_device_acc_attr_t	msix_dev_attr;		/* MSI-X device attr */
169 } ddi_intr_msix_t;
170 
171 
172 /*
173  * One such data structure is allocated for each dip.
174  * It has interrupt related information that can be
175  * stored/retrieved for convenience.
176  */
177 typedef struct devinfo_intr {
178 	/* These three fields show what the device is capable of */
179 	uint_t		devi_intr_sup_types;	/* Intrs supported by device */
180 
181 	ddi_intr_msix_t	*devi_msix_p;		/* MSI-X info, if supported */
182 
183 	/* Next three fields show current status for the device */
184 	uint_t		devi_intr_curr_type;	/* Interrupt type being used */
185 	uint_t		devi_intr_sup_nintrs;	/* #intr supported */
186 	uint_t		devi_intr_curr_nintrs;	/* #intr currently being used */
187 
188 	ddi_intr_handle_t **devi_intr_handle_p;	/* Hdl for legacy intr APIs */
189 } devinfo_intr_t;
190 
191 #define	NEXUS_HAS_INTR_OP(dip)	\
192 	((DEVI(dip)->devi_ops->devo_bus_ops) && \
193 	(DEVI(dip)->devi_ops->devo_bus_ops->busops_rev >= BUSO_REV_9) && \
194 	(DEVI(dip)->devi_ops->devo_bus_ops->bus_intr_op))
195 
196 int	i_ddi_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t op,
197 	    ddi_intr_handle_impl_t *hdlp, void *result);
198 
199 int	i_ddi_add_softint(ddi_softint_hdl_impl_t *);
200 void	i_ddi_remove_softint(ddi_softint_hdl_impl_t *);
201 int	i_ddi_trigger_softint(ddi_softint_hdl_impl_t *, void *);
202 int	i_ddi_set_softint_pri(ddi_softint_hdl_impl_t *, uint_t);
203 
204 void	i_ddi_intr_devi_init(dev_info_t *dip);
205 void	i_ddi_intr_devi_fini(dev_info_t *dip);
206 
207 uint_t	i_ddi_intr_get_supported_types(dev_info_t *dip);
208 void	i_ddi_intr_set_supported_types(dev_info_t *dip, int sup_type);
209 uint_t	i_ddi_intr_get_current_type(dev_info_t *dip);
210 void	i_ddi_intr_set_current_type(dev_info_t *dip, int intr_type);
211 uint_t	i_ddi_intr_get_supported_nintrs(dev_info_t *dip, int intr_type);
212 void	i_ddi_intr_set_supported_nintrs(dev_info_t *dip, int nintrs);
213 uint_t	i_ddi_intr_get_current_nintrs(dev_info_t *dip);
214 void	i_ddi_intr_set_current_nintrs(dev_info_t *dip, int nintrs);
215 
216 ddi_intr_handle_t *i_ddi_get_intr_handle(dev_info_t *dip, int inum);
217 void	i_ddi_set_intr_handle(dev_info_t *dip, int inum,
218 	    ddi_intr_handle_t *hdlp);
219 
220 ddi_intr_msix_t	*i_ddi_get_msix(dev_info_t *dip);
221 void	i_ddi_set_msix(dev_info_t *dip, ddi_intr_msix_t *msix_p);
222 
223 int32_t i_ddi_get_intr_weight(dev_info_t *);
224 int32_t i_ddi_set_intr_weight(dev_info_t *, int32_t);
225 
226 #define	DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, func, arg1, arg2) \
227 	hdlp->ih_cb_func = func; \
228 	hdlp->ih_cb_arg1 = arg1; \
229 	hdlp->ih_cb_arg2 = arg2;
230 
231 #else	/* _KERNEL */
232 
233 typedef struct devinfo_intr devinfo_intr_t;
234 
235 #endif	/* _KERNEL */
236 
237 /*
238  * Used only by old DDI interrupt interfaces.
239  */
240 
241 /*
242  * This structure represents one interrupt possible from the given
243  * device. It is used in an array for devices with multiple interrupts.
244  */
245 struct intrspec {
246 	uint_t intrspec_pri;		/* interrupt priority */
247 	uint_t intrspec_vec;		/* vector # (0 if none) */
248 	uint_t (*intrspec_func)();	/* function to call for interrupt, */
249 					/* If (uint_t (*)()) 0, none. */
250 					/* If (uint_t (*)()) 1, then */
251 };
252 
253 #ifdef _KERNEL
254 
255 /*
256  * NOTE:
257  *	The following 4 busops entry points are obsoleted with version
258  *	9 or greater. Use i_ddi_intr_op interface in place of these
259  *	obsolete interfaces.
260  *
261  *	Remove these busops entry points and all related data structures
262  *	in future minor/major solaris release.
263  */
264 typedef enum {DDI_INTR_CTLOPS_NONE} ddi_intr_ctlop_t;
265 
266 /* The following are the obsolete interfaces */
267 ddi_intrspec_t	i_ddi_get_intrspec(dev_info_t *dip, dev_info_t *rdip,
268 	    uint_t inumber);
269 
270 int	i_ddi_add_intrspec(dev_info_t *dip, dev_info_t *rdip,
271 	    ddi_intrspec_t intrspec, ddi_iblock_cookie_t *iblock_cookiep,
272 	    ddi_idevice_cookie_t *idevice_cookiep,
273 	    uint_t (*int_handler)(caddr_t int_handler_arg),
274 	    caddr_t int_handler_arg, int kind);
275 
276 void	i_ddi_remove_intrspec(dev_info_t *dip, dev_info_t *rdip,
277 	    ddi_intrspec_t intrspec, ddi_iblock_cookie_t iblock_cookie);
278 
279 int	i_ddi_intr_ctlops(dev_info_t *dip, dev_info_t *rdip,
280 	    ddi_intr_ctlop_t op, void *arg, void *val);
281 
282 #endif	/* _KERNEL */
283 
284 #ifdef	__cplusplus
285 }
286 #endif
287 
288 #endif	/* _SYS_DDI_INTR_IMPL_H */
289