aboutsummaryrefslogtreecommitdiff
path: root/libmctp/alloc.c
diff options
context:
space:
mode:
authorChristophe Lombard <clombard@linux.ibm.com>2023-06-20 16:52:05 +0200
committerReza Arbab <arbab@linux.ibm.com>2023-09-12 14:22:11 -0500
commitb9b330a0090d7092dffab2b8137da154c7248ad9 (patch)
treedf99eb84ab3f1c64897a3224af40a4e110b4af37 /libmctp/alloc.c
parenta55d0672d62aaf6eb77dcbc6461d35b751b56c41 (diff)
downloadskiboot-b9b330a0090d7092dffab2b8137da154c7248ad9.zip
skiboot-b9b330a0090d7092dffab2b8137da154c7248ad9.tar.gz
skiboot-b9b330a0090d7092dffab2b8137da154c7248ad9.tar.bz2
libmctp: Import libmctp library handling MCTP protocol
The Management Component Transport Protocol (MCTP) is a protocol defined by the DMTF Platform Management Component Intercommunications sub-team of the DMTF Pre-OS Workgroup. MCTP is designed to support communications between different intelligent hardware components that make up a platform management subsystem that is provides monitoring and control functions inside a managed system. DMTF standard "DSP2016" This library is intended to be a portable implementation of the Management Component Transport Protocol (MCTP), as defined by DMTF standard "DSP0236", plus transport binding specifications. MCTP has been designed to carry multiple types of manageability-related traffic across a common medium. The base MCTP specifications define message types for supporting the initialization and configuration of MCTP itself, and to support vendor-specific messages over MCTP. Other message types, such as message types to support a Platform Level Data Model (PLDM). The source is located here: https://github.com/openbmc/libmctp and use as is, without any update. The libmctp code is integrated into the folder ./libmctp as a set of sources, compiled if the compiler flag CONFIG_PLDM is set. A config file is required. Not being generated automatically by 'configure', it must be edited manually to match the environment. Signed-off-by: Christophe Lombard <clombard@linux.ibm.com> Acked-by: Nicholas Piggin <npiggin@gmail.com> Signed-off-by: Reza Arbab <arbab@linux.ibm.com>
Diffstat (limited to 'libmctp/alloc.c')
-rw-r--r--libmctp/alloc.c59
1 files changed, 59 insertions, 0 deletions
diff --git a/libmctp/alloc.c b/libmctp/alloc.c
new file mode 100644
index 0000000..84c3f65
--- /dev/null
+++ b/libmctp/alloc.c
@@ -0,0 +1,59 @@
+/* SPDX-License-Identifier: Apache-2.0 OR GPL-2.0-or-later */
+
+#include <assert.h>
+
+#include "libmctp.h"
+#include "libmctp-alloc.h"
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+struct {
+ void *(*m_alloc)(size_t);
+ void (*m_free)(void *);
+ void *(*m_realloc)(void *, size_t);
+} alloc_ops = {
+#ifdef MCTP_DEFAULT_ALLOC
+ malloc,
+ free,
+ realloc,
+#endif
+};
+
+/* internal-only allocation functions */
+void *__mctp_alloc(size_t size)
+{
+ if (alloc_ops.m_alloc)
+ return alloc_ops.m_alloc(size);
+ if (alloc_ops.m_realloc)
+ return alloc_ops.m_realloc(NULL, size);
+ assert(0);
+ return NULL;
+}
+
+void __mctp_free(void *ptr)
+{
+ if (alloc_ops.m_free)
+ alloc_ops.m_free(ptr);
+ else if (alloc_ops.m_realloc)
+ alloc_ops.m_realloc(ptr, 0);
+ else
+ assert(0);
+}
+
+void *__mctp_realloc(void *ptr, size_t size)
+{
+ if (alloc_ops.m_realloc)
+ return alloc_ops.m_realloc(ptr, size);
+ assert(0);
+ return NULL;
+}
+
+void mctp_set_alloc_ops(void *(*m_alloc)(size_t), void (*m_free)(void *),
+ void *(m_realloc)(void *, size_t))
+{
+ alloc_ops.m_alloc = m_alloc;
+ alloc_ops.m_free = m_free;
+ alloc_ops.m_realloc = m_realloc;
+}