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 void mlx5_malloc_mem_select(uint32_t sys_mem_en); 42 43 /** 44 * Dump the PMD memory usage statistic. 45 */ 46 __rte_internal 47 void mlx5_memory_stat_dump(void); 48 49 /** 50 * Memory allocate function. 51 * 52 * @param flags 53 * The bits as enum mlx5_mem_flags defined. 54 * @param size 55 * Memory size to be allocated. 56 * @param align 57 * Memory alignment. 58 * @param socket 59 * The socket memory should allocated. 60 * Valid only when allocate the memory from rte hugepage. 61 * 62 * @return 63 * Pointer of the allocated memory, NULL otherwise. 64 */ 65 __rte_internal 66 void *mlx5_malloc(uint32_t flags, size_t size, unsigned int align, int socket); 67 68 /** 69 * Memory reallocate function. 70 * 71 * 72 * 73 * @param addr 74 * The memory to be reallocated. 75 * @param flags 76 * The bits as enum mlx5_mem_flags defined. 77 * @param size 78 * Memory size to be allocated. 79 * @param align 80 * Memory alignment. 81 * @param socket 82 * The socket memory should allocated. 83 * Valid only when allocate the memory from rte hugepage. 84 * 85 * @return 86 * Pointer of the allocated memory, NULL otherwise. 87 */ 88 89 __rte_internal 90 void *mlx5_realloc(void *addr, uint32_t flags, size_t size, unsigned int align, 91 int socket); 92 93 /** 94 * Memory free function. 95 * 96 * @param addr 97 * The memory address to be freed.. 98 */ 99 __rte_internal 100 void mlx5_free(void *addr); 101 102 #ifdef __cplusplus 103 } 104 #endif 105 106 #endif 107