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