Linux USB Host-Controller的初始化代码框架分析【转】

简介: 转自:http://blog.csdn.net/zkami/article/details/2496770 usb_hcd_omap_probe (const struct hc_driver *driver) (dev/ohci/ohci-omap.

转自:http://blog.csdn.net/zkami/article/details/2496770

usb_hcd_omap_probe (const struct hc_driver *driver) (dev/ohci/ohci-omap.c)
在模块初始化时被platform_driver_register()调用,用来初始化与ohci_hcd_omap_driver
相匹配的usb主控制器.
->usb_create_hcd(driver);   创建一个代表host-controller的数据结构(struct usb_hcd)并初始化 core/hcd.h 
        ->hcd = kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL); 为struct usb_hcd分配一块内存  
        ->usb_bus_init (struct usb_bus *bus); (hcd.c) 初始化代表usb bus的数据结构(struct usb_bus)
        ->初始化struct usb_hcd的定时器,工作队列
->填充struct usb_hcd的rsrc_start字段:host-controller memory/io的起始物理地址
    rsrc_len字段:host-controller memory/io的长度
    regs字段:host-controller memory/io映射的内核虚拟地址。
->ohci_hcd_init(struct ohci_hcd *ohci);    (dev/ohci/ohci-mem.c)
->usb_add_hcd(struct usb_hcd *hcd,unsigned int irqnum, unsigned long irqflags)    (/core/hcd.h)
    完成struct usb_hcd剩余的初始化工作
        ->hcd_buffer_create(hcd):创建dmapool
        ->usb_register_bus(usb_bus):注册usb bus
        ->usb_alloc_dev(NULL, &hcd->self, 0): (core/usb.c)
            处理主控制器hcd上的根Hub(hcd->self.root_hub),这里做的就是为Root Hub申请了一个struct                usb_device结构体,并且初始化, 将返回值赋给指针rhdev. Root Hub的parent指针指向了Controller本身.
        ->ohci_omap_init:完成omap硬件的init工作  
            ->otg_get_transceiver();
            ->otg_set_host(ohci->transceiver, &ohci_to_hcd(ohci)->self);    
                针对OTG特性进行的初始化,后面分析
            ->ohci_init(struct ohci_hcd *ohci); (host/ohci-hcd.c)
                    ->为ohci->hcca分配空间
                    ->ohci_mem_init() 创建ohci->td_cache和ohci->ed_cache的dma_pool
        ->request_irq(irqnum, &usb_hcd_irq, irqflags,hcd->irq_descr, hcd)
           注册中断处理函数.其中中断号是irqnum, 中断服务程序是usb_hcd_irq(struct usb_hcd *hcd) (ohci-hcd.c).
           根据usb2.0 spec定义的中断类型有:usb_hcd_irq()根据具体类型执行相应操作,后面分析.
           #define OHCI_INTR_SO    (1 << 0)    /* scheduling overrun */
           #define OHCI_INTR_WDH    (1 << 1)    /* writeback of done_head */
           #define OHCI_INTR_SF    (1 << 2)    /* start frame */
           #define OHCI_INTR_RD    (1 << 3)    /* resume detect */
           #define OHCI_INTR_UE    (1 << 4)    /* unrecoverable error */
           #define OHCI_INTR_FNO    (1 << 5)    /* frame number overflow */
           #define OHCI_INTR_RHSC    (1 << 6)    /* root hub status change */
           #define OHCI_INTR_OC    (1 << 30)    /* ownership change */
           #define OHCI_INTR_MIE    (1 << 31)    /* master interrupt enable */
        ->ohci_omap_start(struct usb_hcd *hcd):启动OHCI
              ->ohci_run(struct ohci_hcd *ohci) (ohci-hcd.c)
                  Start an OHCI controller, set the BUS operational resets USB and controller
                  enable interrupts 根据spec写相应寄存器来启动OHCI HC
              ->ohci_stop(struct usb_hcd *hcd)
                  ohci_run失败的话,释放一些资源和已申请的中断, 释放ohci的ed/td cache以及ohci-hcca
        ->register_root_hub(struct usb_hcd) (core/hcd.c)
              ->usb_set_device_state(usb_device, usb_device_state)
                 是roothub的话仅将new_state赋给udev->state,否则根据usb_device_state作不同处理
              ->usb_get_device_descriptor(usb_dev, USB_DT_DEVICE_SIZE) 获取roothub的设备描述符
                      ->usb_get_descriptor(dev, USB_DT_DEVICE, 0, desc, size);返回设备描述符,后面分析
              ->usb_new_device(usb_dev)       配置并注册usb设备 (hub.c)
                      ->usb_configure_device(udev); (hub.c)    读取设备的配置信息
                          ->usb_get_configuration(udev);
                          ->usb_cache_string() 读取设备以下三个信息(字符描述符):product, manufacturer, serial
                          ->usb_configure_device_otg(udev);
                      ->usb_autoresume_device(udev->parent);  建立usb设备的父子关系
                      ->device_add(&udev->dev);   
                         注册usb设备: 将设备加载到总线上(添加到总线的设备队列中),并为该设备搜索与之匹配的驱动
                      ->usb_set_device_state(udev, USB_STATE_NOTATTACHED);
              ->usb_hc_died (hcd);
        ->usb_hcd_poll_rh_status(usb_hcd)    hcd.c
            获取“根Hub状态变化”的具体信息,并将该信息递交给usb_hcd->status_urb
                ->ohci_hub_status_data(usb_hcd, buf)
                    首先: 读取根Hub"状态变化信息",并将其存放于buffer中
                      ->ohci_root_hub_state_changes(ohci, changed, any_connected);
                      根据主控制器在设备接入前的状态(如SUSPEND),将主控制器状态设置为中断发生后的下一状态(如OPERATION), 并判断根Hub是否需要继续轮询(poll_rh等于表示需要继续轮询)
                          ->ohci_rh_suspend(ohci, 1);  pm方面以后分析
                          ->ohci_rh_resume(ohci);      pm方面以后分析
                          ->usb_hcd_resume_root_hub(ohci_to_hcd(ohci));    pm方面以后分析
                    然后: 将保存于buffer中的root hub"状态变化信息"传递给usb_hcd->status_urb并将该urb提交给root hub驱动层
                -> usb_hcd_unlink_urb_from_ep()
                -> usb_hcd_giveback_urb()
                -> mod_timer() 调整roothub定时器使其再次进入定时器队列

