Difference between revisions of "How the system Finds and Loads Drivers"

From ReactOS Wiki
Jump to: navigation, search
(Created page with "=How the system Finds and Loads Drivers =original: http://blogs.msdn.com/b/xiz/archive/2013/11/04/how-the-system-finds-and-loads-drivers.aspx 1. PnP device It has an electron...")
 
m
Line 1: Line 1:
=How the system Finds and Loads Drivers =original: http://blogs.msdn.com/b/xiz/archive/2013/11/04/how-the-system-finds-and-loads-drivers.aspx
+
=How the system Finds and Loads Drivers=
1. PnP device
+
 
 +
original: http://blogs.msdn.com/b/xiz/archive/2013/11/04/how-the-system-finds-and-loads-drivers.aspx
 +
 
 +
===1. PnP device===
  
 
It has an electronic signature that bus driver can detect the new hardware
 
It has an electronic signature that bus driver can detect the new hardware
  
2. Legacy device
+
===2. Legacy device===
  
 
Initiate the detection by invoking Add New Hardware Wizard.
 
Initiate the detection by invoking Add New Hardware Wizard.
Line 13: Line 16:
  
  
Function driver:
+
===Function driver:===
  
 
It understands the details about how to make the HW work.
 
It understands the details about how to make the HW work.
Line 20: Line 23:
  
  
 
+
Bus driver:
+
===Bus driver:===
  
 
It's responsible for managing the connection between the HW and the computer.
 
It's responsible for managing the connection between the HW and the computer.
Line 27: Line 30:
  
  
Filter Driver:
+
===Filter Driver:===
  
to Modify the behavior of an existing function driver in some way.Upper filter driver sees IRPs before function driver. Lower filter can modify the stream of bus operations that the function driver is trying to perform.
+
to Modify the behavior of an existing function driver in some way. Upper filter driver sees IRPs before function driver. Lower filter can modify the stream of bus operations that the function driver is trying to perform.
  
  
  
PDO stands for physical device object. The bus driver uses it to represent the conncetion between the device and the bus.
+
'''PDO''' stands for physical device object. The bus driver uses it to represent the conncetion between the device and the bus.
  
FDO stands for function devive object. The function driver uses it to manage the functionality of the device.
+
'''FDO''' stands for function devive object. The function driver uses it to manage the functionality of the device.
  
  
  
Installing a PnP Device:
+
==Installing a PnP Device:==
  
 
1.Bus driver detects the insertion or removal of hardware.
 
1.Bus driver detects the insertion or removal of hardware.
  
2.Bus driver calls IoInvalidateDeviceRelations to notify PnP manager that the bus's population of child devices has changed.
+
2.Bus driver calls '''IoInvalidateDeviceRelations''' to notify PnP manager that the bus's population of child devices has changed.
  
3.PnP manager sends IRP_MN_QUERY_DEVICE_RELATIONS to bus driver, to obtain an updated list of the PDOs for the child devices.
+
3.PnP manager sends '''IRP_MN_QUERY_DEVICE_RELATIONS''' to bus driver, to obtain an updated list of the PDOs for the child devices.
  
4.PnP manager sends IRP_MN_QUERY_ID to bus driver, to obtain Device ID
+
4.PnP manager sends '''IRP_MN_QUERY_ID''' to bus driver, to obtain Device ID
  
 
5.PnP manager locates INF install section and initialize driver. Memory Manager then calls DriverEntry routine.
 
5.PnP manager locates INF install section and initialize driver. Memory Manager then calls DriverEntry routine.
Line 53: Line 56:
 
6.PnP manager calls AddDevice, to inform driver that a new instance of the device hs been discovered
 
6.PnP manager calls AddDevice, to inform driver that a new instance of the device hs been discovered
  
7.PnP manager sends IRP_MN_QUERY_RESOURCE_REQUIREMENTS to bus driver, to ask bus driver report resource requirements.
+
7.PnP manager sends '''IRP_MN_QUERY_RESOURCE_REQUIREMENTS''' to bus driver, to ask bus driver report resource requirements.
  
 
8.PnP manager configuire the hardware with as set of resource arbitrators to assign resources to the device.
 
8.PnP manager configuire the hardware with as set of resource arbitrators to assign resources to the device.
  
8.PnP manager sends IRP_MN_START_DEVICE to your driver(the driver stack). Function driver handles thei IRP by configuring and connecting various kernel resources.
+
8.PnP manager sends '''IRP_MN_START_DEVICE''' to your driver(the driver stack). Function driver handles thei IRP by configuring and connecting various kernel resources.
  
  
Order of AddDevice Calls (Driver Loading):
+
===Order of AddDevice Calls (Driver Loading):===
  
 
5. Class upper filters
 
5. Class upper filters
Line 71: Line 74:
  
 
1. Device lower filters  
 
1. Device lower filters  
 
+
 
+
IRP Routing:  
+
===IRP Routing: ===
 
System sends an IRP to the topmost filter dirver in the stack, that driver can decide to process the IRP, to pass the IRP down to the next level, or to do both. Each driver that sees the IRP makes the same decision.
 
System sends an IRP to the topmost filter dirver in the stack, that driver can decide to process the IRP, to pass the IRP down to the next level, or to do both. Each driver that sees the IRP makes the same decision.

Revision as of 17:06, 26 March 2014

How the system Finds and Loads Drivers

original: http://blogs.msdn.com/b/xiz/archive/2013/11/04/how-the-system-finds-and-loads-drivers.aspx

1. PnP device

It has an electronic signature that bus driver can detect the new hardware

2. Legacy device

Initiate the detection by invoking Add New Hardware Wizard.


In the end, in both PnP and Legacy Device situation, system uses the same automatic registry and INF file process to load the right driver.


Function driver:

It understands the details about how to make the HW work.

It's responsible for initiating IO operations, for handling interrupts, and for provding a way for end user to exersise control over the device.


Bus driver:

It's responsible for managing the connection between the HW and the computer.


Filter Driver:

to Modify the behavior of an existing function driver in some way. Upper filter driver sees IRPs before function driver. Lower filter can modify the stream of bus operations that the function driver is trying to perform.


PDO stands for physical device object. The bus driver uses it to represent the conncetion between the device and the bus.

FDO stands for function devive object. The function driver uses it to manage the functionality of the device.


Installing a PnP Device:

1.Bus driver detects the insertion or removal of hardware.

2.Bus driver calls IoInvalidateDeviceRelations to notify PnP manager that the bus's population of child devices has changed.

3.PnP manager sends IRP_MN_QUERY_DEVICE_RELATIONS to bus driver, to obtain an updated list of the PDOs for the child devices.

4.PnP manager sends IRP_MN_QUERY_ID to bus driver, to obtain Device ID

5.PnP manager locates INF install section and initialize driver. Memory Manager then calls DriverEntry routine.

6.PnP manager calls AddDevice, to inform driver that a new instance of the device hs been discovered

7.PnP manager sends IRP_MN_QUERY_RESOURCE_REQUIREMENTS to bus driver, to ask bus driver report resource requirements.

8.PnP manager configuire the hardware with as set of resource arbitrators to assign resources to the device.

8.PnP manager sends IRP_MN_START_DEVICE to your driver(the driver stack). Function driver handles thei IRP by configuring and connecting various kernel resources.


Order of AddDevice Calls (Driver Loading):

5. Class upper filters

4. Device upper filters

3. function driver

2. Class lower filters

1. Device lower filters


IRP Routing:

System sends an IRP to the topmost filter dirver in the stack, that driver can decide to process the IRP, to pass the IRP down to the next level, or to do both. Each driver that sees the IRP makes the same decision.