⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ncfindhardware.c

📁 CE下 NET2778 NDIS Drivers, 在每个平台上都可以使用
💻 C
字号:
#include <windows.h>
#include <nkintr.h>
#include <ceddk.h>
#include <giisr.h>
#include <ddkreg.h>

#if _NC_BANDON
#include "oalintr.h"

#include "XSC1.h"
#include "XSC1bd.h"
#include "dmacbits.h"
#include <NcXscale.h>

#endif // #if _NC_BANDON

#if _NC_CEPC
#include <plx.h>

///////////////////////////////////////////////////////////////////////////////
PVOID * TranslatePCIAddress(DWORD dwBusNumber,PHYSICAL_ADDRESS physAddress,ULONG addrLen,ULONG inIoSpace)
{
    PVOID pReturnAddress=NULL;
    // Map address to the 2280
    if (HalTranslateBusAddress(PCIBus, dwBusNumber, physAddress, &inIoSpace, &physAddress)) 
    {
        if (!inIoSpace) 
        {
            if ((pReturnAddress = (PUCHAR) MmMapIoSpace(physAddress, addrLen, FALSE)) == NULL) 
            {
                DEBUGMSG(TRUE, (TEXT("FindHardware: Error mapping 2280 I/O Ports.\r\n")));
            }
        } 
        else 
        {
            pReturnAddress = (PUCHAR) physAddress.LowPart;
        }
    } ;
    return pReturnAddress;
}

///////////////////////////////////////////////////////////////////////////////
#define PLX9054_BASE_ADDR_NUM 0
#define NETCHIP_BAR 2

