xref: /titanic_50/usr/src/uts/common/sys/ddi_intr_impl.h (revision 6dfee4834394825da35b977ca71cdc965bc7b6a4)
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		- On X86 it usually carries a pointer to
100 	 *			  ihdl_plat_t.  Not used on SPARC platforms.
101 	 */
102 	void			*ih_private;	/* Platform specific data */
103 	uint_t			ih_scratch1;	/* Scratch1: #interrupts */
104 	uint_t			ih_scratch2;	/* Scratch2: flag */
105 } ddi_intr_handle_impl_t;
106 
107 /* values for ih_state (strictly for interrupt handle) */
108 #define	DDI_IHDL_STATE_ALLOC	0x01	/* Allocated. ddi_intr_alloc() called */
109 #define	DDI_IHDL_STATE_ADDED	0x02	/* Added interrupt handler */
110 					/* ddi_intr_add_handler() called */
111 #define	DDI_IHDL_STATE_ENABLE	0x04	/* Enabled. ddi_intr_enable() called */
112 
113 #define	DDI_INTR_IS_MSI_OR_MSIX(type) \
114 	((type) == DDI_INTR_TYPE_MSI || (type) == DDI_INTR_TYPE_MSIX)
115 
116 #define	DDI_INTR_SUP_TYPES	DDI_INTR_TYPE_FIXED|DDI_INTR_TYPE_MSI|\
117 				DDI_INTR_TYPE_MSIX
118 
119 /*
120  * One such data structure is allocated per ddi_soft_intr_handle
121  * This is the incore copy of the softint info.
122  */
123 typedef struct ddi_softint_hdl_impl {
124 	dev_info_t	*ih_dip;		/* dip associated with handle */
125 	uint_t		ih_pri;			/* priority - bus dependent */
126 	krwlock_t	ih_rwlock;		/* read/write lock per handle */
127 	uint_t		ih_pending;		/* whether softint is pending */
128 
129 	uint_t		(*ih_cb_func)(caddr_t, caddr_t);
130 						/* cb function for soft ints */
131 	void		*ih_cb_arg1;		/* arg1 of callback function */
132 	void		*ih_cb_arg2;		/* arg2 passed to "trigger" */
133 
134 	/*
135 	 * The next member is for 'scratch' purpose only.
136 	 * The DDI interrupt framework uses it internally and its
137 	 * interpretation is left to the framework.
138 	 *	private		- used by the DDI framework to pass back
139 	 *			  and forth 'softid' information on SPARC
140 	 *			  side only. Not used on X86 platform.
141 	 */
142 	void		*ih_private;		/* Platform specific data */
143 } ddi_softint_hdl_impl_t;
144 
145 /* Softint internal implementation defines */
146 #define	DDI_SOFT_INTR_PRI_M	4
147 #define	DDI_SOFT_INTR_PRI_H	6
148 
149 /*
150  * One such data structure is allocated for MSI-X enabled
151  * device. If no MSI-X is enabled then it is NULL
152  */
153 typedef struct ddi_intr_msix {
154 	uint_t			msix_intrs_in_use;	/* MSI-X intrs in use */
155 
156 	/* MSI-X Table related information */
157 	ddi_acc_handle_t	msix_tbl_hdl;		/* MSI-X table handle */
158 	caddr_t			msix_tbl_addr;		/* MSI-X table addr */
159 	offset_t		msix_tbl_offset;	/* MSI-X table offset */
160 
161 	/* MSI-X PBA Table related information */
162 	ddi_acc_handle_t	msix_pba_hdl;		/* MSI-X PBA handle */
163 	caddr_t			msix_pba_addr;		/* MSI-X PBA addr */
164 	offset_t		msix_pba_offset;	/* MSI-X PBA offset */
165 
166 	ddi_device_acc_attr_t	msix_dev_attr;		/* MSI-X device attr */
167 } ddi_intr_msix_t;
168 
169 
170 /*
171  * One such data structure is allocated for each dip.
172  * It has interrupt related information that can be
173  * stored/retrieved for convenience.
174  */
175 typedef struct devinfo_intr {
176 	/* These three fields show what the device is capable of */
177 	uint_t		devi_intr_sup_types;	/* Intrs supported by device */
178 
179 	ddi_intr_msix_t	*devi_msix_p;		/* MSI-X info, if supported */
180 
181 	/* Next three fields show current status for the device */
182 	uint_t		devi_intr_curr_type;	/* Interrupt type being used */
183 	uint_t		devi_intr_sup_nintrs;	/* #intr supported */
184 	uint_t		devi_intr_curr_nintrs;	/* #intr currently being used */
185 
186 	ddi_intr_handle_t **devi_intr_handle_p;	/* Hdl for legacy intr APIs */
187 } devinfo_intr_t;
188 
189 #define	NEXUS_HAS_INTR_OP(dip)	\
190 	((DEVI(dip)->devi_ops->devo_bus_ops) && \
191 	(DEVI(dip)->devi_ops->devo_bus_ops->busops_rev >= BUSO_REV_9) && \
192 	(DEVI(dip)->devi_ops->devo_bus_ops->bus_intr_op))
193 
194 int	i_ddi_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t op,
195 	    ddi_intr_handle_impl_t *hdlp, void *result);
196 
197 int	i_ddi_add_softint(ddi_softint_hdl_impl_t *);
198 void	i_ddi_remove_softint(ddi_softint_hdl_impl_t *);
199 int	i_ddi_trigger_softint(ddi_softint_hdl_impl_t *, void *);
200 int	i_ddi_set_softint_pri(ddi_softint_hdl_impl_t *, uint_t);
201 
202 void	i_ddi_intr_devi_init(dev_info_t *dip);
203 void	i_ddi_intr_devi_fini(dev_info_t *dip);
204 
205 uint_t	i_ddi_intr_get_supported_types(dev_info_t *dip);
206 void	i_ddi_intr_set_supported_types(dev_info_t *dip, int sup_type);
207 uint_t	i_ddi_intr_get_current_type(dev_info_t *dip);
208 void	i_ddi_intr_set_current_type(dev_info_t *dip, int intr_type);
209 uint_t	i_ddi_intr_get_supported_nintrs(dev_info_t *dip, int intr_type);
210 void	i_ddi_intr_set_supported_nintrs(dev_info_t *dip, int nintrs);
211 uint_t	i_ddi_intr_get_current_nintrs(dev_info_t *dip);
212 void	i_ddi_intr_set_current_nintrs(dev_info_t *dip, int nintrs);
213 
214 ddi_intr_handle_t *i_ddi_get_intr_handle(dev_info_t *dip, int inum);
215 void	i_ddi_set_intr_handle(dev_info_t *dip, int inum,
216 	    ddi_intr_handle_t *hdlp);
217 
218 ddi_intr_msix_t	*i_ddi_get_msix(dev_info_t *dip);
219 void	i_ddi_set_msix(dev_info_t *dip, ddi_intr_msix_t *msix_p);
220 
221 int32_t i_ddi_get_intr_weight(dev_info_t *);
222 int32_t i_ddi_set_intr_weight(dev_info_t *, int32_t);
223 
224 void	i_ddi_alloc_intr_phdl(ddi_intr_handle_impl_t *);
225 void	i_ddi_free_intr_phdl(ddi_intr_handle_impl_t *);
226 
227 #define	DDI_INTR_ASSIGN_HDLR_N_ARGS(hdlp, func, arg1, arg2) \
228 	hdlp->ih_cb_func = func; \
229 	hdlp->ih_cb_arg1 = arg1; \
230 	hdlp->ih_cb_arg2 = arg2;
231 
232 #else	/* _KERNEL */
233 
234 typedef struct devinfo_intr devinfo_intr_t;
235 
236 #endif	/* _KERNEL */
237 
238 /*
239  * Used only by old DDI interrupt interfaces.
240  */
241 
242 /*
243  * This structure represents one interrupt possible from the given
244  * device. It is used in an array for devices with multiple interrupts.
245  */
246 struct intrspec {
247 	uint_t intrspec_pri;		/* interrupt priority */
248 	uint_t intrspec_vec;		/* vector # (0 if none) */
249 	uint_t (*intrspec_func)();	/* function to call for interrupt, */
250 					/* If (uint_t (*)()) 0, none. */
251 					/* If (uint_t (*)()) 1, then */
252 };
253 
254 #ifdef _KERNEL
255 
256 /*
257  * NOTE:
258  *	The following 4 busops entry points are obsoleted with version
259  *	9 or greater. Use i_ddi_intr_op interface in place of these
260  *	obsolete interfaces.
261  *
262  *	Remove these busops entry points and all related data structures
263  *	in future minor/major solaris release.
264  */
265 typedef enum {DDI_INTR_CTLOPS_NONE} ddi_intr_ctlop_t;
266 
267 /* The following are the obsolete interfaces */
268 ddi_intrspec_t	i_ddi_get_intrspec(dev_info_t *dip, dev_info_t *rdip,
269 	    uint_t inumber);
270 
271 int	i_ddi_add_intrspec(dev_info_t *dip, dev_info_t *rdip,
272 	    ddi_intrspec_t intrspec, 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, int kind);
276 
277 void	i_ddi_remove_intrspec(dev_info_t *dip, dev_info_t *rdip,
278 	    ddi_intrspec_t intrspec, ddi_iblock_cookie_t iblock_cookie);
279 
280 int	i_ddi_intr_ctlops(dev_info_t *dip, dev_info_t *rdip,
281 	    ddi_intr_ctlop_t op, void *arg, void *val);
282 
283 #endif	/* _KERNEL */
284 
285 #ifdef	__cplusplus
286 }
287 #endif
288 
289 #endif	/* _SYS_DDI_INTR_IMPL_H */
290