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 5*19397407SSherry Moore * Common Development and Distribution License (the "License"). 6*19397407SSherry Moore * 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 277c478bd9Sstevel@tonic-gate #include <sys/types.h> 287c478bd9Sstevel@tonic-gate #include <sys/conf.h> 297c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 307c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 317c478bd9Sstevel@tonic-gate #include <sys/open.h> 327c478bd9Sstevel@tonic-gate #include <sys/stat.h> 337c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 347c478bd9Sstevel@tonic-gate #include <sys/errno.h> 357c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 367c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate /* #define SBUSMEM_DEBUG */ 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate #ifdef SBUSMEM_DEBUG 417c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate int sbusmem_debug_flag; 447c478bd9Sstevel@tonic-gate #define sbusmem_debug if (sbusmem_debug_flag) printf 457c478bd9Sstevel@tonic-gate #endif /* SBUSMEM_DEBUG */ 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate static void *sbusmem_state_head; 487c478bd9Sstevel@tonic-gate 497c478bd9Sstevel@tonic-gate struct sbusmem_unit { 507c478bd9Sstevel@tonic-gate uint_t size; 517c478bd9Sstevel@tonic-gate uint_t pagesize; 527c478bd9Sstevel@tonic-gate dev_info_t *dip; 537c478bd9Sstevel@tonic-gate }; 547c478bd9Sstevel@tonic-gate 557c478bd9Sstevel@tonic-gate static int sbmem_open(dev_t *, int, int, cred_t *); 567c478bd9Sstevel@tonic-gate static int sbmem_close(dev_t, int, int, struct cred *); 577c478bd9Sstevel@tonic-gate static int sbmem_read(dev_t, struct uio *, cred_t *); 587c478bd9Sstevel@tonic-gate static int sbmem_write(dev_t, struct uio *, cred_t *); 597c478bd9Sstevel@tonic-gate static int sbmem_devmap(dev_t, devmap_cookie_t, offset_t, size_t, 607c478bd9Sstevel@tonic-gate size_t *, uint_t); 617c478bd9Sstevel@tonic-gate 627c478bd9Sstevel@tonic-gate static struct cb_ops sbmem_cb_ops = { 637c478bd9Sstevel@tonic-gate sbmem_open, /* open */ 647c478bd9Sstevel@tonic-gate sbmem_close, /* close */ 657c478bd9Sstevel@tonic-gate nodev, /* strategy */ 667c478bd9Sstevel@tonic-gate nodev, /* print */ 677c478bd9Sstevel@tonic-gate nodev, /* dump */ 687c478bd9Sstevel@tonic-gate sbmem_read, /* read */ 697c478bd9Sstevel@tonic-gate sbmem_write, /* write */ 707c478bd9Sstevel@tonic-gate nodev, /* ioctl */ 717c478bd9Sstevel@tonic-gate sbmem_devmap, /* devmap */ 727c478bd9Sstevel@tonic-gate nodev, /* mmap */ 737c478bd9Sstevel@tonic-gate ddi_devmap_segmap, /* segmap */ 747c478bd9Sstevel@tonic-gate nochpoll, /* poll */ 757c478bd9Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */ 767c478bd9Sstevel@tonic-gate 0, /* streamtab */ 777c478bd9Sstevel@tonic-gate D_NEW|D_MP|D_DEVMAP|D_HOTPLUG, /* Driver compatibility flag */ 787c478bd9Sstevel@tonic-gate CB_REV, /* rev */ 797c478bd9Sstevel@tonic-gate nodev, /* int (*cb_aread)() */ 807c478bd9Sstevel@tonic-gate nodev /* int (*cb_awrite)() */ 817c478bd9Sstevel@tonic-gate }; 827c478bd9Sstevel@tonic-gate 837c478bd9Sstevel@tonic-gate static int sbmem_attach(dev_info_t *, ddi_attach_cmd_t); 847c478bd9Sstevel@tonic-gate static int sbmem_detach(dev_info_t *, ddi_detach_cmd_t); 857c478bd9Sstevel@tonic-gate static int sbmem_info(dev_info_t *, ddi_info_cmd_t, void *, void **); 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate static struct dev_ops sbmem_ops = { 887c478bd9Sstevel@tonic-gate DEVO_REV, /* devo_rev, */ 897c478bd9Sstevel@tonic-gate 0, /* refcnt */ 907c478bd9Sstevel@tonic-gate sbmem_info, /* get_dev_info */ 917c478bd9Sstevel@tonic-gate nulldev, /* identify */ 927c478bd9Sstevel@tonic-gate nulldev, /* probe */ 937c478bd9Sstevel@tonic-gate sbmem_attach, /* attach */ 947c478bd9Sstevel@tonic-gate sbmem_detach, /* detach */ 957c478bd9Sstevel@tonic-gate nodev, /* reset */ 967c478bd9Sstevel@tonic-gate &sbmem_cb_ops, /* driver operations */ 977c478bd9Sstevel@tonic-gate (struct bus_ops *)0, /* bus operations */ 98*19397407SSherry Moore nulldev, /* power */ 99*19397407SSherry Moore ddi_quiesce_not_needed, /* quiesce */ 1007c478bd9Sstevel@tonic-gate }; 1017c478bd9Sstevel@tonic-gate 1027c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 1037c478bd9Sstevel@tonic-gate &mod_driverops, /* Type of module. This one is a driver */ 104*19397407SSherry Moore "SBus memory driver", /* Name of module. */ 1057c478bd9Sstevel@tonic-gate &sbmem_ops, /* driver ops */ 1067c478bd9Sstevel@tonic-gate }; 1077c478bd9Sstevel@tonic-gate 1087c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 1097c478bd9Sstevel@tonic-gate MODREV_1, (void *)&modldrv, NULL 1107c478bd9Sstevel@tonic-gate }; 1117c478bd9Sstevel@tonic-gate 1127c478bd9Sstevel@tonic-gate static int sbmem_rw(dev_t, struct uio *, enum uio_rw, cred_t *); 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate #if !defined(lint) 115*19397407SSherry Moore static char sbusmem_initmsg[] = "sbusmem _init: sbusmem.c\t1.28\t08/19/2008\n"; 1167c478bd9Sstevel@tonic-gate #endif 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate int 1197c478bd9Sstevel@tonic-gate _init(void) 1207c478bd9Sstevel@tonic-gate { 1217c478bd9Sstevel@tonic-gate int error; 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate if ((error = ddi_soft_state_init(&sbusmem_state_head, 1247c478bd9Sstevel@tonic-gate sizeof (struct sbusmem_unit), 1)) != 0) { 1257c478bd9Sstevel@tonic-gate return (error); 1267c478bd9Sstevel@tonic-gate } 1277c478bd9Sstevel@tonic-gate if ((error = mod_install(&modlinkage)) != 0) { 1287c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&sbusmem_state_head); 1297c478bd9Sstevel@tonic-gate } 1307c478bd9Sstevel@tonic-gate return (error); 1317c478bd9Sstevel@tonic-gate } 1327c478bd9Sstevel@tonic-gate 1337c478bd9Sstevel@tonic-gate int 1347c478bd9Sstevel@tonic-gate _fini(void) 1357c478bd9Sstevel@tonic-gate { 1367c478bd9Sstevel@tonic-gate int error; 1377c478bd9Sstevel@tonic-gate 1387c478bd9Sstevel@tonic-gate if ((error = mod_remove(&modlinkage)) == 0) { 1397c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&sbusmem_state_head); 1407c478bd9Sstevel@tonic-gate } 1417c478bd9Sstevel@tonic-gate return (error); 1427c478bd9Sstevel@tonic-gate } 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate int 1457c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 1467c478bd9Sstevel@tonic-gate { 1477c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 1487c478bd9Sstevel@tonic-gate } 1497c478bd9Sstevel@tonic-gate 1507c478bd9Sstevel@tonic-gate static int 1517c478bd9Sstevel@tonic-gate sbmem_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 1527c478bd9Sstevel@tonic-gate { 1537c478bd9Sstevel@tonic-gate struct sbusmem_unit *un; 1547c478bd9Sstevel@tonic-gate int error = DDI_FAILURE; 1557c478bd9Sstevel@tonic-gate int instance, ilen; 1567c478bd9Sstevel@tonic-gate uint_t size; 1577c478bd9Sstevel@tonic-gate char *ident; 1587c478bd9Sstevel@tonic-gate 1597c478bd9Sstevel@tonic-gate switch (cmd) { 1607c478bd9Sstevel@tonic-gate case DDI_ATTACH: 1617c478bd9Sstevel@tonic-gate instance = ddi_get_instance(devi); 1627c478bd9Sstevel@tonic-gate 1637c478bd9Sstevel@tonic-gate size = ddi_getprop(DDI_DEV_T_NONE, devi, 1647c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS | DDI_PROP_CANSLEEP, "size", -1); 1657c478bd9Sstevel@tonic-gate if (size == (uint_t)-1) { 1667c478bd9Sstevel@tonic-gate #ifdef SBUSMEM_DEBUG 1677c478bd9Sstevel@tonic-gate sbusmem_debug( 1687c478bd9Sstevel@tonic-gate "sbmem_attach%d: No size property\n", instance); 1697c478bd9Sstevel@tonic-gate #endif /* SBUSMEM_DEBUG */ 1707c478bd9Sstevel@tonic-gate break; 1717c478bd9Sstevel@tonic-gate } 1727c478bd9Sstevel@tonic-gate 1737c478bd9Sstevel@tonic-gate #ifdef SBUSMEM_DEBUG 1747c478bd9Sstevel@tonic-gate { 1757c478bd9Sstevel@tonic-gate struct regspec *rp = ddi_rnumber_to_regspec(devi, 0); 1767c478bd9Sstevel@tonic-gate 1777c478bd9Sstevel@tonic-gate if (rp == NULL) { 1787c478bd9Sstevel@tonic-gate sbusmem_debug( 1797c478bd9Sstevel@tonic-gate "sbmem_attach%d: No reg property\n", instance); 1807c478bd9Sstevel@tonic-gate } else { 1817c478bd9Sstevel@tonic-gate sbusmem_debug( 1827c478bd9Sstevel@tonic-gate "sbmem_attach%d: slot 0x%x size 0x%x\n", instance, 1837c478bd9Sstevel@tonic-gate rp->regspec_bustype, rp->regspec_size); 1847c478bd9Sstevel@tonic-gate } 1857c478bd9Sstevel@tonic-gate } 1867c478bd9Sstevel@tonic-gate #endif /* SBUSMEM_DEBUG */ 1877c478bd9Sstevel@tonic-gate 188a3282898Scth if (ddi_getlongprop(DDI_DEV_T_ANY, devi, 1897c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS | DDI_PROP_CANSLEEP, "ident", 1907c478bd9Sstevel@tonic-gate (caddr_t)&ident, &ilen) != DDI_PROP_SUCCESS) { 1917c478bd9Sstevel@tonic-gate #ifdef SBUSMEM_DEBUG 1927c478bd9Sstevel@tonic-gate sbusmem_debug( 1937c478bd9Sstevel@tonic-gate "sbmem_attach%d: No ident property\n", instance); 1947c478bd9Sstevel@tonic-gate #endif /* SBUSMEM_DEBUG */ 1957c478bd9Sstevel@tonic-gate break; 1967c478bd9Sstevel@tonic-gate } 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate if (ddi_soft_state_zalloc(sbusmem_state_head, 1997c478bd9Sstevel@tonic-gate instance) != DDI_SUCCESS) 2007c478bd9Sstevel@tonic-gate break; 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate if ((un = ddi_get_soft_state(sbusmem_state_head, 2037c478bd9Sstevel@tonic-gate instance)) == NULL) { 2047c478bd9Sstevel@tonic-gate ddi_soft_state_free(sbusmem_state_head, instance); 2057c478bd9Sstevel@tonic-gate break; 2067c478bd9Sstevel@tonic-gate } 2077c478bd9Sstevel@tonic-gate 2087c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(devi, ident, S_IFCHR, instance, 2097c478bd9Sstevel@tonic-gate DDI_PSEUDO, NULL) == DDI_FAILURE) { 2107c478bd9Sstevel@tonic-gate kmem_free(ident, ilen); 2117c478bd9Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 2127c478bd9Sstevel@tonic-gate ddi_soft_state_free(sbusmem_state_head, instance); 2137c478bd9Sstevel@tonic-gate break; 2147c478bd9Sstevel@tonic-gate } 2157c478bd9Sstevel@tonic-gate kmem_free(ident, ilen); 2167c478bd9Sstevel@tonic-gate un->dip = devi; 2177c478bd9Sstevel@tonic-gate un->size = size; 2187c478bd9Sstevel@tonic-gate un->pagesize = ddi_ptob(devi, 1); 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate #ifdef SBUSMEM_DEBUG 2217c478bd9Sstevel@tonic-gate sbusmem_debug("sbmem_attach%d: dip 0x%p size 0x%x\n", 2227c478bd9Sstevel@tonic-gate instance, devi, size); 2237c478bd9Sstevel@tonic-gate #endif /* SBUSMEM_DEBUG */ 2247c478bd9Sstevel@tonic-gate 2257c478bd9Sstevel@tonic-gate ddi_report_dev(devi); 2267c478bd9Sstevel@tonic-gate error = DDI_SUCCESS; 2277c478bd9Sstevel@tonic-gate break; 2287c478bd9Sstevel@tonic-gate case DDI_RESUME: 2297c478bd9Sstevel@tonic-gate error = DDI_SUCCESS; 2307c478bd9Sstevel@tonic-gate break; 2317c478bd9Sstevel@tonic-gate default: 2327c478bd9Sstevel@tonic-gate break; 2337c478bd9Sstevel@tonic-gate } 2347c478bd9Sstevel@tonic-gate return (error); 2357c478bd9Sstevel@tonic-gate } 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate static int 2387c478bd9Sstevel@tonic-gate sbmem_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 2397c478bd9Sstevel@tonic-gate { 2407c478bd9Sstevel@tonic-gate int instance; 2417c478bd9Sstevel@tonic-gate 2427c478bd9Sstevel@tonic-gate switch (cmd) { 2437c478bd9Sstevel@tonic-gate case DDI_DETACH: 2447c478bd9Sstevel@tonic-gate instance = ddi_get_instance(devi); 2457c478bd9Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 2467c478bd9Sstevel@tonic-gate ddi_soft_state_free(sbusmem_state_head, instance); 2477c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate case DDI_SUSPEND: 2507c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 2517c478bd9Sstevel@tonic-gate } 2527c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2537c478bd9Sstevel@tonic-gate } 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate /*ARGSUSED1*/ 2567c478bd9Sstevel@tonic-gate static int 2577c478bd9Sstevel@tonic-gate sbmem_open(dev_t *devp, int flag, int typ, cred_t *cred) 2587c478bd9Sstevel@tonic-gate { 2597c478bd9Sstevel@tonic-gate int instance; 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate if (typ != OTYP_CHR) 2627c478bd9Sstevel@tonic-gate return (EINVAL); 2637c478bd9Sstevel@tonic-gate 2647c478bd9Sstevel@tonic-gate instance = getminor(*devp); 2657c478bd9Sstevel@tonic-gate if (ddi_get_soft_state(sbusmem_state_head, instance) == NULL) { 2667c478bd9Sstevel@tonic-gate return (ENXIO); 2677c478bd9Sstevel@tonic-gate } 2687c478bd9Sstevel@tonic-gate return (0); 2697c478bd9Sstevel@tonic-gate } 2707c478bd9Sstevel@tonic-gate 2717c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2727c478bd9Sstevel@tonic-gate static int 2737c478bd9Sstevel@tonic-gate sbmem_close(dev_t dev, int flag, int otyp, struct cred *cred) 2747c478bd9Sstevel@tonic-gate { 2757c478bd9Sstevel@tonic-gate if (otyp != OTYP_CHR) 2767c478bd9Sstevel@tonic-gate return (EINVAL); 2777c478bd9Sstevel@tonic-gate 2787c478bd9Sstevel@tonic-gate return (0); 2797c478bd9Sstevel@tonic-gate } 2807c478bd9Sstevel@tonic-gate 2817c478bd9Sstevel@tonic-gate static int 2827c478bd9Sstevel@tonic-gate sbmem_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) 2837c478bd9Sstevel@tonic-gate { 2847c478bd9Sstevel@tonic-gate int instance, error = DDI_FAILURE; 2857c478bd9Sstevel@tonic-gate struct sbusmem_unit *un; 2867c478bd9Sstevel@tonic-gate 2877c478bd9Sstevel@tonic-gate #if defined(lint) || defined(__lint) 2887c478bd9Sstevel@tonic-gate dip = dip; 2897c478bd9Sstevel@tonic-gate #endif /* lint || __lint */ 2907c478bd9Sstevel@tonic-gate 2917c478bd9Sstevel@tonic-gate switch (infocmd) { 2927c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 2937c478bd9Sstevel@tonic-gate instance = getminor((dev_t)arg); 2947c478bd9Sstevel@tonic-gate if ((un = ddi_get_soft_state(sbusmem_state_head, 2957c478bd9Sstevel@tonic-gate instance)) != NULL) { 2967c478bd9Sstevel@tonic-gate *result = (void *)un->dip; 2977c478bd9Sstevel@tonic-gate error = DDI_SUCCESS; 2987c478bd9Sstevel@tonic-gate #ifdef SBUSMEM_DEBUG 2997c478bd9Sstevel@tonic-gate sbusmem_debug( 3007c478bd9Sstevel@tonic-gate "sbmem_info%d: returning dip 0x%p\n", instance, un->dip); 3017c478bd9Sstevel@tonic-gate #endif /* SBUSMEM_DEBUG */ 3027c478bd9Sstevel@tonic-gate 3037c478bd9Sstevel@tonic-gate } 3047c478bd9Sstevel@tonic-gate break; 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 3077c478bd9Sstevel@tonic-gate instance = getminor((dev_t)arg); 3081a70ae91Smathue *result = (void *)(uintptr_t)instance; 3097c478bd9Sstevel@tonic-gate error = DDI_SUCCESS; 3107c478bd9Sstevel@tonic-gate break; 3117c478bd9Sstevel@tonic-gate 3127c478bd9Sstevel@tonic-gate default: 3137c478bd9Sstevel@tonic-gate break; 3147c478bd9Sstevel@tonic-gate } 3157c478bd9Sstevel@tonic-gate return (error); 3167c478bd9Sstevel@tonic-gate } 3177c478bd9Sstevel@tonic-gate 3187c478bd9Sstevel@tonic-gate static int 3197c478bd9Sstevel@tonic-gate sbmem_read(dev_t dev, struct uio *uio, cred_t *cred) 3207c478bd9Sstevel@tonic-gate { 3217c478bd9Sstevel@tonic-gate return (sbmem_rw(dev, uio, UIO_READ, cred)); 3227c478bd9Sstevel@tonic-gate } 3237c478bd9Sstevel@tonic-gate 3247c478bd9Sstevel@tonic-gate static int 3257c478bd9Sstevel@tonic-gate sbmem_write(dev_t dev, struct uio *uio, cred_t *cred) 3267c478bd9Sstevel@tonic-gate { 3277c478bd9Sstevel@tonic-gate return (sbmem_rw(dev, uio, UIO_WRITE, cred)); 3287c478bd9Sstevel@tonic-gate } 3297c478bd9Sstevel@tonic-gate 3307c478bd9Sstevel@tonic-gate static int 3317c478bd9Sstevel@tonic-gate sbmem_rw(dev_t dev, struct uio *uio, enum uio_rw rw, cred_t *cred) 3327c478bd9Sstevel@tonic-gate { 3337c478bd9Sstevel@tonic-gate uint_t c; 3347c478bd9Sstevel@tonic-gate struct iovec *iov; 3357c478bd9Sstevel@tonic-gate struct sbusmem_unit *un; 3367c478bd9Sstevel@tonic-gate uint_t pagesize, msize; 3377c478bd9Sstevel@tonic-gate int instance, error = 0; 3387c478bd9Sstevel@tonic-gate dev_info_t *dip; 3397c478bd9Sstevel@tonic-gate caddr_t reg; 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate #if defined(lint) || defined(__lint) 3427c478bd9Sstevel@tonic-gate cred = cred; 3437c478bd9Sstevel@tonic-gate #endif /* lint || __lint */ 3447c478bd9Sstevel@tonic-gate 3457c478bd9Sstevel@tonic-gate instance = getminor(dev); 3467c478bd9Sstevel@tonic-gate if ((un = ddi_get_soft_state(sbusmem_state_head, instance)) == NULL) { 3477c478bd9Sstevel@tonic-gate return (ENXIO); 3487c478bd9Sstevel@tonic-gate } 3497c478bd9Sstevel@tonic-gate dip = un->dip; 3507c478bd9Sstevel@tonic-gate pagesize = un->pagesize; 3517c478bd9Sstevel@tonic-gate 3527c478bd9Sstevel@tonic-gate while (uio->uio_resid > 0 && error == 0) { 3537c478bd9Sstevel@tonic-gate iov = uio->uio_iov; 3547c478bd9Sstevel@tonic-gate if (iov->iov_len == 0) { 3557c478bd9Sstevel@tonic-gate uio->uio_iov++; 3567c478bd9Sstevel@tonic-gate uio->uio_iovcnt--; 3577c478bd9Sstevel@tonic-gate if (uio->uio_iovcnt < 0) 3587c478bd9Sstevel@tonic-gate cmn_err(CE_PANIC, "sbmem_rw"); 3597c478bd9Sstevel@tonic-gate continue; 3607c478bd9Sstevel@tonic-gate } 3617c478bd9Sstevel@tonic-gate 3627c478bd9Sstevel@tonic-gate if (uio->uio_offset > un->size) { 3637c478bd9Sstevel@tonic-gate return (EFAULT); 3647c478bd9Sstevel@tonic-gate } 3657c478bd9Sstevel@tonic-gate 3667c478bd9Sstevel@tonic-gate if (uio->uio_offset == un->size) { 3677c478bd9Sstevel@tonic-gate return (0); /* EOF */ 3687c478bd9Sstevel@tonic-gate } 3697c478bd9Sstevel@tonic-gate msize = pagesize - (uio->uio_offset & (pagesize - 1)); 3707c478bd9Sstevel@tonic-gate if (ddi_map_regs(dip, 0, ®, uio->uio_offset, 3717c478bd9Sstevel@tonic-gate (off_t)msize) != DDI_SUCCESS) { 3727c478bd9Sstevel@tonic-gate return (EFAULT); 3737c478bd9Sstevel@tonic-gate } 3747c478bd9Sstevel@tonic-gate c = min(msize, (uint_t)iov->iov_len); 3757c478bd9Sstevel@tonic-gate if (ddi_peekpokeio(dip, uio, rw, reg, (int)c, 3767c478bd9Sstevel@tonic-gate sizeof (int)) != DDI_SUCCESS) 3777c478bd9Sstevel@tonic-gate error = EFAULT; 3787c478bd9Sstevel@tonic-gate 3797c478bd9Sstevel@tonic-gate ddi_unmap_regs(dip, 0, ®, uio->uio_offset, (off_t)msize); 3807c478bd9Sstevel@tonic-gate } 3817c478bd9Sstevel@tonic-gate return (error); 3827c478bd9Sstevel@tonic-gate } 3837c478bd9Sstevel@tonic-gate 3847c478bd9Sstevel@tonic-gate static int 3857c478bd9Sstevel@tonic-gate sbmem_devmap(dev_t dev, devmap_cookie_t dhp, offset_t off, size_t len, 3867c478bd9Sstevel@tonic-gate size_t *maplen, uint_t model) 3877c478bd9Sstevel@tonic-gate { 3887c478bd9Sstevel@tonic-gate struct sbusmem_unit *un; 3897c478bd9Sstevel@tonic-gate int instance, error; 3907c478bd9Sstevel@tonic-gate 3917c478bd9Sstevel@tonic-gate #if defined(lint) || defined(__lint) 3927c478bd9Sstevel@tonic-gate model = model; 3937c478bd9Sstevel@tonic-gate #endif /* lint || __lint */ 3947c478bd9Sstevel@tonic-gate 3957c478bd9Sstevel@tonic-gate instance = getminor(dev); 3967c478bd9Sstevel@tonic-gate if ((un = ddi_get_soft_state(sbusmem_state_head, instance)) == NULL) { 3977c478bd9Sstevel@tonic-gate return (ENXIO); 3987c478bd9Sstevel@tonic-gate } 3997c478bd9Sstevel@tonic-gate if (off + len > un->size) { 4007c478bd9Sstevel@tonic-gate return (ENXIO); 4017c478bd9Sstevel@tonic-gate } 4027c478bd9Sstevel@tonic-gate if ((error = devmap_devmem_setup(dhp, un->dip, NULL, 0, 4037c478bd9Sstevel@tonic-gate off, len, PROT_ALL, DEVMAP_DEFAULTS, NULL)) < 0) { 4047c478bd9Sstevel@tonic-gate return (error); 4057c478bd9Sstevel@tonic-gate } 4067c478bd9Sstevel@tonic-gate *maplen = ptob(btopr(len)); 4077c478bd9Sstevel@tonic-gate return (0); 4087c478bd9Sstevel@tonic-gate } 409