Device node and device stack

Source: Internet
Author: User

MSDN Original:https://msdn.microsoft.com/zh-cn/library/windows/hardware/ff554721 (v=vs.85). aspx

In Windows, a device is represented by a device node in the Plug and Play (PnP) device tree. Typically, when you send an I/O request to a device, some drivers help handle the request. Each of these drivers is associated with a device object that is arranged in the stack. The order of device objects is called the device stack along with their associated drivers. Each device node has its own device stack.

Device node and Plug and Play device tree

Windows organizes devices in a tree structure called a plug-and-play device tree or simply a device tree. Typically, a node in the device tree represents a device or a single function on a composite device. However, some nodes represent software components that are not associated with a physical device.

The nodes in the device tree are called "Device nodes." The root node of the device tree is called the root device node. Under normal circumstances, the root device node is drawn at the bottom of the device tree, as shown in.

The device tree illustrates the parent/child relationships inherent in the PnP environment. Some nodes in the device tree represent the buses that contain the child devices connected to them. For example, a PCI bus node represents a physical PCI bus on the motherboard. During the boot process, the PnP manager requests that the PCI bus driver enumerate the devices that are connected to the PCI bus. These devices are represented by the child nodes of the PCI bus node. In, the PCI bus node contains the child nodes of some devices connected to the PCI bus, including the USB host controller, the audio controller, and the PCI Express port.

Some devices connected to the PCI bus are the bus itself. The PnP manager requests that each of these buses enumerate the devices to which they are connected. In, we can see that the audio controller is a bus that contains the audio device to which it is connected. We can see that the PCI Express port is a bus with a display adapter attached to it, which is a bus that contains a monitor to which it is connected.

It depends on your point of view to treat a node as a device or a bus. For example, you can treat a display adapter as a device that plays a significant role in preparing frames to be displayed on the screen. However, you can also treat the display adapter as a bus that can detect and enumerate the connected monitors.

Device Objects and device stacks

"Device Object" is an instance of the device_object structure. Each device node in the PnP device tree has an ordered list of device objects, each of which is associated with a driver. An ordered list of device objects, together with their associated drivers, is called the device stack of the device node.

You can consider the device stack in a number of ways. In the most formal sense, the device stack is an ordered list of pairs (device objects, drivers). However, in some contexts, it might be useful to treat the device stack as an ordered list of device objects. In other contexts, it might be useful to treat the device stack as an ordered list of drivers.

In general, the device stack has the top and bottom. The first device object created in the device stack is located at the bottom, and the last device object created and attached to the device stack is at the top.

In, the device stack of the Proseware Gizmo device node contains three pairs (device object, driver). The top device object is associated with the driver Afterthought.sys, the middle device object is associated with the driver Proseware.sys, and the device object at the bottom is associated with the driver Pci.sys. The device stack of the PCI bus node in the figure center consists of two pairs (device object, driver), a device object associated with the Pci.sys, and a device object associated with the Acpi.sys.

How do I build a device stack?

During the boot process, the PnP manager requests that the driver for each bus enumerate the sub-devices connected to the bus. For example, the PnP manager requests the PCI bus driver (Pci.sys) to enumerate the devices that are connected to the PCI bus. In response to this request, Pci.sys creates a device object for each device connected to the PCI bus. Each of these device objects is called a physical device object (PDO). Shortly after Pci.sys created the group PDO, the device tree resembles a device tree in.

The PnP Manager associates the device node with each newly created PDO and queries the registry to determine which drivers need to be part of the device stack for that node. The device stack must have one (and only one) function driver, and you can choose to have one or more filter drivers. The function driver is the primary driver for the device stack and is responsible for processing read, write, and device control requests. The filter driver plays a secondary role in processing read, write, and device control requests. When each function driver and filter driver is loaded, it creates a device object and attaches itself to the device stack. A device object created by a function driver is called a function device object (FDO), and a device object created by a filter driver is called a Filter device object (filter do). The device tree is now similar to this diagram.

In this diagram, note that in one node, the filter driver is on top of the function driver, and in another node, the filter driver is under the function driver. The filter driver on the device stack that is above the function driver is called the top filter driver. The filter driver under the function driver is called the down filter driver.

PDO is always the bottom device object in the device stack. This is because of how the device stack is constructed. PDO is created first, and when other device objects are attached to the stack, the objects are appended to the top of the existing stack.

Note

After you install the device driver, Setup uses the information in the information (INF) file to determine which driver is the function driver and which drivers are filters. Typically, INF files are provided by Microsoft or hardware vendors. After the device driver is installed, the PnP Manager can determine the device's function driver and filter driver by locating the registry.

Bus driver

In, you can see that the driver Pci.sys plays two roles. First, the Pci.sys is associated with the FDO in the PCI Bus device node. In fact, Pci.sys has created FDO in the PCI Bus device node. Therefore, the Pci.sys is a function driver for the PCI bus. Second, the Pci.sys is associated with the PDO in each child node of the PCI bus node. Remember that Pci.sys has created PDO for the child device. The driver that creates PDO for a device node is called the bus driver for that node.

If your reference point is a PCI bus, then Pci.sys is the function driver. But if your reference point is a Proseware Gizmo device, then Pci.sys is the bus driver. This dual role is typical in the PnP device tree. The driver for the function driver for the bus is also the bus driver for the bus sub-device.

User-mode device stacks

So far, we've covered the kernel-mode device stack. That is, the driver in the stack runs in the kernel mode, and the device object is mapped to system space, which is the only address space that can be used by code running in kernel mode. For information about the differences between kernel mode and user mode, see user mode and kernel mode.

In some cases, the device has not only a kernel-mode device stack, but also a user-mode device stack. User-mode drivers are typically based on the user-mode driver Framework (UMDF), which is one of the driver models provided by the Windows Driver Framework (WDF). In UMDF, the driver is a user-mode DLL, and the device object is a COM object that implements the Iwdfdevice interface. The device object in the UMDF device stack is called a WDF device object (WDF do).

Displays the device node, the kernel-mode device stack, and the user-mode device stack for the usb-fx-2 device. Drivers in user-mode and kernel-mode stacks participate in I/O requests that are directed on usb-fx-2 devices.

Device node and device stack

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.