10Sstevel@tonic-gate /*
20Sstevel@tonic-gate * CDDL HEADER START
30Sstevel@tonic-gate *
40Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7656SSherry.Moore@Sun.COM * Common Development and Distribution License (the "License").
6*7656SSherry.Moore@Sun.COM * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate *
80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate * See the License for the specific language governing permissions
110Sstevel@tonic-gate * and limitations under the License.
120Sstevel@tonic-gate *
130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate *
190Sstevel@tonic-gate * CDDL HEADER END
200Sstevel@tonic-gate */
210Sstevel@tonic-gate /*
22*7656SSherry.Moore@Sun.COM * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
230Sstevel@tonic-gate * Use is subject to license terms.
240Sstevel@tonic-gate */
250Sstevel@tonic-gate
260Sstevel@tonic-gate
270Sstevel@tonic-gate #include <sys/types.h>
280Sstevel@tonic-gate #include <sys/conf.h>
290Sstevel@tonic-gate #include <sys/cmn_err.h>
300Sstevel@tonic-gate #include <sys/kmem.h>
310Sstevel@tonic-gate #include <sys/open.h>
320Sstevel@tonic-gate #include <sys/stat.h>
330Sstevel@tonic-gate #include <sys/modctl.h>
340Sstevel@tonic-gate #include <sys/errno.h>
350Sstevel@tonic-gate #include <sys/ddi.h>
360Sstevel@tonic-gate #include <sys/sunddi.h>
370Sstevel@tonic-gate
380Sstevel@tonic-gate /* #define SBUSMEM_DEBUG */
390Sstevel@tonic-gate
400Sstevel@tonic-gate #ifdef SBUSMEM_DEBUG
410Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
420Sstevel@tonic-gate
430Sstevel@tonic-gate int sbusmem_debug_flag;
440Sstevel@tonic-gate #define sbusmem_debug if (sbusmem_debug_flag) printf
450Sstevel@tonic-gate #endif /* SBUSMEM_DEBUG */
460Sstevel@tonic-gate
470Sstevel@tonic-gate static void *sbusmem_state_head;
480Sstevel@tonic-gate
490Sstevel@tonic-gate struct sbusmem_unit {
500Sstevel@tonic-gate uint_t size;
510Sstevel@tonic-gate uint_t pagesize;
520Sstevel@tonic-gate dev_info_t *dip;
530Sstevel@tonic-gate };
540Sstevel@tonic-gate
550Sstevel@tonic-gate static int sbmem_open(dev_t *, int, int, cred_t *);
560Sstevel@tonic-gate static int sbmem_close(dev_t, int, int, struct cred *);
570Sstevel@tonic-gate static int sbmem_read(dev_t, struct uio *, cred_t *);
580Sstevel@tonic-gate static int sbmem_write(dev_t, struct uio *, cred_t *);
590Sstevel@tonic-gate static int sbmem_devmap(dev_t, devmap_cookie_t, offset_t, size_t,
600Sstevel@tonic-gate size_t *, uint_t);
610Sstevel@tonic-gate
620Sstevel@tonic-gate static struct cb_ops sbmem_cb_ops = {
630Sstevel@tonic-gate sbmem_open, /* open */
640Sstevel@tonic-gate sbmem_close, /* close */
650Sstevel@tonic-gate nodev, /* strategy */
660Sstevel@tonic-gate nodev, /* print */
670Sstevel@tonic-gate nodev, /* dump */
680Sstevel@tonic-gate sbmem_read, /* read */
690Sstevel@tonic-gate sbmem_write, /* write */
700Sstevel@tonic-gate nodev, /* ioctl */
710Sstevel@tonic-gate sbmem_devmap, /* devmap */
720Sstevel@tonic-gate nodev, /* mmap */
730Sstevel@tonic-gate ddi_devmap_segmap, /* segmap */
740Sstevel@tonic-gate nochpoll, /* poll */
750Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */
760Sstevel@tonic-gate 0, /* streamtab */
770Sstevel@tonic-gate D_NEW|D_MP|D_DEVMAP|D_HOTPLUG, /* Driver compatibility flag */
780Sstevel@tonic-gate CB_REV, /* rev */
790Sstevel@tonic-gate nodev, /* int (*cb_aread)() */
800Sstevel@tonic-gate nodev /* int (*cb_awrite)() */
810Sstevel@tonic-gate };
820Sstevel@tonic-gate
830Sstevel@tonic-gate static int sbmem_attach(dev_info_t *, ddi_attach_cmd_t);
840Sstevel@tonic-gate static int sbmem_detach(dev_info_t *, ddi_detach_cmd_t);
850Sstevel@tonic-gate static int sbmem_info(dev_info_t *, ddi_info_cmd_t, void *, void **);
860Sstevel@tonic-gate
870Sstevel@tonic-gate static struct dev_ops sbmem_ops = {
880Sstevel@tonic-gate DEVO_REV, /* devo_rev, */
890Sstevel@tonic-gate 0, /* refcnt */
900Sstevel@tonic-gate sbmem_info, /* get_dev_info */
910Sstevel@tonic-gate nulldev, /* identify */
920Sstevel@tonic-gate nulldev, /* probe */
930Sstevel@tonic-gate sbmem_attach, /* attach */
940Sstevel@tonic-gate sbmem_detach, /* detach */
950Sstevel@tonic-gate nodev, /* reset */
960Sstevel@tonic-gate &sbmem_cb_ops, /* driver operations */
970Sstevel@tonic-gate (struct bus_ops *)0, /* bus operations */
98*7656SSherry.Moore@Sun.COM nulldev, /* power */
99*7656SSherry.Moore@Sun.COM ddi_quiesce_not_needed, /* quiesce */
1000Sstevel@tonic-gate };
1010Sstevel@tonic-gate
1020Sstevel@tonic-gate static struct modldrv modldrv = {
1030Sstevel@tonic-gate &mod_driverops, /* Type of module. This one is a driver */
104*7656SSherry.Moore@Sun.COM "SBus memory driver", /* Name of module. */
1050Sstevel@tonic-gate &sbmem_ops, /* driver ops */
1060Sstevel@tonic-gate };
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate static struct modlinkage modlinkage = {
1090Sstevel@tonic-gate MODREV_1, (void *)&modldrv, NULL
1100Sstevel@tonic-gate };
1110Sstevel@tonic-gate
1120Sstevel@tonic-gate static int sbmem_rw(dev_t, struct uio *, enum uio_rw, cred_t *);
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate #if !defined(lint)
115*7656SSherry.Moore@Sun.COM static char sbusmem_initmsg[] = "sbusmem _init: sbusmem.c\t1.28\t08/19/2008\n";
1160Sstevel@tonic-gate #endif
1170Sstevel@tonic-gate
1180Sstevel@tonic-gate int
_init(void)1190Sstevel@tonic-gate _init(void)
1200Sstevel@tonic-gate {
1210Sstevel@tonic-gate int error;
1220Sstevel@tonic-gate
1230Sstevel@tonic-gate if ((error = ddi_soft_state_init(&sbusmem_state_head,
1240Sstevel@tonic-gate sizeof (struct sbusmem_unit), 1)) != 0) {
1250Sstevel@tonic-gate return (error);
1260Sstevel@tonic-gate }
1270Sstevel@tonic-gate if ((error = mod_install(&modlinkage)) != 0) {
1280Sstevel@tonic-gate ddi_soft_state_fini(&sbusmem_state_head);
1290Sstevel@tonic-gate }
1300Sstevel@tonic-gate return (error);
1310Sstevel@tonic-gate }
1320Sstevel@tonic-gate
1330Sstevel@tonic-gate int
_fini(void)1340Sstevel@tonic-gate _fini(void)
1350Sstevel@tonic-gate {
1360Sstevel@tonic-gate int error;
1370Sstevel@tonic-gate
1380Sstevel@tonic-gate if ((error = mod_remove(&modlinkage)) == 0) {
1390Sstevel@tonic-gate ddi_soft_state_fini(&sbusmem_state_head);
1400Sstevel@tonic-gate }
1410Sstevel@tonic-gate return (error);
1420Sstevel@tonic-gate }
1430Sstevel@tonic-gate
1440Sstevel@tonic-gate int
_info(struct modinfo * modinfop)1450Sstevel@tonic-gate _info(struct modinfo *modinfop)
1460Sstevel@tonic-gate {
1470Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
1480Sstevel@tonic-gate }
1490Sstevel@tonic-gate
1500Sstevel@tonic-gate static int
sbmem_attach(dev_info_t * devi,ddi_attach_cmd_t cmd)1510Sstevel@tonic-gate sbmem_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
1520Sstevel@tonic-gate {
1530Sstevel@tonic-gate struct sbusmem_unit *un;
1540Sstevel@tonic-gate int error = DDI_FAILURE;
1550Sstevel@tonic-gate int instance, ilen;
1560Sstevel@tonic-gate uint_t size;
1570Sstevel@tonic-gate char *ident;
1580Sstevel@tonic-gate
1590Sstevel@tonic-gate switch (cmd) {
1600Sstevel@tonic-gate case DDI_ATTACH:
1610Sstevel@tonic-gate instance = ddi_get_instance(devi);
1620Sstevel@tonic-gate
1630Sstevel@tonic-gate size = ddi_getprop(DDI_DEV_T_NONE, devi,
1640Sstevel@tonic-gate DDI_PROP_DONTPASS | DDI_PROP_CANSLEEP, "size", -1);
1650Sstevel@tonic-gate if (size == (uint_t)-1) {
1660Sstevel@tonic-gate #ifdef SBUSMEM_DEBUG
1670Sstevel@tonic-gate sbusmem_debug(
1680Sstevel@tonic-gate "sbmem_attach%d: No size property\n", instance);
1690Sstevel@tonic-gate #endif /* SBUSMEM_DEBUG */
1700Sstevel@tonic-gate break;
1710Sstevel@tonic-gate }
1720Sstevel@tonic-gate
1730Sstevel@tonic-gate #ifdef SBUSMEM_DEBUG
1740Sstevel@tonic-gate {
1750Sstevel@tonic-gate struct regspec *rp = ddi_rnumber_to_regspec(devi, 0);
1760Sstevel@tonic-gate
1770Sstevel@tonic-gate if (rp == NULL) {
1780Sstevel@tonic-gate sbusmem_debug(
1790Sstevel@tonic-gate "sbmem_attach%d: No reg property\n", instance);
1800Sstevel@tonic-gate } else {
1810Sstevel@tonic-gate sbusmem_debug(
1820Sstevel@tonic-gate "sbmem_attach%d: slot 0x%x size 0x%x\n", instance,
1830Sstevel@tonic-gate rp->regspec_bustype, rp->regspec_size);
1840Sstevel@tonic-gate }
1850Sstevel@tonic-gate }
1860Sstevel@tonic-gate #endif /* SBUSMEM_DEBUG */
1870Sstevel@tonic-gate
188506Scth if (ddi_getlongprop(DDI_DEV_T_ANY, devi,
1890Sstevel@tonic-gate DDI_PROP_DONTPASS | DDI_PROP_CANSLEEP, "ident",
1900Sstevel@tonic-gate (caddr_t)&ident, &ilen) != DDI_PROP_SUCCESS) {
1910Sstevel@tonic-gate #ifdef SBUSMEM_DEBUG
1920Sstevel@tonic-gate sbusmem_debug(
1930Sstevel@tonic-gate "sbmem_attach%d: No ident property\n", instance);
1940Sstevel@tonic-gate #endif /* SBUSMEM_DEBUG */
1950Sstevel@tonic-gate break;
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate
1980Sstevel@tonic-gate if (ddi_soft_state_zalloc(sbusmem_state_head,
1990Sstevel@tonic-gate instance) != DDI_SUCCESS)
2000Sstevel@tonic-gate break;
2010Sstevel@tonic-gate
2020Sstevel@tonic-gate if ((un = ddi_get_soft_state(sbusmem_state_head,
2030Sstevel@tonic-gate instance)) == NULL) {
2040Sstevel@tonic-gate ddi_soft_state_free(sbusmem_state_head, instance);
2050Sstevel@tonic-gate break;
2060Sstevel@tonic-gate }
2070Sstevel@tonic-gate
2080Sstevel@tonic-gate if (ddi_create_minor_node(devi, ident, S_IFCHR, instance,
2090Sstevel@tonic-gate DDI_PSEUDO, NULL) == DDI_FAILURE) {
2100Sstevel@tonic-gate kmem_free(ident, ilen);
2110Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL);
2120Sstevel@tonic-gate ddi_soft_state_free(sbusmem_state_head, instance);
2130Sstevel@tonic-gate break;
2140Sstevel@tonic-gate }
2150Sstevel@tonic-gate kmem_free(ident, ilen);
2160Sstevel@tonic-gate un->dip = devi;
2170Sstevel@tonic-gate un->size = size;
2180Sstevel@tonic-gate un->pagesize = ddi_ptob(devi, 1);
2190Sstevel@tonic-gate
2200Sstevel@tonic-gate #ifdef SBUSMEM_DEBUG
2210Sstevel@tonic-gate sbusmem_debug("sbmem_attach%d: dip 0x%p size 0x%x\n",
2220Sstevel@tonic-gate instance, devi, size);
2230Sstevel@tonic-gate #endif /* SBUSMEM_DEBUG */
2240Sstevel@tonic-gate
2250Sstevel@tonic-gate ddi_report_dev(devi);
2260Sstevel@tonic-gate error = DDI_SUCCESS;
2270Sstevel@tonic-gate break;
2280Sstevel@tonic-gate case DDI_RESUME:
2290Sstevel@tonic-gate error = DDI_SUCCESS;
2300Sstevel@tonic-gate break;
2310Sstevel@tonic-gate default:
2320Sstevel@tonic-gate break;
2330Sstevel@tonic-gate }
2340Sstevel@tonic-gate return (error);
2350Sstevel@tonic-gate }
2360Sstevel@tonic-gate
2370Sstevel@tonic-gate static int
sbmem_detach(dev_info_t * devi,ddi_detach_cmd_t cmd)2380Sstevel@tonic-gate sbmem_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
2390Sstevel@tonic-gate {
2400Sstevel@tonic-gate int instance;
2410Sstevel@tonic-gate
2420Sstevel@tonic-gate switch (cmd) {
2430Sstevel@tonic-gate case DDI_DETACH:
2440Sstevel@tonic-gate instance = ddi_get_instance(devi);
2450Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL);
2460Sstevel@tonic-gate ddi_soft_state_free(sbusmem_state_head, instance);
2470Sstevel@tonic-gate return (DDI_SUCCESS);
2480Sstevel@tonic-gate
2490Sstevel@tonic-gate case DDI_SUSPEND:
2500Sstevel@tonic-gate return (DDI_SUCCESS);
2510Sstevel@tonic-gate }
2520Sstevel@tonic-gate return (DDI_FAILURE);
2530Sstevel@tonic-gate }
2540Sstevel@tonic-gate
2550Sstevel@tonic-gate /*ARGSUSED1*/
2560Sstevel@tonic-gate static int
sbmem_open(dev_t * devp,int flag,int typ,cred_t * cred)2570Sstevel@tonic-gate sbmem_open(dev_t *devp, int flag, int typ, cred_t *cred)
2580Sstevel@tonic-gate {
2590Sstevel@tonic-gate int instance;
2600Sstevel@tonic-gate
2610Sstevel@tonic-gate if (typ != OTYP_CHR)
2620Sstevel@tonic-gate return (EINVAL);
2630Sstevel@tonic-gate
2640Sstevel@tonic-gate instance = getminor(*devp);
2650Sstevel@tonic-gate if (ddi_get_soft_state(sbusmem_state_head, instance) == NULL) {
2660Sstevel@tonic-gate return (ENXIO);
2670Sstevel@tonic-gate }
2680Sstevel@tonic-gate return (0);
2690Sstevel@tonic-gate }
2700Sstevel@tonic-gate
2710Sstevel@tonic-gate /*ARGSUSED*/
2720Sstevel@tonic-gate static int
sbmem_close(dev_t dev,int flag,int otyp,struct cred * cred)2730Sstevel@tonic-gate sbmem_close(dev_t dev, int flag, int otyp, struct cred *cred)
2740Sstevel@tonic-gate {
2750Sstevel@tonic-gate if (otyp != OTYP_CHR)
2760Sstevel@tonic-gate return (EINVAL);
2770Sstevel@tonic-gate
2780Sstevel@tonic-gate return (0);
2790Sstevel@tonic-gate }
2800Sstevel@tonic-gate
2810Sstevel@tonic-gate static int
sbmem_info(dev_info_t * dip,ddi_info_cmd_t infocmd,void * arg,void ** result)2820Sstevel@tonic-gate sbmem_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
2830Sstevel@tonic-gate {
2840Sstevel@tonic-gate int instance, error = DDI_FAILURE;
2850Sstevel@tonic-gate struct sbusmem_unit *un;
2860Sstevel@tonic-gate
2870Sstevel@tonic-gate #if defined(lint) || defined(__lint)
2880Sstevel@tonic-gate dip = dip;
2890Sstevel@tonic-gate #endif /* lint || __lint */
2900Sstevel@tonic-gate
2910Sstevel@tonic-gate switch (infocmd) {
2920Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO:
2930Sstevel@tonic-gate instance = getminor((dev_t)arg);
2940Sstevel@tonic-gate if ((un = ddi_get_soft_state(sbusmem_state_head,
2950Sstevel@tonic-gate instance)) != NULL) {
2960Sstevel@tonic-gate *result = (void *)un->dip;
2970Sstevel@tonic-gate error = DDI_SUCCESS;
2980Sstevel@tonic-gate #ifdef SBUSMEM_DEBUG
2990Sstevel@tonic-gate sbusmem_debug(
3000Sstevel@tonic-gate "sbmem_info%d: returning dip 0x%p\n", instance, un->dip);
3010Sstevel@tonic-gate #endif /* SBUSMEM_DEBUG */
3020Sstevel@tonic-gate
3030Sstevel@tonic-gate }
3040Sstevel@tonic-gate break;
3050Sstevel@tonic-gate
3060Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE:
3070Sstevel@tonic-gate instance = getminor((dev_t)arg);
3081009Smathue *result = (void *)(uintptr_t)instance;
3090Sstevel@tonic-gate error = DDI_SUCCESS;
3100Sstevel@tonic-gate break;
3110Sstevel@tonic-gate
3120Sstevel@tonic-gate default:
3130Sstevel@tonic-gate break;
3140Sstevel@tonic-gate }
3150Sstevel@tonic-gate return (error);
3160Sstevel@tonic-gate }
3170Sstevel@tonic-gate
3180Sstevel@tonic-gate static int
sbmem_read(dev_t dev,struct uio * uio,cred_t * cred)3190Sstevel@tonic-gate sbmem_read(dev_t dev, struct uio *uio, cred_t *cred)
3200Sstevel@tonic-gate {
3210Sstevel@tonic-gate return (sbmem_rw(dev, uio, UIO_READ, cred));
3220Sstevel@tonic-gate }
3230Sstevel@tonic-gate
3240Sstevel@tonic-gate static int
sbmem_write(dev_t dev,struct uio * uio,cred_t * cred)3250Sstevel@tonic-gate sbmem_write(dev_t dev, struct uio *uio, cred_t *cred)
3260Sstevel@tonic-gate {
3270Sstevel@tonic-gate return (sbmem_rw(dev, uio, UIO_WRITE, cred));
3280Sstevel@tonic-gate }
3290Sstevel@tonic-gate
3300Sstevel@tonic-gate static int
sbmem_rw(dev_t dev,struct uio * uio,enum uio_rw rw,cred_t * cred)3310Sstevel@tonic-gate sbmem_rw(dev_t dev, struct uio *uio, enum uio_rw rw, cred_t *cred)
3320Sstevel@tonic-gate {
3330Sstevel@tonic-gate uint_t c;
3340Sstevel@tonic-gate struct iovec *iov;
3350Sstevel@tonic-gate struct sbusmem_unit *un;
3360Sstevel@tonic-gate uint_t pagesize, msize;
3370Sstevel@tonic-gate int instance, error = 0;
3380Sstevel@tonic-gate dev_info_t *dip;
3390Sstevel@tonic-gate caddr_t reg;
3400Sstevel@tonic-gate
3410Sstevel@tonic-gate #if defined(lint) || defined(__lint)
3420Sstevel@tonic-gate cred = cred;
3430Sstevel@tonic-gate #endif /* lint || __lint */
3440Sstevel@tonic-gate
3450Sstevel@tonic-gate instance = getminor(dev);
3460Sstevel@tonic-gate if ((un = ddi_get_soft_state(sbusmem_state_head, instance)) == NULL) {
3470Sstevel@tonic-gate return (ENXIO);
3480Sstevel@tonic-gate }
3490Sstevel@tonic-gate dip = un->dip;
3500Sstevel@tonic-gate pagesize = un->pagesize;
3510Sstevel@tonic-gate
3520Sstevel@tonic-gate while (uio->uio_resid > 0 && error == 0) {
3530Sstevel@tonic-gate iov = uio->uio_iov;
3540Sstevel@tonic-gate if (iov->iov_len == 0) {
3550Sstevel@tonic-gate uio->uio_iov++;
3560Sstevel@tonic-gate uio->uio_iovcnt--;
3570Sstevel@tonic-gate if (uio->uio_iovcnt < 0)
3580Sstevel@tonic-gate cmn_err(CE_PANIC, "sbmem_rw");
3590Sstevel@tonic-gate continue;
3600Sstevel@tonic-gate }
3610Sstevel@tonic-gate
3620Sstevel@tonic-gate if (uio->uio_offset > un->size) {
3630Sstevel@tonic-gate return (EFAULT);
3640Sstevel@tonic-gate }
3650Sstevel@tonic-gate
3660Sstevel@tonic-gate if (uio->uio_offset == un->size) {
3670Sstevel@tonic-gate return (0); /* EOF */
3680Sstevel@tonic-gate }
3690Sstevel@tonic-gate msize = pagesize - (uio->uio_offset & (pagesize - 1));
3700Sstevel@tonic-gate if (ddi_map_regs(dip, 0, ®, uio->uio_offset,
3710Sstevel@tonic-gate (off_t)msize) != DDI_SUCCESS) {
3720Sstevel@tonic-gate return (EFAULT);
3730Sstevel@tonic-gate }
3740Sstevel@tonic-gate c = min(msize, (uint_t)iov->iov_len);
3750Sstevel@tonic-gate if (ddi_peekpokeio(dip, uio, rw, reg, (int)c,
3760Sstevel@tonic-gate sizeof (int)) != DDI_SUCCESS)
3770Sstevel@tonic-gate error = EFAULT;
3780Sstevel@tonic-gate
3790Sstevel@tonic-gate ddi_unmap_regs(dip, 0, ®, uio->uio_offset, (off_t)msize);
3800Sstevel@tonic-gate }
3810Sstevel@tonic-gate return (error);
3820Sstevel@tonic-gate }
3830Sstevel@tonic-gate
3840Sstevel@tonic-gate static int
sbmem_devmap(dev_t dev,devmap_cookie_t dhp,offset_t off,size_t len,size_t * maplen,uint_t model)3850Sstevel@tonic-gate sbmem_devmap(dev_t dev, devmap_cookie_t dhp, offset_t off, size_t len,
3860Sstevel@tonic-gate size_t *maplen, uint_t model)
3870Sstevel@tonic-gate {
3880Sstevel@tonic-gate struct sbusmem_unit *un;
3890Sstevel@tonic-gate int instance, error;
3900Sstevel@tonic-gate
3910Sstevel@tonic-gate #if defined(lint) || defined(__lint)
3920Sstevel@tonic-gate model = model;
3930Sstevel@tonic-gate #endif /* lint || __lint */
3940Sstevel@tonic-gate
3950Sstevel@tonic-gate instance = getminor(dev);
3960Sstevel@tonic-gate if ((un = ddi_get_soft_state(sbusmem_state_head, instance)) == NULL) {
3970Sstevel@tonic-gate return (ENXIO);
3980Sstevel@tonic-gate }
3990Sstevel@tonic-gate if (off + len > un->size) {
4000Sstevel@tonic-gate return (ENXIO);
4010Sstevel@tonic-gate }
4020Sstevel@tonic-gate if ((error = devmap_devmem_setup(dhp, un->dip, NULL, 0,
403*7656SSherry.Moore@Sun.COM off, len, PROT_ALL, DEVMAP_DEFAULTS, NULL)) < 0) {
4040Sstevel@tonic-gate return (error);
4050Sstevel@tonic-gate }
4060Sstevel@tonic-gate *maplen = ptob(btopr(len));
4070Sstevel@tonic-gate return (0);
4080Sstevel@tonic-gate }
409