您的位置:首页 > 其它

一、usb子系统相关结构体

2016-11-02 10:49 330 查看
1. usb总线

struct usb_bus {  

    struct device *controller;    

    int busnum; //总线号   

    const char *bus_name;   //总线名   

    u8 uses_dma;  

    u8 uses_pio_for_control;  

    u8 otg_port;  

    unsigned is_b_host:1;  

    unsigned b_hnp_enable:1;  

    unsigned sg_tablesize;  

    int devnum_next;    //下一个地址   

    struct usb_devmap devmap;   //usb设备地址表   

    struct usb_device *root_hub;    //根hub   

    struct usb_bus *hs_companion;  

    struct list_head bus_list;  //总线链表   

    int bandwidth_allocated;  

    int bandwidth_int_reqs;  

    int bandwidth_isoc_reqs;  

#ifdef CONFIG_USB_DEVICEFS   

    struct dentry *usbfs_dentry;  

#endif   

#if defined(CONFIG_USB_MON) || defined(CONFIG_USB_MON_MODULE)   

    struct mon_bus *mon_bus;  

    int monitored;  

#endif   

};    

2. usb hub

struct usb_hub {  

    struct device   *intfdev;  

    struct usb_device   *hdev;  //usb设备   

    struct kref kref;  

    struct urb  *urb;     

    char    (*buffer)[8];  

    union {  

        struct usb_hub_status   hub;  

        struct usb_port_status  port;  

    }*status;  

    struct mutex    status_mutex;  

    int error;  //出错标志   

    int nerrors;  

    struct list_head    event_list; //事件链表   

    unsigned long   event_bits[1];  

    unsigned long   change_bits[1];  

    unsigned long   busy_bits[1];  

    unsigned long   removed_bits[1];  

#if USB_MAXCHILDREN > 31   

#error event_bits[] is too short!   

#endif   

    struct usb_hub_descriptor *descriptor;  //hub描述符   

    struct usb_tt   tt;  

    unsigned    mA_per_port;    //每个端口电流量   

    unsigned    limited_power:1;  

    unsigned    quiescing:1;  

    unsigned    disconnected:1;  

    unsigned    has_indicators:1;  

    u8  indicator[USB_MAXCHILDREN];  

    struct delayed_work leds;  

    struct delayed_work init_work;  

    void    **port_owners;  

};   

3. usb主控器驱动

[cpp] view
plaincopy

struct hc_driver {  

    const char *description;    //主控器类型   

    const char *product_desc;   //厂商字串   

    size_t hcd_priv_size;   //私有数据大小   

    irqreturn_t (*irq) (struct usb_hcd *hcd);  

    int flags;  //版本标志   

    int (*reset) (struct usb_hcd *hcd); //重置   

    int (*start) (struct usb_hcd *hcd); //启动   

    int (*pci_suspend)(struct usb_hcd *hcd, bool do_wakeup);  

    int (*pci_resume)(struct usb_hcd *hcd, bool hibernated);  

    void (*stop) (struct usb_hcd *hcd); //停止   

    void (*shutdown) (struct usb_hcd *hcd); //关闭   

    int (*get_frame_number) (struct usb_hcd *hcd);  

    int (*urb_enqueue)(struct usb_hcd *hcd,struct urb *urb, gfp_t mem_flags);  

    int (*urb_dequeue)(struct usb_hcd *hcd,struct urb *urb, int status);  

    void (*endpoint_disable)(struct usb_hcd *hcd,struct usb_host_endpoint *ep);  

    void (*endpoint_reset)(struct usb_hcd *hcd,struct usb_host_endpoint *ep);  

    int (*hub_status_data) (struct usb_hcd *hcd, char *buf);  

    int (*hub_control) (struct usb_hcd *hcd,u16 typeReq, u16 wValue, u16 wIndex,char *buf, u16 wLength);  

    int (*bus_suspend)(struct usb_hcd *);   //总线挂起   

    int (*bus_resume)(struct usb_hcd *);  

    int (*start_port_reset)(struct usb_hcd *, unsigned port_num);  

    void (*relinquish_port)(struct usb_hcd *, int);  

    int (*port_handed_over)(struct usb_hcd *, int);  

    void (*clear_tt_buffer_complete)(struct usb_hcd *,struct usb_host_endpoint *);  

    void (*recover_hcd)(struct work_struct *data);  

    int (*alloc_dev)(struct usb_hcd *, struct usb_device *);  

    void (*free_dev)(struct usb_hcd *, struct usb_device *);  

    int (*alloc_streams)(struct usb_hcd *hcd, struct usb_device *udev,struct usb_host_endpoint **eps,   

                        unsigned int num_eps,unsigned int num_streams, gfp_t mem_flags);  

    int (*free_streams)(struct usb_hcd *hcd, struct usb_device *udev,struct usb_host_endpoint **eps,   

                        unsigned int num_eps,gfp_t mem_flags);  

