2 * Copyright (c) 1998-2016 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #ifndef _IOKIT_ROOTDOMAIN_H
29 #define _IOKIT_ROOTDOMAIN_H
31 #include <IOKit/IOService.h>
32 #include <IOKit/pwr_mgt/IOPM.h>
33 #include <IOKit/IOBufferMemoryDescriptor.h>
34 #include <sys/vnode.h>
36 #ifdef XNU_KERNEL_PRIVATE
37 struct AggressivesRecord
;
38 struct IOPMMessageFilterContext
;
40 struct IOPMSystemSleepParameters
;
41 class PMSettingObject
;
43 class IOPMPowerStateQueue
;
44 class RootDomainUserClient
;
45 class PMAssertionsTracker
;
47 #define OBFUSCATE(x) (void *)VM_KERNEL_UNSLIDE_OR_PERM(x)
52 * Types for PM Assertions
53 * For creating, releasing, and getting PM assertion levels.
56 /*! IOPMDriverAssertionType
57 * A bitfield describing a set of assertions. May be used to specify which assertions
58 * to set with <link>IOPMrootDomain::createPMAssertion</link>; or to query which
59 * assertions are set with <link>IOPMrootDomain::releasePMAssertion</link>.
61 typedef uint64_t IOPMDriverAssertionType
;
63 /* IOPMDriverAssertionID
64 * Drivers may create PM assertions to request system behavior (keep the system awake,
65 * or keep the display awake). When a driver creates an assertion via
66 * <link>IOPMrootDomain::createPMAssertion</link>, PM returns a handle to
67 * the assertion of type IOPMDriverAssertionID.
69 typedef uint64_t IOPMDriverAssertionID
;
70 #define kIOPMUndefinedDriverAssertionID 0
72 /* IOPMDriverAssertionLevel
73 * Possible values for IOPMDriverAssertionLevel are <link>kIOPMDriverAssertionLevelOff</link>
74 * and <link>kIOPMDriverAssertionLevelOn</link>
76 typedef uint32_t IOPMDriverAssertionLevel
;
77 #define kIOPMDriverAssertionLevelOff 0
78 #define kIOPMDriverAssertionLevelOn 255
81 * Flags for get/setSleepSupported()
84 kRootDomainSleepNotSupported
= 0x00000000,
85 kRootDomainSleepSupported
= 0x00000001,
86 kFrameBufferDeepSleepSupported
= 0x00000002,
87 kPCICantSleep
= 0x00000004
91 *IOPMrootDomain registry property keys
93 #define kRootDomainSupportedFeatures "Supported Features"
94 #define kRootDomainSleepReasonKey "Last Sleep Reason"
95 #define kRootDomainSleepOptionsKey "Last Sleep Options"
96 #define kIOPMRootDomainWakeReasonKey "Wake Reason"
97 #define kIOPMRootDomainWakeTypeKey "Wake Type"
98 #define kIOPMRootDomainPowerStatusKey "Power Status"
101 * Possible sleep reasons found under kRootDomainSleepReasonsKey
103 #define kIOPMClamshellSleepKey "Clamshell Sleep"
104 #define kIOPMPowerButtonSleepKey "Power Button Sleep"
105 #define kIOPMSoftwareSleepKey "Software Sleep"
106 #define kIOPMOSSwitchHibernationKey "OS Switch Sleep"
107 #define kIOPMIdleSleepKey "Idle Sleep"
108 #define kIOPMLowPowerSleepKey "Low Power Sleep"
109 #define kIOPMThermalEmergencySleepKey "Thermal Emergency Sleep"
110 #define kIOPMMaintenanceSleepKey "Maintenance Sleep"
113 * String constants for communication with PM CPU
115 #define kIOPMRootDomainLidCloseCString "LidClose"
116 #define kIOPMRootDomainBatPowerCString "BatPower"
119 * Supported Feature bitfields for IOPMrootDomain::publishFeature()
122 kIOPMSupportedOnAC
= (1<<0),
123 kIOPMSupportedOnBatt
= (1<<1),
124 kIOPMSupportedOnUPS
= (1<<2)
127 typedef IOReturn (*IOPMSettingControllerCallback
)
128 (OSObject
*target
, const OSSymbol
*type
,
129 OSObject
*val
, uintptr_t refcon
);
132 IONotifier
* registerSleepWakeInterest(
133 IOServiceInterestHandler
, void *, void * = 0);
135 IONotifier
* registerPrioritySleepWakeInterest(
136 IOServiceInterestHandler handler
,
137 void * self
, void * ref
= 0);
139 IOReturn
acknowledgeSleepWakeNotification(void * );
141 IOReturn
vetoSleepWakeNotification(void * PMrefcon
);
144 #define IOPM_ROOTDOMAIN_REV 2
146 class IOPMrootDomain
: public IOService
148 OSDeclareFinalStructors(IOPMrootDomain
)
151 static IOPMrootDomain
* construct( void );
153 virtual bool start( IOService
* provider
) APPLE_KEXT_OVERRIDE
;
154 virtual IOReturn
setAggressiveness( unsigned long, unsigned long ) APPLE_KEXT_OVERRIDE
;
155 virtual IOReturn
getAggressiveness( unsigned long, unsigned long * ) APPLE_KEXT_OVERRIDE
;
157 virtual IOReturn
sleepSystem( void );
158 IOReturn
sleepSystemOptions( OSDictionary
*options
);
160 virtual IOReturn
setProperties( OSObject
* ) APPLE_KEXT_OVERRIDE
;
161 virtual bool serializeProperties( OSSerialize
* s
) const APPLE_KEXT_OVERRIDE
;
162 virtual OSObject
* copyProperty( const char * aKey
) const APPLE_KEXT_OVERRIDE
;
164 /*! @function systemPowerEventOccurred
165 @abstract Other drivers may inform IOPMrootDomain of system PM events
166 @discussion systemPowerEventOccurred is a richer alternative to receivePowerNotification()
167 Only Apple-owned kexts should have reason to call systemPowerEventOccurred.
168 @param event An OSSymbol describing the type of power event.
169 @param intValue A 32-bit integer value associated with the event.
170 @result kIOReturnSuccess on success */
172 IOReturn
systemPowerEventOccurred(
173 const OSSymbol
*event
,
176 IOReturn
systemPowerEventOccurred(
177 const OSSymbol
*event
,
180 #ifdef XNU_KERNEL_PRIVATE // Hide doc from public headers
181 /*! @function claimSystemWakeEvent
182 @abstract Apple-internal SPI to describe system wake events.
183 @discussion IOKit drivers may call claimSystemWakeEvent() during system wakeup to
184 provide human readable debug information describing the event(s) that
185 caused the system to wake.
187 - Drivers should call claimSystemWakeEvent before completing
188 their setPowerState() acknowledgement. IOPMrootDomain stops
189 collecting wake events when driver wake is complete.
191 - It is only appropriate to claim a wake event when the driver
192 can positively identify its hardware has generated an event
193 that can wake the system.
195 - This call tracks wake events from a non-S0 state (S0i, S3, S4) into S0.
196 - This call does not track wake events from DarkWake(S0) to FullWake(S0).
199 (reason = "WiFi.TCPData",
200 details = "TCPKeepAlive packet arrived from IP 16.2.1.1")
201 (reason = "WiFi.ScanOffload",
202 details = "WiFi station 'AppleWiFi' signal dropped below threshold")
203 (reason = "Enet.LinkToggle",
204 details = "Ethernet attached")
206 @param device The device/nub that is associated with the wake event.
208 @param flags Pass kIOPMWakeEventSource if the device is the source
209 of the wake event. Pass zero if the device is forwarding or
210 aggregating wake events from multiple sources, e.g. an USB or
211 Thunderbolt host controller.
213 @param reason Caller should pass a human readable C string describing the
214 wake reason. Please use a string from the list below, or create
215 your own string matching this format:
231 Enet.ConflictResolution
239 @param details Optional details further describing the wake event.
240 Please pass an OSString defining the event.
243 void claimSystemWakeEvent( IOService
*device
,
246 OSObject
*details
= 0 );
248 virtual IOReturn
receivePowerNotification( UInt32 msg
);
250 virtual void setSleepSupported( IOOptionBits flags
);
252 virtual IOOptionBits
getSleepSupported( void );
254 void wakeFromDoze( void );
256 // KEXT driver announces support of power management feature
258 void publishFeature( const char *feature
);
260 // KEXT driver announces support of power management feature
261 // And specifies power sources with kIOPMSupportedOn{AC/Batt/UPS} bitfield.
262 // Returns a unique uint32_t identifier for later removing support for this
264 // NULL is acceptable for uniqueFeatureID for kexts without plans to unload.
266 void publishFeature( const char *feature
,
267 uint32_t supportedWhere
,
268 uint32_t *uniqueFeatureID
);
270 // KEXT driver announces removal of a previously published power management
271 // feature. Pass 'uniqueFeatureID' returned from publishFeature()
273 IOReturn
removePublishedFeature( uint32_t removeFeatureID
);
275 /*! @function copyPMSetting
276 @abstract Copy the current value for a PM setting. Returns an OSNumber or
277 OSData depending on the setting.
278 @param whichSetting Name of the desired setting.
279 @result OSObject value if valid, NULL otherwise. */
281 OSObject
* copyPMSetting( OSSymbol
*whichSetting
);
283 /*! @function registerPMSettingController
284 @abstract Register for callbacks on changes to certain PM settings.
285 @param settings NULL terminated array of C strings, each string for a PM
286 setting that the caller is interested in and wants to get callbacks for.
287 @param callout C function ptr or member function cast as such.
288 @param target The target of the callback, usually 'this'
289 @param refcon Will be passed to caller in callback; for caller's use.
290 @param handle Caller should keep the OSObject * returned here. If non-NULL,
291 handle will have a retain count of 1 on return. To deregister, pass to
292 unregisterPMSettingController()
293 @result kIOReturnSuccess on success. */
295 IOReturn
registerPMSettingController(
296 const OSSymbol
*settings
[],
297 IOPMSettingControllerCallback callout
,
300 OSObject
**handle
); // out param
302 /*! @function registerPMSettingController
303 @abstract Register for callbacks on changes to certain PM settings.
304 @param settings NULL terminated array of C strings, each string for a PM
305 setting that the caller is interested in and wants to get callbacks for.
306 @param supportedPowerSources bitfield indicating which power sources these
307 settings are supported for (kIOPMSupportedOnAC, etc.)
308 @param callout C function ptr or member function cast as such.
309 @param target The target of the callback, usually 'this'
310 @param refcon Will be passed to caller in callback; for caller's use.
311 @param handle Caller should keep the OSObject * returned here. If non-NULL,
312 handle will have a retain count of 1 on return. To deregister, pass to
313 unregisterPMSettingController()
314 @result kIOReturnSuccess on success. */
316 IOReturn
registerPMSettingController(
317 const OSSymbol
*settings
[],
318 uint32_t supportedPowerSources
,
319 IOPMSettingControllerCallback callout
,
322 OSObject
**handle
); // out param
324 virtual IONotifier
* registerInterest(
325 const OSSymbol
* typeOfInterest
,
326 IOServiceInterestHandler handler
,
327 void * target
, void * ref
= 0 ) APPLE_KEXT_OVERRIDE
;
329 virtual IOReturn
callPlatformFunction(
330 const OSSymbol
*functionName
,
331 bool waitForFunction
,
332 void *param1
, void *param2
,
333 void *param3
, void *param4
) APPLE_KEXT_OVERRIDE
;
335 /*! @function createPMAssertion
336 @abstract Creates an assertion to influence system power behavior.
337 @param whichAssertionsBits A bitfield specify the assertion that the caller requests.
338 @param assertionLevel An integer detailing the initial assertion level, kIOPMDriverAssertionLevelOn
339 or kIOPMDriverAssertionLevelOff.
340 @param ownerService A pointer to the caller's IOService class, for tracking.
341 @param ownerDescription A reverse-DNS string describing the caller's identity and reason.
342 @result On success, returns a new assertion of type IOPMDriverAssertionID
344 IOPMDriverAssertionID
createPMAssertion(
345 IOPMDriverAssertionType whichAssertionsBits
,
346 IOPMDriverAssertionLevel assertionLevel
,
347 IOService
*ownerService
,
348 const char *ownerDescription
);
350 /* @function setPMAssertionLevel
351 @abstract Modify the level of a pre-existing assertion.
352 @discussion Change the value of a PM assertion to influence system behavior,
353 without undergoing the work required to create or destroy an assertion. Suggested
354 for clients who will assert and de-assert needs for PM behavior several times over
356 @param assertionID An assertion ID previously returned by <link>createPMAssertion</link>
357 @param assertionLevel The new assertion level.
358 @result kIOReturnSuccess if it worked; kIOReturnNotFound or other IOReturn error on failure.
360 IOReturn
setPMAssertionLevel(IOPMDriverAssertionID assertionID
, IOPMDriverAssertionLevel assertionLevel
);
362 /*! @function getPMAssertionLevel
363 @absract Returns the active level of the specified assertion(s).
364 @discussion Returns <link>kIOPMDriverAssertionLevelOff</link> or
365 <link>kIOPMDriverAssertionLevelOn</link>. If multiple assertions are specified
366 in the bitfield, only returns <link>kIOPMDriverAssertionLevelOn</link>
367 if all assertions are active.
368 @param whichAssertionBits Bits defining the assertion or assertions the caller is interested in
369 the level of. If in doubt, pass <link>kIOPMDriverAssertionCPUBit</link> as the argument.
370 @result Returns <link>kIOPMDriverAssertionLevelOff</link> or
371 <link>kIOPMDriverAssertionLevelOn</link> indicating the specified assertion's levels, if available.
372 If the assertions aren't supported on this machine, or aren't recognized by the OS, the
375 IOPMDriverAssertionLevel
getPMAssertionLevel(IOPMDriverAssertionType whichAssertionBits
);
377 /*! @function releasePMAssertion
378 @abstract Removes an assertion to influence system power behavior.
379 @result On success, returns a new assertion of type IOPMDriverAssertionID *
381 IOReturn
releasePMAssertion(IOPMDriverAssertionID releaseAssertion
);
383 /*! @function restartWithStackshot
384 @abstract Take a stackshot of the system and restart the system.
385 @result Return kIOReturnSuccess if it work, kIOReturnError if the service is not available.
387 IOReturn
restartWithStackshot();
390 virtual IOReturn
changePowerStateTo( unsigned long ordinal
) APPLE_KEXT_COMPATIBILITY_OVERRIDE
;
391 virtual IOReturn
changePowerStateToPriv( unsigned long ordinal
);
392 virtual IOReturn
requestPowerDomainState( IOPMPowerFlags
, IOPowerConnection
*, unsigned long ) APPLE_KEXT_OVERRIDE
;
393 virtual void powerChangeDone( unsigned long ) APPLE_KEXT_OVERRIDE
;
394 virtual bool tellChangeDown( unsigned long ) APPLE_KEXT_OVERRIDE
;
395 virtual bool askChangeDown( unsigned long ) APPLE_KEXT_OVERRIDE
;
396 virtual void tellChangeUp( unsigned long ) APPLE_KEXT_OVERRIDE
;
397 virtual void tellNoChangeDown( unsigned long ) APPLE_KEXT_OVERRIDE
;
398 virtual IOReturn
configureReport(IOReportChannelList
*channels
,
399 IOReportConfigureAction action
,
401 void *destination
) APPLE_KEXT_OVERRIDE
;
402 virtual IOReturn
updateReport(IOReportChannelList
*channels
,
403 IOReportUpdateAction action
,
405 void *destination
) APPLE_KEXT_OVERRIDE
;
407 void configureReportGated(uint64_t channel_id
,
410 IOReturn
updateReportGated(uint64_t ch_id
,
412 IOBufferMemoryDescriptor
*dest
);
414 #ifdef XNU_KERNEL_PRIVATE
415 /* Root Domain internals */
417 void tagPowerPlaneService(
419 IOPMActions
* actions
);
421 void overrideOurPowerChange(
423 IOPMActions
* actions
,
424 IOPMPowerStateIndex
* inOutPowerState
,
425 IOPMPowerChangeFlags
* inOutChangeFlags
,
426 IOPMRequestTag requestTag
);
428 void handleOurPowerChangeStart(
430 IOPMActions
* actions
,
431 IOPMPowerStateIndex powerState
,
432 IOPMPowerChangeFlags
* inOutChangeFlags
,
433 IOPMRequestTag requestTag
);
435 void handleOurPowerChangeDone(
437 IOPMActions
* actions
,
438 IOPMPowerStateIndex powerState
,
439 IOPMPowerChangeFlags changeFlags
,
440 IOPMRequestTag requestTag
);
442 void overridePowerChangeForUIService(
444 IOPMActions
* actions
,
445 IOPMPowerStateIndex
* inOutPowerState
,
446 IOPMPowerChangeFlags
* inOutChangeFlags
);
448 void handleActivityTickleForDisplayWrangler(
450 IOPMActions
* actions
);
452 void handleUpdatePowerClientForDisplayWrangler(
454 IOPMActions
* actions
,
455 const OSSymbol
* powerClient
,
456 IOPMPowerStateIndex oldPowerState
,
457 IOPMPowerStateIndex newPowerState
);
459 bool shouldDelayChildNotification(
460 IOService
* service
);
462 void handlePowerChangeStartForPCIDevice(
464 IOPMActions
* actions
,
465 IOPMPowerStateIndex powerState
,
466 IOPMPowerChangeFlags
* inOutChangeFlags
);
468 void handlePowerChangeDoneForPCIDevice(
470 IOPMActions
* actions
,
471 IOPMPowerStateIndex powerState
,
472 IOPMPowerChangeFlags changeFlags
);
474 void askChangeDownDone(
475 IOPMPowerChangeFlags
* inOutChangeFlags
,
478 void handlePublishSleepWakeUUID(
481 void handleQueueSleepWakeUUID(
484 void handleDisplayPowerOn( );
486 void willNotifyPowerChildren( IOPMPowerStateIndex newPowerState
);
488 IOReturn
setMaintenanceWakeCalendar(
489 const IOPMCalendarStruct
* calendar
);
491 IOReturn
getSystemSleepType(uint32_t * sleepType
, uint32_t * standbyTimer
);
493 // Handle callbacks from IOService::systemWillShutdown()
494 void acknowledgeSystemWillShutdown( IOService
* from
);
496 // Handle platform halt and restart notifications
497 void handlePlatformHaltRestart( UInt32 pe_type
);
499 IOReturn
shutdownSystem( void );
500 IOReturn
restartSystem( void );
501 void handleSleepTimerExpiration( void );
503 bool activitySinceSleep(void);
504 bool abortHibernation(void);
505 void updateConsoleUsers(void);
507 IOReturn
joinAggressiveness( IOService
* service
);
508 void handleAggressivesRequests( void );
510 void kdebugTrace(uint32_t event
, uint64_t regId
,
511 uintptr_t param1
, uintptr_t param2
, uintptr_t param3
= 0);
512 void tracePoint(uint8_t point
);
513 void traceDetail(uint32_t msgType
, uint32_t msgIndex
, uint32_t delay
);
514 void traceDetail(OSObject
*notifier
);
515 void traceAckDelay(OSObject
*notifier
, uint32_t response
, uint32_t delay_ms
);
517 void startSpinDump(uint32_t spindumpKind
);
519 bool systemMessageFilter(
520 void * object
, void * arg1
, void * arg2
, void * arg3
);
522 bool updatePreventIdleSleepList(
523 IOService
* service
, bool addNotRemove
);
524 void updatePreventSystemSleepList(
525 IOService
* service
, bool addNotRemove
);
527 void publishPMSetting(
528 const OSSymbol
* feature
, uint32_t where
, uint32_t * featureID
);
530 void pmStatsRecordEvent(
532 AbsoluteTime timestamp
);
534 void pmStatsRecordApplicationResponse(
535 const OSSymbol
*response
,
541 IOPMPowerStateIndex ps
=0);
543 void copyWakeReasonString( char * outBuf
, size_t bufSize
);
546 bool getHibernateSettings(
547 uint32_t * hibernateMode
,
548 uint32_t * hibernateFreeRatio
,
549 uint32_t * hibernateFreeTime
);
550 bool mustHibernate( void );
552 void takeStackshot(bool restart
, bool isOSXWatchdog
, bool isSpinDump
);
553 void sleepWakeDebugTrig(bool restart
);
554 void sleepWakeDebugEnableWdog();
555 bool sleepWakeDebugIsWdogEnabled();
556 static void saveTimeoutAppStackShot(void *p0
, void *p1
);
557 void sleepWakeDebugSaveSpinDumpFile();
558 void swdDebugSetup();
559 void swdDebugTeardown();
562 friend class PMSettingObject
;
563 friend class RootDomainUserClient
;
564 friend class PMAssertionsTracker
;
566 static IOReturn
sysPowerDownHandler( void * target
, void * refCon
,
567 UInt32 messageType
, IOService
* service
,
568 void * messageArgument
, vm_size_t argSize
);
570 static IOReturn
displayWranglerNotification( void * target
, void * refCon
,
571 UInt32 messageType
, IOService
* service
,
572 void * messageArgument
, vm_size_t argSize
);
574 static IOReturn
rootBusyStateChangeHandler( void * target
, void * refCon
,
575 UInt32 messageType
, IOService
* service
,
576 void * messageArgument
, vm_size_t argSize
);
578 static bool displayWranglerMatchPublished( void * target
, void * refCon
,
579 IOService
* newService
,
580 IONotifier
* notifier
);
582 static bool IONVRAMMatchPublished( void * target
, void * refCon
,
583 IOService
* newService
,
584 IONotifier
* notifier
);
586 static bool batteryPublished( void * target
, void * refCon
,
587 IOService
* resourceService
,
588 IONotifier
* notifier
);
590 void initializeBootSessionUUID( void );
592 void fullWakeDelayedWork( void );
594 IOService
* wrangler
;
595 OSDictionary
* wranglerIdleSettings
;
597 IOLock
*featuresDictLock
; // guards supportedFeatures
598 IOLock
*wakeEventLock
;
599 IOPMPowerStateQueue
*pmPowerStateQueue
;
601 OSArray
*allowedPMSettings
;
602 OSArray
*noPublishPMSettings
;
603 PMTraceWorker
*pmTracer
;
604 PMAssertionsTracker
*pmAssertions
;
606 // Settings controller info
607 IOLock
*settingsCtrlLock
;
608 OSDictionary
*settingsCallbacks
;
609 OSDictionary
*fPMSettingsDict
;
611 IONotifier
*_batteryPublishNotifier
;
612 IONotifier
*_displayWranglerNotifier
;
615 const OSSymbol
*_statsNameKey
;
616 const OSSymbol
*_statsPIDKey
;
617 const OSSymbol
*_statsTimeMSKey
;
618 const OSSymbol
*_statsResponseTypeKey
;
619 const OSSymbol
*_statsMessageTypeKey
;
620 const OSSymbol
*_statsPowerCapsKey
;
622 uint32_t darkWakeCnt
;
623 uint32_t displayWakeCnt
;
625 OSString
*queuedSleepWakeUUIDString
;
626 OSArray
*pmStatsAppResponses
;
627 IOLock
*pmStatsLock
; // guards pmStatsAppResponses
629 void *sleepDelaysReport
; // report to track time taken to go to sleep
630 uint32_t sleepDelaysClientCnt
; // Number of interested clients in sleepDelaysReport
631 uint64_t ts_sleepStart
;
632 uint64_t wake2DarkwakeDelay
; // Time taken to change from full wake -> Dark wake
635 void *assertOnWakeReport
; // report to track time spent without any assertions held after wake
636 uint32_t assertOnWakeClientCnt
; // Number of clients interested in assertOnWakeReport
637 clock_sec_t assertOnWakeSecs
; // Num of secs after wake for first assertion
641 // Pref: idle time before idle sleep
642 bool idleSleepEnabled
;
643 unsigned long sleepSlider
;
644 unsigned long idleSeconds
;
645 uint64_t autoWakeStart
;
646 uint64_t autoWakeEnd
;
648 // Difference between sleepSlider and longestNonSleepSlider
649 unsigned long extraSleepDelay
;
651 // Used to wait between say display idle and system idle
652 thread_call_t extraSleepTimer
;
653 thread_call_t diskSyncCalloutEntry
;
654 thread_call_t fullWakeThreadCall
;
655 thread_call_t swdDebugSetupEntry
;
656 thread_call_t swdDebugTearDownEntry
;
657 thread_call_t updateConsoleUsersEntry
;
659 // Track system capabilities.
660 uint32_t _desiredCapability
;
661 uint32_t _currentCapability
;
662 uint32_t _pendingCapability
;
663 uint32_t _highestCapability
;
664 OSSet
* _joinedCapabilityClients
;
665 uint32_t _systemStateGeneration
;
667 // Type of clients that can receive system messages.
669 kSystemMessageClientPowerd
= 0x01,
670 kSystemMessageClientLegacyApp
= 0x02,
671 kSystemMessageClientKernel
= 0x04,
672 kSystemMessageClientAll
= 0x07
674 uint32_t _systemMessageClientMask
;
676 // Power state and capability change transitions.
678 kSystemTransitionNone
= 0,
679 kSystemTransitionSleep
= 1,
680 kSystemTransitionWake
= 2,
681 kSystemTransitionCapability
= 3,
682 kSystemTransitionNewCapClient
= 4
683 } _systemTransitionType
;
685 unsigned int systemBooting
:1;
686 unsigned int systemShutdown
:1;
687 unsigned int systemDarkWake
:1;
688 unsigned int clamshellExists
:1;
689 unsigned int clamshellClosed
:1;
690 unsigned int clamshellDisabled
:1;
691 unsigned int desktopMode
:1;
692 unsigned int acAdaptorConnected
:1;
694 unsigned int clamshellSleepDisabled
:1;
695 unsigned int idleSleepTimerPending
:1;
696 unsigned int userDisabledAllSleep
:1;
697 unsigned int ignoreTellChangeDown
:1;
698 unsigned int wranglerAsleep
:1;
699 unsigned int wranglerTickled
:1;
700 unsigned int _preventUserActive
:1;
701 unsigned int graphicsSuppressed
:1;
703 unsigned int capabilityLoss
:1;
704 unsigned int pciCantSleepFlag
:1;
705 unsigned int pciCantSleepValid
:1;
706 unsigned int logGraphicsClamp
:1;
707 unsigned int darkWakeToSleepASAP
:1;
708 unsigned int darkWakeMaintenance
:1;
709 unsigned int darkWakeSleepService
:1;
710 unsigned int darkWakePostTickle
:1;
712 unsigned int sleepTimerMaintenance
:1;
713 unsigned int sleepToStandby
:1;
714 unsigned int lowBatteryCondition
:1;
715 unsigned int hibernateDisabled
:1;
716 unsigned int hibernateRetry
:1;
717 unsigned int wranglerTickleLatched
:1;
718 unsigned int userIsActive
:1;
719 unsigned int userWasActive
:1;
721 unsigned int displayIdleForDemandSleep
:1;
722 unsigned int darkWakeHibernateError
:1;
723 unsigned int thermalWarningState
:1;
724 unsigned int toldPowerdCapWillChange
:1;
725 unsigned int displayPowerOnRequested
:1;
727 uint8_t tasksSuspended
;
728 uint32_t hibernateMode
;
729 AbsoluteTime userActivityTime
;
730 AbsoluteTime userActivityTime_prev
;
731 uint32_t userActivityCount
;
732 uint32_t userActivityAtSleep
;
733 uint32_t lastSleepReason
;
734 uint32_t fullToDarkReason
;
735 uint32_t hibernateAborted
;
736 uint8_t standbyNixed
;
739 enum FullWakeReason
{
740 kFullWakeReasonNone
= 0,
741 kFullWakeReasonLocalUser
= 1,
742 kFullWakeReasonDisplayOn
= 2,
743 fFullWakeReasonDisplayOnAndLocalUser
= 3
745 uint32_t fullWakeReason
;
747 // Info for communicating system state changes to PMCPU
748 int32_t idxPMCPUClamshell
;
749 int32_t idxPMCPULimitedPower
;
751 IOOptionBits platformSleepSupport
;
752 uint32_t _debugWakeSeconds
;
753 uint32_t _lastDebugWakeSeconds
;
755 queue_head_t aggressivesQueue
;
756 thread_call_t aggressivesThreadCall
;
757 OSData
* aggressivesData
;
759 AbsoluteTime userBecameInactiveTime
;
761 // PCI top-level PM trace
762 IOService
* pciHostBridgeDevice
;
763 IOService
* pciHostBridgeDriver
;
765 IONotifier
* systemCapabilityNotifier
;
770 } PMNotifySuspendedStruct
;
772 uint32_t pmSuspendedCapacity
;
773 uint32_t pmSuspendedSize
;
774 PMNotifySuspendedStruct
*pmSuspendedPIDS
;
776 OSSet
* preventIdleSleepList
;
777 OSSet
* preventSystemSleepList
;
779 UInt32 _scheduledAlarms
;
780 UInt32 _userScheduledAlarm
;
783 clock_sec_t _standbyTimerResetSeconds
;
785 volatile uint32_t swd_lock
; /* Lock to access swd_buffer & and its header */
786 void * swd_buffer
; /* Memory allocated for dumping sleep/wake logs */
787 uint32_t swd_flags
; /* Flags defined in IOPMPrivate.h */
788 uint8_t swd_DebugImageSetup
;
789 void * swd_spindump_buffer
;
791 IOBufferMemoryDescriptor
*swd_memDesc
;
793 IOMemoryMap
* swd_logBufMap
; /* Memory with sleep/wake logs from previous boot */
795 // Wake Event Reporting
796 OSArray
* _systemWakeEventsArray
;
797 bool _acceptSystemWakeEvents
;
799 int findSuspendedPID(uint32_t pid
, uint32_t *outRefCount
);
801 // IOPMrootDomain internal sleep call
802 IOReturn
privateSleepSystem( uint32_t sleepReason
);
803 void reportUserInput( void );
804 void setDisableClamShellSleep( bool );
805 bool checkSystemSleepAllowed( IOOptionBits options
,
806 uint32_t sleepReason
);
807 bool checkSystemSleepEnabled( void );
808 bool checkSystemCanSleep( uint32_t sleepReason
);
809 bool checkSystemCanSustainFullWake( void );
811 void adjustPowerState( bool sleepASAP
= false );
812 void setQuickSpinDownTimeout( void );
813 void restoreUserSpinDownTimeout( void );
815 bool shouldSleepOnClamshellClosed(void );
816 void sendClientClamshellNotification( void );
818 // Inform PMCPU of changes to state like lid, AC vs. battery
819 void informCPUStateChange( uint32_t type
, uint32_t value
);
821 void dispatchPowerEvent( uint32_t event
, void * arg0
, uint64_t arg1
);
822 void handlePowerNotification( UInt32 msg
);
824 IOReturn
setPMSetting(const OSSymbol
*, OSObject
*);
826 void startIdleSleepTimer( uint32_t inSeconds
);
827 void cancelIdleSleepTimer( void );
828 uint32_t getTimeToIdleSleep( void );
830 IOReturn
setAggressiveness(
833 IOOptionBits options
);
835 void synchronizeAggressives(
836 queue_head_t
* services
,
837 const AggressivesRecord
* array
,
840 void broadcastAggressives(
841 const AggressivesRecord
* array
,
844 IOReturn
setPMAssertionUserLevels(IOPMDriverAssertionType
);
846 void publishSleepWakeUUID( bool shouldPublish
);
848 void evaluatePolicy( int stimulus
, uint32_t arg
= 0 );
849 void requestFullWake( FullWakeReason reason
);
850 void willEnterFullWake( void );
852 void evaluateAssertions(IOPMDriverAssertionType newAssertions
,
853 IOPMDriverAssertionType oldAssertions
);
854 void evaluateWranglerAssertions();
856 void deregisterPMSettingObject( PMSettingObject
* pmso
);
858 uint32_t checkForValidDebugData(const char *fname
, vfs_context_t
*ctx
,
859 void *tmpBuf
, struct vnode
**vp
);
860 void sleepWakeDebugMemAlloc( );
861 void sleepWakeDebugSpinDumpMemAlloc( );
862 void sleepWakeDebugDumpFromMem(IOMemoryMap
*logBufMap
);
863 void sleepWakeDebugDumpFromFile( );
864 IOMemoryMap
*sleepWakeDebugRetrieve();
865 errno_t
sleepWakeDebugSaveFile(const char *name
, char *buf
, int len
);
866 errno_t
sleepWakeDebugCopyFile( struct vnode
*srcVp
,
867 vfs_context_t srcCtx
,
868 char *tmpBuf
, uint64_t tmpBufSize
,
870 const char *dstFname
,
876 bool getSleepOption( const char * key
, uint32_t * option
);
877 bool evaluateSystemSleepPolicy( IOPMSystemSleepParameters
* p
,
878 int phase
, uint32_t * hibMode
);
879 void evaluateSystemSleepPolicyEarly( void );
880 void evaluateSystemSleepPolicyFinal( void );
881 #endif /* HIBERNATION */
883 bool latchDisplayWranglerTickle( bool latch
);
884 void setDisplayPowerOn( uint32_t options
);
886 void acceptSystemWakeEvents( bool accept
);
887 void systemDidNotSleep( void );
888 void preventTransitionToUserActive( bool prevent
);
889 void setThermalState(OSObject
*value
);
890 void copySleepPreventersList(OSArray
**idleSleepList
, OSArray
**systemSleepList
);
891 #endif /* XNU_KERNEL_PRIVATE */
894 #ifdef XNU_KERNEL_PRIVATE
895 class IORootParent
: public IOService
897 OSDeclareFinalStructors(IORootParent
)
900 static void initialize( void );
901 virtual OSObject
* copyProperty( const char * aKey
) const APPLE_KEXT_OVERRIDE
;
902 bool start( IOService
* nub
) APPLE_KEXT_OVERRIDE
;
903 void shutDownSystem( void );
904 void restartSystem( void );
905 void sleepSystem( void );
906 void dozeSystem( void );
907 void sleepToDoze( void );
908 void wakeSystem( void );
910 #endif /* XNU_KERNEL_PRIVATE */
912 #endif /* _IOKIT_ROOTDOMAIN_H */