]> git.saurik.com Git - apple/xnu.git/blobdiff - iokit/Kernel/IOPMrootDomain.cpp
xnu-792.6.56.tar.gz
[apple/xnu.git] / iokit / Kernel / IOPMrootDomain.cpp
index b811ffbf8e797f16c06dadc0496786bd74704ef7..17132892c39c93c3a872fbb487d08975e95faa67 100644 (file)
@@ -1,21 +1,22 @@
 /*
- * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1998-2005 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
  * 
- * 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.
  * 
- * This Original Code and all software distributed under the License are
- * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
+ * The 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 OR NON-INFRINGEMENT.  Please see the
- * License for the specific language governing rights and limitations
- * under the License.
+ * 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.
  * 
  * @APPLE_LICENSE_HEADER_END@
  */
 #include "IOKit/pwr_mgt/IOPowerConnection.h"
 #include "IOPMPowerStateQueue.h"
 #include <IOKit/IOCatalogue.h>
+#include <IOKit/IOHibernatePrivate.h>
 
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
-
-#include <IOKit/IOPolledInterface.h>
-
-OSDefineMetaClassAndAbstractStructors(IOPolledInterface, OSObject);
-
-OSMetaClassDefineReservedUnused(IOPolledInterface, 0);
-OSMetaClassDefineReservedUnused(IOPolledInterface, 1);
-OSMetaClassDefineReservedUnused(IOPolledInterface, 2);
-OSMetaClassDefineReservedUnused(IOPolledInterface, 3);
-OSMetaClassDefineReservedUnused(IOPolledInterface, 4);
-OSMetaClassDefineReservedUnused(IOPolledInterface, 5);
-OSMetaClassDefineReservedUnused(IOPolledInterface, 6);
-OSMetaClassDefineReservedUnused(IOPolledInterface, 7);
-OSMetaClassDefineReservedUnused(IOPolledInterface, 8);
-OSMetaClassDefineReservedUnused(IOPolledInterface, 9);
-OSMetaClassDefineReservedUnused(IOPolledInterface, 10);
-OSMetaClassDefineReservedUnused(IOPolledInterface, 11);
-OSMetaClassDefineReservedUnused(IOPolledInterface, 12);
-OSMetaClassDefineReservedUnused(IOPolledInterface, 13);
-OSMetaClassDefineReservedUnused(IOPolledInterface, 14);
-OSMetaClassDefineReservedUnused(IOPolledInterface, 15);
-
-IOReturn
-IOPolledInterface::checkAllForWork(void)
-{
-    return (kIOReturnSuccess);
-}
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
+#ifdef __ppc__
+#include <ppc/pms.h>
+#endif
 
 extern "C" void kprintf(const char *, ...);
 
@@ -217,6 +189,7 @@ static void disk_sync_callout(thread_call_param_t p0, thread_call_param_t p1)
     IOService                               *rootDomain = (IOService *) p0;
     unsigned long                           pmRef = (unsigned long) p1;
 
+    IOHibernateSystemSleep();
     sync_internal();
     rootDomain->allowPowerChange(pmRef);
 }
@@ -314,6 +287,7 @@ bool IOPMrootDomain::start ( IOService * nub )
         temp_entry->release();
     }
 
+    IOHibernateSystemInit(this);
 
     registerService();                                         // let clients find us
 
@@ -353,6 +327,10 @@ IOReturn IOPMrootDomain::setProperties ( OSObject *props_obj)
     const OSSymbol                            *fileserver_string = OSSymbol::withCString("AutoRestartOnPowerLoss");
     const OSSymbol                            *wakeonlid_string = OSSymbol::withCString("WakeOnLid");
     const OSSymbol                            *wakeonac_string = OSSymbol::withCString("WakeOnACChange");
+    const OSSymbol                            *hibernatemode_string = OSSymbol::withCString(kIOHibernateModeKey);
+    const OSSymbol                            *hibernatefile_string = OSSymbol::withCString(kIOHibernateFileKey);
+    const OSSymbol                            *hibernatefreeratio_string = OSSymbol::withCString(kIOHibernateFreeRatioKey);
+    const OSSymbol                            *hibernatefreetime_string = OSSymbol::withCString(kIOHibernateFreeTimeKey);
     const OSSymbol                            *timezone_string = OSSymbol::withCString("TimeZoneOffsetSeconds");
     
     if(!dict) 
