现在回到input_attach_handler中
error = handler->connect(handler, dev, id);
现在知道handler->connect是啥了吧,就是mousedev_connect
mousedev_connect在/drivers/input/mousedev.c中
static int mousedev_connect(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id) { struct mousedev *mousedev; int minor; int error; //历遍mousedev_table数组,寻找一个为空的位置 for (minor = 0; minor < MOUSEDEV_MINORS; minor++) if (!mousedev_table[minor]) break; //检测数组是否满了 if (minor == MOUSEDEV_MINORS) { printk(KERN_ERR "mousedev: no more free mousedev devices\n"); return -ENFILE; } //创建一个鼠标设备 mousedev = mousedev_create(dev, handler, minor); if (IS_ERR(mousedev)) return PTR_ERR(mousedev); //添加到mice设备队列中 error = mixdev_add_device(mousedev); if (error) { mousedev_destroy(mousedev); return error; } return 0; }
|
由于mice使用了31,所以这里我们这个鼠标设备的minor 就是32了
现在终于可以进入mousedev_create中的input_register_handle了
input_register_handle在/drivers/input/input.c中
int input_register_handle(struct input_handle *handle) { struct input_handler *handler = handle->handler; struct input_dev *dev = handle->dev; int error; /* * We take dev->mutex here to prevent race with * input_release_device(). */ error = mutex_lock_interruptible(&dev->mutex); if (error) return error; //连接连接器到设备 list_add_tail_rcu(&handle->d_node, &dev->h_list); mutex_unlock(&dev->mutex); synchronize_rcu(); /* * Since we are supposed to be called from ->connect() * which is mutually exclusive with ->disconnect() * we can't be racing with input_unregister_handle() * and so separate lock is not needed here. */ //连接连接器与处理模块 list_add_tail(&handle->h_node, &handler->h_list); //检测处理模块是否有start操作 if (handler->start) handler->start(handle); return 0; }
|
注册好的鼠标设备数据结构