X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/cf03f5cdc65293b4cb5eba3ed23fed26dad903c9..de355530ae67247cbd0da700edb3a2a1dae884c2:/iokit/Kernel/IOServicePM.cpp diff --git a/iokit/Kernel/IOServicePM.cpp b/iokit/Kernel/IOServicePM.cpp index a8542bc7d..0f381dbfb 100644 --- a/iokit/Kernel/IOServicePM.cpp +++ b/iokit/Kernel/IOServicePM.cpp @@ -3,22 +3,19 @@ * * @APPLE_LICENSE_HEADER_START@ * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * The contents of this file constitute Original Code as defined in and + * are subject to the Apple Public Source License Version 1.1 (the + * "License"). You may not use this file except in compliance with the + * License. Please obtain a copy of the License at + * http://www.apple.com/publicsource and read it before using this file. * - * This file contains Original Code and/or Modifications of Original Code - * as defined in and that are subject to the Apple Public Source License - * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. - * - * The Original Code and all software distributed under the License are - * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER + * This Original Code and all software distributed under the License are + * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, - * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. - * Please see the License for the specific language governing rights and - * limitations under the License. + * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the + * License for the specific language governing rights and limitations + * under the License. * * @APPLE_LICENSE_HEADER_END@ */ @@ -636,7 +633,7 @@ IOReturn IOService::removePowerChild ( IOPowerConnection * theNub ) } } } - + theNub->release(); if ( (pm_vars->theControllingDriver == NULL) || // if not fully initialized @@ -645,10 +642,6 @@ IOReturn IOService::removePowerChild ( IOPowerConnection * theNub ) return IOPMNoErr; // we can do no more } - // Perhaps the departing child was holding up idle or system sleep - we need to re-evaluate our - // childrens' requests. Clear and re-calculate our kIOPMChildClamp and kIOPMChildClamp2 bits. - rebuildChildClampBits(); - computeDesiredState(); // this may be different now changeState(); // change state if we can now tolerate lower power @@ -1089,54 +1082,6 @@ void IOService::setParentInfo ( IOPMPowerFlags newPowerStateFlags, IOPowerConnec IOLockUnlock(pm_vars->parentLock); } -//********************************************************************************* -// rebuildChildClampBits -// -// The ChildClamp bits (kIOPMChildClamp & kIOPMChildClamp2) in our capabilityFlags -// indicate that one of our children (or grandchildren or great-grandchildren or ...) -// doesn't support idle or system sleep in its current state. Since we don't track the -// origin of each bit, every time any child changes state we have to clear these bits -// and rebuild them. -//********************************************************************************* - -void IOService::rebuildChildClampBits(void) -{ - unsigned long i; - OSIterator * iter; - OSObject * next; - IOPowerConnection * connection; - - - // A child's desires has changed. We need to rebuild the child-clamp bits in our - // power state array. Start by clearing the bits in each power state. - - for ( i = 0; i < pm_vars->theNumberOfPowerStates; i++ ) { - pm_vars->thePowerStates[i].capabilityFlags &= ~(kIOPMChildClamp | kIOPMChildClamp2); - } - - // Now loop through the children. When we encounter the calling child, save - // the computed state as this child's desire. And while we're at it, set the ChildClamp bits - // in any of our states that some child has requested with clamp on. - - iter = getChildIterator(gIOPowerPlane); - - if ( iter ) - { - while ( (next = iter->getNextObject()) ) - { - if ( (connection = OSDynamicCast(IOPowerConnection,next)) ) - { - if ( connection->getPreventIdleSleepFlag() ) - pm_vars->thePowerStates[connection->getDesiredDomainState()].capabilityFlags |= kIOPMChildClamp; - if ( connection->getPreventSystemSleepFlag() ) - pm_vars->thePowerStates[connection->getDesiredDomainState()].capabilityFlags |= kIOPMChildClamp2; - } - } - iter->release(); - } - -} - //********************************************************************************* // requestPowerDomainState @@ -1221,8 +1166,17 @@ IOReturn IOService::requestPowerDomainState ( IOPMPowerFlags desiredState, IOPow IOLockLock(pm_vars->childLock); - // Now loop through the children. When we encounter the calling child, save - // the computed state as this child's desire. +// A child's desires has changed. We need to rebuild the child-clamp bits in our +// power state array. Start by clearing the bits in each power state. + + for ( i = 0; i < pm_vars->theNumberOfPowerStates; i++ ) { + pm_vars->thePowerStates[i].capabilityFlags &= ~(kIOPMChildClamp | kIOPMChildClamp2); + } + +// Now loop through the children. When we encounter the calling child, save +// the computed state as this child's desire. And while we're at it, set the ChildClamp bits +// in any of our states that some child has requested with clamp on. + iter = getChildIterator(gIOPowerPlane); if ( iter ) { @@ -1234,14 +1188,16 @@ IOReturn IOService::requestPowerDomainState ( IOPMPowerFlags desiredState, IOPow connection->setPreventSystemSleepFlag(desiredState & kIOPMPreventSystemSleep); connection->setChildHasRequestedPower(); } + if ( connection->getPreventIdleSleepFlag() ) { + pm_vars->thePowerStates[connection->getDesiredDomainState()].capabilityFlags |= kIOPMChildClamp; + } + if ( connection->getPreventSystemSleepFlag() ) { + pm_vars->thePowerStates[connection->getDesiredDomainState()].capabilityFlags |= kIOPMChildClamp2; + } } } iter->release(); } - - // Since a child's power requirements may have changed, clear and rebuild - // kIOPMChildClamp and kIOPMChildClamp2 (idle and system sleep clamps) - rebuildChildClampBits(); IOLockUnlock(pm_vars->childLock); @@ -3268,11 +3224,8 @@ IOReturn IOService::ask_parent ( unsigned long requestedState ) ourRequest |= kIOPMPreventSystemSleep; } - // is this a new desire? - if ( priv->previousRequest == ourRequest ) - { - // no, the parent knows already, just return - return IOPMNoErr; + if ( priv->previousRequest == ourRequest ) { // is this a new desire? + return IOPMNoErr; // no, the parent knows already, just return } if ( priv->we_are_root ) {