]>
Commit | Line | Data |
---|---|---|
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> | |
fe8ab488 A |
33 | #include <IOKit/IOBufferMemoryDescriptor.h> |
34 | #include <sys/vnode.h> | |
b0d623f7 A |
35 | |
36 | #ifdef XNU_KERNEL_PRIVATE | |
b0d623f7 | 37 | struct AggressivesRecord; |
6d2010ae A |
38 | struct IOPMMessageFilterContext; |
39 | struct IOPMActions; | |
316670eb | 40 | struct IOPMSystemSleepParameters; |
6d2010ae | 41 | class PMSettingObject; |
6d2010ae | 42 | class PMTraceWorker; |
55e303ae | 43 | class IOPMPowerStateQueue; |
1c79356b | 44 | class RootDomainUserClient; |
6d2010ae | 45 | class PMAssertionsTracker; |
fe8ab488 A |
46 | |
47 | #define OBFUSCATE(x) \ | |
48 | (((((uintptr_t)(x)) >= VM_MIN_KERNEL_AND_KEXT_ADDRESS) && (((uintptr_t)(x)) < VM_MAX_KERNEL_ADDRESS)) ? \ | |
49 | ((void *)(VM_KERNEL_ADDRPERM(x))) : (void *)(x)) | |
50 | ||
6d2010ae | 51 | #endif |
1c79356b | 52 | |
0b4c1975 A |
53 | /*! |
54 | * Types for PM Assertions | |
55 | * For creating, releasing, and getting PM assertion levels. | |
56 | */ | |
fe8ab488 | 57 | |
0b4c1975 A |
58 | /*! IOPMDriverAssertionType |
59 | * A bitfield describing a set of assertions. May be used to specify which assertions | |
fe8ab488 | 60 | * to set with <link>IOPMrootDomain::createPMAssertion</link>; or to query which |
0b4c1975 A |
61 | * assertions are set with <link>IOPMrootDomain::releasePMAssertion</link>. |
62 | */ | |
63 | typedef uint64_t IOPMDriverAssertionType; | |
64 | ||
65 | /* IOPMDriverAssertionID | |
66 | * Drivers may create PM assertions to request system behavior (keep the system awake, | |
fe8ab488 A |
67 | * or keep the display awake). When a driver creates an assertion via |
68 | * <link>IOPMrootDomain::createPMAssertion</link>, PM returns a handle to | |
0b4c1975 A |
69 | * the assertion of type IOPMDriverAssertionID. |
70 | */ | |
71 | typedef uint64_t IOPMDriverAssertionID; | |
72 | #define kIOPMUndefinedDriverAssertionID 0 | |
73 | ||
74 | /* IOPMDriverAssertionLevel | |
75 | * Possible values for IOPMDriverAssertionLevel are <link>kIOPMDriverAssertionLevelOff</link> | |
76 | * and <link>kIOPMDriverAssertionLevelOn</link> | |
77 | */ | |
78 | typedef uint32_t IOPMDriverAssertionLevel; | |
79 | #define kIOPMDriverAssertionLevelOff 0 | |
80 | #define kIOPMDriverAssertionLevelOn 255 | |
81 | ||
b0d623f7 A |
82 | /* |
83 | * Flags for get/setSleepSupported() | |
84 | */ | |
1c79356b | 85 | enum { |
fe8ab488 A |
86 | kRootDomainSleepNotSupported = 0x00000000, |
87 | kRootDomainSleepSupported = 0x00000001, | |
88 | kFrameBufferDeepSleepSupported = 0x00000002, | |
b0d623f7 | 89 | kPCICantSleep = 0x00000004 |
1c79356b A |
90 | }; |
91 | ||
fe8ab488 | 92 | /* |
2d21ac55 A |
93 | *IOPMrootDomain registry property keys |
94 | */ | |
95 | #define kRootDomainSupportedFeatures "Supported Features" | |
96 | #define kRootDomainSleepReasonKey "Last Sleep Reason" | |
97 | #define kRootDomainSleepOptionsKey "Last Sleep Options" | |
b0d623f7 A |
98 | #define kIOPMRootDomainWakeReasonKey "Wake Reason" |
99 | #define kIOPMRootDomainWakeTypeKey "Wake Type" | |
4a3eedf9 | 100 | #define kIOPMRootDomainPowerStatusKey "Power Status" |
2d21ac55 A |
101 | |
102 | /* | |
103 | * Possible sleep reasons found under kRootDomainSleepReasonsKey | |
104 | */ | |
105 | #define kIOPMClamshellSleepKey "Clamshell Sleep" | |
106 | #define kIOPMPowerButtonSleepKey "Power Button Sleep" | |
107 | #define kIOPMSoftwareSleepKey "Software Sleep" | |
108 | #define kIOPMOSSwitchHibernationKey "OS Switch Sleep" | |
109 | #define kIOPMIdleSleepKey "Idle Sleep" | |
110 | #define kIOPMLowPowerSleepKey "Low Power Sleep" | |
111 | #define kIOPMThermalEmergencySleepKey "Thermal Emergency Sleep" | |
b0d623f7 | 112 | #define kIOPMMaintenanceSleepKey "Maintenance Sleep" |
2d21ac55 A |
113 | |
114 | /* | |
115 | * String constants for communication with PM CPU | |
116 | */ | |
117 | #define kIOPMRootDomainLidCloseCString "LidClose" | |
118 | #define kIOPMRootDomainBatPowerCString "BatPower" | |
0c530ab8 | 119 | |
b0d623f7 A |
120 | /* |
121 | * Supported Feature bitfields for IOPMrootDomain::publishFeature() | |
122 | */ | |
e5568f75 | 123 | enum { |
b0d623f7 A |
124 | kIOPMSupportedOnAC = (1<<0), |
125 | kIOPMSupportedOnBatt = (1<<1), | |
126 | kIOPMSupportedOnUPS = (1<<2) | |
e5568f75 | 127 | }; |
4452a7af | 128 | |
b0d623f7 A |
129 | typedef IOReturn (*IOPMSettingControllerCallback) |
130 | (OSObject *target, const OSSymbol *type, | |
0c530ab8 | 131 | OSObject *val, uintptr_t refcon); |
4452a7af | 132 | |
b0d623f7 A |
133 | __BEGIN_DECLS |
134 | IONotifier * registerSleepWakeInterest( | |
135 | IOServiceInterestHandler, void *, void * = 0); | |
fe8ab488 | 136 | |
b0d623f7 | 137 | IONotifier * registerPrioritySleepWakeInterest( |
fe8ab488 | 138 | IOServiceInterestHandler handler, |
b0d623f7 | 139 | void * self, void * ref = 0); |
0c530ab8 | 140 | |
b0d623f7 | 141 | IOReturn acknowledgeSleepWakeNotification(void * ); |
0c530ab8 | 142 | |
b0d623f7 A |
143 | IOReturn vetoSleepWakeNotification(void * PMrefcon); |
144 | __END_DECLS | |
1c79356b | 145 | |
fe8ab488 | 146 | #define IOPM_ROOTDOMAIN_REV 2 |
1c79356b A |
147 | |
148 | class IOPMrootDomain: public IOService | |
149 | { | |
b0d623f7 | 150 | OSDeclareFinalStructors(IOPMrootDomain) |
0b4e3aa0 | 151 | |
b0d623f7 | 152 | public: |
0b4e3aa0 | 153 | static IOPMrootDomain * construct( void ); |
2d21ac55 | 154 | |
b0d623f7 A |
155 | virtual bool start( IOService * provider ); |
156 | virtual IOReturn setAggressiveness( unsigned long, unsigned long ); | |
157 | virtual IOReturn getAggressiveness( unsigned long, unsigned long * ); | |
2d21ac55 | 158 | |
b0d623f7 A |
159 | virtual IOReturn sleepSystem( void ); |
160 | IOReturn sleepSystemOptions( OSDictionary *options ); | |
161 | ||
162 | virtual IOReturn setProperties( OSObject * ); | |
0b4c1975 | 163 | virtual bool serializeProperties( OSSerialize * s ) const; |
39236c6e | 164 | virtual OSObject * copyProperty( const char * aKey ) const; |
4a3eedf9 A |
165 | |
166 | /*! @function systemPowerEventOccurred | |
167 | @abstract Other drivers may inform IOPMrootDomain of system PM events | |
168 | @discussion systemPowerEventOccurred is a richer alternative to receivePowerNotification() | |
169 | Only Apple-owned kexts should have reason to call systemPowerEventOccurred. | |
170 | @param event An OSSymbol describing the type of power event. | |
171 | @param value A 32-bit integer value associated with the event. | |
172 | @param shouldUpdate indicates whether the root domain should send a notification | |
173 | to interested parties. Pass false if you're calling systemPowerEventOccurred | |
174 | several times in succession; and pass true only on the last invocatino. | |
175 | @result kIOReturnSuccess on success */ | |
b0d623f7 A |
176 | |
177 | IOReturn systemPowerEventOccurred( | |
fe8ab488 | 178 | const OSSymbol *event, |
b0d623f7 A |
179 | uint32_t intValue ); |
180 | ||
181 | IOReturn systemPowerEventOccurred( | |
fe8ab488 | 182 | const OSSymbol *event, |
b0d623f7 A |
183 | OSObject *value ); |
184 | ||
fe8ab488 A |
185 | #ifdef XNU_KERNEL_PRIVATE // Hide doc from public headers |
186 | /*! @function claimSystemWakeEvent | |
187 | @abstract Apple-internal SPI to describe system wake events. | |
188 | @discussion IOKit drivers may call claimSystemWakeEvent() during system wakeup to | |
189 | provide human readable debug information describing the event(s) that | |
190 | caused the system to wake. | |
191 | ||
192 | - Drivers should call claimSystemWakeEvent before completing | |
193 | their setPowerState() acknowledgement. IOPMrootDomain stops | |
194 | collecting wake events when driver wake is complete. | |
195 | ||
196 | - It is only appropriate to claim a wake event when the driver | |
197 | can positively identify its hardware has generated an event | |
198 | that can wake the system. | |
199 | ||
200 | - This call tracks wake events from a non-S0 state (S0i, S3, S4) into S0. | |
201 | - This call does not track wake events from DarkWake(S0) to FullWake(S0). | |
202 | ||
203 | Examples: | |
204 | (reason = "WiFi.TCPData", | |
205 | details = "TCPKeepAlive packet arrived from IP 16.2.1.1") | |
206 | (reason = "WiFi.ScanOffload", | |
207 | details = "WiFi station 'AppleWiFi' signal dropped below threshold") | |
208 | (reason = "Enet.LinkToggle", | |
209 | details = "Ethernet attached") | |
210 | ||
211 | @param device The device/nub that is associated with the wake event. | |
212 | ||
213 | @param flags Pass kIOPMWakeEventSource if the device is the source | |
214 | of the wake event. Pass zero if the device is forwarding or | |
215 | aggregating wake events from multiple sources, e.g. an USB or | |
216 | Thunderbolt host controller. | |
217 | ||
218 | @param reason Caller should pass a human readable C string describing the | |
219 | wake reason. Please use a string from the list below, or create | |
220 | your own string matching this format: | |
221 | [Hardware].[Event] | |
222 | WiFi.MagicPacket | |
223 | WiFi.ScanOffload | |
224 | WiFi.mDNSConflict | |
225 | WiFi.mDNSService | |
226 | WiFi.TCPData | |
227 | WiFi.TCPTimeout | |
228 | WiFi.FirmwareCrash | |
229 | Enet.MagicPacket | |
230 | Enet.mDNSConflict | |
231 | Enet.mDNSService | |
232 | Enet.TCPData | |
233 | Enet.TCPTimeout | |
234 | Enet.Service | |
235 | Enet.LinkToggle | |
236 | Enet.ConflictResolution | |
237 | Enet.PatternMatch | |
238 | Enet.Timer | |
239 | Enet.LinkUpTimeout | |
240 | Enet.LinkDown | |
241 | USB.DeviceAttach | |
242 | USB.DeviceDetach | |
243 | ||
244 | @param details Optional details further describing the wake event. | |
245 | Please pass an OSString defining the event. | |
246 | */ | |
247 | #endif | |
248 | void claimSystemWakeEvent( IOService *device, | |
249 | IOOptionBits flags, | |
250 | const char *reason, | |
251 | OSObject *details = 0 ); | |
252 | ||
b0d623f7 A |
253 | virtual IOReturn receivePowerNotification( UInt32 msg ); |
254 | ||
255 | virtual void setSleepSupported( IOOptionBits flags ); | |
256 | ||
257 | virtual IOOptionBits getSleepSupported( void ); | |
258 | ||
259 | void wakeFromDoze( void ); | |
0c530ab8 A |
260 | |
261 | // KEXT driver announces support of power management feature | |
b0d623f7 A |
262 | |
263 | void publishFeature( const char *feature ); | |
fe8ab488 | 264 | |
0c530ab8 A |
265 | // KEXT driver announces support of power management feature |
266 | // And specifies power sources with kIOPMSupportedOn{AC/Batt/UPS} bitfield. | |
267 | // Returns a unique uint32_t identifier for later removing support for this | |
fe8ab488 | 268 | // feature. |
0c530ab8 | 269 | // NULL is acceptable for uniqueFeatureID for kexts without plans to unload. |
b0d623f7 | 270 | |
fe8ab488 | 271 | void publishFeature( const char *feature, |
b0d623f7 A |
272 | uint32_t supportedWhere, |
273 | uint32_t *uniqueFeatureID); | |
0c530ab8 | 274 | |
fe8ab488 | 275 | // KEXT driver announces removal of a previously published power management |
0c530ab8 | 276 | // feature. Pass 'uniqueFeatureID' returned from publishFeature() |
0c530ab8 | 277 | |
b0d623f7 | 278 | IOReturn removePublishedFeature( uint32_t removeFeatureID ); |
9bccf70c | 279 | |
0c530ab8 | 280 | /*! @function copyPMSetting |
b0d623f7 | 281 | @abstract Copy the current value for a PM setting. Returns an OSNumber or |
0c530ab8 | 282 | OSData depending on the setting. |
b0d623f7 A |
283 | @param whichSetting Name of the desired setting. |
284 | @result OSObject value if valid, NULL otherwise. */ | |
285 | ||
286 | OSObject * copyPMSetting( OSSymbol *whichSetting ); | |
287 | ||
0c530ab8 A |
288 | /*! @function registerPMSettingController |
289 | @abstract Register for callbacks on changes to certain PM settings. | |
fe8ab488 A |
290 | @param settings NULL terminated array of C strings, each string for a PM |
291 | setting that the caller is interested in and wants to get callbacks for. | |
0c530ab8 A |
292 | @param callout C function ptr or member function cast as such. |
293 | @param target The target of the callback, usually 'this' | |
294 | @param refcon Will be passed to caller in callback; for caller's use. | |
295 | @param handle Caller should keep the OSObject * returned here. If non-NULL, | |
296 | handle will have a retain count of 1 on return. To deregister, pass to | |
297 | unregisterPMSettingController() | |
298 | @result kIOReturnSuccess on success. */ | |
b0d623f7 A |
299 | |
300 | IOReturn registerPMSettingController( | |
0c530ab8 A |
301 | const OSSymbol *settings[], |
302 | IOPMSettingControllerCallback callout, | |
303 | OSObject *target, | |
304 | uintptr_t refcon, | |
305 | OSObject **handle); // out param | |
306 | ||
307 | /*! @function registerPMSettingController | |
308 | @abstract Register for callbacks on changes to certain PM settings. | |
fe8ab488 A |
309 | @param settings NULL terminated array of C strings, each string for a PM |
310 | setting that the caller is interested in and wants to get callbacks for. | |
0c530ab8 A |
311 | @param supportedPowerSources bitfield indicating which power sources these |
312 | settings are supported for (kIOPMSupportedOnAC, etc.) | |
313 | @param callout C function ptr or member function cast as such. | |
314 | @param target The target of the callback, usually 'this' | |
315 | @param refcon Will be passed to caller in callback; for caller's use. | |
316 | @param handle Caller should keep the OSObject * returned here. If non-NULL, | |
317 | handle will have a retain count of 1 on return. To deregister, pass to | |
318 | unregisterPMSettingController() | |
319 | @result kIOReturnSuccess on success. */ | |
b0d623f7 A |
320 | |
321 | IOReturn registerPMSettingController( | |
0c530ab8 A |
322 | const OSSymbol *settings[], |
323 | uint32_t supportedPowerSources, | |
324 | IOPMSettingControllerCallback callout, | |
325 | OSObject *target, | |
326 | uintptr_t refcon, | |
327 | OSObject **handle); // out param | |
e5568f75 | 328 | |
b0d623f7 A |
329 | virtual IONotifier * registerInterest( |
330 | const OSSymbol * typeOfInterest, | |
331 | IOServiceInterestHandler handler, | |
332 | void * target, void * ref = 0 ); | |
b0d623f7 A |
333 | |
334 | virtual IOReturn callPlatformFunction( | |
335 | const OSSymbol *functionName, | |
336 | bool waitForFunction, | |
337 | void *param1, void *param2, | |
338 | void *param3, void *param4 ); | |
339 | ||
0b4c1975 A |
340 | /*! @function createPMAssertion |
341 | @abstract Creates an assertion to influence system power behavior. | |
342 | @param whichAssertionBits A bitfield specify the assertion that the caller requests. | |
343 | @param assertionLevel An integer detailing the initial assertion level, kIOPMDriverAssertionLevelOn | |
344 | or kIOPMDriverAssertionLevelOff. | |
345 | @param ownerService A pointer to the caller's IOService class, for tracking. | |
346 | @param ownerDescription A reverse-DNS string describing the caller's identity and reason. | |
347 | @result On success, returns a new assertion of type IOPMDriverAssertionID | |
348 | */ | |
349 | IOPMDriverAssertionID createPMAssertion( | |
350 | IOPMDriverAssertionType whichAssertionsBits, | |
351 | IOPMDriverAssertionLevel assertionLevel, | |
352 | IOService *ownerService, | |
353 | const char *ownerDescription); | |
354 | ||
355 | /* @function setPMAssertionLevel | |
356 | @abstract Modify the level of a pre-existing assertion. | |
fe8ab488 | 357 | @discussion Change the value of a PM assertion to influence system behavior, |
0b4c1975 A |
358 | without undergoing the work required to create or destroy an assertion. Suggested |
359 | for clients who will assert and de-assert needs for PM behavior several times over | |
360 | their lifespan. | |
361 | @param assertionID An assertion ID previously returned by <link>createPMAssertion</link> | |
362 | @param assertionLevel The new assertion level. | |
363 | @result kIOReturnSuccess if it worked; kIOReturnNotFound or other IOReturn error on failure. | |
364 | */ | |
365 | IOReturn setPMAssertionLevel(IOPMDriverAssertionID assertionID, IOPMDriverAssertionLevel assertionLevel); | |
366 | ||
367 | /*! @function getPMAssertionLevel | |
368 | @absract Returns the active level of the specified assertion(s). | |
fe8ab488 | 369 | @discussion Returns <link>kIOPMDriverAssertionLevelOff</link> or |
0b4c1975 A |
370 | <link>kIOPMDriverAssertionLevelOn</link>. If multiple assertions are specified |
371 | in the bitfield, only returns <link>kIOPMDriverAssertionLevelOn</link> | |
372 | if all assertions are active. | |
373 | @param whichAssertionBits Bits defining the assertion or assertions the caller is interested in | |
374 | the level of. If in doubt, pass <link>kIOPMDriverAssertionCPUBit</link> as the argument. | |
fe8ab488 | 375 | @result Returns <link>kIOPMDriverAssertionLevelOff</link> or |
0b4c1975 A |
376 | <link>kIOPMDriverAssertionLevelOn</link> indicating the specified assertion's levels, if available. |
377 | If the assertions aren't supported on this machine, or aren't recognized by the OS, the | |
378 | result is undefined. | |
379 | */ | |
380 | IOPMDriverAssertionLevel getPMAssertionLevel(IOPMDriverAssertionType whichAssertionBits); | |
381 | ||
382 | /*! @function releasePMAssertion | |
383 | @abstract Removes an assertion to influence system power behavior. | |
384 | @result On success, returns a new assertion of type IOPMDriverAssertionID * | |
385 | */ | |
386 | IOReturn releasePMAssertion(IOPMDriverAssertionID releaseAssertion); | |
39236c6e | 387 | |
fe8ab488 A |
388 | /*! @function restartWithStackshot |
389 | @abstract Take a stackshot of the system and restart the system. | |
390 | @result Return kIOReturnSuccess if it work, kIOReturnError if the service is not available. | |
391 | */ | |
392 | IOReturn restartWithStackshot(); | |
393 | ||
b0d623f7 A |
394 | private: |
395 | virtual IOReturn changePowerStateTo( unsigned long ordinal ); | |
396 | virtual IOReturn changePowerStateToPriv( unsigned long ordinal ); | |
397 | virtual IOReturn requestPowerDomainState( IOPMPowerFlags, IOPowerConnection *, unsigned long ); | |
398 | virtual void powerChangeDone( unsigned long ); | |
399 | virtual bool tellChangeDown( unsigned long ); | |
400 | virtual bool askChangeDown( unsigned long ); | |
401 | virtual void tellChangeUp( unsigned long ); | |
402 | virtual void tellNoChangeDown( unsigned long ); | |
39236c6e A |
403 | virtual IOReturn configureReport(IOReportChannelList *channels, |
404 | IOReportConfigureAction action, | |
405 | void *result, | |
406 | void *destination); | |
407 | virtual IOReturn updateReport(IOReportChannelList *channels, | |
408 | IOReportUpdateAction action, | |
409 | void *result, | |
410 | void *destination); | |
411 | ||
b0d623f7 A |
412 | #ifdef XNU_KERNEL_PRIVATE |
413 | /* Root Domain internals */ | |
414 | public: | |
6d2010ae A |
415 | void tagPowerPlaneService( |
416 | IOService * service, | |
417 | IOPMActions * actions ); | |
b0d623f7 | 418 | |
6d2010ae | 419 | void overrideOurPowerChange( |
39236c6e A |
420 | IOService * service, |
421 | IOPMActions * actions, | |
422 | IOPMPowerStateIndex * inOutPowerState, | |
423 | IOPMPowerChangeFlags * inOutChangeFlags, | |
424 | IOPMRequestTag requestTag ); | |
0b4c1975 | 425 | |
6d2010ae | 426 | void handleOurPowerChangeStart( |
39236c6e A |
427 | IOService * service, |
428 | IOPMActions * actions, | |
429 | IOPMPowerStateIndex powerState, | |
430 | IOPMPowerChangeFlags * inOutChangeFlags, | |
431 | IOPMRequestTag requestTag ); | |
6d2010ae A |
432 | |
433 | void handleOurPowerChangeDone( | |
39236c6e A |
434 | IOService * service, |
435 | IOPMActions * actions, | |
436 | IOPMPowerStateIndex powerState, | |
437 | IOPMPowerChangeFlags changeFlags, | |
438 | IOPMRequestTag requestTag ); | |
6d2010ae A |
439 | |
440 | void overridePowerChangeForUIService( | |
39236c6e A |
441 | IOService * service, |
442 | IOPMActions * actions, | |
443 | IOPMPowerStateIndex * inOutPowerState, | |
444 | IOPMPowerChangeFlags * inOutChangeFlags ); | |
6d2010ae A |
445 | |
446 | void handleActivityTickleForDisplayWrangler( | |
39236c6e A |
447 | IOService * service, |
448 | IOPMActions * actions ); | |
449 | ||
450 | void handleUpdatePowerClientForDisplayWrangler( | |
451 | IOService * service, | |
452 | IOPMActions * actions, | |
453 | const OSSymbol * powerClient, | |
454 | IOPMPowerStateIndex oldPowerState, | |
455 | IOPMPowerStateIndex newPowerState ); | |
6d2010ae A |
456 | |
457 | bool shouldDelayChildNotification( | |
39236c6e | 458 | IOService * service ); |
6d2010ae A |
459 | |
460 | void handlePowerChangeStartForPCIDevice( | |
39236c6e | 461 | IOService * service, |
fe8ab488 | 462 | IOPMActions * actions, |
39236c6e A |
463 | IOPMPowerStateIndex powerState, |
464 | IOPMPowerChangeFlags * inOutChangeFlags ); | |
6d2010ae A |
465 | |
466 | void handlePowerChangeDoneForPCIDevice( | |
39236c6e | 467 | IOService * service, |
fe8ab488 | 468 | IOPMActions * actions, |
39236c6e A |
469 | IOPMPowerStateIndex powerState, |
470 | IOPMPowerChangeFlags changeFlags ); | |
b0d623f7 | 471 | |
6d2010ae A |
472 | void askChangeDownDone( |
473 | IOPMPowerChangeFlags * inOutChangeFlags, | |
474 | bool * cancel ); | |
475 | ||
476 | void handlePublishSleepWakeUUID( | |
477 | bool shouldPublish); | |
478 | ||
479 | void handleQueueSleepWakeUUID( | |
480 | OSObject *obj); | |
481 | ||
39236c6e A |
482 | void willNotifyPowerChildren( IOPMPowerStateIndex newPowerState ); |
483 | ||
316670eb A |
484 | IOReturn setMaintenanceWakeCalendar( |
485 | const IOPMCalendarStruct * calendar ); | |
b0d623f7 | 486 | |
db609669 A |
487 | IOReturn getSystemSleepType( uint32_t * sleepType ); |
488 | ||
b0d623f7 | 489 | // Handle callbacks from IOService::systemWillShutdown() |
fe8ab488 | 490 | void acknowledgeSystemWillShutdown( IOService * from ); |
2d21ac55 | 491 | |
b0d623f7 | 492 | // Handle platform halt and restart notifications |
fe8ab488 | 493 | void handlePlatformHaltRestart( UInt32 pe_type ); |
6d2010ae A |
494 | |
495 | IOReturn shutdownSystem( void ); | |
496 | IOReturn restartSystem( void ); | |
497 | void handleSleepTimerExpiration( void ); | |
2d21ac55 | 498 | |
0b4c1975 A |
499 | bool activitySinceSleep(void); |
500 | bool abortHibernation(void); | |
b0d623f7 A |
501 | |
502 | IOReturn joinAggressiveness( IOService * service ); | |
503 | void handleAggressivesRequests( void ); | |
504 | ||
505 | void tracePoint( uint8_t point ); | |
6d2010ae A |
506 | void tracePoint( uint8_t point, uint8_t data ); |
507 | void traceDetail( uint32_t data32 ); | |
508 | ||
509 | bool systemMessageFilter( | |
510 | void * object, void * arg1, void * arg2, void * arg3 ); | |
511 | ||
39236c6e | 512 | bool updatePreventIdleSleepList( |
316670eb A |
513 | IOService * service, bool addNotRemove ); |
514 | void updatePreventSystemSleepList( | |
515 | IOService * service, bool addNotRemove ); | |
516 | ||
7ddcb079 A |
517 | void publishPMSetting( |
518 | const OSSymbol * feature, uint32_t where, uint32_t * featureID ); | |
519 | ||
6d2010ae A |
520 | void pmStatsRecordEvent( |
521 | int eventIndex, | |
522 | AbsoluteTime timestamp); | |
523 | ||
524 | void pmStatsRecordApplicationResponse( | |
fe8ab488 A |
525 | const OSSymbol *response, |
526 | const char *name, | |
6d2010ae | 527 | int messageType, |
fe8ab488 A |
528 | uint32_t delay_ms, |
529 | int app_pid, | |
530 | OSObject *object, | |
531 | IOPMPowerStateIndex ps=0); | |
316670eb | 532 | |
fe8ab488 | 533 | void copyWakeReasonString( char * outBuf, size_t bufSize ); |
316670eb | 534 | |
6d2010ae A |
535 | #if HIBERNATION |
536 | bool getHibernateSettings( | |
537 | uint32_t * hibernateMode, | |
538 | uint32_t * hibernateFreeRatio, | |
539 | uint32_t * hibernateFreeTime ); | |
540 | #endif | |
fe8ab488 | 541 | void takeStackshot(bool restart, bool isOSXWatchdog); |
39236c6e | 542 | void sleepWakeDebugTrig(bool restart); |
39236c6e A |
543 | void sleepWakeDebugEnableWdog(); |
544 | bool sleepWakeDebugIsWdogEnabled(); | |
545 | static void saveTimeoutAppStackShot(void *p0, void *p1); | |
b0d623f7 | 546 | |
1c79356b | 547 | private: |
b0d623f7 | 548 | friend class PMSettingObject; |
0b4c1975 | 549 | friend class RootDomainUserClient; |
6d2010ae A |
550 | friend class PMAssertionsTracker; |
551 | ||
552 | static IOReturn sysPowerDownHandler( void * target, void * refCon, | |
553 | UInt32 messageType, IOService * service, | |
554 | void * messageArgument, vm_size_t argSize ); | |
555 | ||
556 | static IOReturn displayWranglerNotification( void * target, void * refCon, | |
557 | UInt32 messageType, IOService * service, | |
558 | void * messageArgument, vm_size_t argSize ); | |
559 | ||
560 | static IOReturn rootBusyStateChangeHandler( void * target, void * refCon, | |
561 | UInt32 messageType, IOService * service, | |
562 | void * messageArgument, vm_size_t argSize ); | |
563 | ||
564 | static bool displayWranglerMatchPublished( void * target, void * refCon, | |
565 | IOService * newService, | |
566 | IONotifier * notifier); | |
567 | ||
39236c6e A |
568 | static bool IONVRAMMatchPublished( void * target, void * refCon, |
569 | IOService * newService, | |
570 | IONotifier * notifier); | |
571 | ||
6d2010ae A |
572 | static bool batteryPublished( void * target, void * refCon, |
573 | IOService * resourceService, | |
574 | IONotifier * notifier); | |
1c79356b | 575 | |
39236c6e A |
576 | void initializeBootSessionUUID( void ); |
577 | ||
578 | void fullWakeDelayedWork( void ); | |
579 | ||
b0d623f7 | 580 | IOService * wrangler; |
39236c6e | 581 | OSDictionary * wranglerIdleSettings; |
0c530ab8 | 582 | |
b0d623f7 | 583 | IOLock *featuresDictLock; // guards supportedFeatures |
fe8ab488 | 584 | IOLock *wakeEventLock; |
b0d623f7 A |
585 | IOPMPowerStateQueue *pmPowerStateQueue; |
586 | ||
587 | OSArray *allowedPMSettings; | |
7ddcb079 | 588 | OSArray *noPublishPMSettings; |
b0d623f7 | 589 | PMTraceWorker *pmTracer; |
0b4c1975 | 590 | PMAssertionsTracker *pmAssertions; |
0c530ab8 | 591 | |
b0d623f7 | 592 | // Settings controller info |
fe8ab488 | 593 | IOLock *settingsCtrlLock; |
b0d623f7 A |
594 | OSDictionary *settingsCallbacks; |
595 | OSDictionary *fPMSettingsDict; | |
596 | ||
597 | IONotifier *_batteryPublishNotifier; | |
598 | IONotifier *_displayWranglerNotifier; | |
599 | ||
600 | // Statistics | |
6d2010ae A |
601 | const OSSymbol *_statsNameKey; |
602 | const OSSymbol *_statsPIDKey; | |
603 | const OSSymbol *_statsTimeMSKey; | |
604 | const OSSymbol *_statsResponseTypeKey; | |
605 | const OSSymbol *_statsMessageTypeKey; | |
39236c6e A |
606 | const OSSymbol *_statsPowerCapsKey; |
607 | uint32_t sleepCnt; | |
608 | uint32_t darkWakeCnt; | |
609 | uint32_t displayWakeCnt; | |
fe8ab488 | 610 | |
b0d623f7 | 611 | OSString *queuedSleepWakeUUIDString; |
b0d623f7 | 612 | OSArray *pmStatsAppResponses; |
fe8ab488 | 613 | IOLock *pmStatsLock; // guards pmStatsAppResponses |
b0d623f7 | 614 | |
6d2010ae | 615 | bool uuidPublished; |
b0d623f7 A |
616 | |
617 | // Pref: idle time before idle sleep | |
39236c6e | 618 | unsigned long sleepSlider; |
b0d623f7 A |
619 | unsigned long idleSeconds; |
620 | uint64_t autoWakeStart; | |
621 | uint64_t autoWakeEnd; | |
0c530ab8 A |
622 | |
623 | // Difference between sleepSlider and longestNonSleepSlider | |
fe8ab488 | 624 | unsigned long extraSleepDelay; |
0c530ab8 A |
625 | |
626 | // Used to wait between say display idle and system idle | |
6d2010ae | 627 | thread_call_t extraSleepTimer; |
b0d623f7 | 628 | thread_call_t diskSyncCalloutEntry; |
39236c6e | 629 | thread_call_t fullWakeThreadCall; |
fe8ab488 | 630 | thread_call_t hibDebugSetupEntry; |
6d2010ae A |
631 | |
632 | // Track system capabilities. | |
633 | uint32_t _desiredCapability; | |
634 | uint32_t _currentCapability; | |
635 | uint32_t _pendingCapability; | |
636 | uint32_t _highestCapability; | |
637 | OSSet * _joinedCapabilityClients; | |
638 | uint32_t _systemStateGeneration; | |
639 | ||
640 | // Type of clients that can receive system messages. | |
641 | enum { | |
39236c6e A |
642 | kSystemMessageClientPowerd = 0x01, |
643 | kSystemMessageClientLegacyApp = 0x02, | |
6d2010ae A |
644 | kSystemMessageClientKernel = 0x04, |
645 | kSystemMessageClientAll = 0x07 | |
646 | }; | |
647 | uint32_t _systemMessageClientMask; | |
648 | ||
649 | // Power state and capability change transitions. | |
650 | enum { | |
651 | kSystemTransitionNone = 0, | |
652 | kSystemTransitionSleep = 1, | |
653 | kSystemTransitionWake = 2, | |
654 | kSystemTransitionCapability = 3, | |
655 | kSystemTransitionNewCapClient = 4 | |
656 | } _systemTransitionType; | |
b0d623f7 A |
657 | |
658 | unsigned int systemBooting :1; | |
659 | unsigned int systemShutdown :1; | |
6d2010ae | 660 | unsigned int systemDarkWake :1; |
b0d623f7 | 661 | unsigned int clamshellExists :1; |
6d2010ae A |
662 | unsigned int clamshellClosed :1; |
663 | unsigned int clamshellDisabled :1; | |
b0d623f7 | 664 | unsigned int desktopMode :1; |
6d2010ae | 665 | unsigned int acAdaptorConnected :1; |
b0d623f7 | 666 | |
39236c6e | 667 | unsigned int clamshellSleepDisabled :1; |
b0d623f7 A |
668 | unsigned int idleSleepTimerPending :1; |
669 | unsigned int userDisabledAllSleep :1; | |
6d2010ae | 670 | unsigned int ignoreTellChangeDown :1; |
b0d623f7 | 671 | unsigned int wranglerAsleep :1; |
6d2010ae | 672 | unsigned int wranglerTickled :1; |
22ba694c | 673 | unsigned int _preventUserActive :1; |
6d2010ae A |
674 | unsigned int graphicsSuppressed :1; |
675 | ||
676 | unsigned int capabilityLoss :1; | |
677 | unsigned int pciCantSleepFlag :1; | |
678 | unsigned int pciCantSleepValid :1; | |
6d2010ae A |
679 | unsigned int logGraphicsClamp :1; |
680 | unsigned int darkWakeToSleepASAP :1; | |
681 | unsigned int darkWakeMaintenance :1; | |
7ddcb079 | 682 | unsigned int darkWakeSleepService :1; |
13f56ec4 | 683 | unsigned int darkWakePostTickle :1; |
39236c6e | 684 | |
0b4c1975 | 685 | unsigned int sleepTimerMaintenance :1; |
39236c6e | 686 | unsigned int sleepToStandby :1; |
0b4c1975 A |
687 | unsigned int lowBatteryCondition :1; |
688 | unsigned int hibernateDisabled :1; | |
39236c6e | 689 | unsigned int hibernateRetry :1; |
13f56ec4 | 690 | unsigned int wranglerTickleLatched :1; |
39236c6e A |
691 | unsigned int userIsActive :1; |
692 | unsigned int userWasActive :1; | |
fe8ab488 | 693 | |
39236c6e | 694 | unsigned int displayIdleForDemandSleep :1; |
fe8ab488 | 695 | unsigned int darkWakeHibernateError :1; |
a1c7dba1 | 696 | unsigned int thermalWarningState:1; |
0b4c1975 A |
697 | |
698 | uint32_t hibernateMode; | |
39236c6e A |
699 | AbsoluteTime userActivityTime; |
700 | AbsoluteTime userActivityTime_prev; | |
0b4c1975 A |
701 | uint32_t userActivityCount; |
702 | uint32_t userActivityAtSleep; | |
703 | uint32_t lastSleepReason; | |
39236c6e | 704 | uint32_t fullToDarkReason; |
13f56ec4 | 705 | uint32_t hibernateAborted; |
0b4c1975 | 706 | |
39236c6e A |
707 | enum FullWakeReason { |
708 | kFullWakeReasonNone = 0, | |
709 | kFullWakeReasonLocalUser = 1, | |
710 | kFullWakeReasonDisplayOn = 2, | |
711 | fFullWakeReasonDisplayOnAndLocalUser = 3 | |
712 | }; | |
713 | uint32_t fullWakeReason; | |
714 | ||
b0d623f7 A |
715 | // Info for communicating system state changes to PMCPU |
716 | int32_t idxPMCPUClamshell; | |
717 | int32_t idxPMCPULimitedPower; | |
718 | ||
719 | IOOptionBits platformSleepSupport; | |
6d2010ae | 720 | uint32_t _debugWakeSeconds; |
7ddcb079 | 721 | uint32_t _lastDebugWakeSeconds; |
b0d623f7 A |
722 | |
723 | queue_head_t aggressivesQueue; | |
724 | thread_call_t aggressivesThreadCall; | |
725 | OSData * aggressivesData; | |
726 | ||
39236c6e | 727 | AbsoluteTime userBecameInactiveTime; |
6d2010ae A |
728 | AbsoluteTime systemWakeTime; |
729 | ||
b0d623f7 A |
730 | // PCI top-level PM trace |
731 | IOService * pciHostBridgeDevice; | |
6d2010ae | 732 | IOService * pciHostBridgeDriver; |
b0d623f7 | 733 | |
6d2010ae | 734 | IONotifier * systemCapabilityNotifier; |
2d21ac55 | 735 | |
316670eb A |
736 | typedef struct { |
737 | uint32_t pid; | |
738 | uint32_t refcount; | |
739 | } PMNotifySuspendedStruct; | |
fe8ab488 A |
740 | |
741 | uint32_t pmSuspendedCapacity; | |
316670eb A |
742 | uint32_t pmSuspendedSize; |
743 | PMNotifySuspendedStruct *pmSuspendedPIDS; | |
744 | ||
745 | OSSet * preventIdleSleepList; | |
746 | OSSet * preventSystemSleepList; | |
747 | ||
99c3a104 | 748 | UInt32 _scheduledAlarms; |
db609669 | 749 | UInt32 _userScheduledAlarm; |
99c3a104 | 750 | |
316670eb A |
751 | #if HIBERNATION |
752 | clock_sec_t _standbyTimerResetSeconds; | |
753 | #endif | |
39236c6e A |
754 | volatile uint32_t swd_lock; /* Lock to access swd_buffer & and its header */ |
755 | void * swd_buffer; /* Memory allocated for dumping sleep/wake logs */ | |
756 | uint8_t swd_flags; /* Flags defined in IOPMPrivate.h */ | |
fe8ab488 | 757 | |
39236c6e | 758 | IOMemoryMap * swd_logBufMap; /* Memory with sleep/wake logs from previous boot */ |
fe8ab488 A |
759 | |
760 | // Wake Event Reporting | |
761 | OSArray * _systemWakeEventsArray; | |
762 | bool _acceptSystemWakeEvents; | |
0b4e3aa0 | 763 | |
316670eb | 764 | int findSuspendedPID(uint32_t pid, uint32_t *outRefCount); |
7ddcb079 | 765 | |
fe8ab488 | 766 | // IOPMrootDomain internal sleep call |
6d2010ae A |
767 | IOReturn privateSleepSystem( uint32_t sleepReason ); |
768 | void reportUserInput( void ); | |
db609669 | 769 | void setDisableClamShellSleep( bool ); |
39236c6e A |
770 | bool checkSystemSleepAllowed( IOOptionBits options, |
771 | uint32_t sleepReason ); | |
772 | bool checkSystemSleepEnabled( void ); | |
773 | bool checkSystemCanSleep( uint32_t sleepReason ); | |
13f56ec4 | 774 | bool checkSystemCanSustainFullWake( void ); |
0b4e3aa0 | 775 | |
6d2010ae A |
776 | void adjustPowerState( bool sleepASAP = false ); |
777 | void setQuickSpinDownTimeout( void ); | |
778 | void restoreUserSpinDownTimeout( void ); | |
0b4e3aa0 | 779 | |
6d2010ae A |
780 | bool shouldSleepOnClamshellClosed(void ); |
781 | void sendClientClamshellNotification( void ); | |
483a1d10 | 782 | |
2d21ac55 | 783 | // Inform PMCPU of changes to state like lid, AC vs. battery |
6d2010ae | 784 | void informCPUStateChange( uint32_t type, uint32_t value ); |
b0d623f7 | 785 | |
6d2010ae A |
786 | void dispatchPowerEvent( uint32_t event, void * arg0, uint64_t arg1 ); |
787 | void handlePowerNotification( UInt32 msg ); | |
b0d623f7 | 788 | |
6d2010ae | 789 | IOReturn setPMSetting(const OSSymbol *, OSObject *); |
0c530ab8 | 790 | |
6d2010ae A |
791 | void startIdleSleepTimer( uint32_t inSeconds ); |
792 | void cancelIdleSleepTimer( void ); | |
39236c6e | 793 | uint32_t getTimeToIdleSleep( void ); |
b0d623f7 A |
794 | |
795 | IOReturn setAggressiveness( | |
796 | unsigned long type, | |
797 | unsigned long value, | |
798 | IOOptionBits options ); | |
799 | ||
800 | void synchronizeAggressives( | |
801 | queue_head_t * services, | |
802 | const AggressivesRecord * array, | |
803 | int count ); | |
804 | ||
805 | void broadcastAggressives( | |
806 | const AggressivesRecord * array, | |
807 | int count ); | |
808 | ||
0b4c1975 | 809 | IOReturn setPMAssertionUserLevels(IOPMDriverAssertionType); |
6d2010ae | 810 | |
0b4c1975 A |
811 | void publishSleepWakeUUID( bool shouldPublish ); |
812 | ||
6d2010ae | 813 | void evaluatePolicy( int stimulus, uint32_t arg = 0 ); |
39236c6e A |
814 | void requestFullWake( FullWakeReason reason ); |
815 | void willEnterFullWake( void ); | |
6d2010ae | 816 | |
fe8ab488 | 817 | void evaluateAssertions(IOPMDriverAssertionType newAssertions, |
39236c6e | 818 | IOPMDriverAssertionType oldAssertions); |
7ddcb079 | 819 | |
6d2010ae A |
820 | void deregisterPMSettingObject( PMSettingObject * pmso ); |
821 | ||
39236c6e | 822 | void sleepWakeDebugMemAlloc( ); |
fe8ab488 A |
823 | void sleepWakeDebugDumpFromMem(IOMemoryMap *logBufMap); |
824 | void sleepWakeDebugDumpFromFile( ); | |
39236c6e A |
825 | IOMemoryMap *sleepWakeDebugRetrieve(); |
826 | errno_t sleepWakeDebugSaveFile(const char *name, char *buf, int len); | |
fe8ab488 A |
827 | errno_t sleepWakeDebugCopyFile( struct vnode *srcVp, |
828 | vfs_context_t srcCtx, | |
829 | char *tmpBuf, uint64_t tmpBufSize, | |
830 | uint64_t srcOffset, | |
831 | const char *dstFname, | |
832 | uint64_t numBytes, | |
833 | uint32_t crc); | |
834 | ||
39236c6e | 835 | |
0b4c1975 A |
836 | #if HIBERNATION |
837 | bool getSleepOption( const char * key, uint32_t * option ); | |
db609669 A |
838 | bool evaluateSystemSleepPolicy( IOPMSystemSleepParameters * p, |
839 | int phase, uint32_t * hibMode ); | |
0b4c1975 A |
840 | void evaluateSystemSleepPolicyEarly( void ); |
841 | void evaluateSystemSleepPolicyFinal( void ); | |
842 | #endif /* HIBERNATION */ | |
13f56ec4 A |
843 | |
844 | bool latchDisplayWranglerTickle( bool latch ); | |
39236c6e | 845 | void setDisplayPowerOn( uint32_t options ); |
fe8ab488 A |
846 | |
847 | void acceptSystemWakeEvents( bool accept ); | |
22ba694c A |
848 | void systemDidNotSleep( void ); |
849 | void preventTransitionToUserActive( bool prevent ); | |
a1c7dba1 | 850 | void setThermalState(OSObject *value); |
b0d623f7 | 851 | #endif /* XNU_KERNEL_PRIVATE */ |
1c79356b A |
852 | }; |
853 | ||
b0d623f7 | 854 | #ifdef XNU_KERNEL_PRIVATE |
1c79356b A |
855 | class IORootParent: public IOService |
856 | { | |
b0d623f7 | 857 | OSDeclareFinalStructors(IORootParent) |
0b4e3aa0 | 858 | |
b0d623f7 | 859 | public: |
6d2010ae A |
860 | static void initialize( void ); |
861 | virtual OSObject * copyProperty( const char * aKey ) const; | |
b0d623f7 A |
862 | bool start( IOService * nub ); |
863 | void shutDownSystem( void ); | |
864 | void restartSystem( void ); | |
865 | void sleepSystem( void ); | |
866 | void dozeSystem( void ); | |
867 | void sleepToDoze( void ); | |
868 | void wakeSystem( void ); | |
1c79356b | 869 | }; |
b0d623f7 | 870 | #endif /* XNU_KERNEL_PRIVATE */ |
1c79356b | 871 | |
b0d623f7 | 872 | #endif /* _IOKIT_ROOTDOMAIN_H */ |