]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/pwr_mgt/RootDomain.h
xnu-3789.60.24.tar.gz
[apple/xnu.git] / iokit / IOKit / pwr_mgt / RootDomain.h
CommitLineData
1c79356b 1/*
39037602 2 * Copyright (c) 1998-2016 Apple Inc. All rights reserved.
1c79356b 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>
fe8ab488
A
33#include <IOKit/IOBufferMemoryDescriptor.h>
34#include <sys/vnode.h>
b0d623f7
A
35
36#ifdef XNU_KERNEL_PRIVATE
b0d623f7 37struct AggressivesRecord;
6d2010ae
A
38struct IOPMMessageFilterContext;
39struct IOPMActions;
316670eb 40struct IOPMSystemSleepParameters;
6d2010ae 41class PMSettingObject;
6d2010ae 42class PMTraceWorker;
55e303ae 43class IOPMPowerStateQueue;
1c79356b 44class RootDomainUserClient;
6d2010ae 45class PMAssertionsTracker;
fe8ab488
A
46
47#define OBFUSCATE(x) \
48 (((((uintptr_t)(x)) >= VM_MIN_KERNEL_AND_KEXT_ADDRESS) && (((uintptr_t)(x)) < VM_MAX_KERNEL_ADDRESS)) ? \
49 ((void *)(VM_KERNEL_ADDRPERM(x))) : (void *)(x))
50
6d2010ae 51#endif
1c79356b 52
0b4c1975
A
53/*!
54 * Types for PM Assertions
55 * For creating, releasing, and getting PM assertion levels.
56 */
fe8ab488 57
0b4c1975
A
58/*! IOPMDriverAssertionType
59 * A bitfield describing a set of assertions. May be used to specify which assertions
fe8ab488 60 * to set with <link>IOPMrootDomain::createPMAssertion</link>; or to query which
0b4c1975
A
61 * assertions are set with <link>IOPMrootDomain::releasePMAssertion</link>.
62 */
63typedef uint64_t IOPMDriverAssertionType;
64
65/* IOPMDriverAssertionID
66 * Drivers may create PM assertions to request system behavior (keep the system awake,
fe8ab488
A
67 * or keep the display awake). When a driver creates an assertion via
68 * <link>IOPMrootDomain::createPMAssertion</link>, PM returns a handle to
0b4c1975
A
69 * the assertion of type IOPMDriverAssertionID.
70 */
71typedef uint64_t IOPMDriverAssertionID;
72#define kIOPMUndefinedDriverAssertionID 0
73
74/* IOPMDriverAssertionLevel
75 * Possible values for IOPMDriverAssertionLevel are <link>kIOPMDriverAssertionLevelOff</link>
76 * and <link>kIOPMDriverAssertionLevelOn</link>
77 */
78typedef uint32_t IOPMDriverAssertionLevel;
79#define kIOPMDriverAssertionLevelOff 0
80#define kIOPMDriverAssertionLevelOn 255
81
b0d623f7
A
82/*
83 * Flags for get/setSleepSupported()
84 */
1c79356b 85enum {
fe8ab488
A
86 kRootDomainSleepNotSupported = 0x00000000,
87 kRootDomainSleepSupported = 0x00000001,
88 kFrameBufferDeepSleepSupported = 0x00000002,
b0d623f7 89 kPCICantSleep = 0x00000004
1c79356b
A
90};
91
fe8ab488 92/*
2d21ac55
A
93 *IOPMrootDomain registry property keys
94 */
95#define kRootDomainSupportedFeatures "Supported Features"
96#define kRootDomainSleepReasonKey "Last Sleep Reason"
97#define kRootDomainSleepOptionsKey "Last Sleep Options"
b0d623f7
A
98#define kIOPMRootDomainWakeReasonKey "Wake Reason"
99#define kIOPMRootDomainWakeTypeKey "Wake Type"
4a3eedf9 100#define kIOPMRootDomainPowerStatusKey "Power Status"
2d21ac55
A
101
102/*
103 * Possible sleep reasons found under kRootDomainSleepReasonsKey
104 */
105#define kIOPMClamshellSleepKey "Clamshell Sleep"
106#define kIOPMPowerButtonSleepKey "Power Button Sleep"
107#define kIOPMSoftwareSleepKey "Software Sleep"
108#define kIOPMOSSwitchHibernationKey "OS Switch Sleep"
109#define kIOPMIdleSleepKey "Idle Sleep"
110#define kIOPMLowPowerSleepKey "Low Power Sleep"
111#define kIOPMThermalEmergencySleepKey "Thermal Emergency Sleep"
b0d623f7 112#define kIOPMMaintenanceSleepKey "Maintenance Sleep"
2d21ac55
A
113
114/*
115 * String constants for communication with PM CPU
116 */
117#define kIOPMRootDomainLidCloseCString "LidClose"
118#define kIOPMRootDomainBatPowerCString "BatPower"
0c530ab8 119
b0d623f7
A
120/*
121 * Supported Feature bitfields for IOPMrootDomain::publishFeature()
122 */
e5568f75 123enum {
b0d623f7
A
124 kIOPMSupportedOnAC = (1<<0),
125 kIOPMSupportedOnBatt = (1<<1),
126 kIOPMSupportedOnUPS = (1<<2)
e5568f75 127};
4452a7af 128
b0d623f7
A
129typedef IOReturn (*IOPMSettingControllerCallback)
130 (OSObject *target, const OSSymbol *type,
0c530ab8 131 OSObject *val, uintptr_t refcon);
4452a7af 132
b0d623f7
A
133__BEGIN_DECLS
134IONotifier * registerSleepWakeInterest(
135 IOServiceInterestHandler, void *, void * = 0);
fe8ab488 136
b0d623f7 137IONotifier * registerPrioritySleepWakeInterest(
fe8ab488 138 IOServiceInterestHandler handler,
b0d623f7 139 void * self, void * ref = 0);
0c530ab8 140
b0d623f7 141IOReturn acknowledgeSleepWakeNotification(void * );
0c530ab8 142
b0d623f7
A
143IOReturn vetoSleepWakeNotification(void * PMrefcon);
144__END_DECLS
1c79356b 145
fe8ab488 146#define IOPM_ROOTDOMAIN_REV 2
1c79356b
A
147
148class IOPMrootDomain: public IOService
149{
b0d623f7 150 OSDeclareFinalStructors(IOPMrootDomain)
0b4e3aa0 151
b0d623f7 152public:
0b4e3aa0 153 static IOPMrootDomain * construct( void );
2d21ac55 154
3e170ce0
A
155 virtual bool start( IOService * provider ) APPLE_KEXT_OVERRIDE;
156 virtual IOReturn setAggressiveness( unsigned long, unsigned long ) APPLE_KEXT_OVERRIDE;
157 virtual IOReturn getAggressiveness( unsigned long, unsigned long * ) APPLE_KEXT_OVERRIDE;
2d21ac55 158
b0d623f7
A
159 virtual IOReturn sleepSystem( void );
160 IOReturn sleepSystemOptions( OSDictionary *options );
161
3e170ce0
A
162 virtual IOReturn setProperties( OSObject * ) APPLE_KEXT_OVERRIDE;
163 virtual bool serializeProperties( OSSerialize * s ) const APPLE_KEXT_OVERRIDE;
164 virtual OSObject * copyProperty( const char * aKey ) const APPLE_KEXT_OVERRIDE;
4a3eedf9
A
165
166/*! @function systemPowerEventOccurred
167 @abstract Other drivers may inform IOPMrootDomain of system PM events
168 @discussion systemPowerEventOccurred is a richer alternative to receivePowerNotification()
169 Only Apple-owned kexts should have reason to call systemPowerEventOccurred.
170 @param event An OSSymbol describing the type of power event.
39037602 171 @param intValue A 32-bit integer value associated with the event.
4a3eedf9 172 @result kIOReturnSuccess on success */
b0d623f7
A
173
174 IOReturn systemPowerEventOccurred(
fe8ab488 175 const OSSymbol *event,
b0d623f7
A
176 uint32_t intValue );
177
178 IOReturn systemPowerEventOccurred(
fe8ab488 179 const OSSymbol *event,
b0d623f7
A
180 OSObject *value );
181
fe8ab488
A
182#ifdef XNU_KERNEL_PRIVATE // Hide doc from public headers
183/*! @function claimSystemWakeEvent
184 @abstract Apple-internal SPI to describe system wake events.
185 @discussion IOKit drivers may call claimSystemWakeEvent() during system wakeup to
186 provide human readable debug information describing the event(s) that
187 caused the system to wake.
188
189 - Drivers should call claimSystemWakeEvent before completing
190 their setPowerState() acknowledgement. IOPMrootDomain stops
191 collecting wake events when driver wake is complete.
192
193 - It is only appropriate to claim a wake event when the driver
194 can positively identify its hardware has generated an event
195 that can wake the system.
196
197 - This call tracks wake events from a non-S0 state (S0i, S3, S4) into S0.
198 - This call does not track wake events from DarkWake(S0) to FullWake(S0).
199
200 Examples:
201 (reason = "WiFi.TCPData",
202 details = "TCPKeepAlive packet arrived from IP 16.2.1.1")
203 (reason = "WiFi.ScanOffload",
204 details = "WiFi station 'AppleWiFi' signal dropped below threshold")
205 (reason = "Enet.LinkToggle",
206 details = "Ethernet attached")
207
208 @param device The device/nub that is associated with the wake event.
209
210 @param flags Pass kIOPMWakeEventSource if the device is the source
211 of the wake event. Pass zero if the device is forwarding or
212 aggregating wake events from multiple sources, e.g. an USB or
213 Thunderbolt host controller.
214
215 @param reason Caller should pass a human readable C string describing the
216 wake reason. Please use a string from the list below, or create
217 your own string matching this format:
218 [Hardware].[Event]
219 WiFi.MagicPacket
220 WiFi.ScanOffload
221 WiFi.mDNSConflict
222 WiFi.mDNSService
223 WiFi.TCPData
224 WiFi.TCPTimeout
225 WiFi.FirmwareCrash
226 Enet.MagicPacket
227 Enet.mDNSConflict
228 Enet.mDNSService
229 Enet.TCPData
230 Enet.TCPTimeout
231 Enet.Service
232 Enet.LinkToggle
233 Enet.ConflictResolution
234 Enet.PatternMatch
235 Enet.Timer
236 Enet.LinkUpTimeout
237 Enet.LinkDown
238 USB.DeviceAttach
239 USB.DeviceDetach
240
241 @param details Optional details further describing the wake event.
242 Please pass an OSString defining the event.
243 */
244#endif
245 void claimSystemWakeEvent( IOService *device,
246 IOOptionBits flags,
247 const char *reason,
248 OSObject *details = 0 );
249
b0d623f7
A
250 virtual IOReturn receivePowerNotification( UInt32 msg );
251
252 virtual void setSleepSupported( IOOptionBits flags );
253
254 virtual IOOptionBits getSleepSupported( void );
255
256 void wakeFromDoze( void );
0c530ab8
A
257
258 // KEXT driver announces support of power management feature
b0d623f7
A
259
260 void publishFeature( const char *feature );
fe8ab488 261
0c530ab8
A
262 // KEXT driver announces support of power management feature
263 // And specifies power sources with kIOPMSupportedOn{AC/Batt/UPS} bitfield.
264 // Returns a unique uint32_t identifier for later removing support for this
fe8ab488 265 // feature.
0c530ab8 266 // NULL is acceptable for uniqueFeatureID for kexts without plans to unload.
b0d623f7 267
fe8ab488 268 void publishFeature( const char *feature,
b0d623f7
A
269 uint32_t supportedWhere,
270 uint32_t *uniqueFeatureID);
0c530ab8 271
fe8ab488 272 // KEXT driver announces removal of a previously published power management
0c530ab8 273 // feature. Pass 'uniqueFeatureID' returned from publishFeature()
0c530ab8 274
b0d623f7 275 IOReturn removePublishedFeature( uint32_t removeFeatureID );
9bccf70c 276
0c530ab8 277/*! @function copyPMSetting
b0d623f7 278 @abstract Copy the current value for a PM setting. Returns an OSNumber or
0c530ab8 279 OSData depending on the setting.
b0d623f7
A
280 @param whichSetting Name of the desired setting.
281 @result OSObject value if valid, NULL otherwise. */
282
283 OSObject * copyPMSetting( OSSymbol *whichSetting );
284
0c530ab8
A
285/*! @function registerPMSettingController
286 @abstract Register for callbacks on changes to certain PM settings.
fe8ab488
A
287 @param settings NULL terminated array of C strings, each string for a PM
288 setting that the caller is interested in and wants to get callbacks for.
0c530ab8
A
289 @param callout C function ptr or member function cast as such.
290 @param target The target of the callback, usually 'this'
291 @param refcon Will be passed to caller in callback; for caller's use.
292 @param handle Caller should keep the OSObject * returned here. If non-NULL,
293 handle will have a retain count of 1 on return. To deregister, pass to
294 unregisterPMSettingController()
295 @result kIOReturnSuccess on success. */
b0d623f7
A
296
297 IOReturn registerPMSettingController(
0c530ab8
A
298 const OSSymbol *settings[],
299 IOPMSettingControllerCallback callout,
300 OSObject *target,
301 uintptr_t refcon,
302 OSObject **handle); // out param
303
304/*! @function registerPMSettingController
305 @abstract Register for callbacks on changes to certain PM settings.
fe8ab488
A
306 @param settings NULL terminated array of C strings, each string for a PM
307 setting that the caller is interested in and wants to get callbacks for.
0c530ab8
A
308 @param supportedPowerSources bitfield indicating which power sources these
309 settings are supported for (kIOPMSupportedOnAC, etc.)
310 @param callout C function ptr or member function cast as such.
311 @param target The target of the callback, usually 'this'
312 @param refcon Will be passed to caller in callback; for caller's use.
313 @param handle Caller should keep the OSObject * returned here. If non-NULL,
314 handle will have a retain count of 1 on return. To deregister, pass to
315 unregisterPMSettingController()
316 @result kIOReturnSuccess on success. */
b0d623f7
A
317
318 IOReturn registerPMSettingController(
0c530ab8
A
319 const OSSymbol *settings[],
320 uint32_t supportedPowerSources,
321 IOPMSettingControllerCallback callout,
322 OSObject *target,
323 uintptr_t refcon,
324 OSObject **handle); // out param
e5568f75 325
b0d623f7
A
326 virtual IONotifier * registerInterest(
327 const OSSymbol * typeOfInterest,
328 IOServiceInterestHandler handler,
3e170ce0 329 void * target, void * ref = 0 ) APPLE_KEXT_OVERRIDE;
b0d623f7
A
330
331 virtual IOReturn callPlatformFunction(
332 const OSSymbol *functionName,
333 bool waitForFunction,
334 void *param1, void *param2,
3e170ce0 335 void *param3, void *param4 ) APPLE_KEXT_OVERRIDE;
b0d623f7 336
0b4c1975
A
337/*! @function createPMAssertion
338 @abstract Creates an assertion to influence system power behavior.
39037602 339 @param whichAssertionsBits A bitfield specify the assertion that the caller requests.
0b4c1975
A
340 @param assertionLevel An integer detailing the initial assertion level, kIOPMDriverAssertionLevelOn
341 or kIOPMDriverAssertionLevelOff.
342 @param ownerService A pointer to the caller's IOService class, for tracking.
343 @param ownerDescription A reverse-DNS string describing the caller's identity and reason.
344 @result On success, returns a new assertion of type IOPMDriverAssertionID
345*/
346 IOPMDriverAssertionID createPMAssertion(
347 IOPMDriverAssertionType whichAssertionsBits,
348 IOPMDriverAssertionLevel assertionLevel,
349 IOService *ownerService,
350 const char *ownerDescription);
351
352/* @function setPMAssertionLevel
353 @abstract Modify the level of a pre-existing assertion.
fe8ab488 354 @discussion Change the value of a PM assertion to influence system behavior,
0b4c1975
A
355 without undergoing the work required to create or destroy an assertion. Suggested
356 for clients who will assert and de-assert needs for PM behavior several times over
357 their lifespan.
358 @param assertionID An assertion ID previously returned by <link>createPMAssertion</link>
359 @param assertionLevel The new assertion level.
360 @result kIOReturnSuccess if it worked; kIOReturnNotFound or other IOReturn error on failure.
361*/
362 IOReturn setPMAssertionLevel(IOPMDriverAssertionID assertionID, IOPMDriverAssertionLevel assertionLevel);
363
364/*! @function getPMAssertionLevel
365 @absract Returns the active level of the specified assertion(s).
fe8ab488 366 @discussion Returns <link>kIOPMDriverAssertionLevelOff</link> or
0b4c1975
A
367 <link>kIOPMDriverAssertionLevelOn</link>. If multiple assertions are specified
368 in the bitfield, only returns <link>kIOPMDriverAssertionLevelOn</link>
369 if all assertions are active.
370 @param whichAssertionBits Bits defining the assertion or assertions the caller is interested in
371 the level of. If in doubt, pass <link>kIOPMDriverAssertionCPUBit</link> as the argument.
fe8ab488 372 @result Returns <link>kIOPMDriverAssertionLevelOff</link> or
0b4c1975
A
373 <link>kIOPMDriverAssertionLevelOn</link> indicating the specified assertion's levels, if available.
374 If the assertions aren't supported on this machine, or aren't recognized by the OS, the
375 result is undefined.
376*/
377 IOPMDriverAssertionLevel getPMAssertionLevel(IOPMDriverAssertionType whichAssertionBits);
378
379/*! @function releasePMAssertion
380 @abstract Removes an assertion to influence system power behavior.
381 @result On success, returns a new assertion of type IOPMDriverAssertionID *
382*/
383 IOReturn releasePMAssertion(IOPMDriverAssertionID releaseAssertion);
39236c6e 384
fe8ab488
A
385/*! @function restartWithStackshot
386 @abstract Take a stackshot of the system and restart the system.
387 @result Return kIOReturnSuccess if it work, kIOReturnError if the service is not available.
388*/
389 IOReturn restartWithStackshot();
390
b0d623f7 391private:
3e170ce0 392 virtual IOReturn changePowerStateTo( unsigned long ordinal ) APPLE_KEXT_COMPATIBILITY_OVERRIDE;
b0d623f7 393 virtual IOReturn changePowerStateToPriv( unsigned long ordinal );
3e170ce0
A
394 virtual IOReturn requestPowerDomainState( IOPMPowerFlags, IOPowerConnection *, unsigned long ) APPLE_KEXT_OVERRIDE;
395 virtual void powerChangeDone( unsigned long ) APPLE_KEXT_OVERRIDE;
396 virtual bool tellChangeDown( unsigned long ) APPLE_KEXT_OVERRIDE;
397 virtual bool askChangeDown( unsigned long ) APPLE_KEXT_OVERRIDE;
398 virtual void tellChangeUp( unsigned long ) APPLE_KEXT_OVERRIDE;
399 virtual void tellNoChangeDown( unsigned long ) APPLE_KEXT_OVERRIDE;
39236c6e
A
400 virtual IOReturn configureReport(IOReportChannelList *channels,
401 IOReportConfigureAction action,
402 void *result,
3e170ce0 403 void *destination) APPLE_KEXT_OVERRIDE;
39236c6e
A
404 virtual IOReturn updateReport(IOReportChannelList *channels,
405 IOReportUpdateAction action,
406 void *result,
3e170ce0
A
407 void *destination) APPLE_KEXT_OVERRIDE;
408
409 void configureReportGated(uint64_t channel_id,
410 uint64_t action,
411 void *result);
412 IOReturn updateReportGated(uint64_t ch_id,
413 void *result,
414 IOBufferMemoryDescriptor *dest);
39236c6e 415
b0d623f7
A
416#ifdef XNU_KERNEL_PRIVATE
417 /* Root Domain internals */
418public:
6d2010ae
A
419 void tagPowerPlaneService(
420 IOService * service,
421 IOPMActions * actions );
b0d623f7 422
6d2010ae 423 void overrideOurPowerChange(
39236c6e
A
424 IOService * service,
425 IOPMActions * actions,
426 IOPMPowerStateIndex * inOutPowerState,
427 IOPMPowerChangeFlags * inOutChangeFlags,
428 IOPMRequestTag requestTag );
0b4c1975 429
6d2010ae 430 void handleOurPowerChangeStart(
39236c6e
A
431 IOService * service,
432 IOPMActions * actions,
433 IOPMPowerStateIndex powerState,
434 IOPMPowerChangeFlags * inOutChangeFlags,
435 IOPMRequestTag requestTag );
6d2010ae
A
436
437 void handleOurPowerChangeDone(
39236c6e
A
438 IOService * service,
439 IOPMActions * actions,
440 IOPMPowerStateIndex powerState,
441 IOPMPowerChangeFlags changeFlags,
442 IOPMRequestTag requestTag );
6d2010ae
A
443
444 void overridePowerChangeForUIService(
39236c6e
A
445 IOService * service,
446 IOPMActions * actions,
447 IOPMPowerStateIndex * inOutPowerState,
448 IOPMPowerChangeFlags * inOutChangeFlags );
6d2010ae
A
449
450 void handleActivityTickleForDisplayWrangler(
39236c6e
A
451 IOService * service,
452 IOPMActions * actions );
453
454 void handleUpdatePowerClientForDisplayWrangler(
455 IOService * service,
456 IOPMActions * actions,
457 const OSSymbol * powerClient,
458 IOPMPowerStateIndex oldPowerState,
459 IOPMPowerStateIndex newPowerState );
6d2010ae
A
460
461 bool shouldDelayChildNotification(
39236c6e 462 IOService * service );
6d2010ae
A
463
464 void handlePowerChangeStartForPCIDevice(
39236c6e 465 IOService * service,
fe8ab488 466 IOPMActions * actions,
39236c6e
A
467 IOPMPowerStateIndex powerState,
468 IOPMPowerChangeFlags * inOutChangeFlags );
6d2010ae
A
469
470 void handlePowerChangeDoneForPCIDevice(
39236c6e 471 IOService * service,
fe8ab488 472 IOPMActions * actions,
39236c6e
A
473 IOPMPowerStateIndex powerState,
474 IOPMPowerChangeFlags changeFlags );
b0d623f7 475
6d2010ae
A
476 void askChangeDownDone(
477 IOPMPowerChangeFlags * inOutChangeFlags,
478 bool * cancel );
479
480 void handlePublishSleepWakeUUID(
481 bool shouldPublish);
482
483 void handleQueueSleepWakeUUID(
484 OSObject *obj);
485
3e170ce0
A
486 void handleDisplayPowerOn( );
487
39236c6e
A
488 void willNotifyPowerChildren( IOPMPowerStateIndex newPowerState );
489
316670eb
A
490 IOReturn setMaintenanceWakeCalendar(
491 const IOPMCalendarStruct * calendar );
b0d623f7 492
db609669
A
493 IOReturn getSystemSleepType( uint32_t * sleepType );
494
b0d623f7 495 // Handle callbacks from IOService::systemWillShutdown()
fe8ab488 496 void acknowledgeSystemWillShutdown( IOService * from );
2d21ac55 497
b0d623f7 498 // Handle platform halt and restart notifications
fe8ab488 499 void handlePlatformHaltRestart( UInt32 pe_type );
6d2010ae
A
500
501 IOReturn shutdownSystem( void );
502 IOReturn restartSystem( void );
503 void handleSleepTimerExpiration( void );
2d21ac55 504
0b4c1975
A
505 bool activitySinceSleep(void);
506 bool abortHibernation(void);
4bd07ac2 507 void updateConsoleUsers(void);
b0d623f7
A
508
509 IOReturn joinAggressiveness( IOService * service );
510 void handleAggressivesRequests( void );
511
39037602
A
512 void kdebugTrace(uint32_t event, uint64_t regId,
513 uintptr_t param1, uintptr_t param2, uintptr_t param3 = 0);
b0d623f7 514 void tracePoint( uint8_t point );
39037602 515 void traceDetail(uint32_t msgType, uint32_t msgIndex, uintptr_t handler);
6d2010ae
A
516
517 bool systemMessageFilter(
518 void * object, void * arg1, void * arg2, void * arg3 );
519
39236c6e 520 bool updatePreventIdleSleepList(
316670eb
A
521 IOService * service, bool addNotRemove );
522 void updatePreventSystemSleepList(
523 IOService * service, bool addNotRemove );
524
7ddcb079
A
525 void publishPMSetting(
526 const OSSymbol * feature, uint32_t where, uint32_t * featureID );
527
6d2010ae
A
528 void pmStatsRecordEvent(
529 int eventIndex,
530 AbsoluteTime timestamp);
531
532 void pmStatsRecordApplicationResponse(
fe8ab488
A
533 const OSSymbol *response,
534 const char *name,
6d2010ae 535 int messageType,
fe8ab488 536 uint32_t delay_ms,
39037602 537 uint64_t id,
fe8ab488
A
538 OSObject *object,
539 IOPMPowerStateIndex ps=0);
316670eb 540
fe8ab488 541 void copyWakeReasonString( char * outBuf, size_t bufSize );
316670eb 542
6d2010ae
A
543#if HIBERNATION
544 bool getHibernateSettings(
545 uint32_t * hibernateMode,
546 uint32_t * hibernateFreeRatio,
547 uint32_t * hibernateFreeTime );
00867663 548 bool mustHibernate( void );
6d2010ae 549#endif
3e170ce0 550 void takeStackshot(bool restart, bool isOSXWatchdog, bool isSpinDump);
39236c6e 551 void sleepWakeDebugTrig(bool restart);
39236c6e
A
552 void sleepWakeDebugEnableWdog();
553 bool sleepWakeDebugIsWdogEnabled();
554 static void saveTimeoutAppStackShot(void *p0, void *p1);
3e170ce0 555 void sleepWakeDebugSaveSpinDumpFile();
39037602
A
556 void swdDebugSetup();
557 void swdDebugTeardown();
b0d623f7 558
1c79356b 559private:
b0d623f7 560 friend class PMSettingObject;
0b4c1975 561 friend class RootDomainUserClient;
6d2010ae
A
562 friend class PMAssertionsTracker;
563
564 static IOReturn sysPowerDownHandler( void * target, void * refCon,
565 UInt32 messageType, IOService * service,
566 void * messageArgument, vm_size_t argSize );
567
568 static IOReturn displayWranglerNotification( void * target, void * refCon,
569 UInt32 messageType, IOService * service,
570 void * messageArgument, vm_size_t argSize );
571
572 static IOReturn rootBusyStateChangeHandler( void * target, void * refCon,
573 UInt32 messageType, IOService * service,
574 void * messageArgument, vm_size_t argSize );
575
576 static bool displayWranglerMatchPublished( void * target, void * refCon,
577 IOService * newService,
578 IONotifier * notifier);
579
39236c6e
A
580 static bool IONVRAMMatchPublished( void * target, void * refCon,
581 IOService * newService,
582 IONotifier * notifier);
583
6d2010ae
A
584 static bool batteryPublished( void * target, void * refCon,
585 IOService * resourceService,
586 IONotifier * notifier);
1c79356b 587
39236c6e
A
588 void initializeBootSessionUUID( void );
589
590 void fullWakeDelayedWork( void );
591
b0d623f7 592 IOService * wrangler;
39236c6e 593 OSDictionary * wranglerIdleSettings;
0c530ab8 594
b0d623f7 595 IOLock *featuresDictLock; // guards supportedFeatures
fe8ab488 596 IOLock *wakeEventLock;
b0d623f7
A
597 IOPMPowerStateQueue *pmPowerStateQueue;
598
599 OSArray *allowedPMSettings;
7ddcb079 600 OSArray *noPublishPMSettings;
b0d623f7 601 PMTraceWorker *pmTracer;
0b4c1975 602 PMAssertionsTracker *pmAssertions;
0c530ab8 603
b0d623f7 604 // Settings controller info
fe8ab488 605 IOLock *settingsCtrlLock;
b0d623f7
A
606 OSDictionary *settingsCallbacks;
607 OSDictionary *fPMSettingsDict;
608
609 IONotifier *_batteryPublishNotifier;
610 IONotifier *_displayWranglerNotifier;
611
612 // Statistics
6d2010ae
A
613 const OSSymbol *_statsNameKey;
614 const OSSymbol *_statsPIDKey;
615 const OSSymbol *_statsTimeMSKey;
616 const OSSymbol *_statsResponseTypeKey;
617 const OSSymbol *_statsMessageTypeKey;
39236c6e
A
618 const OSSymbol *_statsPowerCapsKey;
619 uint32_t sleepCnt;
620 uint32_t darkWakeCnt;
621 uint32_t displayWakeCnt;
fe8ab488 622
b0d623f7 623 OSString *queuedSleepWakeUUIDString;
b0d623f7 624 OSArray *pmStatsAppResponses;
fe8ab488 625 IOLock *pmStatsLock; // guards pmStatsAppResponses
b0d623f7 626
3e170ce0
A
627 void *sleepDelaysReport; // report to track time taken to go to sleep
628 uint32_t sleepDelaysClientCnt; // Number of interested clients in sleepDelaysReport
629 uint64_t ts_sleepStart;
630 uint64_t wake2DarkwakeDelay; // Time taken to change from full wake -> Dark wake
631
632
633 void *assertOnWakeReport; // report to track time spent without any assertions held after wake
634 uint32_t assertOnWakeClientCnt; // Number of clients interested in assertOnWakeReport
635 clock_sec_t assertOnWakeSecs; // Num of secs after wake for first assertion
636
6d2010ae 637 bool uuidPublished;
b0d623f7
A
638
639 // Pref: idle time before idle sleep
743345f9 640 bool idleSleepEnabled;
39236c6e 641 unsigned long sleepSlider;
b0d623f7
A
642 unsigned long idleSeconds;
643 uint64_t autoWakeStart;
644 uint64_t autoWakeEnd;
0c530ab8
A
645
646 // Difference between sleepSlider and longestNonSleepSlider
fe8ab488 647 unsigned long extraSleepDelay;
0c530ab8
A
648
649 // Used to wait between say display idle and system idle
6d2010ae 650 thread_call_t extraSleepTimer;
b0d623f7 651 thread_call_t diskSyncCalloutEntry;
39236c6e 652 thread_call_t fullWakeThreadCall;
39037602
A
653 thread_call_t swdDebugSetupEntry;
654 thread_call_t swdDebugTearDownEntry;
3e170ce0 655 thread_call_t updateConsoleUsersEntry;
6d2010ae
A
656
657 // Track system capabilities.
658 uint32_t _desiredCapability;
659 uint32_t _currentCapability;
660 uint32_t _pendingCapability;
661 uint32_t _highestCapability;
662 OSSet * _joinedCapabilityClients;
663 uint32_t _systemStateGeneration;
664
665 // Type of clients that can receive system messages.
666 enum {
39236c6e
A
667 kSystemMessageClientPowerd = 0x01,
668 kSystemMessageClientLegacyApp = 0x02,
6d2010ae
A
669 kSystemMessageClientKernel = 0x04,
670 kSystemMessageClientAll = 0x07
671 };
672 uint32_t _systemMessageClientMask;
673
674 // Power state and capability change transitions.
675 enum {
676 kSystemTransitionNone = 0,
677 kSystemTransitionSleep = 1,
678 kSystemTransitionWake = 2,
679 kSystemTransitionCapability = 3,
680 kSystemTransitionNewCapClient = 4
681 } _systemTransitionType;
b0d623f7
A
682
683 unsigned int systemBooting :1;
684 unsigned int systemShutdown :1;
6d2010ae 685 unsigned int systemDarkWake :1;
b0d623f7 686 unsigned int clamshellExists :1;
6d2010ae
A
687 unsigned int clamshellClosed :1;
688 unsigned int clamshellDisabled :1;
b0d623f7 689 unsigned int desktopMode :1;
6d2010ae 690 unsigned int acAdaptorConnected :1;
b0d623f7 691
39236c6e 692 unsigned int clamshellSleepDisabled :1;
b0d623f7
A
693 unsigned int idleSleepTimerPending :1;
694 unsigned int userDisabledAllSleep :1;
6d2010ae 695 unsigned int ignoreTellChangeDown :1;
b0d623f7 696 unsigned int wranglerAsleep :1;
6d2010ae 697 unsigned int wranglerTickled :1;
22ba694c 698 unsigned int _preventUserActive :1;
6d2010ae
A
699 unsigned int graphicsSuppressed :1;
700
701 unsigned int capabilityLoss :1;
702 unsigned int pciCantSleepFlag :1;
703 unsigned int pciCantSleepValid :1;
6d2010ae
A
704 unsigned int logGraphicsClamp :1;
705 unsigned int darkWakeToSleepASAP :1;
706 unsigned int darkWakeMaintenance :1;
7ddcb079 707 unsigned int darkWakeSleepService :1;
13f56ec4 708 unsigned int darkWakePostTickle :1;
39236c6e 709
0b4c1975 710 unsigned int sleepTimerMaintenance :1;
39236c6e 711 unsigned int sleepToStandby :1;
0b4c1975
A
712 unsigned int lowBatteryCondition :1;
713 unsigned int hibernateDisabled :1;
39236c6e 714 unsigned int hibernateRetry :1;
13f56ec4 715 unsigned int wranglerTickleLatched :1;
39236c6e
A
716 unsigned int userIsActive :1;
717 unsigned int userWasActive :1;
fe8ab488 718
39236c6e 719 unsigned int displayIdleForDemandSleep :1;
fe8ab488 720 unsigned int darkWakeHibernateError :1;
a1c7dba1 721 unsigned int thermalWarningState:1;
3e170ce0
A
722 unsigned int toldPowerdCapWillChange :1;
723 unsigned int displayPowerOnRequested:1;
0b4c1975 724
4bd07ac2 725 uint8_t tasksSuspended;
0b4c1975 726 uint32_t hibernateMode;
39236c6e
A
727 AbsoluteTime userActivityTime;
728 AbsoluteTime userActivityTime_prev;
0b4c1975
A
729 uint32_t userActivityCount;
730 uint32_t userActivityAtSleep;
731 uint32_t lastSleepReason;
39236c6e 732 uint32_t fullToDarkReason;
13f56ec4 733 uint32_t hibernateAborted;
39037602
A
734 uint8_t standbyNixed;
735 uint8_t resetTimers;
0b4c1975 736
39236c6e
A
737 enum FullWakeReason {
738 kFullWakeReasonNone = 0,
739 kFullWakeReasonLocalUser = 1,
740 kFullWakeReasonDisplayOn = 2,
741 fFullWakeReasonDisplayOnAndLocalUser = 3
742 };
743 uint32_t fullWakeReason;
744
b0d623f7
A
745 // Info for communicating system state changes to PMCPU
746 int32_t idxPMCPUClamshell;
747 int32_t idxPMCPULimitedPower;
748
749 IOOptionBits platformSleepSupport;
6d2010ae 750 uint32_t _debugWakeSeconds;
7ddcb079 751 uint32_t _lastDebugWakeSeconds;
b0d623f7
A
752
753 queue_head_t aggressivesQueue;
754 thread_call_t aggressivesThreadCall;
755 OSData * aggressivesData;
756
39236c6e 757 AbsoluteTime userBecameInactiveTime;
6d2010ae 758
b0d623f7
A
759 // PCI top-level PM trace
760 IOService * pciHostBridgeDevice;
6d2010ae 761 IOService * pciHostBridgeDriver;
b0d623f7 762
6d2010ae 763 IONotifier * systemCapabilityNotifier;
2d21ac55 764
316670eb
A
765 typedef struct {
766 uint32_t pid;
767 uint32_t refcount;
768 } PMNotifySuspendedStruct;
fe8ab488
A
769
770 uint32_t pmSuspendedCapacity;
316670eb
A
771 uint32_t pmSuspendedSize;
772 PMNotifySuspendedStruct *pmSuspendedPIDS;
773
774 OSSet * preventIdleSleepList;
775 OSSet * preventSystemSleepList;
776
99c3a104 777 UInt32 _scheduledAlarms;
db609669 778 UInt32 _userScheduledAlarm;
99c3a104 779
316670eb
A
780#if HIBERNATION
781 clock_sec_t _standbyTimerResetSeconds;
782#endif
39236c6e
A
783 volatile uint32_t swd_lock; /* Lock to access swd_buffer & and its header */
784 void * swd_buffer; /* Memory allocated for dumping sleep/wake logs */
39037602
A
785 uint32_t swd_flags; /* Flags defined in IOPMPrivate.h */
786 uint8_t swd_DebugImageSetup;
3e170ce0 787 void * swd_spindump_buffer;
fe8ab488 788
39037602
A
789 IOBufferMemoryDescriptor *swd_memDesc;
790
39236c6e 791 IOMemoryMap * swd_logBufMap; /* Memory with sleep/wake logs from previous boot */
fe8ab488
A
792
793 // Wake Event Reporting
794 OSArray * _systemWakeEventsArray;
795 bool _acceptSystemWakeEvents;
0b4e3aa0 796
316670eb 797 int findSuspendedPID(uint32_t pid, uint32_t *outRefCount);
7ddcb079 798
fe8ab488 799 // IOPMrootDomain internal sleep call
6d2010ae
A
800 IOReturn privateSleepSystem( uint32_t sleepReason );
801 void reportUserInput( void );
db609669 802 void setDisableClamShellSleep( bool );
39236c6e
A
803 bool checkSystemSleepAllowed( IOOptionBits options,
804 uint32_t sleepReason );
805 bool checkSystemSleepEnabled( void );
806 bool checkSystemCanSleep( uint32_t sleepReason );
13f56ec4 807 bool checkSystemCanSustainFullWake( void );
0b4e3aa0 808
6d2010ae
A
809 void adjustPowerState( bool sleepASAP = false );
810 void setQuickSpinDownTimeout( void );
811 void restoreUserSpinDownTimeout( void );
0b4e3aa0 812
6d2010ae
A
813 bool shouldSleepOnClamshellClosed(void );
814 void sendClientClamshellNotification( void );
483a1d10 815
2d21ac55 816 // Inform PMCPU of changes to state like lid, AC vs. battery
6d2010ae 817 void informCPUStateChange( uint32_t type, uint32_t value );
b0d623f7 818
6d2010ae
A
819 void dispatchPowerEvent( uint32_t event, void * arg0, uint64_t arg1 );
820 void handlePowerNotification( UInt32 msg );
b0d623f7 821
6d2010ae 822 IOReturn setPMSetting(const OSSymbol *, OSObject *);
0c530ab8 823
6d2010ae
A
824 void startIdleSleepTimer( uint32_t inSeconds );
825 void cancelIdleSleepTimer( void );
39236c6e 826 uint32_t getTimeToIdleSleep( void );
b0d623f7
A
827
828 IOReturn setAggressiveness(
829 unsigned long type,
830 unsigned long value,
831 IOOptionBits options );
832
833 void synchronizeAggressives(
834 queue_head_t * services,
835 const AggressivesRecord * array,
836 int count );
837
838 void broadcastAggressives(
839 const AggressivesRecord * array,
840 int count );
841
0b4c1975 842 IOReturn setPMAssertionUserLevels(IOPMDriverAssertionType);
6d2010ae 843
0b4c1975
A
844 void publishSleepWakeUUID( bool shouldPublish );
845
6d2010ae 846 void evaluatePolicy( int stimulus, uint32_t arg = 0 );
39236c6e
A
847 void requestFullWake( FullWakeReason reason );
848 void willEnterFullWake( void );
6d2010ae 849
fe8ab488 850 void evaluateAssertions(IOPMDriverAssertionType newAssertions,
39236c6e 851 IOPMDriverAssertionType oldAssertions);
7ddcb079 852
6d2010ae
A
853 void deregisterPMSettingObject( PMSettingObject * pmso );
854
39037602 855 uint32_t checkForValidDebugData(const char *fname, vfs_context_t *ctx,
3e170ce0 856 void *tmpBuf, struct vnode **vp);
39236c6e 857 void sleepWakeDebugMemAlloc( );
3e170ce0 858 void sleepWakeDebugSpinDumpMemAlloc( );
fe8ab488
A
859 void sleepWakeDebugDumpFromMem(IOMemoryMap *logBufMap);
860 void sleepWakeDebugDumpFromFile( );
39236c6e
A
861 IOMemoryMap *sleepWakeDebugRetrieve();
862 errno_t sleepWakeDebugSaveFile(const char *name, char *buf, int len);
3e170ce0 863 errno_t sleepWakeDebugCopyFile( struct vnode *srcVp,
fe8ab488
A
864 vfs_context_t srcCtx,
865 char *tmpBuf, uint64_t tmpBufSize,
866 uint64_t srcOffset,
867 const char *dstFname,
868 uint64_t numBytes,
869 uint32_t crc);
870
39236c6e 871
0b4c1975
A
872#if HIBERNATION
873 bool getSleepOption( const char * key, uint32_t * option );
db609669
A
874 bool evaluateSystemSleepPolicy( IOPMSystemSleepParameters * p,
875 int phase, uint32_t * hibMode );
0b4c1975
A
876 void evaluateSystemSleepPolicyEarly( void );
877 void evaluateSystemSleepPolicyFinal( void );
878#endif /* HIBERNATION */
13f56ec4
A
879
880 bool latchDisplayWranglerTickle( bool latch );
39236c6e 881 void setDisplayPowerOn( uint32_t options );
fe8ab488
A
882
883 void acceptSystemWakeEvents( bool accept );
22ba694c
A
884 void systemDidNotSleep( void );
885 void preventTransitionToUserActive( bool prevent );
a1c7dba1 886 void setThermalState(OSObject *value);
3e170ce0 887 void copySleepPreventersList(OSArray **idleSleepList, OSArray **systemSleepList);
b0d623f7 888#endif /* XNU_KERNEL_PRIVATE */
1c79356b
A
889};
890
b0d623f7 891#ifdef XNU_KERNEL_PRIVATE
1c79356b
A
892class IORootParent: public IOService
893{
b0d623f7 894 OSDeclareFinalStructors(IORootParent)
0b4e3aa0 895
b0d623f7 896public:
6d2010ae 897 static void initialize( void );
3e170ce0
A
898 virtual OSObject * copyProperty( const char * aKey ) const APPLE_KEXT_OVERRIDE;
899 bool start( IOService * nub ) APPLE_KEXT_OVERRIDE;
b0d623f7
A
900 void shutDownSystem( void );
901 void restartSystem( void );
902 void sleepSystem( void );
903 void dozeSystem( void );
904 void sleepToDoze( void );
905 void wakeSystem( void );
1c79356b 906};
b0d623f7 907#endif /* XNU_KERNEL_PRIVATE */
1c79356b 908
b0d623f7 909#endif /* _IOKIT_ROOTDOMAIN_H */