码迷,mamicode.com
首页 > Windows程序 > 详细

[windows驱动]基本概念

时间:2015-02-26 18:05:55      阅读:243      评论:0      收藏:0      [点我收藏+]

标签:

https://msdn.microsoft.com/zh-cn/library/windows/hardware/ff554721

 

1、设备节点和设备堆栈

在windows中,设备通过即插即用设备树中的设备节点表示。典型地,当设备接受到一个I/O请求,数个驱动帮忙处理这个请求,这些驱动各自与一个设备对象相关,这些设备对象在堆栈中有序排列。一个设备对象序列以及它们各自相关的驱动称为设备堆栈。每个设备节点拥有一个它们自己的设备堆栈。

1.2、设备对象和设备堆栈

一个设备对象是一个DEVICE_OBJECT的实例。pnp树中的每一个设备节点都有一个有序的设备对象列表,每一个设备对象都有一个相关的驱动。这个有序设备对象列表及设备对象的相关驱动组成设备节点的设备堆栈。

我们可以从多个角度来看待这个设备堆栈概念。最普遍的看法是:一个设备堆栈是一个有序的设备对象和驱动的列表;但在有些上下文中,我们认为设备堆栈就是一个有序设备对象列表;而在另一些上下文中,我们认为设备堆栈是一个有序设备驱动列表。

A device object is an instance of a DEVICE_OBJECT structure. Each device node in the PnP device tree has an ordered list of device objects, and each of these device objects is associated with a driver. The ordered list of device objects, along with their associated drivers, is called the device stack for the device node.

You can think of a device stack in several ways. In the most formal sense, a device stack is an ordered list of (device object, driver) pairs. However, in certain contexts it might be useful to think of the device stack as an ordered list of device objects. In other contexts, it might be useful to think of the device stack as an ordered list of drivers.

By convention, a device stack has a top and a bottom. The first device object to be created in the device stack is at the bottom, and the last device object to be created and attached to the device stack is at the top.

In the following diagram, the Proseware Gizmo device node has a device stack that contains three (device object, driver) pairs. The top device object is associated with the driver AfterThought.sys, the middle device object is associated with the driver Proseware.sys, and the bottom device object is associated with the driver Pci.sys. The PCI Bus node in the center of the diagram has a device stack that contains two (device object, driver) pairs--a device object associated with Pci.sys and a device object associated with Acpi.sys.

1.3、如何构建设备堆栈:

在启动过程中,PnP 管理器请求每个总线的驱动程序枚举连接到该总线的子设备。例如,PnP 管理器请求 PCI 总线驱动程序 (Pci.sys) 枚举连接到该 PCI 总线的设备。为了响应此请求,Pci.sys 会为连接到 PCI 总线的每个设备创建一个设备对象。这些设备对象中的每一个都被称为“物理设备对象”(PDO)。在 Pci.sys 创建该组 PDO 不久之后,设备树类似于下图中的一个设备树。

                                       技术分享

PnP 管理器将设备节点与每个新创建的 PDO 关联,并查询注册表以确定哪些驱动程序需要成为该节点设备堆栈的一部分。设备堆栈必须具有一个(且只有一个)“函数驱动程序”,并且可以选择具有一个或多个“筛选器驱动程序”。 函数驱动程序为设备堆栈的主要驱动程序且负责处理读、写以及设备控制请求。筛选器驱动程序在处理读、写以及设备控制请求中扮演辅助角色。加载每个函数驱动 程序和筛选器驱动程序时,它都会创建一个设备对象并将其自身附加到设备堆栈。由函数驱动程序创建的设备对象称为“函数设备对象”(FDO),由筛选器驱动程序创建的设备对象称为“筛选器设备对象”(筛选器 DO)。现在设备树类似于此图。

                                                   技术分享

在该图中,注意在一个节点中,筛选器驱动程序位于函数驱动程序之上,而在另一节点中,筛选器驱动程序位于函数驱动程序之下。在设备堆栈中位于函数驱动程序之上的筛选器驱动程序称为“上筛选器驱动程序”。位于函数驱动程序之下的筛选器驱动程序称为“下筛选器驱动程序”。

PDO 始终为设备堆栈中的底部设备对象。这缘于设备堆栈的构造方式。PDO 最先创建,并且当其他设备对象附加到堆栈中时,这些对象会附加到现有堆栈的顶部。

[注]:安装设备驱动程序后,安装程序使用信息 (INF) 文件中的信息来确定哪个驱动程序为函数驱动程序,哪些驱动程序为筛选器。通常,INF 文件由 Microsoft 或硬件供应商提供。安装设备驱动程序后,PnP 管理器可以通过查找注册表来确定设备的函数驱动程序和筛选器驱动程序。

1.4、总线驱动程序

在上图中,你可以看到驱动程序 Pci.sys 扮演两个角色。第一,Pci.sys 与 PCI 总线设备节点中的 FDO 关联。事实上,Pci.sys 已在 PCI 总线设备节点中创建 FDO。因此,Pci.sys 为 PCI 总线的函数驱动程序。第二,Pci.sys 与 PCI 总线节点的每个子节点中的 PDO 关联。谨记 Pci.sys 已为子设备创建 PDO。为设备节点创建 PDO 的驱动程序称为该节点的“总线驱动程序”。

如果你的参考点为 PCI 总线,则 Pci.sys 为函数驱动程序。但如果你的参考点为 Proseware Gizmo 设备,则 Pci.sys 为总线驱动程序。此双重角色为 PnP 设备树中的典型。作为总线的函数驱动程序的驱动程序也是总线子设备的总线驱动程序。

 

[windows驱动]基本概念

标签:

原文地址:http://www.cnblogs.com/victor-ma/p/4301648.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!