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 52155Scth * Common Development and Distribution License (the "License"). 62155Scth * 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 /* 228639SVikram.Hegde@Sun.COM * Copyright 2009 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 * pseudo bus nexus driver 280Sstevel@tonic-gate * hotplug framework test facility 290Sstevel@tonic-gate */ 300Sstevel@tonic-gate 310Sstevel@tonic-gate /* 320Sstevel@tonic-gate * The pshot driver can be used to exercise the i/o framework together 330Sstevel@tonic-gate * with devfs by configuring an arbitrarily complex device tree. 340Sstevel@tonic-gate * 350Sstevel@tonic-gate * The pshot driver is rooted at /devices/pshot. The following commands 360Sstevel@tonic-gate * illustrate the operation of devfs together with pshot's bus_config. 370Sstevel@tonic-gate * The first command demonstrates that, like the magician showing there's 380Sstevel@tonic-gate * nothing up his sleeve, /devices/pshot is empty. The second command 390Sstevel@tonic-gate * conjures up a branch of pshot nodes. Note that pshot's bus_config is 400Sstevel@tonic-gate * called sequentially by devfs for each node, as part of the pathname 410Sstevel@tonic-gate * resolution, and that each pshot node is fully configured and 420Sstevel@tonic-gate * attached before that node's bus_config is called to configure the 430Sstevel@tonic-gate * next child down the tree. The final result is a "disk" node configured 440Sstevel@tonic-gate * at the bottom of the named hierarchy of pshot nodes. 450Sstevel@tonic-gate * 460Sstevel@tonic-gate * # 470Sstevel@tonic-gate * # ls /devices/pshot 480Sstevel@tonic-gate * # 490Sstevel@tonic-gate * # ls -ld /devices/pshot/pshot@0/pshot@1/pshot@2/disk@3,0 500Sstevel@tonic-gate * drwxr-xr-x 2 root sys 512 Feb 6 15:10 510Sstevel@tonic-gate * /devices/pshot/pshot@0/pshot@1/pshot@2/disk@3,0 520Sstevel@tonic-gate * 530Sstevel@tonic-gate * pshot supports some unique behaviors as aids for test error cases. 540Sstevel@tonic-gate * 550Sstevel@tonic-gate * Match these special address formats to behavior: 560Sstevel@tonic-gate * 570Sstevel@tonic-gate * err.* - induce bus_config error 580Sstevel@tonic-gate * delay - induce 1 second of bus_config delay time 590Sstevel@tonic-gate * delay,n - induce n seconds of bus_config delay time 600Sstevel@tonic-gate * wait - induce 1 second of bus_config wait time 610Sstevel@tonic-gate * wait,n - induce n seconds of bus_config wait time 620Sstevel@tonic-gate * failinit.* - induce error at INITCHILD 630Sstevel@tonic-gate * failprobe.* - induce error at probe 640Sstevel@tonic-gate * failattach.* - induce error at attach 650Sstevel@tonic-gate */ 660Sstevel@tonic-gate 670Sstevel@tonic-gate #if defined(lint) && !defined(DEBUG) 680Sstevel@tonic-gate #define DEBUG 1 690Sstevel@tonic-gate #endif 700Sstevel@tonic-gate 710Sstevel@tonic-gate #include <sys/types.h> 720Sstevel@tonic-gate #include <sys/cmn_err.h> 730Sstevel@tonic-gate #include <sys/conf.h> 740Sstevel@tonic-gate #include <sys/ddi_impldefs.h> 750Sstevel@tonic-gate #include <sys/autoconf.h> 760Sstevel@tonic-gate #include <sys/open.h> 770Sstevel@tonic-gate #include <sys/stat.h> 780Sstevel@tonic-gate #include <sys/file.h> 790Sstevel@tonic-gate #include <sys/errno.h> 800Sstevel@tonic-gate #include <sys/systm.h> 810Sstevel@tonic-gate #include <sys/modctl.h> 820Sstevel@tonic-gate #include <sys/kmem.h> 830Sstevel@tonic-gate #include <sys/ddi.h> 840Sstevel@tonic-gate #include <sys/sunddi.h> 850Sstevel@tonic-gate #include <sys/sunndi.h> 860Sstevel@tonic-gate #include <sys/devctl.h> 870Sstevel@tonic-gate #include <sys/disp.h> 880Sstevel@tonic-gate #include <sys/utsname.h> 890Sstevel@tonic-gate #include <sys/pshot.h> 900Sstevel@tonic-gate #include <sys/debug.h> 910Sstevel@tonic-gate 920Sstevel@tonic-gate static int pshot_log = 0; 930Sstevel@tonic-gate static int pshot_devctl_debug = 0; 940Sstevel@tonic-gate static int pshot_debug_busy = 0; 950Sstevel@tonic-gate 960Sstevel@tonic-gate static void *pshot_softstatep; 970Sstevel@tonic-gate 980Sstevel@tonic-gate static int pshot_prop_autoattach; 990Sstevel@tonic-gate 1000Sstevel@tonic-gate #define MAXPWR 3 1010Sstevel@tonic-gate 1020Sstevel@tonic-gate 1030Sstevel@tonic-gate /* 1040Sstevel@tonic-gate * device configuration data 1050Sstevel@tonic-gate */ 1060Sstevel@tonic-gate 1070Sstevel@tonic-gate /* should keep in sync with current release */ 1080Sstevel@tonic-gate static struct { 1090Sstevel@tonic-gate char *name; 1100Sstevel@tonic-gate char *val; 1110Sstevel@tonic-gate } pshot_nodetypes[] = { 1120Sstevel@tonic-gate {"DDI_NT_SERIAL", DDI_NT_SERIAL}, 1130Sstevel@tonic-gate {"DDI_NT_SERIAL_MB", DDI_NT_SERIAL_MB}, 1140Sstevel@tonic-gate {"DDI_NT_SERIAL_DO", DDI_NT_SERIAL_DO}, 1150Sstevel@tonic-gate {"DDI_NT_SERIAL_MB_DO", DDI_NT_SERIAL_MB_DO}, 1160Sstevel@tonic-gate {"DDI_NT_SERIAL_LOMCON", DDI_NT_SERIAL_LOMCON}, 1170Sstevel@tonic-gate {"DDI_NT_BLOCK", DDI_NT_BLOCK}, 1180Sstevel@tonic-gate {"DDI_NT_BLOCK_CHAN", DDI_NT_BLOCK_CHAN}, 1190Sstevel@tonic-gate {"DDI_NT_BLOCK_WWN", DDI_NT_BLOCK_WWN}, 120*9249SJaven.Wu@Sun.COM {"DDI_NT_BLOCK_SAS", DDI_NT_BLOCK_SAS}, 1210Sstevel@tonic-gate {"DDI_NT_CD", DDI_NT_CD}, 1220Sstevel@tonic-gate {"DDI_NT_CD_CHAN", DDI_NT_CD_CHAN}, 1230Sstevel@tonic-gate {"DDI_NT_FD", DDI_NT_FD}, 1240Sstevel@tonic-gate {"DDI_NT_ENCLOSURE", DDI_NT_ENCLOSURE}, 1250Sstevel@tonic-gate {"DDI_NT_SCSI_ENCLOSURE", DDI_NT_SCSI_ENCLOSURE}, 1260Sstevel@tonic-gate {"DDI_NT_TAPE", DDI_NT_TAPE}, 1270Sstevel@tonic-gate {"DDI_NT_NET", DDI_NT_NET}, 1280Sstevel@tonic-gate {"DDI_NT_DISPLAY", DDI_NT_DISPLAY}, 1290Sstevel@tonic-gate {"DDI_PSEUDO", DDI_PSEUDO}, 1300Sstevel@tonic-gate {"DDI_NT_AUDIO", DDI_NT_AUDIO}, 1310Sstevel@tonic-gate {"DDI_NT_MOUSE", DDI_NT_MOUSE}, 1320Sstevel@tonic-gate {"DDI_NT_KEYBOARD", DDI_NT_KEYBOARD}, 1330Sstevel@tonic-gate {"DDI_NT_PARALLEL", DDI_NT_PARALLEL}, 1340Sstevel@tonic-gate {"DDI_NT_PRINTER", DDI_NT_PRINTER}, 1350Sstevel@tonic-gate {"DDI_NT_UGEN", DDI_NT_UGEN}, 1360Sstevel@tonic-gate {"DDI_NT_NEXUS", DDI_NT_NEXUS}, 1370Sstevel@tonic-gate {"DDI_NT_SCSI_NEXUS", DDI_NT_SCSI_NEXUS}, 1380Sstevel@tonic-gate {"DDI_NT_ATTACHMENT_POINT", DDI_NT_ATTACHMENT_POINT}, 1390Sstevel@tonic-gate {"DDI_NT_SCSI_ATTACHMENT_POINT", DDI_NT_SCSI_ATTACHMENT_POINT}, 1400Sstevel@tonic-gate {"DDI_NT_PCI_ATTACHMENT_POINT", DDI_NT_PCI_ATTACHMENT_POINT}, 1410Sstevel@tonic-gate {"DDI_NT_SBD_ATTACHMENT_POINT", DDI_NT_SBD_ATTACHMENT_POINT}, 1420Sstevel@tonic-gate {"DDI_NT_FC_ATTACHMENT_POINT", DDI_NT_FC_ATTACHMENT_POINT}, 1430Sstevel@tonic-gate {"DDI_NT_USB_ATTACHMENT_POINT", DDI_NT_USB_ATTACHMENT_POINT}, 1440Sstevel@tonic-gate {"DDI_NT_BLOCK_FABRIC", DDI_NT_BLOCK_FABRIC}, 1450Sstevel@tonic-gate {"DDI_NT_SMARTCARD_READER", DDI_NT_SMARTCARD_READER}, 1460Sstevel@tonic-gate {"DDI_NT_AV_ASYNC", DDI_NT_AV_ASYNC}, 1470Sstevel@tonic-gate {"DDI_NT_AV_ISOCH", DDI_NT_AV_ISOCH}, 1480Sstevel@tonic-gate { NULL, NULL } 1490Sstevel@tonic-gate }; 1500Sstevel@tonic-gate 1510Sstevel@tonic-gate /* Node name */ 1520Sstevel@tonic-gate static char *pshot_compat_diskname = "cdisk"; 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate /* Compatible names... */ 1550Sstevel@tonic-gate static char *pshot_compat_psramdisks[] = { 1560Sstevel@tonic-gate "psramhead", 1570Sstevel@tonic-gate "psramrom", 1580Sstevel@tonic-gate "psramdisk", 1590Sstevel@tonic-gate "psramd", 1600Sstevel@tonic-gate "psramwhat" 1610Sstevel@tonic-gate }; 1620Sstevel@tonic-gate 1630Sstevel@tonic-gate /* 1640Sstevel@tonic-gate * devices "natively" supported by pshot (i.e. included with SUNWiotu) 1650Sstevel@tonic-gate * used to initialize pshot_devices with 1660Sstevel@tonic-gate */ 1670Sstevel@tonic-gate static pshot_device_t pshot_stock_devices[] = { 1680Sstevel@tonic-gate {"disk", DDI_NT_BLOCK, "gen_drv"}, 1690Sstevel@tonic-gate {"disk_chan", DDI_NT_BLOCK_CHAN, "gen_drv"}, 1700Sstevel@tonic-gate {"disk_wwn", DDI_NT_BLOCK_WWN, "gen_drv"}, 1710Sstevel@tonic-gate {"disk_cdrom", DDI_NT_CD, "gen_drv"}, 1720Sstevel@tonic-gate {"disk_cdrom.chan", DDI_NT_CD_CHAN, "gen_drv"}, 1730Sstevel@tonic-gate /* Note: use bad_drv to force attach errors */ 1740Sstevel@tonic-gate {"disk_fd", DDI_NT_FD, "bad_drv"}, 1750Sstevel@tonic-gate {"tape", DDI_NT_TAPE, "gen_drv"}, 1760Sstevel@tonic-gate {"net", DDI_NT_NET, "gen_drv"}, 1770Sstevel@tonic-gate {"display", DDI_NT_DISPLAY, "gen_drv"}, 1780Sstevel@tonic-gate {"pseudo", DDI_PSEUDO, "gen_drv"}, 1790Sstevel@tonic-gate {"audio", DDI_NT_AUDIO, "gen_drv"}, 1800Sstevel@tonic-gate {"mouse", DDI_NT_MOUSE, "gen_drv"}, 1810Sstevel@tonic-gate {"keyboard", DDI_NT_KEYBOARD, "gen_drv"}, 1820Sstevel@tonic-gate {"nexus", DDI_NT_NEXUS, "pshot"} 1830Sstevel@tonic-gate }; 1840Sstevel@tonic-gate #define PSHOT_N_STOCK_DEVICES \ 1850Sstevel@tonic-gate (sizeof (pshot_stock_devices) / sizeof (pshot_device_t)) 1860Sstevel@tonic-gate 1870Sstevel@tonic-gate static pshot_device_t *pshot_devices = NULL; 1880Sstevel@tonic-gate static size_t pshot_devices_len = 0; 1890Sstevel@tonic-gate 1900Sstevel@tonic-gate /* protects <pshot_devices>, <pshot_devices_len> */ 1910Sstevel@tonic-gate static kmutex_t pshot_devices_lock; 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate 1940Sstevel@tonic-gate /* 1950Sstevel@tonic-gate * event testing 1960Sstevel@tonic-gate */ 1970Sstevel@tonic-gate 1980Sstevel@tonic-gate static ndi_event_definition_t pshot_ndi_event_defs[] = { 1990Sstevel@tonic-gate { PSHOT_EVENT_TAG_OFFLINE, PSHOT_EVENT_NAME_DEV_OFFLINE, 2000Sstevel@tonic-gate EPL_INTERRUPT, NDI_EVENT_POST_TO_ALL }, 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate { PSHOT_EVENT_TAG_DEV_RESET, PSHOT_EVENT_NAME_DEV_RESET, 2030Sstevel@tonic-gate EPL_INTERRUPT, NDI_EVENT_POST_TO_TGT }, 2040Sstevel@tonic-gate 2050Sstevel@tonic-gate { PSHOT_EVENT_TAG_BUS_RESET, PSHOT_EVENT_NAME_BUS_RESET, 2060Sstevel@tonic-gate EPL_INTERRUPT, NDI_EVENT_POST_TO_ALL }, 2070Sstevel@tonic-gate 2080Sstevel@tonic-gate { PSHOT_EVENT_TAG_BUS_QUIESCE, PSHOT_EVENT_NAME_BUS_QUIESCE, 2090Sstevel@tonic-gate EPL_INTERRUPT, NDI_EVENT_POST_TO_ALL }, 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate { PSHOT_EVENT_TAG_BUS_UNQUIESCE, PSHOT_EVENT_NAME_BUS_UNQUIESCE, 2120Sstevel@tonic-gate EPL_INTERRUPT, NDI_EVENT_POST_TO_ALL }, 2130Sstevel@tonic-gate 2140Sstevel@tonic-gate { PSHOT_EVENT_TAG_TEST_POST, PSHOT_EVENT_NAME_BUS_TEST_POST, 2150Sstevel@tonic-gate EPL_INTERRUPT, NDI_EVENT_POST_TO_TGT } 2160Sstevel@tonic-gate }; 2170Sstevel@tonic-gate 2180Sstevel@tonic-gate 2190Sstevel@tonic-gate #define PSHOT_N_NDI_EVENTS \ 2200Sstevel@tonic-gate (sizeof (pshot_ndi_event_defs) / sizeof (ndi_event_definition_t)) 2210Sstevel@tonic-gate 2220Sstevel@tonic-gate #ifdef DEBUG 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate static ndi_event_definition_t pshot_test_events[] = { 2250Sstevel@tonic-gate { 10, "test event 0", EPL_INTERRUPT, NDI_EVENT_POST_TO_ALL }, 2260Sstevel@tonic-gate { 11, "test event 1", EPL_KERNEL, NDI_EVENT_POST_TO_TGT }, 2270Sstevel@tonic-gate { 12, "test event 2", EPL_INTERRUPT, NDI_EVENT_POST_TO_TGT }, 2280Sstevel@tonic-gate { 13, "test event 3", EPL_INTERRUPT, NDI_EVENT_POST_TO_ALL }, 2290Sstevel@tonic-gate { 14, "test event 4", EPL_KERNEL, NDI_EVENT_POST_TO_ALL}, 2300Sstevel@tonic-gate { 15, "test event 5", EPL_INTERRUPT, NDI_EVENT_POST_TO_ALL }, 2310Sstevel@tonic-gate { 16, "test event 6", EPL_KERNEL, NDI_EVENT_POST_TO_ALL }, 2320Sstevel@tonic-gate { 17, "test event 7", EPL_INTERRUPT, NDI_EVENT_POST_TO_ALL } 2330Sstevel@tonic-gate }; 2340Sstevel@tonic-gate 2350Sstevel@tonic-gate static ndi_event_definition_t pshot_test_events_high[] = { 2360Sstevel@tonic-gate { 20, "test event high 0", EPL_HIGHLEVEL, NDI_EVENT_POST_TO_ALL} 2370Sstevel@tonic-gate }; 2380Sstevel@tonic-gate 2390Sstevel@tonic-gate #define PSHOT_N_TEST_EVENTS \ 2400Sstevel@tonic-gate (sizeof (pshot_test_events)/sizeof (ndi_event_definition_t)) 2410Sstevel@tonic-gate #endif 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate struct register_events { 2440Sstevel@tonic-gate char *event_name; 2450Sstevel@tonic-gate ddi_eventcookie_t event_cookie; 2460Sstevel@tonic-gate void (*event_callback) 2470Sstevel@tonic-gate (dev_info_t *, 2480Sstevel@tonic-gate ddi_eventcookie_t, 2490Sstevel@tonic-gate void *arg, 2500Sstevel@tonic-gate void *impldata); 2510Sstevel@tonic-gate ddi_callback_id_t cb_id; 2520Sstevel@tonic-gate }; 2530Sstevel@tonic-gate 2540Sstevel@tonic-gate struct register_events pshot_register_events[] = { 2550Sstevel@tonic-gate { PSHOT_EVENT_NAME_DEV_OFFLINE, 0, pshot_event_cb, 0 }, 2560Sstevel@tonic-gate { PSHOT_EVENT_NAME_DEV_RESET, 0, pshot_event_cb, 0 }, 2570Sstevel@tonic-gate { PSHOT_EVENT_NAME_BUS_RESET, 0, pshot_event_cb, 0 }, 2580Sstevel@tonic-gate { PSHOT_EVENT_NAME_BUS_QUIESCE, 0, pshot_event_cb, 0 }, 2590Sstevel@tonic-gate { PSHOT_EVENT_NAME_BUS_UNQUIESCE, 0, pshot_event_cb, 0 }, 2600Sstevel@tonic-gate { PSHOT_EVENT_NAME_BUS_TEST_POST, 0, pshot_event_cb, 0 } 2610Sstevel@tonic-gate }; 2620Sstevel@tonic-gate 2630Sstevel@tonic-gate #define PSHOT_N_DDI_EVENTS \ 2640Sstevel@tonic-gate (sizeof (pshot_register_events) / sizeof (struct register_events)) 2650Sstevel@tonic-gate 2660Sstevel@tonic-gate 2670Sstevel@tonic-gate #ifdef DEBUG 2680Sstevel@tonic-gate 2690Sstevel@tonic-gate static struct register_events pshot_register_test[] = { 2700Sstevel@tonic-gate { "test event 0", 0, pshot_event_cb_test, 0}, 2710Sstevel@tonic-gate { "test event 1", 0, pshot_event_cb_test, 0}, 2720Sstevel@tonic-gate { "test event 2", 0, pshot_event_cb_test, 0}, 2730Sstevel@tonic-gate { "test event 3", 0, pshot_event_cb_test, 0}, 2740Sstevel@tonic-gate { "test event 4", 0, pshot_event_cb_test, 0}, 2750Sstevel@tonic-gate { "test event 5", 0, pshot_event_cb_test, 0}, 2760Sstevel@tonic-gate { "test event 6", 0, pshot_event_cb_test, 0}, 2770Sstevel@tonic-gate { "test event 7", 0, pshot_event_cb_test, 0} 2780Sstevel@tonic-gate }; 2790Sstevel@tonic-gate 2800Sstevel@tonic-gate 2810Sstevel@tonic-gate static struct register_events pshot_register_high_test[] = { 2820Sstevel@tonic-gate {"test event high 0", 0, pshot_event_cb_test, 0} 2830Sstevel@tonic-gate }; 2840Sstevel@tonic-gate 2850Sstevel@tonic-gate #endif /* DEBUG */ 2860Sstevel@tonic-gate 2870Sstevel@tonic-gate static struct { 2880Sstevel@tonic-gate int ioctl_int; 2890Sstevel@tonic-gate char *ioctl_char; 2900Sstevel@tonic-gate } pshot_devctls[] = { 2910Sstevel@tonic-gate {DEVCTL_DEVICE_GETSTATE, "DEVCTL_DEVICE_GETSTATE"}, 2920Sstevel@tonic-gate {DEVCTL_DEVICE_ONLINE, "DEVCTL_DEVICE_ONLINE"}, 2930Sstevel@tonic-gate {DEVCTL_DEVICE_OFFLINE, "DEVCTL_DEVICE_OFFLINE"}, 2940Sstevel@tonic-gate {DEVCTL_DEVICE_REMOVE, "DEVCTL_DEVICE_REMOVE"}, 2950Sstevel@tonic-gate {DEVCTL_BUS_GETSTATE, "DEVCTL_BUS_GETSTATE"}, 2960Sstevel@tonic-gate {DEVCTL_BUS_DEV_CREATE, "DEVCTL_BUS_DEV_CREATE"}, 2970Sstevel@tonic-gate {DEVCTL_BUS_RESET, "DEVCTL_BUS_RESET"}, 2980Sstevel@tonic-gate {DEVCTL_BUS_RESETALL, "DEVCTL_BUS_RESETALL"}, 2990Sstevel@tonic-gate {0, NULL} 3000Sstevel@tonic-gate }; 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate static struct bus_ops pshot_bus_ops = { 3030Sstevel@tonic-gate BUSO_REV, /* busops_rev */ 3040Sstevel@tonic-gate nullbusmap, /* bus_map */ 3050Sstevel@tonic-gate NULL, /* bus_get_intrspec */ 3060Sstevel@tonic-gate NULL, /* bus_add_interspec */ 3070Sstevel@tonic-gate NULL, /* bus_remove_interspec */ 3080Sstevel@tonic-gate i_ddi_map_fault, /* bus_map_fault */ 30985Scth ddi_dma_map, /* bus_dma_map */ 31085Scth ddi_dma_allochdl, /* bus_dma_allochdl */ 31185Scth ddi_dma_freehdl, /* bus_dma_freehdl */ 31285Scth ddi_dma_bindhdl, /* bus_dma_bindhdl */ 31385Scth ddi_dma_unbindhdl, /* bus_dma_unbindhdl */ 31485Scth ddi_dma_flush, /* bus_dma_flush */ 31585Scth ddi_dma_win, /* bus_dma_win */ 31685Scth ddi_dma_mctl, /* bus_dma_ctl */ 3170Sstevel@tonic-gate pshot_ctl, /* bus_ctl */ 3180Sstevel@tonic-gate ddi_bus_prop_op, /* bus_prop_op */ 3190Sstevel@tonic-gate pshot_get_eventcookie, /* bus_get_eventcookie */ 3200Sstevel@tonic-gate pshot_add_eventcall, /* bus_add_eventcall */ 3210Sstevel@tonic-gate pshot_remove_eventcall, /* bus_remove_event */ 3220Sstevel@tonic-gate pshot_post_event, /* bus_post_event */ 3230Sstevel@tonic-gate NULL, /* bus_intr_ctl */ 3240Sstevel@tonic-gate pshot_bus_config, /* bus_config */ 3250Sstevel@tonic-gate pshot_bus_unconfig, /* bus_unconfig */ 3260Sstevel@tonic-gate NULL, /* bus_fm_init */ 3270Sstevel@tonic-gate NULL, /* bus_fm_fini */ 3280Sstevel@tonic-gate NULL, /* bus_fm_access_enter */ 3290Sstevel@tonic-gate NULL, /* bus_fm_access_exit */ 3300Sstevel@tonic-gate pshot_bus_power, /* bus_power */ 3310Sstevel@tonic-gate pshot_bus_introp /* bus_intr_op */ 3320Sstevel@tonic-gate }; 3330Sstevel@tonic-gate 3340Sstevel@tonic-gate static struct cb_ops pshot_cb_ops = { 3350Sstevel@tonic-gate pshot_open, /* open */ 3360Sstevel@tonic-gate pshot_close, /* close */ 3370Sstevel@tonic-gate nodev, /* strategy */ 3380Sstevel@tonic-gate nodev, /* print */ 3390Sstevel@tonic-gate nodev, /* dump */ 3400Sstevel@tonic-gate nodev, /* read */ 3410Sstevel@tonic-gate nodev, /* write */ 3420Sstevel@tonic-gate pshot_ioctl, /* ioctl */ 3430Sstevel@tonic-gate nodev, /* devmap */ 3440Sstevel@tonic-gate nodev, /* mmap */ 3450Sstevel@tonic-gate nodev, /* segmap */ 3460Sstevel@tonic-gate nochpoll, /* poll */ 3470Sstevel@tonic-gate ddi_prop_op, /* prop_op */ 3480Sstevel@tonic-gate NULL, /* streamtab */ 3490Sstevel@tonic-gate D_NEW | D_MP | D_HOTPLUG, /* flags */ 3500Sstevel@tonic-gate CB_REV, /* cb_rev */ 3510Sstevel@tonic-gate nodev, /* aread */ 3520Sstevel@tonic-gate nodev, /* awrite */ 3530Sstevel@tonic-gate }; 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate static struct dev_ops pshot_ops = { 3560Sstevel@tonic-gate DEVO_REV, /* devo_rev, */ 3570Sstevel@tonic-gate 0, /* refcnt */ 3580Sstevel@tonic-gate pshot_info, /* getinfo */ 3590Sstevel@tonic-gate nulldev, /* identify */ 3600Sstevel@tonic-gate pshot_probe, /* probe */ 3610Sstevel@tonic-gate pshot_attach, /* attach */ 3620Sstevel@tonic-gate pshot_detach, /* detach */ 3630Sstevel@tonic-gate nodev, /* reset */ 3640Sstevel@tonic-gate &pshot_cb_ops, /* driver operations */ 3650Sstevel@tonic-gate &pshot_bus_ops, /* bus operations */ 3667656SSherry.Moore@Sun.COM pshot_power, /* power */ 3677656SSherry.Moore@Sun.COM ddi_quiesce_not_supported, /* devo_quiesce */ 3680Sstevel@tonic-gate 3690Sstevel@tonic-gate }; 3700Sstevel@tonic-gate 3710Sstevel@tonic-gate 3720Sstevel@tonic-gate /* 3730Sstevel@tonic-gate * Module linkage information for the kernel. 3740Sstevel@tonic-gate */ 3750Sstevel@tonic-gate static struct modldrv modldrv = { 3760Sstevel@tonic-gate &mod_driverops, 3777656SSherry.Moore@Sun.COM "pshotnex", 3780Sstevel@tonic-gate &pshot_ops, 3790Sstevel@tonic-gate }; 3800Sstevel@tonic-gate 3810Sstevel@tonic-gate static struct modlinkage modlinkage = { 3820Sstevel@tonic-gate MODREV_1, &modldrv, NULL 3830Sstevel@tonic-gate }; 3840Sstevel@tonic-gate 3850Sstevel@tonic-gate 3860Sstevel@tonic-gate /* 3870Sstevel@tonic-gate * pshot_devices is set up on the first attach and destroyed on fini 3880Sstevel@tonic-gate * 3890Sstevel@tonic-gate * therefore PSHOT_PROP_DEV* properties may be set just for the root device, 3900Sstevel@tonic-gate * instead of being set globably, in pshot.conf by specifying the properties 3910Sstevel@tonic-gate * on a single line in the form: 3920Sstevel@tonic-gate * name="pshot" parent="/" <dev props ..> 3930Sstevel@tonic-gate * to unclutter a device tree snapshot. 3940Sstevel@tonic-gate * this of course produces a long single line that may wrap around several 3950Sstevel@tonic-gate * times on screen 3960Sstevel@tonic-gate */ 3970Sstevel@tonic-gate 3980Sstevel@tonic-gate int 3990Sstevel@tonic-gate _init(void) 4000Sstevel@tonic-gate { 4010Sstevel@tonic-gate int rv; 4020Sstevel@tonic-gate 4030Sstevel@tonic-gate rv = ddi_soft_state_init(&pshot_softstatep, sizeof (pshot_t), 0); 4040Sstevel@tonic-gate 4050Sstevel@tonic-gate if (rv != DDI_SUCCESS) 4060Sstevel@tonic-gate return (rv); 4070Sstevel@tonic-gate 4080Sstevel@tonic-gate mutex_init(&pshot_devices_lock, NULL, MUTEX_DRIVER, NULL); 4090Sstevel@tonic-gate pshot_devices = NULL; 4100Sstevel@tonic-gate pshot_devices_len = 0; 4110Sstevel@tonic-gate 4120Sstevel@tonic-gate if ((rv = mod_install(&modlinkage)) != 0) { 4130Sstevel@tonic-gate ddi_soft_state_fini(&pshot_softstatep); 4140Sstevel@tonic-gate mutex_destroy(&pshot_devices_lock); 4150Sstevel@tonic-gate } 4160Sstevel@tonic-gate return (rv); 4170Sstevel@tonic-gate } 4180Sstevel@tonic-gate 4190Sstevel@tonic-gate int 4200Sstevel@tonic-gate _fini(void) 4210Sstevel@tonic-gate { 4220Sstevel@tonic-gate int rv; 4230Sstevel@tonic-gate 4240Sstevel@tonic-gate if ((rv = mod_remove(&modlinkage)) != 0) 4250Sstevel@tonic-gate return (rv); 4260Sstevel@tonic-gate 4270Sstevel@tonic-gate ddi_soft_state_fini(&pshot_softstatep); 4280Sstevel@tonic-gate mutex_destroy(&pshot_devices_lock); 4290Sstevel@tonic-gate if (pshot_devices) 4300Sstevel@tonic-gate pshot_devices_free(pshot_devices, pshot_devices_len); 4310Sstevel@tonic-gate return (0); 4320Sstevel@tonic-gate } 4330Sstevel@tonic-gate 4340Sstevel@tonic-gate int 4350Sstevel@tonic-gate _info(struct modinfo *modinfop) 4360Sstevel@tonic-gate { 4370Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop)); 4380Sstevel@tonic-gate } 4390Sstevel@tonic-gate 4400Sstevel@tonic-gate 4410Sstevel@tonic-gate /*ARGSUSED*/ 4420Sstevel@tonic-gate static int 4430Sstevel@tonic-gate pshot_probe(dev_info_t *devi) 4440Sstevel@tonic-gate { 4450Sstevel@tonic-gate int instance = ddi_get_instance(devi); 4460Sstevel@tonic-gate char *bus_addr; 4470Sstevel@tonic-gate 4480Sstevel@tonic-gate /* 4490Sstevel@tonic-gate * Hook for tests to force probe fail 4500Sstevel@tonic-gate */ 4510Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, devi, 0, "bus-addr", 4520Sstevel@tonic-gate &bus_addr) == DDI_PROP_SUCCESS) { 4530Sstevel@tonic-gate if (strncmp(bus_addr, "failprobe", 9) == 0) { 4540Sstevel@tonic-gate if (pshot_debug) 4550Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: " 4560Sstevel@tonic-gate "%s forced probe failure\n", 4570Sstevel@tonic-gate instance, bus_addr); 4580Sstevel@tonic-gate ddi_prop_free(bus_addr); 4590Sstevel@tonic-gate return (DDI_PROBE_FAILURE); 4600Sstevel@tonic-gate } 4610Sstevel@tonic-gate ddi_prop_free(bus_addr); 4620Sstevel@tonic-gate } 4630Sstevel@tonic-gate 4640Sstevel@tonic-gate return (DDI_PROBE_SUCCESS); 4650Sstevel@tonic-gate } 4660Sstevel@tonic-gate 4670Sstevel@tonic-gate 4680Sstevel@tonic-gate /*ARGSUSED*/ 4690Sstevel@tonic-gate static int 4700Sstevel@tonic-gate pshot_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result) 4710Sstevel@tonic-gate { 4720Sstevel@tonic-gate int instance; 4730Sstevel@tonic-gate minor_t minor; 4740Sstevel@tonic-gate pshot_t *pshot; 4750Sstevel@tonic-gate 4760Sstevel@tonic-gate minor = getminor((dev_t)arg); 4770Sstevel@tonic-gate instance = pshot_minor_decode_inst(minor); 4780Sstevel@tonic-gate switch (infocmd) { 4790Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO: 4800Sstevel@tonic-gate pshot = ddi_get_soft_state(pshot_softstatep, instance); 4810Sstevel@tonic-gate if (pshot == NULL) { 4820Sstevel@tonic-gate cmn_err(CE_WARN, "pshot_info: get soft state failed " 4830Sstevel@tonic-gate "on minor %u, instance %d", minor, instance); 4840Sstevel@tonic-gate return (DDI_FAILURE); 4850Sstevel@tonic-gate } 4860Sstevel@tonic-gate *result = (void *)pshot->dip; 4870Sstevel@tonic-gate break; 4880Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE: 4890Sstevel@tonic-gate *result = (void *)(uintptr_t)instance; 4900Sstevel@tonic-gate break; 4910Sstevel@tonic-gate default: 4920Sstevel@tonic-gate cmn_err(CE_WARN, "pshot_info: unrecognized cmd 0x%x on " 4930Sstevel@tonic-gate "minor %u, instance %d", infocmd, minor, instance); 4940Sstevel@tonic-gate return (DDI_FAILURE); 4950Sstevel@tonic-gate } 4960Sstevel@tonic-gate 4970Sstevel@tonic-gate return (DDI_SUCCESS); 4980Sstevel@tonic-gate } 4990Sstevel@tonic-gate 5000Sstevel@tonic-gate 5010Sstevel@tonic-gate static int 5020Sstevel@tonic-gate pshot_attach(dev_info_t *devi, ddi_attach_cmd_t cmd) 5030Sstevel@tonic-gate { 5040Sstevel@tonic-gate int instance = ddi_get_instance(devi); 5050Sstevel@tonic-gate pshot_t *pshot; 5060Sstevel@tonic-gate int rval, i; 5070Sstevel@tonic-gate int prop_flags = DDI_PROP_DONTPASS | DDI_PROP_NOTPROM; 5080Sstevel@tonic-gate char *bus_addr; 5090Sstevel@tonic-gate char *pm_comp[] = { 5100Sstevel@tonic-gate "NAME=bus", 5110Sstevel@tonic-gate "0=B3", 5120Sstevel@tonic-gate "1=B2", 5130Sstevel@tonic-gate "2=B1", 5140Sstevel@tonic-gate "3=B0"}; 5150Sstevel@tonic-gate char *pm_hw_state = {"needs-suspend-resume"}; 5160Sstevel@tonic-gate 5170Sstevel@tonic-gate pshot_prop_autoattach = ddi_prop_get_int(DDI_DEV_T_ANY, devi, 5180Sstevel@tonic-gate prop_flags, "autoattach", 0); 5190Sstevel@tonic-gate 5200Sstevel@tonic-gate switch (cmd) { 5210Sstevel@tonic-gate 5220Sstevel@tonic-gate case DDI_ATTACH: 5230Sstevel@tonic-gate if (pshot_debug) 5240Sstevel@tonic-gate cmn_err(CE_CONT, "attach: %s%d/pshot%d\n", 5257656SSherry.Moore@Sun.COM ddi_get_name(ddi_get_parent(devi)), 5267656SSherry.Moore@Sun.COM ddi_get_instance(ddi_get_parent(devi)), 5277656SSherry.Moore@Sun.COM instance); 5280Sstevel@tonic-gate 5290Sstevel@tonic-gate /* 5300Sstevel@tonic-gate * Hook for tests to force attach fail 5310Sstevel@tonic-gate */ 5320Sstevel@tonic-gate if ((ddi_prop_lookup_string(DDI_DEV_T_ANY, devi, 0, "bus-addr", 5330Sstevel@tonic-gate &bus_addr) == DDI_PROP_SUCCESS) && bus_addr != NULL) { 5340Sstevel@tonic-gate if (strncmp(bus_addr, "failattach", 10) == 0) { 5350Sstevel@tonic-gate if (pshot_debug) 5360Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: " 5370Sstevel@tonic-gate "%s forced attach failure\n", 5380Sstevel@tonic-gate instance, bus_addr); 5390Sstevel@tonic-gate ddi_prop_free(bus_addr); 5400Sstevel@tonic-gate return (DDI_FAILURE); 5410Sstevel@tonic-gate } 5420Sstevel@tonic-gate ddi_prop_free(bus_addr); 5430Sstevel@tonic-gate } 5440Sstevel@tonic-gate 5450Sstevel@tonic-gate /* 5460Sstevel@tonic-gate * minor nodes setup 5470Sstevel@tonic-gate */ 5480Sstevel@tonic-gate if (ddi_soft_state_zalloc(pshot_softstatep, instance) != 5490Sstevel@tonic-gate DDI_SUCCESS) { 5500Sstevel@tonic-gate return (DDI_FAILURE); 5510Sstevel@tonic-gate } 5520Sstevel@tonic-gate pshot = ddi_get_soft_state(pshot_softstatep, instance); 5530Sstevel@tonic-gate pshot->dip = devi; 5540Sstevel@tonic-gate pshot->instance = instance; 5550Sstevel@tonic-gate mutex_init(&pshot->lock, NULL, MUTEX_DRIVER, NULL); 5560Sstevel@tonic-gate 5570Sstevel@tonic-gate /* set each minor, then create on dip all together */ 5580Sstevel@tonic-gate 5590Sstevel@tonic-gate i = PSHOT_NODENUM_DEVCTL; 5600Sstevel@tonic-gate pshot->nodes[i].pshot = pshot; 5610Sstevel@tonic-gate pshot->nodes[i].minor = pshot_minor_encode(instance, i); 5620Sstevel@tonic-gate (void) strncpy(pshot->nodes[i].name, PSHOT_NODENAME_DEVCTL, 5630Sstevel@tonic-gate PSHOT_MAX_MINOR_NAMELEN); 5640Sstevel@tonic-gate 5650Sstevel@tonic-gate i = PSHOT_NODENUM_TESTCTL; 5660Sstevel@tonic-gate pshot->nodes[i].pshot = pshot; 5670Sstevel@tonic-gate pshot->nodes[i].minor = pshot_minor_encode(instance, i); 5680Sstevel@tonic-gate (void) strncpy(pshot->nodes[i].name, PSHOT_NODENAME_TESTCTL, 5690Sstevel@tonic-gate PSHOT_MAX_MINOR_NAMELEN); 5700Sstevel@tonic-gate 5710Sstevel@tonic-gate /* this assumes contiguous a filling */ 5720Sstevel@tonic-gate for (i = 0; i <= PSHOT_MAX_NODENUM; i++) { 5730Sstevel@tonic-gate if (ddi_create_minor_node(devi, pshot->nodes[i].name, 5740Sstevel@tonic-gate S_IFCHR, pshot->nodes[i].minor, DDI_NT_NEXUS, 0) != 5750Sstevel@tonic-gate DDI_SUCCESS) { 5760Sstevel@tonic-gate cmn_err(CE_WARN, "attach: cannot create " 5770Sstevel@tonic-gate "minor %s", pshot->nodes[i].name); 5780Sstevel@tonic-gate goto FAIL_ATTACH; 5790Sstevel@tonic-gate } 5800Sstevel@tonic-gate } 5810Sstevel@tonic-gate 5820Sstevel@tonic-gate /* 5830Sstevel@tonic-gate * pshot_devices setup 5840Sstevel@tonic-gate */ 5850Sstevel@tonic-gate if (pshot_devices_setup(devi)) { 5860Sstevel@tonic-gate cmn_err(CE_WARN, "attach: pshot devices setup " 5870Sstevel@tonic-gate "failed"); 5880Sstevel@tonic-gate goto FAIL_ATTACH; 5890Sstevel@tonic-gate } 5900Sstevel@tonic-gate 5910Sstevel@tonic-gate /* 5920Sstevel@tonic-gate * events setup 5930Sstevel@tonic-gate */ 5940Sstevel@tonic-gate for (i = 0; i < PSHOT_N_DDI_EVENTS; i++) { 5950Sstevel@tonic-gate rval = ddi_get_eventcookie(devi, 5960Sstevel@tonic-gate pshot_register_events[i].event_name, 5970Sstevel@tonic-gate &pshot_register_events[i].event_cookie); 5980Sstevel@tonic-gate 5990Sstevel@tonic-gate if (pshot_debug) 6000Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: event=%s:" 6010Sstevel@tonic-gate "ddi_get_eventcookie rval=%d\n", 6020Sstevel@tonic-gate instance, 6030Sstevel@tonic-gate pshot_register_events[i].event_name, rval); 6040Sstevel@tonic-gate 6050Sstevel@tonic-gate if (rval == DDI_SUCCESS) { 6060Sstevel@tonic-gate rval = ddi_add_event_handler(devi, 6070Sstevel@tonic-gate pshot_register_events[i].event_cookie, 6080Sstevel@tonic-gate pshot_register_events[i].event_callback, 6090Sstevel@tonic-gate (void *)pshot, 6100Sstevel@tonic-gate &pshot->callback_cache[i]); 6110Sstevel@tonic-gate 6120Sstevel@tonic-gate if (pshot_debug) 6130Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: event=%s: " 6140Sstevel@tonic-gate "ddi_add_event_handler rval=%d\n", 6150Sstevel@tonic-gate instance, 6160Sstevel@tonic-gate pshot_register_events[i].event_name, 6170Sstevel@tonic-gate rval); 6180Sstevel@tonic-gate } 6190Sstevel@tonic-gate } 6200Sstevel@tonic-gate 6210Sstevel@tonic-gate #ifdef DEBUG 6220Sstevel@tonic-gate if (pshot_event_test_enable) { 6230Sstevel@tonic-gate pshot_event_test((void *)pshot); 6240Sstevel@tonic-gate (void) timeout(pshot_event_test_post_one, (void *)pshot, 6250Sstevel@tonic-gate instance * drv_usectohz(60000000)); 6260Sstevel@tonic-gate } 6270Sstevel@tonic-gate #endif 6280Sstevel@tonic-gate 6290Sstevel@tonic-gate /* 6300Sstevel@tonic-gate * allocate an ndi event handle 6310Sstevel@tonic-gate */ 6320Sstevel@tonic-gate if (ndi_event_alloc_hdl(devi, NULL, &pshot->ndi_event_hdl, 6330Sstevel@tonic-gate NDI_SLEEP) != NDI_SUCCESS) { 6340Sstevel@tonic-gate goto FAIL_ATTACH; 6350Sstevel@tonic-gate } 6360Sstevel@tonic-gate 6370Sstevel@tonic-gate pshot->ndi_events.ndi_events_version = NDI_EVENTS_REV1; 6380Sstevel@tonic-gate pshot->ndi_events.ndi_n_events = PSHOT_N_NDI_EVENTS; 6390Sstevel@tonic-gate pshot->ndi_events.ndi_event_defs = pshot_ndi_event_defs; 6400Sstevel@tonic-gate 6410Sstevel@tonic-gate if (ndi_event_bind_set(pshot->ndi_event_hdl, &pshot->ndi_events, 6420Sstevel@tonic-gate NDI_SLEEP) != NDI_SUCCESS) { 6430Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d bind set failed\n", 6447656SSherry.Moore@Sun.COM instance); 6450Sstevel@tonic-gate } 6460Sstevel@tonic-gate 6470Sstevel@tonic-gate /* 6480Sstevel@tonic-gate * setup a test for nexus auto-attach iff we are 6490Sstevel@tonic-gate * a second level pshot node (parent == /SUNW,pshot) 6500Sstevel@tonic-gate * enable by setting "autoattach=1" in pshot.conf 6510Sstevel@tonic-gate */ 6520Sstevel@tonic-gate if ((PARENT_IS_PSHOT(devi)) && (pshot_prop_autoattach != 0) && 6530Sstevel@tonic-gate (ddi_get_instance(ddi_get_parent(devi))) == 0) 6540Sstevel@tonic-gate pshot_setup_autoattach(devi); 6550Sstevel@tonic-gate 6560Sstevel@tonic-gate /* 6570Sstevel@tonic-gate * initialize internal state to idle: busy = 0, 6580Sstevel@tonic-gate * power level = -1 6590Sstevel@tonic-gate */ 6600Sstevel@tonic-gate mutex_enter(&pshot->lock); 6610Sstevel@tonic-gate pshot->busy = 0; 6620Sstevel@tonic-gate pshot->busy_ioctl = 0; 6630Sstevel@tonic-gate pshot->level = -1; 6640Sstevel@tonic-gate pshot->state &= ~STRICT_PARENT; 6650Sstevel@tonic-gate pshot->state |= PM_SUPPORTED; 6660Sstevel@tonic-gate mutex_exit(&pshot->lock); 6670Sstevel@tonic-gate 6680Sstevel@tonic-gate /* 6690Sstevel@tonic-gate * Create the "pm-want-child-notification?" property 6700Sstevel@tonic-gate * for the root node /devices/pshot 6710Sstevel@tonic-gate */ 6720Sstevel@tonic-gate if (instance == 0) { 6730Sstevel@tonic-gate if (pshot_debug) { 6740Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_ATTACH:\n\t" 6750Sstevel@tonic-gate " create the" 6760Sstevel@tonic-gate " \"pm-want-child-notification?\" property" 6770Sstevel@tonic-gate " for the root node\n", instance); 6780Sstevel@tonic-gate } 6790Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, devi, 0, 6800Sstevel@tonic-gate "pm-want-child-notification?", NULL, 0) 6810Sstevel@tonic-gate != DDI_PROP_SUCCESS) { 6820Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d:\n\t" 6830Sstevel@tonic-gate " unable to create the" 6840Sstevel@tonic-gate " \"pm-want-child-notification?\"" 6850Sstevel@tonic-gate " property", ddi_get_name(devi), 6860Sstevel@tonic-gate ddi_get_instance(devi)); 6870Sstevel@tonic-gate 6880Sstevel@tonic-gate goto FAIL_ATTACH; 6890Sstevel@tonic-gate } 6900Sstevel@tonic-gate } 6910Sstevel@tonic-gate 6920Sstevel@tonic-gate /* 6930Sstevel@tonic-gate * Check if the pm-want-child-notification? property was 6940Sstevel@tonic-gate * created in pshot_bus_config_setup_nexus() by the parent. 6950Sstevel@tonic-gate * Set the STRICT_PARENT flag if not. 6960Sstevel@tonic-gate */ 6970Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, devi, 6980Sstevel@tonic-gate (DDI_PROP_DONTPASS | DDI_PROP_NOTPROM), 6990Sstevel@tonic-gate "pm-want-child-notification?") != 1) { 7000Sstevel@tonic-gate if (pshot_debug) { 7010Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_ATTACH:" 7020Sstevel@tonic-gate " STRICT PARENT\n", instance); 7030Sstevel@tonic-gate } 7040Sstevel@tonic-gate mutex_enter(&pshot->lock); 7050Sstevel@tonic-gate pshot->state |= STRICT_PARENT; 7060Sstevel@tonic-gate mutex_exit(&pshot->lock); 7070Sstevel@tonic-gate } else { 7080Sstevel@tonic-gate if (pshot_debug) { 7090Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_ATTACH:" 7100Sstevel@tonic-gate " INVOLVED PARENT\n", instance); 7110Sstevel@tonic-gate } 7120Sstevel@tonic-gate mutex_enter(&pshot->lock); 7130Sstevel@tonic-gate pshot->state &= ~STRICT_PARENT; 7140Sstevel@tonic-gate mutex_exit(&pshot->lock); 7150Sstevel@tonic-gate } 7160Sstevel@tonic-gate 7170Sstevel@tonic-gate /* 7180Sstevel@tonic-gate * create the pm-components property: one component 7190Sstevel@tonic-gate * with 4 power levels. 7200Sstevel@tonic-gate * - skip for pshot@XXX,nopm and pshot@XXX,nopm_strict: 7210Sstevel@tonic-gate * "no-pm-components" property 7220Sstevel@tonic-gate */ 7230Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, devi, 7240Sstevel@tonic-gate (DDI_PROP_DONTPASS | DDI_PROP_NOTPROM), 7250Sstevel@tonic-gate "no-pm-components") == 0) { 7260Sstevel@tonic-gate if (pshot_debug) { 7270Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_ATTACH:" 7280Sstevel@tonic-gate " create the \"pm_components\" property\n", 7290Sstevel@tonic-gate instance); 7300Sstevel@tonic-gate } 7310Sstevel@tonic-gate if (ddi_prop_update_string_array(DDI_DEV_T_NONE, devi, 7320Sstevel@tonic-gate "pm-components", pm_comp, 5) != DDI_PROP_SUCCESS) { 7330Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: DDI_ATTACH:\n\t" 7340Sstevel@tonic-gate " unable to create the \"pm-components\"" 7350Sstevel@tonic-gate " property", ddi_get_name(devi), 7360Sstevel@tonic-gate ddi_get_instance(devi)); 7370Sstevel@tonic-gate 7380Sstevel@tonic-gate goto FAIL_ATTACH; 7390Sstevel@tonic-gate } 7400Sstevel@tonic-gate } else { 7410Sstevel@tonic-gate if (pshot_debug) { 7420Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_ATTACH:" 7430Sstevel@tonic-gate " NO-PM_COMPONENTS PARENT\n", instance); 7440Sstevel@tonic-gate } 7450Sstevel@tonic-gate mutex_enter(&pshot->lock); 7460Sstevel@tonic-gate pshot->state &= ~PM_SUPPORTED; 7470Sstevel@tonic-gate mutex_exit(&pshot->lock); 7480Sstevel@tonic-gate } 7490Sstevel@tonic-gate 7500Sstevel@tonic-gate /* 7510Sstevel@tonic-gate * create the property needed to get DDI_SUSPEND 7520Sstevel@tonic-gate * and DDI_RESUME calls 7530Sstevel@tonic-gate */ 7540Sstevel@tonic-gate if (pshot_debug) { 7550Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_ATTACH:" 7560Sstevel@tonic-gate " create pm-hardware-state property\n", 7570Sstevel@tonic-gate instance); 7580Sstevel@tonic-gate } 7590Sstevel@tonic-gate if (ddi_prop_update_string(DDI_DEV_T_NONE, devi, 7600Sstevel@tonic-gate "pm-hardware-state", pm_hw_state) != DDI_PROP_SUCCESS) { 7610Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: DDI_ATTACH:\n\t" 7620Sstevel@tonic-gate " unable to create the \"pm-hardware-state\"" 7630Sstevel@tonic-gate " property", ddi_get_name(devi), 7640Sstevel@tonic-gate ddi_get_instance(devi)); 7650Sstevel@tonic-gate 7660Sstevel@tonic-gate goto FAIL_ATTACH; 7670Sstevel@tonic-gate } 7680Sstevel@tonic-gate 7690Sstevel@tonic-gate /* 7700Sstevel@tonic-gate * set power level to max via pm_raise_power(), 7710Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm) 7720Sstevel@tonic-gate */ 7730Sstevel@tonic-gate if (pshot->state & PM_SUPPORTED) { 7740Sstevel@tonic-gate if (pshot_debug) { 7750Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_ATTACH:" 7760Sstevel@tonic-gate " raise power to MAXPWR\n", instance); 7770Sstevel@tonic-gate } 7780Sstevel@tonic-gate if (pm_raise_power(pshot->dip, 0, MAXPWR) != 7790Sstevel@tonic-gate DDI_SUCCESS) { 7800Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: DDI_ATTACH:" 7810Sstevel@tonic-gate " pm_raise_power failed", 7820Sstevel@tonic-gate ddi_get_name(devi), 7830Sstevel@tonic-gate ddi_get_instance(devi)); 7840Sstevel@tonic-gate 7850Sstevel@tonic-gate goto FAIL_ATTACH; 7860Sstevel@tonic-gate 7870Sstevel@tonic-gate } 7880Sstevel@tonic-gate } 7890Sstevel@tonic-gate 7900Sstevel@tonic-gate if (pshot_log) 7910Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d attached\n", instance); 7920Sstevel@tonic-gate ddi_report_dev(devi); 7930Sstevel@tonic-gate 7940Sstevel@tonic-gate return (DDI_SUCCESS); 7950Sstevel@tonic-gate /*NOTREACHED*/ 7960Sstevel@tonic-gate FAIL_ATTACH: 7970Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 7980Sstevel@tonic-gate mutex_destroy(&pshot->lock); 7990Sstevel@tonic-gate ddi_soft_state_free(pshot_softstatep, instance); 8000Sstevel@tonic-gate return (DDI_FAILURE); 8010Sstevel@tonic-gate 8020Sstevel@tonic-gate case DDI_RESUME: 8030Sstevel@tonic-gate if (pshot_debug) { 8040Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_RESUME: resuming\n", 8050Sstevel@tonic-gate instance); 8060Sstevel@tonic-gate } 8070Sstevel@tonic-gate pshot = ddi_get_soft_state(pshot_softstatep, instance); 8080Sstevel@tonic-gate 8090Sstevel@tonic-gate /* 8100Sstevel@tonic-gate * set power level to max via pm_raise_power(), 8110Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm) 8120Sstevel@tonic-gate */ 8130Sstevel@tonic-gate if (pshot->state & PM_SUPPORTED) { 8140Sstevel@tonic-gate if (pshot_debug) { 8150Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_RESUME:" 8160Sstevel@tonic-gate " raise power to MAXPWR\n", instance); 8170Sstevel@tonic-gate } 8180Sstevel@tonic-gate if (pm_raise_power(pshot->dip, 0, MAXPWR) != 8190Sstevel@tonic-gate DDI_SUCCESS) { 8200Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: DDI_RESUME:" 8210Sstevel@tonic-gate " pm_raise_power failed", 8220Sstevel@tonic-gate ddi_get_name(devi), 8230Sstevel@tonic-gate ddi_get_instance(devi)); 8240Sstevel@tonic-gate } 8250Sstevel@tonic-gate } 8260Sstevel@tonic-gate 8270Sstevel@tonic-gate if (pshot_debug) { 8280Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_RESUME: resumed\n", 8290Sstevel@tonic-gate instance); 8300Sstevel@tonic-gate } 8310Sstevel@tonic-gate return (DDI_SUCCESS); 8320Sstevel@tonic-gate 8330Sstevel@tonic-gate default: 8340Sstevel@tonic-gate return (DDI_FAILURE); 8350Sstevel@tonic-gate } 8360Sstevel@tonic-gate } 8370Sstevel@tonic-gate 8380Sstevel@tonic-gate static int 8390Sstevel@tonic-gate pshot_detach(dev_info_t *devi, ddi_detach_cmd_t cmd) 8400Sstevel@tonic-gate { 8410Sstevel@tonic-gate int instance = ddi_get_instance(devi); 8420Sstevel@tonic-gate int i, rval; 8430Sstevel@tonic-gate pshot_t *pshot = ddi_get_soft_state(pshot_softstatep, instance); 8440Sstevel@tonic-gate int level_tmp; 8450Sstevel@tonic-gate 8460Sstevel@tonic-gate if (pshot == NULL) 8470Sstevel@tonic-gate return (DDI_FAILURE); 8480Sstevel@tonic-gate 8490Sstevel@tonic-gate switch (cmd) { 8500Sstevel@tonic-gate 8510Sstevel@tonic-gate case DDI_DETACH: 8520Sstevel@tonic-gate if (pshot_debug) 8530Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_DETACH\n", instance); 8540Sstevel@tonic-gate /* 8550Sstevel@tonic-gate * power off component 0 8560Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm) 8570Sstevel@tonic-gate */ 8580Sstevel@tonic-gate if (pshot->state & PM_SUPPORTED) { 8590Sstevel@tonic-gate if (pshot_debug) { 8600Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_DETACH:" 8610Sstevel@tonic-gate " power off\n", instance); 8620Sstevel@tonic-gate } 8630Sstevel@tonic-gate if (pm_lower_power(pshot->dip, 0, 0) != DDI_SUCCESS) { 8640Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: DDI_DETACH:\n\t" 8650Sstevel@tonic-gate "pm_lower_power failed for comp 0 to" 8660Sstevel@tonic-gate " level 0", ddi_get_name(devi), 8670Sstevel@tonic-gate ddi_get_instance(devi)); 8680Sstevel@tonic-gate 8690Sstevel@tonic-gate return (DDI_FAILURE); 8700Sstevel@tonic-gate } 8710Sstevel@tonic-gate 8720Sstevel@tonic-gate /* 8730Sstevel@tonic-gate * Check if the power level is actually OFF. 8740Sstevel@tonic-gate * Issue pm_power_has_changed if not. 8750Sstevel@tonic-gate */ 8760Sstevel@tonic-gate mutex_enter(&pshot->lock); 8770Sstevel@tonic-gate if (pshot->level != 0) { 8780Sstevel@tonic-gate if (pshot_debug) { 8790Sstevel@tonic-gate cmn_err(CE_NOTE, "pshot%d:" 8800Sstevel@tonic-gate " DDI_DETACH: power off via" 8810Sstevel@tonic-gate " pm_power_has_changed instead\n", 8820Sstevel@tonic-gate instance); 8830Sstevel@tonic-gate } 8840Sstevel@tonic-gate level_tmp = pshot->level; 8850Sstevel@tonic-gate pshot->level = 0; 8860Sstevel@tonic-gate if (pm_power_has_changed(pshot->dip, 0, 0) != 8870Sstevel@tonic-gate DDI_SUCCESS) { 8880Sstevel@tonic-gate if (pshot_debug) { 8890Sstevel@tonic-gate cmn_err(CE_NOTE, "pshot%d:" 8900Sstevel@tonic-gate " DDI_DETACH:" 8910Sstevel@tonic-gate " pm_power_has_changed" 8920Sstevel@tonic-gate " failed\n", instance); 8930Sstevel@tonic-gate } 8940Sstevel@tonic-gate pshot->level = level_tmp; 8950Sstevel@tonic-gate mutex_exit(&pshot->lock); 8960Sstevel@tonic-gate 8970Sstevel@tonic-gate return (DDI_FAILURE); 8980Sstevel@tonic-gate } 8990Sstevel@tonic-gate } 9000Sstevel@tonic-gate mutex_exit(&pshot->lock); 9010Sstevel@tonic-gate } 9020Sstevel@tonic-gate 9030Sstevel@tonic-gate for (i = 0; i < PSHOT_N_DDI_EVENTS; i++) { 9040Sstevel@tonic-gate if (pshot->callback_cache[i] != NULL) { 9050Sstevel@tonic-gate rval = ddi_remove_event_handler( 9060Sstevel@tonic-gate pshot->callback_cache[i]); 9070Sstevel@tonic-gate ASSERT(rval == DDI_SUCCESS); 9080Sstevel@tonic-gate } 9090Sstevel@tonic-gate } 9100Sstevel@tonic-gate 9110Sstevel@tonic-gate #ifdef DEBUG 9120Sstevel@tonic-gate for (i = 0; i < PSHOT_N_TEST_EVENTS; i++) { 9130Sstevel@tonic-gate if (pshot->test_callback_cache[i] != NULL) { 9140Sstevel@tonic-gate rval = ddi_remove_event_handler( 9150Sstevel@tonic-gate pshot->test_callback_cache[i]); 9160Sstevel@tonic-gate ASSERT(rval == DDI_SUCCESS); 9170Sstevel@tonic-gate } 9180Sstevel@tonic-gate } 9190Sstevel@tonic-gate #endif 9200Sstevel@tonic-gate rval = ndi_event_free_hdl(pshot->ndi_event_hdl); 9210Sstevel@tonic-gate ASSERT(rval == DDI_SUCCESS); 9220Sstevel@tonic-gate 9230Sstevel@tonic-gate if (pshot_log) 9240Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d detached\n", instance); 9250Sstevel@tonic-gate 9260Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL); 9270Sstevel@tonic-gate mutex_destroy(&pshot->lock); 9280Sstevel@tonic-gate ddi_soft_state_free(pshot_softstatep, instance); 9290Sstevel@tonic-gate break; 9300Sstevel@tonic-gate 9310Sstevel@tonic-gate case DDI_SUSPEND: 9320Sstevel@tonic-gate if (pshot_debug) 9330Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_SUSPEND\n", instance); 9340Sstevel@tonic-gate /* 9350Sstevel@tonic-gate * fail the suspend if FAIL_SUSPEND_FLAG is set. 9360Sstevel@tonic-gate * clear the FAIL_SUSPEND_FLAG flag 9370Sstevel@tonic-gate */ 9380Sstevel@tonic-gate mutex_enter(&pshot->lock); 9390Sstevel@tonic-gate if (pshot->state & FAIL_SUSPEND_FLAG) { 9400Sstevel@tonic-gate if (pshot_debug) { 9410Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:" 9427656SSherry.Moore@Sun.COM " FAIL_SUSPEND_FLAG set, fail suspend\n", 9437656SSherry.Moore@Sun.COM ddi_get_instance(devi)); 9440Sstevel@tonic-gate } 9450Sstevel@tonic-gate pshot->state &= ~FAIL_SUSPEND_FLAG; 9460Sstevel@tonic-gate rval = DDI_FAILURE; 9470Sstevel@tonic-gate } else { 9480Sstevel@tonic-gate rval = DDI_SUCCESS; 9490Sstevel@tonic-gate } 9500Sstevel@tonic-gate mutex_exit(&pshot->lock); 9510Sstevel@tonic-gate 9520Sstevel@tonic-gate /* 9530Sstevel@tonic-gate * power OFF via pm_power_has_changed 9540Sstevel@tonic-gate */ 9550Sstevel@tonic-gate mutex_enter(&pshot->lock); 9560Sstevel@tonic-gate if (pshot->state & PM_SUPPORTED) { 9570Sstevel@tonic-gate if (pshot_debug) { 9580Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_SUSPEND:" 9590Sstevel@tonic-gate " power off via pm_power_has_changed\n", 9600Sstevel@tonic-gate instance); 9610Sstevel@tonic-gate } 9620Sstevel@tonic-gate level_tmp = pshot->level; 9630Sstevel@tonic-gate pshot->level = 0; 9640Sstevel@tonic-gate if (pm_power_has_changed(pshot->dip, 0, 0) != 9650Sstevel@tonic-gate DDI_SUCCESS) { 9660Sstevel@tonic-gate if (pshot_debug) { 9670Sstevel@tonic-gate cmn_err(CE_NOTE, "pshot%d:" 9680Sstevel@tonic-gate " DDI_SUSPEND:" 9690Sstevel@tonic-gate " pm_power_has_changed failed\n", 9700Sstevel@tonic-gate instance); 9710Sstevel@tonic-gate } 9720Sstevel@tonic-gate pshot->level = level_tmp; 9730Sstevel@tonic-gate rval = DDI_FAILURE; 9740Sstevel@tonic-gate } 9750Sstevel@tonic-gate } 9760Sstevel@tonic-gate mutex_exit(&pshot->lock); 9770Sstevel@tonic-gate return (rval); 9780Sstevel@tonic-gate 9790Sstevel@tonic-gate default: 9800Sstevel@tonic-gate break; 9810Sstevel@tonic-gate } 9820Sstevel@tonic-gate 9830Sstevel@tonic-gate return (DDI_SUCCESS); 9840Sstevel@tonic-gate } 9850Sstevel@tonic-gate 9860Sstevel@tonic-gate 9870Sstevel@tonic-gate /* 9880Sstevel@tonic-gate * returns number of bits to represent <val> 9890Sstevel@tonic-gate */ 9900Sstevel@tonic-gate static size_t 9910Sstevel@tonic-gate pshot_numbits(size_t val) 9920Sstevel@tonic-gate { 9930Sstevel@tonic-gate size_t bitcnt; 9940Sstevel@tonic-gate 9950Sstevel@tonic-gate if (val == 0) 9960Sstevel@tonic-gate return (0); 9970Sstevel@tonic-gate for (bitcnt = 1; 1 << bitcnt < val; bitcnt++) 9980Sstevel@tonic-gate ; 9990Sstevel@tonic-gate return (bitcnt); 10000Sstevel@tonic-gate } 10010Sstevel@tonic-gate 10020Sstevel@tonic-gate /* 10030Sstevel@tonic-gate * returns a minor number encoded with instance <inst> and an index <nodenum> 10040Sstevel@tonic-gate * that identifies the minor node for this instance 10050Sstevel@tonic-gate */ 10060Sstevel@tonic-gate static minor_t 10070Sstevel@tonic-gate pshot_minor_encode(int inst, minor_t nodenum) 10080Sstevel@tonic-gate { 10090Sstevel@tonic-gate return (((minor_t)inst << PSHOT_NODENUM_BITS()) | 10100Sstevel@tonic-gate (((1 << PSHOT_NODENUM_BITS()) - 1) & nodenum)); 10110Sstevel@tonic-gate } 10120Sstevel@tonic-gate 10130Sstevel@tonic-gate /* 10140Sstevel@tonic-gate * returns instance of <minor> 10150Sstevel@tonic-gate */ 10160Sstevel@tonic-gate static int 10170Sstevel@tonic-gate pshot_minor_decode_inst(minor_t minor) 10180Sstevel@tonic-gate { 10190Sstevel@tonic-gate return (minor >> PSHOT_NODENUM_BITS()); 10200Sstevel@tonic-gate } 10210Sstevel@tonic-gate 10220Sstevel@tonic-gate /* 10230Sstevel@tonic-gate * returns node number indexing a minor node for the instance in <minor> 10240Sstevel@tonic-gate */ 10250Sstevel@tonic-gate static minor_t 10260Sstevel@tonic-gate pshot_minor_decode_nodenum(minor_t minor) 10270Sstevel@tonic-gate { 10280Sstevel@tonic-gate return (minor & ((1 << PSHOT_NODENUM_BITS()) - 1)); 10290Sstevel@tonic-gate } 10300Sstevel@tonic-gate 10310Sstevel@tonic-gate 10320Sstevel@tonic-gate /* 10330Sstevel@tonic-gate * pshot_bus_introp: pshot convert an interrupt number to an 10340Sstevel@tonic-gate * interrupt. NO OP for pseudo drivers. 10350Sstevel@tonic-gate */ 10360Sstevel@tonic-gate /*ARGSUSED*/ 10370Sstevel@tonic-gate static int 10380Sstevel@tonic-gate pshot_bus_introp(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op, 10390Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result) 10400Sstevel@tonic-gate { 10410Sstevel@tonic-gate return (DDI_FAILURE); 10420Sstevel@tonic-gate } 10430Sstevel@tonic-gate static int 10440Sstevel@tonic-gate pshot_ctl(dev_info_t *dip, dev_info_t *rdip, 10450Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, void *result) 10460Sstevel@tonic-gate { 10470Sstevel@tonic-gate int instance; 10480Sstevel@tonic-gate pshot_t *pshot; 10490Sstevel@tonic-gate char *childname; 10500Sstevel@tonic-gate int childinstance; 10510Sstevel@tonic-gate char *name; 10520Sstevel@tonic-gate int circ; 10530Sstevel@tonic-gate struct attachspec *as; 10540Sstevel@tonic-gate struct detachspec *ds; 10550Sstevel@tonic-gate int rval = DDI_SUCCESS; 10560Sstevel@tonic-gate int no_pm_components_child; 10570Sstevel@tonic-gate 10580Sstevel@tonic-gate name = ddi_get_name(dip); 10590Sstevel@tonic-gate instance = ddi_get_instance(dip); 10600Sstevel@tonic-gate pshot = ddi_get_soft_state(pshot_softstatep, instance); 10610Sstevel@tonic-gate if (pshot == NULL) { 10620Sstevel@tonic-gate return (ENXIO); 10630Sstevel@tonic-gate } 10640Sstevel@tonic-gate 10650Sstevel@tonic-gate switch (ctlop) { 10660Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV: 10670Sstevel@tonic-gate if (rdip == (dev_info_t *)0) 10680Sstevel@tonic-gate return (DDI_FAILURE); 10690Sstevel@tonic-gate cmn_err(CE_CONT, "?pshot-device: %s%d\n", 10700Sstevel@tonic-gate ddi_get_name(rdip), ddi_get_instance(rdip)); 10710Sstevel@tonic-gate return (DDI_SUCCESS); 10720Sstevel@tonic-gate 10730Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD: 10740Sstevel@tonic-gate { 10750Sstevel@tonic-gate dev_info_t *child = (dev_info_t *)arg; 10760Sstevel@tonic-gate 10770Sstevel@tonic-gate if (pshot_debug) { 10780Sstevel@tonic-gate cmn_err(CE_CONT, "initchild %s%d/%s%d state 0x%x\n", 10790Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip), 10800Sstevel@tonic-gate ddi_node_name(child), ddi_get_instance(child), 10810Sstevel@tonic-gate DEVI(child)->devi_state); 10820Sstevel@tonic-gate } 10830Sstevel@tonic-gate 10840Sstevel@tonic-gate return (pshot_initchild(dip, child)); 10850Sstevel@tonic-gate } 10860Sstevel@tonic-gate 10870Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD: 10880Sstevel@tonic-gate { 10890Sstevel@tonic-gate dev_info_t *child = (dev_info_t *)arg; 10900Sstevel@tonic-gate 10910Sstevel@tonic-gate if (pshot_debug) { 10920Sstevel@tonic-gate cmn_err(CE_CONT, "uninitchild %s%d/%s%d state 0x%x\n", 10930Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip), 10940Sstevel@tonic-gate ddi_node_name(child), ddi_get_instance(child), 10950Sstevel@tonic-gate DEVI(child)->devi_state); 10960Sstevel@tonic-gate } 10970Sstevel@tonic-gate 10980Sstevel@tonic-gate return (pshot_uninitchild(dip, child)); 10990Sstevel@tonic-gate } 11000Sstevel@tonic-gate 11010Sstevel@tonic-gate case DDI_CTLOPS_DMAPMAPC: 11020Sstevel@tonic-gate case DDI_CTLOPS_REPORTINT: 11030Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE: 11040Sstevel@tonic-gate case DDI_CTLOPS_NREGS: 11050Sstevel@tonic-gate case DDI_CTLOPS_SIDDEV: 11060Sstevel@tonic-gate case DDI_CTLOPS_SLAVEONLY: 11070Sstevel@tonic-gate case DDI_CTLOPS_AFFINITY: 11080Sstevel@tonic-gate case DDI_CTLOPS_POKE: 11090Sstevel@tonic-gate case DDI_CTLOPS_PEEK: 11100Sstevel@tonic-gate /* 11110Sstevel@tonic-gate * These ops correspond to functions that "shouldn't" be called 11120Sstevel@tonic-gate * by a pseudo driver. So we whine when we're called. 11130Sstevel@tonic-gate */ 11140Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: invalid op (%d) from %s%d\n", 11157656SSherry.Moore@Sun.COM ddi_get_name(dip), ddi_get_instance(dip), 11167656SSherry.Moore@Sun.COM ctlop, ddi_get_name(rdip), ddi_get_instance(rdip)); 11170Sstevel@tonic-gate return (DDI_FAILURE); 11180Sstevel@tonic-gate 11190Sstevel@tonic-gate case DDI_CTLOPS_ATTACH: 11200Sstevel@tonic-gate { 11210Sstevel@tonic-gate dev_info_t *child = (dev_info_t *)rdip; 11220Sstevel@tonic-gate childname = ddi_node_name(child); 11230Sstevel@tonic-gate childinstance = ddi_get_instance(child); 11240Sstevel@tonic-gate as = (struct attachspec *)arg; 11250Sstevel@tonic-gate 11260Sstevel@tonic-gate no_pm_components_child = 0; 11270Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, child, 11280Sstevel@tonic-gate (DDI_PROP_DONTPASS | DDI_PROP_NOTPROM), 11290Sstevel@tonic-gate "no-pm-components") == 1) { 11300Sstevel@tonic-gate no_pm_components_child = 1; 11310Sstevel@tonic-gate } 11320Sstevel@tonic-gate if (pshot_debug) { 11330Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: ctl_attach %s%d [%d]\n", 11340Sstevel@tonic-gate name, instance, childname, childinstance, 11350Sstevel@tonic-gate no_pm_components_child); 11360Sstevel@tonic-gate } 11370Sstevel@tonic-gate 11380Sstevel@tonic-gate ndi_devi_enter(dip, &circ); 11390Sstevel@tonic-gate 11400Sstevel@tonic-gate switch (as->when) { 11410Sstevel@tonic-gate case DDI_PRE: 11420Sstevel@tonic-gate /* 11430Sstevel@tonic-gate * Mark nexus busy before a child attaches. 11440Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm 11450Sstevel@tonic-gate * - pshot@XXX,nopm_strict) 11460Sstevel@tonic-gate */ 11470Sstevel@tonic-gate if (!(pshot->state & PM_SUPPORTED)) 11480Sstevel@tonic-gate break; 11490Sstevel@tonic-gate mutex_enter(&pshot->lock); 11500Sstevel@tonic-gate ++(pshot->busy); 11510Sstevel@tonic-gate if (pshot_debug_busy) { 11520Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d:" 11530Sstevel@tonic-gate " ctl_attach_pre: busy for %s%d:" 11540Sstevel@tonic-gate " busy = %d\n", name, instance, 11550Sstevel@tonic-gate childname, childinstance, 11560Sstevel@tonic-gate pshot->busy); 11570Sstevel@tonic-gate } 11580Sstevel@tonic-gate mutex_exit(&pshot->lock); 11590Sstevel@tonic-gate rval = pm_busy_component(dip, 0); 11600Sstevel@tonic-gate ASSERT(rval == DDI_SUCCESS); 11610Sstevel@tonic-gate break; 11620Sstevel@tonic-gate case DDI_POST: 11630Sstevel@tonic-gate /* 11640Sstevel@tonic-gate * Mark nexus idle after a child attaches. 11650Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm). 11660Sstevel@tonic-gate * - also skip if this is not a stict parent and 11670Sstevel@tonic-gate * - the child is a tape device or a no-pm-components 11680Sstevel@tonic-gate * - nexus node. 11690Sstevel@tonic-gate */ 11700Sstevel@tonic-gate if (!(pshot->state & PM_SUPPORTED) || 11710Sstevel@tonic-gate (strcmp(childname, "tape") == 0 && 11720Sstevel@tonic-gate !(pshot->state & STRICT_PARENT)) || 11730Sstevel@tonic-gate no_pm_components_child) 11740Sstevel@tonic-gate break; 11750Sstevel@tonic-gate mutex_enter(&pshot->lock); 11760Sstevel@tonic-gate ASSERT(pshot->busy > 0); 11770Sstevel@tonic-gate --pshot->busy; 11780Sstevel@tonic-gate if (pshot_debug_busy) { 11790Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d:" 11800Sstevel@tonic-gate " ctl_attach_post: idle for %s%d:" 11810Sstevel@tonic-gate " busy = %d\n", name, instance, 11820Sstevel@tonic-gate childname, childinstance, 11830Sstevel@tonic-gate pshot->busy); 11840Sstevel@tonic-gate } 11850Sstevel@tonic-gate mutex_exit(&pshot->lock); 11860Sstevel@tonic-gate rval = pm_idle_component(dip, 0); 11870Sstevel@tonic-gate ASSERT(rval == DDI_SUCCESS); 11880Sstevel@tonic-gate break; 11890Sstevel@tonic-gate } 11900Sstevel@tonic-gate 11910Sstevel@tonic-gate ndi_devi_exit(dip, circ); 11920Sstevel@tonic-gate 11930Sstevel@tonic-gate return (rval); 11940Sstevel@tonic-gate } 11950Sstevel@tonic-gate case DDI_CTLOPS_DETACH: 11960Sstevel@tonic-gate { 11970Sstevel@tonic-gate dev_info_t *child = (dev_info_t *)rdip; 11980Sstevel@tonic-gate childname = ddi_node_name(child); 11990Sstevel@tonic-gate childinstance = ddi_get_instance(child); 12000Sstevel@tonic-gate ds = (struct detachspec *)arg; 12010Sstevel@tonic-gate 12020Sstevel@tonic-gate no_pm_components_child = 0; 12030Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, child, 12040Sstevel@tonic-gate (DDI_PROP_DONTPASS | DDI_PROP_NOTPROM), 12050Sstevel@tonic-gate "no-pm-components") == 1) { 12060Sstevel@tonic-gate no_pm_components_child = 1; 12070Sstevel@tonic-gate } 12080Sstevel@tonic-gate if (pshot_debug) { 12090Sstevel@tonic-gate cmn_err(CE_CONT, 12100Sstevel@tonic-gate "%s%d: ctl_detach %s%d [%d]\n", 12110Sstevel@tonic-gate name, instance, childname, childinstance, 12120Sstevel@tonic-gate no_pm_components_child); 12130Sstevel@tonic-gate } 12140Sstevel@tonic-gate 12150Sstevel@tonic-gate ndi_devi_enter(dip, &circ); 12160Sstevel@tonic-gate 12170Sstevel@tonic-gate switch (ds->when) { 12180Sstevel@tonic-gate case DDI_PRE: 12190Sstevel@tonic-gate /* 12200Sstevel@tonic-gate * Mark nexus busy before a child detaches. 12210Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm 12220Sstevel@tonic-gate * - pshot@XXX,nopm_strict), or if the child is a 12230Sstevel@tonic-gate * - no-pm-components nexus node. 12240Sstevel@tonic-gate */ 12250Sstevel@tonic-gate if (!(pshot->state & PM_SUPPORTED) || 12260Sstevel@tonic-gate (strcmp(childname, "tape") == 0 && 12270Sstevel@tonic-gate !(pshot->state & STRICT_PARENT)) || 12280Sstevel@tonic-gate no_pm_components_child) 12290Sstevel@tonic-gate break; 12300Sstevel@tonic-gate mutex_enter(&pshot->lock); 12310Sstevel@tonic-gate ++(pshot->busy); 12320Sstevel@tonic-gate if (pshot_debug_busy) { 12330Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d:" 12340Sstevel@tonic-gate " ctl_detach_pre: busy for %s%d:" 12350Sstevel@tonic-gate " busy = %d\n", name, instance, 12360Sstevel@tonic-gate childname, childinstance, 12370Sstevel@tonic-gate pshot->busy); 12380Sstevel@tonic-gate } 12390Sstevel@tonic-gate mutex_exit(&pshot->lock); 12400Sstevel@tonic-gate rval = pm_busy_component(dip, 0); 12410Sstevel@tonic-gate ASSERT(rval == DDI_SUCCESS); 12420Sstevel@tonic-gate 12430Sstevel@tonic-gate break; 12440Sstevel@tonic-gate case DDI_POST: 12450Sstevel@tonic-gate /* 12460Sstevel@tonic-gate * Mark nexus idle after a child detaches. 12470Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm) 12480Sstevel@tonic-gate */ 12490Sstevel@tonic-gate if (!(pshot->state & PM_SUPPORTED)) 12500Sstevel@tonic-gate break; 12510Sstevel@tonic-gate mutex_enter(&pshot->lock); 12520Sstevel@tonic-gate ASSERT(pshot->busy > 0); 12530Sstevel@tonic-gate --pshot->busy; 12540Sstevel@tonic-gate if (pshot_debug_busy) { 12550Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d:" 12560Sstevel@tonic-gate " ctl_detach_post: idle for %s%d:" 12570Sstevel@tonic-gate " busy = %d\n", name, instance, 12580Sstevel@tonic-gate childname, childinstance, 12590Sstevel@tonic-gate pshot->busy); 12600Sstevel@tonic-gate } 12610Sstevel@tonic-gate mutex_exit(&pshot->lock); 12620Sstevel@tonic-gate rval = pm_idle_component(dip, 0); 12630Sstevel@tonic-gate ASSERT(rval == DDI_SUCCESS); 12640Sstevel@tonic-gate 12650Sstevel@tonic-gate /* 12660Sstevel@tonic-gate * Mark the driver idle if the NO_INVOL_FLAG 12670Sstevel@tonic-gate * is set. This is needed to make sure the 12680Sstevel@tonic-gate * parent is idle after the child detaches 12690Sstevel@tonic-gate * without calling pm_lower_power(). 12700Sstevel@tonic-gate * Clear the NO_INVOL_FLAG. 12710Sstevel@tonic-gate * - also mark idle if a tape device has detached 12720Sstevel@tonic-gate */ 12730Sstevel@tonic-gate if (!(pshot->state & NO_INVOL_FLAG)) 12740Sstevel@tonic-gate break; 12750Sstevel@tonic-gate mutex_enter(&pshot->lock); 12760Sstevel@tonic-gate ASSERT(pshot->busy > 0); 12770Sstevel@tonic-gate --pshot->busy; 12780Sstevel@tonic-gate if (pshot_debug_busy) { 12790Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d:" 12800Sstevel@tonic-gate " ctl_detach_post: NO_INVOL:" 12810Sstevel@tonic-gate " idle for %s%d: busy = %d\n", 12820Sstevel@tonic-gate name, instance, childname, 12830Sstevel@tonic-gate childinstance, pshot->busy); 12840Sstevel@tonic-gate } 12850Sstevel@tonic-gate pshot->state &= ~NO_INVOL_FLAG; 12860Sstevel@tonic-gate mutex_exit(&pshot->lock); 12870Sstevel@tonic-gate rval = pm_idle_component(dip, 0); 12880Sstevel@tonic-gate ASSERT(rval == DDI_SUCCESS); 12890Sstevel@tonic-gate 12900Sstevel@tonic-gate break; 12910Sstevel@tonic-gate } 12920Sstevel@tonic-gate 12930Sstevel@tonic-gate ndi_devi_exit(dip, circ); 12940Sstevel@tonic-gate 12950Sstevel@tonic-gate return (rval); 12960Sstevel@tonic-gate } 12970Sstevel@tonic-gate 12982155Scth case DDI_CTLOPS_BTOP: 12992155Scth case DDI_CTLOPS_BTOPR: 13000Sstevel@tonic-gate case DDI_CTLOPS_DVMAPAGESIZE: 13010Sstevel@tonic-gate case DDI_CTLOPS_IOMIN: 13020Sstevel@tonic-gate case DDI_CTLOPS_PTOB: 13030Sstevel@tonic-gate default: 13040Sstevel@tonic-gate /* 13050Sstevel@tonic-gate * The ops that we pass up (default). We pass up memory 13060Sstevel@tonic-gate * allocation oriented ops that we receive - these may be 13070Sstevel@tonic-gate * associated with pseudo HBA drivers below us with target 13080Sstevel@tonic-gate * drivers below them that use ddi memory allocation 13090Sstevel@tonic-gate * interfaces like scsi_alloc_consistent_buf. 13100Sstevel@tonic-gate */ 13110Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result)); 13120Sstevel@tonic-gate } 13130Sstevel@tonic-gate } 13140Sstevel@tonic-gate 13150Sstevel@tonic-gate /*ARGSUSED0*/ 13160Sstevel@tonic-gate static int 13170Sstevel@tonic-gate pshot_power(dev_info_t *dip, int cmpt, int level) 13180Sstevel@tonic-gate { 13190Sstevel@tonic-gate pshot_t *pshot; 13200Sstevel@tonic-gate int instance = ddi_get_instance(dip); 13210Sstevel@tonic-gate char *name = ddi_node_name(dip); 13220Sstevel@tonic-gate int circ; 13230Sstevel@tonic-gate int rv; 13240Sstevel@tonic-gate 13250Sstevel@tonic-gate pshot = ddi_get_soft_state(pshot_softstatep, instance); 13260Sstevel@tonic-gate if (pshot == NULL) { 13270Sstevel@tonic-gate 13280Sstevel@tonic-gate return (DDI_FAILURE); 13290Sstevel@tonic-gate } 13300Sstevel@tonic-gate 13310Sstevel@tonic-gate ndi_devi_enter(dip, &circ); 13320Sstevel@tonic-gate 13330Sstevel@tonic-gate /* 13340Sstevel@tonic-gate * set POWER_FLAG when power() is called. 13350Sstevel@tonic-gate * ioctl(DEVCT_PM_POWER) is a clear on read call. 13360Sstevel@tonic-gate */ 13370Sstevel@tonic-gate mutex_enter(&pshot->lock); 13380Sstevel@tonic-gate pshot->state |= POWER_FLAG; 13390Sstevel@tonic-gate /* 13400Sstevel@tonic-gate * refuse to power OFF if the component is busy 13410Sstevel@tonic-gate */ 13420Sstevel@tonic-gate if (pshot->busy != 0 && pshot->level > level) { 13430Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: power: REFUSING POWER LEVEL CHANGE" 13440Sstevel@tonic-gate " (%d->%d), DEVICE NOT IDLE: busy = %d", 13450Sstevel@tonic-gate name, instance, pshot->level, level, pshot->busy); 13460Sstevel@tonic-gate rv = DDI_FAILURE; 13470Sstevel@tonic-gate } else { 13480Sstevel@tonic-gate if (pshot_debug) { 13490Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: power: comp %d (%d->%d)\n", 13500Sstevel@tonic-gate name, instance, cmpt, pshot->level, level); 13510Sstevel@tonic-gate } 13520Sstevel@tonic-gate pshot->level = level; 13530Sstevel@tonic-gate rv = DDI_SUCCESS; 13540Sstevel@tonic-gate } 13550Sstevel@tonic-gate mutex_exit(&pshot->lock); 13560Sstevel@tonic-gate 13570Sstevel@tonic-gate ndi_devi_exit(dip, circ); 13580Sstevel@tonic-gate 13590Sstevel@tonic-gate return (rv); 13600Sstevel@tonic-gate } 13610Sstevel@tonic-gate 13620Sstevel@tonic-gate /*ARGSUSED0*/ 13630Sstevel@tonic-gate static int 13640Sstevel@tonic-gate pshot_bus_power(dev_info_t *dip, void *impl_arg, pm_bus_power_op_t op, 13650Sstevel@tonic-gate void *arg, void *result) 13660Sstevel@tonic-gate 13670Sstevel@tonic-gate { 13680Sstevel@tonic-gate int ret; 13690Sstevel@tonic-gate int instance = ddi_get_instance(dip); 13700Sstevel@tonic-gate char *name = ddi_node_name(dip); 13710Sstevel@tonic-gate pshot_t *pshot; 13720Sstevel@tonic-gate pm_bp_child_pwrchg_t *bpc; 13730Sstevel@tonic-gate pm_bp_nexus_pwrup_t bpn; 13740Sstevel@tonic-gate pm_bp_has_changed_t *bphc; 13750Sstevel@tonic-gate int pwrup_res; 13760Sstevel@tonic-gate int ret_failed = 0; 13770Sstevel@tonic-gate int pwrup_res_failed = 0; 13780Sstevel@tonic-gate 13790Sstevel@tonic-gate pshot = ddi_get_soft_state(pshot_softstatep, instance); 13800Sstevel@tonic-gate if (pshot == NULL) { 13810Sstevel@tonic-gate 13820Sstevel@tonic-gate return (DDI_FAILURE); 13830Sstevel@tonic-gate } 13840Sstevel@tonic-gate 13850Sstevel@tonic-gate switch (op) { 13860Sstevel@tonic-gate case BUS_POWER_PRE_NOTIFICATION: 13870Sstevel@tonic-gate bpc = (pm_bp_child_pwrchg_t *)arg; 13880Sstevel@tonic-gate if (pshot_debug) { 13890Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: pre_bus_power:" 13900Sstevel@tonic-gate " %s%d comp %d (%d->%d)\n", 13910Sstevel@tonic-gate name, instance, ddi_node_name(bpc->bpc_dip), 13920Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip), 13930Sstevel@tonic-gate bpc->bpc_comp, bpc->bpc_olevel, 13940Sstevel@tonic-gate bpc->bpc_nlevel); 13950Sstevel@tonic-gate } 13960Sstevel@tonic-gate 13970Sstevel@tonic-gate /* 13980Sstevel@tonic-gate * mark parent busy if old_level is either -1 or 0, 13990Sstevel@tonic-gate * and new level is == MAXPWR 14000Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm) 14010Sstevel@tonic-gate */ 14020Sstevel@tonic-gate if ((bpc->bpc_comp == 0 && bpc->bpc_nlevel == MAXPWR && 14030Sstevel@tonic-gate bpc->bpc_olevel <= 0) && (pshot->state & PM_SUPPORTED)) { 14040Sstevel@tonic-gate mutex_enter(&pshot->lock); 14050Sstevel@tonic-gate ++(pshot->busy); 14060Sstevel@tonic-gate if (pshot_debug_busy) { 14070Sstevel@tonic-gate cmn_err(CE_CONT, 14080Sstevel@tonic-gate "%s%d: pre_bus_power:" 14090Sstevel@tonic-gate " busy parent for %s%d (%d->%d): " 14100Sstevel@tonic-gate " busy = %d\n", 14110Sstevel@tonic-gate name, instance, 14120Sstevel@tonic-gate ddi_node_name(bpc->bpc_dip), 14130Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip), 14140Sstevel@tonic-gate bpc->bpc_olevel, bpc->bpc_nlevel, 14150Sstevel@tonic-gate pshot->busy); 14160Sstevel@tonic-gate } 14170Sstevel@tonic-gate mutex_exit(&pshot->lock); 14180Sstevel@tonic-gate ret = pm_busy_component(dip, 0); 14190Sstevel@tonic-gate ASSERT(ret == DDI_SUCCESS); 14200Sstevel@tonic-gate } 14210Sstevel@tonic-gate 14220Sstevel@tonic-gate /* 14230Sstevel@tonic-gate * if new_level > 0, power up parent, if not already at 14240Sstevel@tonic-gate * MAXPWR, via pm_busop_bus_power 14250Sstevel@tonic-gate * - skip for the no-pm nexus (pshot@XXX,nopm) 14260Sstevel@tonic-gate */ 14270Sstevel@tonic-gate if (bpc->bpc_comp == 0 && bpc->bpc_nlevel > 0 && 14280Sstevel@tonic-gate pshot->level < MAXPWR && (pshot->state & PM_SUPPORTED)) { 14290Sstevel@tonic-gate /* 14300Sstevel@tonic-gate * stuff the bpn struct 14310Sstevel@tonic-gate */ 14320Sstevel@tonic-gate bpn.bpn_comp = 0; 14330Sstevel@tonic-gate bpn.bpn_level = MAXPWR; 14340Sstevel@tonic-gate bpn.bpn_private = bpc->bpc_private; 14350Sstevel@tonic-gate bpn.bpn_dip = dip; 14360Sstevel@tonic-gate 14370Sstevel@tonic-gate /* 14380Sstevel@tonic-gate * ask pm to power parent up 14390Sstevel@tonic-gate */ 14400Sstevel@tonic-gate if (pshot_debug) { 14410Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: pre_bus_power:" 14420Sstevel@tonic-gate " pm_busop_bus_power on parent for %s%d" 14430Sstevel@tonic-gate " (%d->%d): enter", name, instance, 14440Sstevel@tonic-gate ddi_node_name(bpc->bpc_dip), 14450Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip), 14460Sstevel@tonic-gate bpc->bpc_olevel, bpc->bpc_nlevel); 14470Sstevel@tonic-gate } 14480Sstevel@tonic-gate ret = pm_busop_bus_power(dip, impl_arg, 14490Sstevel@tonic-gate BUS_POWER_NEXUS_PWRUP, (void *)&bpn, 14500Sstevel@tonic-gate (void *)&pwrup_res); 14510Sstevel@tonic-gate 14520Sstevel@tonic-gate /* 14530Sstevel@tonic-gate * check the return status individually, 14540Sstevel@tonic-gate * idle parent and exit if either failed. 14550Sstevel@tonic-gate */ 14560Sstevel@tonic-gate if (ret != DDI_SUCCESS) { 14570Sstevel@tonic-gate cmn_err(CE_WARN, 14580Sstevel@tonic-gate "%s%d: pre_bus_power:" 14590Sstevel@tonic-gate " pm_busop_bus_power FAILED (ret) FOR" 14600Sstevel@tonic-gate " %s%d (%d->%d)", 14610Sstevel@tonic-gate name, instance, 14620Sstevel@tonic-gate ddi_node_name(bpc->bpc_dip), 14630Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip), 14640Sstevel@tonic-gate bpc->bpc_olevel, bpc->bpc_nlevel); 14650Sstevel@tonic-gate ret_failed = 1; 14660Sstevel@tonic-gate } 14670Sstevel@tonic-gate if (pwrup_res != DDI_SUCCESS) { 14680Sstevel@tonic-gate cmn_err(CE_WARN, 14690Sstevel@tonic-gate "%s%d: pre_bus_power:" 14700Sstevel@tonic-gate " pm_busop_bus_power FAILED (pwrup_res)" 14710Sstevel@tonic-gate " FOR %s%d (%d->%d)", 14720Sstevel@tonic-gate name, instance, 14730Sstevel@tonic-gate ddi_node_name(bpc->bpc_dip), 14740Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip), 14750Sstevel@tonic-gate bpc->bpc_olevel, bpc->bpc_nlevel); 14760Sstevel@tonic-gate pwrup_res_failed = 1; 14770Sstevel@tonic-gate } 14780Sstevel@tonic-gate if (ret_failed || pwrup_res_failed) { 14790Sstevel@tonic-gate /* 14800Sstevel@tonic-gate * decrement the busy count if it 14810Sstevel@tonic-gate * had been incremented. 14820Sstevel@tonic-gate */ 14830Sstevel@tonic-gate if ((bpc->bpc_comp == 0 && 14840Sstevel@tonic-gate bpc->bpc_nlevel == MAXPWR && 14850Sstevel@tonic-gate bpc->bpc_olevel <= 0) && 14860Sstevel@tonic-gate (pshot->state & PM_SUPPORTED)) { 14870Sstevel@tonic-gate mutex_enter(&pshot->lock); 14880Sstevel@tonic-gate ASSERT(pshot->busy > 0); 14890Sstevel@tonic-gate --(pshot->busy); 14900Sstevel@tonic-gate if (pshot_debug_busy) { 14910Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d:" 14920Sstevel@tonic-gate " pm_busop_bus_power" 14930Sstevel@tonic-gate " failed: idle parent for" 14940Sstevel@tonic-gate " %s%d (%d->%d):" 14950Sstevel@tonic-gate " busy = %d\n", 14960Sstevel@tonic-gate name, instance, 14970Sstevel@tonic-gate ddi_node_name( 14980Sstevel@tonic-gate bpc->bpc_dip), 14990Sstevel@tonic-gate ddi_get_instance( 15000Sstevel@tonic-gate bpc->bpc_dip), 15010Sstevel@tonic-gate bpc->bpc_olevel, 15020Sstevel@tonic-gate bpc->bpc_nlevel, 15030Sstevel@tonic-gate pshot->busy); 15040Sstevel@tonic-gate } 15050Sstevel@tonic-gate mutex_exit(&pshot->lock); 15060Sstevel@tonic-gate ret = pm_idle_component(dip, 0); 15070Sstevel@tonic-gate ASSERT(ret == DDI_SUCCESS); 15080Sstevel@tonic-gate } 15090Sstevel@tonic-gate return (DDI_FAILURE); 15100Sstevel@tonic-gate 15110Sstevel@tonic-gate } else { 15120Sstevel@tonic-gate if (pshot_debug) { 15130Sstevel@tonic-gate cmn_err(CE_CONT, 15140Sstevel@tonic-gate "%s%d: pre_bus_power:" 15150Sstevel@tonic-gate " pm_busop_bus_power on parent" 15160Sstevel@tonic-gate " for %s%d (%d->%d)\n", 15170Sstevel@tonic-gate name, instance, 15180Sstevel@tonic-gate ddi_node_name(bpc->bpc_dip), 15190Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip), 15200Sstevel@tonic-gate bpc->bpc_olevel, bpc->bpc_nlevel); 15210Sstevel@tonic-gate } 15220Sstevel@tonic-gate } 15230Sstevel@tonic-gate } 15240Sstevel@tonic-gate break; 15250Sstevel@tonic-gate 15260Sstevel@tonic-gate case BUS_POWER_POST_NOTIFICATION: 15270Sstevel@tonic-gate bpc = (pm_bp_child_pwrchg_t *)arg; 15280Sstevel@tonic-gate if (pshot_debug) { 15290Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: post_bus_power:" 15300Sstevel@tonic-gate " %s%d comp %d (%d->%d) result %d\n", 15310Sstevel@tonic-gate name, instance, ddi_node_name(bpc->bpc_dip), 15320Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip), 15330Sstevel@tonic-gate bpc->bpc_comp, bpc->bpc_olevel, 15340Sstevel@tonic-gate bpc->bpc_nlevel, *(int *)result); 15350Sstevel@tonic-gate } 15360Sstevel@tonic-gate 15370Sstevel@tonic-gate /* 15380Sstevel@tonic-gate * handle pm_busop_bus_power() failure case. 15390Sstevel@tonic-gate * mark parent idle if had been marked busy. 15400Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm) 15410Sstevel@tonic-gate */ 15420Sstevel@tonic-gate if (*(int *)result != DDI_SUCCESS) { 15430Sstevel@tonic-gate cmn_err(CE_WARN, 15440Sstevel@tonic-gate "pshot%d: post_bus_power_failed:" 15450Sstevel@tonic-gate " pm_busop_bus_power FAILED FOR %s%d (%d->%d)", 15460Sstevel@tonic-gate instance, ddi_node_name(bpc->bpc_dip), 15470Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip), 15480Sstevel@tonic-gate bpc->bpc_olevel, bpc->bpc_nlevel); 15490Sstevel@tonic-gate 15500Sstevel@tonic-gate if ((bpc->bpc_comp == 0 && bpc->bpc_nlevel == MAXPWR && 15510Sstevel@tonic-gate bpc->bpc_olevel <= 0) && 15520Sstevel@tonic-gate (pshot->state & PM_SUPPORTED)) { 15530Sstevel@tonic-gate mutex_enter(&pshot->lock); 15540Sstevel@tonic-gate ASSERT(pshot->busy > 0); 15550Sstevel@tonic-gate --(pshot->busy); 15560Sstevel@tonic-gate if (pshot_debug_busy) { 15570Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d:" 15580Sstevel@tonic-gate " post_bus_power_failed:" 15590Sstevel@tonic-gate " idle parent for %s%d" 15600Sstevel@tonic-gate " (%d->%d): busy = %d\n", 15610Sstevel@tonic-gate name, instance, 15620Sstevel@tonic-gate ddi_node_name(bpc->bpc_dip), 15630Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip), 15640Sstevel@tonic-gate bpc->bpc_olevel, bpc->bpc_nlevel, 15650Sstevel@tonic-gate pshot->busy); 15660Sstevel@tonic-gate } 15670Sstevel@tonic-gate mutex_exit(&pshot->lock); 15680Sstevel@tonic-gate ret = pm_idle_component(dip, 0); 15690Sstevel@tonic-gate ASSERT(ret == DDI_SUCCESS); 15700Sstevel@tonic-gate } 15710Sstevel@tonic-gate } 15720Sstevel@tonic-gate 15730Sstevel@tonic-gate /* 15740Sstevel@tonic-gate * Mark nexus idle when a child's comp 0 15750Sstevel@tonic-gate * is set to level 0 from level 1, 2, or 3 only. 15760Sstevel@tonic-gate * And only if result arg == DDI_SUCCESS. 15770Sstevel@tonic-gate * This will leave the parent busy when the child 15780Sstevel@tonic-gate * does not call pm_lower_power() on detach after 15790Sstevel@tonic-gate * unsetting the NO_LOWER_POWER flag. 15800Sstevel@tonic-gate * If so, need to notify the parent to mark itself 15810Sstevel@tonic-gate * idle anyway, else the no-involumtary-power-cycles 15820Sstevel@tonic-gate * test cases will report false passes! 15830Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm) 15840Sstevel@tonic-gate */ 15850Sstevel@tonic-gate if ((bpc->bpc_comp == 0 && bpc->bpc_nlevel == 0 && 15860Sstevel@tonic-gate !(bpc->bpc_olevel <= 0) && 15870Sstevel@tonic-gate *(int *)result == DDI_SUCCESS) && 15880Sstevel@tonic-gate (pshot->state & PM_SUPPORTED)) { 15890Sstevel@tonic-gate mutex_enter(&pshot->lock); 15900Sstevel@tonic-gate ASSERT(pshot->busy > 0); 15910Sstevel@tonic-gate --(pshot->busy); 15920Sstevel@tonic-gate if (pshot_debug_busy) { 15930Sstevel@tonic-gate cmn_err(CE_CONT, 15940Sstevel@tonic-gate "%s%d: post_bus_power:" 15950Sstevel@tonic-gate " idle parent for %s%d (%d->%d):" 15960Sstevel@tonic-gate " busy = %d\n", name, instance, 15970Sstevel@tonic-gate ddi_node_name(bpc->bpc_dip), 15980Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip), 15990Sstevel@tonic-gate bpc->bpc_olevel, bpc->bpc_nlevel, 16000Sstevel@tonic-gate pshot->busy); 16010Sstevel@tonic-gate } 16020Sstevel@tonic-gate mutex_exit(&pshot->lock); 16030Sstevel@tonic-gate ret = pm_idle_component(dip, 0); 16040Sstevel@tonic-gate ASSERT(ret == DDI_SUCCESS); 16050Sstevel@tonic-gate } 16060Sstevel@tonic-gate break; 16070Sstevel@tonic-gate 16080Sstevel@tonic-gate case BUS_POWER_HAS_CHANGED: 16090Sstevel@tonic-gate bphc = (pm_bp_has_changed_t *)arg; 16100Sstevel@tonic-gate if (pshot_debug) { 16110Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: has_changed_bus_power:" 16120Sstevel@tonic-gate " %s%d comp %d (%d->%d) result %d\n", 16130Sstevel@tonic-gate name, instance, ddi_node_name(bphc->bphc_dip), 16140Sstevel@tonic-gate ddi_get_instance(bphc->bphc_dip), 16150Sstevel@tonic-gate bphc->bphc_comp, bphc->bphc_olevel, 16160Sstevel@tonic-gate bphc->bphc_nlevel, *(int *)result); 16170Sstevel@tonic-gate } 16180Sstevel@tonic-gate 16190Sstevel@tonic-gate /* 16200Sstevel@tonic-gate * Mark nexus idle when a child's comp 0 16210Sstevel@tonic-gate * is set to level 0 from levels 1, 2, or 3 only. 16220Sstevel@tonic-gate * 16230Sstevel@tonic-gate * If powering up child leaf/nexus nodes via 16240Sstevel@tonic-gate * pm_power_has_changed() calls, first issue 16250Sstevel@tonic-gate * DEVCTL_PM_BUSY_COMP ioctl to mark parent busy 16260Sstevel@tonic-gate * before powering the parent up, then power up the 16270Sstevel@tonic-gate * child node. 16280Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm) 16290Sstevel@tonic-gate */ 16300Sstevel@tonic-gate if ((bphc->bphc_comp == 0 && bphc->bphc_nlevel == 0 && 16310Sstevel@tonic-gate !(bphc->bphc_olevel <= 0)) && 16320Sstevel@tonic-gate pshot->state & PM_SUPPORTED) { 16330Sstevel@tonic-gate mutex_enter(&pshot->lock); 16340Sstevel@tonic-gate ASSERT(pshot->busy > 0); 16350Sstevel@tonic-gate --(pshot->busy); 16360Sstevel@tonic-gate if (pshot_debug_busy) { 16370Sstevel@tonic-gate cmn_err(CE_CONT, 16380Sstevel@tonic-gate "%s%d: has_changed_bus_power:" 16390Sstevel@tonic-gate " idle parent for %s%d (%d->%d):" 16400Sstevel@tonic-gate " busy = %d\n", name, instance, 16410Sstevel@tonic-gate ddi_node_name(bphc->bphc_dip), 16420Sstevel@tonic-gate ddi_get_instance(bphc->bphc_dip), 16430Sstevel@tonic-gate bphc->bphc_olevel, 16440Sstevel@tonic-gate bphc->bphc_nlevel, pshot->busy); 16450Sstevel@tonic-gate } 16460Sstevel@tonic-gate mutex_exit(&pshot->lock); 16470Sstevel@tonic-gate ret = pm_idle_component(dip, 0); 16480Sstevel@tonic-gate ASSERT(ret == DDI_SUCCESS); 16490Sstevel@tonic-gate } 16500Sstevel@tonic-gate break; 16510Sstevel@tonic-gate 16520Sstevel@tonic-gate default: 16530Sstevel@tonic-gate return (pm_busop_bus_power(dip, impl_arg, op, arg, result)); 16540Sstevel@tonic-gate 16550Sstevel@tonic-gate } 16560Sstevel@tonic-gate 16570Sstevel@tonic-gate return (DDI_SUCCESS); 16580Sstevel@tonic-gate } 16590Sstevel@tonic-gate 16600Sstevel@tonic-gate static int 16610Sstevel@tonic-gate pshot_initchild(dev_info_t *dip, dev_info_t *child) 16620Sstevel@tonic-gate { 16630Sstevel@tonic-gate char name[64]; 16640Sstevel@tonic-gate char *bus_addr; 16650Sstevel@tonic-gate char *c_nodename; 16660Sstevel@tonic-gate int bus_id; 16670Sstevel@tonic-gate dev_info_t *enum_child; 16680Sstevel@tonic-gate int enum_base; 16690Sstevel@tonic-gate int enum_extent; 16700Sstevel@tonic-gate 16710Sstevel@tonic-gate 16720Sstevel@tonic-gate /* check for bus_enum node */ 16730Sstevel@tonic-gate 16740Sstevel@tonic-gate #ifdef NOT_USED 16750Sstevel@tonic-gate if (impl_ddi_merge_child(child) != DDI_SUCCESS) 16760Sstevel@tonic-gate return (DDI_FAILURE); 16770Sstevel@tonic-gate #endif 16780Sstevel@tonic-gate 16790Sstevel@tonic-gate enum_base = ddi_prop_get_int(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS, 16800Sstevel@tonic-gate "busid_ebase", 0); 16810Sstevel@tonic-gate 16820Sstevel@tonic-gate enum_extent = ddi_prop_get_int(DDI_DEV_T_ANY, child, 16830Sstevel@tonic-gate DDI_PROP_DONTPASS, "busid_range", 0); 16840Sstevel@tonic-gate 16850Sstevel@tonic-gate /* 16860Sstevel@tonic-gate * bus enumeration node 16870Sstevel@tonic-gate */ 16880Sstevel@tonic-gate if ((enum_base != 0) && (enum_extent != 0)) { 16890Sstevel@tonic-gate c_nodename = ddi_node_name(child); 16900Sstevel@tonic-gate bus_id = enum_base; 16910Sstevel@tonic-gate for (; bus_id < enum_extent; bus_id++) { 16920Sstevel@tonic-gate if (ndi_devi_alloc(dip, c_nodename, DEVI_PSEUDO_NODEID, 16930Sstevel@tonic-gate &enum_child) != NDI_SUCCESS) 16940Sstevel@tonic-gate return (DDI_FAILURE); 16950Sstevel@tonic-gate 16960Sstevel@tonic-gate (void) sprintf(name, "%d", bus_id); 16970Sstevel@tonic-gate if (ndi_prop_update_string(DDI_DEV_T_NONE, enum_child, 16980Sstevel@tonic-gate "bus-addr", name) != DDI_PROP_SUCCESS) { 16990Sstevel@tonic-gate (void) ndi_devi_free(enum_child); 17000Sstevel@tonic-gate return (DDI_FAILURE); 17010Sstevel@tonic-gate } 17020Sstevel@tonic-gate 17030Sstevel@tonic-gate if (ndi_devi_online(enum_child, 0) != 17040Sstevel@tonic-gate DDI_SUCCESS) { 17050Sstevel@tonic-gate (void) ndi_devi_free(enum_child); 17060Sstevel@tonic-gate return (DDI_FAILURE); 17070Sstevel@tonic-gate } 17080Sstevel@tonic-gate } 17090Sstevel@tonic-gate /* 17100Sstevel@tonic-gate * fail the enumeration node itself 17110Sstevel@tonic-gate */ 17120Sstevel@tonic-gate return (DDI_FAILURE); 17130Sstevel@tonic-gate } 17140Sstevel@tonic-gate 17150Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, child, 0, "bus-addr", 17160Sstevel@tonic-gate &bus_addr) != DDI_PROP_SUCCESS) { 17170Sstevel@tonic-gate cmn_err(CE_WARN, "pshot_initchild: bus-addr not defined (%s)", 17180Sstevel@tonic-gate ddi_node_name(child)); 17190Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED); 17200Sstevel@tonic-gate } 17210Sstevel@tonic-gate 17220Sstevel@tonic-gate if (strlen(bus_addr) == 0) { 17230Sstevel@tonic-gate cmn_err(CE_WARN, "pshot_initchild: NULL bus-addr (%s)", 17240Sstevel@tonic-gate ddi_node_name(child)); 17250Sstevel@tonic-gate ddi_prop_free(bus_addr); 17260Sstevel@tonic-gate return (DDI_FAILURE); 17270Sstevel@tonic-gate } 17280Sstevel@tonic-gate 17290Sstevel@tonic-gate if (strncmp(bus_addr, "failinit", 8) == 0) { 17300Sstevel@tonic-gate if (pshot_debug) 17310Sstevel@tonic-gate cmn_err(CE_CONT, 17320Sstevel@tonic-gate "pshot%d: %s forced INITCHILD failure\n", 17337656SSherry.Moore@Sun.COM ddi_get_instance(dip), bus_addr); 17340Sstevel@tonic-gate ddi_prop_free(bus_addr); 17350Sstevel@tonic-gate return (DDI_FAILURE); 17360Sstevel@tonic-gate } 17370Sstevel@tonic-gate 17380Sstevel@tonic-gate if (pshot_log) { 17390Sstevel@tonic-gate cmn_err(CE_CONT, "initchild %s%d/%s@%s\n", 17407656SSherry.Moore@Sun.COM ddi_get_name(dip), ddi_get_instance(dip), 17417656SSherry.Moore@Sun.COM ddi_node_name(child), bus_addr); 17420Sstevel@tonic-gate } 17430Sstevel@tonic-gate 17440Sstevel@tonic-gate ddi_set_name_addr(child, bus_addr); 17450Sstevel@tonic-gate ddi_prop_free(bus_addr); 17460Sstevel@tonic-gate return (DDI_SUCCESS); 17470Sstevel@tonic-gate } 17480Sstevel@tonic-gate 17490Sstevel@tonic-gate /*ARGSUSED*/ 17500Sstevel@tonic-gate static int 17510Sstevel@tonic-gate pshot_uninitchild(dev_info_t *dip, dev_info_t *child) 17520Sstevel@tonic-gate { 17530Sstevel@tonic-gate ddi_set_name_addr(child, NULL); 17540Sstevel@tonic-gate return (DDI_SUCCESS); 17550Sstevel@tonic-gate } 17560Sstevel@tonic-gate 17570Sstevel@tonic-gate 17580Sstevel@tonic-gate /* 17590Sstevel@tonic-gate * devctl IOCTL support 17600Sstevel@tonic-gate */ 17610Sstevel@tonic-gate /* ARGSUSED */ 17620Sstevel@tonic-gate static int 17630Sstevel@tonic-gate pshot_open(dev_t *devp, int flags, int otyp, cred_t *credp) 17640Sstevel@tonic-gate { 17650Sstevel@tonic-gate int instance; 17660Sstevel@tonic-gate pshot_t *pshot; 17670Sstevel@tonic-gate 17680Sstevel@tonic-gate if (otyp != OTYP_CHR) 17690Sstevel@tonic-gate return (EINVAL); 17700Sstevel@tonic-gate 17710Sstevel@tonic-gate instance = pshot_minor_decode_inst(getminor(*devp)); 17720Sstevel@tonic-gate if ((pshot = ddi_get_soft_state(pshot_softstatep, instance)) == NULL) 17730Sstevel@tonic-gate return (ENXIO); 17740Sstevel@tonic-gate 17750Sstevel@tonic-gate /* 17760Sstevel@tonic-gate * Access is currently determined on a per-instance basis. 17770Sstevel@tonic-gate * If we want per-node, then need to add state and lock members to 17780Sstevel@tonic-gate * pshot_minor_t 17790Sstevel@tonic-gate */ 17800Sstevel@tonic-gate mutex_enter(&pshot->lock); 17810Sstevel@tonic-gate if (((flags & FEXCL) && (pshot->state & IS_OPEN)) || 17820Sstevel@tonic-gate (!(flags & FEXCL) && (pshot->state & IS_OPEN_EXCL))) { 17830Sstevel@tonic-gate mutex_exit(&pshot->lock); 17840Sstevel@tonic-gate return (EBUSY); 17850Sstevel@tonic-gate } 17860Sstevel@tonic-gate pshot->state |= IS_OPEN; 17870Sstevel@tonic-gate if (flags & FEXCL) 17880Sstevel@tonic-gate pshot->state |= IS_OPEN_EXCL; 17890Sstevel@tonic-gate 17900Sstevel@tonic-gate if (pshot_debug) 17910Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d open\n", instance); 17920Sstevel@tonic-gate 17930Sstevel@tonic-gate mutex_exit(&pshot->lock); 17940Sstevel@tonic-gate return (0); 17950Sstevel@tonic-gate } 17960Sstevel@tonic-gate 17970Sstevel@tonic-gate /* 17980Sstevel@tonic-gate * pshot_close 17990Sstevel@tonic-gate */ 18000Sstevel@tonic-gate /* ARGSUSED */ 18010Sstevel@tonic-gate static int 18020Sstevel@tonic-gate pshot_close(dev_t dev, int flag, int otyp, cred_t *credp) 18030Sstevel@tonic-gate { 18040Sstevel@tonic-gate int instance; 18050Sstevel@tonic-gate pshot_t *pshot; 18060Sstevel@tonic-gate 18070Sstevel@tonic-gate if (otyp != OTYP_CHR) 18080Sstevel@tonic-gate return (EINVAL); 18090Sstevel@tonic-gate 18100Sstevel@tonic-gate instance = pshot_minor_decode_inst(getminor(dev)); 18110Sstevel@tonic-gate if ((pshot = ddi_get_soft_state(pshot_softstatep, instance)) == NULL) 18120Sstevel@tonic-gate return (ENXIO); 18130Sstevel@tonic-gate 18140Sstevel@tonic-gate mutex_enter(&pshot->lock); 18150Sstevel@tonic-gate pshot->state &= ~(IS_OPEN | IS_OPEN_EXCL); 18160Sstevel@tonic-gate mutex_exit(&pshot->lock); 18170Sstevel@tonic-gate if (pshot_debug) 18180Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d closed\n", instance); 18190Sstevel@tonic-gate return (0); 18200Sstevel@tonic-gate } 18210Sstevel@tonic-gate 18220Sstevel@tonic-gate 18230Sstevel@tonic-gate /* 18240Sstevel@tonic-gate * pshot_ioctl: redirects to appropriate command handler based on various 18250Sstevel@tonic-gate * criteria 18260Sstevel@tonic-gate */ 18270Sstevel@tonic-gate /* ARGSUSED */ 18280Sstevel@tonic-gate static int 18290Sstevel@tonic-gate pshot_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp, 18300Sstevel@tonic-gate int *rvalp) 18310Sstevel@tonic-gate { 18320Sstevel@tonic-gate pshot_t *pshot; 18330Sstevel@tonic-gate int instance; 18340Sstevel@tonic-gate minor_t nodenum; 18350Sstevel@tonic-gate char *nodename; 18360Sstevel@tonic-gate 18370Sstevel@tonic-gate instance = pshot_minor_decode_inst(getminor(dev)); 18380Sstevel@tonic-gate if ((pshot = ddi_get_soft_state(pshot_softstatep, instance)) == NULL) 18390Sstevel@tonic-gate return (ENXIO); 18400Sstevel@tonic-gate 18410Sstevel@tonic-gate nodenum = pshot_minor_decode_nodenum(getminor(dev)); 18420Sstevel@tonic-gate nodename = pshot->nodes[nodenum].name; 18430Sstevel@tonic-gate 18440Sstevel@tonic-gate if (pshot_debug) 18450Sstevel@tonic-gate cmn_err(CE_CONT, 18460Sstevel@tonic-gate "pshot%d ioctl: dev=%p, cmd=%x, arg=%p, mode=%x\n", 18470Sstevel@tonic-gate instance, (void *)dev, cmd, (void *)arg, mode); 18480Sstevel@tonic-gate 18490Sstevel@tonic-gate if (strcmp(nodename, PSHOT_NODENAME_DEVCTL) == 0) 18500Sstevel@tonic-gate return (pshot_devctl(pshot, nodenum, cmd, arg, mode, credp, 18510Sstevel@tonic-gate rvalp)); 18520Sstevel@tonic-gate 18530Sstevel@tonic-gate if (strcmp(nodename, PSHOT_NODENAME_TESTCTL) == 0) 18540Sstevel@tonic-gate return (pshot_testctl(pshot, nodenum, cmd, arg, mode, credp, 18550Sstevel@tonic-gate rvalp)); 18560Sstevel@tonic-gate 18570Sstevel@tonic-gate cmn_err(CE_WARN, "pshot_ioctl: unmatched nodename on minor %u", 18580Sstevel@tonic-gate pshot->nodes[nodenum].minor); 18590Sstevel@tonic-gate return (ENXIO); 18600Sstevel@tonic-gate } 18610Sstevel@tonic-gate 18620Sstevel@tonic-gate 18630Sstevel@tonic-gate /* 18640Sstevel@tonic-gate * pshot_devctl: handle DEVCTL operations 18650Sstevel@tonic-gate */ 18660Sstevel@tonic-gate /* ARGSUSED */ 18670Sstevel@tonic-gate static int 18680Sstevel@tonic-gate pshot_devctl(pshot_t *pshot, minor_t nodenum, int cmd, intptr_t arg, int mode, 18690Sstevel@tonic-gate cred_t *credp, int *rvalp) 18700Sstevel@tonic-gate { 18710Sstevel@tonic-gate dev_info_t *self; 18720Sstevel@tonic-gate dev_info_t *child = NULL; 18730Sstevel@tonic-gate struct devctl_iocdata *dcp; 18740Sstevel@tonic-gate uint_t state; 18750Sstevel@tonic-gate int rv = 0; 18760Sstevel@tonic-gate uint_t flags; 18770Sstevel@tonic-gate int instance; 18780Sstevel@tonic-gate int i; 18790Sstevel@tonic-gate int ret; 18800Sstevel@tonic-gate 18810Sstevel@tonic-gate self = pshot->dip; 18820Sstevel@tonic-gate 18830Sstevel@tonic-gate flags = (pshot_devctl_debug) ? NDI_DEVI_DEBUG : 0; 18840Sstevel@tonic-gate instance = pshot->instance; 18850Sstevel@tonic-gate 18860Sstevel@tonic-gate /* 18870Sstevel@tonic-gate * We can use the generic implementation for these ioctls 18880Sstevel@tonic-gate */ 18890Sstevel@tonic-gate for (i = 0; pshot_devctls[i].ioctl_int != 0; i++) { 18900Sstevel@tonic-gate if (pshot_devctls[i].ioctl_int == cmd) { 18910Sstevel@tonic-gate if (pshot_debug) 18920Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl: %s", 18930Sstevel@tonic-gate instance, pshot_devctls[i].ioctl_char); 18940Sstevel@tonic-gate } 18950Sstevel@tonic-gate } 18960Sstevel@tonic-gate switch (cmd) { 18970Sstevel@tonic-gate case DEVCTL_DEVICE_GETSTATE: 18980Sstevel@tonic-gate case DEVCTL_DEVICE_ONLINE: 18990Sstevel@tonic-gate case DEVCTL_DEVICE_OFFLINE: 19000Sstevel@tonic-gate case DEVCTL_DEVICE_REMOVE: 19010Sstevel@tonic-gate case DEVCTL_BUS_GETSTATE: 19020Sstevel@tonic-gate case DEVCTL_BUS_DEV_CREATE: 19030Sstevel@tonic-gate rv = ndi_devctl_ioctl(self, cmd, arg, mode, flags); 19040Sstevel@tonic-gate if (pshot_debug && rv != 0) { 19050Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d ndi_devctl_ioctl:" 19060Sstevel@tonic-gate " failed, rv = %d", instance, rv); 19070Sstevel@tonic-gate } 19080Sstevel@tonic-gate 19090Sstevel@tonic-gate return (rv); 19100Sstevel@tonic-gate } 19110Sstevel@tonic-gate 19120Sstevel@tonic-gate /* 19130Sstevel@tonic-gate * read devctl ioctl data 19140Sstevel@tonic-gate */ 19150Sstevel@tonic-gate if (ndi_dc_allochdl((void *)arg, &dcp) != NDI_SUCCESS) 19160Sstevel@tonic-gate return (EFAULT); 19170Sstevel@tonic-gate 19180Sstevel@tonic-gate switch (cmd) { 19190Sstevel@tonic-gate 19200Sstevel@tonic-gate case DEVCTL_DEVICE_RESET: 19210Sstevel@tonic-gate if (pshot_debug) 19220Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:" 19230Sstevel@tonic-gate " DEVCTL_DEVICE_RESET\n", instance); 19240Sstevel@tonic-gate rv = pshot_event(pshot, PSHOT_EVENT_TAG_DEV_RESET, 19250Sstevel@tonic-gate child, (void *)self); 19260Sstevel@tonic-gate ASSERT(rv == NDI_SUCCESS); 19270Sstevel@tonic-gate break; 19280Sstevel@tonic-gate 19290Sstevel@tonic-gate case DEVCTL_BUS_QUIESCE: 19300Sstevel@tonic-gate if (pshot_debug) 19310Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:" 19320Sstevel@tonic-gate " DEVCTL_BUS_QUIESCE\n", instance); 19330Sstevel@tonic-gate if (ndi_get_bus_state(self, &state) == NDI_SUCCESS) { 19340Sstevel@tonic-gate if (state == BUS_QUIESCED) { 19350Sstevel@tonic-gate break; 19360Sstevel@tonic-gate } 19370Sstevel@tonic-gate (void) ndi_set_bus_state(self, BUS_QUIESCED); 19380Sstevel@tonic-gate } 19390Sstevel@tonic-gate rv = pshot_event(pshot, PSHOT_EVENT_TAG_BUS_QUIESCE, 19400Sstevel@tonic-gate child, (void *)self); 19410Sstevel@tonic-gate ASSERT(rv == NDI_SUCCESS); 19420Sstevel@tonic-gate 19430Sstevel@tonic-gate break; 19440Sstevel@tonic-gate 19450Sstevel@tonic-gate case DEVCTL_BUS_UNQUIESCE: 19460Sstevel@tonic-gate if (pshot_debug) 19470Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:" 19480Sstevel@tonic-gate " DEVCTL_BUS_UNQUIESCE\n", instance); 19490Sstevel@tonic-gate if (ndi_get_bus_state(self, &state) == NDI_SUCCESS) { 19500Sstevel@tonic-gate if (state == BUS_ACTIVE) { 19510Sstevel@tonic-gate break; 19520Sstevel@tonic-gate } 19530Sstevel@tonic-gate } 19540Sstevel@tonic-gate 19550Sstevel@tonic-gate /* 19560Sstevel@tonic-gate * quiesce the bus through bus-specific means 19570Sstevel@tonic-gate */ 19580Sstevel@tonic-gate (void) ndi_set_bus_state(self, BUS_ACTIVE); 19590Sstevel@tonic-gate rv = pshot_event(pshot, PSHOT_EVENT_TAG_BUS_UNQUIESCE, 19600Sstevel@tonic-gate child, (void *)self); 19610Sstevel@tonic-gate ASSERT(rv == NDI_SUCCESS); 19620Sstevel@tonic-gate break; 19630Sstevel@tonic-gate 19640Sstevel@tonic-gate case DEVCTL_BUS_RESET: 19650Sstevel@tonic-gate case DEVCTL_BUS_RESETALL: 19660Sstevel@tonic-gate /* 19670Sstevel@tonic-gate * no reset support for the pseudo bus 19680Sstevel@tonic-gate * but if there were.... 19690Sstevel@tonic-gate */ 19700Sstevel@tonic-gate rv = pshot_event(pshot, PSHOT_EVENT_TAG_BUS_RESET, 19717656SSherry.Moore@Sun.COM child, (void *)self); 19720Sstevel@tonic-gate ASSERT(rv == NDI_SUCCESS); 19730Sstevel@tonic-gate break; 19740Sstevel@tonic-gate 19750Sstevel@tonic-gate /* 19760Sstevel@tonic-gate * PM related ioctls 19770Sstevel@tonic-gate */ 19780Sstevel@tonic-gate case DEVCTL_PM_BUSY_COMP: 19790Sstevel@tonic-gate /* 19800Sstevel@tonic-gate * mark component 0 busy. 19810Sstevel@tonic-gate * Keep track of ioctl updates to the busy count 19820Sstevel@tonic-gate * via pshot->busy_ioctl. 19830Sstevel@tonic-gate */ 19840Sstevel@tonic-gate if (pshot_debug) { 19850Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:" 19860Sstevel@tonic-gate " DEVCTL_PM_BUSY_COMP\n", instance); 19870Sstevel@tonic-gate } 19880Sstevel@tonic-gate mutex_enter(&pshot->lock); 19890Sstevel@tonic-gate ++(pshot->busy); 19900Sstevel@tonic-gate ++(pshot->busy_ioctl); 19910Sstevel@tonic-gate if (pshot_debug_busy) { 19920Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:" 19930Sstevel@tonic-gate " DEVCTL_PM_BUSY_COMP comp 0 busy" 19940Sstevel@tonic-gate " %d busy_ioctl %d\n", instance, pshot->busy, 19950Sstevel@tonic-gate pshot->busy_ioctl); 19960Sstevel@tonic-gate } 19970Sstevel@tonic-gate mutex_exit(&pshot->lock); 19980Sstevel@tonic-gate ret = pm_busy_component(pshot->dip, 0); 19990Sstevel@tonic-gate ASSERT(ret == DDI_SUCCESS); 20000Sstevel@tonic-gate 20010Sstevel@tonic-gate break; 20020Sstevel@tonic-gate 20030Sstevel@tonic-gate case DEVCTL_PM_BUSY_COMP_TEST: 20040Sstevel@tonic-gate /* 20050Sstevel@tonic-gate * test bus's busy state 20060Sstevel@tonic-gate */ 20070Sstevel@tonic-gate if (pshot_debug) { 20080Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:" 20090Sstevel@tonic-gate " DEVCTL_PM_BUSY_COMP_TEST\n", instance); 20100Sstevel@tonic-gate } 20110Sstevel@tonic-gate mutex_enter(&pshot->lock); 20120Sstevel@tonic-gate state = pshot->busy; 20130Sstevel@tonic-gate if (copyout(&state, dcp->cpyout_buf, 20140Sstevel@tonic-gate sizeof (uint_t)) != 0) { 20150Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d devctl:" 20160Sstevel@tonic-gate " DEVCTL_PM_BUSY_COMP_TEST: copyout failed", 20170Sstevel@tonic-gate instance); 20180Sstevel@tonic-gate rv = EINVAL; 20190Sstevel@tonic-gate } 20200Sstevel@tonic-gate if (pshot_debug_busy) { 20210Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DEVCTL_PM_BUSY_COMP_TEST:" 20220Sstevel@tonic-gate " comp 0 busy %d busy_ioctl %d\n", instance, 20230Sstevel@tonic-gate state, pshot->busy_ioctl); 20240Sstevel@tonic-gate } 20250Sstevel@tonic-gate mutex_exit(&pshot->lock); 20260Sstevel@tonic-gate break; 20270Sstevel@tonic-gate 20280Sstevel@tonic-gate case DEVCTL_PM_IDLE_COMP: 20290Sstevel@tonic-gate /* 20300Sstevel@tonic-gate * mark component 0 idle. 20310Sstevel@tonic-gate * NOP if pshot->busy_ioctl <= 0. 20320Sstevel@tonic-gate */ 20330Sstevel@tonic-gate if (pshot_debug) { 20340Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:" 20350Sstevel@tonic-gate " DEVCTL_PM_IDLE_COMP\n", instance); 20360Sstevel@tonic-gate } 20370Sstevel@tonic-gate mutex_enter(&pshot->lock); 20380Sstevel@tonic-gate if (pshot->busy_ioctl > 0) { 20390Sstevel@tonic-gate ASSERT(pshot->busy > 0); 20400Sstevel@tonic-gate --(pshot->busy); 20410Sstevel@tonic-gate --(pshot->busy_ioctl); 20420Sstevel@tonic-gate if (pshot_debug_busy) { 20430Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:" 20440Sstevel@tonic-gate " DEVCTL_PM_IDLE_COM: comp 0" 20450Sstevel@tonic-gate " busy %d busy_ioctl %d\n", instance, 20460Sstevel@tonic-gate pshot->busy, pshot->busy_ioctl); 20470Sstevel@tonic-gate } 20480Sstevel@tonic-gate mutex_exit(&pshot->lock); 20490Sstevel@tonic-gate ret = pm_idle_component(pshot->dip, 0); 20500Sstevel@tonic-gate ASSERT(ret == DDI_SUCCESS); 20510Sstevel@tonic-gate 20520Sstevel@tonic-gate } else { 20530Sstevel@tonic-gate mutex_exit(&pshot->lock); 20540Sstevel@tonic-gate } 20550Sstevel@tonic-gate break; 20560Sstevel@tonic-gate 20570Sstevel@tonic-gate case DEVCTL_PM_RAISE_PWR: 20580Sstevel@tonic-gate /* 20590Sstevel@tonic-gate * raise component 0 to full power level MAXPWR via a 20600Sstevel@tonic-gate * pm_raise_power() call 20610Sstevel@tonic-gate */ 20620Sstevel@tonic-gate if (pshot_debug) { 20630Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:" 20640Sstevel@tonic-gate " DEVCTL_PM_RAISE_PWR\n", instance); 20650Sstevel@tonic-gate } 20660Sstevel@tonic-gate if (pm_raise_power(pshot->dip, 0, MAXPWR) != DDI_SUCCESS) { 20670Sstevel@tonic-gate rv = EINVAL; 20680Sstevel@tonic-gate } else { 20690Sstevel@tonic-gate mutex_enter(&pshot->lock); 20700Sstevel@tonic-gate if (pshot_debug) { 20710Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:" 20720Sstevel@tonic-gate " DEVCTL_PM_RAISE_POWER: comp 0" 20730Sstevel@tonic-gate " to level %d\n", instance, pshot->level); 20740Sstevel@tonic-gate } 20750Sstevel@tonic-gate mutex_exit(&pshot->lock); 20760Sstevel@tonic-gate } 20770Sstevel@tonic-gate break; 20780Sstevel@tonic-gate 20790Sstevel@tonic-gate case DEVCTL_PM_LOWER_PWR: 20800Sstevel@tonic-gate /* 20810Sstevel@tonic-gate * pm_lower_power() call for negative testing 20820Sstevel@tonic-gate * expected to fail. 20830Sstevel@tonic-gate */ 20840Sstevel@tonic-gate if (pshot_debug) { 20850Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:" 20860Sstevel@tonic-gate " DEVCTL_PM_LOWER_PWR\n", instance); 20870Sstevel@tonic-gate } 20880Sstevel@tonic-gate if (pm_lower_power(pshot->dip, 0, 0) != DDI_SUCCESS) { 20890Sstevel@tonic-gate rv = EINVAL; 20900Sstevel@tonic-gate } else { 20910Sstevel@tonic-gate mutex_enter(&pshot->lock); 20920Sstevel@tonic-gate if (pshot_debug) { 20930Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:" 20940Sstevel@tonic-gate " DEVCTL_PM_LOWER_POWER comp 0" 20950Sstevel@tonic-gate " to level %d\n", instance, pshot->level); 20960Sstevel@tonic-gate } 20970Sstevel@tonic-gate mutex_exit(&pshot->lock); 20980Sstevel@tonic-gate } 20990Sstevel@tonic-gate break; 21000Sstevel@tonic-gate 21010Sstevel@tonic-gate case DEVCTL_PM_CHANGE_PWR_LOW: 21020Sstevel@tonic-gate /* 21030Sstevel@tonic-gate * inform the PM framework that component 0 has changed 21040Sstevel@tonic-gate * power level to 0 via a pm_power_has_changed() call 21050Sstevel@tonic-gate */ 21060Sstevel@tonic-gate if (pshot_debug) { 21070Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:" 21080Sstevel@tonic-gate " DEVCTL_PM_CHANGE_PWR_LOW\n", instance); 21090Sstevel@tonic-gate } 21100Sstevel@tonic-gate mutex_enter(&pshot->lock); 21110Sstevel@tonic-gate pshot->level = 0; 21120Sstevel@tonic-gate if (pm_power_has_changed(pshot->dip, 0, 0) != DDI_SUCCESS) { 21130Sstevel@tonic-gate rv = EINVAL; 21140Sstevel@tonic-gate } else { 21150Sstevel@tonic-gate if (pshot_debug) { 21160Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:" 21170Sstevel@tonic-gate " DEVCTL_PM_CHANGE_PWR_LOW comp 0 to" 21180Sstevel@tonic-gate " level %d\n", instance, pshot->level); 21190Sstevel@tonic-gate } 21200Sstevel@tonic-gate } 21210Sstevel@tonic-gate mutex_exit(&pshot->lock); 21220Sstevel@tonic-gate break; 21230Sstevel@tonic-gate 21240Sstevel@tonic-gate case DEVCTL_PM_CHANGE_PWR_HIGH: 21250Sstevel@tonic-gate /* 21260Sstevel@tonic-gate * inform the PM framework that component 0 has changed 21270Sstevel@tonic-gate * power level to MAXPWR via a pm_power_has_changed() call 21280Sstevel@tonic-gate */ 21290Sstevel@tonic-gate if (pshot_debug) { 21300Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:" 21310Sstevel@tonic-gate " DEVCTL_PM_CHANGE_PWR_HIGH\n", instance); 21320Sstevel@tonic-gate } 21330Sstevel@tonic-gate mutex_enter(&pshot->lock); 21340Sstevel@tonic-gate pshot->level = MAXPWR; 21350Sstevel@tonic-gate if (pm_power_has_changed(pshot->dip, 0, MAXPWR) 21360Sstevel@tonic-gate != DDI_SUCCESS) { 21370Sstevel@tonic-gate rv = EINVAL; 21380Sstevel@tonic-gate } else { 21390Sstevel@tonic-gate if (pshot_debug) { 21400Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:" 21410Sstevel@tonic-gate " DEVCTL_PM_CHANGE_PWR_HIGH comp 0 to" 21420Sstevel@tonic-gate " level %d\n", instance, pshot->level); 21430Sstevel@tonic-gate } 21440Sstevel@tonic-gate } 21450Sstevel@tonic-gate mutex_exit(&pshot->lock); 21460Sstevel@tonic-gate break; 21470Sstevel@tonic-gate 21480Sstevel@tonic-gate case DEVCTL_PM_POWER: 21490Sstevel@tonic-gate /* 21500Sstevel@tonic-gate * test if the pshot_power() routine has been called, 21510Sstevel@tonic-gate * then clear 21520Sstevel@tonic-gate */ 21530Sstevel@tonic-gate if (pshot_debug) { 21540Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:" 21550Sstevel@tonic-gate " DEVCTL_PM_POWER\n", instance); 21560Sstevel@tonic-gate } 21570Sstevel@tonic-gate mutex_enter(&pshot->lock); 21580Sstevel@tonic-gate state = (pshot->state & POWER_FLAG) ? 1 : 0; 21590Sstevel@tonic-gate if (copyout(&state, dcp->cpyout_buf, 21600Sstevel@tonic-gate sizeof (uint_t)) != 0) { 21610Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d devctl:" 21620Sstevel@tonic-gate " DEVCTL_PM_POWER: copyout failed", 21630Sstevel@tonic-gate instance); 21640Sstevel@tonic-gate rv = EINVAL; 21650Sstevel@tonic-gate } 21660Sstevel@tonic-gate if (pshot_debug) { 21670Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DEVCTL_PM_POWER:" 21680Sstevel@tonic-gate " POWER_FLAG = %d\n", instance, state); 21690Sstevel@tonic-gate } 21700Sstevel@tonic-gate pshot->state &= ~POWER_FLAG; 21710Sstevel@tonic-gate mutex_exit(&pshot->lock); 21720Sstevel@tonic-gate break; 21730Sstevel@tonic-gate 21740Sstevel@tonic-gate case DEVCTL_PM_FAIL_SUSPEND: 21750Sstevel@tonic-gate /* 21760Sstevel@tonic-gate * fail DDI_SUSPEND 21770Sstevel@tonic-gate */ 21780Sstevel@tonic-gate if (pshot_debug) { 21790Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:" 21800Sstevel@tonic-gate " DEVCTL_PM_FAIL_SUSPEND\n", instance); 21810Sstevel@tonic-gate } 21820Sstevel@tonic-gate mutex_enter(&pshot->lock); 21830Sstevel@tonic-gate pshot->state |= FAIL_SUSPEND_FLAG; 21840Sstevel@tonic-gate mutex_exit(&pshot->lock); 21850Sstevel@tonic-gate if (pshot_debug) { 21860Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DEVCTL_PM_FAIL_SUSPEND\n", 21870Sstevel@tonic-gate instance); 21880Sstevel@tonic-gate } 21890Sstevel@tonic-gate break; 21900Sstevel@tonic-gate 21910Sstevel@tonic-gate case DEVCTL_PM_BUS_STRICT_TEST: 21920Sstevel@tonic-gate /* 21930Sstevel@tonic-gate * test the STRICT_PARENT flag: 21940Sstevel@tonic-gate * set => STRICT PARENT 21950Sstevel@tonic-gate * not set => INVOLVED PARENT 21960Sstevel@tonic-gate */ 21970Sstevel@tonic-gate mutex_enter(&pshot->lock); 21980Sstevel@tonic-gate state = (pshot->state & STRICT_PARENT) ? 1 : 0; 21990Sstevel@tonic-gate if (copyout(&state, dcp->cpyout_buf, 22000Sstevel@tonic-gate sizeof (uint_t)) != 0) { 22010Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d devctl:" 22020Sstevel@tonic-gate " DEVCTL_PM_BUS_STRICT_TEST: copyout failed", 22030Sstevel@tonic-gate instance); 22040Sstevel@tonic-gate rv = EINVAL; 22050Sstevel@tonic-gate } 22060Sstevel@tonic-gate if (pshot_debug) { 22070Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:" 22080Sstevel@tonic-gate " DEVCTL_PM_BUS_STRICT_TEST: type = %s\n", 22090Sstevel@tonic-gate instance, ((state == 0) ? "INVOLVED" : "STRICT")); 22100Sstevel@tonic-gate } 22110Sstevel@tonic-gate mutex_exit(&pshot->lock); 22120Sstevel@tonic-gate break; 22130Sstevel@tonic-gate 22140Sstevel@tonic-gate case DEVCTL_PM_BUS_NO_INVOL: 22150Sstevel@tonic-gate /* 22160Sstevel@tonic-gate * Set the NO_INVOL_FLAG flag to 22170Sstevel@tonic-gate * notify the driver that the child will not 22180Sstevel@tonic-gate * call pm_lower_power() on detach. 22190Sstevel@tonic-gate * The driver needs to mark itself idle twice 22200Sstevel@tonic-gate * during DDI_CTLOPS_DETACH (post). 22210Sstevel@tonic-gate */ 22220Sstevel@tonic-gate if (pshot_debug) { 22230Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:" 22240Sstevel@tonic-gate " DEVCTL_PM_BUS_NO_INVOL\n", instance); 22250Sstevel@tonic-gate } 22260Sstevel@tonic-gate mutex_enter(&pshot->lock); 22270Sstevel@tonic-gate pshot->state |= NO_INVOL_FLAG; 22280Sstevel@tonic-gate mutex_exit(&pshot->lock); 22290Sstevel@tonic-gate break; 22300Sstevel@tonic-gate 22310Sstevel@tonic-gate default: 22320Sstevel@tonic-gate rv = ENOTTY; 22330Sstevel@tonic-gate } 22340Sstevel@tonic-gate 22350Sstevel@tonic-gate ndi_dc_freehdl(dcp); 22360Sstevel@tonic-gate return (rv); 22370Sstevel@tonic-gate } 22380Sstevel@tonic-gate 22390Sstevel@tonic-gate 22400Sstevel@tonic-gate /* 22410Sstevel@tonic-gate * pshot_testctl: handle other test operations 22420Sstevel@tonic-gate * - If <cmd> is a DEVCTL cmd, then <arg> is a dev_t indicating which 22430Sstevel@tonic-gate * child to direct the DEVCTL to, if applicable; 22440Sstevel@tonic-gate * furthermore, any cmd here can be sent by layered ioctls (unlike 22450Sstevel@tonic-gate * those to pshot_devctl() which must come from userland) 22460Sstevel@tonic-gate */ 22470Sstevel@tonic-gate /* ARGSUSED */ 22480Sstevel@tonic-gate static int 22490Sstevel@tonic-gate pshot_testctl(pshot_t *pshot, minor_t nodenum, int cmd, intptr_t arg, int mode, 22500Sstevel@tonic-gate cred_t *credp, int *rvalp) 22510Sstevel@tonic-gate { 22520Sstevel@tonic-gate dev_info_t *self; 22530Sstevel@tonic-gate dev_info_t *child = NULL; 22540Sstevel@tonic-gate uint_t state; 22550Sstevel@tonic-gate int rv = 0; 22560Sstevel@tonic-gate int instance; 22570Sstevel@tonic-gate int i; 22580Sstevel@tonic-gate 22590Sstevel@tonic-gate /* uint_t flags; */ 22600Sstevel@tonic-gate 22610Sstevel@tonic-gate /* flags = (pshot_devctl_debug) ? NDI_DEVI_DEBUG : 0; */ 22620Sstevel@tonic-gate self = pshot->dip; 22630Sstevel@tonic-gate instance = pshot->instance; 22640Sstevel@tonic-gate 22650Sstevel@tonic-gate if (cmd & DEVCTL_IOC) { 22660Sstevel@tonic-gate child = e_ddi_hold_devi_by_dev((dev_t)arg, 0); 22670Sstevel@tonic-gate } 22680Sstevel@tonic-gate 22690Sstevel@tonic-gate for (i = 0; pshot_devctls[i].ioctl_int != 0; i++) { 22700Sstevel@tonic-gate if (pshot_devctls[i].ioctl_int == cmd) { 22710Sstevel@tonic-gate if (pshot_debug) 22720Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl: %s", 22730Sstevel@tonic-gate instance, pshot_devctls[i].ioctl_char); 22740Sstevel@tonic-gate } 22750Sstevel@tonic-gate } 22760Sstevel@tonic-gate switch (cmd) { 22770Sstevel@tonic-gate case DEVCTL_DEVICE_RESET: 22780Sstevel@tonic-gate if (pshot_debug) 22790Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d testctl:" 22800Sstevel@tonic-gate " DEVCTL_PM_POWER\n", instance); 22810Sstevel@tonic-gate rv = pshot_event(pshot, PSHOT_EVENT_TAG_DEV_RESET, 22820Sstevel@tonic-gate child, (void *)self); 22830Sstevel@tonic-gate ASSERT(rv == NDI_SUCCESS); 22840Sstevel@tonic-gate break; 22850Sstevel@tonic-gate 22860Sstevel@tonic-gate case DEVCTL_BUS_QUIESCE: 22870Sstevel@tonic-gate if (pshot_debug) 22880Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d testctl:" 22890Sstevel@tonic-gate " DEVCTL_PM_POWER\n", instance); 22900Sstevel@tonic-gate if (ndi_get_bus_state(self, &state) == NDI_SUCCESS) { 22910Sstevel@tonic-gate if (state == BUS_QUIESCED) { 22920Sstevel@tonic-gate break; 22930Sstevel@tonic-gate } 22940Sstevel@tonic-gate (void) ndi_set_bus_state(self, BUS_QUIESCED); 22950Sstevel@tonic-gate } 22960Sstevel@tonic-gate rv = pshot_event(pshot, PSHOT_EVENT_TAG_BUS_QUIESCE, 22970Sstevel@tonic-gate child, (void *)self); 22980Sstevel@tonic-gate ASSERT(rv == NDI_SUCCESS); 22990Sstevel@tonic-gate 23000Sstevel@tonic-gate break; 23010Sstevel@tonic-gate 23020Sstevel@tonic-gate case DEVCTL_BUS_UNQUIESCE: 23030Sstevel@tonic-gate if (pshot_debug) 23040Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d testctl:" 23050Sstevel@tonic-gate " DEVCTL_PM_POWER\n", instance); 23060Sstevel@tonic-gate if (ndi_get_bus_state(self, &state) == NDI_SUCCESS) { 23070Sstevel@tonic-gate if (state == BUS_ACTIVE) { 23080Sstevel@tonic-gate break; 23090Sstevel@tonic-gate } 23100Sstevel@tonic-gate } 23110Sstevel@tonic-gate 23120Sstevel@tonic-gate /* 23130Sstevel@tonic-gate * quiesce the bus through bus-specific means 23140Sstevel@tonic-gate */ 23150Sstevel@tonic-gate (void) ndi_set_bus_state(self, BUS_ACTIVE); 23160Sstevel@tonic-gate rv = pshot_event(pshot, PSHOT_EVENT_TAG_BUS_UNQUIESCE, 23170Sstevel@tonic-gate child, (void *)self); 23180Sstevel@tonic-gate ASSERT(rv == NDI_SUCCESS); 23190Sstevel@tonic-gate break; 23200Sstevel@tonic-gate 23210Sstevel@tonic-gate case DEVCTL_BUS_RESET: 23220Sstevel@tonic-gate case DEVCTL_BUS_RESETALL: 23230Sstevel@tonic-gate /* 23240Sstevel@tonic-gate * no reset support for the pseudo bus 23250Sstevel@tonic-gate * but if there were.... 23260Sstevel@tonic-gate */ 23270Sstevel@tonic-gate rv = pshot_event(pshot, PSHOT_EVENT_TAG_BUS_RESET, 23287656SSherry.Moore@Sun.COM child, (void *)self); 23290Sstevel@tonic-gate ASSERT(rv == NDI_SUCCESS); 23300Sstevel@tonic-gate break; 23310Sstevel@tonic-gate 23320Sstevel@tonic-gate default: 23330Sstevel@tonic-gate rv = ENOTTY; 23340Sstevel@tonic-gate } 23350Sstevel@tonic-gate 23360Sstevel@tonic-gate if (child != NULL) 23370Sstevel@tonic-gate ddi_release_devi(child); 23380Sstevel@tonic-gate return (rv); 23390Sstevel@tonic-gate } 23400Sstevel@tonic-gate 23410Sstevel@tonic-gate 23420Sstevel@tonic-gate static int 23430Sstevel@tonic-gate pshot_get_eventcookie(dev_info_t *dip, dev_info_t *rdip, 23440Sstevel@tonic-gate char *eventname, ddi_eventcookie_t *event_cookiep) 23450Sstevel@tonic-gate { 23460Sstevel@tonic-gate int instance = ddi_get_instance(dip); 23470Sstevel@tonic-gate pshot_t *pshot = ddi_get_soft_state(pshot_softstatep, instance); 23480Sstevel@tonic-gate 23490Sstevel@tonic-gate if (pshot_debug) 23507656SSherry.Moore@Sun.COM cmn_err(CE_CONT, "pshot%d: " 23517656SSherry.Moore@Sun.COM "pshot_get_eventcookie:\n\t" 23527656SSherry.Moore@Sun.COM "dip = 0x%p rdip = 0x%p (%s/%d) eventname = %s\n", 23537656SSherry.Moore@Sun.COM instance, (void *)dip, (void *)rdip, 23547656SSherry.Moore@Sun.COM ddi_node_name(rdip), ddi_get_instance(rdip), 23557656SSherry.Moore@Sun.COM eventname); 23560Sstevel@tonic-gate 23570Sstevel@tonic-gate 23580Sstevel@tonic-gate return (ndi_event_retrieve_cookie(pshot->ndi_event_hdl, 23597656SSherry.Moore@Sun.COM rdip, eventname, event_cookiep, NDI_EVENT_NOPASS)); 23600Sstevel@tonic-gate } 23610Sstevel@tonic-gate 23620Sstevel@tonic-gate static int 23630Sstevel@tonic-gate pshot_add_eventcall(dev_info_t *dip, dev_info_t *rdip, 23640Sstevel@tonic-gate ddi_eventcookie_t cookie, 23650Sstevel@tonic-gate void (*callback)(), void *arg, ddi_callback_id_t *cb_id) 23660Sstevel@tonic-gate { 23670Sstevel@tonic-gate int instance = ddi_get_instance(dip); 23680Sstevel@tonic-gate pshot_t *pshot = ddi_get_soft_state(pshot_softstatep, instance); 23690Sstevel@tonic-gate 23700Sstevel@tonic-gate if (pshot_debug) 23717656SSherry.Moore@Sun.COM cmn_err(CE_CONT, "pshot%d: " 23727656SSherry.Moore@Sun.COM "pshot_add_eventcall:\n\t" 23737656SSherry.Moore@Sun.COM "dip = 0x%p rdip = 0x%p (%s%d)\n\tcookie = 0x%p (%s)\n\t" 23747656SSherry.Moore@Sun.COM "cb = 0x%p, arg = 0x%p\n", 23757656SSherry.Moore@Sun.COM instance, (void *)dip, (void *)rdip, 23767656SSherry.Moore@Sun.COM ddi_node_name(rdip), ddi_get_instance(rdip), (void *)cookie, 23777656SSherry.Moore@Sun.COM NDI_EVENT_NAME(cookie), (void *)callback, arg); 23780Sstevel@tonic-gate 23790Sstevel@tonic-gate /* add callback to our event handle */ 23800Sstevel@tonic-gate return (ndi_event_add_callback(pshot->ndi_event_hdl, rdip, 23817656SSherry.Moore@Sun.COM cookie, callback, arg, NDI_SLEEP, cb_id)); 23820Sstevel@tonic-gate } 23830Sstevel@tonic-gate 23840Sstevel@tonic-gate static int 23850Sstevel@tonic-gate pshot_remove_eventcall(dev_info_t *dip, ddi_callback_id_t cb_id) 23860Sstevel@tonic-gate { 23870Sstevel@tonic-gate 23880Sstevel@tonic-gate ndi_event_callbacks_t *cb = (ndi_event_callbacks_t *)cb_id; 23890Sstevel@tonic-gate 23900Sstevel@tonic-gate int instance = ddi_get_instance(dip); 23910Sstevel@tonic-gate pshot_t *pshot = ddi_get_soft_state(pshot_softstatep, instance); 23920Sstevel@tonic-gate 23930Sstevel@tonic-gate ASSERT(cb); 23940Sstevel@tonic-gate 23950Sstevel@tonic-gate if (pshot_debug) 23967656SSherry.Moore@Sun.COM cmn_err(CE_CONT, "pshot%d: " 23977656SSherry.Moore@Sun.COM "pshot_remove_eventcall:\n\t" 23987656SSherry.Moore@Sun.COM "dip = 0x%p rdip = 0x%p (%s%d)\n\tcookie = 0x%p (%s)\n", 23997656SSherry.Moore@Sun.COM instance, (void *)dip, (void *)cb->ndi_evtcb_dip, 24007656SSherry.Moore@Sun.COM ddi_node_name(cb->ndi_evtcb_dip), 24017656SSherry.Moore@Sun.COM ddi_get_instance(cb->ndi_evtcb_dip), 24027656SSherry.Moore@Sun.COM (void *)cb->ndi_evtcb_cookie, 24037656SSherry.Moore@Sun.COM NDI_EVENT_NAME(cb->ndi_evtcb_cookie)); 24040Sstevel@tonic-gate 24050Sstevel@tonic-gate return (ndi_event_remove_callback(pshot->ndi_event_hdl, cb_id)); 24060Sstevel@tonic-gate } 24070Sstevel@tonic-gate 24080Sstevel@tonic-gate static int 24090Sstevel@tonic-gate pshot_post_event(dev_info_t *dip, dev_info_t *rdip, 24100Sstevel@tonic-gate ddi_eventcookie_t cookie, void *impl_data) 24110Sstevel@tonic-gate { 24120Sstevel@tonic-gate int instance = ddi_get_instance(dip); 24130Sstevel@tonic-gate pshot_t *pshot = ddi_get_soft_state(pshot_softstatep, instance); 24140Sstevel@tonic-gate 24150Sstevel@tonic-gate if (pshot_debug) { 24167656SSherry.Moore@Sun.COM if (rdip) { 24177656SSherry.Moore@Sun.COM cmn_err(CE_CONT, "pshot%d: " 24187656SSherry.Moore@Sun.COM "pshot_post_event:\n\t" 24197656SSherry.Moore@Sun.COM "dip = 0x%p rdip = 0x%p (%s%d\n\t" 24207656SSherry.Moore@Sun.COM "cookie = 0x%p (%s)\n\tbus_impl = 0x%p\n", 24217656SSherry.Moore@Sun.COM instance, (void *)dip, (void *)rdip, 24227656SSherry.Moore@Sun.COM ddi_node_name(rdip), ddi_get_instance(rdip), 24237656SSherry.Moore@Sun.COM (void *)cookie, 24247656SSherry.Moore@Sun.COM NDI_EVENT_NAME(cookie), impl_data); 24257656SSherry.Moore@Sun.COM } else { 24267656SSherry.Moore@Sun.COM cmn_err(CE_CONT, "pshot%d: " 24277656SSherry.Moore@Sun.COM "pshot_post_event:\n\t" 24287656SSherry.Moore@Sun.COM "dip = 0x%p cookie = 0x%p (%s) bus_impl = 0x%p\n", 24297656SSherry.Moore@Sun.COM instance, (void *)dip, (void *)cookie, 24307656SSherry.Moore@Sun.COM NDI_EVENT_NAME(cookie), impl_data); 24317656SSherry.Moore@Sun.COM } 24320Sstevel@tonic-gate } 24330Sstevel@tonic-gate 24340Sstevel@tonic-gate /* run callbacks for this event */ 24350Sstevel@tonic-gate return (ndi_event_run_callbacks(pshot->ndi_event_hdl, rdip, 24360Sstevel@tonic-gate cookie, impl_data)); 24370Sstevel@tonic-gate } 24380Sstevel@tonic-gate 24390Sstevel@tonic-gate /* 24400Sstevel@tonic-gate * the nexus driver will generate events 24410Sstevel@tonic-gate * that need to go to children 24420Sstevel@tonic-gate */ 24430Sstevel@tonic-gate static int 24440Sstevel@tonic-gate pshot_event(pshot_t *pshot, int event_tag, dev_info_t *child, 24450Sstevel@tonic-gate void *bus_impldata) 24460Sstevel@tonic-gate { 24470Sstevel@tonic-gate ddi_eventcookie_t cookie = ndi_event_tag_to_cookie( 24487656SSherry.Moore@Sun.COM pshot->ndi_event_hdl, event_tag); 24490Sstevel@tonic-gate 24500Sstevel@tonic-gate if (pshot_debug) { 24510Sstevel@tonic-gate if (child) { 24527656SSherry.Moore@Sun.COM cmn_err(CE_CONT, "pshot%d: " 24537656SSherry.Moore@Sun.COM "pshot_event: event_tag = 0x%x (%s)\n\t" 24547656SSherry.Moore@Sun.COM "child = 0x%p (%s%d) bus_impl = 0x%p (%s%d)\n", 24557656SSherry.Moore@Sun.COM pshot->instance, event_tag, 24567656SSherry.Moore@Sun.COM ndi_event_tag_to_name(pshot->ndi_event_hdl, 24577656SSherry.Moore@Sun.COM event_tag), 24587656SSherry.Moore@Sun.COM (void *)child, ddi_node_name(child), 24597656SSherry.Moore@Sun.COM ddi_get_instance(child), bus_impldata, 24607656SSherry.Moore@Sun.COM ddi_node_name((dev_info_t *)bus_impldata), 24617656SSherry.Moore@Sun.COM ddi_get_instance((dev_info_t *)bus_impldata)); 24620Sstevel@tonic-gate } else { 24637656SSherry.Moore@Sun.COM cmn_err(CE_CONT, "pshot%d: " 24647656SSherry.Moore@Sun.COM "pshot_event: event_tag = 0x%x (%s)\n\t" 24657656SSherry.Moore@Sun.COM "child = NULL, bus_impl = 0x%p (%s%d)\n", 24667656SSherry.Moore@Sun.COM pshot->instance, event_tag, 24677656SSherry.Moore@Sun.COM ndi_event_tag_to_name(pshot->ndi_event_hdl, 24687656SSherry.Moore@Sun.COM event_tag), 24697656SSherry.Moore@Sun.COM bus_impldata, 24707656SSherry.Moore@Sun.COM ddi_node_name((dev_info_t *)bus_impldata), 24717656SSherry.Moore@Sun.COM ddi_get_instance((dev_info_t *)bus_impldata)); 24720Sstevel@tonic-gate } 24730Sstevel@tonic-gate } 24740Sstevel@tonic-gate 24750Sstevel@tonic-gate return (ndi_event_run_callbacks(pshot->ndi_event_hdl, 24767656SSherry.Moore@Sun.COM child, cookie, bus_impldata)); 24770Sstevel@tonic-gate } 24780Sstevel@tonic-gate 24790Sstevel@tonic-gate 24800Sstevel@tonic-gate /* 24810Sstevel@tonic-gate * the pshot driver event notification callback 24820Sstevel@tonic-gate */ 24830Sstevel@tonic-gate static void 24840Sstevel@tonic-gate pshot_event_cb(dev_info_t *dip, ddi_eventcookie_t cookie, 24850Sstevel@tonic-gate void *arg, void *bus_impldata) 24860Sstevel@tonic-gate { 24870Sstevel@tonic-gate pshot_t *pshot = (pshot_t *)arg; 24880Sstevel@tonic-gate int event_tag; 24890Sstevel@tonic-gate 24900Sstevel@tonic-gate /* look up the event */ 24910Sstevel@tonic-gate event_tag = NDI_EVENT_TAG(cookie); 24920Sstevel@tonic-gate 24930Sstevel@tonic-gate if (pshot_debug) { 24940Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: " 24950Sstevel@tonic-gate "pshot_event_cb:\n\t" 24960Sstevel@tonic-gate "dip = 0x%p cookie = 0x%p (%s), tag = 0x%x\n\t" 24970Sstevel@tonic-gate "arg = 0x%p bus_impl = 0x%p (%s%d)\n", 24980Sstevel@tonic-gate pshot->instance, (void *)dip, (void *)cookie, 24990Sstevel@tonic-gate NDI_EVENT_NAME(cookie), event_tag, arg, bus_impldata, 25000Sstevel@tonic-gate ddi_node_name((dev_info_t *)bus_impldata), 25010Sstevel@tonic-gate ddi_get_instance((dev_info_t *)bus_impldata)); 25020Sstevel@tonic-gate } 25030Sstevel@tonic-gate 25040Sstevel@tonic-gate switch (event_tag) { 25050Sstevel@tonic-gate case PSHOT_EVENT_TAG_OFFLINE: 25060Sstevel@tonic-gate case PSHOT_EVENT_TAG_BUS_RESET: 25070Sstevel@tonic-gate case PSHOT_EVENT_TAG_BUS_QUIESCE: 25080Sstevel@tonic-gate case PSHOT_EVENT_TAG_BUS_UNQUIESCE: 25090Sstevel@tonic-gate /* notify all subscribers of the this event */ 25100Sstevel@tonic-gate (void) ndi_event_run_callbacks(pshot->ndi_event_hdl, 25117656SSherry.Moore@Sun.COM NULL, cookie, bus_impldata); 25120Sstevel@tonic-gate if (pshot_debug) { 25130Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: event=%s\n\t" 25147656SSherry.Moore@Sun.COM "pshot_event_cb\n", pshot->instance, 25157656SSherry.Moore@Sun.COM NDI_EVENT_NAME(cookie)); 25160Sstevel@tonic-gate } 25170Sstevel@tonic-gate /*FALLTHRU*/ 25180Sstevel@tonic-gate case PSHOT_EVENT_TAG_TEST_POST: 25190Sstevel@tonic-gate case PSHOT_EVENT_TAG_DEV_RESET: 25200Sstevel@tonic-gate default: 25210Sstevel@tonic-gate return; 25220Sstevel@tonic-gate } 25230Sstevel@tonic-gate } 25240Sstevel@tonic-gate 25250Sstevel@tonic-gate static int 25260Sstevel@tonic-gate pshot_bus_config(dev_info_t *parent, uint_t flags, 25270Sstevel@tonic-gate ddi_bus_config_op_t op, void *arg, dev_info_t **childp) 25280Sstevel@tonic-gate { 25290Sstevel@tonic-gate int rval; 25300Sstevel@tonic-gate char *devname; 25310Sstevel@tonic-gate char *devstr, *cname, *caddr; 25320Sstevel@tonic-gate int devstrlen; 25330Sstevel@tonic-gate int circ; 25340Sstevel@tonic-gate pshot_t *pshot; 25350Sstevel@tonic-gate int instance = ddi_get_instance(parent); 25360Sstevel@tonic-gate 25370Sstevel@tonic-gate if (pshot_debug) { 25380Sstevel@tonic-gate flags |= NDI_DEVI_DEBUG; 25390Sstevel@tonic-gate cmn_err(CE_CONT, 25400Sstevel@tonic-gate "pshot%d: bus_config %s flags=0x%x\n", 25410Sstevel@tonic-gate ddi_get_instance(parent), 25420Sstevel@tonic-gate (op == BUS_CONFIG_ONE) ? (char *)arg : "", flags); 25430Sstevel@tonic-gate } 25440Sstevel@tonic-gate 25450Sstevel@tonic-gate pshot = ddi_get_soft_state(pshot_softstatep, instance); 25460Sstevel@tonic-gate if (pshot == NULL) { 25470Sstevel@tonic-gate 25480Sstevel@tonic-gate return (NDI_FAILURE); 25490Sstevel@tonic-gate } 25500Sstevel@tonic-gate 25510Sstevel@tonic-gate /* 25520Sstevel@tonic-gate * Hold the nexus across the bus_config 25530Sstevel@tonic-gate */ 25540Sstevel@tonic-gate ndi_devi_enter(parent, &circ); 25550Sstevel@tonic-gate 25560Sstevel@tonic-gate switch (op) { 25570Sstevel@tonic-gate case BUS_CONFIG_ONE: 25580Sstevel@tonic-gate 25590Sstevel@tonic-gate /* 25600Sstevel@tonic-gate * lookup and hold child device, create if not found 25610Sstevel@tonic-gate */ 25620Sstevel@tonic-gate devname = (char *)arg; 25630Sstevel@tonic-gate devstrlen = strlen(devname) + 1; 25640Sstevel@tonic-gate devstr = i_ddi_strdup(devname, KM_SLEEP); 25650Sstevel@tonic-gate i_ddi_parse_name(devstr, &cname, &caddr, NULL); 25660Sstevel@tonic-gate 25670Sstevel@tonic-gate /* 25680Sstevel@tonic-gate * The framework ensures that the node has 25690Sstevel@tonic-gate * a name but each nexus is responsible for 25700Sstevel@tonic-gate * the bus address name space. This driver 25710Sstevel@tonic-gate * requires that a bus address be specified, 25720Sstevel@tonic-gate * as will most nexus drivers. 25730Sstevel@tonic-gate */ 25740Sstevel@tonic-gate ASSERT(cname && strlen(cname) > 0); 25750Sstevel@tonic-gate if (caddr == NULL || strlen(caddr) == 0) { 25760Sstevel@tonic-gate cmn_err(CE_WARN, 25770Sstevel@tonic-gate "pshot%d: malformed name %s (no bus address)", 25780Sstevel@tonic-gate ddi_get_instance(parent), devname); 25790Sstevel@tonic-gate kmem_free(devstr, devstrlen); 25800Sstevel@tonic-gate ndi_devi_exit(parent, circ); 25810Sstevel@tonic-gate return (NDI_FAILURE); 25820Sstevel@tonic-gate } 25830Sstevel@tonic-gate 25840Sstevel@tonic-gate /* 25850Sstevel@tonic-gate * Handle a few special cases for testing purposes 25860Sstevel@tonic-gate */ 25870Sstevel@tonic-gate rval = pshot_bus_config_test_specials(parent, 25887656SSherry.Moore@Sun.COM devname, cname, caddr); 25890Sstevel@tonic-gate 25900Sstevel@tonic-gate if (rval == NDI_SUCCESS) { 25910Sstevel@tonic-gate /* 25920Sstevel@tonic-gate * Set up either a leaf or nexus device 25930Sstevel@tonic-gate */ 25940Sstevel@tonic-gate if (strcmp(cname, "pshot") == 0) { 25950Sstevel@tonic-gate rval = pshot_bus_config_setup_nexus(parent, 25960Sstevel@tonic-gate cname, caddr); 25970Sstevel@tonic-gate } else { 25980Sstevel@tonic-gate rval = pshot_bus_config_setup_leaf(parent, 25990Sstevel@tonic-gate cname, caddr); 26000Sstevel@tonic-gate } 26010Sstevel@tonic-gate } 26020Sstevel@tonic-gate 26030Sstevel@tonic-gate kmem_free(devstr, devstrlen); 26040Sstevel@tonic-gate break; 26050Sstevel@tonic-gate 26060Sstevel@tonic-gate case BUS_CONFIG_DRIVER: 26070Sstevel@tonic-gate case BUS_CONFIG_ALL: 26080Sstevel@tonic-gate rval = NDI_SUCCESS; 26090Sstevel@tonic-gate break; 26100Sstevel@tonic-gate 26110Sstevel@tonic-gate default: 26120Sstevel@tonic-gate rval = NDI_FAILURE; 26130Sstevel@tonic-gate break; 26140Sstevel@tonic-gate } 26150Sstevel@tonic-gate 26160Sstevel@tonic-gate if (rval == NDI_SUCCESS) 26170Sstevel@tonic-gate rval = ndi_busop_bus_config(parent, flags, op, arg, childp, 0); 26180Sstevel@tonic-gate 26190Sstevel@tonic-gate ndi_devi_exit(parent, circ); 26200Sstevel@tonic-gate 26210Sstevel@tonic-gate if (pshot_debug) 26220Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: bus_config %s\n", 26230Sstevel@tonic-gate ddi_get_instance(parent), 26240Sstevel@tonic-gate (rval == NDI_SUCCESS) ? "ok" : "failed"); 26250Sstevel@tonic-gate 26260Sstevel@tonic-gate return (rval); 26270Sstevel@tonic-gate } 26280Sstevel@tonic-gate 26290Sstevel@tonic-gate static int 26300Sstevel@tonic-gate pshot_bus_unconfig(dev_info_t *parent, uint_t flags, 26310Sstevel@tonic-gate ddi_bus_config_op_t op, void *arg) 26320Sstevel@tonic-gate { 26330Sstevel@tonic-gate major_t major; 26340Sstevel@tonic-gate int rval = NDI_SUCCESS; 26350Sstevel@tonic-gate int circ; 26360Sstevel@tonic-gate 26370Sstevel@tonic-gate if (pshot_debug) { 26380Sstevel@tonic-gate flags |= NDI_DEVI_DEBUG; 26390Sstevel@tonic-gate cmn_err(CE_CONT, 26400Sstevel@tonic-gate "pshot%d: bus_unconfig %s flags=0x%x\n", 26410Sstevel@tonic-gate ddi_get_instance(parent), 26420Sstevel@tonic-gate (op == BUS_UNCONFIG_ONE) ? (char *)arg : "", flags); 26430Sstevel@tonic-gate } 26440Sstevel@tonic-gate 26450Sstevel@tonic-gate /* 26460Sstevel@tonic-gate * Hold the nexus across the bus_unconfig 26470Sstevel@tonic-gate */ 26480Sstevel@tonic-gate ndi_devi_enter(parent, &circ); 26490Sstevel@tonic-gate 26500Sstevel@tonic-gate switch (op) { 26510Sstevel@tonic-gate case BUS_UNCONFIG_ONE: 26520Sstevel@tonic-gate /* 26530Sstevel@tonic-gate * Nothing special required here 26540Sstevel@tonic-gate */ 26550Sstevel@tonic-gate if (pshot_debug) { 26560Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: bus_unconfig:" 26570Sstevel@tonic-gate " BUS_UNCONFIG_ONE\n", ddi_get_instance(parent)); 26580Sstevel@tonic-gate } 26590Sstevel@tonic-gate break; 26600Sstevel@tonic-gate 26610Sstevel@tonic-gate case BUS_UNCONFIG_DRIVER: 26620Sstevel@tonic-gate if (pshot_debug > 0) { 26630Sstevel@tonic-gate major = (major_t)(uintptr_t)arg; 26640Sstevel@tonic-gate cmn_err(CE_CONT, 26650Sstevel@tonic-gate "pshot%d: BUS_UNCONFIG_DRIVER: %s\n", 26660Sstevel@tonic-gate ddi_get_instance(parent), 26670Sstevel@tonic-gate ddi_major_to_name(major)); 26680Sstevel@tonic-gate } 26690Sstevel@tonic-gate break; 26700Sstevel@tonic-gate 26710Sstevel@tonic-gate case BUS_UNCONFIG_ALL: 26720Sstevel@tonic-gate if (pshot_debug) { 26730Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: bus_unconfig:" 26740Sstevel@tonic-gate " BUS_UNCONFIG_ALL\n", ddi_get_instance(parent)); 26750Sstevel@tonic-gate } 26760Sstevel@tonic-gate break; 26770Sstevel@tonic-gate 26780Sstevel@tonic-gate default: 26790Sstevel@tonic-gate if (pshot_debug) { 26800Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: bus_unconfig: DEFAULT\n", 26810Sstevel@tonic-gate ddi_get_instance(parent)); 26820Sstevel@tonic-gate } 26830Sstevel@tonic-gate rval = NDI_FAILURE; 26840Sstevel@tonic-gate } 26850Sstevel@tonic-gate 26860Sstevel@tonic-gate if (rval == NDI_SUCCESS) 26870Sstevel@tonic-gate rval = ndi_busop_bus_unconfig(parent, flags, op, arg); 26880Sstevel@tonic-gate 26890Sstevel@tonic-gate ndi_devi_exit(parent, circ); 26900Sstevel@tonic-gate 26910Sstevel@tonic-gate if (pshot_debug) 26920Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: bus_unconfig %s\n", 26930Sstevel@tonic-gate ddi_get_instance(parent), 26940Sstevel@tonic-gate (rval == NDI_SUCCESS) ? "ok" : "failed"); 26950Sstevel@tonic-gate 26960Sstevel@tonic-gate return (rval); 26970Sstevel@tonic-gate } 26980Sstevel@tonic-gate 26990Sstevel@tonic-gate static dev_info_t * 27000Sstevel@tonic-gate pshot_findchild(dev_info_t *pdip, char *cname, char *caddr) 27010Sstevel@tonic-gate { 27020Sstevel@tonic-gate dev_info_t *dip; 27030Sstevel@tonic-gate char *addr; 27040Sstevel@tonic-gate 27050Sstevel@tonic-gate ASSERT(cname != NULL && caddr != NULL); 27060Sstevel@tonic-gate ASSERT(DEVI_BUSY_OWNED(pdip)); 27070Sstevel@tonic-gate 27080Sstevel@tonic-gate for (dip = ddi_get_child(pdip); dip != NULL; 27090Sstevel@tonic-gate dip = ddi_get_next_sibling(dip)) { 27100Sstevel@tonic-gate if (strcmp(cname, ddi_node_name(dip)) != 0) 27110Sstevel@tonic-gate continue; 27120Sstevel@tonic-gate 27130Sstevel@tonic-gate if ((addr = ddi_get_name_addr(dip)) == NULL) { 27140Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, 0, 27150Sstevel@tonic-gate "bus-addr", &addr) == DDI_PROP_SUCCESS) { 27160Sstevel@tonic-gate if (strcmp(caddr, addr) == 0) { 27170Sstevel@tonic-gate ddi_prop_free(addr); 27180Sstevel@tonic-gate return (dip); 27190Sstevel@tonic-gate } 27200Sstevel@tonic-gate ddi_prop_free(addr); 27210Sstevel@tonic-gate } 27220Sstevel@tonic-gate } else { 27230Sstevel@tonic-gate if (strcmp(caddr, addr) == 0) 27240Sstevel@tonic-gate return (dip); 27250Sstevel@tonic-gate } 27260Sstevel@tonic-gate } 27270Sstevel@tonic-gate 27280Sstevel@tonic-gate return (NULL); 27290Sstevel@tonic-gate } 27300Sstevel@tonic-gate 27310Sstevel@tonic-gate static void 27320Sstevel@tonic-gate pshot_nexus_properties(dev_info_t *parent, dev_info_t *child, char *cname, 27330Sstevel@tonic-gate char *caddr) 27340Sstevel@tonic-gate { 27350Sstevel@tonic-gate char *extension; 27360Sstevel@tonic-gate 27370Sstevel@tonic-gate /* 273885Scth * extract the address extension 27390Sstevel@tonic-gate */ 27400Sstevel@tonic-gate extension = strstr(caddr, ","); 27410Sstevel@tonic-gate if (extension != NULL) { 27420Sstevel@tonic-gate ++extension; 27430Sstevel@tonic-gate } else { 27440Sstevel@tonic-gate extension = "null"; 27450Sstevel@tonic-gate } 27460Sstevel@tonic-gate 27470Sstevel@tonic-gate /* 27480Sstevel@tonic-gate * Create the "pm-want-child-notification?" property for all 27490Sstevel@tonic-gate * nodes that do not have the "pm_strict" or "nopm_strict" 27500Sstevel@tonic-gate * extension 27510Sstevel@tonic-gate */ 27520Sstevel@tonic-gate if (strcmp(extension, "pm_strict") != 0 && 27530Sstevel@tonic-gate strcmp(extension, "nopm_strict") != 0) { 27540Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, child, 27550Sstevel@tonic-gate (DDI_PROP_DONTPASS | DDI_PROP_NOTPROM), 27560Sstevel@tonic-gate "pm-want-child-notification?") == 0) { 27570Sstevel@tonic-gate if (pshot_debug) { 27580Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:" 27590Sstevel@tonic-gate " nexus_properties:\n\tcreate the" 27600Sstevel@tonic-gate " \"pm-want-child-notification?\"" 27610Sstevel@tonic-gate " property for %s@%s\n", 27620Sstevel@tonic-gate ddi_get_instance(parent), cname, caddr); 27630Sstevel@tonic-gate } 27640Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, child, 0, 27650Sstevel@tonic-gate "pm-want-child-notification?", NULL, 0) 27660Sstevel@tonic-gate != DDI_PROP_SUCCESS) { 27670Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d:" 27680Sstevel@tonic-gate " nexus_properties:\n\tunable to create" 27690Sstevel@tonic-gate " the \"pm-want-child-notification?\"" 27700Sstevel@tonic-gate " property for %s@%s", 27710Sstevel@tonic-gate ddi_get_instance(parent), cname, caddr); 27720Sstevel@tonic-gate } 27730Sstevel@tonic-gate } 27740Sstevel@tonic-gate } 27750Sstevel@tonic-gate 27760Sstevel@tonic-gate /* 27770Sstevel@tonic-gate * Create the "no-pm-components" property for all nodes 27780Sstevel@tonic-gate * with extension "nopm" or "nopm_strict" 27790Sstevel@tonic-gate */ 27800Sstevel@tonic-gate if (strcmp(extension, "nopm") == 0 || 27810Sstevel@tonic-gate strcmp(extension, "nopm_strict") == 0) { 27820Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, child, 27830Sstevel@tonic-gate (DDI_PROP_DONTPASS | DDI_PROP_NOTPROM), 27840Sstevel@tonic-gate "no-pm-components") == 0) { 27850Sstevel@tonic-gate if (pshot_debug) { 27860Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:" 27870Sstevel@tonic-gate " nexus_properties:\n\tcreate the" 27880Sstevel@tonic-gate " \"no-pm-components\"" 27890Sstevel@tonic-gate " property for %s@%s\n", 27900Sstevel@tonic-gate ddi_get_instance(parent), cname, caddr); 27910Sstevel@tonic-gate } 27920Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, child, 0, 27930Sstevel@tonic-gate "no-pm-components", NULL, 0) 27940Sstevel@tonic-gate != DDI_PROP_SUCCESS) { 27950Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d:" 27960Sstevel@tonic-gate " nexus_properties:\n\tunable to create" 27970Sstevel@tonic-gate " the \"no-pm-components\"" 27980Sstevel@tonic-gate " property for %s@%s", 27997656SSherry.Moore@Sun.COM ddi_get_instance(parent), cname, caddr); 28000Sstevel@tonic-gate } 28010Sstevel@tonic-gate } 28020Sstevel@tonic-gate } 28030Sstevel@tonic-gate } 28040Sstevel@tonic-gate 28050Sstevel@tonic-gate static void 28060Sstevel@tonic-gate pshot_leaf_properties(dev_info_t *parent, dev_info_t *child, char *cname, 28070Sstevel@tonic-gate char *caddr) 28080Sstevel@tonic-gate { 28090Sstevel@tonic-gate char *extension; 28100Sstevel@tonic-gate 28110Sstevel@tonic-gate /* 281285Scth * extract the address extension 28130Sstevel@tonic-gate */ 28140Sstevel@tonic-gate extension = strstr(caddr, ","); 28150Sstevel@tonic-gate if (extension != NULL) { 28160Sstevel@tonic-gate ++extension; 28170Sstevel@tonic-gate } else { 28180Sstevel@tonic-gate extension = "null"; 28190Sstevel@tonic-gate } 28200Sstevel@tonic-gate 28210Sstevel@tonic-gate /* 28220Sstevel@tonic-gate * Create the "no-involuntary-power-cycles" property for 28230Sstevel@tonic-gate * all leaf nodes with extension "no_invol" 28240Sstevel@tonic-gate */ 28250Sstevel@tonic-gate if (strcmp(extension, "no_invol") == 0) { 28260Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, child, 28270Sstevel@tonic-gate (DDI_PROP_DONTPASS | DDI_PROP_NOTPROM), 28280Sstevel@tonic-gate "no-involuntary-power-cycles") == 0) { 28290Sstevel@tonic-gate if (pshot_debug) { 28300Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:" 28310Sstevel@tonic-gate " leaf_properties:\n\tcreate the" 28320Sstevel@tonic-gate " \"no-involuntary-power-cycles\"" 28330Sstevel@tonic-gate " property for %s@%s\n", 28340Sstevel@tonic-gate ddi_get_instance(parent), cname, caddr); 28350Sstevel@tonic-gate } 28360Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, child, 28370Sstevel@tonic-gate DDI_PROP_CANSLEEP, 28380Sstevel@tonic-gate "no-involuntary-power-cycles", NULL, 0) 28390Sstevel@tonic-gate != DDI_PROP_SUCCESS) { 28400Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d:" 28410Sstevel@tonic-gate " leaf_properties:\n\tunable to create the" 28420Sstevel@tonic-gate " \"no-involuntary-power-cycles\"" 28430Sstevel@tonic-gate " property for %s@%s", 28440Sstevel@tonic-gate ddi_get_instance(parent), cname, caddr); 28450Sstevel@tonic-gate } 28460Sstevel@tonic-gate } 28470Sstevel@tonic-gate } 28480Sstevel@tonic-gate 28490Sstevel@tonic-gate /* 28500Sstevel@tonic-gate * Create the "dependency-property" property for all leaf 28510Sstevel@tonic-gate * nodes with extension "dep_prop" 28520Sstevel@tonic-gate * to be used with the PM_ADD_DEPENDENT_PROPERTY ioctl 28530Sstevel@tonic-gate */ 28540Sstevel@tonic-gate if (strcmp(extension, "dep_prop") == 0) { 28550Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, child, 28560Sstevel@tonic-gate (DDI_PROP_DONTPASS | DDI_PROP_NOTPROM), 28570Sstevel@tonic-gate "dependency-property") == 0) { 28580Sstevel@tonic-gate if (pshot_debug) { 28590Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:" 28600Sstevel@tonic-gate " leaf_properties:\n\tcreate the" 28610Sstevel@tonic-gate " \"dependency-property\"" 28620Sstevel@tonic-gate " property for %s@%s\n", 28630Sstevel@tonic-gate ddi_get_instance(parent), cname, caddr); 28640Sstevel@tonic-gate } 28650Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, child, 28660Sstevel@tonic-gate DDI_PROP_CANSLEEP, "dependency-property", NULL, 0) 28670Sstevel@tonic-gate != DDI_PROP_SUCCESS) { 28680Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d:" 28690Sstevel@tonic-gate " leaf_properties:\n\tunable to create the" 28700Sstevel@tonic-gate " \"dependency-property\" property for" 28710Sstevel@tonic-gate " %s@%s", ddi_get_instance(parent), 28720Sstevel@tonic-gate cname, caddr); 28730Sstevel@tonic-gate } 28740Sstevel@tonic-gate } 28750Sstevel@tonic-gate } 28760Sstevel@tonic-gate } 28770Sstevel@tonic-gate 28780Sstevel@tonic-gate /* 28790Sstevel@tonic-gate * BUS_CONFIG_ONE: setup a child nexus instance. 28800Sstevel@tonic-gate */ 28810Sstevel@tonic-gate static int 28820Sstevel@tonic-gate pshot_bus_config_setup_nexus(dev_info_t *parent, char *cname, char *caddr) 28830Sstevel@tonic-gate { 28840Sstevel@tonic-gate dev_info_t *child; 28850Sstevel@tonic-gate int rval; 28860Sstevel@tonic-gate 28870Sstevel@tonic-gate ASSERT(parent != 0); 28880Sstevel@tonic-gate ASSERT(cname != NULL); 28890Sstevel@tonic-gate ASSERT(caddr != NULL); 28900Sstevel@tonic-gate 28910Sstevel@tonic-gate child = pshot_findchild(parent, cname, caddr); 28920Sstevel@tonic-gate if (child) { 28930Sstevel@tonic-gate if (pshot_debug) { 28940Sstevel@tonic-gate cmn_err(CE_CONT, 28950Sstevel@tonic-gate "pshot%d: bus_config one %s@%s found\n", 28960Sstevel@tonic-gate ddi_get_instance(parent), cname, caddr); 28970Sstevel@tonic-gate } 28982155Scth 28990Sstevel@tonic-gate /* 29000Sstevel@tonic-gate * create the "pm-want-child-notification?" property 29010Sstevel@tonic-gate * for this child, if it doesn't already exist 29020Sstevel@tonic-gate */ 29030Sstevel@tonic-gate (void) pshot_nexus_properties(parent, child, cname, caddr); 29040Sstevel@tonic-gate 29050Sstevel@tonic-gate return (NDI_SUCCESS); 29060Sstevel@tonic-gate } 29070Sstevel@tonic-gate 29080Sstevel@tonic-gate ndi_devi_alloc_sleep(parent, cname, DEVI_SID_NODEID, &child); 29090Sstevel@tonic-gate ASSERT(child != NULL); 29100Sstevel@tonic-gate 29110Sstevel@tonic-gate if (ndi_prop_update_string(DDI_DEV_T_NONE, child, 29120Sstevel@tonic-gate "bus-addr", caddr) != DDI_PROP_SUCCESS) { 29130Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d: _prop_update %s@%s failed", 29140Sstevel@tonic-gate ddi_get_instance(parent), cname, caddr); 29150Sstevel@tonic-gate (void) ndi_devi_free(child); 29160Sstevel@tonic-gate return (NDI_FAILURE); 29170Sstevel@tonic-gate } 29180Sstevel@tonic-gate 29190Sstevel@tonic-gate rval = ndi_devi_bind_driver(child, 0); 29200Sstevel@tonic-gate if (rval != NDI_SUCCESS) { 29210Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d: bind_driver %s failed", 29220Sstevel@tonic-gate ddi_get_instance(parent), cname); 29230Sstevel@tonic-gate (void) ndi_devi_free(child); 29240Sstevel@tonic-gate return (NDI_FAILURE); 29250Sstevel@tonic-gate } 29260Sstevel@tonic-gate 29270Sstevel@tonic-gate /* 29280Sstevel@tonic-gate * create the "pm-want-child-notification?" property 29290Sstevel@tonic-gate */ 29300Sstevel@tonic-gate (void) pshot_nexus_properties(parent, child, cname, caddr); 29310Sstevel@tonic-gate 29320Sstevel@tonic-gate return (NDI_SUCCESS); 29330Sstevel@tonic-gate } 29340Sstevel@tonic-gate 29350Sstevel@tonic-gate /* 29360Sstevel@tonic-gate * BUS_CONFIG_ONE: setup a child leaf device instance. 29370Sstevel@tonic-gate * for testing purposes, we will create nodes of a variety of types. 29380Sstevel@tonic-gate */ 29390Sstevel@tonic-gate static int 29400Sstevel@tonic-gate pshot_bus_config_setup_leaf(dev_info_t *parent, char *cname, char *caddr) 29410Sstevel@tonic-gate { 29420Sstevel@tonic-gate dev_info_t *child; 29430Sstevel@tonic-gate char *compat_name; 29440Sstevel@tonic-gate char *nodetype; 29450Sstevel@tonic-gate int rval; 29460Sstevel@tonic-gate int i; 29470Sstevel@tonic-gate 29480Sstevel@tonic-gate ASSERT(parent != 0); 29490Sstevel@tonic-gate ASSERT(cname != NULL); 29500Sstevel@tonic-gate ASSERT(caddr != NULL); 29510Sstevel@tonic-gate 29520Sstevel@tonic-gate /* 29530Sstevel@tonic-gate * if we already have a node with this name, return it 29540Sstevel@tonic-gate */ 29550Sstevel@tonic-gate if ((child = pshot_findchild(parent, cname, caddr)) != NULL) { 29560Sstevel@tonic-gate /* 29570Sstevel@tonic-gate * create the "no-involuntary-power-cycles" or 29580Sstevel@tonic-gate * the "dependency-property" property, if they 29590Sstevel@tonic-gate * don't already exit 29600Sstevel@tonic-gate */ 29610Sstevel@tonic-gate (void) pshot_leaf_properties(parent, child, cname, caddr); 29620Sstevel@tonic-gate 29630Sstevel@tonic-gate return (NDI_SUCCESS); 29640Sstevel@tonic-gate } 29650Sstevel@tonic-gate 29660Sstevel@tonic-gate ndi_devi_alloc_sleep(parent, cname, DEVI_SID_NODEID, &child); 29670Sstevel@tonic-gate ASSERT(child != NULL); 29680Sstevel@tonic-gate 29690Sstevel@tonic-gate if (ndi_prop_update_string(DDI_DEV_T_NONE, child, "bus-addr", 29700Sstevel@tonic-gate caddr) != DDI_PROP_SUCCESS) { 29710Sstevel@tonic-gate (void) ndi_devi_free(child); 29720Sstevel@tonic-gate return (NDI_FAILURE); 29730Sstevel@tonic-gate } 29740Sstevel@tonic-gate 29750Sstevel@tonic-gate /* 29760Sstevel@tonic-gate * test compatible naming 29770Sstevel@tonic-gate * if the child nodename is "cdisk", attach the list of compatible 29780Sstevel@tonic-gate * named disks 29790Sstevel@tonic-gate */ 29800Sstevel@tonic-gate if (strcmp(cname, pshot_compat_diskname) == 0) { 29810Sstevel@tonic-gate if ((ndi_prop_update_string_array(DDI_DEV_T_NONE, 29820Sstevel@tonic-gate child, "compatible", (char **)pshot_compat_psramdisks, 29830Sstevel@tonic-gate 5)) != DDI_PROP_SUCCESS) { 29840Sstevel@tonic-gate (void) ndi_devi_free(child); 29850Sstevel@tonic-gate return (NDI_FAILURE); 29860Sstevel@tonic-gate } 29870Sstevel@tonic-gate } else { 29880Sstevel@tonic-gate for (i = 0; i < pshot_devices_len && pshot_devices[i].name; 29890Sstevel@tonic-gate i++) { 29900Sstevel@tonic-gate if (strcmp(cname, pshot_devices[i].name) == 0) { 29910Sstevel@tonic-gate compat_name = pshot_devices[i].compat; 29920Sstevel@tonic-gate nodetype = pshot_devices[i].nodetype; 29930Sstevel@tonic-gate if (pshot_debug) { 29940Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: %s %s %s\n", 29950Sstevel@tonic-gate ddi_get_instance(parent), cname, 29960Sstevel@tonic-gate compat_name, nodetype); 29970Sstevel@tonic-gate } 29980Sstevel@tonic-gate if ((ndi_prop_update_string_array( 29990Sstevel@tonic-gate DDI_DEV_T_NONE, child, "compatible", 30000Sstevel@tonic-gate &compat_name, 1)) != DDI_PROP_SUCCESS) { 30010Sstevel@tonic-gate (void) ndi_devi_free(child); 30020Sstevel@tonic-gate return (NDI_FAILURE); 30030Sstevel@tonic-gate } 30040Sstevel@tonic-gate if ((ndi_prop_update_string( 30050Sstevel@tonic-gate DDI_DEV_T_NONE, child, "node-type", 30060Sstevel@tonic-gate nodetype)) != DDI_PROP_SUCCESS) { 30070Sstevel@tonic-gate (void) ndi_devi_free(child); 30080Sstevel@tonic-gate return (NDI_FAILURE); 30090Sstevel@tonic-gate } 30100Sstevel@tonic-gate } 30110Sstevel@tonic-gate } 30120Sstevel@tonic-gate } 30130Sstevel@tonic-gate 30140Sstevel@tonic-gate rval = ndi_devi_bind_driver(child, 0); 30150Sstevel@tonic-gate if (rval != NDI_SUCCESS) { 30160Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d: bind_driver %s failed", 30170Sstevel@tonic-gate ddi_get_instance(parent), cname); 30180Sstevel@tonic-gate (void) ndi_devi_free(child); 30190Sstevel@tonic-gate return (NDI_FAILURE); 30200Sstevel@tonic-gate } 30210Sstevel@tonic-gate 30220Sstevel@tonic-gate /* 30230Sstevel@tonic-gate * create the "no-involuntary-power-cycles" or 30240Sstevel@tonic-gate * the "dependency-property" property 30250Sstevel@tonic-gate */ 30260Sstevel@tonic-gate (void) pshot_leaf_properties(parent, child, cname, caddr); 30270Sstevel@tonic-gate 30280Sstevel@tonic-gate return (NDI_SUCCESS); 30290Sstevel@tonic-gate } 30300Sstevel@tonic-gate 30310Sstevel@tonic-gate /* 30320Sstevel@tonic-gate * Handle some special cases for testing bus_config via pshot 30330Sstevel@tonic-gate * 30340Sstevel@tonic-gate * Match these special address formats to behavior: 30350Sstevel@tonic-gate * 30360Sstevel@tonic-gate * err.* - induce bus_config error 30370Sstevel@tonic-gate * delay - induce 1 second of bus_config delay time 30380Sstevel@tonic-gate * delay,n - induce n seconds of bus_config delay time 30390Sstevel@tonic-gate * wait - induce 1 second of bus_config wait time 30400Sstevel@tonic-gate * wait,n - induce n seconds of bus_config wait time 30410Sstevel@tonic-gate * failinit.* - induce error at INITCHILD 30420Sstevel@tonic-gate * failprobe.* - induce error at probe 30430Sstevel@tonic-gate * failattach.* - induce error at attach 30440Sstevel@tonic-gate */ 30450Sstevel@tonic-gate /*ARGSUSED*/ 30460Sstevel@tonic-gate static int 30470Sstevel@tonic-gate pshot_bus_config_test_specials(dev_info_t *parent, char *devname, 30480Sstevel@tonic-gate char *cname, char *caddr) 30490Sstevel@tonic-gate { 30500Sstevel@tonic-gate char *p; 30510Sstevel@tonic-gate int n; 30520Sstevel@tonic-gate 30530Sstevel@tonic-gate if (strncmp(caddr, "err", 3) == 0) { 30540Sstevel@tonic-gate if (pshot_debug) 30550Sstevel@tonic-gate cmn_err(CE_CONT, 30560Sstevel@tonic-gate "pshot%d: %s forced failure\n", 30577656SSherry.Moore@Sun.COM ddi_get_instance(parent), devname); 30580Sstevel@tonic-gate return (NDI_FAILURE); 30590Sstevel@tonic-gate } 30600Sstevel@tonic-gate 30610Sstevel@tonic-gate /* 30620Sstevel@tonic-gate * The delay and wait strings have the same effect. 30630Sstevel@tonic-gate * The "wait[,]" support should be removed once the 30640Sstevel@tonic-gate * devfs test suites are fixed. 30650Sstevel@tonic-gate * NOTE: delay should not be called from interrupt context 30660Sstevel@tonic-gate */ 30670Sstevel@tonic-gate ASSERT(!servicing_interrupt()); 30680Sstevel@tonic-gate 30690Sstevel@tonic-gate if (strncmp(caddr, "delay,", 6) == 0) { 30700Sstevel@tonic-gate p = caddr+6; 30710Sstevel@tonic-gate n = stoi(&p); 30720Sstevel@tonic-gate if (*p != 0) 30730Sstevel@tonic-gate n = 1; 30740Sstevel@tonic-gate if (pshot_debug) 30750Sstevel@tonic-gate cmn_err(CE_CONT, 30760Sstevel@tonic-gate "pshot%d: %s delay %d second\n", 30777656SSherry.Moore@Sun.COM ddi_get_instance(parent), devname, n); 30780Sstevel@tonic-gate delay(n * drv_usectohz(1000000)); 30790Sstevel@tonic-gate } else if (strncmp(caddr, "delay", 5) == 0) { 30800Sstevel@tonic-gate if (pshot_debug) 30810Sstevel@tonic-gate cmn_err(CE_CONT, 30820Sstevel@tonic-gate "pshot%d: %s delay 1 second\n", 30837656SSherry.Moore@Sun.COM ddi_get_instance(parent), devname); 30840Sstevel@tonic-gate delay(drv_usectohz(1000000)); 30850Sstevel@tonic-gate } else if (strncmp(caddr, "wait,", 5) == 0) { 30860Sstevel@tonic-gate p = caddr+5; 30870Sstevel@tonic-gate n = stoi(&p); 30880Sstevel@tonic-gate if (*p != 0) 30890Sstevel@tonic-gate n = 1; 30900Sstevel@tonic-gate if (pshot_debug) 30910Sstevel@tonic-gate cmn_err(CE_CONT, 30920Sstevel@tonic-gate "pshot%d: %s wait %d second\n", 30937656SSherry.Moore@Sun.COM ddi_get_instance(parent), devname, n); 30940Sstevel@tonic-gate delay(n * drv_usectohz(1000000)); 30950Sstevel@tonic-gate } else if (strncmp(caddr, "wait", 4) == 0) { 30960Sstevel@tonic-gate if (pshot_debug) 30970Sstevel@tonic-gate cmn_err(CE_CONT, 30980Sstevel@tonic-gate "pshot%d: %s wait 1 second\n", 30990Sstevel@tonic-gate ddi_get_instance(parent), devname); 31000Sstevel@tonic-gate delay(drv_usectohz(1000000)); 31010Sstevel@tonic-gate } 31020Sstevel@tonic-gate 31030Sstevel@tonic-gate return (NDI_SUCCESS); 31040Sstevel@tonic-gate } 31050Sstevel@tonic-gate 31060Sstevel@tonic-gate /* 31070Sstevel@tonic-gate * translate nodetype name to actual value 31080Sstevel@tonic-gate */ 31090Sstevel@tonic-gate static char * 31100Sstevel@tonic-gate pshot_str2nt(char *str) 31110Sstevel@tonic-gate { 31120Sstevel@tonic-gate int i; 31130Sstevel@tonic-gate 31140Sstevel@tonic-gate for (i = 0; pshot_nodetypes[i].name; i++) { 31150Sstevel@tonic-gate if (strcmp(pshot_nodetypes[i].name, str) == 0) 31160Sstevel@tonic-gate return (pshot_nodetypes[i].val); 31170Sstevel@tonic-gate } 31180Sstevel@tonic-gate return (NULL); 31190Sstevel@tonic-gate } 31200Sstevel@tonic-gate 31210Sstevel@tonic-gate /* 31220Sstevel@tonic-gate * grows array pointed to by <dstp>, with <src> data 31230Sstevel@tonic-gate * <dstlen> = # elements of the original <*dstp> 31240Sstevel@tonic-gate * <srclen> = # elements of <src> 31250Sstevel@tonic-gate * 31260Sstevel@tonic-gate * on success, returns 0 and a pointer to the new array through <dstp> with 31270Sstevel@tonic-gate * <srclen> + <dstlen> number of elements; 31280Sstevel@tonic-gate * else returns non-zero 31290Sstevel@tonic-gate * 31300Sstevel@tonic-gate * a NULL <*dstp> is OK (a NULL <dstp> is not) and so is a zero <dstlen> 31310Sstevel@tonic-gate */ 31320Sstevel@tonic-gate static int 31330Sstevel@tonic-gate pshot_devices_grow(pshot_device_t **dstp, size_t dstlen, 31340Sstevel@tonic-gate const pshot_device_t *src, size_t srclen) 31350Sstevel@tonic-gate { 31360Sstevel@tonic-gate size_t i; 31370Sstevel@tonic-gate pshot_device_t *newdst; 31380Sstevel@tonic-gate 31390Sstevel@tonic-gate newdst = kmem_alloc((srclen + dstlen) * sizeof (*src), 31400Sstevel@tonic-gate KM_SLEEP); 31410Sstevel@tonic-gate 31420Sstevel@tonic-gate /* keep old pointers and dup new ones */ 31430Sstevel@tonic-gate if (*dstp) 31440Sstevel@tonic-gate bcopy(*dstp, newdst, dstlen * sizeof (*src)); 31450Sstevel@tonic-gate for (i = 0; i < srclen; i++) { 31460Sstevel@tonic-gate newdst[i + dstlen].name = 31470Sstevel@tonic-gate i_ddi_strdup(src[i].name, KM_SLEEP); 31480Sstevel@tonic-gate 31490Sstevel@tonic-gate newdst[i + dstlen].nodetype = 31500Sstevel@tonic-gate i_ddi_strdup(src[i].nodetype, KM_SLEEP); 31510Sstevel@tonic-gate 31520Sstevel@tonic-gate newdst[i + dstlen].compat = 31530Sstevel@tonic-gate i_ddi_strdup(src[i].compat, KM_SLEEP); 31540Sstevel@tonic-gate } 31550Sstevel@tonic-gate 31560Sstevel@tonic-gate /* do last */ 31570Sstevel@tonic-gate if (*dstp) 31580Sstevel@tonic-gate kmem_free(*dstp, dstlen * sizeof (*src)); 31590Sstevel@tonic-gate *dstp = newdst; 31600Sstevel@tonic-gate return (0); 31610Sstevel@tonic-gate } 31620Sstevel@tonic-gate 31630Sstevel@tonic-gate /* 31640Sstevel@tonic-gate * free a pshot_device_t array <dp> with <len> elements 31650Sstevel@tonic-gate * null pointers within the elements are ok 31660Sstevel@tonic-gate */ 31670Sstevel@tonic-gate static void 31680Sstevel@tonic-gate pshot_devices_free(pshot_device_t *dp, size_t len) 31690Sstevel@tonic-gate { 31700Sstevel@tonic-gate size_t i; 31710Sstevel@tonic-gate 31720Sstevel@tonic-gate for (i = 0; i < len; i++) { 31730Sstevel@tonic-gate if (dp[i].name) 31740Sstevel@tonic-gate kmem_free(dp[i].name, strlen(dp[i].name) + 1); 31750Sstevel@tonic-gate if (dp[i].nodetype) 31760Sstevel@tonic-gate kmem_free(dp[i].nodetype, strlen(dp[i].nodetype) + 1); 31770Sstevel@tonic-gate if (dp[i].compat) 31780Sstevel@tonic-gate kmem_free(dp[i].compat, strlen(dp[i].compat) + 1); 31790Sstevel@tonic-gate } 31800Sstevel@tonic-gate kmem_free(dp, len * sizeof (*dp)); 31810Sstevel@tonic-gate } 31820Sstevel@tonic-gate 31830Sstevel@tonic-gate /* 31840Sstevel@tonic-gate * returns an array of pshot_device_t parsed from <dip>'s properties 31850Sstevel@tonic-gate * 31860Sstevel@tonic-gate * property structure (i.e. pshot.conf) for pshot: 31870Sstevel@tonic-gate * 31880Sstevel@tonic-gate * corresponding | pshot_device_t array elements 31890Sstevel@tonic-gate * pshot_device_t | 31900Sstevel@tonic-gate * member by prop name | [0] [1] [2] 31910Sstevel@tonic-gate * ----------------------|--------------|-------------|----------------------- 31920Sstevel@tonic-gate * <PSHOT_PROP_DEVNAME> ="disk", "tape", "testdev"; 31930Sstevel@tonic-gate * <PSHOT_PROP_DEVNT> ="DDI_NT_BLOCK","DDI_NT_TAPE","ddi_testdev_nodetype"; 31940Sstevel@tonic-gate * <PSHOT_PROP_DEVCOMPAT>="testdrv", "testdrv", "testdrv"; 31950Sstevel@tonic-gate * 31960Sstevel@tonic-gate * 31970Sstevel@tonic-gate * if any of these properties are specified, then: 31980Sstevel@tonic-gate * - all the members must be specified 31990Sstevel@tonic-gate * - the number of elements for each string array property must be the same 32000Sstevel@tonic-gate * - no empty strings allowed 32010Sstevel@tonic-gate * - nodetypes (PSHOT_PROP_DEVNT) must be the nodetype name as specified in 32020Sstevel@tonic-gate * sys/sunddi.h 32030Sstevel@tonic-gate * 32040Sstevel@tonic-gate * NOTE: the pshot_nodetypes[] table should be kept in sync with the list 32050Sstevel@tonic-gate * of ddi nodetypes. It's not normally critical to always be in sync so 32060Sstevel@tonic-gate * keeping this up-to-date can usually be done "on-demand". 32070Sstevel@tonic-gate * 32080Sstevel@tonic-gate * if <flags> & PSHOT_DEV_ANYNT, then custom nodetype strings are allowed. 32090Sstevel@tonic-gate * these will be duplicated verbatim 32100Sstevel@tonic-gate */ 32110Sstevel@tonic-gate static pshot_device_t * 32120Sstevel@tonic-gate pshot_devices_from_props(dev_info_t *dip, size_t *lenp, int flags) 32130Sstevel@tonic-gate { 32140Sstevel@tonic-gate pshot_device_t *devarr = NULL; 32150Sstevel@tonic-gate char **name_arr = NULL, **nt_arr = NULL, **compat_arr = NULL; 32160Sstevel@tonic-gate uint_t name_arr_len, nt_arr_len, compat_arr_len; 32170Sstevel@tonic-gate uint_t i; 32180Sstevel@tonic-gate char *str; 32190Sstevel@tonic-gate 32200Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, dip, 0, 32210Sstevel@tonic-gate PSHOT_PROP_DEVNAME, &name_arr, &name_arr_len) != 32220Sstevel@tonic-gate DDI_PROP_SUCCESS) 32230Sstevel@tonic-gate name_arr = NULL; 32240Sstevel@tonic-gate 32250Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, dip, 0, 32260Sstevel@tonic-gate PSHOT_PROP_DEVNT, &nt_arr, &nt_arr_len) != 32270Sstevel@tonic-gate DDI_PROP_SUCCESS) 32280Sstevel@tonic-gate nt_arr = NULL; 32290Sstevel@tonic-gate 32300Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, dip, 0, 32310Sstevel@tonic-gate PSHOT_PROP_DEVCOMPAT, &compat_arr, &compat_arr_len) != 32320Sstevel@tonic-gate DDI_PROP_SUCCESS) 32330Sstevel@tonic-gate compat_arr = NULL; 32340Sstevel@tonic-gate 32350Sstevel@tonic-gate /* 32360Sstevel@tonic-gate * warn about any incorrect usage, if specified 32370Sstevel@tonic-gate */ 32380Sstevel@tonic-gate if (!(name_arr || nt_arr || compat_arr)) 32390Sstevel@tonic-gate return (NULL); 32400Sstevel@tonic-gate 32410Sstevel@tonic-gate if (!(name_arr && nt_arr && compat_arr) || 32420Sstevel@tonic-gate (name_arr_len != nt_arr_len) || 32430Sstevel@tonic-gate (name_arr_len != compat_arr_len)) 32440Sstevel@tonic-gate goto FAIL; 32450Sstevel@tonic-gate 32460Sstevel@tonic-gate for (i = 0; i < name_arr_len; i++) { 32470Sstevel@tonic-gate if (*name_arr[i] == '\0' || 32480Sstevel@tonic-gate *nt_arr[i] == '\0' || 32490Sstevel@tonic-gate *compat_arr[i] == '\0') 32500Sstevel@tonic-gate goto FAIL; 32510Sstevel@tonic-gate } 32520Sstevel@tonic-gate 32530Sstevel@tonic-gate devarr = kmem_zalloc(name_arr_len * sizeof (*devarr), KM_SLEEP); 32540Sstevel@tonic-gate for (i = 0; i < name_arr_len; i++) { 32550Sstevel@tonic-gate devarr[i].name = i_ddi_strdup(name_arr[i], KM_SLEEP); 32560Sstevel@tonic-gate devarr[i].compat = i_ddi_strdup(compat_arr[i], KM_SLEEP); 32570Sstevel@tonic-gate 32580Sstevel@tonic-gate if ((str = pshot_str2nt(nt_arr[i])) == NULL) 32590Sstevel@tonic-gate if (flags & PSHOT_DEV_ANYNT) 32600Sstevel@tonic-gate str = nt_arr[i]; 32610Sstevel@tonic-gate else 32620Sstevel@tonic-gate goto FAIL; 32630Sstevel@tonic-gate devarr[i].nodetype = i_ddi_strdup(str, KM_SLEEP); 32640Sstevel@tonic-gate } 32650Sstevel@tonic-gate ddi_prop_free(name_arr); 32660Sstevel@tonic-gate ddi_prop_free(nt_arr); 32670Sstevel@tonic-gate ddi_prop_free(compat_arr); 32680Sstevel@tonic-gate 32690Sstevel@tonic-gate /* set <*lenp> ONLY on success */ 32700Sstevel@tonic-gate *lenp = name_arr_len; 32710Sstevel@tonic-gate 32720Sstevel@tonic-gate return (devarr); 32730Sstevel@tonic-gate /*NOTREACHED*/ 32740Sstevel@tonic-gate FAIL: 32750Sstevel@tonic-gate cmn_err(CE_WARN, "malformed device specification property"); 32760Sstevel@tonic-gate if (name_arr) 32770Sstevel@tonic-gate ddi_prop_free(name_arr); 32780Sstevel@tonic-gate if (nt_arr) 32790Sstevel@tonic-gate ddi_prop_free(nt_arr); 32800Sstevel@tonic-gate if (compat_arr) 32810Sstevel@tonic-gate ddi_prop_free(compat_arr); 32820Sstevel@tonic-gate if (devarr) 32830Sstevel@tonic-gate pshot_devices_free(devarr, name_arr_len); 32840Sstevel@tonic-gate return (NULL); 32850Sstevel@tonic-gate } 32860Sstevel@tonic-gate 32870Sstevel@tonic-gate /* 32880Sstevel@tonic-gate * if global <pshot_devices> was not set up already (i.e. is NULL): 32890Sstevel@tonic-gate * sets up global <pshot_devices> and <pshot_devices_len>, 32900Sstevel@tonic-gate * using device properties from <dip> and global <pshot_stock_devices>. 32910Sstevel@tonic-gate * device properties, if any, overrides pshot_stock_devices. 32920Sstevel@tonic-gate * 32930Sstevel@tonic-gate * returns 0 on success (or if pshot_devices already set up) 32940Sstevel@tonic-gate * 32950Sstevel@tonic-gate * INTERNAL LOCKING: <pshot_devices_lock> 32960Sstevel@tonic-gate */ 32970Sstevel@tonic-gate static int 32980Sstevel@tonic-gate pshot_devices_setup(dev_info_t *dip) 32990Sstevel@tonic-gate { 33000Sstevel@tonic-gate pshot_device_t *newdevs = NULL; 33010Sstevel@tonic-gate size_t newdevs_len = 0; 33020Sstevel@tonic-gate int rv = 0; 33030Sstevel@tonic-gate 33040Sstevel@tonic-gate mutex_enter(&pshot_devices_lock); 33050Sstevel@tonic-gate if (pshot_devices != NULL) 33060Sstevel@tonic-gate goto FAIL; 33070Sstevel@tonic-gate 33080Sstevel@tonic-gate ASSERT(pshot_devices_len == 0); 33090Sstevel@tonic-gate 33100Sstevel@tonic-gate newdevs = pshot_devices_from_props(dip, &newdevs_len, PSHOT_DEV_ANYNT); 33110Sstevel@tonic-gate rv = pshot_devices_grow(&newdevs, newdevs_len, pshot_stock_devices, 33120Sstevel@tonic-gate PSHOT_N_STOCK_DEVICES); 33130Sstevel@tonic-gate if (rv != 0) { 33140Sstevel@tonic-gate cmn_err(CE_WARN, "pshot_devices_setup: pshot_devices_grow " 33150Sstevel@tonic-gate "failed"); 33160Sstevel@tonic-gate goto FAIL; 33170Sstevel@tonic-gate } 33180Sstevel@tonic-gate newdevs_len += PSHOT_N_STOCK_DEVICES; 33190Sstevel@tonic-gate 33200Sstevel@tonic-gate pshot_devices = newdevs; 33210Sstevel@tonic-gate pshot_devices_len = newdevs_len; 33220Sstevel@tonic-gate rv = 0; 33230Sstevel@tonic-gate FAIL: 33240Sstevel@tonic-gate if (rv && newdevs) 33250Sstevel@tonic-gate pshot_devices_free(newdevs, newdevs_len); 33260Sstevel@tonic-gate mutex_exit(&pshot_devices_lock); 33270Sstevel@tonic-gate return (rv); 33280Sstevel@tonic-gate } 33290Sstevel@tonic-gate 33300Sstevel@tonic-gate 33310Sstevel@tonic-gate #ifdef NOTNEEDED 33320Sstevel@tonic-gate /* ARGSUSED */ 33330Sstevel@tonic-gate static int 33340Sstevel@tonic-gate pshot_probe_family(dev_info_t *self, ddi_probe_method_t probe_how, 33350Sstevel@tonic-gate dev_info_t **return_dip) 33360Sstevel@tonic-gate { 33370Sstevel@tonic-gate char name[64]; 33380Sstevel@tonic-gate uint_t bus_id; 33390Sstevel@tonic-gate dev_info_t *child; 33400Sstevel@tonic-gate 33410Sstevel@tonic-gate for (bus_id = 10; bus_id < 20; bus_id++) { 33420Sstevel@tonic-gate (void) sprintf(name, "%d", bus_id); 33430Sstevel@tonic-gate if ((ndi_devi_alloc(self, "psramd", DEVI_SID_NODEID, 33440Sstevel@tonic-gate &child)) != NDI_SUCCESS) { 33450Sstevel@tonic-gate return (DDI_FAILURE); 33460Sstevel@tonic-gate } 33470Sstevel@tonic-gate 33480Sstevel@tonic-gate if (ndi_prop_update_string(DDI_DEV_T_NONE, child, 33490Sstevel@tonic-gate "bus-addr", name) != DDI_PROP_SUCCESS) { 33500Sstevel@tonic-gate (void) ndi_devi_free(child); 33510Sstevel@tonic-gate if (return_dip != NULL) 33520Sstevel@tonic-gate *return_dip = (dev_info_t *)NULL; 33530Sstevel@tonic-gate return (DDI_FAILURE); 33540Sstevel@tonic-gate } 33550Sstevel@tonic-gate 33560Sstevel@tonic-gate if (ndi_devi_online(child, 0) != NDI_SUCCESS) { 33570Sstevel@tonic-gate return (DDI_FAILURE); 33580Sstevel@tonic-gate } 33590Sstevel@tonic-gate } 33600Sstevel@tonic-gate return (DDI_SUCCESS); 33610Sstevel@tonic-gate } 336285Scth 33630Sstevel@tonic-gate static int 33640Sstevel@tonic-gate strtoi(char *str) 33650Sstevel@tonic-gate { 33660Sstevel@tonic-gate int c; 33670Sstevel@tonic-gate int val; 33680Sstevel@tonic-gate 33690Sstevel@tonic-gate for (val = 0, c = *str++; c >= '0' && c <= '9'; c = *str++) { 33700Sstevel@tonic-gate val *= 10; 33710Sstevel@tonic-gate val += c - '0'; 33720Sstevel@tonic-gate } 33730Sstevel@tonic-gate return (val); 33740Sstevel@tonic-gate } 33750Sstevel@tonic-gate 337685Scth #endif 33770Sstevel@tonic-gate 33780Sstevel@tonic-gate static void 33790Sstevel@tonic-gate pshot_setup_autoattach(dev_info_t *devi) 33800Sstevel@tonic-gate { 33810Sstevel@tonic-gate dev_info_t *l1child, *l2child; 33820Sstevel@tonic-gate int rv; 33830Sstevel@tonic-gate 33840Sstevel@tonic-gate rv = ndi_devi_alloc(devi, "pshot", DEVI_SID_NODEID, &l1child); 33850Sstevel@tonic-gate if (rv == NDI_SUCCESS) { 33860Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, l1child, 33870Sstevel@tonic-gate "bus-addr", "0"); 33880Sstevel@tonic-gate rv = ndi_devi_alloc(l1child, "port", DEVI_SID_NODEID, 33890Sstevel@tonic-gate &l2child); 33900Sstevel@tonic-gate if (rv == NDI_SUCCESS) 33910Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, 33920Sstevel@tonic-gate l2child, "bus-addr", "99"); 33930Sstevel@tonic-gate } 33940Sstevel@tonic-gate 33950Sstevel@tonic-gate rv = ndi_devi_alloc(devi, "port", DEVI_SID_NODEID, &l1child); 33960Sstevel@tonic-gate if (rv == NDI_SUCCESS) 33970Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, l1child, 33980Sstevel@tonic-gate "bus-addr", "99"); 33990Sstevel@tonic-gate 34000Sstevel@tonic-gate rv = ndi_devi_alloc(devi, "gen_drv", DEVI_SID_NODEID, &l1child); 34010Sstevel@tonic-gate if (rv == NDI_SUCCESS) 34020Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, l1child, 34030Sstevel@tonic-gate "bus-addr", "99"); 34040Sstevel@tonic-gate 34050Sstevel@tonic-gate rv = ndi_devi_alloc(devi, "no_driver", DEVI_SID_NODEID, &l1child); 34060Sstevel@tonic-gate if (rv == NDI_SUCCESS) 34070Sstevel@tonic-gate (void) ndi_devi_alloc(l1child, "no_driver", DEVI_SID_NODEID, 34080Sstevel@tonic-gate &l2child); 34090Sstevel@tonic-gate } 34100Sstevel@tonic-gate 34110Sstevel@tonic-gate #ifdef PRUNE_SNUBS 34120Sstevel@tonic-gate 34130Sstevel@tonic-gate #define PRUNE_THIS_NODE(d) (((d)->devi_node_name != NULL) && \ 34140Sstevel@tonic-gate (DEVI_PROM_NODE((d)->devi_nodeid)) && \ 34150Sstevel@tonic-gate ((d)->devi_addr == NULL)) 34160Sstevel@tonic-gate /* 34170Sstevel@tonic-gate * test code to remove OBP nodes that have not attached 34180Sstevel@tonic-gate */ 34190Sstevel@tonic-gate static void 34200Sstevel@tonic-gate prune_snubs(const char *name) 34210Sstevel@tonic-gate { 34220Sstevel@tonic-gate struct dev_info *nex_dip, *cdip, *cndip; 34230Sstevel@tonic-gate int maj; 34240Sstevel@tonic-gate int rv; 34250Sstevel@tonic-gate 34260Sstevel@tonic-gate maj = ddi_name_to_major((char *)name); 34270Sstevel@tonic-gate if (maj != -1) { 34280Sstevel@tonic-gate nex_dip = (struct dev_info *)devnamesp[maj].dn_head; 34290Sstevel@tonic-gate while (nex_dip != NULL) { 34300Sstevel@tonic-gate cndip = ddi_get_child(nex_dip); 34310Sstevel@tonic-gate while ((cdip = cndip) != NULL) { 34320Sstevel@tonic-gate cndip = cdip->devi_sibling; 34330Sstevel@tonic-gate if (PRUNE_THIS_NODE(cdip)) { 34340Sstevel@tonic-gate cmn_err(CE_NOTE, 34350Sstevel@tonic-gate "parent %s@%s pruning node %s", 34360Sstevel@tonic-gate nex_dip->devi_node_name, 34370Sstevel@tonic-gate nex_dip->devi_addr, 34380Sstevel@tonic-gate cdip->devi_node_name); 34390Sstevel@tonic-gate rv = ndi_devi_offline(cdip, 34400Sstevel@tonic-gate NDI_DEVI_REMOVE); 34410Sstevel@tonic-gate if (rv != NDI_SUCCESS) 34420Sstevel@tonic-gate cmn_err(CE_NOTE, 34430Sstevel@tonic-gate "failed to prune node, " 34440Sstevel@tonic-gate "err %d", rv); 34450Sstevel@tonic-gate } 34460Sstevel@tonic-gate } 34470Sstevel@tonic-gate nex_dip = nex_dip->devi_next; 34480Sstevel@tonic-gate } 34490Sstevel@tonic-gate } 34500Sstevel@tonic-gate } 34510Sstevel@tonic-gate 34520Sstevel@tonic-gate #endif /* PRUBE_SNUBS */ 34530Sstevel@tonic-gate 34540Sstevel@tonic-gate #ifdef KERNEL_DEVICE_TREE_WALKER 34550Sstevel@tonic-gate static kthread_id_t pwt; 34560Sstevel@tonic-gate static kmutex_t pwl; 34570Sstevel@tonic-gate static kcondvar_t pwcv; 34580Sstevel@tonic-gate 34590Sstevel@tonic-gate static void 34600Sstevel@tonic-gate pshot_walk_tree() 34610Sstevel@tonic-gate { 34620Sstevel@tonic-gate static int pshot_devnode(dev_info_t *dip, void * arg); 34630Sstevel@tonic-gate 34640Sstevel@tonic-gate dev_info_t *root = ddi_root_node(); 34650Sstevel@tonic-gate ddi_walk_devs(root, pshot_devnode, NULL); 34660Sstevel@tonic-gate } 34670Sstevel@tonic-gate 34680Sstevel@tonic-gate static void 34690Sstevel@tonic-gate pshot_walk_thread() 34700Sstevel@tonic-gate { 34710Sstevel@tonic-gate static void pshot_timeout(void *arg); 34720Sstevel@tonic-gate static kthread_id_t pwt; 34730Sstevel@tonic-gate 34740Sstevel@tonic-gate pwt = curthread; 34750Sstevel@tonic-gate mutex_init(&pwl, NULL, MUTEX_DRIVER, NULL); 34760Sstevel@tonic-gate cv_init(&pwcv, NULL, CV_DRIVER, NULL); 34770Sstevel@tonic-gate 34780Sstevel@tonic-gate while (1) { 34790Sstevel@tonic-gate pshot_walk_tree(); 34800Sstevel@tonic-gate mutex_enter(&pwl); 34810Sstevel@tonic-gate (void) timeout(pshot_timeout, NULL, 5 * drv_usectohz(1000000)); 34820Sstevel@tonic-gate cv_wait(&pwcv, &pwl); 34830Sstevel@tonic-gate mutex_exit(&pwl); 34840Sstevel@tonic-gate } 34850Sstevel@tonic-gate } 34860Sstevel@tonic-gate 34870Sstevel@tonic-gate static void 34880Sstevel@tonic-gate pshot_timeout(void *arg) 34890Sstevel@tonic-gate { 34900Sstevel@tonic-gate mutex_enter(&pwl); 34910Sstevel@tonic-gate cv_signal(&pwcv); 34920Sstevel@tonic-gate mutex_exit(&pwl); 34930Sstevel@tonic-gate } 34940Sstevel@tonic-gate 34950Sstevel@tonic-gate static int 34960Sstevel@tonic-gate pshot_devnode(dev_info_t *dip, void *arg) 34970Sstevel@tonic-gate { 34980Sstevel@tonic-gate dev_info_t *f_dip; 34990Sstevel@tonic-gate 35000Sstevel@tonic-gate if (dip != ddi_root_node()) { 35010Sstevel@tonic-gate f_dip = ndi_devi_find((dev_info_t *)DEVI(dip)->devi_parent, 35020Sstevel@tonic-gate DEVI(dip)->devi_node_name, DEVI(dip)->devi_addr); 35030Sstevel@tonic-gate if (f_dip != dip) { 35040Sstevel@tonic-gate cmn_err(CE_NOTE, "!pshot_devnode: failed lookup" 35057656SSherry.Moore@Sun.COM "node (%s/%s@%s)\n", 35067656SSherry.Moore@Sun.COM DEVI(DEVI(dip)->devi_parent)->devi_node_name, 35077656SSherry.Moore@Sun.COM (DEVI(dip)->devi_node_name ? 35087656SSherry.Moore@Sun.COM DEVI(dip)->devi_node_name : "NULL"), 35097656SSherry.Moore@Sun.COM (DEVI(dip)->devi_addr ? DEVI(dip)->devi_addr : 35107656SSherry.Moore@Sun.COM "NULL")); 35110Sstevel@tonic-gate } 35120Sstevel@tonic-gate } 35130Sstevel@tonic-gate return (DDI_WALK_CONTINUE); 35140Sstevel@tonic-gate } 35150Sstevel@tonic-gate #endif /* KERNEL_DEVICE_TREE_WALKER */ 35160Sstevel@tonic-gate 35170Sstevel@tonic-gate #ifdef DEBUG 35180Sstevel@tonic-gate static void 35190Sstevel@tonic-gate pshot_event_cb_test(dev_info_t *dip, ddi_eventcookie_t cookie, 35200Sstevel@tonic-gate void *arg, void *bus_impldata) 35210Sstevel@tonic-gate { 35220Sstevel@tonic-gate pshot_t *softstate = (pshot_t *)arg; 35230Sstevel@tonic-gate int event_tag; 35240Sstevel@tonic-gate 35250Sstevel@tonic-gate /* look up the event */ 35260Sstevel@tonic-gate event_tag = NDI_EVENT_TAG(cookie); 35270Sstevel@tonic-gate cmn_err(CE_CONT, "pshot_event_cb_test:\n\t" 35280Sstevel@tonic-gate "dip = 0x%p cookie = 0x%p (%s), tag = %d\n\t" 35290Sstevel@tonic-gate "arg = 0x%p bus_impl = 0x%p\n", 35300Sstevel@tonic-gate (void *)dip, (void *)cookie, NDI_EVENT_NAME(cookie), 35310Sstevel@tonic-gate event_tag, (void *)softstate, (void *)bus_impldata); 35320Sstevel@tonic-gate 35330Sstevel@tonic-gate } 35340Sstevel@tonic-gate 35350Sstevel@tonic-gate static void 35360Sstevel@tonic-gate pshot_event_test(void *arg) 35370Sstevel@tonic-gate { 35380Sstevel@tonic-gate pshot_t *pshot = (pshot_t *)arg; 35390Sstevel@tonic-gate ndi_event_hdl_t hdl; 35400Sstevel@tonic-gate ndi_event_set_t events; 35410Sstevel@tonic-gate int i, rval; 35420Sstevel@tonic-gate 35430Sstevel@tonic-gate (void) ndi_event_alloc_hdl(pshot->dip, NULL, &hdl, NDI_SLEEP); 35440Sstevel@tonic-gate 35450Sstevel@tonic-gate events.ndi_events_version = NDI_EVENTS_REV1; 35460Sstevel@tonic-gate events.ndi_n_events = PSHOT_N_TEST_EVENTS; 35470Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events; 35480Sstevel@tonic-gate 35490Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: binding set of 8 events\n"); 35500Sstevel@tonic-gate delay(drv_usectohz(1000000)); 35510Sstevel@tonic-gate rval = ndi_event_bind_set(hdl, &events, NDI_SLEEP); 35520Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval); 35530Sstevel@tonic-gate 35540Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: binding the same set of 8 events\n"); 35550Sstevel@tonic-gate delay(drv_usectohz(1000000)); 35560Sstevel@tonic-gate rval = ndi_event_bind_set(hdl, &events, NDI_SLEEP); 35570Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval); 35580Sstevel@tonic-gate 35590Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding all events\n"); 35600Sstevel@tonic-gate delay(drv_usectohz(1000000)); 35610Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP); 35620Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval); 35630Sstevel@tonic-gate 35640Sstevel@tonic-gate 35650Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: binding one highlevel event\n"); 35660Sstevel@tonic-gate delay(drv_usectohz(1000000)); 35670Sstevel@tonic-gate events.ndi_n_events = 1; 35680Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events_high; 35690Sstevel@tonic-gate rval = ndi_event_bind_set(hdl, &events, NDI_SLEEP); 35700Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval); 35710Sstevel@tonic-gate 35720Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: binding the same set of 8 events\n"); 35730Sstevel@tonic-gate delay(drv_usectohz(1000000)); 35740Sstevel@tonic-gate events.ndi_n_events = PSHOT_N_TEST_EVENTS; 35750Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events; 35760Sstevel@tonic-gate rval = ndi_event_bind_set(hdl, &events, NDI_SLEEP); 35770Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval); 35780Sstevel@tonic-gate 35790Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding one highlevel event\n"); 35800Sstevel@tonic-gate delay(drv_usectohz(1000000)); 35810Sstevel@tonic-gate events.ndi_n_events = 1; 35820Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events_high; 35830Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP); 35840Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval); 35850Sstevel@tonic-gate 35860Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: binding one highlevel event\n"); 35870Sstevel@tonic-gate delay(drv_usectohz(1000000)); 35880Sstevel@tonic-gate events.ndi_n_events = 1; 35890Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events_high; 35900Sstevel@tonic-gate rval = ndi_event_bind_set(hdl, &events, NDI_SLEEP); 35910Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval); 35920Sstevel@tonic-gate 35930Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding one highlevel event\n"); 35940Sstevel@tonic-gate delay(drv_usectohz(1000000)); 35950Sstevel@tonic-gate events.ndi_n_events = 1; 35960Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events_high; 35970Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP); 35980Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval); 35990Sstevel@tonic-gate 36000Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: binding the same set of 8 events\n"); 36010Sstevel@tonic-gate delay(drv_usectohz(1000000)); 36020Sstevel@tonic-gate events.ndi_n_events = PSHOT_N_TEST_EVENTS; 36030Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events; 36040Sstevel@tonic-gate rval = ndi_event_bind_set(hdl, &events, NDI_SLEEP); 36050Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval); 36060Sstevel@tonic-gate 36070Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding first 2 events\n"); 36080Sstevel@tonic-gate delay(drv_usectohz(1000000)); 36090Sstevel@tonic-gate events.ndi_n_events = 2; 36100Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events; 36110Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP); 36120Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval); 36130Sstevel@tonic-gate 36140Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding first 2 events again\n"); 36150Sstevel@tonic-gate delay(drv_usectohz(1000000)); 36160Sstevel@tonic-gate events.ndi_n_events = 2; 36170Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events; 36180Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP); 36190Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval); 36200Sstevel@tonic-gate 36210Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding middle 2 events\n"); 36220Sstevel@tonic-gate delay(drv_usectohz(1000000)); 36230Sstevel@tonic-gate events.ndi_n_events = 2; 36240Sstevel@tonic-gate events.ndi_event_defs = &pshot_test_events[4]; 36250Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP); 36260Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval); 36270Sstevel@tonic-gate 36280Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: binding those 2 events back\n"); 36290Sstevel@tonic-gate delay(drv_usectohz(1000000)); 36300Sstevel@tonic-gate events.ndi_n_events = 2; 36310Sstevel@tonic-gate events.ndi_event_defs = &pshot_test_events[4]; 36320Sstevel@tonic-gate rval = ndi_event_bind_set(hdl, &events, NDI_SLEEP); 36330Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval); 36340Sstevel@tonic-gate 36350Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding 2 events\n"); 36360Sstevel@tonic-gate delay(drv_usectohz(1000000)); 36370Sstevel@tonic-gate events.ndi_n_events = 2; 36380Sstevel@tonic-gate events.ndi_event_defs = &pshot_test_events[4]; 36390Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP); 36400Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval); 36410Sstevel@tonic-gate 36420Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding all events\n"); 36430Sstevel@tonic-gate delay(drv_usectohz(1000000)); 36440Sstevel@tonic-gate events.ndi_n_events = PSHOT_N_TEST_EVENTS; 36450Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events; 36460Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP); 36470Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval); 36480Sstevel@tonic-gate 36490Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding 1 event\n"); 36500Sstevel@tonic-gate delay(drv_usectohz(1000000)); 36510Sstevel@tonic-gate events.ndi_n_events = 1; 36520Sstevel@tonic-gate events.ndi_event_defs = &pshot_test_events[2]; 36530Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP); 36540Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval); 36550Sstevel@tonic-gate 36560Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding 1 event\n"); 36570Sstevel@tonic-gate delay(drv_usectohz(1000000)); 36580Sstevel@tonic-gate events.ndi_n_events = 1; 36590Sstevel@tonic-gate events.ndi_event_defs = &pshot_test_events[3]; 36600Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP); 36610Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval); 36620Sstevel@tonic-gate 36630Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding 1 event\n"); 36640Sstevel@tonic-gate delay(drv_usectohz(1000000)); 36650Sstevel@tonic-gate events.ndi_n_events = 1; 36660Sstevel@tonic-gate events.ndi_event_defs = &pshot_test_events[6]; 36670Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP); 36680Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval); 36690Sstevel@tonic-gate 36700Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding 1 event\n"); 36710Sstevel@tonic-gate delay(drv_usectohz(1000000)); 36720Sstevel@tonic-gate events.ndi_n_events = 1; 36730Sstevel@tonic-gate events.ndi_event_defs = &pshot_test_events[7]; 36740Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP); 36750Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval); 36760Sstevel@tonic-gate 36770Sstevel@tonic-gate events.ndi_n_events = PSHOT_N_TEST_EVENTS; 36780Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events; 36790Sstevel@tonic-gate 36800Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: binding set of 8 events\n"); 36810Sstevel@tonic-gate delay(drv_usectohz(1000000)); 36820Sstevel@tonic-gate rval = ndi_event_bind_set(hdl, &events, NDI_SLEEP); 36830Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval); 36840Sstevel@tonic-gate 36850Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: adding 8 callbacks\n"); 36860Sstevel@tonic-gate delay(drv_usectohz(1000000)); 36870Sstevel@tonic-gate for (i = 0; i < 8; i++) { 36880Sstevel@tonic-gate rval = ndi_event_add_callback(hdl, pshot->dip, 36897656SSherry.Moore@Sun.COM ndi_event_tag_to_cookie(hdl, 36907656SSherry.Moore@Sun.COM pshot_test_events[i].ndi_event_tag), 36917656SSherry.Moore@Sun.COM pshot_event_cb_test, 36927656SSherry.Moore@Sun.COM (void *)(uintptr_t)pshot_test_events[i].ndi_event_tag, 36937656SSherry.Moore@Sun.COM NDI_SLEEP, &pshot->test_callback_cache[i]); 36940Sstevel@tonic-gate ASSERT(rval == NDI_SUCCESS); 36950Sstevel@tonic-gate } 36960Sstevel@tonic-gate 36970Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: event callbacks\n"); 36980Sstevel@tonic-gate 36990Sstevel@tonic-gate for (i = 10; i < 18; i++) { 37000Sstevel@tonic-gate ddi_eventcookie_t cookie = ndi_event_tag_to_cookie(hdl, i); 37010Sstevel@tonic-gate 37020Sstevel@tonic-gate rval = ndi_event_run_callbacks(hdl, pshot->dip, cookie, 37030Sstevel@tonic-gate (void *)hdl); 37040Sstevel@tonic-gate 37050Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: callback, tag=%d rval=%d\n", 37067656SSherry.Moore@Sun.COM i, rval); 37070Sstevel@tonic-gate delay(drv_usectohz(1000000)); 37080Sstevel@tonic-gate } 37090Sstevel@tonic-gate 37100Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: redo event callbacks\n"); 37110Sstevel@tonic-gate 37120Sstevel@tonic-gate for (i = 10; i < 18; i++) { 37130Sstevel@tonic-gate ddi_eventcookie_t cookie = ndi_event_tag_to_cookie(hdl, i); 37140Sstevel@tonic-gate 37150Sstevel@tonic-gate rval = ndi_event_run_callbacks(hdl, 37167656SSherry.Moore@Sun.COM pshot->dip, cookie, (void *)hdl); 37170Sstevel@tonic-gate 37180Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: callback, tag=%d rval=%d\n", 37197656SSherry.Moore@Sun.COM i, rval); 37200Sstevel@tonic-gate delay(drv_usectohz(1000000)); 37210Sstevel@tonic-gate } 37220Sstevel@tonic-gate 37230Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: removing 8 callbacks\n"); 37240Sstevel@tonic-gate delay(drv_usectohz(1000000)); 37250Sstevel@tonic-gate 37260Sstevel@tonic-gate for (i = 0; i < 8; i++) { 37270Sstevel@tonic-gate (void) ndi_event_remove_callback(hdl, 37280Sstevel@tonic-gate pshot->test_callback_cache[i]); 37290Sstevel@tonic-gate 37300Sstevel@tonic-gate pshot->test_callback_cache[i] = 0; 37310Sstevel@tonic-gate } 37320Sstevel@tonic-gate 37330Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: freeing handle with bound set\n"); 37340Sstevel@tonic-gate delay(drv_usectohz(1000000)); 37350Sstevel@tonic-gate 37360Sstevel@tonic-gate rval = ndi_event_free_hdl(hdl); 37370Sstevel@tonic-gate 37380Sstevel@tonic-gate ASSERT(rval == NDI_SUCCESS); 37390Sstevel@tonic-gate 37400Sstevel@tonic-gate } 37410Sstevel@tonic-gate 37420Sstevel@tonic-gate void 37430Sstevel@tonic-gate pshot_event_test_post_one(void *arg) 37440Sstevel@tonic-gate { 37450Sstevel@tonic-gate pshot_t *pshot = (pshot_t *)arg; 37460Sstevel@tonic-gate int rval; 37470Sstevel@tonic-gate ddi_eventcookie_t cookie; 37480Sstevel@tonic-gate 37490Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: pshot_event_post_one event\n", 37507656SSherry.Moore@Sun.COM pshot->instance); 37510Sstevel@tonic-gate 37520Sstevel@tonic-gate if (ddi_get_eventcookie(pshot->dip, PSHOT_EVENT_NAME_BUS_TEST_POST, 37530Sstevel@tonic-gate &cookie) != DDI_SUCCESS) { 37540Sstevel@tonic-gate cmn_err(CE_NOTE, "pshot_bus_test_post cookie not found"); 37550Sstevel@tonic-gate return; 37560Sstevel@tonic-gate } 37570Sstevel@tonic-gate 37580Sstevel@tonic-gate rval = ndi_post_event(pshot->dip, pshot->dip, cookie, NULL); 37590Sstevel@tonic-gate 37600Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: pshot_event_post_one rval=%d\n", 37617656SSherry.Moore@Sun.COM pshot->instance, rval); 37620Sstevel@tonic-gate 37630Sstevel@tonic-gate (void) timeout(pshot_event_test_post_one, (void *)pshot, 37647656SSherry.Moore@Sun.COM pshot->instance * drv_usectohz(60000000)); 37650Sstevel@tonic-gate 37660Sstevel@tonic-gate } 37670Sstevel@tonic-gate #endif /* DEBUG */ 3768