|
|
1.1 root 1: /*
2: * Copyright (c) 1998-2000 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
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.
11: *
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
18: * under the License.
19: *
20: * @APPLE_LICENSE_HEADER_END@
21: */
22: /*
23: * Copyright (c) 1998 Apple Computer, Inc. All rights reserved.
24: *
25: * HISTORY
26: * 23 Nov 98 sdouglas created.
27: */
28:
29: #include <IOKit/system.h>
30: extern "C" {
31: #include <pexpert/pexpert.h>
32: }
33:
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>
39:
40: #include <IOKit/pci/IOPCIDevice.h>
41:
42: #include <IOKit/platform/AppleMacIO.h>
43:
44: #include <IOKit/ppc/IODBDMA.h>
45:
46: #include <assert.h>
47:
48: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
49:
50: #define super IOService
51:
52: OSDefineMetaClass(AppleMacIO, IOService);
53: OSDefineAbstractStructors(AppleMacIO, IOService);
54:
55: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
56:
57: bool AppleMacIO::start( IOService * provider )
58: {
59: IOPCIDevice *pciNub = (IOPCIDevice *)provider;
60:
61: if( !super::start( provider))
62: return( false);
63:
64: // Make sure memory space is on.
65: pciNub->setMemoryEnable(true);
66:
67: fNub = provider;
68: fMemory = provider->mapDeviceMemoryWithIndex( 0 );
69: if( 0 == fMemory)
70: IOLog("%s: unexpected ranges\n", getName());
71: else if( !selfTest())
72: IOLog("Warning: AppleMacIO self test fails\n");
73:
74: return( true);
75: }
76:
77: IOService * AppleMacIO::createNub( IORegistryEntry * from )
78: {
79: IOService * nub;
80:
81: nub = new AppleMacIODevice;
82:
83: if( nub && !nub->init( from, gIODTPlane )) {
84: nub->free();
85: nub = 0;
86: }
87:
88: return( nub);
89: }
90:
91: void AppleMacIO::processNub(IOService * /*nub*/)
92: {
93: }
94:
95: const char * AppleMacIO::deleteList ( void )
96: {
97: return( "('sd', 'st', 'disk', 'tape', 'adb', 'pram', 'rtc', 'power-mgt')" );
98: }
99:
100: const char * AppleMacIO::excludeList( void )
101: {
102: return( 0 );
103: }
104:
105: void AppleMacIO::publishBelow( IORegistryEntry * root )
106: {
107: OSCollectionIterator * kids;
108: IORegistryEntry * next;
109: IOService * nub;
110:
111: // infanticide
112: kids = IODTFindMatchingEntries( root, kIODTRecursive, deleteList() );
113: if( kids) {
114: while( (next = (IORegistryEntry *)kids->getNextObject())) {
115: next->detachAll( gIODTPlane);
116: }
117: kids->release();
118: }
119:
120: // publish everything below, minus excludeList
121: kids = IODTFindMatchingEntries( root, kIODTRecursive | kIODTExclusive,
122: excludeList());
123: if( kids) {
124: while( (next = (IORegistryEntry *)kids->getNextObject())) {
125:
126: if( 0 == (nub = createNub( next )))
127: continue;
128:
129: nub->attach( this );
130:
131: processNub(nub);
132:
133: nub->registerService();
134: }
135: kids->release();
136: }
137: }
138:
139: bool AppleMacIO::compareNubName( const IOService * nub,
140: OSString * name, OSString ** matched ) const
141: {
142: return( IODTCompareNubName( nub, name, matched )
143: || nub->IORegistryEntry::compareName( name, matched ) );
144: }
145:
146: IOReturn AppleMacIO::getNubResources( IOService * nub )
147: {
148: if( nub->getDeviceMemory())
149: return( kIOReturnSuccess );
150:
151: IODTResolveAddressing( nub, "reg", fNub->getDeviceMemoryWithIndex(0) );
152:
153: return( kIOReturnSuccess);
154: }
155:
156: bool AppleMacIO::selfTest( void )
157: {
158: IODBDMADescriptor *dmaDescriptors;
159: UInt32 dmaDescriptorsPhys;
160: UInt32 i;
161: UInt32 status;
162: IODBDMADescriptor *dmaDesc;
163: volatile IODBDMAChannelRegisters *ioBaseDMA;
164: bool ok = false;
165: enum { kTestChannel = 0x8000 };
166:
167: ioBaseDMA = (volatile IODBDMAChannelRegisters *)
168: (((UInt32)fMemory->getVirtualAddress())
169: + kTestChannel );
170:
171: do {
172: dmaDescriptors = (IODBDMADescriptor *)IOMallocContiguous(page_size, 1, & dmaDescriptorsPhys);
173: if (!dmaDescriptors)
174: continue;
175:
176: if ( (UInt32)dmaDescriptors & (page_size - 1) ) {
177: IOLog("AppleMacIO::%s() - DMA Descriptor memory not page aligned!!", __FUNCTION__);
178: continue;
179: }
180:
181: bzero( dmaDescriptors, page_size );
182:
183: IODBDMAReset( ioBaseDMA );
184:
185: dmaDesc = dmaDescriptors;
186:
187: IOMakeDBDMADescriptor( dmaDesc,
188: kdbdmaNop,
189: kdbdmaKeyStream0,
190: kdbdmaIntNever,
191: kdbdmaBranchNever,
192: kdbdmaWaitNever,
193: 0,
194: 0 );
195:
196: dmaDesc++;
197:
198: IOMakeDBDMADescriptorDep( dmaDesc,
199: kdbdmaStoreQuad,
200: kdbdmaKeySystem,
201: kdbdmaIntNever,
202: kdbdmaBranchNever,
203: kdbdmaWaitNever,
204: 4,
205: dmaDescriptorsPhys+16*sizeof(IODBDMADescriptor),
206: 0x12345678 );
207:
208: dmaDesc++;
209:
210: IOMakeDBDMADescriptor( dmaDesc,
211: kdbdmaStop,
212: kdbdmaKeyStream0,
213: kdbdmaIntNever,
214: kdbdmaBranchNever,
215: kdbdmaWaitNever,
216: 0,
217: 0 );
218:
219:
220: for ( i = 0; (!ok) && (i < 3); i++ )
221: {
222: dmaDescriptors[16].operation = 0;
223:
224: IOSetDBDMACommandPtr( ioBaseDMA, dmaDescriptorsPhys );
225: IODBDMAContinue( ioBaseDMA );
226:
227: IODelay( 200 );
228:
229: status = IOGetDBDMAChannelStatus( ioBaseDMA );
230:
231: if ( ((status & kdbdmaActive) == 0)
232: && ((status & kdbdmaDead) == 0)
233: && (OSReadSwapInt32( &dmaDescriptors[16].operation, 0 ) == 0x12345678 ))
234: ok = true;
235: }
236:
237: IODBDMAReset( ioBaseDMA );
238:
239: } while (false);
240:
241: if (dmaDescriptors)
242: IOFreeContiguous(dmaDescriptors, page_size);
243:
244:
245: return ok;
246: }
247:
248: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
249:
250: #undef super
251: #define super IOService
252:
253: OSDefineMetaClassAndStructors(AppleMacIODevice, IOService);
254:
255: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
256:
257: bool AppleMacIODevice::compareName( OSString * name,
258: OSString ** matched = 0 ) const
259: {
260: return( ((AppleMacIO *)getProvider())->
261: compareNubName( this, name, matched ));
262: }
263:
264: IOService * AppleMacIODevice::matchLocation( IOService * /* client */ )
265: {
266: return( this );
267: }
268:
269: IOReturn AppleMacIODevice::getResources( void )
270: {
271: return( ((AppleMacIO *)getProvider())->getNubResources( this ));
272: }
273:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.