+/*****************************************************************************/
+/*****************************************************************************/
+
+/*
+ * PM notification types
+ */
+
+/*! @constant kIOPMSleepServiceScheduleImmediate
+ *
+ * Setting type used in calls to IOPMrootDomain::registerPMSettingController
+ * Use this type between powerd and IOKit.framework
+ *
+ */
+#define kIOPMSleepServiceScheduleImmediate "SleepServiceImmediate"
+
+/*! @constant kIOPMSettingSleepServiceScheduleImmediate
+ *
+ * Setting type used in calls to IOPMrootDomain::registerPMSettingController
+ * Use this type between xnu and AppleRTC
+ */
+#define kIOPMSettingSleepServiceWakeCalendarKey "SleepServiceWakeCalendarKey"
+
+/*! @constant kIOPMCalendarWakeTypes
+ *
+ * These are valid values for IOPM.h:IOPMCalendarStruct->selector
+ */
+enum {
+ kPMCalendarTypeMaintenance = 1,
+ kPMCalendarTypeSleepService = 2
+};
+
+
+/* @constant kIOPMStateConsoleShutdown
+ * @abstract Notification of GUI shutdown state available to kexts.
+ * @discussion This type can be passed as arguments to registerPMSettingController()
+ * to receive callbacks.
+ */
+#define kIOPMStateConsoleShutdown "ConsoleShutdown"
+
+/* @enum ShutdownValues
+ * @abstract Potential values shared with key kIOPMStateConsoleShutdown
+ */
+enum {
+/* @constant kIOPMStateConsoleShutdownNone
+ * @abstract System shutdown (or restart) hasn't started; system is ON.
+ * @discussion Next state: 2
+ */
+ kIOPMStateConsoleShutdownNone = 1,
+/* @constant kIOPMStateConsoleShutdownPossible
+ * @abstract User has been presented with the option to shutdown or restart. Shutdown may be cancelled.
+ * @discussion Next state may be: 1, 4
+ */
+ kIOPMStateConsoleShutdownPossible = 2,
+/* @constant kIOPMStateConsoleShutdownUnderway
+ * @abstract Shutdown or restart is proceeding. It may still be cancelled.
+ * @discussion Next state may be: 1, 4. This state is currently unused.
+ */
+ kIOPMStateConsoleShutdownUnderway = 3,
+/* @constant kIOPMStateConsoleShutdownCertain
+ * @abstract Shutdown is in progress and irrevocable.
+ * @discussion State remains 4 until power is removed from CPU.
+ */
+ kIOPMStateConsoleShutdownCertain = 4,
+/* @constant kIOPMStateConsoleSULogoutInitiated
+ Indicates that LoginWindow has initiated a software update restart.
+ The next logout will not immediately lead to a shutdown.
+ */
+ kIOPMStateConsoleSULogoutInitiated = 5
+};
+
+/* @constant kIOPMSettingSilentRunningKey
+ * @abstract Notification of silent running mode changes to kexts.
+ * @discussion This key can be passed as an argument to registerPMSettingController()
+ * and also identifies the type of PMSetting notification callback.
+ */
+#define kIOPMSettingSilentRunningKey "SilentRunning"
+#define kIOPMFeatureSilentRunningKey kIOPMSettingSilentRunningKey
+
+/* @enum SilentRunningFlags
+ * @abstract The kIOPMSettingSilentRunningKey notification provides an OSNumber
+ * object with a value described by the following flags.
+ */
+enum {
+ kIOPMSilentRunningModeOn = 0x00000001
+};
+
+/*****************************************************************************/
+/*****************************************************************************/
+
+/* PM Statistics - event indices
+ * These are arguments to IOPMrootDomain::pmStatsRecordEvent().
+ */
+enum {
+ kIOPMStatsHibernateImageWrite = 1,
+ kIOPMStatsHibernateImageRead,
+ kIOPMStatsDriversNotify,
+ kIOPMStatsApplicationNotify,
+ kIOPMStatsLateDriverAcknowledge,
+ kIOPMStatsLateAppAcknowledge,
+
+ // To designate if you're specifying the start or stop end of
+ // each of the above events, do a bitwise OR of the appropriate
+ // Start/Stop flag and pass the result to IOPMrootDomain to record
+ // the event.
+ kIOPMStatsEventStartFlag = (1 << 24),
+ kIOPMStatsEventStopFlag = (1 << 25)
+};
+
+// Keys for IOPMrootDomain registry properties
+#define kIOPMSleepStatisticsKey "SleepStatistics"
+#define kIOPMSleepStatisticsAppsKey "AppStatistics"
+#define kIOPMIdleSleepPreventersKey "IdleSleepPreventers"
+#define kIOPMSystemSleepPreventersKey "SystemSleepPreventers"
+
+// Application response statistics
+#define kIOPMStatsNameKey "Name"
+#define kIOPMStatsPIDKey "Pid"
+#define kIOPMStatsTimeMSKey "TimeMS"
+#define kIOPMStatsApplicationResponseTypeKey "ResponseType"
+#define kIOPMStatsMessageTypeKey "MessageType"
+#define kIOPMStatsPowerCapabilityKey "PowerCaps"
+#define kIOPMStatsSystemTransitionKey "TransitionType"
+
+// PM Statistics: potential values for the key kIOPMStatsApplicationResponseTypeKey
+// entry in the application results array.
+#define kIOPMStatsResponseTimedOut "ResponseTimedOut"
+#define kIOPMStatsResponseCancel "ResponseCancel"
+#define kIOPMStatsResponseSlow "ResponseSlow"
+#define kIOPMStatsResponsePrompt "ResponsePrompt"
+#define kIOPMStatsDriverPSChangeSlow "DriverPSChangeSlow"
+
+struct PMStatsBounds{
+ uint64_t start;
+ uint64_t stop;
+};
+typedef struct {
+
+ struct PMStatsBounds hibWrite;
+ struct PMStatsBounds hibRead;
+// bounds driverNotifySleep;
+// bounds driverNotifyWake;
+// bounds appNotifySleep;
+// bounds appNotifyWake;
+// OSDictionary *tardyApps;
+// OSDictionary *tardyDrivers;
+} PMStatsStruct;
+
+/*****************************************************************************/
+
+/* PM RootDomain tracePoints
+ *
+ * In the sleep/wake process, we expect the sleep trace points to proceed
+ * in increasing order. Once sleep begins with code kIOPMTracePointSleepStarted,
+ * we expect sleep to continue in a monotonically increasing order of tracepoints
+ * to kIOPMTracePointSystemLoginwindowPhase. After trace point SystemLoginWindowPhase,
+ * the system will return to kIOPMTracePointSystemUp.
+ *
+ * If the trace point decreases (instead of increasing) before reaching kIOPMTracePointSystemUp,
+ * that indicates that the sleep process was cancelled. The cancel reason shall be indicated
+ * in the cancel tracepoint. (TBD)
+ */
+
+enum {
+/* When kTracePointSystemUp is the latest tracePoint,
+ * the system is awake. It is not asleep, sleeping, or waking.
+ *
+ * Phase begins: At boot, at completion of wake from sleep,
+ * immediately following kIOPMTracePointSystemLoginwindowPhase.
+ * Phase ends: When a sleep attempt is initiated.
+ */
+ kIOPMTracePointSystemUp = 0,
+
+/* When kIOPMTracePointSleepStarted is the latest tracePoint,
+ * sleep has been initiated.
+ *
+ * Phase begins: At initiation of system sleep (idle or forced).
+ * Phase ends: PM starts to notify applications of system sleep.
+ */
+ kIOPMTracePointSleepStarted = 0x10,
+
+/* When kIOPMTracePointSleepApplications is the latest tracePoint,
+ * a system sleep has been initiated and PM waits for responses
+ * from notified applications.
+ *
+ * Phase begins: Begin to asynchronously fire kIOMessageSystemWillSleep
+ * notifications, and also kIOMessageCanSystemSleep for the idle sleep case.
+ * Phase ends: When PM has received all application responses.
+ */
+ kIOPMTracePointSleepApplications = 0x11,
+
+/* When kIOPMTracePointSleepPriorityClients is the latest tracePoint,
+ * PM is notifying priority clients and in-kernel system capability
+ * clients, and waiting for any asynchronous completions.
+ *
+ * Phase begins: Synchronous delivery of kIOMessageSystemWillSleep notifications.
+ * Phase ends: All notified clients have acknowledged.
+ */
+ kIOPMTracePointSleepPriorityClients = 0x12,
+
+/* When kIOPMTracePointSleepWillChangeInterests is the latest tracePoint,
+ * PM is calling powerStateWillChangeTo() on interested drivers of root domain.
+ *
+ * Phase begins: Dispatch a callout thread to call interested drivers.
+ * Phase ends: Callout thread work done, and acknowledgePowerChange() called
+ * by drivers that indicated asynchronous completion.
+ */
+ kIOPMTracePointSleepWillChangeInterests = 0x13,
+
+/* When kIOPMTracePointSleepPowerPlaneDrivers is the latest tracePoint,
+ * PM is directing power plane drivers to power off in leaf-to-root order.
+ *
+ * Phase begins: Root domain informs its power children that it will drop to
+ * sleep state. This has a cascade effect and triggers all drivers in
+ * the power plane to transition to a lower power state if necessary.
+ * Phase ends: All power transitions in response to the root domain power
+ * change have completed.
+ */
+ kIOPMTracePointSleepPowerPlaneDrivers = 0x14,
+
+/* When kIOPMTracePointSleepDidChangeInterests is the latest tracePoint,
+ * PM is calling powerStateDidChangeTo() on interested drivers of root domain.
+ *
+ * Phase begins: Dispatch a callout thread to call interested drivers.
+ * Phase ends: Callout thread work done, and acknowledgePowerChange() called
+ * by drivers that indicated asynchronous completion.
+ */
+ kIOPMTracePointSleepDidChangeInterests = 0x15,
+
+/* When kIOPMTracePointSleepCapabilityClients is the latest tracePoint,
+ * PM is notifying system capability clients about system sleep.
+ *
+ * Phase begins: Send kIOMessageSystemCapabilityChange notifications to inform
+ * capability clients that system has lost all capabilities.
+ * Phase ends: Finished sending notifications.
+ */
+ kIOPMTracePointSleepCapabilityClients = 0x16,
+
+/* When kIOPMTracePointSleepPlatformActions is the latest tracePoint,
+ * PM is calling drivers that have registered a platform sleep action.
+ */
+ kIOPMTracePointSleepPlatformActions = 0x17,
+
+/* When kIOPMTracePointSleepCPUs is the latest tracePoint,
+ * PM is shutting down all non-boot processors.
+ *
+ * Phase begins: Shutdown all non-boot processors.
+ * Phase ends: Reduced to only the boot processor running.
+ */
+ kIOPMTracePointSleepCPUs = 0x18,
+
+/* When kIOPMTracePointSleepPlatformDriver is the latest tracePoint,
+ * PM is executing platform dependent code to prepare for system sleep.
+ */
+ kIOPMTracePointSleepPlatformDriver = 0x19,
+
+/* When kIOPMTracePointHibernate is the latest tracePoint,
+ * PM is writing the hibernate image to disk.
+ */
+ kIOPMTracePointHibernate = 0x1a,
+
+/* When kIOPMTracePointSystemSleep is the latest tracePoint,
+ * PM has recorded the final trace point before the hardware platform
+ * enters sleep state, or low level wakeup is underway - such as restoring
+ * the hibernate image from disk.
+ *
+ * Note: If a system is asleep and then loses power, and it does not have a
+ * hibernate image to restore from (e.g. hibernatemode = 0), then OS X will
+ * interpret this power loss as a failure in kIOPMTracePointSystemSleep.
+ *
+ * Phase begins: Before the OS directs the hardware to enter sleep state.
+ * Phase ends: Control returns to the OS on wake, but before recording the first
+ * wake trace point.
+ */
+ kIOPMTracePointSystemSleep = 0x1f,
+
+/* When kIOPMTracePointWakePlatformDriver is the latest tracePoint,
+ * PM is executing platform dependent code to prepare for system wake.
+ */
+ kIOPMTracePointWakePlatformDriver = 0x21,
+
+/* When kIOPMTracePointWakePlatformActions is the latest tracePoint,
+ * PM is calling drivers that have registered a platform wake action.
+ */
+ kIOPMTracePointWakePlatformActions = 0x22,
+
+/* When kIOPMTracePointWakeCPUs is the latest tracePoint,
+ * PM is bringing all non-boot processors online.
+ */
+ kIOPMTracePointWakeCPUs = 0x23,
+
+/* When kIOPMTracePointWakeWillPowerOnClients is the latest tracePoint,
+ * PM is sending kIOMessageSystemWillPowerOn to both kernel clients and
+ * applications. PM also notifies system capability clients about the
+ * proposed capability change.
+ *
+ * Phase begins: Send kIOMessageSystemWillPowerOn and
+ * kIOMessageSystemCapabilityChange notifications.
+ * Phase ends: Finished sending notifications.
+ */
+ kIOPMTracePointWakeWillPowerOnClients = 0x24,
+
+/* When kIOPMTracePointWakeWillChangeInterests is the latest tracePoint,
+ * PM is calling powerStateWillChangeTo() on interested drivers of root domain.
+ *
+ * Phase begins: Dispatch a callout thread to call interested drivers.
+ * Phase ends: Callout thread work done, and acknowledgePowerChange() called
+ * by drivers that indicated asynchronous completion.
+ */
+ kIOPMTracePointWakeWillChangeInterests = 0x25,
+
+/* When kIOPMTracePointWakeDidChangeInterests is the latest tracePoint,
+ * PM is calling powerStateDidChangeTo() on interested drivers of root domain.
+ *
+ * Phase begins: Dispatch a callout thread to call interested drivers.
+ * Phase ends: Callout thread work done, and acknowledgePowerChange() called
+ * by drivers that indicated asynchronous completion.
+ */
+ kIOPMTracePointWakeDidChangeInterests = 0x26,
+
+/* When kIOPMTracePointWakePowerPlaneDrivers is the latest tracePoint,
+ * PM is directing power plane drivers to power up in root-to-leaf order.
+ *
+ * Phase begins: Root domain informs its power children that it transitioned
+ * to ON state. This has a cascade effect and triggers all drivers in
+ * the power plane to re-evaluate and potentially change power state.
+ * Phase ends: All power transitions in response to the root domain power
+ * change have completed.
+ */
+ kIOPMTracePointWakePowerPlaneDrivers = 0x27,
+
+/* When kIOPMTracePointWakeCapabilityClients is the latest tracePoint,
+ * PM is notifying system capability clients about system wake, and waiting
+ * for any asynchronous completions.
+ *
+ * Phase begins: Inform capability clients that system has gained capabilities.
+ * Phase ends: All notified clients have acknowledged.
+ */
+ kIOPMTracePointWakeCapabilityClients = 0x28,
+
+/* When kIOPMTracePointWakeApplications is the latest tracePoint,
+ * System CPU is powered, PM has powered on each driver.
+ *
+ * Phase begins: Send asynchronous kIOMessageSystemHasPoweredOn notifications.
+ * Phase ends: Finished sending asynchronous notifications.
+ */
+ kIOPMTracePointWakeApplications = 0x29,
+
+/* kIOPMTracePointSystemLoginwindowPhase
+ * This phase represents a several minute window after the system has powered on.
+ * Higher levels of system diagnostics are in a heightened state of alert in this phase,
+ * in case any user errors occurred that we could not detect in software.
+ *
+ * Phase begins: After IOPMrootDomain sends kIOMessageSystemHasPoweredOn message.
+ * Phase ends: When loginwindow calls IOPMSleepWakeSetUUID(NULL) the system shall
+ * be considered awake and usable. The next phase shall be kIOPMTracePointSystemUp.
+ */
+ kIOPMTracePointSystemLoginwindowPhase = 0x30,
+
+/* When kIOPMTracePointDarkWakeEntry is the latest tracePoint,
+ * PM has started a transition from full wake to dark wake.
+ *
+ * Phase begins: Start transition to dark wake.
+ * Phase ends: System in dark wake. Before recording kIOPMTracePointSystemUp.
+ */
+ kIOPMTracePointDarkWakeEntry = 0x31,
+
+/* When kIOPMTracePointDarkWakeExit is the latest tracePoint,
+ * PM has started a transition from dark wake to full wake.
+ *
+ * Phase begins: Start transition to full wake.
+ * Phase ends: System in full wake. Before recording kIOPMTracePointSystemUp.
+ */
+ kIOPMTracePointDarkWakeExit = 0x32
+};
+
+/*****************************************************************************/
+
+/*
+Ê* kIOPMLoginWindowSecurityDebugKey - identifies PM debug data specific to LoginWindow
+ * for use with IOPMrootDomain.
+Ê*/
+#define kIOPMLoginWindowSecurityDebugKey "LoginWindowSecurity"
+
+// For PM internal use only - key to locate sleep failure results within SCDynamicStore.
+#define kIOPMDynamicStoreSleepFailureKey "SleepFailure"
+
+/*****************************************************************************/
+
+// For IOPMLibPrivate.h
+#define kIOPMSleepWakeFailureKey "PMFailurePhase"
+#define kIOPMSleepWakeFailureCodeKey "PMStatusCode"
+#define kIOPMSleepWakeFailureLoginKey "LWFailurePhase"
+#define kIOPMSleepWakeFailureUUIDKey "UUID"
+#define kIOPMSleepWakeFailureDateKey "Date"
+#define kIOPMSleepWakeWdogRebootKey "SWWdogTriggeredRestart"
+#define kIOPMSleepWakeWdogLogsValidKey "SWWdogLogsValid"
+
+/*****************************************************************************
+ *
+ * Root Domain private property keys
+ *
+ *****************************************************************************/
+
+/* kIOPMFeatureAutoPowerOffKey
+ * Feature published if Auto Power Off is supported
+ */
+#define kIOPMFeatureAutoPowerOffKey "AutoPowerOff"
+
+/* kIOPMAutoPowerOffEnabledKey
+ * Indicates if Auto Power Off is enabled.
+ * It has a boolean value.
+ * true == Auto Power Off is enabled
+ * false == Auto Power Off is disabled
+ * not present == Auto Power Off is not supported on this hardware
+ */
+#define kIOPMAutoPowerOffEnabledKey "AutoPowerOff Enabled"
+
+/* kIOPMAutoPowerOffDelayKey
+ * Key refers to a CFNumberRef that represents the delay in seconds before
+ * entering the Auto Power Off state. The property is not present if Auto
+ * Power Off is unsupported.
+ */
+#define kIOPMAutoPowerOffDelayKey "AutoPowerOff Delay"
+
+/* kIOPMAutoPowerOffTimerKey
+ * Key refers to a CFNumberRef that indicates the time in seconds until the
+ * expiration of the Auto Power Off delay period. This value should be used
+ * to program a wake alarm before system sleep.
+ */
+#define kIOPMAutoPowerOffTimerKey "AutoPowerOff Timer"
+
+/* kIOPMUserWakeAlarmScheduledKey
+ * Key refers to a boolean value that indicates if an user alarm was scheduled
+ * or pending.
+ */
+#define kIOPMUserWakeAlarmScheduledKey "UserWakeAlarmScheduled"
+
+/* kIOPMDeepIdleSupportedKey
+ * Presence of this key indicates Deep Idle is supported on this platform.
+ * Key will always refer to a value of kOSBooleanTrue.
+ */
+#define kIOPMDeepIdleSupportedKey "IOPMDeepIdleSupported"
+
+/* kIOPMUserTriggeredFullWakeKey
+ * Key refers to a boolean value that indicates if the first full wake since
+ * last system sleep was triggered by the local user. This property is set
+ * before the initial full wake transition, and removed after powering down
+ * drivers for system sleep.
+ */
+#define kIOPMUserTriggeredFullWakeKey "IOPMUserTriggeredFullWake"
+
+/* kIOPMUserIsActiveKey
+ * Key refers to a boolean value that indicates if the user is active.
+ */
+#define kIOPMUserIsActiveKey "IOPMUserIsActive"
+
+/* kIOPMDriverWakeEventsKey
+ * Key refers to a property that should only be examined by powerd.
+ */
+#define kIOPMDriverWakeEventsKey "IOPMDriverWakeEvents"
+
+/*****************************************************************************
+ *
+ * IOPMDriverWakeEvents dictionary keys
+ *
+ *****************************************************************************/
+
+#define kIOPMWakeEventTimeKey "Time"
+#define kIOPMWakeEventFlagsKey "Flags"
+#define kIOPMWakeEventReasonKey "Reason"
+#define kIOPMWakeEventDetailsKey "Details"
+
+/*****************************************************************************
+ *
+ * Wake event flags reported to IOPMrootDomain::claimSystemWakeEvent()
+ *
+ *****************************************************************************/
+
+#define kIOPMWakeEventSource 0x00000001
+
+/*****************************************************************************
+ *
+ * System Sleep Policy
+ *
+ *****************************************************************************/
+
+#define kIOPMSystemSleepPolicySignature 0x54504c53
+#define kIOPMSystemSleepPolicyVersion 2
+
+/*!
+ * @defined kIOPMSystemSleepTypeKey
+ * @abstract Indicates the type of system sleep.
+ * @discussion An OSNumber property of root domain that describes the type
+ * of system sleep. This property is set after notifying priority sleep/wake
+ * clients, but before informing interested drivers and shutting down power
+ * plane drivers. On a hibernate abort or failure, this property will not be
+ * updated and will indicate the failed sleep type.
+ */
+#define kIOPMSystemSleepTypeKey "IOPMSystemSleepType"
+
+struct IOPMSystemSleepPolicyVariables
+{
+ uint32_t signature; // kIOPMSystemSleepPolicySignature
+ uint32_t version; // kIOPMSystemSleepPolicyVersion