eal/freebsd: support option --base-virtaddr
[dpdk.git] / lib / librte_eal / common / eal_common_options.c
index 05cae5f..a7f9c5f 100644 (file)
@@ -20,6 +20,7 @@
 #include <rte_eal.h>
 #include <rte_log.h>
 #include <rte_lcore.h>
+#include <rte_memory.h>
 #include <rte_tailq.h>
 #include <rte_version.h>
 #include <rte_devargs.h>
@@ -1095,6 +1096,36 @@ eal_parse_iova_mode(const char *name)
        return 0;
 }
 
+static int
+eal_parse_base_virtaddr(const char *arg)
+{
+       char *end;
+       uint64_t addr;
+
+       errno = 0;
+       addr = strtoull(arg, &end, 16);
+
+       /* check for errors */
+       if ((errno != 0) || (arg[0] == '\0') || end == NULL || (*end != '\0'))
+               return -1;
+
+       /* make sure we don't exceed 32-bit boundary on 32-bit target */
+#ifndef RTE_ARCH_64
+       if (addr >= UINTPTR_MAX)
+               return -1;
+#endif
+
+       /* align the addr on 16M boundary, 16MB is the minimum huge page
+        * size on IBM Power architecture. If the addr is aligned to 16MB,
+        * it can align to 2MB for x86. So this alignment can also be used
+        * on x86 and other architectures.
+        */
+       internal_config.base_virtaddr =
+               RTE_PTR_ALIGN_CEIL((uintptr_t)addr, (size_t)RTE_PGSIZE_16M);
+
+       return 0;
+}
+
 /* caller is responsible for freeing the returned string */
 static char *
 available_cores(void)
@@ -1408,6 +1439,13 @@ eal_parse_common_option(int opt, const char *optarg,
                        return -1;
                }
                break;
+       case OPT_BASE_VIRTADDR_NUM:
+               if (eal_parse_base_virtaddr(optarg) < 0) {
+                       RTE_LOG(ERR, EAL, "invalid parameter for --"
+                                       OPT_BASE_VIRTADDR "\n");
+                       return -1;
+               }
+               break;
 
        /* don't know what to do, leave this to caller */
        default:
@@ -1648,6 +1686,7 @@ eal_common_usage(void)
               "  -h, --help          This help\n"
               "  --"OPT_IN_MEMORY"   Operate entirely in memory. This will\n"
               "                      disable secondary process support\n"
+              "  --"OPT_BASE_VIRTADDR"     Base virtual address\n"
               "\nEAL options for DEBUG use only:\n"
               "  --"OPT_HUGE_UNLINK"       Unlink hugepage files after init\n"
               "  --"OPT_NO_HUGE"           Use malloc instead of hugetlbfs\n"