]> git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOServicePMPrivate.h
xnu-4903.270.47.tar.gz
[apple/xnu.git] / iokit / Kernel / IOServicePMPrivate.h
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
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,
57 kIOPMRequestTypeIgnoreIdleTimer = 0x10,
58 kIOPMRequestTypeQuiescePowerTree = 0x11,
59
60 /* Reply Types */
61 kIOPMRequestTypeReplyStart = 0x80,
62 kIOPMRequestTypeAckPowerChange = 0x81,
63 kIOPMRequestTypeAckSetPowerState = 0x82,
64 kIOPMRequestTypeAllowPowerChange = 0x83,
65 kIOPMRequestTypeCancelPowerChange = 0x84,
66 kIOPMRequestTypeInterestChanged = 0x85,
67 kIOPMRequestTypeIdleCancel = 0x86,
68 kIOPMRequestTypeChildNotifyDelayCancel = 0x87
69 };
70
71 //******************************************************************************
72 // PM actions - For root domain only
73 //******************************************************************************
74
75 struct IOPMActions;
76
77 typedef void
78 (*IOPMActionPowerChangeStart)(
79 void * target,
80 IOService * service,
81 IOPMActions * actions,
82 IOPMPowerStateIndex powerState,
83 IOPMPowerChangeFlags * changeFlags,
84 IOPMRequestTag requestTag );
85
86 typedef void
87 (*IOPMActionPowerChangeDone)(
88 void * target,
89 IOService * service,
90 IOPMActions * actions,
91 IOPMPowerStateIndex powerState,
92 IOPMPowerChangeFlags changeFlags,
93 IOPMRequestTag requestTag );
94
95 typedef void
96 (*IOPMActionPowerChangeOverride)(
97 void * target,
98 IOService * service,
99 IOPMActions * actions,
100 IOPMPowerStateIndex * powerState,
101 IOPMPowerChangeFlags * changeFlags,
102 IOPMRequestTag requestTag );
103
104 typedef void
105 (*IOPMActionActivityTickle)(
106 void * target,
107 IOService * service,
108 IOPMActions * actions );
109
110 typedef void
111 (*IOPMActionUpdatePowerClient)(
112 void * target,
113 IOService * service,
114 IOPMActions * actions,
115 const OSSymbol * powerClient,
116 IOPMPowerStateIndex oldPowerState,
117 IOPMPowerStateIndex newPowerState
118 );
119
120 struct IOPMActions {
121 void * target;
122 uint32_t parameter;
123 IOPMActionPowerChangeStart actionPowerChangeStart;
124 IOPMActionPowerChangeDone actionPowerChangeDone;
125 IOPMActionPowerChangeOverride actionPowerChangeOverride;
126 IOPMActionActivityTickle actionActivityTickle;
127 IOPMActionUpdatePowerClient actionUpdatePowerClient;
128 };
129
130 // IOPMActions parameter flags
131 enum {
132 kPMActionsFlagIsDisplayWrangler = 0x00000100,
133 kPMActionsFlagIsGraphicsDevice = 0x00000200,
134 kPMActionsFlagIsAudioDevice = 0x00000400,
135 kPMActionsFlagLimitPower = 0x00000800,
136 kPMActionsPCIBitNumberMask = 0x000000ff
137 };
138
139 //******************************************************************************
140 // Internal concise representation of IOPMPowerState
141 struct IOPMPSEntry {
142 IOPMPowerFlags capabilityFlags;
143 IOPMPowerFlags outputPowerFlags;
144 IOPMPowerFlags inputPowerFlags;
145 uint32_t staticPower;
146 uint32_t settleUpTime;
147 uint32_t settleDownTime;
148 IOPMPowerStateIndex stateOrder;
149 IOPMPowerStateIndex stateOrderToIndex;
150 };
151
152 //******************************************************************************
153 // IOServicePM
154 //******************************************************************************
155
156 class IOServicePM : public OSObject
157 {
158 friend class IOService;
159 friend class IOPMWorkQueue;
160
161 OSDeclareDefaultStructors( IOServicePM )
162
163 private:
164 // Link IOServicePM objects on IOPMWorkQueue.
165 queue_chain_t WorkChain;
166
167 // Queue of IOPMRequest objects.
168 queue_head_t RequestHead;
169
170 // IOService creator and owner.
171 IOService * Owner;
172
173 // List of interested drivers (protected by PMLock).
174 IOPMinformeeList * InterestedDrivers;
175
176 // How long to wait for controlling driver to acknowledge.
177 IOReturn DriverTimer;
178
179 // Current power management machine state.
180 uint32_t MachineState;
181
182 thread_call_t AckTimer;
183 thread_call_t SettleTimer;
184 thread_call_t IdleTimer;
185 thread_call_t WatchdogTimer;
186 thread_call_t SpinDumpTimer;
187
188 IOLock * WatchdogLock;
189 OSArray * BlockedArray;
190 uint64_t PendingResponseDeadline;
191 uint64_t WatchdogDeadline;
192
193 // Settle time after changing power state.
194 uint32_t SettleTimeUS;
195 uint32_t IdleTimerGeneration;
196
197 // The flags describing current change note.
198 IOPMPowerChangeFlags HeadNoteChangeFlags;
199
200 // The new power state number being changed to.
201 IOPMPowerStateIndex HeadNotePowerState;
202
203 // Points to the entry in the power state array.
204 IOPMPSEntry * HeadNotePowerArrayEntry;
205
206 // Power flags supplied by all parents (domain).
207 IOPMPowerFlags HeadNoteDomainFlags;
208
209 // Power flags supplied by domain accounting for parent changes.
210 IOPMPowerFlags HeadNoteDomainTargetFlags;
211
212 // Connection attached to the changing parent.
213 IOPowerConnection * HeadNoteParentConnection;
214
215 // Power flags supplied by the changing parent.
216 IOPMPowerFlags HeadNoteParentFlags;
217
218 // Number of acks still outstanding.
219 uint32_t HeadNotePendingAcks;
220
221 // PM state lock.
222 IOLock * PMLock;
223
224 unsigned int InitialPowerChange :1;
225 unsigned int InitialSetPowerState :1;
226 unsigned int DeviceOverrideEnabled :1;
227 unsigned int DoNotPowerDown :1;
228 unsigned int ParentsKnowState :1;
229 unsigned int StrictTreeOrder :1;
230 unsigned int IdleTimerStopped :1;
231 unsigned int AdjustPowerScheduled :1;
232
233 unsigned int IsPreChange :1;
234 unsigned int DriverCallBusy :1;
235 unsigned int PCDFunctionOverride :1;
236 unsigned int IdleTimerIgnored :1;
237 unsigned int HasAdvisoryDesire :1;
238 unsigned int AdvisoryTickleUsed :1;
239 unsigned int ResetPowerStateOnWake :1;
240
241 // Time of last device activity.
242 AbsoluteTime DeviceActiveTimestamp;
243 AbsoluteTime MaxPowerStateEntryTime;
244 AbsoluteTime MaxPowerStateExitTime;
245
246 // Used to protect activity flag.
247 IOLock * ActivityLock;
248
249 // Idle timer's period in seconds.
250 unsigned long IdleTimerPeriod;
251 unsigned long IdleTimerMinPowerState;
252 unsigned long NextIdleTimerPeriod;
253 AbsoluteTime IdleTimerStartTime;
254
255 // Power state desired by a subclassed device object.
256 IOPMPowerStateIndex DeviceDesire;
257
258 // This is the power state we desire currently.
259 IOPMPowerStateIndex DesiredPowerState;
260
261 // This is what our parent thinks our need is.
262 IOPMPowerFlags PreviousRequestPowerFlags;
263
264 // Cache result from getName(), used in logging.
265 const char * Name;
266
267 // Number of power states in the power array.
268 IOPMPowerStateIndex NumberOfPowerStates;
269
270 // Ordered highest power state in the power array.
271 IOPMPowerStateIndex HighestPowerState;
272
273 // Power state array.
274 IOPMPSEntry * PowerStates;
275
276 // The controlling driver.
277 IOService * ControllingDriver;
278
279 // Our current power state.
280 IOPMPowerStateIndex CurrentPowerState;
281
282 // Logical OR of power flags for each power domain parent.
283 IOPMPowerFlags ParentsCurrentPowerFlags;
284
285 // The highest power state we can achieve in current power domain.
286 IOPMPowerStateIndex MaxPowerState;
287
288 // Logical OR of all output power flags in the power state array.
289 IOPMPowerFlags MergedOutputPowerFlags;
290
291 // OSArray which manages responses from notified apps and clients.
292 OSArray * ResponseArray;
293 OSArray * NotifyClientArray;
294
295 // Used to uniquely identify power management notification to apps and clients.
296 UInt16 SerialNumber;
297
298 // Used to communicate desired function to tellClientsWithResponse().
299 // This is used because it avoids changing the signatures of the affected virtual methods.
300 int OutOfBandParameter;
301
302 AbsoluteTime DriverCallStartTime;
303 IOPMPowerFlags CurrentCapabilityFlags;
304 unsigned long CurrentPowerConsumption;
305 IOPMPowerStateIndex TempClampPowerState;
306 OSArray * NotifyChildArray;
307 OSDictionary * PowerClients;
308 thread_call_t DriverCallEntry;
309 void * DriverCallParamPtr;
310 IOItemCount DriverCallParamCount;
311 IOItemCount DriverCallParamSlots;
312 uint32_t DriverCallReason;
313 uint32_t OutOfBandMessage;
314 uint32_t TempClampCount;
315 uint32_t OverrideMaxPowerState;
316 uint32_t DeviceUsablePowerState;
317
318 // Protected by ActivityLock - BEGIN
319 IOPMPowerStateIndex ActivityTicklePowerState;
320 IOPMPowerStateIndex AdvisoryTicklePowerState;
321 uint32_t ActivityTickleCount;
322 uint32_t DeviceWasActive : 1;
323 uint32_t AdvisoryTickled : 1;
324 // Protected by ActivityLock - END
325
326 uint32_t WaitReason;
327 uint32_t SavedMachineState;
328
329 // Protected by PMLock - BEGIN
330 struct {
331 uint32_t PMStop : 1;
332 uint32_t PMDriverCallWait : 1;
333 } LockedFlags;
334
335 queue_head_t PMDriverCallQueue;
336 OSSet * InsertInterestSet;
337 OSSet * RemoveInterestSet;
338
339 // IOReporter Data
340 uint32_t ReportClientCnt;
341 void * ReportBuf;
342 // Protected by PMLock - END
343
344 #if PM_VARS_SUPPORT
345 IOPMprot * PMVars;
346 #endif
347
348 IOPMActions PMActions;
349
350 // Serialize IOServicePM state for debug output.
351 IOReturn gatedSerialize( OSSerialize * s ) const;
352 virtual bool serialize( OSSerialize * s ) const APPLE_KEXT_OVERRIDE;
353
354 // PM log and trace
355 void pmPrint( uint32_t event, uintptr_t param1, uintptr_t param2 ) const;
356 void pmTrace( uint32_t event, uint32_t eventFunc, uintptr_t param1, uintptr_t param2 ) const;
357 };
358
359 #define fOwner pwrMgt->Owner
360 #define fInterestedDrivers pwrMgt->InterestedDrivers
361 #define fDriverTimer pwrMgt->DriverTimer
362 #define fMachineState pwrMgt->MachineState
363 #define fAckTimer pwrMgt->AckTimer
364 #define fSettleTimer pwrMgt->SettleTimer
365 #define fIdleTimer pwrMgt->IdleTimer
366 #define fWatchdogTimer pwrMgt->WatchdogTimer
367 #define fWatchdogDeadline pwrMgt->WatchdogDeadline
368 #define fWatchdogLock pwrMgt->WatchdogLock
369 #define fBlockedArray pwrMgt->BlockedArray
370 #define fPendingResponseDeadline pwrMgt->PendingResponseDeadline
371 #define fSpinDumpTimer pwrMgt->SpinDumpTimer
372 #define fSettleTimeUS pwrMgt->SettleTimeUS
373 #define fIdleTimerGeneration pwrMgt->IdleTimerGeneration
374 #define fHeadNoteChangeFlags pwrMgt->HeadNoteChangeFlags
375 #define fHeadNotePowerState pwrMgt->HeadNotePowerState
376 #define fHeadNotePowerArrayEntry pwrMgt->HeadNotePowerArrayEntry
377 #define fHeadNoteDomainFlags pwrMgt->HeadNoteDomainFlags
378 #define fHeadNoteDomainTargetFlags pwrMgt->HeadNoteDomainTargetFlags
379 #define fHeadNoteParentConnection pwrMgt->HeadNoteParentConnection
380 #define fHeadNoteParentFlags pwrMgt->HeadNoteParentFlags
381 #define fHeadNotePendingAcks pwrMgt->HeadNotePendingAcks
382 #define fPMLock pwrMgt->PMLock
383 #define fInitialPowerChange pwrMgt->InitialPowerChange
384 #define fInitialSetPowerState pwrMgt->InitialSetPowerState
385 #define fDeviceOverrideEnabled pwrMgt->DeviceOverrideEnabled
386 #define fDoNotPowerDown pwrMgt->DoNotPowerDown
387 #define fParentsKnowState pwrMgt->ParentsKnowState
388 #define fStrictTreeOrder pwrMgt->StrictTreeOrder
389 #define fIdleTimerStopped pwrMgt->IdleTimerStopped
390 #define fAdjustPowerScheduled pwrMgt->AdjustPowerScheduled
391 #define fIsPreChange pwrMgt->IsPreChange
392 #define fDriverCallBusy pwrMgt->DriverCallBusy
393 #define fPCDFunctionOverride pwrMgt->PCDFunctionOverride
394 #define fIdleTimerIgnored pwrMgt->IdleTimerIgnored
395 #define fHasAdvisoryDesire pwrMgt->HasAdvisoryDesire
396 #define fAdvisoryTickleUsed pwrMgt->AdvisoryTickleUsed
397 #define fResetPowerStateOnWake pwrMgt->ResetPowerStateOnWake
398 #define fDeviceActiveTimestamp pwrMgt->DeviceActiveTimestamp
399 #define fMaxPowerStateEntryTime pwrMgt->MaxPowerStateEntryTime
400 #define fMaxPowerStateExitTime pwrMgt->MaxPowerStateExitTime
401 #define fActivityLock pwrMgt->ActivityLock
402 #define fIdleTimerPeriod pwrMgt->IdleTimerPeriod
403 #define fIdleTimerMinPowerState pwrMgt->IdleTimerMinPowerState
404 #define fNextIdleTimerPeriod pwrMgt->NextIdleTimerPeriod
405 #define fIdleTimerStartTime pwrMgt->IdleTimerStartTime
406 #define fDeviceDesire pwrMgt->DeviceDesire
407 #define fDesiredPowerState pwrMgt->DesiredPowerState
408 #define fPreviousRequestPowerFlags pwrMgt->PreviousRequestPowerFlags
409 #define fName pwrMgt->Name
410 #define fNumberOfPowerStates pwrMgt->NumberOfPowerStates
411 #define fHighestPowerState pwrMgt->HighestPowerState
412 #define fPowerStates pwrMgt->PowerStates
413 #define fControllingDriver pwrMgt->ControllingDriver
414 #define fCurrentPowerState pwrMgt->CurrentPowerState
415 #define fParentsCurrentPowerFlags pwrMgt->ParentsCurrentPowerFlags
416 #define fMaxPowerState pwrMgt->MaxPowerState
417 #define fMergedOutputPowerFlags pwrMgt->MergedOutputPowerFlags
418 #define fResponseArray pwrMgt->ResponseArray
419 #define fNotifyClientArray pwrMgt->NotifyClientArray
420 #define fSerialNumber pwrMgt->SerialNumber
421 #define fOutOfBandParameter pwrMgt->OutOfBandParameter
422 #define fDriverCallStartTime pwrMgt->DriverCallStartTime
423 #define fCurrentCapabilityFlags pwrMgt->CurrentCapabilityFlags
424 #define fCurrentPowerConsumption pwrMgt->CurrentPowerConsumption
425 #define fTempClampPowerState pwrMgt->TempClampPowerState
426 #define fNotifyChildArray pwrMgt->NotifyChildArray
427 #define fPowerClients pwrMgt->PowerClients
428 #define fDriverCallEntry pwrMgt->DriverCallEntry
429 #define fDriverCallParamPtr pwrMgt->DriverCallParamPtr
430 #define fDriverCallParamCount pwrMgt->DriverCallParamCount
431 #define fDriverCallParamSlots pwrMgt->DriverCallParamSlots
432 #define fDriverCallReason pwrMgt->DriverCallReason
433 #define fOutOfBandMessage pwrMgt->OutOfBandMessage
434 #define fTempClampCount pwrMgt->TempClampCount
435 #define fOverrideMaxPowerState pwrMgt->OverrideMaxPowerState
436 #define fDeviceUsablePowerState pwrMgt->DeviceUsablePowerState
437 #define fActivityTicklePowerState pwrMgt->ActivityTicklePowerState
438 #define fAdvisoryTicklePowerState pwrMgt->AdvisoryTicklePowerState
439 #define fActivityTickleCount pwrMgt->ActivityTickleCount
440 #define fDeviceWasActive pwrMgt->DeviceWasActive
441 #define fAdvisoryTickled pwrMgt->AdvisoryTickled
442 #define fWaitReason pwrMgt->WaitReason
443 #define fSavedMachineState pwrMgt->SavedMachineState
444 #define fLockedFlags pwrMgt->LockedFlags
445 #define fPMDriverCallQueue pwrMgt->PMDriverCallQueue
446 #define fInsertInterestSet pwrMgt->InsertInterestSet
447 #define fRemoveInterestSet pwrMgt->RemoveInterestSet
448 #define fReportClientCnt pwrMgt->ReportClientCnt
449 #define fReportBuf pwrMgt->ReportBuf
450 #define fPMVars pwrMgt->PMVars
451 #define fPMActions pwrMgt->PMActions
452
453 #define StateOrder(state) (((state) < fNumberOfPowerStates) \
454 ? pwrMgt->PowerStates[(state)].stateOrder \
455 : (state))
456 #define StateMax(a, b) (StateOrder((a)) < StateOrder((b)) ? (b) : (a))
457 #define StateMin(a, b) (StateOrder((a)) < StateOrder((b)) ? (a) : (b))
458
459 #define kPowerStateZero (0)
460
461 /*
462 * When an IOService is waiting for acknowledgement to a power change
463 * notification from an interested driver or the controlling driver,
464 * the ack timer is ticking every tenth of a second.
465 * (100000000 nanoseconds are one tenth of a second).
466 */
467 #define ACK_TIMER_PERIOD 100000000
468
469 #if defined(__i386__) || defined(__x86_64__)
470 #define WATCHDOG_SLEEP_TIMEOUT (180) // 180 secs
471 #define WATCHDOG_WAKE_TIMEOUT (180) // 180 secs
472 #else
473 #define WATCHDOG_SLEEP_TIMEOUT (180) // 180 secs
474 #define WATCHDOG_WAKE_TIMEOUT (180) // 180 secs
475 #endif
476
477 // Max wait time in microseconds for kernel priority and capability clients
478 // with async message handlers to acknowledge.
479 //
480 #define kPriorityClientMaxWait (90 * 1000 * 1000)
481 #define kCapabilityClientMaxWait (240 * 1000 * 1000)
482
483 // Attributes describing a power state change.
484 // See IOPMPowerChangeFlags data type.
485 //
486 #define kIOPMParentInitiated 0x0001 // power change initiated by our parent
487 #define kIOPMSelfInitiated 0x0002 // power change initiated by this device
488 #define kIOPMNotDone 0x0004 // we couldn't make this change
489 #define kIOPMDomainWillChange 0x0008 // change started by PowerDomainWillChangeTo
490 #define kIOPMDomainDidChange 0x0010 // change started by PowerDomainDidChangeTo
491 #define kIOPMDomainPowerDrop 0x0020 // Domain is lowering power
492 #define kIOPMIgnoreChildren 0x0040 // Ignore children and driver power desires
493 #define kIOPMSkipAskPowerDown 0x0080 // skip the ask app phase
494 #define kIOPMSynchronize 0x0100 // change triggered by power tree re-sync
495 #define kIOPMSyncNoChildNotify 0x0200 // sync root domain only, not entire tree
496 #define kIOPMSyncTellPowerDown 0x0400 // send the ask/will power off messages
497 #define kIOPMSyncCancelPowerDown 0x0800 // sleep cancel for maintenance wake
498 #define kIOPMInitialPowerChange 0x1000 // set for initial power change
499 #define kIOPMRootChangeUp 0x2000 // Root power domain change up
500 #define kIOPMRootChangeDown 0x4000 // Root power domain change down
501 #define kIOPMExpireIdleTimer 0x8000 // Accelerate idle timer expiration
502
503 #define kIOPMRootBroadcastFlags (kIOPMSynchronize | \
504 kIOPMRootChangeUp | kIOPMRootChangeDown)
505
506 // Activity tickle request flags
507 #define kTickleTypePowerDrop 0x01
508 #define kTickleTypePowerRise 0x02
509 #define kTickleTypeActivity 0x04
510 #define kTickleTypeAdvisory 0x08
511
512 enum {
513 kDriverCallInformPreChange,
514 kDriverCallInformPostChange,
515 kDriverCallSetPowerState,
516 kRootDomainInformPreChange
517 };
518
519 struct DriverCallParam {
520 OSObject * Target;
521 IOReturn Result;
522 };
523
524 // values of OutOfBandParameter
525 enum {
526 kNotifyApps,
527 kNotifyPriority,
528 kNotifyCapabilityChangeApps,
529 kNotifyCapabilityChangePriority
530 };
531
532 typedef bool (*IOPMMessageFilter)(
533 void * target, void * object, void * arg1, void * arg2, void * arg3 );
534
535 // used for applyToInterested
536 struct IOPMInterestContext {
537 OSArray * responseArray;
538 OSArray * notifyClients;
539 uint16_t serialNumber;
540 uint8_t isPreChange;
541 uint8_t enableTracing;
542 uint32_t maxTimeRequested;
543 uint32_t messageType;
544 uint32_t notifyType;
545 IOService * us;
546 IOPMPowerStateIndex stateNumber;
547 IOPMPowerFlags stateFlags;
548 IOPMPowerChangeFlags changeFlags;
549 const char * errorLog;
550 IOPMMessageFilter messageFilter;
551 };
552
553 // assertPMDriverCall() options
554 enum {
555 kIOPMADC_NoInactiveCheck = 1
556 };
557
558 //******************************************************************************
559 // PM Statistics & Diagnostics
560 //******************************************************************************
561
562 extern const OSSymbol *gIOPMStatsResponseTimedOut;
563 extern const OSSymbol *gIOPMStatsResponseCancel;
564 extern const OSSymbol *gIOPMStatsResponseSlow;
565 extern const OSSymbol *gIOPMStatsResponsePrompt;
566 extern const OSSymbol *gIOPMStatsDriverPSChangeSlow;
567
568 //******************************************************************************
569 // IOPMRequest
570 //******************************************************************************
571
572 class IOPMRequest : public IOCommand
573 {
574 OSDeclareDefaultStructors( IOPMRequest )
575
576 protected:
577 IOService * fTarget; // request target
578 IOPMRequest * fRequestNext; // the next request in the chain
579 IOPMRequest * fRequestRoot; // the root request in the call tree
580 IOItemCount fWorkWaitCount;// execution blocked if non-zero
581 IOItemCount fFreeWaitCount;// completion blocked if non-zero
582 uint32_t fRequestType; // request type
583 bool fIsQuiesceBlocker;
584
585 IOPMCompletionAction fCompletionAction;
586 void * fCompletionTarget;
587 void * fCompletionParam;
588
589 public:
590 uint32_t fRequestTag;
591 void * fArg0;
592 void * fArg1;
593 void * fArg2;
594
595 inline bool
596 isWorkBlocked( void ) const
597 {
598 return fWorkWaitCount != 0;
599 }
600
601 inline bool
602 isFreeBlocked( void ) const
603 {
604 return fFreeWaitCount != 0;
605 }
606
607 inline IOPMRequest *
608 getNextRequest( void ) const
609 {
610 return fRequestNext;
611 }
612
613 inline IOPMRequest *
614 getRootRequest( void ) const
615 {
616 if (fRequestRoot) {
617 return fRequestRoot;
618 }
619 #if NOT_READY
620 if (fCompletionAction) {
621 return (IOPMRequest *) this;
622 }
623 #endif
624 return 0;
625 }
626
627 inline uint32_t
628 getType( void ) const
629 {
630 return fRequestType;
631 }
632
633 inline bool
634 isReplyType( void ) const
635 {
636 return fRequestType > kIOPMRequestTypeReplyStart;
637 }
638
639 inline IOService *
640 getTarget( void ) const
641 {
642 return fTarget;
643 }
644
645 inline bool
646 isQuiesceBlocker( void ) const
647 {
648 return fIsQuiesceBlocker;
649 }
650
651 inline bool
652 isQuiesceType( void ) const
653 {
654 return (kIOPMRequestTypeQuiescePowerTree == fRequestType) &&
655 (fCompletionAction != 0) && (fCompletionTarget != 0);
656 }
657
658 inline void
659 installCompletionAction(
660 void * target,
661 IOPMCompletionAction action,
662 void * param )
663 {
664 fCompletionTarget = target;
665 fCompletionAction = action;
666 fCompletionParam = param;
667 }
668
669 static IOPMRequest * create( void );
670 bool init( IOService * owner, IOOptionBits type );
671 void reset( void );
672 bool attachNextRequest( IOPMRequest * next );
673 bool detachNextRequest( void );
674 bool attachRootRequest( IOPMRequest * root );
675 bool detachRootRequest( void );
676 };
677
678 //******************************************************************************
679 // IOPMRequestQueue
680 //******************************************************************************
681
682 class IOPMRequestQueue : public IOEventSource
683 {
684 OSDeclareDefaultStructors( IOPMRequestQueue )
685
686 public:
687 typedef bool (*Action)( IOService *, IOPMRequest *, IOPMRequestQueue * );
688
689 protected:
690 queue_head_t fQueue;
691 IOLock * fLock;
692
693 enum { kMaxDequeueCount = 256 };
694
695 virtual bool checkForWork( void ) APPLE_KEXT_OVERRIDE;
696 virtual void free( void ) APPLE_KEXT_OVERRIDE;
697 virtual bool init( IOService * inOwner, Action inAction );
698
699 public:
700 static IOPMRequestQueue * create( IOService * inOwner, Action inAction );
701 void queuePMRequest( IOPMRequest * request );
702 void queuePMRequestChain( IOPMRequest ** requests, IOItemCount count );
703 };
704
705 //******************************************************************************
706 // IOPMWorkQueue
707 //******************************************************************************
708
709 #define WORK_QUEUE_STATS 1
710
711 class IOPMWorkQueue : public IOEventSource
712 {
713 OSDeclareDefaultStructors( IOPMWorkQueue )
714
715 public:
716 typedef bool (*Action)( IOService *, IOPMRequest *, IOPMWorkQueue * );
717
718 #if WORK_QUEUE_STATS
719 uint64_t fStatCheckForWork;
720 uint64_t fStatScanEntries;
721 uint64_t fStatQueueEmpty;
722 uint64_t fStatNoWorkDone;
723 #endif
724
725 protected:
726 queue_head_t fWorkQueue;
727 Action fInvokeAction;
728 Action fRetireAction;
729 uint32_t fQueueLength;
730 uint32_t fConsumerCount;
731 volatile uint32_t fProducerCount;
732 IOPMRequest * fQuiesceRequest;
733 AbsoluteTime fQuiesceStartTime;
734 AbsoluteTime fQuiesceFinishTime;
735
736 virtual bool checkForWork( void ) APPLE_KEXT_OVERRIDE;
737 virtual bool init( IOService * inOwner, Action invoke, Action retire );
738 bool checkRequestQueue( queue_head_t * queue, bool * empty );
739
740 public:
741 static IOPMWorkQueue * create( IOService * inOwner, Action invoke, Action retire );
742 bool queuePMRequest( IOPMRequest * request, IOServicePM * pwrMgt );
743 void signalWorkAvailable( void );
744 void incrementProducerCount( void );
745 void attachQuiesceRequest( IOPMRequest * quiesceRequest );
746 void finishQuiesceRequest( IOPMRequest * quiesceRequest );
747 };
748
749 //******************************************************************************
750 // IOPMCompletionQueue
751 //******************************************************************************
752
753 class IOPMCompletionQueue : public IOEventSource
754 {
755 OSDeclareDefaultStructors( IOPMCompletionQueue )
756
757 public:
758 typedef bool (*Action)( IOService *, IOPMRequest *, IOPMCompletionQueue * );
759
760 protected:
761 queue_head_t fQueue;
762
763 virtual bool checkForWork( void ) APPLE_KEXT_OVERRIDE;
764 virtual bool init( IOService * inOwner, Action inAction );
765
766 public:
767 static IOPMCompletionQueue * create( IOService * inOwner, Action inAction );
768 bool queuePMRequest( IOPMRequest * request );
769 };
770
771 #endif /* !_IOKIT_IOSERVICEPMPRIVATE_H */