aboutsummaryrefslogtreecommitdiff
path: root/pldm/libpldm/msgbuf
diff options
context:
space:
mode:
authorChristophe Lombard <clombard@linux.ibm.com>2023-06-20 16:52:06 +0200
committerReza Arbab <arbab@linux.ibm.com>2023-09-12 14:22:11 -0500
commit37a1c488de831fd9cacbc4ee04992c310dc342c1 (patch)
tree8b57508606113929c57bed486030a677e28f005e /pldm/libpldm/msgbuf
parentb9b330a0090d7092dffab2b8137da154c7248ad9 (diff)
downloadskiboot-37a1c488de831fd9cacbc4ee04992c310dc342c1.zip
skiboot-37a1c488de831fd9cacbc4ee04992c310dc342c1.tar.gz
skiboot-37a1c488de831fd9cacbc4ee04992c310dc342c1.tar.bz2
pldm/libpldm: Import libpldm library handling PLDM protocol
Platform Level Data Model (PLDM) is a standard application layer communication protocol defined by the DMTF. PLDM is an effective data and control source. PLDM defines a method to provide efficient access to low-level platform inventory, monitoring, control, eventing, and data/parameters transfer functions such as temperature, fan, voltage, event logging, and boot control. PLDM has defined data representations and commands that abstract the platform management hardware. The library deals with the encoding and decoding of PLDM messages. The source is located here: https://github.com/openbmc/pldm/tree/master/libpldm and use as is, without any update. The libpldm code is integrated into the folder ./pldm/libpldm as a set of sources, compilated if the compiler flag CONFIG_PLDM is set. 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 'pldm/libpldm/msgbuf')
-rw-r--r--pldm/libpldm/msgbuf/platform.h127
1 files changed, 127 insertions, 0 deletions
diff --git a/pldm/libpldm/msgbuf/platform.h b/pldm/libpldm/msgbuf/platform.h
new file mode 100644
index 0000000..bc296b8
--- /dev/null
+++ b/pldm/libpldm/msgbuf/platform.h
@@ -0,0 +1,127 @@
+#ifndef PLDM_MSGBUF_PLATFORM_H
+#define PLDM_MSGBUF_PLATFORM_H
+
+#include "../msgbuf.h"
+#include <libpldm/base.h>
+#include <libpldm/platform.h>
+
+static inline int
+pldm_msgbuf_extract_value_pdr_hdr(struct pldm_msgbuf *ctx,
+ struct pldm_value_pdr_hdr *hdr)
+{
+ pldm_msgbuf_extract(ctx, &hdr->record_handle);
+ pldm_msgbuf_extract(ctx, &hdr->version);
+ pldm_msgbuf_extract(ctx, &hdr->type);
+ pldm_msgbuf_extract(ctx, &hdr->record_change_num);
+ pldm_msgbuf_extract(ctx, &hdr->length);
+
+ return pldm_msgbuf_validate(ctx);
+}
+
+/*
+ * We use __attribute__((always_inline)) below so the compiler has visibility of
+ * the switch() at the call site. It is often the case that the size of multiple
+ * fields depends on the tag. Inlining thus gives the compiler visibility to
+ * hoist one tag-based code-path condition to cover all invocations.
+ */
+
+__attribute__((always_inline)) static inline int
+pldm_msgbuf_extract_sensor_data(struct pldm_msgbuf *ctx,
+ enum pldm_sensor_readings_data_type tag,
+ union_sensor_data_size *dst)
+{
+ switch (tag) {
+ case PLDM_SENSOR_DATA_SIZE_UINT8:
+ return pldm_msgbuf_extract(ctx, &dst->value_u8);
+ case PLDM_SENSOR_DATA_SIZE_SINT8:
+ return pldm_msgbuf_extract(ctx, &dst->value_s8);
+ case PLDM_SENSOR_DATA_SIZE_UINT16:
+ return pldm_msgbuf_extract(ctx, &dst->value_u16);
+ case PLDM_SENSOR_DATA_SIZE_SINT16:
+ return pldm_msgbuf_extract(ctx, &dst->value_s16);
+ case PLDM_SENSOR_DATA_SIZE_UINT32:
+ return pldm_msgbuf_extract(ctx, &dst->value_u32);
+ case PLDM_SENSOR_DATA_SIZE_SINT32:
+ return pldm_msgbuf_extract(ctx, &dst->value_s32);
+ }
+
+ return -PLDM_ERROR_INVALID_DATA;
+}
+
+/*
+ * This API is bad, but it's because the caller's APIs are also bad. They should
+ * have used the approach used by callers of pldm_msgbuf_extract_sensor_data()
+ * above
+ */
+__attribute__((always_inline)) static inline int
+pldm_msgbuf_extract_sensor_value(struct pldm_msgbuf *ctx,
+ enum pldm_effecter_data_size tag, uint8_t *val)
+{
+ switch (tag) {
+ case PLDM_SENSOR_DATA_SIZE_UINT8:
+ return pldm_msgbuf_extract_uint8(ctx, (uint8_t *)val);
+ case PLDM_SENSOR_DATA_SIZE_SINT8:
+ return pldm_msgbuf_extract_int8(ctx, (int8_t *)val);
+ case PLDM_SENSOR_DATA_SIZE_UINT16:
+ return pldm_msgbuf_extract_uint16(ctx, (uint16_t *)val);
+ case PLDM_SENSOR_DATA_SIZE_SINT16:
+ return pldm_msgbuf_extract_int16(ctx, (int16_t *)val);
+ case PLDM_SENSOR_DATA_SIZE_UINT32:
+ return pldm_msgbuf_extract_uint32(ctx, (uint32_t *)val);
+ case PLDM_SENSOR_DATA_SIZE_SINT32:
+ return pldm_msgbuf_extract_int32(ctx, (int32_t *)val);
+ }
+
+ return -PLDM_ERROR_INVALID_DATA;
+}
+
+__attribute__((always_inline)) static inline int
+pldm_msgbuf_extract_range_field_format(struct pldm_msgbuf *ctx,
+ enum pldm_range_field_format tag,
+ union_range_field_format *dst)
+{
+ switch (tag) {
+ case PLDM_RANGE_FIELD_FORMAT_UINT8:
+ return pldm_msgbuf_extract(ctx, &dst->value_u8);
+ case PLDM_RANGE_FIELD_FORMAT_SINT8:
+ return pldm_msgbuf_extract(ctx, &dst->value_s8);
+ case PLDM_RANGE_FIELD_FORMAT_UINT16:
+ return pldm_msgbuf_extract(ctx, &dst->value_u16);
+ case PLDM_RANGE_FIELD_FORMAT_SINT16:
+ return pldm_msgbuf_extract(ctx, &dst->value_s16);
+ case PLDM_RANGE_FIELD_FORMAT_UINT32:
+ return pldm_msgbuf_extract(ctx, &dst->value_u32);
+ case PLDM_RANGE_FIELD_FORMAT_SINT32:
+ return pldm_msgbuf_extract(ctx, &dst->value_s32);
+ case PLDM_RANGE_FIELD_FORMAT_REAL32:
+ return pldm_msgbuf_extract(ctx, &dst->value_f32);
+ }
+
+ return -PLDM_ERROR_INVALID_DATA;
+}
+
+/* This API is bad, but it's because the caller's APIs are also bad */
+__attribute__((always_inline)) static inline int
+pldm_msgbuf_extract_effecter_value(struct pldm_msgbuf *ctx,
+ enum pldm_effecter_data_size tag,
+ uint8_t *val)
+{
+ switch (tag) {
+ case PLDM_EFFECTER_DATA_SIZE_UINT8:
+ return pldm_msgbuf_extract_uint8(ctx, (uint8_t *)val);
+ case PLDM_EFFECTER_DATA_SIZE_SINT8:
+ return pldm_msgbuf_extract_int8(ctx, (int8_t *)val);
+ case PLDM_EFFECTER_DATA_SIZE_UINT16:
+ return pldm_msgbuf_extract_uint16(ctx, (uint16_t *)val);
+ case PLDM_EFFECTER_DATA_SIZE_SINT16:
+ return pldm_msgbuf_extract_int16(ctx, (int16_t *)val);
+ case PLDM_EFFECTER_DATA_SIZE_UINT32:
+ return pldm_msgbuf_extract_uint32(ctx, (uint32_t *)val);
+ case PLDM_EFFECTER_DATA_SIZE_SINT32:
+ return pldm_msgbuf_extract_int32(ctx, (int32_t *)val);
+ }
+
+ return -PLDM_ERROR_INVALID_DATA;
+}
+
+#endif