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();
560 bool checkShutdownTimeout();
561 void panicWithShutdownLog(uint32_t timeoutInMs
);
564 friend class PMSettingObject
;
565 friend class RootDomainUserClient
;
566 friend class PMAssertionsTracker
;
568 static IOReturn
sysPowerDownHandler( void * target
, void * refCon
,
569 UInt32 messageType
, IOService
* service
,
570 void * messageArgument
, vm_size_t argSize
);
572 static IOReturn
displayWranglerNotification( void * target
, void * refCon
,
573 UInt32 messageType
, IOService
* service
,
574 void * messageArgument
, vm_size_t argSize
);
576 static IOReturn
rootBusyStateChangeHandler( void * target
, void * refCon
,
577 UInt32 messageType
, IOService
* service
,
578 void * messageArgument
, vm_size_t argSize
);
580 static bool displayWranglerMatchPublished( void * target
, void * refCon
,
581 IOService
* newService
,
582 IONotifier
* notifier
);
584 static bool IONVRAMMatchPublished( void * target
, void * refCon
,
585 IOService
* newService
,
586 IONotifier
* notifier
);
588 static bool batteryPublished( void * target
, void * refCon
,
589 IOService
* resourceService
,
590 IONotifier
* notifier
);
592 void initializeBootSessionUUID( void );
594 void fullWakeDelayedWork( void );
596 IOService
* wrangler
;
597 OSDictionary
* wranglerIdleSettings
;
599 IOLock
*featuresDictLock
; // guards supportedFeatures
600 IOLock
*wakeEventLock
;
601 IOPMPowerStateQueue
*pmPowerStateQueue
;
603 OSArray
*allowedPMSettings
;
604 OSArray
*noPublishPMSettings
;
605 PMTraceWorker
*pmTracer
;
606 PMAssertionsTracker
*pmAssertions
;
608 // Settings controller info
609 IOLock
*settingsCtrlLock
;
610 OSDictionary
*settingsCallbacks
;
611 OSDictionary
*fPMSettingsDict
;
613 IONotifier
*_batteryPublishNotifier
;
614 IONotifier
*_displayWranglerNotifier
;
617 const OSSymbol
*_statsNameKey
;
618 const OSSymbol
*_statsPIDKey
;
619 const OSSymbol
*_statsTimeMSKey
;
620 const OSSymbol
*_statsResponseTypeKey
;
621 const OSSymbol
*_statsMessageTypeKey
;
622 const OSSymbol
*_statsPowerCapsKey
;
624 uint32_t darkWakeCnt
;
625 uint32_t displayWakeCnt
;
627 OSString
*queuedSleepWakeUUIDString
;
628 OSArray
*pmStatsAppResponses
;
629 IOLock
*pmStatsLock
; // guards pmStatsAppResponses
631 void *sleepDelaysReport
; // report to track time taken to go to sleep
632 uint32_t sleepDelaysClientCnt
; // Number of interested clients in sleepDelaysReport
633 uint64_t ts_sleepStart
;
634 uint64_t wake2DarkwakeDelay
; // Time taken to change from full wake -> Dark wake
637 void *assertOnWakeReport
; // report to track time spent without any assertions held after wake
638 uint32_t assertOnWakeClientCnt
; // Number of clients interested in assertOnWakeReport
639 clock_sec_t assertOnWakeSecs
; // Num of secs after wake for first assertion
643 // Pref: idle time before idle sleep
644 bool idleSleepEnabled
;
645 unsigned long sleepSlider
;
646 unsigned long idleSeconds
;
647 uint64_t autoWakeStart
;
648 uint64_t autoWakeEnd
;
650 // Difference between sleepSlider and longestNonSleepSlider
651 unsigned long extraSleepDelay
;
653 // Used to wait between say display idle and system idle
654 thread_call_t extraSleepTimer
;
655 thread_call_t diskSyncCalloutEntry
;
656 thread_call_t fullWakeThreadCall
;
657 thread_call_t swdDebugSetupEntry
;
658 thread_call_t swdDebugTearDownEntry
;
659 thread_call_t updateConsoleUsersEntry
;
661 // Track system capabilities.
662 uint32_t _desiredCapability
;
663 uint32_t _currentCapability
;
664 uint32_t _pendingCapability
;
665 uint32_t _highestCapability
;
666 OSSet
* _joinedCapabilityClients
;
667 uint32_t _systemStateGeneration
;
669 // Type of clients that can receive system messages.
671 kSystemMessageClientPowerd
= 0x01,
672 kSystemMessageClientLegacyApp
= 0x02,
673 kSystemMessageClientKernel
= 0x04,
674 kSystemMessageClientAll
= 0x07
676 uint32_t _systemMessageClientMask
;
678 // Power state and capability change transitions.
680 kSystemTransitionNone
= 0,
681 kSystemTransitionSleep
= 1,
682 kSystemTransitionWake
= 2,
683 kSystemTransitionCapability
= 3,
684 kSystemTransitionNewCapClient
= 4
685 } _systemTransitionType
;
687 unsigned int systemBooting
:1;
688 unsigned int systemShutdown
:1;
689 unsigned int systemDarkWake
:1;
690 unsigned int clamshellExists
:1;
691 unsigned int clamshellClosed
:1;
692 unsigned int clamshellDisabled
:1;
693 unsigned int desktopMode
:1;
694 unsigned int acAdaptorConnected
:1;
696 unsigned int clamshellSleepDisabled
:1;
697 unsigned int idleSleepTimerPending
:1;
698 unsigned int userDisabledAllSleep
:1;
699 unsigned int ignoreTellChangeDown
:1;
700 unsigned int wranglerAsleep
:1;
701 unsigned int wranglerTickled
:1;
702 unsigned int _preventUserActive
:1;
703 unsigned int graphicsSuppressed
:1;
705 unsigned int capabilityLoss
:1;
706 unsigned int pciCantSleepFlag
:1;
707 unsigned int pciCantSleepValid
:1;
708 unsigned int logGraphicsClamp
:1;
709 unsigned int darkWakeToSleepASAP
:1;
710 unsigned int darkWakeMaintenance
:1;
711 unsigned int darkWakeSleepService
:1;
712 unsigned int darkWakePostTickle
:1;
714 unsigned int sleepTimerMaintenance
:1;
715 unsigned int sleepToStandby
:1;
716 unsigned int lowBatteryCondition
:1;
717 unsigned int hibernateDisabled
:1;
718 unsigned int hibernateRetry
:1;
719 unsigned int wranglerTickleLatched
:1;
720 unsigned int userIsActive
:1;
721 unsigned int userWasActive
:1;
723 unsigned int displayIdleForDemandSleep
:1;
724 unsigned int darkWakeHibernateError
:1;
725 unsigned int thermalWarningState
:1;
726 unsigned int toldPowerdCapWillChange
:1;
727 unsigned int displayPowerOnRequested
:1;
729 uint8_t tasksSuspended
;
730 uint32_t hibernateMode
;
731 AbsoluteTime userActivityTime
;
732 AbsoluteTime userActivityTime_prev
;
733 uint32_t userActivityCount
;
734 uint32_t userActivityAtSleep
;
735 uint32_t lastSleepReason
;
736 uint32_t fullToDarkReason
;
737 uint32_t hibernateAborted
;
738 uint8_t standbyNixed
;
741 enum FullWakeReason
{
742 kFullWakeReasonNone
= 0,
743 kFullWakeReasonLocalUser
= 1,
744 kFullWakeReasonDisplayOn
= 2,
745 fFullWakeReasonDisplayOnAndLocalUser
= 3
747 uint32_t fullWakeReason
;
749 // Info for communicating system state changes to PMCPU
750 int32_t idxPMCPUClamshell
;
751 int32_t idxPMCPULimitedPower
;
753 IOOptionBits platformSleepSupport
;
754 uint32_t _debugWakeSeconds
;
755 uint32_t _lastDebugWakeSeconds
;
757 queue_head_t aggressivesQueue
;
758 thread_call_t aggressivesThreadCall
;
759 OSData
* aggressivesData
;
761 AbsoluteTime userBecameInactiveTime
;
763 // PCI top-level PM trace
764 IOService
* pciHostBridgeDevice
;
765 IOService
* pciHostBridgeDriver
;
767 IONotifier
* systemCapabilityNotifier
;
772 } PMNotifySuspendedStruct
;
774 uint32_t pmSuspendedCapacity
;
775 uint32_t pmSuspendedSize
;
776 PMNotifySuspendedStruct
*pmSuspendedPIDS
;
778 OSSet
* preventIdleSleepList
;
779 OSSet
* preventSystemSleepList
;
781 UInt32 _scheduledAlarms
;
782 UInt32 _userScheduledAlarm
;
785 clock_sec_t _standbyTimerResetSeconds
;
787 volatile uint32_t swd_lock
; /* Lock to access swd_buffer & and its header */
788 void * swd_buffer
; /* Memory allocated for dumping sleep/wake logs */
789 uint32_t swd_flags
; /* Flags defined in IOPMPrivate.h */
790 uint8_t swd_DebugImageSetup
;
791 void * swd_spindump_buffer
;
793 IOBufferMemoryDescriptor
*swd_memDesc
;
795 IOMemoryMap
* swd_logBufMap
; /* Memory with sleep/wake logs from previous boot */
797 // Wake Event Reporting
798 OSArray
* _systemWakeEventsArray
;
799 bool _acceptSystemWakeEvents
;
801 int findSuspendedPID(uint32_t pid
, uint32_t *outRefCount
);
803 // IOPMrootDomain internal sleep call
804 IOReturn
privateSleepSystem( uint32_t sleepReason
);
805 void reportUserInput( void );
806 void setDisableClamShellSleep( bool );
807 bool checkSystemSleepAllowed( IOOptionBits options
,
808 uint32_t sleepReason
);
809 bool checkSystemSleepEnabled( void );
810 bool checkSystemCanSleep( uint32_t sleepReason
);
811 bool checkSystemCanSustainFullWake( void );
813 void adjustPowerState( bool sleepASAP
= false );
814 void setQuickSpinDownTimeout( void );
815 void restoreUserSpinDownTimeout( void );
817 bool shouldSleepOnClamshellClosed(void );
818 void sendClientClamshellNotification( void );
820 // Inform PMCPU of changes to state like lid, AC vs. battery
821 void informCPUStateChange( uint32_t type
, uint32_t value
);
823 void dispatchPowerEvent( uint32_t event
, void * arg0
, uint64_t arg1
);
824 void handlePowerNotification( UInt32 msg
);
826 IOReturn
setPMSetting(const OSSymbol
*, OSObject
*);
828 void startIdleSleepTimer( uint32_t inSeconds
);
829 void cancelIdleSleepTimer( void );
830 uint32_t getTimeToIdleSleep( void );
832 IOReturn
setAggressiveness(
835 IOOptionBits options
);
837 void synchronizeAggressives(
838 queue_head_t
* services
,
839 const AggressivesRecord
* array
,
842 void broadcastAggressives(
843 const AggressivesRecord
* array
,
846 IOReturn
setPMAssertionUserLevels(IOPMDriverAssertionType
);
848 void publishSleepWakeUUID( bool shouldPublish
);
850 void evaluatePolicy( int stimulus
, uint32_t arg
= 0 );
851 void requestFullWake( FullWakeReason reason
);
852 void willEnterFullWake( void );
854 void evaluateAssertions(IOPMDriverAssertionType newAssertions
,
855 IOPMDriverAssertionType oldAssertions
);
857 void deregisterPMSettingObject( PMSettingObject
* pmso
);
859 uint32_t checkForValidDebugData(const char *fname
, vfs_context_t
*ctx
,
860 void *tmpBuf
, struct vnode
**vp
);
861 void sleepWakeDebugMemAlloc( );
862 void sleepWakeDebugSpinDumpMemAlloc( );
863 void sleepWakeDebugDumpFromMem(IOMemoryMap
*logBufMap
);
864 void sleepWakeDebugDumpFromFile( );
865 IOMemoryMap
*sleepWakeDebugRetrieve();
866 errno_t
sleepWakeDebugSaveFile(const char *name
, char *buf
, int len
);
867 errno_t
sleepWakeDebugCopyFile( struct vnode
*srcVp
,
868 vfs_context_t srcCtx
,
869 char *tmpBuf
, uint64_t tmpBufSize
,
871 const char *dstFname
,
877 bool getSleepOption( const char * key
, uint32_t * option
);
878 bool evaluateSystemSleepPolicy( IOPMSystemSleepParameters
* p
,
879 int phase
, uint32_t * hibMode
);
880 void evaluateSystemSleepPolicyEarly( void );
881 void evaluateSystemSleepPolicyFinal( void );
882 #endif /* HIBERNATION */
884 bool latchDisplayWranglerTickle( bool latch
);
885 void setDisplayPowerOn( uint32_t options
);
887 void acceptSystemWakeEvents( bool accept
);
888 void systemDidNotSleep( void );
889 void preventTransitionToUserActive( bool prevent
);
890 void setThermalState(OSObject
*value
);
891 void copySleepPreventersList(OSArray
**idleSleepList
, OSArray
**systemSleepList
);
892 #endif /* XNU_KERNEL_PRIVATE */
895 #ifdef XNU_KERNEL_PRIVATE
896 class IORootParent
: public IOService
898 OSDeclareFinalStructors(IORootParent
)
901 static void initialize( void );
902 virtual OSObject
* copyProperty( const char * aKey
) const APPLE_KEXT_OVERRIDE
;
903 bool start( IOService
* nub
) APPLE_KEXT_OVERRIDE
;
904 void shutDownSystem( void );
905 void restartSystem( void );
906 void sleepSystem( void );
907 void dozeSystem( void );
908 void sleepToDoze( void );
909 void wakeSystem( void );
911 #endif /* XNU_KERNEL_PRIVATE */
913 #endif /* _IOKIT_ROOTDOMAIN_H */