]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOATAStandard/ATAQueueHelpers.cpp
xnu-123.5.tar.gz
[apple/xnu.git] / iokit / Families / IOATAStandard / ATAQueueHelpers.cpp
1 /*
2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 *
24 * queueHelpers.cpp
25 *
26 */
27 #include <IOKit/ata/IOATAStandardInterface.h>
28
29 void IOATAStandardDevice::addCommand( queue_head_t *list, IOATAStandardCommand *ataCmd )
30 {
31 ataCmd->list = list;
32
33 queue_enter( list, ataCmd, IOATAStandardCommand *, nextCommand );
34 }
35
36 void IOATAStandardDevice::deleteCommand( queue_head_t *list, IOATAStandardCommand *ataCmd, IOReturn rc = kIOReturnSuccess )
37 {
38 ataCmd->list = 0;
39
40 if ( rc != kIOReturnSuccess )
41 {
42 if ( ataCmd->results.returnCode == kIOReturnSuccess )
43 {
44 ataCmd->results.returnCode = (IOReturn) rc;
45 }
46 }
47
48 queue_remove( list, ataCmd, IOATAStandardCommand *, nextCommand );
49 }
50
51 IOATAStandardCommand *IOATAStandardDevice::checkCommand( queue_head_t *list )
52 {
53 if ( queue_empty( list ) == true )
54 {
55 return 0;
56 }
57
58 return (IOATAStandardCommand *)queue_first( list );
59 }
60
61
62 IOATAStandardCommand *IOATAStandardDevice::getCommand( queue_head_t *list )
63 {
64 IOATAStandardCommand *ataCmd = 0;
65
66 if ( queue_empty( list ) == false )
67 {
68 queue_remove_first( list, ataCmd, IOATAStandardCommand *, nextCommand );
69 ataCmd->list = 0;
70 }
71
72 return ataCmd;
73 }
74
75 void IOATAStandardDevice::stackCommand( queue_head_t *list, IOATAStandardCommand *ataCmd )
76 {
77 ataCmd->list = list;
78
79 queue_enter_first( list, ataCmd, IOATAStandardCommand *, nextCommand );
80 }
81
82 void IOATAStandardDevice::moveCommand( queue_head_t *fromList, queue_head_t *toList, IOATAStandardCommand *ataCmd, IOReturn rc = kIOReturnSuccess )
83 {
84 if ( rc != kIOReturnSuccess )
85 {
86 if ( ataCmd->results.returnCode == kIOReturnSuccess )
87 {
88 ataCmd->results.returnCode = (IOReturn) rc;
89 }
90 }
91
92 ataCmd->list = toList;
93
94 queue_remove( fromList, ataCmd, IOATAStandardCommand *, nextCommand );
95 queue_enter( toList, ataCmd, IOATAStandardCommand *, nextCommand );
96 }
97
98 void IOATAStandardDevice::moveAllCommands( queue_head_t *fromList, queue_head_t *toList, IOReturn rc = kIOReturnSuccess )
99 {
100 IOATAStandardCommand *ataCmd;
101
102 if ( queue_empty( fromList ) == true ) return;
103
104 do
105 {
106 ataCmd = (IOATAStandardCommand *)queue_first( fromList );
107
108 if ( rc != kIOReturnSuccess )
109 {
110 if ( ataCmd->results.returnCode == kIOReturnSuccess )
111 {
112 ataCmd->results.returnCode = (IOReturn) rc;
113 }
114 }
115
116 ataCmd->list = toList;
117
118 queue_remove( fromList, ataCmd, IOATAStandardCommand *, nextCommand );
119 queue_enter( toList, ataCmd, IOATAStandardCommand *, nextCommand );
120
121 } while( queue_empty( fromList ) == false );
122 }
123
124 bool IOATAStandardDevice::findCommand( queue_head_t *list, IOATAStandardCommand *findATACmd )
125 {
126 IOATAStandardCommand *ataCmd;
127
128 queue_iterate( list, ataCmd, IOATAStandardCommand *, nextCommand )
129 {
130 if ( ataCmd == findATACmd )
131 {
132 return true;
133 }
134 }
135 return false;
136 }
137
138 void IOATAStandardDevice::purgeAllCommands( queue_head_t *list, IOReturn rc )
139 {
140 IOATAStandardCommand *ataCmd;
141
142 if ( queue_empty( list ) == true ) return;
143
144 do
145 {
146 ataCmd = (IOATAStandardCommand *)queue_first( list );
147
148 deleteCommand( list, ataCmd, rc );
149 finishCommand( ataCmd );
150
151 } while( queue_empty( list ) == false );
152 }