A_STATUS CF_UnMaskInterrupt(CF_DEVICE_HANDLE cfHandle) { CF_DEVICE *cfDevice; #ifndef POLL NDIS_STATUS ndisStatus; #endif HIF_DEBUG_PRINTF(ATH_LOG_TRC, "CF_UnMaskInterrupt \n"); cfDevice = (CF_DEVICE *)cfHandle; #ifdef POLL startPollThread(cfDevice); #else #ifdef SHARED_INTERRUPTS isrHandler = LoadIntChainHandler(TEXT("giisr.dll"),TEXT("ISRHandler"),(BYTE)cfDevice->interruptNumber); if (!isrHandler) { HIF_DEBUG_PRINTF(ATH_LOG_ERR,"CF_UnMaskInterrupt: Load int chain handler failed \n"); return A_ERROR; } memset (&Info,0,sizeof(Info)); Info.SysIntr = cfDevice->sysIntr; Info.CheckPort = TRUE; Info.PortIsIO = FALSE; Info.UseMaskReg = TRUE; Info.PortSize = sizeof(BYTE); Info.PortAddr = (DWORD)giisrMappedAddress + 0x00000400; Info.MaskAddr = (DWORD)giisrMappedAddress + 0x00000418; if (!KernelLibIoControl(isrHandler,IOCTL_GIISR_INFO,&Info,sizeof(Info),NULL,0,NULL)) { HIF_DEBUG_PRINTF(ATH_LOG_ERR,"CF_UnMaskInterrupt: KernelLibIoControl failed \n"); return A_ERROR; } #endif // SHARED_INTERRUPTS ndisStatus = NdisMRegisterInterrupt(&cfDevice->interruptObject, cfDevice->miniportHandle, cfDevice->interruptNumber, 0, TRUE, TRUE, 0); if (ndisStatus != NDIS_STATUS_SUCCESS) { return A_ERROR; } #endif cfDevice->interruptRegistered= TRUE; return A_OK; }
BOOL CSDHCBase::InitializeHardware( ) { SETFNAME(_T("InitializeHardware")); DEBUGCHK(m_hBusAccess); DEBUGCHK(m_regDevice.IsOK()); PREFAST_DEBUGCHK(m_pSlotInfos); RETAILMSG(0,(TEXT("CSDHCBase::InitializeHardware\n"))); ValidateSlotCount(); BOOL fRet = FALSE; PHYSICAL_ADDRESS PortAddress; DWORD inIoSpace = 0; // Read window information DDKWINDOWINFO wini; wini.cbSize = sizeof(wini); DWORD dwStatus = DDKReg_GetWindowInfo(m_regDevice, &wini); if (dwStatus != ERROR_SUCCESS) { DEBUGMSG(SDCARD_ZONE_ERROR, (_T("%s Error getting window information\r\n"), pszFname)); goto EXIT; } // Read ISR information DDKISRINFO isri; isri.cbSize = sizeof(isri); dwStatus = DDKReg_GetIsrInfo(m_regDevice, &isri); if (dwStatus != ERROR_SUCCESS) { DEBUGMSG(SDCARD_ZONE_ERROR, (_T("%s Error getting ISR information\r\n"), pszFname)); goto EXIT; } #ifdef SET_TI_BOARD_PCI_REG { DDKPCIINFO dpi; dpi.cbSize = sizeof(dpi); DDKReg_GetPciInfo(m_regDevice, &dpi); DWORD RetVal; PCI_SLOT_NUMBER SlotNumber; SlotNumber.u.AsULONG = 0; SlotNumber.u.bits.DeviceNumber = dpi.dwDeviceNumber; SlotNumber.u.bits.FunctionNumber = 1; HalGetBusDataByOffset( PCIConfiguration, wini.dwBusNumber, SlotNumber.u.AsULONG, &RetVal, 0x84, sizeof( RetVal ) ); if (!(RetVal & 0x00200000)) { RetVal |= 0x00200000; HalSetBusDataByOffset( PCIConfiguration, wini.dwBusNumber, SlotNumber.u.AsULONG, &RetVal, 0x84, sizeof( RetVal ) ); } } #endif // Sanity check ISR if (isri.dwSysintr == SYSINTR_NOP) { RETAILMSG(0,(TEXT("%s No sysintr specified in registry\r\n"),pszFname)); DEBUGMSG(SDCARD_ZONE_ERROR, (_T("%s No sysintr specified in registry\r\n"), pszFname)); goto EXIT; } if (isri.szIsrDll[0] != 0) { if ( (isri.szIsrHandler[0] == 0) || (isri.dwIrq == IRQ_UNSPECIFIED) ) { DEBUGMSG(SDCARD_ZONE_ERROR, (_T("%s Invalid installable ISR information in registry\r\n"), pszFname)); goto EXIT; } } m_interfaceType = (INTERFACE_TYPE) wini.dwInterfaceType; m_dwBusNumber = wini.dwBusNumber; DWORD dwSlotZeroWindow; dwSlotZeroWindow = DetermineFirstSlotWindow(&wini); DEBUGCHK(dwSlotZeroWindow < wini.dwNumMemWindows); DEBUGCHK( (dwSlotZeroWindow + m_cSlots) <= wini.dwNumMemWindows ); // Use the slot zero window for the ISR PDEVICEWINDOW pWindowSlotZero = &wini.memWindows[dwSlotZeroWindow]; PortAddress.LowPart = pWindowSlotZero->dwBase; PortAddress.HighPart = 0; RETAILMSG(0,(TEXT("CSDHCBase::InitializeHardware go on...\n"))); // Install an ISR, if present if (isri.szIsrDll[0] != 0) { m_hISRHandler = LoadIntChainHandler(isri.szIsrDll, isri.szIsrHandler, (BYTE) isri.dwIrq); if (m_hISRHandler == NULL) { DEBUGMSG(SDCARD_ZONE_ERROR, (_T("%s Error installing ISR\r\n"), pszFname)); goto EXIT; } else { GIISR_INFO Info; DWORD dwPhysAddr; fRet = BusTransBusAddrToStatic(m_hBusAccess, (INTERFACE_TYPE) wini.dwInterfaceType, wini.dwBusNumber, PortAddress, pWindowSlotZero->dwLen, &inIoSpace, (PVOID *) &dwPhysAddr); if (fRet == FALSE) { DEBUGMSG(SDCARD_ZONE_ERROR, (_T("%s Error translating bus address to static address\r\n"), pszFname)); goto EXIT; } // Initialize ISR Info.SysIntr = isri.dwSysintr; Info.CheckPort = TRUE; Info.PortIsIO = (inIoSpace != 0); Info.UseMaskReg = FALSE; Info.PortAddr = dwPhysAddr + SDHC_SLOT_INT_STATUS; Info.PortSize = sizeof(USHORT); Info.Mask = 0xFF; fRet = KernelLibIoControl(m_hISRHandler, IOCTL_GIISR_INFO, &Info, sizeof(Info), NULL, 0, NULL); if (fRet == FALSE) { DEBUGMSG(SDCARD_ZONE_ERROR, (_T("%s Error setting up ISR\r\n"), pszFname)); goto EXIT; } } } m_dwSysIntr = isri.dwSysintr; DEBUGMSG(SDCARD_ZONE_INIT, (_T("%s IRQ 0x%X mapped to SYS_INTR 0x%X\r\n"), pszFname, isri.dwIrq, m_dwSysIntr)); const DWORD dwEndWindow = dwSlotZeroWindow + m_cSlots; for (DWORD dwWindow = dwSlotZeroWindow; dwWindow < dwEndWindow; ++dwWindow) { DEBUGCHK(dwWindow < wini.dwNumMemWindows); PDEVICEWINDOW pWindowSD = &wini.memWindows[dwWindow]; DEBUGMSG(SDCARD_ZONE_INIT, (_T("%s Base address -> 0x%x; length -> 0x%x \r\n"), pszFname, pWindowSD->dwBase, pWindowSD->dwLen)); PortAddress.LowPart = pWindowSD->dwBase; PortAddress.HighPart = 0; inIoSpace = 0; PVOID pvRegisters; DEBUGCHK(pWindowSlotZero->dwLen >= sizeof(SSDHC_REGISTERS)); RETAILMSG(0,(TEXT("BusTransBusAddrToVirtual. 0x%X\n"),PortAddress)); fRet = BusTransBusAddrToVirtual(m_hBusAccess, (INTERFACE_TYPE) wini.dwInterfaceType, wini.dwBusNumber, PortAddress, pWindowSD->dwLen, &inIoSpace, &pvRegisters); if (fRet == FALSE) { RETAILMSG(0,(TEXT("%s error translating SD address \r\n"),pszFname)); DEBUGMSG(SDCARD_ZONE_ERROR, (_T("%s error translating SD address \r\n"), pszFname)); goto EXIT; } DEBUGCHK(inIoSpace == 0); // Will not work for I/O mappings. DWORD dwSlot = dwWindow - dwSlotZeroWindow; DEBUGCHK(dwSlot < m_cSlots); m_pSlotInfos[dwSlot].pucRegisters = (volatile UCHAR*) pvRegisters; m_pSlotInfos[dwSlot].dwExtraInfo = pWindowSD->dwLen; } m_fHardwareInitialized = TRUE; fRet = TRUE; RETAILMSG(0,(TEXT("CSDHCBase::InitializeHardware finished.\n"))); EXIT: return fRet; }
//======================================================================= // LED_Init - Driver initialization function // DWORD LED_Init(LPCSTR pContext, DWORD dwBusContext){ PDRVCONTEXT pDrv; RETAILMSG(RETAIL_ON, (TEXT("Test debug output without context \r\n"))); RETAILMSG(RETAIL_ON, (TEXT("LED_Init++ dwContext: %x\r\n"), pContext)); // Allocate a driver instance structure - required if we want to manage // more instances pDrv = (PDRVCONTEXT)LocalAlloc(LPTR, sizeof(DRVCONTEXT)); if(pDrv){ // initialize structure memset((PBYTE) pDrv, 0, sizeof(DRVCONTEXT)); pDrv->dwSize = sizeof(DRVCONTEXT); // read registry to determine the size of the disk // GetConfigData((DWORD)pContext); }else{ RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. Out of memory\r\n"), pContext)); } DWORD dwGpio = 15; DWORD dwIrq = 0; DWORD dwEdge = GPIO_EDGE_RISING; if (!KernelIoControl(IOCTL_HAL_GPIO2IRQ, &dwGpio, sizeof(DWORD), &dwIrq, sizeof(DWORD), NULL)) { RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. IOCTL_HAL_GPIO2IRQ\r\n"), pContext)); return 0; } if (!KernelIoControl(IOCTL_HAL_IRQEDGE, &dwIrq, sizeof(BYTE), &dwEdge, sizeof(BYTE), NULL)) { RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. IOCTL_HAL_IRQEDGE\r\n"), pContext)); return 0; } if (!KernelIoControl(IOCTL_HAL_REQUEST_SYSINTR, &dwIrq, sizeof(DWORD), &(pDrv->dwSysIntr), sizeof(DWORD), NULL)) { RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. IOCTL_HAL_REQUEST_SYSINTR\r\n"), pContext)); return 0; } pDrv->hEvent = CreateEvent(NULL, false, false, TEXT("ISTEvent")); if (!(pDrv->hEvent)) { RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. Create Event failed.\r\n"), pContext)); return 0; } if (!InterruptInitialize(pDrv->dwSysIntr, pDrv->hEvent, NULL, 0)) { RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. InterruptInitialize failed.\r\n"), pContext)); return 0; } pDrv->hIsrHandle = LoadIntChainHandler(TEXT("\\Program Files\\Drivers\\ISRDll.dll"), TEXT("ISRHandler"), dwIrq); if (!pDrv->hIsrHandle) { RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. LoadIntChainHandler failed.\r\n"), pContext)); return 0; } isr_info.SysIntr = pDrv->dwSysIntr; isr_info.pGPIORegs = (GPIOREG*)CreateStaticMapping(GPIO_BASE >> 8, sizeof(GPIOREG)); if (!isr_info.pGPIORegs) { RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. CreateStaticMapping failed.\r\n"), pContext)); return 0; } if (!KernelLibIoControl(pDrv->hIsrHandle, IOCTL_ISR_INFO, &isr_info, sizeof(isr_info), NULL, 0, NULL)) { RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. IOCTL_HAL_RELEASE_SYSINTR failed.\r\n"), pContext)); return 0; } pDrv->hIntThread = CreateThread(NULL, 0, ISTFunction, pDrv->hEvent, 0, NULL); if (!pDrv->hIntThread) { RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init failure. CreateThread failed.\r\n"), pContext)); return 0; } RETAILMSG(RETAIL_ON, (DTAG TEXT("LED_Init-- pDrv: %x\r\n"), pDrv)); return (DWORD)pDrv; FREECHAINHANDLER: FreeIntChainHandler(pDrv->hIsrHandle); INTERRUPTDISABLE: InterruptDisable(pDrv->dwSysIntr); KERNELIOCONTROL: KernelIoControl(IOCTL_HAL_RELEASE_SYSINTR, &pDrv->dwSysIntr, sizeof(DWORD), NULL, 0, NULL); CLOSEHANDLE: CloseHandle(pDrv->hEvent); DELETESTATICMAPPING: DeleteStaticMapping((LPVOID)isr_info.pGPIORegs, sizeof(GPIOREG)); }
/* InitializeOHCI * * Configure and initialize OHCI card * * Return Value: * Return TRUE if card could be located and configured, otherwise FALSE */ static BOOL InitializeOHCI( SOhcdPdd * pPddObject, // IN - Pointer to PDD structure LPCWSTR szDriverRegKey) // IN - Pointer to active registry key string { PUCHAR ioPortBase = NULL; DWORD dwAddrLen; DWORD dwIOSpace; BOOL InstallIsr = FALSE; BOOL fResult = FALSE; LPVOID pobMem = NULL; LPVOID pobOhcd = NULL; DWORD PhysAddr; DWORD dwHPPhysicalMemSize; HKEY hKey=NULL; DDKWINDOWINFO dwi; DDKISRINFO dii; USBH_MSG((_T("[USBH] ++InitializeOHCI()\n\r"))); g_pSysConReg = (S3C6410_SYSCON_REG *)DrvLib_MapIoSpace(S3C6410_BASE_REG_PA_SYSCON, sizeof(S3C6410_SYSCON_REG), FALSE); if (g_pSysConReg == NULL) { USBH_ERR((_T("[USBH:ERR] InitializeOHCI() : DrvLib_MapIoSpace() Failed\n"))); return FALSE; } #ifdef USE_SRCCLK_EPLL //----------------------- // Initialize Clock // ClkSrc = MOUT_EPLL (96MHz) // Divide by 2 (96/2=48MHz) // HCLK, SCLK gate pass //----------------------- g_pSysConReg->CLK_SRC = (g_pSysConReg->CLK_SRC & ~(0x3<<5)) | (0x1<<5); // UHOST_SEL : MoutEPLL g_pSysConReg->CLK_DIV1 = (g_pSysConReg->CLK_DIV1 & ~(0xf<<20)) | (0x1<<20); // UHOST_RATIO : 96 MHz / (1+1) = 48 MHz #else //----------------------- // Initialize Clock // ClkSrc = USB_PHY(48MHz) // Divide by 1 (48/1=48MHz) // HCLK, SCLK gate pass //----------------------- g_pSysConReg->OTHERS |= (1<<16); // Set SUB Signal Mask g_pSysConReg->CLK_SRC &= ~(0x3<<5); // UHOST_SEL : 48MHz g_pSysConReg->CLK_DIV1 &= ~(0xf<<20); // UHOST_RATIO : 48 MHz / (0+1) = 48 MHz #endif g_pSysConReg->HCLK_GATE |= (0x1<<29); // HCLK_UHOST Pass (EVT1) g_pSysConReg->SCLK_GATE |= (0x1<<30); // SCLK_UHOST Pass if (RegOpenKeyEx(HKEY_LOCAL_MACHINE,szDriverRegKey,0,0,&hKey)!= ERROR_SUCCESS) { DEBUGMSG(ZONE_ERROR,(TEXT("InitializeOHCI:GetRegistryConfig RegOpenKeyEx(%s) failed\r\n"), szDriverRegKey)); return FALSE; } dwi.cbSize=sizeof(dwi); dii.cbSize=sizeof(dii); if ( (DDKReg_GetWindowInfo(hKey, &dwi ) != ERROR_SUCCESS) || (DDKReg_GetIsrInfo (hKey, &dii ) != ERROR_SUCCESS)) { DEBUGMSG(ZONE_ERROR,(TEXT("InitializeOHCI:DDKReg_GetWindowInfo or DDKReg_GetWindowInfo failed\r\n"))); goto InitializeOHCI_Error; } if (dwi.dwNumMemWindows!=0) { PhysAddr = dwi.memWindows[0].dwBase; dwAddrLen= dwi.memWindows[0].dwLen; dwIOSpace = 0; } else if (dwi.dwNumIoWindows!=0) { PhysAddr= dwi.ioWindows[0].dwBase; dwAddrLen = dwi.ioWindows[0].dwLen; dwIOSpace = 1; } else { goto InitializeOHCI_Error; } DEBUGMSG(ZONE_INIT,(TEXT("OHCD: Read config from registry: Base Address: 0x%X, Length: 0x%X, I/O Port: %s, SysIntr: 0x%X, Interface Type: %u, Bus Number: %u\r\n"), PhysAddr, dwAddrLen, dwIOSpace ? L"YES" : L"NO", dii.dwSysintr, dwi.dwInterfaceType, dwi.dwBusNumber)); ioPortBase = (PBYTE) PhysAddr; if (!(fResult = ConfigureOHCICard(pPddObject, &ioPortBase, dwAddrLen, dwIOSpace,(INTERFACE_TYPE)dwi.dwInterfaceType, dwi.dwBusNumber))) { goto InitializeOHCI_Error; } if (dii.szIsrDll[0] != 0 && dii.szIsrHandler[0]!=0 && dii.dwIrq<0xff && dii.dwIrq>0 ) { // Install ISR handler pPddObject->IsrHandle = LoadIntChainHandler(dii.szIsrDll, dii.szIsrHandler, (BYTE)dii.dwIrq); if (!pPddObject->IsrHandle) { DEBUGMSG(ZONE_ERROR, (L"OHCD: Couldn't install ISR handler\r\n")); } else { GIISR_INFO Info; PHYSICAL_ADDRESS PortAddress = {PhysAddr, 0}; DEBUGMSG(ZONE_INIT, (L"OHCD: Installed ISR handler, Dll = '%s', Handler = '%s', Irq = %d\r\n", dii.szIsrDll, dii.szIsrHandler, dii.dwIrq)); if (!BusTransBusAddrToStatic(pPddObject->hParentBusHandle,(INTERFACE_TYPE)dwi.dwInterfaceType, dwi.dwBusNumber, PortAddress, dwAddrLen, &dwIOSpace, (PPVOID)&PhysAddr)) { DEBUGMSG(ZONE_ERROR, (L"OHCD: Failed TransBusAddrToStatic\r\n")); goto InitializeOHCI_Error; } // Set up ISR handler Info.SysIntr = dii.dwSysintr; Info.CheckPort = TRUE; Info.PortIsIO = (dwIOSpace) ? TRUE : FALSE; Info.UseMaskReg = TRUE; Info.PortAddr = PhysAddr + 0x0C; Info.PortSize = sizeof(DWORD); Info.MaskAddr = PhysAddr + 0x10; if (!KernelLibIoControl(pPddObject->IsrHandle, IOCTL_GIISR_INFO, &Info, sizeof(Info), NULL, 0, NULL)) { DEBUGMSG(ZONE_ERROR, (L"OHCD: KernelLibIoControl call failed.\r\n")); } } } // The PDD can supply a buffer of contiguous physical memory here, or can let the // MDD try to allocate the memory from system RAM. We will use the HalAllocateCommonBuffer() // API to allocate the memory and bus controller physical addresses and pass this information // into the MDD. if (GetRegistryPhysicalMemSize(szDriverRegKey,&pPddObject->dwPhysicalMemSize)) { // A quarter for High priority Memory. dwHPPhysicalMemSize = pPddObject->dwPhysicalMemSize/4; // Align with page size. pPddObject->dwPhysicalMemSize = (pPddObject->dwPhysicalMemSize + PAGE_SIZE -1) & ~(PAGE_SIZE -1); dwHPPhysicalMemSize = ((dwHPPhysicalMemSize + PAGE_SIZE -1) & ~(PAGE_SIZE -1)); } else { pPddObject->dwPhysicalMemSize=0; dwHPPhysicalMemSize = 0 ; } if (pPddObject->dwPhysicalMemSize<gcTotalAvailablePhysicalMemory) { // Setup Minimun requirement. pPddObject->dwPhysicalMemSize = gcTotalAvailablePhysicalMemory; dwHPPhysicalMemSize = gcHighPriorityPhysicalMemory; } pPddObject->AdapterObject.ObjectSize = sizeof(DMA_ADAPTER_OBJECT); pPddObject->AdapterObject.InterfaceType = dwi.dwInterfaceType; pPddObject->AdapterObject.BusNumber = dwi.dwBusNumber; if ((pPddObject->pvVirtualAddress = HalAllocateCommonBuffer(&pPddObject->AdapterObject, pPddObject->dwPhysicalMemSize, &pPddObject->LogicalAddress, FALSE)) == NULL) { goto InitializeOHCI_Error; } if (!(pobMem = HcdMdd_CreateMemoryObject(pPddObject->dwPhysicalMemSize, dwHPPhysicalMemSize, (PUCHAR) pPddObject->pvVirtualAddress, (PUCHAR) pPddObject->LogicalAddress.LowPart))) { goto InitializeOHCI_Error; } if (!(pobOhcd = HcdMdd_CreateHcdObject(pPddObject, pobMem, szDriverRegKey, ioPortBase, dii.dwSysintr))) { goto InitializeOHCI_Error; } pPddObject->lpvMemoryObject = pobMem; pPddObject->lpvOhcdMddObject = pobOhcd; _tcsncpy(pPddObject->szDriverRegKey, szDriverRegKey, MAX_PATH); pPddObject->ioPortBase = ioPortBase; pPddObject->dwSysIntr = dii.dwSysintr; // PCI OHCI support suspend and resume if ( hKey!=NULL) { DWORD dwCapability; DWORD dwType; DWORD dwLength = sizeof(DWORD); if (RegQueryValueEx(hKey, HCD_CAPABILITY_VALNAME, 0, &dwType, (PUCHAR)&dwCapability, &dwLength) == ERROR_SUCCESS) { HcdMdd_SetCapability(pobOhcd, dwCapability); USBH_INF((_T("[USBH:INF] InitializeOHCI() : USB Host Cap : 0x%08x\n"), dwCapability)); } RegCloseKey(hKey); } USBH_MSG((_T("[USBH] --InitializeOHCI() : Success\n\r"))); return TRUE; InitializeOHCI_Error: if (g_pSysConReg != NULL) { DrvLib_UnmapIoSpace((PVOID)g_pSysConReg); g_pSysConReg = NULL; } if (pPddObject->IsrHandle) { FreeIntChainHandler(pPddObject->IsrHandle); pPddObject->IsrHandle = NULL; } if (pobOhcd) { HcdMdd_DestroyHcdObject(pobOhcd); } if (pobMem) { HcdMdd_DestroyMemoryObject(pobMem); } if(pPddObject->pvVirtualAddress) { HalFreeCommonBuffer(&pPddObject->AdapterObject, pPddObject->dwPhysicalMemSize, pPddObject->LogicalAddress, pPddObject->pvVirtualAddress, FALSE); } pPddObject->lpvMemoryObject = NULL; pPddObject->lpvOhcdMddObject = NULL; pPddObject->pvVirtualAddress = NULL; if ( hKey!=NULL) { RegCloseKey(hKey); } USBH_ERR((_T("[USBH:ERR] --InitializeOHCI() : Error\n\r"))); return FALSE; }