doc: fix doxygen warnings
[dpdk.git] / lib / librte_eal / common / include / rte_memzone.h
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_MEMZONE_H_
35 #define _RTE_MEMZONE_H_
36
37 /**
38  * @file
39  * RTE Memzone
40  *
41  * The goal of the memzone allocator is to reserve contiguous
42  * portions of physical memory. These zones are identified by a name.
43  *
44  * The memzone descriptors are shared by all partitions and are
45  * located in a known place of physical memory. This zone is accessed
46  * using rte_eal_get_configuration(). The lookup (by name) of a
47  * memory zone can be done in any partition and returns the same
48  * physical address.
49  *
50  * A reserved memory zone cannot be unreserved. The reservation shall
51  * be done at initialization time only.
52  */
53
54 #include <stdio.h>
55 #include <rte_memory.h>
56
57 #ifdef __cplusplus
58 extern "C" {
59 #endif
60
61 #define RTE_MEMZONE_2MB            0x00000001   /**< Use 2MB pages. */
62 #define RTE_MEMZONE_1GB            0x00000002   /**< Use 1GB pages. */
63 #define RTE_MEMZONE_16MB            0x00000100   /**< Use 16MB pages. */
64 #define RTE_MEMZONE_16GB            0x00000200   /**< Use 16GB pages. */
65 #define RTE_MEMZONE_SIZE_HINT_ONLY 0x00000004   /**< Use available page size */
66
67 /**
68  * A structure describing a memzone, which is a contiguous portion of
69  * physical memory identified by a name.
70  */
71 struct rte_memzone {
72
73 #define RTE_MEMZONE_NAMESIZE 32       /**< Maximum length of memory zone name.*/
74         char name[RTE_MEMZONE_NAMESIZE];  /**< Name of the memory zone. */
75
76         phys_addr_t phys_addr;            /**< Start physical address. */
77         union {
78                 void *addr;                   /**< Start virtual address. */
79                 uint64_t addr_64;             /**< Makes sure addr is always 64-bits */
80         };
81 #ifdef RTE_LIBRTE_IVSHMEM
82         phys_addr_t ioremap_addr;         /**< Real physical address inside the VM */
83 #endif
84         size_t len;                       /**< Length of the memzone. */
85
86         uint64_t hugepage_sz;             /**< The page size of underlying memory */
87
88         int32_t socket_id;                /**< NUMA socket ID. */
89
90         uint32_t flags;                   /**< Characteristics of this memzone. */
91         uint32_t memseg_id;             /** <store the memzone is from which memseg. */
92 } __attribute__((__packed__));
93
94 /**
95  * Reserve a portion of physical memory.
96  *
97  * This function reserves some memory and returns a pointer to a
98  * correctly filled memzone descriptor. If the allocation cannot be
99  * done, return NULL. Note: A reserved zone cannot be freed.
100  *
101  * @param name
102  *   The name of the memzone. If it already exists, the function will
103  *   fail and return NULL.
104  * @param len
105  *   The size of the memory to be reserved. If it
106  *   is 0, the biggest contiguous zone will be reserved.
107  * @param socket_id
108  *   The socket identifier in the case of
109  *   NUMA. The value can be SOCKET_ID_ANY if there is no NUMA
110  *   constraint for the reserved zone.
111  * @param flags
112  *   The flags parameter is used to request memzones to be
113  *   taken from 1GB or 2MB hugepages.
114  *   - RTE_MEMZONE_2MB - Reserve from 2MB pages
115  *   - RTE_MEMZONE_1GB - Reserve from 1GB pages
116  *   - RTE_MEMZONE_16MB - Reserve from 16MB pages
117  *   - RTE_MEMZONE_16GB - Reserve from 16GB pages
118  *   - RTE_MEMZONE_SIZE_HINT_ONLY - Allow alternative page size to be used if
119  *                                  the requested page size is unavailable.
120  *                                  If this flag is not set, the function
121  *                                  will return error on an unavailable size
122  *                                  request.
123  * @return
124  *   A pointer to a correctly-filled read-only memzone descriptor, or NULL
125  *   on error.
126  *   On error case, rte_errno will be set appropriately:
127  *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
128  *    - E_RTE_SECONDARY - function was called from a secondary process instance
129  *    - ENOSPC - the maximum number of memzones has already been allocated
130  *    - EEXIST - a memzone with the same name already exists
131  *    - ENOMEM - no appropriate memory area found in which to create memzone
132  *    - EINVAL - invalid parameters
133  */
134 const struct rte_memzone *rte_memzone_reserve(const char *name,
135                                               size_t len, int socket_id,
136                                               unsigned flags);
137
138 /**
139  * Reserve a portion of physical memory with alignment on a specified
140  * boundary.
141  *
142  * This function reserves some memory with alignment on a specified
143  * boundary, and returns a pointer to a correctly filled memzone
144  * descriptor. If the allocation cannot be done or if the alignment
145  * is not a power of 2, returns NULL.
146  * Note: A reserved zone cannot be freed.
147  *
148  * @param name
149  *   The name of the memzone. If it already exists, the function will
150  *   fail and return NULL.
151  * @param len
152  *   The size of the memory to be reserved. If it
153  *   is 0, the biggest contiguous zone will be reserved.
154  * @param socket_id
155  *   The socket identifier in the case of
156  *   NUMA. The value can be SOCKET_ID_ANY if there is no NUMA
157  *   constraint for the reserved zone.
158  * @param flags
159  *   The flags parameter is used to request memzones to be
160  *   taken from 1GB or 2MB hugepages.
161  *   - RTE_MEMZONE_2MB - Reserve from 2MB pages
162  *   - RTE_MEMZONE_1GB - Reserve from 1GB pages
163  *   - RTE_MEMZONE_16MB - Reserve from 16MB pages
164  *   - RTE_MEMZONE_16GB - Reserve from 16GB pages
165  *   - RTE_MEMZONE_SIZE_HINT_ONLY - Allow alternative page size to be used if
166  *                                  the requested page size is unavailable.
167  *                                  If this flag is not set, the function
168  *                                  will return error on an unavailable size
169  *                                  request.
170  * @param align
171  *   Alignment for resulting memzone. Must be a power of 2.
172  * @return
173  *   A pointer to a correctly-filled read-only memzone descriptor, or NULL
174  *   on error.
175  *   On error case, rte_errno will be set appropriately:
176  *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
177  *    - E_RTE_SECONDARY - function was called from a secondary process instance
178  *    - ENOSPC - the maximum number of memzones has already been allocated
179  *    - EEXIST - a memzone with the same name already exists
180  *    - ENOMEM - no appropriate memory area found in which to create memzone
181  *    - EINVAL - invalid parameters
182  */
183 const struct rte_memzone *rte_memzone_reserve_aligned(const char *name,
184                         size_t len, int socket_id,
185                         unsigned flags, unsigned align);
186
187 /**
188  * Reserve a portion of physical memory with specified alignment and
189  * boundary.
190  *
191  * This function reserves some memory with specified alignment and
192  * boundary, and returns a pointer to a correctly filled memzone
193  * descriptor. If the allocation cannot be done or if the alignment
194  * or boundary are not a power of 2, returns NULL.
195  * Memory buffer is reserved in a way, that it wouldn't cross specified
196  * boundary. That implies that requested length should be less or equal
197  * then boundary.
198  * Note: A reserved zone cannot be freed.
199  *
200  * @param name
201  *   The name of the memzone. If it already exists, the function will
202  *   fail and return NULL.
203  * @param len
204  *   The size of the memory to be reserved. If it
205  *   is 0, the biggest contiguous zone will be reserved.
206  * @param socket_id
207  *   The socket identifier in the case of
208  *   NUMA. The value can be SOCKET_ID_ANY if there is no NUMA
209  *   constraint for the reserved zone.
210  * @param flags
211  *   The flags parameter is used to request memzones to be
212  *   taken from 1GB or 2MB hugepages.
213  *   - RTE_MEMZONE_2MB - Reserve from 2MB pages
214  *   - RTE_MEMZONE_1GB - Reserve from 1GB pages
215  *   - RTE_MEMZONE_16MB - Reserve from 16MB pages
216  *   - RTE_MEMZONE_16GB - Reserve from 16GB pages
217  *   - RTE_MEMZONE_SIZE_HINT_ONLY - Allow alternative page size to be used if
218  *                                  the requested page size is unavailable.
219  *                                  If this flag is not set, the function
220  *                                  will return error on an unavailable size
221  *                                  request.
222  * @param align
223  *   Alignment for resulting memzone. Must be a power of 2.
224  * @param bound
225  *   Boundary for resulting memzone. Must be a power of 2 or zero.
226  *   Zero value implies no boundary condition.
227  * @return
228  *   A pointer to a correctly-filled read-only memzone descriptor, or NULL
229  *   on error.
230  *   On error case, rte_errno will be set appropriately:
231  *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
232  *    - E_RTE_SECONDARY - function was called from a secondary process instance
233  *    - ENOSPC - the maximum number of memzones has already been allocated
234  *    - EEXIST - a memzone with the same name already exists
235  *    - ENOMEM - no appropriate memory area found in which to create memzone
236  *    - EINVAL - invalid parameters
237  */
238 const struct rte_memzone *rte_memzone_reserve_bounded(const char *name,
239                         size_t len, int socket_id,
240                         unsigned flags, unsigned align, unsigned bound);
241
242 /**
243  * Lookup for a memzone.
244  *
245  * Get a pointer to a descriptor of an already reserved memory
246  * zone identified by the name given as an argument.
247  *
248  * @param name
249  *   The name of the memzone.
250  * @return
251  *   A pointer to a read-only memzone descriptor.
252  */
253 const struct rte_memzone *rte_memzone_lookup(const char *name);
254
255 /**
256  * Dump all reserved memzones to the console.
257  *
258  * @param f
259  *   A pointer to a file for output
260  */
261 void rte_memzone_dump(FILE *f);
262
263 /**
264  * Walk list of all memzones
265  *
266  * @param func
267  *   Iterator function
268  * @param arg
269  *   Argument passed to iterator
270  */
271 void rte_memzone_walk(void (*func)(const struct rte_memzone *, void *arg),
272                       void *arg);
273
274 #ifdef __cplusplus
275 }
276 #endif
277
278 #endif /* _RTE_MEMZONE_H_ */