usb子系统相关结构体

1. usb总线

[cpp]  view plain copy
  1. struct usb_bus {  
  2.     struct device *controller;    
  3.     int busnum; //总线号  
  4.     const char *bus_name;   //总线名  
  5.     u8 uses_dma;  
  6.     u8 uses_pio_for_control;  
  7.     u8 otg_port;  
  8.     unsigned is_b_host:1;  
  9.     unsigned b_hnp_enable:1;  
  10.     unsigned sg_tablesize;  
  11.     int devnum_next;    //下一个地址  
  12.     struct usb_devmap devmap;   //usb设备地址表  
  13.     struct usb_device *root_hub;    //根hub  
  14.     struct usb_bus *hs_companion;  
  15.     struct list_head bus_list;  //总线链表  
  16.     int bandwidth_allocated;  
  17.     int bandwidth_int_reqs;  
  18.     int bandwidth_isoc_reqs;  
  19. #ifdef CONFIG_USB_DEVICEFS  
  20.     struct dentry *usbfs_dentry;  
  21. #endif  
  22. #if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)  
  23.     struct mon_bus *mon_bus;  
  24.     int monitored;  
  25. #endif  
  26. };  

2. usb hub

[cpp]  view plain copy
  1. struct usb_hub {  
  2.     struct device   *intfdev;  
  3.     struct usb_device   *hdev;  //usb设备  
  4.     struct kref kref;  
  5.     struct urb  *urb;     
  6.     char    (*buffer)[8];  
  7.     union {  
  8.         struct usb_hub_status   hub;  
  9.         struct usb_port_status  port;  
  10.     }*status;  
  11.     struct mutex    status_mutex;  
  12.     int error;  //出错标志  
  13.     int nerrors;  
  14.     struct list_head    event_list; //事件链表  
  15.     unsigned long   event_bits[1];  
  16.     unsigned long   change_bits[1];  
  17.     unsigned long   busy_bits[1];  
  18.     unsigned long   removed_bits[1];  
  19. #if USB_MAXCHILDREN > 31  
  20. #error event_bits[] is too short!  
  21. #endif  
  22.     struct usb_hub_descriptor *descriptor;  //hub描述符  
  23.     struct usb_tt   tt;  
  24.     unsigned    mA_per_port;    //每个端口电流量  
  25.     unsigned    limited_power:1;  
  26.     unsigned    quiescing:1;  
  27.     unsigned    disconnected:1;  
  28.     unsigned    has_indicators:1;  
  29.     u8  indicator[USB_MAXCHILDREN];  
  30.     struct delayed_work leds;  
  31.     struct delayed_work init_work;  
  32.     void    **port_owners;  
  33. };  

3. usb主控器驱动

