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)
void short_sh_interrupt(int irq, struct pt_regs *regs)
{
    void *dev_id = NULL;
#else
void short_sh_interrupt(int irq, void *dev_id, struct pt_regs *regs)
{
#endif


Probing the IRQ Line

The kernel started exporting the probing functions with version 1.3.30. If you want to port your driver to older kernels, you have to implement do-it-yourself probing. The functions themselves exist in all kernels back to 1.2, but they were not available to modularized drivers.

There aren’t any other problems porting interrupt handlers.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.162.216