## Physical Device Driver Reference

[prev][next][parent][TOC]

### Limiting the Number of Nested Interrupts

Physical device driver interrupt handlers must be written to prevent uncontrolled stack growth of the interrupt stack. The interrupt handler must consume as little stack space as possible and limit the depth of nested interrupts.

The system's interrupt fixed-sized stack is configurable; that is, device drivers can indicate their interrupt stack usage by calling the RegisterStackUsage device helper routine during initialization. This allows the physical device drivers that require large stack space to be installed without decreasing available low memory for all device drivers. When calling RegisterStackUsage, a physical device driver provides data describing the interrupt handler for a specified hardware interrupt level ( IRQ). Therefore, RegisterStackUsage is called by a physical device driver for each IRQ that it services. In addition to the interrupt stack size, this data includes the maximum number of interrupt levels that the physical device driver expects to nest. The OS/2 operating system uses this data to detect when unbounded nesting occurs and prevents nested interrupts from causing a system halt.

Physical device drivers that do processing after sending an End-Of- Interrupt (EOI) to the interrupt controller (8259) and enabling interrupts (STI) can receive nested interrupts. To prevent using excessive interrupt stack space, the physical device driver should keep internal flags to limit the amount of interrupt nesting. The amount of interrupt nesting is limited by performing all post-EOI processing at the first-level interrupt. Nested interrupts must avoid and, if possible, eliminate post-EOI processing. In all cases, the physical device driver must bound the number of levels of nesting to as few as possible (preferably two) and must never permit the levels of nesting to be unbounded. Limiting the amount of interrupt nesting to two levels can be implemented as follows:

When a nested interrupt is encountered, a flag (or count) is set so that the post-EOI processing can be done again by the first level interrupt, if necessary.

On a first level interrupt, interrupts are enabled before doing the EOI and remain enabled during the post-EOI processing. Interrupts must be disabled and remain disabled before the interrupt handler clears the interrupt-in-progress flag and returns to the Interrupt Manager.

On a nested interrupt, interrupts must be disabled and remain disabled before the interrupt handler calls the DevHlp_EOI and returns to the Interrupt Manager.

Note: If a physical device driver needs to support more than one level of nested interrupts, it still must limit the number of nested interrupts that it handles. A physical device driver must avoid this if at all possible.

As device drivers allow more levels of nesting for their interrupt handlers , the potential exists for the entire interrupt stack to be consumed. This applies to all device drivers, regardless of the interrupt rate of the device being supported. It might seem that a device driver for a slow device need not follow this convention. However, if the system contains another device that has a high interrupt rate or many devices with more moderate interrupt rates, the time between occurrence of the hardware interrupt and dispatch to the interrupt handler can become greater than the interrupt rate of the slow device, and excessive nesting can occur.