分类: LINUX
2008-09-07 16:09:02
Pci 驱动的加载
一
struct pci_dev { }
struct pci_driver {
struct list_head node;
char *name;
const struct pci_device_id *id_table; /* must be non-NULL for probe to be called */
}
int the include/linux/mod_devicetable.h
struct pci_device_id {
__u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
__u32 subvendor, subdevice; /* Subsystem ID's or PCI_ANY_ID */
__u32 class, class_mask; /* (class,subclass,prog-if) triplet */
kernel_ulong_t driver_data; /* Data private to the driver */
};
the kernle use the pci_device_id to know what devices the driver can handle
the pci_driver is to interact any device with the driver.
二 the use of the /sys filesystem
The /sys filesystem exports information about system buseds , includeing the various devices and relationships between them . /sys also allows an administrator to define new Ids for a given device driver so that besides the static Ids registered by the drivers with their pec_driver structures'id id_table vector, the kernel can use the userconfigured parameters
三example of PCI NIC Driver Registration
First , when the system boot, it creats a sort of database that associates each bus to a list of detected devices that use the bus. In this it use the pci_device_id[] structure . (by the time device drivers are loaded , the kernel has already build its database.)
SECOND , when the device driver is loaded , it registers with the PCI layer by calling pci_register_driver and providing its instance of pci_drivers.it thus creates the driver's device list .in addition ,
third
for each matching its pci_driver structure , the probe function creates and registers the associated net-work device.
第二
struct pci_bus {
struct list_head node; /* node in list of buses */
struct pci_bus *parent; /* parent bus this bridge is on */
struct list_head children; /* list of child buses */
struct list_head devices; /* list of devices on this bus */
struct pci_dev *self; /* bridge device as seen by parent */
struct resource *resource[PCI_BUS_NUM_RESOURCES];
/* address space routed to this bus */
struct pci_ops *ops; /* configuration access functions */
void *sysdata; /* hook for sys-specific extension */
struct proc_dir_entry *procdir; /* directory entry in /proc/bus/pci */
unsigned char number; /* bus number */
unsigned char primary; /* number of primary bridge */
unsigned char secondary; /* number of secondary bridge */
unsigned char subordinate; /* max number of subordinate buses */
char name[48];
unsigned short bridge_ctl; /* manage NO_ISA/FBB/et al behaviors */
pci_bus_flags_t bus_flags; /* Inherited by child busses */
}
struct pci_dev {
struct list_head global_list; /* node in list of all PCI devices */
struct list_head bus_list; /* node in per-bus list */
struct pci_bus *bus; /* bus this device is on */
struct pci_bus *subordinate; /* bus this device bridges to */
struct pci_driver *driver; /* which driver has allocated this device */
}
未完待续