Add mlx5_os_malloc() & mlx5_os_free() APIs Signed-off-by: Srikanth Kaka <srikant...@oneconvergence.com> Signed-off-by: Vag Singh <vag.si...@oneconvergence.com> Signed-off-by: Anand Thulasiram <av...@juniper.net> --- drivers/common/mlx5/freebsd/mlx5_common_os.h | 46 ++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 drivers/common/mlx5/freebsd/mlx5_common_os.h
diff --git a/drivers/common/mlx5/freebsd/mlx5_common_os.h b/drivers/common/mlx5/freebsd/mlx5_common_os.h new file mode 100644 index 0000000000..0bf22e016a --- /dev/null +++ b/drivers/common/mlx5/freebsd/mlx5_common_os.h @@ -0,0 +1,46 @@ + +/* SPDX-License-Identifier: BSD-3-Clause + * Copyright 2020 Mellanox Technologies, Ltd + */ + +#ifndef RTE_PMD_MLX5_COMMON_OS_H_ +#define RTE_PMD_MLX5_COMMON_OS_H_ + +#include <stdio.h> + +/** + * Memory allocation optionally with alignment. + * + * @param[in] align + * Alignment size (may be zero) + * @param[in] size + * Size in bytes to allocate + * + * @return + * Valid pointer to allocated memory, NULL in case of failure + */ +static inline void * +mlx5_os_malloc(size_t align, size_t size) +{ + void *buf; + + if (posix_memalign(&buf, align, size)) + return NULL; + return buf; +} + +/** + * This API de-allocates a memory that originally could have been + * allocated aligned or non-aligned. In Linux it is a wrapper + * around free(). + * + * @param[in] addr + * Pointer to address to free + * + */ +static inline void +mlx5_os_free(void *addr) +{ + free(addr); +} +#endif /* RTE_PMD_MLX5_COMMON_OS_H_ */ -- 2.30.2