2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 #ifndef _IOKIT_ROOTDOMAIN_H
23 #define _IOKIT_ROOTDOMAIN_H
25 #include <IOKit/IOService.h>
26 #include <IOKit/pwr_mgt/IOPM.h>
28 class IOPMPowerStateQueue
;
29 class RootDomainUserClient
;
32 kRootDomainSleepNotSupported
= 0x00000000,
33 kRootDomainSleepSupported
= 0x00000001,
34 kFrameBufferDeepSleepSupported
= 0x00000002,
35 kPCICantSleep
= 0x00000004
38 #define kRootDomainSupportedFeatures "Supported Features"
40 // Supported Feature bitfields for IOPMrootDomain::publishFeature()
42 kIOPMSupportedOnAC
= 1<<0,
43 kIOPMSupportedOnBatt
= 1<<1,
44 kIOPMSupportedOnUPS
= 1<<2
47 typedef IOReturn (*IOPMSettingControllerCallback
) \
48 (OSObject
*target
, const OSSymbol
*type
, \
49 OSObject
*val
, uintptr_t refcon
);
53 IONotifier
* registerSleepWakeInterest(
54 IOServiceInterestHandler
, void *, void * = 0);
56 IONotifier
* registerPrioritySleepWakeInterest(
57 IOServiceInterestHandler handler
,
58 void * self
, void * ref
= 0);
60 IOReturn
acknowledgeSleepWakeNotification(void * );
62 IOReturn
vetoSleepWakeNotification(void * PMrefcon
);
64 IOReturn
rootDomainRestart ( void );
66 IOReturn
rootDomainShutdown ( void );
69 #define IOPM_ROOTDOMAIN_REV 2
71 class IOPMrootDomain
: public IOService
73 OSDeclareDefaultStructors(IOPMrootDomain
)
77 class IOService
* wrangler
; // we tickle the wrangler on button presses, etc
79 static IOPMrootDomain
* construct( void );
80 virtual bool start( IOService
* provider
);
81 virtual IOReturn
setAggressiveness ( unsigned long, unsigned long );
82 virtual IOReturn
youAreRoot ( void );
83 virtual IOReturn
sleepSystem ( void );
84 virtual IOReturn
setProperties ( OSObject
* );
85 IOReturn
shutdownSystem ( void );
86 IOReturn
restartSystem ( void );
87 virtual IOReturn
receivePowerNotification (UInt32 msg
);
88 virtual void setSleepSupported( IOOptionBits flags
);
89 virtual IOOptionBits
getSleepSupported();
90 virtual IOReturn
requestPowerDomainState ( IOPMPowerFlags
, IOPowerConnection
*, unsigned long );
91 virtual void handleSleepTimerExpiration ( void );
92 void stopIgnoringClamshellEventsDuringWakeup ( void );
93 void wakeFromDoze( void );
94 void broadcast_it (unsigned long, unsigned long );
96 // KEXT driver announces support of power management feature
97 void publishFeature( const char *feature
);
99 // KEXT driver announces support of power management feature
100 // And specifies power sources with kIOPMSupportedOn{AC/Batt/UPS} bitfield.
101 // Returns a unique uint32_t identifier for later removing support for this
103 // NULL is acceptable for uniqueFeatureID for kexts without plans to unload.
104 void publishFeature( const char *feature
,
105 uint32_t supportedWhere
,
106 uint32_t *uniqueFeatureID
);
108 // KEXT driver announces removal of a previously published power management
109 // feature. Pass 'uniqueFeatureID' returned from publishFeature()
110 IOReturn
removePublishedFeature( uint32_t removeFeatureID
);
112 void unIdleDevice( IOService
*, unsigned long );
113 void announcePowerSourceChange( void );
115 // Override of these methods for logging purposes.
116 virtual IOReturn
changePowerStateTo ( unsigned long ordinal
);
117 virtual IOReturn
changePowerStateToPriv ( unsigned long ordinal
);
119 /*! @function copyPMSetting
120 @abstract Copy the current value for a PM setting. Returns OSNumber or
121 OSData depending on the setting.
122 @param whichSetting Name of the desired setting.
123 @result OSObject *value if valid, NULL otherwise. */
124 OSObject
*copyPMSetting(OSSymbol
*whichSetting
);
126 /*! @function registerPMSettingController
127 @abstract Register for callbacks on changes to certain PM settings.
128 @param settings NULL terminated array of C strings, each string for a PM
129 setting that the caller is interested in and wants to get callbacks for.
130 @param callout C function ptr or member function cast as such.
131 @param target The target of the callback, usually 'this'
132 @param refcon Will be passed to caller in callback; for caller's use.
133 @param handle Caller should keep the OSObject * returned here. If non-NULL,
134 handle will have a retain count of 1 on return. To deregister, pass to
135 unregisterPMSettingController()
136 @result kIOReturnSuccess on success. */
137 IOReturn
registerPMSettingController(
138 const OSSymbol
*settings
[],
139 IOPMSettingControllerCallback callout
,
142 OSObject
**handle
); // out param
144 /*! @function registerPMSettingController
145 @abstract Register for callbacks on changes to certain PM settings.
146 @param settings NULL terminated array of C strings, each string for a PM
147 setting that the caller is interested in and wants to get callbacks for.
148 @param supportedPowerSources bitfield indicating which power sources these
149 settings are supported for (kIOPMSupportedOnAC, etc.)
150 @param callout C function ptr or member function cast as such.
151 @param target The target of the callback, usually 'this'
152 @param refcon Will be passed to caller in callback; for caller's use.
153 @param handle Caller should keep the OSObject * returned here. If non-NULL,
154 handle will have a retain count of 1 on return. To deregister, pass to
155 unregisterPMSettingController()
156 @result kIOReturnSuccess on success. */
157 IOReturn
registerPMSettingController(
158 const OSSymbol
*settings
[],
159 uint32_t supportedPowerSources
,
160 IOPMSettingControllerCallback callout
,
163 OSObject
**handle
); // out param
167 // Points to our parent
168 class IORootParent
* patriarch
;
170 // Pref: idle time before idle sleep
173 // Pref: longest of other idle times (disk and display)
174 long longestNonSleepSlider
;
176 // Difference between sleepSlider and longestNonSleepSlider
177 long extraSleepDelay
;
179 // Used to wait between say display idle and system idle
180 thread_call_t extraSleepTimer
;
182 // Used to ignore clamshell close events while we're waking from sleep
183 thread_call_t clamshellWakeupIgnore
;
185 virtual void powerChangeDone ( unsigned long );
186 virtual void command_received ( void *, void * , void * , void *);
187 virtual bool tellChangeDown ( unsigned long stateNum
);
188 virtual bool askChangeDown ( unsigned long stateNum
);
189 virtual void tellChangeUp ( unsigned long );
190 virtual void tellNoChangeDown ( unsigned long );
191 void reportUserInput ( void );
192 static IOReturn
sysPowerDownHandler( void * target
, void * refCon
,
193 UInt32 messageType
, IOService
* service
,
194 void * messageArgument
, vm_size_t argSize
);
196 static IOReturn
displayWranglerNotification( void * target
, void * refCon
,
197 UInt32 messageType
, IOService
* service
,
198 void * messageArgument
, vm_size_t argSize
);
200 static bool displayWranglerPublished( void * target
, void * refCon
,
201 IOService
* newService
);
203 static bool batteryPublished( void * target
, void * refCon
,
204 IOService
* resourceService
);
206 void adjustPowerState ( void );
207 void setQuickSpinDownTimeout ( void );
208 void restoreUserSpinDownTimeout ( void );
210 bool shouldSleepOnClamshellClosed (void );
211 void sendClientClamshellNotification ( void );
213 IOLock
*featuresDictLock
; // guards supportedFeatures
214 IOPMPowerStateQueue
*pmPowerStateQueue
;
215 unsigned int user_spindown
; // User's selected disk spindown value
217 unsigned int systemBooting
:1;
218 unsigned int ignoringClamshell
:1;
219 unsigned int allowSleep
:1;
220 unsigned int sleepIsSupported
:1;
221 unsigned int canSleep
:1;
222 unsigned int idleSleepPending
:1;
223 unsigned int sleepASAP
:1;
224 unsigned int desktopMode
:1;
226 unsigned int acAdaptorConnect
:1;
227 unsigned int ignoringClamshellDuringWakeup
:1;
228 unsigned int clamshellIsClosed
:1;
229 unsigned int clamshellExists
:1;
230 unsigned int reservedA
:4;
231 unsigned char reservedB
[3];
233 OSArray
*allowedPMSettings
;
235 // Settings controller info
236 IORecursiveLock
*settingsCtrlLock
;
237 OSDictionary
*settingsCallbacks
;
238 OSDictionary
*fPMSettingsDict
;
239 IOReturn
setPMSetting(const OSSymbol
*, OSObject
*);
241 thread_call_t diskSyncCalloutEntry
;
242 IONotifier
*_batteryPublishNotifier
;
243 IONotifier
*_displayWranglerNotifier
;
245 struct ExpansionData
{
247 ExpansionData
*_reserved
;
248 IOOptionBits platformSleepSupport
;
250 friend class PMSettingObject
;
253 class IORootParent
: public IOService
255 OSDeclareDefaultStructors(IORootParent
)
258 unsigned long mostRecentChange
;
262 virtual IOReturn
changePowerStateToPriv ( unsigned long ordinal
);
264 bool start ( IOService
* nub
);
265 void shutDownSystem ( void );
266 void restartSystem ( void );
267 void sleepSystem ( void );
268 void dozeSystem ( void );
269 void sleepToDoze ( void );
270 void wakeSystem ( void );
274 #endif /* _IOKIT_ROOTDOMAIN_H */