Loading...
iokit/Kernel/IOPMrootDomain.cpp xnu-792.21.3 xnu-517
--- xnu/xnu-792.21.3/iokit/Kernel/IOPMrootDomain.cpp
+++ xnu/xnu-517/iokit/Kernel/IOPMrootDomain.cpp
@@ -1,19 +1,16 @@
-/*
- * Copyright (c) 1998-2005 Apple Computer, Inc. All rights reserved.
+   /*
+ * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
  *
- * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
+ * @APPLE_LICENSE_HEADER_START@
+ * 
+ * Copyright (c) 1999-2003 Apple Computer, Inc.  All Rights Reserved.
  * 
  * 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.
+ * 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
@@ -23,7 +20,7 @@
  * Please see the License for the specific language governing rights and
  * limitations under the License.
  * 
- * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
+ * @APPLE_LICENSE_HEADER_END@
  */
 #include <IOKit/IOWorkLoop.h>
 #include <IOKit/IOCommandGate.h>
@@ -33,21 +30,24 @@
 #include <IOKit/IOTimeStamp.h>
 #include <IOKit/pwr_mgt/RootDomain.h>
 #include <IOKit/pwr_mgt/IOPMPrivate.h>
-#include <IOKit/IODeviceTreeSupport.h>
 #include <IOKit/IOMessage.h>
 #include "RootDomainUserClient.h"
 #include "IOKit/pwr_mgt/IOPowerConnection.h"
 #include "IOPMPowerStateQueue.h"
-#include <IOKit/IOCatalogue.h>
-#include <IOKit/IOHibernatePrivate.h>
-
-#ifdef __ppc__
-#include <ppc/pms.h>
-#endif
 
 extern "C" void kprintf(const char *, ...);
 
 extern const IORegistryPlane * gIOPowerPlane;
+
+// debug trace function
+static inline void
+ioSPMTrace(unsigned int csc,
+	   unsigned int a = 0, unsigned int b = 0,
+	   unsigned int c = 0, unsigned int d = 0)
+{
+    if (gIOKitDebug & kIOLogTracePower)
+	IOTimeStampConstant(IODBG_POWER(csc), a, b, c, d);
+}
 
 IOReturn broadcast_aggressiveness ( OSObject *, void *, void *, void *, void * );
 static void sleepTimerExpired(thread_call_param_t);
@@ -74,13 +74,6 @@
     {1,kIOPMPowerOn,		kIOPMPowerOn,	ON_POWER,0,0,0,0,0,0,0,0},	// state 4, on
 };
 
-// RESERVED IOPMrootDomain class variables
-#define diskSyncCalloutEntry                _reserved->diskSyncCalloutEntry
-#define _settingController                  _reserved->_settingController
-#define _batteryLocationNotifier            _reserved->_batteryLocationNotifier
-#define _displayWranglerNotifier            _reserved->_displayWranglerNotifier
-
-
 static IOPMrootDomain * gRootDomain;
 static UInt32           gSleepOrShutdownPending = 0;
 
@@ -90,12 +83,12 @@
 
 extern "C"
 {
-    IONotifier * registerSleepWakeInterest(IOServiceInterestHandler handler, void * self, void * ref)
+    IONotifier * registerSleepWakeInterest(IOServiceInterestHandler handler, void * self, void * ref = 0)
     {
         return gRootDomain->registerInterest( gIOGeneralInterest, handler, self, ref );
     }
 
-    IONotifier * registerPrioritySleepWakeInterest(IOServiceInterestHandler handler, void * self, void * ref)
+    IONotifier * registerPrioritySleepWakeInterest(IOServiceInterestHandler handler, void * self, void * ref = 0)
     {
         return gRootDomain->registerInterest( gIOPriorityPowerStateInterest, handler, self, ref );
     }
@@ -122,7 +115,6 @@
 
 	void IOSystemShutdownNotification ( void )
     {
-	IOCatalogue::disableExternalLinker();
         for ( int i = 0; i < 100; i++ )
         {
             if ( OSCompareAndSwap( 0, 1, &gSleepOrShutdownPending ) ) break;
@@ -174,6 +166,7 @@
 to be tickled)).
 */
 
+
 // **********************************************************************************
 
 IOPMrootDomain * IOPMrootDomain::construct( void )
@@ -194,7 +187,6 @@
     IOService                               *rootDomain = (IOService *) p0;
     unsigned long                           pmRef = (unsigned long) p1;
 
-    IOHibernateSystemSleep();
     sync_internal();
     rootDomain->allowPowerChange(pmRef);
 }