【作者】 张昺华
【新浪微博】 张昺华--sky
【twitter】 @sky2030_
【facebook】 张昺华 zhangbinghua
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
目录
相关文章
|
2月前
|
Linux Android开发
嵌入式linux中Framebuffer 驱动程序框架分析
嵌入式linux中Framebuffer 驱动程序框架分析
33 0
|
2月前
|
Linux C语言 SoC
嵌入式linux总线设备驱动模型分析
嵌入式linux总线设备驱动模型分析
33 1
|
2月前
|
Linux
嵌入式linux系统设备树实例分析
嵌入式linux系统设备树实例分析
48 0
|
2月前
|
监控 Shell Linux
【Shell 命令集合 网络通讯 】Linux 分析串口的状态 statserial命令 使用指南
【Shell 命令集合 网络通讯 】Linux 分析串口的状态 statserial命令 使用指南
34 0
|
4月前
|
安全 Linux 编译器
内存泄漏检测组件的分析与实现(linux c)-mtrace工具使用
内存泄漏产生原因 在堆上使用malloc/remalloc/calloc分配了内存空间,但是没有使用free释放对应的空间。
78 0
|
4月前
|
监控 Linux 编译器
多线程死锁检测的分析与实现(linux c)-有向图的应用
在日常的软件开发中,多线程是不可避免的,使用多线程中的一大问题就是线程对锁的不合理使用造成的死锁,死锁一旦发生,将导致多线程程序响应时间长,吞吐量下降甚至宕机崩溃,那么如何检测出一个多线程程序中是否存在死锁呢?在提出解决方案之前,先对死锁产生的原因以及产生的现象做一个分析。最后在用有向环来检测多线程中是否存在死锁的问题。
58 0
|
4月前
|
存储 安全 Linux
linux系统中u-boot命令的EMMC和SD卡操作命令分析
linux系统中u-boot命令的EMMC和SD卡操作命令分析
136 1
|
6天前
|
缓存 Linux
linux性能分析之内存分析(free,vmstat,top,ps,pmap等工具使用介绍)
这些工具可以帮助你监视系统的内存使用情况、识别内存泄漏、找到高内存消耗的进程等。根据具体的问题和需求,你可以选择使用其中一个或多个工具来进行内存性能分析。注意,内存分析通常需要综合考虑多个指标和工具的输出,以便更好地理解系统的行为并采取相应的优化措施。
27 6
|
19天前
|
监控 Linux 测试技术
性能分析之Linux系统平均负载案例分析
【4月更文挑战第20天】在上文性能基础之理解Linux系统平均负载和CPU使用率中,我们详细介绍了 Linux 系统平均负载的相关概念,本文我们来做几个案例分析,以达到加深理解。
41 2
性能分析之Linux系统平均负载案例分析
|
22天前
|
数据可视化 数据挖掘 Linux
如何在Linux部署DataEase数据分析服务并实现无公网IP远程分析内网数据信息
如何在Linux部署DataEase数据分析服务并实现无公网IP远程分析内网数据信息