How does the System Find and Load Drivers?

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.