[译]6.1. Data Structures Featured in This Chapter 本章涉及到的数据结构

本文介绍了PCI设备驱动的关键数据结构,包括pci_device_id、pci_dev和pci_driver等,并详细解释了它们在PCI层与设备驱动之间的交互作用。文章还讨论了设备驱动如何通过这些数据结构进行初始化、注册和管理。

目录:http://www.cnblogs.com/WuCountry/archive/2008/11/15/1333960.html
 
[不提供插图,读者最好从网上下载源书]

6.1. Data Structures Featured in This Chapter 本章涉及到的数据结构
Here are a few key data structure types used by the PCI layer. There are many others, but the following ones are all we need to know for our overview in this book. The first one is defined in include/linux/mod_devicetable.h, and the other two are defined in include/linux/pci.h.
这里有一些PCI层会使用到的关键数据结构类型。有很多其它的数据类型,但下面的这些是本书中一直提及到的。第一个是定义在include/linux/mod_devicetable.h中,其它的两个定义在include/linux/pci.h中。

pci_device_id

Device identifier. This is not a local ID used by Linux, but an ID defined accordingly to the PCI standard. The later section "Registering a PCI NIC Device Driver" shows the ID's definition, and the later section "Example of PCI NIC Driver Registration" presents an example.
设备标识。这不是一个本地的由Linux所使用的ID,而是一个根据PCI标准定义的ID。在后面的一节“注册PCI NIC设备驱动”中会展示这个ID的定义,其后的“一个PCI NIC设备注册的例子”一节是会有一个例子。

pci_dev

Each PCI device is assigned a pci_dev instance, just as network devices are assigned net_device instances. This is the structure used by the kernel to refer to a PCI device.
每一个PCI设备就是一个指定的pci_dev实例,只有网络设备才会指定为net_device实例。这个数据结构就是内核用于引用到一个PCI设备。

pci_driver

Defines the interface between the PCI layer and the device drivers. This structure consists mostly of function pointers. All PCI devices use it. See the later section "Example of PCI NIC Driver Registration" for its definition and an example of its initialization.
用于在PCI层和设备驱动之间定义接口。这个结构包括了大多数函数指针。所有的CPI设备都使用它。在后面的一节中有一个它的定义和初始化的示例。


PCI device drivers are defined by an instance of a pci_driver structure. Here is a description of its main fields, with special attention paid to the case of NIC devices. The function pointers are initialized by the device driver to point to appropriate functions within that driver.
PCI设备驱动由一个pci_driver结构的实例所定义。这里对于它的主要成员有些说明,重点关注的是NIC设备这种情况。它的函数指针由设备驱动指向相关驱动的适当函数。

char *name

Name of the driver.
设备名。


const struct pci_device_id *id_table

Vector of IDs the kernel will use to associate devices to this driver. The section "Example of PCI NIC Driver Registration" shows an example.
一个内核会用于关联到设备驱动的向量ID。


int (*probe)(struct pci_dev *dev, const struct pci_device_id *id)

Function invoked by the PCI layer when it finds a match between a device ID for which it is seeking a driver and the id_table mentioned previously. This function should enable the hardware, allocate the net_device structure, and initialize and register the new device.[*] In this function, the driver also allocates any additional data structures (e.g., buffer rings used during transmission or reception) that it may need to work properly.
当PCI设备在设备ID中查找一个匹配的设备时,就调由PCI层调用这个函数。这个ID用于查找前面提到过的驱动和id_table。这个函数应该让硬件使能,分配net_device结构,并初始化和注册新的设备。在这个函数中,驱动同样会分配一些让它正常工作的额外的数据结构(例如,用于数据传输和接收的缓存区)。

[*] NIC registration is covered in Chapter 8.

void (*remove)(struct pci_dev *dev)

Function invoked by the PCI layer when the driver is unregistered from the kernel or when a hot-pluggable device is removed. It is the counterpart of probe and is used to clean up any data structure and state.
当驱动从内核中移出,或者热插拨设备从系统中移走时,PCI层会调用这个函数。它是与探测器相对的功能,用于清除数据结构和状态。

Network devices use this function to release the allocated I/O ports and I/O memory, to unregister the device, and to free the net_device data structure and any other auxiliary data structure that could have been allocated by the device driver, usually in its probe function.
网络设备用这个函数来释放已经分配的IO端口和IO内存,反注册设备,并释放net_device数据结构和其它的可能已经分配给设备驱动的辅助数据结构,通常是它的探测函数。

int (*suspend)(struct pci_dev *dev, pm_message_t state)

int (*resume)(struct pci_dev *dev)

Functions invoked by the PCI layer when the system goes into suspend mode and when it is resumed, respectively. See the later section "Power Management and Wake-on-LAN."
这两个函数是系统进入挂起模式和从该模式中恢复时由PCI层调用的。


int (*enable_wake)(struct pci_dev *dev, u32 state, int enable)

With this function, a driver can enable or disable the capability of the device to wake the system up by generating specific Power Management Event signals. See the later section "Power Management and Wake-on-LAN."
利用这两个函数,一个驱动可以使能或者去使能设备生成特殊的电源管理事件来唤醒系统的能力。

struct pci_dynids dynids

Dynamic IDs. See the following section.
动态ID。

See the later section "Example of PCI NIC Driver Registration" for an example of initialization of a pci_driver instance.

 

转载于:https://www.cnblogs.com/WuCountry/archive/2009/03/02/1401818.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值