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 * 27 */ 28 29 30#ifndef _IOKIT_APPLEMACRISCPCI_H 31#define _IOKIT_APPLEMACRISCPCI_H 32 33#include <IOKit/IOBufferMemoryDescriptor.h> 34#include <IOKit/pci/IOPCIBridge.h> 35 36/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 37 38enum { 39 kHTBridgeSelfDevice = 0, 40 kPCIEBridgeSelfDevice = 0, 41 kPCIBridgeSelfDevice = 11 42}; 43 44enum { 45 kMacRISCHTAddressSelect = 0x80, 46 kMacRISCPCIAddressSelect = 0x48, 47 kMacRISCPCIEAddressSelect = 0xFC, 48 kMacRISCPCIEBridgeRegs = 0x40, 49 kMacRISCPCIModeSelect = 0x50, 50 kMacRISCPCIModeSelectRDGBit = 0x00080000, 51 kMacRISCPCIModeSelectWCBit = 0x00100000 52}; 53 54/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 55 56class AppleMacRiscPCI : public IOPCIBridge 57{ 58 OSDeclareDefaultStructors(AppleMacRiscPCI) 59 60protected: 61 IOSimpleLock * lock; 62 IODeviceMemory * ioMemory; 63 IOMemoryMap * configAddrMap; 64 IOMemoryMap * configDataMap; 65 66 volatile UInt32 * configAddr; 67 volatile UInt8 * configData; 68 69 UInt16 coarseAddressMask; 70 UInt16 fineAddressMask; 71 UInt8 secondaryBus; 72 UInt8 subordinateBus; 73 UInt8 configDataOffsetMask; 74 UInt32 uniNVersion; 75 76 inline bool setConfigSpace( IOPCIAddressSpace space, UInt8 offset ); 77 virtual UInt8 firstBusNum( void ); 78 virtual UInt8 lastBusNum( void ); 79 80public: 81 virtual bool start( IOService * provider ); 82 virtual bool configure( IOService * provider ); 83 84 virtual void free(); 85 86 virtual IODeviceMemory * ioDeviceMemory( void ); 87 88 virtual UInt32 configRead32( IOPCIAddressSpace space, UInt8 offset ); 89 virtual void configWrite32( IOPCIAddressSpace space, 90 UInt8 offset, UInt32 data ); 91 virtual UInt16 configRead16( IOPCIAddressSpace space, UInt8 offset ); 92 virtual void configWrite16( IOPCIAddressSpace space, 93 UInt8 offset, UInt16 data ); 94 virtual UInt8 configRead8( IOPCIAddressSpace space, UInt8 offset ); 95 virtual void configWrite8( IOPCIAddressSpace space, 96 UInt8 offset, UInt8 data ); 97 98 virtual IOPCIAddressSpace getBridgeSpace( void ); 99}; 100 101class AppleMacRiscVCI : public AppleMacRiscPCI 102{ 103 OSDeclareDefaultStructors(AppleMacRiscVCI) 104 105public: 106 virtual bool configure( IOService * provider ); 107 108 virtual IODeviceMemory * ioDeviceMemory( void ); 109 110}; 111 112class AppleMacRiscHT : public IOPCIBridge 113{ 114 OSDeclareDefaultStructors(AppleMacRiscHT) 115 116protected: 117 IOMemoryMap * configType0Map; 118 IOMemoryMap * configType1Map; 119 IOMemoryMap * configSelfMap; 120 IODeviceMemory * ioMemory; 121 122 volatile UInt8 * configType0; 123 volatile UInt8 * configType1; 124 volatile UInt8 * configSelf; 125 126 UInt16 coarseAddressMask; 127 UInt16 fineAddressMask; 128 UInt8 primaryBus; 129 130 inline volatile UInt8 * setConfigSpace( IOPCIAddressSpace space, UInt8 offset ); 131 132public: 133 virtual bool start( IOService * provider ); 134 virtual bool configure( IOService * provider ); 135 136 virtual void free(); 137 138 virtual IODeviceMemory * ioDeviceMemory( void ); 139 140 virtual UInt32 configRead32( IOPCIAddressSpace space, UInt8 offset ); 141 virtual void configWrite32( IOPCIAddressSpace space, 142 UInt8 offset, UInt32 data ); 143 virtual UInt16 configRead16( IOPCIAddressSpace space, UInt8 offset ); 144 virtual void configWrite16( IOPCIAddressSpace space, 145 UInt8 offset, UInt16 data ); 146 virtual UInt8 configRead8( IOPCIAddressSpace space, UInt8 offset ); 147 virtual void configWrite8( IOPCIAddressSpace space, 148 UInt8 offset, UInt8 data ); 149 150 virtual IOPCIAddressSpace getBridgeSpace( void ); 151}; 152 153class AppleMacRiscPCIE : public IOPCIBridge 154{ 155 OSDeclareDefaultStructors(AppleMacRiscPCIE) 156 157protected: 158 IOSimpleLock * lock; 159 IOMemoryMap * hostRegsMap; 160 IOMemoryMap * configAtomicMap; 161 IODeviceMemory * ioMemory; 162 163 volatile UInt8 * hostRegs; 164 volatile UInt8 * configAtomic; 165 volatile UInt32 * configAddrNA; 166 volatile UInt8 * configDataNA; 167 168 UInt16 coarseAddressMask; 169 UInt16 fineAddressMask; 170 UInt8 primaryBus; 171 172 UInt32 bridgeState[kMacRISCPCIEBridgeRegs]; 173 174 inline bool configCycleAtomic( IOPCIAddressSpace space); 175 inline volatile UInt8 * setConfigSpace( IOPCIAddressSpace space, UInt8 offset ); 176 177public: 178 virtual bool start( IOService * provider ); 179 virtual bool configure( IOService * provider ); 180 181 virtual void free(); 182 183 virtual IODeviceMemory * ioDeviceMemory( void ); 184 185 virtual UInt32 configRead32( IOPCIAddressSpace space, UInt8 offset ); 186 virtual void configWrite32( IOPCIAddressSpace space, 187 UInt8 offset, UInt32 data ); 188 virtual UInt16 configRead16( IOPCIAddressSpace space, UInt8 offset ); 189 virtual void configWrite16( IOPCIAddressSpace space, 190 UInt8 offset, UInt16 data ); 191 virtual UInt8 configRead8( IOPCIAddressSpace space, UInt8 offset ); 192 virtual void configWrite8( IOPCIAddressSpace space, 193 UInt8 offset, UInt8 data ); 194 195 virtual IOPCIAddressSpace getBridgeSpace( void ); 196 197 virtual IOReturn setDevicePowerState( IOPCIDevice * device, 198 unsigned long whatToDo ); 199 200 virtual void saveBridgeState( void ); 201 202 virtual void restoreBridgeState( void ); 203}; 204 205/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 206 207/* Definitions of UniNorth Target config registers */ 208enum { 209 kUniNGART_BASE = 0x8c, 210 kUniNAGP_BASE = 0x90, 211 kUniNGART_CTRL = 0x94, 212 kUniNINTERNAL_STATUS = 0x98, 213 kUniNDUMMY_PAGE = 0xa4 214}; 215enum { 216 kGART_INV = 0x00000001, 217 kGART_EN = 0x00000100, 218 kGART_2xRESET = 0x00010000, 219 kGART_DIS_SBA_DET = 0x00020000, 220 kGART_SYNC_MODE = 0x00040000, 221 kGART_PERF_RD = 0x00080000, 222 kGART_B2B_GNT = 0x00200000, 223 kGART_FAST_DDR = 0x00400000 224}; 225 226 227enum { 228 kIOAGP3Mode = 0x00000008, 229 kIOAGP4xDataRateMode3 = 0x00000001, 230 kIOAGP8xDataRateMode3 = 0x00000002, 231}; 232 233class IORangeAllocator; 234 235/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 236 237class AppleMacRiscAGP : public AppleMacRiscPCI 238{ 239 OSDeclareDefaultStructors(AppleMacRiscAGP); 240 241protected: 242 IORangeAllocator * agpRange; 243 UInt32 agpBaseIndex; 244 IOPhysicalAddress systemBase; 245 IOPhysicalLength systemLength; 246 volatile UInt32 * gartArray; 247 IOByteCount gartLength; 248 UInt32 gartCtrl; 249 UInt32 agpCommandMask; 250 UInt32 agpCommandSet; 251 UInt8 targetAGPRegisters; 252 UInt8 isU3; 253 UInt8 isU32; 254 IOBufferMemoryDescriptor * dummyPage; 255 addr64_t dummyPhys; 256 OSData * gartHandle; // Handle returned by IOMapper 257 258private: 259 virtual IOReturn setAGPEnable( IOAGPDevice * master, bool enable, 260 IOOptionBits options = 0 ); 261 262 inline void configSetClearMask( IOPCIAddressSpace space, 263 UInt8 offset, UInt32 data, UInt32 mask ); 264 265public: 266 virtual bool configure( IOService * provider ); 267 268 virtual IOPCIDevice * createNub( OSDictionary * from ); 269 270 virtual IOReturn saveDeviceState( IOPCIDevice * device, 271 IOOptionBits options = 0 ); 272 virtual IOReturn restoreDeviceState( IOPCIDevice * device, 273 IOOptionBits options = 0 ); 274 275 virtual IOReturn createAGPSpace( IOAGPDevice * master, 276 IOOptionBits options, 277 IOPhysicalAddress * address, 278 IOPhysicalLength * length ); 279 280 virtual IOReturn destroyAGPSpace( IOAGPDevice * master ); 281 282 virtual IORangeAllocator * getAGPRangeAllocator( IOAGPDevice * master ); 283 284 virtual IOOptionBits getAGPStatus( IOAGPDevice * master, 285 IOOptionBits options = 0 ); 286 virtual IOReturn resetAGPDevice( IOAGPDevice * master, 287 IOOptionBits options = 0 ); 288 289 virtual IOReturn getAGPSpace( IOAGPDevice * master, 290 IOPhysicalAddress * address, 291 IOPhysicalLength * length ); 292 293 virtual IOReturn commitAGPMemory( IOAGPDevice * master, 294 IOMemoryDescriptor * memory, 295 IOByteCount agpOffset, 296 IOOptionBits options = 0 ); 297 298 virtual IOReturn releaseAGPMemory( IOAGPDevice * master, 299 IOMemoryDescriptor * memory, 300 IOByteCount agpOffset, 301 IOOptionBits options = 0 ); 302 303}; 304 305/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ 306 307#endif /* ! _IOKIT_APPLEMACRISCPCI_H */ 308 309