DPDK  21.11.0
rte_memory.h
Go to the documentation of this file.
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 Intel Corporation
3  */
4 
5 #ifndef _RTE_MEMORY_H_
6 #define _RTE_MEMORY_H_
7 
14 #include <stdint.h>
15 #include <stddef.h>
16 #include <stdio.h>
17 
18 #ifdef __cplusplus
19 extern "C" {
20 #endif
21 
22 #include <rte_common.h>
23 #include <rte_compat.h>
24 #include <rte_config.h>
25 #include <rte_fbarray.h>
26 
27 #define RTE_PGSIZE_4K (1ULL << 12)
28 #define RTE_PGSIZE_64K (1ULL << 16)
29 #define RTE_PGSIZE_256K (1ULL << 18)
30 #define RTE_PGSIZE_2M (1ULL << 21)
31 #define RTE_PGSIZE_16M (1ULL << 24)
32 #define RTE_PGSIZE_256M (1ULL << 28)
33 #define RTE_PGSIZE_512M (1ULL << 29)
34 #define RTE_PGSIZE_1G (1ULL << 30)
35 #define RTE_PGSIZE_4G (1ULL << 32)
36 #define RTE_PGSIZE_16G (1ULL << 34)
37 
38 #define SOCKET_ID_ANY -1
43 #define RTE_MEMSEG_FLAG_DO_NOT_FREE (1 << 0)
44 
45 struct rte_memseg {
46  rte_iova_t iova;
48  union {
49  void *addr;
50  uint64_t addr_64;
51  };
52  size_t len;
53  uint64_t hugepage_sz;
54  int32_t socket_id;
55  uint32_t nchannel;
56  uint32_t nrank;
57  uint32_t flags;
58 } __rte_packed;
59 
66  union {
67  void *base_va;
69  uint64_t addr_64;
71  };
72  uint64_t page_sz;
73  int socket_id;
74  volatile uint32_t version;
75  size_t len;
76  unsigned int external;
77  unsigned int heap;
78  struct rte_fbarray memseg_arr;
79 };
80 
89 int rte_mem_lock_page(const void *virt);
90 
101 phys_addr_t rte_mem_virt2phy(const void *virt);
102 
116 rte_iova_t rte_mem_virt2iova(const void *virt);
117 
130 void *
132 
144 struct rte_memseg *
145 rte_mem_virt2memseg(const void *virt, const struct rte_memseg_list *msl);
146 
155 struct rte_memseg_list *
156 rte_mem_virt2memseg_list(const void *virt);
157 
165 typedef int (*rte_memseg_walk_t)(const struct rte_memseg_list *msl,
166  const struct rte_memseg *ms, void *arg);
167 
177 typedef int (*rte_memseg_contig_walk_t)(const struct rte_memseg_list *msl,
178  const struct rte_memseg *ms, size_t len, void *arg);
179 
188 typedef int (*rte_memseg_list_walk_t)(const struct rte_memseg_list *msl,
189  void *arg);
190 
209 int
210 rte_memseg_walk(rte_memseg_walk_t func, void *arg);
211 
230 int
232 
251 int
253 
269 int
271 
287 int
289 
305 int
307 
329 int
330 rte_memseg_get_fd(const struct rte_memseg *ms);
331 
353 int
354 rte_memseg_get_fd_thread_unsafe(const struct rte_memseg *ms);
355 
377 int
378 rte_memseg_get_fd_offset(const struct rte_memseg *ms, size_t *offset);
379 
401 int
402 rte_memseg_get_fd_offset_thread_unsafe(const struct rte_memseg *ms,
403  size_t *offset);
404 
439 int
440 rte_extmem_register(void *va_addr, size_t len, rte_iova_t iova_addrs[],
441  unsigned int n_pages, size_t page_sz);
442 
466 int
467 rte_extmem_unregister(void *va_addr, size_t len);
468 
489 int
490 rte_extmem_attach(void *va_addr, size_t len);
491 
512 int
513 rte_extmem_detach(void *va_addr, size_t len);
514 
524 void rte_dump_physmem_layout(FILE *f);
525 
535 uint64_t rte_eal_get_physmem_size(void);
536 
544 unsigned rte_memory_get_nchannel(void);
545 
553 unsigned rte_memory_get_nrank(void);
554 
562 int rte_mem_check_dma_mask(uint8_t maskbits);
563 
577 int rte_mem_check_dma_mask_thread_unsafe(uint8_t maskbits);
578 
584 void rte_mem_set_dma_mask(uint8_t maskbits);
585 
595 int rte_eal_using_phys_addrs(void);
596 
597 
605 };
606 #define RTE_MEM_EVENT_CALLBACK_NAME_LEN 64
607 
612 typedef void (*rte_mem_event_callback_t)(enum rte_mem_event event_type,
613  const void *addr, size_t len, void *arg);
614 
640 int
642  void *arg);
643 
658 int
659 rte_mem_event_callback_unregister(const char *name, void *arg);
660 
661 
662 #define RTE_MEM_ALLOC_VALIDATOR_NAME_LEN 64
663 
671  size_t cur_limit, size_t new_len);
672 
707 int
708 rte_mem_alloc_validator_register(const char *name,
709  rte_mem_alloc_validator_t clb, int socket_id, size_t limit);
710 
725 int
726 rte_mem_alloc_validator_unregister(const char *name, int socket_id);
727 
728 #ifdef __cplusplus
729 }
730 #endif
731 
732 #endif /* _RTE_MEMORY_H_ */
#define __rte_packed
Definition: rte_common.h:86
unsigned rte_memory_get_nchannel(void)
int rte_memseg_walk(rte_memseg_walk_t func, void *arg)
void * rte_mem_iova2virt(rte_iova_t iova)
int rte_memseg_contig_walk_thread_unsafe(rte_memseg_contig_walk_t func, void *arg)
int rte_mem_alloc_validator_unregister(const char *name, int socket_id)
Unregister validator callback for memory allocations.
int rte_mem_event_callback_register(const char *name, rte_mem_event_callback_t clb, void *arg)
uint64_t rte_iova_t
Definition: rte_common.h:420
int rte_eal_using_phys_addrs(void)
int rte_mem_lock_page(const void *virt)
int rte_memseg_get_fd(const struct rte_memseg *ms)
unsigned rte_memory_get_nrank(void)
int rte_memseg_get_fd_thread_unsafe(const struct rte_memseg *ms)
int rte_extmem_attach(void *va_addr, size_t len)
int(* rte_memseg_walk_t)(const struct rte_memseg_list *msl, const struct rte_memseg *ms, void *arg)
Definition: rte_memory.h:165
rte_mem_event
Definition: rte_memory.h:602
phys_addr_t rte_mem_virt2phy(const void *virt)
int rte_mem_check_dma_mask(uint8_t maskbits)
struct rte_memseg * rte_mem_virt2memseg(const void *virt, const struct rte_memseg_list *msl)
uint64_t rte_eal_get_physmem_size(void)
int rte_mem_alloc_validator_register(const char *name, rte_mem_alloc_validator_t clb, int socket_id, size_t limit)
Register validator callback for memory allocations.
void(* rte_mem_event_callback_t)(enum rte_mem_event event_type, const void *addr, size_t len, void *arg)
Definition: rte_memory.h:612
uint64_t phys_addr_t
Definition: rte_common.h:410
int rte_extmem_unregister(void *va_addr, size_t len)
void rte_mem_set_dma_mask(uint8_t maskbits)
void * base_va
Definition: rte_memory.h:67
volatile uint32_t version
Definition: rte_memory.h:74
uint64_t addr_64
Definition: rte_memory.h:69
int rte_extmem_detach(void *va_addr, size_t len)
int rte_memseg_get_fd_offset_thread_unsafe(const struct rte_memseg *ms, size_t *offset)
void rte_dump_physmem_layout(FILE *f)
int rte_memseg_list_walk(rte_memseg_list_walk_t func, void *arg)
int rte_extmem_register(void *va_addr, size_t len, rte_iova_t iova_addrs[], unsigned int n_pages, size_t page_sz)
int rte_mem_check_dma_mask_thread_unsafe(uint8_t maskbits)
int rte_memseg_get_fd_offset(const struct rte_memseg *ms, size_t *offset)
#define RTE_STD_C11
Definition: rte_common.h:42
struct rte_memseg_list * rte_mem_virt2memseg_list(const void *virt)
int rte_memseg_list_walk_thread_unsafe(rte_memseg_list_walk_t func, void *arg)
unsigned int heap
Definition: rte_memory.h:77
unsigned int external
Definition: rte_memory.h:76
int rte_mem_event_callback_unregister(const char *name, void *arg)
uint64_t page_sz
Definition: rte_memory.h:72
int(* rte_memseg_contig_walk_t)(const struct rte_memseg_list *msl, const struct rte_memseg *ms, size_t len, void *arg)
Definition: rte_memory.h:177
int(* rte_mem_alloc_validator_t)(int socket_id, size_t cur_limit, size_t new_len)
Definition: rte_memory.h:670
int(* rte_memseg_list_walk_t)(const struct rte_memseg_list *msl, void *arg)
Definition: rte_memory.h:188
int rte_memseg_walk_thread_unsafe(rte_memseg_walk_t func, void *arg)
int rte_memseg_contig_walk(rte_memseg_contig_walk_t func, void *arg)
rte_iova_t rte_mem_virt2iova(const void *virt)