@@ -213,16 +205,12 @@
 
     pmPowerStateQueue = 0;
 
-    _reserved = (ExpansionData *)IOMalloc(sizeof(ExpansionData));
-    if(!_reserved) return false;
-
     super::start(nub);
 
     gRootDomain = this;
 
     PMinit();
     setProperty("IOSleepSupported","");
-
     allowSleep = true;
     sleepIsSupported = true;
     systemBooting = true;
@@ -232,18 +220,15 @@
     canSleep = true;
     wrangler = NULL;
     sleepASAP = false;
-    _settingController = NULL;
     ignoringClamshellDuringWakeup = false;
     
     tmpDict = OSDictionary::withCapacity(1);
     setProperty(kRootDomainSupportedFeatures, tmpDict);
     tmpDict->release();
-    
+
     pm_vars->PMworkloop = IOWorkLoop::workLoop();				
     pmPowerStateQueue = IOPMPowerStateQueue::PMPowerStateQueue(this);
     pm_vars->PMworkloop->addEventSource(pmPowerStateQueue);
-    
-    featuresDictLock = IOLockAlloc();
     
     extraSleepTimer = thread_call_allocate((thread_call_func_t)sleepTimerExpired, (thread_call_param_t) this);
     clamshellWakeupIgnore = thread_call_allocate((thread_call_func_t)wakeupClamshellTimerExpired, (thread_call_param_t) this);
@@ -257,7 +242,7 @@
     patriarch->youAreRoot();
     patriarch->wakeSystem();
     patriarch->addPowerChild(this);
-        
+    
     registerPowerDriver(this,ourPowerStates,number_of_power_states);
 
     setPMRootDomain(this);
@@ -268,46 +253,15 @@
     registerPrioritySleepWakeInterest( &sysPowerDownHandler, this, 0);
 
     // Register for a notification when IODisplayWrangler is published
-    _displayWranglerNotifier = addNotification( gIOPublishNotification, 
-                                                serviceMatching("IODisplayWrangler"), 
-                                                &displayWranglerPublished, this, 0);
-
-    _batteryLocationNotifier = addNotification( gIOPublishNotification, 
-                                                resourceMatching("battery"), 
-                                                &batteryLocationPublished, this, this);
+    addNotification( gIOPublishNotification, serviceMatching("IODisplayWrangler"), &displayWranglerPublished, this, 0);
 
     const OSSymbol *ucClassName = OSSymbol::withCStringNoCopy("RootDomainUserClient");
-    setProperty(gIOUserClientClassKey, (OSObject *) ucClassName);
+    setProperty(gIOUserClientClassKey, (OSMetaClassBase *) ucClassName);
     ucClassName->release();
 
-    IORegistryEntry     *temp_entry = NULL;
-    if( (temp_entry = IORegistryEntry::fromPath("mac-io/battery", gIODTPlane)) ||
-        (temp_entry = IORegistryEntry::fromPath("mac-io/via-pmu/battery", gIODTPlane)))
-    {
-        // If this machine has a battery, publish the fact that the backlight
-        //    supports dimming.
-        // Notice similar call in IOPMrootDomain::batteryLocationPublished() to 
-        //    detect batteries on SMU machines.
-        publishFeature("DisplayDims");
-        temp_entry->release();
-    }
-
-    IOHibernateSystemInit(this);
-
     registerService();						// let clients find us
 
     return true;
