linux下pcie设备驱动

来源:互联网 发布:计算机编程与维护 编辑:程序博客网 时间:2024/06/05 00:21

PCIE设备驱动与Platform设备驱动的对比学习

1、驱动模块结构

1) PCIE设备注册:module_pci_driver(xxxx_driver);

展开之后对应于

module_init(xxxx_driver)---->pci_register_drive(xxxx_driver)

module_exit(xxxx_driver)---->pci_unregister_drive(xxxx_driver)

因此也可以采用自己编写module_init(),module_exit()方式使用。

2) Platform设备注册:module_platform_driver(gpio_led_driver);

2、设备驱动结构体

1)pcie设备

static struct pci_driver xxxx_driver = {
.name= xxx, //名称
.id_table= xxxx_table,    //匹配的设备列表
.probe= xxxx_probe,
.remove = xxxx_remove,

....
};

2)Platform设备

static struct platform_driverxxxx_driver = {
.probe=
xxxx_probe,
.remove= xxxx_remove,
.driver = {
.name= "
xxxx",
.of_match_table = of_
xxxx
_match,//一般与设备树中的设备匹配
},
};

3、匹配设备表

1) pcie设备

static const structpci_device_id xxxx_table[] = {
{ PCI_DEVICE(PCI_VENDOR_ID, 0xnnnn) },

//内容为设备的号、厂商号,用于判别设备,与总线上扫描到的设备匹配
{ }
};
MODULE_DEVICE_TABLE(pci, xxxx_table);

2)Platform设备

static const struct of_device_id of_gpio_leds_match[] = {
{.compatible = "gpio-leds", },
/
/主要用于和设备树进行匹配

{},
};
MODULE_DEVICE_TABLE(of, of_gpio_leds_match);

4、Probe函数

1) pcie设备

static int xxxx_probe(struct pci_dev *pdev,
  const struct pci_device_id *id)

//pcie设备id:厂商号、设备号、类等信息

2)Platform设备

static int xxxx_probe(struct platform_device *pdev)

总结:

pcie设备驱动是注册在pcie总线的,对应的设备是通过pcie总线控制器管理,因此其设备与驱动的匹配方式与platform总线上不同;同样USB总线、I2C总线等与pcie总线相似,由总线负责匹配、驱动管理等工作。