📄 usbuhcdinitialization.c
字号:
/* usbUhcdInitialization.c - USB UHCI HCD initialization routine *//* Copyright 2004-2005 Wind River Systems, Inc. This software includes software licensed to Wind River Systems, Inc. by Wipro, Ltd. Wind River licensees may use this software according to the terms of their Wind River license agreement(s) applicable to this software.*//*Modification history--------------------01n,11apr05,ami Function for warm reboot added01m,28mar05,pdg non-PCI changes01l,02mar05,ami SPR #106383 (Max UHCI Host Controller Issue)01k,25feb05,mta SPR 10627601j,25feb05,ami Check in usbUhciExit routine (SPR #106559)01i,09feb05,mta SPR 106159: Detach UHCI gives error01h,15oct04,ami Apigen Changes01g,17aug04,pdg Fix for removing the dependency on OHCI while building the project01f,03aug04,mta coverity error fixes01e,08Sep03,nrv Changed g_HostControllerCount to g_UHCDControllerCount01d,28jul03,mat Endian Related Changes01c,10jul03,mat Bus Abstraction Related changes01b,26jun03,mat changing the code to WRS standards.01a,25apr03,ram written.*//*DESCRIPTIONThis file contains entry and exit points for the UHCI driver.INCLUDE FILES: usb2/usbOsal.h, usb2/usbHst.h, usb2/usbUhci.h, usb2/usbUhcdSupport.h,usb2/usbUhcdCommon.h, usb2/usbUhcdScheduleQueue.h, usb2/usbUhcdScheduleQSupport.h,usb2/BusAbstractionLayer.h, usbPciLib.h, rebootLib.h*//*INTERNAL ******************************************************************************* * Filename : usbUhcdInitialisation.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 file contains entry and exit points for the * UHCI driver. * * ******************************************************************************//* includes */#include "usb2/usbOsal.h"#include "usb2/usbHst.h"#include "usb2/usbUhci.h"#include "usb2/usbUhcdSupport.h"#include "usb2/usbUhcdCommon.h"#include "usb2/usbUhcdScheduleQueue.h"#include "usb2/usbUhcdScheduleQSupport.h"#include "usb2/BusAbstractionLayer.h"#include "usbPciLib.h"#include "rebootLib.h"/* defines */#define USB_UHCI_BASE_ADDRESS_REGISTER_OFFSET 0x20#define USB_UHCI_GET_BASE_ADDRESS(nPciBusNumber, \ nPciDeviceNumber, \ nPciFunctionNumber, \ pBaseAddressBuffer) \ \ READ_BUS_LONG(nPciBusNumber, \ nPciDeviceNumber, \ nPciFunctionNumber, \ USB_UHCI_BASE_ADDRESS_REGISTER_OFFSET, \ pBaseAddressBuffer)/* global *//* To hold the array of pointers to the HCD maintained data structures */PUHCD_DATA *g_pUHCDData = NULL;/* Globals Added for Non PCI support */extern pUSB_HCD_BUS_INFO pUhciBusInfo[];extern UINT32 maxUhciCount; /* locals */void usbUhcdIsr (INT32 pHCDData);void usbUhcdCheckPort (INT32 pHCDData);void usbUhcdManagePort (INT32 pHCDData);void usbUhcdCompletedTdHandler (PUHCD_DATA pHCDData);BOOLEAN usbUhcdCreateFrameList (PUHCD_DATA pHCDData);USBHST_STATUS usbUhcdRemoveResources ( PUHCD_DATA pHCDData, INT8 aReqourceAllocated, UINT32 index); USBHST_STATUS usbUhcdExit ( void );extern void usbUhcdHcReset( PUHCD_DATA pHCDData );/* structure for registering driver */pUSBHST_HC_DRIVER hcDriver;/* handle to driver */UINT32 hHcDriver;/* Flag indicating that the Host Controller is initialised */BOOLEAN alreadyInited = FALSE;/* Number of host controllers present in the system */UINT32 g_UhcdHostControllerCount = 0;/* forward declaration */VOID usbUhcdDisableHC (int startType);/***************************************************************************** usbUhcdInit - initialise the USB UHCD Host Controller Driver.** This routine intializes the UHCI Host Controller Driver and can be called* from either the target initialization code (bootup) or during runtime. * The usbd and hub interfaces should be initialized before this routine is * called.** RETURNS: USBHST_FALIURE - if the UHCD Host Controller initialization fails** ERRNO:* None.*/USBHST_STATUS usbUhcdInit (void) { /* To hold the status of the bus specific function call */ BUS_OPERATION_STATUS busStatus = BUS_OPERATION_FAILURE; INT32 uCount = 0; INT32 hostControllerFound = 0; /* To hold the value of the register */ UINT16 regx = 0; /* To hold the pointer to the HCD maintained data structure */ PUHCD_DATA pHCDData = NULL; /* Hold the status information */ USBHST_STATUS status = USBHST_FAILURE; /* To hold the Number of resources allocated before error occurred */ INT8 *pResourceAllocated = NULL; OS_LOG_MESSAGE_MEDIUM(UHCD,"Entering initialization of UHCI\n",0,0,0,0); /* Check if this function has been already called before */ if (alreadyInited == TRUE) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Function has already been called\n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_UHCI_WV_INIT_EXIT, "usbUhciInit() exits : Error - already called once", USB_UHCD_WV_FILTER); return USBHST_FAILURE; } /* Check if any UHCI Controller is present */ if (maxUhciCount == 0) { OS_LOG_MESSAGE_MEDIUM(UHCD,"No Uhci Controller present\n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_UHCI_WV_INIT_EXIT, "usbUhcdInit() exits : No Uhci Controller present", USB_UHCD_WV_FILTER); return USBHST_FAILURE; } /* Allocate memory for the global */ g_pUHCDData = (PUHCD_DATA *)OS_MALLOC(maxUhciCount * sizeof(PUHCD_DATA)); /* Check if memory allocation is successful */ if (g_pUHCDData == NULL) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Memory allocation failure\n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_UHCI_WV_INIT_EXIT, "usbUhciInit() exits : Memory allocation failure", USB_UHCD_WV_FILTER); return USBHST_FAILURE; } /* Allocate memory for the resources allocated array */ pResourceAllocated = (INT8 *)OS_MALLOC(maxUhciCount * sizeof(INT8)); /* Check if memory allocation is successful */ if (pResourceAllocated == NULL) { OS_LOG_MESSAGE_HIGH(UHCD,"Memory allocation failure\n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_UHCI_WV_INIT_EXIT, "usbUhciInit() exits : Memory allocation failure", USB_UHCD_WV_FILTER); /* Release memory allocated for the global HCD data array */ OS_FREE(g_pUHCDData); g_pUHCDData = NULL; return USBHST_FAILURE; } /* Hook the function that should be called on reboot */ if(ERROR == rebootHookAdd((FUNCPTR)usbUhcdDisableHC)) { return FALSE; } /* Initialize the global array */ for (uCount = 0; uCount < maxUhciCount; uCount++) { g_pUHCDData[uCount] = NULL; pResourceAllocated[uCount] = 0; } /* register the UHCD with USBD */ /* Allocate memory for the HCD maintained data structure */ hcDriver = (pUSBHST_HC_DRIVER) OS_MALLOC (sizeof (USBHST_HC_DRIVER)); /* check if memory allocation is successful */ if (NULL == hcDriver) { OS_LOG_MESSAGE_MEDIUM(UHCD,"usbUhcdInit - memory not allocated for driver data",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_UHCI_WV_INIT_EXIT, "usbUhciInit() exits - memory allocation failed", USB_UHCD_WV_FILTER); /* Release memory allocated for the global HCD data array */ OS_FREE(g_pUHCDData); g_pUHCDData = NULL; /* Release memory allocated for the resource array */ OS_FREE(pResourceAllocated); pResourceAllocated = NULL; return USBHST_FAILURE; } /* Initialize the members of the data structure */ OS_MEMSET (hcDriver, 0, sizeof (USBHST_HC_DRIVER)); /* Initialize members of structure */ hcDriver->getFrameNumber = usbUhcdGetFrameNumber; hcDriver->setBitRate = usbUhcdSetBitRate; hcDriver->isBandwidthAvailable = usbUhcdIsBandwidthAvailable; hcDriver->createPipe = usbUhcdCreatePipe; hcDriver->modifyDefaultPipe = usbUhcdModifyDefaultPipe; hcDriver->deletePipe = usbUhcdDeletePipe; hcDriver->isRequestPending = usbUhcdIsRequestPending; hcDriver->submitURB = usbUhcdSubmitUrb; hcDriver->cancelURB = usbUhcdCancelUrb; status = usbHstHCDRegister (hcDriver, &hHcDriver,NULL); if ( status != USBHST_SUCCESS) { OS_LOG_MESSAGE_MEDIUM(UHCD,"UHCD failed to register with USBD\n",0,0,0,0); OS_FREE (hcDriver); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_UHCI_WV_INIT_EXIT, "usbUhciInit() exits - UHCD registration failed", USB_UHCD_WV_FILTER); /* Release memory allocated for the global HCD data array */ OS_FREE(g_pUHCDData); g_pUHCDData = NULL; /* Release memory allocated for the resource array */ OS_FREE(pResourceAllocated); pResourceAllocated = NULL; return USBHST_FAILURE; } for (g_UhcdHostControllerCount = 0; g_UhcdHostControllerCount < maxUhciCount; g_UhcdHostControllerCount++) { /* Allocate memory for the UHCD_DATA structure */ pHCDData = (PUHCD_DATA)OS_MALLOC(sizeof(UHCD_DATA)); /* Check if memory allocation is successful */ if (NULL == pHCDData) { OS_LOG_MESSAGE_MEDIUM(UHCD,"memory not allocated For HCD_DATA structure\n",0,0,0,0); /* DO PROPER ERROR HANDLING */ } /* Initialize all the elements of the structure */ OS_MEMSET(pHCDData, 0, sizeof(UHCD_DATA)); /* Store in global array */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -