/*
* 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
*/
/*
* Copyright 2008 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* generic character driver
*/
#define MINPWR 0
/*
* The state for each generic device.
* NOTE: We save the node_type in the state structure. The node_type string
* (and not a copy) is stashed in a minor node by ddi_create_minor_node(),
* so ddi_remove_minor_node() must occur prior to state free.
*/
typedef struct dstate {
char *nodename;
} dstate_t;
static void *dstates;
static int gen_debug = 0;
#ifdef DEBUG
static int gen_debug_on = 0;
#else
#endif
extern void prom_printf(const char *fmt, ...);
void **result);
static int gen_power(dev_info_t *, int, int);
gen_open, /* open */
gen_close, /* close */
nodev, /* strategy */
nodev, /* print */
nodev, /* dump */
gen_read, /* read */
gen_write, /* write */
gen_ioctl, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
ddi_prop_op, /* prop_op */
NULL, /* streamtab */
CB_REV, /* cb_rev */
nodev, /* aread */
nodev /* awrite */
};
DEVO_REV, /* devo_rev */
0, /* refcnt */
gen_info, /* getinfo */
nulldev, /* identify */
nulldev, /* probe */
gen_attach, /* attach */
gen_detach, /* detach */
nodev, /* reset */
&gen_cb_ops, /* driver ops */
(struct bus_ops *)0, /* bus ops */
gen_power, /* power */
ddi_quiesce_not_supported, /* devo_quiesce */
};
/*
* INST_TO_MINOR() gives the starting minor number for a given gen_drv driver
* instance. A shift left by 6 bits allows for each instance to have upto
* 64 (2^6) minor numbers. The maximum minor number allowed by the system
* is L_MAXMIN32 (0x3ffff). This effectively limits the gen_drv instance
* numbers from 0 to 0xfff for a total of 4096 instances.
*/
static char *mnodetypes[] = {
"ddi_nt",
"ddi_nt:device_type",
"ddi_nt:device_class:bus_class",
"ddi_nt2",
"ddi_nt2:device_type",
"ddi_nt2:device_type:bus_class",
};
"generic test driver",
};
};
/*
* flags
*/
/*
* ioctl commands (non-devctl ioctl commands)
*/
int
_init(void)
{
int e;
if ((e = ddi_soft_state_init(&dstates,
sizeof (struct dstate), 0)) != 0) {
return (e);
}
if ((e = mod_install(&modlinkage)) != 0) {
}
return (e);
}
int
_fini(void)
{
int e;
if ((e = mod_remove(&modlinkage)) != 0) {
return (e);
}
return (e);
}
int
{
}
static int
{
int rval;
int n_devs;
int n_minorcomps;
int isclone;
int i_init = 0;
int level_tmp;
int i;
char *pm_comp[] = {
"NAME=leaf0",
"0=D0",
"1=D1",
"2=D2",
"3=D3",
"NAME=leaf1",
"0=off",
"1=blank",
"2=on"};
switch (cmd) {
case DDI_ATTACH:
DDI_SUCCESS) {
return (DDI_FAILURE);
}
"ndevs", 1);
"isclone", 0);
"ncomps", 1);
"%s%d attaching: n_devs=%d n_minorcomps=%d isclone=%d",
if (isclone) {
isclone) != DDI_SUCCESS) {
return (DDI_FAILURE);
}
rval = DDI_SUCCESS;
} else {
if (rval != DDI_SUCCESS) {
return (DDI_FAILURE);
}
}
&dev_offline_cookie) == DDI_SUCCESS) {
}
&dev_reset_cookie) == DDI_SUCCESS) {
}
&bus_reset_cookie) == DDI_SUCCESS) {
}
&bus_quiesce_cookie) == DDI_SUCCESS) {
}
&bus_unquiesce_cookie) == DDI_SUCCESS) {
(void) ddi_add_event_handler(devi,
}
&bus_test_post_cookie) == DDI_SUCCESS) {
(void) ddi_add_event_handler(devi,
}
/*
* initialize the devices' pm state
*/
/*
* stash the nodename
*/
/*
* Check if the no-involuntary-power-cycles property
* was created. Set NO_INVOL_FLAG if so.
*/
"no-involuntary-power-cycles") == 1) {
"%s%d: DDI_ATTACH:\n\tno-involuntary-power-cycles"
" property was created",
}
/*
* Check if the dependency-property property
* was created.
*/
"dependency-property") == 1) {
"%s%d: DDI_ATTACH:\n\tdependency-property"
" property was created",
}
/*
* create the pm-components property. two comps:
* 4 levels on comp0, 3 on comp 1.
* - skip for a "tape" device, clear PM_SUPPORTED_FLAG
*/
"unable to create \"pm-components\" "
" property.");
return (DDI_FAILURE);
}
} else {
}
/*
* Check if the pm-components property was created
*/
"pm-components") != 1) {
"\"pm-components\" property does"
" not exist");
return (DDI_FAILURE);
} else {
" created pm-components property",
ddi_get_instance(devi)));
}
}
/*
* create the pm-hardware-state property.
* needed to get DDI_SUSPEND and DDI_RESUME calls
*/
"unable to create \"pm-hardware-state\" "
" property.");
return (DDI_FAILURE);
}
/*
* set power levels to max via pm_raise_power(),
*/
for (i = i_init; i < COMPONENTS; i++) {
"%s%d: DDI_ATTACH: pm_raise_power comp %d "
DDI_SUCCESS) {
"%s%d: DDI_ATTACH: pm_raise_power failed\n",
return (DDI_FAILURE);
}
}
if (rval == DDI_SUCCESS) {
}
return (rval);
case DDI_RESUME:
ddi_get_instance(devi)));
return (DDI_FAILURE);
}
/*
* Call pm_power_has_changed() if flag
* PWR_HAS_CHANGED_ON_RESUME_FLAG is set,
* then clear the flag
*/
for (i = i_init; i < COMPONENTS; i++) {
"%s%d: DDI_RESUME: pm_power_has_changed "
maxpwr[i]) != DDI_SUCCESS) {
"%s%d: DDI_RESUME:\n\t"
" pm_power_has_changed"
" failed: comp %d to level %d\n",
i, maxpwr[i]);
}
}
} else {
/*
* Call pm_raise_power() instead
*/
for (i = i_init; i < COMPONENTS; i++) {
"%s%d: DDI_RESUME: pm_raise_power"
" comp %d to level %d",
i, maxpwr[i]));
!= DDI_SUCCESS) {
"%s%d: DDI_RESUME:"
"\n\tpm_raise_power"
"failed: comp %d to level %d\n",
i, maxpwr[i]);
}
}
}
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
}
static int
{
int instance;
int i;
int rv;
int rm_power;
int level_tmp;
#ifdef DEBUG
int n_devs;
int n_minorcomps;
int isclone;
#endif
switch (cmd) {
case DDI_DETACH:
ddi_get_instance(devi)));
return (DDI_FAILURE);
}
#ifdef DEBUG
"ndevs", 1);
"isclone", 0);
"ncomps", 1);
#endif /* DEBUG */
/*
* power off component 1.
*/
"%s%d: DDI_DETACH: pm_lower_power comp 1 level %d",
MINPWR));
!= DDI_SUCCESS) {
"pm_lower_power failed for comp 1 to"
return (DDI_FAILURE);
}
/*
* check power level. Issue pm_power_has_changed
* if not at MINPWR.
*/
" power off via pm_power_has_changed"
ddi_get_instance(devi)));
" pm_power_has_changed failed for"
" comp 1 to level %d",
MINPWR));
return (DDI_FAILURE);
}
}
}
/*
* If the LOWER_POWER_FLAG flag is not set,
* don't call pm_lowr_power() for comp 0.
* This should be used only for the XXXXX@XX,no_invol
* devices that export the
* no-involuntary-power-cycles property
*/
" NOT CALLING PM_LOWER_POWER():"
" LOWER_POWER_FLAG NOT SET\n",
"%s%d: DDI_DETACH: pm_lower_power comp 0 level %d",
MINPWR));
!= DDI_SUCCESS) {
"pm_lower_power failed for comp 0 to"
return (DDI_FAILURE);
}
/*
* check power level. Issue pm_power_has_changed
* if not at MINPWR.
*/
" power off via pm_power_has_changed"
ddi_get_instance(devi)));
0, MINPWR) != DDI_SUCCESS) {
" pm_power_has_changed failed for"
" comp 0 to level %d",
MINPWR));
return (DDI_FAILURE);
}
}
}
"%s%d detaching: n_devs=%d n_minorcomps=%d isclone=%d",
for (i = 0; i < NUMEVENTS; i++) {
if (dstatep->gen_cb_ids[i]) {
}
}
return (DDI_SUCCESS);
case DDI_SUSPEND:
return (DDI_FAILURE);
}
/*
* fail the suspend if FAIL_SUSPEND_FLAG is set.
* clear the FAIL_SUSPEND_FLAG flag
*/
" FAIL_SUSPEND_FLAG is set,"
" fail suspend",
rv = DDI_FAILURE;
} else {
rv = DDI_SUCCESS;
}
/*
* Issue ddi_removing_power() to determine if the suspend
* was initiated by either CPR or DR. If CPR, the system
* will be powered OFF; if this driver has set the
* NO_INVOL_FLAG, then refuse to suspend. If DR, power
* will not be removed, thus allow the suspend.
*/
" check via ddi_removing_power()",
if (rm_power < 0) {
" ddi_removing_power() failed\n",
} else if (rm_power == 1) {
/*
* CPR: power will be removed
*/
" CPR: POWER WILL BE REMOVED, THEREFORE"
ddi_get_instance(devi)));
rv = DDI_FAILURE;
} else if (rm_power == 0) {
/*
* DR: power will not be removed
*/
" DR: POWER WILL NOT BE REMOVED, THEREFORE"
ddi_get_instance(devi)));
rv = DDI_SUCCESS;
}
}
/*
* power OFF via pm_power_has_changed()
*/
"%s%d: DDI_SUSPEND: pm_power_has_changed comp 0"
!= DDI_SUCCESS) {
"pm_power_has_changed failed for comp 0 to"
return (DDI_FAILURE);
}
}
return (rv);
default:
return (DDI_FAILURE);
}
}
/* ARGSUSED */
static int
{
int instance;
if (infocmd != DDI_INFO_DEVT2INSTANCE)
return (DDI_FAILURE);
return (DDI_SUCCESS);
}
/*ARGSUSED*/
static int
{
return (EINVAL);
return (ENXIO);
"%s%d open",
return (0);
}
/*ARGSUSED*/
static int
{
return (EINVAL);
return (ENXIO);
"%s%d close",
return (0);
}
/*ARGSUSED*/
static int
{
int instance;
int rval = 0;
char *nodename;
int i;
int ret;
int level_tmp;
return (ENXIO);
/*
* read devctl ioctl data
*/
return (EFAULT);
switch (cmd) {
case GENDRV_IOFAULT_SIMULATE:
&(cookie)) != NDI_SUCCESS)
return (DDI_FAILURE);
NULL));
case GENDRV_NDI_EVENT_TEST:
&cookie) == NDI_SUCCESS) {
}
&cookie) == NDI_SUCCESS) {
}
&cookie) == NDI_SUCCESS) {
}
&cookie) == NDI_SUCCESS) {
}
&cookie) == NDI_SUCCESS) {
}
&cookie) == NDI_SUCCESS) {
}
break;
/*
* Issue pm_power_has_changed() call on DDI_RESUME
*/
" DEVCTL_PM_PWR_HAS_CHANGED_ON_RESUME", nodename,
instance));
break;
case DEVCTL_PM_FAIL_SUSPEND:
/*
* Fail the suspend attempt in DDI_SUSPEND
*/
break;
/*
* Use pm_power_has_changed() to power up comp 0 when
* enforcing the comp 0 vs comp-not 0 dependency:
* Power up comp 0 first, if request for comp-not-0
* comes in.
* Else, default to pm_raise_power().
*/
break;
case DEVCTL_PM_BUSY_COMP:
/*
* mark component 0 busy via a pm_busy_component() call.
* update the busy[] array.
*/
break;
case DEVCTL_PM_BUSY_COMP_TEST:
/*
* test busy state on component 0
*/
sizeof (uint_t)) != 0) {
" DEVCTL_PM_BUSY_COMP_TEST: copyout failed\n",
}
" comp 0 busy %d",
break;
case DEVCTL_PM_IDLE_COMP:
/*
* mark component 0 idle via a pm_idle_component() call.
* NOP if dstatep->busy[0] == 0.
*/
} else {
}
break;
case DEVCTL_PM_PROM_PRINTF:
(void) prom_printf("%s%d: PROM_PRINTF FROM GEN_DRV\n",
break;
case DEVCTL_PM_RAISE_PWR:
/*
* power up both components to MAXPWR via
* pm_raise_power() calls. this ioctl() cmd
* assumes that the current level is 0
*/
for (i = 0; i < COMPONENTS; i++) {
" comp %d old 0 new %d",
!= DDI_SUCCESS) {
}
}
break;
case DEVCTL_PM_CHANGE_PWR_LOW:
/*
* power off both components via pm_power_has_changed() calls
*/
for (i = (COMPONENTS - 1); i >= 0; --i) {
" comp %d new 0",
!= DDI_SUCCESS) {
}
}
break;
/*
* power up both components to MAXPWR via
* pm_power_has_changed() calls
*/
for (i = 0; i < COMPONENTS; i++) {
" comp %d new %d",
!= DDI_SUCCESS) {
}
}
break;
case DEVCTL_PM_POWER:
/*
* test if the gen_drv_power() routine has been called,
* then clear
*/
sizeof (uint_t)) != 0) {
}
break;
case DEVCTL_PM_NO_LOWER_POWER:
/*
* issue to not invoke pm_lower_power() on detach
*/
break;
default:
return (ENOTTY);
}
return (rval);
}
/*ARGSUSED*/
static int
{
return (0);
}
/*ARGSUSED*/
static int
{
return (0);
}
/*ARGSUSED0*/
static int
{
int level_tmp;
return (DDI_FAILURE);
}
/*
* Keep track of the power levels for both components
* in the dstatep->comp[] array.
* Set comp 0 to full level if non-zero comps
* are being set to a higher, non-zero level.
*/
if (cmpt == 0) {
/*
* If component 0 is not at COMP_0_MAXPWR, and component 1
* is being powered ON, invoke pm_raise_power() or
* pm_power_has_changed() based on the
* PUP_WITH_PWR_HAS_CHANGED_FLAG flag.
* PUP_WITH_PWR_HAS_CHANGED_FLAG = FALSE by default, invoking
* pm_raise_power().
*/
/*
* first set comp 0 to level COMP_0_MAXPWR
*/
"pm_raise_power: comp 0 to level %d",
DDI_SUCCESS) {
"%s%d: power: pm_raise_power() "
"failed: comp 0 to level %d\n",
return (DDI_FAILURE);
} else {
/*
* now set the level on the non-zero comp
*/
"comp %d to level %d",
}
} else {
"pm_power_has_changed: comp 0 to level %d",
DDI_SUCCESS) {
"%s%d: power: pm_power_has_changed() "
"failed: comp 0 to level %d\n",
} else {
/*
* now set the level on the non-zero comp
*/
" pm_power_has_changed: comp %d"
}
}
} else {
}
return (DDI_SUCCESS);
}
/*
* Create properties of various data types for testing devfs events.
*/
static int
{
"Dev_node_prop:1", "Dev_node_prop:2", "Dev_node_prop:3"};
!= DDI_PROP_SUCCESS)
return (DDI_FAILURE);
return (DDI_FAILURE);
!= DDI_PROP_SUCCESS)
return (DDI_FAILURE);
!= DDI_PROP_SUCCESS)
return (DDI_FAILURE);
!= DDI_PROP_SUCCESS)
return (DDI_FAILURE);
string_array, sizeof (string_array) / sizeof (char *))
!= DDI_PROP_SUCCESS)
return (DDI_FAILURE);
return (DDI_FAILURE);
return (DDI_FAILURE);
/* untyped property */
return (DDI_FAILURE);
return (DDI_SUCCESS);
}
static struct driver_minor_data {
char *name;
int type;
} disk_minor_data[] = {
{"a", 0, S_IFBLK},
{"a,raw", 0, S_IFCHR},
{0}
};
static struct driver_serial_minor_data {
char *name;
int type;
char *node_type;
} serial_minor_data[] = {
{0}
};
static int
{
}
static int
{
return (DDI_FAILURE);
return (DDI_FAILURE);
}
}
return (DDI_SUCCESS);
}
static uint_t
atod(char *s)
{
while (*s) {
if (*s >= '0' && *s <= '9')
digit = *s++ - '0';
else
break;
}
return (val);
}
static int
{
} else { /* this hack is for rm_stale_link() testing */
target = 10;
lun = 5;
}
!= DDI_PROP_SUCCESS) {
return (DDI_FAILURE);
}
!= DDI_PROP_SUCCESS) {
return (DDI_FAILURE);
}
return (DDI_FAILURE);
}
}
return (DDI_SUCCESS);
}
static int
{
return (DDI_FAILURE);
}
}
return (DDI_SUCCESS);
}
static int
{
return (DDI_FAILURE);
}
}
return (DDI_SUCCESS);
}
static int
{
return (DDI_FAILURE);
}
}
return (DDI_SUCCESS);
}
static int
{
return (DDI_FAILURE);
}
static int
{
char *node_name;
} else {
char *node_type;
/*
* Solaris may directly hang the node_type off the minor node
* (without making a copy). Since we free the node_type
* property below we need to make a private copy to pass
* to ddi_create_minor_node to avoid devinfo snapshot panics.
* We store a pointer to our copy in dstate and free it in
* gen_detach after the minor nodes have been deleted by
* ddi_remove_minor_node.
*/
return (DDI_FAILURE);
}
if (node_type) {
}
/* the minor name is the same as the node name */
DDI_SUCCESS) {
}
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
if (rval != DDI_SUCCESS) {
}
return (rval);
}
/*ARGSUSED*/
static void
void *impl_data)
{
if (gen_debug)
}