16.1 Managing Hardware Priorities

The IRQL at which a particular NT device or intermediate driver routine is run determines which kernel-mode support routines it can call. For example, some support routines require that the caller be running at DISPATCH_LEVEL IRQL. Others cannot be called safely if the caller is running at raised IRQL: that is, at any IRQL higher than PASSIVE_LEVEL.

Figure 16.1 illustrates the default IRQLs at which the most commonly implemented standard NT driver routines are called and the Kernel-defined ordering of low-to-high IRQL values.

Figure 16.1 Default IRQLs for NT Driver Routines

As Figure 16.1 shows, lowest-level NT drivers process IRPs while running at one of three IRQLs:

Most higher-level NT drivers process IRPs while running at either of two IRQLs:

In some circumstances, intermediate and lowest-level drivers of mass-storage devices are called at IRQL APC_LEVEL. In particular, this can occur at a page fault for which an NT file system driver sends an IRP_MJ_READ request to lower drivers.

Most standard driver routines are run at an IRQL that allows them simply to call the appropriate support routines. For example, a device driver must call IoAllocateAdapter or IoAllocateController while running at DISPATCH_LEVEL IRQL. Since most NT device drivers call these routines from a StartIo routine, usually they are running at DISPATCH_LEVEL already.

Note that a device driver that has no StartIo routine because it sets up and manages its own queue(s) of IRPs is not necessarily running at DISPATCH_LEVEL IRQL when it should call IoAllocateAdapter (or IoAllocateController). Such a driver must nest its call to IoAllocateAdapter between calls to KeRaiseIrql and KeLowerIrql so that it runs at the required IRQL when it calls IoAllocateAdapter and restores the original IRQL when the calling routine regains control.

    Consider the following facts in order to call support routines at appropriate IRQLs and to manage hardware priorities successfully in NT drivers:

For routine-specific information about IRQL requirements for calling NT support routines, see the Kernel-Mode Driver Reference. For more information about using spin locks, see Section 16.2.