Exemplo n.º 1
0
BOOL
CPCIDisk::Init(
    HKEY hActiveKey
    )
{
    BOOL bRet = FALSE;

    m_f16Bit = TRUE; // PCI is 16-bit

    // configure port
    if (!ConfigPort()) {
        DEBUGMSG(ZONE_INIT, (_T(
            "Atapi!CPCIDisk::Init> Failed to configure port; device(%u)\r\n"
            ), m_dwDeviceId));
        goto exit;
    }

    // assign the appropriate folder name
    m_szDiskName = (IsCDRomDevice() ? g_szPCICDRomDisk : g_szPCIHardDisk);

    // reserve memory for DMA buffers
    m_pStartMemory = (LPBYTE)VirtualAlloc(NULL, 0x10000, MEM_RESERVE, PAGE_READWRITE);
    if (!m_pStartMemory) {
        bRet = FALSE;
    }

    // finish intialization; i.e., initialize device
    bRet = CDisk::Init(hActiveKey);
    if (!bRet) {
        goto exit;
    }

exit:;
    return bRet;
}
Exemplo n.º 2
0
BOOL
CRomiDisk::Init(
    HKEY hActiveKey
    )
{
    BOOL bRet = FALSE;

    m_f16Bit = TRUE; // PCI is 16-bit

    // configure port
    if (!InitializePort()) {
        DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
            "Atapi!CRomiDisk::Init> Failed to configure port; device(%u)\r\n"
            ), m_dwDeviceId));

        goto exit;
    }

    // assign the appropriate folder name
    m_szDiskName = (IsCDRomDevice() ? g_szPCICDRomDisk : g_szPCIHardDisk);

    // reserve memory for DMA buffers
    m_pStartMemory = (LPBYTE)VirtualAlloc(NULL, 0x10000, MEM_RESERVE, PAGE_READWRITE);
    if (!m_pStartMemory) {
        bRet = FALSE;
    }

    WriteReg(ATA_CONTROL, ReadReg(ATA_CONTROL) | 0x1);
    // finish intialization; i.e., initialize device
    bRet = CDisk::Init(hActiveKey);

    if ((m_pPort->m_pDskReg[m_dwDeviceId]->dwEnablePDMA || m_pPort->m_pDskReg[m_dwDeviceId]->dwEnableUDMA) && m_pDMAVirtualAddress == NULL)
    {
        DMA_ADAPTER_OBJECT dmaAdapter;
        dmaAdapter.ObjectSize = sizeof(dmaAdapter);
        dmaAdapter.InterfaceType = Internal;
        dmaAdapter.BusNumber = 0;
        m_pDMAVirtualAddress= (PBYTE)HalAllocateCommonBuffer( &dmaAdapter, m_pPort->m_pDskReg[m_dwDeviceId]->dwDoubleBufferSize, &m_DMAPhyaddress, FALSE );
    }

    if (m_pPort->m_pDskReg[m_dwDeviceId]->dwEnableUDMA && ( m_Id.UltraDMASupport & 0x3f))
    {    
        for(int i=5;i>=0;i--) {
            if(m_Id.UltraDMASupport & (0x01<<i)) {
                m_dwCurrentUDMAMode = (i > 4) ? 4 : i;
                break; 
            }
        }     
        SetPioMode(PIO0);        
        SetUdmaMode();
        DEBUGMSG(ZONE_INIT, (_T("### ATA-Disk supports UDMA to 0x%x 0x%x\r\n"), m_Id.UltraDMASupport,m_dwCurrentUDMAMode));  
        m_pPort->m_pDskReg[m_dwDeviceId]->dwEnablePDMA = FALSE;

    }
    else if (m_pPort->m_pDskReg[m_dwDeviceId]->dwEnablePDMA)
    {
        SetPioMode(m_Id.AdvancedPIOxferreserved);
        m_pPort->m_pDskReg[m_dwDeviceId]->dwEnableUDMA = FALSE;;    
        DEBUGMSG(ZONE_INIT, (_T("### ATA-Disk dose not support UDMA. It is running on PDMA\r\n")));  
    }
    else {
        SetPioMode(m_Id.AdvancedPIOxferreserved);
        m_pPort->m_pDskReg[m_dwDeviceId]->dwEnableUDMA = FALSE;;        
        m_pPort->m_pDskReg[m_dwDeviceId]->dwEnablePDMA = FALSE;;        
        DEBUGMSG(ZONE_INIT, (_T("### ATA-Disk is running on PIO MODE\r\n")));          
        DEBUGMSG(ZONE_INIT, (_T("Atapi!CDisk::Init> Disabled DMA\r\n")));
    }

    // associate interrupt event with IRQ
    if (!InterruptInitialize(
        m_pPort->m_dwSysIntr,
        m_pPort->m_hIRQEvent,
        NULL,
        0)
    ) {
        DEBUGMSG(ZONE_INIT|ZONE_ERROR, (_T(
            "Atapi!CRomiDisk::ConfigPort> Failed to initialize interrupt(SysIntr(%d)) for device(%d)\r\n"
            ), m_pPort->m_dwSysIntr, m_dwDeviceId));
        bRet = FALSE;
    }

    if (!bRet) {
        goto exit;
    }

exit:;
    return bRet;
}