]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/pwr_mgt/RootDomain.h
df1ded306ff3933a8766c7e631822a43a04445d6
[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_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 #ifndef _IOKIT_ROOTDOMAIN_H
23 #define _IOKIT_ROOTDOMAIN_H
24
25 #include <IOKit/IOService.h>
26 #include <IOKit/pwr_mgt/IOPM.h>
27
28 class IOPMPowerStateQueue;
29 class RootDomainUserClient;
30
31 enum {
32 kRootDomainSleepNotSupported = 0x00000000,
33 kRootDomainSleepSupported = 0x00000001,
34 kFrameBufferDeepSleepSupported = 0x00000002,
35 kPCICantSleep = 0x00000004
36 };
37
38 #define kRootDomainSupportedFeatures "Supported Features"
39
40 // Supported Feature bitfields for IOPMrootDomain::publishFeature()
41 enum {
42 kIOPMSupportedOnAC = 1<<0,
43 kIOPMSupportedOnBatt = 1<<1,
44 kIOPMSupportedOnUPS = 1<<2
45 };
46
47 typedef IOReturn (*IOPMSettingControllerCallback) \
48 (OSObject *target, const OSSymbol *type, \
49 OSObject *val, uintptr_t refcon);
50
51 extern "C"
52 {
53 IONotifier * registerSleepWakeInterest(
54 IOServiceInterestHandler, void *, void * = 0);
55
56 IONotifier * registerPrioritySleepWakeInterest(
57 IOServiceInterestHandler handler,
58 void * self, void * ref = 0);
59
60 IOReturn acknowledgeSleepWakeNotification(void * );
61
62 IOReturn vetoSleepWakeNotification(void * PMrefcon);
63
64 IOReturn rootDomainRestart ( void );
65
66 IOReturn rootDomainShutdown ( void );
67 }
68
69 #define IOPM_ROOTDOMAIN_REV 2
70
71 class IOPMrootDomain: public IOService
72 {
73 OSDeclareDefaultStructors(IOPMrootDomain)
74
75 public:
76
77 class IOService * wrangler; // we tickle the wrangler on button presses, etc
78
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 );
95
96 // KEXT driver announces support of power management feature
97 void publishFeature( const char *feature );
98
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
102 // feature.
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);
107
108 // KEXT driver announces removal of a previously published power management
109 // feature. Pass 'uniqueFeatureID' returned from publishFeature()
110 IOReturn removePublishedFeature( uint32_t removeFeatureID );
111
112 void unIdleDevice( IOService *, unsigned long );
113 void announcePowerSourceChange( void );
114
115 // Override of these methods for logging purposes.
116 virtual IOReturn changePowerStateTo ( unsigned long ordinal );
117 virtual IOReturn changePowerStateToPriv ( unsigned long ordinal );
118
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);
125
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,
140 OSObject *target,
141 uintptr_t refcon,
142 OSObject **handle); // out param
143
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,
161 OSObject *target,
162 uintptr_t refcon,
163 OSObject **handle); // out param
164
165 private:
166
167 // Points to our parent
168 class IORootParent * patriarch;
169
170 // Pref: idle time before idle sleep
171 long sleepSlider;
172
173 // Pref: longest of other idle times (disk and display)
174 long longestNonSleepSlider;
175
176 // Difference between sleepSlider and longestNonSleepSlider
177 long extraSleepDelay;
178
179 // Used to wait between say display idle and system idle
180 thread_call_t extraSleepTimer;
181
182 // Used to ignore clamshell close events while we're waking from sleep
183 thread_call_t clamshellWakeupIgnore;
184
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 );
195
196 static IOReturn displayWranglerNotification( void * target, void * refCon,
197 UInt32 messageType, IOService * service,
198 void * messageArgument, vm_size_t argSize );
199
200 static bool displayWranglerPublished( void * target, void * refCon,
201 IOService * newService);
202
203 static bool batteryPublished( void * target, void * refCon,
204 IOService * resourceService );
205
206 void adjustPowerState ( void );
207 void setQuickSpinDownTimeout ( void );
208 void restoreUserSpinDownTimeout ( void );
209
210 bool shouldSleepOnClamshellClosed (void );
211 void sendClientClamshellNotification ( void );
212
213 IOLock *featuresDictLock; // guards supportedFeatures
214 IOPMPowerStateQueue *pmPowerStateQueue;
215 unsigned int user_spindown; // User's selected disk spindown value
216
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;
225
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];
232
233 OSArray *allowedPMSettings;
234
235 // Settings controller info
236 IORecursiveLock *settingsCtrlLock;
237 OSDictionary *settingsCallbacks;
238 OSDictionary *fPMSettingsDict;
239 IOReturn setPMSetting(const OSSymbol *, OSObject *);
240
241 thread_call_t diskSyncCalloutEntry;
242 IONotifier *_batteryPublishNotifier;
243 IONotifier *_displayWranglerNotifier;
244
245 struct ExpansionData {
246 };
247 ExpansionData *_reserved;
248 IOOptionBits platformSleepSupport;
249
250 friend class PMSettingObject;
251 };
252
253 class IORootParent: public IOService
254 {
255 OSDeclareDefaultStructors(IORootParent)
256
257 private:
258 unsigned long mostRecentChange;
259
260 public:
261
262 virtual IOReturn changePowerStateToPriv ( unsigned long ordinal );
263
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 );
271 };
272
273
274 #endif /* _IOKIT_ROOTDOMAIN_H */