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   |  2 ++
 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 |  2 ++
 10 files changed, 89 insertions(+), 82 deletions(-)

diff --git a/lib/librte_eal/bsdapp/eal/eal_pci.c 
b/lib/librte_eal/bsdapp/eal/eal_pci.c
index 8b3ed88..7ed0115 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 2f81f7c..11d9f59 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -170,6 +170,8 @@ DPDK_16.11 {
        rte_delay_us_callback_register;
        rte_eal_dev_attach;
        rte_eal_dev_detach;
+       rte_eal_map_resource;
+       rte_eal_unmap_resource;
        rte_eal_vdrv_register;
        rte_eal_vdrv_unregister;

diff --git a/lib/librte_eal/common/eal_common_dev.c 
b/lib/librte_eal/common/eal_common_dev.c
index 4f3b493..457d227 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>
@@ -151,3 +152,41 @@ err:
        RTE_LOG(ERR, EAL, "Driver cannot detach the device (%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 638cd86..464acc1 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>
@@ -114,44 +113,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 probe() 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 6975b9f..5be6326 100644
--- a/lib/librte_eal/common/include/rte_dev.h
+++ b/lib/librte_eal/common/include/rte_dev.h
@@ -235,6 +235,38 @@ int rte_eal_dev_attach(const char *name, const char 
*devargs);
  */
 int rte_eal_dev_detach(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 RTE_PMD_EXPORT_NAME_ARRAY(n, idx) n##idx[]

 #define RTE_PMD_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 2c7046f..7d6eef5 100644
--- a/lib/librte_eal/common/include/rte_pci.h
+++ b/lib/librte_eal/common/include/rte_pci.h
@@ -399,38 +399,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 83721ba..22b5b59 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -174,6 +174,8 @@ DPDK_16.11 {
        rte_delay_us_callback_register;
        rte_eal_dev_attach;
        rte_eal_dev_detach;
+       rte_eal_map_resource;
+       rte_eal_unmap_resource;
        rte_eal_vdrv_register;
        rte_eal_vdrv_unregister;

-- 
2.7.4

Reply via email to