mem: remove API to get physical address in dom0
[dpdk.git] / lib / librte_eal / linuxapp / eal / eal_xen_memory.c
index 9246f83..19db1cb 100644 (file)
@@ -38,7 +38,6 @@
 #include <stdint.h>
 #include <inttypes.h>
 #include <string.h>
-#include <stdarg.h>
 #include <sys/mman.h>
 #include <sys/types.h>
 #include <sys/stat.h>
@@ -46,7 +45,6 @@
 #include <sys/file.h>
 #include <unistd.h>
 #include <limits.h>
-#include <errno.h>
 #include <sys/ioctl.h>
 #include <sys/time.h>
 
@@ -86,7 +84,7 @@ xen_get_virtual_area(size_t *size, size_t mem_size)
        int fd;
        long aligned_addr;
 
-       RTE_LOG(INFO, EAL, "Ask a virtual area of 0x%zu bytes\n", *size);
+       RTE_LOG(DEBUG, EAL, "Ask a virtual area of 0x%zu bytes\n", *size);
 
        fd = open("/dev/zero", O_RDONLY);
        if (fd < 0){
@@ -102,7 +100,7 @@ xen_get_virtual_area(size_t *size, size_t mem_size)
 
        if (addr == MAP_FAILED) {
                close(fd);
-               RTE_LOG(INFO, EAL, "Cannot get a virtual area\n");
+               RTE_LOG(ERR, EAL, "Cannot get a virtual area\n");
                return NULL;
        }
 
@@ -114,7 +112,7 @@ xen_get_virtual_area(size_t *size, size_t mem_size)
        aligned_addr = RTE_ALIGN_CEIL(aligned_addr, mem_size);
         addr = (void *)(aligned_addr);
 
-       RTE_LOG(INFO, EAL, "Virtual area found at %p (size = 0x%zx)\n",
+       RTE_LOG(DEBUG, EAL, "Virtual area found at %p (size = 0x%zx)\n",
                addr, *size);
 
        return addr;
@@ -156,13 +154,27 @@ get_xen_memory_size(void)
  * Based on physical address to caculate MFN in Xen Dom0.
  */
 phys_addr_t
-rte_mem_phy2mch(uint32_t memseg_id, const phys_addr_t phy_addr)
+rte_xen_mem_phy2mch(int32_t memseg_id, const phys_addr_t phy_addr)
 {
-       int mfn_id;
+       int mfn_id, i;
        uint64_t mfn, mfn_offset;
        struct rte_mem_config *mcfg = rte_eal_get_configuration()->mem_config;
        struct rte_memseg *memseg = mcfg->memseg;
 
+       /* find the memory segment owning the physical address */
+       if (memseg_id == -1) {
+               for (i = 0; i < RTE_MAX_MEMSEG; i++) {
+                       if ((phy_addr >= memseg[i].phys_addr) &&
+                                       (phy_addr < memseg[i].phys_addr +
+                                               memseg[i].len)) {
+                               memseg_id = i;
+                               break;
+                       }
+               }
+               if (memseg_id == -1)
+                       return RTE_BAD_PHYS_ADDR;
+       }
+
        mfn_id = (phy_addr - memseg[memseg_id].phys_addr) / RTE_PGSIZE_2M;
 
        /*the MFN is contiguous in 2M */
@@ -171,7 +183,7 @@ rte_mem_phy2mch(uint32_t memseg_id, const phys_addr_t phy_addr)
        mfn = mfn_offset + memseg[memseg_id].mfn[mfn_id];
 
        /** return mechine address */
-       return (mfn * PAGE_SIZE + phy_addr % PAGE_SIZE);
+       return mfn * PAGE_SIZE + phy_addr % PAGE_SIZE;
 }
 
 int