?? linux設(shè)備驅(qū)動之usb主機控制器驅(qū)動分析-(2)_linux技術(shù)文章_linux_操作系統(tǒng)2.htm
字號:
bus_name:OHCI對應(yīng)的pci_dev的name<BR> <BR>在這里,注意一下hcd內(nèi)存的分配.如下示:<BR>hcd =
kzalloc(sizeof(*hcd) + driver->hcd_priv_size, GFP_KERNEL);<BR>我們知道,struct
usb_hcd是一個位于usb_core下的東東,這個東東所有的host control都會用到.那么hcd就有一個私有區(qū)結(jié)構(gòu),用來表示host
control之間不同的數(shù)據(jù)結(jié)構(gòu).而其它們相同的結(jié)構(gòu)保存在struct usb_hcd中.這個hcd_priv成員在struct
usb_hcd被定義成了0項數(shù)組的形式,而大小則是由hc_driver的hcd_priv_size項來指定的.<BR> <BR>struct
usb_hcd結(jié)構(gòu)很龐大.這里不方便將其全部列出.只來說明一下在這里會用到的成員:<BR>1:self成員: 我們可以這想思考.每條USB總線上只有一個host
control.每個host control都對應(yīng)著一條總線. 這個self成員就是表示hcd所對應(yīng)的USB總線.
self.controller表示該總線上的控制器,也就是UHCI對應(yīng)的pci_dev中封裝的struct device. Self.
bus_name表示該總線的名稱.也就是OHCI對應(yīng)的pci_dev的名稱.self. uses_dma來表示該總線上的控制器是否使用DMA<BR>2:
rh_timer成員:該成員是一個定時器,用來輪詢控制器的根集線器的狀態(tài)改變,通常用做電源管理.在這里不加詳分析.<BR>2:
driver成員:表示該hcd對應(yīng)驅(qū)動.<BR>總而言之,
usb_create_hcd就是對hcd的各項成員賦值.<BR> <BR>相比之下usb_add_hcd()的代碼就比較繁雜了.下面以分段的形式分析如下:<BR>int
usb_add_hcd(struct usb_hcd
*hcd,<BR> unsigned int irqnum,
unsigned long irqflags)<BR>{<BR> int
retval;<BR> struct usb_device
*rhdev;<BR> <BR> dev_info(hcd->self.controller,
"%s\n", hcd->product_desc);<BR> <BR>
hcd->authorized_default = hcd->wireless? 0 :
1;<BR> set_bit(HCD_FLAG_HW_ACCESSIBLE,
&hcd->flags);<BR> <BR> /* HC is in reset
state, but accessible. Now do the one-time
init,<BR> * bottom up so that hcds can customize
the root hubs before khubd<BR> * starts talking to
them. (Note, bus id is assigned early too.)<BR>
*/<BR> //創(chuàng)建pool<BR>
if ((retval = hcd_buffer_create(hcd)) != 0)
{<BR>
dev_dbg(hcd->self.controller, "pool alloc
failed\n");<BR> return
retval;<BR> }<BR>在我們分析的流程中,
Hcd->wireless默認為0.相應(yīng)的hcd->authorized_default也被置為了0.然后將hcd->flags置為HCD_FLAG_HW_ACCESSIBLE.表示該USB控制器是可以訪問的.最后在hcd_buffer_create中,因為hc_driver的flags標志被末置HCD_LOCAL_MEM.該函數(shù)在這里什么都不做就返回0了.<BR> <BR>
//注冊usb_bus<BR> if ((retval =
usb_register_bus(&hcd->self)) <
0)<BR> goto
err_register_bus;<BR> <BR> //分配并初始化root
hub<BR> if ((rhdev = usb_alloc_dev(NULL,
&hcd->self, 0)) == NULL)
{<BR>
dev_err(hcd->self.controller, "unable to allocate root
hub\n");<BR> retval =
-ENOMEM;<BR> goto
err_allocate_root_hub;<BR> }<BR>
//OHCI定義于usb1.1只能支持全速<BR> rhdev->speed =
(hcd->driver->flags & HCD_USB2) ? USB_SPEED_HIGH
:<BR>
USB_SPEED_FULL;<BR> hcd->self.root_hub =
rhdev;<BR> <BR> /* wakeup flag init defaults to
"everything works" for root hubs,<BR> * but
drivers can override it in reset() if needed, along
with<BR> * recording the overall controller's
system wakeup capability.<BR>
*/<BR> device_init_wakeup(&rhdev->dev,
1);<BR>在前面.我們看到了在hcd的self成員的賦值過程,而所有的總線信息都要保存在一個地方,在其它的地方會用到這些總線信息.所以usb_register_bus()對應(yīng)的工作就是在全局變量busmap的位圖中找到?jīng)]有被使用的位做為usb_bus的序號(我們暫且稱呼它為USB總線號).然后為該總線注冊一個屬于usb_host_class類的設(shè)備.以后在/sys/class/host中就可以看到該bus對應(yīng)的目錄了.最后,將總線鏈接到usb_bus_list鏈表中.<BR>然后,每一個USB控制器都有一個根集線器.這里也要為總線下的根集錢器創(chuàng)建相應(yīng)的結(jié)構(gòu),
usb_alloc_dev()用來生成并初始化的usb_device結(jié)構(gòu).這個函數(shù)比較重要,在后面給出這個函數(shù)的詳細分析.<BR>因為OHCI是USB1.1的設(shè)備,所以,根集線器的speed會被定義成USB_SPEED_FULL(全速).最后將這個根集線器關(guān)聯(lián)到總線中.<BR>device_init_wakeup(&rhdev->dev,
1)是和總線相關(guān)的,忽略它吧 :-)<BR> /* "reset" is misnamed; its role
is now one-time init. the controller<BR> * should
already have been reset (and boot firmware kicked off
etc).<BR> */<BR> if
(hcd->driver->reset && (retval = hcd->driver->reset(hcd))
< 0) {<BR>
dev_err(hcd->self.controller,</P>
<DIV class=ad_f10 id=ad_f10>
<SCRIPT
src="linux設(shè)備驅(qū)動之USB主機控制器驅(qū)動分析-(2)_Linux技術(shù)文章_Linux_操作系統(tǒng)2.files/ad_f10.js"></SCRIPT>
</DIV>
<DIV class=ad_f11 id=ad_f11>
<SCRIPT
src="linux設(shè)備驅(qū)動之USB主機控制器驅(qū)動分析-(2)_Linux技術(shù)文章_Linux_操作系統(tǒng)2.files/ad_f11.js"></SCRIPT>
</DIV>
<DIV class=kjy><STRONG>文章整理:</STRONG><A href="http://www.diybl.com/"
target=_blank><STRONG><FONT color=#cc0000>DIY部落</FONT></STRONG></A>
<STRONG>http://www.diybl.com</STRONG> (本站) <A class=redlink
href="javascript:self.location='/user/chm/rar.asp?c_id=144940'">【點擊打包該文章】</A></DIV>
<DIV class=klkl><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/course/6_system/linux/Linuxjs/2008923/144939.html"><SPAN
style="DISPLAY: none">'klkl'</SPAN></A> [2] <A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940_3.html">[3]</A><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/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設(shè)備驅(qū)動之USB主機控制器驅(qū)動分析-(2)_Linux技術(shù)文章_Linux_操作系統(tǒng)2.files/ad_f4.js"></SCRIPT>
</DIV>
<DIV class=mediacontent>如果圖片或頁面不能正常顯示請<A class=redlink
onmouseover="this.style.cursor='hand';"
onclick="openerror('144940','linux設(shè)備驅(qū)動之USB主機控制器驅(qū)動分析');">點擊這里</A> 站內(nèi)搜索: <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設(shè)備驅(qū)動之USB主機控制器驅(qū)動分析-DIY部落');">收藏此頁</A>】【<A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/6a44sdetjoktk.html"
target=_blank>欄目頁面</A>】【<A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940_2.html#comment">發(fā)表評論</A>】【<A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144940_2.html#">返回頂部</A>】【<A
href="javascript:window.close()">關(guān)閉</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命令參數(shù)詳解</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/2008814/135944.html"
target=_blank>桌面Linux系統(tǒng)優(yōu)化</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008821/136822.html"
target=_blank>Vi的基本命令</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/20071027/80317.html"
target=_blank>終于搞定了X~</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2007930/75354.html"
target=_blank>撥開云霧:Lastlog文件不斷變大的原因</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2007917/71731.html"
target=_blank>9月15日,我們爬山去</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2007126/90911.html"
target=_blank>常用的幾個shell腳本_4_更新jsp</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008717/133287.html"
target=_blank>rhel5-kvm虛擬機安裝oracle rac</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144806.html"
target=_blank>NAND閃存工作原理</A></DIV>
<DIV class="tj_r tj"><NOBR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008617/125862.html"
target=_blank>MySql源文件安裝</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008617/125890.html"
target=_blank>定制Linux系統(tǒng)內(nèi)核,發(fā)揮Linux潛能</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008923/144890.html"
target=_blank>使用VIM開發(fā)軟件項目 - (10) 程序員的利器: cscope</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/200899/141129.html"
target=_blank>ssh系列</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2007114/84145.html"
target=_blank>禁止不用的帳戶登陸</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008812/135754.html"
target=_blank>Linux認證復(fù)習(xí)題100道(3)</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008816/136151.html"
target=_blank>Linux系統(tǒng)NFS服務(wù)</A><BR><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/200896/139648.html"
target=_blank>linux內(nèi)核的移植與遭遇問題的解決</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設(shè)備驅(qū)動之USB主機控制器驅(qū)動分析-(2)_Linux技術(shù)文章_Linux_操作系統(tǒng)2.files/CAP2NPPM.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部落網(wǎng)友 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=發(fā)表評論>
</DIV></DIV>
<DIV class=comment_1
style="FLOAT: left; MARGIN-LEFT: 6px; WIDTH: 313px; HEIGHT: 90px">
<DIV class=cleanblock2>
<H3>網(wǎng)友推薦文章</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/2008611/124679.html"
target=_blank>轉(zhuǎn):我理解的邏輯地址、線性地址、物理地址和虛擬地址</A></LI>
<LI><A
href="http://www.diybl.com/course/6_system/linux/Linuxjs/2008624/128094.html"
target=_blank>使用gdbserver遠程調(diào)試</A></LI>
<LI><A
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -