common/mlx5/linux: replace malloc and free in glue
[dpdk.git] / drivers / common / mlx5 / mlx5_malloc.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2020 Mellanox Technologies, Ltd
3  */
4
5 #ifndef MLX5_MALLOC_H_
6 #define MLX5_MALLOC_H_
7
8 #ifdef __cplusplus
9 extern "C" {
10 #endif
11
12 #ifndef MLX5_MALLOC_ALIGNMENT
13 #ifndef RTE_ARCH_64
14 #define MLX5_MALLOC_ALIGNMENT 8
15 #else
16 #define MLX5_MALLOC_ALIGNMENT 16
17 #endif
18 #endif
19
20 enum mlx5_mem_flags {
21         MLX5_MEM_ANY = 0,
22         /* Memory will be allocated dpends on sys_mem_en. */
23         MLX5_MEM_SYS = 1 << 0,
24         /* Memory should be allocated from system. */
25         MLX5_MEM_RTE = 1 << 1,
26         /* Memory should be allocated from rte hugepage. */
27         MLX5_MEM_ZERO = 1 << 2,
28         /* Memory should be cleared to zero. */
29 };
30
31 /**
32  * Select the PMD memory allocate preference.
33  *
34  * Once sys_mem_en is set, the default memory allocate will from
35  * system only if an explicitly flag is set to order the memory
36  * from rte hugepage memory.
37  *
38  * @param sys_mem_en
39  *   Use system memory or not.
40  */
41 __rte_internal
42 void mlx5_malloc_mem_select(uint32_t sys_mem_en);
43
44 /**
45  * Dump the PMD memory usage statistic.
46  */
47 __rte_internal
48 void mlx5_memory_stat_dump(void);
49
50 /**
51  * Memory allocate function.
52  *
53  * @param flags
54  *   The bits as enum mlx5_mem_flags defined.
55  * @param size
56  *   Memory size to be allocated.
57  * @param align
58  *   Memory alignment.
59  * @param socket
60  *   The socket memory should allocated.
61  *   Valid only when allocate the memory from rte hugepage.
62  *
63  * @return
64  *   Pointer of the allocated memory, NULL otherwise.
65  */
66 __rte_internal
67 void *mlx5_malloc(uint32_t flags, size_t size, unsigned int align, int socket);
68
69 /**
70  * Memory reallocate function.
71  *
72  *
73  *
74  * @param addr
75  *   The memory to be reallocated.
76  * @param flags
77  *   The bits as enum mlx5_mem_flags defined.
78  * @param size
79  *   Memory size to be allocated.
80  * @param align
81  *   Memory alignment.
82  * @param socket
83  *   The socket memory should allocated.
84  *   Valid only when allocate the memory from rte hugepage.
85  *
86  * @return
87  *   Pointer of the allocated memory, NULL otherwise.
88  */
89
90 __rte_internal
91 void *mlx5_realloc(void *addr, uint32_t flags, size_t size, unsigned int align,
92                    int socket);
93
94 /**
95  * Memory free function.
96  *
97  * @param addr
98  *   The memory address to be freed..
99  */
100 __rte_internal
101 void mlx5_free(void *addr);
102
103 #ifdef __cplusplus
104 }
105 #endif
106
107 #endif