[v2,02/41] common/mlx5: add memory APIs
Checks
Commit Message
Add mlx5_os_malloc() & mlx5_os_free() APIs
Signed-off-by: Srikanth Kaka <srikanth.k@oneconvergence.com>
Signed-off-by: Vag Singh <vag.singh@oneconvergence.com>
Signed-off-by: Anand Thulasiram <avelu@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
new file mode 100644
@@ -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_ */