[dpdk-dev,v5,6/8] Move common functions in eal_pci.c

Message ID 1428608412-31191-7-git-send-email-rkerur@gmail.com (mailing list archive)
State Superseded, archived
Headers

Commit Message

Ravi Kerur April 9, 2015, 7:40 p.m. UTC
  Changes in v5
Rebase to latest code.
Removed RTE_EXEC_ENV_BSDAPP from earlier changes.

Changes in v4
Move common functions in eal_pci.c to librte_eal/common/
eal_common_pci.c file.

Following functions are moved to eal_common_pci.c file.

void *pci_map_resource(void *requested_addr, const int vfio_fd,
      const char *devname, off_t offset, size_t size);
int pci_addr_comparison(struct rte_pci_addr *addr,
                        struct rte_pci_addr *addr2);
int rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
                        struct rte_pci_device *dev);

Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in
common function.
Fix checkpatch warnings and errors.

Changes in v3
N/A

Changes in v2
N/A

Changes in v1
N/A

Signed-off-by: Ravi Kerur <rkerur@gmail.com>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c        | 122 ++++-----------------------
 lib/librte_eal/common/eal_common_pci.c     | 130 ++++++++++++++++++++++++++++-
 lib/librte_eal/common/eal_private.h        |  48 +++++++++++
 lib/librte_eal/linuxapp/eal/eal_pci.c      | 100 +---------------------
 lib/librte_eal/linuxapp/eal/eal_pci_init.h |   6 --
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c  |  36 ++------
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c |  17 ++--
 7 files changed, 212 insertions(+), 247 deletions(-)
  

Comments

Thomas Monjalon April 16, 2015, 9:02 a.m. UTC | #1
This patch is very sensible and difficult to follow.
I'm really afraid that some nasty bugs could be hidden.
Please could you try to split it in several steps?
Thanks

2015-04-09 12:40, Ravi Kerur:
> Changes in v5
> Rebase to latest code.
> Removed RTE_EXEC_ENV_BSDAPP from earlier changes.
> 
> Changes in v4
> Move common functions in eal_pci.c to librte_eal/common/
> eal_common_pci.c file.
> 
> Following functions are moved to eal_common_pci.c file.
> 
> void *pci_map_resource(void *requested_addr, const int vfio_fd,
>       const char *devname, off_t offset, size_t size);
> int pci_addr_comparison(struct rte_pci_addr *addr,
>                         struct rte_pci_addr *addr2);
> int rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
>                         struct rte_pci_device *dev);
> 
> Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in
> common function.
> Fix checkpatch warnings and errors.
> 
> Changes in v3
> N/A
> 
> Changes in v2
> N/A
> 
> Changes in v1
> N/A
> 
> Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> ---
>  lib/librte_eal/bsdapp/eal/eal_pci.c        | 122 ++++-----------------------
>  lib/librte_eal/common/eal_common_pci.c     | 130 ++++++++++++++++++++++++++++-
>  lib/librte_eal/common/eal_private.h        |  48 +++++++++++
>  lib/librte_eal/linuxapp/eal/eal_pci.c      | 100 +---------------------
>  lib/librte_eal/linuxapp/eal/eal_pci_init.h |   6 --
>  lib/librte_eal/linuxapp/eal/eal_pci_uio.c  |  36 ++------
>  lib/librte_eal/linuxapp/eal/eal_pci_vfio.c |  17 ++--
>  7 files changed, 212 insertions(+), 247 deletions(-)
  
Ravi Kerur April 16, 2015, 10:12 p.m. UTC | #2
On Thu, Apr 16, 2015 at 2:02 AM, Thomas Monjalon <thomas.monjalon@6wind.com>
wrote:

> This patch is very sensible and difficult to follow.
> I'm really afraid that some nasty bugs could be hidden.
> Please could you try to split it in several steps?
> Thanks
>

Sure, will drop eal_pci_uio.c and eal_pci_vfio.c  changes and will send out
new version.

