DPDK patches and discussions
 help / color / mirror / Atom feed
From: Tetsuya Mukawa <mukawa@igel.co.jp>
To: dev@dpdk.org
Subject: [dpdk-dev] [PATCH v2 14/15] eal: Consolidate pci uio functions of linuxapp and bsdapp
Date: Thu, 12 Mar 2015 19:17:53 +0900	[thread overview]
Message-ID: <1426155474-1596-15-git-send-email-mukawa@igel.co.jp> (raw)
In-Reply-To: <1426155474-1596-1-git-send-email-mukawa@igel.co.jp>

The patch consolidates below functions, and implement these
in eal_common_pci_uio.c.
 - pci_uio_map_secondary()
 - pci_uio_map_resource()
 - pci_uio_unmap()
 - pci_uio_find_resource()
 - pci_uio_unmap_resource()

Signed-off-by: Tetsuya Mukawa <mukawa@igel.co.jp>
---
 lib/librte_eal/bsdapp/eal/Makefile                 |   1 +
 lib/librte_eal/bsdapp/eal/eal_pci.c                | 111 +---------
 .../bsdapp/eal/include/exec-env/rte_interrupts.h   |   1 +
 lib/librte_eal/common/eal_common_pci_uio.c         | 226 +++++++++++++++++++++
 lib/librte_eal/common/eal_private.h                |  36 ++++
 lib/librte_eal/linuxapp/eal/Makefile               |   1 +
 lib/librte_eal/linuxapp/eal/eal_pci_init.h         |  11 +-
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c          | 184 +----------------
 8 files changed, 273 insertions(+), 298 deletions(-)
 create mode 100644 lib/librte_eal/common/eal_common_pci_uio.c

diff --git a/lib/librte_eal/bsdapp/eal/Makefile b/lib/librte_eal/bsdapp/eal/Makefile
index 2357cfa..1dec11e 100644
--- a/lib/librte_eal/bsdapp/eal/Makefile
+++ b/lib/librte_eal/bsdapp/eal/Makefile
@@ -68,6 +68,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_log.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_launch.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_pci.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_pci_uio.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_memory.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_tailqs.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_BSDAPP) += eal_common_errno.c
diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c b/lib/librte_eal/bsdapp/eal/eal_pci.c
index d7d6439..b6785d4 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -81,10 +81,6 @@
  * network card, only providing access to PCI BAR to applications, and
  * enabling bus master.
  */
-static struct rte_tailq_elem rte_uio_tailq = {
-	.name = "UIO_RESOURCE_LIST",
-};
-EAL_REGISTER_TAILQ(rte_uio_tailq)
 
 /* unbind kernel driver for this device */
 int
@@ -95,62 +91,7 @@ pci_unbind_kernel_driver(struct rte_pci_device *dev __rte_unused)
 	return -ENOTSUP;
 }
 
