]> git.saurik.com Git - apple/xnu.git/blame - iokit/IOKit/ata/IOATACommand_Reference.h
xnu-124.7.tar.gz
[apple/xnu.git] / iokit / IOKit / ata / IOATACommand_Reference.h
CommitLineData
1c79356b
A
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/*!
24@header IOATACommand_Reference.h
25
26This header defines the IOATACommand class.
27
28This class encapsulates an ATA/ATAPI Command. The client driver allocates a
29command using IOATADevice::allocCommand() and initializes it using
30functions of this class. The client can then submit the command to
31the ATA/ATAPI stack by invoking the execute() function.
32*/
33
34/*!
35@typedef ATATaskfile
36@discussion
37The ATATaskfile structure provides information to be read/written into an IOATACommand. This
38information includes the ATA taskfile register settings and the protocol the transport driver
39is to use when the corresponding IOATACommand is executed.
40@field protocol
41Indicates the type of protocol the ATA Controller driver is to use when executing this command.
42See enum ATAProtocol in IOATADevice_Reference for allowable values for this field.
43@field tagType
44Indicates whether an ATA command requires a tag. This field is only used when the protocol
45selected for the command supports the Overlap feature set.
46@field tag
47This field is set by the IOATAController class to tell the host
48adapter driver the tag value to assign to this IOATACommand.
49@field resultmask
50This field is set by the IOATADevice client and is a bit mask indicating the registers to be
51returned when the IOATACommand completes. Clients should use ATARegToMask() convert ATA register
52index values to bit mask values.
53@field regmask
54This field is set by the IOATADevice client and is a bit mask indicating the registers to be written
55when an IOATACommand is executed. Clients should use ATARegToMask() convert ATA register
56index values to bit mask values.
57@field ataRegs
58This array contains the ATA taskfile register values to be written when an IOATACommand is executed.
59The index values for ATA taskfile registers is specified by enum ATARegs.
60*/
61typedef struct ATATaskfile {
62
63 ATAProtocol protocol;
64
65 UInt32 flags;
66
67 UInt8 tagType;
68 UInt32 tag;
69
70 UInt32 resultmask;
71
72 UInt32 regmask;
73 UInt32 ataRegs[kMaxATARegs];
74
75} ATATaskfile;
76
77/*!
78@typedef ATACDBInfo
79@discussion
80The ATACDBInfo structure provides cdb information to be read/written into an IOATACommand.
81@field cdbFlags
82Indicates flags to applicable to the CDB to be executed. There are currently no flags defined for
83IOATADevice clients.
84@field cdbLength
85Set by the IOATADevice client to the length of the Command Descriptor
86Block (CDB).
87@field cdb
88Set by the IOATADevice client to command descriptor block the client
89wishes the ATAPI device to execute.
90*/
91typedef struct ATACDBInfo {
92
93 UInt32 cdbFlags;
94
95 UInt32 cdbLength;
96 UInt8 cdb[16];
97
98 UInt32 reserved[16];
99
100} ATACDBInfo;
101
102/*!
103@typedef ATAResults
104@discussion
105The ATAResults structure provides completion information for an IOATACommand.
106@field returnCode
107The overall return code for the command. See iokit/iokit/IOReturn.h.
108This value is also returned as the getResults() return value.
109@field bytesTransferred
110The total number of bytes transferred to/from the ATA device.
111Note: Some ATA controllers are not capable of returning accurate byte counts when
112operating in bus-master mode. Clients should use some caution in interpreting the
113contents of this field.
114@field adapterStatus
115This field contains the low-level ATA Controller status for a completed IOATACommand.
116Values for this field are defined by enum ATAReturnCode.
117@field requestSenseDone
118A boolean indicating whether sense data was obtained from the ATAPI
119device.
120@field requestSenseLength
121The number of sense data bytes returned from the ATAPI device.
122@field ataRegs
123This array contains the ATA taskfile register values to be returned when an IOATACommand completes.
124The index values for ATA taskfile registers is specified by enum ATARegs. Registers to be returned
125are indicated by the bit mask resultmask. See structure ATATaskfile.
126*/
127typedef struct ATAResults {
128
129 IOReturn returnCode;
130
131 UInt32 bytesTransferred;
132
133 ATAReturnCode adapterStatus;
134
135 bool requestSenseDone;
136 UInt32 requestSenseLength;
137
138 UInt32 ataRegs[kMaxATARegs];
139
140 UInt32 reserved[16];
141
142} ATAResults;
143
144
145
146class IOATACommand : public IOCDBCommand
147{
148public:
149
150
151/*!
152@function setPointers
153@abstract
154Sets the data buffer component of an ATA/ATAPI Command.
155@discussion
156The client provides an IOMemoryDescriptor object to corresponding
157to the client's data or request sense buffer, the maximum data transfer count
158and data transfer direction.
159@param desc
160Pointer to a IOMemoryDescriptor describing the client's I/O buffer.
161@param transferCount
162Maximum data transfer count in bytes.
163@param isWrite
164Data transfer direction. (Defined with respect to the device, i.e. isWrite = true
165indicates the host is writing to the device.
166@param isSense
167If isSense is set to false, the IOATACommand's data buffer information is set. If isSense is
168set to true, the IOATACommand's request sense buffer information is set.
169*/
170 void setPointers( IOMemoryDescriptor *desc,
171 UInt32 transferCount,
172 bool isWrite,
173 bool isSense = false );
174/*!
175@function getPointers
176@abstract
177Gets the data buffer component of an ATA/ATAPI Command.
178@discussion
179The client provides a set of pointers to fields to receive the IOATACommand's
180data/request sense buffer pointers.
181@param desc
182Pointer to a field (IOMemoryDescriptor *) to receive the IOATACommand's IOMemoryDescriptor pointer.
183@param transferCount
184Pointer to a field (UInt32) to receive the IOATACommand's maximum transfer count.
185@param isWrite
186Pointer to a field (bool) to receive the IOATACommand's transfer direction.
187@param isSense
188If isSense is set to true, the IOATACommand's data buffer information is returned. Otherwise,
189the IOATACommand's request sense buffer information is returned.
190*/
191 void getPointers( IOMemoryDescriptor **desc,
192 UInt32 *transferCount,
193 bool *isWrite,
194 bool isSense = false );
195/*!
196@function setTimeout
197@abstract
198Sets the timeout for the command in milliseconds.
199@discussion
200The IOATAController class will abort a command which does not
201complete with in the time interval specified. The client should
202set the timeout parameter to zero if they want to suppress
203timing.
204@param timeout
205Command timeout in milliseconds.
206*/
207 void setTimeout( UInt32 timeoutmS );
208
209/*!
210@function getTimeout
211@abstract
212Gets the timeout for the command in milliseconds.
213@discussion
214This function returns the command timeout previously set by setTimeout().
215@param timeout
216Command timeout in milliseconds.
217*/
218 UInt32 getTimeout();
219
220/*!
221@function setCallback
222@abstract
223Sets the callback routine to be invoked when the ATA/ATAPI Command completes.
224@param target
225Pointer to the object to be passed to the callback routine. This would usually
226be the client's (this) pointer.
227@param callback
228Pointer to the client's function to process the completed command
229@param refcon
230Pointer to the information required by the client's callback routine to process
231the completed command.
232*/
233 void setCallback( void *target = 0, CallbackFn callback = 0, void *refcon = 0 );
234
235/*!
236@function execute
237@abstract
238Submits a ATA/ATAPI command to be executed.
239@discussion
240Once the execute() function is called, the client should not
241invoke any further functions on the ATA/ATAPI Command with the
242exception of abort().
243
244The execute() function optionally returns sets a unique sequence
245number token for the command. If the client intends to use the abort()
246method they must retain this sequence number token.
247@param sequenceNumber
248Pointer to field (UInt32) to receive the sequence number assigned to the ATA/ATAPI
249Command.
250*/
251 bool execute( UInt32 *sequenceNumber = 0 );
252
253/*!
254@function abort
255@abstract
256Aborts an executing ATA/ATAPI Command.
257@discussion
258The client may invoke the abort() method to force the completion of an
259executing ATA/ATAPI Command. The client must pass the sequence number
260provided when the execute() function was invoked.
261
262Note: The abort function provides no status on whether or not a
263command has been successfully aborted. The client should wait for the
264command to actually complete to determine whether the abort completed
265successfully.
266@param sequenceNumber
267The client must pass the sequence number assigned to the command when
268the client called the execute() function.
269*/
270 void abort( UInt32 sequenceNumber );
271
272/*!
273@function complete
274@abstract
275Indicates the IOATAController subclass (host adapter driver) has completed an ATA/ATAPI command.
276@discussion
277Once the complete() function is called, the controller
278subclass should make no further accesses to the IOATACommand
279being completed.
280
281A IOATADevice client would not normally call this function.
282*/
283 void complete();
284
285/*!
286@function getClientData
287@abstract
288Returns a pointer to the ATA/ATAPI Command's client data area.
289@discussion
290The client may allocate storage in the ATA/ATAPI Command for its own use.
291See IOATADevice::allocateCmd().
292*/
293 void *getClientData();
294
295/*
296@function getCommandData
297@abstract
298Returns a pointer to the ATA Command's controller data area
299@discussion
300This area is allocated for use by the IOATAController subclass (host adapter
301driver). The client should not normally access this area.
302*/
303
304 void *getCommandData();
305
306/*!
307@function getSequenceNumber
308@abstract
309Returns the sequence number assigned to an executing command.
310@discussion
311The caller should check the sequence number for 0. This indicates that
312the command has completed or has not been processed to the point where
313a sequence number has been assigned.
314*/
315 UInt32 getSequenceNumber();
316
317/*!
318@function setTaskfile
319@abstract
320Sets the ATA taskfile register information and ATA/ATAPI protocol for the IOATACommand.
321@discussion
322See struct ATATaskfile additional information.
323@param ATATaskfile
324Pointer to an ATATaskfile structure.
325*/
326 void setTaskfile( ATATaskfile *taskfile );
327
328/*!
329@function getTaskfile
330@abstract
331Sets the ATA taskfile register information and ATA/ATAPI protocol for the IOATACommand.
332@param ATATaskfile
333Pointer to an ATATaskfile structure.
334*/
335 void getTaskfile( ATATaskfile *taskfile );
336
337/*!
338@function getProtocol
339@abstract
340Returns the protocol specified for the ATA/ATAPI Command.
341@discussion
342The protocol returned is specified by the client in the ATATaskfile structure. See setTaskfile().
343This function is normally used by subclasses of IOATAController to obtain information about the
344ATA command being executed.
345*/
346 ATAProtocol getProtocol();
347
348/*!
349@function getResultMask
350@abstract
351Returns the resultMask specified for the ATA/ATAPI Command.
352@discussion
353The resultMask is specified by the client in the ATATaskfile structure and indicates the ATA taskfile registers
354to be returned when the ATA/ATAPI command completes. See setTaskfile(). This function is normally used by
355subclasses of IOATAController to obtain information about the ATA command being executed.
356*/
357 UInt32 getResultMask();
358
359/*!
360@function getFlags
361@abstract
362Returns the flags specified for the ATA/ATAPI Command.
363@discussion
364The flags are specified by the client in the ATATaskfile structure. See setTaskfile(). This function is
365normally used by subclasses of IOATAController to obtain information about the ATA command being executed.
366*/
367 UInt32 getFlags();
368
369/*!
370@function setCDB
371@abstract
372Sets the CDB component of a ATA/ATAPI Command.
373@param ataCDB
374Pointer to a ATACDBInfo structure.
375*/
376 void setCDB( ATACDBInfo *ataCmd );
377
378/*!
379@function getCDB
380@abstract
381Gets the CDB component of a ATA/ATAPI Command.
382@param ataCDB
383Pointer to an ATACDBInfo structure to receive the ATA/ATAPI Command's cdb information.
384*/
385
386 void getCDB( ATACDBInfo *ataCmd );
387
388/*!
389@function getResults
390@abstract
391Gets results from a completed ATA/ATAPI Command.
392@discussion
393The getResults() function returns the value of the returnCode field of the command results. If
394the client is only interested in a pass/fail indication for the command, the client
395can pass (ATAResults *)0 as a parameter.
396@param results
397Pointer to a ATAResults structure to receive the ATA/ATAPI Command's completion information.
398*/
399 IOReturn getResults( ATAResults *results );
400
401/*!
402@function setResults
403@abstract
404Sets the results component of a ATA/ATAPI Command.
405@discussion
406The setResults() function is used by the IOATAController subclass (host
407adapter driver) return results for a ATA/ATAPI Command about to be completed.
408@param ataResults Pointer to a ATAResults structure containing
409completion information for the ATA/ATAPI Command.
410
411Completion information is copied into the command, so the caller may
412release the ATAResults structure provided when this function returns.
413*/
414 void setResults( ATAResults *results );
415
416/*!
417@function getDevice
418@abstract
419Returns the IOATADevice this command is targeted to.
420@param deviceType
421The caller should use value kIOATADeviceType.
422@discussion
423In some cases a IOATACommand is not associated with a specific ATA Unit. This
424would be the case for a ATA Bus Reset. In this case getDevice() returns 0.
425*/
426 IOATADevice *getDevice( IOATAStandardDevice *deviceType );
427
428/*!
429@function getUnit
430@abstract
431Returns the unit number for the IOATADevice this command is associated with.
432*/
433 ATAUnit getUnit();
434
435/*!
436@function setQueueInfo
437@abstract
438Sets queuing information for the ATA/ATAPI Command.
439@discussion
440Each IOATADevice has two queues, a normal Q and a bypass Q. The treatment of the
441queues is essentially identical except that the bypass Q is given preference whenever
442it has commands available.
443
444Usually, the client will use the normal Q for regular I/O commands and the bypass Q
445to send error recovery commands to the device.
446@param queueType
447Set to kATAQTypeNormalQ or kATAQTypeBypassQ to indicate which IOATADevice queue the
448ATA/ATAPI Command should be routed to.
449@param queuePosition
450Set to kATAQPositionTail or kATAQPositionHead to indicate whether the ATA/ATAPI Command should
451be added to the head to tail for the selected IOATADevice queue.
452*/
453 void setQueueInfo( UInt32 forQueueType = kATAQTypeNormalQ, UInt32 forQueuePosition = kATAQPositionTail );
454
455/*!
456@function getQueueInfo
457@abstract
458Gets queuing information for the ATA Command.
459@param queueType
460Pointer to a field (UInt32) to receive the queue type previously set for this ATA Command.
461@param queuePosition
462Pointer to a field (UInt32) to receive the queue position previously set for this ATA Command.
463*/
464 void getQueueInfo( UInt32 *forQueueType, UInt32 *forQueuePosition = 0 );
465
466/*!
467@function getCmdType
468@abstract
469Obtains the underlying 'intent' of an ATA/ATAPI Command.
470@discussion
471This function provides information on the intent of a ATA/ATAPI
472Command. For example, since Aborts, Request Sense and normal Execute commands are
473all sent to the executeCommand() function, invoking getCmdType()
474will indicate whether a Request Sense, Abort or Normal I/O request is
475being processed.
476
477This information is not normally meaningful to IOATADevice clients.
478*/
479 UInt32 getCmdType();
480
481/*!
482@function getOriginalCmd
483@abstract
484Obtains a 'related' ATA/ATAPI Command.
485@discussion
486In cases where a ATA command is related to a previous command, this
487function will return the original command. For example, if a
488Request Sense command (CmdType = kATACommandReqSense)is processed,
489then this function can be used to obtain the original command that
490caused the check condition. If an Abort command (CmdType =
491kATACommandAbort) then this function can be used to obtain the original
492command the abort was issued against.
493
494It this information is not normally meaningful to IOATADevice clients.
495*/
496
497 IOATAStandardCommand *getOriginalCmd();
498
499};
500