📄 linux设备驱动之usb主机控制器驱动分析-(3)_linux技术文章_linux_操作系统3.htm
字号:
hcd_buffer_destroy(hcd);<BR> return
retval;<BR>}<BR> <BR>经过前面的段式分析,我们对这个函数的流程有了一定的了解.其中有几个函数特别列出,分析如下:<BR>2.1:usb_alloc_dev()的操作<BR>之所以要特别列出分析,是因为这个函数中有很重要的赋值操作.代码如下:<BR>struct
usb_device *usb_alloc_dev(struct usb_device
*parent,<BR>
struct usb_bus *bus, unsigned port1)<BR>{<BR>
struct usb_device *dev;<BR>
//从bus结构,求得usb_hcd<BR> struct usb_hcd *usb_hcd =
container_of(bus, struct usb_hcd, self);<BR> unsigned
root_hub = 0;<BR> <BR> dev = kzalloc(sizeof(*dev),
GFP_KERNEL);<BR> if
(!dev)<BR> return
NULL;<BR> <BR>
//增加hcd的引用计数<BR> if (!usb_get_hcd(bus_to_hcd(bus)))
{<BR>
kfree(dev);<BR> return
NULL;<BR> }<BR> <BR>
//usb_device,内嵌有struct device结构,对这个结构进行初始化<BR>
device_initialize(&dev->dev);<BR> dev->dev.bus
= &usb_bus_type;<BR> dev->dev.type =
&usb_device_type;<BR> dev->dev.dma_mask =
bus->controller->dma_mask;<BR>
set_dev_node(&dev->dev,
dev_to_node(bus->controller));<BR>
//将dev的初始状态置为USB_STATE_ATTACHED.妻示已经连接上了<BR>
dev->state = USB_STATE_ATTACHED;<BR>
atomic_set(&dev->urbnum, 0);<BR> <BR>
//初始化设备的端点0<BR>
INIT_LIST_HEAD(&dev->ep0.urb_list);<BR>
dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;<BR>
dev->ep0.desc.bDescriptorType = USB_DT_ENDPOINT;<BR>
/* ep0 maxpacket comes later, from device descriptor
*/<BR> usb_enable_endpoint(dev,
&dev->ep0);<BR> dev->can_submit =
1;<BR> <BR> /* Save readable and stable topology
id, distinguishing devices<BR> * by location for
diagnostics, tools, driver model, etc. The<BR>
* string is a path along hub ports, from the root. Each
device's<BR> * dev->devpath will be stable
until USB is re-cabled, and hubs<BR> * are often
labeled with these port numbers. The bus_id
isn't<BR> * as stable: bus->busnum
changes easily from modprobe order,<BR> * cardbus
or pci hotplugging, and so on.<BR>
*/<BR> //如果没有父结点,也即该设备是root
hub.usb_device内嵌的dev的父结点指向它的控制器<BR> if
(unlikely(!parent)) {<BR>
dev->devpath[0] =
'0';<BR> <BR>
dev->dev.parent =
bus->controller;<BR>
sprintf(&dev->dev.bus_id[0], "usb%d",
bus->busnum);<BR> root_hub =
1;<BR> } else
{<BR> <BR>
//如果有父结点,就指向其父结点<BR> /* match
any labeling on the hubs; it's one-based
*/<BR> if (parent->devpath[0]
==
'0')<BR>
snprintf(dev->devpath, sizeof
dev->devpath,<BR>
"%d", port1);<BR>
else<BR>
snprintf(dev->devpath, sizeof
dev->devpath,<BR>
"%s.%d", parent->devpath,</P>
<DIV class=ad_f10 id=ad_f10>
<SCRIPT
src="linux设备驱动之USB主机控制器驱动分析-(3)_Linux技术文章_Linux_操作系统3.files/ad_f10.js"></SCRIPT>
</DIV>
<DIV class=ad_f11 id=ad_f11>
<SCRIPT
src="linux设备驱动之USB主机控制器驱动分析-(3)_Linux技术文章_Linux_操作系统3.files/ad_f11.js"></SCRIPT>
</DIV>
<DIV class=kjh>欢迎光临<A href="http://www.diybl.com/" target=_blank><STRONG><FONT
color=#cc0000>DIY部落</FONT></STRONG></A>,<A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/351fsdfetjtk.html"
target=_blank><STRONG><FONT color=#cc0000>点击这里</FONT></STRONG></A>查看更多文章教程 <A
class=redlink
href="javascript:self.location='/user/chm/rar.asp?c_id=144940'">【点击打包该文章】</A></DIV>
<DIV class=zh><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940.html">[1]</A><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940_2.html">
[2]</A> [3] <A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940_4.html">[4]</A><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940_5.html">
[5]</A><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940_6.html">
[6]</A><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940_7.html">
[7]</A><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940_8.html">
[8]</A><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940_9.html">
[9]</A><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940_10.html">
[10]</A><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940_11.html">
[11]</A><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/course/6_system/linux/Linuxjs/2008923/144939.html"><SPAN
style="DISPLAY: none">'zh'</SPAN></A><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940_12.html">
[12]</A><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940_13.html">
[13]</A></DIV></DIV>
<DIV class=ad_f4 id=ad_f4>
<SCRIPT
src="linux设备驱动之USB主机控制器驱动分析-(3)_Linux技术文章_Linux_操作系统3.files/ad_f4.js"></SCRIPT>
</DIV>
<DIV class=mediacontent>如果图片或页面不能正常显示请<A class=redlink
onmouseover="this.style.cursor='hand';"
onclick="openerror('144940','linux设备驱动之USB主机控制器驱动分析');">点击这里</A> 站内搜索: <INPUT
maxLength=255 size=25 name=wd3> <INPUT onclick=tosearch(document.all.wd3); type=button value=千寻搜索></DIV>
<DIV style="CLEAR: both" align=center></DIV>
<DIV class=toollinks>【<A
href="javascript:window.external.addFavorite(window.location,'linux设备驱动之USB主机控制器驱动分析-DIY部落');">收藏此页</A>】【<A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/351fsdfetjtk.html"
target=_blank>栏目页面</A>】【<A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940_3.html#comment">发表评论</A>】【<A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940_3.html#">返回顶部</A>】【<A
href="javascript:window.close()">关闭</A>】 </DIV>
<DIV class=p_bottom>上一篇文章:<A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144941.html">
Linux 启动脚本 完全注释2 --- rc脚本注释</A><BR>下一篇文章:<A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144939.html">Rsync命令参数详解</A></DIV></DIV>
<DIV style="CLEAR: both; BACKGROUND: #fff; OVERFLOW: hidden; HEIGHT: 8px"></DIV>
<DIV id=links align=center>
<TABLE class=xgzt cellSpacing=0 cellPadding=0 width=687>
<TBODY>
<TR>
<TD style="PADDING-LEFT: 5px" bgColor=#e1effa>
<H3>推荐文章</H3></TD></TR>
<TR>
<TD bgColor=#fcfeff>
<DIV class="tj_l tj"><NOBR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008717/133380.html"
target=_blank>linux基础知识</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008813/135778.html"
target=_blank>建立本地的软件源</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/20071114/86222.html"
target=_blank>Linux那些事儿之我是UHCI(18)Root Hub的控制传输(二)</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2007126/90947.html"
target=_blank>在Ubuntu下安装VMware Tools的方法</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/200899/141040.html"
target=_blank>QMAIL 主要配置文件说明一下</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/200868/123613.html"
target=_blank>ARM9与ARM7的比较及优化</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/20071226/94071.html"
target=_blank>2008年:中小企业与自由软件相互拥抱</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144868.html"
target=_blank>进程内存结构</A></DIV>
<DIV class="tj_r tj"><NOBR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/20071129/88943.html"
target=_blank>几种主要的Linux版本之间的比较</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008813/135797.html"
target=_blank>运行级切换和门</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2007926/73955.html"
target=_blank>Linux环境下的基本备份方法</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/20071027/80338.html"
target=_blank>linux环境下挂载(mount)USB设备</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/200798/70542.html"
target=_blank>linux书籍推荐</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/200861/119152.html"
target=_blank>如何成为一个Linux系统内核开发者</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/20071114/86120.html"
target=_blank>启动不了redhat 9的图形界面的解决办法</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/200868/123642.html"
target=_blank>Linux的高级路由和流量控制HOWTO中文版</A></DIV></NOBR></TD></TR></TBODY></TABLE></DIV>
<DIV style="CLEAR: both; BACKGROUND: #fff; OVERFLOW: hidden; HEIGHT: 8px"></DIV>
<DIV class=cleanblock2
style="BORDER-RIGHT: #dedfde 1px solid; BORDER-TOP: #dedfde 1px solid; BACKGROUND: #ededed; BORDER-LEFT: #dedfde 1px solid; BORDER-BOTTOM: #dedfde 1px solid">
<H3>文章评论</H3></DIV>
<DIV class=cleanblock3><IFRAME class=comm_index name=pindex
src="linux设备驱动之USB主机控制器驱动分析-(3)_Linux技术文章_Linux_操作系统3.files/CAY34PAZ.htm"
frameBorder=false width="100%" scrolling=no
onload="window.setTimeout('iframe_resize()',1000)" height=0></IFRAME></DIV>
<DIV style="CLEAR: both; BACKGROUND: #fff; OVERFLOW: hidden; HEIGHT: 8px"></DIV>
<FORM style="MARGIN-TOP: 0px"
action=/user/comment.asp?id=144940&url=http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940.html
method=post>
<DIV class=comment_1>
<DIV class=cleanblock2><A name=comment></A>
<H3>请您留言</H3></DIV>
<DIV class=cleanblock style="PADDING-RIGHT: 20px; PADDING-LEFT: 20px"><LABEL
for=label>昵称: <INPUT onclick=this.focus();this.select() maxLength=20 size=15
value=DIY部落网友 name=hypocorism> <A
href="http://www.diybl.com/user/register.asp" target=_blank><FONT
color=red>注册会员</FONT></A> <A href="http://www.diybl.com/user/login.asp"
target=_blank>会员登陆</A> <BR><SPAN style="LINE-HEIGHT: 25px"><A
href="http://www.diybl.com/user/chgpage/cata.asp?num=1060103"
target=_blank><FONT color=#990000><STRONG>点击这里</STRONG></FONT></A></SPAN>
自己制作打包的chm电子书教程 <TEXTAREA style="VERTICAL-ALIGN: text-top; WIDTH: 100%; HEIGHT: 7em" onfocus=showchk(); name=content rows=6></TEXTAREA>
<LABEL id=checkCode style="DISPLAY: none">验证: <INPUT maxLength=5 size=8
name=loginnum> <IMG id=codeImg
style="VERTICAL-ALIGN: middle; CURSOR: pointer; HEIGHT: 18px"
onclick="this.src='/user/getcode.asp?t='+Math.random()" alt=验证码,看不清楚?请点击刷新验证码
src=""> </LABEL> <INPUT class=btn_2k3 style="MARGIN-TOP: 8px" type=submit value=发表评论>
</DIV></DIV>
<DIV class=comment_1
style="FLOAT: left; MARGIN-LEFT: 6px; WIDTH: 313px; HEIGHT: 90px">
<DIV class=cleanblock2>
<H3>网友推荐文章</H3></DIV>
<DIV class=cleanblock>
<TABLE cellSpacing=0 cellPadding=0 width="100%">
<TBODY>
<TR>
<TD style="PADDING-RIGHT: 15px">
<UL>
<LI><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2007114/84023.html"
target=_blank>NetBeans与SCIM的冲突解决</A></LI>
<LI><A
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -