/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* devctl - device control utility
*
* to compile:
* cc -o devctl -ldevice -ldevinfo devctl.c
*
*
* Commands:
* list - list all controllers exporting the devctl interface
* online - online a device
* offline - offline a device
* remove - remove a device from the device tree
* quiesce - quiesce the bus
* unquiesce - resume bus activity
* configure - configure a bus's child devices
* unconfigure - unconfigure a bus's child devices
* bus-reset - reset a bus
* dev-reset - reset a device
* bus-getstate - return the current state of the bus
* dev-getstate - return the current state of the device
* bus-devcreate - create a new device, bus specific
* dev-raisepower - power up a device via pm_raise_power() (pm)
* dev-idlecomp - idle a device's component 0 (pm)
* dev-busycomp - busy a device's component 0 (pm)
* dev-testbusy - test a device's component 0's busy state (pm)
* dev-changepowerhigh - power up a device via pm_power_has_changed()
* (pm)
* dev-changepowerlow - power off a device via pm_power_has_changed()
* (pm)
* dev-failsuspend - fail DDI_SUSPEND (pm)
* dev-changeonresume - issue pm_power_has_changed() vs,
* pm_raise_power() on device resume (pm)
* dev-nolowerpower - don't call pm_lower_power() on detach (pm)
* dev-promprintf - issue a prom_printf() call (pm)
* bus-raisepower - power up a bus via pm_raise_power() (pm)
* bus-idlecomp - idle a bus' component (pm)
* bus-busycomp - busy a bus' component (pm)
* bus-testbusy - test a bus' component busy state (pm)
* bus-changepowerhigh - power up a bus via pm_power_has_changed() (pm)
* bus-changepowerlow - power off a bus via pm_power_has_changed()
* (pm)
* bus-failsuspend - fail DDI_SUSPEND (pm)
* bus-teststrict - test is bus driver is strict or involved (pm)
* bus-noinvol - mark idle twice when child detaches
*
*
* Returns:
* - Success
* - Operation not supported by device
* - No Permission
* - No Such Device
*
* Examples:
* devctl list - list all controllers exporting a :devctl node
* sd@3,0
*
*/
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include <libdevice.h>
#include <libdevinfo.h>
typedef struct cmds {
char *cmdname;
} cmds_t;
extern int errno;
static int dev_getstate(devctl_hdl_t);
static int bus_getstate(devctl_hdl_t);
static int bus_devcreate(devctl_hdl_t);
static void run_list_ctlrs(void);
static char *s_strdup(char *);
static int dev_pm_testbusy(devctl_hdl_t);
static int bus_pm_teststrict(devctl_hdl_t);
static char *devctl_device;
static char *orig_path;
static char *devctl_cmdname;
static char *progname;
static int verbose;
static int debug;
static char *dev_name;
static char **dev_props;
"\tquiesce | unquiesce | configure | unconfigure |\n"
"\t{bus,dev}-reset {bus,dev}-getstate | {bus,dev}-raisepower |\n"
"\t{bus,dev}-idlecomp | {bus,dev}-busycomp |\n"
"\t{bus,dev}-changepowerhigh | {bus,dev}-changepowerlow |\n"
"\t{bus,dev}-testbusy | {bus,dev}-failsuspend | dev-changeonresume |\n"
"\tdev-promprintf | dev-nolowerpower | bus-teststrict |\n"
"\tbus-noinvol [/dev/... | /devices/...]\n";
{"online", devctl_device_online},
{"offline", devctl_device_offline},
{"remove", devctl_device_remove},
{"dev-reset", devctl_device_reset},
{"dev-getstate", dev_getstate},
{"dev-raisepower", devctl_pm_raisepower},
{"dev-busycomp", devctl_pm_busycomponent},
{"dev-idlecomp", devctl_pm_idlecomponent},
{"dev-testbusy", dev_pm_testbusy},
{"dev-changepowerlow", devctl_pm_changepowerlow},
{"dev-changepowerhigh", devctl_pm_changepowerhigh},
{"dev-failsuspend", devctl_pm_failsuspend},
{"dev-changeonresume", devctl_pm_device_changeonresume},
{"dev-promprintf", devctl_pm_device_promprintf},
{"dev-nolowerpower", devctl_pm_device_no_lower_power},
};
{"quiesce", devctl_bus_quiesce},
{"unquiesce", devctl_bus_unquiesce},
{"bus-reset", devctl_bus_reset},
{"configure", devctl_bus_configure},
{"unconfigure", devctl_bus_unconfigure},
{"bus-getstate", bus_getstate},
{"bus-devcreate", bus_devcreate},
{"bus-raisepower", devctl_pm_raisepower},
{"bus-busycomp", devctl_pm_busycomponent},
{"bus-idlecomp", devctl_pm_idlecomponent},
{"bus-changepowerlow", devctl_pm_changepowerlow},
{"bus-changepowerhigh", devctl_pm_changepowerhigh},
{"bus-testbusy", dev_pm_testbusy},
{"bus-failsuspend", devctl_pm_failsuspend},
{"bus-teststrict", bus_pm_teststrict},
{"bus-noinvol", devctl_pm_bus_no_invol},
};
int
{
int c;
int rv;
int pathlen;
switch (c) {
case 'v':
++verbose;
break;
case 'd':
++debug;
(void) putenv("LIBDEVICE_DEBUG");
break;
default:
exit(1);
/*NOTREACHED*/
}
}
exit(-1);
}
exit(0);
}
/*
* any command other than "list" requires a device path
*/
exit(-1);
}
/*
* Additional properties follow for bus-devcreate
*/
int i;
optind++;
while (--i) {
}
}
/*
* if the device is a logical name, get the physical name
*/
MAXPATHLEN)) == -1) {
"devctl: readlink(%s) - %s\n",
exit(-1);
}
}
}
exit(1);
"devctl: device_pm_bus_acquire %s - %s\n",
exit(-1);
}
} else {
"%s - %s\n",
exit(-1);
}
}
"devctl: device_pm_dev_acquire %s - %s\n",
exit(-1);
}
} else {
"devctl: device_acquire %s - %s\n",
exit(-1);
}
}
if (verbose)
(void) printf("devctl: cmd (%s) device (%s)\n",
if (rv == -1) {
perror("devctl");
exit(-1);
}
return (0);
} /* main */
static int
{
int rv;
if (rv != -1)
return (0);
}
static int
{
int rv;
if (rv != -1)
return (0);
}
static int
{
int rv;
if (rv != -1)
return (0);
}
static int
{
int rv;
if (rv != -1)
return (0);
}
/*
* Only string property is supported now.
* Will add more later.
*/
static void
{
int nstr;
exit(-1);
}
*tmp++ = '\0';
if (*tmp != '"') {
return;
}
nstr = 0;
while (*tmp != '\0') {
exit(-1);
}
nstr++;
*tmp++ = '\0';
if (*tmp)
exit(-1);
}
}
}
static int
{
int rv;
return (-1);
}
while (*propp) {
propp++;
}
"bus-devcreate: failed to create device node\n");
rv = -1;
== NULL) {
"bus-devcreate: failed to get device path\n");
rv = -1;
} else {
rv = 0;
}
if (dev_hdl)
return (rv);
}
static void
{
if (state == BUS_QUIESCED)
(void) printf("Quiesced");
else if (state == BUS_ACTIVE)
(void) printf("Active");
else if (state == BUS_SHUTDOWN)
(void) printf("Shutdown");
(void) printf("\n");
}
static void
{
if (state & DEVICE_ONLINE) {
(void) printf("Online");
if (state & DEVICE_BUSY)
(void) printf(" Busy");
if (state & DEVICE_DOWN)
(void) printf(" Down");
} else {
if (state & DEVICE_OFFLINE) {
(void) printf("Offline");
if (state & DEVICE_DOWN)
(void) printf(" Down");
}
}
(void) printf("\n");
}
static void
{
register char *p;
progname = p + 1;
else
}
static struct cmds *
{
int i;
return (&cmd_tbl[i]);
}
return (NULL);
}
/*
* list all nexus drivers exporting the :devctl minor device
*/
static void
run_list_ctlrs(void)
{
progname);
exit(-1);
}
exit(0);
}
/*ARGSUSED*/
static int
{
char *devname;
}
return (DI_WALK_CONTINUE);
}
void *
{
perror("s_malloc failed");
exit(-1);
}
return (buf);
}
void *
{
perror("s_realloc failed");
exit(-1);
}
return (buf);
}
char *
{
perror("s_malloc failed");
exit(-1);
}
return (buf);
}