Documentation\driver-model\Device Classes


Chinese translated version of Documentation\driver-model\Device Classes.txt




If you have any comment or update to the content, please contact the
original document maintainer directly.  However, if you have a problem
communicating in English you can also ask the Chinese maintainer for
help.  Contact the Chinese maintainer if this translation is outdated
or if there is a problem with the translation.




Chinese maintainer: 朱锋志 605509916@qq.com
---------------------------------------------------------------------
Documentation\driver-model\Device Classes的中文翻译




如果想评论或更新本文的内容,请直接联系原文档的维护者。如果你使用英文
交流有困难的话,也可以向中文版维护者求助。如果本翻译更新不及时或者翻
译存在问题,请联系中文版维护者。




中文版维护者:朱锋志 605509916@qq.com
中文版翻译者: 朱锋志 605509916@qq.com




以下为正文




---------------------------------------------------------------------
Device Classes
设备类


Introduction
~~~~~~~~~~~~
介绍
A device class describes a type of device, like an audio or network
device. The following device classes have been identified:


<Insert List of Device Classes Here>
一个设备类描述了一种类型的设备,比如说是声音或者是网络设备。随后的设备类是这样定义的:


<在这里插入设备类的列表>




Each device class defines a set of semantics and a programming interface
that devices of that class adhere to. Device drivers are the
implementation of that programming interface for a particular device on
a particular bus. 


Device classes are agnostic with respect to what bus a device resides
on. 
每一个设备类都定义了一系列的语意和一个与该类对应的设备所要遵循的编程接口。设备的驱动就是这个编程接口的实现,用于驱动在特定总线上工作的特定设备。


设备工作在什么总线上,对于设备类是不可知的。 




Programming Interface
编程接口
~~~~~~~~~~~~~~~~~~~~~
The device class structure looks like: 
设备类的结构可能会是这样的:


typedef int (*devclass_add)(struct device *);
typedef void (*devclass_remove)(struct device *);


See the kerneldoc for the struct class.


A typical device class definition would look like: 


一个典型的设备类的定义可能会是这样的:


struct device_class input_devclass = {
        .name = "input",
        .add_device = input_add_device,
.remove_device = input_remove_device,
};


Each device class structure should be exported in a header file so it
can be used by drivers, extensions and interfaces.


Device classes are registered and unregistered with the core using: 


每一个设备类的结构应该被导出在一个头文件里面,以便被驱动程序,扩展程序和接口使用。


使用以下的语句,实现设备类的注册和撤销:








int devclass_register(struct device_class * cls);
void devclass_unregister(struct device_class * cls);




Devices
设备
~~~~~~~
As devices are bound to drivers, they are added to the device class
that the driver belongs to. Before the driver model core, this would
typically happen during the driver's probe() callback, once the device
has been initialized. It now happens after the probe() callback
finishes from the core. 


当设备与驱动程序绑定了后,它们就被添加到了驱动程序所属的设备类里面去。
在驱动模型内核(这里不知道怎么翻译比较好)问世之前,当设备被初始化了后,
这一个添加的操作一般都是在驱动程序在回调probe()的时候发生的。但是现在,
添加操作是在内核中回调了probe()后发生的。


The device is enumerated in the class. Each time a device is added to
the class, the class's devnum field is incremented and assigned to the
device. The field is never decremented, so if the device is removed
from the class and re-added, it will receive a different enumerated
value. 
在类中,设备会被枚举出来。每一次设备被加入到类中,类的devnum数据项的值就会就增加,
并且将会被指定给设备。但是这个数据项的值永远不会减少,也就是说,如果设备从类中移除出去,
又重新添加,它将会接受到一个不同的枚举值。
The class is allowed to create a class-specific structure for the
device and store it in the device's class_data pointer. 
类被允许用来为设备创建一个明确的数据结构,并且使用使用一个设备的class_data指针来指向这个数据结构。
There is no list of devices in the device class. Each driver has a
list of devices that it supports. The device class has a list of
drivers of that particular class. To access all of the devices in the
class, iterate over the device lists of each driver in the class.
在设备类中,不存在设备的列表。每一个驱动程序都有它支持的设备的列表。设备类拥有都有一个驱动程序的列表。要访问类中的全部驱动程序,遍历类中每个驱动程序的设备列表即可。


Device Drivers
设备驱动程序
~~~~~~~~~~~~~~
Device drivers are added to device classes when they are registered
with the core. A driver specifies the class it belongs to by setting
the struct device_driver::devclass field. 


当设备被内核注册的时候,设备的驱动程序就添加到了设备的类中去。驱动程序通过设置结构device driver::devclass字段来指明这是什么类。
sysfs directory structure
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
There is a top-level sysfs directory named 'class'. 
文件系统目录结构
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
存在一个顶级的文件系统目录,名称为:'class'




Each class gets a directory in the class directory, along with two
default subdirectories:
每一个类都在class文件夹里面拥有一个目录,下面还有两个默认的子文件夹:
        class/
        `-- input
            |-- devices
            `-- drivers




Drivers registered with the class get a symlink in the drivers/ directory 
that points to the driver's directory (under its bus directory):
通过类来注册的驱动程序,在drivers/目录下有一个符号连接,指向了驱动程序的文件夹(在它的bus目录下):
   class/
   `-- input
       |-- devices
       `-- drivers
           `-- usb:usb_mouse -> ../../../bus/drivers/usb_mouse/




Each device gets a symlink in the devices/ directory that points to the 
device's directory in the physical hierarchy:
每一个设备都在devices/目录下面有一个符号连接,指向了设备的物理层次的文件夹:
   class/
   `-- input
       |-- devices
       |   `-- 1 -> ../../../root/pci0/00:1f.0/usb_bus/00:1f.2-1:0/
       `-- drivers




Exporting Attributes
导出属性
~~~~~~~~~~~~~~~~~~~~
struct devclass_attribute {
        struct attribute        attr;
        ssize_t (*show)(struct device_class *, char * buf, size_t count, loff_t off);
        ssize_t (*store)(struct device_class *, const char * buf, size_t count, loff_t off);
};


Class drivers can export attributes using the DEVCLASS_ATTR macro that works
similarly to the DEVICE_ATTR macro for devices. For example, a definition 
like this:
类驱动程序可以使用DEVCLASS_ATTR宏来导出属性,工作方式和DEVICE_ATTR相似。例如,一个定义可以是这样的:
static DEVCLASS_ATTR(debug,0644,show_debug,store_debug);


is equivalent to declaring:
与如下声明的效果是一样的:
static devclass_attribute devclass_attr_debug;


The bus driver can add and remove the attribute from the class's
sysfs directory using:
总线的驱动可以从类的文件系统目录中添加或者或者删除属性,方法如下:
int devclass_create_file(struct device_class *, struct devclass_attribute *);
void devclass_remove_file(struct device_class *, struct devclass_attribute *);


In the example above, the file will be named 'debug' in placed in the
class's directory in sysfs. 
在上面的例子中,在文件系统的类的文件夹中,文件将会被命名为'debug'。


Interfaces
~~~~~~~~~~
There may exist multiple mechanisms for accessing the same device of a
particular class type. Device interfaces describe these mechanisms. 


When a device is added to a device class, the core attempts to add it
to every interface that is registered with the device class.
接口
~~~~~~~~~~
存在着多种用于访问特定设备类类型的同种设备的机制。设备的接口描述了这些机制。


当一个设备被添加到了设备类中后,内核尝试将设备添加到每一个接口中去。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值