目錄: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.