>
> 2015-04-09 12:40, Ravi Kerur:
> > Changes in v5
> > Rebase to latest code.
> > Removed RTE_EXEC_ENV_BSDAPP from earlier changes.
> >
> > Changes in v4
> > Move common functions in eal_pci.c to librte_eal/common/
> > eal_common_pci.c file.
> >
> > Following functions are moved to eal_common_pci.c file.
> >
> > void *pci_map_resource(void *requested_addr, const int vfio_fd,
> >       const char *devname, off_t offset, size_t size);
> > int pci_addr_comparison(struct rte_pci_addr *addr,
> >                         struct rte_pci_addr *addr2);
> > int rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr,
> >                         struct rte_pci_device *dev);
> >
> > Use RTE_EXEC_ENV_BSDAPP to differentiate minor differences in
> > common function.
> > Fix checkpatch warnings and errors.
> >
> > Changes in v3
> > N/A
> >
> > Changes in v2
> > N/A
> >
> > Changes in v1
> > N/A
> >
> > Signed-off-by: Ravi Kerur <rkerur@gmail.com>
> > ---
> >  lib/librte_eal/bsdapp/eal/eal_pci.c        | 122
> ++++-----------------------
> >  lib/librte_eal/common/eal_common_pci.c     | 130
> ++++++++++++++++++++++++++++-
> >  lib/librte_eal/common/eal_private.h        |  48 +++++++++++
> >  lib/librte_eal/linuxapp/eal/eal_pci.c      | 100 +---------------------
> >  lib/librte_eal/linuxapp/eal/eal_pci_init.h |   6 --
> >  lib/librte_eal/linuxapp/eal/eal_pci_uio.c  |  36 ++------
> >  lib/librte_eal/linuxapp/eal/eal_pci_vfio.c |  17 ++--
> >  7 files changed, 212 insertions(+), 247 deletions(-)
>
>
  

Patch

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 30f0232..5669592 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -111,7 +111,7 @@  static struct rte_tailq_elem rte_uio_tailq = {
 EAL_REGISTER_TAILQ(rte_uio_tailq)
 
 /* unbind kernel driver for this device */
-static int
+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 "
@@ -119,45 +119,6 @@  pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 	return -ENOTSUP;
 }
 
