2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
30 #ifndef _IOKIT_ROOTDOMAIN_H
31 #define _IOKIT_ROOTDOMAIN_H
33 #include <IOKit/IOService.h>
34 #include <IOKit/pwr_mgt/IOPM.h>
36 class IOPMWorkArbiter
;
37 class IOPMPowerStateQueue
;
38 class RootDomainUserClient
;
41 kRootDomainSleepNotSupported
= 0x00000000,
42 kRootDomainSleepSupported
= 0x00000001,
43 kFrameBufferDeepSleepSupported
= 0x00000002,
44 kPCICantSleep
= 0x00000004
47 #define kRootDomainSupportedFeatures "Supported Features"
49 // Supported Feature bitfields for IOPMrootDomain::publishFeature()
51 kIOPMSupportedOnAC
= 1<<0,
52 kIOPMSupportedOnBatt
= 1<<1,
53 kIOPMSupportedOnUPS
= 1<<2
56 typedef IOReturn (*IOPMSettingControllerCallback
) \
57 (OSObject
*target
, const OSSymbol
*type
, \
58 OSObject
*val
, uintptr_t refcon
);
62 IONotifier
* registerSleepWakeInterest(
63 IOServiceInterestHandler
, void *, void * = 0);
65 IONotifier
* registerPrioritySleepWakeInterest(
66 IOServiceInterestHandler handler
,
67 void * self
, void * ref
= 0);
69 IOReturn
acknowledgeSleepWakeNotification(void * );
71 IOReturn
vetoSleepWakeNotification(void * PMrefcon
);
73 IOReturn
rootDomainRestart ( void );
75 IOReturn
rootDomainShutdown ( void );
78 #define IOPM_ROOTDOMAIN_REV 2
80 class IOPMrootDomain
: public IOService
82 OSDeclareDefaultStructors(IOPMrootDomain
)
86 class IOService
* wrangler
; // we tickle the wrangler on button presses, etc
88 IOPMWorkArbiter
* getPMArbiter(void);
90 static IOPMrootDomain
* construct( void );
91 virtual bool start( IOService
* provider
);
92 virtual IOReturn
setAggressiveness ( unsigned long, unsigned long );
93 virtual IOReturn
youAreRoot ( void );
94 virtual IOReturn
sleepSystem ( void );
95 virtual IOReturn
setProperties ( OSObject
* );
96 IOReturn
shutdownSystem ( void );
97 IOReturn
restartSystem ( void );
98 virtual IOReturn
receivePowerNotification (UInt32 msg
);
99 virtual void setSleepSupported( IOOptionBits flags
);
100 virtual IOOptionBits
getSleepSupported();
101 virtual IOReturn
requestPowerDomainState ( IOPMPowerFlags
, IOPowerConnection
*, unsigned long );
102 virtual void handleSleepTimerExpiration ( void );
103 void stopIgnoringClamshellEventsDuringWakeup ( void );
104 void wakeFromDoze( void );
105 void broadcast_it (unsigned long, unsigned long );
107 // KEXT driver announces support of power management feature
108 void publishFeature( const char *feature
);
110 // KEXT driver announces support of power management feature
111 // And specifies power sources with kIOPMSupportedOn{AC/Batt/UPS} bitfield.
112 // Returns a unique uint32_t identifier for later removing support for this
114 // NULL is acceptable for uniqueFeatureID for kexts without plans to unload.
115 void publishFeature( const char *feature
,
116 uint32_t supportedWhere
,
117 uint32_t *uniqueFeatureID
);
119 // KEXT driver announces removal of a previously published power management
120 // feature. Pass 'uniqueFeatureID' returned from publishFeature()
121 IOReturn
removePublishedFeature( uint32_t removeFeatureID
);
123 void unIdleDevice( IOService
*, unsigned long );
124 void announcePowerSourceChange( void );
126 // Override of these methods for logging purposes.
127 virtual IOReturn
changePowerStateTo ( unsigned long ordinal
);
128 virtual IOReturn
changePowerStateToPriv ( unsigned long ordinal
);
130 /*! @function copyPMSetting
131 @abstract Copy the current value for a PM setting. Returns OSNumber or
132 OSData depending on the setting.
133 @param whichSetting Name of the desired setting.
134 @result OSObject *value if valid, NULL otherwise. */
135 OSObject
*copyPMSetting(OSSymbol
*whichSetting
);
137 /*! @function registerPMSettingController
138 @abstract Register for callbacks on changes to certain PM settings.
139 @param settings NULL terminated array of C strings, each string for a PM
140 setting that the caller is interested in and wants to get callbacks for.
141 @param callout C function ptr or member function cast as such.
142 @param target The target of the callback, usually 'this'
143 @param refcon Will be passed to caller in callback; for caller's use.
144 @param handle Caller should keep the OSObject * returned here. If non-NULL,
145 handle will have a retain count of 1 on return. To deregister, pass to
146 unregisterPMSettingController()
147 @result kIOReturnSuccess on success. */
148 IOReturn
registerPMSettingController(
149 const OSSymbol
*settings
[],
150 IOPMSettingControllerCallback callout
,
153 OSObject
**handle
); // out param
155 /*! @function registerPMSettingController
156 @abstract Register for callbacks on changes to certain PM settings.
157 @param settings NULL terminated array of C strings, each string for a PM
158 setting that the caller is interested in and wants to get callbacks for.
159 @param supportedPowerSources bitfield indicating which power sources these
160 settings are supported for (kIOPMSupportedOnAC, etc.)
161 @param callout C function ptr or member function cast as such.
162 @param target The target of the callback, usually 'this'
163 @param refcon Will be passed to caller in callback; for caller's use.
164 @param handle Caller should keep the OSObject * returned here. If non-NULL,
165 handle will have a retain count of 1 on return. To deregister, pass to
166 unregisterPMSettingController()
167 @result kIOReturnSuccess on success. */
168 IOReturn
registerPMSettingController(
169 const OSSymbol
*settings
[],
170 uint32_t supportedPowerSources
,
171 IOPMSettingControllerCallback callout
,
174 OSObject
**handle
); // out param
178 // Points to our parent
179 class IORootParent
* patriarch
;
181 // Pref: idle time before idle sleep
184 // Pref: longest of other idle times (disk and display)
185 long longestNonSleepSlider
;
187 // Difference between sleepSlider and longestNonSleepSlider
188 long extraSleepDelay
;
190 // Used to wait between say display idle and system idle
191 thread_call_t extraSleepTimer
;
193 // Used to ignore clamshell close events while we're waking from sleep
194 thread_call_t clamshellWakeupIgnore
;
196 virtual void powerChangeDone ( unsigned long );
197 virtual void command_received ( void *, void * , void * , void *);
198 virtual bool tellChangeDown ( unsigned long stateNum
);
199 virtual bool askChangeDown ( unsigned long stateNum
);
200 virtual void tellChangeUp ( unsigned long );
201 virtual void tellNoChangeDown ( unsigned long );
202 void reportUserInput ( void );
203 static IOReturn
sysPowerDownHandler( void * target
, void * refCon
,
204 UInt32 messageType
, IOService
* service
,
205 void * messageArgument
, vm_size_t argSize
);
207 static IOReturn
displayWranglerNotification( void * target
, void * refCon
,
208 UInt32 messageType
, IOService
* service
,
209 void * messageArgument
, vm_size_t argSize
);
211 static bool displayWranglerPublished( void * target
, void * refCon
,
212 IOService
* newService
);
214 static bool batteryPublished( void * target
, void * refCon
,
215 IOService
* resourceService
);
217 void adjustPowerState ( void );
218 void setQuickSpinDownTimeout ( void );
219 void restoreUserSpinDownTimeout ( void );
221 bool shouldSleepOnClamshellClosed (void );
222 void sendClientClamshellNotification ( void );
224 IOLock
*featuresDictLock
; // guards supportedFeatures
225 IOPMPowerStateQueue
*pmPowerStateQueue
;
227 IOWorkLoop
*arbiterWorkLoop
;
228 IOPMWorkArbiter
*pmArbiter
;
230 unsigned int user_spindown
; // User's selected disk spindown value
232 unsigned int systemBooting
:1;
233 unsigned int ignoringClamshell
:1;
234 unsigned int allowSleep
:1;
235 unsigned int sleepIsSupported
:1;
236 unsigned int canSleep
:1;
237 unsigned int idleSleepPending
:1;
238 unsigned int sleepASAP
:1;
239 unsigned int desktopMode
:1;
241 unsigned int acAdaptorConnect
:1;
242 unsigned int ignoringClamshellDuringWakeup
:1;
243 unsigned int clamshellIsClosed
:1;
244 unsigned int clamshellExists
:1;
245 unsigned int reservedA
:4;
246 unsigned char reservedB
[3];
248 OSArray
*allowedPMSettings
;
250 // Settings controller info
251 IORecursiveLock
*settingsCtrlLock
;
252 OSDictionary
*settingsCallbacks
;
253 OSDictionary
*fPMSettingsDict
;
254 IOReturn
setPMSetting(const OSSymbol
*, OSObject
*);
256 thread_call_t diskSyncCalloutEntry
;
257 IONotifier
*_batteryPublishNotifier
;
258 IONotifier
*_displayWranglerNotifier
;
260 struct ExpansionData
{
262 ExpansionData
*_reserved
;
263 IOOptionBits platformSleepSupport
;
265 friend class PMSettingObject
;
268 class IORootParent
: public IOService
270 OSDeclareDefaultStructors(IORootParent
)
273 unsigned long mostRecentChange
;
277 virtual IOReturn
changePowerStateToPriv ( unsigned long ordinal
);
279 bool start ( IOService
* nub
);
280 void shutDownSystem ( void );
281 void restartSystem ( void );
282 void sleepSystem ( void );
283 void dozeSystem ( void );
284 void sleepToDoze ( void );
285 void wakeSystem ( void );
289 #endif /* _IOKIT_ROOTDOMAIN_H */