4 * Copyright(c) 2010-2012 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.
40 #include <sys/queue.h>
42 #include <rte_memory.h>
43 #include <rte_memzone.h>
44 #include <rte_tailq.h>
46 #include <rte_eal_memconfig.h>
49 #include "eal_private.h"
52 * Return a pointer to a read-only table of struct rte_physmem_desc
53 * elements, containing the layout of all addressable physical
54 * memory. The last element of the table contains a NULL address.
56 const struct rte_memseg *
57 rte_eal_get_physmem_layout(void)
59 return rte_eal_get_configuration()->mem_config->memseg;
63 /* get the total size of memory */
65 rte_eal_get_physmem_size(void)
67 const struct rte_mem_config *mcfg;
69 uint64_t total_len = 0;
71 /* get pointer to global configuration */
72 mcfg = rte_eal_get_configuration()->mem_config;
74 for (i=0; i<RTE_MAX_MEMSEG; i++) {
75 if (mcfg->memseg[i].addr == NULL)
78 total_len += mcfg->memseg[i].len;
84 /* Dump the physical memory layout on console */
86 rte_dump_physmem_layout(void)
88 const struct rte_mem_config *mcfg;
91 /* get pointer to global configuration */
92 mcfg = rte_eal_get_configuration()->mem_config;
94 for (i=0; i<RTE_MAX_MEMSEG; i++) {
95 if (mcfg->memseg[i].addr == NULL)
98 printf("Segment %o: phys:0x%"PRIx64", len:0x%"PRIx64", "
99 "virt:%p, socket_id:%"PRId32", "
100 "hugepage_sz:0x%"PRIx64", nchannel:%"PRIx32", "
101 "nrank:%"PRIx32"\n", i,
102 mcfg->memseg[i].phys_addr,
104 mcfg->memseg[i].addr,
105 mcfg->memseg[i].socket_id,
106 mcfg->memseg[i].hugepage_sz,
107 mcfg->memseg[i].nchannel,
108 mcfg->memseg[i].nrank);
112 /* return the number of memory channels */
113 unsigned rte_memory_get_nchannel(void)
115 return rte_eal_get_configuration()->mem_config->nchannel;
118 /* return the number of memory rank */
119 unsigned rte_memory_get_nrank(void)
121 return rte_eal_get_configuration()->mem_config->nrank;