ivshmem: library changes for mmaping using ivshmem
[dpdk.git] / lib / librte_eal / common / include / rte_memory.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_MEMORY_H_
35 #define _RTE_MEMORY_H_
36
37 /**
38  * @file
39  *
40  * Memory-related RTE API.
41  */
42
43 #include <stdint.h>
44 #include <stddef.h>
45
46 #ifdef __cplusplus
47 extern "C" {
48 #endif
49
50 enum rte_page_sizes {
51         RTE_PGSIZE_4K = 1 << 12,
52         RTE_PGSIZE_2M = RTE_PGSIZE_4K << 9,
53         RTE_PGSIZE_1G = RTE_PGSIZE_2M <<9
54 };
55
56 #define SOCKET_ID_ANY -1                    /**< Any NUMA socket. */
57 #ifndef CACHE_LINE_SIZE
58 #define CACHE_LINE_SIZE 64                  /**< Cache line size. */
59 #endif
60 #define CACHE_LINE_MASK (CACHE_LINE_SIZE-1) /**< Cache line mask. */
61
62 #define CACHE_LINE_ROUNDUP(size) \
63         (CACHE_LINE_SIZE * ((size + CACHE_LINE_SIZE - 1) / CACHE_LINE_SIZE))
64 /**< Return the first cache-aligned value greater or equal to size. */
65
66 /**
67  * Force alignment to cache line.
68  */
69 #define __rte_cache_aligned __attribute__((__aligned__(CACHE_LINE_SIZE)))
70
71 typedef uint64_t phys_addr_t; /**< Physical address definition. */
72
73 /**
74  * Physical memory segment descriptor.
75  */
76 struct rte_memseg {
77         phys_addr_t phys_addr;      /**< Start physical address. */
78         union {
79                 void *addr;         /**< Start virtual address. */
80                 uint64_t addr_64;   /**< Makes sure addr is always 64 bits */
81         };
82 #ifdef RTE_LIBRTE_IVSHMEM
83         phys_addr_t ioremap_addr; /**< Real physical address inside the VM */
84 #endif
85         size_t len;               /**< Length of the segment. */
86         size_t hugepage_sz;       /**< The pagesize of underlying memory */
87         int32_t socket_id;          /**< NUMA socket ID. */
88         uint32_t nchannel;          /**< Number of channels. */
89         uint32_t nrank;             /**< Number of ranks. */
90 } __attribute__((__packed__));
91
92
93 /**
94  * Get the layout of the available physical memory.
95  *
96  * It can be useful for an application to have the full physical
97  * memory layout to decide the size of a memory zone to reserve. This
98  * table is stored in rte_config (see rte_eal_get_configuration()).
99  *
100  * @return
101  *  - On success, return a pointer to a read-only table of struct
102  *    rte_physmem_desc elements, containing the layout of all
103  *    addressable physical memory. The last element of the table
104  *    contains a NULL address.
105  *  - On error, return NULL. This should not happen since it is a fatal
106  *    error that will probably cause the entire system to panic.
107  */
108 const struct rte_memseg *rte_eal_get_physmem_layout(void);
109
110 /**
111  * Dump the physical memory layout to the console.
112  */
113 void rte_dump_physmem_layout(void);
114
115 /**
116  * Get the total amount of available physical memory.
117  *
118  * @return
119  *    The total amount of available physical memory in bytes.
120  */
121 uint64_t rte_eal_get_physmem_size(void);
122
123 /**
124  * Get the number of memory channels.
125  *
126  * @return
127  *   The number of memory channels on the system. The value is 0 if unknown
128  *   or not the same on all devices.
129  */
130 unsigned rte_memory_get_nchannel(void);
131
132 /**
133  * Get the number of memory ranks.
134  *
135  * @return
136  *   The number of memory ranks on the system. The value is 0 if unknown or
137  *   not the same on all devices.
138  */
139 unsigned rte_memory_get_nrank(void);
140
141 #ifdef __cplusplus
142 }
143 #endif
144
145 #endif /* _RTE_MEMORY_H_ */