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 * IOATAStandardDevice.cpp
27 #include <IOKit/IOSyncer.h>
28 #include <IOKit/ata/IOATAStandardInterface.h>
29 #include <IOKit/ata/ata-standard/ATAStandardPrivate.h>
32 #define super IOATADevice
35 #define MIN(a,b) ((a <= b) ? a : b)
38 #define round(x,y) (((int)(x) + (y) - 1) & ~((y)-1))
40 extern EndianTable AppleIdentifyEndianTable
[];
42 extern UInt32 AppleNumPIOModes
;
43 extern ATAModeTable ApplePIOModes
[];
44 extern UInt32 AppleNumDMAModes
;
45 extern ATAModeTable AppleDMAModes
[];
46 extern UInt32 AppleNumUltraModes
;
47 extern ATAModeTable AppleUltraModes
[];
49 OSDefineMetaClassAndAbstractStructors( IOATADevice
, IOCDBDevice
)
50 OSDefineMetaClassAndStructors( IOATAStandardDevice
, IOATADevice
)
57 bool IOATAStandardDevice::init( IOATAStandardController
*forController
, ATAUnit forUnit
)
62 controller
= forController
;
65 target
= &controller
->targets
[unit
];
67 queue_init( &deviceList
);
68 queue_init( &bypassList
);
69 queue_init( &activeList
);
70 queue_init( &abortList
);
71 queue_init( &cancelList
);
73 clientSem
= IORWLockAlloc();
79 if ( super::init() == false )
84 if ( controller
->controllerInfo
.devicePrivateDataSize
!= 0 )
86 devicePrivateData
= IOMallocContiguous( controller
->controllerInfo
.devicePrivateDataSize
, 16, 0 );
87 if ( devicePrivateData
== 0 )
93 bzero( &ataCDB
, sizeof(ataCDB
) );
95 probeCmd
= allocCommand(kIOATAStandardDevice
, 0);
101 abortCmd
= allocCommand(kIOATAStandardDevice
, 0);
106 abortCmd
->setTimeout( kATAAbortTimeoutmS
);
108 cancelCmd
= allocCommand(kIOATAStandardDevice
, 0);
109 if ( cancelCmd
== 0 )
113 cancelCmd
->setTimeout( 0 );
114 cancelCmd
->cmdType
= kATACommandCancel
;
116 reqSenseCmd
= allocCommand(kIOATAStandardDevice
, 0);
117 if ( reqSenseCmd
== 0 )
122 bzero( &taskfile
, sizeof(taskfile
) );
123 taskfile
.protocol
= kATAProtocolATAPIPIO
;
124 taskfile
.tagType
= kATATagTypeNone
;
126 taskfile
.resultmask
= ATARegtoMask( kATARegStatus
);
128 taskfile
.regmask
= ATARegtoMask( kATARegATAPIFeatures
)
129 | ATARegtoMask( kATARegATAPIByteCountLow
)
130 | ATARegtoMask( kATARegATAPIByteCountHigh
)
131 | ATARegtoMask( kATARegATAPIDeviceSelect
)
132 | ATARegtoMask( kATARegATAPICommand
);
134 taskfile
.ataRegs
[kATARegATAPIFeatures
] = 0;
135 taskfile
.ataRegs
[kATARegATAPIByteCountLow
] = 0xfe;
136 taskfile
.ataRegs
[kATARegATAPIByteCountHigh
] = 0xff;
137 taskfile
.ataRegs
[kATARegATAPIDeviceSelect
] = kATAModeLBA
| (getUnit() << 4);
138 taskfile
.ataRegs
[kATARegATAPICommand
] = kATACommandATAPIPacket
;
140 reqSenseCmd
->setTaskfile( &taskfile
);
142 ataCDB
.cdbLength
= 12;
143 ataCDB
.cdb
[0] = kATAPICmdRequestSense
;
145 reqSenseCmd
->setTimeout( kATAReqSenseTimeoutmS
);
146 reqSenseCmd
->cmdType
= kATACommandReqSense
;
147 reqSenseCmd
->setCDB( &ataCDB
);
149 deviceGate
= IOCommandGate::commandGate( this, (IOCommandGate::Action
) &IOATAStandardDevice::receiveCommand
);
150 if ( deviceGate
== 0 )
155 if ( controller
->workLoop
->addEventSource( deviceGate
) != kIOReturnSuccess
)
160 commandLimitSave
= commandLimit
= 1;
162 idleNotifyActive
= false;
167 currentTiming
= kATATimingPIO
;
172 IOReturn
IOATAStandardDevice::probeDevice()
174 OSDictionary
*propTable
= 0;
176 if ( doIdentify( (void **)&identifyData
) != kIOReturnSuccess
)
178 goto probeDevice_error
;
181 if ( deviceType
== kATADeviceATA
)
186 else if ( deviceType
== kATADeviceATAPI
)
188 atapiPktInt
= ((identifyData
->generalConfiguration
& kATAPIPktProtocolIntDRQ
) != 0);
190 if ( doInquiry( (void **)&inquiryData
) != kIOReturnSuccess
)
192 goto probeDevice_error
;
196 if ( getATATimings() != true )
198 goto probeDevice_error
;
203 tagArraySize
= round( maxTags
, 32 ) / 8;
204 tagArray
= (UInt32
*)IOMalloc( tagArraySize
);
207 goto probeDevice_error
;
209 bzero( tagArray
, tagArraySize
);
212 propTable
= createProperties();
215 goto probeDevice_error
;
218 setPropertyTable( propTable
);
220 propTable
->release();
236 ATADeviceType
IOATAStandardDevice::probeDeviceType()
238 ATATaskfile taskfile
;
241 bzero( (void *)&taskfile
, sizeof(taskfile
) );
243 taskfile
.protocol
= kATAProtocolSetRegs
;
244 taskfile
.regmask
= ATARegtoMask(kATARegDriveHead
);
246 taskfile
.resultmask
= ATARegtoMask(kATARegSectorCount
)
247 | ATARegtoMask(kATARegSectorNumber
)
248 | ATARegtoMask(kATARegCylinderLow
)
249 | ATARegtoMask(kATARegCylinderHigh
)
250 | ATARegtoMask(kATARegStatus
);
252 taskfile
.flags
= kATACmdFlagTimingChanged
;
254 taskfile
.ataRegs
[kATARegDriveHead
] = kATAModeLBA
| (getUnit() << 4);
256 probeCmd
->setQueueInfo();
257 probeCmd
->setTaskfile( &taskfile
);
260 if ( probeCmd
->getResults( &results
) != kIOReturnSuccess
)
262 return (deviceType
= kATADeviceNone
);
265 if ( results
.ataRegs
[kATARegSectorCount
] == kATASignatureSectorCount
266 && results
.ataRegs
[kATARegSectorNumber
] == kATASignatureSectorNumber
267 && results
.ataRegs
[kATARegCylinderLow
] == kATASignatureCylinderLow
268 && results
.ataRegs
[kATARegCylinderHigh
] == kATASignatureCylinderHigh
)
270 if ( !(results
.ataRegs
[kATARegStatus
] & kATAStatusBSY
)
271 && (results
.ataRegs
[kATARegStatus
] & kATAStatusDRDY
) )
273 return (deviceType
= kATADeviceATA
);
277 if ( results
.ataRegs
[kATARegCylinderLow
] == kATAPISignatureCylinderLow
278 && results
.ataRegs
[kATARegCylinderHigh
] == kATAPISignatureCylinderHigh
)
280 return (deviceType
= kATADeviceATAPI
);
283 return (deviceType
= kATADeviceNone
);
292 IOReturn
IOATAStandardDevice::doSpinUp()
297 rc
= doSectorCommand( kATACommandReadSector
, 0, 1, &buffer
);
299 if ( rc
!= kIOReturnSuccess
)
304 IOFree( buffer
, 512 );
314 IOReturn
IOATAStandardDevice::doIdentify( void **dataPtr
)
319 ataCmd
= (deviceType
== kATADeviceATA
) ? kATACommandIdentify
: kATACommandATAPIIdentify
;
321 rc
= doSectorCommand( ataCmd
, 0, 1, dataPtr
);
323 if ( rc
!= kIOReturnSuccess
)
328 endianConvertData( *dataPtr
, AppleIdentifyEndianTable
);
340 IOReturn
IOATAStandardDevice::doSectorCommand( ATACommand ataCmd
, UInt32 ataLBA
, UInt32 ataCount
, void **dataPtr
)
342 ATATaskfile taskfile
;
344 IOMemoryDescriptor
*desc
;
352 size
= ataCount
* 512;
354 if ( !(data
= (void *)IOMalloc(size
)) )
356 return kIOReturnNoMemory
;
359 bzero( &taskfile
, sizeof(taskfile
) );
361 desc
= IOMemoryDescriptor::withAddress( data
, size
, kIODirectionIn
);
364 rc
= kIOReturnNoMemory
;
365 goto doSectorCommand_error
;
369 taskfile
.protocol
= kATAProtocolPIO
;
370 taskfile
.regmask
= ATARegtoMask(kATARegDriveHead
)
371 | ATARegtoMask(kATARegSectorCount
)
372 | ATARegtoMask(kATARegSectorNumber
)
373 | ATARegtoMask(kATARegCylinderLow
)
374 | ATARegtoMask(kATARegCylinderHigh
)
375 | ATARegtoMask(kATARegFeatures
)
376 | ATARegtoMask(kATARegCommand
);
379 taskfile
.resultmask
= ATARegtoMask(kATARegError
)
380 | ATARegtoMask(kATARegStatus
);
382 taskfile
.ataRegs
[kATARegSectorCount
] = ataCount
;
383 taskfile
.ataRegs
[kATARegSectorNumber
] = ataLBA
& 0xff;
384 taskfile
.ataRegs
[kATARegCylinderLow
] = (ataLBA
>> 8) & 0xff;
385 taskfile
.ataRegs
[kATARegCylinderHigh
] = (ataLBA
>> 16) & 0xff;
386 taskfile
.ataRegs
[kATARegDriveHead
] = (ataLBA
>> 24) & 0x0f;
388 taskfile
.ataRegs
[kATARegDriveHead
] |= kATAModeLBA
| (getUnit() << 4);
389 taskfile
.ataRegs
[kATARegCommand
] = ataCmd
;
391 probeCmd
->setQueueInfo();
393 for ( i
= 0; i
< 2; i
++ )
395 probeCmd
->setTimeout( 25000 );
396 probeCmd
->setTaskfile( &taskfile
);
397 probeCmd
->setPointers( desc
, size
, false );
400 rc
= probeCmd
->getResults( &result
);
401 if ( rc
== kIOReturnSuccess
)
408 doSectorCommand_error
: ;
412 if ( rc
!= kIOReturnSuccess
)
414 IOFree( data
, size
);
415 return result
.returnCode
;
420 return kIOReturnSuccess
;
428 IOReturn
IOATAStandardDevice::doInquiry( void **dataPtr
)
430 ATATaskfile taskfile
;
434 IOMemoryDescriptor
*desc
;
435 UInt32 size
= sizeof(ATAPIInquiry
);
439 if ( !(data
= (void *)IOMalloc(size
)) )
441 return kIOReturnNoMemory
;
445 bzero( &taskfile
, sizeof(taskfile
) );
446 bzero( &atapiCmd
, sizeof(atapiCmd
) );
448 desc
= IOMemoryDescriptor::withAddress( data
, size
, kIODirectionIn
);
450 taskfile
.protocol
= kATAProtocolATAPIPIO
;
451 taskfile
.regmask
= ATARegtoMask(kATARegATAPIDeviceSelect
)
452 | ATARegtoMask(kATARegATAPICommand
)
453 | ATARegtoMask(kATARegATAPIByteCountLow
)
454 | ATARegtoMask(kATARegATAPIByteCountHigh
)
455 | ATARegtoMask(kATARegATAPIFeatures
);
456 taskfile
.ataRegs
[kATARegATAPIDeviceSelect
] = kATAModeLBA
| (getUnit() << 4);
457 taskfile
.ataRegs
[kATARegATAPICommand
] = kATACommandATAPIPacket
;
458 taskfile
.ataRegs
[kATARegATAPIFeatures
] = 0;
459 taskfile
.ataRegs
[kATARegATAPIByteCountLow
] = 0xfe;
460 taskfile
.ataRegs
[kATARegATAPIByteCountHigh
] = 0xff;
462 atapiCmd
.cdbLength
= 12; // Fix 16 byte cmdpkts??
463 atapiCmd
.cdb
[0] = 0x12;
464 atapiCmd
.cdb
[4] = size
;
466 probeCmd
->setCDB( &atapiCmd
);
467 probeCmd
->setTaskfile( &taskfile
);
468 probeCmd
->setPointers( desc
, size
, false );
469 probeCmd
->setTimeout( 5000 );
470 probeCmd
->setQueueInfo();
473 if ( probeCmd
->getResults(&result
) == kIOReturnSuccess
)
477 else if ( ( result
.returnCode
== kIOReturnUnderrun
) &&
478 ( result
.bytesTransferred
>= 36 ) )
480 // The standard INQUIRY contain 36 required bytes,
481 // the rest is optional and vendor specific.
483 result
.returnCode
= kIOReturnSuccess
;
488 IOFree( data
, size
);
493 return result
.returnCode
;
500 bool IOATAStandardDevice::getDeviceCapacity( UInt32
*blockMax
, UInt32
*blockSize
)
505 if ( deviceType
== kATADeviceATA
)
507 if ( identifyData
!= NULL
)
509 *blockMax
= *(UInt32
*)identifyData
->userAddressableSectors
- 1;
515 if ( deviceType
== kATADeviceATAPI
)
517 for ( i
=0; i
< 8; i
++ )
519 if ( doTestUnitReady() == kIOReturnSuccess
)
525 if ( doReadCapacity( data
) == kIOReturnSuccess
)
527 *blockMax
= OSSwapBigToHostInt32( data
[0] );
528 *blockSize
= OSSwapBigToHostInt32( data
[1] );
537 IOReturn
IOATAStandardDevice::doTestUnitReady()
539 ATATaskfile taskfile
;
543 bzero( &taskfile
, sizeof(taskfile
) );
544 bzero( &atapiCmd
, sizeof(atapiCmd
) );
546 taskfile
.protocol
= kATAProtocolATAPIPIO
;
548 taskfile
.regmask
= ATARegtoMask(kATARegATAPIDeviceSelect
)
549 | ATARegtoMask(kATARegATAPICommand
)
550 | ATARegtoMask(kATARegATAPIByteCountLow
)
551 | ATARegtoMask(kATARegATAPIByteCountHigh
)
552 | ATARegtoMask(kATARegATAPIFeatures
);
554 taskfile
.ataRegs
[kATARegATAPIDeviceSelect
] = kATAModeLBA
| (getUnit() << 4);
555 taskfile
.ataRegs
[kATARegATAPICommand
] = kATACommandATAPIPacket
;
556 taskfile
.ataRegs
[kATARegATAPIFeatures
] = 0;
557 taskfile
.ataRegs
[kATARegATAPIByteCountLow
] = 0xfe;
558 taskfile
.ataRegs
[kATARegATAPIByteCountHigh
] = 0xff;
560 atapiCmd
.cdbLength
= 12; // Fix 16 byte cmdpkts??
561 atapiCmd
.cdb
[0] = 0x00;
563 probeCmd
->setCDB( &atapiCmd
);
564 probeCmd
->setTaskfile( &taskfile
);
565 probeCmd
->setPointers( (IOMemoryDescriptor
*)NULL
, 0, false );
566 probeCmd
->setTimeout( 5000 );
567 probeCmd
->setQueueInfo();
569 probeCmd
->getResults(&result
);
571 return result
.returnCode
;
579 IOReturn
IOATAStandardDevice::doReadCapacity( void *data
)
581 ATATaskfile taskfile
;
584 IOMemoryDescriptor
*dataDesc
;
588 bzero( &taskfile
, sizeof(taskfile
) );
589 bzero( &atapiCmd
, sizeof(atapiCmd
) );
591 dataDesc
= IOMemoryDescriptor::withAddress( data
, size
, kIODirectionIn
);
592 if ( dataDesc
== NULL
)
594 return kIOReturnNoMemory
;
597 taskfile
.protocol
= kATAProtocolATAPIPIO
;
598 taskfile
.regmask
= ATARegtoMask(kATARegATAPIDeviceSelect
)
599 | ATARegtoMask(kATARegATAPICommand
)
600 | ATARegtoMask(kATARegATAPIByteCountLow
)
601 | ATARegtoMask(kATARegATAPIByteCountHigh
)
602 | ATARegtoMask(kATARegATAPIFeatures
);
603 taskfile
.ataRegs
[kATARegATAPIDeviceSelect
] = kATAModeLBA
| (getUnit() << 4);
604 taskfile
.ataRegs
[kATARegATAPICommand
] = kATACommandATAPIPacket
;
605 taskfile
.ataRegs
[kATARegATAPIFeatures
] = 0;
606 taskfile
.ataRegs
[kATARegATAPIByteCountLow
] = 0xfe;
607 taskfile
.ataRegs
[kATARegATAPIByteCountHigh
] = 0xff;
609 atapiCmd
.cdbLength
= 12; // Fix 16 byte cmdpkts??
610 atapiCmd
.cdb
[0] = 0x25;
612 probeCmd
->setCDB( &atapiCmd
);
613 probeCmd
->setTaskfile( &taskfile
);
614 probeCmd
->setPointers( dataDesc
, size
, false );
615 probeCmd
->setTimeout( 5000 );
616 probeCmd
->setQueueInfo();
619 probeCmd
->getResults(&result
);
623 return result
.returnCode
;
630 bool IOATAStandardDevice::getTimingsSupported( ATATimingProtocol
*timingsSupported
)
634 *(UInt32
*)timingsSupported
= 0;
636 for ( i
=0; i
< numTimings
; i
++ )
638 *(UInt32
*) timingsSupported
|= (UInt32
)ataTimings
[i
].timingProtocol
;
648 bool IOATAStandardDevice::getTimingSelected( ATATimingProtocol
*timingSelected
)
650 *timingSelected
= currentTiming
;
658 bool IOATAStandardDevice::getProtocolsSupported( ATAProtocol
*forProtocolsSupported
)
660 *(UInt32
*)forProtocolsSupported
= protocolsSupported
;
668 bool IOATAStandardDevice::getTiming( ATATimingProtocol
*timingProtocol
, ATATiming
*timing
)
672 for ( i
=0; i
< numTimings
; i
++ )
674 if ( ataTimings
[i
].timingProtocol
== *timingProtocol
)
676 bcopy( &ataTimings
[i
], timing
, sizeof(ATATiming
) );
689 bool IOATAStandardDevice::selectTiming( ATATimingProtocol timingProtocol
, bool fNotifyMsg
)
691 ATATaskfile taskfile
;
694 IOATAStandardCommand
* ataCmd
;
696 for ( i
=0; i
< numTimings
; i
++ )
698 if ( ataTimings
[i
].timingProtocol
== timingProtocol
)
710 ataCmd
= allocCommand(kIOATAStandardDevice
, 0);
711 if ( ataCmd
== 0 ) return false;
713 currentTiming
= timingProtocol
;
715 bzero( &taskfile
, sizeof(taskfile
) );
717 taskfile
.protocol
= kATAProtocolPIO
;
718 taskfile
.regmask
= ATARegtoMask(kATARegFeatures
)
719 | ATARegtoMask(kATARegSectorCount
)
720 | ATARegtoMask(kATARegDriveHead
)
721 | ATARegtoMask(kATARegCommand
);
723 taskfile
.ataRegs
[kATARegSectorCount
] = ataTimings
[i
].featureSetting
;
724 taskfile
.ataRegs
[kATARegFeatures
] = kATAFeatureTransferMode
;
725 taskfile
.ataRegs
[kATARegDriveHead
] = kATAModeLBA
| (getUnit() << 4);
726 taskfile
.ataRegs
[kATARegCommand
] = kATACommandSetFeatures
;
728 taskfile
.flags
= kATACmdFlagTimingChanged
;
730 ataCmd
->setTaskfile( &taskfile
);
731 ataCmd
->setPointers( (IOMemoryDescriptor
*)NULL
, 0, false );
732 ataCmd
->setTimeout( 5000 );
733 ataCmd
->setQueueInfo( kATAQTypeBypassQ
);
735 if ( fNotifyMsg
== false )
737 ataCmd
->setCallback();
739 if ( ataCmd
->getResults( (ATAResults
*) 0 ) != kIOReturnSuccess
)
747 ataCmd
->setCallback( this, (CallbackFn
)&IOATAStandardDevice::selectTimingDone
, ataCmd
);
757 void IOATAStandardDevice::selectTimingDone( IOATAStandardCommand
*ataCmd
)
761 rc
= (ataCmd
->getResults( (ATAResults
*)0 ) == kIOReturnSuccess
);
763 client
->message( kATAClientMsgSelectTiming
| kATAClientMsgDone
, this, (void *)rc
);
772 bool IOATAStandardDevice::getATATimings()
776 UInt32 cycleTime
= 0;
780 if ( controller
->getProtocolsSupported( (ATAProtocol
*)&protocolsSupported
) == false )
785 pTimings
= ataTimings
;
788 * PIO Cycle timing......
790 * 1. Try to match Word 51 (pioCycleTime) with cycle timings
791 * in our pioModes table to get mode/CycleTime. (Valid for Modes 0-2)
792 * 2. If Words 64-68 are supported and Mode 3 or 4 supported check,
793 * update CycleTime with Word 68 (CycleTimeWithIORDY).
796 cycleTime
= identifyData
->pioMode
;
800 for ( i
=AppleNumPIOModes
-1; i
!= -1; i
-- )
802 if ( cycleTime
<= ApplePIOModes
[i
].minDataCycle
)
811 cycleTime
= ApplePIOModes
[mode
].minDataCycle
;
817 cycleTime
= ApplePIOModes
[mode
].minDataCycle
;
821 if ( identifyData
->validFields
& identifyWords_64to70_Valid
)
823 if (identifyData
->advancedPIOModes
& advPIOModes_Mode4_Supported
)
825 else if (identifyData
->advancedPIOModes
& advPIOModes_Mode3_Supported
)
828 if ( (mode
>= 3) && identifyData
->minPIOCyclcTimeIORDY
)
830 cycleTime
= identifyData
->minPIOCyclcTimeIORDY
;
834 pTimings
->timingProtocol
= kATATimingPIO
;
835 pTimings
->mode
= mode
;
836 pTimings
->featureSetting
= mode
| kATATransferModePIOwFC
;
837 pTimings
->minDataCycle
= cycleTime
;
838 pTimings
->minDataAccess
= ApplePIOModes
[mode
].minDataAccess
;
840 if ( ((protocolsSupported
& kATAProtocolPIO
) == 0)
841 || (controller
->calculateTiming( getUnit(), pTimings
) == false) )
843 IOLog("IOATAStandardDevice::%s() - Controller driver must support PIO protocol\n\r", __FUNCTION__
);
851 * Multiword DMA timing.....
853 * 1. Check Word 63(7:0) (Multiword DMA Modes Supported). Lookup
854 * CycleTime for highest mode we support.
855 * 2. If Words 64-68 supported, update CycleTime from Word 66
856 * (RecommendedMultiWordCycleTime) if specified.
859 n
= identifyData
->dmaModes
& dmaModes_Supported
;
862 for ( i
=0; n
; i
++, n
>>=1 )
866 if ( mode
> AppleNumDMAModes
-1 )
868 mode
= AppleNumDMAModes
-1;
870 cycleTime
= AppleDMAModes
[mode
].minDataCycle
;
872 if (identifyData
->validFields
& identifyWords_64to70_Valid
)
874 if ( identifyData
->recDMACycleTime
)
876 cycleTime
= identifyData
->recDMACycleTime
;
879 pTimings
->timingProtocol
= kATATimingDMA
;
880 pTimings
->mode
= mode
;
881 pTimings
->featureSetting
= mode
| kATATransferModeDMA
;
882 pTimings
->minDataCycle
= cycleTime
;
883 pTimings
->minDataAccess
= AppleDMAModes
[mode
].minDataAccess
;
885 if ( ((protocolsSupported
& kATAProtocolDMA
) != 0)
886 && (controller
->calculateTiming( getUnit(), pTimings
) == true) )
894 * Ultra DMA timing.....
897 if ( identifyData
->validFields
& identifyWords_88to88_Valid
)
899 n
= identifyData
->ultraDMAModes
& ultraDMAModes_Supported
;
902 for ( i
=0; n
; i
++, n
>>=1 )
906 if ( mode
> AppleNumUltraModes
-1 )
908 mode
= AppleNumUltraModes
-1;
912 * Build a separate timing entry for Ultra DMA/33 (mode <= 2) and Ultra DMA/66
916 cycleTime
= AppleUltraModes
[mode
].minDataCycle
;
918 pTimings
->timingProtocol
= (mode
> 2) ? kATATimingUltraDMA66
: kATATimingUltraDMA33
;
919 pTimings
->mode
= mode
;
920 pTimings
->featureSetting
= mode
| kATATransferModeUltraDMA33
;
921 pTimings
->minDataCycle
= cycleTime
;
922 pTimings
->minDataAccess
= AppleUltraModes
[mode
].minDataAccess
;
924 if ( ((protocolsSupported
& kATAProtocolDMA
) != 0)
925 && (controller
->calculateTiming( getUnit(), pTimings
) == true) )
931 if ( mode
< 3 ) break;
940 if ( deviceType
== kATADeviceATA
)
942 if ( ((identifyData
->commandSetsSupported2
& commandSetsSupported2_ValidMask
) == commandSetsSupported2_Valid
)
943 && ((identifyData
->commandSetsSupported3
& commandSetsSupported3_ValidMask
) == commandSetsSupported3_Valid
) )
945 if ( ((identifyData
->commandSetsSupported2
& commandSetsSupported2_DMAQueued
) != 0)
946 && ((identifyData
->commandSetsEnabled2
& commandSetsEnabled2_DMAQueued
) != 0) )
948 maxTags
= identifyData
->queueDepth
+ 1;
955 protocolsSupported
&= ~(kATAProtocolDMAQueued
| kATAProtocolDMAQueuedRelease
);
967 ATAUnit
IOATAStandardDevice::getUnit()
976 ATADeviceType
IOATAStandardDevice::getDeviceType()
985 bool IOATAStandardDevice::getATAPIPktInt()
994 bool IOATAStandardDevice::getIdentifyData( ATAIdentify
*identifyBuffer
)
996 if ( identifyData
== NULL
)
998 bzero( identifyBuffer
, sizeof(ATAIdentify
) );
1002 bcopy( identifyData
, identifyBuffer
, sizeof(ATAIdentify
) );
1010 bool IOATAStandardDevice::getInquiryData( UInt32 inquiryBufLength
, ATAPIInquiry
*inquiryBuffer
)
1012 bzero( inquiryBuffer
, inquiryBufLength
);
1014 if ( inquiryData
== NULL
)
1019 bcopy( inquiryData
, inquiryBuffer
, inquiryBufLength
);
1030 void IOATAStandardDevice::setupTarget()
1039 void IOATAStandardDevice::getInquiryData( void *clientBuf
, UInt32 clientBufSize
, UInt32
*clientDataSize
)
1043 bzero( clientBuf
, clientBufSize
);
1045 len
= MIN( clientBufSize
, inquiryDataSize
);
1047 bcopy( inquiryData
, clientBuf
, len
);
1049 *clientDataSize
= len
;
1057 void IOATAStandardDevice::abort()
1059 submitCommand( kATACommandAbortAll
, 0 );
1067 void IOATAStandardDevice::reset()
1069 submitCommand( kATACommandDeviceReset
, 0 );
1077 void IOATAStandardDevice::holdQueue( UInt32 queueType
)
1079 if ( getWorkLoop()->inGate() == false )
1081 IOPanic( "IOATAStandardDevice::holdQueue() - must be called from workloop!!\n\r");
1084 if ( queueType
== kATAQTypeBypassQ
)
1088 else if ( queueType
== kATAQTypeNormalQ
)
1099 void IOATAStandardDevice::releaseQueue( UInt32 queueType
)
1101 bool doDispatchRequest
= false;
1103 if ( getWorkLoop()->inGate() == false )
1105 IOPanic( "IOATAStandardDevice::releaseQueue() - must be called from workloop!!\n\r");
1108 if ( queueType
== kATAQTypeBypassQ
)
1110 if ( bypassQHeld
&& (--bypassQHeld
== 0) )
1111 doDispatchRequest
= true;
1113 else if ( queueType
== kATAQTypeNormalQ
)
1115 if ( normalQHeld
&& (--normalQHeld
== 0) )
1116 doDispatchRequest
= true;
1119 if ( doDispatchRequest
) dispatchRequest();
1127 void IOATAStandardDevice::notifyIdle( void *target
= 0, CallbackFn callback
= 0, void *refcon
= 0 )
1129 if ( getWorkLoop()->inGate() == false )
1131 IOPanic( "IOATAStandardDevice:::notifyIdle() - must be called from workloop!!\n\r");
1134 if ( callback
== 0 )
1136 idleNotifyActive
= false;
1140 if ( idleNotifyActive
== true )
1142 IOPanic( "IOATAStandardDevice:::notifyIdle() - only one idle notify may be active\n\r");
1145 idleNotifyActive
= true;
1146 idleNotifyTarget
= target
;
1147 idleNotifyCallback
= callback
;
1148 idleNotifyRefcon
= refcon
;
1159 void IOATAStandardDevice::submitCommand( UInt32 cmdType
, IOATAStandardCommand
*ataCmd
, UInt32 cmdSequenceNumber
)
1161 deviceGate
->runCommand( (void *)cmdType
, (void *)ataCmd
, (void *) cmdSequenceNumber
, (void *) 0 );
1169 void IOATAStandardDevice::receiveCommand( UInt32 cmdType
, IOATAStandardCommand
*ataCmd
, UInt32 cmdSequenceNumber
, void *p3
)
1171 queue_head_t
*queue
;
1175 case kATACommandExecute
:
1176 ataCmd
->cmdType
= (ATACommandType
) cmdType
;
1178 queue
= (ataCmd
->queueType
== kATAQTypeBypassQ
) ? &bypassList
: &deviceList
;
1180 if ( ataCmd
->queuePosition
== kATAQPositionHead
)
1182 stackCommand( queue
, ataCmd
);
1186 addCommand( queue
, ataCmd
);
1192 case kATACommandAbortAll
:
1193 abortAllCommands( kATACommandAbortAll
);
1196 case kATACommandAbort
:
1197 abortCommand( ataCmd
, cmdSequenceNumber
);
1200 case kATACommandDeviceReset
:
1201 abortAllCommands( kATACommandDeviceReset
);
1215 void IOATAStandardDevice::abortCommand( IOATAStandardCommand
*ataCmd
, UInt32 sequenceNumber
)
1217 if ( ataCmd
->list
== (queue_head_t
*)deviceGate
)
1219 if ( ataCmd
->sequenceNumber
!= sequenceNumber
)
1223 ataCmd
->results
.returnCode
= kIOReturnAborted
;
1225 else if ( ataCmd
->list
== &deviceList
)
1227 if ( ataCmd
->sequenceNumber
!= sequenceNumber
)
1232 deleteCommand( &deviceList
, ataCmd
);
1233 ataCmd
->results
.returnCode
= kIOReturnAborted
;
1234 finishCommand( ataCmd
);
1236 else if ( ataCmd
->list
== &activeList
)
1238 if ( ataCmd
->sequenceNumber
!= sequenceNumber
)
1243 moveCommand( &activeList
, &abortList
, ataCmd
);
1255 void IOATAStandardDevice::abortAllCommands( ATACommandType cmdType
)
1258 abortCmdPending
= cmdType
;
1260 if ( abortCmdPending
== kATACommandAbortAll
)
1264 client
->message( kATAClientMsgDeviceAbort
, this );
1267 else if ( abortCmdPending
== kATACommandDeviceReset
)
1271 client
->message( kATAClientMsgDeviceReset
, this );
1283 void IOATAStandardDevice::resetOccurred( ATAClientMessage clientMsg
)
1285 moveAllCommands( &activeList
, &cancelList
, kIOReturnAborted
);
1286 moveAllCommands( &abortList
, &cancelList
, kIOReturnAborted
);
1288 abortState
= kStateIdle
;
1289 reqSenseState
= kStateIdle
;
1292 isSuspended
= false;
1293 AbsoluteTime_to_scalar( &suspendTime
) = 0;
1295 if ( (client
!= 0) && (clientMsg
!= kATAClientMsgNone
) )
1297 client
->message( clientMsg
, this );
1303 void IOATAStandardDevice::resetComplete()
1307 client
->message( kATAClientMsgBusReset
| kATAClientMsgDone
, this );
1317 bool IOATAStandardDevice::checkAbortQueue()
1319 IOATAStandardCommand
*origCmd
;
1321 if ( abortState
== kStateActive
)
1326 if ( abortCmdPending
!= kATACommandNone
)
1328 abortCmd
->origCommand
= 0;
1329 abortCmd
->taskfile
.tagType
= kATATagTypeNone
;
1330 abortCmd
->cmdType
= abortCmdPending
;
1332 abortCmd
->timer
= ( abortCmd
->timeout
!= 0 ) ?
1333 abortCmd
->timeout
/ kATATimerIntervalmS
+ 1 : 0;
1335 bzero( &abortCmd
->results
, sizeof(ATAResults
) );
1337 abortState
= kStateActive
;
1339 addCommand( &activeList
, abortCmd
);
1341 if ( (abortCmdPending
== kATACommandDeviceReset
) ||
1342 (abortCmdPending
== kATACommandAbortAll
) && (queue_empty( &abortList
) == false) )
1344 controller
->abortCommand( abortCmd
);
1348 abortCmd
->complete();
1351 else if ( queue_empty( &abortList
) == false )
1353 origCmd
= (IOATAStandardCommand
*)queue_first( &abortList
);
1354 abortCmd
->origCommand
= origCmd
;
1356 abortCmd
->cmdType
= kATACommandAbort
;
1357 abortCmd
->taskfile
.tagType
= origCmd
->taskfile
.tagType
;
1358 abortCmd
->taskfile
.tag
= origCmd
->taskfile
.tag
;
1360 abortCmd
->timer
= ( abortCmd
->timeout
!= 0 ) ?
1361 abortCmd
->timeout
/ kATATimerIntervalmS
+ 1 : 0;
1363 bzero( &abortCmd
->results
, sizeof(ATAResults
) );
1365 abortState
= kStateActive
;
1367 addCommand( &activeList
, abortCmd
);
1368 controller
->abortCommand( abortCmd
);
1383 void IOATAStandardDevice::checkCancelQueue()
1385 if ( cancelState
!= kStateIdle
)
1390 if ( queue_empty( &cancelList
) == true )
1395 if ( controller
->controllerInfo
.disableCancelCommands
== true )
1400 cancelCmd
->origCommand
= (IOATAStandardCommand
*)queue_first( &cancelList
);
1401 bzero( &cancelCmd
->results
, sizeof(ATAResults
) );
1403 cancelState
= kStateActive
;
1404 controller
->cancelCommand( cancelCmd
);
1412 bool IOATAStandardDevice::checkReqSense()
1414 IOMemoryDescriptor
*senseData
;
1417 if ( reqSenseState
== kStateIssue
)
1419 reqSenseCmd
->origCommand
= reqSenseOrigCmd
;
1420 bzero( &reqSenseCmd
->results
, sizeof(ATAResults
) );
1422 reqSenseOrigCmd
->getPointers( &senseData
, &senseLength
, 0, true );
1423 reqSenseCmd
->setPointers( senseData
, senseLength
, false );
1425 reqSenseCmd
->timer
= ( reqSenseCmd
->timeout
!= 0 ) ?
1426 reqSenseCmd
->timeout
/ kATATimerIntervalmS
+ 1 : 0;
1428 reqSenseCmd
->ataCmd
.cdb
[3] = (senseLength
>> 8) & 0xff;
1429 reqSenseCmd
->ataCmd
.cdb
[4] = senseLength
& 0xff;
1431 reqSenseState
= kStatePending
;
1434 if ( reqSenseState
== kStatePending
)
1436 reqSenseState
= kStateActive
;
1438 addCommand( &activeList
, reqSenseCmd
);
1441 controller
->commandCount
++;
1443 controller
->executeCommand( reqSenseCmd
);
1446 return (reqSenseState
!= kStateIdle
);
1455 bool IOATAStandardDevice::checkDeviceQueue( UInt32
*dispatchAction
)
1457 IOATAStandardCommand
*ataCmd
= 0;
1458 queue_head_t
*queue
;
1465 if ( isSuspended
== true )
1467 *dispatchAction
= kDispatchNextDevice
;
1471 if ( controller
->commandCount
>= controller
->commandLimit
)
1473 *dispatchAction
= kDispatchStop
;
1477 *dispatchAction
= kDispatchNextDevice
;
1479 if ( commandCount
>= commandLimit
)
1484 for ( i
=0; i
< 2; i
++ )
1486 queueHeld
= (i
== 0) ? bypassQHeld
: normalQHeld
;
1487 queue
= (i
== 0) ? &bypassList
: &deviceList
;
1489 if ( queueHeld
> 0 )
1494 ataCmd
= checkCommand( queue
);
1497 *dispatchAction
= kDispatchNextCommand
;
1509 if ( checkTag( ataCmd
) == false )
1511 *dispatchAction
= kDispatchNextDevice
;
1515 getCommand( queue
);
1517 ataCmd
->timer
= ( ataCmd
->timeout
!= 0 ) ? ataCmd
->timeout
/ kATATimerIntervalmS
+ 1 : 0;
1520 controller
->commandCount
++;
1522 addCommand( &activeList
, ataCmd
);
1524 controller
->executeCommand( ataCmd
);
1536 void IOATAStandardDevice::suspend()
1538 if ( AbsoluteTime_to_scalar( &suspendTime
) == 0 )
1540 clock_get_uptime( &suspendTime
);
1551 void IOATAStandardDevice::resume()
1553 AbsoluteTime_to_scalar( &suspendTime
) = 0;
1554 isSuspended
= false;
1565 void IOATAStandardDevice::rescheduleCommand( IOATAStandardCommand
*ataCmd
)
1567 queue_head_t
*queue
;
1569 if ( ataCmd
->list
!= &activeList
)
1571 IOLog( "IOATAStandardController::rescheduleCommand() - Command not active. Cmd = %08x\n\r", (int)ataCmd
);
1575 deleteCommand( &activeList
, ataCmd
);
1577 switch ( ataCmd
->cmdType
)
1579 case kATACommandExecute
:
1580 if ( ataCmd
->taskfile
.tagType
!= kATATagTypeNone
)
1582 freeTag( ataCmd
->taskfile
.tag
);
1583 ataCmd
->taskfile
.tag
= kATATagTypeNone
;
1586 queue
= (ataCmd
->queueType
== kATAQTypeBypassQ
) ? &bypassList
: &deviceList
;
1588 stackCommand( queue
, ataCmd
);
1590 controller
->commandCount
--;
1594 case kATACommandReqSense
:
1595 reqSenseState
= kStatePending
;
1597 controller
->commandCount
--;
1600 case kATACommandAbortAll
:
1601 case kATACommandDeviceReset
:
1602 abortCmdPending
= ataCmd
->cmdType
;
1604 case kATACommandAbort
:
1605 abortState
= kStateIdle
;
1621 bool IOATAStandardDevice::checkTag( IOATAStandardCommand
*ataCmd
)
1625 ATAProtocol protocol
;
1627 ataCmd
->getCDB( &ataCDB
);
1629 ataCmd
->taskfile
.tagType
= kATATagTypeNone
;
1631 protocol
= ataCmd
->getProtocol();
1635 if ( protocol
!= kATAProtocolDMAQueued
&& protocol
!= kATAProtocolDMAQueuedRelease
)
1639 if ( allocTag( &ataCmd
->taskfile
.tag
) == false )
1645 ataCmd
->taskfile
.tagType
= kATATagTypeSimple
;
1649 ataCmd
->setCDB( &ataCDB
);
1659 bool IOATAStandardDevice::allocTag( UInt32
*tagId
)
1668 if ( tags
== 0 ) return false;
1670 for ( i
= 0; i
< maxTags
; i
++ )
1673 tagMask
= 1 << (i
% 32);
1674 if ( !(tags
[tagIndex
] & tagMask
) )
1676 tags
[tagIndex
] |= tagMask
;
1689 void IOATAStandardDevice::freeTag( UInt32 tagId
)
1695 if ( tags
== 0 ) return;
1697 tags
[tagId
/32] &= ~(1 << (tagId
% 32));
1705 IOATAStandardCommand
*IOATAStandardDevice::findCommandWithNexus( UInt32 tagValue
)
1707 IOATAStandardCommand
*ataCmd
;
1710 queue_iterate( &activeList
, ataCmd
, IOATAStandardCommand
*, nextCommand
)
1712 switch ( ataCmd
->cmdType
)
1714 case kATACommandExecute
:
1715 case kATACommandReqSense
:
1716 tag
= (ataCmd
->taskfile
.tagType
== kATATagTypeNone
) ? (UInt32
) -1 : ataCmd
->taskfile
.tag
;
1717 if ( tag
== tagValue
)
1727 queue_iterate( &abortList
, ataCmd
, IOATAStandardCommand
*, nextCommand
)
1729 switch ( ataCmd
->cmdType
)
1731 case kATACommandExecute
:
1732 case kATACommandReqSense
:
1733 if ( ataCmd
->taskfile
.tag
== tagValue
)
1751 void IOATAStandardDevice::timer()
1753 IOATAStandardCommand
*ataCmd
, *tmp
= 0;
1755 queue_iterate( &activeList
, ataCmd
, IOATAStandardCommand
*, nextCommand
)
1757 tmp
= (IOATAStandardCommand
*)queue_prev( &ataCmd
->nextCommand
);
1759 if ( ataCmd
->timer
)
1761 if ( !--ataCmd
->timer
)
1763 IOLog("Timeout: Unit = %d Cmd = %08x Cmd Type = %d\n\r",
1764 unit
, (int)ataCmd
, ataCmd
->cmdType
);
1766 controller
->busResetState
= kStateIssue
;
1771 if ( queue_end( &activeList
, (queue_head_t
*)ataCmd
) == true )
1783 void IOATAStandardDevice::dispatchRequest()
1785 target
->state
= kStateActive
;
1786 controller
->dispatchRequest();
1794 bool IOATAStandardDevice::dispatch( UInt32
*dispatchAction
)
1800 if ( controller
->checkBusReset() == true )
1802 *dispatchAction
= kDispatchStop
;
1806 if ( checkAbortQueue() == true )
1808 *dispatchAction
= kDispatchNextDevice
;
1814 if ( (rc
= controller
->commandDisable
) == true )
1816 *dispatchAction
= kDispatchStop
;
1820 if ( isSuspended
== true )
1822 *dispatchAction
= kDispatchNextDevice
;
1826 if ( (rc
= checkReqSense()) == true )
1828 *dispatchAction
= kDispatchNextDevice
;
1832 rc
= checkDeviceQueue( dispatchAction
);
1834 } while ( *dispatchAction
== kDispatchNextCommand
);
1845 void IOATAStandardDevice::completeCommand( IOATAStandardCommand
*ataCmd
)
1847 ATACommandType cmdType
;
1849 cmdType
= ataCmd
->cmdType
;
1852 case kATACommandExecute
:
1853 executeCommandDone( ataCmd
);
1856 case kATACommandReqSense
:
1857 executeReqSenseDone( ataCmd
);
1860 case kATACommandAbort
:
1861 case kATACommandAbortAll
:
1862 case kATACommandDeviceReset
:
1863 abortCommandDone( ataCmd
);
1866 case kATACommandCancel
:
1867 cancelCommandDone( ataCmd
);
1884 void IOATAStandardDevice::checkIdleNotify()
1886 if ( idleNotifyActive
== false )
1891 if ( (queue_empty( &activeList
) == true)
1892 && (queue_empty( &abortList
) == true)
1893 && (queue_empty( &cancelList
) == true) )
1895 idleNotifyActive
= false;
1896 (idleNotifyCallback
)( idleNotifyTarget
, idleNotifyRefcon
);
1905 void IOATAStandardDevice::flushQueue( UInt32 queueType
, IOReturn rc
)
1907 queue_head_t
*queue
;
1909 queue
= (queueType
== kATAQTypeBypassQ
) ? &bypassList
: &deviceList
;
1910 purgeAllCommands( queue
, rc
);
1918 void IOATAStandardDevice::executeCommandDone( IOATAStandardCommand
*ataCmd
)
1920 deleteCommand( ataCmd
->list
, ataCmd
);
1923 controller
->commandCount
--;
1925 if ( ataCmd
->taskfile
.tagType
!= kATATagTypeNone
)
1927 freeTag( ataCmd
->taskfile
.tag
);
1928 ataCmd
->taskfile
.tagType
= kATATagTypeNone
;
1931 if ( deviceType
== kATADeviceATAPI
1932 && ataCmd
->results
.adapterStatus
== kATAReturnStatusError
1933 && ataCmd
->results
.requestSenseDone
== false
1934 && ataCmd
->senseData
!= 0 )
1936 reqSenseOrigCmd
= ataCmd
;
1937 reqSenseState
= kStateIssue
;
1941 finishCommand( ataCmd
);
1949 void IOATAStandardDevice::executeReqSenseDone( IOATAStandardCommand
*ataCmd
)
1951 IOATAStandardCommand
*origCommand
;
1953 deleteCommand( ataCmd
->list
, ataCmd
);
1956 controller
->commandCount
--;
1958 reqSenseState
= kStateIdle
;
1960 reqSenseOrigCmd
= 0;
1962 origCommand
= ataCmd
->origCommand
;
1964 if ( (ataCmd
->results
.returnCode
== kIOReturnSuccess
) || (ataCmd
->results
.returnCode
== kIOReturnUnderrun
))
1966 origCommand
->results
.requestSenseDone
= true;
1967 origCommand
->results
.requestSenseLength
= ataCmd
->results
.bytesTransferred
;
1971 origCommand
->results
.requestSenseDone
= false;
1972 origCommand
->results
.requestSenseLength
= 0;
1975 finishCommand( ataCmd
->origCommand
);
1983 void IOATAStandardDevice::abortCommandDone( IOATAStandardCommand
*ataCmd
)
1985 IOATAStandardCommand
*origATACmd
;
1987 deleteCommand( ataCmd
->list
, ataCmd
);
1989 if ( ataCmd
->cmdType
== kATACommandAbortAll
)
1991 resetOccurred( (ATAClientMessage
) (kATAClientMsgDeviceAbort
| kATAClientMsgDone
) );
1992 abortCmdPending
= kATACommandNone
;
1994 if ( ataCmd
->cmdType
== kATACommandDeviceReset
)
1996 resetOccurred( (ATAClientMessage
) (kATAClientMsgDeviceReset
| kATAClientMsgDone
) );
1997 abortCmdPending
= kATACommandNone
;
1999 else if ( ataCmd
->cmdType
== kATACommandAbort
)
2001 origATACmd
= ataCmd
->origCommand
;
2003 if ( findCommand( &abortList
, origATACmd
) == true )
2005 moveCommand( &abortList
, &cancelList
, origATACmd
, kIOReturnAborted
);
2009 abortState
= kStateIdle
;
2019 void IOATAStandardDevice::cancelCommandDone( IOATAStandardCommand
*ataCmd
)
2021 IOATAStandardCommand
*origATACmd
;
2023 cancelState
= kStateIdle
;
2025 origATACmd
= ataCmd
->origCommand
;
2027 if ( findCommand( &cancelList
, origATACmd
) == true )
2029 IOLog( "IOATAStandardDevice::cancelCommandDone - Cancelled command not completed - ataCmd = %08x\n\r", (int)origATACmd
);
2030 deleteCommand( &cancelList
, origATACmd
);
2039 void IOATAStandardDevice::finishCommand( IOATAStandardCommand
*ataCmd
)
2041 if ( ataCmd
->completionInfo
.async
.callback
)
2043 (*ataCmd
->completionInfo
.async
.callback
)( ataCmd
->completionInfo
.async
.target
,
2044 ataCmd
->completionInfo
.async
.refcon
);
2048 ataCmd
->completionInfo
.sync
.lock
->signal();
2057 OSDictionary
*IOATAStandardDevice::createProperties()
2059 OSDictionary
*propTable
= 0;
2066 propTable
= OSDictionary::withCapacity(kATAMaxProperties
);
2067 if ( propTable
== NULL
)
2072 s
= (deviceType
== kATADeviceATA
) ? kATAPropertyProtocolATA
: kATAPropertyProtocolATAPI
;
2073 regObj
= (OSObject
*)OSString::withCString( s
);
2074 if ( addToRegistry( propTable
, regObj
, kATAPropertyProtocol
) != true )
2076 goto createprop_error
;
2079 regObj
= (OSObject
*)OSNumber::withNumber(unit
,32);
2080 if ( addToRegistry( propTable
, regObj
, kATAPropertyDeviceNumber
) != true )
2082 goto createprop_error
;
2085 regObj
= (OSObject
*)OSNumber::withNumber(unit
,32);
2086 if ( addToRegistry( propTable
, regObj
, kATAPropertyLocation
) != true )
2088 goto createprop_error
;
2092 stripBlanks( d
, (char *)identifyData
->modelNumber
, sizeof(identifyData
->modelNumber
));
2093 regObj
= (OSObject
*)OSString::withCString( d
);
2094 if ( addToRegistry( propTable
, regObj
, kATAPropertyModelNumber
) != true )
2096 goto createprop_error
;
2100 stripBlanks( d
, (char *)identifyData
->firmwareRevision
, sizeof(identifyData
->firmwareRevision
));
2101 regObj
= (OSObject
*)OSString::withCString( d
);
2102 if ( addToRegistry( propTable
, regObj
, kATAPropertyFirmwareRev
) != true )
2104 goto createprop_error
;
2109 stripBlanks( d
, (char *)inquiryData
->vendorName
, sizeof(inquiryData
->vendorName
) );
2110 regObj
= (OSObject
*)OSString::withCString( d
);
2111 if ( addToRegistry( propTable
, regObj
, kATAPropertyVendorName
) != true )
2113 goto createprop_error
;
2116 stripBlanks( d
, (char *)inquiryData
->productName
, sizeof(inquiryData
->productName
) );
2117 regObj
= (OSObject
*)OSString::withCString( d
);
2118 if ( addToRegistry( propTable
, regObj
, kATAPropertyProductName
) != true )
2120 goto createprop_error
;
2123 stripBlanks( d
, (char *)inquiryData
->productRevision
, sizeof(inquiryData
->productRevision
) );
2124 regObj
= (OSObject
*)OSString::withCString( d
);
2125 if ( addToRegistry( propTable
, regObj
, kATAPropertyProductRevision
) != true )
2127 goto createprop_error
;
2133 propTable
->release();
2142 bool IOATAStandardDevice::addToRegistry( OSDictionary
*propTable
, OSObject
*regObj
, char *key
,
2143 bool doRelease
= true )
2147 if ( regObj
== NULL
)
2152 rc
= propTable
->setObject( key
, regObj
);
2156 // If 'doRelease' is true, then a reference count is consumed.
2169 bool IOATAStandardDevice::matchPropertyTable(OSDictionary
* table
)
2171 return( controller
->matchNubWithPropertyTable( this, table
));
2180 IOService
*IOATAStandardDevice::matchLocation(IOService
* client
)
2191 void IOATAStandardDevice::stripBlanks( char *d
, char *s
, UInt32 l
)
2195 for ( p
= d
, c
= *s
; l
&& c
; l
--)
2210 void IOATAStandardDevice::endianConvertData( void *data
, void *endianTable
)
2220 UInt64
*longlongPtr
;
2227 t
= (EndianTable
*)endianTable
;
2229 for ( ; t
->type
; t
++ )
2231 i
= t
->size
/t
->type
;
2238 * The ATA standard defines identify strings as arrays of short ints,
2239 * with the left-most character of the string as the most significant
2240 * byte of the short int. Strings are not normally affected by the host
2241 * endianess. However, the way ATA defines strings would cause strings
2242 * to appear byte reversed. We do a manditory short int byte-swap here,
2243 * although strictly speaking this is not an endian issue.
2247 for ( j
= 0; j
< i
/2; j
++ )
2249 *p
.shortPtr
++ = OSSwapInt16(*p
.shortPtr
);
2254 case sizeof(UInt16
):
2255 for ( j
= 0; j
< i
; j
++ )
2257 *p
.shortPtr
++ = OSSwapLittleToHostInt16(*p
.shortPtr
);
2261 case sizeof(UInt32
):
2262 for ( j
= 0; j
< i
; j
++ )
2264 *p
.longPtr
++ = OSSwapLittleToHostInt32(*p
.longPtr
);
2268 case sizeof(UInt64
):
2269 for ( j
= 0; j
< i
; j
++ )
2271 *p
.longlongPtr
++ = OSSwapLittleToHostInt64(*p
.longlongPtr
);
2286 IOATACommand
*IOATAStandardDevice::allocCommand( IOATADevice
*, UInt32 clientDataSize
)
2288 return (IOATAStandardCommand
*) allocCommand( kIOATAStandardDevice
, clientDataSize
);
2291 IOCDBCommand
*IOATAStandardDevice::allocCommand( IOCDBDevice
*, UInt32 clientDataSize
)
2293 return (IOCDBCommand
*) allocCommand( kIOATAStandardDevice
, clientDataSize
);
2296 IOATAStandardCommand
*IOATAStandardDevice::allocCommand( IOATAStandardDevice
*, UInt32 clientDataSize
)
2298 IOATAStandardCommand
*cmd
;
2300 if ( (cmd
= controller
->allocCommand( clientDataSize
)) )
2312 IOWorkLoop
*IOATAStandardDevice::getWorkLoop() const
2314 return controller
->workLoop
;
2323 bool IOATAStandardDevice::open( IOService
*forClient
, IOOptionBits options
, void *arg
)
2325 if ( client
!= 0 ) return false;
2329 return super::open( forClient
, options
, arg
);
2337 void IOATAStandardDevice::close( IOService
*forClient
, IOOptionBits options
)
2341 return super::close( forClient
, options
);
2349 void IOATAStandardDevice::free()
2351 if ( deviceGate
!= 0 )
2353 controller
->workLoop
->removeEventSource( deviceGate
);
2354 deviceGate
->release();
2357 if ( reqSenseCmd
!= 0 ) reqSenseCmd
->release();
2358 if ( abortCmd
!= 0 ) abortCmd
->release();
2359 if ( cancelCmd
!= 0 ) cancelCmd
->release();
2360 if ( probeCmd
!= 0 ) probeCmd
->release();
2362 if ( tagArray
!= 0 ) IOFree( tagArray
, tagArraySize
);
2363 if ( inquiryData
!= 0 ) IOFree( inquiryData
, inquiryDataSize
);
2364 if ( devicePrivateData
!= 0 ) IOFreeContiguous( devicePrivateData
, controller
->controllerInfo
.devicePrivateDataSize
);
2365 if ( clientSem
!= 0 ) IORWLockFree( clientSem
);