应用和驱动是如何交互
在app中,fd = open("/dev/event1");
于是调用驱动层的open。
1.因为cdev是在drivers/input/input.c创建所以进入drivers/input/input.c
static int input_open_file(struct inode *inode, struct file *file)
|
//取出evdev_handler,将evdev_handler的fops赋值给cdev的fops
handler = input_table[iminor(inode) >> 5];
new_fops = fops_get(handler->fops);
old_fops = file->f_op;
file->f_op = new_fops;
//跳转到取出evdev_handler的fops的open函数
new_fops->open(inode, file);
-------evdev.c的open
static int evdev_open(struct inode *inode, struct file *file)
|
//取出evdev
evdev = evdev_table[i];
//分配evdev_client对象,并且为缓冲队列分配空间
bufsize = evdev_compute_buffer_size(evdev->handle.dev);
client = kzalloc(sizeof(struct evdev_client) +
bufsize * sizeof(struct input_event),
GFP_KERNEL);
client->bufsize = bufsize;
client->evdev = evdev;
//将evdev_client关联到evdev中去
evdev_attach_client(evdev, client);
|
list_add_tail_rcu(&client->node, &evdev->client_list);
file->private_data = client;
read是如何交互的
read函数
//阻塞
retval = wait_event_interruptible(evdev->wait,client->packet_head != client->tail || !evdev->exist);
|
//如果阻塞被唤醒,会从evdev_client中获取数据event
while (retval + input_event_size() <= count &&
evdev_fetch_next_event(client, &event)) {
|
*event = client->buffer[client->tail++];
//拷贝给用户
if (input_event_to_user(buffer + retval, &event))
怎么唤醒read中的wait
input_sync()
|
input_handle_event(struct input_dev *dev,unsigned int type, unsigned int code, int value)
|
switch (type) {
case EV_SYN:
switch (code) {
case SYN_REPORT:
if (!dev->sync) {
dev->sync = true;
disposition = INPUT_PASS_TO_HANDLERS;
}
break;
|
input_pass_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
|
//通过input dev找到input handle
list_for_each_entry_rcu(handle, &dev->h_list, d_node)
//通过input handle找到input handler
handler = handle->handler;
//调用了 input handler中的event(), 调转到evdevc.
handler->event(handle, type, code, value);
跳转到handler->event
if (type == EV_SYN && code == SYN_REPORT)
wake_up_interruptible(&evdev->wait);