输入子系统源代码跟读2

应用和驱动是如何交互

在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);
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值