pci: introduce helpers for device name parsing/update
[dpdk.git] / lib / librte_eal / bsdapp / eal / eal_pci.c
index 7b04fa6..1d91c78 100644 (file)
@@ -1,13 +1,13 @@
 /*-
  *   BSD LICENSE
- * 
+ *
  *   Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
  *   All rights reserved.
- * 
+ *
  *   Redistribution and use in source and binary forms, with or without
  *   modification, are permitted provided that the following conditions
  *   are met:
- * 
+ *
  *     * Redistributions of source code must retain the above copyright
  *       notice, this list of conditions and the following disclaimer.
  *     * Redistributions in binary form must reproduce the above copyright
@@ -17,7 +17,7 @@
  *     * Neither the name of Intel Corporation nor the names of its
  *       contributors may be used to endorse or promote products derived
  *       from this software without specific prior written permission.
- * 
+ *
  *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 #include <sys/pciio.h>
 #include <dev/pci/pcireg.h>
 
+#if defined(RTE_ARCH_X86)
+#include <sys/types.h>
+#include <machine/cpufunc.h>
+#endif
+
 #include <rte_interrupts.h>
 #include <rte_log.h>
 #include <rte_pci.h>
@@ -58,7 +63,6 @@
 #include <rte_launch.h>
 #include <rte_memory.h>
 #include <rte_memzone.h>
-#include <rte_tailq.h>
 #include <rte_eal.h>
 #include <rte_eal_memconfig.h>
 #include <rte_per_lcore.h>
@@ -66,8 +70,8 @@
 #include <rte_malloc.h>
 #include <rte_string_fns.h>
 #include <rte_debug.h>
+#include <rte_devargs.h>
 
-#include "rte_pci_dev_ids.h"
 #include "eal_filesystem.h"
 #include "eal_private.h"
 
  * enabling bus master.
  */
 
-struct uio_map {
-       void *addr;
-       uint64_t offset;
-       uint64_t size;
-       uint64_t phaddr;
-};
-
-/*
- * For multi-process we need to reproduce all PCI mappings in secondary
- * processes, so save them in a tailq.
- */
-struct uio_resource {
-       TAILQ_ENTRY(uio_resource) next;
-
-       struct rte_pci_addr pci_addr;
-       char path[PATH_MAX];
-       size_t nb_maps;
-       struct uio_map maps[PCI_MAX_RESOURCE];
-};
-
-TAILQ_HEAD(uio_res_list, uio_resource);
-
-static struct uio_res_list *uio_res_list = NULL;
-
-/* forward prototype of function called in pci_switch_module below */
-static int pci_uio_map_resource(struct rte_pci_device *dev);
+/* unbind kernel driver for this device */
+int
+pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
+{
+       RTE_LOG(ERR, EAL, "RTE_PCI_DRV_FORCE_UNBIND flag is not implemented "
+               "for BSD\n");
+       return -ENOTSUP;
+}
 
-/* map a particular resource from a file */
-static void *
-pci_map_resource(struct rte_pci_device *dev, void *requested_addr, 
-               const char *devname, off_t offset, size_t size)
+/* Map pci device */
+int
+rte_eal_pci_map_device(struct rte_pci_device *dev)
 {
-       int fd;
-       void *mapaddr;
+       int ret = -1;
 
-       /*
-        * open devname, to mmap it
-        */
-       fd = open(devname, O_RDWR);
-       if (fd < 0) {
-               RTE_LOG(ERR, EAL, "Cannot open %s: %s\n", 
-                       devname, strerror(errno));
-               goto fail;
+       /* try mapping the NIC resources */
+       switch (dev->kdrv) {
+       case RTE_KDRV_NIC_UIO:
+               /* map resources for devices that use uio */
+               ret = pci_uio_map_resource(dev);
+               break;
+       default:
+               RTE_LOG(DEBUG, EAL,
+                       "  Not managed by a supported kernel driver, skipped\n");
+               ret = 1;
+               break;
        }
 
-       /* Map the PCI memory resource of device */
-       mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-                       MAP_SHARED, fd, offset);
-       if (mapaddr == MAP_FAILED ||
-                       (requested_addr != NULL && mapaddr != requested_addr)) {
-               RTE_LOG(ERR, EAL, "%s(): cannot mmap(%s(%d), %p, 0x%lx, 0x%lx):"
-                       " %s (%p)\n", __func__, devname, fd, requested_addr, 
-                       (unsigned long)size, (unsigned long)offset,
-                       strerror(errno), mapaddr);
-               close(fd);
-               goto fail;
-       }
+       return ret;
+}
 
