4 * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Intel Corporation nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
41 #include <sys/queue.h>
43 #include <rte_common.h>
45 #include <rte_debug.h>
46 #include <rte_memory.h>
47 #include <rte_memzone.h>
48 #include <rte_atomic.h>
49 #include <rte_launch.h>
51 #include <rte_eal_memconfig.h>
52 #include <rte_per_lcore.h>
53 #include <rte_lcore.h>
54 #include <rte_branch_prediction.h>
56 #include <rte_errno.h>
57 #include <rte_string_fns.h>
58 #include <rte_spinlock.h>
60 #include "rte_mempool.h"
63 get_phys_map(void *va, phys_addr_t pa[], uint32_t pg_num,
64 uint32_t pg_sz, uint32_t memseg_id)
67 uint64_t virt_addr, mfn_id;
68 struct rte_mem_config *mcfg;
69 uint32_t page_size = getpagesize();
71 /* get pointer to global configuration */
72 mcfg = rte_eal_get_configuration()->mem_config;
73 virt_addr = (uintptr_t) mcfg->memseg[memseg_id].addr;
75 for (i = 0; i != pg_num; i++) {
76 mfn_id = ((uintptr_t)va + i * pg_sz - virt_addr) / RTE_PGSIZE_2M;
77 pa[i] = mcfg->memseg[memseg_id].mfn[mfn_id] * page_size;
81 /* create the mempool for supporting Dom0 */
83 rte_dom0_mempool_create(const char *name, unsigned elt_num, unsigned elt_size,
84 unsigned cache_size, unsigned private_data_size,
85 rte_mempool_ctor_t *mp_init, void *mp_init_arg,
86 rte_mempool_obj_ctor_t *obj_init, void *obj_init_arg,
87 int socket_id, unsigned flags)
89 struct rte_mempool *mp = NULL;
93 uint32_t pg_num, pg_shift, pg_sz, total_size;
94 const struct rte_memzone *mz;
95 char mz_name[RTE_MEMZONE_NAMESIZE];
96 int mz_flags = RTE_MEMZONE_1GB|RTE_MEMZONE_SIZE_HINT_ONLY;
98 pg_sz = RTE_PGSIZE_2M;
100 pg_shift = rte_bsf32(pg_sz);
101 total_size = rte_mempool_calc_obj_size(elt_size, flags, NULL);
103 /* calc max memory size and max number of pages needed. */
104 sz = rte_mempool_xmem_size(elt_num, total_size, pg_shift) +
106 pg_num = sz >> pg_shift;
108 /* extract physical mappings of the allocated memory. */
109 pa = calloc(pg_num, sizeof (*pa));
113 snprintf(mz_name, sizeof(mz_name), RTE_MEMPOOL_OBJ_NAME, name);
114 mz = rte_memzone_reserve(mz_name, sz, socket_id, mz_flags);
120 va = (char *)RTE_ALIGN_CEIL((uintptr_t)mz->addr, RTE_PGSIZE_2M);
121 /* extract physical mappings of the allocated memory. */
122 get_phys_map(va, pa, pg_num, pg_sz, mz->memseg_id);
124 mp = rte_mempool_xmem_create(name, elt_num, elt_size,
125 cache_size, private_data_size,
126 mp_init, mp_init_arg,
127 obj_init, obj_init_arg,
128 socket_id, flags, va, pa, pg_num, pg_shift);