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.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定时器使其再次进入定时器队列
Linux USB Host-Controller的初始化代码框架分析【转】的更多相关文章
- linux USB HOST之EHCI和OHCI【转】
转自:http://blog.csdn.net/ljzcom/article/details/8186914 版权声明:本文为博主原创文章,未经博主允许不得转载. 目录(?)[-] 2 关键数据结 ...
- Using a USB host controller security extension for controlling changes in and auditing USB topology
Protecting computer systems from attacks that attempt to change USB topology and for ensuring that t ...
- Linux usb 3. Host 详解
文章目录 1. 简介 2. Usb Core 驱动设备模型 2.1 Usb Device Layer 2.1.1 device (struct usb_device) 2.1.2 driver (st ...
- 转:USB主机控制器(Host Controller)--深入理解
1. 主机控制器(Host Controller) • UHCI: Universal Host Controller Interface (通用主机控制接口, USB1.0/1.1) • ...
- linux usb驱动记录(一)
一.linux 下的usb驱动框架 在linux系统中,usb驱动可以从两个角度去观察,一个是主机侧,一个是设备侧.linux usb 驱动的总体框架如下图所示: 从主机侧看usb驱动可分为四层: ...
- Security arrangements for extended USB protocol stack of a USB host system
Security arrangements for a universal serial bus (USB) protocol stack of a USB host system are provi ...
- Linux usb 6. HC/UDC 测试
目录 1. 背景介绍 2. Device (gadget zero) 2.1 gadget zero 创建 2.2 SourceSink Function 2.3 Loopback Function ...
- Linux USB驱动框架分析(2)【转】
转自:http://blog.chinaunix.net/uid-23046336-id-3243543.html 看了http://blog.chinaunix.net/uid-11848011 ...
- Linux USB驱动框架分析 【转】
转自:http://blog.chinaunix.net/uid-11848011-id-96188.html 初次接触与OS相关的设备驱动编写,感觉还挺有意思的,为了不至于忘掉看过的东西,笔记跟总结 ...
随机推荐
- BFS和DFS算法
昨晚刚昨晚华为笔试题,用到了BFS和DFS,可惜自己学艺不精,忘记了实现原理,现在借用大佬写的内容给自己做个提高 转自:https://www.jianshu.com/p/70952b51f0c8 图 ...
- 冲刺Two之站立会议6
今天继续了昨天的工作,对视频进行优化.因为昨天的工作没有达到预期的效果,所以又继续对音质和画面质量做了相应的优化.还对相应的聊天室界面进行了优化.
- 作业6小学生四则运算测试APP的NABCD模型
小学生四则运算测试NABCD模型 组员:李新,朱浩龙,叶煜稳,陈俊金,林德麟 (1) N (Need 需求) 需求分析: 四则运算是小学生学习数学的核心和基础,必须经过大量的练习才能熟练掌握,但是一 ...
- Yale数据库上的人脸识别
一.问题分析 1. 问题描述 在Yale数据集上完成以下工作:在给定的人脸库中,通过算法完成人脸识别,算法需要做到能判断出测试的人脸是否属于给定的数据集.如果属于,需要判断出测试的人脸属于数据集中的哪 ...
- kickstart自动化安装
preboot execute environment预启动执行环境--intel开发的技术,计算机可以通过pxe协议从网络引导启动. 工作模式为客户端/服务器端的c/s模式 客户端从远端服务器下载镜 ...
- 【Leetcode】222. Count Complete Tree Nodes
Question: Given a complete binary tree, count the number of nodes. Definition of a complete binary t ...
- php多进程pcntl学习(一)
pcntl在windows下无法使用,linux编译php时加上参数--enable-pcntl 即可.第一次使用pcntl模块,遇到了一些坑也慢慢填上了,这里简单记录下. 1. 子进程之间变量无法共 ...
- Installing OpenSSH from the Settings UI on Windows Server 2019 or Windows 10 1809
Installing OpenSSH from the Settings UI on Windows Server 2019 or Windows 10 1809 OpenSSH client and ...
- Win2019 preview 版本的安装过程
1. 加入 windows insider 协议 登录自己的账号 同意 insder 协议. 然后 https://www.microsoft.com/en-us/software-download/ ...
- 如何使用js判断视频是否可以成功访问
日常工作中会出现各个公司网络不互通的情况,视频如果采用不互通的地址也无法播放,下面方法提供了检测视频是否可以播放的解决方案: 1.跨域 var video = document.createEleme ...