linux之class,bus_type等结构体之间的关系

先看一张图,描述各个结构体之间的关系
在这里插入图片描述
再上第二张图,下图描述了bus总线和class是如何管理设备和驱动的
在这里插入图片描述

1.class和bus是管理设备和驱动的两种型式:
2.class提供一种顶层的视图,帮助用户空间只需要知道这些是什么设备,而不需要关心他们是怎么连接和工作的;class对应于/sys/class目录.
3.bus以总线的方式来区分管理设备和驱动;对应于/sys/bus目录.
4.class和bus都是通过subsys_private 中的列表来管理设备(device)和驱动(device_driver).
5.platform_device,platform_driver是内嵌了device和device_driver的平台设备和驱动,针对的一般是片上集成的外设

以下是各结构体的介绍:
bus_type
bus 是处理器和一或多个设备之间的通道.为了设备驱动模型目的,所有的设备是通过一条总线连接的,
甚至它是内部的,虚拟的,平台(platform)型的总线.总线能让彼此联通.比如,USB控制器通常是PCI设备.
总线由bus_type结构体表示.它包含name,default attributes,bus’s method,PM操作,和driver core’s private data
(A bus is a channel between the processor and one or more devices. For the
purposes of the device model, all devices are connected via a bus, even if
it is an internal, virtual, “platform” bus. Buses can plug into each other.
A USB controller is usually a PCI device, for example. The device model
represents the actual connections between buses and the devices they control.
A bus is represented by the bus_type structure. It contains the name, the
default attributes, the bus’ methods, PM operations, and the driver core’s
private data.)

class
class是设备的更高层视图,抽象除了底层的实现细节.驱动程序会区分SCSI硬盘和ATA硬盘,但在class层他们都是
硬盘.classes帮助用户空间只需要知道这些是什么设备,而不需要关心他们是怎么连接和工作的.
( A class is a higher-level view of a device that abstracts out low-level
implementation details. Drivers may see a SCSI disk or an ATA disk, but,
at the class level, they are all simply disks. Classes allow user space
to work with devices based on what they do, rather than how they are
connected or how they work.)

subsys_private
bus_type和class结构体用来保存驱动内核的私有数据的结构体
(struct subsys_private - structure to hold the private to the driver core portions of the bus_type/class structure)

device
基本的device结构体. 在最底层,在linux系统里每个设备由一个device结构体表示.device结构体包含了设备模型内核需要的信息.大部分subsystem,还会增加额外的信息.因此很少单独由一个device表示一个设备;而是像kobject一样嵌入到 一个更大的结构体来表示一个设备.
(The basic device structure.
At the lowest level, every device in a Linux system is represented by an
instance of struct device. The device structure contains the information
that the device model core needs to model the system. Most subsystems,
however, track additional information about the devices they host. As a
result, it is rare for devices to be represented by bare device structures;
instead, that structure, like kobject structures, is usually embedded within
a higher-level representation of the device.)

device_driver
基本的设备驱动结构体.
设备驱动模型追踪了系统里的所有驱动.追踪的主要原因是为了使驱动能够匹配新加入的设备.一旦驱动程序是系统已知的对象,然而,许多其他的事情成为可能.设备驱动可以导出信息和配置变量独立于任何特定的设备.
(The basic device driver structure.
The device driver-model tracks all of the drivers known to the system.
The main reason for this tracking is to enable the driver core to match
up drivers with new devices. Once drivers are known objects within the
system, however, a number of other things become possible. Device drivers
can export information and configuration variables that are independent
of any specific device.)

platform_device
平台设备是指系统自带的设备.包括传统基于端口的设备和外设总线桥接的以及大部分控制器集成在片内的设备.他们通常有个共同点就是cpu总线直接寻址.少数的平台设备通过部分其他总线连接;但它们的寄存器仍是直接寻址的.
(Platform devices are devices that typically appear as autonomous
entities in the system. This includes legacy port-based devices and
host bridges to peripheral buses, and most controllers integrated
into system-on-chip platforms. What they usually have in common
is direct addressing from a CPU bus. Rarely, a platform_device will
be connected through a segment of some other kind of bus; but its
registers will still be directly addressable.)

platform_driver
平台驱动遵循标准的驱动模型惯例,设备的发现和枚举在驱动外处理,驱动提供probe()和remove()函数.它们支持电源管理和停电通知.
(Platform drivers follow the standard driver model convention, where
discovery/enumeration is handled outside the drivers, and drivers
provide probe() and remove() methods. They support power management
and shutdown notifications using the standard conventions.)

  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值