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