]> git.saurik.com Git - apple/xnu.git/blame_incremental - iokit/IOKit/pwr_mgt/RootDomain.h
xnu-792.18.15.tar.gz
[apple/xnu.git] / iokit / IOKit / pwr_mgt / RootDomain.h
... / ...
CommitLineData
1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_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 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.
14 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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
34class IOPMWorkArbiter;
35class IOPMPowerStateQueue;
36class RootDomainUserClient;
37
38enum {
39 kRootDomainSleepNotSupported = 0x00000000,
40 kRootDomainSleepSupported = 0x00000001,
41 kFrameBufferDeepSleepSupported = 0x00000002,
42 kPCICantSleep = 0x00000004
43};
44
45#define kRootDomainSupportedFeatures "Supported Features"
46
47// Supported Feature bitfields for IOPMrootDomain::publishFeature()
48enum {
49 kIOPMSupportedOnAC = 1<<0,
50 kIOPMSupportedOnBatt = 1<<1,
51 kIOPMSupportedOnUPS = 1<<2
52};
53
54typedef IOReturn (*IOPMSettingControllerCallback) \
55 (OSObject *target, const OSSymbol *type, \
56 OSObject *val, uintptr_t refcon);
57
58extern "C"
59{
60 IONotifier * registerSleepWakeInterest(
61 IOServiceInterestHandler, void *, void * = 0);
62
63 IONotifier * registerPrioritySleepWakeInterest(
64 IOServiceInterestHandler handler,
65 void * self, void * ref = 0);
66
67 IOReturn acknowledgeSleepWakeNotification(void * );
68
69 IOReturn vetoSleepWakeNotification(void * PMrefcon);
70
71 IOReturn rootDomainRestart ( void );
72
73 IOReturn rootDomainShutdown ( void );
74}
75
76#define IOPM_ROOTDOMAIN_REV 2
77
78class IOPMrootDomain: public IOService
79{
80OSDeclareDefaultStructors(IOPMrootDomain)
81
82public:
83
84 class IOService * wrangler; // we tickle the wrangler on button presses, etc
85
86 IOPMWorkArbiter * getPMArbiter(void);
87
88 static IOPMrootDomain * construct( void );
89 virtual bool start( IOService * provider );
90 virtual IOReturn setAggressiveness ( unsigned long, unsigned long );
91 virtual IOReturn youAreRoot ( void );
92 virtual IOReturn sleepSystem ( void );
93 virtual IOReturn setProperties ( OSObject * );
94 IOReturn shutdownSystem ( void );
95 IOReturn restartSystem ( void );
96 virtual IOReturn receivePowerNotification (UInt32 msg);
97 virtual void setSleepSupported( IOOptionBits flags );
98 virtual IOOptionBits getSleepSupported();
99 virtual IOReturn requestPowerDomainState ( IOPMPowerFlags, IOPowerConnection *, unsigned long );
100 virtual void handleSleepTimerExpiration ( void );
101 void stopIgnoringClamshellEventsDuringWakeup ( void );
102 void wakeFromDoze( void );
103 void broadcast_it (unsigned long, unsigned long );
104
105 // KEXT driver announces support of power management feature
106 void publishFeature( const char *feature );
107
108 // KEXT driver announces support of power management feature
109 // And specifies power sources with kIOPMSupportedOn{AC/Batt/UPS} bitfield.
110 // Returns a unique uint32_t identifier for later removing support for this
111 // feature.
112 // NULL is acceptable for uniqueFeatureID for kexts without plans to unload.
113 void publishFeature( const char *feature,
114 uint32_t supportedWhere,
115 uint32_t *uniqueFeatureID);
116
117 // KEXT driver announces removal of a previously published power management
118 // feature. Pass 'uniqueFeatureID' returned from publishFeature()
119 IOReturn removePublishedFeature( uint32_t removeFeatureID );
120
121 void unIdleDevice( IOService *, unsigned long );
122 void announcePowerSourceChange( void );
123
124 // Override of these methods for logging purposes.
125 virtual IOReturn changePowerStateTo ( unsigned long ordinal );
126 virtual IOReturn changePowerStateToPriv ( unsigned long ordinal );
127
128/*! @function copyPMSetting
129 @abstract Copy the current value for a PM setting. Returns OSNumber or
130 OSData depending on the setting.
131 @param whichSetting Name of the desired setting.
132 @result OSObject *value if valid, NULL otherwise. */
133 OSObject *copyPMSetting(OSSymbol *whichSetting);
134
135/*! @function registerPMSettingController
136 @abstract Register for callbacks on changes to certain PM settings.
137 @param settings NULL terminated array of C strings, each string for a PM
138 setting that the caller is interested in and wants to get callbacks for.
139 @param callout C function ptr or member function cast as such.
140 @param target The target of the callback, usually 'this'
141 @param refcon Will be passed to caller in callback; for caller's use.
142 @param handle Caller should keep the OSObject * returned here. If non-NULL,
143 handle will have a retain count of 1 on return. To deregister, pass to
144 unregisterPMSettingController()
145 @result kIOReturnSuccess on success. */
146 IOReturn registerPMSettingController(
147 const OSSymbol *settings[],
148 IOPMSettingControllerCallback callout,
149 OSObject *target,
150 uintptr_t refcon,
151 OSObject **handle); // out param
152
153/*! @function registerPMSettingController
154 @abstract Register for callbacks on changes to certain PM settings.
155 @param settings NULL terminated array of C strings, each string for a PM
156 setting that the caller is interested in and wants to get callbacks for.
157 @param supportedPowerSources bitfield indicating which power sources these
158 settings are supported for (kIOPMSupportedOnAC, etc.)
159 @param callout C function ptr or member function cast as such.
160 @param target The target of the callback, usually 'this'
161 @param refcon Will be passed to caller in callback; for caller's use.
162 @param handle Caller should keep the OSObject * returned here. If non-NULL,
163 handle will have a retain count of 1 on return. To deregister, pass to
164 unregisterPMSettingController()
165 @result kIOReturnSuccess on success. */
166 IOReturn registerPMSettingController(
167 const OSSymbol *settings[],
168 uint32_t supportedPowerSources,
169 IOPMSettingControllerCallback callout,
170 OSObject *target,
171 uintptr_t refcon,
172 OSObject **handle); // out param
173
174private:
175
176 // Points to our parent
177 class IORootParent * patriarch;
178
179 // Pref: idle time before idle sleep
180 long sleepSlider;
181
182 // Pref: longest of other idle times (disk and display)
183 long longestNonSleepSlider;
184
185 // Difference between sleepSlider and longestNonSleepSlider
186 long extraSleepDelay;
187
188 // Used to wait between say display idle and system idle
189 thread_call_t extraSleepTimer;
190
191 // Used to ignore clamshell close events while we're waking from sleep
192 thread_call_t clamshellWakeupIgnore;
193
194 virtual void powerChangeDone ( unsigned long );
195 virtual void command_received ( void *, void * , void * , void *);
196 virtual bool tellChangeDown ( unsigned long stateNum);
197 virtual bool askChangeDown ( unsigned long stateNum);
198 virtual void tellChangeUp ( unsigned long );
199 virtual void tellNoChangeDown ( unsigned long );
200 void reportUserInput ( void );
201 static IOReturn sysPowerDownHandler( void * target, void * refCon,
202 UInt32 messageType, IOService * service,
203 void * messageArgument, vm_size_t argSize );
204
205 static IOReturn displayWranglerNotification( void * target, void * refCon,
206 UInt32 messageType, IOService * service,
207 void * messageArgument, vm_size_t argSize );
208
209 static bool displayWranglerPublished( void * target, void * refCon,
210 IOService * newService);
211
212 static bool batteryPublished( void * target, void * refCon,
213 IOService * resourceService );
214
215 void adjustPowerState ( void );
216 void setQuickSpinDownTimeout ( void );
217 void restoreUserSpinDownTimeout ( void );
218
219 bool shouldSleepOnClamshellClosed (void );
220 void sendClientClamshellNotification ( void );
221
222 IOLock *featuresDictLock; // guards supportedFeatures
223 IOPMPowerStateQueue *pmPowerStateQueue;
224
225 IOWorkLoop *arbiterWorkLoop;
226 IOPMWorkArbiter *pmArbiter;
227
228 unsigned int user_spindown; // User's selected disk spindown value
229
230 unsigned int systemBooting:1;
231 unsigned int systemShutdown:1;
232 unsigned int ignoringClamshell:1;
233 unsigned int allowSleep:1;
234 unsigned int sleepIsSupported:1;
235 unsigned int canSleep:1;
236 unsigned int idleSleepPending:1;
237 unsigned int sleepASAP:1;
238 unsigned int desktopMode:1;
239
240 unsigned int acAdaptorConnect:1;
241 unsigned int ignoringClamshellDuringWakeup:1;
242 unsigned int clamshellIsClosed:1;
243 unsigned int clamshellExists:1;
244 unsigned int reservedA:4;
245 unsigned char reservedB[3];
246
247 OSArray *allowedPMSettings;
248
249 // Settings controller info
250 IORecursiveLock *settingsCtrlLock;
251 OSDictionary *settingsCallbacks;
252 OSDictionary *fPMSettingsDict;
253 IOReturn setPMSetting(const OSSymbol *, OSObject *);
254
255 thread_call_t diskSyncCalloutEntry;
256 IONotifier *_batteryPublishNotifier;
257 IONotifier *_displayWranglerNotifier;
258
259 struct ExpansionData {
260 };
261 ExpansionData *_reserved;
262 IOOptionBits platformSleepSupport;
263
264 friend class PMSettingObject;
265};
266
267class IORootParent: public IOService
268{
269OSDeclareDefaultStructors(IORootParent)
270
271private:
272 unsigned long mostRecentChange;
273
274public:
275
276 virtual IOReturn changePowerStateToPriv ( unsigned long ordinal );
277
278 bool start ( IOService * nub );
279 void shutDownSystem ( void );
280 void restartSystem ( void );
281 void sleepSystem ( void );
282 void dozeSystem ( void );
283 void sleepToDoze ( void );
284 void wakeSystem ( void );
285};
286
287
288#endif /* _IOKIT_ROOTDOMAIN_H */