static errcode GetObject(FILE * dfile, SceneHandle scene) { char objtype[80]; fscanf(dfile, "%s", objtype); if (!stringcmp(objtype, "END_SCENE")) { return PARSEEOF; /* end parsing */ } if (!stringcmp(objtype, "TEXDEF")) { return GetTexDef(dfile); } if (!stringcmp(objtype, "TEXALIAS")) { return GetTexAlias(dfile); } if (!stringcmp(objtype, "BACKGROUND")) { return GetBackGnd(dfile); } if (!stringcmp(objtype, "CYLINDER")) { return GetCylinder(dfile); } if (!stringcmp(objtype, "FCYLINDER")) { return GetFCylinder(dfile); } if (!stringcmp(objtype, "POLYCYLINDER")) { return GetPolyCylinder(dfile); } if (!stringcmp(objtype, "SPHERE")) { return GetSphere(dfile); } if (!stringcmp(objtype, "PLANE")) { return GetPlane(dfile); } if (!stringcmp(objtype, "RING")) { return GetRing(dfile); } if (!stringcmp(objtype, "BOX")) { return GetBox(dfile); } if (!stringcmp(objtype, "SCALARVOL")) { return GetVol(dfile); } if (!stringcmp(objtype, "TRI")) { return GetTri(dfile); } if (!stringcmp(objtype, "STRI")) { return GetSTri(dfile); } if (!stringcmp(objtype, "LIGHT")) { return GetLight(dfile); } if (!stringcmp(objtype, "SCAPE")) { return GetLandScape(dfile); } if (!stringcmp(objtype, "TPOLYFILE")) { return GetTPolyFile(dfile); } fprintf(stderr, "Found bad token: %s expected an object type\n", objtype); return PARSEBADSYNTAX; }
static void Test11(void) { Tree t = { NULL }; Key a; VAR_SLICE(s, MAX_DATA); u64 i; printf("%s\n", __FUNCTION__); for (i = 0; i < LAG; i++) { a = MkKey(i, 0); RandSlice(&s); Put(&t, a, s); PutRing(i); } for (; i < TRYS; i++) { a = MkKey(i, 0); RandSlice(&s); Put(&t, a, s); PutRing(i); a = MkKey(GetRing(), 0); Delete(&t, a); } Dump(WHERE, &t); }
static errcode GetObject(parsehandle * ph, SceneHandle scene) { char objtype[256]; if (fscanf(ph->ifp, "%s", objtype) == EOF) { return PARSEEOF; } if (!stringcmp(objtype, "TRI")) { return GetTri(ph, scene); } if (!stringcmp(objtype, "STRI")) { return GetSTri(ph, scene); } if (!stringcmp(objtype, "VCSTRI")) { return GetVCSTri(ph, scene); } if (!stringcmp(objtype, "SPHERE")) { return GetSphere(ph, scene); } if (!stringcmp(objtype, "FCYLINDER")) { return GetFCylinder(ph, scene); } if (!stringcmp(objtype, "RING")) { return GetRing(ph, scene); } if (!stringcmp(objtype, "POLYCYLINDER")) { return GetPolyCylinder(ph, scene); } if (!stringcmp(objtype, "CYLINDER")) { return GetCylinder(ph, scene); } if (!stringcmp(objtype, "PLANE")) { return GetPlane(ph, scene); } if (!stringcmp(objtype, "BOX")) { return GetBox(ph, scene); } if (!stringcmp(objtype, "SCALARVOL")) { return GetVol(ph, scene); } if (!stringcmp(objtype, "TEXDEF")) { return GetTexDef(ph, scene); } if (!stringcmp(objtype, "TEXALIAS")) { return GetTexAlias(ph); } if (!stringcmp(objtype, "LIGHT")) { return GetLight(ph, scene); } if (!stringcmp(objtype, "DIRECTIONAL_LIGHT")) { return GetDirLight(ph, scene); } if (!stringcmp(objtype, "SPOTLIGHT")) { return GetSpotLight(ph, scene); } if (!stringcmp(objtype, "SCAPE")) { return GetLandScape(ph, scene); } if (!stringcmp(objtype, "CAMERA")) { return GetCamera(ph, scene); } if (!stringcmp(objtype, "TPOLYFILE")) { return GetTPolyFile(ph, scene); } if (!stringcmp(objtype, "MGFFILE")) { #ifdef USELIBMGF return GetMGFFile(ph, scene); #else printf("MGF File Parsing is not available in this build.\n"); return PARSEBADSYNTAX; #endif } if (!stringcmp(objtype, "#")) { int c; while (1) { c=fgetc(ph->ifp); if (c == EOF || c == '\n') /* eat comment text */ return PARSENOERR; } } if (!stringcmp(objtype, "BACKGROUND")) { return GetBackGnd(ph, scene); } if (!stringcmp(objtype, "FOG")) { return GetFog(ph, scene); } if (!stringcmp(objtype, "INCLUDE")) { char includefile[FILENAME_MAX]; fscanf(ph->ifp, "%s", includefile); return ReadIncludeFile(ph, includefile, scene); } if (!stringcmp(objtype, "START_CLIPGROUP")) { return GetClipGroup(ph, scene); } if (!stringcmp(objtype, "END_CLIPGROUP")) { return GetClipGroupEnd(ph, scene); } if (!stringcmp(objtype, "END_SCENE")) { return PARSEEOF; /* end parsing */ } PrintSyntaxError(ph, "an object or other declaration", objtype); return PARSEBADSYNTAX; }
IOReturn CLASS::AddressDevice(uint32_t deviceSlot, uint16_t maxPacketSize, bool wantSAR, uint8_t speed, int32_t highSpeedHubSlot, int32_t highSpeedPort) { ringStruct* pRing; ContextStruct *pContext, *pHubContext; uint32_t routeString; int32_t retFromCMD; uint16_t currentPortOnHub, currentHubAddress, addr; TRBStruct localTrb = { 0 }; pRing = GetRing(deviceSlot, 1, 0U); if (pRing->isInactive()) return kIOReturnInternalError; currentPortOnHub = _deviceZero.PortOnHub; currentHubAddress = _deviceZero.HubAddress; routeString = 0U; for (int32_t depth = 0; depth < 5; ++depth) { if (currentHubAddress == _hub3Address || currentHubAddress == _hub2Address) break; if (currentPortOnHub > kMaxExternalHubPorts) currentPortOnHub = kMaxExternalHubPorts; routeString = (routeString << 4) + currentPortOnHub; addr = currentHubAddress; currentHubAddress = _addressMapper.HubAddress[addr]; currentPortOnHub = _addressMapper.PortOnHub[addr]; } if (currentHubAddress != _hub3Address && currentHubAddress != _hub2Address) { IOLog("%s: Root hub port not found in topology: hub: %u, rootHubSS: %u rootHubHS: %u\n", __FUNCTION__, currentHubAddress, _hub3Address, _hub2Address); return kIOReturnInternalError; } if (!currentPortOnHub || currentPortOnHub > _rootHubNumPorts) { IOLog("%s: Root hub port number invalid: %u\n", __FUNCTION__, currentPortOnHub); return kIOReturnInternalError; } GetInputContext(); pContext = GetInputContextPtr(); pContext->_ic.dwInCtx1 = XHCI_INCTX_1_ADD_MASK(1U) | XHCI_INCTX_1_ADD_MASK(0U); pContext = GetInputContextPtr(1); pContext->_s.dwSctx1 |= XHCI_SCTX_1_RH_PORT_SET(static_cast<uint32_t>(currentPortOnHub)); pContext->_s.dwSctx0 = XHCI_SCTX_0_CTX_NUM_SET(1U); #if 0 uint32_t portSpeed = Read32Reg(&_pXHCIOperationalRegisters->prs[currentPortOnHub - 1U].PortSC); if (m_invalid_regspace) return kIOReturnNoDevice; portSpeed = XHCI_PS_SPEED_GET(portSpeed); if (portSpeed >= XDEV_SS) { SetSlCtxSpeed(pContext, portSpeed); maxPacketSize = 512U; goto skip_low_full; } #else if ((currentHubAddress == _hub3Address) && (speed < kUSBDeviceSpeedSuper || maxPacketSize != 512U)) IOLog("%s: Inconsistent device speed %u (maxPacketSize %u) for topology rooted in SuperSpeed hub\n", __FUNCTION__, speed, maxPacketSize); #endif switch (speed) { case kUSBDeviceSpeedLow: SetSlCtxSpeed(pContext, XDEV_LS); break; case kUSBDeviceSpeedFull: default: SetSlCtxSpeed(pContext, XDEV_FS); break; case kUSBDeviceSpeedHigh: SetSlCtxSpeed(pContext, XDEV_HS); goto skip_low_full; case kUSBDeviceSpeedSuper: SetSlCtxSpeed(pContext, XDEV_SS); goto skip_low_full; } /* * Note: Only for Low or Full Speed devices */ if (highSpeedHubSlot) { pContext->_s.dwSctx2 |= XHCI_SCTX_2_TT_PORT_NUM_SET(highSpeedPort); pContext->_s.dwSctx2 |= XHCI_SCTX_2_TT_HUB_SID_SET(highSpeedHubSlot); pHubContext = GetSlotContext(highSpeedHubSlot); if (pHubContext && XHCI_SCTX_0_MTT_GET(pHubContext->_s.dwSctx0)) pContext->_s.dwSctx0 |= XHCI_SCTX_0_MTT_SET(1U); else pContext->_s.dwSctx0 &= ~XHCI_SCTX_0_MTT_SET(1U); } skip_low_full: #if kMaxActiveInterrupters > 1 pContext->_s.dwSctx2 |= XHCI_SCTX_2_IRQ_TARGET_SET(1U); #endif pContext->_s.dwSctx0 |= XHCI_SCTX_0_ROUTE_SET(routeString); pContext = GetInputContextPtr(2); pContext->_e.dwEpCtx1 |= XHCI_EPCTX_1_EPTYPE_SET(CTRL_EP); pContext->_e.dwEpCtx1 |= XHCI_EPCTX_1_MAXP_SIZE_SET(static_cast<uint32_t>(maxPacketSize)); pContext->_e.qwEpCtx2 |= (pRing->physAddr + pRing->dequeueIndex * sizeof *pRing->ptr) & XHCI_EPCTX_2_TR_DQ_PTR_MASK; if (pRing->cycleState) pContext->_e.qwEpCtx2 |= XHCI_EPCTX_2_DCS_SET(1U); else pContext->_e.qwEpCtx2 &= ~static_cast<uint64_t>(XHCI_EPCTX_2_DCS_SET(1U)); pContext->_e.dwEpCtx1 |= XHCI_EPCTX_1_CERR_SET(3U); pContext->_e.dwEpCtx4 |= XHCI_EPCTX_4_AVG_TRB_LEN_SET(8U); SetTRBAddr64(&localTrb, _inputContext.physAddr); localTrb.d |= XHCI_TRB_3_SLOT_SET(deviceSlot); if (!wantSAR) localTrb.d |= XHCI_TRB_3_BSR_BIT; retFromCMD = WaitForCMD(&localTrb, XHCI_TRB_TYPE_ADDRESS_DEVICE, 0); ReleaseInputContext(); if (retFromCMD == -1) return kIOReturnInternalError; else if (retFromCMD > -1000) return kIOReturnSuccess; else if (retFromCMD == -1000 - XHCI_TRB_ERROR_PARAMETER) { #if 0 PrintContext(GetInputContextPtr()); PrintContext(GetInputContextPtr(1)); PrintContext(GetInputContextPtr(2)); #endif } return TranslateXHCIStatus(-1000 - retFromCMD, deviceSlot, false); }
Int_t KVINDRATelescope::GetRingNumber() const { return (GetRing() ? GetRing()->GetNumber() : 0); }
IOReturn CLASS::UIMCreateControlTransfer(short functionNumber, short endpointNumber, IOUSBCommand* command, IOMemoryDescriptor* CBP, bool /* bufferRounding */, UInt32 bufferSize, short direction) { IOReturn rc; uint32_t mystery; // Note: structure as fourth uint32_t of Transfer TRB uint8_t slot, immediateDataSize; ringStruct* pRing; SetupStageHeader smallbuf1; SetupStageHeader smallbuf2; slot = GetSlotID(functionNumber); if (!slot) return kIOUSBEndpointNotFound; if (endpointNumber) return kIOReturnBadArgument; #if 0 /* * Note: Added Mavericks */ if (!IsStillConnectedAndEnabled(slot)) return kIOReturnNoDevice; #endif pRing = GetRing(slot, 1, 0U); if (pRing->isInactive()) return kIOReturnBadArgument; if (GetNeedsReset(slot)) return AddDummyCommand(pRing, command); if (pRing->deleteInProgress) return kIOReturnNoDevice; if (pRing->epType != CTRL_EP) return kIOUSBEndpointNotFound; XHCIAsyncEndpoint* pAsyncEp = pRing->asyncEndpoint; if (!pAsyncEp) return kIOUSBEndpointNotFound; if (pAsyncEp->aborting) return kIOReturnNotPermitted; if (CBP && bufferSize) { IODMACommand* dmac = command->GetDMACommand(); if (!dmac) { IOLog("%s: no dmaCommand\n", __FUNCTION__); return kIOReturnNoMemory; } IOMemoryDescriptor const* dmac_md = dmac->getMemoryDescriptor(); if (dmac_md != CBP) { IOLog("%s: mismatched CBP (%p) and dmaCommand memory descriptor (%p)\n", __FUNCTION__, CBP, dmac_md); return kIOReturnInternalError; } } bzero(&smallbuf1, sizeof smallbuf1); if (direction == kUSBNone) { if (bufferSize != sizeof smallbuf2) return kIOReturnBadArgument; if (CBP->readBytes(0U, &smallbuf2, sizeof smallbuf2) != sizeof smallbuf2) return kIOReturnInternalError; if (smallbuf2.bmRequestType == 0U && smallbuf2.bRequest == 5U) { /* kSetAddress */ uint16_t deviceAddress = smallbuf2.wValue; ContextStruct* pContext = GetSlotContext(slot, 1); uint16_t maxPacketSize = static_cast<uint16_t>(XHCI_EPCTX_1_MAXP_SIZE_GET(pContext->_e.dwEpCtx1)); pContext = GetSlotContext(slot); _deviceZero.isBeingAddressed = true; rc = AddressDevice(slot, maxPacketSize, true, GetSlCtxSpeed(pContext), XHCI_SCTX_2_TT_HUB_SID_GET(pContext->_s.dwSctx2), XHCI_SCTX_2_TT_PORT_NUM_GET(pContext->_s.dwSctx2)); if (rc != kIOReturnSuccess) return rc; _addressMapper.HubAddress[deviceAddress] = static_cast<uint8_t>(_deviceZero.HubAddress); _addressMapper.PortOnHub[deviceAddress] = static_cast<uint8_t>(_deviceZero.PortOnHub); _addressMapper.Slot[deviceAddress] = static_cast<uint8_t>(slot); _addressMapper.Active[deviceAddress] = true; _deviceZero.HubAddress = 0U; _deviceZero.PortOnHub = 0U; mystery = XHCI_TRB_3_TYPE_SET(XHCI_TRB_TYPE_NOOP) | XHCI_TRB_3_IOC_BIT; immediateDataSize = 0U; } else { mystery = XHCI_TRB_3_TYPE_SET(XHCI_TRB_TYPE_SETUP_STAGE) | XHCI_TRB_3_IDT_BIT | XHCI_TRB_3_IOC_BIT; /* * Set TRT field */ if (smallbuf2.wLength >= 1U) /* * Note: Upper bit of bmRequestType is transfer direction (1 - in, 0 - out) */ mystery |= (smallbuf2.bmRequestType & 0x80U) ? XHCI_TRB_3_TRT_IN : XHCI_TRB_3_TRT_OUT; // else XHCI_TRB_3_TRT_NONE bcopy(&smallbuf2, &smallbuf1, sizeof smallbuf1); immediateDataSize = sizeof smallbuf1; } } else if (bufferSize) { mystery = XHCI_TRB_3_TYPE_SET(XHCI_TRB_TYPE_DATA_STAGE); if (direction == kUSBIn) mystery |= XHCI_TRB_3_DIR_IN; immediateDataSize = 0xFFU; // Note: means data is not immediate } else if (_deviceZero.isBeingAddressed) { _addressMapper.Slot[0] = 0U; _addressMapper.Active[0] = false; _deviceZero.isBeingAddressed = false; mystery = XHCI_TRB_3_TYPE_SET(XHCI_TRB_TYPE_NOOP) | XHCI_TRB_3_IOC_BIT; immediateDataSize = 0U; } else { mystery = XHCI_TRB_3_TYPE_SET(XHCI_TRB_TYPE_STATUS_STAGE) | XHCI_TRB_3_IOC_BIT; if (direction == kUSBIn) mystery |= XHCI_TRB_3_DIR_IN; immediateDataSize = 0U; } rc = pAsyncEp->CreateTDs(command, 0U, mystery, immediateDataSize, reinterpret_cast<uint8_t const*>(&smallbuf1)); pAsyncEp->ScheduleTDs(); return rc; }