2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
24 #include <kern/thread_call.h>
27 #include <libkern/c++/OSObject.h>
28 #include <IOKit/IOLocks.h>
30 class IOPMinformeeList
;
31 class IOPMchangeNoteList
;
36 class IOTimerEventSource
;
37 class IOPlatformExpert
;
39 #include <IOKit/pwr_mgt/IOPM.h>
43 @defined ACK_TIMER_PERIOD
44 @discussion When an IOService is waiting for acknowledgement to a power state change
45 notification from an interested driver or the controlling driver its ack timer is ticking every tenth of a second.
46 (100000000 nanoseconds are one tenth of a second).
48 #define ACK_TIMER_PERIOD 100000000
54 @abstract Private power management private instance variables for IOService objects.
56 class IOPMpriv
: public OSObject
58 friend class IOService
;
60 OSDeclareDefaultStructors(IOPMpriv
)
65 TRUE if this device is the root power domain.
69 /*! @var interestedDrivers
70 List of interested drivers.
72 IOPMinformeeList
* interestedDrivers
;
75 List of power domain children.
77 IOPMinformeeList
* children
;
80 List of pending power state changes.
82 IOPMchangeNoteList
* changeList
;
85 Timeout on waiting for controlling driver to acknowledgeSetPowerState.
87 IOReturn driver_timer
;
90 thread_call_t ackTimer
;
92 /*! @var settleTimer */
93 thread_call_t settleTimer
;
95 /*! @var machine_state
96 State number of state machine processing current change note.
98 unsigned long machine_state
;
101 Settle timer after changing power state.
103 unsigned long settle_time
;
106 Ordinal of change note currently being processed.
110 /*! @var head_note_flags
111 Copy of flags field in change note currently being processed.
113 unsigned long head_note_flags
;
115 /*! @var head_note_state
116 Copy of newStateNumberfield in change note currently being processed.
118 unsigned long head_note_state
;
120 /*! @var head_note_outputFlags
121 OutputPowerCharacter field from change note currently being processed.
123 unsigned long head_note_outputFlags
;
125 /*! @var head_note_domainState
126 Power domain flags from parent... (only on parent change).
128 unsigned long head_note_domainState
;
130 /*! @var head_note_parent
131 Pointer to initiating parent... (only on parent change).
133 IOPowerConnection
* head_note_parent
;
135 /*! @var head_note_capabilityFlags
136 Copy of capabilityFlags field in change note currently being processed.
138 unsigned long head_note_capabilityFlags
;
140 /*! @var head_note_pendingAcks
141 Number of acks we are waiting for during notification.
143 unsigned long head_note_pendingAcks
;
146 Used to control access to head_note_pendingAcks and driver_timer.
151 Used to control access to response flags array.
156 Used to control access to change note queue.
160 /*! @var initial_change
161 True forces first state to be broadcast even if it isn't a change.
165 /*! @var need_to_become_usable
166 Someone called makeUsable before we had a controlling driver.
168 bool need_to_become_usable
;
170 /*! @var device_overrides
171 State changes are made based only on subclass's desire.
173 bool device_overrides
;
176 Domain is clamped on till first child registers.
181 Points to object which made this struct. Used for debug output only.
185 /*! @var activityLock
186 Used to protect activity flag.
188 IOLock
* activityLock
;
190 /*! @var timerEventSrc
193 IOTimerEventSource
* timerEventSrc
;
195 /*! @var idle_timer_period
196 Timer's period in seconds.
198 unsigned long idle_timer_period
;
200 /*! @var clampTimerEventSrc
201 Timer for clamping power on.
203 IOTimerEventSource
* clampTimerEventSrc
;
205 /*! @var device_active
206 True: there has been device activity since last idle timer expiration.
210 /*! @var device_active_timestamp
211 Time in ticks of last activity.
213 AbsoluteTime device_active_timestamp
;
215 /*! @var driverDesire
216 This is the power state desired by our controlling driver. It is initialized to myCurrentState and is changed
217 when the controlling driver calls changePowerStateTo. A change in driverDesire may cause a change in ourDesiredPowerState.
219 unsigned long driverDesire
;
223 /*! @var deviceDesire
224 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.
226 unsigned long deviceDesire
;
230 /*! @var ourDesiredPowerState
231 This is the power state we desire currently. If equal to myCurrentState, we're happy.
232 Otherwise, we're waiting for the parent to raise the power domain to at least this level.
234 If this is a power domain, this is the maximum of all our children's desires, driverDesire, and deviceDesire.
236 a child asks for more power via requestDomainState,
237 the controlling driver asks for more power via changePowerStateTo
240 we lose a child and the child had the highest power need of all our children,
241 the child with the highest power need suggests a lower power domain state,
242 the controlling driver asks for lower power for some reason via changePowerStateTo
244 If this is not a power domain, ourDesiredPowerState represents the greater of driverDesire and deviceDesire.
246 the controlling driver asks for more power via changePowerStateTo
247 some driver calls makeUsable
248 a subclassed object asks for more power via changePowerStateToPriv
251 the controlling driver asks for lower power for some reason via changePowerStateTo
252 a subclassed object asks for lower power for some reason via changePowerStateToPriv
254 unsigned long ourDesiredPowerState
;
257 /*! @var previousRequest
258 This is a reminder of what our parent thinks our need is. Whenever it changes,
259 we call requestDomainState in the parent to keep it current. It is usually equal to ourDesiredPowerState
260 except while a power change is in progress.
262 unsigned long previousRequest
;
268 unsigned long askingFor
;
271 /*! @var imminentState
272 Usually the same as myCurrentState, except right after calling powerStateWillChangeTo.
274 unsigned long imminentState
;
276 /*! @function serialize
277 Serialize private instance variables for debug output (IORegistryDumper).
279 virtual bool serialize(OSSerialize
*s
) const;
288 @abstract Protected power management instance variables for IOService objects.
290 class IOPMprot
: public OSObject
//management
292 friend class IOService
;
294 OSDeclareDefaultStructors(IOPMprot
)
299 From getName(), used in logging.
301 const char * ourName
;
304 From getPlatform, used in logging and registering.
306 IOPlatformExpert
* thePlatform
;
308 /*! @var theNumberOfPowerStates
309 The number of states in the array.
311 unsigned long theNumberOfPowerStates
; // the number of states in the array
313 /*! @var thePowerStates
316 IOPMPowerState thePowerStates
[IOPMMaxPowerStates
];
318 /*! @var theControllingDriver
319 Points to the controlling driver.
321 IOService
* theControllingDriver
;
323 /*! @var aggressiveness
324 Current value of power management aggressiveness.
326 unsigned long aggressiveness
;
328 /*! @var current_aggressiveness_values
329 Array of aggressiveness values.
331 unsigned long current_aggressiveness_values
[kMaxType
+1];
333 /*! @var current_aggressiveness_validity
334 True for values that are currently valid.
336 bool current_aggressiveness_valid
[kMaxType
+1];
338 /*! @var myCurrentState
339 The ordinal of our current power state.
341 unsigned long myCurrentState
;
343 /*! @var parentsKnowState
344 True if all our parents know the state of their power domain.
346 bool parentsKnowState
;
348 /*! @var parentsCurrentPowerFlags
349 Logical OR of power flags for the current state of each power domainparent.
351 IOPMPowerFlags parentsCurrentPowerFlags
;
353 /*! @var maxCapability
354 Ordinal of highest state we can achieve in current power domain state.
356 unsigned long maxCapability
;
359 Points to the single power management workloop.
361 IOWorkLoop
* PMworkloop
;
363 /*! @var commandQueue
364 Used to serialize idle-power-down and busy-power-up.
366 IOCommandQueue
* commandQueue
;
368 /*! @var PMcommandGate
369 Used to serialize timer expirations and incoming acknowledgements.
371 IOCommandGate
* PMcommandGate
;
373 /*! @var myCharacterFlags
374 Logical OR of all output power character flags in the array.
376 IOPMPowerFlags myCharacterFlags
;
378 /*! @var serialNumber
379 Used to uniquely identify power management notification to apps and clients.
383 /*! @var responseFlags
384 Points to an OSArray which manages responses from notified apps and clients.
386 OSArray
* responseFlags
;
388 /*! @var doNotPowerDown
389 Keeps track of any negative responses from notified apps and clients.
394 Used to serialize scanning the children.
399 Used to serialize scanning the parents.
403 /*! @var outofbandparameter
404 Used to communicate desired function to tellClientsWithResponse().
405 This is used because it avoids changing the signatures of the affected virtual methods.
407 int outofbandparameter
;
409 /*! @function serialize
410 Serialize protected instance variables for debug output (IORegistryDumper).
412 virtual bool serialize(OSSerialize
*s
) const;