【linux驱动】USB子系统分析
本文針對Linux內核下USB子系統進行分析,主要會涉及一下幾個方面:
-
USB基礎知識:介紹USB設備相關的基礎知識
-
Linux USB子系統分析:分析USB系統框架,USB HCD/ROOT HUB注冊過程,USB新設備枚舉過程
-
USB設備驅動案例:介紹常用的USB相關設備驅動
-
USB電源管理
0、USB基礎知識
USB,是英文Universal Serial Bus(通用串行總線)、支持設備的即插即用和熱插拔功能。在1994年底由英特爾、IBM、Microsoft等公司聯合提出的,在此之前PC的接口雜亂,擴展能力差,熱拔插不支持等。USB正是為了解決速度,擴展能力,易用性等而出現。
USB各版本速率對比
| USB版本 | 理論最大傳輸速率 | 速率稱號 | 最大輸出電流 | 推出時間 |
| USB 1.0 | 1.5Mbps(192KB/s) | 低速(Low-Speed) | 5V/500mA | 1996年1月 |
| USB 1.1 | 12Mbps(1.5MB/s) | 全速(Full-Speed) | 5V/500mA | 1998年9月 |
| USB 2.0 | 480Mbps(60MB/s) | 高速(High-Speed) | 5V/500mA | 2000年4月 |
| USB 3.0 | 5Gbps(500MB/s) | 超高速(Super-Speed) | 5V/900mA | 2008年11月 |
| USB 3.1 | 10Gbps(1280MB/s) | 超高速+(Super-speed+) | 20V/5A | 2013年12月 |
| USB 4.0 | 40Gbps | 協議(2019年9月) |
Linux 5.6將開始支持 USB 4 。
? ? ? ? 一個USB設備可能支持低速和全速,或者支持全速和高速,但是不會同時支持低速和高速。
0.1 USB主從結構:通信都是主機端先發起通信
從設備端沒有主動通知USB主機端的能力,從機插入后,主機控制器根據協議,獲取設備描述符及驅動匹配。
0.2 USB描述符
? ? ? ? USB設備有一下幾個主要組成,設備、配置、接口、端點。每個組成部分都有專有的描述符來描述信息。
定義路徑:kernel\include\uapi\linux\usb\ch9.h
設備描述符
/* USB_DT_DEVICE: Device descriptor */ struct usb_device_descriptor {__u8 bLength; //本結構體大小__u8 bDescriptorType; //描述符類型__le16 bcdUSB; //usb版本號 200->USB2.0__u8 bDeviceClass; //設備類 __u8 bDeviceSubClass; //設備類子類__u8 bDeviceProtocol; //設備協議,以上三點都是USB官方定義__u8 bMaxPacketSize0; //端點0最大包大小__le16 idVendor; //廠家id__le16 idProduct; //產品id__le16 bcdDevice; //設備出廠編號__u8 iManufacturer; //設備廠商字符串索引__u8 iProduct; //產品描述__u8 iSerialNumber; //設備序列號字符串索引 __u8 bNumConfigurations; //配置的個數 } __attribute__ ((packed));配置描述符
struct usb_config_descriptor {__u8 bLength; //自身長度__u8 bDescriptorType;//描述符類型(本結構體中固定為0x02) __le16 wTotalLength; //該配置下,信息的總長度__u8 bNumInterfaces; //接口的個數__u8 bConfigurationValue; //Set_Configuration命令所需要的參數值__u8 iConfiguration; //描述該配置的字符串的索引值 __u8 bmAttributes;//供電模式的選擇 __u8 bMaxPower;//設備從總線提取的最大電流 } __attribute__ ((packed));接口描述符
struct usb_interface_descriptor {__u8 bLength;__u8 bDescriptorType;//接口描述符的類型編號(0x04)__u8 bInterfaceNumber; //該接口的編號 __u8 bAlternateSetting; //備用的接口描述符編號 __u8 bNumEndpoints; //該接口使用的端點數,不包括端點0 __u8 bInterfaceClass; //接口類__u8 bInterfaceSubClass; //子類__u8 bInterfaceProtocol; //協議__u8 iInterface;//描述該接口的字符串索引值 } __attribute__ ((packed));端點描述符
/* USB_DT_ENDPOINT: Endpoint descriptor */ struct usb_endpoint_descriptor {__u8 bLength;//端點描述符字節數大小(7個字節)__u8 bDescriptorType;//端點描述符類型編號(0x05) __u8 bEndpointAddress; //端點地址及輸入輸出屬性 __u8 bmAttributes; //屬性,包含端點的傳輸類型,控制,中斷...__le16 wMaxPacketSize; //端點收、發的最大包大小__u8 bInterval; //主機查詢端點的時間間隔/* NOTE: these two are _only_ in audio endpoints. *//* use USB_DT_ENDPOINT*_SIZE in bLength, not sizeof. */__u8 bRefresh;__u8 bSynchAddress; } __attribute__ ((packed));usb驅動開發18之設備生命線 - 科創園 - 博客園
USB主機是如何檢測到設備的插入的呢? - 奔流聚海 - 博客園
USB 總線上電復位及枚舉_michaelcao1980的博客-CSDN博客_usb復位信號
0.3 USB傳輸:四種類型
- 控制傳輸:用于配置設備、獲取設備信息、發送命令或者獲取設備的狀態報告,如:USB枚舉階段。
- 批量傳輸:
- 中斷傳輸
- 實時傳輸
0.4 USB傳輸對象:端點
- 從端點接收和發送數據
- 每個端點都只有一個傳輸類型:控制,批量...
- 每個端點都只有一個傳輸方向:輸入or輸出 。端點0除外,端點0為雙向(查詢描述符,設置描述符)。
- 傳輸方向基于主機端而言,數據由從到主,則該端點為輸入端點
一、USB通信基礎
1.1 常見通信方式
串口:
? ? ? ? 基于固定通信速率,波特率下的單線通信。雙方規定好一個bit的時間。
I2C:
? ? ? ? 一個時鐘,一個數據,在時鐘邊沿進行數據傳輸。
USB:
1.2 USB 插入與斷開檢測
1.2.1 低速設備插入
? ? ? ? D-信號線在未插入的時候,主機在下拉的驅動下,呈現低電平,當插入后,在設備端內部D-上來的驅動下,D-呈現高電平,為設備插入。
1.2.2 高速設備插入
????????主機D+變高,插入。
1.3 信號狀態定義
? ? ? ? 低俗和全速的D+ D-信號狀態定義如下。
? ? ? ? J狀態,K狀態
?1.4 傳輸幀
SOF
SYNC
EOF
Data
? ? ? ? 信號不變為1,變化為0。通過 NRZI:Non Return Zero Inverted Code,反向不歸零編碼和位填充來進行數據傳輸。
? ? ? ? 沒6個不變的插入一個0,保證時鐘采用不錯位
1.5 USB通信_傳輸_事務_包_域
? ? ? ? USB通信基于傳輸,傳輸類型有:
? ? ? ? 一個傳輸由多個事務組成
? ? ? ? 一個事務由多個包組成
? ? ? ? 一個包由多個域構成
? ? ? ? 傳輸(transfer)>事務(transaction)>包(packet)>域()
傳輸
????????中斷、批量、同步實時、控制傳輸
事務
????????in事務、out事務、setup事務
包
????????令牌包(Token)、數據包(data)、握手包(ack)、特殊包
域
????????同步域(sync)、標識域(pid)、地址域(addr)、端點域(endp)、幀號域(fram)、數據域(data)、校驗域(crc)
?
1.6 傳輸要素?
批量傳輸?
中斷傳輸
?同步傳輸
控制傳輸
?
?
?
?
二、Linux USB子系統分析
Linux內核USB子系統,以總線(Bus)、設備(device)、驅動(device_driver)模型來完成設備和驅動的綁定,實現USB業務邏輯。
本節在Linux USB驅動框架的基礎上,分析USB子系統在內核中的整個初始化流程,以及內核對USB hub的監測及USB設備插入后的一系列初始化和驅動的匹配過程分析,從而分析USB業務實現的主要流程。
2.1 USB子系統框架
????????整個USB驅動模型可以總結為如上圖,USB分為主機測和設備側。本文重點分析主機測一端的USB驅動。
從主機HOST測來看,其包含:
-
USB設備驅動(RNDIS,HID,Mass Storagr...)
-
USB核心(Core init,Core API...)
-
USB主機控制器驅動HCD(Root Hub)
USB設備驅動:用于和枚舉到的USB設備進行綁定,完成特定的功能。
USB Core:用于內核USB總線的初始化及USB相關API,為設備驅動和HCD的交互提供橋梁。
USB主機控制器HCD:完成主機控制器的初始化以及數據的傳輸,并監測外部設備插入,完成設備枚舉。
接下來將從以上三個方面分析USB子系統在內核完成的初始化操作及USB業務實現的流程。
2.2 USB Core分析
Linux啟動階段,通過subsys_initcall會完成USB Core的加載,其代碼位于kernel/drivers/usb/core/usb.c。
順著驅動加載的入口函數,來分析USB被加載進內核的第一步。
2.2.1 入口函數usb_init分析
由于USB基于總線設備驅動模型來組織,其初始化階段一個重點任務為完成USB總線的創建,usb_init代碼如下:
static int __init usb_init(void) {int retval;//通過command line傳入nousb=1可禁止掉USB子模塊的加載if (nousb) {pr_info("%s: USB support disabled\n", usbcore_name);return 0;}retval = usb_debugfs_init();if (retval)goto out;usb_acpi_register();//注冊USB總線(*****)retval = bus_register(&usb_bus_type);if (retval)goto bus_register_failed;retval = bus_register_notifier(&usb_bus_type, &usb_bus_nb);if (retval)goto bus_notifier_failed;retval = usb_major_init();if (retval)goto major_init_failed;retval = usb_register(&usbfs_driver);if (retval)goto driver_register_failed;retval = usb_devio_init();if (retval)goto usb_devio_init_failed;//usb hub的初始化,完成驅動注冊和內核線程創建retval = usb_hub_init();if (retval)goto hub_init_failed;//加載一個通用的usb_device_driver驅動retval = usb_register_device_driver(&usb_generic_driver, THIS_MODULE);if (!retval)goto out;...... }usb_init主要完成USB相關的初始化操作,其重點工作:
-
通過bus_register注冊USB總線usb_bus_type
bus_register中創建了兩個鏈表,一端為設備鏈表,一端為驅動鏈表。
klist_init(&priv->klist_devices, klist_devices_get, klist_devices_put); klist_init(&priv->klist_drivers, NULL, NULL);usb_bus_type提供了設備與驅動的匹配函數usb_device_match,這個函數很重要,后面用到的時候再詳細分析。
-
完成USB Hub的初始化usb_hub_init()
任務之1:是通過usb_register(&hub_driver),向USB總線添加一個hub驅動。指定了probe,disconnect,suspend,resume,id_table等相關函數。可以猜測,在root hub創建后,會執行此處的hub_probe函數。
任務之2:完成內核線程hub_thread的創建,該線程是檢測USB端口插入設備后的處理函數,是完成USB設備識別到枚舉的監控進程,十分重要。
static int hub_thread(void *__unused) {/* khubd needs to be freezable to avoid intefering with USB-PERSIST* port handover. Otherwise it might see that a full-speed device* was gone before the EHCI controller had handed its port over to* the companion full-speed controller.*/set_freezable();do {hub_events();wait_event_freezable(khubd_wait,!list_empty(&hub_event_list) ||kthread_should_stop());} while (!kthread_should_stop() || !list_empty(&hub_event_list));pr_debug("%s: khubd exiting\n", usbcore_name);return 0; }hub_events()是一個死循環,其任務是解析hub_event_list,來一個一個處理發生在hub上的事件,比如插入,拔出。當hub_event_list事件被處理完后,break跳出while,通過wait_event_freezable使進程進入休眠態。一旦hub_event_list上有新事件需要處理,此處khubd_wait會在事件中斷中被喚醒,重新執行到此處的hub_events()來遍歷執行事件,完成處理。
hub_events()十分龐大,且十分重要,后面分析到此處流程的時候再詳細分析。
-
usb_register_device_driver完成一個usb_device_driver usb_generic_driver的注冊
區別于usb_register函數,usb_register_device_driver完成一個device的注冊,既然是一個device的驅動,那么在USB枚舉之后,創建一個USB設備后,這個驅動就會被probe。
2.2.2 USB Core重點函數及數據結構
-
usb_register()?注冊一個USB接口驅動
usb_register是一個宏,展開后:
#define usb_register(driver)? usb_register_driver(driver, THIS_MODULE, KBUILD_MODNAME) /*** usb_register_driver - register a USB interface driver* @new_driver: USB operations for the interface driver** Registers a USB interface driver with the USB core. The list of* unattached interfaces will be rescanned whenever a new driver is* added, allowing the new driver to attach to any recognized interfaces.* Returns a negative error code on failure and 0 on success.** NOTE: if you want your driver to use the USB major number, you must call* usb_register_dev() to enable that functionality. This function no longer* takes care of that.*/ int usb_register_driver(struct usb_driver *new_driver, struct module *owner,const char *mod_name) {...new_driver->drvwrap.for_devices = 0;new_driver->drvwrap.driver.name = (char *) new_driver->name;new_driver->drvwrap.driver.bus = &usb_bus_type;new_driver->drvwrap.driver.probe = usb_probe_interface;new_driver->drvwrap.driver.remove = usb_unbind_interface;...retval = driver_register(&new_driver->drvwrap.driver);retval = usb_create_newid_files(new_driver);pr_info("%s: registered new interface driver %s\n",usbcore_name, new_driver->name); }-
int usb_register_device_driver(struct usb_device_driver *new_udriver,?struct module *owner):注冊USB設備驅動
對比兩個驅動注冊函數,一個為注冊USB 接口驅動,一個為注冊USB設備驅動,一個設備可以有多個接口,設備和接口的驅動在內核是有所區別的,他們都掛在usb_bus_type下,設備驅動的for_devices變量被置1,這個變量在總線的match函數usb_device_match的時候會用于判斷是什么類型的驅動。且usb_device_match對接口和設備驅動進行了判斷,走了不通的match分支。
由于總線的match函數通過for_devices進行匹配,可以猜測內核針對的USB設備驅動僅有usb_generic_driver一個,且USB枚舉后產生的所有設備,都將被此驅動所probe。
-
struct usb_driver:USB接口驅動結構體
USB分為:USB設備驅動,USB Core和HCD。在編寫USB設備驅動的時候,一定也會向Core一樣調用usb_register來向USB總線注冊USB接口驅動。此時就需要實現一個usb_driver結構體,并填充里面重要的函數。
如上比較重要的成員,如probe匹配、id_table匹配的id表、supports_autosuspend休眠,對接設備驅動模型的drvwrap結構體等。
2.2.3 總結
可以將USB口的入口函數任務總結為如下:
-
創建并初始化了USB總線,usb_bus_type,提供了總線的匹配函數
-
向總線注冊hub的驅動,并啟動了內核線程hub_thread監控hub事件。
-
向總線注冊USB設備驅動usb_generic_driver,用于USB設備插入后的設備驅動枚舉。
2.3 USB主機控制器驅動分析
分析主機控制器驅動前,首先來看一個USB2.0協議 5.2.3 Physical Bus Topology?內的USB物理總線拓撲圖。
(譯:如下圖)USB上的設備通過分層星形拓撲物理連接到主機,如中所示圖5-5。USB連接點由一種特殊的USB設備(稱為集線器hub)提供。這個集線器提供的附加連接點稱為端口port。主機包括一個名為根集線器。主機通過根集線器提供一個或多個連接點。
從協議中可以看到,控制器上綁定了一個特殊的USB設備,稱為root hub,根集線器提供的連接點稱為port。所以可以總結出HCD需要完成的任務:
-
完成控制器硬件的初始化,使得USB PHY工作在主狀態下。
-
從軟件上構造出控制器結構體,并提供控制器驅動的操作函數,用于數據交互等。
-
既然root hub是一個USB設備,對于驅動中,一定需要創建一個USB設備來表示這個root hub。
-
外部設備插在root hub上,軟件需要完成對root hub的監控,以及USB設備插入后的創建操作。
2.3.1 HCD入口函數分析
CPU一般在內部集成USB,可選的HCD也比較多,比如dwc2、dwc3、chipidea的等等,均在kernel/drivers/usb/目下可以找到其對應的目錄。本文以dwc2為例,代碼位置: kernel/drivers/usb/dwc2/core.c。
HCD控制器驅動一般以platform的形式將驅動注冊進內核,本文HCD的入口函數中注冊了兩個platform_driver,并在板級代碼中提供了platform_device。
本文將HCD控制器驅動可以從整體上分為兩個大部分:
平臺相關的硬件初始化
內核通用的USB HCD軟件初始化流程
-
平臺硬件相關初始化
第一部分:平臺相關的硬件初始化,主要完成硬件相關初始化,devm_clk_get/clk_enable申請并使能時鐘,phy_init對USB PHY寄存器進行初始化設置,devm_request_threaded_irq申請id引腳中斷等。是與硬件相關的初始化。在完成平臺硬件的初始化后,在probe的末尾部分,調用了dwc2_host_init()函數。
將dwc2_host_init()看做HCD驅動第二部分,其主要完成HCD控制器的創建注冊以及ROOT HUB的注冊和HUB的監測。由于內核該部分調用關系比較多,本文將第二部分分為多個層次,從dwc2_host_init()開始。
-
第一層:dwc2_host_init(dwc)
從最頂層名字上說明了整個代碼最終是為了完成host控制器的初始化。在上面,我們知道主機控制器上綁定了一個ROOT HUB。
int dwc2_host_init(struct dwc2 *dwc) {struct usb_hcd *hcd;int ret;...hcd = usb_create_hcd(&dwc2_hc_driver, dwc->dev, dev_name(dwc->dev));dev_set_drvdata(dwc->dev, dwc);*(struct dwc2 **)(hcd->hcd_priv) = dwc;dwc->hcd = hcd;ret = usb_add_hcd(hcd, -1, 0);... }dwc2_host_init 主要調用了兩個函數usb_create_hcd和usb_add_hcd
① usb_create_hcd(&dwc2_hc_driver, dwc->dev, dev_name(dwc->dev));
struct usb_hcd *usb_create_hcd(const struct hc_driver *driver,struct device *dev, const char *bus_name) {return usb_create_shared_hcd(driver, dev, bus_name, NULL); } /*** usb_create_shared_hcd - create and initialize an HCD structure* @driver: HC driver that will use this hcd* @dev: device for this HC, stored in hcd->self.controller* @bus_name: value to store in hcd->self.bus_name* @primary_hcd: a pointer to the usb_hcd structure that is sharing the* PCI device. Only allocate certain resources for the primary HCD* Context: !in_interrupt()** Allocate a struct usb_hcd, with extra space at the end for the* HC driver's private data. Initialize the generic members of the* hcd structure.** If memory is unavailable, returns NULL.*/ struct usb_hcd *usb_create_shared_hcd(const struct hc_driver *driver,struct device *dev, const char *bus_name,struct usb_hcd *primary_hcd) {struct usb_hcd *hcd;hcd = kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL);...usb_bus_init(&hcd->self);hcd->self.controller = dev;hcd->self.bus_name = bus_name;hcd->self.uses_dma = (dev->dma_mask != NULL);init_timer(&hcd->rh_timer);hcd->rh_timer.function = rh_timer_func;hcd->rh_timer.data = (unsigned long) hcd; #ifdef CONFIG_PM_RUNTIMEINIT_WORK(&hcd->wakeup_work, hcd_resume_work); #endifhcd->driver = driver;... }根據注釋該函數主要任務是創建并初始化一個HCD 結構體usb_hcd ,該函數主要實現:
完成usb_hcd內存申請
usb_bus總線初始化,usb_bus_init(&hcd->self);
填充控制器驅動hc_driver。
usb_hcd的第一個成員是:struct usb_bus?? ??? ?self;?? ??? ?/* hcd is-a bus */。
一個主控制器對應一條usb總線,一個主控制器綁定著一個root hub,一個root hub對應于一個usb_device,然后注冊此root ?hub。
每個usb設備(usb_device)有一種或多種配置,每種配置有一個或多個接口,一個接口有一種或多種設置,一種設置有一個或多個端點。
hcd->driver = driver;中的driver=&dwc2_hc_driver(struct hc_driver)是主機控制器驅動函數,實現了通過主機控制器硬件向外通信的方法。類似于網卡設備驅動里面的net_device_ops結構體。后面用到再具體分析hc_driver。
② usb_add_hcd(hcd, -1, 0);
int usb_add_hcd(struct usb_hcd *hcd,unsigned int irqnum, unsigned long irqflags) {int retval;struct usb_device *rhdev;if ((retval = usb_register_bus(&hcd->self)) < 0)goto err_register_bus;if ((rhdev = usb_alloc_dev(NULL, &hcd->self, 0)) == NULL) {dev_err(hcd->self.controller, "unable to allocate root hub\n");retval = -ENOMEM;goto err_allocate_root_hub;}hcd->self.root_hub = rhdev;if (hcd->driver->reset && (retval = hcd->driver->reset(hcd)) < 0) {dev_err(hcd->self.controller, "can't setup\n");goto err_hcd_driver_setup;}hcd->state = HC_STATE_RUNNING;retval = hcd->driver->start(hcd);/* starting here, usbcore will pay attention to this root hub */retval = register_root_hub(hcd); }將hcd添加到USB總線,該函數主要實現
注冊usb_bus總線
usb_alloc_dev申請一個usb_device,并賦給hcd->self.root_hub
register_root_hub
上面我們根據協議知道主機控制器上會被綁定一個特殊的USB設備叫做root hub,在hcd注冊完成后,為了實現正常的usb功能,此處應該還要實現一個root hub并綁定在hcd上。當完成usb_bus總線的注冊后,此處調用usb_alloc_dev來創建一個USB設備,并將該設備指給了控制器的root hub,hcd->self.root_hub = rhdev;并調用register_root_hub注冊到usb總線。
-
第二層:register_root_hub()
usb_new_device創建一個usb設備并將其掛到usb_bus_type總線上,由于USB為總線設備驅動模型,在執行usb_new_device后,將執行總線的匹配函數如下。
usb_new_device->device_add->bus_probe_device->device_attach->bus_for_each_drv->__device_attach->driver_match_device->drv->bus->match(dev, drv)->usb_device_match
回顧USB2.0協議,這里確實是實現了一個綁定在控制器上的usb設備,并將其掛在USB總線上作為root hub來維護。
-
第三層:設備與驅動的匹配
USB總線的匹配函數usb_device_match這時就需要被調用到了,其代碼如下:
static int usb_device_match(struct device *dev, struct device_driver *drv) {/* devices and interfaces are handled separately */if (is_usb_device(dev)) {/* interface drivers never match devices */if (!is_usb_device_driver(drv))return 0;/* TODO: Add real matching code */return 1;} else if (is_usb_interface(dev)) {struct usb_interface *intf;struct usb_driver *usb_drv;const struct usb_device_id *id;/* device drivers never match interfaces */if (is_usb_device_driver(drv))return 0;intf = to_usb_interface(dev);usb_drv = to_usb_driver(drv);id = usb_match_id(intf, usb_drv->id_table);if (id)return 1;id = usb_match_dynamic_id(intf, usb_drv);if (id)return 1;}return 0; }2.2章節我們分析了usb_register來注冊一個usb接口驅動,usb_register_device_driver來注冊一個usb設備驅動。同樣在match函數里面也針對usb接口和設備進行了區分,形成了if else兩個分支。
① USB設備&USB設備驅動?
is_usb_device(dev)
static inline int is_usb_device(const struct device *dev) {return dev->type == &usb_device_type; }usb_alloc_dev在創建usb hub的時候,其內部指定了dev->dev.type = &usb_device_type;
is_usb_device_driver(drv)
static inline int is_usb_device_driver(struct device_driver *drv) {return container_of(drv, struct usbdrv_wrap, driver)->for_devices; }回顧分析usb core入口函數,當時注冊了一個usb設備驅動usb_generic_driver,其for_devices為1.此時顯然root hub設備與usb_generic_driver驅動匹配成功,因此usb_generic_driver的generic_probe函數被調用。
① USB接口&USB接口驅動?
我們繼續分析usb root hub的注冊,此時generic_probe被調用。
static int generic_probe(struct usb_device *udev) {int err, c;/* Choose and set the configuration. This registers the interfaces* with the driver core and lets interface drivers bind to them.*/c = usb_choose_configuration(udev);err = usb_set_configuration(udev, c);/* USB device state == configured ... usable */usb_notify_add_device(udev);return 0; }其主要函數2個:usb_choose_configuration和usb_set_configuration,選擇配置并設置配置。
-
第四層:usb配置選擇和設置
USB驅動框架分析1_段小蘇學習之路的博客-CSDN博客_usb驅動框架
Linux下的USB HUB驅動 第3頁_Linux編程_Linux公社-Linux系統門戶網站
在usb_set_configuration的尾部,會將每一個接口設備注冊到內核中。
?? ?for (i = 0; i < nintf; ++i) {struct usb_interface *intf = cp->interface[i];ret = device_add(&intf->dev);create_intf_ep_devs(intf);}在執行device_add后導致總線的匹配函數usb_device_match再次被調用,這次由于是接口設備,設備類型為usb_if_device_type,那么匹配的一定是接口驅動,于是會執行usb_device_match的else分支,去匹配接口驅動。根據上面對usb_device_match的分析,此時在core注冊的hub_driver的hub_probe函數被調用。
-
第五層:hub_probe分析
申請usb_hub ,填充,調用hub_configure配置hub
static int hub_configure(struct usb_hub *hub,struct usb_endpoint_descriptor *endpoint) {struct usb_hcd *hcd;struct usb_device *hdev = hub->hdev;struct device *hub_dev = hub->intfdev;u16 hubstatus, hubchange;hub->descriptor = kmalloc(sizeof(*hub->descriptor), GFP_KERNEL);//獲取HUB的描述符ret = get_hub_descriptor(hdev, hub->descriptor);hub->ports = kzalloc(hdev->maxchild * sizeof(struct usb_port *),//填充urbhub->urb = usb_alloc_urb(0, GFP_KERNEL);//初始化一個中斷urb,回調函數為hub_irqusb_fill_int_urb(hub->urb, hdev, pipe, *hub->buffer, maxp, hub_irq,hub, endpoint->bInterval);//激活hubhub_activate(hub, HUB_INIT);}填充hub的相關描述符信息
初始化一個urb中斷,其回調函數為hub_irq
并激活hub
在當hub上存在事件的時候時候會觸發hub_irq調用,hub_irq調用kick_khubd完成對hub_thread的喚醒,去執行hub_events。
/* completion function, fires on port status changes and various faults */ static void hub_irq(struct urb *urb) {struct usb_hub *hub = urb->context;int status = urb->status;unsigned i;unsigned long bits;switch (status) {case -ENOENT: /* synchronous unlink */case -ECONNRESET: /* async unlink */case -ESHUTDOWN: /* hardware going away */return;default: /* presumably an error *//* Cause a hub reset after 10 consecutive errors */dev_dbg (hub->intfdev, "transfer --> %d\n", status);if ((++hub->nerrors < 10) || hub->error)goto resubmit;hub->error = status;/* FALL THROUGH *//* let khubd handle things */case 0: /* we got data: port status changed */bits = 0;for (i = 0; i < urb->actual_length; ++i)bits |= ((unsigned long) ((*hub->buffer)[i]))<< (i*8);hub->event_bits[0] = bits;break;}hub->nerrors = 0;/* Something happened, let khubd figure it out */kick_khubd(hub);if ((status = usb_submit_urb (hub->urb, GFP_ATOMIC)) != 0&& status != -ENODEV && status != -EPERM)dev_err (hub->intfdev, "resubmit --> %d\n", status); } static void kick_khubd(struct usb_hub *hub) {unsigned long flags;spin_lock_irqsave(&hub_event_lock, flags);if (!hub->disconnected && list_empty(&hub->event_list)) {list_add_tail(&hub->event_list, &hub_event_list);/* Suppress autosuspend until khubd runs */usb_autopm_get_interface_no_resume(to_usb_interface(hub->intfdev));wake_up(&khubd_wait);}spin_unlock_irqrestore(&hub_event_lock, flags); }usb協議:11.12.3 Port Change Information Processing?
?
-
第六層?hub_events()事件處理
第五層,完成了root hub的初始化及相關hub監測的創建,當hub上存在新事件的時候,hub_events開始執行,進行hub事件處理。是hub功能最為核心的處理函數。
static void hub_events(void) {struct list_head *tmp;struct usb_device *hdev;struct usb_interface *intf;struct usb_hub *hub;struct device *hub_dev;u16 hubstatus;u16 hubchange;u16 portstatus;u16 portchange;int i, ret;int connect_change, wakeup_change;/** We restart the list every time to avoid a deadlock with* deleting hubs downstream from this one. This should be* safe since we delete the hub from the event list.* Not the most efficient, but avoids deadlocks.*/while (1) {/* Grab the first entry at the beginning of the list */spin_lock_irq(&hub_event_lock);if (list_empty(&hub_event_list)) {spin_unlock_irq(&hub_event_lock);break;}tmp = hub_event_list.next;list_del_init(tmp);hub = list_entry(tmp, struct usb_hub, event_list);kref_get(&hub->kref);spin_unlock_irq(&hub_event_lock);hdev = hub->hdev;hub_dev = hub->intfdev;intf = to_usb_interface(hub_dev);dev_dbg(hub_dev, "state %d ports %d chg %04x evt %04x\n",hdev->state, hub->descriptor? hub->descriptor->bNbrPorts: 0,/* NOTE: expects max 15 ports... */(u16) hub->change_bits[0],(u16) hub->event_bits[0]);/* Lock the device, then check to see if we were* disconnected while waiting for the lock to succeed. */usb_lock_device(hdev);if (unlikely(hub->disconnected))goto loop_disconnected;/* If the hub has died, clean up after it */if (hdev->state == USB_STATE_NOTATTACHED) {hub->error = -ENODEV;hub_quiesce(hub, HUB_DISCONNECT);goto loop;}/* Autoresume */ret = usb_autopm_get_interface(intf);if (ret) {dev_dbg(hub_dev, "Can't autoresume: %d\n", ret);goto loop;}/* If this is an inactive hub, do nothing */if (hub->quiescing)goto loop_autopm;if (hub->error) {dev_dbg (hub_dev, "resetting for error %d\n",hub->error);ret = usb_reset_device(hdev);if (ret) {dev_dbg (hub_dev,"error resetting hub: %d\n", ret);goto loop_autopm;}hub->nerrors = 0;hub->error = 0;}/* deal with port status changes */for (i = 1; i <= hub->descriptor->bNbrPorts; i++) {if (test_bit(i, hub->busy_bits))continue;connect_change = test_bit(i, hub->change_bits);wakeup_change = test_and_clear_bit(i, hub->wakeup_bits);if (!test_and_clear_bit(i, hub->event_bits) &&!connect_change && !wakeup_change)continue;ret = hub_port_status(hub, i,&portstatus, &portchange);if (ret < 0)continue;if (portchange & USB_PORT_STAT_C_CONNECTION) {usb_clear_port_feature(hdev, i,USB_PORT_FEAT_C_CONNECTION);connect_change = 1;}if (portchange & USB_PORT_STAT_C_ENABLE) {if (!connect_change)dev_dbg (hub_dev,"port %d enable change, ""status %08x\n",i, portstatus);usb_clear_port_feature(hdev, i,USB_PORT_FEAT_C_ENABLE);/** EM interference sometimes causes badly* shielded USB devices to be shutdown by* the hub, this hack enables them again.* Works at least with mouse driver. */if (!(portstatus & USB_PORT_STAT_ENABLE)&& !connect_change&& hub->ports[i - 1]->child) {dev_err (hub_dev,"port %i ""disabled by hub (EMI?), ""re-enabling...\n",i);connect_change = 1;}}if (hub_handle_remote_wakeup(hub, i,portstatus, portchange))connect_change = 1;if (portchange & USB_PORT_STAT_C_OVERCURRENT) {u16 status = 0;u16 unused;dev_dbg(hub_dev, "over-current change on port ""%d\n", i);usb_clear_port_feature(hdev, i,USB_PORT_FEAT_C_OVER_CURRENT);msleep(100); /* Cool down */hub_power_on(hub, true);hub_port_status(hub, i, &status, &unused);if (status & USB_PORT_STAT_OVERCURRENT)dev_err(hub_dev, "over-current ""condition on port %d\n", i);}if (portchange & USB_PORT_STAT_C_RESET) {dev_dbg (hub_dev,"reset change on port %d\n",i);usb_clear_port_feature(hdev, i,USB_PORT_FEAT_C_RESET);}if ((portchange & USB_PORT_STAT_C_BH_RESET) &&hub_is_superspeed(hub->hdev)) {dev_dbg(hub_dev,"warm reset change on port %d\n",i);usb_clear_port_feature(hdev, i,USB_PORT_FEAT_C_BH_PORT_RESET);}if (portchange & USB_PORT_STAT_C_LINK_STATE) {usb_clear_port_feature(hub->hdev, i,USB_PORT_FEAT_C_PORT_LINK_STATE);}if (portchange & USB_PORT_STAT_C_CONFIG_ERROR) {dev_warn(hub_dev,"config error on port %d\n",i);usb_clear_port_feature(hub->hdev, i,USB_PORT_FEAT_C_PORT_CONFIG_ERROR);}/* Warm reset a USB3 protocol port if it's in* SS.Inactive state.*/if (hub_port_warm_reset_required(hub, portstatus)) {int status;struct usb_device *udev =hub->ports[i - 1]->child;dev_dbg(hub_dev, "warm reset port %d\n", i);if (!udev || !(portstatus &USB_PORT_STAT_CONNECTION)) {status = hub_port_reset(hub, i,NULL, HUB_BH_RESET_TIME,true);if (status < 0)hub_port_disable(hub, i, 1);} else {usb_lock_device(udev);status = usb_reset_device(udev);usb_unlock_device(udev);connect_change = 0;}}if (connect_change)hub_port_connect_change(hub, i,portstatus, portchange);} /* end for i *//* deal with hub status changes */if (test_and_clear_bit(0, hub->event_bits) == 0); /* do nothing */else if (hub_hub_status(hub, &hubstatus, &hubchange) < 0)dev_err (hub_dev, "get_hub_status failed\n");else {if (hubchange & HUB_CHANGE_LOCAL_POWER) {dev_dbg (hub_dev, "power change\n");clear_hub_feature(hdev, C_HUB_LOCAL_POWER);if (hubstatus & HUB_STATUS_LOCAL_POWER)/* FIXME: Is this always true? */hub->limited_power = 1;elsehub->limited_power = 0;}if (hubchange & HUB_CHANGE_OVERCURRENT) {u16 status = 0;u16 unused;dev_dbg(hub_dev, "over-current change\n");clear_hub_feature(hdev, C_HUB_OVER_CURRENT);msleep(500); /* Cool down */hub_power_on(hub, true);hub_hub_status(hub, &status, &unused);if (status & HUB_STATUS_OVERCURRENT)dev_err(hub_dev, "over-current ""condition\n");}}loop_autopm:/* Balance the usb_autopm_get_interface() above */usb_autopm_put_interface_no_suspend(intf);loop:/* Balance the usb_autopm_get_interface_no_resume() in* kick_khubd() and allow autosuspend.*/usb_autopm_put_interface(intf);loop_disconnected:usb_unlock_device(hdev);kref_put(&hub->kref, hub_release);} /* end while (1) */ }hub_events主要任務:
調用hub_port_status獲取hub上發生的時間
調用hub_port_connect_change去處理事件
hub_port_connect_change主要任務
判斷發生的事件的類型
若有新設備插入,則創建一個usb設備,并完成設備的信息獲取和初始化。
USB協議 9.1?USB設備狀態
usb_alloc_devdev->state = USB_STATE_ATTACHED;第七層 USB設備與驅動的枚舉
2.3.2 HCD重點函數及結構體
/*-------------------------------------------------------------------------*//** USB Host Controller Driver (usb_hcd) framework** Since "struct usb_bus" is so thin, you can't share much code in it.* This framework is a layer over that, and should be more sharable.** @authorized_default: Specifies if new devices are authorized to* connect by default or they require explicit* user space authorization; this bit is settable* through /sys/class/usb_host/X/authorized_default.* For the rest is RO, so we don't lock to r/w it.*//*-------------------------------------------------------------------------*/struct usb_hcd {/** housekeeping*/struct usb_bus self; /* hcd is-a bus */struct kref kref; /* reference counter */const char *product_desc; /* product/vendor string */int speed; /* Speed for this roothub.* May be different from* hcd->driver->flags & HCD_MASK*/char irq_descr[24]; /* driver + bus # */struct timer_list rh_timer; /* drives root-hub polling */struct urb *status_urb; /* the current status urb */ #ifdef CONFIG_PM_RUNTIMEstruct work_struct wakeup_work; /* for remote wakeup */ #endif/** hardware info/state*/const struct hc_driver *driver; /* hw-specific hooks *//** OTG and some Host controllers need software interaction with phys;* other external phys should be software-transparent*/struct usb_phy *phy;/* Flags that need to be manipulated atomically because they can* change while the host controller is running. Always use* set_bit() or clear_bit() to change their values.*/unsigned long flags; #define HCD_FLAG_HW_ACCESSIBLE 0 /* at full power */ #define HCD_FLAG_POLL_RH 2 /* poll for rh status? */ #define HCD_FLAG_POLL_PENDING 3 /* status has changed? */ #define HCD_FLAG_WAKEUP_PENDING 4 /* root hub is resuming? */ #define HCD_FLAG_RH_RUNNING 5 /* root hub is running? */ #define HCD_FLAG_DEAD 6 /* controller has died? *//* The flags can be tested using these macros; they are likely to* be slightly faster than test_bit().*/ #define HCD_HW_ACCESSIBLE(hcd) ((hcd)->flags & (1U << HCD_FLAG_HW_ACCESSIBLE)) #define HCD_POLL_RH(hcd) ((hcd)->flags & (1U << HCD_FLAG_POLL_RH)) #define HCD_POLL_PENDING(hcd) ((hcd)->flags & (1U << HCD_FLAG_POLL_PENDING)) #define HCD_WAKEUP_PENDING(hcd) ((hcd)->flags & (1U << HCD_FLAG_WAKEUP_PENDING)) #define HCD_RH_RUNNING(hcd) ((hcd)->flags & (1U << HCD_FLAG_RH_RUNNING)) #define HCD_DEAD(hcd) ((hcd)->flags & (1U << HCD_FLAG_DEAD))/* Flags that get set only during HCD registration or removal. */unsigned rh_registered:1;/* is root hub registered? */unsigned rh_pollable:1; /* may we poll the root hub? */unsigned msix_enabled:1; /* driver has MSI-X enabled? *//* The next flag is a stopgap, to be removed when all the HCDs* support the new root-hub polling mechanism. */unsigned uses_new_polling:1;unsigned wireless:1; /* Wireless USB HCD */unsigned authorized_default:1;unsigned has_tt:1; /* Integrated TT in root hub */unsigned int irq; /* irq allocated */void __iomem *regs; /* device memory/io */resource_size_t rsrc_start; /* memory/io resource start */resource_size_t rsrc_len; /* memory/io resource length */unsigned power_budget; /* in mA, 0 = no limit *//* bandwidth_mutex should be taken before adding or removing* any new bus bandwidth constraints:* 1. Before adding a configuration for a new device.* 2. Before removing the configuration to put the device into* the addressed state.* 3. Before selecting a different configuration.* 4. Before selecting an alternate interface setting.** bandwidth_mutex should be dropped after a successful control message* to the device, or resetting the bandwidth after a failed attempt.*/struct mutex *bandwidth_mutex;struct usb_hcd *shared_hcd;struct usb_hcd *primary_hcd;#define HCD_BUFFER_POOLS 4struct dma_pool *pool[HCD_BUFFER_POOLS];int state; # define __ACTIVE 0x01 # define __SUSPEND 0x04 # define __TRANSIENT 0x80# define HC_STATE_HALT 0 # define HC_STATE_RUNNING (__ACTIVE) # define HC_STATE_QUIESCING (__SUSPEND|__TRANSIENT|__ACTIVE) # define HC_STATE_RESUMING (__SUSPEND|__TRANSIENT) # define HC_STATE_SUSPENDED (__SUSPEND)#define HC_IS_RUNNING(state) ((state) & __ACTIVE) #define HC_IS_SUSPENDED(state) ((state) & __SUSPEND)/* more shared queuing code would be good; it should support* smarter scheduling, handle transaction translators, etc;* input size of periodic table to an interrupt scheduler.* (ohci 32, uhci 1024, ehci 256/512/1024).*//* The HC driver's private data is stored at the end of* this structure.*/unsigned long hcd_priv[0]__attribute__ ((aligned(sizeof(s64)))); };2.3.3 總結
三、USB驅動分析
根據以上對內核USB子系統分析,此時可以來分析USB驅動的案例,加強對USB的理解。
分析HCD的過程中,在控制器上綁定的root hub就是一個usb device,HCD初始化過程完成了對這個USB設備的一系列初始化,并使用usb_fill_int_urb初始化了一個中斷urb,使用usb_submit_urb 進行提交。
首先分析一個usb鼠標驅動,其和root hub的過程相似,也是中斷傳輸。
3.1 Usb Mouse驅動
代碼位置:kernel\drivers\hid\usbhid\usbmouse.c
Linux USB驅動學習總結(三)---- USB鼠標的加載、初始化和通信過程 - 圖靈之夢 - 博客園
#include <linux/kernel.h> #include <linux/slab.h> #include <linux/module.h> #include <linux/init.h> #include <linux/usb/input.h> #include <linux/hid.h>/* for apple IDs */ #ifdef CONFIG_USB_HID_MODULE #include "../hid-ids.h" #endif/** Version Information*/ #define DRIVER_VERSION "v1.6" #define DRIVER_AUTHOR "Vojtech Pavlik <vojtech@ucw.cz>" #define DRIVER_DESC "USB HID Boot Protocol mouse driver" #define DRIVER_LICENSE "GPL"MODULE_AUTHOR(DRIVER_AUTHOR); MODULE_DESCRIPTION(DRIVER_DESC); MODULE_LICENSE(DRIVER_LICENSE);struct usb_mouse {char name[128];char phys[64];struct usb_device *usbdev;struct input_dev *dev;struct urb *irq;signed char *data;dma_addr_t data_dma; };static void usb_mouse_irq(struct urb *urb) {struct usb_mouse *mouse = urb->context;signed char *data = mouse->data;struct input_dev *dev = mouse->dev;int status;switch (urb->status) {case 0: /* success */break;case -ECONNRESET: /* unlink */case -ENOENT:case -ESHUTDOWN:return;/* -EPIPE: should clear the halt */default: /* error */goto resubmit;}input_report_key(dev, BTN_LEFT, data[0] & 0x01);input_report_key(dev, BTN_RIGHT, data[0] & 0x02);input_report_key(dev, BTN_MIDDLE, data[0] & 0x04);input_report_key(dev, BTN_SIDE, data[0] & 0x08);input_report_key(dev, BTN_EXTRA, data[0] & 0x10);input_report_rel(dev, REL_X, data[1]);input_report_rel(dev, REL_Y, data[2]);input_report_rel(dev, REL_WHEEL, data[3]);input_sync(dev); resubmit:status = usb_submit_urb (urb, GFP_ATOMIC);if (status)dev_err(&mouse->usbdev->dev,"can't resubmit intr, %s-%s/input0, status %d\n",mouse->usbdev->bus->bus_name,mouse->usbdev->devpath, status); }static int usb_mouse_open(struct input_dev *dev) {struct usb_mouse *mouse = input_get_drvdata(dev);mouse->irq->dev = mouse->usbdev;if (usb_submit_urb(mouse->irq, GFP_KERNEL))return -EIO;return 0; }static void usb_mouse_close(struct input_dev *dev) {struct usb_mouse *mouse = input_get_drvdata(dev);usb_kill_urb(mouse->irq); }static int usb_mouse_probe(struct usb_interface *intf, const struct usb_device_id *id) {struct usb_device *dev = interface_to_usbdev(intf);struct usb_host_interface *interface;struct usb_endpoint_descriptor *endpoint;struct usb_mouse *mouse;struct input_dev *input_dev;int pipe, maxp;int error = -ENOMEM;interface = intf->cur_altsetting;if (interface->desc.bNumEndpoints != 1)return -ENODEV;endpoint = &interface->endpoint[0].desc;if (!usb_endpoint_is_int_in(endpoint))return -ENODEV;pipe = usb_rcvintpipe(dev, endpoint->bEndpointAddress);maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe));mouse = kzalloc(sizeof(struct usb_mouse), GFP_KERNEL);input_dev = input_allocate_device();if (!mouse || !input_dev)goto fail1;mouse->data = usb_alloc_coherent(dev, 8, GFP_ATOMIC, &mouse->data_dma);if (!mouse->data)goto fail1;mouse->irq = usb_alloc_urb(0, GFP_KERNEL);if (!mouse->irq)goto fail2;mouse->usbdev = dev;mouse->dev = input_dev;if (dev->manufacturer)strlcpy(mouse->name, dev->manufacturer, sizeof(mouse->name));if (dev->product) {if (dev->manufacturer)strlcat(mouse->name, " ", sizeof(mouse->name));strlcat(mouse->name, dev->product, sizeof(mouse->name));}if (!strlen(mouse->name))snprintf(mouse->name, sizeof(mouse->name),"USB HIDBP Mouse %04x:%04x",le16_to_cpu(dev->descriptor.idVendor),le16_to_cpu(dev->descriptor.idProduct));usb_make_path(dev, mouse->phys, sizeof(mouse->phys));strlcat(mouse->phys, "/input0", sizeof(mouse->phys));input_dev->name = mouse->name;input_dev->phys = mouse->phys;usb_to_input_id(dev, &input_dev->id);input_dev->dev.parent = &intf->dev;input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);input_dev->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |BIT_MASK(BTN_RIGHT) | BIT_MASK(BTN_MIDDLE);input_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_SIDE) |BIT_MASK(BTN_EXTRA);input_dev->relbit[0] |= BIT_MASK(REL_WHEEL);input_set_drvdata(input_dev, mouse);input_dev->open = usb_mouse_open;input_dev->close = usb_mouse_close;usb_fill_int_urb(mouse->irq, dev, pipe, mouse->data,(maxp > 8 ? 8 : maxp),usb_mouse_irq, mouse, endpoint->bInterval);mouse->irq->transfer_dma = mouse->data_dma;mouse->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;error = input_register_device(mouse->dev);if (error)goto fail3;usb_set_intfdata(intf, mouse);return 0;fail3: usb_free_urb(mouse->irq); fail2: usb_free_coherent(dev, 8, mouse->data, mouse->data_dma); fail1: input_free_device(input_dev);kfree(mouse);return error; }static void usb_mouse_disconnect(struct usb_interface *intf) {struct usb_mouse *mouse = usb_get_intfdata (intf);usb_set_intfdata(intf, NULL);if (mouse) {usb_kill_urb(mouse->irq);input_unregister_device(mouse->dev);usb_free_urb(mouse->irq);usb_free_coherent(interface_to_usbdev(intf), 8, mouse->data, mouse->data_dma);kfree(mouse);} }//用于驅動的匹配: //match_flags 匹配哪些項,USB_DEVICE_ID_MATCH_INT_INFO:接口信息 //bInterfaceClass 、bInterfaceSubClass 、bInterfaceProtocol 所屬的類,子類,及設備協議是否匹配 //#define USB_INTERFACE_INFO(cl, sc, pr) \.match_flags = USB_DEVICE_ID_MATCH_INT_INFO, \.bInterfaceClass = (cl), \.bInterfaceSubClass = (sc), \.bInterfaceProtocol = (pr) static struct usb_device_id usb_mouse_id_table [] = {{ USB_INTERFACE_INFO(USB_INTERFACE_CLASS_HID, USB_INTERFACE_SUBCLASS_BOOT,USB_INTERFACE_PROTOCOL_MOUSE) },{ } /* Terminating entry */ };MODULE_DEVICE_TABLE (usb, usb_mouse_id_table);static struct usb_driver usb_mouse_driver = {.name = "usbmouse",.probe = usb_mouse_probe,.disconnect = usb_mouse_disconnect,.id_table = usb_mouse_id_table, };module_usb_driver(usb_mouse_driver);3.2 USB網卡
USB設備信息
設備電源管理信息
參數1:autosuspend & autosuspend_delay_ms
運行時期休眠的超時時間,即但總線掛起設備后,多久之后設備開始進入休眠。
參數2:runtime_enabled &?
runtime_enabled :是否允許運行時期的休眠,狀態有4中:disabled、forbidden、disabled & forbidden、enabled
disabled:dev->power.disable_depth
forbidden:dev->power.runtime_auto
runtime_status:當前狀態
參數3:runtime_status?
當前設備狀態有四種:suspended、suspending、resuming、active。見上圖。
參數:runtime_usage:&dev->power.usage_count
參數:runtime_suspended_time &?runtime_active_time
設備活躍時間和掛起的時間
USB枚舉過程_木木總裁的博客-CSDN博客_usb掛起
總結
以上是生活随笔為你收集整理的【linux驱动】USB子系统分析的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 其他blast使用方法
- 下一篇: 微服务层次图