]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/pwr_mgt/RootDomain.h
xnu-6153.11.26.tar.gz
[apple/xnu.git] / iokit / IOKit / pwr_mgt / RootDomain.h
CommitLineData
1c79356b 1/*
cb323159 2 * Copyright (c) 1998-2019 Apple Inc. All rights reserved.
1c79356b 3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
0a7de745 5 *
2d21ac55
A
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
0a7de745 14 *
2d21ac55
A
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
0a7de745 17 *
2d21ac55
A
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
0a7de745 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
27 */
28#ifndef _IOKIT_ROOTDOMAIN_H
29#define _IOKIT_ROOTDOMAIN_H
30
31#include <IOKit/IOService.h>
32#include <IOKit/pwr_mgt/IOPM.h>
fe8ab488
A
33#include <IOKit/IOBufferMemoryDescriptor.h>
34#include <sys/vnode.h>
b0d623f7
A
35
36#ifdef XNU_KERNEL_PRIVATE
cb323159
A
37
38#include <IOKit/pwr_mgt/IOPMPrivate.h>
39
b0d623f7 40struct AggressivesRecord;
6d2010ae
A
41struct IOPMMessageFilterContext;
42struct IOPMActions;
316670eb 43struct IOPMSystemSleepParameters;
6d2010ae 44class PMSettingObject;
6d2010ae 45class PMTraceWorker;
55e303ae 46class IOPMPowerStateQueue;
1c79356b 47class RootDomainUserClient;
6d2010ae 48class PMAssertionsTracker;
cb323159 49class IOTimerEventSource;
fe8ab488 50
5ba3f43e 51#define OBFUSCATE(x) (void *)VM_KERNEL_UNSLIDE_OR_PERM(x)
fe8ab488 52
6d2010ae 53#endif
1c79356b 54
0b4c1975
A
55/*!
56 * Types for PM Assertions
57 * For creating, releasing, and getting PM assertion levels.
58 */
fe8ab488 59
0b4c1975
A
60/*! IOPMDriverAssertionType
61 * A bitfield describing a set of assertions. May be used to specify which assertions
fe8ab488 62 * to set with <link>IOPMrootDomain::createPMAssertion</link>; or to query which
0b4c1975
A
63 * assertions are set with <link>IOPMrootDomain::releasePMAssertion</link>.
64 */
65typedef uint64_t IOPMDriverAssertionType;
66
67/* IOPMDriverAssertionID
68 * Drivers may create PM assertions to request system behavior (keep the system awake,
fe8ab488
A
69 * or keep the display awake). When a driver creates an assertion via
70 * <link>IOPMrootDomain::createPMAssertion</link>, PM returns a handle to
0b4c1975
A
71 * the assertion of type IOPMDriverAssertionID.
72 */
73typedef uint64_t IOPMDriverAssertionID;
74#define kIOPMUndefinedDriverAssertionID 0
75
76/* IOPMDriverAssertionLevel
77 * Possible values for IOPMDriverAssertionLevel are <link>kIOPMDriverAssertionLevelOff</link>
78 * and <link>kIOPMDriverAssertionLevelOn</link>
79 */
80typedef uint32_t IOPMDriverAssertionLevel;
81#define kIOPMDriverAssertionLevelOff 0
82#define kIOPMDriverAssertionLevelOn 255
83
b0d623f7
A
84/*
85 * Flags for get/setSleepSupported()
86 */
1c79356b 87enum {
0a7de745
A
88 kRootDomainSleepNotSupported = 0x00000000,
89 kRootDomainSleepSupported = 0x00000001,
90 kFrameBufferDeepSleepSupported = 0x00000002,
91 kPCICantSleep = 0x00000004
1c79356b
A
92};
93
fe8ab488 94/*
0a7de745 95 * IOPMrootDomain registry property keys
2d21ac55
A
96 */
97#define kRootDomainSupportedFeatures "Supported Features"
98#define kRootDomainSleepReasonKey "Last Sleep Reason"
99#define kRootDomainSleepOptionsKey "Last Sleep Options"
b0d623f7
A
100#define kIOPMRootDomainWakeReasonKey "Wake Reason"
101#define kIOPMRootDomainWakeTypeKey "Wake Type"
4a3eedf9 102#define kIOPMRootDomainPowerStatusKey "Power Status"
2d21ac55
A
103
104/*
105 * Possible sleep reasons found under kRootDomainSleepReasonsKey
106 */
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"
b0d623f7 114#define kIOPMMaintenanceSleepKey "Maintenance Sleep"
2d21ac55
A
115
116/*
117 * String constants for communication with PM CPU
118 */
119#define kIOPMRootDomainLidCloseCString "LidClose"
120#define kIOPMRootDomainBatPowerCString "BatPower"
0c530ab8 121
b0d623f7
A
122/*
123 * Supported Feature bitfields for IOPMrootDomain::publishFeature()
124 */
e5568f75 125enum {
0a7de745
A
126 kIOPMSupportedOnAC = (1 << 0),
127 kIOPMSupportedOnBatt = (1 << 1),
128 kIOPMSupportedOnUPS = (1 << 2)
e5568f75 129};
4452a7af 130
b0d623f7 131typedef IOReturn (*IOPMSettingControllerCallback)
0a7de745
A
132(OSObject *target, const OSSymbol *type,
133 OSObject *val, uintptr_t refcon);
4452a7af 134
b0d623f7
A
135__BEGIN_DECLS
136IONotifier * registerSleepWakeInterest(
cb323159 137 IOServiceInterestHandler, void *, void * = NULL);
fe8ab488 138
b0d623f7 139IONotifier * registerPrioritySleepWakeInterest(
0a7de745 140 IOServiceInterestHandler handler,
cb323159 141 void * self, void * ref = NULL);
0c530ab8 142
b0d623f7 143IOReturn acknowledgeSleepWakeNotification(void * );
0c530ab8 144
b0d623f7
A
145IOReturn vetoSleepWakeNotification(void * PMrefcon);
146__END_DECLS
1c79356b 147
fe8ab488 148#define IOPM_ROOTDOMAIN_REV 2
1c79356b 149
0a7de745 150class IOPMrootDomain : public IOService
1c79356b 151{
cb323159 152 OSDeclareFinalStructors(IOPMrootDomain);
0b4e3aa0 153
b0d623f7 154public:
0a7de745 155 static IOPMrootDomain * construct( void );
2d21ac55 156
0a7de745
A
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;
2d21ac55 160
0a7de745
A
161 virtual IOReturn sleepSystem( void );
162 IOReturn sleepSystemOptions( OSDictionary *options );
b0d623f7 163
0a7de745
A
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;
4a3eedf9
A
167
168/*! @function systemPowerEventOccurred
0a7de745
A
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 */
b0d623f7 175
0a7de745
A
176 IOReturn systemPowerEventOccurred(
177 const OSSymbol *event,
178 uint32_t intValue );
b0d623f7 179
0a7de745
A
180 IOReturn systemPowerEventOccurred(
181 const OSSymbol *event,
182 OSObject *value );
b0d623f7 183
fe8ab488
A
184#ifdef XNU_KERNEL_PRIVATE // Hide doc from public headers
185/*! @function claimSystemWakeEvent
0a7de745
A
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.
190 *
191 * - Drivers should call claimSystemWakeEvent before completing
192 * their setPowerState() acknowledgement. IOPMrootDomain stops
193 * collecting wake events when driver wake is complete.
194 *
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.
198 *
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).
201 *
202 * Examples:
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")
209 *
210 * @param device The device/nub that is associated with the wake event.
211 *
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.
216 *
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:
220 * [Hardware].[Event]
221 * WiFi.MagicPacket
222 * WiFi.ScanOffload
223 * WiFi.mDNSConflict
224 * WiFi.mDNSService
225 * WiFi.TCPData
226 * WiFi.TCPTimeout
227 * WiFi.FirmwareCrash
228 * Enet.MagicPacket
229 * Enet.mDNSConflict
230 * Enet.mDNSService
231 * Enet.TCPData
232 * Enet.TCPTimeout
233 * Enet.Service
234 * Enet.LinkToggle
235 * Enet.ConflictResolution
236 * Enet.PatternMatch
237 * Enet.Timer
238 * Enet.LinkUpTimeout
239 * Enet.LinkDown
240 * USB.DeviceAttach
241 * USB.DeviceDetach
242 *
243 * @param details Optional details further describing the wake event.
244 * Please pass an OSString defining the event.
245 */
fe8ab488 246#endif
0a7de745
A
247 void claimSystemWakeEvent( IOService *device,
248 IOOptionBits flags,
249 const char *reason,
cb323159 250 OSObject *details = NULL );
fe8ab488 251
0a7de745 252 virtual IOReturn receivePowerNotification( UInt32 msg );
b0d623f7 253
0a7de745 254 virtual void setSleepSupported( IOOptionBits flags );
b0d623f7 255
0a7de745 256 virtual IOOptionBits getSleepSupported( void );
b0d623f7 257
0a7de745 258 void wakeFromDoze( void );
0c530ab8 259
0a7de745 260// KEXT driver announces support of power management feature
b0d623f7 261
0a7de745 262 void publishFeature( const char *feature );
fe8ab488 263
0a7de745
A
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
267// feature.
268// NULL is acceptable for uniqueFeatureID for kexts without plans to unload.
b0d623f7 269
0a7de745
A
270 void publishFeature( const char *feature,
271 uint32_t supportedWhere,
272 uint32_t *uniqueFeatureID);
0c530ab8 273
0a7de745
A
274// KEXT driver announces removal of a previously published power management
275// feature. Pass 'uniqueFeatureID' returned from publishFeature()
0c530ab8 276
0a7de745 277 IOReturn removePublishedFeature( uint32_t removeFeatureID );
9bccf70c 278
0c530ab8 279/*! @function copyPMSetting
0a7de745
A
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. */
b0d623f7 284
0a7de745 285 OSObject * copyPMSetting( OSSymbol *whichSetting );
b0d623f7 286
0c530ab8 287/*! @function registerPMSettingController
0a7de745
A
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. */
298
299 IOReturn registerPMSettingController(
300 const OSSymbol *settings[],
301 IOPMSettingControllerCallback callout,
302 OSObject *target,
303 uintptr_t refcon,
304 OSObject **handle); // out param
0c530ab8
A
305
306/*! @function registerPMSettingController
0a7de745
A
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. */
319
320 IOReturn registerPMSettingController(
321 const OSSymbol *settings[],
322 uint32_t supportedPowerSources,
323 IOPMSettingControllerCallback callout,
324 OSObject *target,
325 uintptr_t refcon,
326 OSObject **handle); // out param
327
328 virtual IONotifier * registerInterest(
329 const OSSymbol * typeOfInterest,
330 IOServiceInterestHandler handler,
cb323159 331 void * target, void * ref = NULL ) APPLE_KEXT_OVERRIDE;
0a7de745
A
332
333 virtual IOReturn callPlatformFunction(
334 const OSSymbol *functionName,
335 bool waitForFunction,
336 void *param1, void *param2,
337 void *param3, void *param4 ) APPLE_KEXT_OVERRIDE;
b0d623f7 338
0b4c1975 339/*! @function createPMAssertion
0a7de745
A
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
347 */
348 IOPMDriverAssertionID createPMAssertion(
349 IOPMDriverAssertionType whichAssertionsBits,
350 IOPMDriverAssertionLevel assertionLevel,
351 IOService *ownerService,
352 const char *ownerDescription);
0b4c1975
A
353
354/* @function setPMAssertionLevel
0a7de745
A
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
359 * their lifespan.
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.
363 */
364 IOReturn setPMAssertionLevel(IOPMDriverAssertionID assertionID, IOPMDriverAssertionLevel assertionLevel);
0b4c1975
A
365
366/*! @function getPMAssertionLevel
0a7de745
A
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.
378 */
379 IOPMDriverAssertionLevel getPMAssertionLevel(IOPMDriverAssertionType whichAssertionBits);
0b4c1975
A
380
381/*! @function releasePMAssertion
0a7de745
A
382 * @abstract Removes an assertion to influence system power behavior.
383 * @result On success, returns a new assertion of type IOPMDriverAssertionID *
384 */
385 IOReturn releasePMAssertion(IOPMDriverAssertionID releaseAssertion);
39236c6e 386
fe8ab488 387/*! @function restartWithStackshot
0a7de745
A
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.
390 */
391 IOReturn restartWithStackshot();
fe8ab488 392
cb323159
A
393 IOReturn setWakeTime(uint64_t wakeContinuousTime);
394
b0d623f7 395private:
cb323159
A
396 unsigned long getRUN_STATE(void);
397
0a7de745
A
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,
408 void *result,
409 void *destination) APPLE_KEXT_OVERRIDE;
410 virtual IOReturn updateReport(IOReportChannelList *channels,
411 IOReportUpdateAction action,
412 void *result,
413 void *destination) APPLE_KEXT_OVERRIDE;
414
415 void configureReportGated(uint64_t channel_id,
416 uint64_t action,
417 void *result);
418 IOReturn updateReportGated(uint64_t ch_id,
419 void *result,
420 IOBufferMemoryDescriptor *dest);
39236c6e 421
b0d623f7 422#ifdef XNU_KERNEL_PRIVATE
0a7de745 423/* Root Domain internals */
b0d623f7 424public:
0a7de745
A
425 void tagPowerPlaneService(
426 IOService * service,
427 IOPMActions * actions );
428
429 void overrideOurPowerChange(
430 IOService * service,
431 IOPMActions * actions,
432 IOPMPowerStateIndex * inOutPowerState,
433 IOPMPowerChangeFlags * inOutChangeFlags,
434 IOPMRequestTag requestTag );
435
436 void handleOurPowerChangeStart(
437 IOService * service,
438 IOPMActions * actions,
439 IOPMPowerStateIndex powerState,
440 IOPMPowerChangeFlags * inOutChangeFlags,
441 IOPMRequestTag requestTag );
442
443 void handleOurPowerChangeDone(
444 IOService * service,
445 IOPMActions * actions,
446 IOPMPowerStateIndex powerState,
447 IOPMPowerChangeFlags changeFlags,
448 IOPMRequestTag requestTag );
449
450 void overridePowerChangeForUIService(
451 IOService * service,
452 IOPMActions * actions,
453 IOPMPowerStateIndex * inOutPowerState,
454 IOPMPowerChangeFlags * inOutChangeFlags );
455
456 void handleActivityTickleForDisplayWrangler(
457 IOService * service,
458 IOPMActions * actions );
459
460 void handleUpdatePowerClientForDisplayWrangler(
461 IOService * service,
462 IOPMActions * actions,
463 const OSSymbol * powerClient,
464 IOPMPowerStateIndex oldPowerState,
465 IOPMPowerStateIndex newPowerState );
466
467 bool shouldDelayChildNotification(
468 IOService * service );
469
470 void handlePowerChangeStartForPCIDevice(
471 IOService * service,
472 IOPMActions * actions,
473 IOPMPowerStateIndex powerState,
474 IOPMPowerChangeFlags * inOutChangeFlags );
475
476 void handlePowerChangeDoneForPCIDevice(
477 IOService * service,
478 IOPMActions * actions,
479 IOPMPowerStateIndex powerState,
480 IOPMPowerChangeFlags changeFlags );
481
482 void askChangeDownDone(
483 IOPMPowerChangeFlags * inOutChangeFlags,
484 bool * cancel );
485
486 void handlePublishSleepWakeUUID(
487 bool shouldPublish);
488
489 void handleQueueSleepWakeUUID(
490 OSObject *obj);
491
492 void handleDisplayPowerOn();
493
494 void willNotifyPowerChildren( IOPMPowerStateIndex newPowerState );
495
496 IOReturn setMaintenanceWakeCalendar(
497 const IOPMCalendarStruct * calendar );
498
499 IOReturn getSystemSleepType(uint32_t * sleepType, uint32_t * standbyTimer);
500
501// Handle callbacks from IOService::systemWillShutdown()
502 void acknowledgeSystemWillShutdown( IOService * from );
503
504// Handle platform halt and restart notifications
505 void handlePlatformHaltRestart( UInt32 pe_type );
506
507 IOReturn shutdownSystem( void );
508 IOReturn restartSystem( void );
509 void handleSleepTimerExpiration( void );
510
511 bool activitySinceSleep(void);
512 bool abortHibernation(void);
513 void updateConsoleUsers(void);
514
515 IOReturn joinAggressiveness( IOService * service );
516 void handleAggressivesRequests( void );
517
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);
524
525 void startSpinDump(uint32_t spindumpKind);
526
527 bool systemMessageFilter(
528 void * object, void * arg1, void * arg2, void * arg3 );
529
530 bool updatePreventIdleSleepList(
531 IOService * service, bool addNotRemove );
532 void updatePreventSystemSleepList(
533 IOService * service, bool addNotRemove );
316670eb 534
cb323159
A
535 bool updatePreventIdleSleepListInternal(
536 IOService * service, bool addNotRemove, unsigned int oldCount);
537 unsigned int idleSleepPreventersCount();
538
0a7de745
A
539 void publishPMSetting(
540 const OSSymbol * feature, uint32_t where, uint32_t * featureID );
541
542 void pmStatsRecordEvent(
543 int eventIndex,
544 AbsoluteTime timestamp);
6d2010ae 545
0a7de745
A
546 void pmStatsRecordApplicationResponse(
547 const OSSymbol *response,
548 const char *name,
549 int messageType,
550 uint32_t delay_ms,
551 uint64_t id,
552 OSObject *object,
553 IOPMPowerStateIndex ps = 0);
316670eb 554
0a7de745 555 void copyWakeReasonString( char * outBuf, size_t bufSize );
316670eb 556
6d2010ae 557#if HIBERNATION
0a7de745
A
558 bool getHibernateSettings(
559 uint32_t * hibernateMode,
560 uint32_t * hibernateFreeRatio,
561 uint32_t * hibernateFreeTime );
562 bool mustHibernate( void );
6d2010ae 563#endif
cb323159 564 void takeStackshot(bool restart);
0a7de745
A
565 void sleepWakeDebugTrig(bool restart);
566 void sleepWakeDebugEnableWdog();
567 bool sleepWakeDebugIsWdogEnabled();
568 void sleepWakeDebugSaveSpinDumpFile();
569 bool checkShutdownTimeout();
cb323159 570 void panicWithShutdownLog(uint32_t timeoutInMs) __abortlike;
0a7de745 571 uint32_t getWatchdogTimeout();
cb323159 572 void deleteStackshot();
b0d623f7 573
1c79356b 574private:
0a7de745
A
575 friend class PMSettingObject;
576 friend class RootDomainUserClient;
577 friend class PMAssertionsTracker;
578
579 static IOReturn sysPowerDownHandler( void * target, void * refCon,
580 UInt32 messageType, IOService * service,
581 void * messageArgument, vm_size_t argSize );
582
583 static IOReturn displayWranglerNotification( void * target, void * refCon,
584 UInt32 messageType, IOService * service,
585 void * messageArgument, vm_size_t argSize );
586
587 static IOReturn rootBusyStateChangeHandler( void * target, void * refCon,
588 UInt32 messageType, IOService * service,
589 void * messageArgument, vm_size_t argSize );
590
591 static bool displayWranglerMatchPublished( void * target, void * refCon,
592 IOService * newService,
593 IONotifier * notifier);
594
595 static bool batteryPublished( void * target, void * refCon,
596 IOService * resourceService,
597 IONotifier * notifier);
598
599 void initializeBootSessionUUID( void );
600
601 void fullWakeDelayedWork( void );
602
603 IOService * wrangler;
604 OSDictionary * wranglerIdleSettings;
605
606 IOLock *featuresDictLock;// guards supportedFeatures
607 IOLock *wakeEventLock;
608 IOPMPowerStateQueue *pmPowerStateQueue;
609
610 OSArray *allowedPMSettings;
611 OSArray *noPublishPMSettings;
612 PMTraceWorker *pmTracer;
613 PMAssertionsTracker *pmAssertions;
614
615// Settings controller info
616 IOLock *settingsCtrlLock;
617 OSDictionary *settingsCallbacks;
618 OSDictionary *fPMSettingsDict;
619
620 IONotifier *_batteryPublishNotifier;
621 IONotifier *_displayWranglerNotifier;
622
623// Statistics
624 const OSSymbol *_statsNameKey;
625 const OSSymbol *_statsPIDKey;
626 const OSSymbol *_statsTimeMSKey;
627 const OSSymbol *_statsResponseTypeKey;
628 const OSSymbol *_statsMessageTypeKey;
629 const OSSymbol *_statsPowerCapsKey;
630 uint32_t sleepCnt;
631 uint32_t darkWakeCnt;
632 uint32_t displayWakeCnt;
633
634 OSString *queuedSleepWakeUUIDString;
635 OSArray *pmStatsAppResponses;
636 IOLock *pmStatsLock;// guards pmStatsAppResponses
637
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
642
643
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
647
648 bool uuidPublished;
649
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;
656
657// Difference between sleepSlider and longestNonSleepSlider
658 unsigned long extraSleepDelay;
659
660// Used to wait between say display idle and system idle
661 thread_call_t extraSleepTimer;
cb323159
A
662 thread_call_t powerButtonDown;
663 thread_call_t powerButtonUp;
0a7de745
A
664 thread_call_t diskSyncCalloutEntry;
665 thread_call_t fullWakeThreadCall;
666 thread_call_t updateConsoleUsersEntry;
667
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;
675
676// Type of clients that can receive system messages.
677 enum {
678 kSystemMessageClientPowerd = 0x01,
679 kSystemMessageClientLegacyApp = 0x02,
680 kSystemMessageClientKernel = 0x04,
681 kSystemMessageClientAll = 0x07
682 };
683 uint32_t _systemMessageClientMask;
684
685// Power state and capability change transitions.
686 enum {
687 kSystemTransitionNone = 0,
688 kSystemTransitionSleep = 1,
689 kSystemTransitionWake = 2,
690 kSystemTransitionCapability = 3,
691 kSystemTransitionNewCapClient = 4
692 } _systemTransitionType;
693
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;
702
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;
cb323159 711 unsigned int isRTCAlarmWake :1;
0a7de745
A
712
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;
721
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;
730
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;
736
737 uint8_t tasksSuspended;
cb323159 738 uint8_t tasksSuspendState;
0a7de745
A
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;
748 uint8_t resetTimers;
749
750 enum FullWakeReason {
751 kFullWakeReasonNone = 0,
752 kFullWakeReasonLocalUser = 1,
753 kFullWakeReasonDisplayOn = 2,
754 fFullWakeReasonDisplayOnAndLocalUser = 3
755 };
756 uint32_t fullWakeReason;
757
758// Info for communicating system state changes to PMCPU
759 int32_t idxPMCPUClamshell;
760 int32_t idxPMCPULimitedPower;
761
762 IOOptionBits platformSleepSupport;
763 uint32_t _debugWakeSeconds;
764 uint32_t _lastDebugWakeSeconds;
765
766 queue_head_t aggressivesQueue;
767 thread_call_t aggressivesThreadCall;
768 OSData * aggressivesData;
769
770 AbsoluteTime userBecameInactiveTime;
771
772// PCI top-level PM trace
773 IOService * pciHostBridgeDevice;
774 IOService * pciHostBridgeDriver;
775
776 IONotifier * systemCapabilityNotifier;
777
778 typedef struct {
779 uint32_t pid;
780 uint32_t refcount;
781 } PMNotifySuspendedStruct;
782
783 uint32_t pmSuspendedCapacity;
784 uint32_t pmSuspendedSize;
785 PMNotifySuspendedStruct *pmSuspendedPIDS;
786
787 OSSet * preventIdleSleepList;
788 OSSet * preventSystemSleepList;
789
790 UInt32 _scheduledAlarms;
791 UInt32 _userScheduledAlarm;
cb323159 792 clock_sec_t _scheduledAlarmUTC;
99c3a104 793
316670eb 794#if HIBERNATION
0a7de745 795 clock_sec_t _standbyTimerResetSeconds;
316670eb 796#endif
0a7de745
A
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;
fe8ab488 804
0a7de745 805 IOBufferMemoryDescriptor *swd_memDesc;
39037602 806
0a7de745
A
807// Wake Event Reporting
808 OSArray * _systemWakeEventsArray;
809 bool _acceptSystemWakeEvents;
0b4e3aa0 810
cb323159
A
811#if !(defined(RC_HIDE_N144) || defined(RC_HIDE_N146))
812 // AOT --
813 IOPMCalendarStruct _aotWakeTimeCalendar;
814 IOTimerEventSource * _aotTimerES;
815 clock_sec_t _aotWakeTimeUTC;
816 uint64_t _aotTestTime;
817 uint64_t _aotTestInterval;
818 uint32_t _aotPendingFlags;
819public:
820 IOPMAOTMetrics * _aotMetrics;
821 uint8_t _aotMode;
822private:
823 uint8_t _aotNow;
824 uint8_t _aotTasksSuspended;
825 uint8_t _aotExit;
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;
833
834 bool aotShouldExit(bool checkTimeSet, bool software);
835 void aotExit(bool cps);
836 void aotEvaluate(IOTimerEventSource * timer);
837public:
838 bool isAOTMode(void);
839private:
840 // -- AOT
841#endif /* !(defined(RC_HIDE_N144) || defined(RC_HIDE_N146)) */
842
843 void updateTasksSuspend(void);
0a7de745 844 int findSuspendedPID(uint32_t pid, uint32_t *outRefCount);
7ddcb079 845
0a7de745
A
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 );
0b4e3aa0 855
0a7de745
A
856 void adjustPowerState( bool sleepASAP = false );
857 void setQuickSpinDownTimeout( void );
858 void restoreUserSpinDownTimeout( void );
0b4e3aa0 859
0a7de745 860 bool shouldSleepOnClamshellClosed(void );
cb323159 861 bool shouldSleepOnRTCAlarmWake(void );
0a7de745 862 void sendClientClamshellNotification( void );
483a1d10 863
0a7de745
A
864// Inform PMCPU of changes to state like lid, AC vs. battery
865 void informCPUStateChange( uint32_t type, uint32_t value );
b0d623f7 866
0a7de745
A
867 void dispatchPowerEvent( uint32_t event, void * arg0, uint64_t arg1 );
868 void handlePowerNotification( UInt32 msg );
b0d623f7 869
0a7de745 870 IOReturn setPMSetting(const OSSymbol *, OSObject *);
0c530ab8 871
0a7de745
A
872 void startIdleSleepTimer( uint32_t inSeconds );
873 void cancelIdleSleepTimer( void );
874 uint32_t getTimeToIdleSleep( void );
b0d623f7 875
0a7de745
A
876 IOReturn setAggressiveness(
877 unsigned long type,
878 unsigned long value,
879 IOOptionBits options );
b0d623f7 880
0a7de745
A
881 void synchronizeAggressives(
882 queue_head_t * services,
883 const AggressivesRecord * array,
884 int count );
b0d623f7 885
0a7de745
A
886 void broadcastAggressives(
887 const AggressivesRecord * array,
888 int count );
b0d623f7 889
0a7de745 890 IOReturn setPMAssertionUserLevels(IOPMDriverAssertionType);
6d2010ae 891
0a7de745 892 void publishSleepWakeUUID( bool shouldPublish );
0b4c1975 893
0a7de745
A
894 void evaluatePolicy( int stimulus, uint32_t arg = 0 );
895 void requestFullWake( FullWakeReason reason );
896 void willEnterFullWake( void );
6d2010ae 897
0a7de745
A
898 void evaluateAssertions(IOPMDriverAssertionType newAssertions,
899 IOPMDriverAssertionType oldAssertions);
7ddcb079 900
0a7de745 901 void deregisterPMSettingObject( PMSettingObject * pmso );
6d2010ae 902
0a7de745
A
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);
fe8ab488 911
39236c6e 912
0b4c1975 913#if HIBERNATION
0a7de745
A
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 );
0b4c1975 919#endif /* HIBERNATION */
13f56ec4 920
0a7de745
A
921 bool latchDisplayWranglerTickle( bool latch );
922 void setDisplayPowerOn( uint32_t options );
fe8ab488 923
0a7de745
A
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);
cb323159 929 void copySleepPreventersListWithID(OSArray **idleSleepList, OSArray **systemSleepList);
b0d623f7 930#endif /* XNU_KERNEL_PRIVATE */
1c79356b
A
931};
932
b0d623f7 933#ifdef XNU_KERNEL_PRIVATE
0a7de745 934class IORootParent : public IOService
1c79356b 935{
cb323159 936 OSDeclareFinalStructors(IORootParent);
0b4e3aa0 937
b0d623f7 938public:
0a7de745
A
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 );
1c79356b 948};
b0d623f7 949#endif /* XNU_KERNEL_PRIVATE */
1c79356b 950
b0d623f7 951#endif /* _IOKIT_ROOTDOMAIN_H */