]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/pwr_mgt/RootDomain.h
xnu-792.13.8.tar.gz
[apple/xnu.git] / iokit / IOKit / pwr_mgt / RootDomain.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
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
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
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.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 #ifndef _IOKIT_ROOTDOMAIN_H
31 #define _IOKIT_ROOTDOMAIN_H
32
33 #include <IOKit/IOService.h>
34 #include <IOKit/pwr_mgt/IOPM.h>
35
36 class IOPMWorkArbiter;
37 class IOPMPowerStateQueue;
38 class RootDomainUserClient;
39
40 enum {
41 kRootDomainSleepNotSupported = 0x00000000,
42 kRootDomainSleepSupported = 0x00000001,
43 kFrameBufferDeepSleepSupported = 0x00000002,
44 kPCICantSleep = 0x00000004
45 };
46
47 #define kRootDomainSupportedFeatures "Supported Features"
48
49 // Supported Feature bitfields for IOPMrootDomain::publishFeature()
50 enum {
51 kIOPMSupportedOnAC = 1<<0,
52 kIOPMSupportedOnBatt = 1<<1,
53 kIOPMSupportedOnUPS = 1<<2
54 };
55
56 typedef IOReturn (*IOPMSettingControllerCallback) \
57 (OSObject *target, const OSSymbol *type, \
58 OSObject *val, uintptr_t refcon);
59
60 extern "C"
61 {
62 IONotifier * registerSleepWakeInterest(
63 IOServiceInterestHandler, void *, void * = 0);
64
65 IONotifier * registerPrioritySleepWakeInterest(
66 IOServiceInterestHandler handler,
67 void * self, void * ref = 0);
68
69 IOReturn acknowledgeSleepWakeNotification(void * );
70
71 IOReturn vetoSleepWakeNotification(void * PMrefcon);
72
73 IOReturn rootDomainRestart ( void );
74
75 IOReturn rootDomainShutdown ( void );
76 }
77
78 #define IOPM_ROOTDOMAIN_REV 2
79
80 class IOPMrootDomain: public IOService
81 {
82 OSDeclareDefaultStructors(IOPMrootDomain)
83
84 public:
85
86 class IOService * wrangler; // we tickle the wrangler on button presses, etc
87
88 IOPMWorkArbiter * getPMArbiter(void);
89
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 );
106
107 // KEXT driver announces support of power management feature
108 void publishFeature( const char *feature );
109
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
113 // feature.
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);
118
119 // KEXT driver announces removal of a previously published power management
120 // feature. Pass 'uniqueFeatureID' returned from publishFeature()
121 IOReturn removePublishedFeature( uint32_t removeFeatureID );
122
123 void unIdleDevice( IOService *, unsigned long );
124 void announcePowerSourceChange( void );
125
126 // Override of these methods for logging purposes.
127 virtual IOReturn changePowerStateTo ( unsigned long ordinal );
128 virtual IOReturn changePowerStateToPriv ( unsigned long ordinal );
129
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);
136
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,
151 OSObject *target,
152 uintptr_t refcon,
153 OSObject **handle); // out param
154
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,
172 OSObject *target,
173 uintptr_t refcon,
174 OSObject **handle); // out param
175
176 private:
177
178 // Points to our parent
179 class IORootParent * patriarch;
180
181 // Pref: idle time before idle sleep
182 long sleepSlider;
183
184 // Pref: longest of other idle times (disk and display)
185 long longestNonSleepSlider;
186
187 // Difference between sleepSlider and longestNonSleepSlider
188 long extraSleepDelay;
189
190 // Used to wait between say display idle and system idle
191 thread_call_t extraSleepTimer;
192
193 // Used to ignore clamshell close events while we're waking from sleep
194 thread_call_t clamshellWakeupIgnore;
195
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 );
206
207 static IOReturn displayWranglerNotification( void * target, void * refCon,
208 UInt32 messageType, IOService * service,
209 void * messageArgument, vm_size_t argSize );
210
211 static bool displayWranglerPublished( void * target, void * refCon,
212 IOService * newService);
213
214 static bool batteryPublished( void * target, void * refCon,
215 IOService * resourceService );
216
217 void adjustPowerState ( void );
218 void setQuickSpinDownTimeout ( void );
219 void restoreUserSpinDownTimeout ( void );
220
221 bool shouldSleepOnClamshellClosed (void );
222 void sendClientClamshellNotification ( void );
223
224 IOLock *featuresDictLock; // guards supportedFeatures
225 IOPMPowerStateQueue *pmPowerStateQueue;
226
227 IOWorkLoop *arbiterWorkLoop;
228 IOPMWorkArbiter *pmArbiter;
229
230 unsigned int user_spindown; // User's selected disk spindown value
231
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;
240
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];
247
248 OSArray *allowedPMSettings;
249
250 // Settings controller info
251 IORecursiveLock *settingsCtrlLock;
252 OSDictionary *settingsCallbacks;
253 OSDictionary *fPMSettingsDict;
254 IOReturn setPMSetting(const OSSymbol *, OSObject *);
255
256 thread_call_t diskSyncCalloutEntry;
257 IONotifier *_batteryPublishNotifier;
258 IONotifier *_displayWranglerNotifier;
259
260 struct ExpansionData {
261 };
262 ExpansionData *_reserved;
263 IOOptionBits platformSleepSupport;
264
265 friend class PMSettingObject;
266 };
267
268 class IORootParent: public IOService
269 {
270 OSDeclareDefaultStructors(IORootParent)
271
272 private:
273 unsigned long mostRecentChange;
274
275 public:
276
277 virtual IOReturn changePowerStateToPriv ( unsigned long ordinal );
278
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 );
286 };
287
288
289 #endif /* _IOKIT_ROOTDOMAIN_H */