]>
Commit | Line | Data |
---|---|---|
1c79356b A |
1 | /* |
2 | * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
43866e37 | 6 | * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. |
1c79356b | 7 | * |
43866e37 A |
8 | * This file contains Original Code and/or Modifications of Original Code |
9 | * as defined in and that are subject to the Apple Public Source License | |
10 | * Version 2.0 (the 'License'). You may not use this file except in | |
11 | * compliance with the License. Please obtain a copy of the License at | |
12 | * http://www.opensource.apple.com/apsl/ and read it before using this | |
13 | * file. | |
14 | * | |
15 | * The Original Code and all software distributed under the License are | |
16 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
1c79356b A |
17 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
18 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
43866e37 A |
19 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
20 | * Please see the License for the specific language governing rights and | |
21 | * limitations under the License. | |
1c79356b A |
22 | * |
23 | * @APPLE_LICENSE_HEADER_END@ | |
24 | */ | |
25 | #include <IOKit/pwr_mgt/IOPM.h> | |
26 | #include <IOKit/pwr_mgt/IOPMchangeNoteList.h> | |
55e303ae | 27 | #include <IOKit/pwr_mgt/IOPowerConnection.h> |
1c79356b A |
28 | |
29 | #define super OSObject | |
30 | OSDefineMetaClassAndStructors(IOPMchangeNoteList,OSObject) | |
31 | ||
32 | //********************************************************************************* | |
33 | // init | |
34 | // | |
35 | //********************************************************************************* | |
36 | void IOPMchangeNoteList::initialize ( void ) | |
37 | { | |
38 | long i; | |
39 | ||
40 | firstInList = 0; | |
41 | firstUnused = 0; | |
42 | for ( i = 0; i < IOPMMaxChangeNotes; i++ ) { | |
43 | changeNote[i].flags = IOPMNotInUse; | |
44 | } | |
45 | } | |
46 | ||
47 | //********************************************************************************* | |
48 | // createChangeNote | |
49 | // | |
50 | //********************************************************************************* | |
51 | ||
52 | long IOPMchangeNoteList::createChangeNote ( void ) | |
53 | { | |
54 | unsigned long i, j; | |
55 | ||
56 | i = increment(firstUnused); | |
57 | if ( firstInList == i ) { | |
58 | return -1; | |
59 | } | |
60 | j = firstUnused; | |
61 | firstUnused = i; | |
62 | ||
63 | return j; | |
64 | } | |
65 | ||
66 | //********************************************************************************* | |
67 | // currentChange | |
68 | // | |
69 | // Return the ordinal of the first change note in the list. | |
70 | // If the list is empty, return -1. | |
71 | //********************************************************************************* | |
72 | ||
73 | long IOPMchangeNoteList::currentChange ( void ) | |
74 | { | |
75 | if ( firstUnused == firstInList ) { | |
76 | return -1; | |
77 | } | |
78 | else { | |
79 | return firstInList; | |
80 | } | |
81 | } | |
82 | ||
83 | //********************************************************************************* | |
84 | // latestChange | |
85 | // | |
86 | // Return the ordinal of the last change note in the list. | |
87 | // If the list is empty, return -1. | |
88 | //********************************************************************************* | |
89 | ||
90 | long IOPMchangeNoteList::latestChange ( void ) | |
91 | { | |
92 | if ( firstUnused == firstInList ) { | |
93 | return -1; | |
94 | } | |
95 | else { | |
96 | return decrement(firstUnused); | |
97 | } | |
98 | } | |
99 | ||
100 | //********************************************************************************* | |
101 | // releaseHeadChangeNote | |
102 | // | |
103 | // Mark the head node unused. | |
104 | // This happens when the first change in the list is completely processed. | |
105 | // That is, all interested parties have acknowledged it, and power is settled | |
106 | // at the new level. | |
107 | //********************************************************************************* | |
108 | ||
109 | IOReturn IOPMchangeNoteList::releaseHeadChangeNote ( void ) | |
110 | { | |
55e303ae A |
111 | IOPowerConnection *tmp; |
112 | ||
113 | if(tmp = changeNote[firstInList].parent) { | |
114 | changeNote[firstInList].parent = 0; | |
115 | tmp->release(); | |
116 | } | |
117 | ||
1c79356b A |
118 | changeNote[firstInList].flags = IOPMNotInUse; |
119 | firstInList = increment(firstInList); | |
120 | return IOPMNoErr; | |
121 | } | |
122 | ||
123 | //********************************************************************************* | |
124 | // releaseTailChangeNote | |
125 | // | |
126 | // Mark the tail node unused. | |
127 | // This happens when a power change is queued up after another which has | |
128 | // not yet been started, and the second one supercedes the first. The data in | |
129 | // the second is copied into the first and the the second is released. This | |
130 | // collapses the first change out of the list. | |
131 | //********************************************************************************* | |
132 | ||
133 | IOReturn IOPMchangeNoteList::releaseTailChangeNote ( void ) | |
134 | { | |
55e303ae A |
135 | IOPowerConnection *tmp; |
136 | ||
137 | if(tmp = changeNote[firstInList].parent) { | |
138 | changeNote[firstInList].parent = 0; | |
139 | tmp->release(); | |
140 | } | |
141 | ||
1c79356b A |
142 | firstUnused = decrement(firstUnused); |
143 | changeNote[firstUnused].flags = IOPMNotInUse; | |
144 | return IOPMNoErr; | |
145 | } | |
146 | ||
147 | //********************************************************************************* | |
148 | // changeNoteInUse | |
149 | // | |
150 | //********************************************************************************* | |
151 | ||
152 | bool IOPMchangeNoteList::changeNoteInUse ( unsigned long ordinal ) | |
153 | { | |
154 | if ( changeNote[ordinal].flags == IOPMNotInUse ) { | |
155 | return false; | |
156 | } | |
157 | else { | |
158 | return true; | |
159 | } | |
160 | } | |
161 | ||
162 | //********************************************************************************* | |
163 | // nextChangeNote | |
164 | // | |
165 | // If the parameter corresponds to the most recent power change notification | |
166 | // passed to drivers and children, return -1. Otherwise, return the array | |
167 | // position of the next notification in the circular list. | |
168 | //********************************************************************************* | |
169 | ||
170 | long IOPMchangeNoteList::nextChangeNote ( unsigned long ordinal ) | |
171 | { | |
172 | unsigned long i; | |
173 | ||
174 | i = increment(ordinal); | |
175 | if ( i == firstUnused) { | |
176 | return -1; | |
177 | } | |
178 | return ( i ); | |
179 | } | |
180 | ||
181 | //********************************************************************************* | |
182 | // increment | |
183 | // | |
184 | // Increment the parameter mod the circular list size and return it. | |
185 | //********************************************************************************* | |
186 | ||
187 | unsigned long IOPMchangeNoteList::increment ( unsigned long ordinal ) | |
188 | { | |
189 | if ( ordinal == (IOPMMaxChangeNotes - 1) ) { | |
190 | return 0; | |
191 | } | |
192 | else { | |
193 | return ordinal + 1; | |
194 | } | |
195 | } | |
196 | ||
197 | //********************************************************************************* | |
198 | // decrement | |
199 | // | |
200 | // Decrement the parameter mod the circular list size and return it. | |
201 | //********************************************************************************* | |
202 | ||
203 | unsigned long IOPMchangeNoteList::decrement ( unsigned long ordinal ) | |
204 | { | |
205 | if ( ordinal == 0 ) { | |
206 | return IOPMMaxChangeNotes - 1; | |
207 | } | |
208 | else { | |
209 | return ordinal - 1; | |
210 | } | |
211 | } | |
212 | ||
213 | //********************************************************************************* | |
214 | // previousChangeNote | |
215 | // | |
216 | // If the parameter corresponds to the oldest power change notification | |
217 | // passed to drivers and children, return -1. Otherwise, return the array | |
218 | // position of the previous notification in the circular list. | |
219 | //********************************************************************************* | |
220 | ||
221 | long IOPMchangeNoteList::previousChangeNote ( unsigned long ordinal ) | |
222 | { | |
223 | if ( ordinal == firstInList ) { | |
224 | return -1; | |
225 | } | |
226 | return decrement(ordinal); | |
227 | } | |
228 | ||
229 | //********************************************************************************* | |
230 | // listEmpty | |
231 | // | |
232 | //********************************************************************************* | |
233 | ||
234 | bool IOPMchangeNoteList::listEmpty ( void ) | |
235 | { | |
236 | return ( firstInList == firstUnused ) ; | |
237 | } |