Loading...
iokit/Kernel/IOPMrootDomain.cpp xnu-792.2.4 xnu-792.12.6
--- xnu/xnu-792.2.4/iokit/Kernel/IOPMrootDomain.cpp
+++ xnu/xnu-792.12.6/iokit/Kernel/IOPMrootDomain.cpp
@@ -1,23 +1,31 @@
 /*
- * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 1998-2005 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_LICENSE_HEADER_START@
+ * @APPLE_LICENSE_OSREFERENCE_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 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.
- * 
- * @APPLE_LICENSE_HEADER_END@
+ * 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.  The rights granted to you under the 
+ * License may not be used to create, or enable the creation or 
+ * redistribution of, unlawful or unlicensed copies of an Apple operating 
+ * system, or to circumvent, violate, or enable the circumvention or 
+ * violation of, any terms of an Apple operating system software license 
+ * agreement.
+ *
+ * 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 
+ * 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.
+ *
+ * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
  */
 #include <IOKit/IOWorkLoop.h>
 #include <IOKit/IOCommandGate.h>
@@ -33,40 +41,11 @@
 #include "IOKit/pwr_mgt/IOPowerConnection.h"
 #include "IOPMPowerStateQueue.h"
 #include <IOKit/IOCatalogue.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);
-}
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
+#include <IOKit/IOHibernatePrivate.h>
+
+#ifdef __ppc__
+#include <ppc/pms.h>
+#endif
 
 extern "C" void kprintf(const char *, ...);
 
@@ -217,6 +196,7 @@
     IOService                               *rootDomain = (IOService *) p0;
     unsigned long                           pmRef = (unsigned long) p1;
 
+    IOHibernateSystemSleep();
     sync_internal();
     rootDomain->allowPowerChange(pmRef);
 }
@@ -314,6 +294,7 @@
         temp_entry->release();
     }
 
+    IOHibernateSystemInit(this);
 
     registerService();						// let clients find us
 
@@ -353,6 +334,10 @@
     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 +366,26 @@
         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 +587,24 @@
 // 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 +680,17 @@
                 // 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 +715,7 @@
                 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 +1143,7 @@
 {
     if ( stateNum == ON_STATE ) 
     {
+	IOHibernateSystemPostWake();
         return tellClients(kIOMessageSystemHasPoweredOn);
     }
 }
@@ -1217,6 +1243,8 @@
 
             // 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 ) )
             {