|
|
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) 1999 Apple Computer, Inc. All rights reserved. ! 24: * ! 25: * HISTORY ! 26: * 21 May 99 wgulland created. ! 27: * ! 28: */ ! 29: ! 30: #define DEBUGGING_LEVEL 0 // 1 = low; 2 = high; 3 = extreme ! 31: #define DEBUGLOG kprintf ! 32: #include <IOKit/assert.h> ! 33: ! 34: #include <IOKit/IOMessage.h> ! 35: #include <IOKit/firewire/IOFireWireNub.h> ! 36: #include <IOKit/firewire/IOFireWireController.h> ! 37: #include "IOFireWireUserClient.h" ! 38: ! 39: #define super IOService ! 40: ! 41: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ ! 42: ! 43: OSDefineMetaClass( IOFireWireNub, IOService ) ! 44: OSDefineAbstractStructors(IOFireWireNub, IOService) ! 45: ! 46: /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ ! 47: ! 48: bool IOFireWireNub::init(OSDictionary * propTable) ! 49: { ! 50: OSNumber *offset; ! 51: if( !super::init(propTable)) ! 52: return (false); ! 53: ! 54: offset = OSDynamicCast(OSNumber, propTable->getObject("GUID")); ! 55: if(offset) ! 56: fUniqueID = offset->unsigned64BitValue(); ! 57: ! 58: return true; ! 59: } ! 60: ! 61: IOFWSpeed IOFireWireNub::FWSpeed() const ! 62: { ! 63: return fControl->FWSpeed(fNodeID); ! 64: } ! 65: ! 66: // How fast can this node talk to another node? ! 67: IOFWSpeed IOFireWireNub::FWSpeed(const IOFireWireNub *dst) const ! 68: { ! 69: return fControl->FWSpeed(fNodeID, dst->fNodeID); ! 70: } ! 71: ! 72: // How big (as a power of two) can packets sent to the node be? ! 73: int IOFireWireNub::maxPackLog(bool forSend) const ! 74: { ! 75: return fControl->maxPackLog(forSend, fNodeID); ! 76: } ! 77: ! 78: // How big (as a power of two) can packets sent between nodes be? ! 79: int IOFireWireNub::maxPackLog(bool forSend, const IOFireWireNub *dst) const ! 80: { ! 81: if(forSend) ! 82: return fControl->maxPackLog(fNodeID, dst->fNodeID); ! 83: else ! 84: return fControl->maxPackLog(dst->fNodeID, fNodeID); ! 85: } ! 86: ! 87: IOFWReadCommand *IOFireWireNub::createReadCommand(FWAddress devAddress, IOMemoryDescriptor *hostMem, ! 88: FWDeviceCallback completion, void *refcon, ! 89: bool failOnReset) ! 90: { ! 91: IOFWReadCommand * cmd; ! 92: cmd = new IOFWReadCommand; ! 93: if(cmd) { ! 94: if(!cmd->initAll(this, devAddress, hostMem, completion, refcon, failOnReset)) { ! 95: cmd->release(); ! 96: cmd = NULL; ! 97: } ! 98: } ! 99: return cmd; ! 100: } ! 101: ! 102: IOFWReadQuadCommand *IOFireWireNub::createReadQuadCommand(FWAddress devAddress, UInt32 *quads, int numQuads, ! 103: FWDeviceCallback completion, void *refcon, ! 104: bool failOnReset) ! 105: { ! 106: IOFWReadQuadCommand * cmd; ! 107: cmd = new IOFWReadQuadCommand; ! 108: if(cmd) { ! 109: if(!cmd->initAll(fControl, this, devAddress, quads, numQuads, ! 110: completion, refcon, failOnReset)) { ! 111: cmd->release(); ! 112: cmd = NULL; ! 113: } ! 114: } ! 115: return cmd; ! 116: } ! 117: ! 118: IOFWWriteCommand *IOFireWireNub::createWriteCommand(FWAddress devAddress, IOMemoryDescriptor *hostMem, ! 119: FWDeviceCallback completion, void *refcon, ! 120: bool failOnReset) ! 121: { ! 122: IOFWWriteCommand * cmd; ! 123: cmd = new IOFWWriteCommand; ! 124: if(cmd) { ! 125: if(!cmd->initAll(this, devAddress, hostMem, completion, refcon, failOnReset)) { ! 126: cmd->release(); ! 127: cmd = NULL; ! 128: } ! 129: } ! 130: return cmd; ! 131: } ! 132: ! 133: IOFWWriteQuadCommand *IOFireWireNub::createWriteQuadCommand(FWAddress devAddress, ! 134: UInt32 *quads, int numQuads, ! 135: FWDeviceCallback completion, void *refcon, ! 136: bool failOnReset) ! 137: { ! 138: IOFWWriteQuadCommand * cmd; ! 139: cmd = new IOFWWriteQuadCommand; ! 140: if(cmd) { ! 141: if(!cmd->initAll(fControl, this, devAddress, quads, numQuads, ! 142: completion, refcon, failOnReset)) { ! 143: cmd->release(); ! 144: cmd = NULL; ! 145: } ! 146: } ! 147: return cmd; ! 148: } ! 149: ! 150: IOFWCompareAndSwapCommand * ! 151: IOFireWireNub::createCompareAndSwapCommand(FWAddress devAddress, const UInt32 *cmpVal, const UInt32 *newVal, ! 152: int size, FWDeviceCallback completion, void *refcon, bool failOnReset) ! 153: { ! 154: IOFWCompareAndSwapCommand * cmd; ! 155: cmd = new IOFWCompareAndSwapCommand; ! 156: if(cmd) { ! 157: if(!cmd->initAll(this, devAddress, cmpVal, newVal, size, completion, refcon, failOnReset)) { ! 158: cmd->release(); ! 159: cmd = NULL; ! 160: } ! 161: } ! 162: return cmd; ! 163: } ! 164: ! 165: /* ! 166: * Create local FireWire address spaces for the device to access ! 167: */ ! 168: IOFWPhysicalAddressSpace *IOFireWireNub::createPhysicalAddressSpace(IOMemoryDescriptor *mem) ! 169: { ! 170: IOFWPhysicalAddressSpace *space; ! 171: space = new IOFWPhysicalAddressSpace; ! 172: if(!space) ! 173: return NULL; ! 174: if(!space->initWithDesc(mem)) { ! 175: space->release(); ! 176: space = NULL; ! 177: } ! 178: return space; ! 179: } ! 180: ! 181: IOFWPseudoAddressSpace *IOFireWireNub::createPseudoAddressSpace(FWAddress addr, UInt32 len, ! 182: FWReadCallback reader, FWWriteCallback writer, void *refcon) ! 183: { ! 184: IOFWPseudoAddressSpace *space; ! 185: space = new IOFWPseudoAddressSpace; ! 186: if(!space) ! 187: return NULL; ! 188: if(!space->initAll(addr, len, reader, writer, refcon)) { ! 189: space->release(); ! 190: space = NULL; ! 191: } ! 192: return space; ! 193: } ! 194: ! 195: /* ! 196: * Create commands to activate/deactivate local FireWire address spaces ! 197: */ ! 198: IOFWAllocAddressCommand *IOFireWireNub::createAllocAddrCommand(IOFWAddressSpace *space, ! 199: FWBusCallback completion, void *refcon) ! 200: { ! 201: IOFWAllocAddressCommand * cmd; ! 202: cmd = new IOFWAllocAddressCommand; ! 203: if(cmd) { ! 204: if(!cmd->initWithSpace(this, space, completion, refcon)) { ! 205: cmd->release(); ! 206: cmd = NULL; ! 207: } ! 208: } ! 209: return cmd; ! 210: } ! 211: ! 212: IOFWDeallocAddressCommand *IOFireWireNub::createDeallocAddrCommand(IOFWAddressSpace *space, ! 213: FWBusCallback completion, void *refcon) ! 214: { ! 215: IOFWDeallocAddressCommand * cmd; ! 216: cmd = new IOFWDeallocAddressCommand; ! 217: if(cmd) { ! 218: if(!cmd->initWithSpace(this, space, completion, refcon)) { ! 219: cmd->release(); ! 220: cmd = NULL; ! 221: } ! 222: } ! 223: return cmd; ! 224: } ! 225: ! 226: ! 227: /* ! 228: * Create an iterator for the device ROM ! 229: */ ! 230: IOReturn IOFireWireNub::CSRROMCreateIterator (CSRROMEntryIterator *pCSRROMIterator) ! 231: { ! 232: CSRROMEntryIteratorRecPtr pIteratorRec; ! 233: UInt32 hdrSize; ! 234: ! 235: // Allocate memory for iterator record. ! 236: pIteratorRec = (CSRROMEntryIteratorRecPtr)IOMalloc (sizeof (CSRROMEntryIteratorRec)); ! 237: if (pIteratorRec == NULL) ! 238: return kIOReturnNoMemory; ! 239: ! 240: // Fill in other record fields. ! 241: // Set relationship to descendants. ! 242: pIteratorRec->relationship = kIterateDescendants; ! 243: // Find start of root directory. ! 244: hdrSize = ((fROM[0] & kCSRBusInfoBlockLength) >> kCSRBusInfoBlockLengthPhase) + 1; ! 245: pIteratorRec->data = fROM; ! 246: pIteratorRec->logicalPath[0] = 0; ! 247: pIteratorRec->physicalPath[0] = hdrSize; ! 248: ! 249: pIteratorRec->logicalPath[1] = 0; ! 250: pIteratorRec->physicalPath[1] = pIteratorRec->physicalPath[0] + 1; ! 251: ! 252: pIteratorRec->pathSize = 2; ! 253: pIteratorRec->reset = true; ! 254: ! 255: // Return iterator. ! 256: *pCSRROMIterator = (CSRROMEntryIterator) pIteratorRec; ! 257: ! 258: return (kIOReturnSuccess); ! 259: } ! 260: ! 261: ! 262: /** ! 263: ** IOUserClient methods ! 264: **/ ! 265: ! 266: IOReturn IOFireWireNub::newUserClient(task_t owningTask, ! 267: void * /* security_id */, ! 268: UInt32 type, ! 269: IOUserClient ** handler ) ! 270: ! 271: { ! 272: IOReturn err = kIOReturnSuccess; ! 273: IOFireWireUserClient * client; ! 274: ! 275: if( type != 11) ! 276: return( kIOReturnBadArgument); ! 277: ! 278: client = IOFireWireUserClient::withTask(owningTask); ! 279: ! 280: if( !client || (false == client->attach( this )) || ! 281: (false == client->start( this )) ) { ! 282: if(client) { ! 283: client->detach( this ); ! 284: client->release(); ! 285: } ! 286: err = kIOReturnNoMemory; ! 287: } ! 288: ! 289: *handler = client; ! 290: return( err ); ! 291: } ! 292: ! 293:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.