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

📄 devclass.cpp

📁 RTL8139 网卡驱动源码 for WinCE.net CEPC
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//****************************************************************************
//                            File DEVCLASS.CPP
//
//                   Device object for functional driver
//
//                     Copyright (c) APSoft, 1998-2002.
//                          All rights reserved.
//
//****************************************************************************


#define INITGUID
extern "C"
{
#include <ntddk.h>                          // Main DDK's include
#include <wdmguid.h>                        // Interface IDs
#include <wmidata.h>                        // WMI GUIDs
#include <devguid.h>                        // GUIDs for device classes
#include <ntddpcm.h>                        // PCMCIA specific
}

#include <devclass.h>                       // Class declaration
#include <utils.h>                          // PnpQueryInterface

//--------------------------- Local definitions ------------------------------

#define MEM_LOW                 0x00000000  // The whole possible PC's memory
#define MEM_HIGH                0xFFFFFFFF
#define MEM_SIZE                0x00004000  //  memory window


///////////////////////////////////////////////////////////////////////////////
//                        --- Class CFuncDevice ---                          //
///////////////////////////////////////////////////////////////////////////////

//****************************************************************************
//                    --- CFuncDevice::CFuncDevice ---
//
// Purpose: CFuncDevice object constructor
//   Input: PDEVICE_OBJECT pDevObject - Address of assotiated device object
//          PDEVICE_OBJECT pPdo       - Physical device object
//          PWSTR          pLnkName   - Name of symbolic link or NULL
//  Output: none
// Written: by Anton V. Krivenko 4/10/2002
//****************************************************************************
CFuncDevice::CFuncDevice(PDEVICE_OBJECT pDevObject, PDEVICE_OBJECT pPdo,
                         PWSTR          pLnkName) :
             CPnpDevice(pDevObject, pPdo, pLnkName)
{
    m_uStart             = 0;
    m_uLength            = 0;
	m_dwMask             = 0;
	m_uMemBaseAddr       = 0;
	m_phyMemAddr.LowPart  = 0;
	m_phyMemAddr.HighPart = 0;

    m_pDevObject->Flags |= DO_DIRECT_IO |
                          (m_pNextStackDevice->Flags & (DO_POWER_PAGABLE | DO_POWER_INRUSH));
    m_pDevObject->Flags &= ~DO_DEVICE_INITIALIZING;
}

//****************************************************************************
//                    --- CFuncDevice::~CFuncDevice ---
//
// Purpose: CFuncDevice object destructor
//   Input: none
//  Output: none
// Written: by Anton V. Krivenko 4/11/2002
//****************************************************************************
CFuncDevice::~CFuncDevice(void)
{
}

//****************************************************************************
//                      --- CFuncDevice::PowerOn ---
//
// Purpose: Proceed power on process
//   Input: none
//  Output: none
// Written: by Anton V. Krivenko 4/10/2002
//****************************************************************************
void CFuncDevice::PowerOn(void)
{
    // ...
    // You can implement here any specific code, which should be executed on
    // device powering on.
    // ...
}

//****************************************************************************
//                      --- CFuncDevice::PowerOff ---
//
// Purpose: Procees power off process
//   Input: none
//  Output: none
// Written: by Anton V. Krivenko 4/10/2002
//****************************************************************************
void CFuncDevice::PowerOff(void)
{
    // ...
    // You can implement here any specific code, which should be executed on
    // device powering off.
    // ...
}

//****************************************************************************
//                   --- CFuncDevice::PreStopDevice ---
//
// Purpose: Pre-stop processing
//   Input: none
//  Output: none
// Written: by Anton V. Krivenko 4/10/2002
//****************************************************************************
void CFuncDevice::PreStopDevice(void)
{
    // ...
    // You can implement here any specific code, which should be executed on
    // device stopping (e.g. via Device Manager).
    // ...
}

//****************************************************************************
//                  --- CFuncDevice::PreRemoveDevice ---
//
// Purpose: Pre-remove device processing
//   Input: PIRP pIrp - IRP
//  Output: none
// Written: by Anton V. Krivenko 4/10/2002
//****************************************************************************
void CFuncDevice::PreRemoveDevice(PIRP pIrp)
{
    // ...
    // You can implement here any specific code, which should be executed on
    // device removal from socket.
    // ...
}