    int (*add_endpoint)(struct usb_hcd *, struct usb_device *,struct usb_host_endpoint *);  

    int (*drop_endpoint)(struct usb_hcd *, struct usb_device *,struct usb_host_endpoint *);  

    int (*check_bandwidth)(struct usb_hcd *, struct usb_device *);  

    void (*reset_bandwidth)(struct usb_hcd *, struct usb_device *);  

    int (*address_device)(struct usb_hcd *, struct usb_device *udev);  

    int (*update_hub_device)(struct usb_hcd *, struct usb_device *hdev,struct usb_tt *tt, gfp_t mem_flags);  

    int (*reset_device)(struct usb_hcd *, struct usb_device *);  

    int (*update_device)(struct usb_hcd *, struct usb_device *);  

};    

4. usb主控器设备

struct usb_hcd {  

    struct usb_bus self;  

    struct kref kref;  

    const char *product_desc;   //厂商字串   

    char irq_descr[24];  

    struct timer_list rh_timer; //轮询定时器   

    struct urb *status_urb; //urb状态   

#ifdef CONFIG_USB_SUSPEND   

    struct work_struct  wakeup_work;  

#endif   

    struct work_struct ehci_omap_work;  

    const struct hc_driver *driver;  

    unsigned long flags;  

    unsigned rh_registered:1;  

    unsigned rh_pollable:1;  

    unsigned uses_new_polling:1;  

    unsigned wireless:1;  

    unsigned authorized_default:1;  

    unsigned has_tt:1;  

    int irq;    //中断号   

    void __iomem *regs; //设备内存   

    u64 rsrc_start; //设备内存资源起始地址   

    u64 rsrc_len;   //设备内存资源长度   

    unsigned power_budget;  

    struct mutex bandwidth_mutex;  

    struct dma_pool *pool[HCD_BUFFER_POOLS];  

    int state;  

    unsigned long hcd_priv[0] __attribute__ ((aligned(sizeof(unsigned long))));  

};   

5. usb设备驱动

struct usb_driver {  

    const char *name;   //usb驱动名   

    int (*probe) (struct usb_interface *intf,const struct usb_device_id *id);   //插入   

    void (*disconnect) (struct usb_interface *intf);    //拔出   

    int (*unlocked_ioctl) (struct usb_interface *intf, unsigned int code,void *buf);    //控制   

    int (*suspend) (struct usb_interface *intf, pm_message_t message);  //挂起   

    int (*resume) (struct usb_interface *intf); //唤醒   

    int (*reset_resume)(struct usb_interface *intf);    //复位唤醒   

    int (*pre_reset)(struct usb_interface *intf);   //预复位   

    int (*post_reset)(struct usb_interface *intf);    

    const struct usb_device_id *id_table;   //支持设备id表   

    struct usb_dynids dynids;  

    struct usbdrv_wrap drvwrap; //设备驱动的一个封装   

    unsigned int no_dynamic_id:1;  

    unsigned int supports_autosuspend:1;  

    unsigned int soft_unbind:1;  

};  

6. usb设备

struct usb_device {  

    int devnum; //usb设备地址   

    char    devpath[16];    //usb树中的路径   

    u32 route;  

    enum usb_device_state   state;  //usb设备状态   

    enum usb_device_speed   speed;  //usb速度   

    struct usb_tt   *tt;  

    int ttport;  

    unsigned int toggle[2];  

    struct usb_device *parent;  //父设备hub   

    struct usb_bus *bus;    //总线   

    struct usb_host_endpoint ep0;   //端点0   

    struct device dev;  //设备文件   

    struct usb_device_descriptor descriptor;    //设备描述符   

    struct usb_host_config *config;   

    struct usb_host_config *actconfig;  

    struct usb_host_endpoint *ep_in[16];    //输入端点   

    struct usb_host_endpoint *ep_out[16];   //输出端点   

    char **rawdescriptors;  

    unsigned short bus_mA;  //总线电流限值   

    u8 portnum; //端口数   

    u8 level;   //所处hub层数   

    unsigned can_submit:1;  

    unsigned persist_enabled:1;  

    unsigned have_langid:1;  

    unsigned authorized:1;  

    unsigned authenticated:1;  

    unsigned wusb:1;  

    int string_langid;  

    char *product;  //产品id   

    char *manufacturer; //厂商id   

    char *serial;  

    struct list_head filelist;  

#ifdef CONFIG_USB_DEVICE_CLASS   

    struct device *usb_classdev;  

#endif   

#ifdef CONFIG_USB_DEVICEFS   

    struct dentry *usbfs_dentry;    //usbfs入口   

#endif   

    int maxchild;   //最大子设备个数   

    struct usb_device *children[USB_MAXCHILDREN];   //子设备数组   

    u32 quirks;  

    atomic_t urbnum;  

