?? usbhubclassinterface.c
字號:
/* usbHubClassInterface.c - Functions used by USB host stack *//* Copyright 2003 Wind River Systems, Inc. *//*Modification history--------------------01a,27jun03,nrv Changing the code to WRS standards*//*DESCRIPTIONThis module implements the functions to be used by the USB Host Software Stack. The following functions are described in this module: 1. Function for plug and play. 2. Function for power management. 3. Function for root hub management. 4. Function for selective suspend and resume. 5. Function for checking hub power capability. 6. Function for resetting a device. usb2/usbHubUtility.h usb2/usbHubClassInterface.h*//*INTERNAL******************************************************************************* * Filename : HUB_ClassInterface.c * * Copyright : * * THE COPYRIGHT IN THE CONTENTS OF THIS SOFTWARE VEST WITH WIPRO * LIMITED A COMPANY INCORPORATED UNDER THE LAWS OF INDIA AND HAVING * ITS REGISTERED OFFICE AT DODDAKANNELLI SARJAPUR ROAD BANGALORE * 560 035. DISTRIBUTION OR COPYING OF THIS SOFTWARE BY * ANY INDIVIDUAL OR ENTITY OTHER THAN THE ADDRESSEE IS STRICTLY * PROHIBITED AND MAY INCUR LEGAL LIABILITY. IF YOU ARE NOT THE * ADDRESSEE PLEASE NOTIFY US IMMEDIATELY BY PHONE OR BY RETURN EMAIL. * THE ADDRESSEE IS ADVISED TO MAINTAIN THE PROPRIETARY INTERESTS OF * THIS COPYRIGHT AS PER APPLICABLE LAWS. * * * Description : This module implements the functions to be used by the * USB Host Software Stack. The following functions are * described in this module: * 1. Function for plug and play. * 2. Function for power management. * 3. Function for root hub management. * 4. Function for selective suspend and resume. * 5. Function for checking hub power capability. * 6. Function for resetting a device. * * ******************************************************************************//************************** INCLUDE FILES *************************************/#include "usb2/usbOsal.h"#include "usb2/usbHubCommon.h"#include "usb2/usbHubGlobalVariables.h"#include "usb2/usbHubUtility.h"#include "usb2/usbHubClassInterface.h"/************************ GLOBAL FUNCTIONS DEFINITION *************************//***************************************************************************** usbHubAdd - called by USB Host Software for adding a new hub.** This routine is called by USB Host Software for adding a new hub and* to configure it.** ERRNO: None** \NOMANUAL*/LOCAL USBHST_STATUS usbHubAdd ( UINT32 uDeviceHandle, UINT8 uInterfaceNumber, UINT8 uSpeed, void ** pContext ) { /* pointer to the parent hub */ pUSB_HUB_INFO pParentHub = NULL; /* port where the child hub is connected */ UINT8 uPortIndex = 0; /* Storage for the results */ USBHST_STATUS Result = USBHST_FAILURE; /* The new hub pointer */ pUSB_HUB_INFO pHub = NULL; /* The port Information */ pUSB_HUB_PORT_INFO pPort = NULL; /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Entering usbHubAdd() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubAdd : Called devH=0x%x I/f Num= 0x%x,*pCon=0x%x\n", uDeviceHandle, uInterfaceNumber, (UINT32)*pContext,0); /* * Call HUB_FindParentHubInBuses() to find the parent hub and If this * is not found, then return USBHST_INVALID_PARAMETER. */ pParentHub = usbHubFindParentHubInBuses(uDeviceHandle); /* if not found return USBHST_INVALID_PARAMETER */ if (NULL == pParentHub) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB,"usbHubAdd : ParentHub not found\n",0,0,0,0); return USBHST_INVALID_PARAMETER; }/* End of if (NULL == pParentHub ) */ /* * Call 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); /* if not found return USBHST_INVALID_PARAMETER */ if ( USB_PORT_NUMBER_NOT_FOUND == uPortIndex) { OS_LOG_MESSAGE_MEDIUM( HUB,"usbHubAdd : port num not found\n",0,0,0,0); return USBHST_INVALID_PARAMETER; }/* End of if (PORT_NUMBER_NOT_FOUND == uPortIndex ) */ /* * Call the HUB_ConfigureHub() to configure the hub. If the function * call fails: * i. Return result returned by HUB_ConfigureHub() function call. */ Result=usbHubConfigure(&pHub, uDeviceHandle, pParentHub->pBus, pParentHub); /* Check for the result */ if (USBHST_SUCCESS != Result) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubAdd : Device Config failed = 0x%x\n", Result, 0, 0, 0); return Result; }/* End of (USBHST_SUCCESS !=Result ) */ /* Attach the HUB_INFO structure to the parent hub. */ /* Extract the port info from parent */ OS_ASSERT( NULL != pParentHub->pPortList[uPortIndex]); /* Verify */ pPort = pParentHub->pPortList[uPortIndex]; /* update the hub information */ OS_ASSERT( NULL == pPort->pHub); /* Verify */ OS_ASSERT( NULL != pHub); /* Verify */ pPort->pHub=pHub; /* Store the parent hub pointer into pContext. */ *pContext = (void *) pParentHub; /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Exiting usbHubAdd() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubAdd : Done devH=0x%x I/f Num= 0x%x,*pCon=0x%x\n", uDeviceHandle, uInterfaceNumber, (UINT32)*pContext, 0); /* Return USBHST_SUCCESS. */ return USBHST_SUCCESS;} /* End of function HUB_AddHub() *//***************************************************************************** usbHubRemove - delete a hub.** This routine is called by the USB Host Software Stack for deletion of a hub.** RETURNS: N/A** ERRNO: None** \NOMANUAL*/LOCAL void usbHubRemove ( UINT32 uDeviceHandle, void * pContext ) { /* The pointer to the parent hub */ pUSB_HUB_INFO pParentHub = NULL; /* port number of the device */ UINT8 uPortIndex = 0; /* port count for the hub */ UINT8 uPortCount = 0; /* Storage for the hub structure */ pUSB_HUB_INFO pHub = NULL; /* The port Information */ pUSB_HUB_PORT_INFO pPort = NULL; /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Entering usbHubRemove() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubRemove : Called devH=0x%x pCon=0x%x\n", uDeviceHandle, (UINT32)pContext, 0, 0); /* If pContext is NULL then return. */ if (NULL==pContext) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB,"usbHubRemove : pContext is NULL\n",0,0,0,0); return; } /* End of if (NULL==pContext..*/ /* Get the parent hub pointer from the pContext. */ pParentHub= (pUSB_HUB_INFO) pContext; /* Search for the DeviceID in the parent hub. If failed return. */ /* get the port number */ uPortIndex = usbHubFindPortNumber(pParentHub,uDeviceHandle); /* Check if the port is found */ if (USB_PORT_NUMBER_NOT_FOUND == uPortIndex) { OS_LOG_MESSAGE_HIGH( HUB, "usbHubRemove : port number not found\n", 0, 0, 0, 0); return; } /* End of if (PORT_NUM.. */ /* Check if the port number is within limits */ if (uPortIndex > (pParentHub->HubDescriptor.bNbrPorts)) { OS_LOG_MESSAGE_HIGH( HUB, "usbHubRemove : port num %d > %d max\n", uPortIndex, pParentHub->HubDescriptor.bNbrPorts, 0, 0); return; } /* End of (uPortIndex > (pParentHub->.... */ /* * Retrieve HUB_INFO structure from * parentHub::pPortList[uPortIndex]::pHub. */ pPort = pParentHub->pPortList[uPortIndex]; /* update the hub information */ OS_ASSERT( NULL != pPort->pHub); /* Verify */ pHub=pPort->pHub; /* If the HUB_INFO structure is NULL then return. */ if (NULL == pHub) { OS_LOG_MESSAGE_HIGH( HUB,"usbHubRemove : pHub is NULL\n",0,0,0,0); return; } /* End of if (NULL== pHub) */ /* Call the USBHST_CancelURB function to cancel the URB for the hub. */ usbHstURBCancel(&(pHub->StatusChangeURB)); /* * for all the ports in the pHub::pPortList which are enabled, * i. Call the HUB_RemoveDevice() function for * the pHub::pPortList[uPortCount]::uDeviceHandle. * ii. Call the OS_FREE() function to free the * pHub::pPortList[uPortCount] * iii. Set the pHub::pPortList[uPortCount] as NULL */ for (uPortCount = 0; uPortCount < pHub->HubDescriptor.bNbrPorts; uPortCount++) { /* Retrieve the HUB_PORT_INFO structure */ pUSB_HUB_PORT_INFO pPort = pHub->pPortList[uPortCount]; /* Check if the port is enabled */ if (NULL != pPort) { /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB,"usbHubRemove : a device found.. del it.\n",0,0,0,0); /* 9/5/2k3:NM: Changed here to centralise the effect*/ usbHubRemoveDevice(pHub,uPortCount); } /* End of If (NULL != pPort) */ } /* End of for (uPortCount.... */ /* * Call the OS_FREE() function to free all the allocated memory for * the hub. */ /* Get the parent port */ pPort=pParentHub->pPortList[uPortIndex]; /* Setting parent port port as not enabled */ pParentHub->pPortList[uPortIndex]=NULL; /* Free the memory */ OS_FREE(pPort); OS_FREE (pHub->pStatus); /* Free the status bitmap */ OS_FREE (pHub->StatusChangeURB.pTransferBuffer); /* Free URB Buffer */ OS_FREE (pHub); /* Free the Hub itself */ /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Exiting usbHubRemove() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubRemove : Done devH=0x%x pCon=0x%x\n", uDeviceHandle, (UINT32)pContext, 0, 0); /* Return */ return;} /* End of function HUB_RemoveHub() *//***************************************************************************** usbHubSuspend - called by the USB Host Software Stack for suspending a hub.** This routine is called by the USB Host Software Stack for suspending a hub.** RETURNS: N/A** ERRNO: None** \NOMANUAL*/LOCAL void usbHubSuspend ( UINT32 uDeviceHandle, void * pContext ) { /* The pointer to the parent hub */ pUSB_HUB_INFO pParentHub = NULL; /* port number of the device */ UINT8 uPortIndex = 0; /* port count for the hub */ UINT8 uPortCount = 0; /* Storage for the hub structure */ pUSB_HUB_INFO pHub = NULL; /* The port Information */ pUSB_HUB_PORT_INFO pPort = NULL; /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Entering usbHubSuspend() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubSuspend : Called devH=0x%x pCon=0x%x\n", uDeviceHandle, (UINT32)pContext, 0, 0); /* If pContext is NULL then return. */ if (NULL==pContext) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB,"usbHubSuspend : pContext is NULL \n",0,0,0,0); return; } /* End of if (NULL==pContext..*/ /* Get the parent hub pointer from the pContext. */ pParentHub= (pUSB_HUB_INFO) pContext; /* Search for the DeviceID in the parent hub. If failed return. */ /* get the port number */ uPortIndex = usbHubFindPortNumber(pParentHub,uDeviceHandle); /* Check if the port is found */ if (USB_PORT_NUMBER_NOT_FOUND == uPortIndex) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB,"usbHubSuspend : port num not found\n",0,0,0,0); return; } /* End of if (PORT_NUM.. */ /* Check if the port number is within limits */ if (uPortIndex > (pParentHub->HubDescriptor.bNbrPorts)) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubSuspend : port %d > % d max\n", uPortIndex, pParentHub->HubDescriptor.bNbrPorts, 0, 0); return;
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -