?? usbhubclassinterface.c
字號:
}/* End of if (NULL == pParentHub ) */ /* Search for the DeviceID in the parent hub. If failed return. */ /* * HUB_FindPortNumber() to find the port number for this device handle. * If this is not found, then return USBHST_INVALID_PARAMETER. */ uPortIndex = usbHubFindPortNumber(pParentHub,uDeviceHandle); /* Check if the port is found */ if (USB_PORT_NUMBER_NOT_FOUND == uPortIndex) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB,"usbHubSelectiveResumeDevice: port number not found\n",0,0,0,0); return USBHST_INVALID_PARAMETER; } /* End of if (PORT_NUM.. */ /* Check if the port number is within limits */ if (uPortIndex > (pParentHub->HubDescriptor.bNbrPorts)) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "HUB_SelectiveResumeDevice:port=%d > %d\n", uPortIndex, pParentHub->HubDescriptor.bNbrPorts, 0, 0); return USBHST_INVALID_PARAMETER; } /* End of (uPortIndex > (pParentHub->.... */ /* * Retrieve HUB_INFO structure from * parentHub::pPortList[uPortIndex]::pHub. */ pPort = pParentHub->pPortList[uPortIndex]; OS_ASSERT( NULL == pPort->pHub); /* Verify */ /* * Call the HUB_SubmitFeature() function to submit a selective resume to * the parent hub on the port number. * Note: actual port number is 1 more than the port index. */ Result = USB_HUB_CLEAR_PORT_FEATURE(pParentHub,uPortIndex,USB_PORT_SUSPEND); /* resume recovery period of 10 ms */ OS_DELAY_MS(10); /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Exiting usbHubSelectiveResumeDevice() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "HUB_SelectiveResumeDevice: Called devH=0x%x\n", uDeviceHandle, 0, 0, 0); /* Return the result of the submission.*/ return Result;} /* End of function HUB_SelectiveResumeDevice() *//***************************************************************************** usbHubAddRoot - configures the root hub** This function is called by the USB Host Software Stack for adding a new root* hub. In this process, it configures the root hub and also initializes the* structures to handle the bus under the root hub.** RETURNS: N/A** ERRNO: None** \NOMANUAL*/LOCAL USBHST_STATUS usbHubAddRoot ( UINT32 uDeviceHandle, UINT8 uBusHandle, UINT8 uSpeed ) { /* Bus List pointer */ pUSB_HUB_BUS_INFO pBus = NULL; /* Hub pointer */ pUSB_HUB_INFO pRootHub = NULL; /* Results */ USBHST_STATUS Result = USBHST_FAILURE; /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Entering usbHubAddRoot() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubAddRoot: Called devH=0x%x BusH=0x%x\n", uDeviceHandle, uBusHandle, 0, 0); /* * Call the HUB_CreateBusStructure() function to create * HUB_BUS_INFO structure. If this fails, then return * USBHST_INVALID_PARAMETER. */ pBus = usbHubCreateBusStructure (uBusHandle); if (NULL == pBus) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "usbHubAddRoot: Bus Structure was not created.Duplicate bus id?\n", 0, 0, 0, 0); return USBHST_INVALID_PARAMETER; } /* Update the HUB_BUS_INFO::uDeviceHandle with the uDeviceHandle.*/ pBus->uDeviceHandle = uDeviceHandle; /* * Call the HUB_ConfigureHub() function to configure the hub. * If the configuration fails then * i. Call the HUB_DeleteBusStructure() function. * ii. Return the result of the configuration. */ Result=usbHubConfigure(&pRootHub,uDeviceHandle,pBus,NULL); /* Check the result */ if ((USBHST_SUCCESS != Result)|| (NULL == pRootHub) ) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubAddRoot: Configuring root hub failed=0x%x\n", Result, 0, 0, 0); /* Delete the Bus structure */ usbHubDeleteBusStructure(uBusHandle); /* return the failure result */ return Result; } /* End of if ((USBHST_SUCCESS != Result)|| (NULL == pRootHub) ) */ /* * Set the BUS_INFO::uBusSpeed as the uSpeed */ pBus->uBusSpeed = uSpeed; /* * Set the BUS_INFO::pRootHubInfo as HUB_INFO structure returned by the * HUB_ConfigureHub() function. */ pBus->pRootHubInfo=pRootHub; /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Exiting usbHubAddRoot() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "HUB_AddRootHub: Done devH=0x%x BusH=0x%x\n", uDeviceHandle, uBusHandle, 0, 0); /* Return USBHST_SUCCESS */ return USBHST_SUCCESS; } /* End of function HUB_AddRootHub() *//***************************************************************************** usbHubRemoveRoot - removes the root hub.** This function is called by the USB Host Software Stack for removing a root* hub.** RETURNS: N/A** ERRNO: None** \NOMANUAL*/LOCAL void usbHubRemoveRoot ( UINT8 uBusHandle ) { /* Bus List pointer */ pUSB_HUB_BUS_INFO pBusList = gpGlobalBus; /* Root hub structure */ pUSB_HUB_INFO pRootHub = NULL; /* Port counter */ UINT8 uPortCount = 0; /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Entering usbHubRemoveRoot() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubRemoveRoot: Called BusH=0x%x\n", uBusHandle, 0, 0, 0); /* * Scan through the gpGlobalBus to find the matching HUB_BUS_INFO structure * for the uBusHandle. If not found return. */ while (NULL != pBusList) { /* Check for duplicate entries */ if (pBusList->uBusHandle == uBusHandle) { /* Jump out of the loop */ break; } /* End of if (pBusList->....*/ /* Move the pointer to the next bus */ pBusList=pBusList->pNextBus; } /* End of While (NULL != pBusList) */ /* Check if we found the bus */ if (NULL==pBusList) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB,"usbHubRemoveRoot: BUS NOT FOUND \n",0,0,0,0); /* nope.. we did nto find the bus, so we return */ return; } /* End of if (NULL==pBusList) */ /* Retrieve the HUB_INFO structure from the HUB_BUS_INFO structure.*/ pRootHub = pBusList->pRootHubInfo; if (NULL == pRootHub) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB,"usbHubRemoveRoot: root hub NOT FOUND \n",0,0,0,0); /* Call the HUB_DeleteBusStructure() function to delete bus structure. */ usbHubDeleteBusStructure(uBusHandle); return; } /* * Call the USBHST_CancelURB() function to cancel the Status change * interrupt IN request URB. */ usbHstURBCancel(&(pRootHub->StatusChangeURB) ); /* * If any of the HUB_PORT_INFO pointer of the HUB_BUS_INFO::pPortList is * enabled then call the g_USBHSTFunctionList::HUB_RemoveDevice(). * Power down the port and free the resources allocated. */ for (uPortCount = 0; uPortCount < pRootHub->HubDescriptor.bNbrPorts; uPortCount++) { /* To store the result of the transactions */ USBHST_STATUS Result; /* Retrieve the HUB_PORT_INFO structure */ pUSB_HUB_PORT_INFO pPort = pRootHub->pPortList[uPortCount]; /* power off the port */ Result = USB_HUB_CLEAR_PORT_FEATURE(pRootHub,uPortCount,USB_PORT_POWER); /* This call shud ideally never goof up.. still we do a check */ OS_ASSERT(USBHST_SUCCESS == Result); /* Verify */ /* Check if the port is topology enabled */ if (NULL != pPort) { /* * we have a device still attached.. we have to quit clean.. */ /* Disable the port */ pRootHub->pPortList[uPortCount]=NULL; /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubRemoveRoot: device found on root hub -deleting it \n", 0, 0, 0, 0); /* let the USB host stack know.. that we have discon the device * Physically */ /* 9/5/2k3:NM: Changed here to centralise the effect*/ usbHubRemoveDevice(pRootHub,uPortCount); } /* End of If (NULL != pPort) */ } /* End of for (uPortCount.... */ /* Call the HUB_DeleteBusStructure() function to delete bus structure. */ usbHubDeleteBusStructure(uBusHandle); /* * Call OS_FREE () to free the memory allocated for a root hub * HUB_INFO structure. */ OS_FREE (pRootHub->pStatus); /* Free the status bitmap */ OS_FREE (pRootHub->StatusChangeURB.pTransferBuffer);/* Free URB Buffer */ OS_FREE (pRootHub); /* Free the Hub itself */ /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Exiting usbHubRemoveRoot() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB,"usbHubRemoveRoot: Done BusH=0x%x\n",uBusHandle,0,0,0); /* Return */ return;} /* End of function HUB_RemoveRootHub() *//***************************************************************************** usbHubCheckPower -check the parent hub can support a power for a device.** called by the USB Host Software Stack for checking if the parent hub can* support a power for a device.** RETURNS: USBHST_SUCCESS, USBHST_FAILURE if the power cannot be supported.** ERRNO: None** \NOMANUAL*/LOCAL USBHST_STATUS usbHubCheckPower ( UINT32 uDeviceHandle, UINT8 uPowerRequirement ) { /* Storage for the parent hub structure */ pUSB_HUB_INFO pParentHub = NULL; /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Entering usbHubCheckPower() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubCheckPower: Called DevH=0x%x PowReq=%d\n", uDeviceHandle, uPowerRequirement, 0, 0); /* * Call HUB_FindParentHubInBuses() to find the parent hub and If this * is not found, then return USBHST_INVALID_PARAMETER. */ /* Call HUB_FindParentHubInBuses() to find the parent hub. */ pParentHub = usbHubFindParentHubInBuses(uDeviceHandle); /* * If parent hub pointer is not found then search through the bus structures * for BUS_INFO::uDeviceHandle matching for the uDeviceHandle. * This is coz the device could be root hub. In that case we wont have a * parent hub. */ if (NULL == pParentHub) { /* start searching thru the HUB_BUS_INFO list */ pUSB_HUB_BUS_INFO pBusList=gpGlobalBus; /* scan thru all the buses available */ while (NULL != pBusList) { /* check if this is a root hub */ if (uDeviceHandle == pBusList->uDeviceHandle) { /* voila.. a root hub.. */ /* If uPowerRequirement is less than MAXIMUM_POWER_PER_ROOT_HUB * return USBHST_SUCCESS. Else return USBHST_FAILURE. */ if (USB_MAXIMUM_POWER_PER_ROOT_HUB >=uPowerRequirement) { /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubCheckPower: root hub power ok\n", 0, 0, 0, 0); /* ok power requirement- return success */ return USBHST_SUCCESS; } else { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubCheckPower: root hub power not ok\n", 0, 0, 0, 0); /* * root hub is asking for more power than we can provide. * return failure. */ return USBHST_FAILURE; } } /* End of if (uDeviceHandle == pBusList->uDeviceHandle) */ } /* End of while (NULL != pBusList) */ }/* End of if (NULL == pParentHub ) */ /* if still NULL then we have a invalid parameter passed to us */ if (NULL == pParentHub) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB,"usbHubCheckPower: parent hub not found\n",0,0,0,0); /* cannot find the parent hub. return USBHST_INVALID_PARAMETER */ return USBHST_INVALID_PARAMETER; }/* End of if (NULL == pParentHub ) */ /* * If this uPowerRequirement less than HUB_INFO::nPowerPerPort * then return USBHST_SUCCESS.
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -