標籤:
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驅動]基本概念