xref: /onnv-gate/usr/src/uts/common/sys/devops.h (revision 7656:2621e50fdf4a)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5*7656SSherry.Moore@Sun.COM  * Common Development and Distribution License (the "License").
6*7656SSherry.Moore@Sun.COM  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
210Sstevel@tonic-gate /*
22*7656SSherry.Moore@Sun.COM  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #ifndef	_SYS_DEVOPS_H
270Sstevel@tonic-gate #define	_SYS_DEVOPS_H
280Sstevel@tonic-gate 
290Sstevel@tonic-gate 
300Sstevel@tonic-gate #include <sys/types.h>
310Sstevel@tonic-gate #include <sys/cred.h>
320Sstevel@tonic-gate #include <sys/uio.h>
330Sstevel@tonic-gate #include <sys/buf.h>
340Sstevel@tonic-gate #include <sys/poll.h>
350Sstevel@tonic-gate #include <vm/as.h>
360Sstevel@tonic-gate 
370Sstevel@tonic-gate #include <sys/dditypes.h>
380Sstevel@tonic-gate #include <sys/ddidmareq.h>
390Sstevel@tonic-gate #include <sys/ddimapreq.h>
400Sstevel@tonic-gate #include <sys/ddipropdefs.h>
410Sstevel@tonic-gate #include <sys/ddidevmap.h>
420Sstevel@tonic-gate #include <sys/ddifm.h>
430Sstevel@tonic-gate #include <sys/nexusdefs.h>
440Sstevel@tonic-gate #include <sys/ddi_intr.h>
450Sstevel@tonic-gate #include <sys/aio_req.h>
460Sstevel@tonic-gate #include <vm/page.h>
470Sstevel@tonic-gate 
480Sstevel@tonic-gate #ifdef	__cplusplus
490Sstevel@tonic-gate extern "C" {
500Sstevel@tonic-gate #endif
510Sstevel@tonic-gate 
520Sstevel@tonic-gate #ifdef	_KERNEL
530Sstevel@tonic-gate 
540Sstevel@tonic-gate /*
550Sstevel@tonic-gate  * cb_ops:	Leaf device drivers or bus nexus drivers supporting
560Sstevel@tonic-gate  *		direct user process access (open/close/etc).
570Sstevel@tonic-gate  *
580Sstevel@tonic-gate  * This is an OR of cdevsw and bdevsw fields for drivers that
590Sstevel@tonic-gate  * support both character and block entry points.
600Sstevel@tonic-gate  *
610Sstevel@tonic-gate  * For streams stuff, see also sys/stream.h.
620Sstevel@tonic-gate  *
630Sstevel@tonic-gate  * The following DDI/DKI or DKI only or DDI only functions are
640Sstevel@tonic-gate  * provided in the character/block driver operations structure.
650Sstevel@tonic-gate  *
660Sstevel@tonic-gate  *	block/char	Function	description
670Sstevel@tonic-gate  *	b/c		XXopen		DDI/DKI
680Sstevel@tonic-gate  *	b/c		XXclose		DDI/DKI
690Sstevel@tonic-gate  *	b		XXstrategy	DDI/DKI
700Sstevel@tonic-gate  *	b  		XXprint		DDI/DKI
710Sstevel@tonic-gate  *	b  		XXdump		DDI(Sun)
720Sstevel@tonic-gate  *	  c		XXread		DDI/DKI
730Sstevel@tonic-gate  *	  c		XXwrite		DDI/DKI
740Sstevel@tonic-gate  *	  c		XXioctl		DDI/DKI
750Sstevel@tonic-gate  *	  c		XXdevmap	DDI(Sun)
760Sstevel@tonic-gate  *	  c		XXmmap		DKI
770Sstevel@tonic-gate  *	  c		XXsegmap	DKI
780Sstevel@tonic-gate  *	  c		XXchpoll	DDI/DKI
790Sstevel@tonic-gate  *	  c		XXprop_op	DDI(Sun)
800Sstevel@tonic-gate  */
810Sstevel@tonic-gate 
820Sstevel@tonic-gate struct cb_ops  {
830Sstevel@tonic-gate 	int	(*cb_open)(dev_t *devp, int flag, int otyp, cred_t *credp);
840Sstevel@tonic-gate 	int	(*cb_close)(dev_t dev, int flag, int otyp, cred_t *credp);
850Sstevel@tonic-gate 	int	(*cb_strategy)(struct buf *bp);
860Sstevel@tonic-gate 	int	(*cb_print)(dev_t dev, char *str);
870Sstevel@tonic-gate 	int	(*cb_dump)(dev_t dev, caddr_t addr, daddr_t blkno, int nblk);
880Sstevel@tonic-gate 	int	(*cb_read)(dev_t dev, struct uio *uiop, cred_t *credp);
890Sstevel@tonic-gate 	int	(*cb_write)(dev_t dev, struct uio *uiop, cred_t *credp);
900Sstevel@tonic-gate 	int	(*cb_ioctl)(dev_t dev, int cmd, intptr_t arg, int mode,
910Sstevel@tonic-gate 		    cred_t *credp, int *rvalp);
920Sstevel@tonic-gate 	int	(*cb_devmap)(dev_t dev, devmap_cookie_t dhp, offset_t off,
930Sstevel@tonic-gate 			size_t len, size_t *maplen, uint_t model);
940Sstevel@tonic-gate 	int	(*cb_mmap)(dev_t dev, off_t off, int prot);
950Sstevel@tonic-gate 	int	(*cb_segmap)(dev_t dev, off_t off, struct as *asp,
960Sstevel@tonic-gate 		    caddr_t *addrp, off_t len, unsigned int prot,
970Sstevel@tonic-gate 		    unsigned int maxprot, unsigned int flags, cred_t *credp);
980Sstevel@tonic-gate 	int	(*cb_chpoll)(dev_t dev, short events, int anyyet,
990Sstevel@tonic-gate 		    short *reventsp, struct pollhead **phpp);
1000Sstevel@tonic-gate 	int	(*cb_prop_op)(dev_t dev, dev_info_t *dip,
1010Sstevel@tonic-gate 		    ddi_prop_op_t prop_op, int mod_flags,
1020Sstevel@tonic-gate 		    char *name, caddr_t valuep, int *length);
1030Sstevel@tonic-gate 
1040Sstevel@tonic-gate 	struct streamtab *cb_str;	/* streams information */
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 	/*
1070Sstevel@tonic-gate 	 * The cb_flag fields are here to tell the system a
1080Sstevel@tonic-gate 	 * bit about the device. The bit definitions are
1090Sstevel@tonic-gate 	 * in <sys/conf.h>.
1100Sstevel@tonic-gate 	 */
1110Sstevel@tonic-gate 	int	cb_flag;		/* driver compatibility flag */
1120Sstevel@tonic-gate 	int	cb_rev;			/* cb_ops version number */
1130Sstevel@tonic-gate 	int	(*cb_aread)(dev_t dev, struct aio_req *aio, cred_t *credp);
1140Sstevel@tonic-gate 	int	(*cb_awrite)(dev_t dev, struct aio_req *aio, cred_t *credp);
1150Sstevel@tonic-gate };
1160Sstevel@tonic-gate 
1170Sstevel@tonic-gate /*
1180Sstevel@tonic-gate  * bus_ops:	bus nexus drivers only.
1190Sstevel@tonic-gate  *
1200Sstevel@tonic-gate  * These functions are used to implement the Sun DDI functions
1210Sstevel@tonic-gate  * described elsewhere.
1220Sstevel@tonic-gate  *
1230Sstevel@tonic-gate  * Only nexus drivers support these entry points.
1240Sstevel@tonic-gate  *
1250Sstevel@tonic-gate  * The following bus nexus functions are provided in the bus nexus
1260Sstevel@tonic-gate  * driver operations structure.  Note that all functions take both
1270Sstevel@tonic-gate  * their dip and the requesters dip except for the child functions since
1280Sstevel@tonic-gate  * they will be called from outside the ddi.
1290Sstevel@tonic-gate  *
1300Sstevel@tonic-gate  *	bus_map			-  Map/unmap/control IU -> device mappings.
1310Sstevel@tonic-gate  *	bus_get_intrspec	-  get interrupt specification by number
1320Sstevel@tonic-gate  *	bus_add_intrspec	-  add interrupt specification, return cookie
1330Sstevel@tonic-gate  *	bus_remove_intrspec	-  remove interrupt specification
1340Sstevel@tonic-gate  *	bus_map_fault		-  bus fault handler
1350Sstevel@tonic-gate  *	bus_dma_map		-  setup dma mapping
1360Sstevel@tonic-gate  *	bus_dma_mapctl		-  control (and free) dma mapping
1370Sstevel@tonic-gate  *	bus_ctl			-  generic control operations
1380Sstevel@tonic-gate  *	bus_prop_op		_  request for property
1390Sstevel@tonic-gate  */
1400Sstevel@tonic-gate 
1410Sstevel@tonic-gate #define	BUSO_REV_3	3
1420Sstevel@tonic-gate #define	BUSO_REV_4	4
1430Sstevel@tonic-gate #define	BUSO_REV_5	5
1440Sstevel@tonic-gate #define	BUSO_REV_6	6
1450Sstevel@tonic-gate #define	BUSO_REV_7	7
1460Sstevel@tonic-gate #define	BUSO_REV_8	8
1470Sstevel@tonic-gate #define	BUSO_REV_9	9
1480Sstevel@tonic-gate #define	BUSO_REV	BUSO_REV_9
1490Sstevel@tonic-gate 
1500Sstevel@tonic-gate 
1510Sstevel@tonic-gate struct bus_ops  {
1520Sstevel@tonic-gate 	int		busops_rev;	/* rev of this structure */
1530Sstevel@tonic-gate 	int		(*bus_map)(dev_info_t *dip, dev_info_t *rdip,
1540Sstevel@tonic-gate 			    ddi_map_req_t *mp, off_t offset, off_t len,
1550Sstevel@tonic-gate 			    caddr_t *vaddrp);
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate 	/*
1580Sstevel@tonic-gate 	 * NOTE: the following 3 busops entrypoints are obsoleted with
1590Sstevel@tonic-gate 	 * version 9 or greater. Use bus_intr_op interface in place of
1600Sstevel@tonic-gate 	 * these obsolete interfaces.
1610Sstevel@tonic-gate 	 */
1620Sstevel@tonic-gate 	ddi_intrspec_t	(*bus_get_intrspec)(dev_info_t *dip, dev_info_t *rdip,
1630Sstevel@tonic-gate 			    uint_t inumber);
1640Sstevel@tonic-gate 	int		(*bus_add_intrspec)(dev_info_t *dip,
1650Sstevel@tonic-gate 			    dev_info_t *rdip, ddi_intrspec_t intrspec,
1660Sstevel@tonic-gate 			    ddi_iblock_cookie_t *ibcp,
1670Sstevel@tonic-gate 			    ddi_idevice_cookie_t *idcp,
1680Sstevel@tonic-gate 			    uint_t (*int_handler)(caddr_t intr_handler_arg),
1690Sstevel@tonic-gate 			    caddr_t intr_handler_arg, int kind);
1700Sstevel@tonic-gate 	void		(*bus_remove_intrspec)(dev_info_t *dip,
1710Sstevel@tonic-gate 			    dev_info_t *rdip, ddi_intrspec_t intrspec,
1720Sstevel@tonic-gate 			    ddi_iblock_cookie_t iblock_cookie);
1730Sstevel@tonic-gate 
1740Sstevel@tonic-gate 	int		(*bus_map_fault)(dev_info_t *dip, dev_info_t *rdip,
1750Sstevel@tonic-gate 			    struct hat *hat, struct seg *seg, caddr_t addr,
1760Sstevel@tonic-gate 			    struct devpage *dp, pfn_t pfn, uint_t prot,
1770Sstevel@tonic-gate 			    uint_t lock);
1780Sstevel@tonic-gate 	int		(*bus_dma_map)(dev_info_t *dip, dev_info_t *rdip,
1790Sstevel@tonic-gate 			    struct ddi_dma_req *dmareq,
1800Sstevel@tonic-gate 			    ddi_dma_handle_t *handlep);
1810Sstevel@tonic-gate 	int		(*bus_dma_allochdl)(dev_info_t *dip, dev_info_t *rdip,
1820Sstevel@tonic-gate 			    ddi_dma_attr_t *attr, int (*waitfp)(caddr_t),
1830Sstevel@tonic-gate 			    caddr_t arg, ddi_dma_handle_t *handlep);
1840Sstevel@tonic-gate 	int		(*bus_dma_freehdl)(dev_info_t *dip, dev_info_t *rdip,
1850Sstevel@tonic-gate 			    ddi_dma_handle_t handle);
1860Sstevel@tonic-gate 	int		(*bus_dma_bindhdl)(dev_info_t *dip, dev_info_t *rdip,
1870Sstevel@tonic-gate 			    ddi_dma_handle_t handle, struct ddi_dma_req *dmareq,
1880Sstevel@tonic-gate 			    ddi_dma_cookie_t *, uint_t *);
1890Sstevel@tonic-gate 	int		(*bus_dma_unbindhdl)(dev_info_t *dip, dev_info_t *rdip,
1900Sstevel@tonic-gate 			    ddi_dma_handle_t handle);
1910Sstevel@tonic-gate 	int		(*bus_dma_flush)(dev_info_t *dip, dev_info_t *rdip,
1920Sstevel@tonic-gate 			    ddi_dma_handle_t handle, off_t off,
1930Sstevel@tonic-gate 			    size_t len, uint_t cache_flags);
1940Sstevel@tonic-gate 	int		(*bus_dma_win)(dev_info_t *dip, dev_info_t *rdip,
1950Sstevel@tonic-gate 			    ddi_dma_handle_t handle, uint_t win, off_t *offp,
1960Sstevel@tonic-gate 			    size_t *lenp, ddi_dma_cookie_t *cookiep,
1970Sstevel@tonic-gate 			    uint_t *ccountp);
1980Sstevel@tonic-gate 	int		(*bus_dma_ctl)(dev_info_t *dip, dev_info_t *rdip,
1990Sstevel@tonic-gate 			    ddi_dma_handle_t handle,
2000Sstevel@tonic-gate 			    enum ddi_dma_ctlops request, off_t *offp,
2010Sstevel@tonic-gate 			    size_t *lenp, caddr_t *objp, uint_t flags);
2020Sstevel@tonic-gate 	int		(*bus_ctl)(dev_info_t *dip, dev_info_t *rdip,
2030Sstevel@tonic-gate 			    ddi_ctl_enum_t ctlop, void *arg, void *result);
2040Sstevel@tonic-gate 	int		(*bus_prop_op)(dev_t dev, dev_info_t *dip,
2050Sstevel@tonic-gate 			    dev_info_t *child_dip, ddi_prop_op_t prop_op,
2060Sstevel@tonic-gate 			    int mod_flags, char *name, caddr_t valuep,
2070Sstevel@tonic-gate 			    int *length);
2080Sstevel@tonic-gate 	/*
2090Sstevel@tonic-gate 	 * NOTE: the following 4 busops entrypoints are only available
2100Sstevel@tonic-gate 	 * with version 3 or greater.  Due to interface modifications, these
2110Sstevel@tonic-gate 	 * entrypoints can only be used with version 6 or greater.
2120Sstevel@tonic-gate 	 */
2130Sstevel@tonic-gate 
2140Sstevel@tonic-gate 	int		(*bus_get_eventcookie)(dev_info_t *dip,
2150Sstevel@tonic-gate 			    dev_info_t *rdip, char *eventname,
2160Sstevel@tonic-gate 			    ddi_eventcookie_t *cookiep);
2170Sstevel@tonic-gate 	int		(*bus_add_eventcall)(dev_info_t *dip, dev_info_t *rdip,
2180Sstevel@tonic-gate 			    ddi_eventcookie_t eventid,
2190Sstevel@tonic-gate 			    void (*event_hdlr)(dev_info_t *dip,
2200Sstevel@tonic-gate 			    ddi_eventcookie_t event, void *arg,
2210Sstevel@tonic-gate 			    void *bus_impldata), void *arg,
2220Sstevel@tonic-gate 			    ddi_callback_id_t *cb_id);
2230Sstevel@tonic-gate 	int		(*bus_remove_eventcall)(dev_info_t *devi,
2240Sstevel@tonic-gate 			    ddi_callback_id_t cb_id);
2250Sstevel@tonic-gate 	int		(*bus_post_event)(dev_info_t *dip, dev_info_t *rdip,
2260Sstevel@tonic-gate 			    ddi_eventcookie_t event, void *impl_data);
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate 	/*
2290Sstevel@tonic-gate 	 * NOTE: the following bus_intr_ctl entrypoint is obsoleted with
2300Sstevel@tonic-gate 	 * version 9 or greater. Use bus_intr_op interface in place of
2310Sstevel@tonic-gate 	 * this obsolete interface.
2320Sstevel@tonic-gate 	 */
2330Sstevel@tonic-gate 	int		(*bus_intr_ctl)(dev_info_t *dip, dev_info_t *rdip,
2340Sstevel@tonic-gate 			    ddi_intr_ctlop_t ctlop, void * arg, void * result);
2350Sstevel@tonic-gate 	/*
2360Sstevel@tonic-gate 	 * NOTE: the following busop entrypoints are available with version
2370Sstevel@tonic-gate 	 * 5 or greater.
2380Sstevel@tonic-gate 	 */
2390Sstevel@tonic-gate 	int		(*bus_config)(dev_info_t *parent, uint_t flags,
2400Sstevel@tonic-gate 			    ddi_bus_config_op_t op, void *arg,
2410Sstevel@tonic-gate 			    dev_info_t **childp);
2420Sstevel@tonic-gate 	int		(*bus_unconfig)(dev_info_t *parent, uint_t flags,
2430Sstevel@tonic-gate 			    ddi_bus_config_op_t op, void *arg);
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate 	/*
2460Sstevel@tonic-gate 	 * NOTE: the following busop entrypoints are available with version
2470Sstevel@tonic-gate 	 * 6 or greater.
2480Sstevel@tonic-gate 	 */
2490Sstevel@tonic-gate 	int		(*bus_fm_init)(dev_info_t *dip, dev_info_t *tdip,
2500Sstevel@tonic-gate 			    int cap, ddi_iblock_cookie_t *ibc);
2510Sstevel@tonic-gate 	void		(*bus_fm_fini)(dev_info_t *dip, dev_info_t *tdip);
2520Sstevel@tonic-gate 	void		(*bus_fm_access_enter)(dev_info_t *dip,
2530Sstevel@tonic-gate 			    ddi_acc_handle_t handle);
2540Sstevel@tonic-gate 	void		(*bus_fm_access_exit)(dev_info_t *dip,
2550Sstevel@tonic-gate 			    ddi_acc_handle_t handle);
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate 	/*
2580Sstevel@tonic-gate 	 * NOTE: the following busop entrypoint is available with version
2590Sstevel@tonic-gate 	 * 7 or greater.
2600Sstevel@tonic-gate 	 */
2610Sstevel@tonic-gate 	int		(*bus_power)(dev_info_t *dip, void *impl_arg,
2620Sstevel@tonic-gate 			    pm_bus_power_op_t op, void *arg, void *result);
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate 	/*
2650Sstevel@tonic-gate 	 * NOTE: the following busop entrypoint is available with version
2660Sstevel@tonic-gate 	 * 9 or greater.
2670Sstevel@tonic-gate 	 */
2680Sstevel@tonic-gate 	int		(*bus_intr_op)(dev_info_t *dip, dev_info_t *rdip,
2690Sstevel@tonic-gate 			    ddi_intr_op_t op, ddi_intr_handle_impl_t *hdlp,
2700Sstevel@tonic-gate 			    void *result);
2710Sstevel@tonic-gate };
2720Sstevel@tonic-gate 
2730Sstevel@tonic-gate /*
2740Sstevel@tonic-gate  * REV 1 bus ops structure
2750Sstevel@tonic-gate  */
2760Sstevel@tonic-gate 
2770Sstevel@tonic-gate struct bus_ops_rev1 {
2780Sstevel@tonic-gate 	int		(*bus_map)(dev_info_t *dip, dev_info_t *rdip,
2790Sstevel@tonic-gate 			    ddi_map_req_t *mp, off_t offset, off_t len,
2800Sstevel@tonic-gate 			    caddr_t *vaddrp);
2810Sstevel@tonic-gate 	ddi_intrspec_t	(*bus_get_intrspec)(dev_info_t *dip, dev_info_t *rdip,
2820Sstevel@tonic-gate 			    uint_t inumber);
2830Sstevel@tonic-gate 	int		(*bus_add_intrspec)(dev_info_t *dip,
2840Sstevel@tonic-gate 			    dev_info_t *rdip, ddi_intrspec_t intrspec,
2850Sstevel@tonic-gate 			    ddi_iblock_cookie_t *ibcp,
2860Sstevel@tonic-gate 			    ddi_idevice_cookie_t *idcp,
2870Sstevel@tonic-gate 			    uint_t (*int_handler)(caddr_t intr_handler_arg),
2880Sstevel@tonic-gate 			    caddr_t intr_handler_arg, int kind);
2890Sstevel@tonic-gate 	void		(*bus_remove_intrspec)(dev_info_t *dip,
2900Sstevel@tonic-gate 			    dev_info_t *rdip, ddi_intrspec_t intrspec,
2910Sstevel@tonic-gate 			    ddi_iblock_cookie_t iblock_cookie);
2920Sstevel@tonic-gate 	int		(*bus_map_fault)(dev_info_t *dip, dev_info_t *rdip,
2930Sstevel@tonic-gate 			    struct hat *hat, struct seg *seg, caddr_t addr,
2940Sstevel@tonic-gate 			    struct devpage *dp, pfn_t pfn, uint_t prot,
2950Sstevel@tonic-gate 			    uint_t lock);
2960Sstevel@tonic-gate 	int		(*bus_dma_map)(dev_info_t *dip, dev_info_t *rdip,
2970Sstevel@tonic-gate 			    struct ddi_dma_req *dmareq,
2980Sstevel@tonic-gate 			    ddi_dma_handle_t *handlep);
2990Sstevel@tonic-gate 	int		(*bus_dma_ctl)(dev_info_t *dip, dev_info_t *rdip,
3000Sstevel@tonic-gate 			    ddi_dma_handle_t handle,
3010Sstevel@tonic-gate 			    enum ddi_dma_ctlops request, off_t *offp,
3020Sstevel@tonic-gate 			    uint_t *lenp, caddr_t *objp, uint_t flags);
3030Sstevel@tonic-gate 	int		(*bus_ctl)(dev_info_t *dip, dev_info_t *rdip,
3040Sstevel@tonic-gate 			    ddi_ctl_enum_t ctlop, void *arg, void *result);
3050Sstevel@tonic-gate 	int		(*bus_prop_op)(dev_t dev, dev_info_t *dip,
3060Sstevel@tonic-gate 			    dev_info_t *child_dip, ddi_prop_op_t prop_op,
3070Sstevel@tonic-gate 			    int mod_flags, char *name, caddr_t valuep,
3080Sstevel@tonic-gate 			    int *length);
3090Sstevel@tonic-gate };
3100Sstevel@tonic-gate 
3110Sstevel@tonic-gate /*
3120Sstevel@tonic-gate  * dev_ops:	Contains driver common fields and pointers
3130Sstevel@tonic-gate  *		to the bus_ops and/or cb_ops parts.
3140Sstevel@tonic-gate  *
3150Sstevel@tonic-gate  * Drivers should set devo_rev to DEVO_REV at compile time.
3160Sstevel@tonic-gate  * All drivers should support these entry points.
3170Sstevel@tonic-gate  *
3180Sstevel@tonic-gate  * the following device functions are provided in the device operations
3190Sstevel@tonic-gate  * structure.
3200Sstevel@tonic-gate  *
3210Sstevel@tonic-gate  *	devo_getinfo		-  Device handle conversion
3220Sstevel@tonic-gate  *	devo_identify		-  Obsolete, set to nulldev
3230Sstevel@tonic-gate  *	devo_probe		-  Probe for device's existence
3240Sstevel@tonic-gate  *	devo_attach		-  Attach driver to dev_info
3250Sstevel@tonic-gate  *	devo_detach		-  Detach/prepare driver to unload
3260Sstevel@tonic-gate  *	devo_reset		-  Reset device
327*7656SSherry.Moore@Sun.COM  *	devo_quiesce		-  Quiesce device
3280Sstevel@tonic-gate  */
3290Sstevel@tonic-gate 
330*7656SSherry.Moore@Sun.COM #define		DEVO_REV		4
3310Sstevel@tonic-gate #define		CB_REV			1
3320Sstevel@tonic-gate 
3330Sstevel@tonic-gate /*
3340Sstevel@tonic-gate  * Return from driver's devo_probe function:
3350Sstevel@tonic-gate  */
3360Sstevel@tonic-gate 
3370Sstevel@tonic-gate #define	DDI_PROBE_FAILURE	ENXIO	/* matches nodev return */
3380Sstevel@tonic-gate #define	DDI_PROBE_DONTCARE	0	/* matches nulldev return */
3390Sstevel@tonic-gate #define	DDI_PROBE_PARTIAL	1
3400Sstevel@tonic-gate #define	DDI_PROBE_SUCCESS	2
3410Sstevel@tonic-gate 
3420Sstevel@tonic-gate /*
3430Sstevel@tonic-gate  * Typedefs for the info, attach, detach and reset routines.
3440Sstevel@tonic-gate  * These are mostly placeholders for now.
3450Sstevel@tonic-gate  *
3460Sstevel@tonic-gate  * NOTE: DDI_INFO_DEVT2DEVINFO is deprecated
3470Sstevel@tonic-gate  */
3480Sstevel@tonic-gate typedef enum {
3490Sstevel@tonic-gate 	DDI_INFO_DEVT2DEVINFO = 0,	/* Convert a dev_t to a dev_info_t */
3500Sstevel@tonic-gate 	DDI_INFO_DEVT2INSTANCE = 1	/* Convert a dev_t to an instance # */
3510Sstevel@tonic-gate } ddi_info_cmd_t;
3520Sstevel@tonic-gate 
3530Sstevel@tonic-gate typedef enum {
3540Sstevel@tonic-gate 	DDI_ATTACH = 0,
3550Sstevel@tonic-gate 	DDI_RESUME = 1,
3560Sstevel@tonic-gate 	DDI_PM_RESUME = 2
3570Sstevel@tonic-gate } ddi_attach_cmd_t;
3580Sstevel@tonic-gate 
3590Sstevel@tonic-gate typedef enum {
3600Sstevel@tonic-gate 	DDI_DETACH = 0,
3610Sstevel@tonic-gate 	DDI_SUSPEND = 1,
3620Sstevel@tonic-gate 	DDI_PM_SUSPEND = 2,
3630Sstevel@tonic-gate 	DDI_HOTPLUG_DETACH = 3		/* detach, don't try to auto-unconfig */
3640Sstevel@tonic-gate } ddi_detach_cmd_t;
3650Sstevel@tonic-gate 
3660Sstevel@tonic-gate typedef enum {
3670Sstevel@tonic-gate 	DDI_RESET_FORCE = 0
3680Sstevel@tonic-gate } ddi_reset_cmd_t;
3690Sstevel@tonic-gate 
3700Sstevel@tonic-gate struct dev_ops  {
3710Sstevel@tonic-gate 	int		devo_rev;	/* Driver build version		*/
3720Sstevel@tonic-gate 	int		devo_refcnt;	/* device reference count	*/
3730Sstevel@tonic-gate 
3740Sstevel@tonic-gate 	int		(*devo_getinfo)(dev_info_t *dip,
3750Sstevel@tonic-gate 			    ddi_info_cmd_t infocmd, void *arg, void **result);
3760Sstevel@tonic-gate 	int		(*devo_identify)(dev_info_t *dip);
3770Sstevel@tonic-gate 	int		(*devo_probe)(dev_info_t *dip);
3780Sstevel@tonic-gate 	int		(*devo_attach)(dev_info_t *dip, ddi_attach_cmd_t cmd);
3790Sstevel@tonic-gate 	int		(*devo_detach)(dev_info_t *dip, ddi_detach_cmd_t cmd);
3800Sstevel@tonic-gate 	int		(*devo_reset)(dev_info_t *dip, ddi_reset_cmd_t cmd);
3810Sstevel@tonic-gate 
3820Sstevel@tonic-gate 	struct cb_ops	*devo_cb_ops;	/* cb_ops pointer for leaf drivers   */
3830Sstevel@tonic-gate 	struct bus_ops	*devo_bus_ops;	/* bus_ops pointer for nexus drivers */
3840Sstevel@tonic-gate 	int		(*devo_power)(dev_info_t *dip, int component,
3850Sstevel@tonic-gate 			    int level);
386*7656SSherry.Moore@Sun.COM 	int		(*devo_quiesce)(dev_info_t *dip);
3870Sstevel@tonic-gate };
3880Sstevel@tonic-gate 
3890Sstevel@tonic-gate /*
3900Sstevel@tonic-gate  * Create a dev_ops suitable for a streams driver:
3910Sstevel@tonic-gate  *
3920Sstevel@tonic-gate  * XXX: Note:  Since this is a macro, it is NOT supported as
3930Sstevel@tonic-gate  * XXX: part of the Sun DDI.  It is not a documented Sun DDI interface.
3940Sstevel@tonic-gate  *
3950Sstevel@tonic-gate  * STR_OPS(name, identify, probe, attach, detach, reset,
3960Sstevel@tonic-gate  *	info, flag, stream_tab);
3970Sstevel@tonic-gate  *
3980Sstevel@tonic-gate  *	XXname is the name of the dev_ops structure.
3990Sstevel@tonic-gate  *	XXidentify must be set to nulldev
4000Sstevel@tonic-gate  *	XXprobe is the name of the probe routine, or nulldev
4010Sstevel@tonic-gate  *	XXattach is the name of the attach routine
4020Sstevel@tonic-gate  *	XXdetach is the name of the detach routine, or nodev
4030Sstevel@tonic-gate  *	XXreset is the name of the reset routine, or nodev
4040Sstevel@tonic-gate  *	XXinfo is the name of the info routine
4050Sstevel@tonic-gate  *	XXflag is driver flag (cb_flag) in cb_ops,
4060Sstevel@tonic-gate  *	XXstream_tab is the obvious.
407*7656SSherry.Moore@Sun.COM  *	XXquiesce is the name of the quiesce routine. It must be implemented
408*7656SSherry.Moore@Sun.COM  *		for fast reboot to succeed.
4090Sstevel@tonic-gate  *	cb_##XXname is the name of the internally defined cb_ops struct.
4100Sstevel@tonic-gate  *
4110Sstevel@tonic-gate  * uses cb_XXname as name of static cb_ops structure.
4120Sstevel@tonic-gate  */
4130Sstevel@tonic-gate 
4140Sstevel@tonic-gate /*
4150Sstevel@tonic-gate  * This file is included by genassym.c now and I couldn't get it to take the
4160Sstevel@tonic-gate  * next line if it was broken into two lines joined by a '\'.  So, don't try
4170Sstevel@tonic-gate  * to reformat it to satisfy Cstyle because genassym.c won't compile.
4180Sstevel@tonic-gate  */
4190Sstevel@tonic-gate /* CSTYLED */
420*7656SSherry.Moore@Sun.COM #define	DDI_DEFINE_STREAM_OPS(XXname, XXidentify, XXprobe, XXattach, XXdetach, XXreset, XXgetinfo, XXflag, XXstream_tab, XXquiesce) \
4210Sstevel@tonic-gate static struct cb_ops cb_##XXname = {					\
4220Sstevel@tonic-gate 	nulldev,		/* cb_open */				\
4230Sstevel@tonic-gate 	nulldev,		/* cb_close */				\
4240Sstevel@tonic-gate 	nodev,			/* cb_strategy */			\
4250Sstevel@tonic-gate 	nodev,			/* cb_print */				\
4260Sstevel@tonic-gate 	nodev,			/* cb_dump */				\
4270Sstevel@tonic-gate 	nodev,			/* cb_read */				\
4280Sstevel@tonic-gate 	nodev,			/* cb_write */				\
4290Sstevel@tonic-gate 	nodev,			/* cb_ioctl */				\
4300Sstevel@tonic-gate 	nodev,			/* cb_devmap */				\
4310Sstevel@tonic-gate 	nodev,			/* cb_mmap */				\
4320Sstevel@tonic-gate 	nodev,			/* cb_segmap */				\
4330Sstevel@tonic-gate 	nochpoll,		/* cb_chpoll */				\
4340Sstevel@tonic-gate 	ddi_prop_op,		/* cb_prop_op */			\
4350Sstevel@tonic-gate 	(XXstream_tab),		/* cb_stream */				\
4360Sstevel@tonic-gate 	(int)(XXflag),		/* cb_flag */				\
4370Sstevel@tonic-gate 	CB_REV,			/* cb_rev */				\
4380Sstevel@tonic-gate 	nodev,			/* cb_aread */				\
4390Sstevel@tonic-gate 	nodev,			/* cb_awrite */				\
4400Sstevel@tonic-gate };									\
4410Sstevel@tonic-gate 									\
4420Sstevel@tonic-gate static struct dev_ops XXname = {					\
4430Sstevel@tonic-gate 	DEVO_REV,		/* devo_rev */				\
4440Sstevel@tonic-gate 	0,			/* devo_refcnt */			\
4450Sstevel@tonic-gate 	(XXgetinfo),		/* devo_getinfo */			\
4460Sstevel@tonic-gate 	(XXidentify),		/* devo_identify */			\
4470Sstevel@tonic-gate 	(XXprobe),		/* devo_probe */			\
4480Sstevel@tonic-gate 	(XXattach),		/* devo_attach */			\
4490Sstevel@tonic-gate 	(XXdetach),		/* devo_detach */			\
4500Sstevel@tonic-gate 	(XXreset),		/* devo_reset */			\
4510Sstevel@tonic-gate 	&(cb_##XXname),		/* devo_cb_ops */			\
4520Sstevel@tonic-gate 	(struct bus_ops *)NULL,	/* devo_bus_ops */			\
453*7656SSherry.Moore@Sun.COM 	NULL,			/* devo_power */			\
454*7656SSherry.Moore@Sun.COM 	(XXquiesce)		/* devo_quiesce */			\
4550Sstevel@tonic-gate }
4560Sstevel@tonic-gate 
4570Sstevel@tonic-gate #endif	/* _KERNEL */
4580Sstevel@tonic-gate 
4590Sstevel@tonic-gate #ifdef	__cplusplus
4600Sstevel@tonic-gate }
4610Sstevel@tonic-gate #endif
4620Sstevel@tonic-gate 
4630Sstevel@tonic-gate #endif	/* _SYS_DEVOPS_H */
464