⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 linux设备驱动之usb主机控制器驱动分析-(12)_linux技术文章_linux_操作系统12.htm

📁 linux设备驱动之USB主机控制器驱动分析
💻 HTM
📖 第 1 页 / 共 3 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from url=(0073)http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940_12.html -->
<HTML><HEAD><TITLE>linux设备驱动之USB主机控制器驱动分析-(12)_Linux技术文章_Linux_操作系统</TITLE>
<META http-equiv=Content-Type content=text/html;charset=gb2312>
<META content=www.diybl.com,DIY部落版权所有 name=Copyright>
<META content=linux设备驱动之USB主机控制器驱动分析_Linux技术文章_Linux_操作系统 name=keywords>
<META 
content="linux设备驱动之USB主机控制器驱动分析_Linux技术文章_160; alt->endpoint = kzalloc(len, GFP_KERNEL);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;.." 
name=description>
<META content=index,follow name=robots>
<META content=INDEX,FOLLOW name=GOOGLEBOT><LINK href="article2.css" 
type=text/css rel=stylesheet><LINK 
href="linux设备驱动之USB主机控制器驱动分析-(12)_Linux技术文章_Linux_操作系统12.files/article2.css" 
type=text/css rel=stylesheet>
<SCRIPT 
src="linux设备驱动之USB主机控制器驱动分析-(12)_Linux技术文章_Linux_操作系统12.files/article.js" 
type=text/javascript></SCRIPT>

<SCRIPT 
src="linux设备驱动之USB主机控制器驱动分析-(12)_Linux技术文章_Linux_操作系统12.files/1060103.js" 
type=text/javascript></SCRIPT>

<META content="MSHTML 6.00.2900.3395" name=GENERATOR></HEAD>
<BODY><INPUT type=hidden value=144940 name=passage_id><INPUT type=hidden 
value=1060103 name=catalog_id> 
<DIV id=wrap>
<DIV class=top_bar align=center>
<TABLE cellSpacing=0 width=935>
  <TBODY>
  <TR>
    <TD><A href="http://www.diybl.com/">网站首页</A></TD>
    <TD class=top_bar_sline></TD>
    <TD><A href="http://news.diybl.com/" target=_blank>新闻首页</A></TD>
    <TD class=top_bar_sline></TD>
    <TD><A href="http://www.diybl.com/course/1_web/">网页设计</A></TD>
    <TD class=top_bar_sline></TD>
    <TD><A href="http://www.diybl.com/course/2_picdesign/">图形动画</A></TD>
    <TD class=top_bar_sline></TD>
    <TD><A href="http://www.diybl.com/course/3_program/">软件编程</A></TD>
    <TD class=top_bar_sline></TD>
    <TD><A href="http://www.diybl.com/course/4_webprogram/">网站开发</A></TD>
    <TD class=top_bar_sline></TD>
    <TD><A href="http://www.diybl.com/course/5_office/">办公软件</A></TD>
    <TD class=top_bar_sline></TD>
    <TD><A href="http://www.diybl.com/course/6_system/">操作系统</A></TD>
    <TD class=top_bar_sline></TD>
    <TD><A href="http://www.diybl.com/course/7_databases/">数据库</A></TD>
    <TD class=top_bar_sline></TD>
    <TD><A href="http://www.diybl.com/course/webjsh/">网络技术</A></TD>
    <TD class=top_bar_sline></TD>
    <TD><A href="http://www.diybl.com/course/comshiti/">认证考试</A></TD>
    <TD class=top_bar_sline></TD>
    <TD><A href="http://www.diybl.com/course/fwzl/">范文资料</A></TD>
    <TD class=top_bar_sline></TD>
    <TD><A href="http://www.diybl.com/course/hack/">黑客攻防</A></TD>
    <TD class=top_bar_sline></TD>
    <TD><A href="http://www.diybl.com/chm/" target=_blank><FONT 
      color=red>书籍教程</FONT></A></TD>
    <TD class=top_bar_sline></TD>
    <TD><A href="http://bbs.diybl.com/" 
