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@
25 * This class implements SCSI CDROM functionality.
27 * Subclasses may modify the operations to handle device-specific variations.
30 #ifndef _IOSCSICDDRIVE_H
31 #define _IOSCSICDDRIVE_H
33 #include <IOKit/IOTypes.h>
34 #include <IOKit/scsi/IOSCSIDeviceInterface.h>
35 #include <IOKit/storage/IOCDTypes.h>
36 #include <IOKit/storage/scsi/IOSCSIHDDrive.h>
38 /* SCSI (inquiry) device type. */
41 kIOSCSIDeviceTypeCDROM
= 0x05
47 kIOSCSICommandReadSubChannel
= 0x42,
48 kIOSCSICommandReadTOC
= 0x43,
49 kIOSCSICommandPlayAudioMSF
= 0x47,
50 kIOSCSICommandPauseResume
= 0x4b,
51 kIOSCSICommandStopPlay
= 0x4e,
52 kIOSCSICommandScan
= 0xba,
53 kIOSCSICommandReadCD
= 0xbe
56 struct IOAudioPlayMSFcdb
{
72 static const UInt8 kMSF
= 0x02; /* set to get mm:ss:ff format, else logical addr */
77 UInt8 start_trk_session
; /* starting track/session number */
80 UInt8 ctlbyte
; /* and format code */
81 static const UInt8 kTOC
= 0x00;
82 static const UInt8 kSessionInfo
= 0x01;
83 static const UInt8 kFullTOC
= 0x02;
89 static const UInt8 kMSF
= 0x02; /* set to get mm:ss:ff format, else logical addr */
91 static const UInt8 kSubq
= 0x40; /* set to get subq data */
93 static const UInt8 kCurrentPosition
= 1;
94 static const UInt8 kMCN
= 2;
95 static const UInt8 kISRC
= 3;
105 * @class IOSCSICDDrive : public IOSCSIHDDrive
107 * Driver for SCSI CD-ROM drives.
109 * IOSCSICDDrive is a subclass of IOSCSIHDDrive. It adds appropriate CD-ROM
110 * APIs (e.g. audio), and overrides some methods of IOSCSIHDDrive in order
111 * to alter their behavior for CD-ROM devices.
113 /*------------------------------------------------*/
114 class IOSCSICDDrive
: public IOSCSIHDDrive
{
116 OSDeclareDefaultStructors(IOSCSICDDrive
)
120 /* Overrides from IOService: */
122 virtual bool init(OSDictionary
* properties
);
124 /* Overrides from IOBasicSCSI: */
127 * @function deviceTypeMatches
129 * Determine if the device type matches that which we expect.
131 * This override allows us to check for the SCSI CD-ROM
132 * device type instead of hard disk.
133 * See IOBasicSCSI for details.
135 virtual bool deviceTypeMatches(UInt8 inqBuf
[],UInt32 inqLen
,SInt32
*score
);
137 /* End of IOBasicSCSI overrides */
139 /* IOSCSIHDDrive overrides: */
142 * @function doAsyncReadWrite
144 * Start an asynchronous read or write operation.
146 * See IOBlockStorageDevice for details.
148 virtual IOReturn
doAsyncReadWrite(IOMemoryDescriptor
*buffer
,
149 UInt32 block
,UInt32 nblks
,
150 IOStorageCompletion completion
);
153 * @function doSyncReadWrite
155 * Perform a synchronous read or write operation.
157 * See IOBlockStorageDevice for details.
159 virtual IOReturn
doSyncReadWrite(IOMemoryDescriptor
*buffer
,UInt32 block
,UInt32 nblks
);
162 * @function doFormatMedia
164 * Attempt to format the media.
166 * This override allows us to reject formatting attempts for CD-ROM.
168 virtual IOReturn
doFormatMedia(UInt64 byteCapacity
);
171 * @function doGetFormatCapacities
173 * Report available formatting capacities for the device/media.
175 * This override allows us to reject formatting attempts for CD-ROM.
177 virtual UInt32
doGetFormatCapacities(UInt64
* capacities
,
178 UInt32 capacitiesMaxCount
) const;
181 * @function doSynchronizeCache
183 * Issue a synchronize-cache command when finished with a drive.
185 * This override allows us to reject the operation, since we never write to CD-ROM.
187 virtual IOReturn
doSynchronizeCache(void);
190 * @function getDeviceTypeName
192 * Return a character string for the device type.
194 * This override returns kIOBlockStorageDeviceTypeCDROM.
196 virtual const char * getDeviceTypeName(void);
198 * @function instantiateNub
200 * Create the device nub.
202 * This override instantiates an IOSCSICDDriveNub instead of an IOSCSIHDDriveNub.
204 virtual IOService
* instantiateNub(void);
206 /* We want to track media changes to do cleanup. */
208 * @function reportMediaState
210 * Report the device's media state.
212 * This override allows us to reset device settings when media changes.
214 virtual IOReturn
reportMediaState(bool *mediaPresent
,bool *changed
);
216 /* end of IOSCSIHDDrive overrides */
218 /*-----------------------------------------*/
220 /*-----------------------------------------*/
224 * Start an asynchronous read CD operation.
226 * An IOMemoryDescriptor describing the data-transfer buffer. Responsiblity for releasing the descriptor
227 * rests with the caller.
229 * The starting M:S:F address of the data transfer.
231 * The ending M:S:F address of the data transfer.
233 * Sector area(s) to read.
235 * Sector type that is expected. The data transfer is terminated as soon as
236 * data is encountered that does not match the expected type.
238 * The C function called upon completion of the data transfer.
240 * The C++ class "this" pointer, passed as an argument to "action."
242 * This value is passed as an argument to "action." It is not validated or modified.
245 virtual IOReturn
doAsyncReadCD(IOMemoryDescriptor
*buffer
,
246 UInt32 block
,UInt32 nblks
,
247 CDSectorArea sectorArea
,
248 CDSectorType sectorType
,
249 IOStorageCompletion completion
);
254 * Read the International Standard Recording Code for the specified track.
256 * The track number from which to read the ISRC.
258 * The buffer for the ISRC data. Buffer contents will be zero-terminated.
260 virtual IOReturn
readISRC(UInt8 track
,CDISRC isrc
);
265 * Read the Media Catalog Number (also known as the Universal Product Code).
267 * The buffer for the MCN data. Buffer contents will be zero-terminated.
269 virtual IOReturn
readMCN(CDMCN mcn
);
274 * Read the full Table Of Contents.
276 * The buffer for the returned data.
278 virtual IOReturn
readTOC(IOMemoryDescriptor
* buffer
);
281 * @function reportMaxWriteTransfer
283 * Report the maximum allowed byte transfer for write operations.
285 * This override lets us return zero for the max write transfer, since
286 * we never write to CD-ROM media. See IOBasicSCSI for other details.
288 virtual IOReturn
reportMaxWriteTransfer(UInt64 blockSize
,UInt64
*max
);
291 * @function reportWriteProtection
293 * Report whether the media is write-protected or not.
295 * This override lets us return TRUE in all cases. See IOBasicSCSI for details.
297 virtual IOReturn
reportWriteProtection(bool *isWriteProtected
);
299 /*-----------------------------------------*/
300 /* APIs exported by IOCDAudioControl */
301 /*-----------------------------------------*/
304 * @function audioPause
306 * Pause or resume the audio playback.
308 * True to pause playback; False to resume.
310 virtual IOReturn
audioPause(bool pause
);
312 * @function audioPlay
316 * The M:S:F address from which to begin.
318 * The M:S:F address at which to stop.
320 virtual IOReturn
audioPlay(CDMSF timeStart
,CDMSF timeStop
);
322 * @function audioScan
324 * Perform a fast-forward or fast-backward operation.
326 * The M:S:F address from which to begin.
328 * True to go backward; False to go forward.
330 virtual IOReturn
audioScan(CDMSF timeStart
,bool reverse
);
332 * @function audioStop
334 * Stop the audio playback (or audio scan).
336 virtual IOReturn
audioStop();
338 * @function getAudioStatus
340 * Get the current audio play status information.
342 * The buffer for the returned information.
344 virtual IOReturn
getAudioStatus(CDAudioStatus
*status
);
346 * @function getAudioVolume
348 * Get the current audio volume.
350 * A pointer to the returned left-channel volume.
352 * A pointer to the returned right-channel volume.
354 virtual IOReturn
getAudioVolume(UInt8
*leftVolume
,UInt8
*rightVolume
);
356 * @function setAudioVolume
358 * Set the current audio volume.
360 * The desired left-channel volume.
362 * The desired right-channel volume.
364 virtual IOReturn
setAudioVolume(UInt8 leftVolume
,UInt8 rightVolume
);
368 /* Internally used methods: */
371 * @function doAudioPlayCommand
373 * Issue an audio play command to the device.
375 * The M:S:F address from which to begin.
377 * The M:S:F address at which to stop.
379 virtual IOReturn
doAudioPlayCommand(CDMSF timeStart
,CDMSF timeStop
);
382 * @function mediaArrived
384 * React to new media arrival.
386 virtual void mediaArrived(void);
389 * @function mediaGone
391 * React to media going away.
393 virtual void mediaGone(void);
396 * @function readSubChannel
398 * Issue the command necessary to read subchannel data.
400 * The buffer for the data.
402 * The maximum data length desired.
404 * The subchannel data desired.
406 * The desired track from which to read the data
408 virtual IOReturn
readSubChannel(UInt8
*buffer
,UInt32 length
,UInt8 dataFormat
,UInt8 trackNumber
);