1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
11 * Memory-related RTE API.
22 #include <rte_common.h>
23 #include <rte_compat.h>
24 #include <rte_config.h>
26 /* forward declaration for pointers */
27 struct rte_memseg_list;
31 RTE_PGSIZE_4K = 1ULL << 12,
32 RTE_PGSIZE_64K = 1ULL << 16,
33 RTE_PGSIZE_256K = 1ULL << 18,
34 RTE_PGSIZE_2M = 1ULL << 21,
35 RTE_PGSIZE_16M = 1ULL << 24,
36 RTE_PGSIZE_256M = 1ULL << 28,
37 RTE_PGSIZE_512M = 1ULL << 29,
38 RTE_PGSIZE_1G = 1ULL << 30,
39 RTE_PGSIZE_4G = 1ULL << 32,
40 RTE_PGSIZE_16G = 1ULL << 34,
43 #define SOCKET_ID_ANY -1 /**< Any NUMA socket. */
44 #define RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1) /**< Cache line mask. */
46 #define RTE_CACHE_LINE_ROUNDUP(size) \
47 (RTE_CACHE_LINE_SIZE * ((size + RTE_CACHE_LINE_SIZE - 1) / RTE_CACHE_LINE_SIZE))
48 /**< Return the first cache-aligned value greater or equal to size. */
50 /**< Cache line size in terms of log2 */
51 #if RTE_CACHE_LINE_SIZE == 64
52 #define RTE_CACHE_LINE_SIZE_LOG2 6
53 #elif RTE_CACHE_LINE_SIZE == 128
54 #define RTE_CACHE_LINE_SIZE_LOG2 7
56 #error "Unsupported cache line size"
59 #define RTE_CACHE_LINE_MIN_SIZE 64 /**< Minimum Cache line size. */
62 * Force alignment to cache line.
64 #define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE)
67 * Force minimum cache line alignment.
69 #define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE)
71 typedef uint64_t phys_addr_t; /**< Physical address. */
72 #define RTE_BAD_PHYS_ADDR ((phys_addr_t)-1)
74 * IO virtual address type.
75 * When the physical addressing mode (IOVA as PA) is in use,
76 * the translation from an IO virtual address (IOVA) to a physical address
77 * is a direct mapping, i.e. the same value.
78 * Otherwise, in virtual mode (IOVA as VA), an IOMMU may do the translation.
80 typedef uint64_t rte_iova_t;
81 #define RTE_BAD_IOVA ((rte_iova_t)-1)
84 * Physical memory segment descriptor.
89 phys_addr_t phys_addr; /**< deprecated - Start physical address. */
90 rte_iova_t iova; /**< Start IO address. */
94 void *addr; /**< Start virtual address. */
95 uint64_t addr_64; /**< Makes sure addr is always 64 bits */
97 size_t len; /**< Length of the segment. */
98 uint64_t hugepage_sz; /**< The pagesize of underlying memory */
99 int32_t socket_id; /**< NUMA socket ID. */
100 uint32_t nchannel; /**< Number of channels. */
101 uint32_t nrank; /**< Number of ranks. */
105 * Lock page in physical memory and prevent from swapping.
108 * The virtual address.
110 * 0 on success, negative on error.
112 int rte_mem_lock_page(const void *virt);
115 * Get physical address of any mapped virtual address in the current process.
116 * It is found by browsing the /proc/self/pagemap special file.
117 * The page must be locked.
120 * The virtual address.
122 * The physical address or RTE_BAD_IOVA on error.
124 phys_addr_t rte_mem_virt2phy(const void *virt);
127 * Get IO virtual address of any mapped virtual address in the current process.
130 * The virtual address.
132 * The IO address or RTE_BAD_IOVA on error.
134 rte_iova_t rte_mem_virt2iova(const void *virt);
137 * Get virtual memory address corresponding to iova address.
142 * Virtual address corresponding to iova address (or NULL if address does not
143 * exist within DPDK memory map).
145 __rte_experimental void *
146 rte_mem_iova2virt(rte_iova_t iova);
149 * Get memseg to which a particular virtual address belongs.
152 * The virtual address.
154 * The memseg list in which to look up based on ``virt`` address
157 * Memseg pointer on success, or NULL on error.
159 __rte_experimental struct rte_memseg *
160 rte_mem_virt2memseg(const void *virt, const struct rte_memseg_list *msl);
163 * Get memseg list corresponding to virtual memory address.
166 * The virtual address.
168 * Memseg list to which this virtual address belongs to.
170 __rte_experimental struct rte_memseg_list *
171 rte_mem_virt2memseg_list(const void *virt);
174 * Memseg walk function prototype.
176 * Returning 0 will continue walk
177 * Returning 1 will stop the walk
178 * Returning -1 will stop the walk and report error
180 typedef int (*rte_memseg_walk_t)(const struct rte_memseg_list *msl,
181 const struct rte_memseg *ms, void *arg);
184 * Memseg contig walk function prototype. This will trigger a callback on every
185 * VA-contiguous are starting at memseg ``ms``, so total valid VA space at each
186 * callback call will be [``ms->addr``, ``ms->addr + len``).
188 * Returning 0 will continue walk
189 * Returning 1 will stop the walk
190 * Returning -1 will stop the walk and report error
192 typedef int (*rte_memseg_contig_walk_t)(const struct rte_memseg_list *msl,
193 const struct rte_memseg *ms, size_t len, void *arg);
196 * Memseg list walk function prototype. This will trigger a callback on every
197 * allocated memseg list.
199 * Returning 0 will continue walk
200 * Returning 1 will stop the walk
201 * Returning -1 will stop the walk and report error
203 typedef int (*rte_memseg_list_walk_t)(const struct rte_memseg_list *msl,
207 * Walk list of all memsegs.
212 * Argument passed to iterator
214 * 0 if walked over the entire list
215 * 1 if stopped by the user
216 * -1 if user function reported error
218 int __rte_experimental
219 rte_memseg_walk(rte_memseg_walk_t func, void *arg);
222 * Walk each VA-contiguous area.
227 * Argument passed to iterator
229 * 0 if walked over the entire list
230 * 1 if stopped by the user
231 * -1 if user function reported error
233 int __rte_experimental
234 rte_memseg_contig_walk(rte_memseg_contig_walk_t func, void *arg);
237 * Walk each allocated memseg list.
242 * Argument passed to iterator
244 * 0 if walked over the entire list
245 * 1 if stopped by the user
246 * -1 if user function reported error
248 int __rte_experimental
249 rte_memseg_list_walk(rte_memseg_list_walk_t func, void *arg);
252 * Dump the physical memory layout to a file.
255 * A pointer to a file for output
257 void rte_dump_physmem_layout(FILE *f);
260 * Get the total amount of available physical memory.
263 * The total amount of available physical memory in bytes.
265 uint64_t rte_eal_get_physmem_size(void);
268 * Get the number of memory channels.
271 * The number of memory channels on the system. The value is 0 if unknown
272 * or not the same on all devices.
274 unsigned rte_memory_get_nchannel(void);
277 * Get the number of memory ranks.
280 * The number of memory ranks on the system. The value is 0 if unknown or
281 * not the same on all devices.
283 unsigned rte_memory_get_nrank(void);
286 * Drivers based on uio will not load unless physical
287 * addresses are obtainable. It is only possible to get
288 * physical addresses when running as a privileged user.
291 * 1 if the system is able to obtain physical addresses.
292 * 0 if using DMA addresses through an IOMMU.
294 int rte_eal_using_phys_addrs(void);
300 #endif /* _RTE_MEMORY_H_ */