how new hardware device's IRQL is defined

In wdm.h, some IRQL are defined, and i use them in function KeRaiseIrql , this is not a problem. The Problem is that when i have a new device installed on PCIe, and there must be interrupt from this hardware device. is it the device driver to define new IRQL? or OS will define it after bootup?

#define PASSIVE_LEVEL 0 // Passive release level
#define LOW_LEVEL 0 // Lowest interrupt level
#define APC_LEVEL 1 // APC interrupt level
#define DISPATCH_LEVEL 2 // Dispatcher level
#define CMCI_LEVEL 5 // CMCI handler level

#define CLOCK_LEVEL 13 // Interval clock level
#define IPI_LEVEL 14 // Interprocessor interrupt level
#define DRS_LEVEL 14 // Deferred Recovery Service level
#define POWER_LEVEL 14 // Power failure level
#define PROFILE_LEVEL 15 // timer used for profiling.
#define HIGH_LEVEL 15 // Highest interrupt level

Windows assigns the device an IRQL “automatically” when it wires-up the device to the IDT… which happens when your driver connects to interrupts from the device.

There’s nothing you need to do to make this happen, other than write your driver the usual way.

Peter

Thx @“Peter_Viscarola_(OSR)”
How can i know what the IRQL value is?
i want to do some KeRaiseIrql to the level to block the interrupt from this particular device.

You don’t. When you want to raise to your device IRQL you use KeAcquireInterruptSpinLock … or WdfInterruptAcquireLock.

These not only raise the IRQL but also acquire the spin lock that’s used to serialize execution of your ISR.

Peter

i want to do some KeRaiseIrql to the level to block the interrupt from this particular device.

Are you actually trying to synchronize things here? Remember that raising the IRQL only affects the one CPU on which you are running. Interrupts can still be fired on another CPU. That’s why we use a spin lock.

If you really want to stop the device from interrupting, you have to find and disable the “interrupt enable” bit in the device’s registers.

thx @Tim_Roberts and @“Peter_Viscarola_(OSR)” so spin lock will lock the bus ? i recall that the book windows internal says something about a type of lock that can lock the bus. am i right about spin lock?

You say “the bus” as if there was only one. No, the spin lock is a CPU thing. When a process grabs a spin lock, any other process that tries to grab it will block.

In SMP , When a process running on processor A grabs a spin lock, any other process running on processor B that tries to grab it will block too ?

Yes, that’s the point.

Not just SMP, but any MP environment - but that is beyond the scope of Windows - except that NUMA technically breaks the symmetric part to some extent

In SMP , When a process running on processor A grabs a spin lock, any other process running on processor B that tries to grab
it will block too ?

Well, it is not going to “block” in a sense that the term “blocking” is normally used in OS-level lingo. What it is going to do is to spin in an idle do-nothing loop until the lock gets released. No context switches are going to take place on a given CPU meanwhile, because it is going to spin at elevated IRQL. Therefore, spinlocks have to be used judiciously, which is particularly true for the large systems with the large number of logical processors…

Anton Bassov

so spin lock will lock the bus ? i recall that the book windows internal says something about a type of lock that can lock the bus.
am i right about spin lock?

The very first thing that comes up to my mind when I see the lines like that is our discussion of this topic with Alberto - he believed that one might lock a bus with some “bus-level lock” that might span across multiple instructions …

Anton Bassov

thx @anton_bassov