2 * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_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. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
32 * 23 Nov 98 sdouglas created.
35 #include <IOKit/system.h>
37 #include <pexpert/pexpert.h>
40 #include <libkern/c++/OSContainers.h>
41 #include <IOKit/IOLib.h>
42 #include <IOKit/IODeviceTreeSupport.h>
43 #include <IOKit/IODeviceMemory.h>
44 #include <IOKit/IOPlatformExpert.h>
46 #include <IOKit/pci/IOPCIDevice.h>
48 #include <IOKit/platform/AppleMacIO.h>
50 #include <IOKit/ppc/IODBDMA.h>
52 #include <IOKit/assert.h>
54 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
56 #define super IOService
58 OSDefineMetaClassAndAbstractStructors(AppleMacIO
, IOService
);
59 OSMetaClassDefineReservedUnused(AppleMacIO
, 0);
60 OSMetaClassDefineReservedUnused(AppleMacIO
, 1);
61 OSMetaClassDefineReservedUnused(AppleMacIO
, 2);
62 OSMetaClassDefineReservedUnused(AppleMacIO
, 3);
64 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
66 bool AppleMacIO::start( IOService
* provider
)
68 IOPCIDevice
*pciNub
= (IOPCIDevice
*)provider
;
70 if( !super::start( provider
))
73 // Make sure memory space is on.
74 pciNub
->setMemoryEnable(true);
77 fMemory
= provider
->mapDeviceMemoryWithIndex( 0 );
79 IOLog("%s: unexpected ranges\n", getName());
81 IOLog("Warning: AppleMacIO self test fails\n");
82 PMinit(); // initialize for power management
83 temporaryPowerClampOn(); // hold power on till we get children
88 IOService
* AppleMacIO::createNub( IORegistryEntry
* from
)
92 nub
= new AppleMacIODevice
;
94 if( nub
&& !nub
->init( from
, gIODTPlane
)) {
102 void AppleMacIO::processNub(IOService
* /*nub*/)
106 const char * AppleMacIO::deleteList ( void )
108 return( "('sd', 'st', 'disk', 'tape', 'pram', 'rtc', 'mouse')" );
111 const char * AppleMacIO::excludeList( void )
116 void AppleMacIO::publishBelow( IORegistryEntry
* root
)
118 OSCollectionIterator
* kids
;
119 IORegistryEntry
* next
;
123 kids
= IODTFindMatchingEntries( root
, kIODTRecursive
, deleteList() );
125 while( (next
= (IORegistryEntry
*)kids
->getNextObject())) {
126 next
->detachAll( gIODTPlane
);
131 // publish everything below, minus excludeList
132 kids
= IODTFindMatchingEntries( root
, kIODTRecursive
| kIODTExclusive
,
135 while( (next
= (IORegistryEntry
*)kids
->getNextObject())) {
137 if( 0 == (nub
= createNub( next
)))
144 nub
->registerService();
150 bool AppleMacIO::compareNubName( const IOService
* nub
,
151 OSString
* name
, OSString
** matched
) const
153 return( IODTCompareNubName( nub
, name
, matched
)
154 || nub
->IORegistryEntry::compareName( name
, matched
) );
157 IOReturn
AppleMacIO::getNubResources( IOService
* nub
)
159 if( nub
->getDeviceMemory())
160 return( kIOReturnSuccess
);
162 IODTResolveAddressing( nub
, "reg", fNub
->getDeviceMemoryWithIndex(0) );
164 return( kIOReturnSuccess
);
167 bool AppleMacIO::selfTest( void )
169 IODBDMADescriptor
*dmaDescriptors
;
170 UInt32 dmaDescriptorsPhys
;
173 IODBDMADescriptor
*dmaDesc
;
174 volatile IODBDMAChannelRegisters
*ioBaseDMA
;
176 enum { kTestChannel
= 0x8000 };
178 ioBaseDMA
= (volatile IODBDMAChannelRegisters
*)
179 (((UInt32
)fMemory
->getVirtualAddress())
183 dmaDescriptors
= (IODBDMADescriptor
*)IOMallocContiguous(page_size
, 1, & dmaDescriptorsPhys
);
187 if ( (UInt32
)dmaDescriptors
& (page_size
- 1) ) {
188 IOLog("AppleMacIO::%s() - DMA Descriptor memory not page aligned!!", __FUNCTION__
);
192 bzero( dmaDescriptors
, page_size
);
194 IODBDMAReset( ioBaseDMA
);
196 dmaDesc
= dmaDescriptors
;
198 IOMakeDBDMADescriptor( dmaDesc
,
209 IOMakeDBDMADescriptorDep( dmaDesc
,
216 dmaDescriptorsPhys
+16*sizeof(IODBDMADescriptor
),
221 IOMakeDBDMADescriptor( dmaDesc
,
231 for ( i
= 0; (!ok
) && (i
< 3); i
++ )
233 dmaDescriptors
[16].operation
= 0;
235 IOSetDBDMACommandPtr( ioBaseDMA
, dmaDescriptorsPhys
);
236 IODBDMAContinue( ioBaseDMA
);
240 status
= IOGetDBDMAChannelStatus( ioBaseDMA
);
242 if ( ((status
& kdbdmaActive
) == 0)
243 && ((status
& kdbdmaDead
) == 0)
244 && (OSReadSwapInt32( &dmaDescriptors
[16].operation
, 0 ) == 0x12345678 ))
248 IODBDMAReset( ioBaseDMA
);
253 IOFreeContiguous(dmaDescriptors
, page_size
);
259 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
262 #define super IOService
264 OSDefineMetaClassAndStructors(AppleMacIODevice
, IOService
);
265 OSMetaClassDefineReservedUnused(AppleMacIODevice
, 0);
266 OSMetaClassDefineReservedUnused(AppleMacIODevice
, 1);
267 OSMetaClassDefineReservedUnused(AppleMacIODevice
, 2);
268 OSMetaClassDefineReservedUnused(AppleMacIODevice
, 3);
270 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
272 bool AppleMacIODevice::compareName( OSString
* name
,
273 OSString
** matched
) const
275 return (IODTCompareNubName(this, name
, matched
) ||
276 IORegistryEntry::compareName(name
, matched
));
279 IOService
* AppleMacIODevice::matchLocation( IOService
* /* client */ )
284 IOReturn
AppleMacIODevice::getResources( void )
286 IOService
*macIO
= this;
288 if (getDeviceMemory() != 0) return kIOReturnSuccess
;
290 while (macIO
&& ((macIO
= macIO
->getProvider()) != 0))
291 if (strcmp("mac-io", macIO
->getName()) == 0) break;
293 if (macIO
== 0) return kIOReturnError
;
295 IODTResolveAddressing(this, "reg", macIO
->getDeviceMemoryWithIndex(0));
297 return kIOReturnSuccess
;