当前位置: 技术问答>linux和unix
内核驱动中probe函数疑惑
来源: 互联网 发布时间:2016-10-31
本文导语: struct pcie_port_service_driver { const char *name; int (*probe) (struct pcie_device *dev); void (*remove) (struct pcie_device *dev); int (*suspend) (struct pcie_device *dev); int (*resume) (struct pcie_device *dev); /* Service Error Recovery Handler */ struct p...
struct pcie_port_service_driver {
const char *name;
int (*probe) (struct pcie_device *dev);
void (*remove) (struct pcie_device *dev);
int (*suspend) (struct pcie_device *dev);
int (*resume) (struct pcie_device *dev);
/* Service Error Recovery Handler */
struct pci_error_handlers *err_handler;
/* Link Reset Capability - AER service driver specific */
pci_ers_result_t (*reset_link) (struct pci_dev *dev);
int port_type; /* Type of the port this driver can handle */
u32 service; /* Port service this device represents */
struct device_driver driver;};
static struct pcie_port_service_driver hpdriver_portdrv = {
.name = PCIE_MODULE_NAME,
.port_type = PCIE_ANY_PORT,
.service = PCIE_PORT_SERVICE_HP,
.probe = pciehp_probe,
.remove = pciehp_remove,
#ifdef CONFIG_PM
.suspend = pciehp_suspend,
.resume = pciehp_resume,
#endif /* PM */
};
retval = pcie_port_service_register(&hpdriver_portdrv);
int pcie_port_service_register(struct pcie_port_service_driver *new)
{
new->driver.name = (char *)new->name;
new->driver.bus = &pcie_port_bus_type;
new->driver.probe = pcie_port_probe_service;
new->driver.remove = pcie_port_remove_service;
new->driver.shutdown = pcie_port_shutdown_service;
return driver_register(&new->driver);
}
请教内核pcie热插拔中定义了一个驱动数据结构里面有probe函数,这个结构中包含device_driver 结构其内部又有probe,它们什么关系啊?
|
是这样的,linux的驱动架构也是分层设计的,某个总线上会挂很多个设备,比如i2c,他下面有N个设备,那么I2C总线本身会有一个probe,然后这个probe会调用真正的某个驱动的probe,一层一层的调用,说到底从上往下看,所有的设备都是device,所有的驱动都是device_driver,可以没事的时候多研究一下代码,比别人跟你说理解更透彻。
|
内核中只有device,bus,driver.三个实体.pcie_port_service_driver也包含device_driver. 当你调用注册函数时,内核会一步一步的将这些pcie_port_service_driver下的probe传递到device_driver.最终调用最基本的 device,bus,driver,来完成任务.这其实就是做了封装,更加抽象.理解了之后不难