当前位置:首页 » 操作系统 » linux总线驱动设备驱动

linux总线驱动设备驱动

发布时间: 2022-02-24 09:52:31

1. 如何 理解 linux 设备 驱动 总线

linux
主机的硬件配备
lspci
找到的是目前主机上面的硬件配备
[root@www
~]#
lspci
[-vvn]
选项与参数:
-v
:显示更多的
pci
接口装置的详细信息
-vv
:比
-v
还要更详细的信息
-n
:直接观察
pci

id
而不是厂商名称
查阅您系统内的
pci
装置:
[root@www
~]#
lspci
#不必加上任何选项,就能够显示出目前的硬件配备为何
host
bridge:
<==主板芯片
vga
compatible
controller
<==显卡
audio
device
<==音频设备
pci
bridge
<==接口插槽
usb
controller
<==usb控制器
isa
bridge
ide
interface
smbus
ethernet
controller
<==网卡
04:00.0
ethernet
controller:
realtek
semiconctor
co.,
ltd.
查看一般详细信息
[root@www
~]#
lspci
-v
查看网卡详细信息:
[root@www
~]#
lspci
-s
04:00.0
-vv
-s
:后面接的是每个设备的总线、插槽与相关函数功能

2. linux 下platform设备和驱动注册的先后顺序

Linux关于总线、设备、驱动的注册顺序

设备挂接到总线上时,与总线上的所有驱动进行匹配(用bus_type.match进行匹配),
如果匹配成功,则调用bus_type.probe或者driver.probe初始化该设备,挂接到总线上
如果匹配失败,则只是将该设备挂接到总线上。

驱动挂接到总线上时,与总线上的所有设备进行匹配(用bus_type.match进行匹配),
如果匹配成功,则调用bus_type.probe或者driver.probe初始化该设备;挂接到总线上
如果匹配失败,则只是将该驱动挂接到总线上。

需要重点关注的是总线的匹配函数match(),驱动的初始化函数probe()

1. platform_bus_type--总线先被kenrel注册。

2. 系统初始化过程中调用platform_add_devices或者platform_device_register,将平台设备(platform devices)注册到平台总线中(platform_bus_type)
3. 平台驱动(platform driver)与平台设备(platform device)的关联是在platform_driver_register或者driver_register中实现,一般这个函数在驱动的初始化过程调用。

通过这三步,就将平台总线,设备,驱动关联起来。

1. platform bus先被kenrel注册。
------------------------------------------------------
do_basic_setup() -->-driver_init() -->-platform_bus_init()-->bus_register()

2. 系统初始化过程中调用platform_add_devices或者platform_device_register,将平台设备(platform devices)注册到平台总线中(platform_bus_type)
------------------------------------------------------
系统启动阶段,总线的驱动链表还是空的,所以启动阶段的platform_add_devices()只负责将设备添加到总线的设备链表上。

3. linux总线驱动模型中,总线也是一种设备,总线与表示它的设备是怎么联系的

设备模型中,关心总线,设备,驱动这三个实体,总线将设备和驱动绑定,在系统每注册一个设备的时候,会寻找与之匹配的驱动。相反,在系统每注册一个驱动的时候,寻找与之匹配的设备,匹配是由总线来完成的。 你还可以看一看链表的信息。它们都是关联的。 有个最牛的函数contain_o
f 非常牛。还有轮询链表的函数。

4. vxworks驱动跟linux驱动有什么区别总线驱动怎么写

vxworks和linux是不同的两个操作系统,类似的还有wince。

首先,vxworks和linux系统内部很多实现都不一样,导致驱动层实现也不一样。

