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 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
26 * 23 Nov 98 sdouglas created.
29 #include <IOKit/system.h>
31 #include <pexpert/pexpert.h>
34 #include <libkern/c++/OSContainers.h>
35 #include <IOKit/IOLib.h>
36 #include <IOKit/IODeviceTreeSupport.h>
37 #include <IOKit/IODeviceMemory.h>
38 #include <IOKit/IOPlatformExpert.h>
40 #include <IOKit/pci/IOPCIDevice.h>
42 #include <IOKit/platform/AppleMacIO.h>
44 #include <IOKit/ppc/IODBDMA.h>
46 #include <IOKit/assert.h>
48 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
50 #define super IOService
52 OSDefineMetaClassAndAbstractStructors(AppleMacIO
, IOService
);
53 OSMetaClassDefineReservedUnused(AppleMacIO
, 0);
54 OSMetaClassDefineReservedUnused(AppleMacIO
, 1);
55 OSMetaClassDefineReservedUnused(AppleMacIO
, 2);
56 OSMetaClassDefineReservedUnused(AppleMacIO
, 3);
58 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
60 bool AppleMacIO::start( IOService
* provider
)
62 IOPCIDevice
*pciNub
= (IOPCIDevice
*)provider
;
64 if( !super::start( provider
))
67 // Make sure memory space is on.
68 pciNub
->setMemoryEnable(true);
71 fMemory
= provider
->mapDeviceMemoryWithIndex( 0 );
73 IOLog("%s: unexpected ranges\n", getName());
75 IOLog("Warning: AppleMacIO self test fails\n");
76 PMinit(); // initialize for power management
77 temporaryPowerClampOn(); // hold power on till we get children
82 IOService
* AppleMacIO::createNub( IORegistryEntry
* from
)
86 nub
= new AppleMacIODevice
;
88 if( nub
&& !nub
->init( from
, gIODTPlane
)) {
96 void AppleMacIO::processNub(IOService
* /*nub*/)
100 const char * AppleMacIO::deleteList ( void )
102 return( "('sd', 'st', 'disk', 'tape', 'pram', 'rtc', 'mouse')" );
105 const char * AppleMacIO::excludeList( void )
110 void AppleMacIO::publishBelow( IORegistryEntry
* root
)
112 OSCollectionIterator
* kids
;
113 IORegistryEntry
* next
;
117 kids
= IODTFindMatchingEntries( root
, kIODTRecursive
, deleteList() );
119 while( (next
= (IORegistryEntry
*)kids
->getNextObject())) {
120 next
->detachAll( gIODTPlane
);
125 // publish everything below, minus excludeList
126 kids
= IODTFindMatchingEntries( root
, kIODTRecursive
| kIODTExclusive
,
129 while( (next
= (IORegistryEntry
*)kids
->getNextObject())) {
131 if( 0 == (nub
= createNub( next
)))
138 nub
->registerService();
144 bool AppleMacIO::compareNubName( const IOService
* nub
,
145 OSString
* name
, OSString
** matched
) const
147 return( IODTCompareNubName( nub
, name
, matched
)
148 || nub
->IORegistryEntry::compareName( name
, matched
) );
151 IOReturn
AppleMacIO::getNubResources( IOService
* nub
)
153 if( nub
->getDeviceMemory())
154 return( kIOReturnSuccess
);
156 IODTResolveAddressing( nub
, "reg", fNub
->getDeviceMemoryWithIndex(0) );
158 return( kIOReturnSuccess
);
161 bool AppleMacIO::selfTest( void )
163 IODBDMADescriptor
*dmaDescriptors
;
164 UInt32 dmaDescriptorsPhys
;
167 IODBDMADescriptor
*dmaDesc
;
168 volatile IODBDMAChannelRegisters
*ioBaseDMA
;
170 enum { kTestChannel
= 0x8000 };
172 ioBaseDMA
= (volatile IODBDMAChannelRegisters
*)
173 (((UInt32
)fMemory
->getVirtualAddress())
177 dmaDescriptors
= (IODBDMADescriptor
*)IOMallocContiguous(page_size
, 1, & dmaDescriptorsPhys
);
181 if ( (UInt32
)dmaDescriptors
& (page_size
- 1) ) {
182 IOLog("AppleMacIO::%s() - DMA Descriptor memory not page aligned!!", __FUNCTION__
);
186 bzero( dmaDescriptors
, page_size
);
188 IODBDMAReset( ioBaseDMA
);
190 dmaDesc
= dmaDescriptors
;
192 IOMakeDBDMADescriptor( dmaDesc
,
203 IOMakeDBDMADescriptorDep( dmaDesc
,
210 dmaDescriptorsPhys
+16*sizeof(IODBDMADescriptor
),
215 IOMakeDBDMADescriptor( dmaDesc
,
225 for ( i
= 0; (!ok
) && (i
< 3); i
++ )
227 dmaDescriptors
[16].operation
= 0;
229 IOSetDBDMACommandPtr( ioBaseDMA
, dmaDescriptorsPhys
);
230 IODBDMAContinue( ioBaseDMA
);
234 status
= IOGetDBDMAChannelStatus( ioBaseDMA
);
236 if ( ((status
& kdbdmaActive
) == 0)
237 && ((status
& kdbdmaDead
) == 0)
238 && (OSReadSwapInt32( &dmaDescriptors
[16].operation
, 0 ) == 0x12345678 ))
242 IODBDMAReset( ioBaseDMA
);
247 IOFreeContiguous(dmaDescriptors
, page_size
);
253 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
256 #define super IOService
258 OSDefineMetaClassAndStructors(AppleMacIODevice
, IOService
);
259 OSMetaClassDefineReservedUnused(AppleMacIODevice
, 0);
260 OSMetaClassDefineReservedUnused(AppleMacIODevice
, 1);
261 OSMetaClassDefineReservedUnused(AppleMacIODevice
, 2);
262 OSMetaClassDefineReservedUnused(AppleMacIODevice
, 3);
264 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
266 bool AppleMacIODevice::compareName( OSString
* name
,
267 OSString
** matched
) const
269 return (IODTCompareNubName(this, name
, matched
) ||
270 IORegistryEntry::compareName(name
, matched
));
273 IOService
* AppleMacIODevice::matchLocation( IOService
* /* client */ )
278 IOReturn
AppleMacIODevice::getResources( void )
280 IOService
*macIO
= this;
282 if (getDeviceMemory() != 0) return kIOReturnSuccess
;
284 while (macIO
&& ((macIO
= macIO
->getProvider()) != 0))
285 if (strcmp("mac-io", macIO
->getName()) == 0) break;
287 if (macIO
== 0) return kIOReturnError
;
289 IODTResolveAddressing(this, "reg", macIO
->getDeviceMemoryWithIndex(0));
291 return kIOReturnSuccess
;