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_config.h>
27 RTE_PGSIZE_4K = 1ULL << 12,
28 RTE_PGSIZE_64K = 1ULL << 16,
29 RTE_PGSIZE_256K = 1ULL << 18,
30 RTE_PGSIZE_2M = 1ULL << 21,
31 RTE_PGSIZE_16M = 1ULL << 24,
32 RTE_PGSIZE_256M = 1ULL << 28,
33 RTE_PGSIZE_512M = 1ULL << 29,
34 RTE_PGSIZE_1G = 1ULL << 30,
35 RTE_PGSIZE_4G = 1ULL << 32,
36 RTE_PGSIZE_16G = 1ULL << 34,
39 #define SOCKET_ID_ANY -1 /**< Any NUMA socket. */
40 #define RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1) /**< Cache line mask. */
42 #define RTE_CACHE_LINE_ROUNDUP(size) \
43 (RTE_CACHE_LINE_SIZE * ((size + RTE_CACHE_LINE_SIZE - 1) / RTE_CACHE_LINE_SIZE))
44 /**< Return the first cache-aligned value greater or equal to size. */
46 /**< Cache line size in terms of log2 */
47 #if RTE_CACHE_LINE_SIZE == 64
48 #define RTE_CACHE_LINE_SIZE_LOG2 6
49 #elif RTE_CACHE_LINE_SIZE == 128
50 #define RTE_CACHE_LINE_SIZE_LOG2 7
52 #error "Unsupported cache line size"
55 #define RTE_CACHE_LINE_MIN_SIZE 64 /**< Minimum Cache line size. */
58 * Force alignment to cache line.
60 #define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE)
63 * Force minimum cache line alignment.
65 #define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE)
67 typedef uint64_t phys_addr_t; /**< Physical address. */
68 #define RTE_BAD_PHYS_ADDR ((phys_addr_t)-1)
70 * IO virtual address type.
71 * When the physical addressing mode (IOVA as PA) is in use,
72 * the translation from an IO virtual address (IOVA) to a physical address
73 * is a direct mapping, i.e. the same value.
74 * Otherwise, in virtual mode (IOVA as VA), an IOMMU may do the translation.
76 typedef uint64_t rte_iova_t;
77 #define RTE_BAD_IOVA ((rte_iova_t)-1)
80 * Physical memory segment descriptor.
85 phys_addr_t phys_addr; /**< deprecated - Start physical address. */
86 rte_iova_t iova; /**< Start IO address. */
90 void *addr; /**< Start virtual address. */
91 uint64_t addr_64; /**< Makes sure addr is always 64 bits */
93 size_t len; /**< Length of the segment. */
94 uint64_t hugepage_sz; /**< The pagesize of underlying memory */
95 int32_t socket_id; /**< NUMA socket ID. */
96 uint32_t nchannel; /**< Number of channels. */
97 uint32_t nrank; /**< Number of ranks. */
101 * Lock page in physical memory and prevent from swapping.
104 * The virtual address.
106 * 0 on success, negative on error.
108 int rte_mem_lock_page(const void *virt);
111 * Get physical address of any mapped virtual address in the current process.
112 * It is found by browsing the /proc/self/pagemap special file.
113 * The page must be locked.
116 * The virtual address.
118 * The physical address or RTE_BAD_IOVA on error.
120 phys_addr_t rte_mem_virt2phy(const void *virt);
123 * Get IO virtual address of any mapped virtual address in the current process.
126 * The virtual address.
128 * The IO address or RTE_BAD_IOVA on error.
130 rte_iova_t rte_mem_virt2iova(const void *virt);
133 * Get the layout of the available physical memory.
135 * It can be useful for an application to have the full physical
136 * memory layout to decide the size of a memory zone to reserve. This
137 * table is stored in rte_config (see rte_eal_get_configuration()).
140 * - On success, return a pointer to a read-only table of struct
141 * rte_physmem_desc elements, containing the layout of all
142 * addressable physical memory. The last element of the table
143 * contains a NULL address.
144 * - On error, return NULL. This should not happen since it is a fatal
145 * error that will probably cause the entire system to panic.
147 const struct rte_memseg *rte_eal_get_physmem_layout(void);
150 * Dump the physical memory layout to a file.
153 * A pointer to a file for output
155 void rte_dump_physmem_layout(FILE *f);
158 * Get the total amount of available physical memory.
161 * The total amount of available physical memory in bytes.
163 uint64_t rte_eal_get_physmem_size(void);
166 * Get the number of memory channels.
169 * The number of memory channels on the system. The value is 0 if unknown
170 * or not the same on all devices.
172 unsigned rte_memory_get_nchannel(void);
175 * Get the number of memory ranks.
178 * The number of memory ranks on the system. The value is 0 if unknown or
179 * not the same on all devices.
181 unsigned rte_memory_get_nrank(void);
184 * Drivers based on uio will not load unless physical
185 * addresses are obtainable. It is only possible to get
186 * physical addresses when running as a privileged user.
189 * 1 if the system is able to obtain physical addresses.
190 * 0 if using DMA addresses through an IOMMU.
192 int rte_eal_using_phys_addrs(void);
198 #endif /* _RTE_MEMORY_H_ */