2 * Copyright (c) 2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _IOKIT_IOSERVICEPMPRIVATE_H
30 #define _IOKIT_IOSERVICEPMPRIVATE_H
32 #include <IOKit/IOCommand.h>
33 #include <IOKit/IOEventSource.h>
35 //******************************************************************************
37 //******************************************************************************
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,
61 kIOPMRequestTypeReplyStart
= 0x80,
62 kIOPMRequestTypeAckPowerChange
= 0x81,
63 kIOPMRequestTypeAckSetPowerState
= 0x82,
64 kIOPMRequestTypeAllowPowerChange
= 0x83,
65 kIOPMRequestTypeCancelPowerChange
= 0x84,
66 kIOPMRequestTypeInterestChanged
= 0x85,
67 kIOPMRequestTypeIdleCancel
= 0x86,
68 kIOPMRequestTypeChildNotifyDelayCancel
= 0x87
71 //******************************************************************************
72 // PM actions - For root domain only
73 //******************************************************************************
78 (*IOPMActionPowerChangeStart
)(
81 IOPMActions
* actions
,
82 IOPMPowerStateIndex powerState
,
83 IOPMPowerChangeFlags
* changeFlags
,
84 IOPMRequestTag requestTag
);
87 (*IOPMActionPowerChangeDone
)(
90 IOPMActions
* actions
,
91 IOPMPowerStateIndex powerState
,
92 IOPMPowerChangeFlags changeFlags
,
93 IOPMRequestTag requestTag
);
96 (*IOPMActionPowerChangeOverride
)(
99 IOPMActions
* actions
,
100 IOPMPowerStateIndex
* powerState
,
101 IOPMPowerChangeFlags
* changeFlags
,
102 IOPMRequestTag requestTag
);
105 (*IOPMActionActivityTickle
)(
108 IOPMActions
* actions
);
111 (*IOPMActionUpdatePowerClient
)(
114 IOPMActions
* actions
,
115 const OSSymbol
* powerClient
,
116 IOPMPowerStateIndex oldPowerState
,
117 IOPMPowerStateIndex newPowerState
123 IOPMActionPowerChangeStart actionPowerChangeStart
;
124 IOPMActionPowerChangeDone actionPowerChangeDone
;
125 IOPMActionPowerChangeOverride actionPowerChangeOverride
;
126 IOPMActionActivityTickle actionActivityTickle
;
127 IOPMActionUpdatePowerClient actionUpdatePowerClient
;
130 // IOPMActions parameter flags
132 kPMActionsFlagIsDisplayWrangler
= 0x00000100,
133 kPMActionsFlagIsGraphicsDevice
= 0x00000200,
134 kPMActionsFlagIsAudioDevice
= 0x00000400,
135 kPMActionsFlagLimitPower
= 0x00000800,
136 kPMActionsPCIBitNumberMask
= 0x000000ff
139 //******************************************************************************
140 // Internal concise representation of IOPMPowerState
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
;
152 //******************************************************************************
154 //******************************************************************************
156 class IOServicePM
: public OSObject
158 friend class IOService
;
159 friend class IOPMWorkQueue
;
161 OSDeclareDefaultStructors( IOServicePM
)
164 // Link IOServicePM objects on IOPMWorkQueue.
165 queue_chain_t WorkChain
;
167 // Queue of IOPMRequest objects.
168 queue_head_t RequestHead
;
170 // IOService creator and owner.
173 // List of interested drivers (protected by PMLock).
174 IOPMinformeeList
* InterestedDrivers
;
176 // How long to wait for controlling driver to acknowledge.
177 IOReturn DriverTimer
;
179 // Current power management machine state.
180 uint32_t MachineState
;
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
;
188 IOLock
* WatchdogLock
;
189 OSArray
* BlockedArray
;
190 uint64_t PendingResponseDeadline
;
191 uint64_t WatchdogDeadline
;
193 // Settle time after changing power state.
194 uint32_t SettleTimeUS
;
195 uint32_t IdleTimerGeneration
;
197 // The flags describing current change note.
198 IOPMPowerChangeFlags HeadNoteChangeFlags
;
200 // The new power state number being changed to.
201 IOPMPowerStateIndex HeadNotePowerState
;
203 // Points to the entry in the power state array.
204 IOPMPSEntry
* HeadNotePowerArrayEntry
;
206 // Power flags supplied by all parents (domain).
207 IOPMPowerFlags HeadNoteDomainFlags
;
209 // Power flags supplied by domain accounting for parent changes.
210 IOPMPowerFlags HeadNoteDomainTargetFlags
;
212 // Connection attached to the changing parent.
213 IOPowerConnection
* HeadNoteParentConnection
;
215 // Power flags supplied by the changing parent.
216 IOPMPowerFlags HeadNoteParentFlags
;
218 // Number of acks still outstanding.
219 uint32_t HeadNotePendingAcks
;
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;
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;
241 // Time of last device activity.
242 AbsoluteTime DeviceActiveTimestamp
;
243 AbsoluteTime MaxPowerStateEntryTime
;
244 AbsoluteTime MaxPowerStateExitTime
;
246 // Used to protect activity flag.
247 IOLock
* ActivityLock
;
249 // Idle timer's period in seconds.
250 unsigned long IdleTimerPeriod
;
251 unsigned long IdleTimerMinPowerState
;
252 unsigned long NextIdleTimerPeriod
;
253 AbsoluteTime IdleTimerStartTime
;
255 // Power state desired by a subclassed device object.
256 IOPMPowerStateIndex DeviceDesire
;
258 // This is the power state we desire currently.
259 IOPMPowerStateIndex DesiredPowerState
;
261 // This is what our parent thinks our need is.
262 IOPMPowerFlags PreviousRequestPowerFlags
;
264 // Cache result from getName(), used in logging.
267 // Number of power states in the power array.
268 IOPMPowerStateIndex NumberOfPowerStates
;
270 // Ordered highest power state in the power array.
271 IOPMPowerStateIndex HighestPowerState
;
273 // Power state array.
274 IOPMPSEntry
* PowerStates
;
276 // The controlling driver.
277 IOService
* ControllingDriver
;
279 // Our current power state.
280 IOPMPowerStateIndex CurrentPowerState
;
282 // Logical OR of power flags for each power domain parent.
283 IOPMPowerFlags ParentsCurrentPowerFlags
;
285 // The highest power state we can achieve in current power domain.
286 IOPMPowerStateIndex MaxPowerState
;
288 // Logical OR of all output power flags in the power state array.
289 IOPMPowerFlags MergedOutputPowerFlags
;
291 // OSArray which manages responses from notified apps and clients.
292 OSArray
* ResponseArray
;
293 OSArray
* NotifyClientArray
;
295 // Used to uniquely identify power management notification to apps and clients.
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
;
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
;
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
327 uint32_t SavedMachineState
;
329 // Protected by PMLock - BEGIN
332 uint32_t PMDriverCallWait
: 1;
335 queue_head_t PMDriverCallQueue
;
336 OSSet
* InsertInterestSet
;
337 OSSet
* RemoveInterestSet
;
340 uint32_t ReportClientCnt
;
342 // Protected by PMLock - END
348 IOPMActions PMActions
;
350 // Serialize IOServicePM state for debug output.
351 IOReturn
gatedSerialize( OSSerialize
* s
) const;
352 virtual bool serialize( OSSerialize
* s
) const APPLE_KEXT_OVERRIDE
;
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;
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
453 #define StateOrder(state) (((state) < fNumberOfPowerStates) \
454 ? pwrMgt->PowerStates[(state)].stateOrder \
456 #define StateMax(a, b) (StateOrder((a)) < StateOrder((b)) ? (b) : (a))
457 #define StateMin(a, b) (StateOrder((a)) < StateOrder((b)) ? (a) : (b))
459 #define kPowerStateZero (0)
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).
467 #define ACK_TIMER_PERIOD 100000000
469 #if defined(__i386__) || defined(__x86_64__)
470 #define WATCHDOG_SLEEP_TIMEOUT (180) // 180 secs
471 #define WATCHDOG_WAKE_TIMEOUT (180) // 180 secs
473 #define WATCHDOG_SLEEP_TIMEOUT (180) // 180 secs
474 #define WATCHDOG_WAKE_TIMEOUT (180) // 180 secs
477 // Max wait time in microseconds for kernel priority and capability clients
478 // with async message handlers to acknowledge.
480 #define kPriorityClientMaxWait (90 * 1000 * 1000)
481 #define kCapabilityClientMaxWait (240 * 1000 * 1000)
483 // Attributes describing a power state change.
484 // See IOPMPowerChangeFlags data type.
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
503 #define kIOPMRootBroadcastFlags (kIOPMSynchronize | \
504 kIOPMRootChangeUp | kIOPMRootChangeDown)
506 // Activity tickle request flags
507 #define kTickleTypePowerDrop 0x01
508 #define kTickleTypePowerRise 0x02
509 #define kTickleTypeActivity 0x04
510 #define kTickleTypeAdvisory 0x08
513 kDriverCallInformPreChange
,
514 kDriverCallInformPostChange
,
515 kDriverCallSetPowerState
,
516 kRootDomainInformPreChange
519 struct DriverCallParam
{
524 // values of OutOfBandParameter
528 kNotifyCapabilityChangeApps
,
529 kNotifyCapabilityChangePriority
532 typedef bool (*IOPMMessageFilter
)(
533 void * target
, void * object
, void * arg1
, void * arg2
, void * arg3
);
535 // used for applyToInterested
536 struct IOPMInterestContext
{
537 OSArray
* responseArray
;
538 OSArray
* notifyClients
;
539 uint16_t serialNumber
;
541 uint8_t enableTracing
;
542 uint32_t maxTimeRequested
;
543 uint32_t messageType
;
546 IOPMPowerStateIndex stateNumber
;
547 IOPMPowerFlags stateFlags
;
548 IOPMPowerChangeFlags changeFlags
;
549 const char * errorLog
;
550 IOPMMessageFilter messageFilter
;
553 // assertPMDriverCall() options
555 kIOPMADC_NoInactiveCheck
= 1
558 //******************************************************************************
559 // PM Statistics & Diagnostics
560 //******************************************************************************
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
;
568 //******************************************************************************
570 //******************************************************************************
572 class IOPMRequest
: public IOCommand
574 OSDeclareDefaultStructors( IOPMRequest
)
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
;
585 IOPMCompletionAction fCompletionAction
;
586 void * fCompletionTarget
;
587 void * fCompletionParam
;
590 uint32_t fRequestTag
;
596 isWorkBlocked( void ) const
598 return fWorkWaitCount
!= 0;
602 isFreeBlocked( void ) const
604 return fFreeWaitCount
!= 0;
608 getNextRequest( void ) const
614 getRootRequest( void ) const
620 if (fCompletionAction
) {
621 return (IOPMRequest
*) this;
628 getType( void ) const
634 isReplyType( void ) const
636 return fRequestType
> kIOPMRequestTypeReplyStart
;
640 getTarget( void ) const
646 isQuiesceBlocker( void ) const
648 return fIsQuiesceBlocker
;
652 isQuiesceType( void ) const
654 return (kIOPMRequestTypeQuiescePowerTree
== fRequestType
) &&
655 (fCompletionAction
!= 0) && (fCompletionTarget
!= 0);
659 installCompletionAction(
661 IOPMCompletionAction action
,
664 fCompletionTarget
= target
;
665 fCompletionAction
= action
;
666 fCompletionParam
= param
;
669 static IOPMRequest
* create( void );
670 bool init( IOService
* owner
, IOOptionBits type
);
672 bool attachNextRequest( IOPMRequest
* next
);
673 bool detachNextRequest( void );
674 bool attachRootRequest( IOPMRequest
* root
);
675 bool detachRootRequest( void );
678 //******************************************************************************
680 //******************************************************************************
682 class IOPMRequestQueue
: public IOEventSource
684 OSDeclareDefaultStructors( IOPMRequestQueue
)
687 typedef bool (*Action
)( IOService
*, IOPMRequest
*, IOPMRequestQueue
* );
693 enum { kMaxDequeueCount
= 256 };
695 virtual bool checkForWork( void ) APPLE_KEXT_OVERRIDE
;
696 virtual void free( void ) APPLE_KEXT_OVERRIDE
;
697 virtual bool init( IOService
* inOwner
, Action inAction
);
700 static IOPMRequestQueue
* create( IOService
* inOwner
, Action inAction
);
701 void queuePMRequest( IOPMRequest
* request
);
702 void queuePMRequestChain( IOPMRequest
** requests
, IOItemCount count
);
705 //******************************************************************************
707 //******************************************************************************
709 #define WORK_QUEUE_STATS 1
711 class IOPMWorkQueue
: public IOEventSource
713 OSDeclareDefaultStructors( IOPMWorkQueue
)
716 typedef bool (*Action
)( IOService
*, IOPMRequest
*, IOPMWorkQueue
* );
719 uint64_t fStatCheckForWork
;
720 uint64_t fStatScanEntries
;
721 uint64_t fStatQueueEmpty
;
722 uint64_t fStatNoWorkDone
;
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
;
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
);
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
);
749 //******************************************************************************
750 // IOPMCompletionQueue
751 //******************************************************************************
753 class IOPMCompletionQueue
: public IOEventSource
755 OSDeclareDefaultStructors( IOPMCompletionQueue
)
758 typedef bool (*Action
)( IOService
*, IOPMRequest
*, IOPMCompletionQueue
* );
763 virtual bool checkForWork( void ) APPLE_KEXT_OVERRIDE
;
764 virtual bool init( IOService
* inOwner
, Action inAction
);
767 static IOPMCompletionQueue
* create( IOService
* inOwner
, Action inAction
);
768 bool queuePMRequest( IOPMRequest
* request
);
771 #endif /* !_IOKIT_IOSERVICEPMPRIVATE_H */