]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/pwr_mgt/RootDomain.h
xnu-1228.0.2.tar.gz
[apple/xnu.git] / iokit / IOKit / pwr_mgt / RootDomain.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
8f6c56a5 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28#ifndef _IOKIT_ROOTDOMAIN_H
29#define _IOKIT_ROOTDOMAIN_H
30
31#include <IOKit/IOService.h>
32#include <IOKit/pwr_mgt/IOPM.h>
33
55e303ae 34class IOPMPowerStateQueue;
1c79356b
A
35class RootDomainUserClient;
36
37enum {
38 kRootDomainSleepNotSupported = 0x00000000,
39 kRootDomainSleepSupported = 0x00000001,
0b4e3aa0
A
40 kFrameBufferDeepSleepSupported = 0x00000002,
41 kPCICantSleep = 0x00000004
1c79356b
A
42};
43
2d21ac55
A
44/*
45 *IOPMrootDomain registry property keys
46 */
47#define kRootDomainSupportedFeatures "Supported Features"
48#define kRootDomainSleepReasonKey "Last Sleep Reason"
49#define kRootDomainSleepOptionsKey "Last Sleep Options"
50
51/*
52 * Possible sleep reasons found under kRootDomainSleepReasonsKey
53 */
54#define kIOPMClamshellSleepKey "Clamshell Sleep"
55#define kIOPMPowerButtonSleepKey "Power Button Sleep"
56#define kIOPMSoftwareSleepKey "Software Sleep"
57#define kIOPMOSSwitchHibernationKey "OS Switch Sleep"
58#define kIOPMIdleSleepKey "Idle Sleep"
59#define kIOPMLowPowerSleepKey "Low Power Sleep"
60#define kIOPMThermalEmergencySleepKey "Thermal Emergency Sleep"
61
62/*
63 * String constants for communication with PM CPU
64 */
65#define kIOPMRootDomainLidCloseCString "LidClose"
66#define kIOPMRootDomainBatPowerCString "BatPower"
0c530ab8
A
67
68// Supported Feature bitfields for IOPMrootDomain::publishFeature()
e5568f75 69enum {
0c530ab8
A
70 kIOPMSupportedOnAC = 1<<0,
71 kIOPMSupportedOnBatt = 1<<1,
72 kIOPMSupportedOnUPS = 1<<2
e5568f75 73};
4452a7af 74
0c530ab8
A
75typedef IOReturn (*IOPMSettingControllerCallback) \
76 (OSObject *target, const OSSymbol *type, \
77 OSObject *val, uintptr_t refcon);
4452a7af 78
6601e61a
A
79extern "C"
80{
0c530ab8
A
81 IONotifier * registerSleepWakeInterest(
82 IOServiceInterestHandler, void *, void * = 0);
83
84 IONotifier * registerPrioritySleepWakeInterest(
85 IOServiceInterestHandler handler,
86 void * self, void * ref = 0);
87
88 IOReturn acknowledgeSleepWakeNotification(void * );
89
90 IOReturn vetoSleepWakeNotification(void * PMrefcon);
91
92 IOReturn rootDomainRestart ( void );
93
94 IOReturn rootDomainShutdown ( void );
1c79356b
A
95}
96
d52fe63f 97#define IOPM_ROOTDOMAIN_REV 2
1c79356b
A
98
99class IOPMrootDomain: public IOService
100{
101OSDeclareDefaultStructors(IOPMrootDomain)
102
103public:
104
0b4e3aa0
A
105 class IOService * wrangler; // we tickle the wrangler on button presses, etc
106
107 static IOPMrootDomain * construct( void );
108 virtual bool start( IOService * provider );
1c79356b
A
109 virtual IOReturn setAggressiveness ( unsigned long, unsigned long );
110 virtual IOReturn youAreRoot ( void );
2d21ac55 111
1c79356b 112 virtual IOReturn sleepSystem ( void );
2d21ac55
A
113 IOReturn sleepSystemOptions ( OSDictionary *options );
114
9bccf70c 115 virtual IOReturn setProperties ( OSObject * );
0b4e3aa0
A
116 IOReturn shutdownSystem ( void );
117 IOReturn restartSystem ( void );
1c79356b
A
118 virtual IOReturn receivePowerNotification (UInt32 msg);
119 virtual void setSleepSupported( IOOptionBits flags );
120 virtual IOOptionBits getSleepSupported();
0b4e3aa0
A
121 virtual IOReturn requestPowerDomainState ( IOPMPowerFlags, IOPowerConnection *, unsigned long );
122 virtual void handleSleepTimerExpiration ( void );
d52fe63f 123 void stopIgnoringClamshellEventsDuringWakeup ( void );
0b4e3aa0 124 void wakeFromDoze( void );
9bccf70c 125 void broadcast_it (unsigned long, unsigned long );
0c530ab8
A
126
127 // KEXT driver announces support of power management feature
d52fe63f 128 void publishFeature( const char *feature );
0c530ab8
A
129
130 // KEXT driver announces support of power management feature
131 // And specifies power sources with kIOPMSupportedOn{AC/Batt/UPS} bitfield.
132 // Returns a unique uint32_t identifier for later removing support for this
133 // feature.
134 // NULL is acceptable for uniqueFeatureID for kexts without plans to unload.
135 void publishFeature( const char *feature,
136 uint32_t supportedWhere,
137 uint32_t *uniqueFeatureID);
138
139 // KEXT driver announces removal of a previously published power management
140 // feature. Pass 'uniqueFeatureID' returned from publishFeature()
141 IOReturn removePublishedFeature( uint32_t removeFeatureID );
142
55e303ae
A
143 void unIdleDevice( IOService *, unsigned long );
144 void announcePowerSourceChange( void );
0c530ab8 145
9bccf70c
A
146 // Override of these methods for logging purposes.
147 virtual IOReturn changePowerStateTo ( unsigned long ordinal );
148 virtual IOReturn changePowerStateToPriv ( unsigned long ordinal );
149
0c530ab8
A
150/*! @function copyPMSetting
151 @abstract Copy the current value for a PM setting. Returns OSNumber or
152 OSData depending on the setting.
153 @param whichSetting Name of the desired setting.
154 @result OSObject *value if valid, NULL otherwise. */
155 OSObject *copyPMSetting(OSSymbol *whichSetting);
156
157/*! @function registerPMSettingController
158 @abstract Register for callbacks on changes to certain PM settings.
159 @param settings NULL terminated array of C strings, each string for a PM
160 setting that the caller is interested in and wants to get callbacks for.
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 IOPMSettingControllerCallback callout,
171 OSObject *target,
172 uintptr_t refcon,
173 OSObject **handle); // out param
174
175/*! @function registerPMSettingController
176 @abstract Register for callbacks on changes to certain PM settings.
177 @param settings NULL terminated array of C strings, each string for a PM
178 setting that the caller is interested in and wants to get callbacks for.
179 @param supportedPowerSources bitfield indicating which power sources these
180 settings are supported for (kIOPMSupportedOnAC, etc.)
181 @param callout C function ptr or member function cast as such.
182 @param target The target of the callback, usually 'this'
183 @param refcon Will be passed to caller in callback; for caller's use.
184 @param handle Caller should keep the OSObject * returned here. If non-NULL,
185 handle will have a retain count of 1 on return. To deregister, pass to
186 unregisterPMSettingController()
187 @result kIOReturnSuccess on success. */
188 IOReturn registerPMSettingController(
189 const OSSymbol *settings[],
190 uint32_t supportedPowerSources,
191 IOPMSettingControllerCallback callout,
192 OSObject *target,
193 uintptr_t refcon,
194 OSObject **handle); // out param
e5568f75 195
2d21ac55
A
196/*! @function acknowledgeSystemWillShutdown
197 @abstract Handle callbacks from IOService::systemWillShutdown().
198 @param The IOService sender of the callback. */
199 void acknowledgeSystemWillShutdown( IOService * from );
200
201/*! @function handlePlatformHaltRestart
202 @abstract Handle platform halt and restart notifications.
203 @param kPEHaltCPU or kPERestartCPU. */
204 void handlePlatformHaltRestart( UInt32 pe_type );
205
1c79356b
A
206private:
207
0c530ab8
A
208 // Points to our parent
209 class IORootParent * patriarch;
210
211 // Pref: idle time before idle sleep
2d21ac55
A
212 long sleepSlider;
213 long idleSeconds;
214 uint64_t autoWakeStart;
215 uint64_t autoWakeEnd;
0c530ab8
A
216
217 // Pref: longest of other idle times (disk and display)
2d21ac55 218 long longestNonSleepSlider;
0c530ab8
A
219
220 // Difference between sleepSlider and longestNonSleepSlider
221 long extraSleepDelay;
222
223 // Used to wait between say display idle and system idle
224 thread_call_t extraSleepTimer;
225
226 // Used to ignore clamshell close events while we're waking from sleep
227 thread_call_t clamshellWakeupIgnore;
d52fe63f 228
2d21ac55
A
229 // IOPMrootDomain internal sleep call
230 IOReturn privateSleepSystem ( const char *sleepReason );
231
232
1c79356b
A
233 virtual void powerChangeDone ( unsigned long );
234 virtual void command_received ( void *, void * , void * , void *);
235 virtual bool tellChangeDown ( unsigned long stateNum);
236 virtual bool askChangeDown ( unsigned long stateNum);
237 virtual void tellChangeUp ( unsigned long );
238 virtual void tellNoChangeDown ( unsigned long );
0b4e3aa0
A
239 void reportUserInput ( void );
240 static IOReturn sysPowerDownHandler( void * target, void * refCon,
241 UInt32 messageType, IOService * service,
242 void * messageArgument, vm_size_t argSize );
243
244 static IOReturn displayWranglerNotification( void * target, void * refCon,
245 UInt32 messageType, IOService * service,
246 void * messageArgument, vm_size_t argSize );
247
248 static bool displayWranglerPublished( void * target, void * refCon,
249 IOService * newService);
250
0c530ab8 251 static bool batteryPublished( void * target, void * refCon,
483a1d10
A
252 IOService * resourceService );
253
0c530ab8 254 void adjustPowerState ( void );
0b4e3aa0 255 void setQuickSpinDownTimeout ( void );
0b4e3aa0 256 void restoreUserSpinDownTimeout ( void );
0c530ab8
A
257
258 bool shouldSleepOnClamshellClosed (void );
259 void sendClientClamshellNotification ( void );
260
2d21ac55
A
261 // Inform PMCPU of changes to state like lid, AC vs. battery
262 void informCPUStateChange( uint32_t type, uint32_t value );
263
91447636 264 IOLock *featuresDictLock; // guards supportedFeatures
55e303ae 265 IOPMPowerStateQueue *pmPowerStateQueue;
0b4e3aa0
A
266 unsigned int user_spindown; // User's selected disk spindown value
267
268 unsigned int systemBooting:1;
0c530ab8 269 unsigned int systemShutdown:1;
0b4e3aa0
A
270 unsigned int ignoringClamshell:1;
271 unsigned int allowSleep:1;
272 unsigned int sleepIsSupported:1;
273 unsigned int canSleep:1;
274 unsigned int idleSleepPending:1;
275 unsigned int sleepASAP:1;
d52fe63f 276 unsigned int desktopMode:1;
2d21ac55 277 unsigned int userDisabledAllSleep:1;
d52fe63f
A
278
279 unsigned int acAdaptorConnect:1;
280 unsigned int ignoringClamshellDuringWakeup:1;
0c530ab8
A
281 unsigned int clamshellIsClosed:1;
282 unsigned int clamshellExists:1;
e5568f75 283
0c530ab8
A
284 OSArray *allowedPMSettings;
285
286 // Settings controller info
287 IORecursiveLock *settingsCtrlLock;
288 OSDictionary *settingsCallbacks;
289 OSDictionary *fPMSettingsDict;
290 IOReturn setPMSetting(const OSSymbol *, OSObject *);
291
292 thread_call_t diskSyncCalloutEntry;
293 IONotifier *_batteryPublishNotifier;
294 IONotifier *_displayWranglerNotifier;
e5568f75 295
2d21ac55
A
296 // Info for communicating system state changes to PMCPU
297 int32_t idxPMCPUClamshell;
298 int32_t idxPMCPULimitedPower;
299
e5568f75 300 struct ExpansionData {
e5568f75
A
301 };
302 ExpansionData *_reserved;
1c79356b 303 IOOptionBits platformSleepSupport;
0c530ab8
A
304
305 friend class PMSettingObject;
1c79356b
A
306};
307
308class IORootParent: public IOService
309{
310OSDeclareDefaultStructors(IORootParent)
0b4e3aa0
A
311
312private:
313 unsigned long mostRecentChange;
1c79356b
A
314
315public:
316
0c530ab8
A
317 virtual IOReturn changePowerStateToPriv ( unsigned long ordinal );
318
1c79356b
A
319 bool start ( IOService * nub );
320 void shutDownSystem ( void );
0b4e3aa0 321 void restartSystem ( void );
1c79356b 322 void sleepSystem ( void );
0b4e3aa0
A
323 void dozeSystem ( void );
324 void sleepToDoze ( void );
1c79356b
A
325 void wakeSystem ( void );
326};
327
328
329#endif /* _IOKIT_ROOTDOMAIN_H */