1/* 2 * Copyright (c) 1998-2012 Apple Inc. All rights reserved. 3 * 4 * @APPLE_LICENSE_HEADER_START@ 5 * 6 * This file contains Original Code and/or Modifications of Original Code 7 * as defined in and that are subject to the Apple Public Source License 8 * Version 2.0 (the 'License'). You may not use this file except in 9 * compliance with the License. Please obtain a copy of the License at 10 * http://www.opensource.apple.com/apsl/ and read it before using this 11 * file. 12 * 13 * The Original Code and all software distributed under the License are 14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, 16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 18 * Please see the License for the specific language governing rights and 19 * limitations under the License. 20 * 21 * @APPLE_LICENSE_HEADER_END@ 22 */ 23/* 24 * IOCDBlockStorageDriver.h 25 * 26 * This class implements CD functionality, independent of 27 * the physical connection protocol (e.g. SCSI, ATA, USB). 28 * 29 * A protocol-specific provider implements the functionality using an appropriate 30 * protocol and commands. 31 */ 32 33#ifndef _IOCDBLOCKSTORAGEDRIVER_H 34#define _IOCDBLOCKSTORAGEDRIVER_H 35 36#include <IOKit/IOTypes.h> 37#include <IOKit/storage/IOCDBlockStorageDevice.h> 38#include <IOKit/storage/IOCDTypes.h> 39#include <IOKit/storage/IOBlockStorageDriver.h> 40 41/* 42 * @defined kIOCDBlockStorageDriverClass 43 * @abstract 44 * kIOCDBlockStorageDriverClass is the name of the IOCDBlockStorageDriver class. 45 * @discussion 46 * kIOCDBlockStorageDriverClass is the name of the IOCDBlockStorageDriver class. 47 */ 48 49#define kIOCDBlockStorageDriverClass "IOCDBlockStorageDriver" 50 51class IOCDBlockStorageDriver : public IOBlockStorageDriver { 52 53 OSDeclareDefaultStructors(IOCDBlockStorageDriver) 54 55public: 56 57 static const UInt64 kBlockSizeCD = 2352; 58 static const UInt8 kBlockTypeCD = 0x01; 59 60 /* Overrides of IORegistryEntry */ 61 62 virtual bool init(OSDictionary * properties); 63 virtual void free(void); 64 65 /* Overrides of IOBlockStorageDriver: */ 66 67 virtual IOReturn ejectMedia(void); 68 virtual void executeRequest(UInt64 byteStart, 69 IOMemoryDescriptor *buffer, 70#ifdef __LP64__ 71 IOStorageAttributes *attributes, 72 IOStorageCompletion *completion, 73#else /* !__LP64__ */ 74 IOStorageCompletion completion, 75#endif /* !__LP64__ */ 76 Context *context); 77 virtual const char * getDeviceTypeName(void); 78 virtual IOMedia * instantiateDesiredMediaObject(void); 79 virtual IOMedia * instantiateMediaObject(UInt64 base,UInt64 byteSize, 80 UInt32 blockSize,char *mediaName); 81 virtual IOReturn recordMediaParameters(void); 82 83 /* End of IOBlockStorageDriver overrides. */ 84 85 /* 86 * @function getMediaType 87 * @abstract 88 * Get the current type of media inserted in the CD drive. 89 * @discussion 90 * Certain I/O operations may not be allowed depending on the type of 91 * media currently inserted. For example, one cannot issue write operations 92 * if CD-ROM media is inserted. 93 * @result 94 * See the kCDMediaType constants in IOCDTypes.h. 95 */ 96 virtual UInt32 getMediaType(void); 97 98 /* -------------------------------------------------*/ 99 /* APIs implemented here, exported by IOCDMedia: */ 100 /* -------------------------------------------------*/ 101 102 virtual CDTOC * getTOC(void); 103 virtual void readCD(IOService *client, 104 UInt64 byteStart, 105 IOMemoryDescriptor *buffer, 106 CDSectorArea sectorArea, 107 CDSectorType sectorType, 108#ifdef __LP64__ 109 IOStorageAttributes *attributes, 110 IOStorageCompletion *completion); 111#else /* !__LP64__ */ 112 IOStorageCompletion completion); 113#endif /* !__LP64__ */ 114 virtual IOReturn readISRC(UInt8 track,CDISRC isrc); 115 virtual IOReturn readMCN(CDMCN mcn); 116 117 /* end of IOCDMedia APIs */ 118 119#ifndef __LP64__ 120 /* --------------------------------------------------------*/ 121 /* APIs implemented here, exported by IOCDAudioControl: */ 122 /* --------------------------------------------------------*/ 123 124 virtual IOReturn audioPause(bool pause) __attribute__ ((deprecated)); 125 virtual IOReturn audioPlay(CDMSF timeStart,CDMSF timeStop) __attribute__ ((deprecated)); 126 virtual IOReturn audioScan(CDMSF timeStart,bool reverse) __attribute__ ((deprecated)); 127 virtual IOReturn audioStop() __attribute__ ((deprecated)); 128 virtual IOReturn getAudioStatus(CDAudioStatus *status) __attribute__ ((deprecated)); 129 virtual IOReturn getAudioVolume(UInt8 *leftVolume,UInt8 *rightVolume) __attribute__ ((deprecated)); 130 virtual IOReturn setAudioVolume(UInt8 leftVolume,UInt8 rightVolume) __attribute__ ((deprecated)); 131 132 /* end of IOCDAudioControl APIs */ 133#endif /* !__LP64__ */ 134 135 /* 136 * Obtain this object's provider. We override the superclass's method to 137 * return a more specific subclass of IOService -- IOCDBlockStorageDevice. 138 * This method serves simply as a convenience to subclass developers. 139 */ 140 141 virtual IOCDBlockStorageDevice * getProvider() const; 142 143protected: 144 145 /* Overrides of IOBlockStorageDriver behavior. */ 146 147 /* When CD media is inserted, we want to create multiple nubs for the data and 148 * audio tracks, for sessions, and the entire media. We override the methods 149 * that manage nubs. 150 */ 151 virtual IOReturn acceptNewMedia(void); 152 virtual IOReturn decommissionMedia(bool forcible); 153 154 /* End of IOBlockStorageDriver overrides. */ 155 156 /* Internally used methods: */ 157 158 using IOBlockStorageDriver::getMediaBlockSize; 159 160 virtual IOReturn cacheTocInfo(void); 161 virtual UInt64 getMediaBlockSize(CDSectorArea area,CDSectorType type); 162 virtual void prepareRequest(UInt64 byteStart, 163 IOMemoryDescriptor *buffer, 164 CDSectorArea sectorArea, 165 CDSectorType sectorType, 166#ifdef __LP64__ 167 IOStorageAttributes *attributes, 168 IOStorageCompletion *completion); 169#else /* !__LP64__ */ 170 IOStorageCompletion completion); 171#endif /* !__LP64__ */ 172 173 /* ------- */ 174 175 struct ExpansionData 176 { 177 UInt32 minBlockNumberAudio; 178 UInt32 maxBlockNumberAudio; 179 }; 180 ExpansionData * _expansionData; 181 182 #define _minBlockNumberAudio \ 183 IOCDBlockStorageDriver::_expansionData->minBlockNumberAudio 184 #define _maxBlockNumberAudio \ 185 IOCDBlockStorageDriver::_expansionData->maxBlockNumberAudio 186 187 UInt32 _reserved0032; 188 189 /* We keep the TOC here because we'll always need it, so what the heck. 190 * 191 * There are possible "point" track entries for 0xa0..a2, 0xb0..b4, and 0xc0..0xc1. 192 * Tracks need not start at 1, as long as they're between 1 and 99, and have contiguous 193 * numbers. 194 */ 195 196 CDTOC * _toc; 197 UInt32 _tocSize; 198 199 /* ------- */ 200 201 IOReturn reportDiscInfo(CDDiscInfo *discInfo); 202 IOReturn reportTrackInfo(UInt16 track,CDTrackInfo *trackInfo); 203 204public: 205 206 virtual IOReturn getSpeed(UInt16 * kilobytesPerSecond); /* 10.1.0 */ 207 208 virtual IOReturn setSpeed(UInt16 kilobytesPerSecond); /* 10.1.0 */ 209 210 virtual IOReturn readTOC(IOMemoryDescriptor *buffer,CDTOCFormat format, 211 UInt8 formatAsTime,UInt8 trackOrSessionNumber, 212 UInt16 *actualByteCount); /* 10.1.3 */ 213 214 virtual IOReturn readDiscInfo(IOMemoryDescriptor *buffer, 215 UInt16 *actualByteCount); /* 10.1.3 */ 216 217 virtual IOReturn readTrackInfo(IOMemoryDescriptor *buffer,UInt32 address, 218 CDTrackInfoAddressType addressType, 219 UInt16 *actualByteCount); /* 10.1.3 */ 220 221 virtual void writeCD(IOService *client, 222 UInt64 byteStart, 223 IOMemoryDescriptor *buffer, 224 CDSectorArea sectorArea, 225 CDSectorType sectorType, 226#ifdef __LP64__ 227 IOStorageAttributes *attributes, 228 IOStorageCompletion *completion); 229#else /* !__LP64__ */ 230 IOStorageCompletion completion); /* 10.2.0 */ 231#endif /* !__LP64__ */ 232 233#ifdef __LP64__ 234 OSMetaClassDeclareReservedUnused(IOCDBlockStorageDriver, 0); 235 OSMetaClassDeclareReservedUnused(IOCDBlockStorageDriver, 1); 236 OSMetaClassDeclareReservedUnused(IOCDBlockStorageDriver, 2); 237 OSMetaClassDeclareReservedUnused(IOCDBlockStorageDriver, 3); 238 OSMetaClassDeclareReservedUnused(IOCDBlockStorageDriver, 4); 239 OSMetaClassDeclareReservedUnused(IOCDBlockStorageDriver, 5); 240#else /* !__LP64__ */ 241 OSMetaClassDeclareReservedUsed(IOCDBlockStorageDriver, 0); 242 OSMetaClassDeclareReservedUsed(IOCDBlockStorageDriver, 1); 243 OSMetaClassDeclareReservedUsed(IOCDBlockStorageDriver, 2); 244 OSMetaClassDeclareReservedUsed(IOCDBlockStorageDriver, 3); 245 OSMetaClassDeclareReservedUsed(IOCDBlockStorageDriver, 4); 246 OSMetaClassDeclareReservedUsed(IOCDBlockStorageDriver, 5); 247#endif /* !__LP64__ */ 248 OSMetaClassDeclareReservedUnused(IOCDBlockStorageDriver, 6); 249 OSMetaClassDeclareReservedUnused(IOCDBlockStorageDriver, 7); 250 OSMetaClassDeclareReservedUnused(IOCDBlockStorageDriver, 8); 251 OSMetaClassDeclareReservedUnused(IOCDBlockStorageDriver, 9); 252 OSMetaClassDeclareReservedUnused(IOCDBlockStorageDriver, 10); 253 OSMetaClassDeclareReservedUnused(IOCDBlockStorageDriver, 11); 254 OSMetaClassDeclareReservedUnused(IOCDBlockStorageDriver, 12); 255 OSMetaClassDeclareReservedUnused(IOCDBlockStorageDriver, 13); 256 OSMetaClassDeclareReservedUnused(IOCDBlockStorageDriver, 14); 257 OSMetaClassDeclareReservedUnused(IOCDBlockStorageDriver, 15); 258}; 259#endif 260