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 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #include <sys/types.h> 307c478bd9Sstevel@tonic-gate #include <sys/conf.h> 317c478bd9Sstevel@tonic-gate #include <sys/ddi.h> 327c478bd9Sstevel@tonic-gate #include <sys/sunddi.h> 337c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 347c478bd9Sstevel@tonic-gate #include <sys/ddi_subrdefs.h> 357c478bd9Sstevel@tonic-gate #include <sys/pci.h> 367c478bd9Sstevel@tonic-gate #include <sys/autoconf.h> 377c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h> 387c478bd9Sstevel@tonic-gate #include <sys/errno.h> 397c478bd9Sstevel@tonic-gate #include <sys/kmem.h> 407c478bd9Sstevel@tonic-gate #include <sys/debug.h> 417c478bd9Sstevel@tonic-gate #include <sys/sysmacros.h> 427c478bd9Sstevel@tonic-gate #include <sys/ebus.h> 437c478bd9Sstevel@tonic-gate #include <sys/open.h> 447c478bd9Sstevel@tonic-gate #include <sys/stat.h> 457c478bd9Sstevel@tonic-gate #include <sys/file.h> 467c478bd9Sstevel@tonic-gate #include <sys/sunndi.h> 477c478bd9Sstevel@tonic-gate 487c478bd9Sstevel@tonic-gate #ifdef DEBUG 497c478bd9Sstevel@tonic-gate uint64_t ebus_debug_flags = 0; 507c478bd9Sstevel@tonic-gate #endif 517c478bd9Sstevel@tonic-gate 527c478bd9Sstevel@tonic-gate /* 537c478bd9Sstevel@tonic-gate * The values of the following variables are used to initialize 547c478bd9Sstevel@tonic-gate * the cache line size and latency timer registers in the ebus 557c478bd9Sstevel@tonic-gate * configuration header. Variables are used instead of constants 567c478bd9Sstevel@tonic-gate * to allow tuning from the /etc/system file. 577c478bd9Sstevel@tonic-gate */ 587c478bd9Sstevel@tonic-gate static uint8_t ebus_cache_line_size = 0x10; /* 64 bytes */ 597c478bd9Sstevel@tonic-gate static uint8_t ebus_latency_timer = 0x40; /* 64 PCI cycles */ 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate /* 627c478bd9Sstevel@tonic-gate * function prototypes for bus ops routines: 637c478bd9Sstevel@tonic-gate */ 647c478bd9Sstevel@tonic-gate static int 657c478bd9Sstevel@tonic-gate ebus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, 667c478bd9Sstevel@tonic-gate off_t offset, off_t len, caddr_t *addrp); 677c478bd9Sstevel@tonic-gate static int 687c478bd9Sstevel@tonic-gate ebus_ctlops(dev_info_t *dip, dev_info_t *rdip, 697c478bd9Sstevel@tonic-gate ddi_ctl_enum_t op, void *arg, void *result); 707c478bd9Sstevel@tonic-gate static int 717c478bd9Sstevel@tonic-gate ebus_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 727c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result); 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate /* 757c478bd9Sstevel@tonic-gate * function prototypes for dev ops routines: 767c478bd9Sstevel@tonic-gate */ 777c478bd9Sstevel@tonic-gate static int ebus_attach(dev_info_t *dip, ddi_attach_cmd_t cmd); 787c478bd9Sstevel@tonic-gate static int ebus_detach(dev_info_t *dip, ddi_detach_cmd_t cmd); 797c478bd9Sstevel@tonic-gate static int ebus_info(dev_info_t *dip, ddi_info_cmd_t infocmd, 807c478bd9Sstevel@tonic-gate void *arg, void **result); 817c478bd9Sstevel@tonic-gate 827c478bd9Sstevel@tonic-gate /* 837c478bd9Sstevel@tonic-gate * general function prototypes: 847c478bd9Sstevel@tonic-gate */ 857c478bd9Sstevel@tonic-gate static int ebus_config(ebus_devstate_t *ebus_p); 867c478bd9Sstevel@tonic-gate static int ebus_apply_range(ebus_devstate_t *ebus_p, dev_info_t *rdip, 87c4485e78Sjasonwu ebus_regspec_t *ebus_rp, vregspec_t *rp); 88c4485e78Sjasonwu int ebus_get_ranges_prop(ebus_devstate_t *ebus_p); 89c4485e78Sjasonwu static void ebus_get_cells_prop(ebus_devstate_t *ebus_p); 90c4485e78Sjasonwu static void ebus_vreg_dump(ebus_devstate_t *ebus_p, vregspec_t *rp); 917c478bd9Sstevel@tonic-gate 927c478bd9Sstevel@tonic-gate #define getprop(dip, name, addr, intp) \ 93a3282898Scth ddi_getlongprop(DDI_DEV_T_ANY, (dip), DDI_PROP_DONTPASS, \ 947c478bd9Sstevel@tonic-gate (name), (caddr_t)(addr), (intp)) 957c478bd9Sstevel@tonic-gate 967c478bd9Sstevel@tonic-gate static int ebus_open(dev_t *devp, int flags, int otyp, cred_t *credp); 977c478bd9Sstevel@tonic-gate static int ebus_close(dev_t dev, int flags, int otyp, cred_t *credp); 987c478bd9Sstevel@tonic-gate static int ebus_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, 997c478bd9Sstevel@tonic-gate cred_t *credp, int *rvalp); 1007c478bd9Sstevel@tonic-gate struct cb_ops ebus_cb_ops = { 1017c478bd9Sstevel@tonic-gate ebus_open, /* open */ 1027c478bd9Sstevel@tonic-gate ebus_close, /* close */ 1037c478bd9Sstevel@tonic-gate nodev, /* strategy */ 1047c478bd9Sstevel@tonic-gate nodev, /* print */ 1057c478bd9Sstevel@tonic-gate nodev, /* dump */ 1067c478bd9Sstevel@tonic-gate nodev, /* read */ 1077c478bd9Sstevel@tonic-gate nodev, /* write */ 1087c478bd9Sstevel@tonic-gate ebus_ioctl, /* ioctl */ 1097c478bd9Sstevel@tonic-gate nodev, /* devmap */ 1107c478bd9Sstevel@tonic-gate nodev, /* mmap */ 1117c478bd9Sstevel@tonic-gate nodev, /* segmap */ 1127c478bd9Sstevel@tonic-gate nochpoll, /* poll */ 1137c478bd9Sstevel@tonic-gate ddi_prop_op, /* cb_prop_op */ 1147c478bd9Sstevel@tonic-gate NULL, /* streamtab */ 1157c478bd9Sstevel@tonic-gate D_NEW | D_MP | D_HOTPLUG, /* Driver compatibility flag */ 1167c478bd9Sstevel@tonic-gate CB_REV, /* rev */ 1177c478bd9Sstevel@tonic-gate nodev, /* int (*cb_aread)() */ 1187c478bd9Sstevel@tonic-gate nodev /* int (*cb_awrite)() */ 1197c478bd9Sstevel@tonic-gate }; 1207c478bd9Sstevel@tonic-gate 1217c478bd9Sstevel@tonic-gate /* 1227c478bd9Sstevel@tonic-gate * bus ops and dev ops structures: 1237c478bd9Sstevel@tonic-gate */ 1247c478bd9Sstevel@tonic-gate static struct bus_ops ebus_bus_ops = { 1257c478bd9Sstevel@tonic-gate BUSO_REV, 1267c478bd9Sstevel@tonic-gate ebus_map, 1277c478bd9Sstevel@tonic-gate NULL, 1287c478bd9Sstevel@tonic-gate NULL, 1297c478bd9Sstevel@tonic-gate NULL, 1307c478bd9Sstevel@tonic-gate i_ddi_map_fault, 1317c478bd9Sstevel@tonic-gate ddi_dma_map, 1327c478bd9Sstevel@tonic-gate ddi_dma_allochdl, 1337c478bd9Sstevel@tonic-gate ddi_dma_freehdl, 1347c478bd9Sstevel@tonic-gate ddi_dma_bindhdl, 1357c478bd9Sstevel@tonic-gate ddi_dma_unbindhdl, 1367c478bd9Sstevel@tonic-gate ddi_dma_flush, 1377c478bd9Sstevel@tonic-gate ddi_dma_win, 1387c478bd9Sstevel@tonic-gate ddi_dma_mctl, 1397c478bd9Sstevel@tonic-gate ebus_ctlops, 1407c478bd9Sstevel@tonic-gate ddi_bus_prop_op, 1417c478bd9Sstevel@tonic-gate ndi_busop_get_eventcookie, 1427c478bd9Sstevel@tonic-gate ndi_busop_add_eventcall, 1437c478bd9Sstevel@tonic-gate ndi_busop_remove_eventcall, 1447c478bd9Sstevel@tonic-gate ndi_post_event, 1457c478bd9Sstevel@tonic-gate 0, 1467c478bd9Sstevel@tonic-gate 0, 1477c478bd9Sstevel@tonic-gate 0, 1487c478bd9Sstevel@tonic-gate 0, 1497c478bd9Sstevel@tonic-gate 0, 1507c478bd9Sstevel@tonic-gate 0, 1517c478bd9Sstevel@tonic-gate 0, 1527c478bd9Sstevel@tonic-gate 0, 1537c478bd9Sstevel@tonic-gate ebus_intr_ops 1547c478bd9Sstevel@tonic-gate }; 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate static struct dev_ops ebus_ops = { 1577c478bd9Sstevel@tonic-gate DEVO_REV, 1587c478bd9Sstevel@tonic-gate 0, 1597c478bd9Sstevel@tonic-gate ebus_info, 1607c478bd9Sstevel@tonic-gate nulldev, 1617c478bd9Sstevel@tonic-gate nulldev, 1627c478bd9Sstevel@tonic-gate ebus_attach, 1637c478bd9Sstevel@tonic-gate ebus_detach, 1647c478bd9Sstevel@tonic-gate nodev, 1657c478bd9Sstevel@tonic-gate &ebus_cb_ops, 1667c478bd9Sstevel@tonic-gate &ebus_bus_ops 1677c478bd9Sstevel@tonic-gate }; 1687c478bd9Sstevel@tonic-gate 1697c478bd9Sstevel@tonic-gate /* 1707c478bd9Sstevel@tonic-gate * module definitions: 1717c478bd9Sstevel@tonic-gate */ 1727c478bd9Sstevel@tonic-gate #include <sys/modctl.h> 1737c478bd9Sstevel@tonic-gate extern struct mod_ops mod_driverops; 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate static struct modldrv modldrv = { 1767c478bd9Sstevel@tonic-gate &mod_driverops, /* Type of module. This one is a driver */ 1777c478bd9Sstevel@tonic-gate "ebus nexus driver %I%", /* Name of module. */ 1787c478bd9Sstevel@tonic-gate &ebus_ops, /* driver ops */ 1797c478bd9Sstevel@tonic-gate }; 1807c478bd9Sstevel@tonic-gate 1817c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = { 1827c478bd9Sstevel@tonic-gate MODREV_1, (void *)&modldrv, NULL 1837c478bd9Sstevel@tonic-gate }; 1847c478bd9Sstevel@tonic-gate 1857c478bd9Sstevel@tonic-gate /* 1867c478bd9Sstevel@tonic-gate * driver global data: 1877c478bd9Sstevel@tonic-gate */ 1887c478bd9Sstevel@tonic-gate static void *per_ebus_state; /* per-ebus soft state pointer */ 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate 1917c478bd9Sstevel@tonic-gate int 1927c478bd9Sstevel@tonic-gate _init(void) 1937c478bd9Sstevel@tonic-gate { 1947c478bd9Sstevel@tonic-gate int e; 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate /* 1977c478bd9Sstevel@tonic-gate * Initialize per-ebus soft state pointer. 1987c478bd9Sstevel@tonic-gate */ 1997c478bd9Sstevel@tonic-gate e = ddi_soft_state_init(&per_ebus_state, sizeof (ebus_devstate_t), 1); 2007c478bd9Sstevel@tonic-gate if (e != 0) 2017c478bd9Sstevel@tonic-gate return (e); 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate /* 2047c478bd9Sstevel@tonic-gate * Install the module. 2057c478bd9Sstevel@tonic-gate */ 2067c478bd9Sstevel@tonic-gate e = mod_install(&modlinkage); 2077c478bd9Sstevel@tonic-gate if (e != 0) 2087c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&per_ebus_state); 2097c478bd9Sstevel@tonic-gate return (e); 2107c478bd9Sstevel@tonic-gate } 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate int 2137c478bd9Sstevel@tonic-gate _fini(void) 2147c478bd9Sstevel@tonic-gate { 2157c478bd9Sstevel@tonic-gate int e; 2167c478bd9Sstevel@tonic-gate 2177c478bd9Sstevel@tonic-gate /* 2187c478bd9Sstevel@tonic-gate * Remove the module. 2197c478bd9Sstevel@tonic-gate */ 2207c478bd9Sstevel@tonic-gate e = mod_remove(&modlinkage); 2217c478bd9Sstevel@tonic-gate if (e != 0) 2227c478bd9Sstevel@tonic-gate return (e); 2237c478bd9Sstevel@tonic-gate 2247c478bd9Sstevel@tonic-gate /* 2257c478bd9Sstevel@tonic-gate * Free the soft state info. 2267c478bd9Sstevel@tonic-gate */ 2277c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&per_ebus_state); 2287c478bd9Sstevel@tonic-gate return (e); 2297c478bd9Sstevel@tonic-gate } 2307c478bd9Sstevel@tonic-gate 2317c478bd9Sstevel@tonic-gate int 2327c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop) 2337c478bd9Sstevel@tonic-gate { 2347c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 2357c478bd9Sstevel@tonic-gate } 2367c478bd9Sstevel@tonic-gate 2377c478bd9Sstevel@tonic-gate /* device driver entry points */ 2387c478bd9Sstevel@tonic-gate 2397c478bd9Sstevel@tonic-gate /*ARGSUSED*/ 2407c478bd9Sstevel@tonic-gate static int 2417c478bd9Sstevel@tonic-gate ebus_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) 2427c478bd9Sstevel@tonic-gate { 2437c478bd9Sstevel@tonic-gate ebus_devstate_t *ebus_p; /* per ebus state pointer */ 2447c478bd9Sstevel@tonic-gate int instance; 2457c478bd9Sstevel@tonic-gate 2467c478bd9Sstevel@tonic-gate instance = getminor((dev_t)arg); 2477c478bd9Sstevel@tonic-gate ebus_p = get_ebus_soft_state(instance); 2487c478bd9Sstevel@tonic-gate 2497c478bd9Sstevel@tonic-gate switch (infocmd) { 2507c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 2517c478bd9Sstevel@tonic-gate *result = (void *)instance; 252c4485e78Sjasonwu break; 2537c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 2547c478bd9Sstevel@tonic-gate if (ebus_p == NULL) 2557c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2567c478bd9Sstevel@tonic-gate *result = (void *)ebus_p->dip; 257c4485e78Sjasonwu break; 258c4485e78Sjasonwu default: 259c4485e78Sjasonwu return (DDI_FAILURE); 2607c478bd9Sstevel@tonic-gate } 261c4485e78Sjasonwu 262c4485e78Sjasonwu return (DDI_SUCCESS); 2637c478bd9Sstevel@tonic-gate } 2647c478bd9Sstevel@tonic-gate 2657c478bd9Sstevel@tonic-gate /* 2667c478bd9Sstevel@tonic-gate * attach entry point: 2677c478bd9Sstevel@tonic-gate * 2687c478bd9Sstevel@tonic-gate * normal attach: 2697c478bd9Sstevel@tonic-gate * 2707c478bd9Sstevel@tonic-gate * create soft state structure (dip, reg, nreg and state fields) 2717c478bd9Sstevel@tonic-gate * map in configuration header 2727c478bd9Sstevel@tonic-gate * make sure device is properly configured 2737c478bd9Sstevel@tonic-gate * report device 2747c478bd9Sstevel@tonic-gate */ 2757c478bd9Sstevel@tonic-gate static int 2767c478bd9Sstevel@tonic-gate ebus_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) 2777c478bd9Sstevel@tonic-gate { 2787c478bd9Sstevel@tonic-gate ebus_devstate_t *ebus_p; /* per ebus state pointer */ 2797c478bd9Sstevel@tonic-gate int instance; 2807c478bd9Sstevel@tonic-gate 2817c478bd9Sstevel@tonic-gate DBG1(D_ATTACH, NULL, "dip=%p\n", dip); 2827c478bd9Sstevel@tonic-gate 2837c478bd9Sstevel@tonic-gate switch (cmd) { 2847c478bd9Sstevel@tonic-gate case DDI_ATTACH: 2857c478bd9Sstevel@tonic-gate 2867c478bd9Sstevel@tonic-gate /* 2877c478bd9Sstevel@tonic-gate * Allocate soft state for this instance. 2887c478bd9Sstevel@tonic-gate */ 2897c478bd9Sstevel@tonic-gate instance = ddi_get_instance(dip); 2907c478bd9Sstevel@tonic-gate if (ddi_soft_state_zalloc(per_ebus_state, instance) 2917c478bd9Sstevel@tonic-gate != DDI_SUCCESS) { 2927c478bd9Sstevel@tonic-gate DBG(D_ATTACH, NULL, "failed to alloc soft state\n"); 2937c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 2947c478bd9Sstevel@tonic-gate } 2957c478bd9Sstevel@tonic-gate ebus_p = get_ebus_soft_state(instance); 2967c478bd9Sstevel@tonic-gate ebus_p->dip = dip; 2977c478bd9Sstevel@tonic-gate mutex_init(&ebus_p->ebus_mutex, NULL, MUTEX_DRIVER, NULL); 2987c478bd9Sstevel@tonic-gate ebus_p->ebus_soft_state = EBUS_SOFT_STATE_CLOSED; 2997c478bd9Sstevel@tonic-gate 300c4485e78Sjasonwu ebus_get_cells_prop(ebus_p); 3017c478bd9Sstevel@tonic-gate 3027c478bd9Sstevel@tonic-gate (void) ddi_prop_create(DDI_DEV_T_NONE, dip, 3037c478bd9Sstevel@tonic-gate DDI_PROP_CANSLEEP, "no-dma-interrupt-sync", NULL, 0); 3047c478bd9Sstevel@tonic-gate /* Get our ranges property for mapping child registers. */ 305c4485e78Sjasonwu if (ebus_get_ranges_prop(ebus_p) != DDI_SUCCESS) { 306c4485e78Sjasonwu goto attach_fail; 3077c478bd9Sstevel@tonic-gate } 3087c478bd9Sstevel@tonic-gate 3097c478bd9Sstevel@tonic-gate /* 3107c478bd9Sstevel@tonic-gate * create minor node for devctl interfaces 3117c478bd9Sstevel@tonic-gate */ 3127c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(dip, "devctl", S_IFCHR, instance, 3137c478bd9Sstevel@tonic-gate DDI_NT_NEXUS, 0) != DDI_SUCCESS) { 314c4485e78Sjasonwu goto attach_fail; 3157c478bd9Sstevel@tonic-gate } 316c4485e78Sjasonwu 317c4485e78Sjasonwu if (ebus_config(ebus_p) != DDI_SUCCESS) { 3187c478bd9Sstevel@tonic-gate ddi_remove_minor_node(dip, "devctl"); 319c4485e78Sjasonwu goto attach_fail; 3207c478bd9Sstevel@tonic-gate } 3217c478bd9Sstevel@tonic-gate 3227c478bd9Sstevel@tonic-gate /* 3237c478bd9Sstevel@tonic-gate * Make the pci_report_pmcap() call only for RIO 3247c478bd9Sstevel@tonic-gate * implementations. 3257c478bd9Sstevel@tonic-gate */ 3267c478bd9Sstevel@tonic-gate if (IS_RIO(dip)) { 3277c478bd9Sstevel@tonic-gate (void) pci_report_pmcap(dip, PCI_PM_IDLESPEED, 3287c478bd9Sstevel@tonic-gate (void *)EBUS_4MHZ); 3297c478bd9Sstevel@tonic-gate } 3307c478bd9Sstevel@tonic-gate 3317c478bd9Sstevel@tonic-gate /* 3327c478bd9Sstevel@tonic-gate * Make the state as attached and report the device. 3337c478bd9Sstevel@tonic-gate */ 3347c478bd9Sstevel@tonic-gate ebus_p->state = ATTACHED; 3357c478bd9Sstevel@tonic-gate ddi_report_dev(dip); 3367c478bd9Sstevel@tonic-gate DBG(D_ATTACH, ebus_p, "returning\n"); 337c4485e78Sjasonwu break; 3387c478bd9Sstevel@tonic-gate 3397c478bd9Sstevel@tonic-gate case DDI_RESUME: 3407c478bd9Sstevel@tonic-gate 3417c478bd9Sstevel@tonic-gate instance = ddi_get_instance(dip); 3427c478bd9Sstevel@tonic-gate ebus_p = get_ebus_soft_state(instance); 3437c478bd9Sstevel@tonic-gate 344c4485e78Sjasonwu (void) ebus_config(ebus_p); 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate ebus_p->state = RESUMED; 347c4485e78Sjasonwu break; 3487c478bd9Sstevel@tonic-gate } 349c4485e78Sjasonwu 350c4485e78Sjasonwu return (DDI_SUCCESS); 351c4485e78Sjasonwu 352c4485e78Sjasonwu attach_fail: 353c4485e78Sjasonwu mutex_destroy(&ebus_p->ebus_mutex); 354c4485e78Sjasonwu free_ebus_soft_state(instance); 3557c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 3567c478bd9Sstevel@tonic-gate } 3577c478bd9Sstevel@tonic-gate 3587c478bd9Sstevel@tonic-gate /* 3597c478bd9Sstevel@tonic-gate * detach entry point: 3607c478bd9Sstevel@tonic-gate */ 3617c478bd9Sstevel@tonic-gate static int 3627c478bd9Sstevel@tonic-gate ebus_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) 3637c478bd9Sstevel@tonic-gate { 3647c478bd9Sstevel@tonic-gate int instance = ddi_get_instance(dip); 3657c478bd9Sstevel@tonic-gate ebus_devstate_t *ebus_p = get_ebus_soft_state(instance); 3667c478bd9Sstevel@tonic-gate 3677c478bd9Sstevel@tonic-gate switch (cmd) { 3687c478bd9Sstevel@tonic-gate case DDI_DETACH: 3697c478bd9Sstevel@tonic-gate DBG1(D_DETACH, ebus_p, "DDI_DETACH dip=%p\n", dip); 3707c478bd9Sstevel@tonic-gate 371c4485e78Sjasonwu kmem_free(ebus_p->vrangep, ebus_p->vrange_len); 3727c478bd9Sstevel@tonic-gate 3737c478bd9Sstevel@tonic-gate ddi_remove_minor_node(dip, "devctl"); 3747c478bd9Sstevel@tonic-gate mutex_destroy(&ebus_p->ebus_mutex); 3757c478bd9Sstevel@tonic-gate free_ebus_soft_state(instance); 376c4485e78Sjasonwu break; 3777c478bd9Sstevel@tonic-gate case DDI_SUSPEND: 3787c478bd9Sstevel@tonic-gate DBG1(D_DETACH, ebus_p, "DDI_SUSPEND dip=%p\n", dip); 3797c478bd9Sstevel@tonic-gate ebus_p->state = SUSPENDED; 380c4485e78Sjasonwu break; 381c4485e78Sjasonwu default: 382c4485e78Sjasonwu DBG(D_ATTACH, NULL, 383c4485e78Sjasonwu "failed to recognize ebus detach command\n"); 3847c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 3857c478bd9Sstevel@tonic-gate } 386c4485e78Sjasonwu return (DDI_SUCCESS); 387c4485e78Sjasonwu } 3887c478bd9Sstevel@tonic-gate 3897c478bd9Sstevel@tonic-gate 3907c478bd9Sstevel@tonic-gate int 391c4485e78Sjasonwu ebus_get_ranges_prop(ebus_devstate_t *ebus_p) 3927c478bd9Sstevel@tonic-gate { 393c4485e78Sjasonwu if (ddi_getlongprop(DDI_DEV_T_ANY, ebus_p->dip, DDI_PROP_DONTPASS, 394c4485e78Sjasonwu "ranges", (caddr_t)&ebus_p->vrangep, &ebus_p->vrange_len) 395c4485e78Sjasonwu != DDI_SUCCESS) { 3967c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "Can't get %s ranges property", 3977c478bd9Sstevel@tonic-gate ddi_get_name(ebus_p->dip)); 3987c478bd9Sstevel@tonic-gate return (DDI_ME_REGSPEC_RANGE); 3997c478bd9Sstevel@tonic-gate } 4007c478bd9Sstevel@tonic-gate 401c4485e78Sjasonwu ebus_p->vrange_cnt = ebus_p->vrange_len / 402c4485e78Sjasonwu (ebus_p->ebus_paddr_cells + ebus_p->ebus_addr_cells + 403c4485e78Sjasonwu ebus_p->ebus_psz_cells); 4047c478bd9Sstevel@tonic-gate 405c4485e78Sjasonwu if (ebus_p->vrange_cnt == 0) { 406c4485e78Sjasonwu kmem_free(ebus_p->vrangep, ebus_p->vrange_len); 4077c478bd9Sstevel@tonic-gate DBG(D_ATTACH, NULL, "range is equal to zero\n"); 4087c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 4097c478bd9Sstevel@tonic-gate } 4107c478bd9Sstevel@tonic-gate 4117c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 4127c478bd9Sstevel@tonic-gate } 4137c478bd9Sstevel@tonic-gate 414c4485e78Sjasonwu static void 415c4485e78Sjasonwu ebus_get_cells_prop(ebus_devstate_t *ebus_p) 4167c478bd9Sstevel@tonic-gate { 417c4485e78Sjasonwu dev_info_t *dip = ebus_p->dip; 418c4485e78Sjasonwu dev_info_t *pdip; 4197c478bd9Sstevel@tonic-gate 420c4485e78Sjasonwu ebus_p->ebus_addr_cells = ddi_getprop(DDI_DEV_T_ANY, 421c4485e78Sjasonwu dip, DDI_PROP_DONTPASS, "#address-cells", 2); 4227c478bd9Sstevel@tonic-gate 423c4485e78Sjasonwu pdip = ddi_get_parent(dip); 424c4485e78Sjasonwu ebus_p->ebus_paddr_cells = ddi_getprop(DDI_DEV_T_ANY, 425c4485e78Sjasonwu pdip, DDI_PROP_DONTPASS, "#address-cells", 2); 426c4485e78Sjasonwu 427c4485e78Sjasonwu ASSERT((ebus_p->ebus_paddr_cells == 3) || 428c4485e78Sjasonwu (ebus_p->ebus_paddr_cells == 2)); 429c4485e78Sjasonwu 430c4485e78Sjasonwu ebus_p->ebus_sz_cells = ddi_getprop(DDI_DEV_T_ANY, 431c4485e78Sjasonwu dip, DDI_PROP_DONTPASS, "#size-cells", 2); 432c4485e78Sjasonwu ebus_p->ebus_psz_cells = ddi_getprop(DDI_DEV_T_ANY, 433c4485e78Sjasonwu pdip, DDI_PROP_DONTPASS, "#size-cells", 1); 434c4485e78Sjasonwu 435c4485e78Sjasonwu /* XXX rootnex assumes 1 cell and does not respect #size-cells */ 436c4485e78Sjasonwu if (ddi_root_node() == pdip) 437c4485e78Sjasonwu ebus_p->ebus_psz_cells = 1; 438c4485e78Sjasonwu 439c4485e78Sjasonwu ASSERT((ebus_p->ebus_psz_cells == 2) || 440c4485e78Sjasonwu (ebus_p->ebus_psz_cells == 1)); 441c4485e78Sjasonwu 4427c478bd9Sstevel@tonic-gate } 4437c478bd9Sstevel@tonic-gate 4447c478bd9Sstevel@tonic-gate /* bus driver entry points */ 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate /* 4477c478bd9Sstevel@tonic-gate * bus map entry point: 4487c478bd9Sstevel@tonic-gate * 4497c478bd9Sstevel@tonic-gate * if map request is for an rnumber 4507c478bd9Sstevel@tonic-gate * get the corresponding regspec from device node 4517c478bd9Sstevel@tonic-gate * build a new regspec in our parent's format 4527c478bd9Sstevel@tonic-gate * build a new map_req with the new regspec 4537c478bd9Sstevel@tonic-gate * call up the tree to complete the mapping 4547c478bd9Sstevel@tonic-gate */ 4557c478bd9Sstevel@tonic-gate static int 4567c478bd9Sstevel@tonic-gate ebus_map(dev_info_t *dip, dev_info_t *rdip, ddi_map_req_t *mp, 4577c478bd9Sstevel@tonic-gate off_t off, off_t len, caddr_t *addrp) 4587c478bd9Sstevel@tonic-gate { 4597c478bd9Sstevel@tonic-gate ebus_devstate_t *ebus_p = get_ebus_soft_state(ddi_get_instance(dip)); 4607c478bd9Sstevel@tonic-gate ebus_regspec_t *ebus_rp, *ebus_regs; 461c4485e78Sjasonwu vregspec_t vreg; 4627c478bd9Sstevel@tonic-gate ddi_map_req_t p_map_request; 4637c478bd9Sstevel@tonic-gate int rnumber, i, n; 4647c478bd9Sstevel@tonic-gate int rval = DDI_SUCCESS; 4657c478bd9Sstevel@tonic-gate 4667c478bd9Sstevel@tonic-gate /* 4677c478bd9Sstevel@tonic-gate * Handle the mapping according to its type. 4687c478bd9Sstevel@tonic-gate */ 4697c478bd9Sstevel@tonic-gate DBG4(D_MAP, ebus_p, "rdip=%s%d: off=%x len=%x\n", 4707c478bd9Sstevel@tonic-gate ddi_get_name(rdip), ddi_get_instance(rdip), off, len); 4717c478bd9Sstevel@tonic-gate switch (mp->map_type) { 4727c478bd9Sstevel@tonic-gate case DDI_MT_REGSPEC: 4737c478bd9Sstevel@tonic-gate 4747c478bd9Sstevel@tonic-gate /* 4757c478bd9Sstevel@tonic-gate * We assume the register specification is in ebus format. 4767c478bd9Sstevel@tonic-gate * We must convert it into a PCI format regspec and pass 4777c478bd9Sstevel@tonic-gate * the request to our parent. 4787c478bd9Sstevel@tonic-gate */ 4797c478bd9Sstevel@tonic-gate DBG3(D_MAP, ebus_p, "rdip=%s%d: REGSPEC - handlep=%p\n", 4807c478bd9Sstevel@tonic-gate ddi_get_name(rdip), ddi_get_instance(rdip), 4817c478bd9Sstevel@tonic-gate mp->map_handlep); 4827c478bd9Sstevel@tonic-gate ebus_rp = (ebus_regspec_t *)mp->map_obj.rp; 4837c478bd9Sstevel@tonic-gate break; 4847c478bd9Sstevel@tonic-gate 4857c478bd9Sstevel@tonic-gate case DDI_MT_RNUMBER: 4867c478bd9Sstevel@tonic-gate 4877c478bd9Sstevel@tonic-gate /* 4887c478bd9Sstevel@tonic-gate * Get the "reg" property from the device node and convert 4897c478bd9Sstevel@tonic-gate * it to our parent's format. 4907c478bd9Sstevel@tonic-gate */ 4917c478bd9Sstevel@tonic-gate rnumber = mp->map_obj.rnumber; 4927c478bd9Sstevel@tonic-gate DBG4(D_MAP, ebus_p, "rdip=%s%d: rnumber=%x handlep=%p\n", 4937c478bd9Sstevel@tonic-gate ddi_get_name(rdip), ddi_get_instance(rdip), 4947c478bd9Sstevel@tonic-gate rnumber, mp->map_handlep); 4957c478bd9Sstevel@tonic-gate 4967c478bd9Sstevel@tonic-gate if (getprop(rdip, "reg", &ebus_regs, &i) != DDI_SUCCESS) { 4977c478bd9Sstevel@tonic-gate DBG(D_MAP, ebus_p, "can't get reg property\n"); 4987c478bd9Sstevel@tonic-gate return (DDI_ME_RNUMBER_RANGE); 4997c478bd9Sstevel@tonic-gate } 500c4485e78Sjasonwu 5017c478bd9Sstevel@tonic-gate n = i / sizeof (ebus_regspec_t); 5027c478bd9Sstevel@tonic-gate 5037c478bd9Sstevel@tonic-gate if (rnumber < 0 || rnumber >= n) { 5047c478bd9Sstevel@tonic-gate DBG(D_MAP, ebus_p, "rnumber out of range\n"); 5057c478bd9Sstevel@tonic-gate return (DDI_ME_RNUMBER_RANGE); 5067c478bd9Sstevel@tonic-gate } 5077c478bd9Sstevel@tonic-gate ebus_rp = &ebus_regs[rnumber]; 5087c478bd9Sstevel@tonic-gate break; 5097c478bd9Sstevel@tonic-gate 5107c478bd9Sstevel@tonic-gate default: 5117c478bd9Sstevel@tonic-gate return (DDI_ME_INVAL); 5127c478bd9Sstevel@tonic-gate 5137c478bd9Sstevel@tonic-gate } 5147c478bd9Sstevel@tonic-gate 5157c478bd9Sstevel@tonic-gate /* Adjust our reg property with offset and length */ 5167c478bd9Sstevel@tonic-gate ebus_rp->addr_low += off; 5177c478bd9Sstevel@tonic-gate if (len) 5187c478bd9Sstevel@tonic-gate ebus_rp->size = len; 5197c478bd9Sstevel@tonic-gate 520c4485e78Sjasonwu rval = ebus_apply_range(ebus_p, rdip, ebus_rp, &vreg); 5217c478bd9Sstevel@tonic-gate 5227c478bd9Sstevel@tonic-gate if (mp->map_type == DDI_MT_RNUMBER) 5237c478bd9Sstevel@tonic-gate kmem_free(ebus_regs, i); 5247c478bd9Sstevel@tonic-gate 5257c478bd9Sstevel@tonic-gate if (rval != DDI_SUCCESS) 5267c478bd9Sstevel@tonic-gate return (rval); 5277c478bd9Sstevel@tonic-gate 5287c478bd9Sstevel@tonic-gate p_map_request = *mp; 5297c478bd9Sstevel@tonic-gate p_map_request.map_type = DDI_MT_REGSPEC; 5307c478bd9Sstevel@tonic-gate 531c4485e78Sjasonwu p_map_request.map_obj.rp = (struct regspec *)&vreg; 5327c478bd9Sstevel@tonic-gate 5337c478bd9Sstevel@tonic-gate rval = ddi_map(dip, &p_map_request, 0, 0, addrp); 5347c478bd9Sstevel@tonic-gate DBG1(D_MAP, ebus_p, "parent returned %x\n", rval); 5357c478bd9Sstevel@tonic-gate return (rval); 5367c478bd9Sstevel@tonic-gate } 5377c478bd9Sstevel@tonic-gate 538c4485e78Sjasonwu /* 539c4485e78Sjasonwu * ebus_apply_range generically relocates child's regspec to 540c4485e78Sjasonwu * parent's format according to ebus' range spec 541c4485e78Sjasonwu * 542c4485e78Sjasonwu * Assumptions: 543c4485e78Sjasonwu * - rng_caddr_hi is the space type 544c4485e78Sjasonwu * - rng_caddr_low is the base address 545c4485e78Sjasonwu * - ebus address is 32 bit and ebus entirely lives between 0-4G of 546c4485e78Sjasonwu * parent space, so maths on preg/rng_cell_p[ebus_p->ebus_paddr_cells - 1], 547c4485e78Sjasonwu * preg_cell_p[i], rng_caddr_low and ebus_rp->size are sufficient. 548c4485e78Sjasonwu */ 5497c478bd9Sstevel@tonic-gate static int 5507c478bd9Sstevel@tonic-gate ebus_apply_range(ebus_devstate_t *ebus_p, dev_info_t *rdip, 551c4485e78Sjasonwu ebus_regspec_t *ebus_rp, vregspec_t *rp) { 552c4485e78Sjasonwu int b, i; 553c4485e78Sjasonwu int nrange = ebus_p->vrange_cnt; 554c4485e78Sjasonwu uint32_t addr_offset, rng_caddr_hi, rng_caddr_low, rng_sz; 555c4485e78Sjasonwu uint32_t req_addr = ebus_rp->addr_low; 556c4485e78Sjasonwu 557c4485e78Sjasonwu uint32_t *rng_cell_p = (uint32_t *)ebus_p->vrangep; 558c4485e78Sjasonwu int rng_rec_sz = ebus_p->ebus_paddr_cells + ebus_p->ebus_addr_cells + 559c4485e78Sjasonwu ebus_p->ebus_sz_cells; 560c4485e78Sjasonwu uint32_t *preg_cell_p = (uint32_t *)rp; 561c4485e78Sjasonwu int preg_rec_sz = ebus_p->ebus_paddr_cells + ebus_p->ebus_psz_cells; 562c4485e78Sjasonwu 5637c478bd9Sstevel@tonic-gate static char out_of_range[] = 5647c478bd9Sstevel@tonic-gate "Out of range register specification from device node <%s>"; 5657c478bd9Sstevel@tonic-gate 5667c478bd9Sstevel@tonic-gate DBG3(D_MAP, ebus_p, "Range Matching Addr 0x%x.%x size 0x%x\n", 567c4485e78Sjasonwu ebus_rp->addr_hi, req_addr, ebus_rp->size); 5687c478bd9Sstevel@tonic-gate 569c4485e78Sjasonwu for (b = 0; b < nrange; b++, rng_cell_p += rng_rec_sz) { 5707c478bd9Sstevel@tonic-gate 571c4485e78Sjasonwu rng_caddr_hi = rng_cell_p[0]; 572c4485e78Sjasonwu rng_caddr_low = rng_cell_p[1]; 573c4485e78Sjasonwu rng_sz = rng_cell_p[rng_rec_sz-1]; 5747c478bd9Sstevel@tonic-gate 575c4485e78Sjasonwu /* Check for correct space */ 576c4485e78Sjasonwu if (ebus_rp->addr_hi != rng_caddr_hi) 577c4485e78Sjasonwu continue; 578c4485e78Sjasonwu 579c4485e78Sjasonwu /* Detect whether request entirely fits within a range */ 580c4485e78Sjasonwu if (req_addr < rng_caddr_low) 581c4485e78Sjasonwu continue; 582c4485e78Sjasonwu 583c4485e78Sjasonwu if ((req_addr + ebus_rp->size - 1) 584c4485e78Sjasonwu > (rng_caddr_low + rng_sz - 1)) 585c4485e78Sjasonwu continue; 586c4485e78Sjasonwu 587c4485e78Sjasonwu addr_offset = req_addr - rng_caddr_low; 588c4485e78Sjasonwu 589c4485e78Sjasonwu /* parent addr = child addr + offset from ranges */ 590c4485e78Sjasonwu for (i = 0; i < preg_rec_sz; i++) 591c4485e78Sjasonwu preg_cell_p[i] = 0; 592c4485e78Sjasonwu 593c4485e78Sjasonwu /* Copy the physical address */ 594c4485e78Sjasonwu for (i = 0; i < ebus_p->ebus_paddr_cells; i++) 595c4485e78Sjasonwu preg_cell_p[i] = rng_cell_p[ebus_p->ebus_addr_cells+i]; 596c4485e78Sjasonwu 597c4485e78Sjasonwu preg_cell_p[ebus_p->ebus_paddr_cells-1] += addr_offset; 598c4485e78Sjasonwu 599c4485e78Sjasonwu /* Copy the size */ 600c4485e78Sjasonwu preg_cell_p[preg_rec_sz-1] = min(ebus_rp->size, 601c4485e78Sjasonwu rng_sz - addr_offset); 602c4485e78Sjasonwu 603c4485e78Sjasonwu #ifdef DEBUG 604c4485e78Sjasonwu ebus_vreg_dump(ebus_p, (vregspec_t *)preg_cell_p); 605c4485e78Sjasonwu #endif /* DEBUG */ 6067c478bd9Sstevel@tonic-gate 6077c478bd9Sstevel@tonic-gate break; 6087c478bd9Sstevel@tonic-gate } 6097c478bd9Sstevel@tonic-gate 6107c478bd9Sstevel@tonic-gate if (b == nrange) { 6117c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, out_of_range, ddi_get_name(rdip)); 6127c478bd9Sstevel@tonic-gate return (DDI_ME_REGSPEC_RANGE); 6137c478bd9Sstevel@tonic-gate } 6147c478bd9Sstevel@tonic-gate 615c4485e78Sjasonwu return (DDI_SUCCESS); 6167c478bd9Sstevel@tonic-gate } 6177c478bd9Sstevel@tonic-gate 6187c478bd9Sstevel@tonic-gate static int 6197c478bd9Sstevel@tonic-gate ebus_name_child(dev_info_t *child, char *name, int namelen) 6207c478bd9Sstevel@tonic-gate { 6217c478bd9Sstevel@tonic-gate ebus_regspec_t *ebus_rp; 6227c478bd9Sstevel@tonic-gate int reglen; 6237c478bd9Sstevel@tonic-gate 6247c478bd9Sstevel@tonic-gate /* 6257c478bd9Sstevel@tonic-gate * Get the address portion of the node name based on the 6267c478bd9Sstevel@tonic-gate * address/offset. 6277c478bd9Sstevel@tonic-gate */ 628a3282898Scth if (ddi_getlongprop(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 6297c478bd9Sstevel@tonic-gate "reg", (caddr_t)&ebus_rp, ®len) != DDI_SUCCESS) { 6307c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6317c478bd9Sstevel@tonic-gate } 6327c478bd9Sstevel@tonic-gate 6337c478bd9Sstevel@tonic-gate (void) snprintf(name, namelen, "%x,%x", ebus_rp->addr_hi, 6347c478bd9Sstevel@tonic-gate ebus_rp->addr_low); 6357c478bd9Sstevel@tonic-gate kmem_free(ebus_rp, reglen); 6367c478bd9Sstevel@tonic-gate 6377c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 6387c478bd9Sstevel@tonic-gate } 6397c478bd9Sstevel@tonic-gate 6407c478bd9Sstevel@tonic-gate /* 6417c478bd9Sstevel@tonic-gate * control ops entry point: 6427c478bd9Sstevel@tonic-gate * 6437c478bd9Sstevel@tonic-gate * Requests handled completely: 6447c478bd9Sstevel@tonic-gate * DDI_CTLOPS_INITCHILD 6457c478bd9Sstevel@tonic-gate * DDI_CTLOPS_UNINITCHILD 6467c478bd9Sstevel@tonic-gate * DDI_CTLOPS_REPORTDEV 6477c478bd9Sstevel@tonic-gate * DDI_CTLOPS_REGSIZE 6487c478bd9Sstevel@tonic-gate * DDI_CTLOPS_NREGS 6497c478bd9Sstevel@tonic-gate * 6507c478bd9Sstevel@tonic-gate * All others passed to parent. 6517c478bd9Sstevel@tonic-gate */ 6527c478bd9Sstevel@tonic-gate static int 6537c478bd9Sstevel@tonic-gate ebus_ctlops(dev_info_t *dip, dev_info_t *rdip, 6547c478bd9Sstevel@tonic-gate ddi_ctl_enum_t op, void *arg, void *result) 6557c478bd9Sstevel@tonic-gate { 6567c478bd9Sstevel@tonic-gate #ifdef DEBUG 6577c478bd9Sstevel@tonic-gate ebus_devstate_t *ebus_p = get_ebus_soft_state(ddi_get_instance(dip)); 6587c478bd9Sstevel@tonic-gate #endif 6597c478bd9Sstevel@tonic-gate ebus_regspec_t *ebus_rp; 6607c478bd9Sstevel@tonic-gate int i, n; 6617c478bd9Sstevel@tonic-gate char name[10]; 6627c478bd9Sstevel@tonic-gate 6637c478bd9Sstevel@tonic-gate switch (op) { 6647c478bd9Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: { 6657c478bd9Sstevel@tonic-gate dev_info_t *child = (dev_info_t *)arg; 6667c478bd9Sstevel@tonic-gate /* 6677c478bd9Sstevel@tonic-gate * Set the address portion of the node name based on the 6687c478bd9Sstevel@tonic-gate * address/offset. 6697c478bd9Sstevel@tonic-gate */ 6707c478bd9Sstevel@tonic-gate DBG2(D_CTLOPS, ebus_p, "DDI_CTLOPS_INITCHILD: rdip=%s%d\n", 6717c478bd9Sstevel@tonic-gate ddi_get_name(child), ddi_get_instance(child)); 6727c478bd9Sstevel@tonic-gate 6737c478bd9Sstevel@tonic-gate if (ebus_name_child(child, name, 10) != DDI_SUCCESS) { 6747c478bd9Sstevel@tonic-gate DBG(D_CTLOPS, ebus_p, "can't name child\n"); 6757c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 6767c478bd9Sstevel@tonic-gate } 6777c478bd9Sstevel@tonic-gate 6787c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, name); 6797c478bd9Sstevel@tonic-gate ddi_set_parent_data(child, NULL); 6807c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 6817c478bd9Sstevel@tonic-gate } 6827c478bd9Sstevel@tonic-gate 6837c478bd9Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 6847c478bd9Sstevel@tonic-gate DBG2(D_CTLOPS, ebus_p, "DDI_CTLOPS_UNINITCHILD: rdip=%s%d\n", 6857c478bd9Sstevel@tonic-gate ddi_get_name((dev_info_t *)arg), 6867c478bd9Sstevel@tonic-gate ddi_get_instance((dev_info_t *)arg)); 6877c478bd9Sstevel@tonic-gate ddi_set_name_addr((dev_info_t *)arg, NULL); 6887c478bd9Sstevel@tonic-gate ddi_remove_minor_node((dev_info_t *)arg, NULL); 6897c478bd9Sstevel@tonic-gate impl_rem_dev_props((dev_info_t *)arg); 6907c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 6917c478bd9Sstevel@tonic-gate 6927c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: 6937c478bd9Sstevel@tonic-gate 6947c478bd9Sstevel@tonic-gate DBG2(D_CTLOPS, ebus_p, "DDI_CTLOPS_REPORTDEV: rdip=%s%d\n", 6957c478bd9Sstevel@tonic-gate ddi_get_name(rdip), ddi_get_instance(rdip)); 6967c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?%s%d at %s%d: offset %s\n", 6977c478bd9Sstevel@tonic-gate ddi_driver_name(rdip), ddi_get_instance(rdip), 6987c478bd9Sstevel@tonic-gate ddi_driver_name(dip), ddi_get_instance(dip), 6997c478bd9Sstevel@tonic-gate ddi_get_name_addr(rdip)); 7007c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 7017c478bd9Sstevel@tonic-gate 7027c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE: 7037c478bd9Sstevel@tonic-gate 7047c478bd9Sstevel@tonic-gate DBG2(D_CTLOPS, ebus_p, "DDI_CTLOPS_REGSIZE: rdip=%s%d\n", 7057c478bd9Sstevel@tonic-gate ddi_get_name(rdip), ddi_get_instance(rdip)); 7067c478bd9Sstevel@tonic-gate if (getprop(rdip, "reg", &ebus_rp, &i) != DDI_SUCCESS) { 7077c478bd9Sstevel@tonic-gate DBG(D_CTLOPS, ebus_p, "can't get reg property\n"); 7087c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 7097c478bd9Sstevel@tonic-gate } 7107c478bd9Sstevel@tonic-gate n = i / sizeof (ebus_regspec_t); 7117c478bd9Sstevel@tonic-gate if (*(int *)arg < 0 || *(int *)arg >= n) { 7127c478bd9Sstevel@tonic-gate DBG(D_MAP, ebus_p, "rnumber out of range\n"); 7137c478bd9Sstevel@tonic-gate kmem_free(ebus_rp, i); 7147c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 7157c478bd9Sstevel@tonic-gate } 7167c478bd9Sstevel@tonic-gate *((off_t *)result) = ebus_rp[*(int *)arg].size; 7177c478bd9Sstevel@tonic-gate kmem_free(ebus_rp, i); 7187c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 7197c478bd9Sstevel@tonic-gate 7207c478bd9Sstevel@tonic-gate case DDI_CTLOPS_NREGS: 7217c478bd9Sstevel@tonic-gate 7227c478bd9Sstevel@tonic-gate DBG2(D_CTLOPS, ebus_p, "DDI_CTLOPS_NREGS: rdip=%s%d\n", 7237c478bd9Sstevel@tonic-gate ddi_get_name(rdip), ddi_get_instance(rdip)); 7247c478bd9Sstevel@tonic-gate if (getprop(rdip, "reg", &ebus_rp, &i) != DDI_SUCCESS) { 7257c478bd9Sstevel@tonic-gate DBG(D_CTLOPS, ebus_p, "can't get reg property\n"); 7267c478bd9Sstevel@tonic-gate return (DDI_FAILURE); 7277c478bd9Sstevel@tonic-gate } 7287c478bd9Sstevel@tonic-gate *((uint_t *)result) = i / sizeof (ebus_regspec_t); 7297c478bd9Sstevel@tonic-gate kmem_free(ebus_rp, i); 7307c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 7317c478bd9Sstevel@tonic-gate } 7327c478bd9Sstevel@tonic-gate 7337c478bd9Sstevel@tonic-gate /* 7347c478bd9Sstevel@tonic-gate * Now pass the request up to our parent. 7357c478bd9Sstevel@tonic-gate */ 7367c478bd9Sstevel@tonic-gate DBG2(D_CTLOPS, ebus_p, "passing request to parent: rdip=%s%d\n", 7377c478bd9Sstevel@tonic-gate ddi_get_name(rdip), ddi_get_instance(rdip)); 7387c478bd9Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, op, arg, result)); 7397c478bd9Sstevel@tonic-gate } 7407c478bd9Sstevel@tonic-gate 7417c478bd9Sstevel@tonic-gate struct ebus_string_to_pil { 7427c478bd9Sstevel@tonic-gate int8_t *string; 7437c478bd9Sstevel@tonic-gate uint32_t pil; 7447c478bd9Sstevel@tonic-gate }; 7457c478bd9Sstevel@tonic-gate 7467c478bd9Sstevel@tonic-gate static struct ebus_string_to_pil ebus_name_to_pil[] = {{"SUNW,CS4231", 9}, 7477c478bd9Sstevel@tonic-gate {"audio", 9}, 7487c478bd9Sstevel@tonic-gate {"fdthree", 8}, 7497c478bd9Sstevel@tonic-gate {"floppy", 8}, 7507c478bd9Sstevel@tonic-gate {"ecpp", 3}, 7517c478bd9Sstevel@tonic-gate {"parallel", 3}, 7527c478bd9Sstevel@tonic-gate {"su", 12}, 7537c478bd9Sstevel@tonic-gate {"se", 12}, 7547c478bd9Sstevel@tonic-gate {"serial", 12}, 7557c478bd9Sstevel@tonic-gate {"power", 14}}; 7567c478bd9Sstevel@tonic-gate 7577c478bd9Sstevel@tonic-gate static struct ebus_string_to_pil ebus_device_type_to_pil[] = {{"serial", 12}, 7587c478bd9Sstevel@tonic-gate {"block", 8}}; 7597c478bd9Sstevel@tonic-gate 7607c478bd9Sstevel@tonic-gate static int 7617c478bd9Sstevel@tonic-gate ebus_intr_ops(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 7627c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 7637c478bd9Sstevel@tonic-gate { 7647c478bd9Sstevel@tonic-gate #ifdef DEBUG 7657c478bd9Sstevel@tonic-gate ebus_devstate_t *ebus_p = get_ebus_soft_state(ddi_get_instance(dip)); 7667c478bd9Sstevel@tonic-gate #endif 7677c478bd9Sstevel@tonic-gate int32_t i, max_children, max_device_types, len; 7687c478bd9Sstevel@tonic-gate char *name_p, *device_type_p; 7697c478bd9Sstevel@tonic-gate 770*a195726fSgovinda DBG1(D_INTR, ebus_p, "ebus_p 0x%p\n", ebus_p); 7717c478bd9Sstevel@tonic-gate 7727c478bd9Sstevel@tonic-gate /* 7737c478bd9Sstevel@tonic-gate * NOTE: These ops below will never be supported in this nexus 7747c478bd9Sstevel@tonic-gate * driver, hence they always return immediately. 7757c478bd9Sstevel@tonic-gate */ 7767c478bd9Sstevel@tonic-gate switch (intr_op) { 7777c478bd9Sstevel@tonic-gate case DDI_INTROP_GETCAP: 778*a195726fSgovinda *(int *)result = DDI_INTR_FLAG_LEVEL; 7797c478bd9Sstevel@tonic-gate return (DDI_SUCCESS); 7807c478bd9Sstevel@tonic-gate case DDI_INTROP_SETCAP: 7817c478bd9Sstevel@tonic-gate case DDI_INTROP_SETMASK: 7827c478bd9Sstevel@tonic-gate case DDI_INTROP_CLRMASK: 7837c478bd9Sstevel@tonic-gate case DDI_INTROP_GETPENDING: 7847c478bd9Sstevel@tonic-gate return (DDI_ENOTSUP); 7857c478bd9Sstevel@tonic-gate default: 7867c478bd9Sstevel@tonic-gate break; 7877c478bd9Sstevel@tonic-gate } 7887c478bd9Sstevel@tonic-gate 789*a195726fSgovinda if ((intr_op == DDI_INTROP_SUPPORTED_TYPES) || hdlp->ih_pri) 7907c478bd9Sstevel@tonic-gate goto done; 7917c478bd9Sstevel@tonic-gate 7927c478bd9Sstevel@tonic-gate /* 7937c478bd9Sstevel@tonic-gate * This is a hack to set the PIL for the devices under ebus. 7947c478bd9Sstevel@tonic-gate * We first look up a device by it's specific name, if we can't 7957c478bd9Sstevel@tonic-gate * match the name, we try and match it's device_type property. 7967c478bd9Sstevel@tonic-gate * Lastly we default a PIL level of 1. 7977c478bd9Sstevel@tonic-gate */ 7987c478bd9Sstevel@tonic-gate name_p = ddi_node_name(rdip); 7997c478bd9Sstevel@tonic-gate max_children = sizeof (ebus_name_to_pil) / 8007c478bd9Sstevel@tonic-gate sizeof (struct ebus_string_to_pil); 8017c478bd9Sstevel@tonic-gate 8027c478bd9Sstevel@tonic-gate for (i = 0; i < max_children; i++) { 8037c478bd9Sstevel@tonic-gate if (strcmp(ebus_name_to_pil[i].string, name_p) == 0) { 8047c478bd9Sstevel@tonic-gate DBG2(D_INTR, ebus_p, "child name %s; match PIL %d\n", 8057c478bd9Sstevel@tonic-gate ebus_name_to_pil[i].string, 8067c478bd9Sstevel@tonic-gate ebus_name_to_pil[i].pil); 8077c478bd9Sstevel@tonic-gate 808*a195726fSgovinda hdlp->ih_pri = ebus_name_to_pil[i].pil; 8097c478bd9Sstevel@tonic-gate goto done; 8107c478bd9Sstevel@tonic-gate } 8117c478bd9Sstevel@tonic-gate } 8127c478bd9Sstevel@tonic-gate 813a3282898Scth if (ddi_getlongprop(DDI_DEV_T_ANY, rdip, DDI_PROP_DONTPASS, 8147c478bd9Sstevel@tonic-gate "device_type", (caddr_t)&device_type_p, &len) == DDI_SUCCESS) { 8157c478bd9Sstevel@tonic-gate 8167c478bd9Sstevel@tonic-gate max_device_types = sizeof (ebus_device_type_to_pil) / 8177c478bd9Sstevel@tonic-gate sizeof (struct ebus_string_to_pil); 8187c478bd9Sstevel@tonic-gate 8197c478bd9Sstevel@tonic-gate for (i = 0; i < max_device_types; i++) { 8207c478bd9Sstevel@tonic-gate if (strcmp(ebus_device_type_to_pil[i].string, 8217c478bd9Sstevel@tonic-gate device_type_p) == 0) { 8227c478bd9Sstevel@tonic-gate DBG2(D_INTR, ebus_p, "Device type %s; match " 8237c478bd9Sstevel@tonic-gate "PIL %d\n", ebus_device_type_to_pil[i]. 8247c478bd9Sstevel@tonic-gate string, ebus_device_type_to_pil[i].pil); 8257c478bd9Sstevel@tonic-gate 826*a195726fSgovinda hdlp->ih_pri = ebus_device_type_to_pil[i].pil; 8277c478bd9Sstevel@tonic-gate break; 8287c478bd9Sstevel@tonic-gate } 8297c478bd9Sstevel@tonic-gate } 8307c478bd9Sstevel@tonic-gate 8317c478bd9Sstevel@tonic-gate kmem_free(device_type_p, len); 8327c478bd9Sstevel@tonic-gate } 8337c478bd9Sstevel@tonic-gate 8347c478bd9Sstevel@tonic-gate /* 8357c478bd9Sstevel@tonic-gate * If we get here, we need to set a default value 8367c478bd9Sstevel@tonic-gate * for the PIL. 8377c478bd9Sstevel@tonic-gate */ 838*a195726fSgovinda if (hdlp->ih_pri == 0) { 839*a195726fSgovinda hdlp->ih_pri = 1; 8407c478bd9Sstevel@tonic-gate 8417c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d assigning default interrupt level %d " 842*a195726fSgovinda "for device %s%d", ddi_driver_name(dip), 843*a195726fSgovinda ddi_get_instance(dip), hdlp->ih_pri, ddi_driver_name(rdip), 844*a195726fSgovinda ddi_get_instance(rdip)); 8457c478bd9Sstevel@tonic-gate } 8467c478bd9Sstevel@tonic-gate 8477c478bd9Sstevel@tonic-gate done: 8487c478bd9Sstevel@tonic-gate /* Pass up the request to our parent. */ 8497c478bd9Sstevel@tonic-gate return (i_ddi_intr_ops(dip, rdip, intr_op, hdlp, result)); 8507c478bd9Sstevel@tonic-gate } 8517c478bd9Sstevel@tonic-gate 852c4485e78Sjasonwu /* 853c4485e78Sjasonwu * ebus_config: setup pci config space registers: 854c4485e78Sjasonwu * enable bus mastering, memory access and error reporting 855c4485e78Sjasonwu */ 8567c478bd9Sstevel@tonic-gate static int 8577c478bd9Sstevel@tonic-gate ebus_config(ebus_devstate_t *ebus_p) 8587c478bd9Sstevel@tonic-gate { 8597c478bd9Sstevel@tonic-gate ddi_acc_handle_t conf_handle; 8607c478bd9Sstevel@tonic-gate uint16_t comm; 861c4485e78Sjasonwu dev_info_t *dip = ebus_p->dip; 862c4485e78Sjasonwu char *devtype_str; 863c4485e78Sjasonwu int devtype_len; 864c4485e78Sjasonwu 865c4485e78Sjasonwu if (ddi_getlongprop(DDI_DEV_T_ANY, ddi_get_parent(dip), 866c4485e78Sjasonwu DDI_PROP_DONTPASS, "device_type", (caddr_t)&devtype_str, 867c4485e78Sjasonwu &devtype_len) != DDI_SUCCESS) { 868c4485e78Sjasonwu cmn_err(CE_WARN, "Can't get %s device_type property", 869c4485e78Sjasonwu ddi_get_name(ddi_get_parent(dip))); 870c4485e78Sjasonwu 871c4485e78Sjasonwu return (DDI_FAILURE); 872c4485e78Sjasonwu } 873c4485e78Sjasonwu 874c4485e78Sjasonwu comm = strcmp(devtype_str, "pci"); 875c4485e78Sjasonwu kmem_free(devtype_str, devtype_len); 876c4485e78Sjasonwu 877c4485e78Sjasonwu if (comm) 878c4485e78Sjasonwu return (DDI_SUCCESS); 8797c478bd9Sstevel@tonic-gate 8807c478bd9Sstevel@tonic-gate /* 8817c478bd9Sstevel@tonic-gate * Make sure the master enable and memory access enable 8827c478bd9Sstevel@tonic-gate * bits are set in the config command register. 8837c478bd9Sstevel@tonic-gate */ 8847c478bd9Sstevel@tonic-gate if (pci_config_setup(ebus_p->dip, &conf_handle) != DDI_SUCCESS) 885c4485e78Sjasonwu return (DDI_FAILURE); 8867c478bd9Sstevel@tonic-gate 8877c478bd9Sstevel@tonic-gate comm = pci_config_get16(conf_handle, PCI_CONF_COMM), 8887c478bd9Sstevel@tonic-gate #ifdef DEBUG 8897c478bd9Sstevel@tonic-gate DBG1(D_MAP, ebus_p, "command register was 0x%x\n", comm); 8907c478bd9Sstevel@tonic-gate #endif 8917c478bd9Sstevel@tonic-gate comm |= (PCI_COMM_ME|PCI_COMM_MAE|PCI_COMM_SERR_ENABLE| 8927c478bd9Sstevel@tonic-gate PCI_COMM_PARITY_DETECT); 8937c478bd9Sstevel@tonic-gate pci_config_put16(conf_handle, PCI_CONF_COMM, comm), 8947c478bd9Sstevel@tonic-gate #ifdef DEBUG 8957c478bd9Sstevel@tonic-gate DBG1(D_MAP, ebus_p, "command register is now 0x%x\n", comm); 8967c478bd9Sstevel@tonic-gate #endif 8977c478bd9Sstevel@tonic-gate pci_config_put8(conf_handle, PCI_CONF_CACHE_LINESZ, 8987c478bd9Sstevel@tonic-gate (uchar_t)ebus_cache_line_size); 8997c478bd9Sstevel@tonic-gate pci_config_put8(conf_handle, PCI_CONF_LATENCY_TIMER, 9007c478bd9Sstevel@tonic-gate (uchar_t)ebus_latency_timer); 9017c478bd9Sstevel@tonic-gate pci_config_teardown(&conf_handle); 902c4485e78Sjasonwu return (DDI_SUCCESS); 9037c478bd9Sstevel@tonic-gate } 9047c478bd9Sstevel@tonic-gate 9057c478bd9Sstevel@tonic-gate #ifdef DEBUG 9067c478bd9Sstevel@tonic-gate extern void prom_printf(const char *, ...); 9077c478bd9Sstevel@tonic-gate 9087c478bd9Sstevel@tonic-gate static void 9097c478bd9Sstevel@tonic-gate ebus_debug(uint_t flag, ebus_devstate_t *ebus_p, char *fmt, 9107c478bd9Sstevel@tonic-gate uintptr_t a1, uintptr_t a2, uintptr_t a3, uintptr_t a4, uintptr_t a5) 9117c478bd9Sstevel@tonic-gate { 9127c478bd9Sstevel@tonic-gate char *s; 9137c478bd9Sstevel@tonic-gate 9147c478bd9Sstevel@tonic-gate if (ebus_debug_flags & flag) { 9157c478bd9Sstevel@tonic-gate switch (flag) { 9167c478bd9Sstevel@tonic-gate case D_ATTACH: 9177c478bd9Sstevel@tonic-gate s = "attach"; break; 9187c478bd9Sstevel@tonic-gate case D_DETACH: 9197c478bd9Sstevel@tonic-gate s = "detach"; break; 9207c478bd9Sstevel@tonic-gate case D_MAP: 9217c478bd9Sstevel@tonic-gate s = "map"; break; 9227c478bd9Sstevel@tonic-gate case D_CTLOPS: 9237c478bd9Sstevel@tonic-gate s = "ctlops"; break; 9247c478bd9Sstevel@tonic-gate case D_INTR: 9257c478bd9Sstevel@tonic-gate s = "intr"; break; 9267c478bd9Sstevel@tonic-gate } 9277c478bd9Sstevel@tonic-gate if (ebus_p) 9287c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: %s: ", 9297c478bd9Sstevel@tonic-gate ddi_get_name(ebus_p->dip), 9307c478bd9Sstevel@tonic-gate ddi_get_instance(ebus_p->dip), s); 9317c478bd9Sstevel@tonic-gate else 9327c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "ebus: "); 9337c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, fmt, a1, a2, a3, a4, a5); 9347c478bd9Sstevel@tonic-gate } 9357c478bd9Sstevel@tonic-gate } 936c4485e78Sjasonwu 937c4485e78Sjasonwu static void 938c4485e78Sjasonwu ebus_vreg_dump(ebus_devstate_t *ebus_p, vregspec_t *rp) 939c4485e78Sjasonwu { 940c4485e78Sjasonwu if (ebus_p->ebus_paddr_cells == 3) { 941c4485e78Sjasonwu DBG5(D_MAP, ebus_p, "(%x,%x,%x)(%x,%x)\n", 942c4485e78Sjasonwu rp->pci_regspec.pci_phys_hi, 943c4485e78Sjasonwu rp->pci_regspec.pci_phys_mid, 944c4485e78Sjasonwu rp->pci_regspec.pci_phys_low, 945c4485e78Sjasonwu rp->pci_regspec.pci_size_hi, 946c4485e78Sjasonwu rp->pci_regspec.pci_size_low); 947c4485e78Sjasonwu } else if (ebus_p->ebus_paddr_cells == 2) { 948c4485e78Sjasonwu DBG3(D_MAP, ebus_p, "%x,%x,%x\n", 949c4485e78Sjasonwu rp->jbus_regspec.regspec_bustype, 950c4485e78Sjasonwu rp->jbus_regspec.regspec_addr, 951c4485e78Sjasonwu rp->jbus_regspec.regspec_size); 952c4485e78Sjasonwu } 953c4485e78Sjasonwu } 954c4485e78Sjasonwu #endif /* DEBUG */ 9557c478bd9Sstevel@tonic-gate 9567c478bd9Sstevel@tonic-gate /* ARGSUSED3 */ 9577c478bd9Sstevel@tonic-gate static int 9587c478bd9Sstevel@tonic-gate ebus_open(dev_t *devp, int flags, int otyp, cred_t *credp) 9597c478bd9Sstevel@tonic-gate { 9607c478bd9Sstevel@tonic-gate ebus_devstate_t *ebus_p; 9617c478bd9Sstevel@tonic-gate 9627c478bd9Sstevel@tonic-gate /* 9637c478bd9Sstevel@tonic-gate * Make sure the open is for the right file type. 9647c478bd9Sstevel@tonic-gate */ 9657c478bd9Sstevel@tonic-gate if (otyp != OTYP_CHR) 9667c478bd9Sstevel@tonic-gate return (EINVAL); 9677c478bd9Sstevel@tonic-gate 9687c478bd9Sstevel@tonic-gate /* 9697c478bd9Sstevel@tonic-gate * Get the soft state structure for the device. 9707c478bd9Sstevel@tonic-gate */ 9717c478bd9Sstevel@tonic-gate ebus_p = get_ebus_soft_state(getminor(*devp)); 9727c478bd9Sstevel@tonic-gate if (ebus_p == NULL) 9737c478bd9Sstevel@tonic-gate return (ENXIO); 9747c478bd9Sstevel@tonic-gate 9757c478bd9Sstevel@tonic-gate /* 9767c478bd9Sstevel@tonic-gate * Handle the open by tracking the device state. 9777c478bd9Sstevel@tonic-gate */ 9787c478bd9Sstevel@tonic-gate mutex_enter(&ebus_p->ebus_mutex); 9797c478bd9Sstevel@tonic-gate if (flags & FEXCL) { 9807c478bd9Sstevel@tonic-gate if (ebus_p->ebus_soft_state != EBUS_SOFT_STATE_CLOSED) { 9817c478bd9Sstevel@tonic-gate mutex_exit(&ebus_p->ebus_mutex); 9827c478bd9Sstevel@tonic-gate return (EBUSY); 9837c478bd9Sstevel@tonic-gate } 9847c478bd9Sstevel@tonic-gate ebus_p->ebus_soft_state = EBUS_SOFT_STATE_OPEN_EXCL; 9857c478bd9Sstevel@tonic-gate } else { 9867c478bd9Sstevel@tonic-gate if (ebus_p->ebus_soft_state == EBUS_SOFT_STATE_OPEN_EXCL) { 9877c478bd9Sstevel@tonic-gate mutex_exit(&ebus_p->ebus_mutex); 9887c478bd9Sstevel@tonic-gate return (EBUSY); 9897c478bd9Sstevel@tonic-gate } 9907c478bd9Sstevel@tonic-gate ebus_p->ebus_soft_state = EBUS_SOFT_STATE_OPEN; 9917c478bd9Sstevel@tonic-gate } 9927c478bd9Sstevel@tonic-gate mutex_exit(&ebus_p->ebus_mutex); 9937c478bd9Sstevel@tonic-gate return (0); 9947c478bd9Sstevel@tonic-gate } 9957c478bd9Sstevel@tonic-gate 9967c478bd9Sstevel@tonic-gate 9977c478bd9Sstevel@tonic-gate /* ARGSUSED */ 9987c478bd9Sstevel@tonic-gate static int 9997c478bd9Sstevel@tonic-gate ebus_close(dev_t dev, int flags, int otyp, cred_t *credp) 10007c478bd9Sstevel@tonic-gate { 10017c478bd9Sstevel@tonic-gate ebus_devstate_t *ebus_p; 10027c478bd9Sstevel@tonic-gate 10037c478bd9Sstevel@tonic-gate if (otyp != OTYP_CHR) 10047c478bd9Sstevel@tonic-gate return (EINVAL); 10057c478bd9Sstevel@tonic-gate 10067c478bd9Sstevel@tonic-gate ebus_p = get_ebus_soft_state(getminor(dev)); 10077c478bd9Sstevel@tonic-gate if (ebus_p == NULL) 10087c478bd9Sstevel@tonic-gate return (ENXIO); 10097c478bd9Sstevel@tonic-gate 10107c478bd9Sstevel@tonic-gate mutex_enter(&ebus_p->ebus_mutex); 10117c478bd9Sstevel@tonic-gate ebus_p->ebus_soft_state = EBUS_SOFT_STATE_CLOSED; 10127c478bd9Sstevel@tonic-gate mutex_exit(&ebus_p->ebus_mutex); 10137c478bd9Sstevel@tonic-gate return (0); 10147c478bd9Sstevel@tonic-gate } 10157c478bd9Sstevel@tonic-gate 10167c478bd9Sstevel@tonic-gate 10177c478bd9Sstevel@tonic-gate /* 10187c478bd9Sstevel@tonic-gate * ebus_ioctl: devctl hotplug controls 10197c478bd9Sstevel@tonic-gate */ 10207c478bd9Sstevel@tonic-gate /* ARGSUSED */ 10217c478bd9Sstevel@tonic-gate static int 10227c478bd9Sstevel@tonic-gate ebus_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, 10237c478bd9Sstevel@tonic-gate int *rvalp) 10247c478bd9Sstevel@tonic-gate { 10257c478bd9Sstevel@tonic-gate ebus_devstate_t *ebus_p; 10267c478bd9Sstevel@tonic-gate dev_info_t *self; 10277c478bd9Sstevel@tonic-gate struct devctl_iocdata *dcp; 10287c478bd9Sstevel@tonic-gate uint_t bus_state; 10297c478bd9Sstevel@tonic-gate int rv = 0; 10307c478bd9Sstevel@tonic-gate 10317c478bd9Sstevel@tonic-gate ebus_p = get_ebus_soft_state(getminor(dev)); 10327c478bd9Sstevel@tonic-gate if (ebus_p == NULL) 10337c478bd9Sstevel@tonic-gate return (ENXIO); 10347c478bd9Sstevel@tonic-gate 10357c478bd9Sstevel@tonic-gate self = ebus_p->dip; 10367c478bd9Sstevel@tonic-gate 10377c478bd9Sstevel@tonic-gate /* 10387c478bd9Sstevel@tonic-gate * We can use the generic implementation for these ioctls 10397c478bd9Sstevel@tonic-gate */ 10407c478bd9Sstevel@tonic-gate switch (cmd) { 10417c478bd9Sstevel@tonic-gate case DEVCTL_DEVICE_GETSTATE: 10427c478bd9Sstevel@tonic-gate case DEVCTL_DEVICE_ONLINE: 10437c478bd9Sstevel@tonic-gate case DEVCTL_DEVICE_OFFLINE: 10447c478bd9Sstevel@tonic-gate case DEVCTL_BUS_GETSTATE: 10457c478bd9Sstevel@tonic-gate return (ndi_devctl_ioctl(self, cmd, arg, mode, 0)); 10467c478bd9Sstevel@tonic-gate } 10477c478bd9Sstevel@tonic-gate 10487c478bd9Sstevel@tonic-gate /* 10497c478bd9Sstevel@tonic-gate * read devctl ioctl data 10507c478bd9Sstevel@tonic-gate */ 10517c478bd9Sstevel@tonic-gate if (ndi_dc_allochdl((void *)arg, &dcp) != NDI_SUCCESS) 10527c478bd9Sstevel@tonic-gate return (EFAULT); 10537c478bd9Sstevel@tonic-gate 10547c478bd9Sstevel@tonic-gate switch (cmd) { 10557c478bd9Sstevel@tonic-gate 10567c478bd9Sstevel@tonic-gate case DEVCTL_DEVICE_RESET: 10577c478bd9Sstevel@tonic-gate rv = ENOTSUP; 10587c478bd9Sstevel@tonic-gate break; 10597c478bd9Sstevel@tonic-gate 10607c478bd9Sstevel@tonic-gate case DEVCTL_BUS_QUIESCE: 10617c478bd9Sstevel@tonic-gate if (ndi_get_bus_state(self, &bus_state) == NDI_SUCCESS) 10627c478bd9Sstevel@tonic-gate if (bus_state == BUS_QUIESCED) 10637c478bd9Sstevel@tonic-gate break; 10647c478bd9Sstevel@tonic-gate (void) ndi_set_bus_state(self, BUS_QUIESCED); 10657c478bd9Sstevel@tonic-gate break; 10667c478bd9Sstevel@tonic-gate 10677c478bd9Sstevel@tonic-gate case DEVCTL_BUS_UNQUIESCE: 10687c478bd9Sstevel@tonic-gate if (ndi_get_bus_state(self, &bus_state) == NDI_SUCCESS) 10697c478bd9Sstevel@tonic-gate if (bus_state == BUS_ACTIVE) 10707c478bd9Sstevel@tonic-gate break; 10717c478bd9Sstevel@tonic-gate (void) ndi_set_bus_state(self, BUS_ACTIVE); 10727c478bd9Sstevel@tonic-gate break; 10737c478bd9Sstevel@tonic-gate 10747c478bd9Sstevel@tonic-gate case DEVCTL_BUS_RESET: 10757c478bd9Sstevel@tonic-gate rv = ENOTSUP; 10767c478bd9Sstevel@tonic-gate break; 10777c478bd9Sstevel@tonic-gate 10787c478bd9Sstevel@tonic-gate case DEVCTL_BUS_RESETALL: 10797c478bd9Sstevel@tonic-gate rv = ENOTSUP; 10807c478bd9Sstevel@tonic-gate break; 10817c478bd9Sstevel@tonic-gate 10827c478bd9Sstevel@tonic-gate default: 10837c478bd9Sstevel@tonic-gate rv = ENOTTY; 10847c478bd9Sstevel@tonic-gate } 10857c478bd9Sstevel@tonic-gate 10867c478bd9Sstevel@tonic-gate ndi_dc_freehdl(dcp); 10877c478bd9Sstevel@tonic-gate return (rv); 10887c478bd9Sstevel@tonic-gate } 1089