Signed-off-by: Jan Viktorin <viktorin at rehivetech.com>
---
 lib/librte_eal/bsdapp/eal/eal_soc.c             | 12 ++++++
 lib/librte_eal/bsdapp/eal/rte_eal_version.map   |  2 +
 lib/librte_eal/common/eal_common_soc.c          | 13 +++++++
 lib/librte_eal/common/include/rte_soc.h         | 50 +++++++++++++++++++++++++
 lib/librte_eal/linuxapp/eal/eal_soc.c           | 30 +++++++++++++++
 lib/librte_eal/linuxapp/eal/rte_eal_version.map |  2 +
 6 files changed, 109 insertions(+)

diff --git a/lib/librte_eal/bsdapp/eal/eal_soc.c 
b/lib/librte_eal/bsdapp/eal/eal_soc.c
index f84aae9..687d37b 100644
--- a/lib/librte_eal/bsdapp/eal/eal_soc.c
+++ b/lib/librte_eal/bsdapp/eal/eal_soc.c
@@ -32,9 +32,21 @@
  */

 #include <rte_soc.h>
+#include <rte_common.h>

 int
 rte_eal_soc_scan(void)
 {
        return 0;
 }
+
+int
+rte_eal_soc_map_device(struct rte_soc_device *dev __rte_unused)
+{
+       return 0;
+}
+
+void
+rte_eal_soc_unmap_device(struct rte_soc_device *dev __rte_unused)
+{
+}
diff --git a/lib/librte_eal/bsdapp/eal/rte_eal_version.map 
b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
index bd3dd11..b33282a 100644
--- a/lib/librte_eal/bsdapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/bsdapp/eal/rte_eal_version.map
@@ -166,5 +166,7 @@ DPDK_16.07 {
        rte_eal_soc_detach;
        rte_eal_soc_probe;
        rte_eal_soc_probe_one;
+       rte_eal_soc_map_device;
+       rte_eal_soc_unmap_device;

 } DPDK_16.04;
diff --git a/lib/librte_eal/common/eal_common_soc.c 
b/lib/librte_eal/common/eal_common_soc.c
index 75a7a97..d0e5351 100644
--- a/lib/librte_eal/common/eal_common_soc.c
+++ b/lib/librte_eal/common/eal_common_soc.c
@@ -119,6 +119,11 @@ rte_eal_soc_probe_one_driver(struct rte_soc_driver *dr,
                return 1;
        }

+       /* map resources */
+       ret = rte_eal_soc_map_device(dev);
+       if (ret)
+               return ret;
+
        dev->driver = dr;
        RTE_VERIFY(dr->devinit != NULL);
        return dr->devinit(dr, dev);
@@ -168,6 +173,8 @@ rte_eal_soc_detach_dev(struct rte_soc_driver *dr,
        /* clear driver structure */
        dev->driver = NULL;

+       /* unmap resources for devices */
+       rte_eal_soc_unmap_device(dev);
        return 0;
 }

@@ -313,6 +320,12 @@ soc_dump_one_device(FILE *f, struct rte_soc_device *dev)
        for (i = 0; dev->id && dev->id[i].compatible; ++i)
                fprintf(f, "   %s\n", dev->id[i].compatible);

+       for (i = 0; i < SOC_MAX_RESOURCE; i++) {
+               fprintf(f, "   %16.16"PRIx64" %16.16"PRIx64"\n",
+                       dev->mem_resource[i].phys_addr,
+                       dev->mem_resource[i].len);
+       }
+
        return 0;
 }