[cpp]  view plain copy
  1. struct hc_driver {  
  2.     const char *description;    //主控器类型  
  3.     const char *product_desc;   //厂商字串  
  4.     size_t hcd_priv_size;   //私有数据大小  
  5.     irqreturn_t (*irq) (struct usb_hcd *hcd);  
  6.     int flags;  //版本标志  
  7.     int (*reset) (struct usb_hcd *hcd); //重置  
  8.     int (*start) (struct usb_hcd *hcd); //启动  
  9.     int (*pci_suspend)(struct usb_hcd *hcd, bool do_wakeup);  
  10.     int (*pci_resume)(struct usb_hcd *hcd, bool hibernated);  
  11.     void (*stop) (struct usb_hcd *hcd); //停止  
  12.     void (*shutdown) (struct usb_hcd *hcd); //关闭  
  13.     int (*get_frame_number) (struct usb_hcd *hcd);  
  14.     int (*urb_enqueue)(struct usb_hcd *hcd,struct urb *urb, gfp_t mem_flags);  
  15.     int (*urb_dequeue)(struct usb_hcd *hcd,struct urb *urb, int status);  
  16.     void (*endpoint_disable)(struct usb_hcd *hcd,struct usb_host_endpoint *ep);  
  17.     void (*endpoint_reset)(struct usb_hcd *hcd,struct usb_host_endpoint *ep);  
  18.     int (*hub_status_data) (struct usb_hcd *hcd, char *buf);  
  19.     int (*hub_control) (struct usb_hcd *hcd,u16 typeReq, u16 wValue, u16 wIndex,char *buf, u16 wLength);  
  20.     int (*bus_suspend)(struct usb_hcd *);   //总线挂起  
  21.     int (*bus_resume)(struct usb_hcd *);  
  22.     int (*start_port_reset)(struct usb_hcd *, unsigned port_num);  
  23.     void (*relinquish_port)(struct usb_hcd *, int);  
  24.     int (*port_handed_over)(struct usb_hcd *, int);  
  25.     void (*clear_tt_buffer_complete)(struct usb_hcd *,struct usb_host_endpoint *);  
  26.     void (*recover_hcd)(struct work_struct *data);  
  27.     int (*alloc_dev)(struct usb_hcd *, struct usb_device *);  
  28.     void (*free_dev)(struct usb_hcd *, struct usb_device *);  
  29.     int (*alloc_streams)(struct usb_hcd *hcd, struct usb_device *udev,struct usb_host_endpoint **eps,   
  30.                         unsigned int num_eps,unsigned int num_streams, gfp_t mem_flags);  
  31.     int (*free_streams)(struct usb_hcd *hcd, struct usb_device *udev,struct usb_host_endpoint **eps,   
  32.                         unsigned int num_eps,gfp_t mem_flags);  
  33.     int (*add_endpoint)(struct usb_hcd *, struct usb_device *,struct usb_host_endpoint *);  
  34.     int (*drop_endpoint)(struct usb_hcd *, struct usb_device *,struct usb_host_endpoint *);  
  35.     int (*check_bandwidth)(struct usb_hcd *, struct usb_device *);  
  36.     void (*reset_bandwidth)(struct usb_hcd *, struct usb_device *);  
  37.     int (*address_device)(struct usb_hcd *, struct usb_device *udev);  
  38.     int (*update_hub_device)(struct usb_hcd *, struct usb_device *hdev,struct usb_tt *tt, gfp_t mem_flags);  
  39.     int (*reset_device)(struct usb_hcd *, struct usb_device *);  
  40.     int (*update_device)(struct usb_hcd *, struct usb_device *);  
  41. };  

4. usb主控器设备

[cpp]  view plain copy
  1. struct usb_hcd {  
  2.     struct usb_bus self;  
  3.     struct kref kref;  
  4.     const char *product_desc;   //厂商字串  
  5.     char irq_descr[24];  
  6.     struct timer_list rh_timer; //轮询定时器  
  7.     struct urb *status_urb; //urb状态  
  8. #ifdef CONFIG_USB_SUSPEND  
  9.     struct work_struct  wakeup_work;  
  10. #endif  
  11.     struct work_struct ehci_omap_work;  
  12.     const struct hc_driver *driver;  
  13.     unsigned long flags;  
  14.     unsigned rh_registered:1;  
  15.     unsigned rh_pollable:1;  
  16.     unsigned uses_new_polling:1;  
  17.     unsigned wireless:1;  
  18.     unsigned authorized_default:1;  
  19.     unsigned has_tt:1;  
  20.     int irq;    //中断号  
  21.     void __iomem *regs; //设备内存  
  22.     u64 rsrc_start; //设备内存资源起始地址  
  23.     u64 rsrc_len;   //设备内存资源长度  
  24.     unsigned power_budget;  
  25.     struct mutex bandwidth_mutex;  
  26.     struct dma_pool *pool[HCD_BUFFER_POOLS];  
  27.     int state;  
  28.     unsigned long hcd_priv[0] __attribute__ ((aligned(sizeof(unsigned long))));  
  29. };  

5. usb设备驱动

[cpp]  view plain copy
  1. struct usb_driver {  
  2.     const char *name;   //usb驱动名  
  3.     int (*probe) (struct usb_interface *intf,const struct usb_device_id *id);   //插入  
  4.     void (*disconnect) (struct usb_interface *intf);    //拔出  
  5.     int (*unlocked_ioctl) (struct usb_interface *intf, unsigned int code,void *buf);    //控制  
  6.     int (*suspend) (struct usb_interface *intf, pm_message_t message);  //挂起  
  7.     int (*resume) (struct usb_interface *intf); //唤醒  
  8.     int (*reset_resume)(struct usb_interface *intf);    //复位唤醒  
  9.     int (*pre_reset)(struct usb_interface *intf);   //预复位  
  10.     int (*post_reset)(struct usb_interface *intf);    
  11.     const struct usb_device_id *id_table;   //支持设备id表  
  12.     struct usb_dynids dynids;  
  13.     struct usbdrv_wrap drvwrap; //设备驱动的一个封装  
  14.     unsigned int no_dynamic_id:1;  
  15.     unsigned int supports_autosuspend:1;  
  16.     unsigned int soft_unbind:1;  
  17. };  

