New upstream version 16.11.7
[deb_dpdk.git] / lib / librte_eal / linuxapp / eal / eal_pci.c
1 /*-
2  *   BSD LICENSE
3  *
4  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  *   All rights reserved.
6  *
7  *   Redistribution and use in source and binary forms, with or without
8  *   modification, are permitted provided that the following conditions
9  *   are met:
10  *
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
16  *       distribution.
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.
20  *
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.
32  */
33
34 #include <string.h>
35 #include <dirent.h>
36
37 #include <rte_log.h>
38 #include <rte_pci.h>
39 #include <rte_eal_memconfig.h>
40 #include <rte_malloc.h>
41 #include <rte_devargs.h>
42 #include <rte_memcpy.h>
43
44 #include "eal_filesystem.h"
45 #include "eal_private.h"
46 #include "eal_pci_init.h"
47
48 /**
49  * @file
50  * PCI probing under linux
51  *
52  * This code is used to simulate a PCI probe by parsing information in sysfs.
53  * When a registered device matches a driver, it is then initialized with
54  * IGB_UIO driver (or doesn't initialize, if the device wasn't bound to it).
55  */
56
57 /* unbind kernel driver for this device */
58 int
59 pci_unbind_kernel_driver(struct rte_pci_device *dev)
60 {
61         int n;
62         FILE *f;
63         char filename[PATH_MAX];
64         char buf[BUFSIZ];
65         struct rte_pci_addr *loc = &dev->addr;
66
67         /* open /sys/bus/pci/devices/AAAA:BB:CC.D/driver */
68         snprintf(filename, sizeof(filename),
69                 "%s/" PCI_PRI_FMT "/driver/unbind", pci_get_sysfs_path(),
70                 loc->domain, loc->bus, loc->devid, loc->function);
71
72         f = fopen(filename, "w");
73         if (f == NULL) /* device was not bound */
74                 return 0;
75
76         n = snprintf(buf, sizeof(buf), PCI_PRI_FMT "\n",
77                      loc->domain, loc->bus, loc->devid, loc->function);
78         if ((n < 0) || (n >= (int)sizeof(buf))) {
79                 RTE_LOG(ERR, EAL, "%s(): snprintf failed\n", __func__);
80                 goto error;
81         }
82         if (fwrite(buf, n, 1, f) == 0) {
83                 RTE_LOG(ERR, EAL, "%s(): could not write to %s\n", __func__,
84                                 filename);
85                 goto error;
86         }
87
88         fclose(f);
89         return 0;
90
91 error:
92         fclose(f);
93         return -1;
94 }
95
96 static int
97 pci_get_kernel_driver_by_path(const char *filename, char *dri_name,
98                               size_t len)
99 {
100         int count;
101         char path[PATH_MAX];
102         char *name;
103
104         if (!filename || !dri_name)
105                 return -1;
106
107         count = readlink(filename, path, PATH_MAX);
108         if (count >= PATH_MAX)
109                 return -1;
110
111         /* For device does not have a driver */
112         if (count < 0)
113                 return 1;
114
115         path[count] = '\0';
116
117         name = strrchr(path, '/');
118         if (name) {
119                 strlcpy(dri_name, name + 1, len);
120                 return 0;
121         }
122
123         return -1;
124 }
125
126 /* Map pci device */
127 int
128 rte_eal_pci_map_device(struct rte_pci_device *dev)
129 {
130         int ret = -1;
131
132         /* try mapping the NIC resources using VFIO if it exists */
133         switch (dev->kdrv) {
134         case RTE_KDRV_VFIO:
135 #ifdef VFIO_PRESENT
136                 if (pci_vfio_is_enabled())
137                         ret = pci_vfio_map_resource(dev);
138 #endif
139                 break;
140         case RTE_KDRV_IGB_UIO:
141         case RTE_KDRV_UIO_GENERIC:
142                 /* map resources for devices that use uio */
143                 ret = pci_uio_map_resource(dev);
144                 break;
145         default:
146                 RTE_LOG(DEBUG, EAL,
147                         "  Not managed by a supported kernel driver, skipped\n");
148                 ret = 1;
149                 break;
150         }
151
152         return ret;
153 }
154
155 /* Unmap pci device */
156 void
157 rte_eal_pci_unmap_device(struct rte_pci_device *dev)
158 {
159         /* try unmapping the NIC resources using VFIO if it exists */
160         switch (dev->kdrv) {
161         case RTE_KDRV_VFIO:
162                 RTE_LOG(ERR, EAL, "Hotplug doesn't support vfio yet\n");
163                 break;
164         case RTE_KDRV_IGB_UIO:
165         case RTE_KDRV_UIO_GENERIC:
166                 /* unmap resources for devices that use uio */
167                 pci_uio_unmap_resource(dev);
168                 break;
169         default:
170                 RTE_LOG(DEBUG, EAL,
171                         "  Not managed by a supported kernel driver, skipped\n");
172                 break;
173         }
174 }
175
176 void *
177 pci_find_max_end_va(void)
178 {
179         const struct rte_memseg *seg = rte_eal_get_physmem_layout();
180         const struct rte_memseg *last = seg;
181         unsigned i = 0;
182
183         for (i = 0; i < RTE_MAX_MEMSEG; i++, seg++) {
184                 if (seg->addr == NULL)
185                         break;
186
187                 if (seg->addr > last->addr)
188                         last = seg;
189
190         }
191         return RTE_PTR_ADD(last->addr, last->len);
192 }
193
194 /* parse one line of the "resource" sysfs file (note that the 'line'
195  * string is modified)
196  */
197 int
198 pci_parse_one_sysfs_resource(char *line, size_t len, uint64_t *phys_addr,
199         uint64_t *end_addr, uint64_t *flags)
200 {
201         union pci_resource_info {
202                 struct {
203                         char *phys_addr;
204                         char *end_addr;
205                         char *flags;
206                 };
207                 char *ptrs[PCI_RESOURCE_FMT_NVAL];
208         } res_info;
209
210         if (rte_strsplit(line, len, res_info.ptrs, 3, ' ') != 3) {
211                 RTE_LOG(ERR, EAL,
212                         "%s(): bad resource format\n", __func__);
213                 return -1;
214         }
215         errno = 0;
216         *phys_addr = strtoull(res_info.phys_addr, NULL, 16);
217         *end_addr = strtoull(res_info.end_addr, NULL, 16);
218         *flags = strtoull(res_info.flags, NULL, 16);
219         if (errno != 0) {
220                 RTE_LOG(ERR, EAL,
221                         "%s(): bad resource format\n", __func__);
222                 return -1;
223         }
224
225         return 0;
226 }
227
228 /* parse the "resource" sysfs file */
229 static int
230 pci_parse_sysfs_resource(const char *filename, struct rte_pci_device *dev)
231 {
232         FILE *f;
233         char buf[BUFSIZ];
234         int i;
235         uint64_t phys_addr, end_addr, flags;
236
237         f = fopen(filename, "r");
238         if (f == NULL) {
239                 RTE_LOG(ERR, EAL, "Cannot open sysfs resource\n");
240                 return -1;
241         }
242
243         for (i = 0; i<PCI_MAX_RESOURCE; i++) {
244
245                 if (fgets(buf, sizeof(buf), f) == NULL) {
246                         RTE_LOG(ERR, EAL,
247                                 "%s(): cannot read resource\n", __func__);
248                         goto error;
249                 }
250                 if (pci_parse_one_sysfs_resource(buf, sizeof(buf), &phys_addr,
251                                 &end_addr, &flags) < 0)
252                         goto error;
253
254                 if (flags & IORESOURCE_MEM) {
255                         dev->mem_resource[i].phys_addr = phys_addr;
256                         dev->mem_resource[i].len = end_addr - phys_addr + 1;
257                         /* not mapped for now */
258                         dev->mem_resource[i].addr = NULL;
259                 }
260         }
261         fclose(f);
262         return 0;
263
264 error:
265         fclose(f);
266         return -1;
267 }
268
269 /* Scan one pci sysfs entry, and fill the devices list from it. */
270 static int
271 pci_scan_one(const char *dirname, uint16_t domain, uint8_t bus,
272              uint8_t devid, uint8_t function)
273 {
274         char filename[PATH_MAX];
275         unsigned long tmp;
276         struct rte_pci_device *dev;
277         char driver[PATH_MAX];
278         int ret;
279
280         dev = malloc(sizeof(*dev));
281         if (dev == NULL)
282                 return -1;
283
284         memset(dev, 0, sizeof(*dev));
285         dev->addr.domain = domain;
286         dev->addr.bus = bus;
287         dev->addr.devid = devid;
288         dev->addr.function = function;
289
290         /* get vendor id */
291         snprintf(filename, sizeof(filename), "%s/vendor", dirname);
292         if (eal_parse_sysfs_value(filename, &tmp) < 0) {
293                 free(dev);
294                 return -1;
295         }
296         dev->id.vendor_id = (uint16_t)tmp;
297
298         /* get device id */
299         snprintf(filename, sizeof(filename), "%s/device", dirname);
300         if (eal_parse_sysfs_value(filename, &tmp) < 0) {
301                 free(dev);
302                 return -1;
303         }
304         dev->id.device_id = (uint16_t)tmp;
305
306         /* get subsystem_vendor id */
307         snprintf(filename, sizeof(filename), "%s/subsystem_vendor",
308                  dirname);
309         if (eal_parse_sysfs_value(filename, &tmp) < 0) {
310                 free(dev);
311                 return -1;
312         }
313         dev->id.subsystem_vendor_id = (uint16_t)tmp;
314
315         /* get subsystem_device id */
316         snprintf(filename, sizeof(filename), "%s/subsystem_device",
317                  dirname);
318         if (eal_parse_sysfs_value(filename, &tmp) < 0) {
319                 free(dev);
320                 return -1;
321         }
322         dev->id.subsystem_device_id = (uint16_t)tmp;
323
324         /* get class_id */
325         snprintf(filename, sizeof(filename), "%s/class",
326                  dirname);
327         if (eal_parse_sysfs_value(filename, &tmp) < 0) {
328                 free(dev);
329                 return -1;
330         }
331         /* the least 24 bits are valid: class, subclass, program interface */
332         dev->id.class_id = (uint32_t)tmp & RTE_CLASS_ANY_ID;
333
334         /* get max_vfs */
335         dev->max_vfs = 0;
336         snprintf(filename, sizeof(filename), "%s/max_vfs", dirname);
337         if (!access(filename, F_OK) &&
338             eal_parse_sysfs_value(filename, &tmp) == 0)
339                 dev->max_vfs = (uint16_t)tmp;
340         else {
341                 /* for non igb_uio driver, need kernel version >= 3.8 */
342                 snprintf(filename, sizeof(filename),
343                          "%s/sriov_numvfs", dirname);
344                 if (!access(filename, F_OK) &&
345                     eal_parse_sysfs_value(filename, &tmp) == 0)
346                         dev->max_vfs = (uint16_t)tmp;
347         }
348
349         /* get numa node */
350         snprintf(filename, sizeof(filename), "%s/numa_node",
351                  dirname);
352         if (access(filename, R_OK) != 0) {
353                 /* if no NUMA support, set default to 0 */
354                 dev->device.numa_node = 0;
355         } else {
356                 if (eal_parse_sysfs_value(filename, &tmp) < 0) {
357                         free(dev);
358                         return -1;
359                 }
360                 dev->device.numa_node = tmp;
361         }
362
363         /* parse resources */
364         snprintf(filename, sizeof(filename), "%s/resource", dirname);
365         if (pci_parse_sysfs_resource(filename, dev) < 0) {
366                 RTE_LOG(ERR, EAL, "%s(): cannot parse resource\n", __func__);
367                 free(dev);
368                 return -1;
369         }
370
371         /* parse driver */
372         snprintf(filename, sizeof(filename), "%s/driver", dirname);
373         ret = pci_get_kernel_driver_by_path(filename, driver, sizeof(driver));
374         if (ret < 0) {
375                 RTE_LOG(ERR, EAL, "Fail to get kernel driver\n");
376                 free(dev);
377                 return -1;
378         }
379
380         if (!ret) {
381                 if (!strcmp(driver, "vfio-pci"))
382                         dev->kdrv = RTE_KDRV_VFIO;
383                 else if (!strcmp(driver, "igb_uio"))
384                         dev->kdrv = RTE_KDRV_IGB_UIO;
385                 else if (!strcmp(driver, "uio_pci_generic"))
386                         dev->kdrv = RTE_KDRV_UIO_GENERIC;
387                 else
388                         dev->kdrv = RTE_KDRV_UNKNOWN;
389         } else
390                 dev->kdrv = RTE_KDRV_NONE;
391
392         /* device is valid, add in list (sorted) */
393         if (TAILQ_EMPTY(&pci_device_list)) {
394                 rte_eal_device_insert(&dev->device);
395                 TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
396         } else {
397                 struct rte_pci_device *dev2;
398                 int ret;
399
400                 TAILQ_FOREACH(dev2, &pci_device_list, next) {
401                         ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr);
402                         if (ret > 0)
403                                 continue;
404
405                         if (ret < 0) {
406                                 TAILQ_INSERT_BEFORE(dev2, dev, next);
407                                 rte_eal_device_insert(&dev->device);
408                         } else { /* already registered */
409                                 dev2->kdrv = dev->kdrv;
410                                 dev2->max_vfs = dev->max_vfs;
411                                 memmove(dev2->mem_resource, dev->mem_resource,
412                                         sizeof(dev->mem_resource));
413                                 free(dev);
414                         }
415                         return 0;
416                 }
417                 rte_eal_device_insert(&dev->device);
418                 TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
419         }
420
421         return 0;
422 }
423
424 int
425 pci_update_device(const struct rte_pci_addr *addr)
426 {
427         char filename[PATH_MAX];
428
429         snprintf(filename, sizeof(filename), "%s/" PCI_PRI_FMT,
430                  pci_get_sysfs_path(), addr->domain, addr->bus, addr->devid,
431                  addr->function);
432
433         return pci_scan_one(filename, addr->domain, addr->bus, addr->devid,
434                                 addr->function);
435 }
436
437 /*
438  * split up a pci address into its constituent parts.
439  */
440 static int
441 parse_pci_addr_format(const char *buf, int bufsize, uint16_t *domain,
442                 uint8_t *bus, uint8_t *devid, uint8_t *function)
443 {
444         /* first split on ':' */
445         union splitaddr {
446                 struct {
447                         char *domain;
448                         char *bus;
449                         char *devid;
450                         char *function;
451                 };
452                 char *str[PCI_FMT_NVAL]; /* last element-separator is "." not ":" */
453         } splitaddr;
454
455         char *buf_copy = strndup(buf, bufsize);
456         if (buf_copy == NULL)
457                 return -1;
458
459         if (rte_strsplit(buf_copy, bufsize, splitaddr.str, PCI_FMT_NVAL, ':')
460                         != PCI_FMT_NVAL - 1)
461                 goto error;
462         /* final split is on '.' between devid and function */
463         splitaddr.function = strchr(splitaddr.devid,'.');
464         if (splitaddr.function == NULL)
465                 goto error;
466         *splitaddr.function++ = '\0';
467
468         /* now convert to int values */
469         errno = 0;
470         *domain = (uint16_t)strtoul(splitaddr.domain, NULL, 16);
471         *bus = (uint8_t)strtoul(splitaddr.bus, NULL, 16);
472         *devid = (uint8_t)strtoul(splitaddr.devid, NULL, 16);
473         *function = (uint8_t)strtoul(splitaddr.function, NULL, 10);
474         if (errno != 0)
475                 goto error;
476
477         free(buf_copy); /* free the copy made with strdup */
478         return 0;
479 error:
480         free(buf_copy);
481         return -1;
482 }
483
484 /*
485  * Scan the content of the PCI bus, and the devices in the devices
486  * list
487  */
488 int
489 rte_eal_pci_scan(void)
490 {
491         struct dirent *e;
492         DIR *dir;
493         char dirname[PATH_MAX];
494         uint16_t domain;
495         uint8_t bus, devid, function;
496
497         dir = opendir(pci_get_sysfs_path());
498         if (dir == NULL) {
499                 RTE_LOG(ERR, EAL, "%s(): opendir failed: %s\n",
500                         __func__, strerror(errno));
501                 return -1;
502         }
503
504         while ((e = readdir(dir)) != NULL) {
505                 if (e->d_name[0] == '.')
506                         continue;
507
508                 if (parse_pci_addr_format(e->d_name, sizeof(e->d_name), &domain,
509                                 &bus, &devid, &function) != 0)
510                         continue;
511
512                 snprintf(dirname, sizeof(dirname), "%s/%s",
513                                 pci_get_sysfs_path(), e->d_name);
514                 if (pci_scan_one(dirname, domain, bus, devid, function) < 0)
515                         goto error;
516         }
517         closedir(dir);
518         return 0;
519
520 error:
521         closedir(dir);
522         return -1;
523 }
524
525 /* Read PCI config space. */
526 int rte_eal_pci_read_config(const struct rte_pci_device *device,
527                             void *buf, size_t len, off_t offset)
528 {
529         const struct rte_intr_handle *intr_handle = &device->intr_handle;
530
531         switch (intr_handle->type) {
532         case RTE_INTR_HANDLE_UIO:
533         case RTE_INTR_HANDLE_UIO_INTX:
534                 return pci_uio_read_config(intr_handle, buf, len, offset);
535
536 #ifdef VFIO_PRESENT
537         case RTE_INTR_HANDLE_VFIO_MSIX:
538         case RTE_INTR_HANDLE_VFIO_MSI:
539         case RTE_INTR_HANDLE_VFIO_LEGACY:
540                 return pci_vfio_read_config(intr_handle, buf, len, offset);
541 #endif
542         default:
543                 RTE_LOG(ERR, EAL,
544                         "Unknown handle type of fd %d\n",
545                                         intr_handle->fd);
546                 return -1;
547         }
548 }
549
550 /* Write PCI config space. */
551 int rte_eal_pci_write_config(const struct rte_pci_device *device,
552                              const void *buf, size_t len, off_t offset)
553 {
554         const struct rte_intr_handle *intr_handle = &device->intr_handle;
555
556         switch (intr_handle->type) {
557         case RTE_INTR_HANDLE_UIO:
558         case RTE_INTR_HANDLE_UIO_INTX:
559                 return pci_uio_write_config(intr_handle, buf, len, offset);
560
561 #ifdef VFIO_PRESENT
562         case RTE_INTR_HANDLE_VFIO_MSIX:
563         case RTE_INTR_HANDLE_VFIO_MSI:
564         case RTE_INTR_HANDLE_VFIO_LEGACY:
565                 return pci_vfio_write_config(intr_handle, buf, len, offset);
566 #endif
567         default:
568                 RTE_LOG(ERR, EAL,
569                         "Unknown handle type of fd %d\n",
570                                         intr_handle->fd);
571                 return -1;
572         }
573 }
574
575 #if defined(RTE_ARCH_X86)
576 static int
577 pci_ioport_map(struct rte_pci_device *dev, int bar __rte_unused,
578                struct rte_pci_ioport *p)
579 {
580         uint16_t start, end;
581         FILE *fp;
582         char *line = NULL;
583         char pci_id[16];
584         int found = 0;
585         size_t linesz;
586
587         snprintf(pci_id, sizeof(pci_id), PCI_PRI_FMT,
588                  dev->addr.domain, dev->addr.bus,
589                  dev->addr.devid, dev->addr.function);
590
591         fp = fopen("/proc/ioports", "r");
592         if (fp == NULL) {
593                 RTE_LOG(ERR, EAL, "%s(): can't open ioports\n", __func__);
594                 return -1;
595         }
596
597         while (getdelim(&line, &linesz, '\n', fp) > 0) {
598                 char *ptr = line;
599                 char *left;
600                 int n;
601
602                 n = strcspn(ptr, ":");
603                 ptr[n] = 0;
604                 left = &ptr[n + 1];
605
606                 while (*left && isspace(*left))
607                         left++;
608
609                 if (!strncmp(left, pci_id, strlen(pci_id))) {
610                         found = 1;
611
612                         while (*ptr && isspace(*ptr))
613                                 ptr++;
614
615                         sscanf(ptr, "%04hx-%04hx", &start, &end);
616
617                         break;
618                 }
619         }
620
621         free(line);
622         fclose(fp);
623
624         if (!found)
625                 return -1;
626
627         p->base = start;
628         RTE_LOG(DEBUG, EAL, "PCI Port IO found start=0x%x\n", start);
629
630         return 0;
631 }
632 #endif
633
634 int
635 rte_eal_pci_ioport_map(struct rte_pci_device *dev, int bar,
636                        struct rte_pci_ioport *p)
637 {
638         int ret = -1;
639
640         switch (dev->kdrv) {
641 #ifdef VFIO_PRESENT
642         case RTE_KDRV_VFIO:
643                 if (pci_vfio_is_enabled())
644                         ret = pci_vfio_ioport_map(dev, bar, p);
645                 break;
646 #endif
647         case RTE_KDRV_IGB_UIO:
648                 ret = pci_uio_ioport_map(dev, bar, p);
649                 break;
650         case RTE_KDRV_UIO_GENERIC:
651 #if defined(RTE_ARCH_X86)
652                 ret = pci_ioport_map(dev, bar, p);
653 #else
654                 ret = pci_uio_ioport_map(dev, bar, p);
655 #endif
656                 break;
657         case RTE_KDRV_NONE:
658 #if defined(RTE_ARCH_X86)
659                 ret = pci_ioport_map(dev, bar, p);
660 #endif
661                 break;
662         default:
663                 break;
664         }
665
666         if (!ret)
667                 p->dev = dev;
668
669         return ret;
670 }
671
672 void
673 rte_eal_pci_ioport_read(struct rte_pci_ioport *p,
674                         void *data, size_t len, off_t offset)
675 {
676         switch (p->dev->kdrv) {
677 #ifdef VFIO_PRESENT
678         case RTE_KDRV_VFIO:
679                 pci_vfio_ioport_read(p, data, len, offset);
680                 break;
681 #endif
682         case RTE_KDRV_IGB_UIO:
683                 pci_uio_ioport_read(p, data, len, offset);
684                 break;
685         case RTE_KDRV_UIO_GENERIC:
686                 pci_uio_ioport_read(p, data, len, offset);
687                 break;
688         case RTE_KDRV_NONE:
689 #if defined(RTE_ARCH_X86)
690                 pci_uio_ioport_read(p, data, len, offset);
691 #endif
692                 break;
693         default:
694                 break;
695         }
696 }
697
698 void
699 rte_eal_pci_ioport_write(struct rte_pci_ioport *p,
700                          const void *data, size_t len, off_t offset)
701 {
702         switch (p->dev->kdrv) {
703 #ifdef VFIO_PRESENT
704         case RTE_KDRV_VFIO:
705                 pci_vfio_ioport_write(p, data, len, offset);
706                 break;
707 #endif
708         case RTE_KDRV_IGB_UIO:
709                 pci_uio_ioport_write(p, data, len, offset);
710                 break;
711         case RTE_KDRV_UIO_GENERIC:
712                 pci_uio_ioport_write(p, data, len, offset);
713                 break;
714         case RTE_KDRV_NONE:
715 #if defined(RTE_ARCH_X86)
716                 pci_uio_ioport_write(p, data, len, offset);
717 #endif
718                 break;
719         default:
720                 break;
721         }
722 }
723
724 int
725 rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
726 {
727         int ret = -1;
728
729         switch (p->dev->kdrv) {
730 #ifdef VFIO_PRESENT
731         case RTE_KDRV_VFIO:
732                 if (pci_vfio_is_enabled())
733                         ret = pci_vfio_ioport_unmap(p);
734                 break;
735 #endif
736         case RTE_KDRV_IGB_UIO:
737                 ret = pci_uio_ioport_unmap(p);
738                 break;
739         case RTE_KDRV_UIO_GENERIC:
740 #if defined(RTE_ARCH_X86)
741                 ret = 0;
742 #else
743                 ret = pci_uio_ioport_unmap(p);
744 #endif
745                 break;
746         case RTE_KDRV_NONE:
747 #if defined(RTE_ARCH_X86)
748                 ret = 0;
749 #endif
750                 break;
751         default:
752                 break;
753         }
754
755         return ret;
756 }
757
758 /* Init the PCI EAL subsystem */
759 int
760 rte_eal_pci_init(void)
761 {
762         /* for debug purposes, PCI can be disabled */
763         if (internal_config.no_pci)
764                 return 0;
765
766         if (rte_eal_pci_scan() < 0) {
767                 RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);
768                 return -1;
769         }
770
771         return 0;
772 }