Introduction to Linux Inpu subsystems

Source: Internet
Author: User
Tags mutex

1. Preface

This paper mainly introduces the input subsystem under Linux.

2. Software Architecture

Figure input Subsystem structure diagram

The input subsystem consists of three parts: the device drive layer, the core layer and the event layer. We can be understood separately as: specific input devices, over-devices, and logical devices. The only logical device that interacts directly with the user space is the event layer.

The input subsystem consists of two main paths (mainly the first path):

    • First path

The device-driven layer captures the event and reports the core layer to the core layer data that is processed by the user space Read event layer, which is referred to event layer processing

    • Second path

User space write event data, event layer generation events, call the core layer to pass event information to drive layer, device drive layer Drive hardware Device

3. Association between system components

Figure Input_dev The association between Input_handle Input_handler

Usually the relationship between Input_dev, Input_handle and Input_handler is as shown.

    • Input_dev

Input_dev is linked into the global list Input_dev_list via node, and all input_handle associated with it are linked by h_list, which means that each input_dev may have more than one handle connected to it

    • Input_handler

Input_handler is linked into the global list Input_handler_list through node nodes, and all input_handle associated with it are linked by h_list, indicating that each input_ Handler may have multiple handle connected to it

4. System Components 4.1 Input_handle

elemete Name input_handle
Path include/linux/input.h
responsiblities

For connecting Input_dev and Input_ Handler, created by Input_handler

attributions
  • private:voi The d * Type, which holds the unique data of input handle
  • Open:open is used to count, indicates whether the handle was opened
  • name:const char * type, handler name, by handler When creating handle, specify the
  • dev:struct input_dev * type, Input_dev
  • handler:struct input_handler * Type associated with this handle, ha Ndler by handle with the above Input_dev work
  • d_node:struct list_head type, you can link this node to the Input_dev list of h_list, which shows a input_ Dev can link
  • h_node:struct list_head types with multiple handle, which can link this node to the H_list linked list of Input_handler, indicating a input_ Handler can link to multiple handle
Operations

 

 

 

4.2 Input_dev

Elemete Name Input_dev
Path Include/linux/input.h
Responsiblities

Represents an input device, such as a key device, touch screen device, etc.

Attributions

Name:const char * Type, the name of the input device

Phys:const char * Type, file node name under/sys/directory, such as/sys/class/input/event0

Uniq:const char * Type, device Unique identification code, requires device support

struct INPUT_ID ID;

ID of the device, including manufacturer, product good, version number

unsigned long propbit[bits_to_longs (input_prop_cnt)];

unsigned long evbit[bits_to_longs (ev_cnt)];

Which events are supported by the device

unsigned long keybit[bits_to_longs (key_cnt)];

Which keys and buttons are supported by this device

unsigned long relbit[bits_to_longs (rel_cnt)];

Relative coordinates of the device, for mouse devices?

unsigned long absbit[bits_to_longs (abs_cnt)];

For touch screen devices?

unsigned long mscbit[bits_to_longs (msc_cnt)];

Miscellaneous events supported by the device

unsigned long ledbit[bits_to_longs (led_cnt)];

LED on the device

unsigned long sndbit[bits_to_longs (snd_cnt)];

Device sound support related, such as buzzer etc.

unsigned long ffbit[bits_to_longs (ff_cnt)];

Strong feedback events, such as motors, supported by the device

unsigned long swbit[bits_to_longs (sw_cnt)];

Whether the device supports switches, such as the mute switch on the iphone

unsigned int hint_events_per_packet;

The number of events implied by the device packaging event, typically occurring between Ev_syn and Syn_report, Input_handler need to estimate the buffer size to hold the event

unsigned int keycodemax;

Key Code table size, used to hold the key code, the actual number of keys may be less than this

unsigned int keycodesize;

Number of key codes actually stored in the key table

void *keycode;

Scan code to key code mapping, the ADC key scanning code can be understood as a key ADC value, key code volume Plus, volume reduction, etc.

Int (*setkeycode) (struct Input_dev *dev,

const struct Input_keymap_entry *ke,

unsigned int *old_keycode);

Int (*getkeycode) (struct Input_dev *dev,

struct input_keymap_entry *ke);

struct Ff_device *ff;

unsigned int repeat_key;

Repeat_key saved the last pressed button for automatic software re-send

struct Timer_list timer;

The software re-issued timer, including the button press for how long to start the automatic re-send function, every how often to re-send

int rep[rep_cnt];

Save parameter values for automatic re-send

struct INPUT_MT *mt;

struct Input_absinfo *absinfo;

unsigned long key[bits_to_longs (key_cnt)];

React to the current state of the Key/button device, such as press or lift

unsigned long led[bits_to_longs (led_cnt)];

unsigned long snd[bits_to_longs (snd_cnt)];

unsigned long sw[bits_to_longs (sw_cnt)];

Int (*open) (struct Input_dev *dev);

This method is called by the first user when calling Input_open_device, the driver needs to open the poll thread at this time, and can escalate the event, other users will only add the user Count 1

void (*close) (struct Input_dev *dev);

This function is called when the last user calls Input_close_device, and the drive needs to be implemented to do a aftercare work

Int (*flush) (struct Input_dev *dev, struct file *file);

Int (*event) (struct Input_dev *dev, unsigned int type, unsigned int code, int value);

Mainly used for Input_handler receiving user layer operation events, Input_dev operation, such as the operation of the LED and FF devices

struct Input_handle __rcu *grab;

Once grab is not empty, this input_handle will be the only event handler for this Input_dev

spinlock_t Event_lock;

Event for input core to receive or process this Input_dev

struct mutex mutex;

Used to ensure serial execution of the open, close, flush methods

unsigned int users;

Input_handler number of Input_open_device executed

BOOL Going_away;

Flag Input_dev execution Input_open_device will fail during unregister execution

struct device dev;

Device-driven model devices

struct List_head h_list;

All input_handle that are used to link this Input_dev

struct List_head node;

Used to add this input_dev to the global input_dev_list

unsigned int num_vals;

How many frames in the current queue are queued and each frame can be interpreted as an event between Ev_syn and Syn_report

unsigned int max_vals;

The maximum number of events that can be contained in a frame???

struct Input_value *vals;

An array of queues to the current queue????

BOOL devres_managed;

Indicates whether the device resource is managed by the device resource framework

Operations

Introduction to Linux Inpu subsystems

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.