1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
11 * Memory-related RTE API.
22 #include <rte_common.h>
26 RTE_PGSIZE_4K = 1ULL << 12,
27 RTE_PGSIZE_64K = 1ULL << 16,
28 RTE_PGSIZE_256K = 1ULL << 18,
29 RTE_PGSIZE_2M = 1ULL << 21,
30 RTE_PGSIZE_16M = 1ULL << 24,
31 RTE_PGSIZE_256M = 1ULL << 28,
32 RTE_PGSIZE_512M = 1ULL << 29,
33 RTE_PGSIZE_1G = 1ULL << 30,
34 RTE_PGSIZE_4G = 1ULL << 32,
35 RTE_PGSIZE_16G = 1ULL << 34,
38 #define SOCKET_ID_ANY -1 /**< Any NUMA socket. */
39 #define RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1) /**< Cache line mask. */
41 #define RTE_CACHE_LINE_ROUNDUP(size) \
42 (RTE_CACHE_LINE_SIZE * ((size + RTE_CACHE_LINE_SIZE - 1) / RTE_CACHE_LINE_SIZE))
43 /**< Return the first cache-aligned value greater or equal to size. */
45 /**< Cache line size in terms of log2 */
46 #if RTE_CACHE_LINE_SIZE == 64
47 #define RTE_CACHE_LINE_SIZE_LOG2 6
48 #elif RTE_CACHE_LINE_SIZE == 128
49 #define RTE_CACHE_LINE_SIZE_LOG2 7
51 #error "Unsupported cache line size"
54 #define RTE_CACHE_LINE_MIN_SIZE 64 /**< Minimum Cache line size. */
57 * Force alignment to cache line.
59 #define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE)
62 * Force minimum cache line alignment.
64 #define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE)
66 typedef uint64_t phys_addr_t; /**< Physical address. */
67 #define RTE_BAD_PHYS_ADDR ((phys_addr_t)-1)
69 * IO virtual address type.
70 * When the physical addressing mode (IOVA as PA) is in use,
71 * the translation from an IO virtual address (IOVA) to a physical address
72 * is a direct mapping, i.e. the same value.
73 * Otherwise, in virtual mode (IOVA as VA), an IOMMU may do the translation.
75 typedef uint64_t rte_iova_t;
76 #define RTE_BAD_IOVA ((rte_iova_t)-1)
79 * Physical memory segment descriptor.
84 phys_addr_t phys_addr; /**< deprecated - Start physical address. */
85 rte_iova_t iova; /**< Start IO address. */
89 void *addr; /**< Start virtual address. */
90 uint64_t addr_64; /**< Makes sure addr is always 64 bits */
92 size_t len; /**< Length of the segment. */
93 uint64_t hugepage_sz; /**< The pagesize of underlying memory */
94 int32_t socket_id; /**< NUMA socket ID. */
95 uint32_t nchannel; /**< Number of channels. */
96 uint32_t nrank; /**< Number of ranks. */
100 * Lock page in physical memory and prevent from swapping.
103 * The virtual address.
105 * 0 on success, negative on error.
107 int rte_mem_lock_page(const void *virt);
110 * Get physical address of any mapped virtual address in the current process.
111 * It is found by browsing the /proc/self/pagemap special file.
112 * The page must be locked.
115 * The virtual address.
117 * The physical address or RTE_BAD_IOVA on error.
119 phys_addr_t rte_mem_virt2phy(const void *virt);
122 * Get IO virtual address of any mapped virtual address in the current process.
125 * The virtual address.
127 * The IO address or RTE_BAD_IOVA on error.
129 rte_iova_t rte_mem_virt2iova(const void *virt);
132 * Get the layout of the available physical memory.
134 * It can be useful for an application to have the full physical
135 * memory layout to decide the size of a memory zone to reserve. This
136 * table is stored in rte_config (see rte_eal_get_configuration()).
139 * - On success, return a pointer to a read-only table of struct
140 * rte_physmem_desc elements, containing the layout of all
141 * addressable physical memory. The last element of the table
142 * contains a NULL address.
143 * - On error, return NULL. This should not happen since it is a fatal
144 * error that will probably cause the entire system to panic.
146 const struct rte_memseg *rte_eal_get_physmem_layout(void);
149 * Dump the physical memory layout to a file.
152 * A pointer to a file for output
154 void rte_dump_physmem_layout(FILE *f);
157 * Get the total amount of available physical memory.
160 * The total amount of available physical memory in bytes.
162 uint64_t rte_eal_get_physmem_size(void);
165 * Get the number of memory channels.
168 * The number of memory channels on the system. The value is 0 if unknown
169 * or not the same on all devices.
171 unsigned rte_memory_get_nchannel(void);
174 * Get the number of memory ranks.
177 * The number of memory ranks on the system. The value is 0 if unknown or
178 * not the same on all devices.
180 unsigned rte_memory_get_nrank(void);
183 * Drivers based on uio will not load unless physical
184 * addresses are obtainable. It is only possible to get
185 * physical addresses when running as a privileged user.
188 * 1 if the system is able to obtain physical addresses.
189 * 0 if using DMA addresses through an IOMMU.
191 int rte_eal_using_phys_addrs(void);
197 #endif /* _RTE_MEMORY_H_ */