]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/pwr_mgt/RootDomain.h
xnu-792.18.15.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 *
8f6c56a5 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
8f6c56a5
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.
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
8ad349bb 24 * limitations under the License.
8f6c56a5
A
25 *
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
89b3af67 34class IOPMWorkArbiter;
55e303ae 35class IOPMPowerStateQueue;
1c79356b
A
36class RootDomainUserClient;
37
38enum {
39 kRootDomainSleepNotSupported = 0x00000000,
40 kRootDomainSleepSupported = 0x00000001,
0b4e3aa0
A
41 kFrameBufferDeepSleepSupported = 0x00000002,
42 kPCICantSleep = 0x00000004
1c79356b
A
43};
44
89b3af67
A
45#define kRootDomainSupportedFeatures "Supported Features"
46
47// Supported Feature bitfields for IOPMrootDomain::publishFeature()
e5568f75 48enum {
89b3af67
A
49 kIOPMSupportedOnAC = 1<<0,
50 kIOPMSupportedOnBatt = 1<<1,
51 kIOPMSupportedOnUPS = 1<<2
e5568f75 52};
c0fea474 53
89b3af67
A
54typedef IOReturn (*IOPMSettingControllerCallback) \
55 (OSObject *target, const OSSymbol *type, \
56 OSObject *val, uintptr_t refcon);
5d5c5d0d 57
8f6c56a5
A
58extern "C"
59{
89b3af67
A
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 );
1c79356b
A
74}
75
d52fe63f 76#define IOPM_ROOTDOMAIN_REV 2
1c79356b
A
77
78class IOPMrootDomain: public IOService
79{
80OSDeclareDefaultStructors(IOPMrootDomain)
81
82public:
83
0b4e3aa0 84 class IOService * wrangler; // we tickle the wrangler on button presses, etc
89b3af67
A
85
86 IOPMWorkArbiter * getPMArbiter(void);
0b4e3aa0
A
87
88 static IOPMrootDomain * construct( void );
89 virtual bool start( IOService * provider );
1c79356b
A
90 virtual IOReturn setAggressiveness ( unsigned long, unsigned long );
91 virtual IOReturn youAreRoot ( void );
92 virtual IOReturn sleepSystem ( void );
9bccf70c 93 virtual IOReturn setProperties ( OSObject * );
0b4e3aa0
A
94 IOReturn shutdownSystem ( void );
95 IOReturn restartSystem ( void );
1c79356b
A
96 virtual IOReturn receivePowerNotification (UInt32 msg);
97 virtual void setSleepSupported( IOOptionBits flags );
98 virtual IOOptionBits getSleepSupported();
0b4e3aa0
A
99 virtual IOReturn requestPowerDomainState ( IOPMPowerFlags, IOPowerConnection *, unsigned long );
100 virtual void handleSleepTimerExpiration ( void );
d52fe63f 101 void stopIgnoringClamshellEventsDuringWakeup ( void );
0b4e3aa0 102 void wakeFromDoze( void );
9bccf70c 103 void broadcast_it (unsigned long, unsigned long );
89b3af67
A
104
105 // KEXT driver announces support of power management feature
d52fe63f 106 void publishFeature( const char *feature );
89b3af67
A
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
55e303ae
A
121 void unIdleDevice( IOService *, unsigned long );
122 void announcePowerSourceChange( void );
89b3af67 123
9bccf70c
A
124 // Override of these methods for logging purposes.
125 virtual IOReturn changePowerStateTo ( unsigned long ordinal );
126 virtual IOReturn changePowerStateToPriv ( unsigned long ordinal );
127
89b3af67
A
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
e5568f75 173
1c79356b
A
174private:
175
89b3af67
A
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;
d52fe63f 193
1c79356b
A
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 );
0b4e3aa0
A
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
89b3af67 212 static bool batteryPublished( void * target, void * refCon,
483a1d10
A
213 IOService * resourceService );
214
89b3af67 215 void adjustPowerState ( void );
0b4e3aa0 216 void setQuickSpinDownTimeout ( void );
0b4e3aa0 217 void restoreUserSpinDownTimeout ( void );
89b3af67
A
218
219 bool shouldSleepOnClamshellClosed (void );
220 void sendClientClamshellNotification ( void );
221
91447636 222 IOLock *featuresDictLock; // guards supportedFeatures
55e303ae 223 IOPMPowerStateQueue *pmPowerStateQueue;
89b3af67
A
224
225 IOWorkLoop *arbiterWorkLoop;
226 IOPMWorkArbiter *pmArbiter;
227
0b4e3aa0
A
228 unsigned int user_spindown; // User's selected disk spindown value
229
230 unsigned int systemBooting:1;
89b3af67 231 unsigned int systemShutdown:1;
0b4e3aa0
A
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;
d52fe63f
A
238 unsigned int desktopMode:1;
239
240 unsigned int acAdaptorConnect:1;
241 unsigned int ignoringClamshellDuringWakeup:1;
89b3af67
A
242 unsigned int clamshellIsClosed:1;
243 unsigned int clamshellExists:1;
244 unsigned int reservedA:4;
d52fe63f 245 unsigned char reservedB[3];
e5568f75 246
89b3af67
A
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;
e5568f75 258
e5568f75 259 struct ExpansionData {
e5568f75
A
260 };
261 ExpansionData *_reserved;
1c79356b 262 IOOptionBits platformSleepSupport;
89b3af67
A
263
264 friend class PMSettingObject;
1c79356b
A
265};
266
267class IORootParent: public IOService
268{
269OSDeclareDefaultStructors(IORootParent)
0b4e3aa0
A
270
271private:
272 unsigned long mostRecentChange;
1c79356b
A
273
274public:
275
89b3af67
A
276 virtual IOReturn changePowerStateToPriv ( unsigned long ordinal );
277
1c79356b
A
278 bool start ( IOService * nub );
279 void shutDownSystem ( void );
0b4e3aa0 280 void restartSystem ( void );
1c79356b 281 void sleepSystem ( void );
0b4e3aa0
A
282 void dozeSystem ( void );
283 void sleepToDoze ( void );
1c79356b
A
284 void wakeSystem ( void );
285};
286
287
288#endif /* _IOKIT_ROOTDOMAIN_H */