Annotation of XNU/iokit/Drivers/pci/drvApplePCI/AppleGracklePCI.cpp, revision 1.1.1.1

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 from objc version.
                     27:  */
                     28:  
                     29: #include <IOKit/system.h>
                     30: 
                     31: #include <libkern/c++/OSContainers.h>
                     32: #include <IOKit/IODeviceMemory.h>
                     33: #include <IOKit/IODeviceTreeSupport.h>
                     34: #include <IOKit/IOLib.h>
                     35: #include <libkern/OSByteOrder.h>
                     36: 
                     37: #include "AppleGracklePCI.h"
                     38: 
                     39: #include <IOKit/assert.h>
                     40: 
                     41: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
                     42: 
                     43: #define super IOPCIBridge
                     44: 
                     45: OSDefineMetaClassAndStructors(AppleGracklePCI, IOPCIBridge)
                     46: 
                     47: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
                     48: 
                     49: bool AppleGracklePCI::start( IOService * provider )
                     50: {
                     51:     IOPCIPhysicalAddress       ioAddrCell;
                     52:     IOPhysicalAddress          ioPhys;
                     53:     IOPhysicalAddress          ioPhysLen;
                     54:     OSArray *                  array;
                     55:     IODeviceMemory::InitElement        rangeList[ 3 ];
                     56:     IORegistryEntry *          bridge;
                     57:     OSData *                   busProp;
                     58:     IOPCIAddressSpace           grackleSpace;
                     59:     UInt32                      picr1;
                     60:                
                     61:     if( 0 == (lock = IOSimpleLockAlloc()))
                     62:        return( false );
                     63: 
                     64:     ioAddrCell.physHi.bits     = 0;
                     65:     ioAddrCell.physHi.s.space  = kIOPCIIOSpace;
                     66:     ioAddrCell.physMid                 = 0;
                     67:     ioAddrCell.physLo          = 0;
                     68:     ioAddrCell.lengthHi        = 0;
                     69:     ioAddrCell.lengthLo        = 0x10000;
                     70: 
                     71:     bridge = provider;
                     72: 
                     73:     if( ! IODTResolveAddressCell( bridge, (UInt32 *) &ioAddrCell,
                     74:                &ioPhys, &ioPhysLen) ) {
                     75: 
                     76:        IOLog("%s: couldn't find my base\n", getName());
                     77:        return( false);
                     78:     }
                     79: 
                     80:     /* define more explicit ranges */
                     81: 
                     82:     rangeList[0].start = ioPhys;
                     83:     rangeList[0].length = ioPhysLen;
                     84:     rangeList[1].start = ioPhys + 0x00c00000;
                     85:     rangeList[1].length = 4;
                     86:     rangeList[2].start = ioPhys + 0x00e00000;
                     87:     rangeList[2].length        = 4;
                     88: 
                     89:     array = IODeviceMemory::arrayFromList( rangeList, 3 );
                     90:     if( !array)
                     91:        return( false);
                     92: 
                     93:     provider->setDeviceMemory( array );
                     94:     array->release();
                     95:     ioMemory = (IODeviceMemory *) array->getObject( 0 );
                     96: 
                     97:     if( (configAddrMap = provider->mapDeviceMemoryWithIndex( 1 )))
                     98:         configAddr = (volatile UInt32 *) configAddrMap->getVirtualAddress();
                     99:     if( (configDataMap = provider->mapDeviceMemoryWithIndex( 2 )))
                    100:         configData = (volatile UInt32 *) configDataMap->getVirtualAddress();
                    101: 
                    102:     if( !configAddr || !configData)
                    103:        return( false);
                    104: 
                    105:     busProp = (OSData *) bridge->getProperty("bus-range");
                    106:     if( busProp)
                    107:        primaryBus = *((UInt32 *) busProp->getBytesNoCopy());
                    108: 
                    109:     // Check to see if there is a set loop snoop property.
                    110:     if( provider->getProperty("set-loop-snoop")) {
                    111:         // Turn on the Loop Snoop bit in PICR1.
                    112:         // See: MPC106 User's Manual p. 3-55.
                    113:         grackleSpace.bits = 0x80000000;
                    114:         picr1 = configRead32(grackleSpace, 0xA8);
                    115:         picr1 |= (1 << 4);
                    116:         configWrite32(grackleSpace, 0xA8, picr1);
                    117:     }
                    118: 
                    119:     return( super::start( provider));
                    120: }
                    121: 
                    122: bool AppleGracklePCI::configure( IOService * provider )
                    123: {
                    124:     bool ok;
                    125: 
                    126:     ok = addBridgeMemoryRange( 0x80000000, 0x7f000000, true );
                    127:     ok = addBridgeIORange( 0, 0x10000 );
                    128: 
                    129:     return( super::configure( provider ));
                    130: }
                    131: 
                    132: void AppleGracklePCI::free()
                    133: {
                    134:     if( configAddrMap)
                    135:        configAddrMap->release();
                    136:     if( configDataMap)
                    137:        configDataMap->release();
                    138:     if( lock)
                    139:        IOSimpleLockFree( lock);
                    140: 
                    141:     super::free();
                    142: }
                    143: 
                    144: IODeviceMemory * AppleGracklePCI::ioDeviceMemory( void )
                    145: {
                    146:     return( ioMemory);
                    147: }
                    148: 
                    149: UInt8 AppleGracklePCI::firstBusNum( void )
                    150: {
                    151:     return( primaryBus );
                    152: }
                    153: 
                    154: UInt8 AppleGracklePCI::lastBusNum( void )
                    155: {
                    156:     return( firstBusNum() );
                    157: }
                    158: 
                    159: IOPCIAddressSpace AppleGracklePCI::getBridgeSpace( void )
                    160: {
                    161:     IOPCIAddressSpace  space;
                    162: 
                    163:     space.bits = 0;
                    164:     space.s.deviceNum = kBridgeSelfDevice;
                    165: 
                    166:     return( space );
                    167: }
                    168: 
                    169: inline void AppleGracklePCI::setConfigSpace( IOPCIAddressSpace space,
                    170:                                        UInt8 offset )
                    171: {
                    172:     IOPCIAddressSpace  addrCycle;
                    173: 
                    174:     addrCycle = space;
                    175:     addrCycle.s.reloc = 1;
                    176:     addrCycle.s.registerNum = offset;
                    177: 
                    178:     OSWriteSwapInt32( configAddr, 0, addrCycle.bits);
                    179:     eieio();
                    180:     OSReadSwapInt32( configAddr, 0 );
                    181:     eieio();
                    182: }
                    183: 
                    184: 
                    185: UInt32 AppleGracklePCI::configRead32( IOPCIAddressSpace space,
                    186:                                        UInt8 offset )
                    187: {
                    188:     UInt32             data;
                    189:     IOInterruptState   ints;
                    190: 
                    191:     ints = IOSimpleLockLockDisableInterrupt( lock );
                    192: 
                    193:     setConfigSpace( space, offset );
                    194: 
                    195:     data = OSReadSwapInt32( configData, 0 );
                    196:     eieio();
                    197: 
                    198:     IOSimpleLockUnlockEnableInterrupt( lock, ints );
                    199:     return( data );
                    200: }
                    201: 
                    202: void AppleGracklePCI::configWrite32( IOPCIAddressSpace space, 
                    203:                                        UInt8 offset, UInt32 data )
                    204: {
                    205:     IOInterruptState ints;
                    206: 
                    207:     ints = IOSimpleLockLockDisableInterrupt( lock );
                    208: 
                    209:     setConfigSpace( space, offset );
                    210: 
                    211:     OSWriteSwapInt32( configData, 0, data );
                    212:     eieio();
                    213:     /* read to sync (?) */
                    214:     (void) OSReadSwapInt32( configData, 0 );
                    215:     eieio();
                    216: 
                    217:     IOSimpleLockUnlockEnableInterrupt( lock, ints );
                    218: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.