cpr_driver.c revision 2df1fe9ca32bb227b9158c67f5c00b54c20b10fd
/*
* 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 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* CPR driver support routines
*/
#include <sys/ddi_impldefs.h>
#define CPR_BUFSIZE 128
extern int devi_detach(dev_info_t *, int);
extern int devi_attach(dev_info_t *, int);
static char *devi_string(dev_info_t *, char *);
static int cpr_is_real_device(dev_info_t *);
/*
* Xen uses this code to suspend _all_ drivers quickly and easily.
* Suspend and Resume uses it for the same reason, but also has
* to contend with some platform specific code that Xen does not.
* it is also used as a test entry point for developers/testers to
* execute code without going through a complete suspend. So additions
* that have platform implications shall need #if[n]def's.
*/
#ifndef __xpv
extern void i_cpr_save_configuration(dev_info_t *);
extern void i_cpr_restore_configuration(dev_info_t *);
#endif
/*
* Traverse the dev info tree:
* Call each device driver in the system via a special case
* of the detach() entry point to quiesce itself.
* Suspend children first.
*
*/
int
{
int error;
char buf[CPR_BUFSIZE];
return (ENXIO);
if (!cpr_is_real_device(dip))
continue;
#ifndef __xpv
#endif
if (!i_ddi_devi_attached(dip)) {
error = DDI_FAILURE;
} else {
#ifndef __xpv
if (cpr_test_point != DEVICE_SUSPEND_TO_RAM ||
#endif
#ifndef __xpv
} else {
error = DDI_SUCCESS;
}
#endif
}
if (error == DDI_SUCCESS) {
}
else {
"WARNING: Unable to suspend device %s\n",
#ifndef __xpv
/*
* the device has failed to suspend however,
* if cpr_test_point == FORCE_SUSPEND_TO_RAM
* after putting out the warning message above,
* we carry on as if suspending the device had
* been successful
*/
if (cpr_test_point == FORCE_SUSPEND_TO_RAM)
else
#endif
return (ENXIO);
}
}
return (0);
}
/*
* Traverse the dev info tree:
* Call each device driver in the system via a special case
* of the attach() entry point to restore itself.
* This is a little tricky because it has to reverse the traversal
* order of cpr_suspend_devices().
*/
int
{
int did_suspend;
int error = resume_failed;
char buf[CPR_BUFSIZE];
}
/*
* cpr is the only one that uses this field and the device
* itself hasn't resumed yet, there is no need to use a
* lock, even though kernel threads are active by now.
*/
if (did_suspend)
/*
* Always attempt to restore device configuration before
* attempting resume
*/
#ifndef __xpv
#endif
/*
* There may be background attaches happening on devices
* that were not originally suspended by cpr, so resume
* only devices that were suspended by cpr. Also, stop
* resuming after the first resume failure, but traverse
* the entire tree to clear the suspend flag unless the
* FORCE_SUSPEND_TO_RAM test point is set.
*/
#ifndef __xpv
if (did_suspend && (!error ||
#else
if (did_suspend && !error) {
#endif
/*
* If a device suspended by cpr gets detached during
* the resume process (for example, due to hotplugging)
* before cpr gets around to issuing it a DDI_RESUME,
* we'll have problems.
*/
if (!i_ddi_devi_attached(dip)) {
"%s, device not ready for resume\n",
"not ready for resume",
#ifndef __xpv
} else if (cpr_test_point != DEVICE_SUSPEND_TO_RAM ||
#else
} else {
#endif
DDI_SUCCESS) {
}
}
}
"WARNING: Unable to resume device %s\n",
}
}
return (error);
}
/*
* Returns a string which contains device name and address.
*/
static char *
{
char *name;
char *address;
int size;
/*
* Make sure that we don't over-run the buffer.
* There are 2 additional characters in the string.
*/
else
else
return (buf);
}
/*
* This function determines whether the given device is real (and should
* be suspended) or not (pseudo like). If the device has a "reg" property
*/
static int
{
int length;
int rc;
return (0);
/*
* First those devices for which special arrangements have been made
*/
return (1);
return (0);
/*
* now the general case
*/
if (rc != DDI_PROP_SUCCESS) {
return (0);
} else {
return (1);
}
}