-static int
-pci_uio_map_secondary(struct rte_pci_device *dev)
-{
-	int i, fd;
-	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);
-
-	TAILQ_FOREACH(uio_res, uio_res_list, next) {
-
-		/* skip this element if it doesn't match our PCI address */
-		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
-			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,
-					(size_t)uio_res->maps[i].size, 0);
-			if (mapaddr != uio_res->maps[i].addr) {
-				if (mapaddr == MAP_FAILED)
-					RTE_LOG(ERR, EAL,
-						"Cannot mmap device resource "
-						"file %s: %s\n",
-						uio_res->maps[i].path,
-						strerror(errno));
-				else
-					RTE_LOG(ERR, EAL,
-						"Cannot mmap device resource "
-						"file %s to address: %p\n",
-						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;
-	}
-
-	RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
-	return 1;
-}
-
-static int
+int
 pci_uio_alloc_uio_resource(struct rte_pci_device *dev,
 		struct mapped_pci_resource **uio_res)
 {
@@ -197,7 +138,7 @@ pci_uio_alloc_uio_resource(struct rte_pci_device *dev,
 	return 0;
 }
 
-static int
+int
 pci_uio_map_uio_resource_by_index(struct rte_pci_device *dev, int res_idx,
 		struct mapped_pci_resource *uio_res, int map_idx)
 {
@@ -255,54 +196,6 @@ fail:
 	return -1;
 }
 
-/* map the PCI resource of a PCI device in virtual memory */
-int
-pci_uio_map_resource(struct rte_pci_device *dev)
-{
-	int i, map_idx, ret;
-	uint64_t phaddr;
-	struct mapped_pci_resource *uio_res = NULL;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-
-	/* secondary processes - use already recorded details */
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return pci_uio_map_secondary(dev);
-
-	/* allocate uio resource */
-	ret = pci_uio_alloc_uio_resource(dev, &uio_res);
-	if ((ret != 0) || (uio_res == NULL))
-		return ret;
-
-	/* Map all BARs */
-	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
-		/* skip empty BAR */
-		phaddr = dev->mem_resource[i].phys_addr;
-		if (phaddr == 0)
-			continue;
-
-		ret = pci_uio_map_uio_resource_by_index(dev, i,
-				uio_res, map_idx);
-		if (ret != 0)
-			goto fail;
-
-		map_idx++;
-	}
-
-	uio_res->nb_maps = map_idx;
-
-	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
-
-	return 0;
-
-fail:
-	rte_free(uio_res);
-	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)
diff --git a/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h b/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h
index 87a9cf6..d4c388f 100644
--- a/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h
+++ b/lib/librte_eal/bsdapp/eal/include/exec-env/rte_interrupts.h
@@ -48,6 +48,7 @@ enum rte_intr_handle_type {
 /** Handle for interrupts. */
 struct rte_intr_handle {
 	int fd;                          /**< file descriptor */
+	int uio_cfg_fd;                  /**< UIO config file descriptor */
 	enum rte_intr_handle_type type;  /**< handle type */
 };
 
diff --git a/lib/librte_eal/common/eal_common_pci_uio.c b/lib/librte_eal/common/eal_common_pci_uio.c
new file mode 100644
index 0000000..b9d7726
--- /dev/null
+++ b/lib/librte_eal/common/eal_common_pci_uio.c
@@ -0,0 +1,226 @@
+/*-
+ *   BSD LICENSE
+ *
+ *   Copyright(c) 2015 IGEL Co.,Ltd. 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
+ *       notice, this list of conditions and the following disclaimer in
+ *       the documentation and/or other materials provided with the
+ *       distribution.
+ *     * Neither the name of IGEL Co.,Ltd. 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
+ *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+ *   OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+ *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <fcntl.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <sys/mman.h>
+
+#include <rte_eal.h>
+#include <rte_tailq.h>
+#include <rte_log.h>
+#include <rte_malloc.h>
+
+#include "eal_private.h"
+
+static struct rte_tailq_elem rte_uio_tailq = {
+	.name = "UIO_RESOURCE_LIST",
+};
+EAL_REGISTER_TAILQ(rte_uio_tailq)
+
+static int
+pci_uio_map_secondary(struct rte_pci_device *dev)
+{
+	int i, fd;
+	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);
+
+	TAILQ_FOREACH(uio_res, uio_res_list, next) {
+
+		/* skip this element if it doesn't match our PCI address */
+		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
+			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,
+					(size_t)uio_res->maps[i].size, 0);
+			if (mapaddr != uio_res->maps[i].addr) {
+				if (mapaddr == MAP_FAILED)
+					RTE_LOG(ERR, EAL,
+						"Cannot mmap device resource "
+						"file %s: %s\n",
+						uio_res->maps[i].path,
+						strerror(errno));
+				else
+					RTE_LOG(ERR, EAL,
+						"Cannot mmap device resource "
+						"file %s to address: %p\n",
+						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;
+	}
+
+	RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
+	return 1;
+}
+
+/* map the PCI resource of a PCI device in virtual memory */
+int
+pci_uio_map_resource(struct rte_pci_device *dev)
+{
+	int i, map_idx, ret;
+	uint64_t phaddr;
+	struct mapped_pci_resource *uio_res = NULL;
+	struct mapped_pci_res_list *uio_res_list =
+			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
+
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.uio_cfg_fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+
+	/* secondary processes - use already recorded details */
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return pci_uio_map_secondary(dev);
+
+	/* allocate uio resource */
+	ret = pci_uio_alloc_uio_resource(dev, &uio_res);
+	if ((ret != 0) || (uio_res == NULL))
+		return ret;
+
+	/* Map all BARs */
+	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
+		/* skip empty BAR */
+		phaddr = dev->mem_resource[i].phys_addr;
+		if (phaddr == 0)
+			continue;
+
+		ret = pci_uio_map_uio_resource_by_index(dev, i,
+				uio_res, map_idx);
+		if (ret != 0)
+			goto fail;
+
+		map_idx++;
+	}
+
+	uio_res->nb_maps = map_idx;
+
+	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
+
+	return 0;
+
+fail:
+	rte_free(uio_res);
+	return -1;
+}
+
+#ifdef RTE_LIBRTE_EAL_HOTPLUG
+static void
+pci_uio_unmap(struct mapped_pci_resource *uio_res)
+{
+	int i;
+
+	if (uio_res == NULL)
+		return;
+
+	for (i = 0; i != uio_res->nb_maps; i++)
+		pci_unmap_resource(uio_res->maps[i].addr,
+				(size_t)uio_res->maps[i].size);
+}
+
+static struct mapped_pci_resource *
+pci_uio_find_resource(struct rte_pci_device *dev)
+{
+	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);
+
+	if (dev == NULL)
+		return NULL;
+
+	TAILQ_FOREACH(uio_res, uio_res_list, next) {
+
+		/* skip this element if it doesn't match our PCI address */
+		if (!rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
+			return uio_res;
+	}
+	return NULL;
+}
+
+/* unmap the PCI resource of a PCI device in virtual memory */
+void
+pci_uio_unmap_resource(struct rte_pci_device *dev)
+{
+	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);
+
+	if (dev == NULL)
+		return;
+
+	/* find an entry for the device */
+	uio_res = pci_uio_find_resource(dev);
+	if (uio_res == NULL)
+		return;
+
+	/* secondary processes - just free maps */
+	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
+		return pci_uio_unmap(uio_res);
+
+	TAILQ_REMOVE(uio_res_list, uio_res, next);
+
+	/* unmap all resources */
+	pci_uio_unmap(uio_res);
+
+	/* free uio resource */
+	rte_free(uio_res);
+
+	/* close fd if in primary process */
+	close(dev->intr_handle.fd);
+	if (dev->intr_handle.uio_cfg_fd >= 0)
+		close(dev->intr_handle.uio_cfg_fd);
+
+	dev->intr_handle.fd = -1;
+	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
+}
+#endif /* RTE_LIBRTE_EAL_HOTPLUG */
diff --git a/lib/librte_eal/common/eal_private.h b/lib/librte_eal/common/eal_private.h
index badb55c..8c4145a 100644
--- a/lib/librte_eal/common/eal_private.h
+++ b/lib/librte_eal/common/eal_private.h
@@ -35,6 +35,7 @@
 #define _EAL_PRIVATE_H_
 
 #include <stdio.h>
