/*
* 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 2015 Gary Mills
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include "pmconfig.h"
#include <sys/openpromio.h>
#include <sys/efi_partition.h>
#include <syslog.h>
#include <stdlib.h>
#include <kstat.h>
#include <libzfs.h>
/*
* When lines in a config file (usually "/etc/power.conf") start with
* a recognized keyword, a "handler" routine is called for specific
* CPR or PM -related action(s). Each routine returns a status code
* indicating whether all tasks were successful; if any errors occured,
* future CPR or PM updates are skipped. Following are the handler
* routines for all keywords:
*/
static char *
{
return ("??");
}
return (pm_cmd_string);
}
static int
{
int ret;
return (ret == 0);
}
static int
{
if (!suppressed) {
return (NOUP);
} else {
return (OKUP);
}
}
return (OKUP);
}
/*
* Check for valid cpupm behavior and communicate it to the kernel.
*/
int
cpupm(void)
{
struct bmtoc {
char *behavior;
char *mode;
int cmd;
int Errno;
};
NULL, 0, 0, 0
};
char *behavior;
char *mode;
mode = "\0";
break;
}
}
} else {
}
return (NOUP);
}
return (NOUP);
}
return (OKUP);
}
/*
* Check for valid cpu_deep_idle option and communicate it to the kernel.
*/
int
cpuidle(void)
{
struct btoc {
char *behavior;
int cmd;
int Errno;
};
NULL, 0, 0
};
char *behavior;
break;
}
return (NOUP);
}
return (NOUP);
}
return (OKUP);
}
/*
* Two decisions are identical except for the list names and ioctl commands
* inputs: whitelist, blacklist, yes, no
* if (! ("S3" kstat exists))
* return (no)
* if (SystemInformation.Manufacturer == "Sun Microsystems" &&
* (Pref_PM_Profile == Workstation || Pref_PM_Profile == Desktop)) {
* if (platform on blacklist)
* return (no)
* return (yes)
* } else {
* if (platform on whitelist)
* return (yes)
* return (no)
* }
*/
int
{
int ret;
int preferred_pm_profile = 0;
*didyes = 0;
return (OKUP);
}
(void) kstat_close(kc);
return (OKUP);
}
(void) kstat_close(kc);
}
if (!whitelist_only) {
/*
* We still have an ACPI ksp, search it again for
* 'preferred_pm_profile' (needs to be valid if we don't
* aren't only using a whitelist).
*/
(void) kstat_close(kc);
}
}
(void) kstat_close(kc);
/* we promised not to complain */
/* we bail leaving it to the kernel default */
return (OKUP);
}
return (OKUP);
}
return (OKUP);
}
if (!whitelist_only) {
(preferred_pm_profile == PPP_DESKTOP ||
suppress));
} else {
suppress);
return (ret);
}
}
}
return (ret);
} else {
}
}
int
{
struct btoc {
char *behavior;
int cmd;
};
"default", PM_DEFAULT_ALGORITHM,
"enable", PM_ENABLE_S3,
"disable", PM_DISABLE_S3,
NULL, 0
};
char *behavior;
int dontcare;
break;
}
return (NOUP);
}
case PM_ENABLE_S3:
case PM_DISABLE_S3:
case PM_DEFAULT_ALGORITHM:
/*
* we suppress errors in the "default" case because we
* already did an invisible default call, so we know we'll
* get EBUSY
*/
default:
return (NOUP);
}
}
/*
* Check for valid autoS3 behavior and save after ioctl success.
*/
int
autoS3(void)
{
struct btoc {
char *behavior;
int cmd;
};
"default", PM_DEFAULT_ALGORITHM,
"disable", PM_STOP_AUTOS3,
"enable", PM_START_AUTOS3,
NULL, 0
};
char *behavior;
int dontcare;
break;
}
return (NOUP);
}
default:
return (OKUP);
case PM_STOP_AUTOS3:
case PM_START_AUTOS3:
case PM_DEFAULT_ALGORITHM:
}
}
/*
* Check for valid autopm behavior and save after ioctl success.
*/
int
autopm(void)
{
struct btoc {
char *behavior;
};
NULL, 0, 0, 0,
};
char *behavior;
break;
}
return (NOUP);
}
/*
* for "default" behavior, do not enable autopm if not ESTAR_V3
*/
#if defined(__sparc)
return (NOUP);
}
}
return (OKUP);
#endif
#if defined(__x86)
return (NOUP);
}
return (OKUP);
} else {
int didenable;
if (didenable) {
/* tell powerd to attach all devices */
}
return (ret);
}
#endif
}
static int
{
return (-1);
}
return (0);
}
static void
{
}
/*
* check and record autoshutdown behavior.
*/
int
autosd(void)
{
static char *blist[] = {
"autowakeup", "default", "noshutdown",
};
return (NOUP);
break;
}
return (NOUP);
}
return (OKUP);
}
/*
* Check for a real device and try to resolve to a full path.
* and an allocated copy of the result is stored at *destp;
* the caller will need to free that space. Returns 1 for any
* error, otherwise 0; also sets *errp after an alloc error.
*/
static int
{
/*
* When there's a real device, try to resolve the path
* and trim the leading "/devices" component.
*/
return (1);
}
dstr = "/devices";
if (dcs)
} else
/*
* When the path has ":anything", display an error for
* a non-device or truncate a resolved+modifed path.
*/
if (devok == 0) {
"a minor string (%s)\n", src);
return (1);
} else if (dcs)
*cp = '\0';
}
}
}
/*
*/
static int
{
if (isprop) {
} else {
return (upval);
}
/*
* Now loop through any dependents.
*/
return (upval);
break;
}
"kept \"%s\", keeper \"%s\"\n",
}
break;
}
return (upval);
}
int
ddprop(void)
{
return (dev_dep_common(1));
}
int
devdep(void)
{
return (dev_dep_common(0));
}
/*
* Convert a numeric string (with a possible trailing scaling byte)
* into an integer. Returns a converted value and *nerrp unchanged,
* or 0 with *nerrp set to 1 for a conversion error.
*/
static int
{
char *sp;
errno = 0;
*nerrp = 1;
if (*sp == 'h')
factor = 3600;
else if (*sp == 'm')
factor = 60;
else if (*sp != 's')
*nerrp = 1;
}
/* any bytes following sp are ignored */
if (*nerrp == 0) {
*nerrp = 1;
}
if (*nerrp)
return ((int)svalue);
}
/*
* Increment the count of threshold values,
* reallocate *vlistp and append another element.
* Returns 1 on error, otherwise 0.
*/
static int
{
(*vcntp)++;
else
}
/*
* Convert a single threshold string or paren groups of thresh's as
* described below. All thresh's are saved to an allocated list at
* *vlistp; the caller will need to free that space. On return:
* *vcntp is the count of the vlist array, and vlist is either
* a single thresh or N groups of thresh's with a trailing zero:
* (cnt_1 thr_1a thr_1b [...]) ... (cnt_N thr_Na thr_Nb [...]) 0.
* Returns 0 when all conversions were OK, and 1 for any syntax,
* conversion, or alloc error.
*/
static int
{
break;
paren = 1;
src++;
}
if (paren) {
paren = 0;
*rp = '\0';
} else {
nerr = 1;
break;
}
}
break;
}
return (nerr);
}
/*
* Set device thresholds from (3) formats:
* path "always-on"
* path time-spec: [0-9]+[{h,m,s}]
* path (ts1 ts2 ...)+
*/
int
devthr(void)
{
return (upval);
} else if (nthresh == 1) {
} else {
}
return (upval);
}
static int
{
long lval;
errno = 0;
return (NOUP);
}
return (OKUP);
}
static int
{
float fval;
errno = 0;
return (NOUP);
}
return (OKUP);
}
int
dreads(void)
{
}
/*
* Set pathname for idlecheck;
* an overflowed pathname is treated as a fatal error.
*/
int
idlechk(void)
{
return (OKUP);
}
int
loadavg(void)
{
}
int
nfsreq(void)
{
}
#ifdef sparc
/*
* Verify the filesystem type for a regular statefile is "ufs"
* or verify a block device is not in use as a mounted filesytem.
* Returns 1 if any error, otherwise 0.
*/
static int
{
return (1);
}
if (ufs) {
err_fmt = "ufs statefile with zfs root is not"
" supported\n";
return (1);
}
}
/*
* Search for a matching dev_t;
* ignore non-ufs filesystems for a regular statefile.
*/
if (rgent > 0) {
return (1);
continue;
match = 1;
break;
}
}
/*
* No match is needed for a block device statefile,
* a match is needed for a regular statefile.
*/
if (match == 0) {
else
err_fmt = "cannot find ufs mount point for \"%s\"\n";
} else
err_fmt = "statefile device \"%s\" is a mounted filesystem\n";
if (err_fmt)
}
/*
* Convert a Unix device to a prom device and save on success,
* log any ioctl/conversion error.
*/
static int
{
union obpbuf {
};
return (NOUP);
}
OBP_MAXPATHLEN, "statefile device");
"prom device");
} else {
gettext("cannot convert \"%s\" to prom device"),
fs_name);
closelog();
}
return (upval);
}
/*
* given the path to a zvol, return the cXtYdZ name
* returns < 0 on error, 0 if it isn't a zvol, > 1 on success
*/
static int
{
char *vname;
char *p;
return (0);
}
arg += 14;
*p = '\0';
return (-1);
}
return (-1);
}
&nvroot) != 0) {
return (-1);
}
if (children != 1) {
return (-1);
}
return (-1);
}
return (1);
}
/*
* returns NULL if the slice is good (e.g. does not start at block
* zero, or a string describing the error if it doesn't
*/
static boolean_t
{
char *x, *y;
/* convert from dsk to rdsk */
if (x != NULL) {
*x++ = 'r';
(void) strcpy(x, y);
}
*err = "could not open '%s'\n";
/*
* we got a slice number; now check the block
* number where the slice starts
*/
*err = "using '%s' would clobber the disk label\n";
} else if ((rc == VT_ENOTSUP) &&
/* EFI slices don't clobber the disk label */
return (B_TRUE);
} else
*err = "could not read partition table from '%s'\n";
return (B_FALSE);
}
/*
* Check for a valid statefile pathname, inode and mount status.
*/
int
sfpath(void)
{
static int statefile;
int dir = 0;
if (statefile) {
return (OKUP);
} else if (ua_err) {
return (NOUP);
}
/*
* Check for an absolute path and trim any trailing '/'.
*/
if (*sfile != '/') {
return (NOUP);
}
*sp = '\0';
/*
* If the statefile doesn't exist, the leading path must be a dir.
*/
dir = 1;
sp++;
*sp = '\0';
} else
if (err_fmt) {
return (NOUP);
}
}
/*
*/
case 1:
break;
case 0:
break;
case -1:
default:
return (NOUP);
}
}
} else
err_fmt = "bad file type for \"%s\"\n"
"statefile must be a regular file or block device\n";
if (err_fmt) {
return (NOUP);
}
return (NOUP);
return (NOUP);
return (NOUP);
}
statefile = 1;
return (OKUP);
}
#endif /* sparc */
/*
* Common function to set a system or cpu threshold.
*/
static int
{
}
return (upval);
}
/*
* Try setting system threshold.
*/
int
systhr(void)
{
return (cmnthr(PM_SET_SYSTEM_THRESHOLD));
}
/*
* Try setting cpu threshold.
*/
int
cputhr(void)
{
return (cmnthr(PM_SET_CPU_THRESHOLD));
}
int
tchars(void)
{
}