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@
24 @header IOATACommand_Reference.h
26 This header defines the IOATACommand class.
28 This class encapsulates an ATA/ATAPI Command. The client driver allocates a
29 command using IOATADevice::allocCommand() and initializes it using
30 functions of this class. The client can then submit the command to
31 the ATA/ATAPI stack by invoking the execute() function.
37 The ATATaskfile structure provides information to be read/written into an IOATACommand. This
38 information includes the ATA taskfile register settings and the protocol the transport driver
39 is to use when the corresponding IOATACommand is executed.
41 Indicates the type of protocol the ATA Controller driver is to use when executing this command.
42 See enum ATAProtocol in IOATADevice_Reference for allowable values for this field.
44 Indicates whether an ATA command requires a tag. This field is only used when the protocol
45 selected for the command supports the Overlap feature set.
47 This field is set by the IOATAController class to tell the host
48 adapter driver the tag value to assign to this IOATACommand.
50 This field is set by the IOATADevice client and is a bit mask indicating the registers to be
51 returned when the IOATACommand completes. Clients should use ATARegToMask() convert ATA register
52 index values to bit mask values.
54 This field is set by the IOATADevice client and is a bit mask indicating the registers to be written
55 when an IOATACommand is executed. Clients should use ATARegToMask() convert ATA register
56 index values to bit mask values.
58 This array contains the ATA taskfile register values to be written when an IOATACommand is executed.
59 The index values for ATA taskfile registers is specified by enum ATARegs.
61 typedef struct ATATaskfile
{
73 UInt32 ataRegs
[kMaxATARegs
];
80 The ATACDBInfo structure provides cdb information to be read/written into an IOATACommand.
82 Indicates flags to applicable to the CDB to be executed. There are currently no flags defined for
85 Set by the IOATADevice client to the length of the Command Descriptor
88 Set by the IOATADevice client to command descriptor block the client
89 wishes the ATAPI device to execute.
91 typedef struct ATACDBInfo
{
105 The ATAResults structure provides completion information for an IOATACommand.
107 The overall return code for the command. See iokit/iokit/IOReturn.h.
108 This value is also returned as the getResults() return value.
109 @field bytesTransferred
110 The total number of bytes transferred to/from the ATA device.
111 Note: Some ATA controllers are not capable of returning accurate byte counts when
112 operating in bus-master mode. Clients should use some caution in interpreting the
113 contents of this field.
115 This field contains the low-level ATA Controller status for a completed IOATACommand.
116 Values for this field are defined by enum ATAReturnCode.
117 @field requestSenseDone
118 A boolean indicating whether sense data was obtained from the ATAPI
120 @field requestSenseLength
121 The number of sense data bytes returned from the ATAPI device.
123 This array contains the ATA taskfile register values to be returned when an IOATACommand completes.
124 The index values for ATA taskfile registers is specified by enum ATARegs. Registers to be returned
125 are indicated by the bit mask resultmask. See structure ATATaskfile.
127 typedef struct ATAResults
{
131 UInt32 bytesTransferred
;
133 ATAReturnCode adapterStatus
;
135 bool requestSenseDone
;
136 UInt32 requestSenseLength
;
138 UInt32 ataRegs
[kMaxATARegs
];
146 class IOATACommand
: public IOCDBCommand
152 @function setPointers
154 Sets the data buffer component of an ATA/ATAPI Command.
156 The client provides an IOMemoryDescriptor object to corresponding
157 to the client's data or request sense buffer, the maximum data transfer count
158 and data transfer direction.
160 Pointer to a IOMemoryDescriptor describing the client's I/O buffer.
162 Maximum data transfer count in bytes.
164 Data transfer direction. (Defined with respect to the device, i.e. isWrite = true
165 indicates the host is writing to the device.
167 If isSense is set to false, the IOATACommand's data buffer information is set. If isSense is
168 set to true, the IOATACommand's request sense buffer information is set.
170 void setPointers( IOMemoryDescriptor
*desc
,
171 UInt32 transferCount
,
173 bool isSense
= false );
175 @function getPointers
177 Gets the data buffer component of an ATA/ATAPI Command.
179 The client provides a set of pointers to fields to receive the IOATACommand's
180 data/request sense buffer pointers.
182 Pointer to a field (IOMemoryDescriptor *) to receive the IOATACommand's IOMemoryDescriptor pointer.
184 Pointer to a field (UInt32) to receive the IOATACommand's maximum transfer count.
186 Pointer to a field (bool) to receive the IOATACommand's transfer direction.
188 If isSense is set to true, the IOATACommand's data buffer information is returned. Otherwise,
189 the IOATACommand's request sense buffer information is returned.
191 void getPointers( IOMemoryDescriptor
**desc
,
192 UInt32
*transferCount
,
194 bool isSense
= false );
198 Sets the timeout for the command in milliseconds.
200 The IOATAController class will abort a command which does not
201 complete with in the time interval specified. The client should
202 set the timeout parameter to zero if they want to suppress
205 Command timeout in milliseconds.
207 void setTimeout( UInt32 timeoutmS
);
212 Gets the timeout for the command in milliseconds.
214 This function returns the command timeout previously set by setTimeout().
216 Command timeout in milliseconds.
221 @function setCallback
223 Sets the callback routine to be invoked when the ATA/ATAPI Command completes.
225 Pointer to the object to be passed to the callback routine. This would usually
226 be the client's (this) pointer.
228 Pointer to the client's function to process the completed command
230 Pointer to the information required by the client's callback routine to process
231 the completed command.
233 void setCallback( void *target
= 0, CallbackFn callback
= 0, void *refcon
= 0 );
238 Submits a ATA/ATAPI command to be executed.
240 Once the execute() function is called, the client should not
241 invoke any further functions on the ATA/ATAPI Command with the
242 exception of abort().
244 The execute() function optionally returns sets a unique sequence
245 number token for the command. If the client intends to use the abort()
246 method they must retain this sequence number token.
247 @param sequenceNumber
248 Pointer to field (UInt32) to receive the sequence number assigned to the ATA/ATAPI
251 bool execute( UInt32
*sequenceNumber
= 0 );
256 Aborts an executing ATA/ATAPI Command.
258 The client may invoke the abort() method to force the completion of an
259 executing ATA/ATAPI Command. The client must pass the sequence number
260 provided when the execute() function was invoked.
262 Note: The abort function provides no status on whether or not a
263 command has been successfully aborted. The client should wait for the
264 command to actually complete to determine whether the abort completed
266 @param sequenceNumber
267 The client must pass the sequence number assigned to the command when
268 the client called the execute() function.
270 void abort( UInt32 sequenceNumber
);
275 Indicates the IOATAController subclass (host adapter driver) has completed an ATA/ATAPI command.
277 Once the complete() function is called, the controller
278 subclass should make no further accesses to the IOATACommand
281 A IOATADevice client would not normally call this function.
286 @function getClientData
288 Returns a pointer to the ATA/ATAPI Command's client data area.
290 The client may allocate storage in the ATA/ATAPI Command for its own use.
291 See IOATADevice::allocateCmd().
293 void *getClientData();
296 @function getCommandData
298 Returns a pointer to the ATA Command's controller data area
300 This area is allocated for use by the IOATAController subclass (host adapter
301 driver). The client should not normally access this area.
304 void *getCommandData();
307 @function getSequenceNumber
309 Returns the sequence number assigned to an executing command.
311 The caller should check the sequence number for 0. This indicates that
312 the command has completed or has not been processed to the point where
313 a sequence number has been assigned.
315 UInt32
getSequenceNumber();
318 @function setTaskfile
320 Sets the ATA taskfile register information and ATA/ATAPI protocol for the IOATACommand.
322 See struct ATATaskfile additional information.
324 Pointer to an ATATaskfile structure.
326 void setTaskfile( ATATaskfile
*taskfile
);
329 @function getTaskfile
331 Sets the ATA taskfile register information and ATA/ATAPI protocol for the IOATACommand.
333 Pointer to an ATATaskfile structure.
335 void getTaskfile( ATATaskfile
*taskfile
);
338 @function getProtocol
340 Returns the protocol specified for the ATA/ATAPI Command.
342 The protocol returned is specified by the client in the ATATaskfile structure. See setTaskfile().
343 This function is normally used by subclasses of IOATAController to obtain information about the
344 ATA command being executed.
346 ATAProtocol
getProtocol();
349 @function getResultMask
351 Returns the resultMask specified for the ATA/ATAPI Command.
353 The resultMask is specified by the client in the ATATaskfile structure and indicates the ATA taskfile registers
354 to be returned when the ATA/ATAPI command completes. See setTaskfile(). This function is normally used by
355 subclasses of IOATAController to obtain information about the ATA command being executed.
357 UInt32
getResultMask();
362 Returns the flags specified for the ATA/ATAPI Command.
364 The flags are specified by the client in the ATATaskfile structure. See setTaskfile(). This function is
365 normally used by subclasses of IOATAController to obtain information about the ATA command being executed.
372 Sets the CDB component of a ATA/ATAPI Command.
374 Pointer to a ATACDBInfo structure.
376 void setCDB( ATACDBInfo
*ataCmd
);
381 Gets the CDB component of a ATA/ATAPI Command.
383 Pointer to an ATACDBInfo structure to receive the ATA/ATAPI Command's cdb information.
386 void getCDB( ATACDBInfo
*ataCmd
);
391 Gets results from a completed ATA/ATAPI Command.
393 The getResults() function returns the value of the returnCode field of the command results. If
394 the client is only interested in a pass/fail indication for the command, the client
395 can pass (ATAResults *)0 as a parameter.
397 Pointer to a ATAResults structure to receive the ATA/ATAPI Command's completion information.
399 IOReturn
getResults( ATAResults
*results
);
404 Sets the results component of a ATA/ATAPI Command.
406 The setResults() function is used by the IOATAController subclass (host
407 adapter driver) return results for a ATA/ATAPI Command about to be completed.
408 @param ataResults Pointer to a ATAResults structure containing
409 completion information for the ATA/ATAPI Command.
411 Completion information is copied into the command, so the caller may
412 release the ATAResults structure provided when this function returns.
414 void setResults( ATAResults
*results
);
419 Returns the IOATADevice this command is targeted to.
421 The caller should use value kIOATADeviceType.
423 In some cases a IOATACommand is not associated with a specific ATA Unit. This
424 would be the case for a ATA Bus Reset. In this case getDevice() returns 0.
426 IOATADevice
*getDevice( IOATAStandardDevice
*deviceType
);
431 Returns the unit number for the IOATADevice this command is associated with.
436 @function setQueueInfo
438 Sets queuing information for the ATA/ATAPI Command.
440 Each IOATADevice has two queues, a normal Q and a bypass Q. The treatment of the
441 queues is essentially identical except that the bypass Q is given preference whenever
442 it has commands available.
444 Usually, the client will use the normal Q for regular I/O commands and the bypass Q
445 to send error recovery commands to the device.
447 Set to kATAQTypeNormalQ or kATAQTypeBypassQ to indicate which IOATADevice queue the
448 ATA/ATAPI Command should be routed to.
450 Set to kATAQPositionTail or kATAQPositionHead to indicate whether the ATA/ATAPI Command should
451 be added to the head to tail for the selected IOATADevice queue.
453 void setQueueInfo( UInt32 forQueueType
= kATAQTypeNormalQ
, UInt32 forQueuePosition
= kATAQPositionTail
);
456 @function getQueueInfo
458 Gets queuing information for the ATA Command.
460 Pointer to a field (UInt32) to receive the queue type previously set for this ATA Command.
462 Pointer to a field (UInt32) to receive the queue position previously set for this ATA Command.
464 void getQueueInfo( UInt32
*forQueueType
, UInt32
*forQueuePosition
= 0 );
469 Obtains the underlying 'intent' of an ATA/ATAPI Command.
471 This function provides information on the intent of a ATA/ATAPI
472 Command. For example, since Aborts, Request Sense and normal Execute commands are
473 all sent to the executeCommand() function, invoking getCmdType()
474 will indicate whether a Request Sense, Abort or Normal I/O request is
477 This information is not normally meaningful to IOATADevice clients.
482 @function getOriginalCmd
484 Obtains a 'related' ATA/ATAPI Command.
486 In cases where a ATA command is related to a previous command, this
487 function will return the original command. For example, if a
488 Request Sense command (CmdType = kATACommandReqSense)is processed,
489 then this function can be used to obtain the original command that
490 caused the check condition. If an Abort command (CmdType =
491 kATACommandAbort) then this function can be used to obtain the original
492 command the abort was issued against.
494 It this information is not normally meaningful to IOATADevice clients.
497 IOATAStandardCommand
*getOriginalCmd();