DPDK  2.1.0
rte_memory.h
Go to the documentation of this file.
1 /*-
2  * BSD LICENSE
3  *
4  * Copyright(c) 2010-2014 Intel Corporation. All rights reserved.
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
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
16  * distribution.
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.
20  *
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.
32  */
33 
34 #ifndef _RTE_MEMORY_H_
35 #define _RTE_MEMORY_H_
36 
43 #include <stdint.h>
44 #include <stddef.h>
45 #include <stdio.h>
46 
47 #ifdef RTE_EXEC_ENV_LINUXAPP
48 #include <exec-env/rte_dom0_common.h>
49 #endif
50 
51 #ifdef __cplusplus
52 extern "C" {
53 #endif
54 
55 enum rte_page_sizes {
56  RTE_PGSIZE_4K = 1ULL << 12,
57  RTE_PGSIZE_64K = 1ULL << 16,
58  RTE_PGSIZE_256K = 1ULL << 18,
59  RTE_PGSIZE_2M = 1ULL << 21,
60  RTE_PGSIZE_16M = 1ULL << 24,
61  RTE_PGSIZE_256M = 1ULL << 28,
62  RTE_PGSIZE_512M = 1ULL << 29,
63  RTE_PGSIZE_1G = 1ULL << 30,
64  RTE_PGSIZE_4G = 1ULL << 32,
65  RTE_PGSIZE_16G = 1ULL << 34,
66 };
67 
68 #define SOCKET_ID_ANY -1
69 #ifndef RTE_CACHE_LINE_SIZE
70 #define RTE_CACHE_LINE_SIZE 64
71 #endif
72 #define RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1)
74 #define RTE_CACHE_LINE_ROUNDUP(size) \
75  (RTE_CACHE_LINE_SIZE * ((size + RTE_CACHE_LINE_SIZE - 1) / RTE_CACHE_LINE_SIZE))
76 
81 #define __rte_cache_aligned __attribute__((__aligned__(RTE_CACHE_LINE_SIZE)))
82 
83 typedef uint64_t phys_addr_t;
84 #define RTE_BAD_PHYS_ADDR ((phys_addr_t)-1)
85 
89 struct rte_memseg {
90  phys_addr_t phys_addr;
91  union {
92  void *addr;
93  uint64_t addr_64;
94  };
95 #ifdef RTE_LIBRTE_IVSHMEM
96  phys_addr_t ioremap_addr;
97 #endif
98  size_t len;
99  uint64_t hugepage_sz;
100  int32_t socket_id;
101  uint32_t nchannel;
102  uint32_t nrank;
103 #ifdef RTE_LIBRTE_XEN_DOM0
105  uint64_t mfn[DOM0_NUM_MEMBLOCK];
106 #endif
107 } __attribute__((__packed__));
108 
117 int rte_mem_lock_page(const void *virt);
118 
129 phys_addr_t rte_mem_virt2phy(const void *virt);
130 
146 const struct rte_memseg *rte_eal_get_physmem_layout(void);
147 
154 void rte_dump_physmem_layout(FILE *f);
155 
162 uint64_t rte_eal_get_physmem_size(void);
163 
171 unsigned rte_memory_get_nchannel(void);
172 
180 unsigned rte_memory_get_nrank(void);
181 
182 #ifdef RTE_LIBRTE_XEN_DOM0
183 
194 phys_addr_t rte_mem_phy2mch(uint32_t memseg_id, const phys_addr_t phy_addr);
195 
205 int rte_xen_dom0_memory_init(void);
206 
216 int rte_xen_dom0_memory_attach(void);
217 #endif
218 #ifdef __cplusplus
219 }
220 #endif
221 
222 #endif /* _RTE_MEMORY_H_ */