2 * Copyright (c) 1998-2019 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
38 #include <IOKit/pwr_mgt/IOPMPrivate.h>
40 struct AggressivesRecord
;
41 struct IOPMMessageFilterContext
;
43 struct IOPMSystemSleepParameters
;
44 class PMSettingObject
;
46 class IOPMPowerStateQueue
;
47 class RootDomainUserClient
;
48 class PMAssertionsTracker
;
49 class IOTimerEventSource
;
51 #define OBFUSCATE(x) (void *)VM_KERNEL_UNSLIDE_OR_PERM(x)
56 * Types for PM Assertions
57 * For creating, releasing, and getting PM assertion levels.
60 /*! IOPMDriverAssertionType
61 * A bitfield describing a set of assertions. May be used to specify which assertions
62 * to set with <link>IOPMrootDomain::createPMAssertion</link>; or to query which
63 * assertions are set with <link>IOPMrootDomain::releasePMAssertion</link>.
65 typedef uint64_t IOPMDriverAssertionType
;
67 /* IOPMDriverAssertionID
68 * Drivers may create PM assertions to request system behavior (keep the system awake,
69 * or keep the display awake). When a driver creates an assertion via
70 * <link>IOPMrootDomain::createPMAssertion</link>, PM returns a handle to
71 * the assertion of type IOPMDriverAssertionID.
73 typedef uint64_t IOPMDriverAssertionID
;
74 #define kIOPMUndefinedDriverAssertionID 0
76 /* IOPMDriverAssertionLevel
77 * Possible values for IOPMDriverAssertionLevel are <link>kIOPMDriverAssertionLevelOff</link>
78 * and <link>kIOPMDriverAssertionLevelOn</link>
80 typedef uint32_t IOPMDriverAssertionLevel
;
81 #define kIOPMDriverAssertionLevelOff 0
82 #define kIOPMDriverAssertionLevelOn 255
85 * Flags for get/setSleepSupported()
88 kRootDomainSleepNotSupported
= 0x00000000,
89 kRootDomainSleepSupported
= 0x00000001,
90 kFrameBufferDeepSleepSupported
= 0x00000002,
91 kPCICantSleep
= 0x00000004
95 * IOPMrootDomain registry property keys
97 #define kRootDomainSupportedFeatures "Supported Features"
98 #define kRootDomainSleepReasonKey "Last Sleep Reason"
99 #define kRootDomainSleepOptionsKey "Last Sleep Options"
100 #define kIOPMRootDomainWakeReasonKey "Wake Reason"
101 #define kIOPMRootDomainWakeTypeKey "Wake Type"
102 #define kIOPMRootDomainPowerStatusKey "Power Status"
105 * Possible sleep reasons found under kRootDomainSleepReasonsKey
107 #define kIOPMClamshellSleepKey "Clamshell Sleep"
108 #define kIOPMPowerButtonSleepKey "Power Button Sleep"
109 #define kIOPMSoftwareSleepKey "Software Sleep"
110 #define kIOPMOSSwitchHibernationKey "OS Switch Sleep"
111 #define kIOPMIdleSleepKey "Idle Sleep"
112 #define kIOPMLowPowerSleepKey "Low Power Sleep"
113 #define kIOPMThermalEmergencySleepKey "Thermal Emergency Sleep"
114 #define kIOPMMaintenanceSleepKey "Maintenance Sleep"
117 * String constants for communication with PM CPU
119 #define kIOPMRootDomainLidCloseCString "LidClose"
120 #define kIOPMRootDomainBatPowerCString "BatPower"
123 * Supported Feature bitfields for IOPMrootDomain::publishFeature()
126 kIOPMSupportedOnAC
= (1 << 0),
127 kIOPMSupportedOnBatt
= (1 << 1),
128 kIOPMSupportedOnUPS
= (1 << 2)
131 typedef IOReturn (*IOPMSettingControllerCallback
)
132 (OSObject
*target
, const OSSymbol
*type
,
133 OSObject
*val
, uintptr_t refcon
);
136 IONotifier
* registerSleepWakeInterest(
137 IOServiceInterestHandler
, void *, void * = NULL
);
139 IONotifier
* registerPrioritySleepWakeInterest(
140 IOServiceInterestHandler handler
,
141 void * self
, void * ref
= NULL
);
143 IOReturn
acknowledgeSleepWakeNotification(void * );
145 IOReturn
vetoSleepWakeNotification(void * PMrefcon
);
148 #define IOPM_ROOTDOMAIN_REV 2
150 class IOPMrootDomain
: public IOService
152 OSDeclareFinalStructors(IOPMrootDomain
);
155 static IOPMrootDomain
* construct( void );
157 virtual bool start( IOService
* provider
) APPLE_KEXT_OVERRIDE
;
158 virtual IOReturn
setAggressiveness( unsigned long, unsigned long ) APPLE_KEXT_OVERRIDE
;
159 virtual IOReturn
getAggressiveness( unsigned long, unsigned long * ) APPLE_KEXT_OVERRIDE
;
161 virtual IOReturn
sleepSystem( void );
162 IOReturn
sleepSystemOptions( OSDictionary
*options
);
164 virtual IOReturn
setProperties( OSObject
* ) APPLE_KEXT_OVERRIDE
;
165 virtual bool serializeProperties( OSSerialize
* s
) const APPLE_KEXT_OVERRIDE
;
166 virtual OSObject
* copyProperty( const char * aKey
) const APPLE_KEXT_OVERRIDE
;
168 /*! @function systemPowerEventOccurred
169 * @abstract Other drivers may inform IOPMrootDomain of system PM events
170 * @discussion systemPowerEventOccurred is a richer alternative to receivePowerNotification()
171 * Only Apple-owned kexts should have reason to call systemPowerEventOccurred.
172 * @param event An OSSymbol describing the type of power event.
173 * @param intValue A 32-bit integer value associated with the event.
174 * @result kIOReturnSuccess on success */
176 IOReturn
systemPowerEventOccurred(
177 const OSSymbol
*event
,
180 IOReturn
systemPowerEventOccurred(
181 const OSSymbol
*event
,
184 #ifdef XNU_KERNEL_PRIVATE // Hide doc from public headers
185 /*! @function claimSystemWakeEvent
186 * @abstract Apple-internal SPI to describe system wake events.
187 * @discussion IOKit drivers may call claimSystemWakeEvent() during system wakeup to
188 * provide human readable debug information describing the event(s) that
189 * caused the system to wake.
191 * - Drivers should call claimSystemWakeEvent before completing
192 * their setPowerState() acknowledgement. IOPMrootDomain stops
193 * collecting wake events when driver wake is complete.
195 * - It is only appropriate to claim a wake event when the driver
196 * can positively identify its hardware has generated an event
197 * that can wake the system.
199 * - This call tracks wake events from a non-S0 state (S0i, S3, S4) into S0.
200 * - This call does not track wake events from DarkWake(S0) to FullWake(S0).
203 * (reason = "WiFi.TCPData",
204 * details = "TCPKeepAlive packet arrived from IP 16.2.1.1")
205 * (reason = "WiFi.ScanOffload",
206 * details = "WiFi station 'AppleWiFi' signal dropped below threshold")
207 * (reason = "Enet.LinkToggle",
208 * details = "Ethernet attached")
210 * @param device The device/nub that is associated with the wake event.
212 * @param flags Pass kIOPMWakeEventSource if the device is the source
213 * of the wake event. Pass zero if the device is forwarding or
214 * aggregating wake events from multiple sources, e.g. an USB or
215 * Thunderbolt host controller.
217 * @param reason Caller should pass a human readable C string describing the
218 * wake reason. Please use a string from the list below, or create
219 * your own string matching this format:
235 * Enet.ConflictResolution
243 * @param details Optional details further describing the wake event.
244 * Please pass an OSString defining the event.
247 void claimSystemWakeEvent( IOService
*device
,
250 OSObject
*details
= NULL
);
252 virtual IOReturn
receivePowerNotification( UInt32 msg
);
254 virtual void setSleepSupported( IOOptionBits flags
);
256 virtual IOOptionBits
getSleepSupported( void );
258 void wakeFromDoze( void );
260 // KEXT driver announces support of power management feature
262 void publishFeature( const char *feature
);
264 // KEXT driver announces support of power management feature
265 // And specifies power sources with kIOPMSupportedOn{AC/Batt/UPS} bitfield.
266 // Returns a unique uint32_t identifier for later removing support for this
268 // NULL is acceptable for uniqueFeatureID for kexts without plans to unload.
270 void publishFeature( const char *feature
,
271 uint32_t supportedWhere
,
272 uint32_t *uniqueFeatureID
);
274 // KEXT driver announces removal of a previously published power management
275 // feature. Pass 'uniqueFeatureID' returned from publishFeature()
277 IOReturn
removePublishedFeature( uint32_t removeFeatureID
);
279 /*! @function copyPMSetting
280 * @abstract Copy the current value for a PM setting. Returns an OSNumber or
281 * OSData depending on the setting.
282 * @param whichSetting Name of the desired setting.
283 * @result OSObject value if valid, NULL otherwise. */
285 OSObject
* copyPMSetting( OSSymbol
*whichSetting
);
287 /*! @function registerPMSettingController
288 * @abstract Register for callbacks on changes to certain PM settings.
289 * @param settings NULL terminated array of C strings, each string for a PM
290 * setting that the caller is interested in and wants to get callbacks for.
291 * @param callout C function ptr or member function cast as such.
292 * @param target The target of the callback, usually 'this'
293 * @param refcon Will be passed to caller in callback; for caller's use.
294 * @param handle Caller should keep the OSObject * returned here. If non-NULL,
295 * handle will have a retain count of 1 on return. To deregister, pass to
296 * unregisterPMSettingController()
297 * @result kIOReturnSuccess on success. */
299 IOReturn
registerPMSettingController(
300 const OSSymbol
*settings
[],
301 IOPMSettingControllerCallback callout
,
304 OSObject
**handle
); // out param
306 /*! @function registerPMSettingController
307 * @abstract Register for callbacks on changes to certain PM settings.
308 * @param settings NULL terminated array of C strings, each string for a PM
309 * setting that the caller is interested in and wants to get callbacks for.
310 * @param supportedPowerSources bitfield indicating which power sources these
311 * settings are supported for (kIOPMSupportedOnAC, etc.)
312 * @param callout C function ptr or member function cast as such.
313 * @param target The target of the callback, usually 'this'
314 * @param refcon Will be passed to caller in callback; for caller's use.
315 * @param handle Caller should keep the OSObject * returned here. If non-NULL,
316 * handle will have a retain count of 1 on return. To deregister, pass to
317 * unregisterPMSettingController()
318 * @result kIOReturnSuccess on success. */
320 IOReturn
registerPMSettingController(
321 const OSSymbol
*settings
[],
322 uint32_t supportedPowerSources
,
323 IOPMSettingControllerCallback callout
,
326 OSObject
**handle
); // out param
328 virtual IONotifier
* registerInterest(
329 const OSSymbol
* typeOfInterest
,
330 IOServiceInterestHandler handler
,
331 void * target
, void * ref
= NULL
) APPLE_KEXT_OVERRIDE
;
333 virtual IOReturn
callPlatformFunction(
334 const OSSymbol
*functionName
,
335 bool waitForFunction
,
336 void *param1
, void *param2
,
337 void *param3
, void *param4
) APPLE_KEXT_OVERRIDE
;
339 /*! @function createPMAssertion
340 * @abstract Creates an assertion to influence system power behavior.
341 * @param whichAssertionsBits A bitfield specify the assertion that the caller requests.
342 * @param assertionLevel An integer detailing the initial assertion level, kIOPMDriverAssertionLevelOn
343 * or kIOPMDriverAssertionLevelOff.
344 * @param ownerService A pointer to the caller's IOService class, for tracking.
345 * @param ownerDescription A reverse-DNS string describing the caller's identity and reason.
346 * @result On success, returns a new assertion of type IOPMDriverAssertionID
348 IOPMDriverAssertionID
createPMAssertion(
349 IOPMDriverAssertionType whichAssertionsBits
,
350 IOPMDriverAssertionLevel assertionLevel
,
351 IOService
*ownerService
,
352 const char *ownerDescription
);
354 /* @function setPMAssertionLevel
355 * @abstract Modify the level of a pre-existing assertion.
356 * @discussion Change the value of a PM assertion to influence system behavior,
357 * without undergoing the work required to create or destroy an assertion. Suggested
358 * for clients who will assert and de-assert needs for PM behavior several times over
360 * @param assertionID An assertion ID previously returned by <link>createPMAssertion</link>
361 * @param assertionLevel The new assertion level.
362 * @result kIOReturnSuccess if it worked; kIOReturnNotFound or other IOReturn error on failure.
364 IOReturn
setPMAssertionLevel(IOPMDriverAssertionID assertionID
, IOPMDriverAssertionLevel assertionLevel
);
366 /*! @function getPMAssertionLevel
367 * @absract Returns the active level of the specified assertion(s).
368 * @discussion Returns <link>kIOPMDriverAssertionLevelOff</link> or
369 * <link>kIOPMDriverAssertionLevelOn</link>. If multiple assertions are specified
370 * in the bitfield, only returns <link>kIOPMDriverAssertionLevelOn</link>
371 * if all assertions are active.
372 * @param whichAssertionBits Bits defining the assertion or assertions the caller is interested in
373 * the level of. If in doubt, pass <link>kIOPMDriverAssertionCPUBit</link> as the argument.
374 * @result Returns <link>kIOPMDriverAssertionLevelOff</link> or
375 * <link>kIOPMDriverAssertionLevelOn</link> indicating the specified assertion's levels, if available.
376 * If the assertions aren't supported on this machine, or aren't recognized by the OS, the
377 * result is undefined.
379 IOPMDriverAssertionLevel
getPMAssertionLevel(IOPMDriverAssertionType whichAssertionBits
);
381 /*! @function releasePMAssertion
382 * @abstract Removes an assertion to influence system power behavior.
383 * @result On success, returns a new assertion of type IOPMDriverAssertionID *
385 IOReturn
releasePMAssertion(IOPMDriverAssertionID releaseAssertion
);
387 /*! @function restartWithStackshot
388 * @abstract Take a stackshot of the system and restart the system.
389 * @result Return kIOReturnSuccess if it work, kIOReturnError if the service is not available.
391 IOReturn
restartWithStackshot();
393 IOReturn
setWakeTime(uint64_t wakeContinuousTime
);
396 unsigned long getRUN_STATE(void);
398 virtual IOReturn
changePowerStateTo( unsigned long ordinal
) APPLE_KEXT_COMPATIBILITY_OVERRIDE
;
399 virtual IOReturn
changePowerStateToPriv( unsigned long ordinal
);
400 virtual IOReturn
requestPowerDomainState( IOPMPowerFlags
, IOPowerConnection
*, unsigned long ) APPLE_KEXT_OVERRIDE
;
401 virtual void powerChangeDone( unsigned long ) APPLE_KEXT_OVERRIDE
;
402 virtual bool tellChangeDown( unsigned long ) APPLE_KEXT_OVERRIDE
;
403 virtual bool askChangeDown( unsigned long ) APPLE_KEXT_OVERRIDE
;
404 virtual void tellChangeUp( unsigned long ) APPLE_KEXT_OVERRIDE
;
405 virtual void tellNoChangeDown( unsigned long ) APPLE_KEXT_OVERRIDE
;
406 virtual IOReturn
configureReport(IOReportChannelList
*channels
,
407 IOReportConfigureAction action
,
409 void *destination
) APPLE_KEXT_OVERRIDE
;
410 virtual IOReturn
updateReport(IOReportChannelList
*channels
,
411 IOReportUpdateAction action
,
413 void *destination
) APPLE_KEXT_OVERRIDE
;
415 void configureReportGated(uint64_t channel_id
,
418 IOReturn
updateReportGated(uint64_t ch_id
,
420 IOBufferMemoryDescriptor
*dest
);
422 #ifdef XNU_KERNEL_PRIVATE
423 /* Root Domain internals */
425 void tagPowerPlaneService(
427 IOPMActions
* actions
);
429 void overrideOurPowerChange(
431 IOPMActions
* actions
,
432 IOPMPowerStateIndex
* inOutPowerState
,
433 IOPMPowerChangeFlags
* inOutChangeFlags
,
434 IOPMRequestTag requestTag
);
436 void handleOurPowerChangeStart(
438 IOPMActions
* actions
,
439 IOPMPowerStateIndex powerState
,
440 IOPMPowerChangeFlags
* inOutChangeFlags
,
441 IOPMRequestTag requestTag
);
443 void handleOurPowerChangeDone(
445 IOPMActions
* actions
,
446 IOPMPowerStateIndex powerState
,
447 IOPMPowerChangeFlags changeFlags
,
448 IOPMRequestTag requestTag
);
450 void overridePowerChangeForUIService(
452 IOPMActions
* actions
,
453 IOPMPowerStateIndex
* inOutPowerState
,
454 IOPMPowerChangeFlags
* inOutChangeFlags
);
456 void handleActivityTickleForDisplayWrangler(
458 IOPMActions
* actions
);
460 void handleUpdatePowerClientForDisplayWrangler(
462 IOPMActions
* actions
,
463 const OSSymbol
* powerClient
,
464 IOPMPowerStateIndex oldPowerState
,
465 IOPMPowerStateIndex newPowerState
);
467 bool shouldDelayChildNotification(
468 IOService
* service
);
470 void handlePowerChangeStartForPCIDevice(
472 IOPMActions
* actions
,
473 IOPMPowerStateIndex powerState
,
474 IOPMPowerChangeFlags
* inOutChangeFlags
);
476 void handlePowerChangeDoneForPCIDevice(
478 IOPMActions
* actions
,
479 IOPMPowerStateIndex powerState
,
480 IOPMPowerChangeFlags changeFlags
);
482 void askChangeDownDone(
483 IOPMPowerChangeFlags
* inOutChangeFlags
,
486 void handlePublishSleepWakeUUID(
489 void handleQueueSleepWakeUUID(
492 void handleDisplayPowerOn();
494 void willNotifyPowerChildren( IOPMPowerStateIndex newPowerState
);
496 IOReturn
setMaintenanceWakeCalendar(
497 const IOPMCalendarStruct
* calendar
);
499 IOReturn
getSystemSleepType(uint32_t * sleepType
, uint32_t * standbyTimer
);
501 // Handle callbacks from IOService::systemWillShutdown()
502 void acknowledgeSystemWillShutdown( IOService
* from
);
504 // Handle platform halt and restart notifications
505 void handlePlatformHaltRestart( UInt32 pe_type
);
507 IOReturn
shutdownSystem( void );
508 IOReturn
restartSystem( void );
509 void handleSleepTimerExpiration( void );
511 bool activitySinceSleep(void);
512 bool abortHibernation(void);
513 void updateConsoleUsers(void);
515 IOReturn
joinAggressiveness( IOService
* service
);
516 void handleAggressivesRequests( void );
518 void kdebugTrace(uint32_t event
, uint64_t regId
,
519 uintptr_t param1
, uintptr_t param2
, uintptr_t param3
= 0);
520 void tracePoint(uint8_t point
);
521 void traceDetail(uint32_t msgType
, uint32_t msgIndex
, uint32_t delay
);
522 void traceDetail(OSObject
*notifier
, bool start
);
523 void traceAckDelay(OSObject
*notifier
, uint32_t response
, uint32_t delay_ms
);
525 void startSpinDump(uint32_t spindumpKind
);
527 bool systemMessageFilter(
528 void * object
, void * arg1
, void * arg2
, void * arg3
);
530 bool updatePreventIdleSleepList(
531 IOService
* service
, bool addNotRemove
);
532 void updatePreventSystemSleepList(
533 IOService
* service
, bool addNotRemove
);
535 bool updatePreventIdleSleepListInternal(
536 IOService
* service
, bool addNotRemove
, unsigned int oldCount
);
537 unsigned int idleSleepPreventersCount();
539 void publishPMSetting(
540 const OSSymbol
* feature
, uint32_t where
, uint32_t * featureID
);
542 void pmStatsRecordEvent(
544 AbsoluteTime timestamp
);
546 void pmStatsRecordApplicationResponse(
547 const OSSymbol
*response
,
553 IOPMPowerStateIndex ps
= 0);
555 void copyWakeReasonString( char * outBuf
, size_t bufSize
);
558 bool getHibernateSettings(
559 uint32_t * hibernateMode
,
560 uint32_t * hibernateFreeRatio
,
561 uint32_t * hibernateFreeTime
);
562 bool mustHibernate( void );
564 void takeStackshot(bool restart
);
565 void sleepWakeDebugTrig(bool restart
);
566 void sleepWakeDebugEnableWdog();
567 bool sleepWakeDebugIsWdogEnabled();
568 void sleepWakeDebugSaveSpinDumpFile();
569 bool checkShutdownTimeout();
570 void panicWithShutdownLog(uint32_t timeoutInMs
) __abortlike
;
571 uint32_t getWatchdogTimeout();
572 void deleteStackshot();
575 friend class PMSettingObject
;
576 friend class RootDomainUserClient
;
577 friend class PMAssertionsTracker
;
579 static IOReturn
sysPowerDownHandler( void * target
, void * refCon
,
580 UInt32 messageType
, IOService
* service
,
581 void * messageArgument
, vm_size_t argSize
);
583 static IOReturn
displayWranglerNotification( void * target
, void * refCon
,
584 UInt32 messageType
, IOService
* service
,
585 void * messageArgument
, vm_size_t argSize
);
587 static IOReturn
rootBusyStateChangeHandler( void * target
, void * refCon
,
588 UInt32 messageType
, IOService
* service
,
589 void * messageArgument
, vm_size_t argSize
);
591 static bool displayWranglerMatchPublished( void * target
, void * refCon
,
592 IOService
* newService
,
593 IONotifier
* notifier
);
595 static bool batteryPublished( void * target
, void * refCon
,
596 IOService
* resourceService
,
597 IONotifier
* notifier
);
599 void initializeBootSessionUUID( void );
601 void fullWakeDelayedWork( void );
603 IOService
* wrangler
;
604 OSDictionary
* wranglerIdleSettings
;
606 IOLock
*featuresDictLock
;// guards supportedFeatures
607 IOLock
*wakeEventLock
;
608 IOPMPowerStateQueue
*pmPowerStateQueue
;
610 OSArray
*allowedPMSettings
;
611 OSArray
*noPublishPMSettings
;
612 PMTraceWorker
*pmTracer
;
613 PMAssertionsTracker
*pmAssertions
;
615 // Settings controller info
616 IOLock
*settingsCtrlLock
;
617 OSDictionary
*settingsCallbacks
;
618 OSDictionary
*fPMSettingsDict
;
620 IONotifier
*_batteryPublishNotifier
;
621 IONotifier
*_displayWranglerNotifier
;
624 const OSSymbol
*_statsNameKey
;
625 const OSSymbol
*_statsPIDKey
;
626 const OSSymbol
*_statsTimeMSKey
;
627 const OSSymbol
*_statsResponseTypeKey
;
628 const OSSymbol
*_statsMessageTypeKey
;
629 const OSSymbol
*_statsPowerCapsKey
;
631 uint32_t darkWakeCnt
;
632 uint32_t displayWakeCnt
;
634 OSString
*queuedSleepWakeUUIDString
;
635 OSArray
*pmStatsAppResponses
;
636 IOLock
*pmStatsLock
;// guards pmStatsAppResponses
638 void *sleepDelaysReport
; // report to track time taken to go to sleep
639 uint32_t sleepDelaysClientCnt
;// Number of interested clients in sleepDelaysReport
640 uint64_t ts_sleepStart
;
641 uint64_t wake2DarkwakeDelay
; // Time taken to change from full wake -> Dark wake
644 void *assertOnWakeReport
;// report to track time spent without any assertions held after wake
645 uint32_t assertOnWakeClientCnt
;// Number of clients interested in assertOnWakeReport
646 clock_sec_t assertOnWakeSecs
; // Num of secs after wake for first assertion
650 // Pref: idle time before idle sleep
651 bool idleSleepEnabled
;
652 unsigned long sleepSlider
;
653 unsigned long idleSeconds
;
654 uint64_t autoWakeStart
;
655 uint64_t autoWakeEnd
;
657 // Difference between sleepSlider and longestNonSleepSlider
658 unsigned long extraSleepDelay
;
660 // Used to wait between say display idle and system idle
661 thread_call_t extraSleepTimer
;
662 thread_call_t powerButtonDown
;
663 thread_call_t powerButtonUp
;
664 thread_call_t diskSyncCalloutEntry
;
665 thread_call_t fullWakeThreadCall
;
666 thread_call_t updateConsoleUsersEntry
;
668 // Track system capabilities.
669 uint32_t _desiredCapability
;
670 uint32_t _currentCapability
;
671 uint32_t _pendingCapability
;
672 uint32_t _highestCapability
;
673 OSSet
* _joinedCapabilityClients
;
674 uint32_t _systemStateGeneration
;
676 // Type of clients that can receive system messages.
678 kSystemMessageClientPowerd
= 0x01,
679 kSystemMessageClientLegacyApp
= 0x02,
680 kSystemMessageClientKernel
= 0x04,
681 kSystemMessageClientAll
= 0x07
683 uint32_t _systemMessageClientMask
;
685 // Power state and capability change transitions.
687 kSystemTransitionNone
= 0,
688 kSystemTransitionSleep
= 1,
689 kSystemTransitionWake
= 2,
690 kSystemTransitionCapability
= 3,
691 kSystemTransitionNewCapClient
= 4
692 } _systemTransitionType
;
694 unsigned int systemBooting
:1;
695 unsigned int systemShutdown
:1;
696 unsigned int systemDarkWake
:1;
697 unsigned int clamshellExists
:1;
698 unsigned int clamshellClosed
:1;
699 unsigned int clamshellDisabled
:1;
700 unsigned int desktopMode
:1;
701 unsigned int acAdaptorConnected
:1;
703 unsigned int clamshellSleepDisabled
:1;
704 unsigned int idleSleepTimerPending
:1;
705 unsigned int userDisabledAllSleep
:1;
706 unsigned int ignoreTellChangeDown
:1;
707 unsigned int wranglerAsleep
:1;
708 unsigned int wranglerTickled
:1;
709 unsigned int _preventUserActive
:1;
710 unsigned int graphicsSuppressed
:1;
711 unsigned int isRTCAlarmWake
:1;
713 unsigned int capabilityLoss
:1;
714 unsigned int pciCantSleepFlag
:1;
715 unsigned int pciCantSleepValid
:1;
716 unsigned int logGraphicsClamp
:1;
717 unsigned int darkWakeToSleepASAP
:1;
718 unsigned int darkWakeMaintenance
:1;
719 unsigned int darkWakeSleepService
:1;
720 unsigned int darkWakePostTickle
:1;
722 unsigned int sleepTimerMaintenance
:1;
723 unsigned int sleepToStandby
:1;
724 unsigned int lowBatteryCondition
:1;
725 unsigned int hibernateDisabled
:1;
726 unsigned int hibernateRetry
:1;
727 unsigned int wranglerTickleLatched
:1;
728 unsigned int userIsActive
:1;
729 unsigned int userWasActive
:1;
731 unsigned int displayIdleForDemandSleep
:1;
732 unsigned int darkWakeHibernateError
:1;
733 unsigned int thermalWarningState
:1;
734 unsigned int toldPowerdCapWillChange
:1;
735 unsigned int displayPowerOnRequested
:1;
737 uint8_t tasksSuspended
;
738 uint8_t tasksSuspendState
;
739 uint32_t hibernateMode
;
740 AbsoluteTime userActivityTime
;
741 AbsoluteTime userActivityTime_prev
;
742 uint32_t userActivityCount
;
743 uint32_t userActivityAtSleep
;
744 uint32_t lastSleepReason
;
745 uint32_t fullToDarkReason
;
746 uint32_t hibernateAborted
;
747 uint8_t standbyNixed
;
750 enum FullWakeReason
{
751 kFullWakeReasonNone
= 0,
752 kFullWakeReasonLocalUser
= 1,
753 kFullWakeReasonDisplayOn
= 2,
754 fFullWakeReasonDisplayOnAndLocalUser
= 3
756 uint32_t fullWakeReason
;
758 // Info for communicating system state changes to PMCPU
759 int32_t idxPMCPUClamshell
;
760 int32_t idxPMCPULimitedPower
;
762 IOOptionBits platformSleepSupport
;
763 uint32_t _debugWakeSeconds
;
764 uint32_t _lastDebugWakeSeconds
;
766 queue_head_t aggressivesQueue
;
767 thread_call_t aggressivesThreadCall
;
768 OSData
* aggressivesData
;
770 AbsoluteTime userBecameInactiveTime
;
772 // PCI top-level PM trace
773 IOService
* pciHostBridgeDevice
;
774 IOService
* pciHostBridgeDriver
;
776 IONotifier
* systemCapabilityNotifier
;
781 } PMNotifySuspendedStruct
;
783 uint32_t pmSuspendedCapacity
;
784 uint32_t pmSuspendedSize
;
785 PMNotifySuspendedStruct
*pmSuspendedPIDS
;
787 OSSet
* preventIdleSleepList
;
788 OSSet
* preventSystemSleepList
;
790 UInt32 _scheduledAlarms
;
791 UInt32 _userScheduledAlarm
;
792 clock_sec_t _scheduledAlarmUTC
;
795 clock_sec_t _standbyTimerResetSeconds
;
797 volatile uint32_t swd_lock
;/* Lock to access swd_buffer & and its header */
798 void * swd_buffer
;/* Memory allocated for dumping sleep/wake logs */
799 uint32_t swd_flags
;/* Flags defined in IOPMPrivate.h */
800 void * swd_compressed_buffer
;
801 void * swd_spindump_buffer
;
802 thread_t notifierThread
;
803 OSObject
*notifierObject
;
805 IOBufferMemoryDescriptor
*swd_memDesc
;
807 // Wake Event Reporting
808 OSArray
* _systemWakeEventsArray
;
809 bool _acceptSystemWakeEvents
;
811 #if !(defined(RC_HIDE_N144) || defined(RC_HIDE_N146))
813 IOPMCalendarStruct _aotWakeTimeCalendar
;
814 IOTimerEventSource
* _aotTimerES
;
815 clock_sec_t _aotWakeTimeUTC
;
816 uint64_t _aotTestTime
;
817 uint64_t _aotTestInterval
;
818 uint32_t _aotPendingFlags
;
820 IOPMAOTMetrics
* _aotMetrics
;
824 uint8_t _aotTasksSuspended
;
826 uint8_t _aotTimerScheduled
;
827 uint8_t _aotReadyToFullWake
;
828 uint64_t _aotLastWakeTime
;
829 uint64_t _aotWakeTimeContinuous
;
830 uint64_t _aotWakePreWindow
;
831 uint64_t _aotWakePostWindow
;
832 uint64_t _aotLingerTime
;
834 bool aotShouldExit(bool checkTimeSet
, bool software
);
835 void aotExit(bool cps
);
836 void aotEvaluate(IOTimerEventSource
* timer
);
838 bool isAOTMode(void);
841 #endif /* !(defined(RC_HIDE_N144) || defined(RC_HIDE_N146)) */
843 void updateTasksSuspend(void);
844 int findSuspendedPID(uint32_t pid
, uint32_t *outRefCount
);
846 // IOPMrootDomain internal sleep call
847 IOReturn
privateSleepSystem( uint32_t sleepReason
);
848 void reportUserInput( void );
849 void setDisableClamShellSleep( bool );
850 bool checkSystemSleepAllowed( IOOptionBits options
,
851 uint32_t sleepReason
);
852 bool checkSystemSleepEnabled( void );
853 bool checkSystemCanSleep( uint32_t sleepReason
);
854 bool checkSystemCanSustainFullWake( void );
856 void adjustPowerState( bool sleepASAP
= false );
857 void setQuickSpinDownTimeout( void );
858 void restoreUserSpinDownTimeout( void );
860 bool shouldSleepOnClamshellClosed(void );
861 bool shouldSleepOnRTCAlarmWake(void );
862 void sendClientClamshellNotification( void );
864 // Inform PMCPU of changes to state like lid, AC vs. battery
865 void informCPUStateChange( uint32_t type
, uint32_t value
);
867 void dispatchPowerEvent( uint32_t event
, void * arg0
, uint64_t arg1
);
868 void handlePowerNotification( UInt32 msg
);
870 IOReturn
setPMSetting(const OSSymbol
*, OSObject
*);
872 void startIdleSleepTimer( uint32_t inSeconds
);
873 void cancelIdleSleepTimer( void );
874 uint32_t getTimeToIdleSleep( void );
876 IOReturn
setAggressiveness(
879 IOOptionBits options
);
881 void synchronizeAggressives(
882 queue_head_t
* services
,
883 const AggressivesRecord
* array
,
886 void broadcastAggressives(
887 const AggressivesRecord
* array
,
890 IOReturn
setPMAssertionUserLevels(IOPMDriverAssertionType
);
892 void publishSleepWakeUUID( bool shouldPublish
);
894 void evaluatePolicy( int stimulus
, uint32_t arg
= 0 );
895 void requestFullWake( FullWakeReason reason
);
896 void willEnterFullWake( void );
898 void evaluateAssertions(IOPMDriverAssertionType newAssertions
,
899 IOPMDriverAssertionType oldAssertions
);
901 void deregisterPMSettingObject( PMSettingObject
* pmso
);
903 uint32_t checkForValidDebugData(const char *fname
, vfs_context_t
*ctx
,
904 void *tmpBuf
, struct vnode
**vp
);
905 void getFailureData(thread_t
*thread
, char *failureStr
, size_t strLen
);
906 void saveFailureData2File();
907 void tracePhase2String(uint32_t tracePhase
, const char **phaseString
, const char **description
);
908 void sleepWakeDebugMemAlloc();
909 void sleepWakeDebugSpinDumpMemAlloc();
910 errno_t
sleepWakeDebugSaveFile(const char *name
, char *buf
, int len
);
914 bool getSleepOption( const char * key
, uint32_t * option
);
915 bool evaluateSystemSleepPolicy( IOPMSystemSleepParameters
* p
,
916 int phase
, uint32_t * hibMode
);
917 void evaluateSystemSleepPolicyEarly( void );
918 void evaluateSystemSleepPolicyFinal( void );
919 #endif /* HIBERNATION */
921 bool latchDisplayWranglerTickle( bool latch
);
922 void setDisplayPowerOn( uint32_t options
);
924 void acceptSystemWakeEvents( bool accept
);
925 void systemDidNotSleep( void );
926 void preventTransitionToUserActive( bool prevent
);
927 void setThermalState(OSObject
*value
);
928 void copySleepPreventersList(OSArray
**idleSleepList
, OSArray
**systemSleepList
);
929 void copySleepPreventersListWithID(OSArray
**idleSleepList
, OSArray
**systemSleepList
);
930 #endif /* XNU_KERNEL_PRIVATE */
933 #ifdef XNU_KERNEL_PRIVATE
934 class IORootParent
: public IOService
936 OSDeclareFinalStructors(IORootParent
);
939 static void initialize( void );
940 virtual OSObject
* copyProperty( const char * aKey
) const APPLE_KEXT_OVERRIDE
;
941 bool start( IOService
* nub
) APPLE_KEXT_OVERRIDE
;
942 void shutDownSystem( void );
943 void restartSystem( void );
944 void sleepSystem( void );
945 void dozeSystem( void );
946 void sleepToDoze( void );
947 void wakeSystem( void );
949 #endif /* XNU_KERNEL_PRIVATE */
951 #endif /* _IOKIT_ROOTDOMAIN_H */