DPDK  17.11.0
rte_memory.h
Go to the documentation of this file.
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 
43 #include <stdint.h>
44 #include <stddef.h>
45 #include <stdio.h>
46 
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50 
51 #include <rte_common.h>
52 
53 __extension__
54 enum rte_page_sizes {
55  RTE_PGSIZE_4K = 1ULL << 12,
56  RTE_PGSIZE_64K = 1ULL << 16,
57  RTE_PGSIZE_256K = 1ULL << 18,
58  RTE_PGSIZE_2M = 1ULL << 21,
59  RTE_PGSIZE_16M = 1ULL << 24,
60  RTE_PGSIZE_256M = 1ULL << 28,
61  RTE_PGSIZE_512M = 1ULL << 29,
62  RTE_PGSIZE_1G = 1ULL << 30,
63  RTE_PGSIZE_4G = 1ULL << 32,
64  RTE_PGSIZE_16G = 1ULL << 34,
65 };
66 
67 #define SOCKET_ID_ANY -1
68 #define RTE_CACHE_LINE_MASK (RTE_CACHE_LINE_SIZE-1)
70 #define RTE_CACHE_LINE_ROUNDUP(size) \
71  (RTE_CACHE_LINE_SIZE * ((size + RTE_CACHE_LINE_SIZE - 1) / RTE_CACHE_LINE_SIZE))
72 
75 #if RTE_CACHE_LINE_SIZE == 64
76 #define RTE_CACHE_LINE_SIZE_LOG2 6
77 #elif RTE_CACHE_LINE_SIZE == 128
78 #define RTE_CACHE_LINE_SIZE_LOG2 7
79 #else
80 #error "Unsupported cache line size"
81 #endif
82 
83 #define RTE_CACHE_LINE_MIN_SIZE 64
88 #define __rte_cache_aligned __rte_aligned(RTE_CACHE_LINE_SIZE)
89 
93 #define __rte_cache_min_aligned __rte_aligned(RTE_CACHE_LINE_MIN_SIZE)
94 
95 typedef uint64_t phys_addr_t;
96 #define RTE_BAD_PHYS_ADDR ((phys_addr_t)-1)
97 
104 typedef uint64_t rte_iova_t;
105 #define RTE_BAD_IOVA ((rte_iova_t)-1)
110 struct rte_memseg {
112  union {
114  rte_iova_t iova;
115  };
117  union {
118  void *addr;
119  uint64_t addr_64;
120  };
121  size_t len;
122  uint64_t hugepage_sz;
123  int32_t socket_id;
124  uint32_t nchannel;
125  uint32_t nrank;
136 int rte_mem_lock_page(const void *virt);
137 
148 phys_addr_t rte_mem_virt2phy(const void *virt);
149 
158 rte_iova_t rte_mem_virt2iova(const void *virt);
159 
175 const struct rte_memseg *rte_eal_get_physmem_layout(void);
176 
183 void rte_dump_physmem_layout(FILE *f);
184 
191 uint64_t rte_eal_get_physmem_size(void);
192 
200 unsigned rte_memory_get_nchannel(void);
201 
209 unsigned rte_memory_get_nrank(void);
210 
220 int rte_eal_using_phys_addrs(void);
221 
222 #ifdef __cplusplus
223 }
224 #endif
225 
226 #endif /* _RTE_MEMORY_H_ */
void * addr
Definition: rte_memory.h:120
unsigned rte_memory_get_nchannel(void)
const struct rte_memseg * rte_eal_get_physmem_layout(void)
rte_iova_t iova
Definition: rte_memory.h:116
uint32_t nchannel
Definition: rte_memory.h:126
int rte_eal_using_phys_addrs(void)
int rte_mem_lock_page(const void *virt)
unsigned rte_memory_get_nrank(void)
int32_t socket_id
Definition: rte_memory.h:125
uint64_t addr_64
Definition: rte_memory.h:121
size_t len
Definition: rte_memory.h:123
uint64_t hugepage_sz
Definition: rte_memory.h:124
phys_addr_t rte_mem_virt2phy(const void *virt)
#define __rte_packed
Definition: rte_common.h:93
uint64_t rte_eal_get_physmem_size(void)
phys_addr_t phys_addr
Definition: rte_memory.h:115
void rte_dump_physmem_layout(FILE *f)
#define RTE_STD_C11
Definition: rte_common.h:64
uint64_t rte_iova_t
Definition: rte_memory.h:106
uint64_t phys_addr_t
Definition: rte_memory.h:97
uint32_t nrank
Definition: rte_memory.h:127
rte_iova_t rte_mem_virt2iova(const void *virt)