]>
Commit | Line | Data |
---|---|---|
2d21ac55 A |
1 | /* |
2 | * Copyright (c) 2007 Apple Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ | |
5 | * | |
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 License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
14 | * | |
15 | * Please obtain a copy of the License at | |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, | |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. | |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
25 | * | |
26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ | |
27 | */ | |
28 | ||
29 | #ifndef _IOKIT_IOSERVICEPMPRIVATE_H | |
30 | #define _IOKIT_IOSERVICEPMPRIVATE_H | |
31 | ||
6d2010ae A |
32 | #include <IOKit/IOCommand.h> |
33 | #include <IOKit/IOEventSource.h> | |
34 | ||
35 | //****************************************************************************** | |
36 | // PM command types | |
37 | //****************************************************************************** | |
38 | ||
39 | enum { | |
40 | /* Command Types */ | |
41 | kIOPMRequestTypeInvalid = 0x00, | |
42 | kIOPMRequestTypePMStop = 0x01, | |
43 | kIOPMRequestTypeAddPowerChild1 = 0x02, | |
44 | kIOPMRequestTypeAddPowerChild2 = 0x03, | |
45 | kIOPMRequestTypeAddPowerChild3 = 0x04, | |
46 | kIOPMRequestTypeRegisterPowerDriver = 0x05, | |
47 | kIOPMRequestTypeAdjustPowerState = 0x06, | |
48 | kIOPMRequestTypePowerDomainWillChange = 0x07, | |
49 | kIOPMRequestTypePowerDomainDidChange = 0x08, | |
50 | kIOPMRequestTypePowerOverrideOnPriv = 0x09, | |
51 | kIOPMRequestTypePowerOverrideOffPriv = 0x0A, | |
52 | kIOPMRequestTypeActivityTickle = 0x0B, | |
53 | kIOPMRequestTypeRequestPowerState = 0x0C, | |
54 | kIOPMRequestTypeSynchronizePowerTree = 0x0D, | |
55 | kIOPMRequestTypeRequestPowerStateOverride = 0x0E, | |
56 | kIOPMRequestTypeSetIdleTimerPeriod = 0x0F, | |
7ddcb079 | 57 | kIOPMRequestTypeIgnoreIdleTimer = 0x10, |
6d2010ae A |
58 | |
59 | /* Reply Types */ | |
60 | kIOPMRequestTypeReplyStart = 0x80, | |
61 | kIOPMRequestTypeAckPowerChange = 0x81, | |
62 | kIOPMRequestTypeAckSetPowerState = 0x82, | |
63 | kIOPMRequestTypeAllowPowerChange = 0x83, | |
64 | kIOPMRequestTypeCancelPowerChange = 0x84, | |
65 | kIOPMRequestTypeInterestChanged = 0x85, | |
66 | kIOPMRequestTypeIdleCancel = 0x86, | |
67 | kIOPMRequestTypeChildNotifyDelayCancel = 0x87 | |
68 | }; | |
69 | ||
70 | //****************************************************************************** | |
71 | // PM actions - For root domain only | |
72 | //****************************************************************************** | |
73 | ||
74 | struct IOPMActions; | |
75 | ||
76 | typedef void | |
77 | (*IOPMActionPowerChangeStart)( | |
78 | void * target, | |
79 | IOService * service, | |
80 | IOPMActions * actions, | |
81 | uint32_t powerState, | |
82 | uint32_t * changeFlags ); | |
83 | ||
84 | typedef void | |
85 | (*IOPMActionPowerChangeDone)( | |
86 | void * target, | |
87 | IOService * service, | |
88 | IOPMActions * actions, | |
89 | uint32_t powerState, | |
90 | uint32_t changeFlags ); | |
91 | ||
92 | typedef void | |
93 | (*IOPMActionPowerChangeOverride)( | |
94 | void * target, | |
95 | IOService * service, | |
96 | IOPMActions * actions, | |
97 | unsigned long * powerState, | |
98 | uint32_t * changeFlags ); | |
99 | ||
100 | typedef void | |
101 | (*IOPMActionActivityTickle)( | |
102 | void * target, | |
103 | IOService * service, | |
104 | IOPMActions * actions ); | |
105 | ||
106 | struct IOPMActions { | |
107 | void * target; | |
108 | uint32_t parameter; | |
109 | IOPMActionPowerChangeStart actionPowerChangeStart; | |
110 | IOPMActionPowerChangeDone actionPowerChangeDone; | |
111 | IOPMActionPowerChangeOverride actionPowerChangeOverride; | |
112 | IOPMActionActivityTickle actionActivityTickle; | |
113 | }; | |
114 | ||
115 | //****************************************************************************** | |
116 | ||
117 | enum { | |
118 | kIOPMEventClassSystemEvent = 0x00, | |
119 | kIOPMEventClassDriverEvent = 0x1 | |
120 | }; | |
121 | ||
122 | class PMEventDetails : public OSObject | |
123 | { | |
124 | OSDeclareDefaultStructors( PMEventDetails ); | |
125 | friend class IOServicePM; | |
126 | friend class IOPMrootDomain; | |
127 | friend class IOPMTimeline; | |
128 | public: | |
129 | static PMEventDetails *eventDetails(uint32_t type, | |
130 | const char *ownerName, | |
131 | uintptr_t ownerUnique, | |
132 | const char *interestName, | |
133 | uint8_t oldState, | |
134 | uint8_t newState, | |
135 | uint32_t result, | |
136 | uint32_t elapsedTimeUS); | |
137 | ||
138 | static PMEventDetails *eventDetails(uint32_t type, | |
139 | const char *uuid, | |
140 | uint32_t reason, | |
141 | uint32_t result); | |
142 | private: | |
143 | uint8_t eventClassifier; | |
144 | uint32_t eventType; | |
145 | const char *ownerName; | |
146 | uintptr_t ownerUnique; | |
147 | const char *interestName; | |
148 | uint8_t oldState; | |
149 | uint8_t newState; | |
150 | uint32_t result; | |
151 | uint32_t elapsedTimeUS; | |
152 | ||
153 | const char *uuid; | |
154 | uint32_t reason; | |
155 | }; | |
156 | ||
157 | // Internal concise representation of IOPMPowerState | |
158 | struct IOPMPSEntry | |
159 | { | |
160 | IOPMPowerFlags capabilityFlags; | |
161 | IOPMPowerFlags outputPowerFlags; | |
162 | IOPMPowerFlags inputPowerFlags; | |
163 | uint32_t staticPower; | |
164 | uint32_t settleUpTime; | |
165 | uint32_t settleDownTime; | |
166 | }; | |
167 | ||
168 | //****************************************************************************** | |
169 | // IOServicePM | |
170 | //****************************************************************************** | |
171 | ||
2d21ac55 A |
172 | class IOServicePM : public OSObject |
173 | { | |
174 | friend class IOService; | |
6d2010ae | 175 | friend class IOPMWorkQueue; |
2d21ac55 A |
176 | |
177 | OSDeclareDefaultStructors( IOServicePM ) | |
178 | ||
179 | private: | |
6d2010ae A |
180 | // Link IOServicePM objects on IOPMWorkQueue. |
181 | queue_chain_t WorkChain; | |
182 | ||
183 | // Queue of IOPMRequest objects. | |
184 | queue_head_t RequestHead; | |
185 | ||
186 | // IOService creator and owner. | |
187 | IOService * Owner; | |
188 | ||
189 | // List of interested drivers (protected by PMLock). | |
2d21ac55 A |
190 | IOPMinformeeList * InterestedDrivers; |
191 | ||
b0d623f7 | 192 | // How long to wait for controlling driver to acknowledge. |
2d21ac55 A |
193 | IOReturn DriverTimer; |
194 | ||
b0d623f7 A |
195 | // Current power management machine state. |
196 | uint32_t MachineState; | |
2d21ac55 | 197 | |
b0d623f7 | 198 | thread_call_t AckTimer; |
2d21ac55 | 199 | thread_call_t SettleTimer; |
6d2010ae | 200 | thread_call_t IdleTimer; |
2d21ac55 | 201 | |
b0d623f7 | 202 | // Settle time after changing power state. |
6d2010ae | 203 | uint32_t SettleTimeUS; |
2d21ac55 | 204 | |
b0d623f7 | 205 | // The flags describing current change note. |
6d2010ae | 206 | IOPMPowerChangeFlags HeadNoteChangeFlags; |
2d21ac55 | 207 | |
b0d623f7 | 208 | // The new power state number being changed to. |
6d2010ae | 209 | IOPMPowerStateIndex HeadNotePowerState; |
b0d623f7 A |
210 | |
211 | // Points to the entry in the power state array. | |
6d2010ae | 212 | IOPMPSEntry * HeadNotePowerArrayEntry; |
b0d623f7 A |
213 | |
214 | // Power flags supplied by all parents (domain). | |
6d2010ae | 215 | IOPMPowerFlags HeadNoteDomainFlags; |
b0d623f7 | 216 | |
7e4a7d39 A |
217 | // Power flags supplied by domain accounting for parent changes. |
218 | IOPMPowerFlags HeadNoteDomainTargetFlags; | |
219 | ||
b0d623f7 A |
220 | // Connection attached to the changing parent. |
221 | IOPowerConnection * HeadNoteParentConnection; | |
2d21ac55 | 222 | |
b0d623f7 | 223 | // Power flags supplied by the changing parent. |
6d2010ae | 224 | IOPMPowerFlags HeadNoteParentFlags; |
b0d623f7 A |
225 | |
226 | // Number of acks still outstanding. | |
6d2010ae | 227 | uint32_t HeadNotePendingAcks; |
2d21ac55 | 228 | |
b0d623f7 | 229 | // PM state lock. |
6d2010ae A |
230 | IOLock * PMLock; |
231 | ||
232 | unsigned int InitialPowerChange:1; | |
233 | unsigned int InitialSetPowerState:1; | |
234 | unsigned int DeviceOverrideEnabled:1; | |
235 | unsigned int DeviceWasActive:1; | |
236 | unsigned int DoNotPowerDown:1; | |
237 | unsigned int ParentsKnowState:1; | |
238 | unsigned int StrictTreeOrder:1; | |
239 | unsigned int IdleTimerStopped:1; | |
240 | unsigned int AdjustPowerScheduled:1; | |
241 | unsigned int IsPreChange:1; | |
242 | unsigned int DriverCallBusy:1; | |
243 | unsigned int PCDFunctionOverride:1; | |
7ddcb079 | 244 | unsigned int IdleTimerIgnored:1; |
b0d623f7 A |
245 | |
246 | // Time of last device activity. | |
2d21ac55 A |
247 | AbsoluteTime DeviceActiveTimestamp; |
248 | ||
b0d623f7 | 249 | // Used to protect activity flag. |
2d21ac55 A |
250 | IOLock * ActivityLock; |
251 | ||
b0d623f7 | 252 | // Idle timer's period in seconds. |
2d21ac55 | 253 | unsigned long IdleTimerPeriod; |
cf7d32b8 | 254 | unsigned long IdleTimerMinPowerState; |
b0d623f7 | 255 | AbsoluteTime IdleTimerStartTime; |
2d21ac55 | 256 | |
b0d623f7 | 257 | // Power state desired by a subclassed device object. |
6d2010ae | 258 | IOPMPowerStateIndex DeviceDesire; |
2d21ac55 | 259 | |
b0d623f7 | 260 | // This is the power state we desire currently. |
6d2010ae | 261 | IOPMPowerStateIndex DesiredPowerState; |
2d21ac55 | 262 | |
b0d623f7 | 263 | // This is what our parent thinks our need is. |
6d2010ae | 264 | IOPMPowerFlags PreviousRequestPowerFlags; |
2d21ac55 | 265 | |
b0d623f7 | 266 | // Cache result from getName(), used in logging. |
2d21ac55 A |
267 | const char * Name; |
268 | ||
b0d623f7 | 269 | // Number of power states in the power array. |
6d2010ae | 270 | IOPMPowerStateIndex NumberOfPowerStates; |
2d21ac55 | 271 | |
b0d623f7 | 272 | // Power state array. |
6d2010ae | 273 | IOPMPSEntry * PowerStates; |
2d21ac55 | 274 | |
b0d623f7 | 275 | // The controlling driver. |
6d2010ae | 276 | IOService * ControllingDriver; |
2d21ac55 | 277 | |
b0d623f7 | 278 | // Our current power state. |
6d2010ae | 279 | IOPMPowerStateIndex CurrentPowerState; |
2d21ac55 | 280 | |
b0d623f7 | 281 | // Logical OR of power flags for each power domain parent. |
6d2010ae | 282 | IOPMPowerFlags ParentsCurrentPowerFlags; |
2d21ac55 | 283 | |
b0d623f7 | 284 | // The highest power state we can achieve in current power domain. |
6d2010ae | 285 | IOPMPowerStateIndex MaxPowerState; |
2d21ac55 | 286 | |
b0d623f7 | 287 | // Logical OR of all output power character flags in the array. |
6d2010ae | 288 | IOPMPowerFlags OutputPowerCharacterFlags; |
2d21ac55 | 289 | |
b0d623f7 | 290 | // OSArray which manages responses from notified apps and clients. |
6d2010ae | 291 | OSArray * ResponseArray; |
b0d623f7 A |
292 | OSArray * NotifyClientArray; |
293 | ||
294 | // Used to uniquely identify power management notification to apps and clients. | |
6d2010ae | 295 | UInt16 SerialNumber; |
2d21ac55 | 296 | |
b0d623f7 A |
297 | // Used to communicate desired function to tellClientsWithResponse(). |
298 | // This is used because it avoids changing the signatures of the affected virtual methods. | |
6d2010ae | 299 | int OutOfBandParameter; |
2d21ac55 A |
300 | |
301 | AbsoluteTime DriverCallStartTime; | |
302 | IOPMPowerFlags CurrentCapabilityFlags; | |
b0d623f7 | 303 | long ActivityTicklePowerState; |
2d21ac55 | 304 | unsigned long CurrentPowerConsumption; |
6d2010ae A |
305 | IOPMPowerStateIndex TempClampPowerState; |
306 | OSArray * NotifyChildArray; | |
b0d623f7 | 307 | OSDictionary * PowerClients; |
6d2010ae A |
308 | thread_call_t DriverCallEntry; |
309 | void * DriverCallParamPtr; | |
310 | IOItemCount DriverCallParamCount; | |
311 | IOItemCount DriverCallParamSlots; | |
b0d623f7 | 312 | uint32_t DriverCallReason; |
6d2010ae | 313 | uint32_t OutOfBandMessage; |
b0d623f7 A |
314 | uint32_t TempClampCount; |
315 | uint32_t OverrideMaxPowerState; | |
316 | uint32_t ActivityTickleCount; | |
317 | uint32_t WaitReason; | |
6d2010ae | 318 | uint32_t SavedMachineState; |
b0d623f7 | 319 | uint32_t RootDomainState; |
b0d623f7 | 320 | |
6d2010ae | 321 | // Protected by PMLock - BEGIN |
b0d623f7 | 322 | struct { |
6d2010ae A |
323 | uint32_t PMStop : 1; |
324 | uint32_t PMDriverCallWait : 1; | |
b0d623f7 A |
325 | } LockedFlags; |
326 | ||
6d2010ae A |
327 | queue_head_t PMDriverCallQueue; |
328 | OSSet * InsertInterestSet; | |
329 | OSSet * RemoveInterestSet; | |
330 | // Protected by PMLock - END | |
2d21ac55 A |
331 | |
332 | #if PM_VARS_SUPPORT | |
6d2010ae | 333 | IOPMprot * PMVars; |
2d21ac55 A |
334 | #endif |
335 | ||
6d2010ae A |
336 | IOPMActions PMActions; |
337 | ||
b0d623f7 A |
338 | // Serialize IOServicePM state for debug output. |
339 | IOReturn gatedSerialize( OSSerialize * s ); | |
2d21ac55 A |
340 | virtual bool serialize( OSSerialize * s ) const; |
341 | }; | |
342 | ||
6d2010ae | 343 | #define fOwner pwrMgt->Owner |
2d21ac55 A |
344 | #define fInterestedDrivers pwrMgt->InterestedDrivers |
345 | #define fDriverTimer pwrMgt->DriverTimer | |
6d2010ae | 346 | #define fMachineState pwrMgt->MachineState |
2d21ac55 A |
347 | #define fAckTimer pwrMgt->AckTimer |
348 | #define fSettleTimer pwrMgt->SettleTimer | |
6d2010ae | 349 | #define fIdleTimer pwrMgt->IdleTimer |
2d21ac55 | 350 | #define fSettleTimeUS pwrMgt->SettleTimeUS |
6d2010ae | 351 | #define fHeadNoteChangeFlags pwrMgt->HeadNoteChangeFlags |
b0d623f7 A |
352 | #define fHeadNotePowerState pwrMgt->HeadNotePowerState |
353 | #define fHeadNotePowerArrayEntry pwrMgt->HeadNotePowerArrayEntry | |
354 | #define fHeadNoteDomainFlags pwrMgt->HeadNoteDomainFlags | |
7e4a7d39 | 355 | #define fHeadNoteDomainTargetFlags pwrMgt->HeadNoteDomainTargetFlags |
b0d623f7 A |
356 | #define fHeadNoteParentConnection pwrMgt->HeadNoteParentConnection |
357 | #define fHeadNoteParentFlags pwrMgt->HeadNoteParentFlags | |
2d21ac55 A |
358 | #define fHeadNotePendingAcks pwrMgt->HeadNotePendingAcks |
359 | #define fPMLock pwrMgt->PMLock | |
6d2010ae A |
360 | #define fInitialPowerChange pwrMgt->InitialPowerChange |
361 | #define fInitialSetPowerState pwrMgt->InitialSetPowerState | |
362 | #define fDeviceOverrideEnabled pwrMgt->DeviceOverrideEnabled | |
363 | #define fDeviceWasActive pwrMgt->DeviceWasActive | |
364 | #define fDoNotPowerDown pwrMgt->DoNotPowerDown | |
365 | #define fParentsKnowState pwrMgt->ParentsKnowState | |
366 | #define fStrictTreeOrder pwrMgt->StrictTreeOrder | |
367 | #define fIdleTimerStopped pwrMgt->IdleTimerStopped | |
368 | #define fAdjustPowerScheduled pwrMgt->AdjustPowerScheduled | |
369 | #define fIsPreChange pwrMgt->IsPreChange | |
370 | #define fDriverCallBusy pwrMgt->DriverCallBusy | |
371 | #define fPCDFunctionOverride pwrMgt->PCDFunctionOverride | |
7ddcb079 | 372 | #define fIdleTimerIgnored pwrMgt->IdleTimerIgnored |
6d2010ae | 373 | #define fDeviceActiveTimestamp pwrMgt->DeviceActiveTimestamp |
2d21ac55 | 374 | #define fActivityLock pwrMgt->ActivityLock |
2d21ac55 | 375 | #define fIdleTimerPeriod pwrMgt->IdleTimerPeriod |
cf7d32b8 | 376 | #define fIdleTimerMinPowerState pwrMgt->IdleTimerMinPowerState |
b0d623f7 | 377 | #define fIdleTimerStartTime pwrMgt->IdleTimerStartTime |
2d21ac55 | 378 | #define fDeviceDesire pwrMgt->DeviceDesire |
2d21ac55 | 379 | #define fDesiredPowerState pwrMgt->DesiredPowerState |
6d2010ae | 380 | #define fPreviousRequestPowerFlags pwrMgt->PreviousRequestPowerFlags |
2d21ac55 | 381 | #define fName pwrMgt->Name |
2d21ac55 A |
382 | #define fNumberOfPowerStates pwrMgt->NumberOfPowerStates |
383 | #define fPowerStates pwrMgt->PowerStates | |
384 | #define fControllingDriver pwrMgt->ControllingDriver | |
2d21ac55 | 385 | #define fCurrentPowerState pwrMgt->CurrentPowerState |
2d21ac55 | 386 | #define fParentsCurrentPowerFlags pwrMgt->ParentsCurrentPowerFlags |
6d2010ae | 387 | #define fMaxPowerState pwrMgt->MaxPowerState |
2d21ac55 | 388 | #define fOutputPowerCharacterFlags pwrMgt->OutputPowerCharacterFlags |
2d21ac55 | 389 | #define fResponseArray pwrMgt->ResponseArray |
b0d623f7 | 390 | #define fNotifyClientArray pwrMgt->NotifyClientArray |
6d2010ae | 391 | #define fSerialNumber pwrMgt->SerialNumber |
2d21ac55 A |
392 | #define fOutOfBandParameter pwrMgt->OutOfBandParameter |
393 | #define fDriverCallStartTime pwrMgt->DriverCallStartTime | |
394 | #define fCurrentCapabilityFlags pwrMgt->CurrentCapabilityFlags | |
6d2010ae | 395 | #define fActivityTicklePowerState pwrMgt->ActivityTicklePowerState |
2d21ac55 A |
396 | #define fCurrentPowerConsumption pwrMgt->CurrentPowerConsumption |
397 | #define fTempClampPowerState pwrMgt->TempClampPowerState | |
6d2010ae A |
398 | #define fNotifyChildArray pwrMgt->NotifyChildArray |
399 | #define fPowerClients pwrMgt->PowerClients | |
2d21ac55 A |
400 | #define fDriverCallEntry pwrMgt->DriverCallEntry |
401 | #define fDriverCallParamPtr pwrMgt->DriverCallParamPtr | |
402 | #define fDriverCallParamCount pwrMgt->DriverCallParamCount | |
403 | #define fDriverCallParamSlots pwrMgt->DriverCallParamSlots | |
6d2010ae A |
404 | #define fDriverCallReason pwrMgt->DriverCallReason |
405 | #define fOutOfBandMessage pwrMgt->OutOfBandMessage | |
406 | #define fTempClampCount pwrMgt->TempClampCount | |
407 | #define fOverrideMaxPowerState pwrMgt->OverrideMaxPowerState | |
408 | #define fActivityTickleCount pwrMgt->ActivityTickleCount | |
409 | #define fWaitReason pwrMgt->WaitReason | |
410 | #define fSavedMachineState pwrMgt->SavedMachineState | |
411 | #define fRootDomainState pwrMgt->RootDomainState | |
412 | #define fLockedFlags pwrMgt->LockedFlags | |
413 | #define fPMDriverCallQueue pwrMgt->PMDriverCallQueue | |
2d21ac55 A |
414 | #define fInsertInterestSet pwrMgt->InsertInterestSet |
415 | #define fRemoveInterestSet pwrMgt->RemoveInterestSet | |
2d21ac55 | 416 | #define fPMVars pwrMgt->PMVars |
6d2010ae | 417 | #define fPMActions pwrMgt->PMActions |
2d21ac55 | 418 | |
b0d623f7 A |
419 | /* |
420 | When an IOService is waiting for acknowledgement to a power change | |
421 | notification from an interested driver or the controlling driver, | |
422 | the ack timer is ticking every tenth of a second. | |
2d21ac55 A |
423 | (100000000 nanoseconds are one tenth of a second). |
424 | */ | |
b0d623f7 A |
425 | #define ACK_TIMER_PERIOD 100000000 |
426 | ||
6d2010ae A |
427 | // Max wait time in microseconds for kernel priority and capability clients |
428 | // with async message handlers to acknowledge. | |
429 | // | |
430 | #define kPriorityClientMaxWait (90 * 1000 * 1000) | |
431 | #define kCapabilityClientMaxWait (240 * 1000 * 1000) | |
432 | ||
433 | // Attributes describing a power state change. | |
434 | // See IOPMPowerChangeFlags data type. | |
435 | // | |
436 | #define kIOPMParentInitiated 0x0001 // this power change initiated by our parent | |
437 | #define kIOPMSelfInitiated 0x0002 // this power change initiated by this device | |
438 | #define kIOPMNotDone 0x0004 // we couldn't make this change | |
439 | #define kIOPMDomainWillChange 0x0008 // change started by PowerDomainWillChangeTo | |
440 | #define kIOPMDomainDidChange 0x0010 // change started by PowerDomainDidChangeTo | |
441 | #define kIOPMDomainPowerDrop 0x0020 // Domain is lowering power | |
442 | #define kIOPMIgnoreChildren 0x0040 // Ignore children and driver power desires | |
443 | #define kIOPMSkipAskPowerDown 0x0080 // skip the ask app phase | |
444 | #define kIOPMSynchronize 0x0100 // change triggered by power tree re-sync | |
445 | #define kIOPMSyncNoChildNotify 0x0200 // sync root domain only, not entire tree | |
446 | #define kIOPMSyncTellPowerDown 0x0400 // send the ask/will power off messages | |
447 | #define kIOPMSyncCancelPowerDown 0x0800 // sleep cancel for maintenance wake | |
7ee9d059 | 448 | #define kIOPMPowerSuppressed 0x1000 // power suppressed for dark wake |
2d21ac55 A |
449 | |
450 | enum { | |
451 | kDriverCallInformPreChange, | |
452 | kDriverCallInformPostChange, | |
453 | kDriverCallSetPowerState | |
454 | }; | |
455 | ||
456 | struct DriverCallParam { | |
457 | OSObject * Target; | |
458 | IOReturn Result; | |
459 | }; | |
460 | ||
6d2010ae | 461 | // values of OutOfBandParameter |
2d21ac55 A |
462 | enum { |
463 | kNotifyApps, | |
6d2010ae A |
464 | kNotifyPriority, |
465 | kNotifyCapabilityChangeApps, | |
466 | kNotifyCapabilityChangePriority | |
2d21ac55 A |
467 | }; |
468 | ||
6d2010ae A |
469 | typedef bool (*IOPMMessageFilter)( |
470 | void * target, void * object, void * arg1, void * arg2, void * arg3 ); | |
b0d623f7 | 471 | |
2d21ac55 | 472 | // used for applyToInterested |
b0d623f7 | 473 | struct IOPMInterestContext { |
6d2010ae A |
474 | OSArray * responseArray; |
475 | OSArray * notifyClients; | |
476 | uint16_t serialNumber; | |
477 | uint8_t isPreChange; | |
478 | uint8_t enableTracing; | |
479 | uint32_t maxTimeRequested; | |
480 | uint32_t messageType; | |
481 | uint32_t notifyType; | |
482 | IOService * us; | |
483 | IOPMPowerStateIndex stateNumber; | |
484 | IOPMPowerFlags stateFlags; | |
485 | IOPMPowerChangeFlags changeFlags; | |
486 | const char * errorLog; | |
487 | IOPMMessageFilter messageFilter; | |
2d21ac55 A |
488 | }; |
489 | ||
6d2010ae A |
490 | // assertPMDriverCall() options |
491 | enum { | |
492 | kIOPMADC_NoInactiveCheck = 1 | |
493 | }; | |
494 | ||
495 | //****************************************************************************** | |
b0d623f7 | 496 | // PM Statistics & Diagnostics |
6d2010ae | 497 | //****************************************************************************** |
b0d623f7 A |
498 | |
499 | extern const OSSymbol *gIOPMStatsApplicationResponseTimedOut; | |
500 | extern const OSSymbol *gIOPMStatsApplicationResponseCancel; | |
501 | extern const OSSymbol *gIOPMStatsApplicationResponseSlow; | |
502 | ||
6d2010ae A |
503 | //****************************************************************************** |
504 | // IOPMRequest | |
505 | //****************************************************************************** | |
2d21ac55 | 506 | |
b0d623f7 A |
507 | typedef void (*IOPMCompletionAction)(void * target, void * param, IOReturn status); |
508 | ||
2d21ac55 A |
509 | class IOPMRequest : public IOCommand |
510 | { | |
511 | OSDeclareDefaultStructors( IOPMRequest ) | |
512 | ||
513 | protected: | |
b0d623f7 A |
514 | IOService * fTarget; // request target |
515 | IOPMRequest * fRequestNext; // the next request in the chain | |
7e4a7d39 | 516 | IOPMRequest * fRequestRoot; // the root request in the issue tree |
b0d623f7 | 517 | IOItemCount fWorkWaitCount; // execution blocked if non-zero |
7e4a7d39 | 518 | IOItemCount fFreeWaitCount; // completion blocked if non-zero |
b0d623f7 A |
519 | uint32_t fType; // request type |
520 | ||
521 | IOPMCompletionAction fCompletionAction; | |
522 | void * fCompletionTarget; | |
523 | void * fCompletionParam; | |
524 | IOReturn fCompletionStatus; | |
2d21ac55 A |
525 | |
526 | public: | |
b0d623f7 A |
527 | void * fArg0; |
528 | void * fArg1; | |
529 | void * fArg2; | |
2d21ac55 | 530 | |
b0d623f7 | 531 | inline bool isWorkBlocked( void ) const |
2d21ac55 | 532 | { |
b0d623f7 | 533 | return (fWorkWaitCount != 0); |
2d21ac55 A |
534 | } |
535 | ||
b0d623f7 | 536 | inline bool isFreeBlocked( void ) const |
2d21ac55 | 537 | { |
b0d623f7 | 538 | return (fFreeWaitCount != 0); |
2d21ac55 A |
539 | } |
540 | ||
b0d623f7 | 541 | inline IOPMRequest * getNextRequest( void ) const |
2d21ac55 | 542 | { |
b0d623f7 | 543 | return fRequestNext; |
2d21ac55 A |
544 | } |
545 | ||
7e4a7d39 A |
546 | inline IOPMRequest * getRootRequest( void ) const |
547 | { | |
b0d623f7 A |
548 | if (fRequestRoot) return fRequestRoot; |
549 | if (fCompletionAction) return (IOPMRequest *) this; | |
7e4a7d39 A |
550 | return 0; |
551 | } | |
b0d623f7 A |
552 | |
553 | inline uint32_t getType( void ) const | |
2d21ac55 A |
554 | { |
555 | return fType; | |
556 | } | |
557 | ||
b0d623f7 | 558 | inline bool isReplyType( void ) const |
2d21ac55 A |
559 | { |
560 | return (fType > kIOPMRequestTypeReplyStart); | |
561 | } | |
562 | ||
b0d623f7 | 563 | inline IOService * getTarget( void ) const |
2d21ac55 A |
564 | { |
565 | return fTarget; | |
566 | } | |
567 | ||
b0d623f7 A |
568 | inline bool isCompletionInstalled( void ) |
569 | { | |
570 | return (fCompletionAction != 0); | |
571 | } | |
2d21ac55 | 572 | |
b0d623f7 A |
573 | inline void installCompletionAction( |
574 | IOPMCompletionAction action, | |
575 | void * target, | |
576 | void * param ) | |
577 | { | |
578 | fCompletionAction = action; | |
579 | fCompletionTarget = target; | |
580 | fCompletionParam = param; | |
581 | } | |
2d21ac55 | 582 | |
b0d623f7 A |
583 | static IOPMRequest * create( void ); |
584 | bool init( IOService * owner, IOOptionBits type ); | |
585 | void reset( void ); | |
6d2010ae A |
586 | bool attachNextRequest( IOPMRequest * next ); |
587 | bool detachNextRequest( void ); | |
588 | bool attachRootRequest( IOPMRequest * root ); | |
589 | bool detachRootRequest( void ); | |
2d21ac55 A |
590 | }; |
591 | ||
6d2010ae A |
592 | //****************************************************************************** |
593 | // IOPMRequestQueue | |
594 | //****************************************************************************** | |
595 | ||
2d21ac55 A |
596 | class IOPMRequestQueue : public IOEventSource |
597 | { | |
598 | OSDeclareDefaultStructors( IOPMRequestQueue ) | |
599 | ||
600 | public: | |
601 | typedef bool (*Action)( IOService *, IOPMRequest *, IOPMRequestQueue * ); | |
602 | ||
603 | protected: | |
604 | queue_head_t fQueue; | |
605 | IOLock * fLock; | |
606 | ||
607 | virtual bool checkForWork( void ); | |
608 | virtual void free( void ); | |
609 | virtual bool init( IOService * inOwner, Action inAction ); | |
610 | ||
611 | public: | |
612 | static IOPMRequestQueue * create( IOService * inOwner, Action inAction ); | |
613 | void queuePMRequest( IOPMRequest * request ); | |
614 | void queuePMRequestChain( IOPMRequest ** requests, IOItemCount count ); | |
2d21ac55 A |
615 | }; |
616 | ||
6d2010ae A |
617 | //****************************************************************************** |
618 | // IOPMWorkQueue | |
619 | //****************************************************************************** | |
620 | ||
621 | #define WORK_QUEUE_STATS 1 | |
622 | ||
2d21ac55 A |
623 | class IOPMWorkQueue : public IOEventSource |
624 | { | |
625 | OSDeclareDefaultStructors( IOPMWorkQueue ) | |
626 | ||
627 | public: | |
628 | typedef bool (*Action)( IOService *, IOPMRequest *, IOPMWorkQueue * ); | |
629 | ||
6d2010ae A |
630 | #if WORK_QUEUE_STATS |
631 | uint64_t fStatCheckForWork; | |
632 | uint64_t fStatScanEntries; | |
633 | uint64_t fStatQueueEmpty; | |
634 | uint64_t fStatNoWorkDone; | |
635 | #endif | |
636 | ||
2d21ac55 | 637 | protected: |
6d2010ae A |
638 | queue_head_t fWorkQueue; |
639 | Action fWorkAction; | |
640 | Action fRetireAction; | |
641 | uint32_t fQueueLength; | |
642 | uint32_t fConsumerCount; | |
643 | volatile uint32_t fProducerCount; | |
2d21ac55 A |
644 | |
645 | virtual bool checkForWork( void ); | |
646 | virtual bool init( IOService * inOwner, Action work, Action retire ); | |
6d2010ae | 647 | bool checkRequestQueue( queue_head_t * queue, bool * empty ); |
2d21ac55 A |
648 | |
649 | public: | |
b0d623f7 | 650 | static IOPMWorkQueue * create( IOService * inOwner, Action work, Action retire ); |
6d2010ae A |
651 | bool queuePMRequest( IOPMRequest * request, IOServicePM * pwrMgt ); |
652 | void signalWorkAvailable( void ); | |
653 | void incrementProducerCount( void ); | |
b0d623f7 A |
654 | }; |
655 | ||
6d2010ae A |
656 | //****************************************************************************** |
657 | // IOPMCompletionQueue | |
658 | //****************************************************************************** | |
659 | ||
b0d623f7 A |
660 | class IOPMCompletionQueue : public IOEventSource |
661 | { | |
662 | OSDeclareDefaultStructors( IOPMCompletionQueue ) | |
663 | ||
664 | public: | |
665 | typedef bool (*Action)( IOService *, IOPMRequest *, IOPMCompletionQueue * ); | |
666 | ||
667 | protected: | |
668 | queue_head_t fQueue; | |
669 | ||
670 | virtual bool checkForWork( void ); | |
671 | virtual bool init( IOService * inOwner, Action inAction ); | |
672 | ||
673 | public: | |
674 | static IOPMCompletionQueue * create( IOService * inOwner, Action inAction ); | |
6d2010ae | 675 | bool queuePMRequest( IOPMRequest * request ); |
2d21ac55 A |
676 | }; |
677 | ||
678 | #endif /* !_IOKIT_IOSERVICEPMPRIVATE_H */ |