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.
-
See https://elixir.bootlin.com/linux/latest/source/drivers/input/input.c#L131 there appears to be a list of handlers associated with an input device, and `list_for_each_entry_rcu()` calls each of them in turn. Look into how `dev->h_list` is appended to. – jamieguinan Feb 18 '19 at 20:23
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.

- 106
- 2