lib: use SPDX tag for Intel copyright files
[dpdk.git] / lib / librte_eal / bsdapp / eal / eal_memory.c
index 65aabf2..45b198f 100644 (file)
@@ -1,34 +1,5 @@
-/*-
- *   BSD LICENSE
- * 
- *   Copyright(c) 2010-2014 Intel Corporation. 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 Intel Corporation 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.
+/* SPDX-License-Identifier: BSD-3-Clause
+ * Copyright(c) 2010-2014 Intel Corporation
  */
 #include <sys/mman.h>
 #include <unistd.h>
@@ -45,7 +16,7 @@
 #include "eal_internal_cfg.h"
 #include "eal_filesystem.h"
 
-#define PAGE_SIZE (sysconf(_SC_PAGESIZE))
+#define EAL_PAGE_SIZE (sysconf(_SC_PAGESIZE))
 
 /*
  * Get physical address of any mapped virtual address in the current process.
@@ -54,13 +25,18 @@ phys_addr_t
 rte_mem_virt2phy(const void *virtaddr)
 {
        /* XXX not implemented. This function is only used by
-        * rte_mempool_virt2phy() when hugepages are disabled. */
+        * rte_mempool_virt2iova() when hugepages are disabled. */
        (void)virtaddr;
-       return RTE_BAD_PHYS_ADDR;
+       return RTE_BAD_IOVA;
+}
+rte_iova_t
+rte_mem_virt2iova(const void *virtaddr)
+{
+       return rte_mem_virt2phy(virtaddr);
 }
 
-static int
-rte_eal_contigmem_init(void)
+int
+rte_eal_hugepage_init(void)
 {
        struct rte_mem_config *mcfg;
        uint64_t total_mem = 0;
@@ -73,8 +49,9 @@ rte_eal_contigmem_init(void)
        /* for debug purposes, hugetlbfs can be disabled */
        if (internal_config.no_hugetlbfs) {
                addr = malloc(internal_config.memory);
-               mcfg->memseg[0].phys_addr = (phys_addr_t)(uintptr_t)addr;
+               mcfg->memseg[0].iova = (rte_iova_t)(uintptr_t)addr;
                mcfg->memseg[0].addr = addr;
+               mcfg->memseg[0].hugepage_sz = RTE_PGSIZE_4K;
                mcfg->memseg[0].len = internal_config.memory;
                mcfg->memseg[0].socket_id = 0;
                return 0;
@@ -87,20 +64,21 @@ rte_eal_contigmem_init(void)
                hpi = &internal_config.hugepage_info[i];
                for (j = 0; j < hpi->num_pages[0]; j++) {
                        struct rte_memseg *seg;
-                       uint64_t physaddr;
+                       rte_iova_t physaddr;
                        int error;
                        size_t sysctl_size = sizeof(physaddr);
                        char physaddr_str[64];
 
                        addr = mmap(NULL, hpi->hugepage_sz, PROT_READ|PROT_WRITE,
-                                       MAP_SHARED, hpi->lock_descriptor, j * PAGE_SIZE);
+                                   MAP_SHARED, hpi->lock_descriptor,
+                                   j * EAL_PAGE_SIZE);
                        if (addr == MAP_FAILED) {
                                RTE_LOG(ERR, EAL, "Failed to mmap buffer %u from %s\n",
                                                j, hpi->hugedir);
                                return -1;
                        }
 
-                       rte_snprintf(physaddr_str, sizeof(physaddr_str), "hw.contigmem"
+                       snprintf(physaddr_str, sizeof(physaddr_str), "hw.contigmem"
                                        ".physaddr.%d", j);
                        error = sysctlbyname(physaddr_str, &physaddr, &sysctl_size,
                                        NULL, 0);
@@ -112,7 +90,7 @@ rte_eal_contigmem_init(void)
 
                        seg = &mcfg->memseg[seg_idx++];
                        seg->addr = addr;
-                       seg->phys_addr = physaddr;
+                       seg->iova = physaddr;
                        seg->hugepage_sz = hpi->hugepage_sz;
                        seg->len = hpi->hugepage_sz;
                        seg->nchannel = mcfg->nchannel;
@@ -130,14 +108,14 @@ rte_eal_contigmem_init(void)
        return 0;
 }
 
-static int
-rte_eal_contigmem_attach(void)
+int
+rte_eal_hugepage_attach(void)
 {
        const struct hugepage_info *hpi;
        int fd_hugepage_info, fd_hugepage = -1;
        unsigned i = 0;
        struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
-    
+
        /* Obtain a file descriptor for hugepage_info */
        fd_hugepage_info = open(eal_hugepage_info_path(), O_RDONLY);
        if (fd_hugepage_info < 0) {
@@ -167,13 +145,14 @@ rte_eal_contigmem_attach(void)
                struct rte_memseg *seg = &mcfg->memseg[i];
 
                addr = mmap(seg->addr, hpi->hugepage_sz, PROT_READ|PROT_WRITE,
-                               MAP_SHARED|MAP_FIXED, fd_hugepage, i * PAGE_SIZE);
+                           MAP_SHARED|MAP_FIXED, fd_hugepage,
+                           i * EAL_PAGE_SIZE);
                if (addr == MAP_FAILED || addr != seg->addr) {
                        RTE_LOG(ERR, EAL, "Failed to mmap buffer %u from %s\n",
                                i, hpi->hugedir);
                        goto error;
                }
-        
+
        }
 
        /* hugepage_info is no longer required */
@@ -190,35 +169,8 @@ error:
        return -1;
 }
 
-
-static int
-rte_eal_memdevice_init(void)
-{
-       struct rte_config *config;
-
-       if (rte_eal_process_type() == RTE_PROC_SECONDARY)
-               return 0;
-
-       config = rte_eal_get_configuration();
-       config->mem_config->nchannel = internal_config.force_nchannel;
-       config->mem_config->nrank = internal_config.force_nrank;
-
-       return 0;
-}
-
-/* init memory subsystem */
 int
-rte_eal_memory_init(void)
+rte_eal_using_phys_addrs(void)
 {
-       RTE_LOG(INFO, EAL, "Setting up physically contiguous memory...\n");
-       const int retval = rte_eal_process_type() == RTE_PROC_PRIMARY ?
-                       rte_eal_contigmem_init() :
-                       rte_eal_contigmem_attach();
-       if (retval < 0)
-               return -1;
-
-       if (internal_config.no_shconf == 0 && rte_eal_memdevice_init() < 0)
-               return -1;
-
        return 0;
 }