I'm writing a simple key logger as a means to understanding interrupts and IO ports for linux drivers. Now from what I've read, I need to register interrupt handlers via ...
int request_irq(unsigned int irq, irqreturn_t (*handler)(int, void *, struct pt_regs *), unsigned long flags, const char *dev_name, void *dev_id);
However from what I also read, if I call request_irq during module_init() I will hog the interrupt. My problem is that I want to share the interrupt with other resources but I'm not sure how I can call this interrupt. I wish I could just call the function with module_init() and set my flag to SA_SHIRQ. I am told the best practice is to call during open file which allow for me to set the interrupt, but I don't want to rely on writing a user space program calling open "my_dev" just so that I can run the interrupt handler.
Thanks
Don't worry. request_irq
doesn't "hog" the interrupt. It puts the handler on a list of callbacks and calls all handlers (for that IRQ) whenever that interrupt is signaled.
If what you do during the interrupt is heavy lifting, you might want to enable processing IRQs only when the driver is open to minimize system disruption when the driver is not in use. To do that, implement the driver open and close calls, and keep a reference count: only when the ref count > 0 should the ISR be registered
SA_SHIRQ
anywhere in the entire source tree. The drivers use IRQF_SHARED
instead. See if that works for you - wallyk 2012-04-04 06:27
grep "#define E.*22" /usr/include/*/err*
wallyk 2012-04-04 06:40
Get it working first, and worry about best practice later. Requesting the IRQ in module_init
isn't a big deal - so long as all the resources the interrupt handler needs are available for it to be called immediately...