//****************************************************************************
//                     --- CFuncDevice::StopDevice ---
//
// Purpose: Stop device
//   Input: none
//  Output: none
// Written: by Anton V. Krivenko 4/10/2002
//****************************************************************************
void CFuncDevice::StopDevice(void)
{
//------------------------ Dereference interfaces ----------------------------

    m_BusIface.DeReference();
    m_PcmciaIface.DeReference();
}

//****************************************************************************
//                   --- CFuncDevice::OnFilterResReq ---
//
// Purpose: Filter resource requirements
//   Input: PIRP     pIrp - IRP
//  Output: NTSTATUS      - Operation status
// Written: by Anton V. Krivenko 4/11/2002
//****************************************************************************
NTSTATUS CFuncDevice::OnFilterResReq(PIRP pIrp)
{
    // The CIS of PCMCIA card, which supports by this driver can contain
    // resource requirements. But sometimes there is no resources in CIS. This
    // method receives resource list for filtering from PnP manager. If card
    // have no CIS, then list will be NULL. You can fill this list here
    // manually. Otherwise (list will not NULL), you can correct here resources.

    STRACE_PNPDRV(">> CFuncDevice::OnFilterResReq()\n");

//------------------------------ Forward IRP ---------------------------------

    NTSTATUS ntStatus = ForwardAndWait(m_pNextStackDevice, pIrp);

    if (NT_SUCCESS(ntStatus))
    {
        // PDO can return some filtered resource list for device. We can correct
        // this list or remove it and create own list. In this sample we ignore
        // PDO's list.

        if (pIrp->IoStatus.Information != NULL)
            ExFreePool((PVOID)pIrp->IoStatus.Information);

        ULONG            nBytes = sizeof(IO_RESOURCE_REQUIREMENTS_LIST);

        PHYSICAL_ADDRESS paLow;             // Low address
        PHYSICAL_ADDRESS paHigh;            // High address
        ULONG            uLength;           // Size of memory

        paLow.QuadPart  = MEM_LOW;
        paHigh.QuadPart = MEM_HIGH;
        uLength         = MEM_SIZE;

//------------------------- Create resource list -----------------------------

        PIO_RESOURCE_REQUIREMENTS_LIST pList =
            (PIO_RESOURCE_REQUIREMENTS_LIST)ExAllocatePool(PagedPool, nBytes);

        RtlZeroMemory(pList, nBytes);

        pList->ListSize         = nBytes;
        pList->InterfaceType    = PCMCIABus;
        pList->BusNumber        = 0;
        pList->SlotNumber       = 0;
        pList->AlternativeLists = 1;

        pList->List[0].Version  = 1;
        pList->List[0].Revision = 1;
        pList->List[0].Count    = 1;

        PIO_RESOURCE_DESCRIPTOR piord    = pList->List[0].Descriptors;

        piord[0].Option                  = IO_RESOURCE_PREFERRED;
        piord[0].Type                    = CmResourceTypeMemory;
        piord[0].ShareDisposition        = CmResourceShareDeviceExclusive;
        piord[0].Flags                   = CM_RESOURCE_MEMORY_READ_WRITE;
        piord[0].u.Memory.Length         = uLength;
        piord[0].u.Memory.Alignment      = uLength;
        piord[0].u.Memory.MinimumAddress = paLow;
        piord[0].u.Memory.MaximumAddress = paHigh;

        pIrp->IoStatus.Information       = (ULONG)pList;
    }                                       // if (NT_SUCCESS(ntStatus))

    pIrp->IoStatus.Status = ntStatus;
    IoCompleteRequest(pIrp, IO_NO_INCREMENT);

    STRACE_PNPDRV("<< CFuncDevice::OnFilterResReq()- ntStatus=%08lX\n", ntStatus);
    return ntStatus;
}

//****************************************************************************
//                   --- CFuncDevice::PreStartDevice ---
//
// Purpose: Pre-start device processing

⌨️ 快捷键说明

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