📄 usbuhcdinitialization.c
字号:
g_pUHCDData[g_UhcdHostControllerCount] = pHCDData ; /* Update the Bus Index in the Stucture */ pHCDData->busIndex = g_UhcdHostControllerCount; /* Create the semaphore to enter the critical section */ if ((pHCDData->usbUhcdSemCritical = OS_CREATE_EVENT(SEM_FULL)) == NULL ) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Unable to Create semaphore!\n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_UHCI_WV_INIT_EXIT, "usbUhciInit() exits - Creating semaphore for critical section failed", USB_UHCD_WV_FILTER); continue; } /* Increment the Resource allocation count */ pResourceAllocated[g_UhcdHostControllerCount]++; /* Store the IRQ number for the OHCI Information structure */ pHCDData->irq = pUhciBusInfo[g_UhcdHostControllerCount]->irq; if (pHCDData->irq == 0) { OS_LOG_MESSAGE_MEDIUM(UHCD, "Error in reading the IRQ\n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_UHCI_WV_INIT_EXIT, "usbUhciInit() exits - getting IRQ number failed", USB_UHCD_WV_FILTER); continue; } /* Increment the Resource allocation count */ pResourceAllocated[g_UhcdHostControllerCount]++; /* * Read the base address of the UHCI registers by reading the * PCI Configuration Space. */ pHCDData->usbUhcdUsbBase = (UINT32)pUhciBusInfo[g_UhcdHostControllerCount]->pBaseAddress; /* Increment the Resource allocation count */ pResourceAllocated[g_UhcdHostControllerCount]++; /* * UHCI registers are I/O mapped. * The bit 0 of the base address set to 1 indicates that * the registers are mapped to the I/O space. * Check whether the address is I/O mapped */ if (!(pHCDData->usbUhcdUsbBase & 0x01)) { OS_LOG_MESSAGE_MEDIUM(UHCD,"USBBASE Invalid!\n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_UHCI_WV_INIT_EXIT, "usbUhciInit() exits : Error - address is not I/O mapped", USB_UHCD_WV_FILTER); continue; } /* Increment the Resource allocation count */ pResourceAllocated[g_UhcdHostControllerCount]++; /* * Bit 0 is only an indication of I/O mapping of the UHCI registers. * Get the base address of the register only by making this bit 0. */ pHCDData->usbUhcdUsbBase = pHCDData->usbUhcdUsbBase & ~(0x01); /* Interrupt is hard-coded to IRQ 11 on the Southbridge-resident 8259. * Plug the interrupt line value into the configuration header. */ /* Call the function to reset the UHCI Host Controller */ usbUhcdHcReset (pHCDData); /* * The UHCI controller requires a frame list which is accessed * by the Host Controller in every frame to service the requests * meant for the frame. * Call the function to create the frame list required by the * Host Controller. */ if (!usbUhcdCreateFrameList(pHCDData)) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Unable to create frame list",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_UHCI_WV_INIT_EXIT, "usbUhciInit() exits - Creating frame list failed", USB_UHCD_WV_FILTER); continue; } /* Increment the Resource allocation count */ pResourceAllocated[g_UhcdHostControllerCount]++; /* create the default pipe */ pHCDData->hcDefaultPipe = usbUhcdFormEmptyPipe(); if (pHCDData->hcDefaultPipe == NULL) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Unable to create default pipe \n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_UHCI_WV_INIT_EXIT, "usbUhciInit() exits - Creating default pipe failed", USB_UHCD_WV_FILTER); continue; } /* Increment the Resource allocation count */ pResourceAllocated[g_UhcdHostControllerCount]++; /* Link the default pipe the the Control Queue Head */ pHCDData->hcDefaultPipe->qh = pHCDData->usbUhcdCQh; pHCDData->hcDefaultPipe->endPointType = PIPE_CONTROL; pHCDData->hcDefaultPipe->next = NULL; /* * Disable any interrupts on the IRQ line * This is done to hook the ISR */ regx = USB_UHCD_READ_WORD ( pHCDData->usbUhcdUsbBase + USB_UHCD_USBINTR); /* Update the value which is to be written */ regx = regx | 0x0; /* Write the value to the register */ USB_UHCD_WRITE_WORD (pHCDData->usbUhcdUsbBase + USB_UHCD_USBINTR, regx); /* Increment the Resource allocation count */ pResourceAllocated[g_UhcdHostControllerCount]++; /* Write the base address of the frame list in the FLBASEADD register */ USB_UHCD_DWORD_OUT (g_UhcdHostControllerCount, pHCDData->usbUhcdUsbBase + USB_UHCD_FLBASEADD, (USB_UHCD_CONVERT_TO_BUS_MEM ( g_UhcdHostControllerCount, (PVOID)pHCDData->usbUhcdFrameList))); /* * Bit 7 of the USBCMD register indicates the Maximum packet size used for * full speed bandwidth reclamation at the end of the frame. * This value is used by the Host Controller to determine whether it * should initiate any transaction based on the time remaining in the frame. * A value of 0 indicates a maximum packet size of 32 bytes. * This bit set to 1 indicates that the maximum packet size is 64 bytes. */ usbUhcdRegxSetBit (pHCDData, USB_UHCD_USBCMD, 7); /* * Bit 6 of the USBCMD register is provided as a semaphore service * for the software to access the Host Controller. * This has no effect on the hardware. */ usbUhcdRegxSetBit (pHCDData ,USB_UHCD_USBCMD, 6); /* * Bit 0 of the USBCMD register enables the Host Controller to be * operational or non-operational. Setting this bit to 1 makes the * Host Controller operational and 0 vice-versa. */ usbUhcdRegxSetBit (pHCDData, USB_UHCD_USBCMD, 0); /* Create a semaphore used for monitoring the change in port status */ if ((pHCDData->usbUhcdSemCheckPort = OS_CREATE_EVENT(SEM_EMPTY)) == NULL ) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Unable to Create semaphore!\n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_UHCI_WV_INIT_EXIT, "usbUhciInit() exits - Creating semaphore for checking port failed", USB_UHCD_WV_FILTER); continue; } OS_LOG_MESSAGE_HIGH (UHCD,"SEM: PORT STATUS [0x%x]\n",(UINT32)pHCDData->usbUhcdSemCheckPort,0,0,0); /* Increment the Resource allocation count */ pResourceAllocated[g_UhcdHostControllerCount]++; /* * Create a semaphore used by the * Root Hub Emulation module's Interrupt task */ if ((pHCDData->usbUhcdSemPortInterruptTransfer = OS_CREATE_EVENT (SEM_EMPTY)) == NULL ) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Unable to Create semaphore!\n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_UHCI_WV_INIT_EXIT, "usbUhciInit() exits - Creating semaphore for RH inrerrupt failed", USB_UHCD_WV_FILTER); continue; } OS_LOG_MESSAGE_HIGH (UHCD,"SEM: RH Interrupt Task [0x%x]\n",(UINT32)pHCDData->usbUhcdSemPortInterruptTransfer,0,0,0); /* Increment the Resource allocation count */ pResourceAllocated[g_UhcdHostControllerCount]++; /* Ensure that all the port status registers are in the default * condition before creating the polling task * Added by sapna to remove the Port enable bit beign set */ /* Clear the Port Enable change bit */ usbUhcdPortClearBit(pHCDData, USB_UHCD_PORT1, 3); /* Added by sapna to ensure that no undefined states after reset */ /* Clear the Port Enable change bit */ usbUhcdPortClearBit(pHCDData, USB_UHCD_PORT2, 3); /* Clear the status register of the HC */ /* Clear HC halted bit */ usbUhcdRegxSetBit(pHCDData, USB_UHCD_USBSTS, 5); /* Clear the HC Process Error bit */ usbUhcdRegxSetBit(pHCDData, USB_UHCD_USBSTS, 4); /* Clear Host System Error */ usbUhcdRegxSetBit(pHCDData, USB_UHCD_USBSTS, 3); /* Clear Resume Detect */ usbUhcdRegxSetBit(pHCDData, USB_UHCD_USBSTS, 2); /* Clear USB Error Interrupt */ usbUhcdRegxSetBit(pHCDData, USB_UHCD_USBSTS, 1); /* Clear USB Interrupt*/ usbUhcdRegxSetBit(pHCDData, USB_UHCD_USBSTS, 0); /* * There is no interrupt generated specific to the Root hub. * A thread which polls the ports of the UHCI Root Hub is spawned here */ pHCDData->usbUhcdThdManagePort = OS_CREATE_THREAD ("uhcdMPort", 100, usbUhcdManagePort,(INT32) pHCDData); if (pHCDData->usbUhcdThdManagePort == 0) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Unable to Create thread!\n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_UHCI_WV_INIT_EXIT, "usbUhciInit() exits - Creating usbUhcdManagePort thread failed", USB_UHCD_WV_FILTER); continue; } /* Increment the Resource allocation count */ pResourceAllocated[g_UhcdHostControllerCount]++; /* * Create the semaphore used to cleanup the resources * allocated after completion of a transfer request. */ if ((pHCDData->usbUhcdSemCleanupTd = OS_CREATE_EVENT (SEM_EMPTY)) == NULL ) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Unable to Create semaphore!\n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_UHCI_WV_INIT_EXIT, "usbUhciInit() exits - Creating semaphore for cleanup failed", USB_UHCD_WV_FILTER); continue; } OS_LOG_MESSAGE_HIGH (UHCD,"SEM: Cleanup TDs [0x%x]\n",(UINT32)pHCDData->usbUhcdSemCleanupTd,0,0,0); /* Increment the Resource allocation count */ pResourceAllocated[g_UhcdHostControllerCount]++; /* Spawn the thread used for handling transfer completion */ pHCDData->usbUhcdThdTransferComp = OS_CREATE_THREAD ("uhcdClrTd", 90, (FUNCPTR) usbUhcdCompletedTdHandler, (INT32) pHCDData); if (pHCDData->usbUhcdThdTransferComp == 0) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Unable to Create thread!\n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_UHCI_WV_INIT_EXIT, "usbUhciInit() exits - Creating transfer completion thread failed", USB_UHCD_WV_FILTER); continue; } /* Increment the Resource allocation count */ pResourceAllocated[g_UhcdHostControllerCount]++; /* * Hook the ISR function of the UHCD Host Controller Driver * This enables the ISR function to be called when an interrupt * is received for this IRQ. */ if (pUhciBusInfo[g_UhcdHostControllerCount]->pFuncIntConnect != NULL) busStatus = pUhciBusInfo[g_UhcdHostControllerCount]->pFuncIntConnect (usbUhcdIsr, (PVOID)pHCDData, pHCDData->irq); else busStatus = BUS_OPERATION_FAILURE; /* Check whether the interrupt handler was registered successfully */ if (busStatus == BUS_OPERATION_FAILURE) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Unable to Hook Interrupt!\n",0,0,0,0); /* WindView Instrumentation */ USB_HCD_LOG_EVENT( USB_UHCI_WV_INIT_EXIT, "usbUhciInit() exits - Unable to hook interrupt", USB_UHCD_WV_FILTER); continue; } regx = USB_UHCD_READ_WORD ( pHCDData->usbUhcdUsbBase + USB_UHCD_USBINTR); /* Update the value which is to be written */ regx = regx | 0xF; /* Write the value to the register */ USB_UHCD_WRITE_WORD (pHCDData->usbUhcdUsbBase + USB_UHCD_USBINTR, regx); /* Increment the Resource allocation count */ pResourceAllocated[g_UhcdHostControllerCount]++; /* Enable the Interrupts - Start */ /* Enable the Timeout/CRC interrupt - bit 0 */ usbUhcdRegxSetBit (pHCDData, USB_UHCD_USBINTR, 0); /* Enable the IOC(Interrupt on Completion) interrupt - bit 2 */ usbUhcdRegxSetBit (pHCDData, USB_UHCD_USBINTR, 2); /* Enable the Short Packet Interrupt - bit 3 */ usbUhcdRegxSetBit (pHCDData, USB_UHCD_USBINTR, 3); /* Register the Bus with USBD */ status = usbHstBusRegister(hHcDriver,USBHST_FULL_SPEED, (UINT32)pHCDData->hcDefaultPipe ); if (status != USBHST_SUCCESS) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Unable to Register Bus with USBD!\n",0,0,0,0); continue; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -