From: Jan Viktorin <vikto...@rehivetech.com>

From: Jan Viktorin <vikto...@rehivetech.com>

The functions pci_map_resource, pci_unmap_resource are generic so the
pci_* prefix can be omitted. The functions are moved to the
eal_common_dev.c so they can be reused by other infrastructure.

Signed-off-by: Jan Viktorin <viktorin at rehivetech.com>
Signed-off-by: Shreyansh Jain <shreyansh.jain at nxp.com>
---
 lib/librte_eal/bsdapp/eal/eal_pci.c             |  2 +-
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  8 +++++
 lib/librte_eal/common/eal_common_dev.c          | 39 +++++++++++++++++++++++++
 lib/librte_eal/common/eal_common_pci.c          | 39 -------------------------
 lib/librte_eal/common/eal_common_pci_uio.c      | 16 +++++-----
 lib/librte_eal/common/include/rte_dev.h         | 32 ++++++++++++++++++++
 lib/librte_eal/common/include/rte_pci.h         | 32 --------------------
 lib/librte_eal/linuxapp/eal/eal_pci_uio.c       |  2 +-
 lib/librte_eal/linuxapp/eal/eal_pci_vfio.c      |  5 ++--
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  8 +++++
 10 files changed, 101 insertions(+), 82 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c 
b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 374b68f..c021969 100644
--- a/lib/librte_eal/bsdapp/eal/eal_pci.c
+++ b/lib/librte_eal/bsdapp/eal/eal_pci.c
@@ -228,7 +228,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, 
int res_idx,

        /* if matching map is found, then use it */
        offset = res_idx * pagesz;
-       mapaddr = pci_map_resource(NULL, fd, (off_t)offset,
+       mapaddr = rte_eal_map_resource(NULL, fd, (off_t)offset,
                        (size_t)dev->mem_resource[res_idx].len, 0);
        close(fd);
        if (mapaddr == MAP_FAILED)
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map 
b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index a335e04..6dd4186 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -162,3 +162,11 @@ DPDK_16.07 {
        rte_thread_setname;

 } DPDK_16.04;
+
+DPDK_16.11 {
+       global:
+
+       rte_eal_map_resource;
+       rte_eal_unmap_resource;
+
+} DPDK_16.07;
diff --git a/lib/librte_eal/common/eal_common_dev.c 
b/lib/librte_eal/common/eal_common_dev.c
index a8a4146..83aa1ca 100644
--- a/lib/librte_eal/common/eal_common_dev.c
+++ b/lib/librte_eal/common/eal_common_dev.c
@@ -36,6 +36,7 @@
 #include <string.h>
 #include <inttypes.h>
 #include <sys/queue.h>
+#include <sys/mman.h>

 #include <rte_dev.h>
 #include <rte_devargs.h>
@@ -150,3 +151,41 @@ rte_eal_vdev_uninit(const char *name)
        RTE_LOG(ERR, EAL, "no driver found for %s\n", name);
        return -EINVAL;
 }
+
+/* map a particular resource from a file */
+void *
+rte_eal_map_resource(void *requested_addr, int fd, off_t offset, size_t size,
+                int additional_flags)
+{
+       void *mapaddr;
+
+       /* Map the 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, "  Device memory mapped at %p\n", mapaddr);
+
+       return mapaddr;
+}
+
+/* unmap a particular resource */
+void
+rte_eal_unmap_resource(void *requested_addr, size_t size)
+{
+       if (requested_addr == NULL)
+               return;
+
+       /* Unmap the Memory resource of device */
+       if (munmap(requested_addr, size)) {
+               RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, 0x%lx): %s\n",
+                       __func__, requested_addr, (unsigned long)size,
+                       strerror(errno));
+       } else
+               RTE_LOG(DEBUG, EAL, "  Device memory unmapped at %p\n",
+                               requested_addr);
+}
diff --git a/lib/librte_eal/common/eal_common_pci.c 
b/lib/librte_eal/common/eal_common_pci.c
index 7248c38..0818b63 100644
--- a/lib/librte_eal/common/eal_common_pci.c
+++ b/lib/librte_eal/common/eal_common_pci.c
@@ -67,7 +67,6 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <sys/queue.h>
-#include <sys/mman.h>

 #include <rte_interrupts.h>
 #include <rte_log.h>
@@ -112,44 +111,6 @@ static struct rte_devargs *pci_devargs_lookup(struct 
rte_pci_device *dev)
        return NULL;
 }

-/* 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)
-{
-       if (requested_addr == NULL)
-               return;
-
-       /* Unmap the PCI memory resource of device */
-       if (munmap(requested_addr, size)) {
-               RTE_LOG(ERR, EAL, "%s(): cannot munmap(%p, 0x%lx): %s\n",
-                       __func__, requested_addr, (unsigned long)size,
-                       strerror(errno));
-       } else
-               RTE_LOG(DEBUG, EAL, "  PCI memory unmapped at %p\n",
-                               requested_addr);
-}
-
 /*
  * If vendor/device ID match, call the devinit() function of the
  * driver.
diff --git a/lib/librte_eal/common/eal_common_pci_uio.c 
b/lib/librte_eal/common/eal_common_pci_uio.c
index 367a681..3402518 100644
--- a/lib/librte_eal/common/eal_common_pci_uio.c
+++ b/lib/librte_eal/common/eal_common_pci_uio.c
@@ -75,9 +75,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
                                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);
+                       void *mapaddr = rte_eal_map_resource(
+                                               uio_res->maps[i].addr, fd,
+                                               (off_t)uio_res->maps[i].offset,
+                                               (size_t)uio_res->maps[i].size,
+                                               0);
                        /* fd is not needed in slave process, close it */
                        close(fd);
                        if (mapaddr != uio_res->maps[i].addr) {
@@ -88,11 +90,11 @@ pci_uio_map_secondary(struct rte_pci_device *dev)
                                if (mapaddr != MAP_FAILED) {
                                        /* unmap addrs correctly mapped */
                                        for (j = 0; j < i; j++)
-                                               pci_unmap_resource(
+                                               rte_eal_unmap_resource(
                                                        uio_res->maps[j].addr,
                                                        
(size_t)uio_res->maps[j].size);
                                        /* unmap addr wrongly mapped */
-                                       pci_unmap_resource(mapaddr,
+                                       rte_eal_unmap_resource(mapaddr,
                                                (size_t)uio_res->maps[i].size);
                                }
                                return -1;
@@ -150,7 +152,7 @@ pci_uio_map_resource(struct rte_pci_device *dev)
        return 0;
 error:
        for (i = 0; i < map_idx; i++) {
-               pci_unmap_resource(uio_res->maps[i].addr,
+               rte_eal_unmap_resource(uio_res->maps[i].addr,
                                (size_t)uio_res->maps[i].size);
                rte_free(uio_res->maps[i].path);
        }
@@ -167,7 +169,7 @@ pci_uio_unmap(struct mapped_pci_resource *uio_res)
                return;

        for (i = 0; i != uio_res->nb_maps; i++) {
-               pci_unmap_resource(uio_res->maps[i].addr,
+               rte_eal_unmap_resource(uio_res->maps[i].addr,
                                (size_t)uio_res->maps[i].size);
                if (rte_eal_process_type() == RTE_PROC_PRIMARY)
                        rte_free(uio_res->maps[i].path);
diff --git a/lib/librte_eal/common/include/rte_dev.h 
b/lib/librte_eal/common/include/rte_dev.h
index 60bc91d..938f8c8 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -190,6 +190,38 @@ int rte_eal_vdev_init(const char *name, const char *args);
  */
 int rte_eal_vdev_uninit(const char *name);

+/**
+ * @internal
+ * Map a particular resource from a file.
+ *
+ * @param requested_addr
+ *      The starting address for the new mapping range.
+ * @param fd
+ *      The file descriptor.
+ * @param offset
+ *      The offset for the mapping range.
+ * @param size
+ *      The size for the mapping range.
+ * @param additional_flags
+ *      The additional flags for the mapping range.
+ * @return
+ *   - On success, the function returns a pointer to the mapped area.
+ *   - On error, the value MAP_FAILED is returned.
+ */
+void *rte_eal_map_resource(void *requested_addr, int fd, off_t offset,
+               size_t size, int additional_flags);
+
+/**
+ * @internal
+ * Unmap a particular resource.
+ *
+ * @param requested_addr
+ *      The address for the unmapping range.
+ * @param size
+ *      The size for the unmapping range.
+ */
+void rte_eal_unmap_resource(void *requested_addr, size_t size);
+
 #define DRIVER_EXPORT_NAME_ARRAY(n, idx) n##idx[]

 #define DRIVER_EXPORT_NAME(name, idx) \
diff --git a/lib/librte_eal/common/include/rte_pci.h 
b/lib/librte_eal/common/include/rte_pci.h
index a4c8156..78e0245 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -383,38 +383,6 @@ int rte_eal_pci_map_device(struct rte_pci_device *dev);
 void rte_eal_pci_unmap_device(struct rte_pci_device *dev);

 /**
- * @internal
- * Map a particular resource from a file.
- *
- * @param requested_addr
- *      The starting address for the new mapping range.
- * @param fd
- *      The file descriptor.
- * @param offset
- *      The offset for the mapping range.
- * @param size
- *      The size for the mapping range.
- * @param additional_flags
- *      The additional flags for the mapping range.
- * @return
- *   - On success, the function returns a pointer to the mapped area.
- *   - On error, the value MAP_FAILED is returned.
- */
-void *pci_map_resource(void *requested_addr, int fd, off_t offset,
-               size_t size, int additional_flags);
-
-/**
- * @internal
- * Unmap a particular resource.
- *
- * @param requested_addr
- *      The address for the unmapping range.
- * @param size
- *      The size for the unmapping range.
- */
-void pci_unmap_resource(void *requested_addr, size_t size);
-
-/**
  * Probe the single PCI device.
  *
  * Scan the content of the PCI bus, and find the pci device specified by pci
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c 
b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
index 1786b75..5c34421 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_uio.c
@@ -347,7 +347,7 @@ pci_uio_map_resource_by_index(struct rte_pci_device *dev, 
int res_idx,
        if (pci_map_addr == NULL)
                pci_map_addr = pci_find_max_end_va();

-       mapaddr = pci_map_resource(pci_map_addr, fd, 0,
+       mapaddr = rte_eal_map_resource(pci_map_addr, fd, 0,
                        (size_t)dev->mem_resource[res_idx].len, 0);
        close(fd);
        if (mapaddr == MAP_FAILED)
diff --git a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c 
b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
index 5f478c5..5ad8cbe 100644
--- a/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
+++ b/lib/librte_eal/linuxapp/eal/eal_pci_vfio.c
@@ -465,7 +465,8 @@ 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,
+                               map_addr = rte_eal_map_resource(bar_addr,
+                                                           vfio_dev_fd,
                                                            memreg[0].offset,
                                                            memreg[0].size,
                                                            MAP_FIXED);
@@ -477,7 +478,7 @@ pci_vfio_map_resource(struct rte_pci_device *dev)
                                void *second_addr = RTE_PTR_ADD(bar_addr,
                                                                
memreg[1].offset -
                                                                
(uintptr_t)reg.offset);
-                               map_addr = pci_map_resource(second_addr,
+                               map_addr = rte_eal_map_resource(second_addr,
                                                            vfio_dev_fd, 
memreg[1].offset,
                                                            memreg[1].size,
                                                            MAP_FIXED);
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map 
b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index db8c984..15e8332 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -166,3 +166,11 @@ DPDK_16.07 {
        rte_thread_setname;

 } DPDK_16.04;
+
+DPDK_16.11 {
+       global:
+
+       rte_eal_map_resource;
+       rte_eal_unmap_resource;
+
+} DPDK_16.07;
-- 
2.7.4

Reply via email to