+#include <rte_pci.h>
 
 /**
  * Initialize the memzone subsystem (private to eal).
@@ -181,6 +182,41 @@ int pci_uio_map_resource(struct rte_pci_device *dev);
 void pci_uio_unmap_resource(struct rte_pci_device *dev);
 
 /**
+ * Allocate uio resource for PCI device
+ *
+ * This function is private to EAL.
+ *
+ * @param dev
+ *   PCI device to allocate uio resource
+ * @param uio_res
+ *   Pointer to uio resource.
+ *   If the function returns 0, the pointer will be filled.
+ * @return
+ *   0 on success, negative on error
+ */
+int pci_uio_alloc_uio_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource **uio_res);
+
+/**
+ * Map device memory to uio resource
+ *
+ * This function is private to EAL.
+ *
+ * @param dev
+ *   PCI device that has memory information.
+ * @param res_idx
+ *   Memory resource index of the PCI device.
+ * @param uio_res
+ *  uio resource that will keep mapping information.
+ * @param map_idx
+ *   Mapping information index of the uio resource.
+ * @return
+ *   0 on success, negative on error
+ */
+int pci_uio_map_uio_resource_by_index(struct rte_pci_device *dev, int res_idx,
+		struct mapped_pci_resource *uio_res, int map_idx);
+
+/**
  * Init tail queues for non-EAL library structures. This is to allow
  * the rings, mempools, etc. lists to be shared among multiple processes
  *
diff --git a/lib/librte_eal/linuxapp/eal/Makefile b/lib/librte_eal/linuxapp/eal/Makefile
index 23c2d48..a250662 100644
--- a/lib/librte_eal/linuxapp/eal/Makefile
+++ b/lib/librte_eal/linuxapp/eal/Makefile
@@ -80,6 +80,7 @@ SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_memzone.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_log.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_launch.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_pci.c
+SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_pci_uio.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_memory.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_tailqs.c
 SRCS-$(CONFIG_RTE_LIBRTE_EAL_LINUXAPP) += eal_common_errno.c
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_init.h b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
index d426b27..90409b3 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_init.h
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_init.h
@@ -42,13 +42,10 @@
 extern void *pci_map_addr;
 void *pci_find_max_end_va(void);
 
-/* map IGB_UIO resource prototype */
-int pci_uio_map_resource(struct rte_pci_device *dev);
-
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-/* unmap IGB_UIO resource prototype */
-void pci_uio_unmap_resource(struct rte_pci_device *dev);
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
+int pci_uio_alloc_uio_resource(struct rte_pci_device *dev,
+		struct mapped_pci_resource **uio_res);
+int pci_uio_map_uio_resource_by_index(struct rte_pci_device *dev, int res_idx,
+		struct mapped_pci_resource *uio_res, int map_idx);
 
 #ifdef VFIO_PRESENT
 
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 6fca796..6abc639 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -51,11 +51,6 @@
 
 void *pci_map_addr = NULL;
 