@@ -381,6 +359,26 @@ IOReturn IOPMrootDomain::setProperties ( OSObject *props_obj)
         setProperty(stall_halt_string, b);
     }
 
+    if ( hibernatemode_string
+       && (n = OSDynamicCast(OSNumber, dict->getObject(hibernatemode_string))))
+    {
+       setProperty(hibernatemode_string, n);
+    }
+    if ( hibernatefreeratio_string
+       && (n = OSDynamicCast(OSNumber, dict->getObject(hibernatefreeratio_string))))
+    {
+       setProperty(hibernatefreeratio_string, n);
+    }
+    if ( hibernatefreetime_string
+       && (n = OSDynamicCast(OSNumber, dict->getObject(hibernatefreetime_string))))
+    {
+       setProperty(hibernatefreetime_string, n);
+    }
+    if ( hibernatefile_string
+       && (str = OSDynamicCast(OSString, dict->getObject(hibernatefile_string))))
+    {
+       setProperty(hibernatefile_string, str);
+    }
 
     // Relay AutoWake setting to its controller
     if( auto_wake_string
@@ -582,8 +580,24 @@ void IOPMrootDomain::stopIgnoringClamshellEventsDuringWakeup(void)
 // same thread.
 //*********************************************************************************
 
+static int pmsallsetup = 0;
+
 IOReturn IOPMrootDomain::setAggressiveness ( unsigned long type, unsigned long newLevel )
 {
+#ifdef __ppc__
+       if(pmsExperimental & 3) kprintf("setAggressiveness: type = %08X, newlevel = %08X\n", type, newLevel);
+       if(pmsExperimental & 1) {                                               /* Is experimental mode enabled? */
+               if(pmsInstalled && (type == kPMSetProcessorSpeed)) {    /* We want to look at all processor speed changes if stepper is installed */
+                       if(pmsallsetup) return kIOReturnSuccess;        /* If already running, just eat this */
+                       kprintf("setAggressiveness: starting stepper...\n");
+                       pmsallsetup = 1;                                                /* Remember we did this */
+                       pmsPark();
+                       pmsStart();                                                             /* Get it all started up... */
+                       return kIOReturnSuccess;                                /* Leave now... */
+               }
+       }
+#endif
+
     if ( pm_vars->PMcommandGate ) {
         pm_vars->PMcommandGate->runAction(broadcast_aggressiveness,(void *)type,(void *)newLevel);
     }
@@ -659,13 +673,17 @@ void IOPMrootDomain::powerChangeDone ( unsigned long previousState )
                 // re-enable this timer for next sleep
                 idleSleepPending = false;                      
 
-                IOLog("System Sleep\n");
+                IOLog("System %sSleep\n", gIOHibernateState ? "Safe" : "");
+
+                IOHibernateSystemHasSlept();
+
                 pm_vars->thePlatform->sleepKernel();
 
                 // The CPU(s) are off at this point. When they're awakened by CPU interrupt,
                 // code will resume execution here.
 
                 // Now we're waking...
+               IOHibernateSystemWake();
 
                 // stay awake for at least 30 seconds
                 clock_interval_to_deadline(30, kSecondScale, &deadline);       
@@ -690,7 +708,7 @@ void IOPMrootDomain::powerChangeDone ( unsigned long previousState )
                 tellClients(kIOMessageSystemWillPowerOn);
 
                 // tell the tree we're waking
-                IOLog("System Wake\n");
+                IOLog("System %sWake\n", gIOHibernateState ? "SafeSleep " : "");
                 systemWake();
                 
                 // Allow drivers to request extra processing time before clamshell
@@ -1118,6 +1136,7 @@ void IOPMrootDomain::tellChangeUp ( unsigned long stateNum)
 {
     if ( stateNum == ON_STATE ) 
     {
+       IOHibernateSystemPostWake();
         return tellClients(kIOMessageSystemHasPoweredOn);
     }
 }
@@ -1217,6 +1236,8 @@ IOReturn IOPMrootDomain::sysPowerDownHandler( void * target, void * refCon,
 
             // We will ack within 20 seconds
             params->returnValue = 20 * 1000 * 1000;
+            if (gIOHibernateState)
+                params->returnValue += gIOHibernateFreeTime * 1000;    //add in time we could spend freeing pages
 
             if ( ! OSCompareAndSwap( 0, 1, &gSleepOrShutdownPending ) )
             {