remove version in all files
[dpdk.git] / lib / librte_eal / common / include / rte_memzone.h
1 /*-
2  *   BSD LICENSE
3  * 
4  *   Copyright(c) 2010-2012 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
35 #ifndef _RTE_MEMZONE_H_
36 #define _RTE_MEMZONE_H_
37
38 /**
39  * @file
40  * RTE Memzone
41  *
42  * The goal of the memzone allocator is to reserve contiguous
43  * portions of physical memory. These zones are identified by a name.
44  *
45  * The memzone descriptors are shared by all partitions and are
46  * located in a known place of physical memory. This zone is accessed
47  * using rte_eal_get_configuration(). The lookup (by name) of a
48  * memory zone can be done in any partition and returns the same
49  * physical address.
50  *
51  * A reserved memory zone cannot be unreserved. The reservation shall
52  * be done at initialization time only.
53  */
54
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_SIZE_HINT_ONLY 0x00000004   /**< Use available page size */
64
65 /**
66  * A structure describing a memzone, which is a contiguous portion of
67  * physical memory identified by a name.
68  */
69 struct rte_memzone {
70
71 #define RTE_MEMZONE_NAMESIZE 32       /**< Maximum length of memory zone name.*/
72         char name[RTE_MEMZONE_NAMESIZE];  /**< Name of the memory zone. */
73
74         phys_addr_t phys_addr;            /**< Start physical address. */
75         union {
76                 void *addr;                   /**< Start virtual address. */
77                 uint64_t addr_64;             /**< Makes sure addr is always 64-bits */
78         };
79         uint64_t len;                     /**< Length of the memzone. */
80
81         uint64_t hugepage_sz;             /**< The page size of underlying memory */
82
83         int32_t socket_id;                /**< NUMA socket ID. */
84
85         uint32_t flags;                   /**< Characteristics of this memzone. */
86 } __attribute__((__packed__));
87
88 /**
89  * Reserve a portion of physical memory.
90  *
91  * This function reserves some memory and returns a pointer to a
92  * correctly filled memzone descriptor. If the allocation cannot be
93  * done, return NULL. Note: A reserved zone cannot be freed.
94  *
95  * @param name
96  *   The name of the memzone. If it already exists, the function will
97  *   fail and return NULL.
98  * @param len
99  *   The size of the memory to be reserved. If it
100  *   is 0, the biggest contiguous zone will be reserved.
101  * @param socket_id
102  *   The socket identifier in the case of
103  *   NUMA. The value can be SOCKET_ID_ANY if there is no NUMA
104  *   constraint for the reserved zone.
105  * @param flags
106  *   The flags parameter is used to request memzones to be
107  *   taken from 1GB or 2MB hugepages.
108  *   - RTE_MEMZONE_2MB - Reserve from 2MB pages
109  *   - RTE_MEMZONE_1GB - Reserve from 1GB pages
110  *   - RTE_MEMZONE_SIZE_HINT_ONLY - Allow alternative page size to be used if
111  *                                  the requested page size is unavailable.
112  *                                  If this flag is not set, the function
113  *                                  will return error on an unavailable size
114  *                                  request.
115  * @return
116  *   A pointer to a correctly-filled read-only memzone descriptor, or NULL
117  *   on error.
118  *   On error case, rte_errno will be set appropriately:
119  *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
120  *    - E_RTE_SECONDARY - function was called from a secondary process instance
121  *    - ENOSPC - the maximum number of memzones has already been allocated
122  *    - EEXIST - a memzone with the same name already exists
123  *    - ENOMEM - no appropriate memory area found in which to create memzone
124  *    - EINVAL - invalid parameters
125  */
126 const struct rte_memzone *rte_memzone_reserve(const char *name,
127                                               uint64_t len, int socket_id,
128                                               unsigned flags);
129
130 /**
131  * Reserve a portion of physical memory with alignment on a specified
132  * boundary.
133  *
134  * This function reserves some memory with alignment on a specified
135  * boundary, and returns a pointer to a correctly filled memzone
136  * descriptor. If the allocation cannot be done or if the alignment
137  * is not a power of 2, returns NULL.
138  * Note: A reserved zone cannot be freed.
139  *
140  * @param name
141  *   The name of the memzone. If it already exists, the function will
142  *   fail and return NULL.
143  * @param len
144  *   The size of the memory to be reserved. If it
145  *   is 0, the biggest contiguous zone will be reserved.
146  * @param align
147  *   Alignment for resulting memzone. Must be a power of 2.
148  * @param socket_id
149  *   The socket identifier in the case of
150  *   NUMA. The value can be SOCKET_ID_ANY if there is no NUMA
151  *   constraint for the reserved zone.
152  * @param flags
153  *   The flags parameter is used to request memzones to be
154  *   taken from 1GB or 2MB hugepages.
155  *   - RTE_MEMZONE_2MB - Reserve from 2MB pages
156  *   - RTE_MEMZONE_1GB - Reserve from 1GB pages
157  *   - RTE_MEMZONE_SIZE_HINT_ONLY - Allow alternative page size to be used if
158  *                                  the requested page size is unavailable.
159  *                                  If this flag is not set, the function
160  *                                  will return error on an unavailable size
161  *                                  request.
162  * @return
163  *   A pointer to a correctly-filled read-only memzone descriptor, or NULL
164  *   on error.
165  *   On error case, rte_errno will be set appropriately:
166  *    - E_RTE_NO_CONFIG - function could not get pointer to rte_config structure
167  *    - E_RTE_SECONDARY - function was called from a secondary process instance
168  *    - ENOSPC - the maximum number of memzones has already been allocated
169  *    - EEXIST - a memzone with the same name already exists
170  *    - ENOMEM - no appropriate memory area found in which to create memzone
171  *    - EINVAL - invalid parameters
172  */
173 const struct rte_memzone *rte_memzone_reserve_aligned(const char *name,
174                                               uint64_t len, int socket_id, unsigned flags,
175                                               unsigned align);
176
177 /**
178  * Lookup for a memzone.
179  *
180  * Get a pointer to a descriptor of an already reserved memory
181  * zone identified by the name given as an argument.
182  *
183  * @param name
184  *   The name of the memzone.
185  * @return
186  *   A pointer to a read-only memzone descriptor.
187  */
188 const struct rte_memzone *rte_memzone_lookup(const char *name);
189
190 /**
191  * Dump all reserved memzones to the console.
192  */
193 void rte_memzone_dump(void);
194
195 #ifdef __cplusplus
196 }
197 #endif
198
199 #endif /* _RTE_MEMZONE_H_ */