17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate * CDDL HEADER START
37c478bd9Sstevel@tonic-gate *
47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
55e3986cbScth * Common Development and Distribution License (the "License").
65e3986cbScth * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate *
87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate * and limitations under the License.
127c478bd9Sstevel@tonic-gate *
137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate *
197c478bd9Sstevel@tonic-gate * CDDL HEADER END
207c478bd9Sstevel@tonic-gate */
217c478bd9Sstevel@tonic-gate /*
2208492e39SVikram Hegde * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
237c478bd9Sstevel@tonic-gate * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate */
25*cd21e7c5SGarrett D'Amore /*
26*cd21e7c5SGarrett D'Amore * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved.
27*cd21e7c5SGarrett D'Amore */
287c478bd9Sstevel@tonic-gate
297c478bd9Sstevel@tonic-gate /*
307c478bd9Sstevel@tonic-gate * pseudo bus nexus driver
317c478bd9Sstevel@tonic-gate * hotplug framework test facility
327c478bd9Sstevel@tonic-gate */
337c478bd9Sstevel@tonic-gate
347c478bd9Sstevel@tonic-gate /*
357c478bd9Sstevel@tonic-gate * The pshot driver can be used to exercise the i/o framework together
367c478bd9Sstevel@tonic-gate * with devfs by configuring an arbitrarily complex device tree.
377c478bd9Sstevel@tonic-gate *
387c478bd9Sstevel@tonic-gate * The pshot driver is rooted at /devices/pshot. The following commands
397c478bd9Sstevel@tonic-gate * illustrate the operation of devfs together with pshot's bus_config.
407c478bd9Sstevel@tonic-gate * The first command demonstrates that, like the magician showing there's
417c478bd9Sstevel@tonic-gate * nothing up his sleeve, /devices/pshot is empty. The second command
427c478bd9Sstevel@tonic-gate * conjures up a branch of pshot nodes. Note that pshot's bus_config is
437c478bd9Sstevel@tonic-gate * called sequentially by devfs for each node, as part of the pathname
447c478bd9Sstevel@tonic-gate * resolution, and that each pshot node is fully configured and
457c478bd9Sstevel@tonic-gate * attached before that node's bus_config is called to configure the
467c478bd9Sstevel@tonic-gate * next child down the tree. The final result is a "disk" node configured
477c478bd9Sstevel@tonic-gate * at the bottom of the named hierarchy of pshot nodes.
487c478bd9Sstevel@tonic-gate *
497c478bd9Sstevel@tonic-gate * #
507c478bd9Sstevel@tonic-gate * # ls /devices/pshot
517c478bd9Sstevel@tonic-gate * #
527c478bd9Sstevel@tonic-gate * # ls -ld /devices/pshot/pshot@0/pshot@1/pshot@2/disk@3,0
537c478bd9Sstevel@tonic-gate * drwxr-xr-x 2 root sys 512 Feb 6 15:10
547c478bd9Sstevel@tonic-gate * /devices/pshot/pshot@0/pshot@1/pshot@2/disk@3,0
557c478bd9Sstevel@tonic-gate *
567c478bd9Sstevel@tonic-gate * pshot supports some unique behaviors as aids for test error cases.
577c478bd9Sstevel@tonic-gate *
587c478bd9Sstevel@tonic-gate * Match these special address formats to behavior:
597c478bd9Sstevel@tonic-gate *
607c478bd9Sstevel@tonic-gate * err.* - induce bus_config error
617c478bd9Sstevel@tonic-gate * delay - induce 1 second of bus_config delay time
627c478bd9Sstevel@tonic-gate * delay,n - induce n seconds of bus_config delay time
637c478bd9Sstevel@tonic-gate * wait - induce 1 second of bus_config wait time
647c478bd9Sstevel@tonic-gate * wait,n - induce n seconds of bus_config wait time
657c478bd9Sstevel@tonic-gate * failinit.* - induce error at INITCHILD
667c478bd9Sstevel@tonic-gate * failprobe.* - induce error at probe
677c478bd9Sstevel@tonic-gate * failattach.* - induce error at attach
687c478bd9Sstevel@tonic-gate */
697c478bd9Sstevel@tonic-gate
707c478bd9Sstevel@tonic-gate #if defined(lint) && !defined(DEBUG)
717c478bd9Sstevel@tonic-gate #define DEBUG 1
727c478bd9Sstevel@tonic-gate #endif
737c478bd9Sstevel@tonic-gate
747c478bd9Sstevel@tonic-gate #include <sys/types.h>
757c478bd9Sstevel@tonic-gate #include <sys/cmn_err.h>
767c478bd9Sstevel@tonic-gate #include <sys/conf.h>
777c478bd9Sstevel@tonic-gate #include <sys/ddi_impldefs.h>
787c478bd9Sstevel@tonic-gate #include <sys/autoconf.h>
797c478bd9Sstevel@tonic-gate #include <sys/open.h>
807c478bd9Sstevel@tonic-gate #include <sys/stat.h>
817c478bd9Sstevel@tonic-gate #include <sys/file.h>
827c478bd9Sstevel@tonic-gate #include <sys/errno.h>
837c478bd9Sstevel@tonic-gate #include <sys/systm.h>
847c478bd9Sstevel@tonic-gate #include <sys/modctl.h>
857c478bd9Sstevel@tonic-gate #include <sys/kmem.h>
867c478bd9Sstevel@tonic-gate #include <sys/ddi.h>
877c478bd9Sstevel@tonic-gate #include <sys/sunddi.h>
887c478bd9Sstevel@tonic-gate #include <sys/sunndi.h>
897c478bd9Sstevel@tonic-gate #include <sys/devctl.h>
907c478bd9Sstevel@tonic-gate #include <sys/disp.h>
917c478bd9Sstevel@tonic-gate #include <sys/utsname.h>
927c478bd9Sstevel@tonic-gate #include <sys/pshot.h>
937c478bd9Sstevel@tonic-gate #include <sys/debug.h>
947c478bd9Sstevel@tonic-gate
957c478bd9Sstevel@tonic-gate static int pshot_log = 0;
967c478bd9Sstevel@tonic-gate static int pshot_devctl_debug = 0;
977c478bd9Sstevel@tonic-gate static int pshot_debug_busy = 0;
987c478bd9Sstevel@tonic-gate
997c478bd9Sstevel@tonic-gate static void *pshot_softstatep;
1007c478bd9Sstevel@tonic-gate
1017c478bd9Sstevel@tonic-gate static int pshot_prop_autoattach;
1027c478bd9Sstevel@tonic-gate
1037c478bd9Sstevel@tonic-gate #define MAXPWR 3
1047c478bd9Sstevel@tonic-gate
1057c478bd9Sstevel@tonic-gate
1067c478bd9Sstevel@tonic-gate /*
1077c478bd9Sstevel@tonic-gate * device configuration data
1087c478bd9Sstevel@tonic-gate */
1097c478bd9Sstevel@tonic-gate
1107c478bd9Sstevel@tonic-gate /* should keep in sync with current release */
1117c478bd9Sstevel@tonic-gate static struct {
1127c478bd9Sstevel@tonic-gate char *name;
1137c478bd9Sstevel@tonic-gate char *val;
1147c478bd9Sstevel@tonic-gate } pshot_nodetypes[] = {
1157c478bd9Sstevel@tonic-gate {"DDI_NT_SERIAL", DDI_NT_SERIAL},
1167c478bd9Sstevel@tonic-gate {"DDI_NT_SERIAL_MB", DDI_NT_SERIAL_MB},
1177c478bd9Sstevel@tonic-gate {"DDI_NT_SERIAL_DO", DDI_NT_SERIAL_DO},
1187c478bd9Sstevel@tonic-gate {"DDI_NT_SERIAL_MB_DO", DDI_NT_SERIAL_MB_DO},
1197c478bd9Sstevel@tonic-gate {"DDI_NT_SERIAL_LOMCON", DDI_NT_SERIAL_LOMCON},
1207c478bd9Sstevel@tonic-gate {"DDI_NT_BLOCK", DDI_NT_BLOCK},
1217c478bd9Sstevel@tonic-gate {"DDI_NT_BLOCK_CHAN", DDI_NT_BLOCK_CHAN},
1227c478bd9Sstevel@tonic-gate {"DDI_NT_BLOCK_WWN", DDI_NT_BLOCK_WWN},
123d88e498aSjiang wu - Sun Microsystems - Beijing China {"DDI_NT_BLOCK_SAS", DDI_NT_BLOCK_SAS},
1247c478bd9Sstevel@tonic-gate {"DDI_NT_CD", DDI_NT_CD},
1257c478bd9Sstevel@tonic-gate {"DDI_NT_CD_CHAN", DDI_NT_CD_CHAN},
1267c478bd9Sstevel@tonic-gate {"DDI_NT_FD", DDI_NT_FD},
1277c478bd9Sstevel@tonic-gate {"DDI_NT_ENCLOSURE", DDI_NT_ENCLOSURE},
1287c478bd9Sstevel@tonic-gate {"DDI_NT_SCSI_ENCLOSURE", DDI_NT_SCSI_ENCLOSURE},
1297c478bd9Sstevel@tonic-gate {"DDI_NT_TAPE", DDI_NT_TAPE},
1307c478bd9Sstevel@tonic-gate {"DDI_NT_NET", DDI_NT_NET},
1317c478bd9Sstevel@tonic-gate {"DDI_NT_DISPLAY", DDI_NT_DISPLAY},
1327c478bd9Sstevel@tonic-gate {"DDI_PSEUDO", DDI_PSEUDO},
1337c478bd9Sstevel@tonic-gate {"DDI_NT_AUDIO", DDI_NT_AUDIO},
1347c478bd9Sstevel@tonic-gate {"DDI_NT_MOUSE", DDI_NT_MOUSE},
1357c478bd9Sstevel@tonic-gate {"DDI_NT_KEYBOARD", DDI_NT_KEYBOARD},
1367c478bd9Sstevel@tonic-gate {"DDI_NT_PARALLEL", DDI_NT_PARALLEL},
1377c478bd9Sstevel@tonic-gate {"DDI_NT_PRINTER", DDI_NT_PRINTER},
1387c478bd9Sstevel@tonic-gate {"DDI_NT_UGEN", DDI_NT_UGEN},
1397c478bd9Sstevel@tonic-gate {"DDI_NT_NEXUS", DDI_NT_NEXUS},
1407c478bd9Sstevel@tonic-gate {"DDI_NT_SCSI_NEXUS", DDI_NT_SCSI_NEXUS},
1417c478bd9Sstevel@tonic-gate {"DDI_NT_ATTACHMENT_POINT", DDI_NT_ATTACHMENT_POINT},
1427c478bd9Sstevel@tonic-gate {"DDI_NT_SCSI_ATTACHMENT_POINT", DDI_NT_SCSI_ATTACHMENT_POINT},
1437c478bd9Sstevel@tonic-gate {"DDI_NT_PCI_ATTACHMENT_POINT", DDI_NT_PCI_ATTACHMENT_POINT},
1447c478bd9Sstevel@tonic-gate {"DDI_NT_SBD_ATTACHMENT_POINT", DDI_NT_SBD_ATTACHMENT_POINT},
1457c478bd9Sstevel@tonic-gate {"DDI_NT_FC_ATTACHMENT_POINT", DDI_NT_FC_ATTACHMENT_POINT},
1467c478bd9Sstevel@tonic-gate {"DDI_NT_USB_ATTACHMENT_POINT", DDI_NT_USB_ATTACHMENT_POINT},
1477c478bd9Sstevel@tonic-gate {"DDI_NT_BLOCK_FABRIC", DDI_NT_BLOCK_FABRIC},
1487c478bd9Sstevel@tonic-gate {"DDI_NT_AV_ASYNC", DDI_NT_AV_ASYNC},
1497c478bd9Sstevel@tonic-gate {"DDI_NT_AV_ISOCH", DDI_NT_AV_ISOCH},
1507c478bd9Sstevel@tonic-gate { NULL, NULL }
1517c478bd9Sstevel@tonic-gate };
1527c478bd9Sstevel@tonic-gate
1537c478bd9Sstevel@tonic-gate /* Node name */
1547c478bd9Sstevel@tonic-gate static char *pshot_compat_diskname = "cdisk";
1557c478bd9Sstevel@tonic-gate
1567c478bd9Sstevel@tonic-gate /* Compatible names... */
1577c478bd9Sstevel@tonic-gate static char *pshot_compat_psramdisks[] = {
1587c478bd9Sstevel@tonic-gate "psramhead",
1597c478bd9Sstevel@tonic-gate "psramrom",
1607c478bd9Sstevel@tonic-gate "psramdisk",
1617c478bd9Sstevel@tonic-gate "psramd",
1627c478bd9Sstevel@tonic-gate "psramwhat"
1637c478bd9Sstevel@tonic-gate };
1647c478bd9Sstevel@tonic-gate
1657c478bd9Sstevel@tonic-gate /*
1667c478bd9Sstevel@tonic-gate * devices "natively" supported by pshot (i.e. included with SUNWiotu)
1677c478bd9Sstevel@tonic-gate * used to initialize pshot_devices with
1687c478bd9Sstevel@tonic-gate */
1697c478bd9Sstevel@tonic-gate static pshot_device_t pshot_stock_devices[] = {
1707c478bd9Sstevel@tonic-gate {"disk", DDI_NT_BLOCK, "gen_drv"},
1717c478bd9Sstevel@tonic-gate {"disk_chan", DDI_NT_BLOCK_CHAN, "gen_drv"},
1727c478bd9Sstevel@tonic-gate {"disk_wwn", DDI_NT_BLOCK_WWN, "gen_drv"},
1737c478bd9Sstevel@tonic-gate {"disk_cdrom", DDI_NT_CD, "gen_drv"},
1747c478bd9Sstevel@tonic-gate {"disk_cdrom.chan", DDI_NT_CD_CHAN, "gen_drv"},
1757c478bd9Sstevel@tonic-gate /* Note: use bad_drv to force attach errors */
1767c478bd9Sstevel@tonic-gate {"disk_fd", DDI_NT_FD, "bad_drv"},
1777c478bd9Sstevel@tonic-gate {"tape", DDI_NT_TAPE, "gen_drv"},
1787c478bd9Sstevel@tonic-gate {"net", DDI_NT_NET, "gen_drv"},
1797c478bd9Sstevel@tonic-gate {"display", DDI_NT_DISPLAY, "gen_drv"},
1807c478bd9Sstevel@tonic-gate {"pseudo", DDI_PSEUDO, "gen_drv"},
1817c478bd9Sstevel@tonic-gate {"audio", DDI_NT_AUDIO, "gen_drv"},
1827c478bd9Sstevel@tonic-gate {"mouse", DDI_NT_MOUSE, "gen_drv"},
1837c478bd9Sstevel@tonic-gate {"keyboard", DDI_NT_KEYBOARD, "gen_drv"},
1847c478bd9Sstevel@tonic-gate {"nexus", DDI_NT_NEXUS, "pshot"}
1857c478bd9Sstevel@tonic-gate };
1867c478bd9Sstevel@tonic-gate #define PSHOT_N_STOCK_DEVICES \
1877c478bd9Sstevel@tonic-gate (sizeof (pshot_stock_devices) / sizeof (pshot_device_t))
1887c478bd9Sstevel@tonic-gate
1897c478bd9Sstevel@tonic-gate static pshot_device_t *pshot_devices = NULL;
1907c478bd9Sstevel@tonic-gate static size_t pshot_devices_len = 0;
1917c478bd9Sstevel@tonic-gate
1927c478bd9Sstevel@tonic-gate /* protects <pshot_devices>, <pshot_devices_len> */
1937c478bd9Sstevel@tonic-gate static kmutex_t pshot_devices_lock;
1947c478bd9Sstevel@tonic-gate
1957c478bd9Sstevel@tonic-gate
1967c478bd9Sstevel@tonic-gate /*
1977c478bd9Sstevel@tonic-gate * event testing
1987c478bd9Sstevel@tonic-gate */
1997c478bd9Sstevel@tonic-gate
2007c478bd9Sstevel@tonic-gate static ndi_event_definition_t pshot_ndi_event_defs[] = {
2017c478bd9Sstevel@tonic-gate { PSHOT_EVENT_TAG_OFFLINE, PSHOT_EVENT_NAME_DEV_OFFLINE,
2027c478bd9Sstevel@tonic-gate EPL_INTERRUPT, NDI_EVENT_POST_TO_ALL },
2037c478bd9Sstevel@tonic-gate
2047c478bd9Sstevel@tonic-gate { PSHOT_EVENT_TAG_DEV_RESET, PSHOT_EVENT_NAME_DEV_RESET,
2057c478bd9Sstevel@tonic-gate EPL_INTERRUPT, NDI_EVENT_POST_TO_TGT },
2067c478bd9Sstevel@tonic-gate
2077c478bd9Sstevel@tonic-gate { PSHOT_EVENT_TAG_BUS_RESET, PSHOT_EVENT_NAME_BUS_RESET,
2087c478bd9Sstevel@tonic-gate EPL_INTERRUPT, NDI_EVENT_POST_TO_ALL },
2097c478bd9Sstevel@tonic-gate
2107c478bd9Sstevel@tonic-gate { PSHOT_EVENT_TAG_BUS_QUIESCE, PSHOT_EVENT_NAME_BUS_QUIESCE,
2117c478bd9Sstevel@tonic-gate EPL_INTERRUPT, NDI_EVENT_POST_TO_ALL },
2127c478bd9Sstevel@tonic-gate
2137c478bd9Sstevel@tonic-gate { PSHOT_EVENT_TAG_BUS_UNQUIESCE, PSHOT_EVENT_NAME_BUS_UNQUIESCE,
2147c478bd9Sstevel@tonic-gate EPL_INTERRUPT, NDI_EVENT_POST_TO_ALL },
2157c478bd9Sstevel@tonic-gate
2167c478bd9Sstevel@tonic-gate { PSHOT_EVENT_TAG_TEST_POST, PSHOT_EVENT_NAME_BUS_TEST_POST,
2177c478bd9Sstevel@tonic-gate EPL_INTERRUPT, NDI_EVENT_POST_TO_TGT }
2187c478bd9Sstevel@tonic-gate };
2197c478bd9Sstevel@tonic-gate
2207c478bd9Sstevel@tonic-gate
2217c478bd9Sstevel@tonic-gate #define PSHOT_N_NDI_EVENTS \
2227c478bd9Sstevel@tonic-gate (sizeof (pshot_ndi_event_defs) / sizeof (ndi_event_definition_t))
2237c478bd9Sstevel@tonic-gate
2247c478bd9Sstevel@tonic-gate #ifdef DEBUG
2257c478bd9Sstevel@tonic-gate
2267c478bd9Sstevel@tonic-gate static ndi_event_definition_t pshot_test_events[] = {
2277c478bd9Sstevel@tonic-gate { 10, "test event 0", EPL_INTERRUPT, NDI_EVENT_POST_TO_ALL },
2287c478bd9Sstevel@tonic-gate { 11, "test event 1", EPL_KERNEL, NDI_EVENT_POST_TO_TGT },
2297c478bd9Sstevel@tonic-gate { 12, "test event 2", EPL_INTERRUPT, NDI_EVENT_POST_TO_TGT },
2307c478bd9Sstevel@tonic-gate { 13, "test event 3", EPL_INTERRUPT, NDI_EVENT_POST_TO_ALL },
2317c478bd9Sstevel@tonic-gate { 14, "test event 4", EPL_KERNEL, NDI_EVENT_POST_TO_ALL},
2327c478bd9Sstevel@tonic-gate { 15, "test event 5", EPL_INTERRUPT, NDI_EVENT_POST_TO_ALL },
2337c478bd9Sstevel@tonic-gate { 16, "test event 6", EPL_KERNEL, NDI_EVENT_POST_TO_ALL },
2347c478bd9Sstevel@tonic-gate { 17, "test event 7", EPL_INTERRUPT, NDI_EVENT_POST_TO_ALL }
2357c478bd9Sstevel@tonic-gate };
2367c478bd9Sstevel@tonic-gate
2377c478bd9Sstevel@tonic-gate static ndi_event_definition_t pshot_test_events_high[] = {
2387c478bd9Sstevel@tonic-gate { 20, "test event high 0", EPL_HIGHLEVEL, NDI_EVENT_POST_TO_ALL}
2397c478bd9Sstevel@tonic-gate };
2407c478bd9Sstevel@tonic-gate
2417c478bd9Sstevel@tonic-gate #define PSHOT_N_TEST_EVENTS \
2427c478bd9Sstevel@tonic-gate (sizeof (pshot_test_events)/sizeof (ndi_event_definition_t))
2437c478bd9Sstevel@tonic-gate #endif
2447c478bd9Sstevel@tonic-gate
2457c478bd9Sstevel@tonic-gate struct register_events {
2467c478bd9Sstevel@tonic-gate char *event_name;
2477c478bd9Sstevel@tonic-gate ddi_eventcookie_t event_cookie;
2487c478bd9Sstevel@tonic-gate void (*event_callback)
2497c478bd9Sstevel@tonic-gate (dev_info_t *,
2507c478bd9Sstevel@tonic-gate ddi_eventcookie_t,
2517c478bd9Sstevel@tonic-gate void *arg,
2527c478bd9Sstevel@tonic-gate void *impldata);
2537c478bd9Sstevel@tonic-gate ddi_callback_id_t cb_id;
2547c478bd9Sstevel@tonic-gate };
2557c478bd9Sstevel@tonic-gate
2567c478bd9Sstevel@tonic-gate struct register_events pshot_register_events[] = {
2577c478bd9Sstevel@tonic-gate { PSHOT_EVENT_NAME_DEV_OFFLINE, 0, pshot_event_cb, 0 },
2587c478bd9Sstevel@tonic-gate { PSHOT_EVENT_NAME_DEV_RESET, 0, pshot_event_cb, 0 },
2597c478bd9Sstevel@tonic-gate { PSHOT_EVENT_NAME_BUS_RESET, 0, pshot_event_cb, 0 },
2607c478bd9Sstevel@tonic-gate { PSHOT_EVENT_NAME_BUS_QUIESCE, 0, pshot_event_cb, 0 },
2617c478bd9Sstevel@tonic-gate { PSHOT_EVENT_NAME_BUS_UNQUIESCE, 0, pshot_event_cb, 0 },
2627c478bd9Sstevel@tonic-gate { PSHOT_EVENT_NAME_BUS_TEST_POST, 0, pshot_event_cb, 0 }
2637c478bd9Sstevel@tonic-gate };
2647c478bd9Sstevel@tonic-gate
2657c478bd9Sstevel@tonic-gate #define PSHOT_N_DDI_EVENTS \
2667c478bd9Sstevel@tonic-gate (sizeof (pshot_register_events) / sizeof (struct register_events))
2677c478bd9Sstevel@tonic-gate
2687c478bd9Sstevel@tonic-gate
2697c478bd9Sstevel@tonic-gate #ifdef DEBUG
2707c478bd9Sstevel@tonic-gate
2717c478bd9Sstevel@tonic-gate static struct register_events pshot_register_test[] = {
2727c478bd9Sstevel@tonic-gate { "test event 0", 0, pshot_event_cb_test, 0},
2737c478bd9Sstevel@tonic-gate { "test event 1", 0, pshot_event_cb_test, 0},
2747c478bd9Sstevel@tonic-gate { "test event 2", 0, pshot_event_cb_test, 0},
2757c478bd9Sstevel@tonic-gate { "test event 3", 0, pshot_event_cb_test, 0},
2767c478bd9Sstevel@tonic-gate { "test event 4", 0, pshot_event_cb_test, 0},
2777c478bd9Sstevel@tonic-gate { "test event 5", 0, pshot_event_cb_test, 0},
2787c478bd9Sstevel@tonic-gate { "test event 6", 0, pshot_event_cb_test, 0},
2797c478bd9Sstevel@tonic-gate { "test event 7", 0, pshot_event_cb_test, 0}
2807c478bd9Sstevel@tonic-gate };
2817c478bd9Sstevel@tonic-gate
2827c478bd9Sstevel@tonic-gate
2837c478bd9Sstevel@tonic-gate static struct register_events pshot_register_high_test[] = {
2847c478bd9Sstevel@tonic-gate {"test event high 0", 0, pshot_event_cb_test, 0}
2857c478bd9Sstevel@tonic-gate };
2867c478bd9Sstevel@tonic-gate
2877c478bd9Sstevel@tonic-gate #endif /* DEBUG */
2887c478bd9Sstevel@tonic-gate
2897c478bd9Sstevel@tonic-gate static struct {
2907c478bd9Sstevel@tonic-gate int ioctl_int;
2917c478bd9Sstevel@tonic-gate char *ioctl_char;
2927c478bd9Sstevel@tonic-gate } pshot_devctls[] = {
2937c478bd9Sstevel@tonic-gate {DEVCTL_DEVICE_GETSTATE, "DEVCTL_DEVICE_GETSTATE"},
2947c478bd9Sstevel@tonic-gate {DEVCTL_DEVICE_ONLINE, "DEVCTL_DEVICE_ONLINE"},
2957c478bd9Sstevel@tonic-gate {DEVCTL_DEVICE_OFFLINE, "DEVCTL_DEVICE_OFFLINE"},
2967c478bd9Sstevel@tonic-gate {DEVCTL_DEVICE_REMOVE, "DEVCTL_DEVICE_REMOVE"},
2977c478bd9Sstevel@tonic-gate {DEVCTL_BUS_GETSTATE, "DEVCTL_BUS_GETSTATE"},
2987c478bd9Sstevel@tonic-gate {DEVCTL_BUS_DEV_CREATE, "DEVCTL_BUS_DEV_CREATE"},
2997c478bd9Sstevel@tonic-gate {DEVCTL_BUS_RESET, "DEVCTL_BUS_RESET"},
3007c478bd9Sstevel@tonic-gate {DEVCTL_BUS_RESETALL, "DEVCTL_BUS_RESETALL"},
3017c478bd9Sstevel@tonic-gate {0, NULL}
3027c478bd9Sstevel@tonic-gate };
3037c478bd9Sstevel@tonic-gate
3047c478bd9Sstevel@tonic-gate static struct bus_ops pshot_bus_ops = {
3057c478bd9Sstevel@tonic-gate BUSO_REV, /* busops_rev */
3067c478bd9Sstevel@tonic-gate nullbusmap, /* bus_map */
3077c478bd9Sstevel@tonic-gate NULL, /* bus_get_intrspec */
3087c478bd9Sstevel@tonic-gate NULL, /* bus_add_interspec */
3097c478bd9Sstevel@tonic-gate NULL, /* bus_remove_interspec */
3107c478bd9Sstevel@tonic-gate i_ddi_map_fault, /* bus_map_fault */
311*cd21e7c5SGarrett D'Amore NULL, /* bus_dma_map */
312b1dd958fScth ddi_dma_allochdl, /* bus_dma_allochdl */
313b1dd958fScth ddi_dma_freehdl, /* bus_dma_freehdl */
314b1dd958fScth ddi_dma_bindhdl, /* bus_dma_bindhdl */
315b1dd958fScth ddi_dma_unbindhdl, /* bus_dma_unbindhdl */
316b1dd958fScth ddi_dma_flush, /* bus_dma_flush */
317b1dd958fScth ddi_dma_win, /* bus_dma_win */
318b1dd958fScth ddi_dma_mctl, /* bus_dma_ctl */
3197c478bd9Sstevel@tonic-gate pshot_ctl, /* bus_ctl */
3207c478bd9Sstevel@tonic-gate ddi_bus_prop_op, /* bus_prop_op */
3217c478bd9Sstevel@tonic-gate pshot_get_eventcookie, /* bus_get_eventcookie */
3227c478bd9Sstevel@tonic-gate pshot_add_eventcall, /* bus_add_eventcall */
3237c478bd9Sstevel@tonic-gate pshot_remove_eventcall, /* bus_remove_event */
3247c478bd9Sstevel@tonic-gate pshot_post_event, /* bus_post_event */
3257c478bd9Sstevel@tonic-gate NULL, /* bus_intr_ctl */
3267c478bd9Sstevel@tonic-gate pshot_bus_config, /* bus_config */
3277c478bd9Sstevel@tonic-gate pshot_bus_unconfig, /* bus_unconfig */
3287c478bd9Sstevel@tonic-gate NULL, /* bus_fm_init */
3297c478bd9Sstevel@tonic-gate NULL, /* bus_fm_fini */
3307c478bd9Sstevel@tonic-gate NULL, /* bus_fm_access_enter */
3317c478bd9Sstevel@tonic-gate NULL, /* bus_fm_access_exit */
3327c478bd9Sstevel@tonic-gate pshot_bus_power, /* bus_power */
3337c478bd9Sstevel@tonic-gate pshot_bus_introp /* bus_intr_op */
3347c478bd9Sstevel@tonic-gate };
3357c478bd9Sstevel@tonic-gate
3367c478bd9Sstevel@tonic-gate static struct cb_ops pshot_cb_ops = {
3377c478bd9Sstevel@tonic-gate pshot_open, /* open */
3387c478bd9Sstevel@tonic-gate pshot_close, /* close */
3397c478bd9Sstevel@tonic-gate nodev, /* strategy */
3407c478bd9Sstevel@tonic-gate nodev, /* print */
3417c478bd9Sstevel@tonic-gate nodev, /* dump */
3427c478bd9Sstevel@tonic-gate nodev, /* read */
3437c478bd9Sstevel@tonic-gate nodev, /* write */
3447c478bd9Sstevel@tonic-gate pshot_ioctl, /* ioctl */
3457c478bd9Sstevel@tonic-gate nodev, /* devmap */
3467c478bd9Sstevel@tonic-gate nodev, /* mmap */
3477c478bd9Sstevel@tonic-gate nodev, /* segmap */
3487c478bd9Sstevel@tonic-gate nochpoll, /* poll */
3497c478bd9Sstevel@tonic-gate ddi_prop_op, /* prop_op */
3507c478bd9Sstevel@tonic-gate NULL, /* streamtab */
3517c478bd9Sstevel@tonic-gate D_NEW | D_MP | D_HOTPLUG, /* flags */
3527c478bd9Sstevel@tonic-gate CB_REV, /* cb_rev */
3537c478bd9Sstevel@tonic-gate nodev, /* aread */
3547c478bd9Sstevel@tonic-gate nodev, /* awrite */
3557c478bd9Sstevel@tonic-gate };
3567c478bd9Sstevel@tonic-gate
3577c478bd9Sstevel@tonic-gate static struct dev_ops pshot_ops = {
3587c478bd9Sstevel@tonic-gate DEVO_REV, /* devo_rev, */
3597c478bd9Sstevel@tonic-gate 0, /* refcnt */
3607c478bd9Sstevel@tonic-gate pshot_info, /* getinfo */
3617c478bd9Sstevel@tonic-gate nulldev, /* identify */
3627c478bd9Sstevel@tonic-gate pshot_probe, /* probe */
3637c478bd9Sstevel@tonic-gate pshot_attach, /* attach */
3647c478bd9Sstevel@tonic-gate pshot_detach, /* detach */
3657c478bd9Sstevel@tonic-gate nodev, /* reset */
3667c478bd9Sstevel@tonic-gate &pshot_cb_ops, /* driver operations */
3677c478bd9Sstevel@tonic-gate &pshot_bus_ops, /* bus operations */
36819397407SSherry Moore pshot_power, /* power */
36919397407SSherry Moore ddi_quiesce_not_supported, /* devo_quiesce */
3707c478bd9Sstevel@tonic-gate
3717c478bd9Sstevel@tonic-gate };
3727c478bd9Sstevel@tonic-gate
3737c478bd9Sstevel@tonic-gate
3747c478bd9Sstevel@tonic-gate /*
3757c478bd9Sstevel@tonic-gate * Module linkage information for the kernel.
3767c478bd9Sstevel@tonic-gate */
3777c478bd9Sstevel@tonic-gate static struct modldrv modldrv = {
3787c478bd9Sstevel@tonic-gate &mod_driverops,
37919397407SSherry Moore "pshotnex",
3807c478bd9Sstevel@tonic-gate &pshot_ops,
3817c478bd9Sstevel@tonic-gate };
3827c478bd9Sstevel@tonic-gate
3837c478bd9Sstevel@tonic-gate static struct modlinkage modlinkage = {
3847c478bd9Sstevel@tonic-gate MODREV_1, &modldrv, NULL
3857c478bd9Sstevel@tonic-gate };
3867c478bd9Sstevel@tonic-gate
3877c478bd9Sstevel@tonic-gate
3887c478bd9Sstevel@tonic-gate /*
3897c478bd9Sstevel@tonic-gate * pshot_devices is set up on the first attach and destroyed on fini
3907c478bd9Sstevel@tonic-gate *
3917c478bd9Sstevel@tonic-gate * therefore PSHOT_PROP_DEV* properties may be set just for the root device,
3927c478bd9Sstevel@tonic-gate * instead of being set globably, in pshot.conf by specifying the properties
3937c478bd9Sstevel@tonic-gate * on a single line in the form:
3947c478bd9Sstevel@tonic-gate * name="pshot" parent="/" <dev props ..>
3957c478bd9Sstevel@tonic-gate * to unclutter a device tree snapshot.
3967c478bd9Sstevel@tonic-gate * this of course produces a long single line that may wrap around several
3977c478bd9Sstevel@tonic-gate * times on screen
3987c478bd9Sstevel@tonic-gate */
3997c478bd9Sstevel@tonic-gate
4007c478bd9Sstevel@tonic-gate int
_init(void)4017c478bd9Sstevel@tonic-gate _init(void)
4027c478bd9Sstevel@tonic-gate {
4037c478bd9Sstevel@tonic-gate int rv;
4047c478bd9Sstevel@tonic-gate
4057c478bd9Sstevel@tonic-gate rv = ddi_soft_state_init(&pshot_softstatep, sizeof (pshot_t), 0);
4067c478bd9Sstevel@tonic-gate
4077c478bd9Sstevel@tonic-gate if (rv != DDI_SUCCESS)
4087c478bd9Sstevel@tonic-gate return (rv);
4097c478bd9Sstevel@tonic-gate
4107c478bd9Sstevel@tonic-gate mutex_init(&pshot_devices_lock, NULL, MUTEX_DRIVER, NULL);
4117c478bd9Sstevel@tonic-gate pshot_devices = NULL;
4127c478bd9Sstevel@tonic-gate pshot_devices_len = 0;
4137c478bd9Sstevel@tonic-gate
4147c478bd9Sstevel@tonic-gate if ((rv = mod_install(&modlinkage)) != 0) {
4157c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&pshot_softstatep);
4167c478bd9Sstevel@tonic-gate mutex_destroy(&pshot_devices_lock);
4177c478bd9Sstevel@tonic-gate }
4187c478bd9Sstevel@tonic-gate return (rv);
4197c478bd9Sstevel@tonic-gate }
4207c478bd9Sstevel@tonic-gate
4217c478bd9Sstevel@tonic-gate int
_fini(void)4227c478bd9Sstevel@tonic-gate _fini(void)
4237c478bd9Sstevel@tonic-gate {
4247c478bd9Sstevel@tonic-gate int rv;
4257c478bd9Sstevel@tonic-gate
4267c478bd9Sstevel@tonic-gate if ((rv = mod_remove(&modlinkage)) != 0)
4277c478bd9Sstevel@tonic-gate return (rv);
4287c478bd9Sstevel@tonic-gate
4297c478bd9Sstevel@tonic-gate ddi_soft_state_fini(&pshot_softstatep);
4307c478bd9Sstevel@tonic-gate mutex_destroy(&pshot_devices_lock);
4317c478bd9Sstevel@tonic-gate if (pshot_devices)
4327c478bd9Sstevel@tonic-gate pshot_devices_free(pshot_devices, pshot_devices_len);
4337c478bd9Sstevel@tonic-gate return (0);
4347c478bd9Sstevel@tonic-gate }
4357c478bd9Sstevel@tonic-gate
4367c478bd9Sstevel@tonic-gate int
_info(struct modinfo * modinfop)4377c478bd9Sstevel@tonic-gate _info(struct modinfo *modinfop)
4387c478bd9Sstevel@tonic-gate {
4397c478bd9Sstevel@tonic-gate return (mod_info(&modlinkage, modinfop));
4407c478bd9Sstevel@tonic-gate }
4417c478bd9Sstevel@tonic-gate
4427c478bd9Sstevel@tonic-gate
4437c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4447c478bd9Sstevel@tonic-gate static int
pshot_probe(dev_info_t * devi)4457c478bd9Sstevel@tonic-gate pshot_probe(dev_info_t *devi)
4467c478bd9Sstevel@tonic-gate {
4477c478bd9Sstevel@tonic-gate int instance = ddi_get_instance(devi);
4487c478bd9Sstevel@tonic-gate char *bus_addr;
4497c478bd9Sstevel@tonic-gate
4507c478bd9Sstevel@tonic-gate /*
4517c478bd9Sstevel@tonic-gate * Hook for tests to force probe fail
4527c478bd9Sstevel@tonic-gate */
4537c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, devi, 0, "bus-addr",
4547c478bd9Sstevel@tonic-gate &bus_addr) == DDI_PROP_SUCCESS) {
4557c478bd9Sstevel@tonic-gate if (strncmp(bus_addr, "failprobe", 9) == 0) {
4567c478bd9Sstevel@tonic-gate if (pshot_debug)
4577c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: "
4587c478bd9Sstevel@tonic-gate "%s forced probe failure\n",
4597c478bd9Sstevel@tonic-gate instance, bus_addr);
4607c478bd9Sstevel@tonic-gate ddi_prop_free(bus_addr);
4617c478bd9Sstevel@tonic-gate return (DDI_PROBE_FAILURE);
4627c478bd9Sstevel@tonic-gate }
4637c478bd9Sstevel@tonic-gate ddi_prop_free(bus_addr);
4647c478bd9Sstevel@tonic-gate }
4657c478bd9Sstevel@tonic-gate
4667c478bd9Sstevel@tonic-gate return (DDI_PROBE_SUCCESS);
4677c478bd9Sstevel@tonic-gate }
4687c478bd9Sstevel@tonic-gate
4697c478bd9Sstevel@tonic-gate
4707c478bd9Sstevel@tonic-gate /*ARGSUSED*/
4717c478bd9Sstevel@tonic-gate static int
pshot_info(dev_info_t * dip,ddi_info_cmd_t infocmd,void * arg,void ** result)4727c478bd9Sstevel@tonic-gate pshot_info(dev_info_t *dip, ddi_info_cmd_t infocmd, void *arg, void **result)
4737c478bd9Sstevel@tonic-gate {
4747c478bd9Sstevel@tonic-gate int instance;
4757c478bd9Sstevel@tonic-gate minor_t minor;
4767c478bd9Sstevel@tonic-gate pshot_t *pshot;
4777c478bd9Sstevel@tonic-gate
4787c478bd9Sstevel@tonic-gate minor = getminor((dev_t)arg);
4797c478bd9Sstevel@tonic-gate instance = pshot_minor_decode_inst(minor);
4807c478bd9Sstevel@tonic-gate switch (infocmd) {
4817c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2DEVINFO:
4827c478bd9Sstevel@tonic-gate pshot = ddi_get_soft_state(pshot_softstatep, instance);
4837c478bd9Sstevel@tonic-gate if (pshot == NULL) {
4847c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pshot_info: get soft state failed "
4857c478bd9Sstevel@tonic-gate "on minor %u, instance %d", minor, instance);
4867c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
4877c478bd9Sstevel@tonic-gate }
4887c478bd9Sstevel@tonic-gate *result = (void *)pshot->dip;
4897c478bd9Sstevel@tonic-gate break;
4907c478bd9Sstevel@tonic-gate case DDI_INFO_DEVT2INSTANCE:
4917c478bd9Sstevel@tonic-gate *result = (void *)(uintptr_t)instance;
4927c478bd9Sstevel@tonic-gate break;
4937c478bd9Sstevel@tonic-gate default:
4947c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pshot_info: unrecognized cmd 0x%x on "
4957c478bd9Sstevel@tonic-gate "minor %u, instance %d", infocmd, minor, instance);
4967c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
4977c478bd9Sstevel@tonic-gate }
4987c478bd9Sstevel@tonic-gate
4997c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
5007c478bd9Sstevel@tonic-gate }
5017c478bd9Sstevel@tonic-gate
5027c478bd9Sstevel@tonic-gate
5037c478bd9Sstevel@tonic-gate static int
pshot_attach(dev_info_t * devi,ddi_attach_cmd_t cmd)5047c478bd9Sstevel@tonic-gate pshot_attach(dev_info_t *devi, ddi_attach_cmd_t cmd)
5057c478bd9Sstevel@tonic-gate {
5067c478bd9Sstevel@tonic-gate int instance = ddi_get_instance(devi);
5077c478bd9Sstevel@tonic-gate pshot_t *pshot;
5087c478bd9Sstevel@tonic-gate int rval, i;
5097c478bd9Sstevel@tonic-gate int prop_flags = DDI_PROP_DONTPASS | DDI_PROP_NOTPROM;
5107c478bd9Sstevel@tonic-gate char *bus_addr;
5117c478bd9Sstevel@tonic-gate char *pm_comp[] = {
5127c478bd9Sstevel@tonic-gate "NAME=bus",
5137c478bd9Sstevel@tonic-gate "0=B3",
5147c478bd9Sstevel@tonic-gate "1=B2",
5157c478bd9Sstevel@tonic-gate "2=B1",
5167c478bd9Sstevel@tonic-gate "3=B0"};
5177c478bd9Sstevel@tonic-gate char *pm_hw_state = {"needs-suspend-resume"};
5187c478bd9Sstevel@tonic-gate
5197c478bd9Sstevel@tonic-gate pshot_prop_autoattach = ddi_prop_get_int(DDI_DEV_T_ANY, devi,
5207c478bd9Sstevel@tonic-gate prop_flags, "autoattach", 0);
5217c478bd9Sstevel@tonic-gate
5227c478bd9Sstevel@tonic-gate switch (cmd) {
5237c478bd9Sstevel@tonic-gate
5247c478bd9Sstevel@tonic-gate case DDI_ATTACH:
5257c478bd9Sstevel@tonic-gate if (pshot_debug)
5267c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "attach: %s%d/pshot%d\n",
5277c478bd9Sstevel@tonic-gate ddi_get_name(ddi_get_parent(devi)),
5287c478bd9Sstevel@tonic-gate ddi_get_instance(ddi_get_parent(devi)),
5297c478bd9Sstevel@tonic-gate instance);
5307c478bd9Sstevel@tonic-gate
5317c478bd9Sstevel@tonic-gate /*
5327c478bd9Sstevel@tonic-gate * Hook for tests to force attach fail
5337c478bd9Sstevel@tonic-gate */
5347c478bd9Sstevel@tonic-gate if ((ddi_prop_lookup_string(DDI_DEV_T_ANY, devi, 0, "bus-addr",
5357c478bd9Sstevel@tonic-gate &bus_addr) == DDI_PROP_SUCCESS) && bus_addr != NULL) {
5367c478bd9Sstevel@tonic-gate if (strncmp(bus_addr, "failattach", 10) == 0) {
5377c478bd9Sstevel@tonic-gate if (pshot_debug)
5387c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: "
5397c478bd9Sstevel@tonic-gate "%s forced attach failure\n",
5407c478bd9Sstevel@tonic-gate instance, bus_addr);
5417c478bd9Sstevel@tonic-gate ddi_prop_free(bus_addr);
5427c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
5437c478bd9Sstevel@tonic-gate }
5447c478bd9Sstevel@tonic-gate ddi_prop_free(bus_addr);
5457c478bd9Sstevel@tonic-gate }
5467c478bd9Sstevel@tonic-gate
5477c478bd9Sstevel@tonic-gate /*
5487c478bd9Sstevel@tonic-gate * minor nodes setup
5497c478bd9Sstevel@tonic-gate */
5507c478bd9Sstevel@tonic-gate if (ddi_soft_state_zalloc(pshot_softstatep, instance) !=
5517c478bd9Sstevel@tonic-gate DDI_SUCCESS) {
5527c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
5537c478bd9Sstevel@tonic-gate }
5547c478bd9Sstevel@tonic-gate pshot = ddi_get_soft_state(pshot_softstatep, instance);
5557c478bd9Sstevel@tonic-gate pshot->dip = devi;
5567c478bd9Sstevel@tonic-gate pshot->instance = instance;
5577c478bd9Sstevel@tonic-gate mutex_init(&pshot->lock, NULL, MUTEX_DRIVER, NULL);
5587c478bd9Sstevel@tonic-gate
5597c478bd9Sstevel@tonic-gate /* set each minor, then create on dip all together */
5607c478bd9Sstevel@tonic-gate
5617c478bd9Sstevel@tonic-gate i = PSHOT_NODENUM_DEVCTL;
5627c478bd9Sstevel@tonic-gate pshot->nodes[i].pshot = pshot;
5637c478bd9Sstevel@tonic-gate pshot->nodes[i].minor = pshot_minor_encode(instance, i);
5647c478bd9Sstevel@tonic-gate (void) strncpy(pshot->nodes[i].name, PSHOT_NODENAME_DEVCTL,
5657c478bd9Sstevel@tonic-gate PSHOT_MAX_MINOR_NAMELEN);
5667c478bd9Sstevel@tonic-gate
5677c478bd9Sstevel@tonic-gate i = PSHOT_NODENUM_TESTCTL;
5687c478bd9Sstevel@tonic-gate pshot->nodes[i].pshot = pshot;
5697c478bd9Sstevel@tonic-gate pshot->nodes[i].minor = pshot_minor_encode(instance, i);
5707c478bd9Sstevel@tonic-gate (void) strncpy(pshot->nodes[i].name, PSHOT_NODENAME_TESTCTL,
5717c478bd9Sstevel@tonic-gate PSHOT_MAX_MINOR_NAMELEN);
5727c478bd9Sstevel@tonic-gate
5737c478bd9Sstevel@tonic-gate /* this assumes contiguous a filling */
5747c478bd9Sstevel@tonic-gate for (i = 0; i <= PSHOT_MAX_NODENUM; i++) {
5757c478bd9Sstevel@tonic-gate if (ddi_create_minor_node(devi, pshot->nodes[i].name,
5767c478bd9Sstevel@tonic-gate S_IFCHR, pshot->nodes[i].minor, DDI_NT_NEXUS, 0) !=
5777c478bd9Sstevel@tonic-gate DDI_SUCCESS) {
5787c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "attach: cannot create "
5797c478bd9Sstevel@tonic-gate "minor %s", pshot->nodes[i].name);
5807c478bd9Sstevel@tonic-gate goto FAIL_ATTACH;
5817c478bd9Sstevel@tonic-gate }
5827c478bd9Sstevel@tonic-gate }
5837c478bd9Sstevel@tonic-gate
5847c478bd9Sstevel@tonic-gate /*
5857c478bd9Sstevel@tonic-gate * pshot_devices setup
5867c478bd9Sstevel@tonic-gate */
5877c478bd9Sstevel@tonic-gate if (pshot_devices_setup(devi)) {
5887c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "attach: pshot devices setup "
5897c478bd9Sstevel@tonic-gate "failed");
5907c478bd9Sstevel@tonic-gate goto FAIL_ATTACH;
5917c478bd9Sstevel@tonic-gate }
5927c478bd9Sstevel@tonic-gate
5937c478bd9Sstevel@tonic-gate /*
5947c478bd9Sstevel@tonic-gate * events setup
5957c478bd9Sstevel@tonic-gate */
5967c478bd9Sstevel@tonic-gate for (i = 0; i < PSHOT_N_DDI_EVENTS; i++) {
5977c478bd9Sstevel@tonic-gate rval = ddi_get_eventcookie(devi,
5987c478bd9Sstevel@tonic-gate pshot_register_events[i].event_name,
5997c478bd9Sstevel@tonic-gate &pshot_register_events[i].event_cookie);
6007c478bd9Sstevel@tonic-gate
6017c478bd9Sstevel@tonic-gate if (pshot_debug)
6027c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: event=%s:"
6037c478bd9Sstevel@tonic-gate "ddi_get_eventcookie rval=%d\n",
6047c478bd9Sstevel@tonic-gate instance,
6057c478bd9Sstevel@tonic-gate pshot_register_events[i].event_name, rval);
6067c478bd9Sstevel@tonic-gate
6077c478bd9Sstevel@tonic-gate if (rval == DDI_SUCCESS) {
6087c478bd9Sstevel@tonic-gate rval = ddi_add_event_handler(devi,
6097c478bd9Sstevel@tonic-gate pshot_register_events[i].event_cookie,
6107c478bd9Sstevel@tonic-gate pshot_register_events[i].event_callback,
6117c478bd9Sstevel@tonic-gate (void *)pshot,
6127c478bd9Sstevel@tonic-gate &pshot->callback_cache[i]);
6137c478bd9Sstevel@tonic-gate
6147c478bd9Sstevel@tonic-gate if (pshot_debug)
6157c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: event=%s: "
6167c478bd9Sstevel@tonic-gate "ddi_add_event_handler rval=%d\n",
6177c478bd9Sstevel@tonic-gate instance,
6187c478bd9Sstevel@tonic-gate pshot_register_events[i].event_name,
6197c478bd9Sstevel@tonic-gate rval);
6207c478bd9Sstevel@tonic-gate }
6217c478bd9Sstevel@tonic-gate }
6227c478bd9Sstevel@tonic-gate
6237c478bd9Sstevel@tonic-gate #ifdef DEBUG
6247c478bd9Sstevel@tonic-gate if (pshot_event_test_enable) {
6257c478bd9Sstevel@tonic-gate pshot_event_test((void *)pshot);
6267c478bd9Sstevel@tonic-gate (void) timeout(pshot_event_test_post_one, (void *)pshot,
6277c478bd9Sstevel@tonic-gate instance * drv_usectohz(60000000));
6287c478bd9Sstevel@tonic-gate }
6297c478bd9Sstevel@tonic-gate #endif
6307c478bd9Sstevel@tonic-gate
6317c478bd9Sstevel@tonic-gate /*
6327c478bd9Sstevel@tonic-gate * allocate an ndi event handle
6337c478bd9Sstevel@tonic-gate */
6347c478bd9Sstevel@tonic-gate if (ndi_event_alloc_hdl(devi, NULL, &pshot->ndi_event_hdl,
6357c478bd9Sstevel@tonic-gate NDI_SLEEP) != NDI_SUCCESS) {
6367c478bd9Sstevel@tonic-gate goto FAIL_ATTACH;
6377c478bd9Sstevel@tonic-gate }
6387c478bd9Sstevel@tonic-gate
6397c478bd9Sstevel@tonic-gate pshot->ndi_events.ndi_events_version = NDI_EVENTS_REV1;
6407c478bd9Sstevel@tonic-gate pshot->ndi_events.ndi_n_events = PSHOT_N_NDI_EVENTS;
6417c478bd9Sstevel@tonic-gate pshot->ndi_events.ndi_event_defs = pshot_ndi_event_defs;
6427c478bd9Sstevel@tonic-gate
6437c478bd9Sstevel@tonic-gate if (ndi_event_bind_set(pshot->ndi_event_hdl, &pshot->ndi_events,
6447c478bd9Sstevel@tonic-gate NDI_SLEEP) != NDI_SUCCESS) {
6457c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d bind set failed\n",
6467c478bd9Sstevel@tonic-gate instance);
6477c478bd9Sstevel@tonic-gate }
6487c478bd9Sstevel@tonic-gate
6497c478bd9Sstevel@tonic-gate /*
6507c478bd9Sstevel@tonic-gate * setup a test for nexus auto-attach iff we are
6517c478bd9Sstevel@tonic-gate * a second level pshot node (parent == /SUNW,pshot)
6527c478bd9Sstevel@tonic-gate * enable by setting "autoattach=1" in pshot.conf
6537c478bd9Sstevel@tonic-gate */
6547c478bd9Sstevel@tonic-gate if ((PARENT_IS_PSHOT(devi)) && (pshot_prop_autoattach != 0) &&
6557c478bd9Sstevel@tonic-gate (ddi_get_instance(ddi_get_parent(devi))) == 0)
6567c478bd9Sstevel@tonic-gate pshot_setup_autoattach(devi);
6577c478bd9Sstevel@tonic-gate
6587c478bd9Sstevel@tonic-gate /*
6597c478bd9Sstevel@tonic-gate * initialize internal state to idle: busy = 0,
6607c478bd9Sstevel@tonic-gate * power level = -1
6617c478bd9Sstevel@tonic-gate */
6627c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
6637c478bd9Sstevel@tonic-gate pshot->busy = 0;
6647c478bd9Sstevel@tonic-gate pshot->busy_ioctl = 0;
6657c478bd9Sstevel@tonic-gate pshot->level = -1;
6667c478bd9Sstevel@tonic-gate pshot->state &= ~STRICT_PARENT;
6677c478bd9Sstevel@tonic-gate pshot->state |= PM_SUPPORTED;
6687c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
6697c478bd9Sstevel@tonic-gate
6707c478bd9Sstevel@tonic-gate /*
6717c478bd9Sstevel@tonic-gate * Create the "pm-want-child-notification?" property
6727c478bd9Sstevel@tonic-gate * for the root node /devices/pshot
6737c478bd9Sstevel@tonic-gate */
6747c478bd9Sstevel@tonic-gate if (instance == 0) {
6757c478bd9Sstevel@tonic-gate if (pshot_debug) {
6767c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_ATTACH:\n\t"
6777c478bd9Sstevel@tonic-gate " create the"
6787c478bd9Sstevel@tonic-gate " \"pm-want-child-notification?\" property"
6797c478bd9Sstevel@tonic-gate " for the root node\n", instance);
6807c478bd9Sstevel@tonic-gate }
6817c478bd9Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, devi, 0,
6827c478bd9Sstevel@tonic-gate "pm-want-child-notification?", NULL, 0)
6837c478bd9Sstevel@tonic-gate != DDI_PROP_SUCCESS) {
6847c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d:\n\t"
6857c478bd9Sstevel@tonic-gate " unable to create the"
6867c478bd9Sstevel@tonic-gate " \"pm-want-child-notification?\""
6877c478bd9Sstevel@tonic-gate " property", ddi_get_name(devi),
6887c478bd9Sstevel@tonic-gate ddi_get_instance(devi));
6897c478bd9Sstevel@tonic-gate
6907c478bd9Sstevel@tonic-gate goto FAIL_ATTACH;
6917c478bd9Sstevel@tonic-gate }
6927c478bd9Sstevel@tonic-gate }
6937c478bd9Sstevel@tonic-gate
6947c478bd9Sstevel@tonic-gate /*
6957c478bd9Sstevel@tonic-gate * Check if the pm-want-child-notification? property was
6967c478bd9Sstevel@tonic-gate * created in pshot_bus_config_setup_nexus() by the parent.
6977c478bd9Sstevel@tonic-gate * Set the STRICT_PARENT flag if not.
6987c478bd9Sstevel@tonic-gate */
6997c478bd9Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, devi,
7007c478bd9Sstevel@tonic-gate (DDI_PROP_DONTPASS | DDI_PROP_NOTPROM),
7017c478bd9Sstevel@tonic-gate "pm-want-child-notification?") != 1) {
7027c478bd9Sstevel@tonic-gate if (pshot_debug) {
7037c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_ATTACH:"
7047c478bd9Sstevel@tonic-gate " STRICT PARENT\n", instance);
7057c478bd9Sstevel@tonic-gate }
7067c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
7077c478bd9Sstevel@tonic-gate pshot->state |= STRICT_PARENT;
7087c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
7097c478bd9Sstevel@tonic-gate } else {
7107c478bd9Sstevel@tonic-gate if (pshot_debug) {
7117c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_ATTACH:"
7127c478bd9Sstevel@tonic-gate " INVOLVED PARENT\n", instance);
7137c478bd9Sstevel@tonic-gate }
7147c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
7157c478bd9Sstevel@tonic-gate pshot->state &= ~STRICT_PARENT;
7167c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
7177c478bd9Sstevel@tonic-gate }
7187c478bd9Sstevel@tonic-gate
7197c478bd9Sstevel@tonic-gate /*
7207c478bd9Sstevel@tonic-gate * create the pm-components property: one component
7217c478bd9Sstevel@tonic-gate * with 4 power levels.
7227c478bd9Sstevel@tonic-gate * - skip for pshot@XXX,nopm and pshot@XXX,nopm_strict:
7237c478bd9Sstevel@tonic-gate * "no-pm-components" property
7247c478bd9Sstevel@tonic-gate */
7257c478bd9Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, devi,
7267c478bd9Sstevel@tonic-gate (DDI_PROP_DONTPASS | DDI_PROP_NOTPROM),
7277c478bd9Sstevel@tonic-gate "no-pm-components") == 0) {
7287c478bd9Sstevel@tonic-gate if (pshot_debug) {
7297c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_ATTACH:"
7307c478bd9Sstevel@tonic-gate " create the \"pm_components\" property\n",
7317c478bd9Sstevel@tonic-gate instance);
7327c478bd9Sstevel@tonic-gate }
7337c478bd9Sstevel@tonic-gate if (ddi_prop_update_string_array(DDI_DEV_T_NONE, devi,
7347c478bd9Sstevel@tonic-gate "pm-components", pm_comp, 5) != DDI_PROP_SUCCESS) {
7357c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: DDI_ATTACH:\n\t"
7367c478bd9Sstevel@tonic-gate " unable to create the \"pm-components\""
7377c478bd9Sstevel@tonic-gate " property", ddi_get_name(devi),
7387c478bd9Sstevel@tonic-gate ddi_get_instance(devi));
7397c478bd9Sstevel@tonic-gate
7407c478bd9Sstevel@tonic-gate goto FAIL_ATTACH;
7417c478bd9Sstevel@tonic-gate }
7427c478bd9Sstevel@tonic-gate } else {
7437c478bd9Sstevel@tonic-gate if (pshot_debug) {
7447c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_ATTACH:"
7457c478bd9Sstevel@tonic-gate " NO-PM_COMPONENTS PARENT\n", instance);
7467c478bd9Sstevel@tonic-gate }
7477c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
7487c478bd9Sstevel@tonic-gate pshot->state &= ~PM_SUPPORTED;
7497c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
7507c478bd9Sstevel@tonic-gate }
7517c478bd9Sstevel@tonic-gate
7527c478bd9Sstevel@tonic-gate /*
7537c478bd9Sstevel@tonic-gate * create the property needed to get DDI_SUSPEND
7547c478bd9Sstevel@tonic-gate * and DDI_RESUME calls
7557c478bd9Sstevel@tonic-gate */
7567c478bd9Sstevel@tonic-gate if (pshot_debug) {
7577c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_ATTACH:"
7587c478bd9Sstevel@tonic-gate " create pm-hardware-state property\n",
7597c478bd9Sstevel@tonic-gate instance);
7607c478bd9Sstevel@tonic-gate }
7617c478bd9Sstevel@tonic-gate if (ddi_prop_update_string(DDI_DEV_T_NONE, devi,
7627c478bd9Sstevel@tonic-gate "pm-hardware-state", pm_hw_state) != DDI_PROP_SUCCESS) {
7637c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: DDI_ATTACH:\n\t"
7647c478bd9Sstevel@tonic-gate " unable to create the \"pm-hardware-state\""
7657c478bd9Sstevel@tonic-gate " property", ddi_get_name(devi),
7667c478bd9Sstevel@tonic-gate ddi_get_instance(devi));
7677c478bd9Sstevel@tonic-gate
7687c478bd9Sstevel@tonic-gate goto FAIL_ATTACH;
7697c478bd9Sstevel@tonic-gate }
7707c478bd9Sstevel@tonic-gate
7717c478bd9Sstevel@tonic-gate /*
7727c478bd9Sstevel@tonic-gate * set power level to max via pm_raise_power(),
7737c478bd9Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm)
7747c478bd9Sstevel@tonic-gate */
7757c478bd9Sstevel@tonic-gate if (pshot->state & PM_SUPPORTED) {
7767c478bd9Sstevel@tonic-gate if (pshot_debug) {
7777c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_ATTACH:"
7787c478bd9Sstevel@tonic-gate " raise power to MAXPWR\n", instance);
7797c478bd9Sstevel@tonic-gate }
7807c478bd9Sstevel@tonic-gate if (pm_raise_power(pshot->dip, 0, MAXPWR) !=
7817c478bd9Sstevel@tonic-gate DDI_SUCCESS) {
7827c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: DDI_ATTACH:"
7837c478bd9Sstevel@tonic-gate " pm_raise_power failed",
7847c478bd9Sstevel@tonic-gate ddi_get_name(devi),
7857c478bd9Sstevel@tonic-gate ddi_get_instance(devi));
7867c478bd9Sstevel@tonic-gate
7877c478bd9Sstevel@tonic-gate goto FAIL_ATTACH;
7887c478bd9Sstevel@tonic-gate
7897c478bd9Sstevel@tonic-gate }
7907c478bd9Sstevel@tonic-gate }
7917c478bd9Sstevel@tonic-gate
7927c478bd9Sstevel@tonic-gate if (pshot_log)
7937c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d attached\n", instance);
7947c478bd9Sstevel@tonic-gate ddi_report_dev(devi);
7957c478bd9Sstevel@tonic-gate
7967c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
7977c478bd9Sstevel@tonic-gate /*NOTREACHED*/
7987c478bd9Sstevel@tonic-gate FAIL_ATTACH:
7997c478bd9Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL);
8007c478bd9Sstevel@tonic-gate mutex_destroy(&pshot->lock);
8017c478bd9Sstevel@tonic-gate ddi_soft_state_free(pshot_softstatep, instance);
8027c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
8037c478bd9Sstevel@tonic-gate
8047c478bd9Sstevel@tonic-gate case DDI_RESUME:
8057c478bd9Sstevel@tonic-gate if (pshot_debug) {
8067c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_RESUME: resuming\n",
8077c478bd9Sstevel@tonic-gate instance);
8087c478bd9Sstevel@tonic-gate }
8097c478bd9Sstevel@tonic-gate pshot = ddi_get_soft_state(pshot_softstatep, instance);
8107c478bd9Sstevel@tonic-gate
8117c478bd9Sstevel@tonic-gate /*
8127c478bd9Sstevel@tonic-gate * set power level to max via pm_raise_power(),
8137c478bd9Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm)
8147c478bd9Sstevel@tonic-gate */
8157c478bd9Sstevel@tonic-gate if (pshot->state & PM_SUPPORTED) {
8167c478bd9Sstevel@tonic-gate if (pshot_debug) {
8177c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_RESUME:"
8187c478bd9Sstevel@tonic-gate " raise power to MAXPWR\n", instance);
8197c478bd9Sstevel@tonic-gate }
8207c478bd9Sstevel@tonic-gate if (pm_raise_power(pshot->dip, 0, MAXPWR) !=
8217c478bd9Sstevel@tonic-gate DDI_SUCCESS) {
8227c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: DDI_RESUME:"
8237c478bd9Sstevel@tonic-gate " pm_raise_power failed",
8247c478bd9Sstevel@tonic-gate ddi_get_name(devi),
8257c478bd9Sstevel@tonic-gate ddi_get_instance(devi));
8267c478bd9Sstevel@tonic-gate }
8277c478bd9Sstevel@tonic-gate }
8287c478bd9Sstevel@tonic-gate
8297c478bd9Sstevel@tonic-gate if (pshot_debug) {
8307c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_RESUME: resumed\n",
8317c478bd9Sstevel@tonic-gate instance);
8327c478bd9Sstevel@tonic-gate }
8337c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
8347c478bd9Sstevel@tonic-gate
8357c478bd9Sstevel@tonic-gate default:
8367c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
8377c478bd9Sstevel@tonic-gate }
8387c478bd9Sstevel@tonic-gate }
8397c478bd9Sstevel@tonic-gate
8407c478bd9Sstevel@tonic-gate static int
pshot_detach(dev_info_t * devi,ddi_detach_cmd_t cmd)8417c478bd9Sstevel@tonic-gate pshot_detach(dev_info_t *devi, ddi_detach_cmd_t cmd)
8427c478bd9Sstevel@tonic-gate {
8437c478bd9Sstevel@tonic-gate int instance = ddi_get_instance(devi);
8447c478bd9Sstevel@tonic-gate int i, rval;
8457c478bd9Sstevel@tonic-gate pshot_t *pshot = ddi_get_soft_state(pshot_softstatep, instance);
8467c478bd9Sstevel@tonic-gate int level_tmp;
8477c478bd9Sstevel@tonic-gate
8487c478bd9Sstevel@tonic-gate if (pshot == NULL)
8497c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
8507c478bd9Sstevel@tonic-gate
8517c478bd9Sstevel@tonic-gate switch (cmd) {
8527c478bd9Sstevel@tonic-gate
8537c478bd9Sstevel@tonic-gate case DDI_DETACH:
8547c478bd9Sstevel@tonic-gate if (pshot_debug)
8557c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_DETACH\n", instance);
8567c478bd9Sstevel@tonic-gate /*
8577c478bd9Sstevel@tonic-gate * power off component 0
8587c478bd9Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm)
8597c478bd9Sstevel@tonic-gate */
8607c478bd9Sstevel@tonic-gate if (pshot->state & PM_SUPPORTED) {
8617c478bd9Sstevel@tonic-gate if (pshot_debug) {
8627c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_DETACH:"
8637c478bd9Sstevel@tonic-gate " power off\n", instance);
8647c478bd9Sstevel@tonic-gate }
8657c478bd9Sstevel@tonic-gate if (pm_lower_power(pshot->dip, 0, 0) != DDI_SUCCESS) {
8667c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: DDI_DETACH:\n\t"
8677c478bd9Sstevel@tonic-gate "pm_lower_power failed for comp 0 to"
8687c478bd9Sstevel@tonic-gate " level 0", ddi_get_name(devi),
8697c478bd9Sstevel@tonic-gate ddi_get_instance(devi));
8707c478bd9Sstevel@tonic-gate
8717c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
8727c478bd9Sstevel@tonic-gate }
8737c478bd9Sstevel@tonic-gate
8747c478bd9Sstevel@tonic-gate /*
8757c478bd9Sstevel@tonic-gate * Check if the power level is actually OFF.
8767c478bd9Sstevel@tonic-gate * Issue pm_power_has_changed if not.
8777c478bd9Sstevel@tonic-gate */
8787c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
8797c478bd9Sstevel@tonic-gate if (pshot->level != 0) {
8807c478bd9Sstevel@tonic-gate if (pshot_debug) {
8817c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "pshot%d:"
8827c478bd9Sstevel@tonic-gate " DDI_DETACH: power off via"
8837c478bd9Sstevel@tonic-gate " pm_power_has_changed instead\n",
8847c478bd9Sstevel@tonic-gate instance);
8857c478bd9Sstevel@tonic-gate }
8867c478bd9Sstevel@tonic-gate level_tmp = pshot->level;
8877c478bd9Sstevel@tonic-gate pshot->level = 0;
8887c478bd9Sstevel@tonic-gate if (pm_power_has_changed(pshot->dip, 0, 0) !=
8897c478bd9Sstevel@tonic-gate DDI_SUCCESS) {
8907c478bd9Sstevel@tonic-gate if (pshot_debug) {
8917c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "pshot%d:"
8927c478bd9Sstevel@tonic-gate " DDI_DETACH:"
8937c478bd9Sstevel@tonic-gate " pm_power_has_changed"
8947c478bd9Sstevel@tonic-gate " failed\n", instance);
8957c478bd9Sstevel@tonic-gate }
8967c478bd9Sstevel@tonic-gate pshot->level = level_tmp;
8977c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
8987c478bd9Sstevel@tonic-gate
8997c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
9007c478bd9Sstevel@tonic-gate }
9017c478bd9Sstevel@tonic-gate }
9027c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
9037c478bd9Sstevel@tonic-gate }
9047c478bd9Sstevel@tonic-gate
9057c478bd9Sstevel@tonic-gate for (i = 0; i < PSHOT_N_DDI_EVENTS; i++) {
9067c478bd9Sstevel@tonic-gate if (pshot->callback_cache[i] != NULL) {
9077c478bd9Sstevel@tonic-gate rval = ddi_remove_event_handler(
9087c478bd9Sstevel@tonic-gate pshot->callback_cache[i]);
9097c478bd9Sstevel@tonic-gate ASSERT(rval == DDI_SUCCESS);
9107c478bd9Sstevel@tonic-gate }
9117c478bd9Sstevel@tonic-gate }
9127c478bd9Sstevel@tonic-gate
9137c478bd9Sstevel@tonic-gate #ifdef DEBUG
9147c478bd9Sstevel@tonic-gate for (i = 0; i < PSHOT_N_TEST_EVENTS; i++) {
9157c478bd9Sstevel@tonic-gate if (pshot->test_callback_cache[i] != NULL) {
9167c478bd9Sstevel@tonic-gate rval = ddi_remove_event_handler(
9177c478bd9Sstevel@tonic-gate pshot->test_callback_cache[i]);
9187c478bd9Sstevel@tonic-gate ASSERT(rval == DDI_SUCCESS);
9197c478bd9Sstevel@tonic-gate }
9207c478bd9Sstevel@tonic-gate }
9217c478bd9Sstevel@tonic-gate #endif
9227c478bd9Sstevel@tonic-gate rval = ndi_event_free_hdl(pshot->ndi_event_hdl);
9237c478bd9Sstevel@tonic-gate ASSERT(rval == DDI_SUCCESS);
9247c478bd9Sstevel@tonic-gate
9257c478bd9Sstevel@tonic-gate if (pshot_log)
9267c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d detached\n", instance);
9277c478bd9Sstevel@tonic-gate
9287c478bd9Sstevel@tonic-gate ddi_remove_minor_node(devi, NULL);
9297c478bd9Sstevel@tonic-gate mutex_destroy(&pshot->lock);
9307c478bd9Sstevel@tonic-gate ddi_soft_state_free(pshot_softstatep, instance);
9317c478bd9Sstevel@tonic-gate break;
9327c478bd9Sstevel@tonic-gate
9337c478bd9Sstevel@tonic-gate case DDI_SUSPEND:
9347c478bd9Sstevel@tonic-gate if (pshot_debug)
9357c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_SUSPEND\n", instance);
9367c478bd9Sstevel@tonic-gate /*
9377c478bd9Sstevel@tonic-gate * fail the suspend if FAIL_SUSPEND_FLAG is set.
9387c478bd9Sstevel@tonic-gate * clear the FAIL_SUSPEND_FLAG flag
9397c478bd9Sstevel@tonic-gate */
9407c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
9417c478bd9Sstevel@tonic-gate if (pshot->state & FAIL_SUSPEND_FLAG) {
9427c478bd9Sstevel@tonic-gate if (pshot_debug) {
9437c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:"
9447c478bd9Sstevel@tonic-gate " FAIL_SUSPEND_FLAG set, fail suspend\n",
9457c478bd9Sstevel@tonic-gate ddi_get_instance(devi));
9467c478bd9Sstevel@tonic-gate }
9477c478bd9Sstevel@tonic-gate pshot->state &= ~FAIL_SUSPEND_FLAG;
9487c478bd9Sstevel@tonic-gate rval = DDI_FAILURE;
9497c478bd9Sstevel@tonic-gate } else {
9507c478bd9Sstevel@tonic-gate rval = DDI_SUCCESS;
9517c478bd9Sstevel@tonic-gate }
9527c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
9537c478bd9Sstevel@tonic-gate
9547c478bd9Sstevel@tonic-gate /*
9557c478bd9Sstevel@tonic-gate * power OFF via pm_power_has_changed
9567c478bd9Sstevel@tonic-gate */
9577c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
9587c478bd9Sstevel@tonic-gate if (pshot->state & PM_SUPPORTED) {
9597c478bd9Sstevel@tonic-gate if (pshot_debug) {
9607c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DDI_SUSPEND:"
9617c478bd9Sstevel@tonic-gate " power off via pm_power_has_changed\n",
9627c478bd9Sstevel@tonic-gate instance);
9637c478bd9Sstevel@tonic-gate }
9647c478bd9Sstevel@tonic-gate level_tmp = pshot->level;
9657c478bd9Sstevel@tonic-gate pshot->level = 0;
9667c478bd9Sstevel@tonic-gate if (pm_power_has_changed(pshot->dip, 0, 0) !=
9677c478bd9Sstevel@tonic-gate DDI_SUCCESS) {
9687c478bd9Sstevel@tonic-gate if (pshot_debug) {
9697c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "pshot%d:"
9707c478bd9Sstevel@tonic-gate " DDI_SUSPEND:"
9717c478bd9Sstevel@tonic-gate " pm_power_has_changed failed\n",
9727c478bd9Sstevel@tonic-gate instance);
9737c478bd9Sstevel@tonic-gate }
9747c478bd9Sstevel@tonic-gate pshot->level = level_tmp;
9757c478bd9Sstevel@tonic-gate rval = DDI_FAILURE;
9767c478bd9Sstevel@tonic-gate }
9777c478bd9Sstevel@tonic-gate }
9787c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
9797c478bd9Sstevel@tonic-gate return (rval);
9807c478bd9Sstevel@tonic-gate
9817c478bd9Sstevel@tonic-gate default:
9827c478bd9Sstevel@tonic-gate break;
9837c478bd9Sstevel@tonic-gate }
9847c478bd9Sstevel@tonic-gate
9857c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
9867c478bd9Sstevel@tonic-gate }
9877c478bd9Sstevel@tonic-gate
9887c478bd9Sstevel@tonic-gate
9897c478bd9Sstevel@tonic-gate /*
9907c478bd9Sstevel@tonic-gate * returns number of bits to represent <val>
9917c478bd9Sstevel@tonic-gate */
9927c478bd9Sstevel@tonic-gate static size_t
pshot_numbits(size_t val)9937c478bd9Sstevel@tonic-gate pshot_numbits(size_t val)
9947c478bd9Sstevel@tonic-gate {
9957c478bd9Sstevel@tonic-gate size_t bitcnt;
9967c478bd9Sstevel@tonic-gate
9977c478bd9Sstevel@tonic-gate if (val == 0)
9987c478bd9Sstevel@tonic-gate return (0);
9997c478bd9Sstevel@tonic-gate for (bitcnt = 1; 1 << bitcnt < val; bitcnt++)
10007c478bd9Sstevel@tonic-gate ;
10017c478bd9Sstevel@tonic-gate return (bitcnt);
10027c478bd9Sstevel@tonic-gate }
10037c478bd9Sstevel@tonic-gate
10047c478bd9Sstevel@tonic-gate /*
10057c478bd9Sstevel@tonic-gate * returns a minor number encoded with instance <inst> and an index <nodenum>
10067c478bd9Sstevel@tonic-gate * that identifies the minor node for this instance
10077c478bd9Sstevel@tonic-gate */
10087c478bd9Sstevel@tonic-gate static minor_t
pshot_minor_encode(int inst,minor_t nodenum)10097c478bd9Sstevel@tonic-gate pshot_minor_encode(int inst, minor_t nodenum)
10107c478bd9Sstevel@tonic-gate {
10117c478bd9Sstevel@tonic-gate return (((minor_t)inst << PSHOT_NODENUM_BITS()) |
10127c478bd9Sstevel@tonic-gate (((1 << PSHOT_NODENUM_BITS()) - 1) & nodenum));
10137c478bd9Sstevel@tonic-gate }
10147c478bd9Sstevel@tonic-gate
10157c478bd9Sstevel@tonic-gate /*
10167c478bd9Sstevel@tonic-gate * returns instance of <minor>
10177c478bd9Sstevel@tonic-gate */
10187c478bd9Sstevel@tonic-gate static int
pshot_minor_decode_inst(minor_t minor)10197c478bd9Sstevel@tonic-gate pshot_minor_decode_inst(minor_t minor)
10207c478bd9Sstevel@tonic-gate {
10217c478bd9Sstevel@tonic-gate return (minor >> PSHOT_NODENUM_BITS());
10227c478bd9Sstevel@tonic-gate }
10237c478bd9Sstevel@tonic-gate
10247c478bd9Sstevel@tonic-gate /*
10257c478bd9Sstevel@tonic-gate * returns node number indexing a minor node for the instance in <minor>
10267c478bd9Sstevel@tonic-gate */
10277c478bd9Sstevel@tonic-gate static minor_t
pshot_minor_decode_nodenum(minor_t minor)10287c478bd9Sstevel@tonic-gate pshot_minor_decode_nodenum(minor_t minor)
10297c478bd9Sstevel@tonic-gate {
10307c478bd9Sstevel@tonic-gate return (minor & ((1 << PSHOT_NODENUM_BITS()) - 1));
10317c478bd9Sstevel@tonic-gate }
10327c478bd9Sstevel@tonic-gate
10337c478bd9Sstevel@tonic-gate
10347c478bd9Sstevel@tonic-gate /*
10357c478bd9Sstevel@tonic-gate * pshot_bus_introp: pshot convert an interrupt number to an
10367c478bd9Sstevel@tonic-gate * interrupt. NO OP for pseudo drivers.
10377c478bd9Sstevel@tonic-gate */
10387c478bd9Sstevel@tonic-gate /*ARGSUSED*/
10397c478bd9Sstevel@tonic-gate static int
pshot_bus_introp(dev_info_t * dip,dev_info_t * rdip,ddi_intr_op_t intr_op,ddi_intr_handle_impl_t * hdlp,void * result)10407c478bd9Sstevel@tonic-gate pshot_bus_introp(dev_info_t *dip, dev_info_t *rdip, ddi_intr_op_t intr_op,
10417c478bd9Sstevel@tonic-gate ddi_intr_handle_impl_t *hdlp, void *result)
10427c478bd9Sstevel@tonic-gate {
10437c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
10447c478bd9Sstevel@tonic-gate }
10457c478bd9Sstevel@tonic-gate static int
pshot_ctl(dev_info_t * dip,dev_info_t * rdip,ddi_ctl_enum_t ctlop,void * arg,void * result)10467c478bd9Sstevel@tonic-gate pshot_ctl(dev_info_t *dip, dev_info_t *rdip,
10477c478bd9Sstevel@tonic-gate ddi_ctl_enum_t ctlop, void *arg, void *result)
10487c478bd9Sstevel@tonic-gate {
10497c478bd9Sstevel@tonic-gate int instance;
10507c478bd9Sstevel@tonic-gate pshot_t *pshot;
10517c478bd9Sstevel@tonic-gate char *childname;
10527c478bd9Sstevel@tonic-gate int childinstance;
10537c478bd9Sstevel@tonic-gate char *name;
10547c478bd9Sstevel@tonic-gate int circ;
10557c478bd9Sstevel@tonic-gate struct attachspec *as;
10567c478bd9Sstevel@tonic-gate struct detachspec *ds;
10577c478bd9Sstevel@tonic-gate int rval = DDI_SUCCESS;
10587c478bd9Sstevel@tonic-gate int no_pm_components_child;
10597c478bd9Sstevel@tonic-gate
10607c478bd9Sstevel@tonic-gate name = ddi_get_name(dip);
10617c478bd9Sstevel@tonic-gate instance = ddi_get_instance(dip);
10627c478bd9Sstevel@tonic-gate pshot = ddi_get_soft_state(pshot_softstatep, instance);
10637c478bd9Sstevel@tonic-gate if (pshot == NULL) {
10647c478bd9Sstevel@tonic-gate return (ENXIO);
10657c478bd9Sstevel@tonic-gate }
10667c478bd9Sstevel@tonic-gate
10677c478bd9Sstevel@tonic-gate switch (ctlop) {
10687c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REPORTDEV:
10697c478bd9Sstevel@tonic-gate if (rdip == (dev_info_t *)0)
10707c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
10717c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "?pshot-device: %s%d\n",
10727c478bd9Sstevel@tonic-gate ddi_get_name(rdip), ddi_get_instance(rdip));
10737c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
10747c478bd9Sstevel@tonic-gate
10757c478bd9Sstevel@tonic-gate case DDI_CTLOPS_INITCHILD:
10767c478bd9Sstevel@tonic-gate {
10777c478bd9Sstevel@tonic-gate dev_info_t *child = (dev_info_t *)arg;
10787c478bd9Sstevel@tonic-gate
10797c478bd9Sstevel@tonic-gate if (pshot_debug) {
10807c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "initchild %s%d/%s%d state 0x%x\n",
10817c478bd9Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip),
10827c478bd9Sstevel@tonic-gate ddi_node_name(child), ddi_get_instance(child),
10837c478bd9Sstevel@tonic-gate DEVI(child)->devi_state);
10847c478bd9Sstevel@tonic-gate }
10857c478bd9Sstevel@tonic-gate
10867c478bd9Sstevel@tonic-gate return (pshot_initchild(dip, child));
10877c478bd9Sstevel@tonic-gate }
10887c478bd9Sstevel@tonic-gate
10897c478bd9Sstevel@tonic-gate case DDI_CTLOPS_UNINITCHILD:
10907c478bd9Sstevel@tonic-gate {
10917c478bd9Sstevel@tonic-gate dev_info_t *child = (dev_info_t *)arg;
10927c478bd9Sstevel@tonic-gate
10937c478bd9Sstevel@tonic-gate if (pshot_debug) {
10947c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "uninitchild %s%d/%s%d state 0x%x\n",
10957c478bd9Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip),
10967c478bd9Sstevel@tonic-gate ddi_node_name(child), ddi_get_instance(child),
10977c478bd9Sstevel@tonic-gate DEVI(child)->devi_state);
10987c478bd9Sstevel@tonic-gate }
10997c478bd9Sstevel@tonic-gate
11007c478bd9Sstevel@tonic-gate return (pshot_uninitchild(dip, child));
11017c478bd9Sstevel@tonic-gate }
11027c478bd9Sstevel@tonic-gate
11037c478bd9Sstevel@tonic-gate case DDI_CTLOPS_DMAPMAPC:
11047c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REPORTINT:
11057c478bd9Sstevel@tonic-gate case DDI_CTLOPS_REGSIZE:
11067c478bd9Sstevel@tonic-gate case DDI_CTLOPS_NREGS:
11077c478bd9Sstevel@tonic-gate case DDI_CTLOPS_SIDDEV:
11087c478bd9Sstevel@tonic-gate case DDI_CTLOPS_SLAVEONLY:
11097c478bd9Sstevel@tonic-gate case DDI_CTLOPS_AFFINITY:
11107c478bd9Sstevel@tonic-gate case DDI_CTLOPS_POKE:
11117c478bd9Sstevel@tonic-gate case DDI_CTLOPS_PEEK:
11127c478bd9Sstevel@tonic-gate /*
11137c478bd9Sstevel@tonic-gate * These ops correspond to functions that "shouldn't" be called
11147c478bd9Sstevel@tonic-gate * by a pseudo driver. So we whine when we're called.
11157c478bd9Sstevel@tonic-gate */
11167c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: invalid op (%d) from %s%d\n",
11177c478bd9Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip),
11187c478bd9Sstevel@tonic-gate ctlop, ddi_get_name(rdip), ddi_get_instance(rdip));
11197c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
11207c478bd9Sstevel@tonic-gate
11217c478bd9Sstevel@tonic-gate case DDI_CTLOPS_ATTACH:
11227c478bd9Sstevel@tonic-gate {
11237c478bd9Sstevel@tonic-gate dev_info_t *child = (dev_info_t *)rdip;
11247c478bd9Sstevel@tonic-gate childname = ddi_node_name(child);
11257c478bd9Sstevel@tonic-gate childinstance = ddi_get_instance(child);
11267c478bd9Sstevel@tonic-gate as = (struct attachspec *)arg;
11277c478bd9Sstevel@tonic-gate
11287c478bd9Sstevel@tonic-gate no_pm_components_child = 0;
11297c478bd9Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, child,
11307c478bd9Sstevel@tonic-gate (DDI_PROP_DONTPASS | DDI_PROP_NOTPROM),
11317c478bd9Sstevel@tonic-gate "no-pm-components") == 1) {
11327c478bd9Sstevel@tonic-gate no_pm_components_child = 1;
11337c478bd9Sstevel@tonic-gate }
11347c478bd9Sstevel@tonic-gate if (pshot_debug) {
11357c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: ctl_attach %s%d [%d]\n",
11367c478bd9Sstevel@tonic-gate name, instance, childname, childinstance,
11377c478bd9Sstevel@tonic-gate no_pm_components_child);
11387c478bd9Sstevel@tonic-gate }
11397c478bd9Sstevel@tonic-gate
11407c478bd9Sstevel@tonic-gate ndi_devi_enter(dip, &circ);
11417c478bd9Sstevel@tonic-gate
11427c478bd9Sstevel@tonic-gate switch (as->when) {
11437c478bd9Sstevel@tonic-gate case DDI_PRE:
11447c478bd9Sstevel@tonic-gate /*
11457c478bd9Sstevel@tonic-gate * Mark nexus busy before a child attaches.
11467c478bd9Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm
11477c478bd9Sstevel@tonic-gate * - pshot@XXX,nopm_strict)
11487c478bd9Sstevel@tonic-gate */
11497c478bd9Sstevel@tonic-gate if (!(pshot->state & PM_SUPPORTED))
11507c478bd9Sstevel@tonic-gate break;
11517c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
11527c478bd9Sstevel@tonic-gate ++(pshot->busy);
11537c478bd9Sstevel@tonic-gate if (pshot_debug_busy) {
11547c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d:"
11557c478bd9Sstevel@tonic-gate " ctl_attach_pre: busy for %s%d:"
11567c478bd9Sstevel@tonic-gate " busy = %d\n", name, instance,
11577c478bd9Sstevel@tonic-gate childname, childinstance,
11587c478bd9Sstevel@tonic-gate pshot->busy);
11597c478bd9Sstevel@tonic-gate }
11607c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
11617c478bd9Sstevel@tonic-gate rval = pm_busy_component(dip, 0);
11627c478bd9Sstevel@tonic-gate ASSERT(rval == DDI_SUCCESS);
11637c478bd9Sstevel@tonic-gate break;
11647c478bd9Sstevel@tonic-gate case DDI_POST:
11657c478bd9Sstevel@tonic-gate /*
11667c478bd9Sstevel@tonic-gate * Mark nexus idle after a child attaches.
11677c478bd9Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm).
11687c478bd9Sstevel@tonic-gate * - also skip if this is not a stict parent and
11697c478bd9Sstevel@tonic-gate * - the child is a tape device or a no-pm-components
11707c478bd9Sstevel@tonic-gate * - nexus node.
11717c478bd9Sstevel@tonic-gate */
11727c478bd9Sstevel@tonic-gate if (!(pshot->state & PM_SUPPORTED) ||
11737c478bd9Sstevel@tonic-gate (strcmp(childname, "tape") == 0 &&
11747c478bd9Sstevel@tonic-gate !(pshot->state & STRICT_PARENT)) ||
11757c478bd9Sstevel@tonic-gate no_pm_components_child)
11767c478bd9Sstevel@tonic-gate break;
11777c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
11787c478bd9Sstevel@tonic-gate ASSERT(pshot->busy > 0);
11797c478bd9Sstevel@tonic-gate --pshot->busy;
11807c478bd9Sstevel@tonic-gate if (pshot_debug_busy) {
11817c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d:"
11827c478bd9Sstevel@tonic-gate " ctl_attach_post: idle for %s%d:"
11837c478bd9Sstevel@tonic-gate " busy = %d\n", name, instance,
11847c478bd9Sstevel@tonic-gate childname, childinstance,
11857c478bd9Sstevel@tonic-gate pshot->busy);
11867c478bd9Sstevel@tonic-gate }
11877c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
11887c478bd9Sstevel@tonic-gate rval = pm_idle_component(dip, 0);
11897c478bd9Sstevel@tonic-gate ASSERT(rval == DDI_SUCCESS);
11907c478bd9Sstevel@tonic-gate break;
11917c478bd9Sstevel@tonic-gate }
11927c478bd9Sstevel@tonic-gate
11937c478bd9Sstevel@tonic-gate ndi_devi_exit(dip, circ);
11947c478bd9Sstevel@tonic-gate
11957c478bd9Sstevel@tonic-gate return (rval);
11967c478bd9Sstevel@tonic-gate }
11977c478bd9Sstevel@tonic-gate case DDI_CTLOPS_DETACH:
11987c478bd9Sstevel@tonic-gate {
11997c478bd9Sstevel@tonic-gate dev_info_t *child = (dev_info_t *)rdip;
12007c478bd9Sstevel@tonic-gate childname = ddi_node_name(child);
12017c478bd9Sstevel@tonic-gate childinstance = ddi_get_instance(child);
12027c478bd9Sstevel@tonic-gate ds = (struct detachspec *)arg;
12037c478bd9Sstevel@tonic-gate
12047c478bd9Sstevel@tonic-gate no_pm_components_child = 0;
12057c478bd9Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, child,
12067c478bd9Sstevel@tonic-gate (DDI_PROP_DONTPASS | DDI_PROP_NOTPROM),
12077c478bd9Sstevel@tonic-gate "no-pm-components") == 1) {
12087c478bd9Sstevel@tonic-gate no_pm_components_child = 1;
12097c478bd9Sstevel@tonic-gate }
12107c478bd9Sstevel@tonic-gate if (pshot_debug) {
12117c478bd9Sstevel@tonic-gate cmn_err(CE_CONT,
12127c478bd9Sstevel@tonic-gate "%s%d: ctl_detach %s%d [%d]\n",
12137c478bd9Sstevel@tonic-gate name, instance, childname, childinstance,
12147c478bd9Sstevel@tonic-gate no_pm_components_child);
12157c478bd9Sstevel@tonic-gate }
12167c478bd9Sstevel@tonic-gate
12177c478bd9Sstevel@tonic-gate ndi_devi_enter(dip, &circ);
12187c478bd9Sstevel@tonic-gate
12197c478bd9Sstevel@tonic-gate switch (ds->when) {
12207c478bd9Sstevel@tonic-gate case DDI_PRE:
12217c478bd9Sstevel@tonic-gate /*
12227c478bd9Sstevel@tonic-gate * Mark nexus busy before a child detaches.
12237c478bd9Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm
12247c478bd9Sstevel@tonic-gate * - pshot@XXX,nopm_strict), or if the child is a
12257c478bd9Sstevel@tonic-gate * - no-pm-components nexus node.
12267c478bd9Sstevel@tonic-gate */
12277c478bd9Sstevel@tonic-gate if (!(pshot->state & PM_SUPPORTED) ||
12287c478bd9Sstevel@tonic-gate (strcmp(childname, "tape") == 0 &&
12297c478bd9Sstevel@tonic-gate !(pshot->state & STRICT_PARENT)) ||
12307c478bd9Sstevel@tonic-gate no_pm_components_child)
12317c478bd9Sstevel@tonic-gate break;
12327c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
12337c478bd9Sstevel@tonic-gate ++(pshot->busy);
12347c478bd9Sstevel@tonic-gate if (pshot_debug_busy) {
12357c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d:"
12367c478bd9Sstevel@tonic-gate " ctl_detach_pre: busy for %s%d:"
12377c478bd9Sstevel@tonic-gate " busy = %d\n", name, instance,
12387c478bd9Sstevel@tonic-gate childname, childinstance,
12397c478bd9Sstevel@tonic-gate pshot->busy);
12407c478bd9Sstevel@tonic-gate }
12417c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
12427c478bd9Sstevel@tonic-gate rval = pm_busy_component(dip, 0);
12437c478bd9Sstevel@tonic-gate ASSERT(rval == DDI_SUCCESS);
12447c478bd9Sstevel@tonic-gate
12457c478bd9Sstevel@tonic-gate break;
12467c478bd9Sstevel@tonic-gate case DDI_POST:
12477c478bd9Sstevel@tonic-gate /*
12487c478bd9Sstevel@tonic-gate * Mark nexus idle after a child detaches.
12497c478bd9Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm)
12507c478bd9Sstevel@tonic-gate */
12517c478bd9Sstevel@tonic-gate if (!(pshot->state & PM_SUPPORTED))
12527c478bd9Sstevel@tonic-gate break;
12537c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
12547c478bd9Sstevel@tonic-gate ASSERT(pshot->busy > 0);
12557c478bd9Sstevel@tonic-gate --pshot->busy;
12567c478bd9Sstevel@tonic-gate if (pshot_debug_busy) {
12577c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d:"
12587c478bd9Sstevel@tonic-gate " ctl_detach_post: idle for %s%d:"
12597c478bd9Sstevel@tonic-gate " busy = %d\n", name, instance,
12607c478bd9Sstevel@tonic-gate childname, childinstance,
12617c478bd9Sstevel@tonic-gate pshot->busy);
12627c478bd9Sstevel@tonic-gate }
12637c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
12647c478bd9Sstevel@tonic-gate rval = pm_idle_component(dip, 0);
12657c478bd9Sstevel@tonic-gate ASSERT(rval == DDI_SUCCESS);
12667c478bd9Sstevel@tonic-gate
12677c478bd9Sstevel@tonic-gate /*
12687c478bd9Sstevel@tonic-gate * Mark the driver idle if the NO_INVOL_FLAG
12697c478bd9Sstevel@tonic-gate * is set. This is needed to make sure the
12707c478bd9Sstevel@tonic-gate * parent is idle after the child detaches
12717c478bd9Sstevel@tonic-gate * without calling pm_lower_power().
12727c478bd9Sstevel@tonic-gate * Clear the NO_INVOL_FLAG.
12737c478bd9Sstevel@tonic-gate * - also mark idle if a tape device has detached
12747c478bd9Sstevel@tonic-gate */
12757c478bd9Sstevel@tonic-gate if (!(pshot->state & NO_INVOL_FLAG))
12767c478bd9Sstevel@tonic-gate break;
12777c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
12787c478bd9Sstevel@tonic-gate ASSERT(pshot->busy > 0);
12797c478bd9Sstevel@tonic-gate --pshot->busy;
12807c478bd9Sstevel@tonic-gate if (pshot_debug_busy) {
12817c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d:"
12827c478bd9Sstevel@tonic-gate " ctl_detach_post: NO_INVOL:"
12837c478bd9Sstevel@tonic-gate " idle for %s%d: busy = %d\n",
12847c478bd9Sstevel@tonic-gate name, instance, childname,
12857c478bd9Sstevel@tonic-gate childinstance, pshot->busy);
12867c478bd9Sstevel@tonic-gate }
12877c478bd9Sstevel@tonic-gate pshot->state &= ~NO_INVOL_FLAG;
12887c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
12897c478bd9Sstevel@tonic-gate rval = pm_idle_component(dip, 0);
12907c478bd9Sstevel@tonic-gate ASSERT(rval == DDI_SUCCESS);
12917c478bd9Sstevel@tonic-gate
12927c478bd9Sstevel@tonic-gate break;
12937c478bd9Sstevel@tonic-gate }
12947c478bd9Sstevel@tonic-gate
12957c478bd9Sstevel@tonic-gate ndi_devi_exit(dip, circ);
12967c478bd9Sstevel@tonic-gate
12977c478bd9Sstevel@tonic-gate return (rval);
12987c478bd9Sstevel@tonic-gate }
12997c478bd9Sstevel@tonic-gate
13005e3986cbScth case DDI_CTLOPS_BTOP:
13015e3986cbScth case DDI_CTLOPS_BTOPR:
13027c478bd9Sstevel@tonic-gate case DDI_CTLOPS_DVMAPAGESIZE:
13037c478bd9Sstevel@tonic-gate case DDI_CTLOPS_IOMIN:
13047c478bd9Sstevel@tonic-gate case DDI_CTLOPS_PTOB:
13057c478bd9Sstevel@tonic-gate default:
13067c478bd9Sstevel@tonic-gate /*
13077c478bd9Sstevel@tonic-gate * The ops that we pass up (default). We pass up memory
13087c478bd9Sstevel@tonic-gate * allocation oriented ops that we receive - these may be
13097c478bd9Sstevel@tonic-gate * associated with pseudo HBA drivers below us with target
13107c478bd9Sstevel@tonic-gate * drivers below them that use ddi memory allocation
13117c478bd9Sstevel@tonic-gate * interfaces like scsi_alloc_consistent_buf.
13127c478bd9Sstevel@tonic-gate */
13137c478bd9Sstevel@tonic-gate return (ddi_ctlops(dip, rdip, ctlop, arg, result));
13147c478bd9Sstevel@tonic-gate }
13157c478bd9Sstevel@tonic-gate }
13167c478bd9Sstevel@tonic-gate
13177c478bd9Sstevel@tonic-gate /*ARGSUSED0*/
13187c478bd9Sstevel@tonic-gate static int
pshot_power(dev_info_t * dip,int cmpt,int level)13197c478bd9Sstevel@tonic-gate pshot_power(dev_info_t *dip, int cmpt, int level)
13207c478bd9Sstevel@tonic-gate {
13217c478bd9Sstevel@tonic-gate pshot_t *pshot;
13227c478bd9Sstevel@tonic-gate int instance = ddi_get_instance(dip);
13237c478bd9Sstevel@tonic-gate char *name = ddi_node_name(dip);
13247c478bd9Sstevel@tonic-gate int circ;
13257c478bd9Sstevel@tonic-gate int rv;
13267c478bd9Sstevel@tonic-gate
13277c478bd9Sstevel@tonic-gate pshot = ddi_get_soft_state(pshot_softstatep, instance);
13287c478bd9Sstevel@tonic-gate if (pshot == NULL) {
13297c478bd9Sstevel@tonic-gate
13307c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
13317c478bd9Sstevel@tonic-gate }
13327c478bd9Sstevel@tonic-gate
13337c478bd9Sstevel@tonic-gate ndi_devi_enter(dip, &circ);
13347c478bd9Sstevel@tonic-gate
13357c478bd9Sstevel@tonic-gate /*
13367c478bd9Sstevel@tonic-gate * set POWER_FLAG when power() is called.
13377c478bd9Sstevel@tonic-gate * ioctl(DEVCT_PM_POWER) is a clear on read call.
13387c478bd9Sstevel@tonic-gate */
13397c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
13407c478bd9Sstevel@tonic-gate pshot->state |= POWER_FLAG;
13417c478bd9Sstevel@tonic-gate /*
13427c478bd9Sstevel@tonic-gate * refuse to power OFF if the component is busy
13437c478bd9Sstevel@tonic-gate */
13447c478bd9Sstevel@tonic-gate if (pshot->busy != 0 && pshot->level > level) {
13457c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "%s%d: power: REFUSING POWER LEVEL CHANGE"
13467c478bd9Sstevel@tonic-gate " (%d->%d), DEVICE NOT IDLE: busy = %d",
13477c478bd9Sstevel@tonic-gate name, instance, pshot->level, level, pshot->busy);
13487c478bd9Sstevel@tonic-gate rv = DDI_FAILURE;
13497c478bd9Sstevel@tonic-gate } else {
13507c478bd9Sstevel@tonic-gate if (pshot_debug) {
13517c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: power: comp %d (%d->%d)\n",
13527c478bd9Sstevel@tonic-gate name, instance, cmpt, pshot->level, level);
13537c478bd9Sstevel@tonic-gate }
13547c478bd9Sstevel@tonic-gate pshot->level = level;
13557c478bd9Sstevel@tonic-gate rv = DDI_SUCCESS;
13567c478bd9Sstevel@tonic-gate }
13577c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
13587c478bd9Sstevel@tonic-gate
13597c478bd9Sstevel@tonic-gate ndi_devi_exit(dip, circ);
13607c478bd9Sstevel@tonic-gate
13617c478bd9Sstevel@tonic-gate return (rv);
13627c478bd9Sstevel@tonic-gate }
13637c478bd9Sstevel@tonic-gate
13647c478bd9Sstevel@tonic-gate /*ARGSUSED0*/
13657c478bd9Sstevel@tonic-gate static int
pshot_bus_power(dev_info_t * dip,void * impl_arg,pm_bus_power_op_t op,void * arg,void * result)13667c478bd9Sstevel@tonic-gate pshot_bus_power(dev_info_t *dip, void *impl_arg, pm_bus_power_op_t op,
13677c478bd9Sstevel@tonic-gate void *arg, void *result)
13687c478bd9Sstevel@tonic-gate
13697c478bd9Sstevel@tonic-gate {
13707c478bd9Sstevel@tonic-gate int ret;
13717c478bd9Sstevel@tonic-gate int instance = ddi_get_instance(dip);
13727c478bd9Sstevel@tonic-gate char *name = ddi_node_name(dip);
13737c478bd9Sstevel@tonic-gate pshot_t *pshot;
13747c478bd9Sstevel@tonic-gate pm_bp_child_pwrchg_t *bpc;
13757c478bd9Sstevel@tonic-gate pm_bp_nexus_pwrup_t bpn;
13767c478bd9Sstevel@tonic-gate pm_bp_has_changed_t *bphc;
13777c478bd9Sstevel@tonic-gate int pwrup_res;
13787c478bd9Sstevel@tonic-gate int ret_failed = 0;
13797c478bd9Sstevel@tonic-gate int pwrup_res_failed = 0;
13807c478bd9Sstevel@tonic-gate
13817c478bd9Sstevel@tonic-gate pshot = ddi_get_soft_state(pshot_softstatep, instance);
13827c478bd9Sstevel@tonic-gate if (pshot == NULL) {
13837c478bd9Sstevel@tonic-gate
13847c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
13857c478bd9Sstevel@tonic-gate }
13867c478bd9Sstevel@tonic-gate
13877c478bd9Sstevel@tonic-gate switch (op) {
13887c478bd9Sstevel@tonic-gate case BUS_POWER_PRE_NOTIFICATION:
13897c478bd9Sstevel@tonic-gate bpc = (pm_bp_child_pwrchg_t *)arg;
13907c478bd9Sstevel@tonic-gate if (pshot_debug) {
13917c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: pre_bus_power:"
13927c478bd9Sstevel@tonic-gate " %s%d comp %d (%d->%d)\n",
13937c478bd9Sstevel@tonic-gate name, instance, ddi_node_name(bpc->bpc_dip),
13947c478bd9Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip),
13957c478bd9Sstevel@tonic-gate bpc->bpc_comp, bpc->bpc_olevel,
13967c478bd9Sstevel@tonic-gate bpc->bpc_nlevel);
13977c478bd9Sstevel@tonic-gate }
13987c478bd9Sstevel@tonic-gate
13997c478bd9Sstevel@tonic-gate /*
14007c478bd9Sstevel@tonic-gate * mark parent busy if old_level is either -1 or 0,
14017c478bd9Sstevel@tonic-gate * and new level is == MAXPWR
14027c478bd9Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm)
14037c478bd9Sstevel@tonic-gate */
14047c478bd9Sstevel@tonic-gate if ((bpc->bpc_comp == 0 && bpc->bpc_nlevel == MAXPWR &&
14057c478bd9Sstevel@tonic-gate bpc->bpc_olevel <= 0) && (pshot->state & PM_SUPPORTED)) {
14067c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
14077c478bd9Sstevel@tonic-gate ++(pshot->busy);
14087c478bd9Sstevel@tonic-gate if (pshot_debug_busy) {
14097c478bd9Sstevel@tonic-gate cmn_err(CE_CONT,
14107c478bd9Sstevel@tonic-gate "%s%d: pre_bus_power:"
14117c478bd9Sstevel@tonic-gate " busy parent for %s%d (%d->%d): "
14127c478bd9Sstevel@tonic-gate " busy = %d\n",
14137c478bd9Sstevel@tonic-gate name, instance,
14147c478bd9Sstevel@tonic-gate ddi_node_name(bpc->bpc_dip),
14157c478bd9Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip),
14167c478bd9Sstevel@tonic-gate bpc->bpc_olevel, bpc->bpc_nlevel,
14177c478bd9Sstevel@tonic-gate pshot->busy);
14187c478bd9Sstevel@tonic-gate }
14197c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
14207c478bd9Sstevel@tonic-gate ret = pm_busy_component(dip, 0);
14217c478bd9Sstevel@tonic-gate ASSERT(ret == DDI_SUCCESS);
14227c478bd9Sstevel@tonic-gate }
14237c478bd9Sstevel@tonic-gate
14247c478bd9Sstevel@tonic-gate /*
14257c478bd9Sstevel@tonic-gate * if new_level > 0, power up parent, if not already at
14267c478bd9Sstevel@tonic-gate * MAXPWR, via pm_busop_bus_power
14277c478bd9Sstevel@tonic-gate * - skip for the no-pm nexus (pshot@XXX,nopm)
14287c478bd9Sstevel@tonic-gate */
14297c478bd9Sstevel@tonic-gate if (bpc->bpc_comp == 0 && bpc->bpc_nlevel > 0 &&
14307c478bd9Sstevel@tonic-gate pshot->level < MAXPWR && (pshot->state & PM_SUPPORTED)) {
14317c478bd9Sstevel@tonic-gate /*
14327c478bd9Sstevel@tonic-gate * stuff the bpn struct
14337c478bd9Sstevel@tonic-gate */
14347c478bd9Sstevel@tonic-gate bpn.bpn_comp = 0;
14357c478bd9Sstevel@tonic-gate bpn.bpn_level = MAXPWR;
14367c478bd9Sstevel@tonic-gate bpn.bpn_private = bpc->bpc_private;
14377c478bd9Sstevel@tonic-gate bpn.bpn_dip = dip;
14387c478bd9Sstevel@tonic-gate
14397c478bd9Sstevel@tonic-gate /*
14407c478bd9Sstevel@tonic-gate * ask pm to power parent up
14417c478bd9Sstevel@tonic-gate */
14427c478bd9Sstevel@tonic-gate if (pshot_debug) {
14437c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: pre_bus_power:"
14447c478bd9Sstevel@tonic-gate " pm_busop_bus_power on parent for %s%d"
14457c478bd9Sstevel@tonic-gate " (%d->%d): enter", name, instance,
14467c478bd9Sstevel@tonic-gate ddi_node_name(bpc->bpc_dip),
14477c478bd9Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip),
14487c478bd9Sstevel@tonic-gate bpc->bpc_olevel, bpc->bpc_nlevel);
14497c478bd9Sstevel@tonic-gate }
14507c478bd9Sstevel@tonic-gate ret = pm_busop_bus_power(dip, impl_arg,
14517c478bd9Sstevel@tonic-gate BUS_POWER_NEXUS_PWRUP, (void *)&bpn,
14527c478bd9Sstevel@tonic-gate (void *)&pwrup_res);
14537c478bd9Sstevel@tonic-gate
14547c478bd9Sstevel@tonic-gate /*
14557c478bd9Sstevel@tonic-gate * check the return status individually,
14567c478bd9Sstevel@tonic-gate * idle parent and exit if either failed.
14577c478bd9Sstevel@tonic-gate */
14587c478bd9Sstevel@tonic-gate if (ret != DDI_SUCCESS) {
14597c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
14607c478bd9Sstevel@tonic-gate "%s%d: pre_bus_power:"
14617c478bd9Sstevel@tonic-gate " pm_busop_bus_power FAILED (ret) FOR"
14627c478bd9Sstevel@tonic-gate " %s%d (%d->%d)",
14637c478bd9Sstevel@tonic-gate name, instance,
14647c478bd9Sstevel@tonic-gate ddi_node_name(bpc->bpc_dip),
14657c478bd9Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip),
14667c478bd9Sstevel@tonic-gate bpc->bpc_olevel, bpc->bpc_nlevel);
14677c478bd9Sstevel@tonic-gate ret_failed = 1;
14687c478bd9Sstevel@tonic-gate }
14697c478bd9Sstevel@tonic-gate if (pwrup_res != DDI_SUCCESS) {
14707c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
14717c478bd9Sstevel@tonic-gate "%s%d: pre_bus_power:"
14727c478bd9Sstevel@tonic-gate " pm_busop_bus_power FAILED (pwrup_res)"
14737c478bd9Sstevel@tonic-gate " FOR %s%d (%d->%d)",
14747c478bd9Sstevel@tonic-gate name, instance,
14757c478bd9Sstevel@tonic-gate ddi_node_name(bpc->bpc_dip),
14767c478bd9Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip),
14777c478bd9Sstevel@tonic-gate bpc->bpc_olevel, bpc->bpc_nlevel);
14787c478bd9Sstevel@tonic-gate pwrup_res_failed = 1;
14797c478bd9Sstevel@tonic-gate }
14807c478bd9Sstevel@tonic-gate if (ret_failed || pwrup_res_failed) {
14817c478bd9Sstevel@tonic-gate /*
14827c478bd9Sstevel@tonic-gate * decrement the busy count if it
14837c478bd9Sstevel@tonic-gate * had been incremented.
14847c478bd9Sstevel@tonic-gate */
14857c478bd9Sstevel@tonic-gate if ((bpc->bpc_comp == 0 &&
14867c478bd9Sstevel@tonic-gate bpc->bpc_nlevel == MAXPWR &&
14877c478bd9Sstevel@tonic-gate bpc->bpc_olevel <= 0) &&
14887c478bd9Sstevel@tonic-gate (pshot->state & PM_SUPPORTED)) {
14897c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
14907c478bd9Sstevel@tonic-gate ASSERT(pshot->busy > 0);
14917c478bd9Sstevel@tonic-gate --(pshot->busy);
14927c478bd9Sstevel@tonic-gate if (pshot_debug_busy) {
14937c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d:"
14947c478bd9Sstevel@tonic-gate " pm_busop_bus_power"
14957c478bd9Sstevel@tonic-gate " failed: idle parent for"
14967c478bd9Sstevel@tonic-gate " %s%d (%d->%d):"
14977c478bd9Sstevel@tonic-gate " busy = %d\n",
14987c478bd9Sstevel@tonic-gate name, instance,
14997c478bd9Sstevel@tonic-gate ddi_node_name(
15007c478bd9Sstevel@tonic-gate bpc->bpc_dip),
15017c478bd9Sstevel@tonic-gate ddi_get_instance(
15027c478bd9Sstevel@tonic-gate bpc->bpc_dip),
15037c478bd9Sstevel@tonic-gate bpc->bpc_olevel,
15047c478bd9Sstevel@tonic-gate bpc->bpc_nlevel,
15057c478bd9Sstevel@tonic-gate pshot->busy);
15067c478bd9Sstevel@tonic-gate }
15077c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
15087c478bd9Sstevel@tonic-gate ret = pm_idle_component(dip, 0);
15097c478bd9Sstevel@tonic-gate ASSERT(ret == DDI_SUCCESS);
15107c478bd9Sstevel@tonic-gate }
15117c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
15127c478bd9Sstevel@tonic-gate
15137c478bd9Sstevel@tonic-gate } else {
15147c478bd9Sstevel@tonic-gate if (pshot_debug) {
15157c478bd9Sstevel@tonic-gate cmn_err(CE_CONT,
15167c478bd9Sstevel@tonic-gate "%s%d: pre_bus_power:"
15177c478bd9Sstevel@tonic-gate " pm_busop_bus_power on parent"
15187c478bd9Sstevel@tonic-gate " for %s%d (%d->%d)\n",
15197c478bd9Sstevel@tonic-gate name, instance,
15207c478bd9Sstevel@tonic-gate ddi_node_name(bpc->bpc_dip),
15217c478bd9Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip),
15227c478bd9Sstevel@tonic-gate bpc->bpc_olevel, bpc->bpc_nlevel);
15237c478bd9Sstevel@tonic-gate }
15247c478bd9Sstevel@tonic-gate }
15257c478bd9Sstevel@tonic-gate }
15267c478bd9Sstevel@tonic-gate break;
15277c478bd9Sstevel@tonic-gate
15287c478bd9Sstevel@tonic-gate case BUS_POWER_POST_NOTIFICATION:
15297c478bd9Sstevel@tonic-gate bpc = (pm_bp_child_pwrchg_t *)arg;
15307c478bd9Sstevel@tonic-gate if (pshot_debug) {
15317c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: post_bus_power:"
15327c478bd9Sstevel@tonic-gate " %s%d comp %d (%d->%d) result %d\n",
15337c478bd9Sstevel@tonic-gate name, instance, ddi_node_name(bpc->bpc_dip),
15347c478bd9Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip),
15357c478bd9Sstevel@tonic-gate bpc->bpc_comp, bpc->bpc_olevel,
15367c478bd9Sstevel@tonic-gate bpc->bpc_nlevel, *(int *)result);
15377c478bd9Sstevel@tonic-gate }
15387c478bd9Sstevel@tonic-gate
15397c478bd9Sstevel@tonic-gate /*
15407c478bd9Sstevel@tonic-gate * handle pm_busop_bus_power() failure case.
15417c478bd9Sstevel@tonic-gate * mark parent idle if had been marked busy.
15427c478bd9Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm)
15437c478bd9Sstevel@tonic-gate */
15447c478bd9Sstevel@tonic-gate if (*(int *)result != DDI_SUCCESS) {
15457c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
15467c478bd9Sstevel@tonic-gate "pshot%d: post_bus_power_failed:"
15477c478bd9Sstevel@tonic-gate " pm_busop_bus_power FAILED FOR %s%d (%d->%d)",
15487c478bd9Sstevel@tonic-gate instance, ddi_node_name(bpc->bpc_dip),
15497c478bd9Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip),
15507c478bd9Sstevel@tonic-gate bpc->bpc_olevel, bpc->bpc_nlevel);
15517c478bd9Sstevel@tonic-gate
15527c478bd9Sstevel@tonic-gate if ((bpc->bpc_comp == 0 && bpc->bpc_nlevel == MAXPWR &&
15537c478bd9Sstevel@tonic-gate bpc->bpc_olevel <= 0) &&
15547c478bd9Sstevel@tonic-gate (pshot->state & PM_SUPPORTED)) {
15557c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
15567c478bd9Sstevel@tonic-gate ASSERT(pshot->busy > 0);
15577c478bd9Sstevel@tonic-gate --(pshot->busy);
15587c478bd9Sstevel@tonic-gate if (pshot_debug_busy) {
15597c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d:"
15607c478bd9Sstevel@tonic-gate " post_bus_power_failed:"
15617c478bd9Sstevel@tonic-gate " idle parent for %s%d"
15627c478bd9Sstevel@tonic-gate " (%d->%d): busy = %d\n",
15637c478bd9Sstevel@tonic-gate name, instance,
15647c478bd9Sstevel@tonic-gate ddi_node_name(bpc->bpc_dip),
15657c478bd9Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip),
15667c478bd9Sstevel@tonic-gate bpc->bpc_olevel, bpc->bpc_nlevel,
15677c478bd9Sstevel@tonic-gate pshot->busy);
15687c478bd9Sstevel@tonic-gate }
15697c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
15707c478bd9Sstevel@tonic-gate ret = pm_idle_component(dip, 0);
15717c478bd9Sstevel@tonic-gate ASSERT(ret == DDI_SUCCESS);
15727c478bd9Sstevel@tonic-gate }
15737c478bd9Sstevel@tonic-gate }
15747c478bd9Sstevel@tonic-gate
15757c478bd9Sstevel@tonic-gate /*
15767c478bd9Sstevel@tonic-gate * Mark nexus idle when a child's comp 0
15777c478bd9Sstevel@tonic-gate * is set to level 0 from level 1, 2, or 3 only.
15787c478bd9Sstevel@tonic-gate * And only if result arg == DDI_SUCCESS.
15797c478bd9Sstevel@tonic-gate * This will leave the parent busy when the child
15807c478bd9Sstevel@tonic-gate * does not call pm_lower_power() on detach after
15817c478bd9Sstevel@tonic-gate * unsetting the NO_LOWER_POWER flag.
15827c478bd9Sstevel@tonic-gate * If so, need to notify the parent to mark itself
15837c478bd9Sstevel@tonic-gate * idle anyway, else the no-involumtary-power-cycles
15847c478bd9Sstevel@tonic-gate * test cases will report false passes!
15857c478bd9Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm)
15867c478bd9Sstevel@tonic-gate */
15877c478bd9Sstevel@tonic-gate if ((bpc->bpc_comp == 0 && bpc->bpc_nlevel == 0 &&
15887c478bd9Sstevel@tonic-gate !(bpc->bpc_olevel <= 0) &&
15897c478bd9Sstevel@tonic-gate *(int *)result == DDI_SUCCESS) &&
15907c478bd9Sstevel@tonic-gate (pshot->state & PM_SUPPORTED)) {
15917c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
15927c478bd9Sstevel@tonic-gate ASSERT(pshot->busy > 0);
15937c478bd9Sstevel@tonic-gate --(pshot->busy);
15947c478bd9Sstevel@tonic-gate if (pshot_debug_busy) {
15957c478bd9Sstevel@tonic-gate cmn_err(CE_CONT,
15967c478bd9Sstevel@tonic-gate "%s%d: post_bus_power:"
15977c478bd9Sstevel@tonic-gate " idle parent for %s%d (%d->%d):"
15987c478bd9Sstevel@tonic-gate " busy = %d\n", name, instance,
15997c478bd9Sstevel@tonic-gate ddi_node_name(bpc->bpc_dip),
16007c478bd9Sstevel@tonic-gate ddi_get_instance(bpc->bpc_dip),
16017c478bd9Sstevel@tonic-gate bpc->bpc_olevel, bpc->bpc_nlevel,
16027c478bd9Sstevel@tonic-gate pshot->busy);
16037c478bd9Sstevel@tonic-gate }
16047c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
16057c478bd9Sstevel@tonic-gate ret = pm_idle_component(dip, 0);
16067c478bd9Sstevel@tonic-gate ASSERT(ret == DDI_SUCCESS);
16077c478bd9Sstevel@tonic-gate }
16087c478bd9Sstevel@tonic-gate break;
16097c478bd9Sstevel@tonic-gate
16107c478bd9Sstevel@tonic-gate case BUS_POWER_HAS_CHANGED:
16117c478bd9Sstevel@tonic-gate bphc = (pm_bp_has_changed_t *)arg;
16127c478bd9Sstevel@tonic-gate if (pshot_debug) {
16137c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "%s%d: has_changed_bus_power:"
16147c478bd9Sstevel@tonic-gate " %s%d comp %d (%d->%d) result %d\n",
16157c478bd9Sstevel@tonic-gate name, instance, ddi_node_name(bphc->bphc_dip),
16167c478bd9Sstevel@tonic-gate ddi_get_instance(bphc->bphc_dip),
16177c478bd9Sstevel@tonic-gate bphc->bphc_comp, bphc->bphc_olevel,
16187c478bd9Sstevel@tonic-gate bphc->bphc_nlevel, *(int *)result);
16197c478bd9Sstevel@tonic-gate }
16207c478bd9Sstevel@tonic-gate
16217c478bd9Sstevel@tonic-gate /*
16227c478bd9Sstevel@tonic-gate * Mark nexus idle when a child's comp 0
16237c478bd9Sstevel@tonic-gate * is set to level 0 from levels 1, 2, or 3 only.
16247c478bd9Sstevel@tonic-gate *
16257c478bd9Sstevel@tonic-gate * If powering up child leaf/nexus nodes via
16267c478bd9Sstevel@tonic-gate * pm_power_has_changed() calls, first issue
16277c478bd9Sstevel@tonic-gate * DEVCTL_PM_BUSY_COMP ioctl to mark parent busy
16287c478bd9Sstevel@tonic-gate * before powering the parent up, then power up the
16297c478bd9Sstevel@tonic-gate * child node.
16307c478bd9Sstevel@tonic-gate * - skip if PM_SUPPORTED is not set (pshot@XXX,nopm)
16317c478bd9Sstevel@tonic-gate */
16327c478bd9Sstevel@tonic-gate if ((bphc->bphc_comp == 0 && bphc->bphc_nlevel == 0 &&
16337c478bd9Sstevel@tonic-gate !(bphc->bphc_olevel <= 0)) &&
16347c478bd9Sstevel@tonic-gate pshot->state & PM_SUPPORTED) {
16357c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
16367c478bd9Sstevel@tonic-gate ASSERT(pshot->busy > 0);
16377c478bd9Sstevel@tonic-gate --(pshot->busy);
16387c478bd9Sstevel@tonic-gate if (pshot_debug_busy) {
16397c478bd9Sstevel@tonic-gate cmn_err(CE_CONT,
16407c478bd9Sstevel@tonic-gate "%s%d: has_changed_bus_power:"
16417c478bd9Sstevel@tonic-gate " idle parent for %s%d (%d->%d):"
16427c478bd9Sstevel@tonic-gate " busy = %d\n", name, instance,
16437c478bd9Sstevel@tonic-gate ddi_node_name(bphc->bphc_dip),
16447c478bd9Sstevel@tonic-gate ddi_get_instance(bphc->bphc_dip),
16457c478bd9Sstevel@tonic-gate bphc->bphc_olevel,
16467c478bd9Sstevel@tonic-gate bphc->bphc_nlevel, pshot->busy);
16477c478bd9Sstevel@tonic-gate }
16487c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
16497c478bd9Sstevel@tonic-gate ret = pm_idle_component(dip, 0);
16507c478bd9Sstevel@tonic-gate ASSERT(ret == DDI_SUCCESS);
16517c478bd9Sstevel@tonic-gate }
16527c478bd9Sstevel@tonic-gate break;
16537c478bd9Sstevel@tonic-gate
16547c478bd9Sstevel@tonic-gate default:
16557c478bd9Sstevel@tonic-gate return (pm_busop_bus_power(dip, impl_arg, op, arg, result));
16567c478bd9Sstevel@tonic-gate
16577c478bd9Sstevel@tonic-gate }
16587c478bd9Sstevel@tonic-gate
16597c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
16607c478bd9Sstevel@tonic-gate }
16617c478bd9Sstevel@tonic-gate
16627c478bd9Sstevel@tonic-gate static int
pshot_initchild(dev_info_t * dip,dev_info_t * child)16637c478bd9Sstevel@tonic-gate pshot_initchild(dev_info_t *dip, dev_info_t *child)
16647c478bd9Sstevel@tonic-gate {
16657c478bd9Sstevel@tonic-gate char name[64];
16667c478bd9Sstevel@tonic-gate char *bus_addr;
16677c478bd9Sstevel@tonic-gate char *c_nodename;
16687c478bd9Sstevel@tonic-gate int bus_id;
16697c478bd9Sstevel@tonic-gate dev_info_t *enum_child;
16707c478bd9Sstevel@tonic-gate int enum_base;
16717c478bd9Sstevel@tonic-gate int enum_extent;
16727c478bd9Sstevel@tonic-gate
16737c478bd9Sstevel@tonic-gate
16747c478bd9Sstevel@tonic-gate /* check for bus_enum node */
16757c478bd9Sstevel@tonic-gate
16767c478bd9Sstevel@tonic-gate #ifdef NOT_USED
16777c478bd9Sstevel@tonic-gate if (impl_ddi_merge_child(child) != DDI_SUCCESS)
16787c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
16797c478bd9Sstevel@tonic-gate #endif
16807c478bd9Sstevel@tonic-gate
16817c478bd9Sstevel@tonic-gate enum_base = ddi_prop_get_int(DDI_DEV_T_ANY, child, DDI_PROP_DONTPASS,
16827c478bd9Sstevel@tonic-gate "busid_ebase", 0);
16837c478bd9Sstevel@tonic-gate
16847c478bd9Sstevel@tonic-gate enum_extent = ddi_prop_get_int(DDI_DEV_T_ANY, child,
16857c478bd9Sstevel@tonic-gate DDI_PROP_DONTPASS, "busid_range", 0);
16867c478bd9Sstevel@tonic-gate
16877c478bd9Sstevel@tonic-gate /*
16887c478bd9Sstevel@tonic-gate * bus enumeration node
16897c478bd9Sstevel@tonic-gate */
16907c478bd9Sstevel@tonic-gate if ((enum_base != 0) && (enum_extent != 0)) {
16917c478bd9Sstevel@tonic-gate c_nodename = ddi_node_name(child);
16927c478bd9Sstevel@tonic-gate bus_id = enum_base;
16937c478bd9Sstevel@tonic-gate for (; bus_id < enum_extent; bus_id++) {
16947c478bd9Sstevel@tonic-gate if (ndi_devi_alloc(dip, c_nodename, DEVI_PSEUDO_NODEID,
16957c478bd9Sstevel@tonic-gate &enum_child) != NDI_SUCCESS)
16967c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
16977c478bd9Sstevel@tonic-gate
16987c478bd9Sstevel@tonic-gate (void) sprintf(name, "%d", bus_id);
16997c478bd9Sstevel@tonic-gate if (ndi_prop_update_string(DDI_DEV_T_NONE, enum_child,
17007c478bd9Sstevel@tonic-gate "bus-addr", name) != DDI_PROP_SUCCESS) {
17017c478bd9Sstevel@tonic-gate (void) ndi_devi_free(enum_child);
17027c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
17037c478bd9Sstevel@tonic-gate }
17047c478bd9Sstevel@tonic-gate
17057c478bd9Sstevel@tonic-gate if (ndi_devi_online(enum_child, 0) !=
17067c478bd9Sstevel@tonic-gate DDI_SUCCESS) {
17077c478bd9Sstevel@tonic-gate (void) ndi_devi_free(enum_child);
17087c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
17097c478bd9Sstevel@tonic-gate }
17107c478bd9Sstevel@tonic-gate }
17117c478bd9Sstevel@tonic-gate /*
17127c478bd9Sstevel@tonic-gate * fail the enumeration node itself
17137c478bd9Sstevel@tonic-gate */
17147c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
17157c478bd9Sstevel@tonic-gate }
17167c478bd9Sstevel@tonic-gate
17177c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, child, 0, "bus-addr",
17187c478bd9Sstevel@tonic-gate &bus_addr) != DDI_PROP_SUCCESS) {
17197c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pshot_initchild: bus-addr not defined (%s)",
17207c478bd9Sstevel@tonic-gate ddi_node_name(child));
17217c478bd9Sstevel@tonic-gate return (DDI_NOT_WELL_FORMED);
17227c478bd9Sstevel@tonic-gate }
17237c478bd9Sstevel@tonic-gate
17247c478bd9Sstevel@tonic-gate if (strlen(bus_addr) == 0) {
17257c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pshot_initchild: NULL bus-addr (%s)",
17267c478bd9Sstevel@tonic-gate ddi_node_name(child));
17277c478bd9Sstevel@tonic-gate ddi_prop_free(bus_addr);
17287c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
17297c478bd9Sstevel@tonic-gate }
17307c478bd9Sstevel@tonic-gate
17317c478bd9Sstevel@tonic-gate if (strncmp(bus_addr, "failinit", 8) == 0) {
17327c478bd9Sstevel@tonic-gate if (pshot_debug)
17337c478bd9Sstevel@tonic-gate cmn_err(CE_CONT,
17347c478bd9Sstevel@tonic-gate "pshot%d: %s forced INITCHILD failure\n",
17357c478bd9Sstevel@tonic-gate ddi_get_instance(dip), bus_addr);
17367c478bd9Sstevel@tonic-gate ddi_prop_free(bus_addr);
17377c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
17387c478bd9Sstevel@tonic-gate }
17397c478bd9Sstevel@tonic-gate
17407c478bd9Sstevel@tonic-gate if (pshot_log) {
17417c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "initchild %s%d/%s@%s\n",
17427c478bd9Sstevel@tonic-gate ddi_get_name(dip), ddi_get_instance(dip),
17437c478bd9Sstevel@tonic-gate ddi_node_name(child), bus_addr);
17447c478bd9Sstevel@tonic-gate }
17457c478bd9Sstevel@tonic-gate
17467c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, bus_addr);
17477c478bd9Sstevel@tonic-gate ddi_prop_free(bus_addr);
17487c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
17497c478bd9Sstevel@tonic-gate }
17507c478bd9Sstevel@tonic-gate
17517c478bd9Sstevel@tonic-gate /*ARGSUSED*/
17527c478bd9Sstevel@tonic-gate static int
pshot_uninitchild(dev_info_t * dip,dev_info_t * child)17537c478bd9Sstevel@tonic-gate pshot_uninitchild(dev_info_t *dip, dev_info_t *child)
17547c478bd9Sstevel@tonic-gate {
17557c478bd9Sstevel@tonic-gate ddi_set_name_addr(child, NULL);
17567c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
17577c478bd9Sstevel@tonic-gate }
17587c478bd9Sstevel@tonic-gate
17597c478bd9Sstevel@tonic-gate
17607c478bd9Sstevel@tonic-gate /*
17617c478bd9Sstevel@tonic-gate * devctl IOCTL support
17627c478bd9Sstevel@tonic-gate */
17637c478bd9Sstevel@tonic-gate /* ARGSUSED */
17647c478bd9Sstevel@tonic-gate static int
pshot_open(dev_t * devp,int flags,int otyp,cred_t * credp)17657c478bd9Sstevel@tonic-gate pshot_open(dev_t *devp, int flags, int otyp, cred_t *credp)
17667c478bd9Sstevel@tonic-gate {
17677c478bd9Sstevel@tonic-gate int instance;
17687c478bd9Sstevel@tonic-gate pshot_t *pshot;
17697c478bd9Sstevel@tonic-gate
17707c478bd9Sstevel@tonic-gate if (otyp != OTYP_CHR)
17717c478bd9Sstevel@tonic-gate return (EINVAL);
17727c478bd9Sstevel@tonic-gate
17737c478bd9Sstevel@tonic-gate instance = pshot_minor_decode_inst(getminor(*devp));
17747c478bd9Sstevel@tonic-gate if ((pshot = ddi_get_soft_state(pshot_softstatep, instance)) == NULL)
17757c478bd9Sstevel@tonic-gate return (ENXIO);
17767c478bd9Sstevel@tonic-gate
17777c478bd9Sstevel@tonic-gate /*
17787c478bd9Sstevel@tonic-gate * Access is currently determined on a per-instance basis.
17797c478bd9Sstevel@tonic-gate * If we want per-node, then need to add state and lock members to
17807c478bd9Sstevel@tonic-gate * pshot_minor_t
17817c478bd9Sstevel@tonic-gate */
17827c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
17837c478bd9Sstevel@tonic-gate if (((flags & FEXCL) && (pshot->state & IS_OPEN)) ||
17847c478bd9Sstevel@tonic-gate (!(flags & FEXCL) && (pshot->state & IS_OPEN_EXCL))) {
17857c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
17867c478bd9Sstevel@tonic-gate return (EBUSY);
17877c478bd9Sstevel@tonic-gate }
17887c478bd9Sstevel@tonic-gate pshot->state |= IS_OPEN;
17897c478bd9Sstevel@tonic-gate if (flags & FEXCL)
17907c478bd9Sstevel@tonic-gate pshot->state |= IS_OPEN_EXCL;
17917c478bd9Sstevel@tonic-gate
17927c478bd9Sstevel@tonic-gate if (pshot_debug)
17937c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d open\n", instance);
17947c478bd9Sstevel@tonic-gate
17957c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
17967c478bd9Sstevel@tonic-gate return (0);
17977c478bd9Sstevel@tonic-gate }
17987c478bd9Sstevel@tonic-gate
17997c478bd9Sstevel@tonic-gate /*
18007c478bd9Sstevel@tonic-gate * pshot_close
18017c478bd9Sstevel@tonic-gate */
18027c478bd9Sstevel@tonic-gate /* ARGSUSED */
18037c478bd9Sstevel@tonic-gate static int
pshot_close(dev_t dev,int flag,int otyp,cred_t * credp)18047c478bd9Sstevel@tonic-gate pshot_close(dev_t dev, int flag, int otyp, cred_t *credp)
18057c478bd9Sstevel@tonic-gate {
18067c478bd9Sstevel@tonic-gate int instance;
18077c478bd9Sstevel@tonic-gate pshot_t *pshot;
18087c478bd9Sstevel@tonic-gate
18097c478bd9Sstevel@tonic-gate if (otyp != OTYP_CHR)
18107c478bd9Sstevel@tonic-gate return (EINVAL);
18117c478bd9Sstevel@tonic-gate
18127c478bd9Sstevel@tonic-gate instance = pshot_minor_decode_inst(getminor(dev));
18137c478bd9Sstevel@tonic-gate if ((pshot = ddi_get_soft_state(pshot_softstatep, instance)) == NULL)
18147c478bd9Sstevel@tonic-gate return (ENXIO);
18157c478bd9Sstevel@tonic-gate
18167c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
18177c478bd9Sstevel@tonic-gate pshot->state &= ~(IS_OPEN | IS_OPEN_EXCL);
18187c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
18197c478bd9Sstevel@tonic-gate if (pshot_debug)
18207c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d closed\n", instance);
18217c478bd9Sstevel@tonic-gate return (0);
18227c478bd9Sstevel@tonic-gate }
18237c478bd9Sstevel@tonic-gate
18247c478bd9Sstevel@tonic-gate
18257c478bd9Sstevel@tonic-gate /*
18267c478bd9Sstevel@tonic-gate * pshot_ioctl: redirects to appropriate command handler based on various
18277c478bd9Sstevel@tonic-gate * criteria
18287c478bd9Sstevel@tonic-gate */
18297c478bd9Sstevel@tonic-gate /* ARGSUSED */
18307c478bd9Sstevel@tonic-gate static int
pshot_ioctl(dev_t dev,int cmd,intptr_t arg,int mode,cred_t * credp,int * rvalp)18317c478bd9Sstevel@tonic-gate pshot_ioctl(dev_t dev, int cmd, intptr_t arg, int mode, cred_t *credp,
18327c478bd9Sstevel@tonic-gate int *rvalp)
18337c478bd9Sstevel@tonic-gate {
18347c478bd9Sstevel@tonic-gate pshot_t *pshot;
18357c478bd9Sstevel@tonic-gate int instance;
18367c478bd9Sstevel@tonic-gate minor_t nodenum;
18377c478bd9Sstevel@tonic-gate char *nodename;
18387c478bd9Sstevel@tonic-gate
18397c478bd9Sstevel@tonic-gate instance = pshot_minor_decode_inst(getminor(dev));
18407c478bd9Sstevel@tonic-gate if ((pshot = ddi_get_soft_state(pshot_softstatep, instance)) == NULL)
18417c478bd9Sstevel@tonic-gate return (ENXIO);
18427c478bd9Sstevel@tonic-gate
18437c478bd9Sstevel@tonic-gate nodenum = pshot_minor_decode_nodenum(getminor(dev));
18447c478bd9Sstevel@tonic-gate nodename = pshot->nodes[nodenum].name;
18457c478bd9Sstevel@tonic-gate
18467c478bd9Sstevel@tonic-gate if (pshot_debug)
18477c478bd9Sstevel@tonic-gate cmn_err(CE_CONT,
18487c478bd9Sstevel@tonic-gate "pshot%d ioctl: dev=%p, cmd=%x, arg=%p, mode=%x\n",
18497c478bd9Sstevel@tonic-gate instance, (void *)dev, cmd, (void *)arg, mode);
18507c478bd9Sstevel@tonic-gate
18517c478bd9Sstevel@tonic-gate if (strcmp(nodename, PSHOT_NODENAME_DEVCTL) == 0)
18527c478bd9Sstevel@tonic-gate return (pshot_devctl(pshot, nodenum, cmd, arg, mode, credp,
18537c478bd9Sstevel@tonic-gate rvalp));
18547c478bd9Sstevel@tonic-gate
18557c478bd9Sstevel@tonic-gate if (strcmp(nodename, PSHOT_NODENAME_TESTCTL) == 0)
18567c478bd9Sstevel@tonic-gate return (pshot_testctl(pshot, nodenum, cmd, arg, mode, credp,
18577c478bd9Sstevel@tonic-gate rvalp));
18587c478bd9Sstevel@tonic-gate
18597c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pshot_ioctl: unmatched nodename on minor %u",
18607c478bd9Sstevel@tonic-gate pshot->nodes[nodenum].minor);
18617c478bd9Sstevel@tonic-gate return (ENXIO);
18627c478bd9Sstevel@tonic-gate }
18637c478bd9Sstevel@tonic-gate
18647c478bd9Sstevel@tonic-gate
18657c478bd9Sstevel@tonic-gate /*
18667c478bd9Sstevel@tonic-gate * pshot_devctl: handle DEVCTL operations
18677c478bd9Sstevel@tonic-gate */
18687c478bd9Sstevel@tonic-gate /* ARGSUSED */
18697c478bd9Sstevel@tonic-gate static int
pshot_devctl(pshot_t * pshot,minor_t nodenum,int cmd,intptr_t arg,int mode,cred_t * credp,int * rvalp)18707c478bd9Sstevel@tonic-gate pshot_devctl(pshot_t *pshot, minor_t nodenum, int cmd, intptr_t arg, int mode,
18717c478bd9Sstevel@tonic-gate cred_t *credp, int *rvalp)
18727c478bd9Sstevel@tonic-gate {
18737c478bd9Sstevel@tonic-gate dev_info_t *self;
18747c478bd9Sstevel@tonic-gate dev_info_t *child = NULL;
18757c478bd9Sstevel@tonic-gate struct devctl_iocdata *dcp;
18767c478bd9Sstevel@tonic-gate uint_t state;
18777c478bd9Sstevel@tonic-gate int rv = 0;
18787c478bd9Sstevel@tonic-gate uint_t flags;
18797c478bd9Sstevel@tonic-gate int instance;
18807c478bd9Sstevel@tonic-gate int i;
18817c478bd9Sstevel@tonic-gate int ret;
18827c478bd9Sstevel@tonic-gate
18837c478bd9Sstevel@tonic-gate self = pshot->dip;
18847c478bd9Sstevel@tonic-gate
18857c478bd9Sstevel@tonic-gate flags = (pshot_devctl_debug) ? NDI_DEVI_DEBUG : 0;
18867c478bd9Sstevel@tonic-gate instance = pshot->instance;
18877c478bd9Sstevel@tonic-gate
18887c478bd9Sstevel@tonic-gate /*
18897c478bd9Sstevel@tonic-gate * We can use the generic implementation for these ioctls
18907c478bd9Sstevel@tonic-gate */
18917c478bd9Sstevel@tonic-gate for (i = 0; pshot_devctls[i].ioctl_int != 0; i++) {
18927c478bd9Sstevel@tonic-gate if (pshot_devctls[i].ioctl_int == cmd) {
18937c478bd9Sstevel@tonic-gate if (pshot_debug)
18947c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl: %s",
18957c478bd9Sstevel@tonic-gate instance, pshot_devctls[i].ioctl_char);
18967c478bd9Sstevel@tonic-gate }
18977c478bd9Sstevel@tonic-gate }
18987c478bd9Sstevel@tonic-gate switch (cmd) {
18997c478bd9Sstevel@tonic-gate case DEVCTL_DEVICE_GETSTATE:
19007c478bd9Sstevel@tonic-gate case DEVCTL_DEVICE_ONLINE:
19017c478bd9Sstevel@tonic-gate case DEVCTL_DEVICE_OFFLINE:
19027c478bd9Sstevel@tonic-gate case DEVCTL_DEVICE_REMOVE:
19037c478bd9Sstevel@tonic-gate case DEVCTL_BUS_GETSTATE:
19047c478bd9Sstevel@tonic-gate case DEVCTL_BUS_DEV_CREATE:
19057c478bd9Sstevel@tonic-gate rv = ndi_devctl_ioctl(self, cmd, arg, mode, flags);
19067c478bd9Sstevel@tonic-gate if (pshot_debug && rv != 0) {
19077c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d ndi_devctl_ioctl:"
19087c478bd9Sstevel@tonic-gate " failed, rv = %d", instance, rv);
19097c478bd9Sstevel@tonic-gate }
19107c478bd9Sstevel@tonic-gate
19117c478bd9Sstevel@tonic-gate return (rv);
19127c478bd9Sstevel@tonic-gate }
19137c478bd9Sstevel@tonic-gate
19147c478bd9Sstevel@tonic-gate /*
19157c478bd9Sstevel@tonic-gate * read devctl ioctl data
19167c478bd9Sstevel@tonic-gate */
19177c478bd9Sstevel@tonic-gate if (ndi_dc_allochdl((void *)arg, &dcp) != NDI_SUCCESS)
19187c478bd9Sstevel@tonic-gate return (EFAULT);
19197c478bd9Sstevel@tonic-gate
19207c478bd9Sstevel@tonic-gate switch (cmd) {
19217c478bd9Sstevel@tonic-gate
19227c478bd9Sstevel@tonic-gate case DEVCTL_DEVICE_RESET:
19237c478bd9Sstevel@tonic-gate if (pshot_debug)
19247c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:"
19257c478bd9Sstevel@tonic-gate " DEVCTL_DEVICE_RESET\n", instance);
19267c478bd9Sstevel@tonic-gate rv = pshot_event(pshot, PSHOT_EVENT_TAG_DEV_RESET,
19277c478bd9Sstevel@tonic-gate child, (void *)self);
19287c478bd9Sstevel@tonic-gate ASSERT(rv == NDI_SUCCESS);
19297c478bd9Sstevel@tonic-gate break;
19307c478bd9Sstevel@tonic-gate
19317c478bd9Sstevel@tonic-gate case DEVCTL_BUS_QUIESCE:
19327c478bd9Sstevel@tonic-gate if (pshot_debug)
19337c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:"
19347c478bd9Sstevel@tonic-gate " DEVCTL_BUS_QUIESCE\n", instance);
19357c478bd9Sstevel@tonic-gate if (ndi_get_bus_state(self, &state) == NDI_SUCCESS) {
19367c478bd9Sstevel@tonic-gate if (state == BUS_QUIESCED) {
19377c478bd9Sstevel@tonic-gate break;
19387c478bd9Sstevel@tonic-gate }
19397c478bd9Sstevel@tonic-gate (void) ndi_set_bus_state(self, BUS_QUIESCED);
19407c478bd9Sstevel@tonic-gate }
19417c478bd9Sstevel@tonic-gate rv = pshot_event(pshot, PSHOT_EVENT_TAG_BUS_QUIESCE,
19427c478bd9Sstevel@tonic-gate child, (void *)self);
19437c478bd9Sstevel@tonic-gate ASSERT(rv == NDI_SUCCESS);
19447c478bd9Sstevel@tonic-gate
19457c478bd9Sstevel@tonic-gate break;
19467c478bd9Sstevel@tonic-gate
19477c478bd9Sstevel@tonic-gate case DEVCTL_BUS_UNQUIESCE:
19487c478bd9Sstevel@tonic-gate if (pshot_debug)
19497c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:"
19507c478bd9Sstevel@tonic-gate " DEVCTL_BUS_UNQUIESCE\n", instance);
19517c478bd9Sstevel@tonic-gate if (ndi_get_bus_state(self, &state) == NDI_SUCCESS) {
19527c478bd9Sstevel@tonic-gate if (state == BUS_ACTIVE) {
19537c478bd9Sstevel@tonic-gate break;
19547c478bd9Sstevel@tonic-gate }
19557c478bd9Sstevel@tonic-gate }
19567c478bd9Sstevel@tonic-gate
19577c478bd9Sstevel@tonic-gate /*
19587c478bd9Sstevel@tonic-gate * quiesce the bus through bus-specific means
19597c478bd9Sstevel@tonic-gate */
19607c478bd9Sstevel@tonic-gate (void) ndi_set_bus_state(self, BUS_ACTIVE);
19617c478bd9Sstevel@tonic-gate rv = pshot_event(pshot, PSHOT_EVENT_TAG_BUS_UNQUIESCE,
19627c478bd9Sstevel@tonic-gate child, (void *)self);
19637c478bd9Sstevel@tonic-gate ASSERT(rv == NDI_SUCCESS);
19647c478bd9Sstevel@tonic-gate break;
19657c478bd9Sstevel@tonic-gate
19667c478bd9Sstevel@tonic-gate case DEVCTL_BUS_RESET:
19677c478bd9Sstevel@tonic-gate case DEVCTL_BUS_RESETALL:
19687c478bd9Sstevel@tonic-gate /*
19697c478bd9Sstevel@tonic-gate * no reset support for the pseudo bus
19707c478bd9Sstevel@tonic-gate * but if there were....
19717c478bd9Sstevel@tonic-gate */
19727c478bd9Sstevel@tonic-gate rv = pshot_event(pshot, PSHOT_EVENT_TAG_BUS_RESET,
19737c478bd9Sstevel@tonic-gate child, (void *)self);
19747c478bd9Sstevel@tonic-gate ASSERT(rv == NDI_SUCCESS);
19757c478bd9Sstevel@tonic-gate break;
19767c478bd9Sstevel@tonic-gate
19777c478bd9Sstevel@tonic-gate /*
19787c478bd9Sstevel@tonic-gate * PM related ioctls
19797c478bd9Sstevel@tonic-gate */
19807c478bd9Sstevel@tonic-gate case DEVCTL_PM_BUSY_COMP:
19817c478bd9Sstevel@tonic-gate /*
19827c478bd9Sstevel@tonic-gate * mark component 0 busy.
19837c478bd9Sstevel@tonic-gate * Keep track of ioctl updates to the busy count
19847c478bd9Sstevel@tonic-gate * via pshot->busy_ioctl.
19857c478bd9Sstevel@tonic-gate */
19867c478bd9Sstevel@tonic-gate if (pshot_debug) {
19877c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:"
19887c478bd9Sstevel@tonic-gate " DEVCTL_PM_BUSY_COMP\n", instance);
19897c478bd9Sstevel@tonic-gate }
19907c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
19917c478bd9Sstevel@tonic-gate ++(pshot->busy);
19927c478bd9Sstevel@tonic-gate ++(pshot->busy_ioctl);
19937c478bd9Sstevel@tonic-gate if (pshot_debug_busy) {
19947c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:"
19957c478bd9Sstevel@tonic-gate " DEVCTL_PM_BUSY_COMP comp 0 busy"
19967c478bd9Sstevel@tonic-gate " %d busy_ioctl %d\n", instance, pshot->busy,
19977c478bd9Sstevel@tonic-gate pshot->busy_ioctl);
19987c478bd9Sstevel@tonic-gate }
19997c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
20007c478bd9Sstevel@tonic-gate ret = pm_busy_component(pshot->dip, 0);
20017c478bd9Sstevel@tonic-gate ASSERT(ret == DDI_SUCCESS);
20027c478bd9Sstevel@tonic-gate
20037c478bd9Sstevel@tonic-gate break;
20047c478bd9Sstevel@tonic-gate
20057c478bd9Sstevel@tonic-gate case DEVCTL_PM_BUSY_COMP_TEST:
20067c478bd9Sstevel@tonic-gate /*
20077c478bd9Sstevel@tonic-gate * test bus's busy state
20087c478bd9Sstevel@tonic-gate */
20097c478bd9Sstevel@tonic-gate if (pshot_debug) {
20107c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:"
20117c478bd9Sstevel@tonic-gate " DEVCTL_PM_BUSY_COMP_TEST\n", instance);
20127c478bd9Sstevel@tonic-gate }
20137c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
20147c478bd9Sstevel@tonic-gate state = pshot->busy;
20157c478bd9Sstevel@tonic-gate if (copyout(&state, dcp->cpyout_buf,
20167c478bd9Sstevel@tonic-gate sizeof (uint_t)) != 0) {
20177c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d devctl:"
20187c478bd9Sstevel@tonic-gate " DEVCTL_PM_BUSY_COMP_TEST: copyout failed",
20197c478bd9Sstevel@tonic-gate instance);
20207c478bd9Sstevel@tonic-gate rv = EINVAL;
20217c478bd9Sstevel@tonic-gate }
20227c478bd9Sstevel@tonic-gate if (pshot_debug_busy) {
20237c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DEVCTL_PM_BUSY_COMP_TEST:"
20247c478bd9Sstevel@tonic-gate " comp 0 busy %d busy_ioctl %d\n", instance,
20257c478bd9Sstevel@tonic-gate state, pshot->busy_ioctl);
20267c478bd9Sstevel@tonic-gate }
20277c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
20287c478bd9Sstevel@tonic-gate break;
20297c478bd9Sstevel@tonic-gate
20307c478bd9Sstevel@tonic-gate case DEVCTL_PM_IDLE_COMP:
20317c478bd9Sstevel@tonic-gate /*
20327c478bd9Sstevel@tonic-gate * mark component 0 idle.
20337c478bd9Sstevel@tonic-gate * NOP if pshot->busy_ioctl <= 0.
20347c478bd9Sstevel@tonic-gate */
20357c478bd9Sstevel@tonic-gate if (pshot_debug) {
20367c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:"
20377c478bd9Sstevel@tonic-gate " DEVCTL_PM_IDLE_COMP\n", instance);
20387c478bd9Sstevel@tonic-gate }
20397c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
20407c478bd9Sstevel@tonic-gate if (pshot->busy_ioctl > 0) {
20417c478bd9Sstevel@tonic-gate ASSERT(pshot->busy > 0);
20427c478bd9Sstevel@tonic-gate --(pshot->busy);
20437c478bd9Sstevel@tonic-gate --(pshot->busy_ioctl);
20447c478bd9Sstevel@tonic-gate if (pshot_debug_busy) {
20457c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:"
20467c478bd9Sstevel@tonic-gate " DEVCTL_PM_IDLE_COM: comp 0"
20477c478bd9Sstevel@tonic-gate " busy %d busy_ioctl %d\n", instance,
20487c478bd9Sstevel@tonic-gate pshot->busy, pshot->busy_ioctl);
20497c478bd9Sstevel@tonic-gate }
20507c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
20517c478bd9Sstevel@tonic-gate ret = pm_idle_component(pshot->dip, 0);
20527c478bd9Sstevel@tonic-gate ASSERT(ret == DDI_SUCCESS);
20537c478bd9Sstevel@tonic-gate
20547c478bd9Sstevel@tonic-gate } else {
20557c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
20567c478bd9Sstevel@tonic-gate }
20577c478bd9Sstevel@tonic-gate break;
20587c478bd9Sstevel@tonic-gate
20597c478bd9Sstevel@tonic-gate case DEVCTL_PM_RAISE_PWR:
20607c478bd9Sstevel@tonic-gate /*
20617c478bd9Sstevel@tonic-gate * raise component 0 to full power level MAXPWR via a
20627c478bd9Sstevel@tonic-gate * pm_raise_power() call
20637c478bd9Sstevel@tonic-gate */
20647c478bd9Sstevel@tonic-gate if (pshot_debug) {
20657c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:"
20667c478bd9Sstevel@tonic-gate " DEVCTL_PM_RAISE_PWR\n", instance);
20677c478bd9Sstevel@tonic-gate }
20687c478bd9Sstevel@tonic-gate if (pm_raise_power(pshot->dip, 0, MAXPWR) != DDI_SUCCESS) {
20697c478bd9Sstevel@tonic-gate rv = EINVAL;
20707c478bd9Sstevel@tonic-gate } else {
20717c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
20727c478bd9Sstevel@tonic-gate if (pshot_debug) {
20737c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:"
20747c478bd9Sstevel@tonic-gate " DEVCTL_PM_RAISE_POWER: comp 0"
20757c478bd9Sstevel@tonic-gate " to level %d\n", instance, pshot->level);
20767c478bd9Sstevel@tonic-gate }
20777c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
20787c478bd9Sstevel@tonic-gate }
20797c478bd9Sstevel@tonic-gate break;
20807c478bd9Sstevel@tonic-gate
20817c478bd9Sstevel@tonic-gate case DEVCTL_PM_LOWER_PWR:
20827c478bd9Sstevel@tonic-gate /*
20837c478bd9Sstevel@tonic-gate * pm_lower_power() call for negative testing
20847c478bd9Sstevel@tonic-gate * expected to fail.
20857c478bd9Sstevel@tonic-gate */
20867c478bd9Sstevel@tonic-gate if (pshot_debug) {
20877c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:"
20887c478bd9Sstevel@tonic-gate " DEVCTL_PM_LOWER_PWR\n", instance);
20897c478bd9Sstevel@tonic-gate }
20907c478bd9Sstevel@tonic-gate if (pm_lower_power(pshot->dip, 0, 0) != DDI_SUCCESS) {
20917c478bd9Sstevel@tonic-gate rv = EINVAL;
20927c478bd9Sstevel@tonic-gate } else {
20937c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
20947c478bd9Sstevel@tonic-gate if (pshot_debug) {
20957c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:"
20967c478bd9Sstevel@tonic-gate " DEVCTL_PM_LOWER_POWER comp 0"
20977c478bd9Sstevel@tonic-gate " to level %d\n", instance, pshot->level);
20987c478bd9Sstevel@tonic-gate }
20997c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
21007c478bd9Sstevel@tonic-gate }
21017c478bd9Sstevel@tonic-gate break;
21027c478bd9Sstevel@tonic-gate
21037c478bd9Sstevel@tonic-gate case DEVCTL_PM_CHANGE_PWR_LOW:
21047c478bd9Sstevel@tonic-gate /*
21057c478bd9Sstevel@tonic-gate * inform the PM framework that component 0 has changed
21067c478bd9Sstevel@tonic-gate * power level to 0 via a pm_power_has_changed() call
21077c478bd9Sstevel@tonic-gate */
21087c478bd9Sstevel@tonic-gate if (pshot_debug) {
21097c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:"
21107c478bd9Sstevel@tonic-gate " DEVCTL_PM_CHANGE_PWR_LOW\n", instance);
21117c478bd9Sstevel@tonic-gate }
21127c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
21137c478bd9Sstevel@tonic-gate pshot->level = 0;
21147c478bd9Sstevel@tonic-gate if (pm_power_has_changed(pshot->dip, 0, 0) != DDI_SUCCESS) {
21157c478bd9Sstevel@tonic-gate rv = EINVAL;
21167c478bd9Sstevel@tonic-gate } else {
21177c478bd9Sstevel@tonic-gate if (pshot_debug) {
21187c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:"
21197c478bd9Sstevel@tonic-gate " DEVCTL_PM_CHANGE_PWR_LOW comp 0 to"
21207c478bd9Sstevel@tonic-gate " level %d\n", instance, pshot->level);
21217c478bd9Sstevel@tonic-gate }
21227c478bd9Sstevel@tonic-gate }
21237c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
21247c478bd9Sstevel@tonic-gate break;
21257c478bd9Sstevel@tonic-gate
21267c478bd9Sstevel@tonic-gate case DEVCTL_PM_CHANGE_PWR_HIGH:
21277c478bd9Sstevel@tonic-gate /*
21287c478bd9Sstevel@tonic-gate * inform the PM framework that component 0 has changed
21297c478bd9Sstevel@tonic-gate * power level to MAXPWR via a pm_power_has_changed() call
21307c478bd9Sstevel@tonic-gate */
21317c478bd9Sstevel@tonic-gate if (pshot_debug) {
21327c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:"
21337c478bd9Sstevel@tonic-gate " DEVCTL_PM_CHANGE_PWR_HIGH\n", instance);
21347c478bd9Sstevel@tonic-gate }
21357c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
21367c478bd9Sstevel@tonic-gate pshot->level = MAXPWR;
21377c478bd9Sstevel@tonic-gate if (pm_power_has_changed(pshot->dip, 0, MAXPWR)
21387c478bd9Sstevel@tonic-gate != DDI_SUCCESS) {
21397c478bd9Sstevel@tonic-gate rv = EINVAL;
21407c478bd9Sstevel@tonic-gate } else {
21417c478bd9Sstevel@tonic-gate if (pshot_debug) {
21427c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:"
21437c478bd9Sstevel@tonic-gate " DEVCTL_PM_CHANGE_PWR_HIGH comp 0 to"
21447c478bd9Sstevel@tonic-gate " level %d\n", instance, pshot->level);
21457c478bd9Sstevel@tonic-gate }
21467c478bd9Sstevel@tonic-gate }
21477c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
21487c478bd9Sstevel@tonic-gate break;
21497c478bd9Sstevel@tonic-gate
21507c478bd9Sstevel@tonic-gate case DEVCTL_PM_POWER:
21517c478bd9Sstevel@tonic-gate /*
21527c478bd9Sstevel@tonic-gate * test if the pshot_power() routine has been called,
21537c478bd9Sstevel@tonic-gate * then clear
21547c478bd9Sstevel@tonic-gate */
21557c478bd9Sstevel@tonic-gate if (pshot_debug) {
21567c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:"
21577c478bd9Sstevel@tonic-gate " DEVCTL_PM_POWER\n", instance);
21587c478bd9Sstevel@tonic-gate }
21597c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
21607c478bd9Sstevel@tonic-gate state = (pshot->state & POWER_FLAG) ? 1 : 0;
21617c478bd9Sstevel@tonic-gate if (copyout(&state, dcp->cpyout_buf,
21627c478bd9Sstevel@tonic-gate sizeof (uint_t)) != 0) {
21637c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d devctl:"
21647c478bd9Sstevel@tonic-gate " DEVCTL_PM_POWER: copyout failed",
21657c478bd9Sstevel@tonic-gate instance);
21667c478bd9Sstevel@tonic-gate rv = EINVAL;
21677c478bd9Sstevel@tonic-gate }
21687c478bd9Sstevel@tonic-gate if (pshot_debug) {
21697c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DEVCTL_PM_POWER:"
21707c478bd9Sstevel@tonic-gate " POWER_FLAG = %d\n", instance, state);
21717c478bd9Sstevel@tonic-gate }
21727c478bd9Sstevel@tonic-gate pshot->state &= ~POWER_FLAG;
21737c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
21747c478bd9Sstevel@tonic-gate break;
21757c478bd9Sstevel@tonic-gate
21767c478bd9Sstevel@tonic-gate case DEVCTL_PM_FAIL_SUSPEND:
21777c478bd9Sstevel@tonic-gate /*
21787c478bd9Sstevel@tonic-gate * fail DDI_SUSPEND
21797c478bd9Sstevel@tonic-gate */
21807c478bd9Sstevel@tonic-gate if (pshot_debug) {
21817c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:"
21827c478bd9Sstevel@tonic-gate " DEVCTL_PM_FAIL_SUSPEND\n", instance);
21837c478bd9Sstevel@tonic-gate }
21847c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
21857c478bd9Sstevel@tonic-gate pshot->state |= FAIL_SUSPEND_FLAG;
21867c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
21877c478bd9Sstevel@tonic-gate if (pshot_debug) {
21887c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: DEVCTL_PM_FAIL_SUSPEND\n",
21897c478bd9Sstevel@tonic-gate instance);
21907c478bd9Sstevel@tonic-gate }
21917c478bd9Sstevel@tonic-gate break;
21927c478bd9Sstevel@tonic-gate
21937c478bd9Sstevel@tonic-gate case DEVCTL_PM_BUS_STRICT_TEST:
21947c478bd9Sstevel@tonic-gate /*
21957c478bd9Sstevel@tonic-gate * test the STRICT_PARENT flag:
21967c478bd9Sstevel@tonic-gate * set => STRICT PARENT
21977c478bd9Sstevel@tonic-gate * not set => INVOLVED PARENT
21987c478bd9Sstevel@tonic-gate */
21997c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
22007c478bd9Sstevel@tonic-gate state = (pshot->state & STRICT_PARENT) ? 1 : 0;
22017c478bd9Sstevel@tonic-gate if (copyout(&state, dcp->cpyout_buf,
22027c478bd9Sstevel@tonic-gate sizeof (uint_t)) != 0) {
22037c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d devctl:"
22047c478bd9Sstevel@tonic-gate " DEVCTL_PM_BUS_STRICT_TEST: copyout failed",
22057c478bd9Sstevel@tonic-gate instance);
22067c478bd9Sstevel@tonic-gate rv = EINVAL;
22077c478bd9Sstevel@tonic-gate }
22087c478bd9Sstevel@tonic-gate if (pshot_debug) {
22097c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:"
22107c478bd9Sstevel@tonic-gate " DEVCTL_PM_BUS_STRICT_TEST: type = %s\n",
22117c478bd9Sstevel@tonic-gate instance, ((state == 0) ? "INVOLVED" : "STRICT"));
22127c478bd9Sstevel@tonic-gate }
22137c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
22147c478bd9Sstevel@tonic-gate break;
22157c478bd9Sstevel@tonic-gate
22167c478bd9Sstevel@tonic-gate case DEVCTL_PM_BUS_NO_INVOL:
22177c478bd9Sstevel@tonic-gate /*
22187c478bd9Sstevel@tonic-gate * Set the NO_INVOL_FLAG flag to
22197c478bd9Sstevel@tonic-gate * notify the driver that the child will not
22207c478bd9Sstevel@tonic-gate * call pm_lower_power() on detach.
22217c478bd9Sstevel@tonic-gate * The driver needs to mark itself idle twice
22227c478bd9Sstevel@tonic-gate * during DDI_CTLOPS_DETACH (post).
22237c478bd9Sstevel@tonic-gate */
22247c478bd9Sstevel@tonic-gate if (pshot_debug) {
22257c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl:"
22267c478bd9Sstevel@tonic-gate " DEVCTL_PM_BUS_NO_INVOL\n", instance);
22277c478bd9Sstevel@tonic-gate }
22287c478bd9Sstevel@tonic-gate mutex_enter(&pshot->lock);
22297c478bd9Sstevel@tonic-gate pshot->state |= NO_INVOL_FLAG;
22307c478bd9Sstevel@tonic-gate mutex_exit(&pshot->lock);
22317c478bd9Sstevel@tonic-gate break;
22327c478bd9Sstevel@tonic-gate
22337c478bd9Sstevel@tonic-gate default:
22347c478bd9Sstevel@tonic-gate rv = ENOTTY;
22357c478bd9Sstevel@tonic-gate }
22367c478bd9Sstevel@tonic-gate
22377c478bd9Sstevel@tonic-gate ndi_dc_freehdl(dcp);
22387c478bd9Sstevel@tonic-gate return (rv);
22397c478bd9Sstevel@tonic-gate }
22407c478bd9Sstevel@tonic-gate
22417c478bd9Sstevel@tonic-gate
22427c478bd9Sstevel@tonic-gate /*
22437c478bd9Sstevel@tonic-gate * pshot_testctl: handle other test operations
22447c478bd9Sstevel@tonic-gate * - If <cmd> is a DEVCTL cmd, then <arg> is a dev_t indicating which
22457c478bd9Sstevel@tonic-gate * child to direct the DEVCTL to, if applicable;
22467c478bd9Sstevel@tonic-gate * furthermore, any cmd here can be sent by layered ioctls (unlike
22477c478bd9Sstevel@tonic-gate * those to pshot_devctl() which must come from userland)
22487c478bd9Sstevel@tonic-gate */
22497c478bd9Sstevel@tonic-gate /* ARGSUSED */
22507c478bd9Sstevel@tonic-gate static int
pshot_testctl(pshot_t * pshot,minor_t nodenum,int cmd,intptr_t arg,int mode,cred_t * credp,int * rvalp)22517c478bd9Sstevel@tonic-gate pshot_testctl(pshot_t *pshot, minor_t nodenum, int cmd, intptr_t arg, int mode,
22527c478bd9Sstevel@tonic-gate cred_t *credp, int *rvalp)
22537c478bd9Sstevel@tonic-gate {
22547c478bd9Sstevel@tonic-gate dev_info_t *self;
22557c478bd9Sstevel@tonic-gate dev_info_t *child = NULL;
22567c478bd9Sstevel@tonic-gate uint_t state;
22577c478bd9Sstevel@tonic-gate int rv = 0;
22587c478bd9Sstevel@tonic-gate int instance;
22597c478bd9Sstevel@tonic-gate int i;
22607c478bd9Sstevel@tonic-gate
22617c478bd9Sstevel@tonic-gate /* uint_t flags; */
22627c478bd9Sstevel@tonic-gate
22637c478bd9Sstevel@tonic-gate /* flags = (pshot_devctl_debug) ? NDI_DEVI_DEBUG : 0; */
22647c478bd9Sstevel@tonic-gate self = pshot->dip;
22657c478bd9Sstevel@tonic-gate instance = pshot->instance;
22667c478bd9Sstevel@tonic-gate
22677c478bd9Sstevel@tonic-gate if (cmd & DEVCTL_IOC) {
22687c478bd9Sstevel@tonic-gate child = e_ddi_hold_devi_by_dev((dev_t)arg, 0);
22697c478bd9Sstevel@tonic-gate }
22707c478bd9Sstevel@tonic-gate
22717c478bd9Sstevel@tonic-gate for (i = 0; pshot_devctls[i].ioctl_int != 0; i++) {
22727c478bd9Sstevel@tonic-gate if (pshot_devctls[i].ioctl_int == cmd) {
22737c478bd9Sstevel@tonic-gate if (pshot_debug)
22747c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d devctl: %s",
22757c478bd9Sstevel@tonic-gate instance, pshot_devctls[i].ioctl_char);
22767c478bd9Sstevel@tonic-gate }
22777c478bd9Sstevel@tonic-gate }
22787c478bd9Sstevel@tonic-gate switch (cmd) {
22797c478bd9Sstevel@tonic-gate case DEVCTL_DEVICE_RESET:
22807c478bd9Sstevel@tonic-gate if (pshot_debug)
22817c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d testctl:"
22827c478bd9Sstevel@tonic-gate " DEVCTL_PM_POWER\n", instance);
22837c478bd9Sstevel@tonic-gate rv = pshot_event(pshot, PSHOT_EVENT_TAG_DEV_RESET,
22847c478bd9Sstevel@tonic-gate child, (void *)self);
22857c478bd9Sstevel@tonic-gate ASSERT(rv == NDI_SUCCESS);
22867c478bd9Sstevel@tonic-gate break;
22877c478bd9Sstevel@tonic-gate
22887c478bd9Sstevel@tonic-gate case DEVCTL_BUS_QUIESCE:
22897c478bd9Sstevel@tonic-gate if (pshot_debug)
22907c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d testctl:"
22917c478bd9Sstevel@tonic-gate " DEVCTL_PM_POWER\n", instance);
22927c478bd9Sstevel@tonic-gate if (ndi_get_bus_state(self, &state) == NDI_SUCCESS) {
22937c478bd9Sstevel@tonic-gate if (state == BUS_QUIESCED) {
22947c478bd9Sstevel@tonic-gate break;
22957c478bd9Sstevel@tonic-gate }
22967c478bd9Sstevel@tonic-gate (void) ndi_set_bus_state(self, BUS_QUIESCED);
22977c478bd9Sstevel@tonic-gate }
22987c478bd9Sstevel@tonic-gate rv = pshot_event(pshot, PSHOT_EVENT_TAG_BUS_QUIESCE,
22997c478bd9Sstevel@tonic-gate child, (void *)self);
23007c478bd9Sstevel@tonic-gate ASSERT(rv == NDI_SUCCESS);
23017c478bd9Sstevel@tonic-gate
23027c478bd9Sstevel@tonic-gate break;
23037c478bd9Sstevel@tonic-gate
23047c478bd9Sstevel@tonic-gate case DEVCTL_BUS_UNQUIESCE:
23057c478bd9Sstevel@tonic-gate if (pshot_debug)
23067c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d testctl:"
23077c478bd9Sstevel@tonic-gate " DEVCTL_PM_POWER\n", instance);
23087c478bd9Sstevel@tonic-gate if (ndi_get_bus_state(self, &state) == NDI_SUCCESS) {
23097c478bd9Sstevel@tonic-gate if (state == BUS_ACTIVE) {
23107c478bd9Sstevel@tonic-gate break;
23117c478bd9Sstevel@tonic-gate }
23127c478bd9Sstevel@tonic-gate }
23137c478bd9Sstevel@tonic-gate
23147c478bd9Sstevel@tonic-gate /*
23157c478bd9Sstevel@tonic-gate * quiesce the bus through bus-specific means
23167c478bd9Sstevel@tonic-gate */
23177c478bd9Sstevel@tonic-gate (void) ndi_set_bus_state(self, BUS_ACTIVE);
23187c478bd9Sstevel@tonic-gate rv = pshot_event(pshot, PSHOT_EVENT_TAG_BUS_UNQUIESCE,
23197c478bd9Sstevel@tonic-gate child, (void *)self);
23207c478bd9Sstevel@tonic-gate ASSERT(rv == NDI_SUCCESS);
23217c478bd9Sstevel@tonic-gate break;
23227c478bd9Sstevel@tonic-gate
23237c478bd9Sstevel@tonic-gate case DEVCTL_BUS_RESET:
23247c478bd9Sstevel@tonic-gate case DEVCTL_BUS_RESETALL:
23257c478bd9Sstevel@tonic-gate /*
23267c478bd9Sstevel@tonic-gate * no reset support for the pseudo bus
23277c478bd9Sstevel@tonic-gate * but if there were....
23287c478bd9Sstevel@tonic-gate */
23297c478bd9Sstevel@tonic-gate rv = pshot_event(pshot, PSHOT_EVENT_TAG_BUS_RESET,
23307c478bd9Sstevel@tonic-gate child, (void *)self);
23317c478bd9Sstevel@tonic-gate ASSERT(rv == NDI_SUCCESS);
23327c478bd9Sstevel@tonic-gate break;
23337c478bd9Sstevel@tonic-gate
23347c478bd9Sstevel@tonic-gate default:
23357c478bd9Sstevel@tonic-gate rv = ENOTTY;
23367c478bd9Sstevel@tonic-gate }
23377c478bd9Sstevel@tonic-gate
23387c478bd9Sstevel@tonic-gate if (child != NULL)
23397c478bd9Sstevel@tonic-gate ddi_release_devi(child);
23407c478bd9Sstevel@tonic-gate return (rv);
23417c478bd9Sstevel@tonic-gate }
23427c478bd9Sstevel@tonic-gate
23437c478bd9Sstevel@tonic-gate
23447c478bd9Sstevel@tonic-gate static int
pshot_get_eventcookie(dev_info_t * dip,dev_info_t * rdip,char * eventname,ddi_eventcookie_t * event_cookiep)23457c478bd9Sstevel@tonic-gate pshot_get_eventcookie(dev_info_t *dip, dev_info_t *rdip,
23467c478bd9Sstevel@tonic-gate char *eventname, ddi_eventcookie_t *event_cookiep)
23477c478bd9Sstevel@tonic-gate {
23487c478bd9Sstevel@tonic-gate int instance = ddi_get_instance(dip);
23497c478bd9Sstevel@tonic-gate pshot_t *pshot = ddi_get_soft_state(pshot_softstatep, instance);
23507c478bd9Sstevel@tonic-gate
23517c478bd9Sstevel@tonic-gate if (pshot_debug)
23527c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: "
23537c478bd9Sstevel@tonic-gate "pshot_get_eventcookie:\n\t"
23547c478bd9Sstevel@tonic-gate "dip = 0x%p rdip = 0x%p (%s/%d) eventname = %s\n",
23557c478bd9Sstevel@tonic-gate instance, (void *)dip, (void *)rdip,
23567c478bd9Sstevel@tonic-gate ddi_node_name(rdip), ddi_get_instance(rdip),
23577c478bd9Sstevel@tonic-gate eventname);
23587c478bd9Sstevel@tonic-gate
23597c478bd9Sstevel@tonic-gate
23607c478bd9Sstevel@tonic-gate return (ndi_event_retrieve_cookie(pshot->ndi_event_hdl,
23617c478bd9Sstevel@tonic-gate rdip, eventname, event_cookiep, NDI_EVENT_NOPASS));
23627c478bd9Sstevel@tonic-gate }
23637c478bd9Sstevel@tonic-gate
23647c478bd9Sstevel@tonic-gate static int
pshot_add_eventcall(dev_info_t * dip,dev_info_t * rdip,ddi_eventcookie_t cookie,void (* callback)(),void * arg,ddi_callback_id_t * cb_id)23657c478bd9Sstevel@tonic-gate pshot_add_eventcall(dev_info_t *dip, dev_info_t *rdip,
23667c478bd9Sstevel@tonic-gate ddi_eventcookie_t cookie,
23677c478bd9Sstevel@tonic-gate void (*callback)(), void *arg, ddi_callback_id_t *cb_id)
23687c478bd9Sstevel@tonic-gate {
23697c478bd9Sstevel@tonic-gate int instance = ddi_get_instance(dip);
23707c478bd9Sstevel@tonic-gate pshot_t *pshot = ddi_get_soft_state(pshot_softstatep, instance);
23717c478bd9Sstevel@tonic-gate
23727c478bd9Sstevel@tonic-gate if (pshot_debug)
23737c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: "
23747c478bd9Sstevel@tonic-gate "pshot_add_eventcall:\n\t"
23757c478bd9Sstevel@tonic-gate "dip = 0x%p rdip = 0x%p (%s%d)\n\tcookie = 0x%p (%s)\n\t"
23767c478bd9Sstevel@tonic-gate "cb = 0x%p, arg = 0x%p\n",
23777c478bd9Sstevel@tonic-gate instance, (void *)dip, (void *)rdip,
23787c478bd9Sstevel@tonic-gate ddi_node_name(rdip), ddi_get_instance(rdip), (void *)cookie,
23797c478bd9Sstevel@tonic-gate NDI_EVENT_NAME(cookie), (void *)callback, arg);
23807c478bd9Sstevel@tonic-gate
23817c478bd9Sstevel@tonic-gate /* add callback to our event handle */
23827c478bd9Sstevel@tonic-gate return (ndi_event_add_callback(pshot->ndi_event_hdl, rdip,
23837c478bd9Sstevel@tonic-gate cookie, callback, arg, NDI_SLEEP, cb_id));
23847c478bd9Sstevel@tonic-gate }
23857c478bd9Sstevel@tonic-gate
23867c478bd9Sstevel@tonic-gate static int
pshot_remove_eventcall(dev_info_t * dip,ddi_callback_id_t cb_id)23877c478bd9Sstevel@tonic-gate pshot_remove_eventcall(dev_info_t *dip, ddi_callback_id_t cb_id)
23887c478bd9Sstevel@tonic-gate {
23897c478bd9Sstevel@tonic-gate
23907c478bd9Sstevel@tonic-gate ndi_event_callbacks_t *cb = (ndi_event_callbacks_t *)cb_id;
23917c478bd9Sstevel@tonic-gate
23927c478bd9Sstevel@tonic-gate int instance = ddi_get_instance(dip);
23937c478bd9Sstevel@tonic-gate pshot_t *pshot = ddi_get_soft_state(pshot_softstatep, instance);
23947c478bd9Sstevel@tonic-gate
23957c478bd9Sstevel@tonic-gate ASSERT(cb);
23967c478bd9Sstevel@tonic-gate
23977c478bd9Sstevel@tonic-gate if (pshot_debug)
23987c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: "
23997c478bd9Sstevel@tonic-gate "pshot_remove_eventcall:\n\t"
24007c478bd9Sstevel@tonic-gate "dip = 0x%p rdip = 0x%p (%s%d)\n\tcookie = 0x%p (%s)\n",
24017c478bd9Sstevel@tonic-gate instance, (void *)dip, (void *)cb->ndi_evtcb_dip,
24027c478bd9Sstevel@tonic-gate ddi_node_name(cb->ndi_evtcb_dip),
240319397407SSherry Moore ddi_get_instance(cb->ndi_evtcb_dip),
240419397407SSherry Moore (void *)cb->ndi_evtcb_cookie,
24057c478bd9Sstevel@tonic-gate NDI_EVENT_NAME(cb->ndi_evtcb_cookie));
24067c478bd9Sstevel@tonic-gate
24077c478bd9Sstevel@tonic-gate return (ndi_event_remove_callback(pshot->ndi_event_hdl, cb_id));
24087c478bd9Sstevel@tonic-gate }
24097c478bd9Sstevel@tonic-gate
24107c478bd9Sstevel@tonic-gate static int
pshot_post_event(dev_info_t * dip,dev_info_t * rdip,ddi_eventcookie_t cookie,void * impl_data)24117c478bd9Sstevel@tonic-gate pshot_post_event(dev_info_t *dip, dev_info_t *rdip,
24127c478bd9Sstevel@tonic-gate ddi_eventcookie_t cookie, void *impl_data)
24137c478bd9Sstevel@tonic-gate {
24147c478bd9Sstevel@tonic-gate int instance = ddi_get_instance(dip);
24157c478bd9Sstevel@tonic-gate pshot_t *pshot = ddi_get_soft_state(pshot_softstatep, instance);
24167c478bd9Sstevel@tonic-gate
24177c478bd9Sstevel@tonic-gate if (pshot_debug) {
24187c478bd9Sstevel@tonic-gate if (rdip) {
24197c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: "
24207c478bd9Sstevel@tonic-gate "pshot_post_event:\n\t"
24217c478bd9Sstevel@tonic-gate "dip = 0x%p rdip = 0x%p (%s%d\n\t"
24227c478bd9Sstevel@tonic-gate "cookie = 0x%p (%s)\n\tbus_impl = 0x%p\n",
24237c478bd9Sstevel@tonic-gate instance, (void *)dip, (void *)rdip,
242419397407SSherry Moore ddi_node_name(rdip), ddi_get_instance(rdip),
242519397407SSherry Moore (void *)cookie,
24267c478bd9Sstevel@tonic-gate NDI_EVENT_NAME(cookie), impl_data);
24277c478bd9Sstevel@tonic-gate } else {
24287c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: "
24297c478bd9Sstevel@tonic-gate "pshot_post_event:\n\t"
24307c478bd9Sstevel@tonic-gate "dip = 0x%p cookie = 0x%p (%s) bus_impl = 0x%p\n",
24317c478bd9Sstevel@tonic-gate instance, (void *)dip, (void *)cookie,
24327c478bd9Sstevel@tonic-gate NDI_EVENT_NAME(cookie), impl_data);
24337c478bd9Sstevel@tonic-gate }
24347c478bd9Sstevel@tonic-gate }
24357c478bd9Sstevel@tonic-gate
24367c478bd9Sstevel@tonic-gate /* run callbacks for this event */
24377c478bd9Sstevel@tonic-gate return (ndi_event_run_callbacks(pshot->ndi_event_hdl, rdip,
24387c478bd9Sstevel@tonic-gate cookie, impl_data));
24397c478bd9Sstevel@tonic-gate }
24407c478bd9Sstevel@tonic-gate
24417c478bd9Sstevel@tonic-gate /*
24427c478bd9Sstevel@tonic-gate * the nexus driver will generate events
24437c478bd9Sstevel@tonic-gate * that need to go to children
24447c478bd9Sstevel@tonic-gate */
24457c478bd9Sstevel@tonic-gate static int
pshot_event(pshot_t * pshot,int event_tag,dev_info_t * child,void * bus_impldata)24467c478bd9Sstevel@tonic-gate pshot_event(pshot_t *pshot, int event_tag, dev_info_t *child,
24477c478bd9Sstevel@tonic-gate void *bus_impldata)
24487c478bd9Sstevel@tonic-gate {
24497c478bd9Sstevel@tonic-gate ddi_eventcookie_t cookie = ndi_event_tag_to_cookie(
24507c478bd9Sstevel@tonic-gate pshot->ndi_event_hdl, event_tag);
24517c478bd9Sstevel@tonic-gate
24527c478bd9Sstevel@tonic-gate if (pshot_debug) {
24537c478bd9Sstevel@tonic-gate if (child) {
24547c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: "
24557c478bd9Sstevel@tonic-gate "pshot_event: event_tag = 0x%x (%s)\n\t"
24567c478bd9Sstevel@tonic-gate "child = 0x%p (%s%d) bus_impl = 0x%p (%s%d)\n",
24577c478bd9Sstevel@tonic-gate pshot->instance, event_tag,
245819397407SSherry Moore ndi_event_tag_to_name(pshot->ndi_event_hdl,
245919397407SSherry Moore event_tag),
24607c478bd9Sstevel@tonic-gate (void *)child, ddi_node_name(child),
24617c478bd9Sstevel@tonic-gate ddi_get_instance(child), bus_impldata,
24627c478bd9Sstevel@tonic-gate ddi_node_name((dev_info_t *)bus_impldata),
24637c478bd9Sstevel@tonic-gate ddi_get_instance((dev_info_t *)bus_impldata));
24647c478bd9Sstevel@tonic-gate } else {
24657c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: "
24667c478bd9Sstevel@tonic-gate "pshot_event: event_tag = 0x%x (%s)\n\t"
24677c478bd9Sstevel@tonic-gate "child = NULL, bus_impl = 0x%p (%s%d)\n",
24687c478bd9Sstevel@tonic-gate pshot->instance, event_tag,
246919397407SSherry Moore ndi_event_tag_to_name(pshot->ndi_event_hdl,
247019397407SSherry Moore event_tag),
24717c478bd9Sstevel@tonic-gate bus_impldata,
24727c478bd9Sstevel@tonic-gate ddi_node_name((dev_info_t *)bus_impldata),
24737c478bd9Sstevel@tonic-gate ddi_get_instance((dev_info_t *)bus_impldata));
24747c478bd9Sstevel@tonic-gate }
24757c478bd9Sstevel@tonic-gate }
24767c478bd9Sstevel@tonic-gate
24777c478bd9Sstevel@tonic-gate return (ndi_event_run_callbacks(pshot->ndi_event_hdl,
24787c478bd9Sstevel@tonic-gate child, cookie, bus_impldata));
24797c478bd9Sstevel@tonic-gate }
24807c478bd9Sstevel@tonic-gate
24817c478bd9Sstevel@tonic-gate
24827c478bd9Sstevel@tonic-gate /*
24837c478bd9Sstevel@tonic-gate * the pshot driver event notification callback
24847c478bd9Sstevel@tonic-gate */
24857c478bd9Sstevel@tonic-gate static void
pshot_event_cb(dev_info_t * dip,ddi_eventcookie_t cookie,void * arg,void * bus_impldata)24867c478bd9Sstevel@tonic-gate pshot_event_cb(dev_info_t *dip, ddi_eventcookie_t cookie,
24877c478bd9Sstevel@tonic-gate void *arg, void *bus_impldata)
24887c478bd9Sstevel@tonic-gate {
24897c478bd9Sstevel@tonic-gate pshot_t *pshot = (pshot_t *)arg;
24907c478bd9Sstevel@tonic-gate int event_tag;
24917c478bd9Sstevel@tonic-gate
24927c478bd9Sstevel@tonic-gate /* look up the event */
24937c478bd9Sstevel@tonic-gate event_tag = NDI_EVENT_TAG(cookie);
24947c478bd9Sstevel@tonic-gate
24957c478bd9Sstevel@tonic-gate if (pshot_debug) {
24967c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: "
24977c478bd9Sstevel@tonic-gate "pshot_event_cb:\n\t"
24987c478bd9Sstevel@tonic-gate "dip = 0x%p cookie = 0x%p (%s), tag = 0x%x\n\t"
24997c478bd9Sstevel@tonic-gate "arg = 0x%p bus_impl = 0x%p (%s%d)\n",
25007c478bd9Sstevel@tonic-gate pshot->instance, (void *)dip, (void *)cookie,
25017c478bd9Sstevel@tonic-gate NDI_EVENT_NAME(cookie), event_tag, arg, bus_impldata,
25027c478bd9Sstevel@tonic-gate ddi_node_name((dev_info_t *)bus_impldata),
25037c478bd9Sstevel@tonic-gate ddi_get_instance((dev_info_t *)bus_impldata));
25047c478bd9Sstevel@tonic-gate }
25057c478bd9Sstevel@tonic-gate
25067c478bd9Sstevel@tonic-gate switch (event_tag) {
25077c478bd9Sstevel@tonic-gate case PSHOT_EVENT_TAG_OFFLINE:
25087c478bd9Sstevel@tonic-gate case PSHOT_EVENT_TAG_BUS_RESET:
25097c478bd9Sstevel@tonic-gate case PSHOT_EVENT_TAG_BUS_QUIESCE:
25107c478bd9Sstevel@tonic-gate case PSHOT_EVENT_TAG_BUS_UNQUIESCE:
25117c478bd9Sstevel@tonic-gate /* notify all subscribers of the this event */
25127c478bd9Sstevel@tonic-gate (void) ndi_event_run_callbacks(pshot->ndi_event_hdl,
25137c478bd9Sstevel@tonic-gate NULL, cookie, bus_impldata);
25147c478bd9Sstevel@tonic-gate if (pshot_debug) {
25157c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: event=%s\n\t"
25167c478bd9Sstevel@tonic-gate "pshot_event_cb\n", pshot->instance,
25177c478bd9Sstevel@tonic-gate NDI_EVENT_NAME(cookie));
25187c478bd9Sstevel@tonic-gate }
25197c478bd9Sstevel@tonic-gate /*FALLTHRU*/
25207c478bd9Sstevel@tonic-gate case PSHOT_EVENT_TAG_TEST_POST:
25217c478bd9Sstevel@tonic-gate case PSHOT_EVENT_TAG_DEV_RESET:
25227c478bd9Sstevel@tonic-gate default:
25237c478bd9Sstevel@tonic-gate return;
25247c478bd9Sstevel@tonic-gate }
25257c478bd9Sstevel@tonic-gate }
25267c478bd9Sstevel@tonic-gate
25277c478bd9Sstevel@tonic-gate static int
pshot_bus_config(dev_info_t * parent,uint_t flags,ddi_bus_config_op_t op,void * arg,dev_info_t ** childp)25287c478bd9Sstevel@tonic-gate pshot_bus_config(dev_info_t *parent, uint_t flags,
25297c478bd9Sstevel@tonic-gate ddi_bus_config_op_t op, void *arg, dev_info_t **childp)
25307c478bd9Sstevel@tonic-gate {
25317c478bd9Sstevel@tonic-gate int rval;
25327c478bd9Sstevel@tonic-gate char *devname;
25337c478bd9Sstevel@tonic-gate char *devstr, *cname, *caddr;
25347c478bd9Sstevel@tonic-gate int devstrlen;
25357c478bd9Sstevel@tonic-gate int circ;
25367c478bd9Sstevel@tonic-gate pshot_t *pshot;
25377c478bd9Sstevel@tonic-gate int instance = ddi_get_instance(parent);
25387c478bd9Sstevel@tonic-gate
25397c478bd9Sstevel@tonic-gate if (pshot_debug) {
25407c478bd9Sstevel@tonic-gate flags |= NDI_DEVI_DEBUG;
25417c478bd9Sstevel@tonic-gate cmn_err(CE_CONT,
25427c478bd9Sstevel@tonic-gate "pshot%d: bus_config %s flags=0x%x\n",
25437c478bd9Sstevel@tonic-gate ddi_get_instance(parent),
25447c478bd9Sstevel@tonic-gate (op == BUS_CONFIG_ONE) ? (char *)arg : "", flags);
25457c478bd9Sstevel@tonic-gate }
25467c478bd9Sstevel@tonic-gate
25477c478bd9Sstevel@tonic-gate pshot = ddi_get_soft_state(pshot_softstatep, instance);
25487c478bd9Sstevel@tonic-gate if (pshot == NULL) {
25497c478bd9Sstevel@tonic-gate
25507c478bd9Sstevel@tonic-gate return (NDI_FAILURE);
25517c478bd9Sstevel@tonic-gate }
25527c478bd9Sstevel@tonic-gate
25537c478bd9Sstevel@tonic-gate /*
25547c478bd9Sstevel@tonic-gate * Hold the nexus across the bus_config
25557c478bd9Sstevel@tonic-gate */
25567c478bd9Sstevel@tonic-gate ndi_devi_enter(parent, &circ);
25577c478bd9Sstevel@tonic-gate
25587c478bd9Sstevel@tonic-gate switch (op) {
25597c478bd9Sstevel@tonic-gate case BUS_CONFIG_ONE:
25607c478bd9Sstevel@tonic-gate
25617c478bd9Sstevel@tonic-gate /*
25627c478bd9Sstevel@tonic-gate * lookup and hold child device, create if not found
25637c478bd9Sstevel@tonic-gate */
25647c478bd9Sstevel@tonic-gate devname = (char *)arg;
25657c478bd9Sstevel@tonic-gate devstrlen = strlen(devname) + 1;
25667c478bd9Sstevel@tonic-gate devstr = i_ddi_strdup(devname, KM_SLEEP);
25677c478bd9Sstevel@tonic-gate i_ddi_parse_name(devstr, &cname, &caddr, NULL);
25687c478bd9Sstevel@tonic-gate
25697c478bd9Sstevel@tonic-gate /*
25707c478bd9Sstevel@tonic-gate * The framework ensures that the node has
25717c478bd9Sstevel@tonic-gate * a name but each nexus is responsible for
25727c478bd9Sstevel@tonic-gate * the bus address name space. This driver
25737c478bd9Sstevel@tonic-gate * requires that a bus address be specified,
25747c478bd9Sstevel@tonic-gate * as will most nexus drivers.
25757c478bd9Sstevel@tonic-gate */
25767c478bd9Sstevel@tonic-gate ASSERT(cname && strlen(cname) > 0);
25777c478bd9Sstevel@tonic-gate if (caddr == NULL || strlen(caddr) == 0) {
25787c478bd9Sstevel@tonic-gate cmn_err(CE_WARN,
25797c478bd9Sstevel@tonic-gate "pshot%d: malformed name %s (no bus address)",
25807c478bd9Sstevel@tonic-gate ddi_get_instance(parent), devname);
25817c478bd9Sstevel@tonic-gate kmem_free(devstr, devstrlen);
25827c478bd9Sstevel@tonic-gate ndi_devi_exit(parent, circ);
25837c478bd9Sstevel@tonic-gate return (NDI_FAILURE);
25847c478bd9Sstevel@tonic-gate }
25857c478bd9Sstevel@tonic-gate
25867c478bd9Sstevel@tonic-gate /*
25877c478bd9Sstevel@tonic-gate * Handle a few special cases for testing purposes
25887c478bd9Sstevel@tonic-gate */
25897c478bd9Sstevel@tonic-gate rval = pshot_bus_config_test_specials(parent,
25907c478bd9Sstevel@tonic-gate devname, cname, caddr);
25917c478bd9Sstevel@tonic-gate
25927c478bd9Sstevel@tonic-gate if (rval == NDI_SUCCESS) {
25937c478bd9Sstevel@tonic-gate /*
25947c478bd9Sstevel@tonic-gate * Set up either a leaf or nexus device
25957c478bd9Sstevel@tonic-gate */
25967c478bd9Sstevel@tonic-gate if (strcmp(cname, "pshot") == 0) {
25977c478bd9Sstevel@tonic-gate rval = pshot_bus_config_setup_nexus(parent,
25987c478bd9Sstevel@tonic-gate cname, caddr);
25997c478bd9Sstevel@tonic-gate } else {
26007c478bd9Sstevel@tonic-gate rval = pshot_bus_config_setup_leaf(parent,
26017c478bd9Sstevel@tonic-gate cname, caddr);
26027c478bd9Sstevel@tonic-gate }
26037c478bd9Sstevel@tonic-gate }
26047c478bd9Sstevel@tonic-gate
26057c478bd9Sstevel@tonic-gate kmem_free(devstr, devstrlen);
26067c478bd9Sstevel@tonic-gate break;
26077c478bd9Sstevel@tonic-gate
26087c478bd9Sstevel@tonic-gate case BUS_CONFIG_DRIVER:
26097c478bd9Sstevel@tonic-gate case BUS_CONFIG_ALL:
26107c478bd9Sstevel@tonic-gate rval = NDI_SUCCESS;
26117c478bd9Sstevel@tonic-gate break;
26127c478bd9Sstevel@tonic-gate
26137c478bd9Sstevel@tonic-gate default:
26147c478bd9Sstevel@tonic-gate rval = NDI_FAILURE;
26157c478bd9Sstevel@tonic-gate break;
26167c478bd9Sstevel@tonic-gate }
26177c478bd9Sstevel@tonic-gate
26187c478bd9Sstevel@tonic-gate if (rval == NDI_SUCCESS)
26197c478bd9Sstevel@tonic-gate rval = ndi_busop_bus_config(parent, flags, op, arg, childp, 0);
26207c478bd9Sstevel@tonic-gate
26217c478bd9Sstevel@tonic-gate ndi_devi_exit(parent, circ);
26227c478bd9Sstevel@tonic-gate
26237c478bd9Sstevel@tonic-gate if (pshot_debug)
26247c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: bus_config %s\n",
26257c478bd9Sstevel@tonic-gate ddi_get_instance(parent),
26267c478bd9Sstevel@tonic-gate (rval == NDI_SUCCESS) ? "ok" : "failed");
26277c478bd9Sstevel@tonic-gate
26287c478bd9Sstevel@tonic-gate return (rval);
26297c478bd9Sstevel@tonic-gate }
26307c478bd9Sstevel@tonic-gate
26317c478bd9Sstevel@tonic-gate static int
pshot_bus_unconfig(dev_info_t * parent,uint_t flags,ddi_bus_config_op_t op,void * arg)26327c478bd9Sstevel@tonic-gate pshot_bus_unconfig(dev_info_t *parent, uint_t flags,
26337c478bd9Sstevel@tonic-gate ddi_bus_config_op_t op, void *arg)
26347c478bd9Sstevel@tonic-gate {
26357c478bd9Sstevel@tonic-gate major_t major;
26367c478bd9Sstevel@tonic-gate int rval = NDI_SUCCESS;
26377c478bd9Sstevel@tonic-gate int circ;
26387c478bd9Sstevel@tonic-gate
26397c478bd9Sstevel@tonic-gate if (pshot_debug) {
26407c478bd9Sstevel@tonic-gate flags |= NDI_DEVI_DEBUG;
26417c478bd9Sstevel@tonic-gate cmn_err(CE_CONT,
26427c478bd9Sstevel@tonic-gate "pshot%d: bus_unconfig %s flags=0x%x\n",
26437c478bd9Sstevel@tonic-gate ddi_get_instance(parent),
26447c478bd9Sstevel@tonic-gate (op == BUS_UNCONFIG_ONE) ? (char *)arg : "", flags);
26457c478bd9Sstevel@tonic-gate }
26467c478bd9Sstevel@tonic-gate
26477c478bd9Sstevel@tonic-gate /*
26487c478bd9Sstevel@tonic-gate * Hold the nexus across the bus_unconfig
26497c478bd9Sstevel@tonic-gate */
26507c478bd9Sstevel@tonic-gate ndi_devi_enter(parent, &circ);
26517c478bd9Sstevel@tonic-gate
26527c478bd9Sstevel@tonic-gate switch (op) {
26537c478bd9Sstevel@tonic-gate case BUS_UNCONFIG_ONE:
26547c478bd9Sstevel@tonic-gate /*
26557c478bd9Sstevel@tonic-gate * Nothing special required here
26567c478bd9Sstevel@tonic-gate */
26577c478bd9Sstevel@tonic-gate if (pshot_debug) {
26587c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: bus_unconfig:"
26597c478bd9Sstevel@tonic-gate " BUS_UNCONFIG_ONE\n", ddi_get_instance(parent));
26607c478bd9Sstevel@tonic-gate }
26617c478bd9Sstevel@tonic-gate break;
26627c478bd9Sstevel@tonic-gate
26637c478bd9Sstevel@tonic-gate case BUS_UNCONFIG_DRIVER:
26647c478bd9Sstevel@tonic-gate if (pshot_debug > 0) {
26657c478bd9Sstevel@tonic-gate major = (major_t)(uintptr_t)arg;
26667c478bd9Sstevel@tonic-gate cmn_err(CE_CONT,
26677c478bd9Sstevel@tonic-gate "pshot%d: BUS_UNCONFIG_DRIVER: %s\n",
26687c478bd9Sstevel@tonic-gate ddi_get_instance(parent),
26697c478bd9Sstevel@tonic-gate ddi_major_to_name(major));
26707c478bd9Sstevel@tonic-gate }
26717c478bd9Sstevel@tonic-gate break;
26727c478bd9Sstevel@tonic-gate
26737c478bd9Sstevel@tonic-gate case BUS_UNCONFIG_ALL:
26747c478bd9Sstevel@tonic-gate if (pshot_debug) {
26757c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: bus_unconfig:"
26767c478bd9Sstevel@tonic-gate " BUS_UNCONFIG_ALL\n", ddi_get_instance(parent));
26777c478bd9Sstevel@tonic-gate }
26787c478bd9Sstevel@tonic-gate break;
26797c478bd9Sstevel@tonic-gate
26807c478bd9Sstevel@tonic-gate default:
26817c478bd9Sstevel@tonic-gate if (pshot_debug) {
26827c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: bus_unconfig: DEFAULT\n",
26837c478bd9Sstevel@tonic-gate ddi_get_instance(parent));
26847c478bd9Sstevel@tonic-gate }
26857c478bd9Sstevel@tonic-gate rval = NDI_FAILURE;
26867c478bd9Sstevel@tonic-gate }
26877c478bd9Sstevel@tonic-gate
26887c478bd9Sstevel@tonic-gate if (rval == NDI_SUCCESS)
26897c478bd9Sstevel@tonic-gate rval = ndi_busop_bus_unconfig(parent, flags, op, arg);
26907c478bd9Sstevel@tonic-gate
26917c478bd9Sstevel@tonic-gate ndi_devi_exit(parent, circ);
26927c478bd9Sstevel@tonic-gate
26937c478bd9Sstevel@tonic-gate if (pshot_debug)
26947c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: bus_unconfig %s\n",
26957c478bd9Sstevel@tonic-gate ddi_get_instance(parent),
26967c478bd9Sstevel@tonic-gate (rval == NDI_SUCCESS) ? "ok" : "failed");
26977c478bd9Sstevel@tonic-gate
26987c478bd9Sstevel@tonic-gate return (rval);
26997c478bd9Sstevel@tonic-gate }
27007c478bd9Sstevel@tonic-gate
27017c478bd9Sstevel@tonic-gate static dev_info_t *
pshot_findchild(dev_info_t * pdip,char * cname,char * caddr)27027c478bd9Sstevel@tonic-gate pshot_findchild(dev_info_t *pdip, char *cname, char *caddr)
27037c478bd9Sstevel@tonic-gate {
27047c478bd9Sstevel@tonic-gate dev_info_t *dip;
27057c478bd9Sstevel@tonic-gate char *addr;
27067c478bd9Sstevel@tonic-gate
27077c478bd9Sstevel@tonic-gate ASSERT(cname != NULL && caddr != NULL);
27087c478bd9Sstevel@tonic-gate ASSERT(DEVI_BUSY_OWNED(pdip));
27097c478bd9Sstevel@tonic-gate
27107c478bd9Sstevel@tonic-gate for (dip = ddi_get_child(pdip); dip != NULL;
27117c478bd9Sstevel@tonic-gate dip = ddi_get_next_sibling(dip)) {
27127c478bd9Sstevel@tonic-gate if (strcmp(cname, ddi_node_name(dip)) != 0)
27137c478bd9Sstevel@tonic-gate continue;
27147c478bd9Sstevel@tonic-gate
27157c478bd9Sstevel@tonic-gate if ((addr = ddi_get_name_addr(dip)) == NULL) {
27167c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string(DDI_DEV_T_ANY, dip, 0,
27177c478bd9Sstevel@tonic-gate "bus-addr", &addr) == DDI_PROP_SUCCESS) {
27187c478bd9Sstevel@tonic-gate if (strcmp(caddr, addr) == 0) {
27197c478bd9Sstevel@tonic-gate ddi_prop_free(addr);
27207c478bd9Sstevel@tonic-gate return (dip);
27217c478bd9Sstevel@tonic-gate }
27227c478bd9Sstevel@tonic-gate ddi_prop_free(addr);
27237c478bd9Sstevel@tonic-gate }
27247c478bd9Sstevel@tonic-gate } else {
27257c478bd9Sstevel@tonic-gate if (strcmp(caddr, addr) == 0)
27267c478bd9Sstevel@tonic-gate return (dip);
27277c478bd9Sstevel@tonic-gate }
27287c478bd9Sstevel@tonic-gate }
27297c478bd9Sstevel@tonic-gate
27307c478bd9Sstevel@tonic-gate return (NULL);
27317c478bd9Sstevel@tonic-gate }
27327c478bd9Sstevel@tonic-gate
27337c478bd9Sstevel@tonic-gate static void
pshot_nexus_properties(dev_info_t * parent,dev_info_t * child,char * cname,char * caddr)27347c478bd9Sstevel@tonic-gate pshot_nexus_properties(dev_info_t *parent, dev_info_t *child, char *cname,
27357c478bd9Sstevel@tonic-gate char *caddr)
27367c478bd9Sstevel@tonic-gate {
27377c478bd9Sstevel@tonic-gate char *extension;
27387c478bd9Sstevel@tonic-gate
27397c478bd9Sstevel@tonic-gate /*
2740b1dd958fScth * extract the address extension
27417c478bd9Sstevel@tonic-gate */
27427c478bd9Sstevel@tonic-gate extension = strstr(caddr, ",");
27437c478bd9Sstevel@tonic-gate if (extension != NULL) {
27447c478bd9Sstevel@tonic-gate ++extension;
27457c478bd9Sstevel@tonic-gate } else {
27467c478bd9Sstevel@tonic-gate extension = "null";
27477c478bd9Sstevel@tonic-gate }
27487c478bd9Sstevel@tonic-gate
27497c478bd9Sstevel@tonic-gate /*
27507c478bd9Sstevel@tonic-gate * Create the "pm-want-child-notification?" property for all
27517c478bd9Sstevel@tonic-gate * nodes that do not have the "pm_strict" or "nopm_strict"
27527c478bd9Sstevel@tonic-gate * extension
27537c478bd9Sstevel@tonic-gate */
27547c478bd9Sstevel@tonic-gate if (strcmp(extension, "pm_strict") != 0 &&
27557c478bd9Sstevel@tonic-gate strcmp(extension, "nopm_strict") != 0) {
27567c478bd9Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, child,
27577c478bd9Sstevel@tonic-gate (DDI_PROP_DONTPASS | DDI_PROP_NOTPROM),
27587c478bd9Sstevel@tonic-gate "pm-want-child-notification?") == 0) {
27597c478bd9Sstevel@tonic-gate if (pshot_debug) {
27607c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:"
27617c478bd9Sstevel@tonic-gate " nexus_properties:\n\tcreate the"
27627c478bd9Sstevel@tonic-gate " \"pm-want-child-notification?\""
27637c478bd9Sstevel@tonic-gate " property for %s@%s\n",
27647c478bd9Sstevel@tonic-gate ddi_get_instance(parent), cname, caddr);
27657c478bd9Sstevel@tonic-gate }
27667c478bd9Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, child, 0,
27677c478bd9Sstevel@tonic-gate "pm-want-child-notification?", NULL, 0)
27687c478bd9Sstevel@tonic-gate != DDI_PROP_SUCCESS) {
27697c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d:"
27707c478bd9Sstevel@tonic-gate " nexus_properties:\n\tunable to create"
27717c478bd9Sstevel@tonic-gate " the \"pm-want-child-notification?\""
27727c478bd9Sstevel@tonic-gate " property for %s@%s",
27737c478bd9Sstevel@tonic-gate ddi_get_instance(parent), cname, caddr);
27747c478bd9Sstevel@tonic-gate }
27757c478bd9Sstevel@tonic-gate }
27767c478bd9Sstevel@tonic-gate }
27777c478bd9Sstevel@tonic-gate
27787c478bd9Sstevel@tonic-gate /*
27797c478bd9Sstevel@tonic-gate * Create the "no-pm-components" property for all nodes
27807c478bd9Sstevel@tonic-gate * with extension "nopm" or "nopm_strict"
27817c478bd9Sstevel@tonic-gate */
27827c478bd9Sstevel@tonic-gate if (strcmp(extension, "nopm") == 0 ||
27837c478bd9Sstevel@tonic-gate strcmp(extension, "nopm_strict") == 0) {
27847c478bd9Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, child,
27857c478bd9Sstevel@tonic-gate (DDI_PROP_DONTPASS | DDI_PROP_NOTPROM),
27867c478bd9Sstevel@tonic-gate "no-pm-components") == 0) {
27877c478bd9Sstevel@tonic-gate if (pshot_debug) {
27887c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:"
27897c478bd9Sstevel@tonic-gate " nexus_properties:\n\tcreate the"
27907c478bd9Sstevel@tonic-gate " \"no-pm-components\""
27917c478bd9Sstevel@tonic-gate " property for %s@%s\n",
27927c478bd9Sstevel@tonic-gate ddi_get_instance(parent), cname, caddr);
27937c478bd9Sstevel@tonic-gate }
27947c478bd9Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, child, 0,
27957c478bd9Sstevel@tonic-gate "no-pm-components", NULL, 0)
27967c478bd9Sstevel@tonic-gate != DDI_PROP_SUCCESS) {
27977c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d:"
27987c478bd9Sstevel@tonic-gate " nexus_properties:\n\tunable to create"
27997c478bd9Sstevel@tonic-gate " the \"no-pm-components\""
28007c478bd9Sstevel@tonic-gate " property for %s@%s",
28017c478bd9Sstevel@tonic-gate ddi_get_instance(parent), cname, caddr);
28027c478bd9Sstevel@tonic-gate }
28037c478bd9Sstevel@tonic-gate }
28047c478bd9Sstevel@tonic-gate }
28057c478bd9Sstevel@tonic-gate }
28067c478bd9Sstevel@tonic-gate
28077c478bd9Sstevel@tonic-gate static void
pshot_leaf_properties(dev_info_t * parent,dev_info_t * child,char * cname,char * caddr)28087c478bd9Sstevel@tonic-gate pshot_leaf_properties(dev_info_t *parent, dev_info_t *child, char *cname,
28097c478bd9Sstevel@tonic-gate char *caddr)
28107c478bd9Sstevel@tonic-gate {
28117c478bd9Sstevel@tonic-gate char *extension;
28127c478bd9Sstevel@tonic-gate
28137c478bd9Sstevel@tonic-gate /*
2814b1dd958fScth * extract the address extension
28157c478bd9Sstevel@tonic-gate */
28167c478bd9Sstevel@tonic-gate extension = strstr(caddr, ",");
28177c478bd9Sstevel@tonic-gate if (extension != NULL) {
28187c478bd9Sstevel@tonic-gate ++extension;
28197c478bd9Sstevel@tonic-gate } else {
28207c478bd9Sstevel@tonic-gate extension = "null";
28217c478bd9Sstevel@tonic-gate }
28227c478bd9Sstevel@tonic-gate
28237c478bd9Sstevel@tonic-gate /*
28247c478bd9Sstevel@tonic-gate * Create the "no-involuntary-power-cycles" property for
28257c478bd9Sstevel@tonic-gate * all leaf nodes with extension "no_invol"
28267c478bd9Sstevel@tonic-gate */
28277c478bd9Sstevel@tonic-gate if (strcmp(extension, "no_invol") == 0) {
28287c478bd9Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, child,
28297c478bd9Sstevel@tonic-gate (DDI_PROP_DONTPASS | DDI_PROP_NOTPROM),
28307c478bd9Sstevel@tonic-gate "no-involuntary-power-cycles") == 0) {
28317c478bd9Sstevel@tonic-gate if (pshot_debug) {
28327c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:"
28337c478bd9Sstevel@tonic-gate " leaf_properties:\n\tcreate the"
28347c478bd9Sstevel@tonic-gate " \"no-involuntary-power-cycles\""
28357c478bd9Sstevel@tonic-gate " property for %s@%s\n",
28367c478bd9Sstevel@tonic-gate ddi_get_instance(parent), cname, caddr);
28377c478bd9Sstevel@tonic-gate }
28387c478bd9Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, child,
28397c478bd9Sstevel@tonic-gate DDI_PROP_CANSLEEP,
28407c478bd9Sstevel@tonic-gate "no-involuntary-power-cycles", NULL, 0)
28417c478bd9Sstevel@tonic-gate != DDI_PROP_SUCCESS) {
28427c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d:"
28437c478bd9Sstevel@tonic-gate " leaf_properties:\n\tunable to create the"
28447c478bd9Sstevel@tonic-gate " \"no-involuntary-power-cycles\""
28457c478bd9Sstevel@tonic-gate " property for %s@%s",
28467c478bd9Sstevel@tonic-gate ddi_get_instance(parent), cname, caddr);
28477c478bd9Sstevel@tonic-gate }
28487c478bd9Sstevel@tonic-gate }
28497c478bd9Sstevel@tonic-gate }
28507c478bd9Sstevel@tonic-gate
28517c478bd9Sstevel@tonic-gate /*
28527c478bd9Sstevel@tonic-gate * Create the "dependency-property" property for all leaf
28537c478bd9Sstevel@tonic-gate * nodes with extension "dep_prop"
28547c478bd9Sstevel@tonic-gate * to be used with the PM_ADD_DEPENDENT_PROPERTY ioctl
28557c478bd9Sstevel@tonic-gate */
28567c478bd9Sstevel@tonic-gate if (strcmp(extension, "dep_prop") == 0) {
28577c478bd9Sstevel@tonic-gate if (ddi_prop_exists(DDI_DEV_T_ANY, child,
28587c478bd9Sstevel@tonic-gate (DDI_PROP_DONTPASS | DDI_PROP_NOTPROM),
28597c478bd9Sstevel@tonic-gate "dependency-property") == 0) {
28607c478bd9Sstevel@tonic-gate if (pshot_debug) {
28617c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d:"
28627c478bd9Sstevel@tonic-gate " leaf_properties:\n\tcreate the"
28637c478bd9Sstevel@tonic-gate " \"dependency-property\""
28647c478bd9Sstevel@tonic-gate " property for %s@%s\n",
28657c478bd9Sstevel@tonic-gate ddi_get_instance(parent), cname, caddr);
28667c478bd9Sstevel@tonic-gate }
28677c478bd9Sstevel@tonic-gate if (ddi_prop_create(DDI_DEV_T_NONE, child,
28687c478bd9Sstevel@tonic-gate DDI_PROP_CANSLEEP, "dependency-property", NULL, 0)
28697c478bd9Sstevel@tonic-gate != DDI_PROP_SUCCESS) {
28707c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d:"
28717c478bd9Sstevel@tonic-gate " leaf_properties:\n\tunable to create the"
28727c478bd9Sstevel@tonic-gate " \"dependency-property\" property for"
28737c478bd9Sstevel@tonic-gate " %s@%s", ddi_get_instance(parent),
28747c478bd9Sstevel@tonic-gate cname, caddr);
28757c478bd9Sstevel@tonic-gate }
28767c478bd9Sstevel@tonic-gate }
28777c478bd9Sstevel@tonic-gate }
28787c478bd9Sstevel@tonic-gate }
28797c478bd9Sstevel@tonic-gate
28807c478bd9Sstevel@tonic-gate /*
28817c478bd9Sstevel@tonic-gate * BUS_CONFIG_ONE: setup a child nexus instance.
28827c478bd9Sstevel@tonic-gate */
28837c478bd9Sstevel@tonic-gate static int
pshot_bus_config_setup_nexus(dev_info_t * parent,char * cname,char * caddr)28847c478bd9Sstevel@tonic-gate pshot_bus_config_setup_nexus(dev_info_t *parent, char *cname, char *caddr)
28857c478bd9Sstevel@tonic-gate {
28867c478bd9Sstevel@tonic-gate dev_info_t *child;
28877c478bd9Sstevel@tonic-gate int rval;
28887c478bd9Sstevel@tonic-gate
28897c478bd9Sstevel@tonic-gate ASSERT(parent != 0);
28907c478bd9Sstevel@tonic-gate ASSERT(cname != NULL);
28917c478bd9Sstevel@tonic-gate ASSERT(caddr != NULL);
28927c478bd9Sstevel@tonic-gate
28937c478bd9Sstevel@tonic-gate child = pshot_findchild(parent, cname, caddr);
28947c478bd9Sstevel@tonic-gate if (child) {
28957c478bd9Sstevel@tonic-gate if (pshot_debug) {
28967c478bd9Sstevel@tonic-gate cmn_err(CE_CONT,
28977c478bd9Sstevel@tonic-gate "pshot%d: bus_config one %s@%s found\n",
28987c478bd9Sstevel@tonic-gate ddi_get_instance(parent), cname, caddr);
28997c478bd9Sstevel@tonic-gate }
29005e3986cbScth
29017c478bd9Sstevel@tonic-gate /*
29027c478bd9Sstevel@tonic-gate * create the "pm-want-child-notification?" property
29037c478bd9Sstevel@tonic-gate * for this child, if it doesn't already exist
29047c478bd9Sstevel@tonic-gate */
29057c478bd9Sstevel@tonic-gate (void) pshot_nexus_properties(parent, child, cname, caddr);
29067c478bd9Sstevel@tonic-gate
29077c478bd9Sstevel@tonic-gate return (NDI_SUCCESS);
29087c478bd9Sstevel@tonic-gate }
29097c478bd9Sstevel@tonic-gate
29107c478bd9Sstevel@tonic-gate ndi_devi_alloc_sleep(parent, cname, DEVI_SID_NODEID, &child);
29117c478bd9Sstevel@tonic-gate ASSERT(child != NULL);
29127c478bd9Sstevel@tonic-gate
29137c478bd9Sstevel@tonic-gate if (ndi_prop_update_string(DDI_DEV_T_NONE, child,
29147c478bd9Sstevel@tonic-gate "bus-addr", caddr) != DDI_PROP_SUCCESS) {
29157c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d: _prop_update %s@%s failed",
29167c478bd9Sstevel@tonic-gate ddi_get_instance(parent), cname, caddr);
29177c478bd9Sstevel@tonic-gate (void) ndi_devi_free(child);
29187c478bd9Sstevel@tonic-gate return (NDI_FAILURE);
29197c478bd9Sstevel@tonic-gate }
29207c478bd9Sstevel@tonic-gate
29217c478bd9Sstevel@tonic-gate rval = ndi_devi_bind_driver(child, 0);
29227c478bd9Sstevel@tonic-gate if (rval != NDI_SUCCESS) {
29237c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d: bind_driver %s failed",
29247c478bd9Sstevel@tonic-gate ddi_get_instance(parent), cname);
29257c478bd9Sstevel@tonic-gate (void) ndi_devi_free(child);
29267c478bd9Sstevel@tonic-gate return (NDI_FAILURE);
29277c478bd9Sstevel@tonic-gate }
29287c478bd9Sstevel@tonic-gate
29297c478bd9Sstevel@tonic-gate /*
29307c478bd9Sstevel@tonic-gate * create the "pm-want-child-notification?" property
29317c478bd9Sstevel@tonic-gate */
29327c478bd9Sstevel@tonic-gate (void) pshot_nexus_properties(parent, child, cname, caddr);
29337c478bd9Sstevel@tonic-gate
29347c478bd9Sstevel@tonic-gate return (NDI_SUCCESS);
29357c478bd9Sstevel@tonic-gate }
29367c478bd9Sstevel@tonic-gate
29377c478bd9Sstevel@tonic-gate /*
29387c478bd9Sstevel@tonic-gate * BUS_CONFIG_ONE: setup a child leaf device instance.
29397c478bd9Sstevel@tonic-gate * for testing purposes, we will create nodes of a variety of types.
29407c478bd9Sstevel@tonic-gate */
29417c478bd9Sstevel@tonic-gate static int
pshot_bus_config_setup_leaf(dev_info_t * parent,char * cname,char * caddr)29427c478bd9Sstevel@tonic-gate pshot_bus_config_setup_leaf(dev_info_t *parent, char *cname, char *caddr)
29437c478bd9Sstevel@tonic-gate {
29447c478bd9Sstevel@tonic-gate dev_info_t *child;
29457c478bd9Sstevel@tonic-gate char *compat_name;
29467c478bd9Sstevel@tonic-gate char *nodetype;
29477c478bd9Sstevel@tonic-gate int rval;
29487c478bd9Sstevel@tonic-gate int i;
29497c478bd9Sstevel@tonic-gate
29507c478bd9Sstevel@tonic-gate ASSERT(parent != 0);
29517c478bd9Sstevel@tonic-gate ASSERT(cname != NULL);
29527c478bd9Sstevel@tonic-gate ASSERT(caddr != NULL);
29537c478bd9Sstevel@tonic-gate
29547c478bd9Sstevel@tonic-gate /*
29557c478bd9Sstevel@tonic-gate * if we already have a node with this name, return it
29567c478bd9Sstevel@tonic-gate */
29577c478bd9Sstevel@tonic-gate if ((child = pshot_findchild(parent, cname, caddr)) != NULL) {
29587c478bd9Sstevel@tonic-gate /*
29597c478bd9Sstevel@tonic-gate * create the "no-involuntary-power-cycles" or
29607c478bd9Sstevel@tonic-gate * the "dependency-property" property, if they
29617c478bd9Sstevel@tonic-gate * don't already exit
29627c478bd9Sstevel@tonic-gate */
29637c478bd9Sstevel@tonic-gate (void) pshot_leaf_properties(parent, child, cname, caddr);
29647c478bd9Sstevel@tonic-gate
29657c478bd9Sstevel@tonic-gate return (NDI_SUCCESS);
29667c478bd9Sstevel@tonic-gate }
29677c478bd9Sstevel@tonic-gate
29687c478bd9Sstevel@tonic-gate ndi_devi_alloc_sleep(parent, cname, DEVI_SID_NODEID, &child);
29697c478bd9Sstevel@tonic-gate ASSERT(child != NULL);
29707c478bd9Sstevel@tonic-gate
29717c478bd9Sstevel@tonic-gate if (ndi_prop_update_string(DDI_DEV_T_NONE, child, "bus-addr",
29727c478bd9Sstevel@tonic-gate caddr) != DDI_PROP_SUCCESS) {
29737c478bd9Sstevel@tonic-gate (void) ndi_devi_free(child);
29747c478bd9Sstevel@tonic-gate return (NDI_FAILURE);
29757c478bd9Sstevel@tonic-gate }
29767c478bd9Sstevel@tonic-gate
29777c478bd9Sstevel@tonic-gate /*
29787c478bd9Sstevel@tonic-gate * test compatible naming
29797c478bd9Sstevel@tonic-gate * if the child nodename is "cdisk", attach the list of compatible
29807c478bd9Sstevel@tonic-gate * named disks
29817c478bd9Sstevel@tonic-gate */
29827c478bd9Sstevel@tonic-gate if (strcmp(cname, pshot_compat_diskname) == 0) {
29837c478bd9Sstevel@tonic-gate if ((ndi_prop_update_string_array(DDI_DEV_T_NONE,
29847c478bd9Sstevel@tonic-gate child, "compatible", (char **)pshot_compat_psramdisks,
29857c478bd9Sstevel@tonic-gate 5)) != DDI_PROP_SUCCESS) {
29867c478bd9Sstevel@tonic-gate (void) ndi_devi_free(child);
29877c478bd9Sstevel@tonic-gate return (NDI_FAILURE);
29887c478bd9Sstevel@tonic-gate }
29897c478bd9Sstevel@tonic-gate } else {
29907c478bd9Sstevel@tonic-gate for (i = 0; i < pshot_devices_len && pshot_devices[i].name;
29917c478bd9Sstevel@tonic-gate i++) {
29927c478bd9Sstevel@tonic-gate if (strcmp(cname, pshot_devices[i].name) == 0) {
29937c478bd9Sstevel@tonic-gate compat_name = pshot_devices[i].compat;
29947c478bd9Sstevel@tonic-gate nodetype = pshot_devices[i].nodetype;
29957c478bd9Sstevel@tonic-gate if (pshot_debug) {
29967c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: %s %s %s\n",
29977c478bd9Sstevel@tonic-gate ddi_get_instance(parent), cname,
29987c478bd9Sstevel@tonic-gate compat_name, nodetype);
29997c478bd9Sstevel@tonic-gate }
30007c478bd9Sstevel@tonic-gate if ((ndi_prop_update_string_array(
30017c478bd9Sstevel@tonic-gate DDI_DEV_T_NONE, child, "compatible",
30027c478bd9Sstevel@tonic-gate &compat_name, 1)) != DDI_PROP_SUCCESS) {
30037c478bd9Sstevel@tonic-gate (void) ndi_devi_free(child);
30047c478bd9Sstevel@tonic-gate return (NDI_FAILURE);
30057c478bd9Sstevel@tonic-gate }
30067c478bd9Sstevel@tonic-gate if ((ndi_prop_update_string(
30077c478bd9Sstevel@tonic-gate DDI_DEV_T_NONE, child, "node-type",
30087c478bd9Sstevel@tonic-gate nodetype)) != DDI_PROP_SUCCESS) {
30097c478bd9Sstevel@tonic-gate (void) ndi_devi_free(child);
30107c478bd9Sstevel@tonic-gate return (NDI_FAILURE);
30117c478bd9Sstevel@tonic-gate }
30127c478bd9Sstevel@tonic-gate }
30137c478bd9Sstevel@tonic-gate }
30147c478bd9Sstevel@tonic-gate }
30157c478bd9Sstevel@tonic-gate
30167c478bd9Sstevel@tonic-gate rval = ndi_devi_bind_driver(child, 0);
30177c478bd9Sstevel@tonic-gate if (rval != NDI_SUCCESS) {
30187c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pshot%d: bind_driver %s failed",
30197c478bd9Sstevel@tonic-gate ddi_get_instance(parent), cname);
30207c478bd9Sstevel@tonic-gate (void) ndi_devi_free(child);
30217c478bd9Sstevel@tonic-gate return (NDI_FAILURE);
30227c478bd9Sstevel@tonic-gate }
30237c478bd9Sstevel@tonic-gate
30247c478bd9Sstevel@tonic-gate /*
30257c478bd9Sstevel@tonic-gate * create the "no-involuntary-power-cycles" or
30267c478bd9Sstevel@tonic-gate * the "dependency-property" property
30277c478bd9Sstevel@tonic-gate */
30287c478bd9Sstevel@tonic-gate (void) pshot_leaf_properties(parent, child, cname, caddr);
30297c478bd9Sstevel@tonic-gate
30307c478bd9Sstevel@tonic-gate return (NDI_SUCCESS);
30317c478bd9Sstevel@tonic-gate }
30327c478bd9Sstevel@tonic-gate
30337c478bd9Sstevel@tonic-gate /*
30347c478bd9Sstevel@tonic-gate * Handle some special cases for testing bus_config via pshot
30357c478bd9Sstevel@tonic-gate *
30367c478bd9Sstevel@tonic-gate * Match these special address formats to behavior:
30377c478bd9Sstevel@tonic-gate *
30387c478bd9Sstevel@tonic-gate * err.* - induce bus_config error
30397c478bd9Sstevel@tonic-gate * delay - induce 1 second of bus_config delay time
30407c478bd9Sstevel@tonic-gate * delay,n - induce n seconds of bus_config delay time
30417c478bd9Sstevel@tonic-gate * wait - induce 1 second of bus_config wait time
30427c478bd9Sstevel@tonic-gate * wait,n - induce n seconds of bus_config wait time
30437c478bd9Sstevel@tonic-gate * failinit.* - induce error at INITCHILD
30447c478bd9Sstevel@tonic-gate * failprobe.* - induce error at probe
30457c478bd9Sstevel@tonic-gate * failattach.* - induce error at attach
30467c478bd9Sstevel@tonic-gate */
30477c478bd9Sstevel@tonic-gate /*ARGSUSED*/
30487c478bd9Sstevel@tonic-gate static int
pshot_bus_config_test_specials(dev_info_t * parent,char * devname,char * cname,char * caddr)30497c478bd9Sstevel@tonic-gate pshot_bus_config_test_specials(dev_info_t *parent, char *devname,
30507c478bd9Sstevel@tonic-gate char *cname, char *caddr)
30517c478bd9Sstevel@tonic-gate {
30527c478bd9Sstevel@tonic-gate char *p;
30537c478bd9Sstevel@tonic-gate int n;
30547c478bd9Sstevel@tonic-gate
30557c478bd9Sstevel@tonic-gate if (strncmp(caddr, "err", 3) == 0) {
30567c478bd9Sstevel@tonic-gate if (pshot_debug)
30577c478bd9Sstevel@tonic-gate cmn_err(CE_CONT,
30587c478bd9Sstevel@tonic-gate "pshot%d: %s forced failure\n",
30597c478bd9Sstevel@tonic-gate ddi_get_instance(parent), devname);
30607c478bd9Sstevel@tonic-gate return (NDI_FAILURE);
30617c478bd9Sstevel@tonic-gate }
30627c478bd9Sstevel@tonic-gate
30637c478bd9Sstevel@tonic-gate /*
30647c478bd9Sstevel@tonic-gate * The delay and wait strings have the same effect.
30657c478bd9Sstevel@tonic-gate * The "wait[,]" support should be removed once the
30667c478bd9Sstevel@tonic-gate * devfs test suites are fixed.
30677c478bd9Sstevel@tonic-gate * NOTE: delay should not be called from interrupt context
30687c478bd9Sstevel@tonic-gate */
30697c478bd9Sstevel@tonic-gate ASSERT(!servicing_interrupt());
30707c478bd9Sstevel@tonic-gate
30717c478bd9Sstevel@tonic-gate if (strncmp(caddr, "delay,", 6) == 0) {
30727c478bd9Sstevel@tonic-gate p = caddr+6;
30737c478bd9Sstevel@tonic-gate n = stoi(&p);
30747c478bd9Sstevel@tonic-gate if (*p != 0)
30757c478bd9Sstevel@tonic-gate n = 1;
30767c478bd9Sstevel@tonic-gate if (pshot_debug)
30777c478bd9Sstevel@tonic-gate cmn_err(CE_CONT,
30787c478bd9Sstevel@tonic-gate "pshot%d: %s delay %d second\n",
30797c478bd9Sstevel@tonic-gate ddi_get_instance(parent), devname, n);
30807c478bd9Sstevel@tonic-gate delay(n * drv_usectohz(1000000));
30817c478bd9Sstevel@tonic-gate } else if (strncmp(caddr, "delay", 5) == 0) {
30827c478bd9Sstevel@tonic-gate if (pshot_debug)
30837c478bd9Sstevel@tonic-gate cmn_err(CE_CONT,
30847c478bd9Sstevel@tonic-gate "pshot%d: %s delay 1 second\n",
30857c478bd9Sstevel@tonic-gate ddi_get_instance(parent), devname);
30867c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
30877c478bd9Sstevel@tonic-gate } else if (strncmp(caddr, "wait,", 5) == 0) {
30887c478bd9Sstevel@tonic-gate p = caddr+5;
30897c478bd9Sstevel@tonic-gate n = stoi(&p);
30907c478bd9Sstevel@tonic-gate if (*p != 0)
30917c478bd9Sstevel@tonic-gate n = 1;
30927c478bd9Sstevel@tonic-gate if (pshot_debug)
30937c478bd9Sstevel@tonic-gate cmn_err(CE_CONT,
30947c478bd9Sstevel@tonic-gate "pshot%d: %s wait %d second\n",
30957c478bd9Sstevel@tonic-gate ddi_get_instance(parent), devname, n);
30967c478bd9Sstevel@tonic-gate delay(n * drv_usectohz(1000000));
30977c478bd9Sstevel@tonic-gate } else if (strncmp(caddr, "wait", 4) == 0) {
30987c478bd9Sstevel@tonic-gate if (pshot_debug)
30997c478bd9Sstevel@tonic-gate cmn_err(CE_CONT,
31007c478bd9Sstevel@tonic-gate "pshot%d: %s wait 1 second\n",
31017c478bd9Sstevel@tonic-gate ddi_get_instance(parent), devname);
31027c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
31037c478bd9Sstevel@tonic-gate }
31047c478bd9Sstevel@tonic-gate
31057c478bd9Sstevel@tonic-gate return (NDI_SUCCESS);
31067c478bd9Sstevel@tonic-gate }
31077c478bd9Sstevel@tonic-gate
31087c478bd9Sstevel@tonic-gate /*
31097c478bd9Sstevel@tonic-gate * translate nodetype name to actual value
31107c478bd9Sstevel@tonic-gate */
31117c478bd9Sstevel@tonic-gate static char *
pshot_str2nt(char * str)31127c478bd9Sstevel@tonic-gate pshot_str2nt(char *str)
31137c478bd9Sstevel@tonic-gate {
31147c478bd9Sstevel@tonic-gate int i;
31157c478bd9Sstevel@tonic-gate
31167c478bd9Sstevel@tonic-gate for (i = 0; pshot_nodetypes[i].name; i++) {
31177c478bd9Sstevel@tonic-gate if (strcmp(pshot_nodetypes[i].name, str) == 0)
31187c478bd9Sstevel@tonic-gate return (pshot_nodetypes[i].val);
31197c478bd9Sstevel@tonic-gate }
31207c478bd9Sstevel@tonic-gate return (NULL);
31217c478bd9Sstevel@tonic-gate }
31227c478bd9Sstevel@tonic-gate
31237c478bd9Sstevel@tonic-gate /*
31247c478bd9Sstevel@tonic-gate * grows array pointed to by <dstp>, with <src> data
31257c478bd9Sstevel@tonic-gate * <dstlen> = # elements of the original <*dstp>
31267c478bd9Sstevel@tonic-gate * <srclen> = # elements of <src>
31277c478bd9Sstevel@tonic-gate *
31287c478bd9Sstevel@tonic-gate * on success, returns 0 and a pointer to the new array through <dstp> with
31297c478bd9Sstevel@tonic-gate * <srclen> + <dstlen> number of elements;
31307c478bd9Sstevel@tonic-gate * else returns non-zero
31317c478bd9Sstevel@tonic-gate *
31327c478bd9Sstevel@tonic-gate * a NULL <*dstp> is OK (a NULL <dstp> is not) and so is a zero <dstlen>
31337c478bd9Sstevel@tonic-gate */
31347c478bd9Sstevel@tonic-gate static int
pshot_devices_grow(pshot_device_t ** dstp,size_t dstlen,const pshot_device_t * src,size_t srclen)31357c478bd9Sstevel@tonic-gate pshot_devices_grow(pshot_device_t **dstp, size_t dstlen,
31367c478bd9Sstevel@tonic-gate const pshot_device_t *src, size_t srclen)
31377c478bd9Sstevel@tonic-gate {
31387c478bd9Sstevel@tonic-gate size_t i;
31397c478bd9Sstevel@tonic-gate pshot_device_t *newdst;
31407c478bd9Sstevel@tonic-gate
31417c478bd9Sstevel@tonic-gate newdst = kmem_alloc((srclen + dstlen) * sizeof (*src),
31427c478bd9Sstevel@tonic-gate KM_SLEEP);
31437c478bd9Sstevel@tonic-gate
31447c478bd9Sstevel@tonic-gate /* keep old pointers and dup new ones */
31457c478bd9Sstevel@tonic-gate if (*dstp)
31467c478bd9Sstevel@tonic-gate bcopy(*dstp, newdst, dstlen * sizeof (*src));
31477c478bd9Sstevel@tonic-gate for (i = 0; i < srclen; i++) {
31487c478bd9Sstevel@tonic-gate newdst[i + dstlen].name =
31497c478bd9Sstevel@tonic-gate i_ddi_strdup(src[i].name, KM_SLEEP);
31507c478bd9Sstevel@tonic-gate
31517c478bd9Sstevel@tonic-gate newdst[i + dstlen].nodetype =
31527c478bd9Sstevel@tonic-gate i_ddi_strdup(src[i].nodetype, KM_SLEEP);
31537c478bd9Sstevel@tonic-gate
31547c478bd9Sstevel@tonic-gate newdst[i + dstlen].compat =
31557c478bd9Sstevel@tonic-gate i_ddi_strdup(src[i].compat, KM_SLEEP);
31567c478bd9Sstevel@tonic-gate }
31577c478bd9Sstevel@tonic-gate
31587c478bd9Sstevel@tonic-gate /* do last */
31597c478bd9Sstevel@tonic-gate if (*dstp)
31607c478bd9Sstevel@tonic-gate kmem_free(*dstp, dstlen * sizeof (*src));
31617c478bd9Sstevel@tonic-gate *dstp = newdst;
31627c478bd9Sstevel@tonic-gate return (0);
31637c478bd9Sstevel@tonic-gate }
31647c478bd9Sstevel@tonic-gate
31657c478bd9Sstevel@tonic-gate /*
31667c478bd9Sstevel@tonic-gate * free a pshot_device_t array <dp> with <len> elements
31677c478bd9Sstevel@tonic-gate * null pointers within the elements are ok
31687c478bd9Sstevel@tonic-gate */
31697c478bd9Sstevel@tonic-gate static void
pshot_devices_free(pshot_device_t * dp,size_t len)31707c478bd9Sstevel@tonic-gate pshot_devices_free(pshot_device_t *dp, size_t len)
31717c478bd9Sstevel@tonic-gate {
31727c478bd9Sstevel@tonic-gate size_t i;
31737c478bd9Sstevel@tonic-gate
31747c478bd9Sstevel@tonic-gate for (i = 0; i < len; i++) {
31757c478bd9Sstevel@tonic-gate if (dp[i].name)
31767c478bd9Sstevel@tonic-gate kmem_free(dp[i].name, strlen(dp[i].name) + 1);
31777c478bd9Sstevel@tonic-gate if (dp[i].nodetype)
31787c478bd9Sstevel@tonic-gate kmem_free(dp[i].nodetype, strlen(dp[i].nodetype) + 1);
31797c478bd9Sstevel@tonic-gate if (dp[i].compat)
31807c478bd9Sstevel@tonic-gate kmem_free(dp[i].compat, strlen(dp[i].compat) + 1);
31817c478bd9Sstevel@tonic-gate }
31827c478bd9Sstevel@tonic-gate kmem_free(dp, len * sizeof (*dp));
31837c478bd9Sstevel@tonic-gate }
31847c478bd9Sstevel@tonic-gate
31857c478bd9Sstevel@tonic-gate /*
31867c478bd9Sstevel@tonic-gate * returns an array of pshot_device_t parsed from <dip>'s properties
31877c478bd9Sstevel@tonic-gate *
31887c478bd9Sstevel@tonic-gate * property structure (i.e. pshot.conf) for pshot:
31897c478bd9Sstevel@tonic-gate *
31907c478bd9Sstevel@tonic-gate * corresponding | pshot_device_t array elements
31917c478bd9Sstevel@tonic-gate * pshot_device_t |
31927c478bd9Sstevel@tonic-gate * member by prop name | [0] [1] [2]
31937c478bd9Sstevel@tonic-gate * ----------------------|--------------|-------------|-----------------------
31947c478bd9Sstevel@tonic-gate * <PSHOT_PROP_DEVNAME> ="disk", "tape", "testdev";
31957c478bd9Sstevel@tonic-gate * <PSHOT_PROP_DEVNT> ="DDI_NT_BLOCK","DDI_NT_TAPE","ddi_testdev_nodetype";
31967c478bd9Sstevel@tonic-gate * <PSHOT_PROP_DEVCOMPAT>="testdrv", "testdrv", "testdrv";
31977c478bd9Sstevel@tonic-gate *
31987c478bd9Sstevel@tonic-gate *
31997c478bd9Sstevel@tonic-gate * if any of these properties are specified, then:
32007c478bd9Sstevel@tonic-gate * - all the members must be specified
32017c478bd9Sstevel@tonic-gate * - the number of elements for each string array property must be the same
32027c478bd9Sstevel@tonic-gate * - no empty strings allowed
32037c478bd9Sstevel@tonic-gate * - nodetypes (PSHOT_PROP_DEVNT) must be the nodetype name as specified in
32047c478bd9Sstevel@tonic-gate * sys/sunddi.h
32057c478bd9Sstevel@tonic-gate *
32067c478bd9Sstevel@tonic-gate * NOTE: the pshot_nodetypes[] table should be kept in sync with the list
32077c478bd9Sstevel@tonic-gate * of ddi nodetypes. It's not normally critical to always be in sync so
32087c478bd9Sstevel@tonic-gate * keeping this up-to-date can usually be done "on-demand".
32097c478bd9Sstevel@tonic-gate *
32107c478bd9Sstevel@tonic-gate * if <flags> & PSHOT_DEV_ANYNT, then custom nodetype strings are allowed.
32117c478bd9Sstevel@tonic-gate * these will be duplicated verbatim
32127c478bd9Sstevel@tonic-gate */
32137c478bd9Sstevel@tonic-gate static pshot_device_t *
pshot_devices_from_props(dev_info_t * dip,size_t * lenp,int flags)32147c478bd9Sstevel@tonic-gate pshot_devices_from_props(dev_info_t *dip, size_t *lenp, int flags)
32157c478bd9Sstevel@tonic-gate {
32167c478bd9Sstevel@tonic-gate pshot_device_t *devarr = NULL;
32177c478bd9Sstevel@tonic-gate char **name_arr = NULL, **nt_arr = NULL, **compat_arr = NULL;
32187c478bd9Sstevel@tonic-gate uint_t name_arr_len, nt_arr_len, compat_arr_len;
32197c478bd9Sstevel@tonic-gate uint_t i;
32207c478bd9Sstevel@tonic-gate char *str;
32217c478bd9Sstevel@tonic-gate
32227c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, dip, 0,
32237c478bd9Sstevel@tonic-gate PSHOT_PROP_DEVNAME, &name_arr, &name_arr_len) !=
32247c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS)
32257c478bd9Sstevel@tonic-gate name_arr = NULL;
32267c478bd9Sstevel@tonic-gate
32277c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, dip, 0,
32287c478bd9Sstevel@tonic-gate PSHOT_PROP_DEVNT, &nt_arr, &nt_arr_len) !=
32297c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS)
32307c478bd9Sstevel@tonic-gate nt_arr = NULL;
32317c478bd9Sstevel@tonic-gate
32327c478bd9Sstevel@tonic-gate if (ddi_prop_lookup_string_array(DDI_DEV_T_ANY, dip, 0,
32337c478bd9Sstevel@tonic-gate PSHOT_PROP_DEVCOMPAT, &compat_arr, &compat_arr_len) !=
32347c478bd9Sstevel@tonic-gate DDI_PROP_SUCCESS)
32357c478bd9Sstevel@tonic-gate compat_arr = NULL;
32367c478bd9Sstevel@tonic-gate
32377c478bd9Sstevel@tonic-gate /*
32387c478bd9Sstevel@tonic-gate * warn about any incorrect usage, if specified
32397c478bd9Sstevel@tonic-gate */
32407c478bd9Sstevel@tonic-gate if (!(name_arr || nt_arr || compat_arr))
32417c478bd9Sstevel@tonic-gate return (NULL);
32427c478bd9Sstevel@tonic-gate
32437c478bd9Sstevel@tonic-gate if (!(name_arr && nt_arr && compat_arr) ||
32447c478bd9Sstevel@tonic-gate (name_arr_len != nt_arr_len) ||
32457c478bd9Sstevel@tonic-gate (name_arr_len != compat_arr_len))
32467c478bd9Sstevel@tonic-gate goto FAIL;
32477c478bd9Sstevel@tonic-gate
32487c478bd9Sstevel@tonic-gate for (i = 0; i < name_arr_len; i++) {
32497c478bd9Sstevel@tonic-gate if (*name_arr[i] == '\0' ||
32507c478bd9Sstevel@tonic-gate *nt_arr[i] == '\0' ||
32517c478bd9Sstevel@tonic-gate *compat_arr[i] == '\0')
32527c478bd9Sstevel@tonic-gate goto FAIL;
32537c478bd9Sstevel@tonic-gate }
32547c478bd9Sstevel@tonic-gate
32557c478bd9Sstevel@tonic-gate devarr = kmem_zalloc(name_arr_len * sizeof (*devarr), KM_SLEEP);
32567c478bd9Sstevel@tonic-gate for (i = 0; i < name_arr_len; i++) {
32577c478bd9Sstevel@tonic-gate devarr[i].name = i_ddi_strdup(name_arr[i], KM_SLEEP);
32587c478bd9Sstevel@tonic-gate devarr[i].compat = i_ddi_strdup(compat_arr[i], KM_SLEEP);
32597c478bd9Sstevel@tonic-gate
32607c478bd9Sstevel@tonic-gate if ((str = pshot_str2nt(nt_arr[i])) == NULL)
32617c478bd9Sstevel@tonic-gate if (flags & PSHOT_DEV_ANYNT)
32627c478bd9Sstevel@tonic-gate str = nt_arr[i];
32637c478bd9Sstevel@tonic-gate else
32647c478bd9Sstevel@tonic-gate goto FAIL;
32657c478bd9Sstevel@tonic-gate devarr[i].nodetype = i_ddi_strdup(str, KM_SLEEP);
32667c478bd9Sstevel@tonic-gate }
32677c478bd9Sstevel@tonic-gate ddi_prop_free(name_arr);
32687c478bd9Sstevel@tonic-gate ddi_prop_free(nt_arr);
32697c478bd9Sstevel@tonic-gate ddi_prop_free(compat_arr);
32707c478bd9Sstevel@tonic-gate
32717c478bd9Sstevel@tonic-gate /* set <*lenp> ONLY on success */
32727c478bd9Sstevel@tonic-gate *lenp = name_arr_len;
32737c478bd9Sstevel@tonic-gate
32747c478bd9Sstevel@tonic-gate return (devarr);
32757c478bd9Sstevel@tonic-gate /*NOTREACHED*/
32767c478bd9Sstevel@tonic-gate FAIL:
32777c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "malformed device specification property");
32787c478bd9Sstevel@tonic-gate if (name_arr)
32797c478bd9Sstevel@tonic-gate ddi_prop_free(name_arr);
32807c478bd9Sstevel@tonic-gate if (nt_arr)
32817c478bd9Sstevel@tonic-gate ddi_prop_free(nt_arr);
32827c478bd9Sstevel@tonic-gate if (compat_arr)
32837c478bd9Sstevel@tonic-gate ddi_prop_free(compat_arr);
32847c478bd9Sstevel@tonic-gate if (devarr)
32857c478bd9Sstevel@tonic-gate pshot_devices_free(devarr, name_arr_len);
32867c478bd9Sstevel@tonic-gate return (NULL);
32877c478bd9Sstevel@tonic-gate }
32887c478bd9Sstevel@tonic-gate
32897c478bd9Sstevel@tonic-gate /*
32907c478bd9Sstevel@tonic-gate * if global <pshot_devices> was not set up already (i.e. is NULL):
32917c478bd9Sstevel@tonic-gate * sets up global <pshot_devices> and <pshot_devices_len>,
32927c478bd9Sstevel@tonic-gate * using device properties from <dip> and global <pshot_stock_devices>.
32937c478bd9Sstevel@tonic-gate * device properties, if any, overrides pshot_stock_devices.
32947c478bd9Sstevel@tonic-gate *
32957c478bd9Sstevel@tonic-gate * returns 0 on success (or if pshot_devices already set up)
32967c478bd9Sstevel@tonic-gate *
32977c478bd9Sstevel@tonic-gate * INTERNAL LOCKING: <pshot_devices_lock>
32987c478bd9Sstevel@tonic-gate */
32997c478bd9Sstevel@tonic-gate static int
pshot_devices_setup(dev_info_t * dip)33007c478bd9Sstevel@tonic-gate pshot_devices_setup(dev_info_t *dip)
33017c478bd9Sstevel@tonic-gate {
33027c478bd9Sstevel@tonic-gate pshot_device_t *newdevs = NULL;
33037c478bd9Sstevel@tonic-gate size_t newdevs_len = 0;
33047c478bd9Sstevel@tonic-gate int rv = 0;
33057c478bd9Sstevel@tonic-gate
33067c478bd9Sstevel@tonic-gate mutex_enter(&pshot_devices_lock);
33077c478bd9Sstevel@tonic-gate if (pshot_devices != NULL)
33087c478bd9Sstevel@tonic-gate goto FAIL;
33097c478bd9Sstevel@tonic-gate
33107c478bd9Sstevel@tonic-gate ASSERT(pshot_devices_len == 0);
33117c478bd9Sstevel@tonic-gate
33127c478bd9Sstevel@tonic-gate newdevs = pshot_devices_from_props(dip, &newdevs_len, PSHOT_DEV_ANYNT);
33137c478bd9Sstevel@tonic-gate rv = pshot_devices_grow(&newdevs, newdevs_len, pshot_stock_devices,
33147c478bd9Sstevel@tonic-gate PSHOT_N_STOCK_DEVICES);
33157c478bd9Sstevel@tonic-gate if (rv != 0) {
33167c478bd9Sstevel@tonic-gate cmn_err(CE_WARN, "pshot_devices_setup: pshot_devices_grow "
33177c478bd9Sstevel@tonic-gate "failed");
33187c478bd9Sstevel@tonic-gate goto FAIL;
33197c478bd9Sstevel@tonic-gate }
33207c478bd9Sstevel@tonic-gate newdevs_len += PSHOT_N_STOCK_DEVICES;
33217c478bd9Sstevel@tonic-gate
33227c478bd9Sstevel@tonic-gate pshot_devices = newdevs;
33237c478bd9Sstevel@tonic-gate pshot_devices_len = newdevs_len;
33247c478bd9Sstevel@tonic-gate rv = 0;
33257c478bd9Sstevel@tonic-gate FAIL:
33267c478bd9Sstevel@tonic-gate if (rv && newdevs)
33277c478bd9Sstevel@tonic-gate pshot_devices_free(newdevs, newdevs_len);
33287c478bd9Sstevel@tonic-gate mutex_exit(&pshot_devices_lock);
33297c478bd9Sstevel@tonic-gate return (rv);
33307c478bd9Sstevel@tonic-gate }
33317c478bd9Sstevel@tonic-gate
33327c478bd9Sstevel@tonic-gate
33337c478bd9Sstevel@tonic-gate #ifdef NOTNEEDED
33347c478bd9Sstevel@tonic-gate /* ARGSUSED */
33357c478bd9Sstevel@tonic-gate static int
pshot_probe_family(dev_info_t * self,ddi_probe_method_t probe_how,dev_info_t ** return_dip)33367c478bd9Sstevel@tonic-gate pshot_probe_family(dev_info_t *self, ddi_probe_method_t probe_how,
33377c478bd9Sstevel@tonic-gate dev_info_t **return_dip)
33387c478bd9Sstevel@tonic-gate {
33397c478bd9Sstevel@tonic-gate char name[64];
33407c478bd9Sstevel@tonic-gate uint_t bus_id;
33417c478bd9Sstevel@tonic-gate dev_info_t *child;
33427c478bd9Sstevel@tonic-gate
33437c478bd9Sstevel@tonic-gate for (bus_id = 10; bus_id < 20; bus_id++) {
33447c478bd9Sstevel@tonic-gate (void) sprintf(name, "%d", bus_id);
33457c478bd9Sstevel@tonic-gate if ((ndi_devi_alloc(self, "psramd", DEVI_SID_NODEID,
33467c478bd9Sstevel@tonic-gate &child)) != NDI_SUCCESS) {
33477c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
33487c478bd9Sstevel@tonic-gate }
33497c478bd9Sstevel@tonic-gate
33507c478bd9Sstevel@tonic-gate if (ndi_prop_update_string(DDI_DEV_T_NONE, child,
33517c478bd9Sstevel@tonic-gate "bus-addr", name) != DDI_PROP_SUCCESS) {
33527c478bd9Sstevel@tonic-gate (void) ndi_devi_free(child);
33537c478bd9Sstevel@tonic-gate if (return_dip != NULL)
33547c478bd9Sstevel@tonic-gate *return_dip = (dev_info_t *)NULL;
33557c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
33567c478bd9Sstevel@tonic-gate }
33577c478bd9Sstevel@tonic-gate
33587c478bd9Sstevel@tonic-gate if (ndi_devi_online(child, 0) != NDI_SUCCESS) {
33597c478bd9Sstevel@tonic-gate return (DDI_FAILURE);
33607c478bd9Sstevel@tonic-gate }
33617c478bd9Sstevel@tonic-gate }
33627c478bd9Sstevel@tonic-gate return (DDI_SUCCESS);
33637c478bd9Sstevel@tonic-gate }
33647c478bd9Sstevel@tonic-gate
33657c478bd9Sstevel@tonic-gate static int
strtoi(char * str)33667c478bd9Sstevel@tonic-gate strtoi(char *str)
33677c478bd9Sstevel@tonic-gate {
33687c478bd9Sstevel@tonic-gate int c;
33697c478bd9Sstevel@tonic-gate int val;
33707c478bd9Sstevel@tonic-gate
33717c478bd9Sstevel@tonic-gate for (val = 0, c = *str++; c >= '0' && c <= '9'; c = *str++) {
33727c478bd9Sstevel@tonic-gate val *= 10;
33737c478bd9Sstevel@tonic-gate val += c - '0';
33747c478bd9Sstevel@tonic-gate }
33757c478bd9Sstevel@tonic-gate return (val);
33767c478bd9Sstevel@tonic-gate }
33777c478bd9Sstevel@tonic-gate
3378b1dd958fScth #endif
33797c478bd9Sstevel@tonic-gate
33807c478bd9Sstevel@tonic-gate static void
pshot_setup_autoattach(dev_info_t * devi)33817c478bd9Sstevel@tonic-gate pshot_setup_autoattach(dev_info_t *devi)
33827c478bd9Sstevel@tonic-gate {
33837c478bd9Sstevel@tonic-gate dev_info_t *l1child, *l2child;
33847c478bd9Sstevel@tonic-gate int rv;
33857c478bd9Sstevel@tonic-gate
33867c478bd9Sstevel@tonic-gate rv = ndi_devi_alloc(devi, "pshot", DEVI_SID_NODEID, &l1child);
33877c478bd9Sstevel@tonic-gate if (rv == NDI_SUCCESS) {
33887c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, l1child,
33897c478bd9Sstevel@tonic-gate "bus-addr", "0");
33907c478bd9Sstevel@tonic-gate rv = ndi_devi_alloc(l1child, "port", DEVI_SID_NODEID,
33917c478bd9Sstevel@tonic-gate &l2child);
33927c478bd9Sstevel@tonic-gate if (rv == NDI_SUCCESS)
33937c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE,
33947c478bd9Sstevel@tonic-gate l2child, "bus-addr", "99");
33957c478bd9Sstevel@tonic-gate }
33967c478bd9Sstevel@tonic-gate
33977c478bd9Sstevel@tonic-gate rv = ndi_devi_alloc(devi, "port", DEVI_SID_NODEID, &l1child);
33987c478bd9Sstevel@tonic-gate if (rv == NDI_SUCCESS)
33997c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, l1child,
34007c478bd9Sstevel@tonic-gate "bus-addr", "99");
34017c478bd9Sstevel@tonic-gate
34027c478bd9Sstevel@tonic-gate rv = ndi_devi_alloc(devi, "gen_drv", DEVI_SID_NODEID, &l1child);
34037c478bd9Sstevel@tonic-gate if (rv == NDI_SUCCESS)
34047c478bd9Sstevel@tonic-gate (void) ndi_prop_update_string(DDI_DEV_T_NONE, l1child,
34057c478bd9Sstevel@tonic-gate "bus-addr", "99");
34067c478bd9Sstevel@tonic-gate
34077c478bd9Sstevel@tonic-gate rv = ndi_devi_alloc(devi, "no_driver", DEVI_SID_NODEID, &l1child);
34087c478bd9Sstevel@tonic-gate if (rv == NDI_SUCCESS)
34097c478bd9Sstevel@tonic-gate (void) ndi_devi_alloc(l1child, "no_driver", DEVI_SID_NODEID,
34107c478bd9Sstevel@tonic-gate &l2child);
34117c478bd9Sstevel@tonic-gate }
34127c478bd9Sstevel@tonic-gate
34137c478bd9Sstevel@tonic-gate #ifdef PRUNE_SNUBS
34147c478bd9Sstevel@tonic-gate
34157c478bd9Sstevel@tonic-gate #define PRUNE_THIS_NODE(d) (((d)->devi_node_name != NULL) && \
34167c478bd9Sstevel@tonic-gate (DEVI_PROM_NODE((d)->devi_nodeid)) && \
34177c478bd9Sstevel@tonic-gate ((d)->devi_addr == NULL))
34187c478bd9Sstevel@tonic-gate /*
34197c478bd9Sstevel@tonic-gate * test code to remove OBP nodes that have not attached
34207c478bd9Sstevel@tonic-gate */
34217c478bd9Sstevel@tonic-gate static void
prune_snubs(const char * name)34227c478bd9Sstevel@tonic-gate prune_snubs(const char *name)
34237c478bd9Sstevel@tonic-gate {
34247c478bd9Sstevel@tonic-gate struct dev_info *nex_dip, *cdip, *cndip;
34257c478bd9Sstevel@tonic-gate int maj;
34267c478bd9Sstevel@tonic-gate int rv;
34277c478bd9Sstevel@tonic-gate
34287c478bd9Sstevel@tonic-gate maj = ddi_name_to_major((char *)name);
34297c478bd9Sstevel@tonic-gate if (maj != -1) {
34307c478bd9Sstevel@tonic-gate nex_dip = (struct dev_info *)devnamesp[maj].dn_head;
34317c478bd9Sstevel@tonic-gate while (nex_dip != NULL) {
34327c478bd9Sstevel@tonic-gate cndip = ddi_get_child(nex_dip);
34337c478bd9Sstevel@tonic-gate while ((cdip = cndip) != NULL) {
34347c478bd9Sstevel@tonic-gate cndip = cdip->devi_sibling;
34357c478bd9Sstevel@tonic-gate if (PRUNE_THIS_NODE(cdip)) {
34367c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE,
34377c478bd9Sstevel@tonic-gate "parent %s@%s pruning node %s",
34387c478bd9Sstevel@tonic-gate nex_dip->devi_node_name,
34397c478bd9Sstevel@tonic-gate nex_dip->devi_addr,
34407c478bd9Sstevel@tonic-gate cdip->devi_node_name);
34417c478bd9Sstevel@tonic-gate rv = ndi_devi_offline(cdip,
34427c478bd9Sstevel@tonic-gate NDI_DEVI_REMOVE);
34437c478bd9Sstevel@tonic-gate if (rv != NDI_SUCCESS)
34447c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE,
34457c478bd9Sstevel@tonic-gate "failed to prune node, "
34467c478bd9Sstevel@tonic-gate "err %d", rv);
34477c478bd9Sstevel@tonic-gate }
34487c478bd9Sstevel@tonic-gate }
34497c478bd9Sstevel@tonic-gate nex_dip = nex_dip->devi_next;
34507c478bd9Sstevel@tonic-gate }
34517c478bd9Sstevel@tonic-gate }
34527c478bd9Sstevel@tonic-gate }
34537c478bd9Sstevel@tonic-gate
34547c478bd9Sstevel@tonic-gate #endif /* PRUBE_SNUBS */
34557c478bd9Sstevel@tonic-gate
34567c478bd9Sstevel@tonic-gate #ifdef KERNEL_DEVICE_TREE_WALKER
34577c478bd9Sstevel@tonic-gate static kthread_id_t pwt;
34587c478bd9Sstevel@tonic-gate static kmutex_t pwl;
34597c478bd9Sstevel@tonic-gate static kcondvar_t pwcv;
34607c478bd9Sstevel@tonic-gate
34617c478bd9Sstevel@tonic-gate static void
pshot_walk_tree()34627c478bd9Sstevel@tonic-gate pshot_walk_tree()
34637c478bd9Sstevel@tonic-gate {
34647c478bd9Sstevel@tonic-gate static int pshot_devnode(dev_info_t *dip, void * arg);
34657c478bd9Sstevel@tonic-gate
34667c478bd9Sstevel@tonic-gate dev_info_t *root = ddi_root_node();
34677c478bd9Sstevel@tonic-gate ddi_walk_devs(root, pshot_devnode, NULL);
34687c478bd9Sstevel@tonic-gate }
34697c478bd9Sstevel@tonic-gate
34707c478bd9Sstevel@tonic-gate static void
pshot_walk_thread()34717c478bd9Sstevel@tonic-gate pshot_walk_thread()
34727c478bd9Sstevel@tonic-gate {
34737c478bd9Sstevel@tonic-gate static void pshot_timeout(void *arg);
34747c478bd9Sstevel@tonic-gate static kthread_id_t pwt;
34757c478bd9Sstevel@tonic-gate
34767c478bd9Sstevel@tonic-gate pwt = curthread;
34777c478bd9Sstevel@tonic-gate mutex_init(&pwl, NULL, MUTEX_DRIVER, NULL);
34787c478bd9Sstevel@tonic-gate cv_init(&pwcv, NULL, CV_DRIVER, NULL);
34797c478bd9Sstevel@tonic-gate
34807c478bd9Sstevel@tonic-gate while (1) {
34817c478bd9Sstevel@tonic-gate pshot_walk_tree();
34827c478bd9Sstevel@tonic-gate mutex_enter(&pwl);
34837c478bd9Sstevel@tonic-gate (void) timeout(pshot_timeout, NULL, 5 * drv_usectohz(1000000));
34847c478bd9Sstevel@tonic-gate cv_wait(&pwcv, &pwl);
34857c478bd9Sstevel@tonic-gate mutex_exit(&pwl);
34867c478bd9Sstevel@tonic-gate }
34877c478bd9Sstevel@tonic-gate }
34887c478bd9Sstevel@tonic-gate
34897c478bd9Sstevel@tonic-gate static void
pshot_timeout(void * arg)34907c478bd9Sstevel@tonic-gate pshot_timeout(void *arg)
34917c478bd9Sstevel@tonic-gate {
34927c478bd9Sstevel@tonic-gate mutex_enter(&pwl);
34937c478bd9Sstevel@tonic-gate cv_signal(&pwcv);
34947c478bd9Sstevel@tonic-gate mutex_exit(&pwl);
34957c478bd9Sstevel@tonic-gate }
34967c478bd9Sstevel@tonic-gate
34977c478bd9Sstevel@tonic-gate static int
pshot_devnode(dev_info_t * dip,void * arg)34987c478bd9Sstevel@tonic-gate pshot_devnode(dev_info_t *dip, void *arg)
34997c478bd9Sstevel@tonic-gate {
35007c478bd9Sstevel@tonic-gate dev_info_t *f_dip;
35017c478bd9Sstevel@tonic-gate
35027c478bd9Sstevel@tonic-gate if (dip != ddi_root_node()) {
35037c478bd9Sstevel@tonic-gate f_dip = ndi_devi_find((dev_info_t *)DEVI(dip)->devi_parent,
35047c478bd9Sstevel@tonic-gate DEVI(dip)->devi_node_name, DEVI(dip)->devi_addr);
35057c478bd9Sstevel@tonic-gate if (f_dip != dip) {
35067c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "!pshot_devnode: failed lookup"
35077c478bd9Sstevel@tonic-gate "node (%s/%s@%s)\n",
35087c478bd9Sstevel@tonic-gate DEVI(DEVI(dip)->devi_parent)->devi_node_name,
35097c478bd9Sstevel@tonic-gate (DEVI(dip)->devi_node_name ?
35107c478bd9Sstevel@tonic-gate DEVI(dip)->devi_node_name : "NULL"),
351119397407SSherry Moore (DEVI(dip)->devi_addr ? DEVI(dip)->devi_addr :
351219397407SSherry Moore "NULL"));
35137c478bd9Sstevel@tonic-gate }
35147c478bd9Sstevel@tonic-gate }
35157c478bd9Sstevel@tonic-gate return (DDI_WALK_CONTINUE);
35167c478bd9Sstevel@tonic-gate }
35177c478bd9Sstevel@tonic-gate #endif /* KERNEL_DEVICE_TREE_WALKER */
35187c478bd9Sstevel@tonic-gate
35197c478bd9Sstevel@tonic-gate #ifdef DEBUG
35207c478bd9Sstevel@tonic-gate static void
pshot_event_cb_test(dev_info_t * dip,ddi_eventcookie_t cookie,void * arg,void * bus_impldata)35217c478bd9Sstevel@tonic-gate pshot_event_cb_test(dev_info_t *dip, ddi_eventcookie_t cookie,
35227c478bd9Sstevel@tonic-gate void *arg, void *bus_impldata)
35237c478bd9Sstevel@tonic-gate {
35247c478bd9Sstevel@tonic-gate pshot_t *softstate = (pshot_t *)arg;
35257c478bd9Sstevel@tonic-gate int event_tag;
35267c478bd9Sstevel@tonic-gate
35277c478bd9Sstevel@tonic-gate /* look up the event */
35287c478bd9Sstevel@tonic-gate event_tag = NDI_EVENT_TAG(cookie);
35297c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot_event_cb_test:\n\t"
35307c478bd9Sstevel@tonic-gate "dip = 0x%p cookie = 0x%p (%s), tag = %d\n\t"
35317c478bd9Sstevel@tonic-gate "arg = 0x%p bus_impl = 0x%p\n",
35327c478bd9Sstevel@tonic-gate (void *)dip, (void *)cookie, NDI_EVENT_NAME(cookie),
35337c478bd9Sstevel@tonic-gate event_tag, (void *)softstate, (void *)bus_impldata);
35347c478bd9Sstevel@tonic-gate
35357c478bd9Sstevel@tonic-gate }
35367c478bd9Sstevel@tonic-gate
35377c478bd9Sstevel@tonic-gate static void
pshot_event_test(void * arg)35387c478bd9Sstevel@tonic-gate pshot_event_test(void *arg)
35397c478bd9Sstevel@tonic-gate {
35407c478bd9Sstevel@tonic-gate pshot_t *pshot = (pshot_t *)arg;
35417c478bd9Sstevel@tonic-gate ndi_event_hdl_t hdl;
35427c478bd9Sstevel@tonic-gate ndi_event_set_t events;
35437c478bd9Sstevel@tonic-gate int i, rval;
35447c478bd9Sstevel@tonic-gate
35457c478bd9Sstevel@tonic-gate (void) ndi_event_alloc_hdl(pshot->dip, NULL, &hdl, NDI_SLEEP);
35467c478bd9Sstevel@tonic-gate
35477c478bd9Sstevel@tonic-gate events.ndi_events_version = NDI_EVENTS_REV1;
35487c478bd9Sstevel@tonic-gate events.ndi_n_events = PSHOT_N_TEST_EVENTS;
35497c478bd9Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events;
35507c478bd9Sstevel@tonic-gate
35517c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: binding set of 8 events\n");
35527c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
35537c478bd9Sstevel@tonic-gate rval = ndi_event_bind_set(hdl, &events, NDI_SLEEP);
35547c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval);
35557c478bd9Sstevel@tonic-gate
35567c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: binding the same set of 8 events\n");
35577c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
35587c478bd9Sstevel@tonic-gate rval = ndi_event_bind_set(hdl, &events, NDI_SLEEP);
35597c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval);
35607c478bd9Sstevel@tonic-gate
35617c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding all events\n");
35627c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
35637c478bd9Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP);
35647c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval);
35657c478bd9Sstevel@tonic-gate
35667c478bd9Sstevel@tonic-gate
35677c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: binding one highlevel event\n");
35687c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
35697c478bd9Sstevel@tonic-gate events.ndi_n_events = 1;
35707c478bd9Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events_high;
35717c478bd9Sstevel@tonic-gate rval = ndi_event_bind_set(hdl, &events, NDI_SLEEP);
35727c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval);
35737c478bd9Sstevel@tonic-gate
35747c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: binding the same set of 8 events\n");
35757c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
35767c478bd9Sstevel@tonic-gate events.ndi_n_events = PSHOT_N_TEST_EVENTS;
35777c478bd9Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events;
35787c478bd9Sstevel@tonic-gate rval = ndi_event_bind_set(hdl, &events, NDI_SLEEP);
35797c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval);
35807c478bd9Sstevel@tonic-gate
35817c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding one highlevel event\n");
35827c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
35837c478bd9Sstevel@tonic-gate events.ndi_n_events = 1;
35847c478bd9Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events_high;
35857c478bd9Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP);
35867c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval);
35877c478bd9Sstevel@tonic-gate
35887c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: binding one highlevel event\n");
35897c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
35907c478bd9Sstevel@tonic-gate events.ndi_n_events = 1;
35917c478bd9Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events_high;
35927c478bd9Sstevel@tonic-gate rval = ndi_event_bind_set(hdl, &events, NDI_SLEEP);
35937c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval);
35947c478bd9Sstevel@tonic-gate
35957c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding one highlevel event\n");
35967c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
35977c478bd9Sstevel@tonic-gate events.ndi_n_events = 1;
35987c478bd9Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events_high;
35997c478bd9Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP);
36007c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval);
36017c478bd9Sstevel@tonic-gate
36027c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: binding the same set of 8 events\n");
36037c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
36047c478bd9Sstevel@tonic-gate events.ndi_n_events = PSHOT_N_TEST_EVENTS;
36057c478bd9Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events;
36067c478bd9Sstevel@tonic-gate rval = ndi_event_bind_set(hdl, &events, NDI_SLEEP);
36077c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval);
36087c478bd9Sstevel@tonic-gate
36097c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding first 2 events\n");
36107c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
36117c478bd9Sstevel@tonic-gate events.ndi_n_events = 2;
36127c478bd9Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events;
36137c478bd9Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP);
36147c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval);
36157c478bd9Sstevel@tonic-gate
36167c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding first 2 events again\n");
36177c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
36187c478bd9Sstevel@tonic-gate events.ndi_n_events = 2;
36197c478bd9Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events;
36207c478bd9Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP);
36217c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval);
36227c478bd9Sstevel@tonic-gate
36237c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding middle 2 events\n");
36247c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
36257c478bd9Sstevel@tonic-gate events.ndi_n_events = 2;
36267c478bd9Sstevel@tonic-gate events.ndi_event_defs = &pshot_test_events[4];
36277c478bd9Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP);
36287c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval);
36297c478bd9Sstevel@tonic-gate
36307c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: binding those 2 events back\n");
36317c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
36327c478bd9Sstevel@tonic-gate events.ndi_n_events = 2;
36337c478bd9Sstevel@tonic-gate events.ndi_event_defs = &pshot_test_events[4];
36347c478bd9Sstevel@tonic-gate rval = ndi_event_bind_set(hdl, &events, NDI_SLEEP);
36357c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval);
36367c478bd9Sstevel@tonic-gate
36377c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding 2 events\n");
36387c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
36397c478bd9Sstevel@tonic-gate events.ndi_n_events = 2;
36407c478bd9Sstevel@tonic-gate events.ndi_event_defs = &pshot_test_events[4];
36417c478bd9Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP);
36427c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval);
36437c478bd9Sstevel@tonic-gate
36447c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding all events\n");
36457c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
36467c478bd9Sstevel@tonic-gate events.ndi_n_events = PSHOT_N_TEST_EVENTS;
36477c478bd9Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events;
36487c478bd9Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP);
36497c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval);
36507c478bd9Sstevel@tonic-gate
36517c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding 1 event\n");
36527c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
36537c478bd9Sstevel@tonic-gate events.ndi_n_events = 1;
36547c478bd9Sstevel@tonic-gate events.ndi_event_defs = &pshot_test_events[2];
36557c478bd9Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP);
36567c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval);
36577c478bd9Sstevel@tonic-gate
36587c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding 1 event\n");
36597c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
36607c478bd9Sstevel@tonic-gate events.ndi_n_events = 1;
36617c478bd9Sstevel@tonic-gate events.ndi_event_defs = &pshot_test_events[3];
36627c478bd9Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP);
36637c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval);
36647c478bd9Sstevel@tonic-gate
36657c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding 1 event\n");
36667c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
36677c478bd9Sstevel@tonic-gate events.ndi_n_events = 1;
36687c478bd9Sstevel@tonic-gate events.ndi_event_defs = &pshot_test_events[6];
36697c478bd9Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP);
36707c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval);
36717c478bd9Sstevel@tonic-gate
36727c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: unbinding 1 event\n");
36737c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
36747c478bd9Sstevel@tonic-gate events.ndi_n_events = 1;
36757c478bd9Sstevel@tonic-gate events.ndi_event_defs = &pshot_test_events[7];
36767c478bd9Sstevel@tonic-gate rval = ndi_event_unbind_set(hdl, &events, NDI_SLEEP);
36777c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_unbind_set rval = %d\n", rval);
36787c478bd9Sstevel@tonic-gate
36797c478bd9Sstevel@tonic-gate events.ndi_n_events = PSHOT_N_TEST_EVENTS;
36807c478bd9Sstevel@tonic-gate events.ndi_event_defs = pshot_test_events;
36817c478bd9Sstevel@tonic-gate
36827c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: binding set of 8 events\n");
36837c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
36847c478bd9Sstevel@tonic-gate rval = ndi_event_bind_set(hdl, &events, NDI_SLEEP);
36857c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: ndi_event_bind_set rval = %d\n", rval);
36867c478bd9Sstevel@tonic-gate
36877c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: adding 8 callbacks\n");
36887c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
36897c478bd9Sstevel@tonic-gate for (i = 0; i < 8; i++) {
36907c478bd9Sstevel@tonic-gate rval = ndi_event_add_callback(hdl, pshot->dip,
36917c478bd9Sstevel@tonic-gate ndi_event_tag_to_cookie(hdl,
36927c478bd9Sstevel@tonic-gate pshot_test_events[i].ndi_event_tag),
36937c478bd9Sstevel@tonic-gate pshot_event_cb_test,
36947c478bd9Sstevel@tonic-gate (void *)(uintptr_t)pshot_test_events[i].ndi_event_tag,
36957c478bd9Sstevel@tonic-gate NDI_SLEEP, &pshot->test_callback_cache[i]);
36967c478bd9Sstevel@tonic-gate ASSERT(rval == NDI_SUCCESS);
36977c478bd9Sstevel@tonic-gate }
36987c478bd9Sstevel@tonic-gate
36997c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: event callbacks\n");
37007c478bd9Sstevel@tonic-gate
37017c478bd9Sstevel@tonic-gate for (i = 10; i < 18; i++) {
37027c478bd9Sstevel@tonic-gate ddi_eventcookie_t cookie = ndi_event_tag_to_cookie(hdl, i);
37037c478bd9Sstevel@tonic-gate
37047c478bd9Sstevel@tonic-gate rval = ndi_event_run_callbacks(hdl, pshot->dip, cookie,
37057c478bd9Sstevel@tonic-gate (void *)hdl);
37067c478bd9Sstevel@tonic-gate
37077c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: callback, tag=%d rval=%d\n",
37087c478bd9Sstevel@tonic-gate i, rval);
37097c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
37107c478bd9Sstevel@tonic-gate }
37117c478bd9Sstevel@tonic-gate
37127c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: redo event callbacks\n");
37137c478bd9Sstevel@tonic-gate
37147c478bd9Sstevel@tonic-gate for (i = 10; i < 18; i++) {
37157c478bd9Sstevel@tonic-gate ddi_eventcookie_t cookie = ndi_event_tag_to_cookie(hdl, i);
37167c478bd9Sstevel@tonic-gate
37177c478bd9Sstevel@tonic-gate rval = ndi_event_run_callbacks(hdl,
37187c478bd9Sstevel@tonic-gate pshot->dip, cookie, (void *)hdl);
37197c478bd9Sstevel@tonic-gate
37207c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: callback, tag=%d rval=%d\n",
37217c478bd9Sstevel@tonic-gate i, rval);
37227c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
37237c478bd9Sstevel@tonic-gate }
37247c478bd9Sstevel@tonic-gate
37257c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: removing 8 callbacks\n");
37267c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
37277c478bd9Sstevel@tonic-gate
37287c478bd9Sstevel@tonic-gate for (i = 0; i < 8; i++) {
37297c478bd9Sstevel@tonic-gate (void) ndi_event_remove_callback(hdl,
37307c478bd9Sstevel@tonic-gate pshot->test_callback_cache[i]);
37317c478bd9Sstevel@tonic-gate
37327c478bd9Sstevel@tonic-gate pshot->test_callback_cache[i] = 0;
37337c478bd9Sstevel@tonic-gate }
37347c478bd9Sstevel@tonic-gate
37357c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot: freeing handle with bound set\n");
37367c478bd9Sstevel@tonic-gate delay(drv_usectohz(1000000));
37377c478bd9Sstevel@tonic-gate
37387c478bd9Sstevel@tonic-gate rval = ndi_event_free_hdl(hdl);
37397c478bd9Sstevel@tonic-gate
37407c478bd9Sstevel@tonic-gate ASSERT(rval == NDI_SUCCESS);
37417c478bd9Sstevel@tonic-gate
37427c478bd9Sstevel@tonic-gate }
37437c478bd9Sstevel@tonic-gate
37447c478bd9Sstevel@tonic-gate void
pshot_event_test_post_one(void * arg)37457c478bd9Sstevel@tonic-gate pshot_event_test_post_one(void *arg)
37467c478bd9Sstevel@tonic-gate {
37477c478bd9Sstevel@tonic-gate pshot_t *pshot = (pshot_t *)arg;
37487c478bd9Sstevel@tonic-gate int rval;
37497c478bd9Sstevel@tonic-gate ddi_eventcookie_t cookie;
37507c478bd9Sstevel@tonic-gate
37517c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: pshot_event_post_one event\n",
37527c478bd9Sstevel@tonic-gate pshot->instance);
37537c478bd9Sstevel@tonic-gate
37547c478bd9Sstevel@tonic-gate if (ddi_get_eventcookie(pshot->dip, PSHOT_EVENT_NAME_BUS_TEST_POST,
37557c478bd9Sstevel@tonic-gate &cookie) != DDI_SUCCESS) {
37567c478bd9Sstevel@tonic-gate cmn_err(CE_NOTE, "pshot_bus_test_post cookie not found");
37577c478bd9Sstevel@tonic-gate return;
37587c478bd9Sstevel@tonic-gate }
37597c478bd9Sstevel@tonic-gate
37607c478bd9Sstevel@tonic-gate rval = ndi_post_event(pshot->dip, pshot->dip, cookie, NULL);
37617c478bd9Sstevel@tonic-gate
37627c478bd9Sstevel@tonic-gate cmn_err(CE_CONT, "pshot%d: pshot_event_post_one rval=%d\n",
37637c478bd9Sstevel@tonic-gate pshot->instance, rval);
37647c478bd9Sstevel@tonic-gate
37657c478bd9Sstevel@tonic-gate (void) timeout(pshot_event_test_post_one, (void *)pshot,
37667c478bd9Sstevel@tonic-gate pshot->instance * drv_usectohz(60000000));
37677c478bd9Sstevel@tonic-gate
37687c478bd9Sstevel@tonic-gate }
37697c478bd9Sstevel@tonic-gate #endif /* DEBUG */
3770