-}
-
-IOReturn     IOPMrootDomain::setPMSetting(int type, OSNumber *n)
-{
-    if(_settingController && _settingController->func) {
-        int         seconds;
-        seconds = n->unsigned32BitValue();
-        return (*(_settingController->func))(type, seconds, _settingController->refcon);
-    } else {
-        return kIOReturnNoDevice;
-    }   
 }
 
 // **********************************************************************************
@@ -318,142 +272,24 @@
 // **********************************************************************************
 IOReturn IOPMrootDomain::setProperties ( OSObject *props_obj)
 {
-    IOReturn                            return_value = kIOReturnSuccess;
     OSDictionary                        *dict = OSDynamicCast(OSDictionary, props_obj);
     OSBoolean                           *b;
-    OSNumber                            *n;
-    OSString                            *str;
-    const OSSymbol                      *boot_complete_string = OSSymbol::withCString("System Boot Complete");
-    const OSSymbol                            *power_button_string = OSSymbol::withCString("DisablePowerButtonSleep");
-    const OSSymbol                            *stall_halt_string = OSSymbol::withCString("StallSystemAtHalt");
-    const OSSymbol                            *auto_wake_string = OSSymbol::withCString("wake");
-    const OSSymbol                            *auto_power_string = OSSymbol::withCString("poweron");
-    const OSSymbol                            *wakeonring_string = OSSymbol::withCString("WakeOnRing");
-    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) 
-    {
-        return_value = kIOReturnBadArgument;
-        goto exit;
-    }
-
-    if( systemBooting 
-        && boot_complete_string 
-        && dict->getObject(boot_complete_string)) 
+    
+    if(!dict) return kIOReturnBadArgument;
+
+    if(systemBooting && dict->getObject(OSString::withCString("System Boot Complete"))) 
     {
         systemBooting = false;
+        //kprintf("IOPM: received System Boot Complete property\n");
         adjustPowerState();
     }
     
