Loading...
iokit/Kernel/IOPMrootDomain.cpp xnu-792 xnu-517.7.21
--- xnu/xnu-792/iokit/Kernel/IOPMrootDomain.cpp
+++ xnu/xnu-517.7.21/iokit/Kernel/IOPMrootDomain.cpp
@@ -1,4 +1,4 @@
-/*
+   /*
  * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
  *
  * @APPLE_LICENSE_HEADER_START@
@@ -27,50 +27,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/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);
-}
-
-
-/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
-
 
 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);
@@ -113,12 +87,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 );
     }
@@ -145,7 +119,6 @@
 
 	void IOSystemShutdownNotification ( void )
     {
-	IOCatalogue::disableExternalLinker();
         for ( int i = 0; i < 100; i++ )
         {
             if ( OSCompareAndSwap( 0, 1, &gSleepOrShutdownPending ) ) break;
@@ -244,7 +217,6 @@
 
     PMinit();
     setProperty("IOSleepSupported","");
-
     allowSleep = true;
     sleepIsSupported = true;
     systemBooting = true;
@@ -260,12 +232,10 @@
     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);
@@ -299,21 +269,8 @@
                                                 &batteryLocationPublished, this, this);
 
     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();
-    }
-
 
     registerService();						// let clients find us
 
@@ -343,17 +300,15 @@
     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                            *timezone_string = OSSymbol::withCString("TimeZoneOffsetSeconds");
+    OSString                            *boot_complete_string = OSString::withCString("System Boot Complete");
+    OSString                            *power_button_string = OSString::withCString("DisablePowerButtonSleep");
+    OSString                            *stall_halt_string = OSString::withCString("StallSystemAtHalt");
+    OSString                            *auto_wake_string = OSString::withCString("wake");
+    OSString                            *auto_power_string = OSString::withCString("poweron");
+    OSString                            *wakeonring_string = OSString::withCString("WakeOnRing");
+    OSString                            *fileserver_string = OSString::withCString("AutoRestartOnPowerLoss");
+    OSString                            *wakeonlid_string = OSString::withCString("WakeOnLid");
+    OSString                            *wakeonac_string = OSString::withCString("WakeOnACChange");
     
     if(!dict) 
     {
@@ -380,8 +335,7 @@
     {
         setProperty(stall_halt_string, b);
     }
-
-
+    
     // Relay AutoWake setting to its controller
     if( auto_wake_string
         && (n = OSDynamicCast(OSNumber, dict->getObject(auto_wake_string))) )
@@ -427,14 +381,6 @@
         && (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;
     }
 
@@ -449,7 +395,6 @@
     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;
 }
 
@@ -601,7 +546,6 @@
     //kprintf("sleep demand received\n");
     if ( !systemBooting && allowSleep && sleepIsSupported ) {
         patriarch->sleepSystem();
-
         return kIOReturnSuccess;
     }
     if ( !systemBooting && allowSleep && !sleepIsSupported ) {
@@ -658,14 +602,14 @@
             {
                 // re-enable this timer for next sleep
                 idleSleepPending = false;			
-
                 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...
+                ioSPMTrace(IOPOWER_WAKE, * (int *) this);
 
                 // stay awake for at least 30 seconds
                 clock_interval_to_deadline(30, kSecondScale, &deadline);	
@@ -786,21 +730,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 )
 {
@@ -810,14 +743,14 @@
 
 void IOPMrootDomain::announcePowerSourceChange( void )
 {
-    IORegistryEntry                 *_batteryRegEntry = (IORegistryEntry *) getProperty("BatteryEntry");
+    IORegistryEntry                 *_batteryRegEntry = 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);
+        batt_info = _batteryRegEntry->getProperty(kIOBatteryInfoKey);
         if(batt_info)
             setProperty(kIOBatteryInfoKey, batt_info);
     }
@@ -1173,11 +1106,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);
 }
 
@@ -1365,19 +1302,14 @@
         IOService * resourceService )
 {
     IORegistryEntry                     *battery_location;
-
-    battery_location = (IORegistryEntry *) resourceService->getProperty("battery");
+    char                                battery_reg_path[255];
+    int                                 path_len = 255;
+
+    battery_location = 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);