2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_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
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
32 #include <kern/thread_call.h>
35 #include <libkern/c++/OSObject.h>
36 #include <IOKit/IOLocks.h>
38 class IOPMinformeeList
;
39 class IOPMchangeNoteList
;
44 class IOTimerEventSource
;
45 class IOPlatformExpert
;
47 #include <IOKit/pwr_mgt/IOPM.h>
51 @defined ACK_TIMER_PERIOD
52 @discussion When an IOService is waiting for acknowledgement to a power state change
53 notification from an interested driver or the controlling driver its ack timer is ticking every tenth of a second.
54 (100000000 nanoseconds are one tenth of a second).
56 #define ACK_TIMER_PERIOD 100000000
62 @abstract Private power management private instance variables for IOService objects.
64 class IOPMpriv
: public OSObject
66 friend class IOService
;
68 OSDeclareDefaultStructors(IOPMpriv
)
73 TRUE if this device is the root power domain.
77 /*! @var interestedDrivers
78 List of interested drivers.
80 IOPMinformeeList
* interestedDrivers
;
83 List of power domain children.
85 IOPMinformeeList
* children
;
88 List of pending power state changes.
90 IOPMchangeNoteList
* changeList
;
93 Timeout on waiting for controlling driver to acknowledgeSetPowerState.
95 IOReturn driver_timer
;
98 thread_call_t ackTimer
;
100 /*! @var settleTimer */
101 thread_call_t settleTimer
;
103 /*! @var machine_state
104 State number of state machine processing current change note.
106 unsigned long machine_state
;
109 Settle timer after changing power state.
111 unsigned long settle_time
;
114 Ordinal of change note currently being processed.
118 /*! @var head_note_flags
119 Copy of flags field in change note currently being processed.
121 unsigned long head_note_flags
;
123 /*! @var head_note_state
124 Copy of newStateNumberfield in change note currently being processed.
126 unsigned long head_note_state
;
128 /*! @var head_note_outputFlags
129 OutputPowerCharacter field from change note currently being processed.
131 unsigned long head_note_outputFlags
;
133 /*! @var head_note_domainState
134 Power domain flags from parent... (only on parent change).
136 unsigned long head_note_domainState
;
138 /*! @var head_note_parent
139 Pointer to initiating parent... (only on parent change).
141 IOPowerConnection
* head_note_parent
;
143 /*! @var head_note_capabilityFlags
144 Copy of capabilityFlags field in change note currently being processed.
146 unsigned long head_note_capabilityFlags
;
148 /*! @var head_note_pendingAcks
149 Number of acks we are waiting for during notification.
151 unsigned long head_note_pendingAcks
;
154 Used to control access to head_note_pendingAcks and driver_timer.
159 Used to control access to response flags array.
164 Used to control access to change note queue.
168 /*! @var initial_change
169 True forces first state to be broadcast even if it isn't a change.
173 /*! @var need_to_become_usable
174 Someone called makeUsable before we had a controlling driver.
176 bool need_to_become_usable
;
178 /*! @var device_overrides
179 State changes are made based only on subclass's desire.
181 bool device_overrides
;
184 Domain is clamped on till first child registers.
189 Points to object which made this struct. Used for debug output only.
193 /*! @var activityLock
194 Used to protect activity flag.
196 IOLock
* activityLock
;
198 /*! @var timerEventSrc
201 IOTimerEventSource
* timerEventSrc
;
203 /*! @var idle_timer_period
204 Timer's period in seconds.
206 unsigned long idle_timer_period
;
208 /*! @var clampTimerEventSrc
209 Timer for clamping power on.
211 IOTimerEventSource
* clampTimerEventSrc
;
213 /*! @var device_active
214 True: there has been device activity since last idle timer expiration.
218 /*! @var device_active_timestamp
219 Time in ticks of last activity.
221 AbsoluteTime device_active_timestamp
;
223 /*! @var driverDesire
224 This is the power state desired by our controlling driver. It is initialized to myCurrentState and is changed
225 when the controlling driver calls changePowerStateTo. A change in driverDesire may cause a change in ourDesiredPowerState.
227 unsigned long driverDesire
;
231 /*! @var deviceDesire
232 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.
234 unsigned long deviceDesire
;
238 /*! @var ourDesiredPowerState
239 This is the power state we desire currently. If equal to myCurrentState, we're happy.
240 Otherwise, we're waiting for the parent to raise the power domain to at least this level.
242 If this is a power domain, this is the maximum of all our children's desires, driverDesire, and deviceDesire.
244 a child asks for more power via requestDomainState,
245 the controlling driver asks for more power via changePowerStateTo
248 we lose a child and the child had the highest power need of all our children,
249 the child with the highest power need suggests a lower power domain state,
250 the controlling driver asks for lower power for some reason via changePowerStateTo
252 If this is not a power domain, ourDesiredPowerState represents the greater of driverDesire and deviceDesire.
254 the controlling driver asks for more power via changePowerStateTo
255 some driver calls makeUsable
256 a subclassed object asks for more power via changePowerStateToPriv
259 the controlling driver asks for lower power for some reason via changePowerStateTo
260 a subclassed object asks for lower power for some reason via changePowerStateToPriv
262 unsigned long ourDesiredPowerState
;
265 /*! @var previousRequest
266 This is a reminder of what our parent thinks our need is. Whenever it changes,
267 we call requestDomainState in the parent to keep it current. It is usually equal to ourDesiredPowerState
268 except while a power change is in progress.
270 unsigned long previousRequest
;
276 unsigned long askingFor
;
279 /*! @var imminentState
280 Usually the same as myCurrentState, except right after calling powerStateWillChangeTo.
282 unsigned long imminentState
;
284 /*! @function serialize
285 Serialize private instance variables for debug output (IORegistryDumper).
287 virtual bool serialize(OSSerialize
*s
) const;
296 @abstract Protected power management instance variables for IOService objects.
298 class IOPMprot
: public OSObject
//management
300 friend class IOService
;
302 OSDeclareDefaultStructors(IOPMprot
)
307 From getName(), used in logging.
309 const char * ourName
;
312 From getPlatform, used in logging and registering.
314 IOPlatformExpert
* thePlatform
;
316 /*! @var theNumberOfPowerStates
317 The number of states in the array.
319 unsigned long theNumberOfPowerStates
; // the number of states in the array
321 /*! @var thePowerStates
324 IOPMPowerState thePowerStates
[IOPMMaxPowerStates
];
326 /*! @var theControllingDriver
327 Points to the controlling driver.
329 IOService
* theControllingDriver
;
331 /*! @var aggressiveness
332 Current value of power management aggressiveness.
334 unsigned long aggressiveness
;
336 /*! @var current_aggressiveness_values
337 Array of aggressiveness values.
339 unsigned long current_aggressiveness_values
[kMaxType
+1];
341 /*! @var current_aggressiveness_validity
342 True for values that are currently valid.
344 bool current_aggressiveness_valid
[kMaxType
+1];
346 /*! @var myCurrentState
347 The ordinal of our current power state.
349 unsigned long myCurrentState
;
351 /*! @var parentsKnowState
352 True if all our parents know the state of their power domain.
354 bool parentsKnowState
;
356 /*! @var parentsCurrentPowerFlags
357 Logical OR of power flags for the current state of each power domainparent.
359 IOPMPowerFlags parentsCurrentPowerFlags
;
361 /*! @var maxCapability
362 Ordinal of highest state we can achieve in current power domain state.
364 unsigned long maxCapability
;
367 Points to the single power management workloop.
369 IOWorkLoop
* PMworkloop
;
371 /*! @var commandQueue
372 Used to serialize idle-power-down and busy-power-up.
374 IOCommandQueue
* commandQueue
;
376 /*! @var PMcommandGate
377 Used to serialize timer expirations and incoming acknowledgements.
379 IOCommandGate
* PMcommandGate
;
381 /*! @var myCharacterFlags
382 Logical OR of all output power character flags in the array.
384 IOPMPowerFlags myCharacterFlags
;
386 /*! @var serialNumber
387 Used to uniquely identify power management notification to apps and clients.
391 /*! @var responseFlags
392 Points to an OSArray which manages responses from notified apps and clients.
394 OSArray
* responseFlags
;
396 /*! @var doNotPowerDown
397 Keeps track of any negative responses from notified apps and clients.
402 Used to serialize scanning the children.
407 Used to serialize scanning the parents.
411 /*! @var outofbandparameter
412 Used to communicate desired function to tellClientsWithResponse().
413 This is used because it avoids changing the signatures of the affected virtual methods.
415 int outofbandparameter
;
417 /*! @function serialize
418 Serialize protected instance variables for debug output (IORegistryDumper).
420 virtual bool serialize(OSSerialize
*s
) const;