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>
50 #include <rte_tailq.h>
52 #include <rte_eal_memconfig.h>
53 #include <rte_per_lcore.h>
54 #include <rte_lcore.h>
55 #include <rte_branch_prediction.h>
57 #include <rte_errno.h>
58 #include <rte_string_fns.h>
59 #include <rte_spinlock.h>
61 #include "rte_mempool.h"
64 get_phys_map(void *va, phys_addr_t pa[], uint32_t pg_num,
65 uint32_t pg_sz, uint32_t memseg_id)
68 uint64_t virt_addr, mfn_id;
69 struct rte_mem_config *mcfg;
70 uint32_t page_size = getpagesize();
72 /* get pointer to global configuration */
73 mcfg = rte_eal_get_configuration()->mem_config;
74 virt_addr =(uintptr_t) mcfg->memseg[memseg_id].addr;
76 for (i = 0; i != pg_num; i++) {
77 mfn_id = ((uintptr_t)va + i * pg_sz - virt_addr) / RTE_PGSIZE_2M;
78 pa[i] = mcfg->memseg[memseg_id].mfn[mfn_id] * page_size;
82 /* create the mempool for supporting Dom0 */
84 rte_dom0_mempool_create(const char *name, unsigned elt_num, unsigned elt_size,
85 unsigned cache_size, unsigned private_data_size,
86 rte_mempool_ctor_t *mp_init, void *mp_init_arg,
87 rte_mempool_obj_ctor_t *obj_init, void *obj_init_arg,
88 int socket_id, unsigned flags)
90 struct rte_mempool *mp = NULL;
94 uint32_t pg_num, pg_shift, pg_sz, total_size;
95 const struct rte_memzone *mz;
96 char mz_name[RTE_MEMZONE_NAMESIZE];
97 int mz_flags = RTE_MEMZONE_1GB|RTE_MEMZONE_SIZE_HINT_ONLY;
99 pg_sz = RTE_PGSIZE_2M;
101 pg_shift = rte_bsf32(pg_sz);
102 total_size = rte_mempool_calc_obj_size(elt_size, flags, NULL);
104 /* calc max memory size and max number of pages needed. */
105 sz = rte_mempool_xmem_size(elt_num, total_size, pg_shift) +
107 pg_num = sz >> pg_shift;
109 /* extract physical mappings of the allocated memory. */
110 pa = calloc(pg_num, sizeof (*pa));
114 snprintf(mz_name, sizeof(mz_name), RTE_MEMPOOL_OBJ_NAME, name);
115 mz = rte_memzone_reserve(mz_name, sz, socket_id, mz_flags);
121 va = (char *)RTE_ALIGN_CEIL((uintptr_t)mz->addr, RTE_PGSIZE_2M);
122 /* extract physical mappings of the allocated memory. */
123 get_phys_map(va, pa, pg_num, pg_sz, mz->memseg_id);
125 mp = rte_mempool_xmem_create(name, elt_num, elt_size,
126 cache_size, private_data_size,
127 mp_init, mp_init_arg,
128 obj_init, obj_init_arg,
129 socket_id, flags, va, pa, pg_num, pg_shift);