2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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
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.
21 * @APPLE_LICENSE_HEADER_END@
24 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
27 * 23 Nov 98 sdouglas created.
30 #include <IOKit/system.h>
32 #include <pexpert/pexpert.h>
35 #include <libkern/c++/OSContainers.h>
36 #include <IOKit/IOLib.h>
37 #include <IOKit/IODeviceTreeSupport.h>
38 #include <IOKit/IODeviceMemory.h>
39 #include <IOKit/IOPlatformExpert.h>
41 #include <IOKit/pci/IOPCIDevice.h>
43 #include <IOKit/platform/AppleMacIO.h>
45 #include <IOKit/ppc/IODBDMA.h>
47 #include <IOKit/assert.h>
49 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
51 #define super IOService
53 OSDefineMetaClassAndAbstractStructors(AppleMacIO
, IOService
);
54 OSMetaClassDefineReservedUnused(AppleMacIO
, 0);
55 OSMetaClassDefineReservedUnused(AppleMacIO
, 1);
56 OSMetaClassDefineReservedUnused(AppleMacIO
, 2);
57 OSMetaClassDefineReservedUnused(AppleMacIO
, 3);
59 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
61 bool AppleMacIO::start( IOService
* provider
)
63 IOPCIDevice
*pciNub
= (IOPCIDevice
*)provider
;
65 if( !super::start( provider
))
68 // Make sure memory space is on.
69 pciNub
->setMemoryEnable(true);
72 fMemory
= provider
->mapDeviceMemoryWithIndex( 0 );
74 IOLog("%s: unexpected ranges\n", getName());
76 IOLog("Warning: AppleMacIO self test fails\n");
77 PMinit(); // initialize for power management
78 temporaryPowerClampOn(); // hold power on till we get children
83 IOService
* AppleMacIO::createNub( IORegistryEntry
* from
)
87 nub
= new AppleMacIODevice
;
89 if( nub
&& !nub
->init( from
, gIODTPlane
)) {
97 void AppleMacIO::processNub(IOService
* /*nub*/)
101 const char * AppleMacIO::deleteList ( void )
103 return( "('sd', 'st', 'disk', 'tape', 'pram', 'rtc', 'mouse')" );
106 const char * AppleMacIO::excludeList( void )
111 void AppleMacIO::publishBelow( IORegistryEntry
* root
)
113 OSCollectionIterator
* kids
;
114 IORegistryEntry
* next
;
118 kids
= IODTFindMatchingEntries( root
, kIODTRecursive
, deleteList() );
120 while( (next
= (IORegistryEntry
*)kids
->getNextObject())) {
121 next
->detachAll( gIODTPlane
);
126 // publish everything below, minus excludeList
127 kids
= IODTFindMatchingEntries( root
, kIODTRecursive
| kIODTExclusive
,
130 while( (next
= (IORegistryEntry
*)kids
->getNextObject())) {
132 if( 0 == (nub
= createNub( next
)))
139 nub
->registerService();
145 bool AppleMacIO::compareNubName( const IOService
* nub
,
146 OSString
* name
, OSString
** matched
) const
148 return( IODTCompareNubName( nub
, name
, matched
)
149 || nub
->IORegistryEntry::compareName( name
, matched
) );
152 IOReturn
AppleMacIO::getNubResources( IOService
* nub
)
154 if( nub
->getDeviceMemory())
155 return( kIOReturnSuccess
);
157 IODTResolveAddressing( nub
, "reg", fNub
->getDeviceMemoryWithIndex(0) );
159 return( kIOReturnSuccess
);
162 bool AppleMacIO::selfTest( void )
164 IODBDMADescriptor
*dmaDescriptors
;
165 UInt32 dmaDescriptorsPhys
;
168 IODBDMADescriptor
*dmaDesc
;
169 volatile IODBDMAChannelRegisters
*ioBaseDMA
;
171 enum { kTestChannel
= 0x8000 };
173 ioBaseDMA
= (volatile IODBDMAChannelRegisters
*)
174 (((UInt32
)fMemory
->getVirtualAddress())
178 dmaDescriptors
= (IODBDMADescriptor
*)IOMallocContiguous(page_size
, 1, & dmaDescriptorsPhys
);
182 if ( (UInt32
)dmaDescriptors
& (page_size
- 1) ) {
183 IOLog("AppleMacIO::%s() - DMA Descriptor memory not page aligned!!", __FUNCTION__
);
187 bzero( dmaDescriptors
, page_size
);
189 IODBDMAReset( ioBaseDMA
);
191 dmaDesc
= dmaDescriptors
;
193 IOMakeDBDMADescriptor( dmaDesc
,
204 IOMakeDBDMADescriptorDep( dmaDesc
,
211 dmaDescriptorsPhys
+16*sizeof(IODBDMADescriptor
),
216 IOMakeDBDMADescriptor( dmaDesc
,
226 for ( i
= 0; (!ok
) && (i
< 3); i
++ )
228 dmaDescriptors
[16].operation
= 0;
230 IOSetDBDMACommandPtr( ioBaseDMA
, dmaDescriptorsPhys
);
231 IODBDMAContinue( ioBaseDMA
);
235 status
= IOGetDBDMAChannelStatus( ioBaseDMA
);
237 if ( ((status
& kdbdmaActive
) == 0)
238 && ((status
& kdbdmaDead
) == 0)
239 && (OSReadSwapInt32( &dmaDescriptors
[16].operation
, 0 ) == 0x12345678 ))
243 IODBDMAReset( ioBaseDMA
);
248 IOFreeContiguous(dmaDescriptors
, page_size
);
254 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
257 #define super IOService
259 OSDefineMetaClassAndStructors(AppleMacIODevice
, IOService
);
260 OSMetaClassDefineReservedUnused(AppleMacIODevice
, 0);
261 OSMetaClassDefineReservedUnused(AppleMacIODevice
, 1);
262 OSMetaClassDefineReservedUnused(AppleMacIODevice
, 2);
263 OSMetaClassDefineReservedUnused(AppleMacIODevice
, 3);
265 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
267 bool AppleMacIODevice::compareName( OSString
* name
,
268 OSString
** matched
) const
270 return (IODTCompareNubName(this, name
, matched
) ||
271 IORegistryEntry::compareName(name
, matched
));
274 IOService
* AppleMacIODevice::matchLocation( IOService
* /* client */ )
279 IOReturn
AppleMacIODevice::getResources( void )
281 IOService
*macIO
= this;
283 if (getDeviceMemory() != 0) return kIOReturnSuccess
;
285 while (macIO
&& ((macIO
= macIO
->getProvider()) != 0))
286 if (strcmp("mac-io", macIO
->getName()) == 0) break;
288 if (macIO
== 0) return kIOReturnError
;
290 IODTResolveAddressing(this, "reg", macIO
->getDeviceMemoryWithIndex(0));
292 return kIOReturnSuccess
;