Question

I'm trying to write a simple module, which should replace irq 1 handler. And all the time I get following error:'-1 Device or resourse busy'. Is it any way to fix it? Here's my code:

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>
#include <linux/workqueue.h>
#include <linux/interrupt.h>
#include <asm/io.h>


irqreturn_t myhandler(int irq, void *dev_id, struct pt_regs *regs) 
{
  printk(KERN_ALERT"\n\nMy interrupt handler\n\n");
  return IRQ_HANDLED;
}

int init_module()
{
  int res;
  free_irq(1, NULL);                  
  res = request_irq(1, (void*)myhandler,0, "my_handler", (void*)(myhandler)); 
  return res;
}

void cleanup_module()
{
  free_irq(1, NULL);
}
MODULE_LICENSE("GPL");

Maybe anybody can say what's wrong. PS. I'm working with 2.6.39.3 kernel.

Was it helpful?

Solution

What type of system (architecture) are you on?

On a normal PC, IRQ 1 is the 8042 (keyboard controller) and already has an interrupt handler. You are passing 0 into request_irq() for flags, so you're asking to register a handler for a non-shared interrupt. The core kernel interrupt code will look and see that there is already another handler registered for that IRQ, and return -EBUSY from request_irq.

You can't override the existing handler by registering another handler for the same IRQ. You need to unregister the first one before you can register a new one.

You can look at /proc/interrupts to see what is already using IRQ 1 on your system.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top