]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/pwr_mgt/IOPM.h
b71c9ccad96196d8dbfd1fe458ce44115d5bee54
[apple/xnu.git] / iokit / IOKit / pwr_mgt / IOPM.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 #ifndef _IOKIT_IOPM_H
31 #define _IOKIT_IOPM_H
32
33 #define IOPMMaxPowerStates 10
34
35 typedef unsigned long IOPMPowerFlags;
36 enum {
37 // following bits are used in the input and output power fields
38 kIOPMClockNormal = 0x0004,
39 kIOPMClockRunning = 0x0008,
40 kIOPMAuxPowerOn = 0x0020, // used only between root and root parent
41 kIOPMPagingAvailable = 0x0020, // used only between paging plexus and its children
42 kIOPMPassThrough = 0x0100,
43 kIOPMDoze = 0x0400,
44 kIOPMSoftSleep = 0x0400, // old usage, replaced by kIOPMDoze
45 kIOPMSleep = 0x0001,
46 kIOPMRestart = 0x0080,
47 // following bits are used in the capabilites field and the power fields
48 kIOPMPowerOn = 0x0002,
49 kIOPMPreventSystemSleep = 0x0010,
50 kIOPMPreventIdleSleep = 0x0040,
51 // following bits are used in the capabilites field
52 kIOPMNotAttainable = 0x0001, // used between a driver and its policy-maker
53 kIOPMChildClamp = 0x0080, // used internally in a power domain parent
54 kIOPMChildClamp2 = 0x0200, // used internally in a power domain parent
55 kIOPMDeviceUsable = 0x8000,
56 kIOPMMaxPerformance = 0x4000,
57 kIOPMContextRetained = 0x2000,
58 kIOPMConfigRetained = 0x1000,
59 kIOPMSleepCapability = 0x0004,
60 kIOPMRestartCapability = 0x0080,
61 kIOPMNotPowerManaged = 0x0800, // this is an error return rather than a bit
62 kIOPMStaticPowerValid = 0x0800, // therefore this bit safely overloads it
63
64 kIOPMCapabilitiesMask = kIOPMPowerOn | kIOPMDeviceUsable | kIOPMMaxPerformance |
65 kIOPMContextRetained | kIOPMConfigRetained | kIOPMSleepCapability |
66 kIOPMRestartCapability
67 };
68
69
70 enum {
71 IOPMNotAttainable = kIOPMNotAttainable,
72 IOPMPowerOn = kIOPMPowerOn,
73 IOPMClockNormal = kIOPMClockNormal,
74 IOPMClockRunning = kIOPMClockRunning,
75 IOPMAuxPowerOn = kIOPMAuxPowerOn,
76 IOPMDeviceUsable = kIOPMDeviceUsable,
77 IOPMMaxPerformance = kIOPMMaxPerformance,
78 IOPMContextRetained = kIOPMContextRetained,
79 IOPMConfigRetained = kIOPMConfigRetained,
80 IOPMNotPowerManaged = kIOPMNotPowerManaged,
81 IOPMPagingAvailable = kIOPMPagingAvailable,
82 IOPMSoftSleep = kIOPMSoftSleep
83 };
84
85
86 enum {
87 kIOPMNextHigherState = 1,
88 kIOPMHighestState = 2,
89 kIOPMNextLowerState = 3,
90 kIOPMLowestState = 4
91 };
92
93 enum {
94 IOPMNextHigherState = kIOPMNextHigherState,
95 IOPMHighestState = kIOPMHighestState,
96 IOPMNextLowerState = kIOPMNextLowerState,
97 IOPMLowestState = kIOPMLowestState
98 };
99
100
101
102 enum { // commands on power managment command queue
103 kIOPMBroadcastAggressiveness = 1,
104 kIOPMUnidleDevice
105 };
106
107 enum { // special value means "power consumption unknown"
108 kIOPMUnknown = 0xFFFF
109 };
110
111 // Power events
112 enum {
113 kClamshellClosedEventMask = (1<<0), // User closed lid
114 kDockingBarEventMask = (1<<1), // OBSOLETE
115 kACPlugEventMask = (1<<2), // User plugged or unplugged adapter
116 kFrontPanelButtonEventMask = (1<<3), // User hit the front panel button
117 kBatteryStatusEventMask = (1<<4) // Battery status has changed
118 };
119
120 // Power commands issued to root domain
121 enum {
122 kIOPMSleepNow = (1<<0), // put machine to sleep now
123 kIOPMAllowSleep = (1<<1), // allow idle sleep
124 kIOPMPreventSleep = (1<<2), // do not allow idle sleep
125 kIOPMPowerButton = (1<<3), // power button was pressed
126 kIOPMClamshellClosed = (1<<4), // clamshell was closed
127 kIOPMPowerEmergency = (1<<5), // battery dangerously low
128 kIOPMDisableClamshell = (1<<6), // do not sleep on clamshell closure
129 kIOPMEnableClamshell = (1<<7), // sleep on clamshell closure
130 kIOPMProcessorSpeedChange = (1<<8), // change the processor speed
131 kIOPMOverTemp = (1<<9) // system dangerously hot
132 };
133 // Return codes
134
135 // PUBLIC power management features
136 // NOTE: this is a direct port from classic, some of these bits
137 // are obsolete but are included for completeness
138 enum {
139 kPMHasWakeupTimerMask = (1<<0), // 1=wake timer is supported
140 kPMHasSharedModemPortMask = (1<<1), // Not used
141 kPMHasProcessorCyclingMask = (1<<2), // 1=processor cycling supported
142 kPMMustProcessorCycleMask = (1<<3), // Not used
143 kPMHasReducedSpeedMask = (1<<4), // 1=supports reduced processor speed
144 kPMDynamicSpeedChangeMask = (1<<5), // 1=supports changing processor speed on the fly
145 kPMHasSCSIDiskModeMask = (1<<6), // 1=supports using machine as SCSI drive
146 kPMCanGetBatteryTimeMask = (1<<7), // 1=battery time can be calculated
147 kPMCanWakeupOnRingMask = (1<<8), // 1=machine can wake on modem ring
148 kPMHasDimmingSupportMask = (1<<9), // 1=has monitor dimming support
149 kPMHasStartupTimerMask = (1<<10), // 1=can program startup timer
150 kPMHasChargeNotificationMask = (1<<11), // 1=client can determine charger status/get notifications
151 kPMHasDimSuspendSupportMask = (1<<12), // 1=can dim diplay to DPMS ('off') state
152 kPMHasWakeOnNetActivityMask = (1<<13), // 1=supports waking upon receipt of net packet
153 kPMHasWakeOnLidMask = (1<<14), // 1=can wake upon lid/case opening
154 kPMCanPowerOffPCIBusMask = (1<<15), // 1=can remove power from PCI bus on sleep
155 kPMHasDeepSleepMask = (1<<16), // 1=supports deep (hibernation) sleep
156 kPMHasSleepMask = (1<<17), // 1=machine support low power sleep (ala powerbooks)
157 kPMSupportsServerModeAPIMask = (1<<18), // 1=supports reboot on AC resume for unexpected power loss
158 kPMHasUPSIntegrationMask = (1<<19) // 1=supports incorporating UPS devices into power source calcs
159 };
160
161 // PRIVATE power management features
162 // NOTE: this is a direct port from classic, some of these bits
163 // are obsolete but are included for completeness.
164 enum {
165 kPMHasExtdBattInfoMask = (1<<0), // Not used
166 kPMHasBatteryIDMask = (1<<1), // Not used
167 kPMCanSwitchPowerMask = (1<<2), // Not used
168 kPMHasCelsiusCyclingMask = (1<<3), // Not used
169 kPMHasBatteryPredictionMask = (1<<4), // Not used
170 kPMHasPowerLevelsMask = (1<<5), // Not used
171 kPMHasSleepCPUSpeedMask = (1<<6), // Not used
172 kPMHasBtnIntHandlersMask = (1<<7), // 1=supports individual button interrupt handlers
173 kPMHasSCSITermPowerMask = (1<<8), // 1=supports SCSI termination power switch
174 kPMHasADBButtonHandlersMask = (1<<9), // 1=supports button handlers via ADB
175 kPMHasICTControlMask = (1<<10), // 1=supports ICT control
176 kPMHasLegacyDesktopSleepMask = (1<<11), // 1=supports 'doze' style sleep
177 kPMHasDeepIdleMask = (1<<12), // 1=supports Idle2 in hardware
178 kPMOpenLidPreventsSleepMask = (1<<13), // 1=open case prevent machine from sleeping
179 kPMClosedLidCausesSleepMask = (1<<14), // 1=case closed (clamshell closed) causes sleep
180 kPMHasFanControlMask = (1<<15), // 1=machine has software-programmable fan/thermostat controls
181 kPMHasThermalControlMask = (1<<16), // 1=machine supports thermal monitoring
182 kPMHasVStepSpeedChangeMask = (1<<17), // 1=machine supports processor voltage/clock change
183 kPMEnvironEventsPolledMask = (1<<18) // 1=machine doesn't generate pmu env ints, we must poll instead
184 };
185
186 // DEFAULT public and private features for machines whose device tree
187 // does NOT contain this information (pre-Core99).
188
189 // For Cuda-based Desktops
190
191 #define kStdDesktopPMFeatures kPMHasWakeupTimerMask |\
192 kPMHasProcessorCyclingMask |\
193 kPMHasDimmingSupportMask |\
194 kPMHasStartupTimerMask |\
195 kPMSupportsServerModeAPIMask |\
196 kPMHasUPSIntegrationMask
197
198 #define kStdDesktopPrivPMFeatures kPMHasExtdBattInfoMask |\
199 kPMHasICTControlMask |\
200 kPMHasLegacyDesktopSleepMask
201
202 #define kStdDesktopNumBatteries 0
203
204 // For Wallstreet (PowerBook G3 Series 1998)
205
206 #define kWallstreetPMFeatures kPMHasWakeupTimerMask |\
207 kPMHasProcessorCyclingMask |\
208 kPMHasReducedSpeedMask |\
209 kPMDynamicSpeedChangeMask |\
210 kPMHasSCSIDiskModeMask |\
211 kPMCanGetBatteryTimeMask |\
212 kPMHasDimmingSupportMask |\
213 kPMHasChargeNotificationMask |\
214 kPMHasDimSuspendSupportMask |\
215 kPMHasSleepMask
216
217 #define kWallstreetPrivPMFeatures kPMHasExtdBattInfoMask |\
218 kPMHasBatteryIDMask |\
219 kPMCanSwitchPowerMask |\
220 kPMHasADBButtonHandlersMask |\
221 kPMHasSCSITermPowerMask |\
222 kPMHasICTControlMask |\
223 kPMClosedLidCausesSleepMask |\
224 kPMEnvironEventsPolledMask
225
226 #define kStdPowerBookPMFeatures kWallstreetPMFeatures
227 #define kStdPowerBookPrivPMFeatures kWallstreetPrivPMFeatures
228
229 #define kStdPowerBookNumBatteries 2
230
231 // For 101 (PowerBook G3 Series 1999)
232
233 #define k101PMFeatures kPMHasWakeupTimerMask |\
234 kPMHasProcessorCyclingMask |\
235 kPMHasReducedSpeedMask |\
236 kPMDynamicSpeedChangeMask |\
237 kPMHasSCSIDiskModeMask |\
238 kPMCanGetBatteryTimeMask |\
239 kPMHasDimmingSupportMask |\
240 kPMHasChargeNotificationMask |\
241 kPMHasDimSuspendSupportMask |\
242 kPMHasSleepMask |\
243 kPMHasUPSIntegrationMask
244
245 #define k101PrivPMFeatures kPMHasExtdBattInfoMask |\
246 kPMHasBatteryIDMask |\
247 kPMCanSwitchPowerMask |\
248 kPMHasADBButtonHandlersMask |\
249 kPMHasSCSITermPowerMask |\
250 kPMHasICTControlMask |\
251 kPMClosedLidCausesSleepMask |\
252 kPMEnvironEventsPolledMask
253
254 #define IOPMNoErr 0 // normal return
255
256 // returned by powerStateWillChange and powerStateDidChange:
257 #define IOPMAckImplied 0 // acknowledgement of power state change is implied
258 #define IOPMWillAckLater 1 // acknowledgement of power state change will come later
259
260 // returned by requestDomainState
261 #define IOPMBadSpecification 4 // unrecognized specification parameter
262 #define IOPMNoSuchState 5 // no power state matches search specification
263
264 #define IOPMCannotRaisePower 6 // a device cannot change its power for some reason
265
266 // returned by changeStateTo
267 #define IOPMParameterError 7 // requested state doesn't exist
268 #define IOPMNotYetInitialized 8 // device not yet fully hooked into power management "graph"
269
270
271 // used by Root Domain UserClient
272
273 enum {
274 kPMGeneralAggressiveness = 0,
275 kPMMinutesToDim,
276 kPMMinutesToSpinDown,
277 kPMMinutesToSleep,
278 kPMEthernetWakeOnLANSettings,
279 kPMSetProcessorSpeed,
280 kPMPowerSource,
281 kPMMotionSensor,
282 kPMLastAggressivenessType
283 };
284 #define kMaxType (kPMLastAggressivenessType-1)
285
286 // SetAggressiveness values for the kPMPowerSource aggressiveness type
287 enum {
288 kIOPMInternalPower = 1,
289 kIOPMExternalPower
290 };
291
292 #define kAppleClamshellStateKey "AppleClamshellState"
293 #define kIOREMSleepEnabledKey "REMSleepEnabled"
294
295 // Strings for deciphering the dictionary returned from IOPMCopyBatteryInfo
296 #define kIOBatteryInfoKey "IOBatteryInfo"
297 #define kIOBatteryCurrentChargeKey "Current"
298 #define kIOBatteryCapacityKey "Capacity"
299 #define kIOBatteryFlagsKey "Flags"
300 #define kIOBatteryVoltageKey "Voltage"
301 #define kIOBatteryAmperageKey "Amperage"
302
303 enum {
304 kIOBatteryInstalled = (1 << 2),
305 kIOBatteryCharge = (1 << 1),
306 kIOBatteryChargerConnect = (1 << 0)
307 };
308
309
310 // Private power management message indicating battery data has changed
311 // Indicates new data resides in the IORegistry
312 #define kIOPMMessageBatteryStatusHasChanged iokit_family_msg(sub_iokit_pmu, 0x100)
313
314 // Apple private Legacy messages for re-routing AutoWake and AutoPower messages to the PMU
315 // through newer user space IOPMSchedulePowerEvent API
316 #define kIOPMUMessageLegacyAutoWake iokit_family_msg(sub_iokit_pmu, 0x200)
317 #define kIOPMUMessageLegacyAutoPower iokit_family_msg(sub_iokit_pmu, 0x210)
318
319 // These flags are deprecated. Use the version with the kIOPM prefix below.
320 enum {
321 kACInstalled = kIOBatteryChargerConnect,
322 kBatteryCharging = kIOBatteryCharge,
323 kBatteryInstalled = kIOBatteryInstalled,
324 kUPSInstalled = (1<<3),
325 kBatteryAtWarn = (1<<4),
326 kBatteryDepleted = (1<<5),
327 kACnoChargeCapability = (1<<6), // AC adapter cannot charge battery
328 kRawLowBattery = (1<<7), // used only by Platform Expert
329 kForceLowSpeed = (1<<8) // set by Platfm Expert, chk'd by Pwr Plugin};
330 };
331
332 // For use with IOPMPowerSource bFlags
333 #define IOPM_POWER_SOURCE_REV 2
334 enum {
335 kIOPMACInstalled = kIOBatteryChargerConnect,
336 kIOPMBatteryCharging = kIOBatteryCharge,
337 kIOPMBatteryInstalled = kIOBatteryInstalled,
338 kIOPMUPSInstalled = (1<<3),
339 kIOPMBatteryAtWarn = (1<<4),
340 kIOPMBatteryDepleted = (1<<5),
341 kIOPMACnoChargeCapability = (1<<6), // AC adapter cannot charge battery
342 kIOPMRawLowBattery = (1<<7), // used only by Platform Expert
343 kIOPMForceLowSpeed = (1<<8), // set by Platfm Expert, chk'd by Pwr Plugin
344 kIOPMClosedClamshell = (1<<9), // set by PMU - reflects state of the clamshell
345 kIOPMClamshellStateOnWake = (1<<10) // used only by Platform Expert
346 };
347
348
349 // **********************************************
350 // Internal power management data structures
351 // **********************************************
352
353 #if KERNEL && __cplusplus
354 class IOService;
355
356 enum {
357 kIOPowerEmergencyLevel = 1000
358 };
359
360 enum {
361 kIOPMSubclassPolicy,
362 kIOPMSuperclassPolicy1
363 };
364
365 struct stateChangeNote{
366 IOPMPowerFlags stateFlags;
367 unsigned long stateNum;
368 void * powerRef;
369 };
370 typedef struct stateChangeNote stateChangeNote;
371
372 struct IOPowerStateChangeNotification {
373 void * powerRef;
374 unsigned long returnValue;
375 unsigned long stateNumber;
376 IOPMPowerFlags stateFlags;
377 };
378 typedef struct IOPowerStateChangeNotification IOPowerStateChangeNotification;
379 typedef IOPowerStateChangeNotification sleepWakeNote;
380
381 extern void IOPMRegisterDevice(const char *, IOService *);
382 #endif /* KERNEL && __cplusplus */
383
384 #endif /* ! _IOKIT_IOPM_H */
385