]>
git.saurik.com Git - apple/xnu.git/blob - iokit/Kernel/IOPMchangeNoteList.cpp
2 * Copyright (c) 1998-2000 Apple Computer, 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@
28 #include <IOKit/pwr_mgt/IOPM.h>
29 #include <IOKit/pwr_mgt/IOPMchangeNoteList.h>
30 #include <IOKit/pwr_mgt/IOPowerConnection.h>
32 #define super OSObject
33 OSDefineMetaClassAndStructors(IOPMchangeNoteList
,OSObject
)
35 //*********************************************************************************
38 //*********************************************************************************
39 void IOPMchangeNoteList::initialize ( void )
45 for ( i
= 0; i
< IOPMMaxChangeNotes
; i
++ ) {
46 changeNote
[i
].flags
= IOPMNotInUse
;
50 //*********************************************************************************
53 //*********************************************************************************
55 long IOPMchangeNoteList::createChangeNote ( void )
59 i
= increment(firstUnused
);
60 if ( firstInList
== i
) {
69 //*********************************************************************************
72 // Return the ordinal of the first change note in the list.
73 // If the list is empty, return -1.
74 //*********************************************************************************
76 long IOPMchangeNoteList::currentChange ( void )
78 if ( firstUnused
== firstInList
) {
86 //*********************************************************************************
89 // Return the ordinal of the last change note in the list.
90 // If the list is empty, return -1.
91 //*********************************************************************************
93 long IOPMchangeNoteList::latestChange ( void )
95 if ( firstUnused
== firstInList
) {
99 return decrement(firstUnused
);
103 //*********************************************************************************
104 // releaseHeadChangeNote
106 // Mark the head node unused.
107 // This happens when the first change in the list is completely processed.
108 // That is, all interested parties have acknowledged it, and power is settled
110 //*********************************************************************************
112 IOReturn
IOPMchangeNoteList::releaseHeadChangeNote ( void )
114 IOPowerConnection
*tmp
;
116 if((tmp
= changeNote
[firstInList
].parent
)) {
117 changeNote
[firstInList
].parent
= 0;
121 changeNote
[firstInList
].flags
= IOPMNotInUse
;
122 firstInList
= increment(firstInList
);
126 //*********************************************************************************
127 // releaseTailChangeNote
129 // Mark the tail node unused.
130 // This happens when a power change is queued up after another which has
131 // not yet been started, and the second one supercedes the first. The data in
132 // the second is copied into the first and the the second is released. This
133 // collapses the first change out of the list.
134 //*********************************************************************************
136 IOReturn
IOPMchangeNoteList::releaseTailChangeNote ( void )
138 IOPowerConnection
*tmp
;
140 if((tmp
= changeNote
[firstInList
].parent
)) {
141 changeNote
[firstInList
].parent
= 0;
145 firstUnused
= decrement(firstUnused
);
146 changeNote
[firstUnused
].flags
= IOPMNotInUse
;
150 //*********************************************************************************
153 //*********************************************************************************
155 bool IOPMchangeNoteList::changeNoteInUse ( unsigned long ordinal
)
157 if ( changeNote
[ordinal
].flags
== IOPMNotInUse
) {
165 //*********************************************************************************
168 // If the parameter corresponds to the most recent power change notification
169 // passed to drivers and children, return -1. Otherwise, return the array
170 // position of the next notification in the circular list.
171 //*********************************************************************************
173 long IOPMchangeNoteList::nextChangeNote ( unsigned long ordinal
)
177 i
= increment(ordinal
);
178 if ( i
== firstUnused
) {
184 //*********************************************************************************
187 // Increment the parameter mod the circular list size and return it.
188 //*********************************************************************************
190 unsigned long IOPMchangeNoteList::increment ( unsigned long ordinal
)
192 if ( ordinal
== (IOPMMaxChangeNotes
- 1) ) {
200 //*********************************************************************************
203 // Decrement the parameter mod the circular list size and return it.
204 //*********************************************************************************
206 unsigned long IOPMchangeNoteList::decrement ( unsigned long ordinal
)
208 if ( ordinal
== 0 ) {
209 return IOPMMaxChangeNotes
- 1;
216 //*********************************************************************************
217 // previousChangeNote
219 // If the parameter corresponds to the oldest power change notification
220 // passed to drivers and children, return -1. Otherwise, return the array
221 // position of the previous notification in the circular list.
222 //*********************************************************************************
224 long IOPMchangeNoteList::previousChangeNote ( unsigned long ordinal
)
226 if ( ordinal
== firstInList
) {
229 return decrement(ordinal
);
232 //*********************************************************************************
235 //*********************************************************************************
237 bool IOPMchangeNoteList::listEmpty ( void )
239 return ( firstInList
== firstUnused
) ;