xref: /titanic_41/usr/src/uts/intel/sys/iommulib.h (revision cc1a9a89a73172cc2db053635fab3b1b91691657)
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 2008 Sun Microsystems, Inc.  All rights reserved.
23  * Use is subject to license terms.
24  */
25 
26 #ifndef	_SYS_IOMMULIB_H
27 #define	_SYS_IOMMULIB_H
28 
29 #pragma ident	"@(#)iommulib.h	1.3	08/08/31 SMI"
30 
31 #ifdef	__cplusplus
32 extern "C" {
33 #endif
34 
35 #include <sys/ddi_impldefs.h>
36 
37 #ifdef	_KERNEL
38 
39 typedef enum {
40 	INVALID_VENDOR = 0,
41 	AMD_IOMMU,
42 	INTEL_IOMMU
43 } iommulib_vendor_t;
44 
45 typedef enum {
46 	IOMMU_OPS_VERSION_INVALID = 0,
47 	IOMMU_OPS_VERSION_1 = 1
48 } iommulib_opsversion_t;
49 
50 #define	IOMMU_OPS_VERSION IOMMU_OPS_VERSION_1
51 
52 typedef struct iommulib_ops {
53 	iommulib_opsversion_t	ilops_vers;
54 	iommulib_vendor_t	ilops_vendor;
55 	char			*ilops_id;
56 	void			*ilops_data;
57 
58 	int	(*ilops_probe)(dev_info_t *rdip);
59 
60 	int	(*ilops_dma_allochdl)(iommulib_handle_t handle,
61 	    dev_info_t *dip, dev_info_t *rdip, ddi_dma_attr_t *attr,
62 	    int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *dma_handlep);
63 
64 	int	(*ilops_dma_freehdl)(iommulib_handle_t handle,
65 	    dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t dma_handle);
66 
67 	int	(*ilops_dma_bindhdl)(iommulib_handle_t handle, dev_info_t *dip,
68 	    dev_info_t *rdip, ddi_dma_handle_t dma_handle,
69 	    struct ddi_dma_req *dmareq, ddi_dma_cookie_t *cookiep,
70 	    uint_t *ccountp);
71 
72 	int	(*ilops_dma_unbindhdl)(iommulib_handle_t handle,
73 	    dev_info_t *dip, dev_info_t *rdip, ddi_dma_handle_t dma_handle);
74 
75 	int	(*ilops_dma_sync)(iommulib_handle_t handle, dev_info_t *dip,
76 	    dev_info_t *rdip, ddi_dma_handle_t dma_handle, off_t off,
77 	    size_t len, uint_t cache_flags);
78 
79 	int	(*ilops_dma_win)(iommulib_handle_t handle, dev_info_t *dip,
80 	    dev_info_t *rdip, ddi_dma_handle_t dma_handle, uint_t win,
81 	    off_t *offp, size_t *lenp, ddi_dma_cookie_t *cookiep,
82 	    uint_t *ccountp);
83 
84 
85 	/* Obsolete DMA routines */
86 
87 	int	(*ilops_dma_map)(iommulib_handle_t handle, dev_info_t *dip,
88 	    dev_info_t *rdip, struct ddi_dma_req *dmareq,
89 	    ddi_dma_handle_t *dma_handle);
90 
91 	int	(*ilops_dma_mctl)(iommulib_handle_t handle, dev_info_t *dip,
92 	    dev_info_t *rdip, ddi_dma_handle_t dma_handle,
93 	    enum ddi_dma_ctlops request, off_t *offp, size_t *lenp,
94 	    caddr_t *objpp, uint_t cache_flags);
95 
96 } iommulib_ops_t;
97 
98 #define	IOMMU_USED(dip)	(DEVI(dip)->devi_iommulib_handle != NULL)
99 
100 typedef enum {
101 	IOMMU_NEXOPS_VERSION_INVALID = 0,
102 	IOMMU_NEXOPS_VERSION_1 = 1
103 } iommulib_nexops_version_t;
104 
105 #define	IOMMU_NEXOPS_VERSION IOMMU_NEXOPS_VERSION_1
106 
107 typedef struct iommulib_nexops {
108 	iommulib_nexops_version_t	nops_vers;
109 	char			*nops_id;
110 	void			*nops_data;
111 
112 	int (*nops_dma_allochdl)(dev_info_t *dip, dev_info_t *rdip,
113 	    ddi_dma_attr_t *attr, int (*waitfp)(caddr_t), caddr_t arg,
114 	    ddi_dma_handle_t *handlep);
115 
116 	int (*nops_dma_freehdl)(dev_info_t *dip, dev_info_t *rdip,
117 	    ddi_dma_handle_t handle);
118 
119 	int (*nops_dma_bindhdl)(dev_info_t *dip, dev_info_t *rdip,
120 	    ddi_dma_handle_t handle, struct ddi_dma_req *dmareq,
121 	    ddi_dma_cookie_t *cookiep, uint_t *ccountp);
122 
123 	int (*nops_dma_unbindhdl)(dev_info_t *dip, dev_info_t *rdip,
124 	    ddi_dma_handle_t handle);
125 
126 	void (*nops_dma_reset_cookies)(dev_info_t *dip,
127 	    ddi_dma_handle_t handle);
128 
129 	int (*nops_dma_get_cookies)(dev_info_t *dip, ddi_dma_handle_t handle,
130 	    ddi_dma_cookie_t *cookiep, uint_t *ccountp);
131 
132 	int (*nops_dma_sync)(dev_info_t *dip, dev_info_t *rdip,
133 	    ddi_dma_handle_t handle, off_t off, size_t len, uint_t cache_flags);
134 
135 	int (*nops_dma_win)(dev_info_t *dip, dev_info_t *rdip,
136 	    ddi_dma_handle_t handle, uint_t win, off_t *offp, size_t *lenp,
137 	    ddi_dma_cookie_t *cookiep, uint_t *ccountp);
138 
139 	int (*nops_dma_map)(dev_info_t *dip, dev_info_t *rdip,
140 	    struct ddi_dma_req *dmareq, ddi_dma_handle_t *handlep);
141 
142 	int (*nops_dma_mctl)(dev_info_t *dip, dev_info_t *rdip,
143 	    ddi_dma_handle_t handle, enum ddi_dma_ctlops request, off_t *offp,
144 	    size_t *lenp, caddr_t *objpp, uint_t cache_flags);
145 } iommulib_nexops_t;
146 
147 struct iommulib_nex;
148 typedef struct iommulib_nex *iommulib_nexhandle_t;
149 
150 /*
151  * Interfaces for nexus drivers - typically rootnex
152  */
153 
154 int iommulib_nexus_register(dev_info_t *dip, iommulib_nexops_t *nexops,
155     iommulib_nexhandle_t *handle);
156 
157 int iommulib_nexus_unregister(iommulib_nexhandle_t handle);
158 
159 int iommulib_nex_open(dev_info_t *rdip, uint_t *errorp);
160 void iommulib_nex_close(dev_info_t *rdip);
161 
162 int iommulib_nexdma_allochdl(dev_info_t *dip, dev_info_t *rdip,
163     ddi_dma_attr_t *attr, int (*waitfp)(caddr_t),
164     caddr_t arg, ddi_dma_handle_t *dma_handlep);
165 
166 int iommulib_nexdma_freehdl(dev_info_t *dip, dev_info_t *rdip,
167     ddi_dma_handle_t dma_handle);
168 
169 int iommulib_nexdma_bindhdl(dev_info_t *dip, dev_info_t *rdip,
170     ddi_dma_handle_t dma_handle, struct ddi_dma_req *dmareq,
171     ddi_dma_cookie_t *cookiep, uint_t *ccountp);
172 
173 int iommulib_nexdma_unbindhdl(dev_info_t *dip, dev_info_t *rdip,
174     ddi_dma_handle_t dma_handle);
175 
176 int iommulib_nexdma_sync(dev_info_t *dip, dev_info_t *rdip,
177     ddi_dma_handle_t dma_handle, off_t off, size_t len,
178     uint_t cache_flags);
179 
180 int iommulib_nexdma_win(dev_info_t *dip, dev_info_t *rdip,
181     ddi_dma_handle_t dma_handle, uint_t win, off_t *offp, size_t *lenp,
182     ddi_dma_cookie_t *cookiep, uint_t *ccountp);
183 
184 int iommulib_nexdma_map(dev_info_t *dip, dev_info_t *rdip,
185     struct ddi_dma_req *dmareq, ddi_dma_handle_t *dma_handle);
186 
187 int iommulib_nexdma_mctl(dev_info_t *dip, dev_info_t *rdip,
188     ddi_dma_handle_t dma_handle, enum ddi_dma_ctlops request,
189     off_t *offp, size_t *lenp, caddr_t *objpp, uint_t cache_flags);
190 
191 /*
192  * Interfaces for IOMMU drivers provided by IOMMULIB
193  */
194 
195 int iommulib_iommu_register(dev_info_t *dip, iommulib_ops_t *ops,
196     iommulib_handle_t *handle);
197 
198 int iommulib_iommu_unregister(iommulib_handle_t handle);
199 
200 int iommulib_iommu_getunitid(iommulib_handle_t handle, uint64_t *unitidp);
201 
202 dev_info_t *iommulib_iommu_getdip(iommulib_handle_t handle);
203 
204 iommulib_ops_t *iommulib_iommu_getops(iommulib_handle_t handle);
205 
206 void *iommulib_iommu_getdata(iommulib_handle_t handle);
207 
208 
209 /* Interfaces for IOMMU drivers provided by NEXUS drivers (typically rootnex) */
210 
211 int iommulib_iommu_dma_allochdl(dev_info_t *dip, dev_info_t *rdip,
212     ddi_dma_attr_t *attr, int (*waitfp)(caddr_t), caddr_t arg,
213     ddi_dma_handle_t *handlep);
214 
215 int iommulib_iommu_dma_freehdl(dev_info_t *dip, dev_info_t *rdip,
216     ddi_dma_handle_t handle);
217 
218 int iommulib_iommu_dma_bindhdl(dev_info_t *dip, dev_info_t *rdip,
219     ddi_dma_handle_t handle, struct ddi_dma_req *dmareq,
220     ddi_dma_cookie_t *cookiep, uint_t *ccountp);
221 
222 int iommulib_iommu_dma_unbindhdl(dev_info_t *dip, dev_info_t *rdip,
223     ddi_dma_handle_t handle);
224 
225 void iommulib_iommu_dma_reset_cookies(dev_info_t *dip, ddi_dma_handle_t handle);
226 
227 int iommulib_iommu_dma_get_cookies(dev_info_t *dip, ddi_dma_handle_t handle,
228     ddi_dma_cookie_t *cookiep, uint_t *ccountp);
229 
230 int iommulib_iommu_dma_sync(dev_info_t *dip, dev_info_t *rdip,
231     ddi_dma_handle_t handle, off_t off, size_t len, uint_t cache_flags);
232 
233 int iommulib_iommu_dma_win(dev_info_t *dip, dev_info_t *rdip,
234     ddi_dma_handle_t handle, uint_t win, off_t *offp, size_t *lenp,
235     ddi_dma_cookie_t *cookiep, uint_t *ccountp);
236 
237 int iommulib_iommu_dma_map(dev_info_t *dip, dev_info_t *rdip,
238     struct ddi_dma_req *dmareq, ddi_dma_handle_t *handlep);
239 
240 int iommulib_iommu_dma_mctl(dev_info_t *dip, dev_info_t *rdip,
241     ddi_dma_handle_t handle, enum ddi_dma_ctlops request, off_t *offp,
242     size_t *lenp, caddr_t *objpp, uint_t cache_flags);
243 
244 #endif	/* _KERNEL */
245 
246 #ifdef	__cplusplus
247 }
248 #endif
249 
250 #endif	/* _SYS_IOMMULIB_H */
251