-    if( power_button_string
-        && (b = OSDynamicCast(OSBoolean, dict->getObject(power_button_string))) ) 
-    {
-        setProperty(power_button_string, b);
-    }
-
-    if( stall_halt_string
-        && (b = OSDynamicCast(OSBoolean, dict->getObject(stall_halt_string))) ) 
-    {
-        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
-        && (n = OSDynamicCast(OSNumber, dict->getObject(auto_wake_string))) )
-    {
-        return_value = setPMSetting(kIOPMAutoWakeSetting, n);
-        if(kIOReturnSuccess != return_value) goto exit;
-    }
-
-    // Relay AutoPower setting to its controller
-    if( auto_power_string
-        && (n = OSDynamicCast(OSNumber, dict->getObject(auto_power_string))) )
-    {
-        return_value = setPMSetting(kIOPMAutoPowerOnSetting, n);
-        if(kIOReturnSuccess != return_value) goto exit;
-    }
-
-    // Relay WakeOnRing setting to its controller
-    if( wakeonring_string
-        && (n = OSDynamicCast(OSNumber, dict->getObject(wakeonring_string))) )
-    {
-        return_value = setPMSetting(kIOPMWakeOnRingSetting, n);
-        if(kIOReturnSuccess != return_value) goto exit;
-    }
-
-    // Relay FileServer setting to its controller
-    if( fileserver_string
-        && (n = OSDynamicCast(OSNumber, dict->getObject(fileserver_string))) )
-    {
-        return_value = setPMSetting(kIOPMAutoRestartOnPowerLossSetting, n);
-        if(kIOReturnSuccess != return_value) goto exit;
-    }
-
-    // Relay WakeOnLid setting to its controller
-    if( wakeonlid_string 
-        && (n = OSDynamicCast(OSNumber, dict->getObject(wakeonlid_string))) )
-    {
-        return_value = setPMSetting(kIOPMWakeOnLidSetting, n);
-        if(kIOReturnSuccess != return_value) goto exit;
-    }
-    
-    // Relay WakeOnACChange setting to its controller
-    if( wakeonac_string
-        && (n = OSDynamicCast(OSNumber, dict->getObject(wakeonac_string))) )
-    {
-        return_value = setPMSetting(kIOPMWakeOnACChangeSetting, n);
-        if(kIOReturnSuccess != return_value) goto exit;
-    }
-
-    // Relay timezone offset in seconds to SMU
-    if( timezone_string
-        && (n = OSDynamicCast(OSNumber, dict->getObject(timezone_string))) )
-    {
-        return_value = setPMSetting(kIOPMTimeZoneSetting, n);
-        if(kIOReturnSuccess != return_value) goto exit;
-    }
-
-
-    exit:
-    if(boot_complete_string) boot_complete_string->release();
-    if(power_button_string) power_button_string->release();
-    if(stall_halt_string) stall_halt_string->release();
-    if(auto_wake_string) auto_wake_string->release();
-    if(auto_power_string) auto_power_string->release();
-    if(wakeonring_string) wakeonring_string->release();
-    if(fileserver_string) fileserver_string->release();
-    if(wakeonlid_string) wakeonlid_string->release();
-    if(wakeonac_string) wakeonac_string->release();
-    if(timezone_string) timezone_string->release();
-    return return_value;
+    if(b = dict->getObject(OSString::withCString("DisablePowerButtonSleep"))) 
+    {
+        setProperty(OSString::withCString("DisablePowerButtonSleep"), b);
+    }
+        
+    return kIOReturnSuccess;
 }
 
 
@@ -585,24 +421,8 @@
 // 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);
     }