由于Linux操作系统和Linux引导装载器在结构上的分离,使得它俩之间的设备驱动程序不能够通用,当然在芯片的硬件初始化一些硬件相关的代码上可以互相借鉴。而 VxWorks的BOOTROM和运行版本的设备驱动是相同的,因为,它的运行版本和BOOTROM的结构是一致的,使用同一操作系统内核。 Linux操作系统的设备驱动运行在内核空间,用户进程运行在用户空间。在Linux操作系统中,内核空间和用户空间的内存管理和映射方式是不同的,应用和设备驱动在数据交换时会涉及到不同的内存空间,会影响到一定效率,但这个问题可以通过修改系统内存空间配置等方法来解决。 VxWorks操作系统没有分开内核空间和用户空间,设备驱动和应用都运行于同一空间,相互之间的内存都可以访问,数据交换非常方便,但是,这种结构的稳定性就不如 Linux系统好了。 两种操作系统都提供了很多设备驱动的资源和模板。但是由于Linux的开源特性,它提供的设备驱动的种类和数量远远超过了VxWorks.

参考:http://blog.csdn.net/cybertan/article/details/5707973

5. 怎么查看linux usb设备驱动

下面的信息都是在VMware中运行Ubuntu12-04系统上执行的。同样该命令也支持在嵌入式系统中进行USB调试。
一、cat设备节点获取信息
在一些嵌入式开发中需要调试USB功能,经常会cat /sys 下的相关设备节点来查看某些信息,比如说我们可以看到 /sys/bus/usb/devices 目录有多个子目录。进入到某个子目录可以看到usb设备更加详细的信息(可以理解为设备描述符)。
1、usb设备在总线上的信息
// usb设备在总线上的信息
root@ubuntu:/sys/kernel/debug# cd /sys/bus/usb/devices
root@ubuntu:/sys/bus/usb/devices# ll
total 0
drwxr-xr-x 2 root root 0 Nov 26 21:21 ./
drwxr-xr-x 4 root root 0 Nov 26 21:21 ../
lrwxrwxrwx 1 root root 0 Nov 26 21:21 1-0:1.0 -> ../../../devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-0:1.0/
lrwxrwxrwx 1 root root 0 Dec 15 23:10 1-1 -> ../../../devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-1/
lrwxrwxrwx 1 root root 0 Dec 15 23:18 1-1:1.0 -> ../../../devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/1-1/1-1:1.0/
lrwxrwxrwx 1 root root 0 Nov 26 21:21 2-0:1.0 -> ../../../devices/pci0000:00/0000:00:11.0/0000:02:00.0/usb2/2-0:1.0/
lrwxrwxrwx 1 root root 0 Nov 26 21:21 2-1 -> ../../../devices/pci0000:00/0000:00:11.0/0000:02:00.0/usb2/2-1/
lrwxrwxrwx 1 root root 0 Nov 26 21:21 2-1:1.0 -> ../../../devices/pci0000:00/0000:00:11.0/0000:02:00.0/usb2/2-1/2-1:1.0/
lrwxrwxrwx 1 root root 0 Nov 26 21:21 2-2 -> ../../../devices/pci0000:00/0000:00:11.0/0000:02:00.0/usb2/2-2/
lrwxrwxrwx 1 root root 0 Nov 26 21:21 2-2:1.0 -> ../../../devices/pci0000:00/0000:00:11.0/0000:02:00.0/usb2/2-2/2-2:1.0/
lrwxrwxrwx 1 root root 0 Nov 26 21:21 usb1 -> ../../../devices/pci0000:00/0000:00:11.0/0000:02:03.0/usb1/
lrwxrwxrwx 1 root root 0 Nov 26 21:21 usb2 -> ../../../devices/pci0000:00/0000:00:11.0/0000:02:00.0/usb2/
其中 usbx/第x个总线,x-y:a.b/的目录格式,x表示总线号,y表示端口,a表示配置,b表示接口。
具体解释可以参照如下:
The names that begin with "usb" refer to USB controllers. More accurately, they refer to the "root hub" associated with each controller. The number is the USB bus number. In the example there is only one controller, so its bus is number 1. Hence the name "usb1".
"1-0:1.0" is a special case. It refers to the root hub's interface. This acts just like the interface in an actual hub an almost every respect; see below.
All the other entries refer to genuine USB devices and their interfaces. The devices are named by a scheme like this:
bus-port.port.port ...
In other words, the name starts with the bus number followed by a '-'. Then comes the sequence of port numbers for each of the intermediate hubs along the path to the device.
For example, "1-1" is a device plugged into bus 1, port 1. It happens to be a hub, and "1-1.3" is the device plugged into port 3 of that hub. That device is another hub, and "1-1.3.1" is the device plugged into its port 1.
The interfaces are indicated by suffixes having this form:
:config.interface
That is, a ':' followed by the configuration number followed by '.' followed by the interface number. In the above example, each of the devices is using configuration 1 and this configuration has only a single interface, number 0. So the interfaces show up as;
1-1:1.0 1-1.3:1.0 1-1.3.1:1.0
A hub will never have more than a single interface; that's part of the USB spec. But other devices can and do have multiple interfaces (and sometimes multiple configurations). Each interface gets its own entry in sysfs and can have its own driver.
2、特定设备的详细信息
进入到某个目录中去,可以看到该设备的详细信息,可用cat命令获取信息。
// usb设备的详细信息
root@ubuntu:/sys/bus/usb/devices/usb1# ll
total 0
drwxr-xr-x 6 root root 0 Nov 26 21:21 ./
drwxr-xr-x 4 root root 0 Nov 26 21:21 ../
drwxr-xr-x 10 root root 0 Nov 26 21:21 1-0:1.0/
drwxr-xr-x 5 root root 0 Dec 15 23:10 1-1/
-rw-r--r-- 1 root root 4096 Dec 15 23:40 authorized
-rw-r--r-- 1 root root 4096 Dec 15 23:40 authorized_default
-rw-r--r-- 1 root root 4096 Dec 15 23:40 avoid_reset_quirk
-r--r--r-- 1 root root 4096 Nov 26 21:21 bcdDevice
-rw-r--r-- 1 root root 4096 Nov 26 21:21 bConfigurationValue
-r--r--r-- 1 root root 4096 Nov 26 21:21 bDeviceClass
-r--r--r-- 1 root root 4096 Nov 26 21:21 bDeviceProtocol
-r--r--r-- 1 root root 4096 Nov 26 21:21 bDeviceSubClass
-r--r--r-- 1 root root 4096 Dec 15 23:40 bmAttributes
-r--r--r-- 1 root root 4096 Dec 15 23:40 bMaxPacketSize0
-r--r--r-- 1 root root 4096 Dec 15 23:40 bMaxPower
-r--r--r-- 1 root root 4096 Dec 15 23:40 bNumConfigurations
-r--r--r-- 1 root root 4096 Dec 15 23:40 bNumInterfaces
-r--r--r-- 1 root root 4096 Nov 26 21:21 busnum
-r--r--r-- 1 root root 4096 Dec 15 23:40 configuration
-r--r--r-- 1 root root 65553 Nov 26 21:21 descriptors
-r--r--r-- 1 root root 4096 Dec 15 23:40 dev
-r--r--r-- 1 root root 4096 Nov 26 21:21 devnum
-r--r--r-- 1 root root 4096 Dec 15 23:40 devpath
lrwxrwxrwx 1 root root 0 Nov 27 20:06 driver -> ../../../../../bus/usb/drivers/usb/
drwxr-xr-x 3 root root 0 Dec 15 23:40 ep_00/
-r--r--r-- 1 root root 4096 Nov 26 21:21 idProct
-r--r--r-- 1 root root 4096 Nov 26 21:21 idVendor
-r--r--r-- 1 root root 4096 Dec 15 23:40 ltm_capable
-r--r--r-- 1 root root 4096 Nov 26 21:21 manufacturer
-r--r--r-- 1 root root 4096 Dec 15 23:40 maxchild
drwxr-xr-x 2 root root 0 Nov 26 21:21 power/
-r--r--r-- 1 root root 4096 Nov 26 21:21 proct
-r--r--r-- 1 root root 4096 Dec 15 23:40 quirks
-r--r--r-- 1 root root 4096 Nov 26 21:21 removable
--w------- 1 root root 4096 Dec 15 23:40 remove
-r--r--r-- 1 root root 4096 Nov 26 21:21 serial
-r--r--r-- 1 root root 4096 Nov 26 21:21 speed
lrwxrwxrwx 1 root root 0 Nov 26 21:21 subsystem -> ../../../../../bus/usb/
-rw-r--r-- 1 root root 4096 Nov 26 21:21 uevent
-r--r--r-- 1 root root 4096 Dec 15 23:40 urbnum
-r--r--r-- 1 root root 4096 Dec 15 23:40 version
二、使用debugfs
1、挂载 debugfs 到 /sys/kernel/debug 路径下
root@ubuntu:mount -t debugfs none /sys/kernel/debug
2、执行上述步骤之后,在 /sys/kernel/debug 就会生成如下的文件
root@ubuntu:/sys/bus/usb/devices# cd /sys/kernel/debug/
root@ubuntu:/sys/kernel/debug# ll
total 0
drwx------ 22 root root 0 Nov 26 21:21 ./
drwxr-xr-x 7 root root 0 Nov 26 21:21 ../
drwxr-xr-x 2 root root 0 Nov 26 21:21 acpi/
drwxr-xr-x 32 root root 0 Dec 4 16:30 bdi/
drwxr-xr-x 2 root root 0 Nov 26 21:21 bluetooth/
drwxr-xr-x 2 root root 0 Nov 26 21:21 cleancache/
drwxr-xr-x 2 root root 0 Nov 26 21:21 dma_buf/
drwxr-xr-x 4 root root 0 Nov 26 21:21 dri/
drwxr-xr-x 2 root root 0 Nov 26 21:21 dynamic_debug/
drwxr-xr-x 2 root root 0 Nov 26 21:21 extfrag/
drwxr-xr-x 2 root root 0 Nov 26 21:21 frontswap/
-r--r--r-- 1 root root 0 Nov 26 21:21 gpio
drwxr-xr-x 3 root root 0 Nov 26 21:21 hid/
drwxr-xr-x 2 root root 0 Nov 26 21:21 kprobes/
drwxr-xr-x 3 root root 0 Nov 26 21:21 kvm-guest/
drwxr-xr-x 2 root root 0 Nov 26 21:21 mce/
drwxr-xr-x 2 root root 0 Nov 26 21:21 pinctrl/
-r--r--r-- 1 root root 0 Nov 26 21:21 pwm
drwxr-xr-x 2 root root 0 Nov 26 21:21 regmap/
drwxr-xr-x 3 root root 0 Nov 26 21:21 regulator/
-rw-r--r-- 1 root root 0 Nov 26 21:21 sched_features
-r--r--r-- 1 root root 0 Nov 26 21:21 sleep_time
-r--r--r-- 1 root root 0 Nov 26 21:21 suspend_stats
drwxr-xr-x 7 root root 0 Nov 26 21:21 tracing/
drwxr-xr-x 3 root root 0 Nov 26 21:21 usb/
drwxr-xr-x 2 root root 0 Nov 26 21:21 virtio-ports/
-r--r--r-- 1 root root 0 Nov 26 21:21 vmmemctl
-r--r--r-- 1 root root 0 Nov 26 21:21 wakeup_sources
drwxr-xr-x 2 root root 0 Nov 26 21:21 x86/
3、cat 设备节点
执行下述命令之后会以特定格式打印目前USB总线上所有USB设备的信息如下:
root@ubuntu:/sys/kernel/debug# cat usb/devices
T: Bus=02 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=12 MxCh= 2
B: Alloc= 17/900 us ( 2%), #Int= 1, #Iso= 0
D: Ver= 1.10 Cls=09(hub ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=1d6b ProdID=0001 Rev= 3.13
S: Manufacturer=Linux 3.13.0-32-generic uhci_hcd
S: Proct=UHCI Host Controller
S: SerialNumber=0000:02:00.0
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr= 0mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub
E: Ad=81(I) Atr=03(Int.) MxPS= 2 Ivl=255ms
T: Bus=02 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 2 Spd=12 MxCh= 0
D: Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1
P: Vendor=0e0f ProdID=0003 Rev= 1.03
S: Manufacturer=VMware
S: Proct=VMware Virtual USB Mouse
C:* #Ifs= 1 Cfg#= 1 Atr=c0 MxPwr= 0mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=03(HID ) Sub=01 Prot=02 Driver=usbhid
E: Ad=81(I) Atr=03(Int.) MxPS= 8 Ivl=1ms
T: Bus=02 Lev=01 Prnt=01 Port=01 Cnt=02 Dev#= 3 Spd=12 MxCh= 7
D: Ver= 1.10 Cls=09(hub ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1
P: Vendor=0e0f ProdID=0002 Rev= 1.00
S: Proct=VMware Virtual USB Hub
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr= 0mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub
E: Ad=81(I) Atr=03(Int.) MxPS= 1 Ivl=255ms
T: Bus=01 Lev=00 Prnt=00 Port=00 Cnt=00 Dev#= 1 Spd=480 MxCh= 6
B: Alloc= 0/800 us ( 0%), #Int= 1, #Iso= 0
D: Ver= 2.00 Cls=09(hub ) Sub=00 Prot=00 MxPS=64 #Cfgs= 1
P: Vendor=1d6b ProdID=0002 Rev= 3.13
S: Manufacturer=Linux 3.13.0-32-generic ehci_hcd
S: Proct=EHCI Host Controller
S: SerialNumber=0000:02:03.0
C:* #Ifs= 1 Cfg#= 1 Atr=e0 MxPwr= 0mA
I:* If#= 0 Alt= 0 #EPs= 1 Cls=09(hub ) Sub=00 Prot=00 Driver=hub
E: Ad=81(I) Atr=03(Int.) MxPS= 4 Ivl=256ms
T: Bus=01 Lev=01 Prnt=01 Port=00 Cnt=01 Dev#= 7 Spd=480 MxCh= 0
D: Ver= 2.00 Cls=ff(vend.) Sub=ff Prot=ff MxPS=64 #Cfgs= 1
P: Vendor=0bda ProdID=0129 Rev=39.60
S: Manufacturer=Generic
S: Proct=USB2.0-CRW
S: SerialNumber=20100201396000000
C:* #Ifs= 1 Cfg#= 1 Atr=a0 MxPwr=500mA
I:* If#= 0 Alt= 0 #EPs= 3 Cls=ff(vend.) Sub=06 Prot=50 Driver=rts5139
E: Ad=01(O) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=82(I) Atr=02(Bulk) MxPS= 512 Ivl=0ms
E: Ad=83(I) Atr=03(Int.) MxPS= 3 Ivl=64ms
至于信息的详细解析可以参照 Linux源代码中 Documentation/usb/proc_usb_info.txt 文件。现摘录其中对该格式的详细解释:

| | |__Proct ID code
| |__Vendor ID code
|__Device info tag #2

String descriptor info:
S: Manufacturer=ssss
| |__Manufacturer of this device as read from the device.
| For USB host controller drivers (virtual root hubs) this may
| be omitted, or (for newer drivers) will identify the kernel
| version and the driver which provi

6. Linux驱动程序有几种加载方式以及它们之间的区别

linux关于总线、设备、驱动的注册顺序
设备挂接到总线上时,与总线上的所有驱动进行匹配(用bus_type.match进行匹配),
如果匹配成功,则调用bus_type.probe或者driver.probe初始化该设备,挂接到总线上
如果匹配失败,则只是将该设备挂接到总线上。
驱动挂接到总线上时,与总线上的所有设备进行匹配(用bus_type.match进行匹配),
如果匹配成功,则调用bus_type.probe或者driver.probe初始化该设备;挂接到总线上
如果匹配失败,则只是将该驱动挂接到总线上。
需要重点关注的是总线的匹配函数match(),驱动的初始化函数probe()
1.
platform_bus_type--总线先被kenrel注册。
2.
系统初始化过程中调用platform_add_devices或者platform_device_register,将平台设备(platform
devices)注册到平台总线中(platform_bus_type)
3.
平台驱动(platform
driver)与平台设备(platform
device)的关联是在platform_driver_register或者driver_register中实现,一般这个函数在驱动的初始化过程调用。
通过这三步,就将平台总线,设备,驱动关联起来。
1.
platform
bus先被kenrel注册。
------------------------------------------------------
do_basic_setup()
-->-driver_init()
-->-platform_bus_init()-->bus_register()
2.
系统初始化过程中调用platform_add_devices或者platform_device_register,将平台设备(platform
devices)注册到平台总线中(platform_bus_type)
------------------------------------------------------
系统启动阶段,总线的驱动链表还是空的,所以启动阶段的platform_add_devices()只负责将设备添加到总线的设备链表上。

7. 请问Linux驱动程序中,字符设备驱动,块设备驱动以及网络驱动的区别和比较,学的时候需要注意些什么

可以讲字符设备和块设备归为一类,它们都是可以顺序/随机地进行读取和存储的单元,二者驱动主要在于块设备需要具体的burst实现,对访问也有一定的边界要求。其他的没有什么不同。
网络设备是特殊设备的驱动,它负责接收和发送帧数据,可能是物理帧,也可能是ip数据包,这些特性都有网络驱动决定。它并不存在于/dev下面,所以与一般的设备不同。网络设备是一个net_device结构,并通过register_netdev注册到系统里,最后通过ifconfig -a的命令就能看到。
不论是什么设备,设备级的数据传输都是基本类似的,内核里的数据表示只是一部分,更重要的是总线的访问,例如串行spi,i2c,并行dma等。

8. linux中设备和驱动到底有什么区别,有什么联系啊学习2.6的内核,搞得好晕呢!

2.6.x版本的内核,核心部分变动不大。
每个小版本之间,都是在不停的添加新驱动、解一些小bug、对现有系统进行完善。
你如果让我在这里说每个版本之间的区别的话,估计要写好几页了。建议你到官网(www.kernel.org/目前已经可以访问了)上去看下每个版本的ChangeLog。这个东西,没有任何人比它说的更详细了。如果你对某个修改比较感兴趣,还可以下载对应的patch包,看看那些Hacker究竟做了哪些修改。
当然,最方便的方法,还是使用git把Kerne的代码下载下来,然后用git log命令可以看到每次修改的历史信息的。非常方便和详细。
不明白的请追问。

9. 请问linux驱动怎么调用底层的驱动啊 比如说已有SPI总线驱动,现要为一个SPI设备写驱动,怎么调用底层驱动

spi总线驱动在linux中是采用了分层设计和分隔设计的思想,spi控制器的驱动和核心层的通用api内核已经写完了,你只要写外设驱动就好,具体你可以去看一下你的spi_s3c24xx.c这个驱动是基于platfoem写的,里面含有如何调用核心api。

热点内容
新秀丽箱子怎么改密码 发布:2024-09-21 15:32:21 浏览:860
司歌脚本 发布:2024-09-21 15:09:23 浏览:926
双面文件夹 发布:2024-09-21 14:58:59 浏览:210
qq账号邮箱密码多少 发布:2024-09-21 14:26:21 浏览:946
中国银行网银密码无效是什么意思 发布:2024-09-21 14:10:39 浏览:407
java加密与解密的艺术pdf 发布:2024-09-21 14:10:32 浏览:782
pythonurllib2编码 发布:2024-09-21 14:10:29 浏览:244
php删除表 发布:2024-09-21 14:02:31 浏览:899
安卓哪里有用线程池 发布:2024-09-21 14:00:08 浏览:193
LoongArch编译器 发布:2024-09-21 13:58:38 浏览:630