Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How does the Linux Kernel know which file descriptor to write input events to?

I would like to know the mechanism in which the Linux Kernel knows which file descriptor (e.g. /dev/input/eventX) to write the input to. For example, I know that when the user clicks the mouse, an interrupt occurs, which gets handled by the driver and propagated to the Linux input core via input_event (drivers/input/input.c), which eventually gets written to the appropriate file in /dev/input/. Specifically, I want to know which source files I need to go through to see how the kernel knows which file to write to based on the information given about the input event. My goal is to see if I can determine the file descriptors corresponding to specific input event codes before the kernel writes them to the /dev/input/eventX character files.

like image 720
Dustin Colten McAfee Avatar asked Nov 07 '22 21:11

Dustin Colten McAfee


1 Answers

You may go through two files: drivers/input/input.c drivers/input/evdev.c In evdev.c, evdev_init() will call input_register_handler() to initialize input_handler_list.

Then in an input device driver, after initialize input_dev, it will call: input_register_device(input_dev) -> get device kobj path, like /devices/soc/78ba000.i2c/i2c-6/6-0038/input/input2 -> input_attach_handler() -> handler->connect(handler, dev, id); -> evdev_connect()

In evdev_connect(), it will do below: 1. dynamic allocate a minor for a new evdev. 2. dev_set_name(&evdev->dev, "event%d", dev_no); 3. call input_register_handle() to connect input_dev and evdev->handle. 4. create a cdev, and call device_add().

After this, you will find input node /dev/input/eventX, X is value of dev_no.

like image 92
linzhiyuanlzy Avatar answered Nov 14 '22 05:11

linzhiyuanlzy