Documentation/driver-model/class.txt

Chinese translated version of Documentation/blockdev/cpqarray.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: wuyan<1481494885@qq.com>
---------------------------------------------------------------------
Documentation/driver-model/class.txt的中文翻译

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


中文版校译者: 吴燕 1481494885@qq.com如果本翻译更新不及时或者翻译存在问题,请联系中文版维护者。

中文版维护者: 吴燕 1481494885@qq.com

中文版翻译者: 吴燕 1481494885@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>

 设备类别 介绍

~~~~~~~~
设备类型描述了某种类型的设备,比如音频设备或者网络设备。下面的这些设备类别已经被识别了:

<这里插入设备类别列表>

  
 13 Each device class defines a set of semantics and a programming interface
 14 that devices of that class adhere to. Device drivers are the
 15 implementation of that programming interface for a particular device on
 16 a particular bus. 
 17 
 18 Device classes are agnostic with respect to what bus a device resides
 19 on.

     每个设备类别定义了一组语义和支持该类设备的编程接口。设备驱动程序为一个在特定总线的特定设备实现编程接口。

    考虑到设备该待在什么总线上,设备类别是不可知的。

 22 Programming Interface
 23 ~~~~~~~~~~~~~~~~~~~~~
 24 The device class structure looks like: 
 25 
 26 
 27 typedef int (*devclass_add)(struct device *);
 28 typedef void (*devclass_remove)(struct device *);
 29 
 30 See the kerneldoc for the struct class.

   编程接口

   ~~~~~~~~~~~~~~~~~~~~

  设备类结构如下:

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

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

  把kerneldoc视为struct类。

  

 31 
 32 A typical device class definition would look like: 
 33 
 34 
 39 
 40 Each device class structure should be exported in a header file so it
 41 can be used by drivers, extensions and interfaces.
 42 
 43 Device classes are registered and unregistered with the core using: 
 44 
 45 
 47 
    一个典型的设备类定义如下:

   struct device_class input_devclass = {

          .name           = "input",
          .add_device     = input_add_device,
          .remove_device  = input_remove_device,
  };

    每一个设备类结构应该在一个头文件导出这样它可以被驱动程序、扩展和接口使用。
  设备类注册和未注册的核心使用:

   int devclass_register(struct device_class * cls); 

   void devclass_unregister(struct device_class * cls);

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

  ~~~~~~

  随着设备都被绑定到驱动上,他们也被加到了驱动属于的设备类里。在驱动模型的核心之前,

  这通常会发生在驱动探针回调的时候,一旦设备被初始化。现在它发生在探针回调完成之后。

 57 The device is enumerated in the class. Each time a device is added to
 58 the class, the class's devnum field is incremented and assigned to the
 59 device. The field is never decremented, so if the device is removed
 60 from the class and re-added, it will receive a different enumerated
 61 value. 
 62 

该设备在类中被枚举。每一次一个设备被加到类里,类的devnum字段是递增的而且被分配到设备。

这个字段是从来不递减的,所以如果设备被从类中移除并且重新添加,它讲得到不同的枚举值。

 
 
 63 The class is allowed to create a class-specific structure for the
 64 device and store it in the device's class_data pointer. 
 65 
 66 There is no list of devices in the device class. Each driver has a
 67 list of devices that it supports. The device class has a list of
 68 drivers of that particular class. To access all of the devices in the
 69 class, iterate over the device lists of each driver in the class.

类被允许为设备创建一个类专用的结构,并把它储存在设备的类数据指针里。在设备类

里没有设备列表。每个驱动都有一个它所支持的设备列表。设备类有一个特定类的驱动

的列表。为了访问所有的设备,遍历类中每个驱动的设备列表。


 
 72 Device Drivers
 73 ~~~~~~~~~~~~~~
 74 Device drivers are added to device classes when they are registered
 75 with the core. A driver specifies the class it belongs to by setting
 76 the struct device_driver::devclass field. 
 77

设备驱动 

~~~~~~~~~~~~~~~~

