xref: /illumos-gate/usr/src/uts/common/sys/dditypes.h (revision a4955f4fa65e38d70c07d38e657a9aff43fa155f)
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 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  * Copyright 2022 Tintri by DDN, Inc. All rights reserved.
26  */
27 
28 #ifndef	_SYS_DDITYPES_H
29 #define	_SYS_DDITYPES_H
30 
31 #include <sys/isa_defs.h>
32 #ifndef	_ASM
33 #include <sys/types.h>
34 #endif
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 #ifndef	_ASM
41 /*
42  * DMA types
43  *
44  * A DMA handle represent a "DMA object".  A DMA object is an abstraction
45  * that represents the potential source or destination of DMA transfers to
46  * or from a device.  The DMA object is the highest level description of
47  * the source or destination and is not suitable for the actual transfer.
48  *
49  * Note, that we avoid the specific references to "mapping". The fact that
50  * a transfer requires mapping is an artifact of the specific architectural
51  * implementation.
52  */
53 typedef	struct __ddi_dma_handle *ddi_dma_handle_t;
54 
55 /*
56  * A dma window type represents a "DMA window".  A DMA window is a portion
57  * of a dma object or might be the entire object. A DMA window has had system
58  * resources allocated to it and is prepared to be transferred into or
59  * out of. Examples of system resources are DVMA mapping resources and
60  * intermediate transfer buffer resources.
61  *
62  */
63 typedef	struct __ddi_dma_win *ddi_dma_win_t;
64 
65 
66 /*
67  * A dma segment type represents a "DMA segment".  A dma segment is a
68  * contiguous portion of a DMA window which is entirely addressable by the
69  * device for a transfer operation.  One example where DMA segments are
70  * required is where the system does not contain DVMA capability and
71  * the object or window may be non-contiguous.  In this example the
72  * object or window will be broken into smaller contiguous segments.
73  * Another example is where a device or some intermediary bus adapter has
74  * some upper limit on its transfer size (i.e. an 8-bit address register).
75  * In this example the object or window will be broken into smaller
76  * addressable segments.
77  */
78 typedef	struct __ddi_dma_seg *ddi_dma_seg_t;
79 
80 /*
81  * A DMA cookie contains DMA address information required to
82  * program a DMA engine
83  */
84 typedef struct {
85 	union {
86 		uint64_t	_dmac_ll;	/* 64 bit DMA address */
87 		uint32_t	_dmac_la[2];	/* 2 x 32 bit address */
88 	} _dmu;
89 	size_t		dmac_size;	/* DMA cookie size */
90 	uint_t		dmac_type;	/* bus specific type bits */
91 } ddi_dma_cookie_t;
92 
93 #define	dmac_laddress	_dmu._dmac_ll
94 #ifdef _LONG_LONG_HTOL
95 #define	dmac_notused    _dmu._dmac_la[0]
96 #define	dmac_address    _dmu._dmac_la[1]
97 #else
98 #define	dmac_address	_dmu._dmac_la[0]
99 #define	dmac_notused	_dmu._dmac_la[1]
100 #endif
101 
102 /*
103  * Interrupt types
104  */
105 
106 /*
107  * Both ddi_iblock_cookie_t and ddi_idevice_cookie_t are
108  * obsolete data structures.
109  *
110  * lock initialization type
111  */
112 typedef struct __ddi_iblock_cookie *ddi_iblock_cookie_t;
113 typedef union {
114 	struct {
115 		ushort_t	_idev_vector;	/* vector - bus dependent */
116 		ushort_t	_idev_priority;	/* priority - bus dependent */
117 	} idu;
118 	uint_t	idev_softint;	/* Soft interrupt register bit(s) */
119 } ddi_idevice_cookie_t;
120 #define	idev_vector	idu._idev_vector
121 #define	idev_priority	idu._idev_priority
122 
123 /*
124  * register specification
125  */
126 typedef struct __ddi_regspec *ddi_regspec_t;
127 
128 /*
129  * interrupt specification
130  */
131 typedef struct __ddi_intrspec *ddi_intrspec_t;
132 
133 /*
134  * ddi_softintr_t is an obsolete data structure.
135  *
136  * soft interrupt id
137  */
138 typedef struct __ddi_softintr *ddi_softintr_t;
139 
140 /*
141  * opaque device info handle
142  */
143 typedef struct __dev_info *dev_info_t;
144 
145 /*
146  * Mapping cookie for devmap(9E)
147  */
148 typedef struct __ddi_devmap_data *ddi_devmap_data_t;
149 
150 /*
151  * Opaque Device id
152  */
153 typedef struct __ddi_devid *ddi_devid_t;
154 
155 /*
156  * Device id types
157  */
158 #define	DEVID_NONE		0
159 #define	DEVID_SCSI3_WWN		1
160 #define	DEVID_SCSI_SERIAL	2
161 #define	DEVID_FAB		3
162 #define	DEVID_ENCAP		4
163 #define	DEVID_ATA_SERIAL	5
164 #define	DEVID_SCSI3_VPD_T10	6
165 #define	DEVID_SCSI3_VPD_EUI	7
166 #define	DEVID_SCSI3_VPD_NAA	8
167 #define	DEVID_NVME_NSID		9
168 #define	DEVID_NVME_EUI64	10
169 #define	DEVID_NVME_NGUID	11
170 #define	DEVID_MAXTYPE		11
171 
172 /*
173  * Device id scsi encode versions (version of encode interface, not devid)
174  */
175 #define	DEVID_SCSI_ENCODE_VERSION1		0
176 #define	DEVID_SCSI_ENCODE_VERSION2		1
177 #define	DEVID_SCSI_ENCODE_VERSION_LATEST	DEVID_SCSI_ENCODE_VERSION2
178 
179 /*
180  * Device id smp encode versions (version of encode interface, not devid)
181  */
182 #define	DEVID_SMP_ENCODE_VERSION1		0
183 #define	DEVID_SMP_ENCODE_VERSION_LATEST		DEVID_SMP_ENCODE_VERSION1
184 
185 /* minor name values for devid lookup interfaces */
186 #define	DEVID_MINOR_NAME_ALL		((char *)0)
187 #define	DEVID_MINOR_NAME_ALL_CHR	((char *)1)
188 #define	DEVID_MINOR_NAME_ALL_BLK	((char *)2)
189 
190 /*
191  * Define ddi_devmap_cmd types. This should probably be elsewhere.
192  */
193 typedef enum {
194 	DDI_DEVMAP_VALIDATE = 0		/* Check mapping, but do nothing */
195 } ddi_devmap_cmd_t;
196 
197 /*
198  * Definitions for node state.
199  *
200  * NOTE: DS_ATTACHED and DS_READY should only be used by the devcfg.c state
201  * model code itself, other code should use i_ddi_devi_attached() to avoid
202  * logic errors associated with transient DS_READY->DS_ATTACHED->DS_READY
203  * state changes while the node is attached.
204  */
205 typedef enum {
206 	DS_INVAL = -1,
207 	DS_PROTO = 0,
208 	DS_LINKED,	/* in orphan list */
209 	DS_BOUND,	/* in per-driver list */
210 	DS_INITIALIZED, /* bus address assigned */
211 	DS_PROBED,	/* device known to exist */
212 	DS_ATTACHED,	/* don't use, see NOTE above: driver attached */
213 	DS_READY	/* don't use, see NOTE above: post attach complete */
214 } ddi_node_state_t;
215 
216 /*
217  * NDI Event Service
218  */
219 typedef enum {EPL_KERNEL, EPL_INTERRUPT, EPL_HIGHLEVEL} ddi_plevel_t;
220 typedef struct ddi_event_cookie *ddi_eventcookie_t;
221 typedef struct ddi_event_callbacks *ddi_callback_id_t;
222 
223 #endif	/* !_ASM */
224 
225 #ifdef	_KERNEL
226 #ifndef _ASM
227 
228 /*
229  * Device Access Attributes
230  */
231 
232 typedef struct ddi_device_acc_attr {
233 	ushort_t devacc_attr_version;
234 	uchar_t devacc_attr_endian_flags;
235 	uchar_t devacc_attr_dataorder;
236 	uchar_t devacc_attr_access;		/* access error protection */
237 } ddi_device_acc_attr_t;
238 
239 #define	DDI_DEVICE_ATTR_V0	0x0001
240 #define	DDI_DEVICE_ATTR_V1	0x0002
241 
242 /*
243  * endian-ness flags
244  */
245 #define	 DDI_NEVERSWAP_ACC	0x00
246 #define	 DDI_STRUCTURE_LE_ACC	0x01
247 #define	 DDI_STRUCTURE_BE_ACC	0x02
248 
249 /*
250  * Data ordering values
251  */
252 #define	DDI_STRICTORDER_ACC	0x00
253 #define	DDI_UNORDERED_OK_ACC    0x01
254 #define	DDI_MERGING_OK_ACC	0x02
255 #define	DDI_LOADCACHING_OK_ACC  0x03
256 #define	DDI_STORECACHING_OK_ACC 0x04
257 
258 /*
259  * Data size
260  */
261 #define	DDI_DATA_SZ01_ACC	1
262 #define	DDI_DATA_SZ02_ACC	2
263 #define	DDI_DATA_SZ04_ACC	4
264 #define	DDI_DATA_SZ08_ACC	8
265 
266 /*
267  * Data Access Handle
268  */
269 #define	VERS_ACCHDL			0x0001
270 
271 typedef struct __ddi_acc_handle *ddi_acc_handle_t;
272 
273 typedef struct ddi_acc_hdl {
274 	int	ah_vers;		/* version number */
275 	void	*ah_bus_private;	/* bus private pointer */
276 	void	*ah_platform_private;	/* platform private pointer */
277 	dev_info_t *ah_dip;		/* requesting device */
278 
279 	uint_t	ah_rnumber;		/* register number */
280 	caddr_t	ah_addr;		/* address of mapping */
281 
282 	off_t	ah_offset;		/* offset of mapping */
283 	off_t	ah_len;			/* length of mapping */
284 	uint_t	ah_hat_flags;		/* hat flags used to map object */
285 	pfn_t	ah_pfn;			/* physical page frame number */
286 	uint_t	ah_pnum;		/* number of contiguous pages */
287 	ulong_t	ah_xfermodes;		/* data transfer modes, etc */
288 	ddi_device_acc_attr_t ah_acc;	/* device access attributes */
289 } ddi_acc_hdl_t;
290 
291 /*
292  * Used by DDI_CTLOPS_POKE and DDI_CTLOPS_PEEK for peek/poke and cautious acc
293  */
294 typedef struct {
295 	size_t			size;
296 	uintptr_t		dev_addr;
297 	uintptr_t		host_addr;
298 	ddi_acc_handle_t	handle;
299 	size_t			repcount;
300 	uint_t			flags;
301 } peekpoke_ctlops_t;
302 
303 /*
304  * Used by the high resolution timeout functions
305  */
306 typedef struct __ddi_periodic *ddi_periodic_t;
307 
308 #endif	/* !_ASM */
309 
310 /*
311  * devacc_attr_access error protection types
312  */
313 #define	DDI_DEFAULT_ACC		0x01	/* take default action */
314 #define	DDI_FLAGERR_ACC		0x02	/* protected against access faults */
315 #define	DDI_CAUTIOUS_ACC	0x03	/* high protection against faults */
316 
317 #endif	/* _KERNEL */
318 
319 #ifdef	__cplusplus
320 }
321 #endif
322 
323 #endif	/* _SYS_DDITYPES_H */
324