2 * Copyright (c) 2002 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
28 #ifndef _IOKIT_IOPMPRIVATE_H
29 #define _IOKIT_IOPMPRIVATE_H
31 #include <IOKit/pwr_mgt/IOPM.h>
33 #pragma mark PM Timeline Logging
34 /**************************************************
36 * Timeline API Keys - Reports timing details for
37 * applications, drivers, and system during PM activity
39 * For kernel-internal use only
40 **************************************************/
42 // Keys for interfacing with IOPMrootDomain Timeline
43 /* @constant kIOPMTimelineDictionaryKey
44 * @abstract RootDomain key for dictionary describing Timeline's info
46 #define kIOPMTimelineDictionaryKey "PMTimelineLogging"
48 /* @constant kIOPMTimelineEnabledKey
49 * @abstract Boolean value indicating whether the system is recording PM events.
50 * @discussion Key may be found in the dictionary at IOPMrootDomain's property
51 * kIOPMTimelineDictionaryKey. uint32_t value; may be 0.
53 #define kIOPMTimelineEnabledKey "TimelineEnabled"
55 /* @constant kIOMPTimelineSystemNumberTrackedKey
56 * @abstract The maximum number of system power events the system may record.
57 * @discussion Key may be found in the dictionary at IOPMrootDomain's property
58 * kIOPMTimelineDictionaryKey. uint32_t value; may be 0.
60 #define kIOPMTimelineSystemNumberTrackedKey "TimelineSystemEventsTracked"
62 /* @constant kIOPMTimelineSystemBufferSizeKey
63 * @abstract Size in bytes of buffer recording system PM events
64 * @discussion Key may be found in the dictionary at IOPMrootDomain's property
65 * kIOPMTimelineDictionaryKey. uint32_t value; may be 0.
67 #define kIOPMTimelineSystemBufferSizeKey "TimelineSystemBufferSize"
71 /* @constant kIOPMEventTypeIntermediateFlag
72 * @abstract This bit indicates the event is an intermediate event
73 * which must occur within a major system power event.
75 #define kIOPMEventTypeIntermediateFlag 0x10000000
77 /* @enum SystemEventTypes
78 * @abstract Potential system events logged in the system event record.
81 kIOPMEventTypeUndefined
= 0,
83 /* Event types mark driver events
85 kIOPMEventTypeSetPowerStateImmediate
= 1001,
86 kIOPMEventTypeSetPowerStateDelayed
= 1002,
87 kIOPMEventTypePSWillChangeTo
= 1003,
88 kIOPMEventTypePSDidChangeTo
= 1004,
89 kIOPMEventTypeAppResponse
= 1005,
92 /* Start and stop event types bracket major
93 * system power management events.
95 kIOPMEventTypeSleep
= 2001,
96 kIOPMEventTypeSleepDone
= 2002,
97 kIOPMEventTypeWake
= 3001,
98 kIOPMEventTypeWakeDone
= 3002,
99 kIOPMEventTypeDoze
= 4001,
100 kIOPMEventTypeDozeDone
= 4002,
101 kIOPMEventTypeLiteWakeUp
= 5001,
102 kIOPMEventTypeLiteWakeUpDone
= 5002,
103 kIOPMEventTypeLiteWakeDown
= 5003,
104 kIOPMEventTypeLiteWakeDownDone
= 5004,
105 kIOPMEventTypeUUIDSet
= 6001,
106 kIOPMEventTypeUUIDClear
= 6002,
108 /* Intermediate events that may only occur within the bounds
109 * of a major system event (between the event's initiation and its "done event".)
110 * e.g. chronologically kIOPMEventTypeSleep may be followed by one or more
111 * intermediate events, which then must be followed by kIOPMEventTypeSleepDone.
113 * The intermediate events below will always occur in a Sleep or Wake event, and may
114 * or may not occur for any of the other events.
116 kIOPMEventTypeAppNotificationsFinished
= 501 | kIOPMEventTypeIntermediateFlag
,
117 kIOPMEventTypeDriverNotificationsFinished
= 502 | kIOPMEventTypeIntermediateFlag
,
118 kIOPMEventTypeCalTimeChange
= 503 | kIOPMEventTypeIntermediateFlag
122 /* @enum SystemSleepReasons
123 * @abstract The potential causes for system sleep as logged in the system event record.
126 kIOPMSleepReasonClamshell
= 101,
127 kIOPMSleepReasonPowerButton
= 102,
128 kIOPMSleepReasonSoftware
= 103,
129 kIOPMSleepReasonOSSwitchHibernate
= 104,
130 kIOPMSleepReasonIdle
= 105,
131 kIOPMSleepReasonLowPower
= 106,
132 kIOPMSleepReasonThermalEmergency
= 107,
133 kIOPMSleepReasonMaintenance
= 108
137 * Possible C-string sleep reasons found under kRootDomainSleepReasonsKey
139 #define kIOPMClamshellSleepKey "Clamshell Sleep"
140 #define kIOPMPowerButtonSleepKey "Power Button Sleep"
141 #define kIOPMSoftwareSleepKey "Software Sleep"
142 #define kIOPMOSSwitchHibernationKey "OS Switch Sleep"
143 #define kIOPMIdleSleepKey "Idle Sleep"
144 #define kIOPMLowPowerSleepKey "Low Power Sleep"
145 #define kIOPMThermalEmergencySleepKey "Thermal Emergency Sleep"
149 kIOPMMaxSystemEventsTracked
= 25000,
150 kIOPMDefaultSystemEventsTracked
= 1000,
151 kMaxPMStringLength
= 40,
154 /* @struct IOPMSystemEventRecord
155 * @abstract Records a singe power event to a particular PM entity.
156 * This includes changes to a driver's power state, application responses
157 * to PM notifications, or system power management milestones.
162 char ownerName
[kMaxPMStringLength
];
163 // For SYSTEM events, uuid contains the string describing the active UUID
164 char uuid
[kMaxPMStringLength
];
167 // For DRIVER events - records the name of the driver who generated the notifications.
168 char interestName
[kMaxPMStringLength
];
170 // DRIVER & SYSTEM - Times are stored as uint64_t
171 // The high 32 bytes are the seconds returned from clock_get_calendar_microtime,
172 // and the low 32 bytes are the accompanying microseconds.
176 // For DRIVER events - ownerDisambiguateID is a unique descriptor of the driver, to disambiguate
177 // several similarly named drivers.
178 uint64_t ownerDisambiguateID
;
179 // For SYSTEM events - eventReason is a value in SystemSleepReason
180 uint64_t eventReason
;
183 // DRIVER & SYSTEM - eventType is one of 'SystemEventTypes'
184 // The value of eventType determines, among ohter things, whether this is a SYSTEM or
185 // DRIVER event type.
188 // DRIVER & SYSTEM - eventResult is an IOReturn value
189 uint32_t eventResult
;
191 // DRIVER - If defined, elapsedTimeUS records the entire time a transaction took to complete
192 uint32_t elapsedTimeUS
;
194 // DRIVER - in power state changes, oldState & newState are PM power state indices.
197 } IOPMSystemEventRecord
;
199 /* @struct IOPMTraceBufferHeader
200 * Occupies the first bytes in the buffer allocated by IOPMrootDomain
201 * Describes the size and current index of the trace buffer
205 uint32_t sizeEntries
;
207 } IOPMTraceBufferHeader
;
209 /* Argument to IOPMrootDomain::clientMemoryForType to acquire
213 kPMRootDomainMapTraceBuffer
= 1
216 /**************************************************
218 * Accountability API Ends here
220 **************************************************/
223 #pragma mark Stray Bitfields
224 // Private power commands issued to root domain
225 // bits 0-7 in IOPM.h
228 kIOPMSetValue
= (1<<16),
229 // don't sleep on clamshell closure on a portable with AC connected
230 kIOPMSetDesktopMode
= (1<<17),
231 // set state of AC adaptor connected
232 kIOPMSetACAdaptorConnected
= (1<<18)
235 /*****************************************************************************/
236 /*****************************************************************************/
239 * PM notification types
242 /* @constant kIOPMStateConsoleUserShutdown
243 * @abstract Notification of GUI shutdown state available to kexts.
244 * @discussion This type can be passed as arguments to registerPMSettingController()
245 * to receive callbacks.
247 #define kIOPMStateConsoleShutdown "ConsoleShutdown"
249 /* @enum ShutdownValues
250 * @abstract Potential values shared with key kIOPMStateConsoleUserShutdown
253 /* @constant kIOPMStateConsoleShutdownNone
254 * @abstract System shutdown (or restart) hasn't started; system is ON.
255 * @discussion Next state: 2
257 kIOPMStateConsoleShutdownNone
= 1,
258 /* @constant kIOPMStateConsoleShutdownPossible
259 * @abstract User has been presented with the option to shutdown or restart. Shutdown may be cancelled.
260 * @discussion Next state may be: 1, 4
262 kIOPMStateConsoleShutdownPossible
= 2,
263 /* @constant kIOPMStateConsoleShutdownUnderway
264 * @abstract Shutdown or restart is proceeding. It may still be cancelled.
265 * @discussion Next state may be: 1, 4. This state is currently unused.
267 kIOPMStateConsoleShutdownUnderway
= 3,
268 /* @constant kIOPMStateConsoleShutdownCertain
269 * @abstract Shutdown is in progress and irrevocable.
270 * @discussion State remains 4 until power is removed from CPU.
272 kIOPMStateConsoleShutdownCertain
= 4
275 /*****************************************************************************/
276 /*****************************************************************************/
278 /* PM Statistics - event indices
279 * These are arguments to IOPMrootDomain::pmStatsRecordEvent().
282 kIOPMStatsHibernateImageWrite
= 1,
283 kIOPMStatsHibernateImageRead
,
284 kIOPMStatsDriversNotify
,
285 kIOPMStatsApplicationNotify
,
286 kIOPMStatsLateDriverAcknowledge
,
287 kIOPMStatsLateAppAcknowledge
,
289 // To designate if you're specifying the start or stop end of
290 // each of the above events, do a bitwise OR of the appropriate
291 // Start/Stop flag and pass the result to IOPMrootDomain to record
293 kIOPMStatsEventStartFlag
= (1 << 24),
294 kIOPMStatsEventStopFlag
= (1 << 25)
297 // Keys for IOPMrootDomain registry properties
298 #define kIOPMSleepStatisticsKey "SleepStatistics"
299 #define kIOPMSleepStatisticsAppsKey "AppStatistics"
301 // Application response statistics
302 #define kIOPMStatsNameKey "Name"
303 #define kIOPMStatsPIDKey "Pid"
304 #define kIOPMStatsTimeMSKey "TimeMS"
305 #define kIOPMStatsApplicationResponseTypeKey "ResponseType"
306 #define kIOPMStatsMessageTypeKey "MessageType"
308 // PM Statistics: potential values for the key kIOPMStatsApplicationResponseTypeKey
309 // entry in the application results array.
310 #define kIOPMStatsResponseTimedOut "ResponseTimedOut"
311 #define kIOPMStatsResponseCancel "ResponseCancel"
312 #define kIOPMStatsResponseSlow "ResponseSlow"
320 struct bounds hibWrite
;
321 struct bounds hibRead
;
322 // bounds driverNotifySleep;
323 // bounds driverNotifyWake;
324 // bounds appNotifySleep;
325 // bounds appNotifyWake;
326 // OSDictionary *tardyApps;
327 // OSDictionary *tardyDrivers;
330 /*****************************************************************************/
332 /* PM RootDomain tracePoints
334 * In the sleep/wake process, we expect the sleep trace points to proceed
335 * in increasing order. Once sleep begins with code kIOPMTracePointSleepStarted,
336 * we expect sleep to continue in a monotonically increasing order of tracepoints
337 * to kIOPMTracePointSystemLoginwindowPhase. After trace point SystemLoginWindowPhase,
338 * the system will return to kIOPMTracePointSystemUp.
340 * If the trace point decreases (instead of increasing) before reaching kIOPMTracePointSystemUp,
341 * that indicates that the sleep process was cancelled. The cancel reason shall be indicated
342 * in the cancel tracepoint. (TBD)
346 /* When kTracePointSystemUp is the latest tracePoint,
347 * the system is awake. It is not asleep, sleeping, or waking.
349 * Phase begins: At boot, at completion of wake from sleep,
350 * immediately following kIOPMTracePointSystemLoginwindowPhase.
351 * Phase ends: When a sleep attempt is initiated.
353 kIOPMTracePointSystemUp
= 0,
355 /* When kIOPMTracePointSleepStarted is the latest tracePoint,
356 * sleep has been initiated.
358 * Phase begins: At initiation of system sleep (idle or forced).
359 * Phase ends: PM starts to notify applications of system sleep.
361 kIOPMTracePointSleepStarted
= 0x10,
363 /* When kIOPMTracePointSleepApplications is the latest tracePoint,
364 * a system sleep has been initiated and PM waits for responses
365 * from notified applications.
367 * Phase begins: Begin to asynchronously fire kIOMessageSystemWillSleep
368 * notifications, and also kIOMessageCanSystemSleep for the idle sleep case.
369 * Phase ends: When PM has received all application responses.
371 kIOPMTracePointSleepApplications
= 0x11,
373 /* When kIOPMTracePointSleepPriorityClients is the latest tracePoint,
374 * PM is notifying priority clients and in-kernel system capability
375 * clients, and waiting for any asynchronous completions.
377 * Phase begins: Synchronous delivery of kIOMessageSystemWillSleep notifications.
378 * Phase ends: All notified clients have acknowledged.
380 kIOPMTracePointSleepPriorityClients
= 0x12,
382 /* When kIOPMTracePointSleepWillChangeInterests is the latest tracePoint,
383 * PM is calling powerStateWillChangeTo() on interested drivers of root domain.
385 * Phase begins: Dispatch a callout thread to call interested drivers.
386 * Phase ends: Callout thread work done, and acknowledgePowerChange() called
387 * by drivers that indicated asynchronous completion.
389 kIOPMTracePointSleepWillChangeInterests
= 0x13,
391 /* When kIOPMTracePointSleepPowerPlaneDrivers is the latest tracePoint,
392 * PM is directing power plane drivers to power off in leaf-to-root order.
394 * Phase begins: Root domain informs its power children that it will drop to
395 * sleep state. This has a cascade effect and triggers all drivers in
396 * the power plane to transition to a lower power state if necessary.
397 * Phase ends: All power transitions in response to the root domain power
398 * change have completed.
400 kIOPMTracePointSleepPowerPlaneDrivers
= 0x14,
402 /* When kIOPMTracePointSleepDidChangeInterests is the latest tracePoint,
403 * PM is calling powerStateDidChangeTo() on interested drivers of root domain.
405 * Phase begins: Dispatch a callout thread to call interested drivers.
406 * Phase ends: Callout thread work done, and acknowledgePowerChange() called
407 * by drivers that indicated asynchronous completion.
409 kIOPMTracePointSleepDidChangeInterests
= 0x15,
411 /* When kIOPMTracePointSleepCapabilityClients is the latest tracePoint,
412 * PM is notifying system capability clients about system sleep.
414 * Phase begins: Send kIOMessageSystemCapabilityChange notifications to inform
415 * capability clients that system has lost all capabilities.
416 * Phase ends: Finished sending notifications.
418 kIOPMTracePointSleepCapabilityClients
= 0x16,
420 /* When kIOPMTracePointSleepPlatformActions is the latest tracePoint,
421 * PM is calling drivers that have registered a platform sleep action.
423 kIOPMTracePointSleepPlatformActions
= 0x17,
425 /* When kIOPMTracePointSleepCPUs is the latest tracePoint,
426 * PM is shutting down all non-boot processors.
428 * Phase begins: Shutdown all non-boot processors.
429 * Phase ends: Reduced to only the boot processor running.
431 kIOPMTracePointSleepCPUs
= 0x18,
433 /* When kIOPMTracePointSleepPlatformDriver is the latest tracePoint,
434 * PM is executing platform dependent code to prepare for system sleep.
436 kIOPMTracePointSleepPlatformDriver
= 0x19,
438 /* When kIOPMTracePointHibernate is the latest tracePoint,
439 * PM is writing the hibernate image to disk.
441 kIOPMTracePointHibernate
= 0x1a,
443 /* When kIOPMTracePointSystemSleep is the latest tracePoint,
444 * PM has recorded the final trace point before the hardware platform
445 * enters sleep state, or low level wakeup is underway - such as restoring
446 * the hibernate image from disk.
448 * Note: If a system is asleep and then loses power, and it does not have a
449 * hibernate image to restore from (e.g. hibernatemode = 0), then OS X will
450 * interpret this power loss as a failure in kIOPMTracePointSystemSleep.
452 * Phase begins: Before the OS directs the hardware to enter sleep state.
453 * Phase ends: Control returns to the OS on wake, but before recording the first
456 kIOPMTracePointSystemSleep
= 0x1f,
458 /* When kIOPMTracePointWakePlatformDriver is the latest tracePoint,
459 * PM is executing platform dependent code to prepare for system wake.
461 kIOPMTracePointWakePlatformDriver
= 0x21,
463 /* When kIOPMTracePointWakePlatformActions is the latest tracePoint,
464 * PM is calling drivers that have registered a platform wake action.
466 kIOPMTracePointWakePlatformActions
= 0x22,
468 /* When kIOPMTracePointWakeCPUs is the latest tracePoint,
469 * PM is bringing all non-boot processors online.
471 kIOPMTracePointWakeCPUs
= 0x23,
473 /* When kIOPMTracePointWakeWillPowerOnClients is the latest tracePoint,
474 * PM is sending kIOMessageSystemWillPowerOn to both kernel clients and
475 * applications. PM also notifies system capability clients about the
476 * proposed capability change.
478 * Phase begins: Send kIOMessageSystemWillPowerOn and
479 * kIOMessageSystemCapabilityChange notifications.
480 * Phase ends: Finished sending notifications.
482 kIOPMTracePointWakeWillPowerOnClients
= 0x24,
484 /* When kIOPMTracePointWakeWillChangeInterests is the latest tracePoint,
485 * PM is calling powerStateWillChangeTo() on interested drivers of root domain.
487 * Phase begins: Dispatch a callout thread to call interested drivers.
488 * Phase ends: Callout thread work done, and acknowledgePowerChange() called
489 * by drivers that indicated asynchronous completion.
491 kIOPMTracePointWakeWillChangeInterests
= 0x25,
493 /* When kIOPMTracePointWakeDidChangeInterests is the latest tracePoint,
494 * PM is calling powerStateDidChangeTo() on interested drivers of root domain.
496 * Phase begins: Dispatch a callout thread to call interested drivers.
497 * Phase ends: Callout thread work done, and acknowledgePowerChange() called
498 * by drivers that indicated asynchronous completion.
500 kIOPMTracePointWakeDidChangeInterests
= 0x26,
502 /* When kIOPMTracePointWakePowerPlaneDrivers is the latest tracePoint,
503 * PM is directing power plane drivers to power up in root-to-leaf order.
505 * Phase begins: Root domain informs its power children that it transitioned
506 * to ON state. This has a cascade effect and triggers all drivers in
507 * the power plane to re-evaluate and potentially change power state.
508 * Phase ends: All power transitions in response to the root domain power
509 * change have completed.
511 kIOPMTracePointWakePowerPlaneDrivers
= 0x27,
513 /* When kIOPMTracePointWakeCapabilityClients is the latest tracePoint,
514 * PM is notifying system capability clients about system wake, and waiting
515 * for any asynchronous completions.
517 * Phase begins: Inform capability clients that system has gained capabilities.
518 * Phase ends: All notified clients have acknowledged.
520 kIOPMTracePointWakeCapabilityClients
= 0x28,
522 /* When kIOPMTracePointWakeApplications is the latest tracePoint,
523 * System CPU is powered, PM has powered on each driver.
525 * Phase begins: Send asynchronous kIOMessageSystemHasPoweredOn notifications.
526 * Phase ends: Finished sending asynchronous notifications.
528 kIOPMTracePointWakeApplications
= 0x29,
530 /* kIOPMTracePointSystemLoginwindowPhase
531 * This phase represents a several minute window after the system has powered on.
532 * Higher levels of system diagnostics are in a heightened state of alert in this phase,
533 * in case any user errors occurred that we could not detect in software.
535 * Phase begins: After IOPMrootDomain sends kIOMessageSystemHasPoweredOn message.
536 * Phase ends: When loginwindow calls IOPMSleepWakeSetUUID(NULL) the system shall
537 * be considered awake and usable. The next phase shall be kIOPMTracePointSystemUp.
539 kIOPMTracePointSystemLoginwindowPhase
= 0x30,
541 /* When kIOPMTracePointDarkWakeEntry is the latest tracePoint,
542 * PM has started a transition from full wake to dark wake.
544 * Phase begins: Start transition to dark wake.
545 * Phase ends: System in dark wake. Before recording kIOPMTracePointSystemUp.
547 kIOPMTracePointDarkWakeEntry
= 0x31,
549 /* When kIOPMTracePointDarkWakeExit is the latest tracePoint,
550 * PM has started a transition from dark wake to full wake.
552 * Phase begins: Start transition to full wake.
553 * Phase ends: System in full wake. Before recording kIOPMTracePointSystemUp.
555 kIOPMTracePointDarkWakeExit
= 0x32
558 /*****************************************************************************/
561 Ê* kIOPMLoginWindowSecurityDebugKey - identifies PM debug data specific to LoginWindow
562 * for use with IOPMrootDomain.
564 #define kIOPMLoginWindowSecurityDebugKey "LoginWindowSecurity"
566 // For PM internal use only - key to locate sleep failure results within SCDynamicStore.
567 #define kIOPMDynamicStoreSleepFailureKey "SleepFailure"
569 /*****************************************************************************/
571 // For IOPMLibPrivate.h
572 #define kIOPMSleepWakeFailureKey "PMFailurePhase"
573 #define kIOPMSleepWakeFailureCodeKey "PMStatusCode"
574 #define kIOPMSleepWakeFailureLoginKey "LWFailurePhase"
575 #define kIOPMSleepWakeFailureUUIDKey "UUID"
576 #define kIOPMSleepWakeFailureDateKey "Date"
578 /******************************************************************************/
579 /* System sleep policy
580 * Shared between PM root domain and platform driver.
583 // Platform specific property added by the platform driver.
584 // An OSData that describes the system sleep policy.
585 #define kIOPlatformSystemSleepPolicyKey "IOPlatformSystemSleepPolicy"
587 // Root domain property updated before platform sleep.
588 // An OSData that describes the system sleep parameters.
589 #define kIOPMSystemSleepParametersKey "IOPMSystemSleepParameters"
591 struct IOPMSystemSleepParameters
601 kIOPMSleepFlagHibernate
= 0x00000001,
602 kIOPMSleepFlagSleepTimerEnable
= 0x00000002
605 #endif /* ! _IOKIT_IOPMPRIVATE_H */