-static struct rte_tailq_elem rte_uio_tailq = {
-	.name = "UIO_RESOURCE_LIST",
-};
-EAL_REGISTER_TAILQ(rte_uio_tailq)
-
 #define OFF_MAX              ((uint64_t)(off_t)-1)
 
 static int
@@ -88,61 +83,6 @@ pci_uio_set_bus_master(int dev_fd)
 }
 
 static int
-pci_uio_map_secondary(struct rte_pci_device *dev)
-{
-	int fd, 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);
-
-	TAILQ_FOREACH(uio_res, uio_res_list, next) {
-
-		/* skip this element if it doesn't match our PCI address */
-		if (rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
-			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,
-					(size_t)uio_res->maps[i].size, 0);
-			if (mapaddr != uio_res->maps[i].addr) {
-				if (mapaddr == MAP_FAILED)
-					RTE_LOG(ERR, EAL,
-						"Cannot mmap device resource "
-						"file %s: %s\n",
-						uio_res->maps[i].path,
-						strerror(errno));
-				else
-					RTE_LOG(ERR, EAL,
-						"Cannot mmap device resource "
-						"file %s to address: %p\n",
-						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;
-	}
-
-	RTE_LOG(ERR, EAL, "Cannot find resource for device\n");
-	return 1;
-}
-
-static int
 pci_mknod_uio_dev(const char *sysfs_uio_path, unsigned uio_num)
 {
 	FILE *f;
@@ -262,7 +202,7 @@ pci_get_uio_dev(struct rte_pci_device *dev, char *dstbuf,
 	return uio_num;
 }
 
-static int
+int
 pci_uio_alloc_uio_resource(struct rte_pci_device *dev,
 		struct mapped_pci_resource **uio_res)
 {
@@ -327,7 +267,7 @@ pci_uio_alloc_uio_resource(struct rte_pci_device *dev,
 	return 0;
 }
 
-static int
+int
 pci_uio_map_uio_resource_by_index(struct rte_pci_device *dev, int res_idx,
 		struct mapped_pci_resource *uio_res, int map_idx)
 {
@@ -393,123 +333,3 @@ fail:
 	rte_free(maps[map_idx].path);
 	return -1;
 }
-
-/* map the PCI resource of a PCI device in virtual memory */
-int
-pci_uio_map_resource(struct rte_pci_device *dev)
-{
-	int i, map_idx, ret;
-	uint64_t phaddr;
-	struct mapped_pci_resource *uio_res = NULL;
-	struct mapped_pci_res_list *uio_res_list =
-			RTE_TAILQ_CAST(rte_uio_tailq.head, mapped_pci_res_list);
-
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.uio_cfg_fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-
-	/* secondary processes - use already recorded details */
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return pci_uio_map_secondary(dev);
-
-	/* allocate uio resource */
-	ret = pci_uio_alloc_uio_resource(dev, &uio_res);
-	if ((ret != 0) || (uio_res == NULL))
-		return ret;
-
-	/* Map all BARs */
-	for (i = 0, map_idx = 0; i != PCI_MAX_RESOURCE; i++) {
-		/* skip empty BAR */
-		phaddr = dev->mem_resource[i].phys_addr;
-		if (phaddr == 0)
-			continue;
-
-		ret = pci_uio_map_uio_resource_by_index(dev, i,
-				uio_res, map_idx);
-		if (ret != 0)
-			goto fail;
-
-		map_idx++;
-	}
-
-	uio_res->nb_maps = map_idx;
-
-	TAILQ_INSERT_TAIL(uio_res_list, uio_res, next);
-
-	return 0;
-
-fail:
-	rte_free(uio_res);
-	return -1;
-}
-
-#ifdef RTE_LIBRTE_EAL_HOTPLUG
-static void
-pci_uio_unmap(struct mapped_pci_resource *uio_res)
-{
-	int i;
-
-	if (uio_res == NULL)
-		return;
-
-	for (i = 0; i != uio_res->nb_maps; i++)
-		pci_unmap_resource(uio_res->maps[i].addr,
-				(size_t)uio_res->maps[i].size);
-}
-
-static struct mapped_pci_resource *
-pci_uio_find_resource(struct rte_pci_device *dev)
-{
-	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);
-
-	if (dev == NULL)
-		return NULL;
-
-	TAILQ_FOREACH(uio_res, uio_res_list, next) {
-
-		/* skip this element if it doesn't match our PCI address */
-		if (!rte_eal_compare_pci_addr(&uio_res->pci_addr, &dev->addr))
-			return uio_res;
-	}
-	return NULL;
-}
-
-/* unmap the PCI resource of a PCI device in virtual memory */
-void
-pci_uio_unmap_resource(struct rte_pci_device *dev)
-{
-	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);
-
-	if (dev == NULL)
-		return;
-
-	/* find an entry for the device */
-	uio_res = pci_uio_find_resource(dev);
-	if (uio_res == NULL)
-		return;
-
-	/* secondary processes - just free maps */
-	if (rte_eal_process_type() != RTE_PROC_PRIMARY)
-		return pci_uio_unmap(uio_res);
-
-	TAILQ_REMOVE(uio_res_list, uio_res, next);
-
-	/* unmap all resources */
-	pci_uio_unmap(uio_res);
-
-	/* free uio resource */
-	rte_free(uio_res);
-
-	/* close fd if in primary process */
-	close(dev->intr_handle.fd);
-	if (dev->intr_handle.uio_cfg_fd >= 0)
-		close(dev->intr_handle.uio_cfg_fd);
-
-	dev->intr_handle.fd = -1;
-	dev->intr_handle.type = RTE_INTR_HANDLE_UNKNOWN;
-}
-#endif /* RTE_LIBRTE_EAL_HOTPLUG */
-- 
1.9.1

  parent reply	other threads:[~2015-03-12 10:18 UTC|newest]

Thread overview: 87+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-04  3:11 [dpdk-dev] [PATCH 1/3] BSD: Support Port Hotplug function Tetsuya Mukawa
2015-03-04  3:11 ` [dpdk-dev] [PATCH 2/3] eal, ethdev: Remove CONFIG_RTE_LIBRTE_EAL_HOTPLUG Tetsuya Mukawa
2015-03-04  3:11 ` [dpdk-dev] [PATCH 3/3] doc: Remove BSD limitation from hotplug section of programmer's guide Tetsuya Mukawa
2015-03-06 10:32 ` [dpdk-dev] [PATCH 1/3] BSD: Support Port Hotplug function Iremonger, Bernard
2015-03-09  2:23   ` Tetsuya Mukawa
2015-03-12 10:24     ` Tetsuya Mukawa
2015-03-12 10:17 ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Tetsuya Mukawa
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 01/15] eal: Fix cording style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
2015-03-12 10:48     ` Bruce Richardson
2015-03-12 10:57       ` Qiu, Michael
2015-03-12 11:09         ` Bruce Richardson
2015-03-13  0:25           ` Tetsuya Mukawa
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 02/15] eal: Close file descriptor of uio configuration Tetsuya Mukawa
2015-03-13 13:54     ` Iremonger, Bernard
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 03/15] eal: Fix memory leak of pci_uio_map_resource() Tetsuya Mukawa
2015-03-13 14:04     ` Iremonger, Bernard
2015-03-17  9:30     ` [dpdk-dev] [PATCH 0/6] Clean up pci uio implementations Tetsuya Mukawa
2015-03-17  9:30       ` [dpdk-dev] [PATCH 1/6] eal: Fix cording style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
2015-03-18 14:29         ` Bruce Richardson
2015-03-18 15:08         ` David Marchand
2015-03-17  9:30       ` [dpdk-dev] [PATCH 2/6] eal: Close file descriptor of uio configuration Tetsuya Mukawa
2015-03-18 15:19         ` David Marchand
2015-03-20  1:53           ` Tetsuya Mukawa
2015-03-19 16:04         ` Iremonger, Bernard
2015-03-20  1:54           ` Tetsuya Mukawa
2015-03-17  9:30       ` [dpdk-dev] [PATCH 3/6] eal: Fix memory leaks and needless incrementation of pci uio implementation Tetsuya Mukawa
2015-03-18 15:39         ` David Marchand
2015-03-20  1:53           ` Tetsuya Mukawa
2015-03-19 16:20         ` Iremonger, Bernard
2015-03-20  1:54           ` Tetsuya Mukawa
2015-03-17  9:30       ` [dpdk-dev] [PATCH 4/6] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
2015-03-17  9:30       ` [dpdk-dev] [PATCH 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp Tetsuya Mukawa
2015-03-17  9:30       ` [dpdk-dev] [PATCH 6/6] eal: Fix interface of pci_map_resource() Tetsuya Mukawa
2015-03-20  9:53         ` Iremonger, Bernard
2015-03-24  4:18           ` Tetsuya Mukawa
2015-03-24  4:18         ` [dpdk-dev] [PATCH v2 0/6] Clean up pci uio implementations Tetsuya Mukawa
2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 1/6] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 2/6] eal: Close file descriptor of uio configuration Tetsuya Mukawa
2015-03-24 18:33             ` Stephen Hemminger
2015-03-25  3:17               ` Tetsuya Mukawa
2015-03-25  5:07                 ` Stephen Hemminger
2015-03-26  4:19                   ` Tetsuya Mukawa
2015-03-26 10:03                     ` Iremonger, Bernard
2015-03-27  6:01                       ` Tetsuya Mukawa
2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 3/6] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
2015-03-25 15:00             ` Iremonger, Bernard
2015-03-26  2:44               ` Tetsuya Mukawa
2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 4/6] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 5/6] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp Tetsuya Mukawa
2015-03-25 15:27             ` Iremonger, Bernard
2015-03-26  2:50               ` Tetsuya Mukawa
2015-03-26 10:41                 ` Iremonger, Bernard
2015-03-27  8:19                   ` Tetsuya Mukawa
2015-03-24  4:18           ` [dpdk-dev] [PATCH v2 6/6] eal: Fix interface of pci_map_resource() Tetsuya Mukawa
2015-03-25 15:03             ` Iremonger, Bernard
2015-03-27  8:39         ` [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations Tetsuya Mukawa
2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 1/5] eal: Fix coding style of eal_pci.c and eal_pci_uio.c Tetsuya Mukawa
2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 2/5] eal: Close file descriptor of uio configuration Tetsuya Mukawa
2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 3/5] eal: Fix memory leaks and needless increment of pci_map_addr Tetsuya Mukawa
2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 4/5] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
2015-03-27  8:39           ` [dpdk-dev] [PATCH v3 5/5] eal: Fix uio mapping differences between linuxapp and bsdapp Tetsuya Mukawa
2015-04-21 13:15           ` [dpdk-dev] [PATCH v3 0/5] Clean up pci uio implementations Iremonger, Bernard
2015-04-23  4:23             ` Tetsuya Mukawa
2015-04-23  8:12               ` Iremonger, Bernard
2015-04-23  9:48                 ` Tetsuya Mukawa
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 04/15] eal: Fix needless incrementation of pci_map_addr Tetsuya Mukawa
2015-03-13 14:49     ` Iremonger, Bernard
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 05/15] eal/bsdapp: Change names of pci related data structure Tetsuya Mukawa
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 06/15] eal: Use map_idx in pci_uio_map_resource() of bsdapp to work same as linuxapp Tetsuya Mukawa
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 07/15] eal: Fix interface of pci_map_resource() of bsdapp Tetsuya Mukawa
2015-03-12 11:04     ` Bruce Richardson
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 08/15] eal: Add pci_uio_alloc_uio_resource() Tetsuya Mukawa
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 09/15] eal: Add pci_uio_map_uio_resource_by_index() Tetsuya Mukawa
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 10/15] eal: Consolidate pci_map and mapped_pci_resource of linuxapp and bsdapp Tetsuya Mukawa
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 11/15] eal: Consolidate rte_eal_pci_probe/close_one_driver() " Tetsuya Mukawa
2015-03-13 15:03     ` Iremonger, Bernard
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 12/15] eal: Consolidate pci_map/unmap_device() " Tetsuya Mukawa
2015-03-13 15:10     ` Iremonger, Bernard
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 13/15] eal: Consolidate pci_map/unmap_resource() " Tetsuya Mukawa
2015-03-13 15:23     ` Iremonger, Bernard
2015-03-12 10:17   ` Tetsuya Mukawa [this message]
2015-03-12 10:17   ` [dpdk-dev] [PATCH v2 15/15] eal: Enable Port Hotplug as default in Linux and BSD Tetsuya Mukawa
2015-03-13 15:47     ` Iremonger, Bernard
2015-03-17  8:08       ` Tetsuya Mukawa
2015-03-19 11:41         ` Iremonger, Bernard
2015-03-13 11:46   ` [dpdk-dev] [PATCH v2 00/15] eal: Port Hotplug support for BSD Iremonger, Bernard
2015-03-16  3:36     ` Tetsuya Mukawa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1426155474-1596-15-git-send-email-mukawa@igel.co.jp \
    --to=mukawa@igel.co.jp \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).