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 * IOBlockStorageDevice.h
25 * This class is the protocol for generic block storage functionality, independent
26 * of the physical connection protocol (e.g. SCSI, ATA, USB).
28 * A subclass implements relay methods that translate our requests into
29 * calls to a protocol- and device-specific provider.
32 /*! @language embedded-c++ */
34 #ifndef _IOBLOCKSTORAGEDEVICE_H
35 #define _IOBLOCKSTORAGEDEVICE_H
37 #include <IOKit/IOMessage.h>
38 #include <IOKit/IOTypes.h>
39 #include <IOKit/IOService.h>
40 #include <IOKit/storage/IOMedia.h>
43 * @defined kIOMessageMediaStateHasChanged
44 * The message ID which indicates that the media state has changed. The message
45 * is passed to all clients of the IOBlockStorageDevice via the message() method.
46 * The argument that is passed along with this message is an IOMediaState value.
48 * Devices that aren't capable of detecting media state changes indicate this in
49 * the reportPollRequirements() method.
51 #define kIOMessageMediaStateHasChanged iokit_family_msg(sub_iokit_block_storage, 1)
53 /* Property used for matching, so the generic driver gets the nub it wants. */
55 * @defined kIOBlockStorageDeviceTypeKey
56 * The name of the property tested for nub type matching by the generic block
59 #define kIOBlockStorageDeviceTypeKey "device-type"
61 * @defined kIOBlockStorageDeviceTypeGeneric
62 * A character string used for nub matching.
64 #define kIOBlockStorageDeviceTypeGeneric "Generic"
66 class IOMemoryDescriptor
;
70 * IOBlockStorageDevice : public IOService
72 * "Impedance-matcher" class to connect Generic device driver to Transport Driver.
74 * The IOBlockStorageDevice class exports the generic block storage protocol,
75 * forwarding all requests to its provider (the Transport Driver).
76 * Though the nub does no actual processing of requests, it is necessary
77 * in a C++ environment. The Transport Driver can be of any type, as
78 * long as it inherits from IOService. Because Transport Drivers needn't
79 * derive from a type known to IOBlockStorageDriver, it isn't possible for
80 * IOBlockStorageDriver to include the appropriate header file to allow direct
81 * communication with the Transport Driver. Thus we achieve polymorphism by
82 * having the Transport Driver instantiate a subclass of IOBlockStorageDevice.
83 * A typical implementation for a concrete subclass of IOBlockStorageDevice
84 * simply relays all methods to its provider (the Transport Driver).
86 * All pure-virtual functions must be implemented by the Transport Driver, which
87 * is responsible for instantiating the Nub.
90 class IOBlockStorageDevice
: public IOService
{
92 OSDeclareAbstractStructors(IOBlockStorageDevice
)
96 struct ExpansionData
{ /* */ };
97 ExpansionData
* _expansionData
;
101 /* Overrides from IORegistryEntry */
106 * This function is overridden so that IOBlockStorageDevice can set a
107 * property, used by IOBlockStorageDriver for matching. Since the concrete
108 * subclass of IOBlockStorageDevice can be of any class type, the property
109 * is used for matching.
111 * This function is usually not overridden by developers.
113 virtual bool init(OSDictionary
* properties
);
115 /* --- A subclass must implement the the following methods: --- */
118 * @function doAsyncReadWrite
120 * Start an asynchronous read or write operation.
122 * An IOMemoryDescriptor describing the data-transfer buffer. The data direction
123 * is contained in the IOMemoryDescriptor. Responsiblity for releasing the descriptor
124 * rests with the caller.
126 * The starting block number of the data transfer.
128 * The integral number of blocks to be transferred.
130 * The completion routine to call once the data transfer is complete.
133 virtual IOReturn
doAsyncReadWrite(IOMemoryDescriptor
*buffer
,
134 UInt32 block
,UInt32 nblks
,
135 IOStorageCompletion completion
) = 0;
138 * @function doSyncReadWrite
140 * Perform a synchronous read or write operation.
142 * An IOMemoryDescriptor describing the data-transfer buffer. The data direction
143 * is contained in the IOMemoryDescriptor. Responsiblity for releasing the descriptor
144 * rests with the caller.
146 * The starting block number of the data transfer.
148 * The integral number of blocks to be transferred.
150 virtual IOReturn
doSyncReadWrite(IOMemoryDescriptor
*buffer
,
151 UInt32 block
,UInt32 nblks
) = 0;
154 * @function doEjectMedia
158 virtual IOReturn
doEjectMedia(void) = 0;
161 * @function doFormatMedia
163 * Format the media to the specified byte capacity.
165 * The specified byte capacity must be one supported by the device.
166 * Supported capacities can be obtained by calling doGetFormatCapacities.
167 * @param byteCapacity
168 * The byte capacity to which the device is to be formatted, if possible.
170 virtual IOReturn
doFormatMedia(UInt64 byteCapacity
) = 0;
173 * @function doGetFormatCapacities
175 * Return the allowable formatting byte capacities.
177 * This function returns the supported byte capacities for the device.
179 * Pointer for returning the list of capacities.
180 * @param capacitiesMaxCount
181 * The number of capacity values returned in "capacities."
183 virtual UInt32
doGetFormatCapacities(UInt64
* capacities
,
184 UInt32 capacitiesMaxCount
) const = 0;
187 * @function doLockUnlockMedia
189 * Lock or unlock the (removable) media in the drive.
191 * This method should only be called if the media is known to be removable.
193 * True to lock the media, False to unlock.
195 virtual IOReturn
doLockUnlockMedia(bool doLock
) = 0;
198 * @function doSynchronizeCache
200 * Force data blocks in the hardware's buffer to be flushed to the media.
202 * This method should only be called if the media is writable.
204 virtual IOReturn
doSynchronizeCache(void) = 0;
207 * @function getVendorString
209 * Return Vendor Name string for the device.
211 * A pointer to a static character string.
213 virtual char * getVendorString(void) = 0;
216 * @function getProductString
218 * Return Product Name string for the device.
220 * A pointer to a static character string.
222 virtual char * getProductString(void) = 0;
225 * @function getRevisionString
227 * Return Product Revision string for the device.
229 * A pointer to a static character string.
231 virtual char * getRevisionString(void) = 0;
234 * @function getAdditionalDeviceInfoString
236 * Return additional informational string for the device.
238 * A pointer to a static character string.
240 virtual char * getAdditionalDeviceInfoString(void) = 0;
243 * @function reportBlockSize
245 * Report the block size for the device, in bytes.
247 * Pointer to returned block size value.
249 virtual IOReturn
reportBlockSize(UInt64
*blockSize
) = 0;
252 * @function reportEjectability
254 * Report if the media is ejectable under software control.
256 * This method should only be called if the media is known to be removable.
258 * Pointer to returned result. True indicates the media is ejectable, False indicates
259 * the media cannot be ejected under software control.
261 virtual IOReturn
reportEjectability(bool *isEjectable
) = 0;
264 * @function reportLockability
266 * Report if the media is lockable under software control.
268 * This method should only be called if the media is known to be removable.
270 * Pointer to returned result. True indicates the media can be locked in place; False
271 * indicates the media cannot be locked by software.
273 virtual IOReturn
reportLockability(bool *isLockable
) = 0;
276 * @function reportMaxReadTransfer
278 * Report the maximum allowed byte transfer for read operations.
280 * Some devices impose a maximum data transfer size. Because this limit
281 * may be determined by the size of a block-count field in a command, the limit may
282 * depend on the block size of the transfer.
284 * The block size desired for the transfer.
286 * Pointer to returned result.
288 virtual IOReturn
reportMaxReadTransfer (UInt64 blockSize
,UInt64
*max
) = 0;
291 * @function reportMaxWriteTransfer
293 * Report the maximum allowed byte transfer for write operations.
295 * Some devices impose a maximum data transfer size. Because this limit
296 * may be determined by the size of a block-count field in a command, the limit may
297 * depend on the block size of the transfer.
299 * The block size desired for the transfer.
301 * Pointer to returned result.
303 virtual IOReturn
reportMaxWriteTransfer(UInt64 blockSize
,UInt64
*max
) = 0;
306 * @function reportMaxValidBlock
308 * Report the highest valid block for the device.
310 * Pointer to returned result
312 virtual IOReturn
reportMaxValidBlock(UInt64
*maxBlock
) = 0;
315 * @function reportMediaState
317 * Report the device's media state.
319 * This method reports whether we have media in the drive or not, and
320 * whether the state has changed from the previously reported state.
322 * A result of kIOReturnSuccess is always returned if the test for media is successful,
323 * regardless of media presence. The mediaPresent result should be used to determine
324 * whether media is present or not. A return other than kIOReturnSuccess indicates that
325 * the Transport Driver was unable to interrogate the device. In this error case, the
326 * outputs mediaState and changedState will *not* be stored.
327 * @param mediaPresent Pointer to returned media state. True indicates media is present
328 * in the device; False indicates no media is present.
329 * @param changedState Pointer to returned result. True indicates a change of state since
330 * prior calls, False indicates that the state has not changed.
332 virtual IOReturn
reportMediaState(bool *mediaPresent
,bool *changedState
) = 0;
335 * @function reportPollRequirements
337 * Report if it's necessary to poll for media insertion, and if polling is expensive.
339 * This method reports whether the device must be polled to detect media
340 * insertion, and whether a poll is expensive to perform.
342 * The term "expensive" typically implies a device that must be spun-up to detect media,
343 * as on a PC floppy. Most devices can detect media inexpensively.
344 * @param pollRequired
345 * Pointer to returned result. True indicates that polling is required; False indicates
346 * that polling is not required to detect media.
347 * @param pollIsExpensive
348 * Pointer to returned result. True indicates that the polling operation is expensive;
349 * False indicates that the polling operation is cheap.
351 virtual IOReturn
reportPollRequirements(bool *pollRequired
,
352 bool *pollIsExpensive
) = 0;
355 * @function reportRemovability
357 * Report whether the media is removable or not.
359 * This method reports whether the media is removable, but it does not
360 * provide detailed information regarding software eject or lock/unlock capability.
362 * Pointer to returned result. True indicates that the media is removable; False
363 * indicates the media is not removable.
365 virtual IOReturn
reportRemovability(bool *isRemovable
) = 0;
368 * @function reportWriteProtection
370 * Report whether the media is write-protected or not.
371 * @param isWriteProtected
372 * Pointer to returned result. True indicates that the media is write-protected (it
373 * cannot be written); False indicates that the media is not write-protected (it
374 * is permissible to write).
376 virtual IOReturn
reportWriteProtection(bool *isWriteProtected
) = 0;
378 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 0);
379 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 1);
380 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 2);
381 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 3);
382 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 4);
383 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 5);
384 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 6);
385 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 7);
386 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 8);
387 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 9);
388 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 10);
389 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 11);
390 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 12);
391 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 13);
392 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 14);
393 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 15);
394 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 16);
395 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 17);
396 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 18);
397 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 19);
398 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 20);
399 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 21);
400 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 22);
401 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 23);
402 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 24);
403 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 25);
404 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 26);
405 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 27);
406 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 28);
407 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 29);
408 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 30);
409 OSMetaClassDeclareReservedUnused(IOBlockStorageDevice
, 31);