1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation
5 #ifndef _RTE_MEMZONE_H_
6 #define _RTE_MEMZONE_H_
12 * The goal of the memzone allocator is to reserve contiguous
13 * portions of physical memory. These zones are identified by a name.
15 * The memzone descriptors are shared by all partitions and are
16 * located in a known place of physical memory. This zone is accessed
17 * using rte_eal_get_configuration(). The lookup (by name) of a
18 * memory zone can be done in any partition and returns the same
21 * A reserved memory zone cannot be unreserved. The reservation shall
22 * be done at initialization time only.
26 #include <rte_memory.h>
27 #include <rte_common.h>
33 #define RTE_MEMZONE_2MB 0x00000001 /**< Use 2MB pages. */
34 #define RTE_MEMZONE_1GB 0x00000002 /**< Use 1GB pages. */
35 #define RTE_MEMZONE_16MB 0x00000100 /**< Use 16MB pages. */
36 #define RTE_MEMZONE_16GB 0x00000200 /**< Use 16GB pages. */
37 #define RTE_MEMZONE_256KB 0x00010000 /**< Use 256KB pages. */
38 #define RTE_MEMZONE_256MB 0x00020000 /**< Use 256MB pages. */
39 #define RTE_MEMZONE_512MB 0x00040000 /**< Use 512MB pages. */
40 #define RTE_MEMZONE_4GB 0x00080000 /**< Use 4GB pages. */
41 #define RTE_MEMZONE_SIZE_HINT_ONLY 0x00000004 /**< Use available page size */
44 * A structure describing a memzone, which is a contiguous portion of
45 * physical memory identified by a name.
49 #define RTE_MEMZONE_NAMESIZE 32 /**< Maximum length of memory zone name.*/
50 char name[RTE_MEMZONE_NAMESIZE]; /**< Name of the memory zone. */
54 phys_addr_t phys_addr; /**< deprecated - Start physical address. */
55 rte_iova_t iova; /**< Start IO address. */
59 void *addr; /**< Start virtual address. */
60 uint64_t addr_64; /**< Makes sure addr is always 64-bits */
62 size_t len; /**< Length of the memzone. */
64 uint64_t hugepage_sz; /**< The page size of underlying memory */
66 int32_t socket_id; /**< NUMA socket ID. */
68 uint32_t flags; /**< Characteristics of this memzone. */
69 uint32_t memseg_id; /**< Memseg it belongs. */
70 } __attribute__((__packed__));
73 * Reserve a portion of physical memory.
75 * This function reserves some memory and returns a pointer to a
76 * correctly filled memzone descriptor. If the allocation cannot be
80 * The name of the memzone. If it already exists, the function will
81 * fail and return NULL.
83 * The size of the memory to be reserved. If it
84 * is 0, the biggest contiguous zone will be reserved.
86 * The socket identifier in the case of
87 * NUMA. The value can be SOCKET_ID_ANY if there is no NUMA
88 * constraint for the reserved zone.
90 * The flags parameter is used to request memzones to be
91 * taken from specifically sized hugepages.
92 * - RTE_MEMZONE_2MB - Reserved from 2MB pages
93 * - RTE_MEMZONE_1GB - Reserved from 1GB pages
94 * - RTE_MEMZONE_16MB - Reserved from 16MB pages
95 * - RTE_MEMZONE_16GB - Reserved from 16GB pages
96 * - RTE_MEMZONE_256KB - Reserved from 256KB pages
97 * - RTE_MEMZONE_256MB - Reserved from 256MB pages
98 * - RTE_MEMZONE_512MB - Reserved from 512MB pages
99 * - RTE_MEMZONE_4GB - Reserved from 4GB pages
100 * - RTE_MEMZONE_SIZE_HINT_ONLY - Allow alternative page size to be used if
101 * the requested page size is unavailable.
102 * If this flag is not set, the function
103 * will return error on an unavailable size
106 * A pointer to a correctly-filled read-only memzone descriptor, or NULL
108 * On error case, rte_errno will be set appropriately:
109 * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
110 * - E_RTE_SECONDARY - function was called from a secondary process instance
111 * - ENOSPC - the maximum number of memzones has already been allocated
112 * - EEXIST - a memzone with the same name already exists
113 * - ENOMEM - no appropriate memory area found in which to create memzone
114 * - EINVAL - invalid parameters
116 const struct rte_memzone *rte_memzone_reserve(const char *name,
117 size_t len, int socket_id,
121 * Reserve a portion of physical memory with alignment on a specified
124 * This function reserves some memory with alignment on a specified
125 * boundary, and returns a pointer to a correctly filled memzone
126 * descriptor. If the allocation cannot be done or if the alignment
127 * is not a power of 2, returns NULL.
130 * The name of the memzone. If it already exists, the function will
131 * fail and return NULL.
133 * The size of the memory to be reserved. If it
134 * is 0, the biggest contiguous zone will be reserved.
136 * The socket identifier in the case of
137 * NUMA. The value can be SOCKET_ID_ANY if there is no NUMA
138 * constraint for the reserved zone.
140 * The flags parameter is used to request memzones to be
141 * taken from specifically sized hugepages.
142 * - RTE_MEMZONE_2MB - Reserved from 2MB pages
143 * - RTE_MEMZONE_1GB - Reserved from 1GB pages
144 * - RTE_MEMZONE_16MB - Reserved from 16MB pages
145 * - RTE_MEMZONE_16GB - Reserved from 16GB pages
146 * - RTE_MEMZONE_256KB - Reserved from 256KB pages
147 * - RTE_MEMZONE_256MB - Reserved from 256MB pages
148 * - RTE_MEMZONE_512MB - Reserved from 512MB pages
149 * - RTE_MEMZONE_4GB - Reserved from 4GB pages
150 * - RTE_MEMZONE_SIZE_HINT_ONLY - Allow alternative page size to be used if
151 * the requested page size is unavailable.
152 * If this flag is not set, the function
153 * will return error on an unavailable size
156 * Alignment for resulting memzone. Must be a power of 2.
158 * A pointer to a correctly-filled read-only memzone descriptor, or NULL
160 * On error case, rte_errno will be set appropriately:
161 * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
162 * - E_RTE_SECONDARY - function was called from a secondary process instance
163 * - ENOSPC - the maximum number of memzones has already been allocated
164 * - EEXIST - a memzone with the same name already exists
165 * - ENOMEM - no appropriate memory area found in which to create memzone
166 * - EINVAL - invalid parameters
168 const struct rte_memzone *rte_memzone_reserve_aligned(const char *name,
169 size_t len, int socket_id,
170 unsigned flags, unsigned align);
173 * Reserve a portion of physical memory with specified alignment and
176 * This function reserves some memory with specified alignment and
177 * boundary, and returns a pointer to a correctly filled memzone
178 * descriptor. If the allocation cannot be done or if the alignment
179 * or boundary are not a power of 2, returns NULL.
180 * Memory buffer is reserved in a way, that it wouldn't cross specified
181 * boundary. That implies that requested length should be less or equal
185 * The name of the memzone. If it already exists, the function will
186 * fail and return NULL.
188 * The size of the memory to be reserved. If it
189 * is 0, the biggest contiguous zone will be reserved.
191 * The socket identifier in the case of
192 * NUMA. The value can be SOCKET_ID_ANY if there is no NUMA
193 * constraint for the reserved zone.
195 * The flags parameter is used to request memzones to be
196 * taken from specifically sized hugepages.
197 * - RTE_MEMZONE_2MB - Reserved from 2MB pages
198 * - RTE_MEMZONE_1GB - Reserved from 1GB pages
199 * - RTE_MEMZONE_16MB - Reserved from 16MB pages
200 * - RTE_MEMZONE_16GB - Reserved from 16GB pages
201 * - RTE_MEMZONE_256KB - Reserved from 256KB pages
202 * - RTE_MEMZONE_256MB - Reserved from 256MB pages
203 * - RTE_MEMZONE_512MB - Reserved from 512MB pages
204 * - RTE_MEMZONE_4GB - Reserved from 4GB pages
205 * - RTE_MEMZONE_SIZE_HINT_ONLY - Allow alternative page size to be used if
206 * the requested page size is unavailable.
207 * If this flag is not set, the function
208 * will return error on an unavailable size
211 * Alignment for resulting memzone. Must be a power of 2.
213 * Boundary for resulting memzone. Must be a power of 2 or zero.
214 * Zero value implies no boundary condition.
216 * A pointer to a correctly-filled read-only memzone descriptor, or NULL
218 * On error case, rte_errno will be set appropriately:
219 * - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
220 * - E_RTE_SECONDARY - function was called from a secondary process instance
221 * - ENOSPC - the maximum number of memzones has already been allocated
222 * - EEXIST - a memzone with the same name already exists
223 * - ENOMEM - no appropriate memory area found in which to create memzone
224 * - EINVAL - invalid parameters
226 const struct rte_memzone *rte_memzone_reserve_bounded(const char *name,
227 size_t len, int socket_id,
228 unsigned flags, unsigned align, unsigned bound);
234 * A pointer to the memzone
236 * -EINVAL - invalid parameter.
239 int rte_memzone_free(const struct rte_memzone *mz);
242 * Lookup for a memzone.
244 * Get a pointer to a descriptor of an already reserved memory
245 * zone identified by the name given as an argument.
248 * The name of the memzone.
250 * A pointer to a read-only memzone descriptor.
252 const struct rte_memzone *rte_memzone_lookup(const char *name);
255 * Dump all reserved memzones to a file.
258 * A pointer to a file for output
260 void rte_memzone_dump(FILE *f);
263 * Walk list of all memzones
268 * Argument passed to iterator
270 void rte_memzone_walk(void (*func)(const struct rte_memzone *, void *arg),
277 #endif /* _RTE_MEMZONE_H_ */