/*
* 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 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* Platform Power Management driver for SUNW,Sun-Blade-1000
*/
#include <sys/ddi_impldefs.h>
#include <sys/xcalppm_reg.h>
#include <sys/xcalppm_var.h>
#include <sys/archsystm.h>
#include <sys/cheetahregs.h>
#include <sys/us3_module.h>
/*
* Locking Considerations
*
* xcppm_dev structures the domain_lock for the affected domain must be held.
*
* When the autopm framework needs to change the power of a component of a
* device, it needs to hold the associated power lock (see discussion at
*
* has claimed, xcppm_ctlops will be called with PMR_PPM_LOCK_POWER. Ppm
* needs to be involved because, due to platform constraints, changing the
* power of one device may require that other devices be changed in the same
* operation.
*
* In some domains (e.g., cpus) the power lock must be acquired for all the
* affected devices to avoid possible corruption of the power states. The
* joint change must be an atomic operation. Ppm handles this by acquiring
* the domain lock, then walking the list of affected devices and acquiring
* the power lock for each of them. To unlock, the list is traversed and
* each of the power locks is freed, followed by freeing the domain lock.
*
* For other domains ppm will only be changing the power of a single device
* that is known to the framework. In these cases, the locking is done by
* acquiring the domain lock and directly calling the framework routine for
* getting a single power lock.
*/
ddi_ctl_enum_t, void *, void *);
static void xcppm_dev_init(ppm_dev_t *);
static void xcppm_dev_fini(ppm_dev_t *);
static void xcppm_iocset(uint8_t);
static uint8_t xcppm_iocget(void);
/*
* Note: 1394 and pciupa were originally required to be LOCK_ALL domains.
* However, the underlying nexus drivers aren't able to do power mgmt
* (because of hw implementation issues). The locking protocol for these
* domains is changed to LOCK_ONE to simplify other code. The domain
* code itself will be removed in the future.
*/
};
xcppm_dev_init, /* dev_init */
xcppm_dev_fini, /* dev_fini */
xcppm_iocset, /* iocset */
xcppm_iocget, /* iocget */
};
/*
* The order of entries must be from slowest to fastest and in
* one-to-one correspondence with the cpu_level array.
*/
};
/*
* Configuration data structures
*/
ppm_open, /* open */
ppm_close, /* close */
nodev, /* strategy */
nodev, /* print */
nodev, /* dump */
nodev, /* read */
nodev, /* write */
ppm_ioctl, /* ioctl */
nodev, /* devmap */
nodev, /* mmap */
nodev, /* segmap */
nochpoll, /* poll */
ddi_prop_op, /* prop_op */
NULL, /* streamtab */
CB_REV, /* cb_ops revision */
nodev, /* async read */
nodev /* async write */
};
0,
0,
0,
0,
0,
0,
0, /* (*bus_get_eventcookie)(); */
0, /* (*bus_add_eventcall)(); */
0, /* (*bus_remove_eventcall)(); */
0 /* (*bus_post_event)(); */
};
DEVO_REV, /* devo_rev */
0, /* refcnt */
ppm_getinfo, /* info */
nulldev, /* identify */
nulldev, /* probe */
xcppm_attach, /* attach */
xcppm_detach, /* detach */
nodev, /* reset */
&xcppm_cb_ops, /* driver operations */
&xcppm_bus_ops, /* bus operations */
NULL, /* power */
ddi_quiesce_not_supported, /* devo_quiesce */
};
extern struct mod_ops mod_driverops;
&mod_driverops, /* type of module - pseudo */
"platform pm driver",
};
&modldrv,
};
int
_init(void)
{
}
int
_fini(void)
{
return (EBUSY);
}
int
{
}
static int
{
if (rv0 == DDI_SUCCESS)
if (rv1 == DDI_SUCCESS)
if (rv2 == DDI_SUCCESS)
if (rv3 == DDI_SUCCESS)
return (DDI_FAILURE);
}
/*
* Ppm uses GPIO bits in Bank 0. Make sure Bank 0 is selected.
*/
return (DDI_SUCCESS);
}
static int
{
#ifdef DEBUG
#endif
int retval;
switch (cmd) {
case DDI_ATTACH:
if (ppm_inst != -1) {
("%s: instance already attached\n", str));
return (DDI_FAILURE);
}
/*
* Allocate and initialize soft state structure
*/
return (DDI_FAILURE);
("%s: Can't create minor for 0x%p\n", str,
(void *)dip));
return (DDI_FAILURE);
}
return (retval);
/*
* Map all of the registers under the ppm node.
*/
return (DDI_FAILURE);
if ((retval =
("%s: can't register ppm handler\n", str));
return (retval);
}
break;
case DDI_RESUME:
break;
default:
}
return (retval);
}
/*
* set the front panel LED:
* PPM_LEDON turns it on, PPM_LEDOFF turns it off.
* for GPIO register: 0x0 means led-on, 0x2 means led-off.
*/
static void
{
else
}
static void
{
int new_action;
return;
}
} else {
}
intvl);
}
static void
{
}
/* ARGSUSED */
static int
{
switch (cmd) {
case DDI_DETACH:
return (DDI_FAILURE);
case DDI_SUSPEND:
/*
* Suspend requires that timeout callouts to be canceled.
* Turning off the LED blinking will cancel the timeout.
*/
xcppm_freeze_led((void *)PPM_LEDON);
return (DDI_SUCCESS);
default:
return (DDI_FAILURE);
}
}
/*
* Device we claimed has detached. We must get rid of
* our state which was used to track this device.
*/
static void
{
return;
}
/*
* The system is being resumed from a cpr suspend operation and this
* device's attach entry will be called shortly. The driver will set
* the device's power to a conventional starting value, and we need to
* stay in sync and set our private copy to the same value.
*/
/* ARGSUSED */
static void
{
int powered;
return;
/*
* Maintain correct powered count for domain which cares
*/
powered = 0;
powered++;
}
/*
* If this device was powered off when the system was
* suspended, this resume acts like a power-on transition,
* so we adjust the count.
*/
if (powered == 0)
}
}
}
/*
* Change the power level for a component of a device. If the change
* arg is true, we call the framework to actually change the device's
* power; otherwise, we just update our own copy of the power level.
*/
static int
{
#ifdef DEBUG
#endif
int ret;
ret = DDI_SUCCESS;
if (change)
if (ret == DDI_SUCCESS) {
}
return (ret);
}
static int
{
}
static int
{
}
static uint8_t
{
#ifdef DEBUG
#endif
switch (action) {
case XCPPM_GETBIT:
break;
case XCPPM_SETBIT:
case XCPPM_CLRBIT:
if (action == XCPPM_SETBIT)
else
"bit 0x%x changed from 0x%x to 0x%x\n",
break;
default:
"IO command %d\n", action);
break;
}
return (ret);
}
/*
* Raise the power level of a subrange of cpus. Used when cpu driver
* failed an attempt to lower the power of a cpu (probably because
* it got busy). Need to revert the ones we already changed.
*
* ecpup = the ppm_dev_t for the cpu which failed to lower power
* level = power level to reset prior cpus to
*/
static void
{
}
}
/*
* the converter in low power mode and setting the bit puts it back in
* normal mode.
*/
static void
{
static int xcppm_dcdc_lpm;
switch (action) {
case XCPPM_SETBIT:
if (xcppm_dcdc_lpm) {
"switch to normal power mode.\n"));
xcppm_dcdc_lpm = 0;
}
break;
case XCPPM_CLRBIT:
/*
* put in low power mode before CPUs made the transition
* to 1/32 of clock speed. In those cases, system was
* shut down by hardware for protection. To resolve that
* problem, we make sure CPUs have made the clock transition
*/
ASSERT(xcppm_dcdc_lpm == 0);
while (tries) {
spl = ddi_enter_critical();
spl = ddi_enter_critical();
tick_end = gettick_counter();
(stick_end - stick_begin);
/*
* transition has not happened yet.
*/
if (cur_speed_ratio <= ((full_speed_ratio /
XCPPM_VCL_DIVISOR) + 1)) {
"switch to low power mode.\n"));
xcppm_dcdc_lpm = 1;
break;
}
"has not made transition to lowest speed yet "
"(%d)\n", tries));
tries--;
}
break;
}
}
static void
{
if (mode == XCPPM_SETBIT)
else
data32 &= ~RIO_BBC_ESTAR_MODE;
}
/*
* change the power level of all cpus to the arg value;
* the caller needs to ensure that a legal transition is requested.
*/
static int
{
#ifdef DEBUG
#endif
char *chstr;
/*
* not all cpus may have transitioned to a known level by this time
*/
chstr = "UP";
speedup = 1;
incr = 1;
chstr = "DOWN";
speedup = 0;
incr = -1;
} else
return (DDI_SUCCESS);
undo_flag = 0;
if (speedup) {
/*
* If coming up from lowest power level, set the E*
* mode bit in GPIO to make power supply efficient
* at normal power.
*/
undo_flag = 1;
}
} else {
/*
* set BBC Estar mode bit in RIO AUXIO register
*/
undo_flag = 1;
}
}
/*
* this loop will execute 1x or 2x depending on
* number of times we need to change clock rates
*/
continue;
if (ret == DDI_SUCCESS)
continue;
/*
* if the driver was unable to lower cpu speed,
* the cpu probably got busy; set the previous
* cpus back to the original level
*/
if (speedup == 0)
if (undo_flag) {
if (speedup)
else
}
return (ret);
}
/*
* set the delay times for changing to this rate
*/
}
/*
* clear CPU Estar Mode bit in the gpio register
*/
if (speedup) {
} else {
}
return (DDI_SUCCESS);
}
/*
* Process a request to change the power level of a cpu. If all cpus
* don't want to be at the same power yet, or if we are currently
* refusing slowdown requests due to thermal stress, just cache the
* request. Otherwise, make the change for all cpus.
*/
/* ARGSUSED */
static int
{
#ifdef DEBUG
#endif
int do_rescan = 0;
*result = DDI_SUCCESS;
switch (reqp->request_type) {
case PMR_PPM_SET_POWER:
break;
/* cpu driver can`t change cpu power level by itself */
default:
return (DDI_FAILURE);
}
/*
* At power on, the cpus are at full speed. There is no hardware
* transition needed for going from unknown to full. However, the
* state of the pm framework and cpu driver needs to be adjusted.
*/
if (ret != DDI_SUCCESS) {
}
return (ret);
}
return (DDI_SUCCESS);
}
/*
* A request from lower to higher level transition is granted and
* made effective on both cpus. For more than two cpu platform model,
* the following code needs to be modified to remember the rest of
* the unsoliciting cpus to be rescan'ed.
* A request from higher to lower must be agreed by all cpus.
*/
continue;
return (DDI_SUCCESS);
}
/*
* If a single cpu requests power up, honor the request
* by powering up both cpus.
*/
"because of request from dip(%s@%s, %p), "
do_rescan++;
break;
}
}
if (ret == DDI_SUCCESS) {
else
kmflag = KM_NOSLEEP;
continue;
if ((p = kmem_zalloc(sizeof (pm_ppm_devlist_t),
break;
}
p->ppd_old_level = old;
p->ppd_new_level = new;
devlist = p;
}
if (do_rescan > 0)
}
return (ret);
}
/*
* If powering off and all devices in this domain will now be off,
* shut off common power. If powering up and no devices up yet,
* turn on common power. Always make the requested power level
* change for the target device.
*/
static int
{
#ifdef DEBUG
#endif
switch (reqp->request_type) {
case PMR_PPM_SET_POWER:
break;
break;
default:
return (*result = DDI_FAILURE);
}
/* This is common code for SET_POWER and POWER_CHANGE_NOTIFY cases */
return (DDI_SUCCESS);
/*
* Devices in this domain are known to have 0 (off) as their
* lowest power level. We use this fact to simplify the logic.
*/
if (new > 0) {
if (old == 0) {
incr = 1;
}
}
}
/*
* Decr the power count in two cases:
*
* 1) request was to power device down and was successful
* 2) request was to power up (we pre-incremented count), but failed.
*/
}
}
/*
* Since UPA64S relies on PCI B staying at nominal 33MHz in order to
* have its interrupt pulse function properly, we ensure
* - Lowering PCI B only if UPA64S is at low power, otherwise defer
* the action until UPA64S goes down; hence right after UPA64S goes
* down, perform the deferred action for PCI B;
* - Always raise PCI B power prior to raising UPA64S power.
*
* Both UPA64S and PCI B devices are considered each other's dependency
* device whenever actual power transition is handled (PMR_PPM_SET_POWER).
*/
static int
{
#ifdef DEBUG
#endif
*result = DDI_SUCCESS;
switch (reqp->request_type) {
case PMR_PPM_SET_POWER:
break;
break;
default:
*result = DDI_FAILURE;
return (DDI_FAILURE);
}
/* Common code for SET_POWER and POWER_CHANGE_NOTIFY cases */
return (DDI_SUCCESS);
/*
* find power-wise co-related device
*/
#ifdef DEBUG
#endif
if (flags == XCPPMF_UPA)
else if (flags == XCPPMF_PCIB)
break;
/*
* Raise power level -
* pre-raising: upa ensure pci is powered up.
*/
return (DDI_FAILURE);
}
}
return (DDI_FAILURE);
}
/*
* Lower power level
*
* once upa is attached, pci checks upa level:
* if upa is at high level, defer the request and return.
* otherwise, set power level then check and lower pci level.
*/
return (DDI_SUCCESS);
}
return (DDI_FAILURE);
}
if (flags == XCPPMF_UPA) {
if ((retval = xcppm_change_power_level(
return (DDI_FAILURE);
}
}
}
}
return (DDI_SUCCESS);
}
/*
* When all of the children of the 1394 nexus are idle, a call will be
* made to the nexus driver's own power entry point to lower power. Ppm
* intercepts this and kills 1394 cable power (since the driver doesn't
* have access to the required register). Similar logic applies when
* coming up from the state where all the children were off.
*/
static int
{
#ifdef DEBUG
#endif
switch (reqp->request_type) {
case PMR_PPM_SET_POWER:
break;
break;
default:
return (*result = DDI_FAILURE);
}
/* Common code for SET_POWER and POWER_CHANGE_NOTIFY cases */
return (*result = DDI_SUCCESS);
/* the reduce power case */
if ((*result =
return (DDI_FAILURE);
}
return (DDI_SUCCESS);
}
/* the increase power case */
delay(1);
}
/*
* Even if pwr_func fails we need to check current level again
* because it could have been changed by an intervening
* POWER_CHANGE_NOTIFY operation.
*/
if ((*result =
} else {
}
}
/*
* We get here if component was non-zero. This is not what we
* expect. Let the device deal with it and just pass back the
* result.
*/
}
/*
* lock, unlock, or trylock for one power mutex
*/
static void
{
switch (reqp->request_type) {
case PMR_PPM_LOCK_POWER:
break;
case PMR_PPM_UNLOCK_POWER:
break;
case PMR_PPM_TRY_LOCK_POWER:
break;
}
}
/*
* lock, unlock, or trylock all devices within a domain.
*/
static void
{
/*
* To simplify the implementation we let all the devices
* in the domain be represented by a single device (dip).
* We use the first device in the domain's devlist. This
* is safe because we return with the domain lock held
* which prevents the list from changing.
*/
/* domain lock remains held */
return;
return;
}
*iresp = 0;
return;
}
if (*iresp)
else
}
/*
* The pm framework calls us here to manage power for a device.
* system board power components based on the status of all the devices
* sharing a component.
*
*/
/* ARGSUSED */
static int
{
#ifdef DEBUG
}
#endif
if (ctlop != DDI_CTLOPS_POWER)
return (DDI_FAILURE);
switch (reqp->request_type) {
case PMR_PPM_UNMANAGE:
case PMR_PPM_PRE_PROBE:
case PMR_PPM_POST_PROBE:
case PMR_PPM_PRE_ATTACH:
case PMR_PPM_PRE_DETACH:
return (DDI_SUCCESS);
/*
* There is no hardware configuration required to be done on this
* platform prior to installing drivers.
*/
case PMR_PPM_INIT_CHILD:
case PMR_PPM_UNINIT_CHILD:
return (DDI_SUCCESS);
case PMR_PPM_ALL_LOWEST:
return (DDI_SUCCESS);
}
(void *)PPM_LEDON, PPM_LEDON_INTERVAL);
} else {
xcppm_freeze_led((void *)PPM_LEDON);
}
return (DDI_SUCCESS);
case PMR_PPM_POST_ATTACH:
/*
* After a successful attach, if we haven't already created
* our private data structure for this device, ppm_get_dev()
* will force it to be created.
*/
if (ppmd)
} else if (!ppmd) {
}
return (DDI_SUCCESS);
case PMR_PPM_POST_DETACH:
*(int *)result = DDI_SUCCESS;
return (DDI_SUCCESS);
case PMR_PPM_PRE_RESUME:
return (DDI_SUCCESS);
case PMR_PPM_UNLOCK_POWER:
case PMR_PPM_TRY_LOCK_POWER:
case PMR_PPM_LOCK_POWER:
if (ppmd)
}
else
return (DDI_SUCCESS);
case PMR_PPM_POWER_LOCK_OWNER:
if (ppmd)
else {
}
/*
* In case of LOCK_ALL, effective owner of the power lock
* is the owner of the domain lock. otherwise, it is the owner
* of the power lock.
*/
else {
}
return (DDI_SUCCESS);
default:
}
#ifdef DEBUG
prom_printf("%s: \"%s\", PMR_PPM_SET_POWER\n",
}
#endif
else {
}
}
}
/*
* Initialize our private version of real power level
* as well as lowest and highest levels the device supports;
* see ppmf and ppm_add_dev
*/
static void
{
int maxi;
/*
* ppm exists to handle power-manageable devices which require
* special handling on the current platform. However, a
* driver for such a device may choose not to support power
* we create a structure to represent a single-component device
* for which "level" = PM_LEVEL_UNKNOWN and "lowest" = 0
* are effectively constant.
*/
if (PM_GET_PM_INFO(dip)) {
}
/*
* add any domain-specific initialization here
*/
/*
* when a new device is added to domain_powefet
* it is counted here as being powered up.
*/
/*
* There may be a better way to determine the device type
* instead of comparing to hard coded string names.
*/
}
}
/*
* see ppmf and ppm_rem_dev
*/
static void
{
};
}
}
/*
* see ppmf and ppm_ioctl, PPMIOCSET
*/
static void
{
int action;
if (value == PPM_IDEV_POWER_ON)
else if (value == PPM_IDEV_POWER_OFF)
}
/*
* see ppmf and ppm_ioctl, PPMIOCGET
*/
static uint8_t
xcppm_iocget(void)
{
}