📄 linux设备驱动程序学习(13)-linux设备模型(总线、设备、驱动程序和类) - linux设备驱动程序 - tekkaman ninja.htm
字号:
<HR id=null>
</DIV>
<P>文章的例子和实验使用《LDD3》所配的lddbus模块(稍作修改)。</P>
<P><STRONG><FONT color=#0000ff
size=4>总线</FONT></STRONG></P>
<P>总线是处理器和一个或多个设备之间的通道,在设备模型中, 所有的设备都通过总线相连,
甚至是内部的虚拟"<FONT
color=#ff0000>platform</FONT>"总线。总线可以相互插入。设备模型展示了总线和它们所控制的设备之间的实际连接。<BR>在
Linux 设备模型中, 总线由 bus_type 结构表示, 定义在 <FONT
color=#0000ff><linux/device.h></FONT> :
<TABLE style="BORDER-COLLAPSE: collapse"
borderColor=#999999 cellSpacing=0 cellPadding=0
width="95%" bgColor=#f1f1f1 border=1>
<TBODY>
<TR>
<TD>
<P
style="MARGIN: 5px; LINE-HEIGHT: 150%"><CODE><SPAN
style="COLOR: rgb(0,0,0)"><FONT face=新宋体><SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
bus_type <SPAN
style="COLOR: rgb(0,0,204)">{</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,255)">const</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">char</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN> name<SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><SPAN
style="COLOR: rgb(255,153,0)">/*总线类型名称*/</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
module <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN> owner<SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><SPAN
style="COLOR: rgb(255,153,0)">/*指向模块的指针(如果有),
此模块负责操作这个总线*/</SPAN><BR><BR> <SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
kset subsys<SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><SPAN
style="COLOR: rgb(255,153,0)">/*与该总线相关的子系统*/</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
kset drivers<SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><SPAN
style="COLOR: rgb(255,153,0)">/*总线驱动程序的kset*/</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
kset devices<SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><SPAN
style="COLOR: rgb(255,153,0)">/*
挂在该总线的所有设备的kset*/</SPAN><BR><BR> <SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
klist klist_devices<SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><SPAN
style="COLOR: rgb(255,153,0)">/*与该总线相关的驱动程序链表*/</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
klist klist_drivers<SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><SPAN
style="COLOR: rgb(255,153,0)">/*挂接在该总线的设备链表*/</SPAN><BR><BR> <SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
blocking_notifier_head bus_notifier<SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><BR><BR> <SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
bus_attribute <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>
bus_attrs<SPAN
style="COLOR: rgb(0,0,204)">;</SPAN> <SPAN
style="COLOR: rgb(255,153,0)">/*总线属性*/</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
device_attribute <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>
dev_attrs<SPAN
style="COLOR: rgb(0,0,204)">;</SPAN> <SPAN
style="COLOR: rgb(255,153,0)">/*设备属性,指向为每个加入总线的设备建立的默认属性链表*/</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
driver_attribute <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>
drv_attrs<SPAN
style="COLOR: rgb(0,0,204)">;</SPAN> <SPAN
style="COLOR: rgb(255,153,0)">/*驱动程序属性*/</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
bus_attribute drivers_autoprobe_attr<SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><SPAN
style="COLOR: rgb(255,153,0)">/*驱动自动探测属性*/</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN>
bus_attribute drivers_probe_attr<SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><SPAN
style="COLOR: rgb(255,153,0)">/*驱动探测属性*/</SPAN><BR><BR> <SPAN
style="COLOR: rgb(0,0,255)">int</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>match<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN> device
<SPAN style="COLOR: rgb(0,0,204)">*</SPAN>
dev<SPAN style="COLOR: rgb(0,0,204)">,</SPAN>
<SPAN style="COLOR: rgb(0,0,255)">struct</SPAN>
device_driver <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN> drv<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,255)">int</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>uevent<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN> device
<SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>dev<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">char</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN><SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>envp<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN><BR>
<SPAN style="COLOR: rgb(0,0,255)">int</SPAN>
num_envp<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">char</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>buffer<SPAN
style="COLOR: rgb(0,0,204)">,</SPAN> <SPAN
style="COLOR: rgb(0,0,255)">int</SPAN>
buffer_size<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,255)">int</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>probe<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN> device
<SPAN style="COLOR: rgb(0,0,204)">*</SPAN>
dev<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,255)">int</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,204)">*</SPAN><SPAN
style="COLOR: rgb(255,0,0)">remove</SPAN><SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN> device
<SPAN style="COLOR: rgb(0,0,204)">*</SPAN>
dev<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,255)">void</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,204)">*</SPAN><SPAN
style="COLOR: rgb(255,0,0)">shutdown</SPAN><SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN> device
<SPAN style="COLOR: rgb(0,0,204)">*</SPAN>
dev<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><BR><BR> <SPAN
style="COLOR: rgb(0,0,255)">int</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>suspend<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN> device
<SPAN style="COLOR: rgb(0,0,204)">*</SPAN>
dev<SPAN style="COLOR: rgb(0,0,204)">,</SPAN>
pm_message_t state<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,255)">int</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>suspend_late<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN> device
<SPAN style="COLOR: rgb(0,0,204)">*</SPAN>
dev<SPAN style="COLOR: rgb(0,0,204)">,</SPAN>
pm_message_t state<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><BR> <SPAN
style="COLOR: rgb(0,0,255)">int</SPAN> <SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>resume_early<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN> device
<SPAN style="COLOR: rgb(0,0,204)">*</SPAN>
dev<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">;</SPAN><BR> nt
<SPAN style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,204)">*</SPAN>resume<SPAN
style="COLOR: rgb(0,0,204)">)</SPAN><SPAN
style="COLOR: rgb(0,0,204)">(</SPAN><SPAN
style="COLOR: rgb(0,0,255)">struct</SPAN> device
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -