2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
26 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
29 * 23 Nov 98 sdouglas created.
32 #include <IOKit/system.h>
34 #include <pexpert/pexpert.h>
37 #include <libkern/c++/OSContainers.h>
38 #include <IOKit/IOLib.h>
39 #include <IOKit/IODeviceTreeSupport.h>
40 #include <IOKit/IODeviceMemory.h>
41 #include <IOKit/IOPlatformExpert.h>
43 #include <IOKit/pci/IOPCIDevice.h>
45 #include <IOKit/platform/AppleMacIO.h>
47 #include <IOKit/ppc/IODBDMA.h>
49 #include <IOKit/assert.h>
51 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
53 #define super IOService
55 OSDefineMetaClassAndAbstractStructors(AppleMacIO
, IOService
);
56 OSMetaClassDefineReservedUnused(AppleMacIO
, 0);
57 OSMetaClassDefineReservedUnused(AppleMacIO
, 1);
58 OSMetaClassDefineReservedUnused(AppleMacIO
, 2);
59 OSMetaClassDefineReservedUnused(AppleMacIO
, 3);
61 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
63 bool AppleMacIO::start( IOService
* provider
)
65 IOPCIDevice
*pciNub
= (IOPCIDevice
*)provider
;
67 if( !super::start( provider
))
70 // Make sure memory space is on.
71 pciNub
->setMemoryEnable(true);
74 fMemory
= provider
->mapDeviceMemoryWithIndex( 0 );
76 IOLog("%s: unexpected ranges\n", getName());
78 IOLog("Warning: AppleMacIO self test fails\n");
79 PMinit(); // initialize for power management
80 temporaryPowerClampOn(); // hold power on till we get children
85 IOService
* AppleMacIO::createNub( IORegistryEntry
* from
)
89 nub
= new AppleMacIODevice
;
91 if( nub
&& !nub
->init( from
, gIODTPlane
)) {
99 void AppleMacIO::processNub(IOService
* /*nub*/)
103 const char * AppleMacIO::deleteList ( void )
105 return( "('sd', 'st', 'disk', 'tape', 'pram', 'rtc', 'mouse')" );
108 const char * AppleMacIO::excludeList( void )
113 void AppleMacIO::publishBelow( IORegistryEntry
* root
)
115 OSCollectionIterator
* kids
;
116 IORegistryEntry
* next
;
120 kids
= IODTFindMatchingEntries( root
, kIODTRecursive
, deleteList() );
122 while( (next
= (IORegistryEntry
*)kids
->getNextObject())) {
123 next
->detachAll( gIODTPlane
);
128 // publish everything below, minus excludeList
129 kids
= IODTFindMatchingEntries( root
, kIODTRecursive
| kIODTExclusive
,
132 while( (next
= (IORegistryEntry
*)kids
->getNextObject())) {
134 if( 0 == (nub
= createNub( next
)))
141 nub
->registerService();
147 bool AppleMacIO::compareNubName( const IOService
* nub
,
148 OSString
* name
, OSString
** matched
) const
150 return( IODTCompareNubName( nub
, name
, matched
)
151 || nub
->IORegistryEntry::compareName( name
, matched
) );
154 IOReturn
AppleMacIO::getNubResources( IOService
* nub
)
156 if( nub
->getDeviceMemory())
157 return( kIOReturnSuccess
);
159 IODTResolveAddressing( nub
, "reg", fNub
->getDeviceMemoryWithIndex(0) );
161 return( kIOReturnSuccess
);
164 bool AppleMacIO::selfTest( void )
166 IODBDMADescriptor
*dmaDescriptors
;
167 UInt32 dmaDescriptorsPhys
;
170 IODBDMADescriptor
*dmaDesc
;
171 volatile IODBDMAChannelRegisters
*ioBaseDMA
;
173 enum { kTestChannel
= 0x8000 };
175 ioBaseDMA
= (volatile IODBDMAChannelRegisters
*)
176 (((UInt32
)fMemory
->getVirtualAddress())
180 dmaDescriptors
= (IODBDMADescriptor
*)IOMallocContiguous(page_size
, 1, & dmaDescriptorsPhys
);
184 if ( (UInt32
)dmaDescriptors
& (page_size
- 1) ) {
185 IOLog("AppleMacIO::%s() - DMA Descriptor memory not page aligned!!", __FUNCTION__
);
189 bzero( dmaDescriptors
, page_size
);
191 IODBDMAReset( ioBaseDMA
);
193 dmaDesc
= dmaDescriptors
;
195 IOMakeDBDMADescriptor( dmaDesc
,
206 IOMakeDBDMADescriptorDep( dmaDesc
,
213 dmaDescriptorsPhys
+16*sizeof(IODBDMADescriptor
),
218 IOMakeDBDMADescriptor( dmaDesc
,
228 for ( i
= 0; (!ok
) && (i
< 3); i
++ )
230 dmaDescriptors
[16].operation
= 0;
232 IOSetDBDMACommandPtr( ioBaseDMA
, dmaDescriptorsPhys
);
233 IODBDMAContinue( ioBaseDMA
);
237 status
= IOGetDBDMAChannelStatus( ioBaseDMA
);
239 if ( ((status
& kdbdmaActive
) == 0)
240 && ((status
& kdbdmaDead
) == 0)
241 && (OSReadSwapInt32( &dmaDescriptors
[16].operation
, 0 ) == 0x12345678 ))
245 IODBDMAReset( ioBaseDMA
);
250 IOFreeContiguous(dmaDescriptors
, page_size
);
256 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
259 #define super IOService
261 OSDefineMetaClassAndStructors(AppleMacIODevice
, IOService
);
262 OSMetaClassDefineReservedUnused(AppleMacIODevice
, 0);
263 OSMetaClassDefineReservedUnused(AppleMacIODevice
, 1);
264 OSMetaClassDefineReservedUnused(AppleMacIODevice
, 2);
265 OSMetaClassDefineReservedUnused(AppleMacIODevice
, 3);
267 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
269 bool AppleMacIODevice::compareName( OSString
* name
,
270 OSString
** matched
= 0 ) const
272 return( ((AppleMacIO
*)getProvider())->
273 compareNubName( this, name
, matched
));
276 IOService
* AppleMacIODevice::matchLocation( IOService
* /* client */ )
281 IOReturn
AppleMacIODevice::getResources( void )
283 return( ((AppleMacIO
*)getProvider())->getNubResources( this ));