Input device driver

Bruno E. O. Meneguele bmeneguele at gmail.com
Fri Sep 29 18:38:49 EDT 2017


Hi folks, 

I'm trying to write an input device driver basicaly to play with
interrupt handlers. The idea at first was to catch all keys pressed on
my keyboard, nothing else, but some doubts rised after I wrote the
driver and it didn't work out.

The code so far is as follows:
https://gist.github.com/bmeneguele/621d4bbbfa28fca200df6ba289cfb3fc

Now the questions:
1) from /proc/interrupts I saw the i8042 keyboard+mouse controller on
IRQ line 1 and 12:

CPU0   CPU1     CPU2     CPU3                                      
0:       55        0        0       0 IR-IO-APIC   2-edge      timer     
1:      101        5        7       2 IR-IO-APIC   1-edge      i8042     
8:        0        0        0       1 IR-IO-APIC   8-edge      rtc0      
9:     7216     3565    16517    3485 IR-IO-APIC   9-fasteoi   acpi      
12:     212       29      323      51 IR-IO-APIC   12-edge     i8042     
16:       0        0        0       0 IR-IO-APIC   16-fasteoi  i801_smbus
19:      15        0        6       3 IR-IO-APIC   19-fasteoi             
[...]

then I thought I could share the line along with it, once in
drivers/input/serio/i8042.c the request_irq() is being called with
IRQF_SHARED. Is there a problem here?

2) I'm using a USB keyboard as the testing device, and TBH I got
confused if I could actually use the input subsystem for that or I
_should_ use HID instead (considering the keyboard is HID compliant).

3) the output I'm receiving is just one message regardless the number of
keys I press:

[... (make && insmod) ...]
$ dmesg | tail
[75013.625311] input: Bmeneg's Keyboard as /devices/virtual/input/input25
[75056.682676] [my_kbd] kbd_irq_handler:22:: irq 12 occured!             
[... (rmmod && make && insmod) ...]
[75132.203324] input: Bmeneg's Keyboard as /devices/virtual/input/input26
[75149.669112] [my_kbd] kbd_irq_handler:22:: irq 1 occured!              
[... (rmmod && make && insmod) ...]
[75164.213562] input: Bmeneg's Keyboard as /devices/virtual/input/input27
[75168.720791] [my_kbd] kbd_irq_handler:22:: irq 1 occured!              
[... (rmmod && make && insmod) ...]
[75390.584746] input: Bmeneg's Keyboard as /devices/virtual/input/input28
[75397.149047] [my_kbd] kbd_exit:73:: irq reference counter: 1           
[... (rmmod && make && insmod) ...]
[79146.583034] input: Bmeneg's Keyboard as /devices/virtual/input/input29
[79159.647871] [my_kbd] kbd_exit:73:: irq reference counter: 1           

as you can see I tried with prints inside IRQ handler, that I changed to
a ref counter considering a previous knowledge from embedded systems
that prints inside IRQs are bad :D (is it still true for linux kernel?),
and the output from prints (inside IRQs) just appears after I `rmmod`
the driver. 

Of course something is wrong in my code, but what? (handle kbd as input
device? IRQ shared with i8042? wrong way to handle IRQ?)

Well, this is my first time trying to accomplish something using real
hardware in kernel space, not using just tutorial copy/paste or
software-only things like timers. Because of that any info would be
really great. What I'm trying to get here is just dive into
bottom-helves execution (work queues) to understand how they actually
works and of course more advanced things later!

Thanks in advance!

Note: using kernel 4.12.12 here.

-- 
bmeneg 
PGP Key: http://bmeneg.com/pubkey.txt
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20170929/6e264833/attachment.bin 


More information about the Kernelnewbies mailing list