声明:此文档只做学习交流使用,请勿用作其他商业用途
author:朝阳_tony 转载请注明出处:http://blog.csdn.net/linzhaolove
此文中源码可以去http://dpdk.org/dev 网页中下载;更多官方文档请访问http://dpdk.org
TAILQ_INIT(&driver_list); TAILQ_INIT(&device_list); uio_res_list = RTE_TAILQ_RESERVE_BY_IDX(RTE_TAILQ_PCI, uio_res_list);首先初始化下面struct rte_pci_device , struct rte_pci_driver两个结构体相关的链表,分别是pci 驱动和pci的设备;用来保存查询到的设备相关信息;还要预留一个uio相关结构体的列表;
TAILQ_HEAD(pci_device_list, rte_pci_device); /**< PCI devices in D-linked Q. */ TAILQ_HEAD(pci_driver_list, rte_pci_driver); /**< PCI drivers in D-linked Q. */ extern struct pci_driver_list driver_list; /**< Global list of PCI drivers. */ extern struct pci_device_list device_list; /**< Global list of PCI devices. */
/* for debug purposes, PCI can be disabled */ if (internal_config.no_pci) return 0;在一些调试的场合,或者不需要pci的场合,其实我们是不需要初始化pci设备的;
if (pci_scan() < 0)
dir = opendir(SYSFS_PCI_DEVICES);去打开/sys/bus/pci/devices目录,查询所有的pci设备;我可以用查看一下这个目录
# ls /sys/bus/pci/devices 0000:00:00.0 0000:00:11.0 0000:00:16.2 0000:00:1c.0 0000:00:1f.3 0000:1a:00.0这里有很多设备,我只是摘录了一些;
if (parse_pci_addr_format(e->d_name, sizeof(e->d_name), &domain, &bus, &devid, &function) != 0) continue;函数正确返回后,会分别存储的到 domain bus devid function 中, 如 0000:00:16.2 就分别是 domain=0000 bus =00 devid =16 function =2
if (pci_scan_one(dirname, domain, bus, devid, function) < 0)
dev->mem_resource.phys_addr = phys_addr; dev->mem_resource.len = end_addr - phys_addr + 1; dev->mem_resource.addr = NULL; /* not mapped for now */
/* device is valid, add in list */ TAILQ_INSERT_TAIL(&device_list, dev, next);