Best way to install interrupt handler for port 0x60

Go To


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.


2012-04-04 04:54
by Dr.Knowitall
Wouldn't you basically have to hog the IRQ (read: take over for the keyboard driver) anyway? If you didn't, the next key event read in wouldn't be there when the keyboard driver went to grab it, would it - cHao 2012-04-04 05:02


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

2012-04-04 05:01
by wallyk
I'll try it out, if I can still use my keyboard to type you a "thank you" then it worked, Lol - Dr.Knowitall 2012-04-04 05:06
When I try to use this function I'm getting EBUSY error, probably since the keyboard driver has already registered the keyboard. I'm not sure what to do - Dr.Knowitall 2012-04-04 05:56
Did you set the <code>SA_SHIRQ</code> flag with the call - wallyk 2012-04-04 06:05
I've tried running it with flag as 0. For whatever reason my compiler says SA_SHIRQ is undeclared, though I was hoping it would have been defined in Dr.Knowitall 2012-04-04 06:18
@user1103966: Interesting. Perhaps the documentation is old. The Linux kernel I am developing on does not have 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
Ya I looked up the header file and tried that, it worked but now I'm getting error -22 which I'm trying to figure out Lol. I wish man errno told the values for the error names - Dr.Knowitall 2012-04-04 06:31
To look up application errno, use grep "#define E.*22" /usr/include/*/err*wallyk 2012-04-04 06:40
Ha, thanks so much !!! I'm one step closer to a key logger, my handler and everything is working! Your the best - Dr.Knowitall 2012-04-04 06:47


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...

2012-04-04 05:04
by blueshift