|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved. ! 3: * ! 4: * @APPLE_LICENSE_HEADER_START@ ! 5: * ! 6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights ! 7: * Reserved. This file contains Original Code and/or Modifications of ! 8: * Original Code as defined in and that are subject to the Apple Public ! 9: * Source License Version 1.1 (the "License"). You may not use this file ! 10: * except in compliance with the License. Please obtain a copy of the ! 11: * License at http://www.apple.com/publicsource and read it before using ! 12: * this file. ! 13: * ! 14: * The Original Code and all software distributed under the License are ! 15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER ! 16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, ! 17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, ! 18: * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the ! 19: * License for the specific language governing rights and limitations ! 20: * under the License. ! 21: * ! 22: * @APPLE_LICENSE_HEADER_END@ ! 23: */ ! 24: ! 25: /* ! 26: File: rootHubDriver.c ! 27: ! 28: Contains: Temp root hub stuff ! 29: ! 30: Version: 0 ! 31: ! 32: Copyright: � 1997-1998 by Apple Computer, Inc., all rights reserved. ! 33: ! 34: File Ownership: ! 35: ! 36: DRI: Barry Twycross ! 37: ! 38: Other Contact: xxx put other contact here xxx ! 39: ! 40: Technology: USB ! 41: ! 42: Writers: ! 43: ! 44: (TC) Tom Clark ! 45: (DF) David Ferguson ! 46: (CJK) Craig Keithley ! 47: (BT) Barry Twycross ! 48: ! 49: Change History (most recent first): ! 50: ! 51: <USB29> 10/21/98 DF Pass bus number when adding a root hub ! 52: <USB28> 8/25/98 BT Isoc name changes ! 53: <USB27> 8/13/98 BT Add multibus support ! 54: <USB26> 8/12/98 BT Move root hub back into UIM again. (This file only comment ! 55: changed). ! 56: <USB25> 7/10/98 TC Back out previous revision - it was breaking Yosemite. ! 57: <USB24> 6/30/98 BT Move Root hub sim into UIM ! 58: <USB23> 6/14/98 DF Add RemoveRootHub function ! 59: <USB22> 6/5/98 TC Change uxBusRef to USBBusRef. ! 60: <USB21> 5/20/98 BT Fix V2 pb compatability ! 61: <USB20> 5/12/98 BT New interface stuff ! 62: <USB19> 4/9/98 BT Use USB.h ! 63: <USB18> 4/9/98 DF Fix to work with MasterInterfaces ! 64: <17> 4/6/98 BT Change w names ! 65: <16> 4/6/98 BT New param block names ! 66: <15> 2/8/98 BT Power allocation stuff ! 67: <14> 2/5/98 BT Add status notification stuff ! 68: <13> 2/4/98 BT Add ref/port info to expert notify] ! 69: <12> 2/4/98 BT Clean up after TOms changes ! 70: <11> 1/26/98 CJK Change to use USBDeviceDescriptor (instead of just ! 71: devicedescriptor) ! 72: <10> 1/26/98 BT Mangle names after design review ! 73: <9> 1/26/98 BT Make expert notify public ! 74: <8> 1/15/98 BT Now obsolete this, make this root stub which just boots real hub ! 75: driver, which uses hub simulation. ! 76: <7> 1/15/98 BT Better error checking ! 77: <6> 1/15/98 CJK Change include of USL.h to USBServicesLib.h ! 78: <5> 12/23/97 BT Remove obsolete include ! 79: <4> 12/19/97 BT UIM now a Shared lib ! 80: <3> 12/18/97 BT Add expert call back function ! 81: */ ! 82: ! 83: ! 84: #include "../USB.h" ! 85: #include "../USBpriv.h" ! 86: ! 87: #include "../uimpriv.h" /* for root hub stuff */ ! 88: #include "../Library/uslpriv.h" /* for uslDelay */ ! 89: #include "hub.h" ! 90: ! 91: ! 92: typedef struct{ ! 93: USBPB pb; ! 94: UInt32 bus; ! 95: UInt8 * errorString; ! 96: USBDeviceRef hubRef; ! 97: USBDeviceDescriptor desc; ! 98: }rootHub; ! 99: ! 100: #if 1 ! 101: ! 102: /* Incorporate debugging strings */ ! 103: #define noteError(s) rh->errorString = s; ! 104: ! 105: #else ! 106: ! 107: /* eliminate Error strings */ ! 108: #define noteError(s) ! 109: ! 110: #endif ! 111: ! 112: ! 113: ! 114: static Boolean immediateError(OSStatus err) ! 115: { ! 116: return((err != kUSBPending) && (err != noErr) ); ! 117: } ! 118: ! 119: ! 120: static void rootHubAddDeviceHanlder(USBPB *pb) ! 121: { ! 122: rootHub *rh; ! 123: ! 124: rh = (void *)pb; /* parameter block has been extended */ ! 125: if(pb->usbStatus != noErr) ! 126: { ! 127: /* no idea what to do now?? */ ! 128: USBExpertFatalError(rh->hubRef, pb->usbStatus, rh->errorString, 1); ! 129: ! 130: return; ! 131: } ! 132: ! 133: ! 134: do{switch(pb->usbRefcon++) ! 135: { ! 136: case 1: ! 137: rh->hubRef = 0; /* we use zero to add */ ! 138: rh->bus = pb->usbReference; /* remember who we are */ ! 139: pb->usbReference = rh->hubRef; ! 140: ! 141: /* Tell the USL to add the device */ ! 142: pb->usbFlags = 0; /* 1 if low speed, hub never low speed */ ! 143: ! 144: noteError("Root hub Error Calling Add Device"); ! 145: pb->usbOther = rh->bus; ! 146: uslHubAddDevice(pb); ! 147: ! 148: break; ! 149: ! 150: case 2: ! 151: /* We're called back when its time to reset */ ! 152: pb->usbFlags = 0; /* 1 if low speed, hub never low speed */ ! 153: pb->usb.cntl.WValue = 8; /* max packet size, ?? irrelevant ?? */ ! 154: ! 155: UIMResetRootHub(rh->bus); // ***** Do we need this????? ! 156: ! 157: /* Now address the device */ ! 158: noteError("Resetting root hub"); ! 159: if(immediateError(USBHubSetAddress(pb))) ! 160: { ! 161: USBExpertFatalError(rh->hubRef, pb->usbStatus, rh->errorString, 0); ! 162: } ! 163: ! 164: ! 165: break; ! 166: case 3: ! 167: /* refernce is now new device ref, no longer dev zero */ ! 168: ! 169: /* now do a device request to find out what it is */ ! 170: pb->usb.cntl.BMRequestType = USBMakeBMRequestType(kUSBIn, kUSBStandard, kUSBDevice); ! 171: pb->usb.cntl.BRequest = kUSBRqGetDescriptor; ! 172: pb->usb.cntl.WValue = (kUSBDeviceDesc << 8) + 0/*index*/; ! 173: pb->usb.cntl.WIndex = 0; ! 174: pb->usbReqCount = OFFSET(USBDeviceDescriptor, descEnd); ! 175: pb->usbBuffer = &rh->desc; ! 176: ! 177: /* the get descriptor seems to screw up most often */ ! 178: noteError("Getting root hub descriptor"); ! 179: if(immediateError(USBDeviceRequest(pb))) ! 180: { ! 181: USBExpertFatalError(rh->hubRef, pb->usbStatus, rh->errorString, 0); ! 182: } ! 183: break; ! 184: ! 185: case 4: ! 186: /* FInally use the data gathered */ ! 187: /* The root hub has at least the 500mA available to it. */ ! 188: USBExpertInstallDeviceDriver(pb->usbReference, &rh->desc, 0, rh->bus, kUSB500mAAvailable); ! 189: /* Call to the expert */ ! 190: ! 191: UIMSetRootHubRef(pb->usbOther, pb->usbReference); ! 192: PoolDeallocate(rh); ! 193: break; ! 194: default: ! 195: noteError("Root Hub Driver Internal Error unused case in hub handler"); ! 196: USBExpertFatalError(rh->hubRef, kUSBInternalErr, rh->errorString, pb->usbRefcon); ! 197: break; ! 198: } ! 199: break; /* only execute once, unless continue used */ ! 200: }while(1); /* so case can be reentered with a continue */ ! 201: } ! 202: ! 203: OSStatus StartRootHub(UInt32 bus) ! 204: { ! 205: rootHub *deviceAdd; ! 206: ! 207: deviceAdd = PoolAllocateResident(sizeof(rootHub), true); ! 208: if(deviceAdd == nil) ! 209: { ! 210: USBExpertFatalError(bus, kUSBOutOfMemoryErr, "USL - Root hub could not allocate param block", 0); ! 211: } ! 212: ! 213: ! 214: deviceAdd->pb.pbVersion = kUSBCurrentPBVersion; ! 215: deviceAdd->pb.pbLength = sizeof(rootHub); ! 216: deviceAdd->pb.usbStatus = noErr; ! 217: deviceAdd->pb.usbReference = bus; ! 218: deviceAdd->pb.usbCompletion = rootHubAddDeviceHanlder; ! 219: deviceAdd->pb.usbRefcon = 1; ! 220: deviceAdd->pb.usbBuffer = 0; ! 221: rootHubAddDeviceHanlder(&deviceAdd->pb); ! 222: return(kUSBPending); ! 223: } ! 224:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.