USB Hub 检测装备 [复制链接]
发表于 2025-11-19 13:43:40 | 显示全部楼层 |阅读模式

系列文章目次


xHCI 简朴分析
USB Root Hub 分析
USB Hub 检测装备
<hr>
  
<hr> 一、弁言

    USB Hub 检测装备 一文中讲到,当有 USB 插入时,它会激活 hub_events 函数。
  1. static int hub_thread(void *__unused)
  2. {
  3.    
  4.    
  5.         do {
  6.    
  7.    
  8.                 hub_events();
  9.                 wait_event_interruptible(khubd_wait,
  10.                                 !list_empty(&hub_event_list) ||
  11.                                 kthread_should_stop());
  12.                 try_to_freeze();
  13.         } while (!kthread_should_stop() || !list_empty(&hub_event_list));
  14.         pr_debug("%s: khubd exiting\n", usbcore_name);
  15.         return 0;
  16. }
复制代码
二、hub_events


  1. static void hub_events(void)
  2. {
  3.    
  4.    
  5.         // ...
  6.         while (1) {
  7.    
  8.    
  9.                 // ...
  10.                 tmp = hub_event_list.next;
  11.                 list_del_init(tmp);
  12.                 hub = list_entry(tmp, struct usb_hub, event_list);
  13.                 // 描述 usb 设备(Hub,整体,不是接口)
  14.                 hdev = hub->hdev;
  15.                 intf = to_usb_interface(hub->intfdev);
  16.                 // hub 接口设备
  17.                 hub_dev = &intf->dev;
  18.                 // ...
  19.                 /* Lock the device, then check to see if we were
  20.                  * disconnected while waiting for the lock to succeed. */
  21.                 if (locktree(hdev) < 0) {
  22.    
  23.    
  24.                 // ...
  25.                 /* Autoresume */
  26.                 ret = usb_autopm_get_interface(intf);
  27.                 // ...
  28.                 /* deal with port status changes */
  29.                 for (i = 1; i <= hub->descriptor->bNbrPorts; i++) {
  30.    
  31.    
  32.                         // ...
  33.                         ret = hub_port_status(hub, i,
  34.                                         &portstatus, &portchange);
  35.                         // ...
  36.                         if (connect_change)
  37.                                 hub_port_connect_change(hub, i,
  38.                                                 portstatus, portchange);
  39.                 } /* end for i */
  40.                 // ...
  41.                 if (!hdev->parent && !hub
复制代码
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

×
回复

使用道具 举报

登录后关闭弹窗

登录参与点评抽奖  加入IT实名职场社区
去登录
快速回复 返回顶部 返回列表