07.06.2013 Views

Scsi - Index of

Scsi - Index of

Scsi - Index of

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

直<br />

接对应的,定义于include/linux/usb_ch9.h.(这里取名为"ch9"是因为这个文件很多东西对应于usb<br />

spec 2.0 中的第九章,chapter 9.):<br />

242 /* USB_DT_INTERFACE: Interface descriptor */<br />

243 struct usb_interface_descriptor {<br />

244 __u8 bLength;<br />

245 __u8 bDescriptorType;<br />

246<br />

247 __u8 bInterfaceNumber;<br />

248 __u8 bAlternateSetting;<br />

249 __u8 bNumEndpoints;<br />

250 __u8 bInterfaceClass;<br />

251 __u8 bInterfaceSubClass;<br />

252 __u8 bInterfaceProtocol;<br />

253 __u8 iInterface;<br />

254 } __attribute__ ((packed));<br />

而其中我们这里提到的是bInterfaceNumber,一个设备可以有多个Interface,于是每一个Interface 当<br />

然就得用个编号了,要不然咋区分啊?所有这些描述符里的冬冬都是出厂的时候就固化在设备里边的,而我<br />

们这里之所以可以用bInterfaceNumber 来赋值,是因为usbcore 在为设备初始化的时候就已经做足了<br />

这<br />

些功课.否则的话,我们真是寸步难行.<br />

总之,us->ifnum 就是这样,最终就是等于咱们眼下这个interface 的编号.<br />

438 到444 行就是两句调试语句,打印更多一些描述符信息,包括device 描述符和interface 描述符.<br />

447 行, usb_set_intfdata(),这其实是一个内联函数,她就一行代码,也是定义于<br />

include/linux/usb.h 中:<br />

138 static inline void usb_set_intfdata (struct usb_interface *intf, void *data)<br />

139 {<br />

140 dev_set_drvdata(&intf->dev, data);<br />

141 }<br />

有趣的是,dev_set_drvdata 这个函数也是内联函数,也只有一行代码,她定义于<br />

include/linux/device.h 中:<br />

302 static inline void<br />

303 dev_set_drvdata (struct device *dev, void *data)<br />

304 {<br />

305 dev->driver_data = data;<br />

306 }<br />

所以,结合来看,最终做的事情就是让&intf->dev->driver_data=data,即<br />

&intf->dev->driver_data=us.<br />

36<br />

再往下走,就是申请内存了,us->cr 和us->iobuf 都是指针,这里让它们指向两段内存空间,下面会用得<br />

到.需要注意的是usb_buffer_alloc(),这个函数是usbcore 提供的,我们只管调用即可.从名字上就能知道<br />

它是用来申请内存的,第一个参数就是struct usb_device 结构体的指针,所以我们要传递一个<br />

pusb_dev,<br />

第三个参数,GFP_KERNEL,是一个内存申请的flag,通常内存申请都用这个flag,除非是中断上下文,不能

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!