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@
23 #include <IOKit/assert.h>
24 #include <IOKit/storage/ata/IOATAPICDDrive.h>
26 //---------------------------------------------------------------------------
27 // ATAPI Read TOC command (43).
30 IOATAPICDDrive::atapiCommandReadTOC(IOMemoryDescriptor
* buffer
,
33 UInt8 startTrackSession
)
39 // Create the ATAPI packet.
41 bzero(&atapiCmd
, sizeof(atapiCmd
));
43 atapiCmd
.cdbLength
= 12;
44 atapiCmd
.cdb
[0] = kIOATAPICommandReadTOC
;
45 atapiCmd
.cdb
[1] = msf
? 0x02 : 0x00;
46 atapiCmd
.cdb
[6] = startTrackSession
;
47 atapiCmd
.cdb
[7] = (UInt8
)(buffer
->getLength() >> 8);
48 atapiCmd
.cdb
[8] = (UInt8
)(buffer
->getLength());
51 atapiCmd
.cdb
[2] = (format
& 0x07); // new format field
53 atapiCmd
.cdb
[9] = (format
& 0x03) << 6; // old format field
55 return atapiCommand(&atapiCmd
, buffer
);
58 //---------------------------------------------------------------------------
59 // atapiCommandPlayAudioMSF
62 IOATAPICDDrive::atapiCommandPlayAudioMSF(CDMSF timeStart
, CDMSF timeStop
)
66 bzero(&atapiCmd
, sizeof(atapiCmd
));
67 atapiCmd
.cdbLength
= 12;
69 atapiCmd
.cdb
[0] = kIOATAPICommandPlayAudioMSF
;
71 // starting MSF address
72 atapiCmd
.cdb
[3] = timeStart
.minute
;
73 atapiCmd
.cdb
[4] = timeStart
.second
;
74 atapiCmd
.cdb
[5] = timeStart
.frame
;
77 atapiCmd
.cdb
[6] = timeStop
.minute
;
78 atapiCmd
.cdb
[7] = timeStop
.second
;
79 atapiCmd
.cdb
[8] = timeStop
.frame
;
81 return atapiCommand(&atapiCmd
);
84 //---------------------------------------------------------------------------
85 // atapiCommandPauseResume
88 IOATAPICDDrive::atapiCommandPauseResume(bool resume
)
92 bzero(&atapiCmd
, sizeof(atapiCmd
));
93 atapiCmd
.cdbLength
= 12;
95 atapiCmd
.cdb
[0] = kIOATAPICommandPauseResume
;
98 if (resume
) atapiCmd
.cdb
[8] = 0x01;
100 return atapiCommand(&atapiCmd
);
103 //---------------------------------------------------------------------------
104 // atapiCommandStopPlay
107 IOATAPICDDrive::atapiCommandStopPlay()
111 bzero(&atapiCmd
, sizeof(atapiCmd
));
113 atapiCmd
.cdbLength
= 12;
114 atapiCmd
.cdb
[0] = kIOATAPICommandStopPlay
;
116 return atapiCommand(&atapiCmd
);
119 //---------------------------------------------------------------------------
120 // atapiCommandReadSubChannel
123 IOATAPICDDrive::atapiCommandReadSubChannel(IOMemoryDescriptor
* buffer
,
131 bzero(&atapiCmd
, sizeof(atapiCmd
));
133 atapiCmd
.cdbLength
= 12;
134 atapiCmd
.cdb
[0] = kIOATAPICommandReadSubChannel
;
135 atapiCmd
.cdb
[1] = 0x02;
136 atapiCmd
.cdb
[2] = 0x40;
137 atapiCmd
.cdb
[3] = dataFormat
;
138 atapiCmd
.cdb
[6] = trackNumber
;
139 atapiCmd
.cdb
[7] = (buffer
->getLength() >> 8) & 0xff;
140 atapiCmd
.cdb
[8] = buffer
->getLength() & 0xff;
142 return atapiCommand(&atapiCmd
, buffer
);
145 //---------------------------------------------------------------------------
149 IOATAPICDDrive::atapiCommandScan(CDMSF timeStart
, bool reverse
)
153 bzero(&atapiCmd
, sizeof(atapiCmd
));
155 atapiCmd
.cdbLength
= 12;
156 atapiCmd
.cdb
[0] = kIOATAPICommandScan
;
157 atapiCmd
.cdb
[1] = reverse
? 0x10 : 0x00;
158 atapiCmd
.cdb
[3] = timeStart
.minute
;
159 atapiCmd
.cdb
[4] = timeStart
.second
;
160 atapiCmd
.cdb
[5] = timeStart
.frame
;
161 atapiCmd
.cdb
[9] = 0x40; // MSF
163 return atapiCommand(&atapiCmd
);
166 //---------------------------------------------------------------------------
167 // Allocates and return an IOATACommand to perform a read/write operation.
170 IOATAPICDDrive::atapiCommandReadCD(IOMemoryDescriptor
* buffer
,
173 CDSectorArea sectorArea
,
174 CDSectorType sectorType
)
180 bzero(&atapiCmd
, sizeof(atapiCmd
));
182 atapiCmd
.cdbLength
= 12;
183 atapiCmd
.cdb
[ 0] = kIOATAPICommandReadCD
;
184 atapiCmd
.cdb
[ 1] = (sectorType
& 0x7) << 2;
185 atapiCmd
.cdb
[ 2] = (block
>> 24) & 0xFF;
186 atapiCmd
.cdb
[ 3] = (block
>> 16) & 0xFF;
187 atapiCmd
.cdb
[ 4] = (block
>> 8) & 0xFF;
188 atapiCmd
.cdb
[ 5] = (block
) & 0xFF;
189 atapiCmd
.cdb
[ 6] = (nblks
>> 16) & 0xFF;
190 atapiCmd
.cdb
[ 7] = (nblks
>> 8) & 0xFF;
191 atapiCmd
.cdb
[ 8] = (nblks
) & 0xFF;
192 atapiCmd
.cdb
[ 9] = (sectorArea
& ~kCDSectorAreaSubChannel
);
193 atapiCmd
.cdb
[10] = (sectorArea
& kCDSectorAreaSubChannel
);
195 return atapiCommand(&atapiCmd
, buffer
);