赞
踩
这里开始分析我们第一节贴的图中的class driver。class driver就是负责实现具体功能的driver,像usb-skeleton和usb鼠标的驱动。我认为class driver的功能应该是两个:一个是具体的操作usb device,实现具体的功能;二是像用户态提供dev的文件操作接口。
我们也用usb-skeleton为例进行分析。在这一层,还把usb device抽象成了一个设备 struct usb_skel dev。
- /* Structure to hold all of our device specific stuff */
- struct usb_skel {
- struct usb_device *udev; /* the usb device for this device */
- struct usb_interface *interface; /* the interface for this device */
- struct semaphore limit_sem; /* limiting the number of writes in progress */
- struct usb_anchor submitted; /* in case we need to retract our submissions */
- struct urb *bulk_in_urb; /* the urb to read data with */
- unsigned char *bulk_in_buffer; /* the buffer to receive data */
- size_t bulk_in_size; /* the size of the receive buffer */
- size_t bulk_in_filled; /* number of bytes in the buffer */
- size_t bulk_in_copied; /* already copied to user space */
- __u8 bulk_in_endpointAddr; /* the address of the bulk in endpoint */
- __u8 bulk_out_endpointAddr; /* the address of the bulk out endpoint */
- int errors; /* the last request tanked */
- int open_count; /* count the number of openers */
- bool ongoing_read; /* a read is going on */
- bool processed_urb; /* indicates we haven't processed the urb */
- spinlock_t err_lock; /* lock for errors */
- struct kref kref;
- struct mutex io_mutex; /* synchronize I/O with disconnect */
- struct completion bulk_in_completion; /* to wait for an ongoing read */
- };
我们看到,在class driver这一层,需要用到的gadget的信息就包含在udev、interface、bulk_in_endpointAddr、bulk_out_endpointAddr中,其实主要还是在interface中。
usb-skeleton.c中实现了两个driver。struct usb_driver skel_driver,struct usb_class_driver skel_class。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。