@@ -620,7 +440,6 @@
     //kprintf("sleep demand received\n");
     if ( !systemBooting && allowSleep && sleepIsSupported ) {
         patriarch->sleepSystem();
-
         return kIOReturnSuccess;
     }
     if ( !systemBooting && allowSleep && !sleepIsSupported ) {
@@ -677,18 +496,14 @@
             {
                 // re-enable this timer for next sleep
                 idleSleepPending = false;			
-
-                IOLog("System %sSleep\n", gIOHibernateState ? "Safe" : "");
-
-                IOHibernateSystemHasSlept();
-
+                IOLog("System Sleep\n");
                 pm_vars->thePlatform->sleepKernel();
 
                 // The CPU(s) are off at this point. When they're awakened by CPU interrupt,
-                // code will resume execution here.
-
+                // code will resume exeuction here.
+                
                 // Now we're waking...
-		IOHibernateSystemWake();
+                ioSPMTrace(IOPOWER_WAKE, * (int *) this);
 
                 // stay awake for at least 30 seconds
                 clock_interval_to_deadline(30, kSecondScale, &deadline);	
@@ -713,7 +528,7 @@
                 tellClients(kIOMessageSystemWillPowerOn);
 
                 // tell the tree we're waking
-                IOLog("System %sWake\n", gIOHibernateState ? "SafeSleep " : "");
+                IOLog("System Wake\n");
                 systemWake();
                 
                 // Allow drivers to request extra processing time before clamshell
@@ -809,21 +624,10 @@
 // **********************************************************************************
 void IOPMrootDomain::publishFeature( const char * feature )
 {
-    if(featuresDictLock) IOLockLock(featuresDictLock);
-    OSDictionary *features =
-        (OSDictionary *) getProperty(kRootDomainSupportedFeatures);
-    
-    if ( features && OSDynamicCast(OSDictionary, features))
-        features = OSDictionary::withDictionary(features);
-    else
-        features = OSDictionary::withCapacity(1);
-
-    features->setObject(feature, kOSBooleanTrue);
-    setProperty(kRootDomainSupportedFeatures, features);
-    features->release();
-    if(featuresDictLock) IOLockUnlock(featuresDictLock);
-}
-
+  OSDictionary *features = (OSDictionary *)getProperty(kRootDomainSupportedFeatures);
+  
+  features->setObject(feature, kOSBooleanTrue);
+}
 
 void IOPMrootDomain::unIdleDevice( IOService *theDevice, unsigned long theState )
 {
@@ -833,34 +637,8 @@
 
 void IOPMrootDomain::announcePowerSourceChange( void )
 {
-    IORegistryEntry                 *_batteryRegEntry = (IORegistryEntry *) getProperty("BatteryEntry");
-
-    // (if possible) re-publish power source state under IOPMrootDomain
-    // (only done if the battery controller publishes an IOResource defining battery location)
-    if(_batteryRegEntry)
-    {
-        OSArray             *batt_info;
-        batt_info = (OSArray *) _batteryRegEntry->getProperty(kIOBatteryInfoKey);
-        if(batt_info)
-            setProperty(kIOBatteryInfoKey, batt_info);
-    }
-
     messageClients(kIOPMMessageBatteryStatusHasChanged);
 }
-
-IOReturn IOPMrootDomain::registerPMSettingController
-        (IOPMSettingControllerCallback func, void *info)
-{
-    if(_settingController) return kIOReturnExclusiveAccess;
-    
-    _settingController = (PMSettingCtrl *)IOMalloc(sizeof(PMSettingCtrl));
-    if(!_settingController) return kIOReturnNoMemory;
-    
-    _settingController->func = func;
-    _settingController->refcon = info;
-    return kIOReturnSuccess;
-}
-
 
 //*********************************************************************************
 // receivePowerNotification
@@ -1141,7 +919,6 @@
 {
     if ( stateNum == ON_STATE ) 
     {
-	IOHibernateSystemPostWake();
         return tellClients(kIOMessageSystemHasPoweredOn);
     }
 }
@@ -1197,11 +974,15 @@
 
 IOReturn IOPMrootDomain::changePowerStateTo ( unsigned long ordinal )
 {
+    ioSPMTrace(IOPOWER_ROOT, * (int *) this, (int) true, (int) ordinal);
+
     return super::changePowerStateTo(ordinal);
 }
 
 IOReturn IOPMrootDomain::changePowerStateToPriv ( unsigned long ordinal )
 {
+    ioSPMTrace(IOPOWER_ROOT, * (int *) this, (int) false, (int) ordinal);
+
     return super::changePowerStateToPriv(ordinal);
 }
 
@@ -1241,8 +1022,6 @@
 
             // 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 ) )
             {
@@ -1380,36 +1159,6 @@
     return true;
 }
 
-//*********************************************************************************
-// batteryLocationPublished
-//
-// Notification on AppleSMU publishing location of battery data
-//
-//*********************************************************************************
-
-bool IOPMrootDomain::batteryLocationPublished( void * target, void * root_domain,
-        IOService * resourceService )
-{
-    IORegistryEntry                     *battery_location;
-
-    battery_location = (IORegistryEntry *) resourceService->getProperty("battery");
-    if (!battery_location || !OSDynamicCast(IORegistryEntry, battery_location))
-        return (true);
-        
-    ((IOPMrootDomain *)root_domain)->setProperty("BatteryEntry", battery_location);
-    
-    // rdar://2936060
-    // All laptops have dimmable LCD displays
-    // All laptops have batteries
-    // So if this machine has a battery, publish the fact that the backlight
-    // supports dimming.
-    ((IOPMrootDomain *)root_domain)->publishFeature("DisplayDims");
-    
-    ((IOPMrootDomain *)root_domain)->announcePowerSourceChange();
-    return (true);
-}
-
-
 
 //*********************************************************************************
 // adjustPowerState