6. usb设备

[cpp]  view plain copy
  1. struct usb_device {  
  2.     int devnum; //usb设备地址  
  3.     char    devpath[16];    //usb树中的路径  
  4.     u32 route;  
  5.     enum usb_device_state   state;  //usb设备状态  
  6.     enum usb_device_speed   speed;  //usb速度  
  7.     struct usb_tt   *tt;  
  8.     int ttport;  
  9.     unsigned int toggle[2];  
  10.     struct usb_device *parent;  //父设备hub  
  11.     struct usb_bus *bus;    //总线  
  12.     struct usb_host_endpoint ep0;   //端点0  
  13.     struct device dev;  //设备文件  
  14.     struct usb_device_descriptor descriptor;    //设备描述符  
  15.     struct usb_host_config *config;   
  16.     struct usb_host_config *actconfig;  
  17.     struct usb_host_endpoint *ep_in[16];    //输入端点  
  18.     struct usb_host_endpoint *ep_out[16];   //输出端点  
  19.     char **rawdescriptors;  
  20.     unsigned short bus_mA;  //总线电流限值  
  21.     u8 portnum; //端口数  
  22.     u8 level;   //所处hub层数  
  23.     unsigned can_submit:1;  
  24.     unsigned persist_enabled:1;  
  25.     unsigned have_langid:1;  
  26.     unsigned authorized:1;  
  27.     unsigned authenticated:1;  
  28.     unsigned wusb:1;  
  29.     int string_langid;  
  30.     char *product;  //产品id  
  31.     char *manufacturer; //厂商id  
  32.     char *serial;  
  33.     struct list_head filelist;  
  34. #ifdef CONFIG_USB_DEVICE_CLASS  
  35.     struct device *usb_classdev;  
  36. #endif  
  37. #ifdef CONFIG_USB_DEVICEFS  
  38.     struct dentry *usbfs_dentry;    //usbfs入口  
  39. #endif  
  40.     int maxchild;   //最大子设备个数  
  41.     struct usb_device *children[USB_MAXCHILDREN];   //子设备数组  
  42.     u32 quirks;  
  43.     atomic_t urbnum;  
  44.     unsigned long active_duration;  
  45. #ifdef CONFIG_PM  
  46.     unsigned long last_busy;  
  47.     int autosuspend_delay;  
  48.     unsigned long connect_time;  
  49.     unsigned do_remote_wakeup:1;  
  50.     unsigned reset_resume:1;  
  51. #endif  
  52.     struct wusb_dev *wusb_dev;  
  53.     int slot_id;  
  54. };  

7. usb接口

[cpp]  view plain copy
  1. struct usb_interface {  
  2.     struct usb_host_interface *altsetting;  
  3.     struct usb_host_interface *cur_altsetting;    
  4.     unsigned num_altsetting;  
  5.     struct usb_interface_assoc_descriptor *intf_assoc;  
  6.     int minor;  
  7.     enum usb_interface_condition condition;  
  8.     unsigned sysfs_files_created:1;  
  9.     unsigned ep_devs_created:1;  
  10.     unsigned unregistering:1;  
  11.     unsigned needs_remote_wakeup:1;  
  12.     unsigned needs_altsetting0:1;  
  13.     unsigned needs_binding:1;  
  14.     unsigned reset_running:1;  
  15.     unsigned resetting_device:1;  
  16.     struct device dev;  
  17.     struct device *usb_dev;  
  18.     atomic_t pm_usage_cnt;  
  19.     struct work_struct reset_ws;  
  20. };  

8. usb请求块urb

