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