xref: /titanic_51/usr/src/uts/common/os/driver.c (revision 193974072f41a843678abf5f61979c748687e66b)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5184cd04cScth  * Common Development and Distribution License (the "License").
6184cd04cScth  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*19397407SSherry Moore  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <sys/types.h>
277c478bd9Sstevel@tonic-gate #include <sys/t_lock.h>
287c478bd9Sstevel@tonic-gate #include <sys/param.h>
297c478bd9Sstevel@tonic-gate #include <sys/conf.h>
307c478bd9Sstevel@tonic-gate #include <sys/systm.h>
317c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h>
327c478bd9Sstevel@tonic-gate #include <sys/buf.h>
337c478bd9Sstevel@tonic-gate #include <sys/cred.h>
347c478bd9Sstevel@tonic-gate #include <sys/user.h>
357c478bd9Sstevel@tonic-gate #include <sys/stat.h>
367c478bd9Sstevel@tonic-gate #include <sys/uio.h>
377c478bd9Sstevel@tonic-gate #include <sys/vnode.h>
387c478bd9Sstevel@tonic-gate #include <sys/fs/snode.h>
397c478bd9Sstevel@tonic-gate #include <sys/open.h>
407c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
417c478bd9Sstevel@tonic-gate #include <sys/file.h>
427c478bd9Sstevel@tonic-gate #include <sys/debug.h>
437c478bd9Sstevel@tonic-gate #include <sys/tnf_probe.h>
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /* Don't #include <sys/ddi.h> - it #undef's getmajor() */
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
487c478bd9Sstevel@tonic-gate #include <sys/sunndi.h>
497c478bd9Sstevel@tonic-gate #include <sys/sunpm.h>
507c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
517c478bd9Sstevel@tonic-gate #include <sys/ndi_impldefs.h>
527c478bd9Sstevel@tonic-gate #include <sys/esunddi.h>
537c478bd9Sstevel@tonic-gate #include <sys/autoconf.h>
547c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
557c478bd9Sstevel@tonic-gate #include <sys/epm.h>
567c478bd9Sstevel@tonic-gate #include <sys/dacf.h>
577c478bd9Sstevel@tonic-gate #include <sys/sunmdi.h>
587c478bd9Sstevel@tonic-gate #include <sys/instance.h>
597c478bd9Sstevel@tonic-gate #include <sys/sdt.h>
607c478bd9Sstevel@tonic-gate 
617c478bd9Sstevel@tonic-gate static void i_attach_ctlop(dev_info_t *, ddi_attach_cmd_t, ddi_pre_post_t, int);
627c478bd9Sstevel@tonic-gate static void i_detach_ctlop(dev_info_t *, ddi_detach_cmd_t, ddi_pre_post_t, int);
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate /* decide what to do when a double dev_lclose is detected */
657c478bd9Sstevel@tonic-gate #ifdef	DEBUG
667c478bd9Sstevel@tonic-gate int		dev_lclose_ce = CE_PANIC;
677c478bd9Sstevel@tonic-gate #else	/* DEBUG */
687c478bd9Sstevel@tonic-gate int		dev_lclose_ce = CE_WARN;
697c478bd9Sstevel@tonic-gate #endif	/* DEBUG */
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate /*
727c478bd9Sstevel@tonic-gate  * Configuration-related entry points for nexus and leaf drivers
737c478bd9Sstevel@tonic-gate  */
747c478bd9Sstevel@tonic-gate int
757c478bd9Sstevel@tonic-gate devi_identify(dev_info_t *devi)
767c478bd9Sstevel@tonic-gate {
777c478bd9Sstevel@tonic-gate 	struct dev_ops *ops;
787c478bd9Sstevel@tonic-gate 	int (*fn)(dev_info_t *);
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 	if ((ops = ddi_get_driver(devi)) == NULL ||
817c478bd9Sstevel@tonic-gate 	    (fn = ops->devo_identify) == NULL)
827c478bd9Sstevel@tonic-gate 		return (-1);
837c478bd9Sstevel@tonic-gate 
847c478bd9Sstevel@tonic-gate 	return ((*fn)(devi));
857c478bd9Sstevel@tonic-gate }
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate int
887c478bd9Sstevel@tonic-gate devi_probe(dev_info_t *devi)
897c478bd9Sstevel@tonic-gate {
907c478bd9Sstevel@tonic-gate 	int rv, probe_failed;
917c478bd9Sstevel@tonic-gate 	pm_ppm_cookie_t ppm_cookie;
927c478bd9Sstevel@tonic-gate 	struct dev_ops *ops;
937c478bd9Sstevel@tonic-gate 	int (*fn)(dev_info_t *);
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 	ops = ddi_get_driver(devi);
967c478bd9Sstevel@tonic-gate 	ASSERT(ops);
977c478bd9Sstevel@tonic-gate 
987c478bd9Sstevel@tonic-gate 	pm_pre_probe(devi, &ppm_cookie);
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate 	/*
1017c478bd9Sstevel@tonic-gate 	 * probe(9E) in 2.0 implies that you can get
1027c478bd9Sstevel@tonic-gate 	 * away with not writing one of these .. so we
1037c478bd9Sstevel@tonic-gate 	 * pretend we're 'nulldev' if we don't find one (sigh).
1047c478bd9Sstevel@tonic-gate 	 */
1057c478bd9Sstevel@tonic-gate 	if ((fn = ops->devo_probe) == NULL)
1067c478bd9Sstevel@tonic-gate 		rv = DDI_PROBE_DONTCARE;
1077c478bd9Sstevel@tonic-gate 	else
1087c478bd9Sstevel@tonic-gate 		rv = (*fn)(devi);
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	switch (rv) {
1117c478bd9Sstevel@tonic-gate 	case DDI_PROBE_DONTCARE:
1127c478bd9Sstevel@tonic-gate 	case DDI_PROBE_SUCCESS:
1137c478bd9Sstevel@tonic-gate 		probe_failed = 0;
1147c478bd9Sstevel@tonic-gate 		break;
1157c478bd9Sstevel@tonic-gate 	default:
1167c478bd9Sstevel@tonic-gate 		probe_failed = 1;
1177c478bd9Sstevel@tonic-gate 		break;
1187c478bd9Sstevel@tonic-gate 	}
1197c478bd9Sstevel@tonic-gate 	pm_post_probe(&ppm_cookie, rv, probe_failed);
1207c478bd9Sstevel@tonic-gate 
1217c478bd9Sstevel@tonic-gate 	return (rv);
1227c478bd9Sstevel@tonic-gate }
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate 
1257c478bd9Sstevel@tonic-gate /*
1267c478bd9Sstevel@tonic-gate  * devi_attach()
1277c478bd9Sstevel@tonic-gate  * 	attach a device instance to the system if the driver supplies an
1287c478bd9Sstevel@tonic-gate  * 	attach(9E) entrypoint.
1297c478bd9Sstevel@tonic-gate  */
1307c478bd9Sstevel@tonic-gate int
1317c478bd9Sstevel@tonic-gate devi_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
1327c478bd9Sstevel@tonic-gate {
1337c478bd9Sstevel@tonic-gate 	struct dev_ops *ops;
1347c478bd9Sstevel@tonic-gate 	int error;
1357c478bd9Sstevel@tonic-gate 	int (*fn)(dev_info_t *, ddi_attach_cmd_t);
1367c478bd9Sstevel@tonic-gate 	pm_ppm_cookie_t pc;
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate 	if ((error = mdi_pre_attach(devi, cmd)) != DDI_SUCCESS) {
1397c478bd9Sstevel@tonic-gate 		return (error);
1407c478bd9Sstevel@tonic-gate 	}
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate 	pm_pre_attach(devi, &pc, cmd);
1437c478bd9Sstevel@tonic-gate 
1447c478bd9Sstevel@tonic-gate 	if ((cmd == DDI_RESUME || cmd == DDI_PM_RESUME) &&
1457c478bd9Sstevel@tonic-gate 	    e_ddi_parental_suspend_resume(devi)) {
1467c478bd9Sstevel@tonic-gate 		error = e_ddi_resume(devi, cmd);
1477c478bd9Sstevel@tonic-gate 		goto done;
1487c478bd9Sstevel@tonic-gate 	}
1497c478bd9Sstevel@tonic-gate 	ops = ddi_get_driver(devi);
1507c478bd9Sstevel@tonic-gate 	ASSERT(ops);
1517c478bd9Sstevel@tonic-gate 	if ((fn = ops->devo_attach) == NULL) {
1527c478bd9Sstevel@tonic-gate 		error = DDI_FAILURE;
1537c478bd9Sstevel@tonic-gate 		goto done;
1547c478bd9Sstevel@tonic-gate 	}
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate 	/*
1577c478bd9Sstevel@tonic-gate 	 * Call the driver's attach(9e) entrypoint
1587c478bd9Sstevel@tonic-gate 	 */
1597c478bd9Sstevel@tonic-gate 	i_attach_ctlop(devi, cmd, DDI_PRE, 0);
1607c478bd9Sstevel@tonic-gate 	error = (*fn)(devi, cmd);
1617c478bd9Sstevel@tonic-gate 	i_attach_ctlop(devi, cmd, DDI_POST, error);
1627c478bd9Sstevel@tonic-gate 
1637c478bd9Sstevel@tonic-gate done:
1647c478bd9Sstevel@tonic-gate 	pm_post_attach(&pc, error);
1657c478bd9Sstevel@tonic-gate 	mdi_post_attach(devi, cmd, error);
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	return (error);
1687c478bd9Sstevel@tonic-gate }
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate /*
1717c478bd9Sstevel@tonic-gate  * devi_detach()
1727c478bd9Sstevel@tonic-gate  * 	detach a device instance from the system if the driver supplies a
1737c478bd9Sstevel@tonic-gate  * 	detach(9E) entrypoint.
1747c478bd9Sstevel@tonic-gate  */
1757c478bd9Sstevel@tonic-gate int
1767c478bd9Sstevel@tonic-gate devi_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
1777c478bd9Sstevel@tonic-gate {
1787c478bd9Sstevel@tonic-gate 	struct dev_ops *ops;
1797c478bd9Sstevel@tonic-gate 	int error;
1807c478bd9Sstevel@tonic-gate 	int (*fn)(dev_info_t *, ddi_detach_cmd_t);
1817c478bd9Sstevel@tonic-gate 	pm_ppm_cookie_t pc;
1827c478bd9Sstevel@tonic-gate 
1837c478bd9Sstevel@tonic-gate 	ASSERT(cmd == DDI_SUSPEND || cmd == DDI_PM_SUSPEND ||
1847c478bd9Sstevel@tonic-gate 	    cmd == DDI_DETACH);
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate 	if ((cmd == DDI_SUSPEND || cmd == DDI_PM_SUSPEND) &&
1877c478bd9Sstevel@tonic-gate 	    e_ddi_parental_suspend_resume(devi)) {
1887c478bd9Sstevel@tonic-gate 		return (e_ddi_suspend(devi, cmd));
1897c478bd9Sstevel@tonic-gate 	}
1907c478bd9Sstevel@tonic-gate 	ops = ddi_get_driver(devi);
1917c478bd9Sstevel@tonic-gate 	ASSERT(ops);
1927c478bd9Sstevel@tonic-gate 	if ((fn = ops->devo_detach) == NULL)
1937c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate 	if ((error = mdi_pre_detach(devi, cmd)) != DDI_SUCCESS) {
1967c478bd9Sstevel@tonic-gate 		return (error);
1977c478bd9Sstevel@tonic-gate 	}
1987c478bd9Sstevel@tonic-gate 	i_detach_ctlop(devi, cmd, DDI_PRE, 0);
1997c478bd9Sstevel@tonic-gate 	pm_pre_detach(devi, cmd, &pc);
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	/*
2027c478bd9Sstevel@tonic-gate 	 * Call the driver's detach routine
2037c478bd9Sstevel@tonic-gate 	 */
2047c478bd9Sstevel@tonic-gate 	error = (*fn)(devi, cmd);
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 	pm_post_detach(&pc, error);
2077c478bd9Sstevel@tonic-gate 	i_detach_ctlop(devi, cmd, DDI_POST, error);
2087c478bd9Sstevel@tonic-gate 	mdi_post_detach(devi, cmd, error);
2097c478bd9Sstevel@tonic-gate 
2107c478bd9Sstevel@tonic-gate 	return (error);
2117c478bd9Sstevel@tonic-gate }
2127c478bd9Sstevel@tonic-gate 
2137c478bd9Sstevel@tonic-gate static void
2147c478bd9Sstevel@tonic-gate i_attach_ctlop(dev_info_t *devi, ddi_attach_cmd_t cmd, ddi_pre_post_t w,
2157c478bd9Sstevel@tonic-gate     int ret)
2167c478bd9Sstevel@tonic-gate {
2177c478bd9Sstevel@tonic-gate 	int error;
2187c478bd9Sstevel@tonic-gate 	struct attachspec as;
2197c478bd9Sstevel@tonic-gate 	dev_info_t *pdip = ddi_get_parent(devi);
2207c478bd9Sstevel@tonic-gate 
2217c478bd9Sstevel@tonic-gate 	as.cmd = cmd;
2227c478bd9Sstevel@tonic-gate 	as.when = w;
2237c478bd9Sstevel@tonic-gate 	as.pdip = pdip;
2247c478bd9Sstevel@tonic-gate 	as.result = ret;
2257c478bd9Sstevel@tonic-gate 	(void) ddi_ctlops(devi, devi, DDI_CTLOPS_ATTACH, &as, &error);
2267c478bd9Sstevel@tonic-gate }
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate static void
2297c478bd9Sstevel@tonic-gate i_detach_ctlop(dev_info_t *devi, ddi_detach_cmd_t cmd, ddi_pre_post_t w,
2307c478bd9Sstevel@tonic-gate     int ret)
2317c478bd9Sstevel@tonic-gate {
2327c478bd9Sstevel@tonic-gate 	int error;
2337c478bd9Sstevel@tonic-gate 	struct detachspec ds;
2347c478bd9Sstevel@tonic-gate 	dev_info_t *pdip = ddi_get_parent(devi);
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate 	ds.cmd = cmd;
2377c478bd9Sstevel@tonic-gate 	ds.when = w;
2387c478bd9Sstevel@tonic-gate 	ds.pdip = pdip;
2397c478bd9Sstevel@tonic-gate 	ds.result = ret;
2407c478bd9Sstevel@tonic-gate 	(void) ddi_ctlops(devi, devi, DDI_CTLOPS_DETACH, &ds, &error);
2417c478bd9Sstevel@tonic-gate }
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate /*
2447c478bd9Sstevel@tonic-gate  * This entry point not defined by Solaris 2.0 DDI/DKI, so
2457c478bd9Sstevel@tonic-gate  * its inclusion here is somewhat moot.
2467c478bd9Sstevel@tonic-gate  */
2477c478bd9Sstevel@tonic-gate int
2487c478bd9Sstevel@tonic-gate devi_reset(dev_info_t *devi, ddi_reset_cmd_t cmd)
2497c478bd9Sstevel@tonic-gate {
2507c478bd9Sstevel@tonic-gate 	struct dev_ops *ops;
2517c478bd9Sstevel@tonic-gate 	int (*fn)(dev_info_t *, ddi_reset_cmd_t);
2527c478bd9Sstevel@tonic-gate 
2537c478bd9Sstevel@tonic-gate 	if ((ops = ddi_get_driver(devi)) == NULL ||
2547c478bd9Sstevel@tonic-gate 	    (fn = ops->devo_reset) == NULL)
2557c478bd9Sstevel@tonic-gate 		return (DDI_FAILURE);
2567c478bd9Sstevel@tonic-gate 
2577c478bd9Sstevel@tonic-gate 	return ((*fn)(devi, cmd));
2587c478bd9Sstevel@tonic-gate }
2597c478bd9Sstevel@tonic-gate 
260*19397407SSherry Moore int
261*19397407SSherry Moore devi_quiesce(dev_info_t *devi)
262*19397407SSherry Moore {
263*19397407SSherry Moore 	struct dev_ops *ops;
264*19397407SSherry Moore 	int (*fn)(dev_info_t *);
265*19397407SSherry Moore 
266*19397407SSherry Moore 	if (((ops = ddi_get_driver(devi)) == NULL) ||
267*19397407SSherry Moore 	    (ops->devo_rev < 4) || ((fn = ops->devo_quiesce) == NULL))
268*19397407SSherry Moore 		return (DDI_FAILURE);
269*19397407SSherry Moore 
270*19397407SSherry Moore 	return ((*fn)(devi));
271*19397407SSherry Moore }
272*19397407SSherry Moore 
2737c478bd9Sstevel@tonic-gate /*
2747c478bd9Sstevel@tonic-gate  * Leaf driver entry points. The following [cb]dev_* functions are *not* part
2757c478bd9Sstevel@tonic-gate  * of the DDI, please use functions defined in <sys/sunldi.h> and driver_lyr.c.
2767c478bd9Sstevel@tonic-gate  */
2777c478bd9Sstevel@tonic-gate int
2787c478bd9Sstevel@tonic-gate dev_open(dev_t *devp, int flag, int type, struct cred *cred)
2797c478bd9Sstevel@tonic-gate {
2807c478bd9Sstevel@tonic-gate 	struct cb_ops   *cb;
2817c478bd9Sstevel@tonic-gate 
2827c478bd9Sstevel@tonic-gate 	cb = devopsp[getmajor(*devp)]->devo_cb_ops;
2837c478bd9Sstevel@tonic-gate 	return ((*cb->cb_open)(devp, flag, type, cred));
2847c478bd9Sstevel@tonic-gate }
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate int
2877c478bd9Sstevel@tonic-gate dev_close(dev_t dev, int flag, int type, struct cred *cred)
2887c478bd9Sstevel@tonic-gate {
2897c478bd9Sstevel@tonic-gate 	struct cb_ops   *cb;
2907c478bd9Sstevel@tonic-gate 
2917c478bd9Sstevel@tonic-gate 	cb = (devopsp[getmajor(dev)])->devo_cb_ops;
2927c478bd9Sstevel@tonic-gate 	return ((*cb->cb_close)(dev, flag, type, cred));
2937c478bd9Sstevel@tonic-gate }
2947c478bd9Sstevel@tonic-gate 
2957c478bd9Sstevel@tonic-gate /*
2967c478bd9Sstevel@tonic-gate  * New Leaf driver open entry point.  We make a vnode and go through specfs
2977c478bd9Sstevel@tonic-gate  * in order to obtain open close exclusions guarantees.  Note that we drop
2987c478bd9Sstevel@tonic-gate  * OTYP_LYR if it was specified - we are going through specfs and it provides
2997c478bd9Sstevel@tonic-gate  * last close semantics (FKLYR is provided to open(9E)).  Also, since
3007c478bd9Sstevel@tonic-gate  * spec_open will drive attach via e_ddi_hold_devi_by_dev for a makespecvp
3017c478bd9Sstevel@tonic-gate  * vnode with no SDIP_SET on the common snode, the dev_lopen caller no longer
3027c478bd9Sstevel@tonic-gate  * needs to call ddi_hold_installed_driver.
3037c478bd9Sstevel@tonic-gate  */
3047c478bd9Sstevel@tonic-gate int
3057c478bd9Sstevel@tonic-gate dev_lopen(dev_t *devp, int flag, int otype, struct cred *cred)
3067c478bd9Sstevel@tonic-gate {
3077c478bd9Sstevel@tonic-gate 	struct vnode	*vp;
3087c478bd9Sstevel@tonic-gate 	int		error;
3097c478bd9Sstevel@tonic-gate 	struct vnode	*cvp;
3107c478bd9Sstevel@tonic-gate 
3117c478bd9Sstevel@tonic-gate 	vp = makespecvp(*devp, (otype == OTYP_BLK) ? VBLK : VCHR);
312da6c28aaSamw 	error = VOP_OPEN(&vp, flag | FKLYR, cred, NULL);
3137c478bd9Sstevel@tonic-gate 	if (error == 0) {
3147c478bd9Sstevel@tonic-gate 		/* Pick up the (possibly) new dev_t value. */
3157c478bd9Sstevel@tonic-gate 		*devp = vp->v_rdev;
3167c478bd9Sstevel@tonic-gate 
3177c478bd9Sstevel@tonic-gate 		/*
3187c478bd9Sstevel@tonic-gate 		 * Place extra hold on the common vnode, which contains the
3197c478bd9Sstevel@tonic-gate 		 * open count, so that it is not destroyed by the VN_RELE of
3207c478bd9Sstevel@tonic-gate 		 * the shadow makespecvp vnode below.
3217c478bd9Sstevel@tonic-gate 		 */
3227c478bd9Sstevel@tonic-gate 		cvp = STOV(VTOCS(vp));
3237c478bd9Sstevel@tonic-gate 		VN_HOLD(cvp);
3247c478bd9Sstevel@tonic-gate 	}
3257c478bd9Sstevel@tonic-gate 
3267c478bd9Sstevel@tonic-gate 	/* release the shadow makespecvp vnode. */
3277c478bd9Sstevel@tonic-gate 	VN_RELE(vp);
3287c478bd9Sstevel@tonic-gate 	return (error);
3297c478bd9Sstevel@tonic-gate }
3307c478bd9Sstevel@tonic-gate 
3317c478bd9Sstevel@tonic-gate /*
3327c478bd9Sstevel@tonic-gate  * Leaf driver close entry point.  We make a vnode and go through specfs in
3337c478bd9Sstevel@tonic-gate  * order to obtain open close exclusions guarantees.  Note that we drop
3347c478bd9Sstevel@tonic-gate  * OTYP_LYR if it was specified - we are going through specfs and it provides
3357c478bd9Sstevel@tonic-gate  * last close semantics (FLKYR is provided to close(9E)).
3367c478bd9Sstevel@tonic-gate  */
3377c478bd9Sstevel@tonic-gate int
3387c478bd9Sstevel@tonic-gate dev_lclose(dev_t dev, int flag, int otype, struct cred *cred)
3397c478bd9Sstevel@tonic-gate {
3407c478bd9Sstevel@tonic-gate 	struct vnode	*vp;
3417c478bd9Sstevel@tonic-gate 	int		error;
3427c478bd9Sstevel@tonic-gate 	struct vnode	*cvp;
3437c478bd9Sstevel@tonic-gate 	char		*funcname;
3447c478bd9Sstevel@tonic-gate 	ulong_t		offset;
3457c478bd9Sstevel@tonic-gate 
3467c478bd9Sstevel@tonic-gate 	vp = makespecvp(dev, (otype == OTYP_BLK) ? VBLK : VCHR);
347da6c28aaSamw 	error = VOP_CLOSE(vp, flag | FKLYR, 1, (offset_t)0, cred, NULL);
3487c478bd9Sstevel@tonic-gate 
3497c478bd9Sstevel@tonic-gate 	/*
3507c478bd9Sstevel@tonic-gate 	 * Release the extra dev_lopen hold on the common vnode. We inline a
3517c478bd9Sstevel@tonic-gate 	 * VN_RELE(cvp) call so that we can detect more dev_lclose calls than
3527c478bd9Sstevel@tonic-gate 	 * dev_lopen calls without panic. See vn_rele.  If our inline of
353da6c28aaSamw 	 * vn_rele called VOP_INACTIVE(cvp, CRED(), ...) we would panic on the
3547c478bd9Sstevel@tonic-gate 	 * "release the makespecvp vnode" VN_RELE(vp) that follows  - so
3557c478bd9Sstevel@tonic-gate 	 * instead we diagnose this situation.  Note that the driver has
3567c478bd9Sstevel@tonic-gate 	 * still seen a double close(9E), but that would have occurred with
3577c478bd9Sstevel@tonic-gate 	 * the old dev_close implementation too.
3587c478bd9Sstevel@tonic-gate 	 */
3597c478bd9Sstevel@tonic-gate 	cvp = STOV(VTOCS(vp));
3607c478bd9Sstevel@tonic-gate 	mutex_enter(&cvp->v_lock);
3617c478bd9Sstevel@tonic-gate 	switch (cvp->v_count) {
3627c478bd9Sstevel@tonic-gate 	default:
3637c478bd9Sstevel@tonic-gate 		cvp->v_count--;
3647c478bd9Sstevel@tonic-gate 		break;
3657c478bd9Sstevel@tonic-gate 
3667c478bd9Sstevel@tonic-gate 	case 0:
3677c478bd9Sstevel@tonic-gate 		VTOS(vp)->s_commonvp = NULL;	/* avoid panic */
3687c478bd9Sstevel@tonic-gate 		/*FALLTHROUGH*/
3697c478bd9Sstevel@tonic-gate 	case 1:
3707c478bd9Sstevel@tonic-gate 		/*
3717c478bd9Sstevel@tonic-gate 		 * The following message indicates a serious problem in the
3727c478bd9Sstevel@tonic-gate 		 * identified driver, the driver should be fixed. If obtaining
3737c478bd9Sstevel@tonic-gate 		 * a panic dump is needed to diagnose the driver problem then
3747c478bd9Sstevel@tonic-gate 		 * adding "set dev_lclose_ce=3" to /etc/system will cause a
3757c478bd9Sstevel@tonic-gate 		 * panic when this occurs.
3767c478bd9Sstevel@tonic-gate 		 */
3777c478bd9Sstevel@tonic-gate 		funcname = modgetsymname((uintptr_t)caller(), &offset);
3787c478bd9Sstevel@tonic-gate 		cmn_err(dev_lclose_ce, "dev_lclose: extra close of dev_t 0x%lx "
3797c478bd9Sstevel@tonic-gate 		    "from %s`%s()", dev, mod_containing_pc(caller()),
3807c478bd9Sstevel@tonic-gate 		    funcname ? funcname : "unknown...");
3817c478bd9Sstevel@tonic-gate 		break;
3827c478bd9Sstevel@tonic-gate 	}
3837c478bd9Sstevel@tonic-gate 	mutex_exit(&cvp->v_lock);
3847c478bd9Sstevel@tonic-gate 
3857c478bd9Sstevel@tonic-gate 	/* release the makespecvp vnode. */
3867c478bd9Sstevel@tonic-gate 	VN_RELE(vp);
3877c478bd9Sstevel@tonic-gate 	return (error);
3887c478bd9Sstevel@tonic-gate }
3897c478bd9Sstevel@tonic-gate 
3907c478bd9Sstevel@tonic-gate /*
3917c478bd9Sstevel@tonic-gate  * Returns -1 or the instance number of the given dev_t as
3927c478bd9Sstevel@tonic-gate  * interpreted by the device driver.  The code may load the driver
3937c478bd9Sstevel@tonic-gate  * but it does not attach any instances.
3947c478bd9Sstevel@tonic-gate  *
3957c478bd9Sstevel@tonic-gate  * Instance is supposed to be a int but drivers have assumed that
3967c478bd9Sstevel@tonic-gate  * the pointer was a pointer to "void *" instead of a pointer to
3977c478bd9Sstevel@tonic-gate  * "int *" so we now explicitly pass a pointer to "void *" and then
3987c478bd9Sstevel@tonic-gate  * cast the result to an int when returning the value.
3997c478bd9Sstevel@tonic-gate  */
4007c478bd9Sstevel@tonic-gate int
4017c478bd9Sstevel@tonic-gate dev_to_instance(dev_t dev)
4027c478bd9Sstevel@tonic-gate {
4037c478bd9Sstevel@tonic-gate 	major_t		major = getmajor(dev);
4047c478bd9Sstevel@tonic-gate 	struct dev_ops	*ops;
4057c478bd9Sstevel@tonic-gate 	void		*vinstance;
4067c478bd9Sstevel@tonic-gate 	int		error;
4077c478bd9Sstevel@tonic-gate 
4087c478bd9Sstevel@tonic-gate 	/* verify that the major number is reasonable and driver is loaded */
4097c478bd9Sstevel@tonic-gate 	if ((major >= devcnt) ||
4107c478bd9Sstevel@tonic-gate 	    ((ops = mod_hold_dev_by_major(major)) == NULL))
4117c478bd9Sstevel@tonic-gate 		return (-1);
4127c478bd9Sstevel@tonic-gate 	ASSERT(CB_DRV_INSTALLED(ops));
4137c478bd9Sstevel@tonic-gate 
4147c478bd9Sstevel@tonic-gate 	/* verify that it supports the getinfo(9E) entry point */
4157c478bd9Sstevel@tonic-gate 	if (ops->devo_getinfo == NULL) {
4167c478bd9Sstevel@tonic-gate 		mod_rele_dev_by_major(major);
4177c478bd9Sstevel@tonic-gate 		return (-1);
4187c478bd9Sstevel@tonic-gate 	}
4197c478bd9Sstevel@tonic-gate 
4207c478bd9Sstevel@tonic-gate 	/* ask the driver to extract the instance number from the devt */
4217c478bd9Sstevel@tonic-gate 	error = (*ops->devo_getinfo)(NULL, DDI_INFO_DEVT2INSTANCE,
4227c478bd9Sstevel@tonic-gate 	    (void *)dev, &vinstance);
4237c478bd9Sstevel@tonic-gate 
4247c478bd9Sstevel@tonic-gate 	/* release the driver */
4257c478bd9Sstevel@tonic-gate 	mod_rele_dev_by_major(major);
4267c478bd9Sstevel@tonic-gate 
4277c478bd9Sstevel@tonic-gate 	if (error != DDI_SUCCESS)
4287c478bd9Sstevel@tonic-gate 		return (-1);
4297c478bd9Sstevel@tonic-gate 
4307c478bd9Sstevel@tonic-gate 	return ((int)(uintptr_t)vinstance);
4317c478bd9Sstevel@tonic-gate }
4327c478bd9Sstevel@tonic-gate 
4337c478bd9Sstevel@tonic-gate static void
4347c478bd9Sstevel@tonic-gate bdev_strategy_tnf_probe(struct buf *bp)
4357c478bd9Sstevel@tonic-gate {
4367c478bd9Sstevel@tonic-gate 	/* Kernel probe */
4377c478bd9Sstevel@tonic-gate 	TNF_PROBE_5(strategy, "io blockio", /* CSTYLED */,
4387c478bd9Sstevel@tonic-gate 	    tnf_device, device, bp->b_edev,
4397c478bd9Sstevel@tonic-gate 	    tnf_diskaddr, block, bp->b_lblkno,
4407c478bd9Sstevel@tonic-gate 	    tnf_size, size, bp->b_bcount,
4417c478bd9Sstevel@tonic-gate 	    tnf_opaque, buf, bp,
4427c478bd9Sstevel@tonic-gate 	    tnf_bioflags, flags, bp->b_flags);
4437c478bd9Sstevel@tonic-gate }
4447c478bd9Sstevel@tonic-gate 
4457c478bd9Sstevel@tonic-gate int
4467c478bd9Sstevel@tonic-gate bdev_strategy(struct buf *bp)
4477c478bd9Sstevel@tonic-gate {
4487c478bd9Sstevel@tonic-gate 	struct dev_ops *ops;
4497c478bd9Sstevel@tonic-gate 
4507c478bd9Sstevel@tonic-gate 	ops = devopsp[getmajor(bp->b_edev)];
4517c478bd9Sstevel@tonic-gate 
4527c478bd9Sstevel@tonic-gate 	/*
4537c478bd9Sstevel@tonic-gate 	 * Before we hit the io:::start probe, we need to fill in the b_dip
4547c478bd9Sstevel@tonic-gate 	 * field of the buf structure.  This should be -- for the most part --
4557c478bd9Sstevel@tonic-gate 	 * incredibly cheap.  If you're in this code looking to bum cycles,
4567c478bd9Sstevel@tonic-gate 	 * there is almost certainly bigger game further down the I/O path...
4577c478bd9Sstevel@tonic-gate 	 */
4587c478bd9Sstevel@tonic-gate 	(void) ops->devo_getinfo(NULL, DDI_INFO_DEVT2DEVINFO,
4597c478bd9Sstevel@tonic-gate 	    (void *)bp->b_edev, (void **)&bp->b_dip);
4607c478bd9Sstevel@tonic-gate 
4617c478bd9Sstevel@tonic-gate 	DTRACE_IO1(start, struct buf *, bp);
4627c478bd9Sstevel@tonic-gate 	bp->b_flags |= B_STARTED;
4637c478bd9Sstevel@tonic-gate 
4647c478bd9Sstevel@tonic-gate 	/*
4657c478bd9Sstevel@tonic-gate 	 * Call the TNF probe here instead of the inline code
4667c478bd9Sstevel@tonic-gate 	 * to force our compiler to use the tail call optimization.
4677c478bd9Sstevel@tonic-gate 	 */
4687c478bd9Sstevel@tonic-gate 	bdev_strategy_tnf_probe(bp);
4697c478bd9Sstevel@tonic-gate 
4707c478bd9Sstevel@tonic-gate 	return (ops->devo_cb_ops->cb_strategy(bp));
4717c478bd9Sstevel@tonic-gate }
4727c478bd9Sstevel@tonic-gate 
4737c478bd9Sstevel@tonic-gate int
4747c478bd9Sstevel@tonic-gate bdev_print(dev_t dev, caddr_t str)
4757c478bd9Sstevel@tonic-gate {
4767c478bd9Sstevel@tonic-gate 	struct cb_ops	*cb;
4777c478bd9Sstevel@tonic-gate 
4787c478bd9Sstevel@tonic-gate 	cb = devopsp[getmajor(dev)]->devo_cb_ops;
4797c478bd9Sstevel@tonic-gate 	return ((*cb->cb_print)(dev, str));
4807c478bd9Sstevel@tonic-gate }
4817c478bd9Sstevel@tonic-gate 
482184cd04cScth /*
483184cd04cScth  * Return number of DEV_BSIZE byte blocks.
484184cd04cScth  */
4857c478bd9Sstevel@tonic-gate int
4867c478bd9Sstevel@tonic-gate bdev_size(dev_t dev)
4877c478bd9Sstevel@tonic-gate {
488184cd04cScth 	uint_t		nblocks;
489184cd04cScth 	uint_t		blksize;
490184cd04cScth 
491184cd04cScth 	if ((nblocks = e_ddi_getprop(dev, VBLK, "nblocks",
492184cd04cScth 	    DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, -1)) == -1)
493184cd04cScth 		return (-1);
494184cd04cScth 
495184cd04cScth 	/* Get blksize, default to DEV_BSIZE */
496184cd04cScth 	if ((blksize = e_ddi_getprop(dev, VBLK, "blksize",
497184cd04cScth 	    DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, -1)) == -1)
498184cd04cScth 		blksize = e_ddi_getprop(DDI_DEV_T_ANY, VBLK, "device-blksize",
499184cd04cScth 		    DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, DEV_BSIZE);
500184cd04cScth 
501184cd04cScth 	if (blksize >= DEV_BSIZE)
502184cd04cScth 		return (nblocks * (blksize / DEV_BSIZE));
503184cd04cScth 	else
504184cd04cScth 		return (nblocks / (DEV_BSIZE / blksize));
5057c478bd9Sstevel@tonic-gate }
5067c478bd9Sstevel@tonic-gate 
5077c478bd9Sstevel@tonic-gate /*
5087c478bd9Sstevel@tonic-gate  * Same for 64-bit Nblocks property
5097c478bd9Sstevel@tonic-gate  */
5107c478bd9Sstevel@tonic-gate uint64_t
5117c478bd9Sstevel@tonic-gate bdev_Size(dev_t dev)
5127c478bd9Sstevel@tonic-gate {
513184cd04cScth 	uint64_t	nblocks;
514184cd04cScth 	uint_t		blksize;
515184cd04cScth 
516184cd04cScth 	if ((nblocks = e_ddi_getprop_int64(dev, VBLK, "Nblocks",
517184cd04cScth 	    DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, -1)) == -1)
518184cd04cScth 		return (-1);
519184cd04cScth 
520184cd04cScth 	/* Get blksize, default to DEV_BSIZE */
521184cd04cScth 	if ((blksize = e_ddi_getprop(dev, VBLK, "blksize",
522184cd04cScth 	    DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, -1)) == -1)
523184cd04cScth 		blksize = e_ddi_getprop(DDI_DEV_T_ANY, VBLK, "device-blksize",
524184cd04cScth 		    DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, DEV_BSIZE);
525184cd04cScth 
526184cd04cScth 	if (blksize >= DEV_BSIZE)
527184cd04cScth 		return (nblocks * (blksize / DEV_BSIZE));
528184cd04cScth 	else
529184cd04cScth 		return (nblocks / (DEV_BSIZE / blksize));
5307c478bd9Sstevel@tonic-gate }
5317c478bd9Sstevel@tonic-gate 
5327c478bd9Sstevel@tonic-gate int
5337c478bd9Sstevel@tonic-gate bdev_dump(dev_t dev, caddr_t addr, daddr_t blkno, int blkcnt)
5347c478bd9Sstevel@tonic-gate {
5357c478bd9Sstevel@tonic-gate 	struct cb_ops	*cb;
5367c478bd9Sstevel@tonic-gate 
5377c478bd9Sstevel@tonic-gate 	cb = devopsp[getmajor(dev)]->devo_cb_ops;
5387c478bd9Sstevel@tonic-gate 	return ((*cb->cb_dump)(dev, addr, blkno, blkcnt));
5397c478bd9Sstevel@tonic-gate }
5407c478bd9Sstevel@tonic-gate 
5417c478bd9Sstevel@tonic-gate int
5427c478bd9Sstevel@tonic-gate cdev_read(dev_t dev, struct uio *uiop, struct cred *cred)
5437c478bd9Sstevel@tonic-gate {
5447c478bd9Sstevel@tonic-gate 	struct cb_ops	*cb;
5457c478bd9Sstevel@tonic-gate 
5467c478bd9Sstevel@tonic-gate 	cb = devopsp[getmajor(dev)]->devo_cb_ops;
5477c478bd9Sstevel@tonic-gate 	return ((*cb->cb_read)(dev, uiop, cred));
5487c478bd9Sstevel@tonic-gate }
5497c478bd9Sstevel@tonic-gate 
5507c478bd9Sstevel@tonic-gate int
5517c478bd9Sstevel@tonic-gate cdev_write(dev_t dev, struct uio *uiop, struct cred *cred)
5527c478bd9Sstevel@tonic-gate {
5537c478bd9Sstevel@tonic-gate 	struct cb_ops	*cb;
5547c478bd9Sstevel@tonic-gate 
5557c478bd9Sstevel@tonic-gate 	cb = devopsp[getmajor(dev)]->devo_cb_ops;
5567c478bd9Sstevel@tonic-gate 	return ((*cb->cb_write)(dev, uiop, cred));
5577c478bd9Sstevel@tonic-gate }
5587c478bd9Sstevel@tonic-gate 
5597c478bd9Sstevel@tonic-gate int
5607c478bd9Sstevel@tonic-gate cdev_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, struct cred *cred,
5617c478bd9Sstevel@tonic-gate     int *rvalp)
5627c478bd9Sstevel@tonic-gate {
5637c478bd9Sstevel@tonic-gate 	struct cb_ops	*cb;
5647c478bd9Sstevel@tonic-gate 
5657c478bd9Sstevel@tonic-gate 	cb = devopsp[getmajor(dev)]->devo_cb_ops;
5667c478bd9Sstevel@tonic-gate 	return ((*cb->cb_ioctl)(dev, cmd, arg, mode, cred, rvalp));
5677c478bd9Sstevel@tonic-gate }
5687c478bd9Sstevel@tonic-gate 
5697c478bd9Sstevel@tonic-gate int
5707c478bd9Sstevel@tonic-gate cdev_devmap(dev_t dev, devmap_cookie_t dhp, offset_t off, size_t len,
5717c478bd9Sstevel@tonic-gate 	size_t *maplen, uint_t mode)
5727c478bd9Sstevel@tonic-gate {
5737c478bd9Sstevel@tonic-gate 	struct cb_ops	*cb;
5747c478bd9Sstevel@tonic-gate 
5757c478bd9Sstevel@tonic-gate 	cb = devopsp[getmajor(dev)]->devo_cb_ops;
5767c478bd9Sstevel@tonic-gate 	return ((*cb->cb_devmap)(dev, dhp, off, len, maplen, mode));
5777c478bd9Sstevel@tonic-gate }
5787c478bd9Sstevel@tonic-gate 
5797c478bd9Sstevel@tonic-gate int
5807c478bd9Sstevel@tonic-gate cdev_mmap(int (*mapfunc)(dev_t, off_t, int), dev_t dev, off_t off, int prot)
5817c478bd9Sstevel@tonic-gate {
5827c478bd9Sstevel@tonic-gate 	return ((*mapfunc)(dev, off, prot));
5837c478bd9Sstevel@tonic-gate }
5847c478bd9Sstevel@tonic-gate 
5857c478bd9Sstevel@tonic-gate int
5867c478bd9Sstevel@tonic-gate cdev_segmap(dev_t dev, off_t off, struct as *as, caddr_t *addrp, off_t len,
5877c478bd9Sstevel@tonic-gate 	    uint_t prot, uint_t maxprot, uint_t flags, cred_t *credp)
5887c478bd9Sstevel@tonic-gate {
5897c478bd9Sstevel@tonic-gate 	struct cb_ops	*cb;
5907c478bd9Sstevel@tonic-gate 
5917c478bd9Sstevel@tonic-gate 	cb = devopsp[getmajor(dev)]->devo_cb_ops;
5927c478bd9Sstevel@tonic-gate 	return ((*cb->cb_segmap)(dev, off, as, addrp,
5937c478bd9Sstevel@tonic-gate 	    len, prot, maxprot, flags, credp));
5947c478bd9Sstevel@tonic-gate }
5957c478bd9Sstevel@tonic-gate 
5967c478bd9Sstevel@tonic-gate int
5977c478bd9Sstevel@tonic-gate cdev_poll(dev_t dev, short events, int anyyet, short *reventsp,
5987c478bd9Sstevel@tonic-gate 	struct pollhead **pollhdrp)
5997c478bd9Sstevel@tonic-gate {
6007c478bd9Sstevel@tonic-gate 	struct cb_ops	*cb;
6017c478bd9Sstevel@tonic-gate 
6027c478bd9Sstevel@tonic-gate 	cb = devopsp[getmajor(dev)]->devo_cb_ops;
6037c478bd9Sstevel@tonic-gate 	return ((*cb->cb_chpoll)(dev, events, anyyet, reventsp, pollhdrp));
6047c478bd9Sstevel@tonic-gate }
6057c478bd9Sstevel@tonic-gate 
6067c478bd9Sstevel@tonic-gate /*
6077c478bd9Sstevel@tonic-gate  * A 'size' property can be provided by a VCHR device.
6087c478bd9Sstevel@tonic-gate  *
6097c478bd9Sstevel@tonic-gate  * Since it's defined as zero for STREAMS devices, so we avoid the
6107c478bd9Sstevel@tonic-gate  * overhead of looking it up.  Note also that we don't force an
6117c478bd9Sstevel@tonic-gate  * unused driver into memory simply to ask about it's size.  We also
6127c478bd9Sstevel@tonic-gate  * don't bother to ask it its size unless it's already been attached
6137c478bd9Sstevel@tonic-gate  * (the attach routine is the earliest place the property will be created)
6147c478bd9Sstevel@tonic-gate  *
6157c478bd9Sstevel@tonic-gate  * XXX	In an ideal world, we'd call this at VOP_GETATTR() time.
6167c478bd9Sstevel@tonic-gate  */
6177c478bd9Sstevel@tonic-gate int
6187c478bd9Sstevel@tonic-gate cdev_size(dev_t dev)
6197c478bd9Sstevel@tonic-gate {
6207c478bd9Sstevel@tonic-gate 	major_t maj;
6217c478bd9Sstevel@tonic-gate 	struct devnames *dnp;
6227c478bd9Sstevel@tonic-gate 
6237c478bd9Sstevel@tonic-gate 	if ((maj = getmajor(dev)) >= devcnt)
6247c478bd9Sstevel@tonic-gate 		return (0);
6257c478bd9Sstevel@tonic-gate 
6267c478bd9Sstevel@tonic-gate 	dnp = &(devnamesp[maj]);
6277c478bd9Sstevel@tonic-gate 	LOCK_DEV_OPS(&dnp->dn_lock);
6287c478bd9Sstevel@tonic-gate 	if (devopsp[maj] && devopsp[maj]->devo_cb_ops &&
6297c478bd9Sstevel@tonic-gate 	    !devopsp[maj]->devo_cb_ops->cb_str) {
6307c478bd9Sstevel@tonic-gate 		UNLOCK_DEV_OPS(&dnp->dn_lock);
6317c478bd9Sstevel@tonic-gate 		return (e_ddi_getprop(dev, VCHR, "size",
6327c478bd9Sstevel@tonic-gate 		    DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, 0));
6337c478bd9Sstevel@tonic-gate 	}
6347c478bd9Sstevel@tonic-gate 	UNLOCK_DEV_OPS(&dnp->dn_lock);
6357c478bd9Sstevel@tonic-gate 	return (0);
6367c478bd9Sstevel@tonic-gate }
6377c478bd9Sstevel@tonic-gate 
6387c478bd9Sstevel@tonic-gate /*
6397c478bd9Sstevel@tonic-gate  * same for 64-bit Size property
6407c478bd9Sstevel@tonic-gate  */
6417c478bd9Sstevel@tonic-gate uint64_t
6427c478bd9Sstevel@tonic-gate cdev_Size(dev_t dev)
6437c478bd9Sstevel@tonic-gate {
6447c478bd9Sstevel@tonic-gate 	major_t maj;
6457c478bd9Sstevel@tonic-gate 	struct devnames *dnp;
6467c478bd9Sstevel@tonic-gate 
6477c478bd9Sstevel@tonic-gate 	if ((maj = getmajor(dev)) >= devcnt)
6487c478bd9Sstevel@tonic-gate 		return (0);
6497c478bd9Sstevel@tonic-gate 
6507c478bd9Sstevel@tonic-gate 	dnp = &(devnamesp[maj]);
6517c478bd9Sstevel@tonic-gate 	LOCK_DEV_OPS(&dnp->dn_lock);
6527c478bd9Sstevel@tonic-gate 	if (devopsp[maj] && devopsp[maj]->devo_cb_ops &&
6537c478bd9Sstevel@tonic-gate 	    !devopsp[maj]->devo_cb_ops->cb_str) {
6547c478bd9Sstevel@tonic-gate 		UNLOCK_DEV_OPS(&dnp->dn_lock);
6557c478bd9Sstevel@tonic-gate 		return (e_ddi_getprop_int64(dev, VCHR, "Size",
6567c478bd9Sstevel@tonic-gate 		    DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, 0));
6577c478bd9Sstevel@tonic-gate 	}
6587c478bd9Sstevel@tonic-gate 	UNLOCK_DEV_OPS(&dnp->dn_lock);
6597c478bd9Sstevel@tonic-gate 	return (0);
6607c478bd9Sstevel@tonic-gate }
6617c478bd9Sstevel@tonic-gate 
6627c478bd9Sstevel@tonic-gate /*
6637c478bd9Sstevel@tonic-gate  * XXX	This routine is poorly named, because block devices can and do
6647c478bd9Sstevel@tonic-gate  *	have properties (see bdev_size() above).
6657c478bd9Sstevel@tonic-gate  *
6667c478bd9Sstevel@tonic-gate  * XXX	fix the comment in devops.h that claims that cb_prop_op
6677c478bd9Sstevel@tonic-gate  *	is character-only.
6687c478bd9Sstevel@tonic-gate  */
6697c478bd9Sstevel@tonic-gate int
6707c478bd9Sstevel@tonic-gate cdev_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, int mod_flags,
6717c478bd9Sstevel@tonic-gate     char *name, caddr_t valuep, int *lengthp)
6727c478bd9Sstevel@tonic-gate {
6737c478bd9Sstevel@tonic-gate 	struct cb_ops	*cb;
6747c478bd9Sstevel@tonic-gate 
6757c478bd9Sstevel@tonic-gate 	if ((cb = devopsp[DEVI(dip)->devi_major]->devo_cb_ops) == NULL)
6767c478bd9Sstevel@tonic-gate 		return (DDI_PROP_NOT_FOUND);
6777c478bd9Sstevel@tonic-gate 
6787c478bd9Sstevel@tonic-gate 	return ((*cb->cb_prop_op)(dev, dip, prop_op, mod_flags,
6797c478bd9Sstevel@tonic-gate 	    name, valuep, lengthp));
6807c478bd9Sstevel@tonic-gate }
681