]> git.saurik.com Git - apple/xnu.git/blob - iokit/IOKit/pwr_mgt/IOPMchangeNoteList.h
a35a7247ba04d51404656614c5ced1718b0aa118
[apple/xnu.git] / iokit / IOKit / pwr_mgt / IOPMchangeNoteList.h
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, 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 #include <libkern/c++/OSObject.h>
29 #include <IOKit/IOReturn.h>
30
31 class IOPowerConnection;
32
33 // This is a list of State Changes which are in progress. Its purpose is to keep track of the
34 // notifications and acknowledgements caused by state change. A change is added to the list
35 // when either our parent notifies us that the power domain is changing state or when we decide
36 // to change power to our device or domain.
37 //
38 // A change is removed from the list when all interested parties have been informed of the upcoming
39 // change, all of them have acknowledged the notification, the change has been made, all interested
40 // parties have been informed that the change was made, and all of them have acknowledged.
41 //
42 // The list is strictly first-in, first-out. It is implemented as a circular list in a linear
43 // array. There are two pointers into the array. The circular list is empty when these two
44 // pointers are equal.
45
46 // More specifically, a change note is put into the array when one of these things happens:
47 // the device decides it is idle and needs to reduce power. (changePowerStateTo)
48 // the device decides it is not idle and needs to increase power. (changePowerStateTo)
49 // the controlling driver requests a state change. (changePowerStateTo)
50 // some client needs to use the device but it is powered down. (makeUsable)
51 // the parent says the domain power is changing. (powerStateWillChangeTo)
52 // a child says it no longer needs power, and all other children are similarly idle. (requestDomainState)
53 //. a child wants more power in the domain so it can raise its power state. (requestDomainState)
54 //
55 // A change note is removed from the array when all interested drivers and power domain
56 // children have acknowledged the change.
57
58 // Each change note contains:
59 // A flag field which describes the change.
60 // Which power state the device will be in after the change.
61 // The power flags which describe the result of this change.
62
63 struct changeNoteItem{
64 unsigned long flags;
65 unsigned long newStateNumber;
66 IOPMPowerFlags outputPowerCharacter;
67 IOPMPowerFlags inputPowerRequirement;
68 IOPMPowerFlags domainState;
69 IOPowerConnection * parent;
70 IOPMPowerFlags singleParentState;
71 IOPMPowerFlags capabilityFlags;
72 };
73
74 typedef struct changeNoteItem changeNoteItem;
75
76
77 // flags field
78
79 #define IOPMParentInitiated 1 // this power change initiated by our parent
80 #define IOPMWeInitiated 2 // this power change initiated by this device (not parent)
81 #define IOPMNotDone 4 // we couldn't make this change
82 #define IOPMNotInUse 8 // this list element not currently in use
83 #define IOPMDomainWillChange 16 // parent change started by PowerDomainWillChangeTo
84 #define IOPMDomainDidChange 32 // parent change started by PowerDomainDidChangeTo
85
86
87 // Length of change note list is maximum 5. There cannot be two adjacent device-initiated change notes unless
88 // one is currently being actioned, because two adjacent in-active device-initiated changes are always collapsed
89 // into one, and there cannot be more than two parent-initiated change notes in the queue (from one parent),
90 // because the parent does not
91 // initiate a change (by calling domainStateWillChange) until everybody has acknowledged the previous one
92 // (by calling domainStateDidChange), although if we are the last to send that acknowledgement, the change we
93 // are acknowledging will still be in the queue as we acknowledge, and at that point the parent can give us another
94 // (by callingdomainStateWillChange). So we need room for two parent changes, two non-adjacent device changes,
95 // one more per additional parent, say two more,
96 // and room for one more device change to get into the queue before collapsing it with its neighbor. In this case, seven
97 // entryies suffices. Or, we need
98 // room for two adjacent device changes (one in progress), a parent change, another device change, another parent change,
99 // another device change, another parent change, another device change, plus
100 // one more device change to get into the queue before collapsing it with its neighbor. Nine entries in this case.
101 // I'm not sure what irrationallity causes me to code for twenty entries in the queue.
102 #define IOPMMaxChangeNotes 20
103
104 class IOPMchangeNoteList :public OSObject
105 {
106 OSDeclareDefaultStructors(IOPMchangeNoteList)
107
108 private:
109 unsigned long firstInList; // points to oldest active change note in list
110 unsigned long firstUnused; // points just beyond newest change note in list
111
112 public:
113
114 changeNoteItem changeNote[IOPMMaxChangeNotes];
115
116
117 void initialize ( void );
118
119 long createChangeNote ( void );
120
121 long currentChange ( void );
122
123 long latestChange ( void );
124
125 IOReturn releaseHeadChangeNote ( void );
126
127 IOReturn releaseTailChangeNote ( void );
128
129 bool changeNoteInUse ( unsigned long ordinal );
130
131 long nextChangeNote ( unsigned long ordinal );
132
133 unsigned long increment (unsigned long ordinal );
134
135 unsigned long decrement (unsigned long ordinal );
136
137 long previousChangeNote (unsigned long ordinal );
138
139 bool listEmpty ( void );
140
141 };