pci: move resource mapping to the PCI bus
[dpdk.git] / drivers / bus / pci / pci_common.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation.
3  * Copyright 2013-2014 6WIND S.A.
4  */
5
6 #include <string.h>
7 #include <inttypes.h>
8 #include <stdint.h>
9 #include <stdbool.h>
10 #include <stdlib.h>
11 #include <stdio.h>
12 #include <sys/queue.h>
13 #include <rte_errno.h>
14 #include <rte_interrupts.h>
15 #include <rte_log.h>
16 #include <rte_bus.h>
17 #include <rte_pci.h>
18 #include <rte_bus_pci.h>
19 #include <rte_per_lcore.h>
20 #include <rte_memory.h>
21 #include <rte_eal.h>
22 #include <rte_eal_paging.h>
23 #include <rte_string_fns.h>
24 #include <rte_common.h>
25 #include <rte_devargs.h>
26 #include <rte_vfio.h>
27
28 #include "private.h"
29
30
31 #define SYSFS_PCI_DEVICES "/sys/bus/pci/devices"
32
33 const char *rte_pci_get_sysfs_path(void)
34 {
35         const char *path = NULL;
36
37 #ifdef RTE_EXEC_ENV_LINUX
38         path = getenv("SYSFS_PCI_DEVICES");
39         if (path == NULL)
40                 return SYSFS_PCI_DEVICES;
41 #endif
42
43         return path;
44 }
45
46 static struct rte_devargs *
47 pci_devargs_lookup(const struct rte_pci_addr *pci_addr)
48 {
49         struct rte_devargs *devargs;
50         struct rte_pci_addr addr;
51
52         RTE_EAL_DEVARGS_FOREACH("pci", devargs) {
53                 devargs->bus->parse(devargs->name, &addr);
54                 if (!rte_pci_addr_cmp(pci_addr, &addr))
55                         return devargs;
56         }
57         return NULL;
58 }
59
60 void
61 pci_name_set(struct rte_pci_device *dev)
62 {
63         struct rte_devargs *devargs;
64
65         /* Each device has its internal, canonical name set. */
66         rte_pci_device_name(&dev->addr,
67                         dev->name, sizeof(dev->name));
68         devargs = pci_devargs_lookup(&dev->addr);
69         dev->device.devargs = devargs;
70         /* In blacklist mode, if the device is not blacklisted, no
71          * rte_devargs exists for it.
72          */
73         if (devargs != NULL)
74                 /* If an rte_devargs exists, the generic rte_device uses the
75                  * given name as its name.
76                  */
77                 dev->device.name = dev->device.devargs->name;
78         else
79                 /* Otherwise, it uses the internal, canonical form. */
80                 dev->device.name = dev->name;
81 }
82
83 /* map a particular resource from a file */
84 void *
85 pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
86                  int additional_flags)
87 {
88         void *mapaddr;
89
90         /* Map the PCI memory resource of device */
91         mapaddr = rte_mem_map(requested_addr, size,
92                 RTE_PROT_READ | RTE_PROT_WRITE,
93                 RTE_MAP_SHARED | additional_flags, fd, offset);
94         if (mapaddr == NULL) {
95                 RTE_LOG(ERR, EAL,
96                         "%s(): cannot map resource(%d, %p, 0x%zx, 0x%llx): %s (%p)\n",
97                         __func__, fd, requested_addr, size,
98                         (unsigned long long)offset,
99                         rte_strerror(rte_errno), mapaddr);
100                 mapaddr = MAP_FAILED; /* API uses mmap error code */
101         } else
102                 RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
103
104         return mapaddr;
105 }
106
107 /* unmap a particular resource */
108 void
109 pci_unmap_resource(void *requested_addr, size_t size)
110 {
111         if (requested_addr == NULL)
112                 return;
113
114         /* Unmap the PCI memory resource of device */
115         if (rte_mem_unmap(requested_addr, size)) {
116                 RTE_LOG(ERR, EAL, "%s(): cannot mem unmap(%p, %#zx): %s\n",
117                         __func__, requested_addr, size,
118                         rte_strerror(rte_errno));
119         } else
120                 RTE_LOG(DEBUG, EAL, "  PCI memory unmapped at %p\n",
121                                 requested_addr);
122 }
123 /*
124  * Match the PCI Driver and Device using the ID Table
125  */
126 int
127 rte_pci_match(const struct rte_pci_driver *pci_drv,
128               const struct rte_pci_device *pci_dev)
129 {
130         const struct rte_pci_id *id_table;
131
132         for (id_table = pci_drv->id_table; id_table->vendor_id != 0;
133              id_table++) {
134                 /* check if device's identifiers match the driver's ones */
135                 if (id_table->vendor_id != pci_dev->id.vendor_id &&
136                                 id_table->vendor_id != PCI_ANY_ID)
137                         continue;
138                 if (id_table->device_id != pci_dev->id.device_id &&
139                                 id_table->device_id != PCI_ANY_ID)
140                         continue;
141                 if (id_table->subsystem_vendor_id !=
142                     pci_dev->id.subsystem_vendor_id &&
143                     id_table->subsystem_vendor_id != PCI_ANY_ID)
144                         continue;
145                 if (id_table->subsystem_device_id !=
146                     pci_dev->id.subsystem_device_id &&
147                     id_table->subsystem_device_id != PCI_ANY_ID)
148                         continue;
149                 if (id_table->class_id != pci_dev->id.class_id &&
150                                 id_table->class_id != RTE_CLASS_ANY_ID)
151                         continue;
152
153                 return 1;
154         }
155
156         return 0;
157 }
158
159 /*
160  * If vendor/device ID match, call the probe() function of the
161  * driver.
162  */
163 static int
164 rte_pci_probe_one_driver(struct rte_pci_driver *dr,
165                          struct rte_pci_device *dev)
166 {
167         int ret;
168         bool already_probed;
169         struct rte_pci_addr *loc;
170
171         if ((dr == NULL) || (dev == NULL))
172                 return -EINVAL;
173
174         loc = &dev->addr;
175
176         /* The device is not blacklisted; Check if driver supports it */
177         if (!rte_pci_match(dr, dev))
178                 /* Match of device and driver failed */
179                 return 1;
180
181         RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
182                         loc->domain, loc->bus, loc->devid, loc->function,
183                         dev->device.numa_node);
184
185         /* no initialization when blacklisted, return without error */
186         if (dev->device.devargs != NULL &&
187                 dev->device.devargs->policy ==
188                         RTE_DEV_BLACKLISTED) {
189                 RTE_LOG(INFO, EAL, "  Device is blacklisted, not"
190                         " initializing\n");
191                 return 1;
192         }
193
194         if (dev->device.numa_node < 0) {
195                 RTE_LOG(WARNING, EAL, "  Invalid NUMA socket, default to 0\n");
196                 dev->device.numa_node = 0;
197         }
198
199         already_probed = rte_dev_is_probed(&dev->device);
200         if (already_probed && !(dr->drv_flags & RTE_PCI_DRV_PROBE_AGAIN)) {
201                 RTE_LOG(DEBUG, EAL, "Device %s is already probed\n",
202                                 dev->device.name);
203                 return -EEXIST;
204         }
205
206         RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
207                 dev->id.device_id, dr->driver.name);
208
209         /*
210          * reference driver structure
211          * This needs to be before rte_pci_map_device(), as it enables to use
212          * driver flags for adjusting configuration.
213          */
214         if (!already_probed) {
215                 enum rte_iova_mode dev_iova_mode;
216                 enum rte_iova_mode iova_mode;
217
218                 dev_iova_mode = pci_device_iova_mode(dr, dev);
219                 iova_mode = rte_eal_iova_mode();
220                 if (dev_iova_mode != RTE_IOVA_DC &&
221                     dev_iova_mode != iova_mode) {
222                         RTE_LOG(ERR, EAL, "  Expecting '%s' IOVA mode but current mode is '%s', not initializing\n",
223                                 dev_iova_mode == RTE_IOVA_PA ? "PA" : "VA",
224                                 iova_mode == RTE_IOVA_PA ? "PA" : "VA");
225                         return -EINVAL;
226                 }
227
228                 dev->driver = dr;
229         }
230
231         if (!already_probed && (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)) {
232                 /* map resources for devices that use igb_uio */
233                 ret = rte_pci_map_device(dev);
234                 if (ret != 0) {
235                         dev->driver = NULL;
236                         return ret;
237                 }
238         }
239
240         RTE_LOG(INFO, EAL, "Probe PCI driver: %s (%x:%x) device: "PCI_PRI_FMT" (socket %i)\n",
241                         dr->driver.name, dev->id.vendor_id, dev->id.device_id,
242                         loc->domain, loc->bus, loc->devid, loc->function,
243                         dev->device.numa_node);
244         /* call the driver probe() function */
245         ret = dr->probe(dr, dev);
246         if (already_probed)
247                 return ret; /* no rollback if already succeeded earlier */
248         if (ret) {
249                 dev->driver = NULL;
250                 if ((dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) &&
251                         /* Don't unmap if device is unsupported and
252                          * driver needs mapped resources.
253                          */
254                         !(ret > 0 &&
255                                 (dr->drv_flags & RTE_PCI_DRV_KEEP_MAPPED_RES)))
256                         rte_pci_unmap_device(dev);
257         } else {
258                 dev->device.driver = &dr->driver;
259         }
260
261         return ret;
262 }
263
264 /*
265  * If vendor/device ID match, call the remove() function of the
266  * driver.
267  */
268 static int
269 rte_pci_detach_dev(struct rte_pci_device *dev)
270 {
271         struct rte_pci_addr *loc;
272         struct rte_pci_driver *dr;
273         int ret = 0;
274
275         if (dev == NULL)
276                 return -EINVAL;
277
278         dr = dev->driver;
279         loc = &dev->addr;
280
281         RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
282                         loc->domain, loc->bus, loc->devid,
283                         loc->function, dev->device.numa_node);
284
285         RTE_LOG(DEBUG, EAL, "  remove driver: %x:%x %s\n", dev->id.vendor_id,
286                         dev->id.device_id, dr->driver.name);
287
288         if (dr->remove) {
289                 ret = dr->remove(dev);
290                 if (ret < 0)
291                         return ret;
292         }
293
294         /* clear driver structure */
295         dev->driver = NULL;
296         dev->device.driver = NULL;
297
298         if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING)
299                 /* unmap resources for devices that use igb_uio */
300                 rte_pci_unmap_device(dev);
301
302         return 0;
303 }
304
305 /*
306  * If vendor/device ID match, call the probe() function of all
307  * registered driver for the given device. Return < 0 if initialization
308  * failed, return 1 if no driver is found for this device.
309  */
310 static int
311 pci_probe_all_drivers(struct rte_pci_device *dev)
312 {
313         struct rte_pci_driver *dr = NULL;
314         int rc = 0;
315
316         if (dev == NULL)
317                 return -EINVAL;
318
319         FOREACH_DRIVER_ON_PCIBUS(dr) {
320                 rc = rte_pci_probe_one_driver(dr, dev);
321                 if (rc < 0)
322                         /* negative value is an error */
323                         return rc;
324                 if (rc > 0)
325                         /* positive value means driver doesn't support it */
326                         continue;
327                 return 0;
328         }
329         return 1;
330 }
331
332 /*
333  * Scan the content of the PCI bus, and call the probe() function for
334  * all registered drivers that have a matching entry in its id_table
335  * for discovered devices.
336  */
337 static int
338 pci_probe(void)
339 {
340         struct rte_pci_device *dev = NULL;
341         size_t probed = 0, failed = 0;
342         int ret = 0;
343
344         FOREACH_DEVICE_ON_PCIBUS(dev) {
345                 probed++;
346
347                 ret = pci_probe_all_drivers(dev);
348                 if (ret < 0) {
349                         if (ret != -EEXIST) {
350                                 RTE_LOG(ERR, EAL, "Requested device "
351                                         PCI_PRI_FMT " cannot be used\n",
352                                         dev->addr.domain, dev->addr.bus,
353                                         dev->addr.devid, dev->addr.function);
354                                 rte_errno = errno;
355                                 failed++;
356                         }
357                         ret = 0;
358                 }
359         }
360
361         return (probed && probed == failed) ? -1 : 0;
362 }
363
364 /* dump one device */
365 static int
366 pci_dump_one_device(FILE *f, struct rte_pci_device *dev)
367 {
368         int i;
369
370         fprintf(f, PCI_PRI_FMT, dev->addr.domain, dev->addr.bus,
371                dev->addr.devid, dev->addr.function);
372         fprintf(f, " - vendor:%x device:%x\n", dev->id.vendor_id,
373                dev->id.device_id);
374
375         for (i = 0; i != sizeof(dev->mem_resource) /
376                 sizeof(dev->mem_resource[0]); i++) {
377                 fprintf(f, "   %16.16"PRIx64" %16.16"PRIx64"\n",
378                         dev->mem_resource[i].phys_addr,
379                         dev->mem_resource[i].len);
380         }
381         return 0;
382 }
383
384 /* dump devices on the bus */
385 void
386 rte_pci_dump(FILE *f)
387 {
388         struct rte_pci_device *dev = NULL;
389
390         FOREACH_DEVICE_ON_PCIBUS(dev) {
391                 pci_dump_one_device(f, dev);
392         }
393 }
394
395 static int
396 pci_parse(const char *name, void *addr)
397 {
398         struct rte_pci_addr *out = addr;
399         struct rte_pci_addr pci_addr;
400         bool parse;
401
402         parse = (rte_pci_addr_parse(name, &pci_addr) == 0);
403         if (parse && addr != NULL)
404                 *out = pci_addr;
405         return parse == false;
406 }
407
408 /* register a driver */
409 void
410 rte_pci_register(struct rte_pci_driver *driver)
411 {
412         TAILQ_INSERT_TAIL(&rte_pci_bus.driver_list, driver, next);
413         driver->bus = &rte_pci_bus;
414 }
415
416 /* unregister a driver */
417 void
418 rte_pci_unregister(struct rte_pci_driver *driver)
419 {
420         TAILQ_REMOVE(&rte_pci_bus.driver_list, driver, next);
421         driver->bus = NULL;
422 }
423
424 /* Add a device to PCI bus */
425 void
426 rte_pci_add_device(struct rte_pci_device *pci_dev)
427 {
428         TAILQ_INSERT_TAIL(&rte_pci_bus.device_list, pci_dev, next);
429 }
430
431 /* Insert a device into a predefined position in PCI bus */
432 void
433 rte_pci_insert_device(struct rte_pci_device *exist_pci_dev,
434                       struct rte_pci_device *new_pci_dev)
435 {
436         TAILQ_INSERT_BEFORE(exist_pci_dev, new_pci_dev, next);
437 }
438
439 /* Remove a device from PCI bus */
440 static void
441 rte_pci_remove_device(struct rte_pci_device *pci_dev)
442 {
443         TAILQ_REMOVE(&rte_pci_bus.device_list, pci_dev, next);
444 }
445
446 static struct rte_device *
447 pci_find_device(const struct rte_device *start, rte_dev_cmp_t cmp,
448                 const void *data)
449 {
450         const struct rte_pci_device *pstart;
451         struct rte_pci_device *pdev;
452
453         if (start != NULL) {
454                 pstart = RTE_DEV_TO_PCI_CONST(start);
455                 pdev = TAILQ_NEXT(pstart, next);
456         } else {
457                 pdev = TAILQ_FIRST(&rte_pci_bus.device_list);
458         }
459         while (pdev != NULL) {
460                 if (cmp(&pdev->device, data) == 0)
461                         return &pdev->device;
462                 pdev = TAILQ_NEXT(pdev, next);
463         }
464         return NULL;
465 }
466
467 /*
468  * find the device which encounter the failure, by iterate over all device on
469  * PCI bus to check if the memory failure address is located in the range
470  * of the BARs of the device.
471  */
472 static struct rte_pci_device *
473 pci_find_device_by_addr(const void *failure_addr)
474 {
475         struct rte_pci_device *pdev = NULL;
476         uint64_t check_point, start, end, len;
477         int i;
478
479         check_point = (uint64_t)(uintptr_t)failure_addr;
480
481         FOREACH_DEVICE_ON_PCIBUS(pdev) {
482                 for (i = 0; i != RTE_DIM(pdev->mem_resource); i++) {
483                         start = (uint64_t)(uintptr_t)pdev->mem_resource[i].addr;
484                         len = pdev->mem_resource[i].len;
485                         end = start + len;
486                         if (check_point >= start && check_point < end) {
487                                 RTE_LOG(DEBUG, EAL, "Failure address %16.16"
488                                         PRIx64" belongs to device %s!\n",
489                                         check_point, pdev->device.name);
490                                 return pdev;
491                         }
492                 }
493         }
494         return NULL;
495 }
496
497 static int
498 pci_hot_unplug_handler(struct rte_device *dev)
499 {
500         struct rte_pci_device *pdev = NULL;
501         int ret = 0;
502
503         pdev = RTE_DEV_TO_PCI(dev);
504         if (!pdev)
505                 return -1;
506
507         switch (pdev->kdrv) {
508 #ifdef HAVE_VFIO_DEV_REQ_INTERFACE
509         case RTE_PCI_KDRV_VFIO:
510                 /*
511                  * vfio kernel module guaranty the pci device would not be
512                  * deleted until the user space release the resource, so no
513                  * need to remap BARs resource here, just directly notify
514                  * the req event to the user space to handle it.
515                  */
516                 rte_dev_event_callback_process(dev->name,
517                                                RTE_DEV_EVENT_REMOVE);
518                 break;
519 #endif
520         case RTE_PCI_KDRV_IGB_UIO:
521         case RTE_PCI_KDRV_UIO_GENERIC:
522         case RTE_PCI_KDRV_NIC_UIO:
523                 /* BARs resource is invalid, remap it to be safe. */
524                 ret = pci_uio_remap_resource(pdev);
525                 break;
526         default:
527                 RTE_LOG(DEBUG, EAL,
528                         "Not managed by a supported kernel driver, skipped\n");
529                 ret = -1;
530                 break;
531         }
532
533         return ret;
534 }
535
536 static int
537 pci_sigbus_handler(const void *failure_addr)
538 {
539         struct rte_pci_device *pdev = NULL;
540         int ret = 0;
541
542         pdev = pci_find_device_by_addr(failure_addr);
543         if (!pdev) {
544                 /* It is a generic sigbus error, no bus would handle it. */
545                 ret = 1;
546         } else {
547                 /* The sigbus error is caused of hot-unplug. */
548                 ret = pci_hot_unplug_handler(&pdev->device);
549                 if (ret) {
550                         RTE_LOG(ERR, EAL,
551                                 "Failed to handle hot-unplug for device %s",
552                                 pdev->name);
553                         ret = -1;
554                 }
555         }
556         return ret;
557 }
558
559 static int
560 pci_plug(struct rte_device *dev)
561 {
562         return pci_probe_all_drivers(RTE_DEV_TO_PCI(dev));
563 }
564
565 static int
566 pci_unplug(struct rte_device *dev)
567 {
568         struct rte_pci_device *pdev;
569         int ret;
570
571         pdev = RTE_DEV_TO_PCI(dev);
572         ret = rte_pci_detach_dev(pdev);
573         if (ret == 0) {
574                 rte_pci_remove_device(pdev);
575                 rte_devargs_remove(dev->devargs);
576                 free(pdev);
577         }
578         return ret;
579 }
580
581 static int
582 pci_dma_map(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
583 {
584         struct rte_pci_device *pdev = RTE_DEV_TO_PCI(dev);
585
586         if (!pdev || !pdev->driver) {
587                 rte_errno = EINVAL;
588                 return -1;
589         }
590         if (pdev->driver->dma_map)
591                 return pdev->driver->dma_map(pdev, addr, iova, len);
592         /**
593          *  In case driver don't provides any specific mapping
594          *  try fallback to VFIO.
595          */
596         if (pdev->kdrv == RTE_PCI_KDRV_VFIO)
597                 return rte_vfio_container_dma_map
598                                 (RTE_VFIO_DEFAULT_CONTAINER_FD, (uintptr_t)addr,
599                                  iova, len);
600         rte_errno = ENOTSUP;
601         return -1;
602 }
603
604 static int
605 pci_dma_unmap(struct rte_device *dev, void *addr, uint64_t iova, size_t len)
606 {
607         struct rte_pci_device *pdev = RTE_DEV_TO_PCI(dev);
608
609         if (!pdev || !pdev->driver) {
610                 rte_errno = EINVAL;
611                 return -1;
612         }
613         if (pdev->driver->dma_unmap)
614                 return pdev->driver->dma_unmap(pdev, addr, iova, len);
615         /**
616          *  In case driver don't provides any specific mapping
617          *  try fallback to VFIO.
618          */
619         if (pdev->kdrv == RTE_PCI_KDRV_VFIO)
620                 return rte_vfio_container_dma_unmap
621                                 (RTE_VFIO_DEFAULT_CONTAINER_FD, (uintptr_t)addr,
622                                  iova, len);
623         rte_errno = ENOTSUP;
624         return -1;
625 }
626
627 bool
628 rte_pci_ignore_device(const struct rte_pci_addr *pci_addr)
629 {
630         struct rte_devargs *devargs = pci_devargs_lookup(pci_addr);
631
632         switch (rte_pci_bus.bus.conf.scan_mode) {
633         case RTE_BUS_SCAN_WHITELIST:
634                 if (devargs && devargs->policy == RTE_DEV_WHITELISTED)
635                         return false;
636                 break;
637         case RTE_BUS_SCAN_UNDEFINED:
638         case RTE_BUS_SCAN_BLACKLIST:
639                 if (devargs == NULL ||
640                     devargs->policy != RTE_DEV_BLACKLISTED)
641                         return false;
642                 break;
643         }
644         return true;
645 }
646
647 enum rte_iova_mode
648 rte_pci_get_iommu_class(void)
649 {
650         enum rte_iova_mode iova_mode = RTE_IOVA_DC;
651         const struct rte_pci_device *dev;
652         const struct rte_pci_driver *drv;
653         bool devices_want_va = false;
654         bool devices_want_pa = false;
655         int iommu_no_va = -1;
656
657         FOREACH_DEVICE_ON_PCIBUS(dev) {
658                 /*
659                  * We can check this only once, because the IOMMU hardware is
660                  * the same for all of them.
661                  */
662                 if (iommu_no_va == -1)
663                         iommu_no_va = pci_device_iommu_support_va(dev)
664                                         ? 0 : 1;
665
666                 if (dev->kdrv == RTE_PCI_KDRV_UNKNOWN ||
667                     dev->kdrv == RTE_PCI_KDRV_NONE)
668                         continue;
669                 FOREACH_DRIVER_ON_PCIBUS(drv) {
670                         enum rte_iova_mode dev_iova_mode;
671
672                         if (!rte_pci_match(drv, dev))
673                                 continue;
674
675                         dev_iova_mode = pci_device_iova_mode(drv, dev);
676                         RTE_LOG(DEBUG, EAL, "PCI driver %s for device "
677                                 PCI_PRI_FMT " wants IOVA as '%s'\n",
678                                 drv->driver.name,
679                                 dev->addr.domain, dev->addr.bus,
680                                 dev->addr.devid, dev->addr.function,
681                                 dev_iova_mode == RTE_IOVA_DC ? "DC" :
682                                 (dev_iova_mode == RTE_IOVA_PA ? "PA" : "VA"));
683                         if (dev_iova_mode == RTE_IOVA_PA)
684                                 devices_want_pa = true;
685                         else if (dev_iova_mode == RTE_IOVA_VA)
686                                 devices_want_va = true;
687                 }
688         }
689         if (iommu_no_va == 1) {
690                 iova_mode = RTE_IOVA_PA;
691                 if (devices_want_va) {
692                         RTE_LOG(WARNING, EAL, "Some devices want 'VA' but IOMMU does not support 'VA'.\n");
693                         RTE_LOG(WARNING, EAL, "The devices that want 'VA' won't initialize.\n");
694                 }
695         } else if (devices_want_va && !devices_want_pa) {
696                 iova_mode = RTE_IOVA_VA;
697         } else if (devices_want_pa && !devices_want_va) {
698                 iova_mode = RTE_IOVA_PA;
699         } else {
700                 iova_mode = RTE_IOVA_DC;
701                 if (devices_want_va) {
702                         RTE_LOG(WARNING, EAL, "Some devices want 'VA' but forcing 'DC' because other devices want 'PA'.\n");
703                         RTE_LOG(WARNING, EAL, "Depending on the final decision by the EAL, not all devices may be able to initialize.\n");
704                 }
705         }
706         return iova_mode;
707 }
708
709 struct rte_pci_bus rte_pci_bus = {
710         .bus = {
711                 .scan = rte_pci_scan,
712                 .probe = pci_probe,
713                 .find_device = pci_find_device,
714                 .plug = pci_plug,
715                 .unplug = pci_unplug,
716                 .parse = pci_parse,
717                 .dma_map = pci_dma_map,
718                 .dma_unmap = pci_dma_unmap,
719                 .get_iommu_class = rte_pci_get_iommu_class,
720                 .dev_iterate = rte_pci_dev_iterate,
721                 .hot_unplug_handler = pci_hot_unplug_handler,
722                 .sigbus_handler = pci_sigbus_handler,
723         },
724         .device_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.device_list),
725         .driver_list = TAILQ_HEAD_INITIALIZER(rte_pci_bus.driver_list),
726 };
727
728 RTE_REGISTER_BUS(pci, rte_pci_bus.bus);