All of lore.kernel.org
 help / color / mirror / Atom feed
From: bmeneguele@gmail.com (Bruno E. O. Meneguele)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Input device driver
Date: Fri, 29 Sep 2017 19:38:49 -0300	[thread overview]
Message-ID: <20170929223849.GA18392@glitch> (raw)

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 

             reply	other threads:[~2017-09-29 22:38 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-09-29 22:38 Bruno E. O. Meneguele [this message]
2017-09-29 23:09 ` Input device driver valdis.kletnieks at vt.edu
2017-09-30  0:19   ` Bruno E. O. Meneguele
2017-09-30  7:42     ` Greg KH
2017-09-30 12:05       ` Bruno E. O. Meneguele

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170929223849.GA18392@glitch \
    --to=bmeneguele@gmail.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.