-/* map a particular resource from a file */
-static void *
-pci_map_resource(void *requested_addr, const char *devname, off_t offset,
-		 size_t size)
-{
-	int fd;
-	void *mapaddr;
-
-	/*
-	 * 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;
-	}
-
-	/* Map the PCI memory resource of device */
-	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED, fd, offset);
-	close(fd);
-	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);
-		goto fail;
-	}
-
-	RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
-
-	return mapaddr;
-
-fail:
-	return NULL;
-}
-
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
@@ -172,10 +133,10 @@  pci_uio_map_secondary(struct rte_pci_device *dev)
 			continue;
 
 		for (i = 0; i != uio_res->nb_maps; i++) {
-			if (pci_map_resource(uio_res->maps[i].addr,
+			if (pci_map_resource(uio_res->maps[i].addr, INT_MIN,
 					     uio_res->path,
 					     (off_t)uio_res->maps[i].offset,
-					     (size_t)uio_res->maps[i].size)
+					     (size_t)uio_res->maps[i].size, 0)
 			    != uio_res->maps[i].addr) {
 				RTE_LOG(ERR, EAL,
 					"Cannot mmap device resource\n");
@@ -190,7 +151,7 @@  pci_uio_map_secondary(struct rte_pci_device *dev)
 }
 
 /* map the PCI resource of a PCI device in virtual memory */
-static int
+int
 pci_uio_map_resource(struct rte_pci_device *dev)
 {
 	int i, j;
@@ -257,8 +218,9 @@  pci_uio_map_resource(struct rte_pci_device *dev)
 		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(NULL, devname, (off_t)offset,
-						(size_t)maps[j].size)
+		    (mapaddr = pci_map_resource(NULL, INT_MIN, devname,
+						(off_t)offset,
+						(size_t)maps[j].size, 0)
 		    ) == NULL) {
 			rte_free(uio_res);
 			return (-1);
@@ -274,6 +236,13 @@  pci_uio_map_resource(struct rte_pci_device *dev)
 	return (0);
 }
 
+/* map the PCI resource of a PCI device in virtual memory */
+int
+pci_map_device(struct rte_pci_device *dev)
+{
+	return pci_uio_map_resource(dev);
+}
+
 /* 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)
@@ -426,68 +395,11 @@  error:
 }
 
 /*
- * If vendor/device ID match, call the devinit() function of the
- * driver.
+ * This function is a no-op in BSD.
  */
-int
-rte_eal_pci_probe_one_driver(struct rte_pci_driver *dr, struct rte_pci_device *dev)
+void
+pci_config_space_set(struct rte_pci_device *dev __rte_unused)
 {
-	struct rte_pci_id *id_table;
-	int ret;
-
-	for (id_table = dr->id_table ; id_table->vendor_id != 0; id_table++) {
-
-		/* 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;
-
-		struct rte_pci_addr *loc = &dev->addr;
-
-		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);
-
-		RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
-				dev->id.device_id, dr->name);
-
-		/* no initialization when blacklisted, return without error */
-		if (dev->devargs != NULL &&
-			dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) {
-
-			RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not initializing\n");
-			return 0;
-		}
-
-		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
-			/* map resources for devices that use igb_uio */
-			ret = pci_uio_map_resource(dev);
-			if (ret != 0)
-				return ret;
-		} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
-		           rte_eal_process_type() == RTE_PROC_PRIMARY) {
-			/* unbind current driver */
-			if (pci_unbind_kernel_driver(dev) < 0)
-				return -1;
-		}
-
-		/* reference driver structure */
-		dev->driver = dr;
-
-		/* call the driver devinit() function */
-		return dr->devinit(dr, dev);
-	}
-	/* return positive value if driver is not found */
-	return 1;
 }
 
 /* Init the PCI EAL subsystem */
diff --git a/lib/librte_eal/common/eal_common_pci.c b/lib/librte_eal/common/eal_common_pci.c
index 808b87b..f20fac7 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -61,10 +61,14 @@ 
  *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include <string.h>
-#include <inttypes.h>
-#include <stdint.h>
 #include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+#include <stdarg.h>
+#include <unistd.h>
+#include <sys/file.h>
+#include <stddef.h>
+#include <sys/mman.h>
 #include <stdio.h>
 #include <sys/queue.h>
 
@@ -300,3 +304,123 @@  rte_eal_pci_unregister(struct rte_pci_driver *driver)
 {
 	TAILQ_REMOVE(&pci_driver_list, driver, next);
 }
+
+/* map a particular resource from a file */
+void *
+pci_map_resource(void *requested_addr, const int vfio_fd,
+		const char *devname, off_t offset, size_t size,
+		int additional_flags)
+{
+	int fd;
+	void *mapaddr;
+
+	/*
+	 * For non VFIO environment, vfio_fd is INT_MIN.
+	 */
+	if (vfio_fd == INT_MIN) {
+		/*
+		 * 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));
+			return MAP_FAILED;
+		}
+	} else {
+		fd = vfio_fd;
+	}
+
+	/* Map the PCI memory resource of device */
+	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
+			MAP_SHARED | additional_flags, fd, offset);
+	/*
+	 * Close applies only for non VFIO.
+	 */
+	if (vfio_fd == INT_MIN)
+		close(fd);
+
+	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 ? devname : "vfio"), fd, requested_addr,
+		(unsigned long)size, (unsigned long)offset,
+		strerror(errno), mapaddr);
+	} else {
+		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
+	}
+
+	return mapaddr;
+}
+
+/*
+ * 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)
+{
+	int ret;
+	struct rte_pci_id *id_table;
+
+	for (id_table = dr->id_table ; id_table->vendor_id != 0; id_table++) {
+
+		/* 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;
+
+		struct rte_pci_addr *loc = &dev->addr;
+
+		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);
+
+		RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
+				dev->id.device_id, dr->name);
+
+		/* no initialization when blacklisted, return without error */
+		if (dev->devargs != NULL &&
+			dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) {
+			RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not initializing\n");
+			return 1;
+		}
+
+		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
+#ifdef RTE_PCI_CONFIG
+			/*
+			 * Set PCIe config space for high performance.
+			 * Return value can be ignored.
+			 */
+			pci_config_space_set(dev);
+#endif
+			/* map resources for devices that use igb_uio */
+			ret = pci_map_device(dev);
+			if (ret != 0)
+				return ret;
+		} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
+		           rte_eal_process_type() == RTE_PROC_PRIMARY) {
+			/* unbind current driver */
+			if (pci_unbind_kernel_driver(dev) < 0)
+				return -1;
+		}
+
+		/* reference driver structure */
+		dev->driver = dr;
+
+		/* call the driver devinit() function */
+		return dr->devinit(dr, dev);
+	}
+	/* return positive value if driver is not found */
+	return 1;
+}
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index fde1fc9..021b008 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -37,6 +37,7 @@ 
 #include <stdio.h>
 
 #include <rte_eal.h>
