xref: /titanic_50/usr/src/uts/common/sys/devops.h (revision ae115bc77f6fcde83175c75b4206dc2e50747966)
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_DEVOPS_H
28 #define	_SYS_DEVOPS_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"	/* SVr4.0 */
31 
32 #include <sys/types.h>
33 #include <sys/cred.h>
34 #include <sys/uio.h>
35 #include <sys/buf.h>
36 #include <sys/poll.h>
37 #include <vm/as.h>
38 
39 #include <sys/dditypes.h>
40 #include <sys/ddidmareq.h>
41 #include <sys/ddimapreq.h>
42 #include <sys/ddipropdefs.h>
43 #include <sys/ddidevmap.h>
44 #include <sys/ddifm.h>
45 #include <sys/nexusdefs.h>
46 #include <sys/ddi_intr.h>
47 #include <sys/aio_req.h>
48 #include <vm/page.h>
49 
50 #ifdef	__cplusplus
51 extern "C" {
52 #endif
53 
54 #ifdef	_KERNEL
55 
56 /*
57  * cb_ops:	Leaf device drivers or bus nexus drivers supporting
58  *		direct user process access (open/close/etc).
59  *
60  * This is an OR of cdevsw and bdevsw fields for drivers that
61  * support both character and block entry points.
62  *
63  * For streams stuff, see also sys/stream.h.
64  *
65  * The following DDI/DKI or DKI only or DDI only functions are
66  * provided in the character/block driver operations structure.
67  *
68  *	block/char	Function	description
69  *	b/c		XXopen		DDI/DKI
70  *	b/c		XXclose		DDI/DKI
71  *	b		XXstrategy	DDI/DKI
72  *	b  		XXprint		DDI/DKI
73  *	b  		XXdump		DDI(Sun)
74  *	  c		XXread		DDI/DKI
75  *	  c		XXwrite		DDI/DKI
76  *	  c		XXioctl		DDI/DKI
77  *	  c		XXdevmap	DDI(Sun)
78  *	  c		XXmmap		DKI
79  *	  c		XXsegmap	DKI
80  *	  c		XXchpoll	DDI/DKI
81  *	  c		XXprop_op	DDI(Sun)
82  */
83 
84 struct cb_ops  {
85 	int	(*cb_open)(dev_t *devp, int flag, int otyp, cred_t *credp);
86 	int	(*cb_close)(dev_t dev, int flag, int otyp, cred_t *credp);
87 	int	(*cb_strategy)(struct buf *bp);
88 	int	(*cb_print)(dev_t dev, char *str);
89 	int	(*cb_dump)(dev_t dev, caddr_t addr, daddr_t blkno, int nblk);
90 	int	(*cb_read)(dev_t dev, struct uio *uiop, cred_t *credp);
91 	int	(*cb_write)(dev_t dev, struct uio *uiop, cred_t *credp);
92 	int	(*cb_ioctl)(dev_t dev, int cmd, intptr_t arg, int mode,
93 		    cred_t *credp, int *rvalp);
94 	int	(*cb_devmap)(dev_t dev, devmap_cookie_t dhp, offset_t off,
95 			size_t len, size_t *maplen, uint_t model);
96 	int	(*cb_mmap)(dev_t dev, off_t off, int prot);
97 	int	(*cb_segmap)(dev_t dev, off_t off, struct as *asp,
98 		    caddr_t *addrp, off_t len, unsigned int prot,
99 		    unsigned int maxprot, unsigned int flags, cred_t *credp);
100 	int	(*cb_chpoll)(dev_t dev, short events, int anyyet,
101 		    short *reventsp, struct pollhead **phpp);
102 	int	(*cb_prop_op)(dev_t dev, dev_info_t *dip,
103 		    ddi_prop_op_t prop_op, int mod_flags,
104 		    char *name, caddr_t valuep, int *length);
105 
106 	struct streamtab *cb_str;	/* streams information */
107 
108 	/*
109 	 * The cb_flag fields are here to tell the system a
110 	 * bit about the device. The bit definitions are
111 	 * in <sys/conf.h>.
112 	 */
113 	int	cb_flag;		/* driver compatibility flag */
114 	int	cb_rev;			/* cb_ops version number */
115 	int	(*cb_aread)(dev_t dev, struct aio_req *aio, cred_t *credp);
116 	int	(*cb_awrite)(dev_t dev, struct aio_req *aio, cred_t *credp);
117 };
118 
119 /*
120  * bus_ops:	bus nexus drivers only.
121  *
122  * These functions are used to implement the Sun DDI functions
123  * described elsewhere.
124  *
125  * Only nexus drivers support these entry points.
126  *
127  * The following bus nexus functions are provided in the bus nexus
128  * driver operations structure.  Note that all functions take both
129  * their dip and the requesters dip except for the child functions since
130  * they will be called from outside the ddi.
131  *
132  *	bus_map			-  Map/unmap/control IU -> device mappings.
133  *	bus_get_intrspec	-  get interrupt specification by number
134  *	bus_add_intrspec	-  add interrupt specification, return cookie
135  *	bus_remove_intrspec	-  remove interrupt specification
136  *	bus_map_fault		-  bus fault handler
137  *	bus_dma_map		-  setup dma mapping
138  *	bus_dma_mapctl		-  control (and free) dma mapping
139  *	bus_ctl			-  generic control operations
140  *	bus_prop_op		_  request for property
141  */
142 
143 #define	BUSO_REV_3	3
144 #define	BUSO_REV_4	4
145 #define	BUSO_REV_5	5
146 #define	BUSO_REV_6	6
147 #define	BUSO_REV_7	7
148 #define	BUSO_REV_8	8
149 #define	BUSO_REV_9	9
150 #define	BUSO_REV	BUSO_REV_9
151 
152 
153 struct bus_ops  {
154 	int		busops_rev;	/* rev of this structure */
155 	int		(*bus_map)(dev_info_t *dip, dev_info_t *rdip,
156 			    ddi_map_req_t *mp, off_t offset, off_t len,
157 			    caddr_t *vaddrp);
158 
159 	/*
160 	 * NOTE: the following 3 busops entrypoints are obsoleted with
161 	 * version 9 or greater. Use bus_intr_op interface in place of
162 	 * these obsolete interfaces.
163 	 */
164 	ddi_intrspec_t	(*bus_get_intrspec)(dev_info_t *dip, dev_info_t *rdip,
165 			    uint_t inumber);
166 	int		(*bus_add_intrspec)(dev_info_t *dip,
167 			    dev_info_t *rdip, ddi_intrspec_t intrspec,
168 			    ddi_iblock_cookie_t *ibcp,
169 			    ddi_idevice_cookie_t *idcp,
170 			    uint_t (*int_handler)(caddr_t intr_handler_arg),
171 			    caddr_t intr_handler_arg, int kind);
172 	void		(*bus_remove_intrspec)(dev_info_t *dip,
173 			    dev_info_t *rdip, ddi_intrspec_t intrspec,
174 			    ddi_iblock_cookie_t iblock_cookie);
175 
176 	int		(*bus_map_fault)(dev_info_t *dip, dev_info_t *rdip,
177 			    struct hat *hat, struct seg *seg, caddr_t addr,
178 			    struct devpage *dp, pfn_t pfn, uint_t prot,
179 			    uint_t lock);
180 	int		(*bus_dma_map)(dev_info_t *dip, dev_info_t *rdip,
181 			    struct ddi_dma_req *dmareq,
182 			    ddi_dma_handle_t *handlep);
183 	int		(*bus_dma_allochdl)(dev_info_t *dip, dev_info_t *rdip,
184 			    ddi_dma_attr_t *attr, int (*waitfp)(caddr_t),
185 			    caddr_t arg, ddi_dma_handle_t *handlep);
186 	int		(*bus_dma_freehdl)(dev_info_t *dip, dev_info_t *rdip,
187 			    ddi_dma_handle_t handle);
188 	int		(*bus_dma_bindhdl)(dev_info_t *dip, dev_info_t *rdip,
189 			    ddi_dma_handle_t handle, struct ddi_dma_req *dmareq,
190 			    ddi_dma_cookie_t *, uint_t *);
191 	int		(*bus_dma_unbindhdl)(dev_info_t *dip, dev_info_t *rdip,
192 			    ddi_dma_handle_t handle);
193 	int		(*bus_dma_flush)(dev_info_t *dip, dev_info_t *rdip,
194 			    ddi_dma_handle_t handle, off_t off,
195 			    size_t len, uint_t cache_flags);
196 	int		(*bus_dma_win)(dev_info_t *dip, dev_info_t *rdip,
197 			    ddi_dma_handle_t handle, uint_t win, off_t *offp,
198 			    size_t *lenp, ddi_dma_cookie_t *cookiep,
199 			    uint_t *ccountp);
200 	int		(*bus_dma_ctl)(dev_info_t *dip, dev_info_t *rdip,
201 			    ddi_dma_handle_t handle,
202 			    enum ddi_dma_ctlops request, off_t *offp,
203 			    size_t *lenp, caddr_t *objp, uint_t flags);
204 	int		(*bus_ctl)(dev_info_t *dip, dev_info_t *rdip,
205 			    ddi_ctl_enum_t ctlop, void *arg, void *result);
206 	int		(*bus_prop_op)(dev_t dev, dev_info_t *dip,
207 			    dev_info_t *child_dip, ddi_prop_op_t prop_op,
208 			    int mod_flags, char *name, caddr_t valuep,
209 			    int *length);
210 	/*
211 	 * NOTE: the following 4 busops entrypoints are only available
212 	 * with version 3 or greater.  Due to interface modifications, these
213 	 * entrypoints can only be used with version 6 or greater.
214 	 */
215 
216 	int		(*bus_get_eventcookie)(dev_info_t *dip,
217 			    dev_info_t *rdip, char *eventname,
218 			    ddi_eventcookie_t *cookiep);
219 	int		(*bus_add_eventcall)(dev_info_t *dip, dev_info_t *rdip,
220 			    ddi_eventcookie_t eventid,
221 			    void (*event_hdlr)(dev_info_t *dip,
222 			    ddi_eventcookie_t event, void *arg,
223 			    void *bus_impldata), void *arg,
224 			    ddi_callback_id_t *cb_id);
225 	int		(*bus_remove_eventcall)(dev_info_t *devi,
226 			    ddi_callback_id_t cb_id);
227 	int		(*bus_post_event)(dev_info_t *dip, dev_info_t *rdip,
228 			    ddi_eventcookie_t event, void *impl_data);
229 
230 	/*
231 	 * NOTE: the following bus_intr_ctl entrypoint is obsoleted with
232 	 * version 9 or greater. Use bus_intr_op interface in place of
233 	 * this obsolete interface.
234 	 */
235 	int		(*bus_intr_ctl)(dev_info_t *dip, dev_info_t *rdip,
236 			    ddi_intr_ctlop_t ctlop, void * arg, void * result);
237 	/*
238 	 * NOTE: the following busop entrypoints are available with version
239 	 * 5 or greater.
240 	 */
241 	int		(*bus_config)(dev_info_t *parent, uint_t flags,
242 			    ddi_bus_config_op_t op, void *arg,
243 			    dev_info_t **childp);
244 	int		(*bus_unconfig)(dev_info_t *parent, uint_t flags,
245 			    ddi_bus_config_op_t op, void *arg);
246 
247 	/*
248 	 * NOTE: the following busop entrypoints are available with version
249 	 * 6 or greater.
250 	 */
251 	int		(*bus_fm_init)(dev_info_t *dip, dev_info_t *tdip,
252 			    int cap, ddi_iblock_cookie_t *ibc);
253 	void		(*bus_fm_fini)(dev_info_t *dip, dev_info_t *tdip);
254 	void		(*bus_fm_access_enter)(dev_info_t *dip,
255 			    ddi_acc_handle_t handle);
256 	void		(*bus_fm_access_exit)(dev_info_t *dip,
257 			    ddi_acc_handle_t handle);
258 
259 	/*
260 	 * NOTE: the following busop entrypoint is available with version
261 	 * 7 or greater.
262 	 */
263 	int		(*bus_power)(dev_info_t *dip, void *impl_arg,
264 			    pm_bus_power_op_t op, void *arg, void *result);
265 
266 	/*
267 	 * NOTE: the following busop entrypoint is available with version
268 	 * 9 or greater.
269 	 */
270 	int		(*bus_intr_op)(dev_info_t *dip, dev_info_t *rdip,
271 			    ddi_intr_op_t op, ddi_intr_handle_impl_t *hdlp,
272 			    void *result);
273 };
274 
275 /*
276  * REV 1 bus ops structure
277  */
278 
279 struct bus_ops_rev1 {
280 	int		(*bus_map)(dev_info_t *dip, dev_info_t *rdip,
281 			    ddi_map_req_t *mp, off_t offset, off_t len,
282 			    caddr_t *vaddrp);
283 	ddi_intrspec_t	(*bus_get_intrspec)(dev_info_t *dip, dev_info_t *rdip,
284 			    uint_t inumber);
285 	int		(*bus_add_intrspec)(dev_info_t *dip,
286 			    dev_info_t *rdip, ddi_intrspec_t intrspec,
287 			    ddi_iblock_cookie_t *ibcp,
288 			    ddi_idevice_cookie_t *idcp,
289 			    uint_t (*int_handler)(caddr_t intr_handler_arg),
290 			    caddr_t intr_handler_arg, int kind);
291 	void		(*bus_remove_intrspec)(dev_info_t *dip,
292 			    dev_info_t *rdip, ddi_intrspec_t intrspec,
293 			    ddi_iblock_cookie_t iblock_cookie);
294 	int		(*bus_map_fault)(dev_info_t *dip, dev_info_t *rdip,
295 			    struct hat *hat, struct seg *seg, caddr_t addr,
296 			    struct devpage *dp, pfn_t pfn, uint_t prot,
297 			    uint_t lock);
298 	int		(*bus_dma_map)(dev_info_t *dip, dev_info_t *rdip,
299 			    struct ddi_dma_req *dmareq,
300 			    ddi_dma_handle_t *handlep);
301 	int		(*bus_dma_ctl)(dev_info_t *dip, dev_info_t *rdip,
302 			    ddi_dma_handle_t handle,
303 			    enum ddi_dma_ctlops request, off_t *offp,
304 			    uint_t *lenp, caddr_t *objp, uint_t flags);
305 	int		(*bus_ctl)(dev_info_t *dip, dev_info_t *rdip,
306 			    ddi_ctl_enum_t ctlop, void *arg, void *result);
307 	int		(*bus_prop_op)(dev_t dev, dev_info_t *dip,
308 			    dev_info_t *child_dip, ddi_prop_op_t prop_op,
309 			    int mod_flags, char *name, caddr_t valuep,
310 			    int *length);
311 };
312 
313 /*
314  * dev_ops:	Contains driver common fields and pointers
315  *		to the bus_ops and/or cb_ops parts.
316  *
317  * Drivers should set devo_rev to DEVO_REV at compile time.
318  * All drivers should support these entry points.
319  *
320  * the following device functions are provided in the device operations
321  * structure.
322  *
323  *	devo_getinfo		-  Device handle conversion
324  *	devo_identify		-  Obsolete, set to nulldev
325  *	devo_probe		-  Probe for device's existence
326  *	devo_attach		-  Attach driver to dev_info
327  *	devo_detach		-  Detach/prepare driver to unload
328  *	devo_reset		-  Reset device
329  */
330 
331 #define		DEVO_REV		3
332 #define		CB_REV			1
333 
334 /*
335  * Return from driver's devo_probe function:
336  */
337 
338 #define	DDI_PROBE_FAILURE	ENXIO	/* matches nodev return */
339 #define	DDI_PROBE_DONTCARE	0	/* matches nulldev return */
340 #define	DDI_PROBE_PARTIAL	1
341 #define	DDI_PROBE_SUCCESS	2
342 
343 /*
344  * Typedefs for the info, attach, detach and reset routines.
345  * These are mostly placeholders for now.
346  *
347  * NOTE: DDI_INFO_DEVT2DEVINFO is deprecated
348  */
349 typedef enum {
350 	DDI_INFO_DEVT2DEVINFO = 0,	/* Convert a dev_t to a dev_info_t */
351 	DDI_INFO_DEVT2INSTANCE = 1	/* Convert a dev_t to an instance # */
352 } ddi_info_cmd_t;
353 
354 typedef enum {
355 	DDI_ATTACH = 0,
356 	DDI_RESUME = 1,
357 	DDI_PM_RESUME = 2
358 } ddi_attach_cmd_t;
359 
360 typedef enum {
361 	DDI_DETACH = 0,
362 	DDI_SUSPEND = 1,
363 	DDI_PM_SUSPEND = 2,
364 	DDI_HOTPLUG_DETACH = 3		/* detach, don't try to auto-unconfig */
365 } ddi_detach_cmd_t;
366 
367 typedef enum {
368 	DDI_RESET_FORCE = 0
369 } ddi_reset_cmd_t;
370 
371 
372 struct dev_ops  {
373 	int		devo_rev;	/* Driver build version		*/
374 	int		devo_refcnt;	/* device reference count	*/
375 
376 	int		(*devo_getinfo)(dev_info_t *dip,
377 			    ddi_info_cmd_t infocmd, void *arg, void **result);
378 	int		(*devo_identify)(dev_info_t *dip);
379 	int		(*devo_probe)(dev_info_t *dip);
380 	int		(*devo_attach)(dev_info_t *dip, ddi_attach_cmd_t cmd);
381 	int		(*devo_detach)(dev_info_t *dip, ddi_detach_cmd_t cmd);
382 	int		(*devo_reset)(dev_info_t *dip, ddi_reset_cmd_t cmd);
383 
384 	struct cb_ops	*devo_cb_ops;	/* cb_ops pointer for leaf drivers   */
385 	struct bus_ops	*devo_bus_ops;	/* bus_ops pointer for nexus drivers */
386 	int		(*devo_power)(dev_info_t *dip, int component,
387 			    int level);
388 };
389 
390 /*
391  * Create a dev_ops suitable for a streams driver:
392  *
393  * XXX: Note:  Since this is a macro, it is NOT supported as
394  * XXX: part of the Sun DDI.  It is not a documented Sun DDI interface.
395  *
396  * STR_OPS(name, identify, probe, attach, detach, reset,
397  *	info, flag, stream_tab);
398  *
399  *	XXname is the name of the dev_ops structure.
400  *	XXidentify must be set to nulldev
401  *	XXprobe is the name of the probe routine, or nulldev
402  *	XXattach is the name of the attach routine
403  *	XXdetach is the name of the detach routine, or nodev
404  *	XXreset is the name of the reset routine, or nodev
405  *	XXinfo is the name of the info routine
406  *	XXflag is driver flag (cb_flag) in cb_ops,
407  *	XXstream_tab is the obvious.
408  *	cb_##XXname is the name of the internally defined cb_ops struct.
409  *
410  * uses cb_XXname as name of static cb_ops structure.
411  */
412 
413 /*
414  * This file is included by genassym.c now and I couldn't get it to take the
415  * next line if it was broken into two lines joined by a '\'.  So, don't try
416  * to reformat it to satisfy Cstyle because genassym.c won't compile.
417  */
418 /* CSTYLED */
419 #define	DDI_DEFINE_STREAM_OPS(XXname, XXidentify, XXprobe, XXattach, XXdetach, XXreset, XXgetinfo, XXflag, XXstream_tab) \
420 static struct cb_ops cb_##XXname = {					\
421 	nulldev,		/* cb_open */				\
422 	nulldev,		/* cb_close */				\
423 	nodev,			/* cb_strategy */			\
424 	nodev,			/* cb_print */				\
425 	nodev,			/* cb_dump */				\
426 	nodev,			/* cb_read */				\
427 	nodev,			/* cb_write */				\
428 	nodev,			/* cb_ioctl */				\
429 	nodev,			/* cb_devmap */				\
430 	nodev,			/* cb_mmap */				\
431 	nodev,			/* cb_segmap */				\
432 	nochpoll,		/* cb_chpoll */				\
433 	ddi_prop_op,		/* cb_prop_op */			\
434 	(XXstream_tab),		/* cb_stream */				\
435 	(int)(XXflag),		/* cb_flag */				\
436 	CB_REV,			/* cb_rev */				\
437 	nodev,			/* cb_aread */				\
438 	nodev,			/* cb_awrite */				\
439 };									\
440 									\
441 static struct dev_ops XXname = {					\
442 	DEVO_REV,		/* devo_rev */				\
443 	0,			/* devo_refcnt */			\
444 	(XXgetinfo),		/* devo_getinfo */			\
445 	(XXidentify),		/* devo_identify */			\
446 	(XXprobe),		/* devo_probe */			\
447 	(XXattach),		/* devo_attach */			\
448 	(XXdetach),		/* devo_detach */			\
449 	(XXreset),		/* devo_reset */			\
450 	&(cb_##XXname),		/* devo_cb_ops */			\
451 	(struct bus_ops *)NULL,	/* devo_bus_ops */			\
452 	NULL			/* devo_power */			\
453 }
454 
455 #endif	/* _KERNEL */
456 
457 #ifdef	__cplusplus
458 }
459 #endif
460 
461 #endif	/* _SYS_DEVOPS_H */
462