当设备驱动程序与核心一起注册的时候,它们被添加到设备类。一个设备通过设置结构体

device_driver::devclass field来指定它属于的类。

 78 
 79 sysfs directory structure
 80 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 81 There is a top-level sysfs directory named 'class'. 
 82 
 83 Each class gets a directory in the class directory, along with two
 84 default subdirectories:
 85 
 86         class/
 87         `-- input
 88             |-- devices
 89             `-- drivers
 90

目录结构

~~~~~~~~~~~~~~~~~~~~

这里有个最高级别的目录,名为‘class’。

每个类在类目录中得到一个目录,连同两个默认的子目录。

class/ `-- input |-- devices `-- drivers

91 92 Drivers registered with the class get a symlink in the drivers/ directory 93 that points to the driver's directory (under its bus directory): 94 95 class/ 96 `-- input 97 |-- devices 98 `-- drivers 99 `-- usb:usb_mouse -> ../../../bus/drivers/usb_mouse/ 100

驱动程序注册类会在驱动/目录中得到指向驱动目录的符号链接(在它的usb目录下):
class/`

-- input
|-- devices
`-- drivers
`-- usb:usb_mouse -> ../../../bus/drivers/usb_mouse/


102 Each device gets a symlink in the devices/ directory that points to the 
103 device's directory in the physical hierarchy:
104 
105    class/
106    `-- input
107        |-- devices
108        |   `-- 1 -> ../../../root/pci0/00:1f.0/usb_bus/00:1f.2-1:0/
109        `-- drivers
110

每个设备在设备/目录中得到一在物理层次个指向设备的目录符号链接:
class/
`-- input |-- devices
| `-- 1 -> ../../../root/pci0/00:1f.0/usb_bus/00:1f.2-1:0/
`-- drivers

111 
112 Exporting Attributes
113 ~~~~~~~~~~~~~~~~~~~~
114 struct devclass_attribute {
115         struct attribute        attr;
116         ssize_t (*show)(struct device_class *, char * buf, size_t count, loff_t off);
117         ssize_t (*store)(struct device_class *, const char * buf, size_t count, loff_t off);
118 };
119 
120 Class drivers can export attributes using the DEVCLASS_ATTR macro that works
121 similarly to the DEVICE_ATTR macro for devices. For example, a definition 
122 like this:
123 
124 static DEVCLASS_ATTR(debug,0644,show_debug,store_debug);
125 
126 is equivalent to declaring:
127 
128 static devclass_attribute devclass_attr_debug;

导出属性

~~~~~~~~~~~~~~~
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);
};

类驱动程序可以用DEVCLASS_ATTR宏导出属性,类似设备的DEVICE_ATTR宏。例如,一个这样的定义:

static DEVCLASS_ATTR(debug,0644,show_debug,store_debug); 
is equivalent to declaring: 
static devclass_attribute devclass_attr_debug;


129 
130 The bus driver can add and remove the attribute from the class's
131 sysfs directory using:
132 
133 int devclass_create_file(struct device_class *, struct devclass_attribute *);
134 void devclass_remove_file(struct device_class *, struct devclass_attribute *);
135 
136 In the example above, the file will be named 'debug' in placed in the
137 class's directory in sysfs. 
138

驱动可以从类的sysfs目录中增加和删除属性:
int devclass_create_file(struct device_class *, struct devclass_attribute *);
void devclass_remove_file(struct device_class *, struct devclass_attribute *);

在上面的例子中,文件将会被命名为‘debug’被放在sysfs中类的目录里。

 
139 
140 Interfaces
141 ~~~~~~~~~~
142 There may exist multiple mechanisms for accessing the same device of a
143 particular class type. Device interfaces describe these mechanisms. 
144 
145 When a device is added to a device class, the core attempts to add it
146 to every interface that is registered with the device class.
147 

接口

~~~~~~~~~~~~~~~~~~

可能存在多个机制来访问特殊类的相同设备。设备接口描述这些机制。

当一个设备被添加到设备类,核心试图把它加入到每个设备类注册的接口。

   


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值