target=_blank>进入论坛</A></TD></TR></TBODY></TABLE></DIV>
<TABLE class=adNone id=PublicRelation cellSpacing=0 cellPadding=0 width=950 
border=0>
  <TBODY>
  <TR>
    <TD vAlign=top width=864>
      <DIV class=logo><A href="http://www.diybl.com/" target=_blank><IMG 
      height=60 
      src="linux设备驱动之USB主机控制器驱动分析-(12)_Linux技术文章_Linux_操作系统12.files/logo.gif" 
      width=200></A></DIV>
      <DIV class=ad_f1 id=ad_f1>
      <SCRIPT 
      src="linux设备驱动之USB主机控制器驱动分析-(12)_Linux技术文章_Linux_操作系统12.files/ad_f1.js"></SCRIPT>
      </DIV><!--<div class="top_bar2">-->
      <UL class=menu>
        <LI><A href="http://www.diybl.com/course/6_system/linux/" 
        target=_blank><SPAN>Linux</SPAN></A>
        <LI><A href="http://www.diybl.com/course/6_system/linux/Linuxxl/" 
        target=_blank><SPAN>Linux系列教程</SPAN></A>
        <LI><A href="http://www.diybl.com/course/6_system/linux/linuxjq/" 
        target=_blank><SPAN>Linux应用技巧</SPAN></A>
        <LI><A 
        href="http://www.diybl.com/course/6_system/linux/Linuxjs/49d5sdf.html" 
        target=_blank><SPAN>Linux技术文章</SPAN></A></LI></UL><!--</div>--></TD>
    <TD width=6></TD>
    <TD vAlign=top align=middle width=100>
      <DIV class=hotNCout>
      <DIV class=hotNC>
      <UL>
        <LI><A 
        href="javascript:window.external.addFavorite('http://www.diybl.com/','DIY部落');">加入收藏</A> 

        <LI><A href="http://www.diybl.com/map.html" target=_blank>网站地图</A> 
        <LI><A href="http://www.diybl.com/chm/" target=_blank>书籍教程</A> 
        <LI><A href="http://www.diybl.com/user/register.asp" 
        target=_blank>会员注册</A> </LI></UL></DIV></DIV></TD></TR></TBODY></TABLE>
<DIV class=split style="HEIGHT: 3px"></DIV>
<DIV class=ad_ftop id=ad_ftop>
<SCRIPT 
src="linux设备驱动之USB主机控制器驱动分析-(12)_Linux技术文章_Linux_操作系统12.files/ad_ftop.js"></SCRIPT>
</DIV>
<DIV class=subNav>
<DIV style="FLOAT: right"><INPUT name=wd1> <INPUT onclick=tosearch(document.all.wd1); type=button value=" 千寻搜索 "></DIV><SPAN><A 
href="http://www.diybl.com/">DIY部落</A> &gt;&gt; <A 
href="http://www.diybl.com/course/6_system/">操作系统</A> &gt;&gt; <A 
href="http://www.diybl.com/course/6_system/linux/">Linux</A> &gt;&gt; <A 
href="http://www.diybl.com/course/6_system/linux/Linuxjs/49d5sdf.html">Linux技术文章</A> 
&gt;&gt; 正文</SPAN></DIV>
<DIV class=split></DIV>
<DIV class=main>
<DIV class=lc_blue>
<DIV class=lcBlk>
<H1>linux设备驱动之USB主机控制器驱动分析</H1>
<DIV class=from_info>http://www.diybl.com/ 2008-9-23  网络 点击:<SPAN 
style="FONT-WEIGHT: bold; COLOR: #ff0000">
<SCRIPT 
src="linux设备驱动之USB主机控制器驱动分析-(12)_Linux技术文章_Linux_操作系统12.files/p_count.htm" 
lanuage="javascript"></SCRIPT>
 </SPAN> <A 
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940_12.html#comment">[ 
评论 ]</A></DIV>
<DIV class=artibody>
<DIV class=ad_f2 id=ad_f2>
<SCRIPT 
src="linux设备驱动之USB主机控制器驱动分析-(12)_Linux技术文章_Linux_操作系统12.files/ad_f2.js"></SCRIPT>
</DIV>
<DIV class=ad_f3 id=ad_f3>
<SCRIPT 
src="linux设备驱动之USB主机控制器驱动分析-(12)_Linux技术文章_Linux_操作系统12.files/ad_f3.js"></SCRIPT>
</DIV>文章搜索: <INPUT maxLength=255 size=30 name=wd2> &nbsp;&nbsp; <INPUT onclick=tosearch(document.all.wd2); type=button value=千寻搜索><A 
class=redlink 
href="javascript:self.location='/user/chm/rar.asp?c_id=48375'">【点击打包该文章】</A>
<SCRIPT 
src="linux设备驱动之USB主机控制器驱动分析-(12)_Linux技术文章_Linux_操作系统12.files/art_top.js"></SCRIPT>
 
