]> git.saurik.com Git - apple/xnu.git/blob - iokit/Families/IOATAPICDDrive/IOATAPICDCommand.cpp
xnu-124.13.tar.gz
[apple/xnu.git] / iokit / Families / IOATAPICDDrive / IOATAPICDCommand.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 #include <IOKit/assert.h>
24 #include <IOKit/storage/ata/IOATAPICDDrive.h>
25
26 //---------------------------------------------------------------------------
27 // ATAPI Read TOC command (43).
28
29 IOATACommand *
30 IOATAPICDDrive::atapiCommandReadTOC(IOMemoryDescriptor * buffer,
31 bool msf,
32 UInt8 format,
33 UInt8 startTrackSession)
34 {
35 ATACDBInfo atapiCmd;
36
37 assert(buffer);
38
39 // Create the ATAPI packet.
40 //
41 bzero(&atapiCmd, sizeof(atapiCmd));
42
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());
49
50 if ((format & 0x04))
51 atapiCmd.cdb[2] = (format & 0x07); // new format field
52 else
53 atapiCmd.cdb[9] = (format & 0x03) << 6; // old format field
54
55 return atapiCommand(&atapiCmd, buffer);
56 }
57
58 //---------------------------------------------------------------------------
59 // atapiCommandPlayAudioMSF
60
61 IOATACommand *
62 IOATAPICDDrive::atapiCommandPlayAudioMSF(CDMSF timeStart, CDMSF timeStop)
63 {
64 ATACDBInfo atapiCmd;
65
66 bzero(&atapiCmd, sizeof(atapiCmd));
67 atapiCmd.cdbLength = 12;
68
69 atapiCmd.cdb[0] = kIOATAPICommandPlayAudioMSF;
70
71 // starting MSF address
72 atapiCmd.cdb[3] = timeStart.minute;
73 atapiCmd.cdb[4] = timeStart.second;
74 atapiCmd.cdb[5] = timeStart.frame;
75
76 // ending MSF address
77 atapiCmd.cdb[6] = timeStop.minute;
78 atapiCmd.cdb[7] = timeStop.second;
79 atapiCmd.cdb[8] = timeStop.frame;
80
81 return atapiCommand(&atapiCmd);
82 }
83
84 //---------------------------------------------------------------------------
85 // atapiCommandPauseResume
86
87 IOATACommand *
88 IOATAPICDDrive::atapiCommandPauseResume(bool resume)
89 {
90 ATACDBInfo atapiCmd;
91
92 bzero(&atapiCmd, sizeof(atapiCmd));
93 atapiCmd.cdbLength = 12;
94
95 atapiCmd.cdb[0] = kIOATAPICommandPauseResume;
96
97 // set resume bit
98 if (resume) atapiCmd.cdb[8] = 0x01;
99
100 return atapiCommand(&atapiCmd);
101 }
102
103 //---------------------------------------------------------------------------
104 // atapiCommandStopPlay
105
106 IOATACommand *
107 IOATAPICDDrive::atapiCommandStopPlay()
108 {
109 ATACDBInfo atapiCmd;
110
111 bzero(&atapiCmd, sizeof(atapiCmd));
112
113 atapiCmd.cdbLength = 12;
114 atapiCmd.cdb[0] = kIOATAPICommandStopPlay;
115
116 return atapiCommand(&atapiCmd);
117 }
118
119 //---------------------------------------------------------------------------
120 // atapiCommandReadSubChannel
121
122 IOATACommand *
123 IOATAPICDDrive::atapiCommandReadSubChannel(IOMemoryDescriptor * buffer,
124 UInt8 dataFormat,
125 UInt8 trackNumber)
126 {
127 ATACDBInfo atapiCmd;
128
129 assert(buffer);
130
131 bzero(&atapiCmd, sizeof(atapiCmd));
132
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;
141
142 return atapiCommand(&atapiCmd, buffer);
143 }
144
145 //---------------------------------------------------------------------------
146 // atapiCommandScan
147
148 IOATACommand *
149 IOATAPICDDrive::atapiCommandScan(CDMSF timeStart, bool reverse)
150 {
151 ATACDBInfo atapiCmd;
152
153 bzero(&atapiCmd, sizeof(atapiCmd));
154
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
162
163 return atapiCommand(&atapiCmd);
164 }
165
166 //---------------------------------------------------------------------------
167 // Allocates and return an IOATACommand to perform a read/write operation.
168
169 IOATACommand *
170 IOATAPICDDrive::atapiCommandReadCD(IOMemoryDescriptor * buffer,
171 UInt32 block,
172 UInt32 nblks,
173 CDSectorArea sectorArea,
174 CDSectorType sectorType)
175 {
176 ATACDBInfo atapiCmd;
177
178 assert(buffer);
179
180 bzero(&atapiCmd, sizeof(atapiCmd));
181
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);
194
195 return atapiCommand(&atapiCmd, buffer);
196 }