+#include <rte_pci.h>
 
 /**
  * Initialize the memzone subsystem (private to eal).
@@ -370,4 +371,51 @@  int rte_eal_hugepage_init(void);
  */
 int rte_eal_hugepage_attach(void);
 
+/**
+ * This function maps a particular resource from a file
+ *
+ * This function is private to the EAL.
+ */
+void *
+pci_map_resource(void *requested_addr, const int vfio_fd,
+		const char *devname, off_t offset, size_t size,
+		int additional_flags);
+
+/**
+ * This function maps PCI resource of a PCI
+ * device in virtual memory
+ *
+ * This function is private to the EAL.
+ */
+int
+pci_uio_map_resource(struct rte_pci_device *dev);
+
+/**
+ * This function unbinds kernel driver for this device
+ *
+ * This function is private to the EAL.
+ */
+int
+pci_unbind_kernel_driver(struct rte_pci_device *dev);
+
+/**
+ * This function maps resources for devices
+ * that use igb_uio on Linux and it's a
+ * wrapper for pci_uio_map_resource on BSD.
+ *
+ * This function is private to the EAL.
+ */
+int
+pci_map_device(struct rte_pci_device *dev);
+
+/**
+ * This function sets PCIe config space for
+ * high performance.
+ * It's a NO-OP on BSD.
+ *
+ * This function is private to the EAL.
+ */
+void
+pci_config_space_set(struct rte_pci_device *dev);
+
 #endif /* _EAL_PRIVATE_H_ */
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci.c b/lib/librte_eal/linuxapp/eal/eal_pci.c
index 9cb0ffd..8aad7e7 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci.c
@@ -57,7 +57,7 @@ 
  */
 
 /* unbind kernel driver for this device */
-static int
+int
 pci_unbind_kernel_driver(struct rte_pci_device *dev)
 {
 	int n;
@@ -142,29 +142,6 @@  pci_find_max_end_va(void)
 	return RTE_PTR_ADD(last->addr, last->len);
 }
 
-
-/* map a particular resource from a file */
-void *
-pci_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
-		 int additional_flags)
-{
-	void *mapaddr;
-
-	/* Map the PCI memory resource of device */
-	mapaddr = mmap(requested_addr, size, PROT_READ | PROT_WRITE,
-			MAP_SHARED | additional_flags, fd, offset);
-	if (mapaddr == MAP_FAILED) {
-		RTE_LOG(ERR, EAL, "%s(): cannot mmap(%d, %p, 0x%lx, 0x%lx): %s (%p)\n",
-			__func__, fd, requested_addr,
-			(unsigned long)size, (unsigned long)offset,
-			strerror(errno), mapaddr);
-	} else {
-		RTE_LOG(DEBUG, EAL, "  PCI memory mapped at %p\n", mapaddr);
-	}
-
-	return mapaddr;
-}
-
 /* unmap a particular resource */
 void
 pci_unmap_resource(void *requested_addr, size_t size)
