]> git.saurik.com Git - apple/xnu.git/blame - iokit/Kernel/IOServicePMPrivate.h
xnu-2050.7.9.tar.gz
[apple/xnu.git] / iokit / Kernel / IOServicePMPrivate.h
CommitLineData
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
39enum {
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
74struct IOPMActions;
75
76typedef void
77(*IOPMActionPowerChangeStart)(
78 void * target,
79 IOService * service,
80 IOPMActions * actions,
81 uint32_t powerState,
82 uint32_t * changeFlags );
83
84typedef void
85(*IOPMActionPowerChangeDone)(
86 void * target,
87 IOService * service,
88 IOPMActions * actions,
89 uint32_t powerState,
90 uint32_t changeFlags );
91
92typedef void
93(*IOPMActionPowerChangeOverride)(
94 void * target,
95 IOService * service,
96 IOPMActions * actions,
97 unsigned long * powerState,
98 uint32_t * changeFlags );
99
100typedef void
101(*IOPMActionActivityTickle)(
102 void * target,
103 IOService * service,
104 IOPMActions * actions );
105
106struct IOPMActions {
107 void * target;
108 uint32_t parameter;
109 IOPMActionPowerChangeStart actionPowerChangeStart;
110 IOPMActionPowerChangeDone actionPowerChangeDone;
111 IOPMActionPowerChangeOverride actionPowerChangeOverride;
112 IOPMActionActivityTickle actionActivityTickle;
113};
114
115//******************************************************************************
116
117enum {
118 kIOPMEventClassSystemEvent = 0x00,
119 kIOPMEventClassDriverEvent = 0x1
120};
121
122class PMEventDetails : public OSObject
123{
124 OSDeclareDefaultStructors( PMEventDetails );
125 friend class IOServicePM;
126 friend class IOPMrootDomain;
127 friend class IOPMTimeline;
128public:
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);
142private:
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
158struct 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
172class IOServicePM : public OSObject
173{
174 friend class IOService;
6d2010ae 175 friend class IOPMWorkQueue;
2d21ac55
A
176
177 OSDeclareDefaultStructors( IOServicePM )
178
179private:
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;
6d2010ae
A
235 unsigned int DoNotPowerDown:1;
236 unsigned int ParentsKnowState:1;
237 unsigned int StrictTreeOrder:1;
238 unsigned int IdleTimerStopped:1;
239 unsigned int AdjustPowerScheduled:1;
240 unsigned int IsPreChange:1;
241 unsigned int DriverCallBusy:1;
242 unsigned int PCDFunctionOverride:1;
7ddcb079 243 unsigned int IdleTimerIgnored:1;
b0d623f7
A
244
245 // Time of last device activity.
2d21ac55
A
246 AbsoluteTime DeviceActiveTimestamp;
247
b0d623f7 248 // Used to protect activity flag.
2d21ac55
A
249 IOLock * ActivityLock;
250
b0d623f7 251 // Idle timer's period in seconds.
2d21ac55 252 unsigned long IdleTimerPeriod;
cf7d32b8 253 unsigned long IdleTimerMinPowerState;
b0d623f7 254 AbsoluteTime IdleTimerStartTime;
2d21ac55 255
b0d623f7 256 // Power state desired by a subclassed device object.
6d2010ae 257 IOPMPowerStateIndex DeviceDesire;
2d21ac55 258
b0d623f7 259 // This is the power state we desire currently.
6d2010ae 260 IOPMPowerStateIndex DesiredPowerState;
2d21ac55 261
b0d623f7 262 // This is what our parent thinks our need is.
6d2010ae 263 IOPMPowerFlags PreviousRequestPowerFlags;
2d21ac55 264
b0d623f7 265 // Cache result from getName(), used in logging.
2d21ac55
A
266 const char * Name;
267
b0d623f7 268 // Number of power states in the power array.
6d2010ae 269 IOPMPowerStateIndex NumberOfPowerStates;
2d21ac55 270
b0d623f7 271 // Power state array.
6d2010ae 272 IOPMPSEntry * PowerStates;
2d21ac55 273
b0d623f7 274 // The controlling driver.
6d2010ae 275 IOService * ControllingDriver;
2d21ac55 276
b0d623f7 277 // Our current power state.
6d2010ae 278 IOPMPowerStateIndex CurrentPowerState;
2d21ac55 279
b0d623f7 280 // Logical OR of power flags for each power domain parent.
6d2010ae 281 IOPMPowerFlags ParentsCurrentPowerFlags;
2d21ac55 282
b0d623f7 283 // The highest power state we can achieve in current power domain.
6d2010ae 284 IOPMPowerStateIndex MaxPowerState;
2d21ac55 285
b0d623f7 286 // Logical OR of all output power character flags in the array.
6d2010ae 287 IOPMPowerFlags OutputPowerCharacterFlags;
2d21ac55 288
b0d623f7 289 // OSArray which manages responses from notified apps and clients.
6d2010ae 290 OSArray * ResponseArray;
b0d623f7
A
291 OSArray * NotifyClientArray;
292
293 // Used to uniquely identify power management notification to apps and clients.
6d2010ae 294 UInt16 SerialNumber;
2d21ac55 295
b0d623f7
A
296 // Used to communicate desired function to tellClientsWithResponse().
297 // This is used because it avoids changing the signatures of the affected virtual methods.
6d2010ae 298 int OutOfBandParameter;
2d21ac55
A
299
300 AbsoluteTime DriverCallStartTime;
301 IOPMPowerFlags CurrentCapabilityFlags;
b0d623f7 302 long ActivityTicklePowerState;
2d21ac55 303 unsigned long CurrentPowerConsumption;
6d2010ae
A
304 IOPMPowerStateIndex TempClampPowerState;
305 OSArray * NotifyChildArray;
b0d623f7 306 OSDictionary * PowerClients;
6d2010ae
A
307 thread_call_t DriverCallEntry;
308 void * DriverCallParamPtr;
309 IOItemCount DriverCallParamCount;
310 IOItemCount DriverCallParamSlots;
b0d623f7 311 uint32_t DriverCallReason;
6d2010ae 312 uint32_t OutOfBandMessage;
b0d623f7
A
313 uint32_t TempClampCount;
314 uint32_t OverrideMaxPowerState;
316670eb
A
315
316 // Protected by ActivityLock - BEGIN
b0d623f7 317 uint32_t ActivityTickleCount;
316670eb
A
318 uint32_t DeviceWasActive;
319 // Protected by ActivityLock - END
320
b0d623f7 321 uint32_t WaitReason;
6d2010ae 322 uint32_t SavedMachineState;
b0d623f7 323 uint32_t RootDomainState;
b0d623f7 324
6d2010ae 325 // Protected by PMLock - BEGIN
b0d623f7 326 struct {
6d2010ae
A
327 uint32_t PMStop : 1;
328 uint32_t PMDriverCallWait : 1;
b0d623f7
A
329 } LockedFlags;
330
6d2010ae
A
331 queue_head_t PMDriverCallQueue;
332 OSSet * InsertInterestSet;
333 OSSet * RemoveInterestSet;
334 // Protected by PMLock - END
2d21ac55
A
335
336#if PM_VARS_SUPPORT
6d2010ae 337 IOPMprot * PMVars;
2d21ac55
A
338#endif
339
6d2010ae
A
340 IOPMActions PMActions;
341
b0d623f7
A
342 // Serialize IOServicePM state for debug output.
343 IOReturn gatedSerialize( OSSerialize * s );
2d21ac55
A
344 virtual bool serialize( OSSerialize * s ) const;
345};
346
6d2010ae 347#define fOwner pwrMgt->Owner
2d21ac55
A
348#define fInterestedDrivers pwrMgt->InterestedDrivers
349#define fDriverTimer pwrMgt->DriverTimer
6d2010ae 350#define fMachineState pwrMgt->MachineState
2d21ac55
A
351#define fAckTimer pwrMgt->AckTimer
352#define fSettleTimer pwrMgt->SettleTimer
6d2010ae 353#define fIdleTimer pwrMgt->IdleTimer
2d21ac55 354#define fSettleTimeUS pwrMgt->SettleTimeUS
6d2010ae 355#define fHeadNoteChangeFlags pwrMgt->HeadNoteChangeFlags
b0d623f7
A
356#define fHeadNotePowerState pwrMgt->HeadNotePowerState
357#define fHeadNotePowerArrayEntry pwrMgt->HeadNotePowerArrayEntry
358#define fHeadNoteDomainFlags pwrMgt->HeadNoteDomainFlags
7e4a7d39 359#define fHeadNoteDomainTargetFlags pwrMgt->HeadNoteDomainTargetFlags
b0d623f7
A
360#define fHeadNoteParentConnection pwrMgt->HeadNoteParentConnection
361#define fHeadNoteParentFlags pwrMgt->HeadNoteParentFlags
2d21ac55
A
362#define fHeadNotePendingAcks pwrMgt->HeadNotePendingAcks
363#define fPMLock pwrMgt->PMLock
6d2010ae
A
364#define fInitialPowerChange pwrMgt->InitialPowerChange
365#define fInitialSetPowerState pwrMgt->InitialSetPowerState
366#define fDeviceOverrideEnabled pwrMgt->DeviceOverrideEnabled
367#define fDeviceWasActive pwrMgt->DeviceWasActive
368#define fDoNotPowerDown pwrMgt->DoNotPowerDown
369#define fParentsKnowState pwrMgt->ParentsKnowState
370#define fStrictTreeOrder pwrMgt->StrictTreeOrder
371#define fIdleTimerStopped pwrMgt->IdleTimerStopped
372#define fAdjustPowerScheduled pwrMgt->AdjustPowerScheduled
373#define fIsPreChange pwrMgt->IsPreChange
374#define fDriverCallBusy pwrMgt->DriverCallBusy
375#define fPCDFunctionOverride pwrMgt->PCDFunctionOverride
7ddcb079 376#define fIdleTimerIgnored pwrMgt->IdleTimerIgnored
6d2010ae 377#define fDeviceActiveTimestamp pwrMgt->DeviceActiveTimestamp
2d21ac55 378#define fActivityLock pwrMgt->ActivityLock
2d21ac55 379#define fIdleTimerPeriod pwrMgt->IdleTimerPeriod
cf7d32b8 380#define fIdleTimerMinPowerState pwrMgt->IdleTimerMinPowerState
b0d623f7 381#define fIdleTimerStartTime pwrMgt->IdleTimerStartTime
2d21ac55 382#define fDeviceDesire pwrMgt->DeviceDesire
2d21ac55 383#define fDesiredPowerState pwrMgt->DesiredPowerState
6d2010ae 384#define fPreviousRequestPowerFlags pwrMgt->PreviousRequestPowerFlags
2d21ac55 385#define fName pwrMgt->Name
2d21ac55
A
386#define fNumberOfPowerStates pwrMgt->NumberOfPowerStates
387#define fPowerStates pwrMgt->PowerStates
388#define fControllingDriver pwrMgt->ControllingDriver
2d21ac55 389#define fCurrentPowerState pwrMgt->CurrentPowerState
2d21ac55 390#define fParentsCurrentPowerFlags pwrMgt->ParentsCurrentPowerFlags
6d2010ae 391#define fMaxPowerState pwrMgt->MaxPowerState
2d21ac55 392#define fOutputPowerCharacterFlags pwrMgt->OutputPowerCharacterFlags
2d21ac55 393#define fResponseArray pwrMgt->ResponseArray
b0d623f7 394#define fNotifyClientArray pwrMgt->NotifyClientArray
6d2010ae 395#define fSerialNumber pwrMgt->SerialNumber
2d21ac55
A
396#define fOutOfBandParameter pwrMgt->OutOfBandParameter
397#define fDriverCallStartTime pwrMgt->DriverCallStartTime
398#define fCurrentCapabilityFlags pwrMgt->CurrentCapabilityFlags
6d2010ae 399#define fActivityTicklePowerState pwrMgt->ActivityTicklePowerState
2d21ac55
A
400#define fCurrentPowerConsumption pwrMgt->CurrentPowerConsumption
401#define fTempClampPowerState pwrMgt->TempClampPowerState
6d2010ae
A
402#define fNotifyChildArray pwrMgt->NotifyChildArray
403#define fPowerClients pwrMgt->PowerClients
2d21ac55
A
404#define fDriverCallEntry pwrMgt->DriverCallEntry
405#define fDriverCallParamPtr pwrMgt->DriverCallParamPtr
406#define fDriverCallParamCount pwrMgt->DriverCallParamCount
407#define fDriverCallParamSlots pwrMgt->DriverCallParamSlots
6d2010ae
A
408#define fDriverCallReason pwrMgt->DriverCallReason
409#define fOutOfBandMessage pwrMgt->OutOfBandMessage
410#define fTempClampCount pwrMgt->TempClampCount
411#define fOverrideMaxPowerState pwrMgt->OverrideMaxPowerState
412#define fActivityTickleCount pwrMgt->ActivityTickleCount
413#define fWaitReason pwrMgt->WaitReason
414#define fSavedMachineState pwrMgt->SavedMachineState
415#define fRootDomainState pwrMgt->RootDomainState
416#define fLockedFlags pwrMgt->LockedFlags
417#define fPMDriverCallQueue pwrMgt->PMDriverCallQueue
2d21ac55
A
418#define fInsertInterestSet pwrMgt->InsertInterestSet
419#define fRemoveInterestSet pwrMgt->RemoveInterestSet
2d21ac55 420#define fPMVars pwrMgt->PMVars
6d2010ae 421#define fPMActions pwrMgt->PMActions
2d21ac55 422
b0d623f7
A
423/*
424When an IOService is waiting for acknowledgement to a power change
425notification from an interested driver or the controlling driver,
426the ack timer is ticking every tenth of a second.
2d21ac55
A
427(100000000 nanoseconds are one tenth of a second).
428*/
b0d623f7
A
429#define ACK_TIMER_PERIOD 100000000
430
6d2010ae
A
431// Max wait time in microseconds for kernel priority and capability clients
432// with async message handlers to acknowledge.
433//
434#define kPriorityClientMaxWait (90 * 1000 * 1000)
435#define kCapabilityClientMaxWait (240 * 1000 * 1000)
436
437// Attributes describing a power state change.
438// See IOPMPowerChangeFlags data type.
439//
440#define kIOPMParentInitiated 0x0001 // this power change initiated by our parent
441#define kIOPMSelfInitiated 0x0002 // this power change initiated by this device
442#define kIOPMNotDone 0x0004 // we couldn't make this change
443#define kIOPMDomainWillChange 0x0008 // change started by PowerDomainWillChangeTo
444#define kIOPMDomainDidChange 0x0010 // change started by PowerDomainDidChangeTo
445#define kIOPMDomainPowerDrop 0x0020 // Domain is lowering power
446#define kIOPMIgnoreChildren 0x0040 // Ignore children and driver power desires
447#define kIOPMSkipAskPowerDown 0x0080 // skip the ask app phase
448#define kIOPMSynchronize 0x0100 // change triggered by power tree re-sync
449#define kIOPMSyncNoChildNotify 0x0200 // sync root domain only, not entire tree
450#define kIOPMSyncTellPowerDown 0x0400 // send the ask/will power off messages
451#define kIOPMSyncCancelPowerDown 0x0800 // sleep cancel for maintenance wake
316670eb 452#define kIOPMInitialPowerChange 0x1000 // set for initial power change
2d21ac55
A
453
454enum {
455 kDriverCallInformPreChange,
456 kDriverCallInformPostChange,
457 kDriverCallSetPowerState
458};
459
460struct DriverCallParam {
461 OSObject * Target;
462 IOReturn Result;
463};
464
6d2010ae 465// values of OutOfBandParameter
2d21ac55
A
466enum {
467 kNotifyApps,
6d2010ae
A
468 kNotifyPriority,
469 kNotifyCapabilityChangeApps,
470 kNotifyCapabilityChangePriority
2d21ac55
A
471};
472
6d2010ae
A
473typedef bool (*IOPMMessageFilter)(
474 void * target, void * object, void * arg1, void * arg2, void * arg3 );
b0d623f7 475
2d21ac55 476// used for applyToInterested
b0d623f7 477struct IOPMInterestContext {
6d2010ae
A
478 OSArray * responseArray;
479 OSArray * notifyClients;
480 uint16_t serialNumber;
481 uint8_t isPreChange;
482 uint8_t enableTracing;
483 uint32_t maxTimeRequested;
484 uint32_t messageType;
485 uint32_t notifyType;
486 IOService * us;
487 IOPMPowerStateIndex stateNumber;
488 IOPMPowerFlags stateFlags;
489 IOPMPowerChangeFlags changeFlags;
490 const char * errorLog;
491 IOPMMessageFilter messageFilter;
2d21ac55
A
492};
493
6d2010ae
A
494// assertPMDriverCall() options
495enum {
496 kIOPMADC_NoInactiveCheck = 1
497};
498
499//******************************************************************************
b0d623f7 500// PM Statistics & Diagnostics
6d2010ae 501//******************************************************************************
b0d623f7
A
502
503extern const OSSymbol *gIOPMStatsApplicationResponseTimedOut;
504extern const OSSymbol *gIOPMStatsApplicationResponseCancel;
505extern const OSSymbol *gIOPMStatsApplicationResponseSlow;
506
6d2010ae
A
507//******************************************************************************
508// IOPMRequest
509//******************************************************************************
2d21ac55 510
b0d623f7
A
511typedef void (*IOPMCompletionAction)(void * target, void * param, IOReturn status);
512
2d21ac55
A
513class IOPMRequest : public IOCommand
514{
515 OSDeclareDefaultStructors( IOPMRequest )
516
517protected:
b0d623f7
A
518 IOService * fTarget; // request target
519 IOPMRequest * fRequestNext; // the next request in the chain
7e4a7d39 520 IOPMRequest * fRequestRoot; // the root request in the issue tree
b0d623f7 521 IOItemCount fWorkWaitCount; // execution blocked if non-zero
7e4a7d39 522 IOItemCount fFreeWaitCount; // completion blocked if non-zero
b0d623f7
A
523 uint32_t fType; // request type
524
525 IOPMCompletionAction fCompletionAction;
526 void * fCompletionTarget;
527 void * fCompletionParam;
528 IOReturn fCompletionStatus;
2d21ac55
A
529
530public:
b0d623f7
A
531 void * fArg0;
532 void * fArg1;
533 void * fArg2;
2d21ac55 534
b0d623f7 535 inline bool isWorkBlocked( void ) const
2d21ac55 536 {
b0d623f7 537 return (fWorkWaitCount != 0);
2d21ac55
A
538 }
539
b0d623f7 540 inline bool isFreeBlocked( void ) const
2d21ac55 541 {
b0d623f7 542 return (fFreeWaitCount != 0);
2d21ac55
A
543 }
544
b0d623f7 545 inline IOPMRequest * getNextRequest( void ) const
2d21ac55 546 {
b0d623f7 547 return fRequestNext;
2d21ac55
A
548 }
549
7e4a7d39
A
550 inline IOPMRequest * getRootRequest( void ) const
551 {
b0d623f7
A
552 if (fRequestRoot) return fRequestRoot;
553 if (fCompletionAction) return (IOPMRequest *) this;
7e4a7d39
A
554 return 0;
555 }
b0d623f7
A
556
557 inline uint32_t getType( void ) const
2d21ac55
A
558 {
559 return fType;
560 }
561
b0d623f7 562 inline bool isReplyType( void ) const
2d21ac55
A
563 {
564 return (fType > kIOPMRequestTypeReplyStart);
565 }
566
b0d623f7 567 inline IOService * getTarget( void ) const
2d21ac55
A
568 {
569 return fTarget;
570 }
571
b0d623f7
A
572 inline bool isCompletionInstalled( void )
573 {
574 return (fCompletionAction != 0);
575 }
2d21ac55 576
b0d623f7
A
577 inline void installCompletionAction(
578 IOPMCompletionAction action,
579 void * target,
580 void * param )
581 {
582 fCompletionAction = action;
583 fCompletionTarget = target;
584 fCompletionParam = param;
585 }
2d21ac55 586
b0d623f7
A
587 static IOPMRequest * create( void );
588 bool init( IOService * owner, IOOptionBits type );
589 void reset( void );
6d2010ae
A
590 bool attachNextRequest( IOPMRequest * next );
591 bool detachNextRequest( void );
592 bool attachRootRequest( IOPMRequest * root );
593 bool detachRootRequest( void );
2d21ac55
A
594};
595
6d2010ae
A
596//******************************************************************************
597// IOPMRequestQueue
598//******************************************************************************
599
2d21ac55
A
600class IOPMRequestQueue : public IOEventSource
601{
602 OSDeclareDefaultStructors( IOPMRequestQueue )
603
604public:
605 typedef bool (*Action)( IOService *, IOPMRequest *, IOPMRequestQueue * );
606
607protected:
608 queue_head_t fQueue;
609 IOLock * fLock;
610
611 virtual bool checkForWork( void );
612 virtual void free( void );
613 virtual bool init( IOService * inOwner, Action inAction );
614
615public:
616 static IOPMRequestQueue * create( IOService * inOwner, Action inAction );
617 void queuePMRequest( IOPMRequest * request );
618 void queuePMRequestChain( IOPMRequest ** requests, IOItemCount count );
2d21ac55
A
619};
620
6d2010ae
A
621//******************************************************************************
622// IOPMWorkQueue
623//******************************************************************************
624
625#define WORK_QUEUE_STATS 1
626
2d21ac55
A
627class IOPMWorkQueue : public IOEventSource
628{
629 OSDeclareDefaultStructors( IOPMWorkQueue )
630
631public:
632 typedef bool (*Action)( IOService *, IOPMRequest *, IOPMWorkQueue * );
633
6d2010ae
A
634#if WORK_QUEUE_STATS
635 uint64_t fStatCheckForWork;
636 uint64_t fStatScanEntries;
637 uint64_t fStatQueueEmpty;
638 uint64_t fStatNoWorkDone;
639#endif
640
2d21ac55 641protected:
6d2010ae
A
642 queue_head_t fWorkQueue;
643 Action fWorkAction;
644 Action fRetireAction;
645 uint32_t fQueueLength;
646 uint32_t fConsumerCount;
647 volatile uint32_t fProducerCount;
2d21ac55
A
648
649 virtual bool checkForWork( void );
650 virtual bool init( IOService * inOwner, Action work, Action retire );
6d2010ae 651 bool checkRequestQueue( queue_head_t * queue, bool * empty );
2d21ac55
A
652
653public:
b0d623f7 654 static IOPMWorkQueue * create( IOService * inOwner, Action work, Action retire );
6d2010ae
A
655 bool queuePMRequest( IOPMRequest * request, IOServicePM * pwrMgt );
656 void signalWorkAvailable( void );
657 void incrementProducerCount( void );
b0d623f7
A
658};
659
6d2010ae
A
660//******************************************************************************
661// IOPMCompletionQueue
662//******************************************************************************
663
b0d623f7
A
664class IOPMCompletionQueue : public IOEventSource
665{
666 OSDeclareDefaultStructors( IOPMCompletionQueue )
667
668public:
669 typedef bool (*Action)( IOService *, IOPMRequest *, IOPMCompletionQueue * );
670
671protected:
672 queue_head_t fQueue;
673
674 virtual bool checkForWork( void );
675 virtual bool init( IOService * inOwner, Action inAction );
676
677public:
678 static IOPMCompletionQueue * create( IOService * inOwner, Action inAction );
6d2010ae 679 bool queuePMRequest( IOPMRequest * request );
2d21ac55
A
680};
681
682#endif /* !_IOKIT_IOSERVICEPMPRIVATE_H */