显示驱动教程(4)

DriverEntry

DriverEntryminiport驱动的入口,每个miniport驱动程序都应该实现它。在DriverEntry中应该完成的任务如下:

l         定义一个VIDEO_HW_INITIALIZATION_DATA结构,并将其初始化。初始化的内容包括:miniport驱动程序的其他入口、设备扩展(Device Extension)的大小等等。<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

   

VIDEO_HW_INITIALIZATION_DATA hwInitData.

 

// Zero out structure.

VideoPortZeroMemory(

&hwInitData, sizeof(VIDEO_HW_INITIALIZATION_DATA));

 

 

// Specify sizes of structure and extension.

hwInitData.HwInitDataSize = sizeof(VIDEO_HW_INITIALIZATION_DATA);

 

// Set entry points.

hwInitData.HwFindAdapter             = &VirtualFindAdapter;

hwInitData.HwInitialize              = &VirtualInitialize;

hwInitData.HwStartIO                 = &VirtualStartIO;

hwInitData.HwGetPowerState           = &VirtualGetPowerState;

hwInitData.HwSetPowerState           = &VirtualSetPowerState;

 

hwInitData.HwLegacyResourceList      = NULL;

hwInitData.HwLegacyResourceCount     = 0;

 

// Set device extension size.

hwInitData.HwDeviceExtensionSize = sizeof(HW_DEVICE_EXTENSION);

 

// Virtual device's interface type is zero.

hwInitData.AdapterInterfaceType = 0;

 

l         调用VideoPortInitialize函数,将VIDEO_HW_INITIALIZATION_DATA结构的地址指针通知系统。

    initializationStatus = VideoPortInitialize(Context1,

                                     Context2,

                                     &hwInitData,

                                     NULL);

 

l         VideoPortInitialize的返回值作为DriverEntry函数的返回值,返回调用者。

return initializationStatus;

 

代码说明:

虚拟显示驱动类似mirror驱动,所以我就在mirror的基础上作了相应的修改;这也是微软建议的实现方法:修改一个现存的显示驱动,减少开发时间。Mirror驱动的miniport实现十分简单,基本上所有函数的都是一个空函数。我对DriverEntry作的修改主要是:为自定义的设备扩展申请存储空间。

hwInitData.HwDeviceExtensionSize = sizeof(HW_DEVICE_EXTENSION);

HW_DEVICE_EXTENSION是我自己定义的一个结构,用于存放帧缓冲区的地址:

//

// Define device extension structure. This is device dependent/private

// information.

//

typedef struct _HW_DEVICE_EXTENSION

{

       // Frame buffer

       ULONG ulFrameBufferSize;

       PVOID pFrameBufferAddr;

 

}HW_DEVICE_EXTENSION, *PHW_DEVICE_EXTENSION;

 

DriverEntry完整的代码如下:

ULONG

DriverEntry (

    PVOID Context1,

    PVOID Context2

    )

{

 

    VIDEO_HW_INITIALIZATION_DATA hwInitData;

    ULONG initializationStatus;

 

    VideoDebugPrint((0, "Virtualed Driver VideoPort [Driver Entry]/n"));

 

    // Zero out structure.

 

    VideoPortZeroMemory(&hwInitData, sizeof(VIDEO_HW_INITIALIZATION_DATA));

 

    // Specify sizes of structure and extension.

 

    hwInitData.HwInitDataSize = sizeof(VIDEO_HW_INITIALIZATION_DATA);

 

    // Set entry points.

 

    hwInitData.HwFindAdapter             = &VirtualFindAdapter;

    hwInitData.HwInitialize              = &VirtualInitialize;

    hwInitData.HwStartIO                 = &VirtualStartIO;

    hwInitData.HwGetPowerState           = &VirtualGetPowerState;

    hwInitData.HwSetPowerState           = &VirtualSetPowerState;

   

    hwInitData.HwLegacyResourceList      = NULL;

    hwInitData.HwLegacyResourceCount     = 0;

 

    // Set device extension size.

    hwInitData.HwDeviceExtensionSize = sizeof(HW_DEVICE_EXTENSION);

 

    // Virtual device's interface type is zero.

    hwInitData.AdapterInterfaceType = 0;

 

    initializationStatus = VideoPortInitialize(Context1,

                                               Context2,

                                               &hwInitData,

                                               NULL);

 

    return initializationStatus;

 

} // end DriverEntry()

阅读更多
个人分类: Display Driver
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