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