4 * Copyright(c) 2010-2013 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 #include <sys/types.h>
49 #include <sys/queue.h>
51 #include <sys/ioctl.h>
53 #include <rte_interrupts.h>
56 #include <rte_common.h>
57 #include <rte_launch.h>
58 #include <rte_memory.h>
59 #include <rte_memzone.h>
60 #include <rte_tailq.h>
62 #include <rte_eal_memconfig.h>
63 #include <rte_per_lcore.h>
64 #include <rte_lcore.h>
65 #include <rte_malloc.h>
66 #include <rte_string_fns.h>
67 #include <rte_debug.h>
69 #include "eal_filesystem.h"
70 #include "eal_private.h"
74 * PCI probing under linux
76 * This code is used to simulate a PCI probe by parsing information in
77 * sysfs. Moreover, when a registered driver matches a device, the
78 * kernel driver currently using it is unloaded and replaced by
79 * igb_uio module, which is a very minimal userland driver for Intel
80 * network card, only providing access to PCI BAR to applications, and
81 * enabling bus master.
91 #define PROC_MODULES "/proc/modules"
93 #define IGB_UIO_NAME "igb_uio"
95 #define UIO_DRV_PATH "/sys/bus/pci/drivers/%s"
97 /* maximum time to wait that /dev/uioX appears */
98 #define UIO_DEV_WAIT_TIMEOUT 3 /* seconds */
101 * For multi-process we need to reproduce all PCI mappings in secondary
102 * processes, so save them in a tailq.
104 struct uio_resource {
105 TAILQ_ENTRY(uio_resource) next;
107 struct rte_pci_addr pci_addr;
110 struct uio_map maps[PCI_MAX_RESOURCE];
113 TAILQ_HEAD(uio_res_list, uio_resource);
115 static struct uio_res_list *uio_res_list = NULL;
116 static int pci_parse_sysfs_value(const char *filename, uint64_t *val);
119 * Check that a kernel module is loaded. Returns 0 on success, or if the
120 * parameter is NULL, or -1 if the module is not loaded.
123 pci_uio_check_module(const char *module_name)
129 if (module_name == NULL)
132 f = fopen(PROC_MODULES, "r");
134 RTE_LOG(ERR, EAL, "Cannot open "PROC_MODULES": %s\n",
139 while(fgets(buf, sizeof(buf), f) != NULL) {
141 for (i = 0; i < sizeof(buf) && buf[i] != '\0'; i++) {
146 if (strncmp(buf, module_name, sizeof(buf)) == 0) {
155 /* bind a PCI to the kernel module driver */
157 pci_bind_device(struct rte_pci_device *dev, char dr_path[])
162 char dev_bind[PATH_MAX];
163 struct rte_pci_addr *loc = &dev->addr;
165 RTE_LOG(DEBUG, EAL, "bind PCI device "PCI_PRI_FMT"\n",
166 loc->domain, loc->bus, loc->devid, loc->function);
168 n = rte_snprintf(dev_bind, sizeof(dev_bind), "%s/bind", dr_path);
169 if ((n < 0) || (n >= (int)sizeof(buf))) {
170 RTE_LOG(ERR, EAL, "Cannot rte_snprintf device bind path\n");
174 f = fopen(dev_bind, "w");
176 RTE_LOG(ERR, EAL, "Cannot open %s\n", dev->previous_dr);
179 n = rte_snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n",
180 loc->domain, loc->bus, loc->devid, loc->function);
181 if ((n < 0) || (n >= (int)sizeof(buf))) {
182 RTE_LOG(ERR, EAL, "Cannot rte_snprintf PCI infos\n");
186 if (fwrite(buf, n, 1, f) == 0) {
191 RTE_LOG(DEBUG, EAL, "Device bound\n");
198 pci_uio_bind_device(struct rte_pci_device *dev, const char *module_name)
203 char uio_newid[PATH_MAX];
204 char uio_bind[PATH_MAX];
206 n = rte_snprintf(uio_newid, sizeof(uio_newid), UIO_DRV_PATH "/new_id", module_name);
207 if ((n < 0) || (n >= (int)sizeof(uio_newid))) {
208 RTE_LOG(ERR, EAL, "Cannot rte_snprintf uio_newid name\n");
212 n = rte_snprintf(uio_bind, sizeof(uio_bind), UIO_DRV_PATH, module_name);
213 if ((n < 0) || (n >= (int)sizeof(uio_bind))) {
214 RTE_LOG(ERR, EAL, "Cannot rte_snprintf uio_bind name\n");
218 n = rte_snprintf(buf, sizeof(buf), "%x %x\n",
219 dev->id.vendor_id, dev->id.device_id);
220 if ((n < 0) || (n >= (int)sizeof(buf))) {
221 RTE_LOG(ERR, EAL, "Cannot rte_snprintf vendor_id/device_id\n");
225 f = fopen(uio_newid, "w");
227 RTE_LOG(ERR, EAL, "Cannot open %s\n", uio_newid);
230 if (fwrite(buf, n, 1, f) == 0) {
236 pci_bind_device(dev, uio_bind);
242 * open devname: it can take some time to
243 * appear, so we wait some time before returning an error
245 static int uio_open(const char *devname)
249 for (n=0; n < UIO_DEV_WAIT_TIMEOUT*10; n++) {
250 fd = open(devname, O_RDWR);
261 /* map a particular resource from a file */
263 pci_mmap(int fd, void *addr, off_t offset, size_t size)
267 /* Map the PCI memory resource of device */
268 mapaddr = mmap(addr, size, PROT_READ | PROT_WRITE, MAP_SHARED,
270 if (mapaddr == MAP_FAILED || (addr != NULL && mapaddr != addr)) {
271 RTE_LOG(ERR, EAL, "%s(): cannot mmap %zd@0x%lx: %s\n",
272 __func__, size, offset, strerror(errno));
276 RTE_LOG(DEBUG, EAL, "PCI memory mapped at %p\n", mapaddr);
280 dev->intr_handle.fd = -1;
281 dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
286 #define OFF_MAX ((uint64_t)(off_t)-1)
288 pci_uio_get_mappings(const char *devname, struct uio_map maps[], size_t nb_maps)
291 char dirname[PATH_MAX];
292 char filename[PATH_MAX];
293 uint64_t offset, size;
295 for (i = 0; i != nb_maps; i++) {
297 /* check if map directory exists */
298 rte_snprintf(dirname, sizeof(dirname),
299 "%s/maps/map%u", devname, i);
301 if (access(dirname, F_OK) != 0)
304 /* get mapping offset */
305 rte_snprintf(filename, sizeof(filename),
306 "%s/offset", dirname);
307 if (pci_parse_sysfs_value(filename, &offset) < 0) {
309 "%s(): cannot parse offset of %s\n",
314 /* get mapping size */
315 rte_snprintf(filename, sizeof(filename),
317 if (pci_parse_sysfs_value(filename, &size) < 0) {
319 "%s(): cannot parse size of %s\n",
324 /* get mapping physical address */
325 rte_snprintf(filename, sizeof(filename),
327 if (pci_parse_sysfs_value(filename, &maps[i].phaddr) < 0) {
329 "%s(): cannot parse addr of %s\n",
334 if ((offset > OFF_MAX) || (size > SIZE_MAX)) {
336 "%s(): offset/size exceed system max value\n",
341 maps[i].offset = offset;
348 pci_uio_map_secondary(struct rte_pci_device *dev)
351 struct uio_resource *uio_res;
353 TAILQ_FOREACH(uio_res, uio_res_list, next) {
355 /* skip this element if it doesn't match our PCI address */
356 if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev->addr)))
359 for (i = 0; i != uio_res->nb_maps; i++) {
360 if (pci_map_resource(dev, uio_res->maps[i].addr,
362 (off_t)uio_res->maps[i].offset,
363 (size_t)uio_res->maps[i].size) !=
364 uio_res->maps[i].addr) {
366 "Cannot mmap device resource\n");
373 RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
377 /* map the PCI resource of a PCI device in virtual memory */
379 pci_uio_map_resource(struct rte_pci_device *dev)
384 char dirname[PATH_MAX];
385 char dirname2[PATH_MAX];
386 char devname[PATH_MAX]; /* contains the /dev/uioX */
393 struct rte_pci_addr *loc = &dev->addr;
394 struct uio_resource *uio_res;
395 struct uio_map *maps;
397 RTE_LOG(DEBUG, EAL, "map PCI resource for device "PCI_PRI_FMT"\n",
398 loc->domain, loc->bus, loc->devid, loc->function);
400 /* secondary processes - use already recorded details */
401 if (rte_eal_process_type() != RTE_PROC_PRIMARY)
402 return pci_uio_map_restore(dev);
404 /* depending on kernel version, uio can be located in uio/uioX
407 rte_snprintf(dirname, sizeof(dirname),
408 "/sys/bus/pci/devices/" PCI_PRI_FMT "/uio",
409 loc->domain, loc->bus, loc->devid, loc->function);
411 dir = opendir(dirname);
413 /* retry with the parent directory */
414 rte_snprintf(dirname, sizeof(dirname),
415 "/sys/bus/pci/devices/" PCI_PRI_FMT,
416 loc->domain, loc->bus, loc->devid, loc->function);
417 dir = opendir(dirname);
420 RTE_LOG(ERR, EAL, "Cannot opendir %s\n", dirname);
425 /* take the first file starting with "uio" */
426 while ((e = readdir(dir)) != NULL) {
427 int shortprefix_len = sizeof("uio") - 1; /* format could be uio%d ...*/
428 int longprefix_len = sizeof("uio:uio") - 1; /* ... or uio:uio%d */
431 if (strncmp(e->d_name, "uio", 3) != 0)
434 /* first try uio%d */
436 uio_num = strtoull(e->d_name + shortprefix_len, &endptr, 10);
437 if (errno == 0 && endptr != e->d_name) {
438 rte_snprintf(dirname2, sizeof(dirname2),
439 "%s/uio%u", dirname, uio_num);
443 /* then try uio:uio%d */
445 uio_num = strtoull(e->d_name + longprefix_len, &endptr, 10);
446 if (errno == 0 && endptr != e->d_name) {
447 rte_snprintf(dirname2, sizeof(dirname2),
448 "%s/uio:uio%u", dirname, uio_num);
454 /* No uio resource found */
456 RTE_LOG(WARNING, EAL, " "PCI_PRI_FMT" not managed by UIO driver, "
457 "skipping\n", loc->domain, loc->bus, loc->devid, loc->function);
461 /* allocate the mapping details for secondary processes*/
462 if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
464 "%s(): cannot store uio mmap details\n", __func__);
468 rte_snprintf(devname, sizeof(devname), "/dev/uio%u", uio_num);
469 rte_snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
470 memcpy(&uio_res->pci_addr, &dev->addr, sizeof(uio_res->pci_addr));
472 /* collect info about device mappings */
473 if ((nb_maps = pci_uio_get_mappings(dirname2, uio_res->maps,
474 sizeof (uio_res->maps) / sizeof (uio_res->maps[0])))
478 uio_res->nb_maps = nb_maps;
481 pagesz = sysconf(_SC_PAGESIZE);
483 maps = uio_res->maps;
484 for (i = 0; i != PCI_MAX_RESOURCE; i++) {
487 if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
490 for (j = 0; j != nb_maps && (phaddr != maps[j].phaddr ||
491 dev->mem_resource[i].len != maps[j].size);
495 /* if matching map is found, then use it */
498 if (maps[j].addr != NULL ||
499 (mapaddr = pci_map_resource(dev,
500 NULL, devname, (off_t)offset,
501 (size_t)maps[j].size)) == NULL) {
505 maps[j].addr = mapaddr;
506 maps[j].offset = offset;
507 dev->mem_resource[i].addr = mapaddr;
511 TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
516 /* parse the "resource" sysfs file */
517 #define IORESOURCE_MEM 0x00000200
520 pci_parse_sysfs_resource(const char *filename, struct rte_pci_device *dev)
524 union pci_resource_info {
530 char *ptrs[PCI_RESOURCE_FMT_NVAL];
533 uint64_t phys_addr, end_addr, flags;
535 f = fopen(filename, "r");
537 RTE_LOG(ERR, EAL, "Cannot open sysfs resource\n");
541 for (i = 0; i<PCI_MAX_RESOURCE; i++) {
543 if (fgets(buf, sizeof(buf), f) == NULL) {
544 RTE_LOG(ERR, EAL, "%s(): cannot read resource\n", __func__);
548 if (rte_strsplit(buf, sizeof(buf), res_info.ptrs, 3, ' ') != 3) {
549 RTE_LOG(ERR, EAL, "%s(): bad resource format\n", __func__);
553 phys_addr = strtoull(res_info.phys_addr, NULL, 16);
554 end_addr = strtoull(res_info.end_addr, NULL, 16);
555 flags = strtoull(res_info.flags, NULL, 16);
557 RTE_LOG(ERR, EAL, "%s(): bad resource format\n", __func__);
561 if (flags & IORESOURCE_MEM) {
562 dev->mem_resource[i].phys_addr = phys_addr;
563 dev->mem_resource[i].len = end_addr - phys_addr + 1;
564 /* not mapped for now */
565 dev->mem_resource[i].addr = NULL;
577 * parse a sysfs file containing one integer value
578 * different to the eal version, as it needs to work with 64-bit values
581 pci_parse_sysfs_value(const char *filename, uint64_t *val)
587 f = fopen(filename, "r");
589 RTE_LOG(ERR, EAL, "%s(): cannot open sysfs value %s\n",
594 if (fgets(buf, sizeof(buf), f) == NULL) {
595 RTE_LOG(ERR, EAL, "%s(): cannot read sysfs value %s\n",
600 *val = strtoull(buf, &end, 0);
601 if ((buf[0] == '\0') || (end == NULL) || (*end != '\n')) {
602 RTE_LOG(ERR, EAL, "%s(): cannot parse sysfs value %s\n",
611 /* Compare two PCI device addresses. */
613 pci_addr_comparison(struct rte_pci_addr *addr, struct rte_pci_addr *addr2)
615 uint64_t dev_addr = (addr->domain << 24) + (addr->bus << 16) + (addr->devid << 8) + addr->function;
616 uint64_t dev_addr2 = (addr2->domain << 24) + (addr2->bus << 16) + (addr2->devid << 8) + addr2->function;
618 if (dev_addr > dev_addr2)
625 /* Scan one pci sysfs entry, and fill the devices list from it. */
627 pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,
628 uint8_t devid, uint8_t function)
630 char filename[PATH_MAX];
632 struct rte_pci_device *dev;
634 dev = malloc(sizeof(*dev));
639 memset(dev, 0, sizeof(*dev));
640 dev->addr.domain = domain;
642 dev->addr.devid = devid;
643 dev->addr.function = function;
646 rte_snprintf(filename, sizeof(filename), "%s/vendor", dirname);
647 if (eal_parse_sysfs_value(filename, &tmp) < 0) {
651 dev->id.vendor_id = (uint16_t)tmp;
654 rte_snprintf(filename, sizeof(filename), "%s/device", dirname);
655 if (eal_parse_sysfs_value(filename, &tmp) < 0) {
659 dev->id.device_id = (uint16_t)tmp;
661 /* get subsystem_vendor id */
662 rte_snprintf(filename, sizeof(filename), "%s/subsystem_vendor",
664 if (eal_parse_sysfs_value(filename, &tmp) < 0) {
668 dev->id.subsystem_vendor_id = (uint16_t)tmp;
670 /* get subsystem_device id */
671 rte_snprintf(filename, sizeof(filename), "%s/subsystem_device",
673 if (eal_parse_sysfs_value(filename, &tmp) < 0) {
677 dev->id.subsystem_device_id = (uint16_t)tmp;
679 /* parse resources */
680 rte_snprintf(filename, sizeof(filename), "%s/resource", dirname);
681 if (pci_parse_sysfs_resource(filename, dev) < 0) {
682 RTE_LOG(ERR, EAL, "%s(): cannot parse resource\n", __func__);
687 /* device is valid, add in list (sorted) */
688 if (TAILQ_EMPTY(&device_list)) {
689 TAILQ_INSERT_TAIL(&device_list, dev, next);
692 struct rte_pci_device *dev2 = NULL;
694 TAILQ_FOREACH(dev2, &device_list, next) {
695 if (pci_addr_comparison(&dev->addr, &dev2->addr))
698 TAILQ_INSERT_BEFORE(dev2, dev, next);
702 TAILQ_INSERT_TAIL(&device_list, dev, next);
709 * split up a pci address into its constituent parts.
712 parse_pci_addr_format(const char *buf, int bufsize, uint16_t *domain,
713 uint8_t *bus, uint8_t *devid, uint8_t *function)
715 /* first split on ':' */
723 char *str[PCI_FMT_NVAL]; /* last element-separator is "." not ":" */
726 char *buf_copy = strndup(buf, bufsize);
727 if (buf_copy == NULL)
730 if (rte_strsplit(buf_copy, bufsize, splitaddr.str, PCI_FMT_NVAL, ':')
733 /* final split is on '.' between devid and function */
734 splitaddr.function = strchr(splitaddr.devid,'.');
735 if (splitaddr.function == NULL)
737 *splitaddr.function++ = '\0';
739 /* now convert to int values */
741 *domain = (uint16_t)strtoul(splitaddr.domain, NULL, 16);
742 *bus = (uint8_t)strtoul(splitaddr.bus, NULL, 16);
743 *devid = (uint8_t)strtoul(splitaddr.devid, NULL, 16);
744 *function = (uint8_t)strtoul(splitaddr.function, NULL, 10);
748 free(buf_copy); /* free the copy made with strdup */
756 * Scan the content of the PCI bus, and the devices in the devices
764 char dirname[PATH_MAX];
766 uint8_t bus, devid, function;
768 dir = opendir(SYSFS_PCI_DEVICES);
770 RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n",
771 __func__, strerror(errno));
775 while ((e = readdir(dir)) != NULL) {
776 if (e->d_name[0] == '.')
779 if (parse_pci_addr_format(e->d_name, sizeof(e->d_name), &domain,
780 &bus, &devid, &function) != 0)
783 rte_snprintf(dirname, sizeof(dirname), "%s/%s", SYSFS_PCI_DEVICES,
785 if (pci_scan_one(dirname, domain, bus, devid, function) < 0)
796 /* unbind kernel driver for this device */
798 pci_unbind_kernel_driver(struct rte_pci_device *dev)
802 char filename[PATH_MAX];
804 struct rte_pci_addr *loc = &dev->addr;
806 /* open /sys/bus/pci/devices/AAAA:BB:CC.D/driver */
807 rte_snprintf(filename, sizeof(filename),
808 SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/driver/unbind",
809 loc->domain, loc->bus, loc->devid, loc->function);
811 RTE_LOG(DEBUG, EAL, "unbind kernel driver %s\n", filename);
813 f = fopen(filename, "w");
814 if (f == NULL) /* device was not bound */
817 n = rte_snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n",
818 loc->domain, loc->bus, loc->devid, loc->function);
819 if ((n < 0) || (n >= (int)sizeof(buf))) {
820 RTE_LOG(ERR, EAL, "%s(): rte_snprintf failed\n", __func__);
823 if (fwrite(buf, n, 1, f) == 0) {
824 RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__,
838 pci_exit_process(struct rte_pci_device *dev)
840 if (munmap(dev->mem_resource.addr, dev->mem_resource.len) == -1){
841 RTE_LOG(ERR, EAL, "Error with munmap\n");
844 if (close(dev->intr_handle.fd) == -1){
845 RTE_LOG(ERR, EAL, "Error closing interrupt handle\n");
848 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
849 if (pci_unbind_kernel_driver(dev) < 0){
850 RTE_LOG(ERR, EAL, "Error unbinding\n");
853 if (pci_bind_device(dev, dev->previous_dr) < 0){
854 RTE_LOG(ERR, EAL, "Error binding\n");
863 pci_get_previous_driver_path(struct rte_pci_device *dev)
866 char dev_path[PATH_MAX];
867 char dr_path[PATH_MAX];
868 struct rte_pci_addr *loc = &dev->addr;
870 n = rte_snprintf(dev_path, sizeof(dev_path), SYSFS_PCI_DEVICES "/"
871 PCI_PRI_FMT "/driver", loc->domain, loc->bus, loc->devid, loc->function );
872 if ((n < 0) || (n >= (int)sizeof(dev_path)))
873 RTE_LOG(ERR, EAL, "Cannot rte_snprintf device filepath\n");
875 n = readlink(dev_path, dr_path, sizeof(dr_path));
876 if ((n < 0) || (n >= (int)sizeof(dr_path))){
877 RTE_LOG(ERR, EAL, "Cannot readlink driver filepath\n");
878 dev->previous_dr[0] = '\0';
883 if (dr_path[0] != '/')
884 n = rte_snprintf(dev->previous_dr, sizeof(dev->previous_dr),
885 SYSFS_PCI_DEVICES "/" PCI_PRI_FMT "/%s",
886 loc->domain, loc->bus, loc->devid, loc->function, dr_path);
888 n = rte_snprintf(dev->previous_dr, sizeof(dev->previous_dr),
890 if ((n < 0) || (n >= (int)sizeof(dev_path)))
891 RTE_LOG(ERR, EAL, "Cannot rte_snprintf driver filepath\n");
895 * If vendor/device ID match, call the devinit() function of the
899 rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev)
901 struct rte_pci_id *id_table;
902 const char *module_name = NULL;
905 if (dr->drv_flags & RTE_PCI_DRV_NEED_IGB_UIO)
906 module_name = IGB_UIO_NAME;
908 for (id_table = dr->id_table ; id_table->vendor_id != 0; id_table++) {
910 /* check if device's identifiers match the driver's ones */
911 if (id_table->vendor_id != dev->id.vendor_id &&
912 id_table->vendor_id != PCI_ANY_ID)
914 if (id_table->device_id != dev->id.device_id &&
915 id_table->device_id != PCI_ANY_ID)
917 if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id &&
918 id_table->subsystem_vendor_id != PCI_ANY_ID)
920 if (id_table->subsystem_device_id != dev->id.subsystem_device_id &&
921 id_table->subsystem_device_id != PCI_ANY_ID)
924 RTE_LOG(DEBUG, EAL, "probe driver: %x:%x %s\n", dev->id.vendor_id,
925 dev->id.device_id, dr->name);
927 /* reference driver structure */
930 /* no initialization when blacklisted, return without error */
931 if (dev->blacklisted)
934 /* Unbind PCI devices if needed */
935 if (module_name != NULL) {
937 if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
938 /* check that our driver is loaded */
939 if (uio_status != 0 &&
940 (uio_status = pci_uio_check_module(module_name)) != 0)
941 rte_exit(EXIT_FAILURE, "The %s module is required by the "
942 "%s driver\n", module_name, dr->name);
944 /* unbind current driver, bind ours */
945 pci_get_previous_driver_path(dev);
946 if (pci_unbind_kernel_driver(dev) < 0)
948 if (pci_uio_bind_device(dev, module_name) < 0)
951 /* map the NIC resources */
952 if (pci_uio_map_resource(dev) < 0)
955 /* just map the NIC resources */
956 if (pci_uio_map_resource(dev) < 0)
960 /* We always should have BAR0 mapped */
961 if (rte_eal_process_type() == RTE_PROC_PRIMARY &&
962 dev->mem_resource[0].addr == NULL) {
964 "%s(): BAR0 is not mapped\n",
969 /* reference driver structure */
972 /* call the driver devinit() function */
973 return dr->devinit(dr, dev);
978 /*Start the exit process for each dev in use*/
980 rte_eal_pci_exit(void)
982 struct rte_pci_device *dev = NULL;
984 TAILQ_FOREACH(dev, &device_list, next){
985 if (dev->previous_dr[0] == '\0')
987 if(pci_exit_process(dev) == 1)
988 RTE_LOG(ERR, EAL, "Exit process failure\n");
992 /* Init the PCI EAL subsystem */
994 rte_eal_pci_init(void)
996 TAILQ_INIT(&driver_list);
997 TAILQ_INIT(&device_list);
998 uio_res_list = RTE_TAILQ_RESERVE_BY_IDX(RTE_TAILQ_PCI, uio_res_list);
1000 /* for debug purposes, PCI can be disabled */
1001 if (internal_config.no_pci)
1004 if (pci_scan() < 0) {
1005 RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);