Linux驱动 probe函数调用

来源:互联网 发布:阿里云服务器好吗 编辑:程序博客网 时间:2024/05/20 02:26

参考:

http://blog.chinaunix.net/space.php?uid=15887868&do=blog&id=2758294

http://www.cnblogs.com/hoys/archive/2011/04/01/2002299.html
1,driver_register把驱动注册到总线 


2,驱动注册到总线的实现函数3,driver_attach()上面真正起作用的是__driver_attach:4,really_probe是我们真正要找的函数

5.drv->bus->match(dev, drv)

driver_probe_device(struct device_driver *drv, struct device *dev)会通过drv->bus->match()来匹配PCIE设备与相应的设备驱动。对于内核为2.6.27的bus驱动“pci_express”来说,是通过调用pcie_port_bus_match()实现驱动match的。

 

static int pcie_port_bus_match(struct device *dev, struct device_driver *drv){struct pcie_device *pciedev;struct pcie_port_service_driver *driver;if (drv->bus != &pcie_port_bus_type || dev->bus != &pcie_port_bus_type)return 0;pciedev = to_pcie_device(dev);driver = to_service_driver(drv);if (   (driver->id_table->vendor != PCI_ANY_ID && driver->id_table->vendor != pciedev->id.vendor) ||       (driver->id_table->device != PCI_ANY_ID &&driver->id_table->device != pciedev->id.device) ||       (driver->id_table->port_type != PCIE_ANY_PORT &&driver->id_table->port_type != pciedev->id.port_type) ||driver->id_table->service_type != pciedev->id.service_type )return 0;          // driver与pciedev的id_table匹配成功,才match成功;return 1;}
// id_table的结构定义如下,match时只关注vendor,device,port_type,service_typestruct pcie_port_service_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 */__u32 port_type, service_type;/* Port Entity */kernel_ulong_t driver_data;};

 

打印出的驱动设备信息如:

………………

[    0.588087] bus: 'platform': really_probe: bound device power.0to driverpower  //总线:platform  设备:power.0  驱动:power
[    0.661226] bus: 'platform': really_probe: bound device s3c24xx-pwm.0 to driver s3c24xx-pwm
[    0.678552] bus: 'platform': really_probe: bound device s3c24xx-pwm.1 to driver s3c24xx-pwm
[    0.695971] bus: 'platform': really_probe: bound device s3c24xx-pwm.2 to driver s3c24xx-pwm
[    0.713389 bus: 'platform': really_probe: bound device s3c24xx-pwm.3 to driver
……………………

原创粉丝点击