diff --git a/lib/librte_eal/common/include/rte_soc.h 
b/lib/librte_eal/common/include/rte_soc.h
index 206244a..3192121 100644
--- a/lib/librte_eal/common/include/rte_soc.h
+++ b/lib/librte_eal/common/include/rte_soc.h
@@ -50,6 +50,7 @@ extern "C" {
 #include <stdint.h>
 #include <inttypes.h>
 #include <string.h>
+#include <limits.h>

 #include <rte_debug.h>
 #include <rte_eal.h>
@@ -64,6 +65,14 @@ extern struct soc_device_list soc_device_list; /**< Global 
list of SoC devices.
 /** Return SoC scan path of the sysfs root. */
 const char *soc_get_sysfs_path(void);

+#define SOC_MAX_RESOURCE 6
+
+struct rte_soc_resource {
+       uint64_t phys_addr;
+       uint64_t len;
+       void *addr;
+};
+
 struct rte_soc_id {
        const char *compatible; /**< OF compatible specification */
 };
@@ -82,6 +91,7 @@ struct rte_soc_device {
        TAILQ_ENTRY(rte_soc_device) next;   /**< Next probed SoC device */
        struct rte_soc_addr addr;           /**< SoC device Location */
        struct rte_soc_id *id;              /**< SoC device ID list */
+       struct rte_soc_resource mem_resource[SOC_MAX_RESOURCE];
        struct rte_soc_driver *driver;      /**< Associated driver */
        struct rte_devargs *devargs;        /**< Device user arguments */
        enum rte_kernel_driver kdrv;        /**< Kernel driver */
@@ -111,6 +121,34 @@ struct rte_soc_driver {
 };

 /**
+ * A structure describing a SoC mapping.
+ */
+struct soc_map {
+       void *addr;
+       char *path;
+       uint64_t offset;
+       uint64_t size;
+       uint64_t phaddr;
+};
+
+/**
+ * A structure describing a mapped SoC resource.
+ * For multi-process we need to reproduce all SoC mappings in secondary
+ * processes, so save them in a tailq.
+ */
+struct mapped_soc_resource {
+       TAILQ_ENTRY(mapped_soc_resource) next;
+
+       struct rte_soc_addr soc_addr;
+       char path[PATH_MAX];
+       int nb_maps;
+       struct soc_map maps[SOC_MAX_RESOURCE];
+};
+
+/** mapped SoC resource list */
+TAILQ_HEAD(mapped_soc_res_list, mapped_soc_resource);
+
+/**
  * Utility function to write a SoC device name, this device name can later be
  * used to retrieve the corresponding rte_soc_addr using above functions.
  *
@@ -202,6 +240,18 @@ int rte_eal_soc_probe_one(const struct rte_soc_addr *addr);
 int rte_eal_soc_detach(const struct rte_soc_addr *addr);

 /**
+ * Map SoC device resources into userspace.
+ *
+ * This is called by the EAL if (drv_flags & RTE_SOC_DRV_NEED_MAPPING).
+ */
+int rte_eal_soc_map_device(struct rte_soc_device *dev);
+
+/**
+ * Unmap the device resources.
+ */
+void rte_eal_soc_unmap_device(struct rte_soc_device *dev);
+
+/**
  * Dump discovered SoC devices.
  */
 void rte_eal_soc_dump(FILE *f);
diff --git a/lib/librte_eal/linuxapp/eal/eal_soc.c 
b/lib/librte_eal/linuxapp/eal/eal_soc.c
index 4f9070e..f57486a 100644
--- a/lib/librte_eal/linuxapp/eal/eal_soc.c
+++ b/lib/librte_eal/linuxapp/eal/eal_soc.c
@@ -47,6 +47,34 @@
 #include "eal_internal_cfg.h"
 #include "eal_private.h"

+int
+rte_eal_soc_map_device(struct rte_soc_device *dev)
+{
+       int ret = -1;
+
+       /* try mapping the NIC resources using VFIO if it exists */
+       switch (dev->kdrv) {
+       default:
+               RTE_LOG(DEBUG, EAL,
+                       "  Not managed by a supported kernel driver, 
skipped\n");
+               ret = 1;
+               break;
+       }
+
+       return ret;
+}
+
+void
+rte_eal_soc_unmap_device(struct rte_soc_device *dev)
+{
+       switch (dev->kdrv) {
+       default:
+               RTE_LOG(DEBUG, EAL,
+                       "  Not managed by a supported kernel driver, 
skipped\n");
+               break;
+       }
+}
+
 static char *
 dev_read_uevent(const char *dirname)
 {
@@ -259,6 +287,8 @@ soc_scan_one(const char *dirname, const char *name)
                                TAILQ_INSERT_BEFORE(dev2, dev, next);
                        } else { /* already registered */
                                dev2->kdrv = dev->kdrv;
+                               memmove(dev2->mem_resource, dev->mem_resource,
+                                       sizeof(dev->mem_resource));

                                dev_content_free(dev2);
                                dev2->addr.fdt_path = dev->addr.fdt_path;
diff --git a/lib/librte_eal/linuxapp/eal/rte_eal_version.map 
b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
index 811cbf8..8e95a41 100644
--- a/lib/librte_eal/linuxapp/eal/rte_eal_version.map
+++ b/lib/librte_eal/linuxapp/eal/rte_eal_version.map
@@ -171,5 +171,7 @@ DPDK_16.07 {
        rte_eal_soc_detach;
        rte_eal_soc_probe;
        rte_eal_soc_probe_one;
+       rte_eal_soc_map_device;
+       rte_eal_soc_unmap_device;

 } DPDK_16.04;
-- 
2.8.0

Reply via email to