]>
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 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 #include <IOKit/pwr_mgt/IOPM.h>
23 #include <IOKit/pwr_mgt/IOPMchangeNoteList.h>
24 #include <IOKit/pwr_mgt/IOPowerConnection.h>
26 #define super OSObject
27 OSDefineMetaClassAndStructors(IOPMchangeNoteList
,OSObject
)
29 //*********************************************************************************
32 //*********************************************************************************
33 void IOPMchangeNoteList::initialize ( void )
39 for ( i
= 0; i
< IOPMMaxChangeNotes
; i
++ ) {
40 changeNote
[i
].flags
= IOPMNotInUse
;
44 //*********************************************************************************
47 //*********************************************************************************
49 long IOPMchangeNoteList::createChangeNote ( void )
53 i
= increment(firstUnused
);
54 if ( firstInList
== i
) {
63 //*********************************************************************************
66 // Return the ordinal of the first change note in the list.
67 // If the list is empty, return -1.
68 //*********************************************************************************
70 long IOPMchangeNoteList::currentChange ( void )
72 if ( firstUnused
== firstInList
) {
80 //*********************************************************************************
83 // Return the ordinal of the last change note in the list.
84 // If the list is empty, return -1.
85 //*********************************************************************************
87 long IOPMchangeNoteList::latestChange ( void )
89 if ( firstUnused
== firstInList
) {
93 return decrement(firstUnused
);
97 //*********************************************************************************
98 // releaseHeadChangeNote
100 // Mark the head node unused.
101 // This happens when the first change in the list is completely processed.
102 // That is, all interested parties have acknowledged it, and power is settled
104 //*********************************************************************************
106 IOReturn
IOPMchangeNoteList::releaseHeadChangeNote ( void )
108 IOPowerConnection
*tmp
;
110 if(tmp
= changeNote
[firstInList
].parent
) {
111 changeNote
[firstInList
].parent
= 0;
115 changeNote
[firstInList
].flags
= IOPMNotInUse
;
116 firstInList
= increment(firstInList
);
120 //*********************************************************************************
121 // releaseTailChangeNote
123 // Mark the tail node unused.
124 // This happens when a power change is queued up after another which has
125 // not yet been started, and the second one supercedes the first. The data in
126 // the second is copied into the first and the the second is released. This
127 // collapses the first change out of the list.
128 //*********************************************************************************
130 IOReturn
IOPMchangeNoteList::releaseTailChangeNote ( void )
132 IOPowerConnection
*tmp
;
134 if(tmp
= changeNote
[firstInList
].parent
) {
135 changeNote
[firstInList
].parent
= 0;
139 firstUnused
= decrement(firstUnused
);
140 changeNote
[firstUnused
].flags
= IOPMNotInUse
;
144 //*********************************************************************************
147 //*********************************************************************************
149 bool IOPMchangeNoteList::changeNoteInUse ( unsigned long ordinal
)
151 if ( changeNote
[ordinal
].flags
== IOPMNotInUse
) {
159 //*********************************************************************************
162 // If the parameter corresponds to the most recent power change notification
163 // passed to drivers and children, return -1. Otherwise, return the array
164 // position of the next notification in the circular list.
165 //*********************************************************************************
167 long IOPMchangeNoteList::nextChangeNote ( unsigned long ordinal
)
171 i
= increment(ordinal
);
172 if ( i
== firstUnused
) {
178 //*********************************************************************************
181 // Increment the parameter mod the circular list size and return it.
182 //*********************************************************************************
184 unsigned long IOPMchangeNoteList::increment ( unsigned long ordinal
)
186 if ( ordinal
== (IOPMMaxChangeNotes
- 1) ) {
194 //*********************************************************************************
197 // Decrement the parameter mod the circular list size and return it.
198 //*********************************************************************************
200 unsigned long IOPMchangeNoteList::decrement ( unsigned long ordinal
)
202 if ( ordinal
== 0 ) {
203 return IOPMMaxChangeNotes
- 1;
210 //*********************************************************************************
211 // previousChangeNote
213 // If the parameter corresponds to the oldest power change notification
214 // passed to drivers and children, return -1. Otherwise, return the array
215 // position of the previous notification in the circular list.
216 //*********************************************************************************
218 long IOPMchangeNoteList::previousChangeNote ( unsigned long ordinal
)
220 if ( ordinal
== firstInList
) {
223 return decrement(ordinal
);
226 //*********************************************************************************
229 //*********************************************************************************
231 bool IOPMchangeNoteList::listEmpty ( void )
233 return ( firstInList
== firstUnused
) ;