Version Dependencies of IRQ Handling

Not all of the code introduced in this chapter is backward portable to Linux 1.2. I outline here the main differences and suggest how to deal with them. short actually compiles and runs equally well with 2.0.x and 1.2.13 kernels.

Different Prototypes for request_irq

The way of passing arguments to request_irq that I’ve used throughout this chapter was introduced only with version 1.3.70 of the kernel, when shared handlers appeared.

Previous kernel versions didn’t require a dev_id argument, and the prototype was slightly simpler:

int request_irq(unsigned int irq,
                void (*handler)(int, struct pt_regs *),
                unsigned long flags, const char *device);

The new semantics can easily be forced onto the old prototype by using the following macro definitions (note that free_irq also had no dev_id argument in early versions):

#if LINUX_VERSION_CODE < VERSION_CODE(1,3,70)
   /* the preprocessor is able to handle recursive definitions */
#  define request_irq(irq,fun,fla,nam,dev) request_irq(irq,fun,fla,nam)
#  define free_irq(irq,dev)                free_irq(irq)
#endif

The macros just discard the extra dev argument.

The difference in the handler prototypes is best taken care of with an explicit #if/#else/#endif statement. If you use the dev_id pointer, the conditional case for old kernels could declare a NULL variable, and the body of the handler should be able to deal with a NULL device pointer.

One of the short examples exemplifies the idea:

#if LINUX_VERSION_CODE < VERSION_CODE(1,3,70) ...

Get Linux Device Drivers now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.