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