Linux usb_device usb_bus usb_driver的三角关系-USB Bus

一、USB Device 

1. struct device:

 The Basic Device Structure, generic device interface(所有设备的抽象)
  -struct bus_type *bus;            /* type of bus device is on */
  -struct device_driver *driver;  /* which driver has allocated this device */

 

2. struct usb_device:

kernel's representation of a USB device (它包含struct device,USB设备)

  -struct device dev;  /* generic device interface */

  -struct usb_device_descriptor descriptor; /* USB device descriptor */
  - struct usb_bus *bus;                               /* bus we're part of */
  -struct usb_host_endpoint ep0;                /* endpoint 0 data (default control pipe) */

  -struct usb_host_config *config;          /* all of the device's configs */
  -struct usb_host_config *actconfig;       /* the active configuration */
  -struct usb_host_endpoint *ep_in[16];     /* array of IN endpoints */
  -struct usb_host_endpoint *ep_out[16];    /* array of OUT endpoints */

 

3. struct usb_host_config

representation of a device's configuration

/* array of pointers to usb_interface structures, one for each  interface in the configuration. These pointers are valid only while the the configuration is active.*/

 -struct usb_interface *interface[USB_MAXINTERFACES];    

 

/* array of pointers to usb_interface_cache structures, one  for each interface in the configuration.  These structures exist  for the entirelife of the device. Interface information availableeven when this isnot activeconfiguration */

 -struct usb_interface_cache *intf_cache[USB_MAXINTERFACES];

 

4. struct usb_interface

what usb device drivers talk to

 /* array of alternate settings for this interface, stored in no particular order. one for each alternate setting that may be selected.  Each one includes a set of endpoint configurations. */
 -struct usb_host_interface *altsetting;
 -struct usb_host_interface *cur_altsetting; /* the currently

 

5. struct usb_host_interface
host-side wrapper for one interface setting's parsed descriptors
-struct usb_interface_descriptor desc;
/* array of desc.bNumEndpoint endpoints associated with this interface setting.  these will be in no particular order.*/
-struct usb_host_endpoint *endpoint;

 

6. struct usb_host_endpoint

 host-side endpoint descriptor and queue

 /* descriptor for this endpoint, e.g.: wMaxPacketSize */

 -struct usb_endpoint_descriptor desc;   

 /*urbs queued to this endpoint; maintained by usbcore*/
 -struct list_head  urb_list;     

  /* for use by HCD; typically holds hardware dma queue head (QH) */
 -void    *hcpriv;        

 /* ep_device for sysfs info*/

 -struct ep_device   *ep_dev;   

 

7. usb_alloc_dev

usb device constructor (usbcore-internal)
struct usb_device *usb_alloc_dev(struct usb_device *parent, struct usb_bus *bus, unsigned port1)

   @parent: hub to which device is connected; null to allocate a root hub
  @bus: bus used to access the device
  @port1: one-based index of port; ignored for root hubs

二、USB Bus

每一条USB总线对应一个struct usb_bus结构体变量.

 struct bus_type usb_bus_type = {
 .name =  "usb",
 .match = usb_device_match,
 .uevent = usb_uevent,
 .pm =  &usb_bus_pm_ops,
};

struct bus_type表示总线的类型,而usb_bus_type定义了一种usb总线类型,通过bus_register(&usb_bus_type)让系统知道有usb这么一个类型的总线。


而一个总线类型和一条总线是两码子事儿。从硬件上来讲,一个host controller就会连出一条usb总线,而从软件上来讲,不管你有多少个host controller,或者说有多少条总线,它们通通属于usb_bus_type这么一个类型,只是每一条总线对应一个struct usb_bus结构体变量,这个变量在host controller的驱动程序中去申请。

 

HCD is bus. struct usb_hcd包含一个struct usb_bus.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值