<P>160; alt-&gt;endpoint = kzalloc(len, 
GFP_KERNEL);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if 
(!alt-&gt;endpoint)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return -ENOMEM;<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
}<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp; /* Parse all the endpoint descriptors 
*/<BR>&nbsp;&nbsp;&nbsp;&nbsp; n = 0;<BR>&nbsp;&nbsp;&nbsp;&nbsp; while (size 
&gt; 0) {<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if (((struct 
usb_descriptor_header *) 
buffer)-&gt;bDescriptorType<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp;&nbsp; == 
USB_DT_INTERFACE)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
break;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; retval = 
usb_parse_endpoint(ddev, cfgno, inum, asnum, 
alt,<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
num_ep, buffer, size);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if 
(retval &lt; 
0)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
return retval;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
++n;<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; buffer += 
retval;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; size -= 
retval;<BR>&nbsp;&nbsp;&nbsp;&nbsp; }<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp; if 
(n != num_ep_orig)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
dev_warn(ddev, "config %d interface %d altsetting %d has %d 
"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
"endpoint descriptor%s, different from the interface 
"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
"descriptor's value: %d\n",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; cfgno, inum, asnum, n, plural(n), 
num_ep_orig);<BR>&nbsp;&nbsp;&nbsp;&nbsp; return buffer - 
buffer0;<BR>&nbsp;<BR>skip_to_next_interface_descriptor:<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
i = find_next_descriptor(buffer, size, 
USB_DT_INTERFACE,<BR>&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
USB_DT_INTERFACE, NULL);<BR>&nbsp;&nbsp;&nbsp;&nbsp; return buffer - buffer0 + 
i;<BR>}<BR>usb_parse_endpoint()代码如下:<BR>static int usb_parse_endpoint(struct 
device *ddev, int cfgno, int inum,<BR>&nbsp;&nbsp;&nbsp; int asnum, struct 
usb_host_interface *ifp, int num_ep,<BR>&nbsp;&nbsp;&nbsp; unsigned char 
*buffer, int size)<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp; unsigned char *buffer0 = 
buffer;<BR>&nbsp;&nbsp;&nbsp;&nbsp; struct usb_endpoint_descriptor 
*d;<BR>&nbsp;&nbsp;&nbsp;&nbsp; struct usb_host_endpoint 
*endpoint;<BR>&nbsp;&nbsp;&nbsp;&nbsp; int n, i, 
j;<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp; d = (struct usb_endpoint_descriptor *) 
buffer;<BR>&nbsp;&nbsp;&nbsp;&nbsp; buffer += 
d-&gt;bLength;<BR>&nbsp;&nbsp;&nbsp;&nbsp; size -= 
d-&gt;bLength;<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
//判断长度是否合法<BR>&nbsp;&nbsp;&nbsp;&nbsp; if (d-&gt;bLength &gt;= 
USB_DT_ENDPOINT_AUDIO_SIZE)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
n = USB_DT_ENDPOINT_AUDIO_SIZE;<BR>&nbsp;&nbsp;&nbsp;&nbsp; else if 
(d-&gt;bLength &gt;= 
USB_DT_ENDPOINT_SIZE)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; n = 
USB_DT_ENDPOINT_SIZE;<BR>&nbsp;&nbsp;&nbsp;&nbsp; else 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dev_warn(ddev, "config %d 
interface %d altsetting %d has an 
"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
"invalid endpoint descriptor of length %d, 
skipping\n",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; cfgno, inum, asnum, 
d-&gt;bLength);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto 
skip_to_next_endpoint_or_interface_descriptor;<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
}<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
//取得端点的地址,也就是端口号<BR>&nbsp;&nbsp;&nbsp;&nbsp; i = d-&gt;bEndpointAddress &amp; 
~USB_ENDPOINT_DIR_MASK;<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
//不可能会超16个端点,也不可能<BR>&nbsp;&nbsp;&nbsp;&nbsp; if (i &gt;= 16 || i == 0) 
{<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dev_warn(ddev, "config %d 
interface %d altsetting %d has an 
"<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; 
"invalid endpoint with address 0x%X, 
skipping\n",<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
&nbsp;&nbsp;&nbsp; cfgno, inum, asnum, 
d-&gt;bEndpointAddress);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
goto skip_to_next_endpoint_or_interface_descriptor;<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
}<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp; /* Only store as many endpoints as we 
have room for */<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
//注意在前面调用函数中已经将ifp-&gt;desc.bNumEndpoints清0了,以后每处理<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
//一个端点描述符,都会将这个成员值+1<BR>&nbsp;&nbsp;&nbsp;&nbsp; if (ifp-&gt;desc.bNumEndpoints 
&gt;= num_ep)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goto 
skip_to_next_endpoint_or_interface_descriptor;<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
//保存端点描述符信息,并更新端点数目<BR>&nbsp;&nbsp;&nbsp;&nbsp; endpoint = 
&amp;ifp-&gt;endpoint[ifp-&gt;desc.bNumEndpoints];<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
++ifp-&gt;desc.bNumEndpoints;<BR>&nbsp;<BR>&nbsp;&nbsp;&nbsp;&nbsp; 
memcpy(&amp;endpoint-&gt;desc, d, n);<BR>&nbsp;&nbsp;&nbsp;&nbsp; 

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -