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