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