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 */ 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 */ 105*96c4a178SChris Horne if ((fn = ops->devo_probe) == NULL) { 106*96c4a178SChris Horne if (ddi_dev_is_sid(devi) == DDI_SUCCESS) 1077c478bd9Sstevel@tonic-gate rv = DDI_PROBE_DONTCARE; 1087c478bd9Sstevel@tonic-gate else 109*96c4a178SChris Horne rv = DDI_PROBE_FAILURE; 110*96c4a178SChris Horne } else 1117c478bd9Sstevel@tonic-gate rv = (*fn)(devi); 1127c478bd9Sstevel@tonic-gate 1137c478bd9Sstevel@tonic-gate switch (rv) { 1147c478bd9Sstevel@tonic-gate case DDI_PROBE_DONTCARE: 1157c478bd9Sstevel@tonic-gate case DDI_PROBE_SUCCESS: 1167c478bd9Sstevel@tonic-gate probe_failed = 0; 1177c478bd9Sstevel@tonic-gate break; 1187c478bd9Sstevel@tonic-gate default: 1197c478bd9Sstevel@tonic-gate probe_failed = 1; 1207c478bd9Sstevel@tonic-gate break; 1217c478bd9Sstevel@tonic-gate } 1227c478bd9Sstevel@tonic-gate pm_post_probe(&ppm_cookie, rv, probe_failed); 1237c478bd9Sstevel@tonic-gate 1247c478bd9Sstevel@tonic-gate return (rv); 1257c478bd9Sstevel@tonic-gate } 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate /* 1297c478bd9Sstevel@tonic-gate * devi_attach() 1307c478bd9Sstevel@tonic-gate * attach a device instance to the system if the driver supplies an 1317c478bd9Sstevel@tonic-gate * attach(9E) entrypoint. 1327c478bd9Sstevel@tonic-gate */ 1337c478bd9Sstevel@tonic-gate int 1347c478bd9Sstevel@tonic-gate devi_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 1357c478bd9Sstevel@tonic-gate { 1367c478bd9Sstevel@tonic-gate struct dev_ops *ops; 1377c478bd9Sstevel@tonic-gate int error; 1387c478bd9Sstevel@tonic-gate int (*fn)(dev_info_t *, ddi_attach_cmd_t); 1397c478bd9Sstevel@tonic-gate pm_ppm_cookie_t pc; 1407c478bd9Sstevel@tonic-gate 1417c478bd9Sstevel@tonic-gate if ((error = mdi_pre_attach(devi, cmd)) != DDI_SUCCESS) { 1427c478bd9Sstevel@tonic-gate return (error); 1437c478bd9Sstevel@tonic-gate } 1447c478bd9Sstevel@tonic-gate 1457c478bd9Sstevel@tonic-gate pm_pre_attach(devi, &pc, cmd); 1467c478bd9Sstevel@tonic-gate 1477c478bd9Sstevel@tonic-gate if ((cmd == DDI_RESUME || cmd == DDI_PM_RESUME) && 1487c478bd9Sstevel@tonic-gate e_ddi_parental_suspend_resume(devi)) { 1497c478bd9Sstevel@tonic-gate error = e_ddi_resume(devi, cmd); 1507c478bd9Sstevel@tonic-gate goto done; 1517c478bd9Sstevel@tonic-gate } 1527c478bd9Sstevel@tonic-gate ops = ddi_get_driver(devi); 1537c478bd9Sstevel@tonic-gate ASSERT(ops); 1547c478bd9Sstevel@tonic-gate if ((fn = ops->devo_attach) == NULL) { 1557c478bd9Sstevel@tonic-gate error = DDI_FAILURE; 1567c478bd9Sstevel@tonic-gate goto done; 1577c478bd9Sstevel@tonic-gate } 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate /* 1607c478bd9Sstevel@tonic-gate * Call the driver's attach(9e) entrypoint 1617c478bd9Sstevel@tonic-gate */ 1627c478bd9Sstevel@tonic-gate i_attach_ctlop(devi, cmd, DDI_PRE, 0); 1637c478bd9Sstevel@tonic-gate error = (*fn)(devi, cmd); 1647c478bd9Sstevel@tonic-gate i_attach_ctlop(devi, cmd, DDI_POST, error); 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate done: 1677c478bd9Sstevel@tonic-gate pm_post_attach(&pc, error); 1687c478bd9Sstevel@tonic-gate mdi_post_attach(devi, cmd, error); 1697c478bd9Sstevel@tonic-gate 1707c478bd9Sstevel@tonic-gate return (error); 1717c478bd9Sstevel@tonic-gate } 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate /* 1747c478bd9Sstevel@tonic-gate * devi_detach() 1757c478bd9Sstevel@tonic-gate * detach a device instance from the system if the driver supplies a 1767c478bd9Sstevel@tonic-gate * detach(9E) entrypoint. 1777c478bd9Sstevel@tonic-gate */ 1787c478bd9Sstevel@tonic-gate int 1797c478bd9Sstevel@tonic-gate devi_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 1807c478bd9Sstevel@tonic-gate { 1817c478bd9Sstevel@tonic-gate struct dev_ops *ops; 1827c478bd9Sstevel@tonic-gate int error; 1837c478bd9Sstevel@tonic-gate int (*fn)(dev_info_t *, ddi_detach_cmd_t); 1847c478bd9Sstevel@tonic-gate pm_ppm_cookie_t pc; 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate ASSERT(cmd == DDI_SUSPEND || cmd == DDI_PM_SUSPEND || 1877c478bd9Sstevel@tonic-gate cmd == DDI_DETACH); 1887c478bd9Sstevel@tonic-gate 1897c478bd9Sstevel@tonic-gate if ((cmd == DDI_SUSPEND || cmd == DDI_PM_SUSPEND) && 1907c478bd9Sstevel@tonic-gate e_ddi_parental_suspend_resume(devi)) { 1917c478bd9Sstevel@tonic-gate return (e_ddi_suspend(devi, cmd)); 1927c478bd9Sstevel@tonic-gate } 1937c478bd9Sstevel@tonic-gate ops = ddi_get_driver(devi); 1947c478bd9Sstevel@tonic-gate ASSERT(ops); 1957c478bd9Sstevel@tonic-gate if ((fn = ops->devo_detach) == NULL) 1967c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate if ((error = mdi_pre_detach(devi, cmd)) != DDI_SUCCESS) { 1997c478bd9Sstevel@tonic-gate return (error); 2007c478bd9Sstevel@tonic-gate } 2017c478bd9Sstevel@tonic-gate i_detach_ctlop(devi, cmd, DDI_PRE, 0); 2027c478bd9Sstevel@tonic-gate pm_pre_detach(devi, cmd, &pc); 2037c478bd9Sstevel@tonic-gate 2047c478bd9Sstevel@tonic-gate /* 2057c478bd9Sstevel@tonic-gate * Call the driver's detach routine 2067c478bd9Sstevel@tonic-gate */ 2077c478bd9Sstevel@tonic-gate error = (*fn)(devi, cmd); 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate pm_post_detach(&pc, error); 2107c478bd9Sstevel@tonic-gate i_detach_ctlop(devi, cmd, DDI_POST, error); 2117c478bd9Sstevel@tonic-gate mdi_post_detach(devi, cmd, error); 2127c478bd9Sstevel@tonic-gate 2137c478bd9Sstevel@tonic-gate return (error); 2147c478bd9Sstevel@tonic-gate } 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate static void 2177c478bd9Sstevel@tonic-gate i_attach_ctlop(dev_info_t *devi, ddi_attach_cmd_t cmd, ddi_pre_post_t w, 2187c478bd9Sstevel@tonic-gate int ret) 2197c478bd9Sstevel@tonic-gate { 2207c478bd9Sstevel@tonic-gate int error; 2217c478bd9Sstevel@tonic-gate struct attachspec as; 2227c478bd9Sstevel@tonic-gate dev_info_t *pdip = ddi_get_parent(devi); 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate as.cmd = cmd; 2257c478bd9Sstevel@tonic-gate as.when = w; 2267c478bd9Sstevel@tonic-gate as.pdip = pdip; 2277c478bd9Sstevel@tonic-gate as.result = ret; 2287c478bd9Sstevel@tonic-gate (void) ddi_ctlops(devi, devi, DDI_CTLOPS_ATTACH, &as, &error); 2297c478bd9Sstevel@tonic-gate } 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate static void 2327c478bd9Sstevel@tonic-gate i_detach_ctlop(dev_info_t *devi, ddi_detach_cmd_t cmd, ddi_pre_post_t w, 2337c478bd9Sstevel@tonic-gate int ret) 2347c478bd9Sstevel@tonic-gate { 2357c478bd9Sstevel@tonic-gate int error; 2367c478bd9Sstevel@tonic-gate struct detachspec ds; 2377c478bd9Sstevel@tonic-gate dev_info_t *pdip = ddi_get_parent(devi); 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate ds.cmd = cmd; 2407c478bd9Sstevel@tonic-gate ds.when = w; 2417c478bd9Sstevel@tonic-gate ds.pdip = pdip; 2427c478bd9Sstevel@tonic-gate ds.result = ret; 2437c478bd9Sstevel@tonic-gate (void) ddi_ctlops(devi, devi, DDI_CTLOPS_DETACH, &ds, &error); 2447c478bd9Sstevel@tonic-gate } 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate /* 2477c478bd9Sstevel@tonic-gate * This entry point not defined by Solaris 2.0 DDI/DKI, so 2487c478bd9Sstevel@tonic-gate * its inclusion here is somewhat moot. 2497c478bd9Sstevel@tonic-gate */ 2507c478bd9Sstevel@tonic-gate int 2517c478bd9Sstevel@tonic-gate devi_reset(dev_info_t *devi, ddi_reset_cmd_t cmd) 2527c478bd9Sstevel@tonic-gate { 2537c478bd9Sstevel@tonic-gate struct dev_ops *ops; 2547c478bd9Sstevel@tonic-gate int (*fn)(dev_info_t *, ddi_reset_cmd_t); 2557c478bd9Sstevel@tonic-gate 2567c478bd9Sstevel@tonic-gate if ((ops = ddi_get_driver(devi)) == NULL || 2577c478bd9Sstevel@tonic-gate (fn = ops->devo_reset) == NULL) 2587c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2597c478bd9Sstevel@tonic-gate 2607c478bd9Sstevel@tonic-gate return ((*fn)(devi, cmd)); 2617c478bd9Sstevel@tonic-gate } 2627c478bd9Sstevel@tonic-gate 26319397407SSherry Moore int 26419397407SSherry Moore devi_quiesce(dev_info_t *devi) 26519397407SSherry Moore { 26619397407SSherry Moore struct dev_ops *ops; 26719397407SSherry Moore int (*fn)(dev_info_t *); 26819397407SSherry Moore 26919397407SSherry Moore if (((ops = ddi_get_driver(devi)) == NULL) || 27019397407SSherry Moore (ops->devo_rev < 4) || ((fn = ops->devo_quiesce) == NULL)) 27119397407SSherry Moore return (DDI_FAILURE); 27219397407SSherry Moore 27319397407SSherry Moore return ((*fn)(devi)); 27419397407SSherry Moore } 27519397407SSherry Moore 2767c478bd9Sstevel@tonic-gate /* 2777c478bd9Sstevel@tonic-gate * Leaf driver entry points. The following [cb]dev_* functions are *not* part 2787c478bd9Sstevel@tonic-gate * of the DDI, please use functions defined in <sys/sunldi.h> and driver_lyr.c. 2797c478bd9Sstevel@tonic-gate */ 2807c478bd9Sstevel@tonic-gate int 2817c478bd9Sstevel@tonic-gate dev_open(dev_t *devp, int flag, int type, struct cred *cred) 2827c478bd9Sstevel@tonic-gate { 2837c478bd9Sstevel@tonic-gate struct cb_ops *cb; 2847c478bd9Sstevel@tonic-gate 2857c478bd9Sstevel@tonic-gate cb = devopsp[getmajor(*devp)]->devo_cb_ops; 2867c478bd9Sstevel@tonic-gate return ((*cb->cb_open)(devp, flag, type, cred)); 2877c478bd9Sstevel@tonic-gate } 2887c478bd9Sstevel@tonic-gate 2897c478bd9Sstevel@tonic-gate int 2907c478bd9Sstevel@tonic-gate dev_close(dev_t dev, int flag, int type, struct cred *cred) 2917c478bd9Sstevel@tonic-gate { 2927c478bd9Sstevel@tonic-gate struct cb_ops *cb; 2937c478bd9Sstevel@tonic-gate 2947c478bd9Sstevel@tonic-gate cb = (devopsp[getmajor(dev)])->devo_cb_ops; 2957c478bd9Sstevel@tonic-gate return ((*cb->cb_close)(dev, flag, type, cred)); 2967c478bd9Sstevel@tonic-gate } 2977c478bd9Sstevel@tonic-gate 2987c478bd9Sstevel@tonic-gate /* 2997c478bd9Sstevel@tonic-gate * New Leaf driver open entry point. We make a vnode and go through specfs 3007c478bd9Sstevel@tonic-gate * in order to obtain open close exclusions guarantees. Note that we drop 3017c478bd9Sstevel@tonic-gate * OTYP_LYR if it was specified - we are going through specfs and it provides 3027c478bd9Sstevel@tonic-gate * last close semantics (FKLYR is provided to open(9E)). Also, since 3037c478bd9Sstevel@tonic-gate * spec_open will drive attach via e_ddi_hold_devi_by_dev for a makespecvp 3047c478bd9Sstevel@tonic-gate * vnode with no SDIP_SET on the common snode, the dev_lopen caller no longer 3057c478bd9Sstevel@tonic-gate * needs to call ddi_hold_installed_driver. 3067c478bd9Sstevel@tonic-gate */ 3077c478bd9Sstevel@tonic-gate int 3087c478bd9Sstevel@tonic-gate dev_lopen(dev_t *devp, int flag, int otype, struct cred *cred) 3097c478bd9Sstevel@tonic-gate { 3107c478bd9Sstevel@tonic-gate struct vnode *vp; 3117c478bd9Sstevel@tonic-gate int error; 3127c478bd9Sstevel@tonic-gate struct vnode *cvp; 3137c478bd9Sstevel@tonic-gate 3147c478bd9Sstevel@tonic-gate vp = makespecvp(*devp, (otype == OTYP_BLK) ? VBLK : VCHR); 315da6c28aaSamw error = VOP_OPEN(&vp, flag | FKLYR, cred, NULL); 3167c478bd9Sstevel@tonic-gate if (error == 0) { 3177c478bd9Sstevel@tonic-gate /* Pick up the (possibly) new dev_t value. */ 3187c478bd9Sstevel@tonic-gate *devp = vp->v_rdev; 3197c478bd9Sstevel@tonic-gate 3207c478bd9Sstevel@tonic-gate /* 3217c478bd9Sstevel@tonic-gate * Place extra hold on the common vnode, which contains the 3227c478bd9Sstevel@tonic-gate * open count, so that it is not destroyed by the VN_RELE of 3237c478bd9Sstevel@tonic-gate * the shadow makespecvp vnode below. 3247c478bd9Sstevel@tonic-gate */ 3257c478bd9Sstevel@tonic-gate cvp = STOV(VTOCS(vp)); 3267c478bd9Sstevel@tonic-gate VN_HOLD(cvp); 3277c478bd9Sstevel@tonic-gate } 3287c478bd9Sstevel@tonic-gate 3297c478bd9Sstevel@tonic-gate /* release the shadow makespecvp vnode. */ 3307c478bd9Sstevel@tonic-gate VN_RELE(vp); 3317c478bd9Sstevel@tonic-gate return (error); 3327c478bd9Sstevel@tonic-gate } 3337c478bd9Sstevel@tonic-gate 3347c478bd9Sstevel@tonic-gate /* 3357c478bd9Sstevel@tonic-gate * Leaf driver close entry point. We make a vnode and go through specfs in 3367c478bd9Sstevel@tonic-gate * order to obtain open close exclusions guarantees. Note that we drop 3377c478bd9Sstevel@tonic-gate * OTYP_LYR if it was specified - we are going through specfs and it provides 3387c478bd9Sstevel@tonic-gate * last close semantics (FLKYR is provided to close(9E)). 3397c478bd9Sstevel@tonic-gate */ 3407c478bd9Sstevel@tonic-gate int 3417c478bd9Sstevel@tonic-gate dev_lclose(dev_t dev, int flag, int otype, struct cred *cred) 3427c478bd9Sstevel@tonic-gate { 3437c478bd9Sstevel@tonic-gate struct vnode *vp; 3447c478bd9Sstevel@tonic-gate int error; 3457c478bd9Sstevel@tonic-gate struct vnode *cvp; 3467c478bd9Sstevel@tonic-gate char *funcname; 3477c478bd9Sstevel@tonic-gate ulong_t offset; 3487c478bd9Sstevel@tonic-gate 3497c478bd9Sstevel@tonic-gate vp = makespecvp(dev, (otype == OTYP_BLK) ? VBLK : VCHR); 350da6c28aaSamw error = VOP_CLOSE(vp, flag | FKLYR, 1, (offset_t)0, cred, NULL); 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate /* 3537c478bd9Sstevel@tonic-gate * Release the extra dev_lopen hold on the common vnode. We inline a 3547c478bd9Sstevel@tonic-gate * VN_RELE(cvp) call so that we can detect more dev_lclose calls than 3557c478bd9Sstevel@tonic-gate * dev_lopen calls without panic. See vn_rele. If our inline of 356da6c28aaSamw * vn_rele called VOP_INACTIVE(cvp, CRED(), ...) we would panic on the 3577c478bd9Sstevel@tonic-gate * "release the makespecvp vnode" VN_RELE(vp) that follows - so 3587c478bd9Sstevel@tonic-gate * instead we diagnose this situation. Note that the driver has 3597c478bd9Sstevel@tonic-gate * still seen a double close(9E), but that would have occurred with 3607c478bd9Sstevel@tonic-gate * the old dev_close implementation too. 3617c478bd9Sstevel@tonic-gate */ 3627c478bd9Sstevel@tonic-gate cvp = STOV(VTOCS(vp)); 3637c478bd9Sstevel@tonic-gate mutex_enter(&cvp->v_lock); 3647c478bd9Sstevel@tonic-gate switch (cvp->v_count) { 3657c478bd9Sstevel@tonic-gate default: 3667c478bd9Sstevel@tonic-gate cvp->v_count--; 3677c478bd9Sstevel@tonic-gate break; 3687c478bd9Sstevel@tonic-gate 3697c478bd9Sstevel@tonic-gate case 0: 3707c478bd9Sstevel@tonic-gate VTOS(vp)->s_commonvp = NULL; /* avoid panic */ 3717c478bd9Sstevel@tonic-gate /*FALLTHROUGH*/ 3727c478bd9Sstevel@tonic-gate case 1: 3737c478bd9Sstevel@tonic-gate /* 3747c478bd9Sstevel@tonic-gate * The following message indicates a serious problem in the 3757c478bd9Sstevel@tonic-gate * identified driver, the driver should be fixed. If obtaining 3767c478bd9Sstevel@tonic-gate * a panic dump is needed to diagnose the driver problem then 3777c478bd9Sstevel@tonic-gate * adding "set dev_lclose_ce=3" to /etc/system will cause a 3787c478bd9Sstevel@tonic-gate * panic when this occurs. 3797c478bd9Sstevel@tonic-gate */ 3807c478bd9Sstevel@tonic-gate funcname = modgetsymname((uintptr_t)caller(), &offset); 3817c478bd9Sstevel@tonic-gate cmn_err(dev_lclose_ce, "dev_lclose: extra close of dev_t 0x%lx " 3827c478bd9Sstevel@tonic-gate "from %s`%s()", dev, mod_containing_pc(caller()), 3837c478bd9Sstevel@tonic-gate funcname ? funcname : "unknown..."); 3847c478bd9Sstevel@tonic-gate break; 3857c478bd9Sstevel@tonic-gate } 3867c478bd9Sstevel@tonic-gate mutex_exit(&cvp->v_lock); 3877c478bd9Sstevel@tonic-gate 3887c478bd9Sstevel@tonic-gate /* release the makespecvp vnode. */ 3897c478bd9Sstevel@tonic-gate VN_RELE(vp); 3907c478bd9Sstevel@tonic-gate return (error); 3917c478bd9Sstevel@tonic-gate } 3927c478bd9Sstevel@tonic-gate 3937c478bd9Sstevel@tonic-gate /* 3947c478bd9Sstevel@tonic-gate * Returns -1 or the instance number of the given dev_t as 3957c478bd9Sstevel@tonic-gate * interpreted by the device driver. The code may load the driver 3967c478bd9Sstevel@tonic-gate * but it does not attach any instances. 3977c478bd9Sstevel@tonic-gate * 3987c478bd9Sstevel@tonic-gate * Instance is supposed to be a int but drivers have assumed that 3997c478bd9Sstevel@tonic-gate * the pointer was a pointer to "void *" instead of a pointer to 4007c478bd9Sstevel@tonic-gate * "int *" so we now explicitly pass a pointer to "void *" and then 4017c478bd9Sstevel@tonic-gate * cast the result to an int when returning the value. 4027c478bd9Sstevel@tonic-gate */ 4037c478bd9Sstevel@tonic-gate int 4047c478bd9Sstevel@tonic-gate dev_to_instance(dev_t dev) 4057c478bd9Sstevel@tonic-gate { 4067c478bd9Sstevel@tonic-gate major_t major = getmajor(dev); 4077c478bd9Sstevel@tonic-gate struct dev_ops *ops; 4087c478bd9Sstevel@tonic-gate void *vinstance; 4097c478bd9Sstevel@tonic-gate int error; 4107c478bd9Sstevel@tonic-gate 411c9cc1492SJerry Gilliam /* verify that the driver is loaded */ 412c9cc1492SJerry Gilliam if ((ops = mod_hold_dev_by_major(major)) == NULL) 4137c478bd9Sstevel@tonic-gate return (-1); 4147c478bd9Sstevel@tonic-gate ASSERT(CB_DRV_INSTALLED(ops)); 4157c478bd9Sstevel@tonic-gate 4167c478bd9Sstevel@tonic-gate /* verify that it supports the getinfo(9E) entry point */ 4177c478bd9Sstevel@tonic-gate if (ops->devo_getinfo == NULL) { 4187c478bd9Sstevel@tonic-gate mod_rele_dev_by_major(major); 4197c478bd9Sstevel@tonic-gate return (-1); 4207c478bd9Sstevel@tonic-gate } 4217c478bd9Sstevel@tonic-gate 4227c478bd9Sstevel@tonic-gate /* ask the driver to extract the instance number from the devt */ 4237c478bd9Sstevel@tonic-gate error = (*ops->devo_getinfo)(NULL, DDI_INFO_DEVT2INSTANCE, 4247c478bd9Sstevel@tonic-gate (void *)dev, &vinstance); 4257c478bd9Sstevel@tonic-gate 4267c478bd9Sstevel@tonic-gate /* release the driver */ 4277c478bd9Sstevel@tonic-gate mod_rele_dev_by_major(major); 4287c478bd9Sstevel@tonic-gate 4297c478bd9Sstevel@tonic-gate if (error != DDI_SUCCESS) 4307c478bd9Sstevel@tonic-gate return (-1); 4317c478bd9Sstevel@tonic-gate 4327c478bd9Sstevel@tonic-gate return ((int)(uintptr_t)vinstance); 4337c478bd9Sstevel@tonic-gate } 4347c478bd9Sstevel@tonic-gate 4357c478bd9Sstevel@tonic-gate static void 4367c478bd9Sstevel@tonic-gate bdev_strategy_tnf_probe(struct buf *bp) 4377c478bd9Sstevel@tonic-gate { 4387c478bd9Sstevel@tonic-gate /* Kernel probe */ 4397c478bd9Sstevel@tonic-gate TNF_PROBE_5(strategy, "io blockio", /* CSTYLED */, 4407c478bd9Sstevel@tonic-gate tnf_device, device, bp->b_edev, 4417c478bd9Sstevel@tonic-gate tnf_diskaddr, block, bp->b_lblkno, 4427c478bd9Sstevel@tonic-gate tnf_size, size, bp->b_bcount, 4437c478bd9Sstevel@tonic-gate tnf_opaque, buf, bp, 4447c478bd9Sstevel@tonic-gate tnf_bioflags, flags, bp->b_flags); 4457c478bd9Sstevel@tonic-gate } 4467c478bd9Sstevel@tonic-gate 4477c478bd9Sstevel@tonic-gate int 4487c478bd9Sstevel@tonic-gate bdev_strategy(struct buf *bp) 4497c478bd9Sstevel@tonic-gate { 4507c478bd9Sstevel@tonic-gate struct dev_ops *ops; 4517c478bd9Sstevel@tonic-gate 4527c478bd9Sstevel@tonic-gate ops = devopsp[getmajor(bp->b_edev)]; 4537c478bd9Sstevel@tonic-gate 4547c478bd9Sstevel@tonic-gate /* 4557c478bd9Sstevel@tonic-gate * Before we hit the io:::start probe, we need to fill in the b_dip 4567c478bd9Sstevel@tonic-gate * field of the buf structure. This should be -- for the most part -- 4577c478bd9Sstevel@tonic-gate * incredibly cheap. If you're in this code looking to bum cycles, 4587c478bd9Sstevel@tonic-gate * there is almost certainly bigger game further down the I/O path... 4597c478bd9Sstevel@tonic-gate */ 4607c478bd9Sstevel@tonic-gate (void) ops->devo_getinfo(NULL, DDI_INFO_DEVT2DEVINFO, 4617c478bd9Sstevel@tonic-gate (void *)bp->b_edev, (void **)&bp->b_dip); 4627c478bd9Sstevel@tonic-gate 4637c478bd9Sstevel@tonic-gate DTRACE_IO1(start, struct buf *, bp); 4647c478bd9Sstevel@tonic-gate bp->b_flags |= B_STARTED; 4657c478bd9Sstevel@tonic-gate 4667c478bd9Sstevel@tonic-gate /* 4677c478bd9Sstevel@tonic-gate * Call the TNF probe here instead of the inline code 4687c478bd9Sstevel@tonic-gate * to force our compiler to use the tail call optimization. 4697c478bd9Sstevel@tonic-gate */ 4707c478bd9Sstevel@tonic-gate bdev_strategy_tnf_probe(bp); 4717c478bd9Sstevel@tonic-gate 4727c478bd9Sstevel@tonic-gate return (ops->devo_cb_ops->cb_strategy(bp)); 4737c478bd9Sstevel@tonic-gate } 4747c478bd9Sstevel@tonic-gate 4757c478bd9Sstevel@tonic-gate int 4767c478bd9Sstevel@tonic-gate bdev_print(dev_t dev, caddr_t str) 4777c478bd9Sstevel@tonic-gate { 4787c478bd9Sstevel@tonic-gate struct cb_ops *cb; 4797c478bd9Sstevel@tonic-gate 4807c478bd9Sstevel@tonic-gate cb = devopsp[getmajor(dev)]->devo_cb_ops; 4817c478bd9Sstevel@tonic-gate return ((*cb->cb_print)(dev, str)); 4827c478bd9Sstevel@tonic-gate } 4837c478bd9Sstevel@tonic-gate 484184cd04cScth /* 485184cd04cScth * Return number of DEV_BSIZE byte blocks. 486184cd04cScth */ 4877c478bd9Sstevel@tonic-gate int 4887c478bd9Sstevel@tonic-gate bdev_size(dev_t dev) 4897c478bd9Sstevel@tonic-gate { 490184cd04cScth uint_t nblocks; 491184cd04cScth uint_t blksize; 492184cd04cScth 493184cd04cScth if ((nblocks = e_ddi_getprop(dev, VBLK, "nblocks", 494184cd04cScth DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, -1)) == -1) 495184cd04cScth return (-1); 496184cd04cScth 497184cd04cScth /* Get blksize, default to DEV_BSIZE */ 498184cd04cScth if ((blksize = e_ddi_getprop(dev, VBLK, "blksize", 499184cd04cScth DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, -1)) == -1) 500184cd04cScth blksize = e_ddi_getprop(DDI_DEV_T_ANY, VBLK, "device-blksize", 501184cd04cScth DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, DEV_BSIZE); 502184cd04cScth 503184cd04cScth if (blksize >= DEV_BSIZE) 504184cd04cScth return (nblocks * (blksize / DEV_BSIZE)); 505184cd04cScth else 506184cd04cScth return (nblocks / (DEV_BSIZE / blksize)); 5077c478bd9Sstevel@tonic-gate } 5087c478bd9Sstevel@tonic-gate 5097c478bd9Sstevel@tonic-gate /* 5107c478bd9Sstevel@tonic-gate * Same for 64-bit Nblocks property 5117c478bd9Sstevel@tonic-gate */ 5127c478bd9Sstevel@tonic-gate uint64_t 5137c478bd9Sstevel@tonic-gate bdev_Size(dev_t dev) 5147c478bd9Sstevel@tonic-gate { 515184cd04cScth uint64_t nblocks; 516184cd04cScth uint_t blksize; 517184cd04cScth 518184cd04cScth if ((nblocks = e_ddi_getprop_int64(dev, VBLK, "Nblocks", 519184cd04cScth DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, -1)) == -1) 520184cd04cScth return (-1); 521184cd04cScth 522184cd04cScth /* Get blksize, default to DEV_BSIZE */ 523184cd04cScth if ((blksize = e_ddi_getprop(dev, VBLK, "blksize", 524184cd04cScth DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, -1)) == -1) 525184cd04cScth blksize = e_ddi_getprop(DDI_DEV_T_ANY, VBLK, "device-blksize", 526184cd04cScth DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, DEV_BSIZE); 527184cd04cScth 528184cd04cScth if (blksize >= DEV_BSIZE) 529184cd04cScth return (nblocks * (blksize / DEV_BSIZE)); 530184cd04cScth else 531184cd04cScth return (nblocks / (DEV_BSIZE / blksize)); 5327c478bd9Sstevel@tonic-gate } 5337c478bd9Sstevel@tonic-gate 5347c478bd9Sstevel@tonic-gate int 5357c478bd9Sstevel@tonic-gate bdev_dump(dev_t dev, caddr_t addr, daddr_t blkno, int blkcnt) 5367c478bd9Sstevel@tonic-gate { 5377c478bd9Sstevel@tonic-gate struct cb_ops *cb; 5387c478bd9Sstevel@tonic-gate 5397c478bd9Sstevel@tonic-gate cb = devopsp[getmajor(dev)]->devo_cb_ops; 5407c478bd9Sstevel@tonic-gate return ((*cb->cb_dump)(dev, addr, blkno, blkcnt)); 5417c478bd9Sstevel@tonic-gate } 5427c478bd9Sstevel@tonic-gate 5437c478bd9Sstevel@tonic-gate int 5447c478bd9Sstevel@tonic-gate cdev_read(dev_t dev, struct uio *uiop, struct cred *cred) 5457c478bd9Sstevel@tonic-gate { 5467c478bd9Sstevel@tonic-gate struct cb_ops *cb; 5477c478bd9Sstevel@tonic-gate 5487c478bd9Sstevel@tonic-gate cb = devopsp[getmajor(dev)]->devo_cb_ops; 5497c478bd9Sstevel@tonic-gate return ((*cb->cb_read)(dev, uiop, cred)); 5507c478bd9Sstevel@tonic-gate } 5517c478bd9Sstevel@tonic-gate 5527c478bd9Sstevel@tonic-gate int 5537c478bd9Sstevel@tonic-gate cdev_write(dev_t dev, struct uio *uiop, struct cred *cred) 5547c478bd9Sstevel@tonic-gate { 5557c478bd9Sstevel@tonic-gate struct cb_ops *cb; 5567c478bd9Sstevel@tonic-gate 5577c478bd9Sstevel@tonic-gate cb = devopsp[getmajor(dev)]->devo_cb_ops; 5587c478bd9Sstevel@tonic-gate return ((*cb->cb_write)(dev, uiop, cred)); 5597c478bd9Sstevel@tonic-gate } 5607c478bd9Sstevel@tonic-gate 5617c478bd9Sstevel@tonic-gate int 5627c478bd9Sstevel@tonic-gate cdev_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, struct cred *cred, 5637c478bd9Sstevel@tonic-gate int *rvalp) 5647c478bd9Sstevel@tonic-gate { 5657c478bd9Sstevel@tonic-gate struct cb_ops *cb; 5667c478bd9Sstevel@tonic-gate 5677c478bd9Sstevel@tonic-gate cb = devopsp[getmajor(dev)]->devo_cb_ops; 5687c478bd9Sstevel@tonic-gate return ((*cb->cb_ioctl)(dev, cmd, arg, mode, cred, rvalp)); 5697c478bd9Sstevel@tonic-gate } 5707c478bd9Sstevel@tonic-gate 5717c478bd9Sstevel@tonic-gate int 5727c478bd9Sstevel@tonic-gate cdev_devmap(dev_t dev, devmap_cookie_t dhp, offset_t off, size_t len, 5737c478bd9Sstevel@tonic-gate size_t *maplen, uint_t mode) 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_devmap)(dev, dhp, off, len, maplen, mode)); 5797c478bd9Sstevel@tonic-gate } 5807c478bd9Sstevel@tonic-gate 5817c478bd9Sstevel@tonic-gate int 5827c478bd9Sstevel@tonic-gate cdev_mmap(int (*mapfunc)(dev_t, off_t, int), dev_t dev, off_t off, int prot) 5837c478bd9Sstevel@tonic-gate { 5847c478bd9Sstevel@tonic-gate return ((*mapfunc)(dev, off, prot)); 5857c478bd9Sstevel@tonic-gate } 5867c478bd9Sstevel@tonic-gate 5877c478bd9Sstevel@tonic-gate int 5887c478bd9Sstevel@tonic-gate cdev_segmap(dev_t dev, off_t off, struct as *as, caddr_t *addrp, off_t len, 5897c478bd9Sstevel@tonic-gate uint_t prot, uint_t maxprot, uint_t flags, cred_t *credp) 5907c478bd9Sstevel@tonic-gate { 5917c478bd9Sstevel@tonic-gate struct cb_ops *cb; 5927c478bd9Sstevel@tonic-gate 5937c478bd9Sstevel@tonic-gate cb = devopsp[getmajor(dev)]->devo_cb_ops; 5947c478bd9Sstevel@tonic-gate return ((*cb->cb_segmap)(dev, off, as, addrp, 5957c478bd9Sstevel@tonic-gate len, prot, maxprot, flags, credp)); 5967c478bd9Sstevel@tonic-gate } 5977c478bd9Sstevel@tonic-gate 5987c478bd9Sstevel@tonic-gate int 5997c478bd9Sstevel@tonic-gate cdev_poll(dev_t dev, short events, int anyyet, short *reventsp, 6007c478bd9Sstevel@tonic-gate struct pollhead **pollhdrp) 6017c478bd9Sstevel@tonic-gate { 6027c478bd9Sstevel@tonic-gate struct cb_ops *cb; 6037c478bd9Sstevel@tonic-gate 6047c478bd9Sstevel@tonic-gate cb = devopsp[getmajor(dev)]->devo_cb_ops; 6057c478bd9Sstevel@tonic-gate return ((*cb->cb_chpoll)(dev, events, anyyet, reventsp, pollhdrp)); 6067c478bd9Sstevel@tonic-gate } 6077c478bd9Sstevel@tonic-gate 6087c478bd9Sstevel@tonic-gate /* 6097c478bd9Sstevel@tonic-gate * A 'size' property can be provided by a VCHR device. 6107c478bd9Sstevel@tonic-gate * 6117c478bd9Sstevel@tonic-gate * Since it's defined as zero for STREAMS devices, so we avoid the 6127c478bd9Sstevel@tonic-gate * overhead of looking it up. Note also that we don't force an 6137c478bd9Sstevel@tonic-gate * unused driver into memory simply to ask about it's size. We also 6147c478bd9Sstevel@tonic-gate * don't bother to ask it its size unless it's already been attached 6157c478bd9Sstevel@tonic-gate * (the attach routine is the earliest place the property will be created) 6167c478bd9Sstevel@tonic-gate * 6177c478bd9Sstevel@tonic-gate * XXX In an ideal world, we'd call this at VOP_GETATTR() time. 6187c478bd9Sstevel@tonic-gate */ 6197c478bd9Sstevel@tonic-gate int 6207c478bd9Sstevel@tonic-gate cdev_size(dev_t dev) 6217c478bd9Sstevel@tonic-gate { 6227c478bd9Sstevel@tonic-gate major_t maj; 6237c478bd9Sstevel@tonic-gate struct devnames *dnp; 6247c478bd9Sstevel@tonic-gate 6257c478bd9Sstevel@tonic-gate if ((maj = getmajor(dev)) >= devcnt) 6267c478bd9Sstevel@tonic-gate return (0); 6277c478bd9Sstevel@tonic-gate 6287c478bd9Sstevel@tonic-gate dnp = &(devnamesp[maj]); 6297c478bd9Sstevel@tonic-gate LOCK_DEV_OPS(&dnp->dn_lock); 6307c478bd9Sstevel@tonic-gate if (devopsp[maj] && devopsp[maj]->devo_cb_ops && 6317c478bd9Sstevel@tonic-gate !devopsp[maj]->devo_cb_ops->cb_str) { 6327c478bd9Sstevel@tonic-gate UNLOCK_DEV_OPS(&dnp->dn_lock); 6337c478bd9Sstevel@tonic-gate return (e_ddi_getprop(dev, VCHR, "size", 6347c478bd9Sstevel@tonic-gate DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, 0)); 6357c478bd9Sstevel@tonic-gate } 6367c478bd9Sstevel@tonic-gate UNLOCK_DEV_OPS(&dnp->dn_lock); 6377c478bd9Sstevel@tonic-gate return (0); 6387c478bd9Sstevel@tonic-gate } 6397c478bd9Sstevel@tonic-gate 6407c478bd9Sstevel@tonic-gate /* 6417c478bd9Sstevel@tonic-gate * same for 64-bit Size property 6427c478bd9Sstevel@tonic-gate */ 6437c478bd9Sstevel@tonic-gate uint64_t 6447c478bd9Sstevel@tonic-gate cdev_Size(dev_t dev) 6457c478bd9Sstevel@tonic-gate { 6467c478bd9Sstevel@tonic-gate major_t maj; 6477c478bd9Sstevel@tonic-gate struct devnames *dnp; 6487c478bd9Sstevel@tonic-gate 6497c478bd9Sstevel@tonic-gate if ((maj = getmajor(dev)) >= devcnt) 6507c478bd9Sstevel@tonic-gate return (0); 6517c478bd9Sstevel@tonic-gate 6527c478bd9Sstevel@tonic-gate dnp = &(devnamesp[maj]); 6537c478bd9Sstevel@tonic-gate LOCK_DEV_OPS(&dnp->dn_lock); 6547c478bd9Sstevel@tonic-gate if (devopsp[maj] && devopsp[maj]->devo_cb_ops && 6557c478bd9Sstevel@tonic-gate !devopsp[maj]->devo_cb_ops->cb_str) { 6567c478bd9Sstevel@tonic-gate UNLOCK_DEV_OPS(&dnp->dn_lock); 6577c478bd9Sstevel@tonic-gate return (e_ddi_getprop_int64(dev, VCHR, "Size", 6587c478bd9Sstevel@tonic-gate DDI_PROP_NOTPROM | DDI_PROP_DONTPASS, 0)); 6597c478bd9Sstevel@tonic-gate } 6607c478bd9Sstevel@tonic-gate UNLOCK_DEV_OPS(&dnp->dn_lock); 6617c478bd9Sstevel@tonic-gate return (0); 6627c478bd9Sstevel@tonic-gate } 6637c478bd9Sstevel@tonic-gate 6647c478bd9Sstevel@tonic-gate /* 6657c478bd9Sstevel@tonic-gate * XXX This routine is poorly named, because block devices can and do 6667c478bd9Sstevel@tonic-gate * have properties (see bdev_size() above). 6677c478bd9Sstevel@tonic-gate * 6687c478bd9Sstevel@tonic-gate * XXX fix the comment in devops.h that claims that cb_prop_op 6697c478bd9Sstevel@tonic-gate * is character-only. 6707c478bd9Sstevel@tonic-gate */ 6717c478bd9Sstevel@tonic-gate int 6727c478bd9Sstevel@tonic-gate cdev_prop_op(dev_t dev, dev_info_t *dip, ddi_prop_op_t prop_op, int mod_flags, 6737c478bd9Sstevel@tonic-gate char *name, caddr_t valuep, int *lengthp) 6747c478bd9Sstevel@tonic-gate { 6757c478bd9Sstevel@tonic-gate struct cb_ops *cb; 6767c478bd9Sstevel@tonic-gate 6777c478bd9Sstevel@tonic-gate if ((cb = devopsp[DEVI(dip)->devi_major]->devo_cb_ops) == NULL) 6787c478bd9Sstevel@tonic-gate return (DDI_PROP_NOT_FOUND); 6797c478bd9Sstevel@tonic-gate 6807c478bd9Sstevel@tonic-gate return ((*cb->cb_prop_op)(dev, dip, prop_op, mod_flags, 6817c478bd9Sstevel@tonic-gate name, valuep, lengthp)); 6827c478bd9Sstevel@tonic-gate } 683