[cpp]  view plain copy
  1. struct urb {  
  2.     struct kref kref;   //参考计数  
  3.     void *hcpriv;  
  4.     atomic_t use_count;  
  5.     atomic_t reject;  
  6.     int unlinked;  
  7.     struct list_head urb_list;  //urb链表头  
  8.     struct list_head anchor_list;  
  9.     struct list_head giveback_list;  
  10.     struct usb_anchor *anchor;  
  11.     struct usb_device *dev; //usb设备  
  12.     struct usb_host_endpoint *ep;  
  13.     unsigned int pipe;  //pipe  
  14.     unsigned int stream_id;  
  15.     int status;  
  16.     unsigned int transfer_flags;  
  17.     void *transfer_buffer;  //传输缓冲区  
  18.     dma_addr_t transfer_dma;  
  19.     struct scatterlist *sg;  
  20.     int num_sgs;  
  21.     u32 transfer_buffer_length; //缓冲区长度  
  22.     u32 actual_length;  
  23.     unsigned char *setup_packet;    //setup包  
  24.     dma_addr_t setup_dma;  
  25.     int start_frame;  
  26.     int number_of_packets;  //包数  
  27.     int interval;  
  28.     int error_count;  
  29.     void *context;  
  30.     usb_complete_t complete;    //回调函数  
  31.     struct usb_iso_packet_descriptor iso_frame_desc[0];  
  32. };  

9. usb设备id

[cpp]  view plain copy
  1. struct usb_device_id {  
  2.     __u16       match_flags;    //匹配标志  
  3.     __u16       idVendor;   //厂商id  
  4.     __u16       idProduct;  //产品id  
  5.     __u16       bcdDevice_lo;   //usb版本信息低位  
  6.     __u16       bcdDevice_hi;   //usb版本信息高位  
  7.     __u8        bDeviceClass;   //设备类  
  8.     __u8        bDeviceSubClass;    //子设备类  
  9.     __u8        bDeviceProtocol;    //设备协议  
  10.     __u8        bInterfaceClass;    //接口类  
  11.     __u8        bInterfaceSubClass; //接口之类  
  12.     __u8        bInterfaceProtocol; //接口协议  
  13.     kernel_ulong_t  driver_info;    //驱动信息  
  14. };  


1.usb设备描述符

[cpp]  view plain copy
  1. struct usb_device_descriptor {  
  2.     __u8  bLength;  
  3.     __u8  bDescriptorType;  
  4.   
  5.     __le16 bcdUSB;  
  6.     __u8  bDeviceClass;  
  7.     __u8  bDeviceSubClass;  
  8.     __u8  bDeviceProtocol;  
  9.     __u8  bMaxPacketSize0;  
  10.     __le16 idVendor;  
  11.     __le16 idProduct;  
  12.     __le16 bcdDevice;  
  13.     __u8  iManufacturer;  
  14.     __u8  iProduct;  
  15.     __u8  iSerialNumber;  
  16.     __u8  bNumConfigurations;  
  17. } __attribute__ ((packed));  

2.usb配置描述符

[cpp]  view plain copy
  1. struct usb_config_descriptor {  
  2.     __u8  bLength;  
  3.     __u8  bDescriptorType;  
  4.   
  5.     __le16 wTotalLength;  
  6.     __u8  bNumInterfaces;  
  7.     __u8  bConfigurationValue;  
  8.     __u8  iConfiguration;  
  9.     __u8  bmAttributes;  
  10.     __u8  bMaxPower;  
  11. } __attribute__ ((packed));  

3.usb端点描述符

[cpp]  view plain copy
  1. struct usb_endpoint_descriptor {  
  2.     __u8  bLength;  
  3.     __u8  bDescriptorType;  
  4.   
  5.     __u8  bEndpointAddress;  
  6.     __u8  bmAttributes;  
  7.     __le16 wMaxPacketSize;  
  8.     __u8  bInterval;  
  9.     __u8  bRefresh;  
  10.     __u8  bSynchAddress;  
  11. } __attribute__ ((packed));  

4.usb接口描述符

[cpp]  view plain copy
  1. struct usb_interface_descriptor {  
  2.     __u8  bLength;  
  3.     __u8  bDescriptorType;  
  4.   
  5.     __u8  bInterfaceNumber;  
  6.     __u8  bAlternateSetting;  
  7.     __u8  bNumEndpoints;  
  8.     __u8  bInterfaceClass;  
  9.     __u8  bInterfaceSubClass;  
  10.     __u8  bInterfaceProtocol;  
  11.     __u8  iInterface;  
  12. } __attribute__ ((packed));  
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值