]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/pwr_mgt/IOPMPrivate.h
1a549c0c40f917ce816d27e8a4a5d75fe5f459e9
[apple/xnu.git] / iokit / IOKit / pwr_mgt / IOPMPrivate.h
1 /*
2 * Copyright (c) 2002 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_IOPMPRIVATE_H
29 #define _IOKIT_IOPMPRIVATE_H
30
31 #include <IOKit/pwr_mgt/IOPM.h>
32
33 /* @constant kIOPMEventTypeIntermediateFlag
34 * @abstract This bit indicates the event is an intermediate event
35 * which must occur within a major system power event.
36 */
37 #define kIOPMEventTypeIntermediateFlag 0x10000000
38
39 /* @enum SystemEventTypes
40 * @abstract Potential system events logged in the system event record.
41 */
42 enum {
43 kIOPMEventTypeUndefined = 0,
44
45 /* Event types mark driver events
46 */
47 kIOPMEventTypeSetPowerStateImmediate = 1001,
48 kIOPMEventTypeSetPowerStateDelayed = 1002,
49 kIOPMEventTypePSWillChangeTo = 1003,
50 kIOPMEventTypePSDidChangeTo = 1004,
51 kIOPMEventTypeAppResponse = 1005,
52
53
54 /* Start and stop event types bracket major
55 * system power management events.
56 */
57 kIOPMEventTypeSleep = 2001,
58 kIOPMEventTypeSleepDone = 2002,
59 kIOPMEventTypeWake = 3001,
60 kIOPMEventTypeWakeDone = 3002,
61 kIOPMEventTypeDoze = 4001,
62 kIOPMEventTypeDozeDone = 4002,
63 kIOPMEventTypeUUIDSet = 6001,
64 kIOPMEventTypeUUIDClear = 6002,
65
66 /* Intermediate events that may only occur within the bounds
67 * of a major system event (between the event's initiation and its "done event".)
68 * e.g. chronologically kIOPMEventTypeSleep may be followed by one or more
69 * intermediate events, which then must be followed by kIOPMEventTypeSleepDone.
70 *
71 * The intermediate events below will always occur in a Sleep or Wake event, and may
72 * or may not occur for any of the other events.
73 */
74 kIOPMEventTypeAppNotificationsFinished = 501 | kIOPMEventTypeIntermediateFlag,
75 kIOPMEventTypeDriverNotificationsFinished = 502 | kIOPMEventTypeIntermediateFlag,
76 kIOPMEventTypeCalTimeChange = 503 | kIOPMEventTypeIntermediateFlag
77 };
78
79 /*****************************************************************************
80 *
81 * Private Root Domain general interest messages
82 *
83 * Check IOPM.h when adding new messages to avoid conflict.
84 *
85 *****************************************************************************/
86
87 /* kIOPMMessageUserIsActiveChanged
88 * User became active or inactive. Message sent after the kIOPMUserIsActiveKey
89 * property was updated with a new value.
90 */
91 #define kIOPMMessageUserIsActiveChanged \
92 iokit_family_msg(sub_iokit_powermanagement, 0x400)
93
94 /*
95 * Private IOMessage notifications shared between kernel and userspace PM policy
96 */
97 #define kIOPMMessageLastCallBeforeSleep \
98 iokit_family_msg(sub_iokit_powermanagement, 0x410)
99
100 #define kIOPMMessageIdleSleepPreventers \
101 iokit_family_msg(sub_iokit_powermanagement, 0x420)
102
103 #define kIOPMMessageSystemSleepPreventers \
104 iokit_family_msg(sub_iokit_powermanagement, 0x430)
105
106 #define kIOPMMessageLaunchBootSpinDump \
107 iokit_family_msg(sub_iokit_powermanagement, 0x440)
108
109 /* @enum SystemSleepReasons
110 * @abstract The potential causes for system sleep as logged in the system event record.
111 */
112 enum {
113 kIOPMSleepReasonClamshell = 101,
114 kIOPMSleepReasonPowerButton = 102,
115 kIOPMSleepReasonSoftware = 103,
116 kIOPMSleepReasonOSSwitchHibernate = 104,
117 kIOPMSleepReasonIdle = 105,
118 kIOPMSleepReasonLowPower = 106,
119 kIOPMSleepReasonThermalEmergency = 107,
120 kIOPMSleepReasonMaintenance = 108,
121 kIOPMSleepReasonSleepServiceExit = 109,
122 kIOPMSleepReasonDarkWakeThermalEmergency = 110
123 };
124
125 /*
126 * Possible C-string sleep reasons found under kRootDomainSleepReasonsKey
127 */
128 #define kIOPMClamshellSleepKey "Clamshell Sleep"
129 #define kIOPMPowerButtonSleepKey "Power Button Sleep"
130 #define kIOPMSoftwareSleepKey "Software Sleep"
131 #define kIOPMOSSwitchHibernationKey "OS Switch Sleep"
132 #define kIOPMIdleSleepKey "Idle Sleep"
133 #define kIOPMLowPowerSleepKey "Low Power Sleep"
134 #define kIOPMThermalEmergencySleepKey "Thermal Emergency Sleep"
135 #define kIOPMSleepServiceExitKey "Sleep Service Back to Sleep"
136 #define kIOPMDarkWakeThermalEmergencyKey "Dark Wake Thermal Emergency"
137
138 /*! kIOPMPSRestrictedModeKey
139 * An IOPMPowerSource property key
140 * Its property has an integer value.
141 * - value = 1 when the device is in a low power state and not fully functional.
142 * - value = 0, or property missing altogether, when the device is
143 * not in a restricted mode power state.
144 */
145 #define kIOPMPSRestrictedModeKey "RestrictedMode"
146
147 #pragma mark Stray Bitfields
148 // Private power commands issued to root domain
149 // bits 0-7 in IOPM.h
150
151 enum {
152 kIOPMSetValue = (1<<16),
153 // don't sleep on clamshell closure on a portable with AC connected
154 kIOPMSetDesktopMode = (1<<17),
155 // set state of AC adaptor connected
156 kIOPMSetACAdaptorConnected = (1<<18)
157 };
158
159 /*****************************************************************************/
160 /*****************************************************************************/
161
162 /*
163 * PM notification types
164 */
165
166 /*! @constant kIOPMSleepServiceScheduleImmediate
167 *
168 * Setting type used in calls to IOPMrootDomain::registerPMSettingController
169 * Use this type between powerd and IOKit.framework
170 *
171 */
172 #define kIOPMSleepServiceScheduleImmediate "SleepServiceImmediate"
173
174 /*! @constant kIOPMSettingSleepServiceScheduleImmediate
175 *
176 * Setting type used in calls to IOPMrootDomain::registerPMSettingController
177 * Use this type between xnu and AppleRTC
178 */
179 #define kIOPMSettingSleepServiceWakeCalendarKey "SleepServiceWakeCalendarKey"
180
181 /*! @constant kIOPMCalendarWakeTypes
182 *
183 * These are valid values for IOPM.h:IOPMCalendarStruct->selector
184 */
185 enum {
186 kPMCalendarTypeInvalid = 0,
187 kPMCalendarTypeMaintenance = 1,
188 kPMCalendarTypeSleepService = 2
189 };
190
191
192 /* @constant kIOPMStateConsoleShutdown
193 * @abstract Notification of GUI shutdown state available to kexts.
194 * @discussion This type can be passed as arguments to registerPMSettingController()
195 * to receive callbacks.
196 */
197 #define kIOPMStateConsoleShutdown "ConsoleShutdown"
198
199 /* @enum ShutdownValues
200 * @abstract Potential values shared with key kIOPMStateConsoleShutdown
201 */
202 enum {
203 /* @constant kIOPMStateConsoleShutdownNone
204 * @abstract System shutdown (or restart) hasn't started; system is ON.
205 * @discussion Next state: 2
206 */
207 kIOPMStateConsoleShutdownNone = 1,
208 /* @constant kIOPMStateConsoleShutdownPossible
209 * @abstract User has been presented with the option to shutdown or restart. Shutdown may be cancelled.
210 * @discussion Next state may be: 1, 4
211 */
212 kIOPMStateConsoleShutdownPossible = 2,
213 /* @constant kIOPMStateConsoleShutdownUnderway
214 * @abstract Shutdown or restart is proceeding. It may still be cancelled.
215 * @discussion Next state may be: 1, 4. This state is currently unused.
216 */
217 kIOPMStateConsoleShutdownUnderway = 3,
218 /* @constant kIOPMStateConsoleShutdownCertain
219 * @abstract Shutdown is in progress and irrevocable.
220 * @discussion State remains 4 until power is removed from CPU.
221 */
222 kIOPMStateConsoleShutdownCertain = 4,
223 /* @constant kIOPMStateConsoleSULogoutInitiated
224 Indicates that LoginWindow has initiated a software update restart.
225 The next logout will not immediately lead to a shutdown.
226 */
227 kIOPMStateConsoleSULogoutInitiated = 5
228 };
229
230 /* @constant kIOPMSettingSilentRunningKey
231 * @abstract Notification of silent running mode changes to kexts.
232 * @discussion This key can be passed as an argument to registerPMSettingController()
233 * and also identifies the type of PMSetting notification callback.
234 */
235 #define kIOPMSettingSilentRunningKey "SilentRunning"
236 #define kIOPMFeatureSilentRunningKey kIOPMSettingSilentRunningKey
237
238 /* @enum SilentRunningFlags
239 * @abstract The kIOPMSettingSilentRunningKey notification provides an OSNumber
240 * object with a value described by the following flags.
241 */
242 enum {
243 kIOPMSilentRunningModeOn = 0x00000001
244 };
245
246 /*****************************************************************************/
247 /*****************************************************************************/
248
249 /* PM Statistics - event indices
250 * These are arguments to IOPMrootDomain::pmStatsRecordEvent().
251 */
252 enum {
253 kIOPMStatsHibernateImageWrite = 1,
254 kIOPMStatsHibernateImageRead,
255 kIOPMStatsDriversNotify,
256 kIOPMStatsApplicationNotify,
257 kIOPMStatsLateDriverAcknowledge,
258 kIOPMStatsLateAppAcknowledge,
259
260 // To designate if you're specifying the start or stop end of
261 // each of the above events, do a bitwise OR of the appropriate
262 // Start/Stop flag and pass the result to IOPMrootDomain to record
263 // the event.
264 kIOPMStatsEventStartFlag = (1 << 24),
265 kIOPMStatsEventStopFlag = (1 << 25)
266 };
267
268 // Keys for IOPMrootDomain registry properties
269 #define kIOPMSleepStatisticsKey "SleepStatistics"
270 #define kIOPMSleepStatisticsAppsKey "AppStatistics"
271 #define kIOPMIdleSleepPreventersKey "IdleSleepPreventers"
272 #define kIOPMSystemSleepPreventersKey "SystemSleepPreventers"
273 #define kIOPMIdleSleepPreventersWithIDKey "IdleSleepPreventersWithID"
274 #define kIOPMSystemSleepPreventersWithIDKey "SystemSleepPreventersWithID"
275
276 // Application response statistics
277 #define kIOPMStatsNameKey "Name"
278 #define kIOPMStatsPIDKey "Pid"
279 #define kIOPMStatsTimeMSKey "TimeMS"
280 #define kIOPMStatsApplicationResponseTypeKey "ResponseType"
281 #define kIOPMStatsMessageTypeKey "MessageType"
282 #define kIOPMStatsPowerCapabilityKey "PowerCaps"
283 #define kIOPMStatsSystemTransitionKey "TransitionType"
284
285 // PM Statistics: potential values for the key kIOPMStatsApplicationResponseTypeKey
286 // entry in the application results array.
287 #define kIOPMStatsResponseTimedOut "ResponseTimedOut"
288 #define kIOPMStatsResponseCancel "ResponseCancel"
289 #define kIOPMStatsResponseSlow "ResponseSlow"
290 #define kIOPMStatsResponsePrompt "ResponsePrompt"
291 #define kIOPMStatsDriverPSChangeSlow "DriverPSChangeSlow"
292
293 struct PMStatsBounds{
294 uint64_t start;
295 uint64_t stop;
296 };
297 typedef struct {
298
299 struct PMStatsBounds hibWrite;
300 struct PMStatsBounds hibRead;
301 // bounds driverNotifySleep;
302 // bounds driverNotifyWake;
303 // bounds appNotifySleep;
304 // bounds appNotifyWake;
305 // OSDictionary *tardyApps;
306 // OSDictionary *tardyDrivers;
307 } PMStatsStruct;
308
309 /*****************************************************************************/
310
311 /* PM RootDomain tracePoints
312 *
313 * In the sleep/wake process, we expect the sleep trace points to proceed
314 * in increasing order. Once sleep begins with code kIOPMTracePointSleepStarted,
315 * we expect sleep to continue in a monotonically increasing order of tracepoints
316 * to kIOPMTracePointSystemLoginwindowPhase. After trace point SystemLoginWindowPhase,
317 * the system will return to kIOPMTracePointSystemUp.
318 *
319 * If the trace point decreases (instead of increasing) before reaching kIOPMTracePointSystemUp,
320 * that indicates that the sleep process was cancelled. The cancel reason shall be indicated
321 * in the cancel tracepoint. (TBD)
322 */
323
324 enum {
325 /* When kTracePointSystemUp is the latest tracePoint,
326 * the system is awake. It is not asleep, sleeping, or waking.
327 *
328 * Phase begins: At boot, at completion of wake from sleep,
329 * immediately following kIOPMTracePointSystemLoginwindowPhase.
330 * Phase ends: When a sleep attempt is initiated.
331 */
332 kIOPMTracePointSystemUp = 0,
333
334 /* When kIOPMTracePointSleepStarted is the latest tracePoint,
335 * sleep has been initiated.
336 *
337 * Phase begins: At initiation of system sleep (idle or forced).
338 * Phase ends: PM starts to notify applications of system sleep.
339 */
340 kIOPMTracePointSleepStarted = 0x10,
341
342 /* When kIOPMTracePointSleepApplications is the latest tracePoint,
343 * a system sleep has been initiated and PM waits for responses
344 * from notified applications.
345 *
346 * Phase begins: Begin to asynchronously fire kIOMessageSystemWillSleep
347 * notifications, and also kIOMessageCanSystemSleep for the idle sleep case.
348 * Phase ends: When PM has received all application responses.
349 */
350 kIOPMTracePointSleepApplications = 0x11,
351
352 /* When kIOPMTracePointSleepPriorityClients is the latest tracePoint,
353 * PM is notifying priority clients and in-kernel system capability
354 * clients, and waiting for any asynchronous completions.
355 *
356 * Phase begins: Synchronous delivery of kIOMessageSystemWillSleep notifications.
357 * Phase ends: All notified clients have acknowledged.
358 */
359 kIOPMTracePointSleepPriorityClients = 0x12,
360
361 /* When kIOPMTracePointSleepWillChangeInterests is the latest tracePoint,
362 * PM is calling powerStateWillChangeTo() on interested drivers of root domain.
363 *
364 * Phase begins: Dispatch a callout thread to call interested drivers.
365 * Phase ends: Callout thread work done, and acknowledgePowerChange() called
366 * by drivers that indicated asynchronous completion.
367 */
368 kIOPMTracePointSleepWillChangeInterests = 0x13,
369
370 /* When kIOPMTracePointSleepPowerPlaneDrivers is the latest tracePoint,
371 * PM is directing power plane drivers to power off in leaf-to-root order.
372 *
373 * Phase begins: Root domain informs its power children that it will drop to
374 * sleep state. This has a cascade effect and triggers all drivers in
375 * the power plane to transition to a lower power state if necessary.
376 * Phase ends: All power transitions in response to the root domain power
377 * change have completed.
378 */
379 kIOPMTracePointSleepPowerPlaneDrivers = 0x14,
380
381 /* When kIOPMTracePointSleepDidChangeInterests is the latest tracePoint,
382 * PM is calling powerStateDidChangeTo() on interested drivers of root domain.
383 *
384 * Phase begins: Dispatch a callout thread to call interested drivers.
385 * Phase ends: Callout thread work done, and acknowledgePowerChange() called
386 * by drivers that indicated asynchronous completion.
387 */
388 kIOPMTracePointSleepDidChangeInterests = 0x15,
389
390 /* When kIOPMTracePointSleepCapabilityClients is the latest tracePoint,
391 * PM is notifying system capability clients about system sleep.
392 *
393 * Phase begins: Send kIOMessageSystemCapabilityChange notifications to inform
394 * capability clients that system has lost all capabilities.
395 * Phase ends: Finished sending notifications.
396 */
397 kIOPMTracePointSleepCapabilityClients = 0x16,
398
399 /* When kIOPMTracePointSleepPlatformActions is the latest tracePoint,
400 * PM is calling drivers that have registered a platform sleep action.
401 */
402 kIOPMTracePointSleepPlatformActions = 0x17,
403
404 /* When kIOPMTracePointSleepCPUs is the latest tracePoint,
405 * PM is shutting down all non-boot processors.
406 *
407 * Phase begins: Shutdown all non-boot processors.
408 * Phase ends: Reduced to only the boot processor running.
409 */
410 kIOPMTracePointSleepCPUs = 0x18,
411
412 /* When kIOPMTracePointSleepPlatformDriver is the latest tracePoint,
413 * PM is executing platform dependent code to prepare for system sleep.
414 */
415 kIOPMTracePointSleepPlatformDriver = 0x19,
416
417 /* When kIOPMTracePointHibernate is the latest tracePoint,
418 * PM is writing the hibernate image to disk.
419 */
420 kIOPMTracePointHibernate = 0x1a,
421
422 /* When kIOPMTracePointSystemSleep is the latest tracePoint,
423 * PM has recorded the final trace point before the hardware platform
424 * enters sleep state, or low level wakeup is underway - such as restoring
425 * the hibernate image from disk.
426 *
427 * Note: If a system is asleep and then loses power, and it does not have a
428 * hibernate image to restore from (e.g. hibernatemode = 0), then OS X will
429 * interpret this power loss as a failure in kIOPMTracePointSystemSleep.
430 *
431 * Phase begins: Before the OS directs the hardware to enter sleep state.
432 * Phase ends: Control returns to the OS on wake, but before recording the first
433 * wake trace point.
434 */
435 kIOPMTracePointSystemSleep = 0x1f,
436
437 /* When kIOPMTracePointWakePlatformDriver is the latest tracePoint,
438 * PM is executing platform dependent code to prepare for system wake.
439 */
440 kIOPMTracePointWakePlatformDriver = 0x21,
441
442 /* When kIOPMTracePointWakePlatformActions is the latest tracePoint,
443 * PM is calling drivers that have registered a platform wake action.
444 */
445 kIOPMTracePointWakePlatformActions = 0x22,
446
447 /* When kIOPMTracePointWakeCPUs is the latest tracePoint,
448 * PM is bringing all non-boot processors online.
449 */
450 kIOPMTracePointWakeCPUs = 0x23,
451
452 /* When kIOPMTracePointWakeWillPowerOnClients is the latest tracePoint,
453 * PM is sending kIOMessageSystemWillPowerOn to both kernel clients and
454 * applications. PM also notifies system capability clients about the
455 * proposed capability change.
456 *
457 * Phase begins: Send kIOMessageSystemWillPowerOn and
458 * kIOMessageSystemCapabilityChange notifications.
459 * Phase ends: Finished sending notifications.
460 */
461 kIOPMTracePointWakeWillPowerOnClients = 0x24,
462
463 /* When kIOPMTracePointWakeWillChangeInterests is the latest tracePoint,
464 * PM is calling powerStateWillChangeTo() on interested drivers of root domain.
465 *
466 * Phase begins: Dispatch a callout thread to call interested drivers.
467 * Phase ends: Callout thread work done, and acknowledgePowerChange() called
468 * by drivers that indicated asynchronous completion.
469 */
470 kIOPMTracePointWakeWillChangeInterests = 0x25,
471
472 /* When kIOPMTracePointWakeDidChangeInterests is the latest tracePoint,
473 * PM is calling powerStateDidChangeTo() on interested drivers of root domain.
474 *
475 * Phase begins: Dispatch a callout thread to call interested drivers.
476 * Phase ends: Callout thread work done, and acknowledgePowerChange() called
477 * by drivers that indicated asynchronous completion.
478 */
479 kIOPMTracePointWakeDidChangeInterests = 0x26,
480
481 /* When kIOPMTracePointWakePowerPlaneDrivers is the latest tracePoint,
482 * PM is directing power plane drivers to power up in root-to-leaf order.
483 *
484 * Phase begins: Root domain informs its power children that it transitioned
485 * to ON state. This has a cascade effect and triggers all drivers in
486 * the power plane to re-evaluate and potentially change power state.
487 * Phase ends: All power transitions in response to the root domain power
488 * change have completed.
489 */
490 kIOPMTracePointWakePowerPlaneDrivers = 0x27,
491
492 /* When kIOPMTracePointWakeCapabilityClients is the latest tracePoint,
493 * PM is notifying system capability clients about system wake, and waiting
494 * for any asynchronous completions.
495 *
496 * Phase begins: Inform capability clients that system has gained capabilities.
497 * Phase ends: All notified clients have acknowledged.
498 */
499 kIOPMTracePointWakeCapabilityClients = 0x28,
500
501 /* When kIOPMTracePointWakeApplications is the latest tracePoint,
502 * System CPU is powered, PM has powered on each driver.
503 *
504 * Phase begins: Send asynchronous kIOMessageSystemHasPoweredOn notifications.
505 * Phase ends: Finished sending asynchronous notifications.
506 */
507 kIOPMTracePointWakeApplications = 0x29,
508
509 /* kIOPMTracePointSystemLoginwindowPhase
510 * This phase represents a several minute window after the system has powered on.
511 * Higher levels of system diagnostics are in a heightened state of alert in this phase,
512 * in case any user errors occurred that we could not detect in software.
513 *
514 * Phase begins: After IOPMrootDomain sends kIOMessageSystemHasPoweredOn message.
515 * Phase ends: When loginwindow calls IOPMSleepWakeSetUUID(NULL) the system shall
516 * be considered awake and usable. The next phase shall be kIOPMTracePointSystemUp.
517 */
518 kIOPMTracePointSystemLoginwindowPhase = 0x30,
519
520 /* When kIOPMTracePointDarkWakeEntry is the latest tracePoint,
521 * PM has started a transition from full wake to dark wake.
522 *
523 * Phase begins: Start transition to dark wake.
524 * Phase ends: System in dark wake. Before recording kIOPMTracePointSystemUp.
525 */
526 kIOPMTracePointDarkWakeEntry = 0x31,
527
528 /* When kIOPMTracePointDarkWakeExit is the latest tracePoint,
529 * PM has started a transition from dark wake to full wake.
530 *
531 * Phase begins: Start transition to full wake.
532 * Phase ends: System in full wake. Before recording kIOPMTracePointSystemUp.
533 */
534 kIOPMTracePointDarkWakeExit = 0x32
535 };
536
537 /*****************************************************************************/
538
539 /*
540 * Component wake progress keys
541 *
542 * Certain components have the ability to log their wake progress with
543 * root domain using the keys provided below.
544 *
545 * LoginWindow - 4 bits
546 * CoreDisplay - 8 bits
547 * CoreGraphics - 8 bits
548 *
549 * These bits are stored with the trace phase that gets logged to
550 * the RTC register.
551 */
552
553 // Values that should be passed in to IOPMLogWakeProgress
554 enum {
555 kIOPMLoginWindowProgress = 1,
556 kIOPMCoreDisplayProgress = 2,
557 kIOPMCoreGraphicsProgress = 3
558 };
559
560 enum {
561 kIOPMLoginWindowProgressMask = 0x0f,
562 kIOPMCoreDisplayProgressMask = 0xff,
563 kIOPMCoreGraphicsProgressMask = 0xff
564 };
565
566 /*
567 * kIOPMLoginWindowProgressKey - identifies PM debug data specific to LoginWindow
568 * for use with IOPMrootDomain. Only 4 bits of data are allotted.
569 */
570 #define kIOPMLoginWindowProgressKey "LoginWindowProgress"
571
572 /*
573 * kIOPMCoreDisplayProgressKey - identifies PM debug data specific to CoreDisplay
574 * for use with IOPMrootDomain. Only 8 bits of data are allotted.
575 */
576 #define kIOPMCoreDisplayProgressKey "CoreDisplayProgress"
577
578 /*
579 * kIOPMCoreGraphicsProgressKey - identifies PM debug data specific to CoreGraphics
580 * for use with IOPMrootDomain. Only 8 bits of data are allotted.
581 */
582 #define kIOPMCoreGraphicsProgressKey "CoreGraphicsProgress"
583
584 // For PM internal use only - key to locate sleep failure results within SCDynamicStore.
585 #define kIOPMDynamicStoreSleepFailureKey "SleepFailure"
586
587 /*****************************************************************************/
588
589 // For IOPMLibPrivate.h
590 #define kIOPMSleepWakeFailureKey "PMFailurePhase"
591 #define kIOPMSleepWakeFailureCodeKey "PMStatusCode"
592 #define kIOPMSleepWakeFailureLoginKey "LWFailurePhase"
593 #define kIOPMSleepWakeFailureUUIDKey "UUID"
594 #define kIOPMSleepWakeFailureDateKey "Date"
595 #define kIOPMSleepWakeWdogRebootKey "SWWdogTriggeredRestart"
596 #define kIOPMSleepWakeWdogLogsValidKey "SWWdogLogsValid"
597
598 /*****************************************************************************
599 *
600 * Root Domain private property keys
601 *
602 *****************************************************************************/
603
604 /* kIOPMFeatureAutoPowerOffKey
605 * Feature published if Auto Power Off is supported
606 */
607 #define kIOPMFeatureAutoPowerOffKey "AutoPowerOff"
608
609 /* kIOPMAutoPowerOffEnabledKey
610 * Indicates if Auto Power Off is enabled.
611 * It has a boolean value.
612 * true == Auto Power Off is enabled
613 * false == Auto Power Off is disabled
614 * not present == Auto Power Off is not supported on this hardware
615 */
616 #define kIOPMAutoPowerOffEnabledKey "AutoPowerOff Enabled"
617
618 /* kIOPMAutoPowerOffDelayKey
619 * Key refers to a CFNumberRef that represents the delay in seconds before
620 * entering the Auto Power Off state. The property is not present if Auto
621 * Power Off is unsupported.
622 */
623 #define kIOPMAutoPowerOffDelayKey "AutoPowerOff Delay"
624
625 /* kIOPMAutoPowerOffTimerKey
626 * Key refers to a CFNumberRef that indicates the time in seconds until the
627 * expiration of the Auto Power Off delay period. This value should be used
628 * to program a wake alarm before system sleep.
629 */
630 #define kIOPMAutoPowerOffTimerKey "AutoPowerOff Timer"
631
632 /* kIOPMDeepSleepTimerKey
633 * Key refers to a CFNumberRef that indicates the time in seconds until the
634 * expiration of the Standby delay period. This value should be used
635 * to program a wake alarm before system sleep.
636 */
637 #define kIOPMDeepSleepTimerKey "Standby Timer"
638
639 /* kIOPMUserWakeAlarmScheduledKey
640 * Key refers to a boolean value that indicates if an user alarm was scheduled
641 * or pending.
642 */
643 #define kIOPMUserWakeAlarmScheduledKey "UserWakeAlarmScheduled"
644
645 /* kIOPMDeepIdleSupportedKey
646 * Presence of this key indicates Deep Idle is supported on this platform.
647 * Key will always refer to a value of kOSBooleanTrue.
648 */
649 #define kIOPMDeepIdleSupportedKey "IOPMDeepIdleSupported"
650
651 /* kIOPMUserTriggeredFullWakeKey
652 * Key refers to a boolean value that indicates if the first full wake since
653 * last system sleep was triggered by the local user. This property is set
654 * before the initial full wake transition, and removed after powering down
655 * drivers for system sleep.
656 */
657 #define kIOPMUserTriggeredFullWakeKey "IOPMUserTriggeredFullWake"
658
659 /* kIOPMUserIsActiveKey
660 * Key refers to a boolean value that indicates if the user is active.
661 */
662 #define kIOPMUserIsActiveKey "IOPMUserIsActive"
663
664 /* kIOPMDriverWakeEventsKey
665 * Key refers to a property that should only be examined by powerd.
666 */
667 #define kIOPMDriverWakeEventsKey "IOPMDriverWakeEvents"
668
669 /*****************************************************************************
670 *
671 * IOPMDriverWakeEvents dictionary keys
672 *
673 *****************************************************************************/
674
675 #define kIOPMWakeEventTimeKey "Time"
676 #define kIOPMWakeEventFlagsKey "Flags"
677 #define kIOPMWakeEventReasonKey "Reason"
678 #define kIOPMWakeEventDetailsKey "Details"
679
680 /*****************************************************************************
681 *
682 * Wake event flags reported to IOPMrootDomain::claimSystemWakeEvent()
683 *
684 *****************************************************************************/
685
686 #define kIOPMWakeEventSource 0x00000001
687
688 #if !(defined(RC_HIDE_N144) || defined(RC_HIDE_N146))
689 /*****************************************************************************
690 *
691 * AOT defs
692 *
693 *****************************************************************************/
694
695 // signals the device should wake up to user space running
696 #define kIOPMWakeEventAOTExit 0x00000002
697
698 // will start a 400 ms timer before sleeping
699 #define kIOPMWakeEventAOTPossibleExit 0x00000004
700
701 // signals the device should wake up to user space running
702 #define kIOPMWakeEventAOTConfirmedPossibleExit 0x00000008
703
704 // signals the device should go back to AOT
705 #define kIOPMWakeEventAOTRejectedPossibleExit 0x00000010
706
707 // signals the device should go back to AOT
708 #define kIOPMWakeEventAOTExpiredPossibleExit 0x00000020
709
710 #define kIOPMWakeEventAOTFlags \
711 (kIOPMWakeEventAOTExit \
712 | kIOPMWakeEventAOTPossibleExit \
713 | kIOPMWakeEventAOTConfirmedPossibleExit \
714 | kIOPMWakeEventAOTRejectedPossibleExit \
715 | kIOPMWakeEventAOTExpiredPossibleExit)
716
717 #define kIOPMWakeEventAOTPossibleFlags \
718 (kIOPMWakeEventAOTPossibleExit \
719 | kIOPMWakeEventAOTConfirmedPossibleExit \
720 | kIOPMWakeEventAOTRejectedPossibleExit \
721 | kIOPMWakeEventAOTExpiredPossibleExit)
722
723 #define kIOPMWakeEventAOTPerCycleFlags \
724 (kIOPMWakeEventAOTPossibleExit \
725 | kIOPMWakeEventAOTRejectedPossibleExit \
726 | kIOPMWakeEventAOTExpiredPossibleExit)
727
728 #define kIOPMWakeEventAOTExitFlags \
729 (kIOPMWakeEventAOTExit \
730 | kIOPMWakeEventAOTConfirmedPossibleExit)
731
732 enum {
733 kIOPMAOTModeEnable = 0x00000001,
734 kIOPMAOTModeCycle = 0x00000002,
735 kIOPMAOTModeAddEventFlags = 0x00000004,
736 kIOPMAOTModeRespectTimers = 0x00000008,
737 kIOPMAOTModeDefault = (kIOPMAOTModeEnable | kIOPMAOTModeAddEventFlags | kIOPMAOTModeRespectTimers)
738 };
739
740 enum {
741 kIOPMAOTMetricsKernelWakeCountMax = 24
742 };
743
744 struct IOPMAOTMetrics
745 {
746 uint32_t sleepCount;
747 uint32_t possibleCount;
748 uint32_t confirmedPossibleCount;
749 uint32_t rejectedPossibleCount;
750 uint32_t expiredPossibleCount;
751 uint32_t noTimeSetCount;
752 uint32_t rtcAlarmsCount;
753 uint32_t softwareRequestCount;
754 uint64_t totalTime;
755
756 char kernelWakeReason[kIOPMAOTMetricsKernelWakeCountMax][64];
757 // 54:10 secs:ms calendar time
758 uint64_t kernelSleepTime[kIOPMAOTMetricsKernelWakeCountMax];
759 uint64_t kernelWakeTime[kIOPMAOTMetricsKernelWakeCountMax];
760 };
761
762 #define kIOPMAOTPowerKey "aot-power"
763
764 #endif /* !(defined(RC_HIDE_N144) || defined(RC_HIDE_N146)) */
765
766 /*****************************************************************************
767 *
768 * System Sleep Policy
769 *
770 *****************************************************************************/
771
772 #define kIOPMSystemSleepPolicySignature 0x54504c53
773 #define kIOPMSystemSleepPolicyVersion 2
774
775 /*!
776 * @defined kIOPMSystemSleepTypeKey
777 * @abstract Indicates the type of system sleep.
778 * @discussion An OSNumber property of root domain that describes the type
779 * of system sleep. This property is set after notifying priority sleep/wake
780 * clients, but before informing interested drivers and shutting down power
781 * plane drivers. On a hibernate abort or failure, this property will not be
782 * updated and will indicate the failed sleep type.
783 */
784 #define kIOPMSystemSleepTypeKey "IOPMSystemSleepType"
785
786 struct IOPMSystemSleepPolicyVariables
787 {
788 uint32_t signature; // kIOPMSystemSleepPolicySignature
789 uint32_t version; // kIOPMSystemSleepPolicyVersion
790
791 uint64_t currentCapability; // current system capability bits
792 uint64_t highestCapability; // highest system capability bits
793
794 uint64_t sleepFactors; // sleep factor bits
795 uint32_t sleepReason; // kIOPMSleepReason*
796 uint32_t sleepPhase; // identify the sleep phase
797 uint32_t hibernateMode; // current hibernate mode
798
799 uint32_t standbyDelay; // standby delay in seconds
800 uint32_t standbyTimer; // standby timer in seconds
801 uint32_t poweroffDelay; // auto-poweroff delay in seconds
802 uint32_t scheduledAlarms; // bitmask of scheduled alarm types
803 uint32_t poweroffTimer; // auto-poweroff timer in seconds
804
805 uint32_t reserved[49]; // pad sizeof 256 bytes
806 };
807
808 enum {
809 kIOPMAlarmBitDebugWake = 0x01,
810 kIOPMAlarmBitCalendarWake = 0x02,
811 kIOPMAlarmBitMaintenanceWake = 0x04,
812 kIOPMAlarmBitSleepServiceWake = 0x08
813 };
814
815 enum {
816 kIOPMSleepPhase0 = 0,
817 kIOPMSleepPhase1,
818 kIOPMSleepPhase2
819 };
820
821 // Sleep Factor Mask / Bits
822 enum {
823 kIOPMSleepFactorSleepTimerWake = 0x00000001ULL,
824 kIOPMSleepFactorLidOpen = 0x00000002ULL,
825 kIOPMSleepFactorACPower = 0x00000004ULL,
826 kIOPMSleepFactorBatteryLow = 0x00000008ULL,
827 kIOPMSleepFactorStandbyNoDelay = 0x00000010ULL,
828 kIOPMSleepFactorStandbyForced = 0x00000020ULL,
829 kIOPMSleepFactorStandbyDisabled = 0x00000040ULL,
830 kIOPMSleepFactorUSBExternalDevice = 0x00000080ULL,
831 kIOPMSleepFactorBluetoothHIDDevice = 0x00000100ULL,
832 kIOPMSleepFactorExternalMediaMounted = 0x00000200ULL,
833 kIOPMSleepFactorThunderboltDevice = 0x00000400ULL,
834 kIOPMSleepFactorRTCAlarmScheduled = 0x00000800ULL,
835 kIOPMSleepFactorMagicPacketWakeEnabled = 0x00001000ULL,
836 kIOPMSleepFactorHibernateForced = 0x00010000ULL,
837 kIOPMSleepFactorAutoPowerOffDisabled = 0x00020000ULL,
838 kIOPMSleepFactorAutoPowerOffForced = 0x00040000ULL,
839 kIOPMSleepFactorExternalDisplay = 0x00080000ULL,
840 kIOPMSleepFactorNetworkKeepAliveActive = 0x00100000ULL,
841 kIOPMSleepFactorLocalUserActivity = 0x00200000ULL,
842 kIOPMSleepFactorHibernateFailed = 0x00400000ULL,
843 kIOPMSleepFactorThermalWarning = 0x00800000ULL,
844 kIOPMSleepFactorDisplayCaptured = 0x01000000ULL
845 };
846
847 // System Sleep Types
848 enum {
849 kIOPMSleepTypeInvalid = 0,
850 kIOPMSleepTypeAbortedSleep = 1,
851 kIOPMSleepTypeNormalSleep = 2,
852 kIOPMSleepTypeSafeSleep = 3,
853 kIOPMSleepTypeHibernate = 4,
854 kIOPMSleepTypeStandby = 5,
855 kIOPMSleepTypePowerOff = 6,
856 kIOPMSleepTypeDeepIdle = 7,
857 kIOPMSleepTypeLast = 8
858 };
859
860 // System Sleep Flags
861 enum {
862 kIOPMSleepFlagDisableHibernateAbort = 0x00000001,
863 kIOPMSleepFlagDisableUSBWakeEvents = 0x00000002,
864 kIOPMSleepFlagDisableBatlowAssertion = 0x00000004,
865 kIOPMSleepFlagDisableS4WakeSources = 0x00000008
866 };
867
868 // System Wake Events
869 enum {
870 kIOPMWakeEventLidOpen = 0x00000001,
871 kIOPMWakeEventLidClose = 0x00000002,
872 kIOPMWakeEventACAttach = 0x00000004,
873 kIOPMWakeEventACDetach = 0x00000008,
874 kIOPMWakeEventCDInsert = 0x00000010,
875 kIOPMWakeEventCDEject = 0x00000020,
876 kIOPMWakeEventHPDAttach = 0x00000040,
877 kIOPMWakeEventHPDDetach = 0x00000080,
878 kIOPMWakeEventPowerButton = 0x00000100,
879 kIOPMWakeEventG3PowerOn = 0x00000200,
880 kIOPMWakeEventUserPME = 0x00000400,
881 kIOPMWakeEventSleepTimer = 0x00000800,
882 kIOPMWakeEventBatteryLow = 0x00001000,
883 kIOPMWakeEventDarkPME = 0x00002000,
884 kIOPMWakeEventWifi = 0x00004000,
885 kIOPMWakeEventRTCSystem = 0x00008000, // Maintenance RTC wake
886 kIOPMWakeEventUSBCPlugin = 0x00010000, // USB-C Plugin
887 kIOPMWakeEventHID = 0x00020000,
888 kIOPMWakeEventBluetooth = 0x00040000,
889 kIOPMWakeEventDFR = 0x00080000,
890 kIOPMWakeEventSD = 0x00100000, // SD card
891 kIOPMWakeEventLANWake = 0x00200000, // Wake on Lan
892 kIOPMWakeEventLANPlugin = 0x00400000, // Ethernet media sense
893 kIOPMWakeEventThunderbolt = 0x00800000,
894 kIOPMWakeEventRTCUser = 0x01000000, // User requested RTC wake
895 };
896
897 /*!
898 * @defined kIOPMSystemSleepParametersKey
899 * @abstract Sleep parameters describing the upcoming sleep
900 * @discussion Root domain updates this OSData property before system sleep
901 * to pass sleep parameters to the platform driver. Some of the parameters
902 * are based on the chosen entry in the system sleep policy table.
903 */
904 #define kIOPMSystemSleepParametersKey "IOPMSystemSleepParameters"
905 #define kIOPMSystemSleepParametersVersion 2
906
907 struct IOPMSystemSleepParameters
908 {
909 uint16_t version;
910 uint16_t reserved1;
911 uint32_t sleepType;
912 uint32_t sleepFlags;
913 uint32_t ecWakeEvents;
914 uint32_t ecWakeTimer;
915 uint32_t ecPoweroffTimer;
916 uint32_t reserved2[10];
917 } __attribute__((packed));
918
919
920 /*
921 * Sleep Wake debug buffer header
922 */
923 typedef struct {
924 uint32_t signature;
925 uint32_t alloc_size;
926 uint32_t crc; /* CRC for spindump & following data.*/
927 uint32_t spindump_offset; /* Offset at which spindump offset is stored */
928 uint32_t spindump_size;
929 uint8_t is_osx_watchdog;
930
931 /* All members from UUID onwards are saved into log file */
932 char UUID[44];
933 char spindump_status[24]; /* stackshot status*/
934 char PMStatusCode[32];
935 char reason[32];
936 } swd_hdr;
937
938
939 #define SWD_HDR_SIGNATURE 0xdeb8da2a
940
941 #define SWD_STACKSHOT_SIZE (40*PAGE_SIZE)
942 #define SWD_COMPRESSED_BUFSIZE (5*PAGE_SIZE)
943 #define SWD_ZLIB_BUFSIZE (10*PAGE_SIZE)
944 #define SWD_STACKSHOT_VAR_PREFIX "sleepwake_diags"
945
946 #define SWD_SPINDUMP_SIZE (256*1024)
947 #define SWD_INITIAL_SPINDUMP_SIZE ((SWD_SPINDUMP_SIZE/2)-sizeof(swd_hdr))
948 #define SWD_MAX_STACKSHOTS (10)
949
950 /* Bits in swd_flags */
951 #define SWD_WDOG_ENABLED 0x01
952 #define SWD_BOOT_BY_SW_WDOG 0x02
953 #define SWD_BOOT_BY_OSX_WDOG 0x04
954 #define SWD_VALID_LOGS 0x08
955 #define SWD_LOGS_IN_FILE 0x10
956 #define SWD_LOGS_IN_MEM 0x20
957 #define SWD_PWR_BTN_STACKSHOT 0x30
958
959 #define SWD_DATA_CRC_ERROR 0x010000
960 #define SWD_BUF_SIZE_ERROR 0x020000
961 #define SWD_HDR_SIZE_ERROR 0x040000
962 #define SWD_FILEOP_ERROR 0x080000
963 #define SWD_HDR_SIGNATURE_ERROR 0x100000
964 #define SWD_INTERNAL_FAILURE 0x200000
965
966
967 /* Filenames associated with the stackshots/logs generated by the SWD */
968 #define kOSWatchdogStacksFilename "/var/log/OSXWatchdogStacks.gz"
969 #define kOSWatchdogFailureStringFile "/var/log/OSWatchdogFailureString.txt"
970 #define kSleepWakeStacksFilename "/var/log/SleepWakeStacks.gz"
971 #define kSleepWakeFailureStringFile "/var/log/SleepWakeFailureString.txt"
972
973
974 /* RootDomain IOReporting channels */
975 #define kSleepCntChID IOREPORT_MAKEID('S','l','e','e','p','C','n','t')
976 #define kDarkWkCntChID IOREPORT_MAKEID('G','U','I','W','k','C','n','t')
977 #define kUserWkCntChID IOREPORT_MAKEID('D','r','k','W','k','C','n','t')
978
979 /*
980 * kAssertDelayChID - Histogram of time elapsed before assertion after wake.
981 */
982 #define kAssertDelayBcktCnt 11
983 #define kAssertDelayBcktSize 3
984 #define kAssertDelayChID IOREPORT_MAKEID('r','d','A','s','r','t','D','l')
985
986 /*
987 * kSleepDelaysChID - Histogram of time taken to put system to sleep
988 */
989 #define kSleepDelaysBcktCnt 13
990 #define kSleepDelaysBcktSize 10
991 #define kSleepDelaysChID IOREPORT_MAKEID('r','d','S','l','p','D','l','y')
992
993 /* Sleep Options/settings */
994 #define kSleepOptionDisplayCapturedModeKey "DisplayCapturedMode"
995
996
997 #if defined(KERNEL) && defined(__cplusplus)
998
999 /*!
1000 * @defined kIOPMInstallSystemSleepPolicyHandlerKey
1001 * @abstract Name of the platform function to install a sleep policy handler.
1002 * @discussion Pass to IOPMrootDomain::callPlatformFunction(), with a pointer
1003 * to the C-function handler at param1, and an optional target at param2, to
1004 * register a sleep policy handler. Only a single sleep policy handler can
1005 * be installed.
1006 */
1007 #define kIOPMInstallSystemSleepPolicyHandlerKey \
1008 "IOPMInstallSystemSleepPolicyHandler"
1009
1010 typedef IOReturn (*IOPMSystemSleepPolicyHandler)(
1011 void * target,
1012 const IOPMSystemSleepPolicyVariables * vars,
1013 IOPMSystemSleepParameters * params );
1014
1015 #endif /* KERNEL */
1016
1017 /*****************************************************************************
1018 *
1019 * Performance Warning
1020 *
1021 *****************************************************************************/
1022
1023 /* Performance Warning Key
1024 * Key for performance warning event published using IOPMrootDomain::
1025 * systemPowerEventOccurred()
1026 */
1027 #define kIOPMPerformanceWarningKey "Performance_Warning"
1028
1029 /* Performance warning values */
1030 enum {
1031 kIOPMPerformanceNormal = 0,
1032 kIOPMPerformanceWarning = 100
1033 };
1034
1035 #endif /* ! _IOKIT_IOPMPRIVATE_H */