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) \
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))
54 * Types for PM Assertions
55 * For creating, releasing, and getting PM assertion levels.
58 /*! IOPMDriverAssertionType
59 * A bitfield describing a set of assertions. May be used to specify which assertions
60 * to set with <link>IOPMrootDomain::createPMAssertion</link>; or to query which
61 * assertions are set with <link>IOPMrootDomain::releasePMAssertion</link>.
63 typedef uint64_t IOPMDriverAssertionType
;
65 /* IOPMDriverAssertionID
66 * Drivers may create PM assertions to request system behavior (keep the system awake,
67 * or keep the display awake). When a driver creates an assertion via
68 * <link>IOPMrootDomain::createPMAssertion</link>, PM returns a handle to
69 * the assertion of type IOPMDriverAssertionID.
71 typedef uint64_t IOPMDriverAssertionID
;
72 #define kIOPMUndefinedDriverAssertionID 0
74 /* IOPMDriverAssertionLevel
75 * Possible values for IOPMDriverAssertionLevel are <link>kIOPMDriverAssertionLevelOff</link>
76 * and <link>kIOPMDriverAssertionLevelOn</link>
78 typedef uint32_t IOPMDriverAssertionLevel
;
79 #define kIOPMDriverAssertionLevelOff 0
80 #define kIOPMDriverAssertionLevelOn 255
83 * Flags for get/setSleepSupported()
86 kRootDomainSleepNotSupported
= 0x00000000,
87 kRootDomainSleepSupported
= 0x00000001,
88 kFrameBufferDeepSleepSupported
= 0x00000002,
89 kPCICantSleep
= 0x00000004
93 *IOPMrootDomain registry property keys
95 #define kRootDomainSupportedFeatures "Supported Features"
96 #define kRootDomainSleepReasonKey "Last Sleep Reason"
97 #define kRootDomainSleepOptionsKey "Last Sleep Options"
98 #define kIOPMRootDomainWakeReasonKey "Wake Reason"
99 #define kIOPMRootDomainWakeTypeKey "Wake Type"
100 #define kIOPMRootDomainPowerStatusKey "Power Status"
103 * Possible sleep reasons found under kRootDomainSleepReasonsKey
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"
112 #define kIOPMMaintenanceSleepKey "Maintenance Sleep"
115 * String constants for communication with PM CPU
117 #define kIOPMRootDomainLidCloseCString "LidClose"
118 #define kIOPMRootDomainBatPowerCString "BatPower"
121 * Supported Feature bitfields for IOPMrootDomain::publishFeature()
124 kIOPMSupportedOnAC
= (1<<0),
125 kIOPMSupportedOnBatt
= (1<<1),
126 kIOPMSupportedOnUPS
= (1<<2)
129 typedef IOReturn (*IOPMSettingControllerCallback
)
130 (OSObject
*target
, const OSSymbol
*type
,
131 OSObject
*val
, uintptr_t refcon
);
134 IONotifier
* registerSleepWakeInterest(
135 IOServiceInterestHandler
, void *, void * = 0);
137 IONotifier
* registerPrioritySleepWakeInterest(
138 IOServiceInterestHandler handler
,
139 void * self
, void * ref
= 0);
141 IOReturn
acknowledgeSleepWakeNotification(void * );
143 IOReturn
vetoSleepWakeNotification(void * PMrefcon
);
146 #define IOPM_ROOTDOMAIN_REV 2
148 class IOPMrootDomain
: public IOService
150 OSDeclareFinalStructors(IOPMrootDomain
)
153 static IOPMrootDomain
* construct( void );
155 virtual bool start( IOService
* provider
) APPLE_KEXT_OVERRIDE
;
156 virtual IOReturn
setAggressiveness( unsigned long, unsigned long ) APPLE_KEXT_OVERRIDE
;
157 virtual IOReturn
getAggressiveness( unsigned long, unsigned long * ) APPLE_KEXT_OVERRIDE
;
159 virtual IOReturn
sleepSystem( void );
160 IOReturn
sleepSystemOptions( OSDictionary
*options
);
162 virtual IOReturn
setProperties( OSObject
* ) APPLE_KEXT_OVERRIDE
;
163 virtual bool serializeProperties( OSSerialize
* s
) const APPLE_KEXT_OVERRIDE
;
164 virtual OSObject
* copyProperty( const char * aKey
) const APPLE_KEXT_OVERRIDE
;
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 intValue A 32-bit integer value associated with the event.
172 @result kIOReturnSuccess on success */
174 IOReturn
systemPowerEventOccurred(
175 const OSSymbol
*event
,
178 IOReturn
systemPowerEventOccurred(
179 const OSSymbol
*event
,
182 #ifdef XNU_KERNEL_PRIVATE // Hide doc from public headers
183 /*! @function claimSystemWakeEvent
184 @abstract Apple-internal SPI to describe system wake events.
185 @discussion IOKit drivers may call claimSystemWakeEvent() during system wakeup to
186 provide human readable debug information describing the event(s) that
187 caused the system to wake.
189 - Drivers should call claimSystemWakeEvent before completing
190 their setPowerState() acknowledgement. IOPMrootDomain stops
191 collecting wake events when driver wake is complete.
193 - It is only appropriate to claim a wake event when the driver
194 can positively identify its hardware has generated an event
195 that can wake the system.
197 - This call tracks wake events from a non-S0 state (S0i, S3, S4) into S0.
198 - This call does not track wake events from DarkWake(S0) to FullWake(S0).
201 (reason = "WiFi.TCPData",
202 details = "TCPKeepAlive packet arrived from IP 16.2.1.1")
203 (reason = "WiFi.ScanOffload",
204 details = "WiFi station 'AppleWiFi' signal dropped below threshold")
205 (reason = "Enet.LinkToggle",
206 details = "Ethernet attached")
208 @param device The device/nub that is associated with the wake event.
210 @param flags Pass kIOPMWakeEventSource if the device is the source
211 of the wake event. Pass zero if the device is forwarding or
212 aggregating wake events from multiple sources, e.g. an USB or
213 Thunderbolt host controller.
215 @param reason Caller should pass a human readable C string describing the
216 wake reason. Please use a string from the list below, or create
217 your own string matching this format:
233 Enet.ConflictResolution
241 @param details Optional details further describing the wake event.
242 Please pass an OSString defining the event.
245 void claimSystemWakeEvent( IOService
*device
,
248 OSObject
*details
= 0 );
250 virtual IOReturn
receivePowerNotification( UInt32 msg
);
252 virtual void setSleepSupported( IOOptionBits flags
);
254 virtual IOOptionBits
getSleepSupported( void );
256 void wakeFromDoze( void );
258 // KEXT driver announces support of power management feature
260 void publishFeature( const char *feature
);
262 // KEXT driver announces support of power management feature
263 // And specifies power sources with kIOPMSupportedOn{AC/Batt/UPS} bitfield.
264 // Returns a unique uint32_t identifier for later removing support for this
266 // NULL is acceptable for uniqueFeatureID for kexts without plans to unload.
268 void publishFeature( const char *feature
,
269 uint32_t supportedWhere
,
270 uint32_t *uniqueFeatureID
);
272 // KEXT driver announces removal of a previously published power management
273 // feature. Pass 'uniqueFeatureID' returned from publishFeature()
275 IOReturn
removePublishedFeature( uint32_t removeFeatureID
);
277 /*! @function copyPMSetting
278 @abstract Copy the current value for a PM setting. Returns an OSNumber or
279 OSData depending on the setting.
280 @param whichSetting Name of the desired setting.
281 @result OSObject value if valid, NULL otherwise. */
283 OSObject
* copyPMSetting( OSSymbol
*whichSetting
);
285 /*! @function registerPMSettingController
286 @abstract Register for callbacks on changes to certain PM settings.
287 @param settings NULL terminated array of C strings, each string for a PM
288 setting that the caller is interested in and wants to get callbacks for.
289 @param callout C function ptr or member function cast as such.
290 @param target The target of the callback, usually 'this'
291 @param refcon Will be passed to caller in callback; for caller's use.
292 @param handle Caller should keep the OSObject * returned here. If non-NULL,
293 handle will have a retain count of 1 on return. To deregister, pass to
294 unregisterPMSettingController()
295 @result kIOReturnSuccess on success. */
297 IOReturn
registerPMSettingController(
298 const OSSymbol
*settings
[],
299 IOPMSettingControllerCallback callout
,
302 OSObject
**handle
); // out param
304 /*! @function registerPMSettingController
305 @abstract Register for callbacks on changes to certain PM settings.
306 @param settings NULL terminated array of C strings, each string for a PM
307 setting that the caller is interested in and wants to get callbacks for.
308 @param supportedPowerSources bitfield indicating which power sources these
309 settings are supported for (kIOPMSupportedOnAC, etc.)
310 @param callout C function ptr or member function cast as such.
311 @param target The target of the callback, usually 'this'
312 @param refcon Will be passed to caller in callback; for caller's use.
313 @param handle Caller should keep the OSObject * returned here. If non-NULL,
314 handle will have a retain count of 1 on return. To deregister, pass to
315 unregisterPMSettingController()
316 @result kIOReturnSuccess on success. */
318 IOReturn
registerPMSettingController(
319 const OSSymbol
*settings
[],
320 uint32_t supportedPowerSources
,
321 IOPMSettingControllerCallback callout
,
324 OSObject
**handle
); // out param
326 virtual IONotifier
* registerInterest(
327 const OSSymbol
* typeOfInterest
,
328 IOServiceInterestHandler handler
,
329 void * target
, void * ref
= 0 ) APPLE_KEXT_OVERRIDE
;
331 virtual IOReturn
callPlatformFunction(
332 const OSSymbol
*functionName
,
333 bool waitForFunction
,
334 void *param1
, void *param2
,
335 void *param3
, void *param4
) APPLE_KEXT_OVERRIDE
;
337 /*! @function createPMAssertion
338 @abstract Creates an assertion to influence system power behavior.
339 @param whichAssertionsBits A bitfield specify the assertion that the caller requests.
340 @param assertionLevel An integer detailing the initial assertion level, kIOPMDriverAssertionLevelOn
341 or kIOPMDriverAssertionLevelOff.
342 @param ownerService A pointer to the caller's IOService class, for tracking.
343 @param ownerDescription A reverse-DNS string describing the caller's identity and reason.
344 @result On success, returns a new assertion of type IOPMDriverAssertionID
346 IOPMDriverAssertionID
createPMAssertion(
347 IOPMDriverAssertionType whichAssertionsBits
,
348 IOPMDriverAssertionLevel assertionLevel
,
349 IOService
*ownerService
,
350 const char *ownerDescription
);
352 /* @function setPMAssertionLevel
353 @abstract Modify the level of a pre-existing assertion.
354 @discussion Change the value of a PM assertion to influence system behavior,
355 without undergoing the work required to create or destroy an assertion. Suggested
356 for clients who will assert and de-assert needs for PM behavior several times over
358 @param assertionID An assertion ID previously returned by <link>createPMAssertion</link>
359 @param assertionLevel The new assertion level.
360 @result kIOReturnSuccess if it worked; kIOReturnNotFound or other IOReturn error on failure.
362 IOReturn
setPMAssertionLevel(IOPMDriverAssertionID assertionID
, IOPMDriverAssertionLevel assertionLevel
);
364 /*! @function getPMAssertionLevel
365 @absract Returns the active level of the specified assertion(s).
366 @discussion Returns <link>kIOPMDriverAssertionLevelOff</link> or
367 <link>kIOPMDriverAssertionLevelOn</link>. If multiple assertions are specified
368 in the bitfield, only returns <link>kIOPMDriverAssertionLevelOn</link>
369 if all assertions are active.
370 @param whichAssertionBits Bits defining the assertion or assertions the caller is interested in
371 the level of. If in doubt, pass <link>kIOPMDriverAssertionCPUBit</link> as the argument.
372 @result Returns <link>kIOPMDriverAssertionLevelOff</link> or
373 <link>kIOPMDriverAssertionLevelOn</link> indicating the specified assertion's levels, if available.
374 If the assertions aren't supported on this machine, or aren't recognized by the OS, the
377 IOPMDriverAssertionLevel
getPMAssertionLevel(IOPMDriverAssertionType whichAssertionBits
);
379 /*! @function releasePMAssertion
380 @abstract Removes an assertion to influence system power behavior.
381 @result On success, returns a new assertion of type IOPMDriverAssertionID *
383 IOReturn
releasePMAssertion(IOPMDriverAssertionID releaseAssertion
);
385 /*! @function restartWithStackshot
386 @abstract Take a stackshot of the system and restart the system.
387 @result Return kIOReturnSuccess if it work, kIOReturnError if the service is not available.
389 IOReturn
restartWithStackshot();
392 virtual IOReturn
changePowerStateTo( unsigned long ordinal
) APPLE_KEXT_COMPATIBILITY_OVERRIDE
;
393 virtual IOReturn
changePowerStateToPriv( unsigned long ordinal
);
394 virtual IOReturn
requestPowerDomainState( IOPMPowerFlags
, IOPowerConnection
*, unsigned long ) APPLE_KEXT_OVERRIDE
;
395 virtual void powerChangeDone( unsigned long ) APPLE_KEXT_OVERRIDE
;
396 virtual bool tellChangeDown( unsigned long ) APPLE_KEXT_OVERRIDE
;
397 virtual bool askChangeDown( unsigned long ) APPLE_KEXT_OVERRIDE
;
398 virtual void tellChangeUp( unsigned long ) APPLE_KEXT_OVERRIDE
;
399 virtual void tellNoChangeDown( unsigned long ) APPLE_KEXT_OVERRIDE
;
400 virtual IOReturn
configureReport(IOReportChannelList
*channels
,
401 IOReportConfigureAction action
,
403 void *destination
) APPLE_KEXT_OVERRIDE
;
404 virtual IOReturn
updateReport(IOReportChannelList
*channels
,
405 IOReportUpdateAction action
,
407 void *destination
) APPLE_KEXT_OVERRIDE
;
409 void configureReportGated(uint64_t channel_id
,
412 IOReturn
updateReportGated(uint64_t ch_id
,
414 IOBufferMemoryDescriptor
*dest
);
416 #ifdef XNU_KERNEL_PRIVATE
417 /* Root Domain internals */
419 void tagPowerPlaneService(
421 IOPMActions
* actions
);
423 void overrideOurPowerChange(
425 IOPMActions
* actions
,
426 IOPMPowerStateIndex
* inOutPowerState
,
427 IOPMPowerChangeFlags
* inOutChangeFlags
,
428 IOPMRequestTag requestTag
);
430 void handleOurPowerChangeStart(
432 IOPMActions
* actions
,
433 IOPMPowerStateIndex powerState
,
434 IOPMPowerChangeFlags
* inOutChangeFlags
,
435 IOPMRequestTag requestTag
);
437 void handleOurPowerChangeDone(
439 IOPMActions
* actions
,
440 IOPMPowerStateIndex powerState
,
441 IOPMPowerChangeFlags changeFlags
,
442 IOPMRequestTag requestTag
);
444 void overridePowerChangeForUIService(
446 IOPMActions
* actions
,
447 IOPMPowerStateIndex
* inOutPowerState
,
448 IOPMPowerChangeFlags
* inOutChangeFlags
);
450 void handleActivityTickleForDisplayWrangler(
452 IOPMActions
* actions
);
454 void handleUpdatePowerClientForDisplayWrangler(
456 IOPMActions
* actions
,
457 const OSSymbol
* powerClient
,
458 IOPMPowerStateIndex oldPowerState
,
459 IOPMPowerStateIndex newPowerState
);
461 bool shouldDelayChildNotification(
462 IOService
* service
);
464 void handlePowerChangeStartForPCIDevice(
466 IOPMActions
* actions
,
467 IOPMPowerStateIndex powerState
,
468 IOPMPowerChangeFlags
* inOutChangeFlags
);
470 void handlePowerChangeDoneForPCIDevice(
472 IOPMActions
* actions
,
473 IOPMPowerStateIndex powerState
,
474 IOPMPowerChangeFlags changeFlags
);
476 void askChangeDownDone(
477 IOPMPowerChangeFlags
* inOutChangeFlags
,
480 void handlePublishSleepWakeUUID(
483 void handleQueueSleepWakeUUID(
486 void handleDisplayPowerOn( );
488 void willNotifyPowerChildren( IOPMPowerStateIndex newPowerState
);
490 IOReturn
setMaintenanceWakeCalendar(
491 const IOPMCalendarStruct
* calendar
);
493 IOReturn
getSystemSleepType( uint32_t * sleepType
);
495 // Handle callbacks from IOService::systemWillShutdown()
496 void acknowledgeSystemWillShutdown( IOService
* from
);
498 // Handle platform halt and restart notifications
499 void handlePlatformHaltRestart( UInt32 pe_type
);
501 IOReturn
shutdownSystem( void );
502 IOReturn
restartSystem( void );
503 void handleSleepTimerExpiration( void );
505 bool activitySinceSleep(void);
506 bool abortHibernation(void);
507 void updateConsoleUsers(void);
509 IOReturn
joinAggressiveness( IOService
* service
);
510 void handleAggressivesRequests( void );
512 void kdebugTrace(uint32_t event
, uint64_t regId
,
513 uintptr_t param1
, uintptr_t param2
, uintptr_t param3
= 0);
514 void tracePoint( uint8_t point
);
515 void traceDetail(uint32_t msgType
, uint32_t msgIndex
, uintptr_t handler
);
517 bool systemMessageFilter(
518 void * object
, void * arg1
, void * arg2
, void * arg3
);
520 bool updatePreventIdleSleepList(
521 IOService
* service
, bool addNotRemove
);
522 void updatePreventSystemSleepList(
523 IOService
* service
, bool addNotRemove
);
525 void publishPMSetting(
526 const OSSymbol
* feature
, uint32_t where
, uint32_t * featureID
);
528 void pmStatsRecordEvent(
530 AbsoluteTime timestamp
);
532 void pmStatsRecordApplicationResponse(
533 const OSSymbol
*response
,
539 IOPMPowerStateIndex ps
=0);
541 void copyWakeReasonString( char * outBuf
, size_t bufSize
);
544 bool getHibernateSettings(
545 uint32_t * hibernateMode
,
546 uint32_t * hibernateFreeRatio
,
547 uint32_t * hibernateFreeTime
);
549 void takeStackshot(bool restart
, bool isOSXWatchdog
, bool isSpinDump
);
550 void sleepWakeDebugTrig(bool restart
);
551 void sleepWakeDebugEnableWdog();
552 bool sleepWakeDebugIsWdogEnabled();
553 static void saveTimeoutAppStackShot(void *p0
, void *p1
);
554 void sleepWakeDebugSaveSpinDumpFile();
555 void swdDebugSetup();
556 void swdDebugTeardown();
559 friend class PMSettingObject
;
560 friend class RootDomainUserClient
;
561 friend class PMAssertionsTracker
;
563 static IOReturn
sysPowerDownHandler( void * target
, void * refCon
,
564 UInt32 messageType
, IOService
* service
,
565 void * messageArgument
, vm_size_t argSize
);
567 static IOReturn
displayWranglerNotification( void * target
, void * refCon
,
568 UInt32 messageType
, IOService
* service
,
569 void * messageArgument
, vm_size_t argSize
);
571 static IOReturn
rootBusyStateChangeHandler( void * target
, void * refCon
,
572 UInt32 messageType
, IOService
* service
,
573 void * messageArgument
, vm_size_t argSize
);
575 static bool displayWranglerMatchPublished( void * target
, void * refCon
,
576 IOService
* newService
,
577 IONotifier
* notifier
);
579 static bool IONVRAMMatchPublished( void * target
, void * refCon
,
580 IOService
* newService
,
581 IONotifier
* notifier
);
583 static bool batteryPublished( void * target
, void * refCon
,
584 IOService
* resourceService
,
585 IONotifier
* notifier
);
587 void initializeBootSessionUUID( void );
589 void fullWakeDelayedWork( void );
591 IOService
* wrangler
;
592 OSDictionary
* wranglerIdleSettings
;
594 IOLock
*featuresDictLock
; // guards supportedFeatures
595 IOLock
*wakeEventLock
;
596 IOPMPowerStateQueue
*pmPowerStateQueue
;
598 OSArray
*allowedPMSettings
;
599 OSArray
*noPublishPMSettings
;
600 PMTraceWorker
*pmTracer
;
601 PMAssertionsTracker
*pmAssertions
;
603 // Settings controller info
604 IOLock
*settingsCtrlLock
;
605 OSDictionary
*settingsCallbacks
;
606 OSDictionary
*fPMSettingsDict
;
608 IONotifier
*_batteryPublishNotifier
;
609 IONotifier
*_displayWranglerNotifier
;
612 const OSSymbol
*_statsNameKey
;
613 const OSSymbol
*_statsPIDKey
;
614 const OSSymbol
*_statsTimeMSKey
;
615 const OSSymbol
*_statsResponseTypeKey
;
616 const OSSymbol
*_statsMessageTypeKey
;
617 const OSSymbol
*_statsPowerCapsKey
;
619 uint32_t darkWakeCnt
;
620 uint32_t displayWakeCnt
;
622 OSString
*queuedSleepWakeUUIDString
;
623 OSArray
*pmStatsAppResponses
;
624 IOLock
*pmStatsLock
; // guards pmStatsAppResponses
626 void *sleepDelaysReport
; // report to track time taken to go to sleep
627 uint32_t sleepDelaysClientCnt
; // Number of interested clients in sleepDelaysReport
628 uint64_t ts_sleepStart
;
629 uint64_t wake2DarkwakeDelay
; // Time taken to change from full wake -> Dark wake
632 void *assertOnWakeReport
; // report to track time spent without any assertions held after wake
633 uint32_t assertOnWakeClientCnt
; // Number of clients interested in assertOnWakeReport
634 clock_sec_t assertOnWakeSecs
; // Num of secs after wake for first assertion
638 // Pref: idle time before idle sleep
639 bool idleSleepEnabled
;
640 unsigned long sleepSlider
;
641 unsigned long idleSeconds
;
642 uint64_t autoWakeStart
;
643 uint64_t autoWakeEnd
;
645 // Difference between sleepSlider and longestNonSleepSlider
646 unsigned long extraSleepDelay
;
648 // Used to wait between say display idle and system idle
649 thread_call_t extraSleepTimer
;
650 thread_call_t diskSyncCalloutEntry
;
651 thread_call_t fullWakeThreadCall
;
652 thread_call_t swdDebugSetupEntry
;
653 thread_call_t swdDebugTearDownEntry
;
654 thread_call_t updateConsoleUsersEntry
;
656 // Track system capabilities.
657 uint32_t _desiredCapability
;
658 uint32_t _currentCapability
;
659 uint32_t _pendingCapability
;
660 uint32_t _highestCapability
;
661 OSSet
* _joinedCapabilityClients
;
662 uint32_t _systemStateGeneration
;
664 // Type of clients that can receive system messages.
666 kSystemMessageClientPowerd
= 0x01,
667 kSystemMessageClientLegacyApp
= 0x02,
668 kSystemMessageClientKernel
= 0x04,
669 kSystemMessageClientAll
= 0x07
671 uint32_t _systemMessageClientMask
;
673 // Power state and capability change transitions.
675 kSystemTransitionNone
= 0,
676 kSystemTransitionSleep
= 1,
677 kSystemTransitionWake
= 2,
678 kSystemTransitionCapability
= 3,
679 kSystemTransitionNewCapClient
= 4
680 } _systemTransitionType
;
682 unsigned int systemBooting
:1;
683 unsigned int systemShutdown
:1;
684 unsigned int systemDarkWake
:1;
685 unsigned int clamshellExists
:1;
686 unsigned int clamshellClosed
:1;
687 unsigned int clamshellDisabled
:1;
688 unsigned int desktopMode
:1;
689 unsigned int acAdaptorConnected
:1;
691 unsigned int clamshellSleepDisabled
:1;
692 unsigned int idleSleepTimerPending
:1;
693 unsigned int userDisabledAllSleep
:1;
694 unsigned int ignoreTellChangeDown
:1;
695 unsigned int wranglerAsleep
:1;
696 unsigned int wranglerTickled
:1;
697 unsigned int _preventUserActive
:1;
698 unsigned int graphicsSuppressed
:1;
700 unsigned int capabilityLoss
:1;
701 unsigned int pciCantSleepFlag
:1;
702 unsigned int pciCantSleepValid
:1;
703 unsigned int logGraphicsClamp
:1;
704 unsigned int darkWakeToSleepASAP
:1;
705 unsigned int darkWakeMaintenance
:1;
706 unsigned int darkWakeSleepService
:1;
707 unsigned int darkWakePostTickle
:1;
709 unsigned int sleepTimerMaintenance
:1;
710 unsigned int sleepToStandby
:1;
711 unsigned int lowBatteryCondition
:1;
712 unsigned int hibernateDisabled
:1;
713 unsigned int hibernateRetry
:1;
714 unsigned int wranglerTickleLatched
:1;
715 unsigned int userIsActive
:1;
716 unsigned int userWasActive
:1;
718 unsigned int displayIdleForDemandSleep
:1;
719 unsigned int darkWakeHibernateError
:1;
720 unsigned int thermalWarningState
:1;
721 unsigned int toldPowerdCapWillChange
:1;
722 unsigned int displayPowerOnRequested
:1;
724 uint8_t tasksSuspended
;
725 uint32_t hibernateMode
;
726 AbsoluteTime userActivityTime
;
727 AbsoluteTime userActivityTime_prev
;
728 uint32_t userActivityCount
;
729 uint32_t userActivityAtSleep
;
730 uint32_t lastSleepReason
;
731 uint32_t fullToDarkReason
;
732 uint32_t hibernateAborted
;
733 uint8_t standbyNixed
;
736 enum FullWakeReason
{
737 kFullWakeReasonNone
= 0,
738 kFullWakeReasonLocalUser
= 1,
739 kFullWakeReasonDisplayOn
= 2,
740 fFullWakeReasonDisplayOnAndLocalUser
= 3
742 uint32_t fullWakeReason
;
744 // Info for communicating system state changes to PMCPU
745 int32_t idxPMCPUClamshell
;
746 int32_t idxPMCPULimitedPower
;
748 IOOptionBits platformSleepSupport
;
749 uint32_t _debugWakeSeconds
;
750 uint32_t _lastDebugWakeSeconds
;
752 queue_head_t aggressivesQueue
;
753 thread_call_t aggressivesThreadCall
;
754 OSData
* aggressivesData
;
756 AbsoluteTime userBecameInactiveTime
;
758 // PCI top-level PM trace
759 IOService
* pciHostBridgeDevice
;
760 IOService
* pciHostBridgeDriver
;
762 IONotifier
* systemCapabilityNotifier
;
767 } PMNotifySuspendedStruct
;
769 uint32_t pmSuspendedCapacity
;
770 uint32_t pmSuspendedSize
;
771 PMNotifySuspendedStruct
*pmSuspendedPIDS
;
773 OSSet
* preventIdleSleepList
;
774 OSSet
* preventSystemSleepList
;
776 UInt32 _scheduledAlarms
;
777 UInt32 _userScheduledAlarm
;
780 clock_sec_t _standbyTimerResetSeconds
;
782 volatile uint32_t swd_lock
; /* Lock to access swd_buffer & and its header */
783 void * swd_buffer
; /* Memory allocated for dumping sleep/wake logs */
784 uint32_t swd_flags
; /* Flags defined in IOPMPrivate.h */
785 uint8_t swd_DebugImageSetup
;
786 void * swd_spindump_buffer
;
788 IOBufferMemoryDescriptor
*swd_memDesc
;
790 IOMemoryMap
* swd_logBufMap
; /* Memory with sleep/wake logs from previous boot */
792 // Wake Event Reporting
793 OSArray
* _systemWakeEventsArray
;
794 bool _acceptSystemWakeEvents
;
796 int findSuspendedPID(uint32_t pid
, uint32_t *outRefCount
);
798 // IOPMrootDomain internal sleep call
799 IOReturn
privateSleepSystem( uint32_t sleepReason
);
800 void reportUserInput( void );
801 void setDisableClamShellSleep( bool );
802 bool checkSystemSleepAllowed( IOOptionBits options
,
803 uint32_t sleepReason
);
804 bool checkSystemSleepEnabled( void );
805 bool checkSystemCanSleep( uint32_t sleepReason
);
806 bool checkSystemCanSustainFullWake( void );
808 void adjustPowerState( bool sleepASAP
= false );
809 void setQuickSpinDownTimeout( void );
810 void restoreUserSpinDownTimeout( void );
812 bool shouldSleepOnClamshellClosed(void );
813 void sendClientClamshellNotification( void );
815 // Inform PMCPU of changes to state like lid, AC vs. battery
816 void informCPUStateChange( uint32_t type
, uint32_t value
);
818 void dispatchPowerEvent( uint32_t event
, void * arg0
, uint64_t arg1
);
819 void handlePowerNotification( UInt32 msg
);
821 IOReturn
setPMSetting(const OSSymbol
*, OSObject
*);
823 void startIdleSleepTimer( uint32_t inSeconds
);
824 void cancelIdleSleepTimer( void );
825 uint32_t getTimeToIdleSleep( void );
827 IOReturn
setAggressiveness(
830 IOOptionBits options
);
832 void synchronizeAggressives(
833 queue_head_t
* services
,
834 const AggressivesRecord
* array
,
837 void broadcastAggressives(
838 const AggressivesRecord
* array
,
841 IOReturn
setPMAssertionUserLevels(IOPMDriverAssertionType
);
843 void publishSleepWakeUUID( bool shouldPublish
);
845 void evaluatePolicy( int stimulus
, uint32_t arg
= 0 );
846 void requestFullWake( FullWakeReason reason
);
847 void willEnterFullWake( void );
849 void evaluateAssertions(IOPMDriverAssertionType newAssertions
,
850 IOPMDriverAssertionType oldAssertions
);
852 void deregisterPMSettingObject( PMSettingObject
* pmso
);
854 uint32_t checkForValidDebugData(const char *fname
, vfs_context_t
*ctx
,
855 void *tmpBuf
, struct vnode
**vp
);
856 void sleepWakeDebugMemAlloc( );
857 void sleepWakeDebugSpinDumpMemAlloc( );
858 void sleepWakeDebugDumpFromMem(IOMemoryMap
*logBufMap
);
859 void sleepWakeDebugDumpFromFile( );
860 IOMemoryMap
*sleepWakeDebugRetrieve();
861 errno_t
sleepWakeDebugSaveFile(const char *name
, char *buf
, int len
);
862 errno_t
sleepWakeDebugCopyFile( struct vnode
*srcVp
,
863 vfs_context_t srcCtx
,
864 char *tmpBuf
, uint64_t tmpBufSize
,
866 const char *dstFname
,
872 bool getSleepOption( const char * key
, uint32_t * option
);
873 bool evaluateSystemSleepPolicy( IOPMSystemSleepParameters
* p
,
874 int phase
, uint32_t * hibMode
);
875 void evaluateSystemSleepPolicyEarly( void );
876 void evaluateSystemSleepPolicyFinal( void );
877 #endif /* HIBERNATION */
879 bool latchDisplayWranglerTickle( bool latch
);
880 void setDisplayPowerOn( uint32_t options
);
882 void acceptSystemWakeEvents( bool accept
);
883 void systemDidNotSleep( void );
884 void preventTransitionToUserActive( bool prevent
);
885 void setThermalState(OSObject
*value
);
886 void copySleepPreventersList(OSArray
**idleSleepList
, OSArray
**systemSleepList
);
887 #endif /* XNU_KERNEL_PRIVATE */
890 #ifdef XNU_KERNEL_PRIVATE
891 class IORootParent
: public IOService
893 OSDeclareFinalStructors(IORootParent
)
896 static void initialize( void );
897 virtual OSObject
* copyProperty( const char * aKey
) const APPLE_KEXT_OVERRIDE
;
898 bool start( IOService
* nub
) APPLE_KEXT_OVERRIDE
;
899 void shutDownSystem( void );
900 void restartSystem( void );
901 void sleepSystem( void );
902 void dozeSystem( void );
903 void sleepToDoze( void );
904 void wakeSystem( void );
906 #endif /* XNU_KERNEL_PRIVATE */
908 #endif /* _IOKIT_ROOTDOMAIN_H */