@@ -549,7 +526,7 @@  pci_config_max_read_request_size(struct rte_pci_device *dev)
 	return 0;
 }
 
-static void
+void
 pci_config_space_set(struct rte_pci_device *dev)
 {
 	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
@@ -563,7 +540,7 @@  pci_config_space_set(struct rte_pci_device *dev)
 }
 #endif
 
-static int
+int
 pci_map_device(struct rte_pci_device *dev)
 {
 	int ret = -1;
@@ -616,77 +593,6 @@  pci_unmap_device(struct rte_pci_device *dev)
 }
 #endif /* RTE_LIBRTE_EAL_HOTPLUG */
 
-/*
- * 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)
-{
-	int ret;
-	struct rte_pci_id *id_table;
-
-	for (id_table = dr->id_table ; id_table->vendor_id != 0; id_table++) {
-
-		/* 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;
-
-		struct rte_pci_addr *loc = &dev->addr;
-
-		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);
-
-		RTE_LOG(DEBUG, EAL, "  probe driver: %x:%x %s\n", dev->id.vendor_id,
-				dev->id.device_id, dr->name);
-
-		/* no initialization when blacklisted, return without error */
-		if (dev->devargs != NULL &&
-			dev->devargs->type == RTE_DEVTYPE_BLACKLISTED_PCI) {
-			RTE_LOG(DEBUG, EAL, "  Device is blacklisted, not initializing\n");
-			return 1;
-		}
-
-		if (dr->drv_flags & RTE_PCI_DRV_NEED_MAPPING) {
-#ifdef RTE_PCI_CONFIG
-			/*
-			 * Set PCIe config space for high performance.
-			 * Return value can be ignored.
-			 */
-			pci_config_space_set(dev);
-#endif
-			/* map resources for devices that use igb_uio */
-			ret = pci_map_device(dev);
-			if (ret != 0)
-				return ret;
-		} else if (dr->drv_flags & RTE_PCI_DRV_FORCE_UNBIND &&
-		           rte_eal_process_type() == RTE_PROC_PRIMARY) {
-			/* unbind current driver */
-			if (pci_unbind_kernel_driver(dev) < 0)
-				return -1;
-		}
-
-		/* reference driver structure */
-		dev->driver = dr;
-
-		/* call the driver devinit() function */
-		return dr->devinit(dr, dev);
-	}
-	/* return positive value if driver is not found */
-	return 1;
-}
-
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
 /*
  * If vendor/device ID match, call the devuninit() function of the
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index aa7b755..b8556c3 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -65,12 +65,6 @@  TAILQ_HEAD(mapped_pci_res_list, mapped_pci_resource);
 extern void *pci_map_addr;
 void *pci_find_max_end_va(void);
 
-void *pci_map_resource(void *requested_addr, int fd, off_t offset,
-	       size_t size, int additional_flags);
-
-/* map IGB_UIO resource prototype */
-int pci_uio_map_resource(struct rte_pci_device *dev);
-
 void pci_unmap_resource(void *requested_addr, size_t size);
 
 #ifdef RTE_LIBRTE_EAL_HOTPLUG
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 2d1c69b..ad3f84f 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -48,6 +48,7 @@ 
 #include "rte_pci_dev_ids.h"
 #include "eal_filesystem.h"
 #include "eal_pci_init.h"
+#include "eal_private.h"
 
 void *pci_map_addr = NULL;
 
