]>
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_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
23 * @APPLE_LICENSE_HEADER_END@
25 #include <IOKit/pwr_mgt/IOPM.h>
26 #include <IOKit/pwr_mgt/IOPMchangeNoteList.h>
27 #include <IOKit/pwr_mgt/IOPowerConnection.h>
29 #define super OSObject
30 OSDefineMetaClassAndStructors(IOPMchangeNoteList
,OSObject
)
32 //*********************************************************************************
35 //*********************************************************************************
36 void IOPMchangeNoteList::initialize ( void )
42 for ( i
= 0; i
< IOPMMaxChangeNotes
; i
++ ) {
43 changeNote
[i
].flags
= IOPMNotInUse
;
47 //*********************************************************************************
50 //*********************************************************************************
52 long IOPMchangeNoteList::createChangeNote ( void )
56 i
= increment(firstUnused
);
57 if ( firstInList
== i
) {
66 //*********************************************************************************
69 // Return the ordinal of the first change note in the list.
70 // If the list is empty, return -1.
71 //*********************************************************************************
73 long IOPMchangeNoteList::currentChange ( void )
75 if ( firstUnused
== firstInList
) {
83 //*********************************************************************************
86 // Return the ordinal of the last change note in the list.
87 // If the list is empty, return -1.
88 //*********************************************************************************
90 long IOPMchangeNoteList::latestChange ( void )
92 if ( firstUnused
== firstInList
) {
96 return decrement(firstUnused
);
100 //*********************************************************************************
101 // releaseHeadChangeNote
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
107 //*********************************************************************************
109 IOReturn
IOPMchangeNoteList::releaseHeadChangeNote ( void )
111 IOPowerConnection
*tmp
;
113 if(tmp
= changeNote
[firstInList
].parent
) {
114 changeNote
[firstInList
].parent
= 0;
118 changeNote
[firstInList
].flags
= IOPMNotInUse
;
119 firstInList
= increment(firstInList
);
123 //*********************************************************************************
124 // releaseTailChangeNote
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 //*********************************************************************************
133 IOReturn
IOPMchangeNoteList::releaseTailChangeNote ( void )
135 IOPowerConnection
*tmp
;
137 if(tmp
= changeNote
[firstInList
].parent
) {
138 changeNote
[firstInList
].parent
= 0;
142 firstUnused
= decrement(firstUnused
);
143 changeNote
[firstUnused
].flags
= IOPMNotInUse
;
147 //*********************************************************************************
150 //*********************************************************************************
152 bool IOPMchangeNoteList::changeNoteInUse ( unsigned long ordinal
)
154 if ( changeNote
[ordinal
].flags
== IOPMNotInUse
) {
162 //*********************************************************************************
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 //*********************************************************************************
170 long IOPMchangeNoteList::nextChangeNote ( unsigned long ordinal
)
174 i
= increment(ordinal
);
175 if ( i
== firstUnused
) {
181 //*********************************************************************************
184 // Increment the parameter mod the circular list size and return it.
185 //*********************************************************************************
187 unsigned long IOPMchangeNoteList::increment ( unsigned long ordinal
)
189 if ( ordinal
== (IOPMMaxChangeNotes
- 1) ) {
197 //*********************************************************************************
200 // Decrement the parameter mod the circular list size and return it.
201 //*********************************************************************************
203 unsigned long IOPMchangeNoteList::decrement ( unsigned long ordinal
)
205 if ( ordinal
== 0 ) {
206 return IOPMMaxChangeNotes
- 1;
213 //*********************************************************************************
214 // previousChangeNote
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 //*********************************************************************************
221 long IOPMchangeNoteList::previousChangeNote ( unsigned long ordinal
)
223 if ( ordinal
== firstInList
) {
226 return decrement(ordinal
);
229 //*********************************************************************************
232 //*********************************************************************************
234 bool IOPMchangeNoteList::listEmpty ( void )
236 return ( firstInList
== firstUnused
) ;