/* ConfigureOHCICard * */ BOOL ConfigureOHCICard( SOhcdPdd * pPddObject, // IN - contains PDD reference pointer. PUCHAR *pioPortBase, // IN - contains physical address of register base // OUT- contains virtual address of register base DWORD dwAddrLen, DWORD dwIOSpace, INTERFACE_TYPE IfcType, DWORD dwBusNumber) { ULONG inIoSpace = dwIOSpace; ULONG portBase; PHYSICAL_ADDRESS ioPhysicalBase = {0, 0}; portBase = (ULONG)*pioPortBase; ioPhysicalBase.LowPart = portBase; if (!BusTransBusAddrToVirtual(pPddObject->hParentBusHandle, IfcType, dwBusNumber, ioPhysicalBase, dwAddrLen, &inIoSpace, (PPVOID)pioPortBase)) { DEBUGMSG(ZONE_ERROR, (L"OHCD: Failed TransBusAddrToVirtual\r\n")); return FALSE; } DEBUGMSG(ZONE_INIT, (TEXT("OHCD: ioPhysicalBase 0x%X, IoSpace 0x%X\r\n"), ioPhysicalBase.LowPart, inIoSpace)); DEBUGMSG(ZONE_INIT, (TEXT("OHCD: ioPortBase 0x%X, portBase 0x%X\r\n"), *pioPortBase, portBase)); return TRUE; }
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; }