]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/pwr_mgt/RootDomain.h
xnu-3789.21.4.tar.gz
[apple/xnu.git] / iokit / IOKit / pwr_mgt / RootDomain.h
1 /*
2 * Copyright (c) 1998-2016 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28 #ifndef _IOKIT_ROOTDOMAIN_H
29 #define _IOKIT_ROOTDOMAIN_H
30
31 #include <IOKit/IOService.h>
32 #include <IOKit/pwr_mgt/IOPM.h>
33 #include <IOKit/IOBufferMemoryDescriptor.h>
34 #include <sys/vnode.h>
35
36 #ifdef XNU_KERNEL_PRIVATE
37 struct AggressivesRecord;
38 struct IOPMMessageFilterContext;
39 struct IOPMActions;
40 struct IOPMSystemSleepParameters;
41 class PMSettingObject;
42 class PMTraceWorker;
43 class IOPMPowerStateQueue;
44 class RootDomainUserClient;
45 class PMAssertionsTracker;
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
51 #endif
52
53 /*!
54 * Types for PM Assertions
55 * For creating, releasing, and getting PM assertion levels.
56 */
57
58 /*! IOPMDriverAssertionType
59 * A bitfield describing a set of assertions. May be used to specify which assertions
60 * to set with <link>IOPMrootDomain::createPMAssertion</link>; or to query which
61 * assertions are set with <link>IOPMrootDomain::releasePMAssertion</link>.
62 */
63 typedef uint64_t IOPMDriverAssertionType;
64
65 /* IOPMDriverAssertionID
66 * Drivers may create PM assertions to request system behavior (keep the system awake,
67 * or keep the display awake). When a driver creates an assertion via
68 * <link>IOPMrootDomain::createPMAssertion</link>, PM returns a handle to
69 * the assertion of type IOPMDriverAssertionID.
70 */
71 typedef 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 */
78 typedef uint32_t IOPMDriverAssertionLevel;
79 #define kIOPMDriverAssertionLevelOff 0
80 #define kIOPMDriverAssertionLevelOn 255
81
82 /*
83 * Flags for get/setSleepSupported()
84 */
85 enum {
86 kRootDomainSleepNotSupported = 0x00000000,
87 kRootDomainSleepSupported = 0x00000001,
88 kFrameBufferDeepSleepSupported = 0x00000002,
89 kPCICantSleep = 0x00000004
90 };
91
92 /*
93 *IOPMrootDomain registry property keys
94 */
95 #define kRootDomainSupportedFeatures "Supported Features"
96 #define kRootDomainSleepReasonKey "Last Sleep Reason"
97 #define kRootDomainSleepOptionsKey "Last Sleep Options"
98 #define kIOPMRootDomainWakeReasonKey "Wake Reason"
99 #define kIOPMRootDomainWakeTypeKey "Wake Type"
100 #define kIOPMRootDomainPowerStatusKey "Power Status"
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"
112 #define kIOPMMaintenanceSleepKey "Maintenance Sleep"
113
114 /*
115 * String constants for communication with PM CPU
116 */
117 #define kIOPMRootDomainLidCloseCString "LidClose"
118 #define kIOPMRootDomainBatPowerCString "BatPower"
119
120 /*
121 * Supported Feature bitfields for IOPMrootDomain::publishFeature()
122 */
123 enum {
124 kIOPMSupportedOnAC = (1<<0),
125 kIOPMSupportedOnBatt = (1<<1),
126 kIOPMSupportedOnUPS = (1<<2)
127 };
128
129 typedef IOReturn (*IOPMSettingControllerCallback)
130 (OSObject *target, const OSSymbol *type,
131 OSObject *val, uintptr_t refcon);
132
133 __BEGIN_DECLS
134 IONotifier * registerSleepWakeInterest(
135 IOServiceInterestHandler, void *, void * = 0);
136
137 IONotifier * registerPrioritySleepWakeInterest(
138 IOServiceInterestHandler handler,
139 void * self, void * ref = 0);
140
141 IOReturn acknowledgeSleepWakeNotification(void * );
142
143 IOReturn vetoSleepWakeNotification(void * PMrefcon);
144 __END_DECLS
145
146 #define IOPM_ROOTDOMAIN_REV 2
147
148 class IOPMrootDomain: public IOService
149 {
150 OSDeclareFinalStructors(IOPMrootDomain)
151
152 public:
153 static IOPMrootDomain * construct( void );
154
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;
158
159 virtual IOReturn sleepSystem( void );
160 IOReturn sleepSystemOptions( OSDictionary *options );
161
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;
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.
171 @param intValue A 32-bit integer value associated with the event.
172 @result kIOReturnSuccess on success */
173
174 IOReturn systemPowerEventOccurred(
175 const OSSymbol *event,
176 uint32_t intValue );
177
178 IOReturn systemPowerEventOccurred(
179 const OSSymbol *event,
180 OSObject *value );
181
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
250 virtual IOReturn receivePowerNotification( UInt32 msg );
251
252 virtual void setSleepSupported( IOOptionBits flags );
253
254 virtual IOOptionBits getSleepSupported( void );
255
256 void wakeFromDoze( void );
257
258 // KEXT driver announces support of power management feature
259
260 void publishFeature( const char *feature );
261
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
265 // feature.
266 // NULL is acceptable for uniqueFeatureID for kexts without plans to unload.
267
268 void publishFeature( const char *feature,
269 uint32_t supportedWhere,
270 uint32_t *uniqueFeatureID);
271
272 // KEXT driver announces removal of a previously published power management
273 // feature. Pass 'uniqueFeatureID' returned from publishFeature()
274
275 IOReturn removePublishedFeature( uint32_t removeFeatureID );
276
277 /*! @function copyPMSetting
278 @abstract Copy the current value for a PM setting. Returns an OSNumber or
279 OSData depending on the setting.
280 @param whichSetting Name of the desired setting.
281 @result OSObject value if valid, NULL otherwise. */
282
283 OSObject * copyPMSetting( OSSymbol *whichSetting );
284
285 /*! @function registerPMSettingController
286 @abstract Register for callbacks on changes to certain PM settings.
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.
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. */
296
297 IOReturn registerPMSettingController(
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.
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.
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. */
317
318 IOReturn registerPMSettingController(
319 const OSSymbol *settings[],
320 uint32_t supportedPowerSources,
321 IOPMSettingControllerCallback callout,
322 OSObject *target,
323 uintptr_t refcon,
324 OSObject **handle); // out param
325
326 virtual IONotifier * registerInterest(
327 const OSSymbol * typeOfInterest,
328 IOServiceInterestHandler handler,
329 void * target, void * ref = 0 ) APPLE_KEXT_OVERRIDE;
330
331 virtual IOReturn callPlatformFunction(
332 const OSSymbol *functionName,
333 bool waitForFunction,
334 void *param1, void *param2,
335 void *param3, void *param4 ) APPLE_KEXT_OVERRIDE;
336
337 /*! @function createPMAssertion
338 @abstract Creates an assertion to influence system power behavior.
339 @param whichAssertionsBits A bitfield specify the assertion that the caller requests.
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.
354 @discussion Change the value of a PM assertion to influence system behavior,
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).
366 @discussion Returns <link>kIOPMDriverAssertionLevelOff</link> or
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.
372 @result Returns <link>kIOPMDriverAssertionLevelOff</link> or
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);
384
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
391 private:
392 virtual IOReturn changePowerStateTo( unsigned long ordinal ) APPLE_KEXT_COMPATIBILITY_OVERRIDE;
393 virtual IOReturn changePowerStateToPriv( unsigned long ordinal );
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;
400 virtual IOReturn configureReport(IOReportChannelList *channels,
401 IOReportConfigureAction action,
402 void *result,
403 void *destination) APPLE_KEXT_OVERRIDE;
404 virtual IOReturn updateReport(IOReportChannelList *channels,
405 IOReportUpdateAction action,
406 void *result,
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);
415
416 #ifdef XNU_KERNEL_PRIVATE
417 /* Root Domain internals */
418 public:
419 void tagPowerPlaneService(
420 IOService * service,
421 IOPMActions * actions );
422
423 void overrideOurPowerChange(
424 IOService * service,
425 IOPMActions * actions,
426 IOPMPowerStateIndex * inOutPowerState,
427 IOPMPowerChangeFlags * inOutChangeFlags,
428 IOPMRequestTag requestTag );
429
430 void handleOurPowerChangeStart(
431 IOService * service,
432 IOPMActions * actions,
433 IOPMPowerStateIndex powerState,
434 IOPMPowerChangeFlags * inOutChangeFlags,
435 IOPMRequestTag requestTag );
436
437 void handleOurPowerChangeDone(
438 IOService * service,
439 IOPMActions * actions,
440 IOPMPowerStateIndex powerState,
441 IOPMPowerChangeFlags changeFlags,
442 IOPMRequestTag requestTag );
443
444 void overridePowerChangeForUIService(
445 IOService * service,
446 IOPMActions * actions,
447 IOPMPowerStateIndex * inOutPowerState,
448 IOPMPowerChangeFlags * inOutChangeFlags );
449
450 void handleActivityTickleForDisplayWrangler(
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 );
460
461 bool shouldDelayChildNotification(
462 IOService * service );
463
464 void handlePowerChangeStartForPCIDevice(
465 IOService * service,
466 IOPMActions * actions,
467 IOPMPowerStateIndex powerState,
468 IOPMPowerChangeFlags * inOutChangeFlags );
469
470 void handlePowerChangeDoneForPCIDevice(
471 IOService * service,
472 IOPMActions * actions,
473 IOPMPowerStateIndex powerState,
474 IOPMPowerChangeFlags changeFlags );
475
476 void askChangeDownDone(
477 IOPMPowerChangeFlags * inOutChangeFlags,
478 bool * cancel );
479
480 void handlePublishSleepWakeUUID(
481 bool shouldPublish);
482
483 void handleQueueSleepWakeUUID(
484 OSObject *obj);
485
486 void handleDisplayPowerOn( );
487
488 void willNotifyPowerChildren( IOPMPowerStateIndex newPowerState );
489
490 IOReturn setMaintenanceWakeCalendar(
491 const IOPMCalendarStruct * calendar );
492
493 IOReturn getSystemSleepType( uint32_t * sleepType );
494
495 // Handle callbacks from IOService::systemWillShutdown()
496 void acknowledgeSystemWillShutdown( IOService * from );
497
498 // Handle platform halt and restart notifications
499 void handlePlatformHaltRestart( UInt32 pe_type );
500
501 IOReturn shutdownSystem( void );
502 IOReturn restartSystem( void );
503 void handleSleepTimerExpiration( void );
504
505 bool activitySinceSleep(void);
506 bool abortHibernation(void);
507 void updateConsoleUsers(void);
508
509 IOReturn joinAggressiveness( IOService * service );
510 void handleAggressivesRequests( void );
511
512 void kdebugTrace(uint32_t event, uint64_t regId,
513 uintptr_t param1, uintptr_t param2, uintptr_t param3 = 0);
514 void tracePoint( uint8_t point );
515 void traceDetail(uint32_t msgType, uint32_t msgIndex, uintptr_t handler);
516
517 bool systemMessageFilter(
518 void * object, void * arg1, void * arg2, void * arg3 );
519
520 bool updatePreventIdleSleepList(
521 IOService * service, bool addNotRemove );
522 void updatePreventSystemSleepList(
523 IOService * service, bool addNotRemove );
524
525 void publishPMSetting(
526 const OSSymbol * feature, uint32_t where, uint32_t * featureID );
527
528 void pmStatsRecordEvent(
529 int eventIndex,
530 AbsoluteTime timestamp);
531
532 void pmStatsRecordApplicationResponse(
533 const OSSymbol *response,
534 const char *name,
535 int messageType,
536 uint32_t delay_ms,
537 uint64_t id,
538 OSObject *object,
539 IOPMPowerStateIndex ps=0);
540
541 void copyWakeReasonString( char * outBuf, size_t bufSize );
542
543 #if HIBERNATION
544 bool getHibernateSettings(
545 uint32_t * hibernateMode,
546 uint32_t * hibernateFreeRatio,
547 uint32_t * hibernateFreeTime );
548 #endif
549 void takeStackshot(bool restart, bool isOSXWatchdog, bool isSpinDump);
550 void sleepWakeDebugTrig(bool restart);
551 void sleepWakeDebugEnableWdog();
552 bool sleepWakeDebugIsWdogEnabled();
553 static void saveTimeoutAppStackShot(void *p0, void *p1);
554 void sleepWakeDebugSaveSpinDumpFile();
555 void swdDebugSetup();
556 void swdDebugTeardown();
557
558 private:
559 friend class PMSettingObject;
560 friend class RootDomainUserClient;
561 friend class PMAssertionsTracker;
562
563 static IOReturn sysPowerDownHandler( void * target, void * refCon,
564 UInt32 messageType, IOService * service,
565 void * messageArgument, vm_size_t argSize );
566
567 static IOReturn displayWranglerNotification( void * target, void * refCon,
568 UInt32 messageType, IOService * service,
569 void * messageArgument, vm_size_t argSize );
570
571 static IOReturn rootBusyStateChangeHandler( void * target, void * refCon,
572 UInt32 messageType, IOService * service,
573 void * messageArgument, vm_size_t argSize );
574
575 static bool displayWranglerMatchPublished( void * target, void * refCon,
576 IOService * newService,
577 IONotifier * notifier);
578
579 static bool IONVRAMMatchPublished( void * target, void * refCon,
580 IOService * newService,
581 IONotifier * notifier);
582
583 static bool batteryPublished( void * target, void * refCon,
584 IOService * resourceService,
585 IONotifier * notifier);
586
587 void initializeBootSessionUUID( void );
588
589 void fullWakeDelayedWork( void );
590
591 IOService * wrangler;
592 OSDictionary * wranglerIdleSettings;
593
594 IOLock *featuresDictLock; // guards supportedFeatures
595 IOLock *wakeEventLock;
596 IOPMPowerStateQueue *pmPowerStateQueue;
597
598 OSArray *allowedPMSettings;
599 OSArray *noPublishPMSettings;
600 PMTraceWorker *pmTracer;
601 PMAssertionsTracker *pmAssertions;
602
603 // Settings controller info
604 IOLock *settingsCtrlLock;
605 OSDictionary *settingsCallbacks;
606 OSDictionary *fPMSettingsDict;
607
608 IONotifier *_batteryPublishNotifier;
609 IONotifier *_displayWranglerNotifier;
610
611 // Statistics
612 const OSSymbol *_statsNameKey;
613 const OSSymbol *_statsPIDKey;
614 const OSSymbol *_statsTimeMSKey;
615 const OSSymbol *_statsResponseTypeKey;
616 const OSSymbol *_statsMessageTypeKey;
617 const OSSymbol *_statsPowerCapsKey;
618 uint32_t sleepCnt;
619 uint32_t darkWakeCnt;
620 uint32_t displayWakeCnt;
621
622 OSString *queuedSleepWakeUUIDString;
623 OSArray *pmStatsAppResponses;
624 IOLock *pmStatsLock; // guards pmStatsAppResponses
625
626 void *sleepDelaysReport; // report to track time taken to go to sleep
627 uint32_t sleepDelaysClientCnt; // Number of interested clients in sleepDelaysReport
628 uint64_t ts_sleepStart;
629 uint64_t wake2DarkwakeDelay; // Time taken to change from full wake -> Dark wake
630
631
632 void *assertOnWakeReport; // report to track time spent without any assertions held after wake
633 uint32_t assertOnWakeClientCnt; // Number of clients interested in assertOnWakeReport
634 clock_sec_t assertOnWakeSecs; // Num of secs after wake for first assertion
635
636 bool uuidPublished;
637
638 // Pref: idle time before idle sleep
639 bool idleSleepEnabled;
640 unsigned long sleepSlider;
641 unsigned long idleSeconds;
642 uint64_t autoWakeStart;
643 uint64_t autoWakeEnd;
644
645 // Difference between sleepSlider and longestNonSleepSlider
646 unsigned long extraSleepDelay;
647
648 // Used to wait between say display idle and system idle
649 thread_call_t extraSleepTimer;
650 thread_call_t diskSyncCalloutEntry;
651 thread_call_t fullWakeThreadCall;
652 thread_call_t swdDebugSetupEntry;
653 thread_call_t swdDebugTearDownEntry;
654 thread_call_t updateConsoleUsersEntry;
655
656 // Track system capabilities.
657 uint32_t _desiredCapability;
658 uint32_t _currentCapability;
659 uint32_t _pendingCapability;
660 uint32_t _highestCapability;
661 OSSet * _joinedCapabilityClients;
662 uint32_t _systemStateGeneration;
663
664 // Type of clients that can receive system messages.
665 enum {
666 kSystemMessageClientPowerd = 0x01,
667 kSystemMessageClientLegacyApp = 0x02,
668 kSystemMessageClientKernel = 0x04,
669 kSystemMessageClientAll = 0x07
670 };
671 uint32_t _systemMessageClientMask;
672
673 // Power state and capability change transitions.
674 enum {
675 kSystemTransitionNone = 0,
676 kSystemTransitionSleep = 1,
677 kSystemTransitionWake = 2,
678 kSystemTransitionCapability = 3,
679 kSystemTransitionNewCapClient = 4
680 } _systemTransitionType;
681
682 unsigned int systemBooting :1;
683 unsigned int systemShutdown :1;
684 unsigned int systemDarkWake :1;
685 unsigned int clamshellExists :1;
686 unsigned int clamshellClosed :1;
687 unsigned int clamshellDisabled :1;
688 unsigned int desktopMode :1;
689 unsigned int acAdaptorConnected :1;
690
691 unsigned int clamshellSleepDisabled :1;
692 unsigned int idleSleepTimerPending :1;
693 unsigned int userDisabledAllSleep :1;
694 unsigned int ignoreTellChangeDown :1;
695 unsigned int wranglerAsleep :1;
696 unsigned int wranglerTickled :1;
697 unsigned int _preventUserActive :1;
698 unsigned int graphicsSuppressed :1;
699
700 unsigned int capabilityLoss :1;
701 unsigned int pciCantSleepFlag :1;
702 unsigned int pciCantSleepValid :1;
703 unsigned int logGraphicsClamp :1;
704 unsigned int darkWakeToSleepASAP :1;
705 unsigned int darkWakeMaintenance :1;
706 unsigned int darkWakeSleepService :1;
707 unsigned int darkWakePostTickle :1;
708
709 unsigned int sleepTimerMaintenance :1;
710 unsigned int sleepToStandby :1;
711 unsigned int lowBatteryCondition :1;
712 unsigned int hibernateDisabled :1;
713 unsigned int hibernateRetry :1;
714 unsigned int wranglerTickleLatched :1;
715 unsigned int userIsActive :1;
716 unsigned int userWasActive :1;
717
718 unsigned int displayIdleForDemandSleep :1;
719 unsigned int darkWakeHibernateError :1;
720 unsigned int thermalWarningState:1;
721 unsigned int toldPowerdCapWillChange :1;
722 unsigned int displayPowerOnRequested:1;
723
724 uint8_t tasksSuspended;
725 uint32_t hibernateMode;
726 AbsoluteTime userActivityTime;
727 AbsoluteTime userActivityTime_prev;
728 uint32_t userActivityCount;
729 uint32_t userActivityAtSleep;
730 uint32_t lastSleepReason;
731 uint32_t fullToDarkReason;
732 uint32_t hibernateAborted;
733 uint8_t standbyNixed;
734 uint8_t resetTimers;
735
736 enum FullWakeReason {
737 kFullWakeReasonNone = 0,
738 kFullWakeReasonLocalUser = 1,
739 kFullWakeReasonDisplayOn = 2,
740 fFullWakeReasonDisplayOnAndLocalUser = 3
741 };
742 uint32_t fullWakeReason;
743
744 // Info for communicating system state changes to PMCPU
745 int32_t idxPMCPUClamshell;
746 int32_t idxPMCPULimitedPower;
747
748 IOOptionBits platformSleepSupport;
749 uint32_t _debugWakeSeconds;
750 uint32_t _lastDebugWakeSeconds;
751
752 queue_head_t aggressivesQueue;
753 thread_call_t aggressivesThreadCall;
754 OSData * aggressivesData;
755
756 AbsoluteTime userBecameInactiveTime;
757
758 // PCI top-level PM trace
759 IOService * pciHostBridgeDevice;
760 IOService * pciHostBridgeDriver;
761
762 IONotifier * systemCapabilityNotifier;
763
764 typedef struct {
765 uint32_t pid;
766 uint32_t refcount;
767 } PMNotifySuspendedStruct;
768
769 uint32_t pmSuspendedCapacity;
770 uint32_t pmSuspendedSize;
771 PMNotifySuspendedStruct *pmSuspendedPIDS;
772
773 OSSet * preventIdleSleepList;
774 OSSet * preventSystemSleepList;
775
776 UInt32 _scheduledAlarms;
777 UInt32 _userScheduledAlarm;
778
779 #if HIBERNATION
780 clock_sec_t _standbyTimerResetSeconds;
781 #endif
782 volatile uint32_t swd_lock; /* Lock to access swd_buffer & and its header */
783 void * swd_buffer; /* Memory allocated for dumping sleep/wake logs */
784 uint32_t swd_flags; /* Flags defined in IOPMPrivate.h */
785 uint8_t swd_DebugImageSetup;
786 void * swd_spindump_buffer;
787
788 IOBufferMemoryDescriptor *swd_memDesc;
789
790 IOMemoryMap * swd_logBufMap; /* Memory with sleep/wake logs from previous boot */
791
792 // Wake Event Reporting
793 OSArray * _systemWakeEventsArray;
794 bool _acceptSystemWakeEvents;
795
796 int findSuspendedPID(uint32_t pid, uint32_t *outRefCount);
797
798 // IOPMrootDomain internal sleep call
799 IOReturn privateSleepSystem( uint32_t sleepReason );
800 void reportUserInput( void );
801 void setDisableClamShellSleep( bool );
802 bool checkSystemSleepAllowed( IOOptionBits options,
803 uint32_t sleepReason );
804 bool checkSystemSleepEnabled( void );
805 bool checkSystemCanSleep( uint32_t sleepReason );
806 bool checkSystemCanSustainFullWake( void );
807
808 void adjustPowerState( bool sleepASAP = false );
809 void setQuickSpinDownTimeout( void );
810 void restoreUserSpinDownTimeout( void );
811
812 bool shouldSleepOnClamshellClosed(void );
813 void sendClientClamshellNotification( void );
814
815 // Inform PMCPU of changes to state like lid, AC vs. battery
816 void informCPUStateChange( uint32_t type, uint32_t value );
817
818 void dispatchPowerEvent( uint32_t event, void * arg0, uint64_t arg1 );
819 void handlePowerNotification( UInt32 msg );
820
821 IOReturn setPMSetting(const OSSymbol *, OSObject *);
822
823 void startIdleSleepTimer( uint32_t inSeconds );
824 void cancelIdleSleepTimer( void );
825 uint32_t getTimeToIdleSleep( void );
826
827 IOReturn setAggressiveness(
828 unsigned long type,
829 unsigned long value,
830 IOOptionBits options );
831
832 void synchronizeAggressives(
833 queue_head_t * services,
834 const AggressivesRecord * array,
835 int count );
836
837 void broadcastAggressives(
838 const AggressivesRecord * array,
839 int count );
840
841 IOReturn setPMAssertionUserLevels(IOPMDriverAssertionType);
842
843 void publishSleepWakeUUID( bool shouldPublish );
844
845 void evaluatePolicy( int stimulus, uint32_t arg = 0 );
846 void requestFullWake( FullWakeReason reason );
847 void willEnterFullWake( void );
848
849 void evaluateAssertions(IOPMDriverAssertionType newAssertions,
850 IOPMDriverAssertionType oldAssertions);
851
852 void deregisterPMSettingObject( PMSettingObject * pmso );
853
854 uint32_t checkForValidDebugData(const char *fname, vfs_context_t *ctx,
855 void *tmpBuf, struct vnode **vp);
856 void sleepWakeDebugMemAlloc( );
857 void sleepWakeDebugSpinDumpMemAlloc( );
858 void sleepWakeDebugDumpFromMem(IOMemoryMap *logBufMap);
859 void sleepWakeDebugDumpFromFile( );
860 IOMemoryMap *sleepWakeDebugRetrieve();
861 errno_t sleepWakeDebugSaveFile(const char *name, char *buf, int len);
862 errno_t sleepWakeDebugCopyFile( struct vnode *srcVp,
863 vfs_context_t srcCtx,
864 char *tmpBuf, uint64_t tmpBufSize,
865 uint64_t srcOffset,
866 const char *dstFname,
867 uint64_t numBytes,
868 uint32_t crc);
869
870
871 #if HIBERNATION
872 bool getSleepOption( const char * key, uint32_t * option );
873 bool evaluateSystemSleepPolicy( IOPMSystemSleepParameters * p,
874 int phase, uint32_t * hibMode );
875 void evaluateSystemSleepPolicyEarly( void );
876 void evaluateSystemSleepPolicyFinal( void );
877 #endif /* HIBERNATION */
878
879 bool latchDisplayWranglerTickle( bool latch );
880 void setDisplayPowerOn( uint32_t options );
881
882 void acceptSystemWakeEvents( bool accept );
883 void systemDidNotSleep( void );
884 void preventTransitionToUserActive( bool prevent );
885 void setThermalState(OSObject *value);
886 void copySleepPreventersList(OSArray **idleSleepList, OSArray **systemSleepList);
887 #endif /* XNU_KERNEL_PRIVATE */
888 };
889
890 #ifdef XNU_KERNEL_PRIVATE
891 class IORootParent: public IOService
892 {
893 OSDeclareFinalStructors(IORootParent)
894
895 public:
896 static void initialize( void );
897 virtual OSObject * copyProperty( const char * aKey ) const APPLE_KEXT_OVERRIDE;
898 bool start( IOService * nub ) APPLE_KEXT_OVERRIDE;
899 void shutDownSystem( void );
900 void restartSystem( void );
901 void sleepSystem( void );
902 void dozeSystem( void );
903 void sleepToDoze( void );
904 void wakeSystem( void );
905 };
906 #endif /* XNU_KERNEL_PRIVATE */
907
908 #endif /* _IOKIT_ROOTDOMAIN_H */