    unsigned long active_duration;  

#ifdef CONFIG_PM   

    unsigned long last_busy;  

    int autosuspend_delay;  

    unsigned long connect_time;  

    unsigned do_remote_wakeup:1;  

    unsigned reset_resume:1;  

#endif   

    struct wusb_dev *wusb_dev;  

    int slot_id;  

};  

7. usb接口

[cpp] view
plaincopy

struct usb_interface {  

    struct usb_host_interface *altsetting;  

    struct usb_host_interface *cur_altsetting;    

    unsigned num_altsetting;  

    struct usb_interface_assoc_descriptor *intf_assoc;  

    int minor;  

    enum usb_interface_condition condition;  

    unsigned sysfs_files_created:1;  

    unsigned ep_devs_created:1;  

    unsigned unregistering:1;  

    unsigned needs_remote_wakeup:1;  

    unsigned needs_altsetting0:1;  

    unsigned needs_binding:1;  

    unsigned reset_running:1;  

    unsigned resetting_device:1;  

    struct device dev;  

    struct device *usb_dev;  

    atomic_t pm_usage_cnt;  

    struct work_struct reset_ws;  

};  

8. usb请求块urb

struct urb {  

    struct kref kref;   //参考计数   

    void *hcpriv;  

    atomic_t use_count;  

    atomic_t reject;  

    int unlinked;  

    struct list_head urb_list;  //urb链表头   

    struct list_head anchor_list;  

    struct list_head giveback_list;  

    struct usb_anchor *anchor;  

    struct usb_device *dev; //usb设备   

    struct usb_host_endpoint *ep;  

    unsigned int pipe;  //pipe   

    unsigned int stream_id;  

    int status;  

    unsigned int transfer_flags;  

    void *transfer_buffer;  //传输缓冲区   

    dma_addr_t transfer_dma;  

    struct scatterlist *sg;  

    int num_sgs;  

    u32 transfer_buffer_length; //缓冲区长度   

    u32 actual_length;  

    unsigned char *setup_packet;    //setup包   

    dma_addr_t setup_dma;  

    int start_frame;  

    int number_of_packets;  //包数   

    int interval;  

    int error_count;  

    void *context;  

    usb_complete_t complete;    //回调函数   

    struct usb_iso_packet_descriptor iso_frame_desc[0];  

};  

9. usb设备id

struct usb_device_id {  

    __u16       match_flags;    //匹配标志   

    __u16       idVendor;   //厂商id   

    __u16       idProduct;  //产品id   

    __u16       bcdDevice_lo;   //usb版本信息低位   

    __u16       bcdDevice_hi;   //usb版本信息高位   

    __u8        bDeviceClass;   //设备类   

    __u8        bDeviceSubClass;    //子设备类   

    __u8        bDeviceProtocol;    //设备协议   

    __u8        bInterfaceClass;    //接口类   

    __u8        bInterfaceSubClass; //接口之类   

    __u8        bInterfaceProtocol; //接口协议   

    kernel_ulong_t  driver_info;    //驱动信息   

};  

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

1.usb设备描述符

struct usb_device_descriptor {  

    __u8  bLength;  

    __u8  bDescriptorType;  

  

    __le16 bcdUSB;  

    __u8  bDeviceClass;  

    __u8  bDeviceSubClass;  

    __u8  bDeviceProtocol;  

    __u8  bMaxPacketSize0;  

    __le16 idVendor;  

    __le16 idProduct;  

    __le16 bcdDevice;  

    __u8  iManufacturer;  

    __u8  iProduct;  

    __u8  iSerialNumber;  

    __u8  bNumConfigurations;  

} __attribute__ ((packed));  

2.usb配置描述符

struct usb_config_descriptor {  

    __u8  bLength;  

    __u8  bDescriptorType;  

  

    __le16 wTotalLength;  

    __u8  bNumInterfaces;  

    __u8  bConfigurationValue;  

    __u8  iConfiguration;  

    __u8  bmAttributes;  

    __u8  bMaxPower;  

} __attribute__ ((packed));   

3.usb端点描述符

struct usb_endpoint_descriptor {  

    __u8  bLength;  

    __u8  bDescriptorType;  

  

    __u8  bEndpointAddress;  

    __u8  bmAttributes;  

    __le16 wMaxPacketSize;  

    __u8  bInterval;  

    __u8  bRefresh;  

    __u8  bSynchAddress;  

} __attribute__ ((packed));  

4.usb接口描述符

struct usb_interface_descriptor {  

    __u8  bLength;  

    __u8  bDescriptorType;  

  

    __u8  bInterfaceNumber;  

    __u8  bAlternateSetting;  

    __u8  bNumEndpoints;  

    __u8  bInterfaceClass;  

    __u8  bInterfaceSubClass;  

    __u8  bInterfaceProtocol;  

    __u8  iInterface;  

} __attribute__ ((packed));  
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: