|
|
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: * ! 27: */ ! 28: ! 29: ! 30: #ifndef _IOKIT_APPLEOHCI_H ! 31: #define _IOKIT_APPLEOHCI_H ! 32: ! 33: #include <libkern/c++/OSData.h> ! 34: #include <IOKit/IOService.h> ! 35: #include <IOKit/IOInterruptEventSource.h> ! 36: #include <IOKit/pci/IOPCIBridge.h> ! 37: #include <IOKit/pci/IOPCIDevice.h> ! 38: ! 39: #include <IOKit/usb/IOUSBController.h> ! 40: #include <IOKit/usb/USB.h> ! 41: #include <IOKit/usb/USBHub.h> ! 42: ! 43: #include "OHCI.h" ! 44: #include "OHCIRootHub.h" ! 45: ! 46: #define USB_CONSTANT16(x) ((((x) >> 8) & 0x0ff) | ((x & 0xff) << 8)) ! 47: #define MICROSECOND (1) ! 48: #define MILLISECOND (1000) ! 49: ! 50: #ifdef __ppc__ ! 51: #define IOSync eieio ! 52: #endif ! 53: ! 54: extern "C" { ! 55: extern int kvtophys(vm_offset_t); ! 56: extern void delay(int); ! 57: }; ! 58: ! 59: struct InterruptTransaction { ! 60: IOMemoryDescriptor * buf; ! 61: UInt32 bufLen; ! 62: IOUSBCompletion completion; ! 63: }; ! 64: #define kMaxOutstandingTrans 4 ! 65: ! 66: class IONaturalMemoryCursor; ! 67: ! 68: class AppleOHCI : public IOUSBController ! 69: { ! 70: OSDeclareDefaultStructors(AppleOHCI) ! 71: ! 72: protected: ! 73: ! 74: char *usbBuffer; ! 75: IOPCIDevice * _device; ! 76: IOMemoryMap * _deviceBase; ! 77: IONaturalMemoryCursor * _genCursor; ! 78: IONaturalMemoryCursor * _isoCursor; ! 79: OHCIGeneralTransferDescriptorPtr _pendingHead, _pendingTail; ! 80: UInt16 _vendorID; ! 81: UInt16 _deviceID; ! 82: UInt16 _revisionID; ! 83: ! 84: static void OHCIUIMInterruptHandler(OSObject *owner, ! 85: IOInterruptEventSource * source, ! 86: int count); ! 87: void SetVendorInfo(void); ! 88: void finishPending(); ! 89: ! 90: OHCIUIMDataPtr pOHCIUIMData; ! 91: IOInterruptEventSource *interruptSource; ! 92: IOLock * _intLock; ! 93: struct InterruptTransaction _outstandingTrans[kMaxOutstandingTrans]; ! 94: ! 95: IOReturn OHCIUIMControlInitialize(void); ! 96: IOReturn OHCIUIMBulkInitialize (void); ! 97: IOReturn OHCIUIMIsochronousInitialize(void); ! 98: IOReturn OHCIUIMInterruptInitialize (void); ! 99: ! 100: // Memory routines ! 101: UInt32 OHCIUIMGetLogicalAddress(UInt32 pPhysicalAddress); ! 102: UInt32 OHCIUIMGetPhysicalAddress(UInt32 LogicalAddress, ! 103: UInt32 count); ! 104: UInt32 OHCIUIMCreatePhysicalAddress(UInt32 pLogicalAddress, ! 105: UInt32 count); ! 106: IOReturn OHCIUIMAllocateMemory(int num_of_TDs, ! 107: int num_of_EDs, ! 108: int num_of_ITDs); ! 109: void doCallback(OHCIGeneralTransferDescriptorPtr nextTD, ! 110: UInt32 transferStatus, ! 111: UInt32 bufferSizeRemaining); ! 112: UInt32 findBufferRemaining (OHCIGeneralTransferDescriptorPtr pCurrentTD); ! 113: OHCIIsochTransferDescriptorPtr OHCIUIMAllocateITD(void); ! 114: OHCIGeneralTransferDescriptorPtr OHCIUIMAllocateTD(void); ! 115: OHCIEndpointDescriptorPtr OHCIUIMAllocateED(void); ! 116: IOReturn OHCIUIMDeallocateITD (OHCIIsochTransferDescriptorPtr pTD); ! 117: IOReturn OHCIUIMDeallocateTD (OHCIGeneralTransferDescriptorPtr pTD); ! 118: IOReturn OHCIUIMDeallocateED (OHCIEndpointDescriptorPtr pED); ! 119: IOReturn RemoveAllTDs(OHCIEndpointDescriptorPtr pED); ! 120: IOReturn RemoveTDs(OHCIEndpointDescriptorPtr pED); ! 121: IOReturn DoDoneQueueProcessing(OHCIGeneralTransferDescriptorPtr pHCDoneTD, ! 122: IOUSBCompletionAction safeAction); ! 123: void UIMProcessDoneQueue(IOUSBCompletionAction safeAction=0); ! 124: void UIMRootHubStatusChange(void); ! 125: void SimulateRootHubInt( ! 126: UInt8 endpoint, ! 127: IOMemoryDescriptor * buf, ! 128: UInt32 bufLen, ! 129: IOUSBCompletion completion); ! 130: ! 131: OHCIEndpointDescriptorPtr AddEmptyEndPoint( ! 132: UInt8 functionAddress, ! 133: UInt8 endpointNumber, ! 134: UInt16 maxPacketSize, ! 135: UInt8 speed, ! 136: UInt8 direction, ! 137: OHCIEndpointDescriptorPtr pED, ! 138: OHCIEDFormat format); ! 139: ! 140: OHCIEndpointDescriptorPtr FindEndpoint ( ! 141: short functionNumber, ! 142: short endpointNumber, ! 143: short direction, ! 144: OHCIEndpointDescriptorPtr *pEDQueueBack, ! 145: UInt32 *controlMask); ! 146: ! 147: OHCIEndpointDescriptorPtr FindControlEndpoint ( ! 148: short functionNumber, ! 149: short endpointNumber, ! 150: OHCIEndpointDescriptorPtr *pEDBack); ! 151: ! 152: OHCIEndpointDescriptorPtr FindBulkEndpoint ( ! 153: short functionNumber, ! 154: short endpointNumber, ! 155: short direction, ! 156: OHCIEndpointDescriptorPtr *pEDBack); ! 157: ! 158: OHCIEndpointDescriptorPtr FindIsochronousEndpoint( ! 159: short functionNumber, ! 160: short endpointNumber, ! 161: short direction, ! 162: OHCIEndpointDescriptorPtr *pEDBack); ! 163: ! 164: OHCIEndpointDescriptorPtr FindInterruptEndpoint( ! 165: short functionNumber, ! 166: short endpointNumber, ! 167: short direction, ! 168: OHCIEndpointDescriptorPtr *pEDBack); ! 169: ! 170: ! 171: void DoOptiFix(OHCIEndpointDescriptorPtr pIsochHead); ! 172: void OptiLSHSFix(void); ! 173: void dumpRegs(void); ! 174: bool DetermineInterruptOffset(UInt32 pollingRate, ! 175: UInt32 reserveBandwidth, ! 176: int *offset); ! 177: void ReturnTransactions( ! 178: OHCIGeneralTransferDescriptor *transaction, ! 179: UInt32 tail); ! 180: ! 181: public: ! 182: bool init(OSDictionary * propTable); ! 183: ! 184: /* ! 185: * UIM methods ! 186: */ ! 187: IOReturn UIMInitialize(IOService * provider); ! 188: IOReturn UIMFinalize(); ! 189: // Control ! 190: virtual IOReturn UIMCreateControlEndpoint( ! 191: UInt8 functionNumber, ! 192: UInt8 endpointNumber, ! 193: UInt16 maxPacketSize, ! 194: UInt8 speed); ! 195: ! 196: virtual IOReturn UIMCreateControlTransfer( ! 197: short functionNumber, ! 198: short endpointNumber, ! 199: IOUSBCompletion completion, ! 200: void * CBP, ! 201: bool bufferRounding, ! 202: UInt32 bufferSize, ! 203: short direction); ! 204: ! 205: virtual IOReturn UIMCreateControlTransfer( ! 206: short functionNumber, ! 207: short endpointNumber, ! 208: IOUSBCompletion completion, ! 209: IOMemoryDescriptor * CBP, ! 210: bool bufferRounding, ! 211: UInt32 bufferSize, ! 212: short direction); ! 213: ! 214: // Bulk ! 215: virtual IOReturn UIMCreateBulkEndpoint( ! 216: UInt8 functionNumber, ! 217: UInt8 endpointNumber, ! 218: UInt8 direction, ! 219: UInt8 speed, ! 220: UInt8 maxPacketSize); ! 221: ! 222: virtual IOReturn UIMCreateBulkTransfer( ! 223: short functionNumber, ! 224: short endpointNumber, ! 225: IOUSBCompletion completion, ! 226: IOMemoryDescriptor * CBP, ! 227: bool bufferRounding, ! 228: UInt32 bufferSize, ! 229: short direction); ! 230: ! 231: virtual IOReturn UIMCreateGeneralTransfer( ! 232: OHCIEndpointDescriptorPtr queue, ! 233: IOUSBCompletion completion, ! 234: IOMemoryDescriptor * CBP, ! 235: UInt32 bufferSize, ! 236: UInt32 flags, ! 237: UInt32 type, ! 238: UInt32 kickBits); ! 239: ! 240: // Interrupt ! 241: virtual IOReturn UIMCreateInterruptEndpoint( ! 242: short functionAddress, ! 243: short endpointNumber, ! 244: UInt8 direction, ! 245: short speed, ! 246: UInt16 maxPacketSize, ! 247: short pollingRate); ! 248: ! 249: virtual IOReturn UIMCreateInterruptTransfer( ! 250: short functionNumber, ! 251: short endpointNumber, ! 252: IOUSBCompletion completion, ! 253: IOMemoryDescriptor * CBP, ! 254: bool bufferRounding, ! 255: UInt32 bufferSize, ! 256: short direction); ! 257: ! 258: // Isoch ! 259: virtual IOReturn UIMCreateIsochEndpoint( ! 260: short functionAddress, ! 261: short endpointNumber, ! 262: UInt32 maxPacketSize, ! 263: UInt8 direction); ! 264: ! 265: virtual IOReturn UIMCreateIsochTransfer( ! 266: short functionAddress, ! 267: short endpointNumber, ! 268: IOUSBIsocCompletion completion, ! 269: UInt8 direction, ! 270: UInt64 frameStart, ! 271: IOMemoryDescriptor * pBuffer, ! 272: UInt32 frameCount, ! 273: IOUSBIsocFrame *pFrames); ! 274: ! 275: virtual IOReturn UIMAbortEndpoint( ! 276: short functionNumber, ! 277: short endpointNumber, ! 278: short direction); ! 279: virtual IOReturn UIMDeleteEndpoint( ! 280: short functionNumber, ! 281: short endpointNumber, ! 282: short direction); ! 283: virtual IOReturn UIMClearEndpointStall( ! 284: short functionNumber, ! 285: short endpointNumber, ! 286: short direction); ! 287: /* ! 288: * Root hub methods ! 289: */ ! 290: IOReturn getRootHubDeviceDescriptor(IOUSBDeviceDescriptor *desc); ! 291: IOReturn getRootHubDescriptor(IOUSBHubDescriptor *desc); ! 292: IOReturn setRootHubDescriptor(OSData *buffer); ! 293: IOReturn getRootHubConfDescriptor(OSData *desc); ! 294: IOReturn getRootHubStatus(IOUSBHubStatus *status); ! 295: IOReturn setRootHubFeature(UInt16 wValue); ! 296: IOReturn clearRootHubFeature(UInt16 wValue); ! 297: IOReturn getRootHubPortStatus(IOUSBHubPortStatus *status, UInt16 port); ! 298: IOReturn setRootHubPortFeature(UInt16 wValue, UInt16 port); ! 299: IOReturn clearRootHubPortFeature(UInt16 wValue, UInt16 port); ! 300: IOReturn getRootHubPortState(UInt8 *state, UInt16 port); ! 301: IOReturn setHubAddress(UInt16 wValue); ! 302: ! 303: void OHCIRootHubPower(bool on); ! 304: void OHCIRootHubResetChangeConnection(UInt16 port); ! 305: void OHCIRootHubResetResetChange(UInt16 port); ! 306: void OHCIRootHubResetSuspendChange(UInt16 port); ! 307: void OHCIRootHubResetEnableChange(UInt16 port); ! 308: void OHCIRootHubResetOverCurrentChange(UInt16 port); ! 309: void OHCIRootHubResetPort (UInt16 port); ! 310: void OHCIRootHubPortEnable(UInt16 port, bool on); ! 311: void OHCIRootHubPortSuspend(UInt16 port, bool on); ! 312: void OHCIRootHubPortPower(UInt16 port, bool on); ! 313: ! 314: virtual UInt32 GetBandwidthAvailable(); ! 315: virtual UInt64 GetFrameNumber(); ! 316: virtual UInt32 GetFrameNumber32(); ! 317: ! 318: virtual void pollInterrupts(IOUSBCompletionAction safeAction=0); ! 319: ! 320: }; ! 321: ! 322: #endif /* _IOKIT_APPLEOHCI_H */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.