]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/pwr_mgt/IOPM.h
xnu-792.25.20.tar.gz
[apple/xnu.git] / iokit / IOKit / pwr_mgt / IOPM.h
CommitLineData
1c79356b 1/*
0c530ab8 2 * Copyright (c) 1998-2005 Apple Computer, Inc. All rights reserved.
1c79356b 3 *
6601e61a 4 * @APPLE_LICENSE_HEADER_START@
1c79356b 5 *
6601e61a
A
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
8f6c56a5 11 *
6601e61a
A
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
8f6c56a5
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
6601e61a
A
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
8f6c56a5 19 *
6601e61a 20 * @APPLE_LICENSE_HEADER_END@
1c79356b
A
21 */
22#ifndef _IOKIT_IOPM_H
23#define _IOKIT_IOPM_H
24
0c530ab8
A
25#include <IOKit/IOTypes.h>
26#include <IOKit/IOMessage.h>
27#include <IOKit/IOReturn.h>
28
29#ifdef __ppc__
30#include <IOKit/pwr_mgt/IOPMDeprecated.h>
31#endif
32
33
34
35enum {
36 kIOPMMaxPowerStates = 10,
37 IOPMMaxPowerStates = kIOPMMaxPowerStates
38};
1c79356b
A
39
40typedef unsigned long IOPMPowerFlags;
0b4e3aa0 41enum {
0c530ab8
A
42 // The following bits are used in the input and output power fields.
43 kIOPMClockNormal = 0x0004,
44 kIOPMClockRunning = 0x0008,
45 // Reserved - Used only between root and root parent.
46 kIOPMAuxPowerOn = 0x0020,
47 // Reserved - kIOPMPagingAvailable used only by now-defunct paging plexus
48 kIOPMPagingAvailable = 0x0020,
49 kIOPMPassThrough = 0x0100,
50 kIOPMDoze = 0x0400,
51 // Obsolete - use kIOPMDoze instead of kIOPMSoftSleep
52 kIOPMSoftSleep = 0x0400,
53 kIOPMSleep = 0x0001,
54 kIOPMRestart = 0x0080,
55
56 // The following bits are used in the capabilites field and the power fields
57 kIOPMPowerOn = 0x0002,
58 kIOPMPreventSystemSleep = 0x0010,
59 kIOPMPreventIdleSleep = 0x0040,
60
61 // The following bits are used in the capabilites field only.
62 // Used between a driver and its policy-maker
63 kIOPMNotAttainable = 0x0001,
64 // Used internally in a power domain parent
65 kIOPMChildClamp = 0x0080,
66 // Used internally in a power domain parent
67 kIOPMChildClamp2 = 0x0200,
68 // Marks device as usable in this state
69 kIOPMDeviceUsable = 0x8000,
70 // Device runs at max performance in this state
71 kIOPMMaxPerformance = 0x4000,
72 kIOPMContextRetained = 0x2000,
73 kIOPMConfigRetained = 0x1000,
74 // Device is capable of system sleep in this state
75 kIOPMSleepCapability = 0x0004,
76 kIOPMRestartCapability = 0x0080,
77
78 // Reserved - Error code. (this is an error return rather than a bit)
79 kIOPMNotPowerManaged = 0x0800,
80 // Therefore this bit safely overloads it
81 kIOPMStaticPowerValid = 0x0800,
0b4e3aa0 82
0c530ab8
A
83 kIOPMCapabilitiesMask = kIOPMPowerOn | kIOPMDeviceUsable |
84 kIOPMMaxPerformance | kIOPMContextRetained |
85 kIOPMConfigRetained | kIOPMSleepCapability |
0b4e3aa0
A
86 kIOPMRestartCapability
87};
88
89
90enum {
0c530ab8
A
91 IOPMNotAttainable = kIOPMNotAttainable,
92 IOPMPowerOn = kIOPMPowerOn,
93 IOPMClockNormal = kIOPMClockNormal,
94 IOPMClockRunning = kIOPMClockRunning,
95 IOPMAuxPowerOn = kIOPMAuxPowerOn,
96 IOPMDeviceUsable = kIOPMDeviceUsable,
97 IOPMMaxPerformance = kIOPMMaxPerformance,
98 IOPMContextRetained = kIOPMContextRetained,
99 IOPMConfigRetained = kIOPMConfigRetained,
100 IOPMNotPowerManaged = kIOPMNotPowerManaged,
101 IOPMPagingAvailable = kIOPMPagingAvailable,
102 IOPMSoftSleep = kIOPMSoftSleep
0b4e3aa0
A
103};
104
105
106enum {
0c530ab8
A
107 kIOPMNextHigherState = 1,
108 kIOPMHighestState = 2,
109 kIOPMNextLowerState = 3,
110 kIOPMLowestState = 4
0b4e3aa0
A
111};
112
113enum {
0c530ab8
A
114 IOPMNextHigherState = kIOPMNextHigherState,
115 IOPMHighestState = kIOPMHighestState,
116 IOPMNextLowerState = kIOPMNextLowerState,
117 IOPMLowestState = kIOPMLowestState
0b4e3aa0 118};
1c79356b 119
0c530ab8
A
120// Internal commands used by power managment command queue
121enum {
0b4e3aa0
A
122 kIOPMBroadcastAggressiveness = 1,
123 kIOPMUnidleDevice
124};
125
0c530ab8
A
126// Power consumption unknown value
127enum {
0b4e3aa0 128 kIOPMUnknown = 0xFFFF
1c79356b
A
129};
130
0c530ab8
A
131/*******************************************************************************
132 *
133 * Root Domain property keys of interest
134 *
135 ******************************************************************************/
136
137/* AppleClamshellState
138 * reflects the state of the clamshell (lid) on a portable.
139 * It has a boolean value.
140 * true == clamshell is closed
141 * false == clamshell is open
142 * not present == no clamshell on this hardware
143 */
144#define kAppleClamshellStateKey "AppleClamshellState"
145
146/* AppleClamshellCausesSleep
147 * reflects the clamshell close behavior on a portable.
148 * It has a boolean value.
149 * true == system will sleep when clamshell is closed
150 * false == system will not sleep on clamshell close
151 * (typically external display mode)
152 * not present == no clamshell on this hardware
153 */
154#define kAppleClamshellCausesSleepKey "AppleClamshellCausesSleep"
155
156/*******************************************************************************
157 *
158 * Root Domain general interest messages
159 *
160 ******************************************************************************/
161
162/* kIOPMMessageClamshellStateChange
163 * Delivered as a general interest notification on the IOPMrootDomain
164 * IOPMrootDomain sends this message when state of either AppleClamshellState
165 * or AppleClamshellCausesSleep changes. If this clamshell change results in
166 * a sleep, the sleep will initiate soon AFTER delivery of this message.
167 * The state of both variables is encoded in a bitfield argument sent with
168 * the message. Check bits 0 and 1 using kClamshellStateBit & kClamshellSleepBit
169 */
170enum {
171 kClamshellStateBit = (1 << 0),
172 kClamshellSleepBit = (1 << 1)
173};
174
175#define kIOPMMessageClamshellStateChange \
176 iokit_family_msg(sub_iokit_powermanagement, 0x100)
177
178/* kIOPMMessageFeatureChange
179 * Delivered when the set of supported features ("Supported Features" dictionary
180 * under IOPMrootDomain registry) changes in some way. Typically addition or
181 * removal of a supported feature.
182 * RootDomain passes no argument with this message.
183 */
184#define kIOPMMessageFeatureChange \
185 iokit_family_msg(sub_iokit_powermanagement, 0x110)
186
187/* kIOPMMessageInflowDisableCancelled
188 * The battery has drained completely to its "Fully Discharged" state.
189 * If a user process has disabled battery inflow for battery
190 * calibration, we forcibly re-enable Inflow at this point.
191 * If inflow HAS been forcibly re-enabled, bit 0
192 * (kInflowForciblyEnabledBit) will be set.
193 */
4452a7af 194enum {
0c530ab8 195 kInflowForciblyEnabledBit = (1 << 0)
4452a7af
A
196};
197
0c530ab8
A
198#define kIOPMMessageInternalBatteryFullyDischarged \
199 iokit_family_msg(sub_iokit_powermanagement, 0x120)
200
201
202/*******************************************************************************
203 *
204 * Power commands issued to root domain
205 *
206 * These commands are issued from system drivers only:
207 * ApplePMU, AppleSMU, IOGraphics, AppleACPIFamily
208 *
209 ******************************************************************************/
1c79356b 210enum {
0c530ab8
A
211 kIOPMSleepNow = (1<<0), // put machine to sleep now
212 kIOPMAllowSleep = (1<<1), // allow idle sleep
213 kIOPMPreventSleep = (1<<2), // do not allow idle sleep
214 kIOPMPowerButton = (1<<3), // power button was pressed
215 kIOPMClamshellClosed = (1<<4), // clamshell was closed
216 kIOPMPowerEmergency = (1<<5), // battery dangerously low
217 kIOPMDisableClamshell = (1<<6), // do not sleep on clamshell closure
218 kIOPMEnableClamshell = (1<<7), // sleep on clamshell closure
219 kIOPMProcessorSpeedChange = (1<<8), // change the processor speed
220 kIOPMOverTemp = (1<<9), // system dangerously hot
221 kIOPMClamshellOpened = (1<<10) // clamshell was opened
1c79356b
A
222};
223
0c530ab8
A
224/*******************************************************************************
225 *
226 * Power Management Return Codes
227 *
228 ******************************************************************************/
1c79356b 229enum {
0c530ab8
A
230 kIOPMNoErr = 0,
231 // Returned by powerStateWillChange and powerStateDidChange:
232 // Immediate acknowledgement of power state change
233 kIOPMAckImplied = 0,
234 // Acknowledgement of power state change will come later
235 kIOPMWillAckLater = 1,
236
237 // Returned by requestDomainState:
238 // Unrecognized specification parameter
239 kIOPMBadSpecification = 4,
240 // No power state matches search specification
241 kIOPMNoSuchState = 5,
242
243 // Device cannot change its power for some reason
244 kIOPMCannotRaisePower = 6,
245
246 // Returned by changeStateTo:
247 // Requested state doesn't exist
248 kIOPMParameterError = 7,
249 // Device not yet fully hooked into power management
250 kIOPMNotYetInitialized = 8,
251
252 // And the old constants; deprecated
253 IOPMNoErr = kIOPMNoErr,
254 IOPMAckImplied = kIOPMAckImplied,
255 IOPMWillAckLater = kIOPMWillAckLater,
256 IOPMBadSpecification = kIOPMBadSpecification,
257 IOPMNoSuchState = kIOPMNoSuchState,
258 IOPMCannotRaisePower = kIOPMCannotRaisePower,
259 IOPMParameterError = kIOPMParameterError,
260 IOPMNotYetInitialized = kIOPMNotYetInitialized
261};
262
263
264// IOPMPowerSource class descriptive strings
265// Power Source state is published as properties to the IORegistry under these
266// keys.
267#define kIOPMPSExternalConnectedKey "ExternalConnected"
268#define kIOPMPSExternalChargeCapableKey "ExternalChargeCapable"
269#define kIOPMPSBatteryInstalledKey "BatteryInstalled"
270#define kIOPMPSIsChargingKey "IsCharging"
271#define kIOPMFullyChargedKey "FullyCharged"
272#define kIOPMPSAtWarnLevelKey "AtWarnLevel"
273#define kIOPMPSAtCriticalLevelKey "AtCriticalLevel"
274#define kIOPMPSCurrentCapacityKey "CurrentCapacity"
275#define kIOPMPSMaxCapacityKey "MaxCapacity"
276#define kIOPMPSDesignCapacityKey "DesignCapacity"
277#define kIOPMPSTimeRemainingKey "TimeRemaining"
278#define kIOPMPSAmperageKey "Amperage"
279#define kIOPMPSVoltageKey "Voltage"
280#define kIOPMPSCycleCountKey "CycleCount"
281#define kIOPMPSMaxErrKey "MaxErr"
282#define kIOPMPSAdapterInfoKey "AdapterInfo"
283#define kIOPMPSLocationKey "Location"
284#define kIOPMPSErrorConditionKey "ErrorCondition"
285#define kIOPMPSManufacturerKey "Manufacturer"
286#define kIOPMPSManufactureDateKey "ManufactureDate"
287#define kIOPMPSModelKey "Model"
288#define kIOPMPSSerialKey "Serial"
289#define kIOPMDeviceNameKey "DeviceName"
290#define kIOPMPSLegacyBatteryInfoKey "LegacyBatteryInfo"
291#define kIOPMPSBatteryHealthKey "BatteryHealth"
292#define kIOPMPSHealthConfidenceKey "HealthConfidence"
293
294// Definitions for battery location, in case of multiple batteries.
295// A location of 0 is unspecified
296// Location is undefined for single battery systems
297enum {
298 kIOPMPSLocationLeft = 1001,
299 kIOPMPSLocationRight = 1002
5d5c5d0d
A
300};
301
0c530ab8
A
302// Battery quality health types, specified by BatteryHealth and HealthConfidence
303// properties in an IOPMPowerSource battery kext.
5d5c5d0d 304enum {
0c530ab8
A
305 kIOPMUndefinedValue = 0,
306 kIOPMPoorValue = 1,
307 kIOPMFairValue = 2,
308 kIOPMGoodValue = 3
4452a7af
A
309};
310
0c530ab8
A
311// Battery's time remaining estimate is invalid this long (seconds) after a wake
312#define kIOPMPSInvalidWakeSecondsKey "BatteryInvalidWakeSeconds"
313
314// Battery must wait this long (seconds) after being completely charged before
315// the battery is settled.
316#define kIOPMPSPostChargeWaitSecondsKey "PostChargeWaitSeconds"
317
318// Battery must wait this long (seconds) after being completely discharged
319// before the battery is settled.
320#define kIOPMPSPostDishargeWaitSecondsKey "PostDischargeWaitSeconds"
321
322
323
324// PM Settings Controller setting types
325// Settings types used primarily with:
326// IOPMrootDomain::registerPMSettingController
327// The values are identical to the similarly named keys for use in user space
328// PM settings work. Those keys are defined in IOPMLibPrivate.h.
329#define kIOPMSettingWakeOnRingKey "Wake On Modem Ring"
330#define kIOPMSettingRestartOnPowerLossKey "Automatic Restart On Power Loss"
331#define kIOPMSettingWakeOnACChangeKey "Wake On AC Change"
332#define kIOPMSettingSleepOnPowerButtonKey "Sleep On Power Button"
333#define kIOPMSettingWakeOnClamshellKey "Wake On Clamshell Open"
334#define kIOPMSettingReduceBrightnessKey "ReduceBrightness"
335#define kIOPMSettingDisplaySleepUsesDimKey "Display Sleep Uses Dim"
336#define kIOPMSettingTimeZoneOffsetKey "TimeZoneOffsetSeconds"
337#define kIOPMSettingMobileMotionModuleKey "MobileMotionModule"
338
339// Setting controlling drivers can register to receive scheduled wake data
340// Either in "CF seconds" type, or structured calendar data in a formatted
341// IOPMCalendarStruct defined below.
342#define kIOPMSettingAutoWakeSecondsKey "wake"
343#define kIOPMSettingAutoWakeCalendarKey "WakeByCalendarDate"
344#define kIOPMSettingAutoPowerSecondsKey "poweron"
345#define kIOPMSettingAutoPowerCalendarKey "PowerByCalendarDate"
346
347// Debug seconds auto wake
348// Used by sleep cycling debug tools
349#define kIOPMSettingDebugWakeRelativeKey "WakeRelativeToSleep"
350#define kIOPMSettingDebugPowerRelativeKey "PowerRelativeToShutdown"
351
352struct IOPMCalendarStruct {
353 UInt32 year;
354 UInt8 month;
355 UInt8 day;
356 UInt8 hour;
357 UInt8 minute;
358 UInt8 second;
359};
360typedef struct IOPMCalendarStruct IOPMCalendarStruct;
4452a7af 361
0c530ab8 362// SetAggressiveness types
1c79356b
A
363enum {
364 kPMGeneralAggressiveness = 0,
365 kPMMinutesToDim,
366 kPMMinutesToSpinDown,
0b4e3aa0
A
367 kPMMinutesToSleep,
368 kPMEthernetWakeOnLANSettings,
9bccf70c 369 kPMSetProcessorSpeed,
91447636
A
370 kPMPowerSource,
371 kPMMotionSensor,
372 kPMLastAggressivenessType
1c79356b 373};
91447636 374#define kMaxType (kPMLastAggressivenessType-1)
1c79356b 375
9bccf70c
A
376// SetAggressiveness values for the kPMPowerSource aggressiveness type
377enum {
378 kIOPMInternalPower = 1,
379 kIOPMExternalPower
380};
381
0c530ab8 382#define kIOREMSleepEnabledKey "REMSleepEnabled"
1c79356b 383
55e303ae 384// Strings for deciphering the dictionary returned from IOPMCopyBatteryInfo
0c530ab8
A
385#define kIOBatteryInfoKey "IOBatteryInfo"
386#define kIOBatteryCurrentChargeKey "Current"
387#define kIOBatteryCapacityKey "Capacity"
388#define kIOBatteryFlagsKey "Flags"
389#define kIOBatteryVoltageKey "Voltage"
390#define kIOBatteryAmperageKey "Amperage"
391#define kIOBatteryCycleCountKey "Cycle Count"
d52fe63f 392
1c79356b 393enum {
0c530ab8
A
394 kIOBatteryInstalled = (1 << 2),
395 kIOBatteryCharge = (1 << 1),
396 kIOBatteryChargerConnect = (1 << 0)
1c79356b
A
397};
398
e5568f75 399
55e303ae
A
400// Private power management message indicating battery data has changed
401// Indicates new data resides in the IORegistry
402#define kIOPMMessageBatteryStatusHasChanged iokit_family_msg(sub_iokit_pmu, 0x100)
403
404// Apple private Legacy messages for re-routing AutoWake and AutoPower messages to the PMU
405// through newer user space IOPMSchedulePowerEvent API
406#define kIOPMUMessageLegacyAutoWake iokit_family_msg(sub_iokit_pmu, 0x200)
0c530ab8 407#define kIOPMUMessageLegacyAutoPower iokit_family_msg(sub_iokit_pmu, 0x210)
d52fe63f
A
408
409// For use with IOPMPowerSource bFlags
410#define IOPM_POWER_SOURCE_REV 2
411enum {
412 kIOPMACInstalled = kIOBatteryChargerConnect,
413 kIOPMBatteryCharging = kIOBatteryCharge,
414 kIOPMBatteryInstalled = kIOBatteryInstalled,
415 kIOPMUPSInstalled = (1<<3),
416 kIOPMBatteryAtWarn = (1<<4),
417 kIOPMBatteryDepleted = (1<<5),
418 kIOPMACnoChargeCapability = (1<<6), // AC adapter cannot charge battery
419 kIOPMRawLowBattery = (1<<7), // used only by Platform Expert
420 kIOPMForceLowSpeed = (1<<8), // set by Platfm Expert, chk'd by Pwr Plugin
421 kIOPMClosedClamshell = (1<<9), // set by PMU - reflects state of the clamshell
422 kIOPMClamshellStateOnWake = (1<<10) // used only by Platform Expert
423};
424
425
55e303ae
A
426// **********************************************
427// Internal power management data structures
428// **********************************************
1c79356b
A
429
430#if KERNEL && __cplusplus
431class IOService;
432
433enum {
434 kIOPowerEmergencyLevel = 1000
435};
436
437enum {
438 kIOPMSubclassPolicy,
439 kIOPMSuperclassPolicy1
440};
441
442struct stateChangeNote{
0c530ab8
A
443 IOPMPowerFlags stateFlags;
444 unsigned long stateNum;
445 void * powerRef;
1c79356b
A
446};
447typedef struct stateChangeNote stateChangeNote;
448
0b4e3aa0 449struct IOPowerStateChangeNotification {
0c530ab8
A
450 void * powerRef;
451 unsigned long returnValue;
452 unsigned long stateNumber;
453 IOPMPowerFlags stateFlags;
1c79356b 454};
0b4e3aa0
A
455typedef struct IOPowerStateChangeNotification IOPowerStateChangeNotification;
456typedef IOPowerStateChangeNotification sleepWakeNote;
1c79356b
A
457
458extern void IOPMRegisterDevice(const char *, IOService *);
459#endif /* KERNEL && __cplusplus */
460
461#endif /* ! _IOKIT_IOPM_H */
462