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