]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/IOServicePM.h
xnu-792.6.22.tar.gz
[apple/xnu.git] / iokit / IOKit / IOServicePM.h
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
e5568f75
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.
1c79356b 11 *
e5568f75
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
1c79356b
A
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
e5568f75
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.
1c79356b
A
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22
23extern "C" {
24#include <kern/thread_call.h>
25}
26
27#include <libkern/c++/OSObject.h>
28#include <IOKit/IOLocks.h>
29class IOPMinformee;
30class IOPMinformeeList;
31class IOPMchangeNoteList;
32class IOPMpmChild;
33class IOWorkLoop;
34class IOCommandQueue;
35class IOCommandGate;
36class IOTimerEventSource;
37class IOPlatformExpert;
38
39#include <IOKit/pwr_mgt/IOPM.h>
40
41
42/*!
43@defined ACK_TIMER_PERIOD
44@discussion When an IOService is waiting for acknowledgement to a power state change
45notification 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).
47*/
48 #define ACK_TIMER_PERIOD 100000000
49
50
51
52/*!
91447636 53@class IOPMpriv
1c79356b
A
54@abstract Private power management private instance variables for IOService objects.
55*/
56class IOPMpriv : public OSObject
57{
58 friend class IOService;
59
60 OSDeclareDefaultStructors(IOPMpriv)
61
62 public:
63
91447636
A
64/*! @var we_are_root
65 TRUE if this device is the root power domain.
66*/
1c79356b
A
67 bool we_are_root;
68
91447636
A
69 /*! @var interestedDrivers
70 List of interested drivers.
71 */
1c79356b
A
72 IOPMinformeeList * interestedDrivers;
73
91447636
A
74 /*! @var children
75 List of power domain children.
76 */
1c79356b
A
77 IOPMinformeeList * children;
78
91447636
A
79 /*! @var changeList
80 List of pending power state changes.
81 */
1c79356b
A
82 IOPMchangeNoteList * changeList;
83
91447636
A
84 /*! @var driver_timer
85 Timeout on waiting for controlling driver to acknowledgeSetPowerState.
86 */
1c79356b
A
87 IOReturn driver_timer;
88
91447636 89 /*! @var ackTimer */
1c79356b
A
90 thread_call_t ackTimer;
91
91447636 92 /*! @var settleTimer */
1c79356b
A
93 thread_call_t settleTimer;
94
91447636
A
95 /*! @var machine_state
96 State number of state machine processing current change note.
97 */
1c79356b
A
98 unsigned long machine_state;
99
91447636
A
100 /*! @var settle_time
101 Settle timer after changing power state.
102 */
1c79356b
A
103 unsigned long settle_time;
104
91447636
A
105 /*! @var head_note
106 Ordinal of change note currently being processed.
107 */
1c79356b
A
108 long head_note;
109
91447636
A
110 /*! @var head_note_flags
111 Copy of flags field in change note currently being processed.
112 */
1c79356b
A
113 unsigned long head_note_flags;
114
91447636
A
115 /*! @var head_note_state
116 Copy of newStateNumberfield in change note currently being processed.
117 */
1c79356b
A
118 unsigned long head_note_state;
119
91447636
A
120 /*! @var head_note_outputFlags
121 OutputPowerCharacter field from change note currently being processed.
122 */
1c79356b
A
123 unsigned long head_note_outputFlags;
124
91447636
A
125 /*! @var head_note_domainState
126 Power domain flags from parent... (only on parent change).
127 */
1c79356b
A
128 unsigned long head_note_domainState;
129
91447636
A
130 /*! @var head_note_parent
131 Pointer to initiating parent... (only on parent change).
132 */
1c79356b
A
133 IOPowerConnection * head_note_parent;
134
91447636
A
135 /*! @var head_note_capabilityFlags
136 Copy of capabilityFlags field in change note currently being processed.
137 */
1c79356b
A
138 unsigned long head_note_capabilityFlags;
139
91447636
A
140 /*! @var head_note_pendingAcks
141 Number of acks we are waiting for during notification.
142 */
1c79356b
A
143 unsigned long head_note_pendingAcks;
144
91447636
A
145 /*! @var our_lock
146 Used to control access to head_note_pendingAcks and driver_timer.
147 */
1c79356b
A
148 IOLock * our_lock;
149
91447636
A
150 /*! @var flags_lock
151 Used to control access to response flags array.
152 */
1c79356b
A
153 IOLock * flags_lock;
154
91447636
A
155 /*! @var queue_lock
156 Used to control access to change note queue.
157 */
0b4e3aa0
A
158 IOLock * queue_lock;
159
91447636
A
160 /*! @var initial_change
161 True forces first state to be broadcast even if it isn't a change.
162 */
1c79356b
A
163 bool initial_change;
164
91447636
A
165 /*! @var need_to_become_usable
166 Someone called makeUsable before we had a controlling driver.
167 */
1c79356b
A
168 bool need_to_become_usable;
169
91447636
A
170 /*! @var device_overrides
171 State changes are made based only on subclass's desire.
172 */
1c79356b
A
173 bool device_overrides;
174
91447636
A
175 /*! @var clampOn
176 Domain is clamped on till first child registers.
177 */
1c79356b
A
178 bool clampOn;
179
91447636
A
180 /*! @var owner
181 Points to object which made this struct. Used for debug output only.
182 */
1c79356b
A
183 IOService * owner;
184
91447636
A
185 /*! @var activityLock
186 Used to protect activity flag.
187 */
1c79356b
A
188 IOLock * activityLock;
189
91447636
A
190 /*! @var timerEventSrc
191 An idle timer.
192 */
1c79356b
A
193 IOTimerEventSource * timerEventSrc;
194
91447636
A
195 /*! @var idle_timer_period
196 Timer's period in seconds.
197 */
1c79356b
A
198 unsigned long idle_timer_period;
199
91447636
A
200 /*! @var clampTimerEventSrc
201 Timer for clamping power on.
202 */
1c79356b
A
203 IOTimerEventSource * clampTimerEventSrc;
204
91447636
A
205 /*! @var device_active
206 True: there has been device activity since last idle timer expiration.
207 */
1c79356b
A
208 bool device_active;
209
91447636
A
210 /*! @var device_active_timestamp
211 Time in ticks of last activity.
212 */
e7c99d92
A
213 AbsoluteTime device_active_timestamp;
214
91447636
A
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.
1c79356b
A
218*/
219 unsigned long driverDesire;
220
221
222
91447636
A
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.
1c79356b
A
225*/
226 unsigned long deviceDesire;
227
228
229
91447636 230 /*! @var ourDesiredPowerState
1c79356b
A
231This is the power state we desire currently. If equal to myCurrentState, we're happy.
232Otherwise, we're waiting for the parent to raise the power domain to at least this level.
233
234If this is a power domain, this is the maximum of all our children's desires, driverDesire, and deviceDesire.
235It increases when:
236a child asks for more power via requestDomainState,
237the controlling driver asks for more power via changePowerStateTo
238
239It decreases when:
240we lose a child and the child had the highest power need of all our children,
241the child with the highest power need suggests a lower power domain state,
242the controlling driver asks for lower power for some reason via changePowerStateTo
243
244If this is not a power domain, ourDesiredPowerState represents the greater of driverDesire and deviceDesire.
245It increases when:
246the controlling driver asks for more power via changePowerStateTo
247some driver calls makeUsable
248a subclassed object asks for more power via changePowerStateToPriv
249
250It decreases when:
251the controlling driver asks for lower power for some reason via changePowerStateTo
252a subclassed object asks for lower power for some reason via changePowerStateToPriv
253*/
254 unsigned long ourDesiredPowerState;
255
256
91447636 257 /*! @var previousRequest
1c79356b
A
258This is a reminder of what our parent thinks our need is. Whenever it changes,
259we call requestDomainState in the parent to keep it current. It is usually equal to ourDesiredPowerState
260except while a power change is in progress.
261*/
262 unsigned long previousRequest;
263
264
91447636
A
265 /*! @var askingFor
266 Not used.
1c79356b
A
267*/
268 unsigned long askingFor;
269
270
91447636
A
271 /*! @var imminentState
272 Usually the same as myCurrentState, except right after calling powerStateWillChangeTo.
1c79356b
A
273*/
274 unsigned long imminentState;
275
276 /*! @function serialize
91447636 277 Serialize private instance variables for debug output (IORegistryDumper).
1c79356b
A
278*/
279 virtual bool serialize(OSSerialize *s) const;
280
281};
282
283
284
285
286/*!
91447636 287@class IOPMprott
1c79356b
A
288@abstract Protected power management instance variables for IOService objects.
289*/
290class IOPMprot : public OSObject //management
291{
292 friend class IOService;
293
294 OSDeclareDefaultStructors(IOPMprot)
295
296 public:
297
91447636
A
298 /*! @var ourName
299 From getName(), used in logging.
300 */
1c79356b
A
301 const char * ourName;
302
91447636
A
303 /*! @var thePlatform
304 From getPlatform, used in logging and registering.
305 */
1c79356b
A
306 IOPlatformExpert * thePlatform;
307
91447636
A
308 /*! @var theNumberOfPowerStates
309 The number of states in the array.
310 */
1c79356b
A
311 unsigned long theNumberOfPowerStates; // the number of states in the array
312
91447636
A
313 /*! @var thePowerStates
314 The array.
315 */
1c79356b
A
316 IOPMPowerState thePowerStates[IOPMMaxPowerStates];
317
91447636
A
318 /*! @var theControllingDriver
319 Points to the controlling driver.
320 */
1c79356b
A
321 IOService * theControllingDriver;
322
91447636
A
323 /*! @var aggressiveness
324 Current value of power management aggressiveness.
325 */
1c79356b
A
326 unsigned long aggressiveness;
327
91447636
A
328 /*! @var current_aggressiveness_values
329 Array of aggressiveness values.
330 */
1c79356b
A
331 unsigned long current_aggressiveness_values [kMaxType+1];
332
91447636
A
333 /*! @var current_aggressiveness_validity
334 True for values that are currently valid.
335 */
1c79356b
A
336 bool current_aggressiveness_valid [kMaxType+1];
337
91447636
A
338 /*! @var myCurrentState
339 The ordinal of our current power state.
340 */
1c79356b
A
341 unsigned long myCurrentState;
342
91447636
A
343 /*! @var parentsKnowState
344 True if all our parents know the state of their power domain.
345 */
1c79356b
A
346 bool parentsKnowState;
347
91447636
A
348 /*! @var parentsCurrentPowerFlags
349 Logical OR of power flags for the current state of each power domainparent.
350 */
1c79356b
A
351 IOPMPowerFlags parentsCurrentPowerFlags;
352
91447636
A
353 /*! @var maxCapability
354 Ordinal of highest state we can achieve in current power domain state.
355 */
1c79356b
A
356 unsigned long maxCapability;
357
91447636
A
358 /*! @var PMworkloop
359 Points to the single power management workloop.
360 */
1c79356b
A
361 IOWorkLoop * PMworkloop;
362
91447636
A
363 /*! @var commandQueue
364 Used to serialize idle-power-down and busy-power-up.
365 */
1c79356b
A
366 IOCommandQueue * commandQueue;
367
91447636
A
368 /*! @var PMcommandGate
369 Used to serialize timer expirations and incoming acknowledgements.
370 */
1c79356b
A
371 IOCommandGate * PMcommandGate;
372
91447636
A
373 /*! @var myCharacterFlags
374 Logical OR of all output power character flags in the array.
375 */
1c79356b
A
376 IOPMPowerFlags myCharacterFlags;
377
91447636
A
378 /*! @var serialNumber
379 Used to uniquely identify power management notification to apps and clients.
380 */
1c79356b
A
381 UInt16 serialNumber;
382
91447636
A
383 /*! @var responseFlags
384 Points to an OSArray which manages responses from notified apps and clients.
385 */
1c79356b
A
386 OSArray* responseFlags;
387
91447636
A
388 /*! @var doNotPowerDown
389 Keeps track of any negative responses from notified apps and clients.
390 */
1c79356b
A
391 bool doNotPowerDown;
392
91447636
A
393 /*! @var childLock
394 Used to serialize scanning the children.
395 */
0b4e3aa0
A
396 IOLock * childLock;
397
91447636
A
398 /*! @var parentLock
399 Used to serialize scanning the parents.
400 */
0b4e3aa0
A
401 IOLock * parentLock;
402
91447636
A
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.
406 */
0b4e3aa0
A
407 int outofbandparameter;
408
1c79356b
A
409 /*! @function serialize
410Serialize protected instance variables for debug output (IORegistryDumper).
411*/
412 virtual bool serialize(OSSerialize *s) const;
413
414};
415