BOOL 
FindHardware(PUCHAR *NcAddress, PUCHAR *plx9054Address, PULONG pIrq, HKEY hKey)
{
    DDKWINDOWINFO wini;
    DDKISRINFO isri;
    DDKPCIINFO pcii;
    DWORD dwStatus;
    HKEY m_hKey = hKey;
    PHYSICAL_ADDRESS PortAddress;

    if (m_hKey==NULL) // Open key fails
        return FALSE;
    // read window information
    wini.cbSize = sizeof(wini);
    dwStatus = DDKReg_GetWindowInfo(m_hKey, &wini);
    if(dwStatus != ERROR_SUCCESS) {
        DEBUGMSG(TRUE, (_T("NCSYSTEM: DDKReg_GetWindowInfo() failed %d\r\n"), dwStatus));
        //RegCloseKey (m_hKey);
        return FALSE;
    }

    // sanity check return values
    if(wini.dwNumMemWindows <3 ) {
        DEBUGMSG(TRUE, (_T("NCSYSTEM: invalid window parameters read from registry\r\n")));
        //RegCloseKey (m_hKey);
        return FALSE;
    }

    // read ISR information
    isri.cbSize = sizeof(isri);
    dwStatus = DDKReg_GetIsrInfo(m_hKey, &isri);
    if(dwStatus != ERROR_SUCCESS) {
        DEBUGMSG(TRUE, (_T("NCSYSTEM: DDKReg_GetIsrInfo() failed %d\r\n"), dwStatus));
        //RegCloseKey (m_hKey);
        return FALSE;
    }

    // sanity check return values
    if(isri.dwSysintr == SYSINTR_NOP) {
        DEBUGMSG(TRUE, (_T("NCSYSTEM: no sysintr specified in registry\r\n")));
        //RegCloseKey (m_hKey);
        return FALSE;
    }
    if(isri.szIsrDll[0] != 0) {
        if(isri.szIsrHandler[0] == 0 || isri.dwIrq == IRQ_UNSPECIFIED) {
            DEBUGMSG(TRUE, (_T("NCSYSTEM: invalid installable ISR information in registry\r\n")));
            //RegCloseKey (m_hKey);
            return FALSE;
        }
    }

    // read PCI id
    pcii.cbSize = sizeof(pcii);
    dwStatus = DDKReg_GetPciInfo(m_hKey, &pcii);
    if(dwStatus != ERROR_SUCCESS) {
        DEBUGMSG(TRUE, (_T("NCSYSTEM: DDKReg_GetPciInfo() failed %d\r\n"), dwStatus));
        //RegCloseKey (m_hKey);
        return FALSE;
    }
    //RegCloseKey (m_hKey);

    // sanity check return values
    if((pcii.dwWhichIds & (PCIIDM_DEVICEID | PCIIDM_REVISIONID)) != (PCIIDM_DEVICEID | PCIIDM_REVISIONID)) {
        DEBUGMSG(TRUE, (_T("NCSYSTEM: insufficient device ID information in registry\r\n")));
        return FALSE;
    }

/*    if (!KernelIoControl(
        IOCTL_HAL_TRANSLATE_IRQ, 
        &isri.dwIrq, 
        sizeof(isri.dwIrq), 
        &isri.dwSysintr,
        sizeof(isri.dwSysintr),
        NULL)) 
    {
        DEBUGMSG(TRUE, 
            (TEXT("NCSYSTEM: IRQ -> SYSINTR translation failed\r\n")));
        
        return FALSE;;
    }        
*/    
 
    // Install ISR handler if there is one
    if (isri.szIsrDll[0] != 0) {
        // Install ISR handler
        HANDLE m_hIsrHandler = LoadIntChainHandler(isri.szIsrDll, isri.szIsrHandler, (BYTE) isri.dwIrq);

        DEBUGMSG(TRUE, (TEXT("FindHardware: Install ISR for irq @ 0x%x map to  SysInter=0x%x \r\n"), isri.dwIrq,isri.dwSysintr));
        if (m_hIsrHandler == NULL) {
            DEBUGMSG(TRUE, (TEXT("NCSYSTEM: Couldn't install ISR handler\r\n")));
        } else {
            GIISR_INFO Info;
            DWORD dwPhysAddr;
            DWORD inIoSpace=0;

            PortAddress.LowPart=wini.memWindows[PLX9054_BASE_ADDR_NUM].dwBase;
            PortAddress.HighPart=0;
            if (!TransBusAddrToStatic(PCIBus, wini.dwBusNumber, PortAddress,wini.memWindows[PLX9054_BASE_ADDR_NUM].dwLen, &inIoSpace, (PVOID *)&dwPhysAddr)) {
                DEBUGMSG(TRUE, (TEXT("FindHardware: Failed TransBusAddrToStatic\r\n")));
                return FALSE;
            }
            
            DEBUGMSG(TRUE, (TEXT("FindHardware: Installed ISR handler, Dll = '%s', Handler = '%s', Irq = %d, PhysAddr = 0x%x\r\n"),
                isri.szIsrDll, isri.szIsrHandler, isri.dwIrq, dwPhysAddr));
            
            // Set up ISR handler
            Info.SysIntr = isri.dwSysintr;
            Info.CheckPort = TRUE;
            Info.PortIsIO = FALSE;
            Info.UseMaskReg = FALSE;
            Info.PortAddr = (DWORD)dwPhysAddr + INTCSR;
            Info.PortSize = sizeof(DWORD);
            Info.Mask = (1<<LOCAL_INPUT_INTERRUPT_ACTIVE);
             
            if (!KernelLibIoControl(m_hIsrHandler, IOCTL_GIISR_INFO, &Info, sizeof(Info), NULL, 0, NULL)) {
                DEBUGMSG(TRUE, (TEXT("NCSYSTEM: KernelLibIoControl call failed.\r\n")));
                return FALSE;
            }
        }
    }

    *pIrq = isri.dwSysintr;
    DEBUGMSG(TRUE, (TEXT("FindHardware: Irq @ 0x%x map to  SysInter=0x%x \r\n"), isri.dwIrq,isri.dwSysintr));

    PortAddress.LowPart=wini.memWindows[NETCHIP_BAR].dwBase;
    PortAddress.HighPart=0;
    DEBUGMSG(TRUE, (TEXT("FindHardware: Netchip(PCI) @ 0x%x, Lenght=0x%x \r\n"), 
        wini.memWindows[NETCHIP_BAR].dwBase, wini.memWindows[NETCHIP_BAR].dwLen));

    if ((*NcAddress=(PUCHAR)TranslatePCIAddress(wini.dwBusNumber, PortAddress,wini.memWindows[NETCHIP_BAR].dwLen,0))==NULL) {
        DEBUGMSG(TRUE, (TEXT("FindHardware: Error translating 2280 I/O Ports.\r\n")));
        return FALSE;
    };

    PortAddress.LowPart=wini.memWindows[PLX9054_BASE_ADDR_NUM].dwBase;
    PortAddress.HighPart=0;
    DEBUGMSG(TRUE, (TEXT("FindHardware: PLX9050(PCI) @ 0x%x, Lenght=0x%x \r\n"), 
        wini.memWindows[PLX9054_BASE_ADDR_NUM].dwBase, wini.memWindows[PLX9054_BASE_ADDR_NUM].dwLen));

    if ((*plx9054Address=(PUCHAR)TranslatePCIAddress(wini.dwBusNumber,PortAddress,wini.memWindows[PLX9054_BASE_ADDR_NUM].dwLen,0))==NULL) {
        DEBUGMSG(TRUE, (TEXT("FindHardware: Error translating 9054 I/O Ports.\r\n")));
        return FALSE;
    }

    DEBUGMSG(TRUE, (TEXT("FindHardware: NET2280 @ 0x%x, IRQ = %d\r\n"), 
        *NcAddress, *pIrq));

    return TRUE;
}
///////////////////////////////////////////////////////////////////////////////
#endif // #if _NC_CEPC

///////////////////////////////////////////////////////////////////////////////
//  End of file
///////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -