2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 #include <kern/thread_call.h>
28 #include <libkern/c++/OSObject.h>
29 #include <IOKit/IOLocks.h>
31 class IOPMinformeeList
;
32 class IOPMchangeNoteList
;
37 class IOTimerEventSource
;
38 class IOPlatformExpert
;
40 #include <IOKit/pwr_mgt/IOPM.h>
44 @defined ACK_TIMER_PERIOD
45 @discussion When an IOService is waiting for acknowledgement to a power state change
46 notification from an interested driver or the controlling driver its ack timer is ticking every tenth of a second.
47 (100000000 nanoseconds are one tenth of a second).
49 #define ACK_TIMER_PERIOD 100000000
55 @abstract Private power management private instance variables for IOService objects.
57 class IOPMpriv
: public OSObject
59 friend class IOService
;
61 OSDeclareDefaultStructors(IOPMpriv
)
66 TRUE if this device is the root power domain.
70 /*! @var interestedDrivers
71 List of interested drivers.
73 IOPMinformeeList
* interestedDrivers
;
76 List of power domain children.
78 IOPMinformeeList
* children
;
81 List of pending power state changes.
83 IOPMchangeNoteList
* changeList
;
86 Timeout on waiting for controlling driver to acknowledgeSetPowerState.
88 IOReturn driver_timer
;
91 thread_call_t ackTimer
;
93 /*! @var settleTimer */
94 thread_call_t settleTimer
;
96 /*! @var machine_state
97 State number of state machine processing current change note.
99 unsigned long machine_state
;
102 Settle timer after changing power state.
104 unsigned long settle_time
;
107 Ordinal of change note currently being processed.
111 /*! @var head_note_flags
112 Copy of flags field in change note currently being processed.
114 unsigned long head_note_flags
;
116 /*! @var head_note_state
117 Copy of newStateNumberfield in change note currently being processed.
119 unsigned long head_note_state
;
121 /*! @var head_note_outputFlags
122 OutputPowerCharacter field from change note currently being processed.
124 unsigned long head_note_outputFlags
;
126 /*! @var head_note_domainState
127 Power domain flags from parent... (only on parent change).
129 unsigned long head_note_domainState
;
131 /*! @var head_note_parent
132 Pointer to initiating parent... (only on parent change).
134 IOPowerConnection
* head_note_parent
;
136 /*! @var head_note_capabilityFlags
137 Copy of capabilityFlags field in change note currently being processed.
139 unsigned long head_note_capabilityFlags
;
141 /*! @var head_note_pendingAcks
142 Number of acks we are waiting for during notification.
144 unsigned long head_note_pendingAcks
;
147 Used to control access to head_note_pendingAcks and driver_timer.
152 Used to control access to response flags array.
157 Used to control access to change note queue.
161 /*! @var initial_change
162 True forces first state to be broadcast even if it isn't a change.
166 /*! @var need_to_become_usable
167 Someone called makeUsable before we had a controlling driver.
169 bool need_to_become_usable
;
171 /*! @var device_overrides
172 State changes are made based only on subclass's desire.
174 bool device_overrides
;
177 Domain is clamped on till first child registers.
182 Points to object which made this struct. Used for debug output only.
186 /*! @var activityLock
187 Used to protect activity flag.
189 IOLock
* activityLock
;
191 /*! @var timerEventSrc
194 IOTimerEventSource
* timerEventSrc
;
196 /*! @var idle_timer_period
197 Timer's period in seconds.
199 unsigned long idle_timer_period
;
201 /*! @var clampTimerEventSrc
202 Timer for clamping power on.
204 IOTimerEventSource
* clampTimerEventSrc
;
206 /*! @var device_active
207 True: there has been device activity since last idle timer expiration.
211 /*! @var device_active_timestamp
212 Time in ticks of last activity.
214 AbsoluteTime device_active_timestamp
;
216 /*! @var driverDesire
217 This is the power state desired by our controlling driver. It is initialized to myCurrentState and is changed
218 when the controlling driver calls changePowerStateTo. A change in driverDesire may cause a change in ourDesiredPowerState.
220 unsigned long driverDesire
;
224 /*! @var deviceDesire
225 This is the power state desired by a subclassed device object. It is initialized to myCurrentState and is changed when the subclassed object calls changePowerStateToPriv. A change in deviceDesire may cause a change in ourDesiredPowerState.
227 unsigned long deviceDesire
;
231 /*! @var ourDesiredPowerState
232 This is the power state we desire currently. If equal to myCurrentState, we're happy.
233 Otherwise, we're waiting for the parent to raise the power domain to at least this level.
235 If this is a power domain, this is the maximum of all our children's desires, driverDesire, and deviceDesire.
237 a child asks for more power via requestDomainState,
238 the controlling driver asks for more power via changePowerStateTo
241 we lose a child and the child had the highest power need of all our children,
242 the child with the highest power need suggests a lower power domain state,
243 the controlling driver asks for lower power for some reason via changePowerStateTo
245 If this is not a power domain, ourDesiredPowerState represents the greater of driverDesire and deviceDesire.
247 the controlling driver asks for more power via changePowerStateTo
248 some driver calls makeUsable
249 a subclassed object asks for more power via changePowerStateToPriv
252 the controlling driver asks for lower power for some reason via changePowerStateTo
253 a subclassed object asks for lower power for some reason via changePowerStateToPriv
255 unsigned long ourDesiredPowerState
;
258 /*! @var previousRequest
259 This is a reminder of what our parent thinks our need is. Whenever it changes,
260 we call requestDomainState in the parent to keep it current. It is usually equal to ourDesiredPowerState
261 except while a power change is in progress.
263 unsigned long previousRequest
;
269 unsigned long askingFor
;
272 /*! @var imminentState
273 Usually the same as myCurrentState, except right after calling powerStateWillChangeTo.
275 unsigned long imminentState
;
277 /*! @function serialize
278 Serialize private instance variables for debug output (IORegistryDumper).
280 virtual bool serialize(OSSerialize
*s
) const;
289 @abstract Protected power management instance variables for IOService objects.
291 class IOPMprot
: public OSObject
//management
293 friend class IOService
;
295 OSDeclareDefaultStructors(IOPMprot
)
300 From getName(), used in logging.
302 const char * ourName
;
305 From getPlatform, used in logging and registering.
307 IOPlatformExpert
* thePlatform
;
309 /*! @var theNumberOfPowerStates
310 The number of states in the array.
312 unsigned long theNumberOfPowerStates
; // the number of states in the array
314 /*! @var thePowerStates
317 IOPMPowerState thePowerStates
[IOPMMaxPowerStates
];
319 /*! @var theControllingDriver
320 Points to the controlling driver.
322 IOService
* theControllingDriver
;
324 /*! @var aggressiveness
325 Current value of power management aggressiveness.
327 unsigned long aggressiveness
;
329 /*! @var current_aggressiveness_values
330 Array of aggressiveness values.
332 unsigned long current_aggressiveness_values
[kMaxType
+1];
334 /*! @var current_aggressiveness_validity
335 True for values that are currently valid.
337 bool current_aggressiveness_valid
[kMaxType
+1];
339 /*! @var myCurrentState
340 The ordinal of our current power state.
342 unsigned long myCurrentState
;
344 /*! @var parentsKnowState
345 True if all our parents know the state of their power domain.
347 bool parentsKnowState
;
349 /*! @var parentsCurrentPowerFlags
350 Logical OR of power flags for the current state of each power domainparent.
352 IOPMPowerFlags parentsCurrentPowerFlags
;
354 /*! @var maxCapability
355 Ordinal of highest state we can achieve in current power domain state.
357 unsigned long maxCapability
;
360 Points to the single power management workloop.
362 IOWorkLoop
* PMworkloop
;
364 /*! @var commandQueue
365 Used to serialize idle-power-down and busy-power-up.
367 IOCommandQueue
* commandQueue
;
369 /*! @var PMcommandGate
370 Used to serialize timer expirations and incoming acknowledgements.
372 IOCommandGate
* PMcommandGate
;
374 /*! @var myCharacterFlags
375 Logical OR of all output power character flags in the array.
377 IOPMPowerFlags myCharacterFlags
;
379 /*! @var serialNumber
380 Used to uniquely identify power management notification to apps and clients.
384 /*! @var responseFlags
385 Points to an OSArray which manages responses from notified apps and clients.
387 OSArray
* responseFlags
;
389 /*! @var doNotPowerDown
390 Keeps track of any negative responses from notified apps and clients.
395 Used to serialize scanning the children.
400 Used to serialize scanning the parents.
404 /*! @var outofbandparameter
405 Used to communicate desired function to tellClientsWithResponse().
406 This is used because it avoids changing the signatures of the affected virtual methods.
408 int outofbandparameter
;
410 /*! @function serialize
411 Serialize protected instance variables for debug output (IORegistryDumper).
413 virtual bool serialize(OSSerialize
*s
) const;