@@ -90,7 +91,7 @@  pci_uio_set_bus_master(int dev_fd)
 static int
 pci_uio_map_secondary(struct rte_pci_device *dev)
 {
-	int fd, i;
+	int i;
 	struct mapped_pci_resource *uio_res;
 	struct mapped_pci_res_list *uio_res_list = RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
 
@@ -101,18 +102,11 @@  pci_uio_map_secondary(struct rte_pci_device *dev)
 			continue;
 
 		for (i = 0; i != uio_res->nb_maps; i++) {
-			/*
-			 * open devname, to mmap it
-			 */
-			fd = open(uio_res->maps[i].path, O_RDWR);
-			if (fd < 0) {
-				RTE_LOG(ERR, EAL, "Cannot open %s: %s\n",
-					uio_res->maps[i].path, strerror(errno));
-				return -1;
-			}
 
-			void *mapaddr = pci_map_resource(uio_res->maps[i].addr,
-					fd, (off_t)uio_res->maps[i].offset,
+			void *mapaddr = pci_map_resource(
+					uio_res->maps[i].addr, INT_MIN,
+					uio_res->maps[i].path,
+					(off_t)uio_res->maps[i].offset,
 					(size_t)uio_res->maps[i].size, 0);
 			if (mapaddr != uio_res->maps[i].addr) {
 				if (mapaddr == MAP_FAILED)
@@ -126,11 +120,8 @@  pci_uio_map_secondary(struct rte_pci_device *dev)
 							uio_res->maps[i].path,
 							uio_res->maps[i].addr);
 
-				close(fd);
 				return -1;
 			}
-			/* fd is not needed in slave process, close it */
-			close(fd);
 		}
 		return 0;
 	}
@@ -330,7 +321,6 @@  pci_uio_map_resource(struct rte_pci_device *dev)
 	/* Map all BARs */
 	maps = uio_res->maps;
 	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
-		int fd;
 		int fail = 0;
 
 		/* skip empty BAR */
@@ -345,21 +335,11 @@  pci_uio_map_resource(struct rte_pci_device *dev)
 				loc->domain, loc->bus, loc->devid, loc->function,
 				i);
 
-		/*
-		 * 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));
-			return -1;
-		}
-
 		/* try mapping somewhere close to the end of hugepages */
 		if (pci_map_addr == NULL)
 			pci_map_addr = pci_find_max_end_va();
 
-		mapaddr = pci_map_resource(pci_map_addr, fd, 0,
+		mapaddr = pci_map_resource(pci_map_addr, INT_MIN, devname, 0,
 				(size_t)dev->mem_resource[i].len, 0);
 		if (mapaddr == MAP_FAILED)
 			fail = 1;
@@ -373,10 +353,8 @@  pci_uio_map_resource(struct rte_pci_device *dev)
 
 		if (fail) {
 			rte_free(uio_res);
-			close(fd);
 			return -1;
 		}
-		close(fd);
 
 		maps[map_idx].phaddr = dev->mem_resource[i].phys_addr;
 		maps[map_idx].size = dev->mem_resource[i].len;
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index aea1fb1..01250ae 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -48,6 +48,7 @@ 
 #include "eal_filesystem.h"
 #include "eal_pci_init.h"
 #include "eal_vfio.h"
+#include "eal_private.h"
 
 /**
  * @file
@@ -799,10 +800,11 @@  pci_vfio_map_resource(struct rte_pci_device *dev)
 			void *map_addr = NULL;
 			if (memreg[0].size) {
 				/* actual map of first part */
-				map_addr = pci_map_resource(bar_addr, vfio_dev_fd,
-							    memreg[0].offset,
-							    memreg[0].size,
-							    MAP_FIXED);
+				map_addr = pci_map_resource(bar_addr,
+						vfio_dev_fd, NULL,
+						memreg[0].offset,
+						memreg[0].size,
+						MAP_FIXED);
 			}
 
 			/* if there's a second part, try to map it */
@@ -810,9 +812,10 @@  pci_vfio_map_resource(struct rte_pci_device *dev)
 			    && memreg[1].offset && memreg[1].size) {
 				void *second_addr = RTE_PTR_ADD(bar_addr, memreg[1].offset);
 				map_addr = pci_map_resource(second_addr,
-							    vfio_dev_fd, memreg[1].offset,
-							    memreg[1].size,
-							    MAP_FIXED);
+						vfio_dev_fd, NULL,
+						memreg[1].offset,
+						memreg[1].size,
+						MAP_FIXED);
 			}
 
 			if (map_addr == MAP_FAILED || !map_addr) {