-       if (rte_eal_process_type() == RTE_PROC_PRIMARY) {
-               /* save fd if in primary process */
-               dev->intr_handle.fd = fd;
-               dev->intr_handle.type = RTE_INTR_HANDLE_UIO;
-       } else {
-               /* fd is not needed in slave process, close it */
-               dev->intr_handle.fd = -1;
-               dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-               close(fd);
+/* Unmap pci device */
+void
+rte_eal_pci_unmap_device(struct rte_pci_device *dev)
+{
+       /* try unmapping the NIC resources */
+       switch (dev->kdrv) {
+       case RTE_KDRV_NIC_UIO:
+               /* unmap resources for devices that use uio */
+               pci_uio_unmap_resource(dev);
+               break;
+       default:
+               RTE_LOG(DEBUG, EAL,
+                       "  Not managed by a supported kernel driver, skipped\n");
+               break;
        }
-
-       RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
-
-       return mapaddr;
-
-fail:
-       dev->intr_handle.fd = -1;
-       dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-
-       return NULL;
 }
 
-#ifndef OFF_MAX
-#define OFF_MAX              ((uint64_t)(off_t)-1)
-#endif
-
-static int
-pci_uio_map_secondary(struct rte_pci_device *dev)
+void
+pci_uio_free_resource(struct rte_pci_device *dev,
+               struct mapped_pci_resource *uio_res)
 {
-        size_t i;
-        struct uio_resource *uio_res;
-       TAILQ_FOREACH(uio_res, uio_res_list, next) {
-               /* skip this element if it doesn't match our PCI address */
-               if (memcmp(&uio_res->pci_addr, &dev->addr, sizeof(dev->addr)))
-                       continue;
-                
-               for (i = 0; i != uio_res->nb_maps; i++) {
-                       if (pci_map_resource(dev, uio_res->maps[i].addr,
-                                       uio_res->path,
-                                       (off_t)uio_res->maps[i].offset,
-                                       (size_t)uio_res->maps[i].size) != 
-                                       uio_res->maps[i].addr) {
-                               RTE_LOG(ERR, EAL,
-                                       "Cannot mmap device resource\n");
-                               return (-1);
-                       }
-               }
-               return (0);
-       }
+       rte_free(uio_res);
 
-       RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
-       return -1;
+       if (dev->intr_handle.fd) {
+               close(dev->intr_handle.fd);
+               dev->intr_handle.fd = -1;
+               dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+       }
 }
 
-/* map the PCI resource of a PCI device in virtual memory */
-static int
-pci_uio_map_resource(struct rte_pci_device *dev)
+int
+pci_uio_alloc_resource(struct rte_pci_device *dev,
+               struct mapped_pci_resource **uio_res)
 {
-       int i, j;
        char devname[PATH_MAX]; /* contains the /dev/uioX */
-       void *mapaddr;
-       uint64_t phaddr;
-       uint64_t offset;
-       uint64_t pagesz;
-       struct rte_pci_addr *loc = &dev->addr;
-       struct uio_resource *uio_res;
-       struct uio_map *maps;
+       struct rte_pci_addr *loc;
 
-       dev->intr_handle.fd = -1;
+       loc = &dev->addr;
 
-       rte_snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u",
+       snprintf(devname, sizeof(devname), "/dev/uio@pci:%u:%u:%u",
                        dev->addr.bus, dev->addr.devid, dev->addr.function);
 
        if (access(devname, O_RDWR) < 0) {
                RTE_LOG(WARNING, EAL, "  "PCI_PRI_FMT" not managed by UIO driver, "
                                "skipping\n", loc->domain, loc->bus, loc->devid, loc->function);
-               return -1;
+               return 1;
        }
 
-       /* secondary processes - use already recorded details */
-       if ((rte_eal_process_type() != RTE_PROC_PRIMARY) &&
-               (dev->id.vendor_id != PCI_VENDOR_ID_QUMRANET))
-               return (pci_uio_map_secondary(dev));
-
-       if(dev->id.vendor_id == PCI_VENDOR_ID_QUMRANET) {
-               /* I/O port address already assigned */
-               /* rte_virtio_pmd does not need any other bar even if available */
-               return (0);
+       /* save fd if in primary process */
+       dev->intr_handle.fd = open(devname, O_RDWR);
+       if (dev->intr_handle.fd < 0) {
+               RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+                       devname, strerror(errno));
+               goto error;
        }
-       
+       dev->intr_handle.type = RTE_INTR_HANDLE_UIO;
+
        /* allocate the mapping details for secondary processes*/
-       if ((uio_res = rte_zmalloc("UIO_RES", sizeof (*uio_res), 0)) == NULL) {
+       *uio_res = rte_zmalloc("UIO_RES", sizeof(**uio_res), 0);
+       if (*uio_res == NULL) {
                RTE_LOG(ERR, EAL,
                        "%s(): cannot store uio mmap details\n", __func__);
-               return (-1);
+               goto error;
        }
 
-       rte_snprintf(uio_res->path, sizeof(uio_res->path), "%s", devname);
-       memcpy(&uio_res->pci_addr, &dev->addr, sizeof(uio_res->pci_addr));
+       snprintf((*uio_res)->path, sizeof((*uio_res)->path), "%s", devname);
+       memcpy(&(*uio_res)->pci_addr, &dev->addr, sizeof((*uio_res)->pci_addr));
 
+       return 0;
 
-       /* Map all BARs */
-       pagesz = sysconf(_SC_PAGESIZE);
-       maps = uio_res->maps;
-       for (i = uio_res->nb_maps = 0; i != PCI_MAX_RESOURCE; i++) {
+error:
+       pci_uio_free_resource(dev, *uio_res);
+       return -1;
+}
 
-               j = uio_res->nb_maps;
-               /* skip empty BAR */
-               if ((phaddr = dev->mem_resource[i].phys_addr) == 0)
-                       continue;
-               /* if matching map is found, then use it */
-               offset = i * pagesz;
-               maps[j].offset = offset;
-               maps[j].phaddr = dev->mem_resource[i].phys_addr;
-               maps[j].size = dev->mem_resource[i].len;
-               if (maps[j].addr != NULL ||
-                               (mapaddr = pci_map_resource(dev,
-                               NULL, devname, (off_t)offset,
-                               (size_t)maps[j].size)) == NULL) {
-                       rte_free(uio_res);
-                       return (-1);
-               }
+int
+pci_uio_map_resource_by_index(struct rte_pci_device *dev, int res_idx,
+               struct mapped_pci_resource *uio_res, int map_idx)
+{
+       int fd;
+       char *devname;
+       void *mapaddr;
+       uint64_t offset;
+       uint64_t pagesz;
+       struct pci_map *maps;
 
-               maps[j].addr = mapaddr;
-               uio_res->nb_maps++;
-               dev->mem_resource[i].addr = mapaddr;
+       maps = uio_res->maps;
+       devname = uio_res->path;
+       pagesz = sysconf(_SC_PAGESIZE);
+
+       /* allocate memory to keep path */
+       maps[map_idx].path = rte_malloc(NULL, strlen(devname) + 1, 0);
+       if (maps[map_idx].path == NULL) {
+               RTE_LOG(ERR, EAL, "Cannot allocate memory for path: %s\n",
+                               strerror(errno));
+               return -1;
        }
 
-       TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
+       /*
+        * open resource file, to mmap it
+        */
+       fd = open(devname, O_RDWR);
+       if (fd < 0) {
+               RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
+                               devname, strerror(errno));
+               goto error;
+       }
 
-       return (0);
-}
+       /* if matching map is found, then use it */
+       offset = res_idx * pagesz;
+       mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+                       (size_t)dev->mem_resource[res_idx].len, 0);
+       close(fd);
+       if (mapaddr == MAP_FAILED)
+               goto error;
 
-/* parse the "resource" sysfs file */
-#define IORESOURCE_MEM  0x00000200
+       maps[map_idx].phaddr = dev->mem_resource[res_idx].phys_addr;
+       maps[map_idx].size = dev->mem_resource[res_idx].len;
+       maps[map_idx].addr = mapaddr;
+       maps[map_idx].offset = offset;
+       strcpy(maps[map_idx].path, devname);
+       dev->mem_resource[res_idx].addr = mapaddr;
 
-/* Compare two PCI device addresses. */
-static int
-pci_addr_comparison(struct rte_pci_addr *addr, struct rte_pci_addr *addr2)
-{
-       uint64_t dev_addr = (addr->domain << 24) + (addr->bus << 16) + (addr->devid << 8) + addr->function;
-       uint64_t dev_addr2 = (addr2->domain << 24) + (addr2->bus << 16) + (addr2->devid << 8) + addr2->function;
+       return 0;
 
-       if (dev_addr > dev_addr2)
-               return 1;
-       else
-               return 0;
+error:
+       rte_free(maps[map_idx].path);
+       return -1;
 }
 
-
-/* Scan one pci sysfs entry, and fill the devices list from it. */
 static int
 pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
 {
@@ -326,13 +278,21 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
        /* get subsystem_device id */
        dev->id.subsystem_device_id = conf->pc_subdevice;
 
+       /* get class id */
+       dev->id.class_id = (conf->pc_class << 16) |
+                          (conf->pc_subclass << 8) |
+                          (conf->pc_progif);
+
        /* TODO: get max_vfs */
        dev->max_vfs = 0;
 
        /* FreeBSD has no NUMA support (yet) */
        dev->numa_node = 0;
 
-/* parse resources */
+       /* FreeBSD has only one pass through driver */
+       dev->kdrv = RTE_KDRV_NIC_UIO;
+
+       /* parse resources */
        switch (conf->pc_hdr & PCIM_HDRTYPE) {
        case PCIM_HDRTYPE_NORMAL:
                max = PCIR_MAX_BAR_0;
@@ -362,23 +322,33 @@ pci_scan_one(int dev_pci_fd, struct pci_conf *conf)
        }
 
        /* device is valid, add in list (sorted) */
-       if (TAILQ_EMPTY(&device_list)) {
-               TAILQ_INSERT_TAIL(&device_list, dev, next);
-       }       
+       if (TAILQ_EMPTY(&pci_device_list)) {
+               TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
+       }
        else {
                struct rte_pci_device *dev2 = NULL;
+               int ret;
 
-               TAILQ_FOREACH(dev2, &device_list, next) {
-                       if (pci_addr_comparison(&dev->addr, &dev2->addr))
+               TAILQ_FOREACH(dev2, &pci_device_list, next) {
+                       ret = rte_eal_compare_pci_addr(&dev->addr, &dev2->addr);
+                       if (ret > 0)
                                continue;
-                       else {
+                       else if (ret < 0) {
                                TAILQ_INSERT_BEFORE(dev2, dev, next);
                                return 0;
+                       } else { /* already registered */
+                               dev2->kdrv = dev->kdrv;
+                               dev2->max_vfs = dev->max_vfs;
+                               memmove(dev2->mem_resource,
+                                       dev->mem_resource,
+                                       sizeof(dev->mem_resource));
+                               free(dev);
+                               return 0;
                        }
                }
-               TAILQ_INSERT_TAIL(&device_list, dev, next);
+               TAILQ_INSERT_TAIL(&pci_device_list, dev, next);
        }
-                               
+
        return 0;
 
 skipdev:
@@ -390,10 +360,10 @@ skipdev:
  * Scan the content of the PCI bus, and add the devices in the devices
  * list. Call pci_scan_one() for each pci entry found.
  */
-static int
-pci_scan(void)
+int
+rte_eal_pci_scan(void)
 {
-       int fd = -1;
+       int fd;
        unsigned dev_count = 0;
        struct pci_conf matches[16];
        struct pci_conf_io conf_io = {
@@ -436,82 +406,277 @@ error:
        return -1;
 }
 
-/*
- * If vendor/device ID match, call the devinit() function of the
- * driver.
- */
 int
-rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev)
+pci_update_device(const struct rte_pci_addr *addr)
+{
+       int fd;
+       struct pci_conf matches[2];
+       struct pci_match_conf match = {
+               .pc_sel = {
+                       .pc_domain = addr->domain,
+                       .pc_bus = addr->bus,
+                       .pc_dev = addr->devid,
+                       .pc_func = addr->function,
+               },
+       };
+       struct pci_conf_io conf_io = {
+               .pat_buf_len = 0,
+               .num_patterns = 1,
+               .patterns = &match,
+               .match_buf_len = sizeof(matches),
+               .matches = &matches[0],
+       };
+
+       fd = open("/dev/pci", O_RDONLY);
+       if (fd < 0) {
+               RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
+               goto error;
+       }
+
+       if (ioctl(fd, PCIOCGETCONF, &conf_io) < 0) {
+               RTE_LOG(ERR, EAL, "%s(): error with ioctl on /dev/pci: %s\n",
+                               __func__, strerror(errno));
+               goto error;
+       }
+
+       if (conf_io.num_matches != 1)
+               goto error;
+
+       if (pci_scan_one(fd, &matches[0]) < 0)
+               goto error;
+
+       close(fd);
+
+       return 0;
+
+error:
+       if (fd >= 0)
+               close(fd);
+       return -1;
+}
+
+/* Read PCI config space. */
+int rte_eal_pci_read_config(const struct rte_pci_device *dev,
+                           void *buf, size_t len, off_t offset)
 {
-       struct rte_pci_id *id_table;
+       int fd = -1;
+       struct pci_io pi = {
+               .pi_sel = {
+                       .pc_domain = dev->addr.domain,
+                       .pc_bus = dev->addr.bus,
+                       .pc_dev = dev->addr.devid,
+                       .pc_func = dev->addr.function,
+               },
+               .pi_reg = offset,
+               .pi_width = len,
+       };
 
-       for (id_table = dr->id_table ; id_table->vendor_id != 0; id_table++) {
+       if (len == 3 || len > sizeof(pi.pi_data)) {
+               RTE_LOG(ERR, EAL, "%s(): invalid pci read length\n", __func__);
+               goto error;
+       }
 
-               /* check if device's identifiers match the driver's ones */
-               if (id_table->vendor_id != dev->id.vendor_id &&
-                               id_table->vendor_id != PCI_ANY_ID)
-                       continue;
-               if (id_table->device_id != dev->id.device_id &&
-                               id_table->device_id != PCI_ANY_ID)
-                       continue;
-               if (id_table->subsystem_vendor_id != dev->id.subsystem_vendor_id &&
-                               id_table->subsystem_vendor_id != PCI_ANY_ID)
-                       continue;
-               if (id_table->subsystem_device_id != dev->id.subsystem_device_id &&
-                               id_table->subsystem_device_id != PCI_ANY_ID)
-                       continue;
+       fd = open("/dev/pci", O_RDWR);
+       if (fd < 0) {
+               RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
+               goto error;
+       }
+
+       if (ioctl(fd, PCIOCREAD, &pi) < 0)
+               goto error;
+       close(fd);
 
-               struct rte_pci_addr *loc = &dev->addr;
+       memcpy(buf, &pi.pi_data, len);
+       return 0;
+
+ error:
+       if (fd >= 0)
+               close(fd);
+       return -1;
+}
+
+/* Write PCI config space. */
+int rte_eal_pci_write_config(const struct rte_pci_device *dev,
+                            const void *buf, size_t len, off_t offset)
+{
+       int fd = -1;
 
-               RTE_LOG(DEBUG, EAL, "PCI device "PCI_PRI_FMT" on NUMA socket %i\n",
-                               loc->domain, loc->bus, loc->devid, loc->function,
-                               dev->numa_node);
+       struct pci_io pi = {
+               .pi_sel = {
+                       .pc_domain = dev->addr.domain,
+                       .pc_bus = dev->addr.bus,
+                       .pc_dev = dev->addr.devid,
+                       .pc_func = dev->addr.function,
+               },
+               .pi_reg = offset,
+               .pi_data = *(const uint32_t *)buf,
+               .pi_width = len,
+       };
 
-               RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
-                               dev->id.device_id, dr->name);
+       if (len == 3 || len > sizeof(pi.pi_data)) {
+               RTE_LOG(ERR, EAL, "%s(): invalid pci read length\n", __func__);
+               goto error;
+       }
+
+       memcpy(&pi.pi_data, buf, len);
 
-               /* no initialization when blacklisted, return without error */
-               if (dev->blacklisted) {
-                       RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not initializing\n");
-                       return 0;
+       fd = open("/dev/pci", O_RDWR);
+       if (fd < 0) {
+               RTE_LOG(ERR, EAL, "%s(): error opening /dev/pci\n", __func__);
+               goto error;
+       }
+
+       if (ioctl(fd, PCIOCWRITE, &pi) < 0)
+               goto error;
+
+       close(fd);
+       return 0;
+
+ error:
+       if (fd >= 0)
+               close(fd);
+       return -1;
+}
+
+int
+rte_eal_pci_ioport_map(struct rte_pci_device *dev, int bar,
+                      struct rte_pci_ioport *p)
+{
+       int ret;
+
+       switch (dev->kdrv) {
+#if defined(RTE_ARCH_X86)
+       case RTE_KDRV_NIC_UIO:
+               if ((uintptr_t) dev->mem_resource[bar].addr <= UINT16_MAX) {
+                       p->base = (uintptr_t)dev->mem_resource[bar].addr;
+                       ret = 0;
+               } else
+                       ret = -1;
+               break;
+#endif
+       default:
+               ret = -1;
+               break;
+       }
+
+       if (!ret)
+               p->dev = dev;
+
+       return ret;
+}
+
+static void
+pci_uio_ioport_read(struct rte_pci_ioport *p,
+                   void *data, size_t len, off_t offset)
+{
+#if defined(RTE_ARCH_X86)
+       uint8_t *d;
+       int size;
+       unsigned short reg = p->base + offset;
+
+       for (d = data; len > 0; d += size, reg += size, len -= size) {
+               if (len >= 4) {
+                       size = 4;
+                       *(uint32_t *)d = inl(reg);
+               } else if (len >= 2) {
+                       size = 2;
+                       *(uint16_t *)d = inw(reg);
+               } else {
+                       size = 1;
+                       *d = inb(reg);
                }
+       }
+#else
+       RTE_SET_USED(p);
+       RTE_SET_USED(data);
+       RTE_SET_USED(len);
+       RTE_SET_USED(offset);
+#endif
+}
+
+void
+rte_eal_pci_ioport_read(struct rte_pci_ioport *p,
+                       void *data, size_t len, off_t offset)
+{
+       switch (p->dev->kdrv) {
+       case RTE_KDRV_NIC_UIO:
+               pci_uio_ioport_read(p, data, len, offset);
+               break;
+       default:
+               break;
+       }
+}
 
-               /* just map the NIC resources */
-               if (pci_uio_map_resource(dev) < 0)
-                       return -1;
-
-               /* We always should have BAR0 mapped */
-               if (rte_eal_process_type() == RTE_PROC_PRIMARY && 
-                       dev->mem_resource[0].addr == NULL) {
-                       RTE_LOG(ERR, EAL,
-                               "%s(): BAR0 is not mapped\n",
-                               __func__);
-                       return (-1);
+static void
+pci_uio_ioport_write(struct rte_pci_ioport *p,
+                    const void *data, size_t len, off_t offset)
+{
+#if defined(RTE_ARCH_X86)
+       const uint8_t *s;
+       int size;
+       unsigned short reg = p->base + offset;
+
+       for (s = data; len > 0; s += size, reg += size, len -= size) {
+               if (len >= 4) {
+                       size = 4;
+                       outl(*(const uint32_t *)s, reg);
+               } else if (len >= 2) {
+                       size = 2;
+                       outw(*(const uint16_t *)s, reg);
+               } else {
+                       size = 1;
+                       outb(*s, reg);
                }
-               /* reference driver structure */
-               dev->driver = dr;
+       }
+#else
+       RTE_SET_USED(p);
+       RTE_SET_USED(data);
+       RTE_SET_USED(len);
+       RTE_SET_USED(offset);
+#endif
+}
+
+void
+rte_eal_pci_ioport_write(struct rte_pci_ioport *p,
+                        const void *data, size_t len, off_t offset)
+{
+       switch (p->dev->kdrv) {
+       case RTE_KDRV_NIC_UIO:
+               pci_uio_ioport_write(p, data, len, offset);
+               break;
+       default:
+               break;
+       }
+}
+
+int
+rte_eal_pci_ioport_unmap(struct rte_pci_ioport *p)
+{
+       int ret;
 
-               /* call the driver devinit() function */
-               return dr->devinit(dr, dev);
+       switch (p->dev->kdrv) {
+#if defined(RTE_ARCH_X86)
+       case RTE_KDRV_NIC_UIO:
+               ret = 0;
+               break;
+#endif
+       default:
+               ret = -1;
+               break;
        }
-       /* return positive value if driver is not found */
-       return 1;
+
+       return ret;
 }
 
 /* Init the PCI EAL subsystem */
 int
 rte_eal_pci_init(void)
 {
-       TAILQ_INIT(&driver_list);
-       TAILQ_INIT(&device_list);
-       uio_res_list = RTE_TAILQ_RESERVE_BY_IDX(RTE_TAILQ_PCI, uio_res_list);
-
        /* for debug purposes, PCI can be disabled */
        if (internal_config.no_pci)
                return 0;
 
-       if (pci_scan() < 0) {
+       if (rte_eal_pci_scan() < 0) {
                RTE_LOG(ERR, EAL, "%s(): Cannot scan PCI bus\n", __func__);
                return -1;
        }