]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/pwr_mgt/RootDomain.h
xnu-2050.9.2.tar.gz
[apple/xnu.git] / iokit / IOKit / pwr_mgt / RootDomain.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 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.
8f6c56a5 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.
17 *
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.
8f6c56a5 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>
6d2010ae 33#include <IOKit/IOBufferMemoryDescriptor.h>
b0d623f7
A
34
35#ifdef XNU_KERNEL_PRIVATE
b0d623f7 36struct AggressivesRecord;
6d2010ae
A
37struct IOPMMessageFilterContext;
38struct IOPMActions;
316670eb 39struct IOPMSystemSleepParameters;
6d2010ae
A
40class PMSettingObject;
41class IOPMTimeline;
42class PMEventDetails;
43class PMTraceWorker;
55e303ae 44class IOPMPowerStateQueue;
1c79356b 45class RootDomainUserClient;
6d2010ae
A
46class PMAssertionsTracker;
47#endif
1c79356b 48
0b4c1975
A
49/*!
50 * Types for PM Assertions
51 * For creating, releasing, and getting PM assertion levels.
52 */
53
54/*! IOPMDriverAssertionType
55 * A bitfield describing a set of assertions. May be used to specify which assertions
56 * to set with <link>IOPMrootDomain::createPMAssertion</link>; or to query which
57 * assertions are set with <link>IOPMrootDomain::releasePMAssertion</link>.
58 */
59typedef uint64_t IOPMDriverAssertionType;
60
61/* IOPMDriverAssertionID
62 * Drivers may create PM assertions to request system behavior (keep the system awake,
63 * or keep the display awake). When a driver creates an assertion via
64 * <link>IOPMrootDomain::createPMAssertion</link>, PM returns a handle to
65 * the assertion of type IOPMDriverAssertionID.
66 */
67typedef uint64_t IOPMDriverAssertionID;
68#define kIOPMUndefinedDriverAssertionID 0
69
70/* IOPMDriverAssertionLevel
71 * Possible values for IOPMDriverAssertionLevel are <link>kIOPMDriverAssertionLevelOff</link>
72 * and <link>kIOPMDriverAssertionLevelOn</link>
73 */
74typedef uint32_t IOPMDriverAssertionLevel;
75#define kIOPMDriverAssertionLevelOff 0
76#define kIOPMDriverAssertionLevelOn 255
77
b0d623f7
A
78/*
79 * Flags for get/setSleepSupported()
80 */
1c79356b
A
81enum {
82 kRootDomainSleepNotSupported = 0x00000000,
83 kRootDomainSleepSupported = 0x00000001,
0b4e3aa0 84 kFrameBufferDeepSleepSupported = 0x00000002,
b0d623f7 85 kPCICantSleep = 0x00000004
1c79356b
A
86};
87
2d21ac55
A
88/*
89 *IOPMrootDomain registry property keys
90 */
91#define kRootDomainSupportedFeatures "Supported Features"
92#define kRootDomainSleepReasonKey "Last Sleep Reason"
93#define kRootDomainSleepOptionsKey "Last Sleep Options"
b0d623f7
A
94#define kIOPMRootDomainWakeReasonKey "Wake Reason"
95#define kIOPMRootDomainWakeTypeKey "Wake Type"
4a3eedf9 96#define kIOPMRootDomainPowerStatusKey "Power Status"
2d21ac55
A
97
98/*
99 * Possible sleep reasons found under kRootDomainSleepReasonsKey
100 */
101#define kIOPMClamshellSleepKey "Clamshell Sleep"
102#define kIOPMPowerButtonSleepKey "Power Button Sleep"
103#define kIOPMSoftwareSleepKey "Software Sleep"
104#define kIOPMOSSwitchHibernationKey "OS Switch Sleep"
105#define kIOPMIdleSleepKey "Idle Sleep"
106#define kIOPMLowPowerSleepKey "Low Power Sleep"
107#define kIOPMThermalEmergencySleepKey "Thermal Emergency Sleep"
b0d623f7 108#define kIOPMMaintenanceSleepKey "Maintenance Sleep"
2d21ac55
A
109
110/*
111 * String constants for communication with PM CPU
112 */
113#define kIOPMRootDomainLidCloseCString "LidClose"
114#define kIOPMRootDomainBatPowerCString "BatPower"
0c530ab8 115
b0d623f7
A
116/*
117 * Supported Feature bitfields for IOPMrootDomain::publishFeature()
118 */
e5568f75 119enum {
b0d623f7
A
120 kIOPMSupportedOnAC = (1<<0),
121 kIOPMSupportedOnBatt = (1<<1),
122 kIOPMSupportedOnUPS = (1<<2)
e5568f75 123};
4452a7af 124
b0d623f7
A
125typedef IOReturn (*IOPMSettingControllerCallback)
126 (OSObject *target, const OSSymbol *type,
0c530ab8 127 OSObject *val, uintptr_t refcon);
4452a7af 128
b0d623f7
A
129__BEGIN_DECLS
130IONotifier * registerSleepWakeInterest(
131 IOServiceInterestHandler, void *, void * = 0);
0c530ab8 132
b0d623f7
A
133IONotifier * registerPrioritySleepWakeInterest(
134 IOServiceInterestHandler handler,
135 void * self, void * ref = 0);
0c530ab8 136
b0d623f7 137IOReturn acknowledgeSleepWakeNotification(void * );
0c530ab8 138
b0d623f7
A
139IOReturn vetoSleepWakeNotification(void * PMrefcon);
140__END_DECLS
1c79356b 141
d52fe63f 142#define IOPM_ROOTDOMAIN_REV 2
1c79356b
A
143
144class IOPMrootDomain: public IOService
145{
b0d623f7 146 OSDeclareFinalStructors(IOPMrootDomain)
0b4e3aa0 147
b0d623f7 148public:
0b4e3aa0 149 static IOPMrootDomain * construct( void );
2d21ac55 150
b0d623f7
A
151 virtual bool start( IOService * provider );
152 virtual IOReturn setAggressiveness( unsigned long, unsigned long );
153 virtual IOReturn getAggressiveness( unsigned long, unsigned long * );
2d21ac55 154
b0d623f7
A
155 virtual IOReturn sleepSystem( void );
156 IOReturn sleepSystemOptions( OSDictionary *options );
157
158 virtual IOReturn setProperties( OSObject * );
0b4c1975 159 virtual bool serializeProperties( OSSerialize * s ) const;
4a3eedf9
A
160
161/*! @function systemPowerEventOccurred
162 @abstract Other drivers may inform IOPMrootDomain of system PM events
163 @discussion systemPowerEventOccurred is a richer alternative to receivePowerNotification()
164 Only Apple-owned kexts should have reason to call systemPowerEventOccurred.
165 @param event An OSSymbol describing the type of power event.
166 @param value A 32-bit integer value associated with the event.
167 @param shouldUpdate indicates whether the root domain should send a notification
168 to interested parties. Pass false if you're calling systemPowerEventOccurred
169 several times in succession; and pass true only on the last invocatino.
170 @result kIOReturnSuccess on success */
b0d623f7
A
171
172 IOReturn systemPowerEventOccurred(
173 const OSSymbol *event,
174 uint32_t intValue );
175
176 IOReturn systemPowerEventOccurred(
177 const OSSymbol *event,
178 OSObject *value );
179
180 virtual IOReturn receivePowerNotification( UInt32 msg );
181
182 virtual void setSleepSupported( IOOptionBits flags );
183
184 virtual IOOptionBits getSleepSupported( void );
185
186 void wakeFromDoze( void );
0c530ab8
A
187
188 // KEXT driver announces support of power management feature
b0d623f7
A
189
190 void publishFeature( const char *feature );
0c530ab8
A
191
192 // KEXT driver announces support of power management feature
193 // And specifies power sources with kIOPMSupportedOn{AC/Batt/UPS} bitfield.
194 // Returns a unique uint32_t identifier for later removing support for this
195 // feature.
196 // NULL is acceptable for uniqueFeatureID for kexts without plans to unload.
b0d623f7
A
197
198 void publishFeature( const char *feature,
199 uint32_t supportedWhere,
200 uint32_t *uniqueFeatureID);
0c530ab8
A
201
202 // KEXT driver announces removal of a previously published power management
203 // feature. Pass 'uniqueFeatureID' returned from publishFeature()
0c530ab8 204
b0d623f7 205 IOReturn removePublishedFeature( uint32_t removeFeatureID );
9bccf70c 206
0c530ab8 207/*! @function copyPMSetting
b0d623f7 208 @abstract Copy the current value for a PM setting. Returns an OSNumber or
0c530ab8 209 OSData depending on the setting.
b0d623f7
A
210 @param whichSetting Name of the desired setting.
211 @result OSObject value if valid, NULL otherwise. */
212
213 OSObject * copyPMSetting( OSSymbol *whichSetting );
214
0c530ab8
A
215/*! @function registerPMSettingController
216 @abstract Register for callbacks on changes to certain PM settings.
217 @param settings NULL terminated array of C strings, each string for a PM
218 setting that the caller is interested in and wants to get callbacks for.
219 @param callout C function ptr or member function cast as such.
220 @param target The target of the callback, usually 'this'
221 @param refcon Will be passed to caller in callback; for caller's use.
222 @param handle Caller should keep the OSObject * returned here. If non-NULL,
223 handle will have a retain count of 1 on return. To deregister, pass to
224 unregisterPMSettingController()
225 @result kIOReturnSuccess on success. */
b0d623f7
A
226
227 IOReturn registerPMSettingController(
0c530ab8
A
228 const OSSymbol *settings[],
229 IOPMSettingControllerCallback callout,
230 OSObject *target,
231 uintptr_t refcon,
232 OSObject **handle); // out param
233
234/*! @function registerPMSettingController
235 @abstract Register for callbacks on changes to certain PM settings.
236 @param settings NULL terminated array of C strings, each string for a PM
237 setting that the caller is interested in and wants to get callbacks for.
238 @param supportedPowerSources bitfield indicating which power sources these
239 settings are supported for (kIOPMSupportedOnAC, etc.)
240 @param callout C function ptr or member function cast as such.
241 @param target The target of the callback, usually 'this'
242 @param refcon Will be passed to caller in callback; for caller's use.
243 @param handle Caller should keep the OSObject * returned here. If non-NULL,
244 handle will have a retain count of 1 on return. To deregister, pass to
245 unregisterPMSettingController()
246 @result kIOReturnSuccess on success. */
b0d623f7
A
247
248 IOReturn registerPMSettingController(
0c530ab8
A
249 const OSSymbol *settings[],
250 uint32_t supportedPowerSources,
251 IOPMSettingControllerCallback callout,
252 OSObject *target,
253 uintptr_t refcon,
254 OSObject **handle); // out param
e5568f75 255
b0d623f7
A
256 virtual IONotifier * registerInterest(
257 const OSSymbol * typeOfInterest,
258 IOServiceInterestHandler handler,
259 void * target, void * ref = 0 );
b0d623f7
A
260
261 virtual IOReturn callPlatformFunction(
262 const OSSymbol *functionName,
263 bool waitForFunction,
264 void *param1, void *param2,
265 void *param3, void *param4 );
266
0b4c1975
A
267/*! @function createPMAssertion
268 @abstract Creates an assertion to influence system power behavior.
269 @param whichAssertionBits A bitfield specify the assertion that the caller requests.
270 @param assertionLevel An integer detailing the initial assertion level, kIOPMDriverAssertionLevelOn
271 or kIOPMDriverAssertionLevelOff.
272 @param ownerService A pointer to the caller's IOService class, for tracking.
273 @param ownerDescription A reverse-DNS string describing the caller's identity and reason.
274 @result On success, returns a new assertion of type IOPMDriverAssertionID
275*/
276 IOPMDriverAssertionID createPMAssertion(
277 IOPMDriverAssertionType whichAssertionsBits,
278 IOPMDriverAssertionLevel assertionLevel,
279 IOService *ownerService,
280 const char *ownerDescription);
281
282/* @function setPMAssertionLevel
283 @abstract Modify the level of a pre-existing assertion.
284 @discussion Change the value of a PM assertion to influence system behavior,
285 without undergoing the work required to create or destroy an assertion. Suggested
286 for clients who will assert and de-assert needs for PM behavior several times over
287 their lifespan.
288 @param assertionID An assertion ID previously returned by <link>createPMAssertion</link>
289 @param assertionLevel The new assertion level.
290 @result kIOReturnSuccess if it worked; kIOReturnNotFound or other IOReturn error on failure.
291*/
292 IOReturn setPMAssertionLevel(IOPMDriverAssertionID assertionID, IOPMDriverAssertionLevel assertionLevel);
293
294/*! @function getPMAssertionLevel
295 @absract Returns the active level of the specified assertion(s).
296 @discussion Returns <link>kIOPMDriverAssertionLevelOff</link> or
297 <link>kIOPMDriverAssertionLevelOn</link>. If multiple assertions are specified
298 in the bitfield, only returns <link>kIOPMDriverAssertionLevelOn</link>
299 if all assertions are active.
300 @param whichAssertionBits Bits defining the assertion or assertions the caller is interested in
301 the level of. If in doubt, pass <link>kIOPMDriverAssertionCPUBit</link> as the argument.
302 @result Returns <link>kIOPMDriverAssertionLevelOff</link> or
303 <link>kIOPMDriverAssertionLevelOn</link> indicating the specified assertion's levels, if available.
304 If the assertions aren't supported on this machine, or aren't recognized by the OS, the
305 result is undefined.
306*/
307 IOPMDriverAssertionLevel getPMAssertionLevel(IOPMDriverAssertionType whichAssertionBits);
308
309/*! @function releasePMAssertion
310 @abstract Removes an assertion to influence system power behavior.
311 @result On success, returns a new assertion of type IOPMDriverAssertionID *
312*/
313 IOReturn releasePMAssertion(IOPMDriverAssertionID releaseAssertion);
316670eb 314
b0d623f7
A
315private:
316 virtual IOReturn changePowerStateTo( unsigned long ordinal );
317 virtual IOReturn changePowerStateToPriv( unsigned long ordinal );
318 virtual IOReturn requestPowerDomainState( IOPMPowerFlags, IOPowerConnection *, unsigned long );
319 virtual void powerChangeDone( unsigned long );
320 virtual bool tellChangeDown( unsigned long );
321 virtual bool askChangeDown( unsigned long );
322 virtual void tellChangeUp( unsigned long );
323 virtual void tellNoChangeDown( unsigned long );
324#ifdef XNU_KERNEL_PRIVATE
325 /* Root Domain internals */
326public:
6d2010ae
A
327 void tagPowerPlaneService(
328 IOService * service,
329 IOPMActions * actions );
b0d623f7 330
6d2010ae
A
331 void overrideOurPowerChange(
332 IOService * service,
333 IOPMActions * actions,
334 unsigned long * inOutPowerState,
335 uint32_t * inOutChangeFlags );
0b4c1975 336
6d2010ae 337 void handleOurPowerChangeStart(
b0d623f7 338 IOService * service,
6d2010ae
A
339 IOPMActions * actions,
340 uint32_t powerState,
341 uint32_t * inOutChangeFlags );
342
343 void handleOurPowerChangeDone(
344 IOService * service,
345 IOPMActions * actions,
346 uint32_t powerState,
347 uint32_t changeFlags );
348
349 void overridePowerChangeForUIService(
350 IOService * service,
351 IOPMActions * actions,
352 unsigned long * inOutPowerState,
353 uint32_t * inOutChangeFlags );
354
355 void handleActivityTickleForDisplayWrangler(
356 IOService * service,
357 IOPMActions * actions );
358
359 bool shouldDelayChildNotification(
360 IOService * service );
361
362 void handlePowerChangeStartForPCIDevice(
363 IOService * service,
364 IOPMActions * actions,
365 uint32_t powerState,
366 uint32_t * inOutChangeFlags );
367
368 void handlePowerChangeDoneForPCIDevice(
369 IOService * service,
370 IOPMActions * actions,
371 uint32_t powerState,
b0d623f7
A
372 uint32_t changeFlags );
373
6d2010ae
A
374 void askChangeDownDone(
375 IOPMPowerChangeFlags * inOutChangeFlags,
376 bool * cancel );
377
378 void handlePublishSleepWakeUUID(
379 bool shouldPublish);
380
381 void handleQueueSleepWakeUUID(
382 OSObject *obj);
383
316670eb
A
384 void handleSuspendPMNotificationClient(
385 uint32_t pid, bool doSuspend);
386
387 IOReturn setMaintenanceWakeCalendar(
388 const IOPMCalendarStruct * calendar );
b0d623f7
A
389
390 // Handle callbacks from IOService::systemWillShutdown()
6d2010ae 391 void acknowledgeSystemWillShutdown( IOService * from );
2d21ac55 392
b0d623f7 393 // Handle platform halt and restart notifications
6d2010ae
A
394 void handlePlatformHaltRestart( UInt32 pe_type );
395
396 IOReturn shutdownSystem( void );
397 IOReturn restartSystem( void );
398 void handleSleepTimerExpiration( void );
2d21ac55 399
0b4c1975
A
400 bool activitySinceSleep(void);
401 bool abortHibernation(void);
b0d623f7
A
402
403 IOReturn joinAggressiveness( IOService * service );
404 void handleAggressivesRequests( void );
405
406 void tracePoint( uint8_t point );
6d2010ae
A
407 void tracePoint( uint8_t point, uint8_t data );
408 void traceDetail( uint32_t data32 );
409
410 bool systemMessageFilter(
411 void * object, void * arg1, void * arg2, void * arg3 );
412
316670eb
A
413 void updatePreventIdleSleepList(
414 IOService * service, bool addNotRemove );
415 void updatePreventSystemSleepList(
416 IOService * service, bool addNotRemove );
417
7ddcb079
A
418 void publishPMSetting(
419 const OSSymbol * feature, uint32_t where, uint32_t * featureID );
420
6d2010ae
A
421/*! @function recordPMEvent
422 @abstract Logs IOService PM event timing.
423 @discussion Should only be called from IOServicePM. Should not be exported.
424 @result kIOReturn on success.
425*/
426 IOReturn recordPMEvent( PMEventDetails *details );
427 IOReturn recordAndReleasePMEvent( PMEventDetails *details );
428 IOReturn recordPMEventGated( PMEventDetails *details );
429 IOReturn recordAndReleasePMEventGated( PMEventDetails *details );
430
431 void pmStatsRecordEvent(
432 int eventIndex,
433 AbsoluteTime timestamp);
434
435 void pmStatsRecordApplicationResponse(
436 const OSSymbol *response,
437 const char *name,
438 int messageType,
439 uint32_t delay_ms,
440 int app_pid);
441
316670eb
A
442
443/*! @function suspendPMNotificationsForPID
444 @abstract kernel process management calls this to disable sleep/wake notifications
445 when a process is suspended.
446 @param pid the process ID
447 @param doSuspend true suspends the notifications; false enables them
448*/
449 void suspendPMNotificationsForPID( uint32_t pid, bool doSuspend);
450
451/*! @function pmNotificationIsSuspended
452 @abstract returns true if PM notifications have been suspended
453 @param pid the process ID
454 @result true if the process has been suspended
455*/
456 bool pmNotificationIsSuspended( uint32_t pid );
457
458
6d2010ae
A
459#if HIBERNATION
460 bool getHibernateSettings(
461 uint32_t * hibernateMode,
462 uint32_t * hibernateFreeRatio,
463 uint32_t * hibernateFreeTime );
464#endif
b0d623f7 465
1c79356b 466private:
b0d623f7 467 friend class PMSettingObject;
0b4c1975 468 friend class RootDomainUserClient;
6d2010ae
A
469 friend class PMAssertionsTracker;
470
471 static IOReturn sysPowerDownHandler( void * target, void * refCon,
472 UInt32 messageType, IOService * service,
473 void * messageArgument, vm_size_t argSize );
474
475 static IOReturn displayWranglerNotification( void * target, void * refCon,
476 UInt32 messageType, IOService * service,
477 void * messageArgument, vm_size_t argSize );
478
479 static IOReturn rootBusyStateChangeHandler( void * target, void * refCon,
480 UInt32 messageType, IOService * service,
481 void * messageArgument, vm_size_t argSize );
482
483 static bool displayWranglerMatchPublished( void * target, void * refCon,
484 IOService * newService,
485 IONotifier * notifier);
486
487 static bool batteryPublished( void * target, void * refCon,
488 IOService * resourceService,
489 IONotifier * notifier);
1c79356b 490
b0d623f7 491 IOService * wrangler;
0c530ab8 492
b0d623f7
A
493 IOLock *featuresDictLock; // guards supportedFeatures
494 IOPMPowerStateQueue *pmPowerStateQueue;
495
496 OSArray *allowedPMSettings;
7ddcb079 497 OSArray *noPublishPMSettings;
b0d623f7 498 PMTraceWorker *pmTracer;
0b4c1975 499 PMAssertionsTracker *pmAssertions;
0c530ab8 500
b0d623f7 501 // Settings controller info
6d2010ae 502 IOLock *settingsCtrlLock;
b0d623f7
A
503 OSDictionary *settingsCallbacks;
504 OSDictionary *fPMSettingsDict;
505
506 IONotifier *_batteryPublishNotifier;
507 IONotifier *_displayWranglerNotifier;
508
509 // Statistics
6d2010ae
A
510 const OSSymbol *_statsNameKey;
511 const OSSymbol *_statsPIDKey;
512 const OSSymbol *_statsTimeMSKey;
513 const OSSymbol *_statsResponseTypeKey;
514 const OSSymbol *_statsMessageTypeKey;
b0d623f7
A
515
516 OSString *queuedSleepWakeUUIDString;
b0d623f7
A
517 OSArray *pmStatsAppResponses;
518
6d2010ae 519 bool uuidPublished;
b0d623f7
A
520
521 // Pref: idle time before idle sleep
522 unsigned long sleepSlider;
523 unsigned long idleSeconds;
524 uint64_t autoWakeStart;
525 uint64_t autoWakeEnd;
0c530ab8
A
526
527 // Difference between sleepSlider and longestNonSleepSlider
b0d623f7 528 unsigned long extraSleepDelay;
0c530ab8
A
529
530 // Used to wait between say display idle and system idle
6d2010ae 531 thread_call_t extraSleepTimer;
b0d623f7
A
532 thread_call_t diskSyncCalloutEntry;
533
6d2010ae
A
534 // IOPMActions parameter encoding
535 enum {
536 kPMActionsFlagIsDisplayWrangler = 0x00000001,
537 kPMActionsFlagIsGraphicsDevice = 0x00000002,
538 kPMActionsFlagIsAudioDevice = 0x00000004,
539 kPMActionsFlagLimitPower = 0x00000008,
540 kPMActionsPCIBitNumberMask = 0x000000ff
541 };
542
543 // Track system capabilities.
544 uint32_t _desiredCapability;
545 uint32_t _currentCapability;
546 uint32_t _pendingCapability;
547 uint32_t _highestCapability;
548 OSSet * _joinedCapabilityClients;
549 uint32_t _systemStateGeneration;
550
551 // Type of clients that can receive system messages.
552 enum {
553 kSystemMessageClientConfigd = 0x01,
554 kSystemMessageClientApp = 0x02,
555 kSystemMessageClientUser = 0x03,
556 kSystemMessageClientKernel = 0x04,
557 kSystemMessageClientAll = 0x07
558 };
559 uint32_t _systemMessageClientMask;
560
561 // Power state and capability change transitions.
562 enum {
563 kSystemTransitionNone = 0,
564 kSystemTransitionSleep = 1,
565 kSystemTransitionWake = 2,
566 kSystemTransitionCapability = 3,
567 kSystemTransitionNewCapClient = 4
568 } _systemTransitionType;
b0d623f7
A
569
570 unsigned int systemBooting :1;
571 unsigned int systemShutdown :1;
6d2010ae 572 unsigned int systemDarkWake :1;
b0d623f7 573 unsigned int clamshellExists :1;
6d2010ae
A
574 unsigned int clamshellClosed :1;
575 unsigned int clamshellDisabled :1;
b0d623f7 576 unsigned int desktopMode :1;
6d2010ae 577 unsigned int acAdaptorConnected :1;
b0d623f7 578
b0d623f7
A
579 unsigned int idleSleepTimerPending :1;
580 unsigned int userDisabledAllSleep :1;
6d2010ae 581 unsigned int ignoreTellChangeDown :1;
b0d623f7 582 unsigned int wranglerAsleep :1;
6d2010ae
A
583 unsigned int wranglerTickled :1;
584 unsigned int wranglerSleepIgnored :1;
585 unsigned int graphicsSuppressed :1;
316670eb 586 unsigned int darkWakeThermalAlarm :1;
6d2010ae
A
587
588 unsigned int capabilityLoss :1;
589 unsigned int pciCantSleepFlag :1;
590 unsigned int pciCantSleepValid :1;
591 unsigned int logWranglerTickle :1;
592 unsigned int logGraphicsClamp :1;
593 unsigned int darkWakeToSleepASAP :1;
594 unsigned int darkWakeMaintenance :1;
7ddcb079 595 unsigned int darkWakeSleepService :1;
b0d623f7 596
13f56ec4 597 unsigned int darkWakePostTickle :1;
0b4c1975
A
598 unsigned int sleepTimerMaintenance :1;
599 unsigned int lowBatteryCondition :1;
316670eb 600 unsigned int darkWakeThermalEmergency:1;
0b4c1975
A
601 unsigned int hibernateDisabled :1;
602 unsigned int hibernateNoDefeat :1;
6d2010ae 603 unsigned int rejectWranglerTickle :1;
13f56ec4 604 unsigned int wranglerTickleLatched :1;
0b4c1975
A
605
606 uint32_t hibernateMode;
607 uint32_t userActivityCount;
608 uint32_t userActivityAtSleep;
609 uint32_t lastSleepReason;
13f56ec4 610 uint32_t hibernateAborted;
0b4c1975 611
b0d623f7
A
612 // Info for communicating system state changes to PMCPU
613 int32_t idxPMCPUClamshell;
614 int32_t idxPMCPULimitedPower;
615
616 IOOptionBits platformSleepSupport;
6d2010ae 617 uint32_t _debugWakeSeconds;
7ddcb079 618 uint32_t _lastDebugWakeSeconds;
b0d623f7
A
619
620 queue_head_t aggressivesQueue;
621 thread_call_t aggressivesThreadCall;
622 OSData * aggressivesData;
623
624 AbsoluteTime wranglerSleepTime;
6d2010ae
A
625 AbsoluteTime systemWakeTime;
626
b0d623f7
A
627 // PCI top-level PM trace
628 IOService * pciHostBridgeDevice;
6d2010ae 629 IOService * pciHostBridgeDriver;
b0d623f7 630
6d2010ae 631 IONotifier * systemCapabilityNotifier;
2d21ac55 632
6d2010ae 633 IOPMTimeline *timeline;
316670eb
A
634
635 typedef struct {
636 uint32_t pid;
637 uint32_t refcount;
638 } PMNotifySuspendedStruct;
639
640 uint32_t pmSuspendedCapacity;
641 uint32_t pmSuspendedSize;
642 PMNotifySuspendedStruct *pmSuspendedPIDS;
643
644 OSSet * preventIdleSleepList;
645 OSSet * preventSystemSleepList;
646
647#if HIBERNATION
648 clock_sec_t _standbyTimerResetSeconds;
649#endif
0b4e3aa0 650
316670eb 651 int findSuspendedPID(uint32_t pid, uint32_t *outRefCount);
7ddcb079 652
6d2010ae
A
653 // IOPMrootDomain internal sleep call
654 IOReturn privateSleepSystem( uint32_t sleepReason );
655 void reportUserInput( void );
656 bool checkSystemCanSleep( IOOptionBits options = 0 );
13f56ec4 657 bool checkSystemCanSustainFullWake( void );
0b4e3aa0 658
6d2010ae
A
659 void adjustPowerState( bool sleepASAP = false );
660 void setQuickSpinDownTimeout( void );
661 void restoreUserSpinDownTimeout( void );
0b4e3aa0 662
6d2010ae
A
663 bool shouldSleepOnClamshellClosed(void );
664 void sendClientClamshellNotification( void );
483a1d10 665
2d21ac55 666 // Inform PMCPU of changes to state like lid, AC vs. battery
6d2010ae 667 void informCPUStateChange( uint32_t type, uint32_t value );
b0d623f7 668
6d2010ae
A
669 void dispatchPowerEvent( uint32_t event, void * arg0, uint64_t arg1 );
670 void handlePowerNotification( UInt32 msg );
b0d623f7 671
6d2010ae 672 IOReturn setPMSetting(const OSSymbol *, OSObject *);
0c530ab8 673
6d2010ae
A
674 void startIdleSleepTimer( uint32_t inSeconds );
675 void cancelIdleSleepTimer( void );
b0d623f7
A
676
677 IOReturn setAggressiveness(
678 unsigned long type,
679 unsigned long value,
680 IOOptionBits options );
681
682 void synchronizeAggressives(
683 queue_head_t * services,
684 const AggressivesRecord * array,
685 int count );
686
687 void broadcastAggressives(
688 const AggressivesRecord * array,
689 int count );
690
6d2010ae
A
691 // getPMTraceMemoryDescriptor should only be called by our friend RootDomainUserClient
692 IOMemoryDescriptor *getPMTraceMemoryDescriptor(void);
2d21ac55 693
0b4c1975 694 IOReturn setPMAssertionUserLevels(IOPMDriverAssertionType);
6d2010ae 695
0b4c1975
A
696 void publishSleepWakeUUID( bool shouldPublish );
697
6d2010ae
A
698 void evaluatePolicy( int stimulus, uint32_t arg = 0 );
699
7ddcb079
A
700 void evaluateAssertions(IOPMDriverAssertionType newAssertions,
701 IOPMDriverAssertionType oldAssertions);
702
6d2010ae
A
703 void deregisterPMSettingObject( PMSettingObject * pmso );
704
0b4c1975
A
705#if HIBERNATION
706 bool getSleepOption( const char * key, uint32_t * option );
316670eb 707 bool evaluateSystemSleepPolicy( IOPMSystemSleepParameters * p, int sleepPhase );
0b4c1975
A
708 void evaluateSystemSleepPolicyEarly( void );
709 void evaluateSystemSleepPolicyFinal( void );
710#endif /* HIBERNATION */
13f56ec4
A
711
712 bool latchDisplayWranglerTickle( bool latch );
b0d623f7 713#endif /* XNU_KERNEL_PRIVATE */
1c79356b
A
714};
715
b0d623f7 716#ifdef XNU_KERNEL_PRIVATE
1c79356b
A
717class IORootParent: public IOService
718{
b0d623f7 719 OSDeclareFinalStructors(IORootParent)
0b4e3aa0 720
b0d623f7 721public:
6d2010ae
A
722 static void initialize( void );
723 virtual OSObject * copyProperty( const char * aKey ) const;
b0d623f7
A
724 bool start( IOService * nub );
725 void shutDownSystem( void );
726 void restartSystem( void );
727 void sleepSystem( void );
728 void dozeSystem( void );
729 void sleepToDoze( void );
730 void wakeSystem( void );
1c79356b 731};
b0d623f7 732#endif /* XNU_KERNEL_PRIVATE */
1c79356b 733
b0d623f7 734#endif /* _IOKIT_ROOTDOMAIN_H */